polotno-node 2.15.14 → 2.15.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./jspdf.es.min-B7BbMBrq.js","./chunk-DseTPa7n.js","./typeof-GPCnPm50.js","./lib-C0YGJINc.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./jspdf.es.min-CBRoYge0.js","./chunk-DseTPa7n.js","./typeof-GPCnPm50.js","./lib-Cm7bIAAZ.js"])))=>i.map(i=>d[i]);
2
2
  import{i as e,n as t,r as n,t as r}from"./chunk-DseTPa7n.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var i=r((e=>{var t=Symbol.for(`react.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.provider`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.iterator;function p(e){return typeof e!=`object`||!e?null:(e=f&&e[f]||e[`@@iterator`],typeof e==`function`?e:null)}var m={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},h=Object.assign,g={};function _(e,t,n){this.props=e,this.context=t,this.refs=g,this.updater=n||m}_.prototype.isReactComponent={},_.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`setState(...): takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},_.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function v(){}v.prototype=_.prototype;function y(e,t,n){this.props=e,this.context=t,this.refs=g,this.updater=n||m}var b=y.prototype=new v;b.constructor=y,h(b,_.prototype),b.isPureReactComponent=!0;var x=Array.isArray,S=Object.prototype.hasOwnProperty,C={current:null},w={key:!0,ref:!0,__self:!0,__source:!0};function T(e,n,r){var i,a={},o=null,s=null;if(n!=null)for(i in n.ref!==void 0&&(s=n.ref),n.key!==void 0&&(o=``+n.key),n)S.call(n,i)&&!w.hasOwnProperty(i)&&(a[i]=n[i]);var c=arguments.length-2;if(c===1)a.children=r;else if(1<c){for(var l=Array(c),u=0;u<c;u++)l[u]=arguments[u+2];a.children=l}if(e&&e.defaultProps)for(i in c=e.defaultProps,c)a[i]===void 0&&(a[i]=c[i]);return{$$typeof:t,type:e,key:o,ref:s,props:a,_owner:C.current}}function E(e,n){return{$$typeof:t,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function D(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function O(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var k=/\/+/g;function A(e,t){return typeof e==`object`&&e&&e.key!=null?O(``+e.key):t.toString(36)}function j(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0}}if(c)return c=e,o=o(c),e=a===``?`.`+A(c,0):a,x(o)?(i=``,e!=null&&(i=e.replace(k,`$&/`)+`/`),j(o,r,i,``,function(e){return e})):o!=null&&(D(o)&&(o=E(o,i+(!o.key||c&&c.key===o.key?``:(``+o.key).replace(k,`$&/`)+`/`)+e)),r.push(o)),1;if(c=0,a=a===``?`.`:a+`:`,x(e))for(var l=0;l<e.length;l++){s=e[l];var u=a+A(s,l);c+=j(s,r,i,u,o)}else if(u=p(e),typeof u==`function`)for(e=u.call(e),l=0;!(s=e.next()).done;)s=s.value,u=a+A(s,l++),c+=j(s,r,i,u,o);else if(s===`object`)throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`);return c}function M(e,t,n){if(e==null)return e;var r=[],i=0;return j(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function N(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var P={current:null},F={transition:null},ee={ReactCurrentDispatcher:P,ReactCurrentBatchConfig:F,ReactCurrentOwner:C};function te(){throw Error(`act(...) is not supported in production builds of React.`)}e.Children={map:M,forEach:function(e,t,n){M(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return M(e,function(){t++}),t},toArray:function(e){return M(e,function(e){return e})||[]},only:function(e){if(!D(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}},e.Component=_,e.Fragment=r,e.Profiler=a,e.PureComponent=y,e.StrictMode=i,e.Suspense=l,e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=ee,e.act=te,e.cloneElement=function(e,n,r){if(e==null)throw Error(`React.cloneElement(...): The argument must be a React element, but you passed `+e+`.`);var i=h({},e.props),a=e.key,o=e.ref,s=e._owner;if(n!=null){if(n.ref!==void 0&&(o=n.ref,s=C.current),n.key!==void 0&&(a=``+n.key),e.type&&e.type.defaultProps)var c=e.type.defaultProps;for(l in n)S.call(n,l)&&!w.hasOwnProperty(l)&&(i[l]=n[l]===void 0&&c!==void 0?c[l]:n[l])}var l=arguments.length-2;if(l===1)i.children=r;else if(1<l){c=Array(l);for(var u=0;u<l;u++)c[u]=arguments[u+2];i.children=c}return{$$typeof:t,type:e.type,key:a,ref:o,props:i,_owner:s}},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:o,_context:e},e.Consumer=e},e.createElement=T,e.createFactory=function(e){var t=T.bind(null,e);return t.type=e,t},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=D,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:N}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=F.transition;F.transition={};try{e()}finally{F.transition=t}},e.unstable_act=te,e.useCallback=function(e,t){return P.current.useCallback(e,t)},e.useContext=function(e){return P.current.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e){return P.current.useDeferredValue(e)},e.useEffect=function(e,t){return P.current.useEffect(e,t)},e.useId=function(){return P.current.useId()},e.useImperativeHandle=function(e,t,n){return P.current.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return P.current.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return P.current.useLayoutEffect(e,t)},e.useMemo=function(e,t){return P.current.useMemo(e,t)},e.useReducer=function(e,t,n){return P.current.useReducer(e,t,n)},e.useRef=function(e){return P.current.useRef(e)},e.useState=function(e){return P.current.useState(e)},e.useSyncExternalStore=function(e,t,n){return P.current.useSyncExternalStore(e,t,n)},e.useTransition=function(){return P.current.useTransition()},e.version=`18.3.1`})),a=r(((e,t)=>{t.exports=i()})),o=r((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=typeof setTimeout==`function`?setTimeout:null,_=typeof clearTimeout==`function`?clearTimeout:null,v=typeof setImmediate<`u`?setImmediate:null;typeof navigator<`u`&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function y(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function b(e){if(h=!1,y(e),!m)if(n(c)!==null)m=!0,M(x);else{var t=n(l);t!==null&&N(b,t.startTime-e)}}function x(t,i){m=!1,h&&(h=!1,_(w),w=-1),p=!0;var a=f;try{for(y(i),d=n(c);d!==null&&(!(d.expirationTime>i)||t&&!D());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=i);i=e.unstable_now(),typeof s==`function`?d.callback=s:d===n(c)&&r(c),y(i)}else r(c);d=n(c)}if(d!==null)var u=!0;else{var g=n(l);g!==null&&N(b,g.startTime-i),u=!1}return u}finally{d=null,f=a,p=!1}}var S=!1,C=null,w=-1,T=5,E=-1;function D(){return!(e.unstable_now()-E<T)}function O(){if(C!==null){var t=e.unstable_now();E=t;var n=!0;try{n=C(!0,t)}finally{n?k():(S=!1,C=null)}}else S=!1}var k;if(typeof v==`function`)k=function(){v(O)};else if(typeof MessageChannel<`u`){var A=new MessageChannel,j=A.port2;A.port1.onmessage=O,k=function(){j.postMessage(null)}}else k=function(){g(O,0)};function M(e){C=e,S||(S=!0,k())}function N(t,n){w=g(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_continueExecution=function(){m||p||(m=!0,M(x))},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):T=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_getFirstCallbackNode=function(){return n(c)},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(_(w),w=-1):h=!0,N(b,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,M(x))),r},e.unstable_shouldYield=D,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),s=r(((e,t)=>{t.exports=o()})),c=r((e=>{var t=a(),n=s();function r(e){for(var t=`https://reactjs.org/docs/error-decoder.html?invariant=`+e,n=1;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n]);return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}var i=new Set,o={};function c(e,t){l(e,t),l(e+`Capture`,t)}function l(e,t){for(o[e]=t,e=0;e<t.length;e++)i.add(t[e])}var u=!(typeof window>`u`||window.document===void 0||window.document.createElement===void 0),d=Object.prototype.hasOwnProperty,f=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,p={},m={};function h(e){return d.call(m,e)?!0:d.call(p,e)?!1:f.test(e)?m[e]=!0:(p[e]=!0,!1)}function g(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case`function`:case`symbol`:return!0;case`boolean`:return r?!1:n===null?(e=e.toLowerCase().slice(0,5),e!==`data-`&&e!==`aria-`):!n.acceptsBooleans;default:return!1}}function _(e,t,n,r){if(t==null||g(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return!1===t;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function v(e,t,n,r,i,a,o){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=i,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=a,this.removeEmptyString=o}var y={};`children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style`.split(` `).forEach(function(e){y[e]=new v(e,0,!1,e,null,!1,!1)}),[[`acceptCharset`,`accept-charset`],[`className`,`class`],[`htmlFor`,`for`],[`httpEquiv`,`http-equiv`]].forEach(function(e){var t=e[0];y[t]=new v(t,1,!1,e[1],null,!1,!1)}),[`contentEditable`,`draggable`,`spellCheck`,`value`].forEach(function(e){y[e]=new v(e,2,!1,e.toLowerCase(),null,!1,!1)}),[`autoReverse`,`externalResourcesRequired`,`focusable`,`preserveAlpha`].forEach(function(e){y[e]=new v(e,2,!1,e,null,!1,!1)}),`allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope`.split(` `).forEach(function(e){y[e]=new v(e,3,!1,e.toLowerCase(),null,!1,!1)}),[`checked`,`multiple`,`muted`,`selected`].forEach(function(e){y[e]=new v(e,3,!0,e,null,!1,!1)}),[`capture`,`download`].forEach(function(e){y[e]=new v(e,4,!1,e,null,!1,!1)}),[`cols`,`rows`,`size`,`span`].forEach(function(e){y[e]=new v(e,6,!1,e,null,!1,!1)}),[`rowSpan`,`start`].forEach(function(e){y[e]=new v(e,5,!1,e.toLowerCase(),null,!1,!1)});var b=/[\-:]([a-z])/g;function x(e){return e[1].toUpperCase()}`accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height`.split(` `).forEach(function(e){var t=e.replace(b,x);y[t]=new v(t,1,!1,e,null,!1,!1)}),`xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type`.split(` `).forEach(function(e){var t=e.replace(b,x);y[t]=new v(t,1,!1,e,`http://www.w3.org/1999/xlink`,!1,!1)}),[`xml:base`,`xml:lang`,`xml:space`].forEach(function(e){var t=e.replace(b,x);y[t]=new v(t,1,!1,e,`http://www.w3.org/XML/1998/namespace`,!1,!1)}),[`tabIndex`,`crossOrigin`].forEach(function(e){y[e]=new v(e,1,!1,e.toLowerCase(),null,!1,!1)}),y.xlinkHref=new v(`xlinkHref`,1,!1,`xlink:href`,`http://www.w3.org/1999/xlink`,!0,!1),[`src`,`href`,`action`,`formAction`].forEach(function(e){y[e]=new v(e,1,!1,e.toLowerCase(),null,!0,!0)});function S(e,t,n,r){var i=y.hasOwnProperty(t)?y[t]:null;(i===null?r||!(2<t.length)||t[0]!==`o`&&t[0]!==`O`||t[1]!==`n`&&t[1]!==`N`:i.type!==0)&&(_(t,n,i,r)&&(n=null),r||i===null?h(t)&&(n===null?e.removeAttribute(t):e.setAttribute(t,``+n)):i.mustUseProperty?e[i.propertyName]=n===null?i.type===3?!1:``:n:(t=i.attributeName,r=i.attributeNamespace,n===null?e.removeAttribute(t):(i=i.type,n=i===3||i===4&&!0===n?``:``+n,r?e.setAttributeNS(r,t,n):e.setAttribute(t,n))))}var C=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,w=Symbol.for(`react.element`),T=Symbol.for(`react.portal`),E=Symbol.for(`react.fragment`),D=Symbol.for(`react.strict_mode`),O=Symbol.for(`react.profiler`),k=Symbol.for(`react.provider`),A=Symbol.for(`react.context`),j=Symbol.for(`react.forward_ref`),M=Symbol.for(`react.suspense`),N=Symbol.for(`react.suspense_list`),P=Symbol.for(`react.memo`),F=Symbol.for(`react.lazy`),ee=Symbol.for(`react.offscreen`),te=Symbol.iterator;function ne(e){return typeof e!=`object`||!e?null:(e=te&&e[te]||e[`@@iterator`],typeof e==`function`?e:null)}var re=Object.assign,ie;function I(e){if(ie===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);ie=t&&t[1]||``}return`
3
3
  `+ie+e}var ae=!1;function oe(e,t){if(!e||ae)return``;ae=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(t)if(t=function(){throw Error()},Object.defineProperty(t.prototype,`props`,{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(t,[])}catch(e){var r=e}Reflect.construct(e,[],t)}else{try{t.call()}catch(e){r=e}e.call(t.prototype)}else{try{throw Error()}catch(e){r=e}e()}}catch(t){if(t&&r&&typeof t.stack==`string`){for(var i=t.stack.split(`
4
4
  `),a=r.stack.split(`
@@ -40,18 +40,18 @@ For more info see: https://github.com/konvajs/react-konva/issues/256
40
40
  react-konva may get confused with ordering. Just define correct order of elements in your render function of a component.
41
41
  For more info see: https://github.com/konvajs/react-konva/issues/194
42
42
  `,Vu={};function Hu(e,t,n=Vu){if(!Fu&&`zIndex`in t&&(console.warn(Bu),Fu=!0),!Iu&&t.draggable){var r=t.x!==void 0||t.y!==void 0,i=t.onDragEnd||t.onDragMove;r&&!i&&(console.warn(zu),Iu=!0)}for(var a in n)if(!Pu[a]){var o=a.slice(0,2)===`on`,s=n[a]!==t[a];if(o&&s){var c=a.substr(2).toLowerCase();c.substr(0,7)===`content`&&(c=`content`+c.substr(7,1).toUpperCase()+c.substr(8)),e.off(c,n[a])}t.hasOwnProperty(a)||e.setAttr(a,void 0)}var l=Ru||t._useStrictMode,u={},d=!1;let f={};for(var a in t)if(!Pu[a]){var o=a.slice(0,2)===`on`,p=n[a]!==t[a];if(o&&p){var c=a.substr(2).toLowerCase();c.substr(0,7)===`content`&&(c=`content`+c.substr(7,1).toUpperCase()+c.substr(8)),t[a]&&(f[c]=t[a])}!o&&(t[a]!==n[a]||l&&t[a]!==e.getAttr(a))&&(d=!0,u[a]=t[a])}for(var c in d&&(e.setAttrs(u),Uu(e)),f)e.on(c+Lu,f[c])}function Uu(e){if(!z.autoDrawEnabled){var t=e.getLayer()||e.getStage();t&&t.batchDraw()}}var Wu=t({appendChild:()=>ud,appendChildToContainer:()=>dd,appendInitialChild:()=>Ju,cancelTimeout:()=>cd,clearContainer:()=>Cd,commitMount:()=>_d,commitTextUpdate:()=>gd,commitUpdate:()=>vd,createInstance:()=>Yu,createTextInstance:()=>Xu,detachDeletedInstance:()=>wd,finalizeInitialChildren:()=>Zu,getChildHostContext:()=>od,getCurrentEventPriority:()=>Td,getPublicInstance:()=>Qu,getRootHostContext:()=>ad,hideInstance:()=>yd,hideTextInstance:()=>bd,idlePriority:()=>Gu.unstable_IdlePriority,insertBefore:()=>fd,insertInContainerBefore:()=>pd,isPrimaryRenderer:()=>!1,noTimeout:()=>-1,now:()=>Gu.unstable_now,prepareForCommit:()=>$u,preparePortalMount:()=>ed,prepareUpdate:()=>td,removeChild:()=>md,removeChildFromContainer:()=>hd,resetAfterCommit:()=>nd,resetTextContent:()=>rd,run:()=>Gu.unstable_runWithPriority,scheduleTimeout:()=>sd,shouldDeprioritizeSubtree:()=>id,shouldSetTextContent:()=>ld,supportsMutation:()=>!0,unhideInstance:()=>xd,unhideTextInstance:()=>Sd,warnsIfNotActing:()=>!0}),Gu=s(),Ku={},qu={};Ou.Node.prototype._applyProps=Hu;function Ju(e,t){if(typeof t==`string`){console.error(`Do not use plain text as child of Konva.Node. You are using text: ${t}`);return}e.add(t),Uu(e)}function Yu(e,t,n){let r=Ou[e];r||=(console.error(`Konva has no node with the type ${e}. Group will be used instead. If you use minimal version of react-konva, just import required nodes into Konva: "import "konva/lib/shapes/${e}" If you want to render DOM elements as part of canvas tree take a look into this demo: https://konvajs.github.io/docs/react/DOM_Portal.html`),Ou.Group);let i={},a={};for(var o in t)o.slice(0,2)===`on`?a[o]=t[o]:i[o]=t[o];let s=new r(i);return Hu(s,a),s}function Xu(e,t,n){console.error(`Text components are not supported for now in ReactKonva. Your text is: "${e}"`)}function Zu(e,t,n){return!1}function Qu(e){return e}function $u(){return null}function ed(){return null}function td(e,t,n,r){return qu}function nd(){}function rd(e){}function id(e,t){return!1}function ad(){return Ku}function od(){return Ku}var sd=setTimeout,cd=clearTimeout;function ld(e,t){return!1}function ud(e,t){t.parent===e?t.moveToTop():e.add(t),Uu(e)}function dd(e,t){t.parent===e?t.moveToTop():e.add(t),Uu(e)}function fd(e,t,n){t._remove(),e.add(t),t.setZIndex(n.getZIndex()),Uu(e)}function pd(e,t,n){fd(e,t,n)}function md(e,t){t.destroy(),t.off(Lu),Uu(e)}function hd(e,t){t.destroy(),t.off(Lu),Uu(e)}function gd(e,t,n){console.error(`Text components are not yet supported in ReactKonva. You text is: "${n}"`)}function _d(e,t,n){}function vd(e,t,n,r,i){Hu(e,i,r)}function yd(e){e.hide(),Uu(e)}function bd(e){}function xd(e,t){(t.visible==null||t.visible)&&e.show()}function Sd(e,t){}function Cd(e){}function wd(){}var Td=()=>Mu.DefaultEventPriority,Ed=Object.defineProperty,Dd=Object.defineProperties,Od=Object.getOwnPropertyDescriptors,kd=Object.getOwnPropertySymbols,Ad=Object.prototype.hasOwnProperty,jd=Object.prototype.propertyIsEnumerable,Md=(e,t,n)=>t in e?Ed(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Nd=(e,t)=>{for(var n in t||={})Ad.call(t,n)&&Md(e,n,t[n]);if(kd)for(var n of kd(t))jd.call(t,n)&&Md(e,n,t[n]);return e},Pd=(e,t)=>Dd(e,Od(t));typeof window<`u`&&(window.document?.createElement||window.navigator?.product===`ReactNative`)?d.useLayoutEffect:d.useEffect;function Fd(e,t,n){if(!e)return;if(n(e)===!0)return e;let r=t?e.return:e.child;for(;r;){let e=Fd(r,t,n);if(e)return e;r=t?null:r.sibling}}function Id(e){try{return Object.defineProperties(e,{_currentRenderer:{get(){return null},set(){}},_currentRenderer2:{get(){return null},set(){}}})}catch{return e}}var Ld=console.error;console.error=function(){let e=[...arguments].join(``);if(e?.startsWith(`Warning:`)&&e.includes(`useContext`)){console.error=Ld;return}return Ld.apply(this,arguments)};var Rd=Id(d.createContext(null)),zd=class extends d.Component{render(){return d.createElement(Rd.Provider,{value:this._reactInternals},this.props.children)}};function Bd(){let e=d.useContext(Rd);if(e===null)throw Error(`its-fine: useFiber must be called within a <FiberProvider />!`);let t=d.useId();return d.useMemo(()=>{for(let n of[e,e?.alternate]){if(!n)continue;let e=Fd(n,!1,e=>{let n=e.memoizedState;for(;n;){if(n.memoizedState===t)return!0;n=n.next}});if(e)return e}},[e,t])}function Vd(){let e=Bd(),[t]=d.useState(()=>new Map);t.clear();let n=e;for(;n;){if(n.type&&typeof n.type==`object`){let e=n.type._context===void 0&&n.type.Provider===n.type?n.type:n.type._context;e&&e!==Rd&&!t.has(e)&&t.set(e,d.useContext(Id(e)))}n=n.return}return t}function Hd(){let e=Vd();return d.useMemo(()=>Array.from(e.keys()).reduce((t,n)=>r=>d.createElement(t,null,d.createElement(n.Provider,Pd(Nd({},r),{value:e.get(n)}))),e=>d.createElement(zd,Nd({},e))),[e])}function Ud(e){let t=d.useRef({});return d.useLayoutEffect(()=>{t.current=e}),d.useLayoutEffect(()=>()=>{t.current={}},[]),t.current}var Wd=e=>{let t=d.useRef(null),n=d.useRef(null),r=d.useRef(null),i=Ud(e),a=Hd(),o=t=>{let{forwardedRef:n}=e;n&&(typeof n==`function`?n(t):n.current=t)};return d.useLayoutEffect(()=>(n.current=new Ou.Stage({width:e.width,height:e.height,container:t.current}),o(n.current),r.current=tf.createContainer(n.current,Mu.LegacyRoot,!1,null),tf.updateContainer(d.createElement(a,{},e.children),r.current),()=>{Ou.isBrowser&&(o(null),tf.updateContainer(null,r.current,null),n.current.destroy())}),[]),d.useLayoutEffect(()=>{o(n.current),Hu(n.current,e,i),tf.updateContainer(d.createElement(a,{},e.children),r.current,null)}),d.createElement(`div`,{ref:t,id:e.id,accessKey:e.accessKey,className:e.className,role:e.role,style:e.style,tabIndex:e.tabIndex,title:e.title})},Gd=`Layer`,Kd=`Group`,qd=`Label`,Jd=`Rect`,Yd=`Line`,Xd=`Image`,Zd=`Text`,Qd=`TextPath`,$d=`Path`,ef=`Transformer`,tf=(0,Nu.default)(Wu);tf.injectIntoDevTools({findHostInstanceByFiber:()=>null,bundleType:0,version:`18.3.1`,rendererPackageName:`react-konva`});var nf=d.forwardRef((e,t)=>d.createElement(zd,{},d.createElement(Wd,{...e,forwardedRef:t}))),rf=e(r(((e,t)=>{var n=a();t.exports=function(e,t,r){let i=n.useRef(`loading`),a=n.useRef(),[o,s]=n.useState(0),c=n.useRef(),l=n.useRef(),u=n.useRef();return(c.current!==e||l.current!==t||u.current!==r)&&(i.current=`loading`,a.current=void 0,c.current=e,l.current=t,u.current=r),n.useLayoutEffect(function(){if(!e)return;var n=document.createElement(`img`);function o(){n.decode().catch(()=>{}).finally(()=>{i.current=`loaded`,a.current=n,s(Math.random())})}function c(){i.current=`failed`,a.current=void 0,s(Math.random())}return n.addEventListener(`load`,o),n.addEventListener(`error`,c),t&&(n.crossOrigin=t),r&&(n.referrerPolicy=r),n.src=e,function(){n.removeEventListener(`load`,o),n.removeEventListener(`error`,c)}},[e,t,r]),[a.current,i.current]}}))()),af=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n},of=e=>{let t=window.getComputedStyle(e).position;return!(t===`absolute`||t===`relative`)};function sf(e=()=>{}){let t=d.useRef(e);return t.current=e,d.useCallback((...e)=>t.current.apply(null,e),[])}var cf=({children:e,groupProps:t,divProps:n,transform:r,transformFunc:i,parentNodeFunc:a})=>{let o=Hd(),s=d.useRef(null),[c]=d.useState(()=>document.createElement(`div`)),l=d.useMemo(()=>u.createRoot(c),[c]),f=r??!0,p=sf(()=>{if(f&&s.current){let e=s.current.getAbsoluteTransform().decompose();i&&(e=i(e)),c.style.position=`absolute`,c.style.zIndex=`10`,c.style.top=`0px`,c.style.left=`0px`,c.style.transform=`translate(${e.x}px, ${e.y}px) rotate(${e.rotation}deg) scaleX(${e.scaleX}) scaleY(${e.scaleY})`,c.style.transformOrigin=`top left`}else c.style.position=``,c.style.zIndex=``,c.style.top=``,c.style.left=``,c.style.transform=``,c.style.transformOrigin=``;let e=n||{},{style:t}=e,r=af(e,[`style`]);Object.assign(c.style,t),Object.assign(c,r)});return d.useLayoutEffect(()=>{let e=s.current;if(!e)return;let t=a?a({stage:e.getStage()}):e.getStage()?.container();if(t)return t.appendChild(c),f&&of(t)&&(t.style.position=`relative`),e.on(`absoluteTransformChange`,p),p(),()=>{var t;e.off(`absoluteTransformChange`,p),(t=c.parentNode)==null||t.removeChild(c)}},[f,a]),d.useLayoutEffect(()=>{p()},[n,i]),d.useLayoutEffect(()=>{queueMicrotask(()=>{(0,Ui.flushSync)(()=>{l.render(d.createElement(o,null,e))})})}),d.useLayoutEffect(()=>()=>{setTimeout(()=>{l.unmount()})},[]),d.createElement(Kd,Object.assign({ref:s},t))},lf=({selector:e,enabled:t,children:n})=>{let r=d.useRef(null),i=d.useRef(null),a=d.useRef(null),o=t??!0;return d.useLayoutEffect(()=>{if(!r.current||!i.current)return;a.current=i.current;let t=r.current.getStage().findOne(e);o&&t?i.current.moveTo(t):i.current.moveTo(r.current);let n=r.current.getLayer();if(n&&(n.batchDraw(),t)){let e=t.getLayer();if(!e)return;e.batchDraw()}},[e,o]),d.useEffect(()=>()=>{var e;(e=a.current)==null||e.destroy()},[]),d.createElement(Kd,{name:`_outer_portal`,ref:r},d.createElement(Kd,{name:`_inner_portal`,ref:i},n))};function uf(e,t){return Object.keys(e.values).forEach(n=>e.values[n]=e.values[n]&&parseFloat(e.values[n].toFixed(t))),e}function df(e,t,n){let r=t-1,i=n[hf(r,n.length)];return i.marker===`Z`?df(e,r,n):i}function ff(e,t,n){let r=t+1,i=n[hf(r,n.length)];return i.marker===`Z`?ff(e,r,n):i}function pf(e,t,n){let r=n[t-1]||{values:{x:0,y:0}};if(e.marker===e.marker.toLowerCase())switch(e.marker=e.marker.toUpperCase(),e.marker){case`M`:e.values.x+=r.values.x,e.values.y+=r.values.y;break;case`L`:case`A`:e.values.x+=r.values.x,e.values.y+=r.values.y;break;case`H`:e.marker=`L`,e.values.x+=r.values.x,e.values.y=r.values.y;break;case`V`:e.marker=`L`,e.values.x=r.values.x,e.values.y+=r.values.y;break;case`C`:e.values.x+=r.values.x,e.values.y+=r.values.y,e.values.x1+=r.values.x,e.values.y1+=r.values.y,e.values.x2+=r.values.x,e.values.y2+=r.values.y;break;case`S`:e.values.x+=r.values.x,e.values.y+=r.values.y,e.values.x2+=r.values.x,e.values.y2+=r.values.y;break;case`Q`:e.values.x+=r.values.x,e.values.y+=r.values.y,e.values.x1+=r.values.x,e.values.y1+=r.values.y;break;case`T`:e.values.x+=r.values.x,e.values.y+=r.values.y;break;case`Z`:break}else if(e.marker===e.marker.toUpperCase())switch(e.marker){case`H`:e.marker=`L`,e.values.y=r.values.y;break;case`V`:e.marker=`L`,e.values.x=r.values.x;break}if(e.marker===`Z`){function r(e,t){return e[t].marker===`M`?e[t]:r(e,t-1)}let i=r(n,t);e.values.x=i.values.x,e.values.y=i.values.y}return e}function mf(e,t){let n=[];switch(e.toUpperCase()){case`M`:for(let r=0;r<t.length;r+=2){let i;i=e===e.toUpperCase()?r===0?`M`:`L`:r===0?`m`:`l`,n.push({marker:i,values:{x:t[r],y:t[r+1]}})}break;case`L`:for(let r=0;r<t.length;r+=2)n.push({marker:e,values:{x:t[r],y:t[r+1]}});break;case`H`:for(let r=0;r<t.length;r++)n.push({marker:e,values:{x:t[r],y:0}});break;case`V`:for(let r=0;r<t.length;r++)n.push({marker:e,values:{x:0,y:t[r]}});break;case`C`:for(let r=0;r<t.length;r+=6)n.push({marker:e,values:{x1:t[r],y1:t[r+1],x2:t[r+2],y2:t[r+3],x:t[r+4],y:t[r+5]}});break;case`S`:for(let r=0;r<t.length;r+=4)n.push({marker:e,values:{x2:t[r],y2:t[r+1],x:t[r+2],y:t[r+3]}});break;case`Q`:for(let r=0;r<t.length;r+=4)n.push({marker:e,values:{x1:t[r],y1:t[r+1],x:t[r+2],y:t[r+3]}});break;case`T`:for(let r=0;r<t.length;r+=2)n.push({marker:e,values:{x:t[r],y:t[r+1]}});break;case`A`:for(let r=0;r<t.length;r+=7)n.push({marker:e,values:{radiusX:t[r],radiusY:t[r+1],rotation:t[r+2],largeArc:t[r+3],sweep:t[r+4],x:t[r+5],y:t[r+6]}});break;case`Z`:n.push({marker:e,values:{x:0,y:0}});break}return n}function hf(e,t){return(e%t+t)%t}function gf(e,t,n){if(t!==0&&e.marker===`L`){let r=n[t-1];[`x`,`y`].every(t=>Math.round(Math.abs(r.values[t]-e.values[t]))===0)&&(e.overlap=!0)}return e}function _f(e,t){let n=[`x`,`y`].every(n=>Math.round(Math.abs(e[t].values[n]-e[0].values[n]))===0);e[t].marker===`L`&&n&&(e[t].overlap=!0,_f(e,t-1)),e[t].marker===`Z`&&_f(e,t-1)}function vf(e,t,n){let r=bf(e.values,n.values),i=bf(t.values,e.values);return Math.min(i,r)}function yf(e,t){return Math.atan2(t.x-e.x,t.y-e.y)}function bf(e,t){let n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n**2+r**2)}function xf(e,t){return Math.sin(e)*t}function Sf(e,t){return Math.cos(e)*t}function Cf(e,t){let n=t/Math.tan(e);return n===1/0||n===-1/0||isNaN(n)?t:n}function wf(e,t){return t*Math.tan(e)}function Tf(e,t){let n,r=0,i=e*(180/Math.PI);return i<0&&i>=-180||i>180&&i<360?n=Cf(e/2,-t):(n=Cf(e/2,t),r=1,n===1/0&&(n=t)),{offset:n,sweepFlag:r}}function Ef(e){let t=[`radiusX`,`radiusY`,`rotation`,`largeArc`,`sweep`,`x1`,`y1`,`x2`,`y2`,`x`,`y`];return e.map(e=>{let n=``;if(e.marker!==`Z`){let r=Object.keys(e.values);n=t.filter(e=>r.indexOf(e)!==-1).map(t=>e.values[t]).join()}return`${e.marker}${n}`}).join(``).trim()}function Df(e){let t=/[MmLlSsQqLlHhVvCcSsQqTtAaZz]/g,n=/-?[0-9]*\.?\d+/g;return[...e.matchAll(t)].map(e=>({marker:e[0],index:e.index})).reduceRight((t,n)=>{let r=e.substring(n.index,t.length?t[t.length-1].index:e.length);return t.concat([{marker:n.marker,index:n.index,chunk:r.length>0?r.substr(1,r.length-1):r}])},[]).reverse().flatMap(e=>{let t=e.chunk.match(n),r=t?t.map(parseFloat):[];return mf(e.marker,r)}).map(pf)}function Of(e,t,n){let r=[],i=[];return n&&e.forEach(e=>uf(e,n)),e.forEach(e=>{e.marker===`M`&&r.push([]),r[r.length-1].push(e)}),r.forEach(e=>{e.map(gf),_f(e,e.length-1);let n=e[e.length-1].marker==`Z`;e.filter(e=>!e.overlap).map((e,r,a)=>{let o=df(e,r,a),s=ff(e,r,a),c=yf(e.values,o.values),l=yf(e.values,s.values),u=l-c,d=u*(180/Math.PI),f=vf(e,o,s),p=Math.abs(wf(u/2,f/2)),m=Math.min(t,p),h=Tf(u,m),g=h.offset,_=h.sweepFlag,v=(r==0||r==a.length-1)&&!n;switch(e.marker){case`M`:case`L`:let t=[e.values.x+xf(c,g),e.values.y+Sf(c,g)],n=[e.values.x+xf(l,g),e.values.y+Sf(l,g)];v?i.push({marker:e.marker,values:e.values}):i.push({marker:e.marker,values:{x:parseFloat(t[0].toFixed(3)),y:parseFloat(t[1].toFixed(3))}}),!v&&(s.marker===`L`||s.marker===`M`)&&i.push({marker:`A`,radius:m,values:{radiusX:parseFloat(m.toFixed(3)),radiusY:parseFloat(m.toFixed(3)),rotation:d,largeArc:0,sweep:_,x:parseFloat(n[0].toFixed(3)),y:parseFloat(n[1].toFixed(3))}});break;case`C`:case`S`:case`Q`:case`T`:case`A`:case`Z`:i.push({marker:e.marker,values:e.values});break}})}),{path:Ef(i),commands:i}}var kf=kf||{};kf.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_conic-gradient":function(t){return e.visit_gradient(t)},"visit_repeating-conic-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&&(t.hasAtKeyword?n+=`at `+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_rem:function(e){return e.value+`rem`},visit_vw:function(e){return e.value+`vw`},visit_vh:function(e){return e.value+`vh`},visit_vmin:function(e){return e.value+`vmin`},visit_vmax:function(e){return e.value+`vmax`},visit_ch:function(e){return e.value+`ch`},visit_ex:function(e){return e.value+`ex`},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);i&&(r+=` `+i);var a=e.visit(n.length2);return a&&(r+=` `+a),r},visit_angular:function(e){return e.value+(e.unit||`deg`)},visit_directional:function(e){return`to `+e.value},visit_conic:function(t){var n=``;return t.angle&&(n+=`from `+e.visit(t.angle)),t.at&&(n&&(n+=` `),n+=`at `+e.visit(t.at)),n},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)}})();var kf=kf||{};kf.parse=(function(){var 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,conicGradient:/^(\-(webkit|o|ms|moz)\-)?(conic\-gradient)/i,repeatingConicGradient:/^(\-(webkit|o|ms|moz)\-)?(repeating\-conic\-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:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))px/,percentageValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))\%/,emValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))em/,remValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))rem/,vwValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))vw/,vhValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))vh/,vminValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))vmin/,vmaxValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))vmax/,chValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))ch/,exValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))ex/,angleValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,radianValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))rad/,gradianValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))grad/,turnValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))turn/,startCall:/^\(/,endCall:/^\)/,comma:/^,/,slash:/^\//,hexColor:/^\#([0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{4}|[0-9a-fA-F]{3})(?![0-9a-fA-F])/,literalColor:/^([a-zA-Z]+)/,rgbColor:/^rgb/i,rgbaColor:/^rgba/i,varColor:/^var/i,calcValue:/^calc/i,variableName:/^(--[a-zA-Z0-9-,\s\#]+)/,number:/^(([0-9]*\.[0-9]+)|([0-9]+\.?))/,hslColor:/^hsl/i,hslaColor:/^hsla/i},t=``;function n(e){var n=Error(t+`: `+e);throw n.source=t,n}function r(){var e=i();return t.length>0&&n(`Invalid input not EOF`),e}function i(){return S(a)}function a(){return o(`linear-gradient`,e.linearGradient,c)||o(`repeating-linear-gradient`,e.repeatingLinearGradient,c)||o(`radial-gradient`,e.radialGradient,m)||o(`repeating-radial-gradient`,e.repeatingRadialGradient,m)||o(`conic-gradient`,e.conicGradient,l)||o(`repeating-conic-gradient`,e.repeatingConicGradient,l)}function o(t,r,i){return s(r,function(r){var a=i();return a&&(I(e.comma)||n(`Missing comma before color stops`)),{type:t,orientation:a,colorStops:S(C)}})}function s(t,r){var i=I(t);if(i){I(e.startCall)||n(`Missing (`);var a=r(i);return I(e.endCall)||n(`Missing )`),a}}function c(){var t=d();if(t)return t;var n=ie(`position-keyword`,e.positionKeywords,1);return n?{type:`directional`,value:n.value}:f()}function l(){var e=u(),t=y();if(e||t)return{type:`conic`,angle:e||void 0,at:t||void 0}}function u(){if(ie(`from`,/^from/,0)){var e=f();return e||n(`Missing angle after "from" in conic-gradient`),e}}function d(){return ie(`directional`,e.sideOrCorner,1)}function f(){return p(`deg`,e.angleValue)||p(`rad`,e.radianValue)||p(`grad`,e.gradianValue)||p(`turn`,e.turnValue)}function p(e,t){var n=I(t);if(n)return{type:`angular`,value:n[1],unit:e}}function m(){var n,r=h(),i;return r&&(n=[],n.push(r),i=t,I(e.comma)&&(r=h(),r?n.push(r):t=i)),n}function h(){var e=g()||_();if(e)e.at=y();else{var t=v();if(t){e=t;var n=y();n&&(e.at=n)}else{var r=y();if(r)e={type:`default-radial`,at:r,hasAtKeyword:!0};else{var i=b();i&&(e={type:`default-radial`,at:i})}}}return e}function g(){var e=ie(`shape`,/^(circle)/i,0);return e&&(e.style=re()||v()),e}function _(){var e=ie(`shape`,/^(ellipse)/i,0);return e&&(e.style=b()||ee()||v()),e}function v(){return ie(`extent-keyword`,e.extentKeywords,1)}function y(){if(ie(`position`,/^at/,0)){var e=b();return e||n(`Missing positioning value`),e}}function b(){var e=x();if(e.x||e.y)return{type:`position`,value:e}}function x(){return{x:ee(),y:ee()}}function S(t){var 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 C(){var e=w();return e||n(`Expected color definition`),e.length=ee(),e.length&&(e.length2=ee()),e}function w(){return E()||M()||j()||O()||D()||A()||T()}function T(){return ie(`literal`,e.literalColor,0)}function E(){return ie(`hex`,e.hexColor,1)}function D(){return s(e.rgbColor,function(){return k(`rgb`)})}function O(){return s(e.rgbaColor,function(){return k(`rgba`)})}function k(t){var n=F();if(I(e.comma)){var r=F();I(e.comma);var i=F(),a=[n,r,i];return I(e.comma)?(a.push(F()),{type:`rgba`,value:a}):{type:t,value:a}}else{var r=F(),i=F(),a=[n,r,i];return I(e.slash)?(a.push(F()),{type:`rgba`,value:a}):{type:t,value:a}}}function A(){return s(e.varColor,function(){return{type:`var`,value:P()}})}function j(){return s(e.hslColor,function(){return N(`hsl`)})}function M(){return s(e.hslaColor,function(){return N(`hsla`)})}function N(t){I(e.percentageValue)&&n(`HSL hue value must be a number in degrees (0-360) or normalized (-360 to 360), not a percentage`);var r=F();if(I(e.comma)){var i=I(e.percentageValue),a=i?i[1]:null;I(e.comma),i=I(e.percentageValue);var o=i?i[1]:null;if((!a||!o)&&n(`Expected percentage value for saturation and lightness in HSL`),I(e.comma)){var s=F();return{type:`hsla`,value:[r,a,o,s]}}return{type:t,value:[r,a,o]}}else{var i=I(e.percentageValue),a=i?i[1]:null;i=I(e.percentageValue);var o=i?i[1]:null;if((!a||!o)&&n(`Expected percentage value for saturation and lightness in HSL`),I(e.slash)){var s=F();return{type:`hsla`,value:[r,a,o,s]}}return{type:t,value:[r,a,o]}}}function P(){return I(e.variableName)[1]}function F(){return I(e.number)[1]}function ee(){return ie(`%`,e.percentageValue,1)||te()||ne()||re()}function te(){return ie(`position-keyword`,e.positionKeywords,1)}function ne(){return s(e.calcValue,function(){for(var e=1,r=0;e>0&&r<t.length;){var i=t.charAt(r);i===`(`?e++:i===`)`&&e--,r++}e>0&&n(`Missing closing parenthesis in calc() expression`);var a=t.substring(0,r-1);return ae(r-1),{type:`calc`,value:a}})}function re(){return ie(`px`,e.pixelValue,1)||ie(`em`,e.emValue,1)||ie(`rem`,e.remValue,1)||ie(`vw`,e.vwValue,1)||ie(`vh`,e.vhValue,1)||ie(`vmin`,e.vminValue,1)||ie(`vmax`,e.vmaxValue,1)||ie(`ch`,e.chValue,1)||ie(`ex`,e.exValue,1)}function ie(e,t,n){var r=I(t);if(r)return{type:e,value:r[n]}}function I(e){var n,r=/^[\n\r\t\s]+/.exec(t);return r&&ae(r[0].length),n=e.exec(t),n&&ae(n[0].length),n}function ae(e){t=t.substring(e)}return function(e){return t=e.toString().trim(),t.endsWith(`;`)&&(t=t.slice(0,-1)),r()}})(),kf.parse,kf.stringify;var Af={parse:kf.parse,stringify:kf.stringify},jf=e=>e.indexOf(`linear-gradient`)>=0,Mf=e=>e.type===`hex`?`#`+e.value:e.type===`literal`?e.value:`${e.type}(${e.value.join(`,`)})`,Nf=e=>{if(!jf(e))return{rotation:0,stops:[{offset:0,color:e},{offset:1,color:e}]};let t=Af.parse(e)[0];return{rotation:t.orientation&&`value`in t.orientation?parseFloat(t.orientation.value):0,stops:t.colorStops.map((e,n)=>({color:Mf(e),offset:e.length?parseFloat(e.length.value)/100:n/(t.colorStops.length-1)}))}},Pf=(e,t,n)=>(t===void 0&&(t=e.fill??``),n===void 0&&(n=`fill`),d.useMemo(()=>{if(!jf(t))return{[n]:t};let{stops:r,rotation:i}=Nf(t),a=e.a.width/2,o=e.a.height/2,s=(i%180+180)%180,c=s>45&&s<135?e.a.width:e.a.height,l=Du.Util.degToRad(i)-Math.PI/2,u=[];return r.forEach(({offset:e,color:t})=>{u.push(e,t)}),n===`fill`?{fillLinearGradientStartPointX:a-c/2*Math.cos(l),fillLinearGradientStartPointY:o-c/2*Math.sin(l),fillLinearGradientColorStops:u,fillLinearGradientEndPointX:a+c/2*Math.cos(l),fillLinearGradientEndPointY:o+c/2*Math.sin(l),fill:r[1].color,fillPriority:`linear-gradient`}:{strokeLinearGradientStartPointX:a-c/2*Math.cos(l),strokeLinearGradientStartPointY:o-c/2*Math.sin(l),strokeLinearGradientColorStops:u,strokeLinearGradientEndPointX:a+c/2*Math.cos(l),strokeLinearGradientEndPointY:o+c/2*Math.sin(l)}},[t,e.width,e.height])),Ff=!1,If=(e=!Ff)=>{Ff=e},Lf=()=>Ff;function Rf(e,t){let n=d.useRef();d.useLayoutEffect(()=>{n.current&&n.current.destroy()},[t]),d.useLayoutEffect(()=>{if(!Ff)return;let t=e.current.opacity();return t?(e.current.opacity(0),n.current=new Du.Tween({node:e.current,opacity:t,onFinish:()=>{var e;(e=n.current)==null||e.destroy()}}),n.current.play(),()=>{var e;(e=n.current)==null||e.destroy()}):void 0},[])}var zf=0,Bf=[],Vf=3e4,Hf=e=>{Vf=e},Uf=6e3,Wf=e=>{Uf=e},Gf=()=>Uf;function Kf(e){zf+=1;let t=!1,n=!1,r=setTimeout(()=>{t||(Zf(`Timeout loading asset ${e}`),console.error(`Timeout triggered for loader. Some assets may not have loaded.`,e),t=!0,qf())},Vf);return()=>{n?console.error(`Finish called twice! That is not expected. id: `,e):(n=!0,t||(clearTimeout(r),qf()))}}function qf(){--zf,zf===0&&(Bf.forEach(e=>e()),Bf=[])}function Jf(){return new Promise(e=>{t=()=>{Lf()?setTimeout(e,300):e(!0)},zf===0?t():Bf.push(t);return;var t})}var Yf=[];function Xf(e){Yf.push(e)}function Zf(e){Yf.forEach(t=>t(e))}function Qf(e=``){return(e.match(/<\/p>/gi)||[]).length>1&&(e=e.replace(/<\/p>/gi,(e,t,n)=>(n.slice(t+e.length).match(/<\/p>/gi)||[]).length>0?`
43
- `:e)),e.replace(/(<([^>]+)>)/gi,``).replace(/&amp;/g,`&`).replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&quot;/g,`"`).replace(/&apos;/g,`'`).replace(/&nbsp;/g,` `)}function $f(e,t){return!!e.bold==!!t.bold&&!!e.italic==!!t.italic&&!!e.underline==!!t.underline&&!!e.strike==!!t.strike&&(e.color||``)===(t.color||``)}function ep(e){if(!e)return[];let t=new DOMParser().parseFromString(e,`text/html`),n=[],r=t.body.querySelectorAll(`p`);function i(e,t){if(e.nodeType===Node.TEXT_NODE){let r=e.textContent||``;r&&n.push(function(e,t){let n={text:e};return t.bold&&(n.bold=!0),t.italic&&(n.italic=!0),t.underline&&(n.underline=!0),t.strike&&(n.strike=!0),t.color&&(n.color=t.color),n}(r,t));return}if(e.nodeType!==Node.ELEMENT_NODE)return;let r=e,a=r.tagName.toLowerCase(),o=Object.assign({},t);a!==`strong`&&a!==`b`||(o.bold=!0),a!==`em`&&a!==`i`||(o.italic=!0),a===`u`&&(o.underline=!0),a===`s`&&(o.strike=!0);let s=r.style;s.color&&(o.color=s.color),(s.fontWeight===`bold`||parseInt(s.fontWeight)>=700)&&(o.bold=!0),s.fontStyle===`italic`&&(o.italic=!0);let c=s.textDecoration||s.textDecorationLine||``;c.includes(`underline`)&&(o.underline=!0),c.includes(`line-through`)&&(o.strike=!0);for(let e of Array.from(r.childNodes))i(e,o)}r.length>0?r.forEach((e,t)=>{i(e,{}),t<r.length-1&&n.push({text:` `})}):i(t.body,{});let a=[];for(let e of n){if(!e.text)continue;let t=a[a.length-1];t&&$f(t,e)?t.text+=e.text:a.push(e)}return a}function tp(e){return e?/<[a-z][a-z0-9]*(\s[^>]*)?>[^<]*<\/[a-z][a-z0-9]*>/i.test(e)?e=(e=e.replace(/<(?![a-z/!])/gi,`&lt;`)).replace(/([^a-z0-9"'\s/])>/gi,`$1&gt;`):e.replace(/</g,`&lt;`).replace(/>/g,`&gt;`):``}L([`Roboto`,`Amatic SC`,`Press Start 2P`,`Marck Script`,`Rubik Mono One`]),L({value:!1});var np=L([]);function rp(e){np.push(e)}var ip=`BESbswy 0123456789 Il1Ww`;function ap(e){let t=function(e=``){let t=Qf(e).replace(/\s+/g,` `).trim();return t?Array.from(t).slice(0,10).join(``):``}(e);return t?`${ip} ${t}`:ip}var op;function sp(e,t=`sans-serif`,n=`normal`,r=`normal`,i=ip){op||=document.createElement(`canvas`);var a=op.getContext(`2d`);return a.font=`${n} ${r} 40px '${e}', ${t}`,a.measureText(i).width}var cp={Arial:!0},lp=(e,t,n)=>t&&n?!!cp[`${e}_${t}_${n}`]:Object.keys(cp).some(t=>t.startsWith(e+`_`))||!!cp[e];async function up(e,t,n,r){let i=`${e}_${t}_${n}`;if(cp[i])return;let a=!!document.fonts?.load,o=ap(r),s=function(e=`normal`,t=`normal`,n=ip){op||=document.createElement(`canvas`);var r=op.getContext(`2d`);return r.font=`${e} ${t} 40px sans-serif`,r.measureText(n).width}(t,n,o);if(a)try{if(await document.fonts.load(`${t} ${n} 16px '${e}'`,o),s!==sp(e,`sans-serif`,t,n,o)){cp[i]=!0;return}}catch{}let c=function(e=`normal`,t=`normal`,n=ip){op||=document.createElement(`canvas`);var r=op.getContext(`2d`);return r.font=`${e} ${t} 40px serif`,r.measureText(n).width}(t,n,o),l=sp(e,`sans-serif`,t,n,o),u=Math.min(6e3,Gf())/60;for(let r=0;r<u;r++){let r=sp(e,`sans-serif`,t,n,o),a=sp(e,`serif`,t,n,o);if(r!==l||r!==s||a!==c){await new Promise(e=>setTimeout(e,100)),cp[i]=!0;return}await new Promise(e=>setTimeout(e,60))}console.warn(`Timeout for loading font "${e}". Looks like polotno can't load it. Is it a correct font family?`),Zf(`Timeout for loading font "${e}"`)}var dp={},fp=`400,400italic,700,700italic`;function pp(){return fp}function mp(e){return`https://fonts.googleapis.com/css?family=${e.replace(/ /g,`+`)}:${fp}`}function hp(e){if(dp[e])return;let t=mp(e),n=document.createElement(`link`);n.type=`text/css`,n.href=t,n.rel=`stylesheet`,document.getElementsByTagName(`head`)[0].appendChild(n),dp[e]=!0}var gp={},_p;function vp(e){let t=e.fontFamily;if(gp[t]||!e.url&&!e.styles)return;let n=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]),r=(_p||(_p=document.getElementById(`polotno-font-style`),_p||(_p=document.createElement(`style`),_p.id=`polotno-font-style`,document.head.appendChild(_p)),_p)).sheet;n.forEach(e=>{r.insertRule(`\n @font-face{\n font-family:'${t}';\n src:${e.src};\n font-style:${e.fontStyle||`normal`};\n font-weight:${e.fontWeight||`normal`};\n font-display:swap; /* optional but recommended */\n }`,r.cssRules.length)}),gp[e.fontFamily]=!0}var yp=L({imageDownScalingEnabled:!0,removeBackgroundEnabled:!1,htmlRenderEnabled:!1,forceTextFitEnabled:!1,textVerticalResizeEnabled:!1,textOverflow:`resize`,textSplitAllowed:!1,animationsEnabled:!1,aiTextEnabled:!1,autoDeleteEmptyText:!0}),bp=typeof window<`u`&&window.location.hostname===`localhost`||typeof process<`u`&&!1,xp=Vn(e=>{yp.textVerticalResizeEnabled=e}),Sp=Vn(e=>{yp.removeBackgroundEnabled=e});Vn(e=>{bp&&console.warn(`useRemoveBackground is deprecated. Use setRemoveBackgroundEnabled instead.`),Sp(e)}),Vn(e=>{yp.aiTextEnabled=e}),Vn(e=>{bp&&console.warn(`useHtmlTextRender is deprecated. Use setRichTextEnabled instead.`),yp.htmlRenderEnabled=e});var Cp=Vn(e=>{yp.htmlRenderEnabled=e}),wp=Vn(e=>{yp.imageDownScalingEnabled=e});Vn(e=>{console.warn(`useDownScaling is deprecated. Use setDownScalingEnabled instead.`),wp(e)}),Vn(e=>{console.warn(`setForceTextFit is deprecated. Use setTextOverflow instead.`),yp.textOverflow=`change-font-size`});var Tp=Vn(e=>{yp.textOverflow=e}),Ep=Vn(e=>{yp.textSplitAllowed=e});Vn(e=>{yp.animationsEnabled=e}),Vn(e=>{yp.autoDeleteEmptyText=e});var Dp={fontSize:14,fontFamily:`Roboto`,fontWeight:`normal`,fontStyle:`normal`,lineHeight:1.2,letterSpacing:0,textTransform:`none`,textDecoration:``,align:`center`,fill:`black`,stroke:`black`,strokeWidth:0,curveEnabled:!1,curvePower:.5};function Op(e){return Object.assign(Object.assign({},Dp),e)}function kp(e){var t=`֑-߿‏‫‮יִ-﷽ﹰ-ﻼ`;return RegExp(`^[^`+t+`]*?[`+t+`]`).test(e)}function Ap(e){return function(e){e=e.replace(/\s/g,``);let t=0;for(var n=0;n<e.length;n++)kp(e[n])&&(t+=1);return t>e.length/2}(e)?`rtl`:`ltr`}function jp(e,t,n,r){let i=Math.max(-.9999,Math.min(.9999,n));if(Math.abs(i)<1e-4)return`M 0 ${t/2} L ${e} ${t/2}`;let a=5*r/(2*Math.abs(i))-r,o=e/2;if(i>0){let e=2*a+r/2;return[`M ${o} ${e}`,`A ${a} ${a} 0 1 1 ${o} ${e-2*a}`,`A ${a} ${a} 0 1 1 ${o} ${e}`].join(` `)}{let e=-(2*a-Math.round(t))-r/2;return[`M ${o} ${e}`,`A ${a} ${a} 0 1 0 ${o} ${e+2*a}`,`A ${a} ${a} 0 1 0 ${o} ${e}`].join(` `)}}function Mp(e,t,n,r){if(!jf(e))return``;let{stops:i,rotation:a}=Nf(e),o=a*Math.PI/180;return`<linearGradient id="${t}" x1="${100*(.5-.5*Math.sin(o))}%" y1="${100*(.5+.5*Math.cos(o))}%" x2="${100*(.5+.5*Math.sin(o))}%" y2="${100*(.5-.5*Math.cos(o))}%">${i.map(({offset:e,color:t})=>`<stop offset="${100*e}%" stop-color="${t}" />`).join(``)}</linearGradient>`}function Np(e){let t=e.a?e.a:e,n=Op(e),r=t.fontSize??n.fontSize,i=new Du.TextPath({data:jp(t.width??n.width,t.height??n.height??0,n.curvePower,r),align:`center`,textBaseline:`middle`,text:Qf(n.text),fontSize:r,fontFamily:n.fontFamily,fontWeight:n.fontWeight,fontStyle:n.fontStyle,letterSpacing:n.letterSpacing*r,fill:n.fill}),a=i.getSelfRect().height||r;return i.destroy(),a}function Pp(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function Fp(e,t,n){return e.map(e=>{let r=[];e.bold&&t.fontWeight!==`bold`&&r.push(`font-weight="bold"`),e.italic&&t.fontStyle!==`italic`&&r.push(`font-style="italic"`),e.underline&&r.push(`text-decoration="underline"`),e.strike&&r.push(`text-decoration="line-through"`),!n?.omitColors&&e.color&&e.color!==t.fill&&r.push(`fill="${Pp(e.color)}"`);let i=Pp(e.text);return r.length===0?i:`<tspan ${r.join(` `)}>${i}</tspan>`}).join(``)}function Ip(e,{fontFamily:t=``,color:n=`black`,forEditor:r=!1}={}){let i=Op(e),a=t||i.fontFamily,o=jf(i.fill),s=jf(i.stroke),c=yp.textOverflow===`ellipsis`&&!r&&!i.curveEnabled&&!!i.height,l=(()=>{if(!c)return[];let e=Math.max(1,Math.round(i.height)),t=typeof i.lineHeight==`number`?i.lineHeight:1.2,n=Math.max(1,t*i.fontSize),r=Math.max(1,Math.floor(e/n));return[`max-height: ${e}px`,`overflow: hidden`,`display: -webkit-box`,`-webkit-box-orient: vertical`,`-webkit-line-clamp: ${r}`,`line-clamp: ${r}`]})(),u=e=>`\n background-image: ${e};\n background-size: 100% 100%;\n background-repeat: repeat;\n -webkit-background-clip: text;\n -moz-background-clip: text;\n background-clip: text;\n -webkit-text-fill-color: transparent;\n color: transparent\n `.trim(),d=`color: ${n||i.fill}`,f=``;s&&i.strokeWidth?(d=`color: ${n||i.fill}; ${u(i.stroke)}`,f=`-webkit-text-stroke: ${i.strokeWidth}px transparent`):o&&(d=u(i.fill));let p=[`white-space: pre-wrap`,`word-break: break-word`,`width: ${Math.round(i.width||100)}px`,...l,d,`font-size: ${i.fontSize}px`,`font-family: '${a}'`,`text-align: ${i.align}`,`text-transform: ${i.textTransform}`,i.textDecoration?`text-decoration: ${i.textDecoration}; text-decoration-color: ${n||i.fill}; text-decoration-layer: over`:``,i.lineHeight?`line-height: ${i.lineHeight}`:``,i.letterSpacing?`letter-spacing: ${i.letterSpacing*i.fontSize}px`:``,i.fontStyle?`font-style: ${i.fontStyle}`:``,i.fontWeight?`font-weight: ${i.fontWeight}`:``,f||(i.strokeWidth?`-webkit-text-stroke: ${i.strokeWidth}px ${i.stroke}`:``),i.strokeWidth&&!s?`paint-order: stroke fill`:``].filter(Boolean).join(`; `);if(i.curveEnabled&&!r){let t=Np(e),r=Math.round(i.width||100),c=jp(r,t,i.curvePower,i.fontSize),l=ep(i.text),u={fontWeight:i.fontWeight||`normal`,fontStyle:i.fontStyle||`normal`,fill:n||i.fill||`black`},d=Fp(l,u),f=Fp(l,u,{omitColors:!0}),p=`curve-${i.id||`temp`}`,m=i.strokeWidth&&(s||o&&!s),h=`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${t}">\n <defs>\n <path id="${p}" d="${c}" fill="none" />`;if(o){let e=`curve-fill-grad-${i.id||`temp`}`;h+=Mp(i.fill,e,r,t)}if(s&&i.strokeWidth){let e=`curve-stroke-grad-${i.id||`temp`}`;h+=Mp(i.stroke,e,r,t)}if(h+=`</defs>`,m){let e=`\n font-family="'${a}'"\n font-size="${i.fontSize}"\n font-weight="${i.fontWeight}"\n font-style="${i.fontStyle}"\n text-anchor="middle"\n dominant-baseline="central"\n letter-spacing="${i.letterSpacing*i.fontSize}px"${i.textDecoration?` text-decoration="${i.textDecoration}"`:``}`,t=s?`url(#curve-stroke-grad-${i.id||`temp`})`:i.stroke;h+=`\n <text ${e} fill="${t}" stroke="${t}" stroke-width="${i.strokeWidth}">\n <textPath href="#${p}" startOffset="50%">${f}</textPath>\n </text>`,h+=`\n <text ${e} fill="${o?`url(#curve-fill-grad-${i.id||`temp`})`:n}">\n <textPath href="#${p}" startOffset="50%">${d}</textPath>\n </text>`}else{let e=o?`url(#curve-fill-grad-${i.id||`temp`})`:n,t=s?`url(#curve-stroke-grad-${i.id||`temp`})`:i.stroke;h+=`\n <text\n font-family="'${a}'"\n font-size="${i.fontSize}"\n font-weight="${i.fontWeight}"\n font-style="${i.fontStyle}"\n fill="${e}"\n text-anchor="middle"\n dominant-baseline="central"\n letter-spacing="${i.letterSpacing*i.fontSize}px"${i.textDecoration?` text-decoration="${i.textDecoration}"`:``}${i.strokeWidth?` stroke="${t}" stroke-width="${i.strokeWidth}" paint-order="stroke fill"`:``}>\n <textPath href="#${p}" startOffset="50%">${d}</textPath>\n </text>`}return h+=`</svg>`,h}if(i.strokeWidth&&(s||o&&!s)&&!r){let e=tp(i.text).replace(/\n/g,`<br/>`),t=Math.round(i.width||100),r=[`white-space: pre-wrap`,`word-break: break-word`,`width: ${t}px`,...l,`font-size: ${i.fontSize}px`,`font-family: '${a}'`,`text-align: ${i.align}`,`text-transform: ${i.textTransform}`,i.textDecoration?`text-decoration: ${i.textDecoration}; text-decoration-color: ${n||i.fill}; text-decoration-layer: over`:``,i.lineHeight?`line-height: ${i.lineHeight}`:``,i.letterSpacing?`letter-spacing: ${i.letterSpacing*i.fontSize}px`:``,i.fontStyle?`font-style: ${i.fontStyle}`:``,i.fontWeight?`font-weight: ${i.fontWeight}`:``].filter(Boolean).join(`; `),c;return c=s?`${r}; ${u(i.stroke)}; -webkit-text-stroke: ${i.strokeWidth}px transparent`:`${r}; color: transparent; -webkit-text-stroke: ${i.strokeWidth}px ${i.stroke}`,`\n <div style="position: relative; width: ${t}px;">\n <div style="${c}; position: absolute; top: 0; left: 0; pointer-events: none;" aria-hidden="true">${e}</div>\n <div style="${r}; ${o?u(i.fill):`color: ${n||i.fill}`}; position: relative;" contentEditable dir="${Ap(Qf(i.text))}">${e}</div>\n </div>\n `}return`<div style="${p}" contentEditable dir="${Ap(Qf(i.text))}">${tp(i.text).replace(/\n/g,`</br>`)}</div>`}function Lp({fontFamily:e,fontSize:t,lineHeight:n}){if(typeof n==`number`)return n;let r=document.createElement(`div`);r.style.fontFamily=e,r.style.fontSize=t+`px`,r.style.lineHeight=n,r.innerText=`Test text`,document.body.appendChild(r);let i=r.offsetHeight;return document.body.removeChild(r),i/t}var Rp={warm:e=>t=>{let n=t.data;e=Math.max(0,Math.min(1,e));for(let t=0;t<n.length;t+=4)n[t]=Math.min(n[t]+30*e,255),n[t+1]=Math.min(n[t+1]+15*e,255);return t},cold:e=>t=>{let n=t.data;e=Math.max(0,Math.min(1,e));for(let t=0;t<n.length;t+=4)n[t]=Math.min(n[t]-15*e,255),n[t+1]=Math.min(n[t+1]-10*e,255),n[t+2]=Math.min(n[t+2]+15*e,255);return t},natural:e=>t=>{let n=t.data;e=Math.max(0,Math.min(1,e));for(let t=0;t<n.length;t+=4){n[t]=Math.min(n[t]*(1+.1*e),255),n[t+1]=Math.min(n[t+1]*(1+.1*e),255),n[t+2]=Math.min(n[t+2]*(1+.1*e),255);let r=(n[t]+n[t+1]+n[t+2])/3;n[t]=Math.min((n[t]-r)*(1+.2*e)+r,255),n[t+1]=Math.min((n[t+1]-r)*(1+.2*e)+r,255),n[t+2]=Math.min((n[t+2]-r)*(1+.2*e)+r,255)}return t},temperature:e=>t=>{let n=t.data;e=Math.max(-1,Math.min(1,e));for(let t=0;t<n.length;t+=4){let r=n[t],i=(n[t+1],n[t+2]);n[t]=Math.min(Math.max(r+15*e,0),255),n[t+2]=Math.min(Math.max(i-15*e,0),255)}return t},contrast:e=>t=>{let n=t.data,r=100*(e=Math.max(-1,Math.min(1,e))),i=259*(r+255)/(255*(259-r));for(let e=0;e<n.length;e+=4)n[e]=Math.min(Math.max(i*(n[e]-128)+128,0),255),n[e+1]=Math.min(Math.max(i*(n[e+1]-128)+128,0),255),n[e+2]=Math.min(Math.max(i*(n[e+2]-128)+128,0),255);return t},shadows:e=>t=>{let n=t.data;e=Math.max(-1,Math.min(1,e));for(let t=0;t<n.length;t+=4){let r=(n[t]+n[t+1]+n[t+2])/3;if(r<128){let i=1+e*(1-r/128)*2;n[t]=Math.min(Math.max(n[t]*i,0),255),n[t+1]=Math.min(Math.max(n[t+1]*i,0),255),n[t+2]=Math.min(Math.max(n[t+2]*i,0),255)}}return t},white:e=>t=>{let n=t.data;e=Math.max(-1,Math.min(1,e));for(let t=0;t<n.length;t+=4){let r=n[t],i=n[t+1],a=n[t+2],o=(r+i+a)/3;if(o>128){let s=1+e*((o-128)/127);n[t]=Math.min(Math.max(r*s,0),255),n[t+1]=Math.min(Math.max(i*s,0),255),n[t+2]=Math.min(Math.max(a*s,0),255)}}return t},black:e=>t=>{let n=t.data;e=Math.max(-1,Math.min(1,e));for(let t=0;t<n.length;t+=4){let r=n[t],i=n[t+1],a=n[t+2],o=(r+i+a)/3;if(o<128){let s=1+e*((128-o)/128);n[t]=Math.min(Math.max(r*s,0),255),n[t+1]=Math.min(Math.max(i*s,0),255),n[t+2]=Math.min(Math.max(a*s,0),255)}}return t},vibrance:e=>t=>{let n=t.data;e=Math.max(-1,Math.min(1,e));for(let t=0;t<n.length;t+=4){let r=n[t],i=n[t+1],a=n[t+2],o=Math.max(r,i,a),s=e<0?(1-(o===0?0:(o-(r+i+a)/3)/o))*e*1.5:.5*e;n[t]=Math.min(Math.max(r-(o-r)*s,0),255),n[t+1]=Math.min(Math.max(i-(o-i)*s,0),255),n[t+2]=Math.min(Math.max(a-(o-a)*s,0),255)}return t},saturation:e=>t=>{let n=t.data;e=Math.max(-1,Math.min(1,e));for(let t=0;t<n.length;t+=4){let r=n[t],i=n[t+1],a=n[t+2],o=.2126*r+.7152*i+.0722*a;n[t]=Math.min(Math.max(o+(r-o)*(1+e),0),255),n[t+1]=Math.min(Math.max(o+(i-o)*(1+e),0),255),n[t+2]=Math.min(Math.max(o+(a-o)*(1+e),0),255)}return t}};function zp(e,t){var n;let r={filters:[]},i={};t.brightnessEnabled&&(r.filters.push(Du.Filters.Brighten),r.brightness=t.brightness),t.blurEnabled&&(r.filters.push(Du.Filters.Blur),r.blurRadius=t.blurRadius,t.type===`text`&&t.lineHeight<1&&(i.offset=t.fontSize)),t.sepiaEnabled&&r.filters.push(Du.Filters.Sepia),t.grayscaleEnabled&&r.filters.push(Du.Filters.Grayscale),t.filters.forEach((e,t)=>{let n=Rp[t];n&&r.filters.push(n(e.intensity))}),e.setAttrs(r),r.filters.length?e.cache(Object.assign(Object.assign({},i),{pixelRatio:t.store._elementsPixelRatio})):e.clearCache(),(n=e.getLayer())==null||n.batchDraw()}var Bp=()=>`ontouchstart`in window||navigator.maxTouchPoints>0,Vp=`warn`;function Hp(e){Vp=e}function Up(){return Vp}var Wp;(function(e){e.afterCreate=`afterCreate`,e.afterAttach=`afterAttach`,e.afterCreationFinalization=`afterCreationFinalization`,e.beforeDetach=`beforeDetach`,e.beforeDestroy=`beforeDestroy`})(Wp||={});var Gp=function(e,t){return Gp=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},Gp(e,t)};function Kp(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Class extends value `+String(t)+` is not a constructor or null`);Gp(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var qp=function(){return qp=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},qp.apply(this,arguments)};function Jp(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function Yp(e){var t=typeof Symbol==`function`&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length==`number`)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw TypeError(t?`Object is not iterable.`:`Symbol.iterator is not defined.`)}function Xp(e,t){var n=typeof Symbol==`function`&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),i,a=[],o;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(e){o={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a}function Zp(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}function Qp(e){return rh(e,1),ih(e).type}function $p(e,t){return rh(e,1),zh(t,2),ih(e).onSnapshot(t)}function em(e,t){rh(e,1),Rh(t,function(e){return typeof e==`object`},`object or array`,2),ih(e).applyPatches(yh(t))}function tm(e,t){return rh(e,1),ih(e).applySnapshot(t)}function nm(e,t){t===void 0&&(t=!0),rh(e,1);var n=ih(e);return t?n.snapshot:wh(n.type.getSnapshot(n,!1))}function rm(e,t){t===void 0&&(t=1),rh(e,1),Bh(t,2,0);for(var n=t,r=ih(e).parent;r;){if(--n===0)return r.storedValue;r=r.parent}throw new K(`Failed to find the parent of ${ih(e)} at depth ${t}`)}function im(e,t){rh(e,1),km(t,2);for(var n=ih(e).parent;n;){if(t.is(n.storedValue))return!0;n=n.parent}return!1}function am(e,t){rh(e,1),km(t,2);for(var n=ih(e).parent;n;){if(t.is(n.storedValue))return n.storedValue;n=n.parent}throw new K(`Failed to find the parent of ${ih(e)} of a given type`)}function om(e){return rh(e,1),ih(e).root.storedValue}function sm(e){return rh(e,1),ih(e).path}function cm(e,t){rh(e,1),Vh(t,2);var n=sh(ih(e),t);return n?n.value:void 0}function lm(e){return rh(e,1),ih(e).identifier}function um(e){return rh(e,1),ih(e).detach(),e}function dm(e){rh(e,1);var t=ih(e);t.isRoot?t.die():t.parent.removeChild(t.subpath)}function fm(e){return rh(e,1),ih(e).observableIsAlive}function pm(e){return e}var mm=function(){function e(e,t,n,r){Object.defineProperty(this,`type`,{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,`environment`,{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,`_escapedSubpath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`_subpath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`_subpathUponDeath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`_pathUponDeath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`storedValue`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`aliveAtom`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`_state`,{enumerable:!0,configurable:!0,writable:!0,value:th.INITIALIZING}),Object.defineProperty(this,`_hookSubscribers`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`_parent`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`pathAtom`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.environment=r,this.baseSetParent(t,n)}return Object.defineProperty(e.prototype,`subpath`,{get:function(){return this._subpath},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`subpathUponDeath`,{get:function(){return this._subpathUponDeath},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`pathUponDeath`,{get:function(){return this._pathUponDeath},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`value`,{get:function(){return this.type.getValue(this)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`state`,{get:function(){return this._state},set:function(e){var t=this.isAlive;this._state=e;var n=this.isAlive;this.aliveAtom&&t!==n&&this.aliveAtom.reportChanged()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`fireInternalHook`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._hookSubscribers&&this._hookSubscribers.emit(e,this,e)}}),Object.defineProperty(e.prototype,`registerHook`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this._hookSubscribers||=new jh,this._hookSubscribers.register(e,t)}}),Object.defineProperty(e.prototype,`parent`,{get:function(){return this._parent},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`getReconciliationType`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.type}}),Object.defineProperty(e.prototype,`baseSetParent`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){this._parent=e,this._subpath=t,this._escapedSubpath=void 0,this.pathAtom&&this.pathAtom.reportChanged()}}),Object.defineProperty(e.prototype,`path`,{get:function(){return this.getEscapedPath(!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`getEscapedPath`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e&&(this.pathAtom||=Ee(`path`),this.pathAtom.reportObserved()),this.parent?(this._escapedSubpath===void 0&&(this._escapedSubpath=this._subpath?Kh(this._subpath):``),this.parent.getEscapedPath(e)+`/`+this._escapedSubpath):``}}),Object.defineProperty(e.prototype,`isRoot`,{get:function(){return this.parent===null},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`isAlive`,{get:function(){return this.state!==th.DEAD},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`isDetaching`,{get:function(){return this.state===th.DETACHING},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`observableIsAlive`,{get:function(){return this.aliveAtom||=Ee(`alive`),this.aliveAtom.reportObserved(),this.isAlive},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`baseFinalizeCreation`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(Lh()&&!this.isAlive)throw new K(`assertion failed: cannot finalize the creation of a node that is already dead`);if(this.state===th.CREATED){if(this.parent){if(this.parent.state!==th.FINALIZED)return;this.fireHook(Wp.afterAttach)}this.state=th.FINALIZED,e&&e()}}}),Object.defineProperty(e.prototype,`baseFinalizeDeath`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this._hookSubscribers&&this._hookSubscribers.clearAll(),this._subpathUponDeath=this._subpath,this._pathUponDeath=this.getEscapedPath(!1),this.baseSetParent(null,``),this.state=th.DEAD}}),Object.defineProperty(e.prototype,`baseAboutToDie`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.fireHook(Wp.beforeDestroy)}}),e}(),hm=function(e){Kp(t,e);function t(t,n,r,i,a){var o=e.call(this,t,n,r,i)||this;try{o.storedValue=t.createNewInstance(a)}catch(e){throw o.state=th.DEAD,e}return o.state=th.CREATED,o.finalizeCreation(),o}return Object.defineProperty(t.prototype,`root`,{get:function(){if(!this.parent)throw new K(`This scalar node is not part of a tree`);return this.parent.root},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`setParent`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.parent!==e,r=this.subpath!==t;if(!(!n&&!r)){if(Lh()){if(!t)throw new K(`assertion failed: subpath expected`);if(!e)throw new K(`assertion failed: parent expected`);if(n)throw new K(`assertion failed: scalar nodes cannot change their parent`)}this.environment=void 0,this.baseSetParent(this.parent,t)}}}),Object.defineProperty(t.prototype,`snapshot`,{get:function(){return wh(this.getSnapshot())},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.type.getSnapshot(this)}}),Object.defineProperty(t.prototype,`toString`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=(this.isAlive?this.path:this.pathUponDeath)||`<root>`;return`${this.type.name}@${e}${this.isAlive?``:` [dead]`}`}}),Object.defineProperty(t.prototype,`die`,{enumerable:!1,configurable:!0,writable:!0,value:function(){!this.isAlive||this.state===th.DETACHING||(this.aboutToDie(),this.finalizeDeath())}}),Object.defineProperty(t.prototype,`finalizeCreation`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.baseFinalizeCreation()}}),Object.defineProperty(t.prototype,`aboutToDie`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.baseAboutToDie()}}),Object.defineProperty(t.prototype,`finalizeDeath`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.baseFinalizeDeath()}}),Object.defineProperty(t.prototype,`fireHook`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.fireInternalHook(e)}}),t}(mm);hm.prototype.die=Vn(hm.prototype.die);var gm=1,_m;(function(e){e[e.UNINITIALIZED=0]=`UNINITIALIZED`,e[e.CREATING=1]=`CREATING`,e[e.CREATED=2]=`CREATED`})(_m||={});var vm;(function(e){e.Dispose=`dispose`,e.Patch=`patch`,e.Snapshot=`snapshot`})(vm||={});var ym={onError:function(e){throw e}},bm=function(e){Kp(t,e);function t(t,n,r,i,a){var o=e.call(this,t,n,r,i)||this;if(Object.defineProperty(o,`nodeId`,{enumerable:!0,configurable:!0,writable:!0,value:++gm}),Object.defineProperty(o,`identifierAttribute`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`identifier`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`unnormalizedIdentifier`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`identifierCache`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`isProtectionEnabled`,{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(o,`middlewares`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`hasSnapshotPostProcessor`,{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(o,`_applyPatches`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_applySnapshot`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_autoUnbox`,{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(o,`_isRunningAction`,{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(o,`_hasSnapshotReaction`,{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(o,`_observableInstanceState`,{enumerable:!0,configurable:!0,writable:!0,value:_m.UNINITIALIZED}),Object.defineProperty(o,`_childNodes`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_initialSnapshot`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_cachedInitialSnapshot`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_cachedInitialSnapshotCreated`,{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(o,`_snapshotComputed`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_snapshotUponDeath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_internalEvents`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),o._snapshotComputed=jt(function(){return wh(o.getSnapshot())}),o.unbox=o.unbox.bind(o),o._initialSnapshot=wh(a),o.identifierAttribute=t.identifierAttribute,n||(o.identifierCache=new Zm),o._childNodes=t.initializeChildNodes(o,o._initialSnapshot),o.identifier=null,o.unnormalizedIdentifier=null,o.identifierAttribute&&o._initialSnapshot){var s=o._initialSnapshot[o.identifierAttribute];if(s===void 0){var c=o._childNodes[o.identifierAttribute];c&&(s=c.value)}if(typeof s!=`string`&&typeof s!=`number`)throw new K(`Instance identifier '${o.identifierAttribute}' for type '${o.type.name}' must be a string or a number`);o.identifier=h_(s),o.unnormalizedIdentifier=s}return n?n.root.identifierCache.addNodeToCache(o):o.identifierCache.addNodeToCache(o),o}return Object.defineProperty(t.prototype,`applyPatches`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.createObservableInstanceIfNeeded(),this._applyPatches(e)}}),Object.defineProperty(t.prototype,`applySnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.createObservableInstanceIfNeeded(),this._applySnapshot(e)}}),Object.defineProperty(t.prototype,`createObservableInstanceIfNeeded`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){e===void 0&&(e=!0),this._observableInstanceState===_m.UNINITIALIZED&&this.createObservableInstance(e)}}),Object.defineProperty(t.prototype,`createObservableInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t,n,r,i;if(e===void 0&&(e=!0),Lh()&&this.state!==th.INITIALIZING)throw new K(`assertion failed: the creation of the observable instance must be done on the initializing phase`);this._observableInstanceState=_m.CREATING;for(var a=[],o=this.parent;o&&o._observableInstanceState===_m.UNINITIALIZED;)a.unshift(o),o=o.parent;try{for(var s=Yp(a),c=s.next();!c.done;c=s.next()){var l=c.value;l.createObservableInstanceIfNeeded(!1)}}catch(e){t={error:e}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}var u=this.type;try{this.storedValue=u.createNewInstance(this._childNodes),this.preboot(),this._isRunningAction=!0,u.finalizeNewInstance(this,this.storedValue)}catch(e){throw this.state=th.DEAD,e}finally{this._isRunningAction=!1}if(this._observableInstanceState=_m.CREATED,this._snapshotComputed.trackAndCompute(),this.isRoot&&this._addSnapshotReaction(),this._childNodes=fh,this.state=th.CREATED,e){this.fireHook(Wp.afterCreate),this.finalizeCreation();try{for(var d=Yp(a.reverse()),f=d.next();!f.done;f=d.next()){var l=f.value;l.fireHook(Wp.afterCreate),l.finalizeCreation()}}catch(e){r={error:e}}finally{try{f&&!f.done&&(i=d.return)&&i.call(d)}finally{if(r)throw r.error}}}}}),Object.defineProperty(t.prototype,`root`,{get:function(){var e=this.parent;return e?e.root:this},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`clearParent`,{enumerable:!1,configurable:!0,writable:!0,value:function(){if(this.parent){this.fireHook(Wp.beforeDetach);var e=this.state;this.state=th.DETACHING;var t=this.root,n=t.environment,r=t.identifierCache.splitCache(this);try{this.parent.removeChild(this.subpath),this.baseSetParent(null,``),this.environment=n,this.identifierCache=r}finally{this.state=e}}}}),Object.defineProperty(t.prototype,`setParent`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=e!==this.parent,r=t!==this.subpath;if(!(!n&&!r)){if(Lh()){if(!t)throw new K(`assertion failed: subpath expected`);if(!e)throw new K(`assertion failed: new parent expected`);if(this.parent&&n)throw new K(`A node cannot exists twice in the state tree. Failed to add ${this} to path '${e.path}/${t}'.`);if(!this.parent&&e.root===this)throw new K(`A state tree is not allowed to contain itself. Cannot assign ${this} to path '${e.path}/${t}'`);if(!this.parent&&this.environment&&this.environment!==e.root.environment)throw new K(`A state tree cannot be made part of another state tree as long as their environments are different.`)}n?(this.environment=void 0,e.root.identifierCache.mergeCache(this),this.baseSetParent(e,t),this.fireHook(Wp.afterAttach)):r&&this.baseSetParent(this.parent,t)}}}),Object.defineProperty(t.prototype,`fireHook`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this.fireInternalHook(e);var n=this.storedValue&&typeof this.storedValue==`object`&&this.storedValue[e];typeof n==`function`&&(Un?Un(function(){n.apply(t.storedValue)}):n.apply(this.storedValue))}}),Object.defineProperty(t.prototype,`snapshot`,{get:function(){return this.hasSnapshotPostProcessor&&this.createObservableInstanceIfNeeded(),this._snapshotComputed.get()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.isAlive?this._observableInstanceState===_m.CREATED?this._getActualSnapshot():this._getCachedInitialSnapshot():this._snapshotUponDeath}}),Object.defineProperty(t.prototype,`_getActualSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.type.getSnapshot(this)}}),Object.defineProperty(t.prototype,`_getCachedInitialSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){if(!this._cachedInitialSnapshotCreated){var e=this.type,t=this._childNodes,n=this._initialSnapshot;this._cachedInitialSnapshot=e.processInitialSnapshot(t,n),this._cachedInitialSnapshotCreated=!0}return this._cachedInitialSnapshot}}),Object.defineProperty(t.prototype,`isRunningAction`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._isRunningAction?!0:this.isRoot?!1:this.parent.isRunningAction()}}),Object.defineProperty(t.prototype,`assertAlive`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=Up();if(!this.isAlive&&t!==`ignore`){var n=this._getAssertAliveError(e);switch(t){case`error`:throw new K(n);case`warn`:Fh(n)}}}}),Object.defineProperty(t.prototype,`_getAssertAliveError`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.getEscapedPath(!1)||this.pathUponDeath||``,n=e.subpath&&Kh(e.subpath)||``,r=e.actionContext||Mm();r&&r.type!==`action`&&r.parentActionEvent&&(r=r.parentActionEvent);var i=``;return r&&r.name!=null&&(i=`${r&&r.context&&sm(r.context)||t}.${r.name}()`),`You are trying to read or write to an object that is no longer part of a state tree. (Object type: '${this.type.name}', Path upon death: '${t}', Subpath: '${n}', Action: '${i}'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.`}}),Object.defineProperty(t.prototype,`getChildNode`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.assertAlive({subpath:e}),this._autoUnbox=!1;try{return this._observableInstanceState===_m.CREATED?this.type.getChildNode(this,e):this._childNodes[e]}finally{this._autoUnbox=!0}}}),Object.defineProperty(t.prototype,`getChildren`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.assertAlive(fh),this._autoUnbox=!1;try{return this._observableInstanceState===_m.CREATED?this.type.getChildren(this):lh(this._childNodes)}finally{this._autoUnbox=!0}}}),Object.defineProperty(t.prototype,`getChildType`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.type.getChildType(e)}}),Object.defineProperty(t.prototype,`isProtected`,{get:function(){return this.root.isProtectionEnabled},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`assertWritable`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this.assertAlive(e),!this.isRunningAction()&&this.isProtected)throw new K(`Cannot modify '${this}', the object is protected and can only be modified by using an action.`)}}),Object.defineProperty(t.prototype,`removeChild`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.type.removeChild(this,e)}}),Object.defineProperty(t.prototype,`unbox`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e&&(this.assertAlive({subpath:e.subpath||e.subpathUponDeath}),this._autoUnbox?e.value:e)}}),Object.defineProperty(t.prototype,`toString`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=(this.isAlive?this.path:this.pathUponDeath)||`<root>`,t=this.identifier?`(id: ${this.identifier})`:``;return`${this.type.name}@${e}${t}${this.isAlive?``:` [dead]`}`}}),Object.defineProperty(t.prototype,`finalizeCreation`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;this.baseFinalizeCreation(function(){var t,n;try{for(var r=Yp(e.getChildren()),i=r.next();!i.done;i=r.next())i.value.finalizeCreation()}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}e.fireInternalHook(Wp.afterCreationFinalization)})}}),Object.defineProperty(t.prototype,`detach`,{enumerable:!1,configurable:!0,writable:!0,value:function(){if(!this.isAlive)throw new K(`Error while detaching, node is not alive.`);this.clearParent()}}),Object.defineProperty(t.prototype,`preboot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;this._applyPatches=Im(this.storedValue,`@APPLY_PATCHES`,function(t){t.forEach(function(t){if(!t.path){e.type.applySnapshot(e,t.value);return}var n=Yh(t.path);ch(e,n.slice(0,-1)).applyPatchLocally(n[n.length-1],t)})}),this._applySnapshot=Im(this.storedValue,`@APPLY_SNAPSHOT`,function(t){if(t!==e.snapshot)return e.type.applySnapshot(e,t)}),Oh(this.storedValue,`$treenode`,this),Oh(this.storedValue,`toJSON`,oh)}}),Object.defineProperty(t.prototype,`die`,{enumerable:!1,configurable:!0,writable:!0,value:function(){!this.isAlive||this.state===th.DETACHING||(this.aboutToDie(),this.finalizeDeath())}}),Object.defineProperty(t.prototype,`aboutToDie`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this._observableInstanceState!==_m.UNINITIALIZED&&(this.getChildren().forEach(function(e){e.aboutToDie()}),this.baseAboutToDie(),this._internalEventsEmit(vm.Dispose),this._internalEventsClear(vm.Dispose))}}),Object.defineProperty(t.prototype,`finalizeDeath`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.getChildren().forEach(function(e){e.finalizeDeath()}),this.root.identifierCache.notifyDied(this),this._snapshotUponDeath=this.snapshot,this._internalEventsClearAll(),this.baseFinalizeDeath()}}),Object.defineProperty(t.prototype,`onSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._addSnapshotReaction(),this._internalEventsRegister(vm.Snapshot,e)}}),Object.defineProperty(t.prototype,`emitSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._internalEventsEmit(vm.Snapshot,e)}}),Object.defineProperty(t.prototype,`onPatch`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._internalEventsRegister(vm.Patch,e)}}),Object.defineProperty(t.prototype,`emitPatch`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this._internalEventsHasSubscribers(vm.Patch)){var n=Xp(Hh(bh({},e,{path:t.path.substr(this.path.length)+(e.path?`/`+e.path:``)})),2),r=n[0],i=n[1];this._internalEventsEmit(vm.Patch,r,i)}this.parent&&this.parent.emitPatch(e,t)}}),Object.defineProperty(t.prototype,`hasDisposer`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._internalEventsHas(vm.Dispose,e)}}),Object.defineProperty(t.prototype,`addDisposer`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!this.hasDisposer(e)){this._internalEventsRegister(vm.Dispose,e,!0);return}throw new K(`cannot add a disposer when it is already registered for execution`)}}),Object.defineProperty(t.prototype,`removeDisposer`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!this._internalEventsHas(vm.Dispose,e))throw new K(`cannot remove a disposer which was never registered for execution`);this._internalEventsUnregister(vm.Dispose,e)}}),Object.defineProperty(t.prototype,`removeMiddleware`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this.middlewares){var t=this.middlewares.indexOf(e);t>=0&&this.middlewares.splice(t,1)}}}),Object.defineProperty(t.prototype,`addMiddleWare`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;t===void 0&&(t=!0);var r={handler:e,includeHooks:t};return this.middlewares?this.middlewares.push(r):this.middlewares=[r],function(){n.removeMiddleware(r)}}}),Object.defineProperty(t.prototype,`applyPatchLocally`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){this.assertWritable({subpath:e}),this.createObservableInstanceIfNeeded(),this.type.applyPatchLocally(this,e,t)}}),Object.defineProperty(t.prototype,`_addSnapshotReaction`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;if(!this._hasSnapshotReaction){var t=Jn(function(){return e.snapshot},function(t){return e.emitSnapshot(t)},ym);this.addDisposer(t),this._hasSnapshotReaction=!0}}}),Object.defineProperty(t.prototype,`_internalEventsHasSubscribers`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return!!this._internalEvents&&this._internalEvents.hasSubscribers(e)}}),Object.defineProperty(t.prototype,`_internalEventsRegister`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){return n===void 0&&(n=!1),this._internalEvents||=new jh,this._internalEvents.register(e,t,n)}}),Object.defineProperty(t.prototype,`_internalEventsHas`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return!!this._internalEvents&&this._internalEvents.has(e,t)}}),Object.defineProperty(t.prototype,`_internalEventsUnregister`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){this._internalEvents&&this._internalEvents.unregister(e,t)}}),Object.defineProperty(t.prototype,`_internalEventsEmit`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){for(var t,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];this._internalEvents&&(t=this._internalEvents).emit.apply(t,Zp([e],Xp(n),!1))}}),Object.defineProperty(t.prototype,`_internalEventsClear`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._internalEvents&&this._internalEvents.clear(e)}}),Object.defineProperty(t.prototype,`_internalEventsClearAll`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this._internalEvents&&this._internalEvents.clearAll()}}),t}(mm);bm.prototype.createObservableInstance=Vn(bm.prototype.createObservableInstance),bm.prototype.detach=Vn(bm.prototype.detach),bm.prototype.die=Vn(bm.prototype.die);var xm,Sm;(function(e){e[e.String=1]=`String`,e[e.Number=2]=`Number`,e[e.Boolean=4]=`Boolean`,e[e.Date=8]=`Date`,e[e.Literal=16]=`Literal`,e[e.Array=32]=`Array`,e[e.Map=64]=`Map`,e[e.Object=128]=`Object`,e[e.Frozen=256]=`Frozen`,e[e.Optional=512]=`Optional`,e[e.Reference=1024]=`Reference`,e[e.Identifier=2048]=`Identifier`,e[e.Late=4096]=`Late`,e[e.Refinement=8192]=`Refinement`,e[e.Union=16384]=`Union`,e[e.Null=32768]=`Null`,e[e.Undefined=65536]=`Undefined`,e[e.Integer=131072]=`Integer`,e[e.Custom=262144]=`Custom`,e[e.SnapshotProcessor=524288]=`SnapshotProcessor`,e[e.Lazy=1048576]=`Lazy`,e[e.Finite=2097152]=`Finite`,e[e.Float=4194304]=`Float`})(Sm||={});var Cm=`cannotDetermine`,wm=Symbol(`$type`),Tm=function(){function e(e){Object.defineProperty(this,xm,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`C`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`S`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`T`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`N`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`isType`,{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,`name`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=e}return Object.defineProperty(e.prototype,`create`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return qm(this,e),this.instantiate(null,``,t,e).value}}),Object.defineProperty(e.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){throw new K(`unimplemented method`)}}),Object.defineProperty(e.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e===this}}),Object.defineProperty(e.prototype,`validate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(ah(e)){var n=Qp(e);return this.isAssignableFrom(n)?Wm():Gm(t,e)}return this.isValidSnapshot(e,t)}}),Object.defineProperty(e.prototype,`is`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.validate(e,[{path:``,type:this}]).length===0}}),Object.defineProperty(e.prototype,`Type`,{get:function(){throw new K("Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`TypeWithoutSTN`,{get:function(){throw new K("Factory.TypeWithoutSTN should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.TypeWithoutSTN`")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`SnapshotType`,{get:function(){throw new K("Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`CreationType`,{get:function(){throw new K("Factory.CreationType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.CreationType`")},enumerable:!1,configurable:!0}),e}();xm=wm,Tm.prototype.create=Vn(Tm.prototype.create);var Em=function(e){Kp(t,e);function t(t){var n=e.call(this,t)||this;return Object.defineProperty(n,`identifierAttribute`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),n}return Object.defineProperty(t.prototype,`create`,{enumerable:!1,configurable:!0,writable:!0,value:function(t,n){return t===void 0&&(t=this.getDefaultSnapshot()),e.prototype.create.call(this,t,n)}}),Object.defineProperty(t.prototype,`getValue`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.createObservableInstanceIfNeeded(),e.storedValue}}),Object.defineProperty(t.prototype,`isMatchingSnapshotId`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return!e.identifierAttribute||e.identifier===h_(t[e.identifierAttribute])}}),Object.defineProperty(t.prototype,`tryToReconcileNode`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return e.isDetaching?!1:e.snapshot===t||nh(t)&&ih(t)===e?!0:e.type===this&&Sh(t)&&!nh(t)&&this.isMatchingSnapshotId(e,t)?(e.applySnapshot(t),!0):!1}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){if(this.tryToReconcileNode(e,t))return e.setParent(n,r),e;if(e.die(),nh(t)&&this.isAssignableFrom(Qp(t))){var i=ih(t);return i.setParent(n,r),i}return this.instantiate(n,r,void 0,t)}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return null}}),t}(Tm);Em.prototype.create=Vn(Em.prototype.create);var Dm=function(e){Kp(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return Object.defineProperty(t.prototype,`createNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e}}),Object.defineProperty(t.prototype,`getValue`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){if(!e.isDetaching&&e.type===this&&e.storedValue===t)return e;var i=this.instantiate(n,r,void 0,t);return e.die(),i}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return null}}),t}(Tm);function Om(e){return typeof e==`object`&&e&&e.isType===!0}function km(e,t){Rh(e,Om,`mobx-state-tree type`,t)}(function(){function e(e,t){Object.defineProperty(this,`hooks`,{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,`call`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,`flowsPending`,{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,`running`,{enumerable:!0,configurable:!0,writable:!0,value:!0}),e&&e.onStart(t)}return Object.defineProperty(e.prototype,`finish`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.running&&(this.running=!1,this.hooks&&this.hooks.onFinish(this.call,e))}}),Object.defineProperty(e.prototype,`incFlowsPending`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.flowsPending++}}),Object.defineProperty(e.prototype,`decFlowsPending`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.flowsPending--}}),Object.defineProperty(e.prototype,`hasFlowsPending`,{get:function(){return this.flowsPending>0},enumerable:!1,configurable:!0}),e})();var Am=1,jm;function Mm(){return jm}function Nm(){return Am++}function Pm(e,t){var n=ih(e.context);e.type===`action`&&n.assertAlive({actionContext:e});var r=n._isRunningAction;n._isRunningAction=!0;var i=jm;jm=e;try{return Rm(n,e,t)}finally{jm=i,n._isRunningAction=r}}function Fm(e){if(e)return e.type===`action`?e:e.parentActionEvent}function Im(e,t,n){var r=function(){var r=Nm(),i=jm,a=Fm(i);return Pm({type:`action`,name:t,id:r,args:Mh(arguments),context:e,tree:om(e),rootId:i?i.rootId:r,parentId:i?i.id:0,allParentIds:i?Zp(Zp([],Xp(i.allParentIds),!1),[i.id],!1):[],parentEvent:i,parentActionEvent:a},n)};return r._isMSTAction=!0,r._isFlowAction=n._isFlowAction,r}var Lm=function(){function e(e,t){Object.defineProperty(this,`arrayIndex`,{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,`inArrayIndex`,{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,`middlewares`,{enumerable:!0,configurable:!0,writable:!0,value:[]}),t.$mst_middleware&&this.middlewares.push(t.$mst_middleware);for(var n=e;n;)n.middlewares&&this.middlewares.push(n.middlewares),n=n.parent}return Object.defineProperty(e.prototype,`isEmpty`,{get:function(){return this.middlewares.length<=0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`getNextMiddleware`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.middlewares[this.arrayIndex];if(e)return e[this.inArrayIndex++]||(this.arrayIndex++,this.inArrayIndex=0,this.getNextMiddleware())}}),e}();function Rm(e,t,n){var r=new Lm(e,n);if(r.isEmpty)return Vn(n).apply(null,t.args);var i=null;function a(e){var t=r.getNextMiddleware(),o=t&&t.handler;if(!o)return Vn(n).apply(null,e.args);if(!t.includeHooks&&Wp[e.name])return a(e);var s=!1;function c(e,t){s=!0,i=a(e),t&&(i=t(i))}var l=!1;function u(e){l=!0,i=e}if(o(e,c,u),Lh()){if(!s&&!l){var d=ih(e.tree);throw new K(`Neither the next() nor the abort() callback within the middleware ${o.name} for the action: "${e.name}" on the node: ${d.type.name} was invoked.`)}else if(s&&l){var d=ih(e.tree);throw new K(`The next() and abort() callback within the middleware ${o.name} for the action: "${e.name}" on the node: ${d.type.name} were invoked.`)}}return i}return a(t)}function zm(e){try{return JSON.stringify(e)}catch(e){return`<Unserializable: ${e}>`}}function Bm(e){return typeof e==`function`?`<function${e.name?` `+e.name:``}>`:nh(e)?`<${e}>`:`\`${zm(e)}\``}function Vm(e){return e.length<280?e:`${e.substring(0,272)}......${e.substring(e.length-8)}`}function Hm(e){var t=e.value,n=e.context[e.context.length-1].type,r=e.context.map(function(e){return e.path}).filter(function(e){return e.length>0}).join(`/`),i=r.length>0?`at path "/${r}" `:``,a=nh(t)?`value of type ${ih(t).type.name}:`:Ch(t)?`value`:`snapshot`,o=n&&nh(t)&&n.is(ih(t).snapshot);return`${i}${a} ${Bm(t)} is not assignable ${n?`to type: \`${n.name}\``:``}`+(e.message?` (${e.message})`:``)+(n?Mg(n)||Ch(t)?`.`:`, expected an instance of \`${n.name}\` or a snapshot like \`${n.describe()}\` instead.`+(o?` (Note that a snapshot of the provided value is compatible with the targeted type)`:``):`.`)}function Um(e,t,n){return e.concat([{path:t,type:n}])}function Wm(){return dh}function Gm(e,t,n){return[{context:e,value:t,message:n}]}function Km(e){return e.reduce(function(e,t){return e.concat(t)},[])}function qm(e,t){Ih()&&Jm(e,t)}function Jm(e,t){var n=e.validate(t,[{path:``,type:e}]);if(n.length>0)throw new K(Ym(e,t,n))}function Ym(e,t,n){if(n.length!==0)return`Error while converting ${Vm(Bm(t))} to \`${e.name}\`:
43
+ `:e)),e.replace(/(<([^>]+)>)/gi,``).replace(/&amp;/g,`&`).replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&quot;/g,`"`).replace(/&apos;/g,`'`).replace(/&nbsp;/g,` `)}function $f(e,t){return!!e.bold==!!t.bold&&!!e.italic==!!t.italic&&!!e.underline==!!t.underline&&!!e.strike==!!t.strike&&(e.color||``)===(t.color||``)}function ep(e){if(!e)return[];let t=new DOMParser().parseFromString(e,`text/html`),n=[],r=t.body.querySelectorAll(`p`);function i(e,t){if(e.nodeType===Node.TEXT_NODE){let r=e.textContent||``;r&&n.push(function(e,t){let n={text:e};return t.bold&&(n.bold=!0),t.italic&&(n.italic=!0),t.underline&&(n.underline=!0),t.strike&&(n.strike=!0),t.color&&(n.color=t.color),n}(r,t));return}if(e.nodeType!==Node.ELEMENT_NODE)return;let r=e,a=r.tagName.toLowerCase(),o=Object.assign({},t);a!==`strong`&&a!==`b`||(o.bold=!0),a!==`em`&&a!==`i`||(o.italic=!0),a===`u`&&(o.underline=!0),a===`s`&&(o.strike=!0);let s=r.style;s.color&&(o.color=s.color),(s.fontWeight===`bold`||parseInt(s.fontWeight)>=700)&&(o.bold=!0),s.fontStyle===`italic`&&(o.italic=!0);let c=s.textDecoration||s.textDecorationLine||``;c.includes(`underline`)&&(o.underline=!0),c.includes(`line-through`)&&(o.strike=!0);for(let e of Array.from(r.childNodes))i(e,o)}r.length>0?r.forEach((e,t)=>{i(e,{}),t<r.length-1&&n.push({text:` `})}):i(t.body,{});let a=[];for(let e of n){if(!e.text)continue;let t=a[a.length-1];t&&$f(t,e)?t.text+=e.text:a.push(e)}return a}function tp(e){return e?/<[a-z][a-z0-9]*(\s[^>]*)?>[^<]*<\/[a-z][a-z0-9]*>/i.test(e)?e=(e=e.replace(/<(?![a-z/!])/gi,`&lt;`)).replace(/([^a-z0-9"'\s/])>/gi,`$1&gt;`):e.replace(/</g,`&lt;`).replace(/>/g,`&gt;`):``}L([`Roboto`,`Amatic SC`,`Press Start 2P`,`Marck Script`,`Rubik Mono One`]),L({value:!1});var np=L([]);function rp(e){np.push(e)}var ip=`BESbswy 0123456789 Il1Ww`,ap=[`sans-serif`,`serif`,`monospace`];function op(e){let t=function(e=``){let t=Qf(e).replace(/\s+/g,` `).trim();return t?Array.from(t).slice(0,10).join(``):``}(e);return t?`${ip} ${t}`:ip}var sp;function cp(e){return{width:e.width,actualBoundingBoxLeft:e.actualBoundingBoxLeft||0,actualBoundingBoxRight:e.actualBoundingBoxRight||0,actualBoundingBoxAscent:e.actualBoundingBoxAscent||0,actualBoundingBoxDescent:e.actualBoundingBoxDescent||0}}function lp(e=`sans-serif`,t=`normal`,n=`normal`,r=ip){sp||=document.createElement(`canvas`);let i=sp.getContext(`2d`);return i.font=`${t} ${n} 40px ${e}`,cp(i.measureText(r))}function up(e,t,n,r,i){return ap.some(a=>function(e,t,n=.01){return Math.abs(e.width-t.width)>n||Math.abs(e.actualBoundingBoxLeft-t.actualBoundingBoxLeft)>n||Math.abs(e.actualBoundingBoxRight-t.actualBoundingBoxRight)>n||Math.abs(e.actualBoundingBoxAscent-t.actualBoundingBoxAscent)>n||Math.abs(e.actualBoundingBoxDescent-t.actualBoundingBoxDescent)>n}(function(e,t=`sans-serif`,n=`normal`,r=`normal`,i=ip){sp||=document.createElement(`canvas`);let a=sp.getContext(`2d`);return a.font=`${n} ${r} 40px '${e}', ${t}`,cp(a.measureText(i))}(e,a,t,n,r),i[a]))}var dp={Arial:!0},fp=(e,t,n)=>t&&n?!!dp[`${e}_${t}_${n}`]:Object.keys(dp).some(t=>t.startsWith(e+`_`))||!!dp[e];async function pp(e,t,n,r){let i=`${e}_${t}_${n}`;if(dp[i])return;let a=!!document.fonts?.load,o=op(r),s={"sans-serif":lp(`sans-serif`,t,n,o),serif:lp(`serif`,t,n,o),monospace:lp(`monospace`,t,n,o)};if(a)try{if(await document.fonts.load(`${t} ${n} 16px '${e}'`,o),up(e,t,n,o,s)){dp[i]=!0;return}}catch{}let c=Math.min(6e3,Gf())/60;for(let r=0;r<c;r++){if(up(e,t,n,o,s)){dp[i]=!0;return}await new Promise(e=>setTimeout(e,60))}console.warn(`Timeout for loading font "${e}". Looks like polotno can't load it. Is it a correct font family?`),Zf(`Timeout for loading font "${e}"`)}var mp={},hp=`400,400italic,700,700italic`;function gp(){return hp}function _p(e){return`https://fonts.googleapis.com/css?family=${e.replace(/ /g,`+`)}:${hp}`}function vp(e){if(mp[e])return;let t=_p(e),n=document.createElement(`link`);n.type=`text/css`,n.href=t,n.rel=`stylesheet`,document.getElementsByTagName(`head`)[0].appendChild(n),mp[e]=!0}var yp={},bp;function xp(e){let t=e.fontFamily;if(yp[t]||!e.url&&!e.styles)return;let n=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]),r=(bp||(bp=document.getElementById(`polotno-font-style`),bp||(bp=document.createElement(`style`),bp.id=`polotno-font-style`,document.head.appendChild(bp)),bp)).sheet;n.forEach(e=>{r.insertRule(`\n @font-face{\n font-family:'${t}';\n src:${e.src};\n font-style:${e.fontStyle||`normal`};\n font-weight:${e.fontWeight||`normal`};\n font-display:swap; /* optional but recommended */\n }`,r.cssRules.length)}),yp[e.fontFamily]=!0}var Sp=L({imageDownScalingEnabled:!0,removeBackgroundEnabled:!1,htmlRenderEnabled:!1,forceTextFitEnabled:!1,textVerticalResizeEnabled:!1,textOverflow:`resize`,textSplitAllowed:!1,animationsEnabled:!1,aiTextEnabled:!1,autoDeleteEmptyText:!0}),Cp=typeof window<`u`&&window.location.hostname===`localhost`||typeof process<`u`&&!1,wp=Vn(e=>{Sp.textVerticalResizeEnabled=e}),Tp=Vn(e=>{Sp.removeBackgroundEnabled=e});Vn(e=>{Cp&&console.warn(`useRemoveBackground is deprecated. Use setRemoveBackgroundEnabled instead.`),Tp(e)}),Vn(e=>{Sp.aiTextEnabled=e}),Vn(e=>{Cp&&console.warn(`useHtmlTextRender is deprecated. Use setRichTextEnabled instead.`),Sp.htmlRenderEnabled=e});var Ep=Vn(e=>{Sp.htmlRenderEnabled=e}),Dp=Vn(e=>{Sp.imageDownScalingEnabled=e});Vn(e=>{console.warn(`useDownScaling is deprecated. Use setDownScalingEnabled instead.`),Dp(e)}),Vn(e=>{console.warn(`setForceTextFit is deprecated. Use setTextOverflow instead.`),Sp.textOverflow=`change-font-size`});var Op=Vn(e=>{Sp.textOverflow=e}),kp=Vn(e=>{Sp.textSplitAllowed=e});Vn(e=>{Sp.animationsEnabled=e}),Vn(e=>{Sp.autoDeleteEmptyText=e});var Ap={fontSize:14,fontFamily:`Roboto`,fontWeight:`normal`,fontStyle:`normal`,lineHeight:1.2,letterSpacing:0,textTransform:`none`,textDecoration:``,align:`center`,fill:`black`,stroke:`black`,strokeWidth:0,curveEnabled:!1,curvePower:.5};function jp(e){return Object.assign(Object.assign({},Ap),e)}function Mp(e){var t=`֑-߿‏‫‮יִ-﷽ﹰ-ﻼ`;return RegExp(`^[^`+t+`]*?[`+t+`]`).test(e)}function Np(e){return function(e){e=e.replace(/\s/g,``);let t=0;for(var n=0;n<e.length;n++)Mp(e[n])&&(t+=1);return t>e.length/2}(e)?`rtl`:`ltr`}function Pp(e,t,n,r){let i=Math.max(-.9999,Math.min(.9999,n));if(Math.abs(i)<1e-4)return`M 0 ${t/2} L ${e} ${t/2}`;let a=5*r/(2*Math.abs(i))-r,o=e/2;if(i>0){let e=2*a+r/2;return[`M ${o} ${e}`,`A ${a} ${a} 0 1 1 ${o} ${e-2*a}`,`A ${a} ${a} 0 1 1 ${o} ${e}`].join(` `)}{let e=-(2*a-Math.round(t))-r/2;return[`M ${o} ${e}`,`A ${a} ${a} 0 1 0 ${o} ${e+2*a}`,`A ${a} ${a} 0 1 0 ${o} ${e}`].join(` `)}}function Fp(e,t,n,r){if(!jf(e))return``;let{stops:i,rotation:a}=Nf(e),o=a*Math.PI/180;return`<linearGradient id="${t}" x1="${100*(.5-.5*Math.sin(o))}%" y1="${100*(.5+.5*Math.cos(o))}%" x2="${100*(.5+.5*Math.sin(o))}%" y2="${100*(.5-.5*Math.cos(o))}%">${i.map(({offset:e,color:t})=>`<stop offset="${100*e}%" stop-color="${t}" />`).join(``)}</linearGradient>`}function Ip(e){let t=e.a?e.a:e,n=jp(e),r=t.fontSize??n.fontSize,i=new Du.TextPath({data:Pp(t.width??n.width,t.height??n.height??0,n.curvePower,r),align:`center`,textBaseline:`middle`,text:Qf(n.text),fontSize:r,fontFamily:n.fontFamily,fontWeight:n.fontWeight,fontStyle:n.fontStyle,letterSpacing:n.letterSpacing*r,fill:n.fill}),a=i.getSelfRect().height||r;return i.destroy(),a}function Lp(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function Rp(e,t,n){return e.map(e=>{let r=[];e.bold&&t.fontWeight!==`bold`&&r.push(`font-weight="bold"`),e.italic&&t.fontStyle!==`italic`&&r.push(`font-style="italic"`),e.underline&&r.push(`text-decoration="underline"`),e.strike&&r.push(`text-decoration="line-through"`),!n?.omitColors&&e.color&&e.color!==t.fill&&r.push(`fill="${Lp(e.color)}"`);let i=Lp(e.text);return r.length===0?i:`<tspan ${r.join(` `)}>${i}</tspan>`}).join(``)}function zp(e,{fontFamily:t=``,color:n=`black`,forEditor:r=!1}={}){let i=jp(e),a=t||i.fontFamily,o=jf(i.fill),s=jf(i.stroke),c=Sp.textOverflow===`ellipsis`&&!r&&!i.curveEnabled&&!!i.height,l=(()=>{if(!c)return[];let e=Math.max(1,Math.round(i.height)),t=typeof i.lineHeight==`number`?i.lineHeight:1.2,n=Math.max(1,t*i.fontSize),r=Math.max(1,Math.floor(e/n));return[`max-height: ${e}px`,`overflow: hidden`,`display: -webkit-box`,`-webkit-box-orient: vertical`,`-webkit-line-clamp: ${r}`,`line-clamp: ${r}`]})(),u=e=>`\n background-image: ${e};\n background-size: 100% 100%;\n background-repeat: repeat;\n -webkit-background-clip: text;\n -moz-background-clip: text;\n background-clip: text;\n -webkit-text-fill-color: transparent;\n color: transparent\n `.trim(),d=`color: ${n||i.fill}`,f=``;s&&i.strokeWidth?(d=`color: ${n||i.fill}; ${u(i.stroke)}`,f=`-webkit-text-stroke: ${i.strokeWidth}px transparent`):o&&(d=u(i.fill));let p=[`white-space: pre-wrap`,`word-break: break-word`,`width: ${Math.round(i.width||100)}px`,...l,d,`font-size: ${i.fontSize}px`,`font-family: '${a}'`,`text-align: ${i.align}`,`text-transform: ${i.textTransform}`,i.textDecoration?`text-decoration: ${i.textDecoration}; text-decoration-color: ${n||i.fill}; text-decoration-layer: over`:``,i.lineHeight?`line-height: ${i.lineHeight}`:``,i.letterSpacing?`letter-spacing: ${i.letterSpacing*i.fontSize}px`:``,i.fontStyle?`font-style: ${i.fontStyle}`:``,i.fontWeight?`font-weight: ${i.fontWeight}`:``,f||(i.strokeWidth?`-webkit-text-stroke: ${i.strokeWidth}px ${i.stroke}`:``),i.strokeWidth&&!s?`paint-order: stroke fill`:``].filter(Boolean).join(`; `);if(i.curveEnabled&&!r){let t=Ip(e),r=Math.round(i.width||100),c=Pp(r,t,i.curvePower,i.fontSize),l=ep(i.text),u={fontWeight:i.fontWeight||`normal`,fontStyle:i.fontStyle||`normal`,fill:n||i.fill||`black`},d=Rp(l,u),f=Rp(l,u,{omitColors:!0}),p=`curve-${i.id||`temp`}`,m=i.strokeWidth&&(s||o&&!s),h=`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${t}">\n <defs>\n <path id="${p}" d="${c}" fill="none" />`;if(o){let e=`curve-fill-grad-${i.id||`temp`}`;h+=Fp(i.fill,e,r,t)}if(s&&i.strokeWidth){let e=`curve-stroke-grad-${i.id||`temp`}`;h+=Fp(i.stroke,e,r,t)}if(h+=`</defs>`,m){let e=`\n font-family="'${a}'"\n font-size="${i.fontSize}"\n font-weight="${i.fontWeight}"\n font-style="${i.fontStyle}"\n text-anchor="middle"\n dominant-baseline="central"\n letter-spacing="${i.letterSpacing*i.fontSize}px"${i.textDecoration?` text-decoration="${i.textDecoration}"`:``}`,t=s?`url(#curve-stroke-grad-${i.id||`temp`})`:i.stroke;h+=`\n <text ${e} fill="${t}" stroke="${t}" stroke-width="${i.strokeWidth}">\n <textPath href="#${p}" startOffset="50%">${f}</textPath>\n </text>`,h+=`\n <text ${e} fill="${o?`url(#curve-fill-grad-${i.id||`temp`})`:n}">\n <textPath href="#${p}" startOffset="50%">${d}</textPath>\n </text>`}else{let e=o?`url(#curve-fill-grad-${i.id||`temp`})`:n,t=s?`url(#curve-stroke-grad-${i.id||`temp`})`:i.stroke;h+=`\n <text\n font-family="'${a}'"\n font-size="${i.fontSize}"\n font-weight="${i.fontWeight}"\n font-style="${i.fontStyle}"\n fill="${e}"\n text-anchor="middle"\n dominant-baseline="central"\n letter-spacing="${i.letterSpacing*i.fontSize}px"${i.textDecoration?` text-decoration="${i.textDecoration}"`:``}${i.strokeWidth?` stroke="${t}" stroke-width="${i.strokeWidth}" paint-order="stroke fill"`:``}>\n <textPath href="#${p}" startOffset="50%">${d}</textPath>\n </text>`}return h+=`</svg>`,h}if(i.strokeWidth&&(s||o&&!s)&&!r){let e=tp(i.text).replace(/\n/g,`<br/>`),t=Math.round(i.width||100),r=[`white-space: pre-wrap`,`word-break: break-word`,`width: ${t}px`,...l,`font-size: ${i.fontSize}px`,`font-family: '${a}'`,`text-align: ${i.align}`,`text-transform: ${i.textTransform}`,i.textDecoration?`text-decoration: ${i.textDecoration}; text-decoration-color: ${n||i.fill}; text-decoration-layer: over`:``,i.lineHeight?`line-height: ${i.lineHeight}`:``,i.letterSpacing?`letter-spacing: ${i.letterSpacing*i.fontSize}px`:``,i.fontStyle?`font-style: ${i.fontStyle}`:``,i.fontWeight?`font-weight: ${i.fontWeight}`:``].filter(Boolean).join(`; `),c;return c=s?`${r}; ${u(i.stroke)}; -webkit-text-stroke: ${i.strokeWidth}px transparent`:`${r}; color: transparent; -webkit-text-stroke: ${i.strokeWidth}px ${i.stroke}`,`\n <div style="position: relative; width: ${t}px;">\n <div style="${c}; position: absolute; top: 0; left: 0; pointer-events: none;" aria-hidden="true">${e}</div>\n <div style="${r}; ${o?u(i.fill):`color: ${n||i.fill}`}; position: relative;" contentEditable dir="${Np(Qf(i.text))}">${e}</div>\n </div>\n `}return`<div style="${p}" contentEditable dir="${Np(Qf(i.text))}">${tp(i.text).replace(/\n/g,`</br>`)}</div>`}function Bp({fontFamily:e,fontSize:t,lineHeight:n}){if(typeof n==`number`)return n;let r=document.createElement(`div`);r.style.fontFamily=e,r.style.fontSize=t+`px`,r.style.lineHeight=n,r.innerText=`Test text`,document.body.appendChild(r);let i=r.offsetHeight;return document.body.removeChild(r),i/t}var Vp={warm:e=>t=>{let n=t.data;e=Math.max(0,Math.min(1,e));for(let t=0;t<n.length;t+=4)n[t]=Math.min(n[t]+30*e,255),n[t+1]=Math.min(n[t+1]+15*e,255);return t},cold:e=>t=>{let n=t.data;e=Math.max(0,Math.min(1,e));for(let t=0;t<n.length;t+=4)n[t]=Math.min(n[t]-15*e,255),n[t+1]=Math.min(n[t+1]-10*e,255),n[t+2]=Math.min(n[t+2]+15*e,255);return t},natural:e=>t=>{let n=t.data;e=Math.max(0,Math.min(1,e));for(let t=0;t<n.length;t+=4){n[t]=Math.min(n[t]*(1+.1*e),255),n[t+1]=Math.min(n[t+1]*(1+.1*e),255),n[t+2]=Math.min(n[t+2]*(1+.1*e),255);let r=(n[t]+n[t+1]+n[t+2])/3;n[t]=Math.min((n[t]-r)*(1+.2*e)+r,255),n[t+1]=Math.min((n[t+1]-r)*(1+.2*e)+r,255),n[t+2]=Math.min((n[t+2]-r)*(1+.2*e)+r,255)}return t},temperature:e=>t=>{let n=t.data;e=Math.max(-1,Math.min(1,e));for(let t=0;t<n.length;t+=4){let r=n[t],i=(n[t+1],n[t+2]);n[t]=Math.min(Math.max(r+15*e,0),255),n[t+2]=Math.min(Math.max(i-15*e,0),255)}return t},contrast:e=>t=>{let n=t.data,r=100*(e=Math.max(-1,Math.min(1,e))),i=259*(r+255)/(255*(259-r));for(let e=0;e<n.length;e+=4)n[e]=Math.min(Math.max(i*(n[e]-128)+128,0),255),n[e+1]=Math.min(Math.max(i*(n[e+1]-128)+128,0),255),n[e+2]=Math.min(Math.max(i*(n[e+2]-128)+128,0),255);return t},shadows:e=>t=>{let n=t.data;e=Math.max(-1,Math.min(1,e));for(let t=0;t<n.length;t+=4){let r=(n[t]+n[t+1]+n[t+2])/3;if(r<128){let i=1+e*(1-r/128)*2;n[t]=Math.min(Math.max(n[t]*i,0),255),n[t+1]=Math.min(Math.max(n[t+1]*i,0),255),n[t+2]=Math.min(Math.max(n[t+2]*i,0),255)}}return t},white:e=>t=>{let n=t.data;e=Math.max(-1,Math.min(1,e));for(let t=0;t<n.length;t+=4){let r=n[t],i=n[t+1],a=n[t+2],o=(r+i+a)/3;if(o>128){let s=1+e*((o-128)/127);n[t]=Math.min(Math.max(r*s,0),255),n[t+1]=Math.min(Math.max(i*s,0),255),n[t+2]=Math.min(Math.max(a*s,0),255)}}return t},black:e=>t=>{let n=t.data;e=Math.max(-1,Math.min(1,e));for(let t=0;t<n.length;t+=4){let r=n[t],i=n[t+1],a=n[t+2],o=(r+i+a)/3;if(o<128){let s=1+e*((128-o)/128);n[t]=Math.min(Math.max(r*s,0),255),n[t+1]=Math.min(Math.max(i*s,0),255),n[t+2]=Math.min(Math.max(a*s,0),255)}}return t},vibrance:e=>t=>{let n=t.data;e=Math.max(-1,Math.min(1,e));for(let t=0;t<n.length;t+=4){let r=n[t],i=n[t+1],a=n[t+2],o=Math.max(r,i,a),s=e<0?(1-(o===0?0:(o-(r+i+a)/3)/o))*e*1.5:.5*e;n[t]=Math.min(Math.max(r-(o-r)*s,0),255),n[t+1]=Math.min(Math.max(i-(o-i)*s,0),255),n[t+2]=Math.min(Math.max(a-(o-a)*s,0),255)}return t},saturation:e=>t=>{let n=t.data;e=Math.max(-1,Math.min(1,e));for(let t=0;t<n.length;t+=4){let r=n[t],i=n[t+1],a=n[t+2],o=.2126*r+.7152*i+.0722*a;n[t]=Math.min(Math.max(o+(r-o)*(1+e),0),255),n[t+1]=Math.min(Math.max(o+(i-o)*(1+e),0),255),n[t+2]=Math.min(Math.max(o+(a-o)*(1+e),0),255)}return t}};function Hp(e,t){var n;let r={filters:[]},i={};t.brightnessEnabled&&(r.filters.push(Du.Filters.Brighten),r.brightness=t.brightness),t.blurEnabled&&(r.filters.push(Du.Filters.Blur),r.blurRadius=t.blurRadius,t.type===`text`&&t.lineHeight<1&&(i.offset=t.fontSize)),t.sepiaEnabled&&r.filters.push(Du.Filters.Sepia),t.grayscaleEnabled&&r.filters.push(Du.Filters.Grayscale),t.filters.forEach((e,t)=>{let n=Vp[t];n&&r.filters.push(n(e.intensity))}),e.setAttrs(r),r.filters.length?e.cache(Object.assign(Object.assign({},i),{pixelRatio:t.store._elementsPixelRatio})):e.clearCache(),(n=e.getLayer())==null||n.batchDraw()}var Up=()=>`ontouchstart`in window||navigator.maxTouchPoints>0,Wp=`warn`;function Gp(e){Wp=e}function Kp(){return Wp}var qp;(function(e){e.afterCreate=`afterCreate`,e.afterAttach=`afterAttach`,e.afterCreationFinalization=`afterCreationFinalization`,e.beforeDetach=`beforeDetach`,e.beforeDestroy=`beforeDestroy`})(qp||={});var Jp=function(e,t){return Jp=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},Jp(e,t)};function Yp(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Class extends value `+String(t)+` is not a constructor or null`);Jp(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var Xp=function(){return Xp=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},Xp.apply(this,arguments)};function Zp(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function Qp(e){var t=typeof Symbol==`function`&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length==`number`)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw TypeError(t?`Object is not iterable.`:`Symbol.iterator is not defined.`)}function $p(e,t){var n=typeof Symbol==`function`&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),i,a=[],o;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(e){o={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a}function em(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}function tm(e){return oh(e,1),sh(e).type}function nm(e,t){return oh(e,1),Hh(t,2),sh(e).onSnapshot(t)}function rm(e,t){oh(e,1),Vh(t,function(e){return typeof e==`object`},`object or array`,2),sh(e).applyPatches(Sh(t))}function im(e,t){return oh(e,1),sh(e).applySnapshot(t)}function am(e,t){t===void 0&&(t=!0),oh(e,1);var n=sh(e);return t?n.snapshot:Dh(n.type.getSnapshot(n,!1))}function om(e,t){t===void 0&&(t=1),oh(e,1),Uh(t,2,0);for(var n=t,r=sh(e).parent;r;){if(--n===0)return r.storedValue;r=r.parent}throw new K(`Failed to find the parent of ${sh(e)} at depth ${t}`)}function sm(e,t){oh(e,1),Mm(t,2);for(var n=sh(e).parent;n;){if(t.is(n.storedValue))return!0;n=n.parent}return!1}function cm(e,t){oh(e,1),Mm(t,2);for(var n=sh(e).parent;n;){if(t.is(n.storedValue))return n.storedValue;n=n.parent}throw new K(`Failed to find the parent of ${sh(e)} of a given type`)}function lm(e){return oh(e,1),sh(e).root.storedValue}function um(e){return oh(e,1),sh(e).path}function dm(e,t){oh(e,1),Wh(t,2);var n=uh(sh(e),t);return n?n.value:void 0}function fm(e){return oh(e,1),sh(e).identifier}function pm(e){return oh(e,1),sh(e).detach(),e}function mm(e){oh(e,1);var t=sh(e);t.isRoot?t.die():t.parent.removeChild(t.subpath)}function hm(e){return oh(e,1),sh(e).observableIsAlive}function gm(e){return e}var _m=function(){function e(e,t,n,r){Object.defineProperty(this,`type`,{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,`environment`,{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,`_escapedSubpath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`_subpath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`_subpathUponDeath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`_pathUponDeath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`storedValue`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`aliveAtom`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`_state`,{enumerable:!0,configurable:!0,writable:!0,value:ih.INITIALIZING}),Object.defineProperty(this,`_hookSubscribers`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`_parent`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`pathAtom`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.environment=r,this.baseSetParent(t,n)}return Object.defineProperty(e.prototype,`subpath`,{get:function(){return this._subpath},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`subpathUponDeath`,{get:function(){return this._subpathUponDeath},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`pathUponDeath`,{get:function(){return this._pathUponDeath},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`value`,{get:function(){return this.type.getValue(this)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`state`,{get:function(){return this._state},set:function(e){var t=this.isAlive;this._state=e;var n=this.isAlive;this.aliveAtom&&t!==n&&this.aliveAtom.reportChanged()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`fireInternalHook`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._hookSubscribers&&this._hookSubscribers.emit(e,this,e)}}),Object.defineProperty(e.prototype,`registerHook`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this._hookSubscribers||=new Ph,this._hookSubscribers.register(e,t)}}),Object.defineProperty(e.prototype,`parent`,{get:function(){return this._parent},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`getReconciliationType`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.type}}),Object.defineProperty(e.prototype,`baseSetParent`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){this._parent=e,this._subpath=t,this._escapedSubpath=void 0,this.pathAtom&&this.pathAtom.reportChanged()}}),Object.defineProperty(e.prototype,`path`,{get:function(){return this.getEscapedPath(!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`getEscapedPath`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e&&(this.pathAtom||=Ee(`path`),this.pathAtom.reportObserved()),this.parent?(this._escapedSubpath===void 0&&(this._escapedSubpath=this._subpath?Yh(this._subpath):``),this.parent.getEscapedPath(e)+`/`+this._escapedSubpath):``}}),Object.defineProperty(e.prototype,`isRoot`,{get:function(){return this.parent===null},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`isAlive`,{get:function(){return this.state!==ih.DEAD},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`isDetaching`,{get:function(){return this.state===ih.DETACHING},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`observableIsAlive`,{get:function(){return this.aliveAtom||=Ee(`alive`),this.aliveAtom.reportObserved(),this.isAlive},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`baseFinalizeCreation`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(Bh()&&!this.isAlive)throw new K(`assertion failed: cannot finalize the creation of a node that is already dead`);if(this.state===ih.CREATED){if(this.parent){if(this.parent.state!==ih.FINALIZED)return;this.fireHook(qp.afterAttach)}this.state=ih.FINALIZED,e&&e()}}}),Object.defineProperty(e.prototype,`baseFinalizeDeath`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this._hookSubscribers&&this._hookSubscribers.clearAll(),this._subpathUponDeath=this._subpath,this._pathUponDeath=this.getEscapedPath(!1),this.baseSetParent(null,``),this.state=ih.DEAD}}),Object.defineProperty(e.prototype,`baseAboutToDie`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.fireHook(qp.beforeDestroy)}}),e}(),vm=function(e){Yp(t,e);function t(t,n,r,i,a){var o=e.call(this,t,n,r,i)||this;try{o.storedValue=t.createNewInstance(a)}catch(e){throw o.state=ih.DEAD,e}return o.state=ih.CREATED,o.finalizeCreation(),o}return Object.defineProperty(t.prototype,`root`,{get:function(){if(!this.parent)throw new K(`This scalar node is not part of a tree`);return this.parent.root},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`setParent`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.parent!==e,r=this.subpath!==t;if(!(!n&&!r)){if(Bh()){if(!t)throw new K(`assertion failed: subpath expected`);if(!e)throw new K(`assertion failed: parent expected`);if(n)throw new K(`assertion failed: scalar nodes cannot change their parent`)}this.environment=void 0,this.baseSetParent(this.parent,t)}}}),Object.defineProperty(t.prototype,`snapshot`,{get:function(){return Dh(this.getSnapshot())},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.type.getSnapshot(this)}}),Object.defineProperty(t.prototype,`toString`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=(this.isAlive?this.path:this.pathUponDeath)||`<root>`;return`${this.type.name}@${e}${this.isAlive?``:` [dead]`}`}}),Object.defineProperty(t.prototype,`die`,{enumerable:!1,configurable:!0,writable:!0,value:function(){!this.isAlive||this.state===ih.DETACHING||(this.aboutToDie(),this.finalizeDeath())}}),Object.defineProperty(t.prototype,`finalizeCreation`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.baseFinalizeCreation()}}),Object.defineProperty(t.prototype,`aboutToDie`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.baseAboutToDie()}}),Object.defineProperty(t.prototype,`finalizeDeath`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.baseFinalizeDeath()}}),Object.defineProperty(t.prototype,`fireHook`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.fireInternalHook(e)}}),t}(_m);vm.prototype.die=Vn(vm.prototype.die);var ym=1,bm;(function(e){e[e.UNINITIALIZED=0]=`UNINITIALIZED`,e[e.CREATING=1]=`CREATING`,e[e.CREATED=2]=`CREATED`})(bm||={});var xm;(function(e){e.Dispose=`dispose`,e.Patch=`patch`,e.Snapshot=`snapshot`})(xm||={});var Sm={onError:function(e){throw e}},Cm=function(e){Yp(t,e);function t(t,n,r,i,a){var o=e.call(this,t,n,r,i)||this;if(Object.defineProperty(o,`nodeId`,{enumerable:!0,configurable:!0,writable:!0,value:++ym}),Object.defineProperty(o,`identifierAttribute`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`identifier`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`unnormalizedIdentifier`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`identifierCache`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`isProtectionEnabled`,{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(o,`middlewares`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`hasSnapshotPostProcessor`,{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(o,`_applyPatches`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_applySnapshot`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_autoUnbox`,{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(o,`_isRunningAction`,{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(o,`_hasSnapshotReaction`,{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(o,`_observableInstanceState`,{enumerable:!0,configurable:!0,writable:!0,value:bm.UNINITIALIZED}),Object.defineProperty(o,`_childNodes`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_initialSnapshot`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_cachedInitialSnapshot`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_cachedInitialSnapshotCreated`,{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(o,`_snapshotComputed`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_snapshotUponDeath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(o,`_internalEvents`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),o._snapshotComputed=jt(function(){return Dh(o.getSnapshot())}),o.unbox=o.unbox.bind(o),o._initialSnapshot=Dh(a),o.identifierAttribute=t.identifierAttribute,n||(o.identifierCache=new eh),o._childNodes=t.initializeChildNodes(o,o._initialSnapshot),o.identifier=null,o.unnormalizedIdentifier=null,o.identifierAttribute&&o._initialSnapshot){var s=o._initialSnapshot[o.identifierAttribute];if(s===void 0){var c=o._childNodes[o.identifierAttribute];c&&(s=c.value)}if(typeof s!=`string`&&typeof s!=`number`)throw new K(`Instance identifier '${o.identifierAttribute}' for type '${o.type.name}' must be a string or a number`);o.identifier=v_(s),o.unnormalizedIdentifier=s}return n?n.root.identifierCache.addNodeToCache(o):o.identifierCache.addNodeToCache(o),o}return Object.defineProperty(t.prototype,`applyPatches`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.createObservableInstanceIfNeeded(),this._applyPatches(e)}}),Object.defineProperty(t.prototype,`applySnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.createObservableInstanceIfNeeded(),this._applySnapshot(e)}}),Object.defineProperty(t.prototype,`createObservableInstanceIfNeeded`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){e===void 0&&(e=!0),this._observableInstanceState===bm.UNINITIALIZED&&this.createObservableInstance(e)}}),Object.defineProperty(t.prototype,`createObservableInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t,n,r,i;if(e===void 0&&(e=!0),Bh()&&this.state!==ih.INITIALIZING)throw new K(`assertion failed: the creation of the observable instance must be done on the initializing phase`);this._observableInstanceState=bm.CREATING;for(var a=[],o=this.parent;o&&o._observableInstanceState===bm.UNINITIALIZED;)a.unshift(o),o=o.parent;try{for(var s=Qp(a),c=s.next();!c.done;c=s.next()){var l=c.value;l.createObservableInstanceIfNeeded(!1)}}catch(e){t={error:e}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}var u=this.type;try{this.storedValue=u.createNewInstance(this._childNodes),this.preboot(),this._isRunningAction=!0,u.finalizeNewInstance(this,this.storedValue)}catch(e){throw this.state=ih.DEAD,e}finally{this._isRunningAction=!1}if(this._observableInstanceState=bm.CREATED,this._snapshotComputed.trackAndCompute(),this.isRoot&&this._addSnapshotReaction(),this._childNodes=hh,this.state=ih.CREATED,e){this.fireHook(qp.afterCreate),this.finalizeCreation();try{for(var d=Qp(a.reverse()),f=d.next();!f.done;f=d.next()){var l=f.value;l.fireHook(qp.afterCreate),l.finalizeCreation()}}catch(e){r={error:e}}finally{try{f&&!f.done&&(i=d.return)&&i.call(d)}finally{if(r)throw r.error}}}}}),Object.defineProperty(t.prototype,`root`,{get:function(){var e=this.parent;return e?e.root:this},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`clearParent`,{enumerable:!1,configurable:!0,writable:!0,value:function(){if(this.parent){this.fireHook(qp.beforeDetach);var e=this.state;this.state=ih.DETACHING;var t=this.root,n=t.environment,r=t.identifierCache.splitCache(this);try{this.parent.removeChild(this.subpath),this.baseSetParent(null,``),this.environment=n,this.identifierCache=r}finally{this.state=e}}}}),Object.defineProperty(t.prototype,`setParent`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=e!==this.parent,r=t!==this.subpath;if(!(!n&&!r)){if(Bh()){if(!t)throw new K(`assertion failed: subpath expected`);if(!e)throw new K(`assertion failed: new parent expected`);if(this.parent&&n)throw new K(`A node cannot exists twice in the state tree. Failed to add ${this} to path '${e.path}/${t}'.`);if(!this.parent&&e.root===this)throw new K(`A state tree is not allowed to contain itself. Cannot assign ${this} to path '${e.path}/${t}'`);if(!this.parent&&this.environment&&this.environment!==e.root.environment)throw new K(`A state tree cannot be made part of another state tree as long as their environments are different.`)}n?(this.environment=void 0,e.root.identifierCache.mergeCache(this),this.baseSetParent(e,t),this.fireHook(qp.afterAttach)):r&&this.baseSetParent(this.parent,t)}}}),Object.defineProperty(t.prototype,`fireHook`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this.fireInternalHook(e);var n=this.storedValue&&typeof this.storedValue==`object`&&this.storedValue[e];typeof n==`function`&&(Un?Un(function(){n.apply(t.storedValue)}):n.apply(this.storedValue))}}),Object.defineProperty(t.prototype,`snapshot`,{get:function(){return this.hasSnapshotPostProcessor&&this.createObservableInstanceIfNeeded(),this._snapshotComputed.get()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.isAlive?this._observableInstanceState===bm.CREATED?this._getActualSnapshot():this._getCachedInitialSnapshot():this._snapshotUponDeath}}),Object.defineProperty(t.prototype,`_getActualSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.type.getSnapshot(this)}}),Object.defineProperty(t.prototype,`_getCachedInitialSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){if(!this._cachedInitialSnapshotCreated){var e=this.type,t=this._childNodes,n=this._initialSnapshot;this._cachedInitialSnapshot=e.processInitialSnapshot(t,n),this._cachedInitialSnapshotCreated=!0}return this._cachedInitialSnapshot}}),Object.defineProperty(t.prototype,`isRunningAction`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._isRunningAction?!0:this.isRoot?!1:this.parent.isRunningAction()}}),Object.defineProperty(t.prototype,`assertAlive`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=Kp();if(!this.isAlive&&t!==`ignore`){var n=this._getAssertAliveError(e);switch(t){case`error`:throw new K(n);case`warn`:Rh(n)}}}}),Object.defineProperty(t.prototype,`_getAssertAliveError`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.getEscapedPath(!1)||this.pathUponDeath||``,n=e.subpath&&Yh(e.subpath)||``,r=e.actionContext||Fm();r&&r.type!==`action`&&r.parentActionEvent&&(r=r.parentActionEvent);var i=``;return r&&r.name!=null&&(i=`${r&&r.context&&um(r.context)||t}.${r.name}()`),`You are trying to read or write to an object that is no longer part of a state tree. (Object type: '${this.type.name}', Path upon death: '${t}', Subpath: '${n}', Action: '${i}'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.`}}),Object.defineProperty(t.prototype,`getChildNode`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.assertAlive({subpath:e}),this._autoUnbox=!1;try{return this._observableInstanceState===bm.CREATED?this.type.getChildNode(this,e):this._childNodes[e]}finally{this._autoUnbox=!0}}}),Object.defineProperty(t.prototype,`getChildren`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.assertAlive(hh),this._autoUnbox=!1;try{return this._observableInstanceState===bm.CREATED?this.type.getChildren(this):fh(this._childNodes)}finally{this._autoUnbox=!0}}}),Object.defineProperty(t.prototype,`getChildType`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.type.getChildType(e)}}),Object.defineProperty(t.prototype,`isProtected`,{get:function(){return this.root.isProtectionEnabled},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`assertWritable`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this.assertAlive(e),!this.isRunningAction()&&this.isProtected)throw new K(`Cannot modify '${this}', the object is protected and can only be modified by using an action.`)}}),Object.defineProperty(t.prototype,`removeChild`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.type.removeChild(this,e)}}),Object.defineProperty(t.prototype,`unbox`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e&&(this.assertAlive({subpath:e.subpath||e.subpathUponDeath}),this._autoUnbox?e.value:e)}}),Object.defineProperty(t.prototype,`toString`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=(this.isAlive?this.path:this.pathUponDeath)||`<root>`,t=this.identifier?`(id: ${this.identifier})`:``;return`${this.type.name}@${e}${t}${this.isAlive?``:` [dead]`}`}}),Object.defineProperty(t.prototype,`finalizeCreation`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;this.baseFinalizeCreation(function(){var t,n;try{for(var r=Qp(e.getChildren()),i=r.next();!i.done;i=r.next())i.value.finalizeCreation()}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}e.fireInternalHook(qp.afterCreationFinalization)})}}),Object.defineProperty(t.prototype,`detach`,{enumerable:!1,configurable:!0,writable:!0,value:function(){if(!this.isAlive)throw new K(`Error while detaching, node is not alive.`);this.clearParent()}}),Object.defineProperty(t.prototype,`preboot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;this._applyPatches=zm(this.storedValue,`@APPLY_PATCHES`,function(t){t.forEach(function(t){if(!t.path){e.type.applySnapshot(e,t.value);return}var n=Qh(t.path);dh(e,n.slice(0,-1)).applyPatchLocally(n[n.length-1],t)})}),this._applySnapshot=zm(this.storedValue,`@APPLY_SNAPSHOT`,function(t){if(t!==e.snapshot)return e.type.applySnapshot(e,t)}),jh(this.storedValue,`$treenode`,this),jh(this.storedValue,`toJSON`,lh)}}),Object.defineProperty(t.prototype,`die`,{enumerable:!1,configurable:!0,writable:!0,value:function(){!this.isAlive||this.state===ih.DETACHING||(this.aboutToDie(),this.finalizeDeath())}}),Object.defineProperty(t.prototype,`aboutToDie`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this._observableInstanceState!==bm.UNINITIALIZED&&(this.getChildren().forEach(function(e){e.aboutToDie()}),this.baseAboutToDie(),this._internalEventsEmit(xm.Dispose),this._internalEventsClear(xm.Dispose))}}),Object.defineProperty(t.prototype,`finalizeDeath`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.getChildren().forEach(function(e){e.finalizeDeath()}),this.root.identifierCache.notifyDied(this),this._snapshotUponDeath=this.snapshot,this._internalEventsClearAll(),this.baseFinalizeDeath()}}),Object.defineProperty(t.prototype,`onSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._addSnapshotReaction(),this._internalEventsRegister(xm.Snapshot,e)}}),Object.defineProperty(t.prototype,`emitSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._internalEventsEmit(xm.Snapshot,e)}}),Object.defineProperty(t.prototype,`onPatch`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._internalEventsRegister(xm.Patch,e)}}),Object.defineProperty(t.prototype,`emitPatch`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this._internalEventsHasSubscribers(xm.Patch)){var n=$p(Gh(Ch({},e,{path:t.path.substr(this.path.length)+(e.path?`/`+e.path:``)})),2),r=n[0],i=n[1];this._internalEventsEmit(xm.Patch,r,i)}this.parent&&this.parent.emitPatch(e,t)}}),Object.defineProperty(t.prototype,`hasDisposer`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._internalEventsHas(xm.Dispose,e)}}),Object.defineProperty(t.prototype,`addDisposer`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!this.hasDisposer(e)){this._internalEventsRegister(xm.Dispose,e,!0);return}throw new K(`cannot add a disposer when it is already registered for execution`)}}),Object.defineProperty(t.prototype,`removeDisposer`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!this._internalEventsHas(xm.Dispose,e))throw new K(`cannot remove a disposer which was never registered for execution`);this._internalEventsUnregister(xm.Dispose,e)}}),Object.defineProperty(t.prototype,`removeMiddleware`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this.middlewares){var t=this.middlewares.indexOf(e);t>=0&&this.middlewares.splice(t,1)}}}),Object.defineProperty(t.prototype,`addMiddleWare`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;t===void 0&&(t=!0);var r={handler:e,includeHooks:t};return this.middlewares?this.middlewares.push(r):this.middlewares=[r],function(){n.removeMiddleware(r)}}}),Object.defineProperty(t.prototype,`applyPatchLocally`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){this.assertWritable({subpath:e}),this.createObservableInstanceIfNeeded(),this.type.applyPatchLocally(this,e,t)}}),Object.defineProperty(t.prototype,`_addSnapshotReaction`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;if(!this._hasSnapshotReaction){var t=Jn(function(){return e.snapshot},function(t){return e.emitSnapshot(t)},Sm);this.addDisposer(t),this._hasSnapshotReaction=!0}}}),Object.defineProperty(t.prototype,`_internalEventsHasSubscribers`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return!!this._internalEvents&&this._internalEvents.hasSubscribers(e)}}),Object.defineProperty(t.prototype,`_internalEventsRegister`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){return n===void 0&&(n=!1),this._internalEvents||=new Ph,this._internalEvents.register(e,t,n)}}),Object.defineProperty(t.prototype,`_internalEventsHas`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return!!this._internalEvents&&this._internalEvents.has(e,t)}}),Object.defineProperty(t.prototype,`_internalEventsUnregister`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){this._internalEvents&&this._internalEvents.unregister(e,t)}}),Object.defineProperty(t.prototype,`_internalEventsEmit`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){for(var t,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];this._internalEvents&&(t=this._internalEvents).emit.apply(t,em([e],$p(n),!1))}}),Object.defineProperty(t.prototype,`_internalEventsClear`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._internalEvents&&this._internalEvents.clear(e)}}),Object.defineProperty(t.prototype,`_internalEventsClearAll`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this._internalEvents&&this._internalEvents.clearAll()}}),t}(_m);Cm.prototype.createObservableInstance=Vn(Cm.prototype.createObservableInstance),Cm.prototype.detach=Vn(Cm.prototype.detach),Cm.prototype.die=Vn(Cm.prototype.die);var wm,Tm;(function(e){e[e.String=1]=`String`,e[e.Number=2]=`Number`,e[e.Boolean=4]=`Boolean`,e[e.Date=8]=`Date`,e[e.Literal=16]=`Literal`,e[e.Array=32]=`Array`,e[e.Map=64]=`Map`,e[e.Object=128]=`Object`,e[e.Frozen=256]=`Frozen`,e[e.Optional=512]=`Optional`,e[e.Reference=1024]=`Reference`,e[e.Identifier=2048]=`Identifier`,e[e.Late=4096]=`Late`,e[e.Refinement=8192]=`Refinement`,e[e.Union=16384]=`Union`,e[e.Null=32768]=`Null`,e[e.Undefined=65536]=`Undefined`,e[e.Integer=131072]=`Integer`,e[e.Custom=262144]=`Custom`,e[e.SnapshotProcessor=524288]=`SnapshotProcessor`,e[e.Lazy=1048576]=`Lazy`,e[e.Finite=2097152]=`Finite`,e[e.Float=4194304]=`Float`})(Tm||={});var Em=`cannotDetermine`,Dm=Symbol(`$type`),Om=function(){function e(e){Object.defineProperty(this,wm,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`C`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`S`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`T`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`N`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`isType`,{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,`name`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=e}return Object.defineProperty(e.prototype,`create`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return Xm(this,e),this.instantiate(null,``,t,e).value}}),Object.defineProperty(e.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){throw new K(`unimplemented method`)}}),Object.defineProperty(e.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e===this}}),Object.defineProperty(e.prototype,`validate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(ch(e)){var n=tm(e);return this.isAssignableFrom(n)?qm():Jm(t,e)}return this.isValidSnapshot(e,t)}}),Object.defineProperty(e.prototype,`is`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.validate(e,[{path:``,type:this}]).length===0}}),Object.defineProperty(e.prototype,`Type`,{get:function(){throw new K("Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`TypeWithoutSTN`,{get:function(){throw new K("Factory.TypeWithoutSTN should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.TypeWithoutSTN`")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`SnapshotType`,{get:function(){throw new K("Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`CreationType`,{get:function(){throw new K("Factory.CreationType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.CreationType`")},enumerable:!1,configurable:!0}),e}();wm=Dm,Om.prototype.create=Vn(Om.prototype.create);var km=function(e){Yp(t,e);function t(t){var n=e.call(this,t)||this;return Object.defineProperty(n,`identifierAttribute`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),n}return Object.defineProperty(t.prototype,`create`,{enumerable:!1,configurable:!0,writable:!0,value:function(t,n){return t===void 0&&(t=this.getDefaultSnapshot()),e.prototype.create.call(this,t,n)}}),Object.defineProperty(t.prototype,`getValue`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.createObservableInstanceIfNeeded(),e.storedValue}}),Object.defineProperty(t.prototype,`isMatchingSnapshotId`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return!e.identifierAttribute||e.identifier===v_(t[e.identifierAttribute])}}),Object.defineProperty(t.prototype,`tryToReconcileNode`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return e.isDetaching?!1:e.snapshot===t||ah(t)&&sh(t)===e?!0:e.type===this&&Th(t)&&!ah(t)&&this.isMatchingSnapshotId(e,t)?(e.applySnapshot(t),!0):!1}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){if(this.tryToReconcileNode(e,t))return e.setParent(n,r),e;if(e.die(),ah(t)&&this.isAssignableFrom(tm(t))){var i=sh(t);return i.setParent(n,r),i}return this.instantiate(n,r,void 0,t)}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return null}}),t}(Om);km.prototype.create=Vn(km.prototype.create);var Am=function(e){Yp(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return Object.defineProperty(t.prototype,`createNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e}}),Object.defineProperty(t.prototype,`getValue`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){if(!e.isDetaching&&e.type===this&&e.storedValue===t)return e;var i=this.instantiate(n,r,void 0,t);return e.die(),i}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return null}}),t}(Om);function jm(e){return typeof e==`object`&&e&&e.isType===!0}function Mm(e,t){Vh(e,jm,`mobx-state-tree type`,t)}(function(){function e(e,t){Object.defineProperty(this,`hooks`,{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,`call`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,`flowsPending`,{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,`running`,{enumerable:!0,configurable:!0,writable:!0,value:!0}),e&&e.onStart(t)}return Object.defineProperty(e.prototype,`finish`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.running&&(this.running=!1,this.hooks&&this.hooks.onFinish(this.call,e))}}),Object.defineProperty(e.prototype,`incFlowsPending`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.flowsPending++}}),Object.defineProperty(e.prototype,`decFlowsPending`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.flowsPending--}}),Object.defineProperty(e.prototype,`hasFlowsPending`,{get:function(){return this.flowsPending>0},enumerable:!1,configurable:!0}),e})();var Nm=1,Pm;function Fm(){return Pm}function Im(){return Nm++}function Lm(e,t){var n=sh(e.context);e.type===`action`&&n.assertAlive({actionContext:e});var r=n._isRunningAction;n._isRunningAction=!0;var i=Pm;Pm=e;try{return Vm(n,e,t)}finally{Pm=i,n._isRunningAction=r}}function Rm(e){if(e)return e.type===`action`?e:e.parentActionEvent}function zm(e,t,n){var r=function(){var r=Im(),i=Pm,a=Rm(i);return Lm({type:`action`,name:t,id:r,args:Fh(arguments),context:e,tree:lm(e),rootId:i?i.rootId:r,parentId:i?i.id:0,allParentIds:i?em(em([],$p(i.allParentIds),!1),[i.id],!1):[],parentEvent:i,parentActionEvent:a},n)};return r._isMSTAction=!0,r._isFlowAction=n._isFlowAction,r}var Bm=function(){function e(e,t){Object.defineProperty(this,`arrayIndex`,{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,`inArrayIndex`,{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,`middlewares`,{enumerable:!0,configurable:!0,writable:!0,value:[]}),t.$mst_middleware&&this.middlewares.push(t.$mst_middleware);for(var n=e;n;)n.middlewares&&this.middlewares.push(n.middlewares),n=n.parent}return Object.defineProperty(e.prototype,`isEmpty`,{get:function(){return this.middlewares.length<=0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`getNextMiddleware`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.middlewares[this.arrayIndex];if(e)return e[this.inArrayIndex++]||(this.arrayIndex++,this.inArrayIndex=0,this.getNextMiddleware())}}),e}();function Vm(e,t,n){var r=new Bm(e,n);if(r.isEmpty)return Vn(n).apply(null,t.args);var i=null;function a(e){var t=r.getNextMiddleware(),o=t&&t.handler;if(!o)return Vn(n).apply(null,e.args);if(!t.includeHooks&&qp[e.name])return a(e);var s=!1;function c(e,t){s=!0,i=a(e),t&&(i=t(i))}var l=!1;function u(e){l=!0,i=e}if(o(e,c,u),Bh()){if(!s&&!l){var d=sh(e.tree);throw new K(`Neither the next() nor the abort() callback within the middleware ${o.name} for the action: "${e.name}" on the node: ${d.type.name} was invoked.`)}else if(s&&l){var d=sh(e.tree);throw new K(`The next() and abort() callback within the middleware ${o.name} for the action: "${e.name}" on the node: ${d.type.name} were invoked.`)}}return i}return a(t)}function Hm(e){try{return JSON.stringify(e)}catch(e){return`<Unserializable: ${e}>`}}function Um(e){return typeof e==`function`?`<function${e.name?` `+e.name:``}>`:ah(e)?`<${e}>`:`\`${Hm(e)}\``}function Wm(e){return e.length<280?e:`${e.substring(0,272)}......${e.substring(e.length-8)}`}function Gm(e){var t=e.value,n=e.context[e.context.length-1].type,r=e.context.map(function(e){return e.path}).filter(function(e){return e.length>0}).join(`/`),i=r.length>0?`at path "/${r}" `:``,a=ah(t)?`value of type ${sh(t).type.name}:`:Eh(t)?`value`:`snapshot`,o=n&&ah(t)&&n.is(sh(t).snapshot);return`${i}${a} ${Um(t)} is not assignable ${n?`to type: \`${n.name}\``:``}`+(e.message?` (${e.message})`:``)+(n?Fg(n)||Eh(t)?`.`:`, expected an instance of \`${n.name}\` or a snapshot like \`${n.describe()}\` instead.`+(o?` (Note that a snapshot of the provided value is compatible with the targeted type)`:``):`.`)}function Km(e,t,n){return e.concat([{path:t,type:n}])}function qm(){return mh}function Jm(e,t,n){return[{context:e,value:t,message:n}]}function Ym(e){return e.reduce(function(e,t){return e.concat(t)},[])}function Xm(e,t){zh()&&Zm(e,t)}function Zm(e,t){var n=e.validate(t,[{path:``,type:e}]);if(n.length>0)throw new K(Qm(e,t,n))}function Qm(e,t,n){if(n.length!==0)return`Error while converting ${Wm(Um(t))} to \`${e.name}\`:
44
44
 
45
- `+n.map(Hm).join(`
46
- `)}var Xm=0,Zm=function(){function e(){Object.defineProperty(this,`cacheId`,{enumerable:!0,configurable:!0,writable:!0,value:Xm++}),Object.defineProperty(this,`cache`,{enumerable:!0,configurable:!0,writable:!0,value:L.map()}),Object.defineProperty(this,`lastCacheModificationPerId`,{enumerable:!0,configurable:!0,writable:!0,value:L.map()})}return Object.defineProperty(e.prototype,`updateLastCacheModificationPerId`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.lastCacheModificationPerId.get(e);this.lastCacheModificationPerId.set(e,t===void 0?1:t+1)}}),Object.defineProperty(e.prototype,`getLastCacheModificationPerId`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.lastCacheModificationPerId.get(e)||0;return`${this.cacheId}-${t}`}}),Object.defineProperty(e.prototype,`addNodeToCache`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(t===void 0&&(t=!0),e.identifierAttribute){var n=e.identifier;this.cache.has(n)||this.cache.set(n,L.array([],ph));var r=this.cache.get(n);if(r.indexOf(e)!==-1)throw new K(`Already registered`);r.push(e),t&&this.updateLastCacheModificationPerId(n)}}}),Object.defineProperty(e.prototype,`mergeCache`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;Cr(e.identifierCache.cache).forEach(function(e){return e.forEach(function(e){t.addNodeToCache(e)})})}}),Object.defineProperty(e.prototype,`notifyDied`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(e.identifierAttribute){var t=e.identifier,n=this.cache.get(t);n&&(n.remove(e),n.length||this.cache.delete(t),this.updateLastCacheModificationPerId(e.identifier))}}}),Object.defineProperty(e.prototype,`splitCache`,{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=this,r=new e,i=t.path+`/`;return wr(this.cache).forEach(function(e){for(var a=Xp(e,2),o=a[0],s=a[1],c=!1,l=s.length-1;l>=0;l--){var u=s[l];(u===t||u.path.indexOf(i)===0)&&(r.addNodeToCache(u,!1),s.splice(l,1),s.length||n.cache.delete(o),c=!0)}c&&n.updateLastCacheModificationPerId(o)}),r}}),Object.defineProperty(e.prototype,`has`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.cache.get(t);return n?n.some(function(t){return e.isAssignableFrom(t.type)}):!1}}),Object.defineProperty(e.prototype,`resolve`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.cache.get(t);if(!n)return null;var r=n.filter(function(t){return e.isAssignableFrom(t.type)});switch(r.length){case 0:return null;case 1:return r[0];default:throw new K(`Cannot resolve a reference to type '${e.name}' with id: '${t}' unambigously, there are multiple candidates: ${r.map(function(e){return e.path}).join(`, `)}`)}}}),e}();function Qm(e,t,n,r,i){var a=ah(i);if(a){if(a.parent)throw new K(`Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '${t?t.path:``}/${n}', but it lives already at '${a.path}'`);return t&&a.setParent(t,n),a}return new bm(e,t,n,r,i)}function $m(e,t,n,r,i){return new hm(e,t,n,r,i)}function eh(e){return e instanceof hm||e instanceof bm}var th;(function(e){e[e.INITIALIZING=0]=`INITIALIZING`,e[e.CREATED=1]=`CREATED`,e[e.FINALIZED=2]=`FINALIZED`,e[e.DETACHING=3]=`DETACHING`,e[e.DEAD=4]=`DEAD`})(th||={});function nh(e){return!!(e&&e.$treenode)}function rh(e,t){Rh(e,nh,`mobx-state-tree node`,t)}function ih(e){if(!nh(e))throw new K(`Value ${e} is no MST Node`);return e.$treenode}function ah(e){return e&&e.$treenode||null}function oh(){return ih(this).snapshot}function sh(e,t,n){return n===void 0&&(n=!0),ch(e,Yh(t),n)}function ch(e,t,n){n===void 0&&(n=!0);var r=e;try{for(var i=0;i<t.length;i++){var a=t[i];if(a===`..`){if(r=r.parent,r)continue}else if(a===`.`)continue;else if(r){if(r instanceof hm){var o=r.value;nh(o)&&(r=ih(o))}if(r instanceof bm&&r.getChildType(a)&&(r=r.getChildNode(a),r))continue}throw new K(`Could not resolve '${a}' in path '${Jh(t.slice(0,i))||`/`}' while resolving '${Jh(t)}'`)}}catch(e){if(!n)return;throw e}return r}function lh(e){if(!e)return dh;var t=Object.keys(e);if(!t.length)return dh;var n=Array(t.length);return t.forEach(function(t,r){n[r]=e[t]}),n}var uh=Object.toString(),dh=Object.freeze([]),fh=Object.freeze({}),ph=fn().useProxies?{deep:!1}:{deep:!1,proxy:!1};Object.freeze(ph);var K=function(e){Kp(t,e);function t(t){return t===void 0&&(t=`Illegal state`),e.call(this,`[mobx-state-tree] ${t}`)||this}return t}(Error);function mh(e){return e}var hh=Number.isInteger;function gh(e){return Number(e)===e&&e%1!=0}function _h(e){return Number.isFinite(e)}function vh(e){return Array.isArray(e)||ni(e)}function yh(e){return e?vh(e)?e:[e]:dh}function bh(e){for(var t=[...arguments].slice(1),n=0;n<t.length;n++){var r=t[n];for(var i in r)e[i]=r[i]}return e}function xh(e){if(typeof e!=`object`||!e)return!1;var t=Object.getPrototypeOf(e);return t==null?!0:t.constructor?.toString()===uh}function Sh(e){return typeof e==`object`&&!!e&&!(e instanceof Date)&&!(e instanceof RegExp)}function Ch(e,t){return t===void 0&&(t=!0),e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`||t&&e instanceof Date}function wh(e){return Lh()?Ch(e)||ni(e)?e:Object.freeze(e):e}function Th(e){return Lh()?(wh(e),xh(e)&&Object.keys(e).forEach(function(t){!Ch(e[t])&&!Object.isFrozen(e[t])&&Th(e[t])}),e):e}function Eh(e){return typeof e!=`function`}function Dh(e,t,n){bi(e)?Er(e,t,n):Object.defineProperty(e,t,n)}function Oh(e,t,n){Dh(e,t,{enumerable:!1,writable:!1,configurable:!0,value:n})}function kh(e,t,n){Dh(e,t,{enumerable:!1,writable:!0,configurable:!0,value:n})}var Ah=function(){function e(){Object.defineProperty(this,`handlers`,{enumerable:!0,configurable:!0,writable:!0,value:[]})}return Object.defineProperty(e.prototype,`hasSubscribers`,{get:function(){return this.handlers.length>0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`register`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;return t===void 0&&(t=!1),t?this.handlers.unshift(e):this.handlers.push(e),function(){n.unregister(e)}}}),Object.defineProperty(e.prototype,`has`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.handlers.indexOf(e)>=0}}),Object.defineProperty(e.prototype,`unregister`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.handlers.indexOf(e);t>=0&&this.handlers.splice(t,1)}}),Object.defineProperty(e.prototype,`clear`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.handlers.length=0}}),Object.defineProperty(e.prototype,`emit`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=[...arguments];this.handlers.slice().forEach(function(t){return t.apply(void 0,Zp([],Xp(e),!1))})}}),e}(),jh=function(){function e(){Object.defineProperty(this,`eventHandlers`,{enumerable:!0,configurable:!0,writable:!0,value:void 0})}return Object.defineProperty(e.prototype,`hasSubscribers`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.eventHandlers&&this.eventHandlers[e];return!!t&&t.hasSubscribers}}),Object.defineProperty(e.prototype,`register`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){n===void 0&&(n=!1),this.eventHandlers||={};var r=this.eventHandlers[e];return r||=this.eventHandlers[e]=new Ah,r.register(t,n)}}),Object.defineProperty(e.prototype,`has`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.eventHandlers&&this.eventHandlers[e];return!!n&&n.has(t)}}),Object.defineProperty(e.prototype,`unregister`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.eventHandlers&&this.eventHandlers[e];n&&n.unregister(t)}}),Object.defineProperty(e.prototype,`clear`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.eventHandlers&&delete this.eventHandlers[e]}}),Object.defineProperty(e.prototype,`clearAll`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.eventHandlers=void 0}}),Object.defineProperty(e.prototype,`emit`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){for(var t,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var i=this.eventHandlers&&this.eventHandlers[e];i&&(t=i).emit.apply(t,Zp([],Xp(n),!1))}}),e}();function Mh(e){for(var t=Array(e.length),n=0;n<e.length;n++)t[n]=e[n];return t}function Nh(e,t){return e.indexOf(t)===0}var Ph=function(e,t){Lh()&&(Ph.ids&&!Ph.ids.hasOwnProperty(e)&&Fh(`Deprecation warning: `+t),Ph.ids&&(Ph.ids[e]=!0))};Ph.ids={};function Fh(e){console.warn(Error(`[mobx-state-tree] ${e}`))}function Ih(){return Lh()||typeof process<`u`&&{}.ENABLE_TYPE_CHECK===`true`}function Lh(){return!1}function Rh(e,t,n,r){if(Lh()&&!t(e))throw new K(`expected ${n} as argument ${yh(r).join(` or `)}, got ${e} instead`)}function zh(e,t){Rh(e,function(e){return typeof e==`function`},`function`,t)}function Bh(e,t,n,r){Rh(e,function(e){return typeof e==`number`},`number`,t),n!==void 0&&Rh(e,function(e){return e>=n},`number greater than ${n}`,t),r!==void 0&&Rh(e,function(e){return e<=r},`number lesser than ${r}`,t)}function Vh(e,t,n){n===void 0&&(n=!0),Rh(e,function(e){return typeof e==`string`},`string`,t),n||Rh(e,function(e){return e!==``},`not empty string`,t)}function Hh(e){if(!(`oldValue`in e))throw new K("Patches without `oldValue` field cannot be inversed");return[Uh(e),Wh(e)]}function Uh(e){switch(e.op){case`add`:return{op:`add`,path:e.path,value:e.value};case`remove`:return{op:`remove`,path:e.path};case`replace`:return{op:`replace`,path:e.path,value:e.value}}}function Wh(e){switch(e.op){case`add`:return{op:`remove`,path:e.path};case`remove`:return{op:`add`,path:e.path,value:e.oldValue};case`replace`:return{op:`replace`,path:e.path,value:e.oldValue}}}function Gh(e){return typeof e==`number`}function Kh(e){return Gh(e)===!0?``+e:e.indexOf(`/`)===-1&&e.indexOf(`~`)===-1?e:e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function qh(e){return e.replace(/~1/g,`/`).replace(/~0/g,`~`)}function Jh(e){if(e.length===0)return``;var t=function(e){return e.map(Kh).join(`/`)};return e[0]===`.`||e[0]===`..`?t(e):`/`+t(e)}function Yh(e){var t=e.split(`/`).map(qh);if(!(e===``||e===`.`||e===`..`||Nh(e,`/`)||Nh(e,`./`)||Nh(e,`../`)))throw new K(`a json path must be either rooted, empty or relative, but got '${e}'`);return t[0]===``&&t.shift(),t}var Xh=Symbol(`$preProcessorFailed`),Zh=function(e){Kp(t,e);function t(t,n,r){var i=e.call(this,r||t.name)||this;return Object.defineProperty(i,`_subtype`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(i,`_processors`,{enumerable:!0,configurable:!0,writable:!0,value:n}),i}return Object.defineProperty(t.prototype,`flags`,{get:function(){return this._subtype.flags|Sm.SnapshotProcessor},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return`snapshotProcessor(${this._subtype.describe()})`}}),Object.defineProperty(t.prototype,`preProcessSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._processors.preProcessor?this._processors.preProcessor.call(null,e):e}}),Object.defineProperty(t.prototype,`preProcessSnapshotSafe`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){try{return this.preProcessSnapshot(e)}catch{return Xh}}}),Object.defineProperty(t.prototype,`postProcessSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this._processors.postProcessor?this._processors.postProcessor.call(null,e,t.storedValue):e}}),Object.defineProperty(t.prototype,`_fixNode`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;Qh(e.type,this,`create`),e instanceof bm&&(e.hasSnapshotPostProcessor=!!this._processors.postProcessor);var n=e.getSnapshot;e.getSnapshot=function(){return t.postProcessSnapshot(n.call(e),e)},Bg(this._subtype)||(e.getReconciliationType=function(){return t})}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=nh(r)?r:this.preProcessSnapshot(r),a=this._subtype.instantiate(e,t,n,i);return this._fixNode(a),a}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=this._subtype.reconcile(e,nh(t)?t:this.preProcessSnapshot(t),n,r);return i!==e&&this._fixNode(i),i}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){t===void 0&&(t=!0);var n=this._subtype.getSnapshot(e);return t?this.postProcessSnapshot(n,e):n}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.preProcessSnapshotSafe(e);return n===Xh?Gm(t,e,`Failed to preprocess value`):this._subtype.validate(n,t)}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),Object.defineProperty(t.prototype,`is`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=Om(e)?this._subtype:nh(e)?e:this.preProcessSnapshotSafe(e);return t===Xh?!1:this._subtype.validate(t,[{path:``,type:this._subtype}]).length===0}}),Object.defineProperty(t.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._subtype.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,`isMatchingSnapshotId`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(!(this._subtype instanceof Em))return!1;var n=this.preProcessSnapshot(t);return this._subtype.isMatchingSnapshotId(e,n)}}),t}(Tm);function Qh(e,t){for(var n,r,i=[],a=2;a<arguments.length;a++)i[a-2]=arguments[a];try{for(var o=Yp(i),s=o.next();!s.done;s=o.next()){var c=s.value;e[c]=t[c].bind(t)}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}}function $h(e,t,n){if(km(e,1),Lh()){if(t.postProcessor&&typeof t.postProcessor!=`function`)throw new K(`postSnapshotProcessor must be a function`);if(t.preProcessor&&typeof t.preProcessor!=`function`)throw new K(`preSnapshotProcessor must be a function`)}return new Zh(e,t,n)}var eg=`Map.put can only be used to store complex values that have an identifier type attribute`;function tg(e,t){var n,r,i=e.getSubTypes();if(i===Cm)return!1;if(i){var a=yh(i);try{for(var o=Yp(a),s=o.next();!s.done;s=o.next()){var c=s.value;if(!tg(c,t))return!1}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}}return e instanceof gg&&t.push(e),!0}var ng;(function(e){e[e.UNKNOWN=0]=`UNKNOWN`,e[e.YES=1]=`YES`,e[e.NO=2]=`NO`})(ng||={});var rg=function(e){Kp(t,e);function t(t,n){return e.call(this,t,L.ref.enhancer,n)||this}return Object.defineProperty(t.prototype,`get`,{enumerable:!1,configurable:!0,writable:!0,value:function(t){return e.prototype.get.call(this,``+t)}}),Object.defineProperty(t.prototype,`has`,{enumerable:!1,configurable:!0,writable:!0,value:function(t){return e.prototype.has.call(this,``+t)}}),Object.defineProperty(t.prototype,`delete`,{enumerable:!1,configurable:!0,writable:!0,value:function(t){return e.prototype.delete.call(this,``+t)}}),Object.defineProperty(t.prototype,`set`,{enumerable:!1,configurable:!0,writable:!0,value:function(t,n){return e.prototype.set.call(this,``+t,n)}}),Object.defineProperty(t.prototype,`put`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!e)throw new K(`Map.put cannot be used to set empty values`);if(nh(e)){var t=ih(e);if(Lh()&&!t.identifierAttribute||t.identifier===null)throw new K(eg);return this.set(t.identifier,e),e}else if(Sh(e)){var n=ih(this),r=n.type;if(r.identifierMode!==ng.YES)throw new K(eg);var i=e[r.mapIdentifierAttribute];if(!g_(i)){var a=this.put(r.getChildType().create(e,n.environment));return this.put(nm(a))}var o=h_(i);return this.set(o,e),this.get(o)}else throw new K(`Map.put can only be used to store complex values`)}}),t}(oi),ig=function(e){Kp(t,e);function t(t,n,r){r===void 0&&(r=[]);var i=e.call(this,t)||this;return Object.defineProperty(i,`_subType`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(i,`identifierMode`,{enumerable:!0,configurable:!0,writable:!0,value:ng.UNKNOWN}),Object.defineProperty(i,`mapIdentifierAttribute`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Sm.Map}),Object.defineProperty(i,`hookInitializers`,{enumerable:!0,configurable:!0,writable:!0,value:[]}),i._determineIdentifierMode(),i.hookInitializers=r,i}return Object.defineProperty(t.prototype,`hooks`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=this.hookInitializers.length>0?this.hookInitializers.concat(e):[e];return new t(this.name,this._subType,n)}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return this._determineIdentifierMode(),Qm(this,e,t,n,r)}}),Object.defineProperty(t.prototype,`_determineIdentifierMode`,{enumerable:!1,configurable:!0,writable:!0,value:function(){if(this.identifierMode===ng.UNKNOWN){var e=[];if(tg(this._subType,e)){var t=e.reduce(function(e,t){if(!t.identifierAttribute)return e;if(e&&e!==t.identifierAttribute)throw new K(`The objects in a map should all have the same identifier attribute, expected '${e}', but child of type '${t.name}' declared attribute '${t.identifierAttribute}' as identifier`);return t.identifierAttribute},void 0);t?(this.identifierMode=ng.YES,this.mapIdentifierAttribute=t):this.identifierMode=ng.NO}}}}),Object.defineProperty(t.prototype,`initializeChildNodes`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){t===void 0&&(t={});var n=e.type._subType,r={};return Object.keys(t).forEach(function(i){r[i]=n.instantiate(e,i,void 0,t[i])}),r}}),Object.defineProperty(t.prototype,`createNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return new rg(e,this.name)}}),Object.defineProperty(t.prototype,`finalizeNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){gr(t,e.unbox),e.type.hookInitializers.forEach(function(e){var n=e(t);Object.keys(n).forEach(function(e){var r=n[e],i=Im(t,e,r);(Lh()?kh:Oh)(t,e,i)})}),_r(t,this.willChange),Dr(t,this.didChange)}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,`getChildren`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return Cr(e.storedValue)}}),Object.defineProperty(t.prototype,`getChildNode`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=e.storedValue.get(``+t);if(!n)throw new K(`Not a child `+t);return n}}),Object.defineProperty(t.prototype,`willChange`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=ih(e.object),n=e.name;t.assertWritable({subpath:n});var r=t.type,i=r._subType;switch(e.type){case`update`:var a=e.newValue;if(a===e.object.get(n))return null;qm(i,a),e.newValue=i.reconcile(t.getChildNode(n),e.newValue,t,n),r.processIdentifier(n,e.newValue);break;case`add`:qm(i,e.newValue),e.newValue=i.instantiate(t,n,void 0,e.newValue),r.processIdentifier(n,e.newValue);break}return e}}),Object.defineProperty(t.prototype,`processIdentifier`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this.identifierMode===ng.YES&&t instanceof bm){var n=t.identifier;if(n!==e)throw new K(`A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '${n}', but expected: '${e}'`)}}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t={};return e.getChildren().forEach(function(e){t[e.subpath]=e.snapshot}),t}}),Object.defineProperty(t.prototype,`processInitialSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t={};return Object.keys(e).forEach(function(n){t[n]=e[n].getSnapshot()}),t}}),Object.defineProperty(t.prototype,`didChange`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=ih(e.object);switch(e.type){case`update`:t.emitPatch({op:`replace`,path:Kh(e.name),value:e.newValue.snapshot,oldValue:e.oldValue?e.oldValue.snapshot:void 0},t);return;case`add`:t.emitPatch({op:`add`,path:Kh(e.name),value:e.newValue.snapshot,oldValue:void 0},t);return;case`delete`:var n=e.oldValue.snapshot;e.oldValue.die(),t.emitPatch({op:`remove`,path:Kh(e.name),oldValue:n},t);return}}}),Object.defineProperty(t.prototype,`applyPatchLocally`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){var r=e.storedValue;switch(n.op){case`add`:case`replace`:r.set(t,n.value);break;case`remove`:r.delete(t);break}}}),Object.defineProperty(t.prototype,`applySnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){qm(this,t);var n=e.storedValue,r={};if(Array.from(n.keys()).forEach(function(e){r[e]=!1}),t)for(var i in t)n.set(i,t[i]),r[``+i]=!0;Object.keys(r).forEach(function(e){r[e]===!1&&n.delete(e)})}}),Object.defineProperty(t.prototype,`getChildType`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subType}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;return xh(e)?Km(Object.keys(e).map(function(r){return n._subType.validate(e[r],Um(t,r,n._subType))})):Gm(t,e,`Value is not a plain object`)}}),Object.defineProperty(t.prototype,`getDefaultSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return fh}}),Object.defineProperty(t.prototype,`removeChild`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){e.storedValue.delete(t)}}),t}(Em);ig.prototype.applySnapshot=Vn(ig.prototype.applySnapshot);function ag(e){return new ig(`Map<string, ${e.name}>`,e)}var og=function(e){Kp(t,e);function t(t,n,r){r===void 0&&(r=[]);var i=e.call(this,t)||this;return Object.defineProperty(i,`_subType`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(i,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Sm.Array}),Object.defineProperty(i,`hookInitializers`,{enumerable:!0,configurable:!0,writable:!0,value:[]}),i.hookInitializers=r,i}return Object.defineProperty(t.prototype,`hooks`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=this.hookInitializers.length>0?this.hookInitializers.concat(e):[e];return new t(this.name,this._subType,n)}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return Qm(this,e,t,n,r)}}),Object.defineProperty(t.prototype,`initializeChildNodes`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){t===void 0&&(t=[]);var n=e.type._subType,r={};return t.forEach(function(t,i){var a=``+i;r[a]=n.instantiate(e,a,void 0,t)}),r}}),Object.defineProperty(t.prototype,`createNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=qp(qp({},ph),{name:this.name});return L.array(lh(e),t)}}),Object.defineProperty(t.prototype,`finalizeNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){Ni(t).dehancer=e.unbox,e.type.hookInitializers.forEach(function(e){var n=e(t);Object.keys(n).forEach(function(e){var r=n[e],i=Im(t,e,r);(Lh()?kh:Oh)(t,e,i)})}),_r(t,this.willChange),Dr(t,this.didChange)}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,`getChildren`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue.slice()}}),Object.defineProperty(t.prototype,`getChildNode`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=Number(t);if(n<e.storedValue.length)return e.storedValue[n];throw new K(`Not a child: `+t)}}),Object.defineProperty(t.prototype,`willChange`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=ih(e.object);t.assertWritable({subpath:``+e.index});var n=t.type._subType,r=t.getChildren();switch(e.type){case`update`:if(e.newValue===e.object[e.index])return null;var i=cg(t,n,[r[e.index]],[e.newValue],[e.index]);if(!i)return null;e.newValue=i[0];break;case`splice`:var a=e.index,o=e.removedCount,s=e.added,c=cg(t,n,r.slice(a,a+o),s,s.map(function(e,t){return a+t}));if(!c)return null;e.added=c;for(var l=a+o;l<r.length;l++)r[l].setParent(t,``+(l+s.length-o));break}return e}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.getChildren().map(function(e){return e.snapshot})}}),Object.defineProperty(t.prototype,`processInitialSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=[];return Object.keys(e).forEach(function(n){t.push(e[n].getSnapshot())}),t}}),Object.defineProperty(t.prototype,`didChange`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=ih(e.object);switch(e.type){case`update`:t.emitPatch({op:`replace`,path:``+e.index,value:e.newValue.snapshot,oldValue:e.oldValue?e.oldValue.snapshot:void 0},t);return;case`splice`:if(e.removedCount&&e.addedCount===e.object.length){t.emitPatch({op:`replace`,path:``,value:t.snapshot,oldValue:e.removed.map(function(e){return e.snapshot})},t);return}for(var n=e.removedCount-1;n>=0;n--)t.emitPatch({op:`remove`,path:``+(e.index+n),oldValue:e.removed[n].snapshot},t);for(var n=0;n<e.addedCount;n++)t.emitPatch({op:`add`,path:``+(e.index+n),value:e.added[n].snapshot,oldValue:void 0},t);return}}}),Object.defineProperty(t.prototype,`applyPatchLocally`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){var r=e.storedValue,i=t===`-`?r.length:Number(t);switch(n.op){case`replace`:r[i]=n.value;break;case`add`:r.splice(i,0,n.value);break;case`remove`:r.splice(i,1);break}}}),Object.defineProperty(t.prototype,`applySnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){qm(this,t),e.storedValue.replace(t)}}),Object.defineProperty(t.prototype,`getChildType`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subType}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;return vh(e)?Km(e.map(function(e,r){return n._subType.validate(e,Um(t,``+r,n._subType))})):Gm(t,e,`Value is not an array`)}}),Object.defineProperty(t.prototype,`getDefaultSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return dh}}),Object.defineProperty(t.prototype,`removeChild`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){e.storedValue.splice(Number(t),1)}}),t}(Em);og.prototype.applySnapshot=Vn(og.prototype.applySnapshot);function sg(e){return km(e,1),new og(`${e.name}[]`,e)}function cg(e,t,n,r,i){for(var a=!0,o=0;;o++){var s=o<=r.length-1,c=n[o],l=s?r[o]:void 0,u=``+i[o];if(eh(l)&&(l=l.storedValue),!c&&!s)break;if(!s)a=!1,n.splice(o,1),c instanceof bm&&c.createObservableInstanceIfNeeded(),c.die(),o--;else if(!c){if(nh(l)&&ih(l).parent===e)throw new K(`Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '${e.path}/${u}', but it lives already at '${ih(l).path}'`);a=!1;var d=lg(t,e,u,l);n.splice(o,0,d)}else if(ug(c,l))n[o]=lg(t,e,u,l,c);else{for(var f=void 0,p=o;p<n.length;p++)if(ug(n[p],l)){f=n.splice(p,1)[0];break}a=!1;var d=lg(t,e,u,l,f);n.splice(o,0,d)}}return a?null:n}function lg(e,t,n,r,i){qm(e,r);function a(){if(nh(r)){var a=ih(r);if(a.assertAlive(fh),a.parent!==null&&a.parent===t)return a.setParent(t,n),a}return i?e.reconcile(i,r,t,n):e.instantiate(t,n,void 0,r)}var o=a();return i&&i!==o&&(i instanceof bm&&i.createObservableInstanceIfNeeded(),i.die()),o}function ug(e,t){if(!e.isAlive)return!1;if(nh(t)){var n=ih(t);return n.isAlive&&n===e}if(e.snapshot===t)return!0;if(!(e instanceof bm))return!1;var r=e.getReconciliationType();return e.identifier!==null&&e.identifierAttribute&&xh(t)&&r.is(t)&&r.isMatchingSnapshotId(e,t)}var dg=`preProcessSnapshot`,fg=`postProcessSnapshot`;function pg(){return ih(this).toString()}var mg={name:`AnonymousModel`,properties:{},initializers:dh};function hg(e){var t=Object.keys(e),n=new Set;return t.forEach(function(e){if(n.has(e))throw new K(`${e} is declared twice in the model. Model should not contain the same keys`);n.add(e)}),t.reduce(function(t,n){if(n in Wp)throw new K(`Hook '${n}' was defined as property. Hooks should be defined as part of the actions`);var r=Object.getOwnPropertyDescriptor(e,n);if(`get`in r)throw new K(`Getters are not supported as properties. Please use views instead`);var i=r.value;if(i==null)throw new K("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");if(Ch(i))t[n]=Ug(jg(i),i);else if(i instanceof ig)t[n]=Ug(i,{});else if(i instanceof og)t[n]=Ug(i,[]);else if(!Om(i))throw Lh()&&typeof i==`function`?new K(`Invalid type definition for property '${n}', it looks like you passed a function. Did you forget to invoke it, or did you intend to declare a view / action?`):Lh()&&typeof i==`object`?new K(`Invalid type definition for property '${n}', it looks like you passed an object. Try passing another model type or a types.frozen.`):new K(`Invalid type definition for property '${n}', cannot infer a type from a value like '${i}' (${typeof i})`);return t},qp({},e))}var gg=function(e){Kp(t,e);function t(t){var n=e.call(this,t.name||mg.name)||this;return Object.defineProperty(n,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Sm.Object}),Object.defineProperty(n,`initializers`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,`properties`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,`preProcessor`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,`postProcessor`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,`propertyNames`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,`named`,{enumerable:!0,configurable:!0,writable:!0,value:function(e){return n.cloneAndEnhance({name:e})}}),Object.defineProperty(n,`props`,{enumerable:!0,configurable:!0,writable:!0,value:function(e){return n.cloneAndEnhance({properties:e})}}),Object.defineProperty(n,`preProcessSnapshot`,{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=n.preProcessor;return t?n.cloneAndEnhance({preProcessor:function(n){return t(e(n))}}):n.cloneAndEnhance({preProcessor:e})}}),Object.defineProperty(n,`postProcessSnapshot`,{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=n.postProcessor;return t?n.cloneAndEnhance({postProcessor:function(n){return e(t(n))}}):n.cloneAndEnhance({postProcessor:e})}}),Object.assign(n,mg,t),n.properties=hg(n.properties),wh(n.properties),n.propertyNames=Object.keys(n.properties),n.identifierAttribute=n._getIdentifierAttribute(),n}return Object.defineProperty(t.prototype,`_getIdentifierAttribute`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=void 0;return this.forAllProps(function(t,n){if(n.flags&Sm.Identifier){if(e)throw new K(`Cannot define property '${t}' as object identifier, property '${e}' is already defined as identifier property`);e=t}}),e}}),Object.defineProperty(t.prototype,`cloneAndEnhance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return new t({name:e.name||this.name,properties:Object.assign({},this.properties,e.properties),initializers:this.initializers.concat(e.initializers||[]),preProcessor:e.preProcessor||this.preProcessor,postProcessor:e.postProcessor||this.postProcessor})}}),Object.defineProperty(t.prototype,`actions`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;return this.cloneAndEnhance({initializers:[function(n){return t.instantiateActions(n,e(n)),n}]})}}),Object.defineProperty(t.prototype,`instantiateActions`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;if(!xh(t))throw new K(`actions initializer should return a plain object containing actions`);Object.getOwnPropertyNames(t).forEach(function(r){if(r in n.properties)throw new K(`'${r}' is a property and cannot be declared as an action`);if(r===dg)throw new K(`Cannot define action '${dg}', it should be defined using 'type.preProcessSnapshot(fn)' instead`);if(r===fg)throw new K(`Cannot define action '${fg}', it should be defined using 'type.postProcessSnapshot(fn)' instead`);var i=t[r],a=e[r];if(r in Wp&&a){var o=i;i=function(){a.apply(null,arguments),o.apply(null,arguments)}}var s=i.$mst_middleware,c=i.bind(t);c._isFlowAction=i._isFlowAction||!1,c.$mst_middleware=s;var l=Im(e,r,c);t[r]=l,(Lh()?kh:Oh)(e,r,l)})}}),Object.defineProperty(t.prototype,`volatile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;if(typeof e!=`function`)throw new K(`You passed an ${typeof e} to volatile state as an argument, when function is expected`);return this.cloneAndEnhance({initializers:[function(n){return t.instantiateVolatileState(n,e(n)),n}]})}}),Object.defineProperty(t.prototype,`instantiateVolatileState`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;if(!xh(t))throw new K(`volatile state initializer should return a plain object containing state`);Object.getOwnPropertyNames(t).forEach(function(r){if(r in n.properties)throw new K(`'${r}' is a property and cannot be declared as volatile state`);Tr(e,r,t[r])})}}),Object.defineProperty(t.prototype,`extend`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;return this.cloneAndEnhance({initializers:[function(n){var r=e(n),i=r.actions,a=r.views,o=r.state;for(var s in Jp(r,[`actions`,`views`,`state`]))throw new K(`The \`extend\` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '${s}'`);return o&&t.instantiateVolatileState(n,o),a&&t.instantiateViews(n,a),i&&t.instantiateActions(n,i),n}]})}}),Object.defineProperty(t.prototype,`views`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;return this.cloneAndEnhance({initializers:[function(n){return t.instantiateViews(n,e(n)),n}]})}}),Object.defineProperty(t.prototype,`instantiateViews`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;if(!xh(t))throw new K(`views initializer should return a plain object containing views`);Object.getOwnPropertyNames(t).forEach(function(r){var i;if(r in n.properties)throw new K(`'${r}' is a property and cannot be declared as a view`);var a=Object.getOwnPropertyDescriptor(t,r);if(`get`in a)Er(e,r,a),Ur(e,(i={},i[r]=jt,i));else if(typeof a.value==`function`)(Lh()?kh:Oh)(e,r,a.value);else throw new K(`A view member should either be a function or getter based property`)})}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=nh(r)?r:this.applySnapshotPreProcessor(r);return Qm(this,e,t,n,i)}}),Object.defineProperty(t.prototype,`initializeChildNodes`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){t===void 0&&(t={});var n=e.type,r={};return n.forAllProps(function(n,i){r[n]=i.instantiate(e,n,void 0,t[n])}),r}}),Object.defineProperty(t.prototype,`createNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=qp(qp({},ph),{name:this.name});return L.object(e,fh,t)}}),Object.defineProperty(t.prototype,`finalizeNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){Oh(t,`toString`,pg),this.forAllProps(function(n){gr(t,n,e.unbox)}),this.initializers.reduce(function(e,t){return t(e)},t),_r(t,this.willChange),Dr(t,this.didChange)}}),Object.defineProperty(t.prototype,`willChange`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e,n=ih(t.object),r=t.name;n.assertWritable({subpath:r});var i=n.type.properties[r];return i&&(qm(i,t.newValue),t.newValue=i.reconcile(n.getChildNode(r),t.newValue,n,r)),t}}),Object.defineProperty(t.prototype,`didChange`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e,n=ih(t.object);if(n.type.properties[t.name]){var r=t.oldValue?t.oldValue.snapshot:void 0;n.emitPatch({op:`replace`,path:Kh(t.name),value:t.newValue.snapshot,oldValue:r},n)}}}),Object.defineProperty(t.prototype,`getChildren`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this,n=[];return this.forAllProps(function(r){n.push(t.getChildNode(e,r))}),n}}),Object.defineProperty(t.prototype,`getChildNode`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(!(t in this.properties))throw new K(`Not a value property: `+t);var n=Ni(e.storedValue,t),r=n.raw?.call(n);if(!r)throw new K(`Node not available for property `+t);return r}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;t===void 0&&(t=!0);var r={};return this.forAllProps(function(t,i){Mi(e.storedValue,t).reportObserved(),r[t]=n.getChildNode(e,t).snapshot}),t?this.applySnapshotPostProcessor(r):r}}),Object.defineProperty(t.prototype,`processInitialSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t={};return Object.keys(e).forEach(function(n){t[n]=e[n].getSnapshot()}),this.applySnapshotPostProcessor(t)}}),Object.defineProperty(t.prototype,`applyPatchLocally`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){if(!(n.op===`replace`||n.op===`add`))throw new K(`object does not support operation ${n.op}`);e.storedValue[t]=n.value}}),Object.defineProperty(t.prototype,`applySnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){qm(this,t);var n=this.applySnapshotPreProcessor(t);this.forAllProps(function(t){e.storedValue[t]=n[t]})}}),Object.defineProperty(t.prototype,`applySnapshotPreProcessor`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.preProcessor;return t?t.call(null,e):e}}),Object.defineProperty(t.prototype,`applySnapshotPostProcessor`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.postProcessor;return t?t.call(null,e):e}}),Object.defineProperty(t.prototype,`getChildType`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return Vh(e,1),this.properties[e]}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this,r=this.applySnapshotPreProcessor(e);return xh(r)?Km(this.propertyNames.map(function(e){return n.properties[e].validate(r[e],Um(t,e,n.properties[e]))})):Gm(t,r,`Value is not a plain object`)}}),Object.defineProperty(t.prototype,`forAllProps`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this.propertyNames.forEach(function(n){return e(n,t.properties[n])})}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;return`{ `+this.propertyNames.map(function(t){return t+`: `+e.properties[t].describe()}).join(`; `)+` }`}}),Object.defineProperty(t.prototype,`getDefaultSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return fh}}),Object.defineProperty(t.prototype,`removeChild`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){e.storedValue[t]=void 0}}),t}(Em);gg.prototype.applySnapshot=Vn(gg.prototype.applySnapshot);function _g(){var e=[...arguments];if(Lh()&&typeof e[0]!=`string`&&e[1])throw new K(`Model creation failed. First argument must be a string when two arguments are provided`);return new gg({name:typeof e[0]==`string`?e.shift():`AnonymousModel`,properties:e.shift()||{}})}function vg(){var e=[...arguments],t=typeof e[0]==`string`,n=t?e[0]:`AnonymousModel`;return t&&e.shift(),Lh()&&e.forEach(function(e,n){Rh(e,yg,`mobx-state-tree model type`,t?n+2:n+1)}),e.reduce(function(e,t){return e.cloneAndEnhance({name:e.name+`_`+t.name,properties:t.properties,initializers:t.initializers,preProcessor:function(n){return t.applySnapshotPreProcessor(e.applySnapshotPreProcessor(n))},postProcessor:function(n){return t.applySnapshotPostProcessor(e.applySnapshotPostProcessor(n))}})}).named(n)}function yg(e){return Om(e)&&(e.flags&Sm.Object)>0}var bg=function(e){Kp(t,e);function t(t,n,r,i){i===void 0&&(i=mh);var a=e.call(this,t)||this;return Object.defineProperty(a,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(a,`checker`,{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(a,`initializer`,{enumerable:!0,configurable:!0,writable:!0,value:i}),a.flags=n,a}return Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return $m(this,e,t,n,r)}}),Object.defineProperty(t.prototype,`createNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.initializer(e)}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return Ch(e)&&this.checker(e)?Wm():Gm(t,e,`Value is not a ${this.name===`Date`?`Date or a unix milliseconds timestamp`:this.name}`)}}),t}(Dm),xg=new bg(`string`,Sm.String,function(e){return typeof e==`string`}),Sg=new bg(`number`,Sm.Number,function(e){return typeof e==`number`}),Cg=new bg(`integer`,Sm.Integer,function(e){return hh(e)}),wg=new bg(`float`,Sm.Float,function(e){return gh(e)}),Tg=new bg(`finite`,Sm.Finite,function(e){return _h(e)}),Eg=new bg(`boolean`,Sm.Boolean,function(e){return typeof e==`boolean`}),Dg=new bg(`null`,Sm.Null,function(e){return e===null}),Og=new bg(`undefined`,Sm.Undefined,function(e){return e===void 0}),kg=new bg(`Date`,Sm.Date,function(e){return typeof e==`number`||e instanceof Date},function(e){return e instanceof Date?e:new Date(e)});kg.getSnapshot=function(e){return e.storedValue.getTime()};var Ag=kg;function jg(e){switch(typeof e){case`string`:return xg;case`number`:return Sg;case`boolean`:return Eg;case`object`:if(e instanceof Date)return Ag}throw new K(`Cannot determine primitive type from value `+e)}function Mg(e){return Om(e)&&(e.flags&(Sm.String|Sm.Number|Sm.Integer|Sm.Boolean|Sm.Date))>0}var Ng=function(e){Kp(t,e);function t(t){var n=e.call(this,JSON.stringify(t))||this;return Object.defineProperty(n,`value`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Sm.Literal}),n.value=t,n}return Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return $m(this,e,t,n,r)}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return JSON.stringify(this.value)}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return Ch(e)&&e===this.value?Wm():Gm(t,e,`Value is not a literal ${JSON.stringify(this.value)}`)}}),t}(Dm);function Pg(e){return Rh(e,Ch,`primitive`,1),new Ng(e)}var Fg=function(e){Kp(t,e);function t(t,n,r,i){var a=e.call(this,t)||this;return Object.defineProperty(a,`_subtype`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(a,`_predicate`,{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(a,`_message`,{enumerable:!0,configurable:!0,writable:!0,value:i}),a}return Object.defineProperty(t.prototype,`flags`,{get:function(){return this._subtype.flags|Sm.Refinement},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return this._subtype.instantiate(e,t,n,r)}}),Object.defineProperty(t.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._subtype.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this._subtype.validate(e,t);if(n.length>0)return n;var r=nh(e)?ih(e).snapshot:e;return this._predicate(r)?Wm():Gm(t,e,this._message(e))}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return this._subtype.reconcile(e,t,n,r)}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),t}(Tm);function Ig(){var e=[...arguments],t=typeof e[0]==`string`?e.shift():Om(e[0])?e[0].name:null,n=e[0],r=e[1],i=e[2]?e[2]:function(e){return`Value does not respect the refinement predicate`};return km(n,[1,2]),Vh(t,1),zh(r,[2,3]),zh(i,[3,4]),new Fg(t,n,r,i)}function Lg(e,t){var n=typeof e==`string`?t:e;Lh()&&n.forEach(function(e,t){Vh(e,t+1)});var r=zg.apply(void 0,Zp([],Xp(n.map(function(e){return Pg(``+e)})),!1));return typeof e==`string`&&(r.name=e),r}var Rg=function(e){Kp(t,e);function t(t,n,r){var i=e.call(this,t)||this;return Object.defineProperty(i,`_types`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(i,`_dispatcher`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,`_eager`,{enumerable:!0,configurable:!0,writable:!0,value:!0}),r=qp({eager:!0,dispatcher:void 0},r),i._dispatcher=r.dispatcher,r.eager||(i._eager=!1),i}return Object.defineProperty(t.prototype,`flags`,{get:function(){var e=Sm.Union;return this._types.forEach(function(t){e|=t.flags}),e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._types.some(function(t){return t.isAssignableFrom(e)})}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return`(`+this._types.map(function(e){return e.describe()}).join(` | `)+`)`}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=this.determineType(r,void 0);if(!i)throw new K(`No matching type for union `+this.describe());return i.instantiate(e,t,n,r)}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=this.determineType(t,e.getReconciliationType());if(!i)throw new K(`No matching type for union `+this.describe());return i.reconcile(e,t,n,r)}}),Object.defineProperty(t.prototype,`determineType`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this._dispatcher?this._dispatcher(e):t?t.is(e)?t:this._types.filter(function(e){return e!==t}).find(function(t){return t.is(e)}):this._types.find(function(t){return t.is(e)})}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this._dispatcher)return this._dispatcher(e).validate(e,t);for(var n=[],r=0,i=0;i<this._types.length;i++){var a=this._types[i].validate(e,t);if(a.length===0){if(this._eager)return Wm();r++}else n.push(a)}return r===1?Wm():Gm(t,e,`No type is applicable for the union`).concat(Km(n))}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._types}}),t}(Tm);function zg(e){var t=[...arguments].slice(1),n=Om(e)?void 0:e,r=Om(e)?Zp([e],Xp(t),!1):t,i=`(`+r.map(function(e){return e.name}).join(` | `)+`)`;return Lh()&&(n&&Rh(n,function(e){return xh(e)},`object { eager?: boolean, dispatcher?: Function }`,1),r.forEach(function(e,t){km(e,n?t+2:t+1)})),new Rg(i,r,n)}function Bg(e){return Om(e)&&(e.flags&Sm.Union)>0}var Vg=function(e){Kp(t,e);function t(t,n,r){var i=e.call(this,t.name)||this;return Object.defineProperty(i,`_subtype`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(i,`_defaultValue`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(i,`optionalValues`,{enumerable:!0,configurable:!0,writable:!0,value:r}),i}return Object.defineProperty(t.prototype,`flags`,{get:function(){return this._subtype.flags|Sm.Optional},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype.describe()+`?`}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){if(this.optionalValues.indexOf(r)>=0){var i=this.getDefaultInstanceOrSnapshot();return this._subtype.instantiate(e,t,n,i)}return this._subtype.instantiate(e,t,n,r)}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return this._subtype.reconcile(e,this.optionalValues.indexOf(t)<0&&this._subtype.is(t)?t:this.getDefaultInstanceOrSnapshot(),n,r)}}),Object.defineProperty(t.prototype,`getDefaultInstanceOrSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=typeof this._defaultValue==`function`?this._defaultValue():this._defaultValue;return typeof this._defaultValue==`function`&&qm(this,e),e}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this.optionalValues.indexOf(e)>=0?Wm():this._subtype.validate(e,t)}}),Object.defineProperty(t.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._subtype.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),t}(Tm);function Hg(e,t){if(typeof t!=`function`&&nh(t))throw new K(`default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead`);km(e,1),Lh()&&typeof t!=`function`&&qm(e,t)}function Ug(e,t,n){return Hg(e,t),new Vg(e,t,n||Wg)}var Wg=[void 0],Gg=Ug(Og,void 0),Kg=Ug(Dg,null);function qg(e){return km(e,1),zg(e,Gg)}function Jg(e){return km(e,1),zg(e,Kg)}var Yg=function(e){Kp(t,e);function t(t,n){var r=e.call(this,t)||this;return Object.defineProperty(r,`_definition`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(r,`_subType`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),r}return Object.defineProperty(t.prototype,`flags`,{get:function(){return(this._subType?this._subType.flags:0)|Sm.Late},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`getSubType`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!this._subType){var t=void 0;try{t=this._definition()}catch(e){if(e instanceof ReferenceError)t=void 0;else throw e}if(e&&t===void 0)throw new K(`Late type seems to be used too early, the definition (still) returns undefined`);if(t){if(Lh()&&!Om(t))throw new K(`Failed to determine subtype, make sure types.late returns a type definition.`);this._subType=t}}return this._subType}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return this.getSubType(!0).instantiate(e,t,n,r)}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return this.getSubType(!0).reconcile(e,t,n,r)}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.getSubType(!1);return e?e.name:`<uknown late type>`}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.getSubType(!1);return n?n.validate(e,t):Wm()}}),Object.defineProperty(t.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.getSubType(!1);return t?t.isAssignableFrom(e):!1}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.getSubType(!1)||Cm}}),t}(Tm);function Xg(e,t){var n=typeof e==`string`?e:`late(${e.toString()})`,r=typeof e==`string`?t:e;if(Lh()&&!(typeof r==`function`&&r.length===0))throw new K(`Invalid late type, expected a function with zero arguments that returns a type, got: `+r);return new Yg(n,r)}function Zg(e,t){return new Qg(e,t)}var Qg=function(e){Kp(t,e);function t(t,n){var r=e.call(this,t)||this;return Object.defineProperty(r,`options`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(r,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Sm.Lazy}),Object.defineProperty(r,`loadedType`,{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(r,`pendingNodeList`,{enumerable:!0,configurable:!0,writable:!0,value:L.array()}),jr(function(){return r.pendingNodeList.length>0&&r.pendingNodeList.some(function(e){return e.isAlive&&r.options.shouldLoadPredicate(e.parent?e.parent.value:null)})},function(){r.options.loadType().then(Vn(function(e){r.loadedType=e,r.pendingNodeList.forEach(function(e){e.parent&&r.loadedType&&e.parent.applyPatches([{op:`replace`,path:`/${e.subpath}`,value:e.snapshot}])})}))}),r}return Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return`<lazy ${this.name}>`}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=this;if(this.loadedType)return this.loadedType.instantiate(e,t,n,r);var a=$m(this,e,t,n,Th(r));return this.pendingNodeList.push(a),jr(function(){return!a.isAlive},function(){return i.pendingNodeList.splice(i.pendingNodeList.indexOf(a),1)}),a}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this.loadedType?this.loadedType.validate(e,t):Eh(e)?Wm():Gm(t,e,`Value is not serializable and cannot be lazy`)}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(t,n,r,i){return this.loadedType?(t.die(),this.loadedType.instantiate(r,i,r.environment,n)):e.prototype.reconcile.call(this,t,n,r,i)}}),t}(Dm),$g=function(e){Kp(t,e);function t(t){var n=e.call(this,t?`frozen(${t.name})`:`frozen`)||this;return Object.defineProperty(n,`subType`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(n,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Sm.Frozen}),n}return Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return`<any immutable value>`}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return $m(this,e,t,n,Th(r))}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return Eh(e)?this.subType?this.subType.validate(e,t):Wm():Gm(t,e,`Value is not serializable and cannot be frozen`)}}),t}(Dm),e_=new $g;function t_(e){return arguments.length===0?e_:Om(e)?new $g(e):Ug(e_,e)}function n_(e){switch(e){case Wp.beforeDestroy:return`destroy`;case Wp.beforeDetach:return`detach`;default:return}}var r_=function(){function e(e,t){if(Object.defineProperty(this,`targetType`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,`identifier`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`node`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`resolvedReference`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),g_(e))this.identifier=e;else if(nh(e)){var n=ih(e);if(!n.identifierAttribute)throw new K(`Can only store references with a defined identifier attribute.`);var r=n.unnormalizedIdentifier;if(r==null)throw new K(`Can only store references to tree nodes with a defined identifier.`);this.identifier=r}else throw new K(`Can only store references to tree nodes or identifiers, got: '${e}'`)}return Object.defineProperty(e.prototype,`updateResolvedReference`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=h_(this.identifier),n=e.root,r=n.identifierCache.getLastCacheModificationPerId(t);if(!this.resolvedReference||this.resolvedReference.lastCacheModification!==r){var i=this.targetType,a=n.identifierCache.resolve(i,t);if(!a)throw new i_(`[mobx-state-tree] Failed to resolve reference '${this.identifier}' to type '${this.targetType.name}' (from node: ${e.path})`);this.resolvedReference={node:a,lastCacheModification:r}}}}),Object.defineProperty(e.prototype,`resolvedValue`,{get:function(){return this.updateResolvedReference(this.node),this.resolvedReference.node.value},enumerable:!1,configurable:!0}),e}(),i_=function(e){Kp(t,e);function t(n){var r=e.call(this,n)||this;return Object.setPrototypeOf(r,t.prototype),r}return t}(Error),a_=function(e){Kp(t,e);function t(t,n){var r=e.call(this,`reference(${t.name})`)||this;return Object.defineProperty(r,`targetType`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(r,`onInvalidated`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(r,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Sm.Reference}),r}return Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.targetType.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return g_(e)?Wm():Gm(t,e,`Value is not a valid identifier, which is a string or a number`)}}),Object.defineProperty(t.prototype,`fireInvalidated`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=t.parent;if(!(!i||!i.isAlive)){var a=i.storedValue;a&&this.onInvalidated({cause:e,parent:a,invalidTarget:r?r.storedValue:void 0,invalidId:n,replaceRef:function(e){em(t.root.storedValue,{op:`replace`,value:e,path:t.path})},removeRef:function(){yg(i.type)?this.replaceRef(void 0):em(t.root.storedValue,{op:`remove`,path:t.path})}})}}}),Object.defineProperty(t.prototype,`addTargetNodeWatcher`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this,r=this.getValue(e);if(r){var i=ih(r),a=function(r,a){var o=n_(a);o&&n.fireInvalidated(o,e,t,i)},o=i.registerHook(Wp.beforeDetach,a),s=i.registerHook(Wp.beforeDestroy,a);return function(){o(),s()}}}}),Object.defineProperty(t.prototype,`watchTargetNodeForInvalidations`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){var r=this;if(this.onInvalidated){var i;e.registerHook(Wp.beforeDestroy,function(){i&&i()});var a=function(a){i&&i();var o=e.parent,s=o&&o.storedValue;if(o&&o.isAlive&&s){var c=void 0;c=n?!!n.get(t,s):e.root.identifierCache.has(r.targetType,h_(t)),c?i=r.addTargetNodeWatcher(e,t):a||r.fireInvalidated(`invalidSnapshotReference`,e,t,null)}};e.state===th.FINALIZED?a(!0):(e.isRoot||e.root.registerHook(Wp.afterCreationFinalization,function(){e.parent&&e.parent.createObservableInstanceIfNeeded()}),e.registerHook(Wp.afterAttach,function(){a(!1)}))}}}),t}(Dm),o_=function(e){Kp(t,e);function t(t,n){return e.call(this,t,n)||this}return Object.defineProperty(t.prototype,`getValue`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(e.isAlive)return e.storedValue.resolvedValue}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue.identifier}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=nh(r)?lm(r):r,a=new r_(r,this.targetType),o=$m(this,e,t,n,a);return a.node=o,this.watchTargetNodeForInvalidations(o,i,void 0),o}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){if(!e.isDetaching&&e.type===this){var i=nh(t),a=e.storedValue;if(!i&&a.identifier===t||i&&a.resolvedValue===t)return e.setParent(n,r),e}var o=this.instantiate(n,r,void 0,t);return e.die(),o}}),t}(a_),s_=function(e){Kp(t,e);function t(t,n,r){var i=e.call(this,t,r)||this;return Object.defineProperty(i,`options`,{enumerable:!0,configurable:!0,writable:!0,value:n}),i}return Object.defineProperty(t.prototype,`getValue`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(e.isAlive)return this.options.get(e.storedValue,e.parent?e.parent.storedValue:null)}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=nh(r)?this.options.set(r,e?e.storedValue:null):r,a=$m(this,e,t,n,i);return this.watchTargetNodeForInvalidations(a,i,this.options),a}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=nh(t)?this.options.set(t,e?e.storedValue:null):t;if(!e.isDetaching&&e.type===this&&e.storedValue===i)return e.setParent(n,r),e;var a=this.instantiate(n,r,void 0,i);return e.die(),a}}),t}(a_);function c_(e,t){if(km(e,1),Lh()&&arguments.length===2&&typeof arguments[1]==`string`)throw new K(`References with base path are no longer supported. Please remove the base path.`);var n=t||void 0,r=t?t.onInvalidated:void 0;if(n&&(n.get||n.set)){if(Lh()&&(!n.get||!n.set))throw new K(`reference options must either contain both a 'get' and a 'set' method or none of them`);return new s_(e,{get:n.get,set:n.set},r)}else return new o_(e,r)}function l_(e,t){var n=c_(e,qp(qp({},t),{onInvalidated:function(e){t&&t.onInvalidated&&t.onInvalidated(e),e.removeRef()}}));return t&&t.acceptsUndefined===!1?n:qg(n)}var u_=function(e){Kp(t,e);function t(t,n){var r=e.call(this,t)||this;return Object.defineProperty(r,`validType`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(r,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Sm.Identifier}),r}return Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){if(!e||!(e.type instanceof gg))throw new K(`Identifier types can only be instantiated as direct child of a model type`);return $m(this,e,t,n,r)}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){if(e.storedValue!==t)throw new K(`Tried to change identifier from '${e.storedValue}' to '${t}'. Changing identifiers is not allowed.`);return e.setParent(n,r),e}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return typeof e===this.validType?Wm():Gm(t,e,`Value is not a valid ${this.describe()}, expected a ${this.validType}`)}}),t}(Dm),d_=function(e){Kp(t,e);function t(){var t=e.call(this,`identifier`,`string`)||this;return Object.defineProperty(t,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Sm.Identifier}),t}return Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return`identifier`}}),t}(u_),f_=function(e){Kp(t,e);function t(){return e.call(this,`identifierNumber`,`number`)||this}return Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return`identifierNumber`}}),t}(u_),p_=new d_,m_=new f_;function h_(e){return``+e}function g_(e){return typeof e==`string`||typeof e==`number`}function __(e){return new v_(e)}var v_=function(e){Kp(t,e);function t(t){var n=e.call(this,t.name)||this;return Object.defineProperty(n,`options`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(n,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Sm.Custom}),n}return Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this.options.isTargetType(e))return Wm();var n=this.options.getValidationMessage(e);return n?Gm(t,e,`Invalid value for type '${this.name}': ${n}`):Wm()}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.options.toSnapshot(e.storedValue)}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=this.options.isTargetType(r)?r:this.options.fromSnapshot(r,e&&e.root.environment);return $m(this,e,t,n,i)}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=!this.options.isTargetType(t);if(!e.isDetaching&&e.type===this&&(i?t===e.snapshot:t===e.storedValue))return e.setParent(n,r),e;var a=i?this.options.fromSnapshot(t,n.root.environment):t,o=this.instantiate(n,r,void 0,a);return e.die(),o}}),t}(Dm),q={enumeration:Lg,model:_g,compose:vg,custom:__,reference:c_,safeReference:l_,union:zg,optional:Ug,literal:Pg,maybe:qg,maybeNull:Jg,refinement:Ig,string:xg,boolean:Eg,number:Sg,integer:Cg,float:wg,finite:Tg,Date:Ag,map:ag,array:sg,frozen:t_,identifier:p_,identifierNumber:m_,late:Xg,lazy:Zg,undefined:Og,null:Dg,snapshotProcessor:$h};function y_({oldText:e,newText:t,element:n}){if(!(t.length/Math.max(20,e.length)>=4))return n.fontSize;let r=n.width*n.page.computedHeight/t.length,i=1.5*Math.sqrt(r),a=n.fontSize;return Math.min(a,Math.max(5,Math.round(i)))}function b_(e){try{let{stops:t}=Nf(e);if(t.length===0)return 127.5;let n=0,r=0;for(let e of t)try{let t=Du.Util.colorToRGBA(e.color);if(!t||t.a<.5)continue;n+=(299*t.r+587*t.g+114*t.b)/1e3,r++}catch{continue}return r===0?127.5:n/r}catch(e){return console.warn(`Error calculating gradient brightness:`,e),127.5}}function x_(e){if(jf(e))return b_(e);let t=Du.Util.colorToRGBA(e);if(!t)return 127.5;let{r:n,g:r,b:i}=t;return(299*n+587*r+114*i)/1e3}function S_(e){let{outlineSize:t,outlineColor:n}=function(e){let t=e.strokeWidth||0;return t>0?{outlineSize:t,outlineColor:e.stroke}:{outlineSize:e.shadowEnabled&&e.shadowBlur>0&&e.shadowOpacity>.1?e.shadowBlur*e.shadowOpacity:0,outlineColor:e.shadowColor}}(e);if(t<.001)return e.fill;let r=x_(e.fill),i=x_(n);return Math.abs(r-i)>=50?n:e.fill}var C_;function w_(){return C_||(C_=document.getElementById(`polotno-text-style`),C_||(C_=document.createElement(`style`),C_.id=`polotno-text-style`,document.head.appendChild(C_)),C_)}Du._fixTextRendering=!0;var T_={border:`none`,padding:`0px`,overflow:`hidden`,background:`none`,outline:`none`,resize:`none`,overflowWrap:`break-word`,whiteSpace:`pre-wrap`,userSelect:`text`,wordBreak:`normal`,textTransform:`none`},E_=sa(({textNodeRef:e,element:t,onBlur:n,selectAll:r,cursorPosition:i})=>{let[a,o]=d.useState(T_),s=e.current;d.useLayoutEffect(()=>{if(!s)return;let e={};e.width=s.width()-2*s.padding()+`px`,e.height=s.height()-2*s.padding()+s.fontSize()*s.lineHeight()+`px`,e.fontSize=s.fontSize()+`px`,e.lineHeight=s.lineHeight()+.01,e.fontFamily=s.fontFamily(),e.textAlign=s.align(),e.color=s.fill(),e.fontWeight=t.fontWeight,e.fontStyle=t.fontStyle,e.letterSpacing=t.letterSpacing+`em`,e.opacity=Math.max(t.a.opacity,.2),e.textTransform=t.textTransform,e.caretColor=S_(t);let n=`\n .polotno-input::placeholder {\n color: ${a.color};\n opacity: 0.6;\n }\n `,r=w_();r.innerHTML=``,r.appendChild(document.createTextNode(n)),JSON.stringify(e)!==JSON.stringify(a)&&o(e)});let c=d.useRef(null);if(d.useLayoutEffect(()=>{var e;let t=c.current;t&&((e=c.current)==null||e.focus(),t.selectionStart=t.selectionEnd=i||t.value.length,r&&(t?.select(),document.execCommand(`selectAll`,!1,void 0)))},[]),d.useEffect(()=>{window.addEventListener(`blur`,n);let e=e=>{var t;(t=c.current)!=null&&t.contains(e.target)||n()};return window.addEventListener(`touchstart`,e),()=>{window.removeEventListener(`blur`,n),window.removeEventListener(`touchstart`,e)}},[]),!s)return null;let l=0,u=s.textArr.length*s.lineHeight()*s.fontSize();t.verticalAlign===`middle`&&(l=(t.a.height-u)/2),t.verticalAlign===`bottom`&&(l=t.a.height-u);let f=Qf(t.text);return d.createElement(`textarea`,{className:`polotno-input`,ref:c,dir:Ap(f),style:Object.assign(Object.assign(Object.assign({},T_),a),{paddingTop:l+`px`}),value:f,onChange:e=>{let n=y_({oldText:t.text,newText:e.target.value,element:t});t.set({text:e.target.value,fontSize:n})},placeholder:t.placeholder,onBlur:n})}),D_=e=>d.createElement(cf,null,d.createElement(E_,Object.assign({},e))),O_=(e,t,n,r,i)=>{let[a,o]=d.useReducer(e=>e+1,0),s=d.useRef(lp(t,n,r)),c=d.useRef(null);return d.useLayoutEffect(()=>{if(s.current=lp(t,n,r),s.current)return;let a=!0;return(async()=>{s.current=!1,o();let l=Kf(`text ${t}`);await e.loadFont(t,n,r,i),a?(c.current=l,s.current=!0,o()):l()})(),()=>{c.current&&=(c.current(),null),a=!1}},[t,n,r]),d.useEffect(()=>{s.current&&setTimeout(()=>{c.current&&=(c.current(),null)})},[s.current]),[s.current]},k_=({fontLoaded:e,fontFamily:t,fontSize:n,lineHeight:r})=>d.useMemo(()=>Lp({fontFamily:t,fontSize:n,lineHeight:r}),[e,t,n,r]);function A_(e){let t=d.useRef(e),n=d.useRef(e);return d.useMemo(()=>{n.current=t.current,t.current=e},[e]),n.current}function j_(e,t,n=!1){let r=e.fontSize(),i=e.height(),a=Qf(t.text),o=t.a.fontSize;e.height(void 0);let s=Math.round(2*t.a.fontSize)-1;for(let r=1;r<s;r++){let r=t.a.height&&e.height()>t.a.height,i=a.split(`
47
- `).join(` `).split(/[\s-]+/).reduce((e,t)=>(t=t.toLowerCase(),/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\uAC00-\uD7AF]/.test(t)?e.concat(t.split(``)):e.concat(t)),[]),s=e.textArr.map(e=>e.text.toLowerCase()).join(`;`),c=i.find(e=>!s.includes(e)||(s=s.replace(e,``),!1));if(!(r||c&&!n))break;o-=.5,e.fontSize(o)}return e.fontSize(r),e.height(i),o}var M_=sa(({element:e,store:t})=>{let n=d.useRef(null),r=d.useRef(null),i=d.useRef(null),a=d.useRef([]),[,o]=d.useReducer(e=>e+1,0),{editorEnabled:s,selectAll:c}=(e=>{let[t,n]=d.useState(!1),r=d.useRef(!1);return d.useEffect(()=>{var t=!0;return setTimeout(()=>{t&&(e._editModeEnabled&&(r.current=!0),n(!0),setTimeout(()=>{r.current=!1},50))},50),()=>{t=!1}},[]),{editorEnabled:t&&e._editModeEnabled,selectAll:r.current}})(e),[l,u]=d.useState(!1),f=d.useRef(e.a.height),p=t.selectedShapes.indexOf(e)>=0&&e.selectable,m=A_(p),{textVerticalResizeEnabled:h}=yp,g=yp.autoDeleteEmptyText,_=A_(e.fontFamily),[v,y]=d.useState([]);d.useEffect(()=>{let e=n.current?.textArr??[];JSON.stringify(e)!==JSON.stringify(v)&&y(e)}),d.useEffect(()=>{if(e.a.width||e.type===`tablecell`)return;let t=n.current;t.width(600),e.set({width:1.4*t.getTextWidth()})},[]),d.useEffect(()=>{m&&!p&&g&&e.text===``&&e.removable&&!e.placeholder&&t.deleteElements([e.id])},[g,e.placeholder,e.removable,e.text,p,m]),d.useLayoutEffect(()=>Gn(()=>{let t=n.current;zp(t,e)})),d.useEffect(()=>{let e=a.current;e.length>0&&(a.current=[],e.forEach(e=>e()))});let b=Qf(e.text);e.textTransform===`uppercase`&&(b=b.toUpperCase());let[x]=O_(t,e.fontFamily,e.fontStyle,e.fontWeight,e.text||e.placeholder),S=()=>{if(e.curveEnabled){let e=r.current;return e.getSelfRect().height||e.fontSize()}let t=n.current.clone({height:void 0}),i=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),i};d.useLayoutEffect(()=>{if(!x)return;if(e.type===`tablecell`){let{textOverflow:r}=yp;if(r===`resize`){let t=S(),n=fm(e)?rm(e,2):null;n!=null&&n.setCellContentHeight&&n.setCellContentHeight(e.id,t)}else if(r===`change-font-size`){let r=n.current;if(r){let n=j_(r,e,yp.textSplitAllowed);n!==e.fontSize&&t.history.ignore(()=>{e.set({fontSize:n})})}}return}let{textOverflow:r,textSplitAllowed:i}=yp,s=(n,r,i,s)=>{let c=Kf(`text ${e.id}`),l=()=>{t.history.ignore(n,r,i).then(()=>{a.current.push(c),o()})};s?queueMicrotask(l):l()};if(!e.height){let t=S();s(()=>{e.height||e.set({height:t})},void 0,void 0,!0);return}if(!t.isPlaying)if(r!==`change-font-size`||l){if(r===`resize`){let t=S();h&&e.height<t&&!l&&s(()=>{var r;fm(e)&&e.set({height:t}),(r=n.current)==null||r.height(t)},!1,!0),h||e.height===t||l||s(()=>{var r;fm(e)&&e.set({height:t}),(r=n.current)==null||r.height(t)},!1,!0)}}else{let t=j_(n.current,e,i);if(t!==e.fontSize){s(()=>{e.set({fontSize:t})},!1,!0);return}let r=S();e.height===r||h||s(()=>{e.set({height:r})},!1,!0)}}),d.useLayoutEffect(()=>{if(x&&e.curveEnabled){let t=r.current?.getSelfRect().width;if(t){let n=t-e.a.width,r=e.a.rotation*Math.PI/180,i=-n/2*Math.cos(r),a=-n/2*Math.sin(r);e.set({width:t,x:e.a.x+i,y:e.a.y+a})}}},[x,e.curveEnabled,e.curvePower,e.text,e.fontSize,e.fontFamily,e.fontWeight,e.fontStyle,e.letterSpacing]),d.useLayoutEffect(()=>{let t=n.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),zp(t,e))},[x]);let C=d.useRef(null),w=d.useRef(0),T=n=>{n.evt.preventDefault(),t.selectedShapes.find(t=>t===e)&&e.contentEditable&&(w.current=function(e){let t=e.target,n=function(e){var t=e.getAbsoluteTransform().copy();t.invert();var n=e.getStage().getPointerPosition();return t.point(n)}(t),r=t.textArr,i=Math.floor(n.y/(t.fontSize()*t.lineHeight())),a=r.slice(0,i).reduce((e,t)=>e+t.text.length,i),o=r[i]??r[0],s=0;return t.align()===`right`?s=t.width()-o.width:t.align()===`center`&&(s=t.width()/2-o.width/2),a+Math.round((n.x-s)/o.width*o.text.length)}(n),e.toggleEditMode())},E=!b&&e.placeholder?.6:e.a.opacity;Rf(n,E);let D=k_({fontLoaded:x,fontFamily:e.fontFamily,fontSize:e.a.fontSize,lineHeight:e.lineHeight}),O=e.selectable||t.role===`admin`,k=Pf(e),A=Pf(e,e.stroke,`stroke`),j=d.useMemo(()=>e.backgroundEnabled?e.curveEnabled?function({width:e,height:t,padding:n=0,cornerRadius:r=0}){let i=-n,a=-n,o=e+n,s=t+n;return Of(Df(`M ${i} ${a} L ${o} ${a} L ${o} ${s} L ${i} ${s} Z`),r).path}({width:e.a.width,height:e.a.height,cornerRadius:e.backgroundCornerRadius*(e.a.fontSize*D*.5),padding:e.backgroundPadding*(e.a.fontSize*D*.5)}):function({lines:e,lineHeight:t,width:n,align:r=`left`,padding:i=0,cornerRadius:a=0}){e.forEach((e,t)=>{e.cx=n/2,r===`right`?e.cx=n-e.width/2:r===`left`&&(e.cx=e.width/2),r!==`justify`||e.lastInParagraph||(e.width=n),r===`justify`&&(e.cx=e.width/2)});let o=`M ${e[0]?.cx} ${-i}`;e.forEach((n,r)=>{let{cx:a}=n,s=e[r-1];s&&s.width>n.width?o+=` L ${a+n.width/2+i} ${r*t+i}`:o+=` L ${a+n.width/2+i} ${r*t-i}`;let c=e[r+1];c&&c.width>n.width?o+=` L ${a+n.width/2+i} ${(r+1)*t-i}`:o+=` L ${a+n.width/2+i} ${(r+1)*t+i}`});for(var s=e.length-1;s>=0;s--){let n=e[s],{cx:r}=n,a=e[s+1];a&&a.width>n.width?o+=` L ${r-n.width/2-i} ${(s+1)*t-i}`:o+=` L ${r-n.width/2-i} ${(s+1)*t+i}`;let c=e[s-1];c&&c.width>n.width?o+=` L ${r-n.width/2-i} ${s*t+i}`:o+=` L ${r-n.width/2-i} ${s*t-i}`}return o+=` Z`,Of(Df(o),a).path}({lines:JSON.parse(JSON.stringify(v)),cornerRadius:e.backgroundCornerRadius*(e.a.fontSize*D*.5),lineHeight:D*e.a.fontSize,padding:e.backgroundPadding*(e.a.fontSize*D*.5),width:e.a.width,align:e.align}):``,[e.backgroundEnabled,e.curveEnabled,e.backgroundCornerRadius,e.a.fontSize,e.a.height,D,e.backgroundPadding,e.a.width,e.align,v]),M=Bp(),N=0;e.curveEnabled||(e.verticalAlign===`middle`?N=(e.a.height-v.length*D*e.a.fontSize)/2:e.verticalAlign===`bottom`&&(N=e.a.height-v.length*D*e.a.fontSize));let P=e.curveEnabled?jp(e.a.width,e.a.height,e.curvePower,e.a.fontSize):``,F=x?`"`+e.fontFamily+`"`:_===e.fontFamily?`Arial`:`"`+_+`"`;return d.createElement(d.Fragment,null,d.createElement($d,{ref:i,x:e.a.x,y:e.a.y,rotation:e.a.rotation,hideInExport:!e.showInExport,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity*E,data:j,fill:e.backgroundColor,offsetY:-N}),d.createElement($d,{data:P,stroke:`red`,strokeWidth:1,x:e.a.x,y:e.a.y,rotation:e.a.rotation,visible:!1}),d.createElement(Qd,Object.assign({ref:r,visible:e.curveEnabled,data:P,text:b||e.placeholder,listening:!1,align:`center`,textBaseline:`middle`},k,A,{strokeWidth:e.strokeWidth,lineJoin:`round`,fillAfterStrokeEnabled:!0,fontSize:e.a.fontSize,fontFamily:`"${e.fontFamily}", "${_}"`,fontStyle:e.fontStyle+` `+e.fontWeight,textDecoration:e.textDecoration.trim(),letterSpacing:e.letterSpacing*e.a.fontSize,x:e.a.x,y:e.a.y,rotation:e.a.rotation,opacity:e._editModeEnabled?.3:E,hideInExport:!e.showInExport,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity})),d.createElement(Zd,Object.assign({ref:n,id:e.selectable?e.id:void 0,name:e.selectable?`element`:``,hideInExport:!e.showInExport,editModeEnabled:e._editModeEnabled,x:e.a.x,y:e.a.y,rotation:e.a.rotation,width:e.a.width,height:e.a.height,text:b||e.placeholder,direction:Ap(b)},k,A,{lineJoin:`round`,strokeWidth:e.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:e.a.fontSize,fontFamily:F,fontStyle:e.fontStyle+` `+e.fontWeight,textDecoration:e.textDecoration,align:e.align,verticalAlign:e.verticalAlign,draggable:M?e.draggable&&p:e.draggable,preventDefault:!M||p,opacity:e.curveEnabled?0:E,visible:!e._editModeEnabled,ellipsis:yp.textOverflow===`ellipsis`,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,lineHeight:D,letterSpacing:e.letterSpacing*e.a.fontSize,listening:!!e.selectable&&O,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onClick:T,onTap:T,onTransformStart:()=>{u(!0),f.current=n.current.height()},onTransform:t=>{var n,r;let a=t.target;(n=i.current)==null||n.setAttrs({x:a.x(),y:a.y(),rotation:a.rotation(),scale:a.scale()});let o=(a.getStage()?.findOne(`Transformer`)).getActiveAnchor();if(o===`middle-left`||o===`middle-right`){let t=a.scaleX(),n=a.width()*t,r=e.a.fontSize,i=n;n<r&&(i=r,C.current&&a.position(C.current)),a.width(i),a.scaleX(1),a.scaleY(1);let o=S();if(yp.textOverflow===`ellipsis`)o=f.current;else{let t=Math.max(o,f.current);a.height(t),e.set({height:a.height()})}let s=yp.textVerticalResizeEnabled?Math.max(o,f.current):S();e.set({x:a.x(),width:a.width(),rotation:a.rotation(),height:s}),zp(a,e)}if(o===`top-center`||o===`bottom-center`){let n=yp.textOverflow===`resize`?S():D*e.a.fontSize;t.target.height(Math.max(n,t.target.height()*t.target.scaleY())),t.target.scaleY(1)}C.current=t.target.position();let s=t.target.scaleX();(r=i.current)==null||r.setAttrs({scaleX:1,scaleY:1}),t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.a.fontSize*s,width:t.target.width()*s,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*s,shadowBlur:e.shadowBlur*s,shadowOffsetX:e.shadowOffsetX*s,shadowOffsetY:e.shadowOffsetY*s,strokeWidth:e.strokeWidth*s})},onTransformEnd:t=>{var n;let r=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:Math.round(e.a.fontSize*r),width:Math.ceil(t.target.width()*r),x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*r,shadowBlur:e.shadowBlur*r,shadowOffsetX:e.shadowOffsetX*r,shadowOffsetY:e.shadowOffsetY*r,strokeWidth:e.strokeWidth*r}),(n=i.current)==null||n.setAttrs({scaleX:1,scaleY:1}),u(!1)}})),s&&e.contentEditable&&d.createElement(`Group`,{x:e.a.x,y:e.a.y,rotation:e.a.rotation},d.createElement(D_,{textNodeRef:n,element:e,selectAll:c,cursorPosition:w.current,onBlur:()=>{e.toggleEditMode(!1)}})))}),N_=r(((e,t)=>{e=t.exports=n;function n(e){return r.bind(null,e)}function r(e){var t=[].slice.call(arguments,1);t.unshift(`[`+e+`]`),process.stderr.write(t.join(` `)+`
48
- `)}})),P_=r(((e,t)=>{var n=!1,r=!1,i=N_()(`lex`);e=t.exports=a;function a(e){var t,a=``,o,s=0,c=-1,l=0,u=1,d=`before-selector`,f=[d],p={},m=[],h=[`media`,`keyframes`,{name:`-webkit-keyframes`,type:`keyframes`,prefix:`-webkit-`},{name:`-moz-keyframes`,type:`keyframes`,prefix:`-moz-`},{name:`-ms-keyframes`,type:`keyframes`,prefix:`-ms-`},{name:`-o-keyframes`,type:`keyframes`,prefix:`-o-`},`font-face`,{name:`import`,state:`before-at-value`},{name:`charset`,state:`before-at-value`},`supports`,`viewport`,{name:`namespace`,state:`before-at-value`},`document`,{name:`-moz-document`,type:`document`,prefix:`-moz-`},`page`];function g(){return T(),e[c]}function _(e){return e?f[f.length-1-e]:d}function v(t){var n=c+1;return t===e.slice(n,n+t.length)}function y(t){var n=e.slice(c).indexOf(t);return n>0?n:!1}function b(e){return e===x(1)}function x(t){return e[c+(t||1)]}function S(){var e=f.pop();return d=f[f.length-1],e}function C(e){return d=e,f.push(d),f.length}function w(e){var t=d;return f[f.length-1]=d=e,t}function T(t){if((t||1)==1)e[c]==`
45
+ `+n.map(Gm).join(`
46
+ `)}var $m=0,eh=function(){function e(){Object.defineProperty(this,`cacheId`,{enumerable:!0,configurable:!0,writable:!0,value:$m++}),Object.defineProperty(this,`cache`,{enumerable:!0,configurable:!0,writable:!0,value:L.map()}),Object.defineProperty(this,`lastCacheModificationPerId`,{enumerable:!0,configurable:!0,writable:!0,value:L.map()})}return Object.defineProperty(e.prototype,`updateLastCacheModificationPerId`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.lastCacheModificationPerId.get(e);this.lastCacheModificationPerId.set(e,t===void 0?1:t+1)}}),Object.defineProperty(e.prototype,`getLastCacheModificationPerId`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.lastCacheModificationPerId.get(e)||0;return`${this.cacheId}-${t}`}}),Object.defineProperty(e.prototype,`addNodeToCache`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(t===void 0&&(t=!0),e.identifierAttribute){var n=e.identifier;this.cache.has(n)||this.cache.set(n,L.array([],gh));var r=this.cache.get(n);if(r.indexOf(e)!==-1)throw new K(`Already registered`);r.push(e),t&&this.updateLastCacheModificationPerId(n)}}}),Object.defineProperty(e.prototype,`mergeCache`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;Cr(e.identifierCache.cache).forEach(function(e){return e.forEach(function(e){t.addNodeToCache(e)})})}}),Object.defineProperty(e.prototype,`notifyDied`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(e.identifierAttribute){var t=e.identifier,n=this.cache.get(t);n&&(n.remove(e),n.length||this.cache.delete(t),this.updateLastCacheModificationPerId(e.identifier))}}}),Object.defineProperty(e.prototype,`splitCache`,{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=this,r=new e,i=t.path+`/`;return wr(this.cache).forEach(function(e){for(var a=$p(e,2),o=a[0],s=a[1],c=!1,l=s.length-1;l>=0;l--){var u=s[l];(u===t||u.path.indexOf(i)===0)&&(r.addNodeToCache(u,!1),s.splice(l,1),s.length||n.cache.delete(o),c=!0)}c&&n.updateLastCacheModificationPerId(o)}),r}}),Object.defineProperty(e.prototype,`has`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.cache.get(t);return n?n.some(function(t){return e.isAssignableFrom(t.type)}):!1}}),Object.defineProperty(e.prototype,`resolve`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.cache.get(t);if(!n)return null;var r=n.filter(function(t){return e.isAssignableFrom(t.type)});switch(r.length){case 0:return null;case 1:return r[0];default:throw new K(`Cannot resolve a reference to type '${e.name}' with id: '${t}' unambigously, there are multiple candidates: ${r.map(function(e){return e.path}).join(`, `)}`)}}}),e}();function th(e,t,n,r,i){var a=ch(i);if(a){if(a.parent)throw new K(`Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '${t?t.path:``}/${n}', but it lives already at '${a.path}'`);return t&&a.setParent(t,n),a}return new Cm(e,t,n,r,i)}function nh(e,t,n,r,i){return new vm(e,t,n,r,i)}function rh(e){return e instanceof vm||e instanceof Cm}var ih;(function(e){e[e.INITIALIZING=0]=`INITIALIZING`,e[e.CREATED=1]=`CREATED`,e[e.FINALIZED=2]=`FINALIZED`,e[e.DETACHING=3]=`DETACHING`,e[e.DEAD=4]=`DEAD`})(ih||={});function ah(e){return!!(e&&e.$treenode)}function oh(e,t){Vh(e,ah,`mobx-state-tree node`,t)}function sh(e){if(!ah(e))throw new K(`Value ${e} is no MST Node`);return e.$treenode}function ch(e){return e&&e.$treenode||null}function lh(){return sh(this).snapshot}function uh(e,t,n){return n===void 0&&(n=!0),dh(e,Qh(t),n)}function dh(e,t,n){n===void 0&&(n=!0);var r=e;try{for(var i=0;i<t.length;i++){var a=t[i];if(a===`..`){if(r=r.parent,r)continue}else if(a===`.`)continue;else if(r){if(r instanceof vm){var o=r.value;ah(o)&&(r=sh(o))}if(r instanceof Cm&&r.getChildType(a)&&(r=r.getChildNode(a),r))continue}throw new K(`Could not resolve '${a}' in path '${Zh(t.slice(0,i))||`/`}' while resolving '${Zh(t)}'`)}}catch(e){if(!n)return;throw e}return r}function fh(e){if(!e)return mh;var t=Object.keys(e);if(!t.length)return mh;var n=Array(t.length);return t.forEach(function(t,r){n[r]=e[t]}),n}var ph=Object.toString(),mh=Object.freeze([]),hh=Object.freeze({}),gh=fn().useProxies?{deep:!1}:{deep:!1,proxy:!1};Object.freeze(gh);var K=function(e){Yp(t,e);function t(t){return t===void 0&&(t=`Illegal state`),e.call(this,`[mobx-state-tree] ${t}`)||this}return t}(Error);function _h(e){return e}var vh=Number.isInteger;function yh(e){return Number(e)===e&&e%1!=0}function bh(e){return Number.isFinite(e)}function xh(e){return Array.isArray(e)||ni(e)}function Sh(e){return e?xh(e)?e:[e]:mh}function Ch(e){for(var t=[...arguments].slice(1),n=0;n<t.length;n++){var r=t[n];for(var i in r)e[i]=r[i]}return e}function wh(e){if(typeof e!=`object`||!e)return!1;var t=Object.getPrototypeOf(e);return t==null?!0:t.constructor?.toString()===ph}function Th(e){return typeof e==`object`&&!!e&&!(e instanceof Date)&&!(e instanceof RegExp)}function Eh(e,t){return t===void 0&&(t=!0),e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`||t&&e instanceof Date}function Dh(e){return Bh()?Eh(e)||ni(e)?e:Object.freeze(e):e}function Oh(e){return Bh()?(Dh(e),wh(e)&&Object.keys(e).forEach(function(t){!Eh(e[t])&&!Object.isFrozen(e[t])&&Oh(e[t])}),e):e}function kh(e){return typeof e!=`function`}function Ah(e,t,n){bi(e)?Er(e,t,n):Object.defineProperty(e,t,n)}function jh(e,t,n){Ah(e,t,{enumerable:!1,writable:!1,configurable:!0,value:n})}function Mh(e,t,n){Ah(e,t,{enumerable:!1,writable:!0,configurable:!0,value:n})}var Nh=function(){function e(){Object.defineProperty(this,`handlers`,{enumerable:!0,configurable:!0,writable:!0,value:[]})}return Object.defineProperty(e.prototype,`hasSubscribers`,{get:function(){return this.handlers.length>0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,`register`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;return t===void 0&&(t=!1),t?this.handlers.unshift(e):this.handlers.push(e),function(){n.unregister(e)}}}),Object.defineProperty(e.prototype,`has`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.handlers.indexOf(e)>=0}}),Object.defineProperty(e.prototype,`unregister`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.handlers.indexOf(e);t>=0&&this.handlers.splice(t,1)}}),Object.defineProperty(e.prototype,`clear`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.handlers.length=0}}),Object.defineProperty(e.prototype,`emit`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=[...arguments];this.handlers.slice().forEach(function(t){return t.apply(void 0,em([],$p(e),!1))})}}),e}(),Ph=function(){function e(){Object.defineProperty(this,`eventHandlers`,{enumerable:!0,configurable:!0,writable:!0,value:void 0})}return Object.defineProperty(e.prototype,`hasSubscribers`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.eventHandlers&&this.eventHandlers[e];return!!t&&t.hasSubscribers}}),Object.defineProperty(e.prototype,`register`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){n===void 0&&(n=!1),this.eventHandlers||={};var r=this.eventHandlers[e];return r||=this.eventHandlers[e]=new Nh,r.register(t,n)}}),Object.defineProperty(e.prototype,`has`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.eventHandlers&&this.eventHandlers[e];return!!n&&n.has(t)}}),Object.defineProperty(e.prototype,`unregister`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.eventHandlers&&this.eventHandlers[e];n&&n.unregister(t)}}),Object.defineProperty(e.prototype,`clear`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.eventHandlers&&delete this.eventHandlers[e]}}),Object.defineProperty(e.prototype,`clearAll`,{enumerable:!1,configurable:!0,writable:!0,value:function(){this.eventHandlers=void 0}}),Object.defineProperty(e.prototype,`emit`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){for(var t,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var i=this.eventHandlers&&this.eventHandlers[e];i&&(t=i).emit.apply(t,em([],$p(n),!1))}}),e}();function Fh(e){for(var t=Array(e.length),n=0;n<e.length;n++)t[n]=e[n];return t}function Ih(e,t){return e.indexOf(t)===0}var Lh=function(e,t){Bh()&&(Lh.ids&&!Lh.ids.hasOwnProperty(e)&&Rh(`Deprecation warning: `+t),Lh.ids&&(Lh.ids[e]=!0))};Lh.ids={};function Rh(e){console.warn(Error(`[mobx-state-tree] ${e}`))}function zh(){return Bh()||typeof process<`u`&&{}.ENABLE_TYPE_CHECK===`true`}function Bh(){return!1}function Vh(e,t,n,r){if(Bh()&&!t(e))throw new K(`expected ${n} as argument ${Sh(r).join(` or `)}, got ${e} instead`)}function Hh(e,t){Vh(e,function(e){return typeof e==`function`},`function`,t)}function Uh(e,t,n,r){Vh(e,function(e){return typeof e==`number`},`number`,t),n!==void 0&&Vh(e,function(e){return e>=n},`number greater than ${n}`,t),r!==void 0&&Vh(e,function(e){return e<=r},`number lesser than ${r}`,t)}function Wh(e,t,n){n===void 0&&(n=!0),Vh(e,function(e){return typeof e==`string`},`string`,t),n||Vh(e,function(e){return e!==``},`not empty string`,t)}function Gh(e){if(!(`oldValue`in e))throw new K("Patches without `oldValue` field cannot be inversed");return[Kh(e),qh(e)]}function Kh(e){switch(e.op){case`add`:return{op:`add`,path:e.path,value:e.value};case`remove`:return{op:`remove`,path:e.path};case`replace`:return{op:`replace`,path:e.path,value:e.value}}}function qh(e){switch(e.op){case`add`:return{op:`remove`,path:e.path};case`remove`:return{op:`add`,path:e.path,value:e.oldValue};case`replace`:return{op:`replace`,path:e.path,value:e.oldValue}}}function Jh(e){return typeof e==`number`}function Yh(e){return Jh(e)===!0?``+e:e.indexOf(`/`)===-1&&e.indexOf(`~`)===-1?e:e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function Xh(e){return e.replace(/~1/g,`/`).replace(/~0/g,`~`)}function Zh(e){if(e.length===0)return``;var t=function(e){return e.map(Yh).join(`/`)};return e[0]===`.`||e[0]===`..`?t(e):`/`+t(e)}function Qh(e){var t=e.split(`/`).map(Xh);if(!(e===``||e===`.`||e===`..`||Ih(e,`/`)||Ih(e,`./`)||Ih(e,`../`)))throw new K(`a json path must be either rooted, empty or relative, but got '${e}'`);return t[0]===``&&t.shift(),t}var $h=Symbol(`$preProcessorFailed`),eg=function(e){Yp(t,e);function t(t,n,r){var i=e.call(this,r||t.name)||this;return Object.defineProperty(i,`_subtype`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(i,`_processors`,{enumerable:!0,configurable:!0,writable:!0,value:n}),i}return Object.defineProperty(t.prototype,`flags`,{get:function(){return this._subtype.flags|Tm.SnapshotProcessor},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return`snapshotProcessor(${this._subtype.describe()})`}}),Object.defineProperty(t.prototype,`preProcessSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._processors.preProcessor?this._processors.preProcessor.call(null,e):e}}),Object.defineProperty(t.prototype,`preProcessSnapshotSafe`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){try{return this.preProcessSnapshot(e)}catch{return $h}}}),Object.defineProperty(t.prototype,`postProcessSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this._processors.postProcessor?this._processors.postProcessor.call(null,e,t.storedValue):e}}),Object.defineProperty(t.prototype,`_fixNode`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;tg(e.type,this,`create`),e instanceof Cm&&(e.hasSnapshotPostProcessor=!!this._processors.postProcessor);var n=e.getSnapshot;e.getSnapshot=function(){return t.postProcessSnapshot(n.call(e),e)},Ug(this._subtype)||(e.getReconciliationType=function(){return t})}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=ah(r)?r:this.preProcessSnapshot(r),a=this._subtype.instantiate(e,t,n,i);return this._fixNode(a),a}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=this._subtype.reconcile(e,ah(t)?t:this.preProcessSnapshot(t),n,r);return i!==e&&this._fixNode(i),i}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){t===void 0&&(t=!0);var n=this._subtype.getSnapshot(e);return t?this.postProcessSnapshot(n,e):n}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.preProcessSnapshotSafe(e);return n===$h?Jm(t,e,`Failed to preprocess value`):this._subtype.validate(n,t)}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),Object.defineProperty(t.prototype,`is`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=jm(e)?this._subtype:ah(e)?e:this.preProcessSnapshotSafe(e);return t===$h?!1:this._subtype.validate(t,[{path:``,type:this._subtype}]).length===0}}),Object.defineProperty(t.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._subtype.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,`isMatchingSnapshotId`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(!(this._subtype instanceof km))return!1;var n=this.preProcessSnapshot(t);return this._subtype.isMatchingSnapshotId(e,n)}}),t}(Om);function tg(e,t){for(var n,r,i=[],a=2;a<arguments.length;a++)i[a-2]=arguments[a];try{for(var o=Qp(i),s=o.next();!s.done;s=o.next()){var c=s.value;e[c]=t[c].bind(t)}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}}function ng(e,t,n){if(Mm(e,1),Bh()){if(t.postProcessor&&typeof t.postProcessor!=`function`)throw new K(`postSnapshotProcessor must be a function`);if(t.preProcessor&&typeof t.preProcessor!=`function`)throw new K(`preSnapshotProcessor must be a function`)}return new eg(e,t,n)}var rg=`Map.put can only be used to store complex values that have an identifier type attribute`;function ig(e,t){var n,r,i=e.getSubTypes();if(i===Em)return!1;if(i){var a=Sh(i);try{for(var o=Qp(a),s=o.next();!s.done;s=o.next()){var c=s.value;if(!ig(c,t))return!1}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}}return e instanceof yg&&t.push(e),!0}var ag;(function(e){e[e.UNKNOWN=0]=`UNKNOWN`,e[e.YES=1]=`YES`,e[e.NO=2]=`NO`})(ag||={});var og=function(e){Yp(t,e);function t(t,n){return e.call(this,t,L.ref.enhancer,n)||this}return Object.defineProperty(t.prototype,`get`,{enumerable:!1,configurable:!0,writable:!0,value:function(t){return e.prototype.get.call(this,``+t)}}),Object.defineProperty(t.prototype,`has`,{enumerable:!1,configurable:!0,writable:!0,value:function(t){return e.prototype.has.call(this,``+t)}}),Object.defineProperty(t.prototype,`delete`,{enumerable:!1,configurable:!0,writable:!0,value:function(t){return e.prototype.delete.call(this,``+t)}}),Object.defineProperty(t.prototype,`set`,{enumerable:!1,configurable:!0,writable:!0,value:function(t,n){return e.prototype.set.call(this,``+t,n)}}),Object.defineProperty(t.prototype,`put`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!e)throw new K(`Map.put cannot be used to set empty values`);if(ah(e)){var t=sh(e);if(Bh()&&!t.identifierAttribute||t.identifier===null)throw new K(rg);return this.set(t.identifier,e),e}else if(Th(e)){var n=sh(this),r=n.type;if(r.identifierMode!==ag.YES)throw new K(rg);var i=e[r.mapIdentifierAttribute];if(!y_(i)){var a=this.put(r.getChildType().create(e,n.environment));return this.put(am(a))}var o=v_(i);return this.set(o,e),this.get(o)}else throw new K(`Map.put can only be used to store complex values`)}}),t}(oi),sg=function(e){Yp(t,e);function t(t,n,r){r===void 0&&(r=[]);var i=e.call(this,t)||this;return Object.defineProperty(i,`_subType`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(i,`identifierMode`,{enumerable:!0,configurable:!0,writable:!0,value:ag.UNKNOWN}),Object.defineProperty(i,`mapIdentifierAttribute`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Tm.Map}),Object.defineProperty(i,`hookInitializers`,{enumerable:!0,configurable:!0,writable:!0,value:[]}),i._determineIdentifierMode(),i.hookInitializers=r,i}return Object.defineProperty(t.prototype,`hooks`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=this.hookInitializers.length>0?this.hookInitializers.concat(e):[e];return new t(this.name,this._subType,n)}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return this._determineIdentifierMode(),th(this,e,t,n,r)}}),Object.defineProperty(t.prototype,`_determineIdentifierMode`,{enumerable:!1,configurable:!0,writable:!0,value:function(){if(this.identifierMode===ag.UNKNOWN){var e=[];if(ig(this._subType,e)){var t=e.reduce(function(e,t){if(!t.identifierAttribute)return e;if(e&&e!==t.identifierAttribute)throw new K(`The objects in a map should all have the same identifier attribute, expected '${e}', but child of type '${t.name}' declared attribute '${t.identifierAttribute}' as identifier`);return t.identifierAttribute},void 0);t?(this.identifierMode=ag.YES,this.mapIdentifierAttribute=t):this.identifierMode=ag.NO}}}}),Object.defineProperty(t.prototype,`initializeChildNodes`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){t===void 0&&(t={});var n=e.type._subType,r={};return Object.keys(t).forEach(function(i){r[i]=n.instantiate(e,i,void 0,t[i])}),r}}),Object.defineProperty(t.prototype,`createNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return new og(e,this.name)}}),Object.defineProperty(t.prototype,`finalizeNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){gr(t,e.unbox),e.type.hookInitializers.forEach(function(e){var n=e(t);Object.keys(n).forEach(function(e){var r=n[e],i=zm(t,e,r);(Bh()?Mh:jh)(t,e,i)})}),_r(t,this.willChange),Dr(t,this.didChange)}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,`getChildren`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return Cr(e.storedValue)}}),Object.defineProperty(t.prototype,`getChildNode`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=e.storedValue.get(``+t);if(!n)throw new K(`Not a child `+t);return n}}),Object.defineProperty(t.prototype,`willChange`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=sh(e.object),n=e.name;t.assertWritable({subpath:n});var r=t.type,i=r._subType;switch(e.type){case`update`:var a=e.newValue;if(a===e.object.get(n))return null;Xm(i,a),e.newValue=i.reconcile(t.getChildNode(n),e.newValue,t,n),r.processIdentifier(n,e.newValue);break;case`add`:Xm(i,e.newValue),e.newValue=i.instantiate(t,n,void 0,e.newValue),r.processIdentifier(n,e.newValue);break}return e}}),Object.defineProperty(t.prototype,`processIdentifier`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this.identifierMode===ag.YES&&t instanceof Cm){var n=t.identifier;if(n!==e)throw new K(`A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '${n}', but expected: '${e}'`)}}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t={};return e.getChildren().forEach(function(e){t[e.subpath]=e.snapshot}),t}}),Object.defineProperty(t.prototype,`processInitialSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t={};return Object.keys(e).forEach(function(n){t[n]=e[n].getSnapshot()}),t}}),Object.defineProperty(t.prototype,`didChange`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=sh(e.object);switch(e.type){case`update`:t.emitPatch({op:`replace`,path:Yh(e.name),value:e.newValue.snapshot,oldValue:e.oldValue?e.oldValue.snapshot:void 0},t);return;case`add`:t.emitPatch({op:`add`,path:Yh(e.name),value:e.newValue.snapshot,oldValue:void 0},t);return;case`delete`:var n=e.oldValue.snapshot;e.oldValue.die(),t.emitPatch({op:`remove`,path:Yh(e.name),oldValue:n},t);return}}}),Object.defineProperty(t.prototype,`applyPatchLocally`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){var r=e.storedValue;switch(n.op){case`add`:case`replace`:r.set(t,n.value);break;case`remove`:r.delete(t);break}}}),Object.defineProperty(t.prototype,`applySnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){Xm(this,t);var n=e.storedValue,r={};if(Array.from(n.keys()).forEach(function(e){r[e]=!1}),t)for(var i in t)n.set(i,t[i]),r[``+i]=!0;Object.keys(r).forEach(function(e){r[e]===!1&&n.delete(e)})}}),Object.defineProperty(t.prototype,`getChildType`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subType}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;return wh(e)?Ym(Object.keys(e).map(function(r){return n._subType.validate(e[r],Km(t,r,n._subType))})):Jm(t,e,`Value is not a plain object`)}}),Object.defineProperty(t.prototype,`getDefaultSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return hh}}),Object.defineProperty(t.prototype,`removeChild`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){e.storedValue.delete(t)}}),t}(km);sg.prototype.applySnapshot=Vn(sg.prototype.applySnapshot);function cg(e){return new sg(`Map<string, ${e.name}>`,e)}var lg=function(e){Yp(t,e);function t(t,n,r){r===void 0&&(r=[]);var i=e.call(this,t)||this;return Object.defineProperty(i,`_subType`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(i,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Tm.Array}),Object.defineProperty(i,`hookInitializers`,{enumerable:!0,configurable:!0,writable:!0,value:[]}),i.hookInitializers=r,i}return Object.defineProperty(t.prototype,`hooks`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=this.hookInitializers.length>0?this.hookInitializers.concat(e):[e];return new t(this.name,this._subType,n)}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return th(this,e,t,n,r)}}),Object.defineProperty(t.prototype,`initializeChildNodes`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){t===void 0&&(t=[]);var n=e.type._subType,r={};return t.forEach(function(t,i){var a=``+i;r[a]=n.instantiate(e,a,void 0,t)}),r}}),Object.defineProperty(t.prototype,`createNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=Xp(Xp({},gh),{name:this.name});return L.array(fh(e),t)}}),Object.defineProperty(t.prototype,`finalizeNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){Ni(t).dehancer=e.unbox,e.type.hookInitializers.forEach(function(e){var n=e(t);Object.keys(n).forEach(function(e){var r=n[e],i=zm(t,e,r);(Bh()?Mh:jh)(t,e,i)})}),_r(t,this.willChange),Dr(t,this.didChange)}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,`getChildren`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue.slice()}}),Object.defineProperty(t.prototype,`getChildNode`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=Number(t);if(n<e.storedValue.length)return e.storedValue[n];throw new K(`Not a child: `+t)}}),Object.defineProperty(t.prototype,`willChange`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=sh(e.object);t.assertWritable({subpath:``+e.index});var n=t.type._subType,r=t.getChildren();switch(e.type){case`update`:if(e.newValue===e.object[e.index])return null;var i=dg(t,n,[r[e.index]],[e.newValue],[e.index]);if(!i)return null;e.newValue=i[0];break;case`splice`:var a=e.index,o=e.removedCount,s=e.added,c=dg(t,n,r.slice(a,a+o),s,s.map(function(e,t){return a+t}));if(!c)return null;e.added=c;for(var l=a+o;l<r.length;l++)r[l].setParent(t,``+(l+s.length-o));break}return e}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.getChildren().map(function(e){return e.snapshot})}}),Object.defineProperty(t.prototype,`processInitialSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=[];return Object.keys(e).forEach(function(n){t.push(e[n].getSnapshot())}),t}}),Object.defineProperty(t.prototype,`didChange`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=sh(e.object);switch(e.type){case`update`:t.emitPatch({op:`replace`,path:``+e.index,value:e.newValue.snapshot,oldValue:e.oldValue?e.oldValue.snapshot:void 0},t);return;case`splice`:if(e.removedCount&&e.addedCount===e.object.length){t.emitPatch({op:`replace`,path:``,value:t.snapshot,oldValue:e.removed.map(function(e){return e.snapshot})},t);return}for(var n=e.removedCount-1;n>=0;n--)t.emitPatch({op:`remove`,path:``+(e.index+n),oldValue:e.removed[n].snapshot},t);for(var n=0;n<e.addedCount;n++)t.emitPatch({op:`add`,path:``+(e.index+n),value:e.added[n].snapshot,oldValue:void 0},t);return}}}),Object.defineProperty(t.prototype,`applyPatchLocally`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){var r=e.storedValue,i=t===`-`?r.length:Number(t);switch(n.op){case`replace`:r[i]=n.value;break;case`add`:r.splice(i,0,n.value);break;case`remove`:r.splice(i,1);break}}}),Object.defineProperty(t.prototype,`applySnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){Xm(this,t),e.storedValue.replace(t)}}),Object.defineProperty(t.prototype,`getChildType`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subType}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;return xh(e)?Ym(e.map(function(e,r){return n._subType.validate(e,Km(t,``+r,n._subType))})):Jm(t,e,`Value is not an array`)}}),Object.defineProperty(t.prototype,`getDefaultSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return mh}}),Object.defineProperty(t.prototype,`removeChild`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){e.storedValue.splice(Number(t),1)}}),t}(km);lg.prototype.applySnapshot=Vn(lg.prototype.applySnapshot);function ug(e){return Mm(e,1),new lg(`${e.name}[]`,e)}function dg(e,t,n,r,i){for(var a=!0,o=0;;o++){var s=o<=r.length-1,c=n[o],l=s?r[o]:void 0,u=``+i[o];if(rh(l)&&(l=l.storedValue),!c&&!s)break;if(!s)a=!1,n.splice(o,1),c instanceof Cm&&c.createObservableInstanceIfNeeded(),c.die(),o--;else if(!c){if(ah(l)&&sh(l).parent===e)throw new K(`Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '${e.path}/${u}', but it lives already at '${sh(l).path}'`);a=!1;var d=fg(t,e,u,l);n.splice(o,0,d)}else if(pg(c,l))n[o]=fg(t,e,u,l,c);else{for(var f=void 0,p=o;p<n.length;p++)if(pg(n[p],l)){f=n.splice(p,1)[0];break}a=!1;var d=fg(t,e,u,l,f);n.splice(o,0,d)}}return a?null:n}function fg(e,t,n,r,i){Xm(e,r);function a(){if(ah(r)){var a=sh(r);if(a.assertAlive(hh),a.parent!==null&&a.parent===t)return a.setParent(t,n),a}return i?e.reconcile(i,r,t,n):e.instantiate(t,n,void 0,r)}var o=a();return i&&i!==o&&(i instanceof Cm&&i.createObservableInstanceIfNeeded(),i.die()),o}function pg(e,t){if(!e.isAlive)return!1;if(ah(t)){var n=sh(t);return n.isAlive&&n===e}if(e.snapshot===t)return!0;if(!(e instanceof Cm))return!1;var r=e.getReconciliationType();return e.identifier!==null&&e.identifierAttribute&&wh(t)&&r.is(t)&&r.isMatchingSnapshotId(e,t)}var mg=`preProcessSnapshot`,hg=`postProcessSnapshot`;function gg(){return sh(this).toString()}var _g={name:`AnonymousModel`,properties:{},initializers:mh};function vg(e){var t=Object.keys(e),n=new Set;return t.forEach(function(e){if(n.has(e))throw new K(`${e} is declared twice in the model. Model should not contain the same keys`);n.add(e)}),t.reduce(function(t,n){if(n in qp)throw new K(`Hook '${n}' was defined as property. Hooks should be defined as part of the actions`);var r=Object.getOwnPropertyDescriptor(e,n);if(`get`in r)throw new K(`Getters are not supported as properties. Please use views instead`);var i=r.value;if(i==null)throw new K("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");if(Eh(i))t[n]=Kg(Pg(i),i);else if(i instanceof sg)t[n]=Kg(i,{});else if(i instanceof lg)t[n]=Kg(i,[]);else if(!jm(i))throw Bh()&&typeof i==`function`?new K(`Invalid type definition for property '${n}', it looks like you passed a function. Did you forget to invoke it, or did you intend to declare a view / action?`):Bh()&&typeof i==`object`?new K(`Invalid type definition for property '${n}', it looks like you passed an object. Try passing another model type or a types.frozen.`):new K(`Invalid type definition for property '${n}', cannot infer a type from a value like '${i}' (${typeof i})`);return t},Xp({},e))}var yg=function(e){Yp(t,e);function t(t){var n=e.call(this,t.name||_g.name)||this;return Object.defineProperty(n,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Tm.Object}),Object.defineProperty(n,`initializers`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,`properties`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,`preProcessor`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,`postProcessor`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,`propertyNames`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,`named`,{enumerable:!0,configurable:!0,writable:!0,value:function(e){return n.cloneAndEnhance({name:e})}}),Object.defineProperty(n,`props`,{enumerable:!0,configurable:!0,writable:!0,value:function(e){return n.cloneAndEnhance({properties:e})}}),Object.defineProperty(n,`preProcessSnapshot`,{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=n.preProcessor;return t?n.cloneAndEnhance({preProcessor:function(n){return t(e(n))}}):n.cloneAndEnhance({preProcessor:e})}}),Object.defineProperty(n,`postProcessSnapshot`,{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=n.postProcessor;return t?n.cloneAndEnhance({postProcessor:function(n){return e(t(n))}}):n.cloneAndEnhance({postProcessor:e})}}),Object.assign(n,_g,t),n.properties=vg(n.properties),Dh(n.properties),n.propertyNames=Object.keys(n.properties),n.identifierAttribute=n._getIdentifierAttribute(),n}return Object.defineProperty(t.prototype,`_getIdentifierAttribute`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=void 0;return this.forAllProps(function(t,n){if(n.flags&Tm.Identifier){if(e)throw new K(`Cannot define property '${t}' as object identifier, property '${e}' is already defined as identifier property`);e=t}}),e}}),Object.defineProperty(t.prototype,`cloneAndEnhance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return new t({name:e.name||this.name,properties:Object.assign({},this.properties,e.properties),initializers:this.initializers.concat(e.initializers||[]),preProcessor:e.preProcessor||this.preProcessor,postProcessor:e.postProcessor||this.postProcessor})}}),Object.defineProperty(t.prototype,`actions`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;return this.cloneAndEnhance({initializers:[function(n){return t.instantiateActions(n,e(n)),n}]})}}),Object.defineProperty(t.prototype,`instantiateActions`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;if(!wh(t))throw new K(`actions initializer should return a plain object containing actions`);Object.getOwnPropertyNames(t).forEach(function(r){if(r in n.properties)throw new K(`'${r}' is a property and cannot be declared as an action`);if(r===mg)throw new K(`Cannot define action '${mg}', it should be defined using 'type.preProcessSnapshot(fn)' instead`);if(r===hg)throw new K(`Cannot define action '${hg}', it should be defined using 'type.postProcessSnapshot(fn)' instead`);var i=t[r],a=e[r];if(r in qp&&a){var o=i;i=function(){a.apply(null,arguments),o.apply(null,arguments)}}var s=i.$mst_middleware,c=i.bind(t);c._isFlowAction=i._isFlowAction||!1,c.$mst_middleware=s;var l=zm(e,r,c);t[r]=l,(Bh()?Mh:jh)(e,r,l)})}}),Object.defineProperty(t.prototype,`volatile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;if(typeof e!=`function`)throw new K(`You passed an ${typeof e} to volatile state as an argument, when function is expected`);return this.cloneAndEnhance({initializers:[function(n){return t.instantiateVolatileState(n,e(n)),n}]})}}),Object.defineProperty(t.prototype,`instantiateVolatileState`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;if(!wh(t))throw new K(`volatile state initializer should return a plain object containing state`);Object.getOwnPropertyNames(t).forEach(function(r){if(r in n.properties)throw new K(`'${r}' is a property and cannot be declared as volatile state`);Tr(e,r,t[r])})}}),Object.defineProperty(t.prototype,`extend`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;return this.cloneAndEnhance({initializers:[function(n){var r=e(n),i=r.actions,a=r.views,o=r.state;for(var s in Zp(r,[`actions`,`views`,`state`]))throw new K(`The \`extend\` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '${s}'`);return o&&t.instantiateVolatileState(n,o),a&&t.instantiateViews(n,a),i&&t.instantiateActions(n,i),n}]})}}),Object.defineProperty(t.prototype,`views`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;return this.cloneAndEnhance({initializers:[function(n){return t.instantiateViews(n,e(n)),n}]})}}),Object.defineProperty(t.prototype,`instantiateViews`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;if(!wh(t))throw new K(`views initializer should return a plain object containing views`);Object.getOwnPropertyNames(t).forEach(function(r){var i;if(r in n.properties)throw new K(`'${r}' is a property and cannot be declared as a view`);var a=Object.getOwnPropertyDescriptor(t,r);if(`get`in a)Er(e,r,a),Ur(e,(i={},i[r]=jt,i));else if(typeof a.value==`function`)(Bh()?Mh:jh)(e,r,a.value);else throw new K(`A view member should either be a function or getter based property`)})}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=ah(r)?r:this.applySnapshotPreProcessor(r);return th(this,e,t,n,i)}}),Object.defineProperty(t.prototype,`initializeChildNodes`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){t===void 0&&(t={});var n=e.type,r={};return n.forAllProps(function(n,i){r[n]=i.instantiate(e,n,void 0,t[n])}),r}}),Object.defineProperty(t.prototype,`createNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=Xp(Xp({},gh),{name:this.name});return L.object(e,hh,t)}}),Object.defineProperty(t.prototype,`finalizeNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){jh(t,`toString`,gg),this.forAllProps(function(n){gr(t,n,e.unbox)}),this.initializers.reduce(function(e,t){return t(e)},t),_r(t,this.willChange),Dr(t,this.didChange)}}),Object.defineProperty(t.prototype,`willChange`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e,n=sh(t.object),r=t.name;n.assertWritable({subpath:r});var i=n.type.properties[r];return i&&(Xm(i,t.newValue),t.newValue=i.reconcile(n.getChildNode(r),t.newValue,n,r)),t}}),Object.defineProperty(t.prototype,`didChange`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e,n=sh(t.object);if(n.type.properties[t.name]){var r=t.oldValue?t.oldValue.snapshot:void 0;n.emitPatch({op:`replace`,path:Yh(t.name),value:t.newValue.snapshot,oldValue:r},n)}}}),Object.defineProperty(t.prototype,`getChildren`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this,n=[];return this.forAllProps(function(r){n.push(t.getChildNode(e,r))}),n}}),Object.defineProperty(t.prototype,`getChildNode`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(!(t in this.properties))throw new K(`Not a value property: `+t);var n=Ni(e.storedValue,t),r=n.raw?.call(n);if(!r)throw new K(`Node not available for property `+t);return r}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;t===void 0&&(t=!0);var r={};return this.forAllProps(function(t,i){Mi(e.storedValue,t).reportObserved(),r[t]=n.getChildNode(e,t).snapshot}),t?this.applySnapshotPostProcessor(r):r}}),Object.defineProperty(t.prototype,`processInitialSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t={};return Object.keys(e).forEach(function(n){t[n]=e[n].getSnapshot()}),this.applySnapshotPostProcessor(t)}}),Object.defineProperty(t.prototype,`applyPatchLocally`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){if(!(n.op===`replace`||n.op===`add`))throw new K(`object does not support operation ${n.op}`);e.storedValue[t]=n.value}}),Object.defineProperty(t.prototype,`applySnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){Xm(this,t);var n=this.applySnapshotPreProcessor(t);this.forAllProps(function(t){e.storedValue[t]=n[t]})}}),Object.defineProperty(t.prototype,`applySnapshotPreProcessor`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.preProcessor;return t?t.call(null,e):e}}),Object.defineProperty(t.prototype,`applySnapshotPostProcessor`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.postProcessor;return t?t.call(null,e):e}}),Object.defineProperty(t.prototype,`getChildType`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return Wh(e,1),this.properties[e]}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this,r=this.applySnapshotPreProcessor(e);return wh(r)?Ym(this.propertyNames.map(function(e){return n.properties[e].validate(r[e],Km(t,e,n.properties[e]))})):Jm(t,r,`Value is not a plain object`)}}),Object.defineProperty(t.prototype,`forAllProps`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this.propertyNames.forEach(function(n){return e(n,t.properties[n])})}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;return`{ `+this.propertyNames.map(function(t){return t+`: `+e.properties[t].describe()}).join(`; `)+` }`}}),Object.defineProperty(t.prototype,`getDefaultSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return hh}}),Object.defineProperty(t.prototype,`removeChild`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){e.storedValue[t]=void 0}}),t}(km);yg.prototype.applySnapshot=Vn(yg.prototype.applySnapshot);function bg(){var e=[...arguments];if(Bh()&&typeof e[0]!=`string`&&e[1])throw new K(`Model creation failed. First argument must be a string when two arguments are provided`);return new yg({name:typeof e[0]==`string`?e.shift():`AnonymousModel`,properties:e.shift()||{}})}function xg(){var e=[...arguments],t=typeof e[0]==`string`,n=t?e[0]:`AnonymousModel`;return t&&e.shift(),Bh()&&e.forEach(function(e,n){Vh(e,Sg,`mobx-state-tree model type`,t?n+2:n+1)}),e.reduce(function(e,t){return e.cloneAndEnhance({name:e.name+`_`+t.name,properties:t.properties,initializers:t.initializers,preProcessor:function(n){return t.applySnapshotPreProcessor(e.applySnapshotPreProcessor(n))},postProcessor:function(n){return t.applySnapshotPostProcessor(e.applySnapshotPostProcessor(n))}})}).named(n)}function Sg(e){return jm(e)&&(e.flags&Tm.Object)>0}var Cg=function(e){Yp(t,e);function t(t,n,r,i){i===void 0&&(i=_h);var a=e.call(this,t)||this;return Object.defineProperty(a,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(a,`checker`,{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(a,`initializer`,{enumerable:!0,configurable:!0,writable:!0,value:i}),a.flags=n,a}return Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return nh(this,e,t,n,r)}}),Object.defineProperty(t.prototype,`createNewInstance`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.initializer(e)}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return Eh(e)&&this.checker(e)?qm():Jm(t,e,`Value is not a ${this.name===`Date`?`Date or a unix milliseconds timestamp`:this.name}`)}}),t}(Am),wg=new Cg(`string`,Tm.String,function(e){return typeof e==`string`}),Tg=new Cg(`number`,Tm.Number,function(e){return typeof e==`number`}),Eg=new Cg(`integer`,Tm.Integer,function(e){return vh(e)}),Dg=new Cg(`float`,Tm.Float,function(e){return yh(e)}),Og=new Cg(`finite`,Tm.Finite,function(e){return bh(e)}),kg=new Cg(`boolean`,Tm.Boolean,function(e){return typeof e==`boolean`}),Ag=new Cg(`null`,Tm.Null,function(e){return e===null}),jg=new Cg(`undefined`,Tm.Undefined,function(e){return e===void 0}),Mg=new Cg(`Date`,Tm.Date,function(e){return typeof e==`number`||e instanceof Date},function(e){return e instanceof Date?e:new Date(e)});Mg.getSnapshot=function(e){return e.storedValue.getTime()};var Ng=Mg;function Pg(e){switch(typeof e){case`string`:return wg;case`number`:return Tg;case`boolean`:return kg;case`object`:if(e instanceof Date)return Ng}throw new K(`Cannot determine primitive type from value `+e)}function Fg(e){return jm(e)&&(e.flags&(Tm.String|Tm.Number|Tm.Integer|Tm.Boolean|Tm.Date))>0}var Ig=function(e){Yp(t,e);function t(t){var n=e.call(this,JSON.stringify(t))||this;return Object.defineProperty(n,`value`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Tm.Literal}),n.value=t,n}return Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return nh(this,e,t,n,r)}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return JSON.stringify(this.value)}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return Eh(e)&&e===this.value?qm():Jm(t,e,`Value is not a literal ${JSON.stringify(this.value)}`)}}),t}(Am);function Lg(e){return Vh(e,Eh,`primitive`,1),new Ig(e)}var Rg=function(e){Yp(t,e);function t(t,n,r,i){var a=e.call(this,t)||this;return Object.defineProperty(a,`_subtype`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(a,`_predicate`,{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(a,`_message`,{enumerable:!0,configurable:!0,writable:!0,value:i}),a}return Object.defineProperty(t.prototype,`flags`,{get:function(){return this._subtype.flags|Tm.Refinement},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return this._subtype.instantiate(e,t,n,r)}}),Object.defineProperty(t.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._subtype.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this._subtype.validate(e,t);if(n.length>0)return n;var r=ah(e)?sh(e).snapshot:e;return this._predicate(r)?qm():Jm(t,e,this._message(e))}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return this._subtype.reconcile(e,t,n,r)}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),t}(Om);function zg(){var e=[...arguments],t=typeof e[0]==`string`?e.shift():jm(e[0])?e[0].name:null,n=e[0],r=e[1],i=e[2]?e[2]:function(e){return`Value does not respect the refinement predicate`};return Mm(n,[1,2]),Wh(t,1),Hh(r,[2,3]),Hh(i,[3,4]),new Rg(t,n,r,i)}function Bg(e,t){var n=typeof e==`string`?t:e;Bh()&&n.forEach(function(e,t){Wh(e,t+1)});var r=Hg.apply(void 0,em([],$p(n.map(function(e){return Lg(``+e)})),!1));return typeof e==`string`&&(r.name=e),r}var Vg=function(e){Yp(t,e);function t(t,n,r){var i=e.call(this,t)||this;return Object.defineProperty(i,`_types`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(i,`_dispatcher`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,`_eager`,{enumerable:!0,configurable:!0,writable:!0,value:!0}),r=Xp({eager:!0,dispatcher:void 0},r),i._dispatcher=r.dispatcher,r.eager||(i._eager=!1),i}return Object.defineProperty(t.prototype,`flags`,{get:function(){var e=Tm.Union;return this._types.forEach(function(t){e|=t.flags}),e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._types.some(function(t){return t.isAssignableFrom(e)})}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return`(`+this._types.map(function(e){return e.describe()}).join(` | `)+`)`}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=this.determineType(r,void 0);if(!i)throw new K(`No matching type for union `+this.describe());return i.instantiate(e,t,n,r)}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=this.determineType(t,e.getReconciliationType());if(!i)throw new K(`No matching type for union `+this.describe());return i.reconcile(e,t,n,r)}}),Object.defineProperty(t.prototype,`determineType`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this._dispatcher?this._dispatcher(e):t?t.is(e)?t:this._types.filter(function(e){return e!==t}).find(function(t){return t.is(e)}):this._types.find(function(t){return t.is(e)})}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this._dispatcher)return this._dispatcher(e).validate(e,t);for(var n=[],r=0,i=0;i<this._types.length;i++){var a=this._types[i].validate(e,t);if(a.length===0){if(this._eager)return qm();r++}else n.push(a)}return r===1?qm():Jm(t,e,`No type is applicable for the union`).concat(Ym(n))}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._types}}),t}(Om);function Hg(e){var t=[...arguments].slice(1),n=jm(e)?void 0:e,r=jm(e)?em([e],$p(t),!1):t,i=`(`+r.map(function(e){return e.name}).join(` | `)+`)`;return Bh()&&(n&&Vh(n,function(e){return wh(e)},`object { eager?: boolean, dispatcher?: Function }`,1),r.forEach(function(e,t){Mm(e,n?t+2:t+1)})),new Vg(i,r,n)}function Ug(e){return jm(e)&&(e.flags&Tm.Union)>0}var Wg=function(e){Yp(t,e);function t(t,n,r){var i=e.call(this,t.name)||this;return Object.defineProperty(i,`_subtype`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(i,`_defaultValue`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(i,`optionalValues`,{enumerable:!0,configurable:!0,writable:!0,value:r}),i}return Object.defineProperty(t.prototype,`flags`,{get:function(){return this._subtype.flags|Tm.Optional},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype.describe()+`?`}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){if(this.optionalValues.indexOf(r)>=0){var i=this.getDefaultInstanceOrSnapshot();return this._subtype.instantiate(e,t,n,i)}return this._subtype.instantiate(e,t,n,r)}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return this._subtype.reconcile(e,this.optionalValues.indexOf(t)<0&&this._subtype.is(t)?t:this.getDefaultInstanceOrSnapshot(),n,r)}}),Object.defineProperty(t.prototype,`getDefaultInstanceOrSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=typeof this._defaultValue==`function`?this._defaultValue():this._defaultValue;return typeof this._defaultValue==`function`&&Xm(this,e),e}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this.optionalValues.indexOf(e)>=0?qm():this._subtype.validate(e,t)}}),Object.defineProperty(t.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._subtype.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),t}(Om);function Gg(e,t){if(typeof t!=`function`&&ah(t))throw new K(`default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead`);Mm(e,1),Bh()&&typeof t!=`function`&&Xm(e,t)}function Kg(e,t,n){return Gg(e,t),new Wg(e,t,n||qg)}var qg=[void 0],Jg=Kg(jg,void 0),Yg=Kg(Ag,null);function Xg(e){return Mm(e,1),Hg(e,Jg)}function Zg(e){return Mm(e,1),Hg(e,Yg)}var Qg=function(e){Yp(t,e);function t(t,n){var r=e.call(this,t)||this;return Object.defineProperty(r,`_definition`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(r,`_subType`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),r}return Object.defineProperty(t.prototype,`flags`,{get:function(){return(this._subType?this._subType.flags:0)|Tm.Late},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`getSubType`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!this._subType){var t=void 0;try{t=this._definition()}catch(e){if(e instanceof ReferenceError)t=void 0;else throw e}if(e&&t===void 0)throw new K(`Late type seems to be used too early, the definition (still) returns undefined`);if(t){if(Bh()&&!jm(t))throw new K(`Failed to determine subtype, make sure types.late returns a type definition.`);this._subType=t}}return this._subType}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return this.getSubType(!0).instantiate(e,t,n,r)}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return this.getSubType(!0).reconcile(e,t,n,r)}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.getSubType(!1);return e?e.name:`<uknown late type>`}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this.getSubType(!1);return n?n.validate(e,t):qm()}}),Object.defineProperty(t.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.getSubType(!1);return t?t.isAssignableFrom(e):!1}}),Object.defineProperty(t.prototype,`getSubTypes`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.getSubType(!1)||Em}}),t}(Om);function $g(e,t){var n=typeof e==`string`?e:`late(${e.toString()})`,r=typeof e==`string`?t:e;if(Bh()&&!(typeof r==`function`&&r.length===0))throw new K(`Invalid late type, expected a function with zero arguments that returns a type, got: `+r);return new Qg(n,r)}function e_(e,t){return new t_(e,t)}var t_=function(e){Yp(t,e);function t(t,n){var r=e.call(this,t)||this;return Object.defineProperty(r,`options`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(r,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Tm.Lazy}),Object.defineProperty(r,`loadedType`,{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(r,`pendingNodeList`,{enumerable:!0,configurable:!0,writable:!0,value:L.array()}),jr(function(){return r.pendingNodeList.length>0&&r.pendingNodeList.some(function(e){return e.isAlive&&r.options.shouldLoadPredicate(e.parent?e.parent.value:null)})},function(){r.options.loadType().then(Vn(function(e){r.loadedType=e,r.pendingNodeList.forEach(function(e){e.parent&&r.loadedType&&e.parent.applyPatches([{op:`replace`,path:`/${e.subpath}`,value:e.snapshot}])})}))}),r}return Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return`<lazy ${this.name}>`}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=this;if(this.loadedType)return this.loadedType.instantiate(e,t,n,r);var a=nh(this,e,t,n,Oh(r));return this.pendingNodeList.push(a),jr(function(){return!a.isAlive},function(){return i.pendingNodeList.splice(i.pendingNodeList.indexOf(a),1)}),a}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this.loadedType?this.loadedType.validate(e,t):kh(e)?qm():Jm(t,e,`Value is not serializable and cannot be lazy`)}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(t,n,r,i){return this.loadedType?(t.die(),this.loadedType.instantiate(r,i,r.environment,n)):e.prototype.reconcile.call(this,t,n,r,i)}}),t}(Am),n_=function(e){Yp(t,e);function t(t){var n=e.call(this,t?`frozen(${t.name})`:`frozen`)||this;return Object.defineProperty(n,`subType`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(n,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Tm.Frozen}),n}return Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return`<any immutable value>`}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return nh(this,e,t,n,Oh(r))}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return kh(e)?this.subType?this.subType.validate(e,t):qm():Jm(t,e,`Value is not serializable and cannot be frozen`)}}),t}(Am),r_=new n_;function i_(e){return arguments.length===0?r_:jm(e)?new n_(e):Kg(r_,e)}function a_(e){switch(e){case qp.beforeDestroy:return`destroy`;case qp.beforeDetach:return`detach`;default:return}}var o_=function(){function e(e,t){if(Object.defineProperty(this,`targetType`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,`identifier`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`node`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`resolvedReference`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),y_(e))this.identifier=e;else if(ah(e)){var n=sh(e);if(!n.identifierAttribute)throw new K(`Can only store references with a defined identifier attribute.`);var r=n.unnormalizedIdentifier;if(r==null)throw new K(`Can only store references to tree nodes with a defined identifier.`);this.identifier=r}else throw new K(`Can only store references to tree nodes or identifiers, got: '${e}'`)}return Object.defineProperty(e.prototype,`updateResolvedReference`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=v_(this.identifier),n=e.root,r=n.identifierCache.getLastCacheModificationPerId(t);if(!this.resolvedReference||this.resolvedReference.lastCacheModification!==r){var i=this.targetType,a=n.identifierCache.resolve(i,t);if(!a)throw new s_(`[mobx-state-tree] Failed to resolve reference '${this.identifier}' to type '${this.targetType.name}' (from node: ${e.path})`);this.resolvedReference={node:a,lastCacheModification:r}}}}),Object.defineProperty(e.prototype,`resolvedValue`,{get:function(){return this.updateResolvedReference(this.node),this.resolvedReference.node.value},enumerable:!1,configurable:!0}),e}(),s_=function(e){Yp(t,e);function t(n){var r=e.call(this,n)||this;return Object.setPrototypeOf(r,t.prototype),r}return t}(Error),c_=function(e){Yp(t,e);function t(t,n){var r=e.call(this,`reference(${t.name})`)||this;return Object.defineProperty(r,`targetType`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(r,`onInvalidated`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(r,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Tm.Reference}),r}return Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,`isAssignableFrom`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.targetType.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return y_(e)?qm():Jm(t,e,`Value is not a valid identifier, which is a string or a number`)}}),Object.defineProperty(t.prototype,`fireInvalidated`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=t.parent;if(!(!i||!i.isAlive)){var a=i.storedValue;a&&this.onInvalidated({cause:e,parent:a,invalidTarget:r?r.storedValue:void 0,invalidId:n,replaceRef:function(e){rm(t.root.storedValue,{op:`replace`,value:e,path:t.path})},removeRef:function(){Sg(i.type)?this.replaceRef(void 0):rm(t.root.storedValue,{op:`remove`,path:t.path})}})}}}),Object.defineProperty(t.prototype,`addTargetNodeWatcher`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this,r=this.getValue(e);if(r){var i=sh(r),a=function(r,a){var o=a_(a);o&&n.fireInvalidated(o,e,t,i)},o=i.registerHook(qp.beforeDetach,a),s=i.registerHook(qp.beforeDestroy,a);return function(){o(),s()}}}}),Object.defineProperty(t.prototype,`watchTargetNodeForInvalidations`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){var r=this;if(this.onInvalidated){var i;e.registerHook(qp.beforeDestroy,function(){i&&i()});var a=function(a){i&&i();var o=e.parent,s=o&&o.storedValue;if(o&&o.isAlive&&s){var c=void 0;c=n?!!n.get(t,s):e.root.identifierCache.has(r.targetType,v_(t)),c?i=r.addTargetNodeWatcher(e,t):a||r.fireInvalidated(`invalidSnapshotReference`,e,t,null)}};e.state===ih.FINALIZED?a(!0):(e.isRoot||e.root.registerHook(qp.afterCreationFinalization,function(){e.parent&&e.parent.createObservableInstanceIfNeeded()}),e.registerHook(qp.afterAttach,function(){a(!1)}))}}}),t}(Am),l_=function(e){Yp(t,e);function t(t,n){return e.call(this,t,n)||this}return Object.defineProperty(t.prototype,`getValue`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(e.isAlive)return e.storedValue.resolvedValue}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue.identifier}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=ah(r)?fm(r):r,a=new o_(r,this.targetType),o=nh(this,e,t,n,a);return a.node=o,this.watchTargetNodeForInvalidations(o,i,void 0),o}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){if(!e.isDetaching&&e.type===this){var i=ah(t),a=e.storedValue;if(!i&&a.identifier===t||i&&a.resolvedValue===t)return e.setParent(n,r),e}var o=this.instantiate(n,r,void 0,t);return e.die(),o}}),t}(c_),u_=function(e){Yp(t,e);function t(t,n,r){var i=e.call(this,t,r)||this;return Object.defineProperty(i,`options`,{enumerable:!0,configurable:!0,writable:!0,value:n}),i}return Object.defineProperty(t.prototype,`getValue`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(e.isAlive)return this.options.get(e.storedValue,e.parent?e.parent.storedValue:null)}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=ah(r)?this.options.set(r,e?e.storedValue:null):r,a=nh(this,e,t,n,i);return this.watchTargetNodeForInvalidations(a,i,this.options),a}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=ah(t)?this.options.set(t,e?e.storedValue:null):t;if(!e.isDetaching&&e.type===this&&e.storedValue===i)return e.setParent(n,r),e;var a=this.instantiate(n,r,void 0,i);return e.die(),a}}),t}(c_);function d_(e,t){if(Mm(e,1),Bh()&&arguments.length===2&&typeof arguments[1]==`string`)throw new K(`References with base path are no longer supported. Please remove the base path.`);var n=t||void 0,r=t?t.onInvalidated:void 0;if(n&&(n.get||n.set)){if(Bh()&&(!n.get||!n.set))throw new K(`reference options must either contain both a 'get' and a 'set' method or none of them`);return new u_(e,{get:n.get,set:n.set},r)}else return new l_(e,r)}function f_(e,t){var n=d_(e,Xp(Xp({},t),{onInvalidated:function(e){t&&t.onInvalidated&&t.onInvalidated(e),e.removeRef()}}));return t&&t.acceptsUndefined===!1?n:Xg(n)}var p_=function(e){Yp(t,e);function t(t,n){var r=e.call(this,t)||this;return Object.defineProperty(r,`validType`,{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(r,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Tm.Identifier}),r}return Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){if(!e||!(e.type instanceof yg))throw new K(`Identifier types can only be instantiated as direct child of a model type`);return nh(this,e,t,n,r)}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){if(e.storedValue!==t)throw new K(`Tried to change identifier from '${e.storedValue}' to '${t}'. Changing identifiers is not allowed.`);return e.setParent(n,r),e}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return typeof e===this.validType?qm():Jm(t,e,`Value is not a valid ${this.describe()}, expected a ${this.validType}`)}}),t}(Am),m_=function(e){Yp(t,e);function t(){var t=e.call(this,`identifier`,`string`)||this;return Object.defineProperty(t,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Tm.Identifier}),t}return Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return`identifier`}}),t}(p_),h_=function(e){Yp(t,e);function t(){return e.call(this,`identifierNumber`,`number`)||this}return Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return`identifierNumber`}}),t}(p_),g_=new m_,__=new h_;function v_(e){return``+e}function y_(e){return typeof e==`string`||typeof e==`number`}function b_(e){return new x_(e)}var x_=function(e){Yp(t,e);function t(t){var n=e.call(this,t.name)||this;return Object.defineProperty(n,`options`,{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(n,`flags`,{enumerable:!0,configurable:!0,writable:!0,value:Tm.Custom}),n}return Object.defineProperty(t.prototype,`describe`,{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,`isValidSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this.options.isTargetType(e))return qm();var n=this.options.getValidationMessage(e);return n?Jm(t,e,`Invalid value for type '${this.name}': ${n}`):qm()}}),Object.defineProperty(t.prototype,`getSnapshot`,{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.options.toSnapshot(e.storedValue)}}),Object.defineProperty(t.prototype,`instantiate`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=this.options.isTargetType(r)?r:this.options.fromSnapshot(r,e&&e.root.environment);return nh(this,e,t,n,i)}}),Object.defineProperty(t.prototype,`reconcile`,{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){var i=!this.options.isTargetType(t);if(!e.isDetaching&&e.type===this&&(i?t===e.snapshot:t===e.storedValue))return e.setParent(n,r),e;var a=i?this.options.fromSnapshot(t,n.root.environment):t,o=this.instantiate(n,r,void 0,a);return e.die(),o}}),t}(Am),q={enumeration:Bg,model:bg,compose:xg,custom:b_,reference:d_,safeReference:f_,union:Hg,optional:Kg,literal:Lg,maybe:Xg,maybeNull:Zg,refinement:zg,string:wg,boolean:kg,number:Tg,integer:Eg,float:Dg,finite:Og,Date:Ng,map:cg,array:ug,frozen:i_,identifier:g_,identifierNumber:__,late:$g,lazy:e_,undefined:jg,null:Ag,snapshotProcessor:ng};function S_({oldText:e,newText:t,element:n}){if(!(t.length/Math.max(20,e.length)>=4))return n.fontSize;let r=n.width*n.page.computedHeight/t.length,i=1.5*Math.sqrt(r),a=n.fontSize;return Math.min(a,Math.max(5,Math.round(i)))}function C_(e){try{let{stops:t}=Nf(e);if(t.length===0)return 127.5;let n=0,r=0;for(let e of t)try{let t=Du.Util.colorToRGBA(e.color);if(!t||t.a<.5)continue;n+=(299*t.r+587*t.g+114*t.b)/1e3,r++}catch{continue}return r===0?127.5:n/r}catch(e){return console.warn(`Error calculating gradient brightness:`,e),127.5}}function w_(e){if(jf(e))return C_(e);let t=Du.Util.colorToRGBA(e);if(!t)return 127.5;let{r:n,g:r,b:i}=t;return(299*n+587*r+114*i)/1e3}function T_(e){let{outlineSize:t,outlineColor:n}=function(e){let t=e.strokeWidth||0;return t>0?{outlineSize:t,outlineColor:e.stroke}:{outlineSize:e.shadowEnabled&&e.shadowBlur>0&&e.shadowOpacity>.1?e.shadowBlur*e.shadowOpacity:0,outlineColor:e.shadowColor}}(e);if(t<.001)return e.fill;let r=w_(e.fill),i=w_(n);return Math.abs(r-i)>=50?n:e.fill}var E_;function D_(){return E_||(E_=document.getElementById(`polotno-text-style`),E_||(E_=document.createElement(`style`),E_.id=`polotno-text-style`,document.head.appendChild(E_)),E_)}Du._fixTextRendering=!0;var O_={border:`none`,padding:`0px`,overflow:`hidden`,background:`none`,outline:`none`,resize:`none`,overflowWrap:`break-word`,whiteSpace:`pre-wrap`,userSelect:`text`,wordBreak:`normal`,textTransform:`none`},k_=sa(({textNodeRef:e,element:t,onBlur:n,selectAll:r,cursorPosition:i})=>{let[a,o]=d.useState(O_),s=e.current;d.useLayoutEffect(()=>{if(!s)return;let e={};e.width=s.width()-2*s.padding()+`px`,e.height=s.height()-2*s.padding()+s.fontSize()*s.lineHeight()+`px`,e.fontSize=s.fontSize()+`px`,e.lineHeight=s.lineHeight()+.01,e.fontFamily=s.fontFamily(),e.textAlign=s.align(),e.color=s.fill(),e.fontWeight=t.fontWeight,e.fontStyle=t.fontStyle,e.letterSpacing=t.letterSpacing+`em`,e.opacity=Math.max(t.a.opacity,.2),e.textTransform=t.textTransform,e.caretColor=T_(t);let n=`\n .polotno-input::placeholder {\n color: ${a.color};\n opacity: 0.6;\n }\n `,r=D_();r.innerHTML=``,r.appendChild(document.createTextNode(n)),JSON.stringify(e)!==JSON.stringify(a)&&o(e)});let c=d.useRef(null);if(d.useLayoutEffect(()=>{var e;let t=c.current;t&&((e=c.current)==null||e.focus(),t.selectionStart=t.selectionEnd=i||t.value.length,r&&(t?.select(),document.execCommand(`selectAll`,!1,void 0)))},[]),d.useEffect(()=>{window.addEventListener(`blur`,n);let e=e=>{var t;(t=c.current)!=null&&t.contains(e.target)||n()};return window.addEventListener(`touchstart`,e),()=>{window.removeEventListener(`blur`,n),window.removeEventListener(`touchstart`,e)}},[]),!s)return null;let l=0,u=s.textArr.length*s.lineHeight()*s.fontSize();t.verticalAlign===`middle`&&(l=(t.a.height-u)/2),t.verticalAlign===`bottom`&&(l=t.a.height-u);let f=Qf(t.text);return d.createElement(`textarea`,{className:`polotno-input`,ref:c,dir:Np(f),style:Object.assign(Object.assign(Object.assign({},O_),a),{paddingTop:l+`px`}),value:f,onChange:e=>{let n=S_({oldText:t.text,newText:e.target.value,element:t});t.set({text:e.target.value,fontSize:n})},placeholder:t.placeholder,onBlur:n})}),A_=e=>d.createElement(cf,null,d.createElement(k_,Object.assign({},e))),j_=(e,t,n,r,i)=>{let[a,o]=d.useReducer(e=>e+1,0),s=d.useRef(fp(t,n,r)),c=d.useRef(null);return d.useLayoutEffect(()=>{if(s.current=fp(t,n,r),s.current)return;let a=!0;return(async()=>{s.current=!1,o();let l=Kf(`text ${t}`);await e.loadFont(t,n,r,i),a?(c.current=l,s.current=!0,o()):l()})(),()=>{c.current&&=(c.current(),null),a=!1}},[t,n,r]),d.useEffect(()=>{s.current&&setTimeout(()=>{c.current&&=(c.current(),null)})},[s.current]),[s.current]},M_=({fontLoaded:e,fontFamily:t,fontSize:n,lineHeight:r})=>d.useMemo(()=>Bp({fontFamily:t,fontSize:n,lineHeight:r}),[e,t,n,r]);function N_(e){let t=d.useRef(e),n=d.useRef(e);return d.useMemo(()=>{n.current=t.current,t.current=e},[e]),n.current}function P_(e,t,n=!1){let r=e.fontSize(),i=e.height(),a=Qf(t.text),o=t.a.fontSize;e.height(void 0);let s=Math.round(2*t.a.fontSize)-1;for(let r=1;r<s;r++){let r=t.a.height&&e.height()>t.a.height,i=a.split(`
47
+ `).join(` `).split(/[\s-]+/).reduce((e,t)=>(t=t.toLowerCase(),/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\uAC00-\uD7AF]/.test(t)?e.concat(t.split(``)):e.concat(t)),[]),s=e.textArr.map(e=>e.text.toLowerCase()).join(`;`),c=i.find(e=>!s.includes(e)||(s=s.replace(e,``),!1));if(!(r||c&&!n))break;o-=.5,e.fontSize(o)}return e.fontSize(r),e.height(i),o}var F_=sa(({element:e,store:t})=>{let n=d.useRef(null),r=d.useRef(null),i=d.useRef(null),a=d.useRef([]),[,o]=d.useReducer(e=>e+1,0),{editorEnabled:s,selectAll:c}=(e=>{let[t,n]=d.useState(!1),r=d.useRef(!1);return d.useEffect(()=>{var t=!0;return setTimeout(()=>{t&&(e._editModeEnabled&&(r.current=!0),n(!0),setTimeout(()=>{r.current=!1},50))},50),()=>{t=!1}},[]),{editorEnabled:t&&e._editModeEnabled,selectAll:r.current}})(e),[l,u]=d.useState(!1),f=d.useRef(e.a.height),p=t.selectedShapes.indexOf(e)>=0&&e.selectable,m=N_(p),{textVerticalResizeEnabled:h}=Sp,g=Sp.autoDeleteEmptyText,_=N_(e.fontFamily),[v,y]=d.useState([]);d.useEffect(()=>{let e=n.current?.textArr??[];JSON.stringify(e)!==JSON.stringify(v)&&y(e)}),d.useEffect(()=>{if(e.a.width||e.type===`tablecell`)return;let t=n.current;t.width(600),e.set({width:1.4*t.getTextWidth()})},[]),d.useEffect(()=>{m&&!p&&g&&e.text===``&&e.removable&&!e.placeholder&&t.deleteElements([e.id])},[g,e.placeholder,e.removable,e.text,p,m]),d.useLayoutEffect(()=>Gn(()=>{let t=n.current;Hp(t,e)})),d.useEffect(()=>{let e=a.current;e.length>0&&(a.current=[],e.forEach(e=>e()))});let b=Qf(e.text);e.textTransform===`uppercase`&&(b=b.toUpperCase());let[x]=j_(t,e.fontFamily,e.fontStyle,e.fontWeight,e.text||e.placeholder),S=()=>{if(e.curveEnabled){let e=r.current;return e.getSelfRect().height||e.fontSize()}let t=n.current.clone({height:void 0}),i=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),i};d.useLayoutEffect(()=>{if(!x)return;if(e.type===`tablecell`){let{textOverflow:r}=Sp;if(r===`resize`){let t=S(),n=hm(e)?om(e,2):null;n!=null&&n.setCellContentHeight&&n.setCellContentHeight(e.id,t)}else if(r===`change-font-size`){let r=n.current;if(r){let n=P_(r,e,Sp.textSplitAllowed);n!==e.fontSize&&t.history.ignore(()=>{e.set({fontSize:n})})}}return}let{textOverflow:r,textSplitAllowed:i}=Sp,s=(n,r,i,s)=>{let c=Kf(`text ${e.id}`),l=()=>{t.history.ignore(n,r,i).then(()=>{a.current.push(c),o()})};s?queueMicrotask(l):l()};if(!e.height){let t=S();s(()=>{e.height||e.set({height:t})},void 0,void 0,!0);return}if(!t.isPlaying)if(r!==`change-font-size`||l){if(r===`resize`){let t=S();h&&e.height<t&&!l&&s(()=>{var r;hm(e)&&e.set({height:t}),(r=n.current)==null||r.height(t)},!1,!0),h||e.height===t||l||s(()=>{var r;hm(e)&&e.set({height:t}),(r=n.current)==null||r.height(t)},!1,!0)}}else{let t=P_(n.current,e,i);if(t!==e.fontSize){s(()=>{e.set({fontSize:t})},!1,!0);return}let r=S();e.height===r||h||s(()=>{e.set({height:r})},!1,!0)}}),d.useLayoutEffect(()=>{if(x&&e.curveEnabled){let t=r.current?.getSelfRect().width;if(t){let n=t-e.a.width,r=e.a.rotation*Math.PI/180,i=-n/2*Math.cos(r),a=-n/2*Math.sin(r);e.set({width:t,x:e.a.x+i,y:e.a.y+a})}}},[x,e.curveEnabled,e.curvePower,e.text,e.fontSize,e.fontFamily,e.fontWeight,e.fontStyle,e.letterSpacing]),d.useLayoutEffect(()=>{let t=n.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),Hp(t,e))},[x]);let C=d.useRef(null),w=d.useRef(0),T=n=>{n.evt.preventDefault(),t.selectedShapes.find(t=>t===e)&&e.contentEditable&&(w.current=function(e){let t=e.target,n=function(e){var t=e.getAbsoluteTransform().copy();t.invert();var n=e.getStage().getPointerPosition();return t.point(n)}(t),r=t.textArr,i=Math.floor(n.y/(t.fontSize()*t.lineHeight())),a=r.slice(0,i).reduce((e,t)=>e+t.text.length,i),o=r[i]??r[0],s=0;return t.align()===`right`?s=t.width()-o.width:t.align()===`center`&&(s=t.width()/2-o.width/2),a+Math.round((n.x-s)/o.width*o.text.length)}(n),e.toggleEditMode())},E=!b&&e.placeholder?.6:e.a.opacity;Rf(n,E);let D=M_({fontLoaded:x,fontFamily:e.fontFamily,fontSize:e.a.fontSize,lineHeight:e.lineHeight}),O=e.selectable||t.role===`admin`,k=Pf(e),A=Pf(e,e.stroke,`stroke`),j=d.useMemo(()=>e.backgroundEnabled?e.curveEnabled?function({width:e,height:t,padding:n=0,cornerRadius:r=0}){let i=-n,a=-n,o=e+n,s=t+n;return Of(Df(`M ${i} ${a} L ${o} ${a} L ${o} ${s} L ${i} ${s} Z`),r).path}({width:e.a.width,height:e.a.height,cornerRadius:e.backgroundCornerRadius*(e.a.fontSize*D*.5),padding:e.backgroundPadding*(e.a.fontSize*D*.5)}):function({lines:e,lineHeight:t,width:n,align:r=`left`,padding:i=0,cornerRadius:a=0}){e.forEach((e,t)=>{e.cx=n/2,r===`right`?e.cx=n-e.width/2:r===`left`&&(e.cx=e.width/2),r!==`justify`||e.lastInParagraph||(e.width=n),r===`justify`&&(e.cx=e.width/2)});let o=`M ${e[0]?.cx} ${-i}`;e.forEach((n,r)=>{let{cx:a}=n,s=e[r-1];s&&s.width>n.width?o+=` L ${a+n.width/2+i} ${r*t+i}`:o+=` L ${a+n.width/2+i} ${r*t-i}`;let c=e[r+1];c&&c.width>n.width?o+=` L ${a+n.width/2+i} ${(r+1)*t-i}`:o+=` L ${a+n.width/2+i} ${(r+1)*t+i}`});for(var s=e.length-1;s>=0;s--){let n=e[s],{cx:r}=n,a=e[s+1];a&&a.width>n.width?o+=` L ${r-n.width/2-i} ${(s+1)*t-i}`:o+=` L ${r-n.width/2-i} ${(s+1)*t+i}`;let c=e[s-1];c&&c.width>n.width?o+=` L ${r-n.width/2-i} ${s*t+i}`:o+=` L ${r-n.width/2-i} ${s*t-i}`}return o+=` Z`,Of(Df(o),a).path}({lines:JSON.parse(JSON.stringify(v)),cornerRadius:e.backgroundCornerRadius*(e.a.fontSize*D*.5),lineHeight:D*e.a.fontSize,padding:e.backgroundPadding*(e.a.fontSize*D*.5),width:e.a.width,align:e.align}):``,[e.backgroundEnabled,e.curveEnabled,e.backgroundCornerRadius,e.a.fontSize,e.a.height,D,e.backgroundPadding,e.a.width,e.align,v]),M=Up(),N=0;e.curveEnabled||(e.verticalAlign===`middle`?N=(e.a.height-v.length*D*e.a.fontSize)/2:e.verticalAlign===`bottom`&&(N=e.a.height-v.length*D*e.a.fontSize));let P=e.curveEnabled?Pp(e.a.width,e.a.height,e.curvePower,e.a.fontSize):``,F=x?`"`+e.fontFamily+`"`:_===e.fontFamily?`Arial`:`"`+_+`"`;return d.createElement(d.Fragment,null,d.createElement($d,{ref:i,x:e.a.x,y:e.a.y,rotation:e.a.rotation,hideInExport:!e.showInExport,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity*E,data:j,fill:e.backgroundColor,offsetY:-N}),d.createElement($d,{data:P,stroke:`red`,strokeWidth:1,x:e.a.x,y:e.a.y,rotation:e.a.rotation,visible:!1}),d.createElement(Qd,Object.assign({ref:r,visible:e.curveEnabled,data:P,text:b||e.placeholder,listening:!1,align:`center`,textBaseline:`middle`},k,A,{strokeWidth:e.strokeWidth,lineJoin:`round`,fillAfterStrokeEnabled:!0,fontSize:e.a.fontSize,fontFamily:`"${e.fontFamily}", "${_}"`,fontStyle:e.fontStyle+` `+e.fontWeight,textDecoration:e.textDecoration.trim(),letterSpacing:e.letterSpacing*e.a.fontSize,x:e.a.x,y:e.a.y,rotation:e.a.rotation,opacity:e._editModeEnabled?.3:E,hideInExport:!e.showInExport,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity})),d.createElement(Zd,Object.assign({ref:n,id:e.selectable?e.id:void 0,name:e.selectable?`element`:``,hideInExport:!e.showInExport,editModeEnabled:e._editModeEnabled,x:e.a.x,y:e.a.y,rotation:e.a.rotation,width:e.a.width,height:e.a.height,text:b||e.placeholder,direction:Np(b)},k,A,{lineJoin:`round`,strokeWidth:e.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:e.a.fontSize,fontFamily:F,fontStyle:e.fontStyle+` `+e.fontWeight,textDecoration:e.textDecoration,align:e.align,verticalAlign:e.verticalAlign,draggable:M?e.draggable&&p:e.draggable,preventDefault:!M||p,opacity:e.curveEnabled?0:E,visible:!e._editModeEnabled,ellipsis:Sp.textOverflow===`ellipsis`,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,lineHeight:D,letterSpacing:e.letterSpacing*e.a.fontSize,listening:!!e.selectable&&O,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onClick:T,onTap:T,onTransformStart:()=>{u(!0),f.current=n.current.height()},onTransform:t=>{var n,r;let a=t.target;(n=i.current)==null||n.setAttrs({x:a.x(),y:a.y(),rotation:a.rotation(),scale:a.scale()});let o=(a.getStage()?.findOne(`Transformer`)).getActiveAnchor();if(o===`middle-left`||o===`middle-right`){let t=a.scaleX(),n=a.width()*t,r=e.a.fontSize,i=n;n<r&&(i=r,C.current&&a.position(C.current)),a.width(i),a.scaleX(1),a.scaleY(1);let o=S();if(Sp.textOverflow===`ellipsis`)o=f.current;else{let t=Math.max(o,f.current);a.height(t),e.set({height:a.height()})}let s=Sp.textVerticalResizeEnabled?Math.max(o,f.current):S();e.set({x:a.x(),width:a.width(),rotation:a.rotation(),height:s}),Hp(a,e)}if(o===`top-center`||o===`bottom-center`){let n=Sp.textOverflow===`resize`?S():D*e.a.fontSize;t.target.height(Math.max(n,t.target.height()*t.target.scaleY())),t.target.scaleY(1)}C.current=t.target.position();let s=t.target.scaleX();(r=i.current)==null||r.setAttrs({scaleX:1,scaleY:1}),t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.a.fontSize*s,width:t.target.width()*s,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*s,shadowBlur:e.shadowBlur*s,shadowOffsetX:e.shadowOffsetX*s,shadowOffsetY:e.shadowOffsetY*s,strokeWidth:e.strokeWidth*s})},onTransformEnd:t=>{var n;let r=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:Math.round(e.a.fontSize*r),width:Math.ceil(t.target.width()*r),x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*r,shadowBlur:e.shadowBlur*r,shadowOffsetX:e.shadowOffsetX*r,shadowOffsetY:e.shadowOffsetY*r,strokeWidth:e.strokeWidth*r}),(n=i.current)==null||n.setAttrs({scaleX:1,scaleY:1}),u(!1)}})),s&&e.contentEditable&&d.createElement(`Group`,{x:e.a.x,y:e.a.y,rotation:e.a.rotation},d.createElement(A_,{textNodeRef:n,element:e,selectAll:c,cursorPosition:w.current,onBlur:()=>{e.toggleEditMode(!1)}})))}),I_=r(((e,t)=>{e=t.exports=n;function n(e){return r.bind(null,e)}function r(e){var t=[].slice.call(arguments,1);t.unshift(`[`+e+`]`),process.stderr.write(t.join(` `)+`
48
+ `)}})),L_=r(((e,t)=>{var n=!1,r=!1,i=I_()(`lex`);e=t.exports=a;function a(e){var t,a=``,o,s=0,c=-1,l=0,u=1,d=`before-selector`,f=[d],p={},m=[],h=[`media`,`keyframes`,{name:`-webkit-keyframes`,type:`keyframes`,prefix:`-webkit-`},{name:`-moz-keyframes`,type:`keyframes`,prefix:`-moz-`},{name:`-ms-keyframes`,type:`keyframes`,prefix:`-ms-`},{name:`-o-keyframes`,type:`keyframes`,prefix:`-o-`},`font-face`,{name:`import`,state:`before-at-value`},{name:`charset`,state:`before-at-value`},`supports`,`viewport`,{name:`namespace`,state:`before-at-value`},`document`,{name:`-moz-document`,type:`document`,prefix:`-moz-`},`page`];function g(){return T(),e[c]}function _(e){return e?f[f.length-1-e]:d}function v(t){var n=c+1;return t===e.slice(n,n+t.length)}function y(t){var n=e.slice(c).indexOf(t);return n>0?n:!1}function b(e){return e===x(1)}function x(t){return e[c+(t||1)]}function S(){var e=f.pop();return d=f[f.length-1],e}function C(e){return d=e,f.push(d),f.length}function w(e){var t=d;return f[f.length-1]=d=e,t}function T(t){if((t||1)==1)e[c]==`
49
49
  `?(u++,s=1):s++,c++;else{var n=e.slice(c,c+t).split(`
50
50
  `);n.length>1&&(u+=n.length-1,s=1),s+=n[n.length-1].length,c+=t}}function E(){p.end={line:u,col:s},n&&i(`addToken:`,JSON.stringify(p,null,2)),m.push(p),a=``,p={}}function D(e){p={type:e,start:{line:u,col:s}}}for(r&&(t=Date.now());o=g();)switch(n&&i(o,_()),o){case` `:switch(_()){case`selector`:case`value`:case`value-paren`:case`at-group`:case`at-value`:case`comment`:case`double-string`:case`single-string`:a+=o;break}break;case`
51
51
  `:case` `:case`\r`:case`\f`:switch(_()){case`value`:case`value-paren`:case`at-group`:case`comment`:case`single-string`:case`double-string`:case`selector`:a+=o;break;case`at-value`:o===`
52
- `&&(p.value=a.trim(),E(),S());break}break;case`:`:switch(_()){case`name`:p.name=a.trim(),a=``,w(`before-value`);break;case`before-selector`:a+=o,D(`selector`),C(`selector`);break;case`before-value`:w(`value`),a+=o;break;default:a+=o;break}break;case`;`:switch(_()){case`name`:case`before-value`:case`value`:a.trim().length>0&&(p.value=a.trim(),E()),w(`before-name`);break;case`value-paren`:a+=o;break;case`at-value`:p.value=a.trim(),E(),S();break;case`before-name`:break;default:a+=o;break}break;case`{`:switch(_()){case`selector`:if(x(-1)===`\\`){a+=o;break}p.text=a.trim(),E(),w(`before-name`),l+=1;break;case`at-group`:switch(p.name=a.trim(),p.type){case`font-face`:case`viewport`:case`page`:C(`before-name`);break;default:C(`before-selector`)}E(),l+=1;break;case`name`:case`at-rule`:p.name=a.trim(),E(),C(`before-name`),l+=1;break;case`comment`:case`double-string`:case`single-string`:a+=o;break;case`before-value`:w(`value`),a+=o;break}break;case`}`:switch(_()){case`before-name`:case`name`:case`before-value`:case`value`:a&&(p.value=a.trim()),p.name&&p.value&&E(),D(`end`),E(),S(),_()===`at-group`&&(D(`at-group-end`),E(),S()),l>0&&--l;break;case`at-group`:case`before-selector`:case`selector`:if(x(-1)===`\\`){a+=o;break}l>0&&_(1)===`at-group`&&(D(`at-group-end`),E()),l>1&&S(),l>0&&--l;break;case`double-string`:case`single-string`:case`comment`:a+=o;break}break;case`"`:case`'`:switch(_()){case`double-string`:o===`"`&&x(-1)!==`\\`&&S();break;case`single-string`:o===`'`&&x(-1)!==`\\`&&S();break;case`before-at-value`:w(`at-value`),C(o===`"`?`double-string`:`single-string`);break;case`before-value`:w(`value`),C(o===`"`?`double-string`:`single-string`);break;case`comment`:break;default:x(-1)!==`\\`&&C(o===`"`?`double-string`:`single-string`)}a+=o;break;case`/`:switch(_()){case`comment`:case`double-string`:case`single-string`:a+=o;break;case`before-value`:case`selector`:case`name`:case`value`:if(b(`*`)){var O=y(`*/`);O&&T(O+1)}else _()==`before-value`&&w(`value`),a+=o;break;default:b(`*`)?(D(`comment`),C(`comment`),T()):a+=o;break}break;case`*`:switch(_()){case`comment`:b(`/`)?(p.text=a,T(),E(),S()):a+=o;break;case`before-selector`:a+=o,D(`selector`),C(`selector`);break;case`before-value`:w(`value`),a+=o;break;default:a+=o}break;case`@`:switch(_()){case`comment`:case`double-string`:case`single-string`:a+=o;break;case`before-value`:w(`value`),a+=o;break;default:for(var k=!1,A,j,M=0,N=h.length;!k&&M<N;++M)j=h[M],A=j.name||j,v(A)&&(k=!0,D(A),C(j.state||`at-group`),T(A.length),j.prefix&&(p.prefix=j.prefix),j.type&&(p.type=j.type));k||(a+=o);break}break;case`(`:switch(_()){case`value`:C(`value-paren`);break;case`before-value`:w(`value`);break}a+=o;break;case`)`:switch(_()){case`value-paren`:S();break;case`before-value`:w(`value`);break}a+=o;break;default:switch(_()){case`before-selector`:D(`selector`),C(`selector`);break;case`before-name`:D(`property`),w(`name`);break;case`before-value`:w(`value`);break;case`before-at-value`:w(`at-value`);break}a+=o;break}return r&&i(`ran in`,Date.now()-t+`ms`),m}})),F_=r(((e,t)=>{var n=!1,r=!1,i=N_()(`parse`),a=P_();e=t.exports=u;var o,s,c,l;function u(e,t){var n;t||={},o=!!t.comments,c=!!t.position,s=0,l=Array.isArray(e)?e.slice():a(e);var u,d=[],p;for(r&&(n=Date.now());p=f();)u=b(p),u&&d.push(u);return r&&i(`ran in`,Date.now()-n+`ms`),{type:`stylesheet`,stylesheet:{rules:d}}}function d(e,t){t||={};for(var r,a=[`type`,`name`,`value`],o={},s=0;s<a.length;++s)r=a[s],e[r]&&(o[r]=t[r]||e[r]);for(a=Object.keys(t),s=0;s<a.length;++s)r=a[s],o[r]||(o[r]=t[r]);return c&&(o.position={start:e.start,end:e.end}),n&&i(`astNode:`,JSON.stringify(o,null,2)),o}function f(){var e=l.shift();return n&&i(`next:`,JSON.stringify(e,null,2)),e}function p(e){s+=1;var t={};switch(e.type){case`font-face`:case`viewport`:t.declarations=S();break;case`page`:t.prefix=e.prefix,t.declarations=S();break;default:t.prefix=e.prefix,t.rules=C()}return d(e,t)}function m(e){return d(e)}function h(e){return d(e)}function g(e){return d(e,{text:e.text})}function _(e){return d(e)}function v(e){return d(e)}function y(e){function t(e){return e.trim()}return d(e,{type:`rule`,selectors:e.text.split(`,`).map(t),declarations:S(e)})}function b(e){switch(e.type){case`property`:return v(e);case`selector`:return y(e);case`at-group-end`:--s;return;case`media`:case`keyframes`:return p(e);case`comment`:if(o)return g(e);break;case`charset`:return h(e);case`import`:return m(e);case`namespace`:return _(e);case`font-face`:case`supports`:case`viewport`:case`document`:case`page`:return p(e)}n&&i(`parseToken: unexpected token:`,JSON.stringify(e))}function x(e){for(var t,n=[],r;(r=f())&&e&&e(r);)t=b(r),t&&n.push(t);return r&&r.type!==`end`&&l.unshift(r),n}function S(){return x(function(e){return e.type===`property`||e.type===`comment`})}function C(){return x(function(){return s})}})),I_=r(((e,t)=>{var n=!1,r=!1,i=N_()(`stringify`),a,o,s,c,l,u;e=t.exports=d;function d(e,t){var n;t||={},s=t.indentation||``,o=!!t.compress,a=!!t.comments,c=1,o?l=u=``:(l=`
52
+ `&&(p.value=a.trim(),E(),S());break}break;case`:`:switch(_()){case`name`:p.name=a.trim(),a=``,w(`before-value`);break;case`before-selector`:a+=o,D(`selector`),C(`selector`);break;case`before-value`:w(`value`),a+=o;break;default:a+=o;break}break;case`;`:switch(_()){case`name`:case`before-value`:case`value`:a.trim().length>0&&(p.value=a.trim(),E()),w(`before-name`);break;case`value-paren`:a+=o;break;case`at-value`:p.value=a.trim(),E(),S();break;case`before-name`:break;default:a+=o;break}break;case`{`:switch(_()){case`selector`:if(x(-1)===`\\`){a+=o;break}p.text=a.trim(),E(),w(`before-name`),l+=1;break;case`at-group`:switch(p.name=a.trim(),p.type){case`font-face`:case`viewport`:case`page`:C(`before-name`);break;default:C(`before-selector`)}E(),l+=1;break;case`name`:case`at-rule`:p.name=a.trim(),E(),C(`before-name`),l+=1;break;case`comment`:case`double-string`:case`single-string`:a+=o;break;case`before-value`:w(`value`),a+=o;break}break;case`}`:switch(_()){case`before-name`:case`name`:case`before-value`:case`value`:a&&(p.value=a.trim()),p.name&&p.value&&E(),D(`end`),E(),S(),_()===`at-group`&&(D(`at-group-end`),E(),S()),l>0&&--l;break;case`at-group`:case`before-selector`:case`selector`:if(x(-1)===`\\`){a+=o;break}l>0&&_(1)===`at-group`&&(D(`at-group-end`),E()),l>1&&S(),l>0&&--l;break;case`double-string`:case`single-string`:case`comment`:a+=o;break}break;case`"`:case`'`:switch(_()){case`double-string`:o===`"`&&x(-1)!==`\\`&&S();break;case`single-string`:o===`'`&&x(-1)!==`\\`&&S();break;case`before-at-value`:w(`at-value`),C(o===`"`?`double-string`:`single-string`);break;case`before-value`:w(`value`),C(o===`"`?`double-string`:`single-string`);break;case`comment`:break;default:x(-1)!==`\\`&&C(o===`"`?`double-string`:`single-string`)}a+=o;break;case`/`:switch(_()){case`comment`:case`double-string`:case`single-string`:a+=o;break;case`before-value`:case`selector`:case`name`:case`value`:if(b(`*`)){var O=y(`*/`);O&&T(O+1)}else _()==`before-value`&&w(`value`),a+=o;break;default:b(`*`)?(D(`comment`),C(`comment`),T()):a+=o;break}break;case`*`:switch(_()){case`comment`:b(`/`)?(p.text=a,T(),E(),S()):a+=o;break;case`before-selector`:a+=o,D(`selector`),C(`selector`);break;case`before-value`:w(`value`),a+=o;break;default:a+=o}break;case`@`:switch(_()){case`comment`:case`double-string`:case`single-string`:a+=o;break;case`before-value`:w(`value`),a+=o;break;default:for(var k=!1,A,j,M=0,N=h.length;!k&&M<N;++M)j=h[M],A=j.name||j,v(A)&&(k=!0,D(A),C(j.state||`at-group`),T(A.length),j.prefix&&(p.prefix=j.prefix),j.type&&(p.type=j.type));k||(a+=o);break}break;case`(`:switch(_()){case`value`:C(`value-paren`);break;case`before-value`:w(`value`);break}a+=o;break;case`)`:switch(_()){case`value-paren`:S();break;case`before-value`:w(`value`);break}a+=o;break;default:switch(_()){case`before-selector`:D(`selector`),C(`selector`);break;case`before-name`:D(`property`),w(`name`);break;case`before-value`:w(`value`);break;case`before-at-value`:w(`at-value`);break}a+=o;break}return r&&i(`ran in`,Date.now()-t+`ms`),m}})),R_=r(((e,t)=>{var n=!1,r=!1,i=I_()(`parse`),a=L_();e=t.exports=u;var o,s,c,l;function u(e,t){var n;t||={},o=!!t.comments,c=!!t.position,s=0,l=Array.isArray(e)?e.slice():a(e);var u,d=[],p;for(r&&(n=Date.now());p=f();)u=b(p),u&&d.push(u);return r&&i(`ran in`,Date.now()-n+`ms`),{type:`stylesheet`,stylesheet:{rules:d}}}function d(e,t){t||={};for(var r,a=[`type`,`name`,`value`],o={},s=0;s<a.length;++s)r=a[s],e[r]&&(o[r]=t[r]||e[r]);for(a=Object.keys(t),s=0;s<a.length;++s)r=a[s],o[r]||(o[r]=t[r]);return c&&(o.position={start:e.start,end:e.end}),n&&i(`astNode:`,JSON.stringify(o,null,2)),o}function f(){var e=l.shift();return n&&i(`next:`,JSON.stringify(e,null,2)),e}function p(e){s+=1;var t={};switch(e.type){case`font-face`:case`viewport`:t.declarations=S();break;case`page`:t.prefix=e.prefix,t.declarations=S();break;default:t.prefix=e.prefix,t.rules=C()}return d(e,t)}function m(e){return d(e)}function h(e){return d(e)}function g(e){return d(e,{text:e.text})}function _(e){return d(e)}function v(e){return d(e)}function y(e){function t(e){return e.trim()}return d(e,{type:`rule`,selectors:e.text.split(`,`).map(t),declarations:S(e)})}function b(e){switch(e.type){case`property`:return v(e);case`selector`:return y(e);case`at-group-end`:--s;return;case`media`:case`keyframes`:return p(e);case`comment`:if(o)return g(e);break;case`charset`:return h(e);case`import`:return m(e);case`namespace`:return _(e);case`font-face`:case`supports`:case`viewport`:case`document`:case`page`:return p(e)}n&&i(`parseToken: unexpected token:`,JSON.stringify(e))}function x(e){for(var t,n=[],r;(r=f())&&e&&e(r);)t=b(r),t&&n.push(t);return r&&r.type!==`end`&&l.unshift(r),n}function S(){return x(function(e){return e.type===`property`||e.type===`comment`})}function C(){return x(function(){return s})}})),z_=r(((e,t)=>{var n=!1,r=!1,i=I_()(`stringify`),a,o,s,c,l,u;e=t.exports=d;function d(e,t){var n;t||={},s=t.indentation||``,o=!!t.compress,a=!!t.comments,c=1,o?l=u=``:(l=`
53
53
  `,u=` `),r&&(n=Date.now());var d=_(e.stylesheet.rules,x).join(`
54
- `).trim();return r&&i(`ran in`,Date.now()-n+`ms`),d}function f(e){if(e){c+=e;return}return o?``:Array(c).join(s||``)}function p(e){return`@`+e.type+` `+e.value+`;`+l}function m(e){var t=``,n=e.prefix||``;e.name&&(t=` `+e.name);var r=e.type!==`page`;return`@`+n+e.type+t+u+v(e,r)+l}function h(e){return a?`/*`+(e.text||``)+`*/`+l:``}function g(e){var t;return e.selectors?t=e.selectors.join(`,`+l):(t=`@`+e.type,t+=e.name?` `+e.name:``),f()+t+u+v(e)+l}function _(e,t){return e.reduce(function(e,n){var r=n.type===`comment`?h(n):t(n);return r&&e.push(r),e},[])}function v(e,t){var n=e.declarations,r=b;return e.rules&&(n=e.rules,r=g),n=y(n,r),n&&=l+n+(t?``:l),`{`+n+f()+`}`}function y(e,t){if(!e)return``;f(1);var n=_(e,t);return f(-1),n.length?n.join(l):``}function b(e){if(e.type===`property`)return S(e);n&&i(`stringifyDeclaration: unexpected node:`,JSON.stringify(e))}function x(e){switch(e.type){case`rule`:return g(e);case`media`:case`keyframes`:return m(e);case`comment`:return h(e);case`import`:case`charset`:case`namespace`:return p(e);case`font-face`:case`supports`:case`viewport`:case`document`:case`page`:return m(e)}n&&i(`stringifyNode: unexpected node: `+JSON.stringify(e))}function S(e){var t=e.name?e.name+`:`+u:``;return f()+t+e.value+`;`}})),L_=e(r(((e,t)=>{t.exports={lex:P_(),parse:F_(),stringify:I_()}}))(),1);function R_(e){for(;e.parentNode;){if(e.nodeName===`defs`)return!0;e=e.parentNode}return!1}function z_(e){let t={};return e.querySelectorAll(`style`).forEach(e=>{let n=L_.default.parse(e.textContent).stylesheet.rules;for(let e of n)e.selectors&&e.selectors.forEach(n=>{let r=t[n]||{};e.declarations.forEach(e=>{r[e.name]=e.value}),t[n]=r})}),t}function B_(e,t){let n={fill:``,stroke:``},r=e.getAttribute(`class`)?.split(` `)||[],i=e.getAttribute(`id`),a={};i&&t[`#${i}`]?a=t[`#${i}`]:r.forEach(e=>{t[`.${e}`]&&(a=Object.assign(Object.assign({},a),t[`.${e}`]))}),t[e.nodeName]&&(a=Object.assign(Object.assign({},a),t[e.nodeName]));let o=e.getAttribute(`fill`);o&&o!==`none`?n.fill=o:a.fill&&a.fill!==`none`&&(n.fill=a.fill);let s=e.getAttribute(`stroke`);if(s&&s!==`none`?n.stroke=s:a.stroke&&a.stroke!==`none`&&(n.stroke=a.stroke),!n.fill&&e.style.fill&&e.style.fill!==`none`&&(n.fill=e.style.fill),!n.stroke&&e.style.stroke&&e.style.stroke!==`none`&&(n.stroke=e.style.stroke),!n.stroke&&!n.fill){let r=e.ownerSVGElement,i=r&&r!==e?B_(r,t):null;i?.fill===`currentColor`||i?.stroke===`currentColor`||(n.fill=`black`)}return n}var V_=[`path`,`rect`,`circle`,`line`,`polygon`,`polyline`,`ellipse`,`text`];function H_(e){for(var t=[],n=e.getElementsByTagName(`*`),r=0,i=n.length;r<i;r++){let e=n[r];R_(e)||(e.getAttribute(`fill`)!==null&&t.push(e),(e.getAttribute(`stroke`)!==null||e.style&&e.style.fill||V_.indexOf(e.nodeName)>=0)&&t.push(e))}return t}async function U_(e){return G_(await(await fetch(e)).text())}async function W_(e){return await(await fetch(e,{mode:`cors`})).text()}function G_(e){return`data:image/svg+xml;base64,`+window.btoa(unescape(encodeURIComponent(e)))}function K_(e){var t=new DOMParser().parseFromString(e,`image/svg+xml`);let[n,r,i,a]=t.documentElement.getAttribute(`viewBox`)?.split(` `)||[],o=t.documentElement.getAttribute(`width`);!o&&t.documentElement.setAttribute(`width`,i+`px`);let s=t.documentElement.getAttribute(`height`);if((!s||s.indexOf(`%`)>=0)&&t.documentElement.setAttribute(`height`,a+`px`),o&&o.indexOf(`%`)>=0&&s&&s.indexOf(`%`)===-1){let e=parseFloat(s)/parseFloat(a);t.documentElement.setAttribute(`width`,e*parseFloat(i)+`px`)}if(s&&s.indexOf(`%`)>=0&&o&&o.indexOf(`%`)===-1){let e=parseFloat(o)/parseFloat(i);t.documentElement.setAttribute(`height`,e*parseFloat(a)+`px`)}return o===`100%`&&s===`100%`&&(t.documentElement.setAttribute(`width`,i+`px`),t.documentElement.setAttribute(`height`,a+`px`)),new XMLSerializer().serializeToString(t)}var q_=(e,t)=>{if(!e||!t)return!1;if(t===`currentColor`&&e===`black`)return!0;let n=Du.Util.colorToRGBA(e),r=Du.Util.colorToRGBA(t);return n&&r?n.r===r.r&&n.g===r.g&&n.b===r.b&&n.a===r.a:void 0};function J_(e,t){var n=new DOMParser().parseFromString(e,`image/svg+xml`);let r=H_(n),i=Array.from(t.keys()),a=z_(n);return r.forEach(e=>{let{fill:r,stroke:o}=B_(e,a);[{prop:`fill`,color:r},{prop:`stroke`,color:o}].forEach(({prop:r,color:a})=>{let o=i.find(e=>q_(e,a));if(o){let i=t.get(o);if(jf(i)){let{rotation:t,stops:a}=Nf(i),o=a.map(e=>({offset:100*e.offset+`%`,"stop-color":e.color})),s=`color`+Math.round(1e8*Math.random());(function(e,t,n,r){var i=e.namespaceURI,a=document.createElementNS(i,`linearGradient`);let o=Du.Util.degToRad(n+90),s=(Math.cos(o)+1)/2,c=(Math.sin(o)+1)/2,l=(Math.cos(o+Math.PI)+1)/2,u=(Math.sin(o+Math.PI)+1)/2;a.setAttribute(`x1`,100*s+`%`),a.setAttribute(`y1`,100*c+`%`),a.setAttribute(`x2`,100*l+`%`),a.setAttribute(`y2`,100*u+`%`),a.setAttribute(`gradientUnits`,`userSpaceOnUse`),a.setAttribute(`id`,t);for(var d=0;d<r.length;d++){var f=r[d],p=document.createElementNS(i,`stop`);for(var m in f)f.hasOwnProperty(m)&&p.setAttribute(m,f[m]);a.appendChild(p)}(e.querySelector(`defs`)||e.insertBefore(document.createElementNS(i,`defs`),e.firstChild)).appendChild(a)})(n.children[0],s,t,o),e.style[r]=null,e.setAttribute(r,`url('#${s}')`)}else e.style[r]=t.get(o)}})}),G_(new XMLSerializer().serializeToString(n))}var Y_=(e,t,n)=>{let r=t,i=n,a=1;for(;r>0&&i>0;){if(e.width=r,e.height=i,r+i<4e3)return;let o=e.getContext(`2d`);if(!o)return;if(o.fillStyle=`rgba(0,0,0,0.1)`,o.fillRect(0,0,1,1),o.getImageData(0,0,1,1).data[3]!==0){o.clearRect(0,0,e.width,e.height);return}if(a*=.9,r=Math.floor(t*a),i=Math.floor(n*a),r=Math.max(r,1),i=Math.max(i,1),r<=1&&i<=1){e.width=1,e.height=1;return}}};function X_(e,t){let n=t.x??0,r=t.y??0,i=t.pixelRatio||1,a=Math.round(t.width*i),o=Math.round(t.height*i),s=a/i,c=o/i,l=t.sceneCanvas;l?(l.width!==a||l.height!==o||l.pixelRatio!==i)&&(l.setSize(s,c),l.setPixelRatio(i)):l=new to({width:s,height:c,pixelRatio:i});let u=l.getContext(),d=l.width/l.pixelRatio+Math.abs(n),f=l.height/l.pixelRatio+Math.abs(r),p=t.bufferCanvas;if(p){let e=Math.round(d*l.pixelRatio),t=Math.round(f*l.pixelRatio);(p.width!==e||p.height!==t||p.pixelRatio!==l.pixelRatio)&&(p.setSize(d,f),p.setPixelRatio(l.pixelRatio))}else p=new to({width:d,height:f,pixelRatio:l.pixelRatio});return!1===t.imageSmoothingEnabled&&(u._context.imageSmoothingEnabled=!1),u.save(),(n||r)&&u.translate(-1*n,-1*r),e.drawScene(l,void 0,p),u.restore(),l}function Z_(){return{sceneCanvas:new to({width:1,height:1,pixelRatio:1}),bufferCanvas:new to({width:1,height:1,pixelRatio:1})}}var Q_=(e,t=100,n=!1,r)=>{let i=d.useRef(r??e),[,a]=d.useReducer(e=>e+1,0),o=d.useCallback(e=>{i.current!==e&&(i.current=e,a())},[i]),s=d.useRef(null);return e===n&&(s.current&&=(clearTimeout(s.current),null),i.current=n),d.useEffect(()=>(s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{o(e),s.current=null},t),()=>{s.current&&clearTimeout(s.current)}),[e,t,n]),[i.current,o]};function $_(){return document.createElement(`canvas`)}var ev=e=>e.indexOf(`data:image/svg+xml`)>=0||e.indexOf(`.svg`)>=0,tv=e=>{let[t,n]=d.useState(e);return d.useEffect(()=>{(async()=>{let r=await async function(e){return ev(e)?G_(K_(await W_(e))):e}(e);r!==t&&n(r)})()},[e]),t};function nv(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}var rv={boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`],keepRatio:!1,rotateEnabled:!1,anchorFill:`rgb(240, 240, 240)`,anchorStrokeWidth:2,borderStrokeWidth:2},iv={boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,anchorSize:20,enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`],rotateEnabled:!1,borderEnabled:!1,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2},av=(e,t,n)=>Math.max(t,Math.min(n,e)),ov=(e,t,n,r,i=0,a=!1,o=!0)=>{let s=Math.floor(av(e.a.width*r,1,1e4)),c=Math.floor(av(e.a.height*r,1,1e4)),l=Math.min(i*r,s/2,c/2),u=Math.max(e.a.width/n.width,e.a.height/n.height)*r,f=e.page._exportingOrRendering&&yp.imageDownScalingEnabled&&u<1&&!a,p=n.x===0&&n.y===0&&n.width===t?.width&&n.height===t?.height,m=d.useMemo(()=>{if(t&&t.width&&t.height)return p&&l===0&&!f?void 0:$_()},[t,l,f,p]);return d.useLayoutEffect(()=>{if(!m||!t)return;Y_(m,s,c);let e=m.getContext(`2d`);if(!e)return;l&&(e.beginPath(),e.moveTo(l,0),e.lineTo(s-l,0),e.arc(s-l,l,l,3*Math.PI/2,0,!1),e.lineTo(s,c-l),e.arc(s-l,c-l,l,0,Math.PI/2,!1),e.lineTo(l,c),e.arc(l,c-l,l,Math.PI/2,Math.PI,!1),e.lineTo(0,l),e.arc(l,l,l,Math.PI,3*Math.PI/2,!1),e.clip());let r=f?function(e,t){var n,r;let i=$_();i.width=e.width,i.height=e.height;let a=Math.max(1,Math.floor(i.width*t)),o=Math.max(1,Math.floor(i.height*t));(n=i.getContext(`2d`))==null||n.drawImage(e,0,0,i.width,i.height);let s=function(e,t,n,r,i,a,o){for(var s=new ImageData(t,n),c=new Int32Array(e.data.buffer),l=e.width,u=new Int32Array(s.data.buffer),d=s.width,f=t/a,p=n/o,m=Math.round(1/f),h=Math.round(1/p),g=m*h,_=0;_<s.height;_++)for(var v=0;v<d;v++){for(var y=0+Math.round(v/f)+(0+Math.round(_/p))*l,b=0,x=0,S=0,C=0,w=0;w<h;w++)for(var T=0;T<m;T++){var E=c[y+T+w*l];b+=E<<24>>>24,x+=E<<16>>>24,S+=E<<8>>>24,C+=E>>>24}b=Math.round(b/g),x=Math.round(x/g),S=Math.round(S/g),C=Math.round(C/g),u[v+_*d]=C<<24|S<<16|x<<8|b}return s}(i.getContext(`2d`).getImageData(0,0,i.width,i.height),a,o,0,0,i.width,i.height);return i.width=a,i.height=o,(r=i.getContext(`2d`))==null||r.putImageData(s,0,0),i}(t,u):t,i=f?{x:Math.floor(n.x*u),y:Math.floor(n.y*u),width:Math.floor(n.width*u),height:Math.floor(n.height*u)}:n;e.drawImage(r,i.x,i.y,i.width,i.height,0,0,m.width,m.height)},[m,e.a.width,e.a.height,n.x,n.y,n.width,n.height,i,r,a,e.page._exportingOrRendering,f]),d.useEffect(()=>()=>{m&&m.nodeName===`CANVAS`&&Du.Util.releaseCanvas(m)},[m]),m||t},sv=$_(),cv=sa(({element:e})=>{let t=Math.min(30,e.a.width/4,e.a.height/4),n=d.useRef(null);return d.useEffect(()=>{let e=n.current;if(!e)return;let t=new Du.Animation(t=>{e.rotate((t?.timeDiff||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}}),d.createElement(Kd,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},d.createElement(Jd,{width:e.a.width,height:e.a.height,fill:`rgba(124, 173, 212, 0.8)`}),d.createElement(`Arc`,{ref:n,x:e.a.width/2,y:e.a.height/2,fill:`white`,outerRadius:Math.abs(t),innerRadius:Math.max(1,t-5),angle:270}))}),lv=sa(({element:e})=>{let t=Math.max(10,Math.min(30,e.a.width/25));return d.createElement(Kd,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},d.createElement(Jd,{width:e.a.width,height:e.a.height,fill:`rgba(223, 102, 102, 0.8)`}),d.createElement(Zd,{text:`Can not load the image...`,fontSize:t,width:e.a.width,height:e.a.height,align:`center`,fill:`white`,verticalAlign:`middle`,padding:5}))}),uv=rf.default,dv=(e,t=``,n=``)=>{let r=d.useRef(),i=()=>{var e;(e=r.current)==null||e.call(r),r.current=void 0};d.useEffect(()=>i,[]),d.useLayoutEffect(()=>{let a=`image with id ${n} url: ${t.slice(0,200)}`;e!==`loading`||r.current||(r.current=Kf(a)),e!==`loading`&&i(),e===`failed`&&Zf(a)},[e])},fv=sa(({element:e,store:t})=>{let[n,r]=d.useState(!1),i=d.useRef(null),a=d.useRef(null),o=t.selectedShapes.indexOf(e)>=0&&e.selectable,[s,c]=(e=>{let[t,n]=d.useReducer(e=>e+1,0),r=d.useRef(`loading`),i=d.useRef(e.src),a=d.useRef(e.src);a.current!==e.src&&(a.current=e.src,r.current=`loading`);let o=d.useMemo(()=>ev(e.src)||e.type===`svg`,[e.src,e.type]);return d.useEffect(()=>{if(!o||!e.src)return;let t=!1;return(async()=>{r.current=`loading`,n();let a=K_(await W_(e.src)),o;o=e.colorsReplace?J_(a,e.colorsReplace||new Map):G_(a),t||(i.current=o,r.current=`loaded`,n())})(),()=>{t=!0}},[e.src,JSON.stringify(e.colorsReplace)]),o?[i.current,r.current]:[e.src,`loaded`]})(e),[l,u]=uv(s,`anonymous`);dv(e.type!==`svg`||c===`loaded`?u:`loading`,e.src,e.id);let f=e.page._exportingOrRendering?1:Math.max(1,t.scale),p=t._elementsPixelRatio*f,m=(({image:e,status:t,type:n})=>{let r=d.useRef();return d.useEffect(()=>{r.current=e||r.current},[e]),t!==`failed`||t!==`failed`&&n===`svg`?r.current:void 0})({image:l,status:u,type:e.type}),h=((e,t)=>{let n=tv(e.maskSrc||``),[r,i]=uv(n,`anonymous`);return dv(n?i:`loaded`,n||``,e.id),d.useMemo(()=>{if(!r||!t||!t.width||!t.height)return t;let n=$_();n.width=Math.max(t.width,1),n.height=Math.max(t.height,1);let i=n.getContext(`2d`);if(!i)return t;i.drawImage(t,0,0),i.globalCompositeOperation=`source-in`;let a=function(e,t){let n=t.width/t.height,r,i;return n>=e.width/e.height?(r=e.width,i=e.width/n):(r=e.height*n,i=e.height),{x:(e.width-r)/2,y:(e.height-i)/2,width:r,height:i}}(r,e);return i.drawImage(r,a.x,a.y,a.width,a.height,0,0,t.width,t.height),n},[t,r,e.a.width,e.a.height])})(e,((e,t,n)=>{let r=d.useMemo(()=>{var r,i;let{flipX:a,flipY:o}=e,s=e.type===`svg`||e.src.indexOf(`data:image/svg+xml`)>=0||e.src.indexOf(`.svg`)>=0,c=navigator.userAgent.toLowerCase().indexOf(`firefox`)>-1,l=(/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||c)&&s||e.maskSrc;if(!a&&!o&&!l)return t;if(!t||!t.width||!t.height)return null;let u=$_(),d=1;e.type===`svg`&&(d=Math.max(e.a.width/t.width*n,e.a.height/t.height*n)),Y_(u,Math.max(t.width*d,1),Math.max(t.height*d,1));let f=a?-u.width:0,p=o?-u.height:0;return(r=u.getContext(`2d`))==null||r.scale(a?-1:1,o?-1:1),(i=u.getContext(`2d`))==null||i.drawImage(t,f,p,u.width,u.height),u},[e.maskSrc,e.flipX,e.flipY,t,e.a.width,e.a.height,n]);return d.useEffect(()=>()=>{r&&r.nodeName===`CANVAS`&&Du.Util.releaseCanvas(r)},[r]),r})(e,l||m,p))||sv,{cropX:g,cropY:_,cropWidth:v,cropHeight:y}=e.a;u!==`loaded`&&(g=_=0,v=y=1);let b=h.width*v,x=h.height*y,S=e.a.width/e.a.height,C,w,T=b/x,E=e.stretchEnabled;E?(C=b,w=x):S>=T?(C=b,w=b/S):(C=x*S,w=x);let D={x:h.width*g,y:h.height*_,width:C,height:w},O=e.cornerRadius??0,k=e.page._exportingOrRendering?1:Math.min(2,t.scale),A=t._elementsPixelRatio*k,j=((e,t,n,r)=>{let[i,a]=uv(tv(e.clipSrc||``),`anonymous`);dv(e.clipSrc?a:`loaded`,e.clipSrc,e.id);let o=d.useMemo(()=>{if(t&&i)return $_()},[t,i]);return d.useLayoutEffect(()=>{var r;if(!i||!t||!t.width||!t.height||!i||!i.width||!i.height||!o)return;let a=$_(),s=Math.max(e.a.width/i.width*n,e.a.height/i.height*n);a.width=Math.max(i.width*s,1),a.height=Math.max(i.height*s,1),(r=a.getContext(`2d`))==null||r.drawImage(i,0,0,a.width,a.height),o.width=Math.max(t.width,1),o.height=Math.max(t.height,1);let c=o.getContext(`2d`);c&&(c.save(),c.drawImage(a,0,0,t.width,t.height),Du.Util.releaseCanvas(a),c.globalCompositeOperation=`source-in`,c.drawImage(t,0,0,o.width,o.height),c.restore())},[o,t,i,e.a.width,e.a.height,n,...r]),e.clipSrc&&i?o:t})(e,ov(e,h,D,A,O,n||e._cropModeEnabled||e.type===`svg`,!0),A,[D,O,A]),M=Math.max(e.a.width/C,e.a.height/w);d.useEffect(()=>{if(!e._cropModeEnabled)return;let t=i.current?.getStage();function n(t){e._cropModeEnabled&&t.target!==a.current&&e.toggleCropMode(!1)}function r(n){e._cropModeEnabled&&n.target.parentNode!==t?.content&&e.toggleCropMode(!1)}return document.body.addEventListener(`click`,r),t?.on(`click`,n),t?.on(`tap`,n),()=>{document.body.removeEventListener(`click`,r),document.body.removeEventListener(`touchstart`,r),t?.off(`click`,n),t?.off(`click`,n)}},[e._cropModeEnabled]),d.useLayoutEffect(()=>{if(!n&&!e._cropModeEnabled)return zp(i.current,e),Gn(()=>{zp(i.current,e)},{delay:100})},[j,e.page._exportingOrRendering,n,v,y,e._cropModeEnabled]),d.useLayoutEffect(()=>{var t;n||e._cropModeEnabled?(t=i.current)==null||t.clearCache():zp(i.current,e)},[n,e.a.width,e.a.height,e._cropModeEnabled]),d.useEffect(()=>{zp(i.current,e)},[e.shadowEnabled,e.shadowBlur,e.cornerRadius,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);let N=d.useRef(null),P=d.useRef(null),F=d.useRef(null);d.useLayoutEffect(()=>{e._cropModeEnabled&&(P.current.nodes([N.current]),F.current.nodes([a.current]))},[e._cropModeEnabled]);var ee=d.useRef(null),te=d.useRef(0),ne=d.useRef(!1);let re=t=>{t.evt.touches?.length>2&&t.target.stopDrag(),Math.round(t.target.x())>0&&(t.target.x(0),t.target.scaleX(1)),Math.round(t.target.y())>0&&(t.target.y(0),t.target.scaleY(1));let n=t.target.width()*t.target.scaleX(),r=t.target.height()*t.target.scaleY(),i=Math.min(1,C/n),a=Math.min(1,w/r),o=1-i,s=Math.min(o,Math.max(0,Math.round(-t.target.x())/n)),c=1-a,l=Math.min(c,Math.max(0,Math.round(-t.target.y())/r));t.target.setAttrs({x:-s*h.width,y:-l*h.height,scaleX:1,scaleY:1}),e.set({cropX:s,cropY:l,cropWidth:i,cropHeight:a})},ie=()=>{e.type!==`svg`&&e.contentEditable&&(e.stretchEnabled||setTimeout(()=>{e.toggleCropMode(!0)}))},I=e.type===`svg`&&m,[ae]=Q_(u===`loading`&&!I,100,!1,!1),oe=u===`failed`,se=!ae&&!oe,ce=d.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),le=se?e.a.opacity:0;Rf(i,le);let ue=e.selectable||t.role===`admin`,de=Bp(),fe=Pf(e,e.borderColor,`stroke`);return d.createElement(d.Fragment,null,ae&&d.createElement(cv,{element:e}),oe&&d.createElement(lv,{element:e}),d.createElement(Xd,{ref:i,name:`element`,id:e.id,image:j,x:e.a.x,y:e.a.y,width:e.a.width||1,height:e.a.height||1,rotation:e.a.rotation,opacity:le,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,customCrop:D,listening:ue,draggable:de?e.draggable&&o:e.draggable,preventDefault:!de||o,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDblClick:ie,onDblTap:ie,onTransformStart:()=>{r(!0),ce.current={cropX:e.cropX,cropY:e.cropY,cropWidth:e.cropWidth,cropHeight:e.cropHeight}},onTransform:t=>{let n=t.currentTarget,r=Math.abs(n.scaleX()-1)<1e-7?1:n.scaleX(),i=Math.abs(n.scaleY()-1)<1e-7?1:n.scaleY();n.scaleX(1),n.scaleY(1);let a=t.target.getStage()?.findOne(`Transformer`),o=1-C/h.width,s=Math.min(o,Math.max(0,e.cropX)),c=1-w/h.height,l=Math.min(c,Math.max(0,e.cropY)),u=a.getActiveAnchor(),d=!(u.indexOf(`middle`)>=0||u.indexOf(`center`)>=0),f=!d&&r<1&&ce.current.cropHeight>w/h.height,p=d?e.cropWidth:e.cropWidth*r;f&&(p=e.cropWidth);let m=!d&&i<1&&ce.current.cropWidth>C/h.width,g=d?e.cropHeight:e.cropHeight*i;m&&(g=e.cropHeight),E&&(p=e.cropWidth,g=e.cropHeight),e.set({cropX:s,cropY:l,x:n.x(),y:n.y(),width:n.width()*r,height:n.height()*i,rotation:t.target.rotation(),cropWidth:Math.min(p,1-s),cropHeight:Math.min(g,1-l)})},onTransformEnd:t=>{let n=t.currentTarget;e.set({width:n.width(),height:n.height(),x:n.x(),y:n.y(),rotation:t.target.rotation(),cropWidth:C/h.width,cropHeight:w/h.height}),r(!1)}}),d.createElement(Jd,Object.assign({x:e.x,y:e.y,width:Math.max(e.a.width-e.borderSize,0),height:Math.max(e.a.height-e.borderSize,0),opacity:le,offsetX:-e.borderSize/2,offsetY:-e.borderSize/2},fe,{strokeWidth:e.borderSize,listening:!1,visible:!!e.borderSize,rotation:e.rotation,cornerRadius:Math.max(0,O-e.borderSize),hideInExport:!e.showInExport})),e._cropModeEnabled&&d.createElement(lf,{selector:`.page-abs-container`,enabled:!0},d.createElement(`Rect`,{x:-window.innerWidth/t.scale,y:-window.innerWidth/t.scale,width:window.innerWidth/t.scale*3,height:window.innerWidth/t.scale*3,fill:`rgba(0,0,0,0.3)`}),d.createElement(`Image`,{listening:!1,image:j,x:e.x,y:e.y,width:e.a.width,height:e.a.height,rotation:e.rotation,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur}),d.createElement(`Group`,{x:e.x,y:e.y,rotation:e.rotation,scaleX:M,scaleY:M},d.createElement(`Image`,{image:h,ref:a,opacity:.4,draggable:!0,x:-e.cropX*h.width,y:-e.cropY*h.height,onDragMove:re,onTransform:re,onTouchMove:e=>{e.evt.preventDefault();let t=e.target.getStage().getPointersPositions();var n=t[0],r=t[1];let i=e.target;if(n&&!r&&!i.isDragging()&&ne.current&&(i.startDrag(),ne.current=!1),n&&r){Du.hitOnDragEnabled=!0,i.isDragging()&&(ne.current=!0,i.stopDrag());let t=e.target.getAbsoluteTransform().copy();t.invert();var a={x:n.x,y:n.y},o={x:r.x,y:r.y};if(!ee.current){ee.current=nv(a,o);return}var s=nv(a,o),c=function(e,t){return Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2)}(a,o);te.current||=c;let m=i.position();var l={x:s.x-m.x,y:s.y-m.y},u=c/te.current;i.scaleX(u),i.scaleY(u);let h=t.point(s),g=t.point(ee.current);var d=h.x-g.x,f=h.y-g.y,p={x:Math.min(0,s.x-l.x*u+d),y:Math.min(0,s.y-l.y*u+f)};i.position(p),te.current=c,ee.current=s,re(e)}},onTouchEnd:e=>{te.current=0,ee.current=null,Du.hitOnDragEnabled=!1}}),d.createElement(`Transformer`,Object.assign({ref:F},iv)),d.createElement(`Rect`,{width:C,height:w,ref:N,listening:!1,onTransform:t=>{if(e.cropX<Math.abs(t.target.x()/h.width)&&t.target.x()<0&&e.cropX>0){let n=(e.cropWidth+e.cropX)*h.width;t.target.scaleX(1),t.target.width(n)}if(e.cropY<Math.abs(t.target.y()/h.height)&&t.target.y()<0&&e.cropY>0){let n=(e.cropHeight+e.cropY)*h.height;t.target.scaleY(1),t.target.height(n)}t.target.x()<-e.cropX*h.width-1e-9&&(t.target.x(-e.cropX*h.width),t.target.scaleX(1)),t.target.y()<-e.cropY*h.height-1e-9&&(t.target.y(-e.cropY*h.height),t.target.scaleY(1));let n=Math.min(1,Math.max(0,e.cropX+t.target.x()/h.width)),r=Math.min(1,Math.max(0,t.target.y()/h.height+e.cropY)),i=t.target.width()*t.target.scaleX(),a=t.target.height()*t.target.scaleY(),o=Math.min(1-n,i/h.width),s=Math.min(1-r,a/h.height),c=t.target.getAbsolutePosition(t.target.getParent().getParent());t.target.scale({x:1,y:1}),t.target.position({x:0,y:0}),e.set({x:c.x,y:c.y,cropX:n,cropY:r,cropWidth:o,cropHeight:s,width:Math.min(i*M,h.width*(1-n)*M),height:Math.min(a*M,h.height*(1-r)*M)})}}),d.createElement(`Transformer`,Object.assign({ref:P},rv,{visible:e.resizable})))))}),pv=r(((e,t)=>{(function(n,r){typeof e==`object`&&typeof t==`object`?t.exports=r():typeof define==`function`&&define.amd?define([],r):typeof e==`object`?e.Quill=r():n.Quill=r()})(typeof self<`u`?self:e,function(){return(function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,`a`,t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=``,n(n.s=109)})([(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=n(17),i=n(18),a=n(19),o=n(45),s=n(46),c=n(47),l=n(48),u=n(49),d=n(12),f=n(32),p=n(33),m=n(31),h=n(1);t.default={Scope:h.Scope,create:h.create,find:h.find,query:h.query,register:h.register,Container:r.default,Format:i.default,Leaf:a.default,Embed:l.default,Scroll:o.default,Block:c.default,Inline:s.default,Text:u.default,Attributor:{Attribute:d.default,Class:f.default,Style:p.default,Store:m.default}}}),(function(e,t,n){var r=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}})();Object.defineProperty(t,`__esModule`,{value:!0});var i=function(e){r(t,e);function t(t){var n=this;return t=`[Parchment] `+t,n=e.call(this,t)||this,n.message=t,n.name=n.constructor.name,n}return t}(Error);t.ParchmentError=i;var a={},o={},s={},c={};t.DATA_KEY=`__blot`;var l;(function(e){e[e.TYPE=3]=`TYPE`,e[e.LEVEL=12]=`LEVEL`,e[e.ATTRIBUTE=13]=`ATTRIBUTE`,e[e.BLOT=14]=`BLOT`,e[e.INLINE=7]=`INLINE`,e[e.BLOCK=11]=`BLOCK`,e[e.BLOCK_BLOT=10]=`BLOCK_BLOT`,e[e.INLINE_BLOT=6]=`INLINE_BLOT`,e[e.BLOCK_ATTRIBUTE=9]=`BLOCK_ATTRIBUTE`,e[e.INLINE_ATTRIBUTE=5]=`INLINE_ATTRIBUTE`,e[e.ANY=15]=`ANY`})(l=t.Scope||={});function u(e,t){var n=f(e);if(n==null)throw new i(`Unable to create `+e+` blot`);var r=n;return new r(e instanceof Node||e.nodeType===Node.TEXT_NODE?e:r.create(t),t)}t.create=u;function d(e,n){return n===void 0&&(n=!1),e==null?null:e[t.DATA_KEY]==null?n?d(e.parentNode,n):null:e[t.DATA_KEY].blot}t.find=d;function f(e,t){t===void 0&&(t=l.ANY);var n;if(typeof e==`string`)n=c[e]||a[e];else if(e instanceof Text||e.nodeType===Node.TEXT_NODE)n=c.text;else if(typeof e==`number`)e&l.LEVEL&l.BLOCK?n=c.block:e&l.LEVEL&l.INLINE&&(n=c.inline);else if(e instanceof HTMLElement){var r=(e.getAttribute(`class`)||``).split(/\s+/);for(var i in r)if(n=o[r[i]],n)break;n||=s[e.tagName]}return n==null?null:t&l.LEVEL&n.scope&&t&l.TYPE&n.scope?n:null}t.query=f;function p(){var e=[...arguments];if(e.length>1)return e.map(function(e){return p(e)});var t=e[0];if(typeof t.blotName!=`string`&&typeof t.attrName!=`string`)throw new i(`Invalid definition`);if(t.blotName===`abstract`)throw new i(`Cannot register abstract class`);return c[t.blotName||t.attrName]=t,typeof t.keyName==`string`?a[t.keyName]=t:(t.className!=null&&(o[t.className]=t),t.tagName!=null&&(Array.isArray(t.tagName)?t.tagName=t.tagName.map(function(e){return e.toUpperCase()}):t.tagName=t.tagName.toUpperCase(),(Array.isArray(t.tagName)?t.tagName:[t.tagName]).forEach(function(e){(s[e]==null||t.className==null)&&(s[e]=t)}))),t}t.register=p}),(function(e,t,n){var r=n(51),i=n(11),a=n(3),o=n(20),s=`\0`,c=function(e){Array.isArray(e)?this.ops=e:e!=null&&Array.isArray(e.ops)?this.ops=e.ops:this.ops=[]};c.prototype.insert=function(e,t){var n={};return e.length===0?this:(n.insert=e,typeof t==`object`&&t&&Object.keys(t).length>0&&(n.attributes=t),this.push(n))},c.prototype.delete=function(e){return e<=0?this:this.push({delete:e})},c.prototype.retain=function(e,t){if(e<=0)return this;var n={retain:e};return typeof t==`object`&&t&&Object.keys(t).length>0&&(n.attributes=t),this.push(n)},c.prototype.push=function(e){var t=this.ops.length,n=this.ops[t-1];if(e=a(!0,{},e),typeof n==`object`){if(typeof e.delete==`number`&&typeof n.delete==`number`)return this.ops[t-1]={delete:n.delete+e.delete},this;if(typeof n.delete==`number`&&e.insert!=null&&(--t,n=this.ops[t-1],typeof n!=`object`))return this.ops.unshift(e),this;if(i(e.attributes,n.attributes)){if(typeof e.insert==`string`&&typeof n.insert==`string`)return this.ops[t-1]={insert:n.insert+e.insert},typeof e.attributes==`object`&&(this.ops[t-1].attributes=e.attributes),this;if(typeof e.retain==`number`&&typeof n.retain==`number`)return this.ops[t-1]={retain:n.retain+e.retain},typeof e.attributes==`object`&&(this.ops[t-1].attributes=e.attributes),this}}return t===this.ops.length?this.ops.push(e):this.ops.splice(t,0,e),this},c.prototype.chop=function(){var e=this.ops[this.ops.length-1];return e&&e.retain&&!e.attributes&&this.ops.pop(),this},c.prototype.filter=function(e){return this.ops.filter(e)},c.prototype.forEach=function(e){this.ops.forEach(e)},c.prototype.map=function(e){return this.ops.map(e)},c.prototype.partition=function(e){var t=[],n=[];return this.forEach(function(r){(e(r)?t:n).push(r)}),[t,n]},c.prototype.reduce=function(e,t){return this.ops.reduce(e,t)},c.prototype.changeLength=function(){return this.reduce(function(e,t){return t.insert?e+o.length(t):t.delete?e-t.delete:e},0)},c.prototype.length=function(){return this.reduce(function(e,t){return e+o.length(t)},0)},c.prototype.slice=function(e,t){e||=0,typeof t!=`number`&&(t=1/0);for(var n=[],r=o.iterator(this.ops),i=0;i<t&&r.hasNext();){var a;i<e?a=r.next(e-i):(a=r.next(t-i),n.push(a)),i+=o.length(a)}return new c(n)},c.prototype.compose=function(e){var t=o.iterator(this.ops),n=o.iterator(e.ops),r=[],a=n.peek();if(a!=null&&typeof a.retain==`number`&&a.attributes==null){for(var s=a.retain;t.peekType()===`insert`&&t.peekLength()<=s;)s-=t.peekLength(),r.push(t.next());a.retain-s>0&&n.next(a.retain-s)}for(var l=new c(r);t.hasNext()||n.hasNext();)if(n.peekType()===`insert`)l.push(n.next());else if(t.peekType()===`delete`)l.push(t.next());else{var u=Math.min(t.peekLength(),n.peekLength()),d=t.next(u),f=n.next(u);if(typeof f.retain==`number`){var p={};typeof d.retain==`number`?p.retain=u:p.insert=d.insert;var m=o.attributes.compose(d.attributes,f.attributes,typeof d.retain==`number`);if(m&&(p.attributes=m),l.push(p),!n.hasNext()&&i(l.ops[l.ops.length-1],p)){var h=new c(t.rest());return l.concat(h).chop()}}else typeof f.delete==`number`&&typeof d.retain==`number`&&l.push(f)}return l.chop()},c.prototype.concat=function(e){var t=new c(this.ops.slice());return e.ops.length>0&&(t.push(e.ops[0]),t.ops=t.ops.concat(e.ops.slice(1))),t},c.prototype.diff=function(e,t){if(this.ops===e.ops)return new c;var n=[this,e].map(function(t){return t.map(function(n){if(n.insert!=null)return typeof n.insert==`string`?n.insert:s;var r=t===e?`on`:`with`;throw Error(`diff() called `+r+` non-document`)}).join(``)}),a=new c,l=r(n[0],n[1],t),u=o.iterator(this.ops),d=o.iterator(e.ops);return l.forEach(function(e){for(var t=e[1].length;t>0;){var n=0;switch(e[0]){case r.INSERT:n=Math.min(d.peekLength(),t),a.push(d.next(n));break;case r.DELETE:n=Math.min(t,u.peekLength()),u.next(n),a.delete(n);break;case r.EQUAL:n=Math.min(u.peekLength(),d.peekLength(),t);var s=u.next(n),c=d.next(n);i(s.insert,c.insert)?a.retain(n,o.attributes.diff(s.attributes,c.attributes)):a.push(c).delete(n);break}t-=n}}),a.chop()},c.prototype.eachLine=function(e,t){t||=`
54
+ `).trim();return r&&i(`ran in`,Date.now()-n+`ms`),d}function f(e){if(e){c+=e;return}return o?``:Array(c).join(s||``)}function p(e){return`@`+e.type+` `+e.value+`;`+l}function m(e){var t=``,n=e.prefix||``;e.name&&(t=` `+e.name);var r=e.type!==`page`;return`@`+n+e.type+t+u+v(e,r)+l}function h(e){return a?`/*`+(e.text||``)+`*/`+l:``}function g(e){var t;return e.selectors?t=e.selectors.join(`,`+l):(t=`@`+e.type,t+=e.name?` `+e.name:``),f()+t+u+v(e)+l}function _(e,t){return e.reduce(function(e,n){var r=n.type===`comment`?h(n):t(n);return r&&e.push(r),e},[])}function v(e,t){var n=e.declarations,r=b;return e.rules&&(n=e.rules,r=g),n=y(n,r),n&&=l+n+(t?``:l),`{`+n+f()+`}`}function y(e,t){if(!e)return``;f(1);var n=_(e,t);return f(-1),n.length?n.join(l):``}function b(e){if(e.type===`property`)return S(e);n&&i(`stringifyDeclaration: unexpected node:`,JSON.stringify(e))}function x(e){switch(e.type){case`rule`:return g(e);case`media`:case`keyframes`:return m(e);case`comment`:return h(e);case`import`:case`charset`:case`namespace`:return p(e);case`font-face`:case`supports`:case`viewport`:case`document`:case`page`:return m(e)}n&&i(`stringifyNode: unexpected node: `+JSON.stringify(e))}function S(e){var t=e.name?e.name+`:`+u:``;return f()+t+e.value+`;`}})),B_=e(r(((e,t)=>{t.exports={lex:L_(),parse:R_(),stringify:z_()}}))(),1);function V_(e){for(;e.parentNode;){if(e.nodeName===`defs`)return!0;e=e.parentNode}return!1}function H_(e){let t={};return e.querySelectorAll(`style`).forEach(e=>{let n=B_.default.parse(e.textContent).stylesheet.rules;for(let e of n)e.selectors&&e.selectors.forEach(n=>{let r=t[n]||{};e.declarations.forEach(e=>{r[e.name]=e.value}),t[n]=r})}),t}function U_(e,t){let n={fill:``,stroke:``},r=e.getAttribute(`class`)?.split(` `)||[],i=e.getAttribute(`id`),a={};i&&t[`#${i}`]?a=t[`#${i}`]:r.forEach(e=>{t[`.${e}`]&&(a=Object.assign(Object.assign({},a),t[`.${e}`]))}),t[e.nodeName]&&(a=Object.assign(Object.assign({},a),t[e.nodeName]));let o=e.getAttribute(`fill`);o&&o!==`none`?n.fill=o:a.fill&&a.fill!==`none`&&(n.fill=a.fill);let s=e.getAttribute(`stroke`);if(s&&s!==`none`?n.stroke=s:a.stroke&&a.stroke!==`none`&&(n.stroke=a.stroke),!n.fill&&e.style.fill&&e.style.fill!==`none`&&(n.fill=e.style.fill),!n.stroke&&e.style.stroke&&e.style.stroke!==`none`&&(n.stroke=e.style.stroke),!n.stroke&&!n.fill){let r=e.ownerSVGElement,i=r&&r!==e?U_(r,t):null;i?.fill===`currentColor`||i?.stroke===`currentColor`||(n.fill=`black`)}return n}var W_=[`path`,`rect`,`circle`,`line`,`polygon`,`polyline`,`ellipse`,`text`];function G_(e){for(var t=[],n=e.getElementsByTagName(`*`),r=0,i=n.length;r<i;r++){let e=n[r];V_(e)||(e.getAttribute(`fill`)!==null&&t.push(e),(e.getAttribute(`stroke`)!==null||e.style&&e.style.fill||W_.indexOf(e.nodeName)>=0)&&t.push(e))}return t}async function K_(e){return J_(await(await fetch(e)).text())}async function q_(e){return await(await fetch(e,{mode:`cors`})).text()}function J_(e){return`data:image/svg+xml;base64,`+window.btoa(unescape(encodeURIComponent(e)))}function Y_(e){var t=new DOMParser().parseFromString(e,`image/svg+xml`);let[n,r,i,a]=t.documentElement.getAttribute(`viewBox`)?.split(` `)||[],o=t.documentElement.getAttribute(`width`);!o&&t.documentElement.setAttribute(`width`,i+`px`);let s=t.documentElement.getAttribute(`height`);if((!s||s.indexOf(`%`)>=0)&&t.documentElement.setAttribute(`height`,a+`px`),o&&o.indexOf(`%`)>=0&&s&&s.indexOf(`%`)===-1){let e=parseFloat(s)/parseFloat(a);t.documentElement.setAttribute(`width`,e*parseFloat(i)+`px`)}if(s&&s.indexOf(`%`)>=0&&o&&o.indexOf(`%`)===-1){let e=parseFloat(o)/parseFloat(i);t.documentElement.setAttribute(`height`,e*parseFloat(a)+`px`)}return o===`100%`&&s===`100%`&&(t.documentElement.setAttribute(`width`,i+`px`),t.documentElement.setAttribute(`height`,a+`px`)),new XMLSerializer().serializeToString(t)}var X_=(e,t)=>{if(!e||!t)return!1;if(t===`currentColor`&&e===`black`)return!0;let n=Du.Util.colorToRGBA(e),r=Du.Util.colorToRGBA(t);return n&&r?n.r===r.r&&n.g===r.g&&n.b===r.b&&n.a===r.a:void 0};function Z_(e,t){var n=new DOMParser().parseFromString(e,`image/svg+xml`);let r=G_(n),i=Array.from(t.keys()),a=H_(n);return r.forEach(e=>{let{fill:r,stroke:o}=U_(e,a);[{prop:`fill`,color:r},{prop:`stroke`,color:o}].forEach(({prop:r,color:a})=>{let o=i.find(e=>X_(e,a));if(o){let i=t.get(o);if(jf(i)){let{rotation:t,stops:a}=Nf(i),o=a.map(e=>({offset:100*e.offset+`%`,"stop-color":e.color})),s=`color`+Math.round(1e8*Math.random());(function(e,t,n,r){var i=e.namespaceURI,a=document.createElementNS(i,`linearGradient`);let o=Du.Util.degToRad(n+90),s=(Math.cos(o)+1)/2,c=(Math.sin(o)+1)/2,l=(Math.cos(o+Math.PI)+1)/2,u=(Math.sin(o+Math.PI)+1)/2;a.setAttribute(`x1`,100*s+`%`),a.setAttribute(`y1`,100*c+`%`),a.setAttribute(`x2`,100*l+`%`),a.setAttribute(`y2`,100*u+`%`),a.setAttribute(`gradientUnits`,`userSpaceOnUse`),a.setAttribute(`id`,t);for(var d=0;d<r.length;d++){var f=r[d],p=document.createElementNS(i,`stop`);for(var m in f)f.hasOwnProperty(m)&&p.setAttribute(m,f[m]);a.appendChild(p)}(e.querySelector(`defs`)||e.insertBefore(document.createElementNS(i,`defs`),e.firstChild)).appendChild(a)})(n.children[0],s,t,o),e.style[r]=null,e.setAttribute(r,`url('#${s}')`)}else e.style[r]=t.get(o)}})}),J_(new XMLSerializer().serializeToString(n))}var Q_=(e,t,n)=>{let r=t,i=n,a=1;for(;r>0&&i>0;){if(e.width=r,e.height=i,r+i<4e3)return;let o=e.getContext(`2d`);if(!o)return;if(o.fillStyle=`rgba(0,0,0,0.1)`,o.fillRect(0,0,1,1),o.getImageData(0,0,1,1).data[3]!==0){o.clearRect(0,0,e.width,e.height);return}if(a*=.9,r=Math.floor(t*a),i=Math.floor(n*a),r=Math.max(r,1),i=Math.max(i,1),r<=1&&i<=1){e.width=1,e.height=1;return}}};function $_(e,t){let n=t.x??0,r=t.y??0,i=t.pixelRatio||1,a=Math.round(t.width*i),o=Math.round(t.height*i),s=a/i,c=o/i,l=t.sceneCanvas;l?(l.width!==a||l.height!==o||l.pixelRatio!==i)&&(l.setSize(s,c),l.setPixelRatio(i)):l=new to({width:s,height:c,pixelRatio:i});let u=l.getContext(),d=l.width/l.pixelRatio+Math.abs(n),f=l.height/l.pixelRatio+Math.abs(r),p=t.bufferCanvas;if(p){let e=Math.round(d*l.pixelRatio),t=Math.round(f*l.pixelRatio);(p.width!==e||p.height!==t||p.pixelRatio!==l.pixelRatio)&&(p.setSize(d,f),p.setPixelRatio(l.pixelRatio))}else p=new to({width:d,height:f,pixelRatio:l.pixelRatio});return!1===t.imageSmoothingEnabled&&(u._context.imageSmoothingEnabled=!1),u.save(),(n||r)&&u.translate(-1*n,-1*r),e.drawScene(l,void 0,p),u.restore(),l}function ev(){return{sceneCanvas:new to({width:1,height:1,pixelRatio:1}),bufferCanvas:new to({width:1,height:1,pixelRatio:1})}}var tv=(e,t=100,n=!1,r)=>{let i=d.useRef(r??e),[,a]=d.useReducer(e=>e+1,0),o=d.useCallback(e=>{i.current!==e&&(i.current=e,a())},[i]),s=d.useRef(null);return e===n&&(s.current&&=(clearTimeout(s.current),null),i.current=n),d.useEffect(()=>(s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{o(e),s.current=null},t),()=>{s.current&&clearTimeout(s.current)}),[e,t,n]),[i.current,o]};function nv(){return document.createElement(`canvas`)}var rv=e=>e.indexOf(`data:image/svg+xml`)>=0||e.indexOf(`.svg`)>=0,iv=e=>{let[t,n]=d.useState(e);return d.useEffect(()=>{(async()=>{let r=await async function(e){return rv(e)?J_(Y_(await q_(e))):e}(e);r!==t&&n(r)})()},[e]),t};function av(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}var ov={boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`],keepRatio:!1,rotateEnabled:!1,anchorFill:`rgb(240, 240, 240)`,anchorStrokeWidth:2,borderStrokeWidth:2},sv={boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,anchorSize:20,enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`],rotateEnabled:!1,borderEnabled:!1,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2},cv=(e,t,n)=>Math.max(t,Math.min(n,e)),lv=(e,t,n,r,i=0,a=!1,o=!0)=>{let s=Math.floor(cv(e.a.width*r,1,1e4)),c=Math.floor(cv(e.a.height*r,1,1e4)),l=Math.min(i*r,s/2,c/2),u=Math.max(e.a.width/n.width,e.a.height/n.height)*r,f=e.page._exportingOrRendering&&Sp.imageDownScalingEnabled&&u<1&&!a,p=n.x===0&&n.y===0&&n.width===t?.width&&n.height===t?.height,m=d.useMemo(()=>{if(t&&t.width&&t.height)return p&&l===0&&!f?void 0:nv()},[t,l,f,p]);return d.useLayoutEffect(()=>{if(!m||!t)return;Q_(m,s,c);let e=m.getContext(`2d`);if(!e)return;l&&(e.beginPath(),e.moveTo(l,0),e.lineTo(s-l,0),e.arc(s-l,l,l,3*Math.PI/2,0,!1),e.lineTo(s,c-l),e.arc(s-l,c-l,l,0,Math.PI/2,!1),e.lineTo(l,c),e.arc(l,c-l,l,Math.PI/2,Math.PI,!1),e.lineTo(0,l),e.arc(l,l,l,Math.PI,3*Math.PI/2,!1),e.clip());let r=f?function(e,t){var n,r;let i=nv();i.width=e.width,i.height=e.height;let a=Math.max(1,Math.floor(i.width*t)),o=Math.max(1,Math.floor(i.height*t));(n=i.getContext(`2d`))==null||n.drawImage(e,0,0,i.width,i.height);let s=function(e,t,n,r,i,a,o){for(var s=new ImageData(t,n),c=new Int32Array(e.data.buffer),l=e.width,u=new Int32Array(s.data.buffer),d=s.width,f=t/a,p=n/o,m=Math.round(1/f),h=Math.round(1/p),g=m*h,_=0;_<s.height;_++)for(var v=0;v<d;v++){for(var y=0+Math.round(v/f)+(0+Math.round(_/p))*l,b=0,x=0,S=0,C=0,w=0;w<h;w++)for(var T=0;T<m;T++){var E=c[y+T+w*l];b+=E<<24>>>24,x+=E<<16>>>24,S+=E<<8>>>24,C+=E>>>24}b=Math.round(b/g),x=Math.round(x/g),S=Math.round(S/g),C=Math.round(C/g),u[v+_*d]=C<<24|S<<16|x<<8|b}return s}(i.getContext(`2d`).getImageData(0,0,i.width,i.height),a,o,0,0,i.width,i.height);return i.width=a,i.height=o,(r=i.getContext(`2d`))==null||r.putImageData(s,0,0),i}(t,u):t,i=f?{x:Math.floor(n.x*u),y:Math.floor(n.y*u),width:Math.floor(n.width*u),height:Math.floor(n.height*u)}:n;e.drawImage(r,i.x,i.y,i.width,i.height,0,0,m.width,m.height)},[m,e.a.width,e.a.height,n.x,n.y,n.width,n.height,i,r,a,e.page._exportingOrRendering,f]),d.useEffect(()=>()=>{m&&m.nodeName===`CANVAS`&&Du.Util.releaseCanvas(m)},[m]),m||t},uv=nv(),dv=sa(({element:e})=>{let t=Math.min(30,e.a.width/4,e.a.height/4),n=d.useRef(null);return d.useEffect(()=>{let e=n.current;if(!e)return;let t=new Du.Animation(t=>{e.rotate((t?.timeDiff||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}}),d.createElement(Kd,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},d.createElement(Jd,{width:e.a.width,height:e.a.height,fill:`rgba(124, 173, 212, 0.8)`}),d.createElement(`Arc`,{ref:n,x:e.a.width/2,y:e.a.height/2,fill:`white`,outerRadius:Math.abs(t),innerRadius:Math.max(1,t-5),angle:270}))}),fv=sa(({element:e})=>{let t=Math.max(10,Math.min(30,e.a.width/25));return d.createElement(Kd,{x:e.x,y:e.y,rotation:e.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},d.createElement(Jd,{width:e.a.width,height:e.a.height,fill:`rgba(223, 102, 102, 0.8)`}),d.createElement(Zd,{text:`Can not load the image...`,fontSize:t,width:e.a.width,height:e.a.height,align:`center`,fill:`white`,verticalAlign:`middle`,padding:5}))}),pv=rf.default,mv=(e,t=``,n=``)=>{let r=d.useRef(),i=()=>{var e;(e=r.current)==null||e.call(r),r.current=void 0};d.useEffect(()=>i,[]),d.useLayoutEffect(()=>{let a=`image with id ${n} url: ${t.slice(0,200)}`;e!==`loading`||r.current||(r.current=Kf(a)),e!==`loading`&&i(),e===`failed`&&Zf(a)},[e])},hv=sa(({element:e,store:t})=>{let[n,r]=d.useState(!1),i=d.useRef(null),a=d.useRef(null),o=t.selectedShapes.indexOf(e)>=0&&e.selectable,[s,c]=(e=>{let[t,n]=d.useReducer(e=>e+1,0),r=d.useRef(`loading`),i=d.useRef(e.src),a=d.useRef(e.src);a.current!==e.src&&(a.current=e.src,r.current=`loading`);let o=d.useMemo(()=>rv(e.src)||e.type===`svg`,[e.src,e.type]);return d.useEffect(()=>{if(!o||!e.src)return;let t=!1;return(async()=>{r.current=`loading`,n();let a=Y_(await q_(e.src)),o;o=e.colorsReplace?Z_(a,e.colorsReplace||new Map):J_(a),t||(i.current=o,r.current=`loaded`,n())})(),()=>{t=!0}},[e.src,JSON.stringify(e.colorsReplace)]),o?[i.current,r.current]:[e.src,`loaded`]})(e),[l,u]=pv(s,`anonymous`);mv(e.type!==`svg`||c===`loaded`?u:`loading`,e.src,e.id);let f=e.page._exportingOrRendering?1:Math.max(1,t.scale),p=t._elementsPixelRatio*f,m=(({image:e,status:t,type:n})=>{let r=d.useRef();return d.useEffect(()=>{r.current=e||r.current},[e]),t!==`failed`||t!==`failed`&&n===`svg`?r.current:void 0})({image:l,status:u,type:e.type}),h=((e,t)=>{let n=iv(e.maskSrc||``),[r,i]=pv(n,`anonymous`);return mv(n?i:`loaded`,n||``,e.id),d.useMemo(()=>{if(!r||!t||!t.width||!t.height)return t;let n=nv();n.width=Math.max(t.width,1),n.height=Math.max(t.height,1);let i=n.getContext(`2d`);if(!i)return t;i.drawImage(t,0,0),i.globalCompositeOperation=`source-in`;let a=function(e,t){let n=t.width/t.height,r,i;return n>=e.width/e.height?(r=e.width,i=e.width/n):(r=e.height*n,i=e.height),{x:(e.width-r)/2,y:(e.height-i)/2,width:r,height:i}}(r,e);return i.drawImage(r,a.x,a.y,a.width,a.height,0,0,t.width,t.height),n},[t,r,e.a.width,e.a.height])})(e,((e,t,n)=>{let r=d.useMemo(()=>{var r,i;let{flipX:a,flipY:o}=e,s=e.type===`svg`||e.src.indexOf(`data:image/svg+xml`)>=0||e.src.indexOf(`.svg`)>=0,c=navigator.userAgent.toLowerCase().indexOf(`firefox`)>-1,l=(/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||c)&&s||e.maskSrc;if(!a&&!o&&!l)return t;if(!t||!t.width||!t.height)return null;let u=nv(),d=1;e.type===`svg`&&(d=Math.max(e.a.width/t.width*n,e.a.height/t.height*n)),Q_(u,Math.max(t.width*d,1),Math.max(t.height*d,1));let f=a?-u.width:0,p=o?-u.height:0;return(r=u.getContext(`2d`))==null||r.scale(a?-1:1,o?-1:1),(i=u.getContext(`2d`))==null||i.drawImage(t,f,p,u.width,u.height),u},[e.maskSrc,e.flipX,e.flipY,t,e.a.width,e.a.height,n]);return d.useEffect(()=>()=>{r&&r.nodeName===`CANVAS`&&Du.Util.releaseCanvas(r)},[r]),r})(e,l||m,p))||uv,{cropX:g,cropY:_,cropWidth:v,cropHeight:y}=e.a;u!==`loaded`&&(g=_=0,v=y=1);let b=h.width*v,x=h.height*y,S=e.a.width/e.a.height,C,w,T=b/x,E=e.stretchEnabled;E?(C=b,w=x):S>=T?(C=b,w=b/S):(C=x*S,w=x);let D={x:h.width*g,y:h.height*_,width:C,height:w},O=e.cornerRadius??0,k=e.page._exportingOrRendering?1:Math.min(2,t.scale),A=t._elementsPixelRatio*k,j=((e,t,n,r)=>{let[i,a]=pv(iv(e.clipSrc||``),`anonymous`);mv(e.clipSrc?a:`loaded`,e.clipSrc,e.id);let o=d.useMemo(()=>{if(t&&i)return nv()},[t,i]);return d.useLayoutEffect(()=>{var r;if(!i||!t||!t.width||!t.height||!i||!i.width||!i.height||!o)return;let a=nv(),s=Math.max(e.a.width/i.width*n,e.a.height/i.height*n);a.width=Math.max(i.width*s,1),a.height=Math.max(i.height*s,1),(r=a.getContext(`2d`))==null||r.drawImage(i,0,0,a.width,a.height),o.width=Math.max(t.width,1),o.height=Math.max(t.height,1);let c=o.getContext(`2d`);c&&(c.save(),c.drawImage(a,0,0,t.width,t.height),Du.Util.releaseCanvas(a),c.globalCompositeOperation=`source-in`,c.drawImage(t,0,0,o.width,o.height),c.restore())},[o,t,i,e.a.width,e.a.height,n,...r]),e.clipSrc&&i?o:t})(e,lv(e,h,D,A,O,n||e._cropModeEnabled||e.type===`svg`,!0),A,[D,O,A]),M=Math.max(e.a.width/C,e.a.height/w);d.useEffect(()=>{if(!e._cropModeEnabled)return;let t=i.current?.getStage();function n(t){e._cropModeEnabled&&t.target!==a.current&&e.toggleCropMode(!1)}function r(n){e._cropModeEnabled&&n.target.parentNode!==t?.content&&e.toggleCropMode(!1)}return document.body.addEventListener(`click`,r),t?.on(`click`,n),t?.on(`tap`,n),()=>{document.body.removeEventListener(`click`,r),document.body.removeEventListener(`touchstart`,r),t?.off(`click`,n),t?.off(`click`,n)}},[e._cropModeEnabled]),d.useLayoutEffect(()=>{if(!n&&!e._cropModeEnabled)return Hp(i.current,e),Gn(()=>{Hp(i.current,e)},{delay:100})},[j,e.page._exportingOrRendering,n,v,y,e._cropModeEnabled]),d.useLayoutEffect(()=>{var t;n||e._cropModeEnabled?(t=i.current)==null||t.clearCache():Hp(i.current,e)},[n,e.a.width,e.a.height,e._cropModeEnabled]),d.useEffect(()=>{Hp(i.current,e)},[e.shadowEnabled,e.shadowBlur,e.cornerRadius,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);let N=d.useRef(null),P=d.useRef(null),F=d.useRef(null);d.useLayoutEffect(()=>{e._cropModeEnabled&&(P.current.nodes([N.current]),F.current.nodes([a.current]))},[e._cropModeEnabled]);var ee=d.useRef(null),te=d.useRef(0),ne=d.useRef(!1);let re=t=>{t.evt.touches?.length>2&&t.target.stopDrag(),Math.round(t.target.x())>0&&(t.target.x(0),t.target.scaleX(1)),Math.round(t.target.y())>0&&(t.target.y(0),t.target.scaleY(1));let n=t.target.width()*t.target.scaleX(),r=t.target.height()*t.target.scaleY(),i=Math.min(1,C/n),a=Math.min(1,w/r),o=1-i,s=Math.min(o,Math.max(0,Math.round(-t.target.x())/n)),c=1-a,l=Math.min(c,Math.max(0,Math.round(-t.target.y())/r));t.target.setAttrs({x:-s*h.width,y:-l*h.height,scaleX:1,scaleY:1}),e.set({cropX:s,cropY:l,cropWidth:i,cropHeight:a})},ie=()=>{e.type!==`svg`&&e.contentEditable&&(e.stretchEnabled||setTimeout(()=>{e.toggleCropMode(!0)}))},I=e.type===`svg`&&m,[ae]=tv(u===`loading`&&!I,100,!1,!1),oe=u===`failed`,se=!ae&&!oe,ce=d.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),le=se?e.a.opacity:0;Rf(i,le);let ue=e.selectable||t.role===`admin`,de=Up(),fe=Pf(e,e.borderColor,`stroke`);return d.createElement(d.Fragment,null,ae&&d.createElement(dv,{element:e}),oe&&d.createElement(fv,{element:e}),d.createElement(Xd,{ref:i,name:`element`,id:e.id,image:j,x:e.a.x,y:e.a.y,width:e.a.width||1,height:e.a.height||1,rotation:e.a.rotation,opacity:le,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,customCrop:D,listening:ue,draggable:de?e.draggable&&o:e.draggable,preventDefault:!de||o,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDblClick:ie,onDblTap:ie,onTransformStart:()=>{r(!0),ce.current={cropX:e.cropX,cropY:e.cropY,cropWidth:e.cropWidth,cropHeight:e.cropHeight}},onTransform:t=>{let n=t.currentTarget,r=Math.abs(n.scaleX()-1)<1e-7?1:n.scaleX(),i=Math.abs(n.scaleY()-1)<1e-7?1:n.scaleY();n.scaleX(1),n.scaleY(1);let a=t.target.getStage()?.findOne(`Transformer`),o=1-C/h.width,s=Math.min(o,Math.max(0,e.cropX)),c=1-w/h.height,l=Math.min(c,Math.max(0,e.cropY)),u=a.getActiveAnchor(),d=!(u.indexOf(`middle`)>=0||u.indexOf(`center`)>=0),f=!d&&r<1&&ce.current.cropHeight>w/h.height,p=d?e.cropWidth:e.cropWidth*r;f&&(p=e.cropWidth);let m=!d&&i<1&&ce.current.cropWidth>C/h.width,g=d?e.cropHeight:e.cropHeight*i;m&&(g=e.cropHeight),E&&(p=e.cropWidth,g=e.cropHeight),e.set({cropX:s,cropY:l,x:n.x(),y:n.y(),width:n.width()*r,height:n.height()*i,rotation:t.target.rotation(),cropWidth:Math.min(p,1-s),cropHeight:Math.min(g,1-l)})},onTransformEnd:t=>{let n=t.currentTarget;e.set({width:n.width(),height:n.height(),x:n.x(),y:n.y(),rotation:t.target.rotation(),cropWidth:C/h.width,cropHeight:w/h.height}),r(!1)}}),d.createElement(Jd,Object.assign({x:e.x,y:e.y,width:Math.max(e.a.width-e.borderSize,0),height:Math.max(e.a.height-e.borderSize,0),opacity:le,offsetX:-e.borderSize/2,offsetY:-e.borderSize/2},fe,{strokeWidth:e.borderSize,listening:!1,visible:!!e.borderSize,rotation:e.rotation,cornerRadius:Math.max(0,O-e.borderSize),hideInExport:!e.showInExport})),e._cropModeEnabled&&d.createElement(lf,{selector:`.page-abs-container`,enabled:!0},d.createElement(`Rect`,{x:-window.innerWidth/t.scale,y:-window.innerWidth/t.scale,width:window.innerWidth/t.scale*3,height:window.innerWidth/t.scale*3,fill:`rgba(0,0,0,0.3)`}),d.createElement(`Image`,{listening:!1,image:j,x:e.x,y:e.y,width:e.a.width,height:e.a.height,rotation:e.rotation,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur}),d.createElement(`Group`,{x:e.x,y:e.y,rotation:e.rotation,scaleX:M,scaleY:M},d.createElement(`Image`,{image:h,ref:a,opacity:.4,draggable:!0,x:-e.cropX*h.width,y:-e.cropY*h.height,onDragMove:re,onTransform:re,onTouchMove:e=>{e.evt.preventDefault();let t=e.target.getStage().getPointersPositions();var n=t[0],r=t[1];let i=e.target;if(n&&!r&&!i.isDragging()&&ne.current&&(i.startDrag(),ne.current=!1),n&&r){Du.hitOnDragEnabled=!0,i.isDragging()&&(ne.current=!0,i.stopDrag());let t=e.target.getAbsoluteTransform().copy();t.invert();var a={x:n.x,y:n.y},o={x:r.x,y:r.y};if(!ee.current){ee.current=av(a,o);return}var s=av(a,o),c=function(e,t){return Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2)}(a,o);te.current||=c;let m=i.position();var l={x:s.x-m.x,y:s.y-m.y},u=c/te.current;i.scaleX(u),i.scaleY(u);let h=t.point(s),g=t.point(ee.current);var d=h.x-g.x,f=h.y-g.y,p={x:Math.min(0,s.x-l.x*u+d),y:Math.min(0,s.y-l.y*u+f)};i.position(p),te.current=c,ee.current=s,re(e)}},onTouchEnd:e=>{te.current=0,ee.current=null,Du.hitOnDragEnabled=!1}}),d.createElement(`Transformer`,Object.assign({ref:F},sv)),d.createElement(`Rect`,{width:C,height:w,ref:N,listening:!1,onTransform:t=>{if(e.cropX<Math.abs(t.target.x()/h.width)&&t.target.x()<0&&e.cropX>0){let n=(e.cropWidth+e.cropX)*h.width;t.target.scaleX(1),t.target.width(n)}if(e.cropY<Math.abs(t.target.y()/h.height)&&t.target.y()<0&&e.cropY>0){let n=(e.cropHeight+e.cropY)*h.height;t.target.scaleY(1),t.target.height(n)}t.target.x()<-e.cropX*h.width-1e-9&&(t.target.x(-e.cropX*h.width),t.target.scaleX(1)),t.target.y()<-e.cropY*h.height-1e-9&&(t.target.y(-e.cropY*h.height),t.target.scaleY(1));let n=Math.min(1,Math.max(0,e.cropX+t.target.x()/h.width)),r=Math.min(1,Math.max(0,t.target.y()/h.height+e.cropY)),i=t.target.width()*t.target.scaleX(),a=t.target.height()*t.target.scaleY(),o=Math.min(1-n,i/h.width),s=Math.min(1-r,a/h.height),c=t.target.getAbsolutePosition(t.target.getParent().getParent());t.target.scale({x:1,y:1}),t.target.position({x:0,y:0}),e.set({x:c.x,y:c.y,cropX:n,cropY:r,cropWidth:o,cropHeight:s,width:Math.min(i*M,h.width*(1-n)*M),height:Math.min(a*M,h.height*(1-r)*M)})}}),d.createElement(`Transformer`,Object.assign({ref:P},ov,{visible:e.resizable})))))}),gv=r(((e,t)=>{(function(n,r){typeof e==`object`&&typeof t==`object`?t.exports=r():typeof define==`function`&&define.amd?define([],r):typeof e==`object`?e.Quill=r():n.Quill=r()})(typeof self<`u`?self:e,function(){return(function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,`a`,t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=``,n(n.s=109)})([(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=n(17),i=n(18),a=n(19),o=n(45),s=n(46),c=n(47),l=n(48),u=n(49),d=n(12),f=n(32),p=n(33),m=n(31),h=n(1);t.default={Scope:h.Scope,create:h.create,find:h.find,query:h.query,register:h.register,Container:r.default,Format:i.default,Leaf:a.default,Embed:l.default,Scroll:o.default,Block:c.default,Inline:s.default,Text:u.default,Attributor:{Attribute:d.default,Class:f.default,Style:p.default,Store:m.default}}}),(function(e,t,n){var r=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}})();Object.defineProperty(t,`__esModule`,{value:!0});var i=function(e){r(t,e);function t(t){var n=this;return t=`[Parchment] `+t,n=e.call(this,t)||this,n.message=t,n.name=n.constructor.name,n}return t}(Error);t.ParchmentError=i;var a={},o={},s={},c={};t.DATA_KEY=`__blot`;var l;(function(e){e[e.TYPE=3]=`TYPE`,e[e.LEVEL=12]=`LEVEL`,e[e.ATTRIBUTE=13]=`ATTRIBUTE`,e[e.BLOT=14]=`BLOT`,e[e.INLINE=7]=`INLINE`,e[e.BLOCK=11]=`BLOCK`,e[e.BLOCK_BLOT=10]=`BLOCK_BLOT`,e[e.INLINE_BLOT=6]=`INLINE_BLOT`,e[e.BLOCK_ATTRIBUTE=9]=`BLOCK_ATTRIBUTE`,e[e.INLINE_ATTRIBUTE=5]=`INLINE_ATTRIBUTE`,e[e.ANY=15]=`ANY`})(l=t.Scope||={});function u(e,t){var n=f(e);if(n==null)throw new i(`Unable to create `+e+` blot`);var r=n;return new r(e instanceof Node||e.nodeType===Node.TEXT_NODE?e:r.create(t),t)}t.create=u;function d(e,n){return n===void 0&&(n=!1),e==null?null:e[t.DATA_KEY]==null?n?d(e.parentNode,n):null:e[t.DATA_KEY].blot}t.find=d;function f(e,t){t===void 0&&(t=l.ANY);var n;if(typeof e==`string`)n=c[e]||a[e];else if(e instanceof Text||e.nodeType===Node.TEXT_NODE)n=c.text;else if(typeof e==`number`)e&l.LEVEL&l.BLOCK?n=c.block:e&l.LEVEL&l.INLINE&&(n=c.inline);else if(e instanceof HTMLElement){var r=(e.getAttribute(`class`)||``).split(/\s+/);for(var i in r)if(n=o[r[i]],n)break;n||=s[e.tagName]}return n==null?null:t&l.LEVEL&n.scope&&t&l.TYPE&n.scope?n:null}t.query=f;function p(){var e=[...arguments];if(e.length>1)return e.map(function(e){return p(e)});var t=e[0];if(typeof t.blotName!=`string`&&typeof t.attrName!=`string`)throw new i(`Invalid definition`);if(t.blotName===`abstract`)throw new i(`Cannot register abstract class`);return c[t.blotName||t.attrName]=t,typeof t.keyName==`string`?a[t.keyName]=t:(t.className!=null&&(o[t.className]=t),t.tagName!=null&&(Array.isArray(t.tagName)?t.tagName=t.tagName.map(function(e){return e.toUpperCase()}):t.tagName=t.tagName.toUpperCase(),(Array.isArray(t.tagName)?t.tagName:[t.tagName]).forEach(function(e){(s[e]==null||t.className==null)&&(s[e]=t)}))),t}t.register=p}),(function(e,t,n){var r=n(51),i=n(11),a=n(3),o=n(20),s=`\0`,c=function(e){Array.isArray(e)?this.ops=e:e!=null&&Array.isArray(e.ops)?this.ops=e.ops:this.ops=[]};c.prototype.insert=function(e,t){var n={};return e.length===0?this:(n.insert=e,typeof t==`object`&&t&&Object.keys(t).length>0&&(n.attributes=t),this.push(n))},c.prototype.delete=function(e){return e<=0?this:this.push({delete:e})},c.prototype.retain=function(e,t){if(e<=0)return this;var n={retain:e};return typeof t==`object`&&t&&Object.keys(t).length>0&&(n.attributes=t),this.push(n)},c.prototype.push=function(e){var t=this.ops.length,n=this.ops[t-1];if(e=a(!0,{},e),typeof n==`object`){if(typeof e.delete==`number`&&typeof n.delete==`number`)return this.ops[t-1]={delete:n.delete+e.delete},this;if(typeof n.delete==`number`&&e.insert!=null&&(--t,n=this.ops[t-1],typeof n!=`object`))return this.ops.unshift(e),this;if(i(e.attributes,n.attributes)){if(typeof e.insert==`string`&&typeof n.insert==`string`)return this.ops[t-1]={insert:n.insert+e.insert},typeof e.attributes==`object`&&(this.ops[t-1].attributes=e.attributes),this;if(typeof e.retain==`number`&&typeof n.retain==`number`)return this.ops[t-1]={retain:n.retain+e.retain},typeof e.attributes==`object`&&(this.ops[t-1].attributes=e.attributes),this}}return t===this.ops.length?this.ops.push(e):this.ops.splice(t,0,e),this},c.prototype.chop=function(){var e=this.ops[this.ops.length-1];return e&&e.retain&&!e.attributes&&this.ops.pop(),this},c.prototype.filter=function(e){return this.ops.filter(e)},c.prototype.forEach=function(e){this.ops.forEach(e)},c.prototype.map=function(e){return this.ops.map(e)},c.prototype.partition=function(e){var t=[],n=[];return this.forEach(function(r){(e(r)?t:n).push(r)}),[t,n]},c.prototype.reduce=function(e,t){return this.ops.reduce(e,t)},c.prototype.changeLength=function(){return this.reduce(function(e,t){return t.insert?e+o.length(t):t.delete?e-t.delete:e},0)},c.prototype.length=function(){return this.reduce(function(e,t){return e+o.length(t)},0)},c.prototype.slice=function(e,t){e||=0,typeof t!=`number`&&(t=1/0);for(var n=[],r=o.iterator(this.ops),i=0;i<t&&r.hasNext();){var a;i<e?a=r.next(e-i):(a=r.next(t-i),n.push(a)),i+=o.length(a)}return new c(n)},c.prototype.compose=function(e){var t=o.iterator(this.ops),n=o.iterator(e.ops),r=[],a=n.peek();if(a!=null&&typeof a.retain==`number`&&a.attributes==null){for(var s=a.retain;t.peekType()===`insert`&&t.peekLength()<=s;)s-=t.peekLength(),r.push(t.next());a.retain-s>0&&n.next(a.retain-s)}for(var l=new c(r);t.hasNext()||n.hasNext();)if(n.peekType()===`insert`)l.push(n.next());else if(t.peekType()===`delete`)l.push(t.next());else{var u=Math.min(t.peekLength(),n.peekLength()),d=t.next(u),f=n.next(u);if(typeof f.retain==`number`){var p={};typeof d.retain==`number`?p.retain=u:p.insert=d.insert;var m=o.attributes.compose(d.attributes,f.attributes,typeof d.retain==`number`);if(m&&(p.attributes=m),l.push(p),!n.hasNext()&&i(l.ops[l.ops.length-1],p)){var h=new c(t.rest());return l.concat(h).chop()}}else typeof f.delete==`number`&&typeof d.retain==`number`&&l.push(f)}return l.chop()},c.prototype.concat=function(e){var t=new c(this.ops.slice());return e.ops.length>0&&(t.push(e.ops[0]),t.ops=t.ops.concat(e.ops.slice(1))),t},c.prototype.diff=function(e,t){if(this.ops===e.ops)return new c;var n=[this,e].map(function(t){return t.map(function(n){if(n.insert!=null)return typeof n.insert==`string`?n.insert:s;var r=t===e?`on`:`with`;throw Error(`diff() called `+r+` non-document`)}).join(``)}),a=new c,l=r(n[0],n[1],t),u=o.iterator(this.ops),d=o.iterator(e.ops);return l.forEach(function(e){for(var t=e[1].length;t>0;){var n=0;switch(e[0]){case r.INSERT:n=Math.min(d.peekLength(),t),a.push(d.next(n));break;case r.DELETE:n=Math.min(t,u.peekLength()),u.next(n),a.delete(n);break;case r.EQUAL:n=Math.min(u.peekLength(),d.peekLength(),t);var s=u.next(n),c=d.next(n);i(s.insert,c.insert)?a.retain(n,o.attributes.diff(s.attributes,c.attributes)):a.push(c).delete(n);break}t-=n}}),a.chop()},c.prototype.eachLine=function(e,t){t||=`
55
55
  `;for(var n=o.iterator(this.ops),r=new c,i=0;n.hasNext();){if(n.peekType()!==`insert`)return;var a=n.peek(),s=o.length(a)-n.peekLength(),l=typeof a.insert==`string`?a.insert.indexOf(t,s)-s:-1;if(l<0)r.push(n.next());else if(l>0)r.push(n.next(l));else{if(e(r,n.next(1).attributes||{},i)===!1)return;i+=1,r=new c}}r.length()>0&&e(r,{},i)},c.prototype.transform=function(e,t){if(t=!!t,typeof e==`number`)return this.transformPosition(e,t);for(var n=o.iterator(this.ops),r=o.iterator(e.ops),i=new c;n.hasNext()||r.hasNext();)if(n.peekType()===`insert`&&(t||r.peekType()!==`insert`))i.retain(o.length(n.next()));else if(r.peekType()===`insert`)i.push(r.next());else{var a=Math.min(n.peekLength(),r.peekLength()),s=n.next(a),l=r.next(a);if(s.delete)continue;l.delete?i.push(l):i.retain(a,o.attributes.transform(s.attributes,l.attributes,t))}return i.chop()},c.prototype.transformPosition=function(e,t){t=!!t;for(var n=o.iterator(this.ops),r=0;n.hasNext()&&r<=e;){var i=n.peekLength(),a=n.peekType();if(n.next(),a===`delete`){e-=Math.min(i,e-r);continue}else a===`insert`&&(r<e||!t)&&(e+=i);r+=i}return e},e.exports=c}),(function(e,t){var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};e.exports=function e(){var t,n,r,i,a,u,d=arguments[0],f=1,p=arguments.length,m=!1;for(typeof d==`boolean`&&(m=d,d=arguments[1]||{},f=2),(d==null||typeof d!=`object`&&typeof d!=`function`)&&(d={});f<p;++f)if(t=arguments[f],t!=null)for(n in t)r=l(d,n),i=l(t,n),d!==i&&(m&&i&&(s(i)||(a=o(i)))?(a?(a=!1,u=r&&o(r)?r:[]):u=r&&s(r)?r:{},c(d,{name:n,newValue:e(m,u,i)})):i!==void 0&&c(d,{name:n,newValue:i}));return d}}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0}),t.default=t.BlockEmbed=t.bubbleFormats=void 0;var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=d(n(3)),o=d(n(2)),s=d(n(0)),c=d(n(16)),l=d(n(6)),u=d(n(7));function d(e){return e&&e.__esModule?e:{default:e}}function f(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function p(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function m(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var h=1,g=function(e){m(t,e);function t(){return f(this,t),p(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,[{key:`attach`,value:function(){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`attach`,this).call(this),this.attributes=new s.default.Attributor.Store(this.domNode)}},{key:`delta`,value:function(){return new o.default().insert(this.value(),(0,a.default)(this.formats(),this.attributes.values()))}},{key:`format`,value:function(e,t){var n=s.default.query(e,s.default.Scope.BLOCK_ATTRIBUTE);n!=null&&this.attributes.attribute(n,t)}},{key:`formatAt`,value:function(e,t,n,r){this.format(n,r)}},{key:`insertAt`,value:function(e,n,r){if(typeof n==`string`&&n.endsWith(`
56
56
  `)){var a=s.default.create(_.blotName);this.parent.insertBefore(a,e===0?this:this.next),a.insertAt(0,n.slice(0,-1))}else i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`insertAt`,this).call(this,e,n,r)}}]),t}(s.default.Embed);g.scope=s.default.Scope.BLOCK_BLOT;var _=function(e){m(t,e);function t(e){f(this,t);var n=p(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.cache={},n}return r(t,[{key:`delta`,value:function(){return this.cache.delta??(this.cache.delta=this.descendants(s.default.Leaf).reduce(function(e,t){return t.length()===0?e:e.insert(t.value(),v(t))},new o.default).insert(`
57
57
  `,v(this))),this.cache.delta}},{key:`deleteAt`,value:function(e,n){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`deleteAt`,this).call(this,e,n),this.cache={}}},{key:`formatAt`,value:function(e,n,r,a){n<=0||(s.default.query(r,s.default.Scope.BLOCK)?e+n===this.length()&&this.format(r,a):i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`formatAt`,this).call(this,e,Math.min(n,this.length()-e-1),r,a),this.cache={})}},{key:`insertAt`,value:function(e,n,r){if(r!=null)return i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`insertAt`,this).call(this,e,n,r);if(n.length!==0){var a=n.split(`
@@ -86,16 +86,16 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
86
86
  `),t}function ae(e,t){if(N(e)&&e.nextElementSibling!=null&&!M(t,`
87
87
 
88
88
  `)){var n=e.offsetHeight+parseFloat(j(e).marginTop)+parseFloat(j(e).marginBottom);e.nextElementSibling.offsetTop>e.offsetTop+n*1.5&&t.insert(`
89
- `)}return t}function oe(e,t){var n={},r=e.style||{};return r.fontStyle&&j(e).fontStyle===`italic`&&(n.italic=!0),r.fontWeight&&(j(e).fontWeight.startsWith(`bold`)||parseInt(j(e).fontWeight)>=700)&&(n.bold=!0),Object.keys(n).length>0&&(t=A(t,n)),parseFloat(r.textIndent||0)>0&&(t=new s.default().insert(` `).concat(t)),t}function se(e,t){var n=e.data;if(e.parentNode.tagName===`O:P`)return t.insert(n.trim());if(n.trim().length===0&&e.parentNode.classList.contains(`ql-clipboard`))return t;if(!j(e.parentNode).whiteSpace.startsWith(`pre`)){var r=function(e,t){return t=t.replace(/[^\u00a0]/g,``),t.length<1&&e?` `:t};n=n.replace(/\r\n/g,` `).replace(/\n/g,` `),n=n.replace(/\s\s+/g,r.bind(r,!0)),(e.previousSibling==null&&N(e.parentNode)||e.previousSibling!=null&&N(e.previousSibling))&&(n=n.replace(/^\s+/,r.bind(r,!1))),(e.nextSibling==null&&N(e.parentNode)||e.nextSibling!=null&&N(e.nextSibling))&&(n=n.replace(/\s+$/,r.bind(r,!1)))}return t.insert(n)}t.default=k,t.matchAttributor=ee,t.matchBlot=te,t.matchNewline=I,t.matchSpacing=ae,t.matchText=se}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=o(n(6));function o(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function c(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function l(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var u=function(e){l(t,e);function t(){return s(this,t),c(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,[{key:`optimize`,value:function(e){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`optimize`,this).call(this,e),this.domNode.tagName!==this.statics.tagName[0]&&this.replaceWith(this.statics.blotName)}}],[{key:`create`,value:function(){return i(t.__proto__||Object.getPrototypeOf(t),`create`,this).call(this)}},{key:`formats`,value:function(){return!0}}]),t}(a.default);u.blotName=`bold`,u.tagName=[`STRONG`,`B`],t.default=u}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0}),t.addControls=t.default=void 0;var r=function(){function e(e,t){var n=[],r=!0,i=!1,a=void 0;try{for(var o=e[Symbol.iterator](),s;!(r=(s=o.next()).done)&&(n.push(s.value),!(t&&n.length===t));r=!0);}catch(e){i=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(i)throw a}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw TypeError(`Invalid attempt to destructure non-iterable instance`)}}(),i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=u(n(2)),o=u(n(0)),s=u(n(5)),c=u(n(10)),l=u(n(9));function u(e){return e&&e.__esModule?e:{default:e}}function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function p(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function m(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var h=(0,c.default)(`quill:toolbar`),g=function(e){m(t,e);function t(e,n){f(this,t);var i=p(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));if(Array.isArray(i.options.container)){var a=document.createElement(`div`);v(a,i.options.container),e.container.parentNode.insertBefore(a,e.container),i.container=a}else typeof i.options.container==`string`?i.container=document.querySelector(i.options.container):i.container=i.options.container;if(!(i.container instanceof HTMLElement)){var o;return o=h.error(`Container required for toolbar`,i.options),p(i,o)}return i.container.classList.add(`ql-toolbar`),i.controls=[],i.handlers={},Object.keys(i.options.handlers).forEach(function(e){i.addHandler(e,i.options.handlers[e])}),[].forEach.call(i.container.querySelectorAll(`button, select`),function(e){i.attach(e)}),i.quill.on(s.default.events.EDITOR_CHANGE,function(e,t){e===s.default.events.SELECTION_CHANGE&&i.update(t)}),i.quill.on(s.default.events.SCROLL_OPTIMIZE,function(){var e=r(i.quill.selection.getRange(),1)[0];i.update(e)}),i}return i(t,[{key:`addHandler`,value:function(e,t){this.handlers[e]=t}},{key:`attach`,value:function(e){var t=this,n=[].find.call(e.classList,function(e){return e.indexOf(`ql-`)===0});if(n){if(n=n.slice(3),e.tagName===`BUTTON`&&e.setAttribute(`type`,`button`),this.handlers[n]==null){if(this.quill.scroll.whitelist!=null&&this.quill.scroll.whitelist[n]==null){h.warn(`ignoring attaching to disabled format`,n,e);return}if(o.default.query(n)==null){h.warn(`ignoring attaching to nonexistent format`,n,e);return}}var i=e.tagName===`SELECT`?`change`:`click`;e.addEventListener(i,function(i){var c=void 0;if(e.tagName===`SELECT`){if(e.selectedIndex<0)return;var l=e.options[e.selectedIndex];c=l.hasAttribute(`selected`)?!1:l.value||!1}else c=e.classList.contains(`ql-active`)?!1:e.value||!e.hasAttribute(`value`),i.preventDefault();t.quill.focus();var u=r(t.quill.selection.getRange(),1)[0];if(t.handlers[n]!=null)t.handlers[n].call(t,c);else if(o.default.query(n).prototype instanceof o.default.Embed){if(c=prompt(`Enter `+n),!c)return;t.quill.updateContents(new a.default().retain(u.index).delete(u.length).insert(d({},n,c)),s.default.sources.USER)}else t.quill.format(n,c,s.default.sources.USER);t.update(u)}),this.controls.push([n,e])}}},{key:`update`,value:function(e){var t=e==null?{}:this.quill.getFormat(e);this.controls.forEach(function(n){var i=r(n,2),a=i[0],o=i[1];if(o.tagName===`SELECT`){var s=void 0;if(e==null)s=null;else if(t[a]==null)s=o.querySelector(`option[selected]`);else if(!Array.isArray(t[a])){var c=t[a];typeof c==`string`&&(c=c.replace(/\"/g,`\\"`)),s=o.querySelector(`option[value="`+c+`"]`)}s==null?(o.value=``,o.selectedIndex=-1):s.selected=!0}else if(e==null)o.classList.remove(`ql-active`);else if(o.hasAttribute(`value`)){var l=t[a]===o.getAttribute(`value`)||t[a]!=null&&t[a].toString()===o.getAttribute(`value`)||t[a]==null&&!o.getAttribute(`value`);o.classList.toggle(`ql-active`,l)}else o.classList.toggle(`ql-active`,t[a]!=null)})}}]),t}(l.default);g.DEFAULTS={};function _(e,t,n){var r=document.createElement(`button`);r.setAttribute(`type`,`button`),r.classList.add(`ql-`+t),n!=null&&(r.value=n),e.appendChild(r)}function v(e,t){Array.isArray(t[0])||(t=[t]),t.forEach(function(t){var n=document.createElement(`span`);n.classList.add(`ql-formats`),t.forEach(function(e){if(typeof e==`string`)_(n,e);else{var t=Object.keys(e)[0],r=e[t];Array.isArray(r)?y(n,t,r):_(n,t,r)}}),e.appendChild(n)})}function y(e,t,n){var r=document.createElement(`select`);r.classList.add(`ql-`+t),n.forEach(function(e){var t=document.createElement(`option`);e===!1?t.setAttribute(`selected`,`selected`):t.setAttribute(`value`,e),r.appendChild(t)}),e.appendChild(r)}g.DEFAULTS={container:null,handlers:{clean:function(){var e=this,t=this.quill.getSelection();if(t!=null)if(t.length==0){var n=this.quill.getFormat();Object.keys(n).forEach(function(t){o.default.query(t,o.default.Scope.INLINE)!=null&&e.quill.format(t,!1)})}else this.quill.removeFormat(t,s.default.sources.USER)},direction:function(e){var t=this.quill.getFormat().align;e===`rtl`&&t==null?this.quill.format(`align`,`right`,s.default.sources.USER):!e&&t===`right`&&this.quill.format(`align`,!1,s.default.sources.USER),this.quill.format(`direction`,e,s.default.sources.USER)},indent:function(e){var t=this.quill.getSelection(),n=this.quill.getFormat(t),r=parseInt(n.indent||0);if(e===`+1`||e===`-1`){var i=e===`+1`?1:-1;n.direction===`rtl`&&(i*=-1),this.quill.format(`indent`,r+i,s.default.sources.USER)}},link:function(e){e===!0&&(e=prompt(`Enter link URL:`)),this.quill.format(`link`,e,s.default.sources.USER)},list:function(e){var t=this.quill.getSelection(),n=this.quill.getFormat(t);e===`check`?n.list===`checked`||n.list===`unchecked`?this.quill.format(`list`,!1,s.default.sources.USER):this.quill.format(`list`,`unchecked`,s.default.sources.USER):this.quill.format(`list`,e,s.default.sources.USER)}}},t.default=g,t.addControls=v}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <polyline class="ql-even ql-stroke" points="5 7 3 9 5 11"></polyline> <polyline class="ql-even ql-stroke" points="13 7 15 9 13 11"></polyline> <line class=ql-stroke x1=10 x2=8 y1=5 y2=13></line> </svg>`}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=o(n(28));function o(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function c(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function l(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.default=function(e){l(t,e);function t(e,n){s(this,t);var r=c(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.label.innerHTML=n,r.container.classList.add(`ql-color-picker`),[].slice.call(r.container.querySelectorAll(`.ql-picker-item`),0,7).forEach(function(e){e.classList.add(`ql-primary`)}),r}return r(t,[{key:`buildItem`,value:function(e){var n=i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`buildItem`,this).call(this,e);return n.style.backgroundColor=e.getAttribute(`value`)||``,n}},{key:`selectItem`,value:function(e,n){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`selectItem`,this).call(this,e,n);var r=this.label.querySelector(`.ql-color-label`),a=e&&e.getAttribute(`data-value`)||``;r&&(r.tagName===`line`?r.style.stroke=a:r.style.fill=a)}}]),t}(a.default)}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=o(n(28));function o(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function c(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function l(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.default=function(e){l(t,e);function t(e,n){s(this,t);var r=c(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.container.classList.add(`ql-icon-picker`),[].forEach.call(r.container.querySelectorAll(`.ql-picker-item`),function(e){e.innerHTML=n[e.getAttribute(`data-value`)||``]}),r.defaultItem=r.container.querySelector(`.ql-selected`),r.selectItem(r.defaultItem),r}return r(t,[{key:`selectItem`,value:function(e,n){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`selectItem`,this).call(this,e,n),e||=this.defaultItem,this.label.innerHTML=e.innerHTML}}]),t}(a.default)}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();function i(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}t.default=function(){function e(t,n){var r=this;i(this,e),this.quill=t,this.boundsContainer=n||document.body,this.root=t.addContainer(`ql-tooltip`),this.root.innerHTML=this.constructor.TEMPLATE,this.quill.root===this.quill.scrollingContainer&&this.quill.root.addEventListener(`scroll`,function(){r.root.style.marginTop=-1*r.quill.root.scrollTop+`px`}),this.hide()}return r(e,[{key:`hide`,value:function(){this.root.classList.add(`ql-hidden`)}},{key:`position`,value:function(e){var t=e.left+e.width/2-this.root.offsetWidth/2,n=e.bottom+this.quill.root.scrollTop;this.root.style.left=t+`px`,this.root.style.top=n+`px`,this.root.classList.remove(`ql-flip`);var r=this.boundsContainer.getBoundingClientRect(),i=this.root.getBoundingClientRect(),a=0;if(i.right>r.right&&(a=r.right-i.right,this.root.style.left=t+a+`px`),i.left<r.left&&(a=r.left-i.left,this.root.style.left=t+a+`px`),i.bottom>r.bottom){var o=i.bottom-i.top,s=e.bottom-e.top+o;this.root.style.top=n-s+`px`,this.root.classList.add(`ql-flip`)}return a}},{key:`show`,value:function(){this.root.classList.remove(`ql-editing`),this.root.classList.remove(`ql-hidden`)}}]),e}()}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){var n=[],r=!0,i=!1,a=void 0;try{for(var o=e[Symbol.iterator](),s;!(r=(s=o.next()).done)&&(n.push(s.value),!(t&&n.length===t));r=!0);}catch(e){i=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(i)throw a}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw TypeError(`Invalid attempt to destructure non-iterable instance`)}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=p(n(3)),s=p(n(8)),c=n(43),l=p(c),u=p(n(27)),d=n(15),f=p(n(41));function p(e){return e&&e.__esModule?e:{default:e}}function m(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function h(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function g(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _=[[{header:[`1`,`2`,`3`,!1]}],[`bold`,`italic`,`underline`,`link`],[{list:`ordered`},{list:`bullet`}],[`clean`]],v=function(e){g(t,e);function t(e,n){m(this,t),n.modules.toolbar!=null&&n.modules.toolbar.container==null&&(n.modules.toolbar.container=_);var r=h(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return r.quill.container.classList.add(`ql-snow`),r}return a(t,[{key:`extendToolbar`,value:function(e){e.container.classList.add(`ql-snow`),this.buildButtons([].slice.call(e.container.querySelectorAll(`button`)),f.default),this.buildPickers([].slice.call(e.container.querySelectorAll(`select`)),f.default),this.tooltip=new y(this.quill,this.options.bounds),e.container.querySelector(`.ql-link`)&&this.quill.keyboard.addBinding({key:`K`,shortKey:!0},function(t,n){e.handlers.link.call(e,!n.format.link)})}}]),t}(l.default);v.DEFAULTS=(0,o.default)(!0,{},l.default.DEFAULTS,{modules:{toolbar:{handlers:{link:function(e){if(e){var t=this.quill.getSelection();if(t==null||t.length==0)return;var n=this.quill.getText(t);/^\S+@\S+\.\S+$/.test(n)&&n.indexOf(`mailto:`)!==0&&(n=`mailto:`+n),this.quill.theme.tooltip.edit(`link`,n)}else this.quill.format(`link`,!1)}}}}});var y=function(e){g(t,e);function t(e,n){m(this,t);var r=h(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return r.preview=r.root.querySelector(`a.ql-preview`),r}return a(t,[{key:`listen`,value:function(){var e=this;i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`listen`,this).call(this),this.root.querySelector(`a.ql-action`).addEventListener(`click`,function(t){e.root.classList.contains(`ql-editing`)?e.save():e.edit(`link`,e.preview.textContent),t.preventDefault()}),this.root.querySelector(`a.ql-remove`).addEventListener(`click`,function(t){if(e.linkRange!=null){var n=e.linkRange;e.restoreFocus(),e.quill.formatText(n,`link`,!1,s.default.sources.USER),delete e.linkRange}t.preventDefault(),e.hide()}),this.quill.on(s.default.events.SELECTION_CHANGE,function(t,n,i){if(t!=null){if(t.length===0&&i===s.default.sources.USER){var a=r(e.quill.scroll.descendant(u.default,t.index),2),o=a[0],c=a[1];if(o!=null){e.linkRange=new d.Range(t.index-c,o.length());var l=u.default.formats(o.domNode);e.preview.textContent=l,e.preview.setAttribute(`href`,l),e.show(),e.position(e.quill.getBounds(e.linkRange));return}}else delete e.linkRange;e.hide()}})}},{key:`show`,value:function(){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`show`,this).call(this),this.root.removeAttribute(`data-mode`)}}]),t}(c.BaseTooltip);y.TEMPLATE=[`<a class="ql-preview" rel="noopener noreferrer" target="_blank" href="about:blank"></a>`,`<input type="text" data-formula="e=mc^2" data-link="https://quilljs.com" data-video="Embed URL">`,`<a class="ql-action"></a>`,`<a class="ql-remove"></a>`].join(``),t.default=v}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=F(n(29)),i=n(36),a=n(38),o=n(64),s=F(n(65)),c=F(n(66)),l=n(67),u=F(l),d=n(37),f=n(26),p=n(39),m=n(40),h=F(n(56)),g=F(n(68)),_=F(n(27)),v=F(n(69)),y=F(n(70)),b=F(n(71)),x=F(n(72)),S=F(n(73)),C=n(13),w=F(C),T=F(n(74)),E=F(n(75)),D=F(n(57)),O=F(n(41)),k=F(n(28)),A=F(n(59)),j=F(n(60)),M=F(n(61)),N=F(n(108)),P=F(n(62));function F(e){return e&&e.__esModule?e:{default:e}}r.default.register({"attributors/attribute/direction":a.DirectionAttribute,"attributors/class/align":i.AlignClass,"attributors/class/background":d.BackgroundClass,"attributors/class/color":f.ColorClass,"attributors/class/direction":a.DirectionClass,"attributors/class/font":p.FontClass,"attributors/class/size":m.SizeClass,"attributors/style/align":i.AlignStyle,"attributors/style/background":d.BackgroundStyle,"attributors/style/color":f.ColorStyle,"attributors/style/direction":a.DirectionStyle,"attributors/style/font":p.FontStyle,"attributors/style/size":m.SizeStyle},!0),r.default.register({"formats/align":i.AlignClass,"formats/direction":a.DirectionClass,"formats/indent":o.IndentClass,"formats/background":d.BackgroundStyle,"formats/color":f.ColorStyle,"formats/font":p.FontClass,"formats/size":m.SizeClass,"formats/blockquote":s.default,"formats/code-block":w.default,"formats/header":c.default,"formats/list":u.default,"formats/bold":h.default,"formats/code":C.Code,"formats/italic":g.default,"formats/link":_.default,"formats/script":v.default,"formats/strike":y.default,"formats/underline":b.default,"formats/image":x.default,"formats/video":S.default,"formats/list/item":l.ListItem,"modules/formula":T.default,"modules/syntax":E.default,"modules/toolbar":D.default,"themes/bubble":N.default,"themes/snow":P.default,"ui/icons":O.default,"ui/picker":k.default,"ui/icon-picker":j.default,"ui/color-picker":A.default,"ui/tooltip":M.default},!0),t.default=r.default}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0}),t.IndentClass=void 0;var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=o(n(0));function o(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function c(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function l(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.IndentClass=new(function(e){l(t,e);function t(){return s(this,t),c(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,[{key:`add`,value:function(e,n){if(n===`+1`||n===`-1`){var r=this.value(e)||0;n=n===`+1`?r+1:r-1}return n===0?(this.remove(e),!0):i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`add`,this).call(this,e,n)}},{key:`canAdd`,value:function(e,n){return i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`canAdd`,this).call(this,e,n)||i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`canAdd`,this).call(this,e,parseInt(n))}},{key:`value`,value:function(e){return parseInt(i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`value`,this).call(this,e))||void 0}}]),t}(a.default.Attributor.Class))(`indent`,`ql-indent`,{scope:a.default.Scope.BLOCK,whitelist:[1,2,3,4,5,6,7,8]})}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=i(n(4));function i(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function o(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function s(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var c=function(e){s(t,e);function t(){return a(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return t}(r.default);c.blotName=`blockquote`,c.tagName=`blockquote`,t.default=c}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=a(n(4));function a(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function s(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function c(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var l=function(e){c(t,e);function t(){return o(this,t),s(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,null,[{key:`formats`,value:function(e){return this.tagName.indexOf(e.tagName)+1}}]),t}(i.default);l.blotName=`header`,l.tagName=[`H1`,`H2`,`H3`,`H4`,`H5`,`H6`],t.default=l}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0}),t.default=t.ListItem=void 0;var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=c(n(0)),o=c(n(4)),s=c(n(25));function c(e){return e&&e.__esModule?e:{default:e}}function l(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function d(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function f(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var p=function(e){f(t,e);function t(){return u(this,t),d(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,[{key:`format`,value:function(e,n){e===m.blotName&&!n?this.replaceWith(a.default.create(this.statics.scope)):i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`format`,this).call(this,e,n)}},{key:`remove`,value:function(){this.prev==null&&this.next==null?this.parent.remove():i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`remove`,this).call(this)}},{key:`replaceWith`,value:function(e,n){return this.parent.isolate(this.offset(this.parent),this.length()),e===this.parent.statics.blotName?(this.parent.replaceWith(e,n),this):(this.parent.unwrap(),i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`replaceWith`,this).call(this,e,n))}}],[{key:`formats`,value:function(e){return e.tagName===this.tagName?void 0:i(t.__proto__||Object.getPrototypeOf(t),`formats`,this).call(this,e)}}]),t}(o.default);p.blotName=`list-item`,p.tagName=`LI`;var m=function(e){f(t,e),r(t,null,[{key:`create`,value:function(e){var n=e===`ordered`?`OL`:`UL`,r=i(t.__proto__||Object.getPrototypeOf(t),`create`,this).call(this,n);return(e===`checked`||e===`unchecked`)&&r.setAttribute(`data-checked`,e===`checked`),r}},{key:`formats`,value:function(e){if(e.tagName===`OL`)return`ordered`;if(e.tagName===`UL`)return e.hasAttribute(`data-checked`)?e.getAttribute(`data-checked`)===`true`?`checked`:`unchecked`:`bullet`}}]);function t(e){u(this,t);var n=d(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e)),r=function(t){if(t.target.parentNode===e){var r=n.statics.formats(e),i=a.default.find(t.target);r===`checked`?i.format(`list`,`unchecked`):r===`unchecked`&&i.format(`list`,`checked`)}};return e.addEventListener(`touchstart`,r),e.addEventListener(`mousedown`,r),n}return r(t,[{key:`format`,value:function(e,t){this.children.length>0&&this.children.tail.format(e,t)}},{key:`formats`,value:function(){return l({},this.statics.blotName,this.statics.formats(this.domNode))}},{key:`insertBefore`,value:function(e,n){if(e instanceof p)i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`insertBefore`,this).call(this,e,n);else{var r=n==null?this.length():n.offset(this),a=this.split(r);a.parent.insertBefore(e,a)}}},{key:`optimize`,value:function(e){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`optimize`,this).call(this,e);var n=this.next;n!=null&&n.prev===this&&n.statics.blotName===this.statics.blotName&&n.domNode.tagName===this.domNode.tagName&&n.domNode.getAttribute(`data-checked`)===this.domNode.getAttribute(`data-checked`)&&(n.moveChildren(this),n.remove())}},{key:`replace`,value:function(e){if(e.statics.blotName!==this.statics.blotName){var n=a.default.create(this.statics.defaultChild);e.moveChildren(n),this.appendChild(n)}i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`replace`,this).call(this,e)}}]),t}(s.default);m.blotName=`list`,m.scope=a.default.Scope.BLOCK_BLOT,m.tagName=[`OL`,`UL`],m.defaultChild=`list-item`,m.allowedChildren=[p],t.ListItem=p,t.default=m}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=i(n(56));function i(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function o(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function s(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var c=function(e){s(t,e);function t(){return a(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return t}(r.default);c.blotName=`italic`,c.tagName=[`EM`,`I`],t.default=c}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=o(n(6));function o(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function c(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function l(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var u=function(e){l(t,e);function t(){return s(this,t),c(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,null,[{key:`create`,value:function(e){return e===`super`?document.createElement(`sup`):e===`sub`?document.createElement(`sub`):i(t.__proto__||Object.getPrototypeOf(t),`create`,this).call(this,e)}},{key:`formats`,value:function(e){if(e.tagName===`SUB`)return`sub`;if(e.tagName===`SUP`)return`super`}}]),t}(a.default);u.blotName=`script`,u.tagName=[`SUB`,`SUP`],t.default=u}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=i(n(6));function i(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function o(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function s(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var c=function(e){s(t,e);function t(){return a(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return t}(r.default);c.blotName=`strike`,c.tagName=`S`,t.default=c}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=i(n(6));function i(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function o(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function s(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var c=function(e){s(t,e);function t(){return a(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return t}(r.default);c.blotName=`underline`,c.tagName=`U`,t.default=c}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=s(n(0)),o=n(27);function s(e){return e&&e.__esModule?e:{default:e}}function c(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function l(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function u(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var d=[`alt`,`height`,`width`],f=function(e){u(t,e);function t(){return c(this,t),l(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,[{key:`format`,value:function(e,n){d.indexOf(e)>-1?n?this.domNode.setAttribute(e,n):this.domNode.removeAttribute(e):i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`format`,this).call(this,e,n)}}],[{key:`create`,value:function(e){var n=i(t.__proto__||Object.getPrototypeOf(t),`create`,this).call(this,e);return typeof e==`string`&&n.setAttribute(`src`,this.sanitize(e)),n}},{key:`formats`,value:function(e){return d.reduce(function(t,n){return e.hasAttribute(n)&&(t[n]=e.getAttribute(n)),t},{})}},{key:`match`,value:function(e){return/\.(jpe?g|gif|png)$/.test(e)||/^data:image\/.+;base64/.test(e)}},{key:`sanitize`,value:function(e){return(0,o.sanitize)(e,[`http`,`https`,`data`])?e:`//:0`}},{key:`value`,value:function(e){return e.getAttribute(`src`)}}]),t}(a.default.Embed);f.blotName=`image`,f.tagName=`IMG`,t.default=f}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=n(4),o=s(n(27));function s(e){return e&&e.__esModule?e:{default:e}}function c(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function l(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function u(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var d=[`height`,`width`],f=function(e){u(t,e);function t(){return c(this,t),l(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,[{key:`format`,value:function(e,n){d.indexOf(e)>-1?n?this.domNode.setAttribute(e,n):this.domNode.removeAttribute(e):i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`format`,this).call(this,e,n)}}],[{key:`create`,value:function(e){var n=i(t.__proto__||Object.getPrototypeOf(t),`create`,this).call(this,e);return n.setAttribute(`frameborder`,`0`),n.setAttribute(`allowfullscreen`,!0),n.setAttribute(`src`,this.sanitize(e)),n}},{key:`formats`,value:function(e){return d.reduce(function(t,n){return e.hasAttribute(n)&&(t[n]=e.getAttribute(n)),t},{})}},{key:`sanitize`,value:function(e){return o.default.sanitize(e)}},{key:`value`,value:function(e){return e.getAttribute(`src`)}}]),t}(a.BlockEmbed);f.blotName=`video`,f.className=`ql-video`,f.tagName=`IFRAME`,t.default=f}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0}),t.default=t.FormulaBlot=void 0;var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=c(n(35)),o=c(n(5)),s=c(n(9));function c(e){return e&&e.__esModule?e:{default:e}}function l(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function u(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function d(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var f=function(e){d(t,e);function t(){return l(this,t),u(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,null,[{key:`create`,value:function(e){var n=i(t.__proto__||Object.getPrototypeOf(t),`create`,this).call(this,e);return typeof e==`string`&&(window.katex.render(e,n,{throwOnError:!1,errorColor:`#f00`}),n.setAttribute(`data-value`,e)),n}},{key:`value`,value:function(e){return e.getAttribute(`data-value`)}}]),t}(a.default);f.blotName=`formula`,f.className=`ql-formula`,f.tagName=`SPAN`;var p=function(e){d(t,e),r(t,null,[{key:`register`,value:function(){o.default.register(f,!0)}}]);function t(){l(this,t);var e=u(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));if(window.katex==null)throw Error(`Formula module requires KaTeX.`);return e}return t}(s.default);t.FormulaBlot=f,t.default=p}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0}),t.default=t.CodeToken=t.CodeBlock=void 0;var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=l(n(0)),o=l(n(5)),s=l(n(9)),c=l(n(13));function l(e){return e&&e.__esModule?e:{default:e}}function u(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function d(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function f(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var p=function(e){f(t,e);function t(){return u(this,t),d(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,[{key:`replaceWith`,value:function(e){this.domNode.textContent=this.domNode.textContent,this.attach(),i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`replaceWith`,this).call(this,e)}},{key:`highlight`,value:function(e){var t=this.domNode.textContent;this.cachedText!==t&&((t.trim().length>0||this.cachedText==null)&&(this.domNode.innerHTML=e(t),this.domNode.normalize(),this.attach()),this.cachedText=t)}}]),t}(c.default);p.className=`ql-syntax`;var m=new a.default.Attributor.Class(`token`,`hljs`,{scope:a.default.Scope.INLINE}),h=function(e){f(t,e),r(t,null,[{key:`register`,value:function(){o.default.register(m,!0),o.default.register(p,!0)}}]);function t(e,n){u(this,t);var r=d(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));if(typeof r.options.highlight!=`function`)throw Error(`Syntax module requires highlight.js. Please include the library on the page before Quill.`);var i=null;return r.quill.on(o.default.events.SCROLL_OPTIMIZE,function(){clearTimeout(i),i=setTimeout(function(){r.highlight(),i=null},r.options.interval)}),r.highlight(),r}return r(t,[{key:`highlight`,value:function(){var e=this;if(!this.quill.selection.composing){this.quill.update(o.default.sources.USER);var t=this.quill.getSelection();this.quill.scroll.descendants(p).forEach(function(t){t.highlight(e.options.highlight)}),this.quill.update(o.default.sources.SILENT),t!=null&&this.quill.setSelection(t,o.default.sources.SILENT)}}}]),t}(s.default);h.DEFAULTS={highlight:function(){return window.hljs==null?null:function(e){return window.hljs.highlightAuto(e).value}}(),interval:1e3},t.CodeBlock=p,t.CodeToken=m,t.default=h}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=3 x2=15 y1=9 y2=9></line> <line class=ql-stroke x1=3 x2=13 y1=14 y2=14></line> <line class=ql-stroke x1=3 x2=9 y1=4 y2=4></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=15 x2=3 y1=9 y2=9></line> <line class=ql-stroke x1=14 x2=4 y1=14 y2=14></line> <line class=ql-stroke x1=12 x2=6 y1=4 y2=4></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=15 x2=3 y1=9 y2=9></line> <line class=ql-stroke x1=15 x2=5 y1=14 y2=14></line> <line class=ql-stroke x1=15 x2=9 y1=4 y2=4></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=15 x2=3 y1=9 y2=9></line> <line class=ql-stroke x1=15 x2=3 y1=14 y2=14></line> <line class=ql-stroke x1=15 x2=3 y1=4 y2=4></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <g class="ql-fill ql-color-label"> <polygon points="6 6.868 6 6 5 6 5 7 5.942 7 6 6.868"></polygon> <rect height=1 width=1 x=4 y=4></rect> <polygon points="6.817 5 6 5 6 6 6.38 6 6.817 5"></polygon> <rect height=1 width=1 x=2 y=6></rect> <rect height=1 width=1 x=3 y=5></rect> <rect height=1 width=1 x=4 y=7></rect> <polygon points="4 11.439 4 11 3 11 3 12 3.755 12 4 11.439"></polygon> <rect height=1 width=1 x=2 y=12></rect> <rect height=1 width=1 x=2 y=9></rect> <rect height=1 width=1 x=2 y=15></rect> <polygon points="4.63 10 4 10 4 11 4.192 11 4.63 10"></polygon> <rect height=1 width=1 x=3 y=8></rect> <path d=M10.832,4.2L11,4.582V4H10.708A1.948,1.948,0,0,1,10.832,4.2Z></path> <path d=M7,4.582L7.168,4.2A1.929,1.929,0,0,1,7.292,4H7V4.582Z></path> <path d=M8,13H7.683l-0.351.8a1.933,1.933,0,0,1-.124.2H8V13Z></path> <rect height=1 width=1 x=12 y=2></rect> <rect height=1 width=1 x=11 y=3></rect> <path d=M9,3H8V3.282A1.985,1.985,0,0,1,9,3Z></path> <rect height=1 width=1 x=2 y=3></rect> <rect height=1 width=1 x=6 y=2></rect> <rect height=1 width=1 x=3 y=2></rect> <rect height=1 width=1 x=5 y=3></rect> <rect height=1 width=1 x=9 y=2></rect> <rect height=1 width=1 x=15 y=14></rect> <polygon points="13.447 10.174 13.469 10.225 13.472 10.232 13.808 11 14 11 14 10 13.37 10 13.447 10.174"></polygon> <rect height=1 width=1 x=13 y=7></rect> <rect height=1 width=1 x=15 y=5></rect> <rect height=1 width=1 x=14 y=6></rect> <rect height=1 width=1 x=15 y=8></rect> <rect height=1 width=1 x=14 y=9></rect> <path d=M3.775,14H3v1H4V14.314A1.97,1.97,0,0,1,3.775,14Z></path> <rect height=1 width=1 x=14 y=3></rect> <polygon points="12 6.868 12 6 11.62 6 12 6.868"></polygon> <rect height=1 width=1 x=15 y=2></rect> <rect height=1 width=1 x=12 y=5></rect> <rect height=1 width=1 x=13 y=4></rect> <polygon points="12.933 9 13 9 13 8 12.495 8 12.933 9"></polygon> <rect height=1 width=1 x=9 y=14></rect> <rect height=1 width=1 x=8 y=15></rect> <path d=M6,14.926V15H7V14.316A1.993,1.993,0,0,1,6,14.926Z></path> <rect height=1 width=1 x=5 y=15></rect> <path d=M10.668,13.8L10.317,13H10v1h0.792A1.947,1.947,0,0,1,10.668,13.8Z></path> <rect height=1 width=1 x=11 y=15></rect> <path d=M14.332,12.2a1.99,1.99,0,0,1,.166.8H15V12H14.245Z></path> <rect height=1 width=1 x=14 y=15></rect> <rect height=1 width=1 x=15 y=11></rect> </g> <polyline class=ql-stroke points="5.5 13 9 5 12.5 13"></polyline> <line class=ql-stroke x1=11.63 x2=6.38 y1=11 y2=11></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <rect class="ql-fill ql-stroke" height=3 width=3 x=4 y=5></rect> <rect class="ql-fill ql-stroke" height=3 width=3 x=11 y=5></rect> <path class="ql-even ql-fill ql-stroke" d=M7,8c0,4.031-3,5-3,5></path> <path class="ql-even ql-fill ql-stroke" d=M14,8c0,4.031-3,5-3,5></path> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-stroke d=M5,4H9.5A2.5,2.5,0,0,1,12,6.5v0A2.5,2.5,0,0,1,9.5,9H5A0,0,0,0,1,5,9V4A0,0,0,0,1,5,4Z></path> <path class=ql-stroke d=M5,9h5.5A2.5,2.5,0,0,1,13,11.5v0A2.5,2.5,0,0,1,10.5,14H5a0,0,0,0,1,0,0V9A0,0,0,0,1,5,9Z></path> </svg>`}),(function(e,t){e.exports=`<svg class="" viewbox="0 0 18 18"> <line class=ql-stroke x1=5 x2=13 y1=3 y2=3></line> <line class=ql-stroke x1=6 x2=9.35 y1=12 y2=3></line> <line class=ql-stroke x1=11 x2=15 y1=11 y2=15></line> <line class=ql-stroke x1=15 x2=11 y1=11 y2=15></line> <rect class=ql-fill height=1 rx=0.5 ry=0.5 width=7 x=2 y=14></rect> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class="ql-color-label ql-stroke ql-transparent" x1=3 x2=15 y1=15 y2=15></line> <polyline class=ql-stroke points="5.5 11 9 3 12.5 11"></polyline> <line class=ql-stroke x1=11.63 x2=6.38 y1=9 y2=9></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <polygon class="ql-stroke ql-fill" points="3 11 5 9 3 7 3 11"></polygon> <line class="ql-stroke ql-fill" x1=15 x2=11 y1=4 y2=4></line> <path class=ql-fill d=M11,3a3,3,0,0,0,0,6h1V3H11Z></path> <rect class=ql-fill height=11 width=1 x=11 y=4></rect> <rect class=ql-fill height=11 width=1 x=13 y=4></rect> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <polygon class="ql-stroke ql-fill" points="15 12 13 10 15 8 15 12"></polygon> <line class="ql-stroke ql-fill" x1=9 x2=5 y1=4 y2=4></line> <path class=ql-fill d=M5,3A3,3,0,0,0,5,9H6V3H5Z></path> <rect class=ql-fill height=11 width=1 x=5 y=4></rect> <rect class=ql-fill height=11 width=1 x=7 y=4></rect> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M14,16H4a1,1,0,0,1,0-2H14A1,1,0,0,1,14,16Z /> <path class=ql-fill d=M14,4H4A1,1,0,0,1,4,2H14A1,1,0,0,1,14,4Z /> <rect class=ql-fill x=3 y=6 width=12 height=6 rx=1 ry=1 /> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M13,16H5a1,1,0,0,1,0-2h8A1,1,0,0,1,13,16Z /> <path class=ql-fill d=M13,4H5A1,1,0,0,1,5,2h8A1,1,0,0,1,13,4Z /> <rect class=ql-fill x=2 y=6 width=14 height=6 rx=1 ry=1 /> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M15,8H13a1,1,0,0,1,0-2h2A1,1,0,0,1,15,8Z /> <path class=ql-fill d=M15,12H13a1,1,0,0,1,0-2h2A1,1,0,0,1,15,12Z /> <path class=ql-fill d=M15,16H5a1,1,0,0,1,0-2H15A1,1,0,0,1,15,16Z /> <path class=ql-fill d=M15,4H5A1,1,0,0,1,5,2H15A1,1,0,0,1,15,4Z /> <rect class=ql-fill x=2 y=6 width=8 height=6 rx=1 ry=1 /> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M5,8H3A1,1,0,0,1,3,6H5A1,1,0,0,1,5,8Z /> <path class=ql-fill d=M5,12H3a1,1,0,0,1,0-2H5A1,1,0,0,1,5,12Z /> <path class=ql-fill d=M13,16H3a1,1,0,0,1,0-2H13A1,1,0,0,1,13,16Z /> <path class=ql-fill d=M13,4H3A1,1,0,0,1,3,2H13A1,1,0,0,1,13,4Z /> <rect class=ql-fill x=8 y=6 width=8 height=6 rx=1 ry=1 transform="translate(24 18) rotate(-180)"/> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M11.759,2.482a2.561,2.561,0,0,0-3.53.607A7.656,7.656,0,0,0,6.8,6.2C6.109,9.188,5.275,14.677,4.15,14.927a1.545,1.545,0,0,0-1.3-.933A0.922,0.922,0,0,0,2,15.036S1.954,16,4.119,16s3.091-2.691,3.7-5.553c0.177-.826.36-1.726,0.554-2.6L8.775,6.2c0.381-1.421.807-2.521,1.306-2.676a1.014,1.014,0,0,0,1.02.56A0.966,0.966,0,0,0,11.759,2.482Z></path> <rect class=ql-fill height=1.6 rx=0.8 ry=0.8 width=5 x=5.15 y=6.2></rect> <path class=ql-fill d=M13.663,12.027a1.662,1.662,0,0,1,.266-0.276q0.193,0.069.456,0.138a2.1,2.1,0,0,0,.535.069,1.075,1.075,0,0,0,.767-0.3,1.044,1.044,0,0,0,.314-0.8,0.84,0.84,0,0,0-.238-0.619,0.8,0.8,0,0,0-.594-0.239,1.154,1.154,0,0,0-.781.3,4.607,4.607,0,0,0-.781,1q-0.091.15-.218,0.346l-0.246.38c-0.068-.288-0.137-0.582-0.212-0.885-0.459-1.847-2.494-.984-2.941-0.8-0.482.2-.353,0.647-0.094,0.529a0.869,0.869,0,0,1,1.281.585c0.217,0.751.377,1.436,0.527,2.038a5.688,5.688,0,0,1-.362.467,2.69,2.69,0,0,1-.264.271q-0.221-.08-0.471-0.147a2.029,2.029,0,0,0-.522-0.066,1.079,1.079,0,0,0-.768.3A1.058,1.058,0,0,0,9,15.131a0.82,0.82,0,0,0,.832.852,1.134,1.134,0,0,0,.787-0.3,5.11,5.11,0,0,0,.776-0.993q0.141-.219.215-0.34c0.046-.076.122-0.194,0.223-0.346a2.786,2.786,0,0,0,.918,1.726,2.582,2.582,0,0,0,2.376-.185c0.317-.181.212-0.565,0-0.494A0.807,0.807,0,0,1,14.176,15a5.159,5.159,0,0,1-.913-2.446l0,0Q13.487,12.24,13.663,12.027Z></path> </svg>`}),(function(e,t){e.exports=`<svg viewBox="0 0 18 18"> <path class=ql-fill d=M10,4V14a1,1,0,0,1-2,0V10H3v4a1,1,0,0,1-2,0V4A1,1,0,0,1,3,4V8H8V4a1,1,0,0,1,2,0Zm6.06787,9.209H14.98975V7.59863a.54085.54085,0,0,0-.605-.60547h-.62744a1.01119,1.01119,0,0,0-.748.29688L11.645,8.56641a.5435.5435,0,0,0-.022.8584l.28613.30762a.53861.53861,0,0,0,.84717.0332l.09912-.08789a1.2137,1.2137,0,0,0,.2417-.35254h.02246s-.01123.30859-.01123.60547V13.209H12.041a.54085.54085,0,0,0-.605.60547v.43945a.54085.54085,0,0,0,.605.60547h4.02686a.54085.54085,0,0,0,.605-.60547v-.43945A.54085.54085,0,0,0,16.06787,13.209Z /> </svg>`}),(function(e,t){e.exports=`<svg viewBox="0 0 18 18"> <path class=ql-fill d=M16.73975,13.81445v.43945a.54085.54085,0,0,1-.605.60547H11.855a.58392.58392,0,0,1-.64893-.60547V14.0127c0-2.90527,3.39941-3.42187,3.39941-4.55469a.77675.77675,0,0,0-.84717-.78125,1.17684,1.17684,0,0,0-.83594.38477c-.2749.26367-.561.374-.85791.13184l-.4292-.34082c-.30811-.24219-.38525-.51758-.1543-.81445a2.97155,2.97155,0,0,1,2.45361-1.17676,2.45393,2.45393,0,0,1,2.68408,2.40918c0,2.45312-3.1792,2.92676-3.27832,3.93848h2.79443A.54085.54085,0,0,1,16.73975,13.81445ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z /> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=7 x2=13 y1=4 y2=4></line> <line class=ql-stroke x1=5 x2=11 y1=14 y2=14></line> <line class=ql-stroke x1=8 x2=10 y1=14 y2=4></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <rect class=ql-stroke height=10 width=12 x=3 y=4></rect> <circle class=ql-fill cx=6 cy=7 r=1></circle> <polyline class="ql-even ql-fill" points="5 12 5 11 7 9 8 10 11 7 13 9 13 12 5 12"></polyline> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=3 x2=15 y1=14 y2=14></line> <line class=ql-stroke x1=3 x2=15 y1=4 y2=4></line> <line class=ql-stroke x1=9 x2=15 y1=9 y2=9></line> <polyline class="ql-fill ql-stroke" points="3 7 3 11 5 9 3 7"></polyline> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=3 x2=15 y1=14 y2=14></line> <line class=ql-stroke x1=3 x2=15 y1=4 y2=4></line> <line class=ql-stroke x1=9 x2=15 y1=9 y2=9></line> <polyline class=ql-stroke points="5 7 5 11 3 9 5 7"></polyline> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=7 x2=11 y1=7 y2=11></line> <path class="ql-even ql-stroke" d=M8.9,4.577a3.476,3.476,0,0,1,.36,4.679A3.476,3.476,0,0,1,4.577,8.9C3.185,7.5,2.035,6.4,4.217,4.217S7.5,3.185,8.9,4.577Z></path> <path class="ql-even ql-stroke" d=M13.423,9.1a3.476,3.476,0,0,0-4.679-.36,3.476,3.476,0,0,0,.36,4.679c1.392,1.392,2.5,2.542,4.679.36S14.815,10.5,13.423,9.1Z></path> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=7 x2=15 y1=4 y2=4></line> <line class=ql-stroke x1=7 x2=15 y1=9 y2=9></line> <line class=ql-stroke x1=7 x2=15 y1=14 y2=14></line> <line class="ql-stroke ql-thin" x1=2.5 x2=4.5 y1=5.5 y2=5.5></line> <path class=ql-fill d=M3.5,6A0.5,0.5,0,0,1,3,5.5V3.085l-0.276.138A0.5,0.5,0,0,1,2.053,3c-0.124-.247-0.023-0.324.224-0.447l1-.5A0.5,0.5,0,0,1,4,2.5v3A0.5,0.5,0,0,1,3.5,6Z></path> <path class="ql-stroke ql-thin" d=M4.5,10.5h-2c0-.234,1.85-1.076,1.85-2.234A0.959,0.959,0,0,0,2.5,8.156></path> <path class="ql-stroke ql-thin" d=M2.5,14.846a0.959,0.959,0,0,0,1.85-.109A0.7,0.7,0,0,0,3.75,14a0.688,0.688,0,0,0,.6-0.736,0.959,0.959,0,0,0-1.85-.109></path> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=6 x2=15 y1=4 y2=4></line> <line class=ql-stroke x1=6 x2=15 y1=9 y2=9></line> <line class=ql-stroke x1=6 x2=15 y1=14 y2=14></line> <line class=ql-stroke x1=3 x2=3 y1=4 y2=4></line> <line class=ql-stroke x1=3 x2=3 y1=9 y2=9></line> <line class=ql-stroke x1=3 x2=3 y1=14 y2=14></line> </svg>`}),(function(e,t){e.exports=`<svg class="" viewbox="0 0 18 18"> <line class=ql-stroke x1=9 x2=15 y1=4 y2=4></line> <polyline class=ql-stroke points="3 4 4 5 6 3"></polyline> <line class=ql-stroke x1=9 x2=15 y1=14 y2=14></line> <polyline class=ql-stroke points="3 14 4 15 6 13"></polyline> <line class=ql-stroke x1=9 x2=15 y1=9 y2=9></line> <polyline class=ql-stroke points="3 9 4 10 6 8"></polyline> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M15.5,15H13.861a3.858,3.858,0,0,0,1.914-2.975,1.8,1.8,0,0,0-1.6-1.751A1.921,1.921,0,0,0,12.021,11.7a0.50013,0.50013,0,1,0,.957.291h0a0.914,0.914,0,0,1,1.053-.725,0.81,0.81,0,0,1,.744.762c0,1.076-1.16971,1.86982-1.93971,2.43082A1.45639,1.45639,0,0,0,12,15.5a0.5,0.5,0,0,0,.5.5h3A0.5,0.5,0,0,0,15.5,15Z /> <path class=ql-fill d=M9.65,5.241a1,1,0,0,0-1.409.108L6,7.964,3.759,5.349A1,1,0,0,0,2.192,6.59178Q2.21541,6.6213,2.241,6.649L4.684,9.5,2.241,12.35A1,1,0,0,0,3.71,13.70722q0.02557-.02768.049-0.05722L6,11.036,8.241,13.65a1,1,0,1,0,1.567-1.24277Q9.78459,12.3777,9.759,12.35L7.316,9.5,9.759,6.651A1,1,0,0,0,9.65,5.241Z /> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M15.5,7H13.861a4.015,4.015,0,0,0,1.914-2.975,1.8,1.8,0,0,0-1.6-1.751A1.922,1.922,0,0,0,12.021,3.7a0.5,0.5,0,1,0,.957.291,0.917,0.917,0,0,1,1.053-.725,0.81,0.81,0,0,1,.744.762c0,1.077-1.164,1.925-1.934,2.486A1.423,1.423,0,0,0,12,7.5a0.5,0.5,0,0,0,.5.5h3A0.5,0.5,0,0,0,15.5,7Z /> <path class=ql-fill d=M9.651,5.241a1,1,0,0,0-1.41.108L6,7.964,3.759,5.349a1,1,0,1,0-1.519,1.3L4.683,9.5,2.241,12.35a1,1,0,1,0,1.519,1.3L6,11.036,8.241,13.65a1,1,0,0,0,1.519-1.3L7.317,9.5,9.759,6.651A1,1,0,0,0,9.651,5.241Z /> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class="ql-stroke ql-thin" x1=15.5 x2=2.5 y1=8.5 y2=9.5></line> <path class=ql-fill d=M9.007,8C6.542,7.791,6,7.519,6,6.5,6,5.792,7.283,5,9,5c1.571,0,2.765.679,2.969,1.309a1,1,0,0,0,1.9-.617C13.356,4.106,11.354,3,9,3,6.2,3,4,4.538,4,6.5a3.2,3.2,0,0,0,.5,1.843Z></path> <path class=ql-fill d=M8.984,10C11.457,10.208,12,10.479,12,11.5c0,0.708-1.283,1.5-3,1.5-1.571,0-2.765-.679-2.969-1.309a1,1,0,1,0-1.9.617C4.644,13.894,6.646,15,9,15c2.8,0,5-1.538,5-3.5a3.2,3.2,0,0,0-.5-1.843Z></path> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-stroke d=M5,3V9a4.012,4.012,0,0,0,4,4H9a4.012,4.012,0,0,0,4-4V3></path> <rect class=ql-fill height=1 rx=0.5 ry=0.5 width=12 x=3 y=15></rect> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <rect class=ql-stroke height=12 width=12 x=3 y=3></rect> <rect class=ql-fill height=12 width=1 x=5 y=3></rect> <rect class=ql-fill height=12 width=1 x=12 y=3></rect> <rect class=ql-fill height=2 width=8 x=5 y=8></rect> <rect class=ql-fill height=1 width=3 x=3 y=5></rect> <rect class=ql-fill height=1 width=3 x=3 y=7></rect> <rect class=ql-fill height=1 width=3 x=3 y=10></rect> <rect class=ql-fill height=1 width=3 x=3 y=12></rect> <rect class=ql-fill height=1 width=3 x=12 y=5></rect> <rect class=ql-fill height=1 width=3 x=12 y=7></rect> <rect class=ql-fill height=1 width=3 x=12 y=10></rect> <rect class=ql-fill height=1 width=3 x=12 y=12></rect> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <polygon class=ql-stroke points="7 11 9 13 11 11 7 11"></polygon> <polygon class=ql-stroke points="7 7 9 5 11 7 7 7"></polygon> </svg>`}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0}),t.default=t.BubbleTooltip=void 0;var r=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=d(n(3)),o=d(n(8)),s=n(43),c=d(s),l=n(15),u=d(n(41));function d(e){return e&&e.__esModule?e:{default:e}}function f(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function p(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function m(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var h=[[`bold`,`italic`,`link`],[{header:1},{header:2},`blockquote`]],g=function(e){m(t,e);function t(e,n){f(this,t),n.modules.toolbar!=null&&n.modules.toolbar.container==null&&(n.modules.toolbar.container=h);var r=p(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return r.quill.container.classList.add(`ql-bubble`),r}return i(t,[{key:`extendToolbar`,value:function(e){this.tooltip=new _(this.quill,this.options.bounds),this.tooltip.root.appendChild(e.container),this.buildButtons([].slice.call(e.container.querySelectorAll(`button`)),u.default),this.buildPickers([].slice.call(e.container.querySelectorAll(`select`)),u.default)}}]),t}(c.default);g.DEFAULTS=(0,a.default)(!0,{},c.default.DEFAULTS,{modules:{toolbar:{handlers:{link:function(e){e?this.quill.theme.tooltip.edit():this.quill.format(`link`,!1)}}}}});var _=function(e){m(t,e);function t(e,n){f(this,t);var r=p(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return r.quill.on(o.default.events.EDITOR_CHANGE,function(e,t,n,i){if(e===o.default.events.SELECTION_CHANGE)if(t!=null&&t.length>0&&i===o.default.sources.USER){r.show(),r.root.style.left=`0px`,r.root.style.width=``,r.root.style.width=r.root.offsetWidth+`px`;var a=r.quill.getLines(t.index,t.length);if(a.length===1)r.position(r.quill.getBounds(t));else{var s=a[a.length-1],c=r.quill.getIndex(s),u=Math.min(s.length()-1,t.index+t.length-c),d=r.quill.getBounds(new l.Range(c,u));r.position(d)}}else document.activeElement!==r.textbox&&r.quill.hasFocus()&&r.hide()}),r}return i(t,[{key:`listen`,value:function(){var e=this;r(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`listen`,this).call(this),this.root.querySelector(`.ql-close`).addEventListener(`click`,function(){e.root.classList.remove(`ql-editing`)}),this.quill.on(o.default.events.SCROLL_OPTIMIZE,function(){setTimeout(function(){if(!e.root.classList.contains(`ql-hidden`)){var t=e.quill.getSelection();t!=null&&e.position(e.quill.getBounds(t))}},1)})}},{key:`cancel`,value:function(){this.show()}},{key:`position`,value:function(e){var n=r(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`position`,this).call(this,e),i=this.root.querySelector(`.ql-tooltip-arrow`);if(i.style.marginLeft=``,n===0)return n;i.style.marginLeft=-1*n-i.offsetWidth/2+`px`}}]),t}(s.BaseTooltip);_.TEMPLATE=[`<span class="ql-tooltip-arrow"></span>`,`<div class="ql-tooltip-editor">`,`<input type="text" data-formula="e=mc^2" data-link="https://quilljs.com" data-video="Embed URL">`,`<a class="ql-close"></a>`,`</div>`].join(``),t.BubbleTooltip=_,t.default=g}),(function(e,t,n){e.exports=n(63)})]).default})})),mv=r(((e,t)=>{(function(n){var r=typeof e==`object`&&e&&!e.nodeType&&e,i=typeof t==`object`&&t&&!t.nodeType&&t,a=typeof global==`object`&&global;(a.global===a||a.window===a||a.self===a)&&(n=a);var o,s=2147483647,c=36,l=1,u=26,d=38,f=700,p=72,m=128,h=`-`,g=/^xn--/,_=/[^\x20-\x7E]/,v=/[\x2E\u3002\uFF0E\uFF61]/g,y={overflow:`Overflow: input needs wider integers to process`,"not-basic":`Illegal input >= 0x80 (not a basic code point)`,"invalid-input":`Invalid input`},b=c-l,x=Math.floor,S=String.fromCharCode,C;function w(e){throw RangeError(y[e])}function T(e,t){for(var n=e.length,r=[];n--;)r[n]=t(e[n]);return r}function E(e,t){var n=e.split(`@`),r=``;n.length>1&&(r=n[0]+`@`,e=n[1]),e=e.replace(v,`.`);var i=T(e.split(`.`),t).join(`.`);return r+i}function D(e){for(var t=[],n=0,r=e.length,i,a;n<r;)i=e.charCodeAt(n++),i>=55296&&i<=56319&&n<r?(a=e.charCodeAt(n++),(a&64512)==56320?t.push(((i&1023)<<10)+(a&1023)+65536):(t.push(i),n--)):t.push(i);return t}function O(e){return T(e,function(e){var t=``;return e>65535&&(e-=65536,t+=S(e>>>10&1023|55296),e=56320|e&1023),t+=S(e),t}).join(``)}function k(e){return e-48<10?e-22:e-65<26?e-65:e-97<26?e-97:c}function A(e,t){return e+22+75*(e<26)-((t!=0)<<5)}function j(e,t,n){var r=0;for(e=n?x(e/f):e>>1,e+=x(e/t);e>b*u>>1;r+=c)e=x(e/b);return x(r+(b+1)*e/(e+d))}function M(e){var t=[],n=e.length,r,i=0,a=m,o=p,d=e.lastIndexOf(h),f,g,_,v,y,b,S,C;for(d<0&&(d=0),f=0;f<d;++f)e.charCodeAt(f)>=128&&w(`not-basic`),t.push(e.charCodeAt(f));for(g=d>0?d+1:0;g<n;){for(_=i,v=1,y=c;g>=n&&w(`invalid-input`),b=k(e.charCodeAt(g++)),(b>=c||b>x((s-i)/v))&&w(`overflow`),i+=b*v,S=y<=o?l:y>=o+u?u:y-o,!(b<S);y+=c)C=c-S,v>x(s/C)&&w(`overflow`),v*=C;r=t.length+1,o=j(i-_,r,_==0),x(i/r)>s-a&&w(`overflow`),a+=x(i/r),i%=r,t.splice(i++,0,a)}return O(t)}function N(e){var t,n,r,i,a,o,d,f,g,_,v,y=[],b,C,T,E;for(e=D(e),b=e.length,t=m,n=0,a=p,o=0;o<b;++o)v=e[o],v<128&&y.push(S(v));for(r=i=y.length,i&&y.push(h);r<b;){for(d=s,o=0;o<b;++o)v=e[o],v>=t&&v<d&&(d=v);for(C=r+1,d-t>x((s-n)/C)&&w(`overflow`),n+=(d-t)*C,t=d,o=0;o<b;++o)if(v=e[o],v<t&&++n>s&&w(`overflow`),v==t){for(f=n,g=c;_=g<=a?l:g>=a+u?u:g-a,!(f<_);g+=c)E=f-_,T=c-_,y.push(S(A(_+E%T,0))),f=x(E/T);y.push(S(A(f,0))),a=j(n,C,r==i),n=0,++r}++n,++t}return y.join(``)}function P(e){return E(e,function(e){return g.test(e)?M(e.slice(4).toLowerCase()):e})}function F(e){return E(e,function(e){return _.test(e)?`xn--`+N(e):e})}if(o={version:`1.4.1`,ucs2:{decode:D,encode:O},decode:M,encode:N,toASCII:F,toUnicode:P},typeof define==`function`&&typeof define.amd==`object`&&define.amd)define(`punycode`,function(){return o});else if(r&&i)if(t.exports==r)i.exports=o;else for(C in o)o.hasOwnProperty(C)&&(r[C]=o[C]);else n.punycode=o})(e)})),hv=r(((e,t)=>{t.exports=TypeError})),gv=r(((e,t)=>{t.exports={}})),_v=r(((e,t)=>{var n=typeof Map==`function`&&Map.prototype,r=Object.getOwnPropertyDescriptor&&n?Object.getOwnPropertyDescriptor(Map.prototype,`size`):null,i=n&&r&&typeof r.get==`function`?r.get:null,a=n&&Map.prototype.forEach,o=typeof Set==`function`&&Set.prototype,s=Object.getOwnPropertyDescriptor&&o?Object.getOwnPropertyDescriptor(Set.prototype,`size`):null,c=o&&s&&typeof s.get==`function`?s.get:null,l=o&&Set.prototype.forEach,u=typeof WeakMap==`function`&&WeakMap.prototype?WeakMap.prototype.has:null,d=typeof WeakSet==`function`&&WeakSet.prototype?WeakSet.prototype.has:null,f=typeof WeakRef==`function`&&WeakRef.prototype?WeakRef.prototype.deref:null,p=Boolean.prototype.valueOf,m=Object.prototype.toString,h=Function.prototype.toString,g=String.prototype.match,_=String.prototype.slice,v=String.prototype.replace,y=String.prototype.toUpperCase,b=String.prototype.toLowerCase,x=RegExp.prototype.test,S=Array.prototype.concat,C=Array.prototype.join,w=Array.prototype.slice,T=Math.floor,E=typeof BigInt==`function`?BigInt.prototype.valueOf:null,D=Object.getOwnPropertySymbols,O=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?Symbol.prototype.toString:null,k=typeof Symbol==`function`&&typeof Symbol.iterator==`object`,A=typeof Symbol==`function`&&Symbol.toStringTag&&(typeof Symbol.toStringTag===k||`symbol`)?Symbol.toStringTag:null,j=Object.prototype.propertyIsEnumerable,M=(typeof Reflect==`function`?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function N(e,t){if(e===1/0||e===-1/0||e!==e||e&&e>-1e3&&e<1e3||x.call(/e/,t))return t;var n=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof e==`number`){var r=e<0?-T(-e):T(e);if(r!==e){var i=String(r),a=_.call(t,i.length+1);return v.call(i,n,`$&_`)+`.`+v.call(v.call(a,/([0-9]{3})/g,`$&_`),/_$/,``)}}return v.call(t,n,`$&_`)}var P=gv(),F=P.custom,ee=fe(F)?F:null,te={__proto__:null,double:`"`,single:`'`},ne={__proto__:null,double:/(["\\])/g,single:/(['\\])/g};t.exports=function e(t,n,r,o){var s=n||{};if(he(s,`quoteStyle`)&&!he(te,s.quoteStyle))throw TypeError(`option "quoteStyle" must be "single" or "double"`);if(he(s,`maxStringLength`)&&(typeof s.maxStringLength==`number`?s.maxStringLength<0&&s.maxStringLength!==1/0:s.maxStringLength!==null))throw TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var u=he(s,`customInspect`)?s.customInspect:!0;if(typeof u!=`boolean`&&u!==`symbol`)throw TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(he(s,`indent`)&&s.indent!==null&&s.indent!==` `&&!(parseInt(s.indent,10)===s.indent&&s.indent>0))throw TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(he(s,`numericSeparator`)&&typeof s.numericSeparator!=`boolean`)throw TypeError('option "numericSeparator", if provided, must be `true` or `false`');var d=s.numericSeparator;if(t===void 0)return`undefined`;if(t===null)return`null`;if(typeof t==`boolean`)return t?`true`:`false`;if(typeof t==`string`)return Te(t,s);if(typeof t==`number`){if(t===0)return 1/0/t>0?`0`:`-0`;var f=String(t);return d?N(t,f):f}if(typeof t==`bigint`){var m=String(t)+`n`;return d?N(t,m):m}var h=s.depth===void 0?5:s.depth;if(r===void 0&&(r=0),r>=h&&h>0&&typeof t==`object`)return ae(t)?`[Array]`:`[Object]`;var g=je(s,r);if(o===void 0)o=[];else if(ve(o,t)>=0)return`[Circular]`;function y(t,n,i){if(n&&(o=w.call(o),o.push(n)),i){var a={depth:s.depth};return he(s,`quoteStyle`)&&(a.quoteStyle=s.quoteStyle),e(t,a,r+1,o)}return e(t,s,r+1,o)}if(typeof t==`function`&&!se(t)){var x=_e(t),T=Ne(t,y);return`[Function`+(x?`: `+x:` (anonymous)`)+`]`+(T.length>0?` { `+C.call(T,`, `)+` }`:``)}if(fe(t)){var D=k?v.call(String(t),/^(Symbol\(.*\))_[^)]*$/,`$1`):O.call(t);return typeof t==`object`&&!k?De(D):D}if(we(t)){for(var F=`<`+b.call(String(t.nodeName)),ne=t.attributes||[],I=0;I<ne.length;I++)F+=` `+ne[I].name+`=`+re(ie(ne[I].value),`double`,s);return F+=`>`,t.childNodes&&t.childNodes.length&&(F+=`...`),F+=`</`+b.call(String(t.nodeName))+`>`,F}if(ae(t)){if(t.length===0)return`[]`;var me=Ne(t,y);return g&&!Ae(me)?`[`+Me(me,g)+`]`:`[ `+C.call(me,`, `)+` ]`}if(ce(t)){var Ee=Ne(t,y);return!(`cause`in Error.prototype)&&`cause`in t&&!j.call(t,`cause`)?`{ [`+String(t)+`] `+C.call(S.call(`[cause]: `+y(t.cause),Ee),`, `)+` }`:Ee.length===0?`[`+String(t)+`]`:`{ [`+String(t)+`] `+C.call(Ee,`, `)+` }`}if(typeof t==`object`&&u){if(ee&&typeof t[ee]==`function`&&P)return P(t,{depth:h-r});if(u!==`symbol`&&typeof t.inspect==`function`)return t.inspect()}if(ye(t)){var Pe=[];return a&&a.call(t,function(e,n){Pe.push(y(n,t,!0)+` => `+y(e,t))}),ke(`Map`,i.call(t),Pe,g)}if(Se(t)){var Fe=[];return l&&l.call(t,function(e){Fe.push(y(e,t))}),ke(`Set`,c.call(t),Fe,g)}if(be(t))return Oe(`WeakMap`);if(Ce(t))return Oe(`WeakSet`);if(xe(t))return Oe(`WeakRef`);if(ue(t))return De(y(Number(t)));if(pe(t))return De(y(E.call(t)));if(de(t))return De(p.call(t));if(le(t))return De(y(String(t)));if(typeof window<`u`&&t===window)return`{ [object Window] }`;if(typeof globalThis<`u`&&t===globalThis||typeof global<`u`&&t===global)return`{ [object globalThis] }`;if(!oe(t)&&!se(t)){var Ie=Ne(t,y),Le=M?M(t)===Object.prototype:t instanceof Object||t.constructor===Object,Re=t instanceof Object?``:`null prototype`,ze=!Le&&A&&Object(t)===t&&A in t?_.call(ge(t),8,-1):Re?`Object`:``,Be=(Le||typeof t.constructor!=`function`?``:t.constructor.name?t.constructor.name+` `:``)+(ze||Re?`[`+C.call(S.call([],ze||[],Re||[]),`: `)+`] `:``);return Ie.length===0?Be+`{}`:g?Be+`{`+Me(Ie,g)+`}`:Be+`{ `+C.call(Ie,`, `)+` }`}return String(t)};function re(e,t,n){var r=te[n.quoteStyle||t];return r+e+r}function ie(e){return v.call(String(e),/"/g,`&quot;`)}function I(e){return!A||!(typeof e==`object`&&(A in e||e[A]!==void 0))}function ae(e){return ge(e)===`[object Array]`&&I(e)}function oe(e){return ge(e)===`[object Date]`&&I(e)}function se(e){return ge(e)===`[object RegExp]`&&I(e)}function ce(e){return ge(e)===`[object Error]`&&I(e)}function le(e){return ge(e)===`[object String]`&&I(e)}function ue(e){return ge(e)===`[object Number]`&&I(e)}function de(e){return ge(e)===`[object Boolean]`&&I(e)}function fe(e){if(k)return e&&typeof e==`object`&&e instanceof Symbol;if(typeof e==`symbol`)return!0;if(!e||typeof e!=`object`||!O)return!1;try{return O.call(e),!0}catch{}return!1}function pe(e){if(!e||typeof e!=`object`||!E)return!1;try{return E.call(e),!0}catch{}return!1}var me=Object.prototype.hasOwnProperty||function(e){return e in this};function he(e,t){return me.call(e,t)}function ge(e){return m.call(e)}function _e(e){if(e.name)return e.name;var t=g.call(h.call(e),/^function\s*([\w$]+)/);return t?t[1]:null}function ve(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1}function ye(e){if(!i||!e||typeof e!=`object`)return!1;try{i.call(e);try{c.call(e)}catch{return!0}return e instanceof Map}catch{}return!1}function be(e){if(!u||!e||typeof e!=`object`)return!1;try{u.call(e,u);try{d.call(e,d)}catch{return!0}return e instanceof WeakMap}catch{}return!1}function xe(e){if(!f||!e||typeof e!=`object`)return!1;try{return f.call(e),!0}catch{}return!1}function Se(e){if(!c||!e||typeof e!=`object`)return!1;try{c.call(e);try{i.call(e)}catch{return!0}return e instanceof Set}catch{}return!1}function Ce(e){if(!d||!e||typeof e!=`object`)return!1;try{d.call(e,d);try{u.call(e,u)}catch{return!0}return e instanceof WeakSet}catch{}return!1}function we(e){return!e||typeof e!=`object`?!1:typeof HTMLElement<`u`&&e instanceof HTMLElement?!0:typeof e.nodeName==`string`&&typeof e.getAttribute==`function`}function Te(e,t){if(e.length>t.maxStringLength){var n=e.length-t.maxStringLength,r=`... `+n+` more character`+(n>1?`s`:``);return Te(_.call(e,0,t.maxStringLength),t)+r}var i=ne[t.quoteStyle||`single`];return i.lastIndex=0,re(v.call(v.call(e,i,`\\$1`),/[\x00-\x1f]/g,Ee),`single`,t)}function Ee(e){var t=e.charCodeAt(0),n={8:`b`,9:`t`,10:`n`,12:`f`,13:`r`}[t];return n?`\\`+n:`\\x`+(t<16?`0`:``)+y.call(t.toString(16))}function De(e){return`Object(`+e+`)`}function Oe(e){return e+` { ? }`}function ke(e,t,n,r){var i=r?Me(n,r):C.call(n,`, `);return e+` (`+t+`) {`+i+`}`}function Ae(e){for(var t=0;t<e.length;t++)if(ve(e[t],`
89
+ `)}return t}function oe(e,t){var n={},r=e.style||{};return r.fontStyle&&j(e).fontStyle===`italic`&&(n.italic=!0),r.fontWeight&&(j(e).fontWeight.startsWith(`bold`)||parseInt(j(e).fontWeight)>=700)&&(n.bold=!0),Object.keys(n).length>0&&(t=A(t,n)),parseFloat(r.textIndent||0)>0&&(t=new s.default().insert(` `).concat(t)),t}function se(e,t){var n=e.data;if(e.parentNode.tagName===`O:P`)return t.insert(n.trim());if(n.trim().length===0&&e.parentNode.classList.contains(`ql-clipboard`))return t;if(!j(e.parentNode).whiteSpace.startsWith(`pre`)){var r=function(e,t){return t=t.replace(/[^\u00a0]/g,``),t.length<1&&e?` `:t};n=n.replace(/\r\n/g,` `).replace(/\n/g,` `),n=n.replace(/\s\s+/g,r.bind(r,!0)),(e.previousSibling==null&&N(e.parentNode)||e.previousSibling!=null&&N(e.previousSibling))&&(n=n.replace(/^\s+/,r.bind(r,!1))),(e.nextSibling==null&&N(e.parentNode)||e.nextSibling!=null&&N(e.nextSibling))&&(n=n.replace(/\s+$/,r.bind(r,!1)))}return t.insert(n)}t.default=k,t.matchAttributor=ee,t.matchBlot=te,t.matchNewline=I,t.matchSpacing=ae,t.matchText=se}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=o(n(6));function o(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function c(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function l(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var u=function(e){l(t,e);function t(){return s(this,t),c(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,[{key:`optimize`,value:function(e){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`optimize`,this).call(this,e),this.domNode.tagName!==this.statics.tagName[0]&&this.replaceWith(this.statics.blotName)}}],[{key:`create`,value:function(){return i(t.__proto__||Object.getPrototypeOf(t),`create`,this).call(this)}},{key:`formats`,value:function(){return!0}}]),t}(a.default);u.blotName=`bold`,u.tagName=[`STRONG`,`B`],t.default=u}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0}),t.addControls=t.default=void 0;var r=function(){function e(e,t){var n=[],r=!0,i=!1,a=void 0;try{for(var o=e[Symbol.iterator](),s;!(r=(s=o.next()).done)&&(n.push(s.value),!(t&&n.length===t));r=!0);}catch(e){i=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(i)throw a}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw TypeError(`Invalid attempt to destructure non-iterable instance`)}}(),i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=u(n(2)),o=u(n(0)),s=u(n(5)),c=u(n(10)),l=u(n(9));function u(e){return e&&e.__esModule?e:{default:e}}function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function p(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function m(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var h=(0,c.default)(`quill:toolbar`),g=function(e){m(t,e);function t(e,n){f(this,t);var i=p(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));if(Array.isArray(i.options.container)){var a=document.createElement(`div`);v(a,i.options.container),e.container.parentNode.insertBefore(a,e.container),i.container=a}else typeof i.options.container==`string`?i.container=document.querySelector(i.options.container):i.container=i.options.container;if(!(i.container instanceof HTMLElement)){var o;return o=h.error(`Container required for toolbar`,i.options),p(i,o)}return i.container.classList.add(`ql-toolbar`),i.controls=[],i.handlers={},Object.keys(i.options.handlers).forEach(function(e){i.addHandler(e,i.options.handlers[e])}),[].forEach.call(i.container.querySelectorAll(`button, select`),function(e){i.attach(e)}),i.quill.on(s.default.events.EDITOR_CHANGE,function(e,t){e===s.default.events.SELECTION_CHANGE&&i.update(t)}),i.quill.on(s.default.events.SCROLL_OPTIMIZE,function(){var e=r(i.quill.selection.getRange(),1)[0];i.update(e)}),i}return i(t,[{key:`addHandler`,value:function(e,t){this.handlers[e]=t}},{key:`attach`,value:function(e){var t=this,n=[].find.call(e.classList,function(e){return e.indexOf(`ql-`)===0});if(n){if(n=n.slice(3),e.tagName===`BUTTON`&&e.setAttribute(`type`,`button`),this.handlers[n]==null){if(this.quill.scroll.whitelist!=null&&this.quill.scroll.whitelist[n]==null){h.warn(`ignoring attaching to disabled format`,n,e);return}if(o.default.query(n)==null){h.warn(`ignoring attaching to nonexistent format`,n,e);return}}var i=e.tagName===`SELECT`?`change`:`click`;e.addEventListener(i,function(i){var c=void 0;if(e.tagName===`SELECT`){if(e.selectedIndex<0)return;var l=e.options[e.selectedIndex];c=l.hasAttribute(`selected`)?!1:l.value||!1}else c=e.classList.contains(`ql-active`)?!1:e.value||!e.hasAttribute(`value`),i.preventDefault();t.quill.focus();var u=r(t.quill.selection.getRange(),1)[0];if(t.handlers[n]!=null)t.handlers[n].call(t,c);else if(o.default.query(n).prototype instanceof o.default.Embed){if(c=prompt(`Enter `+n),!c)return;t.quill.updateContents(new a.default().retain(u.index).delete(u.length).insert(d({},n,c)),s.default.sources.USER)}else t.quill.format(n,c,s.default.sources.USER);t.update(u)}),this.controls.push([n,e])}}},{key:`update`,value:function(e){var t=e==null?{}:this.quill.getFormat(e);this.controls.forEach(function(n){var i=r(n,2),a=i[0],o=i[1];if(o.tagName===`SELECT`){var s=void 0;if(e==null)s=null;else if(t[a]==null)s=o.querySelector(`option[selected]`);else if(!Array.isArray(t[a])){var c=t[a];typeof c==`string`&&(c=c.replace(/\"/g,`\\"`)),s=o.querySelector(`option[value="`+c+`"]`)}s==null?(o.value=``,o.selectedIndex=-1):s.selected=!0}else if(e==null)o.classList.remove(`ql-active`);else if(o.hasAttribute(`value`)){var l=t[a]===o.getAttribute(`value`)||t[a]!=null&&t[a].toString()===o.getAttribute(`value`)||t[a]==null&&!o.getAttribute(`value`);o.classList.toggle(`ql-active`,l)}else o.classList.toggle(`ql-active`,t[a]!=null)})}}]),t}(l.default);g.DEFAULTS={};function _(e,t,n){var r=document.createElement(`button`);r.setAttribute(`type`,`button`),r.classList.add(`ql-`+t),n!=null&&(r.value=n),e.appendChild(r)}function v(e,t){Array.isArray(t[0])||(t=[t]),t.forEach(function(t){var n=document.createElement(`span`);n.classList.add(`ql-formats`),t.forEach(function(e){if(typeof e==`string`)_(n,e);else{var t=Object.keys(e)[0],r=e[t];Array.isArray(r)?y(n,t,r):_(n,t,r)}}),e.appendChild(n)})}function y(e,t,n){var r=document.createElement(`select`);r.classList.add(`ql-`+t),n.forEach(function(e){var t=document.createElement(`option`);e===!1?t.setAttribute(`selected`,`selected`):t.setAttribute(`value`,e),r.appendChild(t)}),e.appendChild(r)}g.DEFAULTS={container:null,handlers:{clean:function(){var e=this,t=this.quill.getSelection();if(t!=null)if(t.length==0){var n=this.quill.getFormat();Object.keys(n).forEach(function(t){o.default.query(t,o.default.Scope.INLINE)!=null&&e.quill.format(t,!1)})}else this.quill.removeFormat(t,s.default.sources.USER)},direction:function(e){var t=this.quill.getFormat().align;e===`rtl`&&t==null?this.quill.format(`align`,`right`,s.default.sources.USER):!e&&t===`right`&&this.quill.format(`align`,!1,s.default.sources.USER),this.quill.format(`direction`,e,s.default.sources.USER)},indent:function(e){var t=this.quill.getSelection(),n=this.quill.getFormat(t),r=parseInt(n.indent||0);if(e===`+1`||e===`-1`){var i=e===`+1`?1:-1;n.direction===`rtl`&&(i*=-1),this.quill.format(`indent`,r+i,s.default.sources.USER)}},link:function(e){e===!0&&(e=prompt(`Enter link URL:`)),this.quill.format(`link`,e,s.default.sources.USER)},list:function(e){var t=this.quill.getSelection(),n=this.quill.getFormat(t);e===`check`?n.list===`checked`||n.list===`unchecked`?this.quill.format(`list`,!1,s.default.sources.USER):this.quill.format(`list`,`unchecked`,s.default.sources.USER):this.quill.format(`list`,e,s.default.sources.USER)}}},t.default=g,t.addControls=v}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <polyline class="ql-even ql-stroke" points="5 7 3 9 5 11"></polyline> <polyline class="ql-even ql-stroke" points="13 7 15 9 13 11"></polyline> <line class=ql-stroke x1=10 x2=8 y1=5 y2=13></line> </svg>`}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=o(n(28));function o(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function c(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function l(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.default=function(e){l(t,e);function t(e,n){s(this,t);var r=c(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.label.innerHTML=n,r.container.classList.add(`ql-color-picker`),[].slice.call(r.container.querySelectorAll(`.ql-picker-item`),0,7).forEach(function(e){e.classList.add(`ql-primary`)}),r}return r(t,[{key:`buildItem`,value:function(e){var n=i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`buildItem`,this).call(this,e);return n.style.backgroundColor=e.getAttribute(`value`)||``,n}},{key:`selectItem`,value:function(e,n){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`selectItem`,this).call(this,e,n);var r=this.label.querySelector(`.ql-color-label`),a=e&&e.getAttribute(`data-value`)||``;r&&(r.tagName===`line`?r.style.stroke=a:r.style.fill=a)}}]),t}(a.default)}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=o(n(28));function o(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function c(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function l(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.default=function(e){l(t,e);function t(e,n){s(this,t);var r=c(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.container.classList.add(`ql-icon-picker`),[].forEach.call(r.container.querySelectorAll(`.ql-picker-item`),function(e){e.innerHTML=n[e.getAttribute(`data-value`)||``]}),r.defaultItem=r.container.querySelector(`.ql-selected`),r.selectItem(r.defaultItem),r}return r(t,[{key:`selectItem`,value:function(e,n){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`selectItem`,this).call(this,e,n),e||=this.defaultItem,this.label.innerHTML=e.innerHTML}}]),t}(a.default)}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();function i(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}t.default=function(){function e(t,n){var r=this;i(this,e),this.quill=t,this.boundsContainer=n||document.body,this.root=t.addContainer(`ql-tooltip`),this.root.innerHTML=this.constructor.TEMPLATE,this.quill.root===this.quill.scrollingContainer&&this.quill.root.addEventListener(`scroll`,function(){r.root.style.marginTop=-1*r.quill.root.scrollTop+`px`}),this.hide()}return r(e,[{key:`hide`,value:function(){this.root.classList.add(`ql-hidden`)}},{key:`position`,value:function(e){var t=e.left+e.width/2-this.root.offsetWidth/2,n=e.bottom+this.quill.root.scrollTop;this.root.style.left=t+`px`,this.root.style.top=n+`px`,this.root.classList.remove(`ql-flip`);var r=this.boundsContainer.getBoundingClientRect(),i=this.root.getBoundingClientRect(),a=0;if(i.right>r.right&&(a=r.right-i.right,this.root.style.left=t+a+`px`),i.left<r.left&&(a=r.left-i.left,this.root.style.left=t+a+`px`),i.bottom>r.bottom){var o=i.bottom-i.top,s=e.bottom-e.top+o;this.root.style.top=n-s+`px`,this.root.classList.add(`ql-flip`)}return a}},{key:`show`,value:function(){this.root.classList.remove(`ql-editing`),this.root.classList.remove(`ql-hidden`)}}]),e}()}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){var n=[],r=!0,i=!1,a=void 0;try{for(var o=e[Symbol.iterator](),s;!(r=(s=o.next()).done)&&(n.push(s.value),!(t&&n.length===t));r=!0);}catch(e){i=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(i)throw a}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw TypeError(`Invalid attempt to destructure non-iterable instance`)}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=p(n(3)),s=p(n(8)),c=n(43),l=p(c),u=p(n(27)),d=n(15),f=p(n(41));function p(e){return e&&e.__esModule?e:{default:e}}function m(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function h(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function g(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _=[[{header:[`1`,`2`,`3`,!1]}],[`bold`,`italic`,`underline`,`link`],[{list:`ordered`},{list:`bullet`}],[`clean`]],v=function(e){g(t,e);function t(e,n){m(this,t),n.modules.toolbar!=null&&n.modules.toolbar.container==null&&(n.modules.toolbar.container=_);var r=h(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return r.quill.container.classList.add(`ql-snow`),r}return a(t,[{key:`extendToolbar`,value:function(e){e.container.classList.add(`ql-snow`),this.buildButtons([].slice.call(e.container.querySelectorAll(`button`)),f.default),this.buildPickers([].slice.call(e.container.querySelectorAll(`select`)),f.default),this.tooltip=new y(this.quill,this.options.bounds),e.container.querySelector(`.ql-link`)&&this.quill.keyboard.addBinding({key:`K`,shortKey:!0},function(t,n){e.handlers.link.call(e,!n.format.link)})}}]),t}(l.default);v.DEFAULTS=(0,o.default)(!0,{},l.default.DEFAULTS,{modules:{toolbar:{handlers:{link:function(e){if(e){var t=this.quill.getSelection();if(t==null||t.length==0)return;var n=this.quill.getText(t);/^\S+@\S+\.\S+$/.test(n)&&n.indexOf(`mailto:`)!==0&&(n=`mailto:`+n),this.quill.theme.tooltip.edit(`link`,n)}else this.quill.format(`link`,!1)}}}}});var y=function(e){g(t,e);function t(e,n){m(this,t);var r=h(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return r.preview=r.root.querySelector(`a.ql-preview`),r}return a(t,[{key:`listen`,value:function(){var e=this;i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`listen`,this).call(this),this.root.querySelector(`a.ql-action`).addEventListener(`click`,function(t){e.root.classList.contains(`ql-editing`)?e.save():e.edit(`link`,e.preview.textContent),t.preventDefault()}),this.root.querySelector(`a.ql-remove`).addEventListener(`click`,function(t){if(e.linkRange!=null){var n=e.linkRange;e.restoreFocus(),e.quill.formatText(n,`link`,!1,s.default.sources.USER),delete e.linkRange}t.preventDefault(),e.hide()}),this.quill.on(s.default.events.SELECTION_CHANGE,function(t,n,i){if(t!=null){if(t.length===0&&i===s.default.sources.USER){var a=r(e.quill.scroll.descendant(u.default,t.index),2),o=a[0],c=a[1];if(o!=null){e.linkRange=new d.Range(t.index-c,o.length());var l=u.default.formats(o.domNode);e.preview.textContent=l,e.preview.setAttribute(`href`,l),e.show(),e.position(e.quill.getBounds(e.linkRange));return}}else delete e.linkRange;e.hide()}})}},{key:`show`,value:function(){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`show`,this).call(this),this.root.removeAttribute(`data-mode`)}}]),t}(c.BaseTooltip);y.TEMPLATE=[`<a class="ql-preview" rel="noopener noreferrer" target="_blank" href="about:blank"></a>`,`<input type="text" data-formula="e=mc^2" data-link="https://quilljs.com" data-video="Embed URL">`,`<a class="ql-action"></a>`,`<a class="ql-remove"></a>`].join(``),t.default=v}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=F(n(29)),i=n(36),a=n(38),o=n(64),s=F(n(65)),c=F(n(66)),l=n(67),u=F(l),d=n(37),f=n(26),p=n(39),m=n(40),h=F(n(56)),g=F(n(68)),_=F(n(27)),v=F(n(69)),y=F(n(70)),b=F(n(71)),x=F(n(72)),S=F(n(73)),C=n(13),w=F(C),T=F(n(74)),E=F(n(75)),D=F(n(57)),O=F(n(41)),k=F(n(28)),A=F(n(59)),j=F(n(60)),M=F(n(61)),N=F(n(108)),P=F(n(62));function F(e){return e&&e.__esModule?e:{default:e}}r.default.register({"attributors/attribute/direction":a.DirectionAttribute,"attributors/class/align":i.AlignClass,"attributors/class/background":d.BackgroundClass,"attributors/class/color":f.ColorClass,"attributors/class/direction":a.DirectionClass,"attributors/class/font":p.FontClass,"attributors/class/size":m.SizeClass,"attributors/style/align":i.AlignStyle,"attributors/style/background":d.BackgroundStyle,"attributors/style/color":f.ColorStyle,"attributors/style/direction":a.DirectionStyle,"attributors/style/font":p.FontStyle,"attributors/style/size":m.SizeStyle},!0),r.default.register({"formats/align":i.AlignClass,"formats/direction":a.DirectionClass,"formats/indent":o.IndentClass,"formats/background":d.BackgroundStyle,"formats/color":f.ColorStyle,"formats/font":p.FontClass,"formats/size":m.SizeClass,"formats/blockquote":s.default,"formats/code-block":w.default,"formats/header":c.default,"formats/list":u.default,"formats/bold":h.default,"formats/code":C.Code,"formats/italic":g.default,"formats/link":_.default,"formats/script":v.default,"formats/strike":y.default,"formats/underline":b.default,"formats/image":x.default,"formats/video":S.default,"formats/list/item":l.ListItem,"modules/formula":T.default,"modules/syntax":E.default,"modules/toolbar":D.default,"themes/bubble":N.default,"themes/snow":P.default,"ui/icons":O.default,"ui/picker":k.default,"ui/icon-picker":j.default,"ui/color-picker":A.default,"ui/tooltip":M.default},!0),t.default=r.default}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0}),t.IndentClass=void 0;var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=o(n(0));function o(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function c(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function l(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.IndentClass=new(function(e){l(t,e);function t(){return s(this,t),c(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,[{key:`add`,value:function(e,n){if(n===`+1`||n===`-1`){var r=this.value(e)||0;n=n===`+1`?r+1:r-1}return n===0?(this.remove(e),!0):i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`add`,this).call(this,e,n)}},{key:`canAdd`,value:function(e,n){return i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`canAdd`,this).call(this,e,n)||i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`canAdd`,this).call(this,e,parseInt(n))}},{key:`value`,value:function(e){return parseInt(i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`value`,this).call(this,e))||void 0}}]),t}(a.default.Attributor.Class))(`indent`,`ql-indent`,{scope:a.default.Scope.BLOCK,whitelist:[1,2,3,4,5,6,7,8]})}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=i(n(4));function i(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function o(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function s(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var c=function(e){s(t,e);function t(){return a(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return t}(r.default);c.blotName=`blockquote`,c.tagName=`blockquote`,t.default=c}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=a(n(4));function a(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function s(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function c(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var l=function(e){c(t,e);function t(){return o(this,t),s(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,null,[{key:`formats`,value:function(e){return this.tagName.indexOf(e.tagName)+1}}]),t}(i.default);l.blotName=`header`,l.tagName=[`H1`,`H2`,`H3`,`H4`,`H5`,`H6`],t.default=l}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0}),t.default=t.ListItem=void 0;var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=c(n(0)),o=c(n(4)),s=c(n(25));function c(e){return e&&e.__esModule?e:{default:e}}function l(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function d(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function f(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var p=function(e){f(t,e);function t(){return u(this,t),d(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,[{key:`format`,value:function(e,n){e===m.blotName&&!n?this.replaceWith(a.default.create(this.statics.scope)):i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`format`,this).call(this,e,n)}},{key:`remove`,value:function(){this.prev==null&&this.next==null?this.parent.remove():i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`remove`,this).call(this)}},{key:`replaceWith`,value:function(e,n){return this.parent.isolate(this.offset(this.parent),this.length()),e===this.parent.statics.blotName?(this.parent.replaceWith(e,n),this):(this.parent.unwrap(),i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`replaceWith`,this).call(this,e,n))}}],[{key:`formats`,value:function(e){return e.tagName===this.tagName?void 0:i(t.__proto__||Object.getPrototypeOf(t),`formats`,this).call(this,e)}}]),t}(o.default);p.blotName=`list-item`,p.tagName=`LI`;var m=function(e){f(t,e),r(t,null,[{key:`create`,value:function(e){var n=e===`ordered`?`OL`:`UL`,r=i(t.__proto__||Object.getPrototypeOf(t),`create`,this).call(this,n);return(e===`checked`||e===`unchecked`)&&r.setAttribute(`data-checked`,e===`checked`),r}},{key:`formats`,value:function(e){if(e.tagName===`OL`)return`ordered`;if(e.tagName===`UL`)return e.hasAttribute(`data-checked`)?e.getAttribute(`data-checked`)===`true`?`checked`:`unchecked`:`bullet`}}]);function t(e){u(this,t);var n=d(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e)),r=function(t){if(t.target.parentNode===e){var r=n.statics.formats(e),i=a.default.find(t.target);r===`checked`?i.format(`list`,`unchecked`):r===`unchecked`&&i.format(`list`,`checked`)}};return e.addEventListener(`touchstart`,r),e.addEventListener(`mousedown`,r),n}return r(t,[{key:`format`,value:function(e,t){this.children.length>0&&this.children.tail.format(e,t)}},{key:`formats`,value:function(){return l({},this.statics.blotName,this.statics.formats(this.domNode))}},{key:`insertBefore`,value:function(e,n){if(e instanceof p)i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`insertBefore`,this).call(this,e,n);else{var r=n==null?this.length():n.offset(this),a=this.split(r);a.parent.insertBefore(e,a)}}},{key:`optimize`,value:function(e){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`optimize`,this).call(this,e);var n=this.next;n!=null&&n.prev===this&&n.statics.blotName===this.statics.blotName&&n.domNode.tagName===this.domNode.tagName&&n.domNode.getAttribute(`data-checked`)===this.domNode.getAttribute(`data-checked`)&&(n.moveChildren(this),n.remove())}},{key:`replace`,value:function(e){if(e.statics.blotName!==this.statics.blotName){var n=a.default.create(this.statics.defaultChild);e.moveChildren(n),this.appendChild(n)}i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`replace`,this).call(this,e)}}]),t}(s.default);m.blotName=`list`,m.scope=a.default.Scope.BLOCK_BLOT,m.tagName=[`OL`,`UL`],m.defaultChild=`list-item`,m.allowedChildren=[p],t.ListItem=p,t.default=m}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=i(n(56));function i(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function o(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function s(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var c=function(e){s(t,e);function t(){return a(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return t}(r.default);c.blotName=`italic`,c.tagName=[`EM`,`I`],t.default=c}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=o(n(6));function o(e){return e&&e.__esModule?e:{default:e}}function s(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function c(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function l(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var u=function(e){l(t,e);function t(){return s(this,t),c(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,null,[{key:`create`,value:function(e){return e===`super`?document.createElement(`sup`):e===`sub`?document.createElement(`sub`):i(t.__proto__||Object.getPrototypeOf(t),`create`,this).call(this,e)}},{key:`formats`,value:function(e){if(e.tagName===`SUB`)return`sub`;if(e.tagName===`SUP`)return`super`}}]),t}(a.default);u.blotName=`script`,u.tagName=[`SUB`,`SUP`],t.default=u}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=i(n(6));function i(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function o(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function s(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var c=function(e){s(t,e);function t(){return a(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return t}(r.default);c.blotName=`strike`,c.tagName=`S`,t.default=c}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=i(n(6));function i(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function o(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function s(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var c=function(e){s(t,e);function t(){return a(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return t}(r.default);c.blotName=`underline`,c.tagName=`U`,t.default=c}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=s(n(0)),o=n(27);function s(e){return e&&e.__esModule?e:{default:e}}function c(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function l(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function u(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var d=[`alt`,`height`,`width`],f=function(e){u(t,e);function t(){return c(this,t),l(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,[{key:`format`,value:function(e,n){d.indexOf(e)>-1?n?this.domNode.setAttribute(e,n):this.domNode.removeAttribute(e):i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`format`,this).call(this,e,n)}}],[{key:`create`,value:function(e){var n=i(t.__proto__||Object.getPrototypeOf(t),`create`,this).call(this,e);return typeof e==`string`&&n.setAttribute(`src`,this.sanitize(e)),n}},{key:`formats`,value:function(e){return d.reduce(function(t,n){return e.hasAttribute(n)&&(t[n]=e.getAttribute(n)),t},{})}},{key:`match`,value:function(e){return/\.(jpe?g|gif|png)$/.test(e)||/^data:image\/.+;base64/.test(e)}},{key:`sanitize`,value:function(e){return(0,o.sanitize)(e,[`http`,`https`,`data`])?e:`//:0`}},{key:`value`,value:function(e){return e.getAttribute(`src`)}}]),t}(a.default.Embed);f.blotName=`image`,f.tagName=`IMG`,t.default=f}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=n(4),o=s(n(27));function s(e){return e&&e.__esModule?e:{default:e}}function c(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function l(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function u(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var d=[`height`,`width`],f=function(e){u(t,e);function t(){return c(this,t),l(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,[{key:`format`,value:function(e,n){d.indexOf(e)>-1?n?this.domNode.setAttribute(e,n):this.domNode.removeAttribute(e):i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`format`,this).call(this,e,n)}}],[{key:`create`,value:function(e){var n=i(t.__proto__||Object.getPrototypeOf(t),`create`,this).call(this,e);return n.setAttribute(`frameborder`,`0`),n.setAttribute(`allowfullscreen`,!0),n.setAttribute(`src`,this.sanitize(e)),n}},{key:`formats`,value:function(e){return d.reduce(function(t,n){return e.hasAttribute(n)&&(t[n]=e.getAttribute(n)),t},{})}},{key:`sanitize`,value:function(e){return o.default.sanitize(e)}},{key:`value`,value:function(e){return e.getAttribute(`src`)}}]),t}(a.BlockEmbed);f.blotName=`video`,f.className=`ql-video`,f.tagName=`IFRAME`,t.default=f}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0}),t.default=t.FormulaBlot=void 0;var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=c(n(35)),o=c(n(5)),s=c(n(9));function c(e){return e&&e.__esModule?e:{default:e}}function l(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function u(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function d(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var f=function(e){d(t,e);function t(){return l(this,t),u(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,null,[{key:`create`,value:function(e){var n=i(t.__proto__||Object.getPrototypeOf(t),`create`,this).call(this,e);return typeof e==`string`&&(window.katex.render(e,n,{throwOnError:!1,errorColor:`#f00`}),n.setAttribute(`data-value`,e)),n}},{key:`value`,value:function(e){return e.getAttribute(`data-value`)}}]),t}(a.default);f.blotName=`formula`,f.className=`ql-formula`,f.tagName=`SPAN`;var p=function(e){d(t,e),r(t,null,[{key:`register`,value:function(){o.default.register(f,!0)}}]);function t(){l(this,t);var e=u(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));if(window.katex==null)throw Error(`Formula module requires KaTeX.`);return e}return t}(s.default);t.FormulaBlot=f,t.default=p}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0}),t.default=t.CodeToken=t.CodeBlock=void 0;var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},a=l(n(0)),o=l(n(5)),s=l(n(9)),c=l(n(13));function l(e){return e&&e.__esModule?e:{default:e}}function u(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function d(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function f(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var p=function(e){f(t,e);function t(){return u(this,t),d(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return r(t,[{key:`replaceWith`,value:function(e){this.domNode.textContent=this.domNode.textContent,this.attach(),i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`replaceWith`,this).call(this,e)}},{key:`highlight`,value:function(e){var t=this.domNode.textContent;this.cachedText!==t&&((t.trim().length>0||this.cachedText==null)&&(this.domNode.innerHTML=e(t),this.domNode.normalize(),this.attach()),this.cachedText=t)}}]),t}(c.default);p.className=`ql-syntax`;var m=new a.default.Attributor.Class(`token`,`hljs`,{scope:a.default.Scope.INLINE}),h=function(e){f(t,e),r(t,null,[{key:`register`,value:function(){o.default.register(m,!0),o.default.register(p,!0)}}]);function t(e,n){u(this,t);var r=d(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));if(typeof r.options.highlight!=`function`)throw Error(`Syntax module requires highlight.js. Please include the library on the page before Quill.`);var i=null;return r.quill.on(o.default.events.SCROLL_OPTIMIZE,function(){clearTimeout(i),i=setTimeout(function(){r.highlight(),i=null},r.options.interval)}),r.highlight(),r}return r(t,[{key:`highlight`,value:function(){var e=this;if(!this.quill.selection.composing){this.quill.update(o.default.sources.USER);var t=this.quill.getSelection();this.quill.scroll.descendants(p).forEach(function(t){t.highlight(e.options.highlight)}),this.quill.update(o.default.sources.SILENT),t!=null&&this.quill.setSelection(t,o.default.sources.SILENT)}}}]),t}(s.default);h.DEFAULTS={highlight:function(){return window.hljs==null?null:function(e){return window.hljs.highlightAuto(e).value}}(),interval:1e3},t.CodeBlock=p,t.CodeToken=m,t.default=h}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=3 x2=15 y1=9 y2=9></line> <line class=ql-stroke x1=3 x2=13 y1=14 y2=14></line> <line class=ql-stroke x1=3 x2=9 y1=4 y2=4></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=15 x2=3 y1=9 y2=9></line> <line class=ql-stroke x1=14 x2=4 y1=14 y2=14></line> <line class=ql-stroke x1=12 x2=6 y1=4 y2=4></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=15 x2=3 y1=9 y2=9></line> <line class=ql-stroke x1=15 x2=5 y1=14 y2=14></line> <line class=ql-stroke x1=15 x2=9 y1=4 y2=4></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=15 x2=3 y1=9 y2=9></line> <line class=ql-stroke x1=15 x2=3 y1=14 y2=14></line> <line class=ql-stroke x1=15 x2=3 y1=4 y2=4></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <g class="ql-fill ql-color-label"> <polygon points="6 6.868 6 6 5 6 5 7 5.942 7 6 6.868"></polygon> <rect height=1 width=1 x=4 y=4></rect> <polygon points="6.817 5 6 5 6 6 6.38 6 6.817 5"></polygon> <rect height=1 width=1 x=2 y=6></rect> <rect height=1 width=1 x=3 y=5></rect> <rect height=1 width=1 x=4 y=7></rect> <polygon points="4 11.439 4 11 3 11 3 12 3.755 12 4 11.439"></polygon> <rect height=1 width=1 x=2 y=12></rect> <rect height=1 width=1 x=2 y=9></rect> <rect height=1 width=1 x=2 y=15></rect> <polygon points="4.63 10 4 10 4 11 4.192 11 4.63 10"></polygon> <rect height=1 width=1 x=3 y=8></rect> <path d=M10.832,4.2L11,4.582V4H10.708A1.948,1.948,0,0,1,10.832,4.2Z></path> <path d=M7,4.582L7.168,4.2A1.929,1.929,0,0,1,7.292,4H7V4.582Z></path> <path d=M8,13H7.683l-0.351.8a1.933,1.933,0,0,1-.124.2H8V13Z></path> <rect height=1 width=1 x=12 y=2></rect> <rect height=1 width=1 x=11 y=3></rect> <path d=M9,3H8V3.282A1.985,1.985,0,0,1,9,3Z></path> <rect height=1 width=1 x=2 y=3></rect> <rect height=1 width=1 x=6 y=2></rect> <rect height=1 width=1 x=3 y=2></rect> <rect height=1 width=1 x=5 y=3></rect> <rect height=1 width=1 x=9 y=2></rect> <rect height=1 width=1 x=15 y=14></rect> <polygon points="13.447 10.174 13.469 10.225 13.472 10.232 13.808 11 14 11 14 10 13.37 10 13.447 10.174"></polygon> <rect height=1 width=1 x=13 y=7></rect> <rect height=1 width=1 x=15 y=5></rect> <rect height=1 width=1 x=14 y=6></rect> <rect height=1 width=1 x=15 y=8></rect> <rect height=1 width=1 x=14 y=9></rect> <path d=M3.775,14H3v1H4V14.314A1.97,1.97,0,0,1,3.775,14Z></path> <rect height=1 width=1 x=14 y=3></rect> <polygon points="12 6.868 12 6 11.62 6 12 6.868"></polygon> <rect height=1 width=1 x=15 y=2></rect> <rect height=1 width=1 x=12 y=5></rect> <rect height=1 width=1 x=13 y=4></rect> <polygon points="12.933 9 13 9 13 8 12.495 8 12.933 9"></polygon> <rect height=1 width=1 x=9 y=14></rect> <rect height=1 width=1 x=8 y=15></rect> <path d=M6,14.926V15H7V14.316A1.993,1.993,0,0,1,6,14.926Z></path> <rect height=1 width=1 x=5 y=15></rect> <path d=M10.668,13.8L10.317,13H10v1h0.792A1.947,1.947,0,0,1,10.668,13.8Z></path> <rect height=1 width=1 x=11 y=15></rect> <path d=M14.332,12.2a1.99,1.99,0,0,1,.166.8H15V12H14.245Z></path> <rect height=1 width=1 x=14 y=15></rect> <rect height=1 width=1 x=15 y=11></rect> </g> <polyline class=ql-stroke points="5.5 13 9 5 12.5 13"></polyline> <line class=ql-stroke x1=11.63 x2=6.38 y1=11 y2=11></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <rect class="ql-fill ql-stroke" height=3 width=3 x=4 y=5></rect> <rect class="ql-fill ql-stroke" height=3 width=3 x=11 y=5></rect> <path class="ql-even ql-fill ql-stroke" d=M7,8c0,4.031-3,5-3,5></path> <path class="ql-even ql-fill ql-stroke" d=M14,8c0,4.031-3,5-3,5></path> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-stroke d=M5,4H9.5A2.5,2.5,0,0,1,12,6.5v0A2.5,2.5,0,0,1,9.5,9H5A0,0,0,0,1,5,9V4A0,0,0,0,1,5,4Z></path> <path class=ql-stroke d=M5,9h5.5A2.5,2.5,0,0,1,13,11.5v0A2.5,2.5,0,0,1,10.5,14H5a0,0,0,0,1,0,0V9A0,0,0,0,1,5,9Z></path> </svg>`}),(function(e,t){e.exports=`<svg class="" viewbox="0 0 18 18"> <line class=ql-stroke x1=5 x2=13 y1=3 y2=3></line> <line class=ql-stroke x1=6 x2=9.35 y1=12 y2=3></line> <line class=ql-stroke x1=11 x2=15 y1=11 y2=15></line> <line class=ql-stroke x1=15 x2=11 y1=11 y2=15></line> <rect class=ql-fill height=1 rx=0.5 ry=0.5 width=7 x=2 y=14></rect> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class="ql-color-label ql-stroke ql-transparent" x1=3 x2=15 y1=15 y2=15></line> <polyline class=ql-stroke points="5.5 11 9 3 12.5 11"></polyline> <line class=ql-stroke x1=11.63 x2=6.38 y1=9 y2=9></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <polygon class="ql-stroke ql-fill" points="3 11 5 9 3 7 3 11"></polygon> <line class="ql-stroke ql-fill" x1=15 x2=11 y1=4 y2=4></line> <path class=ql-fill d=M11,3a3,3,0,0,0,0,6h1V3H11Z></path> <rect class=ql-fill height=11 width=1 x=11 y=4></rect> <rect class=ql-fill height=11 width=1 x=13 y=4></rect> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <polygon class="ql-stroke ql-fill" points="15 12 13 10 15 8 15 12"></polygon> <line class="ql-stroke ql-fill" x1=9 x2=5 y1=4 y2=4></line> <path class=ql-fill d=M5,3A3,3,0,0,0,5,9H6V3H5Z></path> <rect class=ql-fill height=11 width=1 x=5 y=4></rect> <rect class=ql-fill height=11 width=1 x=7 y=4></rect> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M14,16H4a1,1,0,0,1,0-2H14A1,1,0,0,1,14,16Z /> <path class=ql-fill d=M14,4H4A1,1,0,0,1,4,2H14A1,1,0,0,1,14,4Z /> <rect class=ql-fill x=3 y=6 width=12 height=6 rx=1 ry=1 /> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M13,16H5a1,1,0,0,1,0-2h8A1,1,0,0,1,13,16Z /> <path class=ql-fill d=M13,4H5A1,1,0,0,1,5,2h8A1,1,0,0,1,13,4Z /> <rect class=ql-fill x=2 y=6 width=14 height=6 rx=1 ry=1 /> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M15,8H13a1,1,0,0,1,0-2h2A1,1,0,0,1,15,8Z /> <path class=ql-fill d=M15,12H13a1,1,0,0,1,0-2h2A1,1,0,0,1,15,12Z /> <path class=ql-fill d=M15,16H5a1,1,0,0,1,0-2H15A1,1,0,0,1,15,16Z /> <path class=ql-fill d=M15,4H5A1,1,0,0,1,5,2H15A1,1,0,0,1,15,4Z /> <rect class=ql-fill x=2 y=6 width=8 height=6 rx=1 ry=1 /> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M5,8H3A1,1,0,0,1,3,6H5A1,1,0,0,1,5,8Z /> <path class=ql-fill d=M5,12H3a1,1,0,0,1,0-2H5A1,1,0,0,1,5,12Z /> <path class=ql-fill d=M13,16H3a1,1,0,0,1,0-2H13A1,1,0,0,1,13,16Z /> <path class=ql-fill d=M13,4H3A1,1,0,0,1,3,2H13A1,1,0,0,1,13,4Z /> <rect class=ql-fill x=8 y=6 width=8 height=6 rx=1 ry=1 transform="translate(24 18) rotate(-180)"/> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M11.759,2.482a2.561,2.561,0,0,0-3.53.607A7.656,7.656,0,0,0,6.8,6.2C6.109,9.188,5.275,14.677,4.15,14.927a1.545,1.545,0,0,0-1.3-.933A0.922,0.922,0,0,0,2,15.036S1.954,16,4.119,16s3.091-2.691,3.7-5.553c0.177-.826.36-1.726,0.554-2.6L8.775,6.2c0.381-1.421.807-2.521,1.306-2.676a1.014,1.014,0,0,0,1.02.56A0.966,0.966,0,0,0,11.759,2.482Z></path> <rect class=ql-fill height=1.6 rx=0.8 ry=0.8 width=5 x=5.15 y=6.2></rect> <path class=ql-fill d=M13.663,12.027a1.662,1.662,0,0,1,.266-0.276q0.193,0.069.456,0.138a2.1,2.1,0,0,0,.535.069,1.075,1.075,0,0,0,.767-0.3,1.044,1.044,0,0,0,.314-0.8,0.84,0.84,0,0,0-.238-0.619,0.8,0.8,0,0,0-.594-0.239,1.154,1.154,0,0,0-.781.3,4.607,4.607,0,0,0-.781,1q-0.091.15-.218,0.346l-0.246.38c-0.068-.288-0.137-0.582-0.212-0.885-0.459-1.847-2.494-.984-2.941-0.8-0.482.2-.353,0.647-0.094,0.529a0.869,0.869,0,0,1,1.281.585c0.217,0.751.377,1.436,0.527,2.038a5.688,5.688,0,0,1-.362.467,2.69,2.69,0,0,1-.264.271q-0.221-.08-0.471-0.147a2.029,2.029,0,0,0-.522-0.066,1.079,1.079,0,0,0-.768.3A1.058,1.058,0,0,0,9,15.131a0.82,0.82,0,0,0,.832.852,1.134,1.134,0,0,0,.787-0.3,5.11,5.11,0,0,0,.776-0.993q0.141-.219.215-0.34c0.046-.076.122-0.194,0.223-0.346a2.786,2.786,0,0,0,.918,1.726,2.582,2.582,0,0,0,2.376-.185c0.317-.181.212-0.565,0-0.494A0.807,0.807,0,0,1,14.176,15a5.159,5.159,0,0,1-.913-2.446l0,0Q13.487,12.24,13.663,12.027Z></path> </svg>`}),(function(e,t){e.exports=`<svg viewBox="0 0 18 18"> <path class=ql-fill d=M10,4V14a1,1,0,0,1-2,0V10H3v4a1,1,0,0,1-2,0V4A1,1,0,0,1,3,4V8H8V4a1,1,0,0,1,2,0Zm6.06787,9.209H14.98975V7.59863a.54085.54085,0,0,0-.605-.60547h-.62744a1.01119,1.01119,0,0,0-.748.29688L11.645,8.56641a.5435.5435,0,0,0-.022.8584l.28613.30762a.53861.53861,0,0,0,.84717.0332l.09912-.08789a1.2137,1.2137,0,0,0,.2417-.35254h.02246s-.01123.30859-.01123.60547V13.209H12.041a.54085.54085,0,0,0-.605.60547v.43945a.54085.54085,0,0,0,.605.60547h4.02686a.54085.54085,0,0,0,.605-.60547v-.43945A.54085.54085,0,0,0,16.06787,13.209Z /> </svg>`}),(function(e,t){e.exports=`<svg viewBox="0 0 18 18"> <path class=ql-fill d=M16.73975,13.81445v.43945a.54085.54085,0,0,1-.605.60547H11.855a.58392.58392,0,0,1-.64893-.60547V14.0127c0-2.90527,3.39941-3.42187,3.39941-4.55469a.77675.77675,0,0,0-.84717-.78125,1.17684,1.17684,0,0,0-.83594.38477c-.2749.26367-.561.374-.85791.13184l-.4292-.34082c-.30811-.24219-.38525-.51758-.1543-.81445a2.97155,2.97155,0,0,1,2.45361-1.17676,2.45393,2.45393,0,0,1,2.68408,2.40918c0,2.45312-3.1792,2.92676-3.27832,3.93848h2.79443A.54085.54085,0,0,1,16.73975,13.81445ZM9,3A.99974.99974,0,0,0,8,4V8H3V4A1,1,0,0,0,1,4V14a1,1,0,0,0,2,0V10H8v4a1,1,0,0,0,2,0V4A.99974.99974,0,0,0,9,3Z /> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=7 x2=13 y1=4 y2=4></line> <line class=ql-stroke x1=5 x2=11 y1=14 y2=14></line> <line class=ql-stroke x1=8 x2=10 y1=14 y2=4></line> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <rect class=ql-stroke height=10 width=12 x=3 y=4></rect> <circle class=ql-fill cx=6 cy=7 r=1></circle> <polyline class="ql-even ql-fill" points="5 12 5 11 7 9 8 10 11 7 13 9 13 12 5 12"></polyline> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=3 x2=15 y1=14 y2=14></line> <line class=ql-stroke x1=3 x2=15 y1=4 y2=4></line> <line class=ql-stroke x1=9 x2=15 y1=9 y2=9></line> <polyline class="ql-fill ql-stroke" points="3 7 3 11 5 9 3 7"></polyline> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=3 x2=15 y1=14 y2=14></line> <line class=ql-stroke x1=3 x2=15 y1=4 y2=4></line> <line class=ql-stroke x1=9 x2=15 y1=9 y2=9></line> <polyline class=ql-stroke points="5 7 5 11 3 9 5 7"></polyline> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=7 x2=11 y1=7 y2=11></line> <path class="ql-even ql-stroke" d=M8.9,4.577a3.476,3.476,0,0,1,.36,4.679A3.476,3.476,0,0,1,4.577,8.9C3.185,7.5,2.035,6.4,4.217,4.217S7.5,3.185,8.9,4.577Z></path> <path class="ql-even ql-stroke" d=M13.423,9.1a3.476,3.476,0,0,0-4.679-.36,3.476,3.476,0,0,0,.36,4.679c1.392,1.392,2.5,2.542,4.679.36S14.815,10.5,13.423,9.1Z></path> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=7 x2=15 y1=4 y2=4></line> <line class=ql-stroke x1=7 x2=15 y1=9 y2=9></line> <line class=ql-stroke x1=7 x2=15 y1=14 y2=14></line> <line class="ql-stroke ql-thin" x1=2.5 x2=4.5 y1=5.5 y2=5.5></line> <path class=ql-fill d=M3.5,6A0.5,0.5,0,0,1,3,5.5V3.085l-0.276.138A0.5,0.5,0,0,1,2.053,3c-0.124-.247-0.023-0.324.224-0.447l1-.5A0.5,0.5,0,0,1,4,2.5v3A0.5,0.5,0,0,1,3.5,6Z></path> <path class="ql-stroke ql-thin" d=M4.5,10.5h-2c0-.234,1.85-1.076,1.85-2.234A0.959,0.959,0,0,0,2.5,8.156></path> <path class="ql-stroke ql-thin" d=M2.5,14.846a0.959,0.959,0,0,0,1.85-.109A0.7,0.7,0,0,0,3.75,14a0.688,0.688,0,0,0,.6-0.736,0.959,0.959,0,0,0-1.85-.109></path> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class=ql-stroke x1=6 x2=15 y1=4 y2=4></line> <line class=ql-stroke x1=6 x2=15 y1=9 y2=9></line> <line class=ql-stroke x1=6 x2=15 y1=14 y2=14></line> <line class=ql-stroke x1=3 x2=3 y1=4 y2=4></line> <line class=ql-stroke x1=3 x2=3 y1=9 y2=9></line> <line class=ql-stroke x1=3 x2=3 y1=14 y2=14></line> </svg>`}),(function(e,t){e.exports=`<svg class="" viewbox="0 0 18 18"> <line class=ql-stroke x1=9 x2=15 y1=4 y2=4></line> <polyline class=ql-stroke points="3 4 4 5 6 3"></polyline> <line class=ql-stroke x1=9 x2=15 y1=14 y2=14></line> <polyline class=ql-stroke points="3 14 4 15 6 13"></polyline> <line class=ql-stroke x1=9 x2=15 y1=9 y2=9></line> <polyline class=ql-stroke points="3 9 4 10 6 8"></polyline> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M15.5,15H13.861a3.858,3.858,0,0,0,1.914-2.975,1.8,1.8,0,0,0-1.6-1.751A1.921,1.921,0,0,0,12.021,11.7a0.50013,0.50013,0,1,0,.957.291h0a0.914,0.914,0,0,1,1.053-.725,0.81,0.81,0,0,1,.744.762c0,1.076-1.16971,1.86982-1.93971,2.43082A1.45639,1.45639,0,0,0,12,15.5a0.5,0.5,0,0,0,.5.5h3A0.5,0.5,0,0,0,15.5,15Z /> <path class=ql-fill d=M9.65,5.241a1,1,0,0,0-1.409.108L6,7.964,3.759,5.349A1,1,0,0,0,2.192,6.59178Q2.21541,6.6213,2.241,6.649L4.684,9.5,2.241,12.35A1,1,0,0,0,3.71,13.70722q0.02557-.02768.049-0.05722L6,11.036,8.241,13.65a1,1,0,1,0,1.567-1.24277Q9.78459,12.3777,9.759,12.35L7.316,9.5,9.759,6.651A1,1,0,0,0,9.65,5.241Z /> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-fill d=M15.5,7H13.861a4.015,4.015,0,0,0,1.914-2.975,1.8,1.8,0,0,0-1.6-1.751A1.922,1.922,0,0,0,12.021,3.7a0.5,0.5,0,1,0,.957.291,0.917,0.917,0,0,1,1.053-.725,0.81,0.81,0,0,1,.744.762c0,1.077-1.164,1.925-1.934,2.486A1.423,1.423,0,0,0,12,7.5a0.5,0.5,0,0,0,.5.5h3A0.5,0.5,0,0,0,15.5,7Z /> <path class=ql-fill d=M9.651,5.241a1,1,0,0,0-1.41.108L6,7.964,3.759,5.349a1,1,0,1,0-1.519,1.3L4.683,9.5,2.241,12.35a1,1,0,1,0,1.519,1.3L6,11.036,8.241,13.65a1,1,0,0,0,1.519-1.3L7.317,9.5,9.759,6.651A1,1,0,0,0,9.651,5.241Z /> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <line class="ql-stroke ql-thin" x1=15.5 x2=2.5 y1=8.5 y2=9.5></line> <path class=ql-fill d=M9.007,8C6.542,7.791,6,7.519,6,6.5,6,5.792,7.283,5,9,5c1.571,0,2.765.679,2.969,1.309a1,1,0,0,0,1.9-.617C13.356,4.106,11.354,3,9,3,6.2,3,4,4.538,4,6.5a3.2,3.2,0,0,0,.5,1.843Z></path> <path class=ql-fill d=M8.984,10C11.457,10.208,12,10.479,12,11.5c0,0.708-1.283,1.5-3,1.5-1.571,0-2.765-.679-2.969-1.309a1,1,0,1,0-1.9.617C4.644,13.894,6.646,15,9,15c2.8,0,5-1.538,5-3.5a3.2,3.2,0,0,0-.5-1.843Z></path> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <path class=ql-stroke d=M5,3V9a4.012,4.012,0,0,0,4,4H9a4.012,4.012,0,0,0,4-4V3></path> <rect class=ql-fill height=1 rx=0.5 ry=0.5 width=12 x=3 y=15></rect> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <rect class=ql-stroke height=12 width=12 x=3 y=3></rect> <rect class=ql-fill height=12 width=1 x=5 y=3></rect> <rect class=ql-fill height=12 width=1 x=12 y=3></rect> <rect class=ql-fill height=2 width=8 x=5 y=8></rect> <rect class=ql-fill height=1 width=3 x=3 y=5></rect> <rect class=ql-fill height=1 width=3 x=3 y=7></rect> <rect class=ql-fill height=1 width=3 x=3 y=10></rect> <rect class=ql-fill height=1 width=3 x=3 y=12></rect> <rect class=ql-fill height=1 width=3 x=12 y=5></rect> <rect class=ql-fill height=1 width=3 x=12 y=7></rect> <rect class=ql-fill height=1 width=3 x=12 y=10></rect> <rect class=ql-fill height=1 width=3 x=12 y=12></rect> </svg>`}),(function(e,t){e.exports=`<svg viewbox="0 0 18 18"> <polygon class=ql-stroke points="7 11 9 13 11 11 7 11"></polygon> <polygon class=ql-stroke points="7 7 9 5 11 7 7 7"></polygon> </svg>`}),(function(e,t,n){Object.defineProperty(t,`__esModule`,{value:!0}),t.default=t.BubbleTooltip=void 0;var r=function e(t,n,r){t===null&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(i===void 0){var a=Object.getPrototypeOf(t);return a===null?void 0:e(a,n,r)}else if(`value`in i)return i.value;else{var o=i.get;return o===void 0?void 0:o.call(r)}},i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=d(n(3)),o=d(n(8)),s=n(43),c=d(s),l=n(15),u=d(n(41));function d(e){return e&&e.__esModule?e:{default:e}}function f(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function p(e,t){if(!e)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return t&&(typeof t==`object`||typeof t==`function`)?t:e}function m(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function, not `+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var h=[[`bold`,`italic`,`link`],[{header:1},{header:2},`blockquote`]],g=function(e){m(t,e);function t(e,n){f(this,t),n.modules.toolbar!=null&&n.modules.toolbar.container==null&&(n.modules.toolbar.container=h);var r=p(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return r.quill.container.classList.add(`ql-bubble`),r}return i(t,[{key:`extendToolbar`,value:function(e){this.tooltip=new _(this.quill,this.options.bounds),this.tooltip.root.appendChild(e.container),this.buildButtons([].slice.call(e.container.querySelectorAll(`button`)),u.default),this.buildPickers([].slice.call(e.container.querySelectorAll(`select`)),u.default)}}]),t}(c.default);g.DEFAULTS=(0,a.default)(!0,{},c.default.DEFAULTS,{modules:{toolbar:{handlers:{link:function(e){e?this.quill.theme.tooltip.edit():this.quill.format(`link`,!1)}}}}});var _=function(e){m(t,e);function t(e,n){f(this,t);var r=p(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return r.quill.on(o.default.events.EDITOR_CHANGE,function(e,t,n,i){if(e===o.default.events.SELECTION_CHANGE)if(t!=null&&t.length>0&&i===o.default.sources.USER){r.show(),r.root.style.left=`0px`,r.root.style.width=``,r.root.style.width=r.root.offsetWidth+`px`;var a=r.quill.getLines(t.index,t.length);if(a.length===1)r.position(r.quill.getBounds(t));else{var s=a[a.length-1],c=r.quill.getIndex(s),u=Math.min(s.length()-1,t.index+t.length-c),d=r.quill.getBounds(new l.Range(c,u));r.position(d)}}else document.activeElement!==r.textbox&&r.quill.hasFocus()&&r.hide()}),r}return i(t,[{key:`listen`,value:function(){var e=this;r(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`listen`,this).call(this),this.root.querySelector(`.ql-close`).addEventListener(`click`,function(){e.root.classList.remove(`ql-editing`)}),this.quill.on(o.default.events.SCROLL_OPTIMIZE,function(){setTimeout(function(){if(!e.root.classList.contains(`ql-hidden`)){var t=e.quill.getSelection();t!=null&&e.position(e.quill.getBounds(t))}},1)})}},{key:`cancel`,value:function(){this.show()}},{key:`position`,value:function(e){var n=r(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),`position`,this).call(this,e),i=this.root.querySelector(`.ql-tooltip-arrow`);if(i.style.marginLeft=``,n===0)return n;i.style.marginLeft=-1*n-i.offsetWidth/2+`px`}}]),t}(s.BaseTooltip);_.TEMPLATE=[`<span class="ql-tooltip-arrow"></span>`,`<div class="ql-tooltip-editor">`,`<input type="text" data-formula="e=mc^2" data-link="https://quilljs.com" data-video="Embed URL">`,`<a class="ql-close"></a>`,`</div>`].join(``),t.BubbleTooltip=_,t.default=g}),(function(e,t,n){e.exports=n(63)})]).default})})),_v=r(((e,t)=>{(function(n){var r=typeof e==`object`&&e&&!e.nodeType&&e,i=typeof t==`object`&&t&&!t.nodeType&&t,a=typeof global==`object`&&global;(a.global===a||a.window===a||a.self===a)&&(n=a);var o,s=2147483647,c=36,l=1,u=26,d=38,f=700,p=72,m=128,h=`-`,g=/^xn--/,_=/[^\x20-\x7E]/,v=/[\x2E\u3002\uFF0E\uFF61]/g,y={overflow:`Overflow: input needs wider integers to process`,"not-basic":`Illegal input >= 0x80 (not a basic code point)`,"invalid-input":`Invalid input`},b=c-l,x=Math.floor,S=String.fromCharCode,C;function w(e){throw RangeError(y[e])}function T(e,t){for(var n=e.length,r=[];n--;)r[n]=t(e[n]);return r}function E(e,t){var n=e.split(`@`),r=``;n.length>1&&(r=n[0]+`@`,e=n[1]),e=e.replace(v,`.`);var i=T(e.split(`.`),t).join(`.`);return r+i}function D(e){for(var t=[],n=0,r=e.length,i,a;n<r;)i=e.charCodeAt(n++),i>=55296&&i<=56319&&n<r?(a=e.charCodeAt(n++),(a&64512)==56320?t.push(((i&1023)<<10)+(a&1023)+65536):(t.push(i),n--)):t.push(i);return t}function O(e){return T(e,function(e){var t=``;return e>65535&&(e-=65536,t+=S(e>>>10&1023|55296),e=56320|e&1023),t+=S(e),t}).join(``)}function k(e){return e-48<10?e-22:e-65<26?e-65:e-97<26?e-97:c}function A(e,t){return e+22+75*(e<26)-((t!=0)<<5)}function j(e,t,n){var r=0;for(e=n?x(e/f):e>>1,e+=x(e/t);e>b*u>>1;r+=c)e=x(e/b);return x(r+(b+1)*e/(e+d))}function M(e){var t=[],n=e.length,r,i=0,a=m,o=p,d=e.lastIndexOf(h),f,g,_,v,y,b,S,C;for(d<0&&(d=0),f=0;f<d;++f)e.charCodeAt(f)>=128&&w(`not-basic`),t.push(e.charCodeAt(f));for(g=d>0?d+1:0;g<n;){for(_=i,v=1,y=c;g>=n&&w(`invalid-input`),b=k(e.charCodeAt(g++)),(b>=c||b>x((s-i)/v))&&w(`overflow`),i+=b*v,S=y<=o?l:y>=o+u?u:y-o,!(b<S);y+=c)C=c-S,v>x(s/C)&&w(`overflow`),v*=C;r=t.length+1,o=j(i-_,r,_==0),x(i/r)>s-a&&w(`overflow`),a+=x(i/r),i%=r,t.splice(i++,0,a)}return O(t)}function N(e){var t,n,r,i,a,o,d,f,g,_,v,y=[],b,C,T,E;for(e=D(e),b=e.length,t=m,n=0,a=p,o=0;o<b;++o)v=e[o],v<128&&y.push(S(v));for(r=i=y.length,i&&y.push(h);r<b;){for(d=s,o=0;o<b;++o)v=e[o],v>=t&&v<d&&(d=v);for(C=r+1,d-t>x((s-n)/C)&&w(`overflow`),n+=(d-t)*C,t=d,o=0;o<b;++o)if(v=e[o],v<t&&++n>s&&w(`overflow`),v==t){for(f=n,g=c;_=g<=a?l:g>=a+u?u:g-a,!(f<_);g+=c)E=f-_,T=c-_,y.push(S(A(_+E%T,0))),f=x(E/T);y.push(S(A(f,0))),a=j(n,C,r==i),n=0,++r}++n,++t}return y.join(``)}function P(e){return E(e,function(e){return g.test(e)?M(e.slice(4).toLowerCase()):e})}function F(e){return E(e,function(e){return _.test(e)?`xn--`+N(e):e})}if(o={version:`1.4.1`,ucs2:{decode:D,encode:O},decode:M,encode:N,toASCII:F,toUnicode:P},typeof define==`function`&&typeof define.amd==`object`&&define.amd)define(`punycode`,function(){return o});else if(r&&i)if(t.exports==r)i.exports=o;else for(C in o)o.hasOwnProperty(C)&&(r[C]=o[C]);else n.punycode=o})(e)})),vv=r(((e,t)=>{t.exports=TypeError})),yv=r(((e,t)=>{t.exports={}})),bv=r(((e,t)=>{var n=typeof Map==`function`&&Map.prototype,r=Object.getOwnPropertyDescriptor&&n?Object.getOwnPropertyDescriptor(Map.prototype,`size`):null,i=n&&r&&typeof r.get==`function`?r.get:null,a=n&&Map.prototype.forEach,o=typeof Set==`function`&&Set.prototype,s=Object.getOwnPropertyDescriptor&&o?Object.getOwnPropertyDescriptor(Set.prototype,`size`):null,c=o&&s&&typeof s.get==`function`?s.get:null,l=o&&Set.prototype.forEach,u=typeof WeakMap==`function`&&WeakMap.prototype?WeakMap.prototype.has:null,d=typeof WeakSet==`function`&&WeakSet.prototype?WeakSet.prototype.has:null,f=typeof WeakRef==`function`&&WeakRef.prototype?WeakRef.prototype.deref:null,p=Boolean.prototype.valueOf,m=Object.prototype.toString,h=Function.prototype.toString,g=String.prototype.match,_=String.prototype.slice,v=String.prototype.replace,y=String.prototype.toUpperCase,b=String.prototype.toLowerCase,x=RegExp.prototype.test,S=Array.prototype.concat,C=Array.prototype.join,w=Array.prototype.slice,T=Math.floor,E=typeof BigInt==`function`?BigInt.prototype.valueOf:null,D=Object.getOwnPropertySymbols,O=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?Symbol.prototype.toString:null,k=typeof Symbol==`function`&&typeof Symbol.iterator==`object`,A=typeof Symbol==`function`&&Symbol.toStringTag&&(typeof Symbol.toStringTag===k||`symbol`)?Symbol.toStringTag:null,j=Object.prototype.propertyIsEnumerable,M=(typeof Reflect==`function`?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function N(e,t){if(e===1/0||e===-1/0||e!==e||e&&e>-1e3&&e<1e3||x.call(/e/,t))return t;var n=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof e==`number`){var r=e<0?-T(-e):T(e);if(r!==e){var i=String(r),a=_.call(t,i.length+1);return v.call(i,n,`$&_`)+`.`+v.call(v.call(a,/([0-9]{3})/g,`$&_`),/_$/,``)}}return v.call(t,n,`$&_`)}var P=yv(),F=P.custom,ee=fe(F)?F:null,te={__proto__:null,double:`"`,single:`'`},ne={__proto__:null,double:/(["\\])/g,single:/(['\\])/g};t.exports=function e(t,n,r,o){var s=n||{};if(he(s,`quoteStyle`)&&!he(te,s.quoteStyle))throw TypeError(`option "quoteStyle" must be "single" or "double"`);if(he(s,`maxStringLength`)&&(typeof s.maxStringLength==`number`?s.maxStringLength<0&&s.maxStringLength!==1/0:s.maxStringLength!==null))throw TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var u=he(s,`customInspect`)?s.customInspect:!0;if(typeof u!=`boolean`&&u!==`symbol`)throw TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(he(s,`indent`)&&s.indent!==null&&s.indent!==` `&&!(parseInt(s.indent,10)===s.indent&&s.indent>0))throw TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(he(s,`numericSeparator`)&&typeof s.numericSeparator!=`boolean`)throw TypeError('option "numericSeparator", if provided, must be `true` or `false`');var d=s.numericSeparator;if(t===void 0)return`undefined`;if(t===null)return`null`;if(typeof t==`boolean`)return t?`true`:`false`;if(typeof t==`string`)return Te(t,s);if(typeof t==`number`){if(t===0)return 1/0/t>0?`0`:`-0`;var f=String(t);return d?N(t,f):f}if(typeof t==`bigint`){var m=String(t)+`n`;return d?N(t,m):m}var h=s.depth===void 0?5:s.depth;if(r===void 0&&(r=0),r>=h&&h>0&&typeof t==`object`)return ae(t)?`[Array]`:`[Object]`;var g=je(s,r);if(o===void 0)o=[];else if(ve(o,t)>=0)return`[Circular]`;function y(t,n,i){if(n&&(o=w.call(o),o.push(n)),i){var a={depth:s.depth};return he(s,`quoteStyle`)&&(a.quoteStyle=s.quoteStyle),e(t,a,r+1,o)}return e(t,s,r+1,o)}if(typeof t==`function`&&!se(t)){var x=_e(t),T=Ne(t,y);return`[Function`+(x?`: `+x:` (anonymous)`)+`]`+(T.length>0?` { `+C.call(T,`, `)+` }`:``)}if(fe(t)){var D=k?v.call(String(t),/^(Symbol\(.*\))_[^)]*$/,`$1`):O.call(t);return typeof t==`object`&&!k?De(D):D}if(we(t)){for(var F=`<`+b.call(String(t.nodeName)),ne=t.attributes||[],I=0;I<ne.length;I++)F+=` `+ne[I].name+`=`+re(ie(ne[I].value),`double`,s);return F+=`>`,t.childNodes&&t.childNodes.length&&(F+=`...`),F+=`</`+b.call(String(t.nodeName))+`>`,F}if(ae(t)){if(t.length===0)return`[]`;var me=Ne(t,y);return g&&!Ae(me)?`[`+Me(me,g)+`]`:`[ `+C.call(me,`, `)+` ]`}if(ce(t)){var Ee=Ne(t,y);return!(`cause`in Error.prototype)&&`cause`in t&&!j.call(t,`cause`)?`{ [`+String(t)+`] `+C.call(S.call(`[cause]: `+y(t.cause),Ee),`, `)+` }`:Ee.length===0?`[`+String(t)+`]`:`{ [`+String(t)+`] `+C.call(Ee,`, `)+` }`}if(typeof t==`object`&&u){if(ee&&typeof t[ee]==`function`&&P)return P(t,{depth:h-r});if(u!==`symbol`&&typeof t.inspect==`function`)return t.inspect()}if(ye(t)){var Pe=[];return a&&a.call(t,function(e,n){Pe.push(y(n,t,!0)+` => `+y(e,t))}),ke(`Map`,i.call(t),Pe,g)}if(Se(t)){var Fe=[];return l&&l.call(t,function(e){Fe.push(y(e,t))}),ke(`Set`,c.call(t),Fe,g)}if(be(t))return Oe(`WeakMap`);if(Ce(t))return Oe(`WeakSet`);if(xe(t))return Oe(`WeakRef`);if(ue(t))return De(y(Number(t)));if(pe(t))return De(y(E.call(t)));if(de(t))return De(p.call(t));if(le(t))return De(y(String(t)));if(typeof window<`u`&&t===window)return`{ [object Window] }`;if(typeof globalThis<`u`&&t===globalThis||typeof global<`u`&&t===global)return`{ [object globalThis] }`;if(!oe(t)&&!se(t)){var Ie=Ne(t,y),Le=M?M(t)===Object.prototype:t instanceof Object||t.constructor===Object,Re=t instanceof Object?``:`null prototype`,ze=!Le&&A&&Object(t)===t&&A in t?_.call(ge(t),8,-1):Re?`Object`:``,Be=(Le||typeof t.constructor!=`function`?``:t.constructor.name?t.constructor.name+` `:``)+(ze||Re?`[`+C.call(S.call([],ze||[],Re||[]),`: `)+`] `:``);return Ie.length===0?Be+`{}`:g?Be+`{`+Me(Ie,g)+`}`:Be+`{ `+C.call(Ie,`, `)+` }`}return String(t)};function re(e,t,n){var r=te[n.quoteStyle||t];return r+e+r}function ie(e){return v.call(String(e),/"/g,`&quot;`)}function I(e){return!A||!(typeof e==`object`&&(A in e||e[A]!==void 0))}function ae(e){return ge(e)===`[object Array]`&&I(e)}function oe(e){return ge(e)===`[object Date]`&&I(e)}function se(e){return ge(e)===`[object RegExp]`&&I(e)}function ce(e){return ge(e)===`[object Error]`&&I(e)}function le(e){return ge(e)===`[object String]`&&I(e)}function ue(e){return ge(e)===`[object Number]`&&I(e)}function de(e){return ge(e)===`[object Boolean]`&&I(e)}function fe(e){if(k)return e&&typeof e==`object`&&e instanceof Symbol;if(typeof e==`symbol`)return!0;if(!e||typeof e!=`object`||!O)return!1;try{return O.call(e),!0}catch{}return!1}function pe(e){if(!e||typeof e!=`object`||!E)return!1;try{return E.call(e),!0}catch{}return!1}var me=Object.prototype.hasOwnProperty||function(e){return e in this};function he(e,t){return me.call(e,t)}function ge(e){return m.call(e)}function _e(e){if(e.name)return e.name;var t=g.call(h.call(e),/^function\s*([\w$]+)/);return t?t[1]:null}function ve(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1}function ye(e){if(!i||!e||typeof e!=`object`)return!1;try{i.call(e);try{c.call(e)}catch{return!0}return e instanceof Map}catch{}return!1}function be(e){if(!u||!e||typeof e!=`object`)return!1;try{u.call(e,u);try{d.call(e,d)}catch{return!0}return e instanceof WeakMap}catch{}return!1}function xe(e){if(!f||!e||typeof e!=`object`)return!1;try{return f.call(e),!0}catch{}return!1}function Se(e){if(!c||!e||typeof e!=`object`)return!1;try{c.call(e);try{i.call(e)}catch{return!0}return e instanceof Set}catch{}return!1}function Ce(e){if(!d||!e||typeof e!=`object`)return!1;try{d.call(e,d);try{u.call(e,u)}catch{return!0}return e instanceof WeakSet}catch{}return!1}function we(e){return!e||typeof e!=`object`?!1:typeof HTMLElement<`u`&&e instanceof HTMLElement?!0:typeof e.nodeName==`string`&&typeof e.getAttribute==`function`}function Te(e,t){if(e.length>t.maxStringLength){var n=e.length-t.maxStringLength,r=`... `+n+` more character`+(n>1?`s`:``);return Te(_.call(e,0,t.maxStringLength),t)+r}var i=ne[t.quoteStyle||`single`];return i.lastIndex=0,re(v.call(v.call(e,i,`\\$1`),/[\x00-\x1f]/g,Ee),`single`,t)}function Ee(e){var t=e.charCodeAt(0),n={8:`b`,9:`t`,10:`n`,12:`f`,13:`r`}[t];return n?`\\`+n:`\\x`+(t<16?`0`:``)+y.call(t.toString(16))}function De(e){return`Object(`+e+`)`}function Oe(e){return e+` { ? }`}function ke(e,t,n,r){var i=r?Me(n,r):C.call(n,`, `);return e+` (`+t+`) {`+i+`}`}function Ae(e){for(var t=0;t<e.length;t++)if(ve(e[t],`
90
90
  `)>=0)return!1;return!0}function je(e,t){var n;if(e.indent===` `)n=` `;else if(typeof e.indent==`number`&&e.indent>0)n=C.call(Array(e.indent+1),` `);else return null;return{base:n,prev:C.call(Array(t+1),n)}}function Me(e,t){if(e.length===0)return``;var n=`
91
91
  `+t.prev+t.base;return n+C.call(e,`,`+n)+`
92
- `+t.prev}function Ne(e,t){var n=ae(e),r=[];if(n){r.length=e.length;for(var i=0;i<e.length;i++)r[i]=he(e,i)?t(e[i],e):``}var a=typeof D==`function`?D(e):[],o;if(k){o={};for(var s=0;s<a.length;s++)o[`$`+a[s]]=a[s]}for(var c in e)he(e,c)&&(n&&String(Number(c))===c&&c<e.length||k&&o[`$`+c]instanceof Symbol||(x.call(/[^\w$]/,c)?r.push(t(c,e)+`: `+t(e[c],e)):r.push(c+`: `+t(e[c],e))));if(typeof D==`function`)for(var l=0;l<a.length;l++)j.call(e,a[l])&&r.push(`[`+t(a[l])+`]: `+t(e[a[l]],e));return r}})),vv=r(((e,t)=>{var n=_v(),r=hv(),i=function(e,t,n){for(var r=e,i;(i=r.next)!=null;r=i)if(i.key===t)return r.next=i.next,n||(i.next=e.next,e.next=i),i},a=function(e,t){if(e){var n=i(e,t);return n&&n.value}},o=function(e,t,n){var r=i(e,t);r?r.value=n:e.next={key:t,next:e.next,value:n}},s=function(e,t){return e?!!i(e,t):!1},c=function(e,t){if(e)return i(e,t,!0)};t.exports=function(){var e,t={assert:function(e){if(!t.has(e))throw new r(`Side channel does not contain `+n(e))},delete:function(t){var n=e&&e.next,r=c(e,t);return r&&n&&n===r&&(e=void 0),!!r},get:function(t){return a(e,t)},has:function(t){return s(e,t)},set:function(t,n){e||={next:void 0},o(e,t,n)}};return t}})),yv=r(((e,t)=>{t.exports=Object})),bv=r(((e,t)=>{t.exports=Error})),xv=r(((e,t)=>{t.exports=EvalError})),Sv=r(((e,t)=>{t.exports=RangeError})),Cv=r(((e,t)=>{t.exports=ReferenceError})),wv=r(((e,t)=>{t.exports=SyntaxError})),Tv=r(((e,t)=>{t.exports=URIError})),Ev=r(((e,t)=>{t.exports=Math.abs})),Dv=r(((e,t)=>{t.exports=Math.floor})),Ov=r(((e,t)=>{t.exports=Math.max})),kv=r(((e,t)=>{t.exports=Math.min})),Av=r(((e,t)=>{t.exports=Math.pow})),jv=r(((e,t)=>{t.exports=Math.round})),Mv=r(((e,t)=>{t.exports=Number.isNaN||function(e){return e!==e}})),Nv=r(((e,t)=>{var n=Mv();t.exports=function(e){return n(e)||e===0?e:e<0?-1:1}})),Pv=r(((e,t)=>{t.exports=Object.getOwnPropertyDescriptor})),Fv=r(((e,t)=>{var n=Pv();if(n)try{n([],`length`)}catch{n=null}t.exports=n})),Iv=r(((e,t)=>{var n=Object.defineProperty||!1;if(n)try{n({},`a`,{value:1})}catch{n=!1}t.exports=n})),Lv=r(((e,t)=>{t.exports=function(){if(typeof Symbol!=`function`||typeof Object.getOwnPropertySymbols!=`function`)return!1;if(typeof Symbol.iterator==`symbol`)return!0;var e={},t=Symbol(`test`),n=Object(t);if(typeof t==`string`||Object.prototype.toString.call(t)!==`[object Symbol]`||Object.prototype.toString.call(n)!==`[object Symbol]`)return!1;var r=42;for(var i in e[t]=r,e)return!1;if(typeof Object.keys==`function`&&Object.keys(e).length!==0||typeof Object.getOwnPropertyNames==`function`&&Object.getOwnPropertyNames(e).length!==0)return!1;var a=Object.getOwnPropertySymbols(e);if(a.length!==1||a[0]!==t||!Object.prototype.propertyIsEnumerable.call(e,t))return!1;if(typeof Object.getOwnPropertyDescriptor==`function`){var o=Object.getOwnPropertyDescriptor(e,t);if(o.value!==r||o.enumerable!==!0)return!1}return!0}})),Rv=r(((e,t)=>{var n=typeof Symbol<`u`&&Symbol,r=Lv();t.exports=function(){return typeof n!=`function`||typeof Symbol!=`function`||typeof n(`foo`)!=`symbol`||typeof Symbol(`bar`)!=`symbol`?!1:r()}})),zv=r(((e,t)=>{t.exports=typeof Reflect<`u`&&Reflect.getPrototypeOf||null})),Bv=r(((e,t)=>{t.exports=yv().getPrototypeOf||null})),Vv=r(((e,t)=>{var n=`Function.prototype.bind called on incompatible `,r=Object.prototype.toString,i=Math.max,a=`[object Function]`,o=function(e,t){for(var n=[],r=0;r<e.length;r+=1)n[r]=e[r];for(var i=0;i<t.length;i+=1)n[i+e.length]=t[i];return n},s=function(e,t){for(var n=[],r=t||0,i=0;r<e.length;r+=1,i+=1)n[i]=e[r];return n},c=function(e,t){for(var n=``,r=0;r<e.length;r+=1)n+=e[r],r+1<e.length&&(n+=t);return n};t.exports=function(e){var t=this;if(typeof t!=`function`||r.apply(t)!==a)throw TypeError(n+t);for(var l=s(arguments,1),u,d=function(){if(this instanceof u){var n=t.apply(this,o(l,arguments));return Object(n)===n?n:this}return t.apply(e,o(l,arguments))},f=i(0,t.length-l.length),p=[],m=0;m<f;m++)p[m]=`$`+m;if(u=Function(`binder`,`return function (`+c(p,`,`)+`){ return binder.apply(this,arguments); }`)(d),t.prototype){var h=function(){};h.prototype=t.prototype,u.prototype=new h,h.prototype=null}return u}})),Hv=r(((e,t)=>{var n=Vv();t.exports=Function.prototype.bind||n})),Uv=r(((e,t)=>{t.exports=Function.prototype.call})),Wv=r(((e,t)=>{t.exports=Function.prototype.apply})),Gv=r(((e,t)=>{t.exports=typeof Reflect<`u`&&Reflect&&Reflect.apply})),Kv=r(((e,t)=>{var n=Hv(),r=Wv(),i=Uv();t.exports=Gv()||n.call(i,r)})),qv=r(((e,t)=>{var n=Hv(),r=hv(),i=Uv(),a=Kv();t.exports=function(e){if(e.length<1||typeof e[0]!=`function`)throw new r(`a function is required`);return a(n,i,e)}})),Jv=r(((e,t)=>{var n=qv(),r=Fv(),i;try{i=[].__proto__===Array.prototype}catch(e){if(!e||typeof e!=`object`||!(`code`in e)||e.code!==`ERR_PROTO_ACCESS`)throw e}var a=!!i&&r&&r(Object.prototype,`__proto__`),o=Object,s=o.getPrototypeOf;t.exports=a&&typeof a.get==`function`?n([a.get]):typeof s==`function`?function(e){return s(e==null?e:o(e))}:!1})),Yv=r(((e,t)=>{var n=zv(),r=Bv(),i=Jv();t.exports=n?function(e){return n(e)}:r?function(e){if(!e||typeof e!=`object`&&typeof e!=`function`)throw TypeError(`getProto: not an object`);return r(e)}:i?function(e){return i(e)}:null})),Xv=r(((e,t)=>{var n=Function.prototype.call,r=Object.prototype.hasOwnProperty;t.exports=Hv().call(n,r)})),Zv=r(((e,t)=>{var n,r=yv(),i=bv(),a=xv(),o=Sv(),s=Cv(),c=wv(),l=hv(),u=Tv(),d=Ev(),f=Dv(),p=Ov(),m=kv(),h=Av(),g=jv(),_=Nv(),v=Function,y=function(e){try{return v(`"use strict"; return (`+e+`).constructor;`)()}catch{}},b=Fv(),x=Iv(),S=function(){throw new l},C=b?function(){try{return arguments.callee,S}catch{try{return b(arguments,`callee`).get}catch{return S}}}():S,w=Rv()(),T=Yv(),E=Bv(),D=zv(),O=Wv(),k=Uv(),A={},j=typeof Uint8Array>`u`||!T?n:T(Uint8Array),M={__proto__:null,"%AggregateError%":typeof AggregateError>`u`?n:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>`u`?n:ArrayBuffer,"%ArrayIteratorPrototype%":w&&T?T([][Symbol.iterator]()):n,"%AsyncFromSyncIteratorPrototype%":n,"%AsyncFunction%":A,"%AsyncGenerator%":A,"%AsyncGeneratorFunction%":A,"%AsyncIteratorPrototype%":A,"%Atomics%":typeof Atomics>`u`?n:Atomics,"%BigInt%":typeof BigInt>`u`?n:BigInt,"%BigInt64Array%":typeof BigInt64Array>`u`?n:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>`u`?n:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>`u`?n:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":i,"%eval%":eval,"%EvalError%":a,"%Float16Array%":typeof Float16Array>`u`?n:Float16Array,"%Float32Array%":typeof Float32Array>`u`?n:Float32Array,"%Float64Array%":typeof Float64Array>`u`?n:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>`u`?n:FinalizationRegistry,"%Function%":v,"%GeneratorFunction%":A,"%Int8Array%":typeof Int8Array>`u`?n:Int8Array,"%Int16Array%":typeof Int16Array>`u`?n:Int16Array,"%Int32Array%":typeof Int32Array>`u`?n:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":w&&T?T(T([][Symbol.iterator]())):n,"%JSON%":typeof JSON==`object`?JSON:n,"%Map%":typeof Map>`u`?n:Map,"%MapIteratorPrototype%":typeof Map>`u`||!w||!T?n:T(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":r,"%Object.getOwnPropertyDescriptor%":b,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>`u`?n:Promise,"%Proxy%":typeof Proxy>`u`?n:Proxy,"%RangeError%":o,"%ReferenceError%":s,"%Reflect%":typeof Reflect>`u`?n:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>`u`?n:Set,"%SetIteratorPrototype%":typeof Set>`u`||!w||!T?n:T(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>`u`?n:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":w&&T?T(``[Symbol.iterator]()):n,"%Symbol%":w?Symbol:n,"%SyntaxError%":c,"%ThrowTypeError%":C,"%TypedArray%":j,"%TypeError%":l,"%Uint8Array%":typeof Uint8Array>`u`?n:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>`u`?n:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>`u`?n:Uint16Array,"%Uint32Array%":typeof Uint32Array>`u`?n:Uint32Array,"%URIError%":u,"%WeakMap%":typeof WeakMap>`u`?n:WeakMap,"%WeakRef%":typeof WeakRef>`u`?n:WeakRef,"%WeakSet%":typeof WeakSet>`u`?n:WeakSet,"%Function.prototype.call%":k,"%Function.prototype.apply%":O,"%Object.defineProperty%":x,"%Object.getPrototypeOf%":E,"%Math.abs%":d,"%Math.floor%":f,"%Math.max%":p,"%Math.min%":m,"%Math.pow%":h,"%Math.round%":g,"%Math.sign%":_,"%Reflect.getPrototypeOf%":D};if(T)try{null.error}catch(e){M[`%Error.prototype%`]=T(T(e))}var N=function e(t){var n;if(t===`%AsyncFunction%`)n=y(`async function () {}`);else if(t===`%GeneratorFunction%`)n=y(`function* () {}`);else if(t===`%AsyncGeneratorFunction%`)n=y(`async function* () {}`);else if(t===`%AsyncGenerator%`){var r=e(`%AsyncGeneratorFunction%`);r&&(n=r.prototype)}else if(t===`%AsyncIteratorPrototype%`){var i=e(`%AsyncGenerator%`);i&&T&&(n=T(i.prototype))}return M[t]=n,n},P={__proto__:null,"%ArrayBufferPrototype%":[`ArrayBuffer`,`prototype`],"%ArrayPrototype%":[`Array`,`prototype`],"%ArrayProto_entries%":[`Array`,`prototype`,`entries`],"%ArrayProto_forEach%":[`Array`,`prototype`,`forEach`],"%ArrayProto_keys%":[`Array`,`prototype`,`keys`],"%ArrayProto_values%":[`Array`,`prototype`,`values`],"%AsyncFunctionPrototype%":[`AsyncFunction`,`prototype`],"%AsyncGenerator%":[`AsyncGeneratorFunction`,`prototype`],"%AsyncGeneratorPrototype%":[`AsyncGeneratorFunction`,`prototype`,`prototype`],"%BooleanPrototype%":[`Boolean`,`prototype`],"%DataViewPrototype%":[`DataView`,`prototype`],"%DatePrototype%":[`Date`,`prototype`],"%ErrorPrototype%":[`Error`,`prototype`],"%EvalErrorPrototype%":[`EvalError`,`prototype`],"%Float32ArrayPrototype%":[`Float32Array`,`prototype`],"%Float64ArrayPrototype%":[`Float64Array`,`prototype`],"%FunctionPrototype%":[`Function`,`prototype`],"%Generator%":[`GeneratorFunction`,`prototype`],"%GeneratorPrototype%":[`GeneratorFunction`,`prototype`,`prototype`],"%Int8ArrayPrototype%":[`Int8Array`,`prototype`],"%Int16ArrayPrototype%":[`Int16Array`,`prototype`],"%Int32ArrayPrototype%":[`Int32Array`,`prototype`],"%JSONParse%":[`JSON`,`parse`],"%JSONStringify%":[`JSON`,`stringify`],"%MapPrototype%":[`Map`,`prototype`],"%NumberPrototype%":[`Number`,`prototype`],"%ObjectPrototype%":[`Object`,`prototype`],"%ObjProto_toString%":[`Object`,`prototype`,`toString`],"%ObjProto_valueOf%":[`Object`,`prototype`,`valueOf`],"%PromisePrototype%":[`Promise`,`prototype`],"%PromiseProto_then%":[`Promise`,`prototype`,`then`],"%Promise_all%":[`Promise`,`all`],"%Promise_reject%":[`Promise`,`reject`],"%Promise_resolve%":[`Promise`,`resolve`],"%RangeErrorPrototype%":[`RangeError`,`prototype`],"%ReferenceErrorPrototype%":[`ReferenceError`,`prototype`],"%RegExpPrototype%":[`RegExp`,`prototype`],"%SetPrototype%":[`Set`,`prototype`],"%SharedArrayBufferPrototype%":[`SharedArrayBuffer`,`prototype`],"%StringPrototype%":[`String`,`prototype`],"%SymbolPrototype%":[`Symbol`,`prototype`],"%SyntaxErrorPrototype%":[`SyntaxError`,`prototype`],"%TypedArrayPrototype%":[`TypedArray`,`prototype`],"%TypeErrorPrototype%":[`TypeError`,`prototype`],"%Uint8ArrayPrototype%":[`Uint8Array`,`prototype`],"%Uint8ClampedArrayPrototype%":[`Uint8ClampedArray`,`prototype`],"%Uint16ArrayPrototype%":[`Uint16Array`,`prototype`],"%Uint32ArrayPrototype%":[`Uint32Array`,`prototype`],"%URIErrorPrototype%":[`URIError`,`prototype`],"%WeakMapPrototype%":[`WeakMap`,`prototype`],"%WeakSetPrototype%":[`WeakSet`,`prototype`]},F=Hv(),ee=Xv(),te=F.call(k,Array.prototype.concat),ne=F.call(O,Array.prototype.splice),re=F.call(k,String.prototype.replace),ie=F.call(k,String.prototype.slice),I=F.call(k,RegExp.prototype.exec),ae=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,oe=/\\(\\)?/g,se=function(e){var t=ie(e,0,1),n=ie(e,-1);if(t===`%`&&n!==`%`)throw new c("invalid intrinsic syntax, expected closing `%`");if(n===`%`&&t!==`%`)throw new c("invalid intrinsic syntax, expected opening `%`");var r=[];return re(e,ae,function(e,t,n,i){r[r.length]=n?re(i,oe,`$1`):t||e}),r},ce=function(e,t){var n=e,r;if(ee(P,n)&&(r=P[n],n=`%`+r[0]+`%`),ee(M,n)){var i=M[n];if(i===A&&(i=N(n)),i===void 0&&!t)throw new l(`intrinsic `+e+` exists, but is not available. Please file an issue!`);return{alias:r,name:n,value:i}}throw new c(`intrinsic `+e+` does not exist!`)};t.exports=function(e,t){if(typeof e!=`string`||e.length===0)throw new l(`intrinsic name must be a non-empty string`);if(arguments.length>1&&typeof t!=`boolean`)throw new l(`"allowMissing" argument must be a boolean`);if(I(/^%?[^%]*%?$/,e)===null)throw new c("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var n=se(e),r=n.length>0?n[0]:``,i=ce(`%`+r+`%`,t),a=i.name,o=i.value,s=!1,u=i.alias;u&&(r=u[0],ne(n,te([0,1],u)));for(var d=1,f=!0;d<n.length;d+=1){var p=n[d],m=ie(p,0,1),h=ie(p,-1);if((m===`"`||m===`'`||m==="`"||h===`"`||h===`'`||h==="`")&&m!==h)throw new c(`property names with quotes must have matching quotes`);if((p===`constructor`||!f)&&(s=!0),r+=`.`+p,a=`%`+r+`%`,ee(M,a))o=M[a];else if(o!=null){if(!(p in o)){if(!t)throw new l(`base intrinsic for `+e+` exists, but the property is not available.`);return}if(b&&d+1>=n.length){var g=b(o,p);f=!!g,o=f&&`get`in g&&!(`originalValue`in g.get)?g.get:o[p]}else f=ee(o,p),o=o[p];f&&!s&&(M[a]=o)}}return o}})),Qv=r(((e,t)=>{var n=Zv(),r=qv(),i=r([n(`%String.prototype.indexOf%`)]);t.exports=function(e,t){var a=n(e,!!t);return typeof a==`function`&&i(e,`.prototype.`)>-1?r([a]):a}})),$v=r(((e,t)=>{var n=Zv(),r=Qv(),i=_v(),a=hv(),o=n(`%Map%`,!0),s=r(`Map.prototype.get`,!0),c=r(`Map.prototype.set`,!0),l=r(`Map.prototype.has`,!0),u=r(`Map.prototype.delete`,!0),d=r(`Map.prototype.size`,!0);t.exports=!!o&&function(){var e,t={assert:function(e){if(!t.has(e))throw new a(`Side channel does not contain `+i(e))},delete:function(t){if(e){var n=u(e,t);return d(e)===0&&(e=void 0),n}return!1},get:function(t){if(e)return s(e,t)},has:function(t){return e?l(e,t):!1},set:function(t,n){e||=new o,c(e,t,n)}};return t}})),ey=r(((e,t)=>{var n=Zv(),r=Qv(),i=_v(),a=$v(),o=hv(),s=n(`%WeakMap%`,!0),c=r(`WeakMap.prototype.get`,!0),l=r(`WeakMap.prototype.set`,!0),u=r(`WeakMap.prototype.has`,!0),d=r(`WeakMap.prototype.delete`,!0);t.exports=s?function(){var e,t,n={assert:function(e){if(!n.has(e))throw new o(`Side channel does not contain `+i(e))},delete:function(n){if(s&&n&&(typeof n==`object`||typeof n==`function`)){if(e)return d(e,n)}else if(a&&t)return t.delete(n);return!1},get:function(n){return s&&n&&(typeof n==`object`||typeof n==`function`)&&e?c(e,n):t&&t.get(n)},has:function(n){return s&&n&&(typeof n==`object`||typeof n==`function`)&&e?u(e,n):!!t&&t.has(n)},set:function(n,r){s&&n&&(typeof n==`object`||typeof n==`function`)?(e||=new s,l(e,n,r)):a&&(t||=a(),t.set(n,r))}};return n}:a})),ty=r(((e,t)=>{var n=hv(),r=_v(),i=vv(),a=$v(),o=ey()||a||i;t.exports=function(){var e,t={assert:function(e){if(!t.has(e))throw new n(`Side channel does not contain `+r(e))},delete:function(t){return!!e&&e.delete(t)},get:function(t){return e&&e.get(t)},has:function(t){return!!e&&e.has(t)},set:function(t,n){e||=o(),e.set(t,n)}};return t}})),ny=r(((e,t)=>{var n=String.prototype.replace,r=/%20/g,i={RFC1738:`RFC1738`,RFC3986:`RFC3986`};t.exports={default:i.RFC3986,formatters:{RFC1738:function(e){return n.call(e,r,`+`)},RFC3986:function(e){return String(e)}},RFC1738:i.RFC1738,RFC3986:i.RFC3986}})),ry=r(((e,t)=>{var n=ny(),r=ty(),i=Object.prototype.hasOwnProperty,a=Array.isArray,o=r(),s=function(e,t){return o.set(e,t),e},c=function(e){return o.has(e)},l=function(e){return o.get(e)},u=function(e,t){o.set(e,t)},d=function(){for(var e=[],t=0;t<256;++t)e[e.length]=`%`+((t<16?`0`:``)+t.toString(16)).toUpperCase();return e}(),f=function(e){for(;e.length>1;){var t=e.pop(),n=t.obj[t.prop];if(a(n)){for(var r=[],i=0;i<n.length;++i)n[i]!==void 0&&(r[r.length]=n[i]);t.obj[t.prop]=r}}},p=function(e,t){for(var n=t&&t.plainObjects?{__proto__:null}:{},r=0;r<e.length;++r)e[r]!==void 0&&(n[r]=e[r]);return n},m=function e(t,n,r){if(!n)return t;if(typeof n!=`object`&&typeof n!=`function`){if(a(t)){var o=t.length;if(r&&typeof r.arrayLimit==`number`&&o>r.arrayLimit)return s(p(t.concat(n),r),o);t[o]=n}else if(t&&typeof t==`object`)if(c(t)){var d=l(t)+1;t[d]=n,u(t,d)}else if(r&&r.strictMerge)return[t,n];else (r&&(r.plainObjects||r.allowPrototypes)||!i.call(Object.prototype,n))&&(t[n]=!0);else return[t,n];return t}if(!t||typeof t!=`object`){if(c(n)){for(var f=Object.keys(n),m=r&&r.plainObjects?{__proto__:null,0:t}:{0:t},h=0;h<f.length;h++){var g=parseInt(f[h],10);m[g+1]=n[f[h]]}return s(m,l(n)+1)}var _=[t].concat(n);return r&&typeof r.arrayLimit==`number`&&_.length>r.arrayLimit?s(p(_,r),_.length-1):_}var v=t;return a(t)&&!a(n)&&(v=p(t,r)),a(t)&&a(n)?(n.forEach(function(n,a){if(i.call(t,a)){var o=t[a];o&&typeof o==`object`&&n&&typeof n==`object`?t[a]=e(o,n,r):t[t.length]=n}else t[a]=n}),t):Object.keys(n).reduce(function(t,a){var o=n[a];if(i.call(t,a)?t[a]=e(t[a],o,r):t[a]=o,c(n)&&!c(t)&&s(t,l(n)),c(t)){var d=parseInt(a,10);String(d)===a&&d>=0&&d>l(t)&&u(t,d)}return t},v)},h=function(e,t){return Object.keys(t).reduce(function(e,n){return e[n]=t[n],e},e)},g=function(e,t,n){var r=e.replace(/\+/g,` `);if(n===`iso-8859-1`)return r.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(r)}catch{return r}},_=1024;t.exports={arrayToObject:p,assign:h,combine:function(e,t,n,r){if(c(e)){var i=l(e)+1;return e[i]=t,u(e,i),e}var a=[].concat(e,t);return a.length>n?s(p(a,{plainObjects:r}),a.length-1):a},compact:function(e){for(var t=[{obj:{o:e},prop:`o`}],n=[],r=0;r<t.length;++r)for(var i=t[r],a=i.obj[i.prop],o=Object.keys(a),s=0;s<o.length;++s){var c=o[s],l=a[c];typeof l==`object`&&l&&n.indexOf(l)===-1&&(t[t.length]={obj:a,prop:c},n[n.length]=l)}return f(t),e},decode:g,encode:function(e,t,r,i,a){if(e.length===0)return e;var o=e;if(typeof e==`symbol`?o=Symbol.prototype.toString.call(e):typeof e!=`string`&&(o=String(e)),r===`iso-8859-1`)return escape(o).replace(/%u[0-9a-f]{4}/gi,function(e){return`%26%23`+parseInt(e.slice(2),16)+`%3B`});for(var s=``,c=0;c<o.length;c+=_){for(var l=o.length>=_?o.slice(c,c+_):o,u=[],f=0;f<l.length;++f){var p=l.charCodeAt(f);if(p===45||p===46||p===95||p===126||p>=48&&p<=57||p>=65&&p<=90||p>=97&&p<=122||a===n.RFC1738&&(p===40||p===41)){u[u.length]=l.charAt(f);continue}if(p<128){u[u.length]=d[p];continue}if(p<2048){u[u.length]=d[192|p>>6]+d[128|p&63];continue}if(p<55296||p>=57344){u[u.length]=d[224|p>>12]+d[128|p>>6&63]+d[128|p&63];continue}f+=1,p=65536+((p&1023)<<10|l.charCodeAt(f)&1023),u[u.length]=d[240|p>>18]+d[128|p>>12&63]+d[128|p>>6&63]+d[128|p&63]}s+=u.join(``)}return s},isBuffer:function(e){return!e||typeof e!=`object`?!1:!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isOverflow:c,isRegExp:function(e){return Object.prototype.toString.call(e)===`[object RegExp]`},markOverflow:s,maybeMap:function(e,t){if(a(e)){for(var n=[],r=0;r<e.length;r+=1)n[n.length]=t(e[r]);return n}return t(e)},merge:m}})),iy=r(((e,t)=>{var n=ty(),r=ry(),i=ny(),a=Object.prototype.hasOwnProperty,o={brackets:function(e){return e+`[]`},comma:`comma`,indices:function(e,t){return e+`[`+t+`]`},repeat:function(e){return e}},s=Array.isArray,c=Array.prototype.push,l=function(e,t){c.apply(e,s(t)?t:[t])},u=Date.prototype.toISOString,d=i.default,f={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:`indices`,charset:`utf-8`,charsetSentinel:!1,commaRoundTrip:!1,delimiter:`&`,encode:!0,encodeDotInKeys:!1,encoder:r.encode,encodeValuesOnly:!1,filter:void 0,format:d,formatter:i.formatters[d],indices:!1,serializeDate:function(e){return u.call(e)},skipNulls:!1,strictNullHandling:!1},p=function(e){return typeof e==`string`||typeof e==`number`||typeof e==`boolean`||typeof e==`symbol`||typeof e==`bigint`},m={},h=function e(t,i,a,o,c,u,d,h,g,_,v,y,b,x,S,C,w,T){for(var E=t,D=T,O=0,k=!1;(D=D.get(m))!==void 0&&!k;){var A=D.get(t);if(O+=1,A!==void 0){if(A===O)throw RangeError(`Cyclic object value`);k=!0}D.get(m)===void 0&&(O=0)}if(typeof _==`function`?E=_(i,E):E instanceof Date?E=b(E):a===`comma`&&s(E)&&(E=r.maybeMap(E,function(e){return e instanceof Date?b(e):e})),E===null){if(u)return g&&!C?g(i,f.encoder,w,`key`,x):i;E=``}if(p(E)||r.isBuffer(E))return g?[S(C?i:g(i,f.encoder,w,`key`,x))+`=`+S(g(E,f.encoder,w,`value`,x))]:[S(i)+`=`+S(String(E))];var j=[];if(E===void 0)return j;var M;if(a===`comma`&&s(E))C&&g&&(E=r.maybeMap(E,g)),M=[{value:E.length>0?E.join(`,`)||null:void 0}];else if(s(_))M=_;else{var N=Object.keys(E);M=v?N.sort(v):N}var P=h?String(i).replace(/\./g,`%2E`):String(i),F=o&&s(E)&&E.length===1?P+`[]`:P;if(c&&s(E)&&E.length===0)return F+`[]`;for(var ee=0;ee<M.length;++ee){var te=M[ee],ne=typeof te==`object`&&te&&te.value!==void 0?te.value:E[te];if(!(d&&ne===null)){var re=y&&h?String(te).replace(/\./g,`%2E`):String(te),ie=s(E)?typeof a==`function`?a(F,re):F:F+(y?`.`+re:`[`+re+`]`);T.set(t,O);var I=n();I.set(m,T),l(j,e(ne,ie,a,o,c,u,d,h,a===`comma`&&C&&s(E)?null:g,_,v,y,b,x,S,C,w,I))}}return j},g=function(e){if(!e)return f;if(e.allowEmptyArrays!==void 0&&typeof e.allowEmptyArrays!=`boolean`)throw TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(e.encodeDotInKeys!==void 0&&typeof e.encodeDotInKeys!=`boolean`)throw TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(e.encoder!==null&&e.encoder!==void 0&&typeof e.encoder!=`function`)throw TypeError(`Encoder has to be a function.`);var t=e.charset||f.charset;if(e.charset!==void 0&&e.charset!==`utf-8`&&e.charset!==`iso-8859-1`)throw TypeError(`The charset option must be either utf-8, iso-8859-1, or undefined`);var n=i.default;if(e.format!==void 0){if(!a.call(i.formatters,e.format))throw TypeError(`Unknown format option provided.`);n=e.format}var r=i.formatters[n],c=f.filter;(typeof e.filter==`function`||s(e.filter))&&(c=e.filter);var l=e.arrayFormat in o?e.arrayFormat:`indices`in e?e.indices?`indices`:`repeat`:f.arrayFormat;if(`commaRoundTrip`in e&&typeof e.commaRoundTrip!=`boolean`)throw TypeError("`commaRoundTrip` must be a boolean, or absent");var u=e.allowDots===void 0?e.encodeDotInKeys===!0?!0:f.allowDots:!!e.allowDots;return{addQueryPrefix:typeof e.addQueryPrefix==`boolean`?e.addQueryPrefix:f.addQueryPrefix,allowDots:u,allowEmptyArrays:typeof e.allowEmptyArrays==`boolean`?!!e.allowEmptyArrays:f.allowEmptyArrays,arrayFormat:l,charset:t,charsetSentinel:typeof e.charsetSentinel==`boolean`?e.charsetSentinel:f.charsetSentinel,commaRoundTrip:!!e.commaRoundTrip,delimiter:e.delimiter===void 0?f.delimiter:e.delimiter,encode:typeof e.encode==`boolean`?e.encode:f.encode,encodeDotInKeys:typeof e.encodeDotInKeys==`boolean`?e.encodeDotInKeys:f.encodeDotInKeys,encoder:typeof e.encoder==`function`?e.encoder:f.encoder,encodeValuesOnly:typeof e.encodeValuesOnly==`boolean`?e.encodeValuesOnly:f.encodeValuesOnly,filter:c,format:n,formatter:r,serializeDate:typeof e.serializeDate==`function`?e.serializeDate:f.serializeDate,skipNulls:typeof e.skipNulls==`boolean`?e.skipNulls:f.skipNulls,sort:typeof e.sort==`function`?e.sort:null,strictNullHandling:typeof e.strictNullHandling==`boolean`?e.strictNullHandling:f.strictNullHandling}};t.exports=function(e,t){var r=e,i=g(t),a,c;typeof i.filter==`function`?(c=i.filter,r=c(``,r)):s(i.filter)&&(c=i.filter,a=c);var u=[];if(typeof r!=`object`||!r)return``;var d=o[i.arrayFormat],f=d===`comma`&&i.commaRoundTrip;a||=Object.keys(r),i.sort&&a.sort(i.sort);for(var p=n(),m=0;m<a.length;++m){var _=a[m],v=r[_];i.skipNulls&&v===null||l(u,h(v,_,d,f,i.allowEmptyArrays,i.strictNullHandling,i.skipNulls,i.encodeDotInKeys,i.encode?i.encoder:null,i.filter,i.sort,i.allowDots,i.serializeDate,i.format,i.formatter,i.encodeValuesOnly,i.charset,p))}var y=u.join(i.delimiter),b=i.addQueryPrefix===!0?`?`:``;return i.charsetSentinel&&(i.charset===`iso-8859-1`?b+=`utf8=%26%2310003%3B&`:b+=`utf8=%E2%9C%93&`),y.length>0?b+y:``}})),ay=r(((e,t)=>{var n=ry(),r=Object.prototype.hasOwnProperty,i=Array.isArray,a={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:`utf-8`,charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:n.decode,delimiter:`&`,depth:5,duplicates:`combine`,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictMerge:!0,strictNullHandling:!1,throwOnLimitExceeded:!1},o=function(e){return e.replace(/&#(\d+);/g,function(e,t){return String.fromCharCode(parseInt(t,10))})},s=function(e,t,n){if(e&&typeof e==`string`&&t.comma&&e.indexOf(`,`)>-1)return e.split(`,`);if(t.throwOnLimitExceeded&&n>=t.arrayLimit)throw RangeError(`Array limit exceeded. Only `+t.arrayLimit+` element`+(t.arrayLimit===1?``:`s`)+` allowed in an array.`);return e},c=`utf8=%26%2310003%3B`,l=`utf8=%E2%9C%93`,u=function(e,t){var u={__proto__:null},d=t.ignoreQueryPrefix?e.replace(/^\?/,``):e;d=d.replace(/%5B/gi,`[`).replace(/%5D/gi,`]`);var f=t.parameterLimit===1/0?void 0:t.parameterLimit,p=d.split(t.delimiter,t.throwOnLimitExceeded?f+1:f);if(t.throwOnLimitExceeded&&p.length>f)throw RangeError(`Parameter limit exceeded. Only `+f+` parameter`+(f===1?``:`s`)+` allowed.`);var m=-1,h,g=t.charset;if(t.charsetSentinel)for(h=0;h<p.length;++h)p[h].indexOf(`utf8=`)===0&&(p[h]===l?g=`utf-8`:p[h]===c&&(g=`iso-8859-1`),m=h,h=p.length);for(h=0;h<p.length;++h)if(h!==m){var _=p[h],v=_.indexOf(`]=`),y=v===-1?_.indexOf(`=`):v+1,b,x;if(y===-1?(b=t.decoder(_,a.decoder,g,`key`),x=t.strictNullHandling?null:``):(b=t.decoder(_.slice(0,y),a.decoder,g,`key`),b!==null&&(x=n.maybeMap(s(_.slice(y+1),t,i(u[b])?u[b].length:0),function(e){return t.decoder(e,a.decoder,g,`value`)}))),x&&t.interpretNumericEntities&&g===`iso-8859-1`&&(x=o(String(x))),_.indexOf(`[]=`)>-1&&(x=i(x)?[x]:x),t.comma&&i(x)&&x.length>t.arrayLimit){if(t.throwOnLimitExceeded)throw RangeError(`Array limit exceeded. Only `+t.arrayLimit+` element`+(t.arrayLimit===1?``:`s`)+` allowed in an array.`);x=n.combine([],x,t.arrayLimit,t.plainObjects)}if(b!==null){var S=r.call(u,b);S&&(t.duplicates===`combine`||_.indexOf(`[]=`)>-1)?u[b]=n.combine(u[b],x,t.arrayLimit,t.plainObjects):(!S||t.duplicates===`last`)&&(u[b]=x)}}return u},d=function(e,t,r,i){var a=0;if(e.length>0&&e[e.length-1]===`[]`){var o=e.slice(0,-1).join(``);a=Array.isArray(t)&&t[o]?t[o].length:0}for(var c=i?t:s(t,r,a),l=e.length-1;l>=0;--l){var u,d=e[l];if(d===`[]`&&r.parseArrays)u=n.isOverflow(c)?c:r.allowEmptyArrays&&(c===``||r.strictNullHandling&&c===null)?[]:n.combine([],c,r.arrayLimit,r.plainObjects);else{u=r.plainObjects?{__proto__:null}:{};var f=d.charAt(0)===`[`&&d.charAt(d.length-1)===`]`?d.slice(1,-1):d,p=r.decodeDotInKeys?f.replace(/%2E/g,`.`):f,m=parseInt(p,10),h=!isNaN(m)&&d!==p&&String(m)===p&&m>=0&&r.parseArrays;if(!r.parseArrays&&p===``)u={0:c};else if(h&&m<r.arrayLimit)u=[],u[m]=c;else if(h&&r.throwOnLimitExceeded)throw RangeError(`Array limit exceeded. Only `+r.arrayLimit+` element`+(r.arrayLimit===1?``:`s`)+` allowed in an array.`);else h?(u[m]=c,n.markOverflow(u,m)):p!==`__proto__`&&(u[p]=c)}c=u}return c},f=function(e,t){var n=t.allowDots?e.replace(/\.([^.[]+)/g,`[$1]`):e;if(t.depth<=0)return!t.plainObjects&&r.call(Object.prototype,n)&&!t.allowPrototypes?void 0:[n];var i=/(\[[^[\]]*])/,a=/(\[[^[\]]*])/g,o=i.exec(n),s=o?n.slice(0,o.index):n,c=[];if(s){if(!t.plainObjects&&r.call(Object.prototype,s)&&!t.allowPrototypes)return;c[c.length]=s}for(var l=0;(o=a.exec(n))!==null&&l<t.depth;){l+=1;var u=o[1].slice(1,-1);if(!t.plainObjects&&r.call(Object.prototype,u)&&!t.allowPrototypes)return;c[c.length]=o[1]}if(o){if(t.strictDepth===!0)throw RangeError(`Input depth exceeded depth option of `+t.depth+` and strictDepth is true`);c[c.length]=`[`+n.slice(o.index)+`]`}return c},p=function(e,t,n,r){if(e){var i=f(e,n);if(i)return d(i,t,n,r)}},m=function(e){if(!e)return a;if(e.allowEmptyArrays!==void 0&&typeof e.allowEmptyArrays!=`boolean`)throw TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(e.decodeDotInKeys!==void 0&&typeof e.decodeDotInKeys!=`boolean`)throw TypeError("`decodeDotInKeys` option can only be `true` or `false`, when provided");if(e.decoder!==null&&e.decoder!==void 0&&typeof e.decoder!=`function`)throw TypeError(`Decoder has to be a function.`);if(e.charset!==void 0&&e.charset!==`utf-8`&&e.charset!==`iso-8859-1`)throw TypeError(`The charset option must be either utf-8, iso-8859-1, or undefined`);if(e.throwOnLimitExceeded!==void 0&&typeof e.throwOnLimitExceeded!=`boolean`)throw TypeError("`throwOnLimitExceeded` option must be a boolean");var t=e.charset===void 0?a.charset:e.charset,r=e.duplicates===void 0?a.duplicates:e.duplicates;if(r!==`combine`&&r!==`first`&&r!==`last`)throw TypeError(`The duplicates option must be either combine, first, or last`);return{allowDots:e.allowDots===void 0?e.decodeDotInKeys===!0?!0:a.allowDots:!!e.allowDots,allowEmptyArrays:typeof e.allowEmptyArrays==`boolean`?!!e.allowEmptyArrays:a.allowEmptyArrays,allowPrototypes:typeof e.allowPrototypes==`boolean`?e.allowPrototypes:a.allowPrototypes,allowSparse:typeof e.allowSparse==`boolean`?e.allowSparse:a.allowSparse,arrayLimit:typeof e.arrayLimit==`number`?e.arrayLimit:a.arrayLimit,charset:t,charsetSentinel:typeof e.charsetSentinel==`boolean`?e.charsetSentinel:a.charsetSentinel,comma:typeof e.comma==`boolean`?e.comma:a.comma,decodeDotInKeys:typeof e.decodeDotInKeys==`boolean`?e.decodeDotInKeys:a.decodeDotInKeys,decoder:typeof e.decoder==`function`?e.decoder:a.decoder,delimiter:typeof e.delimiter==`string`||n.isRegExp(e.delimiter)?e.delimiter:a.delimiter,depth:typeof e.depth==`number`||e.depth===!1?+e.depth:a.depth,duplicates:r,ignoreQueryPrefix:e.ignoreQueryPrefix===!0,interpretNumericEntities:typeof e.interpretNumericEntities==`boolean`?e.interpretNumericEntities:a.interpretNumericEntities,parameterLimit:typeof e.parameterLimit==`number`?e.parameterLimit:a.parameterLimit,parseArrays:e.parseArrays!==!1,plainObjects:typeof e.plainObjects==`boolean`?e.plainObjects:a.plainObjects,strictDepth:typeof e.strictDepth==`boolean`?!!e.strictDepth:a.strictDepth,strictMerge:typeof e.strictMerge==`boolean`?!!e.strictMerge:a.strictMerge,strictNullHandling:typeof e.strictNullHandling==`boolean`?e.strictNullHandling:a.strictNullHandling,throwOnLimitExceeded:typeof e.throwOnLimitExceeded==`boolean`?e.throwOnLimitExceeded:!1}};t.exports=function(e,t){var r=m(t);if(e===``||e==null)return r.plainObjects?{__proto__:null}:{};for(var i=typeof e==`string`?u(e,r):e,a=r.plainObjects?{__proto__:null}:{},o=Object.keys(i),s=0;s<o.length;++s){var c=o[s],l=p(c,i[c],r,typeof e==`string`);a=n.merge(a,l,r)}return r.allowSparse===!0?a:n.compact(a)}})),oy=r(((e,t)=>{var n=iy(),r=ay();t.exports={formats:ny(),parse:r,stringify:n}})),sy=r((e=>{var t=mv();function n(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var r=/^([a-z0-9.+-]+:)/i,i=/:[0-9]*$/,a=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,o=[`'`,`{`,`}`,`|`,`\\`,`^`,"`",`<`,`>`,`"`,"`",` `,`\r`,`
93
- `,` `],s=[`%`,`/`,`?`,`;`,`#`].concat(o),c=[`/`,`?`,`#`],l=255,u=/^[+a-z0-9A-Z_-]{0,63}$/,d=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,f={javascript:!0,"javascript:":!0},p={javascript:!0,"javascript:":!0},m={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},h=oy();function g(e,t,r){if(e&&typeof e==`object`&&e instanceof n)return e;var i=new n;return i.parse(e,t,r),i}n.prototype.parse=function(e,n,i){if(typeof e!=`string`)throw TypeError(`Parameter 'url' must be a string, not `+typeof e);var g=e.indexOf(`?`),_=g!==-1&&g<e.indexOf(`#`)?`?`:`#`,v=e.split(_);v[0]=v[0].replace(/\\/g,`/`),e=v.join(_);var y=e;if(y=y.trim(),!i&&e.split(`#`).length===1){var b=a.exec(y);if(b)return this.path=y,this.href=y,this.pathname=b[1],b[2]?(this.search=b[2],n?this.query=h.parse(this.search.substr(1)):this.query=this.search.substr(1)):n&&(this.search=``,this.query={}),this}var x=r.exec(y);if(x){x=x[0];var S=x.toLowerCase();this.protocol=S,y=y.substr(x.length)}if(i||x||y.match(/^\/\/[^@/]+@[^@/]+/)){var C=y.substr(0,2)===`//`;C&&!(x&&p[x])&&(y=y.substr(2),this.slashes=!0)}if(!p[x]&&(C||x&&!m[x])){for(var w=-1,T=0;T<c.length;T++){var E=y.indexOf(c[T]);E!==-1&&(w===-1||E<w)&&(w=E)}var D,O=w===-1?y.lastIndexOf(`@`):y.lastIndexOf(`@`,w);O!==-1&&(D=y.slice(0,O),y=y.slice(O+1),this.auth=decodeURIComponent(D)),w=-1;for(var T=0;T<s.length;T++){var E=y.indexOf(s[T]);E!==-1&&(w===-1||E<w)&&(w=E)}w===-1&&(w=y.length),this.host=y.slice(0,w),y=y.slice(w),this.parseHost(),this.hostname=this.hostname||``;var k=this.hostname[0]===`[`&&this.hostname[this.hostname.length-1]===`]`;if(!k)for(var A=this.hostname.split(/\./),T=0,j=A.length;T<j;T++){var M=A[T];if(M&&!M.match(u)){for(var N=``,P=0,F=M.length;P<F;P++)M.charCodeAt(P)>127?N+=`x`:N+=M[P];if(!N.match(u)){var ee=A.slice(0,T),te=A.slice(T+1),ne=M.match(d);ne&&(ee.push(ne[1]),te.unshift(ne[2])),te.length&&(y=`/`+te.join(`.`)+y),this.hostname=ee.join(`.`);break}}}this.hostname.length>l?this.hostname=``:this.hostname=this.hostname.toLowerCase(),k||(this.hostname=t.toASCII(this.hostname));var re=this.port?`:`+this.port:``;this.host=(this.hostname||``)+re,this.href+=this.host,k&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),y[0]!==`/`&&(y=`/`+y))}if(!f[S])for(var T=0,j=o.length;T<j;T++){var ie=o[T];if(y.indexOf(ie)!==-1){var I=encodeURIComponent(ie);I===ie&&(I=escape(ie)),y=y.split(ie).join(I)}}var ae=y.indexOf(`#`);ae!==-1&&(this.hash=y.substr(ae),y=y.slice(0,ae));var oe=y.indexOf(`?`);if(oe===-1?n&&(this.search=``,this.query={}):(this.search=y.substr(oe),this.query=y.substr(oe+1),n&&(this.query=h.parse(this.query)),y=y.slice(0,oe)),y&&(this.pathname=y),m[S]&&this.hostname&&!this.pathname&&(this.pathname=`/`),this.pathname||this.search){var re=this.pathname||``;this.path=re+(this.search||``)}return this.href=this.format(),this};function _(e){return typeof e==`string`&&(e=g(e)),e instanceof n?e.format():n.prototype.format.call(e)}n.prototype.format=function(){var e=this.auth||``;e&&(e=encodeURIComponent(e),e=e.replace(/%3A/i,`:`),e+=`@`);var t=this.protocol||``,n=this.pathname||``,r=this.hash||``,i=!1,a=``;this.host?i=e+this.host:this.hostname&&(i=e+(this.hostname.indexOf(`:`)===-1?this.hostname:`[`+this.hostname+`]`),this.port&&(i+=`:`+this.port)),this.query&&typeof this.query==`object`&&Object.keys(this.query).length&&(a=h.stringify(this.query,{arrayFormat:`repeat`,addQueryPrefix:!1}));var o=this.search||a&&`?`+a||``;return t&&t.substr(-1)!==`:`&&(t+=`:`),this.slashes||(!t||m[t])&&i!==!1?(i=`//`+(i||``),n&&n.charAt(0)!==`/`&&(n=`/`+n)):i||=``,r&&r.charAt(0)!==`#`&&(r=`#`+r),o&&o.charAt(0)!==`?`&&(o=`?`+o),n=n.replace(/[?#]/g,function(e){return encodeURIComponent(e)}),o=o.replace(`#`,`%23`),t+i+n+o+r};function v(e,t){return g(e,!1,!0).resolve(t)}n.prototype.resolve=function(e){return this.resolveObject(g(e,!1,!0)).format()};function y(e,t){return e?g(e,!1,!0).resolveObject(t):t}n.prototype.resolveObject=function(e){if(typeof e==`string`){var t=new n;t.parse(e,!1,!0),e=t}for(var r=new n,i=Object.keys(this),a=0;a<i.length;a++){var o=i[a];r[o]=this[o]}if(r.hash=e.hash,e.href===``)return r.href=r.format(),r;if(e.slashes&&!e.protocol){for(var s=Object.keys(e),c=0;c<s.length;c++){var l=s[c];l!==`protocol`&&(r[l]=e[l])}return m[r.protocol]&&r.hostname&&!r.pathname&&(r.pathname=`/`,r.path=r.pathname),r.href=r.format(),r}if(e.protocol&&e.protocol!==r.protocol){if(!m[e.protocol]){for(var u=Object.keys(e),d=0;d<u.length;d++){var f=u[d];r[f]=e[f]}return r.href=r.format(),r}if(r.protocol=e.protocol,!e.host&&!p[e.protocol]){for(var h=(e.pathname||``).split(`/`);h.length&&!(e.host=h.shift()););e.host||=``,e.hostname||=``,h[0]!==``&&h.unshift(``),h.length<2&&h.unshift(``),r.pathname=h.join(`/`)}else r.pathname=e.pathname;return r.search=e.search,r.query=e.query,r.host=e.host||``,r.auth=e.auth,r.hostname=e.hostname||e.host,r.port=e.port,(r.pathname||r.search)&&(r.path=(r.pathname||``)+(r.search||``)),r.slashes=r.slashes||e.slashes,r.href=r.format(),r}var g=r.pathname&&r.pathname.charAt(0)===`/`,_=e.host||e.pathname&&e.pathname.charAt(0)===`/`,v=_||g||r.host&&e.pathname,y=v,b=r.pathname&&r.pathname.split(`/`)||[],h=e.pathname&&e.pathname.split(`/`)||[],x=r.protocol&&!m[r.protocol];if(x&&(r.hostname=``,r.port=null,r.host&&(b[0]===``?b[0]=r.host:b.unshift(r.host)),r.host=``,e.protocol&&(e.hostname=null,e.port=null,e.host&&(h[0]===``?h[0]=e.host:h.unshift(e.host)),e.host=null),v&&=h[0]===``||b[0]===``),_)r.host=e.host||e.host===``?e.host:r.host,r.hostname=e.hostname||e.hostname===``?e.hostname:r.hostname,r.search=e.search,r.query=e.query,b=h;else if(h.length)b||=[],b.pop(),b=b.concat(h),r.search=e.search,r.query=e.query;else if(e.search!=null){if(x){r.host=b.shift(),r.hostname=r.host;var S=r.host&&r.host.indexOf(`@`)>0?r.host.split(`@`):!1;S&&(r.auth=S.shift(),r.hostname=S.shift(),r.host=r.hostname)}return r.search=e.search,r.query=e.query,(r.pathname!==null||r.search!==null)&&(r.path=(r.pathname?r.pathname:``)+(r.search?r.search:``)),r.href=r.format(),r}if(!b.length)return r.pathname=null,r.search?r.path=`/`+r.search:r.path=null,r.href=r.format(),r;for(var C=b.slice(-1)[0],w=(r.host||e.host||b.length>1)&&(C===`.`||C===`..`)||C===``,T=0,E=b.length;E>=0;E--)C=b[E],C===`.`?b.splice(E,1):C===`..`?(b.splice(E,1),T++):T&&(b.splice(E,1),T--);if(!v&&!y)for(;T--;)b.unshift(`..`);v&&b[0]!==``&&(!b[0]||b[0].charAt(0)!==`/`)&&b.unshift(``),w&&b.join(`/`).substr(-1)!==`/`&&b.push(``);var D=b[0]===``||b[0]&&b[0].charAt(0)===`/`;if(x){r.hostname=D?``:b.length?b.shift():``,r.host=r.hostname;var S=r.host&&r.host.indexOf(`@`)>0?r.host.split(`@`):!1;S&&(r.auth=S.shift(),r.hostname=S.shift(),r.host=r.hostname)}return v||=r.host&&b.length,v&&!D&&b.unshift(``),b.length>0?r.pathname=b.join(`/`):(r.pathname=null,r.path=null),(r.pathname!==null||r.search!==null)&&(r.path=(r.pathname?r.pathname:``)+(r.search?r.search:``)),r.auth=e.auth||r.auth,r.slashes=r.slashes||e.slashes,r.href=r.format(),r},n.prototype.parseHost=function(){var e=this.host,t=i.exec(e);t&&(t=t[0],t!==`:`&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)},e.parse=g,e.resolve=v,e.resolveObject=y,e.format=_,e.Url=n})),cy=r(((e,t)=>{(function(e,n){typeof define==`function`&&define.amd?define([],n):typeof t==`object`&&t.exports?t.exports=n():e.xmlserializer=n()})(e,function(){var e=function(e){return e.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g,``)},t=function(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&apos;`)},n=function(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)},r=function(e){var n=e.value;return` `+e.name+`="`+t(n)+`"`},i=function(e){var t=e.tagName;return e.namespaceURI===`http://www.w3.org/1999/xhtml`&&(t=t.toLowerCase()),t},a=function(e,t){return!(Array.prototype.map.call(e.attributes||e.attrs,function(e){return e.name}).indexOf(`xmlns`)>=0)&&(t||e.namespaceURI!==e.parentNode.namespaceURI)?` xmlns="`+e.namespaceURI+`"`:``},o=function(e){return Array.prototype.map.call(e.childNodes,function(e){return d(e)}).join(``)},s=function(e,t){var n=`<`+i(e);return n+=a(e,t),Array.prototype.forEach.call(e.attributes||e.attrs,function(e){n+=r(e)}),e.childNodes.length>0?(n+=`>`,n+=o(e),n+=`</`+i(e)+`>`):n+=`/>`,n},c=function(e){return n(e.nodeValue||e.value||``)},l=function(e){return`<!--`+e.data.replace(/-/g,`&#45;`)+`-->`},u=function(e){return`<![CDATA[`+e.nodeValue+`]]>`},d=function(e,t){var n=t&&t.rootNode;if(e.nodeName===`#document`||e.nodeName===`#document-fragment`)return o(e);if(e.tagName)return s(e,n);if(e.nodeName===`#text`)return c(e);if(e.nodeName===`#comment`)return l(e);if(e.nodeName===`#cdata-section`)return u(e)};return{serializeToString:function(t){return e(d(t,{rootNode:!0}))}}})})),ly=r((e=>{var t=function(e){var t=new XMLSerializer;return Array.prototype.map.call(e.childNodes,function(e){return t.serializeToString(e)}).join(``)},n=function(e){if(e.documentElement.tagName===`parsererror`&&e.documentElement.namespaceURI===`http://www.mozilla.org/newlayout/xml/parsererror.xml`)return e.documentElement;if((e.documentElement.tagName===`xml`||e.documentElement.tagName===`html`)&&e.documentElement.childNodes&&e.documentElement.childNodes.length>0&&e.documentElement.childNodes[0].nodeName===`parsererror`)return e.documentElement.childNodes[0];if(e.documentElement.tagName===`html`&&e.documentElement.childNodes&&e.documentElement.childNodes.length>0&&e.documentElement.childNodes[0].nodeName===`body`&&e.documentElement.childNodes[0].childNodes&&e.documentElement.childNodes[0].childNodes.length&&e.documentElement.childNodes[0].childNodes[0].nodeName===`parsererror`)return e.documentElement.childNodes[0].childNodes[0]},r=[RegExp(`^<h3[^>]*>This page contains the following errors:</h3><div[^>]*>(.+?)
92
+ `+t.prev}function Ne(e,t){var n=ae(e),r=[];if(n){r.length=e.length;for(var i=0;i<e.length;i++)r[i]=he(e,i)?t(e[i],e):``}var a=typeof D==`function`?D(e):[],o;if(k){o={};for(var s=0;s<a.length;s++)o[`$`+a[s]]=a[s]}for(var c in e)he(e,c)&&(n&&String(Number(c))===c&&c<e.length||k&&o[`$`+c]instanceof Symbol||(x.call(/[^\w$]/,c)?r.push(t(c,e)+`: `+t(e[c],e)):r.push(c+`: `+t(e[c],e))));if(typeof D==`function`)for(var l=0;l<a.length;l++)j.call(e,a[l])&&r.push(`[`+t(a[l])+`]: `+t(e[a[l]],e));return r}})),xv=r(((e,t)=>{var n=bv(),r=vv(),i=function(e,t,n){for(var r=e,i;(i=r.next)!=null;r=i)if(i.key===t)return r.next=i.next,n||(i.next=e.next,e.next=i),i},a=function(e,t){if(e){var n=i(e,t);return n&&n.value}},o=function(e,t,n){var r=i(e,t);r?r.value=n:e.next={key:t,next:e.next,value:n}},s=function(e,t){return e?!!i(e,t):!1},c=function(e,t){if(e)return i(e,t,!0)};t.exports=function(){var e,t={assert:function(e){if(!t.has(e))throw new r(`Side channel does not contain `+n(e))},delete:function(t){var n=e&&e.next,r=c(e,t);return r&&n&&n===r&&(e=void 0),!!r},get:function(t){return a(e,t)},has:function(t){return s(e,t)},set:function(t,n){e||={next:void 0},o(e,t,n)}};return t}})),Sv=r(((e,t)=>{t.exports=Object})),Cv=r(((e,t)=>{t.exports=Error})),wv=r(((e,t)=>{t.exports=EvalError})),Tv=r(((e,t)=>{t.exports=RangeError})),Ev=r(((e,t)=>{t.exports=ReferenceError})),Dv=r(((e,t)=>{t.exports=SyntaxError})),Ov=r(((e,t)=>{t.exports=URIError})),kv=r(((e,t)=>{t.exports=Math.abs})),Av=r(((e,t)=>{t.exports=Math.floor})),jv=r(((e,t)=>{t.exports=Math.max})),Mv=r(((e,t)=>{t.exports=Math.min})),Nv=r(((e,t)=>{t.exports=Math.pow})),Pv=r(((e,t)=>{t.exports=Math.round})),Fv=r(((e,t)=>{t.exports=Number.isNaN||function(e){return e!==e}})),Iv=r(((e,t)=>{var n=Fv();t.exports=function(e){return n(e)||e===0?e:e<0?-1:1}})),Lv=r(((e,t)=>{t.exports=Object.getOwnPropertyDescriptor})),Rv=r(((e,t)=>{var n=Lv();if(n)try{n([],`length`)}catch{n=null}t.exports=n})),zv=r(((e,t)=>{var n=Object.defineProperty||!1;if(n)try{n({},`a`,{value:1})}catch{n=!1}t.exports=n})),Bv=r(((e,t)=>{t.exports=function(){if(typeof Symbol!=`function`||typeof Object.getOwnPropertySymbols!=`function`)return!1;if(typeof Symbol.iterator==`symbol`)return!0;var e={},t=Symbol(`test`),n=Object(t);if(typeof t==`string`||Object.prototype.toString.call(t)!==`[object Symbol]`||Object.prototype.toString.call(n)!==`[object Symbol]`)return!1;var r=42;for(var i in e[t]=r,e)return!1;if(typeof Object.keys==`function`&&Object.keys(e).length!==0||typeof Object.getOwnPropertyNames==`function`&&Object.getOwnPropertyNames(e).length!==0)return!1;var a=Object.getOwnPropertySymbols(e);if(a.length!==1||a[0]!==t||!Object.prototype.propertyIsEnumerable.call(e,t))return!1;if(typeof Object.getOwnPropertyDescriptor==`function`){var o=Object.getOwnPropertyDescriptor(e,t);if(o.value!==r||o.enumerable!==!0)return!1}return!0}})),Vv=r(((e,t)=>{var n=typeof Symbol<`u`&&Symbol,r=Bv();t.exports=function(){return typeof n!=`function`||typeof Symbol!=`function`||typeof n(`foo`)!=`symbol`||typeof Symbol(`bar`)!=`symbol`?!1:r()}})),Hv=r(((e,t)=>{t.exports=typeof Reflect<`u`&&Reflect.getPrototypeOf||null})),Uv=r(((e,t)=>{t.exports=Sv().getPrototypeOf||null})),Wv=r(((e,t)=>{var n=`Function.prototype.bind called on incompatible `,r=Object.prototype.toString,i=Math.max,a=`[object Function]`,o=function(e,t){for(var n=[],r=0;r<e.length;r+=1)n[r]=e[r];for(var i=0;i<t.length;i+=1)n[i+e.length]=t[i];return n},s=function(e,t){for(var n=[],r=t||0,i=0;r<e.length;r+=1,i+=1)n[i]=e[r];return n},c=function(e,t){for(var n=``,r=0;r<e.length;r+=1)n+=e[r],r+1<e.length&&(n+=t);return n};t.exports=function(e){var t=this;if(typeof t!=`function`||r.apply(t)!==a)throw TypeError(n+t);for(var l=s(arguments,1),u,d=function(){if(this instanceof u){var n=t.apply(this,o(l,arguments));return Object(n)===n?n:this}return t.apply(e,o(l,arguments))},f=i(0,t.length-l.length),p=[],m=0;m<f;m++)p[m]=`$`+m;if(u=Function(`binder`,`return function (`+c(p,`,`)+`){ return binder.apply(this,arguments); }`)(d),t.prototype){var h=function(){};h.prototype=t.prototype,u.prototype=new h,h.prototype=null}return u}})),Gv=r(((e,t)=>{var n=Wv();t.exports=Function.prototype.bind||n})),Kv=r(((e,t)=>{t.exports=Function.prototype.call})),qv=r(((e,t)=>{t.exports=Function.prototype.apply})),Jv=r(((e,t)=>{t.exports=typeof Reflect<`u`&&Reflect&&Reflect.apply})),Yv=r(((e,t)=>{var n=Gv(),r=qv(),i=Kv();t.exports=Jv()||n.call(i,r)})),Xv=r(((e,t)=>{var n=Gv(),r=vv(),i=Kv(),a=Yv();t.exports=function(e){if(e.length<1||typeof e[0]!=`function`)throw new r(`a function is required`);return a(n,i,e)}})),Zv=r(((e,t)=>{var n=Xv(),r=Rv(),i;try{i=[].__proto__===Array.prototype}catch(e){if(!e||typeof e!=`object`||!(`code`in e)||e.code!==`ERR_PROTO_ACCESS`)throw e}var a=!!i&&r&&r(Object.prototype,`__proto__`),o=Object,s=o.getPrototypeOf;t.exports=a&&typeof a.get==`function`?n([a.get]):typeof s==`function`?function(e){return s(e==null?e:o(e))}:!1})),Qv=r(((e,t)=>{var n=Hv(),r=Uv(),i=Zv();t.exports=n?function(e){return n(e)}:r?function(e){if(!e||typeof e!=`object`&&typeof e!=`function`)throw TypeError(`getProto: not an object`);return r(e)}:i?function(e){return i(e)}:null})),$v=r(((e,t)=>{var n=Function.prototype.call,r=Object.prototype.hasOwnProperty;t.exports=Gv().call(n,r)})),ey=r(((e,t)=>{var n,r=Sv(),i=Cv(),a=wv(),o=Tv(),s=Ev(),c=Dv(),l=vv(),u=Ov(),d=kv(),f=Av(),p=jv(),m=Mv(),h=Nv(),g=Pv(),_=Iv(),v=Function,y=function(e){try{return v(`"use strict"; return (`+e+`).constructor;`)()}catch{}},b=Rv(),x=zv(),S=function(){throw new l},C=b?function(){try{return arguments.callee,S}catch{try{return b(arguments,`callee`).get}catch{return S}}}():S,w=Vv()(),T=Qv(),E=Uv(),D=Hv(),O=qv(),k=Kv(),A={},j=typeof Uint8Array>`u`||!T?n:T(Uint8Array),M={__proto__:null,"%AggregateError%":typeof AggregateError>`u`?n:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>`u`?n:ArrayBuffer,"%ArrayIteratorPrototype%":w&&T?T([][Symbol.iterator]()):n,"%AsyncFromSyncIteratorPrototype%":n,"%AsyncFunction%":A,"%AsyncGenerator%":A,"%AsyncGeneratorFunction%":A,"%AsyncIteratorPrototype%":A,"%Atomics%":typeof Atomics>`u`?n:Atomics,"%BigInt%":typeof BigInt>`u`?n:BigInt,"%BigInt64Array%":typeof BigInt64Array>`u`?n:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>`u`?n:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>`u`?n:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":i,"%eval%":eval,"%EvalError%":a,"%Float16Array%":typeof Float16Array>`u`?n:Float16Array,"%Float32Array%":typeof Float32Array>`u`?n:Float32Array,"%Float64Array%":typeof Float64Array>`u`?n:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>`u`?n:FinalizationRegistry,"%Function%":v,"%GeneratorFunction%":A,"%Int8Array%":typeof Int8Array>`u`?n:Int8Array,"%Int16Array%":typeof Int16Array>`u`?n:Int16Array,"%Int32Array%":typeof Int32Array>`u`?n:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":w&&T?T(T([][Symbol.iterator]())):n,"%JSON%":typeof JSON==`object`?JSON:n,"%Map%":typeof Map>`u`?n:Map,"%MapIteratorPrototype%":typeof Map>`u`||!w||!T?n:T(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":r,"%Object.getOwnPropertyDescriptor%":b,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>`u`?n:Promise,"%Proxy%":typeof Proxy>`u`?n:Proxy,"%RangeError%":o,"%ReferenceError%":s,"%Reflect%":typeof Reflect>`u`?n:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>`u`?n:Set,"%SetIteratorPrototype%":typeof Set>`u`||!w||!T?n:T(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>`u`?n:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":w&&T?T(``[Symbol.iterator]()):n,"%Symbol%":w?Symbol:n,"%SyntaxError%":c,"%ThrowTypeError%":C,"%TypedArray%":j,"%TypeError%":l,"%Uint8Array%":typeof Uint8Array>`u`?n:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>`u`?n:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>`u`?n:Uint16Array,"%Uint32Array%":typeof Uint32Array>`u`?n:Uint32Array,"%URIError%":u,"%WeakMap%":typeof WeakMap>`u`?n:WeakMap,"%WeakRef%":typeof WeakRef>`u`?n:WeakRef,"%WeakSet%":typeof WeakSet>`u`?n:WeakSet,"%Function.prototype.call%":k,"%Function.prototype.apply%":O,"%Object.defineProperty%":x,"%Object.getPrototypeOf%":E,"%Math.abs%":d,"%Math.floor%":f,"%Math.max%":p,"%Math.min%":m,"%Math.pow%":h,"%Math.round%":g,"%Math.sign%":_,"%Reflect.getPrototypeOf%":D};if(T)try{null.error}catch(e){M[`%Error.prototype%`]=T(T(e))}var N=function e(t){var n;if(t===`%AsyncFunction%`)n=y(`async function () {}`);else if(t===`%GeneratorFunction%`)n=y(`function* () {}`);else if(t===`%AsyncGeneratorFunction%`)n=y(`async function* () {}`);else if(t===`%AsyncGenerator%`){var r=e(`%AsyncGeneratorFunction%`);r&&(n=r.prototype)}else if(t===`%AsyncIteratorPrototype%`){var i=e(`%AsyncGenerator%`);i&&T&&(n=T(i.prototype))}return M[t]=n,n},P={__proto__:null,"%ArrayBufferPrototype%":[`ArrayBuffer`,`prototype`],"%ArrayPrototype%":[`Array`,`prototype`],"%ArrayProto_entries%":[`Array`,`prototype`,`entries`],"%ArrayProto_forEach%":[`Array`,`prototype`,`forEach`],"%ArrayProto_keys%":[`Array`,`prototype`,`keys`],"%ArrayProto_values%":[`Array`,`prototype`,`values`],"%AsyncFunctionPrototype%":[`AsyncFunction`,`prototype`],"%AsyncGenerator%":[`AsyncGeneratorFunction`,`prototype`],"%AsyncGeneratorPrototype%":[`AsyncGeneratorFunction`,`prototype`,`prototype`],"%BooleanPrototype%":[`Boolean`,`prototype`],"%DataViewPrototype%":[`DataView`,`prototype`],"%DatePrototype%":[`Date`,`prototype`],"%ErrorPrototype%":[`Error`,`prototype`],"%EvalErrorPrototype%":[`EvalError`,`prototype`],"%Float32ArrayPrototype%":[`Float32Array`,`prototype`],"%Float64ArrayPrototype%":[`Float64Array`,`prototype`],"%FunctionPrototype%":[`Function`,`prototype`],"%Generator%":[`GeneratorFunction`,`prototype`],"%GeneratorPrototype%":[`GeneratorFunction`,`prototype`,`prototype`],"%Int8ArrayPrototype%":[`Int8Array`,`prototype`],"%Int16ArrayPrototype%":[`Int16Array`,`prototype`],"%Int32ArrayPrototype%":[`Int32Array`,`prototype`],"%JSONParse%":[`JSON`,`parse`],"%JSONStringify%":[`JSON`,`stringify`],"%MapPrototype%":[`Map`,`prototype`],"%NumberPrototype%":[`Number`,`prototype`],"%ObjectPrototype%":[`Object`,`prototype`],"%ObjProto_toString%":[`Object`,`prototype`,`toString`],"%ObjProto_valueOf%":[`Object`,`prototype`,`valueOf`],"%PromisePrototype%":[`Promise`,`prototype`],"%PromiseProto_then%":[`Promise`,`prototype`,`then`],"%Promise_all%":[`Promise`,`all`],"%Promise_reject%":[`Promise`,`reject`],"%Promise_resolve%":[`Promise`,`resolve`],"%RangeErrorPrototype%":[`RangeError`,`prototype`],"%ReferenceErrorPrototype%":[`ReferenceError`,`prototype`],"%RegExpPrototype%":[`RegExp`,`prototype`],"%SetPrototype%":[`Set`,`prototype`],"%SharedArrayBufferPrototype%":[`SharedArrayBuffer`,`prototype`],"%StringPrototype%":[`String`,`prototype`],"%SymbolPrototype%":[`Symbol`,`prototype`],"%SyntaxErrorPrototype%":[`SyntaxError`,`prototype`],"%TypedArrayPrototype%":[`TypedArray`,`prototype`],"%TypeErrorPrototype%":[`TypeError`,`prototype`],"%Uint8ArrayPrototype%":[`Uint8Array`,`prototype`],"%Uint8ClampedArrayPrototype%":[`Uint8ClampedArray`,`prototype`],"%Uint16ArrayPrototype%":[`Uint16Array`,`prototype`],"%Uint32ArrayPrototype%":[`Uint32Array`,`prototype`],"%URIErrorPrototype%":[`URIError`,`prototype`],"%WeakMapPrototype%":[`WeakMap`,`prototype`],"%WeakSetPrototype%":[`WeakSet`,`prototype`]},F=Gv(),ee=$v(),te=F.call(k,Array.prototype.concat),ne=F.call(O,Array.prototype.splice),re=F.call(k,String.prototype.replace),ie=F.call(k,String.prototype.slice),I=F.call(k,RegExp.prototype.exec),ae=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,oe=/\\(\\)?/g,se=function(e){var t=ie(e,0,1),n=ie(e,-1);if(t===`%`&&n!==`%`)throw new c("invalid intrinsic syntax, expected closing `%`");if(n===`%`&&t!==`%`)throw new c("invalid intrinsic syntax, expected opening `%`");var r=[];return re(e,ae,function(e,t,n,i){r[r.length]=n?re(i,oe,`$1`):t||e}),r},ce=function(e,t){var n=e,r;if(ee(P,n)&&(r=P[n],n=`%`+r[0]+`%`),ee(M,n)){var i=M[n];if(i===A&&(i=N(n)),i===void 0&&!t)throw new l(`intrinsic `+e+` exists, but is not available. Please file an issue!`);return{alias:r,name:n,value:i}}throw new c(`intrinsic `+e+` does not exist!`)};t.exports=function(e,t){if(typeof e!=`string`||e.length===0)throw new l(`intrinsic name must be a non-empty string`);if(arguments.length>1&&typeof t!=`boolean`)throw new l(`"allowMissing" argument must be a boolean`);if(I(/^%?[^%]*%?$/,e)===null)throw new c("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var n=se(e),r=n.length>0?n[0]:``,i=ce(`%`+r+`%`,t),a=i.name,o=i.value,s=!1,u=i.alias;u&&(r=u[0],ne(n,te([0,1],u)));for(var d=1,f=!0;d<n.length;d+=1){var p=n[d],m=ie(p,0,1),h=ie(p,-1);if((m===`"`||m===`'`||m==="`"||h===`"`||h===`'`||h==="`")&&m!==h)throw new c(`property names with quotes must have matching quotes`);if((p===`constructor`||!f)&&(s=!0),r+=`.`+p,a=`%`+r+`%`,ee(M,a))o=M[a];else if(o!=null){if(!(p in o)){if(!t)throw new l(`base intrinsic for `+e+` exists, but the property is not available.`);return}if(b&&d+1>=n.length){var g=b(o,p);f=!!g,o=f&&`get`in g&&!(`originalValue`in g.get)?g.get:o[p]}else f=ee(o,p),o=o[p];f&&!s&&(M[a]=o)}}return o}})),ty=r(((e,t)=>{var n=ey(),r=Xv(),i=r([n(`%String.prototype.indexOf%`)]);t.exports=function(e,t){var a=n(e,!!t);return typeof a==`function`&&i(e,`.prototype.`)>-1?r([a]):a}})),ny=r(((e,t)=>{var n=ey(),r=ty(),i=bv(),a=vv(),o=n(`%Map%`,!0),s=r(`Map.prototype.get`,!0),c=r(`Map.prototype.set`,!0),l=r(`Map.prototype.has`,!0),u=r(`Map.prototype.delete`,!0),d=r(`Map.prototype.size`,!0);t.exports=!!o&&function(){var e,t={assert:function(e){if(!t.has(e))throw new a(`Side channel does not contain `+i(e))},delete:function(t){if(e){var n=u(e,t);return d(e)===0&&(e=void 0),n}return!1},get:function(t){if(e)return s(e,t)},has:function(t){return e?l(e,t):!1},set:function(t,n){e||=new o,c(e,t,n)}};return t}})),ry=r(((e,t)=>{var n=ey(),r=ty(),i=bv(),a=ny(),o=vv(),s=n(`%WeakMap%`,!0),c=r(`WeakMap.prototype.get`,!0),l=r(`WeakMap.prototype.set`,!0),u=r(`WeakMap.prototype.has`,!0),d=r(`WeakMap.prototype.delete`,!0);t.exports=s?function(){var e,t,n={assert:function(e){if(!n.has(e))throw new o(`Side channel does not contain `+i(e))},delete:function(n){if(s&&n&&(typeof n==`object`||typeof n==`function`)){if(e)return d(e,n)}else if(a&&t)return t.delete(n);return!1},get:function(n){return s&&n&&(typeof n==`object`||typeof n==`function`)&&e?c(e,n):t&&t.get(n)},has:function(n){return s&&n&&(typeof n==`object`||typeof n==`function`)&&e?u(e,n):!!t&&t.has(n)},set:function(n,r){s&&n&&(typeof n==`object`||typeof n==`function`)?(e||=new s,l(e,n,r)):a&&(t||=a(),t.set(n,r))}};return n}:a})),iy=r(((e,t)=>{var n=vv(),r=bv(),i=xv(),a=ny(),o=ry()||a||i;t.exports=function(){var e,t={assert:function(e){if(!t.has(e))throw new n(`Side channel does not contain `+r(e))},delete:function(t){return!!e&&e.delete(t)},get:function(t){return e&&e.get(t)},has:function(t){return!!e&&e.has(t)},set:function(t,n){e||=o(),e.set(t,n)}};return t}})),ay=r(((e,t)=>{var n=String.prototype.replace,r=/%20/g,i={RFC1738:`RFC1738`,RFC3986:`RFC3986`};t.exports={default:i.RFC3986,formatters:{RFC1738:function(e){return n.call(e,r,`+`)},RFC3986:function(e){return String(e)}},RFC1738:i.RFC1738,RFC3986:i.RFC3986}})),oy=r(((e,t)=>{var n=ay(),r=iy(),i=Object.prototype.hasOwnProperty,a=Array.isArray,o=r(),s=function(e,t){return o.set(e,t),e},c=function(e){return o.has(e)},l=function(e){return o.get(e)},u=function(e,t){o.set(e,t)},d=function(){for(var e=[],t=0;t<256;++t)e[e.length]=`%`+((t<16?`0`:``)+t.toString(16)).toUpperCase();return e}(),f=function(e){for(;e.length>1;){var t=e.pop(),n=t.obj[t.prop];if(a(n)){for(var r=[],i=0;i<n.length;++i)n[i]!==void 0&&(r[r.length]=n[i]);t.obj[t.prop]=r}}},p=function(e,t){for(var n=t&&t.plainObjects?{__proto__:null}:{},r=0;r<e.length;++r)e[r]!==void 0&&(n[r]=e[r]);return n},m=function e(t,n,r){if(!n)return t;if(typeof n!=`object`&&typeof n!=`function`){if(a(t)){var o=t.length;if(r&&typeof r.arrayLimit==`number`&&o>r.arrayLimit)return s(p(t.concat(n),r),o);t[o]=n}else if(t&&typeof t==`object`)if(c(t)){var d=l(t)+1;t[d]=n,u(t,d)}else if(r&&r.strictMerge)return[t,n];else (r&&(r.plainObjects||r.allowPrototypes)||!i.call(Object.prototype,n))&&(t[n]=!0);else return[t,n];return t}if(!t||typeof t!=`object`){if(c(n)){for(var f=Object.keys(n),m=r&&r.plainObjects?{__proto__:null,0:t}:{0:t},h=0;h<f.length;h++){var g=parseInt(f[h],10);m[g+1]=n[f[h]]}return s(m,l(n)+1)}var _=[t].concat(n);return r&&typeof r.arrayLimit==`number`&&_.length>r.arrayLimit?s(p(_,r),_.length-1):_}var v=t;return a(t)&&!a(n)&&(v=p(t,r)),a(t)&&a(n)?(n.forEach(function(n,a){if(i.call(t,a)){var o=t[a];o&&typeof o==`object`&&n&&typeof n==`object`?t[a]=e(o,n,r):t[t.length]=n}else t[a]=n}),t):Object.keys(n).reduce(function(t,a){var o=n[a];if(i.call(t,a)?t[a]=e(t[a],o,r):t[a]=o,c(n)&&!c(t)&&s(t,l(n)),c(t)){var d=parseInt(a,10);String(d)===a&&d>=0&&d>l(t)&&u(t,d)}return t},v)},h=function(e,t){return Object.keys(t).reduce(function(e,n){return e[n]=t[n],e},e)},g=function(e,t,n){var r=e.replace(/\+/g,` `);if(n===`iso-8859-1`)return r.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(r)}catch{return r}},_=1024;t.exports={arrayToObject:p,assign:h,combine:function(e,t,n,r){if(c(e)){var i=l(e)+1;return e[i]=t,u(e,i),e}var a=[].concat(e,t);return a.length>n?s(p(a,{plainObjects:r}),a.length-1):a},compact:function(e){for(var t=[{obj:{o:e},prop:`o`}],n=[],r=0;r<t.length;++r)for(var i=t[r],a=i.obj[i.prop],o=Object.keys(a),s=0;s<o.length;++s){var c=o[s],l=a[c];typeof l==`object`&&l&&n.indexOf(l)===-1&&(t[t.length]={obj:a,prop:c},n[n.length]=l)}return f(t),e},decode:g,encode:function(e,t,r,i,a){if(e.length===0)return e;var o=e;if(typeof e==`symbol`?o=Symbol.prototype.toString.call(e):typeof e!=`string`&&(o=String(e)),r===`iso-8859-1`)return escape(o).replace(/%u[0-9a-f]{4}/gi,function(e){return`%26%23`+parseInt(e.slice(2),16)+`%3B`});for(var s=``,c=0;c<o.length;c+=_){for(var l=o.length>=_?o.slice(c,c+_):o,u=[],f=0;f<l.length;++f){var p=l.charCodeAt(f);if(p===45||p===46||p===95||p===126||p>=48&&p<=57||p>=65&&p<=90||p>=97&&p<=122||a===n.RFC1738&&(p===40||p===41)){u[u.length]=l.charAt(f);continue}if(p<128){u[u.length]=d[p];continue}if(p<2048){u[u.length]=d[192|p>>6]+d[128|p&63];continue}if(p<55296||p>=57344){u[u.length]=d[224|p>>12]+d[128|p>>6&63]+d[128|p&63];continue}f+=1,p=65536+((p&1023)<<10|l.charCodeAt(f)&1023),u[u.length]=d[240|p>>18]+d[128|p>>12&63]+d[128|p>>6&63]+d[128|p&63]}s+=u.join(``)}return s},isBuffer:function(e){return!e||typeof e!=`object`?!1:!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isOverflow:c,isRegExp:function(e){return Object.prototype.toString.call(e)===`[object RegExp]`},markOverflow:s,maybeMap:function(e,t){if(a(e)){for(var n=[],r=0;r<e.length;r+=1)n[n.length]=t(e[r]);return n}return t(e)},merge:m}})),sy=r(((e,t)=>{var n=iy(),r=oy(),i=ay(),a=Object.prototype.hasOwnProperty,o={brackets:function(e){return e+`[]`},comma:`comma`,indices:function(e,t){return e+`[`+t+`]`},repeat:function(e){return e}},s=Array.isArray,c=Array.prototype.push,l=function(e,t){c.apply(e,s(t)?t:[t])},u=Date.prototype.toISOString,d=i.default,f={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:`indices`,charset:`utf-8`,charsetSentinel:!1,commaRoundTrip:!1,delimiter:`&`,encode:!0,encodeDotInKeys:!1,encoder:r.encode,encodeValuesOnly:!1,filter:void 0,format:d,formatter:i.formatters[d],indices:!1,serializeDate:function(e){return u.call(e)},skipNulls:!1,strictNullHandling:!1},p=function(e){return typeof e==`string`||typeof e==`number`||typeof e==`boolean`||typeof e==`symbol`||typeof e==`bigint`},m={},h=function e(t,i,a,o,c,u,d,h,g,_,v,y,b,x,S,C,w,T){for(var E=t,D=T,O=0,k=!1;(D=D.get(m))!==void 0&&!k;){var A=D.get(t);if(O+=1,A!==void 0){if(A===O)throw RangeError(`Cyclic object value`);k=!0}D.get(m)===void 0&&(O=0)}if(typeof _==`function`?E=_(i,E):E instanceof Date?E=b(E):a===`comma`&&s(E)&&(E=r.maybeMap(E,function(e){return e instanceof Date?b(e):e})),E===null){if(u)return g&&!C?g(i,f.encoder,w,`key`,x):i;E=``}if(p(E)||r.isBuffer(E))return g?[S(C?i:g(i,f.encoder,w,`key`,x))+`=`+S(g(E,f.encoder,w,`value`,x))]:[S(i)+`=`+S(String(E))];var j=[];if(E===void 0)return j;var M;if(a===`comma`&&s(E))C&&g&&(E=r.maybeMap(E,g)),M=[{value:E.length>0?E.join(`,`)||null:void 0}];else if(s(_))M=_;else{var N=Object.keys(E);M=v?N.sort(v):N}var P=h?String(i).replace(/\./g,`%2E`):String(i),F=o&&s(E)&&E.length===1?P+`[]`:P;if(c&&s(E)&&E.length===0)return F+`[]`;for(var ee=0;ee<M.length;++ee){var te=M[ee],ne=typeof te==`object`&&te&&te.value!==void 0?te.value:E[te];if(!(d&&ne===null)){var re=y&&h?String(te).replace(/\./g,`%2E`):String(te),ie=s(E)?typeof a==`function`?a(F,re):F:F+(y?`.`+re:`[`+re+`]`);T.set(t,O);var I=n();I.set(m,T),l(j,e(ne,ie,a,o,c,u,d,h,a===`comma`&&C&&s(E)?null:g,_,v,y,b,x,S,C,w,I))}}return j},g=function(e){if(!e)return f;if(e.allowEmptyArrays!==void 0&&typeof e.allowEmptyArrays!=`boolean`)throw TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(e.encodeDotInKeys!==void 0&&typeof e.encodeDotInKeys!=`boolean`)throw TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(e.encoder!==null&&e.encoder!==void 0&&typeof e.encoder!=`function`)throw TypeError(`Encoder has to be a function.`);var t=e.charset||f.charset;if(e.charset!==void 0&&e.charset!==`utf-8`&&e.charset!==`iso-8859-1`)throw TypeError(`The charset option must be either utf-8, iso-8859-1, or undefined`);var n=i.default;if(e.format!==void 0){if(!a.call(i.formatters,e.format))throw TypeError(`Unknown format option provided.`);n=e.format}var r=i.formatters[n],c=f.filter;(typeof e.filter==`function`||s(e.filter))&&(c=e.filter);var l=e.arrayFormat in o?e.arrayFormat:`indices`in e?e.indices?`indices`:`repeat`:f.arrayFormat;if(`commaRoundTrip`in e&&typeof e.commaRoundTrip!=`boolean`)throw TypeError("`commaRoundTrip` must be a boolean, or absent");var u=e.allowDots===void 0?e.encodeDotInKeys===!0?!0:f.allowDots:!!e.allowDots;return{addQueryPrefix:typeof e.addQueryPrefix==`boolean`?e.addQueryPrefix:f.addQueryPrefix,allowDots:u,allowEmptyArrays:typeof e.allowEmptyArrays==`boolean`?!!e.allowEmptyArrays:f.allowEmptyArrays,arrayFormat:l,charset:t,charsetSentinel:typeof e.charsetSentinel==`boolean`?e.charsetSentinel:f.charsetSentinel,commaRoundTrip:!!e.commaRoundTrip,delimiter:e.delimiter===void 0?f.delimiter:e.delimiter,encode:typeof e.encode==`boolean`?e.encode:f.encode,encodeDotInKeys:typeof e.encodeDotInKeys==`boolean`?e.encodeDotInKeys:f.encodeDotInKeys,encoder:typeof e.encoder==`function`?e.encoder:f.encoder,encodeValuesOnly:typeof e.encodeValuesOnly==`boolean`?e.encodeValuesOnly:f.encodeValuesOnly,filter:c,format:n,formatter:r,serializeDate:typeof e.serializeDate==`function`?e.serializeDate:f.serializeDate,skipNulls:typeof e.skipNulls==`boolean`?e.skipNulls:f.skipNulls,sort:typeof e.sort==`function`?e.sort:null,strictNullHandling:typeof e.strictNullHandling==`boolean`?e.strictNullHandling:f.strictNullHandling}};t.exports=function(e,t){var r=e,i=g(t),a,c;typeof i.filter==`function`?(c=i.filter,r=c(``,r)):s(i.filter)&&(c=i.filter,a=c);var u=[];if(typeof r!=`object`||!r)return``;var d=o[i.arrayFormat],f=d===`comma`&&i.commaRoundTrip;a||=Object.keys(r),i.sort&&a.sort(i.sort);for(var p=n(),m=0;m<a.length;++m){var _=a[m],v=r[_];i.skipNulls&&v===null||l(u,h(v,_,d,f,i.allowEmptyArrays,i.strictNullHandling,i.skipNulls,i.encodeDotInKeys,i.encode?i.encoder:null,i.filter,i.sort,i.allowDots,i.serializeDate,i.format,i.formatter,i.encodeValuesOnly,i.charset,p))}var y=u.join(i.delimiter),b=i.addQueryPrefix===!0?`?`:``;return i.charsetSentinel&&(i.charset===`iso-8859-1`?b+=`utf8=%26%2310003%3B&`:b+=`utf8=%E2%9C%93&`),y.length>0?b+y:``}})),cy=r(((e,t)=>{var n=oy(),r=Object.prototype.hasOwnProperty,i=Array.isArray,a={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:`utf-8`,charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:n.decode,delimiter:`&`,depth:5,duplicates:`combine`,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictMerge:!0,strictNullHandling:!1,throwOnLimitExceeded:!1},o=function(e){return e.replace(/&#(\d+);/g,function(e,t){return String.fromCharCode(parseInt(t,10))})},s=function(e,t,n){if(e&&typeof e==`string`&&t.comma&&e.indexOf(`,`)>-1)return e.split(`,`);if(t.throwOnLimitExceeded&&n>=t.arrayLimit)throw RangeError(`Array limit exceeded. Only `+t.arrayLimit+` element`+(t.arrayLimit===1?``:`s`)+` allowed in an array.`);return e},c=`utf8=%26%2310003%3B`,l=`utf8=%E2%9C%93`,u=function(e,t){var u={__proto__:null},d=t.ignoreQueryPrefix?e.replace(/^\?/,``):e;d=d.replace(/%5B/gi,`[`).replace(/%5D/gi,`]`);var f=t.parameterLimit===1/0?void 0:t.parameterLimit,p=d.split(t.delimiter,t.throwOnLimitExceeded?f+1:f);if(t.throwOnLimitExceeded&&p.length>f)throw RangeError(`Parameter limit exceeded. Only `+f+` parameter`+(f===1?``:`s`)+` allowed.`);var m=-1,h,g=t.charset;if(t.charsetSentinel)for(h=0;h<p.length;++h)p[h].indexOf(`utf8=`)===0&&(p[h]===l?g=`utf-8`:p[h]===c&&(g=`iso-8859-1`),m=h,h=p.length);for(h=0;h<p.length;++h)if(h!==m){var _=p[h],v=_.indexOf(`]=`),y=v===-1?_.indexOf(`=`):v+1,b,x;if(y===-1?(b=t.decoder(_,a.decoder,g,`key`),x=t.strictNullHandling?null:``):(b=t.decoder(_.slice(0,y),a.decoder,g,`key`),b!==null&&(x=n.maybeMap(s(_.slice(y+1),t,i(u[b])?u[b].length:0),function(e){return t.decoder(e,a.decoder,g,`value`)}))),x&&t.interpretNumericEntities&&g===`iso-8859-1`&&(x=o(String(x))),_.indexOf(`[]=`)>-1&&(x=i(x)?[x]:x),t.comma&&i(x)&&x.length>t.arrayLimit){if(t.throwOnLimitExceeded)throw RangeError(`Array limit exceeded. Only `+t.arrayLimit+` element`+(t.arrayLimit===1?``:`s`)+` allowed in an array.`);x=n.combine([],x,t.arrayLimit,t.plainObjects)}if(b!==null){var S=r.call(u,b);S&&(t.duplicates===`combine`||_.indexOf(`[]=`)>-1)?u[b]=n.combine(u[b],x,t.arrayLimit,t.plainObjects):(!S||t.duplicates===`last`)&&(u[b]=x)}}return u},d=function(e,t,r,i){var a=0;if(e.length>0&&e[e.length-1]===`[]`){var o=e.slice(0,-1).join(``);a=Array.isArray(t)&&t[o]?t[o].length:0}for(var c=i?t:s(t,r,a),l=e.length-1;l>=0;--l){var u,d=e[l];if(d===`[]`&&r.parseArrays)u=n.isOverflow(c)?c:r.allowEmptyArrays&&(c===``||r.strictNullHandling&&c===null)?[]:n.combine([],c,r.arrayLimit,r.plainObjects);else{u=r.plainObjects?{__proto__:null}:{};var f=d.charAt(0)===`[`&&d.charAt(d.length-1)===`]`?d.slice(1,-1):d,p=r.decodeDotInKeys?f.replace(/%2E/g,`.`):f,m=parseInt(p,10),h=!isNaN(m)&&d!==p&&String(m)===p&&m>=0&&r.parseArrays;if(!r.parseArrays&&p===``)u={0:c};else if(h&&m<r.arrayLimit)u=[],u[m]=c;else if(h&&r.throwOnLimitExceeded)throw RangeError(`Array limit exceeded. Only `+r.arrayLimit+` element`+(r.arrayLimit===1?``:`s`)+` allowed in an array.`);else h?(u[m]=c,n.markOverflow(u,m)):p!==`__proto__`&&(u[p]=c)}c=u}return c},f=function(e,t){var n=t.allowDots?e.replace(/\.([^.[]+)/g,`[$1]`):e;if(t.depth<=0)return!t.plainObjects&&r.call(Object.prototype,n)&&!t.allowPrototypes?void 0:[n];var i=/(\[[^[\]]*])/,a=/(\[[^[\]]*])/g,o=i.exec(n),s=o?n.slice(0,o.index):n,c=[];if(s){if(!t.plainObjects&&r.call(Object.prototype,s)&&!t.allowPrototypes)return;c[c.length]=s}for(var l=0;(o=a.exec(n))!==null&&l<t.depth;){l+=1;var u=o[1].slice(1,-1);if(!t.plainObjects&&r.call(Object.prototype,u)&&!t.allowPrototypes)return;c[c.length]=o[1]}if(o){if(t.strictDepth===!0)throw RangeError(`Input depth exceeded depth option of `+t.depth+` and strictDepth is true`);c[c.length]=`[`+n.slice(o.index)+`]`}return c},p=function(e,t,n,r){if(e){var i=f(e,n);if(i)return d(i,t,n,r)}},m=function(e){if(!e)return a;if(e.allowEmptyArrays!==void 0&&typeof e.allowEmptyArrays!=`boolean`)throw TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(e.decodeDotInKeys!==void 0&&typeof e.decodeDotInKeys!=`boolean`)throw TypeError("`decodeDotInKeys` option can only be `true` or `false`, when provided");if(e.decoder!==null&&e.decoder!==void 0&&typeof e.decoder!=`function`)throw TypeError(`Decoder has to be a function.`);if(e.charset!==void 0&&e.charset!==`utf-8`&&e.charset!==`iso-8859-1`)throw TypeError(`The charset option must be either utf-8, iso-8859-1, or undefined`);if(e.throwOnLimitExceeded!==void 0&&typeof e.throwOnLimitExceeded!=`boolean`)throw TypeError("`throwOnLimitExceeded` option must be a boolean");var t=e.charset===void 0?a.charset:e.charset,r=e.duplicates===void 0?a.duplicates:e.duplicates;if(r!==`combine`&&r!==`first`&&r!==`last`)throw TypeError(`The duplicates option must be either combine, first, or last`);return{allowDots:e.allowDots===void 0?e.decodeDotInKeys===!0?!0:a.allowDots:!!e.allowDots,allowEmptyArrays:typeof e.allowEmptyArrays==`boolean`?!!e.allowEmptyArrays:a.allowEmptyArrays,allowPrototypes:typeof e.allowPrototypes==`boolean`?e.allowPrototypes:a.allowPrototypes,allowSparse:typeof e.allowSparse==`boolean`?e.allowSparse:a.allowSparse,arrayLimit:typeof e.arrayLimit==`number`?e.arrayLimit:a.arrayLimit,charset:t,charsetSentinel:typeof e.charsetSentinel==`boolean`?e.charsetSentinel:a.charsetSentinel,comma:typeof e.comma==`boolean`?e.comma:a.comma,decodeDotInKeys:typeof e.decodeDotInKeys==`boolean`?e.decodeDotInKeys:a.decodeDotInKeys,decoder:typeof e.decoder==`function`?e.decoder:a.decoder,delimiter:typeof e.delimiter==`string`||n.isRegExp(e.delimiter)?e.delimiter:a.delimiter,depth:typeof e.depth==`number`||e.depth===!1?+e.depth:a.depth,duplicates:r,ignoreQueryPrefix:e.ignoreQueryPrefix===!0,interpretNumericEntities:typeof e.interpretNumericEntities==`boolean`?e.interpretNumericEntities:a.interpretNumericEntities,parameterLimit:typeof e.parameterLimit==`number`?e.parameterLimit:a.parameterLimit,parseArrays:e.parseArrays!==!1,plainObjects:typeof e.plainObjects==`boolean`?e.plainObjects:a.plainObjects,strictDepth:typeof e.strictDepth==`boolean`?!!e.strictDepth:a.strictDepth,strictMerge:typeof e.strictMerge==`boolean`?!!e.strictMerge:a.strictMerge,strictNullHandling:typeof e.strictNullHandling==`boolean`?e.strictNullHandling:a.strictNullHandling,throwOnLimitExceeded:typeof e.throwOnLimitExceeded==`boolean`?e.throwOnLimitExceeded:!1}};t.exports=function(e,t){var r=m(t);if(e===``||e==null)return r.plainObjects?{__proto__:null}:{};for(var i=typeof e==`string`?u(e,r):e,a=r.plainObjects?{__proto__:null}:{},o=Object.keys(i),s=0;s<o.length;++s){var c=o[s],l=p(c,i[c],r,typeof e==`string`);a=n.merge(a,l,r)}return r.allowSparse===!0?a:n.compact(a)}})),ly=r(((e,t)=>{var n=sy(),r=cy();t.exports={formats:ay(),parse:r,stringify:n}})),uy=r((e=>{var t=_v();function n(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var r=/^([a-z0-9.+-]+:)/i,i=/:[0-9]*$/,a=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,o=[`'`,`{`,`}`,`|`,`\\`,`^`,"`",`<`,`>`,`"`,"`",` `,`\r`,`
93
+ `,` `],s=[`%`,`/`,`?`,`;`,`#`].concat(o),c=[`/`,`?`,`#`],l=255,u=/^[+a-z0-9A-Z_-]{0,63}$/,d=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,f={javascript:!0,"javascript:":!0},p={javascript:!0,"javascript:":!0},m={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},h=ly();function g(e,t,r){if(e&&typeof e==`object`&&e instanceof n)return e;var i=new n;return i.parse(e,t,r),i}n.prototype.parse=function(e,n,i){if(typeof e!=`string`)throw TypeError(`Parameter 'url' must be a string, not `+typeof e);var g=e.indexOf(`?`),_=g!==-1&&g<e.indexOf(`#`)?`?`:`#`,v=e.split(_);v[0]=v[0].replace(/\\/g,`/`),e=v.join(_);var y=e;if(y=y.trim(),!i&&e.split(`#`).length===1){var b=a.exec(y);if(b)return this.path=y,this.href=y,this.pathname=b[1],b[2]?(this.search=b[2],n?this.query=h.parse(this.search.substr(1)):this.query=this.search.substr(1)):n&&(this.search=``,this.query={}),this}var x=r.exec(y);if(x){x=x[0];var S=x.toLowerCase();this.protocol=S,y=y.substr(x.length)}if(i||x||y.match(/^\/\/[^@/]+@[^@/]+/)){var C=y.substr(0,2)===`//`;C&&!(x&&p[x])&&(y=y.substr(2),this.slashes=!0)}if(!p[x]&&(C||x&&!m[x])){for(var w=-1,T=0;T<c.length;T++){var E=y.indexOf(c[T]);E!==-1&&(w===-1||E<w)&&(w=E)}var D,O=w===-1?y.lastIndexOf(`@`):y.lastIndexOf(`@`,w);O!==-1&&(D=y.slice(0,O),y=y.slice(O+1),this.auth=decodeURIComponent(D)),w=-1;for(var T=0;T<s.length;T++){var E=y.indexOf(s[T]);E!==-1&&(w===-1||E<w)&&(w=E)}w===-1&&(w=y.length),this.host=y.slice(0,w),y=y.slice(w),this.parseHost(),this.hostname=this.hostname||``;var k=this.hostname[0]===`[`&&this.hostname[this.hostname.length-1]===`]`;if(!k)for(var A=this.hostname.split(/\./),T=0,j=A.length;T<j;T++){var M=A[T];if(M&&!M.match(u)){for(var N=``,P=0,F=M.length;P<F;P++)M.charCodeAt(P)>127?N+=`x`:N+=M[P];if(!N.match(u)){var ee=A.slice(0,T),te=A.slice(T+1),ne=M.match(d);ne&&(ee.push(ne[1]),te.unshift(ne[2])),te.length&&(y=`/`+te.join(`.`)+y),this.hostname=ee.join(`.`);break}}}this.hostname.length>l?this.hostname=``:this.hostname=this.hostname.toLowerCase(),k||(this.hostname=t.toASCII(this.hostname));var re=this.port?`:`+this.port:``;this.host=(this.hostname||``)+re,this.href+=this.host,k&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),y[0]!==`/`&&(y=`/`+y))}if(!f[S])for(var T=0,j=o.length;T<j;T++){var ie=o[T];if(y.indexOf(ie)!==-1){var I=encodeURIComponent(ie);I===ie&&(I=escape(ie)),y=y.split(ie).join(I)}}var ae=y.indexOf(`#`);ae!==-1&&(this.hash=y.substr(ae),y=y.slice(0,ae));var oe=y.indexOf(`?`);if(oe===-1?n&&(this.search=``,this.query={}):(this.search=y.substr(oe),this.query=y.substr(oe+1),n&&(this.query=h.parse(this.query)),y=y.slice(0,oe)),y&&(this.pathname=y),m[S]&&this.hostname&&!this.pathname&&(this.pathname=`/`),this.pathname||this.search){var re=this.pathname||``;this.path=re+(this.search||``)}return this.href=this.format(),this};function _(e){return typeof e==`string`&&(e=g(e)),e instanceof n?e.format():n.prototype.format.call(e)}n.prototype.format=function(){var e=this.auth||``;e&&(e=encodeURIComponent(e),e=e.replace(/%3A/i,`:`),e+=`@`);var t=this.protocol||``,n=this.pathname||``,r=this.hash||``,i=!1,a=``;this.host?i=e+this.host:this.hostname&&(i=e+(this.hostname.indexOf(`:`)===-1?this.hostname:`[`+this.hostname+`]`),this.port&&(i+=`:`+this.port)),this.query&&typeof this.query==`object`&&Object.keys(this.query).length&&(a=h.stringify(this.query,{arrayFormat:`repeat`,addQueryPrefix:!1}));var o=this.search||a&&`?`+a||``;return t&&t.substr(-1)!==`:`&&(t+=`:`),this.slashes||(!t||m[t])&&i!==!1?(i=`//`+(i||``),n&&n.charAt(0)!==`/`&&(n=`/`+n)):i||=``,r&&r.charAt(0)!==`#`&&(r=`#`+r),o&&o.charAt(0)!==`?`&&(o=`?`+o),n=n.replace(/[?#]/g,function(e){return encodeURIComponent(e)}),o=o.replace(`#`,`%23`),t+i+n+o+r};function v(e,t){return g(e,!1,!0).resolve(t)}n.prototype.resolve=function(e){return this.resolveObject(g(e,!1,!0)).format()};function y(e,t){return e?g(e,!1,!0).resolveObject(t):t}n.prototype.resolveObject=function(e){if(typeof e==`string`){var t=new n;t.parse(e,!1,!0),e=t}for(var r=new n,i=Object.keys(this),a=0;a<i.length;a++){var o=i[a];r[o]=this[o]}if(r.hash=e.hash,e.href===``)return r.href=r.format(),r;if(e.slashes&&!e.protocol){for(var s=Object.keys(e),c=0;c<s.length;c++){var l=s[c];l!==`protocol`&&(r[l]=e[l])}return m[r.protocol]&&r.hostname&&!r.pathname&&(r.pathname=`/`,r.path=r.pathname),r.href=r.format(),r}if(e.protocol&&e.protocol!==r.protocol){if(!m[e.protocol]){for(var u=Object.keys(e),d=0;d<u.length;d++){var f=u[d];r[f]=e[f]}return r.href=r.format(),r}if(r.protocol=e.protocol,!e.host&&!p[e.protocol]){for(var h=(e.pathname||``).split(`/`);h.length&&!(e.host=h.shift()););e.host||=``,e.hostname||=``,h[0]!==``&&h.unshift(``),h.length<2&&h.unshift(``),r.pathname=h.join(`/`)}else r.pathname=e.pathname;return r.search=e.search,r.query=e.query,r.host=e.host||``,r.auth=e.auth,r.hostname=e.hostname||e.host,r.port=e.port,(r.pathname||r.search)&&(r.path=(r.pathname||``)+(r.search||``)),r.slashes=r.slashes||e.slashes,r.href=r.format(),r}var g=r.pathname&&r.pathname.charAt(0)===`/`,_=e.host||e.pathname&&e.pathname.charAt(0)===`/`,v=_||g||r.host&&e.pathname,y=v,b=r.pathname&&r.pathname.split(`/`)||[],h=e.pathname&&e.pathname.split(`/`)||[],x=r.protocol&&!m[r.protocol];if(x&&(r.hostname=``,r.port=null,r.host&&(b[0]===``?b[0]=r.host:b.unshift(r.host)),r.host=``,e.protocol&&(e.hostname=null,e.port=null,e.host&&(h[0]===``?h[0]=e.host:h.unshift(e.host)),e.host=null),v&&=h[0]===``||b[0]===``),_)r.host=e.host||e.host===``?e.host:r.host,r.hostname=e.hostname||e.hostname===``?e.hostname:r.hostname,r.search=e.search,r.query=e.query,b=h;else if(h.length)b||=[],b.pop(),b=b.concat(h),r.search=e.search,r.query=e.query;else if(e.search!=null){if(x){r.host=b.shift(),r.hostname=r.host;var S=r.host&&r.host.indexOf(`@`)>0?r.host.split(`@`):!1;S&&(r.auth=S.shift(),r.hostname=S.shift(),r.host=r.hostname)}return r.search=e.search,r.query=e.query,(r.pathname!==null||r.search!==null)&&(r.path=(r.pathname?r.pathname:``)+(r.search?r.search:``)),r.href=r.format(),r}if(!b.length)return r.pathname=null,r.search?r.path=`/`+r.search:r.path=null,r.href=r.format(),r;for(var C=b.slice(-1)[0],w=(r.host||e.host||b.length>1)&&(C===`.`||C===`..`)||C===``,T=0,E=b.length;E>=0;E--)C=b[E],C===`.`?b.splice(E,1):C===`..`?(b.splice(E,1),T++):T&&(b.splice(E,1),T--);if(!v&&!y)for(;T--;)b.unshift(`..`);v&&b[0]!==``&&(!b[0]||b[0].charAt(0)!==`/`)&&b.unshift(``),w&&b.join(`/`).substr(-1)!==`/`&&b.push(``);var D=b[0]===``||b[0]&&b[0].charAt(0)===`/`;if(x){r.hostname=D?``:b.length?b.shift():``,r.host=r.hostname;var S=r.host&&r.host.indexOf(`@`)>0?r.host.split(`@`):!1;S&&(r.auth=S.shift(),r.hostname=S.shift(),r.host=r.hostname)}return v||=r.host&&b.length,v&&!D&&b.unshift(``),b.length>0?r.pathname=b.join(`/`):(r.pathname=null,r.path=null),(r.pathname!==null||r.search!==null)&&(r.path=(r.pathname?r.pathname:``)+(r.search?r.search:``)),r.auth=e.auth||r.auth,r.slashes=r.slashes||e.slashes,r.href=r.format(),r},n.prototype.parseHost=function(){var e=this.host,t=i.exec(e);t&&(t=t[0],t!==`:`&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)},e.parse=g,e.resolve=v,e.resolveObject=y,e.format=_,e.Url=n})),dy=r(((e,t)=>{(function(e,n){typeof define==`function`&&define.amd?define([],n):typeof t==`object`&&t.exports?t.exports=n():e.xmlserializer=n()})(e,function(){var e=function(e){return e.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g,``)},t=function(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&apos;`)},n=function(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)},r=function(e){var n=e.value;return` `+e.name+`="`+t(n)+`"`},i=function(e){var t=e.tagName;return e.namespaceURI===`http://www.w3.org/1999/xhtml`&&(t=t.toLowerCase()),t},a=function(e,t){return!(Array.prototype.map.call(e.attributes||e.attrs,function(e){return e.name}).indexOf(`xmlns`)>=0)&&(t||e.namespaceURI!==e.parentNode.namespaceURI)?` xmlns="`+e.namespaceURI+`"`:``},o=function(e){return Array.prototype.map.call(e.childNodes,function(e){return d(e)}).join(``)},s=function(e,t){var n=`<`+i(e);return n+=a(e,t),Array.prototype.forEach.call(e.attributes||e.attrs,function(e){n+=r(e)}),e.childNodes.length>0?(n+=`>`,n+=o(e),n+=`</`+i(e)+`>`):n+=`/>`,n},c=function(e){return n(e.nodeValue||e.value||``)},l=function(e){return`<!--`+e.data.replace(/-/g,`&#45;`)+`-->`},u=function(e){return`<![CDATA[`+e.nodeValue+`]]>`},d=function(e,t){var n=t&&t.rootNode;if(e.nodeName===`#document`||e.nodeName===`#document-fragment`)return o(e);if(e.tagName)return s(e,n);if(e.nodeName===`#text`)return c(e);if(e.nodeName===`#comment`)return l(e);if(e.nodeName===`#cdata-section`)return u(e)};return{serializeToString:function(t){return e(d(t,{rootNode:!0}))}}})})),fy=r((e=>{var t=function(e){var t=new XMLSerializer;return Array.prototype.map.call(e.childNodes,function(e){return t.serializeToString(e)}).join(``)},n=function(e){if(e.documentElement.tagName===`parsererror`&&e.documentElement.namespaceURI===`http://www.mozilla.org/newlayout/xml/parsererror.xml`)return e.documentElement;if((e.documentElement.tagName===`xml`||e.documentElement.tagName===`html`)&&e.documentElement.childNodes&&e.documentElement.childNodes.length>0&&e.documentElement.childNodes[0].nodeName===`parsererror`)return e.documentElement.childNodes[0];if(e.documentElement.tagName===`html`&&e.documentElement.childNodes&&e.documentElement.childNodes.length>0&&e.documentElement.childNodes[0].nodeName===`body`&&e.documentElement.childNodes[0].childNodes&&e.documentElement.childNodes[0].childNodes.length&&e.documentElement.childNodes[0].childNodes[0].nodeName===`parsererror`)return e.documentElement.childNodes[0].childNodes[0]},r=[RegExp(`^<h3[^>]*>This page contains the following errors:</h3><div[^>]*>(.+?)
94
94
  ?</div>`),RegExp(`^(.+)
95
- `)],i=function(e){var n=t(e),i,a;for(i=0;i<r.length;i++)if(a=r[i].exec(n),a)return a[1]},a=function(e){var t;if(e===null)throw Error(`Parse error`);var r=n(e);if(r!==void 0)throw t=i(r)||`Parse error`,Error(t)};e.failOnParseError=function(e){return a(e),e}})),uy=r((e=>{var t=sy();e.getDocumentBaseUrl=function(e){return e.baseURI===`about:blank`?null:e.baseURI},e.clone=function(e){var t={},n;for(n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t},e.cloneArray=function(e){return Array.prototype.slice.apply(e,[0])},e.joinUrl=function(e,n){return e?t.resolve(e,n):n},e.isDataUri=function(e){return/^data:/.test(e)},e.collectAndReportErrors=function(e){var t=[];return Promise.all(e.map(function(e){return e.catch(function(e){t.push(e)})})).then(function(){return t})};var n=null,r=function(e,t){return t===!1||t===`none`||t===`repeated`?((n===null||t!==`repeated`)&&(n=Date.now()),e+`?_=`+n):e};e.ajax=function(t,n){return new Promise(function(i,a){var o=new window.XMLHttpRequest,s=e.joinUrl(n.baseUrl,t),c,l=function(){a({msg:`Unable to load url`,url:s})};c=r(s,n.cache),o.addEventListener(`load`,function(){o.status===200||o.status===0?i(o.response):l()},!1),o.addEventListener(`error`,l,!1);try{o.open(`GET`,c,!0),o.overrideMimeType(n.mimeType),o.send(null)}catch{l()}})},e.binaryAjax=function(t,n){var r=e.clone(n);return r.mimeType=`text/plain; charset=x-user-defined`,e.ajax(t,r).then(function(e){for(var t=``,n=0;n<e.length;n++)t+=String.fromCharCode(e.charCodeAt(n)&255);return t})};var i=function(e){var t=function(e,t){return e.substring(0,t.length)===t};return t(e,`<?xml`)||t(e,`<svg`)?`image/svg+xml`:`image/png`};e.getDataURIForImageURL=function(t,n){return e.binaryAjax(t,n).then(function(e){var t=btoa(e);return`data:`+i(e)+`;base64,`+t})};var a=[],o=function(e){return a.indexOf(e)<0&&a.push(e),a.indexOf(e)};e.memoize=function(e,t,n){if(typeof n!=`object`)throw Error(`cacheBucket is not an object`);return function(){var r=Array.prototype.slice.call(arguments),i=t(r),a=o(e),s;return n[a]&&n[a][i]?n[a][i]:(s=e.apply(null,r),n[a]=n[a]||{},n[a][i]=s,s)}}})),dy=r((e=>{var t=uy(),n=function(e,n){var r=null;e.hasAttribute(`src`)?r=e.getAttribute(`src`):e.hasAttributeNS(`http://www.w3.org/1999/xlink`,`href`)?r=e.getAttributeNS(`http://www.w3.org/1999/xlink`,`href`):e.hasAttribute(`href`)&&(r=e.getAttribute(`href`));var i=t.getDocumentBaseUrl(e.ownerDocument),a=t.clone(n);return!a.baseUrl&&i&&(a.baseUrl=i),t.getDataURIForImageURL(r,a).then(function(e){return e},function(e){throw{resourceType:`image`,url:e.url,msg:`Unable to load image `+e.url}})},r=function(e){return e.filter(function(e){var n=null;return e.hasAttribute(`src`)?n=e.getAttribute(`src`):e.hasAttributeNS(`http://www.w3.org/1999/xlink`,`href`)?n=e.getAttributeNS(`http://www.w3.org/1999/xlink`,`href`):e.hasAttribute(`href`)&&(n=e.getAttribute(`href`)),n!==null&&!t.isDataUri(n)})},i=function(e){return Array.prototype.filter.call(e,function(e){return e.type===`image`})},a=function(e){return Array.prototype.slice.call(e)};e.inline=function(e,o){var s=a(e.getElementsByTagName(`img`)),c=a(e.getElementsByTagName(`image`)),l=i(e.getElementsByTagName(`input`));s=s.concat(c),s=s.concat(l);var u=r(s);return t.collectAndReportErrors(u.map(function(e){return n(e,o).then(function(t){e.attributes.src?e.attributes.src.value=t:e.attributes[`xlink:href`]?e.attributes[`xlink:href`].value=t:e.attributes.href&&(e.attributes.href.value=t)})}))}})),fy=r((e=>{var t=uy(),n=function(e,n){var r=e.attributes.src.value,i=t.getDocumentBaseUrl(e.ownerDocument),a=t.clone(n);return!a.baseUrl&&i&&(a.baseUrl=i),t.ajax(r,a).catch(function(e){throw{resourceType:`script`,url:e.url,msg:`Unable to load script `+e.url}})},r=function(e){return e.replace(/<\//g,`<\\/`)},i=function(e,t){e.attributes.removeNamedItem(`src`),e.textContent=r(t)},a=function(e){var t=e.getElementsByTagName(`script`);return Array.prototype.filter.call(t,function(e){return!!e.attributes.src})};e.inline=function(e,r){var o=a(e);return t.collectAndReportErrors(o.map(function(e){return n(e,r).then(function(t){i(e,t)})}))}})),py=r((e=>{e.unquoteString=function(e){var t=/^"(.*)"$/,n=/^'(.*)'$/;return t.test(e)?e.replace(t,`$1`):n.test(e)?e.replace(n,`$1`):e},e.rulesForCssText=function(e,t){var n=document.implementation.createHTMLDocument(``),r=document.createElement(`style`),i;return r.textContent=e,t&&t.nonce&&(r.nonce=t.nonce),n.body.appendChild(r),i=r.sheet.cssRules,Array.prototype.slice.call(i)},e.cssRulesToText=function(e){return e.reduce(function(e,t){return e+t.cssText},``)},e.exchangeRule=function(t,n,r,i){var a=t.indexOf(n);t[a]=e.rulesForCssText(r,i)[0]},e.changeFontFaceRuleSrc=function(t,n,r,i){var a=`@font-face { font-family: `+n.style.getPropertyValue(`font-family`)+`; `;n.style.getPropertyValue(`font-style`)&&(a+=`font-style: `+n.style.getPropertyValue(`font-style`)+`; `),n.style.getPropertyValue(`font-weight`)&&(a+=`font-weight: `+n.style.getPropertyValue(`font-weight`)+`; `),n.style.getPropertyValue(`unicode-range`)&&(a+=`unicode-range: `+n.style.getPropertyValue(`unicode-range`)+`; `),a+=`src: `+r+`}`,e.exchangeRule(t,n,a,i)}})),my=r((e=>{var t=py(),n=function(e){return e.replace(/^[\t\r\f\n ]*(.+?)[\t\r\f\n ]*$/,`$1`)};e.extractCssUrl=function(e){var r=/^url\(("[^"]+"|'[^']+'|[^\)]+)\)/,i;if(!r.test(e))throw Error(`Invalid url`);return i=r.exec(e)[1],t.unquoteString(n(i))};var r=function(e){var t=`(url\\(\\s*(?:"[^"]*"|'[^']*'|[^\\(]+)\\s*\\)|[^,\\s]+)`,n=`(?:\\s*`+t+`)+`,r=`^\\s*(`+n+`)(?:\\s*,\\s*(`+n+`))*\\s*$`,i=new RegExp(n,`g`),a,o=[],s=function(e){for(var n=new RegExp(t,`g`),r=[],i=n.exec(e);i;)r.push(i[1]),i=n.exec(e);return r};if(e.match(new RegExp(r))){for(a=i.exec(e);a;)o.push(s(a[0])),a=i.exec(e);return o}return[]},i=function(t){var n,r;for(n=0;n<t.length;n++)try{return r=e.extractCssUrl(t[n]),{url:r,idx:n}}catch{}};e.parse=function(e){return r(e).map(function(e){var t=i(e);return t?{preUrl:e.slice(0,t.idx),url:t.url,postUrl:e.slice(t.idx+1)}:{preUrl:e}})},e.serialize=function(e){return e.map(function(e){var t=[].concat(e.preUrl);return e.url&&t.push(`url("`+e.url+`")`),e.postUrl&&(t=t.concat(e.postUrl)),t.join(` `)}).join(`, `)}})),hy=r(((e,t)=>{(function(n){if(typeof e==`object`&&t!==void 0)t.exports=n();else if(typeof define==`function`&&define.amd)define([],n);else{var r=typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:this;r.cssFontFaceSrc=n()}})(function(){return(function e(t,r,i){function a(s,c){if(!r[s]){if(!t[s]){var l=typeof n==`function`&&n;if(!c&&l)return l(s,!0);if(o)return o(s,!0);var u=Error(`Cannot find module '`+s+`'`);throw u.code=`MODULE_NOT_FOUND`,u}var d=r[s]={exports:{}};t[s][0].call(d.exports,function(e){var n=t[s][1][e];return a(n||e)},d,d.exports,e,t,r,i)}return r[s].exports}for(var o=typeof n==`function`&&n,s=0;s<i.length;s++)a(i[s]);return a})({1:[function(e,t,n){function r(e,t){function n(){this.constructor=e}n.prototype=t.prototype,e.prototype=new n}function i(e,t,n,r){this.message=e,this.expected=t,this.found=n,this.location=r,this.name=`SyntaxError`,typeof Error.captureStackTrace==`function`&&Error.captureStackTrace(this,i)}r(i,Error),i.buildMessage=function(e,t){var n={literal:function(e){return`"`+i(e.text)+`"`},class:function(e){var t=``,n;for(n=0;n<e.parts.length;n++)t+=e.parts[n]instanceof Array?a(e.parts[n][0])+`-`+a(e.parts[n][1]):a(e.parts[n]);return`[`+(e.inverted?`^`:``)+t+`]`},any:function(e){return`any character`},end:function(e){return`end of input`},other:function(e){return e.description}};function r(e){return e.charCodeAt(0).toString(16).toUpperCase()}function i(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\0/g,`\\0`).replace(/\t/g,`\\t`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`).replace(/[\x00-\x0F]/g,function(e){return`\\x0`+r(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return`\\x`+r(e)})}function a(e){return e.replace(/\\/g,`\\\\`).replace(/\]/g,`\\]`).replace(/\^/g,`\\^`).replace(/-/g,`\\-`).replace(/\0/g,`\\0`).replace(/\t/g,`\\t`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`).replace(/[\x00-\x0F]/g,function(e){return`\\x0`+r(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return`\\x`+r(e)})}function o(e){return n[e.type](e)}function s(e){var t=Array(e.length),n,r;for(n=0;n<e.length;n++)t[n]=o(e[n]);if(t.sort(),t.length>0){for(n=1,r=1;n<t.length;n++)t[n-1]!==t[n]&&(t[r]=t[n],r++);t.length=r}switch(t.length){case 1:return t[0];case 2:return t[0]+` or `+t[1];default:return t.slice(0,-1).join(`, `)+`, or `+t[t.length-1]}}function c(e){return e?`"`+i(e)+`"`:`end of input`}return`Expected `+s(e)+` but `+c(t)+` found.`};function a(t,n){n=n===void 0?{}:n;var r={},a={start:oe},o=oe,s=``,c=function(){return[]},l=`,`,u=ee(`,`,!1),d=function(e,t){return[e].concat(t)},f=function(e){return[e]},p=function(e,t){return{url:e,format:t}},m=function(e){return{url:e}},h=`url(`,g=ee(`url(`,!1),_=`)`,v=ee(`)`,!1),y=function(e){return e},b=`format(`,x=ee(`format(`,!1),S=`local(`,C=ee(`local(`,!1),w=function(e){return{local:e}},T=/^[^)]/,E=te([`)`],!0,!1),D=function(e){return he.extractValue(e.join(``))},O=/^[ \t\r\n\f]/,k=te([` `,` `,`\r`,`
96
- `,`\f`],!1,!1),A=0,j=[{line:1,column:1}],M=0,N=[],P=0,F;if(`startRule`in n){if(!(n.startRule in a))throw Error(`Can't start parsing from rule "`+n.startRule+`".`);o=a[n.startRule]}function ee(e,t){return{type:`literal`,text:e,ignoreCase:t}}function te(e,t,n){return{type:`class`,parts:e,inverted:t,ignoreCase:n}}function ne(){return{type:`end`}}function re(e){var n=j[e],r;if(n)return n;for(r=e-1;!j[r];)r--;for(n=j[r],n={line:n.line,column:n.column};r<e;)t.charCodeAt(r)===10?(n.line++,n.column=1):n.column++,r++;return j[e]=n,n}function ie(e,t){var n=re(e),r=re(t);return{start:{offset:e,line:n.line,column:n.column},end:{offset:t,line:r.line,column:r.column}}}function I(e){A<M||(A>M&&(M=A,N=[]),N.push(e))}function ae(e,t,n){return new i(i.buildMessage(e,t),e,t,n)}function oe(){var e=se(),t;return e===r&&(e=A,t=s,t!==r&&(t=c()),e=t),e}function se(){var e=A,n=ce(),i,a,o,s;if(n!==r){for(i=[],a=me();a!==r;)i.push(a),a=me();if(i!==r)if(t.charCodeAt(A)===44?(a=l,A++):(a=r,P===0&&I(u)),a!==r){for(o=[],s=me();s!==r;)o.push(s),s=me();o===r?(A=e,e=r):(s=se(),s===r?(A=e,e=r):(n=d(n,s),e=n))}else A=e,e=r;else A=e,e=r}else A=e,e=r;return e===r&&(e=A,n=ce(),n!==r&&(n=f(n)),e=n),e}function ce(){var e=le();return e===r&&(e=fe()),e}function le(){var e=A,t=ue(),n,i;if(t!==r){if(n=[],i=me(),i!==r)for(;i!==r;)n.push(i),i=me();else n=r;n===r?(A=e,e=r):(i=de(),i===r?(A=e,e=r):(t=p(t,i),e=t))}else A=e,e=r;return e===r&&(e=A,t=ue(),t!==r&&(t=m(t)),e=t),e}function ue(){var e=A,n,i,a;return t.substr(A,4)===h?(n=h,A+=4):(n=r,P===0&&I(g)),n===r?(A=e,e=r):(i=pe(),i===r?(A=e,e=r):(t.charCodeAt(A)===41?(a=_,A++):(a=r,P===0&&I(v)),a===r?(A=e,e=r):(n=y(i),e=n))),e}function de(){var e=A,n,i,a;return t.substr(A,7)===b?(n=b,A+=7):(n=r,P===0&&I(x)),n===r?(A=e,e=r):(i=pe(),i===r?(A=e,e=r):(t.charCodeAt(A)===41?(a=_,A++):(a=r,P===0&&I(v)),a===r?(A=e,e=r):(n=y(i),e=n))),e}function fe(){var e=A,n,i,a;return t.substr(A,6)===S?(n=S,A+=6):(n=r,P===0&&I(C)),n===r?(A=e,e=r):(i=pe(),i===r?(A=e,e=r):(t.charCodeAt(A)===41?(a=_,A++):(a=r,P===0&&I(v)),a===r?(A=e,e=r):(n=w(i),e=n))),e}function pe(){var e=A,n=[],i;if(T.test(t.charAt(A))?(i=t.charAt(A),A++):(i=r,P===0&&I(E)),i!==r)for(;i!==r;)n.push(i),T.test(t.charAt(A))?(i=t.charAt(A),A++):(i=r,P===0&&I(E));else n=r;return n!==r&&(n=D(n)),e=n,e}function me(){var e;return O.test(t.charAt(A))?(e=t.charAt(A),A++):(e=r,P===0&&I(k)),e}var he=e(`../util`);if(F=o(),F!==r&&A===t.length)return F;throw F!==r&&A<t.length&&I(ne()),ae(N,M<t.length?t.charAt(M):null,M<t.length?ie(M,M+1):ie(M,M))}t.exports={SyntaxError:i,parse:a}},{"../util":3}],2:[function(e,t,n){var r=e(`./grammar`);n.SyntaxError=function(e,t){this.message=e,this.offset=t},n.parse=function(e){try{return r.parse(e)}catch(e){throw new n.SyntaxError(e.message,e.offset)}},n.serialize=function(e){return e.map(function(e){var t;return e.url?(t=`url("`+e.url+`")`,e.format&&(t+=` format("`+e.format+`")`)):t=`local("`+e.local+`")`,t}).join(`, `)}},{"./grammar":1}],3:[function(e,t,n){var r=function(e){return e.replace(/^[\t\r\f\n ]*(.+?)[\t\r\f\n ]*$/,`$1`)},i=function(e){var t=/^"(.*)"$/,n=/^'(.*)'$/;return t.test(e)?e.replace(t,`$1`):n.test(e)?e.replace(n,`$1`):e};n.extractValue=function(e){return i(r(e))}},{}]},{},[2])(2)})})),gy=r((e=>{var t=uy(),n=py(),r=my(),i=hy(),a=function(e,t,n){e.style.setProperty(t,n,e.style.getPropertyPriority(t))},o=function(e){return e.filter(function(e){return e.type===window.CSSRule.STYLE_RULE&&(e.style.getPropertyValue(`background-image`)||e.style.getPropertyValue(`background`))})},s=function(e){var t=[];return e.forEach(function(e){e.style.getPropertyValue(`background-image`)?t.push({property:`background-image`,value:e.style.getPropertyValue(`background-image`),rule:e}):e.style.getPropertyValue(`background`)&&t.push({property:`background`,value:e.style.getPropertyValue(`background`),rule:e})}),t},c=function(e){return e.filter(function(e){return e.type===window.CSSRule.FONT_FACE_RULE&&e.style.getPropertyValue(`src`)})},l=function(e){return e.filter(function(e){return e.type===window.CSSRule.IMPORT_RULE&&e.href})},u=function(e){var n=[];return e.forEach(function(e,r){e.url&&!t.isDataUri(e.url)&&n.push(r)}),n},d=function(e){var n=[];return e.forEach(function(e,r){e.url&&!t.isDataUri(e.url)&&n.push(r)}),n};e.adjustPathsOfCssResources=function(e,f,p){var m=s(o(f)),h=!1;return m.forEach(function(n){var i=r.parse(n.value),o=u(i),s;o.length>0&&(o.forEach(function(n){var r=i[n].url,a=t.joinUrl(e,r);i[n].url=a}),s=r.serialize(i),a(n.rule,n.property,s),h=!0)}),c(f).forEach(function(r){var a=r.style.getPropertyValue(`src`),o,s;try{o=i.parse(a)}catch{return}s=d(o),s.length>0&&(s.forEach(function(n){var r=o[n].url,i=t.joinUrl(e,r);o[n].url=i}),n.changeFontFaceRuleSrc(f,r,i.serialize(o,p),p),h=!0)}),l(f).forEach(function(r){var i=r.href,a=t.joinUrl(e,i);n.exchangeRule(f,r,`@import url(`+a+`);`,p),h=!0}),h};var f=function(e,t,n){var r=e.indexOf(t);e.splice(r,1),n.forEach(function(t,n){e.splice(r+n,0,t)})},p=function(r,i,a,o){var s=i.href,c;return s=n.unquoteString(s),c=t.joinUrl(o.baseUrl,s),a.indexOf(c)>=0?(f(r,i,[]),Promise.resolve([])):(a.push(c),t.ajax(s,o).then(function(t){var c=n.rulesForCssText(t,o);return e.loadCSSImportsForRules(c,a,o).then(function(t){return e.adjustPathsOfCssResources(s,c,o),f(r,i,c),t.errors})},function(e){throw{resourceType:`stylesheet`,url:e.url,msg:`Unable to load stylesheet `+e.url}}))};e.loadCSSImportsForRules=function(e,t,n){var r=l(e),i=[],a=!1;return Promise.all(r.map(function(r){return p(e,r,t,n).then(function(e){i=i.concat(e),a=!0},function(e){i.push(e)})})).then(function(){return{hasChanges:a,errors:i}})};var m=function(e,n){var i=r.parse(e),a=u(i),o=!1;return t.collectAndReportErrors(a.map(function(e){var r=i[e].url;return t.getDataURIForImageURL(r,n).then(function(t){i[e].url=t,o=!0},function(e){throw{resourceType:`backgroundImage`,url:e.url,msg:`Unable to load background-image `+e.url}})})).then(function(e){return{backgroundValue:r.serialize(i),hasChanges:o,errors:e}})},h=function(e,t){var n=s(o(e)),r=[],i=!1;return Promise.all(n.map(function(e){return m(e.value,t).then(function(t){t.hasChanges&&(a(e.rule,e.property,t.backgroundValue),i=!0),r=r.concat(t.errors)})})).then(function(){return{hasChanges:i,errors:r}})},g=function(e,n){var r=!1,a,o;try{a=i.parse(e)}catch{a=[]}return o=d(a),t.collectAndReportErrors(o.map(function(e){var i=a[e],o=i.format||`woff`;return t.binaryAjax(i.url,n).then(function(e){var t=btoa(e);i.url=`data:font/`+o+`;base64,`+t,r=!0},function(e){throw{resourceType:`fontFace`,url:e.url,msg:`Unable to load font-face `+e.url}})})).then(function(e){return{srcDeclarationValue:i.serialize(a),hasChanges:r,errors:e}})},_=function(e,t){var r=c(e),i=[],a=!1;return Promise.all(r.map(function(r){return g(r.style.getPropertyValue(`src`),t).then(function(o){o.hasChanges&&(n.changeFontFaceRuleSrc(e,r,o.srcDeclarationValue,t),a=!0),i=i.concat(o.errors)})})).then(function(){return{hasChanges:a,errors:i}})};e.loadAndInlineCSSResourcesForRules=function(e,t){var n=!1,r=[];return Promise.all([h,_].map(function(i){return i(e,t).then(function(e){n||=e.hasChanges,r=r.concat(e.errors)})})).then(function(){return{hasChanges:n,errors:r}})}})),_y=r((e=>{var t=uy(),n=dy(),r=fy(),i=gy(),a=py(),o=function(e){return t.joinUrl(e,`.`)},s=function(e){return e.map(function(t,n){return n===e.length-1&&(t={baseUrl:o(t.baseUrl)}),JSON.stringify(t)})},c=function(e,n){return n.cache!==!1&&n.cache!==`none`&&n.cacheBucket?t.memoize(e,s,n.cacheBucket):e},l=function(e,t,n){var r=a.rulesForCssText(e,n);return i.loadCSSImportsForRules(r,t,n).then(function(t){return i.loadAndInlineCSSResourcesForRules(r,n).then(function(n){var i=t.errors.concat(n.errors),o=t.hasChanges||n.hasChanges;return o&&(e=a.cssRulesToText(r)),{hasChanges:o,content:e,errors:i}})})},u=function(e,n,r){var i=e.textContent;return c(l,n)(i,r,n).then(function(n){return n.hasChanges&&(e.childNodes[0].nodeValue=n.content),t.cloneArray(n.errors)})},d=function(e){var t=e.getElementsByTagName(`style`);return Array.prototype.filter.call(t,function(e){return!e.attributes.type||e.attributes.type.value===`text/css`})};e.loadAndInlineStyles=function(e,n){var r=d(e),i=[],a=[],o=t.clone(n);return o.baseUrl=o.baseUrl||t.getDocumentBaseUrl(e),Promise.all(r.map(function(e){return u(e,o,a).then(function(e){i=i.concat(e)})})).then(function(){return i})};var f=function(e,t,n){var r=e.parentNode,i;t=t.trim(),t&&(i=e.ownerDocument.createElement(`style`),i.type=`text/css`,n&&n.nonce&&(i.nonce=n.nonce),i.appendChild(e.ownerDocument.createTextNode(t)),r.insertBefore(i,e)),r.removeChild(e)},p=function(e,n){return t.ajax(e,n).then(function(e){return{content:e,cssRules:a.rulesForCssText(e,n)}}).then(function(t){var r=i.adjustPathsOfCssResources(e,t.cssRules,n);return{content:t.content,cssRules:t.cssRules,hasChanges:r}}).then(function(e){return i.loadCSSImportsForRules(e.cssRules,[],n).then(function(t){return{content:e.content,cssRules:e.cssRules,hasChanges:e.hasChanges||t.hasChanges,errors:t.errors}})}).then(function(e){return i.loadAndInlineCSSResourcesForRules(e.cssRules,n).then(function(t){return{content:e.content,cssRules:e.cssRules,hasChanges:e.hasChanges||t.hasChanges,errors:e.errors.concat(t.errors)}})}).then(function(e){var t=e.content;return e.hasChanges&&(t=a.cssRulesToText(e.cssRules)),{content:t,errors:e.errors}})},m=function(e,n){var r=e.attributes.href.value,i=t.getDocumentBaseUrl(e.ownerDocument),a=t.clone(n);return!a.baseUrl&&i&&(a.baseUrl=i),c(p,n)(r,a).then(function(e){return{content:e.content,errors:t.cloneArray(e.errors)}})},h=function(e){var t=e.getElementsByTagName(`link`);return Array.prototype.filter.call(t,function(e){return e.attributes.rel&&e.attributes.rel.value===`stylesheet`&&(!e.attributes.type||e.attributes.type.value===`text/css`)})};e.loadAndInlineCssLinks=function(e,t){var n=h(e),r=[];return Promise.all(n.map(function(e){return m(e,t).then(function(n){f(e,n.content+`
97
- `,t),r=r.concat(n.errors)},function(e){r.push({resourceType:`stylesheet`,url:e.url,msg:`Unable to load stylesheet `+e.url})})})).then(function(){return r})},e.loadAndInlineImages=n.inline,e.loadAndInlineScript=r.inline,e.inlineReferences=function(t,n){var r=[],i=[e.loadAndInlineImages,e.loadAndInlineStyles,e.loadAndInlineCssLinks];return n.inlineScripts!==!1&&i.push(e.loadAndInlineScript),Promise.all(i.map(function(e){return e(t,n).then(function(e){r=r.concat(e)})})).then(function(){return r})}})),vy=e(r(((e,t)=>{(function(e,n){e===void 0&&window!==void 0&&(e=window),typeof define==`function`&&define.amd?define([`url`,`xmlserializer`,`sane-domparser-error`,`inlineresources`],function(t,r,i,a){return e.rasterizeHTML=n(t,r,i,a)}):typeof t==`object`&&t.exports?t.exports=n(sy(),cy(),ly(),_y()):e.rasterizeHTML=n(e.url,e.xmlserializer,e.sanedomparsererror,e.inlineresources)})(e,function(e,t,n,r){var i=(function(e){var t={},n=[];t.joinUrl=function(t,n){return t?e.resolve(t,n):n},t.getConstantUniqueIdFor=function(e){return n.indexOf(e)<0&&n.push(e),n.indexOf(e)},t.clone=function(e){var t={},n;for(n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t};var r=function(e){return typeof e==`object`&&!!e},i=function(e){return r(e)&&Object.prototype.toString.apply(e).match(/\[object (Canvas|HTMLCanvasElement|OffscreenCanvas)\]/i)};return t.parseOptionalParameters=function(e){var n={canvas:null,options:{}};return e[0]==null||i(e[0])?(n.canvas=e[0]||null,n.options=t.clone(e[1])):n.options=t.clone(e[0]),n},t})(e),a=(function(e){var t={},n=function(e,t,n){var r=e[t];return e[t]=function(){var e=Array.prototype.slice.call(arguments);return n.apply(this,[e,r])},r};return t.baseUrlRespectingXhr=function(t,r){return function(){var i=new t;return n(i,`open`,function(t,n){var i=t.shift(),a=t.shift(),o=e.joinUrl(r,a);return n.apply(this,[i,o].concat(t))}),i}},t.finishNotifyingXhr=function(e){var t=0,r=0,i=!1,a,o=new Promise(function(e){a=function(){t-r<=0&&i&&e({totalCount:t})}}),s=function(){var i=new e;return n(i,`send`,function(e,n){return t+=1,n.apply(this,arguments)}),i.addEventListener(`load`,function(){r+=1,a()}),i};return s.waitForRequestsToFinish=function(){return i=!0,a(),o},s},t})(i),o=(function(e){var t={},n=function(e){return Array.prototype.slice.call(e)},r={active:!0,hover:!0,focus:!1,target:!1};return t.fakeUserAction=function(t,n,i){var a=t.querySelector(n),o=`:`+i,s=`rasterizehtml`+i;a&&(r[i]?e.addClassNameRecursively(a,s):e.addClassName(a,s),e.rewriteCssSelectorWith(t,o,`.`+s))},t.persistInputValues=function(e){var t=e.querySelectorAll(`input`),r=e.querySelectorAll(`textarea`),i=function(e){return e.type===`checkbox`||e.type===`radio`};n(t).filter(i).forEach(function(e){e.checked?e.setAttribute(`checked`,``):e.removeAttribute(`checked`)}),n(t).filter(function(e){return!i(e)}).forEach(function(e){e.setAttribute(`value`,e.value)}),n(r).forEach(function(e){e.textContent=e.value})},t.rewriteTagNameSelectorsToLowerCase=function(t){e.lowercaseCssTypeSelectors(t,e.findHtmlOnlyNodeNames(t))},t})((function(){var e={},t=function(e){return Array.prototype.slice.call(e)};e.addClassName=function(e,t){e.className+=` `+t},e.addClassNameRecursively=function(t,n){e.addClassName(t,n),t.parentNode!==t.ownerDocument&&e.addClassNameRecursively(t.parentNode,n)};var n=function(e,n){var r=e.parentStyleSheet,i=t(r.cssRules).indexOf(e);r.insertRule(n,i+1),r.deleteRule(i)},r=function(e,t){var r=e.cssText.replace(/^[^\{]+/,``);n(e,t+` `+r)},i=function(e){return t(e).reduce(function(e,t){return e+t.cssText},``)},a=function(e){e.textContent=i(e.sheet.cssRules)},o=function(e){var t=document.implementation.createHTMLDocument(``),n=document.createElement(`style`);n.textContent=e.textContent,t.body.appendChild(n),e.sheet=n.sheet},s=function(e){return`((?:^|[^.#:\\w])|(?=\\W))(`+e.join(`|`)+`)(?=\\W|$)`},c=function(e,n,i){var c=s(n);t(e.querySelectorAll(`style`)).forEach(function(e){e.sheet===void 0&&o(e);var n=t(e.sheet.cssRules).filter(function(e){return e.selectorText&&new RegExp(c,`i`).test(e.selectorText)});n.length&&(n.forEach(function(e){var t=e.selectorText.replace(new RegExp(c,`gi`),function(e,t,n){return t+i(n)});t!==e.selectorText&&r(e,t)}),a(e))})};return e.rewriteCssSelectorWith=function(e,t,n){c(e,[t],function(){return n})},e.lowercaseCssTypeSelectors=function(e,t){c(e,t,function(e){return e.toLowerCase()})},e.findHtmlOnlyNodeNames=function(e){var t=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),n={},r={},i;do i=t.currentNode.tagName.toLowerCase(),t.currentNode.namespaceURI===`http://www.w3.org/1999/xhtml`?n[i]=!0:r[i]=!0;while(t.nextNode());return Object.keys(n).filter(function(e){return!r[e]})},e})()),s=(function(e,t,n,r){var i={},a=function(e,t,n,r){var i=e.createElement(t);return i.style.visibility=`hidden`,i.style.width=n+`px`,i.style.height=r+`px`,i.style.position=`absolute`,i.style.top=-1e4-r+`px`,i.style.left=-1e4-n+`px`,e.getElementsByTagName(`body`)[0].appendChild(i),i},o=function(e){return e>0?new Promise(function(t){setTimeout(t,e)}):Promise.resolve()};i.executeJavascript=function(e,n){return new Promise(function(i){var s=a(r.document,`iframe`,n.width,n.height),c=e.outerHTML,l=[],u=n.executeJsTimeout||0,d=function(){r.document.getElementsByTagName(`body`)[0].removeChild(s)},f=function(){var e=s.contentDocument;i({document:e,errors:l,cleanUp:d})},p=s.contentWindow.XMLHttpRequest,m=t.finishNotifyingXhr(p),h=t.baseUrlRespectingXhr(m,n.baseUrl);s.onload=function(){o(u).then(m.waitForRequestsToFinish).then(f)},s.contentDocument.open(),s.contentWindow.XMLHttpRequest=h,s.contentWindow.onerror=function(e){l.push({resourceType:`scriptExecution`,msg:e})},s.contentDocument.write(`<!DOCTYPE html>`),s.contentDocument.write(c),s.contentDocument.close()})};var s=function(e,t,n){var r=e.createElement(`iframe`);return r.style.width=t+`px`,r.style.height=n+`px`,r.style.visibility=`hidden`,r.style.position=`absolute`,r.style.top=-1e4-n+`px`,r.style.left=-1e4-t+`px`,r.style.borderWidth=0,r.sandbox=`allow-same-origin`,r.scrolling=`no`,r},c=function(e,t,n){var i=Math.floor(e/n),a=Math.floor(t/n);return s(r.document,i,a)},l=function(e,t,n,r){return{width:Math.max(e.width*r,t),height:Math.max(e.height*r,n)}},u=function(e,t){var n=e.querySelector(t);if(n)return n;if(e.ownerDocument.querySelector(t)===e)return e;throw{message:`Clipping selector not found`}},d=function(e,t,n,i,a){var o=Math.max(e.scrollWidth,e.clientWidth),s=Math.max(e.scrollHeight,e.clientHeight),c,d,f,p,m,h,g,_;return t?(h=u(e,t),g=h.getBoundingClientRect(),c=g.top,d=g.left,f=g.width,p=g.height):(c=0,d=0,f=o,p=s),_=l({width:f,height:p},n,i,a),m=r.getComputedStyle(e.ownerDocument.documentElement).fontSize,{left:d,top:c,width:_.width,height:_.height,viewportWidth:o,viewportHeight:s,rootFontSize:m}},f=function(e,t){var n=e.tagName;return t.querySelector(n)},p=function(e){var t=e.tagName.toLowerCase();return t===`html`||t===`body`?e.outerHTML:`<body style="margin: 0;">`+e.outerHTML+`</body>`};i.calculateDocumentContentSize=function(e,t){return new Promise(function(n,i){var a=t.zoom||1,o=c(t.width,t.height,a);r.document.getElementsByTagName(`body`)[0].appendChild(o),o.onload=function(){var s=o.contentDocument,c;try{c=d(f(e,s),t.clip,t.width,t.height,a),n(c)}catch(e){i(e)}finally{r.document.getElementsByTagName(`body`)[0].removeChild(o)}},o.contentDocument.open(),o.contentDocument.write(`<!DOCTYPE html>`),o.contentDocument.write(p(e)),o.contentDocument.close()})},i.parseHtmlFragment=function(e){var t=r.document.implementation.createHTMLDocument(``);t.documentElement.innerHTML=e;var n=t.querySelector(`body`).firstChild;if(!n)throw`Invalid source`;return n};var m=function(e,t){var n=/<html((?:\s+[^>]*)?)>/im.exec(t),i=r.document.implementation.createHTMLDocument(``),a,o,s,c;if(n)for(a=`<div`+n[1]+`></div>`,i.documentElement.innerHTML=a,s=i.querySelector(`div`),o=0;o<s.attributes.length;o++)c=s.attributes[o],e.documentElement.setAttribute(c.name,c.value)};i.parseHTML=function(e){var t=r.document.implementation.createHTMLDocument(``);return t.documentElement.innerHTML=e,m(t,e),t};var h=function(e){try{return n.failOnParseError(e)}catch(e){throw{message:`Invalid source`,originalError:e}}};i.validateXHTML=function(e){h(new DOMParser().parseFromString(e,`application/xml`))};var g=null,_=function(e,t){return t===`none`||t===`repeated`?((g===null||t!==`repeated`)&&(g=Date.now()),e+`?_=`+g):e},v=function(t,n){return new Promise(function(r,i){var a=new window.XMLHttpRequest,o=_(e.joinUrl(n.baseUrl,t),n.cache),s=function(e){i({message:`Unable to load page`,originalError:e})};a.addEventListener(`load`,function(){a.status===200||a.status===0?r(a.responseXML):s(a.statusText)},!1),a.addEventListener(`error`,function(e){s(e)},!1);try{a.open(`GET`,o,!0),a.responseType=`document`,a.send(null)}catch(e){s(e)}})};return i.loadDocument=function(e,t){return v(e,t).then(function(e){return h(e)})},i})(i,a,n,window),c=(function(){var e={},t=function(e,t){return t?URL.createObjectURL(new Blob([e],{type:`image/svg+xml`})):`data:image/svg+xml;charset=utf-8,`+encodeURIComponent(e)},n=function(e){e instanceof Blob&&URL.revokeObjectURL(e)},r=`<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"><foreignObject></foreignObject></svg>`,i=function(e){return new Promise(function(t,n){var r=document.createElement(`canvas`),i=new Image;i.onload=function(){var e=r.getContext(`2d`);try{e.drawImage(i,0,0),r.toDataURL(`image/png`),t(!0)}catch{t(!1)}},i.onerror=n,i.src=e})},a=function(){var e=t(r,!0);return i(e).then(function(a){return n(e),a?!1:i(t(r,!1)).then(function(e){return e})},function(){return!1})},o=function(){return new Promise(function(e,t){a().then(function(t){e(!t)},function(){t()})})},s,c=function(){return s===void 0&&(s=o()),s},l=function(e){return c().then(function(n){return t(e,n)})};return e.renderSvg=function(e){return new Promise(function(t,r){var i,a,o=function(){a.onload=null,a.onerror=null},s=function(){i&&n(i)};a=new Image,a.onload=function(){o(),s(),t(a)},a.onerror=function(){s(),r()},l(e).then(function(e){i=e,a.src=i},r)})},e})(window);return(function(e,t,n){var r={},i=function(e,t){var n=300,r=200,i=e?e.width:n,a=e?e.height:r;return{width:t.width===void 0?i:t.width,height:t.height===void 0?a:t.height}},a=function(t){var n=i(t.canvas,t.options),r=e.clone(t.options);return r.width=n.width,r.height=n.height,r};r.drawDocument=function(){var t=arguments[0],r=Array.prototype.slice.call(arguments,1),i=e.parseOptionalParameters(r),o=t.documentElement?t.documentElement:t;return n.rasterize(o,i.canvas,a(i))};var o=function(e,n,i){var a=t.parseHTML(e);return r.drawDocument(a,n,i)};r.drawHTML=function(){var t=arguments[0],n=Array.prototype.slice.call(arguments,1),r=e.parseOptionalParameters(n);return o(t,r.canvas,r.options)};var s=function(t,n,r){var i=document.implementation.createHTMLDocument(``);i.replaceChild(t.documentElement,i.documentElement);var a=r?e.clone(r):{};return r.baseUrl||(a.baseUrl=n),{document:i,options:a}},c=function(e,n,i){return t.loadDocument(e,i).then(function(t){var a=s(t,e,i);return r.drawDocument(a.document,n,a.options)})};return r.drawURL=function(){var t=arguments[0],n=Array.prototype.slice.call(arguments,1),r=e.parseOptionalParameters(n);return c(t,r.canvas,r.options)},r})(i,s,(function(e,t,n,r,i,a){var o={},s=function(e){return{message:`Error rendering page`,originalError:e}},c=function(e){return i.renderSvg(e).then(function(t){return{image:t,svg:e}},function(e){throw s(e)})},l=function(e,t){try{t.getContext(`2d`).drawImage(e,0,0)}catch(e){throw s(e)}},u=function(e,t,n){return r.drawDocumentAsSvg(e,n).then(c).then(function(e){return t&&l(e.image,t),e})},d=function(e,r){return t.executeJavascript(e,r).then(function(e){var t=e.document;return n.persistInputValues(t),{document:t,errors:e.errors,cleanUp:e.cleanUp}})};return o.rasterize=function(t,n,r){var i=e.clone(r);return i.inlineScripts=r.executeJs===!0,a.inlineReferences(t,i).then(function(e){return r.executeJs?d(t,r).then(function(t){return{element:t.document.documentElement,errors:e.concat(t.errors),cleanUp:t.cleanUp}}):{element:t,errors:e,cleanUp:function(){}}}).then(function(e){return u(e.element,n,r).then(function(t){return e.cleanUp(),{image:t.image,svg:t.svg,errors:e.errors}})})},o})(i,s,o,(function(e,t,n,r){var i={},a=function(e,t){var n=t||1,r={width:e.width,height:e.height,"font-size":e.rootFontSize};return n!==1&&(r.style=`transform:scale(`+n+`); transform-origin: 0 0;`),r},o=function(e){var t=Math.round(e.viewportWidth),n=Math.round(e.viewportHeight);return{x:-e.left,y:-e.top,width:t,height:n}},s=function(e){e.style=(e.style||``)+`float: left;`},c=function(e){e.externalResourcesRequired=!0},l=function(){return`<style scoped="">html::-webkit-scrollbar { display: none; }</style>`},u=function(e){var t=Object.keys(e);return t.length?` `+t.map(function(t){return t+`="`+e[t]+`"`}).join(` `):``},d=function(e,n,i){var d=r.serializeToString(e);t.validateXHTML(d);var f=o(n);return s(f),c(f),`<svg xmlns="http://www.w3.org/2000/svg"`+u(a(n,i))+`>`+l()+`<foreignObject`+u(f)+`>`+d+`</foreignObject></svg>`};return i.getSvgForDocument=function(e,t,r){return n.rewriteTagNameSelectorsToLowerCase(e),d(e,t,r)},i.drawDocumentAsSvg=function(e,r){return[`hover`,`active`,`focus`,`target`].forEach(function(t){r[t]&&n.fakeUserAction(e,r[t],t)}),t.calculateDocumentContentSize(e,r).then(function(t){return i.getSvgForDocument(e,t,r.zoom)})},i})(i,s,o,t),c,r))})}))(),1),yy=e(pv(),1);function by(e,t){if(!e.includes(`@font-face`))return``;let n=new Set,r=new Set;t&&((t.match(/font-weight:\s*(\d+|bold|normal)/gi)||[]).forEach(e=>{let t=e.split(`:`)[1].trim();t===`bold`?n.add(`700`):t===`normal`?n.add(`400`):/^\d+$/.test(t)&&n.add(t)}),(t.match(/font-style:\s*(italic|normal)/gi)||[]).forEach(e=>{e.split(`:`)[1].trim().toLowerCase()===`italic`&&r.add(`italic`)}),/<(b|strong)\b/i.test(t)&&n.add(`700`),/<(i|em)\b/i.test(t)&&r.add(`italic`));let i=Qf(t);i&&i.trim()&&n.add(`400`),n.size===0&&n.add(`400`);let a=n,o=r.has(`italic`),s=Array.from(new Set(i)).map(e=>e.codePointAt(0)).filter(e=>e!==void 0),c=e.split(/}\s*/).map(e=>e&&e+`}`).filter(e=>/@font-face/.test(e)&&(e=>{let t=(e.match(/font-weight:\s*(\d+)/)||[])[1];if(t&&!a.has(t)||/font-style:\s*italic/.test(e)&&!o)return!1;let n=e.match(/unicode-range:\s*([^;]+);/);if(!n)return!0;let r=n[1].split(`,`).map(e=>{let[t,n=t]=e.replace(`U+`,``).split(`-`).map(e=>parseInt(e,16));return[t,n]});return s.some(e=>r.some(([t,n])=>e>=t&&e<=n))})(e)).join(`
98
- `);return c?`<style>${c}</style>`:``}var xy=`
95
+ `)],i=function(e){var n=t(e),i,a;for(i=0;i<r.length;i++)if(a=r[i].exec(n),a)return a[1]},a=function(e){var t;if(e===null)throw Error(`Parse error`);var r=n(e);if(r!==void 0)throw t=i(r)||`Parse error`,Error(t)};e.failOnParseError=function(e){return a(e),e}})),py=r((e=>{var t=uy();e.getDocumentBaseUrl=function(e){return e.baseURI===`about:blank`?null:e.baseURI},e.clone=function(e){var t={},n;for(n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t},e.cloneArray=function(e){return Array.prototype.slice.apply(e,[0])},e.joinUrl=function(e,n){return e?t.resolve(e,n):n},e.isDataUri=function(e){return/^data:/.test(e)},e.collectAndReportErrors=function(e){var t=[];return Promise.all(e.map(function(e){return e.catch(function(e){t.push(e)})})).then(function(){return t})};var n=null,r=function(e,t){return t===!1||t===`none`||t===`repeated`?((n===null||t!==`repeated`)&&(n=Date.now()),e+`?_=`+n):e};e.ajax=function(t,n){return new Promise(function(i,a){var o=new window.XMLHttpRequest,s=e.joinUrl(n.baseUrl,t),c,l=function(){a({msg:`Unable to load url`,url:s})};c=r(s,n.cache),o.addEventListener(`load`,function(){o.status===200||o.status===0?i(o.response):l()},!1),o.addEventListener(`error`,l,!1);try{o.open(`GET`,c,!0),o.overrideMimeType(n.mimeType),o.send(null)}catch{l()}})},e.binaryAjax=function(t,n){var r=e.clone(n);return r.mimeType=`text/plain; charset=x-user-defined`,e.ajax(t,r).then(function(e){for(var t=``,n=0;n<e.length;n++)t+=String.fromCharCode(e.charCodeAt(n)&255);return t})};var i=function(e){var t=function(e,t){return e.substring(0,t.length)===t};return t(e,`<?xml`)||t(e,`<svg`)?`image/svg+xml`:`image/png`};e.getDataURIForImageURL=function(t,n){return e.binaryAjax(t,n).then(function(e){var t=btoa(e);return`data:`+i(e)+`;base64,`+t})};var a=[],o=function(e){return a.indexOf(e)<0&&a.push(e),a.indexOf(e)};e.memoize=function(e,t,n){if(typeof n!=`object`)throw Error(`cacheBucket is not an object`);return function(){var r=Array.prototype.slice.call(arguments),i=t(r),a=o(e),s;return n[a]&&n[a][i]?n[a][i]:(s=e.apply(null,r),n[a]=n[a]||{},n[a][i]=s,s)}}})),my=r((e=>{var t=py(),n=function(e,n){var r=null;e.hasAttribute(`src`)?r=e.getAttribute(`src`):e.hasAttributeNS(`http://www.w3.org/1999/xlink`,`href`)?r=e.getAttributeNS(`http://www.w3.org/1999/xlink`,`href`):e.hasAttribute(`href`)&&(r=e.getAttribute(`href`));var i=t.getDocumentBaseUrl(e.ownerDocument),a=t.clone(n);return!a.baseUrl&&i&&(a.baseUrl=i),t.getDataURIForImageURL(r,a).then(function(e){return e},function(e){throw{resourceType:`image`,url:e.url,msg:`Unable to load image `+e.url}})},r=function(e){return e.filter(function(e){var n=null;return e.hasAttribute(`src`)?n=e.getAttribute(`src`):e.hasAttributeNS(`http://www.w3.org/1999/xlink`,`href`)?n=e.getAttributeNS(`http://www.w3.org/1999/xlink`,`href`):e.hasAttribute(`href`)&&(n=e.getAttribute(`href`)),n!==null&&!t.isDataUri(n)})},i=function(e){return Array.prototype.filter.call(e,function(e){return e.type===`image`})},a=function(e){return Array.prototype.slice.call(e)};e.inline=function(e,o){var s=a(e.getElementsByTagName(`img`)),c=a(e.getElementsByTagName(`image`)),l=i(e.getElementsByTagName(`input`));s=s.concat(c),s=s.concat(l);var u=r(s);return t.collectAndReportErrors(u.map(function(e){return n(e,o).then(function(t){e.attributes.src?e.attributes.src.value=t:e.attributes[`xlink:href`]?e.attributes[`xlink:href`].value=t:e.attributes.href&&(e.attributes.href.value=t)})}))}})),hy=r((e=>{var t=py(),n=function(e,n){var r=e.attributes.src.value,i=t.getDocumentBaseUrl(e.ownerDocument),a=t.clone(n);return!a.baseUrl&&i&&(a.baseUrl=i),t.ajax(r,a).catch(function(e){throw{resourceType:`script`,url:e.url,msg:`Unable to load script `+e.url}})},r=function(e){return e.replace(/<\//g,`<\\/`)},i=function(e,t){e.attributes.removeNamedItem(`src`),e.textContent=r(t)},a=function(e){var t=e.getElementsByTagName(`script`);return Array.prototype.filter.call(t,function(e){return!!e.attributes.src})};e.inline=function(e,r){var o=a(e);return t.collectAndReportErrors(o.map(function(e){return n(e,r).then(function(t){i(e,t)})}))}})),gy=r((e=>{e.unquoteString=function(e){var t=/^"(.*)"$/,n=/^'(.*)'$/;return t.test(e)?e.replace(t,`$1`):n.test(e)?e.replace(n,`$1`):e},e.rulesForCssText=function(e,t){var n=document.implementation.createHTMLDocument(``),r=document.createElement(`style`),i;return r.textContent=e,t&&t.nonce&&(r.nonce=t.nonce),n.body.appendChild(r),i=r.sheet.cssRules,Array.prototype.slice.call(i)},e.cssRulesToText=function(e){return e.reduce(function(e,t){return e+t.cssText},``)},e.exchangeRule=function(t,n,r,i){var a=t.indexOf(n);t[a]=e.rulesForCssText(r,i)[0]},e.changeFontFaceRuleSrc=function(t,n,r,i){var a=`@font-face { font-family: `+n.style.getPropertyValue(`font-family`)+`; `;n.style.getPropertyValue(`font-style`)&&(a+=`font-style: `+n.style.getPropertyValue(`font-style`)+`; `),n.style.getPropertyValue(`font-weight`)&&(a+=`font-weight: `+n.style.getPropertyValue(`font-weight`)+`; `),n.style.getPropertyValue(`unicode-range`)&&(a+=`unicode-range: `+n.style.getPropertyValue(`unicode-range`)+`; `),a+=`src: `+r+`}`,e.exchangeRule(t,n,a,i)}})),_y=r((e=>{var t=gy(),n=function(e){return e.replace(/^[\t\r\f\n ]*(.+?)[\t\r\f\n ]*$/,`$1`)};e.extractCssUrl=function(e){var r=/^url\(("[^"]+"|'[^']+'|[^\)]+)\)/,i;if(!r.test(e))throw Error(`Invalid url`);return i=r.exec(e)[1],t.unquoteString(n(i))};var r=function(e){var t=`(url\\(\\s*(?:"[^"]*"|'[^']*'|[^\\(]+)\\s*\\)|[^,\\s]+)`,n=`(?:\\s*`+t+`)+`,r=`^\\s*(`+n+`)(?:\\s*,\\s*(`+n+`))*\\s*$`,i=new RegExp(n,`g`),a,o=[],s=function(e){for(var n=new RegExp(t,`g`),r=[],i=n.exec(e);i;)r.push(i[1]),i=n.exec(e);return r};if(e.match(new RegExp(r))){for(a=i.exec(e);a;)o.push(s(a[0])),a=i.exec(e);return o}return[]},i=function(t){var n,r;for(n=0;n<t.length;n++)try{return r=e.extractCssUrl(t[n]),{url:r,idx:n}}catch{}};e.parse=function(e){return r(e).map(function(e){var t=i(e);return t?{preUrl:e.slice(0,t.idx),url:t.url,postUrl:e.slice(t.idx+1)}:{preUrl:e}})},e.serialize=function(e){return e.map(function(e){var t=[].concat(e.preUrl);return e.url&&t.push(`url("`+e.url+`")`),e.postUrl&&(t=t.concat(e.postUrl)),t.join(` `)}).join(`, `)}})),vy=r(((e,t)=>{(function(n){if(typeof e==`object`&&t!==void 0)t.exports=n();else if(typeof define==`function`&&define.amd)define([],n);else{var r=typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:this;r.cssFontFaceSrc=n()}})(function(){return(function e(t,r,i){function a(s,c){if(!r[s]){if(!t[s]){var l=typeof n==`function`&&n;if(!c&&l)return l(s,!0);if(o)return o(s,!0);var u=Error(`Cannot find module '`+s+`'`);throw u.code=`MODULE_NOT_FOUND`,u}var d=r[s]={exports:{}};t[s][0].call(d.exports,function(e){var n=t[s][1][e];return a(n||e)},d,d.exports,e,t,r,i)}return r[s].exports}for(var o=typeof n==`function`&&n,s=0;s<i.length;s++)a(i[s]);return a})({1:[function(e,t,n){function r(e,t){function n(){this.constructor=e}n.prototype=t.prototype,e.prototype=new n}function i(e,t,n,r){this.message=e,this.expected=t,this.found=n,this.location=r,this.name=`SyntaxError`,typeof Error.captureStackTrace==`function`&&Error.captureStackTrace(this,i)}r(i,Error),i.buildMessage=function(e,t){var n={literal:function(e){return`"`+i(e.text)+`"`},class:function(e){var t=``,n;for(n=0;n<e.parts.length;n++)t+=e.parts[n]instanceof Array?a(e.parts[n][0])+`-`+a(e.parts[n][1]):a(e.parts[n]);return`[`+(e.inverted?`^`:``)+t+`]`},any:function(e){return`any character`},end:function(e){return`end of input`},other:function(e){return e.description}};function r(e){return e.charCodeAt(0).toString(16).toUpperCase()}function i(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\0/g,`\\0`).replace(/\t/g,`\\t`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`).replace(/[\x00-\x0F]/g,function(e){return`\\x0`+r(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return`\\x`+r(e)})}function a(e){return e.replace(/\\/g,`\\\\`).replace(/\]/g,`\\]`).replace(/\^/g,`\\^`).replace(/-/g,`\\-`).replace(/\0/g,`\\0`).replace(/\t/g,`\\t`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`).replace(/[\x00-\x0F]/g,function(e){return`\\x0`+r(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return`\\x`+r(e)})}function o(e){return n[e.type](e)}function s(e){var t=Array(e.length),n,r;for(n=0;n<e.length;n++)t[n]=o(e[n]);if(t.sort(),t.length>0){for(n=1,r=1;n<t.length;n++)t[n-1]!==t[n]&&(t[r]=t[n],r++);t.length=r}switch(t.length){case 1:return t[0];case 2:return t[0]+` or `+t[1];default:return t.slice(0,-1).join(`, `)+`, or `+t[t.length-1]}}function c(e){return e?`"`+i(e)+`"`:`end of input`}return`Expected `+s(e)+` but `+c(t)+` found.`};function a(t,n){n=n===void 0?{}:n;var r={},a={start:oe},o=oe,s=``,c=function(){return[]},l=`,`,u=ee(`,`,!1),d=function(e,t){return[e].concat(t)},f=function(e){return[e]},p=function(e,t){return{url:e,format:t}},m=function(e){return{url:e}},h=`url(`,g=ee(`url(`,!1),_=`)`,v=ee(`)`,!1),y=function(e){return e},b=`format(`,x=ee(`format(`,!1),S=`local(`,C=ee(`local(`,!1),w=function(e){return{local:e}},T=/^[^)]/,E=te([`)`],!0,!1),D=function(e){return he.extractValue(e.join(``))},O=/^[ \t\r\n\f]/,k=te([` `,` `,`\r`,`
96
+ `,`\f`],!1,!1),A=0,j=[{line:1,column:1}],M=0,N=[],P=0,F;if(`startRule`in n){if(!(n.startRule in a))throw Error(`Can't start parsing from rule "`+n.startRule+`".`);o=a[n.startRule]}function ee(e,t){return{type:`literal`,text:e,ignoreCase:t}}function te(e,t,n){return{type:`class`,parts:e,inverted:t,ignoreCase:n}}function ne(){return{type:`end`}}function re(e){var n=j[e],r;if(n)return n;for(r=e-1;!j[r];)r--;for(n=j[r],n={line:n.line,column:n.column};r<e;)t.charCodeAt(r)===10?(n.line++,n.column=1):n.column++,r++;return j[e]=n,n}function ie(e,t){var n=re(e),r=re(t);return{start:{offset:e,line:n.line,column:n.column},end:{offset:t,line:r.line,column:r.column}}}function I(e){A<M||(A>M&&(M=A,N=[]),N.push(e))}function ae(e,t,n){return new i(i.buildMessage(e,t),e,t,n)}function oe(){var e=se(),t;return e===r&&(e=A,t=s,t!==r&&(t=c()),e=t),e}function se(){var e=A,n=ce(),i,a,o,s;if(n!==r){for(i=[],a=me();a!==r;)i.push(a),a=me();if(i!==r)if(t.charCodeAt(A)===44?(a=l,A++):(a=r,P===0&&I(u)),a!==r){for(o=[],s=me();s!==r;)o.push(s),s=me();o===r?(A=e,e=r):(s=se(),s===r?(A=e,e=r):(n=d(n,s),e=n))}else A=e,e=r;else A=e,e=r}else A=e,e=r;return e===r&&(e=A,n=ce(),n!==r&&(n=f(n)),e=n),e}function ce(){var e=le();return e===r&&(e=fe()),e}function le(){var e=A,t=ue(),n,i;if(t!==r){if(n=[],i=me(),i!==r)for(;i!==r;)n.push(i),i=me();else n=r;n===r?(A=e,e=r):(i=de(),i===r?(A=e,e=r):(t=p(t,i),e=t))}else A=e,e=r;return e===r&&(e=A,t=ue(),t!==r&&(t=m(t)),e=t),e}function ue(){var e=A,n,i,a;return t.substr(A,4)===h?(n=h,A+=4):(n=r,P===0&&I(g)),n===r?(A=e,e=r):(i=pe(),i===r?(A=e,e=r):(t.charCodeAt(A)===41?(a=_,A++):(a=r,P===0&&I(v)),a===r?(A=e,e=r):(n=y(i),e=n))),e}function de(){var e=A,n,i,a;return t.substr(A,7)===b?(n=b,A+=7):(n=r,P===0&&I(x)),n===r?(A=e,e=r):(i=pe(),i===r?(A=e,e=r):(t.charCodeAt(A)===41?(a=_,A++):(a=r,P===0&&I(v)),a===r?(A=e,e=r):(n=y(i),e=n))),e}function fe(){var e=A,n,i,a;return t.substr(A,6)===S?(n=S,A+=6):(n=r,P===0&&I(C)),n===r?(A=e,e=r):(i=pe(),i===r?(A=e,e=r):(t.charCodeAt(A)===41?(a=_,A++):(a=r,P===0&&I(v)),a===r?(A=e,e=r):(n=w(i),e=n))),e}function pe(){var e=A,n=[],i;if(T.test(t.charAt(A))?(i=t.charAt(A),A++):(i=r,P===0&&I(E)),i!==r)for(;i!==r;)n.push(i),T.test(t.charAt(A))?(i=t.charAt(A),A++):(i=r,P===0&&I(E));else n=r;return n!==r&&(n=D(n)),e=n,e}function me(){var e;return O.test(t.charAt(A))?(e=t.charAt(A),A++):(e=r,P===0&&I(k)),e}var he=e(`../util`);if(F=o(),F!==r&&A===t.length)return F;throw F!==r&&A<t.length&&I(ne()),ae(N,M<t.length?t.charAt(M):null,M<t.length?ie(M,M+1):ie(M,M))}t.exports={SyntaxError:i,parse:a}},{"../util":3}],2:[function(e,t,n){var r=e(`./grammar`);n.SyntaxError=function(e,t){this.message=e,this.offset=t},n.parse=function(e){try{return r.parse(e)}catch(e){throw new n.SyntaxError(e.message,e.offset)}},n.serialize=function(e){return e.map(function(e){var t;return e.url?(t=`url("`+e.url+`")`,e.format&&(t+=` format("`+e.format+`")`)):t=`local("`+e.local+`")`,t}).join(`, `)}},{"./grammar":1}],3:[function(e,t,n){var r=function(e){return e.replace(/^[\t\r\f\n ]*(.+?)[\t\r\f\n ]*$/,`$1`)},i=function(e){var t=/^"(.*)"$/,n=/^'(.*)'$/;return t.test(e)?e.replace(t,`$1`):n.test(e)?e.replace(n,`$1`):e};n.extractValue=function(e){return i(r(e))}},{}]},{},[2])(2)})})),yy=r((e=>{var t=py(),n=gy(),r=_y(),i=vy(),a=function(e,t,n){e.style.setProperty(t,n,e.style.getPropertyPriority(t))},o=function(e){return e.filter(function(e){return e.type===window.CSSRule.STYLE_RULE&&(e.style.getPropertyValue(`background-image`)||e.style.getPropertyValue(`background`))})},s=function(e){var t=[];return e.forEach(function(e){e.style.getPropertyValue(`background-image`)?t.push({property:`background-image`,value:e.style.getPropertyValue(`background-image`),rule:e}):e.style.getPropertyValue(`background`)&&t.push({property:`background`,value:e.style.getPropertyValue(`background`),rule:e})}),t},c=function(e){return e.filter(function(e){return e.type===window.CSSRule.FONT_FACE_RULE&&e.style.getPropertyValue(`src`)})},l=function(e){return e.filter(function(e){return e.type===window.CSSRule.IMPORT_RULE&&e.href})},u=function(e){var n=[];return e.forEach(function(e,r){e.url&&!t.isDataUri(e.url)&&n.push(r)}),n},d=function(e){var n=[];return e.forEach(function(e,r){e.url&&!t.isDataUri(e.url)&&n.push(r)}),n};e.adjustPathsOfCssResources=function(e,f,p){var m=s(o(f)),h=!1;return m.forEach(function(n){var i=r.parse(n.value),o=u(i),s;o.length>0&&(o.forEach(function(n){var r=i[n].url,a=t.joinUrl(e,r);i[n].url=a}),s=r.serialize(i),a(n.rule,n.property,s),h=!0)}),c(f).forEach(function(r){var a=r.style.getPropertyValue(`src`),o,s;try{o=i.parse(a)}catch{return}s=d(o),s.length>0&&(s.forEach(function(n){var r=o[n].url,i=t.joinUrl(e,r);o[n].url=i}),n.changeFontFaceRuleSrc(f,r,i.serialize(o,p),p),h=!0)}),l(f).forEach(function(r){var i=r.href,a=t.joinUrl(e,i);n.exchangeRule(f,r,`@import url(`+a+`);`,p),h=!0}),h};var f=function(e,t,n){var r=e.indexOf(t);e.splice(r,1),n.forEach(function(t,n){e.splice(r+n,0,t)})},p=function(r,i,a,o){var s=i.href,c;return s=n.unquoteString(s),c=t.joinUrl(o.baseUrl,s),a.indexOf(c)>=0?(f(r,i,[]),Promise.resolve([])):(a.push(c),t.ajax(s,o).then(function(t){var c=n.rulesForCssText(t,o);return e.loadCSSImportsForRules(c,a,o).then(function(t){return e.adjustPathsOfCssResources(s,c,o),f(r,i,c),t.errors})},function(e){throw{resourceType:`stylesheet`,url:e.url,msg:`Unable to load stylesheet `+e.url}}))};e.loadCSSImportsForRules=function(e,t,n){var r=l(e),i=[],a=!1;return Promise.all(r.map(function(r){return p(e,r,t,n).then(function(e){i=i.concat(e),a=!0},function(e){i.push(e)})})).then(function(){return{hasChanges:a,errors:i}})};var m=function(e,n){var i=r.parse(e),a=u(i),o=!1;return t.collectAndReportErrors(a.map(function(e){var r=i[e].url;return t.getDataURIForImageURL(r,n).then(function(t){i[e].url=t,o=!0},function(e){throw{resourceType:`backgroundImage`,url:e.url,msg:`Unable to load background-image `+e.url}})})).then(function(e){return{backgroundValue:r.serialize(i),hasChanges:o,errors:e}})},h=function(e,t){var n=s(o(e)),r=[],i=!1;return Promise.all(n.map(function(e){return m(e.value,t).then(function(t){t.hasChanges&&(a(e.rule,e.property,t.backgroundValue),i=!0),r=r.concat(t.errors)})})).then(function(){return{hasChanges:i,errors:r}})},g=function(e,n){var r=!1,a,o;try{a=i.parse(e)}catch{a=[]}return o=d(a),t.collectAndReportErrors(o.map(function(e){var i=a[e],o=i.format||`woff`;return t.binaryAjax(i.url,n).then(function(e){var t=btoa(e);i.url=`data:font/`+o+`;base64,`+t,r=!0},function(e){throw{resourceType:`fontFace`,url:e.url,msg:`Unable to load font-face `+e.url}})})).then(function(e){return{srcDeclarationValue:i.serialize(a),hasChanges:r,errors:e}})},_=function(e,t){var r=c(e),i=[],a=!1;return Promise.all(r.map(function(r){return g(r.style.getPropertyValue(`src`),t).then(function(o){o.hasChanges&&(n.changeFontFaceRuleSrc(e,r,o.srcDeclarationValue,t),a=!0),i=i.concat(o.errors)})})).then(function(){return{hasChanges:a,errors:i}})};e.loadAndInlineCSSResourcesForRules=function(e,t){var n=!1,r=[];return Promise.all([h,_].map(function(i){return i(e,t).then(function(e){n||=e.hasChanges,r=r.concat(e.errors)})})).then(function(){return{hasChanges:n,errors:r}})}})),by=r((e=>{var t=py(),n=my(),r=hy(),i=yy(),a=gy(),o=function(e){return t.joinUrl(e,`.`)},s=function(e){return e.map(function(t,n){return n===e.length-1&&(t={baseUrl:o(t.baseUrl)}),JSON.stringify(t)})},c=function(e,n){return n.cache!==!1&&n.cache!==`none`&&n.cacheBucket?t.memoize(e,s,n.cacheBucket):e},l=function(e,t,n){var r=a.rulesForCssText(e,n);return i.loadCSSImportsForRules(r,t,n).then(function(t){return i.loadAndInlineCSSResourcesForRules(r,n).then(function(n){var i=t.errors.concat(n.errors),o=t.hasChanges||n.hasChanges;return o&&(e=a.cssRulesToText(r)),{hasChanges:o,content:e,errors:i}})})},u=function(e,n,r){var i=e.textContent;return c(l,n)(i,r,n).then(function(n){return n.hasChanges&&(e.childNodes[0].nodeValue=n.content),t.cloneArray(n.errors)})},d=function(e){var t=e.getElementsByTagName(`style`);return Array.prototype.filter.call(t,function(e){return!e.attributes.type||e.attributes.type.value===`text/css`})};e.loadAndInlineStyles=function(e,n){var r=d(e),i=[],a=[],o=t.clone(n);return o.baseUrl=o.baseUrl||t.getDocumentBaseUrl(e),Promise.all(r.map(function(e){return u(e,o,a).then(function(e){i=i.concat(e)})})).then(function(){return i})};var f=function(e,t,n){var r=e.parentNode,i;t=t.trim(),t&&(i=e.ownerDocument.createElement(`style`),i.type=`text/css`,n&&n.nonce&&(i.nonce=n.nonce),i.appendChild(e.ownerDocument.createTextNode(t)),r.insertBefore(i,e)),r.removeChild(e)},p=function(e,n){return t.ajax(e,n).then(function(e){return{content:e,cssRules:a.rulesForCssText(e,n)}}).then(function(t){var r=i.adjustPathsOfCssResources(e,t.cssRules,n);return{content:t.content,cssRules:t.cssRules,hasChanges:r}}).then(function(e){return i.loadCSSImportsForRules(e.cssRules,[],n).then(function(t){return{content:e.content,cssRules:e.cssRules,hasChanges:e.hasChanges||t.hasChanges,errors:t.errors}})}).then(function(e){return i.loadAndInlineCSSResourcesForRules(e.cssRules,n).then(function(t){return{content:e.content,cssRules:e.cssRules,hasChanges:e.hasChanges||t.hasChanges,errors:e.errors.concat(t.errors)}})}).then(function(e){var t=e.content;return e.hasChanges&&(t=a.cssRulesToText(e.cssRules)),{content:t,errors:e.errors}})},m=function(e,n){var r=e.attributes.href.value,i=t.getDocumentBaseUrl(e.ownerDocument),a=t.clone(n);return!a.baseUrl&&i&&(a.baseUrl=i),c(p,n)(r,a).then(function(e){return{content:e.content,errors:t.cloneArray(e.errors)}})},h=function(e){var t=e.getElementsByTagName(`link`);return Array.prototype.filter.call(t,function(e){return e.attributes.rel&&e.attributes.rel.value===`stylesheet`&&(!e.attributes.type||e.attributes.type.value===`text/css`)})};e.loadAndInlineCssLinks=function(e,t){var n=h(e),r=[];return Promise.all(n.map(function(e){return m(e,t).then(function(n){f(e,n.content+`
97
+ `,t),r=r.concat(n.errors)},function(e){r.push({resourceType:`stylesheet`,url:e.url,msg:`Unable to load stylesheet `+e.url})})})).then(function(){return r})},e.loadAndInlineImages=n.inline,e.loadAndInlineScript=r.inline,e.inlineReferences=function(t,n){var r=[],i=[e.loadAndInlineImages,e.loadAndInlineStyles,e.loadAndInlineCssLinks];return n.inlineScripts!==!1&&i.push(e.loadAndInlineScript),Promise.all(i.map(function(e){return e(t,n).then(function(e){r=r.concat(e)})})).then(function(){return r})}})),xy=e(r(((e,t)=>{(function(e,n){e===void 0&&window!==void 0&&(e=window),typeof define==`function`&&define.amd?define([`url`,`xmlserializer`,`sane-domparser-error`,`inlineresources`],function(t,r,i,a){return e.rasterizeHTML=n(t,r,i,a)}):typeof t==`object`&&t.exports?t.exports=n(uy(),dy(),fy(),by()):e.rasterizeHTML=n(e.url,e.xmlserializer,e.sanedomparsererror,e.inlineresources)})(e,function(e,t,n,r){var i=(function(e){var t={},n=[];t.joinUrl=function(t,n){return t?e.resolve(t,n):n},t.getConstantUniqueIdFor=function(e){return n.indexOf(e)<0&&n.push(e),n.indexOf(e)},t.clone=function(e){var t={},n;for(n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t};var r=function(e){return typeof e==`object`&&!!e},i=function(e){return r(e)&&Object.prototype.toString.apply(e).match(/\[object (Canvas|HTMLCanvasElement|OffscreenCanvas)\]/i)};return t.parseOptionalParameters=function(e){var n={canvas:null,options:{}};return e[0]==null||i(e[0])?(n.canvas=e[0]||null,n.options=t.clone(e[1])):n.options=t.clone(e[0]),n},t})(e),a=(function(e){var t={},n=function(e,t,n){var r=e[t];return e[t]=function(){var e=Array.prototype.slice.call(arguments);return n.apply(this,[e,r])},r};return t.baseUrlRespectingXhr=function(t,r){return function(){var i=new t;return n(i,`open`,function(t,n){var i=t.shift(),a=t.shift(),o=e.joinUrl(r,a);return n.apply(this,[i,o].concat(t))}),i}},t.finishNotifyingXhr=function(e){var t=0,r=0,i=!1,a,o=new Promise(function(e){a=function(){t-r<=0&&i&&e({totalCount:t})}}),s=function(){var i=new e;return n(i,`send`,function(e,n){return t+=1,n.apply(this,arguments)}),i.addEventListener(`load`,function(){r+=1,a()}),i};return s.waitForRequestsToFinish=function(){return i=!0,a(),o},s},t})(i),o=(function(e){var t={},n=function(e){return Array.prototype.slice.call(e)},r={active:!0,hover:!0,focus:!1,target:!1};return t.fakeUserAction=function(t,n,i){var a=t.querySelector(n),o=`:`+i,s=`rasterizehtml`+i;a&&(r[i]?e.addClassNameRecursively(a,s):e.addClassName(a,s),e.rewriteCssSelectorWith(t,o,`.`+s))},t.persistInputValues=function(e){var t=e.querySelectorAll(`input`),r=e.querySelectorAll(`textarea`),i=function(e){return e.type===`checkbox`||e.type===`radio`};n(t).filter(i).forEach(function(e){e.checked?e.setAttribute(`checked`,``):e.removeAttribute(`checked`)}),n(t).filter(function(e){return!i(e)}).forEach(function(e){e.setAttribute(`value`,e.value)}),n(r).forEach(function(e){e.textContent=e.value})},t.rewriteTagNameSelectorsToLowerCase=function(t){e.lowercaseCssTypeSelectors(t,e.findHtmlOnlyNodeNames(t))},t})((function(){var e={},t=function(e){return Array.prototype.slice.call(e)};e.addClassName=function(e,t){e.className+=` `+t},e.addClassNameRecursively=function(t,n){e.addClassName(t,n),t.parentNode!==t.ownerDocument&&e.addClassNameRecursively(t.parentNode,n)};var n=function(e,n){var r=e.parentStyleSheet,i=t(r.cssRules).indexOf(e);r.insertRule(n,i+1),r.deleteRule(i)},r=function(e,t){var r=e.cssText.replace(/^[^\{]+/,``);n(e,t+` `+r)},i=function(e){return t(e).reduce(function(e,t){return e+t.cssText},``)},a=function(e){e.textContent=i(e.sheet.cssRules)},o=function(e){var t=document.implementation.createHTMLDocument(``),n=document.createElement(`style`);n.textContent=e.textContent,t.body.appendChild(n),e.sheet=n.sheet},s=function(e){return`((?:^|[^.#:\\w])|(?=\\W))(`+e.join(`|`)+`)(?=\\W|$)`},c=function(e,n,i){var c=s(n);t(e.querySelectorAll(`style`)).forEach(function(e){e.sheet===void 0&&o(e);var n=t(e.sheet.cssRules).filter(function(e){return e.selectorText&&new RegExp(c,`i`).test(e.selectorText)});n.length&&(n.forEach(function(e){var t=e.selectorText.replace(new RegExp(c,`gi`),function(e,t,n){return t+i(n)});t!==e.selectorText&&r(e,t)}),a(e))})};return e.rewriteCssSelectorWith=function(e,t,n){c(e,[t],function(){return n})},e.lowercaseCssTypeSelectors=function(e,t){c(e,t,function(e){return e.toLowerCase()})},e.findHtmlOnlyNodeNames=function(e){var t=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),n={},r={},i;do i=t.currentNode.tagName.toLowerCase(),t.currentNode.namespaceURI===`http://www.w3.org/1999/xhtml`?n[i]=!0:r[i]=!0;while(t.nextNode());return Object.keys(n).filter(function(e){return!r[e]})},e})()),s=(function(e,t,n,r){var i={},a=function(e,t,n,r){var i=e.createElement(t);return i.style.visibility=`hidden`,i.style.width=n+`px`,i.style.height=r+`px`,i.style.position=`absolute`,i.style.top=-1e4-r+`px`,i.style.left=-1e4-n+`px`,e.getElementsByTagName(`body`)[0].appendChild(i),i},o=function(e){return e>0?new Promise(function(t){setTimeout(t,e)}):Promise.resolve()};i.executeJavascript=function(e,n){return new Promise(function(i){var s=a(r.document,`iframe`,n.width,n.height),c=e.outerHTML,l=[],u=n.executeJsTimeout||0,d=function(){r.document.getElementsByTagName(`body`)[0].removeChild(s)},f=function(){var e=s.contentDocument;i({document:e,errors:l,cleanUp:d})},p=s.contentWindow.XMLHttpRequest,m=t.finishNotifyingXhr(p),h=t.baseUrlRespectingXhr(m,n.baseUrl);s.onload=function(){o(u).then(m.waitForRequestsToFinish).then(f)},s.contentDocument.open(),s.contentWindow.XMLHttpRequest=h,s.contentWindow.onerror=function(e){l.push({resourceType:`scriptExecution`,msg:e})},s.contentDocument.write(`<!DOCTYPE html>`),s.contentDocument.write(c),s.contentDocument.close()})};var s=function(e,t,n){var r=e.createElement(`iframe`);return r.style.width=t+`px`,r.style.height=n+`px`,r.style.visibility=`hidden`,r.style.position=`absolute`,r.style.top=-1e4-n+`px`,r.style.left=-1e4-t+`px`,r.style.borderWidth=0,r.sandbox=`allow-same-origin`,r.scrolling=`no`,r},c=function(e,t,n){var i=Math.floor(e/n),a=Math.floor(t/n);return s(r.document,i,a)},l=function(e,t,n,r){return{width:Math.max(e.width*r,t),height:Math.max(e.height*r,n)}},u=function(e,t){var n=e.querySelector(t);if(n)return n;if(e.ownerDocument.querySelector(t)===e)return e;throw{message:`Clipping selector not found`}},d=function(e,t,n,i,a){var o=Math.max(e.scrollWidth,e.clientWidth),s=Math.max(e.scrollHeight,e.clientHeight),c,d,f,p,m,h,g,_;return t?(h=u(e,t),g=h.getBoundingClientRect(),c=g.top,d=g.left,f=g.width,p=g.height):(c=0,d=0,f=o,p=s),_=l({width:f,height:p},n,i,a),m=r.getComputedStyle(e.ownerDocument.documentElement).fontSize,{left:d,top:c,width:_.width,height:_.height,viewportWidth:o,viewportHeight:s,rootFontSize:m}},f=function(e,t){var n=e.tagName;return t.querySelector(n)},p=function(e){var t=e.tagName.toLowerCase();return t===`html`||t===`body`?e.outerHTML:`<body style="margin: 0;">`+e.outerHTML+`</body>`};i.calculateDocumentContentSize=function(e,t){return new Promise(function(n,i){var a=t.zoom||1,o=c(t.width,t.height,a);r.document.getElementsByTagName(`body`)[0].appendChild(o),o.onload=function(){var s=o.contentDocument,c;try{c=d(f(e,s),t.clip,t.width,t.height,a),n(c)}catch(e){i(e)}finally{r.document.getElementsByTagName(`body`)[0].removeChild(o)}},o.contentDocument.open(),o.contentDocument.write(`<!DOCTYPE html>`),o.contentDocument.write(p(e)),o.contentDocument.close()})},i.parseHtmlFragment=function(e){var t=r.document.implementation.createHTMLDocument(``);t.documentElement.innerHTML=e;var n=t.querySelector(`body`).firstChild;if(!n)throw`Invalid source`;return n};var m=function(e,t){var n=/<html((?:\s+[^>]*)?)>/im.exec(t),i=r.document.implementation.createHTMLDocument(``),a,o,s,c;if(n)for(a=`<div`+n[1]+`></div>`,i.documentElement.innerHTML=a,s=i.querySelector(`div`),o=0;o<s.attributes.length;o++)c=s.attributes[o],e.documentElement.setAttribute(c.name,c.value)};i.parseHTML=function(e){var t=r.document.implementation.createHTMLDocument(``);return t.documentElement.innerHTML=e,m(t,e),t};var h=function(e){try{return n.failOnParseError(e)}catch(e){throw{message:`Invalid source`,originalError:e}}};i.validateXHTML=function(e){h(new DOMParser().parseFromString(e,`application/xml`))};var g=null,_=function(e,t){return t===`none`||t===`repeated`?((g===null||t!==`repeated`)&&(g=Date.now()),e+`?_=`+g):e},v=function(t,n){return new Promise(function(r,i){var a=new window.XMLHttpRequest,o=_(e.joinUrl(n.baseUrl,t),n.cache),s=function(e){i({message:`Unable to load page`,originalError:e})};a.addEventListener(`load`,function(){a.status===200||a.status===0?r(a.responseXML):s(a.statusText)},!1),a.addEventListener(`error`,function(e){s(e)},!1);try{a.open(`GET`,o,!0),a.responseType=`document`,a.send(null)}catch(e){s(e)}})};return i.loadDocument=function(e,t){return v(e,t).then(function(e){return h(e)})},i})(i,a,n,window),c=(function(){var e={},t=function(e,t){return t?URL.createObjectURL(new Blob([e],{type:`image/svg+xml`})):`data:image/svg+xml;charset=utf-8,`+encodeURIComponent(e)},n=function(e){e instanceof Blob&&URL.revokeObjectURL(e)},r=`<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"><foreignObject></foreignObject></svg>`,i=function(e){return new Promise(function(t,n){var r=document.createElement(`canvas`),i=new Image;i.onload=function(){var e=r.getContext(`2d`);try{e.drawImage(i,0,0),r.toDataURL(`image/png`),t(!0)}catch{t(!1)}},i.onerror=n,i.src=e})},a=function(){var e=t(r,!0);return i(e).then(function(a){return n(e),a?!1:i(t(r,!1)).then(function(e){return e})},function(){return!1})},o=function(){return new Promise(function(e,t){a().then(function(t){e(!t)},function(){t()})})},s,c=function(){return s===void 0&&(s=o()),s},l=function(e){return c().then(function(n){return t(e,n)})};return e.renderSvg=function(e){return new Promise(function(t,r){var i,a,o=function(){a.onload=null,a.onerror=null},s=function(){i&&n(i)};a=new Image,a.onload=function(){o(),s(),t(a)},a.onerror=function(){s(),r()},l(e).then(function(e){i=e,a.src=i},r)})},e})(window);return(function(e,t,n){var r={},i=function(e,t){var n=300,r=200,i=e?e.width:n,a=e?e.height:r;return{width:t.width===void 0?i:t.width,height:t.height===void 0?a:t.height}},a=function(t){var n=i(t.canvas,t.options),r=e.clone(t.options);return r.width=n.width,r.height=n.height,r};r.drawDocument=function(){var t=arguments[0],r=Array.prototype.slice.call(arguments,1),i=e.parseOptionalParameters(r),o=t.documentElement?t.documentElement:t;return n.rasterize(o,i.canvas,a(i))};var o=function(e,n,i){var a=t.parseHTML(e);return r.drawDocument(a,n,i)};r.drawHTML=function(){var t=arguments[0],n=Array.prototype.slice.call(arguments,1),r=e.parseOptionalParameters(n);return o(t,r.canvas,r.options)};var s=function(t,n,r){var i=document.implementation.createHTMLDocument(``);i.replaceChild(t.documentElement,i.documentElement);var a=r?e.clone(r):{};return r.baseUrl||(a.baseUrl=n),{document:i,options:a}},c=function(e,n,i){return t.loadDocument(e,i).then(function(t){var a=s(t,e,i);return r.drawDocument(a.document,n,a.options)})};return r.drawURL=function(){var t=arguments[0],n=Array.prototype.slice.call(arguments,1),r=e.parseOptionalParameters(n);return c(t,r.canvas,r.options)},r})(i,s,(function(e,t,n,r,i,a){var o={},s=function(e){return{message:`Error rendering page`,originalError:e}},c=function(e){return i.renderSvg(e).then(function(t){return{image:t,svg:e}},function(e){throw s(e)})},l=function(e,t){try{t.getContext(`2d`).drawImage(e,0,0)}catch(e){throw s(e)}},u=function(e,t,n){return r.drawDocumentAsSvg(e,n).then(c).then(function(e){return t&&l(e.image,t),e})},d=function(e,r){return t.executeJavascript(e,r).then(function(e){var t=e.document;return n.persistInputValues(t),{document:t,errors:e.errors,cleanUp:e.cleanUp}})};return o.rasterize=function(t,n,r){var i=e.clone(r);return i.inlineScripts=r.executeJs===!0,a.inlineReferences(t,i).then(function(e){return r.executeJs?d(t,r).then(function(t){return{element:t.document.documentElement,errors:e.concat(t.errors),cleanUp:t.cleanUp}}):{element:t,errors:e,cleanUp:function(){}}}).then(function(e){return u(e.element,n,r).then(function(t){return e.cleanUp(),{image:t.image,svg:t.svg,errors:e.errors}})})},o})(i,s,o,(function(e,t,n,r){var i={},a=function(e,t){var n=t||1,r={width:e.width,height:e.height,"font-size":e.rootFontSize};return n!==1&&(r.style=`transform:scale(`+n+`); transform-origin: 0 0;`),r},o=function(e){var t=Math.round(e.viewportWidth),n=Math.round(e.viewportHeight);return{x:-e.left,y:-e.top,width:t,height:n}},s=function(e){e.style=(e.style||``)+`float: left;`},c=function(e){e.externalResourcesRequired=!0},l=function(){return`<style scoped="">html::-webkit-scrollbar { display: none; }</style>`},u=function(e){var t=Object.keys(e);return t.length?` `+t.map(function(t){return t+`="`+e[t]+`"`}).join(` `):``},d=function(e,n,i){var d=r.serializeToString(e);t.validateXHTML(d);var f=o(n);return s(f),c(f),`<svg xmlns="http://www.w3.org/2000/svg"`+u(a(n,i))+`>`+l()+`<foreignObject`+u(f)+`>`+d+`</foreignObject></svg>`};return i.getSvgForDocument=function(e,t,r){return n.rewriteTagNameSelectorsToLowerCase(e),d(e,t,r)},i.drawDocumentAsSvg=function(e,r){return[`hover`,`active`,`focus`,`target`].forEach(function(t){r[t]&&n.fakeUserAction(e,r[t],t)}),t.calculateDocumentContentSize(e,r).then(function(t){return i.getSvgForDocument(e,t,r.zoom)})},i})(i,s,o,t),c,r))})}))(),1),Sy=e(gv(),1);function Cy(e,t){if(!e.includes(`@font-face`))return``;let n=new Set,r=new Set;t&&((t.match(/font-weight:\s*(\d+|bold|normal)/gi)||[]).forEach(e=>{let t=e.split(`:`)[1].trim();t===`bold`?n.add(`700`):t===`normal`?n.add(`400`):/^\d+$/.test(t)&&n.add(t)}),(t.match(/font-style:\s*(italic|normal)/gi)||[]).forEach(e=>{e.split(`:`)[1].trim().toLowerCase()===`italic`&&r.add(`italic`)}),/<(b|strong)\b/i.test(t)&&n.add(`700`),/<(i|em)\b/i.test(t)&&r.add(`italic`));let i=Qf(t);i&&i.trim()&&n.add(`400`),n.size===0&&n.add(`400`);let a=n,o=r.has(`italic`),s=Array.from(new Set(i)).map(e=>e.codePointAt(0)).filter(e=>e!==void 0),c=e.split(/}\s*/).map(e=>e&&e+`}`).filter(e=>/@font-face/.test(e)&&(e=>{let t=(e.match(/font-weight:\s*(\d+)/)||[])[1];if(t&&!a.has(t)||/font-style:\s*italic/.test(e)&&!o)return!1;let n=e.match(/unicode-range:\s*([^;]+);/);if(!n)return!0;let r=n[1].split(`,`).map(e=>{let[t,n=t]=e.replace(`U+`,``).split(`-`).map(e=>parseInt(e,16));return[t,n]});return s.some(e=>r.some(([t,n])=>e>=t&&e<=n))})(e)).join(`
98
+ `);return c?`<style>${c}</style>`:``}var wy=`
99
99
  p {
100
100
  margin: 0;
101
101
  padding: 0;
@@ -174,7 +174,7 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
174
174
  .ql-indent-3 {
175
175
  margin-inline-start: 1.5em;
176
176
  }
177
- `,Sy=`\n<style>\n html, body {\n padding: 0;\n margin: 0;\n }\n ${xy}\n</style>\n`,Cy,wy=()=>(Cy||(Cy=document.createElement(`div`),Cy.id=`polotno-hidden-do-not-touch`,Cy.style.overflow=`hidden`,Cy.style.position=`relative`,document.body.appendChild(Cy),Cy.innerHTML=`<style>#polotno-hidden-do-not-touch {
177
+ `,Ty=`\n<style>\n html, body {\n padding: 0;\n margin: 0;\n }\n ${wy}\n</style>\n`,Ey,Dy=()=>(Ey||(Ey=document.createElement(`div`),Ey.id=`polotno-hidden-do-not-touch`,Ey.style.overflow=`hidden`,Ey.style.position=`relative`,document.body.appendChild(Ey),Ey.innerHTML=`<style>#polotno-hidden-do-not-touch {
178
178
  p {
179
179
  margin: 0;
180
180
  padding: 0;
@@ -253,7 +253,7 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
253
253
  .ql-indent-3 {
254
254
  margin-inline-start: 1.5em;
255
255
  }
256
- }</style>`),Cy);navigator.userAgent.includes(`Firefox`);function Ty({html:e}){let t=document.createElement(`div`);t.innerHTML=e,t.style.display=`inline-block`,t.style.position=`fixed`,t.style.top=`0px`,t.style.left=`0px`,t.style.zIndex=`1000`,t.style.whiteSpace=`nowrap`,t.style.visibility=`hidden`;let n=wy();n.appendChild(t);let r=t.innerText,i=t.childNodes[0];i.style.whiteSpace=`nowrap`;let a=r?.split(/\s+/)||[],o=!1;for(let e=0;e<a.length;e++){let n=a[e];if(i&&(i.textContent=n,o=i.scrollWidth>t.clientWidth,o))break}return n.removeChild(t),o}function Ey(e){let t=document.createElement(`div`);t.innerHTML=e,t.style.display=`inline-block`,t.style.position=`fixed`,t.style.top=`0px`,t.style.left=`0px`,t.style.zIndex=`1000`;let n=wy();n.appendChild(t);let r=t.getBoundingClientRect();return n.removeChild(t),{width:r.width,height:r.height}}var Dy={},Oy={},ky=new Map;async function Ay({html:e,width:t,height:n,fontFamily:r,padding:i,font:a,pixelRatio:o}){let s=``;if(r!==`Arial`&&!a&&(s=await async function(e,t){let n=`${e}|${t}`;if(ky.has(n))return ky.get(n);let r=`https://fonts.googleapis.com/css?family=${e}:${t}&display=swap`,i=await(await fetch(r)).text();return ky.set(n,i),i}(r,pp())),a){let e=a.styles||(a.url?[{src:`url("${a.url}")`}]:(e=>{if(Oy[e])return Oy[e];let t=function(e){let t=[];for(let n=0;n<document.styleSheets.length;n++){let r=document.styleSheets[n];try{let n=r.cssRules;if(n)for(let r=0;r<n.length;r++){let i=n[r];i instanceof CSSFontFaceRule&&i.style.fontFamily.replace(/['"]/g,``)===e&&t.push(i)}}catch(e){console.warn(`Could not access stylesheet: ${r.href}`,e)}}return t}(e).filter(t=>t.style.fontFamily.replace(/['"]/g,``)===e).map(e=>({src:e.style.getPropertyValue(`src`),fontStyle:e.style.getPropertyValue(`font-style`)||`normal`,fontWeight:e.style.getPropertyValue(`font-weight`)||`normal`}));return Oy[e]=t,t})(r));s=``,e.forEach(e=>{s+=`\n @font-face {\n font-family: '${r}';\n src: ${e.src};\n font-style: ${e.fontStyle||`normal`};\n font-weight: ${e.fontWeight||`normal`};\n }\n `})}let c=``;s&&(c=by(s,e)),e+=c+Sy;let l=t+2*i,u=n+2*i,d=document.createElement(`canvas`),f=await vy.drawHTML(`<div style="padding: ${i}px;" dir="auto">${e}</div>`,d,{width:l,height:u,cacheBucket:Dy});return Y_(d,l*o,u*o),d.getContext(`2d`)?.drawImage(f.image,0,0,l,u,0,0,d.width,d.height),d}var jy={data:``},My=e=>typeof window==`object`?((e?e.querySelector(`#_goober`):window._goober)||Object.assign((e||document.head).appendChild(document.createElement(`style`)),{innerHTML:` `,id:`_goober`})).firstChild:e||jy,Ny=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,Py=/\/\*[^]*?\*\/|\s\s+|\n/g,Fy=(e,t)=>{let n=``,r=``,i=``;for(let a in e){let o=e[a];a[0]==`@`?a[1]==`i`?n=a+` `+o+`;`:r+=a[1]==`f`?Fy(o,a):a+`{`+Fy(o,a[1]==`k`?``:t)+`}`:typeof o==`object`?r+=Fy(o,t?t.replace(/([^,])+/g,e=>a.replace(/(^:.*)|([^,])+/g,t=>/&/.test(t)?t.replace(/&/g,e):e?e+` `+t:t)):a):o!=null&&(a=a.replace(/[A-Z]/g,`-$&`).toLowerCase(),i+=Fy.p?Fy.p(a,o):a+`:`+o+`;`)}return n+(t&&i?t+`{`+i+`}`:i)+r},Iy={},Ly=e=>{if(typeof e==`object`){let t=``;for(let n in e)t+=n+Ly(e[n]);return t}return e},Ry=(e,t,n,r,i)=>{let a=Ly(e),o=Iy[a]||(Iy[a]=(e=>{let t=0,n=11;for(;t<e.length;)n=101*n+e.charCodeAt(t++)>>>0;return`go`+n})(a));if(!Iy[o]){let t=a===e?(e=>{let t,n=[{}];for(;t=Ny.exec(e.replace(Py,``));)t[4]?n.shift():t[3]?n.unshift(n[0][t[3]]=n[0][t[3]]||{}):n[0][t[1]]=t[2];return n[0]})(e):e;Iy[o]=Fy(i?{[`@keyframes `+o]:t}:t,n?``:`.`+o)}return((e,t,n)=>{t.data.indexOf(e)==-1&&(t.data=n?e+t.data:t.data+e)})(Iy[o],t,r),o};function zy(e){let t=this||{},n=e.call?e(t.p):e;return Ry(n.unshift?n.raw?((e,t,n)=>e.reduce((e,r,i)=>{let a=t[i];if(a&&a.call){let e=a(n),t=e&&e.props&&e.props.className||/^go/.test(e)&&e;a=t?`.`+t:e&&typeof e==`object`?e.props?``:Fy(e,``):!1===e?``:e}return e+r+(a??``)},``))(n,[].slice.call(arguments,1),t.p):n.reduce((e,n)=>Object.assign(e,n&&n.call?n(t.p):n),{}):n,My(t.target),t.g,t.o,t.k)}var By,Vy,Hy;zy.bind({g:1}),zy.bind({k:1});function Uy(e,t,n,r){Fy.p=t,By=e,Vy=n,Hy=r}function Wy(e,t){let n=this||{};return function(){let r=arguments;function i(a,o){let s=Object.assign({},a),c=s.className||i.className;n.p=Object.assign({theme:Vy&&Vy()},s),n.o=/ *go\d+/.test(c),s.className=zy.apply(n,r)+(c?` `+c:``),t&&(s.ref=o);let l=e;return e[0]&&(l=s.as||e,delete s.as),Hy&&l[0]&&Hy(s),By(l,s)}return t?t(i):i}}Uy(d.createElement,void 0,void 0,void 0);var Gy=Wy;function Ky(e,t){if(t===1)return e;let n=Du.Util.colorToRGBA(e);return n?`rgba(${n.r}, ${n.g}, ${n.b}, ${n.a*t})`:e}function qy(e){let t=(e||``).trim();if(t===`<p><br></p>`||t===`<p></p>`)return``;if(t.startsWith(`<p>`)&&t.endsWith(`</p>`)){let e=t.slice(3,-4);if(!/(<\/?(p|div|h[1-6]|ul|ol|li|table|thead|tbody|tr|td|blockquote)\b)/i.test(e))return e}return e}var Jy=L({enabled:!1,currentFormat:{},editor:L.object({instance:null},{},{deep:!1})}),Yy=Gy(`div`,d.forwardRef)`
256
+ }</style>`),Ey);navigator.userAgent.includes(`Firefox`);function Oy({html:e}){let t=document.createElement(`div`);t.innerHTML=e,t.style.display=`inline-block`,t.style.position=`fixed`,t.style.top=`0px`,t.style.left=`0px`,t.style.zIndex=`1000`,t.style.whiteSpace=`nowrap`,t.style.visibility=`hidden`;let n=Dy();n.appendChild(t);let r=t.innerText,i=t.childNodes[0];i.style.whiteSpace=`nowrap`;let a=r?.split(/\s+/)||[],o=!1;for(let e=0;e<a.length;e++){let n=a[e];if(i&&(i.textContent=n,o=i.scrollWidth>t.clientWidth,o))break}return n.removeChild(t),o}function ky(e){let t=document.createElement(`div`);t.innerHTML=e,t.style.display=`inline-block`,t.style.position=`fixed`,t.style.top=`0px`,t.style.left=`0px`,t.style.zIndex=`1000`;let n=Dy();n.appendChild(t);let r=t.getBoundingClientRect();return n.removeChild(t),{width:r.width,height:r.height}}var Ay={},jy={},My=new Map;async function Ny({html:e,width:t,height:n,fontFamily:r,padding:i,font:a,pixelRatio:o}){let s=``;if(r!==`Arial`&&!a&&(s=await async function(e,t){let n=`${e}|${t}`;if(My.has(n))return My.get(n);let r=`https://fonts.googleapis.com/css?family=${e}:${t}&display=swap`,i=await(await fetch(r)).text();return My.set(n,i),i}(r,gp())),a){let e=a.styles||(a.url?[{src:`url("${a.url}")`}]:(e=>{if(jy[e])return jy[e];let t=function(e){let t=[];for(let n=0;n<document.styleSheets.length;n++){let r=document.styleSheets[n];try{let n=r.cssRules;if(n)for(let r=0;r<n.length;r++){let i=n[r];i instanceof CSSFontFaceRule&&i.style.fontFamily.replace(/['"]/g,``)===e&&t.push(i)}}catch(e){console.warn(`Could not access stylesheet: ${r.href}`,e)}}return t}(e).filter(t=>t.style.fontFamily.replace(/['"]/g,``)===e).map(e=>({src:e.style.getPropertyValue(`src`),fontStyle:e.style.getPropertyValue(`font-style`)||`normal`,fontWeight:e.style.getPropertyValue(`font-weight`)||`normal`}));return jy[e]=t,t})(r));s=``,e.forEach(e=>{s+=`\n @font-face {\n font-family: '${r}';\n src: ${e.src};\n font-style: ${e.fontStyle||`normal`};\n font-weight: ${e.fontWeight||`normal`};\n }\n `})}let c=``;s&&(c=Cy(s,e)),e+=c+Ty;let l=t+2*i,u=n+2*i,d=document.createElement(`canvas`),f=await xy.drawHTML(`<div style="padding: ${i}px;" dir="auto">${e}</div>`,d,{width:l,height:u,cacheBucket:Ay});return Q_(d,l*o,u*o),d.getContext(`2d`)?.drawImage(f.image,0,0,l,u,0,0,d.width,d.height),d}var Py={data:``},Fy=e=>typeof window==`object`?((e?e.querySelector(`#_goober`):window._goober)||Object.assign((e||document.head).appendChild(document.createElement(`style`)),{innerHTML:` `,id:`_goober`})).firstChild:e||Py,Iy=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,Ly=/\/\*[^]*?\*\/|\s\s+|\n/g,Ry=(e,t)=>{let n=``,r=``,i=``;for(let a in e){let o=e[a];a[0]==`@`?a[1]==`i`?n=a+` `+o+`;`:r+=a[1]==`f`?Ry(o,a):a+`{`+Ry(o,a[1]==`k`?``:t)+`}`:typeof o==`object`?r+=Ry(o,t?t.replace(/([^,])+/g,e=>a.replace(/(^:.*)|([^,])+/g,t=>/&/.test(t)?t.replace(/&/g,e):e?e+` `+t:t)):a):o!=null&&(a=a.replace(/[A-Z]/g,`-$&`).toLowerCase(),i+=Ry.p?Ry.p(a,o):a+`:`+o+`;`)}return n+(t&&i?t+`{`+i+`}`:i)+r},zy={},By=e=>{if(typeof e==`object`){let t=``;for(let n in e)t+=n+By(e[n]);return t}return e},Vy=(e,t,n,r,i)=>{let a=By(e),o=zy[a]||(zy[a]=(e=>{let t=0,n=11;for(;t<e.length;)n=101*n+e.charCodeAt(t++)>>>0;return`go`+n})(a));if(!zy[o]){let t=a===e?(e=>{let t,n=[{}];for(;t=Iy.exec(e.replace(Ly,``));)t[4]?n.shift():t[3]?n.unshift(n[0][t[3]]=n[0][t[3]]||{}):n[0][t[1]]=t[2];return n[0]})(e):e;zy[o]=Ry(i?{[`@keyframes `+o]:t}:t,n?``:`.`+o)}return((e,t,n)=>{t.data.indexOf(e)==-1&&(t.data=n?e+t.data:t.data+e)})(zy[o],t,r),o};function Hy(e){let t=this||{},n=e.call?e(t.p):e;return Vy(n.unshift?n.raw?((e,t,n)=>e.reduce((e,r,i)=>{let a=t[i];if(a&&a.call){let e=a(n),t=e&&e.props&&e.props.className||/^go/.test(e)&&e;a=t?`.`+t:e&&typeof e==`object`?e.props?``:Ry(e,``):!1===e?``:e}return e+r+(a??``)},``))(n,[].slice.call(arguments,1),t.p):n.reduce((e,n)=>Object.assign(e,n&&n.call?n(t.p):n),{}):n,Fy(t.target),t.g,t.o,t.k)}var Uy,Wy,Gy;Hy.bind({g:1}),Hy.bind({k:1});function Ky(e,t,n,r){Ry.p=t,Uy=e,Wy=n,Gy=r}function qy(e,t){let n=this||{};return function(){let r=arguments;function i(a,o){let s=Object.assign({},a),c=s.className||i.className;n.p=Object.assign({theme:Wy&&Wy()},s),n.o=/ *go\d+/.test(c),s.className=Hy.apply(n,r)+(c?` `+c:``),t&&(s.ref=o);let l=e;return e[0]&&(l=s.as||e,delete s.as),Gy&&l[0]&&Gy(s),Uy(l,s)}return t?t(i):i}}Ky(d.createElement,void 0,void 0,void 0);var Jy=qy;function Yy(e,t){if(t===1)return e;let n=Du.Util.colorToRGBA(e);return n?`rgba(${n.r}, ${n.g}, ${n.b}, ${n.a*t})`:e}function Xy(e){let t=(e||``).trim();if(t===`<p><br></p>`||t===`<p></p>`)return``;if(t.startsWith(`<p>`)&&t.endsWith(`</p>`)){let e=t.slice(3,-4);if(!/(<\/?(p|div|h[1-6]|ul|ol|li|table|thead|tbody|tr|td|blockquote)\b)/i.test(e))return e}return e}var Zy=L({enabled:!1,currentFormat:{},editor:L.object({instance:null},{},{deep:!1})}),Qy=Jy(`div`,d.forwardRef)`
257
257
  .ql-editor {
258
258
  outline: none;
259
259
  }
@@ -261,38 +261,38 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
261
261
  pointer-events: none;
262
262
  opacity: 0;
263
263
  }
264
- ${xy}
264
+ ${wy}
265
265
  strong {
266
266
  font-weight: 700;
267
267
  }
268
268
  .ql-direction-rtl {
269
269
  direction: rtl;
270
270
  }
271
- `,Xy=[`bold`,`color`,`font`,`italic`,`size`,`strike`,`underline`,`indent`,`list`,`direction`],Zy=(e,t)=>{var n=e.clipboard.convert(`<div class='ql-editor' style='outline: none;'>`+t+`<p><br></p></div>`);e.setContents(n),e.history.clear()},Qy=({html:e,onBlur:t,onChange:n,element:r,clickCoords:i})=>{let a=d.useRef(null);d.useEffect(()=>{if(!a.current)return;let r=(o=a.current,new yy.default(o,{toolbar:!1,keyboard:!1,clipboard:{matchVisual:!1},formats:Xy}));var o;Un(()=>{Jy.editor.instance=r}),window.__polotnoQuill=r,r.on(`text-change`,()=>{r.getSelection()&&Un(()=>{Jy.currentFormat=r.getFormat(r.getSelection())}),setTimeout(()=>{let e=a.current?.childNodes[0];if(!e)return;let t=e.innerHTML;n(qy(t))},10)}),Zy(r,e),i?nb(r,i):r.setSelection(0,0,`api`),r.on(`selection-change`,(e,t,n)=>{e&&Un(()=>{Jy.currentFormat=r.getFormat(r.getSelection())})}),a.current.childNodes[0].addEventListener(`blur`,e=>{let n=e.relatedTarget;n?.classList.contains(`ql-clipboard`)||(function(e){return!!e&&!!e.closest(`.sketch-picker`)})(n)||t()});let s=a.current.childNodes[0],c=e=>{var t,n;let i=r.getSelection();if(!i||i.length===0)return;let a=r.getText(i.index,i.length).replace(/\n$/,``),o=window.getSelection(),s=``;if(o&&o.rangeCount>0){let e=o.getRangeAt(0),t=document.createElement(`div`);t.appendChild(e.cloneContents()),s=t.innerHTML}if((t=e.clipboardData)==null||t.setData(`text/plain`,a),s){let t=`<!DOCTYPE html><html><head><meta charset="utf-8"></head><body><!--StartFragment--><div style="white-space: pre-wrap; word-wrap: break-word;">`+s+`</div><!--EndFragment--></body></html>`;(n=e.clipboardData)==null||n.setData(`text/html`,t)}e.preventDefault()},l=e=>{c(e);let t=r.getSelection();t&&t.length>0&&r.deleteText(t.index,t.length)};return s.addEventListener(`copy`,c),s.addEventListener(`cut`,l),()=>{s.removeEventListener(`copy`,c),s.removeEventListener(`cut`,l),Un(()=>{Jy.editor.instance=null,Jy.currentFormat={}}),delete window.__polotnoQuill}},[]),d.useEffect(()=>Jn(()=>r.text,()=>{let t=Jy.editor.instance;if(!t)return;let n=t.getSelection(),i=a.current?.childNodes?.[0];qy(i?.innerHTML||``)===r.text||(Zy(t,e),n&&(t.setSelection(n.index,n.length),Un(()=>{Jy.currentFormat=t.getFormat(t.getSelection())})))},{fireImmediately:!0}),[]),d.useEffect(()=>{window.addEventListener(`blur`,t);let e=e=>{var n;(n=a.current)!=null&&n.contains(e.target)||t()};return window.addEventListener(`touchstart`,e),()=>{window.removeEventListener(`blur`,t),window.removeEventListener(`touchstart`,e)}},[]);let o={color:r.fill};r.fill.indexOf(`gradient`)>=0&&(o.backgroundColor=r.fill,o.backgroundImage=r.fill,o.backgroundSize=`100% 100%`,o.backgroundRepeat=`repeat`,o.webkitBackgroundClip=`text`,o.MozBackgroundClip=`text`,o.WebkitTextFillColor=`transparent`,o.MozTextFillColor=`transparent`);let s=S_(r);return d.createElement(Yy,{ref:a,style:Object.assign(Object.assign({},o),{fontSize:r.fontSize,fontWeight:r.fontWeight,textTransform:r.textTransform,width:r.a.width,fontFamily:`"`+r.fontFamily+`"`,lineHeight:r.lineHeight,letterSpacing:r.letterSpacing*r.fontSize+`px`,textAlign:r.align,opacity:Math.max(r.a.opacity,.2),textShadow:r.shadowEnabled?`${r.shadowOffsetX}px ${r.shadowOffsetY}px ${r.shadowBlur}px ${Ky(r.shadowColor,r.shadowOpacity??1)}`:void 0,caretColor:s}),dir:Ap(Qf(r.text))})};function $y(e){return!function(e){let t=e.getContext(`2d`).getImageData(0,0,e.width,e.height).data;for(let e=0;e<t.length;e+=4)if(t[e+3]!==0)return!0;return!1}(e)}var eb=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),tb=sa(({element:e,store:t})=>{let n=d.useRef(null),[r,i]=d.useState(),[a,o]=d.useState(!1),[s,c]=d.useState(!1),l=d.useRef(e.height),u=t.selectedShapes.indexOf(e)>=0&&e.selectable,f=A_(u),p=e.fontSize/3,{textVerticalResizeEnabled:m}=yp,h=yp.autoDeleteEmptyText,g=A_(e.fontFamily),[_]=O_(t,e.fontFamily,e.fontStyle,e.fontWeight,e.text||e.placeholder),v=e._editModeEnabled;Rf(n);let y=_?e.fontFamily:g===e.fontFamily?`Arial`:g,b=Pf(e).fill,x=Ip(e,{fontFamily:y,color:b}),S=Ip(e,{fontFamily:y,color:b,forEditor:!0}),C=d.useRef([]),[,w]=d.useReducer(e=>e+1,0);d.useEffect(()=>{let e=C.current;e.length>0&&(C.current=[],e.forEach(e=>e()))});let{width:T,height:E}=function(e,t,n){return d.useMemo(()=>Ey(e),[e,t.width,n])}(x,e,_);d.useEffect(()=>{if(!_)return;let n=(n,r,i,a)=>{let o=Kf(`text ${e.id}`),s=()=>{t.history.ignore(n,r,i).then(()=>{C.current.push(o),w()})};a?queueMicrotask(s):s()};if(!e.height){n(()=>{e.height||e.set({height:E})},void 0,void 0,!0);return}let{textOverflow:r}=yp;if(r!==`change-font-size`||a)r===`resize`&&(m&&e.height<E&&!a&&n(()=>{e.set({height:E})},!1,!0),m||e.height===E||a||n(()=>{e.set({height:E})},!1,!0));else{let t=(e=>{let t=e.fontSize;for(let n=1;n<50;n++){let n=Ip(Object.assign(Object.assign({},e.toJSON()),{fontSize:t}),{fontFamily:e.fontFamily}),{height:r}=Ey(n);if(!(e.height&&r>e.height||!yp.textSplitAllowed&&!e.curveEnabled&&Ty({html:n})))break;t-=.5}return t})(e);t===e.fontSize?e.height!==E&&(m&&e.height<E?n(()=>{e.set({height:E})},!1,!0):m||n(()=>{e.set({height:E})},!1,!0)):n(()=>{e.set({fontSize:t})},!1,!0)}});let D=d.useMemo(()=>{let e={lastArgs:null,lastResult:null};return async function(t){return e.lastArgs&&e.lastResult&&(n=e.lastArgs,r=t,JSON.stringify(n)===JSON.stringify(r))||(e.lastResult=await Ay(t),e.lastArgs=Object.assign({},t)),e.lastResult;var n,r}},[]),O=d.useRef(0),k=d.useRef(null);d.useEffect(()=>{a||v||(async()=>{O.current++;let n=O.current,r=Kf(`text ${e.id} ${n}`);k.current&&k.current(),k.current=r,c(!0);let a=null,o=eb?5:1;for(let r=0;r<o;r++){let i=r>0?D:Ay;try{if(a=await i({skipCache:r>0,html:x,width:e.width||1,height:e.height||E||1,fontFamily:y,padding:p,pixelRatio:t._elementsPixelRatio,font:t.fonts.find(e=>e.fontFamily===y)||np.find(e=>e.fontFamily===y)}),n!==O.current)return;if(eb&&a&&$y(a)){await new Promise(e=>setTimeout(e,50*(r+1)));continue}break}catch(t){console.error(t),Zf(`Error rendering rich text with id ${e.id}`);break}}a?i(a):r?(r(),r=null):console.error(`Finish function is called twice!`),c(!1)})()},[x,a,E,v,y,e.height,t._elementsPixelRatio,_]);let[A,j]=Q_(s,300),[M]=Q_(a,300,!0),N=M||A;d.useEffect(()=>{var t;if(!N)return Gn(()=>{let t=n.current;zp(t,e)});(t=n.current)==null||t.clearCache()},[r,N,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]),d.useEffect(()=>{r&&!s&&k.current&&(k.current(),k.current=null)},[r,s]),d.useLayoutEffect(()=>{if(!_||!e.curveEnabled)return;let t=new Du.TextPath({data:jp(e.a.width,e.a.height,e.curvePower,e.a.fontSize),text:Qf(e.text),letterSpacing:e.letterSpacing*e.a.fontSize,fontSize:e.a.fontSize,fontFamily:e.fontFamily,fontWeight:e.fontWeight,fontStyle:e.fontStyle,align:`center`,textBaseline:`middle`,fill:e.fill}),n=t.getSelfRect().width;if(n){let t=n-e.a.width,r=e.a.rotation*Math.PI/180,i=-t/2*Math.cos(r),a=-t/2*Math.sin(r);queueMicrotask(()=>{e.set({width:n,x:e.a.x+i,y:e.a.y+a})})}t.destroy()},[_,e.curveEnabled,e.curvePower,e.text,e.fontSize,e.fontFamily,e.fontWeight,e.fontStyle,e.letterSpacing]),d.useEffect(()=>()=>{k.current&&k.current()},[]),d.useEffect(()=>{f&&!u&&h&&Qf(e.text)===``&&e.removable&&!e.placeholder&&t.deleteElements([e.id])},[h,e.placeholder,e.removable,e.text,u,f]);let P=0;e.verticalAlign===`middle`&&(P=(e.height-E)/2),e.verticalAlign===`bottom`&&(P=e.height-E);let F=k_({fontLoaded:_,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),ee=Bp(),te=jp(e.a.width,E,e.curvePower,e.fontSize),ne=d.useRef(null),re=d.useRef(null),ie=v&&e.strokeWidth>0&&!e.curveEnabled;return d.createElement(d.Fragment,null,d.createElement(Jd,{x:e.a.x,y:e.a.y,offsetX:e.backgroundPadding*(e.fontSize*F*.5),offsetY:e.backgroundPadding*(e.fontSize*F*.5),rotation:e.a.rotation,hideInExport:!e.showInExport,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity*e.a.opacity,fill:e.backgroundColor,width:e.a.width+e.backgroundPadding*(e.fontSize*F),height:e.a.height+e.backgroundPadding*(e.fontSize*F),cornerRadius:e.backgroundCornerRadius*(e.fontSize*F*.5)}),d.createElement($d,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,data:te,stroke:`red`,strokeWidth:1,visible:!1}),d.createElement(Jd,{ref:n,name:`element`,x:e.a.x,y:e.a.y,listening:e.selectable,rotation:e.a.rotation,width:e.a.width,height:e.a.height,visible:!N,draggable:ee?e.draggable&&u:e.draggable,preventDefault:!ee||u,opacity:v?0:e.a.opacity,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},id:e.id,onDblClick:t=>{e.contentEditable&&(re.current={x:t.evt.clientX,y:t.evt.clientY},e.toggleEditMode(!0))},onDblTap:t=>{if(e.contentEditable){let n=t.evt.changedTouches?.[0];re.current=n?{x:n.clientX,y:n.clientY}:null,e.toggleEditMode(!0)}},onTransformStart:t=>{o(!0),l.current=e.height},onTransform:t=>{let n=t.target,r=(n.getStage()?.findOne(`Transformer`)).getActiveAnchor(),i=r===`middle-left`||r===`middle-right`,a=r===`top-center`||r===`bottom-center`,o=n.scaleX();if(i){let t=n.scaleX(),r=n.width()*t,i=e.fontSize,a=r;r<i&&(a=i,ne.current&&n.position(ne.current)),n.width(a),n.scaleX(1),n.scaleY(1);let o=Ey(Ip(Object.assign(Object.assign({},e.toJSON()),{width:a}),{fontFamily:y,color:b})).height,s=yp.textVerticalResizeEnabled?Math.max(o,l.current):o;n.height(s),e.set({width:n.width(),height:s,x:n.x(),y:n.y()})}else if(a){let r=yp.textOverflow===`resize`,i=typeof e.lineHeight==`number`?e.lineHeight:1,a=r?E:i*e.fontSize,o=Math.max(a,t.target.height()*t.target.scaleY());n.scaleY(1),e.set({x:n.x(),y:n.y(),height:o,rotation:n.rotation()})}else n.scaleX(1),n.scaleY(1),e.set({fontSize:e.fontSize*o,letterSpacing:e.letterSpacing,width:n.width()*o,x:n.x(),y:n.y(),rotation:n.rotation(),height:n.height()*o});ne.current=t.target.position()},onTransformEnd:t=>{o(!1),c(!0);let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.fontSize*n,width:t.target.width()*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),shadowBlur:e.shadowBlur*n,shadowOffsetX:e.shadowOffsetX*n,shadowOffsetY:e.shadowOffsetY*n,strokeWidth:e.strokeWidth*n})}}),d.createElement(Xd,{ref:n,image:r,x:e.a.x,y:e.a.y,offsetX:p,offsetY:p-P,listening:!1,rotation:e.a.rotation,width:e.a.width+2*p,height:(e.a.width+2*p)*((r?.height??0)/(r?.width||1)||1),visible:!N&&!v,opacity:e.a.opacity,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,hideInExport:!e.showInExport,editModeEnabled:e._editModeEnabled||a||N}),(N||ie)&&d.createElement(`Group`,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,offsetY:-P},d.createElement(cf,{divProps:{style:{pointerEvents:`none`}}},d.createElement(Yy,{dangerouslySetInnerHTML:{__html:x},style:{pointerEvents:`none`,opacity:e.a.opacity,textShadow:e.shadowEnabled?`${e.shadowOffsetX}px ${e.shadowOffsetY}px ${e.shadowBlur}px ${Ky(e.shadowColor,e.shadowOpacity??1)}`:void 0}}))),v&&d.createElement(`Group`,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,offsetY:-P},d.createElement(cf,null,d.createElement(Qy,{html:S,element:e,onChange:t=>{let n=y_({oldText:Qf(e.text),newText:Qf(t),element:e});e.set({text:t,fontSize:n})},onBlur:t=>{e.toggleEditMode(!1),j(!0)},clickCoords:re.current}))))});function nb(e,t){if(!e||!t)return;let{x:n,y:r}=t;try{let t=null;if(document.caretRangeFromPoint)t=document.caretRangeFromPoint(n,r);else if(document.caretPositionFromPoint){let e=document.caretPositionFromPoint(n,r);e&&(t=document.createRange(),t.setStart(e.offsetNode,e.offset))}if(t){let n=yy.default.find(t.startContainer,!0);if(n){let r=n.offset(e.scroll)+t.startOffset;e.setSelection(r,0,`api`);return}}}catch{}e.setSelection(0,0,`api`)}function rb(e){return e/180*Math.PI}function ib(e,t,n,r,i){let a=Math.sqrt(n*n+r*r);return i+=Math.atan2(r,n),{x:e+a*Math.cos(i),y:t+a*Math.sin(i)}}function ab(e){let{x:t,y:n,width:r,height:i}=e,a=rb(e.rotation),o=ib(t,n,0,0,a),s=ib(t,n,r,0,a),c=ib(t,n,r,i,a),l=ib(t,n,0,i,a),u=Math.min(o.x,s.x,c.x,l.x),d=Math.min(o.y,s.y,c.y,l.y),f=Math.max(o.x,s.x,c.x,l.x),p=Math.max(o.y,s.y,c.y,l.y);return{x:u,y:d,width:f-u,height:p-d,minX:u,minY:d,maxX:f,maxY:p}}function ob(e){let t=e.map(e=>ab(e)),n=Math.min(...t.map(e=>e.minX)),r=Math.min(...t.map(e=>e.minY)),i=Math.max(...t.map(e=>e.maxX)),a=Math.max(...t.map(e=>e.maxY));return{x:n,y:r,width:i-n,height:a-r,minX:n,minY:r,maxX:i,maxY:a}}function sb(e){let t=rb(e.rotation||0);return{x:e.x+e.width/2*Math.cos(t)+e.height/2*Math.sin(-t),y:e.y+e.height/2*Math.cos(t)+e.width/2*Math.sin(t)}}function cb(e,t,n){let r=rb(t),i=n.x+(e.x-n.x)*Math.cos(r)-(e.y-n.y)*Math.sin(r),a=n.y+(e.x-n.x)*Math.sin(r)+(e.y-n.y)*Math.cos(r);return Object.assign(Object.assign({},e),{rotation:e.rotation+t,x:i,y:a})}function lb(e,t){return cb(e,t,sb(e))}var ub={stroke:`rgb(0, 161, 255)`,strokeWidth:1,dash:[4,6]},db=({stroke:e,strokeWidth:t,dash:n})=>{e!==void 0&&(ub.stroke=e),t!==void 0&&(ub.strokeWidth=t),n!==void 0&&(ub.dash=n)},fb=({targetKonvaNodes:e,guideKonvaNode:t,distance:n,snapDirection:r})=>n<5;function pb(e,t){var n=[],r=[];e.vertical.forEach(e=>{t.vertical.forEach(t=>{var r=Math.abs(e.offset-t.guide);fb({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:r,snapDirection:e.snap})&&n.push({lineGuide:e.offset,diff:r,snap:t.snap,offset:t.offset})})}),e.horizontal.forEach(e=>{t.horizontal.forEach(t=>{var n=Math.abs(e.offset-t.guide);fb({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:n,snapDirection:e.snap})&&r.push({lineGuide:e.offset,diff:n,snap:t.snap,offset:t.offset})})});var i=[];let a=n.sort((e,t)=>e.diff-t.diff),o=r.sort((e,t)=>e.diff-t.diff);var s=a[0],c=o[0];return s&&a.filter(e=>Math.abs(e.diff-s.diff)<.1).forEach(e=>{i.push(Object.assign({orientation:`V`},e))}),c&&o.filter(e=>Math.abs(e.diff-c.diff)<.1).forEach(e=>{i.push(Object.assign({orientation:`H`},e))}),i}var mb=()=>{if(Du.DD._dragElements.size===0)return;let e=[...Du.DD._dragElements.entries()],t=e.find(([e,t])=>t.node instanceof Du.Transformer);t&&(e.splice(e.indexOf(t),1),e.unshift(t),Du.DD._dragElements.clear(),e.forEach(([e,t])=>{Du.DD._dragElements.set(e,t)}))};function hb(e,t,n){let r=d.useRef(null);n&&db(n);let i=e=>e.hasName(`element`)||e.hasName(`page-background`)||!r.current&&e.hasName(`elements-area`);function a(t){let n=e.current?.getStage(),r=[],a=[];return n.find(i).forEach(e=>{if(!(t.indexOf(e)>=0)){var n=e.getClientRect({skipShadow:!0,skipStroke:!0});r.push({offset:n.x,node:e,snap:`start`},{offset:n.x+n.width,node:e,snap:`end`},{offset:n.x+n.width/2,node:e,snap:`center`}),a.push({offset:n.y,node:e,snap:`start`},{offset:n.y+n.height,node:e,snap:`end`},{offset:n.y+n.height/2,node:e,snap:`center`})}}),{vertical:r,horizontal:a}}function o(t){let n=e.current?.getLayer(),r=n?.children.find(e=>e.name()===`line-guides`);t.forEach(e=>{if(e.orientation===`H`){var t=new Du.Line({x:-n.getStage().x(),y:-n.getStage().y(),points:[-6e3,e.lineGuide,6e3,e.lineGuide],stroke:ub.stroke,strokeWidth:ub.strokeWidth,name:`guid-line`,dash:ub.dash});r?.add(t),n.batchDraw()}else e.orientation===`V`&&(t=new Du.Line({x:-n.getStage().x(),y:-n.getStage().y(),points:[e.lineGuide,-6e3,e.lineGuide,6e3],stroke:ub.stroke,strokeWidth:ub.strokeWidth,name:`guid-line`,dash:ub.dash}),r?.add(t))})}let s=e=>{e.target.getLayer().children.find(e=>e.name()===`line-guides`)?.destroyChildren();var t=pb(a(e.target.nodes()),function(e){let t=e.__getNodeRect(),n=ab(Object.assign(Object.assign({},t),{rotation:Du.Util.radToDeg(t.rotation)})),r=e.getAbsolutePosition();return{vertical:[{guide:n.x,offset:r.x-n.x,snap:`start`,nodes:e.nodes()},{guide:n.x+n.width/2,offset:r.x-n.x-n.width/2,snap:`center`,nodes:e.nodes()},{guide:n.x+n.width,offset:r.x-n.x-n.width,snap:`end`,nodes:e.nodes()}],horizontal:[{guide:n.y,offset:r.y-n.y,snap:`start`,nodes:e.nodes()},{guide:n.y+n.height/2,offset:r.y-n.y-n.height/2,snap:`center`,nodes:e.nodes()},{guide:n.y+n.height,offset:r.y-n.y-n.height,snap:`end`,nodes:e.nodes()}]}}(e.target));if(!t.length)return;o(t);let n=e.target.getAbsolutePosition(),r=(e.target.nodes().map(e=>e.getAbsolutePosition()),Object.assign({},n));t.forEach(e=>{switch(e.snap){case`start`:case`center`:case`end`:switch(e.orientation){case`V`:r.x=e.lineGuide+e.offset;break;case`H`:r.y=e.lineGuide+e.offset}}});let i=r.x-n.x,s=r.y-n.y;e.evt.ctrlKey||e.evt.metaKey||e.target.nodes().forEach(e=>{let t=e.getAbsolutePosition();e.setAbsolutePosition({x:t.x+i,y:t.y+s})})},c=(t,n,r)=>{let i=e.current;if(i.getLayer().children.find(e=>e.name()===`line-guides`)?.destroyChildren(),i.getActiveAnchor()===`rotater`)return n;let s=vb[i.getActiveAnchor()],c=i.findOne(`.${s}`)?.getAbsolutePosition();if(!c)return n;let l={x:t.x-c.x,y:t.y-c.y},u=function(e,t){let n=_b(e,t)/_b(t,t);return{x:n*t.x,y:n*t.y}}({x:n.x-t.x,y:n.y-t.y},l);if(Math.sqrt(u.x**2+u.y**2)>5)return n;let d={x:t.x+u.x,y:t.y+u.y};var f=pb(a(i.nodes()),{vertical:[{guide:d.x,offset:0,snap:`start`,nodes:i.nodes()}],horizontal:[{guide:d.y,offset:0,snap:`start`,nodes:i.nodes()}]});if(!f.length||(o(f),r.ctrlKey||r.metaKey))return n;let p=[];if(f.forEach(e=>{let t=function(e,t,n){if(n.orientation===`V`){let r=n.lineGuide;if(Math.abs(t.x-e.x)<1e-4)return null;let i=(t.y-e.y)/(t.x-e.x);return{x:r,y:i*r+(e.y-i*e.x)}}{let r=n.lineGuide;if(Math.abs(t.y-e.y)<1e-4)return null;let i=(t.y-e.y)/(t.x-e.x);return{x:(r-e.y)/i+e.x,y:r}}}(d,c,{orientation:e.orientation,lineGuide:e.lineGuide});t&&p.push(t)}),p.length>0){let e=p[0],t=Math.sqrt((d.x-e.x)**2+(d.y-e.y)**2);if(p.forEach(n=>{let r=Math.sqrt((d.x-n.x)**2+(d.y-n.y)**2);r<t&&(t=r,e=n)}),t<10)return e}return d},l=e=>{if(!e.target)return;let t=e.target.getLayer();t.children.find(e=>e.name()===`line-guides`)?.destroyChildren(),t.batchDraw()};d.useEffect(()=>{e.current&&(e.current.anchorDragBoundFunc(c),e.current.on(`dragstart`,e=>{setTimeout(()=>{mb()})}),e.current.on(`dragmove`,s),e.current.on(`dragend`,l),e.current.on(`transformend`,l),e.current.on(`transform`,t=>{var n,r;t.evt.ctrlKey||t.evt.metaKey?(n=e.current)==null||n.rotationSnapTolerance(0):(r=e.current)==null||r.rotationSnapTolerance(5)}))},[])}function gb(e,t,n){let r=e=>e.hasName(`element`)||e.hasName(`line-anchor`)||e.hasName(`page-background`)||e.hasName(`elements-area`),i=n=>{n.target.getLayer().children.find(e=>e.name()===`line-guides`)?.destroyChildren();var i,a=pb(function(t){let n=e.current?.getStage();var i=[],a=[];return n.find(r).forEach(e=>{if(!(t.indexOf(e)>=0)){var n=e.getClientRect({skipShadow:!0,skipStroke:!0});e.hasName(`line-anchor`)&&(n={x:e.absolutePosition().x,y:e.absolutePosition().y,width:0,height:0}),i.push({offset:n.x,node:e,snap:`start`},{offset:n.x+n.width,node:e,snap:`end`},{offset:n.x+n.width/2,node:e,snap:`center`}),a.push({offset:n.y,node:e,snap:`start`},{offset:n.y+n.height,node:e,snap:`end`},{offset:n.y+n.height/2,node:e,snap:`center`})}}),{vertical:i,horizontal:a}}([n.target,...t.map(e=>e.current)]),{vertical:[{guide:(i=n.target).absolutePosition().x,offset:0,snap:`center`,nodes:[i]}],horizontal:[{guide:i.absolutePosition().y,offset:0,snap:`center`,nodes:[i]}]});if(!a.length)return;(function(t){let n=e.current?.getLayer(),r=n?.children.find(e=>e.name()===`line-guides`);t.forEach(e=>{if(e.orientation===`H`){var t=new Du.Line({x:-n.getStage().x(),y:-n.getStage().y(),points:[-6e3,e.lineGuide,6e3,e.lineGuide],stroke:ub.stroke,strokeWidth:ub.strokeWidth,name:`guid-line`,dash:ub.dash});r?.add(t),n.batchDraw()}else e.orientation===`V`&&(t=new Du.Line({x:-n.getStage().x(),y:-n.getStage().y(),points:[e.lineGuide,-6e3,e.lineGuide,6e3],stroke:ub.stroke,strokeWidth:ub.strokeWidth,name:`guid-line`,dash:ub.dash}),r?.add(t))})})(a);let o=n.target.getAbsolutePosition(),s=Object.assign({},o);a.forEach(e=>{switch(e.snap){case`start`:case`center`:case`end`:switch(e.orientation){case`V`:s.x=e.lineGuide+e.offset;break;case`H`:s.y=e.lineGuide+e.offset}}});let c=s.x-o.x,l=s.y-o.y;if(!n.evt.ctrlKey&&!n.evt.metaKey){let e=n.target.getAbsolutePosition();n.target.absolutePosition({x:e.x+c,y:e.y+l})}},a=e=>{if(!e.target)return;let t=e.target.getLayer();t.children.find(e=>e.name()===`line-guides`)?.destroyChildren(),t.batchDraw()};d.useEffect(()=>{e.current&&(e.current.on(`dragmove`,i),e.current.on(`dragend`,a))},n)}function _b(e,t){return e.x*t.x+e.y*t.y}var vb={"top-left":`bottom-right`,"top-center":`bottom-center`,"top-right":`bottom-left`,"middle-right":`middle-left`,"bottom-right":`top-left`,"bottom-center":`top-center`,"bottom-left":`top-right`,"middle-left":`middle-right`};function yb(e){let{x:t,y:n,width:r,height:i,rotation:a}=e.a,o=a*Math.PI/180,s={x:t+i/2*Math.cos(o+Math.PI/2),y:n+i/2*Math.sin(o+Math.PI/2)};return{middleLeft:s,middleRight:{x:s.x+r*Math.cos(o),y:s.y+r*Math.sin(o)}}}function bb(e,t,n){let r=Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2),i=Math.atan2(t.y-e.y,t.x-e.x),a=180*i/Math.PI;return{x:e.x+Math.cos(i-Math.PI/2)*n/2,y:e.y+Math.sin(i-Math.PI/2)*n/2,width:r,height:n,rotation:a}}var xb=(e,t)=>{let n=cA.anchorSize||10;return{offsetX:n/2/e,offsetY:n/2/e,width:n/e,height:n/e,cornerRadius:(cA.anchorCornerRadius||0)/e,fill:cA.anchorFill||`white`,stroke:cA.anchorStroke||`rgb(0, 161, 255)`,strokeWidth:cA.anchorStrokeWidth||2,strokeScaleEnabled:!1,draggable:!0,dragDistance:0,onMouseEnter:e=>{e.target.getStage().container().style.cursor=`crosshair`},onMouseLeave:e=>{e.target.getStage().container().style.cursor=``},onDragStart:e=>{t.history.startTransaction()},onDragEnd:e=>{t.history.endTransaction()}}},Sb=sa(({element:e,type:t})=>{let n=Pf(e,e.a.color,`fill`),r=Pf(e,e.a.color,`stroke`),i=Object.assign(Object.assign(Object.assign({strokeWidth:e.height,lineCap:`round`,lineJoin:`round`},r),n),{opacity:e.a.opacity,hideInExport:!e.showInExport});return d.createElement(d.Fragment,null,t===`arrow`&&d.createElement(`Line`,Object.assign({points:[3*e.height,2*-e.height,0,0,3*e.height,2*e.height]},i)),t===`triangle`&&d.createElement(`Line`,Object.assign({points:[3*e.height,2*-e.height,0,0,3*e.height,2*e.height],closed:!0},i)),t===`bar`&&d.createElement(`Line`,Object.assign({points:[0,2*-e.height,0,2*e.height],closed:!0},i)),t===`square`&&d.createElement(`Line`,Object.assign({points:[0,2*-e.height,4*e.height,2*-e.height,4*e.height,2*e.height,0,2*e.height],closed:!0},i)),t===`circle`&&d.createElement(`Circle`,Object.assign({x:2*e.height,y:0,radius:2*e.height},i)))}),Cb=sa(({element:e,store:t})=>{let n=d.useRef(null),r=d.useRef(null),i=d.useRef(null),a=e.selectable||t.role===`admin`,o=Bp(),s=t.selectedElements.indexOf(e)>=0&&t.selectedElements.length===1,c=t.selectedShapes.indexOf(e)>=0&&e.selectable,{middleLeft:l,middleRight:u}=yb(e);gb(r,[n],[s]),gb(i,[n],[s]);let f=Pf(e,e.a.color,`stroke`);return d.createElement(d.Fragment,null,d.createElement(Yd,Object.assign({ref:n,name:`element`,id:e.id,x:e.a.x,y:e.a.y,points:[0,0,e.a.width,0],offsetY:-e.a.height/2,strokeWidth:e.a.height,hitStrokeWidth:Math.max(e.a.height,20),dash:e.dash.map(t=>t*e.a.height)},f,{rotation:e.a.rotation,opacity:e.animated(`opacity`),shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,listening:a,draggable:o?e.draggable&&c:e.draggable,preventDefault:!o||c,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onTransform:t=>{let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({height:e.height*n,width:e.width*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})}})),d.createElement(Kd,{x:l.x,y:l.y,rotation:e.rotation,hideInExport:!e.showInExport,onClick:e=>n.current?.fire(`click`,e),onTap:e=>n.current?.fire(`tap`,e)},d.createElement(Sb,{element:e,type:e.startHead})),d.createElement(Kd,{x:u.x,y:u.y,rotation:e.rotation+180,onClick:e=>n.current?.fire(`click`,e),onTap:e=>n.current?.fire(`tap`,e)},d.createElement(Sb,{element:e,type:e.endHead})),s&&e.resizable&&d.createElement(lf,{selector:`.page-abs-container`,enabled:!0},d.createElement(`Group`,{visible:s},d.createElement(`Rect`,Object.assign({x:l.x,y:l.y,ref:r,name:`line-anchor`},xb(t.scale,t),{onDragMove:t=>{let n=bb(t.target.position(),u,e.height);e.set({x:n.x,y:n.y,width:n.width,rotation:n.rotation})}})),d.createElement(`Rect`,Object.assign({x:u.x,y:u.y,ref:i,name:`line-anchor`},xb(t.scale,t),{onDragMove:t=>{let n=bb(l,t.target.position(),e.height);e.set({x:n.x,y:n.y,width:n.width,rotation:n.rotation})}})))))});function J(e){if(!e)throw Error(`Assertion failed.`)}var wb=e=>{let t=(e%360+360)%360;if(t===0||t===90||t===180||t===270)return t;throw Error(`Invalid rotation ${e}.`)},Tb=e=>e&&e[e.length-1],Eb=e=>e>=0&&e<2**32,Y=e=>{let t=0;for(;e.readBits(1)===0&&t<32;)t++;if(t>=32)throw Error(`Invalid exponential-Golomb code.`);return(1<<t)-1+e.readBits(t)},Db=e=>{let t=Y(e);return t&1?t+1>>1:-(t>>1)},Ob=e=>e.constructor===Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e),kb=e=>e.constructor===DataView?e:ArrayBuffer.isView(e)?new DataView(e.buffer,e.byteOffset,e.byteLength):new DataView(e),Ab=new TextDecoder,jb=new TextEncoder,Mb=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[t,e])),Nb={bt709:1,bt470bg:5,smpte170m:6,bt2020:9,smpte432:12},Pb=Mb(Nb),Fb={bt709:1,smpte170m:6,linear:8,"iec61966-2-1":13,pq:16,hlg:18},Ib=Mb(Fb),Lb={rgb:0,bt709:1,bt470bg:5,smpte170m:6,"bt2020-ncl":9},Rb=Mb(Lb),zb=e=>!!e&&!!e.primaries&&!!e.transfer&&!!e.matrix&&e.fullRange!==void 0,Bb=e=>e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer||ArrayBuffer.isView(e),Vb=class{constructor(){this.currentPromise=Promise.resolve(),this.pending=0}async acquire(){let e,t=new Promise(t=>{let n=!1;e=()=>{n||=(t(),this.pending--,!0)}}),n=this.currentPromise;return this.currentPromise=t,this.pending++,await n,e}},Hb=e=>[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``),Ub=e=>(e=e>>1&1431655765|(e&1431655765)<<1,e=e>>2&858993459|(e&858993459)<<2,e=e>>4&252645135|(e&252645135)<<4,e=e>>8&16711935|(e&16711935)<<8,e=e>>16&65535|(e&65535)<<16,e>>>0),Wb=(e,t,n)=>{let r=0,i=e.length-1,a=-1;for(;r<=i;){let o=r+i>>1,s=n(e[o]);s===t?(a=o,i=o-1):s<t?r=o+1:i=o-1}return a},Gb=(e,t,n)=>{let r=0,i=e.length-1,a=-1;for(;r<=i;){let o=r+(i-r+1)/2|0;n(e[o])<=t?(a=o,r=o+1):i=o-1}return a},Kb=(e,t,n)=>{let r=Gb(e,n(t),n);e.splice(r+1,0,t)},qb=()=>{let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}},Jb=(e,t)=>{for(let n=e.length-1;n>=0;n--)if(t(e[n]))return e[n]},Yb=(e,t)=>{for(let n=e.length-1;n>=0;n--)if(t(e[n]))return n;return-1},Xb=async function*(e){Symbol.iterator in e?yield*e[Symbol.iterator]():yield*e[Symbol.asyncIterator]()},Zb=e=>{if(!(Symbol.iterator in e)&&!(Symbol.asyncIterator in e))throw TypeError(`Argument must be an iterable or async iterable.`)},Qb=e=>{throw Error(`Unexpected value: ${e}`)},$b=(e,t,n)=>{let r=e.getUint8(t),i=e.getUint8(t+1),a=e.getUint8(t+2);return n?r|i<<8|a<<16:r<<16|i<<8|a},ex=(e,t,n)=>$b(e,t,n)<<8>>8,tx=(e,t,n,r)=>{n>>>=0,n&=16777215,r?(e.setUint8(t,n&255),e.setUint8(t+1,n>>>8&255),e.setUint8(t+2,n>>>16&255)):(e.setUint8(t,n>>>16&255),e.setUint8(t+1,n>>>8&255),e.setUint8(t+2,n&255))},nx=(e,t,n,r)=>{n=ix(n,-8388608,8388607),n<0&&(n=n+16777216&16777215),tx(e,t,n,r)},rx=(e,t)=>({async next(){let n=await e.next();return n.done?{value:void 0,done:!0}:{value:t(n.value),done:!1}},return(){return e.return()},throw(t){return e.throw(t)},[Symbol.asyncIterator](){return this}}),ix=(e,t,n)=>Math.max(t,Math.min(n,e)),ax=e=>{let t=Math.round(e);return Math.abs(e/t-1)<10*2**-52?t:e},ox=(e,t)=>Math.round(e/t)*t,sx=(e,t)=>Math.floor(e/t)*t,cx=e=>{let t=0;for(;e;)t++,e>>=1;return t},lx=/^[a-z]{3}$/,ux=e=>lx.test(e),dx=1e6*(1+2**-52),fx=(e,t)=>{let n={...e,...t};if(e.headers||t.headers){let r=e.headers?px(e.headers):{},i=t.headers?px(t.headers):{},a={...r};Object.entries(i).forEach(([e,t])=>{let n=Object.keys(a).find(t=>t.toLowerCase()===e.toLowerCase());n&&delete a[n],a[e]=t}),n.headers=a}return n},px=e=>{if(e instanceof Headers){let t={};return e.forEach((e,n)=>{t[n]=e}),t}if(Array.isArray(e)){let t={};return e.forEach(([e,n])=>{t[e]=n}),t}return e},mx=async(e,t,n,r,i)=>{let a=0;for(;;)try{return await e(t,n)}catch(e){if(i())throw e;a++;let n=r(a,e,t);if(n===null)throw e;if(console.error(`Retrying failed fetch. Error:`,e),!Number.isFinite(n)||n<0)throw TypeError(`Retry delay must be a non-negative finite number.`);if(n>0&&await new Promise(e=>setTimeout(e,1e3*n)),i())throw e}},hx=(e,t)=>{let n=e<0?-1:1;e=Math.abs(e);let r=0,i=1,a=1,o=0,s=e;for(;;){let e=Math.floor(s),c=e*a+r,l=e*o+i;if(l>t)return{numerator:n*a,denominator:o};if(r=a,i=o,a=c,o=l,s=1/(s-e),!isFinite(s))break}return{numerator:n*a,denominator:o}},gx=class{constructor(){this.currentPromise=Promise.resolve()}call(e){return this.currentPromise=this.currentPromise.then(e)}},_x=null,vx=()=>_x===null?_x=!!(typeof navigator<`u`&&(navigator.vendor?.match(/apple/i)||/AppleWebKit/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)||/\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent))):_x,yx=null,bx=()=>yx===null?yx=typeof navigator<`u`&&navigator.userAgent?.includes(`Firefox`):yx,xx=null,Sx=()=>xx===null?xx=!!(typeof navigator<`u`&&(navigator.vendor?.includes(`Google Inc`)||/Chrome/.test(navigator.userAgent))):xx,Cx=null,wx=()=>{if(Cx!==null)return Cx;if(typeof navigator>`u`)return null;let e=/\bChrome\/(\d+)/.exec(navigator.userAgent);return e?Cx=Number(e[1]):null},Tx=(e,t)=>e===-1?t:e,Ex=(e,t,n,r)=>e<=r&&n<=t,Dx=function*(e){for(let t in e){let n=e[t];n!==void 0&&(yield{key:t,value:n})}},Ox=e=>{let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},kx=()=>{Symbol.dispose??=Symbol(`Symbol.dispose`)},Ax=e=>typeof e==`number`&&!Number.isNaN(e),jx=e=>{J(e.den!==0);let t=Math.abs(e.num),n=Math.abs(e.den);for(;n!==0;){let e=t%n;t=n,n=e}let r=t||1;return{num:e.num/r,den:e.den/r}},Mx=(e,t)=>{if(typeof e!=`object`||!e)throw TypeError(`${t} must be an object.`);if(!Number.isInteger(e.left)||e.left<0)throw TypeError(`${t}.left must be a non-negative integer.`);if(!Number.isInteger(e.top)||e.top<0)throw TypeError(`${t}.top must be a non-negative integer.`);if(!Number.isInteger(e.width)||e.width<0)throw TypeError(`${t}.width must be a non-negative integer.`);if(!Number.isInteger(e.height)||e.height<0)throw TypeError(`${t}.height must be a non-negative integer.`)},Nx=class{constructor(e,t){if(this.data=e,this.mimeType=t,!(e instanceof Uint8Array))throw TypeError(`data must be a Uint8Array.`);if(typeof t!=`string`)throw TypeError(`mimeType must be a string.`)}},Px=class{constructor(e,t,n,r){if(this.data=e,this.mimeType=t,this.name=n,this.description=r,!(e instanceof Uint8Array))throw TypeError(`data must be a Uint8Array.`);if(t!==void 0&&typeof t!=`string`)throw TypeError(`mimeType, when provided, must be a string.`);if(n!==void 0&&typeof n!=`string`)throw TypeError(`name, when provided, must be a string.`);if(r!==void 0&&typeof r!=`string`)throw TypeError(`description, when provided, must be a string.`)}},Fx=e=>{if(!e||typeof e!=`object`)throw TypeError(`tags must be an object.`);if(e.title!==void 0&&typeof e.title!=`string`)throw TypeError(`tags.title, when provided, must be a string.`);if(e.description!==void 0&&typeof e.description!=`string`)throw TypeError(`tags.description, when provided, must be a string.`);if(e.artist!==void 0&&typeof e.artist!=`string`)throw TypeError(`tags.artist, when provided, must be a string.`);if(e.album!==void 0&&typeof e.album!=`string`)throw TypeError(`tags.album, when provided, must be a string.`);if(e.albumArtist!==void 0&&typeof e.albumArtist!=`string`)throw TypeError(`tags.albumArtist, when provided, must be a string.`);if(e.trackNumber!==void 0&&(!Number.isInteger(e.trackNumber)||e.trackNumber<=0))throw TypeError(`tags.trackNumber, when provided, must be a positive integer.`);if(e.tracksTotal!==void 0&&(!Number.isInteger(e.tracksTotal)||e.tracksTotal<=0))throw TypeError(`tags.tracksTotal, when provided, must be a positive integer.`);if(e.discNumber!==void 0&&(!Number.isInteger(e.discNumber)||e.discNumber<=0))throw TypeError(`tags.discNumber, when provided, must be a positive integer.`);if(e.discsTotal!==void 0&&(!Number.isInteger(e.discsTotal)||e.discsTotal<=0))throw TypeError(`tags.discsTotal, when provided, must be a positive integer.`);if(e.genre!==void 0&&typeof e.genre!=`string`)throw TypeError(`tags.genre, when provided, must be a string.`);if(e.date!==void 0&&(!(e.date instanceof Date)||Number.isNaN(e.date.getTime())))throw TypeError(`tags.date, when provided, must be a valid Date.`);if(e.lyrics!==void 0&&typeof e.lyrics!=`string`)throw TypeError(`tags.lyrics, when provided, must be a string.`);if(e.images!==void 0){if(!Array.isArray(e.images))throw TypeError(`tags.images, when provided, must be an array.`);for(let t of e.images){if(!t||typeof t!=`object`)throw TypeError(`Each image in tags.images must be an object.`);if(!(t.data instanceof Uint8Array))throw TypeError(`Each image.data must be a Uint8Array.`);if(typeof t.mimeType!=`string`)throw TypeError(`Each image.mimeType must be a string.`);if(![`coverFront`,`coverBack`,`unknown`].includes(t.kind))throw TypeError(`Each image.kind must be 'coverFront', 'coverBack', or 'unknown'.`)}}if(e.comment!==void 0&&typeof e.comment!=`string`)throw TypeError(`tags.comment, when provided, must be a string.`);if(e.raw!==void 0){if(!e.raw||typeof e.raw!=`object`)throw TypeError(`tags.raw, when provided, must be an object.`);for(let t of Object.values(e.raw))if(t!==null&&typeof t!=`string`&&!(t instanceof Uint8Array)&&!(t instanceof Nx)&&!(t instanceof Px))throw TypeError(`Each value in tags.raw must be a string, Uint8Array, RichImageData, AttachedFile, or null.`)}},Ix={default:!0,forced:!1,original:!1,commentary:!1,hearingImpaired:!1,visuallyImpaired:!1},Lx=e=>{if(!e||typeof e!=`object`)throw TypeError(`disposition must be an object.`);if(e.default!==void 0&&typeof e.default!=`boolean`)throw TypeError(`disposition.default must be a boolean.`);if(e.forced!==void 0&&typeof e.forced!=`boolean`)throw TypeError(`disposition.forced must be a boolean.`);if(e.original!==void 0&&typeof e.original!=`boolean`)throw TypeError(`disposition.original must be a boolean.`);if(e.commentary!==void 0&&typeof e.commentary!=`boolean`)throw TypeError(`disposition.commentary must be a boolean.`);if(e.hearingImpaired!==void 0&&typeof e.hearingImpaired!=`boolean`)throw TypeError(`disposition.hearingImpaired must be a boolean.`);if(e.visuallyImpaired!==void 0&&typeof e.visuallyImpaired!=`boolean`)throw TypeError(`disposition.visuallyImpaired must be a boolean.`)},Rx=class e{constructor(e){this.bytes=e,this.pos=0}seekToByte(e){this.pos=8*e}readBit(){let e=Math.floor(this.pos/8),t=this.bytes[e]??0,n=7-(this.pos&7),r=(t&1<<n)>>n;return this.pos++,r}readBits(e){if(e===1)return this.readBit();let t=0;for(let n=0;n<e;n++)t<<=1,t|=this.readBit();return t}writeBits(e,t){let n=this.pos+e;for(let e=this.pos;e<n;e++){let r=Math.floor(e/8),i=this.bytes[r],a=7-(e&7);i&=~(1<<a),i|=(t&1<<n-e-1)>>n-e-1<<a,this.bytes[r]=i}this.pos=n}readAlignedByte(){if(this.pos%8!=0)throw Error(`Bitstream is not byte-aligned.`);let e=this.pos/8,t=this.bytes[e]??0;return this.pos+=8,t}skipBits(e){this.pos+=e}getBitsLeft(){return this.bytes.length*8-this.pos}clone(){let t=new e(this.bytes);return t.pos=this.pos,t}},zx=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],Bx=[-1,1,2,3,4,5,6,8],Vx=e=>{if(!e||e.byteLength<2)throw TypeError(`AAC description must be at least 2 bytes long.`);let t=new Rx(e),n=t.readBits(5);n===31&&(n=32+t.readBits(6));let r=t.readBits(4),i=null;r===15?i=t.readBits(24):r<zx.length&&(i=zx[r]);let a=t.readBits(4),o=null;return a>=1&&a<=7&&(o=Bx[a]),{objectType:n,frequencyIndex:r,sampleRate:i,channelConfiguration:a,numberOfChannels:o}},Hx=e=>{let t=zx.indexOf(e.sampleRate),n=null;t===-1&&(t=15,n=e.sampleRate);let r=Bx.indexOf(e.numberOfChannels);if(r===-1)throw TypeError(`Unsupported number of channels: ${e.numberOfChannels}`);let i=13;e.objectType>=32&&(i+=6),t===15&&(i+=24);let a=Math.ceil(i/8),o=new Uint8Array(a),s=new Rx(o);return e.objectType<32?s.writeBits(5,e.objectType):(s.writeBits(5,31),s.writeBits(6,e.objectType-32)),s.writeBits(4,t),t===15&&s.writeBits(24,n),s.writeBits(4,r),o},Ux=[`avc`,`hevc`,`vp9`,`av1`,`vp8`],Wx=[`pcm-s16`,`pcm-s16be`,`pcm-s24`,`pcm-s24be`,`pcm-s32`,`pcm-s32be`,`pcm-f32`,`pcm-f32be`,`pcm-f64`,`pcm-f64be`,`pcm-u8`,`pcm-s8`,`ulaw`,`alaw`],Gx=[`aac`,`opus`,`mp3`,`vorbis`,`flac`,`ac3`,`eac3`],Kx=[...Gx,...Wx],qx=[`webvtt`],Jx=[{maxMacroblocks:99,maxBitrate:64e3,maxDpbMbs:396,level:10},{maxMacroblocks:396,maxBitrate:192e3,maxDpbMbs:900,level:11},{maxMacroblocks:396,maxBitrate:384e3,maxDpbMbs:2376,level:12},{maxMacroblocks:396,maxBitrate:768e3,maxDpbMbs:2376,level:13},{maxMacroblocks:396,maxBitrate:2e6,maxDpbMbs:2376,level:20},{maxMacroblocks:792,maxBitrate:4e6,maxDpbMbs:4752,level:21},{maxMacroblocks:1620,maxBitrate:4e6,maxDpbMbs:8100,level:22},{maxMacroblocks:1620,maxBitrate:1e7,maxDpbMbs:8100,level:30},{maxMacroblocks:3600,maxBitrate:14e6,maxDpbMbs:18e3,level:31},{maxMacroblocks:5120,maxBitrate:2e7,maxDpbMbs:20480,level:32},{maxMacroblocks:8192,maxBitrate:2e7,maxDpbMbs:32768,level:40},{maxMacroblocks:8192,maxBitrate:5e7,maxDpbMbs:32768,level:41},{maxMacroblocks:8704,maxBitrate:5e7,maxDpbMbs:34816,level:42},{maxMacroblocks:22080,maxBitrate:135e6,maxDpbMbs:110400,level:50},{maxMacroblocks:36864,maxBitrate:24e7,maxDpbMbs:184320,level:51},{maxMacroblocks:36864,maxBitrate:24e7,maxDpbMbs:184320,level:52},{maxMacroblocks:139264,maxBitrate:24e7,maxDpbMbs:696320,level:60},{maxMacroblocks:139264,maxBitrate:48e7,maxDpbMbs:696320,level:61},{maxMacroblocks:139264,maxBitrate:8e8,maxDpbMbs:696320,level:62}],Yx=[{maxPictureSize:36864,maxBitrate:128e3,tier:`L`,level:30},{maxPictureSize:122880,maxBitrate:15e5,tier:`L`,level:60},{maxPictureSize:245760,maxBitrate:3e6,tier:`L`,level:63},{maxPictureSize:552960,maxBitrate:6e6,tier:`L`,level:90},{maxPictureSize:983040,maxBitrate:1e7,tier:`L`,level:93},{maxPictureSize:2228224,maxBitrate:12e6,tier:`L`,level:120},{maxPictureSize:2228224,maxBitrate:3e7,tier:`H`,level:120},{maxPictureSize:2228224,maxBitrate:2e7,tier:`L`,level:123},{maxPictureSize:2228224,maxBitrate:5e7,tier:`H`,level:123},{maxPictureSize:8912896,maxBitrate:25e6,tier:`L`,level:150},{maxPictureSize:8912896,maxBitrate:1e8,tier:`H`,level:150},{maxPictureSize:8912896,maxBitrate:4e7,tier:`L`,level:153},{maxPictureSize:8912896,maxBitrate:16e7,tier:`H`,level:153},{maxPictureSize:8912896,maxBitrate:6e7,tier:`L`,level:156},{maxPictureSize:8912896,maxBitrate:24e7,tier:`H`,level:156},{maxPictureSize:35651584,maxBitrate:6e7,tier:`L`,level:180},{maxPictureSize:35651584,maxBitrate:24e7,tier:`H`,level:180},{maxPictureSize:35651584,maxBitrate:12e7,tier:`L`,level:183},{maxPictureSize:35651584,maxBitrate:48e7,tier:`H`,level:183},{maxPictureSize:35651584,maxBitrate:24e7,tier:`L`,level:186},{maxPictureSize:35651584,maxBitrate:8e8,tier:`H`,level:186}],Xx=[{maxPictureSize:36864,maxBitrate:2e5,level:10},{maxPictureSize:73728,maxBitrate:8e5,level:11},{maxPictureSize:122880,maxBitrate:18e5,level:20},{maxPictureSize:245760,maxBitrate:36e5,level:21},{maxPictureSize:552960,maxBitrate:72e5,level:30},{maxPictureSize:983040,maxBitrate:12e6,level:31},{maxPictureSize:2228224,maxBitrate:18e6,level:40},{maxPictureSize:2228224,maxBitrate:3e7,level:41},{maxPictureSize:8912896,maxBitrate:6e7,level:50},{maxPictureSize:8912896,maxBitrate:12e7,level:51},{maxPictureSize:8912896,maxBitrate:18e7,level:52},{maxPictureSize:35651584,maxBitrate:18e7,level:60},{maxPictureSize:35651584,maxBitrate:24e7,level:61},{maxPictureSize:35651584,maxBitrate:48e7,level:62}],Zx=[{maxPictureSize:147456,maxBitrate:15e5,tier:`M`,level:0},{maxPictureSize:278784,maxBitrate:3e6,tier:`M`,level:1},{maxPictureSize:665856,maxBitrate:6e6,tier:`M`,level:4},{maxPictureSize:1065024,maxBitrate:1e7,tier:`M`,level:5},{maxPictureSize:2359296,maxBitrate:12e6,tier:`M`,level:8},{maxPictureSize:2359296,maxBitrate:3e7,tier:`H`,level:8},{maxPictureSize:2359296,maxBitrate:2e7,tier:`M`,level:9},{maxPictureSize:2359296,maxBitrate:5e7,tier:`H`,level:9},{maxPictureSize:8912896,maxBitrate:3e7,tier:`M`,level:12},{maxPictureSize:8912896,maxBitrate:1e8,tier:`H`,level:12},{maxPictureSize:8912896,maxBitrate:4e7,tier:`M`,level:13},{maxPictureSize:8912896,maxBitrate:16e7,tier:`H`,level:13},{maxPictureSize:8912896,maxBitrate:6e7,tier:`M`,level:14},{maxPictureSize:8912896,maxBitrate:24e7,tier:`H`,level:14},{maxPictureSize:35651584,maxBitrate:6e7,tier:`M`,level:15},{maxPictureSize:35651584,maxBitrate:24e7,tier:`H`,level:15},{maxPictureSize:35651584,maxBitrate:6e7,tier:`M`,level:16},{maxPictureSize:35651584,maxBitrate:24e7,tier:`H`,level:16},{maxPictureSize:35651584,maxBitrate:1e8,tier:`M`,level:17},{maxPictureSize:35651584,maxBitrate:48e7,tier:`H`,level:17},{maxPictureSize:35651584,maxBitrate:16e7,tier:`M`,level:18},{maxPictureSize:35651584,maxBitrate:8e8,tier:`H`,level:18},{maxPictureSize:35651584,maxBitrate:16e7,tier:`M`,level:19},{maxPictureSize:35651584,maxBitrate:8e8,tier:`H`,level:19}],Qx=`.01.01.01.01.00`,$x=`.0.110.01.01.01.0`,eS=(e,t,n,r)=>{if(e===`avc`){let e=Math.ceil(t/16)*Math.ceil(n/16),i=Jx.find(t=>e<=t.maxMacroblocks&&r<=t.maxBitrate)??Tb(Jx),a=i?i.level:0;return`avc1.${`64`.padStart(2,`0`)}00${a.toString(16).padStart(2,`0`)}`}else if(e===`hevc`){let e=t*n,i=Yx.find(t=>e<=t.maxPictureSize&&r<=t.maxBitrate)??Tb(Yx);return`hev1.1.6.${i.tier}${i.level}.B0`}else if(e===`vp8`)return`vp8`;else if(e===`vp9`){let e=t*n;return`vp09.00.${(Xx.find(t=>e<=t.maxPictureSize&&r<=t.maxBitrate)??Tb(Xx)).level.toString().padStart(2,`0`)}.08`}else if(e===`av1`){let e=t*n,i=Zx.find(t=>e<=t.maxPictureSize&&r<=t.maxBitrate)??Tb(Zx);return`av01.0.${i.level.toString().padStart(2,`0`)}${i.tier}.08`}throw TypeError(`Unhandled codec '${e}'.`)},tS=e=>{let t=e.split(`.`),n=Number(t[1]),r=t[2],i=Number(r.slice(0,-1)),a=(n<<5)+i,o=r.slice(-1)===`H`?1:0,s=Number(t[3])===8?0:1,c=t[4]?Number(t[4]):0,l=t[5]?Number(t[5][0]):1,u=t[5]?Number(t[5][1]):1,d=t[5]?Number(t[5][2]):0;return[129,a,(o<<7)+(s<<6)+0+(c<<4)+(l<<3)+(u<<2)+d,0]},nS=e=>{let{codec:t,codecDescription:n,colorSpace:r,avcCodecInfo:i,hevcCodecInfo:a,vp9CodecInfo:o,av1CodecInfo:s}=e;if(t===`avc`){if(J(e.avcType!==null),i){let t=new Uint8Array([i.avcProfileIndication,i.profileCompatibility,i.avcLevelIndication]);return`avc${e.avcType}.${Hb(t)}`}if(!n||n.byteLength<4)throw TypeError(`AVC decoder description is not provided or is not at least 4 bytes long.`);return`avc${e.avcType}.${Hb(n.subarray(1,4))}`}else if(t===`hevc`){let e,t,r,i,o,s;if(a)e=a.generalProfileSpace,t=a.generalProfileIdc,r=Ub(a.generalProfileCompatibilityFlags),i=a.generalTierFlag,o=a.generalLevelIdc,s=[...a.generalConstraintIndicatorFlags];else{if(!n||n.byteLength<23)throw TypeError(`HEVC decoder description is not provided or is not at least 23 bytes long.`);let a=kb(n),c=a.getUint8(1);e=c>>6&3,t=c&31,r=Ub(a.getUint32(2)),i=c>>5&1,o=a.getUint8(12),s=[];for(let e=0;e<6;e++)s.push(a.getUint8(6+e))}let c=`hev1.`;for(c+=[``,`A`,`B`,`C`][e]+t,c+=`.`,c+=r.toString(16).toUpperCase(),c+=`.`,c+=i===0?`L`:`H`,c+=o;s.length>0&&s[s.length-1]===0;)s.pop();return s.length>0&&(c+=`.`,c+=s.map(e=>e.toString(16).toUpperCase()).join(`.`)),c}else if(t===`vp8`)return`vp8`;else if(t===`vp9`){if(!o){let t=e.width*e.height,n=Tb(Xx).level;for(let e of Xx)if(t<=e.maxPictureSize){n=e.level;break}return`vp09.00.${n.toString().padStart(2,`0`)}.08`}let t=o.profile.toString().padStart(2,`0`),n=o.level.toString().padStart(2,`0`),r=o.bitDepth.toString().padStart(2,`0`),i=o.chromaSubsampling.toString().padStart(2,`0`),a=o.colourPrimaries.toString().padStart(2,`0`),s=o.transferCharacteristics.toString().padStart(2,`0`),c=o.matrixCoefficients.toString().padStart(2,`0`),l=o.videoFullRangeFlag.toString().padStart(2,`0`),u=`vp09.${t}.${n}.${r}.${i}`;return u+=`.${a}.${s}.${c}.${l}`,u.endsWith(Qx)&&(u=u.slice(0,-15)),u}else if(t===`av1`){if(!s){let t=e.width*e.height,n=Tb(Xx).level;for(let e of Xx)if(t<=e.maxPictureSize){n=e.level;break}return`av01.0.${n.toString().padStart(2,`0`)}M.08`}let t=s.profile,n=s.level.toString().padStart(2,`0`),i=s.tier?`H`:`M`,a=s.bitDepth.toString().padStart(2,`0`),o=s.monochrome?`1`:`0`,c=100*s.chromaSubsamplingX+10*s.chromaSubsamplingY+1*(s.chromaSubsamplingX&&s.chromaSubsamplingY?s.chromaSamplePosition:0),l=r?.primaries?Nb[r.primaries]:1,u=r?.transfer?Fb[r.transfer]:1,d=r?.matrix?Lb[r.matrix]:1,f=r?.fullRange?1:0,p=`av01.${t}.${n}${i}.${a}`;return p+=`.${o}.${c.toString().padStart(3,`0`)}`,p+=`.${l.toString().padStart(2,`0`)}`,p+=`.${u.toString().padStart(2,`0`)}`,p+=`.${d.toString().padStart(2,`0`)}`,p+=`.${f}`,p.endsWith($x)&&(p=p.slice(0,-17)),p}throw TypeError(`Unhandled codec '${t}'.`)},rS=(e,t,n)=>{if(e===`aac`)return t>=2&&n<=24e3?`mp4a.40.29`:n<=24e3?`mp4a.40.5`:`mp4a.40.2`;if(e===`mp3`)return`mp3`;if(e===`opus`)return`opus`;if(e===`vorbis`)return`vorbis`;if(e===`flac`)return`flac`;if(e===`ac3`)return`ac-3`;if(e===`eac3`)return`ec-3`;if(Wx.includes(e))return e;throw TypeError(`Unhandled codec '${e}'.`)},iS=e=>{let{codec:t,codecDescription:n,aacCodecInfo:r}=e;if(t===`aac`){if(!r)throw TypeError(`AAC codec info must be provided.`);if(r.isMpeg2)return`mp4a.67`;{let e;return e=r.objectType===null?Vx(n).objectType:r.objectType,`mp4a.40.${e}`}}else if(t===`mp3`)return`mp3`;else if(t===`opus`)return`opus`;else if(t===`vorbis`)return`vorbis`;else if(t===`flac`)return`flac`;else if(t===`ac3`)return`ac-3`;else if(t===`eac3`)return`ec-3`;else if(t&&Wx.includes(t))return t;throw TypeError(`Unhandled codec '${t}'.`)},aS=48e3,oS=/^pcm-([usf])(\d+)+(be)?$/,sS=e=>{if(J(Wx.includes(e)),e===`ulaw`)return{dataType:`ulaw`,sampleSize:1,littleEndian:!0,silentValue:255};if(e===`alaw`)return{dataType:`alaw`,sampleSize:1,littleEndian:!0,silentValue:213};let t=oS.exec(e);J(t);let n;n=t[1]===`u`?`unsigned`:t[1]===`s`?`signed`:`float`;let r=Number(t[2])/8,i=t[3]!==`be`;return{dataType:n,sampleSize:r,littleEndian:i,silentValue:e===`pcm-u8`?2**7:0}},cS=e=>e.startsWith(`avc1`)||e.startsWith(`avc3`)?`avc`:e.startsWith(`hev1`)||e.startsWith(`hvc1`)?`hevc`:e===`vp8`?`vp8`:e.startsWith(`vp09`)?`vp9`:e.startsWith(`av01`)?`av1`:e.startsWith(`mp4a.40`)||e===`mp4a.67`?`aac`:e===`mp3`||e===`mp4a.69`||e===`mp4a.6B`||e===`mp4a.6b`?`mp3`:e===`opus`?`opus`:e===`vorbis`?`vorbis`:e===`flac`?`flac`:e===`ac-3`||e===`ac3`?`ac3`:e===`ec-3`||e===`eac3`?`eac3`:e===`ulaw`?`ulaw`:e===`alaw`?`alaw`:oS.test(e)?e:e===`webvtt`?`webvtt`:null,lS=e=>e===`avc`?{avc:{format:`avc`}}:e===`hevc`?{hevc:{format:`hevc`}}:{},uS=e=>e===`aac`?{aac:{format:`aac`}}:e===`opus`?{opus:{format:`opus`}}:{},dS=[`avc1`,`avc3`,`hev1`,`hvc1`,`vp8`,`vp09`,`av01`],fS=/^(avc1|avc3)\.[0-9a-fA-F]{6}$/,pS=/^(hev1|hvc1)\.(?:[ABC]?\d+)\.[0-9a-fA-F]{1,8}\.[LH]\d+(?:\.[0-9a-fA-F]{1,2}){0,6}$/,mS=/^vp09(?:\.\d{2}){3}(?:(?:\.\d{2}){5})?$/,hS=/^av01\.\d\.\d{2}[MH]\.\d{2}(?:\.\d\.\d{3}\.\d{2}\.\d{2}\.\d{2}\.\d)?$/,gS=e=>{if(!e)throw TypeError(`Video chunk metadata must be provided.`);if(typeof e!=`object`)throw TypeError(`Video chunk metadata must be an object.`);if(!e.decoderConfig)throw TypeError(`Video chunk metadata must include a decoder configuration.`);if(typeof e.decoderConfig!=`object`)throw TypeError(`Video chunk metadata decoder configuration must be an object.`);if(typeof e.decoderConfig.codec!=`string`)throw TypeError(`Video chunk metadata decoder configuration must specify a codec string.`);if(!dS.some(t=>e.decoderConfig.codec.startsWith(t)))throw TypeError(`Video chunk metadata decoder configuration codec string must be a valid video codec string as specified in the Mediabunny Codec Registry.`);if(!Number.isInteger(e.decoderConfig.codedWidth)||e.decoderConfig.codedWidth<=0)throw TypeError(`Video chunk metadata decoder configuration must specify a valid codedWidth (positive integer).`);if(!Number.isInteger(e.decoderConfig.codedHeight)||e.decoderConfig.codedHeight<=0)throw TypeError(`Video chunk metadata decoder configuration must specify a valid codedHeight (positive integer).`);if(e.decoderConfig.description!==void 0&&!Bb(e.decoderConfig.description))throw TypeError(`Video chunk metadata decoder configuration description, when defined, must be an ArrayBuffer or an ArrayBuffer view.`);if(e.decoderConfig.colorSpace!==void 0){let{colorSpace:t}=e.decoderConfig;if(typeof t!=`object`)throw TypeError(`Video chunk metadata decoder configuration colorSpace, when provided, must be an object.`);let n=Object.keys(Nb);if(t.primaries!=null&&!n.includes(t.primaries))throw TypeError(`Video chunk metadata decoder configuration colorSpace primaries, when defined, must be one of ${n.join(`, `)}.`);let r=Object.keys(Fb);if(t.transfer!=null&&!r.includes(t.transfer))throw TypeError(`Video chunk metadata decoder configuration colorSpace transfer, when defined, must be one of ${r.join(`, `)}.`);let i=Object.keys(Lb);if(t.matrix!=null&&!i.includes(t.matrix))throw TypeError(`Video chunk metadata decoder configuration colorSpace matrix, when defined, must be one of ${i.join(`, `)}.`);if(t.fullRange!=null&&typeof t.fullRange!=`boolean`)throw TypeError(`Video chunk metadata decoder configuration colorSpace fullRange, when defined, must be a boolean.`)}if(e.decoderConfig.codec.startsWith(`avc1`)||e.decoderConfig.codec.startsWith(`avc3`)){if(!fS.test(e.decoderConfig.codec))throw TypeError(`Video chunk metadata decoder configuration codec string for AVC must be a valid AVC codec string as specified in Section 3.4 of RFC 6381.`)}else if(e.decoderConfig.codec.startsWith(`hev1`)||e.decoderConfig.codec.startsWith(`hvc1`)){if(!pS.test(e.decoderConfig.codec))throw TypeError(`Video chunk metadata decoder configuration codec string for HEVC must be a valid HEVC codec string as specified in Section E.3 of ISO 14496-15.`)}else if(e.decoderConfig.codec.startsWith(`vp8`)){if(e.decoderConfig.codec!==`vp8`)throw TypeError(`Video chunk metadata decoder configuration codec string for VP8 must be "vp8".`)}else if(e.decoderConfig.codec.startsWith(`vp09`)){if(!mS.test(e.decoderConfig.codec))throw TypeError(`Video chunk metadata decoder configuration codec string for VP9 must be a valid VP9 codec string as specified in Section "Codecs Parameter String" of https://www.webmproject.org/vp9/mp4/.`)}else if(e.decoderConfig.codec.startsWith(`av01`)&&!hS.test(e.decoderConfig.codec))throw TypeError(`Video chunk metadata decoder configuration codec string for AV1 must be a valid AV1 codec string as specified in Section "Codecs Parameter String" of https://aomediacodec.github.io/av1-isobmff/.`)},_S=[`mp4a`,`mp3`,`opus`,`vorbis`,`flac`,`ulaw`,`alaw`,`pcm`,`ac-3`,`ec-3`],vS=e=>{if(!e)throw TypeError(`Audio chunk metadata must be provided.`);if(typeof e!=`object`)throw TypeError(`Audio chunk metadata must be an object.`);if(!e.decoderConfig)throw TypeError(`Audio chunk metadata must include a decoder configuration.`);if(typeof e.decoderConfig!=`object`)throw TypeError(`Audio chunk metadata decoder configuration must be an object.`);if(typeof e.decoderConfig.codec!=`string`)throw TypeError(`Audio chunk metadata decoder configuration must specify a codec string.`);if(!_S.some(t=>e.decoderConfig.codec.startsWith(t)))throw TypeError(`Audio chunk metadata decoder configuration codec string must be a valid audio codec string as specified in the Mediabunny Codec Registry.`);if(!Number.isInteger(e.decoderConfig.sampleRate)||e.decoderConfig.sampleRate<=0)throw TypeError(`Audio chunk metadata decoder configuration must specify a valid sampleRate (positive integer).`);if(!Number.isInteger(e.decoderConfig.numberOfChannels)||e.decoderConfig.numberOfChannels<=0)throw TypeError(`Audio chunk metadata decoder configuration must specify a valid numberOfChannels (positive integer).`);if(e.decoderConfig.description!==void 0&&!Bb(e.decoderConfig.description))throw TypeError(`Audio chunk metadata decoder configuration description, when defined, must be an ArrayBuffer or an ArrayBuffer view.`);if(e.decoderConfig.codec.startsWith(`mp4a`)&&e.decoderConfig.codec!==`mp4a.69`&&e.decoderConfig.codec!==`mp4a.6B`&&e.decoderConfig.codec!==`mp4a.6b`){if(![`mp4a.40.2`,`mp4a.40.02`,`mp4a.40.5`,`mp4a.40.05`,`mp4a.40.29`,`mp4a.67`].includes(e.decoderConfig.codec))throw TypeError(`Audio chunk metadata decoder configuration codec string for AAC must be a valid AAC codec string as specified in https://www.w3.org/TR/webcodecs-aac-codec-registration/.`)}else if(e.decoderConfig.codec.startsWith(`mp3`)||e.decoderConfig.codec.startsWith(`mp4a`)){if(e.decoderConfig.codec!==`mp3`&&e.decoderConfig.codec!==`mp4a.69`&&e.decoderConfig.codec!==`mp4a.6B`&&e.decoderConfig.codec!==`mp4a.6b`)throw TypeError(`Audio chunk metadata decoder configuration codec string for MP3 must be "mp3", "mp4a.69" or "mp4a.6B".`)}else if(e.decoderConfig.codec.startsWith(`opus`)){if(e.decoderConfig.codec!==`opus`)throw TypeError(`Audio chunk metadata decoder configuration codec string for Opus must be "opus".`);if(e.decoderConfig.description&&e.decoderConfig.description.byteLength<18)throw TypeError(`Audio chunk metadata decoder configuration description, when specified, is expected to be an Identification Header as specified in Section 5.1 of RFC 7845.`)}else if(e.decoderConfig.codec.startsWith(`vorbis`)){if(e.decoderConfig.codec!==`vorbis`)throw TypeError(`Audio chunk metadata decoder configuration codec string for Vorbis must be "vorbis".`);if(!e.decoderConfig.description)throw TypeError(`Audio chunk metadata decoder configuration for Vorbis must include a description, which is expected to adhere to the format described in https://www.w3.org/TR/webcodecs-vorbis-codec-registration/.`)}else if(e.decoderConfig.codec.startsWith(`flac`)){if(e.decoderConfig.codec!==`flac`)throw TypeError(`Audio chunk metadata decoder configuration codec string for FLAC must be "flac".`);if(!e.decoderConfig.description||e.decoderConfig.description.byteLength<42)throw TypeError(`Audio chunk metadata decoder configuration for FLAC must include a description, which is expected to adhere to the format described in https://www.w3.org/TR/webcodecs-flac-codec-registration/.`)}else if(e.decoderConfig.codec.startsWith(`ac-3`)||e.decoderConfig.codec.startsWith(`ac3`)){if(e.decoderConfig.codec!==`ac-3`)throw TypeError(`Audio chunk metadata decoder configuration codec string for AC-3 must be "ac-3".`)}else if(e.decoderConfig.codec.startsWith(`ec-3`)||e.decoderConfig.codec.startsWith(`eac3`)){if(e.decoderConfig.codec!==`ec-3`)throw TypeError(`Audio chunk metadata decoder configuration codec string for EC-3 must be "ec-3".`)}else if((e.decoderConfig.codec.startsWith(`pcm`)||e.decoderConfig.codec.startsWith(`ulaw`)||e.decoderConfig.codec.startsWith(`alaw`))&&!Wx.includes(e.decoderConfig.codec))throw TypeError(`Audio chunk metadata decoder configuration codec string for PCM must be one of the supported PCM codecs (${Wx.join(`, `)}).`)},yS=e=>{if(!e)throw TypeError(`Subtitle metadata must be provided.`);if(typeof e!=`object`)throw TypeError(`Subtitle metadata must be an object.`);if(!e.config)throw TypeError(`Subtitle metadata must include a config object.`);if(typeof e.config!=`object`)throw TypeError(`Subtitle metadata config must be an object.`);if(typeof e.config.description!=`string`)throw TypeError(`Subtitle metadata config description must be a string.`)},bS=[44100,48e3,32e3],xS=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,32,40,48,56,64,80,96,112,128,160,192,224,256,320,-1,-1,32,48,56,64,80,96,112,128,160,192,224,256,320,384,-1,-1,32,64,96,128,160,192,224,256,288,320,352,384,416,448,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,16,24,32,40,48,56,64,80,96,112,128,144,160,-1,-1,8,16,24,32,40,48,56,64,80,96,112,128,144,160,-1,-1,32,48,56,64,80,96,112,128,144,160,176,192,224,256,-1],SS=(e,t,n,r,i)=>t===0?0:t===1?Math.floor(144*n/(r<<e))+i:t===2?Math.floor(144*n/r)+i:(Math.floor(12*n/r)+i)*4,CS=(e,t)=>e===3?t===3?21:36:t===3?13:21,wS=(e,t)=>{let n=e>>>24,r=e>>>16&255,i=e>>>8&255,a=e&255;if(n!==255&&r!==255&&i!==255&&a!==255)return{header:null,bytesAdvanced:4};if(n!==255||(r&224)!=224)return{header:null,bytesAdvanced:1};let o=0,s=0;r&16?o=r&8?0:1:(o=1,s=1);let c=r>>3&3,l=r>>1&3,u=i>>4&15,d=(i>>2&3)%3,f=i>>1&1,p=a>>6&3,m=a>>4&3,h=a>>3&1,g=a>>2&1,_=a&3,v=xS[o*16*4+l*16+u];if(v===-1)return{header:null,bytesAdvanced:1};let y=v*1e3,b=bS[d]>>o+s,x=SS(o,l,y,b,f);if(t!==null&&t<x)return{header:null,bytesAdvanced:1};let S;return S=c===3?l===3?384:1152:l===3?384:l===2?1152:576,{header:{totalSize:x,mpegVersionId:c,layer:l,bitrate:y,frequencyIndex:d,sampleRate:b,channel:p,modeExtension:m,copyright:h,original:g,emphasis:_,audioSamplesInFrame:S},bytesAdvanced:1}},TS=e=>{let t=2130706432,n=0;for(;t!==0;)n>>=1,n|=e&t,t>>=8;return n},ES=[48e3,44100,32e3],DS=[24e3,22050,16e3],OS;(function(e){e[e.NON_IDR_SLICE=1]=`NON_IDR_SLICE`,e[e.SLICE_DPA=2]=`SLICE_DPA`,e[e.SLICE_DPB=3]=`SLICE_DPB`,e[e.SLICE_DPC=4]=`SLICE_DPC`,e[e.IDR=5]=`IDR`,e[e.SEI=6]=`SEI`,e[e.SPS=7]=`SPS`,e[e.PPS=8]=`PPS`,e[e.AUD=9]=`AUD`,e[e.SPS_EXT=13]=`SPS_EXT`})(OS||={});var kS;(function(e){e[e.RASL_N=8]=`RASL_N`,e[e.RASL_R=9]=`RASL_R`,e[e.BLA_W_LP=16]=`BLA_W_LP`,e[e.RSV_IRAP_VCL23=23]=`RSV_IRAP_VCL23`,e[e.VPS_NUT=32]=`VPS_NUT`,e[e.SPS_NUT=33]=`SPS_NUT`,e[e.PPS_NUT=34]=`PPS_NUT`,e[e.AUD_NUT=35]=`AUD_NUT`,e[e.PREFIX_SEI_NUT=39]=`PREFIX_SEI_NUT`,e[e.SUFFIX_SEI_NUT=40]=`SUFFIX_SEI_NUT`})(kS||={});var AS=function*(e){let t=0,n=-1;for(;t<e.length-2;){let r=e.indexOf(0,t);if(r===-1||r>=e.length-2)break;t=r;let i=0;if(t+3<e.length&&e[t+1]===0&&e[t+2]===0&&e[t+3]===1?i=4:e[t+1]===0&&e[t+2]===1&&(i=3),i===0){t++;continue}n!==-1&&t>n&&(yield{offset:n,length:t-n}),n=t+i,t=n}n!==-1&&n<e.length&&(yield{offset:n,length:e.length-n})},jS=function*(e,t){let n=0,r=new DataView(e.buffer,e.byteOffset,e.byteLength);for(;n+t<=e.length;){let e;t===1?e=r.getUint8(n):t===2?e=r.getUint16(n,!1):t===3?e=$b(r,n,!1):(J(t===4),e=r.getUint32(n,!1)),n+=t,yield{offset:n,length:e},n+=e}},MS=(e,t)=>t.description?jS(e,(Ob(t.description)[4]&3)+1):AS(e),NS=e=>e&31,PS=e=>{let t=[],n=e.length;for(let r=0;r<n;r++)r+2<n&&e[r]===0&&e[r+1]===0&&e[r+2]===3?(t.push(0,0),r+=2):t.push(e[r]);return new Uint8Array(t)},FS=new Uint8Array([0,0,0,1]),IS=e=>{let t=e.reduce((e,t)=>e+FS.byteLength+t.byteLength,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(FS,r),r+=FS.byteLength,n.set(t,r),r+=t.byteLength;return n},LS=(e,t)=>{let n=e.reduce((e,n)=>e+t+n.byteLength,0),r=new Uint8Array(n),i=0;for(let n of e){let e=new DataView(r.buffer,r.byteOffset,r.byteLength);switch(t){case 1:e.setUint8(i,n.byteLength);break;case 2:e.setUint16(i,n.byteLength,!1);break;case 3:tx(e,i,n.byteLength,!1);break;case 4:e.setUint32(i,n.byteLength,!1);break}i+=t,r.set(n,i),i+=n.byteLength}return r},RS=(e,t)=>t.description?LS(e,(Ob(t.description)[4]&3)+1):IS(e),zS=e=>{try{let t=[],n=[],r=[];for(let i of AS(e)){let a=e.subarray(i.offset,i.offset+i.length),o=NS(a[0]);o===OS.SPS?t.push(a):o===OS.PPS?n.push(a):o===OS.SPS_EXT&&r.push(a)}if(t.length===0||n.length===0)return null;let i=t[0],a=US(i);J(a!==null);let o=a.profileIdc===100||a.profileIdc===110||a.profileIdc===122||a.profileIdc===144;return{configurationVersion:1,avcProfileIndication:a.profileIdc,profileCompatibility:a.constraintFlags,avcLevelIndication:a.levelIdc,lengthSizeMinusOne:3,sequenceParameterSets:t,pictureParameterSets:n,chromaFormat:o?a.chromaFormatIdc:null,bitDepthLumaMinus8:o?a.bitDepthLumaMinus8:null,bitDepthChromaMinus8:o?a.bitDepthChromaMinus8:null,sequenceParameterSetExt:o?r:null}}catch(e){return console.error(`Error building AVC Decoder Configuration Record:`,e),null}},BS=e=>{let t=[];t.push(e.configurationVersion),t.push(e.avcProfileIndication),t.push(e.profileCompatibility),t.push(e.avcLevelIndication),t.push(252|e.lengthSizeMinusOne&3),t.push(224|e.sequenceParameterSets.length&31);for(let n of e.sequenceParameterSets){let e=n.byteLength;t.push(e>>8),t.push(e&255);for(let r=0;r<e;r++)t.push(n[r])}t.push(e.pictureParameterSets.length);for(let n of e.pictureParameterSets){let e=n.byteLength;t.push(e>>8),t.push(e&255);for(let r=0;r<e;r++)t.push(n[r])}if(e.avcProfileIndication===100||e.avcProfileIndication===110||e.avcProfileIndication===122||e.avcProfileIndication===144){J(e.chromaFormat!==null),J(e.bitDepthLumaMinus8!==null),J(e.bitDepthChromaMinus8!==null),J(e.sequenceParameterSetExt!==null),t.push(252|e.chromaFormat&3),t.push(248|e.bitDepthLumaMinus8&7),t.push(248|e.bitDepthChromaMinus8&7),t.push(e.sequenceParameterSetExt.length);for(let n of e.sequenceParameterSetExt){let e=n.byteLength;t.push(e>>8),t.push(e&255);for(let r=0;r<e;r++)t.push(n[r])}}return new Uint8Array(t)},VS=e=>{try{let t=kb(e),n=0,r=t.getUint8(n++),i=t.getUint8(n++),a=t.getUint8(n++),o=t.getUint8(n++),s=t.getUint8(n++)&3,c=t.getUint8(n++)&31,l=[];for(let r=0;r<c;r++){let r=t.getUint16(n,!1);n+=2,l.push(e.subarray(n,n+r)),n+=r}let u=t.getUint8(n++),d=[];for(let r=0;r<u;r++){let r=t.getUint16(n,!1);n+=2,d.push(e.subarray(n,n+r)),n+=r}let f={configurationVersion:r,avcProfileIndication:i,profileCompatibility:a,avcLevelIndication:o,lengthSizeMinusOne:s,sequenceParameterSets:l,pictureParameterSets:d,chromaFormat:null,bitDepthLumaMinus8:null,bitDepthChromaMinus8:null,sequenceParameterSetExt:null};if((i===100||i===110||i===122||i===144)&&n+4<=e.length){let r=t.getUint8(n++)&3,i=t.getUint8(n++)&7,a=t.getUint8(n++)&7,o=t.getUint8(n++);f.chromaFormat=r,f.bitDepthLumaMinus8=i,f.bitDepthChromaMinus8=a;let s=[];for(let r=0;r<o;r++){let r=t.getUint16(n,!1);n+=2,s.push(e.subarray(n,n+r)),n+=r}f.sequenceParameterSetExt=s}return f}catch(e){return console.error(`Error deserializing AVC Decoder Configuration Record:`,e),null}},HS={1:{num:1,den:1},2:{num:12,den:11},3:{num:10,den:11},4:{num:16,den:11},5:{num:40,den:33},6:{num:24,den:11},7:{num:20,den:11},8:{num:32,den:11},9:{num:80,den:33},10:{num:18,den:11},11:{num:15,den:11},12:{num:64,den:33},13:{num:160,den:99},14:{num:4,den:3},15:{num:3,den:2},16:{num:2,den:1}},US=e=>{try{let t=new Rx(PS(e));if(t.skipBits(1),t.skipBits(2),t.readBits(5)!==7)return null;let n=t.readAlignedByte(),r=t.readAlignedByte(),i=t.readAlignedByte();Y(t);let a=1,o=0,s=0,c=0;if((n===100||n===110||n===122||n===244||n===44||n===83||n===86||n===118||n===128)&&(a=Y(t),a===3&&(c=t.readBits(1)),o=Y(t),s=Y(t),t.skipBits(1),t.readBits(1))){for(let e=0;e<(a===3?12:8);e++)if(t.readBits(1)){let n=e<6?16:64,r=8,i=8;for(let e=0;e<n;e++){if(i!==0){let e=Db(t);i=(r+e+256)%256}r=i===0?r:i}}}Y(t);let l=Y(t);if(l===0)Y(t);else if(l===1){t.skipBits(1),Db(t),Db(t);let e=Y(t);for(let n=0;n<e;n++)Db(t)}Y(t),t.skipBits(1);let u=Y(t),d=Y(t),f=16*(u+1),p=16*(d+1),m=f,h=p,g=t.readBits(1);if(g||t.skipBits(1),t.skipBits(1),t.readBits(1)){let e=Y(t),n=Y(t),r=Y(t),i=Y(t),o,s;if((c===0?a:0)===0)o=1,s=2-g;else{let e=a===3?1:2,t=a===1?2:1;o=e,s=t*(2-g)}m-=o*(e+n),h-=s*(r+i)}let _=2,v=2,y=2,b=0,x={num:1,den:1},S=null,C=null;if(t.readBits(1)){if(t.readBits(1)){let e=t.readBits(8);if(e===255)x={num:t.readBits(16),den:t.readBits(16)};else{let t=HS[e];t&&(x=t)}}t.readBits(1)&&t.skipBits(1),t.readBits(1)&&(t.skipBits(3),b=t.readBits(1),t.readBits(1)&&(_=t.readBits(8),v=t.readBits(8),y=t.readBits(8))),t.readBits(1)&&(Y(t),Y(t)),t.readBits(1)&&(t.skipBits(32),t.skipBits(32),t.skipBits(1));let e=t.readBits(1);e&&WS(t);let n=t.readBits(1);n&&WS(t),(e||n)&&t.skipBits(1),t.skipBits(1),t.readBits(1)&&(t.skipBits(1),Y(t),Y(t),Y(t),Y(t),S=Y(t),C=Y(t))}if(S===null){J(C===null);let e=r&16;if((n===44||n===86||n===100||n===110||n===122||n===244)&&e)S=0,C=0;else{let e=u+1,t=d+1,n=(2-g)*t,r=Jx.find(e=>e.level>=i)??Tb(Jx),a=Math.min(Math.floor(r.maxDpbMbs/(e*n)),16);S=a,C=a}}return J(C!==null),{profileIdc:n,constraintFlags:r,levelIdc:i,frameMbsOnlyFlag:g,chromaFormatIdc:a,bitDepthLumaMinus8:o,bitDepthChromaMinus8:s,codedWidth:f,codedHeight:p,displayWidth:m,displayHeight:h,pixelAspectRatio:x,colourPrimaries:_,matrixCoefficients:y,transferCharacteristics:v,fullRangeFlag:b,numReorderFrames:S,maxDecFrameBuffering:C}}catch(e){return console.error(`Error parsing AVC SPS:`,e),null}},WS=e=>{let t=Y(e);e.skipBits(4),e.skipBits(4);for(let n=0;n<=t;n++)Y(e),Y(e),e.skipBits(1);e.skipBits(5),e.skipBits(5),e.skipBits(5),e.skipBits(5)},GS=(e,t)=>t.description?jS(e,(Ob(t.description)[21]&3)+1):AS(e),KS=e=>e>>1&63,qS=e=>{try{let t=new Rx(PS(e));t.skipBits(16),t.readBits(4);let n=t.readBits(3),r=t.readBits(1),{general_profile_space:i,general_tier_flag:a,general_profile_idc:o,general_profile_compatibility_flags:s,general_constraint_indicator_flags:c,general_level_idc:l}=YS(t,n);Y(t);let u=Y(t),d=0;u===3&&(d=t.readBits(1));let f=Y(t),p=Y(t),m=f,h=p;if(t.readBits(1)){let e=Y(t),n=Y(t),r=Y(t),i=Y(t),a=1,o=1,s=d===0?u:0;s===1?(a=2,o=2):s===2&&(a=2,o=1),m-=(e+n)*a,h-=(r+i)*o}let g=Y(t),_=Y(t);Y(t);let v=t.readBits(1)?0:n,y=0;for(let e=v;e<=n;e++)Y(t),y=Y(t),Y(t);if(Y(t),Y(t),Y(t),Y(t),Y(t),Y(t),t.readBits(1)&&t.readBits(1)&&XS(t),t.skipBits(1),t.skipBits(1),t.readBits(1)&&(t.skipBits(4),t.skipBits(4),Y(t),Y(t),t.skipBits(1)),ZS(t,Y(t)),t.readBits(1)){let e=Y(t);for(let n=0;n<e;n++)Y(t),t.skipBits(1)}t.skipBits(1),t.skipBits(1);let b=2,x=2,S=2,C=0,w=0,T={num:1,den:1};if(t.readBits(1)){let e=$S(t,n);T=e.pixelAspectRatio,b=e.colourPrimaries,x=e.transferCharacteristics,S=e.matrixCoefficients,C=e.fullRangeFlag,w=e.minSpatialSegmentationIdc}return{displayWidth:m,displayHeight:h,pixelAspectRatio:T,colourPrimaries:b,transferCharacteristics:x,matrixCoefficients:S,fullRangeFlag:C,maxDecFrameBuffering:y+1,spsMaxSubLayersMinus1:n,spsTemporalIdNestingFlag:r,generalProfileSpace:i,generalTierFlag:a,generalProfileIdc:o,generalProfileCompatibilityFlags:s,generalConstraintIndicatorFlags:c,generalLevelIdc:l,chromaFormatIdc:u,bitDepthLumaMinus8:g,bitDepthChromaMinus8:_,minSpatialSegmentationIdc:w}}catch(e){return console.error(`Error parsing HEVC SPS:`,e),null}},JS=e=>{try{let t=[],n=[],r=[],i=[];for(let a of AS(e)){let o=e.subarray(a.offset,a.offset+a.length),s=KS(o[0]);s===kS.VPS_NUT?t.push(o):s===kS.SPS_NUT?n.push(o):s===kS.PPS_NUT?r.push(o):(s===kS.PREFIX_SEI_NUT||s===kS.SUFFIX_SEI_NUT)&&i.push(o)}if(n.length===0||r.length===0)return null;let a=qS(n[0]);if(!a)return null;let o=0;if(r.length>0){let e=r[0],t=new Rx(PS(e));t.skipBits(16),Y(t),Y(t),t.skipBits(1),t.skipBits(1),t.skipBits(3),t.skipBits(1),t.skipBits(1),Y(t),Y(t),Db(t),t.skipBits(1),t.skipBits(1),t.readBits(1)&&Y(t),Db(t),Db(t),t.skipBits(1),t.skipBits(1),t.skipBits(1),t.skipBits(1);let n=t.readBits(1),i=t.readBits(1);o=!n&&!i?0:n&&!i?2:!n&&i?3:0}let s=[...t.length?[{arrayCompleteness:1,nalUnitType:kS.VPS_NUT,nalUnits:t}]:[],...n.length?[{arrayCompleteness:1,nalUnitType:kS.SPS_NUT,nalUnits:n}]:[],...r.length?[{arrayCompleteness:1,nalUnitType:kS.PPS_NUT,nalUnits:r}]:[],...i.length?[{arrayCompleteness:1,nalUnitType:KS(i[0][0]),nalUnits:i}]:[]];return{configurationVersion:1,generalProfileSpace:a.generalProfileSpace,generalTierFlag:a.generalTierFlag,generalProfileIdc:a.generalProfileIdc,generalProfileCompatibilityFlags:a.generalProfileCompatibilityFlags,generalConstraintIndicatorFlags:a.generalConstraintIndicatorFlags,generalLevelIdc:a.generalLevelIdc,minSpatialSegmentationIdc:a.minSpatialSegmentationIdc,parallelismType:o,chromaFormatIdc:a.chromaFormatIdc,bitDepthLumaMinus8:a.bitDepthLumaMinus8,bitDepthChromaMinus8:a.bitDepthChromaMinus8,avgFrameRate:0,constantFrameRate:0,numTemporalLayers:a.spsMaxSubLayersMinus1+1,temporalIdNested:a.spsTemporalIdNestingFlag,lengthSizeMinusOne:3,arrays:s}}catch(e){return console.error(`Error building HEVC Decoder Configuration Record:`,e),null}},YS=(e,t)=>{let n=e.readBits(2),r=e.readBits(1),i=e.readBits(5),a=0;for(let t=0;t<32;t++)a=a<<1|e.readBits(1);let o=new Uint8Array(6);for(let t=0;t<6;t++)o[t]=e.readBits(8);let s=e.readBits(8),c=[],l=[];for(let n=0;n<t;n++)c.push(e.readBits(1)),l.push(e.readBits(1));if(t>0)for(let n=t;n<8;n++)e.skipBits(2);for(let n=0;n<t;n++)c[n]&&e.skipBits(88),l[n]&&e.skipBits(8);return{general_profile_space:n,general_tier_flag:r,general_profile_idc:i,general_profile_compatibility_flags:a,general_constraint_indicator_flags:o,general_level_idc:s}},XS=e=>{for(let t=0;t<4;t++)for(let n=0;n<(t===3?2:6);n++)if(!e.readBits(1))Y(e);else{let n=Math.min(64,1<<4+(t<<1));t>1&&Db(e);for(let t=0;t<n;t++)Db(e)}},ZS=(e,t)=>{let n=[];for(let r=0;r<t;r++)n[r]=QS(e,r,t,n)},QS=(e,t,n,r)=>{let i=0,a=0,o=0;if(t!==0&&(a=e.readBits(1)),a){o=t===n?t-(Y(e)+1):t-1,e.readBits(1),Y(e);let a=r[o]??0;for(let t=0;t<=a;t++)e.readBits(1)||e.readBits(1);i=r[o]}else{let t=Y(e),n=Y(e);for(let n=0;n<t;n++)Y(e),e.readBits(1);for(let t=0;t<n;t++)Y(e),e.readBits(1);i=t+n}return i},$S=(e,t)=>{let n=2,r=2,i=2,a=0,o=0,s={num:1,den:1};if(e.readBits(1)){let t=e.readBits(8);if(t===255)s={num:e.readBits(16),den:e.readBits(16)};else{let e=HS[t];e&&(s=e)}}return e.readBits(1)&&e.readBits(1),e.readBits(1)&&(e.readBits(3),a=e.readBits(1),e.readBits(1)&&(n=e.readBits(8),r=e.readBits(8),i=e.readBits(8))),e.readBits(1)&&(Y(e),Y(e)),e.readBits(1),e.readBits(1),e.readBits(1),e.readBits(1)&&(Y(e),Y(e),Y(e),Y(e)),e.readBits(1)&&(e.readBits(32),e.readBits(32),e.readBits(1)&&Y(e),e.readBits(1)&&eC(e,!0,t)),e.readBits(1)&&(e.readBits(1),e.readBits(1),e.readBits(1),o=Y(e),Y(e),Y(e),Y(e),Y(e)),{pixelAspectRatio:s,colourPrimaries:n,transferCharacteristics:r,matrixCoefficients:i,fullRangeFlag:a,minSpatialSegmentationIdc:o}},eC=(e,t,n)=>{let r=!1,i=!1,a=!1;t&&(r=e.readBits(1)===1,i=e.readBits(1)===1,(r||i)&&(a=e.readBits(1)===1,a&&(e.readBits(8),e.readBits(5),e.readBits(1),e.readBits(5)),e.readBits(4),e.readBits(4),a&&e.readBits(4),e.readBits(5),e.readBits(5),e.readBits(5)));for(let t=0;t<=n;t++){let t=e.readBits(1)===1,n=!0;t||(n=e.readBits(1)===1);let o=!1;n?Y(e):o=e.readBits(1)===1;let s=1;o||(s=Y(e)+1),r&&tC(e,s,a),i&&tC(e,s,a)}},tC=(e,t,n)=>{for(let r=0;r<t;r++)Y(e),Y(e),n&&(Y(e),Y(e)),e.readBits(1)},nC=e=>{let t=[];t.push(e.configurationVersion),t.push((e.generalProfileSpace&3)<<6|(e.generalTierFlag&1)<<5|e.generalProfileIdc&31),t.push(e.generalProfileCompatibilityFlags>>>24&255),t.push(e.generalProfileCompatibilityFlags>>>16&255),t.push(e.generalProfileCompatibilityFlags>>>8&255),t.push(e.generalProfileCompatibilityFlags&255),t.push(...e.generalConstraintIndicatorFlags),t.push(e.generalLevelIdc&255),t.push(240|e.minSpatialSegmentationIdc>>8&15),t.push(e.minSpatialSegmentationIdc&255),t.push(252|e.parallelismType&3),t.push(252|e.chromaFormatIdc&3),t.push(248|e.bitDepthLumaMinus8&7),t.push(248|e.bitDepthChromaMinus8&7),t.push(e.avgFrameRate>>8&255),t.push(e.avgFrameRate&255),t.push((e.constantFrameRate&3)<<6|(e.numTemporalLayers&7)<<3|(e.temporalIdNested&1)<<2|e.lengthSizeMinusOne&3),t.push(e.arrays.length&255);for(let n of e.arrays){t.push((n.arrayCompleteness&1)<<7|0|n.nalUnitType&63),t.push(n.nalUnits.length>>8&255),t.push(n.nalUnits.length&255);for(let e of n.nalUnits){t.push(e.length>>8&255),t.push(e.length&255);for(let n=0;n<e.length;n++)t.push(e[n])}}return new Uint8Array(t)},rC=e=>{let t=new Rx(e);if(t.readBits(2)!==2)return null;let n=t.readBits(1),r=(t.readBits(1)<<1)+n;if(r===3&&t.skipBits(1),t.readBits(1)===1||t.readBits(1)!==0||(t.skipBits(2),t.readBits(24)!==4817730))return null;let i=8;r>=2&&(i=t.readBits(1)?12:10);let a=t.readBits(3),o=0,s=0;if(a!==7)if(s=t.readBits(1),r===1||r===3){let e=t.readBits(1),n=t.readBits(1);o=!e&&!n?3:e&&!n?2:1,t.skipBits(1)}else o=1;else o=3,s=1;let c=t.readBits(16),l=t.readBits(16),u=(c+1)*(l+1),d=Tb(Xx).level;for(let e of Xx)if(u<=e.maxPictureSize){d=e.level;break}return{profile:r,level:d,bitDepth:i,chromaSubsampling:o,videoFullRangeFlag:s,colourPrimaries:a===2?1:a===1?6:2,transferCharacteristics:a===2?1:a===1?6:2,matrixCoefficients:a===7?0:a===2?1:a===1?6:2}},iC=function*(e){let t=new Rx(e),n=()=>{let e=0;for(let n=0;n<8;n++){let r=t.readAlignedByte();if(e|=(r&127)<<n*7,!(r&128))break;if(n===7&&r&128)return null}return e>=2**32-1?null:e};for(;t.getBitsLeft()>=8;){t.skipBits(1);let r=t.readBits(4),i=t.readBits(1),a=t.readBits(1);t.skipBits(1),i&&t.skipBits(8);let o;if(a){let e=n();if(e===null)return;o=e}else o=Math.floor(t.getBitsLeft()/8);J(t.pos%8==0),yield{type:r,data:e.subarray(t.pos/8,t.pos/8+o)},t.skipBits(o*8)}},aC=e=>{for(let{type:t,data:n}of iC(e)){if(t!==1)continue;let e=new Rx(n),r=e.readBits(3);e.readBits(1);let i=e.readBits(1),a=0,o=0,s=0;if(i)a=e.readBits(5);else{if(e.readBits(1)&&(e.skipBits(32),e.skipBits(32),e.readBits(1)))return null;let t=e.readBits(1);t&&(s=e.readBits(5),e.skipBits(32),e.skipBits(5),e.skipBits(5));let n=e.readBits(5);for(let r=0;r<=n;r++){e.skipBits(12);let n=e.readBits(5);if(r===0&&(a=n),n>7){let t=e.readBits(1);r===0&&(o=t)}if(t&&e.readBits(1)){let t=s+1;e.skipBits(t),e.skipBits(t),e.skipBits(1)}e.readBits(1)&&e.skipBits(4)}}let c=e.readBits(4),l=e.readBits(4),u=c+1;e.skipBits(u);let d=l+1;e.skipBits(d);let f=0;if(f=i?0:e.readBits(1),f&&(e.skipBits(4),e.skipBits(3)),e.skipBits(1),e.skipBits(1),e.skipBits(1),!i){e.skipBits(1),e.skipBits(1),e.skipBits(1),e.skipBits(1);let t=e.readBits(1);t&&(e.skipBits(1),e.skipBits(1));let n=e.readBits(1),r=0;r=n?2:e.readBits(1),r>0&&(e.readBits(1)||e.skipBits(1)),t&&e.skipBits(3)}e.skipBits(1),e.skipBits(1),e.skipBits(1);let p=e.readBits(1),m=8;r===2&&p?m=e.readBits(1)?12:10:r<=2&&(m=p?10:8);let h=0;r!==1&&(h=e.readBits(1));let g=1,_=1,v=0;return h||(r===0?(g=1,_=1):r===1?(g=0,_=0):m===12&&(g=e.readBits(1),g&&(_=e.readBits(1))),g&&_&&(v=e.readBits(2))),{profile:r,level:a,tier:o,bitDepth:m,monochrome:h,chromaSubsamplingX:g,chromaSubsamplingY:_,chromaSamplePosition:v}}return null},oC=e=>{let t=kb(e),n=t.getUint8(9),r=t.getUint16(10,!0),i=t.getUint32(12,!0),a=t.getInt16(16,!0),o=t.getUint8(18),s=null;return o&&(s=e.subarray(19,21+n)),{outputChannelCount:n,preSkip:r,inputSampleRate:i,outputGain:a,channelMappingFamily:o,channelMappingTable:s}},sC=[480,960,1920,2880,480,960,1920,2880,480,960,1920,2880,480,960,480,960,120,240,480,960,120,240,480,960,120,240,480,960,120,240,480,960],cC=e=>({durationInSamples:sC[e[0]>>3]}),lC=e=>{if(e.length<7)throw Error(`Setup header is too short.`);if(e[0]!==5)throw Error(`Wrong packet type in Setup header.`);if(String.fromCharCode(...e.slice(1,7))!==`vorbis`)throw Error(`Invalid packet signature in Setup header.`);let t=e.length,n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=e[t-1-r];let r=new Rx(n),i=0;for(;r.getBitsLeft()>97;)if(r.readBits(1)===1){i=r.pos;break}if(i===0)throw Error(`Invalid Setup header: framing bit not found.`);let a=0,o=!1,s=0;for(;r.getBitsLeft()>=97;){let e=r.pos,t=r.readBits(8),n=r.readBits(16),i=r.readBits(16);if(t>63||n!==0||i!==0){r.pos=e;break}if(r.skipBits(1),a++,a>64)break;r.clone().readBits(6)+1===a&&(o=!0,s=a)}if(!o)throw Error(`Invalid Setup header: mode header not found.`);if(s>63)throw Error(`Unsupported mode count: ${s}.`);let c=s;r.pos=0,r.skipBits(i);let l=Array(c).fill(0);for(let e=c-1;e>=0;e--)r.skipBits(40),l[e]=r.readBits(1);return{modeBlockflags:l}},uC=(e,t,n)=>{switch(e){case`avc`:for(let e of MS(n,t)){let t=n[e.offset],r=NS(t);if(r>=OS.NON_IDR_SLICE&&r<=OS.SLICE_DPC)return`delta`;if(r===OS.IDR)return`key`;if(r===OS.SEI&&(!Sx()||wx()>=144)){let t=PS(n.subarray(e.offset,e.offset+e.length)),r=1;do{let e=0;for(;;){let n=t[r++];if(n===void 0||(e+=n,n<255))break}let n=0;for(;;){let e=t[r++];if(e===void 0||(n+=e,e<255))break}if(e===6){let e=new Rx(t);e.pos=8*r;let n=Y(e),i=e.readBits(1);if(n===0&&i===1)return`key`}r+=n}while(r<t.length-1)}}return`delta`;case`hevc`:for(let e of GS(n,t)){let t=KS(n[e.offset]);if(t<kS.BLA_W_LP)return`delta`;if(t<=kS.RSV_IRAP_VCL23)return`key`}return`delta`;case`vp8`:return n[0]&1?`delta`:`key`;case`vp9`:{let e=new Rx(n);if(e.readBits(2)!==2)return null;let t=e.readBits(1);return(e.readBits(1)<<1)+t===3&&e.skipBits(1),e.readBits(1)?null:e.readBits(1)===0?`key`:`delta`}case`av1`:{let e=!1;for(let{type:t,data:r}of iC(n))if(t===1){let t=new Rx(r);t.skipBits(4),e=!!t.readBits(1)}else if(t===3||t===6||t===7){if(e)return`key`;let t=new Rx(r);return t.readBits(1)?null:t.readBits(2)===0?`key`:`delta`}return null}default:Qb(e),J(!1)}},dC;(function(e){e[e.STREAMINFO=0]=`STREAMINFO`,e[e.VORBIS_COMMENT=4]=`VORBIS_COMMENT`,e[e.PICTURE=6]=`PICTURE`})(dC||={});var fC=(e,t)=>{let n=kb(e),r=0,i=n.getUint32(r,!0);r+=4;let a=Ab.decode(e.subarray(r,r+i));r+=i,i>0&&(t.raw??={},t.raw.vendor??=a);let o=n.getUint32(r,!0);r+=4;for(let i=0;i<o;i++){let i=n.getUint32(r,!0);r+=4;let a=Ab.decode(e.subarray(r,r+i));r+=i;let o=a.indexOf(`=`);if(o===-1)continue;let s=a.slice(0,o).toUpperCase(),c=a.slice(o+1);switch(t.raw??={},t.raw[s]??=c,s){case`TITLE`:t.title??=c;break;case`DESCRIPTION`:t.description??=c;break;case`ARTIST`:t.artist??=c;break;case`ALBUM`:t.album??=c;break;case`ALBUMARTIST`:t.albumArtist??=c;break;case`COMMENT`:t.comment??=c;break;case`LYRICS`:t.lyrics??=c;break;case`TRACKNUMBER`:{let e=c.split(`/`),n=Number.parseInt(e[0],10),r=e[1]&&Number.parseInt(e[1],10);Number.isInteger(n)&&n>0&&(t.trackNumber??=n),r&&Number.isInteger(r)&&r>0&&(t.tracksTotal??=r)}break;case`TRACKTOTAL`:{let e=Number.parseInt(c,10);Number.isInteger(e)&&e>0&&(t.tracksTotal??=e)}break;case`DISCNUMBER`:{let e=c.split(`/`),n=Number.parseInt(e[0],10),r=e[1]&&Number.parseInt(e[1],10);Number.isInteger(n)&&n>0&&(t.discNumber??=n),r&&Number.isInteger(r)&&r>0&&(t.discsTotal??=r)}break;case`DISCTOTAL`:{let e=Number.parseInt(c,10);Number.isInteger(e)&&e>0&&(t.discsTotal??=e)}break;case`DATE`:{let e=new Date(c);Number.isNaN(e.getTime())||(t.date??=e)}break;case`GENRE`:t.genre??=c;break;case`METADATA_BLOCK_PICTURE`:{let e=Ox(c),n=kb(e),r=n.getUint32(0,!1),i=n.getUint32(4,!1),a=String.fromCharCode(...e.subarray(8,8+i)),o=n.getUint32(8+i,!1),s=Ab.decode(e.subarray(12+i,12+i+o)),l=n.getUint32(i+o+28),u=e.subarray(i+o+32,i+o+32+l);t.images??=[],t.images.push({data:u,mimeType:a,kind:r===3?`coverFront`:r===4?`coverBack`:`unknown`,name:void 0,description:s||void 0})}break}}},pC=[2,1,2,3,3,4,4,5],mC=e=>{if(e.length<7||e[0]!==11||e[1]!==119)return null;let t=new Rx(e);t.skipBits(16),t.skipBits(16);let n=t.readBits(2);if(n===3)return null;let r=t.readBits(6),i=t.readBits(5);if(i>8)return null;let a=t.readBits(3),o=t.readBits(3);return o&1&&o!==1&&t.skipBits(2),o&4&&t.skipBits(2),o===2&&t.skipBits(2),{fscod:n,bsid:i,bsmod:a,acmod:o,lfeon:t.readBits(1),bitRateCode:Math.floor(r/2)}},hC=[128,138,192,128,140,192,160,174,240,160,176,240,192,208,288,192,210,288,224,242,336,224,244,336,256,278,384,256,280,384,320,348,480,320,350,480,384,416,288*2,384,418,288*2,448,486,336*2,448,488,336*2,256*2,278*2,384*2,256*2,279*2,384*2,320*2,348*2,480*2,320*2,349*2,480*2,384*2,417*2,576*2,384*2,418*2,576*2,448*2,487*2,672*2,448*2,488*2,672*2,512*2,557*2,768*2,512*2,558*2,768*2,640*2,696*2,960*2,640*2,697*2,960*2,768*2,835*2,1152*2,768*2,836*2,1152*2,896*2,975*2,1344*2,896*2,976*2,1344*2,1024*2,1114*2,1536*2,1024*2,1115*2,1536*2,1152*2,1253*2,1728*2,1152*2,1254*2,1728*2,1280*2,1393*2,1920*2,1280*2,1394*2,1920*2],gC=1536;new Uint8Array([5,4,65,67,45,51]),new Uint8Array([5,4,69,65,67,51]);var _C=[1,2,3,6],vC=e=>{if(e.length<6||e[0]!==11||e[1]!==119)return null;let t=new Rx(e);t.skipBits(16);let n=t.readBits(2);if(t.skipBits(3),n!==0&&n!==2)return null;let r=t.readBits(11),i=t.readBits(2),a=0,o;i===3?(a=t.readBits(2),o=3):o=t.readBits(2);let s=t.readBits(3),c=t.readBits(1),l=t.readBits(5);if(l<11||l>16)return null;let u=_C[o],d;return d=i<3?ES[i]/1e3:DS[a]/1e3,{dataRate:Math.round((r+1)*d/(u*16)),substreams:[{fscod:i,fscod2:a,bsid:l,bsmod:0,acmod:s,lfeon:c,numDepSub:0,chanLoc:0}]}},yC=e=>{if(e.length<2)return null;let t=new Rx(e),n=t.readBits(13),r=t.readBits(3),i=[];for(let n=0;n<=r&&!(Math.ceil(t.pos/8)+3>e.length);n++){let e=t.readBits(2),n=t.readBits(5);t.skipBits(1),t.skipBits(1);let r=t.readBits(3),a=t.readBits(3),o=t.readBits(1);t.skipBits(3);let s=t.readBits(4),c=0;s>0?c=t.readBits(9):t.skipBits(1),i.push({fscod:e,fscod2:null,bsid:n,bsmod:r,acmod:a,lfeon:o,numDepSub:s,chanLoc:c})}return i.length===0?null:{dataRate:n,substreams:i}},bC=e=>{let t=e.substreams[0];return J(t),t.fscod<3?ES[t.fscod]:t.fscod2!==null&&t.fscod2<3?DS[t.fscod2]:null},xC=e=>{let t=e.substreams[0];J(t);let n=pC[t.acmod]+t.lfeon;if(t.numDepSub>0){let e=[2,2,1,1,2,2,2,1,1];for(let r=0;r<9;r++)t.chanLoc&1<<8-r&&(n+=e[r])}return n},SC=class{constructor(e){this.input=e}},CC=[],wC=[],TC=[],EC=[],DC=new Uint8Array,OC=class e{constructor(e,t,n,r,i=-1,a,o){if(this.data=e,this.type=t,this.timestamp=n,this.duration=r,this.sequenceNumber=i,e===DC&&a===void 0)throw Error(`Internal error: byteLength must be explicitly provided when constructing metadata-only packets.`);if(a===void 0&&(a=e.byteLength),!(e instanceof Uint8Array))throw TypeError(`data must be a Uint8Array.`);if(t!==`key`&&t!==`delta`)throw TypeError(`type must be either "key" or "delta".`);if(!Number.isFinite(n))throw TypeError(`timestamp must be a number.`);if(!Number.isFinite(r)||r<0)throw TypeError(`duration must be a non-negative number.`);if(!Number.isFinite(i))throw TypeError(`sequenceNumber must be a number.`);if(!Number.isInteger(a)||a<0)throw TypeError(`byteLength must be a non-negative integer.`);if(o!==void 0&&(typeof o!=`object`||!o))throw TypeError(`sideData, when provided, must be an object.`);if(o?.alpha!==void 0&&!(o.alpha instanceof Uint8Array))throw TypeError(`sideData.alpha, when provided, must be a Uint8Array.`);if(o?.alphaByteLength!==void 0&&(!Number.isInteger(o.alphaByteLength)||o.alphaByteLength<0))throw TypeError(`sideData.alphaByteLength, when provided, must be a non-negative integer.`);this.byteLength=a,this.sideData=o??{},this.sideData.alpha&&this.sideData.alphaByteLength===void 0&&(this.sideData.alphaByteLength=this.sideData.alpha.byteLength)}get isMetadataOnly(){return this.data===DC}get microsecondTimestamp(){return Math.trunc(dx*this.timestamp)}get microsecondDuration(){return Math.trunc(dx*this.duration)}toEncodedVideoChunk(){if(this.isMetadataOnly)throw TypeError(`Metadata-only packets cannot be converted to a video chunk.`);if(typeof EncodedVideoChunk>`u`)throw Error(`Your browser does not support EncodedVideoChunk.`);return new EncodedVideoChunk({data:this.data,type:this.type,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}alphaToEncodedVideoChunk(e=this.type){if(!this.sideData.alpha)throw TypeError(`This packet does not contain alpha side data.`);if(this.isMetadataOnly)throw TypeError(`Metadata-only packets cannot be converted to a video chunk.`);if(typeof EncodedVideoChunk>`u`)throw Error(`Your browser does not support EncodedVideoChunk.`);return new EncodedVideoChunk({data:this.sideData.alpha,type:e,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}toEncodedAudioChunk(){if(this.isMetadataOnly)throw TypeError(`Metadata-only packets cannot be converted to an audio chunk.`);if(typeof EncodedAudioChunk>`u`)throw Error(`Your browser does not support EncodedAudioChunk.`);return new EncodedAudioChunk({data:this.data,type:this.type,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}static fromEncodedChunk(t,n){if(!(t instanceof EncodedVideoChunk||t instanceof EncodedAudioChunk))throw TypeError(`chunk must be an EncodedVideoChunk or EncodedAudioChunk.`);let r=new Uint8Array(t.byteLength);return t.copyTo(r),new e(r,t.type,t.timestamp/1e6,(t.duration??0)/1e6,void 0,void 0,n)}clone(t){if(t!==void 0&&(typeof t!=`object`||!t))throw TypeError(`options, when provided, must be an object.`);if(t?.data!==void 0&&!(t.data instanceof Uint8Array))throw TypeError(`options.data, when provided, must be a Uint8Array.`);if(t?.type!==void 0&&t.type!==`key`&&t.type!==`delta`)throw TypeError(`options.type, when provided, must be either "key" or "delta".`);if(t?.timestamp!==void 0&&!Number.isFinite(t.timestamp))throw TypeError(`options.timestamp, when provided, must be a number.`);if(t?.duration!==void 0&&!Number.isFinite(t.duration))throw TypeError(`options.duration, when provided, must be a number.`);if(t?.sequenceNumber!==void 0&&!Number.isFinite(t.sequenceNumber))throw TypeError(`options.sequenceNumber, when provided, must be a number.`);if(t?.sideData!==void 0&&(typeof t.sideData!=`object`||t.sideData===null))throw TypeError(`options.sideData, when provided, must be an object.`);return new e(t?.data??this.data,t?.type??this.type,t?.timestamp??this.timestamp,t?.duration??this.duration,t?.sequenceNumber??this.sequenceNumber,this.byteLength,t?.sideData??this.sideData)}},kC=e=>{let t=8191,n=e,r=4096,i=0,a=12,o=0;for(n<0&&(n=-n,i=128),n+=33,n>t&&(n=t);(n&r)!==r&&a>=5;)r>>=1,a--;return o=n>>a-4&15,~(i|a-5<<4|o)&255},AC=e=>{let t=0,n=0,r=~e;r&128&&(r&=-129,t=-1),n=((r&240)>>4)+5;let i=(1<<n|(r&15)<<n-4|1<<n-5)-33;return t===0?i:-i},jC=e=>{let t=4095,n=2048,r=0,i=11,a=0,o=e;for(o<0&&(o=-o,r=128),o>t&&(o=t);(o&n)!==n&&i>=5;)n>>=1,i--;return a=o>>(i===4?1:i-4)&15,(r|i-4<<4|a)^85},MC=e=>{let t=0,n=0,r=e^85;r&128&&(r&=-129,t=-1),n=((r&240)>>4)+4;let i=0;return i=n===4?r<<1|1:1<<n|(r&15)<<n-4|1<<n-5,t===0?i:-i};kx();var NC=-1/0,PC=-1/0,FC=null;typeof FinalizationRegistry<`u`&&(FC=new FinalizationRegistry(e=>{let t=Date.now();e.type===`video`?(t-NC>=1e3&&(console.error(`A VideoSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your VideoSamples as soon as you're done using them.`),NC=t),typeof VideoFrame<`u`&&e.data instanceof VideoFrame&&e.data.close()):(t-PC>=1e3&&(console.error(`An AudioSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your AudioSamples as soon as you're done using them.`),PC=t),typeof AudioData<`u`&&e.data instanceof AudioData&&e.data.close())}));var IC=[`I420`,`I420P10`,`I420P12`,`I420A`,`I420AP10`,`I420AP12`,`I422`,`I422P10`,`I422P12`,`I422A`,`I422AP10`,`I422AP12`,`I444`,`I444P10`,`I444P12`,`I444A`,`I444AP10`,`I444AP12`,`NV12`,`RGBA`,`RGBX`,`BGRA`,`BGRX`],LC=new Set(IC),RC=class e{get codedWidth(){return this.visibleRect.width}get codedHeight(){return this.visibleRect.height}get displayWidth(){return this.rotation%180==0?this.squarePixelWidth:this.squarePixelHeight}get displayHeight(){return this.rotation%180==0?this.squarePixelHeight:this.squarePixelWidth}get microsecondTimestamp(){return Math.trunc(dx*this.timestamp)}get microsecondDuration(){return Math.trunc(dx*this.duration)}get hasAlpha(){return this.format&&this.format.includes(`A`)}constructor(t,n){if(this._closed=!1,t instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&t instanceof SharedArrayBuffer||ArrayBuffer.isView(t)){if(!n||typeof n!=`object`)throw TypeError(`init must be an object.`);if(n.format===void 0||!LC.has(n.format))throw TypeError(`init.format must be one of: `+IC.join(`, `));if(!Number.isInteger(n.codedWidth)||n.codedWidth<=0)throw TypeError(`init.codedWidth must be a positive integer.`);if(!Number.isInteger(n.codedHeight)||n.codedHeight<=0)throw TypeError(`init.codedHeight must be a positive integer.`);if(n.rotation!==void 0&&![0,90,180,270].includes(n.rotation))throw TypeError(`init.rotation, when provided, must be 0, 90, 180, or 270.`);if(!Number.isFinite(n.timestamp))throw TypeError(`init.timestamp must be a number.`);if(n.duration!==void 0&&(!Number.isFinite(n.duration)||n.duration<0))throw TypeError(`init.duration, when provided, must be a non-negative number.`);if(n.layout!==void 0){if(!Array.isArray(n.layout))throw TypeError(`init.layout, when provided, must be an array.`);for(let e of n.layout){if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`Each entry in init.layout must be an object.`);if(!Number.isInteger(e.offset)||e.offset<0)throw TypeError(`plane.offset must be a non-negative integer.`);if(!Number.isInteger(e.stride)||e.stride<0)throw TypeError(`plane.stride must be a non-negative integer.`)}}if(n.visibleRect!==void 0&&Mx(n.visibleRect,`init.visibleRect`),n.displayWidth!==void 0&&(!Number.isInteger(n.displayWidth)||n.displayWidth<=0))throw TypeError(`init.displayWidth, when provided, must be a positive integer.`);if(n.displayHeight!==void 0&&(!Number.isInteger(n.displayHeight)||n.displayHeight<=0))throw TypeError(`init.displayHeight, when provided, must be a positive integer.`);if(n.displayWidth!==void 0!=(n.displayHeight!==void 0))throw TypeError(`init.displayWidth and init.displayHeight must be either both provided or both omitted.`);this._data=Ob(t).slice(),this._layout=n.layout??WC(n.format,n.codedWidth,n.codedHeight),this.format=n.format,this.rotation=n.rotation??0,this.timestamp=n.timestamp,this.duration=n.duration??0,this.colorSpace=new zC(n.colorSpace),this.visibleRect={left:n.visibleRect?.left??0,top:n.visibleRect?.top??0,width:n.visibleRect?.width??n.codedWidth,height:n.visibleRect?.height??n.codedHeight},n.displayWidth===void 0?(this.squarePixelWidth=this.codedWidth,this.squarePixelHeight=this.codedHeight):(this.squarePixelWidth=this.rotation%180==0?n.displayWidth:n.displayHeight,this.squarePixelHeight=this.rotation%180==0?n.displayHeight:n.displayWidth)}else if(typeof VideoFrame<`u`&&t instanceof VideoFrame){if(n?.rotation!==void 0&&![0,90,180,270].includes(n.rotation))throw TypeError(`init.rotation, when provided, must be 0, 90, 180, or 270.`);if(n?.timestamp!==void 0&&!Number.isFinite(n?.timestamp))throw TypeError(`init.timestamp, when provided, must be a number.`);if(n?.duration!==void 0&&(!Number.isFinite(n.duration)||n.duration<0))throw TypeError(`init.duration, when provided, must be a non-negative number.`);n?.visibleRect!==void 0&&Mx(n.visibleRect,`init.visibleRect`),this._data=t,this._layout=null,this.format=t.format,this.visibleRect={left:t.visibleRect?.x??0,top:t.visibleRect?.y??0,width:t.visibleRect?.width??t.codedWidth,height:t.visibleRect?.height??t.codedHeight},this.rotation=n?.rotation??0,this.squarePixelWidth=t.displayWidth,this.squarePixelHeight=t.displayHeight,this.timestamp=n?.timestamp??t.timestamp/1e6,this.duration=n?.duration??(t.duration??0)/1e6,this.colorSpace=new zC(t.colorSpace)}else if(typeof HTMLImageElement<`u`&&t instanceof HTMLImageElement||typeof SVGImageElement<`u`&&t instanceof SVGImageElement||typeof ImageBitmap<`u`&&t instanceof ImageBitmap||typeof HTMLVideoElement<`u`&&t instanceof HTMLVideoElement||typeof HTMLCanvasElement<`u`&&t instanceof HTMLCanvasElement||typeof OffscreenCanvas<`u`&&t instanceof OffscreenCanvas){if(!n||typeof n!=`object`)throw TypeError(`init must be an object.`);if(n.rotation!==void 0&&![0,90,180,270].includes(n.rotation))throw TypeError(`init.rotation, when provided, must be 0, 90, 180, or 270.`);if(!Number.isFinite(n.timestamp))throw TypeError(`init.timestamp must be a number.`);if(n.duration!==void 0&&(!Number.isFinite(n.duration)||n.duration<0))throw TypeError(`init.duration, when provided, must be a non-negative number.`);if(typeof VideoFrame<`u`)return new e(new VideoFrame(t,{timestamp:Math.trunc(n.timestamp*dx),duration:Math.trunc((n.duration??0)*dx)||void 0}),n);let r=0,i=0;if(`naturalWidth`in t?(r=t.naturalWidth,i=t.naturalHeight):`videoWidth`in t?(r=t.videoWidth,i=t.videoHeight):`width`in t&&(r=Number(t.width),i=Number(t.height)),!r||!i)throw TypeError(`Could not determine dimensions.`);let a=new OffscreenCanvas(r,i),o=a.getContext(`2d`,{alpha:bx(),willReadFrequently:!0});J(o),o.drawImage(t,0,0),this._data=a,this._layout=null,this.format=`RGBX`,this.visibleRect={left:0,top:0,width:r,height:i},this.squarePixelWidth=r,this.squarePixelHeight=i,this.rotation=n.rotation??0,this.timestamp=n.timestamp,this.duration=n.duration??0,this.colorSpace=new zC({matrix:`rgb`,primaries:`bt709`,transfer:`iec61966-2-1`,fullRange:!0})}else throw TypeError(`Invalid data type: Must be a BufferSource or CanvasImageSource.`);this.pixelAspectRatio=jx({num:this.squarePixelWidth*this.codedHeight,den:this.squarePixelHeight*this.codedWidth}),FC?.register(this,{type:`video`,data:this._data},this)}clone(){if(this._closed)throw Error(`VideoSample is closed.`);return J(this._data!==null),BC(this._data)?new e(this._data.clone(),{timestamp:this.timestamp,duration:this.duration,rotation:this.rotation}):this._data instanceof Uint8Array?(J(this._layout),new e(this._data,{format:this.format,layout:this._layout,codedWidth:this.codedWidth,codedHeight:this.codedHeight,timestamp:this.timestamp,duration:this.duration,colorSpace:this.colorSpace,rotation:this.rotation,visibleRect:this.visibleRect,displayWidth:this.displayWidth,displayHeight:this.displayHeight})):new e(this._data,{format:this.format,codedWidth:this.codedWidth,codedHeight:this.codedHeight,timestamp:this.timestamp,duration:this.duration,colorSpace:this.colorSpace,rotation:this.rotation,visibleRect:this.visibleRect,displayWidth:this.displayWidth,displayHeight:this.displayHeight})}close(){this._closed||=(FC?.unregister(this),BC(this._data)?this._data.close():this._data=null,!0)}allocationSize(e={}){if(UC(e),this._closed)throw Error(`VideoSample is closed.`);if(this.format===null)throw Error(`Cannot get allocation size when format is null. Sorry!`);if(J(this._data!==null),!BC(this._data)&&(e.colorSpace||e.format&&e.format!==this.format||e.layout||e.rect)){let t=this.toVideoFrame(),n=t.allocationSize(e);return t.close(),n}return BC(this._data)?this._data.allocationSize(e):this._data instanceof Uint8Array?this._data.byteLength:this.codedWidth*this.codedHeight*4}async copyTo(e,t={}){if(!Bb(e))throw TypeError(`destination must be an ArrayBuffer or an ArrayBuffer view.`);if(UC(t),this._closed)throw Error(`VideoSample is closed.`);if(this.format===null)throw Error(`Cannot copy video sample data when format is null. Sorry!`);if(J(this._data!==null),!BC(this._data)&&(t.colorSpace||t.format&&t.format!==this.format||t.layout||t.rect)){let n=this.toVideoFrame(),r=await n.copyTo(e,t);return n.close(),r}if(BC(this._data))return this._data.copyTo(e,t);if(this._data instanceof Uint8Array)return J(this._layout),Ob(e).set(this._data),this._layout;{let t=this._data.getContext(`2d`);J(t);let n=t.getImageData(0,0,this.codedWidth,this.codedHeight);return Ob(e).set(n.data),[{offset:0,stride:4*this.codedWidth}]}}toVideoFrame(){if(this._closed)throw Error(`VideoSample is closed.`);return J(this._data!==null),BC(this._data)?new VideoFrame(this._data,{timestamp:this.microsecondTimestamp,duration:this.microsecondDuration||void 0}):this._data instanceof Uint8Array?new VideoFrame(this._data,{format:this.format,codedWidth:this.codedWidth,codedHeight:this.codedHeight,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration||void 0,colorSpace:this.colorSpace}):new VideoFrame(this._data,{timestamp:this.microsecondTimestamp,duration:this.microsecondDuration||void 0})}draw(e,t,n,r,i,a,o,s,c){let l=0,u=0,d=this.displayWidth,f=this.displayHeight,p=0,m=0,h=this.displayWidth,g=this.displayHeight;if(a===void 0?(p=t,m=n,r!==void 0&&(h=r,g=i)):(l=t,u=n,d=r,f=i,p=a,m=o,s===void 0?(h=d,g=f):(h=s,g=c)),!(typeof CanvasRenderingContext2D<`u`&&e instanceof CanvasRenderingContext2D||typeof OffscreenCanvasRenderingContext2D<`u`&&e instanceof OffscreenCanvasRenderingContext2D))throw TypeError(`context must be a CanvasRenderingContext2D or OffscreenCanvasRenderingContext2D.`);if(!Number.isFinite(l))throw TypeError(`sx must be a number.`);if(!Number.isFinite(u))throw TypeError(`sy must be a number.`);if(!Number.isFinite(d)||d<0)throw TypeError(`sWidth must be a non-negative number.`);if(!Number.isFinite(f)||f<0)throw TypeError(`sHeight must be a non-negative number.`);if(!Number.isFinite(p))throw TypeError(`dx must be a number.`);if(!Number.isFinite(m))throw TypeError(`dy must be a number.`);if(!Number.isFinite(h)||h<0)throw TypeError(`dWidth must be a non-negative number.`);if(!Number.isFinite(g)||g<0)throw TypeError(`dHeight must be a non-negative number.`);if(this._closed)throw Error(`VideoSample is closed.`);({sx:l,sy:u,sWidth:d,sHeight:f}=this._rotateSourceRegion(l,u,d,f,this.rotation));let _=this.toCanvasImageSource();e.save();let v=p+h/2,y=m+g/2;e.translate(v,y),e.rotate(this.rotation*Math.PI/180);let b=this.rotation%180==0?1:h/g;e.scale(1/b,b),e.drawImage(_,l,u,d,f,-h/2,-g/2,h,g),e.restore()}drawWithFit(e,t){if(!(typeof CanvasRenderingContext2D<`u`&&e instanceof CanvasRenderingContext2D||typeof OffscreenCanvasRenderingContext2D<`u`&&e instanceof OffscreenCanvasRenderingContext2D))throw TypeError(`context must be a CanvasRenderingContext2D or OffscreenCanvasRenderingContext2D.`);if(!t||typeof t!=`object`)throw TypeError(`options must be an object.`);if(![`fill`,`contain`,`cover`].includes(t.fit))throw TypeError(`options.fit must be 'fill', 'contain', or 'cover'.`);if(t.rotation!==void 0&&![0,90,180,270].includes(t.rotation))throw TypeError(`options.rotation, when provided, must be 0, 90, 180, or 270.`);t.crop!==void 0&&HC(t.crop,`options.`);let n=e.canvas.width,r=e.canvas.height,i=t.rotation??this.rotation,[a,o]=i%180==0?[this.squarePixelWidth,this.squarePixelHeight]:[this.squarePixelHeight,this.squarePixelWidth];t.crop&&VC(t.crop,a,o);let s,c,l,u,{sx:d,sy:f,sWidth:p,sHeight:m}=this._rotateSourceRegion(t.crop?.left??0,t.crop?.top??0,t.crop?.width??a,t.crop?.height??o,i);if(t.fit===`fill`)s=0,c=0,l=n,u=r;else{let[e,i]=t.crop?[t.crop.width,t.crop.height]:[a,o],d=t.fit===`contain`?Math.min(n/e,r/i):Math.max(n/e,r/i);l=e*d,u=i*d,s=(n-l)/2,c=(r-u)/2}e.save();let h=i%180==0?1:l/u;e.translate(n/2,r/2),e.rotate(i*Math.PI/180),e.scale(1/h,h),e.translate(-n/2,-r/2),e.drawImage(this.toCanvasImageSource(),d,f,p,m,s,c,l,u),e.restore()}_rotateSourceRegion(e,t,n,r,i){return i===90?[e,t,n,r]=[t,this.squarePixelHeight-e-n,r,n]:i===180?[e,t]=[this.squarePixelWidth-e-n,this.squarePixelHeight-t-r]:i===270&&([e,t,n,r]=[this.squarePixelWidth-t-r,e,r,n]),{sx:e,sy:t,sWidth:n,sHeight:r}}toCanvasImageSource(){if(this._closed)throw Error(`VideoSample is closed.`);if(J(this._data!==null),this._data instanceof Uint8Array){let e=this.toVideoFrame();return queueMicrotask(()=>e.close()),e}else return this._data}setRotation(e){if(![0,90,180,270].includes(e))throw TypeError(`newRotation must be 0, 90, 180, or 270.`);this.rotation=e}setTimestamp(e){if(!Number.isFinite(e))throw TypeError(`newTimestamp must be a number.`);this.timestamp=e}setDuration(e){if(!Number.isFinite(e)||e<0)throw TypeError(`newDuration must be a non-negative number.`);this.duration=e}[Symbol.dispose](){this.close()}},zC=class{constructor(e){if(e!==void 0){if(!e||typeof e!=`object`)throw TypeError(`init.colorSpace, when provided, must be an object.`);let t=Object.keys(Nb);if(e.primaries!=null&&!t.includes(e.primaries))throw TypeError(`init.colorSpace.primaries, when provided, must be one of ${t.join(`, `)}.`);let n=Object.keys(Fb);if(e.transfer!=null&&!n.includes(e.transfer))throw TypeError(`init.colorSpace.transfer, when provided, must be one of ${n.join(`, `)}.`);let r=Object.keys(Lb);if(e.matrix!=null&&!r.includes(e.matrix))throw TypeError(`init.colorSpace.matrix, when provided, must be one of ${r.join(`, `)}.`);if(e.fullRange!=null&&typeof e.fullRange!=`boolean`)throw TypeError(`init.colorSpace.fullRange, when provided, must be a boolean.`)}this.primaries=e?.primaries??null,this.transfer=e?.transfer??null,this.matrix=e?.matrix??null,this.fullRange=e?.fullRange??null}toJSON(){return{primaries:this.primaries,transfer:this.transfer,matrix:this.matrix,fullRange:this.fullRange}}},BC=e=>typeof VideoFrame<`u`&&e instanceof VideoFrame,VC=(e,t,n)=>{e.left=Math.min(e.left,t),e.top=Math.min(e.top,n),e.width=Math.min(e.width,t-e.left),e.height=Math.min(e.height,n-e.top),J(e.width>=0),J(e.height>=0)},HC=(e,t)=>{if(!e||typeof e!=`object`)throw TypeError(t+`crop, when provided, must be an object.`);if(!Number.isInteger(e.left)||e.left<0)throw TypeError(t+`crop.left must be a non-negative integer.`);if(!Number.isInteger(e.top)||e.top<0)throw TypeError(t+`crop.top must be a non-negative integer.`);if(!Number.isInteger(e.width)||e.width<0)throw TypeError(t+`crop.width must be a non-negative integer.`);if(!Number.isInteger(e.height)||e.height<0)throw TypeError(t+`crop.height must be a non-negative integer.`)},UC=e=>{if(!e||typeof e!=`object`)throw TypeError(`options must be an object.`);if(e.colorSpace!==void 0&&![`display-p3`,`srgb`].includes(e.colorSpace))throw TypeError(`options.colorSpace, when provided, must be 'display-p3' or 'srgb'.`);if(e.format!==void 0&&typeof e.format!=`string`)throw TypeError(`options.format, when provided, must be a string.`);if(e.layout!==void 0){if(!Array.isArray(e.layout))throw TypeError(`options.layout, when provided, must be an array.`);for(let t of e.layout){if(!t||typeof t!=`object`)throw TypeError(`Each entry in options.layout must be an object.`);if(!Number.isInteger(t.offset)||t.offset<0)throw TypeError(`plane.offset must be a non-negative integer.`);if(!Number.isInteger(t.stride)||t.stride<0)throw TypeError(`plane.stride must be a non-negative integer.`)}}if(e.rect!==void 0){if(!e.rect||typeof e.rect!=`object`)throw TypeError(`options.rect, when provided, must be an object.`);if(e.rect.x!==void 0&&(!Number.isInteger(e.rect.x)||e.rect.x<0))throw TypeError(`options.rect.x, when provided, must be a non-negative integer.`);if(e.rect.y!==void 0&&(!Number.isInteger(e.rect.y)||e.rect.y<0))throw TypeError(`options.rect.y, when provided, must be a non-negative integer.`);if(e.rect.width!==void 0&&(!Number.isInteger(e.rect.width)||e.rect.width<0))throw TypeError(`options.rect.width, when provided, must be a non-negative integer.`);if(e.rect.height!==void 0&&(!Number.isInteger(e.rect.height)||e.rect.height<0))throw TypeError(`options.rect.height, when provided, must be a non-negative integer.`)}},WC=(e,t,n)=>{let r=GC(e),i=[],a=0;for(let e of r){let r=Math.ceil(t/e.widthDivisor),o=Math.ceil(n/e.heightDivisor),s=r*e.sampleBytes,c=s*o;i.push({offset:a,stride:s}),a+=c}return i},GC=e=>{let t=(e,t,n,r,i)=>{let a=[{sampleBytes:e,widthDivisor:1,heightDivisor:1},{sampleBytes:t,widthDivisor:n,heightDivisor:r},{sampleBytes:t,widthDivisor:n,heightDivisor:r}];return i&&a.push({sampleBytes:e,widthDivisor:1,heightDivisor:1}),a};switch(e){case`I420`:return t(1,1,2,2,!1);case`I420P10`:case`I420P12`:return t(2,2,2,2,!1);case`I420A`:return t(1,1,2,2,!0);case`I420AP10`:case`I420AP12`:return t(2,2,2,2,!0);case`I422`:return t(1,1,2,1,!1);case`I422P10`:case`I422P12`:return t(2,2,2,1,!1);case`I422A`:return t(1,1,2,1,!0);case`I422AP10`:case`I422AP12`:return t(2,2,2,1,!0);case`I444`:return t(1,1,1,1,!1);case`I444P10`:case`I444P12`:return t(2,2,1,1,!1);case`I444A`:return t(1,1,1,1,!0);case`I444AP10`:case`I444AP12`:return t(2,2,1,1,!0);case`NV12`:return[{sampleBytes:1,widthDivisor:1,heightDivisor:1},{sampleBytes:2,widthDivisor:2,heightDivisor:2}];case`RGBA`:case`RGBX`:case`BGRA`:case`BGRX`:return[{sampleBytes:4,widthDivisor:1,heightDivisor:1}];default:Qb(e),J(!1)}},KC=new Set([`f32`,`f32-planar`,`s16`,`s16-planar`,`s32`,`s32-planar`,`u8`,`u8-planar`]),qC=class e{get microsecondTimestamp(){return Math.trunc(dx*this.timestamp)}get microsecondDuration(){return Math.trunc(dx*this.duration)}constructor(e){if(this._closed=!1,QC(e)){if(e.format===null)throw TypeError(`AudioData with null format is not supported.`);this._data=e,this.format=e.format,this.sampleRate=e.sampleRate,this.numberOfFrames=e.numberOfFrames,this.numberOfChannels=e.numberOfChannels,this.timestamp=e.timestamp/1e6,this.duration=e.numberOfFrames/e.sampleRate}else{if(!e||typeof e!=`object`)throw TypeError(`Invalid AudioDataInit: must be an object.`);if(!KC.has(e.format))throw TypeError(`Invalid AudioDataInit: invalid format.`);if(!Number.isFinite(e.sampleRate)||e.sampleRate<=0)throw TypeError(`Invalid AudioDataInit: sampleRate must be > 0.`);if(!Number.isInteger(e.numberOfChannels)||e.numberOfChannels===0)throw TypeError(`Invalid AudioDataInit: numberOfChannels must be an integer > 0.`);if(!Number.isFinite(e?.timestamp))throw TypeError(`init.timestamp must be a number.`);let t=e.data.byteLength/(JC(e.format)*e.numberOfChannels);if(!Number.isInteger(t))throw TypeError(`Invalid AudioDataInit: data size is not a multiple of frame size.`);this.format=e.format,this.sampleRate=e.sampleRate,this.numberOfFrames=t,this.numberOfChannels=e.numberOfChannels,this.timestamp=e.timestamp,this.duration=t/e.sampleRate;let n;if(e.data instanceof ArrayBuffer)n=new Uint8Array(e.data);else if(ArrayBuffer.isView(e.data))n=new Uint8Array(e.data.buffer,e.data.byteOffset,e.data.byteLength);else throw TypeError(`Invalid AudioDataInit: data is not a BufferSource.`);let r=this.numberOfFrames*this.numberOfChannels*JC(this.format);if(n.byteLength<r)throw TypeError(`Invalid AudioDataInit: insufficient data size.`);this._data=n}FC?.register(this,{type:`audio`,data:this._data},this)}allocationSize(e){if(!e||typeof e!=`object`)throw TypeError(`options must be an object.`);if(!Number.isInteger(e.planeIndex)||e.planeIndex<0)throw TypeError(`planeIndex must be a non-negative integer.`);if(e.format!==void 0&&!KC.has(e.format))throw TypeError(`Invalid format.`);if(e.frameOffset!==void 0&&(!Number.isInteger(e.frameOffset)||e.frameOffset<0))throw TypeError(`frameOffset must be a non-negative integer.`);if(e.frameCount!==void 0&&(!Number.isInteger(e.frameCount)||e.frameCount<0))throw TypeError(`frameCount must be a non-negative integer.`);if(this._closed)throw Error(`AudioSample is closed.`);let t=e.format??this.format,n=e.frameOffset??0;if(n>=this.numberOfFrames)throw RangeError(`frameOffset out of range`);let r=e.frameCount===void 0?this.numberOfFrames-n:e.frameCount;if(r>this.numberOfFrames-n)throw RangeError(`frameCount out of range`);let i=JC(t),a=YC(t);if(a&&e.planeIndex>=this.numberOfChannels||!a&&e.planeIndex!==0)throw RangeError(`planeIndex out of range`);return(a?r:r*this.numberOfChannels)*i}copyTo(e,t){if(!Bb(e))throw TypeError(`destination must be an ArrayBuffer or an ArrayBuffer view.`);if(!t||typeof t!=`object`)throw TypeError(`options must be an object.`);if(!Number.isInteger(t.planeIndex)||t.planeIndex<0)throw TypeError(`planeIndex must be a non-negative integer.`);if(t.format!==void 0&&!KC.has(t.format))throw TypeError(`Invalid format.`);if(t.frameOffset!==void 0&&(!Number.isInteger(t.frameOffset)||t.frameOffset<0))throw TypeError(`frameOffset must be a non-negative integer.`);if(t.frameCount!==void 0&&(!Number.isInteger(t.frameCount)||t.frameCount<0))throw TypeError(`frameCount must be a non-negative integer.`);if(this._closed)throw Error(`AudioSample is closed.`);let{planeIndex:n,format:r,frameCount:i,frameOffset:a}=t,o=this.format,s=r??this.format;if(!s)throw Error(`Destination format not determined`);let c=this.numberOfFrames,l=this.numberOfChannels,u=a??0;if(u>=c)throw RangeError(`frameOffset out of range`);let d=i===void 0?c-u:i;if(d>c-u)throw RangeError(`frameCount out of range`);let f=JC(s),p=YC(s);if(p&&n>=l||!p&&n!==0)throw RangeError(`planeIndex out of range`);let m=(p?d:d*l)*f;if(e.byteLength<m)throw RangeError(`Destination buffer is too small`);let h=kb(e),g=ZC(s);if(QC(this._data))vx()&&l>2&&s!==o?$C(this._data,h,o,s,l,n,u,d):this._data.copyTo(e,{planeIndex:n,frameOffset:u,frameCount:d,format:s});else{let e=this._data,t=kb(e),r=XC(o),i=JC(o),a=YC(o);for(let e=0;e<d;e++)if(p){let o=e*f,s;s=a?(n*c+(e+u))*i:((e+u)*l+n)*i,g(h,o,r(t,s))}else for(let n=0;n<l;n++){let o=(e*l+n)*f,s;s=a?(n*c+(e+u))*i:((e+u)*l+n)*i,g(h,o,r(t,s))}}}clone(){if(this._closed)throw Error(`AudioSample is closed.`);if(QC(this._data)){let t=new e(this._data.clone());return t.setTimestamp(this.timestamp),t}else return new e({format:this.format,sampleRate:this.sampleRate,numberOfFrames:this.numberOfFrames,numberOfChannels:this.numberOfChannels,timestamp:this.timestamp,data:this._data})}close(){this._closed||=(FC?.unregister(this),QC(this._data)?this._data.close():this._data=new Uint8Array,!0)}toAudioData(){if(this._closed)throw Error(`AudioSample is closed.`);if(QC(this._data)){if(this._data.timestamp===this.microsecondTimestamp)return this._data.clone();if(YC(this.format)){let e=this.allocationSize({planeIndex:0,format:this.format}),t=new ArrayBuffer(e*this.numberOfChannels);for(let n=0;n<this.numberOfChannels;n++)this.copyTo(new Uint8Array(t,n*e,e),{planeIndex:n,format:this.format});return new AudioData({format:this.format,sampleRate:this.sampleRate,numberOfFrames:this.numberOfFrames,numberOfChannels:this.numberOfChannels,timestamp:this.microsecondTimestamp,data:t})}else{let e=new ArrayBuffer(this.allocationSize({planeIndex:0,format:this.format}));return this.copyTo(e,{planeIndex:0,format:this.format}),new AudioData({format:this.format,sampleRate:this.sampleRate,numberOfFrames:this.numberOfFrames,numberOfChannels:this.numberOfChannels,timestamp:this.microsecondTimestamp,data:e})}}else return new AudioData({format:this.format,sampleRate:this.sampleRate,numberOfFrames:this.numberOfFrames,numberOfChannels:this.numberOfChannels,timestamp:this.microsecondTimestamp,data:this._data.buffer instanceof ArrayBuffer?this._data.buffer:this._data.slice()})}toAudioBuffer(){if(this._closed)throw Error(`AudioSample is closed.`);let e=new AudioBuffer({numberOfChannels:this.numberOfChannels,length:this.numberOfFrames,sampleRate:this.sampleRate}),t=new Float32Array(this.allocationSize({planeIndex:0,format:`f32-planar`})/4);for(let n=0;n<this.numberOfChannels;n++)this.copyTo(t,{planeIndex:n,format:`f32-planar`}),e.copyToChannel(t,n);return e}setTimestamp(e){if(!Number.isFinite(e))throw TypeError(`newTimestamp must be a number.`);this.timestamp=e}[Symbol.dispose](){this.close()}static*_fromAudioBuffer(t,n){if(!(t instanceof AudioBuffer))throw TypeError(`audioBuffer must be an AudioBuffer.`);let r=t.numberOfChannels,i=t.sampleRate,a=t.length,o=Math.floor(24e4/r),s=0,c=a;for(;c>0;){let a=Math.min(o,c),l=new Float32Array(r*a);for(let e=0;e<r;e++)t.copyFromChannel(l.subarray(e*a,(e+1)*a),e,s);yield new e({format:`f32-planar`,sampleRate:i,numberOfFrames:a,numberOfChannels:r,timestamp:n+s/i,data:l}),s+=a,c-=a}}static fromAudioBuffer(t,n){if(!(t instanceof AudioBuffer))throw TypeError(`audioBuffer must be an AudioBuffer.`);let r=t.numberOfChannels,i=t.sampleRate,a=t.length,o=Math.floor(24e4/r),s=0,c=a,l=[];for(;c>0;){let a=Math.min(o,c),u=new Float32Array(r*a);for(let e=0;e<r;e++)t.copyFromChannel(u.subarray(e*a,(e+1)*a),e,s);let d=new e({format:`f32-planar`,sampleRate:i,numberOfFrames:a,numberOfChannels:r,timestamp:n+s/i,data:u});l.push(d),s+=a,c-=a}return l}},JC=e=>{switch(e){case`u8`:case`u8-planar`:return 1;case`s16`:case`s16-planar`:return 2;case`s32`:case`s32-planar`:return 4;case`f32`:case`f32-planar`:return 4;default:throw Error(`Unknown AudioSampleFormat`)}},YC=e=>{switch(e){case`u8-planar`:case`s16-planar`:case`s32-planar`:case`f32-planar`:return!0;default:return!1}},XC=e=>{switch(e){case`u8`:case`u8-planar`:return(e,t)=>(e.getUint8(t)-128)/128;case`s16`:case`s16-planar`:return(e,t)=>e.getInt16(t,!0)/32768;case`s32`:case`s32-planar`:return(e,t)=>e.getInt32(t,!0)/2147483648;case`f32`:case`f32-planar`:return(e,t)=>e.getFloat32(t,!0)}},ZC=e=>{switch(e){case`u8`:case`u8-planar`:return(e,t,n)=>e.setUint8(t,ix((n+1)*127.5,0,255));case`s16`:case`s16-planar`:return(e,t,n)=>e.setInt16(t,ix(Math.round(n*32767),-32768,32767),!0);case`s32`:case`s32-planar`:return(e,t,n)=>e.setInt32(t,ix(Math.round(n*2147483647),-2147483648,2147483647),!0);case`f32`:case`f32-planar`:return(e,t,n)=>e.setFloat32(t,n,!0)}},QC=e=>typeof AudioData<`u`&&e instanceof AudioData,$C=(e,t,n,r,i,a,o,s)=>{let c=XC(n),l=ZC(r),u=JC(n),d=JC(r),f=YC(n);if(YC(r))if(f){let r=new ArrayBuffer(s*u),i=kb(r);e.copyTo(r,{planeIndex:a,frameOffset:o,frameCount:s,format:n});for(let e=0;e<s;e++){let n=e*u;l(t,e*d,c(i,n))}}else{let r=new ArrayBuffer(s*i*u),f=kb(r);e.copyTo(r,{planeIndex:0,frameOffset:o,frameCount:s,format:n});for(let e=0;e<s;e++){let n=(e*i+a)*u;l(t,e*d,c(f,n))}}else if(f){let r=s*u,a=new ArrayBuffer(r),f=kb(a);for(let r=0;r<i;r++){e.copyTo(a,{planeIndex:r,frameOffset:o,frameCount:s,format:n});for(let e=0;e<s;e++){let n=e*u;l(t,(e*i+r)*d,c(f,n))}}}else{let r=new ArrayBuffer(s*i*u),a=kb(r);e.copyTo(r,{planeIndex:0,frameOffset:o,frameCount:s,format:n});for(let e=0;e<s;e++)for(let n=0;n<i;n++){let r=e*i+n,o=r*u;l(t,r*d,c(a,o))}}},ew=e=>{if(!e||typeof e!=`object`)throw TypeError(`options must be an object.`);if(e.metadataOnly!==void 0&&typeof e.metadataOnly!=`boolean`)throw TypeError(`options.metadataOnly, when defined, must be a boolean.`);if(e.verifyKeyPackets!==void 0&&typeof e.verifyKeyPackets!=`boolean`)throw TypeError(`options.verifyKeyPackets, when defined, must be a boolean.`);if(e.verifyKeyPackets&&e.metadataOnly)throw TypeError(`options.verifyKeyPackets and options.metadataOnly cannot be enabled together.`)},tw=e=>{if(!Ax(e))throw TypeError(`timestamp must be a number.`)},nw=(e,t,n)=>n.verifyKeyPackets?t.then(async t=>{if(!t||t.type===`delta`)return t;let n=await e.determinePacketType(t);return n&&(t.type=n),t}):t,rw=class{constructor(e){if(!(e instanceof hw))throw TypeError(`track must be an InputTrack.`);this._track=e}getFirstPacket(e={}){if(ew(e),this._track.input._disposed)throw new DE;return nw(this._track,this._track._backing.getFirstPacket(e),e)}async getFirstKeyPacket(e={}){ew(e);let t=await this.getFirstPacket(e);return t?t.type===`key`?t:this.getNextKeyPacket(t,e):null}getPacket(e,t={}){if(tw(e),ew(t),this._track.input._disposed)throw new DE;return nw(this._track,this._track._backing.getPacket(e,t),t)}getNextPacket(e,t={}){if(!(e instanceof OC))throw TypeError(`packet must be an EncodedPacket.`);if(ew(t),this._track.input._disposed)throw new DE;return nw(this._track,this._track._backing.getNextPacket(e,t),t)}async getKeyPacket(e,t={}){if(tw(e),ew(t),this._track.input._disposed)throw new DE;if(!t.verifyKeyPackets)return this._track._backing.getKeyPacket(e,t);let n=await this._track._backing.getKeyPacket(e,t);return n&&(J(n.type===`key`),await this._track.determinePacketType(n)===`delta`?this.getKeyPacket(n.timestamp-1/this._track.timeResolution,t):n)}async getNextKeyPacket(e,t={}){if(!(e instanceof OC))throw TypeError(`packet must be an EncodedPacket.`);if(ew(t),this._track.input._disposed)throw new DE;if(!t.verifyKeyPackets)return this._track._backing.getNextKeyPacket(e,t);let n=await this._track._backing.getNextKeyPacket(e,t);return n&&(J(n.type===`key`),await this._track.determinePacketType(n)===`delta`?this.getNextKeyPacket(n,t):n)}packets(e,t,n={}){if(e!==void 0&&!(e instanceof OC))throw TypeError(`startPacket must be an EncodedPacket.`);if(e!==void 0&&e.isMetadataOnly&&!n?.metadataOnly)throw TypeError(`startPacket can only be metadata-only if options.metadataOnly is enabled.`);if(t!==void 0&&!(t instanceof OC))throw TypeError(`endPacket must be an EncodedPacket.`);if(ew(n),this._track.input._disposed)throw new DE;let r=[],{promise:i,resolve:a}=qb(),{promise:o,resolve:s}=qb(),c=!1,l=!1,u=null,d=[],f=()=>Math.max(2,d.length);(async()=>{let u=e??await this.getFirstPacket(n);for(;u&&!l&&!this._track.input._disposed&&!(t&&u.sequenceNumber>=t?.sequenceNumber);){if(r.length>f()){({promise:o,resolve:s}=qb()),await o;continue}r.push(u),a(),{promise:i,resolve:a}=qb(),u=await this.getNextPacket(u,n)}c=!0,a()})().catch(e=>{u||(u=e,a())});let p=this._track;return{async next(){for(;;)if(p.input._disposed)throw new DE;else if(l)return{value:void 0,done:!0};else if(u)throw u;else if(r.length>0){let e=r.shift(),t=performance.now();for(d.push(t);d.length>0&&t-d[0]>=1e3;)d.shift();return s(),{value:e,done:!1}}else if(c)return{value:void 0,done:!0};else await i},async return(){return l=!0,s(),a(),{value:void 0,done:!0}},async throw(e){throw e},[Symbol.asyncIterator](){return this}}}},iw=class{constructor(e,t){this.onSample=e,this.onError=t}},aw=class{mediaSamplesInRange(e=0,t=1/0){tw(e),tw(t);let n=[],r=!1,i=null,{promise:a,resolve:o}=qb(),{promise:s,resolve:c}=qb(),l=!1,u=!1,d=!1,f=null;(async()=>{let p=await this._createDecoder(s=>{if(c(),s.timestamp>=t&&(u=!0),u){s.close();return}i&&(s.timestamp>e?(n.push(i),r=!0):i.close()),s.timestamp>=e&&(n.push(s),r=!0),i=r?null:s,n.length>0&&(o(),{promise:a,resolve:o}=qb())},e=>{f||(f=e,o())}),m=this._createPacketSink(),h=await m.getKeyPacket(e,{verifyKeyPackets:!0})??await m.getFirstKeyPacket({verifyKeyPackets:!0}),g=h,_=m.packets(h??void 0,void 0);for(await _.next();g&&!u&&!this._track.input._disposed;){let e=ow(n.length);if(n.length+p.getDecodeQueueSize()>e){({promise:s,resolve:c}=qb()),await s;continue}p.decode(g);let t=await _.next();if(t.done)break;g=t.value}await _.return(),!d&&!this._track.input._disposed&&await p.flush(),p.close(),!r&&i&&n.push(i),l=!0,o()})().catch(e=>{f||(f=e,o())});let p=this._track,m=()=>{i?.close();for(let e of n)e.close()};return{async next(){for(;;)if(p.input._disposed)throw m(),new DE;else if(d)return{value:void 0,done:!0};else if(f)throw m(),f;else if(n.length>0){let e=n.shift();return c(),{value:e,done:!1}}else if(!l)await a;else return{value:void 0,done:!0}},async return(){return d=!0,u=!0,c(),o(),m(),{value:void 0,done:!0}},async throw(e){throw e},[Symbol.asyncIterator](){return this}}}mediaSamplesAtTimestamps(e){Zb(e);let t=Xb(e),n=[],r=[],{promise:i,resolve:a}=qb(),{promise:o,resolve:s}=qb(),c=!1,l=!1,u=null,d=e=>{r.push(e),a(),{promise:i,resolve:a}=qb()};(async()=>{let e=await this._createDecoder(e=>{if(s(),l){e.close();return}let t=0;for(;n.length>0&&e.timestamp-n[0]>-1e-10;)t++,n.shift();if(t>0)for(let n=0;n<t;n++)d(n<t-1?e.clone():e);else e.close()},e=>{u||(u=e,a())}),i=this._createPacketSink(),f=null,p=null,m=-1,h=async()=>{J(p);let t=p;for(e.decode(t);t.sequenceNumber<m;){let n=ow(r.length);for(;r.length+e.getDecodeQueueSize()>n&&!l;)({promise:o,resolve:s}=qb()),await o;if(l)break;let a=await i.getNextPacket(t);J(a),e.decode(a),t=a}m=-1},g=async()=>{await e.flush();for(let e=0;e<n.length;e++)d(null);n.length=0};for await(let e of t){if(tw(e),l||this._track.input._disposed)break;let t=await i.getPacket(e),r=t&&await i.getKeyPacket(e,{verifyKeyPackets:!0});if(!r){m!==-1&&(await h(),await g()),d(null),f=null;continue}f&&(r.sequenceNumber!==p.sequenceNumber||t.timestamp<f.timestamp)&&(await h(),await g()),n.push(t.timestamp),m=Math.max(t.sequenceNumber,m),f=t,p=r}!l&&!this._track.input._disposed&&(m!==-1&&await h(),await g()),e.close(),c=!0,a()})().catch(e=>{u||(u=e,a())});let f=this._track,p=()=>{for(let e of r)e?.close()};return{async next(){for(;;)if(f.input._disposed)throw p(),new DE;else if(l)return{value:void 0,done:!0};else if(u)throw p(),u;else if(r.length>0){let e=r.shift();return J(e!==void 0),s(),{value:e,done:!1}}else if(!c)await i;else return{value:void 0,done:!0}},async return(){return l=!0,s(),a(),p(),{value:void 0,done:!0}},async throw(e){throw e},[Symbol.asyncIterator](){return this}}}},ow=e=>e===0?40:8,sw=class extends iw{constructor(e,t,n,r,i,a){super(e,t),this.codec=n,this.decoderConfig=r,this.rotation=i,this.timeResolution=a,this.decoder=null,this.customDecoder=null,this.customDecoderCallSerializer=new gx,this.customDecoderQueueSize=0,this.inputTimestamps=[],this.sampleQueue=[],this.currentPacketIndex=0,this.raslSkipped=!1,this.alphaDecoder=null,this.alphaHadKeyframe=!1,this.colorQueue=[],this.alphaQueue=[],this.merger=null,this.mergerCreationFailed=!1,this.decodedAlphaChunkCount=0,this.alphaDecoderQueueSize=0,this.nullAlphaFrameQueue=[],this.currentAlphaPacketIndex=0,this.alphaRaslSkipped=!1;let o=CC.find(e=>e.supports(n,r));if(o)this.customDecoder=new o,this.customDecoder.codec=n,this.customDecoder.config=r,this.customDecoder.onSample=e=>{if(!(e instanceof RC))throw TypeError(`The argument passed to onSample must be a VideoSample.`);this.finalizeAndEmitSample(e)},this.customDecoderCallSerializer.call(()=>this.customDecoder.init());else{let e=e=>{if(this.alphaQueue.length>0){let t=this.alphaQueue.shift();J(t!==void 0),this.mergeAlpha(e,t)}else this.colorQueue.push(e)};if(n===`avc`&&this.decoderConfig.description&&Sx()){let e=VS(Ob(this.decoderConfig.description));if(e&&e.sequenceParameterSets.length>0){let t=US(e.sequenceParameterSets[0]);t&&t.frameMbsOnlyFlag===0&&(this.decoderConfig={...this.decoderConfig,hardwareAcceleration:`prefer-software`})}}let t=Error(`Decoding error`).stack;this.decoder=new VideoDecoder({output:t=>{try{e(t)}catch(e){this.onError(e)}},error:e=>{e.stack=t,this.onError(e)}}),this.decoder.configure(this.decoderConfig)}}getDecodeQueueSize(){return this.customDecoder?this.customDecoderQueueSize:(J(this.decoder),Math.max(this.decoder.decodeQueueSize,this.alphaDecoder?.decodeQueueSize??0))}decode(e){if(this.codec===`hevc`&&this.currentPacketIndex>0&&!this.raslSkipped){if(this.hasHevcRaslPicture(e.data))return;this.raslSkipped=!0}if(this.customDecoder)this.customDecoderQueueSize++,this.customDecoderCallSerializer.call(()=>this.customDecoder.decode(e)).then(()=>this.customDecoderQueueSize--);else{if(J(this.decoder),vx()||Kb(this.inputTimestamps,e.timestamp,e=>e),Sx()&&this.currentPacketIndex===0&&this.codec===`avc`){let t=[];for(let n of MS(e.data,this.decoderConfig)){let r=NS(e.data[n.offset]);r>=20&&r<=31||t.push(e.data.subarray(n.offset,n.offset+n.length))}e=new OC(RS(t,this.decoderConfig),e.type,e.timestamp,e.duration)}this.decoder.decode(e.toEncodedVideoChunk()),this.decodeAlphaData(e)}this.currentPacketIndex++}decodeAlphaData(e){if(!e.sideData.alpha||this.mergerCreationFailed){this.pushNullAlphaFrame();return}if(!this.merger)try{this.merger=new cw}catch(t){console.error(`Due to an error, only color data will be decoded.`,t),this.mergerCreationFailed=!0,this.decodeAlphaData(e);return}if(!this.alphaDecoder){let e=e=>{if(this.alphaDecoderQueueSize--,this.colorQueue.length>0){let t=this.colorQueue.shift();J(t!==void 0),this.mergeAlpha(t,e)}else this.alphaQueue.push(e);for(this.decodedAlphaChunkCount++;this.nullAlphaFrameQueue.length>0&&this.nullAlphaFrameQueue[0]===this.decodedAlphaChunkCount;)if(this.nullAlphaFrameQueue.shift(),this.colorQueue.length>0){let e=this.colorQueue.shift();J(e!==void 0),this.mergeAlpha(e,null)}else this.alphaQueue.push(null)},t=Error(`Decoding error`).stack;this.alphaDecoder=new VideoDecoder({output:t=>{try{e(t)}catch(e){this.onError(e)}},error:e=>{e.stack=t,this.onError(e)}}),this.alphaDecoder.configure(this.decoderConfig)}let t=uC(this.codec,this.decoderConfig,e.sideData.alpha);if(this.alphaHadKeyframe||=t===`key`,this.alphaHadKeyframe){if(this.codec===`hevc`&&this.currentAlphaPacketIndex>0&&!this.alphaRaslSkipped){if(this.hasHevcRaslPicture(e.sideData.alpha)){this.pushNullAlphaFrame();return}this.alphaRaslSkipped=!0}this.currentAlphaPacketIndex++,this.alphaDecoder.decode(e.alphaToEncodedVideoChunk(t??e.type)),this.alphaDecoderQueueSize++}else this.pushNullAlphaFrame()}pushNullAlphaFrame(){this.alphaDecoderQueueSize===0?this.alphaQueue.push(null):this.nullAlphaFrameQueue.push(this.decodedAlphaChunkCount+this.alphaDecoderQueueSize)}hasHevcRaslPicture(e){for(let t of GS(e,this.decoderConfig)){let n=KS(e[t.offset]);if(n===kS.RASL_N||n===kS.RASL_R)return!0}return!1}sampleHandler(e){if(vx()){if(this.sampleQueue.length>0&&e.timestamp>=Tb(this.sampleQueue).timestamp){for(let e of this.sampleQueue)this.finalizeAndEmitSample(e);this.sampleQueue.length=0}Kb(this.sampleQueue,e,e=>e.timestamp)}else{let t=this.inputTimestamps.shift();J(t!==void 0),e.setTimestamp(t),this.finalizeAndEmitSample(e)}}finalizeAndEmitSample(e){e.setTimestamp(Math.round(e.timestamp*this.timeResolution)/this.timeResolution),e.setDuration(Math.round(e.duration*this.timeResolution)/this.timeResolution),e.setRotation(this.rotation),this.onSample(e)}mergeAlpha(e,t){if(!t){let t=new RC(e);this.sampleHandler(t);return}J(this.merger),this.merger.update(e,t),e.close(),t.close();let n=new RC(new VideoFrame(this.merger.canvas,{timestamp:e.timestamp,duration:e.duration??void 0}));this.sampleHandler(n)}async flush(){if(this.customDecoder?await this.customDecoderCallSerializer.call(()=>this.customDecoder.flush()):(J(this.decoder),await Promise.all([this.decoder.flush(),this.alphaDecoder?.flush()]),this.colorQueue.forEach(e=>e.close()),this.colorQueue.length=0,this.alphaQueue.forEach(e=>e?.close()),this.alphaQueue.length=0,this.alphaHadKeyframe=!1,this.decodedAlphaChunkCount=0,this.alphaDecoderQueueSize=0,this.nullAlphaFrameQueue.length=0,this.currentAlphaPacketIndex=0,this.alphaRaslSkipped=!1),vx()){for(let e of this.sampleQueue)this.finalizeAndEmitSample(e);this.sampleQueue.length=0}this.currentPacketIndex=0,this.raslSkipped=!1}close(){this.customDecoder?this.customDecoderCallSerializer.call(()=>this.customDecoder.close()):(J(this.decoder),this.decoder.close(),this.alphaDecoder?.close(),this.colorQueue.forEach(e=>e.close()),this.colorQueue.length=0,this.alphaQueue.forEach(e=>e?.close()),this.alphaQueue.length=0,this.merger?.close());for(let e of this.sampleQueue)e.close();this.sampleQueue.length=0}},cw=class{w=0;h=0;colorImageData=null;alphaImageData=null;constructor(){typeof OffscreenCanvas<`u`?(this.canvas=new OffscreenCanvas(1,1),this.alphaCanvas=new OffscreenCanvas(1,1)):(this.canvas=document.createElement(`canvas`),this.alphaCanvas=document.createElement(`canvas`));let e=this.canvas.getContext(`2d`,{alpha:!0,willReadFrequently:!0}),t=this.alphaCanvas.getContext(`2d`,{alpha:!0,willReadFrequently:!0});if(!e||!t)throw Error(`Couldn't acquire 2D canvas context.`);this.ctx=e,this.alphaCtx=t}update(e,t){let n=e.displayWidth,r=e.displayHeight;(n!==this.w||r!==this.h)&&(this.w=n,this.h=r,this.canvas.width=n,this.canvas.height=r,this.alphaCanvas.width=n,this.alphaCanvas.height=r,this.colorImageData=this.ctx.createImageData(n,r),this.alphaImageData=this.ctx.createImageData(n,r)),this.ctx.drawImage(e,0,0,n,r),this.alphaCtx.drawImage(t,0,0,n,r);let i=this.ctx.getImageData(0,0,n,r,{colorSpace:`srgb`}),a=this.alphaCtx.getImageData(0,0,n,r,{colorSpace:`srgb`}),o=new Uint32Array(i.data.buffer),s=new Uint32Array(a.data.buffer),c=o.length;for(let e=0;e<c;e++)o[e]=o[e]&16777215|(s[e]&255)<<24;this.ctx.putImageData(i,0,0)}close(){this.ctx=null,this.alphaCtx=null,this.colorImageData=null,this.alphaImageData=null}},lw=class extends aw{constructor(e){if(!(e instanceof gw))throw TypeError(`videoTrack must be an InputVideoTrack.`);super(),this._track=e}async _createDecoder(e,t){if(!await this._track.canDecode())throw Error(`This video track cannot be decoded by this browser. Make sure to check decodability before using a track.`);let n=this._track.codec,r=this._track.rotation,i=await this._track.getDecoderConfig(),a=this._track.timeResolution;return J(n&&i),new sw(e,t,n,i,r,a)}_createPacketSink(){return new rw(this._track)}async getSample(e){tw(e);for await(let t of this.mediaSamplesAtTimestamps([e]))return t;throw Error(`Internal error: Iterator returned nothing.`)}samples(e=0,t=1/0){return this.mediaSamplesInRange(e,t)}samplesAtTimestamps(e){return this.mediaSamplesAtTimestamps(e)}},uw=class{constructor(e,t={}){if(this._nextCanvasIndex=0,!(e instanceof gw))throw TypeError(`videoTrack must be an InputVideoTrack.`);if(t&&typeof t!=`object`)throw TypeError(`options must be an object.`);if(t.alpha!==void 0&&typeof t.alpha!=`boolean`)throw TypeError(`options.alpha, when provided, must be a boolean.`);if(t.width!==void 0&&(!Number.isInteger(t.width)||t.width<=0))throw TypeError(`options.width, when defined, must be a positive integer.`);if(t.height!==void 0&&(!Number.isInteger(t.height)||t.height<=0))throw TypeError(`options.height, when defined, must be a positive integer.`);if(t.fit!==void 0&&![`fill`,`contain`,`cover`].includes(t.fit))throw TypeError(`options.fit, when provided, must be one of "fill", "contain", or "cover".`);if(t.width!==void 0&&t.height!==void 0&&t.fit===void 0)throw TypeError(`When both options.width and options.height are provided, options.fit must also be provided.`);if(t.rotation!==void 0&&![0,90,180,270].includes(t.rotation))throw TypeError(`options.rotation, when provided, must be 0, 90, 180 or 270.`);if(t.crop!==void 0&&HC(t.crop,`options.`),t.poolSize!==void 0&&(typeof t.poolSize!=`number`||!Number.isInteger(t.poolSize)||t.poolSize<0))throw TypeError(`poolSize must be a non-negative integer.`);let n=t.rotation??e.rotation,[r,i]=n%180==0?[e.squarePixelWidth,e.squarePixelHeight]:[e.squarePixelHeight,e.squarePixelWidth],a=t.crop;a&&VC(a,r,i);let[o,s]=a?[a.width,a.height]:[r,i],c=o/s;t.width!==void 0&&t.height===void 0?(o=t.width,s=Math.round(o/c)):t.width===void 0&&t.height!==void 0?(s=t.height,o=Math.round(s*c)):t.width!==void 0&&t.height!==void 0&&(o=t.width,s=t.height),this._videoTrack=e,this._alpha=t.alpha??!1,this._width=o,this._height=s,this._rotation=n,this._crop=a,this._fit=t.fit??`fill`,this._videoSampleSink=new lw(e),this._canvasPool=Array.from({length:t.poolSize??0},()=>null)}_videoSampleToWrappedCanvas(e){let t=this._canvasPool[this._nextCanvasIndex],n=!1;t||(typeof document<`u`?(t=document.createElement(`canvas`),t.width=this._width,t.height=this._height):t=new OffscreenCanvas(this._width,this._height),this._canvasPool.length>0&&(this._canvasPool[this._nextCanvasIndex]=t),n=!0),this._canvasPool.length>0&&(this._nextCanvasIndex=(this._nextCanvasIndex+1)%this._canvasPool.length);let r=t.getContext(`2d`,{alpha:this._alpha||bx()});J(r),r.resetTransform(),n||(!this._alpha&&bx()?(r.fillStyle=`black`,r.fillRect(0,0,this._width,this._height)):r.clearRect(0,0,this._width,this._height)),e.drawWithFit(r,{fit:this._fit,rotation:this._rotation,crop:this._crop});let i={canvas:t,timestamp:e.timestamp,duration:e.duration};return e.close(),i}async getCanvas(e){tw(e);let t=await this._videoSampleSink.getSample(e);return t&&this._videoSampleToWrappedCanvas(t)}canvases(e=0,t=1/0){return rx(this._videoSampleSink.samples(e,t),e=>this._videoSampleToWrappedCanvas(e))}canvasesAtTimestamps(e){return rx(this._videoSampleSink.samplesAtTimestamps(e),e=>e&&this._videoSampleToWrappedCanvas(e))}},dw=class extends iw{constructor(e,t,n,r){super(e,t),this.decoder=null,this.customDecoder=null,this.customDecoderCallSerializer=new gx,this.customDecoderQueueSize=0,this.currentTimestamp=null;let i=t=>{(this.currentTimestamp===null||Math.abs(t.timestamp-this.currentTimestamp)>=t.duration)&&(this.currentTimestamp=t.timestamp);let n=this.currentTimestamp;if(this.currentTimestamp+=t.duration,t.numberOfFrames===0){t.close();return}let i=r.sampleRate;t.setTimestamp(Math.round(n*i)/i),e(t)},a=wC.find(e=>e.supports(n,r));if(a)this.customDecoder=new a,this.customDecoder.codec=n,this.customDecoder.config=r,this.customDecoder.onSample=e=>{if(!(e instanceof qC))throw TypeError(`The argument passed to onSample must be an AudioSample.`);i(e)},this.customDecoderCallSerializer.call(()=>this.customDecoder.init());else{let e=Error(`Decoding error`).stack;this.decoder=new AudioDecoder({output:e=>{try{i(new qC(e))}catch(e){this.onError(e)}},error:t=>{t.stack=e,this.onError(t)}}),this.decoder.configure(r)}}getDecodeQueueSize(){return this.customDecoder?this.customDecoderQueueSize:(J(this.decoder),this.decoder.decodeQueueSize)}decode(e){this.customDecoder?(this.customDecoderQueueSize++,this.customDecoderCallSerializer.call(()=>this.customDecoder.decode(e)).then(()=>this.customDecoderQueueSize--)):(J(this.decoder),this.decoder.decode(e.toEncodedAudioChunk()))}flush(){return this.customDecoder?this.customDecoderCallSerializer.call(()=>this.customDecoder.flush()):(J(this.decoder),this.decoder.flush())}close(){this.customDecoder?this.customDecoderCallSerializer.call(()=>this.customDecoder.close()):(J(this.decoder),this.decoder.close())}},fw=class extends iw{constructor(e,t,n){super(e,t),this.decoderConfig=n,this.currentTimestamp=null,J(Wx.includes(n.codec)),this.codec=n.codec;let{dataType:r,sampleSize:i,littleEndian:a}=sS(this.codec);switch(this.inputSampleSize=i,i){case 1:r===`unsigned`?this.readInputValue=(e,t)=>e.getUint8(t)-2**7:r===`signed`?this.readInputValue=(e,t)=>e.getInt8(t):r===`ulaw`?this.readInputValue=(e,t)=>AC(e.getUint8(t)):r===`alaw`?this.readInputValue=(e,t)=>MC(e.getUint8(t)):J(!1);break;case 2:r===`unsigned`?this.readInputValue=(e,t)=>e.getUint16(t,a)-2**15:r===`signed`?this.readInputValue=(e,t)=>e.getInt16(t,a):J(!1);break;case 3:r===`unsigned`?this.readInputValue=(e,t)=>$b(e,t,a)-2**23:r===`signed`?this.readInputValue=(e,t)=>ex(e,t,a):J(!1);break;case 4:r===`unsigned`?this.readInputValue=(e,t)=>e.getUint32(t,a)-2**31:r===`signed`?this.readInputValue=(e,t)=>e.getInt32(t,a):r===`float`?this.readInputValue=(e,t)=>e.getFloat32(t,a):J(!1);break;case 8:r===`float`?this.readInputValue=(e,t)=>e.getFloat64(t,a):J(!1);break;default:Qb(i),J(!1)}switch(i){case 1:r===`ulaw`||r===`alaw`?(this.outputSampleSize=2,this.outputFormat=`s16`,this.writeOutputValue=(e,t,n)=>e.setInt16(t,n,!0)):(this.outputSampleSize=1,this.outputFormat=`u8`,this.writeOutputValue=(e,t,n)=>e.setUint8(t,n+2**7));break;case 2:this.outputSampleSize=2,this.outputFormat=`s16`,this.writeOutputValue=(e,t,n)=>e.setInt16(t,n,!0);break;case 3:this.outputSampleSize=4,this.outputFormat=`s32`,this.writeOutputValue=(e,t,n)=>e.setInt32(t,n<<8,!0);break;case 4:this.outputSampleSize=4,r===`float`?(this.outputFormat=`f32`,this.writeOutputValue=(e,t,n)=>e.setFloat32(t,n,!0)):(this.outputFormat=`s32`,this.writeOutputValue=(e,t,n)=>e.setInt32(t,n,!0));break;case 8:this.outputSampleSize=4,this.outputFormat=`f32`,this.writeOutputValue=(e,t,n)=>e.setFloat32(t,n,!0);break;default:Qb(i),J(!1)}}getDecodeQueueSize(){return 0}decode(e){let t=kb(e.data),n=e.byteLength/this.decoderConfig.numberOfChannels/this.inputSampleSize,r=n*this.decoderConfig.numberOfChannels*this.outputSampleSize,i=new ArrayBuffer(r),a=new DataView(i);for(let e=0;e<n*this.decoderConfig.numberOfChannels;e++){let n=e*this.inputSampleSize,r=e*this.outputSampleSize,i=this.readInputValue(t,n);this.writeOutputValue(a,r,i)}let o=n/this.decoderConfig.sampleRate;(this.currentTimestamp===null||Math.abs(e.timestamp-this.currentTimestamp)>=o)&&(this.currentTimestamp=e.timestamp);let s=this.currentTimestamp;this.currentTimestamp+=o;let c=new qC({format:this.outputFormat,data:i,numberOfChannels:this.decoderConfig.numberOfChannels,sampleRate:this.decoderConfig.sampleRate,numberOfFrames:n,timestamp:s});this.onSample(c)}async flush(){}close(){}},pw=class extends aw{constructor(e){if(!(e instanceof _w))throw TypeError(`audioTrack must be an InputAudioTrack.`);super(),this._track=e}async _createDecoder(e,t){if(!await this._track.canDecode())throw Error(`This audio track cannot be decoded by this browser. Make sure to check decodability before using a track.`);let n=this._track.codec,r=await this._track.getDecoderConfig();return J(n&&r),Wx.includes(r.codec)?new fw(e,t,r):new dw(e,t,n,r)}_createPacketSink(){return new rw(this._track)}async getSample(e){tw(e);for await(let t of this.mediaSamplesAtTimestamps([e]))return t;throw Error(`Internal error: Iterator returned nothing.`)}samples(e=0,t=1/0){return this.mediaSamplesInRange(e,t)}samplesAtTimestamps(e){return this.mediaSamplesAtTimestamps(e)}},mw=class{constructor(e){if(!(e instanceof _w))throw TypeError(`audioTrack must be an InputAudioTrack.`);this._audioSampleSink=new pw(e)}_audioSampleToWrappedArrayBuffer(e){let t={buffer:e.toAudioBuffer(),timestamp:e.timestamp,duration:e.duration};return e.close(),t}async getBuffer(e){tw(e);let t=await this._audioSampleSink.getSample(e);return t&&this._audioSampleToWrappedArrayBuffer(t)}buffers(e=0,t=1/0){return rx(this._audioSampleSink.samples(e,t),e=>this._audioSampleToWrappedArrayBuffer(e))}buffersAtTimestamps(e){return rx(this._audioSampleSink.samplesAtTimestamps(e),e=>e&&this._audioSampleToWrappedArrayBuffer(e))}},hw=class{constructor(e,t){this.input=e,this._backing=t}isVideoTrack(){return this instanceof gw}isAudioTrack(){return this instanceof _w}get id(){return this._backing.getId()}get number(){return this._backing.getNumber()}get internalCodecId(){return this._backing.getInternalCodecId()}get languageCode(){return this._backing.getLanguageCode()}get name(){return this._backing.getName()}get timeResolution(){return this._backing.getTimeResolution()}get disposition(){return this._backing.getDisposition()}getFirstTimestamp(){return this._backing.getFirstTimestamp()}computeDuration(){return this._backing.computeDuration()}async computePacketStats(e=1/0){let t=new rw(this),n=1/0,r=-1/0,i=0,a=0;for await(let o of t.packets(void 0,void 0,{metadataOnly:!0})){if(i>=e&&o.timestamp>=r)break;n=Math.min(n,o.timestamp),r=Math.max(r,o.timestamp+o.duration),i++,a+=o.byteLength}return{packetCount:i,averagePacketRate:i?Number((i/(r-n)).toPrecision(16)):0,averageBitrate:i?Number((8*a/(r-n)).toPrecision(16)):0}}},gw=class extends hw{constructor(e,t){super(e,t),this._backing=t,this.pixelAspectRatio=jx({num:this._backing.getSquarePixelWidth()*this._backing.getCodedHeight(),den:this._backing.getSquarePixelHeight()*this._backing.getCodedWidth()})}get type(){return`video`}get codec(){return this._backing.getCodec()}get codedWidth(){return this._backing.getCodedWidth()}get codedHeight(){return this._backing.getCodedHeight()}get rotation(){return this._backing.getRotation()}get squarePixelWidth(){return this._backing.getSquarePixelWidth()}get squarePixelHeight(){return this._backing.getSquarePixelHeight()}get displayWidth(){return this._backing.getRotation()%180==0?this.squarePixelWidth:this.squarePixelHeight}get displayHeight(){return this._backing.getRotation()%180==0?this.squarePixelHeight:this.squarePixelWidth}getColorSpace(){return this._backing.getColorSpace()}async hasHighDynamicRange(){let e=await this._backing.getColorSpace();return e.primaries===`bt2020`||e.primaries===`smpte432`||e.transfer===`pg`||e.transfer===`hlg`||e.matrix===`bt2020-ncl`}canBeTransparent(){return this._backing.canBeTransparent()}getDecoderConfig(){return this._backing.getDecoderConfig()}async getCodecParameterString(){return(await this._backing.getDecoderConfig())?.codec??null}async canDecode(){try{let e=await this._backing.getDecoderConfig();if(!e)return!1;let t=this._backing.getCodec();return J(t!==null),CC.some(n=>n.supports(t,e))?!0:typeof VideoDecoder>`u`?!1:(await VideoDecoder.isConfigSupported(e)).supported===!0}catch(e){return console.error(`Error during decodability check:`,e),!1}}async determinePacketType(e){if(!(e instanceof OC))throw TypeError(`packet must be an EncodedPacket.`);if(e.isMetadataOnly)throw TypeError(`packet must not be metadata-only to determine its type.`);if(this.codec===null)return null;let t=await this.getDecoderConfig();return J(t),uC(this.codec,t,e.data)}},_w=class extends hw{constructor(e,t){super(e,t),this._backing=t}get type(){return`audio`}get codec(){return this._backing.getCodec()}get numberOfChannels(){return this._backing.getNumberOfChannels()}get sampleRate(){return this._backing.getSampleRate()}getDecoderConfig(){return this._backing.getDecoderConfig()}async getCodecParameterString(){return(await this._backing.getDecoderConfig())?.codec??null}async canDecode(){try{let e=await this._backing.getDecoderConfig();if(!e)return!1;let t=this._backing.getCodec();return J(t!==null),wC.some(n=>n.supports(t,e))||e.codec.startsWith(`pcm-`)?!0:typeof AudioDecoder>`u`?!1:(await AudioDecoder.isConfigSupported(e)).supported===!0}catch(e){return console.error(`Error during decodability check:`,e),!1}}async determinePacketType(e){if(!(e instanceof OC))throw TypeError(`packet must be an EncodedPacket.`);return this.codec===null?null:`key`}},vw=e=>{let t=(e.hasVideo?`video/`:e.hasAudio?`audio/`:`application/`)+(e.isQuickTime?`quicktime`:`mp4`);if(e.codecStrings.length>0){let n=[...new Set(e.codecStrings)];t+=`; codecs="${n.join(`, `)}"`}return t},yw=e=>{let t=Z(e),n=qE(e,4),r=8;t===1&&(t=HE(e),r=16);let i=t-r;return i<0?null:{name:n,totalSize:t,headerSize:r,contentSize:i}},bw=e=>zE(e)/65536,xw=e=>zE(e)/1073741824,Sw=e=>{let t=0;for(let n=0;n<4;n++){t<<=7;let n=ME(e);if(t|=n&127,!(n&128))break}return t},Cw=e=>{let t=PE(e);return e.skip(2),t=Math.min(t,e.remainingLength),Ab.decode(jE(e,t))},ww=e=>{let t=yw(e);if(!t||t.name!==`data`||e.remainingLength<8)return null;let n=Z(e);e.skip(4);let r=jE(e,t.contentSize-8);switch(n){case 1:return Ab.decode(r);case 2:return new TextDecoder(`utf-16be`).decode(r);case 13:return new Nx(r,`image/jpeg`);case 14:return new Nx(r,`image/png`);case 27:return new Nx(r,`image/bmp`);default:return r}},Tw=class extends SC{constructor(e){super(e),this.moovSlice=null,this.currentTrack=null,this.tracks=[],this.metadataPromise=null,this.movieTimescale=-1,this.movieDurationInTimescale=-1,this.isQuickTime=!1,this.metadataTags={},this.currentMetadataKeys=null,this.isFragmented=!1,this.fragmentTrackDefaults=[],this.currentFragment=null,this.lastReadFragment=null,this.reader=e._reader}async computeDuration(){let e=await this.getTracks(),t=await Promise.all(e.map(e=>e.computeDuration()));return Math.max(0,...t)}async getTracks(){return await this.readMetadata(),this.tracks.map(e=>e.inputTrack)}async getMimeType(){await this.readMetadata();let e=await Promise.all(this.tracks.map(e=>e.inputTrack.getCodecParameterString()));return vw({isQuickTime:this.isQuickTime,hasVideo:this.tracks.some(e=>e.info?.type===`video`),hasAudio:this.tracks.some(e=>e.info?.type===`audio`),codecStrings:e.filter(Boolean)})}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}readMetadata(){return this.metadataPromise??=(async()=>{let e=0;for(;;){let t=this.reader.requestSliceRange(e,8,16);if(t instanceof Promise&&(t=await t),!t)break;let n=e,r=yw(t);if(!r)break;if(r.name===`ftyp`)this.isQuickTime=qE(t,4)===`qt `;else if(r.name===`moov`){let e=this.reader.requestSlice(t.filePos,r.contentSize);if(e instanceof Promise&&(e=await e),!e)break;this.moovSlice=e,this.readContiguousBoxes(this.moovSlice),this.tracks.sort((e,t)=>Number(t.disposition.default)-Number(e.disposition.default));for(let e of this.tracks){let t=e.editListPreviousSegmentDurations/this.movieTimescale;e.editListOffset-=Math.round(t*e.timescale)}break}e=n+r.totalSize}if(this.isFragmented&&this.reader.fileSize!==null){let e=this.reader.requestSlice(this.reader.fileSize-4,4);e instanceof Promise&&(e=await e),J(e);let t=Z(e),n=this.reader.fileSize-t;if(n>=0&&n<=this.reader.fileSize-16){let e=this.reader.requestSliceRange(n,8,16);if(e instanceof Promise&&(e=await e),e){let t=yw(e);if(t&&t.name===`mfra`){let n=this.reader.requestSlice(e.filePos,t.contentSize);n instanceof Promise&&(n=await n),n&&this.readContiguousBoxes(n)}}}}})()}getSampleTableForTrack(e){if(e.sampleTable)return e.sampleTable;let t={sampleTimingEntries:[],sampleCompositionTimeOffsets:[],sampleSizes:[],keySampleIndices:null,chunkOffsets:[],sampleToChunk:[],presentationTimestamps:null,presentationTimestampIndexMap:null};e.sampleTable=t,J(this.moovSlice);let n=this.moovSlice.slice(e.sampleTableByteOffset);if(this.currentTrack=e,this.traverseBox(n),this.currentTrack=null,e.info?.type===`audio`&&e.info.codec&&Wx.includes(e.info.codec)&&t.sampleCompositionTimeOffsets.length===0){J(e.info?.type===`audio`);let n=sS(e.info.codec),r=[],i=[];for(let a=0;a<t.sampleToChunk.length;a++){let o=t.sampleToChunk[a],s=t.sampleToChunk[a+1],c=(s?s.startChunkIndex:t.chunkOffsets.length)-o.startChunkIndex;for(let a=0;a<c;a++){let s=o.startSampleIndex+a*o.samplesPerChunk,c=s+o.samplesPerChunk,l=Gb(t.sampleTimingEntries,s,e=>e.startIndex),u=t.sampleTimingEntries[l],d=Gb(t.sampleTimingEntries,c,e=>e.startIndex),f=t.sampleTimingEntries[d],p=u.startDecodeTimestamp+(s-u.startIndex)*u.delta,m=f.startDecodeTimestamp+(c-f.startIndex)*f.delta-p,h=Tb(r);h&&h.delta===m?h.count++:r.push({startIndex:o.startChunkIndex+a,startDecodeTimestamp:p,count:1,delta:m});let g=o.samplesPerChunk*n.sampleSize*e.info.numberOfChannels;i.push(g)}o.startSampleIndex=o.startChunkIndex,o.samplesPerChunk=1}t.sampleTimingEntries=r,t.sampleSizes=i}if(t.sampleCompositionTimeOffsets.length>0){t.presentationTimestamps=[];for(let e of t.sampleTimingEntries)for(let n=0;n<e.count;n++)t.presentationTimestamps.push({presentationTimestamp:e.startDecodeTimestamp+n*e.delta,sampleIndex:e.startIndex+n});for(let e of t.sampleCompositionTimeOffsets)for(let n=0;n<e.count;n++){let r=e.startIndex+n,i=t.presentationTimestamps[r];i&&(i.presentationTimestamp+=e.offset)}t.presentationTimestamps.sort((e,t)=>e.presentationTimestamp-t.presentationTimestamp),t.presentationTimestampIndexMap=Array(t.presentationTimestamps.length).fill(-1);for(let e=0;e<t.presentationTimestamps.length;e++)t.presentationTimestampIndexMap[t.presentationTimestamps[e].sampleIndex]=e}return t}async readFragment(e){if(this.lastReadFragment?.moofOffset===e)return this.lastReadFragment;let t=this.reader.requestSliceRange(e,8,16);t instanceof Promise&&(t=await t),J(t);let n=yw(t);J(n?.name===`moof`);let r=this.reader.requestSlice(e,n.totalSize);r instanceof Promise&&(r=await r),J(r),this.traverseBox(r);let i=this.lastReadFragment;J(i&&i.moofOffset===e);for(let[,e]of i.trackData){let t=e.track,{fragmentPositionCache:n}=t;if(!e.startTimestampIsFinal){let r=t.fragmentLookupTable.find(e=>e.moofOffset===i.moofOffset);if(r)Nw(e,r.timestamp);else{let t=Gb(n,i.moofOffset-1,e=>e.moofOffset);if(t!==-1){let r=n[t];Nw(e,r.endTimestamp)}}e.startTimestampIsFinal=!0}let r=Gb(n,e.startTimestamp,e=>e.startTimestamp);(r===-1||n[r].moofOffset!==i.moofOffset)&&n.splice(r+1,0,{moofOffset:i.moofOffset,startTimestamp:e.startTimestamp,endTimestamp:e.endTimestamp})}return i}readContiguousBoxes(e){let t=e.filePos;for(;e.filePos-t<=e.length-8&&this.traverseBox(e););}*iterateContiguousBoxes(e){let t=e.filePos;for(;e.filePos-t<=e.length-8;){let t=e.filePos,n=yw(e);if(!n)break;yield{boxInfo:n,slice:e},e.filePos=t+n.totalSize}}traverseBox(e){let t=e.filePos,n=yw(e);if(!n)return!1;let r=e.filePos,i=t+n.totalSize;switch(n.name){case`mdia`:case`minf`:case`dinf`:case`mfra`:case`edts`:this.readContiguousBoxes(e.slice(r,n.contentSize));break;case`mvhd`:{let t=ME(e);e.skip(3),t===1?(e.skip(16),this.movieTimescale=Z(e),this.movieDurationInTimescale=HE(e)):(e.skip(8),this.movieTimescale=Z(e),this.movieDurationInTimescale=Z(e))}break;case`trak`:{let t={id:-1,demuxer:this,inputTrack:null,disposition:{...Ix},info:null,timescale:-1,durationInMovieTimescale:-1,durationInMediaTimescale:-1,rotation:0,internalCodecId:null,name:null,languageCode:`und`,sampleTableByteOffset:-1,sampleTable:null,fragmentLookupTable:[],currentFragmentState:null,fragmentPositionCache:[],editListPreviousSegmentDurations:0,editListOffset:0};if(this.currentTrack=t,this.readContiguousBoxes(e.slice(r,n.contentSize)),t.id!==-1&&t.timescale!==-1&&t.info!==null){if(t.info.type===`video`&&t.info.width!==-1){let e=t;t.inputTrack=new gw(this.input,new Dw(e)),this.tracks.push(t)}else if(t.info.type===`audio`&&t.info.numberOfChannels!==-1){let e=t;t.inputTrack=new _w(this.input,new Ow(e)),this.tracks.push(t)}}this.currentTrack=null}break;case`tkhd`:{let t=this.currentTrack;if(!t)break;let n=ME(e),r=!!(FE(e)&1);if(t.disposition.default=r,n===0)e.skip(8),t.id=Z(e),e.skip(4),t.durationInMovieTimescale=Z(e);else if(n===1)e.skip(16),t.id=Z(e),e.skip(4),t.durationInMovieTimescale=HE(e);else throw Error(`Incorrect track header version ${n}.`);e.skip(16);let i=wb(ox(Pw([bw(e),bw(e),xw(e),bw(e),bw(e),xw(e),bw(e),bw(e),xw(e)]),90));J(i===0||i===90||i===180||i===270),t.rotation=i}break;case`elst`:{let t=this.currentTrack;if(!t)break;let n=ME(e);e.skip(3);let r=!1,i=0,a=Z(e);for(let o=0;o<a;o++){let a=n===1?HE(e):Z(e),o=n===1?UE(e):zE(e),s=bw(e);if(a!==0){if(r){console.warn(`Unsupported edit list: multiple edits are not currently supported. Only using first edit.`);break}if(o===-1){i+=a;continue}if(s!==1){console.warn(`Unsupported edit list entry: media rate must be 1.`);break}t.editListPreviousSegmentDurations=i,t.editListOffset=o,r=!0}}}break;case`mdhd`:{let t=this.currentTrack;if(!t)break;let n=ME(e);e.skip(3),n===0?(e.skip(8),t.timescale=Z(e),t.durationInMediaTimescale=Z(e)):n===1&&(e.skip(16),t.timescale=Z(e),t.durationInMediaTimescale=HE(e));let r=PE(e);if(r>0){t.languageCode=``;for(let e=0;e<3;e++)t.languageCode=String.fromCharCode(96+(r&31))+t.languageCode,r>>=5;ux(t.languageCode)||(t.languageCode=`und`)}}break;case`hdlr`:{let t=this.currentTrack;if(!t)break;e.skip(8);let n=qE(e,4);n===`vide`?t.info={type:`video`,width:-1,height:-1,squarePixelWidth:-1,squarePixelHeight:-1,codec:null,codecDescription:null,colorSpace:null,avcType:null,avcCodecInfo:null,hevcCodecInfo:null,vp9CodecInfo:null,av1CodecInfo:null}:n===`soun`&&(t.info={type:`audio`,numberOfChannels:-1,sampleRate:-1,codec:null,codecDescription:null,aacCodecInfo:null})}break;case`stbl`:{let i=this.currentTrack;if(!i)break;i.sampleTableByteOffset=t,this.readContiguousBoxes(e.slice(r,n.contentSize))}break;case`stsd`:{let t=this.currentTrack;if(!t||t.info===null||t.sampleTable)break;let n=ME(e);e.skip(3);let r=Z(e);for(let i=0;i<r;i++){let r=e.filePos,i=yw(e);if(!i)break;t.internalCodecId=i.name;let a=i.name.toLowerCase();if(t.info.type===`video`)a===`avc1`||a===`avc3`?(t.info.codec=`avc`,t.info.avcType=a===`avc1`?1:3):a===`hvc1`||a===`hev1`?t.info.codec=`hevc`:a===`vp08`?t.info.codec=`vp8`:a===`vp09`?t.info.codec=`vp9`:a===`av01`?t.info.codec=`av1`:console.warn(`Unsupported video codec (sample entry type '${i.name}').`),e.skip(24),t.info.width=PE(e),t.info.height=PE(e),t.info.squarePixelWidth=t.info.width,t.info.squarePixelHeight=t.info.height,e.skip(50),this.readContiguousBoxes(e.slice(e.filePos,r+i.totalSize-e.filePos));else{a===`mp4a`||(a===`opus`?t.info.codec=`opus`:a===`flac`?t.info.codec=`flac`:a===`twos`||a===`sowt`||a===`raw `||a===`in24`||a===`in32`||a===`fl32`||a===`fl64`||a===`lpcm`||a===`ipcm`||a===`fpcm`||(a===`ulaw`?t.info.codec=`ulaw`:a===`alaw`?t.info.codec=`alaw`:a===`ac-3`?t.info.codec=`ac3`:a===`ec-3`?t.info.codec=`eac3`:console.warn(`Unsupported audio codec (sample entry type '${i.name}').`))),e.skip(8);let o=PE(e);e.skip(6);let s=PE(e),c=PE(e);e.skip(4);let l=Z(e)/65536;if(n===0&&o>0){if(o===1)e.skip(4),c=8*Z(e),e.skip(8);else if(o===2){e.skip(4),l=KE(e),s=Z(e),e.skip(4),c=Z(e);let n=Z(e);if(e.skip(8),a===`lpcm`){let e=c+7>>3,r=!!(n&1),i=!!(n&2),a=n&4?-1:0;c>0&&c<=64&&(r?c===32&&(t.info.codec=i?`pcm-f32be`:`pcm-f32`):a&1<<e-1?e===1?t.info.codec=`pcm-s8`:e===2?t.info.codec=i?`pcm-s16be`:`pcm-s16`:e===3?t.info.codec=i?`pcm-s24be`:`pcm-s24`:e===4&&(t.info.codec=i?`pcm-s32be`:`pcm-s32`):e===1&&(t.info.codec=`pcm-u8`)),t.info.codec===null&&console.warn(`Unsupported PCM format.`)}}}t.info.codec===`opus`&&(l=aS),t.info.numberOfChannels=s,t.info.sampleRate=l,a===`twos`?c===8?t.info.codec=`pcm-s8`:c===16?t.info.codec=`pcm-s16be`:(console.warn(`Unsupported sample size ${c} for codec 'twos'.`),t.info.codec=null):a===`sowt`?c===8?t.info.codec=`pcm-s8`:c===16?t.info.codec=`pcm-s16`:(console.warn(`Unsupported sample size ${c} for codec 'sowt'.`),t.info.codec=null):a===`raw `?t.info.codec=`pcm-u8`:a===`in24`?t.info.codec=`pcm-s24be`:a===`in32`?t.info.codec=`pcm-s32be`:a===`fl32`?t.info.codec=`pcm-f32be`:a===`fl64`?t.info.codec=`pcm-f64be`:a===`ipcm`?t.info.codec=`pcm-s16be`:a===`fpcm`&&(t.info.codec=`pcm-f32be`),this.readContiguousBoxes(e.slice(e.filePos,r+i.totalSize-e.filePos))}}}break;case`avcC`:{let t=this.currentTrack;if(!t)break;J(t.info),t.info.codecDescription=jE(e,n.contentSize)}break;case`hvcC`:{let t=this.currentTrack;if(!t)break;J(t.info),t.info.codecDescription=jE(e,n.contentSize)}break;case`vpcC`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`video`),e.skip(4);let n=ME(e),r=ME(e),i=ME(e),a=i>>4,o=i>>1&7,s=i&1,c=ME(e),l=ME(e),u=ME(e);t.info.vp9CodecInfo={profile:n,level:r,bitDepth:a,chromaSubsampling:o,videoFullRangeFlag:s,colourPrimaries:c,transferCharacteristics:l,matrixCoefficients:u}}break;case`av1C`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`video`),e.skip(1);let n=ME(e),r=n>>5,i=n&31,a=ME(e),o=a>>7,s=a>>6&1,c=a>>5&1,l=a>>4&1,u=a>>3&1,d=a>>2&1,f=a&3,p=r===2&&s?c?12:10:s?10:8;t.info.av1CodecInfo={profile:r,level:i,tier:o,bitDepth:p,monochrome:l,chromaSubsamplingX:u,chromaSubsamplingY:d,chromaSamplePosition:f}}break;case`colr`:{let t=this.currentTrack;if(!t||(J(t.info?.type===`video`),qE(e,4)!==`nclx`))break;let n=PE(e),r=PE(e),i=PE(e),a=!!(ME(e)&128);t.info.colorSpace={primaries:Pb[n],transfer:Ib[r],matrix:Rb[i],fullRange:a}}break;case`pasp`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`video`);let n=Z(e),r=Z(e);n>r?t.info.squarePixelWidth=Math.round(t.info.width*n/r):t.info.squarePixelHeight=Math.round(t.info.height*r/n)}break;case`wave`:this.readContiguousBoxes(e.slice(r,n.contentSize));break;case`esds`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`),e.skip(4),J(ME(e)===3),Sw(e),e.skip(2);let n=ME(e),r=(n&128)!=0,i=(n&64)!=0,a=(n&32)!=0;if(r&&e.skip(2),i){let t=ME(e);e.skip(t)}a&&e.skip(2),J(ME(e)===4);let o=Sw(e),s=e.filePos,c=ME(e);if(c===64||c===103?(t.info.codec=`aac`,t.info.aacCodecInfo={isMpeg2:c===103,objectType:null}):c===105||c===107?t.info.codec=`mp3`:c===221?t.info.codec=`vorbis`:console.warn(`Unsupported audio codec (objectTypeIndication ${c}) - discarding track.`),e.skip(12),o>e.filePos-s){J(ME(e)===5);let n=Sw(e);if(t.info.codecDescription=jE(e,n),t.info.codec===`aac`){let e=Vx(t.info.codecDescription);e.numberOfChannels!==null&&(t.info.numberOfChannels=e.numberOfChannels),e.sampleRate!==null&&(t.info.sampleRate=e.sampleRate)}}}break;case`enda`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`),PE(e)&255&&(t.info.codec===`pcm-s16be`?t.info.codec=`pcm-s16`:t.info.codec===`pcm-s24be`?t.info.codec=`pcm-s24`:t.info.codec===`pcm-s32be`?t.info.codec=`pcm-s32`:t.info.codec===`pcm-f32be`?t.info.codec=`pcm-f32`:t.info.codec===`pcm-f64be`&&(t.info.codec=`pcm-f64`))}break;case`pcmC`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`),e.skip(4);let n=!!(ME(e)&1),r=ME(e);t.info.codec===`pcm-s16be`?n?r===16?t.info.codec=`pcm-s16`:r===24?t.info.codec=`pcm-s24`:r===32?t.info.codec=`pcm-s32`:(console.warn(`Invalid ipcm sample size ${r}.`),t.info.codec=null):r===16?t.info.codec=`pcm-s16be`:r===24?t.info.codec=`pcm-s24be`:r===32?t.info.codec=`pcm-s32be`:(console.warn(`Invalid ipcm sample size ${r}.`),t.info.codec=null):t.info.codec===`pcm-f32be`&&(n?r===32?t.info.codec=`pcm-f32`:r===64?t.info.codec=`pcm-f64`:(console.warn(`Invalid fpcm sample size ${r}.`),t.info.codec=null):r===32?t.info.codec=`pcm-f32be`:r===64?t.info.codec=`pcm-f64be`:(console.warn(`Invalid fpcm sample size ${r}.`),t.info.codec=null));break}case`dOps`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`),e.skip(1);let n=ME(e),r=PE(e),i=Z(e),a=IE(e),o=ME(e),s;s=o===0?new Uint8Array:jE(e,2+n);let c=new Uint8Array(19+s.byteLength),l=new DataView(c.buffer);l.setUint32(0,1332770163,!1),l.setUint32(4,1214603620,!1),l.setUint8(8,1),l.setUint8(9,n),l.setUint16(10,r,!0),l.setUint32(12,i,!0),l.setInt16(16,a,!0),l.setUint8(18,o),c.set(s,19),t.info.codecDescription=c,t.info.numberOfChannels=n}break;case`dfLa`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`),e.skip(4);let n=e.filePos;for(;e.filePos<i;){let n=ME(e),r=FE(e);if((n&127)===dC.STREAMINFO){e.skip(10);let n=Z(e),r=n>>>12,i=(n>>9&7)+1;t.info.sampleRate=r,t.info.numberOfChannels=i,e.skip(20)}else e.skip(r);if(n&128)break}let r=e.filePos;e.filePos=n;let a=jE(e,r-n),o=new Uint8Array(4+a.byteLength);new DataView(o.buffer).setUint32(0,1716281667,!1),o.set(a,4),t.info.codecDescription=o}break;case`dac3`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`);let n=new Rx(jE(e,3)),r=n.readBits(2);n.skipBits(8);let i=n.readBits(3),a=n.readBits(1);r<3&&(t.info.sampleRate=ES[r]),t.info.numberOfChannels=pC[i]+a}break;case`dec3`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`);let r=yC(jE(e,n.contentSize));if(!r){console.warn(`Invalid dec3 box contents, ignoring.`);break}let i=bC(r);i!==null&&(t.info.sampleRate=i),t.info.numberOfChannels=xC(r)}break;case`stts`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4);let n=Z(e),r=0,i=0;for(let a=0;a<n;a++){let n=Z(e),a=Z(e);t.sampleTable.sampleTimingEntries.push({startIndex:r,startDecodeTimestamp:i,count:n,delta:a}),r+=n,i+=n*a}}break;case`ctts`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4);let n=Z(e),r=0;for(let i=0;i<n;i++){let n=Z(e),i=zE(e);t.sampleTable.sampleCompositionTimeOffsets.push({startIndex:r,count:n,offset:i}),r+=n}}break;case`stsz`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4);let n=Z(e),r=Z(e);if(n===0)for(let n=0;n<r;n++){let n=Z(e);t.sampleTable.sampleSizes.push(n)}else t.sampleTable.sampleSizes.push(n)}break;case`stz2`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4),e.skip(3);let n=ME(e),r=Z(e),i=new Rx(jE(e,Math.ceil(r*n/8)));for(let e=0;e<r;e++){let e=i.readBits(n);t.sampleTable.sampleSizes.push(e)}}break;case`stss`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4),t.sampleTable.keySampleIndices=[];let n=Z(e);for(let r=0;r<n;r++){let n=Z(e)-1;t.sampleTable.keySampleIndices.push(n)}t.sampleTable.keySampleIndices[0]!==0&&t.sampleTable.keySampleIndices.unshift(0)}break;case`stsc`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4);let n=Z(e);for(let r=0;r<n;r++){let n=Z(e)-1,r=Z(e),i=Z(e);t.sampleTable.sampleToChunk.push({startSampleIndex:-1,startChunkIndex:n,samplesPerChunk:r,sampleDescriptionIndex:i})}let r=0;for(let e=0;e<t.sampleTable.sampleToChunk.length;e++)if(t.sampleTable.sampleToChunk[e].startSampleIndex=r,e<t.sampleTable.sampleToChunk.length-1){let n=t.sampleTable.sampleToChunk[e+1].startChunkIndex-t.sampleTable.sampleToChunk[e].startChunkIndex;r+=n*t.sampleTable.sampleToChunk[e].samplesPerChunk}}break;case`stco`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4);let n=Z(e);for(let r=0;r<n;r++){let n=Z(e);t.sampleTable.chunkOffsets.push(n)}}break;case`co64`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4);let n=Z(e);for(let r=0;r<n;r++){let n=HE(e);t.sampleTable.chunkOffsets.push(n)}}break;case`mvex`:this.isFragmented=!0,this.readContiguousBoxes(e.slice(r,n.contentSize));break;case`mehd`:{let t=ME(e);e.skip(3),this.movieDurationInTimescale=t===1?HE(e):Z(e)}break;case`trex`:{e.skip(4);let t=Z(e),n=Z(e),r=Z(e),i=Z(e),a=Z(e);this.fragmentTrackDefaults.push({trackId:t,defaultSampleDescriptionIndex:n,defaultSampleDuration:r,defaultSampleSize:i,defaultSampleFlags:a})}break;case`tfra`:{let t=ME(e);e.skip(3);let n=Z(e),r=this.tracks.find(e=>e.id===n);if(!r)break;let i=Z(e),a=(i&48)>>4,o=(i&12)>>2,s=i&3,c=[ME,PE,FE,Z],l=c[a],u=c[o],d=c[s],f=Z(e);for(let n=0;n<f;n++){let n=t===1?HE(e):Z(e),i=t===1?HE(e):Z(e);l(e),u(e),d(e),r.fragmentLookupTable.push({timestamp:n,moofOffset:i})}r.fragmentLookupTable.sort((e,t)=>e.timestamp-t.timestamp);for(let e=0;e<r.fragmentLookupTable.length-1;e++){let t=r.fragmentLookupTable[e],n=r.fragmentLookupTable[e+1];t.timestamp===n.timestamp&&(r.fragmentLookupTable.splice(e+1,1),e--)}}break;case`moof`:this.currentFragment={moofOffset:t,moofSize:n.totalSize,implicitBaseDataOffset:t,trackData:new Map},this.readContiguousBoxes(e.slice(r,n.contentSize)),this.lastReadFragment=this.currentFragment,this.currentFragment=null;break;case`traf`:if(J(this.currentFragment),this.readContiguousBoxes(e.slice(r,n.contentSize)),this.currentTrack){let e=this.currentFragment.trackData.get(this.currentTrack.id);if(e){let{currentFragmentState:t}=this.currentTrack;J(t),t.startTimestamp!==null&&(Nw(e,t.startTimestamp),e.startTimestampIsFinal=!0)}this.currentTrack.currentFragmentState=null,this.currentTrack=null}break;case`tfhd`:{J(this.currentFragment),e.skip(1);let t=FE(e),n=!!(t&1),r=!!(t&2),i=!!(t&8),a=!!(t&16),o=!!(t&32),s=!!(t&65536),c=!!(t&131072),l=Z(e),u=this.tracks.find(e=>e.id===l);if(!u)break;let d=this.fragmentTrackDefaults.find(e=>e.trackId===l);this.currentTrack=u,u.currentFragmentState={baseDataOffset:this.currentFragment.implicitBaseDataOffset,sampleDescriptionIndex:d?.defaultSampleDescriptionIndex??null,defaultSampleDuration:d?.defaultSampleDuration??null,defaultSampleSize:d?.defaultSampleSize??null,defaultSampleFlags:d?.defaultSampleFlags??null,startTimestamp:null},n?u.currentFragmentState.baseDataOffset=HE(e):c&&(u.currentFragmentState.baseDataOffset=this.currentFragment.moofOffset),r&&(u.currentFragmentState.sampleDescriptionIndex=Z(e)),i&&(u.currentFragmentState.defaultSampleDuration=Z(e)),a&&(u.currentFragmentState.defaultSampleSize=Z(e)),o&&(u.currentFragmentState.defaultSampleFlags=Z(e)),s&&(u.currentFragmentState.defaultSampleDuration=0)}break;case`tfdt`:{let t=this.currentTrack;if(!t)break;J(t.currentFragmentState);let n=ME(e);e.skip(3);let r=n===0?Z(e):HE(e);t.currentFragmentState.startTimestamp=r}break;case`trun`:{let t=this.currentTrack;if(!t)break;if(J(this.currentFragment),J(t.currentFragmentState),this.currentFragment.trackData.has(t.id)){console.warn(`Can't have two trun boxes for the same track in one fragment. Ignoring...`);break}let n=ME(e),r=FE(e),i=!!(r&1),a=!!(r&4),o=!!(r&256),s=!!(r&512),c=!!(r&1024),l=!!(r&2048),u=Z(e),d=t.currentFragmentState.baseDataOffset;i&&(d+=zE(e));let f=null;a&&(f=Z(e));let p=d;if(u===0){this.currentFragment.implicitBaseDataOffset=p;break}let m=0,h={track:t,startTimestamp:0,endTimestamp:0,firstKeyFrameTimestamp:null,samples:[],presentationTimestamps:[],startTimestampIsFinal:!1};this.currentFragment.trackData.set(t.id,h);for(let r=0;r<u;r++){let i;o?i=Z(e):(J(t.currentFragmentState.defaultSampleDuration!==null),i=t.currentFragmentState.defaultSampleDuration);let a;s?a=Z(e):(J(t.currentFragmentState.defaultSampleSize!==null),a=t.currentFragmentState.defaultSampleSize);let u;c?u=Z(e):(J(t.currentFragmentState.defaultSampleFlags!==null),u=t.currentFragmentState.defaultSampleFlags),r===0&&f!==null&&(u=f);let d=0;l&&(d=n===0?Z(e):zE(e));let g=!(u&65536);h.samples.push({presentationTimestamp:m+d,duration:i,byteOffset:p,byteSize:a,isKeyFrame:g}),p+=a,m+=i}h.presentationTimestamps=h.samples.map((e,t)=>({presentationTimestamp:e.presentationTimestamp,sampleIndex:t})).sort((e,t)=>e.presentationTimestamp-t.presentationTimestamp);for(let e=0;e<h.presentationTimestamps.length;e++){let t=h.presentationTimestamps[e],n=h.samples[t.sampleIndex];h.firstKeyFrameTimestamp===null&&n.isKeyFrame&&(h.firstKeyFrameTimestamp=n.presentationTimestamp),e<h.presentationTimestamps.length-1&&(n.duration=h.presentationTimestamps[e+1].presentationTimestamp-t.presentationTimestamp)}let g=h.samples[h.presentationTimestamps[0].sampleIndex],_=h.samples[Tb(h.presentationTimestamps).sampleIndex];h.startTimestamp=g.presentationTimestamp,h.endTimestamp=_.presentationTimestamp+_.duration,this.currentFragment.implicitBaseDataOffset=p}break;case`udta`:{let t=this.iterateContiguousBoxes(e.slice(r,n.contentSize));for(let{boxInfo:e,slice:n}of t){if(e.name!==`meta`&&!this.currentTrack){let t=n.filePos;this.metadataTags.raw??={},e.name[0]===`©`?this.metadataTags.raw[e.name]??=Cw(n):this.metadataTags.raw[e.name]??=jE(n,e.contentSize),n.filePos=t}switch(e.name){case`meta`:n.skip(-e.headerSize),this.traverseBox(n);break;case`©nam`:case`name`:this.currentTrack?this.currentTrack.name=Ab.decode(jE(n,e.contentSize)):this.metadataTags.title??=Cw(n);break;case`©des`:this.currentTrack||(this.metadataTags.description??=Cw(n));break;case`©ART`:this.currentTrack||(this.metadataTags.artist??=Cw(n));break;case`©alb`:this.currentTrack||(this.metadataTags.album??=Cw(n));break;case`albr`:this.currentTrack||(this.metadataTags.albumArtist??=Cw(n));break;case`©gen`:this.currentTrack||(this.metadataTags.genre??=Cw(n));break;case`©day`:if(!this.currentTrack){let e=new Date(Cw(n));Number.isNaN(e.getTime())||(this.metadataTags.date??=e)}break;case`©cmt`:this.currentTrack||(this.metadataTags.comment??=Cw(n));break;case`©lyr`:this.currentTrack||(this.metadataTags.lyrics??=Cw(n));break}}}break;case`meta`:{if(this.currentTrack)break;let t=Z(e)!==0;this.currentMetadataKeys=new Map,t?this.readContiguousBoxes(e.slice(r,n.contentSize)):this.readContiguousBoxes(e.slice(r+4,n.contentSize-4)),this.currentMetadataKeys=null}break;case`keys`:{if(!this.currentMetadataKeys)break;e.skip(4);let t=Z(e);for(let n=0;n<t;n++){let t=Z(e);e.skip(4);let r=Ab.decode(jE(e,t-8));this.currentMetadataKeys.set(n+1,r)}}break;case`ilst`:{if(!this.currentMetadataKeys)break;let t=this.iterateContiguousBoxes(e.slice(r,n.contentSize));for(let{boxInfo:e,slice:n}of t){let t=e.name,r=(t.charCodeAt(0)<<24)+(t.charCodeAt(1)<<16)+(t.charCodeAt(2)<<8)+t.charCodeAt(3);this.currentMetadataKeys.has(r)&&(t=this.currentMetadataKeys.get(r));let i=ww(n);switch(this.metadataTags.raw??={},this.metadataTags.raw[t]??=i,t){case`©nam`:case`titl`:case`com.apple.quicktime.title`:case`title`:typeof i==`string`&&(this.metadataTags.title??=i);break;case`©des`:case`desc`:case`dscp`:case`com.apple.quicktime.description`:case`description`:typeof i==`string`&&(this.metadataTags.description??=i);break;case`©ART`:case`com.apple.quicktime.artist`:case`artist`:typeof i==`string`&&(this.metadataTags.artist??=i);break;case`©alb`:case`albm`:case`com.apple.quicktime.album`:case`album`:typeof i==`string`&&(this.metadataTags.album??=i);break;case`aART`:case`album_artist`:typeof i==`string`&&(this.metadataTags.albumArtist??=i);break;case`©cmt`:case`com.apple.quicktime.comment`:case`comment`:typeof i==`string`&&(this.metadataTags.comment??=i);break;case`©gen`:case`gnre`:case`com.apple.quicktime.genre`:case`genre`:typeof i==`string`&&(this.metadataTags.genre??=i);break;case`©lyr`:case`lyrics`:typeof i==`string`&&(this.metadataTags.lyrics??=i);break;case`©day`:case`rldt`:case`com.apple.quicktime.creationdate`:case`date`:if(typeof i==`string`){let e=new Date(i);Number.isNaN(e.getTime())||(this.metadataTags.date??=e)}break;case`covr`:case`com.apple.quicktime.artwork`:i instanceof Nx?(this.metadataTags.images??=[],this.metadataTags.images.push({data:i.data,kind:`coverFront`,mimeType:i.mimeType})):i instanceof Uint8Array&&(this.metadataTags.images??=[],this.metadataTags.images.push({data:i,kind:`coverFront`,mimeType:`image/*`}));break;case`track`:if(typeof i==`string`){let e=i.split(`/`),t=Number.parseInt(e[0],10),n=e[1]&&Number.parseInt(e[1],10);Number.isInteger(t)&&t>0&&(this.metadataTags.trackNumber??=t),n&&Number.isInteger(n)&&n>0&&(this.metadataTags.tracksTotal??=n)}break;case`trkn`:if(i instanceof Uint8Array&&i.length>=6){let e=kb(i),t=e.getUint16(2,!1),n=e.getUint16(4,!1);t>0&&(this.metadataTags.trackNumber??=t),n>0&&(this.metadataTags.tracksTotal??=n)}break;case`disc`:case`disk`:if(i instanceof Uint8Array&&i.length>=6){let e=kb(i),t=e.getUint16(2,!1),n=e.getUint16(4,!1);t>0&&(this.metadataTags.discNumber??=t),n>0&&(this.metadataTags.discsTotal??=n)}break}}}break}return e.filePos=i,!0}},Ew=class{constructor(e){this.internalTrack=e,this.packetToSampleIndex=new WeakMap,this.packetToFragmentLocation=new WeakMap}getId(){return this.internalTrack.id}getNumber(){let e=this.internalTrack.demuxer,t=this.internalTrack.inputTrack.type,n=0;for(let r of e.tracks)if(r.inputTrack.type===t&&n++,r===this.internalTrack)break;return n}getCodec(){throw Error(`Not implemented on base class.`)}getInternalCodecId(){return this.internalTrack.internalCodecId}getName(){return this.internalTrack.name}getLanguageCode(){return this.internalTrack.languageCode}getTimeResolution(){return this.internalTrack.timescale}getDisposition(){return this.internalTrack.disposition}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}async getFirstTimestamp(){return(await this.getFirstPacket({metadataOnly:!0}))?.timestamp??0}async getFirstPacket(e){let t=await this.fetchPacketForSampleIndex(0,e);return t||!this.internalTrack.demuxer.isFragmented?t:this.performFragmentedLookup(null,e=>e.trackData.get(this.internalTrack.id)?{sampleIndex:0,correctSampleFound:!0}:{sampleIndex:-1,correctSampleFound:!1},-1/0,1/0,e)}mapTimestampIntoTimescale(e){return ax(e*this.internalTrack.timescale)+this.internalTrack.editListOffset}async getPacket(e,t){let n=this.mapTimestampIntoTimescale(e),r=this.internalTrack.demuxer.getSampleTableForTrack(this.internalTrack),i=kw(r,n),a=await this.fetchPacketForSampleIndex(i,t);return!Fw(r)||!this.internalTrack.demuxer.isFragmented?a:this.performFragmentedLookup(null,e=>{let t=e.trackData.get(this.internalTrack.id);if(!t)return{sampleIndex:-1,correctSampleFound:!1};let r=Gb(t.presentationTimestamps,n,e=>e.presentationTimestamp);return{sampleIndex:r===-1?-1:t.presentationTimestamps[r].sampleIndex,correctSampleFound:r!==-1&&n<t.endTimestamp}},n,n,t)}async getNextPacket(e,t){let n=this.packetToSampleIndex.get(e);if(n!==void 0)return this.fetchPacketForSampleIndex(n+1,t);let r=this.packetToFragmentLocation.get(e);if(r===void 0)throw Error(`Packet was not created from this track.`);return this.performFragmentedLookup(r.fragment,e=>{if(e===r.fragment){let t=e.trackData.get(this.internalTrack.id);if(r.sampleIndex+1<t.samples.length)return{sampleIndex:r.sampleIndex+1,correctSampleFound:!0}}else if(e.trackData.get(this.internalTrack.id))return{sampleIndex:0,correctSampleFound:!0};return{sampleIndex:-1,correctSampleFound:!1}},-1/0,1/0,t)}async getKeyPacket(e,t){let n=this.mapTimestampIntoTimescale(e),r=this.internalTrack.demuxer.getSampleTableForTrack(this.internalTrack),i=Aw(r,n),a=await this.fetchPacketForSampleIndex(i,t);return!Fw(r)||!this.internalTrack.demuxer.isFragmented?a:this.performFragmentedLookup(null,e=>{let t=e.trackData.get(this.internalTrack.id);if(!t)return{sampleIndex:-1,correctSampleFound:!1};let r=Yb(t.presentationTimestamps,e=>t.samples[e.sampleIndex].isKeyFrame&&e.presentationTimestamp<=n);return{sampleIndex:r===-1?-1:t.presentationTimestamps[r].sampleIndex,correctSampleFound:r!==-1&&n<t.endTimestamp}},n,n,t)}async getNextKeyPacket(e,t){let n=this.packetToSampleIndex.get(e);if(n!==void 0){let e=Mw(this.internalTrack.demuxer.getSampleTableForTrack(this.internalTrack),n);return this.fetchPacketForSampleIndex(e,t)}let r=this.packetToFragmentLocation.get(e);if(r===void 0)throw Error(`Packet was not created from this track.`);return this.performFragmentedLookup(r.fragment,e=>{if(e===r.fragment){let t=e.trackData.get(this.internalTrack.id).samples.findIndex((e,t)=>e.isKeyFrame&&t>r.sampleIndex);if(t!==-1)return{sampleIndex:t,correctSampleFound:!0}}else{let t=e.trackData.get(this.internalTrack.id);if(t&&t.firstKeyFrameTimestamp!==null){let e=t.samples.findIndex(e=>e.isKeyFrame);return J(e!==-1),{sampleIndex:e,correctSampleFound:!0}}}return{sampleIndex:-1,correctSampleFound:!1}},-1/0,1/0,t)}async fetchPacketForSampleIndex(e,t){if(e===-1)return null;let n=jw(this.internalTrack.demuxer.getSampleTableForTrack(this.internalTrack),e);if(!n)return null;let r;if(t.metadataOnly)r=DC;else{let e=this.internalTrack.demuxer.reader.requestSlice(n.sampleOffset,n.sampleSize);e instanceof Promise&&(e=await e),J(e),r=jE(e,n.sampleSize)}let i=(n.presentationTimestamp-this.internalTrack.editListOffset)/this.internalTrack.timescale,a=n.duration/this.internalTrack.timescale,o=new OC(r,n.isKeyFrame?`key`:`delta`,i,a,e,n.sampleSize);return this.packetToSampleIndex.set(o,e),o}async fetchPacketInFragment(e,t,n){if(t===-1)return null;let r=e.trackData.get(this.internalTrack.id).samples[t];J(r);let i;if(n.metadataOnly)i=DC;else{let e=this.internalTrack.demuxer.reader.requestSlice(r.byteOffset,r.byteSize);e instanceof Promise&&(e=await e),J(e),i=jE(e,r.byteSize)}let a=(r.presentationTimestamp-this.internalTrack.editListOffset)/this.internalTrack.timescale,o=r.duration/this.internalTrack.timescale,s=new OC(i,r.isKeyFrame?`key`:`delta`,a,o,e.moofOffset+t,r.byteSize);return this.packetToFragmentLocation.set(s,{fragment:e,sampleIndex:t}),s}async performFragmentedLookup(e,t,n,r,i){let a=this.internalTrack.demuxer,o=null,s=null,c=-1;if(e){let{sampleIndex:n,correctSampleFound:r}=t(e);if(r)return this.fetchPacketInFragment(e,n,i);n!==-1&&(s=e,c=n)}let l=Gb(this.internalTrack.fragmentLookupTable,n,e=>e.timestamp),u=l===-1?null:this.internalTrack.fragmentLookupTable[l],d=Gb(this.internalTrack.fragmentPositionCache,n,e=>e.startTimestamp),f=d===-1?null:this.internalTrack.fragmentPositionCache[d],p=Math.max(u?.moofOffset??0,f?.moofOffset??0)||null,m;for(e?p===null||e.moofOffset>=p?(m=e.moofOffset+e.moofSize,o=e):m=p:m=p??0;;){if(o){let e=o.trackData.get(this.internalTrack.id);if(e&&e.startTimestamp>r)break}let e=a.reader.requestSliceRange(m,8,16);if(e instanceof Promise&&(e=await e),!e)break;let n=m,l=yw(e);if(!l)break;if(l.name===`moof`){o=await a.readFragment(n);let{sampleIndex:e,correctSampleFound:r}=t(o);if(r)return this.fetchPacketInFragment(o,e,i);e!==-1&&(s=o,c=e)}m=n+l.totalSize}if(u&&(!s||s.moofOffset<u.moofOffset)){let e=this.internalTrack.fragmentLookupTable[l-1];J(!e||e.timestamp<u.timestamp);let n=e?.timestamp??-1/0;return this.performFragmentedLookup(null,t,n,r,i)}return s?this.fetchPacketInFragment(s,c,i):null}},Dw=class extends Ew{constructor(e){super(e),this.decoderConfigPromise=null,this.internalTrack=e}getCodec(){return this.internalTrack.info.codec}getCodedWidth(){return this.internalTrack.info.width}getCodedHeight(){return this.internalTrack.info.height}getSquarePixelWidth(){return this.internalTrack.info.squarePixelWidth}getSquarePixelHeight(){return this.internalTrack.info.squarePixelHeight}getRotation(){return this.internalTrack.rotation}async getColorSpace(){return{primaries:this.internalTrack.info.colorSpace?.primaries,transfer:this.internalTrack.info.colorSpace?.transfer,matrix:this.internalTrack.info.colorSpace?.matrix,fullRange:this.internalTrack.info.colorSpace?.fullRange}}async canBeTransparent(){return!1}async getDecoderConfig(){return this.internalTrack.info.codec?this.decoderConfigPromise??=(async()=>{if(this.internalTrack.info.codec===`vp9`&&!this.internalTrack.info.vp9CodecInfo){let e=await this.getFirstPacket({});this.internalTrack.info.vp9CodecInfo=e&&rC(e.data)}else if(this.internalTrack.info.codec===`av1`&&!this.internalTrack.info.av1CodecInfo){let e=await this.getFirstPacket({});this.internalTrack.info.av1CodecInfo=e&&aC(e.data)}return{codec:nS(this.internalTrack.info),codedWidth:this.internalTrack.info.width,codedHeight:this.internalTrack.info.height,displayAspectWidth:this.internalTrack.info.squarePixelWidth,displayAspectHeight:this.internalTrack.info.squarePixelHeight,description:this.internalTrack.info.codecDescription??void 0,colorSpace:this.internalTrack.info.colorSpace??void 0}})():null}},Ow=class extends Ew{constructor(e){super(e),this.decoderConfig=null,this.internalTrack=e}getCodec(){return this.internalTrack.info.codec}getNumberOfChannels(){return this.internalTrack.info.numberOfChannels}getSampleRate(){return this.internalTrack.info.sampleRate}async getDecoderConfig(){return this.internalTrack.info.codec?this.decoderConfig??={codec:iS(this.internalTrack.info),numberOfChannels:this.internalTrack.info.numberOfChannels,sampleRate:this.internalTrack.info.sampleRate,description:this.internalTrack.info.codecDescription??void 0}:null}},kw=(e,t)=>{if(e.presentationTimestamps){let n=Gb(e.presentationTimestamps,t,e=>e.presentationTimestamp);return n===-1?-1:e.presentationTimestamps[n].sampleIndex}else{let n=Gb(e.sampleTimingEntries,t,e=>e.startDecodeTimestamp);if(n===-1)return-1;let r=e.sampleTimingEntries[n];return r.startIndex+Math.min(Math.floor((t-r.startDecodeTimestamp)/r.delta),r.count-1)}},Aw=(e,t)=>{if(!e.keySampleIndices)return kw(e,t);if(e.presentationTimestamps){let n=Gb(e.presentationTimestamps,t,e=>e.presentationTimestamp);if(n===-1)return-1;for(let t=n;t>=0;t--){let n=e.presentationTimestamps[t].sampleIndex;if(Wb(e.keySampleIndices,n,e=>e)!==-1)return n}return-1}else{let n=kw(e,t),r=Gb(e.keySampleIndices,n,e=>e);return e.keySampleIndices[r]??-1}},jw=(e,t)=>{let n=Gb(e.sampleTimingEntries,t,e=>e.startIndex),r=e.sampleTimingEntries[n];if(!r||r.startIndex+r.count<=t)return null;let i=r.startDecodeTimestamp+(t-r.startIndex)*r.delta,a=Gb(e.sampleCompositionTimeOffsets,t,e=>e.startIndex),o=e.sampleCompositionTimeOffsets[a];o&&t-o.startIndex<o.count&&(i+=o.offset);let s=e.sampleSizes[Math.min(t,e.sampleSizes.length-1)],c=Gb(e.sampleToChunk,t,e=>e.startSampleIndex),l=e.sampleToChunk[c];J(l);let u=l.startChunkIndex+Math.floor((t-l.startSampleIndex)/l.samplesPerChunk),d=e.chunkOffsets[u],f=l.startSampleIndex+(u-l.startChunkIndex)*l.samplesPerChunk,p=0,m=d;if(e.sampleSizes.length===1)m+=s*(t-f),p+=s*l.samplesPerChunk;else for(let n=f;n<f+l.samplesPerChunk;n++){let r=e.sampleSizes[n];n<t&&(m+=r),p+=r}let h=r.delta;if(e.presentationTimestamps){let n=e.presentationTimestampIndexMap[t];J(n!==void 0),n<e.presentationTimestamps.length-1&&(h=e.presentationTimestamps[n+1].presentationTimestamp-i)}return{presentationTimestamp:i,duration:h,sampleOffset:m,sampleSize:s,chunkOffset:d,chunkSize:p,isKeyFrame:e.keySampleIndices?Wb(e.keySampleIndices,t,e=>e)!==-1:!0}},Mw=(e,t)=>{if(!e.keySampleIndices)return t+1;let n=Gb(e.keySampleIndices,t,e=>e);return e.keySampleIndices[n+1]??-1},Nw=(e,t)=>{e.startTimestamp+=t,e.endTimestamp+=t;for(let n of e.samples)n.presentationTimestamp+=t;for(let n of e.presentationTimestamps)n.presentationTimestamp+=t},Pw=e=>{let[t,,,n]=e,r=Math.hypot(t,n),i=t/r,a=n/r,o=-Math.atan2(a,i)*(180/Math.PI);return Number.isFinite(o)?o:0},Fw=e=>e.sampleSizes.length===0,X;(function(e){e[e.EBML=440786851]=`EBML`,e[e.EBMLVersion=17030]=`EBMLVersion`,e[e.EBMLReadVersion=17143]=`EBMLReadVersion`,e[e.EBMLMaxIDLength=17138]=`EBMLMaxIDLength`,e[e.EBMLMaxSizeLength=17139]=`EBMLMaxSizeLength`,e[e.DocType=17026]=`DocType`,e[e.DocTypeVersion=17031]=`DocTypeVersion`,e[e.DocTypeReadVersion=17029]=`DocTypeReadVersion`,e[e.Void=236]=`Void`,e[e.Segment=408125543]=`Segment`,e[e.SeekHead=290298740]=`SeekHead`,e[e.Seek=19899]=`Seek`,e[e.SeekID=21419]=`SeekID`,e[e.SeekPosition=21420]=`SeekPosition`,e[e.Duration=17545]=`Duration`,e[e.Info=357149030]=`Info`,e[e.TimestampScale=2807729]=`TimestampScale`,e[e.MuxingApp=19840]=`MuxingApp`,e[e.WritingApp=22337]=`WritingApp`,e[e.Tracks=374648427]=`Tracks`,e[e.TrackEntry=174]=`TrackEntry`,e[e.TrackNumber=215]=`TrackNumber`,e[e.TrackUID=29637]=`TrackUID`,e[e.TrackType=131]=`TrackType`,e[e.FlagEnabled=185]=`FlagEnabled`,e[e.FlagDefault=136]=`FlagDefault`,e[e.FlagForced=21930]=`FlagForced`,e[e.FlagOriginal=21934]=`FlagOriginal`,e[e.FlagHearingImpaired=21931]=`FlagHearingImpaired`,e[e.FlagVisualImpaired=21932]=`FlagVisualImpaired`,e[e.FlagCommentary=21935]=`FlagCommentary`,e[e.FlagLacing=156]=`FlagLacing`,e[e.Name=21358]=`Name`,e[e.Language=2274716]=`Language`,e[e.LanguageBCP47=2274717]=`LanguageBCP47`,e[e.CodecID=134]=`CodecID`,e[e.CodecPrivate=25506]=`CodecPrivate`,e[e.CodecDelay=22186]=`CodecDelay`,e[e.SeekPreRoll=22203]=`SeekPreRoll`,e[e.DefaultDuration=2352003]=`DefaultDuration`,e[e.Video=224]=`Video`,e[e.PixelWidth=176]=`PixelWidth`,e[e.PixelHeight=186]=`PixelHeight`,e[e.DisplayWidth=21680]=`DisplayWidth`,e[e.DisplayHeight=21690]=`DisplayHeight`,e[e.DisplayUnit=21682]=`DisplayUnit`,e[e.AlphaMode=21440]=`AlphaMode`,e[e.Audio=225]=`Audio`,e[e.SamplingFrequency=181]=`SamplingFrequency`,e[e.Channels=159]=`Channels`,e[e.BitDepth=25188]=`BitDepth`,e[e.SimpleBlock=163]=`SimpleBlock`,e[e.BlockGroup=160]=`BlockGroup`,e[e.Block=161]=`Block`,e[e.BlockAdditions=30113]=`BlockAdditions`,e[e.BlockMore=166]=`BlockMore`,e[e.BlockAdditional=165]=`BlockAdditional`,e[e.BlockAddID=238]=`BlockAddID`,e[e.BlockDuration=155]=`BlockDuration`,e[e.ReferenceBlock=251]=`ReferenceBlock`,e[e.Cluster=524531317]=`Cluster`,e[e.Timestamp=231]=`Timestamp`,e[e.Cues=475249515]=`Cues`,e[e.CuePoint=187]=`CuePoint`,e[e.CueTime=179]=`CueTime`,e[e.CueTrackPositions=183]=`CueTrackPositions`,e[e.CueTrack=247]=`CueTrack`,e[e.CueClusterPosition=241]=`CueClusterPosition`,e[e.Colour=21936]=`Colour`,e[e.MatrixCoefficients=21937]=`MatrixCoefficients`,e[e.TransferCharacteristics=21946]=`TransferCharacteristics`,e[e.Primaries=21947]=`Primaries`,e[e.Range=21945]=`Range`,e[e.Projection=30320]=`Projection`,e[e.ProjectionType=30321]=`ProjectionType`,e[e.ProjectionPoseRoll=30325]=`ProjectionPoseRoll`,e[e.Attachments=423732329]=`Attachments`,e[e.AttachedFile=24999]=`AttachedFile`,e[e.FileDescription=18046]=`FileDescription`,e[e.FileName=18030]=`FileName`,e[e.FileMediaType=18016]=`FileMediaType`,e[e.FileData=18012]=`FileData`,e[e.FileUID=18094]=`FileUID`,e[e.Chapters=272869232]=`Chapters`,e[e.Tags=307544935]=`Tags`,e[e.Tag=29555]=`Tag`,e[e.Targets=25536]=`Targets`,e[e.TargetTypeValue=26826]=`TargetTypeValue`,e[e.TargetType=25546]=`TargetType`,e[e.TagTrackUID=25541]=`TagTrackUID`,e[e.TagEditionUID=25545]=`TagEditionUID`,e[e.TagChapterUID=25540]=`TagChapterUID`,e[e.TagAttachmentUID=25542]=`TagAttachmentUID`,e[e.SimpleTag=26568]=`SimpleTag`,e[e.TagName=17827]=`TagName`,e[e.TagLanguage=17530]=`TagLanguage`,e[e.TagString=17543]=`TagString`,e[e.TagBinary=17541]=`TagBinary`,e[e.ContentEncodings=28032]=`ContentEncodings`,e[e.ContentEncoding=25152]=`ContentEncoding`,e[e.ContentEncodingOrder=20529]=`ContentEncodingOrder`,e[e.ContentEncodingScope=20530]=`ContentEncodingScope`,e[e.ContentCompression=20532]=`ContentCompression`,e[e.ContentCompAlgo=16980]=`ContentCompAlgo`,e[e.ContentCompSettings=16981]=`ContentCompSettings`,e[e.ContentEncryption=20533]=`ContentEncryption`})(X||={});var Iw=[X.EBML,X.Segment],Lw=[X.SeekHead,X.Info,X.Cluster,X.Tracks,X.Cues,X.Attachments,X.Chapters,X.Tags],Rw=[...Iw,...Lw],zw=e=>{if(e.remainingLength<1)return null;let t=ME(e);if(e.skip(-1),t===0)return null;let n=1,r=128;for(;(t&r)===0;)n++,r>>=1;return e.remainingLength<n?null:n},Bw=e=>{if(e.remainingLength<1)return null;let t=ME(e);if(t===0)return null;let n=1,r=128;for(;(t&r)===0;)n++,r>>=1;if(e.remainingLength<n-1)return null;let i=t&r-1;for(let t=1;t<n;t++)i*=256,i+=ME(e);return i},Vw=(e,t)=>{if(t<1||t>8)throw Error(`Bad unsigned int size `+t);let n=0;for(let r=0;r<t;r++)n*=256,n+=ME(e);return n},Hw=(e,t)=>{if(t<1)throw Error(`Bad unsigned int size `+t);let n=0n;for(let r=0;r<t;r++)n<<=8n,n+=BigInt(ME(e));return n},Uw=e=>{let t=zw(e);return t===null||e.remainingLength<t?null:Vw(e,t)},Ww=e=>{if(e.remainingLength<1)return null;if(ME(e)===255)return;e.skip(-1);let t=Bw(e);if(t===null)return null;if(t!==72057594037927940)return t},Gw=e=>{J(e.remainingLength>=2);let t=Uw(e);if(t===null)return null;let n=Ww(e);return n===null?null:{id:t,size:n}},Kw=(e,t)=>{let n=jE(e,t),r=0;for(;r<t&&n[r]!==0;)r+=1;return String.fromCharCode(...n.subarray(0,r))},qw=(e,t)=>{let n=jE(e,t),r=0;for(;r<t&&n[r]!==0;)r+=1;return Ab.decode(n.subarray(0,r))},Jw=(e,t)=>{if(t===0)return 0;if(t!==4&&t!==8)throw Error(`Bad float size `+t);return t===4?GE(e):KE(e)},Yw=async(e,t,n,r)=>{let i=new Set(n),a=t;for(;r===null||a<r;){let t=e.requestSliceRange(a,2,16);if(t instanceof Promise&&(t=await t),!t)break;let n=Gw(t);if(!n)break;if(i.has(n.id))return{pos:a,found:!0};Qw(n.size),a=t.filePos+n.size}return{pos:r!==null&&r>a?r:a,found:!1}},Xw=async(e,t,n,r)=>{let i=2**16,a=new Set(n),o=t;for(;o<r;){let t=e.requestSliceRange(o,0,Math.min(i,r-o));if(t instanceof Promise&&(t=await t),!t||t.length<8)break;for(let e=0;e<t.length-8;e++){t.filePos=o;let e=Uw(t);if(e!==null&&a.has(e))return o;o++}}return null},Zw={avc:`V_MPEG4/ISO/AVC`,hevc:`V_MPEGH/ISO/HEVC`,vp8:`V_VP8`,vp9:`V_VP9`,av1:`V_AV1`,aac:`A_AAC`,mp3:`A_MPEG/L3`,opus:`A_OPUS`,vorbis:`A_VORBIS`,flac:`A_FLAC`,ac3:`A_AC3`,eac3:`A_EAC3`,"pcm-u8":`A_PCM/INT/LIT`,"pcm-s16":`A_PCM/INT/LIT`,"pcm-s16be":`A_PCM/INT/BIG`,"pcm-s24":`A_PCM/INT/LIT`,"pcm-s24be":`A_PCM/INT/BIG`,"pcm-s32":`A_PCM/INT/LIT`,"pcm-s32be":`A_PCM/INT/BIG`,"pcm-f32":`A_PCM/FLOAT/IEEE`,"pcm-f64":`A_PCM/FLOAT/IEEE`,webvtt:`S_TEXT/WEBVTT`};function Qw(e){if(e===void 0)throw Error(`Undefined element size is used in a place where it is not supported.`)}var $w=e=>{let t=(e.hasVideo?`video/`:e.hasAudio?`audio/`:`application/`)+(e.isWebM?`webm`:`x-matroska`);if(e.codecStrings.length>0){let n=[...new Set(e.codecStrings.filter(Boolean))];t+=`; codecs="${n.join(`, `)}"`}return t},eT;(function(e){e[e.None=0]=`None`,e[e.Xiph=1]=`Xiph`,e[e.FixedSize=2]=`FixedSize`,e[e.Ebml=3]=`Ebml`})(eT||={});var tT;(function(e){e[e.Block=1]=`Block`,e[e.Private=2]=`Private`,e[e.Next=4]=`Next`})(tT||={});var nT;(function(e){e[e.Zlib=0]=`Zlib`,e[e.Bzlib=1]=`Bzlib`,e[e.lzo1x=2]=`lzo1x`,e[e.HeaderStripping=3]=`HeaderStripping`})(nT||={});var rT=[{id:X.SeekHead,flag:`seekHeadSeen`},{id:X.Info,flag:`infoSeen`},{id:X.Tracks,flag:`tracksSeen`},{id:X.Cues,flag:`cuesSeen`}],iT=10*2**20,aT=class extends SC{constructor(e){super(e),this.readMetadataPromise=null,this.segments=[],this.currentSegment=null,this.currentTrack=null,this.currentCluster=null,this.currentBlock=null,this.currentBlockAdditional=null,this.currentCueTime=null,this.currentDecodingInstruction=null,this.currentTagTargetIsMovie=!0,this.currentSimpleTagName=null,this.currentAttachedFile=null,this.isWebM=!1,this.reader=e._reader}async computeDuration(){let e=await this.getTracks(),t=await Promise.all(e.map(e=>e.computeDuration()));return Math.max(0,...t)}async getTracks(){return await this.readMetadata(),this.segments.flatMap(e=>e.tracks.map(e=>e.inputTrack))}async getMimeType(){await this.readMetadata();let e=await this.getTracks(),t=await Promise.all(e.map(e=>e.getCodecParameterString()));return $w({isWebM:this.isWebM,hasVideo:this.segments.some(e=>e.tracks.some(e=>e.info?.type===`video`)),hasAudio:this.segments.some(e=>e.tracks.some(e=>e.info?.type===`audio`)),codecStrings:t.filter(Boolean)})}async getMetadataTags(){await this.readMetadata();for(let e of this.segments)e.metadataTagsCollected||=(this.reader.fileSize!==null&&await this.loadSegmentMetadata(e),!0);let e={};for(let t of this.segments)e={...e,...t.metadataTags};return e}readMetadata(){return this.readMetadataPromise??=(async()=>{let e=0;for(;;){let t=this.reader.requestSliceRange(e,2,16);if(t instanceof Promise&&(t=await t),!t)break;let n=Gw(t);if(!n)break;let r=n.id,i=n.size,a=t.filePos;if(r===X.EBML){Qw(i);let e=this.reader.requestSlice(a,i);if(e instanceof Promise&&(e=await e),!e)break;this.readContiguousElements(e)}else if(r===X.Segment){if(await this.readSegment(a,i),i===void 0||this.reader.fileSize===null)break}else if(r===X.Cluster){if(this.reader.fileSize===null)break;i===void 0&&(i=(await Yw(this.reader,a,Rw,this.reader.fileSize)).pos-a);let e=Tb(this.segments);e&&(e.elementEndPos=a+i)}Qw(i),e=a+i}})()}async readSegment(e,t){this.currentSegment={seekHeadSeen:!1,infoSeen:!1,tracksSeen:!1,cuesSeen:!1,tagsSeen:!1,attachmentsSeen:!1,timestampScale:-1,timestampFactor:-1,duration:-1,seekEntries:[],tracks:[],cuePoints:[],dataStartPos:e,elementEndPos:t===void 0?null:e+t,clusterSeekStartPos:e,lastReadCluster:null,metadataTags:{},metadataTagsCollected:!1},this.segments.push(this.currentSegment);let n=e;for(;this.currentSegment.elementEndPos===null||n<this.currentSegment.elementEndPos;){let e=this.reader.requestSliceRange(n,2,16);if(e instanceof Promise&&(e=await e),!e)break;let t=n,r=Gw(e);if(!r||!Lw.includes(r.id)&&r.id!==X.Void){let e=await Xw(this.reader,t,Lw,Math.min(this.currentSegment.elementEndPos??1/0,t+iT));if(e){n=e;continue}else break}let{id:i,size:a}=r,o=e.filePos,s=rT.findIndex(e=>e.id===i);if(s!==-1){let e=rT[s].flag;this.currentSegment[e]=!0,Qw(a);let t=this.reader.requestSlice(o,a);t instanceof Promise&&(t=await t),t&&this.readContiguousElements(t)}else if(i===X.Tags||i===X.Attachments){i===X.Tags?this.currentSegment.tagsSeen=!0:this.currentSegment.attachmentsSeen=!0,Qw(a);let e=this.reader.requestSlice(o,a);e instanceof Promise&&(e=await e),e&&this.readContiguousElements(e)}else if(i===X.Cluster){this.currentSegment.clusterSeekStartPos=t;break}if(a===void 0)break;n=o+a}if(this.currentSegment.seekEntries.sort((e,t)=>e.segmentPosition-t.segmentPosition),this.reader.fileSize!==null)for(let t of this.currentSegment.seekEntries){let n=rT.find(e=>e.id===t.id);if(!n||this.currentSegment[n.flag])continue;let r=this.reader.requestSliceRange(e+t.segmentPosition,2,16);if(r instanceof Promise&&(r=await r),!r)continue;let i=Gw(r);if(!i)continue;let{id:a,size:o}=i;if(a!==n.id)continue;Qw(o),this.currentSegment[n.flag]=!0;let s=this.reader.requestSlice(r.filePos,o);s instanceof Promise&&(s=await s),s&&this.readContiguousElements(s)}this.currentSegment.timestampScale===-1&&(this.currentSegment.timestampScale=1e6,this.currentSegment.timestampFactor=1e9/1e6);for(let e of this.currentSegment.tracks)e.defaultDurationNs!==null&&(e.defaultDuration=this.currentSegment.timestampFactor*e.defaultDurationNs/1e9);this.currentSegment.tracks.sort((e,t)=>Number(t.disposition.default)-Number(e.disposition.default));let r=new Map(this.currentSegment.tracks.map(e=>[e.id,e]));for(let e of this.currentSegment.cuePoints){let t=r.get(e.trackId);t&&t.cuePoints.push(e)}for(let e of this.currentSegment.tracks){e.cuePoints.sort((e,t)=>e.time-t.time);for(let t=0;t<e.cuePoints.length-1;t++){let n=e.cuePoints[t],r=e.cuePoints[t+1];n.time===r.time&&(e.cuePoints.splice(t+1,1),t--)}}let i=null,a=-1/0;for(let e of this.currentSegment.tracks)e.cuePoints.length>a&&(a=e.cuePoints.length,i=e);for(let e of this.currentSegment.tracks)e.cuePoints.length===0&&(e.cuePoints=i.cuePoints);this.currentSegment=null}async readCluster(e,t){if(t.lastReadCluster?.elementStartPos===e)return t.lastReadCluster;let n=this.reader.requestSliceRange(e,2,16);n instanceof Promise&&(n=await n),J(n);let r=e,i=Gw(n);J(i);let a=i.id;J(a===X.Cluster);let o=i.size,s=n.filePos;o===void 0&&(o=(await Yw(this.reader,s,Rw,t.elementEndPos)).pos-s);let c=this.reader.requestSlice(s,o);c instanceof Promise&&(c=await c);let l={segment:t,elementStartPos:r,elementEndPos:s+o,dataStartPos:s,timestamp:-1,trackData:new Map};this.currentCluster=l,c&&(l.elementEndPos=this.readContiguousElements(c,Rw));for(let[,e]of l.trackData){let t=e.track;J(e.blocks.length>0);let n=!1;for(let t=0;t<e.blocks.length;t++){let r=e.blocks[t];r.timestamp+=l.timestamp,n||=r.lacing!==eT.None}e.presentationTimestamps=e.blocks.map((e,t)=>({timestamp:e.timestamp,blockIndex:t})).sort((e,t)=>e.timestamp-t.timestamp);for(let n=0;n<e.presentationTimestamps.length;n++){let r=e.presentationTimestamps[n],i=e.blocks[r.blockIndex];e.firstKeyFrameTimestamp===null&&i.isKeyFrame&&(e.firstKeyFrameTimestamp=i.timestamp),n<e.presentationTimestamps.length-1?i.duration=e.presentationTimestamps[n+1].timestamp-i.timestamp:i.duration===0&&t.defaultDuration!=null&&i.lacing===eT.None&&(i.duration=t.defaultDuration)}n&&(this.expandLacedBlocks(e.blocks,t),e.presentationTimestamps=e.blocks.map((e,t)=>({timestamp:e.timestamp,blockIndex:t})).sort((e,t)=>e.timestamp-t.timestamp));let i=e.blocks[e.presentationTimestamps[0].blockIndex],a=e.blocks[Tb(e.presentationTimestamps).blockIndex];e.startTimestamp=i.timestamp,e.endTimestamp=a.timestamp+a.duration;let o=Gb(t.clusterPositionCache,e.startTimestamp,e=>e.startTimestamp);(o===-1||t.clusterPositionCache[o].elementStartPos!==r)&&t.clusterPositionCache.splice(o+1,0,{elementStartPos:l.elementStartPos,startTimestamp:e.startTimestamp})}return t.lastReadCluster=l,l}getTrackDataInCluster(e,t){let n=e.trackData.get(t);if(!n){let r=e.segment.tracks.find(e=>e.id===t);if(!r)return null;n={track:r,startTimestamp:0,endTimestamp:0,firstKeyFrameTimestamp:null,blocks:[],presentationTimestamps:[]},e.trackData.set(t,n)}return n}expandLacedBlocks(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(r.lacing===eT.None)continue;r.decoded||=(r.data=this.decodeBlockData(t,r.data),!0);let i=kE.tempFromBytes(r.data),a=[],o=ME(i)+1;switch(r.lacing){case eT.Xiph:{let e=0;for(let t=0;t<o-1;t++){let t=0;for(;i.bufferPos<i.length;){let n=ME(i);if(t+=n,n<255){a.push(t),e+=t;break}}}a.push(i.length-(i.bufferPos+e))}break;case eT.FixedSize:{let e=i.length-1,t=Math.floor(e/o);for(let e=0;e<o;e++)a.push(t)}break;case eT.Ebml:{let e=Bw(i);J(e!==null);let t=e;a.push(t);let n=t;for(let e=1;e<o-1;e++){let e=i.bufferPos,r=Bw(i);J(r!==null);let o=r-((1<<(i.bufferPos-e)*7-1)-1);t+=o,a.push(t),n+=t}a.push(i.length-(i.bufferPos+n))}break;default:J(!1)}J(a.length===o),e.splice(n,1);let s=r.duration||o*(t.defaultDuration??0);for(let t=0;t<o;t++){let c=a[t],l=jE(i,c),u=r.timestamp+s*t/o,d=s/o;e.splice(n+t,0,{timestamp:u,duration:d,isKeyFrame:r.isKeyFrame,data:l,lacing:eT.None,decoded:!0,mainAdditional:r.mainAdditional})}n+=o,n--}}async loadSegmentMetadata(e){for(let t of e.seekEntries){if(!(t.id===X.Tags&&!e.tagsSeen)&&!(t.id===X.Attachments&&!e.attachmentsSeen))continue;let n=this.reader.requestSliceRange(e.dataStartPos+t.segmentPosition,2,16);if(n instanceof Promise&&(n=await n),!n)continue;let r=Gw(n);if(!r||r.id!==t.id)continue;let{size:i}=r;Qw(i),J(!this.currentSegment),this.currentSegment=e;let a=this.reader.requestSlice(n.filePos,i);a instanceof Promise&&(a=await a),a&&this.readContiguousElements(a),this.currentSegment=null,t.id===X.Tags?e.tagsSeen=!0:t.id===X.Attachments&&(e.attachmentsSeen=!0)}}readContiguousElements(e,t){for(;e.remainingLength>=2;){let n=e.filePos;if(!this.traverseElement(e,t))return n}return e.filePos}traverseElement(e,t){let n=Gw(e);if(!n||t&&t.includes(n.id))return!1;let{id:r,size:i}=n,a=e.filePos;switch(Qw(i),r){case X.DocType:this.isWebM=Kw(e,i)===`webm`;break;case X.Seek:{if(!this.currentSegment)break;let t={id:-1,segmentPosition:-1};this.currentSegment.seekEntries.push(t),this.readContiguousElements(e.slice(a,i)),(t.id===-1||t.segmentPosition===-1)&&this.currentSegment.seekEntries.pop()}break;case X.SeekID:{let t=this.currentSegment?.seekEntries[this.currentSegment.seekEntries.length-1];if(!t)break;t.id=Vw(e,i)}break;case X.SeekPosition:{let t=this.currentSegment?.seekEntries[this.currentSegment.seekEntries.length-1];if(!t)break;t.segmentPosition=Vw(e,i)}break;case X.TimestampScale:if(!this.currentSegment)break;this.currentSegment.timestampScale=Vw(e,i),this.currentSegment.timestampFactor=1e9/this.currentSegment.timestampScale;break;case X.Duration:if(!this.currentSegment)break;this.currentSegment.duration=Jw(e,i);break;case X.TrackEntry:if(!this.currentSegment||(this.currentTrack={id:-1,segment:this.currentSegment,demuxer:this,clusterPositionCache:[],cuePoints:[],disposition:{...Ix},inputTrack:null,codecId:null,codecPrivate:null,defaultDuration:null,defaultDurationNs:null,name:null,languageCode:`und`,decodingInstructions:[],info:null},this.readContiguousElements(e.slice(a,i)),!this.currentTrack))break;if(this.currentTrack.decodingInstructions.some(e=>e.data?.type!==`decompress`||e.scope!==tT.Block||e.data.algorithm!==nT.HeaderStripping)&&(console.warn(`Track #${this.currentTrack.id} has an unsupported content encoding; dropping.`),this.currentTrack=null),this.currentTrack&&this.currentTrack.id!==-1&&this.currentTrack.codecId&&this.currentTrack.info){let e=this.currentTrack.codecId.indexOf(`/`),t=e===-1?this.currentTrack.codecId:this.currentTrack.codecId.slice(0,e);if(this.currentTrack.info.type===`video`&&this.currentTrack.info.width!==-1&&this.currentTrack.info.height!==-1){if(this.currentTrack.info.squarePixelWidth=this.currentTrack.info.width,this.currentTrack.info.squarePixelHeight=this.currentTrack.info.height,this.currentTrack.info.displayWidth!==null&&this.currentTrack.info.displayHeight!==null){let e=this.currentTrack.info.displayWidth*this.currentTrack.info.height,t=this.currentTrack.info.displayHeight*this.currentTrack.info.width;e>t?this.currentTrack.info.squarePixelWidth=Math.round(this.currentTrack.info.width*e/t):this.currentTrack.info.squarePixelHeight=Math.round(this.currentTrack.info.height*t/e)}this.currentTrack.codecId===Zw.avc?(this.currentTrack.info.codec=`avc`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):this.currentTrack.codecId===Zw.hevc?(this.currentTrack.info.codec=`hevc`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):t===Zw.vp8?this.currentTrack.info.codec=`vp8`:t===Zw.vp9?this.currentTrack.info.codec=`vp9`:t===Zw.av1&&(this.currentTrack.info.codec=`av1`);let e=this.currentTrack,n=new gw(this.input,new sT(e));this.currentTrack.inputTrack=n,this.currentSegment.tracks.push(this.currentTrack)}else if(this.currentTrack.info.type===`audio`&&this.currentTrack.info.numberOfChannels!==-1&&this.currentTrack.info.sampleRate!==-1){t===Zw.aac?(this.currentTrack.info.codec=`aac`,this.currentTrack.info.aacCodecInfo={isMpeg2:this.currentTrack.codecId.includes(`MPEG2`),objectType:null},this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):this.currentTrack.codecId===Zw.mp3?this.currentTrack.info.codec=`mp3`:t===Zw.opus?(this.currentTrack.info.codec=`opus`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate,this.currentTrack.info.sampleRate=aS):t===Zw.vorbis?(this.currentTrack.info.codec=`vorbis`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):t===Zw.flac?(this.currentTrack.info.codec=`flac`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):t===Zw.ac3?(this.currentTrack.info.codec=`ac3`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):t===Zw.eac3?(this.currentTrack.info.codec=`eac3`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):this.currentTrack.codecId===`A_PCM/INT/LIT`?this.currentTrack.info.bitDepth===8?this.currentTrack.info.codec=`pcm-u8`:this.currentTrack.info.bitDepth===16?this.currentTrack.info.codec=`pcm-s16`:this.currentTrack.info.bitDepth===24?this.currentTrack.info.codec=`pcm-s24`:this.currentTrack.info.bitDepth===32&&(this.currentTrack.info.codec=`pcm-s32`):this.currentTrack.codecId===`A_PCM/INT/BIG`?this.currentTrack.info.bitDepth===8?this.currentTrack.info.codec=`pcm-u8`:this.currentTrack.info.bitDepth===16?this.currentTrack.info.codec=`pcm-s16be`:this.currentTrack.info.bitDepth===24?this.currentTrack.info.codec=`pcm-s24be`:this.currentTrack.info.bitDepth===32&&(this.currentTrack.info.codec=`pcm-s32be`):this.currentTrack.codecId===`A_PCM/FLOAT/IEEE`&&(this.currentTrack.info.bitDepth===32?this.currentTrack.info.codec=`pcm-f32`:this.currentTrack.info.bitDepth===64&&(this.currentTrack.info.codec=`pcm-f64`));let e=this.currentTrack,n=new _w(this.input,new cT(e));this.currentTrack.inputTrack=n,this.currentSegment.tracks.push(this.currentTrack)}}this.currentTrack=null;break;case X.TrackNumber:if(!this.currentTrack)break;this.currentTrack.id=Vw(e,i);break;case X.TrackType:{if(!this.currentTrack)break;let t=Vw(e,i);t===1?this.currentTrack.info={type:`video`,width:-1,height:-1,displayWidth:null,displayHeight:null,displayUnit:null,squarePixelWidth:-1,squarePixelHeight:-1,rotation:0,codec:null,codecDescription:null,colorSpace:null,alphaMode:!1}:t===2&&(this.currentTrack.info={type:`audio`,numberOfChannels:-1,sampleRate:-1,bitDepth:-1,codec:null,codecDescription:null,aacCodecInfo:null})}break;case X.FlagEnabled:if(!this.currentTrack)break;Vw(e,i)||(this.currentTrack=null);break;case X.FlagDefault:if(!this.currentTrack)break;this.currentTrack.disposition.default=!!Vw(e,i);break;case X.FlagForced:if(!this.currentTrack)break;this.currentTrack.disposition.forced=!!Vw(e,i);break;case X.FlagOriginal:if(!this.currentTrack)break;this.currentTrack.disposition.original=!!Vw(e,i);break;case X.FlagHearingImpaired:if(!this.currentTrack)break;this.currentTrack.disposition.hearingImpaired=!!Vw(e,i);break;case X.FlagVisualImpaired:if(!this.currentTrack)break;this.currentTrack.disposition.visuallyImpaired=!!Vw(e,i);break;case X.FlagCommentary:if(!this.currentTrack)break;this.currentTrack.disposition.commentary=!!Vw(e,i);break;case X.CodecID:if(!this.currentTrack)break;this.currentTrack.codecId=Kw(e,i);break;case X.CodecPrivate:if(!this.currentTrack)break;this.currentTrack.codecPrivate=jE(e,i);break;case X.DefaultDuration:if(!this.currentTrack)break;this.currentTrack.defaultDurationNs=Vw(e,i);break;case X.Name:if(!this.currentTrack)break;this.currentTrack.name=qw(e,i);break;case X.Language:if(!this.currentTrack||this.currentTrack.languageCode!==`und`)break;this.currentTrack.languageCode=Kw(e,i),ux(this.currentTrack.languageCode)||(this.currentTrack.languageCode=`und`);break;case X.LanguageBCP47:{if(!this.currentTrack)break;let t=Kw(e,i).split(`-`)[0];t?this.currentTrack.languageCode=t:this.currentTrack.languageCode=`und`}break;case X.Video:if(this.currentTrack?.info?.type!==`video`)break;this.readContiguousElements(e.slice(a,i));break;case X.PixelWidth:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.width=Vw(e,i);break;case X.PixelHeight:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.height=Vw(e,i);break;case X.DisplayWidth:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.displayWidth=Vw(e,i);break;case X.DisplayHeight:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.displayHeight=Vw(e,i);break;case X.DisplayUnit:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.displayUnit=Vw(e,i);break;case X.AlphaMode:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.alphaMode=Vw(e,i)===1;break;case X.Colour:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.colorSpace={},this.readContiguousElements(e.slice(a,i));break;case X.MatrixCoefficients:{if(this.currentTrack?.info?.type!==`video`||!this.currentTrack.info.colorSpace)break;let t=Rb[Vw(e,i)]??null;this.currentTrack.info.colorSpace.matrix=t}break;case X.Range:if(this.currentTrack?.info?.type!==`video`||!this.currentTrack.info.colorSpace)break;this.currentTrack.info.colorSpace.fullRange=Vw(e,i)===2;break;case X.TransferCharacteristics:{if(this.currentTrack?.info?.type!==`video`||!this.currentTrack.info.colorSpace)break;let t=Ib[Vw(e,i)]??null;this.currentTrack.info.colorSpace.transfer=t}break;case X.Primaries:{if(this.currentTrack?.info?.type!==`video`||!this.currentTrack.info.colorSpace)break;let t=Pb[Vw(e,i)]??null;this.currentTrack.info.colorSpace.primaries=t}break;case X.Projection:if(this.currentTrack?.info?.type!==`video`)break;this.readContiguousElements(e.slice(a,i));break;case X.ProjectionPoseRoll:{if(this.currentTrack?.info?.type!==`video`)break;let t=-Jw(e,i);try{this.currentTrack.info.rotation=wb(t)}catch{}}break;case X.Audio:if(this.currentTrack?.info?.type!==`audio`)break;this.readContiguousElements(e.slice(a,i));break;case X.SamplingFrequency:if(this.currentTrack?.info?.type!==`audio`)break;this.currentTrack.info.sampleRate=Jw(e,i);break;case X.Channels:if(this.currentTrack?.info?.type!==`audio`)break;this.currentTrack.info.numberOfChannels=Vw(e,i);break;case X.BitDepth:if(this.currentTrack?.info?.type!==`audio`)break;this.currentTrack.info.bitDepth=Vw(e,i);break;case X.CuePoint:if(!this.currentSegment)break;this.readContiguousElements(e.slice(a,i)),this.currentCueTime=null;break;case X.CueTime:this.currentCueTime=Vw(e,i);break;case X.CueTrackPositions:{if(this.currentCueTime===null)break;J(this.currentSegment);let t={time:this.currentCueTime,trackId:-1,clusterPosition:-1};this.currentSegment.cuePoints.push(t),this.readContiguousElements(e.slice(a,i)),(t.trackId===-1||t.clusterPosition===-1)&&this.currentSegment.cuePoints.pop()}break;case X.CueTrack:{let t=this.currentSegment?.cuePoints[this.currentSegment.cuePoints.length-1];if(!t)break;t.trackId=Vw(e,i)}break;case X.CueClusterPosition:{let t=this.currentSegment?.cuePoints[this.currentSegment.cuePoints.length-1];if(!t)break;J(this.currentSegment),t.clusterPosition=this.currentSegment.dataStartPos+Vw(e,i)}break;case X.Timestamp:if(!this.currentCluster)break;this.currentCluster.timestamp=Vw(e,i);break;case X.SimpleBlock:{if(!this.currentCluster)break;let t=Bw(e);if(t===null)break;let n=this.getTrackDataInCluster(this.currentCluster,t);if(!n)break;let r=IE(e),o=ME(e),s=o>>1&3,c=!!(o&128);n.track.info?.type===`audio`&&n.track.info.codec&&(c=!0);let l=jE(e,i-(e.filePos-a)),u=n.track.decodingInstructions.length>0;n.blocks.push({timestamp:r,duration:0,isKeyFrame:c,data:l,lacing:s,decoded:!u,mainAdditional:null})}break;case X.BlockGroup:if(!this.currentCluster)break;this.readContiguousElements(e.slice(a,i)),this.currentBlock=null;break;case X.Block:{if(!this.currentCluster)break;let t=Bw(e);if(t===null)break;let n=this.getTrackDataInCluster(this.currentCluster,t);if(!n)break;let r=IE(e),o=ME(e)>>1&3;this.currentBlock={timestamp:r,duration:0,isKeyFrame:!0,data:jE(e,i-(e.filePos-a)),lacing:o,decoded:!(n.track.decodingInstructions.length>0),mainAdditional:null},n.blocks.push(this.currentBlock)}break;case X.BlockAdditions:this.readContiguousElements(e.slice(a,i));break;case X.BlockMore:if(!this.currentBlock)break;this.currentBlockAdditional={addId:1,data:null},this.readContiguousElements(e.slice(a,i)),this.currentBlockAdditional.data&&this.currentBlockAdditional.addId===1&&(this.currentBlock.mainAdditional=this.currentBlockAdditional.data),this.currentBlockAdditional=null;break;case X.BlockAdditional:if(!this.currentBlockAdditional)break;this.currentBlockAdditional.data=jE(e,i);break;case X.BlockAddID:if(!this.currentBlockAdditional)break;this.currentBlockAdditional.addId=Vw(e,i);break;case X.BlockDuration:if(!this.currentBlock)break;this.currentBlock.duration=Vw(e,i);break;case X.ReferenceBlock:if(!this.currentBlock)break;this.currentBlock.isKeyFrame=!1;break;case X.Tag:this.currentTagTargetIsMovie=!0,this.readContiguousElements(e.slice(a,i));break;case X.Targets:this.readContiguousElements(e.slice(a,i));break;case X.TargetTypeValue:Vw(e,i)!==50&&(this.currentTagTargetIsMovie=!1);break;case X.TagTrackUID:case X.TagEditionUID:case X.TagChapterUID:case X.TagAttachmentUID:this.currentTagTargetIsMovie=!1;break;case X.SimpleTag:if(!this.currentTagTargetIsMovie)break;this.currentSimpleTagName=null,this.readContiguousElements(e.slice(a,i));break;case X.TagName:this.currentSimpleTagName=qw(e,i);break;case X.TagString:{if(!this.currentSimpleTagName)break;let t=qw(e,i);this.processTagValue(this.currentSimpleTagName,t)}break;case X.TagBinary:{if(!this.currentSimpleTagName)break;let t=jE(e,i);this.processTagValue(this.currentSimpleTagName,t)}break;case X.AttachedFile:{if(!this.currentSegment)break;this.currentAttachedFile={fileUid:null,fileName:null,fileMediaType:null,fileData:null,fileDescription:null},this.readContiguousElements(e.slice(a,i));let t=this.currentSegment.metadataTags;if(this.currentAttachedFile.fileUid&&this.currentAttachedFile.fileData&&(t.raw??={},t.raw[this.currentAttachedFile.fileUid.toString()]=new Px(this.currentAttachedFile.fileData,this.currentAttachedFile.fileMediaType??void 0,this.currentAttachedFile.fileName??void 0,this.currentAttachedFile.fileDescription??void 0)),this.currentAttachedFile.fileMediaType?.startsWith(`image/`)&&this.currentAttachedFile.fileData){let e=this.currentAttachedFile.fileName,n=`unknown`;if(e){let t=e.toLowerCase();t.startsWith(`cover.`)?n=`coverFront`:t.startsWith(`back.`)&&(n=`coverBack`)}t.images??=[],t.images.push({data:this.currentAttachedFile.fileData,mimeType:this.currentAttachedFile.fileMediaType,kind:n,name:this.currentAttachedFile.fileName??void 0,description:this.currentAttachedFile.fileDescription??void 0})}this.currentAttachedFile=null}break;case X.FileUID:if(!this.currentAttachedFile)break;this.currentAttachedFile.fileUid=Hw(e,i);break;case X.FileName:if(!this.currentAttachedFile)break;this.currentAttachedFile.fileName=qw(e,i);break;case X.FileMediaType:if(!this.currentAttachedFile)break;this.currentAttachedFile.fileMediaType=Kw(e,i);break;case X.FileData:if(!this.currentAttachedFile)break;this.currentAttachedFile.fileData=jE(e,i);break;case X.FileDescription:if(!this.currentAttachedFile)break;this.currentAttachedFile.fileDescription=qw(e,i);break;case X.ContentEncodings:if(!this.currentTrack)break;this.readContiguousElements(e.slice(a,i)),this.currentTrack.decodingInstructions.sort((e,t)=>t.order-e.order);break;case X.ContentEncoding:this.currentDecodingInstruction={order:0,scope:tT.Block,data:null},this.readContiguousElements(e.slice(a,i)),this.currentDecodingInstruction.data&&this.currentTrack.decodingInstructions.push(this.currentDecodingInstruction),this.currentDecodingInstruction=null;break;case X.ContentEncodingOrder:if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.order=Vw(e,i);break;case X.ContentEncodingScope:if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.scope=Vw(e,i);break;case X.ContentCompression:if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.data={type:`decompress`,algorithm:nT.Zlib,settings:null},this.readContiguousElements(e.slice(a,i));break;case X.ContentCompAlgo:if(this.currentDecodingInstruction?.data?.type!==`decompress`)break;this.currentDecodingInstruction.data.algorithm=Vw(e,i);break;case X.ContentCompSettings:if(this.currentDecodingInstruction?.data?.type!==`decompress`)break;this.currentDecodingInstruction.data.settings=jE(e,i);break;case X.ContentEncryption:if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.data={type:`decrypt`};break}return e.filePos=a+i,!0}decodeBlockData(e,t){J(e.decodingInstructions.length>0);let n=t;for(let t of e.decodingInstructions)switch(J(t.data),t.data.type){case`decompress`:switch(t.data.algorithm){case nT.HeaderStripping:if(t.data.settings&&t.data.settings.length>0){let e=t.data.settings,r=new Uint8Array(e.length+n.length);r.set(e,0),r.set(n,e.length),n=r}break;default:}break;default:}return n}processTagValue(e,t){if(!this.currentSegment?.metadataTags)return;let n=this.currentSegment.metadataTags;if(n.raw??={},n.raw[e]??=t,typeof t==`string`)switch(e.toLowerCase()){case`title`:n.title??=t;break;case`description`:n.description??=t;break;case`artist`:n.artist??=t;break;case`album`:n.album??=t;break;case`album_artist`:n.albumArtist??=t;break;case`genre`:n.genre??=t;break;case`comment`:n.comment??=t;break;case`lyrics`:n.lyrics??=t;break;case`date`:{let e=new Date(t);Number.isNaN(e.getTime())||(n.date??=e)}break;case`track_number`:case`part_number`:{let e=t.split(`/`),r=Number.parseInt(e[0],10),i=e[1]&&Number.parseInt(e[1],10);Number.isInteger(r)&&r>0&&(n.trackNumber??=r),i&&Number.isInteger(i)&&i>0&&(n.tracksTotal??=i)}break;case`disc_number`:case`disc`:{let e=t.split(`/`),r=Number.parseInt(e[0],10),i=e[1]&&Number.parseInt(e[1],10);Number.isInteger(r)&&r>0&&(n.discNumber??=r),i&&Number.isInteger(i)&&i>0&&(n.discsTotal??=i)}break}}},oT=class{constructor(e){this.internalTrack=e,this.packetToClusterLocation=new WeakMap}getId(){return this.internalTrack.id}getNumber(){let e=this.internalTrack.demuxer,t=this.internalTrack.inputTrack.type,n=0;for(let r of e.segments)for(let e of r.tracks)if(e.inputTrack.type===t&&n++,e===this.internalTrack)break;return n}getCodec(){throw Error(`Not implemented on base class.`)}getInternalCodecId(){return this.internalTrack.codecId}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}getName(){return this.internalTrack.name}getLanguageCode(){return this.internalTrack.languageCode}async getFirstTimestamp(){return(await this.getFirstPacket({metadataOnly:!0}))?.timestamp??0}getTimeResolution(){return this.internalTrack.segment.timestampFactor}getDisposition(){return this.internalTrack.disposition}async getFirstPacket(e){return this.performClusterLookup(null,e=>e.trackData.get(this.internalTrack.id)?{blockIndex:0,correctBlockFound:!0}:{blockIndex:-1,correctBlockFound:!1},-1/0,1/0,e)}intoTimescale(e){return ax(e*this.internalTrack.segment.timestampFactor)}async getPacket(e,t){let n=this.intoTimescale(e);return this.performClusterLookup(null,e=>{let t=e.trackData.get(this.internalTrack.id);if(!t)return{blockIndex:-1,correctBlockFound:!1};let r=Gb(t.presentationTimestamps,n,e=>e.timestamp);return{blockIndex:r===-1?-1:t.presentationTimestamps[r].blockIndex,correctBlockFound:r!==-1&&n<t.endTimestamp}},n,n,t)}async getNextPacket(e,t){let n=this.packetToClusterLocation.get(e);if(n===void 0)throw Error(`Packet was not created from this track.`);return this.performClusterLookup(n.cluster,e=>{if(e===n.cluster){let t=e.trackData.get(this.internalTrack.id);if(n.blockIndex+1<t.blocks.length)return{blockIndex:n.blockIndex+1,correctBlockFound:!0}}else if(e.trackData.get(this.internalTrack.id))return{blockIndex:0,correctBlockFound:!0};return{blockIndex:-1,correctBlockFound:!1}},-1/0,1/0,t)}async getKeyPacket(e,t){let n=this.intoTimescale(e);return this.performClusterLookup(null,e=>{let t=e.trackData.get(this.internalTrack.id);if(!t)return{blockIndex:-1,correctBlockFound:!1};let r=Yb(t.presentationTimestamps,e=>t.blocks[e.blockIndex].isKeyFrame&&e.timestamp<=n);return{blockIndex:r===-1?-1:t.presentationTimestamps[r].blockIndex,correctBlockFound:r!==-1&&n<t.endTimestamp}},n,n,t)}async getNextKeyPacket(e,t){let n=this.packetToClusterLocation.get(e);if(n===void 0)throw Error(`Packet was not created from this track.`);return this.performClusterLookup(n.cluster,e=>{if(e===n.cluster){let t=e.trackData.get(this.internalTrack.id).blocks.findIndex((e,t)=>e.isKeyFrame&&t>n.blockIndex);if(t!==-1)return{blockIndex:t,correctBlockFound:!0}}else{let t=e.trackData.get(this.internalTrack.id);if(t&&t.firstKeyFrameTimestamp!==null){let e=t.blocks.findIndex(e=>e.isKeyFrame);return J(e!==-1),{blockIndex:e,correctBlockFound:!0}}}return{blockIndex:-1,correctBlockFound:!1}},-1/0,1/0,t)}async fetchPacketInCluster(e,t,n){if(t===-1)return null;let r=e.trackData.get(this.internalTrack.id).blocks[t];J(r),r.decoded||=(r.data=this.internalTrack.demuxer.decodeBlockData(this.internalTrack,r.data),!0);let i=n.metadataOnly?DC:r.data,a=r.timestamp/this.internalTrack.segment.timestampFactor,o=r.duration/this.internalTrack.segment.timestampFactor,s={};r.mainAdditional&&this.internalTrack.info?.type===`video`&&this.internalTrack.info.alphaMode&&(s.alpha=n.metadataOnly?DC:r.mainAdditional,s.alphaByteLength=r.mainAdditional.byteLength);let c=new OC(i,r.isKeyFrame?`key`:`delta`,a,o,e.dataStartPos+t,r.data.byteLength,s);return this.packetToClusterLocation.set(c,{cluster:e,blockIndex:t}),c}async performClusterLookup(e,t,n,r,i){let{demuxer:a,segment:o}=this.internalTrack,s=null,c=null,l=-1;if(e){let{blockIndex:n,correctBlockFound:r}=t(e);if(r)return this.fetchPacketInCluster(e,n,i);n!==-1&&(c=e,l=n)}let u=Gb(this.internalTrack.cuePoints,n,e=>e.time),d=u===-1?null:this.internalTrack.cuePoints[u],f=Gb(this.internalTrack.clusterPositionCache,n,e=>e.startTimestamp),p=f===-1?null:this.internalTrack.clusterPositionCache[f],m=Math.max(d?.clusterPosition??0,p?.elementStartPos??0)||null,h;for(e?m===null||e.elementStartPos>=m?(h=e.elementEndPos,s=e):h=m:h=m??o.clusterSeekStartPos;o.elementEndPos===null||h<=o.elementEndPos-2;){if(s){let e=s.trackData.get(this.internalTrack.id);if(e&&e.startTimestamp>r)break}let e=a.reader.requestSliceRange(h,2,16);if(e instanceof Promise&&(e=await e),!e)break;let n=h,u=Gw(e);if(!u||!Lw.includes(u.id)&&u.id!==X.Void){let e=await Xw(a.reader,n,Lw,Math.min(o.elementEndPos??1/0,n+iT));if(e){h=e;continue}else break}let d=u.id,f=u.size,p=e.filePos;if(d===X.Cluster){s=await a.readCluster(n,o),f=s.elementEndPos-p;let{blockIndex:e,correctBlockFound:r}=t(s);if(r)return this.fetchPacketInCluster(s,e,i);e!==-1&&(c=s,l=e)}f===void 0&&(J(d!==X.Cluster),f=(await Yw(a.reader,p,Rw,o.elementEndPos)).pos-p);let m=p+f;if(o.elementEndPos===null){let e=a.reader.requestSliceRange(m,2,16);if(e instanceof Promise&&(e=await e),!e)break;if(Uw(e)===X.Segment){o.elementEndPos=m;break}}h=m}if(d&&(!c||c.elementStartPos<d.clusterPosition)){let e=this.internalTrack.cuePoints[u-1];J(!e||e.time<d.time);let n=e?.time??-1/0;return this.performClusterLookup(null,t,n,r,i)}return c?this.fetchPacketInCluster(c,l,i):null}},sT=class extends oT{constructor(e){super(e),this.decoderConfigPromise=null,this.internalTrack=e}getCodec(){return this.internalTrack.info.codec}getCodedWidth(){return this.internalTrack.info.width}getCodedHeight(){return this.internalTrack.info.height}getSquarePixelWidth(){return this.internalTrack.info.squarePixelWidth}getSquarePixelHeight(){return this.internalTrack.info.squarePixelHeight}getRotation(){return this.internalTrack.info.rotation}async getColorSpace(){return{primaries:this.internalTrack.info.colorSpace?.primaries,transfer:this.internalTrack.info.colorSpace?.transfer,matrix:this.internalTrack.info.colorSpace?.matrix,fullRange:this.internalTrack.info.colorSpace?.fullRange}}async canBeTransparent(){return this.internalTrack.info.alphaMode}async getDecoderConfig(){return this.internalTrack.info.codec?this.decoderConfigPromise??=(async()=>{let e=null;return(this.internalTrack.info.codec===`vp9`||this.internalTrack.info.codec===`av1`||this.internalTrack.info.codec===`avc`&&!this.internalTrack.info.codecDescription||this.internalTrack.info.codec===`hevc`&&!this.internalTrack.info.codecDescription)&&(e=await this.getFirstPacket({})),{codec:nS({width:this.internalTrack.info.width,height:this.internalTrack.info.height,codec:this.internalTrack.info.codec,codecDescription:this.internalTrack.info.codecDescription,colorSpace:this.internalTrack.info.colorSpace,avcType:1,avcCodecInfo:this.internalTrack.info.codec===`avc`&&e?zS(e.data):null,hevcCodecInfo:this.internalTrack.info.codec===`hevc`&&e?JS(e.data):null,vp9CodecInfo:this.internalTrack.info.codec===`vp9`&&e?rC(e.data):null,av1CodecInfo:this.internalTrack.info.codec===`av1`&&e?aC(e.data):null}),codedWidth:this.internalTrack.info.width,codedHeight:this.internalTrack.info.height,displayAspectWidth:this.internalTrack.info.squarePixelWidth,displayAspectHeight:this.internalTrack.info.squarePixelHeight,description:this.internalTrack.info.codecDescription??void 0,colorSpace:this.internalTrack.info.colorSpace??void 0}})():null}},cT=class extends oT{constructor(e){super(e),this.decoderConfig=null,this.internalTrack=e}getCodec(){return this.internalTrack.info.codec}getNumberOfChannels(){return this.internalTrack.info.numberOfChannels}getSampleRate(){return this.internalTrack.info.sampleRate}async getDecoderConfig(){return this.internalTrack.info.codec?this.decoderConfig??={codec:iS({codec:this.internalTrack.info.codec,codecDescription:this.internalTrack.info.codecDescription,aacCodecInfo:this.internalTrack.info.aacCodecInfo}),numberOfChannels:this.internalTrack.info.numberOfChannels,sampleRate:this.internalTrack.info.sampleRate,description:this.internalTrack.info.codecDescription??void 0}:null}},lT=async(e,t,n)=>{let r=t;for(;n===null||r<n;){let t=e.requestSlice(r,4);if(t instanceof Promise&&(t=await t),!t)break;let n=wS(Z(t),e.fileSize===null?null:e.fileSize-r);if(n.header)return{header:n.header,startPos:r};r+=n.bytesAdvanced}return null},uT=class extends SC{constructor(e){super(e),this.metadataPromise=null,this.firstFrameHeader=null,this.loadedSamples=[],this.metadataTags=null,this.tracks=[],this.readingMutex=new Vb,this.lastSampleLoaded=!1,this.lastLoadedPos=0,this.nextTimestampInSamples=0,this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{for(;!this.firstFrameHeader&&!this.lastSampleLoaded;)await this.advanceReader();if(!this.firstFrameHeader)throw Error(`No valid MP3 frame found.`);this.tracks=[new _w(this.input,new dT(this))]})()}async advanceReader(){if(this.lastLoadedPos===0)for(;;){let e=this.reader.requestSlice(this.lastLoadedPos,10);if(e instanceof Promise&&(e=await e),!e){this.lastSampleLoaded=!0;return}let t=$E(e);if(!t)break;this.lastLoadedPos=e.filePos+t.size}let e=await lT(this.reader,this.lastLoadedPos,this.reader.fileSize);if(!e){this.lastSampleLoaded=!0;return}let t=e.header;this.lastLoadedPos=e.startPos+t.totalSize-1;let n=CS(t.mpegVersionId,t.channel),r=this.reader.requestSlice(e.startPos+n,4);if(r instanceof Promise&&(r=await r),r){let e=Z(r);if(e===1483304551||e===1231971951)return}this.firstFrameHeader||=t,t.sampleRate!==this.firstFrameHeader.sampleRate&&console.warn(`MP3 changed sample rate mid-file: ${this.firstFrameHeader.sampleRate} Hz to ${t.sampleRate} Hz. Might be a bug, so please report this file.`);let i=t.audioSamplesInFrame/this.firstFrameHeader.sampleRate,a={timestamp:this.nextTimestampInSamples/this.firstFrameHeader.sampleRate,duration:i,dataStart:e.startPos,dataSize:t.totalSize};this.loadedSamples.push(a),this.nextTimestampInSamples+=t.audioSamplesInFrame}async getMimeType(){return`audio/mpeg`}async getTracks(){return await this.readMetadata(),this.tracks}async computeDuration(){await this.readMetadata();let e=this.tracks[0];return J(e),e.computeDuration()}async getMetadataTags(){let e=await this.readingMutex.acquire();try{if(await this.readMetadata(),this.metadataTags)return this.metadataTags;this.metadataTags={};let e=0,t=!1;for(;;){let n=this.reader.requestSlice(e,10);if(n instanceof Promise&&(n=await n),!n)break;let r=$E(n);if(!r)break;t=!0;let i=this.reader.requestSlice(n.filePos,r.size);if(i instanceof Promise&&(i=await i),!i)break;eD(i,r,this.metadataTags),e=n.filePos+r.size}if(!t&&this.reader.fileSize!==null&&this.reader.fileSize>=128){let e=this.reader.requestSlice(this.reader.fileSize-128,128);e instanceof Promise&&(e=await e),J(e),qE(e,3)===`TAG`&&ZE(e,this.metadataTags)}return this.metadataTags}finally{e()}}},dT=class{constructor(e){this.demuxer=e}getId(){return 1}getNumber(){return 1}async getFirstTimestamp(){return 0}getTimeResolution(){return J(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.sampleRate/this.demuxer.firstFrameHeader.audioSamplesInFrame}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}getName(){return null}getLanguageCode(){return`und`}getCodec(){return`mp3`}getInternalCodecId(){return null}getNumberOfChannels(){return J(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.channel===3?1:2}getSampleRate(){return J(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.sampleRate}getDisposition(){return{...Ix}}async getDecoderConfig(){return J(this.demuxer.firstFrameHeader),{codec:`mp3`,numberOfChannels:this.demuxer.firstFrameHeader.channel===3?1:2,sampleRate:this.demuxer.firstFrameHeader.sampleRate}}async getPacketAtIndex(e,t){if(e===-1)return null;let n=this.demuxer.loadedSamples[e];if(!n)return null;let r;if(t.metadataOnly)r=DC;else{let e=this.demuxer.reader.requestSlice(n.dataStart,n.dataSize);if(e instanceof Promise&&(e=await e),!e)return null;r=jE(e,n.dataSize)}return new OC(r,`key`,n.timestamp,n.duration,e,n.dataSize)}getFirstPacket(e){return this.getPacketAtIndex(0,e)}async getNextPacket(e,t){let n=await this.demuxer.readingMutex.acquire();try{let n=Wb(this.demuxer.loadedSamples,e.timestamp,e=>e.timestamp);if(n===-1)throw Error(`Packet was not created from this track.`);let r=n+1;for(;r>=this.demuxer.loadedSamples.length&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(r,t)}finally{n()}}async getPacket(e,t){let n=await this.demuxer.readingMutex.acquire();try{for(;;){let n=Gb(this.demuxer.loadedSamples,e,e=>e.timestamp);if(n===-1&&this.demuxer.loadedSamples.length>0)return null;if(this.demuxer.lastSampleLoaded||n>=0&&n+1<this.demuxer.loadedSamples.length)return this.getPacketAtIndex(n,t);await this.demuxer.advanceReader()}}finally{n()}}getKeyPacket(e,t){return this.getPacket(e,t)}getNextKeyPacket(e,t){return this.getNextPacket(e,t)}},fT=79764919,pT=new Uint32Array(256);for(let e=0;e<256;e++){let t=e<<24;for(let e=0;e<8;e++)t=t&2147483648?t<<1^fT:t<<1;pT[e]=t>>>0&4294967295}var mT=e=>{let t=kb(e),n=t.getUint32(22,!0);t.setUint32(22,0,!0);let r=0;for(let t=0;t<e.length;t++){let n=e[t];r=(r<<8^pT[r>>>24^n])>>>0}return t.setUint32(22,n,!0),r},hT=(e,t,n)=>{let r=0,i=null;if(e.length>0)if(t.codec===`vorbis`){J(t.vorbisInfo);let a=t.vorbisInfo.modeBlockflags.length,o=(1<<cx(a-1))-1<<1,s=(e[0]&o)>>1;if(s>=t.vorbisInfo.modeBlockflags.length)throw Error(`Invalid mode number.`);let c=n,l=t.vorbisInfo.modeBlockflags[s];if(i=t.vorbisInfo.blocksizes[l],l===1){let n=(o|1)+1,r=e[0]&n?1:0;c=t.vorbisInfo.blocksizes[r]}r=c===null?0:c+i>>2}else t.codec===`opus`&&(r=cC(e).durationInSamples);return{durationInSamples:r,vorbisBlockSize:i}},gT=e=>{let t=`audio/ogg`;if(e.codecStrings){let n=[...new Set(e.codecStrings)];t+=`; codecs="${n.join(`, `)}"`}return t},_T=65307,vT=e=>{let t=e.filePos;if(RE(e)!==1399285583)return null;e.skip(1);let n=ME(e),r=WE(e),i=RE(e),a=RE(e),o=RE(e),s=ME(e),c=new Uint8Array(s);for(let t=0;t<s;t++)c[t]=ME(e);let l=27+s,u=c.reduce((e,t)=>e+t,0);return{headerStartPos:t,totalSize:l+u,dataStartPos:t+l,dataSize:u,headerType:n,granulePosition:r,serialNumber:i,sequenceNumber:a,checksum:o,lacingValues:c}},yT=(e,t)=>{for(;e.filePos<t-3;){let t=RE(e),n=t&255,r=t>>>8&255,i=t>>>16&255,a=t>>>24&255;if(!(n!==79&&r!==79&&i!==79&&a!==79)){if(e.skip(-4),t===1399285583)return!0;e.skip(1)}}return!1},bT=class extends SC{constructor(e){super(e),this.metadataPromise=null,this.bitstreams=[],this.tracks=[],this.metadataTags={},this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{let e=0;for(;;){let t=this.reader.requestSliceRange(e,27,282);if(t instanceof Promise&&(t=await t),!t)break;let n=vT(t);if(!n||!(n.headerType&2))break;this.bitstreams.push({serialNumber:n.serialNumber,bosPage:n,description:null,numberOfChannels:-1,sampleRate:-1,codecInfo:{codec:null,vorbisInfo:null,opusInfo:null},lastMetadataPacket:null}),e=n.headerStartPos+n.totalSize}for(let e of this.bitstreams){let t=await this.readPacket(e.bosPage,0);t&&(t.data.byteLength>=7&&t.data[0]===1&&t.data[1]===118&&t.data[2]===111&&t.data[3]===114&&t.data[4]===98&&t.data[5]===105&&t.data[6]===115?await this.readVorbisMetadata(t,e):t.data.byteLength>=8&&t.data[0]===79&&t.data[1]===112&&t.data[2]===117&&t.data[3]===115&&t.data[4]===72&&t.data[5]===101&&t.data[6]===97&&t.data[7]===100&&await this.readOpusMetadata(t,e),e.codecInfo.codec!==null&&this.tracks.push(new _w(this.input,new xT(e,this))))}})()}async readVorbisMetadata(e,t){let n=await this.findNextPacketStart(e);if(!n)return;let r=await this.readPacket(n.startPage,n.startSegmentIndex);if(!r||(n=await this.findNextPacketStart(r),!n))return;let i=await this.readPacket(n.startPage,n.startSegmentIndex);if(!i||r.data[0]!==3||i.data[0]!==5)return;let a=[],o=e=>{for(;a.push(Math.min(255,e)),!(e<255);)e-=255};o(e.data.length),o(r.data.length);let s=new Uint8Array(1+a.length+e.data.length+r.data.length+i.data.length);s[0]=2,s.set(a,1),s.set(e.data,1+a.length),s.set(r.data,1+a.length+e.data.length),s.set(i.data,1+a.length+e.data.length+r.data.length),t.codecInfo.codec=`vorbis`,t.description=s,t.lastMetadataPacket=i;let c=kb(e.data);t.numberOfChannels=c.getUint8(11),t.sampleRate=c.getUint32(12,!0);let l=c.getUint8(28);t.codecInfo.vorbisInfo={blocksizes:[1<<(l&15),1<<(l>>4)],modeBlockflags:lC(i.data).modeBlockflags},fC(r.data.subarray(7),this.metadataTags)}async readOpusMetadata(e,t){let n=await this.findNextPacketStart(e);if(!n)return;let r=await this.readPacket(n.startPage,n.startSegmentIndex);if(!r)return;t.codecInfo.codec=`opus`,t.description=e.data,t.lastMetadataPacket=r;let i=oC(e.data);t.numberOfChannels=i.outputChannelCount,t.sampleRate=aS,t.codecInfo.opusInfo={preSkip:i.preSkip},fC(r.data.subarray(8),this.metadataTags)}async readPacket(e,t){J(t<e.lacingValues.length);let n=0;for(let r=0;r<t;r++)n+=e.lacingValues[r];let r=e,i=n,a=t,o=[];outer:for(;;){let t=this.reader.requestSlice(r.dataStartPos,r.dataSize);t instanceof Promise&&(t=await t),J(t);let s=jE(t,r.dataSize);for(;;){if(a===r.lacingValues.length){o.push(s.subarray(n,i));break}let e=r.lacingValues[a];if(i+=e,e<255){o.push(s.subarray(n,i));break outer}a++}let c=r.headerStartPos+r.totalSize;for(;;){let t=this.reader.requestSliceRange(c,27,282);if(t instanceof Promise&&(t=await t),!t)return null;let n=vT(t);if(!n)return null;if(r=n,r.serialNumber===e.serialNumber)break;c=r.headerStartPos+r.totalSize}n=0,i=0,a=0}let s=o.reduce((e,t)=>e+t.length,0);if(s===0)return null;let c=new Uint8Array(s),l=0;for(let e=0;e<o.length;e++){let t=o[e];c.set(t,l),l+=t.length}return{data:c,endPage:r,endSegmentIndex:a}}async findNextPacketStart(e){if(e.endSegmentIndex<e.endPage.lacingValues.length-1)return{startPage:e.endPage,startSegmentIndex:e.endSegmentIndex+1};if(e.endPage.headerType&4)return null;let t=e.endPage.headerStartPos+e.endPage.totalSize;for(;;){let n=this.reader.requestSliceRange(t,27,282);if(n instanceof Promise&&(n=await n),!n)return null;let r=vT(n);if(!r)return null;if(r.serialNumber===e.endPage.serialNumber)return{startPage:r,startSegmentIndex:0};t=r.headerStartPos+r.totalSize}}async getMimeType(){return await this.readMetadata(),gT({codecStrings:(await Promise.all(this.tracks.map(e=>e.getCodecParameterString()))).filter(Boolean)})}async getTracks(){return await this.readMetadata(),this.tracks}async computeDuration(){let e=await this.getTracks(),t=await Promise.all(e.map(e=>e.computeDuration()));return Math.max(0,...t)}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}},xT=class{constructor(e,t){this.bitstream=e,this.demuxer=t,this.encodedPacketToMetadata=new WeakMap,this.sequentialScanCache=[],this.sequentialScanMutex=new Vb,this.internalSampleRate=e.codecInfo.codec===`opus`?aS:e.sampleRate}getId(){return this.bitstream.serialNumber}getNumber(){let e=this.demuxer.tracks.findIndex(e=>e._backing.bitstream===this.bitstream);return J(e!==-1),e+1}getNumberOfChannels(){return this.bitstream.numberOfChannels}getSampleRate(){return this.bitstream.sampleRate}getTimeResolution(){return this.bitstream.sampleRate}getCodec(){return this.bitstream.codecInfo.codec}getInternalCodecId(){return null}async getDecoderConfig(){return J(this.bitstream.codecInfo.codec),{codec:this.bitstream.codecInfo.codec,numberOfChannels:this.bitstream.numberOfChannels,sampleRate:this.bitstream.sampleRate,description:this.bitstream.description??void 0}}getName(){return null}getLanguageCode(){return`und`}getDisposition(){return{...Ix}}async getFirstTimestamp(){return 0}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}granulePositionToTimestampInSamples(e){return this.bitstream.codecInfo.codec===`opus`?(J(this.bitstream.codecInfo.opusInfo),e-this.bitstream.codecInfo.opusInfo.preSkip):e}createEncodedPacketFromOggPacket(e,t,n){if(!e)return null;let{durationInSamples:r,vorbisBlockSize:i}=hT(e.data,this.bitstream.codecInfo,t.vorbisLastBlocksize),a=new OC(n.metadataOnly?DC:e.data,`key`,Math.max(0,t.timestampInSamples)/this.internalSampleRate,r/this.internalSampleRate,e.endPage.headerStartPos+e.endSegmentIndex,e.data.byteLength);return this.encodedPacketToMetadata.set(a,{packet:e,timestampInSamples:t.timestampInSamples,durationInSamples:r,vorbisLastBlockSize:t.vorbisLastBlocksize,vorbisBlockSize:i}),a}async getFirstPacket(e){J(this.bitstream.lastMetadataPacket);let t=await this.demuxer.findNextPacketStart(this.bitstream.lastMetadataPacket);if(!t)return null;let n=0;this.bitstream.codecInfo.codec===`opus`&&(J(this.bitstream.codecInfo.opusInfo),n-=this.bitstream.codecInfo.opusInfo.preSkip);let r=await this.demuxer.readPacket(t.startPage,t.startSegmentIndex);return this.createEncodedPacketFromOggPacket(r,{timestampInSamples:n,vorbisLastBlocksize:null},e)}async getNextPacket(e,t){let n=this.encodedPacketToMetadata.get(e);if(!n)throw Error(`Packet was not created from this track.`);let r=await this.demuxer.findNextPacketStart(n.packet);if(!r)return null;let i=n.timestampInSamples+n.durationInSamples,a=await this.demuxer.readPacket(r.startPage,r.startSegmentIndex);return this.createEncodedPacketFromOggPacket(a,{timestampInSamples:i,vorbisLastBlocksize:n.vorbisBlockSize},t)}async getPacket(e,t){if(this.demuxer.reader.fileSize===null)return this.getPacketSequential(e,t);let n=ax(e*this.internalSampleRate);if(n===0)return this.getFirstPacket(t);if(n<0)return null;J(this.bitstream.lastMetadataPacket);let r=await this.demuxer.findNextPacketStart(this.bitstream.lastMetadataPacket);if(!r)return null;let i=r.startPage,a=this.demuxer.reader.fileSize,o=[i];outer:for(;i.headerStartPos+i.totalSize<a;){let e=i.headerStartPos,t=Math.floor((e+a)/2),r=t;for(;;){let e=Math.min(r+_T,a-27),s=this.demuxer.reader.requestSlice(r,e-r);if(s instanceof Promise&&(s=await s),J(s),!yT(s,e)){a=t+27;continue outer}let c=this.demuxer.reader.requestSliceRange(s.filePos,27,282);c instanceof Promise&&(c=await c),J(c);let l=vT(c);J(l);let u=!1;if(l.serialNumber===this.bitstream.serialNumber)u=!0;else{let e=this.demuxer.reader.requestSlice(l.headerStartPos,l.totalSize);e instanceof Promise&&(e=await e),J(e),u=mT(jE(e,l.totalSize))===l.checksum}if(!u){r=l.headerStartPos+4;continue}if(u&&l.serialNumber!==this.bitstream.serialNumber){r=l.headerStartPos+l.totalSize;continue}if(l.granulePosition===-1){r=l.headerStartPos+l.totalSize;continue}this.granulePositionToTimestampInSamples(l.granulePosition)>n?a=l.headerStartPos:(i=l,o.push(l));continue outer}}let s=r.startPage;for(let e of o){if(e.granulePosition===i.granulePosition)break;(!s||e.headerStartPos>s.headerStartPos)&&(s=e)}let c=s,l=[c];for(;!(c.serialNumber===this.bitstream.serialNumber&&c.granulePosition===i.granulePosition);){let e=c.headerStartPos+c.totalSize,t=this.demuxer.reader.requestSliceRange(e,27,282);t instanceof Promise&&(t=await t),J(t);let n=vT(t);J(n),c=n,c.serialNumber===this.bitstream.serialNumber&&l.push(c)}J(c.granulePosition!==-1);let u=null,d,f,p=c,m=0;if(c.headerStartPos===r.startPage.headerStartPos)d=this.granulePositionToTimestampInSamples(0),f=!0,u=0;else{d=0,f=!1;for(let e=c.lacingValues.length-1;e>=0;e--)if(c.lacingValues[e]<255){u=e+1;break}if(u===null)throw Error(`Invalid page with granule position: no packets end on this page.`);m=u-1;let e={data:DC,endPage:p,endSegmentIndex:m};if(await this.demuxer.findNextPacketStart(e)){let e=CT(l,c,u);J(e);let t=ST(l,e.page,e.segmentIndex);t&&(c=t.page,u=t.segmentIndex)}else for(;;){let e=CT(l,c,u);if(!e)break;let t=ST(l,e.page,e.segmentIndex);if(!t)break;if(c=t.page,u=t.segmentIndex,e.page.headerStartPos!==p.headerStartPos){p=e.page,m=e.segmentIndex;break}}}let h=null,g=null;for(;c!==null;){J(u!==null);let e=await this.demuxer.readPacket(c,u);if(!e)break;if(!(c.headerStartPos===r.startPage.headerStartPos&&u<r.startSegmentIndex)){let r=this.createEncodedPacketFromOggPacket(e,{timestampInSamples:d,vorbisLastBlocksize:g?.vorbisBlockSize??null},t);J(r);let i=this.encodedPacketToMetadata.get(r);if(J(i),!f&&e.endPage.headerStartPos===p.headerStartPos&&e.endSegmentIndex===m?(d=this.granulePositionToTimestampInSamples(c.granulePosition),f=!0,r=this.createEncodedPacketFromOggPacket(e,{timestampInSamples:d-i.durationInSamples,vorbisLastBlocksize:g?.vorbisBlockSize??null},t),J(r),i=this.encodedPacketToMetadata.get(r),J(i)):d+=i.durationInSamples,h=r,g=i,f&&(Math.max(d,0)>n||Math.max(i.timestampInSamples,0)===n))break}let i=await this.demuxer.findNextPacketStart(e);if(!i)break;c=i.startPage,u=i.startSegmentIndex}return h}async getPacketSequential(e,t){let n=await this.sequentialScanMutex.acquire();try{let n=ax(e*this.internalSampleRate);e=n/this.internalSampleRate;let r=Gb(this.sequentialScanCache,n,e=>e.timestampInSamples),i;if(r!==-1){let e=this.sequentialScanCache[r];i=this.createEncodedPacketFromOggPacket(e.packet,{timestampInSamples:e.timestampInSamples,vorbisLastBlocksize:e.vorbisLastBlockSize},t)}else i=await this.getFirstPacket(t);let a=0;for(;i&&i.timestamp<e;){let n=await this.getNextPacket(i,t);if(!n||n.timestamp>e)break;if(i=n,a++,a===100){a=0;let e=this.encodedPacketToMetadata.get(i);J(e),this.sequentialScanCache.length>0&&J(Tb(this.sequentialScanCache).timestampInSamples<=e.timestampInSamples),this.sequentialScanCache.push(e)}}return i}finally{n()}}getKeyPacket(e,t){return this.getPacket(e,t)}getNextKeyPacket(e,t){return this.getNextPacket(e,t)}},ST=(e,t,n)=>{let r=t,i=n;outer:for(;;){for(i--;i>=0;i--)if(r.lacingValues[i]<255){i++;break outer}if(J(i===-1),!(r.headerType&1)){i=0;break}let t=Jb(e,e=>e.headerStartPos<r.headerStartPos);if(!t)return null;r=t,i=r.lacingValues.length}if(J(i!==-1),i===r.lacingValues.length){let t=e[e.indexOf(r)+1];J(t),r=t,i=0}return{page:r,segmentIndex:i}},CT=(e,t,n)=>{if(n>0)return{page:t,segmentIndex:n-1};let r=Jb(e,e=>e.headerStartPos<t.headerStartPos);return r?{page:r,segmentIndex:r.lacingValues.length-1}:null},wT;(function(e){e[e.PCM=1]=`PCM`,e[e.IEEE_FLOAT=3]=`IEEE_FLOAT`,e[e.ALAW=6]=`ALAW`,e[e.MULAW=7]=`MULAW`,e[e.EXTENSIBLE=65534]=`EXTENSIBLE`})(wT||={});var TT=class extends SC{constructor(e){super(e),this.metadataPromise=null,this.dataStart=-1,this.dataSize=-1,this.audioInfo=null,this.tracks=[],this.lastKnownPacketIndex=0,this.metadataTags={},this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{let e=this.reader.requestSlice(0,12);e instanceof Promise&&(e=await e),J(e);let t=qE(e,4),n=t!==`RIFX`,r=t===`RF64`,i=LE(e,n),a=r?this.reader.fileSize:Math.min(i+8,this.reader.fileSize??1/0);if(qE(e,4)!==`WAVE`)throw Error(`Invalid WAVE file - wrong format`);let o=0,s=null,c=e.filePos;for(;a===null||c<a;){let e=this.reader.requestSlice(c,8);if(e instanceof Promise&&(e=await e),!e)break;let t=qE(e,4),i=LE(e,n),l=e.filePos;if(r&&o===0&&t!==`ds64`)throw Error(`Invalid RF64 file: First chunk must be "ds64".`);if(t===`fmt `)await this.parseFmtChunk(l,i,n);else if(t===`data`){if(s??=i,this.dataStart=e.filePos,this.dataSize=Math.min(s,(a??1/0)-this.dataStart),this.reader.fileSize===null)break}else if(t===`ds64`){let e=this.reader.requestSlice(l,i);if(e instanceof Promise&&(e=await e),!e)break;let t=VE(e,n);s=VE(e,n),a=Math.min(t+8,this.reader.fileSize??1/0)}else t===`LIST`?await this.parseListChunk(l,i,n):(t===`ID3 `||t===`id3 `)&&await this.parseId3Chunk(l,i);c=l+i+(i&1),o++}if(!this.audioInfo)throw Error(`Invalid WAVE file - missing "fmt " chunk`);if(this.dataStart===-1)throw Error(`Invalid WAVE file - missing "data" chunk`);let l=this.audioInfo.blockSizeInBytes;this.dataSize=Math.floor(this.dataSize/l)*l,this.tracks.push(new _w(this.input,new DT(this)))})()}async parseFmtChunk(e,t,n){let r=this.reader.requestSlice(e,t);if(r instanceof Promise&&(r=await r),!r)return;let i=NE(r,n),a=NE(r,n),o=LE(r,n);r.skip(4);let s=NE(r,n),c;if(c=t===14?8:NE(r,n),t>=18&&i!==357){let e=NE(r,n),a=t-18;if(Math.min(a,e)>=22&&i===wT.EXTENSIBLE){r.skip(6);let e=jE(r,16);i=e[0]|e[1]<<8}}(i===wT.MULAW||i===wT.ALAW)&&(c=8),this.audioInfo={format:i,numberOfChannels:a,sampleRate:o,sampleSizeInBytes:Math.ceil(c/8),blockSizeInBytes:s}}async parseListChunk(e,t,n){let r=this.reader.requestSlice(e,t);if(r instanceof Promise&&(r=await r),!r)return;let i=qE(r,4);if(i!==`INFO`&&i!==`INF0`)return;let a=r.filePos;for(;a<=e+t-8;){r.filePos=a;let e=qE(r,4),t=LE(r,n),i=jE(r,t),o=0;for(let e=0;e<i.length&&i[e]!==0;e++)o++;let s=String.fromCharCode(...i.subarray(0,o));switch(this.metadataTags.raw??={},this.metadataTags.raw[e]=s,e){case`INAM`:case`TITL`:this.metadataTags.title??=s;break;case`TIT3`:this.metadataTags.description??=s;break;case`IART`:this.metadataTags.artist??=s;break;case`IPRD`:this.metadataTags.album??=s;break;case`IPRT`:case`ITRK`:case`TRCK`:{let e=s.split(`/`),t=Number.parseInt(e[0],10),n=e[1]&&Number.parseInt(e[1],10);Number.isInteger(t)&&t>0&&(this.metadataTags.trackNumber??=t),n&&Number.isInteger(n)&&n>0&&(this.metadataTags.tracksTotal??=n)}break;case`ICRD`:case`IDIT`:{let e=new Date(s);Number.isNaN(e.getTime())||(this.metadataTags.date??=e)}break;case`YEAR`:{let e=Number.parseInt(s,10);Number.isInteger(e)&&e>0&&(this.metadataTags.date??=new Date(e,0,1))}break;case`IGNR`:case`GENR`:this.metadataTags.genre??=s;break;case`ICMT`:case`CMNT`:case`COMM`:this.metadataTags.comment??=s;break}a+=8+t+(t&1)}}async parseId3Chunk(e,t){let n=this.reader.requestSlice(e,t);if(n instanceof Promise&&(n=await n),!n)return;let r=$E(n);if(r){let i=t-10;r.size=Math.min(r.size,i),r.size>0&&eD(n.slice(e+10,r.size),r,this.metadataTags)}}getCodec(){if(J(this.audioInfo),this.audioInfo.format===wT.MULAW)return`ulaw`;if(this.audioInfo.format===wT.ALAW)return`alaw`;if(this.audioInfo.format===wT.PCM){if(this.audioInfo.sampleSizeInBytes===1)return`pcm-u8`;if(this.audioInfo.sampleSizeInBytes===2)return`pcm-s16`;if(this.audioInfo.sampleSizeInBytes===3)return`pcm-s24`;if(this.audioInfo.sampleSizeInBytes===4)return`pcm-s32`}return this.audioInfo.format===wT.IEEE_FLOAT&&this.audioInfo.sampleSizeInBytes===4?`pcm-f32`:null}async getMimeType(){return`audio/wav`}async computeDuration(){await this.readMetadata();let e=this.tracks[0];return J(e),e.computeDuration()}async getTracks(){return await this.readMetadata(),this.tracks}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}},ET=2048,DT=class{constructor(e){this.demuxer=e}getId(){return 1}getNumber(){return 1}getCodec(){return this.demuxer.getCodec()}getInternalCodecId(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.format}async getDecoderConfig(){let e=this.demuxer.getCodec();return e?(J(this.demuxer.audioInfo),{codec:e,numberOfChannels:this.demuxer.audioInfo.numberOfChannels,sampleRate:this.demuxer.audioInfo.sampleRate}):null}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}getNumberOfChannels(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.numberOfChannels}getSampleRate(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}getTimeResolution(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}getName(){return null}getLanguageCode(){return`und`}getDisposition(){return{...Ix}}async getFirstTimestamp(){return 0}async getPacketAtIndex(e,t){J(e>=0),J(this.demuxer.audioInfo);let n=e*ET*this.demuxer.audioInfo.blockSizeInBytes;if(n>=this.demuxer.dataSize)return null;let r=Math.min(ET*this.demuxer.audioInfo.blockSizeInBytes,this.demuxer.dataSize-n);if(this.demuxer.reader.fileSize===null){let e=this.demuxer.reader.requestSlice(this.demuxer.dataStart+n,r);if(e instanceof Promise&&(e=await e),!e)return null}let i;if(t.metadataOnly)i=DC;else{let e=this.demuxer.reader.requestSlice(this.demuxer.dataStart+n,r);e instanceof Promise&&(e=await e),J(e),i=jE(e,r)}let a=e*ET/this.demuxer.audioInfo.sampleRate,o=r/this.demuxer.audioInfo.blockSizeInBytes/this.demuxer.audioInfo.sampleRate;return this.demuxer.lastKnownPacketIndex=Math.max(e,this.demuxer.lastKnownPacketIndex),new OC(i,`key`,a,o,e,r)}getFirstPacket(e){return this.getPacketAtIndex(0,e)}async getPacket(e,t){J(this.demuxer.audioInfo);let n=Math.floor(Math.min(e*this.demuxer.audioInfo.sampleRate/ET,(this.demuxer.dataSize-1)/(ET*this.demuxer.audioInfo.blockSizeInBytes)));if(n<0)return null;let r=await this.getPacketAtIndex(n,t);if(r)return r;if(n===0)return null;J(this.demuxer.reader.fileSize===null);let i=await this.getPacketAtIndex(this.demuxer.lastKnownPacketIndex,t);for(;i;){let e=await this.getNextPacket(i,t);if(!e)break;i=e}return i}getNextPacket(e,t){J(this.demuxer.audioInfo);let n=Math.round(e.timestamp*this.demuxer.audioInfo.sampleRate/ET);return this.getPacketAtIndex(n+1,t)}getKeyPacket(e,t){return this.getPacket(e,t)}getNextKeyPacket(e,t){return this.getNextPacket(e,t)}},OT=e=>{let t=e.filePos,n=new Rx(jE(e,9));if(n.readBits(12)!==4095||(n.skipBits(1),n.readBits(2)!==0))return null;let r=n.readBits(1),i=n.readBits(2)+1,a=n.readBits(4);if(a===15)return null;n.skipBits(1);let o=n.readBits(3);if(o===0)throw Error(`ADTS frames with channel configuration 0 are not supported.`);n.skipBits(1),n.skipBits(1),n.skipBits(1),n.skipBits(1);let s=n.readBits(13);n.skipBits(11);let c=n.readBits(2)+1;if(c!==1)throw Error(`ADTS frames with more than one AAC frame are not supported.`);let l=null;return r===1?e.filePos-=2:l=n.readBits(16),{objectType:i,samplingFrequencyIndex:a,channelConfiguration:o,frameLength:s,numberOfAacFrames:c,crcCheck:l,startPos:t}},kT=1024,AT=class extends SC{constructor(e){super(e),this.metadataPromise=null,this.firstFrameHeader=null,this.loadedSamples=[],this.metadataTags=null,this.tracks=[],this.readingMutex=new Vb,this.lastSampleLoaded=!1,this.lastLoadedPos=0,this.nextTimestampInSamples=0,this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{for(;!this.firstFrameHeader&&!this.lastSampleLoaded;)await this.advanceReader();J(this.firstFrameHeader),this.tracks=[new _w(this.input,new jT(this))]})()}async advanceReader(){if(this.lastLoadedPos===0)for(;;){let e=this.reader.requestSlice(this.lastLoadedPos,10);if(e instanceof Promise&&(e=await e),!e){this.lastSampleLoaded=!0;return}let t=$E(e);if(!t)break;this.lastLoadedPos=e.filePos+t.size}let e=this.reader.requestSliceRange(this.lastLoadedPos,7,9);if(e instanceof Promise&&(e=await e),!e){this.lastSampleLoaded=!0;return}let t=OT(e);if(!t){this.lastSampleLoaded=!0;return}if(this.reader.fileSize!==null&&t.startPos+t.frameLength>this.reader.fileSize){this.lastSampleLoaded=!0;return}this.firstFrameHeader||=t;let n=zx[t.samplingFrequencyIndex];J(n!==void 0);let r=kT/n,i={timestamp:this.nextTimestampInSamples/n,duration:r,dataStart:t.startPos,dataSize:t.frameLength};this.loadedSamples.push(i),this.nextTimestampInSamples+=kT,this.lastLoadedPos=t.startPos+t.frameLength}async getMimeType(){return`audio/aac`}async getTracks(){return await this.readMetadata(),this.tracks}async computeDuration(){await this.readMetadata();let e=this.tracks[0];return J(e),e.computeDuration()}async getMetadataTags(){let e=await this.readingMutex.acquire();try{if(await this.readMetadata(),this.metadataTags)return this.metadataTags;this.metadataTags={};let e=0;for(;;){let t=this.reader.requestSlice(e,10);if(t instanceof Promise&&(t=await t),!t)break;let n=$E(t);if(!n)break;let r=this.reader.requestSlice(t.filePos,n.size);if(r instanceof Promise&&(r=await r),!r)break;eD(r,n,this.metadataTags),e=t.filePos+n.size}return this.metadataTags}finally{e()}}},jT=class{constructor(e){this.demuxer=e}getId(){return 1}getNumber(){return 1}async getFirstTimestamp(){return 0}getTimeResolution(){return this.getSampleRate()/kT}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}getName(){return null}getLanguageCode(){return`und`}getCodec(){return`aac`}getInternalCodecId(){return J(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.objectType}getNumberOfChannels(){J(this.demuxer.firstFrameHeader);let e=Bx[this.demuxer.firstFrameHeader.channelConfiguration];return J(e!==void 0),e}getSampleRate(){J(this.demuxer.firstFrameHeader);let e=zx[this.demuxer.firstFrameHeader.samplingFrequencyIndex];return J(e!==void 0),e}getDisposition(){return{...Ix}}async getDecoderConfig(){return J(this.demuxer.firstFrameHeader),{codec:`mp4a.40.${this.demuxer.firstFrameHeader.objectType}`,numberOfChannels:this.getNumberOfChannels(),sampleRate:this.getSampleRate()}}async getPacketAtIndex(e,t){if(e===-1)return null;let n=this.demuxer.loadedSamples[e];if(!n)return null;let r;if(t.metadataOnly)r=DC;else{let e=this.demuxer.reader.requestSlice(n.dataStart,n.dataSize);if(e instanceof Promise&&(e=await e),!e)return null;r=jE(e,n.dataSize)}return new OC(r,`key`,n.timestamp,n.duration,e,n.dataSize)}getFirstPacket(e){return this.getPacketAtIndex(0,e)}async getNextPacket(e,t){let n=await this.demuxer.readingMutex.acquire();try{let n=Wb(this.demuxer.loadedSamples,e.timestamp,e=>e.timestamp);if(n===-1)throw Error(`Packet was not created from this track.`);let r=n+1;for(;r>=this.demuxer.loadedSamples.length&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(r,t)}finally{n()}}async getPacket(e,t){let n=await this.demuxer.readingMutex.acquire();try{for(;;){let n=Gb(this.demuxer.loadedSamples,e,e=>e.timestamp);if(n===-1&&this.demuxer.loadedSamples.length>0)return null;if(this.demuxer.lastSampleLoaded||n>=0&&n+1<this.demuxer.loadedSamples.length)return this.getPacketAtIndex(n,t);await this.demuxer.advanceReader()}}finally{n()}}getKeyPacket(e,t){return this.getPacket(e,t)}getNextKeyPacket(e,t){return this.getNextPacket(e,t)}},MT=e=>e===0?null:e===1?192:e>=2&&e<=5?144*2**e:e===6?`uncommon-u8`:e===7?`uncommon-u16`:e>=8&&e<=15?2**e:null,NT=(e,t)=>{switch(e){case 0:return t;case 1:return 88200;case 2:return 176400;case 3:return 192e3;case 4:return 8e3;case 5:return 16e3;case 6:return 22050;case 7:return 24e3;case 8:return 32e3;case 9:return 44100;case 10:return 48e3;case 11:return 96e3;case 12:return`uncommon-u8`;case 13:return`uncommon-u16`;case 14:return`uncommon-u16-10`;default:return null}},PT=e=>{let t=0,n=new Rx(jE(e,1));for(;n.readBits(1)===1;)t++;if(t===0)return n.readBits(7);let r=[],i=t-1,a=new Rx(jE(e,i)),o=8-t-1;for(let e=0;e<o;e++)r.unshift(n.readBits(1));for(let e=0;e<i;e++)for(let e=0;e<8;e++){let t=a.readBits(1);e<2||r.unshift(t)}return r.reduce((e,t,n)=>e|t<<n,0)},FT=(e,t)=>{if(t===`uncommon-u16`)return PE(e)+1;if(t===`uncommon-u8`)return ME(e)+1;if(typeof t==`number`)return t;Qb(t),J(!1)},IT=(e,t)=>t===`uncommon-u16`?PE(e):t===`uncommon-u16-10`?PE(e)*10:t===`uncommon-u8`?ME(e):typeof t==`number`?t:null,LT=e=>{let t=0;for(let n of e){t^=n;for(let e=0;e<8;e++)t&128?t=t<<1^7:t<<=1,t&=255}return t},RT=class extends SC{constructor(e){super(e),this.loadedSamples=[],this.metadataPromise=null,this.track=null,this.metadataTags={},this.audioInfo=null,this.lastLoadedPos=null,this.blockingBit=null,this.readingMutex=new Vb,this.lastSampleLoaded=!1,this.reader=e._reader}async computeDuration(){return await this.readMetadata(),J(this.track),this.track.computeDuration()}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}async getTracks(){return await this.readMetadata(),J(this.track),[this.track]}async getMimeType(){return`audio/flac`}async readMetadata(){let e=4;return this.metadataPromise??=(async()=>{for(;this.reader.fileSize===null||e<this.reader.fileSize;){let t=this.reader.requestSlice(e,4);if(t instanceof Promise&&(t=await t),e+=4,t===null)throw Error(`Metadata block at position ${e} is too small! Corrupted file.`);J(t);let n=ME(t),r=FE(t),i=(n&128)!=0;switch(n&127){case dC.STREAMINFO:{let t=this.reader.requestSlice(e,r);if(t instanceof Promise&&(t=await t),J(t),t===null)throw Error(`StreamInfo block at position ${e} is too small! Corrupted file.`);let n=jE(t,34),i=new Rx(n),a=i.readBits(16),o=i.readBits(16),s=i.readBits(24),c=i.readBits(24),l=i.readBits(20),u=i.readBits(3)+1;i.readBits(5);let d=i.readBits(36);i.skipBits(128);let f=new Uint8Array(42);f.set(new Uint8Array([102,76,97,67]),0),f.set(new Uint8Array([128,0,0,34]),4),f.set(n,8),this.audioInfo={numberOfChannels:u,sampleRate:l,totalSamples:d,minimumBlockSize:a,maximumBlockSize:o,minimumFrameSize:s,maximumFrameSize:c,description:f},this.track=new _w(this.input,new zT(this));break}case dC.VORBIS_COMMENT:{let t=this.reader.requestSlice(e,r);t instanceof Promise&&(t=await t),J(t),fC(jE(t,r),this.metadataTags);break}case dC.PICTURE:{let t=this.reader.requestSlice(e,r);t instanceof Promise&&(t=await t),J(t);let n=Z(t),i=Z(t),a=Ab.decode(jE(t,i)),o=Z(t),s=Ab.decode(jE(t,o));t.skip(16);let c=Z(t),l=jE(t,c);this.metadataTags.images??=[],this.metadataTags.images.push({data:l,mimeType:a,kind:n===3?`coverFront`:n===4?`coverBack`:`unknown`,description:s});break}default:break}if(e+=r,i){this.lastLoadedPos=e;break}}})()}async readNextFlacFrame({startPos:e,isFirstPacket:t}){J(this.audioInfo);let n=this.audioInfo.maximumFrameSize+16,r=await this.reader.requestSliceRange(e,this.audioInfo.minimumFrameSize,n);if(!r)return null;let i=this.readFlacFrameHeader({slice:r,isFirstPacket:t});if(!i)return null;for(r.filePos=e+this.audioInfo.minimumFrameSize;;){if(r.filePos>r.end-6)return{num:i.num,blockSize:i.blockSize,sampleRate:i.sampleRate,size:r.end-e,isLastFrame:!0};if(ME(r)===255){let t=r.filePos;if(ME(r)!==(this.blockingBit===1?249:248)){r.filePos=t;continue}r.skip(-2);let n=r.filePos-e,a=this.readFlacFrameHeader({slice:r,isFirstPacket:!1});if(!a){r.filePos=t;continue}if(this.blockingBit===0){if(a.num-i.num!==1){r.filePos=t;continue}}else if(a.num-i.num!==i.blockSize){r.filePos=t;continue}return{num:i.num,blockSize:i.blockSize,sampleRate:i.sampleRate,size:n,isLastFrame:!1}}}}readFlacFrameHeader({slice:e,isFirstPacket:t}){let n=e.filePos,r=new Rx(jE(e,4));if(r.readBits(15)!==32764)return null;if(this.blockingBit===null)J(t),this.blockingBit=r.readBits(1);else if(this.blockingBit===1){if(J(!t),r.readBits(1)!==1)return null}else if(this.blockingBit===0){if(J(!t),r.readBits(1)!==0)return null}else throw Error(`Invalid blocking bit`);let i=MT(r.readBits(4));if(!i)return null;J(this.audioInfo);let a=NT(r.readBits(4),this.audioInfo.sampleRate);if(!a||(r.readBits(4),r.readBits(3),r.readBits(1)!==0))return null;let o=PT(e),s=FT(e,i),c=IT(e,a);if(c===null||c!==this.audioInfo.sampleRate)return null;let l=e.filePos-n,u=ME(e);return e.skip(-l),e.skip(-1),u===LT(jE(e,l))?{num:o,blockSize:s,sampleRate:c}:null}async advanceReader(){await this.readMetadata(),J(this.lastLoadedPos!==null),J(this.audioInfo);let e=this.lastLoadedPos,t=await this.readNextFlacFrame({startPos:e,isFirstPacket:this.loadedSamples.length===0});if(!t){this.lastSampleLoaded=!0;return}let n=this.loadedSamples[this.loadedSamples.length-1],r={blockOffset:n?n.blockOffset+n.blockSize:0,blockSize:t.blockSize,byteOffset:e,byteSize:t.size};if(this.lastLoadedPos+=t.size,this.loadedSamples.push(r),t.isLastFrame){this.lastSampleLoaded=!0;return}}},zT=class{constructor(e){this.demuxer=e}getId(){return 1}getNumber(){return 1}getCodec(){return`flac`}getInternalCodecId(){return null}getNumberOfChannels(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.numberOfChannels}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}getSampleRate(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}getName(){return null}getLanguageCode(){return`und`}getTimeResolution(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}getDisposition(){return{...Ix}}async getFirstTimestamp(){return 0}async getDecoderConfig(){return J(this.demuxer.audioInfo),{codec:`flac`,numberOfChannels:this.demuxer.audioInfo.numberOfChannels,sampleRate:this.demuxer.audioInfo.sampleRate,description:this.demuxer.audioInfo.description}}async getPacket(e,t){if(J(this.demuxer.audioInfo),e<0)throw Error(`Timestamp cannot be negative`);let n=await this.demuxer.readingMutex.acquire();try{for(;;){let n=Gb(this.demuxer.loadedSamples,e,e=>e.blockOffset/this.demuxer.audioInfo.sampleRate);if(n===-1){await this.demuxer.advanceReader();continue}let r=this.demuxer.loadedSamples[n];if(r.blockOffset/this.demuxer.audioInfo.sampleRate+r.blockSize/this.demuxer.audioInfo.sampleRate<=e){if(this.demuxer.lastSampleLoaded)return this.getPacketAtIndex(this.demuxer.loadedSamples.length-1,t);await this.demuxer.advanceReader();continue}return this.getPacketAtIndex(n,t)}}finally{n()}}async getNextPacket(e,t){let n=await this.demuxer.readingMutex.acquire();try{let n=e.sequenceNumber+1;if(this.demuxer.lastSampleLoaded&&n>=this.demuxer.loadedSamples.length)return null;for(;n>=this.demuxer.loadedSamples.length&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(n,t)}finally{n()}}getKeyPacket(e,t){return this.getPacket(e,t)}getNextKeyPacket(e,t){return this.getNextPacket(e,t)}async getPacketAtIndex(e,t){let n=this.demuxer.loadedSamples[e];if(!n)return null;let r;if(t.metadataOnly)r=DC;else{let e=this.demuxer.reader.requestSlice(n.byteOffset,n.byteSize);if(e instanceof Promise&&(e=await e),!e)return null;r=jE(e,n.byteSize)}J(this.demuxer.audioInfo);let i=n.blockOffset/this.demuxer.audioInfo.sampleRate,a=n.blockSize/this.demuxer.audioInfo.sampleRate;return new OC(r,`key`,i,a,e,n.byteSize)}async getFirstPacket(e){for(;this.demuxer.loadedSamples.length===0&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(0,e)}},BT=9e4,VT=e=>{let t=`video/MP2T`,n=[...new Set(e.filter(Boolean))];return n.length>0&&(t+=`; codecs="${n.join(`, `)}"`),t},HT=class extends SC{constructor(e){super(e),this.metadataPromise=null,this.elementaryStreams=[],this.tracks=[],this.packetOffset=0,this.packetStride=-1,this.sectionEndPositions=[],this.seekChunkSize=5*1024*1024,this.minReferencePointByteDistance=-1,this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{let e=this.reader.requestSlice(0,205);e instanceof Promise&&(e=await e),J(e);let t=jE(e,205);if(t[0]===71&&t[188]===71)this.packetOffset=0,this.packetStride=188;else if(t[0]===71&&t[204]===71)this.packetOffset=0,this.packetStride=204;else if(t[4]===71&&t[196]===71)this.packetOffset=4,this.packetStride=192;else throw Error(`Unreachable.`);this.minReferencePointByteDistance=256*this.packetStride;let n=this.packetOffset,r=null,i=!1,a=!1;for(;;){let e=await this.readPacketHeader(n);if(!e)break;if(e.payloadUnitStartIndicator===0){n+=this.packetStride;continue}let t=await this.readSection(n,!0,!a);if(!t)break;let o=!1;if(!a&&t.pid!==0&&!(t.payload[0]===0&&t.payload[1]===0&&t.payload[2]===1)){let e=new Rx(t.payload),n=e.readAlignedByte();e.skipBits(8*n),o=e.readBits(8)===2}if(t.pid===0&&!i){let e=new Rx(t.payload),n=e.readAlignedByte();e.skipBits(8*n),e.skipBits(14);let a=e.readBits(10);for(e.skipBits(40);8*(a+3)-e.pos>32;){let t=e.readBits(16);if(e.skipBits(3),t!==0){if(r!==null)throw Error(`Only files with a single program are supported.`);r=e.readBits(13)}}if(r===null)throw Error(`Program Association Table must link to a Program Map Table.`);i=!0}else if((t.pid===r||o)&&!a){let e=new Rx(t.payload),n=e.readAlignedByte();e.skipBits(8*n),e.skipBits(12);let r=e.readBits(12);e.skipBits(43),e.readBits(13),e.skipBits(6);let i=e.readBits(10);for(e.skipBits(8*i);8*(r+3)-e.pos>32;){let t=e.readBits(8);e.skipBits(3);let n=e.readBits(13);e.skipBits(6);let r=e.readBits(10),i=e.pos+8*r,a=!1,o=!1;for(;e.pos<i;){let t=e.readBits(8),n=e.readBits(8);t===106?a=!0:(t===122||t===204)&&(o=!0),e.skipBits(8*n)}let s=null;switch(t){case 3:case 4:case 15:s={type:`audio`,codec:t===15?`aac`:`mp3`,aacCodecInfo:null,numberOfChannels:-1,sampleRate:-1};break;case 27:case 36:s={type:`video`,codec:t===27?`avc`:`hevc`,avcCodecInfo:null,hevcCodecInfo:null,colorSpace:{primaries:null,transfer:null,matrix:null,fullRange:null},width:-1,height:-1,squarePixelWidth:-1,squarePixelHeight:-1,reorderSize:-1};break;case 129:s={type:`audio`,codec:`ac3`,aacCodecInfo:null,numberOfChannels:-1,sampleRate:-1};break;case 135:s={type:`audio`,codec:`eac3`,aacCodecInfo:null,numberOfChannels:-1,sampleRate:-1};break;case 6:o?s={type:`audio`,codec:`eac3`,aacCodecInfo:null,numberOfChannels:-1,sampleRate:-1}:a&&(s={type:`audio`,codec:`ac3`,aacCodecInfo:null,numberOfChannels:-1,sampleRate:-1});break;default:console.warn(`Unsupported stream_type 0x${t.toString(16)}; ignoring stream.`)}s&&this.elementaryStreams.push({demuxer:this,pid:n,streamType:t,initialized:!1,firstSection:null,info:s,referencePesPackets:[]})}a=!0}else{let e=this.elementaryStreams.find(e=>e.pid===t.pid);if(e&&!e.initialized){let n=WT(t);if(!n)throw Error(`Couldn't read first PES packet for Elementary Stream with PID ${e.pid}`);if(e.firstSection=t,e.info.type===`video`)if(e.info.codec===`avc`){if(e.info.avcCodecInfo=zS(n.data),!e.info.avcCodecInfo)throw Error(`Invalid AVC video stream; could not extract AVCDecoderConfigurationRecord from first packet.`);let t=e.info.avcCodecInfo.sequenceParameterSets[0];J(t);let r=US(t);e.info.width=r.displayWidth,e.info.height=r.displayHeight,r.pixelAspectRatio.num>r.pixelAspectRatio.den?(e.info.squarePixelWidth=Math.round(e.info.width*r.pixelAspectRatio.num/r.pixelAspectRatio.den),e.info.squarePixelHeight=e.info.height):(e.info.squarePixelWidth=e.info.width,e.info.squarePixelHeight=Math.round(e.info.height*r.pixelAspectRatio.den/r.pixelAspectRatio.num)),e.info.colorSpace={primaries:Pb[r.colourPrimaries],transfer:Ib[r.transferCharacteristics],matrix:Rb[r.matrixCoefficients],fullRange:!!r.fullRangeFlag},e.info.reorderSize=r.maxDecFrameBuffering,e.initialized=!0}else if(e.info.codec===`hevc`){if(e.info.hevcCodecInfo=JS(n.data),!e.info.hevcCodecInfo)throw Error(`Invalid HEVC video stream; could not extract HVCDecoderConfigurationRecord from first packet.`);let t=e.info.hevcCodecInfo.arrays.find(e=>e.nalUnitType===kS.SPS_NUT).nalUnits[0];J(t);let r=qS(t);e.info.width=r.displayWidth,e.info.height=r.displayHeight,r.pixelAspectRatio.num>r.pixelAspectRatio.den?(e.info.squarePixelWidth=Math.round(e.info.width*r.pixelAspectRatio.num/r.pixelAspectRatio.den),e.info.squarePixelHeight=e.info.height):(e.info.squarePixelWidth=e.info.width,e.info.squarePixelHeight=Math.round(e.info.height*r.pixelAspectRatio.den/r.pixelAspectRatio.num)),e.info.colorSpace={primaries:Pb[r.colourPrimaries],transfer:Ib[r.transferCharacteristics],matrix:Rb[r.matrixCoefficients],fullRange:!!r.fullRangeFlag},e.info.reorderSize=r.maxDecFrameBuffering,e.initialized=!0}else throw Error(`Unhandled.`);else if(e.info.codec===`aac`){let t=OT(kE.tempFromBytes(n.data));if(!t)throw Error(`Invalid AAC audio stream; could not read ADTS frame header from first packet.`);e.info.aacCodecInfo={isMpeg2:!1,objectType:t.objectType},e.info.numberOfChannels=Bx[t.channelConfiguration],e.info.sampleRate=zx[t.samplingFrequencyIndex],e.initialized=!0}else if(e.info.codec===`mp3`){let t=wS(Z(kE.tempFromBytes(n.data)),n.data.byteLength);if(!t.header)throw Error(`Invalid MP3 audio stream; could not read frame header from first packet.`);e.info.numberOfChannels=t.header.channel===3?1:2,e.info.sampleRate=t.header.sampleRate,e.initialized=!0}else if(e.info.codec===`ac3`){let t=mC(n.data);if(!t)throw Error(`Invalid AC-3 audio stream; could not read sync frame from first packet.`);if(t.fscod===3)throw Error(`Invalid AC-3 audio stream; reserved sample rate code found in first packet.`);e.info.numberOfChannels=pC[t.acmod]+t.lfeon,e.info.sampleRate=ES[t.fscod],e.initialized=!0}else if(e.info.codec===`eac3`){let t=vC(n.data);if(!t)throw Error(`Invalid E-AC-3 audio stream; could not read sync frame from first packet.`);let r=bC(t);if(r===null)throw Error(`Invalid E-AC-3 audio stream; reserved sample rate code found in first packet.`);e.info.numberOfChannels=xC(t),e.info.sampleRate=r,e.initialized=!0}else throw Error(`Unhandled.`)}}if(a&&this.elementaryStreams.every(e=>e.initialized))break;n+=this.packetStride}if(!a)throw i?Error(`No Program Map Table found in the file.`):Error(`No Program Association Table found in the file.`);for(let e of this.elementaryStreams)e.info.type===`video`?this.tracks.push(new gw(this.input,new KT(e))):this.tracks.push(new _w(this.input,new qT(e)))})()}async getTracks(){return await this.readMetadata(),this.tracks}async getMetadataTags(){return{}}async computeDuration(){let e=await this.getTracks(),t=await Promise.all(e.map(e=>e.computeDuration()));return Math.max(0,...t)}async getMimeType(){await this.readMetadata();let e=await this.getTracks();return VT(await Promise.all(e.map(e=>e.getCodecParameterString())))}async readSection(e,t,n=!1){let r=e,i=e,a=[],o=0,s=null,c=!0,l=0;for(;;){let e=await this.readPacket(i);if(i+=this.packetStride,!e)break;if(s){if(e.pid!==s.pid){if(n)break;continue}if(e.payloadUnitStartIndicator===1)break}else{if(e.payloadUnitStartIndicator===0)break;s=e}let u=!!(e.adaptationFieldControl&2),d=!!(e.adaptationFieldControl&1),f=0;if(u&&(f=1+e.body[0],e===s&&f>1&&(l=e.body[1]>>6&1)),d&&(f===0?(a.push(e.body),o+=e.body.byteLength):(a.push(e.body.subarray(f)),o+=e.body.byteLength-f)),r=i,!t&&o>=64){c=!1;break}if(Wb(this.sectionEndPositions,r,e=>e)!==-1){c=!1;break}}if(c){let e=Gb(this.sectionEndPositions,r,e=>e);this.sectionEndPositions.splice(e+1,0,r)}if(!s)return null;let u;if(a.length===1)u=a[0];else{let e=a.reduce((e,t)=>e+t.length,0);u=new Uint8Array(e);let t=0;for(let e of a)u.set(e,t),t+=e.length}return{startPos:e,endPos:t?r:null,pid:s.pid,payload:u,randomAccessIndicator:l}}async readPacketHeader(e){let t=this.reader.requestSlice(e,4);if(t instanceof Promise&&(t=await t),!t)return null;if(ME(t)!==71)throw Error(`Invalid TS packet sync byte. Likely an internal bug, please report this file.`);let n=PE(t);n>>15;let r=n>>14&1;n>>13&1;let i=n&8191,a=ME(t);a>>6;let o=a>>4&3;return a&15,{payloadUnitStartIndicator:r,pid:i,adaptationFieldControl:o}}async readPacket(e){let t=this.reader.requestSlice(e,188);if(t instanceof Promise&&(t=await t),!t)return null;let n=jE(t,188);if(n[0]!==71)throw Error(`Invalid TS packet sync byte. Likely an internal bug, please report this file.`);let r=(n[1]<<8)+n[2];r>>15;let i=r>>14&1;r>>13&1;let a=r&8191,o=n[3];o>>6;let s=o>>4&3;return o&15,{payloadUnitStartIndicator:i,pid:a,adaptationFieldControl:s,body:n.subarray(4)}}},UT=e=>{if(e.payload.byteLength<3)return null;let t=new Rx(e.payload);if(t.readBits(24)!==1)return null;let n=t.readBits(8);if(t.skipBits(16),n===188||n===190||n===191||n===240||n===241||n===255||n===242||n===248)return null;t.skipBits(8);let r=t.readBits(2);t.skipBits(14);let i=0;if(r===2||r===3)t.skipBits(4),i+=t.readBits(3)*(1<<30),t.skipBits(1),i+=t.readBits(15)*32768,t.skipBits(1),i+=t.readBits(15);else throw Error(`PES packets without PTS are not currently supported. If you think this file should be supported, please report it.`);return{sectionStartPos:e.startPos,sectionEndPos:e.endPos,pts:i,randomAccessIndicator:e.randomAccessIndicator}},WT=e=>{J(e.endPos!==null);let t=UT(e);if(!t)return null;let n=new Rx(e.payload);n.skipBits(32);let r=n.readBits(16);n.skipBits(16);let i=n.readBits(8),a=n.pos+8*i;n.pos=a;let o=a/8;J(Number.isInteger(o));let s=e.payload.subarray(o,r>0?6+r:e.payload.byteLength);return{...t,data:s}},GT=class e{constructor(e){this.elementaryStream=e,this.packetBuffers=new WeakMap,this.packetSectionStarts=new WeakMap}getId(){return this.elementaryStream.pid}getNumber(){let t=this.elementaryStream.demuxer,n=this.elementaryStream.info.type,r=0;for(let i of t.tracks)if(i.type===n&&r++,J(i._backing instanceof e),i._backing.elementaryStream===this.elementaryStream)break;return r}getCodec(){throw Error(`Not implemented on base class.`)}getInternalCodecId(){return this.elementaryStream.streamType}getName(){return null}getLanguageCode(){return`und`}getDisposition(){return Ix}getTimeResolution(){return BT}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}async getFirstTimestamp(){return(await this.getFirstPacket({metadataOnly:!0}))?.timestamp??0}createEncodedPacket(e,t,n){let r;return r=this.allPacketsAreKeyPackets()||e.randomAccessIndicator===1?`key`:`delta`,new OC(n.metadataOnly?DC:e.data,r,e.pts/BT,Math.max(t/BT,0),e.sequenceNumber,e.data.byteLength)}async getFirstPacket(e){let t=this.elementaryStream.firstSection;J(t);let n=WT(t);J(n);let r=new XT(this.elementaryStream,n),i=new ZT(this,r),a=await i.readNext();if(!a)return null;let o=this.createEncodedPacket(a.packet,a.duration,e);return this.packetBuffers.set(o,i),this.packetSectionStarts.set(o,a.packet.sectionStartPos),o}async getNextPacket(e,t){let n=this.packetBuffers.get(e);if(n){let r=await n.readNext();if(!r)return null;this.packetBuffers.delete(e);let i=this.createEncodedPacket(r.packet,r.duration,t);return this.packetBuffers.set(i,n),this.packetSectionStarts.set(i,r.packet.sectionStartPos),i}let r=this.packetSectionStarts.get(e);if(r===void 0)throw Error(`Packet was not created from this track.`);let i=await this.elementaryStream.demuxer.readSection(r,!0);J(i);let a=WT(i);J(a);let o=new XT(this.elementaryStream,a);n=new ZT(this,o);let s=e.sequenceNumber;for(;;){let e=await n.readNext();if(!e)return null;if(e.packet.sequenceNumber>s){let r=this.createEncodedPacket(e.packet,e.duration,t);return this.packetBuffers.set(r,n),this.packetSectionStarts.set(r,e.packet.sectionStartPos),r}}}async getNextKeyPacket(e,t){let n=e;for(;;){if(n=await this.getNextPacket(n,t),!n)return null;if(n.type===`key`)return n}}getPacket(e,t){return this.doPacketLookup(e,!1,t)}getKeyPacket(e,t){return this.doPacketLookup(e,!0,t)}async doPacketLookup(e,t,n){let r=ax(e*BT),i=this.elementaryStream.demuxer,{reader:a,seekChunkSize:o}=i,s=this.elementaryStream.pid,c=async(e,t)=>{let n=e;for(;n<t;){let e=await i.readPacketHeader(n);if(!e)return null;if(e.pid===s&&e.payloadUnitStartIndicator===1){let e=await i.readSection(n,!1);if(!e)return null;let t=UT(e);if(t)return t}n+=i.packetStride}return null},l=this.elementaryStream.firstSection;J(l);let u=UT(l);if(J(u),r<u.pts)return null;let d,f=this.elementaryStream.referencePesPackets,p=Gb(f,r,e=>e.pts),m=p===-1?null:f[p];if(m&&r-m.pts<9e4/2)d=m.sectionStartPos;else{let e=0;if(a.fileSize!==null){let t=Math.ceil(a.fileSize/o);if(t>1){let n=0,a=t-1;for(e=n;n<=a;){let t=Math.floor((n+a)/2),s=sx(t*o,i.packetStride)+u.sectionStartPos,l=await c(s,s+o);if(!l){a=t-1;continue}l.pts<=r?(e=t,n=t+1):a=t-1}}}d=sx(e*o,i.packetStride)+u.sectionStartPos}let h=await c(d,a.fileSize??1/0);h||=u;let g=this.getReorderSize(),_=async(e,t)=>{let a=await i.readSection(e,!0);J(a);let o=WT(a);J(o);let s=new XT(this.elementaryStream,o),c=new ZT(this,s);for(;!((Tb(c.presentationOrderPackets)?.pts??-1/0)>=r||!await c.readNextPacket()););let l=Yb(c.presentationOrderPackets,t);if(l===-1)return null;let u=c.presentationOrderPackets[l],d=l===0?0:u.pts-c.presentationOrderPackets[l-1].pts;for(;c.decodeOrderPackets[0]!==u;)c.decodeOrderPackets.shift();c.lastDuration=d;let f=await c.readNext();J(f);let p=this.createEncodedPacket(f.packet,f.duration,n);return this.packetBuffers.set(p,c),this.packetSectionStarts.set(p,f.packet.sectionStartPos),p};if(!t||this.allPacketsAreKeyPackets()){outer:for(;;){let e=h.sectionStartPos+i.packetStride;for(;;){let t=await i.readPacketHeader(e);if(!t)break outer;if(t.pid===s&&t.payloadUnitStartIndicator===1){let t=await i.readSection(e,!1);if(t){let e=UT(t);if(e){if(e.pts>r)break outer;h=e,JT(this.elementaryStream,e);break}}}e+=i.packetStride}}outer:for(let e=0;e<g;e++){let e=h.sectionStartPos-i.packetStride;for(;e>=i.packetOffset;){let t=await i.readPacketHeader(e);if(!t)break outer;if(t.pid===s&&t.payloadUnitStartIndicator===1){let t=await i.readSection(e,!1);if(t){let e=UT(t);if(e){h=e;break}}}e-=i.packetStride}}return _(h.sectionStartPos,e=>e.pts<=r)}else{let e=d,t=null;for(;;){let n=null,l=e<=u.sectionStartPos,d;l?(d=u,n=u):d=await c(e,a.fileSize??1/0);let f=!1,p=0;outer:for(;d&&!(t!==null&&d.sectionStartPos>=t||(d.randomAccessIndicator===1&&d.pts<=r&&(n=d),d.pts>r&&(f=!0),f&&(p++,p>=g)));){let e=d.sectionStartPos+i.packetStride;for(;;){let t=await i.readPacketHeader(e);if(!t)break outer;if(t.pid===s&&t.payloadUnitStartIndicator===1){let t=await i.readSection(e,!1);if(t&&(d=UT(t),d)){JT(this.elementaryStream,d);break}}e+=i.packetStride}}if(n){let e=n;if(p===0)outer:for(let t=0;t<g-1;t++){let t=e.sectionStartPos-i.packetStride;for(;t>=i.packetOffset;){let n=await i.readPacketHeader(t);if(!n)break outer;if(n.pid===s&&n.payloadUnitStartIndicator===1){let n=await i.readSection(t,!1);if(n){let t=UT(n);if(t){e=t;break}}}t-=i.packetStride}}let t=await _(e.sectionStartPos,e=>e.pts<=r&&e.randomAccessIndicator===1);return J(t),t}J(!l),t=e,e=Math.max(sx(e-u.sectionStartPos-o,i.packetStride)+u.sectionStartPos,u.sectionStartPos)}}}},KT=class extends GT{constructor(e){super(e),this.elementaryStream=e,this.decoderConfig={codec:nS({width:this.elementaryStream.info.width,height:this.elementaryStream.info.height,codec:this.elementaryStream.info.codec,codecDescription:null,colorSpace:this.elementaryStream.info.colorSpace,avcType:1,avcCodecInfo:this.elementaryStream.info.avcCodecInfo,hevcCodecInfo:this.elementaryStream.info.hevcCodecInfo,vp9CodecInfo:null,av1CodecInfo:null}),codedWidth:this.elementaryStream.info.width,codedHeight:this.elementaryStream.info.height,displayAspectWidth:this.elementaryStream.info.squarePixelWidth,displayAspectHeight:this.elementaryStream.info.squarePixelHeight,colorSpace:this.elementaryStream.info.colorSpace}}getCodec(){return this.elementaryStream.info.codec}getCodedWidth(){return this.elementaryStream.info.width}getCodedHeight(){return this.elementaryStream.info.height}getSquarePixelWidth(){return this.elementaryStream.info.squarePixelWidth}getSquarePixelHeight(){return this.elementaryStream.info.squarePixelHeight}getRotation(){return 0}async getColorSpace(){return this.elementaryStream.info.colorSpace}async canBeTransparent(){return!1}async getDecoderConfig(){return this.decoderConfig}allPacketsAreKeyPackets(){return!1}getReorderSize(){return this.elementaryStream.info.reorderSize}},qT=class extends GT{constructor(e){super(e),this.elementaryStream=e}getCodec(){return this.elementaryStream.info.codec}getNumberOfChannels(){return this.elementaryStream.info.numberOfChannels}getSampleRate(){return this.elementaryStream.info.sampleRate}async getDecoderConfig(){return{codec:iS({codec:this.elementaryStream.info.codec,codecDescription:null,aacCodecInfo:this.elementaryStream.info.aacCodecInfo}),numberOfChannels:this.elementaryStream.info.numberOfChannels,sampleRate:this.elementaryStream.info.sampleRate}}allPacketsAreKeyPackets(){return!0}getReorderSize(){return 1}},JT=(e,t)=>{let n=e.referencePesPackets,r=Gb(n,t.sectionStartPos,e=>e.sectionStartPos);if(r>=0){let i=n[r];if(t.pts<=i.pts)return!1;let a=e.demuxer.minReferencePointByteDistance;if(t.sectionStartPos-i.sectionStartPos<a)return!1;if(r<n.length-1){let e=n[r+1];if(e.pts<t.pts||e.sectionStartPos-t.sectionStartPos<a)return!1}}return n.splice(r+1,0,t),!0},YT=async e=>{J(!e.suppliedPacket);let t=e.elementaryStream;if(t.info.type===`video`){let n=t.info.codec,r=1024;if(n!==`avc`&&n!==`hevc`)throw Error(`Unhandled.`);let i=null;for(;;){let t=e.ensureBuffered(r);if(t instanceof Promise&&(t=await t),t===0)break;let a=e.currentPos,o=e.readBytes(t),s=o.byteLength,c=0;for(;c<s;){let t=o.indexOf(0,c);if(t===-1||t>=s)break;c=t;let r=a+c;if(c+4>=s){e.seekTo(r);break}let l=o[c+1],u=o[c+2],d=o[c+3],f=0,p=null;if(l===0&&u===0&&d===1?(f=4,p=o[c+4]):l===0&&u===1&&(f=3,p=d),f===0){c++;continue}let m=r;if(i===null){i=m,c+=f;continue}if(p!==null){let t=n===`avc`?NS(p):KS(p);if(n===`avc`?t===OS.AUD:t===kS.AUD_NUT){let t=m-i;return e.seekTo(i),e.supplyPacket(t,0)}}c+=f}if(t<r)break}if(i!==null){let t=e.endPos-i;return e.seekTo(i),e.supplyPacket(t,0)}}else{let n=t.info.codec;for(;;){let r=e.ensureBuffered(128);r instanceof Promise&&(r=await r);let i=e.currentPos;for(;e.currentPos-i<r;){let r=e.readU8();if(n===`aac`){if(r!==255)continue;e.skip(-1);let n=e.currentPos,i=e.ensureBuffered(9);if(i instanceof Promise&&(i=await i),i<9)return;let a=e.readBytes(9),o=OT(kE.tempFromBytes(a));if(o){e.seekTo(n);let r=e.ensureBuffered(o.frameLength);return r instanceof Promise&&(r=await r),e.supplyPacket(r,Math.round(kT*BT/t.info.sampleRate))}else e.seekTo(n+1)}else if(n===`mp3`){if(r!==255)continue;e.skip(-1);let n=e.currentPos,i=e.ensureBuffered(4);if(i instanceof Promise&&(i=await i),i<4)return;let a=wS(kb(e.readBytes(4)).getUint32(0),null);if(a.header){e.seekTo(n);let r=e.ensureBuffered(a.header.totalSize);r instanceof Promise&&(r=await r);let i=a.header.audioSamplesInFrame*BT/t.info.sampleRate;return e.supplyPacket(r,Math.round(i))}else e.seekTo(n+1)}else if(n===`ac3`){if(r!==11)continue;e.skip(-1);let n=e.currentPos,i=e.ensureBuffered(5);if(i instanceof Promise&&(i=await i),i<5)return;let a=e.readBytes(5);if(a[0]!==11||a[1]!==119){e.seekTo(n+1);continue}let o=a[4]>>6,s=a[4]&63;if(o===3||s>37){e.seekTo(n+1);continue}let c=hC[3*s+o];J(c!==void 0),e.seekTo(n),i=e.ensureBuffered(c),i instanceof Promise&&(i=await i);let l=Math.round(gC*BT/t.info.sampleRate);return e.supplyPacket(i,l)}else if(n===`eac3`){if(r!==11)continue;e.skip(-1);let n=e.currentPos,i=e.ensureBuffered(5);if(i instanceof Promise&&(i=await i),i<5)return;let a=e.readBytes(5);if(a[0]!==11||a[1]!==119){e.seekTo(n+1);continue}let o=(((a[2]&7)<<8|a[3])+1)*2,s=_C[a[4]>>6==3?3:a[4]>>4&3];e.seekTo(n),i=e.ensureBuffered(o),i instanceof Promise&&(i=await i);let c=s*256,l=Math.round(c*BT/t.info.sampleRate);return e.supplyPacket(i,l)}else throw Error(`Unhandled.`)}if(r<128)break}}},XT=class e{constructor(e,t){this.currentPos=0,this.pesPackets=[],this.currentPesPacketIndex=0,this.currentPesPacketPos=0,this.endPos=0,this.nextPts=0,this.suppliedPacket=null,this.elementaryStream=e,this.pid=e.pid,this.demuxer=e.demuxer,this.startingPesPacket=t}clone(){let t=new e(this.elementaryStream,this.startingPesPacket);return t.currentPos=this.currentPos,t.pesPackets=[...this.pesPackets],t.currentPesPacketIndex=this.currentPesPacketIndex,t.currentPesPacketPos=this.currentPesPacketPos,t.endPos=this.endPos,t.nextPts=this.nextPts,t}ensureBuffered(e){let t=this.endPos-this.currentPos;return t>=e?e:this.bufferData(e-t).then(()=>Math.min(this.endPos-this.currentPos,e))}getCurrentPesPacket(){let e=this.pesPackets[this.currentPesPacketIndex];return J(e),e}async bufferData(e){let t=this.endPos+e;for(;this.endPos<t;){let e;if(this.pesPackets.length===0)e=this.startingPesPacket;else{let t=Tb(this.pesPackets).sectionEndPos;for(J(t!==null);;){let n=await this.demuxer.readPacketHeader(t);if(!n)return;if(n.pid===this.pid){let n=await this.demuxer.readSection(t,!0);if(!n)return;let r=WT(n);if(r){e=r;break}}t+=this.demuxer.packetStride}}this.pesPackets.push(e),this.endPos+=e.data.byteLength,this.pesPackets.length===1&&(this.nextPts=e.pts)}}readBytes(e){let t=this.getCurrentPesPacket(),n=this.currentPos-this.currentPesPacketPos,r=n+e;if(this.currentPos+=e,r<=t.data.byteLength)return t.data.subarray(n,r);let i=new Uint8Array(e);i.set(t.data.subarray(n));let a=t.data.byteLength-n;for(;;){this.advanceCurrentPacket();let t=this.getCurrentPesPacket(),n=e-a;if(n<=t.data.byteLength){i.set(t.data.subarray(0,n),a);break}i.set(t.data,a),a+=t.data.byteLength}return i}readU8(){let e=this.getCurrentPesPacket(),t=this.currentPos-this.currentPesPacketPos;return this.currentPos++,t<e.data.byteLength?e.data[t]:(this.advanceCurrentPacket(),e=this.getCurrentPesPacket(),e.data[0])}seekTo(e){if(e!==this.currentPos){if(e<this.currentPos)for(;e<this.currentPesPacketPos;){this.currentPesPacketIndex--;let e=this.getCurrentPesPacket();this.currentPesPacketPos-=e.data.byteLength,this.nextPts=e.pts}else for(;;){let t=this.getCurrentPesPacket();if(e<this.currentPesPacketPos+t.data.byteLength)break;this.currentPesPacketPos+=t.data.byteLength,this.currentPesPacketIndex++,this.nextPts=this.getCurrentPesPacket().pts}this.currentPos=e}}skip(e){this.seekTo(this.currentPos+e)}advanceCurrentPacket(){this.currentPesPacketPos+=this.getCurrentPesPacket().data.byteLength,this.currentPesPacketIndex++,this.nextPts=this.getCurrentPesPacket().pts}supplyPacket(e,t){let n=this.getCurrentPesPacket();JT(this.elementaryStream,n);let r=this.nextPts;this.nextPts+=t;let i=n.sectionStartPos,a=i+(this.currentPos-this.currentPesPacketPos),o=this.readBytes(e),s=n.randomAccessIndicator;J(this.elementaryStream.firstSection),n.sectionStartPos===this.elementaryStream.firstSection.startPos&&(s=1),this.suppliedPacket={pts:r,data:o,sequenceNumber:a,sectionStartPos:i,randomAccessIndicator:s},this.pesPackets.splice(0,this.currentPesPacketIndex),this.currentPesPacketIndex=0}},ZT=class{constructor(e,t){this.decodeOrderPackets=[],this.reorderBuffer=[],this.presentationOrderPackets=[],this.reachedEnd=!1,this.lastDuration=0,this.backing=e,this.context=t,this.reorderSize=e.getReorderSize(),J(this.reorderSize>=0)}async readNext(){if(this.decodeOrderPackets.length===0&&!await this.readNextPacket())return null;await this.ensureCurrentPacketHasNext();let e=this.decodeOrderPackets[0],t=this.presentationOrderPackets.indexOf(e);J(t!==-1);let n;for(t===this.presentationOrderPackets.length-1?n=this.lastDuration:(n=this.presentationOrderPackets[t+1].pts-e.pts,this.lastDuration=n),this.decodeOrderPackets.shift();this.presentationOrderPackets.length>0;){let e=this.presentationOrderPackets[0];if(this.decodeOrderPackets.includes(e))break;this.presentationOrderPackets.shift()}return{packet:e,duration:n}}async readNextPacket(){if(this.reachedEnd)return!1;let e;return this.context.suppliedPacket||await YT(this.context),e=this.context.suppliedPacket,this.context.suppliedPacket=null,e?(this.decodeOrderPackets.push(e),this.processPacketThroughReorderBuffer(e),!0):(this.reachedEnd=!0,this.flushReorderBuffer(),!1)}async ensureCurrentPacketHasNext(){let e=this.decodeOrderPackets[0];for(J(e);;){let t=this.presentationOrderPackets.indexOf(e);if(t!==-1&&t<=this.presentationOrderPackets.length-2||!await this.readNextPacket())break}}processPacketThroughReorderBuffer(e){if(this.reorderBuffer.push(e),this.reorderBuffer.length>=this.reorderSize){let e=0;for(let t=1;t<this.reorderBuffer.length;t++)this.reorderBuffer[t].pts<this.reorderBuffer[e].pts&&(e=t);let t=this.reorderBuffer.splice(e,1)[0];this.presentationOrderPackets.push(t)}}flushReorderBuffer(){this.reorderBuffer.sort((e,t)=>e.pts-t.pts),this.presentationOrderPackets.push(...this.reorderBuffer),this.reorderBuffer.length=0}},QT=class{},$T=class extends QT{async _getMajorBrand(e){let t=e._reader.requestSlice(0,12);return t instanceof Promise&&(t=await t),!t||(t.skip(4),qE(t,4)!==`ftyp`)?null:qE(t,4)}_createDemuxer(e){return new Tw(e)}},eE=class extends $T{async _canReadInput(e){let t=await this._getMajorBrand(e);return!!t&&t!==`qt `}get name(){return`MP4`}get mimeType(){return`video/mp4`}},tE=class extends $T{async _canReadInput(e){return await this._getMajorBrand(e)===`qt `}get name(){return`QuickTime File Format`}get mimeType(){return`video/quicktime`}},nE=class extends QT{async isSupportedEBMLOfDocType(e,t){let n=e._reader.requestSlice(0,16);if(n instanceof Promise&&(n=await n),!n)return!1;let r=zw(n);if(r===null||r<1||r>8||Vw(n,r)!==X.EBML)return!1;let i=Ww(n);if(typeof i!=`number`)return!1;let a=e._reader.requestSlice(n.filePos,i);if(a instanceof Promise&&(a=await a),!a)return!1;let o=n.filePos;for(;a.filePos<=o+i-2;){let e=Gw(a);if(!e)break;let{id:n,size:r}=e,i=a.filePos;if(r===void 0)return!1;switch(n){case X.EBMLVersion:if(Vw(a,r)!==1)return!1;break;case X.EBMLReadVersion:if(Vw(a,r)!==1)return!1;break;case X.DocType:if(Kw(a,r)!==t)return!1;break;case X.DocTypeVersion:if(Vw(a,r)>4)return!1;break}a.filePos=i+r}return!0}_canReadInput(e){return this.isSupportedEBMLOfDocType(e,`matroska`)}_createDemuxer(e){return new aT(e)}get name(){return`Matroska`}get mimeType(){return`video/x-matroska`}},rE=class extends nE{_canReadInput(e){return this.isSupportedEBMLOfDocType(e,`webm`)}get name(){return`WebM`}get mimeType(){return`video/webm`}},iE=class extends QT{async _canReadInput(e){let t=0;for(;;){let n=e._reader.requestSlice(t,10);if(n instanceof Promise&&(n=await n),!n)break;let r=$E(n);if(!r)break;t=n.filePos+r.size}let n=await lT(e._reader,t,t+4096);if(!n)return!1;let r=n.header,i=CS(r.mpegVersionId,r.channel),a=e._reader.requestSlice(n.startPos+i,4);if(a instanceof Promise&&(a=await a),!a)return!1;let o=Z(a);if(o===1483304551||o===1231971951)return!0;t=n.startPos+n.header.totalSize;let s=await lT(e._reader,t,t+4);if(!s)return!1;let c=s.header;return!(r.channel!==c.channel||r.sampleRate!==c.sampleRate)}_createDemuxer(e){return new uT(e)}get name(){return`MP3`}get mimeType(){return`audio/mpeg`}},aE=class extends QT{async _canReadInput(e){let t=e._reader.requestSlice(0,12);if(t instanceof Promise&&(t=await t),!t)return!1;let n=qE(t,4);return n!==`RIFF`&&n!==`RIFX`&&n!==`RF64`?!1:(t.skip(4),qE(t,4)===`WAVE`)}_createDemuxer(e){return new TT(e)}get name(){return`WAVE`}get mimeType(){return`audio/wav`}},oE=class extends QT{async _canReadInput(e){let t=e._reader.requestSlice(0,4);return t instanceof Promise&&(t=await t),t?qE(t,4)===`OggS`:!1}_createDemuxer(e){return new bT(e)}get name(){return`Ogg`}get mimeType(){return`application/ogg`}},sE=class extends QT{async _canReadInput(e){let t=e._reader.requestSlice(0,4);return t instanceof Promise&&(t=await t),t?qE(t,4)===`fLaC`:!1}get name(){return`FLAC`}get mimeType(){return`audio/flac`}_createDemuxer(e){return new RT(e)}},cE=class extends QT{async _canReadInput(e){let t=0;for(;;){let n=e._reader.requestSlice(t,10);if(n instanceof Promise&&(n=await n),!n)break;let r=$E(n);if(!r)break;t=n.filePos+r.size}let n=e._reader.requestSliceRange(t,7,9);if(n instanceof Promise&&(n=await n),!n)return!1;let r=OT(n);if(!r||(t+=r.frameLength,n=e._reader.requestSliceRange(t,7,9),n instanceof Promise&&(n=await n),!n))return!1;let i=OT(n);return i?r.objectType===i.objectType&&r.samplingFrequencyIndex===i.samplingFrequencyIndex&&r.channelConfiguration===i.channelConfiguration:!1}_createDemuxer(e){return new AT(e)}get name(){return`ADTS`}get mimeType(){return`audio/aac`}},lE=class extends QT{async _canReadInput(e){let t=e._reader.requestSlice(0,205);if(t instanceof Promise&&(t=await t),!t)return!1;let n=jE(t,205);return n[0]===71&&n[188]===71||n[0]===71&&n[204]===71?!0:n[4]===71&&n[196]===71}_createDemuxer(e){return new HT(e)}get name(){return`MPEG Transport Stream`}get mimeType(){return`video/MP2T`}},uE=new eE,dE=new tE,fE=new nE,pE=new rE,mE=new iE,hE=new aE,gE=new oE,_E=new cE,vE=[uE,dE,fE,pE,hE,gE,new sE,mE,_E,new lE];e(gv(),1);var yE=class{constructor(){this._disposed=!1,this._sizePromise=null,this.onread=null}async getSizeOrNull(){if(this._disposed)throw new DE;return this._sizePromise??=Promise.resolve(this._retrieveSize())}async getSize(){if(this._disposed)throw new DE;let e=await this.getSizeOrNull();if(e===null)throw Error(`Cannot determine the size of an unsized source.`);return e}},bE=class extends yE{constructor(e){if(!(e instanceof ArrayBuffer)&&!(typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer)&&!ArrayBuffer.isView(e))throw TypeError(`buffer must be an ArrayBuffer, SharedArrayBuffer, or ArrayBufferView.`);super(),this._onreadCalled=!1,this._bytes=Ob(e),this._view=kb(e)}_retrieveSize(){return this._bytes.byteLength}_read(){return this._onreadCalled||=(this.onread?.(0,this._bytes.byteLength),!0),{bytes:this._bytes,view:this._view,offset:0}}_dispose(){}},xE=.5*2**20,SE=((e,t,n)=>{if(t instanceof Error&&(t.message.includes(`Failed to fetch`)||t.message.includes(`Load failed`)||t.message.includes(`NetworkError when attempting to fetch resource`))){let e=null;try{typeof window<`u`&&window.location!==void 0&&(e=new URL(n instanceof Request?n.url:n,window.location.href).origin)}catch{}if((!(typeof navigator<`u`&&typeof navigator.onLine==`boolean`)||navigator.onLine)&&e!==null&&e!==window.location.origin)return console.warn(`Request will not be retried because a CORS error was suspected due to different origins. You can modify this behavior by providing your own function for the 'getRetryDelay' option.`),null}return Math.min(2**(e-2),16)}),CE=class extends yE{constructor(e,t={}){if(typeof e!=`string`&&!(e instanceof URL)&&!(typeof Request<`u`&&e instanceof Request))throw TypeError(`url must be a string, URL or Request.`);if(!t||typeof t!=`object`)throw TypeError(`options must be an object.`);if(t.requestInit!==void 0&&(!t.requestInit||typeof t.requestInit!=`object`))throw TypeError(`options.requestInit, when provided, must be an object.`);if(t.getRetryDelay!==void 0&&typeof t.getRetryDelay!=`function`)throw TypeError(`options.getRetryDelay, when provided, must be a function.`);if(t.maxCacheSize!==void 0&&(!Ax(t.maxCacheSize)||t.maxCacheSize<0))throw TypeError(`options.maxCacheSize, when provided, must be a non-negative number.`);if(t.parallelism!==void 0&&(!Number.isInteger(t.parallelism)||t.parallelism<1))throw TypeError(`options.parallelism, when provided, must be a positive number.`);if(t.fetchFn!==void 0&&typeof t.fetchFn!=`function`)throw TypeError(`options.fetchFn, when provided, must be a function.`);super(),this._existingResponses=new WeakMap,this._url=e,this._options=t,this._getRetryDelay=t.getRetryDelay??SE,this._orchestrator=new TE({maxCacheSize:t.maxCacheSize??64*2**20,maxWorkerCount:t.parallelism??2,runWorker:this._runWorker.bind(this),prefetchProfile:wE.network})}async _retrieveSize(){let e=new AbortController,t=await mx(this._options.fetchFn??fetch,this._url,fx(this._options.requestInit??{},{headers:{Range:`bytes=0-`},signal:e.signal}),this._getRetryDelay,()=>this._disposed);if(!t.ok)throw Error(`Error fetching ${String(this._url)}: ${t.status} ${t.statusText}`);let n,r;if(t.status===206)r=this._getTotalLengthFromRangeResponse(t),n=this._orchestrator.createWorker(0,Math.min(r,xE));else{let e=t.headers.get(`Content-Length`);if(e)r=Number(e),n=this._orchestrator.createWorker(0,r),this._orchestrator.options.maxCacheSize=1/0,console.warn(`HTTP server did not respond with 206 Partial Content, meaning the entire remote resource now has to be downloaded. For efficient media file streaming across a network, please make sure your server supports range requests.`);else throw Error(`HTTP response (status ${t.status}) must surface Content-Length header.`)}return this._orchestrator.fileSize=r,this._existingResponses.set(n,{response:t,abortController:e}),this._orchestrator.runWorker(n),r}_read(e,t){return this._orchestrator.read(e,t)}async _runWorker(e){for(;;){let t=this._existingResponses.get(e);this._existingResponses.delete(e);let n=t?.abortController,r=t?.response;if(n||(n=new AbortController,r=await mx(this._options.fetchFn??fetch,this._url,fx(this._options.requestInit??{},{headers:{Range:`bytes=${e.currentPos}-`},signal:n.signal}),this._getRetryDelay,()=>this._disposed)),J(r),!r.ok)throw Error(`Error fetching ${String(this._url)}: ${r.status} ${r.statusText}`);if(e.currentPos>0&&r.status!==206)throw Error(`HTTP server did not respond with 206 Partial Content to a range request. To enable efficient media file streaming across a network, please make sure your server supports range requests.`);if(!r.body)throw Error(`Missing HTTP response body stream. The used fetch function must provide the response body as a ReadableStream.`);let i=r.body.getReader();for(;;){if(e.currentPos>=e.targetPos||e.aborted){n.abort(),e.running=!1;return}let t;try{t=await i.read()}catch(e){if(this._disposed)throw e;let t=this._getRetryDelay(1,e,this._url);if(t!==null){console.error(`Error while reading response stream. Attempting to resume.`,e),await new Promise(e=>setTimeout(e,1e3*t));break}else throw e}if(e.aborted)continue;let{done:r,value:a}=t;if(r){if(e.currentPos>=e.targetPos){this._orchestrator.forgetWorker(e),e.running=!1;return}break}this.onread?.(e.currentPos,e.currentPos+a.length),this._orchestrator.supplyWorkerData(e,a)}}}_getTotalLengthFromRangeResponse(e){let t=e.headers.get(`Content-Range`);if(t){let e=/\/(\d+)/.exec(t);if(e)return Number(e[1])}let n=e.headers.get(`Content-Length`);if(n)return Number(n);throw Error(`Partial HTTP response (status 206) must surface either Content-Range or Content-Length header.`)}_dispose(){this._orchestrator.dispose()}},wE={none:(e,t)=>({start:e,end:t}),fileSystem:(e,t)=>{let n=2**16;return e=Math.floor((e-n)/n)*n,t=Math.ceil((t+n)/n)*n,{start:e,end:t}},network:(e,t,n)=>{let r=2**16;e=Math.max(0,Math.floor((e-r)/r)*r);for(let r of n){let n=8*2**20,i=Math.max((r.startPos+r.targetPos)/2,r.targetPos-n);if(Ex(e,t,i,r.targetPos)){let e=r.targetPos-r.startPos,i=Math.ceil((e+1)/n)*n,a=2**Math.ceil(Math.log2(e+1)),o=Math.min(a,i);t=Math.max(t,r.startPos+o)}}return t=Math.max(t,e+xE),{start:e,end:t}}},TE=class{constructor(e){this.options=e,this.fileSize=null,this.nextAge=0,this.workers=[],this.cache=[],this.currentCacheSize=0,this.disposed=!1}read(e,t){J(this.fileSize!==null);let n=this.options.prefetchProfile(e,t,this.workers),r=Math.max(n.start,0),i=Math.min(n.end,this.fileSize);J(r<=e&&t<=i);let a=null,o=Gb(this.cache,e,e=>e.start),s=o===-1?null:this.cache[o];s&&s.start<=e&&t<=s.end&&(s.age=this.nextAge++,a={bytes:s.bytes,view:s.view,offset:s.start});let c=Gb(this.cache,r,e=>e.start),l=a?null:new Uint8Array(t-e),u=0,d=r,f=[];if(c!==-1){for(let n=c;n<this.cache.length;n++){let a=this.cache[n];if(a.start>=i)break;if(a.end<=r)continue;let o=Math.max(r,a.start),s=Math.min(i,a.end);if(J(o<=s),d<o&&f.push({start:d,end:o}),d=s,l){let n=Math.max(e,a.start),r=Math.min(t,a.end);if(n<r){let t=n-e;l.set(a.bytes.subarray(n-a.start,r-a.start),t),t===u&&(u=r-e)}}a.age=this.nextAge++}d<i&&f.push({start:d,end:i})}else f.push({start:r,end:i});if(l&&u>=l.length&&(a={bytes:l,view:kb(l),offset:e}),f.length===0)return J(a),a;let{promise:p,resolve:m,reject:h}=qb(),g=[];for(let n of f){let r=Math.max(e,n.start),i=Math.min(t,n.end);r===n.start&&i===n.end?g.push(n):r<i&&g.push({start:r,end:i})}for(let t of f){let n=l&&{start:e,bytes:l,holes:g,resolve:m,reject:h},r=!1;for(let e of this.workers)if(Ex(t.start-2**17,t.start,e.currentPos,e.targetPos)){e.targetPos=Math.max(e.targetPos,t.end),r=!0,n&&!e.pendingSlices.includes(n)&&e.pendingSlices.push(n),e.running||this.runWorker(e);break}if(!r){let e=this.createWorker(t.start,t.end);n&&(e.pendingSlices=[n]),this.runWorker(e)}}return a||=(J(l),p.then(t=>({bytes:t,view:kb(t),offset:e}))),a}createWorker(e,t){let n={startPos:e,currentPos:e,targetPos:t,running:!1,aborted:this.disposed,pendingSlices:[],age:this.nextAge++};for(this.workers.push(n);this.workers.length>this.options.maxWorkerCount;){let e=0,t=this.workers[0];for(let n=1;n<this.workers.length;n++){let r=this.workers[n];r.age<t.age&&(e=n,t=r)}if(t.running&&t.pendingSlices.length>0)break;t.aborted=!0,this.workers.splice(e,1)}return n}runWorker(e){J(!e.running),J(e.currentPos<e.targetPos),e.running=!0,e.age=this.nextAge++,this.options.runWorker(e).catch(t=>{if(e.running=!1,e.pendingSlices.length>0)e.pendingSlices.forEach(e=>e.reject(t)),e.pendingSlices.length=0;else throw t})}supplyWorkerData(e,t){J(!e.aborted);let n=e.currentPos,r=n+t.length;this.insertIntoCache({start:n,end:r,bytes:t,view:kb(t),age:this.nextAge++}),e.currentPos+=t.length,e.targetPos=Math.max(e.targetPos,e.currentPos);for(let i=0;i<e.pendingSlices.length;i++){let a=e.pendingSlices[i],o=Math.max(n,a.start),s=Math.min(r,a.start+a.bytes.length);o<s&&a.bytes.set(t.subarray(o-n,s-n),o-a.start);for(let e=0;e<a.holes.length;e++){let t=a.holes[e];n<=t.start&&r>t.start&&(t.start=r),t.end<=t.start&&(a.holes.splice(e,1),e--)}a.holes.length===0&&(a.resolve(a.bytes),e.pendingSlices.splice(i,1),i--)}for(let t=0;t<this.workers.length;t++){let i=this.workers[t];e===i||i.running||Ex(n,r,i.currentPos,i.targetPos)&&(this.workers.splice(t,1),t--)}}forgetWorker(e){let t=this.workers.indexOf(e);J(t!==-1),this.workers.splice(t,1)}insertIntoCache(e){if(this.options.maxCacheSize===0)return;let t=Gb(this.cache,e.start,e=>e.start)+1;if(t>0){let n=this.cache[t-1];if(n.end>=e.end)return;if(n.end>e.start){let r=new Uint8Array(e.end-n.start);r.set(n.bytes,0),r.set(e.bytes,e.start-n.start),this.currentCacheSize+=e.end-n.end,n.bytes=r,n.view=kb(r),n.end=e.end,t--,e=n}else this.cache.splice(t,0,e),this.currentCacheSize+=e.bytes.length}else this.cache.splice(t,0,e),this.currentCacheSize+=e.bytes.length;for(let n=t+1;n<this.cache.length;n++){let t=this.cache[n];if(e.end<=t.start)break;if(e.end>=t.end){this.cache.splice(n,1),this.currentCacheSize-=t.bytes.length,n--;continue}let r=new Uint8Array(t.end-e.start);r.set(e.bytes,0),r.set(t.bytes,t.start-e.start),this.currentCacheSize-=e.end-t.start,e.bytes=r,e.view=kb(r),e.end=t.end,this.cache.splice(n,1);break}for(;this.currentCacheSize>this.options.maxCacheSize;){let e=0,t=this.cache[0];for(let n=1;n<this.cache.length;n++){let r=this.cache[n];r.age<t.age&&(e=n,t=r)}if(this.currentCacheSize-t.bytes.length<=this.options.maxCacheSize)break;this.cache.splice(e,1),this.currentCacheSize-=t.bytes.length}}dispose(){for(let e of this.workers)e.aborted=!0;this.workers.length=0,this.cache.length=0,this.disposed=!0}};kx();var EE=class{get disposed(){return this._disposed}constructor(e){if(this._demuxerPromise=null,this._format=null,this._disposed=!1,!e||typeof e!=`object`)throw TypeError(`options must be an object.`);if(!Array.isArray(e.formats)||e.formats.some(e=>!(e instanceof QT)))throw TypeError(`options.formats must be an array of InputFormat.`);if(!(e.source instanceof yE))throw TypeError(`options.source must be a Source.`);if(e.source._disposed)throw Error(`options.source must not be disposed.`);this._formats=e.formats,this._source=e.source,this._reader=new OE(e.source)}_getDemuxer(){return this._demuxerPromise??=(async()=>{this._reader.fileSize=await this._source.getSizeOrNull();for(let e of this._formats)if(await e._canReadInput(this))return this._format=e,e._createDemuxer(this);throw Error(`Input has an unsupported or unrecognizable format.`)})()}get source(){return this._source}async getFormat(){return await this._getDemuxer(),J(this._format),this._format}async computeDuration(){return(await this._getDemuxer()).computeDuration()}async getFirstTimestamp(){let e=await this.getTracks();if(e.length===0)return 0;let t=await Promise.all(e.map(e=>e.getFirstTimestamp()));return Math.min(...t)}async getTracks(){return(await this._getDemuxer()).getTracks()}async getVideoTracks(){return(await this.getTracks()).filter(e=>e.isVideoTrack())}async getAudioTracks(){return(await this.getTracks()).filter(e=>e.isAudioTrack())}async getPrimaryVideoTrack(){return(await this.getTracks()).find(e=>e.isVideoTrack())??null}async getPrimaryAudioTrack(){return(await this.getTracks()).find(e=>e.isAudioTrack())??null}async getMimeType(){return(await this._getDemuxer()).getMimeType()}async getMetadataTags(){return(await this._getDemuxer()).getMetadataTags()}dispose(){this._disposed||(this._disposed=!0,this._source._disposed=!0,this._source._dispose())}[Symbol.dispose](){this.dispose()}},DE=class extends Error{constructor(e=`Input has been disposed.`){super(e),this.name=`InputDisposedError`}},OE=class{constructor(e){this.source=e}requestSlice(e,t){if(this.source._disposed)throw new DE;if(e<0||this.fileSize!==null&&e+t>this.fileSize)return null;let n=e+t,r=this.source._read(e,n);return r instanceof Promise?r.then(t=>t?new kE(t.bytes,t.view,t.offset,e,n):null):r?new kE(r.bytes,r.view,r.offset,e,n):null}requestSliceRange(e,t,n){if(this.source._disposed)throw new DE;if(e<0)return null;if(this.fileSize!==null)return this.requestSlice(e,ix(this.fileSize-e,t,n));{let r=this.requestSlice(e,n),i=r=>{if(r)return r;let i=r=>(J(r!==null),this.requestSlice(e,ix(r-e,t,n))),a=this.source._retrieveSize();return a instanceof Promise?a.then(i):i(a)};return r instanceof Promise?r.then(i):i(r)}}},kE=class e{constructor(e,t,n,r,i){this.bytes=e,this.view=t,this.offset=n,this.start=r,this.end=i,this.bufferPos=r-n}static tempFromBytes(t){return new e(t,kb(t),0,0,t.length)}get length(){return this.end-this.start}get filePos(){return this.offset+this.bufferPos}set filePos(e){this.bufferPos=e-this.offset}get remainingLength(){return Math.max(this.end-this.filePos,0)}skip(e){this.bufferPos+=e}slice(t,n=this.end-t){if(t<this.start||t+n>this.end)throw RangeError(`Slicing outside of original slice.`);return new e(this.bytes,this.view,this.offset,t,t+n)}},AE=(e,t)=>{if(e.filePos<e.start||e.filePos+t>e.end)throw RangeError(`Tried reading [${e.filePos}, ${e.filePos+t}), but slice is [${e.start}, ${e.end}). This is likely an internal error, please report it alongside the file that caused it.`)},jE=(e,t)=>{AE(e,t);let n=e.bytes.subarray(e.bufferPos,e.bufferPos+t);return e.bufferPos+=t,n},ME=e=>(AE(e,1),e.view.getUint8(e.bufferPos++)),NE=(e,t)=>{AE(e,2);let n=e.view.getUint16(e.bufferPos,t);return e.bufferPos+=2,n},PE=e=>{AE(e,2);let t=e.view.getUint16(e.bufferPos,!1);return e.bufferPos+=2,t},FE=e=>{AE(e,3);let t=$b(e.view,e.bufferPos,!1);return e.bufferPos+=3,t},IE=e=>{AE(e,2);let t=e.view.getInt16(e.bufferPos,!1);return e.bufferPos+=2,t},LE=(e,t)=>{AE(e,4);let n=e.view.getUint32(e.bufferPos,t);return e.bufferPos+=4,n},Z=e=>{AE(e,4);let t=e.view.getUint32(e.bufferPos,!1);return e.bufferPos+=4,t},RE=e=>{AE(e,4);let t=e.view.getUint32(e.bufferPos,!0);return e.bufferPos+=4,t},zE=e=>{AE(e,4);let t=e.view.getInt32(e.bufferPos,!1);return e.bufferPos+=4,t},BE=e=>{AE(e,4);let t=e.view.getInt32(e.bufferPos,!0);return e.bufferPos+=4,t},VE=(e,t)=>{let n,r;return t?(n=LE(e,!0),r=LE(e,!0)):(r=LE(e,!1),n=LE(e,!1)),r*4294967296+n},HE=e=>{let t=Z(e),n=Z(e);return t*4294967296+n},UE=e=>{let t=zE(e),n=Z(e);return t*4294967296+n},WE=e=>{let t=RE(e);return BE(e)*4294967296+t},GE=e=>{AE(e,4);let t=e.view.getFloat32(e.bufferPos,!1);return e.bufferPos+=4,t},KE=e=>{AE(e,8);let t=e.view.getFloat64(e.bufferPos,!1);return e.bufferPos+=8,t},qE=(e,t)=>{AE(e,t);let n=``;for(let r=0;r<t;r++)n+=String.fromCharCode(e.bytes[e.bufferPos++]);return n},JE;(function(e){e[e.Unsynchronisation=128]=`Unsynchronisation`,e[e.ExtendedHeader=64]=`ExtendedHeader`,e[e.ExperimentalIndicator=32]=`ExperimentalIndicator`,e[e.Footer=16]=`Footer`})(JE||={});var YE;(function(e){e[e.ISO_8859_1=0]=`ISO_8859_1`,e[e.UTF_16_WITH_BOM=1]=`UTF_16_WITH_BOM`,e[e.UTF_16_BE_NO_BOM=2]=`UTF_16_BE_NO_BOM`,e[e.UTF_8=3]=`UTF_8`})(YE||={});var XE=`Blues.Classic rock.Country.Dance.Disco.Funk.Grunge.Hip-hop.Jazz.Metal.New age.Oldies.Other.Pop.Rhythm and blues.Rap.Reggae.Rock.Techno.Industrial.Alternative.Ska.Death metal.Pranks.Soundtrack.Euro-techno.Ambient.Trip-hop.Vocal.Jazz & funk.Fusion.Trance.Classical.Instrumental.Acid.House.Game.Sound clip.Gospel.Noise.Alternative rock.Bass.Soul.Punk.Space.Meditative.Instrumental pop.Instrumental rock.Ethnic.Gothic.Darkwave.Techno-industrial.Electronic.Pop-folk.Eurodance.Dream.Southern rock.Comedy.Cult.Gangsta.Top 40.Christian rap.Pop/funk.Jungle music.Native US.Cabaret.New wave.Psychedelic.Rave.Showtunes.Trailer.Lo-fi.Tribal.Acid punk.Acid jazz.Polka.Retro.Musical.Rock 'n' roll.Hard rock.Folk.Folk rock.National folk.Swing.Fast fusion.Bebop.Latin.Revival.Celtic.Bluegrass.Avantgarde.Gothic rock.Progressive rock.Psychedelic rock.Symphonic rock.Slow rock.Big band.Chorus.Easy listening.Acoustic.Humour.Speech.Chanson.Opera.Chamber music.Sonata.Symphony.Booty bass.Primus.Porn groove.Satire.Slow jam.Club.Tango.Samba.Folklore.Ballad.Power ballad.Rhythmic Soul.Freestyle.Duet.Punk rock.Drum solo.A cappella.Euro-house.Dance hall.Goa music.Drum & bass.Club-house.Hardcore techno.Terror.Indie.Britpop.Negerpunk.Polsk punk.Beat.Christian gangsta rap.Heavy metal.Black metal.Crossover.Contemporary Christian.Christian rock.Merengue.Salsa.Thrash metal.Anime.Jpop.Synthpop.Christmas.Art rock.Baroque.Bhangra.Big beat.Breakbeat.Chillout.Downtempo.Dub.EBM.Eclectic.Electro.Electroclash.Emo.Experimental.Garage.Global.IDM.Illbient.Industro-Goth.Jam Band.Krautrock.Leftfield.Lounge.Math rock.New romantic.Nu-breakz.Post-punk.Post-rock.Psytrance.Shoegaze.Space rock.Trop rock.World music.Neoclassical.Audiobook.Audio theatre.Neue Deutsche Welle.Podcast.Indie rock.G-Funk.Dubstep.Garage rock.Psybient`.split(`.`),ZE=(e,t)=>{let n=e.filePos;t.raw??={},t.raw.TAG??=jE(e,125),e.filePos=n;let r=QE(e,30);r&&(t.title??=r);let i=QE(e,30);i&&(t.artist??=i);let a=QE(e,30);a&&(t.album??=a);let o=QE(e,4),s=Number.parseInt(o,10);Number.isInteger(s)&&s>0&&(t.date??=new Date(s,0,1));let c=jE(e,30),l;if(c[28]===0&&c[29]!==0){let n=c[29];n>0&&(t.trackNumber??=n),e.skip(-30),l=QE(e,28),e.skip(2)}else e.skip(-30),l=QE(e,30);l&&(t.comment??=l);let u=ME(e);u<XE.length&&(t.genre??=XE[u])},QE=(e,t)=>{let n=jE(e,t),r=Tx(n.indexOf(0),n.length),i=n.subarray(0,r),a=``;for(let e=0;e<i.length;e++)a+=String.fromCharCode(i[e]);return a.trimEnd()},$E=e=>{let t=e.filePos,n=qE(e,3),r=ME(e),i=ME(e),a=ME(e),o=Z(e);return n!==`ID3`||r===255||i===255||o&2155905152?(e.filePos=t,null):{majorVersion:r,revision:i,flags:a,size:TS(o)}},eD=(e,t,n)=>{if(![2,3,4].includes(t.majorVersion)){console.warn(`Unsupported ID3v2 major version: ${t.majorVersion}`);return}let r=new tD(t,jE(e,t.size));if(t.flags&JE.Footer&&r.removeFooter(),t.flags&JE.Unsynchronisation&&t.majorVersion===3&&r.ununsynchronizeAll(),t.flags&JE.ExtendedHeader){let e=r.readU32();t.majorVersion===3?r.pos+=e:r.pos+=e-4}for(;r.pos<=r.bytes.length-r.frameHeaderSize();){let e=r.readId3V2Frame();if(!e)break;let i=r.pos,a=r.pos+e.size,o=!1,s=!1,c=!1;if(t.majorVersion===3?(o=!!(e.flags&64),s=!!(e.flags&128)):t.majorVersion===4&&(o=!!(e.flags&4),s=!!(e.flags&8),c=!!(e.flags&2)||!!(t.flags&JE.Unsynchronisation)),o){console.warn(`Skipping encrypted ID3v2 frame ${e.id}`),r.pos=a;continue}if(s){console.warn(`Skipping compressed ID3v2 frame ${e.id}`),r.pos=a;continue}switch(c&&r.ununsynchronizeRegion(r.pos,a),n.raw??={},e.id[0]===`T`?n.raw[e.id]??=r.readId3V2EncodingAndText(a):n.raw[e.id]??=r.readBytes(e.size),r.pos=i,e.id){case`TIT2`:case`TT2`:n.title??=r.readId3V2EncodingAndText(a);break;case`TIT3`:case`TT3`:n.description??=r.readId3V2EncodingAndText(a);break;case`TPE1`:case`TP1`:n.artist??=r.readId3V2EncodingAndText(a);break;case`TALB`:case`TAL`:n.album??=r.readId3V2EncodingAndText(a);break;case`TPE2`:case`TP2`:n.albumArtist??=r.readId3V2EncodingAndText(a);break;case`TRCK`:case`TRK`:{let e=r.readId3V2EncodingAndText(a).split(`/`),t=Number.parseInt(e[0],10),i=e[1]&&Number.parseInt(e[1],10);Number.isInteger(t)&&t>0&&(n.trackNumber??=t),i&&Number.isInteger(i)&&i>0&&(n.tracksTotal??=i)}break;case`TPOS`:case`TPA`:{let e=r.readId3V2EncodingAndText(a).split(`/`),t=Number.parseInt(e[0],10),i=e[1]&&Number.parseInt(e[1],10);Number.isInteger(t)&&t>0&&(n.discNumber??=t),i&&Number.isInteger(i)&&i>0&&(n.discsTotal??=i)}break;case`TCON`:case`TCO`:{let e=r.readId3V2EncodingAndText(a),t=/^\((\d+)\)/.exec(e);if(t){let e=Number.parseInt(t[1]);if(XE[e]!==void 0){n.genre??=XE[e];break}}if(t=/^\d+$/.exec(e),t){let e=Number.parseInt(t[0]);if(XE[e]!==void 0){n.genre??=XE[e];break}}n.genre??=e}break;case`TDRC`:case`TDAT`:{let e=r.readId3V2EncodingAndText(a),t=new Date(e);Number.isNaN(t.getTime())||(n.date??=t)}break;case`TYER`:case`TYE`:{let e=r.readId3V2EncodingAndText(a),t=Number.parseInt(e,10);Number.isInteger(t)&&(n.date??=new Date(t,0,1))}break;case`USLT`:case`ULT`:{let e=r.readU8();r.pos+=3,r.readId3V2Text(e,a),n.lyrics??=r.readId3V2Text(e,a)}break;case`COMM`:case`COM`:{let e=r.readU8();r.pos+=3,r.readId3V2Text(e,a),n.comment??=r.readId3V2Text(e,a)}break;case`APIC`:case`PIC`:{let e=r.readId3V2TextEncoding(),i;if(t.majorVersion===2){let e=r.readAscii(3);i=e===`PNG`?`image/png`:e===`JPG`?`image/jpeg`:`image/*`}else i=r.readId3V2Text(e,a);let o=r.readU8(),s=r.readId3V2Text(e,a).trimEnd(),c=a-r.pos;if(c>=0){let e=r.readBytes(c);n.images||=[],n.images.push({data:e,mimeType:i,kind:o===3?`coverFront`:o===4?`coverBack`:`unknown`,description:s})}}break;default:r.pos+=e.size;break}r.pos=a}},tD=class{constructor(e,t){this.header=e,this.bytes=t,this.pos=0,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength)}frameHeaderSize(){return this.header.majorVersion===2?6:10}ununsynchronizeAll(){let e=[];for(let t=0;t<this.bytes.length;t++){let n=this.bytes[t];e.push(n),n===255&&t!==this.bytes.length-1&&this.bytes[t]===0&&t++}this.bytes=new Uint8Array(e),this.view=new DataView(this.bytes.buffer)}ununsynchronizeRegion(e,t){let n=[];for(let r=e;r<t;r++){let e=this.bytes[r];n.push(e),e===255&&r!==t-1&&this.bytes[r+1]===0&&r++}let r=this.bytes.subarray(0,e),i=this.bytes.subarray(t);this.bytes=new Uint8Array(r.length+n.length+i.length),this.bytes.set(r,0),this.bytes.set(n,r.length),this.bytes.set(i,r.length+n.length),this.view=new DataView(this.bytes.buffer)}removeFooter(){this.bytes=this.bytes.subarray(0,this.bytes.length-10),this.view=new DataView(this.bytes.buffer)}readBytes(e){let t=this.bytes.subarray(this.pos,this.pos+e);return this.pos+=e,t}readU8(){let e=this.view.getUint8(this.pos);return this.pos+=1,e}readU16(){let e=this.view.getUint16(this.pos,!1);return this.pos+=2,e}readU24(){let e=this.view.getUint16(this.pos,!1),t=this.view.getUint8(this.pos+1);return this.pos+=3,e*256+t}readU32(){let e=this.view.getUint32(this.pos,!1);return this.pos+=4,e}readAscii(e){let t=``;for(let n=0;n<e;n++)t+=String.fromCharCode(this.view.getUint8(this.pos+n));return this.pos+=e,t}readId3V2Frame(){if(this.header.majorVersion===2){let e=this.readAscii(3);return e===`\0\0\0`?null:{id:e,size:this.readU24(),flags:0}}else{let e=this.readAscii(4);if(e===`\0\0\0\0`)return null;let t=this.readU32(),n=this.header.majorVersion===4?TS(t):t,r=this.readU16(),i=this.pos,a=e=>{let t=this.pos+e;if(t>this.bytes.length)return!1;if(t<=this.bytes.length-this.frameHeaderSize()){this.pos+=e;let t=this.readAscii(4);if(t!==`\0\0\0\0`&&!/[0-9A-Z]{4}/.test(t))return!1}return!0};if(!a(n)){let e=this.header.majorVersion===4?t:TS(t);a(e)&&(n=e)}return this.pos=i,{id:e,size:n,flags:r}}}readId3V2TextEncoding(){let e=this.readU8();if(e>3)throw Error(`Unsupported text encoding: ${e}`);return e}readId3V2Text(e,t){let n=this.pos,r=this.readBytes(t-this.pos);switch(e){case YE.ISO_8859_1:{let e=``;for(let t=0;t<r.length;t++){let i=r[t];if(i===0){this.pos=n+t+1;break}e+=String.fromCharCode(i)}return e}case YE.UTF_16_WITH_BOM:if(r[0]===255&&r[1]===254){let e=new TextDecoder(`utf-16le`),t=Tx(r.findIndex((e,t)=>e===0&&r[t+1]===0&&t%2==0),r.length);return this.pos=n+Math.min(t+2,r.length),e.decode(r.subarray(2,t))}else if(r[0]===254&&r[1]===255){let e=new TextDecoder(`utf-16be`),t=Tx(r.findIndex((e,t)=>e===0&&r[t+1]===0&&t%2==0),r.length);return this.pos=n+Math.min(t+2,r.length),e.decode(r.subarray(2,t))}else{let e=Tx(r.findIndex(e=>e===0),r.length);return this.pos=n+Math.min(e+1,r.length),Ab.decode(r.subarray(0,e))}case YE.UTF_16_BE_NO_BOM:{let e=new TextDecoder(`utf-16be`),t=Tx(r.findIndex((e,t)=>e===0&&r[t+1]===0&&t%2==0),r.length);return this.pos=n+Math.min(t+2,r.length),e.decode(r.subarray(0,t))}case YE.UTF_8:{let e=Tx(r.findIndex(e=>e===0),r.length);return this.pos=n+Math.min(e+1,r.length),Ab.decode(r.subarray(0,e))}}}readId3V2EncodingAndText(e){if(this.pos>=e)return``;let t=this.readId3V2TextEncoding();return this.readId3V2Text(t,e)}},nD=.05,rD=(e,t,n)=>{let[r,i]=d.useState({input:null,videoSink:null,duration:0,isReady:!1,error:null});d.useRef(r).current=r;let a=d.useRef(0),o=d.useRef(null),s=d.useRef(null),c=d.useRef(null),l=d.useRef(null),u=d.useRef(null),f=d.useRef(null),p=d.useRef(!1),m=d.useRef(null),h=d.useRef([]),g=d.useRef(null),_=d.useRef(!1),[,v]=d.useReducer(e=>e+1,0);return d.useEffect(()=>{if(!n)return;let t=!0,r=++a.current,o=null;return(async()=>{try{if(!t||r!==a.current)return;o=Kf(`mediabunny init ${e.id}`);let n=await async function(e){if(function(e){return e.startsWith(`data:`)}(e))return new bE(function(e){let t=e.indexOf(`,`);if(t===-1)throw Error(`Invalid data URL format`);let n=e.slice(t+1),r=atob(n),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i.buffer}(e));if(function(e){return e.startsWith(`file://`)}(e))try{return new bE(await(await fetch(e)).arrayBuffer())}catch(t){throw Error(`Failed to load file URL: ${e}. File URLs may not be supported in this environment. Error: ${t}`)}return new CE(e)}(e.src);if(!t||r!==a.current){o&&=(o(),null);return}let s=new EE({source:n,formats:vE}),c=await s.computeDuration(),l=await s.getPrimaryVideoTrack();if(!l)throw Error(`No video track found`);if(l.codec===null)throw Error(`Unsupported video codec`);if(!await l.canDecode())throw Error(`Unable to decode the video track`);let u=new uw(l,{poolSize:5,fit:`contain`,alpha:await l.canBeTransparent()});if(!t||r!==a.current){s.dispose(),o&&=(o(),null);return}o&&=(o(),null),i(e=>Object.assign(Object.assign({},e),{input:s,videoSink:u,duration:c,isReady:!0,error:null}))}catch(n){console.error(`Failed to initialize mediabunny:`,n),o&&=(o(),null),t&&r===a.current&&(Zf(`Failed to initialize mediabunny for video ${e.id}: ${n}`),i(e=>Object.assign(Object.assign({},e),{error:String(n),isReady:!1})))}})(),()=>{t=!1,o&&=(o(),null)}},[e.src,n]),d.useEffect(()=>()=>{s.current&&=(s.current.return(),null),o.current&&=(o.current(),null),c.current=null,l.current=null,u.current=null,p.current=!1,m.current=null,h.current=[],g.current=null,_.current=!1,i({input:null,videoSink:null,duration:0,isReady:!1,error:null})},[n]),d.useEffect(()=>{if(!n||!r.isReady||!r.videoSink)return;let i=++a.current,d=typeof e.src==`string`?e.src.slice(0,120):String(e.src),y=(t,n={},i=`debug`)=>{let a=``;try{a=JSON.stringify(Object.assign(Object.assign({},n),{timeCalc:f.current}))}catch(e){a=`[unserializable extras: ${String(e)}]`}let o=`mediabunny event=${t} elementId=${e.id} targetTime=${u.current} duration=${r.duration} lastFrameTimestamp=${l.current} hasIterator=${!!s.current} prefetchSize=${h.current.length} srcHint=${d} extras=${a}`;i===`error`?console.error(o):i===`warn`?console.warn(o):console.debug(o)},b=e=>{let t=r.duration||0;if(!t||!Number.isFinite(t))return e;let n=t>nD?t-nD:t;return Math.max(0,Math.min(e,n))},x=e=>{let t=r.duration||0;return!(!t||!Number.isFinite(t))&&t-e<=.050001000000000004},S=e=>{let t=c.current;t&&t.width===e.canvas.width&&t.height===e.canvas.height||(t||(t=document.createElement(`canvas`),c.current=t),t.width=e.canvas.width,t.height=e.canvas.height);let n=t.getContext(`2d`);n&&(n.clearRect(0,0,t.width,t.height),n.drawImage(e.canvas,0,0)),l.current=e.timestamp},C=e=>{let t=s.current;t&&(_.current||(_.current=!0,g.current=(async()=>{try{for(;h.current.length<4&&e===a.current;){let n=await t.next();if(e!==a.current)return;if(n.done||!n.value)break;h.current.push({timestamp:n.value.timestamp,frame:n.value})}}catch{}finally{_.current=!1,g.current=null}})()))},w=e=>{let t=h.current;for(let n=0;n<t.length;n++)if(Math.abs(t[n].timestamp-e)<nD){let e=t[n];return h.current=t.slice(n+1),e}return null},T=()=>{h.current=[]},E=async(e,t,n=0)=>{let i=b(e),o=(e=>{let t=l.current;return t===null||e<t-nD||e>t+.5})(i)?`seek`:`iterate`;try{let n=r.videoSink,c=l.current;if(c!==null&&Math.abs(c-i)<nD){u.current=e;return}let d=w(i);if(d){S(d.frame),u.current=e,C(t),v();return}if(g.current){await g.current;let n=w(i);if(n){S(n.frame),u.current=e,C(t),v();return}}if(T(),o===`seek`){s.current&&=(await s.current.return(),null);let r=n.canvases(i);s.current=r;let c=await r.next();if(t!==a.current){s.current&&=(await s.current.return(),null);return}if(c.done||!c.value){if(x(i)||y(`iterator_exhausted`,{mode:o,requestedTargetTime:e,clampedTargetTime:i},`warn`),t===a.current&&!x(i))try{s.current&&=(await s.current.return(),null),T();let r=n.canvases(i);s.current=r;let a=await r.next();!a.done&&a.value&&(S(a.value),C(t),u.current=e,v())}catch{}return}S(c.value),C(t)}else{let r=s.current;if(!r)return;let c=!1;for(;t===a.current;){let l=await r.next();if(t!==a.current)break;if(l.done||!l.value){if(x(i)||y(`iterator_exhausted`,{mode:o,requestedTargetTime:e,clampedTargetTime:i},`warn`),!c&&!x(i)){c=!0;try{s.current&&=(await s.current.return(),null),T();let e=n.canvases(i);s.current=e;let r=await e.next();if(t!==a.current||r.done||!r.value)break;S(r.value),C(t);break}catch{break}}break}let u=l.value;if(S(u),Math.abs(u.timestamp-i)<nD){C(t);break}if(u.timestamp>i){C(t);break}}}u.current=e,v()}catch(r){let a=r instanceof Error?{name:r.name,message:r.message,stack:r.stack}:{message:String(r)},c=r instanceof Error?`${r.name}: ${r.message}`:String(r),u=c.includes(`Unsupported configuration`)||c.includes(`isConfigSupported`)||c.includes(`OperationError`);if(y(`frame_process_failed`,{mode:o,requestedTargetTime:e,clampedTargetTime:i,unsupportedConfigAttempt:n,isUnsupportedConfig:u,error:a},`error`),u&&n<1)try{s.current&&=(await s.current.return(),null),T(),g.current=null,_.current=!1,l.current=null,await E(e,t,n+1)}catch{}}},D=Gn(()=>{let n=r.videoSink,s=r.duration;if(!n||!s)return;let c=e.startTime*s*1e3,l=s*(e.endTime-e.startTime)*1e3,u=((t.currentTime||e.page.startTime)-e.page.startTime)%l+c,d=u/1e3,h=b(d);f.current={pageStartTime:e.page.startTime,storeCurrentTime:t.currentTime,offsetMs:c,durationMs:l,restMs:u,targetTime:d,clampedTargetTime:h,startTime:e.startTime,endTime:e.endTime,videoDuration:s},((t,n)=>{p.current?m.current=t:(p.current=!0,o.current||=Kf(`mediabunny video frame ${e.id}`),(async()=>{let e=t;for(;e!==null&&n===a.current;)await E(e,n),e=m.current,m.current=null;o.current&&=(o.current(),null),p.current=!1})())})(h,i)});return()=>{D(),a.current++,o.current&&=(o.current(),null)}},[n,r.isReady,r.videoSink,r.duration,t,e]),n&&r.isReady?c.current:null};function iD(){return document.createElement(`canvas`)}var aD=new window.Image;aD.src=G_(`
271
+ `,$y=[`bold`,`color`,`font`,`italic`,`size`,`strike`,`underline`,`indent`,`list`,`direction`],eb=(e,t)=>{var n=e.clipboard.convert(`<div class='ql-editor' style='outline: none;'>`+t+`<p><br></p></div>`);e.setContents(n),e.history.clear()},tb=({html:e,onBlur:t,onChange:n,element:r,clickCoords:i})=>{let a=d.useRef(null);d.useEffect(()=>{if(!a.current)return;let r=(o=a.current,new Sy.default(o,{toolbar:!1,keyboard:!1,clipboard:{matchVisual:!1},formats:$y}));var o;Un(()=>{Zy.editor.instance=r}),window.__polotnoQuill=r,r.on(`text-change`,()=>{r.getSelection()&&Un(()=>{Zy.currentFormat=r.getFormat(r.getSelection())}),setTimeout(()=>{let e=a.current?.childNodes[0];if(!e)return;let t=e.innerHTML;n(Xy(t))},10)}),eb(r,e),i?ab(r,i):r.setSelection(0,0,`api`),r.on(`selection-change`,(e,t,n)=>{e&&Un(()=>{Zy.currentFormat=r.getFormat(r.getSelection())})}),a.current.childNodes[0].addEventListener(`blur`,e=>{let n=e.relatedTarget;n?.classList.contains(`ql-clipboard`)||(function(e){return!!e&&!!e.closest(`.sketch-picker`)})(n)||t()});let s=a.current.childNodes[0],c=e=>{var t,n;let i=r.getSelection();if(!i||i.length===0)return;let a=r.getText(i.index,i.length).replace(/\n$/,``),o=window.getSelection(),s=``;if(o&&o.rangeCount>0){let e=o.getRangeAt(0),t=document.createElement(`div`);t.appendChild(e.cloneContents()),s=t.innerHTML}if((t=e.clipboardData)==null||t.setData(`text/plain`,a),s){let t=`<!DOCTYPE html><html><head><meta charset="utf-8"></head><body><!--StartFragment--><div style="white-space: pre-wrap; word-wrap: break-word;">`+s+`</div><!--EndFragment--></body></html>`;(n=e.clipboardData)==null||n.setData(`text/html`,t)}e.preventDefault()},l=e=>{c(e);let t=r.getSelection();t&&t.length>0&&r.deleteText(t.index,t.length)};return s.addEventListener(`copy`,c),s.addEventListener(`cut`,l),()=>{s.removeEventListener(`copy`,c),s.removeEventListener(`cut`,l),Un(()=>{Zy.editor.instance=null,Zy.currentFormat={}}),delete window.__polotnoQuill}},[]),d.useEffect(()=>Jn(()=>r.text,()=>{let t=Zy.editor.instance;if(!t)return;let n=t.getSelection(),i=a.current?.childNodes?.[0];Xy(i?.innerHTML||``)===r.text||(eb(t,e),n&&(t.setSelection(n.index,n.length),Un(()=>{Zy.currentFormat=t.getFormat(t.getSelection())})))},{fireImmediately:!0}),[]),d.useEffect(()=>{window.addEventListener(`blur`,t);let e=e=>{var n;(n=a.current)!=null&&n.contains(e.target)||t()};return window.addEventListener(`touchstart`,e),()=>{window.removeEventListener(`blur`,t),window.removeEventListener(`touchstart`,e)}},[]);let o={color:r.fill};r.fill.indexOf(`gradient`)>=0&&(o.backgroundColor=r.fill,o.backgroundImage=r.fill,o.backgroundSize=`100% 100%`,o.backgroundRepeat=`repeat`,o.webkitBackgroundClip=`text`,o.MozBackgroundClip=`text`,o.WebkitTextFillColor=`transparent`,o.MozTextFillColor=`transparent`);let s=T_(r);return d.createElement(Qy,{ref:a,style:Object.assign(Object.assign({},o),{fontSize:r.fontSize,fontWeight:r.fontWeight,textTransform:r.textTransform,width:r.a.width,fontFamily:`"`+r.fontFamily+`"`,lineHeight:r.lineHeight,letterSpacing:r.letterSpacing*r.fontSize+`px`,textAlign:r.align,opacity:Math.max(r.a.opacity,.2),textShadow:r.shadowEnabled?`${r.shadowOffsetX}px ${r.shadowOffsetY}px ${r.shadowBlur}px ${Yy(r.shadowColor,r.shadowOpacity??1)}`:void 0,caretColor:s}),dir:Np(Qf(r.text))})};function nb(e){return!function(e){let t=e.getContext(`2d`).getImageData(0,0,e.width,e.height).data;for(let e=0;e<t.length;e+=4)if(t[e+3]!==0)return!0;return!1}(e)}var rb=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),ib=sa(({element:e,store:t})=>{let n=d.useRef(null),[r,i]=d.useState(),[a,o]=d.useState(!1),[s,c]=d.useState(!1),l=d.useRef(e.height),u=t.selectedShapes.indexOf(e)>=0&&e.selectable,f=N_(u),p=e.fontSize/3,{textVerticalResizeEnabled:m}=Sp,h=Sp.autoDeleteEmptyText,g=N_(e.fontFamily),[_]=j_(t,e.fontFamily,e.fontStyle,e.fontWeight,e.text||e.placeholder),v=e._editModeEnabled;Rf(n);let y=_?e.fontFamily:g===e.fontFamily?`Arial`:g,b=Pf(e).fill,x=zp(e,{fontFamily:y,color:b}),S=zp(e,{fontFamily:y,color:b,forEditor:!0}),C=d.useRef([]),[,w]=d.useReducer(e=>e+1,0);d.useEffect(()=>{let e=C.current;e.length>0&&(C.current=[],e.forEach(e=>e()))});let{width:T,height:E}=function(e,t,n){return d.useMemo(()=>ky(e),[e,t.width,n])}(x,e,_);d.useEffect(()=>{if(!_)return;let n=(n,r,i,a)=>{let o=Kf(`text ${e.id}`),s=()=>{t.history.ignore(n,r,i).then(()=>{C.current.push(o),w()})};a?queueMicrotask(s):s()};if(!e.height){n(()=>{e.height||e.set({height:E})},void 0,void 0,!0);return}let{textOverflow:r}=Sp;if(r!==`change-font-size`||a)r===`resize`&&(m&&e.height<E&&!a&&n(()=>{e.set({height:E})},!1,!0),m||e.height===E||a||n(()=>{e.set({height:E})},!1,!0));else{let t=(e=>{let t=e.fontSize;for(let n=1;n<50;n++){let n=zp(Object.assign(Object.assign({},e.toJSON()),{fontSize:t}),{fontFamily:e.fontFamily}),{height:r}=ky(n);if(!(e.height&&r>e.height||!Sp.textSplitAllowed&&!e.curveEnabled&&Oy({html:n})))break;t-=.5}return t})(e);t===e.fontSize?e.height!==E&&(m&&e.height<E?n(()=>{e.set({height:E})},!1,!0):m||n(()=>{e.set({height:E})},!1,!0)):n(()=>{e.set({fontSize:t})},!1,!0)}});let D=d.useMemo(()=>{let e={lastArgs:null,lastResult:null};return async function(t){return e.lastArgs&&e.lastResult&&(n=e.lastArgs,r=t,JSON.stringify(n)===JSON.stringify(r))||(e.lastResult=await Ny(t),e.lastArgs=Object.assign({},t)),e.lastResult;var n,r}},[]),O=d.useRef(0),k=d.useRef(null);d.useEffect(()=>{a||v||(async()=>{O.current++;let n=O.current,r=Kf(`text ${e.id} ${n}`);k.current&&k.current(),k.current=r,c(!0);let a=null,o=rb?5:1;for(let r=0;r<o;r++){let i=r>0?D:Ny;try{if(a=await i({skipCache:r>0,html:x,width:e.width||1,height:e.height||E||1,fontFamily:y,padding:p,pixelRatio:t._elementsPixelRatio,font:t.fonts.find(e=>e.fontFamily===y)||np.find(e=>e.fontFamily===y)}),n!==O.current)return;if(rb&&a&&nb(a)){await new Promise(e=>setTimeout(e,50*(r+1)));continue}break}catch(t){console.error(t),Zf(`Error rendering rich text with id ${e.id}`);break}}a?i(a):r?(r(),r=null):console.error(`Finish function is called twice!`),c(!1)})()},[x,a,E,v,y,e.height,t._elementsPixelRatio,_]);let[A,j]=tv(s,300),[M]=tv(a,300,!0),N=M||A;d.useEffect(()=>{var t;if(!N)return Gn(()=>{let t=n.current;Hp(t,e)});(t=n.current)==null||t.clearCache()},[r,N,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]),d.useEffect(()=>{r&&!s&&k.current&&(k.current(),k.current=null)},[r,s]),d.useLayoutEffect(()=>{if(!_||!e.curveEnabled)return;let t=new Du.TextPath({data:Pp(e.a.width,e.a.height,e.curvePower,e.a.fontSize),text:Qf(e.text),letterSpacing:e.letterSpacing*e.a.fontSize,fontSize:e.a.fontSize,fontFamily:e.fontFamily,fontWeight:e.fontWeight,fontStyle:e.fontStyle,align:`center`,textBaseline:`middle`,fill:e.fill}),n=t.getSelfRect().width;if(n){let t=n-e.a.width,r=e.a.rotation*Math.PI/180,i=-t/2*Math.cos(r),a=-t/2*Math.sin(r);queueMicrotask(()=>{e.set({width:n,x:e.a.x+i,y:e.a.y+a})})}t.destroy()},[_,e.curveEnabled,e.curvePower,e.text,e.fontSize,e.fontFamily,e.fontWeight,e.fontStyle,e.letterSpacing]),d.useEffect(()=>()=>{k.current&&k.current()},[]),d.useEffect(()=>{f&&!u&&h&&Qf(e.text)===``&&e.removable&&!e.placeholder&&t.deleteElements([e.id])},[h,e.placeholder,e.removable,e.text,u,f]);let P=0;e.verticalAlign===`middle`&&(P=(e.height-E)/2),e.verticalAlign===`bottom`&&(P=e.height-E);let F=M_({fontLoaded:_,fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:e.lineHeight}),ee=Up(),te=Pp(e.a.width,E,e.curvePower,e.fontSize),ne=d.useRef(null),re=d.useRef(null),ie=v&&e.strokeWidth>0&&!e.curveEnabled;return d.createElement(d.Fragment,null,d.createElement(Jd,{x:e.a.x,y:e.a.y,offsetX:e.backgroundPadding*(e.fontSize*F*.5),offsetY:e.backgroundPadding*(e.fontSize*F*.5),rotation:e.a.rotation,hideInExport:!e.showInExport,listening:!1,visible:e.backgroundEnabled,opacity:e.backgroundOpacity*e.a.opacity,fill:e.backgroundColor,width:e.a.width+e.backgroundPadding*(e.fontSize*F),height:e.a.height+e.backgroundPadding*(e.fontSize*F),cornerRadius:e.backgroundCornerRadius*(e.fontSize*F*.5)}),d.createElement($d,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,data:te,stroke:`red`,strokeWidth:1,visible:!1}),d.createElement(Jd,{ref:n,name:`element`,x:e.a.x,y:e.a.y,listening:e.selectable,rotation:e.a.rotation,width:e.a.width,height:e.a.height,visible:!N,draggable:ee?e.draggable&&u:e.draggable,preventDefault:!ee||u,opacity:v?0:e.a.opacity,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},id:e.id,onDblClick:t=>{e.contentEditable&&(re.current={x:t.evt.clientX,y:t.evt.clientY},e.toggleEditMode(!0))},onDblTap:t=>{if(e.contentEditable){let n=t.evt.changedTouches?.[0];re.current=n?{x:n.clientX,y:n.clientY}:null,e.toggleEditMode(!0)}},onTransformStart:t=>{o(!0),l.current=e.height},onTransform:t=>{let n=t.target,r=(n.getStage()?.findOne(`Transformer`)).getActiveAnchor(),i=r===`middle-left`||r===`middle-right`,a=r===`top-center`||r===`bottom-center`,o=n.scaleX();if(i){let t=n.scaleX(),r=n.width()*t,i=e.fontSize,a=r;r<i&&(a=i,ne.current&&n.position(ne.current)),n.width(a),n.scaleX(1),n.scaleY(1);let o=ky(zp(Object.assign(Object.assign({},e.toJSON()),{width:a}),{fontFamily:y,color:b})).height,s=Sp.textVerticalResizeEnabled?Math.max(o,l.current):o;n.height(s),e.set({width:n.width(),height:s,x:n.x(),y:n.y()})}else if(a){let r=Sp.textOverflow===`resize`,i=typeof e.lineHeight==`number`?e.lineHeight:1,a=r?E:i*e.fontSize,o=Math.max(a,t.target.height()*t.target.scaleY());n.scaleY(1),e.set({x:n.x(),y:n.y(),height:o,rotation:n.rotation()})}else n.scaleX(1),n.scaleY(1),e.set({fontSize:e.fontSize*o,letterSpacing:e.letterSpacing,width:n.width()*o,x:n.x(),y:n.y(),rotation:n.rotation(),height:n.height()*o});ne.current=t.target.position()},onTransformEnd:t=>{o(!1),c(!0);let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({fontSize:e.fontSize*n,width:t.target.width()*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),shadowBlur:e.shadowBlur*n,shadowOffsetX:e.shadowOffsetX*n,shadowOffsetY:e.shadowOffsetY*n,strokeWidth:e.strokeWidth*n})}}),d.createElement(Xd,{ref:n,image:r,x:e.a.x,y:e.a.y,offsetX:p,offsetY:p-P,listening:!1,rotation:e.a.rotation,width:e.a.width+2*p,height:(e.a.width+2*p)*((r?.height??0)/(r?.width||1)||1),visible:!N&&!v,opacity:e.a.opacity,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,hideInExport:!e.showInExport,editModeEnabled:e._editModeEnabled||a||N}),(N||ie)&&d.createElement(`Group`,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,offsetY:-P},d.createElement(cf,{divProps:{style:{pointerEvents:`none`}}},d.createElement(Qy,{dangerouslySetInnerHTML:{__html:x},style:{pointerEvents:`none`,opacity:e.a.opacity,textShadow:e.shadowEnabled?`${e.shadowOffsetX}px ${e.shadowOffsetY}px ${e.shadowBlur}px ${Yy(e.shadowColor,e.shadowOpacity??1)}`:void 0}}))),v&&d.createElement(`Group`,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,offsetY:-P},d.createElement(cf,null,d.createElement(tb,{html:S,element:e,onChange:t=>{let n=S_({oldText:Qf(e.text),newText:Qf(t),element:e});e.set({text:t,fontSize:n})},onBlur:t=>{e.toggleEditMode(!1),j(!0)},clickCoords:re.current}))))});function ab(e,t){if(!e||!t)return;let{x:n,y:r}=t;try{let t=null;if(document.caretRangeFromPoint)t=document.caretRangeFromPoint(n,r);else if(document.caretPositionFromPoint){let e=document.caretPositionFromPoint(n,r);e&&(t=document.createRange(),t.setStart(e.offsetNode,e.offset))}if(t){let n=Sy.default.find(t.startContainer,!0);if(n){let r=n.offset(e.scroll)+t.startOffset;e.setSelection(r,0,`api`);return}}}catch{}e.setSelection(0,0,`api`)}function ob(e){return e/180*Math.PI}function sb(e,t,n,r,i){let a=Math.sqrt(n*n+r*r);return i+=Math.atan2(r,n),{x:e+a*Math.cos(i),y:t+a*Math.sin(i)}}function cb(e){let{x:t,y:n,width:r,height:i}=e,a=ob(e.rotation),o=sb(t,n,0,0,a),s=sb(t,n,r,0,a),c=sb(t,n,r,i,a),l=sb(t,n,0,i,a),u=Math.min(o.x,s.x,c.x,l.x),d=Math.min(o.y,s.y,c.y,l.y),f=Math.max(o.x,s.x,c.x,l.x),p=Math.max(o.y,s.y,c.y,l.y);return{x:u,y:d,width:f-u,height:p-d,minX:u,minY:d,maxX:f,maxY:p}}function lb(e){let t=e.map(e=>cb(e)),n=Math.min(...t.map(e=>e.minX)),r=Math.min(...t.map(e=>e.minY)),i=Math.max(...t.map(e=>e.maxX)),a=Math.max(...t.map(e=>e.maxY));return{x:n,y:r,width:i-n,height:a-r,minX:n,minY:r,maxX:i,maxY:a}}function ub(e){let t=ob(e.rotation||0);return{x:e.x+e.width/2*Math.cos(t)+e.height/2*Math.sin(-t),y:e.y+e.height/2*Math.cos(t)+e.width/2*Math.sin(t)}}function db(e,t,n){let r=ob(t),i=n.x+(e.x-n.x)*Math.cos(r)-(e.y-n.y)*Math.sin(r),a=n.y+(e.x-n.x)*Math.sin(r)+(e.y-n.y)*Math.cos(r);return Object.assign(Object.assign({},e),{rotation:e.rotation+t,x:i,y:a})}function fb(e,t){return db(e,t,ub(e))}var pb={stroke:`rgb(0, 161, 255)`,strokeWidth:1,dash:[4,6]},mb=({stroke:e,strokeWidth:t,dash:n})=>{e!==void 0&&(pb.stroke=e),t!==void 0&&(pb.strokeWidth=t),n!==void 0&&(pb.dash=n)},hb=({targetKonvaNodes:e,guideKonvaNode:t,distance:n,snapDirection:r})=>n<5;function gb(e,t){var n=[],r=[];e.vertical.forEach(e=>{t.vertical.forEach(t=>{var r=Math.abs(e.offset-t.guide);hb({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:r,snapDirection:e.snap})&&n.push({lineGuide:e.offset,diff:r,snap:t.snap,offset:t.offset})})}),e.horizontal.forEach(e=>{t.horizontal.forEach(t=>{var n=Math.abs(e.offset-t.guide);hb({targetKonvaNodes:t.nodes,guideKonvaNode:e.node,distance:n,snapDirection:e.snap})&&r.push({lineGuide:e.offset,diff:n,snap:t.snap,offset:t.offset})})});var i=[];let a=n.sort((e,t)=>e.diff-t.diff),o=r.sort((e,t)=>e.diff-t.diff);var s=a[0],c=o[0];return s&&a.filter(e=>Math.abs(e.diff-s.diff)<.1).forEach(e=>{i.push(Object.assign({orientation:`V`},e))}),c&&o.filter(e=>Math.abs(e.diff-c.diff)<.1).forEach(e=>{i.push(Object.assign({orientation:`H`},e))}),i}var _b=()=>{if(Du.DD._dragElements.size===0)return;let e=[...Du.DD._dragElements.entries()],t=e.find(([e,t])=>t.node instanceof Du.Transformer);t&&(e.splice(e.indexOf(t),1),e.unshift(t),Du.DD._dragElements.clear(),e.forEach(([e,t])=>{Du.DD._dragElements.set(e,t)}))};function vb(e,t,n){let r=d.useRef(null);n&&mb(n);let i=e=>e.hasName(`element`)||e.hasName(`page-background`)||!r.current&&e.hasName(`elements-area`);function a(t){let n=e.current?.getStage(),r=[],a=[];return n.find(i).forEach(e=>{if(!(t.indexOf(e)>=0)){var n=e.getClientRect({skipShadow:!0,skipStroke:!0});r.push({offset:n.x,node:e,snap:`start`},{offset:n.x+n.width,node:e,snap:`end`},{offset:n.x+n.width/2,node:e,snap:`center`}),a.push({offset:n.y,node:e,snap:`start`},{offset:n.y+n.height,node:e,snap:`end`},{offset:n.y+n.height/2,node:e,snap:`center`})}}),{vertical:r,horizontal:a}}function o(t){let n=e.current?.getLayer(),r=n?.children.find(e=>e.name()===`line-guides`);t.forEach(e=>{if(e.orientation===`H`){var t=new Du.Line({x:-n.getStage().x(),y:-n.getStage().y(),points:[-6e3,e.lineGuide,6e3,e.lineGuide],stroke:pb.stroke,strokeWidth:pb.strokeWidth,name:`guid-line`,dash:pb.dash});r?.add(t),n.batchDraw()}else e.orientation===`V`&&(t=new Du.Line({x:-n.getStage().x(),y:-n.getStage().y(),points:[e.lineGuide,-6e3,e.lineGuide,6e3],stroke:pb.stroke,strokeWidth:pb.strokeWidth,name:`guid-line`,dash:pb.dash}),r?.add(t))})}let s=e=>{e.target.getLayer().children.find(e=>e.name()===`line-guides`)?.destroyChildren();var t=gb(a(e.target.nodes()),function(e){let t=e.__getNodeRect(),n=cb(Object.assign(Object.assign({},t),{rotation:Du.Util.radToDeg(t.rotation)})),r=e.getAbsolutePosition();return{vertical:[{guide:n.x,offset:r.x-n.x,snap:`start`,nodes:e.nodes()},{guide:n.x+n.width/2,offset:r.x-n.x-n.width/2,snap:`center`,nodes:e.nodes()},{guide:n.x+n.width,offset:r.x-n.x-n.width,snap:`end`,nodes:e.nodes()}],horizontal:[{guide:n.y,offset:r.y-n.y,snap:`start`,nodes:e.nodes()},{guide:n.y+n.height/2,offset:r.y-n.y-n.height/2,snap:`center`,nodes:e.nodes()},{guide:n.y+n.height,offset:r.y-n.y-n.height,snap:`end`,nodes:e.nodes()}]}}(e.target));if(!t.length)return;o(t);let n=e.target.getAbsolutePosition(),r=(e.target.nodes().map(e=>e.getAbsolutePosition()),Object.assign({},n));t.forEach(e=>{switch(e.snap){case`start`:case`center`:case`end`:switch(e.orientation){case`V`:r.x=e.lineGuide+e.offset;break;case`H`:r.y=e.lineGuide+e.offset}}});let i=r.x-n.x,s=r.y-n.y;e.evt.ctrlKey||e.evt.metaKey||e.target.nodes().forEach(e=>{let t=e.getAbsolutePosition();e.setAbsolutePosition({x:t.x+i,y:t.y+s})})},c=(t,n,r)=>{let i=e.current;if(i.getLayer().children.find(e=>e.name()===`line-guides`)?.destroyChildren(),i.getActiveAnchor()===`rotater`)return n;let s=xb[i.getActiveAnchor()],c=i.findOne(`.${s}`)?.getAbsolutePosition();if(!c)return n;let l={x:t.x-c.x,y:t.y-c.y},u=function(e,t){let n=bb(e,t)/bb(t,t);return{x:n*t.x,y:n*t.y}}({x:n.x-t.x,y:n.y-t.y},l);if(Math.sqrt(u.x**2+u.y**2)>5)return n;let d={x:t.x+u.x,y:t.y+u.y};var f=gb(a(i.nodes()),{vertical:[{guide:d.x,offset:0,snap:`start`,nodes:i.nodes()}],horizontal:[{guide:d.y,offset:0,snap:`start`,nodes:i.nodes()}]});if(!f.length||(o(f),r.ctrlKey||r.metaKey))return n;let p=[];if(f.forEach(e=>{let t=function(e,t,n){if(n.orientation===`V`){let r=n.lineGuide;if(Math.abs(t.x-e.x)<1e-4)return null;let i=(t.y-e.y)/(t.x-e.x);return{x:r,y:i*r+(e.y-i*e.x)}}{let r=n.lineGuide;if(Math.abs(t.y-e.y)<1e-4)return null;let i=(t.y-e.y)/(t.x-e.x);return{x:(r-e.y)/i+e.x,y:r}}}(d,c,{orientation:e.orientation,lineGuide:e.lineGuide});t&&p.push(t)}),p.length>0){let e=p[0],t=Math.sqrt((d.x-e.x)**2+(d.y-e.y)**2);if(p.forEach(n=>{let r=Math.sqrt((d.x-n.x)**2+(d.y-n.y)**2);r<t&&(t=r,e=n)}),t<10)return e}return d},l=e=>{if(!e.target)return;let t=e.target.getLayer();t.children.find(e=>e.name()===`line-guides`)?.destroyChildren(),t.batchDraw()};d.useEffect(()=>{e.current&&(e.current.anchorDragBoundFunc(c),e.current.on(`dragstart`,e=>{setTimeout(()=>{_b()})}),e.current.on(`dragmove`,s),e.current.on(`dragend`,l),e.current.on(`transformend`,l),e.current.on(`transform`,t=>{var n,r;t.evt.ctrlKey||t.evt.metaKey?(n=e.current)==null||n.rotationSnapTolerance(0):(r=e.current)==null||r.rotationSnapTolerance(5)}))},[])}function yb(e,t,n){let r=e=>e.hasName(`element`)||e.hasName(`line-anchor`)||e.hasName(`page-background`)||e.hasName(`elements-area`),i=n=>{n.target.getLayer().children.find(e=>e.name()===`line-guides`)?.destroyChildren();var i,a=gb(function(t){let n=e.current?.getStage();var i=[],a=[];return n.find(r).forEach(e=>{if(!(t.indexOf(e)>=0)){var n=e.getClientRect({skipShadow:!0,skipStroke:!0});e.hasName(`line-anchor`)&&(n={x:e.absolutePosition().x,y:e.absolutePosition().y,width:0,height:0}),i.push({offset:n.x,node:e,snap:`start`},{offset:n.x+n.width,node:e,snap:`end`},{offset:n.x+n.width/2,node:e,snap:`center`}),a.push({offset:n.y,node:e,snap:`start`},{offset:n.y+n.height,node:e,snap:`end`},{offset:n.y+n.height/2,node:e,snap:`center`})}}),{vertical:i,horizontal:a}}([n.target,...t.map(e=>e.current)]),{vertical:[{guide:(i=n.target).absolutePosition().x,offset:0,snap:`center`,nodes:[i]}],horizontal:[{guide:i.absolutePosition().y,offset:0,snap:`center`,nodes:[i]}]});if(!a.length)return;(function(t){let n=e.current?.getLayer(),r=n?.children.find(e=>e.name()===`line-guides`);t.forEach(e=>{if(e.orientation===`H`){var t=new Du.Line({x:-n.getStage().x(),y:-n.getStage().y(),points:[-6e3,e.lineGuide,6e3,e.lineGuide],stroke:pb.stroke,strokeWidth:pb.strokeWidth,name:`guid-line`,dash:pb.dash});r?.add(t),n.batchDraw()}else e.orientation===`V`&&(t=new Du.Line({x:-n.getStage().x(),y:-n.getStage().y(),points:[e.lineGuide,-6e3,e.lineGuide,6e3],stroke:pb.stroke,strokeWidth:pb.strokeWidth,name:`guid-line`,dash:pb.dash}),r?.add(t))})})(a);let o=n.target.getAbsolutePosition(),s=Object.assign({},o);a.forEach(e=>{switch(e.snap){case`start`:case`center`:case`end`:switch(e.orientation){case`V`:s.x=e.lineGuide+e.offset;break;case`H`:s.y=e.lineGuide+e.offset}}});let c=s.x-o.x,l=s.y-o.y;if(!n.evt.ctrlKey&&!n.evt.metaKey){let e=n.target.getAbsolutePosition();n.target.absolutePosition({x:e.x+c,y:e.y+l})}},a=e=>{if(!e.target)return;let t=e.target.getLayer();t.children.find(e=>e.name()===`line-guides`)?.destroyChildren(),t.batchDraw()};d.useEffect(()=>{e.current&&(e.current.on(`dragmove`,i),e.current.on(`dragend`,a))},n)}function bb(e,t){return e.x*t.x+e.y*t.y}var xb={"top-left":`bottom-right`,"top-center":`bottom-center`,"top-right":`bottom-left`,"middle-right":`middle-left`,"bottom-right":`top-left`,"bottom-center":`top-center`,"bottom-left":`top-right`,"middle-left":`middle-right`};function Sb(e){let{x:t,y:n,width:r,height:i,rotation:a}=e.a,o=a*Math.PI/180,s={x:t+i/2*Math.cos(o+Math.PI/2),y:n+i/2*Math.sin(o+Math.PI/2)};return{middleLeft:s,middleRight:{x:s.x+r*Math.cos(o),y:s.y+r*Math.sin(o)}}}function Cb(e,t,n){let r=Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2),i=Math.atan2(t.y-e.y,t.x-e.x),a=180*i/Math.PI;return{x:e.x+Math.cos(i-Math.PI/2)*n/2,y:e.y+Math.sin(i-Math.PI/2)*n/2,width:r,height:n,rotation:a}}var wb=(e,t)=>{let n=dA.anchorSize||10;return{offsetX:n/2/e,offsetY:n/2/e,width:n/e,height:n/e,cornerRadius:(dA.anchorCornerRadius||0)/e,fill:dA.anchorFill||`white`,stroke:dA.anchorStroke||`rgb(0, 161, 255)`,strokeWidth:dA.anchorStrokeWidth||2,strokeScaleEnabled:!1,draggable:!0,dragDistance:0,onMouseEnter:e=>{e.target.getStage().container().style.cursor=`crosshair`},onMouseLeave:e=>{e.target.getStage().container().style.cursor=``},onDragStart:e=>{t.history.startTransaction()},onDragEnd:e=>{t.history.endTransaction()}}},Tb=sa(({element:e,type:t})=>{let n=Pf(e,e.a.color,`fill`),r=Pf(e,e.a.color,`stroke`),i=Object.assign(Object.assign(Object.assign({strokeWidth:e.height,lineCap:`round`,lineJoin:`round`},r),n),{opacity:e.a.opacity,hideInExport:!e.showInExport});return d.createElement(d.Fragment,null,t===`arrow`&&d.createElement(`Line`,Object.assign({points:[3*e.height,2*-e.height,0,0,3*e.height,2*e.height]},i)),t===`triangle`&&d.createElement(`Line`,Object.assign({points:[3*e.height,2*-e.height,0,0,3*e.height,2*e.height],closed:!0},i)),t===`bar`&&d.createElement(`Line`,Object.assign({points:[0,2*-e.height,0,2*e.height],closed:!0},i)),t===`square`&&d.createElement(`Line`,Object.assign({points:[0,2*-e.height,4*e.height,2*-e.height,4*e.height,2*e.height,0,2*e.height],closed:!0},i)),t===`circle`&&d.createElement(`Circle`,Object.assign({x:2*e.height,y:0,radius:2*e.height},i)))}),Eb=sa(({element:e,store:t})=>{let n=d.useRef(null),r=d.useRef(null),i=d.useRef(null),a=e.selectable||t.role===`admin`,o=Up(),s=t.selectedElements.indexOf(e)>=0&&t.selectedElements.length===1,c=t.selectedShapes.indexOf(e)>=0&&e.selectable,{middleLeft:l,middleRight:u}=Sb(e);yb(r,[n],[s]),yb(i,[n],[s]);let f=Pf(e,e.a.color,`stroke`);return d.createElement(d.Fragment,null,d.createElement(Yd,Object.assign({ref:n,name:`element`,id:e.id,x:e.a.x,y:e.a.y,points:[0,0,e.a.width,0],offsetY:-e.a.height/2,strokeWidth:e.a.height,hitStrokeWidth:Math.max(e.a.height,20),dash:e.dash.map(t=>t*e.a.height)},f,{rotation:e.a.rotation,opacity:e.animated(`opacity`),shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,listening:a,draggable:o?e.draggable&&c:e.draggable,preventDefault:!o||c,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onTransform:t=>{let n=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),e.set({height:e.height*n,width:e.width*n,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})}})),d.createElement(Kd,{x:l.x,y:l.y,rotation:e.rotation,hideInExport:!e.showInExport,onClick:e=>n.current?.fire(`click`,e),onTap:e=>n.current?.fire(`tap`,e)},d.createElement(Tb,{element:e,type:e.startHead})),d.createElement(Kd,{x:u.x,y:u.y,rotation:e.rotation+180,onClick:e=>n.current?.fire(`click`,e),onTap:e=>n.current?.fire(`tap`,e)},d.createElement(Tb,{element:e,type:e.endHead})),s&&e.resizable&&d.createElement(lf,{selector:`.page-abs-container`,enabled:!0},d.createElement(`Group`,{visible:s},d.createElement(`Rect`,Object.assign({x:l.x,y:l.y,ref:r,name:`line-anchor`},wb(t.scale,t),{onDragMove:t=>{let n=Cb(t.target.position(),u,e.height);e.set({x:n.x,y:n.y,width:n.width,rotation:n.rotation})}})),d.createElement(`Rect`,Object.assign({x:u.x,y:u.y,ref:i,name:`line-anchor`},wb(t.scale,t),{onDragMove:t=>{let n=Cb(l,t.target.position(),e.height);e.set({x:n.x,y:n.y,width:n.width,rotation:n.rotation})}})))))});function J(e){if(!e)throw Error(`Assertion failed.`)}var Db=e=>{let t=(e%360+360)%360;if(t===0||t===90||t===180||t===270)return t;throw Error(`Invalid rotation ${e}.`)},Ob=e=>e&&e[e.length-1],kb=e=>e>=0&&e<2**32,Y=e=>{let t=0;for(;e.readBits(1)===0&&t<32;)t++;if(t>=32)throw Error(`Invalid exponential-Golomb code.`);return(1<<t)-1+e.readBits(t)},Ab=e=>{let t=Y(e);return t&1?t+1>>1:-(t>>1)},jb=e=>e.constructor===Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e),Mb=e=>e.constructor===DataView?e:ArrayBuffer.isView(e)?new DataView(e.buffer,e.byteOffset,e.byteLength):new DataView(e),Nb=new TextDecoder,Pb=new TextEncoder,Fb=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[t,e])),Ib={bt709:1,bt470bg:5,smpte170m:6,bt2020:9,smpte432:12},Lb=Fb(Ib),Rb={bt709:1,smpte170m:6,linear:8,"iec61966-2-1":13,pq:16,hlg:18},zb=Fb(Rb),Bb={rgb:0,bt709:1,bt470bg:5,smpte170m:6,"bt2020-ncl":9},Vb=Fb(Bb),Hb=e=>!!e&&!!e.primaries&&!!e.transfer&&!!e.matrix&&e.fullRange!==void 0,Ub=e=>e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer||ArrayBuffer.isView(e),Wb=class{constructor(){this.currentPromise=Promise.resolve(),this.pending=0}async acquire(){let e,t=new Promise(t=>{let n=!1;e=()=>{n||=(t(),this.pending--,!0)}}),n=this.currentPromise;return this.currentPromise=t,this.pending++,await n,e}},Gb=e=>[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``),Kb=e=>(e=e>>1&1431655765|(e&1431655765)<<1,e=e>>2&858993459|(e&858993459)<<2,e=e>>4&252645135|(e&252645135)<<4,e=e>>8&16711935|(e&16711935)<<8,e=e>>16&65535|(e&65535)<<16,e>>>0),qb=(e,t,n)=>{let r=0,i=e.length-1,a=-1;for(;r<=i;){let o=r+i>>1,s=n(e[o]);s===t?(a=o,i=o-1):s<t?r=o+1:i=o-1}return a},Jb=(e,t,n)=>{let r=0,i=e.length-1,a=-1;for(;r<=i;){let o=r+(i-r+1)/2|0;n(e[o])<=t?(a=o,r=o+1):i=o-1}return a},Yb=(e,t,n)=>{let r=Jb(e,n(t),n);e.splice(r+1,0,t)},Xb=()=>{let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}},Zb=(e,t)=>{for(let n=e.length-1;n>=0;n--)if(t(e[n]))return e[n]},Qb=(e,t)=>{for(let n=e.length-1;n>=0;n--)if(t(e[n]))return n;return-1},$b=async function*(e){Symbol.iterator in e?yield*e[Symbol.iterator]():yield*e[Symbol.asyncIterator]()},ex=e=>{if(!(Symbol.iterator in e)&&!(Symbol.asyncIterator in e))throw TypeError(`Argument must be an iterable or async iterable.`)},tx=e=>{throw Error(`Unexpected value: ${e}`)},nx=(e,t,n)=>{let r=e.getUint8(t),i=e.getUint8(t+1),a=e.getUint8(t+2);return n?r|i<<8|a<<16:r<<16|i<<8|a},rx=(e,t,n)=>nx(e,t,n)<<8>>8,ix=(e,t,n,r)=>{n>>>=0,n&=16777215,r?(e.setUint8(t,n&255),e.setUint8(t+1,n>>>8&255),e.setUint8(t+2,n>>>16&255)):(e.setUint8(t,n>>>16&255),e.setUint8(t+1,n>>>8&255),e.setUint8(t+2,n&255))},ax=(e,t,n,r)=>{n=sx(n,-8388608,8388607),n<0&&(n=n+16777216&16777215),ix(e,t,n,r)},ox=(e,t)=>({async next(){let n=await e.next();return n.done?{value:void 0,done:!0}:{value:t(n.value),done:!1}},return(){return e.return()},throw(t){return e.throw(t)},[Symbol.asyncIterator](){return this}}),sx=(e,t,n)=>Math.max(t,Math.min(n,e)),cx=e=>{let t=Math.round(e);return Math.abs(e/t-1)<10*2**-52?t:e},lx=(e,t)=>Math.round(e/t)*t,ux=(e,t)=>Math.floor(e/t)*t,dx=e=>{let t=0;for(;e;)t++,e>>=1;return t},fx=/^[a-z]{3}$/,px=e=>fx.test(e),mx=1e6*(1+2**-52),hx=(e,t)=>{let n={...e,...t};if(e.headers||t.headers){let r=e.headers?gx(e.headers):{},i=t.headers?gx(t.headers):{},a={...r};Object.entries(i).forEach(([e,t])=>{let n=Object.keys(a).find(t=>t.toLowerCase()===e.toLowerCase());n&&delete a[n],a[e]=t}),n.headers=a}return n},gx=e=>{if(e instanceof Headers){let t={};return e.forEach((e,n)=>{t[n]=e}),t}if(Array.isArray(e)){let t={};return e.forEach(([e,n])=>{t[e]=n}),t}return e},_x=async(e,t,n,r,i)=>{let a=0;for(;;)try{return await e(t,n)}catch(e){if(i())throw e;a++;let n=r(a,e,t);if(n===null)throw e;if(console.error(`Retrying failed fetch. Error:`,e),!Number.isFinite(n)||n<0)throw TypeError(`Retry delay must be a non-negative finite number.`);if(n>0&&await new Promise(e=>setTimeout(e,1e3*n)),i())throw e}},vx=(e,t)=>{let n=e<0?-1:1;e=Math.abs(e);let r=0,i=1,a=1,o=0,s=e;for(;;){let e=Math.floor(s),c=e*a+r,l=e*o+i;if(l>t)return{numerator:n*a,denominator:o};if(r=a,i=o,a=c,o=l,s=1/(s-e),!isFinite(s))break}return{numerator:n*a,denominator:o}},yx=class{constructor(){this.currentPromise=Promise.resolve()}call(e){return this.currentPromise=this.currentPromise.then(e)}},bx=null,xx=()=>bx===null?bx=!!(typeof navigator<`u`&&(navigator.vendor?.match(/apple/i)||/AppleWebKit/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)||/\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent))):bx,Sx=null,Cx=()=>Sx===null?Sx=typeof navigator<`u`&&navigator.userAgent?.includes(`Firefox`):Sx,wx=null,Tx=()=>wx===null?wx=!!(typeof navigator<`u`&&(navigator.vendor?.includes(`Google Inc`)||/Chrome/.test(navigator.userAgent))):wx,Ex=null,Dx=()=>{if(Ex!==null)return Ex;if(typeof navigator>`u`)return null;let e=/\bChrome\/(\d+)/.exec(navigator.userAgent);return e?Ex=Number(e[1]):null},Ox=(e,t)=>e===-1?t:e,kx=(e,t,n,r)=>e<=r&&n<=t,Ax=function*(e){for(let t in e){let n=e[t];n!==void 0&&(yield{key:t,value:n})}},jx=e=>{let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},Mx=()=>{Symbol.dispose??=Symbol(`Symbol.dispose`)},Nx=e=>typeof e==`number`&&!Number.isNaN(e),Px=e=>{J(e.den!==0);let t=Math.abs(e.num),n=Math.abs(e.den);for(;n!==0;){let e=t%n;t=n,n=e}let r=t||1;return{num:e.num/r,den:e.den/r}},Fx=(e,t)=>{if(typeof e!=`object`||!e)throw TypeError(`${t} must be an object.`);if(!Number.isInteger(e.left)||e.left<0)throw TypeError(`${t}.left must be a non-negative integer.`);if(!Number.isInteger(e.top)||e.top<0)throw TypeError(`${t}.top must be a non-negative integer.`);if(!Number.isInteger(e.width)||e.width<0)throw TypeError(`${t}.width must be a non-negative integer.`);if(!Number.isInteger(e.height)||e.height<0)throw TypeError(`${t}.height must be a non-negative integer.`)},Ix=class{constructor(e,t){if(this.data=e,this.mimeType=t,!(e instanceof Uint8Array))throw TypeError(`data must be a Uint8Array.`);if(typeof t!=`string`)throw TypeError(`mimeType must be a string.`)}},Lx=class{constructor(e,t,n,r){if(this.data=e,this.mimeType=t,this.name=n,this.description=r,!(e instanceof Uint8Array))throw TypeError(`data must be a Uint8Array.`);if(t!==void 0&&typeof t!=`string`)throw TypeError(`mimeType, when provided, must be a string.`);if(n!==void 0&&typeof n!=`string`)throw TypeError(`name, when provided, must be a string.`);if(r!==void 0&&typeof r!=`string`)throw TypeError(`description, when provided, must be a string.`)}},Rx=e=>{if(!e||typeof e!=`object`)throw TypeError(`tags must be an object.`);if(e.title!==void 0&&typeof e.title!=`string`)throw TypeError(`tags.title, when provided, must be a string.`);if(e.description!==void 0&&typeof e.description!=`string`)throw TypeError(`tags.description, when provided, must be a string.`);if(e.artist!==void 0&&typeof e.artist!=`string`)throw TypeError(`tags.artist, when provided, must be a string.`);if(e.album!==void 0&&typeof e.album!=`string`)throw TypeError(`tags.album, when provided, must be a string.`);if(e.albumArtist!==void 0&&typeof e.albumArtist!=`string`)throw TypeError(`tags.albumArtist, when provided, must be a string.`);if(e.trackNumber!==void 0&&(!Number.isInteger(e.trackNumber)||e.trackNumber<=0))throw TypeError(`tags.trackNumber, when provided, must be a positive integer.`);if(e.tracksTotal!==void 0&&(!Number.isInteger(e.tracksTotal)||e.tracksTotal<=0))throw TypeError(`tags.tracksTotal, when provided, must be a positive integer.`);if(e.discNumber!==void 0&&(!Number.isInteger(e.discNumber)||e.discNumber<=0))throw TypeError(`tags.discNumber, when provided, must be a positive integer.`);if(e.discsTotal!==void 0&&(!Number.isInteger(e.discsTotal)||e.discsTotal<=0))throw TypeError(`tags.discsTotal, when provided, must be a positive integer.`);if(e.genre!==void 0&&typeof e.genre!=`string`)throw TypeError(`tags.genre, when provided, must be a string.`);if(e.date!==void 0&&(!(e.date instanceof Date)||Number.isNaN(e.date.getTime())))throw TypeError(`tags.date, when provided, must be a valid Date.`);if(e.lyrics!==void 0&&typeof e.lyrics!=`string`)throw TypeError(`tags.lyrics, when provided, must be a string.`);if(e.images!==void 0){if(!Array.isArray(e.images))throw TypeError(`tags.images, when provided, must be an array.`);for(let t of e.images){if(!t||typeof t!=`object`)throw TypeError(`Each image in tags.images must be an object.`);if(!(t.data instanceof Uint8Array))throw TypeError(`Each image.data must be a Uint8Array.`);if(typeof t.mimeType!=`string`)throw TypeError(`Each image.mimeType must be a string.`);if(![`coverFront`,`coverBack`,`unknown`].includes(t.kind))throw TypeError(`Each image.kind must be 'coverFront', 'coverBack', or 'unknown'.`)}}if(e.comment!==void 0&&typeof e.comment!=`string`)throw TypeError(`tags.comment, when provided, must be a string.`);if(e.raw!==void 0){if(!e.raw||typeof e.raw!=`object`)throw TypeError(`tags.raw, when provided, must be an object.`);for(let t of Object.values(e.raw))if(t!==null&&typeof t!=`string`&&!(t instanceof Uint8Array)&&!(t instanceof Ix)&&!(t instanceof Lx))throw TypeError(`Each value in tags.raw must be a string, Uint8Array, RichImageData, AttachedFile, or null.`)}},zx={default:!0,forced:!1,original:!1,commentary:!1,hearingImpaired:!1,visuallyImpaired:!1},Bx=e=>{if(!e||typeof e!=`object`)throw TypeError(`disposition must be an object.`);if(e.default!==void 0&&typeof e.default!=`boolean`)throw TypeError(`disposition.default must be a boolean.`);if(e.forced!==void 0&&typeof e.forced!=`boolean`)throw TypeError(`disposition.forced must be a boolean.`);if(e.original!==void 0&&typeof e.original!=`boolean`)throw TypeError(`disposition.original must be a boolean.`);if(e.commentary!==void 0&&typeof e.commentary!=`boolean`)throw TypeError(`disposition.commentary must be a boolean.`);if(e.hearingImpaired!==void 0&&typeof e.hearingImpaired!=`boolean`)throw TypeError(`disposition.hearingImpaired must be a boolean.`);if(e.visuallyImpaired!==void 0&&typeof e.visuallyImpaired!=`boolean`)throw TypeError(`disposition.visuallyImpaired must be a boolean.`)},Vx=class e{constructor(e){this.bytes=e,this.pos=0}seekToByte(e){this.pos=8*e}readBit(){let e=Math.floor(this.pos/8),t=this.bytes[e]??0,n=7-(this.pos&7),r=(t&1<<n)>>n;return this.pos++,r}readBits(e){if(e===1)return this.readBit();let t=0;for(let n=0;n<e;n++)t<<=1,t|=this.readBit();return t}writeBits(e,t){let n=this.pos+e;for(let e=this.pos;e<n;e++){let r=Math.floor(e/8),i=this.bytes[r],a=7-(e&7);i&=~(1<<a),i|=(t&1<<n-e-1)>>n-e-1<<a,this.bytes[r]=i}this.pos=n}readAlignedByte(){if(this.pos%8!=0)throw Error(`Bitstream is not byte-aligned.`);let e=this.pos/8,t=this.bytes[e]??0;return this.pos+=8,t}skipBits(e){this.pos+=e}getBitsLeft(){return this.bytes.length*8-this.pos}clone(){let t=new e(this.bytes);return t.pos=this.pos,t}},Hx=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],Ux=[-1,1,2,3,4,5,6,8],Wx=e=>{if(!e||e.byteLength<2)throw TypeError(`AAC description must be at least 2 bytes long.`);let t=new Vx(e),n=t.readBits(5);n===31&&(n=32+t.readBits(6));let r=t.readBits(4),i=null;r===15?i=t.readBits(24):r<Hx.length&&(i=Hx[r]);let a=t.readBits(4),o=null;return a>=1&&a<=7&&(o=Ux[a]),{objectType:n,frequencyIndex:r,sampleRate:i,channelConfiguration:a,numberOfChannels:o}},Gx=e=>{let t=Hx.indexOf(e.sampleRate),n=null;t===-1&&(t=15,n=e.sampleRate);let r=Ux.indexOf(e.numberOfChannels);if(r===-1)throw TypeError(`Unsupported number of channels: ${e.numberOfChannels}`);let i=13;e.objectType>=32&&(i+=6),t===15&&(i+=24);let a=Math.ceil(i/8),o=new Uint8Array(a),s=new Vx(o);return e.objectType<32?s.writeBits(5,e.objectType):(s.writeBits(5,31),s.writeBits(6,e.objectType-32)),s.writeBits(4,t),t===15&&s.writeBits(24,n),s.writeBits(4,r),o},Kx=[`avc`,`hevc`,`vp9`,`av1`,`vp8`],qx=[`pcm-s16`,`pcm-s16be`,`pcm-s24`,`pcm-s24be`,`pcm-s32`,`pcm-s32be`,`pcm-f32`,`pcm-f32be`,`pcm-f64`,`pcm-f64be`,`pcm-u8`,`pcm-s8`,`ulaw`,`alaw`],Jx=[`aac`,`opus`,`mp3`,`vorbis`,`flac`,`ac3`,`eac3`],Yx=[...Jx,...qx],Xx=[`webvtt`],Zx=[{maxMacroblocks:99,maxBitrate:64e3,maxDpbMbs:396,level:10},{maxMacroblocks:396,maxBitrate:192e3,maxDpbMbs:900,level:11},{maxMacroblocks:396,maxBitrate:384e3,maxDpbMbs:2376,level:12},{maxMacroblocks:396,maxBitrate:768e3,maxDpbMbs:2376,level:13},{maxMacroblocks:396,maxBitrate:2e6,maxDpbMbs:2376,level:20},{maxMacroblocks:792,maxBitrate:4e6,maxDpbMbs:4752,level:21},{maxMacroblocks:1620,maxBitrate:4e6,maxDpbMbs:8100,level:22},{maxMacroblocks:1620,maxBitrate:1e7,maxDpbMbs:8100,level:30},{maxMacroblocks:3600,maxBitrate:14e6,maxDpbMbs:18e3,level:31},{maxMacroblocks:5120,maxBitrate:2e7,maxDpbMbs:20480,level:32},{maxMacroblocks:8192,maxBitrate:2e7,maxDpbMbs:32768,level:40},{maxMacroblocks:8192,maxBitrate:5e7,maxDpbMbs:32768,level:41},{maxMacroblocks:8704,maxBitrate:5e7,maxDpbMbs:34816,level:42},{maxMacroblocks:22080,maxBitrate:135e6,maxDpbMbs:110400,level:50},{maxMacroblocks:36864,maxBitrate:24e7,maxDpbMbs:184320,level:51},{maxMacroblocks:36864,maxBitrate:24e7,maxDpbMbs:184320,level:52},{maxMacroblocks:139264,maxBitrate:24e7,maxDpbMbs:696320,level:60},{maxMacroblocks:139264,maxBitrate:48e7,maxDpbMbs:696320,level:61},{maxMacroblocks:139264,maxBitrate:8e8,maxDpbMbs:696320,level:62}],Qx=[{maxPictureSize:36864,maxBitrate:128e3,tier:`L`,level:30},{maxPictureSize:122880,maxBitrate:15e5,tier:`L`,level:60},{maxPictureSize:245760,maxBitrate:3e6,tier:`L`,level:63},{maxPictureSize:552960,maxBitrate:6e6,tier:`L`,level:90},{maxPictureSize:983040,maxBitrate:1e7,tier:`L`,level:93},{maxPictureSize:2228224,maxBitrate:12e6,tier:`L`,level:120},{maxPictureSize:2228224,maxBitrate:3e7,tier:`H`,level:120},{maxPictureSize:2228224,maxBitrate:2e7,tier:`L`,level:123},{maxPictureSize:2228224,maxBitrate:5e7,tier:`H`,level:123},{maxPictureSize:8912896,maxBitrate:25e6,tier:`L`,level:150},{maxPictureSize:8912896,maxBitrate:1e8,tier:`H`,level:150},{maxPictureSize:8912896,maxBitrate:4e7,tier:`L`,level:153},{maxPictureSize:8912896,maxBitrate:16e7,tier:`H`,level:153},{maxPictureSize:8912896,maxBitrate:6e7,tier:`L`,level:156},{maxPictureSize:8912896,maxBitrate:24e7,tier:`H`,level:156},{maxPictureSize:35651584,maxBitrate:6e7,tier:`L`,level:180},{maxPictureSize:35651584,maxBitrate:24e7,tier:`H`,level:180},{maxPictureSize:35651584,maxBitrate:12e7,tier:`L`,level:183},{maxPictureSize:35651584,maxBitrate:48e7,tier:`H`,level:183},{maxPictureSize:35651584,maxBitrate:24e7,tier:`L`,level:186},{maxPictureSize:35651584,maxBitrate:8e8,tier:`H`,level:186}],$x=[{maxPictureSize:36864,maxBitrate:2e5,level:10},{maxPictureSize:73728,maxBitrate:8e5,level:11},{maxPictureSize:122880,maxBitrate:18e5,level:20},{maxPictureSize:245760,maxBitrate:36e5,level:21},{maxPictureSize:552960,maxBitrate:72e5,level:30},{maxPictureSize:983040,maxBitrate:12e6,level:31},{maxPictureSize:2228224,maxBitrate:18e6,level:40},{maxPictureSize:2228224,maxBitrate:3e7,level:41},{maxPictureSize:8912896,maxBitrate:6e7,level:50},{maxPictureSize:8912896,maxBitrate:12e7,level:51},{maxPictureSize:8912896,maxBitrate:18e7,level:52},{maxPictureSize:35651584,maxBitrate:18e7,level:60},{maxPictureSize:35651584,maxBitrate:24e7,level:61},{maxPictureSize:35651584,maxBitrate:48e7,level:62}],eS=[{maxPictureSize:147456,maxBitrate:15e5,tier:`M`,level:0},{maxPictureSize:278784,maxBitrate:3e6,tier:`M`,level:1},{maxPictureSize:665856,maxBitrate:6e6,tier:`M`,level:4},{maxPictureSize:1065024,maxBitrate:1e7,tier:`M`,level:5},{maxPictureSize:2359296,maxBitrate:12e6,tier:`M`,level:8},{maxPictureSize:2359296,maxBitrate:3e7,tier:`H`,level:8},{maxPictureSize:2359296,maxBitrate:2e7,tier:`M`,level:9},{maxPictureSize:2359296,maxBitrate:5e7,tier:`H`,level:9},{maxPictureSize:8912896,maxBitrate:3e7,tier:`M`,level:12},{maxPictureSize:8912896,maxBitrate:1e8,tier:`H`,level:12},{maxPictureSize:8912896,maxBitrate:4e7,tier:`M`,level:13},{maxPictureSize:8912896,maxBitrate:16e7,tier:`H`,level:13},{maxPictureSize:8912896,maxBitrate:6e7,tier:`M`,level:14},{maxPictureSize:8912896,maxBitrate:24e7,tier:`H`,level:14},{maxPictureSize:35651584,maxBitrate:6e7,tier:`M`,level:15},{maxPictureSize:35651584,maxBitrate:24e7,tier:`H`,level:15},{maxPictureSize:35651584,maxBitrate:6e7,tier:`M`,level:16},{maxPictureSize:35651584,maxBitrate:24e7,tier:`H`,level:16},{maxPictureSize:35651584,maxBitrate:1e8,tier:`M`,level:17},{maxPictureSize:35651584,maxBitrate:48e7,tier:`H`,level:17},{maxPictureSize:35651584,maxBitrate:16e7,tier:`M`,level:18},{maxPictureSize:35651584,maxBitrate:8e8,tier:`H`,level:18},{maxPictureSize:35651584,maxBitrate:16e7,tier:`M`,level:19},{maxPictureSize:35651584,maxBitrate:8e8,tier:`H`,level:19}],tS=`.01.01.01.01.00`,nS=`.0.110.01.01.01.0`,rS=(e,t,n,r)=>{if(e===`avc`){let e=Math.ceil(t/16)*Math.ceil(n/16),i=Zx.find(t=>e<=t.maxMacroblocks&&r<=t.maxBitrate)??Ob(Zx),a=i?i.level:0;return`avc1.${`64`.padStart(2,`0`)}00${a.toString(16).padStart(2,`0`)}`}else if(e===`hevc`){let e=t*n,i=Qx.find(t=>e<=t.maxPictureSize&&r<=t.maxBitrate)??Ob(Qx);return`hev1.1.6.${i.tier}${i.level}.B0`}else if(e===`vp8`)return`vp8`;else if(e===`vp9`){let e=t*n;return`vp09.00.${($x.find(t=>e<=t.maxPictureSize&&r<=t.maxBitrate)??Ob($x)).level.toString().padStart(2,`0`)}.08`}else if(e===`av1`){let e=t*n,i=eS.find(t=>e<=t.maxPictureSize&&r<=t.maxBitrate)??Ob(eS);return`av01.0.${i.level.toString().padStart(2,`0`)}${i.tier}.08`}throw TypeError(`Unhandled codec '${e}'.`)},iS=e=>{let t=e.split(`.`),n=Number(t[1]),r=t[2],i=Number(r.slice(0,-1)),a=(n<<5)+i,o=r.slice(-1)===`H`?1:0,s=Number(t[3])===8?0:1,c=t[4]?Number(t[4]):0,l=t[5]?Number(t[5][0]):1,u=t[5]?Number(t[5][1]):1,d=t[5]?Number(t[5][2]):0;return[129,a,(o<<7)+(s<<6)+0+(c<<4)+(l<<3)+(u<<2)+d,0]},aS=e=>{let{codec:t,codecDescription:n,colorSpace:r,avcCodecInfo:i,hevcCodecInfo:a,vp9CodecInfo:o,av1CodecInfo:s}=e;if(t===`avc`){if(J(e.avcType!==null),i){let t=new Uint8Array([i.avcProfileIndication,i.profileCompatibility,i.avcLevelIndication]);return`avc${e.avcType}.${Gb(t)}`}if(!n||n.byteLength<4)throw TypeError(`AVC decoder description is not provided or is not at least 4 bytes long.`);return`avc${e.avcType}.${Gb(n.subarray(1,4))}`}else if(t===`hevc`){let e,t,r,i,o,s;if(a)e=a.generalProfileSpace,t=a.generalProfileIdc,r=Kb(a.generalProfileCompatibilityFlags),i=a.generalTierFlag,o=a.generalLevelIdc,s=[...a.generalConstraintIndicatorFlags];else{if(!n||n.byteLength<23)throw TypeError(`HEVC decoder description is not provided or is not at least 23 bytes long.`);let a=Mb(n),c=a.getUint8(1);e=c>>6&3,t=c&31,r=Kb(a.getUint32(2)),i=c>>5&1,o=a.getUint8(12),s=[];for(let e=0;e<6;e++)s.push(a.getUint8(6+e))}let c=`hev1.`;for(c+=[``,`A`,`B`,`C`][e]+t,c+=`.`,c+=r.toString(16).toUpperCase(),c+=`.`,c+=i===0?`L`:`H`,c+=o;s.length>0&&s[s.length-1]===0;)s.pop();return s.length>0&&(c+=`.`,c+=s.map(e=>e.toString(16).toUpperCase()).join(`.`)),c}else if(t===`vp8`)return`vp8`;else if(t===`vp9`){if(!o){let t=e.width*e.height,n=Ob($x).level;for(let e of $x)if(t<=e.maxPictureSize){n=e.level;break}return`vp09.00.${n.toString().padStart(2,`0`)}.08`}let t=o.profile.toString().padStart(2,`0`),n=o.level.toString().padStart(2,`0`),r=o.bitDepth.toString().padStart(2,`0`),i=o.chromaSubsampling.toString().padStart(2,`0`),a=o.colourPrimaries.toString().padStart(2,`0`),s=o.transferCharacteristics.toString().padStart(2,`0`),c=o.matrixCoefficients.toString().padStart(2,`0`),l=o.videoFullRangeFlag.toString().padStart(2,`0`),u=`vp09.${t}.${n}.${r}.${i}`;return u+=`.${a}.${s}.${c}.${l}`,u.endsWith(tS)&&(u=u.slice(0,-15)),u}else if(t===`av1`){if(!s){let t=e.width*e.height,n=Ob($x).level;for(let e of $x)if(t<=e.maxPictureSize){n=e.level;break}return`av01.0.${n.toString().padStart(2,`0`)}M.08`}let t=s.profile,n=s.level.toString().padStart(2,`0`),i=s.tier?`H`:`M`,a=s.bitDepth.toString().padStart(2,`0`),o=s.monochrome?`1`:`0`,c=100*s.chromaSubsamplingX+10*s.chromaSubsamplingY+1*(s.chromaSubsamplingX&&s.chromaSubsamplingY?s.chromaSamplePosition:0),l=r?.primaries?Ib[r.primaries]:1,u=r?.transfer?Rb[r.transfer]:1,d=r?.matrix?Bb[r.matrix]:1,f=r?.fullRange?1:0,p=`av01.${t}.${n}${i}.${a}`;return p+=`.${o}.${c.toString().padStart(3,`0`)}`,p+=`.${l.toString().padStart(2,`0`)}`,p+=`.${u.toString().padStart(2,`0`)}`,p+=`.${d.toString().padStart(2,`0`)}`,p+=`.${f}`,p.endsWith(nS)&&(p=p.slice(0,-17)),p}throw TypeError(`Unhandled codec '${t}'.`)},oS=(e,t,n)=>{if(e===`aac`)return t>=2&&n<=24e3?`mp4a.40.29`:n<=24e3?`mp4a.40.5`:`mp4a.40.2`;if(e===`mp3`)return`mp3`;if(e===`opus`)return`opus`;if(e===`vorbis`)return`vorbis`;if(e===`flac`)return`flac`;if(e===`ac3`)return`ac-3`;if(e===`eac3`)return`ec-3`;if(qx.includes(e))return e;throw TypeError(`Unhandled codec '${e}'.`)},sS=e=>{let{codec:t,codecDescription:n,aacCodecInfo:r}=e;if(t===`aac`){if(!r)throw TypeError(`AAC codec info must be provided.`);if(r.isMpeg2)return`mp4a.67`;{let e;return e=r.objectType===null?Wx(n).objectType:r.objectType,`mp4a.40.${e}`}}else if(t===`mp3`)return`mp3`;else if(t===`opus`)return`opus`;else if(t===`vorbis`)return`vorbis`;else if(t===`flac`)return`flac`;else if(t===`ac3`)return`ac-3`;else if(t===`eac3`)return`ec-3`;else if(t&&qx.includes(t))return t;throw TypeError(`Unhandled codec '${t}'.`)},cS=48e3,lS=/^pcm-([usf])(\d+)+(be)?$/,uS=e=>{if(J(qx.includes(e)),e===`ulaw`)return{dataType:`ulaw`,sampleSize:1,littleEndian:!0,silentValue:255};if(e===`alaw`)return{dataType:`alaw`,sampleSize:1,littleEndian:!0,silentValue:213};let t=lS.exec(e);J(t);let n;n=t[1]===`u`?`unsigned`:t[1]===`s`?`signed`:`float`;let r=Number(t[2])/8,i=t[3]!==`be`;return{dataType:n,sampleSize:r,littleEndian:i,silentValue:e===`pcm-u8`?2**7:0}},dS=e=>e.startsWith(`avc1`)||e.startsWith(`avc3`)?`avc`:e.startsWith(`hev1`)||e.startsWith(`hvc1`)?`hevc`:e===`vp8`?`vp8`:e.startsWith(`vp09`)?`vp9`:e.startsWith(`av01`)?`av1`:e.startsWith(`mp4a.40`)||e===`mp4a.67`?`aac`:e===`mp3`||e===`mp4a.69`||e===`mp4a.6B`||e===`mp4a.6b`?`mp3`:e===`opus`?`opus`:e===`vorbis`?`vorbis`:e===`flac`?`flac`:e===`ac-3`||e===`ac3`?`ac3`:e===`ec-3`||e===`eac3`?`eac3`:e===`ulaw`?`ulaw`:e===`alaw`?`alaw`:lS.test(e)?e:e===`webvtt`?`webvtt`:null,fS=e=>e===`avc`?{avc:{format:`avc`}}:e===`hevc`?{hevc:{format:`hevc`}}:{},pS=e=>e===`aac`?{aac:{format:`aac`}}:e===`opus`?{opus:{format:`opus`}}:{},mS=[`avc1`,`avc3`,`hev1`,`hvc1`,`vp8`,`vp09`,`av01`],hS=/^(avc1|avc3)\.[0-9a-fA-F]{6}$/,gS=/^(hev1|hvc1)\.(?:[ABC]?\d+)\.[0-9a-fA-F]{1,8}\.[LH]\d+(?:\.[0-9a-fA-F]{1,2}){0,6}$/,_S=/^vp09(?:\.\d{2}){3}(?:(?:\.\d{2}){5})?$/,vS=/^av01\.\d\.\d{2}[MH]\.\d{2}(?:\.\d\.\d{3}\.\d{2}\.\d{2}\.\d{2}\.\d)?$/,yS=e=>{if(!e)throw TypeError(`Video chunk metadata must be provided.`);if(typeof e!=`object`)throw TypeError(`Video chunk metadata must be an object.`);if(!e.decoderConfig)throw TypeError(`Video chunk metadata must include a decoder configuration.`);if(typeof e.decoderConfig!=`object`)throw TypeError(`Video chunk metadata decoder configuration must be an object.`);if(typeof e.decoderConfig.codec!=`string`)throw TypeError(`Video chunk metadata decoder configuration must specify a codec string.`);if(!mS.some(t=>e.decoderConfig.codec.startsWith(t)))throw TypeError(`Video chunk metadata decoder configuration codec string must be a valid video codec string as specified in the Mediabunny Codec Registry.`);if(!Number.isInteger(e.decoderConfig.codedWidth)||e.decoderConfig.codedWidth<=0)throw TypeError(`Video chunk metadata decoder configuration must specify a valid codedWidth (positive integer).`);if(!Number.isInteger(e.decoderConfig.codedHeight)||e.decoderConfig.codedHeight<=0)throw TypeError(`Video chunk metadata decoder configuration must specify a valid codedHeight (positive integer).`);if(e.decoderConfig.description!==void 0&&!Ub(e.decoderConfig.description))throw TypeError(`Video chunk metadata decoder configuration description, when defined, must be an ArrayBuffer or an ArrayBuffer view.`);if(e.decoderConfig.colorSpace!==void 0){let{colorSpace:t}=e.decoderConfig;if(typeof t!=`object`)throw TypeError(`Video chunk metadata decoder configuration colorSpace, when provided, must be an object.`);let n=Object.keys(Ib);if(t.primaries!=null&&!n.includes(t.primaries))throw TypeError(`Video chunk metadata decoder configuration colorSpace primaries, when defined, must be one of ${n.join(`, `)}.`);let r=Object.keys(Rb);if(t.transfer!=null&&!r.includes(t.transfer))throw TypeError(`Video chunk metadata decoder configuration colorSpace transfer, when defined, must be one of ${r.join(`, `)}.`);let i=Object.keys(Bb);if(t.matrix!=null&&!i.includes(t.matrix))throw TypeError(`Video chunk metadata decoder configuration colorSpace matrix, when defined, must be one of ${i.join(`, `)}.`);if(t.fullRange!=null&&typeof t.fullRange!=`boolean`)throw TypeError(`Video chunk metadata decoder configuration colorSpace fullRange, when defined, must be a boolean.`)}if(e.decoderConfig.codec.startsWith(`avc1`)||e.decoderConfig.codec.startsWith(`avc3`)){if(!hS.test(e.decoderConfig.codec))throw TypeError(`Video chunk metadata decoder configuration codec string for AVC must be a valid AVC codec string as specified in Section 3.4 of RFC 6381.`)}else if(e.decoderConfig.codec.startsWith(`hev1`)||e.decoderConfig.codec.startsWith(`hvc1`)){if(!gS.test(e.decoderConfig.codec))throw TypeError(`Video chunk metadata decoder configuration codec string for HEVC must be a valid HEVC codec string as specified in Section E.3 of ISO 14496-15.`)}else if(e.decoderConfig.codec.startsWith(`vp8`)){if(e.decoderConfig.codec!==`vp8`)throw TypeError(`Video chunk metadata decoder configuration codec string for VP8 must be "vp8".`)}else if(e.decoderConfig.codec.startsWith(`vp09`)){if(!_S.test(e.decoderConfig.codec))throw TypeError(`Video chunk metadata decoder configuration codec string for VP9 must be a valid VP9 codec string as specified in Section "Codecs Parameter String" of https://www.webmproject.org/vp9/mp4/.`)}else if(e.decoderConfig.codec.startsWith(`av01`)&&!vS.test(e.decoderConfig.codec))throw TypeError(`Video chunk metadata decoder configuration codec string for AV1 must be a valid AV1 codec string as specified in Section "Codecs Parameter String" of https://aomediacodec.github.io/av1-isobmff/.`)},bS=[`mp4a`,`mp3`,`opus`,`vorbis`,`flac`,`ulaw`,`alaw`,`pcm`,`ac-3`,`ec-3`],xS=e=>{if(!e)throw TypeError(`Audio chunk metadata must be provided.`);if(typeof e!=`object`)throw TypeError(`Audio chunk metadata must be an object.`);if(!e.decoderConfig)throw TypeError(`Audio chunk metadata must include a decoder configuration.`);if(typeof e.decoderConfig!=`object`)throw TypeError(`Audio chunk metadata decoder configuration must be an object.`);if(typeof e.decoderConfig.codec!=`string`)throw TypeError(`Audio chunk metadata decoder configuration must specify a codec string.`);if(!bS.some(t=>e.decoderConfig.codec.startsWith(t)))throw TypeError(`Audio chunk metadata decoder configuration codec string must be a valid audio codec string as specified in the Mediabunny Codec Registry.`);if(!Number.isInteger(e.decoderConfig.sampleRate)||e.decoderConfig.sampleRate<=0)throw TypeError(`Audio chunk metadata decoder configuration must specify a valid sampleRate (positive integer).`);if(!Number.isInteger(e.decoderConfig.numberOfChannels)||e.decoderConfig.numberOfChannels<=0)throw TypeError(`Audio chunk metadata decoder configuration must specify a valid numberOfChannels (positive integer).`);if(e.decoderConfig.description!==void 0&&!Ub(e.decoderConfig.description))throw TypeError(`Audio chunk metadata decoder configuration description, when defined, must be an ArrayBuffer or an ArrayBuffer view.`);if(e.decoderConfig.codec.startsWith(`mp4a`)&&e.decoderConfig.codec!==`mp4a.69`&&e.decoderConfig.codec!==`mp4a.6B`&&e.decoderConfig.codec!==`mp4a.6b`){if(![`mp4a.40.2`,`mp4a.40.02`,`mp4a.40.5`,`mp4a.40.05`,`mp4a.40.29`,`mp4a.67`].includes(e.decoderConfig.codec))throw TypeError(`Audio chunk metadata decoder configuration codec string for AAC must be a valid AAC codec string as specified in https://www.w3.org/TR/webcodecs-aac-codec-registration/.`)}else if(e.decoderConfig.codec.startsWith(`mp3`)||e.decoderConfig.codec.startsWith(`mp4a`)){if(e.decoderConfig.codec!==`mp3`&&e.decoderConfig.codec!==`mp4a.69`&&e.decoderConfig.codec!==`mp4a.6B`&&e.decoderConfig.codec!==`mp4a.6b`)throw TypeError(`Audio chunk metadata decoder configuration codec string for MP3 must be "mp3", "mp4a.69" or "mp4a.6B".`)}else if(e.decoderConfig.codec.startsWith(`opus`)){if(e.decoderConfig.codec!==`opus`)throw TypeError(`Audio chunk metadata decoder configuration codec string for Opus must be "opus".`);if(e.decoderConfig.description&&e.decoderConfig.description.byteLength<18)throw TypeError(`Audio chunk metadata decoder configuration description, when specified, is expected to be an Identification Header as specified in Section 5.1 of RFC 7845.`)}else if(e.decoderConfig.codec.startsWith(`vorbis`)){if(e.decoderConfig.codec!==`vorbis`)throw TypeError(`Audio chunk metadata decoder configuration codec string for Vorbis must be "vorbis".`);if(!e.decoderConfig.description)throw TypeError(`Audio chunk metadata decoder configuration for Vorbis must include a description, which is expected to adhere to the format described in https://www.w3.org/TR/webcodecs-vorbis-codec-registration/.`)}else if(e.decoderConfig.codec.startsWith(`flac`)){if(e.decoderConfig.codec!==`flac`)throw TypeError(`Audio chunk metadata decoder configuration codec string for FLAC must be "flac".`);if(!e.decoderConfig.description||e.decoderConfig.description.byteLength<42)throw TypeError(`Audio chunk metadata decoder configuration for FLAC must include a description, which is expected to adhere to the format described in https://www.w3.org/TR/webcodecs-flac-codec-registration/.`)}else if(e.decoderConfig.codec.startsWith(`ac-3`)||e.decoderConfig.codec.startsWith(`ac3`)){if(e.decoderConfig.codec!==`ac-3`)throw TypeError(`Audio chunk metadata decoder configuration codec string for AC-3 must be "ac-3".`)}else if(e.decoderConfig.codec.startsWith(`ec-3`)||e.decoderConfig.codec.startsWith(`eac3`)){if(e.decoderConfig.codec!==`ec-3`)throw TypeError(`Audio chunk metadata decoder configuration codec string for EC-3 must be "ec-3".`)}else if((e.decoderConfig.codec.startsWith(`pcm`)||e.decoderConfig.codec.startsWith(`ulaw`)||e.decoderConfig.codec.startsWith(`alaw`))&&!qx.includes(e.decoderConfig.codec))throw TypeError(`Audio chunk metadata decoder configuration codec string for PCM must be one of the supported PCM codecs (${qx.join(`, `)}).`)},SS=e=>{if(!e)throw TypeError(`Subtitle metadata must be provided.`);if(typeof e!=`object`)throw TypeError(`Subtitle metadata must be an object.`);if(!e.config)throw TypeError(`Subtitle metadata must include a config object.`);if(typeof e.config!=`object`)throw TypeError(`Subtitle metadata config must be an object.`);if(typeof e.config.description!=`string`)throw TypeError(`Subtitle metadata config description must be a string.`)},CS=[44100,48e3,32e3],wS=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,32,40,48,56,64,80,96,112,128,160,192,224,256,320,-1,-1,32,48,56,64,80,96,112,128,160,192,224,256,320,384,-1,-1,32,64,96,128,160,192,224,256,288,320,352,384,416,448,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,16,24,32,40,48,56,64,80,96,112,128,144,160,-1,-1,8,16,24,32,40,48,56,64,80,96,112,128,144,160,-1,-1,32,48,56,64,80,96,112,128,144,160,176,192,224,256,-1],TS=(e,t,n,r,i)=>t===0?0:t===1?Math.floor(144*n/(r<<e))+i:t===2?Math.floor(144*n/r)+i:(Math.floor(12*n/r)+i)*4,ES=(e,t)=>e===3?t===3?21:36:t===3?13:21,DS=(e,t)=>{let n=e>>>24,r=e>>>16&255,i=e>>>8&255,a=e&255;if(n!==255&&r!==255&&i!==255&&a!==255)return{header:null,bytesAdvanced:4};if(n!==255||(r&224)!=224)return{header:null,bytesAdvanced:1};let o=0,s=0;r&16?o=r&8?0:1:(o=1,s=1);let c=r>>3&3,l=r>>1&3,u=i>>4&15,d=(i>>2&3)%3,f=i>>1&1,p=a>>6&3,m=a>>4&3,h=a>>3&1,g=a>>2&1,_=a&3,v=wS[o*16*4+l*16+u];if(v===-1)return{header:null,bytesAdvanced:1};let y=v*1e3,b=CS[d]>>o+s,x=TS(o,l,y,b,f);if(t!==null&&t<x)return{header:null,bytesAdvanced:1};let S;return S=c===3?l===3?384:1152:l===3?384:l===2?1152:576,{header:{totalSize:x,mpegVersionId:c,layer:l,bitrate:y,frequencyIndex:d,sampleRate:b,channel:p,modeExtension:m,copyright:h,original:g,emphasis:_,audioSamplesInFrame:S},bytesAdvanced:1}},OS=e=>{let t=2130706432,n=0;for(;t!==0;)n>>=1,n|=e&t,t>>=8;return n},kS=[48e3,44100,32e3],AS=[24e3,22050,16e3],jS;(function(e){e[e.NON_IDR_SLICE=1]=`NON_IDR_SLICE`,e[e.SLICE_DPA=2]=`SLICE_DPA`,e[e.SLICE_DPB=3]=`SLICE_DPB`,e[e.SLICE_DPC=4]=`SLICE_DPC`,e[e.IDR=5]=`IDR`,e[e.SEI=6]=`SEI`,e[e.SPS=7]=`SPS`,e[e.PPS=8]=`PPS`,e[e.AUD=9]=`AUD`,e[e.SPS_EXT=13]=`SPS_EXT`})(jS||={});var MS;(function(e){e[e.RASL_N=8]=`RASL_N`,e[e.RASL_R=9]=`RASL_R`,e[e.BLA_W_LP=16]=`BLA_W_LP`,e[e.RSV_IRAP_VCL23=23]=`RSV_IRAP_VCL23`,e[e.VPS_NUT=32]=`VPS_NUT`,e[e.SPS_NUT=33]=`SPS_NUT`,e[e.PPS_NUT=34]=`PPS_NUT`,e[e.AUD_NUT=35]=`AUD_NUT`,e[e.PREFIX_SEI_NUT=39]=`PREFIX_SEI_NUT`,e[e.SUFFIX_SEI_NUT=40]=`SUFFIX_SEI_NUT`})(MS||={});var NS=function*(e){let t=0,n=-1;for(;t<e.length-2;){let r=e.indexOf(0,t);if(r===-1||r>=e.length-2)break;t=r;let i=0;if(t+3<e.length&&e[t+1]===0&&e[t+2]===0&&e[t+3]===1?i=4:e[t+1]===0&&e[t+2]===1&&(i=3),i===0){t++;continue}n!==-1&&t>n&&(yield{offset:n,length:t-n}),n=t+i,t=n}n!==-1&&n<e.length&&(yield{offset:n,length:e.length-n})},PS=function*(e,t){let n=0,r=new DataView(e.buffer,e.byteOffset,e.byteLength);for(;n+t<=e.length;){let e;t===1?e=r.getUint8(n):t===2?e=r.getUint16(n,!1):t===3?e=nx(r,n,!1):(J(t===4),e=r.getUint32(n,!1)),n+=t,yield{offset:n,length:e},n+=e}},FS=(e,t)=>t.description?PS(e,(jb(t.description)[4]&3)+1):NS(e),IS=e=>e&31,LS=e=>{let t=[],n=e.length;for(let r=0;r<n;r++)r+2<n&&e[r]===0&&e[r+1]===0&&e[r+2]===3?(t.push(0,0),r+=2):t.push(e[r]);return new Uint8Array(t)},RS=new Uint8Array([0,0,0,1]),zS=e=>{let t=e.reduce((e,t)=>e+RS.byteLength+t.byteLength,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(RS,r),r+=RS.byteLength,n.set(t,r),r+=t.byteLength;return n},BS=(e,t)=>{let n=e.reduce((e,n)=>e+t+n.byteLength,0),r=new Uint8Array(n),i=0;for(let n of e){let e=new DataView(r.buffer,r.byteOffset,r.byteLength);switch(t){case 1:e.setUint8(i,n.byteLength);break;case 2:e.setUint16(i,n.byteLength,!1);break;case 3:ix(e,i,n.byteLength,!1);break;case 4:e.setUint32(i,n.byteLength,!1);break}i+=t,r.set(n,i),i+=n.byteLength}return r},VS=(e,t)=>t.description?BS(e,(jb(t.description)[4]&3)+1):zS(e),HS=e=>{try{let t=[],n=[],r=[];for(let i of NS(e)){let a=e.subarray(i.offset,i.offset+i.length),o=IS(a[0]);o===jS.SPS?t.push(a):o===jS.PPS?n.push(a):o===jS.SPS_EXT&&r.push(a)}if(t.length===0||n.length===0)return null;let i=t[0],a=KS(i);J(a!==null);let o=a.profileIdc===100||a.profileIdc===110||a.profileIdc===122||a.profileIdc===144;return{configurationVersion:1,avcProfileIndication:a.profileIdc,profileCompatibility:a.constraintFlags,avcLevelIndication:a.levelIdc,lengthSizeMinusOne:3,sequenceParameterSets:t,pictureParameterSets:n,chromaFormat:o?a.chromaFormatIdc:null,bitDepthLumaMinus8:o?a.bitDepthLumaMinus8:null,bitDepthChromaMinus8:o?a.bitDepthChromaMinus8:null,sequenceParameterSetExt:o?r:null}}catch(e){return console.error(`Error building AVC Decoder Configuration Record:`,e),null}},US=e=>{let t=[];t.push(e.configurationVersion),t.push(e.avcProfileIndication),t.push(e.profileCompatibility),t.push(e.avcLevelIndication),t.push(252|e.lengthSizeMinusOne&3),t.push(224|e.sequenceParameterSets.length&31);for(let n of e.sequenceParameterSets){let e=n.byteLength;t.push(e>>8),t.push(e&255);for(let r=0;r<e;r++)t.push(n[r])}t.push(e.pictureParameterSets.length);for(let n of e.pictureParameterSets){let e=n.byteLength;t.push(e>>8),t.push(e&255);for(let r=0;r<e;r++)t.push(n[r])}if(e.avcProfileIndication===100||e.avcProfileIndication===110||e.avcProfileIndication===122||e.avcProfileIndication===144){J(e.chromaFormat!==null),J(e.bitDepthLumaMinus8!==null),J(e.bitDepthChromaMinus8!==null),J(e.sequenceParameterSetExt!==null),t.push(252|e.chromaFormat&3),t.push(248|e.bitDepthLumaMinus8&7),t.push(248|e.bitDepthChromaMinus8&7),t.push(e.sequenceParameterSetExt.length);for(let n of e.sequenceParameterSetExt){let e=n.byteLength;t.push(e>>8),t.push(e&255);for(let r=0;r<e;r++)t.push(n[r])}}return new Uint8Array(t)},WS=e=>{try{let t=Mb(e),n=0,r=t.getUint8(n++),i=t.getUint8(n++),a=t.getUint8(n++),o=t.getUint8(n++),s=t.getUint8(n++)&3,c=t.getUint8(n++)&31,l=[];for(let r=0;r<c;r++){let r=t.getUint16(n,!1);n+=2,l.push(e.subarray(n,n+r)),n+=r}let u=t.getUint8(n++),d=[];for(let r=0;r<u;r++){let r=t.getUint16(n,!1);n+=2,d.push(e.subarray(n,n+r)),n+=r}let f={configurationVersion:r,avcProfileIndication:i,profileCompatibility:a,avcLevelIndication:o,lengthSizeMinusOne:s,sequenceParameterSets:l,pictureParameterSets:d,chromaFormat:null,bitDepthLumaMinus8:null,bitDepthChromaMinus8:null,sequenceParameterSetExt:null};if((i===100||i===110||i===122||i===144)&&n+4<=e.length){let r=t.getUint8(n++)&3,i=t.getUint8(n++)&7,a=t.getUint8(n++)&7,o=t.getUint8(n++);f.chromaFormat=r,f.bitDepthLumaMinus8=i,f.bitDepthChromaMinus8=a;let s=[];for(let r=0;r<o;r++){let r=t.getUint16(n,!1);n+=2,s.push(e.subarray(n,n+r)),n+=r}f.sequenceParameterSetExt=s}return f}catch(e){return console.error(`Error deserializing AVC Decoder Configuration Record:`,e),null}},GS={1:{num:1,den:1},2:{num:12,den:11},3:{num:10,den:11},4:{num:16,den:11},5:{num:40,den:33},6:{num:24,den:11},7:{num:20,den:11},8:{num:32,den:11},9:{num:80,den:33},10:{num:18,den:11},11:{num:15,den:11},12:{num:64,den:33},13:{num:160,den:99},14:{num:4,den:3},15:{num:3,den:2},16:{num:2,den:1}},KS=e=>{try{let t=new Vx(LS(e));if(t.skipBits(1),t.skipBits(2),t.readBits(5)!==7)return null;let n=t.readAlignedByte(),r=t.readAlignedByte(),i=t.readAlignedByte();Y(t);let a=1,o=0,s=0,c=0;if((n===100||n===110||n===122||n===244||n===44||n===83||n===86||n===118||n===128)&&(a=Y(t),a===3&&(c=t.readBits(1)),o=Y(t),s=Y(t),t.skipBits(1),t.readBits(1))){for(let e=0;e<(a===3?12:8);e++)if(t.readBits(1)){let n=e<6?16:64,r=8,i=8;for(let e=0;e<n;e++){if(i!==0){let e=Ab(t);i=(r+e+256)%256}r=i===0?r:i}}}Y(t);let l=Y(t);if(l===0)Y(t);else if(l===1){t.skipBits(1),Ab(t),Ab(t);let e=Y(t);for(let n=0;n<e;n++)Ab(t)}Y(t),t.skipBits(1);let u=Y(t),d=Y(t),f=16*(u+1),p=16*(d+1),m=f,h=p,g=t.readBits(1);if(g||t.skipBits(1),t.skipBits(1),t.readBits(1)){let e=Y(t),n=Y(t),r=Y(t),i=Y(t),o,s;if((c===0?a:0)===0)o=1,s=2-g;else{let e=a===3?1:2,t=a===1?2:1;o=e,s=t*(2-g)}m-=o*(e+n),h-=s*(r+i)}let _=2,v=2,y=2,b=0,x={num:1,den:1},S=null,C=null;if(t.readBits(1)){if(t.readBits(1)){let e=t.readBits(8);if(e===255)x={num:t.readBits(16),den:t.readBits(16)};else{let t=GS[e];t&&(x=t)}}t.readBits(1)&&t.skipBits(1),t.readBits(1)&&(t.skipBits(3),b=t.readBits(1),t.readBits(1)&&(_=t.readBits(8),v=t.readBits(8),y=t.readBits(8))),t.readBits(1)&&(Y(t),Y(t)),t.readBits(1)&&(t.skipBits(32),t.skipBits(32),t.skipBits(1));let e=t.readBits(1);e&&qS(t);let n=t.readBits(1);n&&qS(t),(e||n)&&t.skipBits(1),t.skipBits(1),t.readBits(1)&&(t.skipBits(1),Y(t),Y(t),Y(t),Y(t),S=Y(t),C=Y(t))}if(S===null){J(C===null);let e=r&16;if((n===44||n===86||n===100||n===110||n===122||n===244)&&e)S=0,C=0;else{let e=u+1,t=d+1,n=(2-g)*t,r=Zx.find(e=>e.level>=i)??Ob(Zx),a=Math.min(Math.floor(r.maxDpbMbs/(e*n)),16);S=a,C=a}}return J(C!==null),{profileIdc:n,constraintFlags:r,levelIdc:i,frameMbsOnlyFlag:g,chromaFormatIdc:a,bitDepthLumaMinus8:o,bitDepthChromaMinus8:s,codedWidth:f,codedHeight:p,displayWidth:m,displayHeight:h,pixelAspectRatio:x,colourPrimaries:_,matrixCoefficients:y,transferCharacteristics:v,fullRangeFlag:b,numReorderFrames:S,maxDecFrameBuffering:C}}catch(e){return console.error(`Error parsing AVC SPS:`,e),null}},qS=e=>{let t=Y(e);e.skipBits(4),e.skipBits(4);for(let n=0;n<=t;n++)Y(e),Y(e),e.skipBits(1);e.skipBits(5),e.skipBits(5),e.skipBits(5),e.skipBits(5)},JS=(e,t)=>t.description?PS(e,(jb(t.description)[21]&3)+1):NS(e),YS=e=>e>>1&63,XS=e=>{try{let t=new Vx(LS(e));t.skipBits(16),t.readBits(4);let n=t.readBits(3),r=t.readBits(1),{general_profile_space:i,general_tier_flag:a,general_profile_idc:o,general_profile_compatibility_flags:s,general_constraint_indicator_flags:c,general_level_idc:l}=QS(t,n);Y(t);let u=Y(t),d=0;u===3&&(d=t.readBits(1));let f=Y(t),p=Y(t),m=f,h=p;if(t.readBits(1)){let e=Y(t),n=Y(t),r=Y(t),i=Y(t),a=1,o=1,s=d===0?u:0;s===1?(a=2,o=2):s===2&&(a=2,o=1),m-=(e+n)*a,h-=(r+i)*o}let g=Y(t),_=Y(t);Y(t);let v=t.readBits(1)?0:n,y=0;for(let e=v;e<=n;e++)Y(t),y=Y(t),Y(t);if(Y(t),Y(t),Y(t),Y(t),Y(t),Y(t),t.readBits(1)&&t.readBits(1)&&$S(t),t.skipBits(1),t.skipBits(1),t.readBits(1)&&(t.skipBits(4),t.skipBits(4),Y(t),Y(t),t.skipBits(1)),eC(t,Y(t)),t.readBits(1)){let e=Y(t);for(let n=0;n<e;n++)Y(t),t.skipBits(1)}t.skipBits(1),t.skipBits(1);let b=2,x=2,S=2,C=0,w=0,T={num:1,den:1};if(t.readBits(1)){let e=nC(t,n);T=e.pixelAspectRatio,b=e.colourPrimaries,x=e.transferCharacteristics,S=e.matrixCoefficients,C=e.fullRangeFlag,w=e.minSpatialSegmentationIdc}return{displayWidth:m,displayHeight:h,pixelAspectRatio:T,colourPrimaries:b,transferCharacteristics:x,matrixCoefficients:S,fullRangeFlag:C,maxDecFrameBuffering:y+1,spsMaxSubLayersMinus1:n,spsTemporalIdNestingFlag:r,generalProfileSpace:i,generalTierFlag:a,generalProfileIdc:o,generalProfileCompatibilityFlags:s,generalConstraintIndicatorFlags:c,generalLevelIdc:l,chromaFormatIdc:u,bitDepthLumaMinus8:g,bitDepthChromaMinus8:_,minSpatialSegmentationIdc:w}}catch(e){return console.error(`Error parsing HEVC SPS:`,e),null}},ZS=e=>{try{let t=[],n=[],r=[],i=[];for(let a of NS(e)){let o=e.subarray(a.offset,a.offset+a.length),s=YS(o[0]);s===MS.VPS_NUT?t.push(o):s===MS.SPS_NUT?n.push(o):s===MS.PPS_NUT?r.push(o):(s===MS.PREFIX_SEI_NUT||s===MS.SUFFIX_SEI_NUT)&&i.push(o)}if(n.length===0||r.length===0)return null;let a=XS(n[0]);if(!a)return null;let o=0;if(r.length>0){let e=r[0],t=new Vx(LS(e));t.skipBits(16),Y(t),Y(t),t.skipBits(1),t.skipBits(1),t.skipBits(3),t.skipBits(1),t.skipBits(1),Y(t),Y(t),Ab(t),t.skipBits(1),t.skipBits(1),t.readBits(1)&&Y(t),Ab(t),Ab(t),t.skipBits(1),t.skipBits(1),t.skipBits(1),t.skipBits(1);let n=t.readBits(1),i=t.readBits(1);o=!n&&!i?0:n&&!i?2:!n&&i?3:0}let s=[...t.length?[{arrayCompleteness:1,nalUnitType:MS.VPS_NUT,nalUnits:t}]:[],...n.length?[{arrayCompleteness:1,nalUnitType:MS.SPS_NUT,nalUnits:n}]:[],...r.length?[{arrayCompleteness:1,nalUnitType:MS.PPS_NUT,nalUnits:r}]:[],...i.length?[{arrayCompleteness:1,nalUnitType:YS(i[0][0]),nalUnits:i}]:[]];return{configurationVersion:1,generalProfileSpace:a.generalProfileSpace,generalTierFlag:a.generalTierFlag,generalProfileIdc:a.generalProfileIdc,generalProfileCompatibilityFlags:a.generalProfileCompatibilityFlags,generalConstraintIndicatorFlags:a.generalConstraintIndicatorFlags,generalLevelIdc:a.generalLevelIdc,minSpatialSegmentationIdc:a.minSpatialSegmentationIdc,parallelismType:o,chromaFormatIdc:a.chromaFormatIdc,bitDepthLumaMinus8:a.bitDepthLumaMinus8,bitDepthChromaMinus8:a.bitDepthChromaMinus8,avgFrameRate:0,constantFrameRate:0,numTemporalLayers:a.spsMaxSubLayersMinus1+1,temporalIdNested:a.spsTemporalIdNestingFlag,lengthSizeMinusOne:3,arrays:s}}catch(e){return console.error(`Error building HEVC Decoder Configuration Record:`,e),null}},QS=(e,t)=>{let n=e.readBits(2),r=e.readBits(1),i=e.readBits(5),a=0;for(let t=0;t<32;t++)a=a<<1|e.readBits(1);let o=new Uint8Array(6);for(let t=0;t<6;t++)o[t]=e.readBits(8);let s=e.readBits(8),c=[],l=[];for(let n=0;n<t;n++)c.push(e.readBits(1)),l.push(e.readBits(1));if(t>0)for(let n=t;n<8;n++)e.skipBits(2);for(let n=0;n<t;n++)c[n]&&e.skipBits(88),l[n]&&e.skipBits(8);return{general_profile_space:n,general_tier_flag:r,general_profile_idc:i,general_profile_compatibility_flags:a,general_constraint_indicator_flags:o,general_level_idc:s}},$S=e=>{for(let t=0;t<4;t++)for(let n=0;n<(t===3?2:6);n++)if(!e.readBits(1))Y(e);else{let n=Math.min(64,1<<4+(t<<1));t>1&&Ab(e);for(let t=0;t<n;t++)Ab(e)}},eC=(e,t)=>{let n=[];for(let r=0;r<t;r++)n[r]=tC(e,r,t,n)},tC=(e,t,n,r)=>{let i=0,a=0,o=0;if(t!==0&&(a=e.readBits(1)),a){o=t===n?t-(Y(e)+1):t-1,e.readBits(1),Y(e);let a=r[o]??0;for(let t=0;t<=a;t++)e.readBits(1)||e.readBits(1);i=r[o]}else{let t=Y(e),n=Y(e);for(let n=0;n<t;n++)Y(e),e.readBits(1);for(let t=0;t<n;t++)Y(e),e.readBits(1);i=t+n}return i},nC=(e,t)=>{let n=2,r=2,i=2,a=0,o=0,s={num:1,den:1};if(e.readBits(1)){let t=e.readBits(8);if(t===255)s={num:e.readBits(16),den:e.readBits(16)};else{let e=GS[t];e&&(s=e)}}return e.readBits(1)&&e.readBits(1),e.readBits(1)&&(e.readBits(3),a=e.readBits(1),e.readBits(1)&&(n=e.readBits(8),r=e.readBits(8),i=e.readBits(8))),e.readBits(1)&&(Y(e),Y(e)),e.readBits(1),e.readBits(1),e.readBits(1),e.readBits(1)&&(Y(e),Y(e),Y(e),Y(e)),e.readBits(1)&&(e.readBits(32),e.readBits(32),e.readBits(1)&&Y(e),e.readBits(1)&&rC(e,!0,t)),e.readBits(1)&&(e.readBits(1),e.readBits(1),e.readBits(1),o=Y(e),Y(e),Y(e),Y(e),Y(e)),{pixelAspectRatio:s,colourPrimaries:n,transferCharacteristics:r,matrixCoefficients:i,fullRangeFlag:a,minSpatialSegmentationIdc:o}},rC=(e,t,n)=>{let r=!1,i=!1,a=!1;t&&(r=e.readBits(1)===1,i=e.readBits(1)===1,(r||i)&&(a=e.readBits(1)===1,a&&(e.readBits(8),e.readBits(5),e.readBits(1),e.readBits(5)),e.readBits(4),e.readBits(4),a&&e.readBits(4),e.readBits(5),e.readBits(5),e.readBits(5)));for(let t=0;t<=n;t++){let t=e.readBits(1)===1,n=!0;t||(n=e.readBits(1)===1);let o=!1;n?Y(e):o=e.readBits(1)===1;let s=1;o||(s=Y(e)+1),r&&iC(e,s,a),i&&iC(e,s,a)}},iC=(e,t,n)=>{for(let r=0;r<t;r++)Y(e),Y(e),n&&(Y(e),Y(e)),e.readBits(1)},aC=e=>{let t=[];t.push(e.configurationVersion),t.push((e.generalProfileSpace&3)<<6|(e.generalTierFlag&1)<<5|e.generalProfileIdc&31),t.push(e.generalProfileCompatibilityFlags>>>24&255),t.push(e.generalProfileCompatibilityFlags>>>16&255),t.push(e.generalProfileCompatibilityFlags>>>8&255),t.push(e.generalProfileCompatibilityFlags&255),t.push(...e.generalConstraintIndicatorFlags),t.push(e.generalLevelIdc&255),t.push(240|e.minSpatialSegmentationIdc>>8&15),t.push(e.minSpatialSegmentationIdc&255),t.push(252|e.parallelismType&3),t.push(252|e.chromaFormatIdc&3),t.push(248|e.bitDepthLumaMinus8&7),t.push(248|e.bitDepthChromaMinus8&7),t.push(e.avgFrameRate>>8&255),t.push(e.avgFrameRate&255),t.push((e.constantFrameRate&3)<<6|(e.numTemporalLayers&7)<<3|(e.temporalIdNested&1)<<2|e.lengthSizeMinusOne&3),t.push(e.arrays.length&255);for(let n of e.arrays){t.push((n.arrayCompleteness&1)<<7|0|n.nalUnitType&63),t.push(n.nalUnits.length>>8&255),t.push(n.nalUnits.length&255);for(let e of n.nalUnits){t.push(e.length>>8&255),t.push(e.length&255);for(let n=0;n<e.length;n++)t.push(e[n])}}return new Uint8Array(t)},oC=e=>{let t=new Vx(e);if(t.readBits(2)!==2)return null;let n=t.readBits(1),r=(t.readBits(1)<<1)+n;if(r===3&&t.skipBits(1),t.readBits(1)===1||t.readBits(1)!==0||(t.skipBits(2),t.readBits(24)!==4817730))return null;let i=8;r>=2&&(i=t.readBits(1)?12:10);let a=t.readBits(3),o=0,s=0;if(a!==7)if(s=t.readBits(1),r===1||r===3){let e=t.readBits(1),n=t.readBits(1);o=!e&&!n?3:e&&!n?2:1,t.skipBits(1)}else o=1;else o=3,s=1;let c=t.readBits(16),l=t.readBits(16),u=(c+1)*(l+1),d=Ob($x).level;for(let e of $x)if(u<=e.maxPictureSize){d=e.level;break}return{profile:r,level:d,bitDepth:i,chromaSubsampling:o,videoFullRangeFlag:s,colourPrimaries:a===2?1:a===1?6:2,transferCharacteristics:a===2?1:a===1?6:2,matrixCoefficients:a===7?0:a===2?1:a===1?6:2}},sC=function*(e){let t=new Vx(e),n=()=>{let e=0;for(let n=0;n<8;n++){let r=t.readAlignedByte();if(e|=(r&127)<<n*7,!(r&128))break;if(n===7&&r&128)return null}return e>=2**32-1?null:e};for(;t.getBitsLeft()>=8;){t.skipBits(1);let r=t.readBits(4),i=t.readBits(1),a=t.readBits(1);t.skipBits(1),i&&t.skipBits(8);let o;if(a){let e=n();if(e===null)return;o=e}else o=Math.floor(t.getBitsLeft()/8);J(t.pos%8==0),yield{type:r,data:e.subarray(t.pos/8,t.pos/8+o)},t.skipBits(o*8)}},cC=e=>{for(let{type:t,data:n}of sC(e)){if(t!==1)continue;let e=new Vx(n),r=e.readBits(3);e.readBits(1);let i=e.readBits(1),a=0,o=0,s=0;if(i)a=e.readBits(5);else{if(e.readBits(1)&&(e.skipBits(32),e.skipBits(32),e.readBits(1)))return null;let t=e.readBits(1);t&&(s=e.readBits(5),e.skipBits(32),e.skipBits(5),e.skipBits(5));let n=e.readBits(5);for(let r=0;r<=n;r++){e.skipBits(12);let n=e.readBits(5);if(r===0&&(a=n),n>7){let t=e.readBits(1);r===0&&(o=t)}if(t&&e.readBits(1)){let t=s+1;e.skipBits(t),e.skipBits(t),e.skipBits(1)}e.readBits(1)&&e.skipBits(4)}}let c=e.readBits(4),l=e.readBits(4),u=c+1;e.skipBits(u);let d=l+1;e.skipBits(d);let f=0;if(f=i?0:e.readBits(1),f&&(e.skipBits(4),e.skipBits(3)),e.skipBits(1),e.skipBits(1),e.skipBits(1),!i){e.skipBits(1),e.skipBits(1),e.skipBits(1),e.skipBits(1);let t=e.readBits(1);t&&(e.skipBits(1),e.skipBits(1));let n=e.readBits(1),r=0;r=n?2:e.readBits(1),r>0&&(e.readBits(1)||e.skipBits(1)),t&&e.skipBits(3)}e.skipBits(1),e.skipBits(1),e.skipBits(1);let p=e.readBits(1),m=8;r===2&&p?m=e.readBits(1)?12:10:r<=2&&(m=p?10:8);let h=0;r!==1&&(h=e.readBits(1));let g=1,_=1,v=0;return h||(r===0?(g=1,_=1):r===1?(g=0,_=0):m===12&&(g=e.readBits(1),g&&(_=e.readBits(1))),g&&_&&(v=e.readBits(2))),{profile:r,level:a,tier:o,bitDepth:m,monochrome:h,chromaSubsamplingX:g,chromaSubsamplingY:_,chromaSamplePosition:v}}return null},lC=e=>{let t=Mb(e),n=t.getUint8(9),r=t.getUint16(10,!0),i=t.getUint32(12,!0),a=t.getInt16(16,!0),o=t.getUint8(18),s=null;return o&&(s=e.subarray(19,21+n)),{outputChannelCount:n,preSkip:r,inputSampleRate:i,outputGain:a,channelMappingFamily:o,channelMappingTable:s}},uC=[480,960,1920,2880,480,960,1920,2880,480,960,1920,2880,480,960,480,960,120,240,480,960,120,240,480,960,120,240,480,960,120,240,480,960],dC=e=>({durationInSamples:uC[e[0]>>3]}),fC=e=>{if(e.length<7)throw Error(`Setup header is too short.`);if(e[0]!==5)throw Error(`Wrong packet type in Setup header.`);if(String.fromCharCode(...e.slice(1,7))!==`vorbis`)throw Error(`Invalid packet signature in Setup header.`);let t=e.length,n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=e[t-1-r];let r=new Vx(n),i=0;for(;r.getBitsLeft()>97;)if(r.readBits(1)===1){i=r.pos;break}if(i===0)throw Error(`Invalid Setup header: framing bit not found.`);let a=0,o=!1,s=0;for(;r.getBitsLeft()>=97;){let e=r.pos,t=r.readBits(8),n=r.readBits(16),i=r.readBits(16);if(t>63||n!==0||i!==0){r.pos=e;break}if(r.skipBits(1),a++,a>64)break;r.clone().readBits(6)+1===a&&(o=!0,s=a)}if(!o)throw Error(`Invalid Setup header: mode header not found.`);if(s>63)throw Error(`Unsupported mode count: ${s}.`);let c=s;r.pos=0,r.skipBits(i);let l=Array(c).fill(0);for(let e=c-1;e>=0;e--)r.skipBits(40),l[e]=r.readBits(1);return{modeBlockflags:l}},pC=(e,t,n)=>{switch(e){case`avc`:for(let e of FS(n,t)){let t=n[e.offset],r=IS(t);if(r>=jS.NON_IDR_SLICE&&r<=jS.SLICE_DPC)return`delta`;if(r===jS.IDR)return`key`;if(r===jS.SEI&&(!Tx()||Dx()>=144)){let t=LS(n.subarray(e.offset,e.offset+e.length)),r=1;do{let e=0;for(;;){let n=t[r++];if(n===void 0||(e+=n,n<255))break}let n=0;for(;;){let e=t[r++];if(e===void 0||(n+=e,e<255))break}if(e===6){let e=new Vx(t);e.pos=8*r;let n=Y(e),i=e.readBits(1);if(n===0&&i===1)return`key`}r+=n}while(r<t.length-1)}}return`delta`;case`hevc`:for(let e of JS(n,t)){let t=YS(n[e.offset]);if(t<MS.BLA_W_LP)return`delta`;if(t<=MS.RSV_IRAP_VCL23)return`key`}return`delta`;case`vp8`:return n[0]&1?`delta`:`key`;case`vp9`:{let e=new Vx(n);if(e.readBits(2)!==2)return null;let t=e.readBits(1);return(e.readBits(1)<<1)+t===3&&e.skipBits(1),e.readBits(1)?null:e.readBits(1)===0?`key`:`delta`}case`av1`:{let e=!1;for(let{type:t,data:r}of sC(n))if(t===1){let t=new Vx(r);t.skipBits(4),e=!!t.readBits(1)}else if(t===3||t===6||t===7){if(e)return`key`;let t=new Vx(r);return t.readBits(1)?null:t.readBits(2)===0?`key`:`delta`}return null}default:tx(e),J(!1)}},mC;(function(e){e[e.STREAMINFO=0]=`STREAMINFO`,e[e.VORBIS_COMMENT=4]=`VORBIS_COMMENT`,e[e.PICTURE=6]=`PICTURE`})(mC||={});var hC=(e,t)=>{let n=Mb(e),r=0,i=n.getUint32(r,!0);r+=4;let a=Nb.decode(e.subarray(r,r+i));r+=i,i>0&&(t.raw??={},t.raw.vendor??=a);let o=n.getUint32(r,!0);r+=4;for(let i=0;i<o;i++){let i=n.getUint32(r,!0);r+=4;let a=Nb.decode(e.subarray(r,r+i));r+=i;let o=a.indexOf(`=`);if(o===-1)continue;let s=a.slice(0,o).toUpperCase(),c=a.slice(o+1);switch(t.raw??={},t.raw[s]??=c,s){case`TITLE`:t.title??=c;break;case`DESCRIPTION`:t.description??=c;break;case`ARTIST`:t.artist??=c;break;case`ALBUM`:t.album??=c;break;case`ALBUMARTIST`:t.albumArtist??=c;break;case`COMMENT`:t.comment??=c;break;case`LYRICS`:t.lyrics??=c;break;case`TRACKNUMBER`:{let e=c.split(`/`),n=Number.parseInt(e[0],10),r=e[1]&&Number.parseInt(e[1],10);Number.isInteger(n)&&n>0&&(t.trackNumber??=n),r&&Number.isInteger(r)&&r>0&&(t.tracksTotal??=r)}break;case`TRACKTOTAL`:{let e=Number.parseInt(c,10);Number.isInteger(e)&&e>0&&(t.tracksTotal??=e)}break;case`DISCNUMBER`:{let e=c.split(`/`),n=Number.parseInt(e[0],10),r=e[1]&&Number.parseInt(e[1],10);Number.isInteger(n)&&n>0&&(t.discNumber??=n),r&&Number.isInteger(r)&&r>0&&(t.discsTotal??=r)}break;case`DISCTOTAL`:{let e=Number.parseInt(c,10);Number.isInteger(e)&&e>0&&(t.discsTotal??=e)}break;case`DATE`:{let e=new Date(c);Number.isNaN(e.getTime())||(t.date??=e)}break;case`GENRE`:t.genre??=c;break;case`METADATA_BLOCK_PICTURE`:{let e=jx(c),n=Mb(e),r=n.getUint32(0,!1),i=n.getUint32(4,!1),a=String.fromCharCode(...e.subarray(8,8+i)),o=n.getUint32(8+i,!1),s=Nb.decode(e.subarray(12+i,12+i+o)),l=n.getUint32(i+o+28),u=e.subarray(i+o+32,i+o+32+l);t.images??=[],t.images.push({data:u,mimeType:a,kind:r===3?`coverFront`:r===4?`coverBack`:`unknown`,name:void 0,description:s||void 0})}break}}},gC=[2,1,2,3,3,4,4,5],_C=e=>{if(e.length<7||e[0]!==11||e[1]!==119)return null;let t=new Vx(e);t.skipBits(16),t.skipBits(16);let n=t.readBits(2);if(n===3)return null;let r=t.readBits(6),i=t.readBits(5);if(i>8)return null;let a=t.readBits(3),o=t.readBits(3);return o&1&&o!==1&&t.skipBits(2),o&4&&t.skipBits(2),o===2&&t.skipBits(2),{fscod:n,bsid:i,bsmod:a,acmod:o,lfeon:t.readBits(1),bitRateCode:Math.floor(r/2)}},vC=[128,138,192,128,140,192,160,174,240,160,176,240,192,208,288,192,210,288,224,242,336,224,244,336,256,278,384,256,280,384,320,348,480,320,350,480,384,416,288*2,384,418,288*2,448,486,336*2,448,488,336*2,256*2,278*2,384*2,256*2,279*2,384*2,320*2,348*2,480*2,320*2,349*2,480*2,384*2,417*2,576*2,384*2,418*2,576*2,448*2,487*2,672*2,448*2,488*2,672*2,512*2,557*2,768*2,512*2,558*2,768*2,640*2,696*2,960*2,640*2,697*2,960*2,768*2,835*2,1152*2,768*2,836*2,1152*2,896*2,975*2,1344*2,896*2,976*2,1344*2,1024*2,1114*2,1536*2,1024*2,1115*2,1536*2,1152*2,1253*2,1728*2,1152*2,1254*2,1728*2,1280*2,1393*2,1920*2,1280*2,1394*2,1920*2],yC=1536;new Uint8Array([5,4,65,67,45,51]),new Uint8Array([5,4,69,65,67,51]);var bC=[1,2,3,6],xC=e=>{if(e.length<6||e[0]!==11||e[1]!==119)return null;let t=new Vx(e);t.skipBits(16);let n=t.readBits(2);if(t.skipBits(3),n!==0&&n!==2)return null;let r=t.readBits(11),i=t.readBits(2),a=0,o;i===3?(a=t.readBits(2),o=3):o=t.readBits(2);let s=t.readBits(3),c=t.readBits(1),l=t.readBits(5);if(l<11||l>16)return null;let u=bC[o],d;return d=i<3?kS[i]/1e3:AS[a]/1e3,{dataRate:Math.round((r+1)*d/(u*16)),substreams:[{fscod:i,fscod2:a,bsid:l,bsmod:0,acmod:s,lfeon:c,numDepSub:0,chanLoc:0}]}},SC=e=>{if(e.length<2)return null;let t=new Vx(e),n=t.readBits(13),r=t.readBits(3),i=[];for(let n=0;n<=r&&!(Math.ceil(t.pos/8)+3>e.length);n++){let e=t.readBits(2),n=t.readBits(5);t.skipBits(1),t.skipBits(1);let r=t.readBits(3),a=t.readBits(3),o=t.readBits(1);t.skipBits(3);let s=t.readBits(4),c=0;s>0?c=t.readBits(9):t.skipBits(1),i.push({fscod:e,fscod2:null,bsid:n,bsmod:r,acmod:a,lfeon:o,numDepSub:s,chanLoc:c})}return i.length===0?null:{dataRate:n,substreams:i}},CC=e=>{let t=e.substreams[0];return J(t),t.fscod<3?kS[t.fscod]:t.fscod2!==null&&t.fscod2<3?AS[t.fscod2]:null},wC=e=>{let t=e.substreams[0];J(t);let n=gC[t.acmod]+t.lfeon;if(t.numDepSub>0){let e=[2,2,1,1,2,2,2,1,1];for(let r=0;r<9;r++)t.chanLoc&1<<8-r&&(n+=e[r])}return n},TC=class{constructor(e){this.input=e}},EC=[],DC=[],OC=[],kC=[],AC=new Uint8Array,jC=class e{constructor(e,t,n,r,i=-1,a,o){if(this.data=e,this.type=t,this.timestamp=n,this.duration=r,this.sequenceNumber=i,e===AC&&a===void 0)throw Error(`Internal error: byteLength must be explicitly provided when constructing metadata-only packets.`);if(a===void 0&&(a=e.byteLength),!(e instanceof Uint8Array))throw TypeError(`data must be a Uint8Array.`);if(t!==`key`&&t!==`delta`)throw TypeError(`type must be either "key" or "delta".`);if(!Number.isFinite(n))throw TypeError(`timestamp must be a number.`);if(!Number.isFinite(r)||r<0)throw TypeError(`duration must be a non-negative number.`);if(!Number.isFinite(i))throw TypeError(`sequenceNumber must be a number.`);if(!Number.isInteger(a)||a<0)throw TypeError(`byteLength must be a non-negative integer.`);if(o!==void 0&&(typeof o!=`object`||!o))throw TypeError(`sideData, when provided, must be an object.`);if(o?.alpha!==void 0&&!(o.alpha instanceof Uint8Array))throw TypeError(`sideData.alpha, when provided, must be a Uint8Array.`);if(o?.alphaByteLength!==void 0&&(!Number.isInteger(o.alphaByteLength)||o.alphaByteLength<0))throw TypeError(`sideData.alphaByteLength, when provided, must be a non-negative integer.`);this.byteLength=a,this.sideData=o??{},this.sideData.alpha&&this.sideData.alphaByteLength===void 0&&(this.sideData.alphaByteLength=this.sideData.alpha.byteLength)}get isMetadataOnly(){return this.data===AC}get microsecondTimestamp(){return Math.trunc(mx*this.timestamp)}get microsecondDuration(){return Math.trunc(mx*this.duration)}toEncodedVideoChunk(){if(this.isMetadataOnly)throw TypeError(`Metadata-only packets cannot be converted to a video chunk.`);if(typeof EncodedVideoChunk>`u`)throw Error(`Your browser does not support EncodedVideoChunk.`);return new EncodedVideoChunk({data:this.data,type:this.type,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}alphaToEncodedVideoChunk(e=this.type){if(!this.sideData.alpha)throw TypeError(`This packet does not contain alpha side data.`);if(this.isMetadataOnly)throw TypeError(`Metadata-only packets cannot be converted to a video chunk.`);if(typeof EncodedVideoChunk>`u`)throw Error(`Your browser does not support EncodedVideoChunk.`);return new EncodedVideoChunk({data:this.sideData.alpha,type:e,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}toEncodedAudioChunk(){if(this.isMetadataOnly)throw TypeError(`Metadata-only packets cannot be converted to an audio chunk.`);if(typeof EncodedAudioChunk>`u`)throw Error(`Your browser does not support EncodedAudioChunk.`);return new EncodedAudioChunk({data:this.data,type:this.type,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}static fromEncodedChunk(t,n){if(!(t instanceof EncodedVideoChunk||t instanceof EncodedAudioChunk))throw TypeError(`chunk must be an EncodedVideoChunk or EncodedAudioChunk.`);let r=new Uint8Array(t.byteLength);return t.copyTo(r),new e(r,t.type,t.timestamp/1e6,(t.duration??0)/1e6,void 0,void 0,n)}clone(t){if(t!==void 0&&(typeof t!=`object`||!t))throw TypeError(`options, when provided, must be an object.`);if(t?.data!==void 0&&!(t.data instanceof Uint8Array))throw TypeError(`options.data, when provided, must be a Uint8Array.`);if(t?.type!==void 0&&t.type!==`key`&&t.type!==`delta`)throw TypeError(`options.type, when provided, must be either "key" or "delta".`);if(t?.timestamp!==void 0&&!Number.isFinite(t.timestamp))throw TypeError(`options.timestamp, when provided, must be a number.`);if(t?.duration!==void 0&&!Number.isFinite(t.duration))throw TypeError(`options.duration, when provided, must be a number.`);if(t?.sequenceNumber!==void 0&&!Number.isFinite(t.sequenceNumber))throw TypeError(`options.sequenceNumber, when provided, must be a number.`);if(t?.sideData!==void 0&&(typeof t.sideData!=`object`||t.sideData===null))throw TypeError(`options.sideData, when provided, must be an object.`);return new e(t?.data??this.data,t?.type??this.type,t?.timestamp??this.timestamp,t?.duration??this.duration,t?.sequenceNumber??this.sequenceNumber,this.byteLength,t?.sideData??this.sideData)}},MC=e=>{let t=8191,n=e,r=4096,i=0,a=12,o=0;for(n<0&&(n=-n,i=128),n+=33,n>t&&(n=t);(n&r)!==r&&a>=5;)r>>=1,a--;return o=n>>a-4&15,~(i|a-5<<4|o)&255},NC=e=>{let t=0,n=0,r=~e;r&128&&(r&=-129,t=-1),n=((r&240)>>4)+5;let i=(1<<n|(r&15)<<n-4|1<<n-5)-33;return t===0?i:-i},PC=e=>{let t=4095,n=2048,r=0,i=11,a=0,o=e;for(o<0&&(o=-o,r=128),o>t&&(o=t);(o&n)!==n&&i>=5;)n>>=1,i--;return a=o>>(i===4?1:i-4)&15,(r|i-4<<4|a)^85},FC=e=>{let t=0,n=0,r=e^85;r&128&&(r&=-129,t=-1),n=((r&240)>>4)+4;let i=0;return i=n===4?r<<1|1:1<<n|(r&15)<<n-4|1<<n-5,t===0?i:-i};Mx();var IC=-1/0,LC=-1/0,RC=null;typeof FinalizationRegistry<`u`&&(RC=new FinalizationRegistry(e=>{let t=Date.now();e.type===`video`?(t-IC>=1e3&&(console.error(`A VideoSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your VideoSamples as soon as you're done using them.`),IC=t),typeof VideoFrame<`u`&&e.data instanceof VideoFrame&&e.data.close()):(t-LC>=1e3&&(console.error(`An AudioSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your AudioSamples as soon as you're done using them.`),LC=t),typeof AudioData<`u`&&e.data instanceof AudioData&&e.data.close())}));var zC=[`I420`,`I420P10`,`I420P12`,`I420A`,`I420AP10`,`I420AP12`,`I422`,`I422P10`,`I422P12`,`I422A`,`I422AP10`,`I422AP12`,`I444`,`I444P10`,`I444P12`,`I444A`,`I444AP10`,`I444AP12`,`NV12`,`RGBA`,`RGBX`,`BGRA`,`BGRX`],BC=new Set(zC),VC=class e{get codedWidth(){return this.visibleRect.width}get codedHeight(){return this.visibleRect.height}get displayWidth(){return this.rotation%180==0?this.squarePixelWidth:this.squarePixelHeight}get displayHeight(){return this.rotation%180==0?this.squarePixelHeight:this.squarePixelWidth}get microsecondTimestamp(){return Math.trunc(mx*this.timestamp)}get microsecondDuration(){return Math.trunc(mx*this.duration)}get hasAlpha(){return this.format&&this.format.includes(`A`)}constructor(t,n){if(this._closed=!1,t instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&t instanceof SharedArrayBuffer||ArrayBuffer.isView(t)){if(!n||typeof n!=`object`)throw TypeError(`init must be an object.`);if(n.format===void 0||!BC.has(n.format))throw TypeError(`init.format must be one of: `+zC.join(`, `));if(!Number.isInteger(n.codedWidth)||n.codedWidth<=0)throw TypeError(`init.codedWidth must be a positive integer.`);if(!Number.isInteger(n.codedHeight)||n.codedHeight<=0)throw TypeError(`init.codedHeight must be a positive integer.`);if(n.rotation!==void 0&&![0,90,180,270].includes(n.rotation))throw TypeError(`init.rotation, when provided, must be 0, 90, 180, or 270.`);if(!Number.isFinite(n.timestamp))throw TypeError(`init.timestamp must be a number.`);if(n.duration!==void 0&&(!Number.isFinite(n.duration)||n.duration<0))throw TypeError(`init.duration, when provided, must be a non-negative number.`);if(n.layout!==void 0){if(!Array.isArray(n.layout))throw TypeError(`init.layout, when provided, must be an array.`);for(let e of n.layout){if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`Each entry in init.layout must be an object.`);if(!Number.isInteger(e.offset)||e.offset<0)throw TypeError(`plane.offset must be a non-negative integer.`);if(!Number.isInteger(e.stride)||e.stride<0)throw TypeError(`plane.stride must be a non-negative integer.`)}}if(n.visibleRect!==void 0&&Fx(n.visibleRect,`init.visibleRect`),n.displayWidth!==void 0&&(!Number.isInteger(n.displayWidth)||n.displayWidth<=0))throw TypeError(`init.displayWidth, when provided, must be a positive integer.`);if(n.displayHeight!==void 0&&(!Number.isInteger(n.displayHeight)||n.displayHeight<=0))throw TypeError(`init.displayHeight, when provided, must be a positive integer.`);if(n.displayWidth!==void 0!=(n.displayHeight!==void 0))throw TypeError(`init.displayWidth and init.displayHeight must be either both provided or both omitted.`);this._data=jb(t).slice(),this._layout=n.layout??qC(n.format,n.codedWidth,n.codedHeight),this.format=n.format,this.rotation=n.rotation??0,this.timestamp=n.timestamp,this.duration=n.duration??0,this.colorSpace=new HC(n.colorSpace),this.visibleRect={left:n.visibleRect?.left??0,top:n.visibleRect?.top??0,width:n.visibleRect?.width??n.codedWidth,height:n.visibleRect?.height??n.codedHeight},n.displayWidth===void 0?(this.squarePixelWidth=this.codedWidth,this.squarePixelHeight=this.codedHeight):(this.squarePixelWidth=this.rotation%180==0?n.displayWidth:n.displayHeight,this.squarePixelHeight=this.rotation%180==0?n.displayHeight:n.displayWidth)}else if(typeof VideoFrame<`u`&&t instanceof VideoFrame){if(n?.rotation!==void 0&&![0,90,180,270].includes(n.rotation))throw TypeError(`init.rotation, when provided, must be 0, 90, 180, or 270.`);if(n?.timestamp!==void 0&&!Number.isFinite(n?.timestamp))throw TypeError(`init.timestamp, when provided, must be a number.`);if(n?.duration!==void 0&&(!Number.isFinite(n.duration)||n.duration<0))throw TypeError(`init.duration, when provided, must be a non-negative number.`);n?.visibleRect!==void 0&&Fx(n.visibleRect,`init.visibleRect`),this._data=t,this._layout=null,this.format=t.format,this.visibleRect={left:t.visibleRect?.x??0,top:t.visibleRect?.y??0,width:t.visibleRect?.width??t.codedWidth,height:t.visibleRect?.height??t.codedHeight},this.rotation=n?.rotation??0,this.squarePixelWidth=t.displayWidth,this.squarePixelHeight=t.displayHeight,this.timestamp=n?.timestamp??t.timestamp/1e6,this.duration=n?.duration??(t.duration??0)/1e6,this.colorSpace=new HC(t.colorSpace)}else if(typeof HTMLImageElement<`u`&&t instanceof HTMLImageElement||typeof SVGImageElement<`u`&&t instanceof SVGImageElement||typeof ImageBitmap<`u`&&t instanceof ImageBitmap||typeof HTMLVideoElement<`u`&&t instanceof HTMLVideoElement||typeof HTMLCanvasElement<`u`&&t instanceof HTMLCanvasElement||typeof OffscreenCanvas<`u`&&t instanceof OffscreenCanvas){if(!n||typeof n!=`object`)throw TypeError(`init must be an object.`);if(n.rotation!==void 0&&![0,90,180,270].includes(n.rotation))throw TypeError(`init.rotation, when provided, must be 0, 90, 180, or 270.`);if(!Number.isFinite(n.timestamp))throw TypeError(`init.timestamp must be a number.`);if(n.duration!==void 0&&(!Number.isFinite(n.duration)||n.duration<0))throw TypeError(`init.duration, when provided, must be a non-negative number.`);if(typeof VideoFrame<`u`)return new e(new VideoFrame(t,{timestamp:Math.trunc(n.timestamp*mx),duration:Math.trunc((n.duration??0)*mx)||void 0}),n);let r=0,i=0;if(`naturalWidth`in t?(r=t.naturalWidth,i=t.naturalHeight):`videoWidth`in t?(r=t.videoWidth,i=t.videoHeight):`width`in t&&(r=Number(t.width),i=Number(t.height)),!r||!i)throw TypeError(`Could not determine dimensions.`);let a=new OffscreenCanvas(r,i),o=a.getContext(`2d`,{alpha:Cx(),willReadFrequently:!0});J(o),o.drawImage(t,0,0),this._data=a,this._layout=null,this.format=`RGBX`,this.visibleRect={left:0,top:0,width:r,height:i},this.squarePixelWidth=r,this.squarePixelHeight=i,this.rotation=n.rotation??0,this.timestamp=n.timestamp,this.duration=n.duration??0,this.colorSpace=new HC({matrix:`rgb`,primaries:`bt709`,transfer:`iec61966-2-1`,fullRange:!0})}else throw TypeError(`Invalid data type: Must be a BufferSource or CanvasImageSource.`);this.pixelAspectRatio=Px({num:this.squarePixelWidth*this.codedHeight,den:this.squarePixelHeight*this.codedWidth}),RC?.register(this,{type:`video`,data:this._data},this)}clone(){if(this._closed)throw Error(`VideoSample is closed.`);return J(this._data!==null),UC(this._data)?new e(this._data.clone(),{timestamp:this.timestamp,duration:this.duration,rotation:this.rotation}):this._data instanceof Uint8Array?(J(this._layout),new e(this._data,{format:this.format,layout:this._layout,codedWidth:this.codedWidth,codedHeight:this.codedHeight,timestamp:this.timestamp,duration:this.duration,colorSpace:this.colorSpace,rotation:this.rotation,visibleRect:this.visibleRect,displayWidth:this.displayWidth,displayHeight:this.displayHeight})):new e(this._data,{format:this.format,codedWidth:this.codedWidth,codedHeight:this.codedHeight,timestamp:this.timestamp,duration:this.duration,colorSpace:this.colorSpace,rotation:this.rotation,visibleRect:this.visibleRect,displayWidth:this.displayWidth,displayHeight:this.displayHeight})}close(){this._closed||=(RC?.unregister(this),UC(this._data)?this._data.close():this._data=null,!0)}allocationSize(e={}){if(KC(e),this._closed)throw Error(`VideoSample is closed.`);if(this.format===null)throw Error(`Cannot get allocation size when format is null. Sorry!`);if(J(this._data!==null),!UC(this._data)&&(e.colorSpace||e.format&&e.format!==this.format||e.layout||e.rect)){let t=this.toVideoFrame(),n=t.allocationSize(e);return t.close(),n}return UC(this._data)?this._data.allocationSize(e):this._data instanceof Uint8Array?this._data.byteLength:this.codedWidth*this.codedHeight*4}async copyTo(e,t={}){if(!Ub(e))throw TypeError(`destination must be an ArrayBuffer or an ArrayBuffer view.`);if(KC(t),this._closed)throw Error(`VideoSample is closed.`);if(this.format===null)throw Error(`Cannot copy video sample data when format is null. Sorry!`);if(J(this._data!==null),!UC(this._data)&&(t.colorSpace||t.format&&t.format!==this.format||t.layout||t.rect)){let n=this.toVideoFrame(),r=await n.copyTo(e,t);return n.close(),r}if(UC(this._data))return this._data.copyTo(e,t);if(this._data instanceof Uint8Array)return J(this._layout),jb(e).set(this._data),this._layout;{let t=this._data.getContext(`2d`);J(t);let n=t.getImageData(0,0,this.codedWidth,this.codedHeight);return jb(e).set(n.data),[{offset:0,stride:4*this.codedWidth}]}}toVideoFrame(){if(this._closed)throw Error(`VideoSample is closed.`);return J(this._data!==null),UC(this._data)?new VideoFrame(this._data,{timestamp:this.microsecondTimestamp,duration:this.microsecondDuration||void 0}):this._data instanceof Uint8Array?new VideoFrame(this._data,{format:this.format,codedWidth:this.codedWidth,codedHeight:this.codedHeight,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration||void 0,colorSpace:this.colorSpace}):new VideoFrame(this._data,{timestamp:this.microsecondTimestamp,duration:this.microsecondDuration||void 0})}draw(e,t,n,r,i,a,o,s,c){let l=0,u=0,d=this.displayWidth,f=this.displayHeight,p=0,m=0,h=this.displayWidth,g=this.displayHeight;if(a===void 0?(p=t,m=n,r!==void 0&&(h=r,g=i)):(l=t,u=n,d=r,f=i,p=a,m=o,s===void 0?(h=d,g=f):(h=s,g=c)),!(typeof CanvasRenderingContext2D<`u`&&e instanceof CanvasRenderingContext2D||typeof OffscreenCanvasRenderingContext2D<`u`&&e instanceof OffscreenCanvasRenderingContext2D))throw TypeError(`context must be a CanvasRenderingContext2D or OffscreenCanvasRenderingContext2D.`);if(!Number.isFinite(l))throw TypeError(`sx must be a number.`);if(!Number.isFinite(u))throw TypeError(`sy must be a number.`);if(!Number.isFinite(d)||d<0)throw TypeError(`sWidth must be a non-negative number.`);if(!Number.isFinite(f)||f<0)throw TypeError(`sHeight must be a non-negative number.`);if(!Number.isFinite(p))throw TypeError(`dx must be a number.`);if(!Number.isFinite(m))throw TypeError(`dy must be a number.`);if(!Number.isFinite(h)||h<0)throw TypeError(`dWidth must be a non-negative number.`);if(!Number.isFinite(g)||g<0)throw TypeError(`dHeight must be a non-negative number.`);if(this._closed)throw Error(`VideoSample is closed.`);({sx:l,sy:u,sWidth:d,sHeight:f}=this._rotateSourceRegion(l,u,d,f,this.rotation));let _=this.toCanvasImageSource();e.save();let v=p+h/2,y=m+g/2;e.translate(v,y),e.rotate(this.rotation*Math.PI/180);let b=this.rotation%180==0?1:h/g;e.scale(1/b,b),e.drawImage(_,l,u,d,f,-h/2,-g/2,h,g),e.restore()}drawWithFit(e,t){if(!(typeof CanvasRenderingContext2D<`u`&&e instanceof CanvasRenderingContext2D||typeof OffscreenCanvasRenderingContext2D<`u`&&e instanceof OffscreenCanvasRenderingContext2D))throw TypeError(`context must be a CanvasRenderingContext2D or OffscreenCanvasRenderingContext2D.`);if(!t||typeof t!=`object`)throw TypeError(`options must be an object.`);if(![`fill`,`contain`,`cover`].includes(t.fit))throw TypeError(`options.fit must be 'fill', 'contain', or 'cover'.`);if(t.rotation!==void 0&&![0,90,180,270].includes(t.rotation))throw TypeError(`options.rotation, when provided, must be 0, 90, 180, or 270.`);t.crop!==void 0&&GC(t.crop,`options.`);let n=e.canvas.width,r=e.canvas.height,i=t.rotation??this.rotation,[a,o]=i%180==0?[this.squarePixelWidth,this.squarePixelHeight]:[this.squarePixelHeight,this.squarePixelWidth];t.crop&&WC(t.crop,a,o);let s,c,l,u,{sx:d,sy:f,sWidth:p,sHeight:m}=this._rotateSourceRegion(t.crop?.left??0,t.crop?.top??0,t.crop?.width??a,t.crop?.height??o,i);if(t.fit===`fill`)s=0,c=0,l=n,u=r;else{let[e,i]=t.crop?[t.crop.width,t.crop.height]:[a,o],d=t.fit===`contain`?Math.min(n/e,r/i):Math.max(n/e,r/i);l=e*d,u=i*d,s=(n-l)/2,c=(r-u)/2}e.save();let h=i%180==0?1:l/u;e.translate(n/2,r/2),e.rotate(i*Math.PI/180),e.scale(1/h,h),e.translate(-n/2,-r/2),e.drawImage(this.toCanvasImageSource(),d,f,p,m,s,c,l,u),e.restore()}_rotateSourceRegion(e,t,n,r,i){return i===90?[e,t,n,r]=[t,this.squarePixelHeight-e-n,r,n]:i===180?[e,t]=[this.squarePixelWidth-e-n,this.squarePixelHeight-t-r]:i===270&&([e,t,n,r]=[this.squarePixelWidth-t-r,e,r,n]),{sx:e,sy:t,sWidth:n,sHeight:r}}toCanvasImageSource(){if(this._closed)throw Error(`VideoSample is closed.`);if(J(this._data!==null),this._data instanceof Uint8Array){let e=this.toVideoFrame();return queueMicrotask(()=>e.close()),e}else return this._data}setRotation(e){if(![0,90,180,270].includes(e))throw TypeError(`newRotation must be 0, 90, 180, or 270.`);this.rotation=e}setTimestamp(e){if(!Number.isFinite(e))throw TypeError(`newTimestamp must be a number.`);this.timestamp=e}setDuration(e){if(!Number.isFinite(e)||e<0)throw TypeError(`newDuration must be a non-negative number.`);this.duration=e}[Symbol.dispose](){this.close()}},HC=class{constructor(e){if(e!==void 0){if(!e||typeof e!=`object`)throw TypeError(`init.colorSpace, when provided, must be an object.`);let t=Object.keys(Ib);if(e.primaries!=null&&!t.includes(e.primaries))throw TypeError(`init.colorSpace.primaries, when provided, must be one of ${t.join(`, `)}.`);let n=Object.keys(Rb);if(e.transfer!=null&&!n.includes(e.transfer))throw TypeError(`init.colorSpace.transfer, when provided, must be one of ${n.join(`, `)}.`);let r=Object.keys(Bb);if(e.matrix!=null&&!r.includes(e.matrix))throw TypeError(`init.colorSpace.matrix, when provided, must be one of ${r.join(`, `)}.`);if(e.fullRange!=null&&typeof e.fullRange!=`boolean`)throw TypeError(`init.colorSpace.fullRange, when provided, must be a boolean.`)}this.primaries=e?.primaries??null,this.transfer=e?.transfer??null,this.matrix=e?.matrix??null,this.fullRange=e?.fullRange??null}toJSON(){return{primaries:this.primaries,transfer:this.transfer,matrix:this.matrix,fullRange:this.fullRange}}},UC=e=>typeof VideoFrame<`u`&&e instanceof VideoFrame,WC=(e,t,n)=>{e.left=Math.min(e.left,t),e.top=Math.min(e.top,n),e.width=Math.min(e.width,t-e.left),e.height=Math.min(e.height,n-e.top),J(e.width>=0),J(e.height>=0)},GC=(e,t)=>{if(!e||typeof e!=`object`)throw TypeError(t+`crop, when provided, must be an object.`);if(!Number.isInteger(e.left)||e.left<0)throw TypeError(t+`crop.left must be a non-negative integer.`);if(!Number.isInteger(e.top)||e.top<0)throw TypeError(t+`crop.top must be a non-negative integer.`);if(!Number.isInteger(e.width)||e.width<0)throw TypeError(t+`crop.width must be a non-negative integer.`);if(!Number.isInteger(e.height)||e.height<0)throw TypeError(t+`crop.height must be a non-negative integer.`)},KC=e=>{if(!e||typeof e!=`object`)throw TypeError(`options must be an object.`);if(e.colorSpace!==void 0&&![`display-p3`,`srgb`].includes(e.colorSpace))throw TypeError(`options.colorSpace, when provided, must be 'display-p3' or 'srgb'.`);if(e.format!==void 0&&typeof e.format!=`string`)throw TypeError(`options.format, when provided, must be a string.`);if(e.layout!==void 0){if(!Array.isArray(e.layout))throw TypeError(`options.layout, when provided, must be an array.`);for(let t of e.layout){if(!t||typeof t!=`object`)throw TypeError(`Each entry in options.layout must be an object.`);if(!Number.isInteger(t.offset)||t.offset<0)throw TypeError(`plane.offset must be a non-negative integer.`);if(!Number.isInteger(t.stride)||t.stride<0)throw TypeError(`plane.stride must be a non-negative integer.`)}}if(e.rect!==void 0){if(!e.rect||typeof e.rect!=`object`)throw TypeError(`options.rect, when provided, must be an object.`);if(e.rect.x!==void 0&&(!Number.isInteger(e.rect.x)||e.rect.x<0))throw TypeError(`options.rect.x, when provided, must be a non-negative integer.`);if(e.rect.y!==void 0&&(!Number.isInteger(e.rect.y)||e.rect.y<0))throw TypeError(`options.rect.y, when provided, must be a non-negative integer.`);if(e.rect.width!==void 0&&(!Number.isInteger(e.rect.width)||e.rect.width<0))throw TypeError(`options.rect.width, when provided, must be a non-negative integer.`);if(e.rect.height!==void 0&&(!Number.isInteger(e.rect.height)||e.rect.height<0))throw TypeError(`options.rect.height, when provided, must be a non-negative integer.`)}},qC=(e,t,n)=>{let r=JC(e),i=[],a=0;for(let e of r){let r=Math.ceil(t/e.widthDivisor),o=Math.ceil(n/e.heightDivisor),s=r*e.sampleBytes,c=s*o;i.push({offset:a,stride:s}),a+=c}return i},JC=e=>{let t=(e,t,n,r,i)=>{let a=[{sampleBytes:e,widthDivisor:1,heightDivisor:1},{sampleBytes:t,widthDivisor:n,heightDivisor:r},{sampleBytes:t,widthDivisor:n,heightDivisor:r}];return i&&a.push({sampleBytes:e,widthDivisor:1,heightDivisor:1}),a};switch(e){case`I420`:return t(1,1,2,2,!1);case`I420P10`:case`I420P12`:return t(2,2,2,2,!1);case`I420A`:return t(1,1,2,2,!0);case`I420AP10`:case`I420AP12`:return t(2,2,2,2,!0);case`I422`:return t(1,1,2,1,!1);case`I422P10`:case`I422P12`:return t(2,2,2,1,!1);case`I422A`:return t(1,1,2,1,!0);case`I422AP10`:case`I422AP12`:return t(2,2,2,1,!0);case`I444`:return t(1,1,1,1,!1);case`I444P10`:case`I444P12`:return t(2,2,1,1,!1);case`I444A`:return t(1,1,1,1,!0);case`I444AP10`:case`I444AP12`:return t(2,2,1,1,!0);case`NV12`:return[{sampleBytes:1,widthDivisor:1,heightDivisor:1},{sampleBytes:2,widthDivisor:2,heightDivisor:2}];case`RGBA`:case`RGBX`:case`BGRA`:case`BGRX`:return[{sampleBytes:4,widthDivisor:1,heightDivisor:1}];default:tx(e),J(!1)}},YC=new Set([`f32`,`f32-planar`,`s16`,`s16-planar`,`s32`,`s32-planar`,`u8`,`u8-planar`]),XC=class e{get microsecondTimestamp(){return Math.trunc(mx*this.timestamp)}get microsecondDuration(){return Math.trunc(mx*this.duration)}constructor(e){if(this._closed=!1,tw(e)){if(e.format===null)throw TypeError(`AudioData with null format is not supported.`);this._data=e,this.format=e.format,this.sampleRate=e.sampleRate,this.numberOfFrames=e.numberOfFrames,this.numberOfChannels=e.numberOfChannels,this.timestamp=e.timestamp/1e6,this.duration=e.numberOfFrames/e.sampleRate}else{if(!e||typeof e!=`object`)throw TypeError(`Invalid AudioDataInit: must be an object.`);if(!YC.has(e.format))throw TypeError(`Invalid AudioDataInit: invalid format.`);if(!Number.isFinite(e.sampleRate)||e.sampleRate<=0)throw TypeError(`Invalid AudioDataInit: sampleRate must be > 0.`);if(!Number.isInteger(e.numberOfChannels)||e.numberOfChannels===0)throw TypeError(`Invalid AudioDataInit: numberOfChannels must be an integer > 0.`);if(!Number.isFinite(e?.timestamp))throw TypeError(`init.timestamp must be a number.`);let t=e.data.byteLength/(ZC(e.format)*e.numberOfChannels);if(!Number.isInteger(t))throw TypeError(`Invalid AudioDataInit: data size is not a multiple of frame size.`);this.format=e.format,this.sampleRate=e.sampleRate,this.numberOfFrames=t,this.numberOfChannels=e.numberOfChannels,this.timestamp=e.timestamp,this.duration=t/e.sampleRate;let n;if(e.data instanceof ArrayBuffer)n=new Uint8Array(e.data);else if(ArrayBuffer.isView(e.data))n=new Uint8Array(e.data.buffer,e.data.byteOffset,e.data.byteLength);else throw TypeError(`Invalid AudioDataInit: data is not a BufferSource.`);let r=this.numberOfFrames*this.numberOfChannels*ZC(this.format);if(n.byteLength<r)throw TypeError(`Invalid AudioDataInit: insufficient data size.`);this._data=n}RC?.register(this,{type:`audio`,data:this._data},this)}allocationSize(e){if(!e||typeof e!=`object`)throw TypeError(`options must be an object.`);if(!Number.isInteger(e.planeIndex)||e.planeIndex<0)throw TypeError(`planeIndex must be a non-negative integer.`);if(e.format!==void 0&&!YC.has(e.format))throw TypeError(`Invalid format.`);if(e.frameOffset!==void 0&&(!Number.isInteger(e.frameOffset)||e.frameOffset<0))throw TypeError(`frameOffset must be a non-negative integer.`);if(e.frameCount!==void 0&&(!Number.isInteger(e.frameCount)||e.frameCount<0))throw TypeError(`frameCount must be a non-negative integer.`);if(this._closed)throw Error(`AudioSample is closed.`);let t=e.format??this.format,n=e.frameOffset??0;if(n>=this.numberOfFrames)throw RangeError(`frameOffset out of range`);let r=e.frameCount===void 0?this.numberOfFrames-n:e.frameCount;if(r>this.numberOfFrames-n)throw RangeError(`frameCount out of range`);let i=ZC(t),a=QC(t);if(a&&e.planeIndex>=this.numberOfChannels||!a&&e.planeIndex!==0)throw RangeError(`planeIndex out of range`);return(a?r:r*this.numberOfChannels)*i}copyTo(e,t){if(!Ub(e))throw TypeError(`destination must be an ArrayBuffer or an ArrayBuffer view.`);if(!t||typeof t!=`object`)throw TypeError(`options must be an object.`);if(!Number.isInteger(t.planeIndex)||t.planeIndex<0)throw TypeError(`planeIndex must be a non-negative integer.`);if(t.format!==void 0&&!YC.has(t.format))throw TypeError(`Invalid format.`);if(t.frameOffset!==void 0&&(!Number.isInteger(t.frameOffset)||t.frameOffset<0))throw TypeError(`frameOffset must be a non-negative integer.`);if(t.frameCount!==void 0&&(!Number.isInteger(t.frameCount)||t.frameCount<0))throw TypeError(`frameCount must be a non-negative integer.`);if(this._closed)throw Error(`AudioSample is closed.`);let{planeIndex:n,format:r,frameCount:i,frameOffset:a}=t,o=this.format,s=r??this.format;if(!s)throw Error(`Destination format not determined`);let c=this.numberOfFrames,l=this.numberOfChannels,u=a??0;if(u>=c)throw RangeError(`frameOffset out of range`);let d=i===void 0?c-u:i;if(d>c-u)throw RangeError(`frameCount out of range`);let f=ZC(s),p=QC(s);if(p&&n>=l||!p&&n!==0)throw RangeError(`planeIndex out of range`);let m=(p?d:d*l)*f;if(e.byteLength<m)throw RangeError(`Destination buffer is too small`);let h=Mb(e),g=ew(s);if(tw(this._data))xx()&&l>2&&s!==o?nw(this._data,h,o,s,l,n,u,d):this._data.copyTo(e,{planeIndex:n,frameOffset:u,frameCount:d,format:s});else{let e=this._data,t=Mb(e),r=$C(o),i=ZC(o),a=QC(o);for(let e=0;e<d;e++)if(p){let o=e*f,s;s=a?(n*c+(e+u))*i:((e+u)*l+n)*i,g(h,o,r(t,s))}else for(let n=0;n<l;n++){let o=(e*l+n)*f,s;s=a?(n*c+(e+u))*i:((e+u)*l+n)*i,g(h,o,r(t,s))}}}clone(){if(this._closed)throw Error(`AudioSample is closed.`);if(tw(this._data)){let t=new e(this._data.clone());return t.setTimestamp(this.timestamp),t}else return new e({format:this.format,sampleRate:this.sampleRate,numberOfFrames:this.numberOfFrames,numberOfChannels:this.numberOfChannels,timestamp:this.timestamp,data:this._data})}close(){this._closed||=(RC?.unregister(this),tw(this._data)?this._data.close():this._data=new Uint8Array,!0)}toAudioData(){if(this._closed)throw Error(`AudioSample is closed.`);if(tw(this._data)){if(this._data.timestamp===this.microsecondTimestamp)return this._data.clone();if(QC(this.format)){let e=this.allocationSize({planeIndex:0,format:this.format}),t=new ArrayBuffer(e*this.numberOfChannels);for(let n=0;n<this.numberOfChannels;n++)this.copyTo(new Uint8Array(t,n*e,e),{planeIndex:n,format:this.format});return new AudioData({format:this.format,sampleRate:this.sampleRate,numberOfFrames:this.numberOfFrames,numberOfChannels:this.numberOfChannels,timestamp:this.microsecondTimestamp,data:t})}else{let e=new ArrayBuffer(this.allocationSize({planeIndex:0,format:this.format}));return this.copyTo(e,{planeIndex:0,format:this.format}),new AudioData({format:this.format,sampleRate:this.sampleRate,numberOfFrames:this.numberOfFrames,numberOfChannels:this.numberOfChannels,timestamp:this.microsecondTimestamp,data:e})}}else return new AudioData({format:this.format,sampleRate:this.sampleRate,numberOfFrames:this.numberOfFrames,numberOfChannels:this.numberOfChannels,timestamp:this.microsecondTimestamp,data:this._data.buffer instanceof ArrayBuffer?this._data.buffer:this._data.slice()})}toAudioBuffer(){if(this._closed)throw Error(`AudioSample is closed.`);let e=new AudioBuffer({numberOfChannels:this.numberOfChannels,length:this.numberOfFrames,sampleRate:this.sampleRate}),t=new Float32Array(this.allocationSize({planeIndex:0,format:`f32-planar`})/4);for(let n=0;n<this.numberOfChannels;n++)this.copyTo(t,{planeIndex:n,format:`f32-planar`}),e.copyToChannel(t,n);return e}setTimestamp(e){if(!Number.isFinite(e))throw TypeError(`newTimestamp must be a number.`);this.timestamp=e}[Symbol.dispose](){this.close()}static*_fromAudioBuffer(t,n){if(!(t instanceof AudioBuffer))throw TypeError(`audioBuffer must be an AudioBuffer.`);let r=t.numberOfChannels,i=t.sampleRate,a=t.length,o=Math.floor(24e4/r),s=0,c=a;for(;c>0;){let a=Math.min(o,c),l=new Float32Array(r*a);for(let e=0;e<r;e++)t.copyFromChannel(l.subarray(e*a,(e+1)*a),e,s);yield new e({format:`f32-planar`,sampleRate:i,numberOfFrames:a,numberOfChannels:r,timestamp:n+s/i,data:l}),s+=a,c-=a}}static fromAudioBuffer(t,n){if(!(t instanceof AudioBuffer))throw TypeError(`audioBuffer must be an AudioBuffer.`);let r=t.numberOfChannels,i=t.sampleRate,a=t.length,o=Math.floor(24e4/r),s=0,c=a,l=[];for(;c>0;){let a=Math.min(o,c),u=new Float32Array(r*a);for(let e=0;e<r;e++)t.copyFromChannel(u.subarray(e*a,(e+1)*a),e,s);let d=new e({format:`f32-planar`,sampleRate:i,numberOfFrames:a,numberOfChannels:r,timestamp:n+s/i,data:u});l.push(d),s+=a,c-=a}return l}},ZC=e=>{switch(e){case`u8`:case`u8-planar`:return 1;case`s16`:case`s16-planar`:return 2;case`s32`:case`s32-planar`:return 4;case`f32`:case`f32-planar`:return 4;default:throw Error(`Unknown AudioSampleFormat`)}},QC=e=>{switch(e){case`u8-planar`:case`s16-planar`:case`s32-planar`:case`f32-planar`:return!0;default:return!1}},$C=e=>{switch(e){case`u8`:case`u8-planar`:return(e,t)=>(e.getUint8(t)-128)/128;case`s16`:case`s16-planar`:return(e,t)=>e.getInt16(t,!0)/32768;case`s32`:case`s32-planar`:return(e,t)=>e.getInt32(t,!0)/2147483648;case`f32`:case`f32-planar`:return(e,t)=>e.getFloat32(t,!0)}},ew=e=>{switch(e){case`u8`:case`u8-planar`:return(e,t,n)=>e.setUint8(t,sx((n+1)*127.5,0,255));case`s16`:case`s16-planar`:return(e,t,n)=>e.setInt16(t,sx(Math.round(n*32767),-32768,32767),!0);case`s32`:case`s32-planar`:return(e,t,n)=>e.setInt32(t,sx(Math.round(n*2147483647),-2147483648,2147483647),!0);case`f32`:case`f32-planar`:return(e,t,n)=>e.setFloat32(t,n,!0)}},tw=e=>typeof AudioData<`u`&&e instanceof AudioData,nw=(e,t,n,r,i,a,o,s)=>{let c=$C(n),l=ew(r),u=ZC(n),d=ZC(r),f=QC(n);if(QC(r))if(f){let r=new ArrayBuffer(s*u),i=Mb(r);e.copyTo(r,{planeIndex:a,frameOffset:o,frameCount:s,format:n});for(let e=0;e<s;e++){let n=e*u;l(t,e*d,c(i,n))}}else{let r=new ArrayBuffer(s*i*u),f=Mb(r);e.copyTo(r,{planeIndex:0,frameOffset:o,frameCount:s,format:n});for(let e=0;e<s;e++){let n=(e*i+a)*u;l(t,e*d,c(f,n))}}else if(f){let r=s*u,a=new ArrayBuffer(r),f=Mb(a);for(let r=0;r<i;r++){e.copyTo(a,{planeIndex:r,frameOffset:o,frameCount:s,format:n});for(let e=0;e<s;e++){let n=e*u;l(t,(e*i+r)*d,c(f,n))}}}else{let r=new ArrayBuffer(s*i*u),a=Mb(r);e.copyTo(r,{planeIndex:0,frameOffset:o,frameCount:s,format:n});for(let e=0;e<s;e++)for(let n=0;n<i;n++){let r=e*i+n,o=r*u;l(t,r*d,c(a,o))}}},rw=e=>{if(!e||typeof e!=`object`)throw TypeError(`options must be an object.`);if(e.metadataOnly!==void 0&&typeof e.metadataOnly!=`boolean`)throw TypeError(`options.metadataOnly, when defined, must be a boolean.`);if(e.verifyKeyPackets!==void 0&&typeof e.verifyKeyPackets!=`boolean`)throw TypeError(`options.verifyKeyPackets, when defined, must be a boolean.`);if(e.verifyKeyPackets&&e.metadataOnly)throw TypeError(`options.verifyKeyPackets and options.metadataOnly cannot be enabled together.`)},iw=e=>{if(!Nx(e))throw TypeError(`timestamp must be a number.`)},aw=(e,t,n)=>n.verifyKeyPackets?t.then(async t=>{if(!t||t.type===`delta`)return t;let n=await e.determinePacketType(t);return n&&(t.type=n),t}):t,ow=class{constructor(e){if(!(e instanceof vw))throw TypeError(`track must be an InputTrack.`);this._track=e}getFirstPacket(e={}){if(rw(e),this._track.input._disposed)throw new AE;return aw(this._track,this._track._backing.getFirstPacket(e),e)}async getFirstKeyPacket(e={}){rw(e);let t=await this.getFirstPacket(e);return t?t.type===`key`?t:this.getNextKeyPacket(t,e):null}getPacket(e,t={}){if(iw(e),rw(t),this._track.input._disposed)throw new AE;return aw(this._track,this._track._backing.getPacket(e,t),t)}getNextPacket(e,t={}){if(!(e instanceof jC))throw TypeError(`packet must be an EncodedPacket.`);if(rw(t),this._track.input._disposed)throw new AE;return aw(this._track,this._track._backing.getNextPacket(e,t),t)}async getKeyPacket(e,t={}){if(iw(e),rw(t),this._track.input._disposed)throw new AE;if(!t.verifyKeyPackets)return this._track._backing.getKeyPacket(e,t);let n=await this._track._backing.getKeyPacket(e,t);return n&&(J(n.type===`key`),await this._track.determinePacketType(n)===`delta`?this.getKeyPacket(n.timestamp-1/this._track.timeResolution,t):n)}async getNextKeyPacket(e,t={}){if(!(e instanceof jC))throw TypeError(`packet must be an EncodedPacket.`);if(rw(t),this._track.input._disposed)throw new AE;if(!t.verifyKeyPackets)return this._track._backing.getNextKeyPacket(e,t);let n=await this._track._backing.getNextKeyPacket(e,t);return n&&(J(n.type===`key`),await this._track.determinePacketType(n)===`delta`?this.getNextKeyPacket(n,t):n)}packets(e,t,n={}){if(e!==void 0&&!(e instanceof jC))throw TypeError(`startPacket must be an EncodedPacket.`);if(e!==void 0&&e.isMetadataOnly&&!n?.metadataOnly)throw TypeError(`startPacket can only be metadata-only if options.metadataOnly is enabled.`);if(t!==void 0&&!(t instanceof jC))throw TypeError(`endPacket must be an EncodedPacket.`);if(rw(n),this._track.input._disposed)throw new AE;let r=[],{promise:i,resolve:a}=Xb(),{promise:o,resolve:s}=Xb(),c=!1,l=!1,u=null,d=[],f=()=>Math.max(2,d.length);(async()=>{let u=e??await this.getFirstPacket(n);for(;u&&!l&&!this._track.input._disposed&&!(t&&u.sequenceNumber>=t?.sequenceNumber);){if(r.length>f()){({promise:o,resolve:s}=Xb()),await o;continue}r.push(u),a(),{promise:i,resolve:a}=Xb(),u=await this.getNextPacket(u,n)}c=!0,a()})().catch(e=>{u||(u=e,a())});let p=this._track;return{async next(){for(;;)if(p.input._disposed)throw new AE;else if(l)return{value:void 0,done:!0};else if(u)throw u;else if(r.length>0){let e=r.shift(),t=performance.now();for(d.push(t);d.length>0&&t-d[0]>=1e3;)d.shift();return s(),{value:e,done:!1}}else if(c)return{value:void 0,done:!0};else await i},async return(){return l=!0,s(),a(),{value:void 0,done:!0}},async throw(e){throw e},[Symbol.asyncIterator](){return this}}}},sw=class{constructor(e,t){this.onSample=e,this.onError=t}},cw=class{mediaSamplesInRange(e=0,t=1/0){iw(e),iw(t);let n=[],r=!1,i=null,{promise:a,resolve:o}=Xb(),{promise:s,resolve:c}=Xb(),l=!1,u=!1,d=!1,f=null;(async()=>{let p=await this._createDecoder(s=>{if(c(),s.timestamp>=t&&(u=!0),u){s.close();return}i&&(s.timestamp>e?(n.push(i),r=!0):i.close()),s.timestamp>=e&&(n.push(s),r=!0),i=r?null:s,n.length>0&&(o(),{promise:a,resolve:o}=Xb())},e=>{f||(f=e,o())}),m=this._createPacketSink(),h=await m.getKeyPacket(e,{verifyKeyPackets:!0})??await m.getFirstKeyPacket({verifyKeyPackets:!0}),g=h,_=m.packets(h??void 0,void 0);for(await _.next();g&&!u&&!this._track.input._disposed;){let e=lw(n.length);if(n.length+p.getDecodeQueueSize()>e){({promise:s,resolve:c}=Xb()),await s;continue}p.decode(g);let t=await _.next();if(t.done)break;g=t.value}await _.return(),!d&&!this._track.input._disposed&&await p.flush(),p.close(),!r&&i&&n.push(i),l=!0,o()})().catch(e=>{f||(f=e,o())});let p=this._track,m=()=>{i?.close();for(let e of n)e.close()};return{async next(){for(;;)if(p.input._disposed)throw m(),new AE;else if(d)return{value:void 0,done:!0};else if(f)throw m(),f;else if(n.length>0){let e=n.shift();return c(),{value:e,done:!1}}else if(!l)await a;else return{value:void 0,done:!0}},async return(){return d=!0,u=!0,c(),o(),m(),{value:void 0,done:!0}},async throw(e){throw e},[Symbol.asyncIterator](){return this}}}mediaSamplesAtTimestamps(e){ex(e);let t=$b(e),n=[],r=[],{promise:i,resolve:a}=Xb(),{promise:o,resolve:s}=Xb(),c=!1,l=!1,u=null,d=e=>{r.push(e),a(),{promise:i,resolve:a}=Xb()};(async()=>{let e=await this._createDecoder(e=>{if(s(),l){e.close();return}let t=0;for(;n.length>0&&e.timestamp-n[0]>-1e-10;)t++,n.shift();if(t>0)for(let n=0;n<t;n++)d(n<t-1?e.clone():e);else e.close()},e=>{u||(u=e,a())}),i=this._createPacketSink(),f=null,p=null,m=-1,h=async()=>{J(p);let t=p;for(e.decode(t);t.sequenceNumber<m;){let n=lw(r.length);for(;r.length+e.getDecodeQueueSize()>n&&!l;)({promise:o,resolve:s}=Xb()),await o;if(l)break;let a=await i.getNextPacket(t);J(a),e.decode(a),t=a}m=-1},g=async()=>{await e.flush();for(let e=0;e<n.length;e++)d(null);n.length=0};for await(let e of t){if(iw(e),l||this._track.input._disposed)break;let t=await i.getPacket(e),r=t&&await i.getKeyPacket(e,{verifyKeyPackets:!0});if(!r){m!==-1&&(await h(),await g()),d(null),f=null;continue}f&&(r.sequenceNumber!==p.sequenceNumber||t.timestamp<f.timestamp)&&(await h(),await g()),n.push(t.timestamp),m=Math.max(t.sequenceNumber,m),f=t,p=r}!l&&!this._track.input._disposed&&(m!==-1&&await h(),await g()),e.close(),c=!0,a()})().catch(e=>{u||(u=e,a())});let f=this._track,p=()=>{for(let e of r)e?.close()};return{async next(){for(;;)if(f.input._disposed)throw p(),new AE;else if(l)return{value:void 0,done:!0};else if(u)throw p(),u;else if(r.length>0){let e=r.shift();return J(e!==void 0),s(),{value:e,done:!1}}else if(!c)await i;else return{value:void 0,done:!0}},async return(){return l=!0,s(),a(),p(),{value:void 0,done:!0}},async throw(e){throw e},[Symbol.asyncIterator](){return this}}}},lw=e=>e===0?40:8,uw=class extends sw{constructor(e,t,n,r,i,a){super(e,t),this.codec=n,this.decoderConfig=r,this.rotation=i,this.timeResolution=a,this.decoder=null,this.customDecoder=null,this.customDecoderCallSerializer=new yx,this.customDecoderQueueSize=0,this.inputTimestamps=[],this.sampleQueue=[],this.currentPacketIndex=0,this.raslSkipped=!1,this.alphaDecoder=null,this.alphaHadKeyframe=!1,this.colorQueue=[],this.alphaQueue=[],this.merger=null,this.mergerCreationFailed=!1,this.decodedAlphaChunkCount=0,this.alphaDecoderQueueSize=0,this.nullAlphaFrameQueue=[],this.currentAlphaPacketIndex=0,this.alphaRaslSkipped=!1;let o=EC.find(e=>e.supports(n,r));if(o)this.customDecoder=new o,this.customDecoder.codec=n,this.customDecoder.config=r,this.customDecoder.onSample=e=>{if(!(e instanceof VC))throw TypeError(`The argument passed to onSample must be a VideoSample.`);this.finalizeAndEmitSample(e)},this.customDecoderCallSerializer.call(()=>this.customDecoder.init());else{let e=e=>{if(this.alphaQueue.length>0){let t=this.alphaQueue.shift();J(t!==void 0),this.mergeAlpha(e,t)}else this.colorQueue.push(e)};if(n===`avc`&&this.decoderConfig.description&&Tx()){let e=WS(jb(this.decoderConfig.description));if(e&&e.sequenceParameterSets.length>0){let t=KS(e.sequenceParameterSets[0]);t&&t.frameMbsOnlyFlag===0&&(this.decoderConfig={...this.decoderConfig,hardwareAcceleration:`prefer-software`})}}let t=Error(`Decoding error`).stack;this.decoder=new VideoDecoder({output:t=>{try{e(t)}catch(e){this.onError(e)}},error:e=>{e.stack=t,this.onError(e)}}),this.decoder.configure(this.decoderConfig)}}getDecodeQueueSize(){return this.customDecoder?this.customDecoderQueueSize:(J(this.decoder),Math.max(this.decoder.decodeQueueSize,this.alphaDecoder?.decodeQueueSize??0))}decode(e){if(this.codec===`hevc`&&this.currentPacketIndex>0&&!this.raslSkipped){if(this.hasHevcRaslPicture(e.data))return;this.raslSkipped=!0}if(this.customDecoder)this.customDecoderQueueSize++,this.customDecoderCallSerializer.call(()=>this.customDecoder.decode(e)).then(()=>this.customDecoderQueueSize--);else{if(J(this.decoder),xx()||Yb(this.inputTimestamps,e.timestamp,e=>e),Tx()&&this.currentPacketIndex===0&&this.codec===`avc`){let t=[];for(let n of FS(e.data,this.decoderConfig)){let r=IS(e.data[n.offset]);r>=20&&r<=31||t.push(e.data.subarray(n.offset,n.offset+n.length))}e=new jC(VS(t,this.decoderConfig),e.type,e.timestamp,e.duration)}this.decoder.decode(e.toEncodedVideoChunk()),this.decodeAlphaData(e)}this.currentPacketIndex++}decodeAlphaData(e){if(!e.sideData.alpha||this.mergerCreationFailed){this.pushNullAlphaFrame();return}if(!this.merger)try{this.merger=new dw}catch(t){console.error(`Due to an error, only color data will be decoded.`,t),this.mergerCreationFailed=!0,this.decodeAlphaData(e);return}if(!this.alphaDecoder){let e=e=>{if(this.alphaDecoderQueueSize--,this.colorQueue.length>0){let t=this.colorQueue.shift();J(t!==void 0),this.mergeAlpha(t,e)}else this.alphaQueue.push(e);for(this.decodedAlphaChunkCount++;this.nullAlphaFrameQueue.length>0&&this.nullAlphaFrameQueue[0]===this.decodedAlphaChunkCount;)if(this.nullAlphaFrameQueue.shift(),this.colorQueue.length>0){let e=this.colorQueue.shift();J(e!==void 0),this.mergeAlpha(e,null)}else this.alphaQueue.push(null)},t=Error(`Decoding error`).stack;this.alphaDecoder=new VideoDecoder({output:t=>{try{e(t)}catch(e){this.onError(e)}},error:e=>{e.stack=t,this.onError(e)}}),this.alphaDecoder.configure(this.decoderConfig)}let t=pC(this.codec,this.decoderConfig,e.sideData.alpha);if(this.alphaHadKeyframe||=t===`key`,this.alphaHadKeyframe){if(this.codec===`hevc`&&this.currentAlphaPacketIndex>0&&!this.alphaRaslSkipped){if(this.hasHevcRaslPicture(e.sideData.alpha)){this.pushNullAlphaFrame();return}this.alphaRaslSkipped=!0}this.currentAlphaPacketIndex++,this.alphaDecoder.decode(e.alphaToEncodedVideoChunk(t??e.type)),this.alphaDecoderQueueSize++}else this.pushNullAlphaFrame()}pushNullAlphaFrame(){this.alphaDecoderQueueSize===0?this.alphaQueue.push(null):this.nullAlphaFrameQueue.push(this.decodedAlphaChunkCount+this.alphaDecoderQueueSize)}hasHevcRaslPicture(e){for(let t of JS(e,this.decoderConfig)){let n=YS(e[t.offset]);if(n===MS.RASL_N||n===MS.RASL_R)return!0}return!1}sampleHandler(e){if(xx()){if(this.sampleQueue.length>0&&e.timestamp>=Ob(this.sampleQueue).timestamp){for(let e of this.sampleQueue)this.finalizeAndEmitSample(e);this.sampleQueue.length=0}Yb(this.sampleQueue,e,e=>e.timestamp)}else{let t=this.inputTimestamps.shift();J(t!==void 0),e.setTimestamp(t),this.finalizeAndEmitSample(e)}}finalizeAndEmitSample(e){e.setTimestamp(Math.round(e.timestamp*this.timeResolution)/this.timeResolution),e.setDuration(Math.round(e.duration*this.timeResolution)/this.timeResolution),e.setRotation(this.rotation),this.onSample(e)}mergeAlpha(e,t){if(!t){let t=new VC(e);this.sampleHandler(t);return}J(this.merger),this.merger.update(e,t),e.close(),t.close();let n=new VC(new VideoFrame(this.merger.canvas,{timestamp:e.timestamp,duration:e.duration??void 0}));this.sampleHandler(n)}async flush(){if(this.customDecoder?await this.customDecoderCallSerializer.call(()=>this.customDecoder.flush()):(J(this.decoder),await Promise.all([this.decoder.flush(),this.alphaDecoder?.flush()]),this.colorQueue.forEach(e=>e.close()),this.colorQueue.length=0,this.alphaQueue.forEach(e=>e?.close()),this.alphaQueue.length=0,this.alphaHadKeyframe=!1,this.decodedAlphaChunkCount=0,this.alphaDecoderQueueSize=0,this.nullAlphaFrameQueue.length=0,this.currentAlphaPacketIndex=0,this.alphaRaslSkipped=!1),xx()){for(let e of this.sampleQueue)this.finalizeAndEmitSample(e);this.sampleQueue.length=0}this.currentPacketIndex=0,this.raslSkipped=!1}close(){this.customDecoder?this.customDecoderCallSerializer.call(()=>this.customDecoder.close()):(J(this.decoder),this.decoder.close(),this.alphaDecoder?.close(),this.colorQueue.forEach(e=>e.close()),this.colorQueue.length=0,this.alphaQueue.forEach(e=>e?.close()),this.alphaQueue.length=0,this.merger?.close());for(let e of this.sampleQueue)e.close();this.sampleQueue.length=0}},dw=class{w=0;h=0;colorImageData=null;alphaImageData=null;constructor(){typeof OffscreenCanvas<`u`?(this.canvas=new OffscreenCanvas(1,1),this.alphaCanvas=new OffscreenCanvas(1,1)):(this.canvas=document.createElement(`canvas`),this.alphaCanvas=document.createElement(`canvas`));let e=this.canvas.getContext(`2d`,{alpha:!0,willReadFrequently:!0}),t=this.alphaCanvas.getContext(`2d`,{alpha:!0,willReadFrequently:!0});if(!e||!t)throw Error(`Couldn't acquire 2D canvas context.`);this.ctx=e,this.alphaCtx=t}update(e,t){let n=e.displayWidth,r=e.displayHeight;(n!==this.w||r!==this.h)&&(this.w=n,this.h=r,this.canvas.width=n,this.canvas.height=r,this.alphaCanvas.width=n,this.alphaCanvas.height=r,this.colorImageData=this.ctx.createImageData(n,r),this.alphaImageData=this.ctx.createImageData(n,r)),this.ctx.drawImage(e,0,0,n,r),this.alphaCtx.drawImage(t,0,0,n,r);let i=this.ctx.getImageData(0,0,n,r,{colorSpace:`srgb`}),a=this.alphaCtx.getImageData(0,0,n,r,{colorSpace:`srgb`}),o=new Uint32Array(i.data.buffer),s=new Uint32Array(a.data.buffer),c=o.length;for(let e=0;e<c;e++)o[e]=o[e]&16777215|(s[e]&255)<<24;this.ctx.putImageData(i,0,0)}close(){this.ctx=null,this.alphaCtx=null,this.colorImageData=null,this.alphaImageData=null}},fw=class extends cw{constructor(e){if(!(e instanceof yw))throw TypeError(`videoTrack must be an InputVideoTrack.`);super(),this._track=e}async _createDecoder(e,t){if(!await this._track.canDecode())throw Error(`This video track cannot be decoded by this browser. Make sure to check decodability before using a track.`);let n=this._track.codec,r=this._track.rotation,i=await this._track.getDecoderConfig(),a=this._track.timeResolution;return J(n&&i),new uw(e,t,n,i,r,a)}_createPacketSink(){return new ow(this._track)}async getSample(e){iw(e);for await(let t of this.mediaSamplesAtTimestamps([e]))return t;throw Error(`Internal error: Iterator returned nothing.`)}samples(e=0,t=1/0){return this.mediaSamplesInRange(e,t)}samplesAtTimestamps(e){return this.mediaSamplesAtTimestamps(e)}},pw=class{constructor(e,t={}){if(this._nextCanvasIndex=0,!(e instanceof yw))throw TypeError(`videoTrack must be an InputVideoTrack.`);if(t&&typeof t!=`object`)throw TypeError(`options must be an object.`);if(t.alpha!==void 0&&typeof t.alpha!=`boolean`)throw TypeError(`options.alpha, when provided, must be a boolean.`);if(t.width!==void 0&&(!Number.isInteger(t.width)||t.width<=0))throw TypeError(`options.width, when defined, must be a positive integer.`);if(t.height!==void 0&&(!Number.isInteger(t.height)||t.height<=0))throw TypeError(`options.height, when defined, must be a positive integer.`);if(t.fit!==void 0&&![`fill`,`contain`,`cover`].includes(t.fit))throw TypeError(`options.fit, when provided, must be one of "fill", "contain", or "cover".`);if(t.width!==void 0&&t.height!==void 0&&t.fit===void 0)throw TypeError(`When both options.width and options.height are provided, options.fit must also be provided.`);if(t.rotation!==void 0&&![0,90,180,270].includes(t.rotation))throw TypeError(`options.rotation, when provided, must be 0, 90, 180 or 270.`);if(t.crop!==void 0&&GC(t.crop,`options.`),t.poolSize!==void 0&&(typeof t.poolSize!=`number`||!Number.isInteger(t.poolSize)||t.poolSize<0))throw TypeError(`poolSize must be a non-negative integer.`);let n=t.rotation??e.rotation,[r,i]=n%180==0?[e.squarePixelWidth,e.squarePixelHeight]:[e.squarePixelHeight,e.squarePixelWidth],a=t.crop;a&&WC(a,r,i);let[o,s]=a?[a.width,a.height]:[r,i],c=o/s;t.width!==void 0&&t.height===void 0?(o=t.width,s=Math.round(o/c)):t.width===void 0&&t.height!==void 0?(s=t.height,o=Math.round(s*c)):t.width!==void 0&&t.height!==void 0&&(o=t.width,s=t.height),this._videoTrack=e,this._alpha=t.alpha??!1,this._width=o,this._height=s,this._rotation=n,this._crop=a,this._fit=t.fit??`fill`,this._videoSampleSink=new fw(e),this._canvasPool=Array.from({length:t.poolSize??0},()=>null)}_videoSampleToWrappedCanvas(e){let t=this._canvasPool[this._nextCanvasIndex],n=!1;t||(typeof document<`u`?(t=document.createElement(`canvas`),t.width=this._width,t.height=this._height):t=new OffscreenCanvas(this._width,this._height),this._canvasPool.length>0&&(this._canvasPool[this._nextCanvasIndex]=t),n=!0),this._canvasPool.length>0&&(this._nextCanvasIndex=(this._nextCanvasIndex+1)%this._canvasPool.length);let r=t.getContext(`2d`,{alpha:this._alpha||Cx()});J(r),r.resetTransform(),n||(!this._alpha&&Cx()?(r.fillStyle=`black`,r.fillRect(0,0,this._width,this._height)):r.clearRect(0,0,this._width,this._height)),e.drawWithFit(r,{fit:this._fit,rotation:this._rotation,crop:this._crop});let i={canvas:t,timestamp:e.timestamp,duration:e.duration};return e.close(),i}async getCanvas(e){iw(e);let t=await this._videoSampleSink.getSample(e);return t&&this._videoSampleToWrappedCanvas(t)}canvases(e=0,t=1/0){return ox(this._videoSampleSink.samples(e,t),e=>this._videoSampleToWrappedCanvas(e))}canvasesAtTimestamps(e){return ox(this._videoSampleSink.samplesAtTimestamps(e),e=>e&&this._videoSampleToWrappedCanvas(e))}},mw=class extends sw{constructor(e,t,n,r){super(e,t),this.decoder=null,this.customDecoder=null,this.customDecoderCallSerializer=new yx,this.customDecoderQueueSize=0,this.currentTimestamp=null;let i=t=>{(this.currentTimestamp===null||Math.abs(t.timestamp-this.currentTimestamp)>=t.duration)&&(this.currentTimestamp=t.timestamp);let n=this.currentTimestamp;if(this.currentTimestamp+=t.duration,t.numberOfFrames===0){t.close();return}let i=r.sampleRate;t.setTimestamp(Math.round(n*i)/i),e(t)},a=DC.find(e=>e.supports(n,r));if(a)this.customDecoder=new a,this.customDecoder.codec=n,this.customDecoder.config=r,this.customDecoder.onSample=e=>{if(!(e instanceof XC))throw TypeError(`The argument passed to onSample must be an AudioSample.`);i(e)},this.customDecoderCallSerializer.call(()=>this.customDecoder.init());else{let e=Error(`Decoding error`).stack;this.decoder=new AudioDecoder({output:e=>{try{i(new XC(e))}catch(e){this.onError(e)}},error:t=>{t.stack=e,this.onError(t)}}),this.decoder.configure(r)}}getDecodeQueueSize(){return this.customDecoder?this.customDecoderQueueSize:(J(this.decoder),this.decoder.decodeQueueSize)}decode(e){this.customDecoder?(this.customDecoderQueueSize++,this.customDecoderCallSerializer.call(()=>this.customDecoder.decode(e)).then(()=>this.customDecoderQueueSize--)):(J(this.decoder),this.decoder.decode(e.toEncodedAudioChunk()))}flush(){return this.customDecoder?this.customDecoderCallSerializer.call(()=>this.customDecoder.flush()):(J(this.decoder),this.decoder.flush())}close(){this.customDecoder?this.customDecoderCallSerializer.call(()=>this.customDecoder.close()):(J(this.decoder),this.decoder.close())}},hw=class extends sw{constructor(e,t,n){super(e,t),this.decoderConfig=n,this.currentTimestamp=null,J(qx.includes(n.codec)),this.codec=n.codec;let{dataType:r,sampleSize:i,littleEndian:a}=uS(this.codec);switch(this.inputSampleSize=i,i){case 1:r===`unsigned`?this.readInputValue=(e,t)=>e.getUint8(t)-2**7:r===`signed`?this.readInputValue=(e,t)=>e.getInt8(t):r===`ulaw`?this.readInputValue=(e,t)=>NC(e.getUint8(t)):r===`alaw`?this.readInputValue=(e,t)=>FC(e.getUint8(t)):J(!1);break;case 2:r===`unsigned`?this.readInputValue=(e,t)=>e.getUint16(t,a)-2**15:r===`signed`?this.readInputValue=(e,t)=>e.getInt16(t,a):J(!1);break;case 3:r===`unsigned`?this.readInputValue=(e,t)=>nx(e,t,a)-2**23:r===`signed`?this.readInputValue=(e,t)=>rx(e,t,a):J(!1);break;case 4:r===`unsigned`?this.readInputValue=(e,t)=>e.getUint32(t,a)-2**31:r===`signed`?this.readInputValue=(e,t)=>e.getInt32(t,a):r===`float`?this.readInputValue=(e,t)=>e.getFloat32(t,a):J(!1);break;case 8:r===`float`?this.readInputValue=(e,t)=>e.getFloat64(t,a):J(!1);break;default:tx(i),J(!1)}switch(i){case 1:r===`ulaw`||r===`alaw`?(this.outputSampleSize=2,this.outputFormat=`s16`,this.writeOutputValue=(e,t,n)=>e.setInt16(t,n,!0)):(this.outputSampleSize=1,this.outputFormat=`u8`,this.writeOutputValue=(e,t,n)=>e.setUint8(t,n+2**7));break;case 2:this.outputSampleSize=2,this.outputFormat=`s16`,this.writeOutputValue=(e,t,n)=>e.setInt16(t,n,!0);break;case 3:this.outputSampleSize=4,this.outputFormat=`s32`,this.writeOutputValue=(e,t,n)=>e.setInt32(t,n<<8,!0);break;case 4:this.outputSampleSize=4,r===`float`?(this.outputFormat=`f32`,this.writeOutputValue=(e,t,n)=>e.setFloat32(t,n,!0)):(this.outputFormat=`s32`,this.writeOutputValue=(e,t,n)=>e.setInt32(t,n,!0));break;case 8:this.outputSampleSize=4,this.outputFormat=`f32`,this.writeOutputValue=(e,t,n)=>e.setFloat32(t,n,!0);break;default:tx(i),J(!1)}}getDecodeQueueSize(){return 0}decode(e){let t=Mb(e.data),n=e.byteLength/this.decoderConfig.numberOfChannels/this.inputSampleSize,r=n*this.decoderConfig.numberOfChannels*this.outputSampleSize,i=new ArrayBuffer(r),a=new DataView(i);for(let e=0;e<n*this.decoderConfig.numberOfChannels;e++){let n=e*this.inputSampleSize,r=e*this.outputSampleSize,i=this.readInputValue(t,n);this.writeOutputValue(a,r,i)}let o=n/this.decoderConfig.sampleRate;(this.currentTimestamp===null||Math.abs(e.timestamp-this.currentTimestamp)>=o)&&(this.currentTimestamp=e.timestamp);let s=this.currentTimestamp;this.currentTimestamp+=o;let c=new XC({format:this.outputFormat,data:i,numberOfChannels:this.decoderConfig.numberOfChannels,sampleRate:this.decoderConfig.sampleRate,numberOfFrames:n,timestamp:s});this.onSample(c)}async flush(){}close(){}},gw=class extends cw{constructor(e){if(!(e instanceof bw))throw TypeError(`audioTrack must be an InputAudioTrack.`);super(),this._track=e}async _createDecoder(e,t){if(!await this._track.canDecode())throw Error(`This audio track cannot be decoded by this browser. Make sure to check decodability before using a track.`);let n=this._track.codec,r=await this._track.getDecoderConfig();return J(n&&r),qx.includes(r.codec)?new hw(e,t,r):new mw(e,t,n,r)}_createPacketSink(){return new ow(this._track)}async getSample(e){iw(e);for await(let t of this.mediaSamplesAtTimestamps([e]))return t;throw Error(`Internal error: Iterator returned nothing.`)}samples(e=0,t=1/0){return this.mediaSamplesInRange(e,t)}samplesAtTimestamps(e){return this.mediaSamplesAtTimestamps(e)}},_w=class{constructor(e){if(!(e instanceof bw))throw TypeError(`audioTrack must be an InputAudioTrack.`);this._audioSampleSink=new gw(e)}_audioSampleToWrappedArrayBuffer(e){let t={buffer:e.toAudioBuffer(),timestamp:e.timestamp,duration:e.duration};return e.close(),t}async getBuffer(e){iw(e);let t=await this._audioSampleSink.getSample(e);return t&&this._audioSampleToWrappedArrayBuffer(t)}buffers(e=0,t=1/0){return ox(this._audioSampleSink.samples(e,t),e=>this._audioSampleToWrappedArrayBuffer(e))}buffersAtTimestamps(e){return ox(this._audioSampleSink.samplesAtTimestamps(e),e=>e&&this._audioSampleToWrappedArrayBuffer(e))}},vw=class{constructor(e,t){this.input=e,this._backing=t}isVideoTrack(){return this instanceof yw}isAudioTrack(){return this instanceof bw}get id(){return this._backing.getId()}get number(){return this._backing.getNumber()}get internalCodecId(){return this._backing.getInternalCodecId()}get languageCode(){return this._backing.getLanguageCode()}get name(){return this._backing.getName()}get timeResolution(){return this._backing.getTimeResolution()}get disposition(){return this._backing.getDisposition()}getFirstTimestamp(){return this._backing.getFirstTimestamp()}computeDuration(){return this._backing.computeDuration()}async computePacketStats(e=1/0){let t=new ow(this),n=1/0,r=-1/0,i=0,a=0;for await(let o of t.packets(void 0,void 0,{metadataOnly:!0})){if(i>=e&&o.timestamp>=r)break;n=Math.min(n,o.timestamp),r=Math.max(r,o.timestamp+o.duration),i++,a+=o.byteLength}return{packetCount:i,averagePacketRate:i?Number((i/(r-n)).toPrecision(16)):0,averageBitrate:i?Number((8*a/(r-n)).toPrecision(16)):0}}},yw=class extends vw{constructor(e,t){super(e,t),this._backing=t,this.pixelAspectRatio=Px({num:this._backing.getSquarePixelWidth()*this._backing.getCodedHeight(),den:this._backing.getSquarePixelHeight()*this._backing.getCodedWidth()})}get type(){return`video`}get codec(){return this._backing.getCodec()}get codedWidth(){return this._backing.getCodedWidth()}get codedHeight(){return this._backing.getCodedHeight()}get rotation(){return this._backing.getRotation()}get squarePixelWidth(){return this._backing.getSquarePixelWidth()}get squarePixelHeight(){return this._backing.getSquarePixelHeight()}get displayWidth(){return this._backing.getRotation()%180==0?this.squarePixelWidth:this.squarePixelHeight}get displayHeight(){return this._backing.getRotation()%180==0?this.squarePixelHeight:this.squarePixelWidth}getColorSpace(){return this._backing.getColorSpace()}async hasHighDynamicRange(){let e=await this._backing.getColorSpace();return e.primaries===`bt2020`||e.primaries===`smpte432`||e.transfer===`pg`||e.transfer===`hlg`||e.matrix===`bt2020-ncl`}canBeTransparent(){return this._backing.canBeTransparent()}getDecoderConfig(){return this._backing.getDecoderConfig()}async getCodecParameterString(){return(await this._backing.getDecoderConfig())?.codec??null}async canDecode(){try{let e=await this._backing.getDecoderConfig();if(!e)return!1;let t=this._backing.getCodec();return J(t!==null),EC.some(n=>n.supports(t,e))?!0:typeof VideoDecoder>`u`?!1:(await VideoDecoder.isConfigSupported(e)).supported===!0}catch(e){return console.error(`Error during decodability check:`,e),!1}}async determinePacketType(e){if(!(e instanceof jC))throw TypeError(`packet must be an EncodedPacket.`);if(e.isMetadataOnly)throw TypeError(`packet must not be metadata-only to determine its type.`);if(this.codec===null)return null;let t=await this.getDecoderConfig();return J(t),pC(this.codec,t,e.data)}},bw=class extends vw{constructor(e,t){super(e,t),this._backing=t}get type(){return`audio`}get codec(){return this._backing.getCodec()}get numberOfChannels(){return this._backing.getNumberOfChannels()}get sampleRate(){return this._backing.getSampleRate()}getDecoderConfig(){return this._backing.getDecoderConfig()}async getCodecParameterString(){return(await this._backing.getDecoderConfig())?.codec??null}async canDecode(){try{let e=await this._backing.getDecoderConfig();if(!e)return!1;let t=this._backing.getCodec();return J(t!==null),DC.some(n=>n.supports(t,e))||e.codec.startsWith(`pcm-`)?!0:typeof AudioDecoder>`u`?!1:(await AudioDecoder.isConfigSupported(e)).supported===!0}catch(e){return console.error(`Error during decodability check:`,e),!1}}async determinePacketType(e){if(!(e instanceof jC))throw TypeError(`packet must be an EncodedPacket.`);return this.codec===null?null:`key`}},xw=e=>{let t=(e.hasVideo?`video/`:e.hasAudio?`audio/`:`application/`)+(e.isQuickTime?`quicktime`:`mp4`);if(e.codecStrings.length>0){let n=[...new Set(e.codecStrings)];t+=`; codecs="${n.join(`, `)}"`}return t},Sw=e=>{let t=Z(e),n=XE(e,4),r=8;t===1&&(t=GE(e),r=16);let i=t-r;return i<0?null:{name:n,totalSize:t,headerSize:r,contentSize:i}},Cw=e=>HE(e)/65536,ww=e=>HE(e)/1073741824,Tw=e=>{let t=0;for(let n=0;n<4;n++){t<<=7;let n=FE(e);if(t|=n&127,!(n&128))break}return t},Ew=e=>{let t=LE(e);return e.skip(2),t=Math.min(t,e.remainingLength),Nb.decode(PE(e,t))},Dw=e=>{let t=Sw(e);if(!t||t.name!==`data`||e.remainingLength<8)return null;let n=Z(e);e.skip(4);let r=PE(e,t.contentSize-8);switch(n){case 1:return Nb.decode(r);case 2:return new TextDecoder(`utf-16be`).decode(r);case 13:return new Ix(r,`image/jpeg`);case 14:return new Ix(r,`image/png`);case 27:return new Ix(r,`image/bmp`);default:return r}},Ow=class extends TC{constructor(e){super(e),this.moovSlice=null,this.currentTrack=null,this.tracks=[],this.metadataPromise=null,this.movieTimescale=-1,this.movieDurationInTimescale=-1,this.isQuickTime=!1,this.metadataTags={},this.currentMetadataKeys=null,this.isFragmented=!1,this.fragmentTrackDefaults=[],this.currentFragment=null,this.lastReadFragment=null,this.reader=e._reader}async computeDuration(){let e=await this.getTracks(),t=await Promise.all(e.map(e=>e.computeDuration()));return Math.max(0,...t)}async getTracks(){return await this.readMetadata(),this.tracks.map(e=>e.inputTrack)}async getMimeType(){await this.readMetadata();let e=await Promise.all(this.tracks.map(e=>e.inputTrack.getCodecParameterString()));return xw({isQuickTime:this.isQuickTime,hasVideo:this.tracks.some(e=>e.info?.type===`video`),hasAudio:this.tracks.some(e=>e.info?.type===`audio`),codecStrings:e.filter(Boolean)})}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}readMetadata(){return this.metadataPromise??=(async()=>{let e=0;for(;;){let t=this.reader.requestSliceRange(e,8,16);if(t instanceof Promise&&(t=await t),!t)break;let n=e,r=Sw(t);if(!r)break;if(r.name===`ftyp`)this.isQuickTime=XE(t,4)===`qt `;else if(r.name===`moov`){let e=this.reader.requestSlice(t.filePos,r.contentSize);if(e instanceof Promise&&(e=await e),!e)break;this.moovSlice=e,this.readContiguousBoxes(this.moovSlice),this.tracks.sort((e,t)=>Number(t.disposition.default)-Number(e.disposition.default));for(let e of this.tracks){let t=e.editListPreviousSegmentDurations/this.movieTimescale;e.editListOffset-=Math.round(t*e.timescale)}break}e=n+r.totalSize}if(this.isFragmented&&this.reader.fileSize!==null){let e=this.reader.requestSlice(this.reader.fileSize-4,4);e instanceof Promise&&(e=await e),J(e);let t=Z(e),n=this.reader.fileSize-t;if(n>=0&&n<=this.reader.fileSize-16){let e=this.reader.requestSliceRange(n,8,16);if(e instanceof Promise&&(e=await e),e){let t=Sw(e);if(t&&t.name===`mfra`){let n=this.reader.requestSlice(e.filePos,t.contentSize);n instanceof Promise&&(n=await n),n&&this.readContiguousBoxes(n)}}}}})()}getSampleTableForTrack(e){if(e.sampleTable)return e.sampleTable;let t={sampleTimingEntries:[],sampleCompositionTimeOffsets:[],sampleSizes:[],keySampleIndices:null,chunkOffsets:[],sampleToChunk:[],presentationTimestamps:null,presentationTimestampIndexMap:null};e.sampleTable=t,J(this.moovSlice);let n=this.moovSlice.slice(e.sampleTableByteOffset);if(this.currentTrack=e,this.traverseBox(n),this.currentTrack=null,e.info?.type===`audio`&&e.info.codec&&qx.includes(e.info.codec)&&t.sampleCompositionTimeOffsets.length===0){J(e.info?.type===`audio`);let n=uS(e.info.codec),r=[],i=[];for(let a=0;a<t.sampleToChunk.length;a++){let o=t.sampleToChunk[a],s=t.sampleToChunk[a+1],c=(s?s.startChunkIndex:t.chunkOffsets.length)-o.startChunkIndex;for(let a=0;a<c;a++){let s=o.startSampleIndex+a*o.samplesPerChunk,c=s+o.samplesPerChunk,l=Jb(t.sampleTimingEntries,s,e=>e.startIndex),u=t.sampleTimingEntries[l],d=Jb(t.sampleTimingEntries,c,e=>e.startIndex),f=t.sampleTimingEntries[d],p=u.startDecodeTimestamp+(s-u.startIndex)*u.delta,m=f.startDecodeTimestamp+(c-f.startIndex)*f.delta-p,h=Ob(r);h&&h.delta===m?h.count++:r.push({startIndex:o.startChunkIndex+a,startDecodeTimestamp:p,count:1,delta:m});let g=o.samplesPerChunk*n.sampleSize*e.info.numberOfChannels;i.push(g)}o.startSampleIndex=o.startChunkIndex,o.samplesPerChunk=1}t.sampleTimingEntries=r,t.sampleSizes=i}if(t.sampleCompositionTimeOffsets.length>0){t.presentationTimestamps=[];for(let e of t.sampleTimingEntries)for(let n=0;n<e.count;n++)t.presentationTimestamps.push({presentationTimestamp:e.startDecodeTimestamp+n*e.delta,sampleIndex:e.startIndex+n});for(let e of t.sampleCompositionTimeOffsets)for(let n=0;n<e.count;n++){let r=e.startIndex+n,i=t.presentationTimestamps[r];i&&(i.presentationTimestamp+=e.offset)}t.presentationTimestamps.sort((e,t)=>e.presentationTimestamp-t.presentationTimestamp),t.presentationTimestampIndexMap=Array(t.presentationTimestamps.length).fill(-1);for(let e=0;e<t.presentationTimestamps.length;e++)t.presentationTimestampIndexMap[t.presentationTimestamps[e].sampleIndex]=e}return t}async readFragment(e){if(this.lastReadFragment?.moofOffset===e)return this.lastReadFragment;let t=this.reader.requestSliceRange(e,8,16);t instanceof Promise&&(t=await t),J(t);let n=Sw(t);J(n?.name===`moof`);let r=this.reader.requestSlice(e,n.totalSize);r instanceof Promise&&(r=await r),J(r),this.traverseBox(r);let i=this.lastReadFragment;J(i&&i.moofOffset===e);for(let[,e]of i.trackData){let t=e.track,{fragmentPositionCache:n}=t;if(!e.startTimestampIsFinal){let r=t.fragmentLookupTable.find(e=>e.moofOffset===i.moofOffset);if(r)Iw(e,r.timestamp);else{let t=Jb(n,i.moofOffset-1,e=>e.moofOffset);if(t!==-1){let r=n[t];Iw(e,r.endTimestamp)}}e.startTimestampIsFinal=!0}let r=Jb(n,e.startTimestamp,e=>e.startTimestamp);(r===-1||n[r].moofOffset!==i.moofOffset)&&n.splice(r+1,0,{moofOffset:i.moofOffset,startTimestamp:e.startTimestamp,endTimestamp:e.endTimestamp})}return i}readContiguousBoxes(e){let t=e.filePos;for(;e.filePos-t<=e.length-8&&this.traverseBox(e););}*iterateContiguousBoxes(e){let t=e.filePos;for(;e.filePos-t<=e.length-8;){let t=e.filePos,n=Sw(e);if(!n)break;yield{boxInfo:n,slice:e},e.filePos=t+n.totalSize}}traverseBox(e){let t=e.filePos,n=Sw(e);if(!n)return!1;let r=e.filePos,i=t+n.totalSize;switch(n.name){case`mdia`:case`minf`:case`dinf`:case`mfra`:case`edts`:this.readContiguousBoxes(e.slice(r,n.contentSize));break;case`mvhd`:{let t=FE(e);e.skip(3),t===1?(e.skip(16),this.movieTimescale=Z(e),this.movieDurationInTimescale=GE(e)):(e.skip(8),this.movieTimescale=Z(e),this.movieDurationInTimescale=Z(e))}break;case`trak`:{let t={id:-1,demuxer:this,inputTrack:null,disposition:{...zx},info:null,timescale:-1,durationInMovieTimescale:-1,durationInMediaTimescale:-1,rotation:0,internalCodecId:null,name:null,languageCode:`und`,sampleTableByteOffset:-1,sampleTable:null,fragmentLookupTable:[],currentFragmentState:null,fragmentPositionCache:[],editListPreviousSegmentDurations:0,editListOffset:0};if(this.currentTrack=t,this.readContiguousBoxes(e.slice(r,n.contentSize)),t.id!==-1&&t.timescale!==-1&&t.info!==null){if(t.info.type===`video`&&t.info.width!==-1){let e=t;t.inputTrack=new yw(this.input,new Aw(e)),this.tracks.push(t)}else if(t.info.type===`audio`&&t.info.numberOfChannels!==-1){let e=t;t.inputTrack=new bw(this.input,new jw(e)),this.tracks.push(t)}}this.currentTrack=null}break;case`tkhd`:{let t=this.currentTrack;if(!t)break;let n=FE(e),r=!!(RE(e)&1);if(t.disposition.default=r,n===0)e.skip(8),t.id=Z(e),e.skip(4),t.durationInMovieTimescale=Z(e);else if(n===1)e.skip(16),t.id=Z(e),e.skip(4),t.durationInMovieTimescale=GE(e);else throw Error(`Incorrect track header version ${n}.`);e.skip(16);let i=Db(lx(Lw([Cw(e),Cw(e),ww(e),Cw(e),Cw(e),ww(e),Cw(e),Cw(e),ww(e)]),90));J(i===0||i===90||i===180||i===270),t.rotation=i}break;case`elst`:{let t=this.currentTrack;if(!t)break;let n=FE(e);e.skip(3);let r=!1,i=0,a=Z(e);for(let o=0;o<a;o++){let a=n===1?GE(e):Z(e),o=n===1?KE(e):HE(e),s=Cw(e);if(a!==0){if(r){console.warn(`Unsupported edit list: multiple edits are not currently supported. Only using first edit.`);break}if(o===-1){i+=a;continue}if(s!==1){console.warn(`Unsupported edit list entry: media rate must be 1.`);break}t.editListPreviousSegmentDurations=i,t.editListOffset=o,r=!0}}}break;case`mdhd`:{let t=this.currentTrack;if(!t)break;let n=FE(e);e.skip(3),n===0?(e.skip(8),t.timescale=Z(e),t.durationInMediaTimescale=Z(e)):n===1&&(e.skip(16),t.timescale=Z(e),t.durationInMediaTimescale=GE(e));let r=LE(e);if(r>0){t.languageCode=``;for(let e=0;e<3;e++)t.languageCode=String.fromCharCode(96+(r&31))+t.languageCode,r>>=5;px(t.languageCode)||(t.languageCode=`und`)}}break;case`hdlr`:{let t=this.currentTrack;if(!t)break;e.skip(8);let n=XE(e,4);n===`vide`?t.info={type:`video`,width:-1,height:-1,squarePixelWidth:-1,squarePixelHeight:-1,codec:null,codecDescription:null,colorSpace:null,avcType:null,avcCodecInfo:null,hevcCodecInfo:null,vp9CodecInfo:null,av1CodecInfo:null}:n===`soun`&&(t.info={type:`audio`,numberOfChannels:-1,sampleRate:-1,codec:null,codecDescription:null,aacCodecInfo:null})}break;case`stbl`:{let i=this.currentTrack;if(!i)break;i.sampleTableByteOffset=t,this.readContiguousBoxes(e.slice(r,n.contentSize))}break;case`stsd`:{let t=this.currentTrack;if(!t||t.info===null||t.sampleTable)break;let n=FE(e);e.skip(3);let r=Z(e);for(let i=0;i<r;i++){let r=e.filePos,i=Sw(e);if(!i)break;t.internalCodecId=i.name;let a=i.name.toLowerCase();if(t.info.type===`video`)a===`avc1`||a===`avc3`?(t.info.codec=`avc`,t.info.avcType=a===`avc1`?1:3):a===`hvc1`||a===`hev1`?t.info.codec=`hevc`:a===`vp08`?t.info.codec=`vp8`:a===`vp09`?t.info.codec=`vp9`:a===`av01`?t.info.codec=`av1`:console.warn(`Unsupported video codec (sample entry type '${i.name}').`),e.skip(24),t.info.width=LE(e),t.info.height=LE(e),t.info.squarePixelWidth=t.info.width,t.info.squarePixelHeight=t.info.height,e.skip(50),this.readContiguousBoxes(e.slice(e.filePos,r+i.totalSize-e.filePos));else{a===`mp4a`||(a===`opus`?t.info.codec=`opus`:a===`flac`?t.info.codec=`flac`:a===`twos`||a===`sowt`||a===`raw `||a===`in24`||a===`in32`||a===`fl32`||a===`fl64`||a===`lpcm`||a===`ipcm`||a===`fpcm`||(a===`ulaw`?t.info.codec=`ulaw`:a===`alaw`?t.info.codec=`alaw`:a===`ac-3`?t.info.codec=`ac3`:a===`ec-3`?t.info.codec=`eac3`:console.warn(`Unsupported audio codec (sample entry type '${i.name}').`))),e.skip(8);let o=LE(e);e.skip(6);let s=LE(e),c=LE(e);e.skip(4);let l=Z(e)/65536;if(n===0&&o>0){if(o===1)e.skip(4),c=8*Z(e),e.skip(8);else if(o===2){e.skip(4),l=YE(e),s=Z(e),e.skip(4),c=Z(e);let n=Z(e);if(e.skip(8),a===`lpcm`){let e=c+7>>3,r=!!(n&1),i=!!(n&2),a=n&4?-1:0;c>0&&c<=64&&(r?c===32&&(t.info.codec=i?`pcm-f32be`:`pcm-f32`):a&1<<e-1?e===1?t.info.codec=`pcm-s8`:e===2?t.info.codec=i?`pcm-s16be`:`pcm-s16`:e===3?t.info.codec=i?`pcm-s24be`:`pcm-s24`:e===4&&(t.info.codec=i?`pcm-s32be`:`pcm-s32`):e===1&&(t.info.codec=`pcm-u8`)),t.info.codec===null&&console.warn(`Unsupported PCM format.`)}}}t.info.codec===`opus`&&(l=cS),t.info.numberOfChannels=s,t.info.sampleRate=l,a===`twos`?c===8?t.info.codec=`pcm-s8`:c===16?t.info.codec=`pcm-s16be`:(console.warn(`Unsupported sample size ${c} for codec 'twos'.`),t.info.codec=null):a===`sowt`?c===8?t.info.codec=`pcm-s8`:c===16?t.info.codec=`pcm-s16`:(console.warn(`Unsupported sample size ${c} for codec 'sowt'.`),t.info.codec=null):a===`raw `?t.info.codec=`pcm-u8`:a===`in24`?t.info.codec=`pcm-s24be`:a===`in32`?t.info.codec=`pcm-s32be`:a===`fl32`?t.info.codec=`pcm-f32be`:a===`fl64`?t.info.codec=`pcm-f64be`:a===`ipcm`?t.info.codec=`pcm-s16be`:a===`fpcm`&&(t.info.codec=`pcm-f32be`),this.readContiguousBoxes(e.slice(e.filePos,r+i.totalSize-e.filePos))}}}break;case`avcC`:{let t=this.currentTrack;if(!t)break;J(t.info),t.info.codecDescription=PE(e,n.contentSize)}break;case`hvcC`:{let t=this.currentTrack;if(!t)break;J(t.info),t.info.codecDescription=PE(e,n.contentSize)}break;case`vpcC`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`video`),e.skip(4);let n=FE(e),r=FE(e),i=FE(e),a=i>>4,o=i>>1&7,s=i&1,c=FE(e),l=FE(e),u=FE(e);t.info.vp9CodecInfo={profile:n,level:r,bitDepth:a,chromaSubsampling:o,videoFullRangeFlag:s,colourPrimaries:c,transferCharacteristics:l,matrixCoefficients:u}}break;case`av1C`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`video`),e.skip(1);let n=FE(e),r=n>>5,i=n&31,a=FE(e),o=a>>7,s=a>>6&1,c=a>>5&1,l=a>>4&1,u=a>>3&1,d=a>>2&1,f=a&3,p=r===2&&s?c?12:10:s?10:8;t.info.av1CodecInfo={profile:r,level:i,tier:o,bitDepth:p,monochrome:l,chromaSubsamplingX:u,chromaSubsamplingY:d,chromaSamplePosition:f}}break;case`colr`:{let t=this.currentTrack;if(!t||(J(t.info?.type===`video`),XE(e,4)!==`nclx`))break;let n=LE(e),r=LE(e),i=LE(e),a=!!(FE(e)&128);t.info.colorSpace={primaries:Lb[n],transfer:zb[r],matrix:Vb[i],fullRange:a}}break;case`pasp`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`video`);let n=Z(e),r=Z(e);n>r?t.info.squarePixelWidth=Math.round(t.info.width*n/r):t.info.squarePixelHeight=Math.round(t.info.height*r/n)}break;case`wave`:this.readContiguousBoxes(e.slice(r,n.contentSize));break;case`esds`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`),e.skip(4),J(FE(e)===3),Tw(e),e.skip(2);let n=FE(e),r=(n&128)!=0,i=(n&64)!=0,a=(n&32)!=0;if(r&&e.skip(2),i){let t=FE(e);e.skip(t)}a&&e.skip(2),J(FE(e)===4);let o=Tw(e),s=e.filePos,c=FE(e);if(c===64||c===103?(t.info.codec=`aac`,t.info.aacCodecInfo={isMpeg2:c===103,objectType:null}):c===105||c===107?t.info.codec=`mp3`:c===221?t.info.codec=`vorbis`:console.warn(`Unsupported audio codec (objectTypeIndication ${c}) - discarding track.`),e.skip(12),o>e.filePos-s){J(FE(e)===5);let n=Tw(e);if(t.info.codecDescription=PE(e,n),t.info.codec===`aac`){let e=Wx(t.info.codecDescription);e.numberOfChannels!==null&&(t.info.numberOfChannels=e.numberOfChannels),e.sampleRate!==null&&(t.info.sampleRate=e.sampleRate)}}}break;case`enda`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`),LE(e)&255&&(t.info.codec===`pcm-s16be`?t.info.codec=`pcm-s16`:t.info.codec===`pcm-s24be`?t.info.codec=`pcm-s24`:t.info.codec===`pcm-s32be`?t.info.codec=`pcm-s32`:t.info.codec===`pcm-f32be`?t.info.codec=`pcm-f32`:t.info.codec===`pcm-f64be`&&(t.info.codec=`pcm-f64`))}break;case`pcmC`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`),e.skip(4);let n=!!(FE(e)&1),r=FE(e);t.info.codec===`pcm-s16be`?n?r===16?t.info.codec=`pcm-s16`:r===24?t.info.codec=`pcm-s24`:r===32?t.info.codec=`pcm-s32`:(console.warn(`Invalid ipcm sample size ${r}.`),t.info.codec=null):r===16?t.info.codec=`pcm-s16be`:r===24?t.info.codec=`pcm-s24be`:r===32?t.info.codec=`pcm-s32be`:(console.warn(`Invalid ipcm sample size ${r}.`),t.info.codec=null):t.info.codec===`pcm-f32be`&&(n?r===32?t.info.codec=`pcm-f32`:r===64?t.info.codec=`pcm-f64`:(console.warn(`Invalid fpcm sample size ${r}.`),t.info.codec=null):r===32?t.info.codec=`pcm-f32be`:r===64?t.info.codec=`pcm-f64be`:(console.warn(`Invalid fpcm sample size ${r}.`),t.info.codec=null));break}case`dOps`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`),e.skip(1);let n=FE(e),r=LE(e),i=Z(e),a=zE(e),o=FE(e),s;s=o===0?new Uint8Array:PE(e,2+n);let c=new Uint8Array(19+s.byteLength),l=new DataView(c.buffer);l.setUint32(0,1332770163,!1),l.setUint32(4,1214603620,!1),l.setUint8(8,1),l.setUint8(9,n),l.setUint16(10,r,!0),l.setUint32(12,i,!0),l.setInt16(16,a,!0),l.setUint8(18,o),c.set(s,19),t.info.codecDescription=c,t.info.numberOfChannels=n}break;case`dfLa`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`),e.skip(4);let n=e.filePos;for(;e.filePos<i;){let n=FE(e),r=RE(e);if((n&127)===mC.STREAMINFO){e.skip(10);let n=Z(e),r=n>>>12,i=(n>>9&7)+1;t.info.sampleRate=r,t.info.numberOfChannels=i,e.skip(20)}else e.skip(r);if(n&128)break}let r=e.filePos;e.filePos=n;let a=PE(e,r-n),o=new Uint8Array(4+a.byteLength);new DataView(o.buffer).setUint32(0,1716281667,!1),o.set(a,4),t.info.codecDescription=o}break;case`dac3`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`);let n=new Vx(PE(e,3)),r=n.readBits(2);n.skipBits(8);let i=n.readBits(3),a=n.readBits(1);r<3&&(t.info.sampleRate=kS[r]),t.info.numberOfChannels=gC[i]+a}break;case`dec3`:{let t=this.currentTrack;if(!t)break;J(t.info?.type===`audio`);let r=SC(PE(e,n.contentSize));if(!r){console.warn(`Invalid dec3 box contents, ignoring.`);break}let i=CC(r);i!==null&&(t.info.sampleRate=i),t.info.numberOfChannels=wC(r)}break;case`stts`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4);let n=Z(e),r=0,i=0;for(let a=0;a<n;a++){let n=Z(e),a=Z(e);t.sampleTable.sampleTimingEntries.push({startIndex:r,startDecodeTimestamp:i,count:n,delta:a}),r+=n,i+=n*a}}break;case`ctts`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4);let n=Z(e),r=0;for(let i=0;i<n;i++){let n=Z(e),i=HE(e);t.sampleTable.sampleCompositionTimeOffsets.push({startIndex:r,count:n,offset:i}),r+=n}}break;case`stsz`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4);let n=Z(e),r=Z(e);if(n===0)for(let n=0;n<r;n++){let n=Z(e);t.sampleTable.sampleSizes.push(n)}else t.sampleTable.sampleSizes.push(n)}break;case`stz2`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4),e.skip(3);let n=FE(e),r=Z(e),i=new Vx(PE(e,Math.ceil(r*n/8)));for(let e=0;e<r;e++){let e=i.readBits(n);t.sampleTable.sampleSizes.push(e)}}break;case`stss`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4),t.sampleTable.keySampleIndices=[];let n=Z(e);for(let r=0;r<n;r++){let n=Z(e)-1;t.sampleTable.keySampleIndices.push(n)}t.sampleTable.keySampleIndices[0]!==0&&t.sampleTable.keySampleIndices.unshift(0)}break;case`stsc`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4);let n=Z(e);for(let r=0;r<n;r++){let n=Z(e)-1,r=Z(e),i=Z(e);t.sampleTable.sampleToChunk.push({startSampleIndex:-1,startChunkIndex:n,samplesPerChunk:r,sampleDescriptionIndex:i})}let r=0;for(let e=0;e<t.sampleTable.sampleToChunk.length;e++)if(t.sampleTable.sampleToChunk[e].startSampleIndex=r,e<t.sampleTable.sampleToChunk.length-1){let n=t.sampleTable.sampleToChunk[e+1].startChunkIndex-t.sampleTable.sampleToChunk[e].startChunkIndex;r+=n*t.sampleTable.sampleToChunk[e].samplesPerChunk}}break;case`stco`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4);let n=Z(e);for(let r=0;r<n;r++){let n=Z(e);t.sampleTable.chunkOffsets.push(n)}}break;case`co64`:{let t=this.currentTrack;if(!t||!t.sampleTable)break;e.skip(4);let n=Z(e);for(let r=0;r<n;r++){let n=GE(e);t.sampleTable.chunkOffsets.push(n)}}break;case`mvex`:this.isFragmented=!0,this.readContiguousBoxes(e.slice(r,n.contentSize));break;case`mehd`:{let t=FE(e);e.skip(3),this.movieDurationInTimescale=t===1?GE(e):Z(e)}break;case`trex`:{e.skip(4);let t=Z(e),n=Z(e),r=Z(e),i=Z(e),a=Z(e);this.fragmentTrackDefaults.push({trackId:t,defaultSampleDescriptionIndex:n,defaultSampleDuration:r,defaultSampleSize:i,defaultSampleFlags:a})}break;case`tfra`:{let t=FE(e);e.skip(3);let n=Z(e),r=this.tracks.find(e=>e.id===n);if(!r)break;let i=Z(e),a=(i&48)>>4,o=(i&12)>>2,s=i&3,c=[FE,LE,RE,Z],l=c[a],u=c[o],d=c[s],f=Z(e);for(let n=0;n<f;n++){let n=t===1?GE(e):Z(e),i=t===1?GE(e):Z(e);l(e),u(e),d(e),r.fragmentLookupTable.push({timestamp:n,moofOffset:i})}r.fragmentLookupTable.sort((e,t)=>e.timestamp-t.timestamp);for(let e=0;e<r.fragmentLookupTable.length-1;e++){let t=r.fragmentLookupTable[e],n=r.fragmentLookupTable[e+1];t.timestamp===n.timestamp&&(r.fragmentLookupTable.splice(e+1,1),e--)}}break;case`moof`:this.currentFragment={moofOffset:t,moofSize:n.totalSize,implicitBaseDataOffset:t,trackData:new Map},this.readContiguousBoxes(e.slice(r,n.contentSize)),this.lastReadFragment=this.currentFragment,this.currentFragment=null;break;case`traf`:if(J(this.currentFragment),this.readContiguousBoxes(e.slice(r,n.contentSize)),this.currentTrack){let e=this.currentFragment.trackData.get(this.currentTrack.id);if(e){let{currentFragmentState:t}=this.currentTrack;J(t),t.startTimestamp!==null&&(Iw(e,t.startTimestamp),e.startTimestampIsFinal=!0)}this.currentTrack.currentFragmentState=null,this.currentTrack=null}break;case`tfhd`:{J(this.currentFragment),e.skip(1);let t=RE(e),n=!!(t&1),r=!!(t&2),i=!!(t&8),a=!!(t&16),o=!!(t&32),s=!!(t&65536),c=!!(t&131072),l=Z(e),u=this.tracks.find(e=>e.id===l);if(!u)break;let d=this.fragmentTrackDefaults.find(e=>e.trackId===l);this.currentTrack=u,u.currentFragmentState={baseDataOffset:this.currentFragment.implicitBaseDataOffset,sampleDescriptionIndex:d?.defaultSampleDescriptionIndex??null,defaultSampleDuration:d?.defaultSampleDuration??null,defaultSampleSize:d?.defaultSampleSize??null,defaultSampleFlags:d?.defaultSampleFlags??null,startTimestamp:null},n?u.currentFragmentState.baseDataOffset=GE(e):c&&(u.currentFragmentState.baseDataOffset=this.currentFragment.moofOffset),r&&(u.currentFragmentState.sampleDescriptionIndex=Z(e)),i&&(u.currentFragmentState.defaultSampleDuration=Z(e)),a&&(u.currentFragmentState.defaultSampleSize=Z(e)),o&&(u.currentFragmentState.defaultSampleFlags=Z(e)),s&&(u.currentFragmentState.defaultSampleDuration=0)}break;case`tfdt`:{let t=this.currentTrack;if(!t)break;J(t.currentFragmentState);let n=FE(e);e.skip(3);let r=n===0?Z(e):GE(e);t.currentFragmentState.startTimestamp=r}break;case`trun`:{let t=this.currentTrack;if(!t)break;if(J(this.currentFragment),J(t.currentFragmentState),this.currentFragment.trackData.has(t.id)){console.warn(`Can't have two trun boxes for the same track in one fragment. Ignoring...`);break}let n=FE(e),r=RE(e),i=!!(r&1),a=!!(r&4),o=!!(r&256),s=!!(r&512),c=!!(r&1024),l=!!(r&2048),u=Z(e),d=t.currentFragmentState.baseDataOffset;i&&(d+=HE(e));let f=null;a&&(f=Z(e));let p=d;if(u===0){this.currentFragment.implicitBaseDataOffset=p;break}let m=0,h={track:t,startTimestamp:0,endTimestamp:0,firstKeyFrameTimestamp:null,samples:[],presentationTimestamps:[],startTimestampIsFinal:!1};this.currentFragment.trackData.set(t.id,h);for(let r=0;r<u;r++){let i;o?i=Z(e):(J(t.currentFragmentState.defaultSampleDuration!==null),i=t.currentFragmentState.defaultSampleDuration);let a;s?a=Z(e):(J(t.currentFragmentState.defaultSampleSize!==null),a=t.currentFragmentState.defaultSampleSize);let u;c?u=Z(e):(J(t.currentFragmentState.defaultSampleFlags!==null),u=t.currentFragmentState.defaultSampleFlags),r===0&&f!==null&&(u=f);let d=0;l&&(d=n===0?Z(e):HE(e));let g=!(u&65536);h.samples.push({presentationTimestamp:m+d,duration:i,byteOffset:p,byteSize:a,isKeyFrame:g}),p+=a,m+=i}h.presentationTimestamps=h.samples.map((e,t)=>({presentationTimestamp:e.presentationTimestamp,sampleIndex:t})).sort((e,t)=>e.presentationTimestamp-t.presentationTimestamp);for(let e=0;e<h.presentationTimestamps.length;e++){let t=h.presentationTimestamps[e],n=h.samples[t.sampleIndex];h.firstKeyFrameTimestamp===null&&n.isKeyFrame&&(h.firstKeyFrameTimestamp=n.presentationTimestamp),e<h.presentationTimestamps.length-1&&(n.duration=h.presentationTimestamps[e+1].presentationTimestamp-t.presentationTimestamp)}let g=h.samples[h.presentationTimestamps[0].sampleIndex],_=h.samples[Ob(h.presentationTimestamps).sampleIndex];h.startTimestamp=g.presentationTimestamp,h.endTimestamp=_.presentationTimestamp+_.duration,this.currentFragment.implicitBaseDataOffset=p}break;case`udta`:{let t=this.iterateContiguousBoxes(e.slice(r,n.contentSize));for(let{boxInfo:e,slice:n}of t){if(e.name!==`meta`&&!this.currentTrack){let t=n.filePos;this.metadataTags.raw??={},e.name[0]===`©`?this.metadataTags.raw[e.name]??=Ew(n):this.metadataTags.raw[e.name]??=PE(n,e.contentSize),n.filePos=t}switch(e.name){case`meta`:n.skip(-e.headerSize),this.traverseBox(n);break;case`©nam`:case`name`:this.currentTrack?this.currentTrack.name=Nb.decode(PE(n,e.contentSize)):this.metadataTags.title??=Ew(n);break;case`©des`:this.currentTrack||(this.metadataTags.description??=Ew(n));break;case`©ART`:this.currentTrack||(this.metadataTags.artist??=Ew(n));break;case`©alb`:this.currentTrack||(this.metadataTags.album??=Ew(n));break;case`albr`:this.currentTrack||(this.metadataTags.albumArtist??=Ew(n));break;case`©gen`:this.currentTrack||(this.metadataTags.genre??=Ew(n));break;case`©day`:if(!this.currentTrack){let e=new Date(Ew(n));Number.isNaN(e.getTime())||(this.metadataTags.date??=e)}break;case`©cmt`:this.currentTrack||(this.metadataTags.comment??=Ew(n));break;case`©lyr`:this.currentTrack||(this.metadataTags.lyrics??=Ew(n));break}}}break;case`meta`:{if(this.currentTrack)break;let t=Z(e)!==0;this.currentMetadataKeys=new Map,t?this.readContiguousBoxes(e.slice(r,n.contentSize)):this.readContiguousBoxes(e.slice(r+4,n.contentSize-4)),this.currentMetadataKeys=null}break;case`keys`:{if(!this.currentMetadataKeys)break;e.skip(4);let t=Z(e);for(let n=0;n<t;n++){let t=Z(e);e.skip(4);let r=Nb.decode(PE(e,t-8));this.currentMetadataKeys.set(n+1,r)}}break;case`ilst`:{if(!this.currentMetadataKeys)break;let t=this.iterateContiguousBoxes(e.slice(r,n.contentSize));for(let{boxInfo:e,slice:n}of t){let t=e.name,r=(t.charCodeAt(0)<<24)+(t.charCodeAt(1)<<16)+(t.charCodeAt(2)<<8)+t.charCodeAt(3);this.currentMetadataKeys.has(r)&&(t=this.currentMetadataKeys.get(r));let i=Dw(n);switch(this.metadataTags.raw??={},this.metadataTags.raw[t]??=i,t){case`©nam`:case`titl`:case`com.apple.quicktime.title`:case`title`:typeof i==`string`&&(this.metadataTags.title??=i);break;case`©des`:case`desc`:case`dscp`:case`com.apple.quicktime.description`:case`description`:typeof i==`string`&&(this.metadataTags.description??=i);break;case`©ART`:case`com.apple.quicktime.artist`:case`artist`:typeof i==`string`&&(this.metadataTags.artist??=i);break;case`©alb`:case`albm`:case`com.apple.quicktime.album`:case`album`:typeof i==`string`&&(this.metadataTags.album??=i);break;case`aART`:case`album_artist`:typeof i==`string`&&(this.metadataTags.albumArtist??=i);break;case`©cmt`:case`com.apple.quicktime.comment`:case`comment`:typeof i==`string`&&(this.metadataTags.comment??=i);break;case`©gen`:case`gnre`:case`com.apple.quicktime.genre`:case`genre`:typeof i==`string`&&(this.metadataTags.genre??=i);break;case`©lyr`:case`lyrics`:typeof i==`string`&&(this.metadataTags.lyrics??=i);break;case`©day`:case`rldt`:case`com.apple.quicktime.creationdate`:case`date`:if(typeof i==`string`){let e=new Date(i);Number.isNaN(e.getTime())||(this.metadataTags.date??=e)}break;case`covr`:case`com.apple.quicktime.artwork`:i instanceof Ix?(this.metadataTags.images??=[],this.metadataTags.images.push({data:i.data,kind:`coverFront`,mimeType:i.mimeType})):i instanceof Uint8Array&&(this.metadataTags.images??=[],this.metadataTags.images.push({data:i,kind:`coverFront`,mimeType:`image/*`}));break;case`track`:if(typeof i==`string`){let e=i.split(`/`),t=Number.parseInt(e[0],10),n=e[1]&&Number.parseInt(e[1],10);Number.isInteger(t)&&t>0&&(this.metadataTags.trackNumber??=t),n&&Number.isInteger(n)&&n>0&&(this.metadataTags.tracksTotal??=n)}break;case`trkn`:if(i instanceof Uint8Array&&i.length>=6){let e=Mb(i),t=e.getUint16(2,!1),n=e.getUint16(4,!1);t>0&&(this.metadataTags.trackNumber??=t),n>0&&(this.metadataTags.tracksTotal??=n)}break;case`disc`:case`disk`:if(i instanceof Uint8Array&&i.length>=6){let e=Mb(i),t=e.getUint16(2,!1),n=e.getUint16(4,!1);t>0&&(this.metadataTags.discNumber??=t),n>0&&(this.metadataTags.discsTotal??=n)}break}}}break}return e.filePos=i,!0}},kw=class{constructor(e){this.internalTrack=e,this.packetToSampleIndex=new WeakMap,this.packetToFragmentLocation=new WeakMap}getId(){return this.internalTrack.id}getNumber(){let e=this.internalTrack.demuxer,t=this.internalTrack.inputTrack.type,n=0;for(let r of e.tracks)if(r.inputTrack.type===t&&n++,r===this.internalTrack)break;return n}getCodec(){throw Error(`Not implemented on base class.`)}getInternalCodecId(){return this.internalTrack.internalCodecId}getName(){return this.internalTrack.name}getLanguageCode(){return this.internalTrack.languageCode}getTimeResolution(){return this.internalTrack.timescale}getDisposition(){return this.internalTrack.disposition}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}async getFirstTimestamp(){return(await this.getFirstPacket({metadataOnly:!0}))?.timestamp??0}async getFirstPacket(e){let t=await this.fetchPacketForSampleIndex(0,e);return t||!this.internalTrack.demuxer.isFragmented?t:this.performFragmentedLookup(null,e=>e.trackData.get(this.internalTrack.id)?{sampleIndex:0,correctSampleFound:!0}:{sampleIndex:-1,correctSampleFound:!1},-1/0,1/0,e)}mapTimestampIntoTimescale(e){return cx(e*this.internalTrack.timescale)+this.internalTrack.editListOffset}async getPacket(e,t){let n=this.mapTimestampIntoTimescale(e),r=this.internalTrack.demuxer.getSampleTableForTrack(this.internalTrack),i=Mw(r,n),a=await this.fetchPacketForSampleIndex(i,t);return!Rw(r)||!this.internalTrack.demuxer.isFragmented?a:this.performFragmentedLookup(null,e=>{let t=e.trackData.get(this.internalTrack.id);if(!t)return{sampleIndex:-1,correctSampleFound:!1};let r=Jb(t.presentationTimestamps,n,e=>e.presentationTimestamp);return{sampleIndex:r===-1?-1:t.presentationTimestamps[r].sampleIndex,correctSampleFound:r!==-1&&n<t.endTimestamp}},n,n,t)}async getNextPacket(e,t){let n=this.packetToSampleIndex.get(e);if(n!==void 0)return this.fetchPacketForSampleIndex(n+1,t);let r=this.packetToFragmentLocation.get(e);if(r===void 0)throw Error(`Packet was not created from this track.`);return this.performFragmentedLookup(r.fragment,e=>{if(e===r.fragment){let t=e.trackData.get(this.internalTrack.id);if(r.sampleIndex+1<t.samples.length)return{sampleIndex:r.sampleIndex+1,correctSampleFound:!0}}else if(e.trackData.get(this.internalTrack.id))return{sampleIndex:0,correctSampleFound:!0};return{sampleIndex:-1,correctSampleFound:!1}},-1/0,1/0,t)}async getKeyPacket(e,t){let n=this.mapTimestampIntoTimescale(e),r=this.internalTrack.demuxer.getSampleTableForTrack(this.internalTrack),i=Nw(r,n),a=await this.fetchPacketForSampleIndex(i,t);return!Rw(r)||!this.internalTrack.demuxer.isFragmented?a:this.performFragmentedLookup(null,e=>{let t=e.trackData.get(this.internalTrack.id);if(!t)return{sampleIndex:-1,correctSampleFound:!1};let r=Qb(t.presentationTimestamps,e=>t.samples[e.sampleIndex].isKeyFrame&&e.presentationTimestamp<=n);return{sampleIndex:r===-1?-1:t.presentationTimestamps[r].sampleIndex,correctSampleFound:r!==-1&&n<t.endTimestamp}},n,n,t)}async getNextKeyPacket(e,t){let n=this.packetToSampleIndex.get(e);if(n!==void 0){let e=Fw(this.internalTrack.demuxer.getSampleTableForTrack(this.internalTrack),n);return this.fetchPacketForSampleIndex(e,t)}let r=this.packetToFragmentLocation.get(e);if(r===void 0)throw Error(`Packet was not created from this track.`);return this.performFragmentedLookup(r.fragment,e=>{if(e===r.fragment){let t=e.trackData.get(this.internalTrack.id).samples.findIndex((e,t)=>e.isKeyFrame&&t>r.sampleIndex);if(t!==-1)return{sampleIndex:t,correctSampleFound:!0}}else{let t=e.trackData.get(this.internalTrack.id);if(t&&t.firstKeyFrameTimestamp!==null){let e=t.samples.findIndex(e=>e.isKeyFrame);return J(e!==-1),{sampleIndex:e,correctSampleFound:!0}}}return{sampleIndex:-1,correctSampleFound:!1}},-1/0,1/0,t)}async fetchPacketForSampleIndex(e,t){if(e===-1)return null;let n=Pw(this.internalTrack.demuxer.getSampleTableForTrack(this.internalTrack),e);if(!n)return null;let r;if(t.metadataOnly)r=AC;else{let e=this.internalTrack.demuxer.reader.requestSlice(n.sampleOffset,n.sampleSize);e instanceof Promise&&(e=await e),J(e),r=PE(e,n.sampleSize)}let i=(n.presentationTimestamp-this.internalTrack.editListOffset)/this.internalTrack.timescale,a=n.duration/this.internalTrack.timescale,o=new jC(r,n.isKeyFrame?`key`:`delta`,i,a,e,n.sampleSize);return this.packetToSampleIndex.set(o,e),o}async fetchPacketInFragment(e,t,n){if(t===-1)return null;let r=e.trackData.get(this.internalTrack.id).samples[t];J(r);let i;if(n.metadataOnly)i=AC;else{let e=this.internalTrack.demuxer.reader.requestSlice(r.byteOffset,r.byteSize);e instanceof Promise&&(e=await e),J(e),i=PE(e,r.byteSize)}let a=(r.presentationTimestamp-this.internalTrack.editListOffset)/this.internalTrack.timescale,o=r.duration/this.internalTrack.timescale,s=new jC(i,r.isKeyFrame?`key`:`delta`,a,o,e.moofOffset+t,r.byteSize);return this.packetToFragmentLocation.set(s,{fragment:e,sampleIndex:t}),s}async performFragmentedLookup(e,t,n,r,i){let a=this.internalTrack.demuxer,o=null,s=null,c=-1;if(e){let{sampleIndex:n,correctSampleFound:r}=t(e);if(r)return this.fetchPacketInFragment(e,n,i);n!==-1&&(s=e,c=n)}let l=Jb(this.internalTrack.fragmentLookupTable,n,e=>e.timestamp),u=l===-1?null:this.internalTrack.fragmentLookupTable[l],d=Jb(this.internalTrack.fragmentPositionCache,n,e=>e.startTimestamp),f=d===-1?null:this.internalTrack.fragmentPositionCache[d],p=Math.max(u?.moofOffset??0,f?.moofOffset??0)||null,m;for(e?p===null||e.moofOffset>=p?(m=e.moofOffset+e.moofSize,o=e):m=p:m=p??0;;){if(o){let e=o.trackData.get(this.internalTrack.id);if(e&&e.startTimestamp>r)break}let e=a.reader.requestSliceRange(m,8,16);if(e instanceof Promise&&(e=await e),!e)break;let n=m,l=Sw(e);if(!l)break;if(l.name===`moof`){o=await a.readFragment(n);let{sampleIndex:e,correctSampleFound:r}=t(o);if(r)return this.fetchPacketInFragment(o,e,i);e!==-1&&(s=o,c=e)}m=n+l.totalSize}if(u&&(!s||s.moofOffset<u.moofOffset)){let e=this.internalTrack.fragmentLookupTable[l-1];J(!e||e.timestamp<u.timestamp);let n=e?.timestamp??-1/0;return this.performFragmentedLookup(null,t,n,r,i)}return s?this.fetchPacketInFragment(s,c,i):null}},Aw=class extends kw{constructor(e){super(e),this.decoderConfigPromise=null,this.internalTrack=e}getCodec(){return this.internalTrack.info.codec}getCodedWidth(){return this.internalTrack.info.width}getCodedHeight(){return this.internalTrack.info.height}getSquarePixelWidth(){return this.internalTrack.info.squarePixelWidth}getSquarePixelHeight(){return this.internalTrack.info.squarePixelHeight}getRotation(){return this.internalTrack.rotation}async getColorSpace(){return{primaries:this.internalTrack.info.colorSpace?.primaries,transfer:this.internalTrack.info.colorSpace?.transfer,matrix:this.internalTrack.info.colorSpace?.matrix,fullRange:this.internalTrack.info.colorSpace?.fullRange}}async canBeTransparent(){return!1}async getDecoderConfig(){return this.internalTrack.info.codec?this.decoderConfigPromise??=(async()=>{if(this.internalTrack.info.codec===`vp9`&&!this.internalTrack.info.vp9CodecInfo){let e=await this.getFirstPacket({});this.internalTrack.info.vp9CodecInfo=e&&oC(e.data)}else if(this.internalTrack.info.codec===`av1`&&!this.internalTrack.info.av1CodecInfo){let e=await this.getFirstPacket({});this.internalTrack.info.av1CodecInfo=e&&cC(e.data)}return{codec:aS(this.internalTrack.info),codedWidth:this.internalTrack.info.width,codedHeight:this.internalTrack.info.height,displayAspectWidth:this.internalTrack.info.squarePixelWidth,displayAspectHeight:this.internalTrack.info.squarePixelHeight,description:this.internalTrack.info.codecDescription??void 0,colorSpace:this.internalTrack.info.colorSpace??void 0}})():null}},jw=class extends kw{constructor(e){super(e),this.decoderConfig=null,this.internalTrack=e}getCodec(){return this.internalTrack.info.codec}getNumberOfChannels(){return this.internalTrack.info.numberOfChannels}getSampleRate(){return this.internalTrack.info.sampleRate}async getDecoderConfig(){return this.internalTrack.info.codec?this.decoderConfig??={codec:sS(this.internalTrack.info),numberOfChannels:this.internalTrack.info.numberOfChannels,sampleRate:this.internalTrack.info.sampleRate,description:this.internalTrack.info.codecDescription??void 0}:null}},Mw=(e,t)=>{if(e.presentationTimestamps){let n=Jb(e.presentationTimestamps,t,e=>e.presentationTimestamp);return n===-1?-1:e.presentationTimestamps[n].sampleIndex}else{let n=Jb(e.sampleTimingEntries,t,e=>e.startDecodeTimestamp);if(n===-1)return-1;let r=e.sampleTimingEntries[n];return r.startIndex+Math.min(Math.floor((t-r.startDecodeTimestamp)/r.delta),r.count-1)}},Nw=(e,t)=>{if(!e.keySampleIndices)return Mw(e,t);if(e.presentationTimestamps){let n=Jb(e.presentationTimestamps,t,e=>e.presentationTimestamp);if(n===-1)return-1;for(let t=n;t>=0;t--){let n=e.presentationTimestamps[t].sampleIndex;if(qb(e.keySampleIndices,n,e=>e)!==-1)return n}return-1}else{let n=Mw(e,t),r=Jb(e.keySampleIndices,n,e=>e);return e.keySampleIndices[r]??-1}},Pw=(e,t)=>{let n=Jb(e.sampleTimingEntries,t,e=>e.startIndex),r=e.sampleTimingEntries[n];if(!r||r.startIndex+r.count<=t)return null;let i=r.startDecodeTimestamp+(t-r.startIndex)*r.delta,a=Jb(e.sampleCompositionTimeOffsets,t,e=>e.startIndex),o=e.sampleCompositionTimeOffsets[a];o&&t-o.startIndex<o.count&&(i+=o.offset);let s=e.sampleSizes[Math.min(t,e.sampleSizes.length-1)],c=Jb(e.sampleToChunk,t,e=>e.startSampleIndex),l=e.sampleToChunk[c];J(l);let u=l.startChunkIndex+Math.floor((t-l.startSampleIndex)/l.samplesPerChunk),d=e.chunkOffsets[u],f=l.startSampleIndex+(u-l.startChunkIndex)*l.samplesPerChunk,p=0,m=d;if(e.sampleSizes.length===1)m+=s*(t-f),p+=s*l.samplesPerChunk;else for(let n=f;n<f+l.samplesPerChunk;n++){let r=e.sampleSizes[n];n<t&&(m+=r),p+=r}let h=r.delta;if(e.presentationTimestamps){let n=e.presentationTimestampIndexMap[t];J(n!==void 0),n<e.presentationTimestamps.length-1&&(h=e.presentationTimestamps[n+1].presentationTimestamp-i)}return{presentationTimestamp:i,duration:h,sampleOffset:m,sampleSize:s,chunkOffset:d,chunkSize:p,isKeyFrame:e.keySampleIndices?qb(e.keySampleIndices,t,e=>e)!==-1:!0}},Fw=(e,t)=>{if(!e.keySampleIndices)return t+1;let n=Jb(e.keySampleIndices,t,e=>e);return e.keySampleIndices[n+1]??-1},Iw=(e,t)=>{e.startTimestamp+=t,e.endTimestamp+=t;for(let n of e.samples)n.presentationTimestamp+=t;for(let n of e.presentationTimestamps)n.presentationTimestamp+=t},Lw=e=>{let[t,,,n]=e,r=Math.hypot(t,n),i=t/r,a=n/r,o=-Math.atan2(a,i)*(180/Math.PI);return Number.isFinite(o)?o:0},Rw=e=>e.sampleSizes.length===0,X;(function(e){e[e.EBML=440786851]=`EBML`,e[e.EBMLVersion=17030]=`EBMLVersion`,e[e.EBMLReadVersion=17143]=`EBMLReadVersion`,e[e.EBMLMaxIDLength=17138]=`EBMLMaxIDLength`,e[e.EBMLMaxSizeLength=17139]=`EBMLMaxSizeLength`,e[e.DocType=17026]=`DocType`,e[e.DocTypeVersion=17031]=`DocTypeVersion`,e[e.DocTypeReadVersion=17029]=`DocTypeReadVersion`,e[e.Void=236]=`Void`,e[e.Segment=408125543]=`Segment`,e[e.SeekHead=290298740]=`SeekHead`,e[e.Seek=19899]=`Seek`,e[e.SeekID=21419]=`SeekID`,e[e.SeekPosition=21420]=`SeekPosition`,e[e.Duration=17545]=`Duration`,e[e.Info=357149030]=`Info`,e[e.TimestampScale=2807729]=`TimestampScale`,e[e.MuxingApp=19840]=`MuxingApp`,e[e.WritingApp=22337]=`WritingApp`,e[e.Tracks=374648427]=`Tracks`,e[e.TrackEntry=174]=`TrackEntry`,e[e.TrackNumber=215]=`TrackNumber`,e[e.TrackUID=29637]=`TrackUID`,e[e.TrackType=131]=`TrackType`,e[e.FlagEnabled=185]=`FlagEnabled`,e[e.FlagDefault=136]=`FlagDefault`,e[e.FlagForced=21930]=`FlagForced`,e[e.FlagOriginal=21934]=`FlagOriginal`,e[e.FlagHearingImpaired=21931]=`FlagHearingImpaired`,e[e.FlagVisualImpaired=21932]=`FlagVisualImpaired`,e[e.FlagCommentary=21935]=`FlagCommentary`,e[e.FlagLacing=156]=`FlagLacing`,e[e.Name=21358]=`Name`,e[e.Language=2274716]=`Language`,e[e.LanguageBCP47=2274717]=`LanguageBCP47`,e[e.CodecID=134]=`CodecID`,e[e.CodecPrivate=25506]=`CodecPrivate`,e[e.CodecDelay=22186]=`CodecDelay`,e[e.SeekPreRoll=22203]=`SeekPreRoll`,e[e.DefaultDuration=2352003]=`DefaultDuration`,e[e.Video=224]=`Video`,e[e.PixelWidth=176]=`PixelWidth`,e[e.PixelHeight=186]=`PixelHeight`,e[e.DisplayWidth=21680]=`DisplayWidth`,e[e.DisplayHeight=21690]=`DisplayHeight`,e[e.DisplayUnit=21682]=`DisplayUnit`,e[e.AlphaMode=21440]=`AlphaMode`,e[e.Audio=225]=`Audio`,e[e.SamplingFrequency=181]=`SamplingFrequency`,e[e.Channels=159]=`Channels`,e[e.BitDepth=25188]=`BitDepth`,e[e.SimpleBlock=163]=`SimpleBlock`,e[e.BlockGroup=160]=`BlockGroup`,e[e.Block=161]=`Block`,e[e.BlockAdditions=30113]=`BlockAdditions`,e[e.BlockMore=166]=`BlockMore`,e[e.BlockAdditional=165]=`BlockAdditional`,e[e.BlockAddID=238]=`BlockAddID`,e[e.BlockDuration=155]=`BlockDuration`,e[e.ReferenceBlock=251]=`ReferenceBlock`,e[e.Cluster=524531317]=`Cluster`,e[e.Timestamp=231]=`Timestamp`,e[e.Cues=475249515]=`Cues`,e[e.CuePoint=187]=`CuePoint`,e[e.CueTime=179]=`CueTime`,e[e.CueTrackPositions=183]=`CueTrackPositions`,e[e.CueTrack=247]=`CueTrack`,e[e.CueClusterPosition=241]=`CueClusterPosition`,e[e.Colour=21936]=`Colour`,e[e.MatrixCoefficients=21937]=`MatrixCoefficients`,e[e.TransferCharacteristics=21946]=`TransferCharacteristics`,e[e.Primaries=21947]=`Primaries`,e[e.Range=21945]=`Range`,e[e.Projection=30320]=`Projection`,e[e.ProjectionType=30321]=`ProjectionType`,e[e.ProjectionPoseRoll=30325]=`ProjectionPoseRoll`,e[e.Attachments=423732329]=`Attachments`,e[e.AttachedFile=24999]=`AttachedFile`,e[e.FileDescription=18046]=`FileDescription`,e[e.FileName=18030]=`FileName`,e[e.FileMediaType=18016]=`FileMediaType`,e[e.FileData=18012]=`FileData`,e[e.FileUID=18094]=`FileUID`,e[e.Chapters=272869232]=`Chapters`,e[e.Tags=307544935]=`Tags`,e[e.Tag=29555]=`Tag`,e[e.Targets=25536]=`Targets`,e[e.TargetTypeValue=26826]=`TargetTypeValue`,e[e.TargetType=25546]=`TargetType`,e[e.TagTrackUID=25541]=`TagTrackUID`,e[e.TagEditionUID=25545]=`TagEditionUID`,e[e.TagChapterUID=25540]=`TagChapterUID`,e[e.TagAttachmentUID=25542]=`TagAttachmentUID`,e[e.SimpleTag=26568]=`SimpleTag`,e[e.TagName=17827]=`TagName`,e[e.TagLanguage=17530]=`TagLanguage`,e[e.TagString=17543]=`TagString`,e[e.TagBinary=17541]=`TagBinary`,e[e.ContentEncodings=28032]=`ContentEncodings`,e[e.ContentEncoding=25152]=`ContentEncoding`,e[e.ContentEncodingOrder=20529]=`ContentEncodingOrder`,e[e.ContentEncodingScope=20530]=`ContentEncodingScope`,e[e.ContentCompression=20532]=`ContentCompression`,e[e.ContentCompAlgo=16980]=`ContentCompAlgo`,e[e.ContentCompSettings=16981]=`ContentCompSettings`,e[e.ContentEncryption=20533]=`ContentEncryption`})(X||={});var zw=[X.EBML,X.Segment],Bw=[X.SeekHead,X.Info,X.Cluster,X.Tracks,X.Cues,X.Attachments,X.Chapters,X.Tags],Vw=[...zw,...Bw],Hw=e=>{if(e.remainingLength<1)return null;let t=FE(e);if(e.skip(-1),t===0)return null;let n=1,r=128;for(;(t&r)===0;)n++,r>>=1;return e.remainingLength<n?null:n},Uw=e=>{if(e.remainingLength<1)return null;let t=FE(e);if(t===0)return null;let n=1,r=128;for(;(t&r)===0;)n++,r>>=1;if(e.remainingLength<n-1)return null;let i=t&r-1;for(let t=1;t<n;t++)i*=256,i+=FE(e);return i},Ww=(e,t)=>{if(t<1||t>8)throw Error(`Bad unsigned int size `+t);let n=0;for(let r=0;r<t;r++)n*=256,n+=FE(e);return n},Gw=(e,t)=>{if(t<1)throw Error(`Bad unsigned int size `+t);let n=0n;for(let r=0;r<t;r++)n<<=8n,n+=BigInt(FE(e));return n},Kw=e=>{let t=Hw(e);return t===null||e.remainingLength<t?null:Ww(e,t)},qw=e=>{if(e.remainingLength<1)return null;if(FE(e)===255)return;e.skip(-1);let t=Uw(e);if(t===null)return null;if(t!==72057594037927940)return t},Jw=e=>{J(e.remainingLength>=2);let t=Kw(e);if(t===null)return null;let n=qw(e);return n===null?null:{id:t,size:n}},Yw=(e,t)=>{let n=PE(e,t),r=0;for(;r<t&&n[r]!==0;)r+=1;return String.fromCharCode(...n.subarray(0,r))},Xw=(e,t)=>{let n=PE(e,t),r=0;for(;r<t&&n[r]!==0;)r+=1;return Nb.decode(n.subarray(0,r))},Zw=(e,t)=>{if(t===0)return 0;if(t!==4&&t!==8)throw Error(`Bad float size `+t);return t===4?JE(e):YE(e)},Qw=async(e,t,n,r)=>{let i=new Set(n),a=t;for(;r===null||a<r;){let t=e.requestSliceRange(a,2,16);if(t instanceof Promise&&(t=await t),!t)break;let n=Jw(t);if(!n)break;if(i.has(n.id))return{pos:a,found:!0};tT(n.size),a=t.filePos+n.size}return{pos:r!==null&&r>a?r:a,found:!1}},$w=async(e,t,n,r)=>{let i=2**16,a=new Set(n),o=t;for(;o<r;){let t=e.requestSliceRange(o,0,Math.min(i,r-o));if(t instanceof Promise&&(t=await t),!t||t.length<8)break;for(let e=0;e<t.length-8;e++){t.filePos=o;let e=Kw(t);if(e!==null&&a.has(e))return o;o++}}return null},eT={avc:`V_MPEG4/ISO/AVC`,hevc:`V_MPEGH/ISO/HEVC`,vp8:`V_VP8`,vp9:`V_VP9`,av1:`V_AV1`,aac:`A_AAC`,mp3:`A_MPEG/L3`,opus:`A_OPUS`,vorbis:`A_VORBIS`,flac:`A_FLAC`,ac3:`A_AC3`,eac3:`A_EAC3`,"pcm-u8":`A_PCM/INT/LIT`,"pcm-s16":`A_PCM/INT/LIT`,"pcm-s16be":`A_PCM/INT/BIG`,"pcm-s24":`A_PCM/INT/LIT`,"pcm-s24be":`A_PCM/INT/BIG`,"pcm-s32":`A_PCM/INT/LIT`,"pcm-s32be":`A_PCM/INT/BIG`,"pcm-f32":`A_PCM/FLOAT/IEEE`,"pcm-f64":`A_PCM/FLOAT/IEEE`,webvtt:`S_TEXT/WEBVTT`};function tT(e){if(e===void 0)throw Error(`Undefined element size is used in a place where it is not supported.`)}var nT=e=>{let t=(e.hasVideo?`video/`:e.hasAudio?`audio/`:`application/`)+(e.isWebM?`webm`:`x-matroska`);if(e.codecStrings.length>0){let n=[...new Set(e.codecStrings.filter(Boolean))];t+=`; codecs="${n.join(`, `)}"`}return t},rT;(function(e){e[e.None=0]=`None`,e[e.Xiph=1]=`Xiph`,e[e.FixedSize=2]=`FixedSize`,e[e.Ebml=3]=`Ebml`})(rT||={});var iT;(function(e){e[e.Block=1]=`Block`,e[e.Private=2]=`Private`,e[e.Next=4]=`Next`})(iT||={});var aT;(function(e){e[e.Zlib=0]=`Zlib`,e[e.Bzlib=1]=`Bzlib`,e[e.lzo1x=2]=`lzo1x`,e[e.HeaderStripping=3]=`HeaderStripping`})(aT||={});var oT=[{id:X.SeekHead,flag:`seekHeadSeen`},{id:X.Info,flag:`infoSeen`},{id:X.Tracks,flag:`tracksSeen`},{id:X.Cues,flag:`cuesSeen`}],sT=10*2**20,cT=class extends TC{constructor(e){super(e),this.readMetadataPromise=null,this.segments=[],this.currentSegment=null,this.currentTrack=null,this.currentCluster=null,this.currentBlock=null,this.currentBlockAdditional=null,this.currentCueTime=null,this.currentDecodingInstruction=null,this.currentTagTargetIsMovie=!0,this.currentSimpleTagName=null,this.currentAttachedFile=null,this.isWebM=!1,this.reader=e._reader}async computeDuration(){let e=await this.getTracks(),t=await Promise.all(e.map(e=>e.computeDuration()));return Math.max(0,...t)}async getTracks(){return await this.readMetadata(),this.segments.flatMap(e=>e.tracks.map(e=>e.inputTrack))}async getMimeType(){await this.readMetadata();let e=await this.getTracks(),t=await Promise.all(e.map(e=>e.getCodecParameterString()));return nT({isWebM:this.isWebM,hasVideo:this.segments.some(e=>e.tracks.some(e=>e.info?.type===`video`)),hasAudio:this.segments.some(e=>e.tracks.some(e=>e.info?.type===`audio`)),codecStrings:t.filter(Boolean)})}async getMetadataTags(){await this.readMetadata();for(let e of this.segments)e.metadataTagsCollected||=(this.reader.fileSize!==null&&await this.loadSegmentMetadata(e),!0);let e={};for(let t of this.segments)e={...e,...t.metadataTags};return e}readMetadata(){return this.readMetadataPromise??=(async()=>{let e=0;for(;;){let t=this.reader.requestSliceRange(e,2,16);if(t instanceof Promise&&(t=await t),!t)break;let n=Jw(t);if(!n)break;let r=n.id,i=n.size,a=t.filePos;if(r===X.EBML){tT(i);let e=this.reader.requestSlice(a,i);if(e instanceof Promise&&(e=await e),!e)break;this.readContiguousElements(e)}else if(r===X.Segment){if(await this.readSegment(a,i),i===void 0||this.reader.fileSize===null)break}else if(r===X.Cluster){if(this.reader.fileSize===null)break;i===void 0&&(i=(await Qw(this.reader,a,Vw,this.reader.fileSize)).pos-a);let e=Ob(this.segments);e&&(e.elementEndPos=a+i)}tT(i),e=a+i}})()}async readSegment(e,t){this.currentSegment={seekHeadSeen:!1,infoSeen:!1,tracksSeen:!1,cuesSeen:!1,tagsSeen:!1,attachmentsSeen:!1,timestampScale:-1,timestampFactor:-1,duration:-1,seekEntries:[],tracks:[],cuePoints:[],dataStartPos:e,elementEndPos:t===void 0?null:e+t,clusterSeekStartPos:e,lastReadCluster:null,metadataTags:{},metadataTagsCollected:!1},this.segments.push(this.currentSegment);let n=e;for(;this.currentSegment.elementEndPos===null||n<this.currentSegment.elementEndPos;){let e=this.reader.requestSliceRange(n,2,16);if(e instanceof Promise&&(e=await e),!e)break;let t=n,r=Jw(e);if(!r||!Bw.includes(r.id)&&r.id!==X.Void){let e=await $w(this.reader,t,Bw,Math.min(this.currentSegment.elementEndPos??1/0,t+sT));if(e){n=e;continue}else break}let{id:i,size:a}=r,o=e.filePos,s=oT.findIndex(e=>e.id===i);if(s!==-1){let e=oT[s].flag;this.currentSegment[e]=!0,tT(a);let t=this.reader.requestSlice(o,a);t instanceof Promise&&(t=await t),t&&this.readContiguousElements(t)}else if(i===X.Tags||i===X.Attachments){i===X.Tags?this.currentSegment.tagsSeen=!0:this.currentSegment.attachmentsSeen=!0,tT(a);let e=this.reader.requestSlice(o,a);e instanceof Promise&&(e=await e),e&&this.readContiguousElements(e)}else if(i===X.Cluster){this.currentSegment.clusterSeekStartPos=t;break}if(a===void 0)break;n=o+a}if(this.currentSegment.seekEntries.sort((e,t)=>e.segmentPosition-t.segmentPosition),this.reader.fileSize!==null)for(let t of this.currentSegment.seekEntries){let n=oT.find(e=>e.id===t.id);if(!n||this.currentSegment[n.flag])continue;let r=this.reader.requestSliceRange(e+t.segmentPosition,2,16);if(r instanceof Promise&&(r=await r),!r)continue;let i=Jw(r);if(!i)continue;let{id:a,size:o}=i;if(a!==n.id)continue;tT(o),this.currentSegment[n.flag]=!0;let s=this.reader.requestSlice(r.filePos,o);s instanceof Promise&&(s=await s),s&&this.readContiguousElements(s)}this.currentSegment.timestampScale===-1&&(this.currentSegment.timestampScale=1e6,this.currentSegment.timestampFactor=1e9/1e6);for(let e of this.currentSegment.tracks)e.defaultDurationNs!==null&&(e.defaultDuration=this.currentSegment.timestampFactor*e.defaultDurationNs/1e9);this.currentSegment.tracks.sort((e,t)=>Number(t.disposition.default)-Number(e.disposition.default));let r=new Map(this.currentSegment.tracks.map(e=>[e.id,e]));for(let e of this.currentSegment.cuePoints){let t=r.get(e.trackId);t&&t.cuePoints.push(e)}for(let e of this.currentSegment.tracks){e.cuePoints.sort((e,t)=>e.time-t.time);for(let t=0;t<e.cuePoints.length-1;t++){let n=e.cuePoints[t],r=e.cuePoints[t+1];n.time===r.time&&(e.cuePoints.splice(t+1,1),t--)}}let i=null,a=-1/0;for(let e of this.currentSegment.tracks)e.cuePoints.length>a&&(a=e.cuePoints.length,i=e);for(let e of this.currentSegment.tracks)e.cuePoints.length===0&&(e.cuePoints=i.cuePoints);this.currentSegment=null}async readCluster(e,t){if(t.lastReadCluster?.elementStartPos===e)return t.lastReadCluster;let n=this.reader.requestSliceRange(e,2,16);n instanceof Promise&&(n=await n),J(n);let r=e,i=Jw(n);J(i);let a=i.id;J(a===X.Cluster);let o=i.size,s=n.filePos;o===void 0&&(o=(await Qw(this.reader,s,Vw,t.elementEndPos)).pos-s);let c=this.reader.requestSlice(s,o);c instanceof Promise&&(c=await c);let l={segment:t,elementStartPos:r,elementEndPos:s+o,dataStartPos:s,timestamp:-1,trackData:new Map};this.currentCluster=l,c&&(l.elementEndPos=this.readContiguousElements(c,Vw));for(let[,e]of l.trackData){let t=e.track;J(e.blocks.length>0);let n=!1;for(let t=0;t<e.blocks.length;t++){let r=e.blocks[t];r.timestamp+=l.timestamp,n||=r.lacing!==rT.None}e.presentationTimestamps=e.blocks.map((e,t)=>({timestamp:e.timestamp,blockIndex:t})).sort((e,t)=>e.timestamp-t.timestamp);for(let n=0;n<e.presentationTimestamps.length;n++){let r=e.presentationTimestamps[n],i=e.blocks[r.blockIndex];e.firstKeyFrameTimestamp===null&&i.isKeyFrame&&(e.firstKeyFrameTimestamp=i.timestamp),n<e.presentationTimestamps.length-1?i.duration=e.presentationTimestamps[n+1].timestamp-i.timestamp:i.duration===0&&t.defaultDuration!=null&&i.lacing===rT.None&&(i.duration=t.defaultDuration)}n&&(this.expandLacedBlocks(e.blocks,t),e.presentationTimestamps=e.blocks.map((e,t)=>({timestamp:e.timestamp,blockIndex:t})).sort((e,t)=>e.timestamp-t.timestamp));let i=e.blocks[e.presentationTimestamps[0].blockIndex],a=e.blocks[Ob(e.presentationTimestamps).blockIndex];e.startTimestamp=i.timestamp,e.endTimestamp=a.timestamp+a.duration;let o=Jb(t.clusterPositionCache,e.startTimestamp,e=>e.startTimestamp);(o===-1||t.clusterPositionCache[o].elementStartPos!==r)&&t.clusterPositionCache.splice(o+1,0,{elementStartPos:l.elementStartPos,startTimestamp:e.startTimestamp})}return t.lastReadCluster=l,l}getTrackDataInCluster(e,t){let n=e.trackData.get(t);if(!n){let r=e.segment.tracks.find(e=>e.id===t);if(!r)return null;n={track:r,startTimestamp:0,endTimestamp:0,firstKeyFrameTimestamp:null,blocks:[],presentationTimestamps:[]},e.trackData.set(t,n)}return n}expandLacedBlocks(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(r.lacing===rT.None)continue;r.decoded||=(r.data=this.decodeBlockData(t,r.data),!0);let i=ME.tempFromBytes(r.data),a=[],o=FE(i)+1;switch(r.lacing){case rT.Xiph:{let e=0;for(let t=0;t<o-1;t++){let t=0;for(;i.bufferPos<i.length;){let n=FE(i);if(t+=n,n<255){a.push(t),e+=t;break}}}a.push(i.length-(i.bufferPos+e))}break;case rT.FixedSize:{let e=i.length-1,t=Math.floor(e/o);for(let e=0;e<o;e++)a.push(t)}break;case rT.Ebml:{let e=Uw(i);J(e!==null);let t=e;a.push(t);let n=t;for(let e=1;e<o-1;e++){let e=i.bufferPos,r=Uw(i);J(r!==null);let o=r-((1<<(i.bufferPos-e)*7-1)-1);t+=o,a.push(t),n+=t}a.push(i.length-(i.bufferPos+n))}break;default:J(!1)}J(a.length===o),e.splice(n,1);let s=r.duration||o*(t.defaultDuration??0);for(let t=0;t<o;t++){let c=a[t],l=PE(i,c),u=r.timestamp+s*t/o,d=s/o;e.splice(n+t,0,{timestamp:u,duration:d,isKeyFrame:r.isKeyFrame,data:l,lacing:rT.None,decoded:!0,mainAdditional:r.mainAdditional})}n+=o,n--}}async loadSegmentMetadata(e){for(let t of e.seekEntries){if(!(t.id===X.Tags&&!e.tagsSeen)&&!(t.id===X.Attachments&&!e.attachmentsSeen))continue;let n=this.reader.requestSliceRange(e.dataStartPos+t.segmentPosition,2,16);if(n instanceof Promise&&(n=await n),!n)continue;let r=Jw(n);if(!r||r.id!==t.id)continue;let{size:i}=r;tT(i),J(!this.currentSegment),this.currentSegment=e;let a=this.reader.requestSlice(n.filePos,i);a instanceof Promise&&(a=await a),a&&this.readContiguousElements(a),this.currentSegment=null,t.id===X.Tags?e.tagsSeen=!0:t.id===X.Attachments&&(e.attachmentsSeen=!0)}}readContiguousElements(e,t){for(;e.remainingLength>=2;){let n=e.filePos;if(!this.traverseElement(e,t))return n}return e.filePos}traverseElement(e,t){let n=Jw(e);if(!n||t&&t.includes(n.id))return!1;let{id:r,size:i}=n,a=e.filePos;switch(tT(i),r){case X.DocType:this.isWebM=Yw(e,i)===`webm`;break;case X.Seek:{if(!this.currentSegment)break;let t={id:-1,segmentPosition:-1};this.currentSegment.seekEntries.push(t),this.readContiguousElements(e.slice(a,i)),(t.id===-1||t.segmentPosition===-1)&&this.currentSegment.seekEntries.pop()}break;case X.SeekID:{let t=this.currentSegment?.seekEntries[this.currentSegment.seekEntries.length-1];if(!t)break;t.id=Ww(e,i)}break;case X.SeekPosition:{let t=this.currentSegment?.seekEntries[this.currentSegment.seekEntries.length-1];if(!t)break;t.segmentPosition=Ww(e,i)}break;case X.TimestampScale:if(!this.currentSegment)break;this.currentSegment.timestampScale=Ww(e,i),this.currentSegment.timestampFactor=1e9/this.currentSegment.timestampScale;break;case X.Duration:if(!this.currentSegment)break;this.currentSegment.duration=Zw(e,i);break;case X.TrackEntry:if(!this.currentSegment||(this.currentTrack={id:-1,segment:this.currentSegment,demuxer:this,clusterPositionCache:[],cuePoints:[],disposition:{...zx},inputTrack:null,codecId:null,codecPrivate:null,defaultDuration:null,defaultDurationNs:null,name:null,languageCode:`und`,decodingInstructions:[],info:null},this.readContiguousElements(e.slice(a,i)),!this.currentTrack))break;if(this.currentTrack.decodingInstructions.some(e=>e.data?.type!==`decompress`||e.scope!==iT.Block||e.data.algorithm!==aT.HeaderStripping)&&(console.warn(`Track #${this.currentTrack.id} has an unsupported content encoding; dropping.`),this.currentTrack=null),this.currentTrack&&this.currentTrack.id!==-1&&this.currentTrack.codecId&&this.currentTrack.info){let e=this.currentTrack.codecId.indexOf(`/`),t=e===-1?this.currentTrack.codecId:this.currentTrack.codecId.slice(0,e);if(this.currentTrack.info.type===`video`&&this.currentTrack.info.width!==-1&&this.currentTrack.info.height!==-1){if(this.currentTrack.info.squarePixelWidth=this.currentTrack.info.width,this.currentTrack.info.squarePixelHeight=this.currentTrack.info.height,this.currentTrack.info.displayWidth!==null&&this.currentTrack.info.displayHeight!==null){let e=this.currentTrack.info.displayWidth*this.currentTrack.info.height,t=this.currentTrack.info.displayHeight*this.currentTrack.info.width;e>t?this.currentTrack.info.squarePixelWidth=Math.round(this.currentTrack.info.width*e/t):this.currentTrack.info.squarePixelHeight=Math.round(this.currentTrack.info.height*t/e)}this.currentTrack.codecId===eT.avc?(this.currentTrack.info.codec=`avc`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):this.currentTrack.codecId===eT.hevc?(this.currentTrack.info.codec=`hevc`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):t===eT.vp8?this.currentTrack.info.codec=`vp8`:t===eT.vp9?this.currentTrack.info.codec=`vp9`:t===eT.av1&&(this.currentTrack.info.codec=`av1`);let e=this.currentTrack,n=new yw(this.input,new uT(e));this.currentTrack.inputTrack=n,this.currentSegment.tracks.push(this.currentTrack)}else if(this.currentTrack.info.type===`audio`&&this.currentTrack.info.numberOfChannels!==-1&&this.currentTrack.info.sampleRate!==-1){t===eT.aac?(this.currentTrack.info.codec=`aac`,this.currentTrack.info.aacCodecInfo={isMpeg2:this.currentTrack.codecId.includes(`MPEG2`),objectType:null},this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):this.currentTrack.codecId===eT.mp3?this.currentTrack.info.codec=`mp3`:t===eT.opus?(this.currentTrack.info.codec=`opus`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate,this.currentTrack.info.sampleRate=cS):t===eT.vorbis?(this.currentTrack.info.codec=`vorbis`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):t===eT.flac?(this.currentTrack.info.codec=`flac`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):t===eT.ac3?(this.currentTrack.info.codec=`ac3`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):t===eT.eac3?(this.currentTrack.info.codec=`eac3`,this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):this.currentTrack.codecId===`A_PCM/INT/LIT`?this.currentTrack.info.bitDepth===8?this.currentTrack.info.codec=`pcm-u8`:this.currentTrack.info.bitDepth===16?this.currentTrack.info.codec=`pcm-s16`:this.currentTrack.info.bitDepth===24?this.currentTrack.info.codec=`pcm-s24`:this.currentTrack.info.bitDepth===32&&(this.currentTrack.info.codec=`pcm-s32`):this.currentTrack.codecId===`A_PCM/INT/BIG`?this.currentTrack.info.bitDepth===8?this.currentTrack.info.codec=`pcm-u8`:this.currentTrack.info.bitDepth===16?this.currentTrack.info.codec=`pcm-s16be`:this.currentTrack.info.bitDepth===24?this.currentTrack.info.codec=`pcm-s24be`:this.currentTrack.info.bitDepth===32&&(this.currentTrack.info.codec=`pcm-s32be`):this.currentTrack.codecId===`A_PCM/FLOAT/IEEE`&&(this.currentTrack.info.bitDepth===32?this.currentTrack.info.codec=`pcm-f32`:this.currentTrack.info.bitDepth===64&&(this.currentTrack.info.codec=`pcm-f64`));let e=this.currentTrack,n=new bw(this.input,new dT(e));this.currentTrack.inputTrack=n,this.currentSegment.tracks.push(this.currentTrack)}}this.currentTrack=null;break;case X.TrackNumber:if(!this.currentTrack)break;this.currentTrack.id=Ww(e,i);break;case X.TrackType:{if(!this.currentTrack)break;let t=Ww(e,i);t===1?this.currentTrack.info={type:`video`,width:-1,height:-1,displayWidth:null,displayHeight:null,displayUnit:null,squarePixelWidth:-1,squarePixelHeight:-1,rotation:0,codec:null,codecDescription:null,colorSpace:null,alphaMode:!1}:t===2&&(this.currentTrack.info={type:`audio`,numberOfChannels:-1,sampleRate:-1,bitDepth:-1,codec:null,codecDescription:null,aacCodecInfo:null})}break;case X.FlagEnabled:if(!this.currentTrack)break;Ww(e,i)||(this.currentTrack=null);break;case X.FlagDefault:if(!this.currentTrack)break;this.currentTrack.disposition.default=!!Ww(e,i);break;case X.FlagForced:if(!this.currentTrack)break;this.currentTrack.disposition.forced=!!Ww(e,i);break;case X.FlagOriginal:if(!this.currentTrack)break;this.currentTrack.disposition.original=!!Ww(e,i);break;case X.FlagHearingImpaired:if(!this.currentTrack)break;this.currentTrack.disposition.hearingImpaired=!!Ww(e,i);break;case X.FlagVisualImpaired:if(!this.currentTrack)break;this.currentTrack.disposition.visuallyImpaired=!!Ww(e,i);break;case X.FlagCommentary:if(!this.currentTrack)break;this.currentTrack.disposition.commentary=!!Ww(e,i);break;case X.CodecID:if(!this.currentTrack)break;this.currentTrack.codecId=Yw(e,i);break;case X.CodecPrivate:if(!this.currentTrack)break;this.currentTrack.codecPrivate=PE(e,i);break;case X.DefaultDuration:if(!this.currentTrack)break;this.currentTrack.defaultDurationNs=Ww(e,i);break;case X.Name:if(!this.currentTrack)break;this.currentTrack.name=Xw(e,i);break;case X.Language:if(!this.currentTrack||this.currentTrack.languageCode!==`und`)break;this.currentTrack.languageCode=Yw(e,i),px(this.currentTrack.languageCode)||(this.currentTrack.languageCode=`und`);break;case X.LanguageBCP47:{if(!this.currentTrack)break;let t=Yw(e,i).split(`-`)[0];t?this.currentTrack.languageCode=t:this.currentTrack.languageCode=`und`}break;case X.Video:if(this.currentTrack?.info?.type!==`video`)break;this.readContiguousElements(e.slice(a,i));break;case X.PixelWidth:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.width=Ww(e,i);break;case X.PixelHeight:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.height=Ww(e,i);break;case X.DisplayWidth:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.displayWidth=Ww(e,i);break;case X.DisplayHeight:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.displayHeight=Ww(e,i);break;case X.DisplayUnit:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.displayUnit=Ww(e,i);break;case X.AlphaMode:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.alphaMode=Ww(e,i)===1;break;case X.Colour:if(this.currentTrack?.info?.type!==`video`)break;this.currentTrack.info.colorSpace={},this.readContiguousElements(e.slice(a,i));break;case X.MatrixCoefficients:{if(this.currentTrack?.info?.type!==`video`||!this.currentTrack.info.colorSpace)break;let t=Vb[Ww(e,i)]??null;this.currentTrack.info.colorSpace.matrix=t}break;case X.Range:if(this.currentTrack?.info?.type!==`video`||!this.currentTrack.info.colorSpace)break;this.currentTrack.info.colorSpace.fullRange=Ww(e,i)===2;break;case X.TransferCharacteristics:{if(this.currentTrack?.info?.type!==`video`||!this.currentTrack.info.colorSpace)break;let t=zb[Ww(e,i)]??null;this.currentTrack.info.colorSpace.transfer=t}break;case X.Primaries:{if(this.currentTrack?.info?.type!==`video`||!this.currentTrack.info.colorSpace)break;let t=Lb[Ww(e,i)]??null;this.currentTrack.info.colorSpace.primaries=t}break;case X.Projection:if(this.currentTrack?.info?.type!==`video`)break;this.readContiguousElements(e.slice(a,i));break;case X.ProjectionPoseRoll:{if(this.currentTrack?.info?.type!==`video`)break;let t=-Zw(e,i);try{this.currentTrack.info.rotation=Db(t)}catch{}}break;case X.Audio:if(this.currentTrack?.info?.type!==`audio`)break;this.readContiguousElements(e.slice(a,i));break;case X.SamplingFrequency:if(this.currentTrack?.info?.type!==`audio`)break;this.currentTrack.info.sampleRate=Zw(e,i);break;case X.Channels:if(this.currentTrack?.info?.type!==`audio`)break;this.currentTrack.info.numberOfChannels=Ww(e,i);break;case X.BitDepth:if(this.currentTrack?.info?.type!==`audio`)break;this.currentTrack.info.bitDepth=Ww(e,i);break;case X.CuePoint:if(!this.currentSegment)break;this.readContiguousElements(e.slice(a,i)),this.currentCueTime=null;break;case X.CueTime:this.currentCueTime=Ww(e,i);break;case X.CueTrackPositions:{if(this.currentCueTime===null)break;J(this.currentSegment);let t={time:this.currentCueTime,trackId:-1,clusterPosition:-1};this.currentSegment.cuePoints.push(t),this.readContiguousElements(e.slice(a,i)),(t.trackId===-1||t.clusterPosition===-1)&&this.currentSegment.cuePoints.pop()}break;case X.CueTrack:{let t=this.currentSegment?.cuePoints[this.currentSegment.cuePoints.length-1];if(!t)break;t.trackId=Ww(e,i)}break;case X.CueClusterPosition:{let t=this.currentSegment?.cuePoints[this.currentSegment.cuePoints.length-1];if(!t)break;J(this.currentSegment),t.clusterPosition=this.currentSegment.dataStartPos+Ww(e,i)}break;case X.Timestamp:if(!this.currentCluster)break;this.currentCluster.timestamp=Ww(e,i);break;case X.SimpleBlock:{if(!this.currentCluster)break;let t=Uw(e);if(t===null)break;let n=this.getTrackDataInCluster(this.currentCluster,t);if(!n)break;let r=zE(e),o=FE(e),s=o>>1&3,c=!!(o&128);n.track.info?.type===`audio`&&n.track.info.codec&&(c=!0);let l=PE(e,i-(e.filePos-a)),u=n.track.decodingInstructions.length>0;n.blocks.push({timestamp:r,duration:0,isKeyFrame:c,data:l,lacing:s,decoded:!u,mainAdditional:null})}break;case X.BlockGroup:if(!this.currentCluster)break;this.readContiguousElements(e.slice(a,i)),this.currentBlock=null;break;case X.Block:{if(!this.currentCluster)break;let t=Uw(e);if(t===null)break;let n=this.getTrackDataInCluster(this.currentCluster,t);if(!n)break;let r=zE(e),o=FE(e)>>1&3;this.currentBlock={timestamp:r,duration:0,isKeyFrame:!0,data:PE(e,i-(e.filePos-a)),lacing:o,decoded:!(n.track.decodingInstructions.length>0),mainAdditional:null},n.blocks.push(this.currentBlock)}break;case X.BlockAdditions:this.readContiguousElements(e.slice(a,i));break;case X.BlockMore:if(!this.currentBlock)break;this.currentBlockAdditional={addId:1,data:null},this.readContiguousElements(e.slice(a,i)),this.currentBlockAdditional.data&&this.currentBlockAdditional.addId===1&&(this.currentBlock.mainAdditional=this.currentBlockAdditional.data),this.currentBlockAdditional=null;break;case X.BlockAdditional:if(!this.currentBlockAdditional)break;this.currentBlockAdditional.data=PE(e,i);break;case X.BlockAddID:if(!this.currentBlockAdditional)break;this.currentBlockAdditional.addId=Ww(e,i);break;case X.BlockDuration:if(!this.currentBlock)break;this.currentBlock.duration=Ww(e,i);break;case X.ReferenceBlock:if(!this.currentBlock)break;this.currentBlock.isKeyFrame=!1;break;case X.Tag:this.currentTagTargetIsMovie=!0,this.readContiguousElements(e.slice(a,i));break;case X.Targets:this.readContiguousElements(e.slice(a,i));break;case X.TargetTypeValue:Ww(e,i)!==50&&(this.currentTagTargetIsMovie=!1);break;case X.TagTrackUID:case X.TagEditionUID:case X.TagChapterUID:case X.TagAttachmentUID:this.currentTagTargetIsMovie=!1;break;case X.SimpleTag:if(!this.currentTagTargetIsMovie)break;this.currentSimpleTagName=null,this.readContiguousElements(e.slice(a,i));break;case X.TagName:this.currentSimpleTagName=Xw(e,i);break;case X.TagString:{if(!this.currentSimpleTagName)break;let t=Xw(e,i);this.processTagValue(this.currentSimpleTagName,t)}break;case X.TagBinary:{if(!this.currentSimpleTagName)break;let t=PE(e,i);this.processTagValue(this.currentSimpleTagName,t)}break;case X.AttachedFile:{if(!this.currentSegment)break;this.currentAttachedFile={fileUid:null,fileName:null,fileMediaType:null,fileData:null,fileDescription:null},this.readContiguousElements(e.slice(a,i));let t=this.currentSegment.metadataTags;if(this.currentAttachedFile.fileUid&&this.currentAttachedFile.fileData&&(t.raw??={},t.raw[this.currentAttachedFile.fileUid.toString()]=new Lx(this.currentAttachedFile.fileData,this.currentAttachedFile.fileMediaType??void 0,this.currentAttachedFile.fileName??void 0,this.currentAttachedFile.fileDescription??void 0)),this.currentAttachedFile.fileMediaType?.startsWith(`image/`)&&this.currentAttachedFile.fileData){let e=this.currentAttachedFile.fileName,n=`unknown`;if(e){let t=e.toLowerCase();t.startsWith(`cover.`)?n=`coverFront`:t.startsWith(`back.`)&&(n=`coverBack`)}t.images??=[],t.images.push({data:this.currentAttachedFile.fileData,mimeType:this.currentAttachedFile.fileMediaType,kind:n,name:this.currentAttachedFile.fileName??void 0,description:this.currentAttachedFile.fileDescription??void 0})}this.currentAttachedFile=null}break;case X.FileUID:if(!this.currentAttachedFile)break;this.currentAttachedFile.fileUid=Gw(e,i);break;case X.FileName:if(!this.currentAttachedFile)break;this.currentAttachedFile.fileName=Xw(e,i);break;case X.FileMediaType:if(!this.currentAttachedFile)break;this.currentAttachedFile.fileMediaType=Yw(e,i);break;case X.FileData:if(!this.currentAttachedFile)break;this.currentAttachedFile.fileData=PE(e,i);break;case X.FileDescription:if(!this.currentAttachedFile)break;this.currentAttachedFile.fileDescription=Xw(e,i);break;case X.ContentEncodings:if(!this.currentTrack)break;this.readContiguousElements(e.slice(a,i)),this.currentTrack.decodingInstructions.sort((e,t)=>t.order-e.order);break;case X.ContentEncoding:this.currentDecodingInstruction={order:0,scope:iT.Block,data:null},this.readContiguousElements(e.slice(a,i)),this.currentDecodingInstruction.data&&this.currentTrack.decodingInstructions.push(this.currentDecodingInstruction),this.currentDecodingInstruction=null;break;case X.ContentEncodingOrder:if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.order=Ww(e,i);break;case X.ContentEncodingScope:if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.scope=Ww(e,i);break;case X.ContentCompression:if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.data={type:`decompress`,algorithm:aT.Zlib,settings:null},this.readContiguousElements(e.slice(a,i));break;case X.ContentCompAlgo:if(this.currentDecodingInstruction?.data?.type!==`decompress`)break;this.currentDecodingInstruction.data.algorithm=Ww(e,i);break;case X.ContentCompSettings:if(this.currentDecodingInstruction?.data?.type!==`decompress`)break;this.currentDecodingInstruction.data.settings=PE(e,i);break;case X.ContentEncryption:if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.data={type:`decrypt`};break}return e.filePos=a+i,!0}decodeBlockData(e,t){J(e.decodingInstructions.length>0);let n=t;for(let t of e.decodingInstructions)switch(J(t.data),t.data.type){case`decompress`:switch(t.data.algorithm){case aT.HeaderStripping:if(t.data.settings&&t.data.settings.length>0){let e=t.data.settings,r=new Uint8Array(e.length+n.length);r.set(e,0),r.set(n,e.length),n=r}break;default:}break;default:}return n}processTagValue(e,t){if(!this.currentSegment?.metadataTags)return;let n=this.currentSegment.metadataTags;if(n.raw??={},n.raw[e]??=t,typeof t==`string`)switch(e.toLowerCase()){case`title`:n.title??=t;break;case`description`:n.description??=t;break;case`artist`:n.artist??=t;break;case`album`:n.album??=t;break;case`album_artist`:n.albumArtist??=t;break;case`genre`:n.genre??=t;break;case`comment`:n.comment??=t;break;case`lyrics`:n.lyrics??=t;break;case`date`:{let e=new Date(t);Number.isNaN(e.getTime())||(n.date??=e)}break;case`track_number`:case`part_number`:{let e=t.split(`/`),r=Number.parseInt(e[0],10),i=e[1]&&Number.parseInt(e[1],10);Number.isInteger(r)&&r>0&&(n.trackNumber??=r),i&&Number.isInteger(i)&&i>0&&(n.tracksTotal??=i)}break;case`disc_number`:case`disc`:{let e=t.split(`/`),r=Number.parseInt(e[0],10),i=e[1]&&Number.parseInt(e[1],10);Number.isInteger(r)&&r>0&&(n.discNumber??=r),i&&Number.isInteger(i)&&i>0&&(n.discsTotal??=i)}break}}},lT=class{constructor(e){this.internalTrack=e,this.packetToClusterLocation=new WeakMap}getId(){return this.internalTrack.id}getNumber(){let e=this.internalTrack.demuxer,t=this.internalTrack.inputTrack.type,n=0;for(let r of e.segments)for(let e of r.tracks)if(e.inputTrack.type===t&&n++,e===this.internalTrack)break;return n}getCodec(){throw Error(`Not implemented on base class.`)}getInternalCodecId(){return this.internalTrack.codecId}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}getName(){return this.internalTrack.name}getLanguageCode(){return this.internalTrack.languageCode}async getFirstTimestamp(){return(await this.getFirstPacket({metadataOnly:!0}))?.timestamp??0}getTimeResolution(){return this.internalTrack.segment.timestampFactor}getDisposition(){return this.internalTrack.disposition}async getFirstPacket(e){return this.performClusterLookup(null,e=>e.trackData.get(this.internalTrack.id)?{blockIndex:0,correctBlockFound:!0}:{blockIndex:-1,correctBlockFound:!1},-1/0,1/0,e)}intoTimescale(e){return cx(e*this.internalTrack.segment.timestampFactor)}async getPacket(e,t){let n=this.intoTimescale(e);return this.performClusterLookup(null,e=>{let t=e.trackData.get(this.internalTrack.id);if(!t)return{blockIndex:-1,correctBlockFound:!1};let r=Jb(t.presentationTimestamps,n,e=>e.timestamp);return{blockIndex:r===-1?-1:t.presentationTimestamps[r].blockIndex,correctBlockFound:r!==-1&&n<t.endTimestamp}},n,n,t)}async getNextPacket(e,t){let n=this.packetToClusterLocation.get(e);if(n===void 0)throw Error(`Packet was not created from this track.`);return this.performClusterLookup(n.cluster,e=>{if(e===n.cluster){let t=e.trackData.get(this.internalTrack.id);if(n.blockIndex+1<t.blocks.length)return{blockIndex:n.blockIndex+1,correctBlockFound:!0}}else if(e.trackData.get(this.internalTrack.id))return{blockIndex:0,correctBlockFound:!0};return{blockIndex:-1,correctBlockFound:!1}},-1/0,1/0,t)}async getKeyPacket(e,t){let n=this.intoTimescale(e);return this.performClusterLookup(null,e=>{let t=e.trackData.get(this.internalTrack.id);if(!t)return{blockIndex:-1,correctBlockFound:!1};let r=Qb(t.presentationTimestamps,e=>t.blocks[e.blockIndex].isKeyFrame&&e.timestamp<=n);return{blockIndex:r===-1?-1:t.presentationTimestamps[r].blockIndex,correctBlockFound:r!==-1&&n<t.endTimestamp}},n,n,t)}async getNextKeyPacket(e,t){let n=this.packetToClusterLocation.get(e);if(n===void 0)throw Error(`Packet was not created from this track.`);return this.performClusterLookup(n.cluster,e=>{if(e===n.cluster){let t=e.trackData.get(this.internalTrack.id).blocks.findIndex((e,t)=>e.isKeyFrame&&t>n.blockIndex);if(t!==-1)return{blockIndex:t,correctBlockFound:!0}}else{let t=e.trackData.get(this.internalTrack.id);if(t&&t.firstKeyFrameTimestamp!==null){let e=t.blocks.findIndex(e=>e.isKeyFrame);return J(e!==-1),{blockIndex:e,correctBlockFound:!0}}}return{blockIndex:-1,correctBlockFound:!1}},-1/0,1/0,t)}async fetchPacketInCluster(e,t,n){if(t===-1)return null;let r=e.trackData.get(this.internalTrack.id).blocks[t];J(r),r.decoded||=(r.data=this.internalTrack.demuxer.decodeBlockData(this.internalTrack,r.data),!0);let i=n.metadataOnly?AC:r.data,a=r.timestamp/this.internalTrack.segment.timestampFactor,o=r.duration/this.internalTrack.segment.timestampFactor,s={};r.mainAdditional&&this.internalTrack.info?.type===`video`&&this.internalTrack.info.alphaMode&&(s.alpha=n.metadataOnly?AC:r.mainAdditional,s.alphaByteLength=r.mainAdditional.byteLength);let c=new jC(i,r.isKeyFrame?`key`:`delta`,a,o,e.dataStartPos+t,r.data.byteLength,s);return this.packetToClusterLocation.set(c,{cluster:e,blockIndex:t}),c}async performClusterLookup(e,t,n,r,i){let{demuxer:a,segment:o}=this.internalTrack,s=null,c=null,l=-1;if(e){let{blockIndex:n,correctBlockFound:r}=t(e);if(r)return this.fetchPacketInCluster(e,n,i);n!==-1&&(c=e,l=n)}let u=Jb(this.internalTrack.cuePoints,n,e=>e.time),d=u===-1?null:this.internalTrack.cuePoints[u],f=Jb(this.internalTrack.clusterPositionCache,n,e=>e.startTimestamp),p=f===-1?null:this.internalTrack.clusterPositionCache[f],m=Math.max(d?.clusterPosition??0,p?.elementStartPos??0)||null,h;for(e?m===null||e.elementStartPos>=m?(h=e.elementEndPos,s=e):h=m:h=m??o.clusterSeekStartPos;o.elementEndPos===null||h<=o.elementEndPos-2;){if(s){let e=s.trackData.get(this.internalTrack.id);if(e&&e.startTimestamp>r)break}let e=a.reader.requestSliceRange(h,2,16);if(e instanceof Promise&&(e=await e),!e)break;let n=h,u=Jw(e);if(!u||!Bw.includes(u.id)&&u.id!==X.Void){let e=await $w(a.reader,n,Bw,Math.min(o.elementEndPos??1/0,n+sT));if(e){h=e;continue}else break}let d=u.id,f=u.size,p=e.filePos;if(d===X.Cluster){s=await a.readCluster(n,o),f=s.elementEndPos-p;let{blockIndex:e,correctBlockFound:r}=t(s);if(r)return this.fetchPacketInCluster(s,e,i);e!==-1&&(c=s,l=e)}f===void 0&&(J(d!==X.Cluster),f=(await Qw(a.reader,p,Vw,o.elementEndPos)).pos-p);let m=p+f;if(o.elementEndPos===null){let e=a.reader.requestSliceRange(m,2,16);if(e instanceof Promise&&(e=await e),!e)break;if(Kw(e)===X.Segment){o.elementEndPos=m;break}}h=m}if(d&&(!c||c.elementStartPos<d.clusterPosition)){let e=this.internalTrack.cuePoints[u-1];J(!e||e.time<d.time);let n=e?.time??-1/0;return this.performClusterLookup(null,t,n,r,i)}return c?this.fetchPacketInCluster(c,l,i):null}},uT=class extends lT{constructor(e){super(e),this.decoderConfigPromise=null,this.internalTrack=e}getCodec(){return this.internalTrack.info.codec}getCodedWidth(){return this.internalTrack.info.width}getCodedHeight(){return this.internalTrack.info.height}getSquarePixelWidth(){return this.internalTrack.info.squarePixelWidth}getSquarePixelHeight(){return this.internalTrack.info.squarePixelHeight}getRotation(){return this.internalTrack.info.rotation}async getColorSpace(){return{primaries:this.internalTrack.info.colorSpace?.primaries,transfer:this.internalTrack.info.colorSpace?.transfer,matrix:this.internalTrack.info.colorSpace?.matrix,fullRange:this.internalTrack.info.colorSpace?.fullRange}}async canBeTransparent(){return this.internalTrack.info.alphaMode}async getDecoderConfig(){return this.internalTrack.info.codec?this.decoderConfigPromise??=(async()=>{let e=null;return(this.internalTrack.info.codec===`vp9`||this.internalTrack.info.codec===`av1`||this.internalTrack.info.codec===`avc`&&!this.internalTrack.info.codecDescription||this.internalTrack.info.codec===`hevc`&&!this.internalTrack.info.codecDescription)&&(e=await this.getFirstPacket({})),{codec:aS({width:this.internalTrack.info.width,height:this.internalTrack.info.height,codec:this.internalTrack.info.codec,codecDescription:this.internalTrack.info.codecDescription,colorSpace:this.internalTrack.info.colorSpace,avcType:1,avcCodecInfo:this.internalTrack.info.codec===`avc`&&e?HS(e.data):null,hevcCodecInfo:this.internalTrack.info.codec===`hevc`&&e?ZS(e.data):null,vp9CodecInfo:this.internalTrack.info.codec===`vp9`&&e?oC(e.data):null,av1CodecInfo:this.internalTrack.info.codec===`av1`&&e?cC(e.data):null}),codedWidth:this.internalTrack.info.width,codedHeight:this.internalTrack.info.height,displayAspectWidth:this.internalTrack.info.squarePixelWidth,displayAspectHeight:this.internalTrack.info.squarePixelHeight,description:this.internalTrack.info.codecDescription??void 0,colorSpace:this.internalTrack.info.colorSpace??void 0}})():null}},dT=class extends lT{constructor(e){super(e),this.decoderConfig=null,this.internalTrack=e}getCodec(){return this.internalTrack.info.codec}getNumberOfChannels(){return this.internalTrack.info.numberOfChannels}getSampleRate(){return this.internalTrack.info.sampleRate}async getDecoderConfig(){return this.internalTrack.info.codec?this.decoderConfig??={codec:sS({codec:this.internalTrack.info.codec,codecDescription:this.internalTrack.info.codecDescription,aacCodecInfo:this.internalTrack.info.aacCodecInfo}),numberOfChannels:this.internalTrack.info.numberOfChannels,sampleRate:this.internalTrack.info.sampleRate,description:this.internalTrack.info.codecDescription??void 0}:null}},fT=async(e,t,n)=>{let r=t;for(;n===null||r<n;){let t=e.requestSlice(r,4);if(t instanceof Promise&&(t=await t),!t)break;let n=DS(Z(t),e.fileSize===null?null:e.fileSize-r);if(n.header)return{header:n.header,startPos:r};r+=n.bytesAdvanced}return null},pT=class extends TC{constructor(e){super(e),this.metadataPromise=null,this.firstFrameHeader=null,this.loadedSamples=[],this.metadataTags=null,this.tracks=[],this.readingMutex=new Wb,this.lastSampleLoaded=!1,this.lastLoadedPos=0,this.nextTimestampInSamples=0,this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{for(;!this.firstFrameHeader&&!this.lastSampleLoaded;)await this.advanceReader();if(!this.firstFrameHeader)throw Error(`No valid MP3 frame found.`);this.tracks=[new bw(this.input,new mT(this))]})()}async advanceReader(){if(this.lastLoadedPos===0)for(;;){let e=this.reader.requestSlice(this.lastLoadedPos,10);if(e instanceof Promise&&(e=await e),!e){this.lastSampleLoaded=!0;return}let t=nD(e);if(!t)break;this.lastLoadedPos=e.filePos+t.size}let e=await fT(this.reader,this.lastLoadedPos,this.reader.fileSize);if(!e){this.lastSampleLoaded=!0;return}let t=e.header;this.lastLoadedPos=e.startPos+t.totalSize-1;let n=ES(t.mpegVersionId,t.channel),r=this.reader.requestSlice(e.startPos+n,4);if(r instanceof Promise&&(r=await r),r){let e=Z(r);if(e===1483304551||e===1231971951)return}this.firstFrameHeader||=t,t.sampleRate!==this.firstFrameHeader.sampleRate&&console.warn(`MP3 changed sample rate mid-file: ${this.firstFrameHeader.sampleRate} Hz to ${t.sampleRate} Hz. Might be a bug, so please report this file.`);let i=t.audioSamplesInFrame/this.firstFrameHeader.sampleRate,a={timestamp:this.nextTimestampInSamples/this.firstFrameHeader.sampleRate,duration:i,dataStart:e.startPos,dataSize:t.totalSize};this.loadedSamples.push(a),this.nextTimestampInSamples+=t.audioSamplesInFrame}async getMimeType(){return`audio/mpeg`}async getTracks(){return await this.readMetadata(),this.tracks}async computeDuration(){await this.readMetadata();let e=this.tracks[0];return J(e),e.computeDuration()}async getMetadataTags(){let e=await this.readingMutex.acquire();try{if(await this.readMetadata(),this.metadataTags)return this.metadataTags;this.metadataTags={};let e=0,t=!1;for(;;){let n=this.reader.requestSlice(e,10);if(n instanceof Promise&&(n=await n),!n)break;let r=nD(n);if(!r)break;t=!0;let i=this.reader.requestSlice(n.filePos,r.size);if(i instanceof Promise&&(i=await i),!i)break;rD(i,r,this.metadataTags),e=n.filePos+r.size}if(!t&&this.reader.fileSize!==null&&this.reader.fileSize>=128){let e=this.reader.requestSlice(this.reader.fileSize-128,128);e instanceof Promise&&(e=await e),J(e),XE(e,3)===`TAG`&&eD(e,this.metadataTags)}return this.metadataTags}finally{e()}}},mT=class{constructor(e){this.demuxer=e}getId(){return 1}getNumber(){return 1}async getFirstTimestamp(){return 0}getTimeResolution(){return J(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.sampleRate/this.demuxer.firstFrameHeader.audioSamplesInFrame}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}getName(){return null}getLanguageCode(){return`und`}getCodec(){return`mp3`}getInternalCodecId(){return null}getNumberOfChannels(){return J(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.channel===3?1:2}getSampleRate(){return J(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.sampleRate}getDisposition(){return{...zx}}async getDecoderConfig(){return J(this.demuxer.firstFrameHeader),{codec:`mp3`,numberOfChannels:this.demuxer.firstFrameHeader.channel===3?1:2,sampleRate:this.demuxer.firstFrameHeader.sampleRate}}async getPacketAtIndex(e,t){if(e===-1)return null;let n=this.demuxer.loadedSamples[e];if(!n)return null;let r;if(t.metadataOnly)r=AC;else{let e=this.demuxer.reader.requestSlice(n.dataStart,n.dataSize);if(e instanceof Promise&&(e=await e),!e)return null;r=PE(e,n.dataSize)}return new jC(r,`key`,n.timestamp,n.duration,e,n.dataSize)}getFirstPacket(e){return this.getPacketAtIndex(0,e)}async getNextPacket(e,t){let n=await this.demuxer.readingMutex.acquire();try{let n=qb(this.demuxer.loadedSamples,e.timestamp,e=>e.timestamp);if(n===-1)throw Error(`Packet was not created from this track.`);let r=n+1;for(;r>=this.demuxer.loadedSamples.length&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(r,t)}finally{n()}}async getPacket(e,t){let n=await this.demuxer.readingMutex.acquire();try{for(;;){let n=Jb(this.demuxer.loadedSamples,e,e=>e.timestamp);if(n===-1&&this.demuxer.loadedSamples.length>0)return null;if(this.demuxer.lastSampleLoaded||n>=0&&n+1<this.demuxer.loadedSamples.length)return this.getPacketAtIndex(n,t);await this.demuxer.advanceReader()}}finally{n()}}getKeyPacket(e,t){return this.getPacket(e,t)}getNextKeyPacket(e,t){return this.getNextPacket(e,t)}},hT=79764919,gT=new Uint32Array(256);for(let e=0;e<256;e++){let t=e<<24;for(let e=0;e<8;e++)t=t&2147483648?t<<1^hT:t<<1;gT[e]=t>>>0&4294967295}var _T=e=>{let t=Mb(e),n=t.getUint32(22,!0);t.setUint32(22,0,!0);let r=0;for(let t=0;t<e.length;t++){let n=e[t];r=(r<<8^gT[r>>>24^n])>>>0}return t.setUint32(22,n,!0),r},vT=(e,t,n)=>{let r=0,i=null;if(e.length>0)if(t.codec===`vorbis`){J(t.vorbisInfo);let a=t.vorbisInfo.modeBlockflags.length,o=(1<<dx(a-1))-1<<1,s=(e[0]&o)>>1;if(s>=t.vorbisInfo.modeBlockflags.length)throw Error(`Invalid mode number.`);let c=n,l=t.vorbisInfo.modeBlockflags[s];if(i=t.vorbisInfo.blocksizes[l],l===1){let n=(o|1)+1,r=e[0]&n?1:0;c=t.vorbisInfo.blocksizes[r]}r=c===null?0:c+i>>2}else t.codec===`opus`&&(r=dC(e).durationInSamples);return{durationInSamples:r,vorbisBlockSize:i}},yT=e=>{let t=`audio/ogg`;if(e.codecStrings){let n=[...new Set(e.codecStrings)];t+=`; codecs="${n.join(`, `)}"`}return t},bT=65307,xT=e=>{let t=e.filePos;if(VE(e)!==1399285583)return null;e.skip(1);let n=FE(e),r=qE(e),i=VE(e),a=VE(e),o=VE(e),s=FE(e),c=new Uint8Array(s);for(let t=0;t<s;t++)c[t]=FE(e);let l=27+s,u=c.reduce((e,t)=>e+t,0);return{headerStartPos:t,totalSize:l+u,dataStartPos:t+l,dataSize:u,headerType:n,granulePosition:r,serialNumber:i,sequenceNumber:a,checksum:o,lacingValues:c}},ST=(e,t)=>{for(;e.filePos<t-3;){let t=VE(e),n=t&255,r=t>>>8&255,i=t>>>16&255,a=t>>>24&255;if(!(n!==79&&r!==79&&i!==79&&a!==79)){if(e.skip(-4),t===1399285583)return!0;e.skip(1)}}return!1},CT=class extends TC{constructor(e){super(e),this.metadataPromise=null,this.bitstreams=[],this.tracks=[],this.metadataTags={},this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{let e=0;for(;;){let t=this.reader.requestSliceRange(e,27,282);if(t instanceof Promise&&(t=await t),!t)break;let n=xT(t);if(!n||!(n.headerType&2))break;this.bitstreams.push({serialNumber:n.serialNumber,bosPage:n,description:null,numberOfChannels:-1,sampleRate:-1,codecInfo:{codec:null,vorbisInfo:null,opusInfo:null},lastMetadataPacket:null}),e=n.headerStartPos+n.totalSize}for(let e of this.bitstreams){let t=await this.readPacket(e.bosPage,0);t&&(t.data.byteLength>=7&&t.data[0]===1&&t.data[1]===118&&t.data[2]===111&&t.data[3]===114&&t.data[4]===98&&t.data[5]===105&&t.data[6]===115?await this.readVorbisMetadata(t,e):t.data.byteLength>=8&&t.data[0]===79&&t.data[1]===112&&t.data[2]===117&&t.data[3]===115&&t.data[4]===72&&t.data[5]===101&&t.data[6]===97&&t.data[7]===100&&await this.readOpusMetadata(t,e),e.codecInfo.codec!==null&&this.tracks.push(new bw(this.input,new wT(e,this))))}})()}async readVorbisMetadata(e,t){let n=await this.findNextPacketStart(e);if(!n)return;let r=await this.readPacket(n.startPage,n.startSegmentIndex);if(!r||(n=await this.findNextPacketStart(r),!n))return;let i=await this.readPacket(n.startPage,n.startSegmentIndex);if(!i||r.data[0]!==3||i.data[0]!==5)return;let a=[],o=e=>{for(;a.push(Math.min(255,e)),!(e<255);)e-=255};o(e.data.length),o(r.data.length);let s=new Uint8Array(1+a.length+e.data.length+r.data.length+i.data.length);s[0]=2,s.set(a,1),s.set(e.data,1+a.length),s.set(r.data,1+a.length+e.data.length),s.set(i.data,1+a.length+e.data.length+r.data.length),t.codecInfo.codec=`vorbis`,t.description=s,t.lastMetadataPacket=i;let c=Mb(e.data);t.numberOfChannels=c.getUint8(11),t.sampleRate=c.getUint32(12,!0);let l=c.getUint8(28);t.codecInfo.vorbisInfo={blocksizes:[1<<(l&15),1<<(l>>4)],modeBlockflags:fC(i.data).modeBlockflags},hC(r.data.subarray(7),this.metadataTags)}async readOpusMetadata(e,t){let n=await this.findNextPacketStart(e);if(!n)return;let r=await this.readPacket(n.startPage,n.startSegmentIndex);if(!r)return;t.codecInfo.codec=`opus`,t.description=e.data,t.lastMetadataPacket=r;let i=lC(e.data);t.numberOfChannels=i.outputChannelCount,t.sampleRate=cS,t.codecInfo.opusInfo={preSkip:i.preSkip},hC(r.data.subarray(8),this.metadataTags)}async readPacket(e,t){J(t<e.lacingValues.length);let n=0;for(let r=0;r<t;r++)n+=e.lacingValues[r];let r=e,i=n,a=t,o=[];outer:for(;;){let t=this.reader.requestSlice(r.dataStartPos,r.dataSize);t instanceof Promise&&(t=await t),J(t);let s=PE(t,r.dataSize);for(;;){if(a===r.lacingValues.length){o.push(s.subarray(n,i));break}let e=r.lacingValues[a];if(i+=e,e<255){o.push(s.subarray(n,i));break outer}a++}let c=r.headerStartPos+r.totalSize;for(;;){let t=this.reader.requestSliceRange(c,27,282);if(t instanceof Promise&&(t=await t),!t)return null;let n=xT(t);if(!n)return null;if(r=n,r.serialNumber===e.serialNumber)break;c=r.headerStartPos+r.totalSize}n=0,i=0,a=0}let s=o.reduce((e,t)=>e+t.length,0);if(s===0)return null;let c=new Uint8Array(s),l=0;for(let e=0;e<o.length;e++){let t=o[e];c.set(t,l),l+=t.length}return{data:c,endPage:r,endSegmentIndex:a}}async findNextPacketStart(e){if(e.endSegmentIndex<e.endPage.lacingValues.length-1)return{startPage:e.endPage,startSegmentIndex:e.endSegmentIndex+1};if(e.endPage.headerType&4)return null;let t=e.endPage.headerStartPos+e.endPage.totalSize;for(;;){let n=this.reader.requestSliceRange(t,27,282);if(n instanceof Promise&&(n=await n),!n)return null;let r=xT(n);if(!r)return null;if(r.serialNumber===e.endPage.serialNumber)return{startPage:r,startSegmentIndex:0};t=r.headerStartPos+r.totalSize}}async getMimeType(){return await this.readMetadata(),yT({codecStrings:(await Promise.all(this.tracks.map(e=>e.getCodecParameterString()))).filter(Boolean)})}async getTracks(){return await this.readMetadata(),this.tracks}async computeDuration(){let e=await this.getTracks(),t=await Promise.all(e.map(e=>e.computeDuration()));return Math.max(0,...t)}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}},wT=class{constructor(e,t){this.bitstream=e,this.demuxer=t,this.encodedPacketToMetadata=new WeakMap,this.sequentialScanCache=[],this.sequentialScanMutex=new Wb,this.internalSampleRate=e.codecInfo.codec===`opus`?cS:e.sampleRate}getId(){return this.bitstream.serialNumber}getNumber(){let e=this.demuxer.tracks.findIndex(e=>e._backing.bitstream===this.bitstream);return J(e!==-1),e+1}getNumberOfChannels(){return this.bitstream.numberOfChannels}getSampleRate(){return this.bitstream.sampleRate}getTimeResolution(){return this.bitstream.sampleRate}getCodec(){return this.bitstream.codecInfo.codec}getInternalCodecId(){return null}async getDecoderConfig(){return J(this.bitstream.codecInfo.codec),{codec:this.bitstream.codecInfo.codec,numberOfChannels:this.bitstream.numberOfChannels,sampleRate:this.bitstream.sampleRate,description:this.bitstream.description??void 0}}getName(){return null}getLanguageCode(){return`und`}getDisposition(){return{...zx}}async getFirstTimestamp(){return 0}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}granulePositionToTimestampInSamples(e){return this.bitstream.codecInfo.codec===`opus`?(J(this.bitstream.codecInfo.opusInfo),e-this.bitstream.codecInfo.opusInfo.preSkip):e}createEncodedPacketFromOggPacket(e,t,n){if(!e)return null;let{durationInSamples:r,vorbisBlockSize:i}=vT(e.data,this.bitstream.codecInfo,t.vorbisLastBlocksize),a=new jC(n.metadataOnly?AC:e.data,`key`,Math.max(0,t.timestampInSamples)/this.internalSampleRate,r/this.internalSampleRate,e.endPage.headerStartPos+e.endSegmentIndex,e.data.byteLength);return this.encodedPacketToMetadata.set(a,{packet:e,timestampInSamples:t.timestampInSamples,durationInSamples:r,vorbisLastBlockSize:t.vorbisLastBlocksize,vorbisBlockSize:i}),a}async getFirstPacket(e){J(this.bitstream.lastMetadataPacket);let t=await this.demuxer.findNextPacketStart(this.bitstream.lastMetadataPacket);if(!t)return null;let n=0;this.bitstream.codecInfo.codec===`opus`&&(J(this.bitstream.codecInfo.opusInfo),n-=this.bitstream.codecInfo.opusInfo.preSkip);let r=await this.demuxer.readPacket(t.startPage,t.startSegmentIndex);return this.createEncodedPacketFromOggPacket(r,{timestampInSamples:n,vorbisLastBlocksize:null},e)}async getNextPacket(e,t){let n=this.encodedPacketToMetadata.get(e);if(!n)throw Error(`Packet was not created from this track.`);let r=await this.demuxer.findNextPacketStart(n.packet);if(!r)return null;let i=n.timestampInSamples+n.durationInSamples,a=await this.demuxer.readPacket(r.startPage,r.startSegmentIndex);return this.createEncodedPacketFromOggPacket(a,{timestampInSamples:i,vorbisLastBlocksize:n.vorbisBlockSize},t)}async getPacket(e,t){if(this.demuxer.reader.fileSize===null)return this.getPacketSequential(e,t);let n=cx(e*this.internalSampleRate);if(n===0)return this.getFirstPacket(t);if(n<0)return null;J(this.bitstream.lastMetadataPacket);let r=await this.demuxer.findNextPacketStart(this.bitstream.lastMetadataPacket);if(!r)return null;let i=r.startPage,a=this.demuxer.reader.fileSize,o=[i];outer:for(;i.headerStartPos+i.totalSize<a;){let e=i.headerStartPos,t=Math.floor((e+a)/2),r=t;for(;;){let e=Math.min(r+bT,a-27),s=this.demuxer.reader.requestSlice(r,e-r);if(s instanceof Promise&&(s=await s),J(s),!ST(s,e)){a=t+27;continue outer}let c=this.demuxer.reader.requestSliceRange(s.filePos,27,282);c instanceof Promise&&(c=await c),J(c);let l=xT(c);J(l);let u=!1;if(l.serialNumber===this.bitstream.serialNumber)u=!0;else{let e=this.demuxer.reader.requestSlice(l.headerStartPos,l.totalSize);e instanceof Promise&&(e=await e),J(e),u=_T(PE(e,l.totalSize))===l.checksum}if(!u){r=l.headerStartPos+4;continue}if(u&&l.serialNumber!==this.bitstream.serialNumber){r=l.headerStartPos+l.totalSize;continue}if(l.granulePosition===-1){r=l.headerStartPos+l.totalSize;continue}this.granulePositionToTimestampInSamples(l.granulePosition)>n?a=l.headerStartPos:(i=l,o.push(l));continue outer}}let s=r.startPage;for(let e of o){if(e.granulePosition===i.granulePosition)break;(!s||e.headerStartPos>s.headerStartPos)&&(s=e)}let c=s,l=[c];for(;!(c.serialNumber===this.bitstream.serialNumber&&c.granulePosition===i.granulePosition);){let e=c.headerStartPos+c.totalSize,t=this.demuxer.reader.requestSliceRange(e,27,282);t instanceof Promise&&(t=await t),J(t);let n=xT(t);J(n),c=n,c.serialNumber===this.bitstream.serialNumber&&l.push(c)}J(c.granulePosition!==-1);let u=null,d,f,p=c,m=0;if(c.headerStartPos===r.startPage.headerStartPos)d=this.granulePositionToTimestampInSamples(0),f=!0,u=0;else{d=0,f=!1;for(let e=c.lacingValues.length-1;e>=0;e--)if(c.lacingValues[e]<255){u=e+1;break}if(u===null)throw Error(`Invalid page with granule position: no packets end on this page.`);m=u-1;let e={data:AC,endPage:p,endSegmentIndex:m};if(await this.demuxer.findNextPacketStart(e)){let e=ET(l,c,u);J(e);let t=TT(l,e.page,e.segmentIndex);t&&(c=t.page,u=t.segmentIndex)}else for(;;){let e=ET(l,c,u);if(!e)break;let t=TT(l,e.page,e.segmentIndex);if(!t)break;if(c=t.page,u=t.segmentIndex,e.page.headerStartPos!==p.headerStartPos){p=e.page,m=e.segmentIndex;break}}}let h=null,g=null;for(;c!==null;){J(u!==null);let e=await this.demuxer.readPacket(c,u);if(!e)break;if(!(c.headerStartPos===r.startPage.headerStartPos&&u<r.startSegmentIndex)){let r=this.createEncodedPacketFromOggPacket(e,{timestampInSamples:d,vorbisLastBlocksize:g?.vorbisBlockSize??null},t);J(r);let i=this.encodedPacketToMetadata.get(r);if(J(i),!f&&e.endPage.headerStartPos===p.headerStartPos&&e.endSegmentIndex===m?(d=this.granulePositionToTimestampInSamples(c.granulePosition),f=!0,r=this.createEncodedPacketFromOggPacket(e,{timestampInSamples:d-i.durationInSamples,vorbisLastBlocksize:g?.vorbisBlockSize??null},t),J(r),i=this.encodedPacketToMetadata.get(r),J(i)):d+=i.durationInSamples,h=r,g=i,f&&(Math.max(d,0)>n||Math.max(i.timestampInSamples,0)===n))break}let i=await this.demuxer.findNextPacketStart(e);if(!i)break;c=i.startPage,u=i.startSegmentIndex}return h}async getPacketSequential(e,t){let n=await this.sequentialScanMutex.acquire();try{let n=cx(e*this.internalSampleRate);e=n/this.internalSampleRate;let r=Jb(this.sequentialScanCache,n,e=>e.timestampInSamples),i;if(r!==-1){let e=this.sequentialScanCache[r];i=this.createEncodedPacketFromOggPacket(e.packet,{timestampInSamples:e.timestampInSamples,vorbisLastBlocksize:e.vorbisLastBlockSize},t)}else i=await this.getFirstPacket(t);let a=0;for(;i&&i.timestamp<e;){let n=await this.getNextPacket(i,t);if(!n||n.timestamp>e)break;if(i=n,a++,a===100){a=0;let e=this.encodedPacketToMetadata.get(i);J(e),this.sequentialScanCache.length>0&&J(Ob(this.sequentialScanCache).timestampInSamples<=e.timestampInSamples),this.sequentialScanCache.push(e)}}return i}finally{n()}}getKeyPacket(e,t){return this.getPacket(e,t)}getNextKeyPacket(e,t){return this.getNextPacket(e,t)}},TT=(e,t,n)=>{let r=t,i=n;outer:for(;;){for(i--;i>=0;i--)if(r.lacingValues[i]<255){i++;break outer}if(J(i===-1),!(r.headerType&1)){i=0;break}let t=Zb(e,e=>e.headerStartPos<r.headerStartPos);if(!t)return null;r=t,i=r.lacingValues.length}if(J(i!==-1),i===r.lacingValues.length){let t=e[e.indexOf(r)+1];J(t),r=t,i=0}return{page:r,segmentIndex:i}},ET=(e,t,n)=>{if(n>0)return{page:t,segmentIndex:n-1};let r=Zb(e,e=>e.headerStartPos<t.headerStartPos);return r?{page:r,segmentIndex:r.lacingValues.length-1}:null},DT;(function(e){e[e.PCM=1]=`PCM`,e[e.IEEE_FLOAT=3]=`IEEE_FLOAT`,e[e.ALAW=6]=`ALAW`,e[e.MULAW=7]=`MULAW`,e[e.EXTENSIBLE=65534]=`EXTENSIBLE`})(DT||={});var OT=class extends TC{constructor(e){super(e),this.metadataPromise=null,this.dataStart=-1,this.dataSize=-1,this.audioInfo=null,this.tracks=[],this.lastKnownPacketIndex=0,this.metadataTags={},this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{let e=this.reader.requestSlice(0,12);e instanceof Promise&&(e=await e),J(e);let t=XE(e,4),n=t!==`RIFX`,r=t===`RF64`,i=BE(e,n),a=r?this.reader.fileSize:Math.min(i+8,this.reader.fileSize??1/0);if(XE(e,4)!==`WAVE`)throw Error(`Invalid WAVE file - wrong format`);let o=0,s=null,c=e.filePos;for(;a===null||c<a;){let e=this.reader.requestSlice(c,8);if(e instanceof Promise&&(e=await e),!e)break;let t=XE(e,4),i=BE(e,n),l=e.filePos;if(r&&o===0&&t!==`ds64`)throw Error(`Invalid RF64 file: First chunk must be "ds64".`);if(t===`fmt `)await this.parseFmtChunk(l,i,n);else if(t===`data`){if(s??=i,this.dataStart=e.filePos,this.dataSize=Math.min(s,(a??1/0)-this.dataStart),this.reader.fileSize===null)break}else if(t===`ds64`){let e=this.reader.requestSlice(l,i);if(e instanceof Promise&&(e=await e),!e)break;let t=WE(e,n);s=WE(e,n),a=Math.min(t+8,this.reader.fileSize??1/0)}else t===`LIST`?await this.parseListChunk(l,i,n):(t===`ID3 `||t===`id3 `)&&await this.parseId3Chunk(l,i);c=l+i+(i&1),o++}if(!this.audioInfo)throw Error(`Invalid WAVE file - missing "fmt " chunk`);if(this.dataStart===-1)throw Error(`Invalid WAVE file - missing "data" chunk`);let l=this.audioInfo.blockSizeInBytes;this.dataSize=Math.floor(this.dataSize/l)*l,this.tracks.push(new bw(this.input,new AT(this)))})()}async parseFmtChunk(e,t,n){let r=this.reader.requestSlice(e,t);if(r instanceof Promise&&(r=await r),!r)return;let i=IE(r,n),a=IE(r,n),o=BE(r,n);r.skip(4);let s=IE(r,n),c;if(c=t===14?8:IE(r,n),t>=18&&i!==357){let e=IE(r,n),a=t-18;if(Math.min(a,e)>=22&&i===DT.EXTENSIBLE){r.skip(6);let e=PE(r,16);i=e[0]|e[1]<<8}}(i===DT.MULAW||i===DT.ALAW)&&(c=8),this.audioInfo={format:i,numberOfChannels:a,sampleRate:o,sampleSizeInBytes:Math.ceil(c/8),blockSizeInBytes:s}}async parseListChunk(e,t,n){let r=this.reader.requestSlice(e,t);if(r instanceof Promise&&(r=await r),!r)return;let i=XE(r,4);if(i!==`INFO`&&i!==`INF0`)return;let a=r.filePos;for(;a<=e+t-8;){r.filePos=a;let e=XE(r,4),t=BE(r,n),i=PE(r,t),o=0;for(let e=0;e<i.length&&i[e]!==0;e++)o++;let s=String.fromCharCode(...i.subarray(0,o));switch(this.metadataTags.raw??={},this.metadataTags.raw[e]=s,e){case`INAM`:case`TITL`:this.metadataTags.title??=s;break;case`TIT3`:this.metadataTags.description??=s;break;case`IART`:this.metadataTags.artist??=s;break;case`IPRD`:this.metadataTags.album??=s;break;case`IPRT`:case`ITRK`:case`TRCK`:{let e=s.split(`/`),t=Number.parseInt(e[0],10),n=e[1]&&Number.parseInt(e[1],10);Number.isInteger(t)&&t>0&&(this.metadataTags.trackNumber??=t),n&&Number.isInteger(n)&&n>0&&(this.metadataTags.tracksTotal??=n)}break;case`ICRD`:case`IDIT`:{let e=new Date(s);Number.isNaN(e.getTime())||(this.metadataTags.date??=e)}break;case`YEAR`:{let e=Number.parseInt(s,10);Number.isInteger(e)&&e>0&&(this.metadataTags.date??=new Date(e,0,1))}break;case`IGNR`:case`GENR`:this.metadataTags.genre??=s;break;case`ICMT`:case`CMNT`:case`COMM`:this.metadataTags.comment??=s;break}a+=8+t+(t&1)}}async parseId3Chunk(e,t){let n=this.reader.requestSlice(e,t);if(n instanceof Promise&&(n=await n),!n)return;let r=nD(n);if(r){let i=t-10;r.size=Math.min(r.size,i),r.size>0&&rD(n.slice(e+10,r.size),r,this.metadataTags)}}getCodec(){if(J(this.audioInfo),this.audioInfo.format===DT.MULAW)return`ulaw`;if(this.audioInfo.format===DT.ALAW)return`alaw`;if(this.audioInfo.format===DT.PCM){if(this.audioInfo.sampleSizeInBytes===1)return`pcm-u8`;if(this.audioInfo.sampleSizeInBytes===2)return`pcm-s16`;if(this.audioInfo.sampleSizeInBytes===3)return`pcm-s24`;if(this.audioInfo.sampleSizeInBytes===4)return`pcm-s32`}return this.audioInfo.format===DT.IEEE_FLOAT&&this.audioInfo.sampleSizeInBytes===4?`pcm-f32`:null}async getMimeType(){return`audio/wav`}async computeDuration(){await this.readMetadata();let e=this.tracks[0];return J(e),e.computeDuration()}async getTracks(){return await this.readMetadata(),this.tracks}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}},kT=2048,AT=class{constructor(e){this.demuxer=e}getId(){return 1}getNumber(){return 1}getCodec(){return this.demuxer.getCodec()}getInternalCodecId(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.format}async getDecoderConfig(){let e=this.demuxer.getCodec();return e?(J(this.demuxer.audioInfo),{codec:e,numberOfChannels:this.demuxer.audioInfo.numberOfChannels,sampleRate:this.demuxer.audioInfo.sampleRate}):null}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}getNumberOfChannels(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.numberOfChannels}getSampleRate(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}getTimeResolution(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}getName(){return null}getLanguageCode(){return`und`}getDisposition(){return{...zx}}async getFirstTimestamp(){return 0}async getPacketAtIndex(e,t){J(e>=0),J(this.demuxer.audioInfo);let n=e*kT*this.demuxer.audioInfo.blockSizeInBytes;if(n>=this.demuxer.dataSize)return null;let r=Math.min(kT*this.demuxer.audioInfo.blockSizeInBytes,this.demuxer.dataSize-n);if(this.demuxer.reader.fileSize===null){let e=this.demuxer.reader.requestSlice(this.demuxer.dataStart+n,r);if(e instanceof Promise&&(e=await e),!e)return null}let i;if(t.metadataOnly)i=AC;else{let e=this.demuxer.reader.requestSlice(this.demuxer.dataStart+n,r);e instanceof Promise&&(e=await e),J(e),i=PE(e,r)}let a=e*kT/this.demuxer.audioInfo.sampleRate,o=r/this.demuxer.audioInfo.blockSizeInBytes/this.demuxer.audioInfo.sampleRate;return this.demuxer.lastKnownPacketIndex=Math.max(e,this.demuxer.lastKnownPacketIndex),new jC(i,`key`,a,o,e,r)}getFirstPacket(e){return this.getPacketAtIndex(0,e)}async getPacket(e,t){J(this.demuxer.audioInfo);let n=Math.floor(Math.min(e*this.demuxer.audioInfo.sampleRate/kT,(this.demuxer.dataSize-1)/(kT*this.demuxer.audioInfo.blockSizeInBytes)));if(n<0)return null;let r=await this.getPacketAtIndex(n,t);if(r)return r;if(n===0)return null;J(this.demuxer.reader.fileSize===null);let i=await this.getPacketAtIndex(this.demuxer.lastKnownPacketIndex,t);for(;i;){let e=await this.getNextPacket(i,t);if(!e)break;i=e}return i}getNextPacket(e,t){J(this.demuxer.audioInfo);let n=Math.round(e.timestamp*this.demuxer.audioInfo.sampleRate/kT);return this.getPacketAtIndex(n+1,t)}getKeyPacket(e,t){return this.getPacket(e,t)}getNextKeyPacket(e,t){return this.getNextPacket(e,t)}},jT=e=>{let t=e.filePos,n=new Vx(PE(e,9));if(n.readBits(12)!==4095||(n.skipBits(1),n.readBits(2)!==0))return null;let r=n.readBits(1),i=n.readBits(2)+1,a=n.readBits(4);if(a===15)return null;n.skipBits(1);let o=n.readBits(3);if(o===0)throw Error(`ADTS frames with channel configuration 0 are not supported.`);n.skipBits(1),n.skipBits(1),n.skipBits(1),n.skipBits(1);let s=n.readBits(13);n.skipBits(11);let c=n.readBits(2)+1;if(c!==1)throw Error(`ADTS frames with more than one AAC frame are not supported.`);let l=null;return r===1?e.filePos-=2:l=n.readBits(16),{objectType:i,samplingFrequencyIndex:a,channelConfiguration:o,frameLength:s,numberOfAacFrames:c,crcCheck:l,startPos:t}},MT=1024,NT=class extends TC{constructor(e){super(e),this.metadataPromise=null,this.firstFrameHeader=null,this.loadedSamples=[],this.metadataTags=null,this.tracks=[],this.readingMutex=new Wb,this.lastSampleLoaded=!1,this.lastLoadedPos=0,this.nextTimestampInSamples=0,this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{for(;!this.firstFrameHeader&&!this.lastSampleLoaded;)await this.advanceReader();J(this.firstFrameHeader),this.tracks=[new bw(this.input,new PT(this))]})()}async advanceReader(){if(this.lastLoadedPos===0)for(;;){let e=this.reader.requestSlice(this.lastLoadedPos,10);if(e instanceof Promise&&(e=await e),!e){this.lastSampleLoaded=!0;return}let t=nD(e);if(!t)break;this.lastLoadedPos=e.filePos+t.size}let e=this.reader.requestSliceRange(this.lastLoadedPos,7,9);if(e instanceof Promise&&(e=await e),!e){this.lastSampleLoaded=!0;return}let t=jT(e);if(!t){this.lastSampleLoaded=!0;return}if(this.reader.fileSize!==null&&t.startPos+t.frameLength>this.reader.fileSize){this.lastSampleLoaded=!0;return}this.firstFrameHeader||=t;let n=Hx[t.samplingFrequencyIndex];J(n!==void 0);let r=MT/n,i={timestamp:this.nextTimestampInSamples/n,duration:r,dataStart:t.startPos,dataSize:t.frameLength};this.loadedSamples.push(i),this.nextTimestampInSamples+=MT,this.lastLoadedPos=t.startPos+t.frameLength}async getMimeType(){return`audio/aac`}async getTracks(){return await this.readMetadata(),this.tracks}async computeDuration(){await this.readMetadata();let e=this.tracks[0];return J(e),e.computeDuration()}async getMetadataTags(){let e=await this.readingMutex.acquire();try{if(await this.readMetadata(),this.metadataTags)return this.metadataTags;this.metadataTags={};let e=0;for(;;){let t=this.reader.requestSlice(e,10);if(t instanceof Promise&&(t=await t),!t)break;let n=nD(t);if(!n)break;let r=this.reader.requestSlice(t.filePos,n.size);if(r instanceof Promise&&(r=await r),!r)break;rD(r,n,this.metadataTags),e=t.filePos+n.size}return this.metadataTags}finally{e()}}},PT=class{constructor(e){this.demuxer=e}getId(){return 1}getNumber(){return 1}async getFirstTimestamp(){return 0}getTimeResolution(){return this.getSampleRate()/MT}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}getName(){return null}getLanguageCode(){return`und`}getCodec(){return`aac`}getInternalCodecId(){return J(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.objectType}getNumberOfChannels(){J(this.demuxer.firstFrameHeader);let e=Ux[this.demuxer.firstFrameHeader.channelConfiguration];return J(e!==void 0),e}getSampleRate(){J(this.demuxer.firstFrameHeader);let e=Hx[this.demuxer.firstFrameHeader.samplingFrequencyIndex];return J(e!==void 0),e}getDisposition(){return{...zx}}async getDecoderConfig(){return J(this.demuxer.firstFrameHeader),{codec:`mp4a.40.${this.demuxer.firstFrameHeader.objectType}`,numberOfChannels:this.getNumberOfChannels(),sampleRate:this.getSampleRate()}}async getPacketAtIndex(e,t){if(e===-1)return null;let n=this.demuxer.loadedSamples[e];if(!n)return null;let r;if(t.metadataOnly)r=AC;else{let e=this.demuxer.reader.requestSlice(n.dataStart,n.dataSize);if(e instanceof Promise&&(e=await e),!e)return null;r=PE(e,n.dataSize)}return new jC(r,`key`,n.timestamp,n.duration,e,n.dataSize)}getFirstPacket(e){return this.getPacketAtIndex(0,e)}async getNextPacket(e,t){let n=await this.demuxer.readingMutex.acquire();try{let n=qb(this.demuxer.loadedSamples,e.timestamp,e=>e.timestamp);if(n===-1)throw Error(`Packet was not created from this track.`);let r=n+1;for(;r>=this.demuxer.loadedSamples.length&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(r,t)}finally{n()}}async getPacket(e,t){let n=await this.demuxer.readingMutex.acquire();try{for(;;){let n=Jb(this.demuxer.loadedSamples,e,e=>e.timestamp);if(n===-1&&this.demuxer.loadedSamples.length>0)return null;if(this.demuxer.lastSampleLoaded||n>=0&&n+1<this.demuxer.loadedSamples.length)return this.getPacketAtIndex(n,t);await this.demuxer.advanceReader()}}finally{n()}}getKeyPacket(e,t){return this.getPacket(e,t)}getNextKeyPacket(e,t){return this.getNextPacket(e,t)}},FT=e=>e===0?null:e===1?192:e>=2&&e<=5?144*2**e:e===6?`uncommon-u8`:e===7?`uncommon-u16`:e>=8&&e<=15?2**e:null,IT=(e,t)=>{switch(e){case 0:return t;case 1:return 88200;case 2:return 176400;case 3:return 192e3;case 4:return 8e3;case 5:return 16e3;case 6:return 22050;case 7:return 24e3;case 8:return 32e3;case 9:return 44100;case 10:return 48e3;case 11:return 96e3;case 12:return`uncommon-u8`;case 13:return`uncommon-u16`;case 14:return`uncommon-u16-10`;default:return null}},LT=e=>{let t=0,n=new Vx(PE(e,1));for(;n.readBits(1)===1;)t++;if(t===0)return n.readBits(7);let r=[],i=t-1,a=new Vx(PE(e,i)),o=8-t-1;for(let e=0;e<o;e++)r.unshift(n.readBits(1));for(let e=0;e<i;e++)for(let e=0;e<8;e++){let t=a.readBits(1);e<2||r.unshift(t)}return r.reduce((e,t,n)=>e|t<<n,0)},RT=(e,t)=>{if(t===`uncommon-u16`)return LE(e)+1;if(t===`uncommon-u8`)return FE(e)+1;if(typeof t==`number`)return t;tx(t),J(!1)},zT=(e,t)=>t===`uncommon-u16`?LE(e):t===`uncommon-u16-10`?LE(e)*10:t===`uncommon-u8`?FE(e):typeof t==`number`?t:null,BT=e=>{let t=0;for(let n of e){t^=n;for(let e=0;e<8;e++)t&128?t=t<<1^7:t<<=1,t&=255}return t},VT=class extends TC{constructor(e){super(e),this.loadedSamples=[],this.metadataPromise=null,this.track=null,this.metadataTags={},this.audioInfo=null,this.lastLoadedPos=null,this.blockingBit=null,this.readingMutex=new Wb,this.lastSampleLoaded=!1,this.reader=e._reader}async computeDuration(){return await this.readMetadata(),J(this.track),this.track.computeDuration()}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}async getTracks(){return await this.readMetadata(),J(this.track),[this.track]}async getMimeType(){return`audio/flac`}async readMetadata(){let e=4;return this.metadataPromise??=(async()=>{for(;this.reader.fileSize===null||e<this.reader.fileSize;){let t=this.reader.requestSlice(e,4);if(t instanceof Promise&&(t=await t),e+=4,t===null)throw Error(`Metadata block at position ${e} is too small! Corrupted file.`);J(t);let n=FE(t),r=RE(t),i=(n&128)!=0;switch(n&127){case mC.STREAMINFO:{let t=this.reader.requestSlice(e,r);if(t instanceof Promise&&(t=await t),J(t),t===null)throw Error(`StreamInfo block at position ${e} is too small! Corrupted file.`);let n=PE(t,34),i=new Vx(n),a=i.readBits(16),o=i.readBits(16),s=i.readBits(24),c=i.readBits(24),l=i.readBits(20),u=i.readBits(3)+1;i.readBits(5);let d=i.readBits(36);i.skipBits(128);let f=new Uint8Array(42);f.set(new Uint8Array([102,76,97,67]),0),f.set(new Uint8Array([128,0,0,34]),4),f.set(n,8),this.audioInfo={numberOfChannels:u,sampleRate:l,totalSamples:d,minimumBlockSize:a,maximumBlockSize:o,minimumFrameSize:s,maximumFrameSize:c,description:f},this.track=new bw(this.input,new HT(this));break}case mC.VORBIS_COMMENT:{let t=this.reader.requestSlice(e,r);t instanceof Promise&&(t=await t),J(t),hC(PE(t,r),this.metadataTags);break}case mC.PICTURE:{let t=this.reader.requestSlice(e,r);t instanceof Promise&&(t=await t),J(t);let n=Z(t),i=Z(t),a=Nb.decode(PE(t,i)),o=Z(t),s=Nb.decode(PE(t,o));t.skip(16);let c=Z(t),l=PE(t,c);this.metadataTags.images??=[],this.metadataTags.images.push({data:l,mimeType:a,kind:n===3?`coverFront`:n===4?`coverBack`:`unknown`,description:s});break}default:break}if(e+=r,i){this.lastLoadedPos=e;break}}})()}async readNextFlacFrame({startPos:e,isFirstPacket:t}){J(this.audioInfo);let n=this.audioInfo.maximumFrameSize+16,r=await this.reader.requestSliceRange(e,this.audioInfo.minimumFrameSize,n);if(!r)return null;let i=this.readFlacFrameHeader({slice:r,isFirstPacket:t});if(!i)return null;for(r.filePos=e+this.audioInfo.minimumFrameSize;;){if(r.filePos>r.end-6)return{num:i.num,blockSize:i.blockSize,sampleRate:i.sampleRate,size:r.end-e,isLastFrame:!0};if(FE(r)===255){let t=r.filePos;if(FE(r)!==(this.blockingBit===1?249:248)){r.filePos=t;continue}r.skip(-2);let n=r.filePos-e,a=this.readFlacFrameHeader({slice:r,isFirstPacket:!1});if(!a){r.filePos=t;continue}if(this.blockingBit===0){if(a.num-i.num!==1){r.filePos=t;continue}}else if(a.num-i.num!==i.blockSize){r.filePos=t;continue}return{num:i.num,blockSize:i.blockSize,sampleRate:i.sampleRate,size:n,isLastFrame:!1}}}}readFlacFrameHeader({slice:e,isFirstPacket:t}){let n=e.filePos,r=new Vx(PE(e,4));if(r.readBits(15)!==32764)return null;if(this.blockingBit===null)J(t),this.blockingBit=r.readBits(1);else if(this.blockingBit===1){if(J(!t),r.readBits(1)!==1)return null}else if(this.blockingBit===0){if(J(!t),r.readBits(1)!==0)return null}else throw Error(`Invalid blocking bit`);let i=FT(r.readBits(4));if(!i)return null;J(this.audioInfo);let a=IT(r.readBits(4),this.audioInfo.sampleRate);if(!a||(r.readBits(4),r.readBits(3),r.readBits(1)!==0))return null;let o=LT(e),s=RT(e,i),c=zT(e,a);if(c===null||c!==this.audioInfo.sampleRate)return null;let l=e.filePos-n,u=FE(e);return e.skip(-l),e.skip(-1),u===BT(PE(e,l))?{num:o,blockSize:s,sampleRate:c}:null}async advanceReader(){await this.readMetadata(),J(this.lastLoadedPos!==null),J(this.audioInfo);let e=this.lastLoadedPos,t=await this.readNextFlacFrame({startPos:e,isFirstPacket:this.loadedSamples.length===0});if(!t){this.lastSampleLoaded=!0;return}let n=this.loadedSamples[this.loadedSamples.length-1],r={blockOffset:n?n.blockOffset+n.blockSize:0,blockSize:t.blockSize,byteOffset:e,byteSize:t.size};if(this.lastLoadedPos+=t.size,this.loadedSamples.push(r),t.isLastFrame){this.lastSampleLoaded=!0;return}}},HT=class{constructor(e){this.demuxer=e}getId(){return 1}getNumber(){return 1}getCodec(){return`flac`}getInternalCodecId(){return null}getNumberOfChannels(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.numberOfChannels}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}getSampleRate(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}getName(){return null}getLanguageCode(){return`und`}getTimeResolution(){return J(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}getDisposition(){return{...zx}}async getFirstTimestamp(){return 0}async getDecoderConfig(){return J(this.demuxer.audioInfo),{codec:`flac`,numberOfChannels:this.demuxer.audioInfo.numberOfChannels,sampleRate:this.demuxer.audioInfo.sampleRate,description:this.demuxer.audioInfo.description}}async getPacket(e,t){if(J(this.demuxer.audioInfo),e<0)throw Error(`Timestamp cannot be negative`);let n=await this.demuxer.readingMutex.acquire();try{for(;;){let n=Jb(this.demuxer.loadedSamples,e,e=>e.blockOffset/this.demuxer.audioInfo.sampleRate);if(n===-1){await this.demuxer.advanceReader();continue}let r=this.demuxer.loadedSamples[n];if(r.blockOffset/this.demuxer.audioInfo.sampleRate+r.blockSize/this.demuxer.audioInfo.sampleRate<=e){if(this.demuxer.lastSampleLoaded)return this.getPacketAtIndex(this.demuxer.loadedSamples.length-1,t);await this.demuxer.advanceReader();continue}return this.getPacketAtIndex(n,t)}}finally{n()}}async getNextPacket(e,t){let n=await this.demuxer.readingMutex.acquire();try{let n=e.sequenceNumber+1;if(this.demuxer.lastSampleLoaded&&n>=this.demuxer.loadedSamples.length)return null;for(;n>=this.demuxer.loadedSamples.length&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(n,t)}finally{n()}}getKeyPacket(e,t){return this.getPacket(e,t)}getNextKeyPacket(e,t){return this.getNextPacket(e,t)}async getPacketAtIndex(e,t){let n=this.demuxer.loadedSamples[e];if(!n)return null;let r;if(t.metadataOnly)r=AC;else{let e=this.demuxer.reader.requestSlice(n.byteOffset,n.byteSize);if(e instanceof Promise&&(e=await e),!e)return null;r=PE(e,n.byteSize)}J(this.demuxer.audioInfo);let i=n.blockOffset/this.demuxer.audioInfo.sampleRate,a=n.blockSize/this.demuxer.audioInfo.sampleRate;return new jC(r,`key`,i,a,e,n.byteSize)}async getFirstPacket(e){for(;this.demuxer.loadedSamples.length===0&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(0,e)}},UT=9e4,WT=e=>{let t=`video/MP2T`,n=[...new Set(e.filter(Boolean))];return n.length>0&&(t+=`; codecs="${n.join(`, `)}"`),t},GT=class extends TC{constructor(e){super(e),this.metadataPromise=null,this.elementaryStreams=[],this.tracks=[],this.packetOffset=0,this.packetStride=-1,this.sectionEndPositions=[],this.seekChunkSize=5*1024*1024,this.minReferencePointByteDistance=-1,this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{let e=this.reader.requestSlice(0,205);e instanceof Promise&&(e=await e),J(e);let t=PE(e,205);if(t[0]===71&&t[188]===71)this.packetOffset=0,this.packetStride=188;else if(t[0]===71&&t[204]===71)this.packetOffset=0,this.packetStride=204;else if(t[4]===71&&t[196]===71)this.packetOffset=4,this.packetStride=192;else throw Error(`Unreachable.`);this.minReferencePointByteDistance=256*this.packetStride;let n=this.packetOffset,r=null,i=!1,a=!1;for(;;){let e=await this.readPacketHeader(n);if(!e)break;if(e.payloadUnitStartIndicator===0){n+=this.packetStride;continue}let t=await this.readSection(n,!0,!a);if(!t)break;let o=!1;if(!a&&t.pid!==0&&!(t.payload[0]===0&&t.payload[1]===0&&t.payload[2]===1)){let e=new Vx(t.payload),n=e.readAlignedByte();e.skipBits(8*n),o=e.readBits(8)===2}if(t.pid===0&&!i){let e=new Vx(t.payload),n=e.readAlignedByte();e.skipBits(8*n),e.skipBits(14);let a=e.readBits(10);for(e.skipBits(40);8*(a+3)-e.pos>32;){let t=e.readBits(16);if(e.skipBits(3),t!==0){if(r!==null)throw Error(`Only files with a single program are supported.`);r=e.readBits(13)}}if(r===null)throw Error(`Program Association Table must link to a Program Map Table.`);i=!0}else if((t.pid===r||o)&&!a){let e=new Vx(t.payload),n=e.readAlignedByte();e.skipBits(8*n),e.skipBits(12);let r=e.readBits(12);e.skipBits(43),e.readBits(13),e.skipBits(6);let i=e.readBits(10);for(e.skipBits(8*i);8*(r+3)-e.pos>32;){let t=e.readBits(8);e.skipBits(3);let n=e.readBits(13);e.skipBits(6);let r=e.readBits(10),i=e.pos+8*r,a=!1,o=!1;for(;e.pos<i;){let t=e.readBits(8),n=e.readBits(8);t===106?a=!0:(t===122||t===204)&&(o=!0),e.skipBits(8*n)}let s=null;switch(t){case 3:case 4:case 15:s={type:`audio`,codec:t===15?`aac`:`mp3`,aacCodecInfo:null,numberOfChannels:-1,sampleRate:-1};break;case 27:case 36:s={type:`video`,codec:t===27?`avc`:`hevc`,avcCodecInfo:null,hevcCodecInfo:null,colorSpace:{primaries:null,transfer:null,matrix:null,fullRange:null},width:-1,height:-1,squarePixelWidth:-1,squarePixelHeight:-1,reorderSize:-1};break;case 129:s={type:`audio`,codec:`ac3`,aacCodecInfo:null,numberOfChannels:-1,sampleRate:-1};break;case 135:s={type:`audio`,codec:`eac3`,aacCodecInfo:null,numberOfChannels:-1,sampleRate:-1};break;case 6:o?s={type:`audio`,codec:`eac3`,aacCodecInfo:null,numberOfChannels:-1,sampleRate:-1}:a&&(s={type:`audio`,codec:`ac3`,aacCodecInfo:null,numberOfChannels:-1,sampleRate:-1});break;default:console.warn(`Unsupported stream_type 0x${t.toString(16)}; ignoring stream.`)}s&&this.elementaryStreams.push({demuxer:this,pid:n,streamType:t,initialized:!1,firstSection:null,info:s,referencePesPackets:[]})}a=!0}else{let e=this.elementaryStreams.find(e=>e.pid===t.pid);if(e&&!e.initialized){let n=qT(t);if(!n)throw Error(`Couldn't read first PES packet for Elementary Stream with PID ${e.pid}`);if(e.firstSection=t,e.info.type===`video`)if(e.info.codec===`avc`){if(e.info.avcCodecInfo=HS(n.data),!e.info.avcCodecInfo)throw Error(`Invalid AVC video stream; could not extract AVCDecoderConfigurationRecord from first packet.`);let t=e.info.avcCodecInfo.sequenceParameterSets[0];J(t);let r=KS(t);e.info.width=r.displayWidth,e.info.height=r.displayHeight,r.pixelAspectRatio.num>r.pixelAspectRatio.den?(e.info.squarePixelWidth=Math.round(e.info.width*r.pixelAspectRatio.num/r.pixelAspectRatio.den),e.info.squarePixelHeight=e.info.height):(e.info.squarePixelWidth=e.info.width,e.info.squarePixelHeight=Math.round(e.info.height*r.pixelAspectRatio.den/r.pixelAspectRatio.num)),e.info.colorSpace={primaries:Lb[r.colourPrimaries],transfer:zb[r.transferCharacteristics],matrix:Vb[r.matrixCoefficients],fullRange:!!r.fullRangeFlag},e.info.reorderSize=r.maxDecFrameBuffering,e.initialized=!0}else if(e.info.codec===`hevc`){if(e.info.hevcCodecInfo=ZS(n.data),!e.info.hevcCodecInfo)throw Error(`Invalid HEVC video stream; could not extract HVCDecoderConfigurationRecord from first packet.`);let t=e.info.hevcCodecInfo.arrays.find(e=>e.nalUnitType===MS.SPS_NUT).nalUnits[0];J(t);let r=XS(t);e.info.width=r.displayWidth,e.info.height=r.displayHeight,r.pixelAspectRatio.num>r.pixelAspectRatio.den?(e.info.squarePixelWidth=Math.round(e.info.width*r.pixelAspectRatio.num/r.pixelAspectRatio.den),e.info.squarePixelHeight=e.info.height):(e.info.squarePixelWidth=e.info.width,e.info.squarePixelHeight=Math.round(e.info.height*r.pixelAspectRatio.den/r.pixelAspectRatio.num)),e.info.colorSpace={primaries:Lb[r.colourPrimaries],transfer:zb[r.transferCharacteristics],matrix:Vb[r.matrixCoefficients],fullRange:!!r.fullRangeFlag},e.info.reorderSize=r.maxDecFrameBuffering,e.initialized=!0}else throw Error(`Unhandled.`);else if(e.info.codec===`aac`){let t=jT(ME.tempFromBytes(n.data));if(!t)throw Error(`Invalid AAC audio stream; could not read ADTS frame header from first packet.`);e.info.aacCodecInfo={isMpeg2:!1,objectType:t.objectType},e.info.numberOfChannels=Ux[t.channelConfiguration],e.info.sampleRate=Hx[t.samplingFrequencyIndex],e.initialized=!0}else if(e.info.codec===`mp3`){let t=DS(Z(ME.tempFromBytes(n.data)),n.data.byteLength);if(!t.header)throw Error(`Invalid MP3 audio stream; could not read frame header from first packet.`);e.info.numberOfChannels=t.header.channel===3?1:2,e.info.sampleRate=t.header.sampleRate,e.initialized=!0}else if(e.info.codec===`ac3`){let t=_C(n.data);if(!t)throw Error(`Invalid AC-3 audio stream; could not read sync frame from first packet.`);if(t.fscod===3)throw Error(`Invalid AC-3 audio stream; reserved sample rate code found in first packet.`);e.info.numberOfChannels=gC[t.acmod]+t.lfeon,e.info.sampleRate=kS[t.fscod],e.initialized=!0}else if(e.info.codec===`eac3`){let t=xC(n.data);if(!t)throw Error(`Invalid E-AC-3 audio stream; could not read sync frame from first packet.`);let r=CC(t);if(r===null)throw Error(`Invalid E-AC-3 audio stream; reserved sample rate code found in first packet.`);e.info.numberOfChannels=wC(t),e.info.sampleRate=r,e.initialized=!0}else throw Error(`Unhandled.`)}}if(a&&this.elementaryStreams.every(e=>e.initialized))break;n+=this.packetStride}if(!a)throw i?Error(`No Program Map Table found in the file.`):Error(`No Program Association Table found in the file.`);for(let e of this.elementaryStreams)e.info.type===`video`?this.tracks.push(new yw(this.input,new YT(e))):this.tracks.push(new bw(this.input,new XT(e)))})()}async getTracks(){return await this.readMetadata(),this.tracks}async getMetadataTags(){return{}}async computeDuration(){let e=await this.getTracks(),t=await Promise.all(e.map(e=>e.computeDuration()));return Math.max(0,...t)}async getMimeType(){await this.readMetadata();let e=await this.getTracks();return WT(await Promise.all(e.map(e=>e.getCodecParameterString())))}async readSection(e,t,n=!1){let r=e,i=e,a=[],o=0,s=null,c=!0,l=0;for(;;){let e=await this.readPacket(i);if(i+=this.packetStride,!e)break;if(s){if(e.pid!==s.pid){if(n)break;continue}if(e.payloadUnitStartIndicator===1)break}else{if(e.payloadUnitStartIndicator===0)break;s=e}let u=!!(e.adaptationFieldControl&2),d=!!(e.adaptationFieldControl&1),f=0;if(u&&(f=1+e.body[0],e===s&&f>1&&(l=e.body[1]>>6&1)),d&&(f===0?(a.push(e.body),o+=e.body.byteLength):(a.push(e.body.subarray(f)),o+=e.body.byteLength-f)),r=i,!t&&o>=64){c=!1;break}if(qb(this.sectionEndPositions,r,e=>e)!==-1){c=!1;break}}if(c){let e=Jb(this.sectionEndPositions,r,e=>e);this.sectionEndPositions.splice(e+1,0,r)}if(!s)return null;let u;if(a.length===1)u=a[0];else{let e=a.reduce((e,t)=>e+t.length,0);u=new Uint8Array(e);let t=0;for(let e of a)u.set(e,t),t+=e.length}return{startPos:e,endPos:t?r:null,pid:s.pid,payload:u,randomAccessIndicator:l}}async readPacketHeader(e){let t=this.reader.requestSlice(e,4);if(t instanceof Promise&&(t=await t),!t)return null;if(FE(t)!==71)throw Error(`Invalid TS packet sync byte. Likely an internal bug, please report this file.`);let n=LE(t);n>>15;let r=n>>14&1;n>>13&1;let i=n&8191,a=FE(t);a>>6;let o=a>>4&3;return a&15,{payloadUnitStartIndicator:r,pid:i,adaptationFieldControl:o}}async readPacket(e){let t=this.reader.requestSlice(e,188);if(t instanceof Promise&&(t=await t),!t)return null;let n=PE(t,188);if(n[0]!==71)throw Error(`Invalid TS packet sync byte. Likely an internal bug, please report this file.`);let r=(n[1]<<8)+n[2];r>>15;let i=r>>14&1;r>>13&1;let a=r&8191,o=n[3];o>>6;let s=o>>4&3;return o&15,{payloadUnitStartIndicator:i,pid:a,adaptationFieldControl:s,body:n.subarray(4)}}},KT=e=>{if(e.payload.byteLength<3)return null;let t=new Vx(e.payload);if(t.readBits(24)!==1)return null;let n=t.readBits(8);if(t.skipBits(16),n===188||n===190||n===191||n===240||n===241||n===255||n===242||n===248)return null;t.skipBits(8);let r=t.readBits(2);t.skipBits(14);let i=0;if(r===2||r===3)t.skipBits(4),i+=t.readBits(3)*(1<<30),t.skipBits(1),i+=t.readBits(15)*32768,t.skipBits(1),i+=t.readBits(15);else throw Error(`PES packets without PTS are not currently supported. If you think this file should be supported, please report it.`);return{sectionStartPos:e.startPos,sectionEndPos:e.endPos,pts:i,randomAccessIndicator:e.randomAccessIndicator}},qT=e=>{J(e.endPos!==null);let t=KT(e);if(!t)return null;let n=new Vx(e.payload);n.skipBits(32);let r=n.readBits(16);n.skipBits(16);let i=n.readBits(8),a=n.pos+8*i;n.pos=a;let o=a/8;J(Number.isInteger(o));let s=e.payload.subarray(o,r>0?6+r:e.payload.byteLength);return{...t,data:s}},JT=class e{constructor(e){this.elementaryStream=e,this.packetBuffers=new WeakMap,this.packetSectionStarts=new WeakMap}getId(){return this.elementaryStream.pid}getNumber(){let t=this.elementaryStream.demuxer,n=this.elementaryStream.info.type,r=0;for(let i of t.tracks)if(i.type===n&&r++,J(i._backing instanceof e),i._backing.elementaryStream===this.elementaryStream)break;return r}getCodec(){throw Error(`Not implemented on base class.`)}getInternalCodecId(){return this.elementaryStream.streamType}getName(){return null}getLanguageCode(){return`und`}getDisposition(){return zx}getTimeResolution(){return UT}async computeDuration(){let e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}async getFirstTimestamp(){return(await this.getFirstPacket({metadataOnly:!0}))?.timestamp??0}createEncodedPacket(e,t,n){let r;return r=this.allPacketsAreKeyPackets()||e.randomAccessIndicator===1?`key`:`delta`,new jC(n.metadataOnly?AC:e.data,r,e.pts/UT,Math.max(t/UT,0),e.sequenceNumber,e.data.byteLength)}async getFirstPacket(e){let t=this.elementaryStream.firstSection;J(t);let n=qT(t);J(n);let r=new $T(this.elementaryStream,n),i=new eE(this,r),a=await i.readNext();if(!a)return null;let o=this.createEncodedPacket(a.packet,a.duration,e);return this.packetBuffers.set(o,i),this.packetSectionStarts.set(o,a.packet.sectionStartPos),o}async getNextPacket(e,t){let n=this.packetBuffers.get(e);if(n){let r=await n.readNext();if(!r)return null;this.packetBuffers.delete(e);let i=this.createEncodedPacket(r.packet,r.duration,t);return this.packetBuffers.set(i,n),this.packetSectionStarts.set(i,r.packet.sectionStartPos),i}let r=this.packetSectionStarts.get(e);if(r===void 0)throw Error(`Packet was not created from this track.`);let i=await this.elementaryStream.demuxer.readSection(r,!0);J(i);let a=qT(i);J(a);let o=new $T(this.elementaryStream,a);n=new eE(this,o);let s=e.sequenceNumber;for(;;){let e=await n.readNext();if(!e)return null;if(e.packet.sequenceNumber>s){let r=this.createEncodedPacket(e.packet,e.duration,t);return this.packetBuffers.set(r,n),this.packetSectionStarts.set(r,e.packet.sectionStartPos),r}}}async getNextKeyPacket(e,t){let n=e;for(;;){if(n=await this.getNextPacket(n,t),!n)return null;if(n.type===`key`)return n}}getPacket(e,t){return this.doPacketLookup(e,!1,t)}getKeyPacket(e,t){return this.doPacketLookup(e,!0,t)}async doPacketLookup(e,t,n){let r=cx(e*UT),i=this.elementaryStream.demuxer,{reader:a,seekChunkSize:o}=i,s=this.elementaryStream.pid,c=async(e,t)=>{let n=e;for(;n<t;){let e=await i.readPacketHeader(n);if(!e)return null;if(e.pid===s&&e.payloadUnitStartIndicator===1){let e=await i.readSection(n,!1);if(!e)return null;let t=KT(e);if(t)return t}n+=i.packetStride}return null},l=this.elementaryStream.firstSection;J(l);let u=KT(l);if(J(u),r<u.pts)return null;let d,f=this.elementaryStream.referencePesPackets,p=Jb(f,r,e=>e.pts),m=p===-1?null:f[p];if(m&&r-m.pts<9e4/2)d=m.sectionStartPos;else{let e=0;if(a.fileSize!==null){let t=Math.ceil(a.fileSize/o);if(t>1){let n=0,a=t-1;for(e=n;n<=a;){let t=Math.floor((n+a)/2),s=ux(t*o,i.packetStride)+u.sectionStartPos,l=await c(s,s+o);if(!l){a=t-1;continue}l.pts<=r?(e=t,n=t+1):a=t-1}}}d=ux(e*o,i.packetStride)+u.sectionStartPos}let h=await c(d,a.fileSize??1/0);h||=u;let g=this.getReorderSize(),_=async(e,t)=>{let a=await i.readSection(e,!0);J(a);let o=qT(a);J(o);let s=new $T(this.elementaryStream,o),c=new eE(this,s);for(;!((Ob(c.presentationOrderPackets)?.pts??-1/0)>=r||!await c.readNextPacket()););let l=Qb(c.presentationOrderPackets,t);if(l===-1)return null;let u=c.presentationOrderPackets[l],d=l===0?0:u.pts-c.presentationOrderPackets[l-1].pts;for(;c.decodeOrderPackets[0]!==u;)c.decodeOrderPackets.shift();c.lastDuration=d;let f=await c.readNext();J(f);let p=this.createEncodedPacket(f.packet,f.duration,n);return this.packetBuffers.set(p,c),this.packetSectionStarts.set(p,f.packet.sectionStartPos),p};if(!t||this.allPacketsAreKeyPackets()){outer:for(;;){let e=h.sectionStartPos+i.packetStride;for(;;){let t=await i.readPacketHeader(e);if(!t)break outer;if(t.pid===s&&t.payloadUnitStartIndicator===1){let t=await i.readSection(e,!1);if(t){let e=KT(t);if(e){if(e.pts>r)break outer;h=e,ZT(this.elementaryStream,e);break}}}e+=i.packetStride}}outer:for(let e=0;e<g;e++){let e=h.sectionStartPos-i.packetStride;for(;e>=i.packetOffset;){let t=await i.readPacketHeader(e);if(!t)break outer;if(t.pid===s&&t.payloadUnitStartIndicator===1){let t=await i.readSection(e,!1);if(t){let e=KT(t);if(e){h=e;break}}}e-=i.packetStride}}return _(h.sectionStartPos,e=>e.pts<=r)}else{let e=d,t=null;for(;;){let n=null,l=e<=u.sectionStartPos,d;l?(d=u,n=u):d=await c(e,a.fileSize??1/0);let f=!1,p=0;outer:for(;d&&!(t!==null&&d.sectionStartPos>=t||(d.randomAccessIndicator===1&&d.pts<=r&&(n=d),d.pts>r&&(f=!0),f&&(p++,p>=g)));){let e=d.sectionStartPos+i.packetStride;for(;;){let t=await i.readPacketHeader(e);if(!t)break outer;if(t.pid===s&&t.payloadUnitStartIndicator===1){let t=await i.readSection(e,!1);if(t&&(d=KT(t),d)){ZT(this.elementaryStream,d);break}}e+=i.packetStride}}if(n){let e=n;if(p===0)outer:for(let t=0;t<g-1;t++){let t=e.sectionStartPos-i.packetStride;for(;t>=i.packetOffset;){let n=await i.readPacketHeader(t);if(!n)break outer;if(n.pid===s&&n.payloadUnitStartIndicator===1){let n=await i.readSection(t,!1);if(n){let t=KT(n);if(t){e=t;break}}}t-=i.packetStride}}let t=await _(e.sectionStartPos,e=>e.pts<=r&&e.randomAccessIndicator===1);return J(t),t}J(!l),t=e,e=Math.max(ux(e-u.sectionStartPos-o,i.packetStride)+u.sectionStartPos,u.sectionStartPos)}}}},YT=class extends JT{constructor(e){super(e),this.elementaryStream=e,this.decoderConfig={codec:aS({width:this.elementaryStream.info.width,height:this.elementaryStream.info.height,codec:this.elementaryStream.info.codec,codecDescription:null,colorSpace:this.elementaryStream.info.colorSpace,avcType:1,avcCodecInfo:this.elementaryStream.info.avcCodecInfo,hevcCodecInfo:this.elementaryStream.info.hevcCodecInfo,vp9CodecInfo:null,av1CodecInfo:null}),codedWidth:this.elementaryStream.info.width,codedHeight:this.elementaryStream.info.height,displayAspectWidth:this.elementaryStream.info.squarePixelWidth,displayAspectHeight:this.elementaryStream.info.squarePixelHeight,colorSpace:this.elementaryStream.info.colorSpace}}getCodec(){return this.elementaryStream.info.codec}getCodedWidth(){return this.elementaryStream.info.width}getCodedHeight(){return this.elementaryStream.info.height}getSquarePixelWidth(){return this.elementaryStream.info.squarePixelWidth}getSquarePixelHeight(){return this.elementaryStream.info.squarePixelHeight}getRotation(){return 0}async getColorSpace(){return this.elementaryStream.info.colorSpace}async canBeTransparent(){return!1}async getDecoderConfig(){return this.decoderConfig}allPacketsAreKeyPackets(){return!1}getReorderSize(){return this.elementaryStream.info.reorderSize}},XT=class extends JT{constructor(e){super(e),this.elementaryStream=e}getCodec(){return this.elementaryStream.info.codec}getNumberOfChannels(){return this.elementaryStream.info.numberOfChannels}getSampleRate(){return this.elementaryStream.info.sampleRate}async getDecoderConfig(){return{codec:sS({codec:this.elementaryStream.info.codec,codecDescription:null,aacCodecInfo:this.elementaryStream.info.aacCodecInfo}),numberOfChannels:this.elementaryStream.info.numberOfChannels,sampleRate:this.elementaryStream.info.sampleRate}}allPacketsAreKeyPackets(){return!0}getReorderSize(){return 1}},ZT=(e,t)=>{let n=e.referencePesPackets,r=Jb(n,t.sectionStartPos,e=>e.sectionStartPos);if(r>=0){let i=n[r];if(t.pts<=i.pts)return!1;let a=e.demuxer.minReferencePointByteDistance;if(t.sectionStartPos-i.sectionStartPos<a)return!1;if(r<n.length-1){let e=n[r+1];if(e.pts<t.pts||e.sectionStartPos-t.sectionStartPos<a)return!1}}return n.splice(r+1,0,t),!0},QT=async e=>{J(!e.suppliedPacket);let t=e.elementaryStream;if(t.info.type===`video`){let n=t.info.codec,r=1024;if(n!==`avc`&&n!==`hevc`)throw Error(`Unhandled.`);let i=null;for(;;){let t=e.ensureBuffered(r);if(t instanceof Promise&&(t=await t),t===0)break;let a=e.currentPos,o=e.readBytes(t),s=o.byteLength,c=0;for(;c<s;){let t=o.indexOf(0,c);if(t===-1||t>=s)break;c=t;let r=a+c;if(c+4>=s){e.seekTo(r);break}let l=o[c+1],u=o[c+2],d=o[c+3],f=0,p=null;if(l===0&&u===0&&d===1?(f=4,p=o[c+4]):l===0&&u===1&&(f=3,p=d),f===0){c++;continue}let m=r;if(i===null){i=m,c+=f;continue}if(p!==null){let t=n===`avc`?IS(p):YS(p);if(n===`avc`?t===jS.AUD:t===MS.AUD_NUT){let t=m-i;return e.seekTo(i),e.supplyPacket(t,0)}}c+=f}if(t<r)break}if(i!==null){let t=e.endPos-i;return e.seekTo(i),e.supplyPacket(t,0)}}else{let n=t.info.codec;for(;;){let r=e.ensureBuffered(128);r instanceof Promise&&(r=await r);let i=e.currentPos;for(;e.currentPos-i<r;){let r=e.readU8();if(n===`aac`){if(r!==255)continue;e.skip(-1);let n=e.currentPos,i=e.ensureBuffered(9);if(i instanceof Promise&&(i=await i),i<9)return;let a=e.readBytes(9),o=jT(ME.tempFromBytes(a));if(o){e.seekTo(n);let r=e.ensureBuffered(o.frameLength);return r instanceof Promise&&(r=await r),e.supplyPacket(r,Math.round(MT*UT/t.info.sampleRate))}else e.seekTo(n+1)}else if(n===`mp3`){if(r!==255)continue;e.skip(-1);let n=e.currentPos,i=e.ensureBuffered(4);if(i instanceof Promise&&(i=await i),i<4)return;let a=DS(Mb(e.readBytes(4)).getUint32(0),null);if(a.header){e.seekTo(n);let r=e.ensureBuffered(a.header.totalSize);r instanceof Promise&&(r=await r);let i=a.header.audioSamplesInFrame*UT/t.info.sampleRate;return e.supplyPacket(r,Math.round(i))}else e.seekTo(n+1)}else if(n===`ac3`){if(r!==11)continue;e.skip(-1);let n=e.currentPos,i=e.ensureBuffered(5);if(i instanceof Promise&&(i=await i),i<5)return;let a=e.readBytes(5);if(a[0]!==11||a[1]!==119){e.seekTo(n+1);continue}let o=a[4]>>6,s=a[4]&63;if(o===3||s>37){e.seekTo(n+1);continue}let c=vC[3*s+o];J(c!==void 0),e.seekTo(n),i=e.ensureBuffered(c),i instanceof Promise&&(i=await i);let l=Math.round(yC*UT/t.info.sampleRate);return e.supplyPacket(i,l)}else if(n===`eac3`){if(r!==11)continue;e.skip(-1);let n=e.currentPos,i=e.ensureBuffered(5);if(i instanceof Promise&&(i=await i),i<5)return;let a=e.readBytes(5);if(a[0]!==11||a[1]!==119){e.seekTo(n+1);continue}let o=(((a[2]&7)<<8|a[3])+1)*2,s=bC[a[4]>>6==3?3:a[4]>>4&3];e.seekTo(n),i=e.ensureBuffered(o),i instanceof Promise&&(i=await i);let c=s*256,l=Math.round(c*UT/t.info.sampleRate);return e.supplyPacket(i,l)}else throw Error(`Unhandled.`)}if(r<128)break}}},$T=class e{constructor(e,t){this.currentPos=0,this.pesPackets=[],this.currentPesPacketIndex=0,this.currentPesPacketPos=0,this.endPos=0,this.nextPts=0,this.suppliedPacket=null,this.elementaryStream=e,this.pid=e.pid,this.demuxer=e.demuxer,this.startingPesPacket=t}clone(){let t=new e(this.elementaryStream,this.startingPesPacket);return t.currentPos=this.currentPos,t.pesPackets=[...this.pesPackets],t.currentPesPacketIndex=this.currentPesPacketIndex,t.currentPesPacketPos=this.currentPesPacketPos,t.endPos=this.endPos,t.nextPts=this.nextPts,t}ensureBuffered(e){let t=this.endPos-this.currentPos;return t>=e?e:this.bufferData(e-t).then(()=>Math.min(this.endPos-this.currentPos,e))}getCurrentPesPacket(){let e=this.pesPackets[this.currentPesPacketIndex];return J(e),e}async bufferData(e){let t=this.endPos+e;for(;this.endPos<t;){let e;if(this.pesPackets.length===0)e=this.startingPesPacket;else{let t=Ob(this.pesPackets).sectionEndPos;for(J(t!==null);;){let n=await this.demuxer.readPacketHeader(t);if(!n)return;if(n.pid===this.pid){let n=await this.demuxer.readSection(t,!0);if(!n)return;let r=qT(n);if(r){e=r;break}}t+=this.demuxer.packetStride}}this.pesPackets.push(e),this.endPos+=e.data.byteLength,this.pesPackets.length===1&&(this.nextPts=e.pts)}}readBytes(e){let t=this.getCurrentPesPacket(),n=this.currentPos-this.currentPesPacketPos,r=n+e;if(this.currentPos+=e,r<=t.data.byteLength)return t.data.subarray(n,r);let i=new Uint8Array(e);i.set(t.data.subarray(n));let a=t.data.byteLength-n;for(;;){this.advanceCurrentPacket();let t=this.getCurrentPesPacket(),n=e-a;if(n<=t.data.byteLength){i.set(t.data.subarray(0,n),a);break}i.set(t.data,a),a+=t.data.byteLength}return i}readU8(){let e=this.getCurrentPesPacket(),t=this.currentPos-this.currentPesPacketPos;return this.currentPos++,t<e.data.byteLength?e.data[t]:(this.advanceCurrentPacket(),e=this.getCurrentPesPacket(),e.data[0])}seekTo(e){if(e!==this.currentPos){if(e<this.currentPos)for(;e<this.currentPesPacketPos;){this.currentPesPacketIndex--;let e=this.getCurrentPesPacket();this.currentPesPacketPos-=e.data.byteLength,this.nextPts=e.pts}else for(;;){let t=this.getCurrentPesPacket();if(e<this.currentPesPacketPos+t.data.byteLength)break;this.currentPesPacketPos+=t.data.byteLength,this.currentPesPacketIndex++,this.nextPts=this.getCurrentPesPacket().pts}this.currentPos=e}}skip(e){this.seekTo(this.currentPos+e)}advanceCurrentPacket(){this.currentPesPacketPos+=this.getCurrentPesPacket().data.byteLength,this.currentPesPacketIndex++,this.nextPts=this.getCurrentPesPacket().pts}supplyPacket(e,t){let n=this.getCurrentPesPacket();ZT(this.elementaryStream,n);let r=this.nextPts;this.nextPts+=t;let i=n.sectionStartPos,a=i+(this.currentPos-this.currentPesPacketPos),o=this.readBytes(e),s=n.randomAccessIndicator;J(this.elementaryStream.firstSection),n.sectionStartPos===this.elementaryStream.firstSection.startPos&&(s=1),this.suppliedPacket={pts:r,data:o,sequenceNumber:a,sectionStartPos:i,randomAccessIndicator:s},this.pesPackets.splice(0,this.currentPesPacketIndex),this.currentPesPacketIndex=0}},eE=class{constructor(e,t){this.decodeOrderPackets=[],this.reorderBuffer=[],this.presentationOrderPackets=[],this.reachedEnd=!1,this.lastDuration=0,this.backing=e,this.context=t,this.reorderSize=e.getReorderSize(),J(this.reorderSize>=0)}async readNext(){if(this.decodeOrderPackets.length===0&&!await this.readNextPacket())return null;await this.ensureCurrentPacketHasNext();let e=this.decodeOrderPackets[0],t=this.presentationOrderPackets.indexOf(e);J(t!==-1);let n;for(t===this.presentationOrderPackets.length-1?n=this.lastDuration:(n=this.presentationOrderPackets[t+1].pts-e.pts,this.lastDuration=n),this.decodeOrderPackets.shift();this.presentationOrderPackets.length>0;){let e=this.presentationOrderPackets[0];if(this.decodeOrderPackets.includes(e))break;this.presentationOrderPackets.shift()}return{packet:e,duration:n}}async readNextPacket(){if(this.reachedEnd)return!1;let e;return this.context.suppliedPacket||await QT(this.context),e=this.context.suppliedPacket,this.context.suppliedPacket=null,e?(this.decodeOrderPackets.push(e),this.processPacketThroughReorderBuffer(e),!0):(this.reachedEnd=!0,this.flushReorderBuffer(),!1)}async ensureCurrentPacketHasNext(){let e=this.decodeOrderPackets[0];for(J(e);;){let t=this.presentationOrderPackets.indexOf(e);if(t!==-1&&t<=this.presentationOrderPackets.length-2||!await this.readNextPacket())break}}processPacketThroughReorderBuffer(e){if(this.reorderBuffer.push(e),this.reorderBuffer.length>=this.reorderSize){let e=0;for(let t=1;t<this.reorderBuffer.length;t++)this.reorderBuffer[t].pts<this.reorderBuffer[e].pts&&(e=t);let t=this.reorderBuffer.splice(e,1)[0];this.presentationOrderPackets.push(t)}}flushReorderBuffer(){this.reorderBuffer.sort((e,t)=>e.pts-t.pts),this.presentationOrderPackets.push(...this.reorderBuffer),this.reorderBuffer.length=0}},tE=class{},nE=class extends tE{async _getMajorBrand(e){let t=e._reader.requestSlice(0,12);return t instanceof Promise&&(t=await t),!t||(t.skip(4),XE(t,4)!==`ftyp`)?null:XE(t,4)}_createDemuxer(e){return new Ow(e)}},rE=class extends nE{async _canReadInput(e){let t=await this._getMajorBrand(e);return!!t&&t!==`qt `}get name(){return`MP4`}get mimeType(){return`video/mp4`}},iE=class extends nE{async _canReadInput(e){return await this._getMajorBrand(e)===`qt `}get name(){return`QuickTime File Format`}get mimeType(){return`video/quicktime`}},aE=class extends tE{async isSupportedEBMLOfDocType(e,t){let n=e._reader.requestSlice(0,16);if(n instanceof Promise&&(n=await n),!n)return!1;let r=Hw(n);if(r===null||r<1||r>8||Ww(n,r)!==X.EBML)return!1;let i=qw(n);if(typeof i!=`number`)return!1;let a=e._reader.requestSlice(n.filePos,i);if(a instanceof Promise&&(a=await a),!a)return!1;let o=n.filePos;for(;a.filePos<=o+i-2;){let e=Jw(a);if(!e)break;let{id:n,size:r}=e,i=a.filePos;if(r===void 0)return!1;switch(n){case X.EBMLVersion:if(Ww(a,r)!==1)return!1;break;case X.EBMLReadVersion:if(Ww(a,r)!==1)return!1;break;case X.DocType:if(Yw(a,r)!==t)return!1;break;case X.DocTypeVersion:if(Ww(a,r)>4)return!1;break}a.filePos=i+r}return!0}_canReadInput(e){return this.isSupportedEBMLOfDocType(e,`matroska`)}_createDemuxer(e){return new cT(e)}get name(){return`Matroska`}get mimeType(){return`video/x-matroska`}},oE=class extends aE{_canReadInput(e){return this.isSupportedEBMLOfDocType(e,`webm`)}get name(){return`WebM`}get mimeType(){return`video/webm`}},sE=class extends tE{async _canReadInput(e){let t=0;for(;;){let n=e._reader.requestSlice(t,10);if(n instanceof Promise&&(n=await n),!n)break;let r=nD(n);if(!r)break;t=n.filePos+r.size}let n=await fT(e._reader,t,t+4096);if(!n)return!1;let r=n.header,i=ES(r.mpegVersionId,r.channel),a=e._reader.requestSlice(n.startPos+i,4);if(a instanceof Promise&&(a=await a),!a)return!1;let o=Z(a);if(o===1483304551||o===1231971951)return!0;t=n.startPos+n.header.totalSize;let s=await fT(e._reader,t,t+4);if(!s)return!1;let c=s.header;return!(r.channel!==c.channel||r.sampleRate!==c.sampleRate)}_createDemuxer(e){return new pT(e)}get name(){return`MP3`}get mimeType(){return`audio/mpeg`}},cE=class extends tE{async _canReadInput(e){let t=e._reader.requestSlice(0,12);if(t instanceof Promise&&(t=await t),!t)return!1;let n=XE(t,4);return n!==`RIFF`&&n!==`RIFX`&&n!==`RF64`?!1:(t.skip(4),XE(t,4)===`WAVE`)}_createDemuxer(e){return new OT(e)}get name(){return`WAVE`}get mimeType(){return`audio/wav`}},lE=class extends tE{async _canReadInput(e){let t=e._reader.requestSlice(0,4);return t instanceof Promise&&(t=await t),t?XE(t,4)===`OggS`:!1}_createDemuxer(e){return new CT(e)}get name(){return`Ogg`}get mimeType(){return`application/ogg`}},uE=class extends tE{async _canReadInput(e){let t=e._reader.requestSlice(0,4);return t instanceof Promise&&(t=await t),t?XE(t,4)===`fLaC`:!1}get name(){return`FLAC`}get mimeType(){return`audio/flac`}_createDemuxer(e){return new VT(e)}},dE=class extends tE{async _canReadInput(e){let t=0;for(;;){let n=e._reader.requestSlice(t,10);if(n instanceof Promise&&(n=await n),!n)break;let r=nD(n);if(!r)break;t=n.filePos+r.size}let n=e._reader.requestSliceRange(t,7,9);if(n instanceof Promise&&(n=await n),!n)return!1;let r=jT(n);if(!r||(t+=r.frameLength,n=e._reader.requestSliceRange(t,7,9),n instanceof Promise&&(n=await n),!n))return!1;let i=jT(n);return i?r.objectType===i.objectType&&r.samplingFrequencyIndex===i.samplingFrequencyIndex&&r.channelConfiguration===i.channelConfiguration:!1}_createDemuxer(e){return new NT(e)}get name(){return`ADTS`}get mimeType(){return`audio/aac`}},fE=class extends tE{async _canReadInput(e){let t=e._reader.requestSlice(0,205);if(t instanceof Promise&&(t=await t),!t)return!1;let n=PE(t,205);return n[0]===71&&n[188]===71||n[0]===71&&n[204]===71?!0:n[4]===71&&n[196]===71}_createDemuxer(e){return new GT(e)}get name(){return`MPEG Transport Stream`}get mimeType(){return`video/MP2T`}},pE=new rE,mE=new iE,hE=new aE,gE=new oE,_E=new sE,vE=new cE,yE=new lE,bE=new dE,xE=[pE,mE,hE,gE,vE,yE,new uE,_E,bE,new fE];e(yv(),1);var SE=class{constructor(){this._disposed=!1,this._sizePromise=null,this.onread=null}async getSizeOrNull(){if(this._disposed)throw new AE;return this._sizePromise??=Promise.resolve(this._retrieveSize())}async getSize(){if(this._disposed)throw new AE;let e=await this.getSizeOrNull();if(e===null)throw Error(`Cannot determine the size of an unsized source.`);return e}},CE=class extends SE{constructor(e){if(!(e instanceof ArrayBuffer)&&!(typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer)&&!ArrayBuffer.isView(e))throw TypeError(`buffer must be an ArrayBuffer, SharedArrayBuffer, or ArrayBufferView.`);super(),this._onreadCalled=!1,this._bytes=jb(e),this._view=Mb(e)}_retrieveSize(){return this._bytes.byteLength}_read(){return this._onreadCalled||=(this.onread?.(0,this._bytes.byteLength),!0),{bytes:this._bytes,view:this._view,offset:0}}_dispose(){}},wE=.5*2**20,TE=((e,t,n)=>{if(t instanceof Error&&(t.message.includes(`Failed to fetch`)||t.message.includes(`Load failed`)||t.message.includes(`NetworkError when attempting to fetch resource`))){let e=null;try{typeof window<`u`&&window.location!==void 0&&(e=new URL(n instanceof Request?n.url:n,window.location.href).origin)}catch{}if((!(typeof navigator<`u`&&typeof navigator.onLine==`boolean`)||navigator.onLine)&&e!==null&&e!==window.location.origin)return console.warn(`Request will not be retried because a CORS error was suspected due to different origins. You can modify this behavior by providing your own function for the 'getRetryDelay' option.`),null}return Math.min(2**(e-2),16)}),EE=class extends SE{constructor(e,t={}){if(typeof e!=`string`&&!(e instanceof URL)&&!(typeof Request<`u`&&e instanceof Request))throw TypeError(`url must be a string, URL or Request.`);if(!t||typeof t!=`object`)throw TypeError(`options must be an object.`);if(t.requestInit!==void 0&&(!t.requestInit||typeof t.requestInit!=`object`))throw TypeError(`options.requestInit, when provided, must be an object.`);if(t.getRetryDelay!==void 0&&typeof t.getRetryDelay!=`function`)throw TypeError(`options.getRetryDelay, when provided, must be a function.`);if(t.maxCacheSize!==void 0&&(!Nx(t.maxCacheSize)||t.maxCacheSize<0))throw TypeError(`options.maxCacheSize, when provided, must be a non-negative number.`);if(t.parallelism!==void 0&&(!Number.isInteger(t.parallelism)||t.parallelism<1))throw TypeError(`options.parallelism, when provided, must be a positive number.`);if(t.fetchFn!==void 0&&typeof t.fetchFn!=`function`)throw TypeError(`options.fetchFn, when provided, must be a function.`);super(),this._existingResponses=new WeakMap,this._url=e,this._options=t,this._getRetryDelay=t.getRetryDelay??TE,this._orchestrator=new OE({maxCacheSize:t.maxCacheSize??64*2**20,maxWorkerCount:t.parallelism??2,runWorker:this._runWorker.bind(this),prefetchProfile:DE.network})}async _retrieveSize(){let e=new AbortController,t=await _x(this._options.fetchFn??fetch,this._url,hx(this._options.requestInit??{},{headers:{Range:`bytes=0-`},signal:e.signal}),this._getRetryDelay,()=>this._disposed);if(!t.ok)throw Error(`Error fetching ${String(this._url)}: ${t.status} ${t.statusText}`);let n,r;if(t.status===206)r=this._getTotalLengthFromRangeResponse(t),n=this._orchestrator.createWorker(0,Math.min(r,wE));else{let e=t.headers.get(`Content-Length`);if(e)r=Number(e),n=this._orchestrator.createWorker(0,r),this._orchestrator.options.maxCacheSize=1/0,console.warn(`HTTP server did not respond with 206 Partial Content, meaning the entire remote resource now has to be downloaded. For efficient media file streaming across a network, please make sure your server supports range requests.`);else throw Error(`HTTP response (status ${t.status}) must surface Content-Length header.`)}return this._orchestrator.fileSize=r,this._existingResponses.set(n,{response:t,abortController:e}),this._orchestrator.runWorker(n),r}_read(e,t){return this._orchestrator.read(e,t)}async _runWorker(e){for(;;){let t=this._existingResponses.get(e);this._existingResponses.delete(e);let n=t?.abortController,r=t?.response;if(n||(n=new AbortController,r=await _x(this._options.fetchFn??fetch,this._url,hx(this._options.requestInit??{},{headers:{Range:`bytes=${e.currentPos}-`},signal:n.signal}),this._getRetryDelay,()=>this._disposed)),J(r),!r.ok)throw Error(`Error fetching ${String(this._url)}: ${r.status} ${r.statusText}`);if(e.currentPos>0&&r.status!==206)throw Error(`HTTP server did not respond with 206 Partial Content to a range request. To enable efficient media file streaming across a network, please make sure your server supports range requests.`);if(!r.body)throw Error(`Missing HTTP response body stream. The used fetch function must provide the response body as a ReadableStream.`);let i=r.body.getReader();for(;;){if(e.currentPos>=e.targetPos||e.aborted){n.abort(),e.running=!1;return}let t;try{t=await i.read()}catch(e){if(this._disposed)throw e;let t=this._getRetryDelay(1,e,this._url);if(t!==null){console.error(`Error while reading response stream. Attempting to resume.`,e),await new Promise(e=>setTimeout(e,1e3*t));break}else throw e}if(e.aborted)continue;let{done:r,value:a}=t;if(r){if(e.currentPos>=e.targetPos){this._orchestrator.forgetWorker(e),e.running=!1;return}break}this.onread?.(e.currentPos,e.currentPos+a.length),this._orchestrator.supplyWorkerData(e,a)}}}_getTotalLengthFromRangeResponse(e){let t=e.headers.get(`Content-Range`);if(t){let e=/\/(\d+)/.exec(t);if(e)return Number(e[1])}let n=e.headers.get(`Content-Length`);if(n)return Number(n);throw Error(`Partial HTTP response (status 206) must surface either Content-Range or Content-Length header.`)}_dispose(){this._orchestrator.dispose()}},DE={none:(e,t)=>({start:e,end:t}),fileSystem:(e,t)=>{let n=2**16;return e=Math.floor((e-n)/n)*n,t=Math.ceil((t+n)/n)*n,{start:e,end:t}},network:(e,t,n)=>{let r=2**16;e=Math.max(0,Math.floor((e-r)/r)*r);for(let r of n){let n=8*2**20,i=Math.max((r.startPos+r.targetPos)/2,r.targetPos-n);if(kx(e,t,i,r.targetPos)){let e=r.targetPos-r.startPos,i=Math.ceil((e+1)/n)*n,a=2**Math.ceil(Math.log2(e+1)),o=Math.min(a,i);t=Math.max(t,r.startPos+o)}}return t=Math.max(t,e+wE),{start:e,end:t}}},OE=class{constructor(e){this.options=e,this.fileSize=null,this.nextAge=0,this.workers=[],this.cache=[],this.currentCacheSize=0,this.disposed=!1}read(e,t){J(this.fileSize!==null);let n=this.options.prefetchProfile(e,t,this.workers),r=Math.max(n.start,0),i=Math.min(n.end,this.fileSize);J(r<=e&&t<=i);let a=null,o=Jb(this.cache,e,e=>e.start),s=o===-1?null:this.cache[o];s&&s.start<=e&&t<=s.end&&(s.age=this.nextAge++,a={bytes:s.bytes,view:s.view,offset:s.start});let c=Jb(this.cache,r,e=>e.start),l=a?null:new Uint8Array(t-e),u=0,d=r,f=[];if(c!==-1){for(let n=c;n<this.cache.length;n++){let a=this.cache[n];if(a.start>=i)break;if(a.end<=r)continue;let o=Math.max(r,a.start),s=Math.min(i,a.end);if(J(o<=s),d<o&&f.push({start:d,end:o}),d=s,l){let n=Math.max(e,a.start),r=Math.min(t,a.end);if(n<r){let t=n-e;l.set(a.bytes.subarray(n-a.start,r-a.start),t),t===u&&(u=r-e)}}a.age=this.nextAge++}d<i&&f.push({start:d,end:i})}else f.push({start:r,end:i});if(l&&u>=l.length&&(a={bytes:l,view:Mb(l),offset:e}),f.length===0)return J(a),a;let{promise:p,resolve:m,reject:h}=Xb(),g=[];for(let n of f){let r=Math.max(e,n.start),i=Math.min(t,n.end);r===n.start&&i===n.end?g.push(n):r<i&&g.push({start:r,end:i})}for(let t of f){let n=l&&{start:e,bytes:l,holes:g,resolve:m,reject:h},r=!1;for(let e of this.workers)if(kx(t.start-2**17,t.start,e.currentPos,e.targetPos)){e.targetPos=Math.max(e.targetPos,t.end),r=!0,n&&!e.pendingSlices.includes(n)&&e.pendingSlices.push(n),e.running||this.runWorker(e);break}if(!r){let e=this.createWorker(t.start,t.end);n&&(e.pendingSlices=[n]),this.runWorker(e)}}return a||=(J(l),p.then(t=>({bytes:t,view:Mb(t),offset:e}))),a}createWorker(e,t){let n={startPos:e,currentPos:e,targetPos:t,running:!1,aborted:this.disposed,pendingSlices:[],age:this.nextAge++};for(this.workers.push(n);this.workers.length>this.options.maxWorkerCount;){let e=0,t=this.workers[0];for(let n=1;n<this.workers.length;n++){let r=this.workers[n];r.age<t.age&&(e=n,t=r)}if(t.running&&t.pendingSlices.length>0)break;t.aborted=!0,this.workers.splice(e,1)}return n}runWorker(e){J(!e.running),J(e.currentPos<e.targetPos),e.running=!0,e.age=this.nextAge++,this.options.runWorker(e).catch(t=>{if(e.running=!1,e.pendingSlices.length>0)e.pendingSlices.forEach(e=>e.reject(t)),e.pendingSlices.length=0;else throw t})}supplyWorkerData(e,t){J(!e.aborted);let n=e.currentPos,r=n+t.length;this.insertIntoCache({start:n,end:r,bytes:t,view:Mb(t),age:this.nextAge++}),e.currentPos+=t.length,e.targetPos=Math.max(e.targetPos,e.currentPos);for(let i=0;i<e.pendingSlices.length;i++){let a=e.pendingSlices[i],o=Math.max(n,a.start),s=Math.min(r,a.start+a.bytes.length);o<s&&a.bytes.set(t.subarray(o-n,s-n),o-a.start);for(let e=0;e<a.holes.length;e++){let t=a.holes[e];n<=t.start&&r>t.start&&(t.start=r),t.end<=t.start&&(a.holes.splice(e,1),e--)}a.holes.length===0&&(a.resolve(a.bytes),e.pendingSlices.splice(i,1),i--)}for(let t=0;t<this.workers.length;t++){let i=this.workers[t];e===i||i.running||kx(n,r,i.currentPos,i.targetPos)&&(this.workers.splice(t,1),t--)}}forgetWorker(e){let t=this.workers.indexOf(e);J(t!==-1),this.workers.splice(t,1)}insertIntoCache(e){if(this.options.maxCacheSize===0)return;let t=Jb(this.cache,e.start,e=>e.start)+1;if(t>0){let n=this.cache[t-1];if(n.end>=e.end)return;if(n.end>e.start){let r=new Uint8Array(e.end-n.start);r.set(n.bytes,0),r.set(e.bytes,e.start-n.start),this.currentCacheSize+=e.end-n.end,n.bytes=r,n.view=Mb(r),n.end=e.end,t--,e=n}else this.cache.splice(t,0,e),this.currentCacheSize+=e.bytes.length}else this.cache.splice(t,0,e),this.currentCacheSize+=e.bytes.length;for(let n=t+1;n<this.cache.length;n++){let t=this.cache[n];if(e.end<=t.start)break;if(e.end>=t.end){this.cache.splice(n,1),this.currentCacheSize-=t.bytes.length,n--;continue}let r=new Uint8Array(t.end-e.start);r.set(e.bytes,0),r.set(t.bytes,t.start-e.start),this.currentCacheSize-=e.end-t.start,e.bytes=r,e.view=Mb(r),e.end=t.end,this.cache.splice(n,1);break}for(;this.currentCacheSize>this.options.maxCacheSize;){let e=0,t=this.cache[0];for(let n=1;n<this.cache.length;n++){let r=this.cache[n];r.age<t.age&&(e=n,t=r)}if(this.currentCacheSize-t.bytes.length<=this.options.maxCacheSize)break;this.cache.splice(e,1),this.currentCacheSize-=t.bytes.length}}dispose(){for(let e of this.workers)e.aborted=!0;this.workers.length=0,this.cache.length=0,this.disposed=!0}};Mx();var kE=class{get disposed(){return this._disposed}constructor(e){if(this._demuxerPromise=null,this._format=null,this._disposed=!1,!e||typeof e!=`object`)throw TypeError(`options must be an object.`);if(!Array.isArray(e.formats)||e.formats.some(e=>!(e instanceof tE)))throw TypeError(`options.formats must be an array of InputFormat.`);if(!(e.source instanceof SE))throw TypeError(`options.source must be a Source.`);if(e.source._disposed)throw Error(`options.source must not be disposed.`);this._formats=e.formats,this._source=e.source,this._reader=new jE(e.source)}_getDemuxer(){return this._demuxerPromise??=(async()=>{this._reader.fileSize=await this._source.getSizeOrNull();for(let e of this._formats)if(await e._canReadInput(this))return this._format=e,e._createDemuxer(this);throw Error(`Input has an unsupported or unrecognizable format.`)})()}get source(){return this._source}async getFormat(){return await this._getDemuxer(),J(this._format),this._format}async computeDuration(){return(await this._getDemuxer()).computeDuration()}async getFirstTimestamp(){let e=await this.getTracks();if(e.length===0)return 0;let t=await Promise.all(e.map(e=>e.getFirstTimestamp()));return Math.min(...t)}async getTracks(){return(await this._getDemuxer()).getTracks()}async getVideoTracks(){return(await this.getTracks()).filter(e=>e.isVideoTrack())}async getAudioTracks(){return(await this.getTracks()).filter(e=>e.isAudioTrack())}async getPrimaryVideoTrack(){return(await this.getTracks()).find(e=>e.isVideoTrack())??null}async getPrimaryAudioTrack(){return(await this.getTracks()).find(e=>e.isAudioTrack())??null}async getMimeType(){return(await this._getDemuxer()).getMimeType()}async getMetadataTags(){return(await this._getDemuxer()).getMetadataTags()}dispose(){this._disposed||(this._disposed=!0,this._source._disposed=!0,this._source._dispose())}[Symbol.dispose](){this.dispose()}},AE=class extends Error{constructor(e=`Input has been disposed.`){super(e),this.name=`InputDisposedError`}},jE=class{constructor(e){this.source=e}requestSlice(e,t){if(this.source._disposed)throw new AE;if(e<0||this.fileSize!==null&&e+t>this.fileSize)return null;let n=e+t,r=this.source._read(e,n);return r instanceof Promise?r.then(t=>t?new ME(t.bytes,t.view,t.offset,e,n):null):r?new ME(r.bytes,r.view,r.offset,e,n):null}requestSliceRange(e,t,n){if(this.source._disposed)throw new AE;if(e<0)return null;if(this.fileSize!==null)return this.requestSlice(e,sx(this.fileSize-e,t,n));{let r=this.requestSlice(e,n),i=r=>{if(r)return r;let i=r=>(J(r!==null),this.requestSlice(e,sx(r-e,t,n))),a=this.source._retrieveSize();return a instanceof Promise?a.then(i):i(a)};return r instanceof Promise?r.then(i):i(r)}}},ME=class e{constructor(e,t,n,r,i){this.bytes=e,this.view=t,this.offset=n,this.start=r,this.end=i,this.bufferPos=r-n}static tempFromBytes(t){return new e(t,Mb(t),0,0,t.length)}get length(){return this.end-this.start}get filePos(){return this.offset+this.bufferPos}set filePos(e){this.bufferPos=e-this.offset}get remainingLength(){return Math.max(this.end-this.filePos,0)}skip(e){this.bufferPos+=e}slice(t,n=this.end-t){if(t<this.start||t+n>this.end)throw RangeError(`Slicing outside of original slice.`);return new e(this.bytes,this.view,this.offset,t,t+n)}},NE=(e,t)=>{if(e.filePos<e.start||e.filePos+t>e.end)throw RangeError(`Tried reading [${e.filePos}, ${e.filePos+t}), but slice is [${e.start}, ${e.end}). This is likely an internal error, please report it alongside the file that caused it.`)},PE=(e,t)=>{NE(e,t);let n=e.bytes.subarray(e.bufferPos,e.bufferPos+t);return e.bufferPos+=t,n},FE=e=>(NE(e,1),e.view.getUint8(e.bufferPos++)),IE=(e,t)=>{NE(e,2);let n=e.view.getUint16(e.bufferPos,t);return e.bufferPos+=2,n},LE=e=>{NE(e,2);let t=e.view.getUint16(e.bufferPos,!1);return e.bufferPos+=2,t},RE=e=>{NE(e,3);let t=nx(e.view,e.bufferPos,!1);return e.bufferPos+=3,t},zE=e=>{NE(e,2);let t=e.view.getInt16(e.bufferPos,!1);return e.bufferPos+=2,t},BE=(e,t)=>{NE(e,4);let n=e.view.getUint32(e.bufferPos,t);return e.bufferPos+=4,n},Z=e=>{NE(e,4);let t=e.view.getUint32(e.bufferPos,!1);return e.bufferPos+=4,t},VE=e=>{NE(e,4);let t=e.view.getUint32(e.bufferPos,!0);return e.bufferPos+=4,t},HE=e=>{NE(e,4);let t=e.view.getInt32(e.bufferPos,!1);return e.bufferPos+=4,t},UE=e=>{NE(e,4);let t=e.view.getInt32(e.bufferPos,!0);return e.bufferPos+=4,t},WE=(e,t)=>{let n,r;return t?(n=BE(e,!0),r=BE(e,!0)):(r=BE(e,!1),n=BE(e,!1)),r*4294967296+n},GE=e=>{let t=Z(e),n=Z(e);return t*4294967296+n},KE=e=>{let t=HE(e),n=Z(e);return t*4294967296+n},qE=e=>{let t=VE(e);return UE(e)*4294967296+t},JE=e=>{NE(e,4);let t=e.view.getFloat32(e.bufferPos,!1);return e.bufferPos+=4,t},YE=e=>{NE(e,8);let t=e.view.getFloat64(e.bufferPos,!1);return e.bufferPos+=8,t},XE=(e,t)=>{NE(e,t);let n=``;for(let r=0;r<t;r++)n+=String.fromCharCode(e.bytes[e.bufferPos++]);return n},ZE;(function(e){e[e.Unsynchronisation=128]=`Unsynchronisation`,e[e.ExtendedHeader=64]=`ExtendedHeader`,e[e.ExperimentalIndicator=32]=`ExperimentalIndicator`,e[e.Footer=16]=`Footer`})(ZE||={});var QE;(function(e){e[e.ISO_8859_1=0]=`ISO_8859_1`,e[e.UTF_16_WITH_BOM=1]=`UTF_16_WITH_BOM`,e[e.UTF_16_BE_NO_BOM=2]=`UTF_16_BE_NO_BOM`,e[e.UTF_8=3]=`UTF_8`})(QE||={});var $E=`Blues.Classic rock.Country.Dance.Disco.Funk.Grunge.Hip-hop.Jazz.Metal.New age.Oldies.Other.Pop.Rhythm and blues.Rap.Reggae.Rock.Techno.Industrial.Alternative.Ska.Death metal.Pranks.Soundtrack.Euro-techno.Ambient.Trip-hop.Vocal.Jazz & funk.Fusion.Trance.Classical.Instrumental.Acid.House.Game.Sound clip.Gospel.Noise.Alternative rock.Bass.Soul.Punk.Space.Meditative.Instrumental pop.Instrumental rock.Ethnic.Gothic.Darkwave.Techno-industrial.Electronic.Pop-folk.Eurodance.Dream.Southern rock.Comedy.Cult.Gangsta.Top 40.Christian rap.Pop/funk.Jungle music.Native US.Cabaret.New wave.Psychedelic.Rave.Showtunes.Trailer.Lo-fi.Tribal.Acid punk.Acid jazz.Polka.Retro.Musical.Rock 'n' roll.Hard rock.Folk.Folk rock.National folk.Swing.Fast fusion.Bebop.Latin.Revival.Celtic.Bluegrass.Avantgarde.Gothic rock.Progressive rock.Psychedelic rock.Symphonic rock.Slow rock.Big band.Chorus.Easy listening.Acoustic.Humour.Speech.Chanson.Opera.Chamber music.Sonata.Symphony.Booty bass.Primus.Porn groove.Satire.Slow jam.Club.Tango.Samba.Folklore.Ballad.Power ballad.Rhythmic Soul.Freestyle.Duet.Punk rock.Drum solo.A cappella.Euro-house.Dance hall.Goa music.Drum & bass.Club-house.Hardcore techno.Terror.Indie.Britpop.Negerpunk.Polsk punk.Beat.Christian gangsta rap.Heavy metal.Black metal.Crossover.Contemporary Christian.Christian rock.Merengue.Salsa.Thrash metal.Anime.Jpop.Synthpop.Christmas.Art rock.Baroque.Bhangra.Big beat.Breakbeat.Chillout.Downtempo.Dub.EBM.Eclectic.Electro.Electroclash.Emo.Experimental.Garage.Global.IDM.Illbient.Industro-Goth.Jam Band.Krautrock.Leftfield.Lounge.Math rock.New romantic.Nu-breakz.Post-punk.Post-rock.Psytrance.Shoegaze.Space rock.Trop rock.World music.Neoclassical.Audiobook.Audio theatre.Neue Deutsche Welle.Podcast.Indie rock.G-Funk.Dubstep.Garage rock.Psybient`.split(`.`),eD=(e,t)=>{let n=e.filePos;t.raw??={},t.raw.TAG??=PE(e,125),e.filePos=n;let r=tD(e,30);r&&(t.title??=r);let i=tD(e,30);i&&(t.artist??=i);let a=tD(e,30);a&&(t.album??=a);let o=tD(e,4),s=Number.parseInt(o,10);Number.isInteger(s)&&s>0&&(t.date??=new Date(s,0,1));let c=PE(e,30),l;if(c[28]===0&&c[29]!==0){let n=c[29];n>0&&(t.trackNumber??=n),e.skip(-30),l=tD(e,28),e.skip(2)}else e.skip(-30),l=tD(e,30);l&&(t.comment??=l);let u=FE(e);u<$E.length&&(t.genre??=$E[u])},tD=(e,t)=>{let n=PE(e,t),r=Ox(n.indexOf(0),n.length),i=n.subarray(0,r),a=``;for(let e=0;e<i.length;e++)a+=String.fromCharCode(i[e]);return a.trimEnd()},nD=e=>{let t=e.filePos,n=XE(e,3),r=FE(e),i=FE(e),a=FE(e),o=Z(e);return n!==`ID3`||r===255||i===255||o&2155905152?(e.filePos=t,null):{majorVersion:r,revision:i,flags:a,size:OS(o)}},rD=(e,t,n)=>{if(![2,3,4].includes(t.majorVersion)){console.warn(`Unsupported ID3v2 major version: ${t.majorVersion}`);return}let r=new iD(t,PE(e,t.size));if(t.flags&ZE.Footer&&r.removeFooter(),t.flags&ZE.Unsynchronisation&&t.majorVersion===3&&r.ununsynchronizeAll(),t.flags&ZE.ExtendedHeader){let e=r.readU32();t.majorVersion===3?r.pos+=e:r.pos+=e-4}for(;r.pos<=r.bytes.length-r.frameHeaderSize();){let e=r.readId3V2Frame();if(!e)break;let i=r.pos,a=r.pos+e.size,o=!1,s=!1,c=!1;if(t.majorVersion===3?(o=!!(e.flags&64),s=!!(e.flags&128)):t.majorVersion===4&&(o=!!(e.flags&4),s=!!(e.flags&8),c=!!(e.flags&2)||!!(t.flags&ZE.Unsynchronisation)),o){console.warn(`Skipping encrypted ID3v2 frame ${e.id}`),r.pos=a;continue}if(s){console.warn(`Skipping compressed ID3v2 frame ${e.id}`),r.pos=a;continue}switch(c&&r.ununsynchronizeRegion(r.pos,a),n.raw??={},e.id[0]===`T`?n.raw[e.id]??=r.readId3V2EncodingAndText(a):n.raw[e.id]??=r.readBytes(e.size),r.pos=i,e.id){case`TIT2`:case`TT2`:n.title??=r.readId3V2EncodingAndText(a);break;case`TIT3`:case`TT3`:n.description??=r.readId3V2EncodingAndText(a);break;case`TPE1`:case`TP1`:n.artist??=r.readId3V2EncodingAndText(a);break;case`TALB`:case`TAL`:n.album??=r.readId3V2EncodingAndText(a);break;case`TPE2`:case`TP2`:n.albumArtist??=r.readId3V2EncodingAndText(a);break;case`TRCK`:case`TRK`:{let e=r.readId3V2EncodingAndText(a).split(`/`),t=Number.parseInt(e[0],10),i=e[1]&&Number.parseInt(e[1],10);Number.isInteger(t)&&t>0&&(n.trackNumber??=t),i&&Number.isInteger(i)&&i>0&&(n.tracksTotal??=i)}break;case`TPOS`:case`TPA`:{let e=r.readId3V2EncodingAndText(a).split(`/`),t=Number.parseInt(e[0],10),i=e[1]&&Number.parseInt(e[1],10);Number.isInteger(t)&&t>0&&(n.discNumber??=t),i&&Number.isInteger(i)&&i>0&&(n.discsTotal??=i)}break;case`TCON`:case`TCO`:{let e=r.readId3V2EncodingAndText(a),t=/^\((\d+)\)/.exec(e);if(t){let e=Number.parseInt(t[1]);if($E[e]!==void 0){n.genre??=$E[e];break}}if(t=/^\d+$/.exec(e),t){let e=Number.parseInt(t[0]);if($E[e]!==void 0){n.genre??=$E[e];break}}n.genre??=e}break;case`TDRC`:case`TDAT`:{let e=r.readId3V2EncodingAndText(a),t=new Date(e);Number.isNaN(t.getTime())||(n.date??=t)}break;case`TYER`:case`TYE`:{let e=r.readId3V2EncodingAndText(a),t=Number.parseInt(e,10);Number.isInteger(t)&&(n.date??=new Date(t,0,1))}break;case`USLT`:case`ULT`:{let e=r.readU8();r.pos+=3,r.readId3V2Text(e,a),n.lyrics??=r.readId3V2Text(e,a)}break;case`COMM`:case`COM`:{let e=r.readU8();r.pos+=3,r.readId3V2Text(e,a),n.comment??=r.readId3V2Text(e,a)}break;case`APIC`:case`PIC`:{let e=r.readId3V2TextEncoding(),i;if(t.majorVersion===2){let e=r.readAscii(3);i=e===`PNG`?`image/png`:e===`JPG`?`image/jpeg`:`image/*`}else i=r.readId3V2Text(e,a);let o=r.readU8(),s=r.readId3V2Text(e,a).trimEnd(),c=a-r.pos;if(c>=0){let e=r.readBytes(c);n.images||=[],n.images.push({data:e,mimeType:i,kind:o===3?`coverFront`:o===4?`coverBack`:`unknown`,description:s})}}break;default:r.pos+=e.size;break}r.pos=a}},iD=class{constructor(e,t){this.header=e,this.bytes=t,this.pos=0,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength)}frameHeaderSize(){return this.header.majorVersion===2?6:10}ununsynchronizeAll(){let e=[];for(let t=0;t<this.bytes.length;t++){let n=this.bytes[t];e.push(n),n===255&&t!==this.bytes.length-1&&this.bytes[t]===0&&t++}this.bytes=new Uint8Array(e),this.view=new DataView(this.bytes.buffer)}ununsynchronizeRegion(e,t){let n=[];for(let r=e;r<t;r++){let e=this.bytes[r];n.push(e),e===255&&r!==t-1&&this.bytes[r+1]===0&&r++}let r=this.bytes.subarray(0,e),i=this.bytes.subarray(t);this.bytes=new Uint8Array(r.length+n.length+i.length),this.bytes.set(r,0),this.bytes.set(n,r.length),this.bytes.set(i,r.length+n.length),this.view=new DataView(this.bytes.buffer)}removeFooter(){this.bytes=this.bytes.subarray(0,this.bytes.length-10),this.view=new DataView(this.bytes.buffer)}readBytes(e){let t=this.bytes.subarray(this.pos,this.pos+e);return this.pos+=e,t}readU8(){let e=this.view.getUint8(this.pos);return this.pos+=1,e}readU16(){let e=this.view.getUint16(this.pos,!1);return this.pos+=2,e}readU24(){let e=this.view.getUint16(this.pos,!1),t=this.view.getUint8(this.pos+1);return this.pos+=3,e*256+t}readU32(){let e=this.view.getUint32(this.pos,!1);return this.pos+=4,e}readAscii(e){let t=``;for(let n=0;n<e;n++)t+=String.fromCharCode(this.view.getUint8(this.pos+n));return this.pos+=e,t}readId3V2Frame(){if(this.header.majorVersion===2){let e=this.readAscii(3);return e===`\0\0\0`?null:{id:e,size:this.readU24(),flags:0}}else{let e=this.readAscii(4);if(e===`\0\0\0\0`)return null;let t=this.readU32(),n=this.header.majorVersion===4?OS(t):t,r=this.readU16(),i=this.pos,a=e=>{let t=this.pos+e;if(t>this.bytes.length)return!1;if(t<=this.bytes.length-this.frameHeaderSize()){this.pos+=e;let t=this.readAscii(4);if(t!==`\0\0\0\0`&&!/[0-9A-Z]{4}/.test(t))return!1}return!0};if(!a(n)){let e=this.header.majorVersion===4?t:OS(t);a(e)&&(n=e)}return this.pos=i,{id:e,size:n,flags:r}}}readId3V2TextEncoding(){let e=this.readU8();if(e>3)throw Error(`Unsupported text encoding: ${e}`);return e}readId3V2Text(e,t){let n=this.pos,r=this.readBytes(t-this.pos);switch(e){case QE.ISO_8859_1:{let e=``;for(let t=0;t<r.length;t++){let i=r[t];if(i===0){this.pos=n+t+1;break}e+=String.fromCharCode(i)}return e}case QE.UTF_16_WITH_BOM:if(r[0]===255&&r[1]===254){let e=new TextDecoder(`utf-16le`),t=Ox(r.findIndex((e,t)=>e===0&&r[t+1]===0&&t%2==0),r.length);return this.pos=n+Math.min(t+2,r.length),e.decode(r.subarray(2,t))}else if(r[0]===254&&r[1]===255){let e=new TextDecoder(`utf-16be`),t=Ox(r.findIndex((e,t)=>e===0&&r[t+1]===0&&t%2==0),r.length);return this.pos=n+Math.min(t+2,r.length),e.decode(r.subarray(2,t))}else{let e=Ox(r.findIndex(e=>e===0),r.length);return this.pos=n+Math.min(e+1,r.length),Nb.decode(r.subarray(0,e))}case QE.UTF_16_BE_NO_BOM:{let e=new TextDecoder(`utf-16be`),t=Ox(r.findIndex((e,t)=>e===0&&r[t+1]===0&&t%2==0),r.length);return this.pos=n+Math.min(t+2,r.length),e.decode(r.subarray(0,t))}case QE.UTF_8:{let e=Ox(r.findIndex(e=>e===0),r.length);return this.pos=n+Math.min(e+1,r.length),Nb.decode(r.subarray(0,e))}}}readId3V2EncodingAndText(e){if(this.pos>=e)return``;let t=this.readId3V2TextEncoding();return this.readId3V2Text(t,e)}},aD=.05,oD=(e,t,n)=>{let[r,i]=d.useState({input:null,videoSink:null,duration:0,isReady:!1,error:null});d.useRef(r).current=r;let a=d.useRef(0),o=d.useRef(null),s=d.useRef(null),c=d.useRef(null),l=d.useRef(null),u=d.useRef(null),f=d.useRef(null),p=d.useRef(!1),m=d.useRef(null),h=d.useRef([]),g=d.useRef(null),_=d.useRef(!1),[,v]=d.useReducer(e=>e+1,0);return d.useEffect(()=>{if(!n)return;let t=!0,r=++a.current,o=null;return(async()=>{try{if(!t||r!==a.current)return;o=Kf(`mediabunny init ${e.id}`);let n=await async function(e){if(function(e){return e.startsWith(`data:`)}(e))return new CE(function(e){let t=e.indexOf(`,`);if(t===-1)throw Error(`Invalid data URL format`);let n=e.slice(t+1),r=atob(n),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i.buffer}(e));if(function(e){return e.startsWith(`file://`)}(e))try{return new CE(await(await fetch(e)).arrayBuffer())}catch(t){throw Error(`Failed to load file URL: ${e}. File URLs may not be supported in this environment. Error: ${t}`)}return new EE(e)}(e.src);if(!t||r!==a.current){o&&=(o(),null);return}let s=new kE({source:n,formats:xE}),c=await s.computeDuration(),l=await s.getPrimaryVideoTrack();if(!l)throw Error(`No video track found`);if(l.codec===null)throw Error(`Unsupported video codec`);if(!await l.canDecode())throw Error(`Unable to decode the video track`);let u=new pw(l,{poolSize:5,fit:`contain`,alpha:await l.canBeTransparent()});if(!t||r!==a.current){s.dispose(),o&&=(o(),null);return}o&&=(o(),null),i(e=>Object.assign(Object.assign({},e),{input:s,videoSink:u,duration:c,isReady:!0,error:null}))}catch(n){console.error(`Failed to initialize mediabunny:`,n),o&&=(o(),null),t&&r===a.current&&(Zf(`Failed to initialize mediabunny for video ${e.id}: ${n}`),i(e=>Object.assign(Object.assign({},e),{error:String(n),isReady:!1})))}})(),()=>{t=!1,o&&=(o(),null)}},[e.src,n]),d.useEffect(()=>()=>{s.current&&=(s.current.return(),null),o.current&&=(o.current(),null),c.current=null,l.current=null,u.current=null,p.current=!1,m.current=null,h.current=[],g.current=null,_.current=!1,i({input:null,videoSink:null,duration:0,isReady:!1,error:null})},[n]),d.useEffect(()=>{if(!n||!r.isReady||!r.videoSink)return;let i=++a.current,d=typeof e.src==`string`?e.src.slice(0,120):String(e.src),y=(t,n={},i=`debug`)=>{let a=``;try{a=JSON.stringify(Object.assign(Object.assign({},n),{timeCalc:f.current}))}catch(e){a=`[unserializable extras: ${String(e)}]`}let o=`mediabunny event=${t} elementId=${e.id} targetTime=${u.current} duration=${r.duration} lastFrameTimestamp=${l.current} hasIterator=${!!s.current} prefetchSize=${h.current.length} srcHint=${d} extras=${a}`;i===`error`?console.error(o):i===`warn`?console.warn(o):console.debug(o)},b=e=>{let t=r.duration||0;if(!t||!Number.isFinite(t))return e;let n=t>aD?t-aD:t;return Math.max(0,Math.min(e,n))},x=e=>{let t=r.duration||0;return!(!t||!Number.isFinite(t))&&t-e<=.050001000000000004},S=e=>{let t=c.current;t&&t.width===e.canvas.width&&t.height===e.canvas.height||(t||(t=document.createElement(`canvas`),c.current=t),t.width=e.canvas.width,t.height=e.canvas.height);let n=t.getContext(`2d`);n&&(n.clearRect(0,0,t.width,t.height),n.drawImage(e.canvas,0,0)),l.current=e.timestamp},C=e=>{let t=s.current;t&&(_.current||(_.current=!0,g.current=(async()=>{try{for(;h.current.length<4&&e===a.current;){let n=await t.next();if(e!==a.current)return;if(n.done||!n.value)break;h.current.push({timestamp:n.value.timestamp,frame:n.value})}}catch{}finally{_.current=!1,g.current=null}})()))},w=e=>{let t=h.current;for(let n=0;n<t.length;n++)if(Math.abs(t[n].timestamp-e)<aD){let e=t[n];return h.current=t.slice(n+1),e}return null},T=()=>{h.current=[]},E=async(e,t,n=0)=>{let i=b(e),o=(e=>{let t=l.current;return t===null||e<t-aD||e>t+.5})(i)?`seek`:`iterate`;try{let n=r.videoSink,c=l.current;if(c!==null&&Math.abs(c-i)<aD){u.current=e;return}let d=w(i);if(d){S(d.frame),u.current=e,C(t),v();return}if(g.current){await g.current;let n=w(i);if(n){S(n.frame),u.current=e,C(t),v();return}}if(T(),o===`seek`){s.current&&=(await s.current.return(),null);let r=n.canvases(i);s.current=r;let c=await r.next();if(t!==a.current){s.current&&=(await s.current.return(),null);return}if(c.done||!c.value){if(x(i)||y(`iterator_exhausted`,{mode:o,requestedTargetTime:e,clampedTargetTime:i},`warn`),t===a.current&&!x(i))try{s.current&&=(await s.current.return(),null),T();let r=n.canvases(i);s.current=r;let a=await r.next();!a.done&&a.value&&(S(a.value),C(t),u.current=e,v())}catch{}return}S(c.value),C(t)}else{let r=s.current;if(!r)return;let c=!1;for(;t===a.current;){let l=await r.next();if(t!==a.current)break;if(l.done||!l.value){if(x(i)||y(`iterator_exhausted`,{mode:o,requestedTargetTime:e,clampedTargetTime:i},`warn`),!c&&!x(i)){c=!0;try{s.current&&=(await s.current.return(),null),T();let e=n.canvases(i);s.current=e;let r=await e.next();if(t!==a.current||r.done||!r.value)break;S(r.value),C(t);break}catch{break}}break}let u=l.value;if(S(u),Math.abs(u.timestamp-i)<aD){C(t);break}if(u.timestamp>i){C(t);break}}}u.current=e,v()}catch(r){let a=r instanceof Error?{name:r.name,message:r.message,stack:r.stack}:{message:String(r)},c=r instanceof Error?`${r.name}: ${r.message}`:String(r),u=c.includes(`Unsupported configuration`)||c.includes(`isConfigSupported`)||c.includes(`OperationError`);if(y(`frame_process_failed`,{mode:o,requestedTargetTime:e,clampedTargetTime:i,unsupportedConfigAttempt:n,isUnsupportedConfig:u,error:a},`error`),u&&n<1)try{s.current&&=(await s.current.return(),null),T(),g.current=null,_.current=!1,l.current=null,await E(e,t,n+1)}catch{}}},D=Gn(()=>{let n=r.videoSink,s=r.duration;if(!n||!s)return;let c=e.startTime*s*1e3,l=s*(e.endTime-e.startTime)*1e3,u=((t.currentTime||e.page.startTime)-e.page.startTime)%l+c,d=u/1e3,h=b(d);f.current={pageStartTime:e.page.startTime,storeCurrentTime:t.currentTime,offsetMs:c,durationMs:l,restMs:u,targetTime:d,clampedTargetTime:h,startTime:e.startTime,endTime:e.endTime,videoDuration:s},((t,n)=>{p.current?m.current=t:(p.current=!0,o.current||=Kf(`mediabunny video frame ${e.id}`),(async()=>{let e=t;for(;e!==null&&n===a.current;)await E(e,n),e=m.current,m.current=null;o.current&&=(o.current(),null),p.current=!1})())})(h,i)});return()=>{D(),a.current++,o.current&&=(o.current(),null)}},[n,r.isReady,r.videoSink,r.duration,t,e]),n&&r.isReady?c.current:null};function sD(){return document.createElement(`canvas`)}var cD=new window.Image;cD.src=J_(`
272
272
  <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
273
273
  <path opacity="0.6" d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" fill="white"/>
274
274
  <path d="M4 5.49683V18.5032C4 20.05 5.68077 21.0113 7.01404 20.227L18.0694 13.7239C19.384 12.9506 19.384 11.0494 18.0694 10.2761L7.01404 3.77296C5.68077 2.98869 4 3.95 4 5.49683Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
275
275
  </svg>
276
- `);var oD=new window.Image;oD.src=G_(`
276
+ `);var lD=new window.Image;lD.src=J_(`
277
277
  <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
278
278
  <path opacity="0.6" d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" fill="white"/>
279
279
  <path opacity="0.6" d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" fill="white"/>
280
280
  <path d="M14 19L14 5C14 3.89543 14.8954 3 16 3L17 3C18.1046 3 19 3.89543 19 5L19 19C19 20.1046 18.1046 21 17 21L16 21C14.8954 21 14 20.1046 14 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
281
281
  <path d="M10 19L10 5C10 3.89543 9.10457 3 8 3L7 3C5.89543 3 5 3.89543 5 5L5 19C5 20.1046 5.89543 21 7 21L8 21C9.10457 21 10 20.1046 10 19Z" stroke="#323232" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
282
282
  </svg>
283
- `);var sD=(e,t,n,r,i=0,a=!1)=>{let o=Math.floor(Math.max(e.width*r,1)),s=Math.floor(Math.max(e.height*r,1)),c=Math.min(i*r,o/2,s/2),l=Math.max(e.width/n.width,e.height/n.height)*r,u=e.page._exportingOrRendering&&yp.imageDownScalingEnabled&&l<1&&!a,f=t instanceof HTMLVideoElement?t.videoWidth:t?.width,p=t instanceof HTMLVideoElement?t.videoHeight:t?.height,m=n.x===0&&n.y===0&&n.width===f&&n.height===p,h=d.useMemo(()=>{if(t&&f&&p)return m&&c===0&&!u?void 0:iD()},[t,c,u,m,f,p]),g=()=>{if(!h||!t)return;h.width=o,h.height=s;let e=h.getContext(`2d`);if(!e)return;c&&(e.beginPath(),e.moveTo(c,0),e.lineTo(o-c,0),e.arc(o-c,c,c,3*Math.PI/2,0,!1),e.lineTo(o,s-c),e.arc(o-c,s-c,c,0,Math.PI/2,!1),e.lineTo(c,s),e.arc(c,s-c,c,Math.PI/2,Math.PI,!1),e.lineTo(0,c),e.arc(c,c,c,Math.PI,3*Math.PI/2,!1),e.clip());let r=u?function(e,t){var n,r;let i=iD(),a=e instanceof HTMLVideoElement?e.videoWidth:e.width,o=e instanceof HTMLVideoElement?e.videoHeight:e.height;i.width=a,i.height=o,(n=i.getContext(`2d`))==null||n.drawImage(e,0,0,i.width,i.height);let s=function(e,t,n,r,i,a,o){for(var s=new ImageData(t,n),c=new Int32Array(e.data.buffer),l=e.width,u=new Int32Array(s.data.buffer),d=s.width,f=t/a,p=n/o,m=Math.round(1/f),h=Math.round(1/p),g=m*h,_=0;_<s.height;_++)for(var v=0;v<d;v++){for(var y=0+Math.round(v/f)+(0+Math.round(_/p))*l,b=0,x=0,S=0,C=0,w=0;w<h;w++)for(var T=0;T<m;T++){var E=c[y+T+w*l];b+=E<<24>>>24,x+=E<<16>>>24,S+=E<<8>>>24,C+=E>>>24}b=Math.round(b/g),x=Math.round(x/g),S=Math.round(S/g),C=Math.round(C/g),u[v+_*d]=C<<24|S<<16|x<<8|b}return s}(i.getContext(`2d`).getImageData(0,0,i.width,i.height),Math.floor(i.width*t),Math.floor(i.height*t),0,0,i.width,i.height);return i.width=Math.floor(i.width*t),i.height=Math.floor(i.height*t),(r=i.getContext(`2d`))==null||r.putImageData(s,0,0),i}(t,l):t,i=u?{x:Math.floor(n.x*l),y:Math.floor(n.y*l),width:Math.floor(n.width*l),height:Math.floor(n.height*l)}:n;e.drawImage(r,i.x,i.y,i.width,i.height,0,0,h.width,h.height)};return d.useLayoutEffect(()=>{g()},[h,e.width,e.height,n.x,n.y,n.width,n.height,i,r,a,e.page._exportingOrRendering,u]),d.useEffect(()=>()=>{h&&h.nodeName===`CANVAS`&&Du.Util.releaseCanvas(h)},[h]),[h||t,g]},cD=iD(),lD=sa(({element:e})=>{let t=Math.min(30,e.width/4,e.height/4),n=d.useRef(null);return d.useEffect(()=>{let e=n.current;if(!e)return;let t=new Du.Animation(t=>{e.rotate((t?.timeDiff||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}}),d.createElement(Kd,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},d.createElement(Jd,{width:e.width,height:e.height,fill:`rgba(124, 173, 212, 0.8)`}),d.createElement(`Arc`,{ref:n,x:e.width/2,y:e.height/2,fill:`white`,outerRadius:Math.abs(t),innerRadius:Math.max(1,t-5),angle:270}))}),uD=sa(({element:e})=>{let t=Math.max(10,Math.min(30,e.width/25));return d.createElement(Kd,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},d.createElement(Jd,{width:e.width,height:e.height,fill:`rgba(223, 102, 102, 0.8)`}),d.createElement(Zd,{text:`Can not load the video...`,fontSize:t,width:e.width,height:e.height,align:`center`,fill:`white`,verticalAlign:`middle`,padding:5}))}),dD=function(e,t,n){let r=d.useRef(`loading`),i=d.useRef(void 0),[a,o]=d.useState(0),s=d.useRef(),c=d.useRef(),l=d.useRef();return s.current===e&&c.current===t&&l.current===n||(r.current=`loading`,i.current=void 0,s.current=e,c.current=t,l.current=n),d.useLayoutEffect(function(){if(e){var a=document.createElement(`video`);return a.addEventListener(`canplay`,s),a.addEventListener(`error`,c),t&&(a.crossOrigin=t),n&&(a.referrerPolicy=n),a.src=e,a.load(),function(){a.removeEventListener(`canplay`,s),a.removeEventListener(`error`,c)}}function s(){r.current=`loaded`,i.current=a,i.current.currentTime=0,o(Math.random()),i.current.removeEventListener(`canplay`,s)}function c(e){let t=a.readyState===4,n=a.buffered&&a.buffered.length>0&&a.buffered.end(a.buffered.length-1)/a.duration*100>=100;if(t&&n)return;let s=e.message||a.error?.message||`Unknown error`,c=Error(`Video failed to load: `+s);console.error(c),r.current=`failed`,i.current=void 0,o(Math.random())}},[e,t,n]),[i.current,r.current]};function fD(e){return e.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA}var pD=(e,t,n)=>{let r=d.useRef(),i=()=>{var e;(e=r.current)==null||e.call(r),r.current=void 0};d.useEffect(()=>i,[]),d.useLayoutEffect(()=>{let a=`video with id ${n} url: ${t.slice(0,200)}`;e!==`loading`||r.current||(r.current=Kf(a)),e!==`loading`&&i(),e===`failed`&&Zf(a)},[e])},mD=sa(({element:e,store:t})=>{let[n,r]=d.useState(!1),i=d.useRef(null),a=d.useRef(null),o=t.selectedShapes.indexOf(e)>=0&&e.selectable,[s,c]=d.useState(!1),[l,u]=dD(e.src,`anonymous`),[f,p]=d.useState(!1),m=t.activePage===e.page,h=e.page._exportingOrRendering&&u===`loaded`,g=rD(e,t,h);pD(u,e.src,e.id),l&&(l.playsInline=!0);let _=((e,t,n)=>{let r=d.useMemo(()=>{var r,i;let{flipX:a,flipY:o}=e,s=e.type===`svg`||e.src.indexOf(`data:image/svg+xml`)>=0||e.src.indexOf(`.svg`)>=0,c=navigator.userAgent.toLowerCase().indexOf(`firefox`)>-1;if(!(a||o||c&&s))return t;if(!t)return null;let l=t instanceof HTMLVideoElement?t.videoWidth:t?.width,u=t instanceof HTMLVideoElement?t.videoHeight:t?.height;if(!l||!u)return null;let d=iD(),f=1;e.type===`svg`&&(f=Math.max(e.width/l*n,e.height/u*n)),d.width=Math.max(l*f,1),d.height=Math.max(u*f,1);let p=a?-d.width:0,m=o?-d.height:0;return(r=d.getContext(`2d`))==null||r.scale(a?-1:1,o?-1:1),(i=d.getContext(`2d`))==null||i.drawImage(t,p,m,d.width,d.height),d},[e.flipX,e.flipY,t,e.width,e.height,n]);return d.useEffect(()=>()=>{r&&r.nodeName===`CANVAS`&&Du.Util.releaseCanvas(r)},[r]),r})(e,l,t._elementsPixelRatio),v=h&&g||_||cD;d.useEffect(()=>{l&&t.history.ignore(()=>{e.set({duration:1e3*l.duration})})},[l]),d.useEffect(()=>{if(!l)return;let n=t.animatedElementsIds,r=(!n.length||n.includes(e.id))&&t.isPlaying,a=m&&(r||s);if(!a){l.pause();return}a&&(l.currentTime=e.startTime*l.duration,l.play());let o=new Du.Animation(()=>{I.current()},i.current?.getLayer());o.start();let u=()=>{c(!1),l.currentTime=e.startTime*l.duration},d=()=>{l.currentTime>=e.endTime*l.duration&&(l.pause(),l.currentTime=e.startTime*l.duration,c(!1))};return l.addEventListener(`ended`,u),l.addEventListener(`timeupdate`,d),()=>{l.pause(),o.stop(),l.removeEventListener(`ended`,u),l.removeEventListener(`timeupdate`,d)}},[l,s,t.isPlaying,m]),d.useEffect(()=>{l&&(l.volume=e.volume)},[l,e.volume]);let y=d.useRef(null);d.useEffect(()=>{let n=Gn(()=>{var n;if(l){if(h&&g){ie(),t.currentTime;return}let r=t.animatedElementsIds;if(r.length&&!r.includes(e.id))return;let a=t.currentTime>=e.page.startTime&&t.currentTime<e.page.startTime+e.page.duration,o=e.startTime*l.duration*1e3,s=l.duration*(e.endTime-e.startTime)*1e3,c=((t.currentTime||e.page.startTime)-e.page.startTime)%s+o;if(a||(c=0),Math.abs(1e3*l.currentTime-c)>500||!t.isPlaying){let n=c/1e3;n!==l.currentTime&&(l.currentTime=n),!fD(l)&&!t.isPlaying&&!y.current&&(y.current=Kf(`video ${e.id}`))}I.current(),(n=i.current?.getLayer())==null||n.batchDraw()}});return()=>{n(),y.current&&=(y.current(),null)}},[t,l,h,g]),d.useEffect(()=>{var t;if(!l)return;if(h){(t=y.current)==null||t.call(y),y.current=null;return}let n=()=>{var t;!fD(l)&&e.page._exportingOrRendering||(y.current&&=(I.current(),(t=i.current?.getLayer())==null||t.batchDraw(),y.current(),null))},r;return e.page._exportingOrRendering&&(r=setInterval(n,20)),l.addEventListener(`timeupdate`,n),l.addEventListener(`canplay`,n),()=>{clearInterval(r),l.removeEventListener(`timeupdate`,n),l.removeEventListener(`canplay`,n)}},[e.page._exportingOrRendering,l,e.id,Kf,h]);let{cropX:b,cropY:x,cropWidth:S,cropHeight:C}=e;u!==`loaded`&&(b=x=0,S=C=1);let w=(T=v)instanceof HTMLVideoElement?T.videoWidth:T?.width||0;var T;let E=(e=>e instanceof HTMLVideoElement?e.videoHeight:e?.height||0)(v),D=w*S,O=E*C,k=e.width/e.height,A,j,M=D/O,N=e.type===`svg`;N?(A=D,j=O):k>=M?(A=D,j=D/k):(A=O*k,j=O);let P={x:w*b,y:E*x,width:A,height:j},F=e.cornerRadius??0,[ee,te]=sD(e,v,P,t._elementsPixelRatio,F,!0),[ne,re]=((e,t,n,r)=>{let[i,a]=(0,rf.default)((e=>{let[t,n]=d.useState(e);return d.useEffect(()=>{(async()=>{let r=await async function(e){return e.indexOf(`data:image/svg+xml`)>=0||e.indexOf(`.svg`)>=0?G_(K_(await W_(e))):e}(e);r!==t&&n(r)})()},[e]),t})(e.clipSrc||``),`anonymous`);pD(e.clipSrc?a:`loaded`,e.clipSrc,e.id);let o=d.useMemo(()=>{if(t&&i)return iD()},[t,i]);function s(){var r;if(!i)return;let a=t instanceof HTMLVideoElement?t.videoWidth:t?.width,s=t instanceof HTMLVideoElement?t.videoHeight:t?.height;if(!t||!a||!s||!i||!i.width||!i.height||!o)return;let c=iD(),l=Math.max(e.width/i.width*n,e.height/i.height*n);c.width=i.width*l,c.height=i.height*l,(r=c.getContext(`2d`))==null||r.drawImage(i,0,0,c.width,c.height),o.width=Math.max(a,1),o.height=Math.max(s,1);let u=o.getContext(`2d`);u&&(u.save(),u.drawImage(c,0,0,a,s),Du.Util.releaseCanvas(c),u.globalCompositeOperation=`source-in`,u.drawImage(t,0,0,o.width,o.height),u.restore())}return d.useLayoutEffect(()=>{s()},[o,t,i,e.width,e.height,n,...r]),[e.clipSrc&&i?o:t,s]})(e,ee,t._elementsPixelRatio,[P,F,t._elementsPixelRatio]);function ie(){var e;te(),re(),(e=i.current?.getLayer())==null||e.batchDraw()}d.useEffect(()=>{ie()});let I=d.useRef(ie);I.current=ie;let ae=Math.max(e.width/A,e.height/j);d.useEffect(()=>{if(!e._cropModeEnabled)return;let t=i.current?.getStage();function n(t){e._cropModeEnabled&&t.target!==a.current&&e.toggleCropMode(!1)}function r(n){e._cropModeEnabled&&n.target.parentNode!==t?.content&&e.toggleCropMode(!1)}return document.body.addEventListener(`click`,r),t?.on(`click`,n),t?.on(`tap`,n),()=>{document.body.removeEventListener(`click`,r),document.body.removeEventListener(`touchstart`,r),t?.off(`click`,n),t?.off(`click`,n)}},[e._cropModeEnabled]),d.useLayoutEffect(()=>{if(!n&&!e._cropModeEnabled)return zp(i.current,e),Gn(()=>{zp(i.current,e)},{delay:100})},[v,n,S,C,e._cropModeEnabled]),d.useLayoutEffect(()=>{var t;n||e._cropModeEnabled?(t=i.current)==null||t.clearCache():zp(i.current,e)},[n,e.width,e.height,e._cropModeEnabled]),d.useEffect(()=>{zp(i.current,e)},[e.shadowEnabled,e.shadowBlur,e.cornerRadius,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);let oe=d.useRef(null),se=d.useRef(null),ce=d.useRef(null);d.useLayoutEffect(()=>{e._cropModeEnabled&&(se.current.nodes([oe.current]),ce.current.nodes([a.current]))},[e._cropModeEnabled]);let le=t=>{Math.round(t.target.x())>0&&(t.target.x(0),t.target.scaleX(1)),Math.round(t.target.y())>0&&(t.target.y(0),t.target.scaleY(1));let n=t.target.width()*t.target.scaleX(),r=t.target.height()*t.target.scaleY(),i=Math.min(1,A/n),a=Math.min(1,j/r),o=1-i,s=Math.min(o,Math.max(0,Math.round(-t.target.x())/n)),c=1-a,l=Math.min(c,Math.max(0,Math.round(-t.target.y())/r));t.target.setAttrs({x:-s*w,y:-l*E,scaleX:1,scaleY:1}),e.set({cropX:s,cropY:l,cropWidth:i,cropHeight:a})},ue=()=>{e.type!==`svg`&&e.contentEditable&&setTimeout(()=>{e.toggleCropMode(!0)})},de=u===`loading`,fe=u===`failed`,pe=!de&&!fe,me=d.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),he=pe?e.a.opacity:0;Rf(i,he);let ge=e.selectable||t.role===`admin`,_e=Bp();return d.createElement(d.Fragment,null,d.createElement(Kd,{onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1)},de&&d.createElement(lD,{element:e}),fe&&d.createElement(uD,{element:e}),d.createElement(Xd,{ref:i,name:`element`,id:e.id,image:ne,x:e.a.x,y:e.a.y,width:e.a.width||1,height:e.a.height||1,rotation:e.a.rotation,opacity:he,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,customCrop:P,listening:ge,draggable:_e?e.draggable&&o:e.draggable,preventDefault:!_e||o,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDblClick:ue,onDblTap:ue,onTransformStart:()=>{r(!0),me.current={cropX:e.cropX,cropY:e.cropY,cropWidth:e.cropWidth,cropHeight:e.cropHeight}},onTransform:t=>{let n=t.currentTarget,r=Math.abs(n.scaleX()-1)<1e-7?1:n.scaleX(),i=Math.abs(n.scaleY()-1)<1e-7?1:n.scaleY();n.scaleX(1),n.scaleY(1);let a=t.target.getStage()?.findOne(`Transformer`),o=1-A/w,s=Math.min(o,Math.max(0,e.cropX)),c=1-j/E,l=Math.min(c,Math.max(0,e.cropY)),u=a.getActiveAnchor(),d=!(u.indexOf(`middle`)>=0||u.indexOf(`center`)>=0),f=!d&&r<1&&me.current.cropHeight>j/E,p=d?e.cropWidth:e.cropWidth*r;f&&(p=e.cropWidth);let m=!d&&i<1&&me.current.cropWidth>A/w,h=d?e.cropHeight:e.cropHeight*i;m&&(h=e.cropHeight),N&&(p=e.cropWidth,h=e.cropHeight),e.set({cropX:s,cropY:l,x:n.x(),y:n.y(),width:n.width()*r,height:n.height()*i,rotation:t.target.rotation(),cropWidth:Math.min(p,1-s),cropHeight:Math.min(h,1-l)})},onTransformEnd:t=>{let n=t.currentTarget;e.set({width:n.width(),height:n.height(),x:n.x(),y:n.y(),rotation:t.target.rotation(),cropWidth:A/w,cropHeight:j/E}),r(!1)}}),d.createElement(Jd,{x:e.a.x,y:e.a.y,width:Math.max(e.a.width-e.borderSize,0),height:Math.max(e.a.height-e.borderSize,0),opacity:he,offsetX:-e.borderSize/2,offsetY:-e.borderSize/2,stroke:e.borderColor,strokeWidth:e.borderSize,listening:!1,visible:!!e.borderSize,rotation:e.rotation,cornerRadius:Math.max(0,F-e.borderSize),hideInExport:!e.showInExport}),!t.isPlaying&&d.createElement(`Image`,{image:s?f||_e?oD:void 0:aD,x:e.a.x,y:e.a.y,offsetX:-e.a.width/2+15/t.scale,offsetY:-e.a.height/2+15/t.scale,rotation:e.a.rotation,width:30/t.scale,height:30/t.scale,hideInExport:!0,onClick:()=>c(!s),onTap:()=>c(!s)}),e._cropModeEnabled&&d.createElement(lf,{selector:`.page-abs-container`,enabled:!0},d.createElement(`Rect`,{x:-window.innerWidth/t.scale,y:-window.innerWidth/t.scale,width:window.innerWidth/t.scale*3,height:window.innerWidth/t.scale*3,fill:`rgba(0,0,0,0.3)`}),d.createElement(`Image`,{listening:!1,image:ne,x:e.a.x,y:e.a.y,width:e.a.width,height:e.a.height,rotation:e.a.rotation,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur}),d.createElement(`Group`,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,scaleX:ae,scaleY:ae},d.createElement(`Image`,{image:v,ref:a,width:w,height:E,opacity:.4,draggable:!0,x:-e.cropX*w,y:-e.cropY*E,onDragMove:le,onTransform:le}),d.createElement(`Transformer`,{ref:ce,anchorSize:20,enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,rotateEnabled:!1,borderEnabled:!1,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2}),d.createElement(`Rect`,{width:A,height:j,ref:oe,listening:!1,onTransform:t=>{t.target.x()<-e.cropX*w-1e-9&&(t.target.x(-e.cropX*w),t.target.scaleX(1)),t.target.y()<-e.cropY*E-1e-9&&(t.target.y(-e.cropY*E),t.target.scaleY(1));let n=Math.min(1,Math.max(0,e.cropX+t.target.x()/w)),r=Math.min(1,Math.max(0,t.target.y()/E+e.cropY)),i=t.target.width()*t.target.scaleX(),a=t.target.height()*t.target.scaleY(),o=Math.min(1-n,i/w),s=Math.min(1-r,a/E),c=t.target.getAbsolutePosition(t.target.getParent().getParent());t.target.scale({x:1,y:1}),t.target.position({x:0,y:0}),e.set({x:c.x,y:c.y,cropX:n,cropY:r,cropWidth:o,cropHeight:s,width:Math.min(i*ae,w*(1-n)*ae),height:Math.min(a*ae,E*(1-r)*ae)})}}),d.createElement(`Transformer`,{ref:se,enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,keepRatio:!1,rotateEnabled:!1,anchorFill:`rgb(240, 240, 240)`,anchorStrokeWidth:2,borderStrokeWidth:2,visible:e.resizable})))))}),hD=({width:e,height:t,cornerRadius:n})=>{if(n>0){let r=Math.min(n,e/2,t/2);return`M 0 ${r} A ${r} ${r} 0 0 1 ${r} 0 L ${e-r} 0 A ${r} ${r} 0 0 1 ${e} ${r} L ${e} ${t-r} A ${r} ${r} 0 0 1 ${e-r} ${t} L ${r} ${t} A ${r} ${r} 0 0 1 0 ${t-r} Z`}return`M 0 0 L ${e} 0 L ${e} ${t} L 0 ${t} Z`},gD=({width:e,height:t})=>`M ${e/2} 0 L ${e} ${t} L 0 ${t} Z`,_D=({width:e,height:t})=>`M 0 0 L ${e} 0 L 0 ${t} Z`,vD=({width:e,height:t})=>`M ${e/2} ${t/2} m -${e/2}, 0 a ${e/2},${t/2} 0 1,0 ${e},0 a ${e/2},${t/2} 0 1,0 -${e},0`;function yD({width:e,height:t}){let n=e/2,r=t/2,i=e/2,a=t/2,o=i/2,s=a/2,c=``,l=Math.PI/5;for(let e=0;e<10;e++){let t=e%2==0?a:s,u=n+(e%2==0?i:o)*Math.sin(e*l),d=r-t*Math.cos(e*l);e===0?c=`M ${u} ${d}`:c+=` L ${u} ${d}`}return c+` Z`}function bD({width:e,height:t}){let n=e/2,r=t/2;return`M ${n} 0 L ${e} ${r} L ${n} ${t} L 0 ${r} Z`}function xD({width:e,height:t}){let n=e/2,r=t/2,i=e/2,a=t/2,o=``,s=2*Math.PI/5;for(let e=0;e<5;e++){let t=a,c=n+i*Math.sin(e*s),l=r-t*Math.cos(e*s);e===0?o=`M ${c} ${l}`:o+=` L ${c} ${l}`}return o+` Z`}function SD({width:e,height:t}){let n=e/2,r=t/2,i=e/2,a=t/2,o=``,s=2*Math.PI/6;for(let e=0;e<6;e++){let t=a,c=n+i*Math.sin(e*s),l=r-t*Math.cos(e*s);e===0?o=`M ${c} ${l}`:o+=` L ${c} ${l}`}return o+` Z`}function Q({path:e,aspectRatio:t,width:n,height:r}){return{path:e,scaleX:n/t.width,scaleY:r/t.height}}function CD({width:e,height:t}){let n=.1*Math.min(e,t),r=.2*e,i=.2*t,a=.5*e,o=`M ${n},0`;return o+=` H `+(e-n),o+=` A ${n},${n} 0 0 1 ${e},${n}`,o+=` V `+(t-n-i),o+=` A ${n},${n} 0 0 1 ${e-n},${t-i}`,o+=` H ${a+r/2}`,o+=` L ${a},${t}`,o+=` L ${a-r/2},${t-i}`,o+=` H ${n}`,o+=` A ${n},${n} 0 0 1 0,${t-n-i}`,o+=` V ${n}`,o+=` A ${n},${n} 0 0 1 ${n},0`,o+=` Z`,o}function wD({width:e,height:t}){let n=.3*e,r=.3*t,i=e/2,a=t/2,o=i-n/2,s=i+n/2,c=a-r/2,l=a+r/2,u=`M ${o},0 `;return u+=`H ${s} `,u+=`V ${c} `,u+=`H ${e} `,u+=`V ${l} `,u+=`H ${s} `,u+=`V ${t} `,u+=`H ${o} `,u+=`V ${l} `,u+=`H 0 `,u+=`V ${c} `,u+=`H ${o} `,u+=`V 0 `,u+=`Z`,u}var TD={rect:hD,circle:vD,star:yD,triangle:gD,rightTriangle:_D,diamond:bD,pentagon:xD,hexagon:SD,speechBubble:CD,cross:wD,arc:({width:e,height:t})=>Q({path:`M234 117C234 85.97 221.673 56.21 199.731 34.269C177.79 12.327 148.03 0 117 0C85.97 0 56.2103 12.327 34.2685 34.268C12.3268 56.21 0 85.97 0 117H117H234Z`,aspectRatio:{width:234,height:117},width:e,height:t}),cloud:({width:e,height:t})=>Q({path:`M216.41 57.006C216.961 54.084 217.249 51.069 217.249 47.986C217.249 21.4841 195.972 0 169.725 0C153.666 0 139.467 8.043 130.865 20.3575C122.606 13.3566 111.954 9.1402 100.327 9.1402C74.3322 9.1402 53.2123 30.2136 52.8094 56.364H52.8035C23.6407 56.364 0 80.235 0 109.682C0 139.129 23.6407 163 52.8035 163H208.197C237.359 163 261 139.129 261 109.682C261 83.056 241.672 60.99 216.41 57.006Z`,aspectRatio:{width:261,height:163},width:e,height:t}),rightArrow:({width:e,height:t})=>{let n=.6*e;return`M 0 ${t/4} L ${n} ${t/4} L ${n} 0 L ${e} ${t/2} L ${n} ${t} L ${n} ${.75*t} L 0 ${.75*t} Z`},leftArrow:({width:e,height:t})=>{let n=.4*e;return`M ${e} ${t/4} L ${n} ${t/4} L ${n} 0 L 0 ${t/2} L ${n} ${t} L ${n} ${.75*t} L ${e} ${.75*t} Z`},downArrow:({width:e,height:t})=>{let n=.6*t;return`M ${e/4} 0 L ${e/4} ${n} L 0 ${n} L ${e/2} ${t} L ${e} ${n} L ${.75*e} ${n} L ${.75*e} 0 Z`},upArrow:({width:e,height:t})=>{let n=.4*t;return`M ${e/4} ${t} L ${e/4} ${n} L 0 ${n} L ${e/2} 0 L ${e} ${n} L ${.75*e} ${n} L ${.75*e} ${t} Z`},asterisk1:({width:e,height:t})=>Q({path:`M45.5265 218.498C51.5466 222.87 58.5359 224.98 65.4742 224.98C75.916 224.98 86.221 220.2 92.853 211.217C92.872 211.198 92.89 211.178 92.907 211.157C92.923 211.136 92.939 211.115 92.954 211.094L92.977 211.061C92.993 211.039 93.008 211.017 93.023 210.996L116.491 178.725L139.959 210.996C139.982 211.031 140.006 211.058 140.029 211.088C140.04 211.102 140.05 211.116 140.061 211.132C151.115 226.188 172.355 229.505 187.473 218.515C202.608 207.526 205.992 186.278 195.074 171.104L195.05 171.066C195.03 171.034 195.014 171.01 194.989 170.985L171.572 138.696L209.512 126.346C227.334 120.545 237.129 101.305 231.33 83.476C225.532 65.648 206.315 55.8493 188.476 61.6334L150.537 73.933L150.52 34.0064C150.502 15.2594 135.248 0 116.508 0C97.768 0 82.514 15.2594 82.497 34.0234L82.463 73.916L44.5233 61.6163C44.5083 61.6163 44.49 61.613 44.4716 61.6078C44.4477 61.6014 44.4232 61.5918 44.4041 61.5823C26.5992 55.8664 7.45076 65.665 1.66886 83.46C-4.11314 101.254 5.61427 120.426 23.3511 126.278C23.3675 126.283 23.3822 126.289 23.3963 126.295L23.4588 126.319L23.4873 126.329L61.4098 138.679L37.9929 170.968C37.9844 170.985 37.9718 171.002 37.9591 171.019C37.9462 171.036 37.9336 171.053 37.9251 171.07C26.9903 186.244 30.3915 207.509 45.5265 218.498Z`,aspectRatio:{width:233,height:225},width:e,height:t}),asterisk2:({width:e,height:t})=>Q({path:`M46.0556 112L0 85.388L33.9456 26.6121L80.028 53.1781L80.054 0H147.946L147.972 53.1781L194.054 26.6121L228 85.388L181.944 112L228 138.612L194.054 197.388L147.972 170.822L147.946 224H80.054L80.028 170.822L33.9456 197.388L0 138.612L46.0556 112Z`,aspectRatio:{width:228,height:224},width:e,height:t}),bookmark:({width:e,height:t})=>Q({path:`M0 0H199V238L99.5 142.8L0 238V0Z`,aspectRatio:{width:199,height:238},width:e,height:t}),butterfly:({width:e,height:t})=>Q({path:`M94.5 100.713C91.935 150.916 50.703 190.909 0 191.493V0C50.703 0.5845 91.935 40.5767 94.5 90.78C97.031 41.2385 137.217 1.6407 187 0.0438004V191.45C137.217 189.853 97.031 150.255 94.5 100.713Z`,aspectRatio:{width:187,height:192},width:e,height:t}),cylinder:({width:e,height:t})=>Q({path:`M169 36.8497V218.15C169 238.502 131.168 255 84.5 255C37.832 255 0 238.502 0 218.15V36.8497C0 16.4982 37.832 0 84.5 0C131.168 0 169 16.4982 169 36.8497Z`,aspectRatio:{width:169,height:255},width:e,height:t}),diamond2:({width:e,height:t})=>Q({path:`M0 55.5L124 185L248 55.5L189.307 0H58.6933L0 55.5Z`,aspectRatio:{width:248,height:185},width:e,height:t}),door:({width:e,height:t})=>Q({path:`M140 69.697C140 31.2044 108.66 0 70 0C31.34 0 0 31.2044 0 69.697V207H140V69.697Z`,aspectRatio:{width:140,height:207},width:e,height:t}),drop1:({width:e,height:t})=>Q({path:`M167 150.687C167 196.328 129.407 234 83.139 234C37.593 234 0 196.328 0 150.687C0 100.7 51.329 36.9474 83.139 0C114.948 39.1207 167 98.526 167 150.687Z`,aspectRatio:{width:167,height:234},width:e,height:t}),drop2:({width:e,height:t})=>Q({path:`M73 239C53.64 239 35.071 231.315 21.3812 217.634C7.691 203.954 0 185.4 0 166.054C0 136.091 13.8696 113.633 30.768 86.27C43.912 64.9877 58.888 40.7377 70.597 7.6816C71.281 5.7496 72.989 0 72.989 0C72.989 0 72.993 0.0124998 73 0.0363998C73.007 0.0124998 73.011 0 73.011 0C73.011 0 74.719 5.7496 75.403 7.6816C87.112 40.7377 102.088 64.9877 115.232 86.27C132.13 113.633 146 136.091 146 166.054C146 185.4 138.309 203.954 124.619 217.634C111.025 231.218 92.225 239 73 239Z`,aspectRatio:{width:146,height:239},width:e,height:t}),explosion:({width:e,height:t})=>Q({path:`M165.802 184.465L118.997 260L125.343 182.079L34.9058 219.45L99.164 159.817L0 163.792L78.538 134.373L0 74.7401L86.471 89.052V0L118.997 89.052L165.802 10.3364L149.143 97.798L217.368 29.419L165.802 112.905L245.927 81.101L165.802 143.914H261L165.802 184.465Z`,aspectRatio:{width:261,height:260},width:e,height:t}),flag:({width:e,height:t})=>Q({path:`M0 142.161C0 142.161 51.9956 118.626 103 137.469C159.992 158.525 206 141.31 206 141.31V11.1373C206 11.1373 160 28.3218 103.016 7.28273C52 -11.553 0 12.0974 0 12.0974V142.161Z`,aspectRatio:{width:206,height:148},width:e,height:t}),flower:({width:e,height:t})=>Q({path:`M135.351 66.1893C196.683 -5.00591 256.536 100.304 164.908 117.361C256.536 135.16 195.944 239.728 135.351 168.532C166.386 257.526 45.9394 256.785 76.975 168.532C15.643 239.728 -44.2109 135.16 47.4173 117.361C-44.9498 100.304 15.643 -4.26431 76.975 66.1893C45.2005 -22.0631 166.386 -22.0631 135.351 66.1893ZM105.793 104.012C113.183 104.012 119.833 109.945 119.833 117.361C119.833 124.777 113.183 131.452 105.793 131.452C98.404 131.452 92.492 124.777 92.492 117.361C92.492 109.945 98.404 104.012 105.793 104.012Z`,aspectRatio:{width:212,height:235},width:e,height:t}),frame:({width:e,height:t})=>Q({path:`M0 0H240L200 88L240 176H0L40 88L0 0Z`,aspectRatio:{width:240,height:176},width:e,height:t}),heart1:({width:e,height:t})=>Q({path:`M215.886 56.157C215.886 24.729 191.112 0 160.584 0C135.933 0 115.08 16.983 107.937 39.93C100.788 16.986 79.935 0.591 55.284 0.591C24.75 0.591 0 24.615 0 56.055C0 71.919 6.321 83.127 16.494 95.121L107.988 189.447L199.377 95.121C209.559 83.127 215.886 72.009 215.886 56.157Z`,aspectRatio:{width:216,height:190},width:e,height:t}),home:({width:e,height:t})=>Q({path:`M0 62.143L95.5 0L191 62.143V195H0V62.143Z`,aspectRatio:{width:191,height:195},width:e,height:t}),home2:({width:e,height:t})=>Q({path:`M206 94.076L103 0L0 94.076H31.2377V189H175.607V94.076H206Z`,aspectRatio:{width:206,height:189},width:e,height:t}),hourglass:({width:e,height:t})=>Q({path:`M0.392782 0H187.607C193.014 43.3688 140.804 53.797 140.804 97.5C140.804 141.203 193.014 151.631 187.607 195H0.392782C-5.01452 151.631 47.196 141.203 47.196 97.5C47.196 53.797 -5.01452 43.3688 0.392782 0Z`,aspectRatio:{width:188,height:195},width:e,height:t}),house:({width:e,height:t})=>Q({path:`M0 92.367L95 0L190 92.367V223H0V92.367Z`,aspectRatio:{width:190,height:223},width:e,height:t}),keyhole:({width:e,height:t})=>Q({path:`M115 57.0494C115 25.5387 89.416 0 57.863 0C26.311 0 0.726898 25.5414 0.726898 57.0494C0.726898 78.652 12.759 97.451 30.505 107.136L0 219H114.845L84.448 107.524C102.608 97.962 115 78.959 115 57.0494Z`,aspectRatio:{width:115,height:219},width:e,height:t}),kiss:({width:e,height:t})=>Q({path:`M124.5 17.1468C80.036 -36.5162 0 52.9218 0 52.9218C0 52.9218 44.4643 120 124.5 120C204.536 120 249 52.9218 249 52.9218C249 52.9218 168.964 -36.5162 124.5 17.1468Z`,aspectRatio:{width:249,height:120},width:e,height:t}),leaf:({width:e,height:t})=>Q({path:`M204.414 0.0151567C204.414 0.0151567 206.837 93.9509 150.394 150.394C93.9507 206.837 0.0151569 204.413 0.0151569 204.413C0.0151569 204.413 -2.40835 110.478 54.0347 54.0349C110.478 -2.40834 204.414 0.0151567 204.414 0.0151567Z`,aspectRatio:{width:205,height:205},width:e,height:t}),lightning1:({width:e,height:t})=>Q({path:`M111.5 0L0 142H51.433L31.5 253L143 111H91.567L111.5 0Z`,aspectRatio:{width:143,height:253},width:e,height:t}),lightning2:({width:e,height:t})=>Q({path:`M126 0H43L0 120.531H36L6 227L110 80.354H73L126 0Z`,aspectRatio:{width:126,height:227},width:e,height:t}),magnet:({width:e,height:t})=>Q({path:`M88.402 0H0V67.669H88.402C105.271 67.669 118.957 81.308 118.957 98C118.957 114.689 105.271 128.331 88.402 128.331H0V196H88.402C142.747 196 187 152.072 187 98C187 43.9279 142.747 0 88.402 0Z`,aspectRatio:{width:187,height:196},width:e,height:t}),mithosis:({width:e,height:t})=>Q({path:`M150.996 136.45C137.141 128.926 117.559 128.7 103.532 135.896C93.843 140.867 82.875 143.67 71.2577 143.67C31.9033 143.67 0 111.508 0 71.835C0 32.161 31.9033 0 71.2577 0C83.467 0 94.959 3.0955 105.004 8.5504C118.859 16.0745 138.441 16.3 152.467 9.1038C162.157 4.1328 173.125 1.3303 184.742 1.3303C224.097 1.3303 256 33.492 256 73.165C256 112.839 224.097 145 184.742 145C172.533 145 161.041 141.905 150.996 136.45Z`,aspectRatio:{width:256,height:145},width:e,height:t}),orangeRicky:({width:e,height:t})=>Q({path:`M69 0H0V69V138V207H69H138V138H69V69V0Z`,aspectRatio:{width:138,height:207},width:e,height:t}),party:({width:e,height:t})=>Q({path:`M134.622 0L144.682 68.2539L174.415 5.9977L163.91 74.1846L210.671 23.4578L180.535 85.519L240.169 50.8289L193.079 101.25L260.29 85.679L200.43 119.98L269.245 124.911L201.934 140.044L266.237 165.04L197.456 159.661L251.535 202.5L187.396 177.086L226.445 233.962L172.646 190.771L193.197 256.631L154.518 199.501L154.743 268.492L134.622 202.5L114.501 268.492L114.727 199.501L76.0482 256.631L96.5985 190.771L42.7992 233.962L81.8489 177.086L17.7091 202.5L71.7885 159.661L3.0072 165.04L67.3112 140.044L0 124.911L68.8149 119.98L8.9545 85.679L76.1658 101.25L29.0753 50.8289L88.7105 85.519L58.5743 23.4578L105.335 74.1846L94.8305 5.9977L124.562 68.2539L134.622 0Z`,aspectRatio:{width:270,height:269},width:e,height:t}),pillow:({width:e,height:t})=>Q({path:`M176 0.00169945C157.812 16.9062 125.203 28.174 88.001 28.174C50.798 28.174 18.1881 16.9054 0 0V258.421C18.1882 241.516 50.798 230.248 88 230.248C125.202 230.248 157.812 241.516 176 258.421V0.00169945Z`,aspectRatio:{width:176,height:259},width:e,height:t}),polygon:({width:e,height:t})=>Q({path:`M110 0L219.119 63V189L110 252L0.880798 189V63L110 0Z`,aspectRatio:{width:220,height:252},width:e,height:t}),rainbow:({width:e,height:t})=>Q({path:`M186.907 141H282C282 63.128 218.872 0 141 0C63.1278 0 0 63.128 0 141H95.093C95.093 115.646 115.646 95.093 141 95.093C166.354 95.093 186.907 115.646 186.907 141Z`,aspectRatio:{width:282,height:141},width:e,height:t}),rhodeIsland:({width:e,height:t})=>Q({path:`M69 0H0V69V138H69V207H138V138V69H69V0Z`,aspectRatio:{width:138,height:207},width:e,height:t}),shell:({width:e,height:t})=>Q({path:`M109 0C169.199 0 218 48.743 218 108.87C185.392 108.87 158.958 135.273 158.958 167.842C158.958 179.736 158.958 191 158.958 191H59.042C59.042 191 59.042 179.736 59.042 167.842C59.042 135.273 32.6077 108.87 0 108.87C0 48.743 48.8007 0 109 0Z`,aspectRatio:{width:218,height:191},width:e,height:t}),shield1:({width:e,height:t})=>Q({path:`M203.184 30.7277C142.457 30.7277 102.853 0 102.853 0C102.853 0 63.249 30.7277 3.05098 30.7277C3.05098 30.7277 -3.81372 128.209 3.05098 162.115C9.38758 193.902 102.853 249 102.853 249C102.853 249 196.319 193.902 203.184 162.115C209.52 128.738 203.184 30.7277 203.184 30.7277Z`,aspectRatio:{width:206,height:249},width:e,height:t}),shield2:({width:e,height:t})=>Q({path:`M0 12.9585C64.624 -4.3195 136.376 -4.3195 201 12.9585C201 51.0564 201 89.154 201 127.252C201 184.396 100.498 240 100.498 240C100.498 240 0 184.406 0 127.252C0 89.154 0 51.0564 0 12.9585Z`,aspectRatio:{width:201,height:240},width:e,height:t}),skewedRectangle:({width:e,height:t})=>Q({path:`M85.9799 0H290L204.02 141H0L85.9799 0Z`,aspectRatio:{width:290,height:141},width:e,height:t}),softFlower:({width:e,height:t})=>Q({path:`M109 0C80.073 0 56.6234 23.4498 56.6234 52.3766C56.6234 54.722 54.722 56.6234 52.3766 56.6234C23.4498 56.6234 0 80.073 0 109C0 137.927 23.4498 161.377 52.3766 161.377C54.722 161.377 56.6234 163.278 56.6234 165.623C56.6234 194.55 80.073 218 109 218C137.927 218 161.377 194.55 161.377 165.623C161.377 163.278 163.278 161.377 165.623 161.377C194.55 161.377 218 137.927 218 109C218 80.073 194.55 56.6234 165.623 56.6234C163.278 56.6234 161.377 54.722 161.377 52.3766C161.377 23.4498 137.927 0 109 0Z`,aspectRatio:{width:218,height:218},width:e,height:t}),softStar:({width:e,height:t})=>Q({path:`M130.424 3.17662C130.927 -1.05888 137.073 -1.05888 137.576 3.17662L141.792 38.7086C147.236 84.59 183.41 120.764 229.291 126.208L264.823 130.424C269.059 130.927 269.059 137.073 264.823 137.576L229.291 141.792C183.41 147.236 147.236 183.41 141.792 229.291L137.576 264.823C137.073 269.059 130.927 269.059 130.424 264.823L126.208 229.291C120.764 183.41 84.59 147.236 38.7086 141.792L3.17662 137.576C-1.05888 137.073 -1.05888 130.927 3.17662 130.424L38.7086 126.208C84.59 120.764 120.764 84.59 126.208 38.7086L130.424 3.17662Z`,aspectRatio:{width:268,height:268},width:e,height:t}),stairs1:({width:e,height:t})=>Q({path:`M0 0H67.667V67.667H135.333V135.333H203V203H0V0Z`,aspectRatio:{width:203,height:203},width:e,height:t}),stairs2:({width:e,height:t})=>Q({path:`M50 0H0V200H200V150H150V100H100V50H50V0Z`,aspectRatio:{width:200,height:200},width:e,height:t}),teewee:({width:e,height:t})=>Q({path:`M69 0H138V69H207V138H138H69H0V69H69V0Z`,aspectRatio:{width:207,height:138},width:e,height:t}),blob1:({width:e,height:t})=>Q({path:`M172.979 19.611C191.285 33.0858 204.505 54.442 210.861 78.5949C217.471 103.002 217.471 130.46 205.776 151.816C194.335 173.427 171.454 189.444 147.047 196.054C122.639 202.919 96.7069 200.631 75.3506 190.715C54.2486 180.546 37.7229 163.003 23.4855 142.155C9.5022 121.307 -2.19289 97.4087 0.349524 74.7813C3.14617 52.1538 19.9261 30.7976 40.2654 17.8313C60.6046 4.61077 84.5033 -0.474048 108.148 0.0344341C131.538 0.542916 154.928 6.13621 172.979 19.611Z`,aspectRatio:{width:216,height:200},width:e,height:t}),blob10:({width:e,height:t})=>Q({path:`M188.684 8.95173C205.601 24.3309 200.988 63.0866 191.453 99.3816C182.225 135.677 168.076 169.511 146.238 175.355C124.399 181.507 94.871 159.668 66.5733 143.059C37.9679 126.449 10.5929 115.068 2.59569 95.0754C-5.4015 75.0824 5.97912 46.1694 24.4342 30.4826C42.8893 14.7958 68.4188 12.0276 100.715 6.79864C132.704 1.5697 171.767 -6.42749 188.684 8.95173Z`,aspectRatio:{width:200,height:177},width:e,height:t}),blob11:({width:e,height:t})=>Q({path:`M137.368 29.4923C148.97 46.7605 146.542 72.1231 148.161 99.1046C149.779 126.086 155.715 154.956 144.113 174.383C132.781 193.81 103.911 203.793 80.4369 198.666C56.963 193.27 38.6156 173.034 28.3626 153.607C17.8398 134.181 15.4115 115.833 9.47555 91.5498C3.53961 67.2664 -5.63411 37.3169 4.61887 20.0488C15.1417 2.51078 45.0911 -1.80626 72.8821 0.622074C100.673 2.78059 126.036 12.2241 137.368 29.4923Z`,aspectRatio:{width:152,height:200},width:e,height:t}),blob12:({width:e,height:t})=>Q({path:`M158.391 17.923C172.491 28.5703 180.261 48.1384 187.743 70.5842C194.937 93.3177 202.419 118.641 194.649 138.785C187.167 158.928 164.146 173.317 138.535 184.54C112.923 196.05 84.4347 204.108 58.8235 197.777C33.2123 191.446 10.191 170.439 2.99688 146.267C-4.48504 121.807 3.57241 94.181 10.4788 68.282C17.0974 42.0953 22.565 17.6352 37.8166 7.27563C53.0682 -3.37171 78.1038 0.081487 100.837 2.67138C123.859 5.26127 144.29 7.27563 158.391 17.923Z`,aspectRatio:{width:198,height:200},width:e,height:t}),blob13:({width:e,height:t})=>Q({path:`M149.668 1.37595C170.663 5.22017 193.728 17.3442 198.755 34.7911C204.078 52.2379 191.363 75.3032 178.943 93.9329C166.819 112.563 154.99 126.757 140.501 145.386C126.011 164.312 108.86 187.673 92.5957 186.194C76.3317 185.011 60.9549 159.285 45.8737 140.655C30.4968 122.321 15.7114 110.788 7.43151 95.1157C-0.848339 79.4432 -2.32688 59.0392 3.5873 41.5924C9.50148 23.8498 23.1041 8.76868 38.7767 3.44592C54.745 -1.87685 73.3746 2.55879 91.7086 2.26308C110.338 2.26308 128.968 -2.17256 149.668 1.37595Z`,aspectRatio:{width:200,height:187},width:e,height:t}),blob14:({width:e,height:t})=>Q({path:`M137.838 28.6426C150.711 40.5617 165.014 46.5213 178.363 58.2021C191.474 69.8828 203.87 87.0464 198.864 99.6807C193.858 112.315 171.689 120.42 157.862 135.676C144.275 151.171 139.269 173.579 126.873 182.161C114.477 190.505 94.9294 185.022 76.8123 178.109C58.4568 171.196 41.5316 163.091 28.1822 150.456C14.5943 137.822 4.58225 120.42 1.24488 101.826C-2.09248 83.2322 1.00651 62.9697 13.8792 52.4809C26.7519 41.992 49.1598 41.0385 65.6083 30.788C82.0567 20.5376 92.0688 0.990158 103.034 0.0366268C113.762 -0.916905 125.204 16.9618 137.838 28.6426Z`,aspectRatio:{width:200,height:187},width:e,height:t}),blob15:({width:e,height:t})=>Q({path:`M185.203 1.52939C197.679 7.62217 200 32.2835 200 51.7223C200 71.1612 197.389 85.3777 197.679 100.175C198.259 114.681 201.741 129.768 198.259 143.114C194.778 156.46 184.623 168.356 171.567 173.868C158.801 179.671 143.134 179.091 130.368 174.739C117.312 170.387 106.867 162.263 86.8482 160.812C66.539 159.362 36.9454 164.294 18.9572 155.3C0.968966 146.306 -5.41395 123.095 5.03083 105.977C15.4756 88.5692 42.4579 77.5442 55.5139 59.5559C68.2798 41.8578 67.1192 17.4867 76.9837 9.6531C86.5581 2.10965 107.158 11.3939 128.627 9.6531C150.097 8.20244 172.728 -4.27327 185.203 1.52939Z`,aspectRatio:{width:200,height:179},width:e,height:t}),blob16:({width:e,height:t})=>Q({path:`M158.441 55.3221C167.253 80.2399 160.264 105.462 147.501 134.938C134.738 164.717 116.81 199.055 97.0576 199.967C77.3057 201.182 55.7305 168.668 34.4592 133.722C13.1879 99.0802 -7.77953 62.3112 2.85612 36.4818C13.4918 10.6523 56.0344 -3.93369 90.0685 0.928322C123.799 6.09421 149.324 30.7081 158.441 55.3221Z`,aspectRatio:{width:163,height:200},width:e,height:t}),blob17:({width:e,height:t})=>Q({path:`M168.917 36.7587C178.871 53.2457 175.138 76.5764 172.961 106.129C170.472 135.37 169.85 170.832 150.563 187.63C131.276 204.739 93.3252 203.495 65.0173 187.63C36.7095 172.077 18.0449 142.213 7.77943 107.373C-2.79714 72.2213 -4.35252 32.7147 14.312 14.0502C32.9765 -4.3033 72.1721 -1.50361 103.591 4.7179C135.32 10.6283 158.962 20.2717 168.917 36.7587Z`,aspectRatio:{width:176,height:200},width:e,height:t}),blob18:({width:e,height:t})=>Q({path:`M178.188 21.1464C193.012 36.3069 196.381 62.9219 198.739 88.1893C200.76 113.12 201.771 136.366 190.316 149.168C178.862 162.307 155.279 164.665 135.065 167.697C115.188 170.73 99.0168 174.098 72.4018 177.131C46.1237 180.163 9.40176 182.521 1.65309 168.371C-6.09559 154.221 15.4659 123.564 23.5515 92.9059C31.6371 62.2481 26.2467 31.2534 38.3751 15.4192C50.1665 -0.0781831 79.8136 -1.08888 107.776 0.595609C136.076 1.9432 163.028 5.64909 178.188 21.1464Z`,aspectRatio:{width:200,height:180},width:e,height:t}),blob19:({width:e,height:t})=>Q({path:`M148.621 13.3857C171.945 24.3818 194.937 41.3756 192.938 60.702C190.605 80.3615 163.282 101.687 149.953 123.346C136.958 145.005 137.958 166.664 128.295 174.661C118.631 182.325 98.3054 175.994 73.6476 181.991C48.9899 187.989 20.0004 205.983 11.0036 197.986C1.67366 189.989 12.6697 156.001 12.3365 131.343C12.0033 106.685 0.340809 91.0243 0.00759636 75.0301C-0.325616 59.0359 10.3372 42.3753 25.3318 28.7135C39.9931 15.0518 58.9863 4.05578 80.3119 1.05687C101.638 -2.27526 124.962 2.38972 148.621 13.3857Z`,aspectRatio:{width:194,height:200},width:e,height:t}),blob2:({width:e,height:t})=>Q({path:`M140.464 18.6393C156.081 28.3718 169.887 39.9149 178.714 54.853C187.541 69.5649 191.389 87.6717 189.578 104.421C187.768 121.396 180.525 137.239 172.377 153.535C164.455 169.832 155.854 186.58 142.048 194.276C128.241 201.971 109.456 200.613 92.4804 197.671C75.2789 194.502 60.1144 189.749 45.1762 182.733C30.4644 175.716 16.2052 166.21 8.28346 153.083C0.361703 139.729 -1.44898 122.527 1.04072 106.91C3.30408 91.2931 9.64147 76.8076 15.9789 60.5114C22.0899 44.2153 28.201 26.1084 40.6495 14.7916C53.0979 3.24849 71.8838 -1.27823 89.7643 0.306124C107.871 1.66414 124.846 9.13322 140.464 18.6393Z`,aspectRatio:{width:191,height:200},width:e,height:t}),blob20:({width:e,height:t})=>Q({path:`M150.035 13.2464C157.376 24.9386 153.026 48.323 157.92 65.7254C163.087 83.1277 177.498 94.2761 182.392 108.415C187.287 122.555 182.392 139.957 173.147 156.272C163.63 172.587 149.763 187.814 132.089 195.155C114.414 202.225 93.2053 201.137 73.6276 194.611C54.3219 188.357 36.9196 176.937 25.7712 161.438C14.8947 145.667 10.5441 126.09 5.92163 105.696C1.57105 85.0311 -3.05145 63.5501 2.65869 45.0601C8.64075 26.5701 24.6835 11.0711 43.1735 4.54524C61.6635 -1.98064 82.6007 0.194657 102.722 1.01039C122.844 1.82613 142.421 1.55421 150.035 13.2464Z`,aspectRatio:{width:185,height:200},width:e,height:t}),blob21:({width:e,height:t})=>Q({path:`M152.611 0.184799C172.596 -0.723643 197.73 1.39606 199.85 13.8114C201.969 26.2268 181.075 48.9379 174.716 68.0151C168.357 87.0924 176.533 102.536 174.11 114.649C171.991 127.064 159.575 136.148 146.252 139.782C132.928 143.719 118.696 141.902 105.977 139.176C93.562 136.451 82.6606 132.212 63.2805 131.909C43.9004 131.606 16.0416 135.24 5.44306 125.853C-5.15543 116.465 1.50648 94.0572 10.2881 76.4939C18.7669 59.2335 29.6682 46.8182 38.7526 35.3112C48.1398 23.5015 56.3158 12.903 66.9143 8.36078C77.5128 4.12138 91.1394 6.24108 104.766 5.63546C118.696 4.72701 132.928 1.09324 152.611 0.184799Z`,aspectRatio:{width:200,height:143},width:e,height:t}),blob22:({width:e,height:t})=>Q({path:`M195.507 15.5715C206.818 33.1668 193.622 69.3001 190.166 101.663C186.71 134.34 193.308 163.561 181.996 178.014C170.685 192.153 141.464 191.525 114.443 189.326C87.1072 187.44 62.2852 183.67 40.6052 169.531C19.2395 155.077 1.6441 130.255 0.0730908 103.862C-1.18372 77.4694 13.898 49.5054 35.2638 31.91C56.6296 14.0004 84.5936 6.45958 116.328 2.37494C148.063 -1.70969 184.196 -2.3381 195.507 15.5715Z`,aspectRatio:{width:200,height:191},width:e,height:t}),blob23:({width:e,height:t})=>Q({path:`M135.742 9.14189C157.815 19.2326 179.258 38.4681 176.105 56.7576C172.951 74.7317 145.202 92.0751 127.858 109.734C110.83 127.077 104.523 145.052 87.4953 164.918C70.4672 184.468 42.7177 206.227 27.5816 198.343C12.4455 190.46 9.60747 153.566 6.45411 126.762C2.98542 100.274 -0.798607 84.1917 0.147399 67.1636C0.77807 50.4508 6.76944 32.4767 19.0675 20.8093C31.0503 9.14189 49.6551 3.78119 70.4672 1.2585C90.964 -1.26418 113.668 -0.633508 135.742 9.14189Z`,aspectRatio:{width:177,height:200},width:e,height:t}),blob24:({width:e,height:t})=>Q({path:`M165.663 24.3715C171.555 44.4059 158.003 76.2254 151.816 96.2598C145.923 116.294 147.691 124.544 148.28 135.445C148.575 146.346 147.396 159.309 140.62 170.8C133.549 181.996 120.88 191.424 104.381 196.432C87.8821 201.441 67.553 202.03 54.8841 192.602C41.9207 183.469 36.6174 164.023 25.1271 143.105C13.3421 122.187 -4.33535 99.7953 0.967891 85.0641C6.27113 70.6275 34.2604 63.8511 56.0626 48.5307C77.5702 33.5048 92.8907 9.93489 113.22 2.56928C133.843 -4.79633 159.77 4.04241 165.663 24.3715Z`,aspectRatio:{width:168,height:200},width:e,height:t}),blob25:({width:e,height:t})=>Q({path:`M180.115 1.256C192.651 2.1962 189.83 34.163 190.771 58.2947C191.711 82.4265 196.098 98.4099 198.606 117.214C201.113 136.018 201.426 157.642 189.204 165.791C177.294 173.626 153.163 167.671 135.299 163.91C117.749 159.836 106.466 157.956 85.7818 162.97C65.0974 168.298 35.3244 180.521 18.7143 174.253C1.79068 167.985 -1.97012 142.913 0.850478 120.975C3.67107 99.0367 13.0731 79.6059 18.4009 54.8473C23.7287 30.0888 24.9823 -0.310996 40.0254 0.00240332C54.7552 0.00240332 82.9612 31.029 111.167 31.029C139.373 31.029 167.579 0.315802 180.115 1.256Z`,aspectRatio:{width:200,height:176},width:e,height:t}),blob26:({width:e,height:t})=>Q({path:`M142.571 0.586925C159.976 3.39414 176.258 15.1844 184.96 30.9048C193.662 46.6253 194.224 66.8372 189.171 83.6805C183.837 100.805 172.327 114.56 163.064 129.157C153.8 143.755 146.501 158.914 134.43 173.231C122.359 187.828 105.516 201.303 89.5146 199.899C73.2327 198.776 58.0738 182.775 42.9148 169.862C28.0366 157.23 13.7198 147.685 6.42103 134.491C-0.877729 121.297 -1.15845 103.892 1.64876 88.4528C4.45598 72.7324 10.0704 58.6963 18.4921 47.4674C27.1944 36.2386 38.4233 27.8169 50.4943 22.2025C62.846 16.3073 75.7592 13.5001 91.1989 8.72785C106.919 4.23631 125.166 -1.93957 142.571 0.586925Z`,aspectRatio:{width:193,height:200},width:e,height:t}),blob27:({width:e,height:t})=>Q({path:`M112.602 54.9337C129.225 71.8646 155.391 78.9448 158.777 89.719C162.471 100.493 143.693 114.654 127.07 135.586C110.447 156.519 96.2866 184.224 71.0442 194.998C46.1096 205.465 10.4008 199.308 2.0893 178.375C-6.22223 157.443 12.5557 121.734 18.4045 92.1817C24.5612 62.6296 17.7889 38.9263 26.4082 21.9954C34.7197 5.06454 58.423 -5.40183 73.5069 2.9097C88.8986 10.9134 95.9788 38.0028 112.602 54.9337Z`,aspectRatio:{width:160,height:200},width:e,height:t}),blob28:({width:e,height:t})=>Q({path:`M125.281 68.5835C142.15 82.9923 165.344 90.021 181.862 108.998C198.028 127.624 207.516 158.902 192.405 166.634C177.293 174.716 137.581 159.605 112.629 156.442C87.326 152.928 77.1344 161.713 59.9142 165.579C43.0453 169.445 19.1478 168.391 11.7677 157.496C4.73907 146.25 14.2278 124.813 11.4163 94.2382C8.2534 63.6634 -6.85825 23.9514 3.68476 8.48836C14.2278 -7.32615 50.4254 1.10826 73.9715 16.2199C97.5175 31.683 108.412 54.1747 125.281 68.5835Z`,aspectRatio:{width:200,height:169},width:e,height:t}),blob29:({width:e,height:t})=>Q({path:`M162.987 10.2348C169.16 25.1809 154.864 58.6471 147.066 79.4417C139.268 100.236 138.293 108.359 134.719 114.532C131.47 120.706 125.297 124.93 119.448 143.45C113.6 161.97 107.426 194.461 98.004 199.335C88.5814 204.209 75.5849 181.14 55.7651 167.494C35.6203 153.522 8.65241 148.648 1.8292 135.327C-4.994 122.33 8.65241 100.561 20.0244 82.041C31.3964 63.5208 40.1691 48.2498 53.4906 35.5782C66.8122 22.9065 84.0326 13.159 106.452 6.33584C128.871 -0.812285 156.489 -4.71127 162.987 10.2348Z`,aspectRatio:{width:165,height:200},width:e,height:t}),blob3:({width:e,height:t})=>Q({path:`M158.095 64.2637C176.543 95.19 192.277 129.1 181.697 155.686C171.117 182.001 133.951 201.533 99.4982 199.905C64.7739 198.549 33.0338 176.032 15.4004 145.377C-2.23296 114.994 -5.75963 76.2002 10.2461 46.6303C26.2518 17.0605 61.5185 -3.557 89.732 0.512241C118.217 4.58149 139.377 33.0662 158.095 64.2637Z`,aspectRatio:{width:186,height:200},width:e,height:t}),blob30:({width:e,height:t})=>Q({path:`M146.076 34.4585C157.052 54.582 155.833 80.1936 164.675 100.622C173.212 121.355 191.201 136.905 189.372 149.711C187.542 162.212 165.285 171.969 146.99 175.018C129.001 178.372 114.671 174.713 103.39 175.018C92.1083 175.018 83.876 178.982 66.8015 186.299C49.7271 193.617 23.8105 204.288 14.3586 198.19C4.90665 191.787 11.6145 168.615 10.3949 147.882C8.87037 127.148 -0.581561 108.549 0.0282404 89.3407C0.638042 70.1319 11.6145 50.6182 28.384 32.934C44.8487 15.5546 67.4113 0.309578 89.974 0.00467694C112.537 -0.300224 135.099 14.335 146.076 34.4585Z`,aspectRatio:{width:190,height:200},width:e,height:t}),blob31:({width:e,height:t})=>Q({path:`M134.218 44.0392C153.568 36.4264 184.97 26.9105 195.755 33.2544C206.222 39.9156 195.755 62.1194 181.481 76.3933C166.89 90.35 148.175 96.0596 145.638 116.36C143.1 136.661 156.74 171.235 151.664 183.923C146.589 196.928 123.434 187.413 105.036 178.531C86.6388 169.967 73.3165 161.72 52.0643 158.548C30.812 155.058 1.62986 156.644 0.0438693 145.225C-1.22492 133.806 25.4197 109.382 29.2261 86.8609C32.7152 64.3398 13.6834 44.0392 11.7802 26.9105C9.877 9.46461 24.7853 -4.80928 42.5484 1.53467C59.9942 7.87863 79.9777 34.5232 93.6172 45.308C107.257 56.4099 114.869 51.3347 134.218 44.0392Z`,aspectRatio:{width:200,height:191},width:e,height:t}),blob32:({width:e,height:t})=>Q({path:`M200 100.339C200 149.831 145.763 197.966 95.5932 197.966C45.7627 197.966 0 149.831 0 100.339C0 50.8475 45.7627 0 95.5932 0C145.763 0 200 50.8475 200 100.339Z`,aspectRatio:{width:200,height:198},width:e,height:t}),blob4:({width:e,height:t})=>Q({path:`M183.427 38.712C198.21 63.2519 196.141 95.1833 189.341 126.523C182.836 157.863 171.305 188.908 150.609 197.482C130.208 205.76 100.642 192.16 69.8936 177.968C39.4405 164.072 7.80478 150.176 1.30024 128.593C-5.2043 107.01 13.718 77.7393 35.3012 51.7211C56.5888 25.9986 81.1287 3.23272 108.921 0.276112C137.009 -2.38484 168.349 14.4678 183.427 38.712Z`,aspectRatio:{width:195,height:200},width:e,height:t}),blob5:({width:e,height:t})=>Q({path:`M166.251 30.6913C183.816 48.5185 195.875 71.8512 199.021 98.8542C202.429 125.595 197.186 155.744 179.359 169.115C161.794 182.223 131.645 178.815 103.331 176.979C75.0171 175.144 48.8006 174.882 29.6625 161.512C10.7866 148.141 -0.748681 121.925 0.0378149 96.2326C0.824311 70.8025 14.1947 46.159 33.0706 28.3318C52.2087 10.5045 76.8522 -0.5064 100.971 0.0179307C125.091 0.804426 148.423 12.864 166.251 30.6913Z`,aspectRatio:{width:200,height:179},width:e,height:t}),blob6:({width:e,height:t})=>Q({path:`M149.146 50.5452C161.911 68.0278 171.901 81.9028 176.619 97.9979C181.336 114.37 180.781 133.241 173.011 149.891C165.519 166.541 151.366 180.693 133.051 189.851C114.736 199.008 92.2586 202.893 71.446 197.621C50.6334 192.348 30.9308 177.918 18.1658 158.216C5.12323 138.791 -0.981801 113.815 0.128204 87.7304C1.51571 61.6453 10.6733 34.1726 29.2658 17.5226C48.1359 1.14999 76.996 -4.40004 98.9186 3.6475C120.841 11.695 136.381 32.7851 149.146 50.5452Z`,aspectRatio:{width:180,height:200},width:e,height:t}),blob7:({width:e,height:t})=>Q({path:`M158.662 41.8295C178.593 57.8305 204.138 64.5677 213.402 79.7266C222.666 94.6047 215.367 118.466 203.015 135.028C190.383 151.871 172.698 161.977 156.416 168.434C140.134 174.89 124.975 177.697 104.483 185.277C83.9903 192.856 58.1642 205.208 44.9704 197.629C31.4959 190.33 31.2152 163.1 21.9514 138.116C12.9684 112.851 -4.71688 90.1132 1.17822 75.5158C7.35404 61.1991 36.8295 55.5847 58.7256 40.1452C80.9024 24.7056 95.4998 -0.278374 109.816 0.00234533C124.414 0.283064 138.45 25.8285 158.662 41.8295Z`,aspectRatio:{width:218,height:200},width:e,height:t}),blob8:({width:e,height:t})=>Q({path:`M153.53 11.0108C168.179 18.1858 181.931 29.5461 192.993 44.4939C203.755 59.4417 212.425 78.2759 210.631 96.5122C209.136 114.748 197.477 132.088 182.529 142.252C167.581 152.716 148.747 156.004 128.717 168.262C108.687 180.22 87.1622 201.147 69.8228 199.951C52.7823 198.456 39.6283 174.54 32.4533 153.015C25.2784 131.49 24.0826 112.357 16.6087 91.131C9.13477 70.2041 -4.31825 46.8855 1.36191 31.9377C7.04207 16.691 31.8554 9.51607 52.7823 5.33069C73.4103 0.846349 90.4507 -0.648433 106.594 0.248435C123.037 1.1453 138.882 4.13486 153.53 11.0108Z`,aspectRatio:{width:211,height:200},width:e,height:t}),blob9:({width:e,height:t})=>Q({path:`M140.289 20.2182C156.96 27.7956 176.661 32.0895 189.29 43.9608C201.667 55.5796 206.718 75.0283 202.424 91.6987C198.131 108.622 184.491 122.766 175.651 140.952C166.81 158.885 162.769 180.607 150.393 191.216C138.016 201.824 117.052 201.572 98.866 197.025C80.6802 192.479 65.2727 183.891 48.3497 175.808C31.4268 167.726 13.2409 160.148 5.1583 146.761C-2.67172 133.122 -0.398493 113.673 4.14797 96.7504C8.69444 80.08 15.5141 65.6828 23.3442 52.296C31.4268 38.6566 40.5197 25.775 52.6436 15.6717C65.0201 5.82101 80.6802 -1.50385 95.3299 0.264221C109.98 1.77971 123.619 12.6407 140.289 20.2182Z`,aspectRatio:{width:204,height:200},width:e,height:t})};function ED(e){return TD[e]||hD}function DD(e){let{subType:t}=e,n=e,r=ED(t);return r?function(e,t){let{width:n,height:r,fill:i,stroke:a,strokeWidth:o,dash:s}=e,c=(s||[]).map(e=>e*o),l=t(e),u=1,d=1;typeof l!=`string`&&(u=l.scaleX,d=l.scaleY,l=l.path);let f=`clip-${e.id||Math.random()}`;return`\n <svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${r}">\n <defs>\n <clipPath id="${f}">\n <path d="${l}" />\n </clipPath>\n </defs>\n\n \x3c!-- Path for the fill --\x3e\n <path d="${l}" fill="${i}" transform="scale(${u}, ${d})"/>\n\n \x3c!-- Path for the stroke, clipped by the star path --\x3e\n <path d="${l}" fill="none" stroke="${a}" stroke-width="${2*o}" clip-path="url(#${f})" transform="scale(${u}, ${d})" stroke-dasharray="${c.join(` `)}"/>\n </svg>\n `}(n,r):(console.error(`Polotno error: Can not convert ${e.subType} figure to svg.`),hD(n))}var OD={},kD=sa(({element:e,store:t})=>{let n=d.useRef(null),r=e.selectable||t.role===`admin`,i=Bp(),a=t.selectedShapes.indexOf(e)>=0&&e.selectable,o=Math.min(e.strokeWidth,e.width/2,e.height/2),s=Math.max(0,Math.min(e.width/2,e.height/2,e.cornerRadius)),c=Pf(e,e.a.fill,`fill`),l=Object.assign(Object.assign({width:e.a.width,height:e.a.height},c),{cornerRadius:s,opacity:e.animated(`opacity`),shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,preventDefault:!i||a,hideInExport:!e.showInExport}),u=Pf(e,e.stroke,`stroke`),f=Object.assign(Object.assign({visible:o>0,x:o/2,y:o/2,width:e.a.width-o,height:e.a.height-o},u),{strokeWidth:o,cornerRadius:Math.max(0,s-o),dash:e.dash.map(e=>e*o),opacity:e.animated(`opacity`),hideInExport:!e.showInExport,listening:!1}),p=(m=e.subType,OD[m]||(OD[m]=(h=ED(m),sa(({element:e,fillProps:t,strokeProps:n})=>{let r=h({width:e.a.width,height:e.a.height,cornerRadius:e.cornerRadius}),i=1,a=1;typeof r!=`string`&&(i=r.scaleX,a=r.scaleY,r=r.path);let o=d.useRef(null);return d.createElement(d.Fragment,null,d.createElement(`Rect`,{width:e.width,height:e.height,fill:`transparent`}),d.createElement(`Path`,Object.assign({},t,{ref:o,data:r,scaleX:i,scaleY:a})),d.createElement(`Group`,{clipFunc:e=>{let t=o.current;if(t){var n=t.dataArray;e.beginPath();for(var r=0;r<n.length;r++){var i=n[r].command,a=n[r].points;switch(i){case`L`:e.lineTo(a[0],a[1]);break;case`M`:e.moveTo(a[0],a[1]);break;case`C`:e.bezierCurveTo(a[0],a[1],a[2],a[3],a[4],a[5]);break;case`Q`:e.quadraticCurveTo(a[0],a[1],a[2],a[3]);break;case`A`:var s=a[0],c=a[1],l=a[2],u=a[3],d=a[4],f=a[5],p=a[6],m=a[7],h=l>u?l:u,g=l>u?1:l/u,_=l>u?u/l:1;e.translate(s,c),e.rotate(p),e.scale(g,_),e.arc(0,0,h,d,d+f,!m),e.scale(1/g,1/_),e.rotate(-p),e.translate(-s,-c);break;case`z`:e.closePath()}}}},scaleX:i,scaleY:a},d.createElement(`Path`,Object.assign({},n,{x:0,y:0,data:r,strokeWidth:2*n.strokeWidth,dash:n.dash.map(e=>e)}))))}))),OD[m]||`Group`);var m,h;return d.createElement(d.Fragment,null,d.createElement(Kd,{ref:n,id:e.id,x:e.a.x,y:e.a.y,rotation:e.a.rotation,opacity:e.a.opacity,listening:r,draggable:i?e.draggable&&a:e.draggable,name:`element`,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onTransform:t=>{let n=t.target.scale();t.target.scaleX(1),t.target.scaleY(1),e.set({width:e.width*n.x,height:e.height*n.y,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})}},d.createElement(p,{element:e,fillProps:l,strokeProps:f})))}),AD=r((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.loop=e.conditional=e.parse=void 0,e.parse=function e(t,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:r;if(Array.isArray(n))n.forEach(function(n){return e(t,n,r,i)});else if(typeof n==`function`)n(t,r,i,e);else{var a=Object.keys(n)[0];Array.isArray(n[a])?(i[a]={},e(t,n[a],r,i[a])):i[a]=n[a](t,r,i,e)}return r},e.conditional=function(e,t){return function(n,r,i,a){t(n,r,i)&&a(n,e,r,i)}},e.loop=function(e,t){return function(n,r,i,a){for(var o=[],s=n.pos;t(n,r,i);){var c={};if(a(n,e,r,c),n.pos===s)break;s=n.pos,o.push(c)}return o}}})),jD=r((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.readBits=e.readArray=e.readUnsigned=e.readString=e.peekBytes=e.readBytes=e.peekByte=e.readByte=e.buildStream=void 0,e.buildStream=function(e){return{data:e,pos:0}};var t=function(){return function(e){return e.data[e.pos++]}};e.readByte=t,e.peekByte=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return function(t){return t.data[t.pos+e]}};var n=function(e){return function(t){return t.data.subarray(t.pos,t.pos+=e)}};e.readBytes=n,e.peekBytes=function(e){return function(t){return t.data.subarray(t.pos,t.pos+e)}},e.readString=function(e){return function(t){return Array.from(n(e)(t)).map(function(e){return String.fromCharCode(e)}).join(``)}},e.readUnsigned=function(e){return function(t){var r=n(2)(t);return e?(r[1]<<8)+r[0]:(r[0]<<8)+r[1]}},e.readArray=function(e,t){return function(r,i,a){for(var o=typeof t==`function`?t(r,i,a):t,s=n(e),c=Array(o),l=0;l<o;l++)c[l]=s(r);return c}};var r=function(e,t,n){for(var r=0,i=0;i<n;i++)r+=e[t+i]&&2**(n-i-1);return r};e.readBits=function(e){return function(n){for(var i=t()(n),a=Array(8),o=0;o<8;o++)a[7-o]=!!(i&1<<o);return Object.keys(e).reduce(function(t,n){var i=e[n];return i.length?t[n]=r(a,i.index,i.length):t[n]=a[i.index],t},{})}}})),MD=r((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.default=void 0;var t=AD(),n=jD(),r={blocks:function(e){for(var t=0,r=[],i=e.data.length,a=0,o=(0,n.readByte)()(e);o!==t&&o;o=(0,n.readByte)()(e)){if(e.pos+o>=i){var s=i-e.pos;r.push((0,n.readBytes)(s)(e)),a+=s;break}r.push((0,n.readBytes)(o)(e)),a+=o}for(var c=new Uint8Array(a),l=0,u=0;u<r.length;u++)c.set(r[u],l),l+=r[u].length;return c}},i=(0,t.conditional)({gce:[{codes:(0,n.readBytes)(2)},{byteSize:(0,n.readByte)()},{extras:(0,n.readBits)({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:(0,n.readUnsigned)(!0)},{transparentColorIndex:(0,n.readByte)()},{terminator:(0,n.readByte)()}]},function(e){var t=(0,n.peekBytes)(2)(e);return t[0]===33&&t[1]===249}),a=(0,t.conditional)({image:[{code:(0,n.readByte)()},{descriptor:[{left:(0,n.readUnsigned)(!0)},{top:(0,n.readUnsigned)(!0)},{width:(0,n.readUnsigned)(!0)},{height:(0,n.readUnsigned)(!0)},{lct:(0,n.readBits)({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},(0,t.conditional)({lct:(0,n.readArray)(3,function(e,t,n){return 2**(n.descriptor.lct.size+1)})},function(e,t,n){return n.descriptor.lct.exists}),{data:[{minCodeSize:(0,n.readByte)()},r]}]},function(e){return(0,n.peekByte)()(e)===44}),o=(0,t.conditional)({text:[{codes:(0,n.readBytes)(2)},{blockSize:(0,n.readByte)()},{preData:function(e,t,r){return(0,n.readBytes)(r.text.blockSize)(e)}},r]},function(e){var t=(0,n.peekBytes)(2)(e);return t[0]===33&&t[1]===1}),s=(0,t.conditional)({application:[{codes:(0,n.readBytes)(2)},{blockSize:(0,n.readByte)()},{id:function(e,t,r){return(0,n.readString)(r.blockSize)(e)}},r]},function(e){var t=(0,n.peekBytes)(2)(e);return t[0]===33&&t[1]===255}),c=(0,t.conditional)({comment:[{codes:(0,n.readBytes)(2)},r]},function(e){var t=(0,n.peekBytes)(2)(e);return t[0]===33&&t[1]===254});e.default=[{header:[{signature:(0,n.readString)(3)},{version:(0,n.readString)(3)}]},{lsd:[{width:(0,n.readUnsigned)(!0)},{height:(0,n.readUnsigned)(!0)},{gct:(0,n.readBits)({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:(0,n.readByte)()},{pixelAspectRatio:(0,n.readByte)()}]},(0,t.conditional)({gct:(0,n.readArray)(3,function(e,t){return 2**(t.lsd.gct.size+1)})},function(e,t){return t.lsd.gct.exists}),{frames:(0,t.loop)([i,s,c,a,o],function(e){var t=(0,n.peekByte)()(e);return t===33||t===44})}]})),ND=r((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.deinterlace=void 0,e.deinterlace=function(e,t){for(var n=Array(e.length),r=e.length/t,i=function(r,i){var a=e.slice(i*t,(i+1)*t);n.splice.apply(n,[r*t,t].concat(a))},a=[0,4,2,1],o=[8,8,4,2],s=0,c=0;c<4;c++)for(var l=a[c];l<r;l+=o[c])i(l,s),s++;return n}})),PD=r((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.lzw=void 0,e.lzw=function(e,t,n){var r=4096,i=-1,a=n,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S=Array(n),C=Array(r),w=Array(r),T=Array(r+1);for(_=e,s=1<<_,u=s+1,o=s+2,f=i,l=_+1,c=(1<<l)-1,m=0;m<s;m++)C[m]=0,w[m]=m;var g=p=v=y=x=b=0,p,v,y,x,b;for(h=0;h<a;){if(y===0){if(p<l){g+=t[b]<<p,p+=8,b++;continue}if(m=g&c,g>>=l,p-=l,m>o||m==u)break;if(m==s){l=_+1,c=(1<<l)-1,o=s+2,f=i;continue}if(f==i){T[y++]=w[m],f=m,v=m;continue}for(d=m,m==o&&(T[y++]=v,m=f);m>s;)T[y++]=w[m],m=C[m];v=w[m]&255,T[y++]=v,o<r&&(C[o]=f,w[o]=v,o++,(o&c)===0&&o<r&&(l++,c+=o)),f=d}y--,S[x++]=T[y],h++}for(h=x;h<a;h++)S[h]=0;return S}})),FD=r((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.decompressFrames=e.decompressFrame=e.parseGIF=void 0;var t=o(MD()),n=AD(),r=jD(),i=ND(),a=PD();function o(e){return e&&e.__esModule?e:{default:e}}e.parseGIF=function(e){var i=new Uint8Array(e);return(0,n.parse)((0,r.buildStream)(i),t.default)};var s=function(e){for(var t=e.pixels.length,n=new Uint8ClampedArray(t*4),r=0;r<t;r++){var i=r*4,a=e.pixels[r],o=e.colorTable[a]||[0,0,0];n[i]=o[0],n[i+1]=o[1],n[i+2]=o[2],n[i+3]=a===e.transparentIndex?0:255}return n},c=function(e,t,n){if(!e.image){console.warn(`gif frame does not have associated image.`);return}var r=e.image,o=r.descriptor.width*r.descriptor.height,c=(0,a.lzw)(r.data.minCodeSize,r.data.blocks,o);r.descriptor.lct.interlaced&&(c=(0,i.deinterlace)(c,r.descriptor.width));var l={pixels:c,dims:{top:e.image.descriptor.top,left:e.image.descriptor.left,width:e.image.descriptor.width,height:e.image.descriptor.height}};return r.descriptor.lct&&r.descriptor.lct.exists?l.colorTable=r.lct:l.colorTable=t,e.gce&&(l.delay=(e.gce.delay||10)*10,l.disposalType=e.gce.extras.disposal,e.gce.extras.transparentColorGiven&&(l.transparentIndex=e.gce.transparentColorIndex)),n&&(l.patch=s(l)),l};e.decompressFrame=c,e.decompressFrames=function(e,t){return e.frames.filter(function(e){return e.image}).map(function(n){return c(n,e.gct,t)})}}))();function ID(e,t,n){let r=t.getContext(`2d`),i=n.getContext(`2d`);if(!r||!i)return;e.disposalType===2&&r.clearRect(0,0,t.width,t.height),n.width=e.width,n.height=e.height;let a=i.createImageData(e.width,e.height);a.data.set(e.patch),i.putImageData(a,0,0),r.drawImage(n,e.left,e.top)}var LD=sa(({element:e})=>{let t=Math.min(30,e.width/4,e.height/4),n=d.useRef(null);return d.useEffect(()=>{let e=n.current;if(!e)return;let t=new Du.Animation(t=>{e.rotate((t?.timeDiff||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}},[]),d.createElement(Kd,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},d.createElement(Jd,{width:e.width,height:e.height,fill:`rgba(124, 173, 212, 0.8)`}),d.createElement(`Arc`,{ref:n,x:e.width/2,y:e.height/2,fill:`white`,outerRadius:Math.abs(t),innerRadius:Math.max(1,t-5),angle:270}))}),RD=sa(({element:e})=>{let t=Math.max(10,Math.min(30,e.width/22));return d.createElement(Kd,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},d.createElement(Jd,{width:e.width,height:e.height,fill:`rgba(223, 102, 102, 0.8)`}),d.createElement(Zd,{text:`Cannot load the GIF...`,fontSize:t,width:e.width,height:e.height,align:`center`,fill:`white`,verticalAlign:`middle`,padding:5}))}),zD=sa(({element:e,store:t})=>{let[n,r]=d.useState(!1),i=t.selectedShapes.indexOf(e)>=0&&e.selectable,a=d.useRef(null),o=d.useRef(),[s,c,l,u]=function(e){let[t,n]=d.useState([]),[r,i]=d.useState(0),[a,o]=d.useState(`loading`),[s,c]=d.useState({width:0,height:0});return d.useEffect(()=>{(async()=>{try{let t=(0,FD.parseGIF)(await(await fetch(e)).arrayBuffer()),r=(0,FD.decompressFrames)(t,!0),a=t.lsd.width,s=t.lsd.height;c({width:a,height:s});let l=r.map(e=>({patch:new Uint8ClampedArray(e.patch),delay:e.delay,width:e.dims.width,height:e.dims.height,left:e.dims.left,top:e.dims.top,disposalType:e.disposalType})),u=l.reduce((e,t)=>e+t.delay,0);n(l),i(u),o(`loaded`)}catch(e){console.error(`Failed to load GIF:`,e),o(`failed`)}})()},[e]),[t,r,s,a]}(e.src);dv(u,e.src,e.id),d.useEffect(()=>(o.current=document.createElement(`canvas`),()=>{o.current&&Du.Util.releaseCanvas(o.current)}),[]),d.useEffect(()=>{if(u===`loaded`&&o.current&&(o.current.width=l.width,o.current.height=l.height,s.length>0)){let e=o.current.getContext(`2d`);if(e){e.clearRect(0,0,l.width,l.height);let t=document.createElement(`canvas`);ID(s[0],o.current,t)}}},[l,u,s]),d.useEffect(()=>{if(!s.length||!o.current)return;let n=o.current;n.width=l.width,n.height=l.height;let r=document.createElement(`canvas`),i=n.getContext(`2d`);i&&i.clearRect(0,0,n.width,n.height);let u=-1;ID(s[0],n,r),y(),u=0;let d=e=>{let t=(e=>{let t=e%c,n=0;for(let e=0;e<s.length;e++)if(n+=s[e].delay,n>t)return e;return 0})(e);t!==u&&(ID(s[t],n,r),y(),a.current.getLayer().draw(),u=t)};if(t.isPlaying||e.page._exportingOrRendering)return Gn(()=>{d(t.currentTime-e.page.startTime)});{let e=window.setInterval(()=>{d(t.currentTime||performance.now())},16);return()=>{clearInterval(e)}}},[t.isPlaying,s,c,e.page._exportingOrRendering]),d.useEffect(()=>{c&&t.history.ignore(()=>{e.set({duration:c})})},[c]);let{cropX:f,cropY:p,cropWidth:m,cropHeight:h}=e;u!==`loaded`&&(f=p=0,m=h=1);let g={x:l.width*f,y:l.height*p,width:l.width*m,height:l.height*h},_=e.cornerRadius??0,[v,y]=sD(e,o.current,g,t._elementsPixelRatio,_,n||e._cropModeEnabled);d.useLayoutEffect(()=>{if(!n&&!e._cropModeEnabled&&a.current)return zp(a.current,e),Gn(()=>{zp(a.current,e)},{delay:100})},[o.current,n,m,h,e._cropModeEnabled,l.width,l.height]);let b=u===`loading`,x=u===`failed`,S=b||x?0:e.a.opacity;Rf(a,S);let C=e.selectable||t.role===`admin`,w=Bp();return d.createElement(d.Fragment,null,b&&d.createElement(LD,{element:e}),x&&d.createElement(RD,{element:e}),d.createElement(Xd,{ref:a,name:`element`,id:e.id,image:v,x:e.a.x,y:e.a.y,width:e.a.width||1,height:e.a.height||1,rotation:e.a.rotation,opacity:S,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,customCrop:g,listening:C,draggable:w?e.draggable&&i:e.draggable,preventDefault:!w||i,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onTransformStart:()=>r(!0),onTransform:t=>{let n=t.currentTarget,r=Math.abs(n.scaleX()-1)<1e-7?1:n.scaleX(),i=Math.abs(n.scaleY()-1)<1e-7?1:n.scaleY();n.scaleX(1),n.scaleY(1),e.set({x:n.x(),y:n.y(),width:n.width()*r,height:n.height()*i,rotation:n.rotation()})},onTransformEnd:()=>r(!1)}),d.createElement(Jd,{x:e.a.x,y:e.a.y,width:Math.max(e.a.width-e.borderSize,0),height:Math.max(e.a.height-e.borderSize,0),opacity:S,offsetX:-e.borderSize/2,offsetY:-e.borderSize/2,stroke:e.borderColor,strokeWidth:e.borderSize,listening:!1,visible:!!e.borderSize,rotation:e.rotation,cornerRadius:Math.max(0,_-e.borderSize),hideInExport:!e.showInExport}))}),BD=sa(({element:e,store:t})=>{let n=d.useRef(null),r=d.useRef(null),i=e.selectable||t.role===`admin`,a=Bp(),o=t.selectedShapes.indexOf(e)>=0&&e.selectable,s=e._focusedCellIds.length>0,c=e.editingCell;d.useEffect(()=>{o||e.clearCellFocus()},[o]);let l=c?._editModeEnabled;d.useEffect(()=>{e._editingCellId&&c&&!c._editModeEnabled&&e.exitCellEdit()},[l]),d.useEffect(()=>{s&&!e._editingCellId&&setTimeout(()=>r.current?.focus(),0)},[s,e._editingCellId]),d.useEffect(()=>Gn(()=>{e._fitRowsToContent&&t.history.ignore(()=>{e._applyFitRowsToContent()})}),[e,t]);let u=t=>{let r=t.target.getStage();if(!r)return;let i=r.getPointerPosition();if(!i)return;let a=n.current;if(!a)return;let o=a.getAbsoluteTransform().copy().invert().point(i);for(let t of e.visibleCells){let n=e.getCellRect(t.row,t.col,t.rowSpan,t.colSpan);if(o.x>=n.x&&o.x<=n.x+n.width&&o.y>=n.y&&o.y<=n.y+n.height)return t}},f=(e,t)=>e===`dashed`?[4*t,2*t]:e===`dotted`?[t,t]:void 0,p=[];for(let t of e.visibleCells){let n=e.getCellRect(t.row,t.col,t.rowSpan,t.colSpan);if(t.row===0){let e=t.getEffectiveBorder(`top`);e.style!==`none`&&e.width>0&&p.push(d.createElement(`Line`,{key:`bt-${t.id}`,points:[n.x,n.y+e.width/2,n.x+n.width,n.y+e.width/2],stroke:e.color,strokeWidth:e.width,dash:f(e.style,e.width),listening:!1}))}if(t.col===0){let e=t.getEffectiveBorder(`left`);e.style!==`none`&&e.width>0&&p.push(d.createElement(`Line`,{key:`bl-${t.id}`,points:[n.x+e.width/2,n.y,n.x+e.width/2,n.y+n.height],stroke:e.color,strokeWidth:e.width,dash:f(e.style,e.width),listening:!1}))}{let e=t.getEffectiveBorder(`bottom`);e.style!==`none`&&e.width>0&&p.push(d.createElement(`Line`,{key:`bb-${t.id}`,points:[n.x,n.y+n.height-e.width/2,n.x+n.width,n.y+n.height-e.width/2],stroke:e.color,strokeWidth:e.width,dash:f(e.style,e.width),listening:!1}))}{let e=t.getEffectiveBorder(`right`);e.style!==`none`&&e.width>0&&p.push(d.createElement(`Line`,{key:`br-${t.id}`,points:[n.x+n.width-e.width/2,n.y,n.x+n.width-e.width/2,n.y+n.height],stroke:e.color,strokeWidth:e.width,dash:f(e.style,e.width),listening:!1}))}}return d.createElement(d.Fragment,null,d.createElement(Jd,{id:e.id,name:`element`,x:e.a.x,y:e.a.y,rotation:e.a.rotation,width:e.a.width,height:e.a.height,fill:`transparent`,opacity:e.a.opacity,hideInExport:!e.showInExport,listening:i,draggable:a?e.draggable&&o:e.draggable,onClick:t=>{if(!o||e.locked||!e.contentEditable)return;let n=u(t);n&&(t.evt.shiftKey&&s?(t.cancelBubble=!0,e.focusCellRange(n.row,n.col)):e.focusCell(n.id))},onDblClick:t=>{if(!o||e.locked||!e.contentEditable)return;let n=u(t);n&&e.enterCellEdit(n.id)},onDragMove:t=>{var r;let i=t.target;e.set({x:i.x(),y:i.y()}),(r=n.current)==null||r.position({x:i.x(),y:i.y()})},onDragEnd:t=>{let n=t.target;e.set({x:n.x(),y:n.y()})},onTransformStart:()=>{e._setIsTransforming(!0)},onTransformEnd:()=>{e._setIsTransforming(!1),e._resetBaseRowHeights()},onTransform:t=>{var r,i;let a=t.target,o=a.scaleX(),s=a.scaleY();a.scaleX(1),a.scaleY(1);let c=e.width*o,l=e.height*s;a.width(c),a.height(l);let u=a.x(),d=a.y(),f=a.rotation();(r=n.current)==null||r.position({x:u,y:d}),(i=n.current)==null||i.rotation(f),e.set({width:c,height:l,x:u,y:d,rotation:f})}}),d.createElement(Kd,{ref:n,x:e.a.x,y:e.a.y,rotation:e.a.rotation,opacity:e.a.opacity,hideInExport:!e.showInExport,scaleX:e.a.width/e.width,scaleY:e.a.height/e.height},e.visibleCells.map(t=>{let n=e.getCellRect(t.row,t.col,t.rowSpan,t.colSpan);return t.cellBackground===`transparent`?null:d.createElement(Jd,{key:`bg-${t.id}`,x:n.x,y:n.y,width:n.width,height:n.height,fill:t.cellBackground,listening:!1})}),p,e.visibleCells.map(e=>d.createElement(M_,{key:`text-${e.id}`,element:e,store:t})),e._focusedCellIds.map(t=>{let n=e.cells.find(e=>e.id===t);if(!n)return null;let r=e.getCellRect(n.row,n.col,n.rowSpan,n.colSpan);return d.createElement(Jd,{key:`focus-${t}`,x:r.x,y:r.y,width:r.width,height:r.height,fill:`rgba(13, 131, 221, 0.1)`,stroke:`#0d83dd`,strokeWidth:2,listening:!1})}),s&&!c&&d.createElement(cf,null,d.createElement(`input`,{ref:r,style:{position:`absolute`,opacity:0,width:`1px`,height:`1px`,pointerEvents:`none`},readOnly:!0})),o&&!c&&!t.isPlaying&&(()=>{let n=[],r=0;for(let i=0;i<e.cols-1;i++){r+=e.colWidths[i]*e.a.width;let a=r,o=i;n.push(d.createElement(`Line`,{key:`col-resize-${i}`,x:a,points:[0,0,0,e.a.height],stroke:`transparent`,strokeWidth:1,hitStrokeWidth:16,draggable:!0,onMouseEnter:e=>{let t=e.target.getStage()?.container();t&&(t.style.cursor=`col-resize`)},onMouseLeave:e=>{let t=e.target.getStage()?.container();t&&(t.style.cursor=``)},onDragStart:e=>{e.cancelBubble=!0,t.history.startTransaction()},onDragMove:t=>{t.cancelBubble=!0;let n=t.target,r=(n.x()-a)/e.width;n.x(a),e.resizeColumn(o,r)},onDragEnd:e=>{e.cancelBubble=!0,e.target.x(a),t.history.endTransaction()}}))}return n})(),o&&!c&&!t.isPlaying&&(()=>{let n=[],r=0;for(let i=0;i<e.rows-1;i++){r+=e.rowHeights[i]*e.a.height;let a=r,o=i;n.push(d.createElement(`Line`,{key:`row-resize-${i}`,y:a,points:[0,0,e.a.width,0],stroke:`transparent`,strokeWidth:1,hitStrokeWidth:16,draggable:!0,onMouseEnter:e=>{let t=e.target.getStage()?.container();t&&(t.style.cursor=`row-resize`)},onMouseLeave:e=>{let t=e.target.getStage()?.container();t&&(t.style.cursor=``)},onDragStart:n=>{n.cancelBubble=!0,e._setIsResizingRows(!0),t.history.startTransaction()},onDragMove:t=>{t.cancelBubble=!0;let n=t.target,r=(n.y()-a)/e.height;n.y(a),e.resizeRow(o,r)},onDragEnd:n=>{n.cancelBubble=!0,n.target.y(a),e._setIsResizingRows(!1),e._resetBaseRowHeights(),t.history.endTransaction()}}))}return n})()))}),VD={stroke:`rgb(0, 161, 255)`,strokeWidth:2},HD=sa(({element:e})=>d.createElement(Jd,Object.assign({name:`highlighter`,x:e.a.x,y:e.a.y,rotation:e.a.rotation,width:e.a.width,height:e.a.height,listening:!1,strokeScaleEnabled:!1},VD))),UD=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+=`-`:e+=`_`,e),``),WD=function(e,t){if(e===t)return!0;if(typeof e==`object`&&e&&typeof t==`object`&&t){if(Object.keys(e).length!=Object.keys(t).length)return!1;for(var n in e)if(!t.hasOwnProperty(n)||!WD(e[n],t[n]))return!1;return!0}return!1};Object.assign(q);var GD=q.model(`UndoManager`,{history:q.array(q.frozen()),undoIdx:-1,targetPath:``}).views(e=>({get canUndo(){return e.undoIdx>0},get canRedo(){return e.undoIdx<e.history.length-1}})).actions(e=>{let t,n,r=!1,i=null,a=0,o=0,s=()=>o>0;function c(){let e=nm(t);return{pages:e.pages,width:e.width,height:e.height,custom:e.custom,audios:e.audios}}function l(e){let n=!WD(t.pages.map(e=>e.id),e.pages.map(e=>e.id)),r=!WD(t.custom,e.custom);n?tm(t.pages,e.pages):t.pages.forEach((t,n)=>{tm(t,e.pages[n])}),r&&t.set({custom:e.custom}),t.setSize(e.width,e.height)}let u={startTransaction(){o++},endTransaction(e){o--,e||u.requestAddState(c())},async ignore(e,t=!1,n=!1){n&&await new Promise(e=>setTimeout(e,10));let r=!!a;a&&u.addUndoState();let i=s();u.startTransaction();let c=o;try{await e()}catch(e){setTimeout(()=>{throw e})}let l=c!==o,d=!l;u.endTransaction(d),t||i&&!r||u.replaceState(),l||(clearTimeout(a),a=0)},async transaction(e){await u.ignore(e,!0),u.addUndoState()},requestAddState(e){i=e,a||s()||(r?r=!1:a=setTimeout(()=>{a=0,clearTimeout(a),s()||u.addUndoState()},100))},addUndoState(){if(r){r=!1;return}let t=e.history[e.undoIdx];!WD(i,t)&&(clearTimeout(a),a=0,e.history.splice(e.undoIdx+1),e.history.push(i),e.undoIdx=e.history.length-1)},afterCreate(){if(t=cm(e,`..`),!t)throw Error("Failed to find target store for UndoManager. Please provide `targetPath` property, or a `targetStore` in the environment");n=$p(t,()=>{u.requestAddState(c())}),e.history.length===0&&u.requestAddState(c())},clear(){clearTimeout(a),a=0,e.history.splice(0,e.history.length),e.undoIdx=-1,u.addUndoState()},beforeDestroy(){n()},undo(){a&&u.addUndoState(),s()?l(e.history[e.undoIdx]):e.canUndo?(e.undoIdx--,r=!0,l(e.history[e.undoIdx])):console.warn("No undo history. Please check `store.history.canUndo` before calling undo action.")},redo(){a&&u.addUndoState(),e.canRedo?(e.undoIdx++,r=!0,l(e.history[e.undoIdx])):console.warn("No redo history. Please check `store.history.canRedo` before calling redo action.")},replaceState(){e.history[e.undoIdx]=c()}};return u});async function KD(e,t){let n=await(await fetch(e)).blob(),r=document.createElement(`a`),i=URL.createObjectURL(n);r.href=i,r.download=t,document.body.appendChild(r),r.click(),setTimeout(function(){document.body.removeChild(r),window.URL.revokeObjectURL(i)},0)}var qD=null;function JD(){return window.jspdf?.jsPDF?Promise.resolve(window.jspdf.jsPDF):qD||(typeof window.__polotnoLoadJspdf==`function`?(qD=window.__polotnoLoadJspdf().then(e=>e?.jsPDF||e),qD):(qD=new Promise(e=>{var t=document.createElement(`script`);t.onload=function(){e(window.jspdf.jsPDF)},t.src=`https://cdnjs.cloudflare.com/ajax/libs/jspdf/3.0.1/jspdf.umd.min.js`,document.head.appendChild(t)}),qD))}function YD(){return window.GIF?Promise.resolve(window.GIF):new Promise(e=>{var t=document.createElement(`script`);t.onload=function(){e(window.GIF)},t.src=`https://cdnjs.cloudflare.com/ajax/libs/gif.js/0.2.0/gif.js`,document.head.appendChild(t)})}async function XD({width:e,height:t}){return new(await(YD()))({workers:4,width:e,height:t,workerScript:URL.createObjectURL(new Blob([`// gif.worker.js 0.2.0 - https://github.com/jnordberg/gif.js
283
+ `);var uD=(e,t,n,r,i=0,a=!1)=>{let o=Math.floor(Math.max(e.width*r,1)),s=Math.floor(Math.max(e.height*r,1)),c=Math.min(i*r,o/2,s/2),l=Math.max(e.width/n.width,e.height/n.height)*r,u=e.page._exportingOrRendering&&Sp.imageDownScalingEnabled&&l<1&&!a,f=t instanceof HTMLVideoElement?t.videoWidth:t?.width,p=t instanceof HTMLVideoElement?t.videoHeight:t?.height,m=n.x===0&&n.y===0&&n.width===f&&n.height===p,h=d.useMemo(()=>{if(t&&f&&p)return m&&c===0&&!u?void 0:sD()},[t,c,u,m,f,p]),g=()=>{if(!h||!t)return;h.width=o,h.height=s;let e=h.getContext(`2d`);if(!e)return;c&&(e.beginPath(),e.moveTo(c,0),e.lineTo(o-c,0),e.arc(o-c,c,c,3*Math.PI/2,0,!1),e.lineTo(o,s-c),e.arc(o-c,s-c,c,0,Math.PI/2,!1),e.lineTo(c,s),e.arc(c,s-c,c,Math.PI/2,Math.PI,!1),e.lineTo(0,c),e.arc(c,c,c,Math.PI,3*Math.PI/2,!1),e.clip());let r=u?function(e,t){var n,r;let i=sD(),a=e instanceof HTMLVideoElement?e.videoWidth:e.width,o=e instanceof HTMLVideoElement?e.videoHeight:e.height;i.width=a,i.height=o,(n=i.getContext(`2d`))==null||n.drawImage(e,0,0,i.width,i.height);let s=function(e,t,n,r,i,a,o){for(var s=new ImageData(t,n),c=new Int32Array(e.data.buffer),l=e.width,u=new Int32Array(s.data.buffer),d=s.width,f=t/a,p=n/o,m=Math.round(1/f),h=Math.round(1/p),g=m*h,_=0;_<s.height;_++)for(var v=0;v<d;v++){for(var y=0+Math.round(v/f)+(0+Math.round(_/p))*l,b=0,x=0,S=0,C=0,w=0;w<h;w++)for(var T=0;T<m;T++){var E=c[y+T+w*l];b+=E<<24>>>24,x+=E<<16>>>24,S+=E<<8>>>24,C+=E>>>24}b=Math.round(b/g),x=Math.round(x/g),S=Math.round(S/g),C=Math.round(C/g),u[v+_*d]=C<<24|S<<16|x<<8|b}return s}(i.getContext(`2d`).getImageData(0,0,i.width,i.height),Math.floor(i.width*t),Math.floor(i.height*t),0,0,i.width,i.height);return i.width=Math.floor(i.width*t),i.height=Math.floor(i.height*t),(r=i.getContext(`2d`))==null||r.putImageData(s,0,0),i}(t,l):t,i=u?{x:Math.floor(n.x*l),y:Math.floor(n.y*l),width:Math.floor(n.width*l),height:Math.floor(n.height*l)}:n;e.drawImage(r,i.x,i.y,i.width,i.height,0,0,h.width,h.height)};return d.useLayoutEffect(()=>{g()},[h,e.width,e.height,n.x,n.y,n.width,n.height,i,r,a,e.page._exportingOrRendering,u]),d.useEffect(()=>()=>{h&&h.nodeName===`CANVAS`&&Du.Util.releaseCanvas(h)},[h]),[h||t,g]},dD=sD(),fD=sa(({element:e})=>{let t=Math.min(30,e.width/4,e.height/4),n=d.useRef(null);return d.useEffect(()=>{let e=n.current;if(!e)return;let t=new Du.Animation(t=>{e.rotate((t?.timeDiff||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}}),d.createElement(Kd,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},d.createElement(Jd,{width:e.width,height:e.height,fill:`rgba(124, 173, 212, 0.8)`}),d.createElement(`Arc`,{ref:n,x:e.width/2,y:e.height/2,fill:`white`,outerRadius:Math.abs(t),innerRadius:Math.max(1,t-5),angle:270}))}),pD=sa(({element:e})=>{let t=Math.max(10,Math.min(30,e.width/25));return d.createElement(Kd,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},d.createElement(Jd,{width:e.width,height:e.height,fill:`rgba(223, 102, 102, 0.8)`}),d.createElement(Zd,{text:`Can not load the video...`,fontSize:t,width:e.width,height:e.height,align:`center`,fill:`white`,verticalAlign:`middle`,padding:5}))}),mD=function(e,t,n){let r=d.useRef(`loading`),i=d.useRef(void 0),[a,o]=d.useState(0),s=d.useRef(),c=d.useRef(),l=d.useRef();return s.current===e&&c.current===t&&l.current===n||(r.current=`loading`,i.current=void 0,s.current=e,c.current=t,l.current=n),d.useLayoutEffect(function(){if(e){var a=document.createElement(`video`);return a.addEventListener(`canplay`,s),a.addEventListener(`error`,c),t&&(a.crossOrigin=t),n&&(a.referrerPolicy=n),a.src=e,a.load(),function(){a.removeEventListener(`canplay`,s),a.removeEventListener(`error`,c)}}function s(){r.current=`loaded`,i.current=a,i.current.currentTime=0,o(Math.random()),i.current.removeEventListener(`canplay`,s)}function c(e){let t=a.readyState===4,n=a.buffered&&a.buffered.length>0&&a.buffered.end(a.buffered.length-1)/a.duration*100>=100;if(t&&n)return;let s=e.message||a.error?.message||`Unknown error`,c=Error(`Video failed to load: `+s);console.error(c),r.current=`failed`,i.current=void 0,o(Math.random())}},[e,t,n]),[i.current,r.current]};function hD(e){return e.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA}var gD=(e,t,n)=>{let r=d.useRef(),i=()=>{var e;(e=r.current)==null||e.call(r),r.current=void 0};d.useEffect(()=>i,[]),d.useLayoutEffect(()=>{let a=`video with id ${n} url: ${t.slice(0,200)}`;e!==`loading`||r.current||(r.current=Kf(a)),e!==`loading`&&i(),e===`failed`&&Zf(a)},[e])},_D=sa(({element:e,store:t})=>{let[n,r]=d.useState(!1),i=d.useRef(null),a=d.useRef(null),o=t.selectedShapes.indexOf(e)>=0&&e.selectable,[s,c]=d.useState(!1),[l,u]=mD(e.src,`anonymous`),[f,p]=d.useState(!1),m=t.activePage===e.page,h=e.page._exportingOrRendering&&u===`loaded`,g=oD(e,t,h);gD(u,e.src,e.id),l&&(l.playsInline=!0);let _=((e,t,n)=>{let r=d.useMemo(()=>{var r,i;let{flipX:a,flipY:o}=e,s=e.type===`svg`||e.src.indexOf(`data:image/svg+xml`)>=0||e.src.indexOf(`.svg`)>=0,c=navigator.userAgent.toLowerCase().indexOf(`firefox`)>-1;if(!(a||o||c&&s))return t;if(!t)return null;let l=t instanceof HTMLVideoElement?t.videoWidth:t?.width,u=t instanceof HTMLVideoElement?t.videoHeight:t?.height;if(!l||!u)return null;let d=sD(),f=1;e.type===`svg`&&(f=Math.max(e.width/l*n,e.height/u*n)),d.width=Math.max(l*f,1),d.height=Math.max(u*f,1);let p=a?-d.width:0,m=o?-d.height:0;return(r=d.getContext(`2d`))==null||r.scale(a?-1:1,o?-1:1),(i=d.getContext(`2d`))==null||i.drawImage(t,p,m,d.width,d.height),d},[e.flipX,e.flipY,t,e.width,e.height,n]);return d.useEffect(()=>()=>{r&&r.nodeName===`CANVAS`&&Du.Util.releaseCanvas(r)},[r]),r})(e,l,t._elementsPixelRatio),v=h&&g||_||dD;d.useEffect(()=>{l&&t.history.ignore(()=>{e.set({duration:1e3*l.duration})})},[l]),d.useEffect(()=>{if(!l)return;let n=t.animatedElementsIds,r=(!n.length||n.includes(e.id))&&t.isPlaying,a=m&&(r||s);if(!a){l.pause();return}a&&(l.currentTime=e.startTime*l.duration,l.play());let o=new Du.Animation(()=>{I.current()},i.current?.getLayer());o.start();let u=()=>{c(!1),l.currentTime=e.startTime*l.duration},d=()=>{l.currentTime>=e.endTime*l.duration&&(l.pause(),l.currentTime=e.startTime*l.duration,c(!1))};return l.addEventListener(`ended`,u),l.addEventListener(`timeupdate`,d),()=>{l.pause(),o.stop(),l.removeEventListener(`ended`,u),l.removeEventListener(`timeupdate`,d)}},[l,s,t.isPlaying,m]),d.useEffect(()=>{l&&(l.volume=e.volume)},[l,e.volume]);let y=d.useRef(null);d.useEffect(()=>{let n=Gn(()=>{var n;if(l){if(h&&g){ie(),t.currentTime;return}let r=t.animatedElementsIds;if(r.length&&!r.includes(e.id))return;let a=t.currentTime>=e.page.startTime&&t.currentTime<e.page.startTime+e.page.duration,o=e.startTime*l.duration*1e3,s=l.duration*(e.endTime-e.startTime)*1e3,c=((t.currentTime||e.page.startTime)-e.page.startTime)%s+o;if(a||(c=0),Math.abs(1e3*l.currentTime-c)>500||!t.isPlaying){let n=c/1e3;n!==l.currentTime&&(l.currentTime=n),!hD(l)&&!t.isPlaying&&!y.current&&(y.current=Kf(`video ${e.id}`))}I.current(),(n=i.current?.getLayer())==null||n.batchDraw()}});return()=>{n(),y.current&&=(y.current(),null)}},[t,l,h,g]),d.useEffect(()=>{var t;if(!l)return;if(h){(t=y.current)==null||t.call(y),y.current=null;return}let n=()=>{var t;!hD(l)&&e.page._exportingOrRendering||(y.current&&=(I.current(),(t=i.current?.getLayer())==null||t.batchDraw(),y.current(),null))},r;return e.page._exportingOrRendering&&(r=setInterval(n,20)),l.addEventListener(`timeupdate`,n),l.addEventListener(`canplay`,n),()=>{clearInterval(r),l.removeEventListener(`timeupdate`,n),l.removeEventListener(`canplay`,n)}},[e.page._exportingOrRendering,l,e.id,Kf,h]);let{cropX:b,cropY:x,cropWidth:S,cropHeight:C}=e;u!==`loaded`&&(b=x=0,S=C=1);let w=(T=v)instanceof HTMLVideoElement?T.videoWidth:T?.width||0;var T;let E=(e=>e instanceof HTMLVideoElement?e.videoHeight:e?.height||0)(v),D=w*S,O=E*C,k=e.width/e.height,A,j,M=D/O,N=e.type===`svg`;N?(A=D,j=O):k>=M?(A=D,j=D/k):(A=O*k,j=O);let P={x:w*b,y:E*x,width:A,height:j},F=e.cornerRadius??0,[ee,te]=uD(e,v,P,t._elementsPixelRatio,F,!0),[ne,re]=((e,t,n,r)=>{let[i,a]=(0,rf.default)((e=>{let[t,n]=d.useState(e);return d.useEffect(()=>{(async()=>{let r=await async function(e){return e.indexOf(`data:image/svg+xml`)>=0||e.indexOf(`.svg`)>=0?J_(Y_(await q_(e))):e}(e);r!==t&&n(r)})()},[e]),t})(e.clipSrc||``),`anonymous`);gD(e.clipSrc?a:`loaded`,e.clipSrc,e.id);let o=d.useMemo(()=>{if(t&&i)return sD()},[t,i]);function s(){var r;if(!i)return;let a=t instanceof HTMLVideoElement?t.videoWidth:t?.width,s=t instanceof HTMLVideoElement?t.videoHeight:t?.height;if(!t||!a||!s||!i||!i.width||!i.height||!o)return;let c=sD(),l=Math.max(e.width/i.width*n,e.height/i.height*n);c.width=i.width*l,c.height=i.height*l,(r=c.getContext(`2d`))==null||r.drawImage(i,0,0,c.width,c.height),o.width=Math.max(a,1),o.height=Math.max(s,1);let u=o.getContext(`2d`);u&&(u.save(),u.drawImage(c,0,0,a,s),Du.Util.releaseCanvas(c),u.globalCompositeOperation=`source-in`,u.drawImage(t,0,0,o.width,o.height),u.restore())}return d.useLayoutEffect(()=>{s()},[o,t,i,e.width,e.height,n,...r]),[e.clipSrc&&i?o:t,s]})(e,ee,t._elementsPixelRatio,[P,F,t._elementsPixelRatio]);function ie(){var e;te(),re(),(e=i.current?.getLayer())==null||e.batchDraw()}d.useEffect(()=>{ie()});let I=d.useRef(ie);I.current=ie;let ae=Math.max(e.width/A,e.height/j);d.useEffect(()=>{if(!e._cropModeEnabled)return;let t=i.current?.getStage();function n(t){e._cropModeEnabled&&t.target!==a.current&&e.toggleCropMode(!1)}function r(n){e._cropModeEnabled&&n.target.parentNode!==t?.content&&e.toggleCropMode(!1)}return document.body.addEventListener(`click`,r),t?.on(`click`,n),t?.on(`tap`,n),()=>{document.body.removeEventListener(`click`,r),document.body.removeEventListener(`touchstart`,r),t?.off(`click`,n),t?.off(`click`,n)}},[e._cropModeEnabled]),d.useLayoutEffect(()=>{if(!n&&!e._cropModeEnabled)return Hp(i.current,e),Gn(()=>{Hp(i.current,e)},{delay:100})},[v,n,S,C,e._cropModeEnabled]),d.useLayoutEffect(()=>{var t;n||e._cropModeEnabled?(t=i.current)==null||t.clearCache():Hp(i.current,e)},[n,e.width,e.height,e._cropModeEnabled]),d.useEffect(()=>{Hp(i.current,e)},[e.shadowEnabled,e.shadowBlur,e.cornerRadius,e.shadowColor,e.shadowOffsetX,e.shadowOffsetY,e.shadowOpacity]);let oe=d.useRef(null),se=d.useRef(null),ce=d.useRef(null);d.useLayoutEffect(()=>{e._cropModeEnabled&&(se.current.nodes([oe.current]),ce.current.nodes([a.current]))},[e._cropModeEnabled]);let le=t=>{Math.round(t.target.x())>0&&(t.target.x(0),t.target.scaleX(1)),Math.round(t.target.y())>0&&(t.target.y(0),t.target.scaleY(1));let n=t.target.width()*t.target.scaleX(),r=t.target.height()*t.target.scaleY(),i=Math.min(1,A/n),a=Math.min(1,j/r),o=1-i,s=Math.min(o,Math.max(0,Math.round(-t.target.x())/n)),c=1-a,l=Math.min(c,Math.max(0,Math.round(-t.target.y())/r));t.target.setAttrs({x:-s*w,y:-l*E,scaleX:1,scaleY:1}),e.set({cropX:s,cropY:l,cropWidth:i,cropHeight:a})},ue=()=>{e.type!==`svg`&&e.contentEditable&&setTimeout(()=>{e.toggleCropMode(!0)})},de=u===`loading`,fe=u===`failed`,pe=!de&&!fe,me=d.useRef({cropX:0,cropY:0,cropWidth:0,cropHeight:0}),he=pe?e.a.opacity:0;Rf(i,he);let ge=e.selectable||t.role===`admin`,_e=Up();return d.createElement(d.Fragment,null,d.createElement(Kd,{onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1)},de&&d.createElement(fD,{element:e}),fe&&d.createElement(pD,{element:e}),d.createElement(Xd,{ref:i,name:`element`,id:e.id,image:ne,x:e.a.x,y:e.a.y,width:e.a.width||1,height:e.a.height||1,rotation:e.a.rotation,opacity:he,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,customCrop:P,listening:ge,draggable:_e?e.draggable&&o:e.draggable,preventDefault:!_e||o,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDblClick:ue,onDblTap:ue,onTransformStart:()=>{r(!0),me.current={cropX:e.cropX,cropY:e.cropY,cropWidth:e.cropWidth,cropHeight:e.cropHeight}},onTransform:t=>{let n=t.currentTarget,r=Math.abs(n.scaleX()-1)<1e-7?1:n.scaleX(),i=Math.abs(n.scaleY()-1)<1e-7?1:n.scaleY();n.scaleX(1),n.scaleY(1);let a=t.target.getStage()?.findOne(`Transformer`),o=1-A/w,s=Math.min(o,Math.max(0,e.cropX)),c=1-j/E,l=Math.min(c,Math.max(0,e.cropY)),u=a.getActiveAnchor(),d=!(u.indexOf(`middle`)>=0||u.indexOf(`center`)>=0),f=!d&&r<1&&me.current.cropHeight>j/E,p=d?e.cropWidth:e.cropWidth*r;f&&(p=e.cropWidth);let m=!d&&i<1&&me.current.cropWidth>A/w,h=d?e.cropHeight:e.cropHeight*i;m&&(h=e.cropHeight),N&&(p=e.cropWidth,h=e.cropHeight),e.set({cropX:s,cropY:l,x:n.x(),y:n.y(),width:n.width()*r,height:n.height()*i,rotation:t.target.rotation(),cropWidth:Math.min(p,1-s),cropHeight:Math.min(h,1-l)})},onTransformEnd:t=>{let n=t.currentTarget;e.set({width:n.width(),height:n.height(),x:n.x(),y:n.y(),rotation:t.target.rotation(),cropWidth:A/w,cropHeight:j/E}),r(!1)}}),d.createElement(Jd,{x:e.a.x,y:e.a.y,width:Math.max(e.a.width-e.borderSize,0),height:Math.max(e.a.height-e.borderSize,0),opacity:he,offsetX:-e.borderSize/2,offsetY:-e.borderSize/2,stroke:e.borderColor,strokeWidth:e.borderSize,listening:!1,visible:!!e.borderSize,rotation:e.rotation,cornerRadius:Math.max(0,F-e.borderSize),hideInExport:!e.showInExport}),!t.isPlaying&&d.createElement(`Image`,{image:s?f||_e?lD:void 0:cD,x:e.a.x,y:e.a.y,offsetX:-e.a.width/2+15/t.scale,offsetY:-e.a.height/2+15/t.scale,rotation:e.a.rotation,width:30/t.scale,height:30/t.scale,hideInExport:!0,onClick:()=>c(!s),onTap:()=>c(!s)}),e._cropModeEnabled&&d.createElement(lf,{selector:`.page-abs-container`,enabled:!0},d.createElement(`Rect`,{x:-window.innerWidth/t.scale,y:-window.innerWidth/t.scale,width:window.innerWidth/t.scale*3,height:window.innerWidth/t.scale*3,fill:`rgba(0,0,0,0.3)`}),d.createElement(`Image`,{listening:!1,image:ne,x:e.a.x,y:e.a.y,width:e.a.width,height:e.a.height,rotation:e.a.rotation,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur}),d.createElement(`Group`,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,scaleX:ae,scaleY:ae},d.createElement(`Image`,{image:v,ref:a,width:w,height:E,opacity:.4,draggable:!0,x:-e.cropX*w,y:-e.cropY*E,onDragMove:le,onTransform:le}),d.createElement(`Transformer`,{ref:ce,anchorSize:20,enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,rotateEnabled:!1,borderEnabled:!1,anchorCornerRadius:10,anchorStrokeWidth:2,borderStrokeWidth:2}),d.createElement(`Rect`,{width:A,height:j,ref:oe,listening:!1,onTransform:t=>{t.target.x()<-e.cropX*w-1e-9&&(t.target.x(-e.cropX*w),t.target.scaleX(1)),t.target.y()<-e.cropY*E-1e-9&&(t.target.y(-e.cropY*E),t.target.scaleY(1));let n=Math.min(1,Math.max(0,e.cropX+t.target.x()/w)),r=Math.min(1,Math.max(0,t.target.y()/E+e.cropY)),i=t.target.width()*t.target.scaleX(),a=t.target.height()*t.target.scaleY(),o=Math.min(1-n,i/w),s=Math.min(1-r,a/E),c=t.target.getAbsolutePosition(t.target.getParent().getParent());t.target.scale({x:1,y:1}),t.target.position({x:0,y:0}),e.set({x:c.x,y:c.y,cropX:n,cropY:r,cropWidth:o,cropHeight:s,width:Math.min(i*ae,w*(1-n)*ae),height:Math.min(a*ae,E*(1-r)*ae)})}}),d.createElement(`Transformer`,{ref:se,enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`],boundBoxFunc:(e,t)=>t.width<5||t.height<5?e:t,keepRatio:!1,rotateEnabled:!1,anchorFill:`rgb(240, 240, 240)`,anchorStrokeWidth:2,borderStrokeWidth:2,visible:e.resizable})))))}),vD=({width:e,height:t,cornerRadius:n})=>{if(n>0){let r=Math.min(n,e/2,t/2);return`M 0 ${r} A ${r} ${r} 0 0 1 ${r} 0 L ${e-r} 0 A ${r} ${r} 0 0 1 ${e} ${r} L ${e} ${t-r} A ${r} ${r} 0 0 1 ${e-r} ${t} L ${r} ${t} A ${r} ${r} 0 0 1 0 ${t-r} Z`}return`M 0 0 L ${e} 0 L ${e} ${t} L 0 ${t} Z`},yD=({width:e,height:t})=>`M ${e/2} 0 L ${e} ${t} L 0 ${t} Z`,bD=({width:e,height:t})=>`M 0 0 L ${e} 0 L 0 ${t} Z`,xD=({width:e,height:t})=>`M ${e/2} ${t/2} m -${e/2}, 0 a ${e/2},${t/2} 0 1,0 ${e},0 a ${e/2},${t/2} 0 1,0 -${e},0`;function SD({width:e,height:t}){let n=e/2,r=t/2,i=e/2,a=t/2,o=i/2,s=a/2,c=``,l=Math.PI/5;for(let e=0;e<10;e++){let t=e%2==0?a:s,u=n+(e%2==0?i:o)*Math.sin(e*l),d=r-t*Math.cos(e*l);e===0?c=`M ${u} ${d}`:c+=` L ${u} ${d}`}return c+` Z`}function CD({width:e,height:t}){let n=e/2,r=t/2;return`M ${n} 0 L ${e} ${r} L ${n} ${t} L 0 ${r} Z`}function wD({width:e,height:t}){let n=e/2,r=t/2,i=e/2,a=t/2,o=``,s=2*Math.PI/5;for(let e=0;e<5;e++){let t=a,c=n+i*Math.sin(e*s),l=r-t*Math.cos(e*s);e===0?o=`M ${c} ${l}`:o+=` L ${c} ${l}`}return o+` Z`}function TD({width:e,height:t}){let n=e/2,r=t/2,i=e/2,a=t/2,o=``,s=2*Math.PI/6;for(let e=0;e<6;e++){let t=a,c=n+i*Math.sin(e*s),l=r-t*Math.cos(e*s);e===0?o=`M ${c} ${l}`:o+=` L ${c} ${l}`}return o+` Z`}function Q({path:e,aspectRatio:t,width:n,height:r}){return{path:e,scaleX:n/t.width,scaleY:r/t.height}}function ED({width:e,height:t}){let n=.1*Math.min(e,t),r=.2*e,i=.2*t,a=.5*e,o=`M ${n},0`;return o+=` H `+(e-n),o+=` A ${n},${n} 0 0 1 ${e},${n}`,o+=` V `+(t-n-i),o+=` A ${n},${n} 0 0 1 ${e-n},${t-i}`,o+=` H ${a+r/2}`,o+=` L ${a},${t}`,o+=` L ${a-r/2},${t-i}`,o+=` H ${n}`,o+=` A ${n},${n} 0 0 1 0,${t-n-i}`,o+=` V ${n}`,o+=` A ${n},${n} 0 0 1 ${n},0`,o+=` Z`,o}function DD({width:e,height:t}){let n=.3*e,r=.3*t,i=e/2,a=t/2,o=i-n/2,s=i+n/2,c=a-r/2,l=a+r/2,u=`M ${o},0 `;return u+=`H ${s} `,u+=`V ${c} `,u+=`H ${e} `,u+=`V ${l} `,u+=`H ${s} `,u+=`V ${t} `,u+=`H ${o} `,u+=`V ${l} `,u+=`H 0 `,u+=`V ${c} `,u+=`H ${o} `,u+=`V 0 `,u+=`Z`,u}var OD={rect:vD,circle:xD,star:SD,triangle:yD,rightTriangle:bD,diamond:CD,pentagon:wD,hexagon:TD,speechBubble:ED,cross:DD,arc:({width:e,height:t})=>Q({path:`M234 117C234 85.97 221.673 56.21 199.731 34.269C177.79 12.327 148.03 0 117 0C85.97 0 56.2103 12.327 34.2685 34.268C12.3268 56.21 0 85.97 0 117H117H234Z`,aspectRatio:{width:234,height:117},width:e,height:t}),cloud:({width:e,height:t})=>Q({path:`M216.41 57.006C216.961 54.084 217.249 51.069 217.249 47.986C217.249 21.4841 195.972 0 169.725 0C153.666 0 139.467 8.043 130.865 20.3575C122.606 13.3566 111.954 9.1402 100.327 9.1402C74.3322 9.1402 53.2123 30.2136 52.8094 56.364H52.8035C23.6407 56.364 0 80.235 0 109.682C0 139.129 23.6407 163 52.8035 163H208.197C237.359 163 261 139.129 261 109.682C261 83.056 241.672 60.99 216.41 57.006Z`,aspectRatio:{width:261,height:163},width:e,height:t}),rightArrow:({width:e,height:t})=>{let n=.6*e;return`M 0 ${t/4} L ${n} ${t/4} L ${n} 0 L ${e} ${t/2} L ${n} ${t} L ${n} ${.75*t} L 0 ${.75*t} Z`},leftArrow:({width:e,height:t})=>{let n=.4*e;return`M ${e} ${t/4} L ${n} ${t/4} L ${n} 0 L 0 ${t/2} L ${n} ${t} L ${n} ${.75*t} L ${e} ${.75*t} Z`},downArrow:({width:e,height:t})=>{let n=.6*t;return`M ${e/4} 0 L ${e/4} ${n} L 0 ${n} L ${e/2} ${t} L ${e} ${n} L ${.75*e} ${n} L ${.75*e} 0 Z`},upArrow:({width:e,height:t})=>{let n=.4*t;return`M ${e/4} ${t} L ${e/4} ${n} L 0 ${n} L ${e/2} 0 L ${e} ${n} L ${.75*e} ${n} L ${.75*e} ${t} Z`},asterisk1:({width:e,height:t})=>Q({path:`M45.5265 218.498C51.5466 222.87 58.5359 224.98 65.4742 224.98C75.916 224.98 86.221 220.2 92.853 211.217C92.872 211.198 92.89 211.178 92.907 211.157C92.923 211.136 92.939 211.115 92.954 211.094L92.977 211.061C92.993 211.039 93.008 211.017 93.023 210.996L116.491 178.725L139.959 210.996C139.982 211.031 140.006 211.058 140.029 211.088C140.04 211.102 140.05 211.116 140.061 211.132C151.115 226.188 172.355 229.505 187.473 218.515C202.608 207.526 205.992 186.278 195.074 171.104L195.05 171.066C195.03 171.034 195.014 171.01 194.989 170.985L171.572 138.696L209.512 126.346C227.334 120.545 237.129 101.305 231.33 83.476C225.532 65.648 206.315 55.8493 188.476 61.6334L150.537 73.933L150.52 34.0064C150.502 15.2594 135.248 0 116.508 0C97.768 0 82.514 15.2594 82.497 34.0234L82.463 73.916L44.5233 61.6163C44.5083 61.6163 44.49 61.613 44.4716 61.6078C44.4477 61.6014 44.4232 61.5918 44.4041 61.5823C26.5992 55.8664 7.45076 65.665 1.66886 83.46C-4.11314 101.254 5.61427 120.426 23.3511 126.278C23.3675 126.283 23.3822 126.289 23.3963 126.295L23.4588 126.319L23.4873 126.329L61.4098 138.679L37.9929 170.968C37.9844 170.985 37.9718 171.002 37.9591 171.019C37.9462 171.036 37.9336 171.053 37.9251 171.07C26.9903 186.244 30.3915 207.509 45.5265 218.498Z`,aspectRatio:{width:233,height:225},width:e,height:t}),asterisk2:({width:e,height:t})=>Q({path:`M46.0556 112L0 85.388L33.9456 26.6121L80.028 53.1781L80.054 0H147.946L147.972 53.1781L194.054 26.6121L228 85.388L181.944 112L228 138.612L194.054 197.388L147.972 170.822L147.946 224H80.054L80.028 170.822L33.9456 197.388L0 138.612L46.0556 112Z`,aspectRatio:{width:228,height:224},width:e,height:t}),bookmark:({width:e,height:t})=>Q({path:`M0 0H199V238L99.5 142.8L0 238V0Z`,aspectRatio:{width:199,height:238},width:e,height:t}),butterfly:({width:e,height:t})=>Q({path:`M94.5 100.713C91.935 150.916 50.703 190.909 0 191.493V0C50.703 0.5845 91.935 40.5767 94.5 90.78C97.031 41.2385 137.217 1.6407 187 0.0438004V191.45C137.217 189.853 97.031 150.255 94.5 100.713Z`,aspectRatio:{width:187,height:192},width:e,height:t}),cylinder:({width:e,height:t})=>Q({path:`M169 36.8497V218.15C169 238.502 131.168 255 84.5 255C37.832 255 0 238.502 0 218.15V36.8497C0 16.4982 37.832 0 84.5 0C131.168 0 169 16.4982 169 36.8497Z`,aspectRatio:{width:169,height:255},width:e,height:t}),diamond2:({width:e,height:t})=>Q({path:`M0 55.5L124 185L248 55.5L189.307 0H58.6933L0 55.5Z`,aspectRatio:{width:248,height:185},width:e,height:t}),door:({width:e,height:t})=>Q({path:`M140 69.697C140 31.2044 108.66 0 70 0C31.34 0 0 31.2044 0 69.697V207H140V69.697Z`,aspectRatio:{width:140,height:207},width:e,height:t}),drop1:({width:e,height:t})=>Q({path:`M167 150.687C167 196.328 129.407 234 83.139 234C37.593 234 0 196.328 0 150.687C0 100.7 51.329 36.9474 83.139 0C114.948 39.1207 167 98.526 167 150.687Z`,aspectRatio:{width:167,height:234},width:e,height:t}),drop2:({width:e,height:t})=>Q({path:`M73 239C53.64 239 35.071 231.315 21.3812 217.634C7.691 203.954 0 185.4 0 166.054C0 136.091 13.8696 113.633 30.768 86.27C43.912 64.9877 58.888 40.7377 70.597 7.6816C71.281 5.7496 72.989 0 72.989 0C72.989 0 72.993 0.0124998 73 0.0363998C73.007 0.0124998 73.011 0 73.011 0C73.011 0 74.719 5.7496 75.403 7.6816C87.112 40.7377 102.088 64.9877 115.232 86.27C132.13 113.633 146 136.091 146 166.054C146 185.4 138.309 203.954 124.619 217.634C111.025 231.218 92.225 239 73 239Z`,aspectRatio:{width:146,height:239},width:e,height:t}),explosion:({width:e,height:t})=>Q({path:`M165.802 184.465L118.997 260L125.343 182.079L34.9058 219.45L99.164 159.817L0 163.792L78.538 134.373L0 74.7401L86.471 89.052V0L118.997 89.052L165.802 10.3364L149.143 97.798L217.368 29.419L165.802 112.905L245.927 81.101L165.802 143.914H261L165.802 184.465Z`,aspectRatio:{width:261,height:260},width:e,height:t}),flag:({width:e,height:t})=>Q({path:`M0 142.161C0 142.161 51.9956 118.626 103 137.469C159.992 158.525 206 141.31 206 141.31V11.1373C206 11.1373 160 28.3218 103.016 7.28273C52 -11.553 0 12.0974 0 12.0974V142.161Z`,aspectRatio:{width:206,height:148},width:e,height:t}),flower:({width:e,height:t})=>Q({path:`M135.351 66.1893C196.683 -5.00591 256.536 100.304 164.908 117.361C256.536 135.16 195.944 239.728 135.351 168.532C166.386 257.526 45.9394 256.785 76.975 168.532C15.643 239.728 -44.2109 135.16 47.4173 117.361C-44.9498 100.304 15.643 -4.26431 76.975 66.1893C45.2005 -22.0631 166.386 -22.0631 135.351 66.1893ZM105.793 104.012C113.183 104.012 119.833 109.945 119.833 117.361C119.833 124.777 113.183 131.452 105.793 131.452C98.404 131.452 92.492 124.777 92.492 117.361C92.492 109.945 98.404 104.012 105.793 104.012Z`,aspectRatio:{width:212,height:235},width:e,height:t}),frame:({width:e,height:t})=>Q({path:`M0 0H240L200 88L240 176H0L40 88L0 0Z`,aspectRatio:{width:240,height:176},width:e,height:t}),heart1:({width:e,height:t})=>Q({path:`M215.886 56.157C215.886 24.729 191.112 0 160.584 0C135.933 0 115.08 16.983 107.937 39.93C100.788 16.986 79.935 0.591 55.284 0.591C24.75 0.591 0 24.615 0 56.055C0 71.919 6.321 83.127 16.494 95.121L107.988 189.447L199.377 95.121C209.559 83.127 215.886 72.009 215.886 56.157Z`,aspectRatio:{width:216,height:190},width:e,height:t}),home:({width:e,height:t})=>Q({path:`M0 62.143L95.5 0L191 62.143V195H0V62.143Z`,aspectRatio:{width:191,height:195},width:e,height:t}),home2:({width:e,height:t})=>Q({path:`M206 94.076L103 0L0 94.076H31.2377V189H175.607V94.076H206Z`,aspectRatio:{width:206,height:189},width:e,height:t}),hourglass:({width:e,height:t})=>Q({path:`M0.392782 0H187.607C193.014 43.3688 140.804 53.797 140.804 97.5C140.804 141.203 193.014 151.631 187.607 195H0.392782C-5.01452 151.631 47.196 141.203 47.196 97.5C47.196 53.797 -5.01452 43.3688 0.392782 0Z`,aspectRatio:{width:188,height:195},width:e,height:t}),house:({width:e,height:t})=>Q({path:`M0 92.367L95 0L190 92.367V223H0V92.367Z`,aspectRatio:{width:190,height:223},width:e,height:t}),keyhole:({width:e,height:t})=>Q({path:`M115 57.0494C115 25.5387 89.416 0 57.863 0C26.311 0 0.726898 25.5414 0.726898 57.0494C0.726898 78.652 12.759 97.451 30.505 107.136L0 219H114.845L84.448 107.524C102.608 97.962 115 78.959 115 57.0494Z`,aspectRatio:{width:115,height:219},width:e,height:t}),kiss:({width:e,height:t})=>Q({path:`M124.5 17.1468C80.036 -36.5162 0 52.9218 0 52.9218C0 52.9218 44.4643 120 124.5 120C204.536 120 249 52.9218 249 52.9218C249 52.9218 168.964 -36.5162 124.5 17.1468Z`,aspectRatio:{width:249,height:120},width:e,height:t}),leaf:({width:e,height:t})=>Q({path:`M204.414 0.0151567C204.414 0.0151567 206.837 93.9509 150.394 150.394C93.9507 206.837 0.0151569 204.413 0.0151569 204.413C0.0151569 204.413 -2.40835 110.478 54.0347 54.0349C110.478 -2.40834 204.414 0.0151567 204.414 0.0151567Z`,aspectRatio:{width:205,height:205},width:e,height:t}),lightning1:({width:e,height:t})=>Q({path:`M111.5 0L0 142H51.433L31.5 253L143 111H91.567L111.5 0Z`,aspectRatio:{width:143,height:253},width:e,height:t}),lightning2:({width:e,height:t})=>Q({path:`M126 0H43L0 120.531H36L6 227L110 80.354H73L126 0Z`,aspectRatio:{width:126,height:227},width:e,height:t}),magnet:({width:e,height:t})=>Q({path:`M88.402 0H0V67.669H88.402C105.271 67.669 118.957 81.308 118.957 98C118.957 114.689 105.271 128.331 88.402 128.331H0V196H88.402C142.747 196 187 152.072 187 98C187 43.9279 142.747 0 88.402 0Z`,aspectRatio:{width:187,height:196},width:e,height:t}),mithosis:({width:e,height:t})=>Q({path:`M150.996 136.45C137.141 128.926 117.559 128.7 103.532 135.896C93.843 140.867 82.875 143.67 71.2577 143.67C31.9033 143.67 0 111.508 0 71.835C0 32.161 31.9033 0 71.2577 0C83.467 0 94.959 3.0955 105.004 8.5504C118.859 16.0745 138.441 16.3 152.467 9.1038C162.157 4.1328 173.125 1.3303 184.742 1.3303C224.097 1.3303 256 33.492 256 73.165C256 112.839 224.097 145 184.742 145C172.533 145 161.041 141.905 150.996 136.45Z`,aspectRatio:{width:256,height:145},width:e,height:t}),orangeRicky:({width:e,height:t})=>Q({path:`M69 0H0V69V138V207H69H138V138H69V69V0Z`,aspectRatio:{width:138,height:207},width:e,height:t}),party:({width:e,height:t})=>Q({path:`M134.622 0L144.682 68.2539L174.415 5.9977L163.91 74.1846L210.671 23.4578L180.535 85.519L240.169 50.8289L193.079 101.25L260.29 85.679L200.43 119.98L269.245 124.911L201.934 140.044L266.237 165.04L197.456 159.661L251.535 202.5L187.396 177.086L226.445 233.962L172.646 190.771L193.197 256.631L154.518 199.501L154.743 268.492L134.622 202.5L114.501 268.492L114.727 199.501L76.0482 256.631L96.5985 190.771L42.7992 233.962L81.8489 177.086L17.7091 202.5L71.7885 159.661L3.0072 165.04L67.3112 140.044L0 124.911L68.8149 119.98L8.9545 85.679L76.1658 101.25L29.0753 50.8289L88.7105 85.519L58.5743 23.4578L105.335 74.1846L94.8305 5.9977L124.562 68.2539L134.622 0Z`,aspectRatio:{width:270,height:269},width:e,height:t}),pillow:({width:e,height:t})=>Q({path:`M176 0.00169945C157.812 16.9062 125.203 28.174 88.001 28.174C50.798 28.174 18.1881 16.9054 0 0V258.421C18.1882 241.516 50.798 230.248 88 230.248C125.202 230.248 157.812 241.516 176 258.421V0.00169945Z`,aspectRatio:{width:176,height:259},width:e,height:t}),polygon:({width:e,height:t})=>Q({path:`M110 0L219.119 63V189L110 252L0.880798 189V63L110 0Z`,aspectRatio:{width:220,height:252},width:e,height:t}),rainbow:({width:e,height:t})=>Q({path:`M186.907 141H282C282 63.128 218.872 0 141 0C63.1278 0 0 63.128 0 141H95.093C95.093 115.646 115.646 95.093 141 95.093C166.354 95.093 186.907 115.646 186.907 141Z`,aspectRatio:{width:282,height:141},width:e,height:t}),rhodeIsland:({width:e,height:t})=>Q({path:`M69 0H0V69V138H69V207H138V138V69H69V0Z`,aspectRatio:{width:138,height:207},width:e,height:t}),shell:({width:e,height:t})=>Q({path:`M109 0C169.199 0 218 48.743 218 108.87C185.392 108.87 158.958 135.273 158.958 167.842C158.958 179.736 158.958 191 158.958 191H59.042C59.042 191 59.042 179.736 59.042 167.842C59.042 135.273 32.6077 108.87 0 108.87C0 48.743 48.8007 0 109 0Z`,aspectRatio:{width:218,height:191},width:e,height:t}),shield1:({width:e,height:t})=>Q({path:`M203.184 30.7277C142.457 30.7277 102.853 0 102.853 0C102.853 0 63.249 30.7277 3.05098 30.7277C3.05098 30.7277 -3.81372 128.209 3.05098 162.115C9.38758 193.902 102.853 249 102.853 249C102.853 249 196.319 193.902 203.184 162.115C209.52 128.738 203.184 30.7277 203.184 30.7277Z`,aspectRatio:{width:206,height:249},width:e,height:t}),shield2:({width:e,height:t})=>Q({path:`M0 12.9585C64.624 -4.3195 136.376 -4.3195 201 12.9585C201 51.0564 201 89.154 201 127.252C201 184.396 100.498 240 100.498 240C100.498 240 0 184.406 0 127.252C0 89.154 0 51.0564 0 12.9585Z`,aspectRatio:{width:201,height:240},width:e,height:t}),skewedRectangle:({width:e,height:t})=>Q({path:`M85.9799 0H290L204.02 141H0L85.9799 0Z`,aspectRatio:{width:290,height:141},width:e,height:t}),softFlower:({width:e,height:t})=>Q({path:`M109 0C80.073 0 56.6234 23.4498 56.6234 52.3766C56.6234 54.722 54.722 56.6234 52.3766 56.6234C23.4498 56.6234 0 80.073 0 109C0 137.927 23.4498 161.377 52.3766 161.377C54.722 161.377 56.6234 163.278 56.6234 165.623C56.6234 194.55 80.073 218 109 218C137.927 218 161.377 194.55 161.377 165.623C161.377 163.278 163.278 161.377 165.623 161.377C194.55 161.377 218 137.927 218 109C218 80.073 194.55 56.6234 165.623 56.6234C163.278 56.6234 161.377 54.722 161.377 52.3766C161.377 23.4498 137.927 0 109 0Z`,aspectRatio:{width:218,height:218},width:e,height:t}),softStar:({width:e,height:t})=>Q({path:`M130.424 3.17662C130.927 -1.05888 137.073 -1.05888 137.576 3.17662L141.792 38.7086C147.236 84.59 183.41 120.764 229.291 126.208L264.823 130.424C269.059 130.927 269.059 137.073 264.823 137.576L229.291 141.792C183.41 147.236 147.236 183.41 141.792 229.291L137.576 264.823C137.073 269.059 130.927 269.059 130.424 264.823L126.208 229.291C120.764 183.41 84.59 147.236 38.7086 141.792L3.17662 137.576C-1.05888 137.073 -1.05888 130.927 3.17662 130.424L38.7086 126.208C84.59 120.764 120.764 84.59 126.208 38.7086L130.424 3.17662Z`,aspectRatio:{width:268,height:268},width:e,height:t}),stairs1:({width:e,height:t})=>Q({path:`M0 0H67.667V67.667H135.333V135.333H203V203H0V0Z`,aspectRatio:{width:203,height:203},width:e,height:t}),stairs2:({width:e,height:t})=>Q({path:`M50 0H0V200H200V150H150V100H100V50H50V0Z`,aspectRatio:{width:200,height:200},width:e,height:t}),teewee:({width:e,height:t})=>Q({path:`M69 0H138V69H207V138H138H69H0V69H69V0Z`,aspectRatio:{width:207,height:138},width:e,height:t}),blob1:({width:e,height:t})=>Q({path:`M172.979 19.611C191.285 33.0858 204.505 54.442 210.861 78.5949C217.471 103.002 217.471 130.46 205.776 151.816C194.335 173.427 171.454 189.444 147.047 196.054C122.639 202.919 96.7069 200.631 75.3506 190.715C54.2486 180.546 37.7229 163.003 23.4855 142.155C9.5022 121.307 -2.19289 97.4087 0.349524 74.7813C3.14617 52.1538 19.9261 30.7976 40.2654 17.8313C60.6046 4.61077 84.5033 -0.474048 108.148 0.0344341C131.538 0.542916 154.928 6.13621 172.979 19.611Z`,aspectRatio:{width:216,height:200},width:e,height:t}),blob10:({width:e,height:t})=>Q({path:`M188.684 8.95173C205.601 24.3309 200.988 63.0866 191.453 99.3816C182.225 135.677 168.076 169.511 146.238 175.355C124.399 181.507 94.871 159.668 66.5733 143.059C37.9679 126.449 10.5929 115.068 2.59569 95.0754C-5.4015 75.0824 5.97912 46.1694 24.4342 30.4826C42.8893 14.7958 68.4188 12.0276 100.715 6.79864C132.704 1.5697 171.767 -6.42749 188.684 8.95173Z`,aspectRatio:{width:200,height:177},width:e,height:t}),blob11:({width:e,height:t})=>Q({path:`M137.368 29.4923C148.97 46.7605 146.542 72.1231 148.161 99.1046C149.779 126.086 155.715 154.956 144.113 174.383C132.781 193.81 103.911 203.793 80.4369 198.666C56.963 193.27 38.6156 173.034 28.3626 153.607C17.8398 134.181 15.4115 115.833 9.47555 91.5498C3.53961 67.2664 -5.63411 37.3169 4.61887 20.0488C15.1417 2.51078 45.0911 -1.80626 72.8821 0.622074C100.673 2.78059 126.036 12.2241 137.368 29.4923Z`,aspectRatio:{width:152,height:200},width:e,height:t}),blob12:({width:e,height:t})=>Q({path:`M158.391 17.923C172.491 28.5703 180.261 48.1384 187.743 70.5842C194.937 93.3177 202.419 118.641 194.649 138.785C187.167 158.928 164.146 173.317 138.535 184.54C112.923 196.05 84.4347 204.108 58.8235 197.777C33.2123 191.446 10.191 170.439 2.99688 146.267C-4.48504 121.807 3.57241 94.181 10.4788 68.282C17.0974 42.0953 22.565 17.6352 37.8166 7.27563C53.0682 -3.37171 78.1038 0.081487 100.837 2.67138C123.859 5.26127 144.29 7.27563 158.391 17.923Z`,aspectRatio:{width:198,height:200},width:e,height:t}),blob13:({width:e,height:t})=>Q({path:`M149.668 1.37595C170.663 5.22017 193.728 17.3442 198.755 34.7911C204.078 52.2379 191.363 75.3032 178.943 93.9329C166.819 112.563 154.99 126.757 140.501 145.386C126.011 164.312 108.86 187.673 92.5957 186.194C76.3317 185.011 60.9549 159.285 45.8737 140.655C30.4968 122.321 15.7114 110.788 7.43151 95.1157C-0.848339 79.4432 -2.32688 59.0392 3.5873 41.5924C9.50148 23.8498 23.1041 8.76868 38.7767 3.44592C54.745 -1.87685 73.3746 2.55879 91.7086 2.26308C110.338 2.26308 128.968 -2.17256 149.668 1.37595Z`,aspectRatio:{width:200,height:187},width:e,height:t}),blob14:({width:e,height:t})=>Q({path:`M137.838 28.6426C150.711 40.5617 165.014 46.5213 178.363 58.2021C191.474 69.8828 203.87 87.0464 198.864 99.6807C193.858 112.315 171.689 120.42 157.862 135.676C144.275 151.171 139.269 173.579 126.873 182.161C114.477 190.505 94.9294 185.022 76.8123 178.109C58.4568 171.196 41.5316 163.091 28.1822 150.456C14.5943 137.822 4.58225 120.42 1.24488 101.826C-2.09248 83.2322 1.00651 62.9697 13.8792 52.4809C26.7519 41.992 49.1598 41.0385 65.6083 30.788C82.0567 20.5376 92.0688 0.990158 103.034 0.0366268C113.762 -0.916905 125.204 16.9618 137.838 28.6426Z`,aspectRatio:{width:200,height:187},width:e,height:t}),blob15:({width:e,height:t})=>Q({path:`M185.203 1.52939C197.679 7.62217 200 32.2835 200 51.7223C200 71.1612 197.389 85.3777 197.679 100.175C198.259 114.681 201.741 129.768 198.259 143.114C194.778 156.46 184.623 168.356 171.567 173.868C158.801 179.671 143.134 179.091 130.368 174.739C117.312 170.387 106.867 162.263 86.8482 160.812C66.539 159.362 36.9454 164.294 18.9572 155.3C0.968966 146.306 -5.41395 123.095 5.03083 105.977C15.4756 88.5692 42.4579 77.5442 55.5139 59.5559C68.2798 41.8578 67.1192 17.4867 76.9837 9.6531C86.5581 2.10965 107.158 11.3939 128.627 9.6531C150.097 8.20244 172.728 -4.27327 185.203 1.52939Z`,aspectRatio:{width:200,height:179},width:e,height:t}),blob16:({width:e,height:t})=>Q({path:`M158.441 55.3221C167.253 80.2399 160.264 105.462 147.501 134.938C134.738 164.717 116.81 199.055 97.0576 199.967C77.3057 201.182 55.7305 168.668 34.4592 133.722C13.1879 99.0802 -7.77953 62.3112 2.85612 36.4818C13.4918 10.6523 56.0344 -3.93369 90.0685 0.928322C123.799 6.09421 149.324 30.7081 158.441 55.3221Z`,aspectRatio:{width:163,height:200},width:e,height:t}),blob17:({width:e,height:t})=>Q({path:`M168.917 36.7587C178.871 53.2457 175.138 76.5764 172.961 106.129C170.472 135.37 169.85 170.832 150.563 187.63C131.276 204.739 93.3252 203.495 65.0173 187.63C36.7095 172.077 18.0449 142.213 7.77943 107.373C-2.79714 72.2213 -4.35252 32.7147 14.312 14.0502C32.9765 -4.3033 72.1721 -1.50361 103.591 4.7179C135.32 10.6283 158.962 20.2717 168.917 36.7587Z`,aspectRatio:{width:176,height:200},width:e,height:t}),blob18:({width:e,height:t})=>Q({path:`M178.188 21.1464C193.012 36.3069 196.381 62.9219 198.739 88.1893C200.76 113.12 201.771 136.366 190.316 149.168C178.862 162.307 155.279 164.665 135.065 167.697C115.188 170.73 99.0168 174.098 72.4018 177.131C46.1237 180.163 9.40176 182.521 1.65309 168.371C-6.09559 154.221 15.4659 123.564 23.5515 92.9059C31.6371 62.2481 26.2467 31.2534 38.3751 15.4192C50.1665 -0.0781831 79.8136 -1.08888 107.776 0.595609C136.076 1.9432 163.028 5.64909 178.188 21.1464Z`,aspectRatio:{width:200,height:180},width:e,height:t}),blob19:({width:e,height:t})=>Q({path:`M148.621 13.3857C171.945 24.3818 194.937 41.3756 192.938 60.702C190.605 80.3615 163.282 101.687 149.953 123.346C136.958 145.005 137.958 166.664 128.295 174.661C118.631 182.325 98.3054 175.994 73.6476 181.991C48.9899 187.989 20.0004 205.983 11.0036 197.986C1.67366 189.989 12.6697 156.001 12.3365 131.343C12.0033 106.685 0.340809 91.0243 0.00759636 75.0301C-0.325616 59.0359 10.3372 42.3753 25.3318 28.7135C39.9931 15.0518 58.9863 4.05578 80.3119 1.05687C101.638 -2.27526 124.962 2.38972 148.621 13.3857Z`,aspectRatio:{width:194,height:200},width:e,height:t}),blob2:({width:e,height:t})=>Q({path:`M140.464 18.6393C156.081 28.3718 169.887 39.9149 178.714 54.853C187.541 69.5649 191.389 87.6717 189.578 104.421C187.768 121.396 180.525 137.239 172.377 153.535C164.455 169.832 155.854 186.58 142.048 194.276C128.241 201.971 109.456 200.613 92.4804 197.671C75.2789 194.502 60.1144 189.749 45.1762 182.733C30.4644 175.716 16.2052 166.21 8.28346 153.083C0.361703 139.729 -1.44898 122.527 1.04072 106.91C3.30408 91.2931 9.64147 76.8076 15.9789 60.5114C22.0899 44.2153 28.201 26.1084 40.6495 14.7916C53.0979 3.24849 71.8838 -1.27823 89.7643 0.306124C107.871 1.66414 124.846 9.13322 140.464 18.6393Z`,aspectRatio:{width:191,height:200},width:e,height:t}),blob20:({width:e,height:t})=>Q({path:`M150.035 13.2464C157.376 24.9386 153.026 48.323 157.92 65.7254C163.087 83.1277 177.498 94.2761 182.392 108.415C187.287 122.555 182.392 139.957 173.147 156.272C163.63 172.587 149.763 187.814 132.089 195.155C114.414 202.225 93.2053 201.137 73.6276 194.611C54.3219 188.357 36.9196 176.937 25.7712 161.438C14.8947 145.667 10.5441 126.09 5.92163 105.696C1.57105 85.0311 -3.05145 63.5501 2.65869 45.0601C8.64075 26.5701 24.6835 11.0711 43.1735 4.54524C61.6635 -1.98064 82.6007 0.194657 102.722 1.01039C122.844 1.82613 142.421 1.55421 150.035 13.2464Z`,aspectRatio:{width:185,height:200},width:e,height:t}),blob21:({width:e,height:t})=>Q({path:`M152.611 0.184799C172.596 -0.723643 197.73 1.39606 199.85 13.8114C201.969 26.2268 181.075 48.9379 174.716 68.0151C168.357 87.0924 176.533 102.536 174.11 114.649C171.991 127.064 159.575 136.148 146.252 139.782C132.928 143.719 118.696 141.902 105.977 139.176C93.562 136.451 82.6606 132.212 63.2805 131.909C43.9004 131.606 16.0416 135.24 5.44306 125.853C-5.15543 116.465 1.50648 94.0572 10.2881 76.4939C18.7669 59.2335 29.6682 46.8182 38.7526 35.3112C48.1398 23.5015 56.3158 12.903 66.9143 8.36078C77.5128 4.12138 91.1394 6.24108 104.766 5.63546C118.696 4.72701 132.928 1.09324 152.611 0.184799Z`,aspectRatio:{width:200,height:143},width:e,height:t}),blob22:({width:e,height:t})=>Q({path:`M195.507 15.5715C206.818 33.1668 193.622 69.3001 190.166 101.663C186.71 134.34 193.308 163.561 181.996 178.014C170.685 192.153 141.464 191.525 114.443 189.326C87.1072 187.44 62.2852 183.67 40.6052 169.531C19.2395 155.077 1.6441 130.255 0.0730908 103.862C-1.18372 77.4694 13.898 49.5054 35.2638 31.91C56.6296 14.0004 84.5936 6.45958 116.328 2.37494C148.063 -1.70969 184.196 -2.3381 195.507 15.5715Z`,aspectRatio:{width:200,height:191},width:e,height:t}),blob23:({width:e,height:t})=>Q({path:`M135.742 9.14189C157.815 19.2326 179.258 38.4681 176.105 56.7576C172.951 74.7317 145.202 92.0751 127.858 109.734C110.83 127.077 104.523 145.052 87.4953 164.918C70.4672 184.468 42.7177 206.227 27.5816 198.343C12.4455 190.46 9.60747 153.566 6.45411 126.762C2.98542 100.274 -0.798607 84.1917 0.147399 67.1636C0.77807 50.4508 6.76944 32.4767 19.0675 20.8093C31.0503 9.14189 49.6551 3.78119 70.4672 1.2585C90.964 -1.26418 113.668 -0.633508 135.742 9.14189Z`,aspectRatio:{width:177,height:200},width:e,height:t}),blob24:({width:e,height:t})=>Q({path:`M165.663 24.3715C171.555 44.4059 158.003 76.2254 151.816 96.2598C145.923 116.294 147.691 124.544 148.28 135.445C148.575 146.346 147.396 159.309 140.62 170.8C133.549 181.996 120.88 191.424 104.381 196.432C87.8821 201.441 67.553 202.03 54.8841 192.602C41.9207 183.469 36.6174 164.023 25.1271 143.105C13.3421 122.187 -4.33535 99.7953 0.967891 85.0641C6.27113 70.6275 34.2604 63.8511 56.0626 48.5307C77.5702 33.5048 92.8907 9.93489 113.22 2.56928C133.843 -4.79633 159.77 4.04241 165.663 24.3715Z`,aspectRatio:{width:168,height:200},width:e,height:t}),blob25:({width:e,height:t})=>Q({path:`M180.115 1.256C192.651 2.1962 189.83 34.163 190.771 58.2947C191.711 82.4265 196.098 98.4099 198.606 117.214C201.113 136.018 201.426 157.642 189.204 165.791C177.294 173.626 153.163 167.671 135.299 163.91C117.749 159.836 106.466 157.956 85.7818 162.97C65.0974 168.298 35.3244 180.521 18.7143 174.253C1.79068 167.985 -1.97012 142.913 0.850478 120.975C3.67107 99.0367 13.0731 79.6059 18.4009 54.8473C23.7287 30.0888 24.9823 -0.310996 40.0254 0.00240332C54.7552 0.00240332 82.9612 31.029 111.167 31.029C139.373 31.029 167.579 0.315802 180.115 1.256Z`,aspectRatio:{width:200,height:176},width:e,height:t}),blob26:({width:e,height:t})=>Q({path:`M142.571 0.586925C159.976 3.39414 176.258 15.1844 184.96 30.9048C193.662 46.6253 194.224 66.8372 189.171 83.6805C183.837 100.805 172.327 114.56 163.064 129.157C153.8 143.755 146.501 158.914 134.43 173.231C122.359 187.828 105.516 201.303 89.5146 199.899C73.2327 198.776 58.0738 182.775 42.9148 169.862C28.0366 157.23 13.7198 147.685 6.42103 134.491C-0.877729 121.297 -1.15845 103.892 1.64876 88.4528C4.45598 72.7324 10.0704 58.6963 18.4921 47.4674C27.1944 36.2386 38.4233 27.8169 50.4943 22.2025C62.846 16.3073 75.7592 13.5001 91.1989 8.72785C106.919 4.23631 125.166 -1.93957 142.571 0.586925Z`,aspectRatio:{width:193,height:200},width:e,height:t}),blob27:({width:e,height:t})=>Q({path:`M112.602 54.9337C129.225 71.8646 155.391 78.9448 158.777 89.719C162.471 100.493 143.693 114.654 127.07 135.586C110.447 156.519 96.2866 184.224 71.0442 194.998C46.1096 205.465 10.4008 199.308 2.0893 178.375C-6.22223 157.443 12.5557 121.734 18.4045 92.1817C24.5612 62.6296 17.7889 38.9263 26.4082 21.9954C34.7197 5.06454 58.423 -5.40183 73.5069 2.9097C88.8986 10.9134 95.9788 38.0028 112.602 54.9337Z`,aspectRatio:{width:160,height:200},width:e,height:t}),blob28:({width:e,height:t})=>Q({path:`M125.281 68.5835C142.15 82.9923 165.344 90.021 181.862 108.998C198.028 127.624 207.516 158.902 192.405 166.634C177.293 174.716 137.581 159.605 112.629 156.442C87.326 152.928 77.1344 161.713 59.9142 165.579C43.0453 169.445 19.1478 168.391 11.7677 157.496C4.73907 146.25 14.2278 124.813 11.4163 94.2382C8.2534 63.6634 -6.85825 23.9514 3.68476 8.48836C14.2278 -7.32615 50.4254 1.10826 73.9715 16.2199C97.5175 31.683 108.412 54.1747 125.281 68.5835Z`,aspectRatio:{width:200,height:169},width:e,height:t}),blob29:({width:e,height:t})=>Q({path:`M162.987 10.2348C169.16 25.1809 154.864 58.6471 147.066 79.4417C139.268 100.236 138.293 108.359 134.719 114.532C131.47 120.706 125.297 124.93 119.448 143.45C113.6 161.97 107.426 194.461 98.004 199.335C88.5814 204.209 75.5849 181.14 55.7651 167.494C35.6203 153.522 8.65241 148.648 1.8292 135.327C-4.994 122.33 8.65241 100.561 20.0244 82.041C31.3964 63.5208 40.1691 48.2498 53.4906 35.5782C66.8122 22.9065 84.0326 13.159 106.452 6.33584C128.871 -0.812285 156.489 -4.71127 162.987 10.2348Z`,aspectRatio:{width:165,height:200},width:e,height:t}),blob3:({width:e,height:t})=>Q({path:`M158.095 64.2637C176.543 95.19 192.277 129.1 181.697 155.686C171.117 182.001 133.951 201.533 99.4982 199.905C64.7739 198.549 33.0338 176.032 15.4004 145.377C-2.23296 114.994 -5.75963 76.2002 10.2461 46.6303C26.2518 17.0605 61.5185 -3.557 89.732 0.512241C118.217 4.58149 139.377 33.0662 158.095 64.2637Z`,aspectRatio:{width:186,height:200},width:e,height:t}),blob30:({width:e,height:t})=>Q({path:`M146.076 34.4585C157.052 54.582 155.833 80.1936 164.675 100.622C173.212 121.355 191.201 136.905 189.372 149.711C187.542 162.212 165.285 171.969 146.99 175.018C129.001 178.372 114.671 174.713 103.39 175.018C92.1083 175.018 83.876 178.982 66.8015 186.299C49.7271 193.617 23.8105 204.288 14.3586 198.19C4.90665 191.787 11.6145 168.615 10.3949 147.882C8.87037 127.148 -0.581561 108.549 0.0282404 89.3407C0.638042 70.1319 11.6145 50.6182 28.384 32.934C44.8487 15.5546 67.4113 0.309578 89.974 0.00467694C112.537 -0.300224 135.099 14.335 146.076 34.4585Z`,aspectRatio:{width:190,height:200},width:e,height:t}),blob31:({width:e,height:t})=>Q({path:`M134.218 44.0392C153.568 36.4264 184.97 26.9105 195.755 33.2544C206.222 39.9156 195.755 62.1194 181.481 76.3933C166.89 90.35 148.175 96.0596 145.638 116.36C143.1 136.661 156.74 171.235 151.664 183.923C146.589 196.928 123.434 187.413 105.036 178.531C86.6388 169.967 73.3165 161.72 52.0643 158.548C30.812 155.058 1.62986 156.644 0.0438693 145.225C-1.22492 133.806 25.4197 109.382 29.2261 86.8609C32.7152 64.3398 13.6834 44.0392 11.7802 26.9105C9.877 9.46461 24.7853 -4.80928 42.5484 1.53467C59.9942 7.87863 79.9777 34.5232 93.6172 45.308C107.257 56.4099 114.869 51.3347 134.218 44.0392Z`,aspectRatio:{width:200,height:191},width:e,height:t}),blob32:({width:e,height:t})=>Q({path:`M200 100.339C200 149.831 145.763 197.966 95.5932 197.966C45.7627 197.966 0 149.831 0 100.339C0 50.8475 45.7627 0 95.5932 0C145.763 0 200 50.8475 200 100.339Z`,aspectRatio:{width:200,height:198},width:e,height:t}),blob4:({width:e,height:t})=>Q({path:`M183.427 38.712C198.21 63.2519 196.141 95.1833 189.341 126.523C182.836 157.863 171.305 188.908 150.609 197.482C130.208 205.76 100.642 192.16 69.8936 177.968C39.4405 164.072 7.80478 150.176 1.30024 128.593C-5.2043 107.01 13.718 77.7393 35.3012 51.7211C56.5888 25.9986 81.1287 3.23272 108.921 0.276112C137.009 -2.38484 168.349 14.4678 183.427 38.712Z`,aspectRatio:{width:195,height:200},width:e,height:t}),blob5:({width:e,height:t})=>Q({path:`M166.251 30.6913C183.816 48.5185 195.875 71.8512 199.021 98.8542C202.429 125.595 197.186 155.744 179.359 169.115C161.794 182.223 131.645 178.815 103.331 176.979C75.0171 175.144 48.8006 174.882 29.6625 161.512C10.7866 148.141 -0.748681 121.925 0.0378149 96.2326C0.824311 70.8025 14.1947 46.159 33.0706 28.3318C52.2087 10.5045 76.8522 -0.5064 100.971 0.0179307C125.091 0.804426 148.423 12.864 166.251 30.6913Z`,aspectRatio:{width:200,height:179},width:e,height:t}),blob6:({width:e,height:t})=>Q({path:`M149.146 50.5452C161.911 68.0278 171.901 81.9028 176.619 97.9979C181.336 114.37 180.781 133.241 173.011 149.891C165.519 166.541 151.366 180.693 133.051 189.851C114.736 199.008 92.2586 202.893 71.446 197.621C50.6334 192.348 30.9308 177.918 18.1658 158.216C5.12323 138.791 -0.981801 113.815 0.128204 87.7304C1.51571 61.6453 10.6733 34.1726 29.2658 17.5226C48.1359 1.14999 76.996 -4.40004 98.9186 3.6475C120.841 11.695 136.381 32.7851 149.146 50.5452Z`,aspectRatio:{width:180,height:200},width:e,height:t}),blob7:({width:e,height:t})=>Q({path:`M158.662 41.8295C178.593 57.8305 204.138 64.5677 213.402 79.7266C222.666 94.6047 215.367 118.466 203.015 135.028C190.383 151.871 172.698 161.977 156.416 168.434C140.134 174.89 124.975 177.697 104.483 185.277C83.9903 192.856 58.1642 205.208 44.9704 197.629C31.4959 190.33 31.2152 163.1 21.9514 138.116C12.9684 112.851 -4.71688 90.1132 1.17822 75.5158C7.35404 61.1991 36.8295 55.5847 58.7256 40.1452C80.9024 24.7056 95.4998 -0.278374 109.816 0.00234533C124.414 0.283064 138.45 25.8285 158.662 41.8295Z`,aspectRatio:{width:218,height:200},width:e,height:t}),blob8:({width:e,height:t})=>Q({path:`M153.53 11.0108C168.179 18.1858 181.931 29.5461 192.993 44.4939C203.755 59.4417 212.425 78.2759 210.631 96.5122C209.136 114.748 197.477 132.088 182.529 142.252C167.581 152.716 148.747 156.004 128.717 168.262C108.687 180.22 87.1622 201.147 69.8228 199.951C52.7823 198.456 39.6283 174.54 32.4533 153.015C25.2784 131.49 24.0826 112.357 16.6087 91.131C9.13477 70.2041 -4.31825 46.8855 1.36191 31.9377C7.04207 16.691 31.8554 9.51607 52.7823 5.33069C73.4103 0.846349 90.4507 -0.648433 106.594 0.248435C123.037 1.1453 138.882 4.13486 153.53 11.0108Z`,aspectRatio:{width:211,height:200},width:e,height:t}),blob9:({width:e,height:t})=>Q({path:`M140.289 20.2182C156.96 27.7956 176.661 32.0895 189.29 43.9608C201.667 55.5796 206.718 75.0283 202.424 91.6987C198.131 108.622 184.491 122.766 175.651 140.952C166.81 158.885 162.769 180.607 150.393 191.216C138.016 201.824 117.052 201.572 98.866 197.025C80.6802 192.479 65.2727 183.891 48.3497 175.808C31.4268 167.726 13.2409 160.148 5.1583 146.761C-2.67172 133.122 -0.398493 113.673 4.14797 96.7504C8.69444 80.08 15.5141 65.6828 23.3442 52.296C31.4268 38.6566 40.5197 25.775 52.6436 15.6717C65.0201 5.82101 80.6802 -1.50385 95.3299 0.264221C109.98 1.77971 123.619 12.6407 140.289 20.2182Z`,aspectRatio:{width:204,height:200},width:e,height:t})};function kD(e){return OD[e]||vD}function AD(e){let{subType:t}=e,n=e,r=kD(t);return r?function(e,t){let{width:n,height:r,fill:i,stroke:a,strokeWidth:o,dash:s}=e,c=(s||[]).map(e=>e*o),l=t(e),u=1,d=1;typeof l!=`string`&&(u=l.scaleX,d=l.scaleY,l=l.path);let f=`clip-${e.id||Math.random()}`;return`\n <svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${r}">\n <defs>\n <clipPath id="${f}">\n <path d="${l}" />\n </clipPath>\n </defs>\n\n \x3c!-- Path for the fill --\x3e\n <path d="${l}" fill="${i}" transform="scale(${u}, ${d})"/>\n\n \x3c!-- Path for the stroke, clipped by the star path --\x3e\n <path d="${l}" fill="none" stroke="${a}" stroke-width="${2*o}" clip-path="url(#${f})" transform="scale(${u}, ${d})" stroke-dasharray="${c.join(` `)}"/>\n </svg>\n `}(n,r):(console.error(`Polotno error: Can not convert ${e.subType} figure to svg.`),vD(n))}var jD={},MD=sa(({element:e,store:t})=>{let n=d.useRef(null),r=e.selectable||t.role===`admin`,i=Up(),a=t.selectedShapes.indexOf(e)>=0&&e.selectable,o=Math.min(e.strokeWidth,e.width/2,e.height/2),s=Math.max(0,Math.min(e.width/2,e.height/2,e.cornerRadius)),c=Pf(e,e.a.fill,`fill`),l=Object.assign(Object.assign({width:e.a.width,height:e.a.height},c),{cornerRadius:s,opacity:e.animated(`opacity`),shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,preventDefault:!i||a,hideInExport:!e.showInExport}),u=Pf(e,e.stroke,`stroke`),f=Object.assign(Object.assign({visible:o>0,x:o/2,y:o/2,width:e.a.width-o,height:e.a.height-o},u),{strokeWidth:o,cornerRadius:Math.max(0,s-o),dash:e.dash.map(e=>e*o),opacity:e.animated(`opacity`),hideInExport:!e.showInExport,listening:!1}),p=(m=e.subType,jD[m]||(jD[m]=(h=kD(m),sa(({element:e,fillProps:t,strokeProps:n})=>{let r=h({width:e.a.width,height:e.a.height,cornerRadius:e.cornerRadius}),i=1,a=1;typeof r!=`string`&&(i=r.scaleX,a=r.scaleY,r=r.path);let o=d.useRef(null);return d.createElement(d.Fragment,null,d.createElement(`Rect`,{width:e.width,height:e.height,fill:`transparent`}),d.createElement(`Path`,Object.assign({},t,{ref:o,data:r,scaleX:i,scaleY:a})),d.createElement(`Group`,{clipFunc:e=>{let t=o.current;if(t){var n=t.dataArray;e.beginPath();for(var r=0;r<n.length;r++){var i=n[r].command,a=n[r].points;switch(i){case`L`:e.lineTo(a[0],a[1]);break;case`M`:e.moveTo(a[0],a[1]);break;case`C`:e.bezierCurveTo(a[0],a[1],a[2],a[3],a[4],a[5]);break;case`Q`:e.quadraticCurveTo(a[0],a[1],a[2],a[3]);break;case`A`:var s=a[0],c=a[1],l=a[2],u=a[3],d=a[4],f=a[5],p=a[6],m=a[7],h=l>u?l:u,g=l>u?1:l/u,_=l>u?u/l:1;e.translate(s,c),e.rotate(p),e.scale(g,_),e.arc(0,0,h,d,d+f,!m),e.scale(1/g,1/_),e.rotate(-p),e.translate(-s,-c);break;case`z`:e.closePath()}}}},scaleX:i,scaleY:a},d.createElement(`Path`,Object.assign({},n,{x:0,y:0,data:r,strokeWidth:2*n.strokeWidth,dash:n.dash.map(e=>e)}))))}))),jD[m]||`Group`);var m,h;return d.createElement(d.Fragment,null,d.createElement(Kd,{ref:n,id:e.id,x:e.a.x,y:e.a.y,rotation:e.a.rotation,opacity:e.a.opacity,listening:r,draggable:i?e.draggable&&a:e.draggable,name:`element`,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onTransform:t=>{let n=t.target.scale();t.target.scaleX(1),t.target.scaleY(1),e.set({width:e.width*n.x,height:e.height*n.y,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation()})}},d.createElement(p,{element:e,fillProps:l,strokeProps:f})))}),ND=r((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.loop=e.conditional=e.parse=void 0,e.parse=function e(t,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:r;if(Array.isArray(n))n.forEach(function(n){return e(t,n,r,i)});else if(typeof n==`function`)n(t,r,i,e);else{var a=Object.keys(n)[0];Array.isArray(n[a])?(i[a]={},e(t,n[a],r,i[a])):i[a]=n[a](t,r,i,e)}return r},e.conditional=function(e,t){return function(n,r,i,a){t(n,r,i)&&a(n,e,r,i)}},e.loop=function(e,t){return function(n,r,i,a){for(var o=[],s=n.pos;t(n,r,i);){var c={};if(a(n,e,r,c),n.pos===s)break;s=n.pos,o.push(c)}return o}}})),PD=r((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.readBits=e.readArray=e.readUnsigned=e.readString=e.peekBytes=e.readBytes=e.peekByte=e.readByte=e.buildStream=void 0,e.buildStream=function(e){return{data:e,pos:0}};var t=function(){return function(e){return e.data[e.pos++]}};e.readByte=t,e.peekByte=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return function(t){return t.data[t.pos+e]}};var n=function(e){return function(t){return t.data.subarray(t.pos,t.pos+=e)}};e.readBytes=n,e.peekBytes=function(e){return function(t){return t.data.subarray(t.pos,t.pos+e)}},e.readString=function(e){return function(t){return Array.from(n(e)(t)).map(function(e){return String.fromCharCode(e)}).join(``)}},e.readUnsigned=function(e){return function(t){var r=n(2)(t);return e?(r[1]<<8)+r[0]:(r[0]<<8)+r[1]}},e.readArray=function(e,t){return function(r,i,a){for(var o=typeof t==`function`?t(r,i,a):t,s=n(e),c=Array(o),l=0;l<o;l++)c[l]=s(r);return c}};var r=function(e,t,n){for(var r=0,i=0;i<n;i++)r+=e[t+i]&&2**(n-i-1);return r};e.readBits=function(e){return function(n){for(var i=t()(n),a=Array(8),o=0;o<8;o++)a[7-o]=!!(i&1<<o);return Object.keys(e).reduce(function(t,n){var i=e[n];return i.length?t[n]=r(a,i.index,i.length):t[n]=a[i.index],t},{})}}})),FD=r((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.default=void 0;var t=ND(),n=PD(),r={blocks:function(e){for(var t=0,r=[],i=e.data.length,a=0,o=(0,n.readByte)()(e);o!==t&&o;o=(0,n.readByte)()(e)){if(e.pos+o>=i){var s=i-e.pos;r.push((0,n.readBytes)(s)(e)),a+=s;break}r.push((0,n.readBytes)(o)(e)),a+=o}for(var c=new Uint8Array(a),l=0,u=0;u<r.length;u++)c.set(r[u],l),l+=r[u].length;return c}},i=(0,t.conditional)({gce:[{codes:(0,n.readBytes)(2)},{byteSize:(0,n.readByte)()},{extras:(0,n.readBits)({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:(0,n.readUnsigned)(!0)},{transparentColorIndex:(0,n.readByte)()},{terminator:(0,n.readByte)()}]},function(e){var t=(0,n.peekBytes)(2)(e);return t[0]===33&&t[1]===249}),a=(0,t.conditional)({image:[{code:(0,n.readByte)()},{descriptor:[{left:(0,n.readUnsigned)(!0)},{top:(0,n.readUnsigned)(!0)},{width:(0,n.readUnsigned)(!0)},{height:(0,n.readUnsigned)(!0)},{lct:(0,n.readBits)({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},(0,t.conditional)({lct:(0,n.readArray)(3,function(e,t,n){return 2**(n.descriptor.lct.size+1)})},function(e,t,n){return n.descriptor.lct.exists}),{data:[{minCodeSize:(0,n.readByte)()},r]}]},function(e){return(0,n.peekByte)()(e)===44}),o=(0,t.conditional)({text:[{codes:(0,n.readBytes)(2)},{blockSize:(0,n.readByte)()},{preData:function(e,t,r){return(0,n.readBytes)(r.text.blockSize)(e)}},r]},function(e){var t=(0,n.peekBytes)(2)(e);return t[0]===33&&t[1]===1}),s=(0,t.conditional)({application:[{codes:(0,n.readBytes)(2)},{blockSize:(0,n.readByte)()},{id:function(e,t,r){return(0,n.readString)(r.blockSize)(e)}},r]},function(e){var t=(0,n.peekBytes)(2)(e);return t[0]===33&&t[1]===255}),c=(0,t.conditional)({comment:[{codes:(0,n.readBytes)(2)},r]},function(e){var t=(0,n.peekBytes)(2)(e);return t[0]===33&&t[1]===254});e.default=[{header:[{signature:(0,n.readString)(3)},{version:(0,n.readString)(3)}]},{lsd:[{width:(0,n.readUnsigned)(!0)},{height:(0,n.readUnsigned)(!0)},{gct:(0,n.readBits)({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:(0,n.readByte)()},{pixelAspectRatio:(0,n.readByte)()}]},(0,t.conditional)({gct:(0,n.readArray)(3,function(e,t){return 2**(t.lsd.gct.size+1)})},function(e,t){return t.lsd.gct.exists}),{frames:(0,t.loop)([i,s,c,a,o],function(e){var t=(0,n.peekByte)()(e);return t===33||t===44})}]})),ID=r((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.deinterlace=void 0,e.deinterlace=function(e,t){for(var n=Array(e.length),r=e.length/t,i=function(r,i){var a=e.slice(i*t,(i+1)*t);n.splice.apply(n,[r*t,t].concat(a))},a=[0,4,2,1],o=[8,8,4,2],s=0,c=0;c<4;c++)for(var l=a[c];l<r;l+=o[c])i(l,s),s++;return n}})),LD=r((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.lzw=void 0,e.lzw=function(e,t,n){var r=4096,i=-1,a=n,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S=Array(n),C=Array(r),w=Array(r),T=Array(r+1);for(_=e,s=1<<_,u=s+1,o=s+2,f=i,l=_+1,c=(1<<l)-1,m=0;m<s;m++)C[m]=0,w[m]=m;var g=p=v=y=x=b=0,p,v,y,x,b;for(h=0;h<a;){if(y===0){if(p<l){g+=t[b]<<p,p+=8,b++;continue}if(m=g&c,g>>=l,p-=l,m>o||m==u)break;if(m==s){l=_+1,c=(1<<l)-1,o=s+2,f=i;continue}if(f==i){T[y++]=w[m],f=m,v=m;continue}for(d=m,m==o&&(T[y++]=v,m=f);m>s;)T[y++]=w[m],m=C[m];v=w[m]&255,T[y++]=v,o<r&&(C[o]=f,w[o]=v,o++,(o&c)===0&&o<r&&(l++,c+=o)),f=d}y--,S[x++]=T[y],h++}for(h=x;h<a;h++)S[h]=0;return S}})),RD=r((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.decompressFrames=e.decompressFrame=e.parseGIF=void 0;var t=o(FD()),n=ND(),r=PD(),i=ID(),a=LD();function o(e){return e&&e.__esModule?e:{default:e}}e.parseGIF=function(e){var i=new Uint8Array(e);return(0,n.parse)((0,r.buildStream)(i),t.default)};var s=function(e){for(var t=e.pixels.length,n=new Uint8ClampedArray(t*4),r=0;r<t;r++){var i=r*4,a=e.pixels[r],o=e.colorTable[a]||[0,0,0];n[i]=o[0],n[i+1]=o[1],n[i+2]=o[2],n[i+3]=a===e.transparentIndex?0:255}return n},c=function(e,t,n){if(!e.image){console.warn(`gif frame does not have associated image.`);return}var r=e.image,o=r.descriptor.width*r.descriptor.height,c=(0,a.lzw)(r.data.minCodeSize,r.data.blocks,o);r.descriptor.lct.interlaced&&(c=(0,i.deinterlace)(c,r.descriptor.width));var l={pixels:c,dims:{top:e.image.descriptor.top,left:e.image.descriptor.left,width:e.image.descriptor.width,height:e.image.descriptor.height}};return r.descriptor.lct&&r.descriptor.lct.exists?l.colorTable=r.lct:l.colorTable=t,e.gce&&(l.delay=(e.gce.delay||10)*10,l.disposalType=e.gce.extras.disposal,e.gce.extras.transparentColorGiven&&(l.transparentIndex=e.gce.transparentColorIndex)),n&&(l.patch=s(l)),l};e.decompressFrame=c,e.decompressFrames=function(e,t){return e.frames.filter(function(e){return e.image}).map(function(n){return c(n,e.gct,t)})}}))();function zD(e,t,n){let r=t.getContext(`2d`),i=n.getContext(`2d`);if(!r||!i)return;e.disposalType===2&&r.clearRect(0,0,t.width,t.height),n.width=e.width,n.height=e.height;let a=i.createImageData(e.width,e.height);a.data.set(e.patch),i.putImageData(a,0,0),r.drawImage(n,e.left,e.top)}var BD=sa(({element:e})=>{let t=Math.min(30,e.width/4,e.height/4),n=d.useRef(null);return d.useEffect(()=>{let e=n.current;if(!e)return;let t=new Du.Animation(t=>{e.rotate((t?.timeDiff||0)/2)},e.getLayer());return t.start(),()=>{t.stop()}},[]),d.createElement(Kd,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},d.createElement(Jd,{width:e.width,height:e.height,fill:`rgba(124, 173, 212, 0.8)`}),d.createElement(`Arc`,{ref:n,x:e.width/2,y:e.height/2,fill:`white`,outerRadius:Math.abs(t),innerRadius:Math.max(1,t-5),angle:270}))}),VD=sa(({element:e})=>{let t=Math.max(10,Math.min(30,e.width/22));return d.createElement(Kd,{x:e.a.x,y:e.a.y,rotation:e.a.rotation,listening:!1,opacity:e.a.opacity,hideInExport:!e.showInExport},d.createElement(Jd,{width:e.width,height:e.height,fill:`rgba(223, 102, 102, 0.8)`}),d.createElement(Zd,{text:`Cannot load the GIF...`,fontSize:t,width:e.width,height:e.height,align:`center`,fill:`white`,verticalAlign:`middle`,padding:5}))}),HD=sa(({element:e,store:t})=>{let[n,r]=d.useState(!1),i=t.selectedShapes.indexOf(e)>=0&&e.selectable,a=d.useRef(null),o=d.useRef(),[s,c,l,u]=function(e){let[t,n]=d.useState([]),[r,i]=d.useState(0),[a,o]=d.useState(`loading`),[s,c]=d.useState({width:0,height:0});return d.useEffect(()=>{(async()=>{try{let t=(0,RD.parseGIF)(await(await fetch(e)).arrayBuffer()),r=(0,RD.decompressFrames)(t,!0),a=t.lsd.width,s=t.lsd.height;c({width:a,height:s});let l=r.map(e=>({patch:new Uint8ClampedArray(e.patch),delay:e.delay,width:e.dims.width,height:e.dims.height,left:e.dims.left,top:e.dims.top,disposalType:e.disposalType})),u=l.reduce((e,t)=>e+t.delay,0);n(l),i(u),o(`loaded`)}catch(e){console.error(`Failed to load GIF:`,e),o(`failed`)}})()},[e]),[t,r,s,a]}(e.src);mv(u,e.src,e.id),d.useEffect(()=>(o.current=document.createElement(`canvas`),()=>{o.current&&Du.Util.releaseCanvas(o.current)}),[]),d.useEffect(()=>{if(u===`loaded`&&o.current&&(o.current.width=l.width,o.current.height=l.height,s.length>0)){let e=o.current.getContext(`2d`);if(e){e.clearRect(0,0,l.width,l.height);let t=document.createElement(`canvas`);zD(s[0],o.current,t)}}},[l,u,s]),d.useEffect(()=>{if(!s.length||!o.current)return;let n=o.current;n.width=l.width,n.height=l.height;let r=document.createElement(`canvas`),i=n.getContext(`2d`);i&&i.clearRect(0,0,n.width,n.height);let u=-1;zD(s[0],n,r),y(),u=0;let d=e=>{let t=(e=>{let t=e%c,n=0;for(let e=0;e<s.length;e++)if(n+=s[e].delay,n>t)return e;return 0})(e);t!==u&&(zD(s[t],n,r),y(),a.current.getLayer().draw(),u=t)};if(t.isPlaying||e.page._exportingOrRendering)return Gn(()=>{d(t.currentTime-e.page.startTime)});{let e=window.setInterval(()=>{d(t.currentTime||performance.now())},16);return()=>{clearInterval(e)}}},[t.isPlaying,s,c,e.page._exportingOrRendering]),d.useEffect(()=>{c&&t.history.ignore(()=>{e.set({duration:c})})},[c]);let{cropX:f,cropY:p,cropWidth:m,cropHeight:h}=e;u!==`loaded`&&(f=p=0,m=h=1);let g={x:l.width*f,y:l.height*p,width:l.width*m,height:l.height*h},_=e.cornerRadius??0,[v,y]=uD(e,o.current,g,t._elementsPixelRatio,_,n||e._cropModeEnabled);d.useLayoutEffect(()=>{if(!n&&!e._cropModeEnabled&&a.current)return Hp(a.current,e),Gn(()=>{Hp(a.current,e)},{delay:100})},[o.current,n,m,h,e._cropModeEnabled,l.width,l.height]);let b=u===`loading`,x=u===`failed`,S=b||x?0:e.a.opacity;Rf(a,S);let C=e.selectable||t.role===`admin`,w=Up();return d.createElement(d.Fragment,null,b&&d.createElement(BD,{element:e}),x&&d.createElement(VD,{element:e}),d.createElement(Xd,{ref:a,name:`element`,id:e.id,image:v,x:e.a.x,y:e.a.y,width:e.a.width||1,height:e.a.height||1,rotation:e.a.rotation,opacity:S,shadowEnabled:e.shadowEnabled,shadowBlur:e.shadowBlur,shadowOffsetX:e.shadowOffsetX,shadowOffsetY:e.shadowOffsetY,shadowColor:e.shadowColor,shadowOpacity:e.shadowOpacity,customCrop:g,listening:C,draggable:w?e.draggable&&i:e.draggable,preventDefault:!w||i,hideInExport:!e.showInExport,onDragMove:t=>{e.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{e.set({x:t.target.x(),y:t.target.y()})},onTransformStart:()=>r(!0),onTransform:t=>{let n=t.currentTarget,r=Math.abs(n.scaleX()-1)<1e-7?1:n.scaleX(),i=Math.abs(n.scaleY()-1)<1e-7?1:n.scaleY();n.scaleX(1),n.scaleY(1),e.set({x:n.x(),y:n.y(),width:n.width()*r,height:n.height()*i,rotation:n.rotation()})},onTransformEnd:()=>r(!1)}),d.createElement(Jd,{x:e.a.x,y:e.a.y,width:Math.max(e.a.width-e.borderSize,0),height:Math.max(e.a.height-e.borderSize,0),opacity:S,offsetX:-e.borderSize/2,offsetY:-e.borderSize/2,stroke:e.borderColor,strokeWidth:e.borderSize,listening:!1,visible:!!e.borderSize,rotation:e.rotation,cornerRadius:Math.max(0,_-e.borderSize),hideInExport:!e.showInExport}))}),UD=sa(({element:e,store:t})=>{let n=d.useRef(null),r=d.useRef(null),i=e.selectable||t.role===`admin`,a=Up(),o=t.selectedShapes.indexOf(e)>=0&&e.selectable,s=e._focusedCellIds.length>0,c=e.editingCell;d.useEffect(()=>{o||e.clearCellFocus()},[o]);let l=c?._editModeEnabled;d.useEffect(()=>{e._editingCellId&&c&&!c._editModeEnabled&&e.exitCellEdit()},[l]),d.useEffect(()=>{s&&!e._editingCellId&&setTimeout(()=>r.current?.focus(),0)},[s,e._editingCellId]),d.useEffect(()=>Gn(()=>{e._fitRowsToContent&&t.history.ignore(()=>{e._applyFitRowsToContent()})}),[e,t]);let u=t=>{let r=t.target.getStage();if(!r)return;let i=r.getPointerPosition();if(!i)return;let a=n.current;if(!a)return;let o=a.getAbsoluteTransform().copy().invert().point(i);for(let t of e.visibleCells){let n=e.getCellRect(t.row,t.col,t.rowSpan,t.colSpan);if(o.x>=n.x&&o.x<=n.x+n.width&&o.y>=n.y&&o.y<=n.y+n.height)return t}},f=(e,t)=>e===`dashed`?[4*t,2*t]:e===`dotted`?[t,t]:void 0,p=[];for(let t of e.visibleCells){let n=e.getCellRect(t.row,t.col,t.rowSpan,t.colSpan);if(t.row===0){let e=t.getEffectiveBorder(`top`);e.style!==`none`&&e.width>0&&p.push(d.createElement(`Line`,{key:`bt-${t.id}`,points:[n.x,n.y+e.width/2,n.x+n.width,n.y+e.width/2],stroke:e.color,strokeWidth:e.width,dash:f(e.style,e.width),listening:!1}))}if(t.col===0){let e=t.getEffectiveBorder(`left`);e.style!==`none`&&e.width>0&&p.push(d.createElement(`Line`,{key:`bl-${t.id}`,points:[n.x+e.width/2,n.y,n.x+e.width/2,n.y+n.height],stroke:e.color,strokeWidth:e.width,dash:f(e.style,e.width),listening:!1}))}{let e=t.getEffectiveBorder(`bottom`);e.style!==`none`&&e.width>0&&p.push(d.createElement(`Line`,{key:`bb-${t.id}`,points:[n.x,n.y+n.height-e.width/2,n.x+n.width,n.y+n.height-e.width/2],stroke:e.color,strokeWidth:e.width,dash:f(e.style,e.width),listening:!1}))}{let e=t.getEffectiveBorder(`right`);e.style!==`none`&&e.width>0&&p.push(d.createElement(`Line`,{key:`br-${t.id}`,points:[n.x+n.width-e.width/2,n.y,n.x+n.width-e.width/2,n.y+n.height],stroke:e.color,strokeWidth:e.width,dash:f(e.style,e.width),listening:!1}))}}return d.createElement(d.Fragment,null,d.createElement(Jd,{id:e.id,name:`element`,x:e.a.x,y:e.a.y,rotation:e.a.rotation,width:e.a.width,height:e.a.height,fill:`transparent`,opacity:e.a.opacity,hideInExport:!e.showInExport,listening:i,draggable:a?e.draggable&&o:e.draggable,onClick:t=>{if(!o||e.locked||!e.contentEditable)return;let n=u(t);n&&(t.evt.shiftKey&&s?(t.cancelBubble=!0,e.focusCellRange(n.row,n.col)):e.focusCell(n.id))},onDblClick:t=>{if(!o||e.locked||!e.contentEditable)return;let n=u(t);n&&e.enterCellEdit(n.id)},onDragMove:t=>{var r;let i=t.target;e.set({x:i.x(),y:i.y()}),(r=n.current)==null||r.position({x:i.x(),y:i.y()})},onDragEnd:t=>{let n=t.target;e.set({x:n.x(),y:n.y()})},onTransformStart:()=>{e._setIsTransforming(!0)},onTransformEnd:()=>{e._setIsTransforming(!1),e._resetBaseRowHeights()},onTransform:t=>{var r,i;let a=t.target,o=a.scaleX(),s=a.scaleY();a.scaleX(1),a.scaleY(1);let c=e.width*o,l=e.height*s;a.width(c),a.height(l);let u=a.x(),d=a.y(),f=a.rotation();(r=n.current)==null||r.position({x:u,y:d}),(i=n.current)==null||i.rotation(f),e.set({width:c,height:l,x:u,y:d,rotation:f})}}),d.createElement(Kd,{ref:n,x:e.a.x,y:e.a.y,rotation:e.a.rotation,opacity:e.a.opacity,hideInExport:!e.showInExport,scaleX:e.a.width/e.width,scaleY:e.a.height/e.height},e.visibleCells.map(t=>{let n=e.getCellRect(t.row,t.col,t.rowSpan,t.colSpan);return t.cellBackground===`transparent`?null:d.createElement(Jd,{key:`bg-${t.id}`,x:n.x,y:n.y,width:n.width,height:n.height,fill:t.cellBackground,listening:!1})}),p,e.visibleCells.map(e=>d.createElement(F_,{key:`text-${e.id}`,element:e,store:t})),e._focusedCellIds.map(t=>{let n=e.cells.find(e=>e.id===t);if(!n)return null;let r=e.getCellRect(n.row,n.col,n.rowSpan,n.colSpan);return d.createElement(Jd,{key:`focus-${t}`,x:r.x,y:r.y,width:r.width,height:r.height,fill:`rgba(13, 131, 221, 0.1)`,stroke:`#0d83dd`,strokeWidth:2,listening:!1})}),s&&!c&&d.createElement(cf,null,d.createElement(`input`,{ref:r,style:{position:`absolute`,opacity:0,width:`1px`,height:`1px`,pointerEvents:`none`},readOnly:!0})),o&&!c&&!t.isPlaying&&(()=>{let n=[],r=0;for(let i=0;i<e.cols-1;i++){r+=e.colWidths[i]*e.a.width;let a=r,o=i;n.push(d.createElement(`Line`,{key:`col-resize-${i}`,x:a,points:[0,0,0,e.a.height],stroke:`transparent`,strokeWidth:1,hitStrokeWidth:16,draggable:!0,onMouseEnter:e=>{let t=e.target.getStage()?.container();t&&(t.style.cursor=`col-resize`)},onMouseLeave:e=>{let t=e.target.getStage()?.container();t&&(t.style.cursor=``)},onDragStart:e=>{e.cancelBubble=!0,t.history.startTransaction()},onDragMove:t=>{t.cancelBubble=!0;let n=t.target,r=(n.x()-a)/e.width;n.x(a),e.resizeColumn(o,r)},onDragEnd:e=>{e.cancelBubble=!0,e.target.x(a),t.history.endTransaction()}}))}return n})(),o&&!c&&!t.isPlaying&&(()=>{let n=[],r=0;for(let i=0;i<e.rows-1;i++){r+=e.rowHeights[i]*e.a.height;let a=r,o=i;n.push(d.createElement(`Line`,{key:`row-resize-${i}`,y:a,points:[0,0,e.a.width,0],stroke:`transparent`,strokeWidth:1,hitStrokeWidth:16,draggable:!0,onMouseEnter:e=>{let t=e.target.getStage()?.container();t&&(t.style.cursor=`row-resize`)},onMouseLeave:e=>{let t=e.target.getStage()?.container();t&&(t.style.cursor=``)},onDragStart:n=>{n.cancelBubble=!0,e._setIsResizingRows(!0),t.history.startTransaction()},onDragMove:t=>{t.cancelBubble=!0;let n=t.target,r=(n.y()-a)/e.height;n.y(a),e.resizeRow(o,r)},onDragEnd:n=>{n.cancelBubble=!0,n.target.y(a),e._setIsResizingRows(!1),e._resetBaseRowHeights(),t.history.endTransaction()}}))}return n})()))}),WD={stroke:`rgb(0, 161, 255)`,strokeWidth:2},GD=sa(({element:e})=>d.createElement(Jd,Object.assign({name:`highlighter`,x:e.a.x,y:e.a.y,rotation:e.a.rotation,width:e.a.width,height:e.a.height,listening:!1,strokeScaleEnabled:!1},WD))),KD=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+=`-`:e+=`_`,e),``),qD=function(e,t){if(e===t)return!0;if(typeof e==`object`&&e&&typeof t==`object`&&t){if(Object.keys(e).length!=Object.keys(t).length)return!1;for(var n in e)if(!t.hasOwnProperty(n)||!qD(e[n],t[n]))return!1;return!0}return!1};Object.assign(q);var JD=q.model(`UndoManager`,{history:q.array(q.frozen()),undoIdx:-1,targetPath:``}).views(e=>({get canUndo(){return e.undoIdx>0},get canRedo(){return e.undoIdx<e.history.length-1}})).actions(e=>{let t,n,r=!1,i=null,a=0,o=0,s=()=>o>0;function c(){let e=am(t);return{pages:e.pages,width:e.width,height:e.height,custom:e.custom,audios:e.audios}}function l(e){let n=!qD(t.pages.map(e=>e.id),e.pages.map(e=>e.id)),r=!qD(t.custom,e.custom);n?im(t.pages,e.pages):t.pages.forEach((t,n)=>{im(t,e.pages[n])}),r&&t.set({custom:e.custom}),t.setSize(e.width,e.height)}let u={startTransaction(){o++},endTransaction(e){o--,e||u.requestAddState(c())},async ignore(e,t=!1,n=!1){n&&await new Promise(e=>setTimeout(e,10));let r=!!a;a&&u.addUndoState();let i=s();u.startTransaction();let c=o;try{await e()}catch(e){setTimeout(()=>{throw e})}let l=c!==o,d=!l;u.endTransaction(d),t||i&&!r||u.replaceState(),l||(clearTimeout(a),a=0)},async transaction(e){await u.ignore(e,!0),u.addUndoState()},requestAddState(e){i=e,a||s()||(r?r=!1:a=setTimeout(()=>{a=0,clearTimeout(a),s()||u.addUndoState()},100))},addUndoState(){if(r){r=!1;return}let t=e.history[e.undoIdx];!qD(i,t)&&(clearTimeout(a),a=0,e.history.splice(e.undoIdx+1),e.history.push(i),e.undoIdx=e.history.length-1)},afterCreate(){if(t=dm(e,`..`),!t)throw Error("Failed to find target store for UndoManager. Please provide `targetPath` property, or a `targetStore` in the environment");n=nm(t,()=>{u.requestAddState(c())}),e.history.length===0&&u.requestAddState(c())},clear(){clearTimeout(a),a=0,e.history.splice(0,e.history.length),e.undoIdx=-1,u.addUndoState()},beforeDestroy(){n()},undo(){a&&u.addUndoState(),s()?l(e.history[e.undoIdx]):e.canUndo?(e.undoIdx--,r=!0,l(e.history[e.undoIdx])):console.warn("No undo history. Please check `store.history.canUndo` before calling undo action.")},redo(){a&&u.addUndoState(),e.canRedo?(e.undoIdx++,r=!0,l(e.history[e.undoIdx])):console.warn("No redo history. Please check `store.history.canRedo` before calling redo action.")},replaceState(){e.history[e.undoIdx]=c()}};return u});async function YD(e,t){let n=await(await fetch(e)).blob(),r=document.createElement(`a`),i=URL.createObjectURL(n);r.href=i,r.download=t,document.body.appendChild(r),r.click(),setTimeout(function(){document.body.removeChild(r),window.URL.revokeObjectURL(i)},0)}var XD=null;function ZD(){return window.jspdf?.jsPDF?Promise.resolve(window.jspdf.jsPDF):XD||(typeof window.__polotnoLoadJspdf==`function`?(XD=window.__polotnoLoadJspdf().then(e=>e?.jsPDF||e),XD):(XD=new Promise(e=>{var t=document.createElement(`script`);t.onload=function(){e(window.jspdf.jsPDF)},t.src=`https://cdnjs.cloudflare.com/ajax/libs/jspdf/3.0.1/jspdf.umd.min.js`,document.head.appendChild(t)}),XD))}function QD(){return window.GIF?Promise.resolve(window.GIF):new Promise(e=>{var t=document.createElement(`script`);t.onload=function(){e(window.GIF)},t.src=`https://cdnjs.cloudflare.com/ajax/libs/gif.js/0.2.0/gif.js`,document.head.appendChild(t)})}async function $D({width:e,height:t}){return new(await(QD()))({workers:4,width:e,height:t,workerScript:URL.createObjectURL(new Blob([`// gif.worker.js 0.2.0 - https://github.com/jnordberg/gif.js
284
284
  (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){var NeuQuant=require("./TypedNeuQuant.js");var LZWEncoder=require("./LZWEncoder.js");function ByteArray(){this.page=-1;this.pages=[];this.newPage()}ByteArray.pageSize=4096;ByteArray.charMap={};for(var i=0;i<256;i++)ByteArray.charMap[i]=String.fromCharCode(i);ByteArray.prototype.newPage=function(){this.pages[++this.page]=new Uint8Array(ByteArray.pageSize);this.cursor=0};ByteArray.prototype.getData=function(){var rv="";for(var p=0;p<this.pages.length;p++){for(var i=0;i<ByteArray.pageSize;i++){rv+=ByteArray.charMap[this.pages[p][i]]}}return rv};ByteArray.prototype.writeByte=function(val){if(this.cursor>=ByteArray.pageSize)this.newPage();this.pages[this.page][this.cursor++]=val};ByteArray.prototype.writeUTFBytes=function(string){for(var l=string.length,i=0;i<l;i++)this.writeByte(string.charCodeAt(i))};ByteArray.prototype.writeBytes=function(array,offset,length){for(var l=length||array.length,i=offset||0;i<l;i++)this.writeByte(array[i])};function GIFEncoder(width,height){this.width=~~width;this.height=~~height;this.transparent=null;this.transIndex=0;this.repeat=-1;this.delay=0;this.image=null;this.pixels=null;this.indexedPixels=null;this.colorDepth=null;this.colorTab=null;this.neuQuant=null;this.usedEntry=new Array;this.palSize=7;this.dispose=-1;this.firstFrame=true;this.sample=10;this.dither=false;this.globalPalette=false;this.out=new ByteArray}GIFEncoder.prototype.setDelay=function(milliseconds){this.delay=Math.round(milliseconds/10)};GIFEncoder.prototype.setFrameRate=function(fps){this.delay=Math.round(100/fps)};GIFEncoder.prototype.setDispose=function(disposalCode){if(disposalCode>=0)this.dispose=disposalCode};GIFEncoder.prototype.setRepeat=function(repeat){this.repeat=repeat};GIFEncoder.prototype.setTransparent=function(color){this.transparent=color};GIFEncoder.prototype.addFrame=function(imageData){this.image=imageData;this.colorTab=this.globalPalette&&this.globalPalette.slice?this.globalPalette:null;this.getImagePixels();this.analyzePixels();if(this.globalPalette===true)this.globalPalette=this.colorTab;if(this.firstFrame){this.writeLSD();this.writePalette();if(this.repeat>=0){this.writeNetscapeExt()}}this.writeGraphicCtrlExt();this.writeImageDesc();if(!this.firstFrame&&!this.globalPalette)this.writePalette();this.writePixels();this.firstFrame=false};GIFEncoder.prototype.finish=function(){this.out.writeByte(59)};GIFEncoder.prototype.setQuality=function(quality){if(quality<1)quality=1;this.sample=quality};GIFEncoder.prototype.setDither=function(dither){if(dither===true)dither="FloydSteinberg";this.dither=dither};GIFEncoder.prototype.setGlobalPalette=function(palette){this.globalPalette=palette};GIFEncoder.prototype.getGlobalPalette=function(){return this.globalPalette&&this.globalPalette.slice&&this.globalPalette.slice(0)||this.globalPalette};GIFEncoder.prototype.writeHeader=function(){this.out.writeUTFBytes("GIF89a")};GIFEncoder.prototype.analyzePixels=function(){if(!this.colorTab){this.neuQuant=new NeuQuant(this.pixels,this.sample);this.neuQuant.buildColormap();this.colorTab=this.neuQuant.getColormap()}if(this.dither){this.ditherPixels(this.dither.replace("-serpentine",""),this.dither.match(/-serpentine/)!==null)}else{this.indexPixels()}this.pixels=null;this.colorDepth=8;this.palSize=7;if(this.transparent!==null){this.transIndex=this.findClosest(this.transparent,true)}};GIFEncoder.prototype.indexPixels=function(imgq){var nPix=this.pixels.length/3;this.indexedPixels=new Uint8Array(nPix);var k=0;for(var j=0;j<nPix;j++){var index=this.findClosestRGB(this.pixels[k++]&255,this.pixels[k++]&255,this.pixels[k++]&255);this.usedEntry[index]=true;this.indexedPixels[j]=index}};GIFEncoder.prototype.ditherPixels=function(kernel,serpentine){var kernels={FalseFloydSteinberg:[[3/8,1,0],[3/8,0,1],[2/8,1,1]],FloydSteinberg:[[7/16,1,0],[3/16,-1,1],[5/16,0,1],[1/16,1,1]],Stucki:[[8/42,1,0],[4/42,2,0],[2/42,-2,1],[4/42,-1,1],[8/42,0,1],[4/42,1,1],[2/42,2,1],[1/42,-2,2],[2/42,-1,2],[4/42,0,2],[2/42,1,2],[1/42,2,2]],Atkinson:[[1/8,1,0],[1/8,2,0],[1/8,-1,1],[1/8,0,1],[1/8,1,1],[1/8,0,2]]};if(!kernel||!kernels[kernel]){throw"Unknown dithering kernel: "+kernel}var ds=kernels[kernel];var index=0,height=this.height,width=this.width,data=this.pixels;var direction=serpentine?-1:1;this.indexedPixels=new Uint8Array(this.pixels.length/3);for(var y=0;y<height;y++){if(serpentine)direction=direction*-1;for(var x=direction==1?0:width-1,xend=direction==1?width:0;x!==xend;x+=direction){index=y*width+x;var idx=index*3;var r1=data[idx];var g1=data[idx+1];var b1=data[idx+2];idx=this.findClosestRGB(r1,g1,b1);this.usedEntry[idx]=true;this.indexedPixels[index]=idx;idx*=3;var r2=this.colorTab[idx];var g2=this.colorTab[idx+1];var b2=this.colorTab[idx+2];var er=r1-r2;var eg=g1-g2;var eb=b1-b2;for(var i=direction==1?0:ds.length-1,end=direction==1?ds.length:0;i!==end;i+=direction){var x1=ds[i][1];var y1=ds[i][2];if(x1+x>=0&&x1+x<width&&y1+y>=0&&y1+y<height){var d=ds[i][0];idx=index+x1+y1*width;idx*=3;data[idx]=Math.max(0,Math.min(255,data[idx]+er*d));data[idx+1]=Math.max(0,Math.min(255,data[idx+1]+eg*d));data[idx+2]=Math.max(0,Math.min(255,data[idx+2]+eb*d))}}}}};GIFEncoder.prototype.findClosest=function(c,used){return this.findClosestRGB((c&16711680)>>16,(c&65280)>>8,c&255,used)};GIFEncoder.prototype.findClosestRGB=function(r,g,b,used){if(this.colorTab===null)return-1;if(this.neuQuant&&!used){return this.neuQuant.lookupRGB(r,g,b)}var c=b|g<<8|r<<16;var minpos=0;var dmin=256*256*256;var len=this.colorTab.length;for(var i=0,index=0;i<len;index++){var dr=r-(this.colorTab[i++]&255);var dg=g-(this.colorTab[i++]&255);var db=b-(this.colorTab[i++]&255);var d=dr*dr+dg*dg+db*db;if((!used||this.usedEntry[index])&&d<dmin){dmin=d;minpos=index}}return minpos};GIFEncoder.prototype.getImagePixels=function(){var w=this.width;var h=this.height;this.pixels=new Uint8Array(w*h*3);var data=this.image;var srcPos=0;var count=0;for(var i=0;i<h;i++){for(var j=0;j<w;j++){this.pixels[count++]=data[srcPos++];this.pixels[count++]=data[srcPos++];this.pixels[count++]=data[srcPos++];srcPos++}}};GIFEncoder.prototype.writeGraphicCtrlExt=function(){this.out.writeByte(33);this.out.writeByte(249);this.out.writeByte(4);var transp,disp;if(this.transparent===null){transp=0;disp=0}else{transp=1;disp=2}if(this.dispose>=0){disp=dispose&7}disp<<=2;this.out.writeByte(0|disp|0|transp);this.writeShort(this.delay);this.out.writeByte(this.transIndex);this.out.writeByte(0)};GIFEncoder.prototype.writeImageDesc=function(){this.out.writeByte(44);this.writeShort(0);this.writeShort(0);this.writeShort(this.width);this.writeShort(this.height);if(this.firstFrame||this.globalPalette){this.out.writeByte(0)}else{this.out.writeByte(128|0|0|0|this.palSize)}};GIFEncoder.prototype.writeLSD=function(){this.writeShort(this.width);this.writeShort(this.height);this.out.writeByte(128|112|0|this.palSize);this.out.writeByte(0);this.out.writeByte(0)};GIFEncoder.prototype.writeNetscapeExt=function(){this.out.writeByte(33);this.out.writeByte(255);this.out.writeByte(11);this.out.writeUTFBytes("NETSCAPE2.0");this.out.writeByte(3);this.out.writeByte(1);this.writeShort(this.repeat);this.out.writeByte(0)};GIFEncoder.prototype.writePalette=function(){this.out.writeBytes(this.colorTab);var n=3*256-this.colorTab.length;for(var i=0;i<n;i++)this.out.writeByte(0)};GIFEncoder.prototype.writeShort=function(pValue){this.out.writeByte(pValue&255);this.out.writeByte(pValue>>8&255)};GIFEncoder.prototype.writePixels=function(){var enc=new LZWEncoder(this.width,this.height,this.indexedPixels,this.colorDepth);enc.encode(this.out)};GIFEncoder.prototype.stream=function(){return this.out};module.exports=GIFEncoder},{"./LZWEncoder.js":2,"./TypedNeuQuant.js":3}],2:[function(require,module,exports){var EOF=-1;var BITS=12;var HSIZE=5003;var masks=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535];function LZWEncoder(width,height,pixels,colorDepth){var initCodeSize=Math.max(2,colorDepth);var accum=new Uint8Array(256);var htab=new Int32Array(HSIZE);var codetab=new Int32Array(HSIZE);var cur_accum,cur_bits=0;var a_count;var free_ent=0;var maxcode;var clear_flg=false;var g_init_bits,ClearCode,EOFCode;function char_out(c,outs){accum[a_count++]=c;if(a_count>=254)flush_char(outs)}function cl_block(outs){cl_hash(HSIZE);free_ent=ClearCode+2;clear_flg=true;output(ClearCode,outs)}function cl_hash(hsize){for(var i=0;i<hsize;++i)htab[i]=-1}function compress(init_bits,outs){var fcode,c,i,ent,disp,hsize_reg,hshift;g_init_bits=init_bits;clear_flg=false;n_bits=g_init_bits;maxcode=MAXCODE(n_bits);ClearCode=1<<init_bits-1;EOFCode=ClearCode+1;free_ent=ClearCode+2;a_count=0;ent=nextPixel();hshift=0;for(fcode=HSIZE;fcode<65536;fcode*=2)++hshift;hshift=8-hshift;hsize_reg=HSIZE;cl_hash(hsize_reg);output(ClearCode,outs);outer_loop:while((c=nextPixel())!=EOF){fcode=(c<<BITS)+ent;i=c<<hshift^ent;if(htab[i]===fcode){ent=codetab[i];continue}else if(htab[i]>=0){disp=hsize_reg-i;if(i===0)disp=1;do{if((i-=disp)<0)i+=hsize_reg;if(htab[i]===fcode){ent=codetab[i];continue outer_loop}}while(htab[i]>=0)}output(ent,outs);ent=c;if(free_ent<1<<BITS){codetab[i]=free_ent++;htab[i]=fcode}else{cl_block(outs)}}output(ent,outs);output(EOFCode,outs)}function encode(outs){outs.writeByte(initCodeSize);remaining=width*height;curPixel=0;compress(initCodeSize+1,outs);outs.writeByte(0)}function flush_char(outs){if(a_count>0){outs.writeByte(a_count);outs.writeBytes(accum,0,a_count);a_count=0}}function MAXCODE(n_bits){return(1<<n_bits)-1}function nextPixel(){if(remaining===0)return EOF;--remaining;var pix=pixels[curPixel++];return pix&255}function output(code,outs){cur_accum&=masks[cur_bits];if(cur_bits>0)cur_accum|=code<<cur_bits;else cur_accum=code;cur_bits+=n_bits;while(cur_bits>=8){char_out(cur_accum&255,outs);cur_accum>>=8;cur_bits-=8}if(free_ent>maxcode||clear_flg){if(clear_flg){maxcode=MAXCODE(n_bits=g_init_bits);clear_flg=false}else{++n_bits;if(n_bits==BITS)maxcode=1<<BITS;else maxcode=MAXCODE(n_bits)}}if(code==EOFCode){while(cur_bits>0){char_out(cur_accum&255,outs);cur_accum>>=8;cur_bits-=8}flush_char(outs)}}this.encode=encode}module.exports=LZWEncoder},{}],3:[function(require,module,exports){var ncycles=100;var netsize=256;var maxnetpos=netsize-1;var netbiasshift=4;var intbiasshift=16;var intbias=1<<intbiasshift;var gammashift=10;var gamma=1<<gammashift;var betashift=10;var beta=intbias>>betashift;var betagamma=intbias<<gammashift-betashift;var initrad=netsize>>3;var radiusbiasshift=6;var radiusbias=1<<radiusbiasshift;var initradius=initrad*radiusbias;var radiusdec=30;var alphabiasshift=10;var initalpha=1<<alphabiasshift;var alphadec;var radbiasshift=8;var radbias=1<<radbiasshift;var alpharadbshift=alphabiasshift+radbiasshift;var alpharadbias=1<<alpharadbshift;var prime1=499;var prime2=491;var prime3=487;var prime4=503;var minpicturebytes=3*prime4;function NeuQuant(pixels,samplefac){var network;var netindex;var bias;var freq;var radpower;function init(){network=[];netindex=new Int32Array(256);bias=new Int32Array(netsize);freq=new Int32Array(netsize);radpower=new Int32Array(netsize>>3);var i,v;for(i=0;i<netsize;i++){v=(i<<netbiasshift+8)/netsize;network[i]=new Float64Array([v,v,v,0]);freq[i]=intbias/netsize;bias[i]=0}}function unbiasnet(){for(var i=0;i<netsize;i++){network[i][0]>>=netbiasshift;network[i][1]>>=netbiasshift;network[i][2]>>=netbiasshift;network[i][3]=i}}function altersingle(alpha,i,b,g,r){network[i][0]-=alpha*(network[i][0]-b)/initalpha;network[i][1]-=alpha*(network[i][1]-g)/initalpha;network[i][2]-=alpha*(network[i][2]-r)/initalpha}function alterneigh(radius,i,b,g,r){var lo=Math.abs(i-radius);var hi=Math.min(i+radius,netsize);var j=i+1;var k=i-1;var m=1;var p,a;while(j<hi||k>lo){a=radpower[m++];if(j<hi){p=network[j++];p[0]-=a*(p[0]-b)/alpharadbias;p[1]-=a*(p[1]-g)/alpharadbias;p[2]-=a*(p[2]-r)/alpharadbias}if(k>lo){p=network[k--];p[0]-=a*(p[0]-b)/alpharadbias;p[1]-=a*(p[1]-g)/alpharadbias;p[2]-=a*(p[2]-r)/alpharadbias}}}function contest(b,g,r){var bestd=~(1<<31);var bestbiasd=bestd;var bestpos=-1;var bestbiaspos=bestpos;var i,n,dist,biasdist,betafreq;for(i=0;i<netsize;i++){n=network[i];dist=Math.abs(n[0]-b)+Math.abs(n[1]-g)+Math.abs(n[2]-r);if(dist<bestd){bestd=dist;bestpos=i}biasdist=dist-(bias[i]>>intbiasshift-netbiasshift);if(biasdist<bestbiasd){bestbiasd=biasdist;bestbiaspos=i}betafreq=freq[i]>>betashift;freq[i]-=betafreq;bias[i]+=betafreq<<gammashift}freq[bestpos]+=beta;bias[bestpos]-=betagamma;return bestbiaspos}function inxbuild(){var i,j,p,q,smallpos,smallval,previouscol=0,startpos=0;for(i=0;i<netsize;i++){p=network[i];smallpos=i;smallval=p[1];for(j=i+1;j<netsize;j++){q=network[j];if(q[1]<smallval){smallpos=j;smallval=q[1]}}q=network[smallpos];if(i!=smallpos){j=q[0];q[0]=p[0];p[0]=j;j=q[1];q[1]=p[1];p[1]=j;j=q[2];q[2]=p[2];p[2]=j;j=q[3];q[3]=p[3];p[3]=j}if(smallval!=previouscol){netindex[previouscol]=startpos+i>>1;for(j=previouscol+1;j<smallval;j++)netindex[j]=i;previouscol=smallval;startpos=i}}netindex[previouscol]=startpos+maxnetpos>>1;for(j=previouscol+1;j<256;j++)netindex[j]=maxnetpos}function inxsearch(b,g,r){var a,p,dist;var bestd=1e3;var best=-1;var i=netindex[g];var j=i-1;while(i<netsize||j>=0){if(i<netsize){p=network[i];dist=p[1]-g;if(dist>=bestd)i=netsize;else{i++;if(dist<0)dist=-dist;a=p[0]-b;if(a<0)a=-a;dist+=a;if(dist<bestd){a=p[2]-r;if(a<0)a=-a;dist+=a;if(dist<bestd){bestd=dist;best=p[3]}}}}if(j>=0){p=network[j];dist=g-p[1];if(dist>=bestd)j=-1;else{j--;if(dist<0)dist=-dist;a=p[0]-b;if(a<0)a=-a;dist+=a;if(dist<bestd){a=p[2]-r;if(a<0)a=-a;dist+=a;if(dist<bestd){bestd=dist;best=p[3]}}}}}return best}function learn(){var i;var lengthcount=pixels.length;var alphadec=30+(samplefac-1)/3;var samplepixels=lengthcount/(3*samplefac);var delta=~~(samplepixels/ncycles);var alpha=initalpha;var radius=initradius;var rad=radius>>radiusbiasshift;if(rad<=1)rad=0;for(i=0;i<rad;i++)radpower[i]=alpha*((rad*rad-i*i)*radbias/(rad*rad));var step;if(lengthcount<minpicturebytes){samplefac=1;step=3}else if(lengthcount%prime1!==0){step=3*prime1}else if(lengthcount%prime2!==0){step=3*prime2}else if(lengthcount%prime3!==0){step=3*prime3}else{step=3*prime4}var b,g,r,j;var pix=0;i=0;while(i<samplepixels){b=(pixels[pix]&255)<<netbiasshift;g=(pixels[pix+1]&255)<<netbiasshift;r=(pixels[pix+2]&255)<<netbiasshift;j=contest(b,g,r);altersingle(alpha,j,b,g,r);if(rad!==0)alterneigh(rad,j,b,g,r);pix+=step;if(pix>=lengthcount)pix-=lengthcount;i++;if(delta===0)delta=1;if(i%delta===0){alpha-=alpha/alphadec;radius-=radius/radiusdec;rad=radius>>radiusbiasshift;if(rad<=1)rad=0;for(j=0;j<rad;j++)radpower[j]=alpha*((rad*rad-j*j)*radbias/(rad*rad))}}}function buildColormap(){init();learn();unbiasnet();inxbuild()}this.buildColormap=buildColormap;function getColormap(){var map=[];var index=[];for(var i=0;i<netsize;i++)index[network[i][3]]=i;var k=0;for(var l=0;l<netsize;l++){var j=index[l];map[k++]=network[j][0];map[k++]=network[j][1];map[k++]=network[j][2]}return map}this.getColormap=getColormap;this.lookupRGB=inxsearch}module.exports=NeuQuant},{}],4:[function(require,module,exports){var GIFEncoder,renderFrame;GIFEncoder=require("./GIFEncoder.js");renderFrame=function(frame){var encoder,page,stream,transfer;encoder=new GIFEncoder(frame.width,frame.height);if(frame.index===0){encoder.writeHeader()}else{encoder.firstFrame=false}encoder.setTransparent(frame.transparent);encoder.setRepeat(frame.repeat);encoder.setDelay(frame.delay);encoder.setQuality(frame.quality);encoder.setDither(frame.dither);encoder.setGlobalPalette(frame.globalPalette);encoder.addFrame(frame.data);if(frame.last){encoder.finish()}if(frame.globalPalette===true){frame.globalPalette=encoder.getGlobalPalette()}stream=encoder.stream();frame.data=stream.pages;frame.cursor=stream.cursor;frame.pageSize=stream.constructor.pageSize;if(frame.canTransfer){transfer=function(){var i,len,ref,results;ref=frame.data;results=[];for(i=0,len=ref.length;i<len;i++){page=ref[i];results.push(page.buffer)}return results}();return self.postMessage(frame,transfer)}else{return self.postMessage(frame)}};self.onmessage=function(event){return renderFrame(event.data)}},{"./GIFEncoder.js":1}]},{},[4]);
285
- `],{type:`application/javascript`}))})}var ZD=`https://api.polotno.com`;`${ZD}`;var QD=()=>ZD+`/api`,$D=L({value:!1}),eO=L({value:`v1`}),tO=()=>eO.value,nO=L({value:0}),rO=()=>nO.value,iO=()=>$D.value,aO=Vn(()=>{$D.value=!0}),oO=typeof window<`u`?window.location.origin:``,sO=typeof navigator<`u`&&navigator.userAgent.indexOf(`Headless`)>-1,cO=typeof navigator<`u`&&navigator.userAgent.indexOf(`Electron`)>-1;oO===`file://`&&sO&&(oO=`headless`),oO===`file://`&&cO&&(oO=`electron`);var lO=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${oO}" here: https://polotno.com/cabinet`,uO=fetch;async function dO(e){for(let t=0;t<5;t++)try{let t=await uO(QD()+`/validate-key`,{method:`POST`,body:JSON.stringify({key:e,site:location.host,skdVersion:`2.38.0`})});if(Un(()=>{eO.value=t.headers.get(`x-api-version`)||``}),!e)return console.error(`Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet`),Un(()=>{nO.value=1}),!1;if(t.status!==200){await new Promise(e=>setTimeout(e,3e3));continue}let n=await t.json();return n.is_valid||(console.error(`Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet`),Un(()=>{nO.value=1})),n.is_paid||(console.log(`%cPolotno Free Version. For development usage only. https://polotno.com/`,`background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;`),Un(()=>{nO.value===0&&(nO.value=2)})),n.is_domain_valid||console.log(lO,`background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;`),Sp(n.remove_background_enabled),n.is_paid||!1}catch{await new Promise(e=>setTimeout(e,3e3))}return console.error(`Can not validate Polotno API key. Please report to anton@polotno.com immediately.`),!0}async function fO(e,t){await dO(e)&&!t||aO()}var pO=[112,72,89,115],mO=(()=>{let e=new Uint32Array(256);for(let t=0;t<256;t++){let n=t;for(let e=0;e<8;e++)n=1&n?3988292384^n>>>1:n>>>1;e[t]=n>>>0}return e})(),hO=()=>typeof globalThis<`u`?globalThis.Buffer:void 0,gO=(e,t,n)=>{e[t]=n>>>24&255,e[t+1]=n>>>16&255,e[t+2]=n>>>8&255,e[t+3]=255&n},_O=(e,t,n)=>{let r=e.indexOf(`,`),i=(e=>{if(typeof atob==`function`){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}let t=hO();if(t)return new Uint8Array(t.from(e,`base64`));throw Error(`No base64 decoder available`)})(r>=0?e.slice(r+1):e);return`data:${t};base64,${(e=>{if(typeof btoa==`function`){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}let t=hO();if(t)return t.from(e).toString(`base64`);throw Error(`No base64 encoder available`)})(t===`image/png`?((e,t)=>{let n=(e=>{let t=new Uint8Array(9),n=new DataView(t.buffer);n.setUint32(0,e,!1),n.setUint32(4,e,!1),t[8]=1;let r=new Uint8Array(8+t.length+4);gO(r,0,t.length),r.set(pO,4),r.set(t,8);let i=new Uint8Array(4+t.length);return i.set(pO,0),i.set(t,4),gO(r,8+t.length,(e=>{let t=4294967295;for(let n=0;n<e.length;n++)t=mO[255&(t^e[n])]^t>>>8;return(4294967295^t)>>>0})(i)),r})(Math.round(t/.0254)),r=((e,t)=>{let n=8;for(;n+8<=e.length;){let r=e[n]<<24|e[n+1]<<16|e[n+2]<<8|e[n+3],i=n+4,a=e.subarray(i,i+4),o=8+r+4;if(t.every((e,t)=>a[t]===e))return{offset:n,totalLength:o};n+=o}return null})(e,pO);if(r){let t=new Uint8Array(e.length-r.totalLength+n.length);return t.set(e.slice(0,r.offset),0),t.set(n,r.offset),t.set(e.slice(r.offset+r.totalLength),r.offset+n.length),t}let i=16+(e[8]<<24|e[9]<<16|e[10]<<8|e[11])+4;if(i>e.length)return e;let a=new Uint8Array(e.length+n.length);return a.set(e.slice(0,i),0),a.set(n,i),a.set(e.slice(i),i+n.length),a})(i,n):((e,t)=>{let n=(e=>{let t=2;for(;t+4<e.length;){if(e[t]!==255)return-1;let n=e[t+1];if(n===216||n===217){t+=2;continue}let r=e[t+2]<<8|e[t+3];if(r<2)return-1;if(n===224&&e[t+4]===74&&e[t+5]===70&&e[t+6]===73&&e[t+7]===70&&e[t+8]===0)return t;let i=t+2+r;if(i<=t||i>e.length)return-1;t=i}return-1})(e);if(n>=0){let r=new Uint8Array(e),i=n+11;return r[i]=1,r[i+1]=t>>8&255,r[i+2]=255&t,r[i+3]=t>>8&255,r[i+4]=255&t,r}let r=(e=>{let t=new Uint8Array(18);return t[0]=255,t[1]=224,t[2]=0,t[3]=16,t[4]=74,t[5]=70,t[6]=73,t[7]=70,t[8]=0,t[9]=1,t[10]=1,t[11]=1,t[12]=e>>8&255,t[13]=255&e,t[14]=e>>8&255,t[15]=255&e,t})(t),i=new Uint8Array(e.length+r.length);return i.set(e.subarray(0,2),0),i.set(r,2),i.set(e.subarray(2),2+r.length),i})(i,n))}`},vO=({px:e,unit:t=`px`,dpi:n})=>{switch(t){case`pt`:default:return e;case`mm`:return e/(n/25.4);case`cm`:return e/(n/2.54);case`in`:return e/n}},yO=({px:e,precious:t=2,dpi:n=72,unit:r=`px`})=>parseFloat(vO({px:e,dpi:n,unit:r}).toFixed(t)),bO=({unitVal:e,dpi:t,unit:n})=>e/vO({px:1,unit:n,dpi:t}),xO=e=>{let t=parseFloat(vO(e).toFixed(1));switch(e.unit){case`pt`:return`${Math.round(t)}pt`;case`mm`:return`${t}mm`;case`cm`:return`${t}cm`;case`in`:return`${t}in`;default:return`${Math.round(t)}px`}};async function SO(e){for(let t=0;t<30;t++){let t=await e();if(t)return t;await new Promise(e=>setTimeout(e,50))}}function CO(e){return new Promise((t,n)=>{let r=document.createElement(`img`);r.onload=()=>{t(r)},r.onerror=e=>{n(e)},r.crossOrigin=`anonymous`,r.src=e})}async function wO(e,t){let n=await CO(e),r=document.createElement(`canvas`);r.width=2*n.width,r.height=2*n.height,r.getContext(`2d`).drawImage(n,0,0,r.width,r.height);let i=document.createElement(`canvas`);i.width=t.width,i.height=t.height;let a=i.getContext(`2d`),{cropX:o,cropY:s}=t,c=r.width*t.cropWidth,l=r.height*t.cropHeight,u=t.width/t.height,d,f,p=c/l;return t.type===`svg`?(d=c,f=l):u>=p?(d=c,f=c/u):(d=l*u,f=l),a.drawImage(r,o*r.width,s*r.height,d,f,0,0,i.width,i.height),i.toDataURL(`image/png`)}function TO(e,t){let{width:n,height:r}=e,i=n/r,a,o;i>=t.width/t.height?(a=t.width,o=t.width/i):(a=t.height*i,o=t.height);let s=(t.width-a)/2,c=(t.height-o)/2;return{cropX:s/t.width,cropY:c/t.height,cropWidth:a/t.width,cropHeight:o/t.height}}var EO;(function(e){e.sepia=`sepia`,e.grayscale=`grayscale`,e.natural=`natural`,e.warm=`warm`,e.cold=`cold`,e.temperature=`temperature`,e.contrast=`contrast`,e.shadows=`shadows`,e.white=`white`,e.black=`black`,e.vibrance=`vibrance`,e.saturation=`saturation`})(EO||={});function DO(e,t){let n={filter:``,html:void 0};switch(e){case EO.warm:{let e=Math.max(0,Math.min(1,t??.5)),r=1+.3*e,i=1+.15*e;return n.filter=`url(#warm-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="warm-filter" color-interpolation-filters="sRGB">\n <feColorMatrix type="matrix" values="\n ${r} 0 0 0 0\n 0 ${i} 0 0 0\n 0 0 1 0 0\n 0 0 0 1 0" />\n </filter>\n </svg>`,n}case EO.cold:{let e=Math.max(0,Math.min(1,t??.5)),r=1-.15*e,i=1-.1*e,a=1+.15*e;return n.filter=`url(#cold-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="cold-filter" color-interpolation-filters="sRGB">\n <feColorMatrix type="matrix" values="\n ${r} 0 0 0 0\n 0 ${i} 0 0 0\n 0 0 ${a} 0 0\n 0 0 0 1 0" />\n </filter>\n </svg>`,n}case`natural`:{let e=Math.max(0,Math.min(1,t??.5)),r=1+.1*e;return n.filter=`saturate(${1+.3*e}) brightness(${r}) contrast(${1+.2*e})`,n}case EO.temperature:{let e=Math.max(-1,Math.min(1,t??0)),r=1+.15*e,i=1-.15*e;return n.filter=`url(#temperature-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="temperature-filter" color-interpolation-filters="sRGB">\n <feColorMatrix type="matrix" values="\n ${r} 0 0 0 0\n 0 1 0 0 0\n 0 0 ${i} 0 0\n 0 0 0 1 0" />\n </filter>\n </svg>\n `,n}case EO.contrast:{let e=100*Math.max(-1,Math.min(1,t??0)),r=259*(e+255)/(255*(259-e)),i=.5*(1-r);return n.filter=`url(#contrast-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="contrast-filter" color-interpolation-filters="sRGB">\n <feComponentTransfer>\n <feFuncR type="linear" slope="${r}" intercept="${i}" />\n <feFuncG type="linear" slope="${r}" intercept="${i}" />\n <feFuncB type="linear" slope="${r}" intercept="${i}" />\n </feComponentTransfer>\n </filter>\n </svg>\n `,n}case EO.shadows:{let e=Math.max(-1,Math.min(1,t??0)),r=Math.min(Math.max(1-.6*e,.4),2.5);return n.filter=`url(#shadows-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="shadows-filter" color-interpolation-filters="sRGB">\n <feComponentTransfer>\n <feFuncR type="gamma" amplitude="1" exponent="${r}" offset="0" />\n <feFuncG type="gamma" amplitude="1" exponent="${r}" offset="0" />\n <feFuncB type="gamma" amplitude="1" exponent="${r}" offset="0" />\n </feComponentTransfer>\n </filter>\n </svg>\n `,n}case EO.white:case EO.black:return null;case EO.vibrance:{let e=Math.max(-1,Math.min(1,t??0)),r=.299,i=.587,a=.114,o;o=e>=0?1+1.5*e:1+e;let s=1-o,c=s*r+o,l=s*i,u=s*a,d=s*r,f=s*i+o,p=s*a,m=s*r,h=s*i,g=s*a+o;return n.filter=`url(#vibrance-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="vibrance-filter" color-interpolation-filters="sRGB">\n <feColorMatrix type="matrix" values="\n ${c} ${l} ${u} 0 0\n ${d} ${f} ${p} 0 0\n ${m} ${h} ${g} 0 0\n 0 0 0 1 0" />\n </filter>\n </svg>\n `,n}case EO.saturation:{let e=.2126,r=.7152,i=.0722,a=1+Math.max(-1,Math.min(1,t??0)),o=1-a,s=o*e+a,c=o*r,l=o*i,u=o*e,d=o*r+a,f=o*i,p=o*e,m=o*r,h=o*i+a;return n.filter=`url(#saturation-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="saturation-filter" color-interpolation-filters="sRGB">\n <feColorMatrix type="matrix" values="\n ${s} ${c} ${l} 0 0\n ${u} ${d} ${f} 0 0\n ${p} ${m} ${h} 0 0\n 0 0 0 1 0" />\n </filter>\n </svg>\n `,n}default:return null}}async function OO(e){return new Promise((t,n)=>{let r=document.createElement(`video`);r.crossOrigin=`anonymous`,r.src=e,r.addEventListener(`loadedmetadata`,()=>{let{videoWidth:e,videoHeight:n}=r;t({width:e,height:n})}),r.addEventListener(`error`,t=>{let r=e.slice(0,100);n(Error(`Failed to load video: ${r}`))})})}var kO=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n},AO=(e,t,...n)=>({type:e,props:t,children:n||[]});function jO(e){return jf(e),e}function MO(e){var t=new DOMParser().parseFromString(e,`image/svg+xml`);return t.documentElement.setAttribute(`preserveAspectRatio`,`none`),new XMLSerializer().serializeToString(t)}var NO=async({element:e,page:t,store:n})=>{let{src:r}=e;if(e.type===`svg`){let t=await W_(r);t=MO(t),r=Object.keys(e.colorsReplace).length?J_(t,new Map(Object.entries(e.colorsReplace))):G_(t)}let i=``;e.flipX&&(i+=`scaleX(-1)`),e.flipY&&(i+=`scaleY(-1)`),i||=`none`;let a={};if(e.type===`svg`&&e.maskSrc){let t=await U_(r);a[`mask-image`]=`url(${t})`,a[`mask-size`]=`100% 100%`,a[`mask-position`]=`0 0`,a[`mask-repeat`]=`no-repeat`,a[`-webkit-mask-image`]=`url(${t})`,a[`-webkit-mask-size`]=`100% 100%`,a[`-webkit-mask-position`]=`0 0`,a[`-webkit-mask-repeat`]=`no-repeat`,r=e.maskSrc}else if(e.clipSrc){let t=e.clipSrc,n=await U_(t);a[`mask-image`]=`url(${n})`,a[`mask-size`]=`100% 100%`,a[`mask-position`]=`0 0`,a[`mask-repeat`]=`no-repeat`,a[`-webkit-mask-image`]=`url(${n})`,a[`-webkit-mask-size`]=`100% 100%`,a[`-webkit-mask-position`]=`0 0`,a[`-webkit-mask-repeat`]=`no-repeat`}let o=await CO(r),s=o.width*e.cropWidth,c=o.height*e.cropHeight,l=e.width/e.height,u,d,f=s/c,p=e.type===`svg`||e.stretchEnabled;p?(u=s,d=c):l>=f?(u=s,d=s/l):(u=c*l,d=c);let m=u/o.width,h=d/o.height,g=u/d>e.width/e.height?e.height/d:e.width/u,_=p?e.width/u:g,v=p?e.height/d:g,y=u*_/m,b=d*v/h,x=e.cropX*_*o.width,S=e.cropY*v*o.height;e.flipX&&(x=(1-e.cropX-e.cropWidth)*_*o.width),e.flipY&&(S=(1-e.cropY-e.cropHeight)*v*o.height);let C=e.borderSize&&jf(e.borderColor),w=C?Math.max(0,e.cornerRadius-e.borderSize):e.cornerRadius,T=AO(`div`,{style:Object.assign(Object.assign({},a),{width:`100%`,height:`100%`,borderRadius:w+`px`,border:e.borderSize&&!C?`${e.borderSize}px solid ${e.borderColor}`:`none`,backgroundRepeat:`no-repeat`,backgroundImage:`url(${r})`,transform:i,backgroundSize:`${Math.round(y)}px ${Math.round(b)}px`,backgroundPositionX:-Math.round(x)+`px`,backgroundPositionY:-Math.round(S)+`px`})});return C?AO(`div`,{style:{width:`100%`,height:`100%`,borderRadius:e.cornerRadius+`px`,background:jO(e.borderColor),padding:e.borderSize+`px`,boxSizing:`border-box`}},T):T},PO=({element:e,type:t})=>{let n={"stroke-width":e.height,stroke:e.color,"stroke-linecap":`round`,"stroke-linejoin":`round`,opacity:e.opacity},r=Object.assign(Object.assign({},n),{fill:e.color}),i=Object.assign(Object.assign({},n),{fill:`none`});return t===`arrow`?AO(`polyline`,Object.assign({points:`${3*e.height},${2*-e.height} 0,0 ${3*e.height},${2*e.height}`},i)):t===`triangle`?AO(`polygon`,Object.assign({points:`${3*e.height},${2*-e.height} 0,0 ${3*e.height},${2*e.height}`},r)):t===`bar`?AO(`polyline`,Object.assign({points:`0,${2*-e.height} 0,${2*e.height}`},i)):t===`circle`?AO(`circle`,Object.assign({cx:2*e.height,cy:0,r:2*e.height},r)):t===`square`?AO(`polygon`,Object.assign({points:`0,${2*-e.height} ${4*e.height},${2*-e.height} ${4*e.height},${2*e.height} 0,${2*e.height}`},r)):null},FO={image:NO,svg:NO,text:async({element:e,page:t,store:n})=>{let r=jf(e.fill),i=jf(e.stroke);if(e.curveEnabled){let t=jp(e.width,e.height,e.curvePower,e.fontSize),n=Fp(ep(e.text),{fontWeight:e.fontWeight||`normal`,fontStyle:e.fontStyle||`normal`,fill:e.fill||`black`}),a=`\n <svg xmlns="http://www.w3.org/2000/svg" width="${e.width}" height="${e.height}" style="display: block;">\n <defs>\n <path id="curve-${e.id}" d="${t}" fill="none" />`;if(r){let t=`curve-fill-grad-${e.id}`;a+=Mp(e.fill,t)}if(i&&e.strokeWidth){let t=`curve-stroke-grad-${e.id}`;a+=Mp(e.stroke,t)}a+=`</defs>\n <text\n font-family="'${e.fontFamily}'"\n font-size="${e.fontSize}"\n font-weight="${e.fontWeight}"\n font-style="${e.fontStyle}"\n fill="${r?`url(#curve-fill-grad-${e.id})`:e.fill}"\n text-anchor="middle"\n dominant-baseline="central"\n letter-spacing="${e.letterSpacing*e.fontSize}px"${e.textDecoration?` text-decoration="${e.textDecoration}"`:``}${e.strokeWidth?` stroke="${i?`url(#curve-stroke-grad-${e.id})`:e.stroke}" stroke-width="${e.strokeWidth}" paint-order="stroke fill"`:``}>\n <textPath href="#curve-${e.id}" startOffset="50%">${n}</textPath>\n </text>\n </svg>`;let o=e.backgroundPadding*(e.fontSize*e.lineHeight);return AO(`div`,{style:{position:`relative`,width:`100%`,height:`100%`}},e.backgroundEnabled&&AO(`div`,{style:{position:`absolute`,top:-o/2+`px`,left:-o/2+`px`,width:e.width+o+`px`,height:e.height+o+`px`,backgroundColor:e.backgroundColor,opacity:e.backgroundOpacity,borderRadius:e.backgroundCornerRadius*(e.fontSize*e.lineHeight*.5)+`px`}}),AO(`div`,{style:{width:`100%`,height:`100%`,position:`absolute`,top:0,left:0},innerHTML:a}))}let a=e=>({backgroundImage:e,backgroundSize:`100% 100%`,backgroundRepeat:`repeat`,WebkitBackgroundClip:`text`,MozBackgroundClip:`text`,backgroundClip:`text`,WebkitTextFillColor:`transparent`,MozTextFillColor:`transparent`,color:`transparent`}),o={top:0,left:0};r&&(o=Object.assign(Object.assign({},o),a(e.fill)));let s=e.backgroundPadding*(e.fontSize*e.lineHeight),c=AO(`div`,{style:{position:`absolute`,top:-s/2+`px`,left:-s/2+`px`,display:e.backgroundEnabled?`block`:`none`,width:e.width+s+`px`,height:e.height+s+`px`,backgroundColor:e.backgroundColor,opacity:e.backgroundOpacity,borderRadius:e.backgroundCornerRadius*(e.fontSize*e.lineHeight*.5)+`px`}});e.verticalAlign===`middle`?(o.top=`50%`,o.transform=`translateY(-50%)`):e.verticalAlign===`bottom`&&(o.bottom=0);let l=/<[a-z][\s\S]*>/i.test(e.text),u=l?e.text:e.text.split(`
286
- `).join(`<br />`);if(e.strokeWidth&&(i||r&&!i)){let t=Object.assign({position:`absolute`,width:e.width+`px`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,fontSize:e.fontSize+`px`,textAlign:e.align,fontFamily:`'${e.fontFamily}'`,textDecoration:e.textDecoration||`none`,textDecorationColor:e.textDecoration?e.fill:void 0,textTransform:e.textTransform||`none`,lineHeight:e.lineHeight,letterSpacing:e.letterSpacing*e.fontSize+`px`,fontStyle:e.fontStyle,fontWeight:e.fontWeight},o),n=i?Object.assign(Object.assign(Object.assign({},t),a(e.stroke)),{WebkitTextStroke:`${e.strokeWidth}px transparent`}):Object.assign(Object.assign({},t),{color:`transparent`,WebkitTextStroke:`${e.strokeWidth}px ${e.stroke}`}),s=r?Object.assign(Object.assign({},t),a(e.fill)):Object.assign(Object.assign({},t),{color:e.fill}),d=`el-`+e.id,f=l?`<style>#${d} {${xy}}</style>`:``,p=AO(`div`,{style:Object.assign(Object.assign({},n),{position:`absolute`,top:0,left:0,pointerEvents:`none`}),"aria-hidden":`true`,innerHTML:l?`${f}${u}`:u}),m=AO(`div`,Object.assign(Object.assign({style:Object.assign(Object.assign({},s),{position:`relative`})},l?{id:d}:{}),{innerHTML:l?`${f}${u}`:u}));return AO(`div`,{style:{position:`relative`,width:`100%`,height:`100%`}},c,AO(`div`,{style:{position:`relative`,width:e.width+`px`}},p,m))}let d=Object.assign(Object.assign({},o),{position:`absolute`,width:e.width+`px`,color:e.fill,whiteSpace:`pre-wrap`,wordBreak:`break-word`,fontSize:e.fontSize+`px`,textAlign:e.align,fontFamily:`'${e.fontFamily}'`,textDecoration:e.textDecoration||`none`,textDecorationColor:e.textDecoration?e.fill:void 0,textTransform:e.textTransform||`none`,lineHeight:e.lineHeight,letterSpacing:e.letterSpacing*e.fontSize+`px`,fontStyle:e.fontStyle,fontWeight:e.fontWeight,WebkitTextStroke:e.strokeWidth?`${e.strokeWidth}px ${e.stroke}`:void 0,paintOrder:e.strokeWidth?`stroke fill`:void 0}),f=`el-`+e.id,p=l?{id:f}:{},m=`<style>#${f} {${xy}}</style>`;return AO(`div`,{style:{position:`relative`,width:`100%`,height:`100%`}},c,AO(`div`,Object.assign(Object.assign({style:d},p),{innerHTML:l?`${m}${u}`:u})))},line:async({element:e,page:t,store:n})=>AO(`svg`,{style:{width:`100%`,height:`100%`,contain:`layout style size`,overflow:`visible`}},AO(`line`,{x1:0,y1:e.height/2,x2:e.width,y2:e.height/2,stroke:e.color,"stroke-width":e.height,"stroke-dasharray":e.dash&&e.dash.length?e.dash.map(t=>t*e.height).join(` `):void 0}),AO(`g`,{transform:`translate(0 ${e.height/2})`},PO({element:e,type:e.startHead})),AO(`g`,{transform:`translate(${e.width} ${e.height/2}) rotate(180)`},PO({element:e,type:e.endHead}))),figure:async({element:e,page:t,store:n,elementHook:r})=>{let i=DD(e);if(e.strokeWidth&&jf(e.stroke)){let t=`figure-stroke-grad-${e.id}`,n=Mp(e.stroke,t);i=i.replace(RegExp(`stroke="${e.stroke.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}"`,`g`),`stroke="url(#${t})"`),i=i.replace(`</defs>`,`${n}</defs>`)}if(jf(e.fill)){let t=`figure-fill-grad-${e.id}`,n=Mp(e.fill,t);i=i.replace(RegExp(`fill="${e.fill.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}"`,`g`),`fill="url(#${t})"`),i=i.replace(`</defs>`,`${n}</defs>`)}let a=AO(`div`,{innerHTML:i});return r&&r({dom:a,element:e})||a},group:async({element:e,page:t,store:n,elementHook:r})=>{let i=await Promise.all(e.children.map(e=>IO({element:e,page:t,store:n,elementHook:r}))),a=AO(`div`,{style:{transformOrigin:`top left`,opacity:e.opacity}},...i);return r&&r({dom:a,element:e})||a},video:async({element:e,page:t,store:n,elementHook:r})=>{let{cropX:i,cropY:a,cropWidth:o,cropHeight:s}=e,c=await OO(e.src),l=c.width*o,u=c.height*s,d=e.width/e.height,f,p;d>=l/u?(f=l,p=l/d):(f=u*d,p=u);let m=f/o,h=p/s,g=i*c.width,_=a*c.height,v=Math.max(e.width/c.width,e.height/c.height),y={position:`absolute`,width:`${Math.round(m*v)}px`,height:`${Math.round(h*v)}px`,left:-Math.round(g*v)+`px`,top:-Math.round(_*v)+`px`,objectFit:`fill`},b=`video-${e.id}`,x=e.borderSize&&jf(e.borderColor),S=AO(`div`,{style:{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`,borderRadius:(x?Math.max(0,e.cornerRadius-e.borderSize):e.cornerRadius)+`px`,border:e.borderSize&&!x?`${e.borderSize}px solid ${e.borderColor}`:`none`}},AO(`video`,{id:b,src:e.src,style:y,controls:!0,playsInline:!0,muted:!0,volume:e.volume}));if(x){let t=AO(`div`,{style:{width:`100%`,height:`100%`,borderRadius:e.cornerRadius+`px`,background:jO(e.borderColor),padding:e.borderSize+`px`,boxSizing:`border-box`}},S);return r&&r({dom:t,element:e})||t}return r&&r({dom:S,element:e})||S},gif:NO,table:async({element:e})=>{let t=e.rows,n=e.cols,r=e.colWidths,i=e.rowHeights,a=[`fontSize`,`fontFamily`,`fontWeight`,`fontStyle`,`textDecoration`,`textTransform`,`fill`,`align`,`verticalAlign`,`lineHeight`,`letterSpacing`,`strokeWidth`,`stroke`,`cellBackground`,`cellPadding`],o=(e.cells||[]).map(t=>{if(!t)return t;let n=Object.assign({},t);for(let t of a)n[t]===void 0&&(n[t]=e[t]);return n}),s=[];for(let r=0;r<t;r++){let t=[];for(let a=0;a<n;a++){let s=o[r*n+a];if(!s||s.mergedInto)continue;let c=s.cellPadding||4,l=s.colSpan||1,u=s.rowSpan||1,d=t=>{let n=s.borders?.[t];return`${n?.width??e.borderWidth}px ${n?.style??e.borderStyle??`solid`} ${n?.color??e.borderColor}`},f={style:{padding:c+`px`,background:s.cellBackground||`transparent`,fontSize:(s.fontSize||12)+`px`,fontFamily:`'${s.fontFamily||`Roboto`}'`,fontWeight:s.fontWeight||`normal`,fontStyle:s.fontStyle||`normal`,color:s.fill||`black`,textAlign:s.align||`left`,verticalAlign:s.verticalAlign||`top`,lineHeight:String(s.lineHeight||1.2),letterSpacing:s.letterSpacing?s.letterSpacing*(s.fontSize||12)+`px`:void 0,textDecoration:s.textDecoration||`none`,textTransform:s.textTransform||`none`,borderTop:d(`top`),borderRight:d(`right`),borderBottom:d(`bottom`),borderLeft:d(`left`),overflow:`hidden`,wordBreak:`break-word`,whiteSpace:`pre-wrap`,height:i[r]*e.height+`px`}};l>1&&(f.colspan=String(l)),u>1&&(f.rowspan=String(u)),t.push(AO(`td`,f,Qf(s.text||``)))}s.push(AO(`tr`,{},...t))}return AO(`table`,{style:{width:`100%`,height:`100%`,borderCollapse:`collapse`,tableLayout:`fixed`}},AO(`colgroup`,{},...r.map(e=>AO(`col`,{style:{width:100*e+`%`}}))),AO(`tbody`,{},...s))}};async function IO({element:e,page:t,store:n,elementHook:r}){let i=await FO[e.type];if(i||(i=()=>AO(`div`,{}),console.error(`HTML export does not support ${e.type} type...`)),!e.visible)return null;let a=await i({element:e,page:t,store:n}),o=[],s=[];if(e.blurEnabled&&o.push(`blur(${e.blurRadius/2}px)`),e.brightnessEnabled&&o.push(`brightness(${100*e.brightness+100}%)`),e.sepiaEnabled&&o.push(`sepia()`),e.grayscaleEnabled&&o.push(`grayscale()`),e.filters)for(let[t,n]of Object.entries(e.filters)){let e=DO(EO[t],n.intensity);e&&(o.push(e.filter),e.html&&s.push(e.html))}if(e.shadowEnabled){let t=function(e,t){if(t===1)return e;let n=Du.Util.colorToRGBA(e);return n?`rgba(${n.r}, ${n.g}, ${n.b}, ${n.a*t})`:e}(e.shadowColor,e.shadowOpacity??1);o.push(`drop-shadow(${e.shadowOffsetX}px ${e.shadowOffsetY}px ${e.shadowBlur/2}px ${t})`)}let c=AO(`div`,{id:e.id,style:{position:`absolute`,left:e.x+`px`,top:e.y+`px`,width:e.width+`px`,height:e.height+`px`,transform:`rotate(${e.rotation}deg)`,transformOrigin:`top left`,opacity:e.opacity,display:e.visible&&e.showInExport?`block`:`none`,filter:o.join(` `)||`none`}},a,...s);return r&&r({dom:c,element:e})||c}async function LO({json:e,elementHook:t}){let n=await Promise.all(e.pages.map(n=>async function({page:e,store:t,elementHook:n}){let r=await Promise.all(e.children.map(r=>IO({element:r,page:e,store:t,elementHook:n}))),i=e.width===`auto`?t.width:e.width,a=e.height===`auto`?t.height:e.height,o={};if(e.background.indexOf(`url`)>=0||e.background.indexOf(`http`)>=0||e.background.indexOf(`.jpg`)>=0||e.background.indexOf(`.png`)>=0||e.background.indexOf(`.jpeg`)>=0){let{width:n,height:o}=await CO(e.background),s=await NO({element:Object.assign({x:0,y:0,width:i,height:a,src:e.background,cornerRadius:0},TO({width:i,height:a},{width:n,height:o})),page:e,store:t});r.unshift(s)}else o=Object.assign(Object.assign({},o),{backgroundColor:e.background});return AO(`div`,{className:`page`,id:e.id,style:Object.assign(Object.assign({},o),{width:i+`px`,height:a+`px`,overflow:`hidden`,position:`relative`})},...r)}({page:n,store:e,elementHook:t}))),r=[];return Vk({children:e.pages},e=>{e.type!==`text`&&e.type!==`tablecell`&&e.type!==`table`||!e.fontFamily||r.indexOf(e.fontFamily)!==-1||r.push(e.fontFamily)}),AO(`div`,{className:`design`},...r.map(t=>{let n=e.fonts.find(e=>e.fontFamily===t);return n?AO(`style`,{},(n.styles||(n.url?[{src:`url("${n.url}")`}]:[])).map(e=>`\n @font-face {\n font-family: '${n.fontFamily}';\n src: ${e.src};\n font-style: ${e.fontStyle||`normal`};\n font-weight: ${e.fontWeight||`normal`};\n font-display: swap;\n }`).join(`
287
- `)):AO(`link`,{href:mp(t),rel:`stylesheet`})}),...n)}var RO=({dom:e})=>{if(typeof e==`string`)return e;if(!e)return``;let t=e.props,{innerHTML:n}=t,r=kO(t,[`innerHTML`]),i=Object.keys(r).map(e=>e===`style`&&typeof r[e]==`object`?`style="${Object.keys(r[e]).filter(t=>r[e][t]!=null).map(t=>`${t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}: ${r[e][t]}`).join(`; `)}"`:((e,t)=>t==null||t===``?``:typeof t==`object`?`${e}="${Object.keys(t).map(e=>`${e.replace(/-([a-z])/g,e=>e[1].toUpperCase())}:${t[e]};`).join(` `)}"`:`${e}="${t}"`)(e,r[e])).filter(e=>e&&e.trim().length>0).join(` `);return`<${e.type} ${i}>${n||e.children.map(e=>RO({dom:e})).join(``)}</${e.type}>`};async function zO({json:e,elementHook:t}){return RO({dom:await LO({json:e,elementHook:t})})}var BO=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n},VO=(e,t)=>{if(e.children)for(let n of e.children){if(!0===t(n))break;VO(n,t)}if(e.cells){for(let n of e.cells)if(!0===t(n))break}},$=(e,t,...n)=>({type:e,props:t,children:n||[]});function HO(e,t){if(!jf(e))return null;let{stops:n,rotation:r}=Nf(e),i=r*Math.PI/180,a=.5-.5*Math.sin(i),o=.5+.5*Math.cos(i),s=.5+.5*Math.sin(i),c=.5-.5*Math.cos(i),l=n.map(({offset:e,color:t})=>$(`stop`,{offset:100*e+`%`,"stop-color":t}));return $(`linearGradient`,{id:t,x1:100*a+`%`,y1:100*o+`%`,x2:100*s+`%`,y2:100*c+`%`},...l)}var UO=async e=>{try{let t=await fetch(e);if(typeof Buffer<`u`){let e=await t.arrayBuffer(),n=Buffer.from(e).toString(`base64`);return`data:${t.headers.get(`content-type`)||`image/png`};base64,${n}`}{let e=await t.blob();return new Promise((t,n)=>{let r=new FileReader;r.onloadend=()=>t(r.result),r.onerror=n,r.readAsDataURL(e)})}}catch(t){return console.error(`Error converting URL to data URL:`,t),e}},WO=async({element:e,page:t,store:n})=>{let{src:r}=e;r=e.type===`svg`?J_(await W_(r),new Map(Object.entries(e.colorsReplace))):await UO(r);let i,a,o,s,c=``;if(e.flipX||e.flipY){let t=e.flipX?-1:1,n=e.flipY?-1:1,r=e.width/2,i=e.height/2;c=`translate(${r}, ${i}) scale(${t}, ${n}) translate(${-r}, ${-i})`}e.clipSrc&&(i=`clip-img-mask-${e.id}`,a=await UO(e.clipSrc)),e.maskSrc&&(o=`mask-img-${e.id}`,s=await UO(e.maskSrc));let l=await CO(r),u=l.width*e.cropWidth,d=l.height*e.cropHeight,f=e.width/e.height,p,m,h=u/d,g=typeof e.stretchEnabled==`boolean`&&e.stretchEnabled||e.type===`svg`;g?(p=u,m=d):f>=h?(p=u,m=u/f):(p=d*f,m=d);let _=p/l.width,v=m/l.height,y=p/m>e.width/e.height?e.height/m:e.width/p,b=g?e.width/p:y,x=g?e.height/m:y,S=p*b/_,C=m*x/v,w=e.cropX*l.width*b,T=e.cropY*l.height*x;e.flipX&&(w=(1-e.cropX-e.cropWidth)*l.width*b),e.flipY&&(T=(1-e.cropY-e.cropHeight)*l.height*x);let E=`clip-${e.id}`,D=e.cornerRadius||0,O=r.replace(/&/g,`&amp;`),k={x:-w,y:-T,width:S,height:C,preserveAspectRatio:`none`,"clip-path":`url(#${E})`},A=[$(`clipPath`,{id:E},$(`rect`,{x:0,y:0,width:e.width,height:e.height,rx:D||void 0,ry:D||void 0}))];i&&a&&A.push($(`mask`,{id:i,maskUnits:`userSpaceOnUse`,"mask-type":`alpha`},$(`image`,{href:a.replace(/&/g,`&amp;`),x:0,y:0,width:e.width,height:e.height,preserveAspectRatio:`none`}))),o&&A.push($(`mask`,{id:o,maskUnits:`userSpaceOnUse`,"mask-type":`alpha`},$(`image`,Object.assign({href:O},k))));let j=O,M={};o&&s&&(j=s.replace(/&/g,`&amp;`),M.mask=`url(#${o})`);let N={};i&&(N.mask=`url(#${i})`);let P=e.borderSize||0,F=P>0&&jf(e.borderColor),ee=F?`border-grad-${e.id}`:null;if(F){let t=HO(e.borderColor,ee);t&&A.push(t)}let te=P>0?$(`rect`,{x:P/2,y:P/2,width:Math.max(0,e.width-P),height:Math.max(0,e.height-P),fill:`none`,stroke:F?`url(#${ee})`:e.borderColor,"stroke-width":P,rx:Math.max(0,D-P)||void 0,ry:Math.max(0,D-P)||void 0}):null,ne=$(`g`,{},$(`defs`,{},...A),$(`image`,Object.assign(Object.assign({href:j},k),M)),te);return $(`g`,N,c?$(`g`,{transform:c},ne):ne)},GO=({element:e,type:t})=>{let n={"stroke-width":e.height,stroke:e.color,"stroke-linecap":`round`,"stroke-linejoin":`round`},r=Object.assign(Object.assign({},n),{fill:e.color}),i=Object.assign(Object.assign({},n),{fill:`none`});return t===`arrow`?$(`polyline`,Object.assign({points:`${3*e.height},${2*-e.height} 0,0 ${3*e.height},${2*e.height}`},i)):t===`triangle`?$(`polygon`,Object.assign({points:`${3*e.height},${2*-e.height} 0,0 ${3*e.height},${2*e.height}`},r)):t===`bar`?$(`polyline`,Object.assign({points:`0,${2*-e.height} 0,${2*e.height}`},i)):t===`circle`?$(`circle`,Object.assign({cx:2*e.height,cy:0,r:2*e.height},r)):t===`square`?$(`polygon`,Object.assign({points:`0,${2*-e.height} ${4*e.height},${2*-e.height} ${4*e.height},${2*e.height} 0,${2*e.height}`},r)):null},KO={image:WO,svg:WO,text:async({element:e,page:t,store:n})=>{let r=jf(e.fill),i=jf(e.stroke);if(e.curveEnabled){let t=jp(e.width,e.height,e.curvePower,e.fontSize),n=`curve-path-${e.id}`,a=(Qf(e.text).replace(/\n/g,` `),ep(e.text)),o={fontWeight:e.fontWeight||`normal`,fontStyle:e.fontStyle||`normal`,fill:e.fill||`black`},s=Fp(a,o),c=Fp(a,o,{omitColors:!0}),l=e.backgroundPadding*(e.fontSize*e.lineHeight*.5),u=e.backgroundEnabled?$(`rect`,{x:-l,y:-l,width:e.width+2*l,height:e.height+2*l,fill:e.backgroundColor,opacity:e.backgroundOpacity,rx:e.backgroundCornerRadius*(e.fontSize*e.lineHeight*.5),ry:e.backgroundCornerRadius*(e.fontSize*e.lineHeight*.5)}):null,d=[$(`path`,{id:n,d:t,fill:`none`})],f=e.strokeWidth&&(i||r&&!i);if(r){let t=`curve-fill-grad-${e.id}`,n=HO(e.fill,t);n&&d.push(n)}if(i&&e.strokeWidth){let t=`curve-stroke-grad-${e.id}`,n=HO(e.stroke,t);n&&d.push(n)}if(f){let t={"font-size":e.fontSize+`px`,"text-anchor":`middle`,"dominant-baseline":`central`,"font-family":e.fontFamily,"font-style":e.fontStyle,"font-weight":e.fontWeight,"text-decoration":e.textDecoration||void 0,"letter-spacing":e.letterSpacing*e.fontSize+`px`},a=i?`url(#curve-stroke-grad-${e.id})`:e.stroke,o=$(`text`,Object.assign(Object.assign({},t),{fill:a,"stroke-width":e.strokeWidth,stroke:a}),$(`textPath`,{href:`#${n}`,startOffset:`50%`,innerHTML:c})),l=r?`url(#curve-fill-grad-${e.id})`:e.fill,f=$(`text`,Object.assign(Object.assign({},t),{fill:l}),$(`textPath`,{href:`#${n}`,startOffset:`50%`,innerHTML:s}));return $(`g`,{},u,$(`defs`,{},...d),o,f)}return $(`g`,{},u,$(`defs`,{},...d),$(`text`,{fill:r?`url(#curve-fill-grad-${e.id})`:e.fill,"font-size":e.fontSize+`px`,"text-anchor":`middle`,"dominant-baseline":`central`,"font-family":e.fontFamily,"font-style":e.fontStyle,"font-weight":e.fontWeight,"text-decoration":e.textDecoration||void 0,"letter-spacing":e.letterSpacing*e.fontSize+`px`,"stroke-width":e.strokeWidth||void 0,stroke:e.strokeWidth?i?`url(#curve-stroke-grad-${e.id})`:e.stroke:void 0,"paint-order":e.strokeWidth?`stroke fill`:void 0},$(`textPath`,{href:`#${n}`,startOffset:`50%`,innerHTML:s})))}let a=(e,t,n,r,i,a=0)=>{let o=document.createElement(`canvas`).getContext(`2d`);return o.font=`${i} ${r} ${t}px ${n}`,o.measureText(e).width+Math.max(0,(e?e.length:0)-1)*a*t},o=(e,t,n,r,i,o,s=0)=>{let c=[];return e.split(`
288
- `).forEach(e=>{let l=e.split(` `),u=``;for(let e=0;e<l.length;e++){let d=u+l[e]+` `;a(d,n,r,i,o,s)>t+.5&&e>0?(c.push(u.trim()),u=l[e]+` `):u=d}c.push(u.trim())}),c},s=Qf(e.text);e.textTransform==`uppercase`&&(s=s.toUpperCase());let c=e.fontSize,l=[];for(;;){l=o(s,e.width,c,e.fontFamily,e.fontWeight,e.fontStyle,e.letterSpacing);let t=Math.max(...l.map(t=>a(t,c,e.fontFamily,e.fontWeight,e.fontStyle,e.letterSpacing))),n=l.length*c*e.lineHeight;if(t<=e.width&&n<=e.height||(--c,c<4))break}let u=c*e.lineHeight,d=l.length*u,f=c;e.verticalAlign===`middle`?f=(e.height-d)/2+c:e.verticalAlign===`bottom`&&(f=e.height-d+c);let p=e.align===`center`?`middle`:e.align===`right`?`end`:`start`,m=l.map((t,n)=>$(`tspan`,{x:e.align===`center`?e.width/2:e.align===`right`?e.width:0,dy:n===0?0:u,innerHTML:t})),h=e.backgroundPadding*(c*e.lineHeight*.5),g=e.backgroundEnabled?$(`rect`,{x:-h,y:-h,width:e.width+2*h,height:e.height+2*h,fill:e.backgroundColor,opacity:e.backgroundOpacity,rx:e.backgroundCornerRadius*(c*e.lineHeight*.5),ry:e.backgroundCornerRadius*(c*e.lineHeight*.5)}):null,_=[],v=e.strokeWidth&&(i||r&&!i);if(r){let t=`text-fill-grad-${e.id}`,n=HO(e.fill,t);n&&_.push(n)}if(i&&e.strokeWidth){let t=`text-stroke-grad-${e.id}`,n=HO(e.stroke,t);n&&_.push(n)}if(v){let t={y:f,"font-size":c+`px`,"text-anchor":p,"font-family":e.fontFamily,"font-style":e.fontStyle,"font-weight":e.fontWeight,"text-decoration":e.textDecoration,"line-height":e.lineHeight,"letter-spacing":e.letterSpacing*c+`px`},n=i?`url(#text-stroke-grad-${e.id})`:e.stroke,a=$(`text`,Object.assign(Object.assign({},t),{fill:n,"stroke-width":e.strokeWidth,stroke:n}),...m.map(e=>$(`tspan`,e.props,e.props.innerHTML))),o=r?`url(#text-fill-grad-${e.id})`:e.fill,s=$(`text`,Object.assign(Object.assign({},t),{fill:o}),...m.map(e=>$(`tspan`,e.props,e.props.innerHTML)));return $(`g`,{},g,_.length>0?$(`defs`,{},..._):null,a,s)}return $(`g`,{},g,_.length>0?$(`defs`,{},..._):null,$(`text`,{fill:r?`url(#text-fill-grad-${e.id})`:e.fill,y:f,"font-size":c+`px`,"text-anchor":p,"font-family":e.fontFamily,"font-style":e.fontStyle,"font-weight":e.fontWeight,"text-decoration":e.textDecoration,"line-height":e.lineHeight,"letter-spacing":e.letterSpacing*c+`px`,"stroke-width":e.strokeWidth||void 0,stroke:e.strokeWidth?e.stroke:void 0,"paint-order":e.strokeWidth?`stroke fill`:void 0},...m))},line:async({element:e,page:t,store:n})=>$(`g`,{},$(`line`,{x1:0,y1:e.height/2,x2:e.width,y2:e.height/2,stroke:e.color,"stroke-width":e.height,"stroke-dasharray":e.dash&&e.dash.length?e.dash.map(t=>t*e.height).join(` `):void 0}),$(`g`,{transform:`translate(0 ${e.height/2})`},GO({element:e,type:e.startHead})),$(`g`,{transform:`translate(${e.width} ${e.height/2}) rotate(180)`},GO({element:e,type:e.endHead}))),figure:async({element:e,page:t,store:n,elementHook:r})=>{let i=function(e){let t=e.replace(/<svg[^>]*>/,``);return t=t.replace(/<\/svg>/,``),t}(DD(e)),a=[];if(e.strokeWidth&&jf(e.stroke)){let t=`figure-stroke-grad-${e.id}`,n=HO(e.stroke,t);if(n){a.push(n);let r=e.stroke.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);i=i.replace(RegExp(`stroke="${r}"`,`g`),`stroke="url(#${t})"`)}}if(jf(e.fill)){let t=`figure-fill-grad-${e.id}`,n=HO(e.fill,t);if(n){a.push(n);let r=e.fill.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);i=i.replace(RegExp(`fill="${r}"`,`g`),`fill="url(#${t})"`)}}if(a.length>0){let t=$(`g`,{},$(`defs`,{},...a),$(`g`,{innerHTML:i}));return r&&r({dom:t,element:e})||t}let o=$(`g`,{innerHTML:i});return r&&r({dom:o,element:e})||o},group:async({element:e,page:t,store:n,elementHook:r})=>{let i=await Promise.all(e.children.map(e=>qO({element:e,page:t,store:n,elementHook:r}))),a=$(`g`,{style:{"transform-origin":`top left`}},...i);return r&&r({dom:a,element:e})||a},gif:WO,table:async({element:e})=>{e.rows;let t=e.cols,n=e.colWidths,r=e.rowHeights,i=[`fontSize`,`fontFamily`,`fontWeight`,`fontStyle`,`textDecoration`,`textTransform`,`fill`,`align`,`verticalAlign`,`lineHeight`,`letterSpacing`,`strokeWidth`,`stroke`,`cellBackground`,`cellPadding`],a=(e.cells||[]).map((n,r)=>{let a=Object.assign(Object.assign({},n),{row:Math.floor(r/t),col:r%t});for(let t of i)a[t]===void 0&&(a[t]=e[t]);return a}),o=[],s=(t,i,a,o)=>{let s=0;for(let t=0;t<i;t++)s+=n[t]*e.width;let c=0;for(let n=0;n<t;n++)c+=r[n]*e.height;let l=0;for(let t=i;t<i+o;t++)l+=(n[t]||0)*e.width;let u=0;for(let n=t;n<t+a;n++)u+=(r[n]||0)*e.height;return{x:s,y:c,width:l,height:u}};for(let e of a)if(!e.mergedInto&&e.cellBackground&&e.cellBackground!==`transparent`){s(e.row,e.col,e.colSpan||1,e.colSpan||1);let{x:t,y:n,width:r,height:i}=s(e.row,e.col,e.rowSpan||1,e.colSpan||1);o.push($(`rect`,{x:t,y:n,width:r,height:i,fill:e.cellBackground}))}let c=(e,t)=>e===`dashed`?`${4*t},${2*t}`:e===`dotted`?`${t},${t}`:void 0,l=(t,n)=>{let r=t.borders?.[n];return{width:r?.width??e.borderWidth,style:r?.style??e.borderStyle??`solid`,color:r?.color??e.borderColor}};for(let e of a){if(e.mergedInto)continue;let t=s(e.row,e.col,e.rowSpan||1,e.colSpan||1);if(e.row===0){let n=l(e,`top`);n.style!==`none`&&n.width>0&&o.push($(`line`,{x1:t.x,y1:t.y+n.width/2,x2:t.x+t.width,y2:t.y+n.width/2,stroke:n.color,"stroke-width":n.width,"stroke-dasharray":c(n.style,n.width)}))}if(e.col===0){let n=l(e,`left`);n.style!==`none`&&n.width>0&&o.push($(`line`,{x1:t.x+n.width/2,y1:t.y,x2:t.x+n.width/2,y2:t.y+t.height,stroke:n.color,"stroke-width":n.width,"stroke-dasharray":c(n.style,n.width)}))}{let n=l(e,`bottom`);n.style!==`none`&&n.width>0&&o.push($(`line`,{x1:t.x,y1:t.y+t.height-n.width/2,x2:t.x+t.width,y2:t.y+t.height-n.width/2,stroke:n.color,"stroke-width":n.width,"stroke-dasharray":c(n.style,n.width)}))}{let n=l(e,`right`);n.style!==`none`&&n.width>0&&o.push($(`line`,{x1:t.x+t.width-n.width/2,y1:t.y,x2:t.x+t.width-n.width/2,y2:t.y+t.height,stroke:n.color,"stroke-width":n.width,"stroke-dasharray":c(n.style,n.width)}))}}for(let t of a){if(t.mergedInto)continue;let i=Qf(t.text||``);if(!i)continue;t.textTransform===`uppercase`&&(i=i.toUpperCase());let a=t.cellPadding||4,s=0;for(let r=0;r<t.col;r++)s+=n[r]*e.width;let c=0;for(let n=0;n<t.row;n++)c+=r[n]*e.height;let l=n[t.col]*e.width,u=r[t.row]*e.height,d=t.fontSize||12,f=t.align||`left`,p=s+a,m=`start`;f===`center`?(p=s+l/2,m=`middle`):f===`right`&&(p=s+l-a,m=`end`);let h=c+a+d,g=t.verticalAlign||`top`;g===`middle`?h=c+u/2+d/3:g===`bottom`&&(h=c+u-a),o.push($(`text`,{x:p,y:h,"font-size":d,"font-family":t.fontFamily||`Roboto`,"font-weight":t.fontWeight||`normal`,"font-style":t.fontStyle||`normal`,fill:t.fill||`black`,"text-anchor":m,"text-decoration":t.textDecoration||`none`,"letter-spacing":t.letterSpacing?t.letterSpacing*d+`px`:void 0},i))}return $(`g`,{},...o)}};async function qO({element:e,page:t,store:n,elementHook:r}){var i;let a=await KO[e.type];a||(a=()=>$(`g`,{}),console.error(`SVG export does not support ${e.type} type...`));let o=await a({element:e,page:t,store:n}),s=[],c=[];if(e.blurEnabled&&s.push(`blur(${e.blurRadius/2}px)`),e.brightnessEnabled&&s.push(`brightness(${100*e.brightness+100}%)`),e.sepiaEnabled&&s.push(`sepia()`),e.grayscaleEnabled&&s.push(`grayscale()`),e.shadowEnabled&&s.push(`drop-shadow(${e.shadowOffsetX}px ${e.shadowOffsetY}px ${e.shadowBlur}px ${e.shadowColor})`),e.filters)for(let[t,n]of Object.entries(e.filters)){let e=DO(EO[t],n.intensity);if(e&&(s.push(e.filter),e.html)){let t=e.html.replace(/<svg([^>]*)>/,`<g$1>`).replace(/<\/svg>/,`</g>`);c.push(t)}}let l=$(`g`,{className:`element`,id:e.id,transform:e.type===`group`?void 0:`translate(${e.x}, ${e.y}) rotate(${e.rotation})`,display:(i=e.visible)==null||i?void 0:`none`,opacity:e.opacity,style:{"transform-origin":`top left`,filter:s.join(` `)}},o,...c);return r&&r({dom:l,element:e})||l}async function JO(e){try{let t=await fetch(e),n=t.headers.get(`content-type`)||`font/ttf`,r=await t.arrayBuffer();return`data:${n};base64,${typeof Buffer<`u`?Buffer.from(r).toString(`base64`):function(e){let t=new Uint8Array(e),n=``;for(let e=0;e<t.length;e+=32768){let r=t.subarray(e,e+32768);n+=String.fromCharCode(...r)}if(typeof btoa<`u`)return btoa(n);if(typeof Buffer<`u`)return Buffer.from(t).toString(`base64`);throw Error(`No base64 encoder available in this environment`)}(r)}`}catch(t){return console.error(`Error embedding font:`,t),e}}async function YO({json:e,elementHook:t,fontEmbedding:n=`inline`}){let r=[];VO({children:e.pages},e=>{e.type!==`text`&&e.type!==`tablecell`&&e.type!==`table`||!e.fontFamily||r.indexOf(e.fontFamily)!==-1||r.push(e.fontFamily)});let i=n===`inline`?await async function(e,t){return await Promise.all(e.map(async e=>{if(e===`Arial`)return null;let n=t.find(t=>t.fontFamily===e);if(n)return $(`style`,{},`@font-face { font-family: ${e}; src: url(${await JO(n.url)}); }`);{let t=`https://fonts.googleapis.com/css?family=${e}:bi,normal,i,b`;try{let n=await(await fetch(t)).text(),r=(n.match(/url\((.*?)\)/g)?.map(e=>e.replace(/url\((.*?)\)/,`$1`)))?.filter(e=>e.startsWith(`https`));if(!r?.length)throw Error(`No font URLs found`);return $(`style`,{},(await Promise.all(r.map(async t=>{let r=await JO(t),i=n.match(/font-style:\s*(.*?);/),a=n.match(/font-weight:\s*(.*?);/);return`@font-face {\n font-family: ${e};\n font-style: ${i?i[1]:`normal`};\n font-weight: ${a?a[1]:`normal`};\n src: url(${r});\n }`}))).join(`
289
- `))}catch(e){return console.error(`Error embedding Google Font:`,e),$(`defs`,{},$(`style`,{type:`text/css`,innerHTML:`@import url('${t}');`.replace(/&/g,`&amp;`)}))}}}))}(r,e.fonts):[],a=await Promise.all(e.pages.map(n=>async function({page:e,store:t,elementHook:n}){let r=await Promise.all(e.children.map(r=>qO({element:r,page:e,store:t,elementHook:n}))),i=e.background.indexOf(`url`)>=0||e.background.indexOf(`http`)>=0||e.background.indexOf(`.jpg`)>=0||e.background.indexOf(`.png`)>=0||e.background.indexOf(`.jpeg`)>=0,a;if(i){let n=await CO(e.background);a=await wO(e.background,Object.assign({width:t.width,height:t.height,x:0,y:0},TO({width:t.width,height:t.height},{width:n.width,height:n.height})))}return $(`g`,{className:`page`,style:{}},i?$(`image`,{"xlink:href":a,x:0,y:0,width:t.width,height:t.height,preserveAspectRatio:`none`}):$(`rect`,{x:0,y:0,width:t.width,height:t.height,fill:i?void 0:e.background}),...r)}({page:n,store:e,elementHook:t})));return $(`svg`,{xmlns:`http://www.w3.org/2000/svg`,"xmlns:xlink":`http://www.w3.org/1999/xlink`,viewBox:`0 0 ${e.width} ${e.height}`,width:e.width,height:e.height},...i,...a)}var XO=({dom:e,nestLevel:t=0})=>{if(typeof e==`string`)return e;if(!e)return``;let n=e.props,{innerHTML:r}=n,i=BO(n,[`innerHTML`]),a=Object.keys(i).map(e=>((e,t)=>typeof t==`object`?`${e}="${Object.keys(t).map(e=>`${e}:${t[e]};`).join(` `)}"`:t==null||t===``?``:`${e}="${t}"`)(e,i[e])).filter(e=>e&&e.trim().length>0).join(` `),o=` `.repeat(t);return`${o}<${e.type}${a?` `+a:``}>${r||`
290
- `+e.children.map(e=>XO({dom:e,nestLevel:t+1})).join(``)}${o}</${e.type}>\n`};async function ZO({json:e,elementHook:t,fontEmbedding:n=`inline`}){return XO({dom:await YO({json:e,elementHook:t,fontEmbedding:n})})}var QO=q.model(`Page`,{id:q.identifier,children:q.array(q.late(()=>Uk)),width:q.optional(q.union(q.number,q.literal(`auto`)),`auto`),height:q.optional(q.union(q.number,q.literal(`auto`)),`auto`),background:`white`,bleed:0,custom:q.frozen(),duration:5e3,_exporting:!1,_rendering:!1,_forceMount:!1}).postProcessSnapshot(e=>{let t=Object.assign({},e),n={};for(var r in t)r[0]!==`_`&&(n[r]=e[r]);return n}).views(e=>({get store(){return am(e,nk)}})).views(e=>({get startTime(){let t=0;for(let n of e.store.pages){if(n.id===e.id)return t;t+=n.duration}return t},get _exportingOrRendering(){return e._exporting||e._rendering}})).views(e=>({get computedWidth(){return e.width===`auto`?e.store.width:e.width},get computedHeight(){return e.height===`auto`?e.store.height:e.height}})).actions(e=>({toJSON:()=>JSON.parse(JSON.stringify(nm(e))),_forEachElementUp(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));r.sort((e,t)=>t.index-e.index);for(let{index:i}of r){if(i==-1)continue;let r=i<e.children.length-1&&e.children[i+1],a=t.indexOf(r?.id)>=0;i===e.children.length-1||a||n(i)}},_forEachElementDown(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));r.sort((e,t)=>e.index-t.index);for(let{index:i}of r){if(i==-1)continue;let r=i>0&&e.children[i-1],a=t.indexOf(r?.id)>=0;i===0||a||n(i)}return!1}})).actions(e=>{let t={clone(t={}){let n=e.toJSON(),r=new Map;n.children.forEach(e=>{let t=e.id,n=UD(10);r.set(t,n),e.id=n,Vk(e,e=>{let t=e.id,n=UD(10);r.set(t,n),e.id=n})}),n.children.forEach(e=>{e.cells&&e.cells.forEach(e=>{e.mergedInto&&r.has(e.mergedInto)&&(e.mergedInto=r.get(e.mergedInto))})});let i=Object.assign(Object.assign(Object.assign({},n),{id:UD(10)}),t),a=e.store.addPage(i),o=e.store.pages.indexOf(e);return a.setZIndex(o+1),a.select(),a},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t,{skipSelect:n=!1}={}){let r=Kk[t.type];if(!r){console.error(`Can not find model with type `+t.type);return}`children`in t&&Array.isArray(t.children)&&Vk(t,e=>{e.id=e.id||UD(10)});let i=e.children.reduce((e,n)=>{if(n.type===`group`){let r=n.children.reduce((e,n)=>{let r=n.name?.match(RegExp(`${t.type}-(\\d+)`));if(r){let t=parseInt(r[1],10);return Math.max(e,t||0)}},0);return Math.max(e,r||0)}{let r=n.name.match(RegExp(`${t.type}-(\\d+)`));if(r){let t=parseInt(r[1],10);return Math.max(e,t||0)}}return e},0),a=r.create(Object.assign({id:UD(10),name:`${t.type}-${i+1}`},t));return e.children.push(a),a.selectable&&!n&&e.store.selectElements([a.id]),a},canMoveElementsUp(t){let n=!1;return e._forEachElementUp(t,()=>{n||=!0}),n},moveElementsUp(t){e._forEachElementUp(t,t=>{let n=e.children[t];um(n),e.children.splice(t+1,0,n)})},canMoveElementsTop:e=>t.canMoveElementsUp(e),moveElementsTop(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(r.concat(n))},canMoveElementsDown(t){let n=!1;return e._forEachElementDown(t,()=>{n||=!0}),n},moveElementsDown(t){e._forEachElementDown(t,t=>{let n=e.children[t];um(n),e.children.splice(t-1,0,n)})},canMoveElementsBottom:e=>t.canMoveElementsDown(e),moveElementsBottom(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(n.concat(r))},setElementZIndex(t,n){let r=e.children.find(e=>e.id===t);r&&(um(r),e.children.remove(r),e.children.splice(n,0,r))},setSize({width:t,height:n,useMagic:r,softChange:i}){if(r){let r=[],i=t=>t.type===`image`&&t.x<1&&t.y<1&&t.width>=e.computedWidth-2&&t.height>=e.computedHeight-2;Bk(e,e=>{e.type!==`group`&&(i(e)||r.push(e))});let a=r.length?ob(r):{x:0,y:0,width:e.computedWidth,height:e.computedHeight},o=1/4,s=Math.max(0,Math.min(a.x,e.computedWidth-a.x-a.width)),c=e.computedWidth*o,l=Math.max(0,s-c),u=Math.max(0,Math.min(a.y,e.computedHeight-a.y-a.height)),d=e.computedHeight*o,f=Math.max(0,u-d),p=e.computedWidth-2*l,m=e.computedHeight-2*f,h=t/p,g=n/m,_=Math.min(h,g),v=(t-p*_)/2-l*_,y=(n-m*_)/2-f*_;Bk(e,e=>{if(e.type!==`group`){if(i(e))e.set({x:e.x*_,y:e.y*_,width:e.width*h,height:e.height*g,cropX:0,cropY:0,cropWidth:1,cropHeight:1});else if(e.set({x:v+e.x*_,y:y+e.y*_,width:e.width*_,height:e.height*_}),e.type===`text`)e.set({fontSize:e.fontSize*_});else if(e.type===`figure`)e.set({strokeWidth:e.strokeWidth*_});else if(e.type===`table`){e.set({borderWidth:e.borderWidth*_});for(let t of e.cells){let e={fontSize:t.fontSize*_,cellPadding:t.cellPadding*_};if(t.borders){let n=JSON.parse(JSON.stringify(t.borders));for(let e of[`top`,`right`,`bottom`,`left`])n[e]?.width!=null&&(n[e]=Object.assign(Object.assign({},n[e]),{width:n[e].width*_}));e.borders=n}t.set(e)}}}})}i||(e.width=t),i||(e.height=n)}};return t}).actions(e=>({moveElementUp(t){console.warn(`page.moveElementUp(id) is deprecated. Please use page.moveElementsUp([id1, id2]) instead.`),e.moveElementsUp([t])},moveElementDown(t){console.warn(`page.moveElementDown(id) is deprecated. Please use page.moveElementsDown([id1, id2]) instead.`),e.moveElementsDown([t])},moveElementTop(t){console.warn(`page.moveElementTop(id) is deprecated. Please use page.moveElementsTop([id1, id2]) instead.`),e.moveElementsTop([t])},moveElementBottom(t){console.warn(`page.moveElementBottom(id) is deprecated. Please use page.moveElementsBottom([id1, id2]) instead.`),e.moveElementsBottom([t])},play(){e.store.play({startTime:e.startTime,endTime:e.startTime+e.duration})}})),$O=q.model(`Audio`,{id:q.identifier,src:``,duration:0,startTime:0,endTime:1,volume:1,delay:0,custom:q.frozen()}).actions(e=>({toJSON:()=>Object.assign({},nm(e))})).actions(e=>({set(t){Object.assign(e,t)}})),ek=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n};Hp(`ignore`);var tk=q.model(`Font`,{fontFamily:q.string,url:q.optional(q.string,``),styles:q.frozen()}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name})),nk=q.model(`Store`,{role:``,pages:q.array(QO),fonts:q.array(tk),audios:q.array($O),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:q.optional(q.enumeration(`UnitType`,[`pt`,`mm`,`cm`,`in`,`px`]),`px`),dpi:72,schemaVersion:2,bleedVisible:!1,rulesVisible:!1,distanceGuidesVisible:!1,openedSidePanel:``,previousOpenedSidePanel:``,custom:q.frozen(),tool:q.optional(q.enumeration(`Tool`,[`selection`,`draw`,`pan`,`text`,`eraser`]),`selection`),toolOptions:q.optional(q.model({brushType:q.optional(q.enumeration(`BrushType`,[`brush`,`highlighter`]),`brush`),strokeWidth:q.optional(q.number,5),stroke:q.optional(q.string,`#000000`),opacity:q.optional(q.number,1)}),{}),selectedElementsIds:q.array(q.string),animatedElementsIds:q.array(q.string),history:q.optional(GD,{targetPath:`../pages`}),_elementsPixelRatio:Math.min(2,typeof window<`u`&&window.devicePixelRatio||1),_activePageId:``,_selectedPagesIds:q.array(q.string),_forceShowCredit:!1,_key:``,_validated:!1}).views(e=>{let t=jt(()=>{let t={};return Vk({children:e.pages},e=>(t[e.id]=e,!1)),t},{keepAlive:!0});return{get _idsMap(){return t.get()}}}).views(e=>({get _bleedVisible(){return console.warn(`store._bleedVisible is deprecated. Please use store.bleedVisible instead.`),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map(t=>{for(let n of e.pages)for(let e of n.children)if(e.id===t)return e}).filter(e=>!!e)},get children(){return e.pages},get selectedShapes(){let e=[];return Bk({children:this.selectedElements},t=>{t.type!==`group`&&e.push(t)}),e},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)},get selectedPages(){return e._selectedPagesIds.map(t=>e.pages.find(e=>e.id===t))},get duration(){let t=0;return e.pages.forEach(e=>{t+=e.duration}),t},get _hasCroppedImages(){return this.find(e=>e.type===`image`&&e._cropModeEnabled)},find(t){let n;return Vk({children:e.pages},e=>{if(!n&&t(e))return n=e,!0}),n},getElementById:t=>e._idsMap[t]})).actions(e=>{let t=0,n=null,r=!1,i={afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},_togglePlaying(t=!e.isPlaying){e.isPlaying=t},play({animatedElementsIds:a=[],startTime:o=0,currentTime:s=0,endTime:c=e.duration,repeat:l=!1}={}){s&&(console.warn(`currentTime property of store.play() is deprecated. Please use startTime instead.`),o=s),e.animatedElementsIds=pm(a),e.currentTime=o,e.isPlaying=!0,t=Date.now(),n=c,r=l,requestAnimationFrame(()=>i.seek())},checkActivePage(){let t=0;for(let n of e.pages){if(e.currentTime>=n.startTime&&e.currentTime<n.startTime+n.duration){i.selectPage(n.id);break}t+=n.duration}},seek(){if(!e.isPlaying)return;let a=Date.now(),o=a-t;t=a,e.currentTime+=o,i.checkActivePage();let s=n||e.duration;e.isPlaying&&e.currentTime<s?requestAnimationFrame(()=>i.seek()):e.isPlaying&&r?(e.currentTime=0,requestAnimationFrame(()=>i.seek())):i.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=pm([]),i.checkActivePage()},__(){e._validated||=(fO(e._key,e._forceShowCredit),!0)},set(t){Object.assign(e,t)},setUnit({unit:t,dpi:n}){e.unit=t||e.unit,e.dpi=n||e.dpi},setRole(t){e.role=t},setTool(t){e.tool=t},setToolOptions(t){Object.assign(e.toolOptions,t)},addPage(t){let n=QO.create(Object.assign({id:UD(10)},t));return e.pages.push(n),e._activePageId=n.id,n},selectPage(t){e._activePageId=t,e._selectedPagesIds.length===1&&(e._selectedPagesIds=pm([t]))},selectPages(t){e._selectedPagesIds=pm(t),e._selectedPagesIds.length===1&&(e._activePageId=e._selectedPagesIds[0])},selectElements(t){e.selectedElementsIds=pm(t.map(t=>e.getElementById(t)).sort((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t)).filter(e=>!!e).map(e=>e.id))},toggleBleed(t){e.bleedVisible=t??!e.bleedVisible},toggleRulers(t){e.rulesVisible=t??!e.rulesVisible},toggleDistanceGuides(t){e.distanceGuidesVisible=t??!e.distanceGuidesVisible},openSidePanel(t){e.openedSidePanel!==t&&(e.previousOpenedSidePanel=e.openedSidePanel,e.openedSidePanel=t)},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,n,r){e.pages.forEach(e=>{e.setSize({width:t,height:n,useMagic:r,softChange:!0})}),e.width=t,e.height=n},setPageZIndex(t,n){let r=e.pages.find(e=>e.id===t);r&&(um(r),e.pages.remove(r),e.pages.splice(n,0,r))},deletePages(t){let n=e.pages.indexOf(e.activePage);t.forEach(t=>{dm(e.pages.find(e=>e.id===t))});let r=Math.min(e.pages.length-1,n),i=e.pages[r];i&&(e._activePageId=i.id),e.selectedElementsIds=pm(e.selectedElementsIds.filter(t=>e.getElementById(t)))},groupElements(t,n={}){let r=t.map(t=>e.getElementById(t)),i=r[0].page;if(r.forEach(e=>{e&&um(e)}),!r.length)return;let a=i.children.reduce((e,t)=>{if(t.type===`group`){let n=t.name.match(/group-(\d+)/);if(n){let t=parseInt(n[1],10);return Math.max(e,t)}}return e},0),o=Object.assign({id:UD(10),name:`group-${a+1}`,children:r,type:`group`},n);return i.children.push(o),e.selectedElementsIds=pm([o.id]),i.children.find(e=>e.id===o.id)},ungroupElements(t){let n=t.map(t=>e.getElementById(t)),r=[];n.forEach(e=>{if(e&&e.type===`group`){let t=e.page,n=t.children.indexOf(e);e.children.forEach(e=>{r.push(e.id)}),e.children.forEach(e=>{um(e),t.children.push(e)}),t.children.splice(n,1)}}),e.selectedElementsIds=pm(r)},deleteElements(t){let n=[];e.find(e=>(t.includes(e.id)&&n.push(e),!1)),n.forEach(e=>{dm(e)}),e.selectedElementsIds=pm(e.selectedElementsIds.filter(t=>e.getElementById(t)))},on(t,n){if(t===`change`){let t=i.toJSON();return $p(e,e=>{let r=i.toJSON();!WD(t,r)&&(t=r,n(r))})}},async _toCanvas({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:a,includeBleed:o,_skipTimeout:s,quickMode:c=!1,_exportCanvases:l}={}){let u=t||1;r||=e.pages[0]?.id;let d=e.pages.find(e=>e.id===r);if(!d)throw Error(`No page for export with id ${r}`);let f=e._elementsPixelRatio;u>e._elementsPixelRatio&&i.setElementsPixelRatio(u),c?d?.set({_forceMount:!0}):d?.set({_exporting:!0});let p=await SO(()=>{let e=Du.stages.filter(e=>e.getAttr(`pageId`)===r);return e.length===0?null:e});if(!p)throw d?.set({_forceMount:!1,_exporting:!1}),i.setElementsPixelRatio(f),Error(`Export is failed. Can not find stage for page ${r}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);p.length>1&&console.error(`Polotno error: Detected several canvas elements for page "${r}" in the document. This is not supported and will lead to incorrect export. Make sure to use unique ids for all pages and make sure you unmount <Workspace /> when it is not needed.`);let m=p[0];await i.waitLoading({_skipTimeout:s});let h=m.findOne(`.page-container`);if(!h)throw i.setElementsPixelRatio(f),d?.set({_forceMount:!1,_exporting:!1}),Error(`Export is failed. Canvas was unmounted.`);let g=m.position();m.position({x:0,y:0}),m.find(`Transformer`).forEach(e=>{e.setAttr(`oldVisible`,e.visible()),e.visible(!1)}),h.find(`.page-background`).forEach(e=>e.shadowEnabled(!1)),h.find(`.page-background`).forEach(e=>e.strokeEnabled(!1)),h.find(`.highlighter`).forEach(e=>e.visible(!1));let _=h.findOne(`.page-background-group`),v=_.clip();_.clip({x:null,y:null,width:null,height:null});let y=h.findOne(`.elements-container`),b=y.clip();y.clip({x:null,y:null,width:null,height:null});let x=h.find(e=>!e.visible()&&e.getAttr(`editModeEnabled`)&&!e.getAttr(`hideInExport`));x.forEach(e=>{e.setAttr(`oldVisible`,e.visible()),e.show()});let S=h.find(e=>e.getAttr(`hideInExport`));S.forEach(e=>{e.setAttr(`oldVisible`,e.visible()),e.hide()}),n&&h.find(`.page-background`).forEach(e=>e.hide());let C=o?d.bleed:0,w=C;!e.bleedVisible&&o||(e.bleedVisible||o?e.bleedVisible&&o?w=0:e.bleedVisible&&!o&&(w=-d.bleed):w=0);let T=d.computedWidth+2*C,E=d.computedHeight+2*C,D=h.scale();h.scale({x:1,y:1});let O=X_(h,{x:h.x()-w,y:h.y()-w,width:T,height:E,pixelRatio:u,sceneCanvas:l?.sceneCanvas,bufferCanvas:l?.bufferCanvas});h.scale(D);let k=O._canvas;if(a===`image/jpeg`){let e=k.getContext(`2d`);e.save(),e.globalCompositeOperation=`destination-over`,e.fillStyle=`white`,e.fillRect(0,0,k.width,k.height),e.restore()}return n&&h.find(`.page-background`).forEach(e=>e.show()),S.forEach(e=>{e.visible(e.getAttr(`oldVisible`))}),x.forEach(e=>{e.visible(e.getAttr(`oldVisible`))}),h.find(`.page-background`).forEach(e=>e.shadowEnabled(!0)),h.find(`.page-background`).forEach(e=>e.strokeEnabled(!0)),m.find(`Transformer`).forEach(e=>{e.visible(e.getAttr(`oldVisible`))}),h.find(`.highlighter`).forEach(e=>e.visible(!0)),_.clip(v),y.clip(b),m.position(g),d?.set({_exporting:!1,_forceMount:!1}),await Promise.resolve(),i.setElementsPixelRatio(f),k},async toDataURL(t={}){var{mimeType:n,quality:r,dpi:a,dpiMetadata:o=`auto`}=t,s=ek(t,[`mimeType`,`quality`,`dpi`,`dpiMetadata`]);let c=await i._toCanvas(Object.assign({mimeType:n},s)),l=n||`image/png`,u=c.toDataURL(l,r);Du.Util.releaseCanvas(c);let d=a??e.dpi;return l!==`image/png`&&l!==`image/jpeg`||o===`never`||o===`auto`&&d===72?u:_O(u,l,d)},async toBlob(e={}){var{mimeType:t,quality:n}=e,r=ek(e,[`mimeType`,`quality`]);let a=await i._toCanvas(Object.assign({mimeType:t},r)),o=await new Promise(e=>{a.toBlob(e,t,n)});return Du.Util.releaseCanvas(a),o},async saveAsImage(e={}){var{fileName:t}=e,n=ek(e,[`fileName`]);let r=(n.mimeType||`image/png`).split(`/`)[1];KD(await i.toDataURL(n),t||`polotno.`+r)},async _toPDF(t){let n=t.dpi||e.dpi,r=t.parallel||1,a=t.unit||(e.unit===`px`?`mm`:e.unit),o=t.pixelRatio||1,s=t.pageIds||e.pages.map(e=>e.id),c=e.pages.filter(e=>s.includes(e.id)),l=await JD(),u=e=>vO({px:e,unit:a,dpi:n}),d=t.cropMarkSize||0,f=u(d),p=c[0]||{},m=t.includeBleed?p.bleed:0,h=u(p.computedWidth+2*m+2*f),g=u(p.computedHeight+2*m+2*f);var _=new l({unit:a,orientation:h>g?`landscape`:`portrait`,format:[h,g],compress:!0,putOnlyUsedFonts:!0});_.deletePage(1);let v=((e,t)=>{let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n})(c,r),y=0;for(let e of v){let n=e.map(async e=>{let n=t.includeBleed?e.bleed:0,r=e.computedWidth+2*n+2*d,a=e.computedHeight+2*n+2*d,c=u(r),l=u(a),f=0,p=o;for(;f<10;){f+=1;let n=await i.toDataURL(Object.assign(Object.assign({},t),{pageId:e.id,pixelRatio:p,dpiMetadata:`never`}));if(n.length>20)return p!==o&&console.error(`Polotno can not export PDF with current settings. Quality is automatically reduced. pixelRatio was reduced to ${parseFloat(p.toFixed(3))}.`),t.onProgress&&t.onProgress(++y/s.length*.9),{url:n,width:c,height:l,widthPx:r,heightPx:a};p*=.8}});(await Promise.all(n)).filter(e=>e!==void 0).forEach(({url:e,width:t,height:n,widthPx:r,heightPx:i})=>{_.addPage([t,n],t>n?`landscape`:`portrait`);let o=_.getCurrentPageInfo();var s;switch(a){case`pt`:s=1;break;case`mm`:s=72/25.4;break;case`cm`:s=72/2.54;break;case`in`:s=72;break;case`px`:s=.75;break;default:throw`Invalid unit: `+a}if(o.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*s,topRightY:n*s},o.pageContext.artBox={bottomLeftX:u(d+m)*s,bottomLeftY:u(d+m)*s,topRightX:u(r-d-m)*s,topRightY:u(i-d-m)*s},o.pageContext.bleedBox={bottomLeftX:u(d+m)*s,bottomLeftY:u(d+m)*s,topRightX:u(r-d-m)*s,topRightY:u(i-d-m)*s},f){_.setLineWidth(u(1));let e=f+u(m);_.line(e,0,e,f),_.line(0,e,f,e),_.line(t-e,0,t-e,f),_.line(t,e,t-f,e),_.line(0,n-e,f,n-e),_.line(e,n,e,n-f),_.line(t,n-e,t-f,n-e),_.line(t-e,n,t-e,n-f)}_.addImage(e,f,f,t-2*f,n-2*f,void 0,`FAST`)})}return _},toPDFDataURL:async e=>(await i._toPDF(Object.assign({mimeType:`image/jpeg`},e))).output(`datauristring`),async toGIFDataURL(t={}){let n=t.pixelRatio||1,r=await XD({width:e.width*n,height:e.height*n}),a=1e3/(t.fps||10),o=e.duration/a;for(let t=0;t<o-1;t++){let o=t*a||1;i.setCurrentTime(o);let s=0,c=``;for(let t of e.pages)if(s+=t.duration,t.set({_rendering:s>o}),s>o){c=t.id;break}let l=await i._toCanvas({pixelRatio:n,pageId:c,_skipTimeout:!0});r.addFrame(l.getContext(`2d`),{delay:a,copy:!0})}for(let t of e.pages)t.set({_rendering:!1});return i.stop(),r.render(),new Promise(e=>{r.on(`finished`,function(t){(function(e,t){var n=new FileReader;n.onload=function(e){t(e.target.result)},n.readAsDataURL(e)})(t,e)})})},async saveAsGIF(e={}){var{fileName:t}=e,n=ek(e,[`fileName`]);KD(await i.toGIFDataURL(n),t||`polotno.gif`)},async toHTML({elementHook:e}={}){return zO({json:i.toJSON(),elementHook:e})},async saveAsHTML({fileName:e,elementHook:t}={}){let n=await i.toHTML({elementHook:t});KD(`data:text/html;base64,`+window.btoa(unescape(encodeURIComponent(n))),e||`polotno.html`)},async toSVG({elementHook:e,pageId:t,fontEmbedding:n=`inline`}={fontEmbedding:`inline`}){let r=i.toJSON();t||=r.pages[0]?.id;let a=r.pages.find(e=>e.id===t);return ZO({json:Object.assign(Object.assign({},r),{pages:a?[a]:[]}),elementHook:e,fontEmbedding:n})},async saveAsSVG({fileName:e,elementHook:t,pageId:n,fontEmbedding:r=`inline`}={}){let a=await i.toSVG({elementHook:t,pageId:n,fontEmbedding:r});KD(`data:text/svg;base64,`+window.btoa(unescape(encodeURIComponent(a))),e||`polotno.svg`)},async saveAsPDF(e={}){var{fileName:t}=e,n=ek(e,[`fileName`]);(await i._toPDF(Object.assign({mimeType:`image/jpeg`},n))).save(t||`polotno.pdf`)},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise(e=>setTimeout(e,50)),await Jf()},toJSON:()=>({width:e.width,height:e.height,fonts:nm(e.fonts),pages:nm(e.pages),audios:nm(e.audios),unit:e.unit,dpi:e.dpi,custom:e.custom,schemaVersion:e.schemaVersion}),loadJSON(t,n=!1){let r=JSON.parse(JSON.stringify(t)),i=r.schemaVersion||0;i<1&&yp.htmlRenderEnabled&&Vk({children:r.pages},e=>{e.type===`text`&&(e.letterSpacing=e.letterSpacing*16/e.fontSize)}),i<2&&Vk({children:r.pages},e=>{e.filters&&Object.keys(e.filters).forEach(t=>{if([`warm`,`cold`,`natural`].includes(t))return;let n=e.filters[t];n&&typeof n.intensity==`number`&&(n.intensity/=100)})}),delete r.schemaVersion;let a=e.activePage?e.pages.indexOf(e.activePage):0;r._activePageId=(r.pages[a]||r.pages[0])?.id;let o=Object.assign({},nm(e));Object.assign(o,r),o.history=n?nm(e.history):{history:[],undoIdx:-1,targetPath:``},tm(e,o)},clear({keepHistory:t=!1}={}){let n=e.pages.map(e=>e.id);i.deletePages(n),e.custom=null,t||e.history.clear()},addFont(t){i.removeFont(t.fontFamily),e.fonts.push(t)},removeFont(t){e.fonts.filter(e=>e.fontFamily===t).forEach(e=>dm(e))},addAudio(t){let n=$O.create(Object.assign({id:UD(10)},t));e.audios.push(n)},removeAudio(t){let n=e.audios.find(e=>e.id===t);n&&e.audios.remove(n)},async loadFont(t,n,r,i){let a=e.fonts.find(e=>e.fontFamily===t)||np.find(e=>e.fontFamily===t),o=[{fontStyle:`normal`,fontWeight:`normal`},{fontStyle:`normal`,fontWeight:`bold`}];return a?(a.styles&&(o=a.styles.map(e=>({fontStyle:e.fontStyle||`normal`,fontWeight:e.fontWeight||`normal`}))),vp(a)):hp(t),n&&r&&!o.some(e=>e.fontStyle===n&&e.fontWeight===r)&&o.push({fontStyle:n,fontWeight:r}),Promise.all(o.map(e=>up(t,e.fontStyle,e.fontWeight,i)))},validate:e=>nk.validate(e,[{path:``,type:nk}]).map(e=>({path:`store`+e.context.map(e=>e.path).join(`.`),message:e.message}))};return i});function rk({key:e,showCredit:t}={key:``,showCredit:!1}){return nk.create({_forceShowCredit:t,_key:e})}var ik=q.model(`Node`,{id:q.identifier,type:`none`,name:``,opacity:1,custom:q.frozen(),visible:!0,selectable:!0,removable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot(e=>{for(var t in e)e[t]===null&&(e[t]=void 0);return e}).postProcessSnapshot(e=>{let t=Object.assign({},e),n={};for(var r in t)r[0]!==`_`&&(n[r]=e[r]);return n}).views(e=>({get page(){return am(e,QO)},get store(){return am(e,nk)},get top(){let t=e;for(;;){if(!im(t,Wk))return t;t=am(t,Wk)}},get parent(){if(im(e,Wk)){let t=am(e,Wk);return t&&t.children&&t.children.length,t}if(im(e,QO)){let t=am(e,QO);return t&&t.children&&t.children.length,t}if(im(e,nk)){let t=am(e,nk);return t&&t.pages&&t.pages.length,t}return null},get zIndex(){return e.parent.children.indexOf(e)}})).actions(e=>({toJSON:()=>Object.assign({},nm(e))})).actions(e=>({clone(t={},{skipSelect:n=!1}={}){let r=JSON.parse(JSON.stringify(e.toJSON()));t.id=t.id||UD(10);let i=new Map;return Vk(r,e=>{let t=e.id,n=UD(10);i.set(t,n),e.id=n}),Vk(r,e=>{e.mergedInto&&i.has(e.mergedInto)&&(e.mergedInto=i.get(e.mergedInto))}),Object.assign(r,t),e.page.addElement(r,{skipSelect:n})},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementsUp([e.id])},moveTop(){e.page.moveElementsTop([e.id])},moveDown(){e.page.moveElementsDown([e.id])},moveBottom(){e.page.moveElementsBottom([e.id])},setZIndex(t){e.parent.setElementZIndex(e.id,t)},beforeDestroy(){}})),ak={right:{from:{x:-200},to:{x:0}},left:{from:{x:200},to:{x:0}},up:{from:{y:200},to:{y:0}},down:{from:{y:-200},to:{y:0}},"bottom-right":{from:{x:-200,y:-200},to:{x:0,y:0}},"bottom-left":{from:{x:200,y:-200},to:{x:0,y:0}},"top-right":{from:{x:-200,y:200},to:{x:0,y:0}},"top-left":{from:{x:200,y:200},to:{x:0,y:0}}},ok={right:{cropX:-1},left:{cropX:1},up:{cropY:1},down:{cropY:-1}},sk={none:()=>({}),fade:({dTime:e,element:t,animation:n})=>{let r=e/n.duration;return n.type===`enter`?{opacity:r*t.opacity}:{opacity:(1-r)*t.opacity}},rotate:({dTime:e,element:t,animation:n})=>{let r=e/n.duration*360;return lb({x:t.x,y:t.y,width:t.width,height:t.height,rotation:t.rotation},r)},blink:({dTime:e,element:t,animation:n})=>{let r=n.duration,i=e%r/(r/2),a=i<=1?i:2-i;return{opacity:t.opacity*a}},bounce:({dTime:e,element:t,animation:n})=>{let r=n.duration,i=r/2,a=n.data.strength??1,o={},s={x:t.x+t.width/3*a,y:t.y+t.height/3*a,width:t.width/3*a,height:t.height/3*a,fontSize:t.fontSize/3*a},c={x:t.x,y:t.y,width:t.width,height:t.height,fontSize:t.fontSize},l=e%r/i,u=l<=1?l:2-l;for(let e in s){let t=s[e];o[e]=t+u*(c[e]-t)}return o},move:({dTime:e,element:t,animation:n})=>{let r=ak[n.data.direction]||ak.right,i=n.data.strength??1,a={};for(var o in r.from){let s=r.from[o],c=r.to[o];n.type===`exit`&&(s=r.to[o],c=-r.from[o]),s*=i,c*=i;let l=t[o]+s,u=t[o]+c-l;a[o]=l+e/n.duration*u}return a},zoom:({dTime:e,element:t,animation:n})=>{let r={},i=1+(((n.data.direction||`in`)===`in`?3/4:5/4)-1)*(n.data.strength??1),a=t.rotation*Math.PI/180,o=Math.cos(a),s=Math.sin(a),c=t.width*(1-i),l=t.height*(1-i),u=(c*o-l*s)/2,d=(c*s+l*o)/2,f={x:t.x+u,y:t.y+d,width:t.width*i,height:t.height*i,fontSize:t.fontSize*i},p={x:t.x,y:t.y,width:t.width,height:t.height,fontSize:t.fontSize};for(var m in f){let t=f[m],i=p[m];if(n.type===`exit`){let e=t;t=i,i=e}let a=i-t;r[m]=t+e/n.duration*a}return r},cameraZoom:({dTime:e,element:t,animation:n})=>{let r={},i=ok[n.data.direction||`right`]||ok.right,a=n.data.movementStrength??.1,o=n.data.shakeStrength??.015,s=n.data.zoomStrength??.6,c=e/n.duration,l=o*(1-c),u=Math.sin(12*c)*l*.7+Math.sin(8*c)*l*.3;if(n.type===`exit`){let e=Math.max(t.cropWidth||1,t.cropHeight||1);s=Math.min(s,1-e)}n.type;let d=1-(1-c)**2,f=t.cropX||0,p=t.cropY||0,m=t.cropWidth||1,h=t.cropHeight||1,g=m,_=h,v,y,b=0,x=0;if(i.cropX){let e=i.cropX>0?1-(f+m):f;b=Math.min(e,Math.abs(a))*i.cropX}if(i.cropY){let e=i.cropY>0?1-(p+h):p;x=Math.min(e,Math.abs(a))*i.cropY}return n.type===`enter`?(v=i.cropX?f+b*(1-d):f,y=i.cropY?p+x*(1-d):p):(v=i.cropX?f+b*d:f,y=i.cropY?p+x*d:p),r.cropX=Math.max(0,Math.min(1-g,v+u*g)),r.cropY=Math.max(0,Math.min(1-_,y+u*_)),r.cropWidth=g,r.cropHeight=_,r}},ck=({element:e,dTime:t,animation:n})=>{let r=sk[n.name];return r?r({element:e,dTime:t,animation:n}):(console.error(`Can not find animation type: `+n.name),{})},lk=q.model(`Animation`,{delay:0,duration:500,enabled:!0,type:q.enumeration(`Type`,[`enter`,`exit`,`loop`]),name:`none`,data:q.frozen({})}),uk=(e,t)=>{let n={};for(let r in t)if(typeof e[r]==`number`&&typeof t[r]==`number`){let i=t[r]-e[r];i!==0&&(n[r]=i)}return n},dk=q.model(`ShapeFilter`,{intensity:1}),fk=[`temperature`,`contrast`,`highlights`,`shadows`,`white`,`black`,`saturation`,`vibrance`],pk=ik.named(`Shape`).props({x:0,y:0,width:100,height:100,rotation:0,opacity:1,animations:q.array(lk),blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,filters:q.map(dk),shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:`black`,shadowOpacity:1,visible:!0,draggable:!0,resizable:!0,selectable:!0,contentEditable:!0,styleEditable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot(e=>{let t=Object.assign(Object.assign({},e),{x:`x`in e&&e.x||0,y:`y`in e&&e.y||0,filters:`filters`in e?Array.isArray(e.filters)?{}:e.filters:void 0});return`width`in e&&(t.width=t.width||1),`height`in e&&(t.height=t.height||1),`locked`in e&&e.locked&&(t.draggable=!1,t.contentEditable=!1,t.styleEditable=!1,t.resizable=!1,t.removable=!1),t}).views(e=>{let t=[`x`,`y`,`width`,`height`,`rotation`,`opacity`,`color`,`fontSize`,`cropX`,`cropY`,`cropWidth`,`cropHeight`],n=e,r={x:n.x??0,y:n.y??0,width:n.width??0,height:n.height??0,rotation:n.rotation??0,opacity:n.opacity??1};for(let i of t)i in e&&(r[i]=n[i]);let i=L(r),a=Vn(e=>{for(let t in e)i[t]=e[t]}),o=Vn(e=>{Object.assign(i,e)}),s=Vn(e=>{for(let t in e)typeof i[t]==`number`&&(i[t]=i[t]+e[t])});return{get locked(){return!(e.draggable||e.contentEditable||e.styleEditable||e.resizable)},get a(){let{currentTime:t}=e.store,r={};for(let e in i)r[e]=n[e];if(a(r),t===0)return i;let c=t-e.page.startTime;if(c>e.page.duration||c<0)return i;let l=e.store.animatedElementsIds;if(l.length&&!l.includes(e.id))return i;let u=e.animations.find(e=>e.type===`enter`),d=u?.enabled&&c<u.delay;d&&o({opacity:0});let f=u?.enabled&&c>=u.delay&&c<=u.delay+u.duration;f&&s(uk(e,ck({element:e,animation:u,dTime:c-u.delay})));let p=e.animations.find(e=>e.type===`exit`);!d&&!f&&p?.enabled&&c>=e.page.duration-p.duration-p.delay&&c<=e.page.duration-p.delay&&s(uk(e,ck({element:e,animation:p,dTime:c-(e.page.duration-p.duration-p.delay)}))),p!=null&&p.enabled&&c>=e.page.duration-p.delay&&o({opacity:0});let m=e.animations.find(e=>e.type===`loop`);return m?.enabled&&s(uk(e,ck({element:e,animation:m,dTime:c}))),i},animated(e){return this.a[e]}}}).actions(e=>({setAnimation(t,n){let r=e.animations.find(e=>e.type===t);r?Object.assign(r,n):e.animations.push(Object.assign({type:t},n))},setFilter(t,n){fk.includes(t)||e.filters.forEach((t,n)=>{fk.includes(n.toString())||e.filters.delete(n.toString())}),n==null?e.filters.delete(t):e.filters.set(t,{intensity:n})}})),mk=pk.named(`Text`).props({type:`text`,text:``,placeholder:``,fontSize:14,fontFamily:`Roboto`,fontStyle:`normal`,fontWeight:`normal`,textDecoration:``,textTransform:`none`,fill:`black`,align:`center`,width:100,height:0,verticalAlign:`top`,strokeWidth:0,stroke:`black`,lineHeight:q.optional(q.union(q.number,q.string),1.2),letterSpacing:0,_editModeEnabled:!1,backgroundEnabled:!1,backgroundColor:`#7ED321`,backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5,curveEnabled:!1,curvePower:.5}).preProcessSnapshot(e=>Object.assign({},e)).actions(e=>({afterCreate(){if(!e.height){let t=e.lineHeight,n=typeof t==`number`?t:parseFloat(t)||1.2;e.height=Math.round(e.fontSize*n)}},toggleEditMode(t){let n=t??!e._editModeEnabled;n!==e._editModeEnabled&&(e._editModeEnabled=n,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())}})),hk=pk.named(`Image`).props({type:`image`,width:100,height:100,src:``,cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:``,borderColor:`black`,borderSize:0,keepRatio:!1,stretchEnabled:!1}).extend(e=>{let t=L.box(!1),n=!1;return{views:{get _cropModeEnabled(){return t.get()}},actions:{toggleCropMode(r){let i=r??!t.get();t.set(i),i&&!n?(e.store.history.startTransaction(),n=!0):!i&&n&&(e.store.history.endTransaction(),n=!1)},beforeDestroy(){n&&=(e.store.history.endTransaction(),!1)}}}}),gk=hk.named(`Video`).props({type:`video`,duration:0,startTime:0,endTime:1,volume:1}),_k=pk.named(`Line`).props({type:`line`,width:400,height:10,color:`black`,dash:q.array(q.number),startHead:``,endHead:``}).actions(e=>({})),vk=pk.named(`SVG`).props({type:`svg`,src:``,maskSrc:``,cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,stretchEnabled:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:`black`,borderSize:0,cornerRadius:0,colorsReplace:q.map(q.string)}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{src:e.src||e.svgSource,colorsReplace:Array.isArray(e.colorsReplace)?{}:e.colorsReplace})).actions(e=>({replaceColor(t,n){e.colorsReplace.set(t,n)}})),yk=pk.named(`Figure`).props({type:`figure`,subType:`rect`,fill:`rgb(0, 161, 255)`,dash:q.array(q.number),strokeWidth:0,stroke:`rgba(98, 197, 255, 1)`,cornerRadius:0}),bk=hk.named(`Gif`).props({type:`gif`,duration:0,keepRatio:!0}),xk=.05,Sk=q.enumeration([`solid`,`dashed`,`dotted`,`none`]);function Ck(e){return rm(e,2)}function wk(e,t,n){return e[`_${t}`]??(fm(e)?Ck(e)[t]:n)}function Tk(e){return rm(e,1)}var Ek=q.model(`BorderSide`,{color:q.maybe(q.string),width:q.maybe(q.number),style:q.maybe(Sk)}).postProcessSnapshot(e=>{let t={};for(let[n,r]of Object.entries(e))r!=null&&(t[n]=r);return t}),Dk=q.model(`CellBorders`,{top:q.maybe(Ek),right:q.maybe(Ek),bottom:q.maybe(Ek),left:q.maybe(Ek)}).postProcessSnapshot(e=>{let t={};for(let[n,r]of Object.entries(e))typeof r==`object`&&r&&Object.keys(r).length>0&&(t[n]=r);return t}),Ok=[`fontSize`,`fontFamily`,`fontWeight`,`fontStyle`,`textDecoration`,`textTransform`,`fill`,`align`,`verticalAlign`,`lineHeight`,`letterSpacing`,`strokeWidth`,`stroke`,`cellBackground`,`cellPadding`],kk=new Set(Ok),Ak=[`blurEnabled`,`blurRadius`,`brightnessEnabled`,`brightness`,`sepiaEnabled`,`grayscaleEnabled`,`filters`,`shadowEnabled`,`shadowBlur`,`shadowOffsetX`,`shadowOffsetY`,`shadowColor`,`shadowOpacity`],jk=[`id`,`type`,`text`,`opacity`,`rowSpan`,`colSpan`,`mergedInto`,`name`,`custom`,`borders`],Mk=new Set(`row.col.x.y.width.height.rotation.draggable.resizable.selectable.removable.contentEditable.visible.showInExport.alwaysOnTop.backgroundEnabled.backgroundOpacity.backgroundColor.backgroundCornerRadius.backgroundPadding.curveEnabled.curvePower.shadowEnabled.shadowBlur.shadowOffsetX.shadowOffsetY.shadowColor.shadowOpacity.blurEnabled.blurRadius.brightnessEnabled.brightness.sepiaEnabled.grayscaleEnabled.placeholder.animations.filters`.split(`.`)),Nk={opacity:1,rowSpan:1,colSpan:1,name:``},Pk=[],Fk=q.model(`TableCell`,{id:q.identifier,type:q.optional(q.literal(`tablecell`),`tablecell`),text:``,_fontSize:q.maybe(q.number),_fontFamily:q.maybe(q.string),_fontWeight:q.maybe(q.string),_fontStyle:q.maybe(q.string),_textDecoration:q.maybe(q.string),_textTransform:q.maybe(q.string),_fill:q.maybe(q.string),_align:q.maybe(q.string),_verticalAlign:q.maybe(q.string),_lineHeight:q.maybe(q.union(q.number,q.string)),_letterSpacing:q.maybe(q.number),_strokeWidth:q.maybe(q.number),_stroke:q.maybe(q.string),_cellBackground:q.maybe(q.string),_cellPadding:q.maybe(q.number),opacity:1,rowSpan:1,colSpan:1,mergedInto:q.maybe(q.string),borders:q.maybe(Dk),name:``,custom:q.frozen()}).volatile(()=>({_editModeEnabled:!1,filters:L.map()})).preProcessSnapshot(e=>{if(!e)return e;for(let t in e)e[t]===null&&(e[t]=void 0);let t={};for(let n of jk)n in e&&(t[n]=e[n]);for(let n of Ok)e[n]!==void 0&&(t[`_${n}`]=e[n]);return t}).postProcessSnapshot(e=>{let t={};for(let[n,r]of Object.entries(e))if(n.startsWith(`_`))r!=null&&(t[n.slice(1)]=r);else if(n===`borders`)typeof r==`object`&&r&&Object.keys(r).length>0&&(t.borders=r);else{if(n in Nk&&r===Nk[n])continue;t[n]=r}return t}).views(e=>{let t={get row(){if(!fm(e))return 0;let t=Ck(e),n=Tk(e).indexOf(e);return n===-1?0:Math.floor(n/t.cols)},get col(){if(!fm(e))return 0;let t=Ck(e),n=Tk(e).indexOf(e);return n===-1?0:n%t.cols},get store(){return fm(e)?om(e):null},get page(){if(!fm(e))return null;try{return Ck(e).page}catch{return null}},get fontSize(){return wk(e,`fontSize`,30)},get fontFamily(){return wk(e,`fontFamily`,`Roboto`)},get fontWeight(){return wk(e,`fontWeight`,`normal`)},get fontStyle(){return wk(e,`fontStyle`,`normal`)},get textDecoration(){return wk(e,`textDecoration`,``)},get textTransform(){return wk(e,`textTransform`,`none`)},get fill(){return wk(e,`fill`,`black`)},get align(){return wk(e,`align`,`left`)},get verticalAlign(){return wk(e,`verticalAlign`,`top`)},get lineHeight(){return wk(e,`lineHeight`,1.2)},get letterSpacing(){return wk(e,`letterSpacing`,0)},get strokeWidth(){return wk(e,`strokeWidth`,0)},get stroke(){return wk(e,`stroke`,`black`)},get cellBackground(){return wk(e,`cellBackground`,`transparent`)},get cellPadding(){return wk(e,`cellPadding`,4)},get width(){if(!fm(e))return 100;try{return Ck(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan).width}catch{return 100}},get height(){if(!fm(e))return 100;try{return Ck(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan).height}catch{return 100}},get a(){if(!fm(e))return{x:0,y:0,width:100,height:100,rotation:0,opacity:1,fontSize:16};let n=Ck(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan),r=t.cellPadding;return{x:n.x+r,y:n.y+r,width:n.width-2*r,height:n.height-2*r,rotation:0,opacity:e.opacity??1,fontSize:t.fontSize}},getEffectiveBorder(t){let n=fm(e)?Ck(e):null,r=e.borders?.[t];return{color:r?.color??n?.borderColor??`#000000`,width:r?.width??n?.borderWidth??1,style:r?.style??n?.borderStyle??`solid`}},get x(){return 0},get y(){return 0},get rotation(){return 0},get draggable(){return!1},get resizable(){return!1},get selectable(){return!1},get removable(){return!1},get contentEditable(){return!0},get visible(){return!0},get showInExport(){return!0},get alwaysOnTop(){return!1},get placeholder(){return``},get backgroundEnabled(){return!1},get backgroundOpacity(){return 1},get backgroundColor(){return`transparent`},get backgroundCornerRadius(){return 0},get backgroundPadding(){return 0},get curveEnabled(){return!1},get curvePower(){return 0},get shadowEnabled(){return!1},get shadowBlur(){return 0},get shadowOffsetX(){return 0},get shadowOffsetY(){return 0},get shadowColor(){return`black`},get shadowOpacity(){return 1},get blurEnabled(){return!1},get blurRadius(){return 0},get brightnessEnabled(){return!1},get brightness(){return 0},get sepiaEnabled(){return!1},get grayscaleEnabled(){return!1},get animations(){return Pk}};return t}).actions(e=>({toJSON:()=>Object.assign({},nm(e)),set(t){let n={};for(let[e,r]of Object.entries(t))kk.has(e)?n[`_${e}`]=r:e===`borders`?n.borders=r&&JSON.parse(JSON.stringify(r)):Mk.has(e)||(n[e]=r);Object.assign(e,n)},setBorder(t,n){let r=e.borders?Object.assign({},nm(e.borders)):{},i=r[t]||{},a=Object.assign({},i);n.color!==void 0&&(a.color=n.color),n.width!==void 0&&(a.width=n.width),n.style!==void 0&&(a.style=n.style),r[t]=a,e.borders=pm(r)},toggleEditMode(t){let n=t??!e._editModeEnabled;n!==e._editModeEnabled&&(e._editModeEnabled=n,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())}}));function Ik(e){return Array.from({length:e},()=>1/e)}function Lk(e){let t=e.reduce((e,t)=>e+t,0);return t===0?Ik(e.length):e.map(e=>e/t)}var Rk=pk.named(`Table`).props({type:`table`,width:300,height:200,rows:3,cols:3,colWidths:q.array(q.number),rowHeights:q.array(q.number),cells:q.array(Fk),borderColor:`#000000`,borderWidth:1,borderStyle:q.optional(q.enumeration([`solid`,`dashed`,`dotted`,`none`]),`solid`),fontSize:30,fontFamily:`Roboto`,fontWeight:`normal`,fontStyle:`normal`,textDecoration:``,textTransform:`none`,fill:`black`,align:`left`,verticalAlign:`top`,lineHeight:q.optional(q.union(q.number,q.string),1.2),letterSpacing:0,strokeWidth:0,stroke:`black`,cellBackground:`transparent`,cellPadding:4}).postProcessSnapshot(e=>{e.cells&&((e=Object.assign({},e)).cells=e.cells.map(t=>{let n={};for(let[r,i]of Object.entries(t))kk.has(r)&&i===e[r]||(n[r]=i);return n}));for(let t of Ak)delete e[t];return e}).volatile(()=>({_focusedCellIds:[],_editingCellId:void 0,_anchorCellId:void 0,_cellContentHeights:L.map(),_baseRowHeights:null,_baseHeight:null,_isResizingRows:!1,_isTransforming:!1})).actions(e=>({afterCreate(){let t=e.rows*e.cols;if(e.cells.length===0)e.cells.replace(pm(function(e,t){let n=[];for(let r=0;r<e*t;r++)n.push({id:UD(10),text:``});return n}(e.rows,e.cols)));else if(e.cells.length<t)for(;e.cells.length<t;)e.cells.push(pm({id:UD(10),text:``}));else e.cells.length>t&&e.cells.splice(t);e.colWidths.length===0&&e.colWidths.replace(Ik(e.cols)),e.rowHeights.length===0&&e.rowHeights.replace(Ik(e.rows))}})).views(e=>({get _cellMap(){let t=new Map,n=e.cols;return e.cells.forEach((e,r)=>{t.set(`${Math.floor(r/n)}:${r%n}`,e)}),t},getActualRowHeight:t=>e.rowHeights[t]*e.height})).views(e=>{let t={getCell:(t,n)=>e._cellMap.get(`${t}:${n}`),get minWidth(){return 20*e.cols},get minHeight(){return 20*e.rows},get actualHeight(){let t=0;for(let n=0;n<e.rows;n++)t+=e.getActualRowHeight(n);return t},getCellRect(t,n,r=1,i=1){let a=0;for(let t=0;t<n;t++)a+=e.colWidths[t]*e.width;let o=0;for(let n=0;n<t;n++)o+=e.getActualRowHeight(n);let s=0;for(let t=n;t<n+i;t++)s+=(e.colWidths[t]||0)*e.width;let c=0;for(let n=t;n<t+r;n++)c+=e.getActualRowHeight(n);return{x:a,y:o,width:s,height:c}},get visibleCells(){return e.cells.filter(e=>!e.mergedInto)},get focusedCells(){return e.cells.filter(t=>e._focusedCellIds.includes(t.id))},get editingCell(){if(e._editingCellId)return e.cells.find(t=>t.id===e._editingCellId)},get _fitRowsToContent(){if(e._isResizingRows||e._isTransforming||e._cellContentHeights.size===0)return null;let n=e._baseHeight??e.height,r=e._baseRowHeights??[...e.rowHeights],i=!1,a=[];for(let o=0;o<e.rows;o++){let s=e.rowHeights[o]*e.height,c=r[o]*n,l=0;for(let n=0;n<e.cols;n++){let r=t.getCell(o,n);if(!r)continue;let i=e._cellContentHeights.get(r.id);if(i!==void 0){let e=i+2*r.cellPadding;l=Math.max(l,e)}}let u=Math.max(l,c);Math.abs(u-s)>1?(a.push(u),i=!0):a.push(s)}if(!i)return null;let o=a.reduce((e,t)=>e+t,0);return{rowHeights:a.map(e=>e/o),height:o}}};return t}).actions(e=>{let t={setCellContentHeight(t,n){e._cellContentHeights.set(t,n)},_applyFitRowsToContent(){e._baseRowHeights===null&&(e._baseRowHeights=[...e.rowHeights],e._baseHeight=e.height);let t=e._fitRowsToContent;t&&(e.height=t.height,e.rowHeights.replace(t.rowHeights))},focusCell(t,n=!1){n?e._focusedCellIds.includes(t)||(e._focusedCellIds=[...e._focusedCellIds,t]):(e._focusedCellIds=[t],e._anchorCellId=t)},focusCellRange(t,n){let r=e.cells.find(t=>t.id===e._anchorCellId);if(!r)return;let i=Math.min(r.row,t),a=Math.max(r.row,t),o=Math.min(r.col,n),s=Math.max(r.col,n),c=[];for(let t of e.cells)t.row>=i&&t.row<=a&&t.col>=o&&t.col<=s&&c.push(t.id);e._focusedCellIds=c},clearCellFocus(){if(fm(e)){if(e._editingCellId){let t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1)}e._focusedCellIds=[],e._editingCellId=void 0,e._anchorCellId=void 0}},enterCellEdit(t){e._editingCellId=t,e._focusedCellIds.includes(t)||(e._focusedCellIds=[t]);let n=e.cells.find(e=>e.id===t);n&&n.toggleEditMode(!0)},exitCellEdit(){if(e._editingCellId){let t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1)}e._editingCellId=void 0},_resetBaseRowHeights(){e._baseRowHeights=null,e._baseHeight=null},_setIsResizingRows(t){e._isResizingRows=t},_setIsTransforming(t){e._isTransforming=t},addRow(n){t._resetBaseRowHeights();let r=n>0?n-1:0,i=(e.rowHeights[r]||1/(e.rows+1))*e.height,a=e.height+i,o=[];for(let t=0;t<e.rows;t++)o.push(e.rowHeights[t]*e.height/a);o.splice(n,0,i/a);let s=n*e.cols,c=Array.from({length:e.cols},()=>({id:UD(10),text:``}));e.cells.splice(s,0,...pm(c)),e.rows+=1,e.height=a,e.rowHeights.replace(Lk(o))},removeRow(n){if(e.rows<=1)return;t._resetBaseRowHeights();let r=n*e.cols,i=[];for(let t=r;t<r+e.cols;t++)i.push(e.cells[t].id);if(e._editingCellId&&i.includes(e._editingCellId)){let t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1),e._editingCellId=void 0}e._focusedCellIds=e._focusedCellIds.filter(e=>!i.includes(e)),i.forEach(t=>e._cellContentHeights.delete(t)),e.cells.splice(r,e.cols);let a=[...e.rowHeights];a.splice(n,1),--e.rows,e.rowHeights.replace(Lk(a))},addColumn(t){let n=t>0?t-1:0,r=(e.colWidths[n]||1/(e.cols+1))*e.width,i=e.width+r,a=[];for(let t=0;t<e.cols;t++)a.push(e.colWidths[t]*e.width/i);a.splice(t,0,r/i);let o=e.cols;for(let n=e.rows-1;n>=0;n--)e.cells.splice(n*o+t,0,pm({id:UD(10),text:``}));e.cols+=1,e.width=i,e.colWidths.replace(Lk(a))},removeColumn(t){if(e.cols<=1)return;let n=e.cols,r=[];for(let i=0;i<e.rows;i++)r.push(e.cells[i*n+t].id);if(e._editingCellId&&r.includes(e._editingCellId)){let t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1),e._editingCellId=void 0}e._focusedCellIds=e._focusedCellIds.filter(e=>!r.includes(e)),r.forEach(t=>e._cellContentHeights.delete(t));for(let r=e.rows-1;r>=0;r--)e.cells.splice(r*n+t,1);let i=[...e.colWidths];i.splice(t,1),--e.cols,e.colWidths.replace(Lk(i))},distributeRowsEvenly(){t._resetBaseRowHeights(),e.rowHeights.replace(Ik(e.rows))},distributeColumnsEvenly(){e.colWidths.replace(Ik(e.cols))},resizeColumn(t,n){if(t>=e.cols-1)return;let r=[...e.colWidths],i=r[t]+r[t+1],a=r[t]+n,o=r[t+1]-n;a<xk?(r[t]=xk,r[t+1]=i-xk):o<xk?(r[t+1]=xk,r[t]=i-xk):(r[t]=a,r[t+1]=o),e.colWidths.replace(r)},resizeRow(t,n){if(t>=e.rows-1)return;let r=[...e.rowHeights],i=r[t]+r[t+1],a=r[t]+n,o=r[t+1]-n;a<xk?(r[t]=xk,r[t+1]=i-xk):o<xk?(r[t+1]=xk,r[t]=i-xk):(r[t]=a,r[t+1]=o),e.rowHeights.replace(r)},setCellBorders(t,n,r){let i={top:{side:`bottom`,dr:-1,dc:0},bottom:{side:`top`,dr:1,dc:0},left:{side:`right`,dr:0,dc:-1},right:{side:`left`,dr:0,dc:1}};for(let a of t){let t=e.cells.find(e=>e.id===a);if(t)for(let a of n){t.setBorder(a,r);let n=i[a],o=t.row+n.dr,s=t.col+n.dc,c=e.getCell(o,s);c&&c.setBorder(n.side,r)}}}};return t}).actions(e=>({clone(t={},{skipSelect:n=!1}={}){let r=JSON.parse(JSON.stringify(e.toJSON()));if(t.id=t.id||UD(10),r.cells){let e=new Map;r.cells.forEach(t=>{let n=t.id,r=UD(10);e.set(n,r),t.id=r}),r.cells.forEach(t=>{t.mergedInto&&e.has(t.mergedInto)&&(t.mergedInto=e.get(t.mergedInto))})}return Object.assign(r,t),e.page.addElement(r,{skipSelect:n})}})),zk=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n},Bk=(e,t)=>{if(e.children)for(let n of e.children){if(!0===t(n))break;Bk(n,t)}},Vk=(e,t)=>{if(e.children)for(let n of e.children){if(!0===t(n))break;Vk(n,t)}if(e.cells){for(let n of e.cells)if(!0===t(n))break}},Hk=[...Array(20)].map((e,t)=>q.late(()=>Gk[t])),Uk=q.union({dispatcher:e=>{let t=Kk[e.type];if(!t)throw Error(`Unknown element type: "${e.type}"`);return t}},vk,mk,hk,_k,gk,yk,bk,Rk,q.late(()=>Wk),...Hk),Wk=ik.named(`Group`).props({type:`group`,children:q.array(Uk)}).views(e=>({get draggable(){let t=!0;return Bk(e,e=>{e.draggable||(t=!1)}),t},get resizable(){let t=!0;return Bk(e,e=>{e.resizable||(t=!1)}),t},get contentEditable(){let t=!0;return Bk(e,e=>{e.contentEditable||(t=!1)}),t},get styleEditable(){let t=!0;return Bk(e,e=>{e.styleEditable||(t=!1)}),t},get locked(){let t=!0;return Bk(e,e=>{e.locked||(t=!1)}),t}})).actions(e=>({set(t){var{draggable:n,contentEditable:r,styleEditable:i,resizable:a}=t,o=zk(t,[`draggable`,`contentEditable`,`styleEditable`,`resizable`]);n!==void 0&&Bk(e,e=>{e.set({draggable:n})}),r!==void 0&&Bk(e,e=>{e.set({contentEditable:r})}),i!==void 0&&Bk(e,e=>{e.set({styleEditable:i})}),a!==void 0&&Bk(e,e=>{e.set({resizable:a})}),Object.assign(e,o)},addElement(t,{skipSelect:n=!1}={}){let r=Kk[t.type];if(!r){console.error(`Can not find model with type `+t.type);return}t.children&&t.children.forEach(e=>{e.id=e.id||UD(10)});let i=r.create(Object.assign({id:UD(10)},t));return e.children.push(i),i.selectable&&!n&&e.store.selectElements([i.id]),i},setElementZIndex(t,n){let r=e.children.find(e=>e.id===t);r&&(um(r),e.children.remove(r),e.children.splice(n,0,r))},setAnimation(t,n){Bk(e,e=>{e.setAnimation(t,n)})}})),Gk=[],Kk={svg:vk,text:mk,image:hk,group:Wk,line:_k,video:gk,figure:yk,gif:bk,table:Rk},qk={text:M_,image:fv,svg:fv,line:Cb,video:mD,figure:kD,group:sa(e=>{let{element:t,store:n}=e,{children:r}=t,i=t.selectable||n.role===`admin`;return d.createElement(Kd,{opacity:t.opacity,listening:i,hideInExport:!t.showInExport,id:t.id},r.map(t=>d.createElement(Yk,Object.assign({},e,{key:t.id,store:n,element:t}))))}),gif:zD,table:BD},Jk=(e,t)=>{let n=[];Bk(e,e=>{e.type!==`group`&&n.push(e.a)});let r=[];n.forEach(e=>{let t=[{x:0,y:0},{x:0+e.width,y:0},{x:0+e.width,y:0+e.height},{x:0,y:0+e.height}],n=new Du.Transform;n.translate(e.x,e.y),n.rotate(Du.Util.degToRad(e.rotation)),t.forEach(e=>{let t=n.point(e);r.push(t)})});let i=new Du.Transform;i.rotate(-Du.Util.degToRad(t));let a=1/0,o=1/0,s=-1/0,c=-1/0;r.forEach(e=>{let t=i.point(e);a=Math.min(a,t.x),o=Math.min(o,t.y),s=Math.max(s,t.x),c=Math.max(c,t.y)}),i.invert();let l=i.point({x:a,y:o});return{x:l.x,y:l.y,width:s-a,height:c-o,rotation:t}},Yk=sa(e=>{let{element:t,store:n}=e,[r,i]=d.useState(!1),a=n.selectedElements.indexOf(t)>=0&&t.selectable,o=t.parent?.type===`group`,s=(e=>{let[t,n]=d.useState();return d.useEffect(()=>{let t=setTimeout(()=>{let t=e.page.id,r=Du.stages.find(e=>e.getAttr(`pageId`)===t);r||console.error(`No stage is found for element`,e.id),n(r)});return()=>clearTimeout(t)},[e.id]),t})(t),c=s?.findOne(`Transformer`);d.useEffect(()=>{if(s){let e=e=>{let r=e.target.findAncestor(`.element`,!0),a=n.getElementById(r?.id())?.top;i(a?.id===t.id)};s.on(`mouseover`,e);let r=()=>{i(!1)};return s.on(`mouseleave`,r),()=>{s.off(`mouseover`,e),s.off(`mouseleave`,r)}}},[s]);let l=qk[e.element.type];return e.element.type===`text`&&yp.htmlRenderEnabled&&(l=tb),e.element.visible?l?d.createElement(Kd,{name:`element-container`},d.createElement(l,Object.assign({},e)),r&&!a&&!o&&d.createElement(HD,{element:t.type===`group`?{a:Jk(t,c?.rotation()||0)}:t})):(console.error(`Can not find component for `+e.element.type),null):null});function Xk(e,t=.5){if(e.length<3)return e;let n=[];n.push(e[0]);for(let t=0;t<e.length-1;t++){let r=e[Math.max(0,t-1)],i=e[t],a=e[t+1],o=e[Math.min(e.length-1,t+2)];for(let e=0;e<10;e++){let t=e/10,s=t*t,c=s*t,l=.5*(2*i.x+(-r.x+a.x)*t+(2*r.x-5*i.x+4*a.x-o.x)*s+(-r.x+3*i.x-3*a.x+o.x)*c),u=.5*(2*i.y+(-r.y+a.y)*t+(2*r.y-5*i.y+4*a.y-o.y)*s+(-r.y+3*i.y-3*a.y+o.y)*c);n.push({x:l,y:u})}}return n.push(e[e.length-1]),n}function Zk(e){if(e.length===0)return``;if(e.length===1){let t=e[0];return`M ${t.x},${t.y} L ${t.x+.1},${t.y}`}let t=`M ${e[0].x},${e[0].y}`;for(let n=1;n<e.length-1;n++){let r=e[n],i=e[n+1],a=(r.x+i.x)/2,o=(r.y+i.y)/2;t+=` Q ${r.x},${r.y} ${a},${o}`}if(e.length>1){let n=e[e.length-1];t+=` L ${n.x},${n.y}`}return t}function Qk(e){if(e.length===0)return{x:0,y:0,width:0,height:0};let t=e[0].x,n=e[0].y,r=e[0].x,i=e[0].y;for(let a of e)t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x),i=Math.max(i,a.y);return{x:t,y:n,width:r-t,height:i-n}}function $k(e,t){if(e.length===0)throw Error(`Cannot create SVG from empty path`);let n=t.smooth?Xk(e):e,r=Qk(n),i=t.strokeWidth,a=r.x-i,o=r.y-i,s=r.width+2*i,c=r.height+2*i;return{src:G_(`\n <svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${c}" viewBox="0 0 ${s} ${c}">\n <path\n d="${Zk(n.map(e=>({x:e.x-a,y:e.y-o})))}"\n stroke="${t.stroke}"\n stroke-width="${t.strokeWidth}"\n stroke-linecap="round"\n stroke-linejoin="round"\n fill="none"\n />\n </svg>\n `.trim()),x:a,y:o,width:s,height:c}}var eA=sa(({store:e,page:t,width:n,height:r,scale:i,xPadding:a,yPadding:o,bleed:s})=>{let[c,l]=d.useState(!1),[u,f]=d.useState([]),p=d.useRef(null),m=e.tool===`draw`,{strokeWidth:h,stroke:g,opacity:_,brushType:v}=e.toolOptions,y=d.useCallback(e=>{if(!m||(l(!0),e.cancelBubble=!0,!e.target.getStage()))return;let t=p.current.getRelativePointerPosition();t&&f([{x:t.x,y:t.y}])},[m,i,a,o,s]),b=d.useCallback(e=>{if(!m||!c||(e.cancelBubble=!0,!e.target.getStage()))return;let t=p.current.getRelativePointerPosition();t&&f(e=>[...e,{x:t.x,y:t.y}])},[m,c,i,a,o,s]),x=d.useCallback(()=>{if(m&&c){if(l(!1),u.length>=1)try{let n=$k(u,{stroke:g,strokeWidth:h,smooth:!0}),r=e.selectedElementsIds.slice();e.history.transaction(()=>{t.addElement({type:`svg`,x:n.x,y:n.y,width:n.width,height:n.height,src:n.src,opacity:_},{skipSelect:!0})}),e.selectElements(r)}catch(e){console.error(`Error creating path SVG:`,e)}f([])}},[m,c,u,g,h,_,t,e.history,e]),S=d.useMemo(()=>u.flatMap(e=>[e.x,e.y]),[u]);return d.useEffect(()=>{if(m&&p.current){let e=p.current.getStage();if(!e)return;let t=h*i;if(t>100||t<4)e.container().style.cursor=`crosshair`;else{let n=t/2,r=t/2,i=`data:image/svg+xml;base64,${btoa(`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}" viewBox="0 0 ${t} ${t}">\n <circle cx="${r}" cy="${r}" r="${n-1}" fill="${g}" opacity="${_}" stroke="white" stroke-width="1"/>\n <circle cx="${r}" cy="${r}" r="${n-1}" fill="none" stroke="black" stroke-width="1" opacity="0.3"/>\n </svg>`)}`;e.container().style.cursor=`url("${i}") ${r} ${r}, crosshair`}return()=>{e.container()&&(e.container().style.cursor=``)}}},[m,g,h,_,i]),m?d.createElement(Kd,{ref:p,listening:m,x:a+s*i,y:o+s*i,scaleX:i,scaleY:i},d.createElement(Jd,{x:-(a+s*i)/i,y:-(o+s*i)/i,width:n/i,height:r/i,fill:`transparent`,onMouseDown:y,onMouseMove:b,onMouseUp:x,onTouchStart:y,onTouchMove:b,onTouchEnd:x}),u.length>0&&d.createElement(`Line`,{points:S,stroke:g,strokeWidth:h,lineCap:`round`,lineJoin:`round`,opacity:_,tension:.5,listening:!1})):null});function tA(e,t,n=`scale`){let r=t.width/t.height,i,a;r>=e.width/e.height?(i=e.width,a=e.width/r):(i=e.height*r,a=e.height);let o=0,s=0;return n===`left-top`?(o=0,s=0):n===`left-middle`?(o=0,s=(e.height-a)/2):n===`left-bottom`?(o=0,s=e.height-a):n===`center-top`?(o=(e.width-i)/2,s=0):n===`center-middle`?(o=(e.width-i)/2,s=(e.height-a)/2):n===`center-bottom`?(o=(e.width-i)/2,s=e.height-a):n===`right-top`?(o=e.width-i,s=0):n===`right-middle`?(o=e.width-i,s=(e.height-a)/2):n===`right-bottom`?(o=e.width-i,s=e.height-a):n===`scale`?(o=0,s=0,i=e.width,a=e.height):console.error(Error(`Unknown clip position property - `+n)),{cropX:o,cropY:s,cropWidth:i,cropHeight:a}}var nA=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n},rA=e=>tf.batchedUpdates(e,null);Gi(e=>{tf.isAlreadyRendering()?queueMicrotask(()=>rA(e)):rA(e)});var iA=Du.DD._drag;window.removeEventListener(`mousemove`,iA),Du.DD._drag=function(e){Un(()=>{iA.call(this,e)})},window.addEventListener(`mousemove`,Du.DD._drag);var aA=new Du.Group,oA=20;aA.add(new Du.Rect({width:oA,height:oA,fill:`white`})),aA.add(new Du.Path({scaleX:oA/24,scaleY:oA/24,data:`M4.98313549,11.0001422 C5.49589839,10.9914935 5.92501998,11.3703506 5.99116425,11.8666444 L5.99985778,11.9831355 L6.00348884,12.2068855 C6.11245031,15.4321748 8.76323537,17.9999971 11.9999971,17.9999971 C12.1869612,17.9999971 12.3726725,17.9914753 12.5567465,17.9745765 L12.2928932,17.7071068 C11.9023689,17.3165825 11.9023689,16.6834175 12.2928932,16.2928932 C12.6834175,15.9023689 13.3165825,15.9023689 13.7071068,16.2928932 L15.7071068,18.2928932 C16.0976311,18.6834175 16.0976311,19.3165825 15.7071068,19.7071068 L13.7071068,21.7071068 C13.3165825,22.0976311 12.6834175,22.0976311 12.2928932,21.7071068 C11.9023689,21.3165825 11.9023689,20.6834175 12.2928932,20.2928932 L12.6111505,19.9769552 C12.4086045,19.9922816 12.2047796,19.9999971 11.9999971,19.9999971 C7.7687005,19.9999971 4.28886152,16.7094374 4.01666425,12.5105203 L4.00420123,12.2575143 L4.00014222,12.0168645 C3.9908282,11.4646583 4.43092928,11.0094562 4.98313549,11.0001422 Z M11.7071068,2.29289322 C12.0675907,2.65337718 12.0953203,3.22060824 11.7902954,3.61289944 L11.7071068,3.70710678 L11.3891629,4.0230186 C11.5916051,4.00770767 11.7953244,4 12,4 C16.418278,4 20,7.581722 20,12 C20,12.5522847 19.5522847,13 19,13 C18.4477153,13 18,12.5522847 18,12 C18,8.6862915 15.3137085,6 12,6 C11.8129339,6 11.6271216,6.00853145 11.4429483,6.02544919 L11.7071068,6.29289322 C12.0976311,6.68341751 12.0976311,7.31658249 11.7071068,7.70710678 C11.3466228,8.06759074 10.7793918,8.09532028 10.3871006,7.79029539 L10.2928932,7.70710678 L8.29289322,5.70710678 C7.93240926,5.34662282 7.90467972,4.77939176 8.20970461,4.38710056 L8.29289322,4.29289322 L10.2928932,2.29289322 C10.6834175,1.90236893 11.3165825,1.90236893 11.7071068,2.29289322 Z`,fill:`black`}));var sA=aA.toCanvas({pixelRatio:2,width:oA,height:oA}),cA={enabledAnchors:[`top-left`,`top-center`,`top-right`,`middle-left`,`bottom-left`,`bottom-right`,`bottom-center`,`middle-right`],borderEnabled:!0,rotateEnabled:!0,rotationSnaps:[0,45,90,135,180,225,270,315],ignoreStroke:!0,flipEnabled:!1,anchorStrokeWidth:2,borderStrokeWidth:2,rotateAnchorOffset:30,keepRatio:!0,anchorStyleFunc:e=>{e.hasName(`rotater`)&&e.setAttrs({width:20,height:20,cornerRadius:20/2,offsetX:20/2,offsetY:20/2,fillPatternImage:sA,fillPatternScaleX:20/oA/2,fillPatternScaleY:20/oA/2,fillPriority:`pattern`,fillPatternRepeat:`no-repeat`})}},lA={text:{enabledAnchors:[`top-left`,`top-right`,`middle-left`,`bottom-left`,`bottom-right`,`middle-right`]},svg:{enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`]},gif:{enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`]},line:{enabledAnchors:[],borderEnabled:!1,rotateEnabled:!1},image:{enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`]},many:{enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`]},group:{enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`]},table:{keepRatio:!1,enabledAnchors:[`top-left`,`top-right`,`middle-left`,`middle-right`,`bottom-left`,`bottom-right`]}},uA=e=>d.createElement(Jd,Object.assign({},e,{preventDefault:!1})),dA=e=>{var{url:t}=e,n=nA(e,[`url`]);let[r,i]=(0,rf.default)(t,`anonymous`),a=r?tA(r,{width:n.width,height:n.height},`center-middle`):{};return dv(i,t,`page background`),d.createElement(Xd,Object.assign({image:r},n,a))},fA=e=>{let t=Pf({a:{width:e.width,height:e.height},width:e.width,height:e.height},e.fill);return d.createElement(Jd,Object.assign({},e,t))},pA=e=>{let{background:t,scale:n,borderColor:r,transparencyBackgroundColor:i}=e,a=nA(e,[`background`,`scale`,`borderColor`,`transparencyBackgroundColor`]),o=d.useMemo(()=>!!Du.Util.colorToRGBA(t)||jf(t),[t]),s=d.useMemo(()=>{if(jf(t))return!0;let e=Du.Util.colorToRGBA(t);return!e||e.a<1},[t]),c=d.useMemo(()=>{if(!s||i)return null;let e=document.createElement(`canvas`);e.width=60,e.height=60;let t=e.getContext(`2d`);return t&&(t.fillStyle=`black`,t.fillRect(30,0,30,30),t.fillRect(0,30,30,30)),e},[s,i]);return d.createElement(d.Fragment,null,s&&(i?d.createElement(`Rect`,Object.assign({fill:i},a,{hideInExport:!0})):d.createElement(`Rect`,Object.assign({fillPatternImage:c},a,{opacity:.1,hideInExport:!0}))),o?d.createElement(fA,Object.assign({fill:t},a)):d.createElement(dA,Object.assign({url:t},a)))},mA=sa(({selection:e,fill:t=`rgba(0, 161, 255, 0.3)`,stroke:n=`rgb(0, 161, 255)`,strokeWidth:r=1})=>e.visible?d.createElement(Jd,{name:`selection`,x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x1-e.x2),height:Math.abs(e.y1-e.y2),fill:t,stroke:n,strokeWidth:r}):null);function hA(e){let t=180*e/Math.PI;return t%=360,t>180?t-=360:t<-180&&(t+=360),Math.round(t)}var gA=sa(({x:e,y:t,width:n,height:r,rotation:i,anchor:a,store:o,tagFill:s,textFill:c})=>{if(e===void 0||t===void 0||n===void 0||r===void 0||i===void 0||a===void 0)return null;let l=ab({x:e,y:t,width:n,height:r,rotation:Du.Util.radToDeg(i)}),u=(r/2+70)*Math.cos(i-Math.PI/2),f=(r/2+70)*Math.sin(i-Math.PI/2),p=yO({unit:o.unit,dpi:o.dpi,px:n/o.scale,precious:o.unit===`px`?0:1})+` x `+yO({unit:o.unit,dpi:o.dpi,px:r/o.scale,precious:o.unit===`px`?0:1})+(o.unit===`px`?``:` `+o.unit);return d.createElement(d.Fragment,null,d.createElement(qd,{x:(l.minX+l.maxX)/2+u,y:(l.minY+l.maxY)/2+f,offsetX:14,offsetY:14,visible:a===`rotater`},d.createElement(`Tag`,{cornerRadius:5,fill:s||`rgb(0, 161, 255)`}),d.createElement(Zd,{align:`center`,verticalAlign:`middle`,fill:c||`white`,padding:8,text:hA(i).toString()+`°`})),d.createElement(qd,{x:(l.minX+l.maxX)/2,y:l.maxY+20,visible:a!==`rotater`},d.createElement(`Tag`,{cornerRadius:5,fill:s||`rgb(0, 161, 255)`,pointerDirection:`up`,pointerHeight:0,pointerWidth:0}),d.createElement(Zd,{align:`center`,verticalAlign:`middle`,fill:c||`white`,padding:8,text:p})))}),_A=sa(({elements:e,store:t})=>{let n=e.filter(e=>e.alwaysOnTop),r=e.filter(e=>!e.alwaysOnTop).concat(n);return d.createElement(d.Fragment,null,r.map(e=>d.createElement(Yk,{key:e.id,store:t,element:e,onClick:()=>{console.warn(`Polotno warning: onClick callback is deprecated. Just stop using it. Polotno will do selection automatically.`)}})))}),vA=({store:e})=>{let[t,n]=d.useState(!1),[r,i]=d.useState({x:0,y:0});return{open:d.useCallback(e=>{n(!0),i(e)},[]),close:d.useCallback(()=>{n(!1)},[]),props:{isOpen:t,offset:r,setIsOpen:n}}},yA=null,bA=atob(`UG9sb3RubyBmcmVlIGxpY2Vuc2UgbGltaXRhdGlvbiBleGNlZWRlZCAtIFBsZWFzZSB1cGdyYWRlIHlvdXIgYWNjb3VudC4=`),xA=atob(`I2MwMzkyYg==`),SA=atob(`djAuOS4y`),CA=e=>d.createElement(d.Fragment,null,d.createElement(qd,{fill:xA,height:200},d.createElement(`Tag`,{fill:xA}),d.createElement(Zd,Object.assign({},e,{fill:`white`,text:bA,height:void 0,padding:10,fontSize:20})))),wA=atob(`RlJFRSAgVFJJQUwgIExJQ0VOU0U=`),TA=(atob(`UG93ZXJlZCBieSBQb2xvdG5v`),atob(`TElDRU5TRSAgS0VZICBJUyAgTUlTU0lORw==`)),EA=atob(`UGxlYXNlIGFjdGl2YXRlIHlvdXIgbGljZW5zZS4KTGljZW5zZSByZWxhdGVkIHF1ZXN0aW9uczoKcG9sb3Ruby5jb20vY29udGFjdA==`),DA=e=>{let t=rO()===1,n=t?TA:wA,r=t?230:195;return d.createElement(Kd,Object.assign({},e,{listening:!1}),d.createElement(Jd,{fill:xA,width:r,height:24,cornerRadius:2}),d.createElement(Zd,{text:n,fill:`white`,fontSize:13,fontFamily:`monospace`,width:r,align:`center`,y:5,listening:!1}),t&&d.createElement(`Text`,{text:EA,fill:`rgba(0,0,0,0.6)`,fontSize:14,y:30,listening:!1}))},OA=sa(({store:e,page:t,width:n,height:r,pageControlsEnabled:i,backColor:a,transparencyBackgroundColor:o,pageBorderColor:s,activePageBorderColor:c,components:l,bleedColor:u,altCloneEnabled:f,viewportSize:p,selectionRectFill:m,selectionRectStroke:h,selectionRectStrokeWidth:g,snapGuideStroke:_,snapGuideStrokeWidth:v,snapGuideDash:y,transformLabelFill:b,transformLabelTextFill:x,distanceGuideStroke:S,distanceLabelFill:C,distanceLabelTextFill:w,layout:T=`vertical`,tooltipSafeArea:E,transformerSafeArea:D})=>{let O=e.bleedVisible?t.bleed:0,k=t.computedWidth+2*O,A=t.computedHeight+2*O,j=(n-k*e.scale)/2,M=(r-A*e.scale)/2,N=d.useRef(null),P=d.useRef(null),F=d.useRef(null),ee=i==null||i,te=d.useRef(!1),[ne,re]=d.useState(null),[ie,I]=d.useState({}),[ae,oe]=d.useState(0),se=vA({store:e}),ce=e.selectedElements.find(e=>e._cropModeEnabled),le=e.selectedElements.find(e=>e.curveEnabled),ue=e.selectedShapes.filter(e=>!e.resizable).length>0,de=e.selectedShapes.filter(e=>!e.draggable).length>0,fe=e.selectedElements.filter(e=>!e.visible).length>0;d.useLayoutEffect(()=>{var t;if(!N.current)return;let n=N.current.getStage(),r=e.selectedShapes.map(e=>e._cropModeEnabled?null:n.findOne(`#`+e.id)).filter(e=>!!e),i=e.selectedElements.length===1,a=i&&e.selectedElements[0]?.type||`many`;lA[a]?(N.current.setAttrs(Object.assign(Object.assign({},cA),lA[a])),a!==`svg`&&a!==`image`&&a!==`gif`||e.selectedElements[0].keepRatio||N.current.setAttrs({enabledAnchors:cA.enabledAnchors}),a===`text`&&yp.textVerticalResizeEnabled&&N.current.setAttrs({enabledAnchors:lA.text.enabledAnchors?.concat([`bottom-center`])}),a===`text`&&i&&e.selectedElements[0].curveEnabled&&N.current.setAttrs({enabledAnchors:lA.many.enabledAnchors})):N.current.setAttrs(cA),ue&&N.current.enabledAnchors([]),de&&N.current.rotateEnabled(!1),r.find(e=>e?.isDragging())&&r.forEach(e=>{e.isDragging()||e==null||e.startDrag()}),N.current.nodes(r),mb(),(t=N.current.getLayer())==null||t.batchDraw()},[e.selectedShapes,ce,ue,fe,de,le]);let pe=()=>{let e=N.current;if(!e)return;if(!e.isTransforming()){I({});return}if(!e.nodes().length||!e.isTransforming())return;let t=e.__getNodeRect(),n=e?.getActiveAnchor(),r=e.getStage();I({anchor:n,x:t.x-(r?.x()??0),y:t.y-(r?.y()??0),rotation:t.rotation,width:t.width,height:t.height})},me=d.useCallback(()=>{if(N.current?.isTransforming())return;let e=N.current;if(!e||!e.nodes().length){oe(0);return}let t=e.getClientRect();e.getStage()&&oe(function(e,t,n,r=0){let i=e.x+e.width/2,a=e.y+e.height/2,o=e.width/2,s=e.height/2,c=r*Math.PI/180,l=e=>{let t=e*Math.PI/180,r=(e%360+360)%360,l;l=r===0||r===180?s:o;let u=Math.sin(t)*(l+n),d=-Math.cos(t)*(l+n),f=u*Math.cos(c)-d*Math.sin(c),p=u*Math.sin(c)+d*Math.cos(c);return{x:i+f,y:a+p}},u=e=>e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom;if(u(l(0)))return 0;for(let e of[180,270,90])if(u(l(e)))return e;return 0}(t,{top:D?.top||0,bottom:r-(D?.bottom||0),left:D?.left||0,right:n-(D?.right||0)},cA.rotateAnchorOffset||30,e.rotation()))},[D,n,r]);d.useEffect(()=>{var e;(e=N.current)==null||e.update(),pe(),me()},[e.scale,me]),d.useEffect(()=>{me()},[e.selectedShapes,me]);let he=da(()=>({visible:!1,x1:0,y1:0,x2:0,y2:0})),ge=d.useRef(!1),_e=Bp(),ve=Vn(e=>{if(_e)return;ge.current=!1;let t=e.target.findAncestor(`.elements-container`),n=e.target.findAncestor(`Transformer`),r=e.target.findAncestor(`.page-abs-container`);if(t||n||r)return;let i=e.target.getStage()?.getPointerPosition();i&&(i.x-=e.target.getStage()?.x()??0,i.y-=e.target.getStage()?.y()??0,he.visible=!0,he.x1=i.x,he.y1=i.y,he.x2=i.x,he.y2=i.y,(e.target.getStage()?.getPointersPositions().length??0)>=2&&(he.visible=!1))});(({stageRef:e,containerRef:t,viewportSize:n})=>{d.useEffect(()=>{let n=t.current?.closest(`.polotno-workspace-inner`);function r(){if(!e.current)return;let r=t.current?.getBoundingClientRect(),i=n?.getBoundingClientRect();if(!r||!i)return;let a=Math.max(0,i.left-r.left-100),o=Math.max(0,i.top-r.top-100);e.current.position({x:-a,y:-o}),e.current.container().style.transform=`translate(${a}px, ${o}px)`}return r(),n?.addEventListener(`scroll`,r),()=>{n?.removeEventListener(`scroll`,r)}},[n.width,n.height])})({stageRef:P,containerRef:F,viewportSize:p}),d.useEffect(()=>{let t=Vn(e=>{var t;if(!he.visible)return;(t=P.current)==null||t.setPointersPositions(e);let n=P.current?.getPointerPosition();n?(n.x-=P.current?.x()??0,n.y-=P.current?.y()??0):n={x:he.x2,y:he.y2},he.x2=n.x,he.y2=n.y}),n=Vn(()=>{if(!he.visible||!P.current)return;let t=P.current.findOne(`.selection`),n=t?t.getClientRect({skipStroke:!0}):{width:0,height:0,x:0,y:0};if(n.width&&n.height){let t=[];P.current.find(`.element`).forEach(r=>{let i=r.getClientRect(),a=e.getElementById(r.id()),o=a?.draggable,s=a?.selectable;Du.Util.haveIntersection(n,i)&&o&&s&&t.push(a.top.id)});let r=[...new Set(t)];ge.current=!0,e.selectElements(r)}he.visible=!1});return window.addEventListener(`mousemove`,t),window.addEventListener(`touchmove`,t),window.addEventListener(`mouseup`,n,{capture:!0}),window.addEventListener(`touchend`,n,{capture:!0}),()=>{window.removeEventListener(`mousemove`,t),window.removeEventListener(`touchmove`,t),window.removeEventListener(`mouseup`,n),window.removeEventListener(`touchend`,n)}},[]);let ye=d.useCallback(n=>{if(!e.selectedElements[0]||n&&e.selectedElementsIds.includes(n))return;let r=ob(e.selectedShapes),i=ab(n?e.getElementById(n):{x:0,y:0,width:t.computedWidth,height:t.computedHeight,rotation:0}),a=[];r.minX>i.maxX&&a.push({distance:r.minX-i.maxX,box1:r,box2:i,points:[{x:r.minX,y:r.minY+r.height/2},{x:i.maxX,y:r.minY+r.height/2},{x:i.maxX,y:i.minY+i.height/2}]}),r.maxX<i.minX&&a.push({distance:i.minX-r.maxX,box1:r,box2:i,points:[{x:r.maxX,y:r.minY+r.height/2},{x:i.minX,y:r.minY+r.height/2},{x:i.minX,y:i.minY+i.height/2}]}),r.minY>i.maxY&&a.push({box1:r,box2:i,distance:r.minY-i.maxY,points:[{x:r.minX+r.width/2,y:r.minY},{x:r.minX+r.width/2,y:i.maxY},{x:i.minX+i.width/2,y:i.maxY}]}),r.maxY<i.minY&&a.push({box1:r,box2:i,distance:i.minY-r.maxY,points:[{x:r.minX+r.width/2,y:r.maxY},{x:r.minX+r.width/2,y:i.minY},{x:i.minX+i.width/2,y:i.minY}]});let o=r.minX>=i.minX&&r.maxX<=i.maxX&&r.minY>=i.minY&&r.maxY<=i.maxY;if(o&&(a.push({distance:r.minX-i.minX,box1:r,box2:i,points:[{x:r.minX,y:r.minY+r.height/2},{x:i.minX,y:r.minY+r.height/2},{x:i.minX,y:i.minY+i.height/2}]}),a.push({distance:i.maxX-r.maxX,box1:r,box2:i,points:[{x:r.maxX,y:r.minY+r.height/2},{x:i.maxX,y:r.minY+r.height/2},{x:i.maxX,y:i.minY+i.height/2}]}),a.push({box1:r,box2:i,distance:r.minY-i.minY,points:[{x:r.minX+r.width/2,y:r.minY},{x:r.minX+r.width/2,y:i.minY},{x:i.minX+i.width/2,y:i.minY}]}),a.push({box1:r,box2:i,distance:i.maxY-r.maxY,points:[{x:r.minX+r.width/2,y:r.maxY},{x:r.minX+r.width/2,y:i.maxY},{x:i.minX+i.width/2,y:i.maxY}]})),a.length===0&&!o){let e=r.minX<i.maxX&&r.maxX>i.minX,t=r.minY<i.maxY&&r.maxY>i.minY;if(e&&t){let e=(Math.max(r.minY,i.minY)+Math.min(r.maxY,i.maxY))/2,t=(Math.max(r.minX,i.minX)+Math.min(r.maxX,i.maxX))/2;r.minX<i.minX?a.push({distance:i.minX-r.minX,box1:r,box2:i,points:[{x:r.minX,y:e},{x:i.minX,y:e},{x:i.minX,y:e}]}):a.push({distance:r.minX-i.minX,box1:r,box2:i,points:[{x:r.minX,y:e},{x:i.minX,y:e},{x:i.minX,y:e}]}),r.maxX>i.maxX?a.push({distance:r.maxX-i.maxX,box1:r,box2:i,points:[{x:i.maxX,y:e},{x:r.maxX,y:e},{x:i.maxX,y:e}]}):a.push({distance:i.maxX-r.maxX,box1:r,box2:i,points:[{x:r.maxX,y:e},{x:i.maxX,y:e},{x:i.maxX,y:e}]}),r.minY<i.minY?a.push({box1:r,box2:i,distance:i.minY-r.minY,points:[{x:t,y:r.minY},{x:t,y:i.minY},{x:t,y:i.minY}]}):a.push({box1:r,box2:i,distance:r.minY-i.minY,points:[{x:t,y:r.minY},{x:t,y:i.minY},{x:t,y:i.minY}]}),r.maxY>i.maxY?a.push({box1:r,box2:i,distance:r.maxY-i.maxY,points:[{x:t,y:i.maxY},{x:t,y:r.maxY},{x:t,y:i.maxY}]}):a.push({box1:r,box2:i,distance:i.maxY-r.maxY,points:[{x:t,y:r.maxY},{x:t,y:i.maxY},{x:t,y:i.maxY}]})}}JSON.stringify(ne)!==JSON.stringify(a)&&re(a)},[e,t]);d.useEffect(()=>{e.distanceGuidesVisible?ye():ne&&re(null)},[e.distanceGuidesVisible,ye,e.selectedShapes.map(e=>`${e.x},${e.y},${e.width},${e.height},${e.rotation}`).join(`|`)]);let be=d.useRef(!1);d.useEffect(()=>{let e,t=F.current?.closest(`.polotno-workspace-inner`),n=()=>{be.current=!0,clearTimeout(e),e=setTimeout(()=>{be.current=!1},300)};return t?.addEventListener(`scroll`,n),()=>{clearTimeout(e),t?.removeEventListener(`scroll`,n)}},[]),d.useEffect(()=>{let e=P.current;if(!e)return;let t=e.container(),n=e=>{var t,n;e.touches.length>=2&&((t=N.current)!=null&&t.isDragging()&&N.current.stopDrag(),(n=N.current)==null||n.nodes().forEach(e=>{e.isDragging()&&e.stopDrag()}))};return t.addEventListener(`touchstart`,n,{passive:!0}),t.addEventListener(`touchmove`,n,{passive:!0}),()=>{t.removeEventListener(`touchstart`,n),t.removeEventListener(`touchmove`,n)}},[]);let xe=n=>{if(e.activePage!==t&&t.select(),be.current||ge.current)return;let r=n.evt.ctrlKey||n.evt.metaKey||n.evt.shiftKey,i=n.target.findAncestor(`.elements-container`),a=n.target.findAncestor(`.page-abs-container`),o=n.target.findAncestor(`Transformer`);if(!(r||i||o||a||he.visible)){e.selectElements([]);return}let s=n.target.findAncestor(`.element-container`,!0)?.findOne(`.element`)||n.target.findAncestor(`.element`,!0),c=e.getElementById(s?.id())?.top?.id,l=e.selectedElementsIds.indexOf(c)>=0,u=n.target.findAncestor(`.page-container`,!0);c&&r&&!l?e.selectElements(e.selectedElementsIds.concat([c])):c&&r&&l?e.selectElements(e.selectedElementsIds.filter(e=>e!==c)):!c||r||l?u?e.selectPages([t.id]):e.selectPages([]):e.selectElements([c])};hb(N,e,{stroke:_,strokeWidth:v,dash:y});let Se=e.activePage===t,Ce=e._selectedPagesIds.includes(t.id),we=l?.PageControls,Te=l?.Tooltip,Ee=l?.ContextMenu,De=1/e.scale,Oe=0/e.scale;return d.createElement(`div`,{ref:F,onDragOver:e=>e.preventDefault(),onDrop:n=>{if(n.preventDefault(),!P.current)return;P.current.setPointersPositions(n);let r=P.current.findOne(`.elements-container`)?.getRelativePointerPosition(),i=P.current.getPointerPosition(),a=P.current.getAllIntersections(i).map(e=>e.findAncestor(`.element`,!0)).filter(Boolean),o=[...new Set(a.reverse())].map(t=>e.getElementById(t.id())).filter(e=>!!e),s=o[0];yA&&r&&(yA(r,s,{elements:o,page:t}),yA=null)},style:{position:`relative`,width:n+`px`,height:r+`px`,overflow:`hidden`,flexShrink:0},className:`polotno-page-container`+(Se?` active-page`:``)},d.createElement(nf,{ref:P,width:Math.min(n,p.width+200),height:Math.min(p.height+200,r),onClick:xe,onTap:xe,onContextMenu:t=>{t.evt.preventDefault();let n=t.target.findAncestor(`.element`,!0),r=e.getElementById(n?.id())?.top?.id;r?e.selectedElementsIds.indexOf(r)>=0||e.selectElements([r]):e.selectElements([]),se.open({x:t.evt.clientX,y:t.evt.clientY})},onMouseDown:ve,onMouseMove:t=>{if(!e.distanceGuidesVisible&&!t.evt.altKey){ne&&re(null);return}ye(t.target.findAncestor(`.element`,!0)?.id())},onDragStart:t=>{var n;let r=t.target.getStage();if(r&&r.getPointersPositions().length>=2){t.target.stopDrag();return}let i=t.target.findAncestor(`.element`,!0);if(i){let r=e.getElementById(i?.id())?.top?.id;!(e.selectedElementsIds.indexOf(r)>=0)&&r&&(e.selectElements([r]),t.target.stopDrag(),t.target.startDrag(t),(n=N.current)==null||n.startDrag(t))}ne&&re(null)},pageId:t.id,style:{position:`absolute`,overflow:`hidden`,top:0,left:0}},d.createElement(Gd,null,d.createElement(uA,{width:n,height:r,fill:a}),d.createElement(Kd,{x:j,y:M,scaleX:e.scale,scaleY:e.scale,name:`page-container`},d.createElement(Kd,{name:`page-container-2`},d.createElement(Kd,{name:`page-background-group`,x:O,y:O},d.createElement(pA,{x:-t.bleed,y:-t.bleed,width:t.computedWidth+2*t.bleed,height:t.computedHeight+2*t.bleed,background:t.background,transparencyBackgroundColor:o,name:`page-background`,preventDefault:!1,scale:e.scale})),d.createElement(Kd,{x:O,y:O,name:`elements-container`,listening:!e.isPlaying},d.createElement(Jd,{name:`elements-area`,width:t.computedWidth,height:t.computedHeight,listening:!1}),d.createElement(_A,{elements:t.children,store:e})),d.createElement(Jd,{stroke:u,name:`bleed`,strokeWidth:t.bleed,x:t.bleed/2,y:t.bleed/2,width:t.computedWidth+t.bleed,height:t.computedHeight+t.bleed,listening:!1,visible:t.bleed>0&&e.bleedVisible,hideInExport:!0}),tO()===SA&&d.createElement(CA,{name:`hit-detection`,x:-De/2-Oe,y:-De/2-Oe,width:k+De+2*Oe,height:A+De+2*Oe}))),d.createElement(Yd,{name:`workspace-background`,points:[0,0,n,0,n,r,0,r,0,0,j,M,j,r-M,n-j,r-M,n-j,M,j,M],listening:!1,closed:!0,fill:a}),d.createElement(Kd,{x:j,y:M,scaleX:e.scale,scaleY:e.scale},d.createElement(Jd,{name:`page-highlight`,hideInExport:!0,x:-De/2-Oe,y:-De/2-Oe,width:k+De+2*Oe,height:A+De+2*Oe,stroke:Ce?c:s,strokeWidth:2,listening:!1,strokeScaleEnabled:!1})),d.createElement(Kd,{x:j+O*e.scale,y:M+O*e.scale,scaleX:e.scale,scaleY:e.scale,name:`page-abs-container`},d.createElement(ef,{ref:N,rotateAnchorAngle:ae,onDragStart:n=>{var r;let i=n.target.getStage();i&&i.getPointersPositions().length>=2?n.target.stopDrag():((r=n.evt)!=null&&r.altKey&&f&&e.selectedElements.forEach(e=>{let n=e.clone({},{skipSelect:!0}),r=t.children.indexOf(e);t.setElementZIndex(n.id,r)}),te.current=!0,e.history.startTransaction())},onDragEnd:()=>{te.current&&=(e.history.endTransaction(),!1),me()},onTransformStart:()=>{e.history.startTransaction(),re(null)},boundBoxFunc:(t,n)=>{let r=Math.abs(n.width)<1||Math.abs(n.height)<1,i=Math.abs(t.width)<1||Math.abs(t.height)<1;if(r&&!i)return t;let a=e.selectedElements;if(a.length===1&&a[0]?.type===`table`){let e=a[0],r=Math.abs(t.width),i=Math.abs(t.height);if(r>0&&i>0){let a=Math.abs(n.width)/r,o=Math.abs(n.height)/i,s=e.width*a,c=e.height*o;if(s<e.minWidth||c<e.minHeight)return t}}return n},onTransform:e=>{let t=N.current.nodes(),n=t[t.length-1];e.target===n&&setTimeout(()=>{pe()},0)},onTransformEnd:t=>{I({}),e.history.endTransaction(),me()},visible:!e.isPlaying}),ne&&ne.map(({points:t,distance:n,box1:r,box2:i},a)=>d.createElement(`Group`,{name:`distances-container`,hideInExport:!0,key:a,listening:!1},d.createElement(`Rect`,Object.assign({},r,{stroke:S,strokeWidth:1,strokeScaleEnabled:!1})),d.createElement(`Rect`,Object.assign({},i,{stroke:S,strokeWidth:1,strokeScaleEnabled:!1})),d.createElement(`Line`,{points:[t[0].x,t[0].y,t[1].x,t[1].y],stroke:S,strokeWidth:1,strokeScaleEnabled:!1}),d.createElement(`Line`,{points:[t[1].x,t[1].y,t[2].x,t[2].y],stroke:S,strokeWidth:1,strokeScaleEnabled:!1}),d.createElement(`Label`,{x:(t[0].x+t[1].x)/2,y:(t[0].y+t[1].y)/2,offsetY:-10,scaleX:1/e.scale,scaleY:1/e.scale},d.createElement(`Tag`,{cornerRadius:5,fill:C,pointerDirection:`down`}),d.createElement(`Text`,{align:`center`,verticalAlign:`middle`,fill:w,padding:5,text:xO({unit:e.unit,dpi:e.dpi,px:n})})))),t._rendering&&d.createElement(`Group`,null,d.createElement(`Rect`,{width:k,height:A,fill:`rgba(255,255,255,0.9)`}),d.createElement(`Text`,{text:`Rendering...`,fontSize:60,width:k,height:A,align:`center`,verticalAlign:`middle`})),Te&&d.createElement(Te,{components:l,store:e,page:t,stageRef:P,tooltipSafeArea:E}),Ee&&d.createElement(cf,null,d.createElement(Ee,Object.assign({components:l,store:e},se.props)))),d.createElement(eA,{store:e,page:t,width:n,height:r,scale:e.scale,xPadding:j,yPadding:M,bleed:O}),d.createElement(gA,Object.assign({},ie,{store:e,tagFill:b,textFill:x})),d.createElement(mA,{selection:he,fill:m,stroke:h,strokeWidth:g}),rO()>0&&d.createElement(`Group`,{hideInExport:!0},d.createElement(DA,{name:`cache-bounds`,x:n-(rO()===1?250:210),y:r-(rO()===1?95:45)}),d.createElement(DA,{name:`cache-bounds-t`,x:10,y:10})),iO()&&d.createElement(`Text`,{text:`Powered by polotno.com`,fontSize:14,fill:`rgba(0,0,0,0.6)`,x:n-170,y:r-18,onMouseEnter:e=>{e.target.getStage().container().style.cursor=`pointer`},onMouseLeave:e=>{e.target.getStage().container().style.cursor=``},onTouchStart:e=>{e.cancelBubble=!0},onMouseDown:e=>{e.cancelBubble=!0},onClick:()=>{window.open(`https://polotno.com`)},onTap:()=>{window.open(`https://polotno.com`)}}),d.createElement(Kd,{name:`line-guides`}))),ee&&we&&d.createElement(we,{store:e,page:t,xPadding:j,yPadding:M,layout:T}))}),kA=Wy(`div`,d.forwardRef)`
285
+ `],{type:`application/javascript`}))})}var eO=`https://api.polotno.com`;`${eO}`;var tO=()=>eO+`/api`,nO=L({value:!1}),rO=L({value:`v1`}),iO=()=>rO.value,aO=L({value:0}),oO=()=>aO.value,sO=()=>nO.value,cO=Vn(()=>{nO.value=!0}),lO=typeof window<`u`?window.location.origin:``,uO=typeof navigator<`u`&&navigator.userAgent.indexOf(`Headless`)>-1,dO=typeof navigator<`u`&&navigator.userAgent.indexOf(`Electron`)>-1;lO===`file://`&&uO&&(lO=`headless`),lO===`file://`&&dO&&(lO=`electron`);var fO=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${lO}" here: https://polotno.com/cabinet`,pO=fetch;async function mO(e){for(let t=0;t<5;t++)try{let t=await pO(tO()+`/validate-key`,{method:`POST`,body:JSON.stringify({key:e,site:location.host,skdVersion:`2.38.2`})});if(Un(()=>{rO.value=t.headers.get(`x-api-version`)||``}),!e)return console.error(`Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet`),Un(()=>{aO.value=1}),!1;if(t.status!==200){await new Promise(e=>setTimeout(e,3e3));continue}let n=await t.json();return n.is_valid||(console.error(`Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet`),Un(()=>{aO.value=1})),n.is_paid||(console.log(`%cPolotno Free Version. For development usage only. https://polotno.com/`,`background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;`),Un(()=>{aO.value===0&&(aO.value=2)})),n.is_domain_valid||console.log(fO,`background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;`),Tp(n.remove_background_enabled),n.is_paid||!1}catch{await new Promise(e=>setTimeout(e,3e3))}return console.error(`Can not validate Polotno API key. Please report to anton@polotno.com immediately.`),!0}async function hO(e,t){await mO(e)&&!t||cO()}var gO=[112,72,89,115],_O=(()=>{let e=new Uint32Array(256);for(let t=0;t<256;t++){let n=t;for(let e=0;e<8;e++)n=1&n?3988292384^n>>>1:n>>>1;e[t]=n>>>0}return e})(),vO=()=>typeof globalThis<`u`?globalThis.Buffer:void 0,yO=(e,t,n)=>{e[t]=n>>>24&255,e[t+1]=n>>>16&255,e[t+2]=n>>>8&255,e[t+3]=255&n},bO=(e,t,n)=>{let r=e.indexOf(`,`),i=(e=>{if(typeof atob==`function`){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}let t=vO();if(t)return new Uint8Array(t.from(e,`base64`));throw Error(`No base64 decoder available`)})(r>=0?e.slice(r+1):e);return`data:${t};base64,${(e=>{if(typeof btoa==`function`){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}let t=vO();if(t)return t.from(e).toString(`base64`);throw Error(`No base64 encoder available`)})(t===`image/png`?((e,t)=>{let n=(e=>{let t=new Uint8Array(9),n=new DataView(t.buffer);n.setUint32(0,e,!1),n.setUint32(4,e,!1),t[8]=1;let r=new Uint8Array(8+t.length+4);yO(r,0,t.length),r.set(gO,4),r.set(t,8);let i=new Uint8Array(4+t.length);return i.set(gO,0),i.set(t,4),yO(r,8+t.length,(e=>{let t=4294967295;for(let n=0;n<e.length;n++)t=_O[255&(t^e[n])]^t>>>8;return(4294967295^t)>>>0})(i)),r})(Math.round(t/.0254)),r=((e,t)=>{let n=8;for(;n+8<=e.length;){let r=e[n]<<24|e[n+1]<<16|e[n+2]<<8|e[n+3],i=n+4,a=e.subarray(i,i+4),o=8+r+4;if(t.every((e,t)=>a[t]===e))return{offset:n,totalLength:o};n+=o}return null})(e,gO);if(r){let t=new Uint8Array(e.length-r.totalLength+n.length);return t.set(e.slice(0,r.offset),0),t.set(n,r.offset),t.set(e.slice(r.offset+r.totalLength),r.offset+n.length),t}let i=16+(e[8]<<24|e[9]<<16|e[10]<<8|e[11])+4;if(i>e.length)return e;let a=new Uint8Array(e.length+n.length);return a.set(e.slice(0,i),0),a.set(n,i),a.set(e.slice(i),i+n.length),a})(i,n):((e,t)=>{let n=(e=>{let t=2;for(;t+4<e.length;){if(e[t]!==255)return-1;let n=e[t+1];if(n===216||n===217){t+=2;continue}let r=e[t+2]<<8|e[t+3];if(r<2)return-1;if(n===224&&e[t+4]===74&&e[t+5]===70&&e[t+6]===73&&e[t+7]===70&&e[t+8]===0)return t;let i=t+2+r;if(i<=t||i>e.length)return-1;t=i}return-1})(e);if(n>=0){let r=new Uint8Array(e),i=n+11;return r[i]=1,r[i+1]=t>>8&255,r[i+2]=255&t,r[i+3]=t>>8&255,r[i+4]=255&t,r}let r=(e=>{let t=new Uint8Array(18);return t[0]=255,t[1]=224,t[2]=0,t[3]=16,t[4]=74,t[5]=70,t[6]=73,t[7]=70,t[8]=0,t[9]=1,t[10]=1,t[11]=1,t[12]=e>>8&255,t[13]=255&e,t[14]=e>>8&255,t[15]=255&e,t})(t),i=new Uint8Array(e.length+r.length);return i.set(e.subarray(0,2),0),i.set(r,2),i.set(e.subarray(2),2+r.length),i})(i,n))}`},xO=({px:e,unit:t=`px`,dpi:n})=>{switch(t){case`pt`:default:return e;case`mm`:return e/(n/25.4);case`cm`:return e/(n/2.54);case`in`:return e/n}},SO=({px:e,precious:t=2,dpi:n=72,unit:r=`px`})=>parseFloat(xO({px:e,dpi:n,unit:r}).toFixed(t)),CO=({unitVal:e,dpi:t,unit:n})=>e/xO({px:1,unit:n,dpi:t}),wO=e=>{let t=parseFloat(xO(e).toFixed(1));switch(e.unit){case`pt`:return`${Math.round(t)}pt`;case`mm`:return`${t}mm`;case`cm`:return`${t}cm`;case`in`:return`${t}in`;default:return`${Math.round(t)}px`}};async function TO(e){for(let t=0;t<30;t++){let t=await e();if(t)return t;await new Promise(e=>setTimeout(e,50))}}function EO(e){return new Promise((t,n)=>{let r=document.createElement(`img`);r.onload=()=>{t(r)},r.onerror=e=>{n(e)},r.crossOrigin=`anonymous`,r.src=e})}async function DO(e,t){let n=await EO(e),r=document.createElement(`canvas`);r.width=2*n.width,r.height=2*n.height,r.getContext(`2d`).drawImage(n,0,0,r.width,r.height);let i=document.createElement(`canvas`);i.width=t.width,i.height=t.height;let a=i.getContext(`2d`),{cropX:o,cropY:s}=t,c=r.width*t.cropWidth,l=r.height*t.cropHeight,u=t.width/t.height,d,f,p=c/l;return t.type===`svg`?(d=c,f=l):u>=p?(d=c,f=c/u):(d=l*u,f=l),a.drawImage(r,o*r.width,s*r.height,d,f,0,0,i.width,i.height),i.toDataURL(`image/png`)}function OO(e,t){let{width:n,height:r}=e,i=n/r,a,o;i>=t.width/t.height?(a=t.width,o=t.width/i):(a=t.height*i,o=t.height);let s=(t.width-a)/2,c=(t.height-o)/2;return{cropX:s/t.width,cropY:c/t.height,cropWidth:a/t.width,cropHeight:o/t.height}}var kO;(function(e){e.sepia=`sepia`,e.grayscale=`grayscale`,e.natural=`natural`,e.warm=`warm`,e.cold=`cold`,e.temperature=`temperature`,e.contrast=`contrast`,e.shadows=`shadows`,e.white=`white`,e.black=`black`,e.vibrance=`vibrance`,e.saturation=`saturation`})(kO||={});function AO(e,t){let n={filter:``,html:void 0};switch(e){case kO.warm:{let e=Math.max(0,Math.min(1,t??.5)),r=1+.3*e,i=1+.15*e;return n.filter=`url(#warm-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="warm-filter" color-interpolation-filters="sRGB">\n <feColorMatrix type="matrix" values="\n ${r} 0 0 0 0\n 0 ${i} 0 0 0\n 0 0 1 0 0\n 0 0 0 1 0" />\n </filter>\n </svg>`,n}case kO.cold:{let e=Math.max(0,Math.min(1,t??.5)),r=1-.15*e,i=1-.1*e,a=1+.15*e;return n.filter=`url(#cold-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="cold-filter" color-interpolation-filters="sRGB">\n <feColorMatrix type="matrix" values="\n ${r} 0 0 0 0\n 0 ${i} 0 0 0\n 0 0 ${a} 0 0\n 0 0 0 1 0" />\n </filter>\n </svg>`,n}case`natural`:{let e=Math.max(0,Math.min(1,t??.5)),r=1+.1*e;return n.filter=`saturate(${1+.3*e}) brightness(${r}) contrast(${1+.2*e})`,n}case kO.temperature:{let e=Math.max(-1,Math.min(1,t??0)),r=1+.15*e,i=1-.15*e;return n.filter=`url(#temperature-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="temperature-filter" color-interpolation-filters="sRGB">\n <feColorMatrix type="matrix" values="\n ${r} 0 0 0 0\n 0 1 0 0 0\n 0 0 ${i} 0 0\n 0 0 0 1 0" />\n </filter>\n </svg>\n `,n}case kO.contrast:{let e=100*Math.max(-1,Math.min(1,t??0)),r=259*(e+255)/(255*(259-e)),i=.5*(1-r);return n.filter=`url(#contrast-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="contrast-filter" color-interpolation-filters="sRGB">\n <feComponentTransfer>\n <feFuncR type="linear" slope="${r}" intercept="${i}" />\n <feFuncG type="linear" slope="${r}" intercept="${i}" />\n <feFuncB type="linear" slope="${r}" intercept="${i}" />\n </feComponentTransfer>\n </filter>\n </svg>\n `,n}case kO.shadows:{let e=Math.max(-1,Math.min(1,t??0)),r=Math.min(Math.max(1-.6*e,.4),2.5);return n.filter=`url(#shadows-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="shadows-filter" color-interpolation-filters="sRGB">\n <feComponentTransfer>\n <feFuncR type="gamma" amplitude="1" exponent="${r}" offset="0" />\n <feFuncG type="gamma" amplitude="1" exponent="${r}" offset="0" />\n <feFuncB type="gamma" amplitude="1" exponent="${r}" offset="0" />\n </feComponentTransfer>\n </filter>\n </svg>\n `,n}case kO.white:case kO.black:return null;case kO.vibrance:{let e=Math.max(-1,Math.min(1,t??0)),r=.299,i=.587,a=.114,o;o=e>=0?1+1.5*e:1+e;let s=1-o,c=s*r+o,l=s*i,u=s*a,d=s*r,f=s*i+o,p=s*a,m=s*r,h=s*i,g=s*a+o;return n.filter=`url(#vibrance-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="vibrance-filter" color-interpolation-filters="sRGB">\n <feColorMatrix type="matrix" values="\n ${c} ${l} ${u} 0 0\n ${d} ${f} ${p} 0 0\n ${m} ${h} ${g} 0 0\n 0 0 0 1 0" />\n </filter>\n </svg>\n `,n}case kO.saturation:{let e=.2126,r=.7152,i=.0722,a=1+Math.max(-1,Math.min(1,t??0)),o=1-a,s=o*e+a,c=o*r,l=o*i,u=o*e,d=o*r+a,f=o*i,p=o*e,m=o*r,h=o*i+a;return n.filter=`url(#saturation-filter)`,n.html=`\n <svg xmlns="http://www.w3.org/2000/svg" style="display:none">\n <filter id="saturation-filter" color-interpolation-filters="sRGB">\n <feColorMatrix type="matrix" values="\n ${s} ${c} ${l} 0 0\n ${u} ${d} ${f} 0 0\n ${p} ${m} ${h} 0 0\n 0 0 0 1 0" />\n </filter>\n </svg>\n `,n}default:return null}}async function jO(e){return new Promise((t,n)=>{let r=document.createElement(`video`);r.crossOrigin=`anonymous`,r.src=e,r.addEventListener(`loadedmetadata`,()=>{let{videoWidth:e,videoHeight:n}=r;t({width:e,height:n})}),r.addEventListener(`error`,t=>{let r=e.slice(0,100);n(Error(`Failed to load video: ${r}`))})})}var MO=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n},NO=(e,t,...n)=>({type:e,props:t,children:n||[]});function PO(e){return jf(e),e}function FO(e){var t=new DOMParser().parseFromString(e,`image/svg+xml`);return t.documentElement.setAttribute(`preserveAspectRatio`,`none`),new XMLSerializer().serializeToString(t)}var IO=async({element:e,page:t,store:n})=>{let{src:r}=e;if(e.type===`svg`){let t=await q_(r);t=FO(t),r=Object.keys(e.colorsReplace).length?Z_(t,new Map(Object.entries(e.colorsReplace))):J_(t)}let i=``;e.flipX&&(i+=`scaleX(-1)`),e.flipY&&(i+=`scaleY(-1)`),i||=`none`;let a={};if(e.type===`svg`&&e.maskSrc){let t=await K_(r);a[`mask-image`]=`url(${t})`,a[`mask-size`]=`100% 100%`,a[`mask-position`]=`0 0`,a[`mask-repeat`]=`no-repeat`,a[`-webkit-mask-image`]=`url(${t})`,a[`-webkit-mask-size`]=`100% 100%`,a[`-webkit-mask-position`]=`0 0`,a[`-webkit-mask-repeat`]=`no-repeat`,r=e.maskSrc}else if(e.clipSrc){let t=e.clipSrc,n=await K_(t);a[`mask-image`]=`url(${n})`,a[`mask-size`]=`100% 100%`,a[`mask-position`]=`0 0`,a[`mask-repeat`]=`no-repeat`,a[`-webkit-mask-image`]=`url(${n})`,a[`-webkit-mask-size`]=`100% 100%`,a[`-webkit-mask-position`]=`0 0`,a[`-webkit-mask-repeat`]=`no-repeat`}let o=await EO(r),s=o.width*e.cropWidth,c=o.height*e.cropHeight,l=e.width/e.height,u,d,f=s/c,p=e.type===`svg`||e.stretchEnabled;p?(u=s,d=c):l>=f?(u=s,d=s/l):(u=c*l,d=c);let m=u/o.width,h=d/o.height,g=u/d>e.width/e.height?e.height/d:e.width/u,_=p?e.width/u:g,v=p?e.height/d:g,y=u*_/m,b=d*v/h,x=e.cropX*_*o.width,S=e.cropY*v*o.height;e.flipX&&(x=(1-e.cropX-e.cropWidth)*_*o.width),e.flipY&&(S=(1-e.cropY-e.cropHeight)*v*o.height);let C=e.borderSize&&jf(e.borderColor),w=C?Math.max(0,e.cornerRadius-e.borderSize):e.cornerRadius,T=NO(`div`,{style:Object.assign(Object.assign({},a),{width:`100%`,height:`100%`,borderRadius:w+`px`,border:e.borderSize&&!C?`${e.borderSize}px solid ${e.borderColor}`:`none`,backgroundRepeat:`no-repeat`,backgroundImage:`url(${r})`,transform:i,backgroundSize:`${Math.round(y)}px ${Math.round(b)}px`,backgroundPositionX:-Math.round(x)+`px`,backgroundPositionY:-Math.round(S)+`px`})});return C?NO(`div`,{style:{width:`100%`,height:`100%`,borderRadius:e.cornerRadius+`px`,background:PO(e.borderColor),padding:e.borderSize+`px`,boxSizing:`border-box`}},T):T},LO=({element:e,type:t})=>{let n={"stroke-width":e.height,stroke:e.color,"stroke-linecap":`round`,"stroke-linejoin":`round`,opacity:e.opacity},r=Object.assign(Object.assign({},n),{fill:e.color}),i=Object.assign(Object.assign({},n),{fill:`none`});return t===`arrow`?NO(`polyline`,Object.assign({points:`${3*e.height},${2*-e.height} 0,0 ${3*e.height},${2*e.height}`},i)):t===`triangle`?NO(`polygon`,Object.assign({points:`${3*e.height},${2*-e.height} 0,0 ${3*e.height},${2*e.height}`},r)):t===`bar`?NO(`polyline`,Object.assign({points:`0,${2*-e.height} 0,${2*e.height}`},i)):t===`circle`?NO(`circle`,Object.assign({cx:2*e.height,cy:0,r:2*e.height},r)):t===`square`?NO(`polygon`,Object.assign({points:`0,${2*-e.height} ${4*e.height},${2*-e.height} ${4*e.height},${2*e.height} 0,${2*e.height}`},r)):null},RO={image:IO,svg:IO,text:async({element:e,page:t,store:n})=>{let r=jf(e.fill),i=jf(e.stroke);if(e.curveEnabled){let t=Pp(e.width,e.height,e.curvePower,e.fontSize),n=Rp(ep(e.text),{fontWeight:e.fontWeight||`normal`,fontStyle:e.fontStyle||`normal`,fill:e.fill||`black`}),a=`\n <svg xmlns="http://www.w3.org/2000/svg" width="${e.width}" height="${e.height}" style="display: block;">\n <defs>\n <path id="curve-${e.id}" d="${t}" fill="none" />`;if(r){let t=`curve-fill-grad-${e.id}`;a+=Fp(e.fill,t)}if(i&&e.strokeWidth){let t=`curve-stroke-grad-${e.id}`;a+=Fp(e.stroke,t)}a+=`</defs>\n <text\n font-family="'${e.fontFamily}'"\n font-size="${e.fontSize}"\n font-weight="${e.fontWeight}"\n font-style="${e.fontStyle}"\n fill="${r?`url(#curve-fill-grad-${e.id})`:e.fill}"\n text-anchor="middle"\n dominant-baseline="central"\n letter-spacing="${e.letterSpacing*e.fontSize}px"${e.textDecoration?` text-decoration="${e.textDecoration}"`:``}${e.strokeWidth?` stroke="${i?`url(#curve-stroke-grad-${e.id})`:e.stroke}" stroke-width="${e.strokeWidth}" paint-order="stroke fill"`:``}>\n <textPath href="#curve-${e.id}" startOffset="50%">${n}</textPath>\n </text>\n </svg>`;let o=e.backgroundPadding*(e.fontSize*e.lineHeight);return NO(`div`,{style:{position:`relative`,width:`100%`,height:`100%`}},e.backgroundEnabled&&NO(`div`,{style:{position:`absolute`,top:-o/2+`px`,left:-o/2+`px`,width:e.width+o+`px`,height:e.height+o+`px`,backgroundColor:e.backgroundColor,opacity:e.backgroundOpacity,borderRadius:e.backgroundCornerRadius*(e.fontSize*e.lineHeight*.5)+`px`}}),NO(`div`,{style:{width:`100%`,height:`100%`,position:`absolute`,top:0,left:0},innerHTML:a}))}let a=e=>({backgroundImage:e,backgroundSize:`100% 100%`,backgroundRepeat:`repeat`,WebkitBackgroundClip:`text`,MozBackgroundClip:`text`,backgroundClip:`text`,WebkitTextFillColor:`transparent`,MozTextFillColor:`transparent`,color:`transparent`}),o={top:0,left:0};r&&(o=Object.assign(Object.assign({},o),a(e.fill)));let s=e.backgroundPadding*(e.fontSize*e.lineHeight),c=NO(`div`,{style:{position:`absolute`,top:-s/2+`px`,left:-s/2+`px`,display:e.backgroundEnabled?`block`:`none`,width:e.width+s+`px`,height:e.height+s+`px`,backgroundColor:e.backgroundColor,opacity:e.backgroundOpacity,borderRadius:e.backgroundCornerRadius*(e.fontSize*e.lineHeight*.5)+`px`}});e.verticalAlign===`middle`?(o.top=`50%`,o.transform=`translateY(-50%)`):e.verticalAlign===`bottom`&&(o.bottom=0);let l=/<[a-z][\s\S]*>/i.test(e.text),u=l?e.text:e.text.split(`
286
+ `).join(`<br />`);if(e.strokeWidth&&(i||r&&!i)){let t=Object.assign({position:`absolute`,width:e.width+`px`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,fontSize:e.fontSize+`px`,textAlign:e.align,fontFamily:`'${e.fontFamily}'`,textDecoration:e.textDecoration||`none`,textDecorationColor:e.textDecoration?e.fill:void 0,textTransform:e.textTransform||`none`,lineHeight:e.lineHeight,letterSpacing:e.letterSpacing*e.fontSize+`px`,fontStyle:e.fontStyle,fontWeight:e.fontWeight},o),n=i?Object.assign(Object.assign(Object.assign({},t),a(e.stroke)),{WebkitTextStroke:`${e.strokeWidth}px transparent`}):Object.assign(Object.assign({},t),{color:`transparent`,WebkitTextStroke:`${e.strokeWidth}px ${e.stroke}`}),s=r?Object.assign(Object.assign({},t),a(e.fill)):Object.assign(Object.assign({},t),{color:e.fill}),d=`el-`+e.id,f=l?`<style>#${d} {${wy}}</style>`:``,p=NO(`div`,{style:Object.assign(Object.assign({},n),{position:`absolute`,top:0,left:0,pointerEvents:`none`}),"aria-hidden":`true`,innerHTML:l?`${f}${u}`:u}),m=NO(`div`,Object.assign(Object.assign({style:Object.assign(Object.assign({},s),{position:`relative`})},l?{id:d}:{}),{innerHTML:l?`${f}${u}`:u}));return NO(`div`,{style:{position:`relative`,width:`100%`,height:`100%`}},c,NO(`div`,{style:{position:`relative`,width:e.width+`px`}},p,m))}let d=Object.assign(Object.assign({},o),{position:`absolute`,width:e.width+`px`,color:e.fill,whiteSpace:`pre-wrap`,wordBreak:`break-word`,fontSize:e.fontSize+`px`,textAlign:e.align,fontFamily:`'${e.fontFamily}'`,textDecoration:e.textDecoration||`none`,textDecorationColor:e.textDecoration?e.fill:void 0,textTransform:e.textTransform||`none`,lineHeight:e.lineHeight,letterSpacing:e.letterSpacing*e.fontSize+`px`,fontStyle:e.fontStyle,fontWeight:e.fontWeight,WebkitTextStroke:e.strokeWidth?`${e.strokeWidth}px ${e.stroke}`:void 0,paintOrder:e.strokeWidth?`stroke fill`:void 0}),f=`el-`+e.id,p=l?{id:f}:{},m=`<style>#${f} {${wy}}</style>`;return NO(`div`,{style:{position:`relative`,width:`100%`,height:`100%`}},c,NO(`div`,Object.assign(Object.assign({style:d},p),{innerHTML:l?`${m}${u}`:u})))},line:async({element:e,page:t,store:n})=>NO(`svg`,{style:{width:`100%`,height:`100%`,contain:`layout style size`,overflow:`visible`}},NO(`line`,{x1:0,y1:e.height/2,x2:e.width,y2:e.height/2,stroke:e.color,"stroke-width":e.height,"stroke-dasharray":e.dash&&e.dash.length?e.dash.map(t=>t*e.height).join(` `):void 0}),NO(`g`,{transform:`translate(0 ${e.height/2})`},LO({element:e,type:e.startHead})),NO(`g`,{transform:`translate(${e.width} ${e.height/2}) rotate(180)`},LO({element:e,type:e.endHead}))),figure:async({element:e,page:t,store:n,elementHook:r})=>{let i=AD(e);if(e.strokeWidth&&jf(e.stroke)){let t=`figure-stroke-grad-${e.id}`,n=Fp(e.stroke,t);i=i.replace(RegExp(`stroke="${e.stroke.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}"`,`g`),`stroke="url(#${t})"`),i=i.replace(`</defs>`,`${n}</defs>`)}if(jf(e.fill)){let t=`figure-fill-grad-${e.id}`,n=Fp(e.fill,t);i=i.replace(RegExp(`fill="${e.fill.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}"`,`g`),`fill="url(#${t})"`),i=i.replace(`</defs>`,`${n}</defs>`)}let a=NO(`div`,{innerHTML:i});return r&&r({dom:a,element:e})||a},group:async({element:e,page:t,store:n,elementHook:r})=>{let i=await Promise.all(e.children.map(e=>zO({element:e,page:t,store:n,elementHook:r}))),a=NO(`div`,{style:{transformOrigin:`top left`,opacity:e.opacity}},...i);return r&&r({dom:a,element:e})||a},video:async({element:e,page:t,store:n,elementHook:r})=>{let{cropX:i,cropY:a,cropWidth:o,cropHeight:s}=e,c=await jO(e.src),l=c.width*o,u=c.height*s,d=e.width/e.height,f,p;d>=l/u?(f=l,p=l/d):(f=u*d,p=u);let m=f/o,h=p/s,g=i*c.width,_=a*c.height,v=Math.max(e.width/c.width,e.height/c.height),y={position:`absolute`,width:`${Math.round(m*v)}px`,height:`${Math.round(h*v)}px`,left:-Math.round(g*v)+`px`,top:-Math.round(_*v)+`px`,objectFit:`fill`},b=`video-${e.id}`,x=e.borderSize&&jf(e.borderColor),S=NO(`div`,{style:{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`,borderRadius:(x?Math.max(0,e.cornerRadius-e.borderSize):e.cornerRadius)+`px`,border:e.borderSize&&!x?`${e.borderSize}px solid ${e.borderColor}`:`none`}},NO(`video`,{id:b,src:e.src,style:y,controls:!0,playsInline:!0,muted:!0,volume:e.volume}));if(x){let t=NO(`div`,{style:{width:`100%`,height:`100%`,borderRadius:e.cornerRadius+`px`,background:PO(e.borderColor),padding:e.borderSize+`px`,boxSizing:`border-box`}},S);return r&&r({dom:t,element:e})||t}return r&&r({dom:S,element:e})||S},gif:IO,table:async({element:e})=>{let t=e.rows,n=e.cols,r=e.colWidths,i=e.rowHeights,a=[`fontSize`,`fontFamily`,`fontWeight`,`fontStyle`,`textDecoration`,`textTransform`,`fill`,`align`,`verticalAlign`,`lineHeight`,`letterSpacing`,`strokeWidth`,`stroke`,`cellBackground`,`cellPadding`],o=(e.cells||[]).map(t=>{if(!t)return t;let n=Object.assign({},t);for(let t of a)n[t]===void 0&&(n[t]=e[t]);return n}),s=[];for(let r=0;r<t;r++){let t=[];for(let a=0;a<n;a++){let s=o[r*n+a];if(!s||s.mergedInto)continue;let c=s.cellPadding||4,l=s.colSpan||1,u=s.rowSpan||1,d=t=>{let n=s.borders?.[t];return`${n?.width??e.borderWidth}px ${n?.style??e.borderStyle??`solid`} ${n?.color??e.borderColor}`},f={style:{padding:c+`px`,background:s.cellBackground||`transparent`,fontSize:(s.fontSize||12)+`px`,fontFamily:`'${s.fontFamily||`Roboto`}'`,fontWeight:s.fontWeight||`normal`,fontStyle:s.fontStyle||`normal`,color:s.fill||`black`,textAlign:s.align||`left`,verticalAlign:s.verticalAlign||`top`,lineHeight:String(s.lineHeight||1.2),letterSpacing:s.letterSpacing?s.letterSpacing*(s.fontSize||12)+`px`:void 0,textDecoration:s.textDecoration||`none`,textTransform:s.textTransform||`none`,borderTop:d(`top`),borderRight:d(`right`),borderBottom:d(`bottom`),borderLeft:d(`left`),overflow:`hidden`,wordBreak:`break-word`,whiteSpace:`pre-wrap`,height:i[r]*e.height+`px`}};l>1&&(f.colspan=String(l)),u>1&&(f.rowspan=String(u)),t.push(NO(`td`,f,Qf(s.text||``)))}s.push(NO(`tr`,{},...t))}return NO(`table`,{style:{width:`100%`,height:`100%`,borderCollapse:`collapse`,tableLayout:`fixed`}},NO(`colgroup`,{},...r.map(e=>NO(`col`,{style:{width:100*e+`%`}}))),NO(`tbody`,{},...s))}};async function zO({element:e,page:t,store:n,elementHook:r}){let i=await RO[e.type];if(i||(i=()=>NO(`div`,{}),console.error(`HTML export does not support ${e.type} type...`)),!e.visible)return null;let a=await i({element:e,page:t,store:n}),o=[],s=[];if(e.blurEnabled&&o.push(`blur(${e.blurRadius/2}px)`),e.brightnessEnabled&&o.push(`brightness(${100*e.brightness+100}%)`),e.sepiaEnabled&&o.push(`sepia()`),e.grayscaleEnabled&&o.push(`grayscale()`),e.filters)for(let[t,n]of Object.entries(e.filters)){let e=AO(kO[t],n.intensity);e&&(o.push(e.filter),e.html&&s.push(e.html))}if(e.shadowEnabled){let t=function(e,t){if(t===1)return e;let n=Du.Util.colorToRGBA(e);return n?`rgba(${n.r}, ${n.g}, ${n.b}, ${n.a*t})`:e}(e.shadowColor,e.shadowOpacity??1);o.push(`drop-shadow(${e.shadowOffsetX}px ${e.shadowOffsetY}px ${e.shadowBlur/2}px ${t})`)}let c=NO(`div`,{id:e.id,style:{position:`absolute`,left:e.x+`px`,top:e.y+`px`,width:e.width+`px`,height:e.height+`px`,transform:`rotate(${e.rotation}deg)`,transformOrigin:`top left`,opacity:e.opacity,display:e.visible&&e.showInExport?`block`:`none`,filter:o.join(` `)||`none`}},a,...s);return r&&r({dom:c,element:e})||c}async function BO({json:e,elementHook:t}){let n=await Promise.all(e.pages.map(n=>async function({page:e,store:t,elementHook:n}){let r=await Promise.all(e.children.map(r=>zO({element:r,page:e,store:t,elementHook:n}))),i=e.width===`auto`?t.width:e.width,a=e.height===`auto`?t.height:e.height,o={};if(e.background.indexOf(`url`)>=0||e.background.indexOf(`http`)>=0||e.background.indexOf(`.jpg`)>=0||e.background.indexOf(`.png`)>=0||e.background.indexOf(`.jpeg`)>=0){let{width:n,height:o}=await EO(e.background),s=await IO({element:Object.assign({x:0,y:0,width:i,height:a,src:e.background,cornerRadius:0},OO({width:i,height:a},{width:n,height:o})),page:e,store:t});r.unshift(s)}else o=Object.assign(Object.assign({},o),{backgroundColor:e.background});return NO(`div`,{className:`page`,id:e.id,style:Object.assign(Object.assign({},o),{width:i+`px`,height:a+`px`,overflow:`hidden`,position:`relative`})},...r)}({page:n,store:e,elementHook:t}))),r=[];return Wk({children:e.pages},e=>{e.type!==`text`&&e.type!==`tablecell`&&e.type!==`table`||!e.fontFamily||r.indexOf(e.fontFamily)!==-1||r.push(e.fontFamily)}),NO(`div`,{className:`design`},...r.map(t=>{let n=e.fonts.find(e=>e.fontFamily===t);return n?NO(`style`,{},(n.styles||(n.url?[{src:`url("${n.url}")`}]:[])).map(e=>`\n @font-face {\n font-family: '${n.fontFamily}';\n src: ${e.src};\n font-style: ${e.fontStyle||`normal`};\n font-weight: ${e.fontWeight||`normal`};\n font-display: swap;\n }`).join(`
287
+ `)):NO(`link`,{href:_p(t),rel:`stylesheet`})}),...n)}var VO=({dom:e})=>{if(typeof e==`string`)return e;if(!e)return``;let t=e.props,{innerHTML:n}=t,r=MO(t,[`innerHTML`]),i=Object.keys(r).map(e=>e===`style`&&typeof r[e]==`object`?`style="${Object.keys(r[e]).filter(t=>r[e][t]!=null).map(t=>`${t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}: ${r[e][t]}`).join(`; `)}"`:((e,t)=>t==null||t===``?``:typeof t==`object`?`${e}="${Object.keys(t).map(e=>`${e.replace(/-([a-z])/g,e=>e[1].toUpperCase())}:${t[e]};`).join(` `)}"`:`${e}="${t}"`)(e,r[e])).filter(e=>e&&e.trim().length>0).join(` `);return`<${e.type} ${i}>${n||e.children.map(e=>VO({dom:e})).join(``)}</${e.type}>`};async function HO({json:e,elementHook:t}){return VO({dom:await BO({json:e,elementHook:t})})}var UO=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n},WO=(e,t)=>{if(e.children)for(let n of e.children){if(!0===t(n))break;WO(n,t)}if(e.cells){for(let n of e.cells)if(!0===t(n))break}},$=(e,t,...n)=>({type:e,props:t,children:n||[]});function GO(e,t){if(!jf(e))return null;let{stops:n,rotation:r}=Nf(e),i=r*Math.PI/180,a=.5-.5*Math.sin(i),o=.5+.5*Math.cos(i),s=.5+.5*Math.sin(i),c=.5-.5*Math.cos(i),l=n.map(({offset:e,color:t})=>$(`stop`,{offset:100*e+`%`,"stop-color":t}));return $(`linearGradient`,{id:t,x1:100*a+`%`,y1:100*o+`%`,x2:100*s+`%`,y2:100*c+`%`},...l)}var KO=async e=>{try{let t=await fetch(e);if(typeof Buffer<`u`){let e=await t.arrayBuffer(),n=Buffer.from(e).toString(`base64`);return`data:${t.headers.get(`content-type`)||`image/png`};base64,${n}`}{let e=await t.blob();return new Promise((t,n)=>{let r=new FileReader;r.onloadend=()=>t(r.result),r.onerror=n,r.readAsDataURL(e)})}}catch(t){return console.error(`Error converting URL to data URL:`,t),e}},qO=async({element:e,page:t,store:n})=>{let{src:r}=e;r=e.type===`svg`?Z_(await q_(r),new Map(Object.entries(e.colorsReplace))):await KO(r);let i,a,o,s,c=``;if(e.flipX||e.flipY){let t=e.flipX?-1:1,n=e.flipY?-1:1,r=e.width/2,i=e.height/2;c=`translate(${r}, ${i}) scale(${t}, ${n}) translate(${-r}, ${-i})`}e.clipSrc&&(i=`clip-img-mask-${e.id}`,a=await KO(e.clipSrc)),e.maskSrc&&(o=`mask-img-${e.id}`,s=await KO(e.maskSrc));let l=await EO(r),u=l.width*e.cropWidth,d=l.height*e.cropHeight,f=e.width/e.height,p,m,h=u/d,g=typeof e.stretchEnabled==`boolean`&&e.stretchEnabled||e.type===`svg`;g?(p=u,m=d):f>=h?(p=u,m=u/f):(p=d*f,m=d);let _=p/l.width,v=m/l.height,y=p/m>e.width/e.height?e.height/m:e.width/p,b=g?e.width/p:y,x=g?e.height/m:y,S=p*b/_,C=m*x/v,w=e.cropX*l.width*b,T=e.cropY*l.height*x;e.flipX&&(w=(1-e.cropX-e.cropWidth)*l.width*b),e.flipY&&(T=(1-e.cropY-e.cropHeight)*l.height*x);let E=`clip-${e.id}`,D=e.cornerRadius||0,O=r.replace(/&/g,`&amp;`),k={x:-w,y:-T,width:S,height:C,preserveAspectRatio:`none`,"clip-path":`url(#${E})`},A=[$(`clipPath`,{id:E},$(`rect`,{x:0,y:0,width:e.width,height:e.height,rx:D||void 0,ry:D||void 0}))];i&&a&&A.push($(`mask`,{id:i,maskUnits:`userSpaceOnUse`,"mask-type":`alpha`},$(`image`,{href:a.replace(/&/g,`&amp;`),x:0,y:0,width:e.width,height:e.height,preserveAspectRatio:`none`}))),o&&A.push($(`mask`,{id:o,maskUnits:`userSpaceOnUse`,"mask-type":`alpha`},$(`image`,Object.assign({href:O},k))));let j=O,M={};o&&s&&(j=s.replace(/&/g,`&amp;`),M.mask=`url(#${o})`);let N={};i&&(N.mask=`url(#${i})`);let P=e.borderSize||0,F=P>0&&jf(e.borderColor),ee=F?`border-grad-${e.id}`:null;if(F){let t=GO(e.borderColor,ee);t&&A.push(t)}let te=P>0?$(`rect`,{x:P/2,y:P/2,width:Math.max(0,e.width-P),height:Math.max(0,e.height-P),fill:`none`,stroke:F?`url(#${ee})`:e.borderColor,"stroke-width":P,rx:Math.max(0,D-P)||void 0,ry:Math.max(0,D-P)||void 0}):null,ne=$(`g`,{},$(`defs`,{},...A),$(`image`,Object.assign(Object.assign({href:j},k),M)),te);return $(`g`,N,c?$(`g`,{transform:c},ne):ne)},JO=({element:e,type:t})=>{let n={"stroke-width":e.height,stroke:e.color,"stroke-linecap":`round`,"stroke-linejoin":`round`},r=Object.assign(Object.assign({},n),{fill:e.color}),i=Object.assign(Object.assign({},n),{fill:`none`});return t===`arrow`?$(`polyline`,Object.assign({points:`${3*e.height},${2*-e.height} 0,0 ${3*e.height},${2*e.height}`},i)):t===`triangle`?$(`polygon`,Object.assign({points:`${3*e.height},${2*-e.height} 0,0 ${3*e.height},${2*e.height}`},r)):t===`bar`?$(`polyline`,Object.assign({points:`0,${2*-e.height} 0,${2*e.height}`},i)):t===`circle`?$(`circle`,Object.assign({cx:2*e.height,cy:0,r:2*e.height},r)):t===`square`?$(`polygon`,Object.assign({points:`0,${2*-e.height} ${4*e.height},${2*-e.height} ${4*e.height},${2*e.height} 0,${2*e.height}`},r)):null},YO={image:qO,svg:qO,text:async({element:e,page:t,store:n})=>{let r=jf(e.fill),i=jf(e.stroke);if(e.curveEnabled){let t=Pp(e.width,e.height,e.curvePower,e.fontSize),n=`curve-path-${e.id}`,a=(Qf(e.text).replace(/\n/g,` `),ep(e.text)),o={fontWeight:e.fontWeight||`normal`,fontStyle:e.fontStyle||`normal`,fill:e.fill||`black`},s=Rp(a,o),c=Rp(a,o,{omitColors:!0}),l=e.backgroundPadding*(e.fontSize*e.lineHeight*.5),u=e.backgroundEnabled?$(`rect`,{x:-l,y:-l,width:e.width+2*l,height:e.height+2*l,fill:e.backgroundColor,opacity:e.backgroundOpacity,rx:e.backgroundCornerRadius*(e.fontSize*e.lineHeight*.5),ry:e.backgroundCornerRadius*(e.fontSize*e.lineHeight*.5)}):null,d=[$(`path`,{id:n,d:t,fill:`none`})],f=e.strokeWidth&&(i||r&&!i);if(r){let t=`curve-fill-grad-${e.id}`,n=GO(e.fill,t);n&&d.push(n)}if(i&&e.strokeWidth){let t=`curve-stroke-grad-${e.id}`,n=GO(e.stroke,t);n&&d.push(n)}if(f){let t={"font-size":e.fontSize+`px`,"text-anchor":`middle`,"dominant-baseline":`central`,"font-family":e.fontFamily,"font-style":e.fontStyle,"font-weight":e.fontWeight,"text-decoration":e.textDecoration||void 0,"letter-spacing":e.letterSpacing*e.fontSize+`px`},a=i?`url(#curve-stroke-grad-${e.id})`:e.stroke,o=$(`text`,Object.assign(Object.assign({},t),{fill:a,"stroke-width":e.strokeWidth,stroke:a}),$(`textPath`,{href:`#${n}`,startOffset:`50%`,innerHTML:c})),l=r?`url(#curve-fill-grad-${e.id})`:e.fill,f=$(`text`,Object.assign(Object.assign({},t),{fill:l}),$(`textPath`,{href:`#${n}`,startOffset:`50%`,innerHTML:s}));return $(`g`,{},u,$(`defs`,{},...d),o,f)}return $(`g`,{},u,$(`defs`,{},...d),$(`text`,{fill:r?`url(#curve-fill-grad-${e.id})`:e.fill,"font-size":e.fontSize+`px`,"text-anchor":`middle`,"dominant-baseline":`central`,"font-family":e.fontFamily,"font-style":e.fontStyle,"font-weight":e.fontWeight,"text-decoration":e.textDecoration||void 0,"letter-spacing":e.letterSpacing*e.fontSize+`px`,"stroke-width":e.strokeWidth||void 0,stroke:e.strokeWidth?i?`url(#curve-stroke-grad-${e.id})`:e.stroke:void 0,"paint-order":e.strokeWidth?`stroke fill`:void 0},$(`textPath`,{href:`#${n}`,startOffset:`50%`,innerHTML:s})))}let a=(e,t,n,r,i,a=0)=>{let o=document.createElement(`canvas`).getContext(`2d`);return o.font=`${i} ${r} ${t}px ${n}`,o.measureText(e).width+Math.max(0,(e?e.length:0)-1)*a*t},o=(e,t,n,r,i,o,s=0)=>{let c=[];return e.split(`
288
+ `).forEach(e=>{let l=e.split(` `),u=``;for(let e=0;e<l.length;e++){let d=u+l[e]+` `;a(d,n,r,i,o,s)>t+.5&&e>0?(c.push(u.trim()),u=l[e]+` `):u=d}c.push(u.trim())}),c},s=Qf(e.text);e.textTransform==`uppercase`&&(s=s.toUpperCase());let c=e.fontSize,l=[];for(;;){l=o(s,e.width,c,e.fontFamily,e.fontWeight,e.fontStyle,e.letterSpacing);let t=Math.max(...l.map(t=>a(t,c,e.fontFamily,e.fontWeight,e.fontStyle,e.letterSpacing))),n=l.length*c*e.lineHeight;if(t<=e.width&&n<=e.height||(--c,c<4))break}let u=c*e.lineHeight,d=l.length*u,f=c;e.verticalAlign===`middle`?f=(e.height-d)/2+c:e.verticalAlign===`bottom`&&(f=e.height-d+c);let p=e.align===`center`?`middle`:e.align===`right`?`end`:`start`,m=l.map((t,n)=>$(`tspan`,{x:e.align===`center`?e.width/2:e.align===`right`?e.width:0,dy:n===0?0:u,innerHTML:t})),h=e.backgroundPadding*(c*e.lineHeight*.5),g=e.backgroundEnabled?$(`rect`,{x:-h,y:-h,width:e.width+2*h,height:e.height+2*h,fill:e.backgroundColor,opacity:e.backgroundOpacity,rx:e.backgroundCornerRadius*(c*e.lineHeight*.5),ry:e.backgroundCornerRadius*(c*e.lineHeight*.5)}):null,_=[],v=e.strokeWidth&&(i||r&&!i);if(r){let t=`text-fill-grad-${e.id}`,n=GO(e.fill,t);n&&_.push(n)}if(i&&e.strokeWidth){let t=`text-stroke-grad-${e.id}`,n=GO(e.stroke,t);n&&_.push(n)}if(v){let t={y:f,"font-size":c+`px`,"text-anchor":p,"font-family":e.fontFamily,"font-style":e.fontStyle,"font-weight":e.fontWeight,"text-decoration":e.textDecoration,"line-height":e.lineHeight,"letter-spacing":e.letterSpacing*c+`px`},n=i?`url(#text-stroke-grad-${e.id})`:e.stroke,a=$(`text`,Object.assign(Object.assign({},t),{fill:n,"stroke-width":e.strokeWidth,stroke:n}),...m.map(e=>$(`tspan`,e.props,e.props.innerHTML))),o=r?`url(#text-fill-grad-${e.id})`:e.fill,s=$(`text`,Object.assign(Object.assign({},t),{fill:o}),...m.map(e=>$(`tspan`,e.props,e.props.innerHTML)));return $(`g`,{},g,_.length>0?$(`defs`,{},..._):null,a,s)}return $(`g`,{},g,_.length>0?$(`defs`,{},..._):null,$(`text`,{fill:r?`url(#text-fill-grad-${e.id})`:e.fill,y:f,"font-size":c+`px`,"text-anchor":p,"font-family":e.fontFamily,"font-style":e.fontStyle,"font-weight":e.fontWeight,"text-decoration":e.textDecoration,"line-height":e.lineHeight,"letter-spacing":e.letterSpacing*c+`px`,"stroke-width":e.strokeWidth||void 0,stroke:e.strokeWidth?e.stroke:void 0,"paint-order":e.strokeWidth?`stroke fill`:void 0},...m))},line:async({element:e,page:t,store:n})=>$(`g`,{},$(`line`,{x1:0,y1:e.height/2,x2:e.width,y2:e.height/2,stroke:e.color,"stroke-width":e.height,"stroke-dasharray":e.dash&&e.dash.length?e.dash.map(t=>t*e.height).join(` `):void 0}),$(`g`,{transform:`translate(0 ${e.height/2})`},JO({element:e,type:e.startHead})),$(`g`,{transform:`translate(${e.width} ${e.height/2}) rotate(180)`},JO({element:e,type:e.endHead}))),figure:async({element:e,page:t,store:n,elementHook:r})=>{let i=function(e){let t=e.replace(/<svg[^>]*>/,``);return t=t.replace(/<\/svg>/,``),t}(AD(e)),a=[];if(e.strokeWidth&&jf(e.stroke)){let t=`figure-stroke-grad-${e.id}`,n=GO(e.stroke,t);if(n){a.push(n);let r=e.stroke.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);i=i.replace(RegExp(`stroke="${r}"`,`g`),`stroke="url(#${t})"`)}}if(jf(e.fill)){let t=`figure-fill-grad-${e.id}`,n=GO(e.fill,t);if(n){a.push(n);let r=e.fill.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);i=i.replace(RegExp(`fill="${r}"`,`g`),`fill="url(#${t})"`)}}if(a.length>0){let t=$(`g`,{},$(`defs`,{},...a),$(`g`,{innerHTML:i}));return r&&r({dom:t,element:e})||t}let o=$(`g`,{innerHTML:i});return r&&r({dom:o,element:e})||o},group:async({element:e,page:t,store:n,elementHook:r})=>{let i=await Promise.all(e.children.map(e=>XO({element:e,page:t,store:n,elementHook:r}))),a=$(`g`,{style:{"transform-origin":`top left`}},...i);return r&&r({dom:a,element:e})||a},gif:qO,table:async({element:e})=>{e.rows;let t=e.cols,n=e.colWidths,r=e.rowHeights,i=[`fontSize`,`fontFamily`,`fontWeight`,`fontStyle`,`textDecoration`,`textTransform`,`fill`,`align`,`verticalAlign`,`lineHeight`,`letterSpacing`,`strokeWidth`,`stroke`,`cellBackground`,`cellPadding`],a=(e.cells||[]).map((n,r)=>{let a=Object.assign(Object.assign({},n),{row:Math.floor(r/t),col:r%t});for(let t of i)a[t]===void 0&&(a[t]=e[t]);return a}),o=[],s=(t,i,a,o)=>{let s=0;for(let t=0;t<i;t++)s+=n[t]*e.width;let c=0;for(let n=0;n<t;n++)c+=r[n]*e.height;let l=0;for(let t=i;t<i+o;t++)l+=(n[t]||0)*e.width;let u=0;for(let n=t;n<t+a;n++)u+=(r[n]||0)*e.height;return{x:s,y:c,width:l,height:u}};for(let e of a)if(!e.mergedInto&&e.cellBackground&&e.cellBackground!==`transparent`){s(e.row,e.col,e.colSpan||1,e.colSpan||1);let{x:t,y:n,width:r,height:i}=s(e.row,e.col,e.rowSpan||1,e.colSpan||1);o.push($(`rect`,{x:t,y:n,width:r,height:i,fill:e.cellBackground}))}let c=(e,t)=>e===`dashed`?`${4*t},${2*t}`:e===`dotted`?`${t},${t}`:void 0,l=(t,n)=>{let r=t.borders?.[n];return{width:r?.width??e.borderWidth,style:r?.style??e.borderStyle??`solid`,color:r?.color??e.borderColor}};for(let e of a){if(e.mergedInto)continue;let t=s(e.row,e.col,e.rowSpan||1,e.colSpan||1);if(e.row===0){let n=l(e,`top`);n.style!==`none`&&n.width>0&&o.push($(`line`,{x1:t.x,y1:t.y+n.width/2,x2:t.x+t.width,y2:t.y+n.width/2,stroke:n.color,"stroke-width":n.width,"stroke-dasharray":c(n.style,n.width)}))}if(e.col===0){let n=l(e,`left`);n.style!==`none`&&n.width>0&&o.push($(`line`,{x1:t.x+n.width/2,y1:t.y,x2:t.x+n.width/2,y2:t.y+t.height,stroke:n.color,"stroke-width":n.width,"stroke-dasharray":c(n.style,n.width)}))}{let n=l(e,`bottom`);n.style!==`none`&&n.width>0&&o.push($(`line`,{x1:t.x,y1:t.y+t.height-n.width/2,x2:t.x+t.width,y2:t.y+t.height-n.width/2,stroke:n.color,"stroke-width":n.width,"stroke-dasharray":c(n.style,n.width)}))}{let n=l(e,`right`);n.style!==`none`&&n.width>0&&o.push($(`line`,{x1:t.x+t.width-n.width/2,y1:t.y,x2:t.x+t.width-n.width/2,y2:t.y+t.height,stroke:n.color,"stroke-width":n.width,"stroke-dasharray":c(n.style,n.width)}))}}for(let t of a){if(t.mergedInto)continue;let i=Qf(t.text||``);if(!i)continue;t.textTransform===`uppercase`&&(i=i.toUpperCase());let a=t.cellPadding||4,s=0;for(let r=0;r<t.col;r++)s+=n[r]*e.width;let c=0;for(let n=0;n<t.row;n++)c+=r[n]*e.height;let l=n[t.col]*e.width,u=r[t.row]*e.height,d=t.fontSize||12,f=t.align||`left`,p=s+a,m=`start`;f===`center`?(p=s+l/2,m=`middle`):f===`right`&&(p=s+l-a,m=`end`);let h=c+a+d,g=t.verticalAlign||`top`;g===`middle`?h=c+u/2+d/3:g===`bottom`&&(h=c+u-a),o.push($(`text`,{x:p,y:h,"font-size":d,"font-family":t.fontFamily||`Roboto`,"font-weight":t.fontWeight||`normal`,"font-style":t.fontStyle||`normal`,fill:t.fill||`black`,"text-anchor":m,"text-decoration":t.textDecoration||`none`,"letter-spacing":t.letterSpacing?t.letterSpacing*d+`px`:void 0},i))}return $(`g`,{},...o)}};async function XO({element:e,page:t,store:n,elementHook:r}){var i;let a=await YO[e.type];a||(a=()=>$(`g`,{}),console.error(`SVG export does not support ${e.type} type...`));let o=await a({element:e,page:t,store:n}),s=[],c=[];if(e.blurEnabled&&s.push(`blur(${e.blurRadius/2}px)`),e.brightnessEnabled&&s.push(`brightness(${100*e.brightness+100}%)`),e.sepiaEnabled&&s.push(`sepia()`),e.grayscaleEnabled&&s.push(`grayscale()`),e.shadowEnabled&&s.push(`drop-shadow(${e.shadowOffsetX}px ${e.shadowOffsetY}px ${e.shadowBlur}px ${e.shadowColor})`),e.filters)for(let[t,n]of Object.entries(e.filters)){let e=AO(kO[t],n.intensity);if(e&&(s.push(e.filter),e.html)){let t=e.html.replace(/<svg([^>]*)>/,`<g$1>`).replace(/<\/svg>/,`</g>`);c.push(t)}}let l=$(`g`,{className:`element`,id:e.id,transform:e.type===`group`?void 0:`translate(${e.x}, ${e.y}) rotate(${e.rotation})`,display:(i=e.visible)==null||i?void 0:`none`,opacity:e.opacity,style:{"transform-origin":`top left`,filter:s.join(` `)}},o,...c);return r&&r({dom:l,element:e})||l}async function ZO(e){try{let t=await fetch(e),n=t.headers.get(`content-type`)||`font/ttf`,r=await t.arrayBuffer();return`data:${n};base64,${typeof Buffer<`u`?Buffer.from(r).toString(`base64`):function(e){let t=new Uint8Array(e),n=``;for(let e=0;e<t.length;e+=32768){let r=t.subarray(e,e+32768);n+=String.fromCharCode(...r)}if(typeof btoa<`u`)return btoa(n);if(typeof Buffer<`u`)return Buffer.from(t).toString(`base64`);throw Error(`No base64 encoder available in this environment`)}(r)}`}catch(t){return console.error(`Error embedding font:`,t),e}}async function QO({json:e,elementHook:t,fontEmbedding:n=`inline`}){let r=[];WO({children:e.pages},e=>{e.type!==`text`&&e.type!==`tablecell`&&e.type!==`table`||!e.fontFamily||r.indexOf(e.fontFamily)!==-1||r.push(e.fontFamily)});let i=n===`inline`?await async function(e,t){return await Promise.all(e.map(async e=>{if(e===`Arial`)return null;let n=t.find(t=>t.fontFamily===e);if(n)return $(`style`,{},`@font-face { font-family: ${e}; src: url(${await ZO(n.url)}); }`);{let t=`https://fonts.googleapis.com/css?family=${e}:bi,normal,i,b`;try{let n=await(await fetch(t)).text(),r=(n.match(/url\((.*?)\)/g)?.map(e=>e.replace(/url\((.*?)\)/,`$1`)))?.filter(e=>e.startsWith(`https`));if(!r?.length)throw Error(`No font URLs found`);return $(`style`,{},(await Promise.all(r.map(async t=>{let r=await ZO(t),i=n.match(/font-style:\s*(.*?);/),a=n.match(/font-weight:\s*(.*?);/);return`@font-face {\n font-family: ${e};\n font-style: ${i?i[1]:`normal`};\n font-weight: ${a?a[1]:`normal`};\n src: url(${r});\n }`}))).join(`
289
+ `))}catch(e){return console.error(`Error embedding Google Font:`,e),$(`defs`,{},$(`style`,{type:`text/css`,innerHTML:`@import url('${t}');`.replace(/&/g,`&amp;`)}))}}}))}(r,e.fonts):[],a=await Promise.all(e.pages.map(n=>async function({page:e,store:t,elementHook:n}){let r=await Promise.all(e.children.map(r=>XO({element:r,page:e,store:t,elementHook:n}))),i=e.background.indexOf(`url`)>=0||e.background.indexOf(`http`)>=0||e.background.indexOf(`.jpg`)>=0||e.background.indexOf(`.png`)>=0||e.background.indexOf(`.jpeg`)>=0,a;if(i){let n=await EO(e.background);a=await DO(e.background,Object.assign({width:t.width,height:t.height,x:0,y:0},OO({width:t.width,height:t.height},{width:n.width,height:n.height})))}return $(`g`,{className:`page`,style:{}},i?$(`image`,{"xlink:href":a,x:0,y:0,width:t.width,height:t.height,preserveAspectRatio:`none`}):$(`rect`,{x:0,y:0,width:t.width,height:t.height,fill:i?void 0:e.background}),...r)}({page:n,store:e,elementHook:t})));return $(`svg`,{xmlns:`http://www.w3.org/2000/svg`,"xmlns:xlink":`http://www.w3.org/1999/xlink`,viewBox:`0 0 ${e.width} ${e.height}`,width:e.width,height:e.height},...i,...a)}var $O=({dom:e,nestLevel:t=0})=>{if(typeof e==`string`)return e;if(!e)return``;let n=e.props,{innerHTML:r}=n,i=UO(n,[`innerHTML`]),a=Object.keys(i).map(e=>((e,t)=>typeof t==`object`?`${e}="${Object.keys(t).map(e=>`${e}:${t[e]};`).join(` `)}"`:t==null||t===``?``:`${e}="${t}"`)(e,i[e])).filter(e=>e&&e.trim().length>0).join(` `),o=` `.repeat(t);return`${o}<${e.type}${a?` `+a:``}>${r||`
290
+ `+e.children.map(e=>$O({dom:e,nestLevel:t+1})).join(``)}${o}</${e.type}>\n`};async function ek({json:e,elementHook:t,fontEmbedding:n=`inline`}){return $O({dom:await QO({json:e,elementHook:t,fontEmbedding:n})})}var tk=q.model(`Page`,{id:q.identifier,children:q.array(q.late(()=>Kk)),width:q.optional(q.union(q.number,q.literal(`auto`)),`auto`),height:q.optional(q.union(q.number,q.literal(`auto`)),`auto`),background:`white`,bleed:0,custom:q.frozen(),duration:5e3,_exporting:!1,_rendering:!1,_forceMount:!1}).postProcessSnapshot(e=>{let t=Object.assign({},e),n={};for(var r in t)r[0]!==`_`&&(n[r]=e[r]);return n}).views(e=>({get store(){return cm(e,ak)}})).views(e=>({get startTime(){let t=0;for(let n of e.store.pages){if(n.id===e.id)return t;t+=n.duration}return t},get _exportingOrRendering(){return e._exporting||e._rendering}})).views(e=>({get computedWidth(){return e.width===`auto`?e.store.width:e.width},get computedHeight(){return e.height===`auto`?e.store.height:e.height}})).actions(e=>({toJSON:()=>JSON.parse(JSON.stringify(am(e))),_forEachElementUp(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));r.sort((e,t)=>t.index-e.index);for(let{index:i}of r){if(i==-1)continue;let r=i<e.children.length-1&&e.children[i+1],a=t.indexOf(r?.id)>=0;i===e.children.length-1||a||n(i)}},_forEachElementDown(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));r.sort((e,t)=>e.index-t.index);for(let{index:i}of r){if(i==-1)continue;let r=i>0&&e.children[i-1],a=t.indexOf(r?.id)>=0;i===0||a||n(i)}return!1}})).actions(e=>{let t={clone(t={}){let n=e.toJSON(),r=new Map;n.children.forEach(e=>{let t=e.id,n=KD(10);r.set(t,n),e.id=n,Wk(e,e=>{let t=e.id,n=KD(10);r.set(t,n),e.id=n})}),n.children.forEach(e=>{e.cells&&e.cells.forEach(e=>{e.mergedInto&&r.has(e.mergedInto)&&(e.mergedInto=r.get(e.mergedInto))})});let i=Object.assign(Object.assign(Object.assign({},n),{id:KD(10)}),t),a=e.store.addPage(i),o=e.store.pages.indexOf(e);return a.setZIndex(o+1),a.select(),a},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t,{skipSelect:n=!1}={}){let r=Yk[t.type];if(!r){console.error(`Can not find model with type `+t.type);return}`children`in t&&Array.isArray(t.children)&&Wk(t,e=>{e.id=e.id||KD(10)});let i=e.children.reduce((e,n)=>{if(n.type===`group`){let r=n.children.reduce((e,n)=>{let r=n.name?.match(RegExp(`${t.type}-(\\d+)`));if(r){let t=parseInt(r[1],10);return Math.max(e,t||0)}},0);return Math.max(e,r||0)}{let r=n.name.match(RegExp(`${t.type}-(\\d+)`));if(r){let t=parseInt(r[1],10);return Math.max(e,t||0)}}return e},0),a=r.create(Object.assign({id:KD(10),name:`${t.type}-${i+1}`},t));return e.children.push(a),a.selectable&&!n&&e.store.selectElements([a.id]),a},canMoveElementsUp(t){let n=!1;return e._forEachElementUp(t,()=>{n||=!0}),n},moveElementsUp(t){e._forEachElementUp(t,t=>{let n=e.children[t];pm(n),e.children.splice(t+1,0,n)})},canMoveElementsTop:e=>t.canMoveElementsUp(e),moveElementsTop(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(r.concat(n))},canMoveElementsDown(t){let n=!1;return e._forEachElementDown(t,()=>{n||=!0}),n},moveElementsDown(t){e._forEachElementDown(t,t=>{let n=e.children[t];pm(n),e.children.splice(t-1,0,n)})},canMoveElementsBottom:e=>t.canMoveElementsDown(e),moveElementsBottom(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(n.concat(r))},setElementZIndex(t,n){let r=e.children.find(e=>e.id===t);r&&(pm(r),e.children.remove(r),e.children.splice(n,0,r))},setSize({width:t,height:n,useMagic:r,softChange:i}){if(r){let r=[],i=t=>t.type===`image`&&t.x<1&&t.y<1&&t.width>=e.computedWidth-2&&t.height>=e.computedHeight-2;Uk(e,e=>{e.type!==`group`&&(i(e)||r.push(e))});let a=r.length?lb(r):{x:0,y:0,width:e.computedWidth,height:e.computedHeight},o=1/4,s=Math.max(0,Math.min(a.x,e.computedWidth-a.x-a.width)),c=e.computedWidth*o,l=Math.max(0,s-c),u=Math.max(0,Math.min(a.y,e.computedHeight-a.y-a.height)),d=e.computedHeight*o,f=Math.max(0,u-d),p=e.computedWidth-2*l,m=e.computedHeight-2*f,h=t/p,g=n/m,_=Math.min(h,g),v=(t-p*_)/2-l*_,y=(n-m*_)/2-f*_;Uk(e,e=>{if(e.type!==`group`){if(i(e))e.set({x:e.x*_,y:e.y*_,width:e.width*h,height:e.height*g,cropX:0,cropY:0,cropWidth:1,cropHeight:1});else if(e.set({x:v+e.x*_,y:y+e.y*_,width:e.width*_,height:e.height*_}),e.type===`text`)e.set({fontSize:e.fontSize*_});else if(e.type===`figure`)e.set({strokeWidth:e.strokeWidth*_});else if(e.type===`table`){e.set({borderWidth:e.borderWidth*_});for(let t of e.cells){let e={fontSize:t.fontSize*_,cellPadding:t.cellPadding*_};if(t.borders){let n=JSON.parse(JSON.stringify(t.borders));for(let e of[`top`,`right`,`bottom`,`left`])n[e]?.width!=null&&(n[e]=Object.assign(Object.assign({},n[e]),{width:n[e].width*_}));e.borders=n}t.set(e)}}}})}i||(e.width=t),i||(e.height=n)}};return t}).actions(e=>({moveElementUp(t){console.warn(`page.moveElementUp(id) is deprecated. Please use page.moveElementsUp([id1, id2]) instead.`),e.moveElementsUp([t])},moveElementDown(t){console.warn(`page.moveElementDown(id) is deprecated. Please use page.moveElementsDown([id1, id2]) instead.`),e.moveElementsDown([t])},moveElementTop(t){console.warn(`page.moveElementTop(id) is deprecated. Please use page.moveElementsTop([id1, id2]) instead.`),e.moveElementsTop([t])},moveElementBottom(t){console.warn(`page.moveElementBottom(id) is deprecated. Please use page.moveElementsBottom([id1, id2]) instead.`),e.moveElementsBottom([t])},play(){e.store.play({startTime:e.startTime,endTime:e.startTime+e.duration})}})),nk=q.model(`Audio`,{id:q.identifier,src:``,duration:0,startTime:0,endTime:1,volume:1,delay:0,custom:q.frozen()}).actions(e=>({toJSON:()=>Object.assign({},am(e))})).actions(e=>({set(t){Object.assign(e,t)}})),rk=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n};Gp(`ignore`);var ik=q.model(`Font`,{fontFamily:q.string,url:q.optional(q.string,``),styles:q.frozen()}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name})),ak=q.model(`Store`,{role:``,pages:q.array(tk),fonts:q.array(ik),audios:q.array(nk),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:q.optional(q.enumeration(`UnitType`,[`pt`,`mm`,`cm`,`in`,`px`]),`px`),dpi:72,schemaVersion:2,bleedVisible:!1,rulesVisible:!1,distanceGuidesVisible:!1,openedSidePanel:``,previousOpenedSidePanel:``,custom:q.frozen(),tool:q.optional(q.enumeration(`Tool`,[`selection`,`draw`,`pan`,`text`,`eraser`]),`selection`),toolOptions:q.optional(q.model({brushType:q.optional(q.enumeration(`BrushType`,[`brush`,`highlighter`]),`brush`),strokeWidth:q.optional(q.number,5),stroke:q.optional(q.string,`#000000`),opacity:q.optional(q.number,1)}),{}),selectedElementsIds:q.array(q.string),animatedElementsIds:q.array(q.string),history:q.optional(JD,{targetPath:`../pages`}),_elementsPixelRatio:Math.min(2,typeof window<`u`&&window.devicePixelRatio||1),_activePageId:``,_selectedPagesIds:q.array(q.string),_forceShowCredit:!1,_key:``,_validated:!1}).views(e=>{let t=jt(()=>{let t={};return Wk({children:e.pages},e=>(t[e.id]=e,!1)),t},{keepAlive:!0});return{get _idsMap(){return t.get()}}}).views(e=>({get _bleedVisible(){return console.warn(`store._bleedVisible is deprecated. Please use store.bleedVisible instead.`),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map(t=>{for(let n of e.pages)for(let e of n.children)if(e.id===t)return e}).filter(e=>!!e)},get children(){return e.pages},get selectedShapes(){let e=[];return Uk({children:this.selectedElements},t=>{t.type!==`group`&&e.push(t)}),e},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)},get selectedPages(){return e._selectedPagesIds.map(t=>e.pages.find(e=>e.id===t))},get duration(){let t=0;return e.pages.forEach(e=>{t+=e.duration}),t},get _hasCroppedImages(){return this.find(e=>e.type===`image`&&e._cropModeEnabled)},find(t){let n;return Wk({children:e.pages},e=>{if(!n&&t(e))return n=e,!0}),n},getElementById:t=>e._idsMap[t]})).actions(e=>{let t=0,n=null,r=!1,i={afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},_togglePlaying(t=!e.isPlaying){e.isPlaying=t},play({animatedElementsIds:a=[],startTime:o=0,currentTime:s=0,endTime:c=e.duration,repeat:l=!1}={}){s&&(console.warn(`currentTime property of store.play() is deprecated. Please use startTime instead.`),o=s),e.animatedElementsIds=gm(a),e.currentTime=o,e.isPlaying=!0,t=Date.now(),n=c,r=l,requestAnimationFrame(()=>i.seek())},checkActivePage(){let t=0;for(let n of e.pages){if(e.currentTime>=n.startTime&&e.currentTime<n.startTime+n.duration){i.selectPage(n.id);break}t+=n.duration}},seek(){if(!e.isPlaying)return;let a=Date.now(),o=a-t;t=a,e.currentTime+=o,i.checkActivePage();let s=n||e.duration;e.isPlaying&&e.currentTime<s?requestAnimationFrame(()=>i.seek()):e.isPlaying&&r?(e.currentTime=0,requestAnimationFrame(()=>i.seek())):i.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=gm([]),i.checkActivePage()},__(){e._validated||=(hO(e._key,e._forceShowCredit),!0)},set(t){Object.assign(e,t)},setUnit({unit:t,dpi:n}){e.unit=t||e.unit,e.dpi=n||e.dpi},setRole(t){e.role=t},setTool(t){e.tool=t},setToolOptions(t){Object.assign(e.toolOptions,t)},addPage(t){let n=tk.create(Object.assign({id:KD(10)},t));return e.pages.push(n),e._activePageId=n.id,n},selectPage(t){e._activePageId=t,e._selectedPagesIds.length===1&&(e._selectedPagesIds=gm([t]))},selectPages(t){e._selectedPagesIds=gm(t),e._selectedPagesIds.length===1&&(e._activePageId=e._selectedPagesIds[0])},selectElements(t){e.selectedElementsIds=gm(t.map(t=>e.getElementById(t)).sort((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t)).filter(e=>!!e).map(e=>e.id))},toggleBleed(t){e.bleedVisible=t??!e.bleedVisible},toggleRulers(t){e.rulesVisible=t??!e.rulesVisible},toggleDistanceGuides(t){e.distanceGuidesVisible=t??!e.distanceGuidesVisible},openSidePanel(t){e.openedSidePanel!==t&&(e.previousOpenedSidePanel=e.openedSidePanel,e.openedSidePanel=t)},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,n,r){e.pages.forEach(e=>{e.setSize({width:t,height:n,useMagic:r,softChange:!0})}),e.width=t,e.height=n},setPageZIndex(t,n){let r=e.pages.find(e=>e.id===t);r&&(pm(r),e.pages.remove(r),e.pages.splice(n,0,r))},deletePages(t){let n=e.pages.indexOf(e.activePage);t.forEach(t=>{mm(e.pages.find(e=>e.id===t))});let r=Math.min(e.pages.length-1,n),i=e.pages[r];i&&(e._activePageId=i.id),e.selectedElementsIds=gm(e.selectedElementsIds.filter(t=>e.getElementById(t)))},groupElements(t,n={}){let r=t.map(t=>e.getElementById(t)),i=r[0].page;if(r.forEach(e=>{e&&pm(e)}),!r.length)return;let a=i.children.reduce((e,t)=>{if(t.type===`group`){let n=t.name.match(/group-(\d+)/);if(n){let t=parseInt(n[1],10);return Math.max(e,t)}}return e},0),o=Object.assign({id:KD(10),name:`group-${a+1}`,children:r,type:`group`},n);return i.children.push(o),e.selectedElementsIds=gm([o.id]),i.children.find(e=>e.id===o.id)},ungroupElements(t){let n=t.map(t=>e.getElementById(t)),r=[];n.forEach(e=>{if(e&&e.type===`group`){let t=e.page,n=t.children.indexOf(e);e.children.forEach(e=>{r.push(e.id)}),e.children.forEach(e=>{pm(e),t.children.push(e)}),t.children.splice(n,1)}}),e.selectedElementsIds=gm(r)},deleteElements(t){let n=[];e.find(e=>(t.includes(e.id)&&n.push(e),!1)),n.forEach(e=>{mm(e)}),e.selectedElementsIds=gm(e.selectedElementsIds.filter(t=>e.getElementById(t)))},on(t,n){if(t===`change`){let t=i.toJSON();return nm(e,e=>{let r=i.toJSON();!qD(t,r)&&(t=r,n(r))})}},async _toCanvas({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:a,includeBleed:o,_skipTimeout:s,quickMode:c=!1,_exportCanvases:l}={}){let u=t||1;r||=e.pages[0]?.id;let d=e.pages.find(e=>e.id===r);if(!d)throw Error(`No page for export with id ${r}`);let f=e._elementsPixelRatio;u>e._elementsPixelRatio&&i.setElementsPixelRatio(u),c?d?.set({_forceMount:!0}):d?.set({_exporting:!0});let p=await TO(()=>{let e=Du.stages.filter(e=>e.getAttr(`pageId`)===r);return e.length===0?null:e});if(!p)throw d?.set({_forceMount:!1,_exporting:!1}),i.setElementsPixelRatio(f),Error(`Export is failed. Can not find stage for page ${r}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);p.length>1&&console.error(`Polotno error: Detected several canvas elements for page "${r}" in the document. This is not supported and will lead to incorrect export. Make sure to use unique ids for all pages and make sure you unmount <Workspace /> when it is not needed.`);let m=p[0];await i.waitLoading({_skipTimeout:s});let h=m.findOne(`.page-container`);if(!h)throw i.setElementsPixelRatio(f),d?.set({_forceMount:!1,_exporting:!1}),Error(`Export is failed. Canvas was unmounted.`);let g=m.position();m.position({x:0,y:0}),m.find(`Transformer`).forEach(e=>{e.setAttr(`oldVisible`,e.visible()),e.visible(!1)}),h.find(`.page-background`).forEach(e=>e.shadowEnabled(!1)),h.find(`.page-background`).forEach(e=>e.strokeEnabled(!1)),h.find(`.highlighter`).forEach(e=>e.visible(!1));let _=h.findOne(`.page-background-group`),v=_.clip();_.clip({x:null,y:null,width:null,height:null});let y=h.findOne(`.elements-container`),b=y.clip();y.clip({x:null,y:null,width:null,height:null});let x=h.find(e=>!e.visible()&&e.getAttr(`editModeEnabled`)&&!e.getAttr(`hideInExport`));x.forEach(e=>{e.setAttr(`oldVisible`,e.visible()),e.show()});let S=h.find(e=>e.getAttr(`hideInExport`));S.forEach(e=>{e.setAttr(`oldVisible`,e.visible()),e.hide()}),n&&h.find(`.page-background`).forEach(e=>e.hide());let C=o?d.bleed:0,w=C;!e.bleedVisible&&o||(e.bleedVisible||o?e.bleedVisible&&o?w=0:e.bleedVisible&&!o&&(w=-d.bleed):w=0);let T=d.computedWidth+2*C,E=d.computedHeight+2*C,D=h.scale();h.scale({x:1,y:1});let O=$_(h,{x:h.x()-w,y:h.y()-w,width:T,height:E,pixelRatio:u,sceneCanvas:l?.sceneCanvas,bufferCanvas:l?.bufferCanvas});h.scale(D);let k=O._canvas;if(a===`image/jpeg`){let e=k.getContext(`2d`);e.save(),e.globalCompositeOperation=`destination-over`,e.fillStyle=`white`,e.fillRect(0,0,k.width,k.height),e.restore()}return n&&h.find(`.page-background`).forEach(e=>e.show()),S.forEach(e=>{e.visible(e.getAttr(`oldVisible`))}),x.forEach(e=>{e.visible(e.getAttr(`oldVisible`))}),h.find(`.page-background`).forEach(e=>e.shadowEnabled(!0)),h.find(`.page-background`).forEach(e=>e.strokeEnabled(!0)),m.find(`Transformer`).forEach(e=>{e.visible(e.getAttr(`oldVisible`))}),h.find(`.highlighter`).forEach(e=>e.visible(!0)),_.clip(v),y.clip(b),m.position(g),d?.set({_exporting:!1,_forceMount:!1}),await Promise.resolve(),i.setElementsPixelRatio(f),k},async toDataURL(t={}){var{mimeType:n,quality:r,dpi:a,dpiMetadata:o=`auto`}=t,s=rk(t,[`mimeType`,`quality`,`dpi`,`dpiMetadata`]);let c=await i._toCanvas(Object.assign({mimeType:n},s)),l=n||`image/png`,u=c.toDataURL(l,r);Du.Util.releaseCanvas(c);let d=a??e.dpi;return l!==`image/png`&&l!==`image/jpeg`||o===`never`||o===`auto`&&d===72?u:bO(u,l,d)},async toBlob(e={}){var{mimeType:t,quality:n}=e,r=rk(e,[`mimeType`,`quality`]);let a=await i._toCanvas(Object.assign({mimeType:t},r)),o=await new Promise(e=>{a.toBlob(e,t,n)});return Du.Util.releaseCanvas(a),o},async saveAsImage(e={}){var{fileName:t}=e,n=rk(e,[`fileName`]);let r=(n.mimeType||`image/png`).split(`/`)[1];YD(await i.toDataURL(n),t||`polotno.`+r)},async _toPDF(t){let n=t.dpi||e.dpi,r=t.parallel||1,a=t.unit||(e.unit===`px`?`mm`:e.unit),o=t.pixelRatio||1,s=t.pageIds||e.pages.map(e=>e.id),c=e.pages.filter(e=>s.includes(e.id)),l=await ZD(),u=e=>xO({px:e,unit:a,dpi:n}),d=t.cropMarkSize||0,f=u(d),p=c[0]||{},m=t.includeBleed?p.bleed:0,h=u(p.computedWidth+2*m+2*f),g=u(p.computedHeight+2*m+2*f);var _=new l({unit:a,orientation:h>g?`landscape`:`portrait`,format:[h,g],compress:!0,putOnlyUsedFonts:!0});_.deletePage(1);let v=((e,t)=>{let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n})(c,r),y=0;for(let e of v){let n=e.map(async e=>{let n=t.includeBleed?e.bleed:0,r=e.computedWidth+2*n+2*d,a=e.computedHeight+2*n+2*d,c=u(r),l=u(a),f=0,p=o;for(;f<10;){f+=1;let n=await i.toDataURL(Object.assign(Object.assign({},t),{pageId:e.id,pixelRatio:p,dpiMetadata:`never`}));if(n.length>20)return p!==o&&console.error(`Polotno can not export PDF with current settings. Quality is automatically reduced. pixelRatio was reduced to ${parseFloat(p.toFixed(3))}.`),t.onProgress&&t.onProgress(++y/s.length*.9),{url:n,width:c,height:l,widthPx:r,heightPx:a};p*=.8}});(await Promise.all(n)).filter(e=>e!==void 0).forEach(({url:e,width:t,height:n,widthPx:r,heightPx:i})=>{_.addPage([t,n],t>n?`landscape`:`portrait`);let o=_.getCurrentPageInfo();var s;switch(a){case`pt`:s=1;break;case`mm`:s=72/25.4;break;case`cm`:s=72/2.54;break;case`in`:s=72;break;case`px`:s=.75;break;default:throw`Invalid unit: `+a}if(o.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*s,topRightY:n*s},o.pageContext.artBox={bottomLeftX:u(d+m)*s,bottomLeftY:u(d+m)*s,topRightX:u(r-d-m)*s,topRightY:u(i-d-m)*s},o.pageContext.bleedBox={bottomLeftX:u(d+m)*s,bottomLeftY:u(d+m)*s,topRightX:u(r-d-m)*s,topRightY:u(i-d-m)*s},f){_.setLineWidth(u(1));let e=f+u(m);_.line(e,0,e,f),_.line(0,e,f,e),_.line(t-e,0,t-e,f),_.line(t,e,t-f,e),_.line(0,n-e,f,n-e),_.line(e,n,e,n-f),_.line(t,n-e,t-f,n-e),_.line(t-e,n,t-e,n-f)}_.addImage(e,f,f,t-2*f,n-2*f,void 0,`FAST`)})}return _},toPDFDataURL:async e=>(await i._toPDF(Object.assign({mimeType:`image/jpeg`},e))).output(`datauristring`),async toGIFDataURL(t={}){let n=t.pixelRatio||1,r=await $D({width:e.width*n,height:e.height*n}),a=1e3/(t.fps||10),o=e.duration/a;for(let t=0;t<o-1;t++){let o=t*a||1;i.setCurrentTime(o);let s=0,c=``;for(let t of e.pages)if(s+=t.duration,t.set({_rendering:s>o}),s>o){c=t.id;break}let l=await i._toCanvas({pixelRatio:n,pageId:c,_skipTimeout:!0});r.addFrame(l.getContext(`2d`),{delay:a,copy:!0})}for(let t of e.pages)t.set({_rendering:!1});return i.stop(),r.render(),new Promise(e=>{r.on(`finished`,function(t){(function(e,t){var n=new FileReader;n.onload=function(e){t(e.target.result)},n.readAsDataURL(e)})(t,e)})})},async saveAsGIF(e={}){var{fileName:t}=e,n=rk(e,[`fileName`]);YD(await i.toGIFDataURL(n),t||`polotno.gif`)},async toHTML({elementHook:e}={}){return HO({json:i.toJSON(),elementHook:e})},async saveAsHTML({fileName:e,elementHook:t}={}){let n=await i.toHTML({elementHook:t});YD(`data:text/html;base64,`+window.btoa(unescape(encodeURIComponent(n))),e||`polotno.html`)},async toSVG({elementHook:e,pageId:t,fontEmbedding:n=`inline`}={fontEmbedding:`inline`}){let r=i.toJSON();t||=r.pages[0]?.id;let a=r.pages.find(e=>e.id===t);return ek({json:Object.assign(Object.assign({},r),{pages:a?[a]:[]}),elementHook:e,fontEmbedding:n})},async saveAsSVG({fileName:e,elementHook:t,pageId:n,fontEmbedding:r=`inline`}={}){let a=await i.toSVG({elementHook:t,pageId:n,fontEmbedding:r});YD(`data:text/svg;base64,`+window.btoa(unescape(encodeURIComponent(a))),e||`polotno.svg`)},async saveAsPDF(e={}){var{fileName:t}=e,n=rk(e,[`fileName`]);(await i._toPDF(Object.assign({mimeType:`image/jpeg`},n))).save(t||`polotno.pdf`)},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise(e=>setTimeout(e,50)),await Jf()},toJSON:()=>({width:e.width,height:e.height,fonts:am(e.fonts),pages:am(e.pages),audios:am(e.audios),unit:e.unit,dpi:e.dpi,custom:e.custom,schemaVersion:e.schemaVersion}),loadJSON(t,n=!1){let r=JSON.parse(JSON.stringify(t)),i=r.schemaVersion||0;i<1&&Sp.htmlRenderEnabled&&Wk({children:r.pages},e=>{e.type===`text`&&(e.letterSpacing=e.letterSpacing*16/e.fontSize)}),i<2&&Wk({children:r.pages},e=>{e.filters&&Object.keys(e.filters).forEach(t=>{if([`warm`,`cold`,`natural`].includes(t))return;let n=e.filters[t];n&&typeof n.intensity==`number`&&(n.intensity/=100)})}),delete r.schemaVersion;let a=e.activePage?e.pages.indexOf(e.activePage):0;r._activePageId=(r.pages[a]||r.pages[0])?.id;let o=Object.assign({},am(e));Object.assign(o,r),o.history=n?am(e.history):{history:[],undoIdx:-1,targetPath:``},im(e,o)},clear({keepHistory:t=!1}={}){let n=e.pages.map(e=>e.id);i.deletePages(n),e.custom=null,t||e.history.clear()},addFont(t){i.removeFont(t.fontFamily),e.fonts.push(t)},removeFont(t){e.fonts.filter(e=>e.fontFamily===t).forEach(e=>mm(e))},addAudio(t){let n=nk.create(Object.assign({id:KD(10)},t));e.audios.push(n)},removeAudio(t){let n=e.audios.find(e=>e.id===t);n&&e.audios.remove(n)},async loadFont(t,n,r,i){let a=e.fonts.find(e=>e.fontFamily===t)||np.find(e=>e.fontFamily===t),o=[{fontStyle:`normal`,fontWeight:`normal`},{fontStyle:`normal`,fontWeight:`bold`}];return a?(a.styles&&(o=a.styles.map(e=>({fontStyle:e.fontStyle||`normal`,fontWeight:e.fontWeight||`normal`}))),xp(a)):vp(t),n&&r&&!o.some(e=>e.fontStyle===n&&e.fontWeight===r)&&o.push({fontStyle:n,fontWeight:r}),Promise.all(o.map(e=>pp(t,e.fontStyle,e.fontWeight,i)))},validate:e=>ak.validate(e,[{path:``,type:ak}]).map(e=>({path:`store`+e.context.map(e=>e.path).join(`.`),message:e.message}))};return i});function ok({key:e,showCredit:t}={key:``,showCredit:!1}){return ak.create({_forceShowCredit:t,_key:e})}var sk=q.model(`Node`,{id:q.identifier,type:`none`,name:``,opacity:1,custom:q.frozen(),visible:!0,selectable:!0,removable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot(e=>{for(var t in e)e[t]===null&&(e[t]=void 0);return e}).postProcessSnapshot(e=>{let t=Object.assign({},e),n={};for(var r in t)r[0]!==`_`&&(n[r]=e[r]);return n}).views(e=>({get page(){return cm(e,tk)},get store(){return cm(e,ak)},get top(){let t=e;for(;;){if(!sm(t,qk))return t;t=cm(t,qk)}},get parent(){if(sm(e,qk)){let t=cm(e,qk);return t&&t.children&&t.children.length,t}if(sm(e,tk)){let t=cm(e,tk);return t&&t.children&&t.children.length,t}if(sm(e,ak)){let t=cm(e,ak);return t&&t.pages&&t.pages.length,t}return null},get zIndex(){return e.parent.children.indexOf(e)}})).actions(e=>({toJSON:()=>Object.assign({},am(e))})).actions(e=>({clone(t={},{skipSelect:n=!1}={}){let r=JSON.parse(JSON.stringify(e.toJSON()));t.id=t.id||KD(10);let i=new Map;return Wk(r,e=>{let t=e.id,n=KD(10);i.set(t,n),e.id=n}),Wk(r,e=>{e.mergedInto&&i.has(e.mergedInto)&&(e.mergedInto=i.get(e.mergedInto))}),Object.assign(r,t),e.page.addElement(r,{skipSelect:n})},set(t){Object.assign(e,t)},moveUp(){e.page.moveElementsUp([e.id])},moveTop(){e.page.moveElementsTop([e.id])},moveDown(){e.page.moveElementsDown([e.id])},moveBottom(){e.page.moveElementsBottom([e.id])},setZIndex(t){e.parent.setElementZIndex(e.id,t)},beforeDestroy(){}})),ck={right:{from:{x:-200},to:{x:0}},left:{from:{x:200},to:{x:0}},up:{from:{y:200},to:{y:0}},down:{from:{y:-200},to:{y:0}},"bottom-right":{from:{x:-200,y:-200},to:{x:0,y:0}},"bottom-left":{from:{x:200,y:-200},to:{x:0,y:0}},"top-right":{from:{x:-200,y:200},to:{x:0,y:0}},"top-left":{from:{x:200,y:200},to:{x:0,y:0}}},lk={right:{cropX:-1},left:{cropX:1},up:{cropY:1},down:{cropY:-1}},uk={none:()=>({}),fade:({dTime:e,element:t,animation:n})=>{let r=e/n.duration;return n.type===`enter`?{opacity:r*t.opacity}:{opacity:(1-r)*t.opacity}},rotate:({dTime:e,element:t,animation:n})=>{let r=e/n.duration*360;return fb({x:t.x,y:t.y,width:t.width,height:t.height,rotation:t.rotation},r)},blink:({dTime:e,element:t,animation:n})=>{let r=n.duration,i=e%r/(r/2),a=i<=1?i:2-i;return{opacity:t.opacity*a}},bounce:({dTime:e,element:t,animation:n})=>{let r=n.duration,i=r/2,a=n.data.strength??1,o={},s={x:t.x+t.width/3*a,y:t.y+t.height/3*a,width:t.width/3*a,height:t.height/3*a,fontSize:t.fontSize/3*a},c={x:t.x,y:t.y,width:t.width,height:t.height,fontSize:t.fontSize},l=e%r/i,u=l<=1?l:2-l;for(let e in s){let t=s[e];o[e]=t+u*(c[e]-t)}return o},move:({dTime:e,element:t,animation:n})=>{let r=ck[n.data.direction]||ck.right,i=n.data.strength??1,a={};for(var o in r.from){let s=r.from[o],c=r.to[o];n.type===`exit`&&(s=r.to[o],c=-r.from[o]),s*=i,c*=i;let l=t[o]+s,u=t[o]+c-l;a[o]=l+e/n.duration*u}return a},zoom:({dTime:e,element:t,animation:n})=>{let r={},i=1+(((n.data.direction||`in`)===`in`?3/4:5/4)-1)*(n.data.strength??1),a=t.rotation*Math.PI/180,o=Math.cos(a),s=Math.sin(a),c=t.width*(1-i),l=t.height*(1-i),u=(c*o-l*s)/2,d=(c*s+l*o)/2,f={x:t.x+u,y:t.y+d,width:t.width*i,height:t.height*i,fontSize:t.fontSize*i},p={x:t.x,y:t.y,width:t.width,height:t.height,fontSize:t.fontSize};for(var m in f){let t=f[m],i=p[m];if(n.type===`exit`){let e=t;t=i,i=e}let a=i-t;r[m]=t+e/n.duration*a}return r},cameraZoom:({dTime:e,element:t,animation:n})=>{let r={},i=lk[n.data.direction||`right`]||lk.right,a=n.data.movementStrength??.1,o=n.data.shakeStrength??.015,s=n.data.zoomStrength??.6,c=e/n.duration,l=o*(1-c),u=Math.sin(12*c)*l*.7+Math.sin(8*c)*l*.3;if(n.type===`exit`){let e=Math.max(t.cropWidth||1,t.cropHeight||1);s=Math.min(s,1-e)}n.type;let d=1-(1-c)**2,f=t.cropX||0,p=t.cropY||0,m=t.cropWidth||1,h=t.cropHeight||1,g=m,_=h,v,y,b=0,x=0;if(i.cropX){let e=i.cropX>0?1-(f+m):f;b=Math.min(e,Math.abs(a))*i.cropX}if(i.cropY){let e=i.cropY>0?1-(p+h):p;x=Math.min(e,Math.abs(a))*i.cropY}return n.type===`enter`?(v=i.cropX?f+b*(1-d):f,y=i.cropY?p+x*(1-d):p):(v=i.cropX?f+b*d:f,y=i.cropY?p+x*d:p),r.cropX=Math.max(0,Math.min(1-g,v+u*g)),r.cropY=Math.max(0,Math.min(1-_,y+u*_)),r.cropWidth=g,r.cropHeight=_,r}},dk=({element:e,dTime:t,animation:n})=>{let r=uk[n.name];return r?r({element:e,dTime:t,animation:n}):(console.error(`Can not find animation type: `+n.name),{})},fk=q.model(`Animation`,{delay:0,duration:500,enabled:!0,type:q.enumeration(`Type`,[`enter`,`exit`,`loop`]),name:`none`,data:q.frozen({})}),pk=(e,t)=>{let n={};for(let r in t)if(typeof e[r]==`number`&&typeof t[r]==`number`){let i=t[r]-e[r];i!==0&&(n[r]=i)}return n},mk=q.model(`ShapeFilter`,{intensity:1}),hk=[`temperature`,`contrast`,`highlights`,`shadows`,`white`,`black`,`saturation`,`vibrance`],gk=sk.named(`Shape`).props({x:0,y:0,width:100,height:100,rotation:0,opacity:1,animations:q.array(fk),blurEnabled:!1,blurRadius:10,brightnessEnabled:!1,brightness:0,sepiaEnabled:!1,grayscaleEnabled:!1,filters:q.map(mk),shadowEnabled:!1,shadowBlur:5,shadowOffsetX:0,shadowOffsetY:0,shadowColor:`black`,shadowOpacity:1,visible:!0,draggable:!0,resizable:!0,selectable:!0,contentEditable:!0,styleEditable:!0,alwaysOnTop:!1,showInExport:!0}).preProcessSnapshot(e=>{let t=Object.assign(Object.assign({},e),{x:`x`in e&&e.x||0,y:`y`in e&&e.y||0,filters:`filters`in e?Array.isArray(e.filters)?{}:e.filters:void 0});return`width`in e&&(t.width=t.width||1),`height`in e&&(t.height=t.height||1),`locked`in e&&e.locked&&(t.draggable=!1,t.contentEditable=!1,t.styleEditable=!1,t.resizable=!1,t.removable=!1),t}).views(e=>{let t=[`x`,`y`,`width`,`height`,`rotation`,`opacity`,`color`,`fontSize`,`cropX`,`cropY`,`cropWidth`,`cropHeight`],n=e,r={x:n.x??0,y:n.y??0,width:n.width??0,height:n.height??0,rotation:n.rotation??0,opacity:n.opacity??1};for(let i of t)i in e&&(r[i]=n[i]);let i=L(r),a=Vn(e=>{for(let t in e)i[t]=e[t]}),o=Vn(e=>{Object.assign(i,e)}),s=Vn(e=>{for(let t in e)typeof i[t]==`number`&&(i[t]=i[t]+e[t])});return{get locked(){return!(e.draggable||e.contentEditable||e.styleEditable||e.resizable)},get a(){let{currentTime:t}=e.store,r={};for(let e in i)r[e]=n[e];if(a(r),t===0)return i;let c=t-e.page.startTime;if(c>e.page.duration||c<0)return i;let l=e.store.animatedElementsIds;if(l.length&&!l.includes(e.id))return i;let u=e.animations.find(e=>e.type===`enter`),d=u?.enabled&&c<u.delay;d&&o({opacity:0});let f=u?.enabled&&c>=u.delay&&c<=u.delay+u.duration;f&&s(pk(e,dk({element:e,animation:u,dTime:c-u.delay})));let p=e.animations.find(e=>e.type===`exit`);!d&&!f&&p?.enabled&&c>=e.page.duration-p.duration-p.delay&&c<=e.page.duration-p.delay&&s(pk(e,dk({element:e,animation:p,dTime:c-(e.page.duration-p.duration-p.delay)}))),p!=null&&p.enabled&&c>=e.page.duration-p.delay&&o({opacity:0});let m=e.animations.find(e=>e.type===`loop`);return m?.enabled&&s(pk(e,dk({element:e,animation:m,dTime:c}))),i},animated(e){return this.a[e]}}}).actions(e=>({setAnimation(t,n){let r=e.animations.find(e=>e.type===t);r?Object.assign(r,n):e.animations.push(Object.assign({type:t},n))},setFilter(t,n){hk.includes(t)||e.filters.forEach((t,n)=>{hk.includes(n.toString())||e.filters.delete(n.toString())}),n==null?e.filters.delete(t):e.filters.set(t,{intensity:n})}})),_k=gk.named(`Text`).props({type:`text`,text:``,placeholder:``,fontSize:14,fontFamily:`Roboto`,fontStyle:`normal`,fontWeight:`normal`,textDecoration:``,textTransform:`none`,fill:`black`,align:`center`,width:100,height:0,verticalAlign:`top`,strokeWidth:0,stroke:`black`,lineHeight:q.optional(q.union(q.number,q.string),1.2),letterSpacing:0,_editModeEnabled:!1,backgroundEnabled:!1,backgroundColor:`#7ED321`,backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5,curveEnabled:!1,curvePower:.5}).preProcessSnapshot(e=>Object.assign({},e)).actions(e=>({afterCreate(){if(!e.height){let t=e.lineHeight,n=typeof t==`number`?t:parseFloat(t)||1.2;e.height=Math.round(e.fontSize*n)}},toggleEditMode(t){let n=t??!e._editModeEnabled;n!==e._editModeEnabled&&(e._editModeEnabled=n,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())}})),vk=gk.named(`Image`).props({type:`image`,width:100,height:100,src:``,cropX:0,cropY:0,cropWidth:1,cropHeight:1,cornerRadius:0,flipX:!1,flipY:!1,clipSrc:``,borderColor:`black`,borderSize:0,keepRatio:!1,stretchEnabled:!1}).extend(e=>{let t=L.box(!1),n=!1;return{views:{get _cropModeEnabled(){return t.get()}},actions:{toggleCropMode(r){let i=r??!t.get();t.set(i),i&&!n?(e.store.history.startTransaction(),n=!0):!i&&n&&(e.store.history.endTransaction(),n=!1)},beforeDestroy(){n&&=(e.store.history.endTransaction(),!1)}}}}),yk=vk.named(`Video`).props({type:`video`,duration:0,startTime:0,endTime:1,volume:1}),bk=gk.named(`Line`).props({type:`line`,width:400,height:10,color:`black`,dash:q.array(q.number),startHead:``,endHead:``}).actions(e=>({})),xk=gk.named(`SVG`).props({type:`svg`,src:``,maskSrc:``,cropX:0,cropY:0,cropWidth:1,cropHeight:1,keepRatio:!0,stretchEnabled:!0,flipX:!1,flipY:!1,width:100,height:100,borderColor:`black`,borderSize:0,cornerRadius:0,colorsReplace:q.map(q.string)}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{src:e.src||e.svgSource,colorsReplace:Array.isArray(e.colorsReplace)?{}:e.colorsReplace})).actions(e=>({replaceColor(t,n){e.colorsReplace.set(t,n)}})),Sk=gk.named(`Figure`).props({type:`figure`,subType:`rect`,fill:`rgb(0, 161, 255)`,dash:q.array(q.number),strokeWidth:0,stroke:`rgba(98, 197, 255, 1)`,cornerRadius:0}),Ck=vk.named(`Gif`).props({type:`gif`,duration:0,keepRatio:!0}),wk=.05,Tk=q.enumeration([`solid`,`dashed`,`dotted`,`none`]);function Ek(e){return om(e,2)}function Dk(e,t,n){return e[`_${t}`]??(hm(e)?Ek(e)[t]:n)}function Ok(e){return om(e,1)}var kk=q.model(`BorderSide`,{color:q.maybe(q.string),width:q.maybe(q.number),style:q.maybe(Tk)}).postProcessSnapshot(e=>{let t={};for(let[n,r]of Object.entries(e))r!=null&&(t[n]=r);return t}),Ak=q.model(`CellBorders`,{top:q.maybe(kk),right:q.maybe(kk),bottom:q.maybe(kk),left:q.maybe(kk)}).postProcessSnapshot(e=>{let t={};for(let[n,r]of Object.entries(e))typeof r==`object`&&r&&Object.keys(r).length>0&&(t[n]=r);return t}),jk=[`fontSize`,`fontFamily`,`fontWeight`,`fontStyle`,`textDecoration`,`textTransform`,`fill`,`align`,`verticalAlign`,`lineHeight`,`letterSpacing`,`strokeWidth`,`stroke`,`cellBackground`,`cellPadding`],Mk=new Set(jk),Nk=[`blurEnabled`,`blurRadius`,`brightnessEnabled`,`brightness`,`sepiaEnabled`,`grayscaleEnabled`,`filters`,`shadowEnabled`,`shadowBlur`,`shadowOffsetX`,`shadowOffsetY`,`shadowColor`,`shadowOpacity`],Pk=[`id`,`type`,`text`,`opacity`,`rowSpan`,`colSpan`,`mergedInto`,`name`,`custom`,`borders`],Fk=new Set(`row.col.x.y.width.height.rotation.draggable.resizable.selectable.removable.contentEditable.visible.showInExport.alwaysOnTop.backgroundEnabled.backgroundOpacity.backgroundColor.backgroundCornerRadius.backgroundPadding.curveEnabled.curvePower.shadowEnabled.shadowBlur.shadowOffsetX.shadowOffsetY.shadowColor.shadowOpacity.blurEnabled.blurRadius.brightnessEnabled.brightness.sepiaEnabled.grayscaleEnabled.placeholder.animations.filters`.split(`.`)),Ik={opacity:1,rowSpan:1,colSpan:1,name:``},Lk=[],Rk=q.model(`TableCell`,{id:q.identifier,type:q.optional(q.literal(`tablecell`),`tablecell`),text:``,_fontSize:q.maybe(q.number),_fontFamily:q.maybe(q.string),_fontWeight:q.maybe(q.string),_fontStyle:q.maybe(q.string),_textDecoration:q.maybe(q.string),_textTransform:q.maybe(q.string),_fill:q.maybe(q.string),_align:q.maybe(q.string),_verticalAlign:q.maybe(q.string),_lineHeight:q.maybe(q.union(q.number,q.string)),_letterSpacing:q.maybe(q.number),_strokeWidth:q.maybe(q.number),_stroke:q.maybe(q.string),_cellBackground:q.maybe(q.string),_cellPadding:q.maybe(q.number),opacity:1,rowSpan:1,colSpan:1,mergedInto:q.maybe(q.string),borders:q.maybe(Ak),name:``,custom:q.frozen()}).volatile(()=>({_editModeEnabled:!1,filters:L.map()})).preProcessSnapshot(e=>{if(!e)return e;for(let t in e)e[t]===null&&(e[t]=void 0);let t={};for(let n of Pk)n in e&&(t[n]=e[n]);for(let n of jk)e[n]!==void 0&&(t[`_${n}`]=e[n]);return t}).postProcessSnapshot(e=>{let t={};for(let[n,r]of Object.entries(e))if(n.startsWith(`_`))r!=null&&(t[n.slice(1)]=r);else if(n===`borders`)typeof r==`object`&&r&&Object.keys(r).length>0&&(t.borders=r);else{if(n in Ik&&r===Ik[n])continue;t[n]=r}return t}).views(e=>{let t={get row(){if(!hm(e))return 0;let t=Ek(e),n=Ok(e).indexOf(e);return n===-1?0:Math.floor(n/t.cols)},get col(){if(!hm(e))return 0;let t=Ek(e),n=Ok(e).indexOf(e);return n===-1?0:n%t.cols},get store(){return hm(e)?lm(e):null},get page(){if(!hm(e))return null;try{return Ek(e).page}catch{return null}},get fontSize(){return Dk(e,`fontSize`,30)},get fontFamily(){return Dk(e,`fontFamily`,`Roboto`)},get fontWeight(){return Dk(e,`fontWeight`,`normal`)},get fontStyle(){return Dk(e,`fontStyle`,`normal`)},get textDecoration(){return Dk(e,`textDecoration`,``)},get textTransform(){return Dk(e,`textTransform`,`none`)},get fill(){return Dk(e,`fill`,`black`)},get align(){return Dk(e,`align`,`left`)},get verticalAlign(){return Dk(e,`verticalAlign`,`top`)},get lineHeight(){return Dk(e,`lineHeight`,1.2)},get letterSpacing(){return Dk(e,`letterSpacing`,0)},get strokeWidth(){return Dk(e,`strokeWidth`,0)},get stroke(){return Dk(e,`stroke`,`black`)},get cellBackground(){return Dk(e,`cellBackground`,`transparent`)},get cellPadding(){return Dk(e,`cellPadding`,4)},get width(){if(!hm(e))return 100;try{return Ek(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan).width}catch{return 100}},get height(){if(!hm(e))return 100;try{return Ek(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan).height}catch{return 100}},get a(){if(!hm(e))return{x:0,y:0,width:100,height:100,rotation:0,opacity:1,fontSize:16};let n=Ek(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan),r=t.cellPadding;return{x:n.x+r,y:n.y+r,width:n.width-2*r,height:n.height-2*r,rotation:0,opacity:e.opacity??1,fontSize:t.fontSize}},getEffectiveBorder(t){let n=hm(e)?Ek(e):null,r=e.borders?.[t];return{color:r?.color??n?.borderColor??`#000000`,width:r?.width??n?.borderWidth??1,style:r?.style??n?.borderStyle??`solid`}},get x(){return 0},get y(){return 0},get rotation(){return 0},get draggable(){return!1},get resizable(){return!1},get selectable(){return!1},get removable(){return!1},get contentEditable(){return!0},get visible(){return!0},get showInExport(){return!0},get alwaysOnTop(){return!1},get placeholder(){return``},get backgroundEnabled(){return!1},get backgroundOpacity(){return 1},get backgroundColor(){return`transparent`},get backgroundCornerRadius(){return 0},get backgroundPadding(){return 0},get curveEnabled(){return!1},get curvePower(){return 0},get shadowEnabled(){return!1},get shadowBlur(){return 0},get shadowOffsetX(){return 0},get shadowOffsetY(){return 0},get shadowColor(){return`black`},get shadowOpacity(){return 1},get blurEnabled(){return!1},get blurRadius(){return 0},get brightnessEnabled(){return!1},get brightness(){return 0},get sepiaEnabled(){return!1},get grayscaleEnabled(){return!1},get animations(){return Lk}};return t}).actions(e=>({toJSON:()=>Object.assign({},am(e)),set(t){let n={};for(let[e,r]of Object.entries(t))Mk.has(e)?n[`_${e}`]=r:e===`borders`?n.borders=r&&JSON.parse(JSON.stringify(r)):Fk.has(e)||(n[e]=r);Object.assign(e,n)},setBorder(t,n){let r=e.borders?Object.assign({},am(e.borders)):{},i=r[t]||{},a=Object.assign({},i);n.color!==void 0&&(a.color=n.color),n.width!==void 0&&(a.width=n.width),n.style!==void 0&&(a.style=n.style),r[t]=a,e.borders=gm(r)},toggleEditMode(t){let n=t??!e._editModeEnabled;n!==e._editModeEnabled&&(e._editModeEnabled=n,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())}}));function zk(e){return Array.from({length:e},()=>1/e)}function Bk(e){let t=e.reduce((e,t)=>e+t,0);return t===0?zk(e.length):e.map(e=>e/t)}var Vk=gk.named(`Table`).props({type:`table`,width:300,height:200,rows:3,cols:3,colWidths:q.array(q.number),rowHeights:q.array(q.number),cells:q.array(Rk),borderColor:`#000000`,borderWidth:1,borderStyle:q.optional(q.enumeration([`solid`,`dashed`,`dotted`,`none`]),`solid`),fontSize:30,fontFamily:`Roboto`,fontWeight:`normal`,fontStyle:`normal`,textDecoration:``,textTransform:`none`,fill:`black`,align:`left`,verticalAlign:`top`,lineHeight:q.optional(q.union(q.number,q.string),1.2),letterSpacing:0,strokeWidth:0,stroke:`black`,cellBackground:`transparent`,cellPadding:4}).postProcessSnapshot(e=>{e.cells&&((e=Object.assign({},e)).cells=e.cells.map(t=>{let n={};for(let[r,i]of Object.entries(t))Mk.has(r)&&i===e[r]||(n[r]=i);return n}));for(let t of Nk)delete e[t];return e}).volatile(()=>({_focusedCellIds:[],_editingCellId:void 0,_anchorCellId:void 0,_cellContentHeights:L.map(),_baseRowHeights:null,_baseHeight:null,_isResizingRows:!1,_isTransforming:!1})).actions(e=>({afterCreate(){let t=e.rows*e.cols;if(e.cells.length===0)e.cells.replace(gm(function(e,t){let n=[];for(let r=0;r<e*t;r++)n.push({id:KD(10),text:``});return n}(e.rows,e.cols)));else if(e.cells.length<t)for(;e.cells.length<t;)e.cells.push(gm({id:KD(10),text:``}));else e.cells.length>t&&e.cells.splice(t);e.colWidths.length===0&&e.colWidths.replace(zk(e.cols)),e.rowHeights.length===0&&e.rowHeights.replace(zk(e.rows))}})).views(e=>({get _cellMap(){let t=new Map,n=e.cols;return e.cells.forEach((e,r)=>{t.set(`${Math.floor(r/n)}:${r%n}`,e)}),t},getActualRowHeight:t=>e.rowHeights[t]*e.height})).views(e=>{let t={getCell:(t,n)=>e._cellMap.get(`${t}:${n}`),get minWidth(){return 20*e.cols},get minHeight(){return 20*e.rows},get actualHeight(){let t=0;for(let n=0;n<e.rows;n++)t+=e.getActualRowHeight(n);return t},getCellRect(t,n,r=1,i=1){let a=0;for(let t=0;t<n;t++)a+=e.colWidths[t]*e.width;let o=0;for(let n=0;n<t;n++)o+=e.getActualRowHeight(n);let s=0;for(let t=n;t<n+i;t++)s+=(e.colWidths[t]||0)*e.width;let c=0;for(let n=t;n<t+r;n++)c+=e.getActualRowHeight(n);return{x:a,y:o,width:s,height:c}},get visibleCells(){return e.cells.filter(e=>!e.mergedInto)},get focusedCells(){return e.cells.filter(t=>e._focusedCellIds.includes(t.id))},get editingCell(){if(e._editingCellId)return e.cells.find(t=>t.id===e._editingCellId)},get _fitRowsToContent(){if(e._isResizingRows||e._isTransforming||e._cellContentHeights.size===0)return null;let n=e._baseHeight??e.height,r=e._baseRowHeights??[...e.rowHeights],i=!1,a=[];for(let o=0;o<e.rows;o++){let s=e.rowHeights[o]*e.height,c=r[o]*n,l=0;for(let n=0;n<e.cols;n++){let r=t.getCell(o,n);if(!r)continue;let i=e._cellContentHeights.get(r.id);if(i!==void 0){let e=i+2*r.cellPadding;l=Math.max(l,e)}}let u=Math.max(l,c);Math.abs(u-s)>1?(a.push(u),i=!0):a.push(s)}if(!i)return null;let o=a.reduce((e,t)=>e+t,0);return{rowHeights:a.map(e=>e/o),height:o}}};return t}).actions(e=>{let t={setCellContentHeight(t,n){e._cellContentHeights.set(t,n)},_applyFitRowsToContent(){e._baseRowHeights===null&&(e._baseRowHeights=[...e.rowHeights],e._baseHeight=e.height);let t=e._fitRowsToContent;t&&(e.height=t.height,e.rowHeights.replace(t.rowHeights))},focusCell(t,n=!1){n?e._focusedCellIds.includes(t)||(e._focusedCellIds=[...e._focusedCellIds,t]):(e._focusedCellIds=[t],e._anchorCellId=t)},focusCellRange(t,n){let r=e.cells.find(t=>t.id===e._anchorCellId);if(!r)return;let i=Math.min(r.row,t),a=Math.max(r.row,t),o=Math.min(r.col,n),s=Math.max(r.col,n),c=[];for(let t of e.cells)t.row>=i&&t.row<=a&&t.col>=o&&t.col<=s&&c.push(t.id);e._focusedCellIds=c},clearCellFocus(){if(hm(e)){if(e._editingCellId){let t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1)}e._focusedCellIds=[],e._editingCellId=void 0,e._anchorCellId=void 0}},enterCellEdit(t){e._editingCellId=t,e._focusedCellIds.includes(t)||(e._focusedCellIds=[t]);let n=e.cells.find(e=>e.id===t);n&&n.toggleEditMode(!0)},exitCellEdit(){if(e._editingCellId){let t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1)}e._editingCellId=void 0},_resetBaseRowHeights(){e._baseRowHeights=null,e._baseHeight=null},_setIsResizingRows(t){e._isResizingRows=t},_setIsTransforming(t){e._isTransforming=t},addRow(n){t._resetBaseRowHeights();let r=n>0?n-1:0,i=(e.rowHeights[r]||1/(e.rows+1))*e.height,a=e.height+i,o=[];for(let t=0;t<e.rows;t++)o.push(e.rowHeights[t]*e.height/a);o.splice(n,0,i/a);let s=n*e.cols,c=Array.from({length:e.cols},()=>({id:KD(10),text:``}));e.cells.splice(s,0,...gm(c)),e.rows+=1,e.height=a,e.rowHeights.replace(Bk(o))},removeRow(n){if(e.rows<=1)return;t._resetBaseRowHeights();let r=n*e.cols,i=[];for(let t=r;t<r+e.cols;t++)i.push(e.cells[t].id);if(e._editingCellId&&i.includes(e._editingCellId)){let t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1),e._editingCellId=void 0}e._focusedCellIds=e._focusedCellIds.filter(e=>!i.includes(e)),i.forEach(t=>e._cellContentHeights.delete(t)),e.cells.splice(r,e.cols);let a=[...e.rowHeights];a.splice(n,1),--e.rows,e.rowHeights.replace(Bk(a))},addColumn(t){let n=t>0?t-1:0,r=(e.colWidths[n]||1/(e.cols+1))*e.width,i=e.width+r,a=[];for(let t=0;t<e.cols;t++)a.push(e.colWidths[t]*e.width/i);a.splice(t,0,r/i);let o=e.cols;for(let n=e.rows-1;n>=0;n--)e.cells.splice(n*o+t,0,gm({id:KD(10),text:``}));e.cols+=1,e.width=i,e.colWidths.replace(Bk(a))},removeColumn(t){if(e.cols<=1)return;let n=e.cols,r=[];for(let i=0;i<e.rows;i++)r.push(e.cells[i*n+t].id);if(e._editingCellId&&r.includes(e._editingCellId)){let t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1),e._editingCellId=void 0}e._focusedCellIds=e._focusedCellIds.filter(e=>!r.includes(e)),r.forEach(t=>e._cellContentHeights.delete(t));for(let r=e.rows-1;r>=0;r--)e.cells.splice(r*n+t,1);let i=[...e.colWidths];i.splice(t,1),--e.cols,e.colWidths.replace(Bk(i))},distributeRowsEvenly(){t._resetBaseRowHeights(),e.rowHeights.replace(zk(e.rows))},distributeColumnsEvenly(){e.colWidths.replace(zk(e.cols))},resizeColumn(t,n){if(t>=e.cols-1)return;let r=[...e.colWidths],i=r[t]+r[t+1],a=r[t]+n,o=r[t+1]-n;a<wk?(r[t]=wk,r[t+1]=i-wk):o<wk?(r[t+1]=wk,r[t]=i-wk):(r[t]=a,r[t+1]=o),e.colWidths.replace(r)},resizeRow(t,n){if(t>=e.rows-1)return;let r=[...e.rowHeights],i=r[t]+r[t+1],a=r[t]+n,o=r[t+1]-n;a<wk?(r[t]=wk,r[t+1]=i-wk):o<wk?(r[t+1]=wk,r[t]=i-wk):(r[t]=a,r[t+1]=o),e.rowHeights.replace(r)},setCellBorders(t,n,r){let i={top:{side:`bottom`,dr:-1,dc:0},bottom:{side:`top`,dr:1,dc:0},left:{side:`right`,dr:0,dc:-1},right:{side:`left`,dr:0,dc:1}};for(let a of t){let t=e.cells.find(e=>e.id===a);if(t)for(let a of n){t.setBorder(a,r);let n=i[a],o=t.row+n.dr,s=t.col+n.dc,c=e.getCell(o,s);c&&c.setBorder(n.side,r)}}}};return t}).actions(e=>({clone(t={},{skipSelect:n=!1}={}){let r=JSON.parse(JSON.stringify(e.toJSON()));if(t.id=t.id||KD(10),r.cells){let e=new Map;r.cells.forEach(t=>{let n=t.id,r=KD(10);e.set(n,r),t.id=r}),r.cells.forEach(t=>{t.mergedInto&&e.has(t.mergedInto)&&(t.mergedInto=e.get(t.mergedInto))})}return Object.assign(r,t),e.page.addElement(r,{skipSelect:n})}})),Hk=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n},Uk=(e,t)=>{if(e.children)for(let n of e.children){if(!0===t(n))break;Uk(n,t)}},Wk=(e,t)=>{if(e.children)for(let n of e.children){if(!0===t(n))break;Wk(n,t)}if(e.cells){for(let n of e.cells)if(!0===t(n))break}},Gk=[...Array(20)].map((e,t)=>q.late(()=>Jk[t])),Kk=q.union({dispatcher:e=>{let t=Yk[e.type];if(!t)throw Error(`Unknown element type: "${e.type}"`);return t}},xk,_k,vk,bk,yk,Sk,Ck,Vk,q.late(()=>qk),...Gk),qk=sk.named(`Group`).props({type:`group`,children:q.array(Kk)}).views(e=>({get draggable(){let t=!0;return Uk(e,e=>{e.draggable||(t=!1)}),t},get resizable(){let t=!0;return Uk(e,e=>{e.resizable||(t=!1)}),t},get contentEditable(){let t=!0;return Uk(e,e=>{e.contentEditable||(t=!1)}),t},get styleEditable(){let t=!0;return Uk(e,e=>{e.styleEditable||(t=!1)}),t},get locked(){let t=!0;return Uk(e,e=>{e.locked||(t=!1)}),t}})).actions(e=>({set(t){var{draggable:n,contentEditable:r,styleEditable:i,resizable:a}=t,o=Hk(t,[`draggable`,`contentEditable`,`styleEditable`,`resizable`]);n!==void 0&&Uk(e,e=>{e.set({draggable:n})}),r!==void 0&&Uk(e,e=>{e.set({contentEditable:r})}),i!==void 0&&Uk(e,e=>{e.set({styleEditable:i})}),a!==void 0&&Uk(e,e=>{e.set({resizable:a})}),Object.assign(e,o)},addElement(t,{skipSelect:n=!1}={}){let r=Yk[t.type];if(!r){console.error(`Can not find model with type `+t.type);return}t.children&&t.children.forEach(e=>{e.id=e.id||KD(10)});let i=r.create(Object.assign({id:KD(10)},t));return e.children.push(i),i.selectable&&!n&&e.store.selectElements([i.id]),i},setElementZIndex(t,n){let r=e.children.find(e=>e.id===t);r&&(pm(r),e.children.remove(r),e.children.splice(n,0,r))},setAnimation(t,n){Uk(e,e=>{e.setAnimation(t,n)})}})),Jk=[],Yk={svg:xk,text:_k,image:vk,group:qk,line:bk,video:yk,figure:Sk,gif:Ck,table:Vk},Xk={text:F_,image:hv,svg:hv,line:Eb,video:_D,figure:MD,group:sa(e=>{let{element:t,store:n}=e,{children:r}=t,i=t.selectable||n.role===`admin`;return d.createElement(Kd,{opacity:t.opacity,listening:i,hideInExport:!t.showInExport,id:t.id},r.map(t=>d.createElement(Qk,Object.assign({},e,{key:t.id,store:n,element:t}))))}),gif:HD,table:UD},Zk=(e,t)=>{let n=[];Uk(e,e=>{e.type!==`group`&&n.push(e.a)});let r=[];n.forEach(e=>{let t=[{x:0,y:0},{x:0+e.width,y:0},{x:0+e.width,y:0+e.height},{x:0,y:0+e.height}],n=new Du.Transform;n.translate(e.x,e.y),n.rotate(Du.Util.degToRad(e.rotation)),t.forEach(e=>{let t=n.point(e);r.push(t)})});let i=new Du.Transform;i.rotate(-Du.Util.degToRad(t));let a=1/0,o=1/0,s=-1/0,c=-1/0;r.forEach(e=>{let t=i.point(e);a=Math.min(a,t.x),o=Math.min(o,t.y),s=Math.max(s,t.x),c=Math.max(c,t.y)}),i.invert();let l=i.point({x:a,y:o});return{x:l.x,y:l.y,width:s-a,height:c-o,rotation:t}},Qk=sa(e=>{let{element:t,store:n}=e,[r,i]=d.useState(!1),a=n.selectedElements.indexOf(t)>=0&&t.selectable,o=t.parent?.type===`group`,s=(e=>{let[t,n]=d.useState();return d.useEffect(()=>{let t=setTimeout(()=>{let t=e.page.id,r=Du.stages.find(e=>e.getAttr(`pageId`)===t);r||console.error(`No stage is found for element`,e.id),n(r)});return()=>clearTimeout(t)},[e.id]),t})(t),c=s?.findOne(`Transformer`);d.useEffect(()=>{if(s){let e=e=>{let r=e.target.findAncestor(`.element`,!0),a=n.getElementById(r?.id())?.top;i(a?.id===t.id)};s.on(`mouseover`,e);let r=()=>{i(!1)};return s.on(`mouseleave`,r),()=>{s.off(`mouseover`,e),s.off(`mouseleave`,r)}}},[s]);let l=Xk[e.element.type];return e.element.type===`text`&&Sp.htmlRenderEnabled&&(l=ib),e.element.visible?l?d.createElement(Kd,{name:`element-container`},d.createElement(l,Object.assign({},e)),r&&!a&&!o&&d.createElement(GD,{element:t.type===`group`?{a:Zk(t,c?.rotation()||0)}:t})):(console.error(`Can not find component for `+e.element.type),null):null});function $k(e,t=.5){if(e.length<3)return e;let n=[];n.push(e[0]);for(let t=0;t<e.length-1;t++){let r=e[Math.max(0,t-1)],i=e[t],a=e[t+1],o=e[Math.min(e.length-1,t+2)];for(let e=0;e<10;e++){let t=e/10,s=t*t,c=s*t,l=.5*(2*i.x+(-r.x+a.x)*t+(2*r.x-5*i.x+4*a.x-o.x)*s+(-r.x+3*i.x-3*a.x+o.x)*c),u=.5*(2*i.y+(-r.y+a.y)*t+(2*r.y-5*i.y+4*a.y-o.y)*s+(-r.y+3*i.y-3*a.y+o.y)*c);n.push({x:l,y:u})}}return n.push(e[e.length-1]),n}function eA(e){if(e.length===0)return``;if(e.length===1){let t=e[0];return`M ${t.x},${t.y} L ${t.x+.1},${t.y}`}let t=`M ${e[0].x},${e[0].y}`;for(let n=1;n<e.length-1;n++){let r=e[n],i=e[n+1],a=(r.x+i.x)/2,o=(r.y+i.y)/2;t+=` Q ${r.x},${r.y} ${a},${o}`}if(e.length>1){let n=e[e.length-1];t+=` L ${n.x},${n.y}`}return t}function tA(e){if(e.length===0)return{x:0,y:0,width:0,height:0};let t=e[0].x,n=e[0].y,r=e[0].x,i=e[0].y;for(let a of e)t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x),i=Math.max(i,a.y);return{x:t,y:n,width:r-t,height:i-n}}function nA(e,t){if(e.length===0)throw Error(`Cannot create SVG from empty path`);let n=t.smooth?$k(e):e,r=tA(n),i=t.strokeWidth,a=r.x-i,o=r.y-i,s=r.width+2*i,c=r.height+2*i;return{src:J_(`\n <svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${c}" viewBox="0 0 ${s} ${c}">\n <path\n d="${eA(n.map(e=>({x:e.x-a,y:e.y-o})))}"\n stroke="${t.stroke}"\n stroke-width="${t.strokeWidth}"\n stroke-linecap="round"\n stroke-linejoin="round"\n fill="none"\n />\n </svg>\n `.trim()),x:a,y:o,width:s,height:c}}var rA=sa(({store:e,page:t,width:n,height:r,scale:i,xPadding:a,yPadding:o,bleed:s})=>{let[c,l]=d.useState(!1),[u,f]=d.useState([]),p=d.useRef(null),m=e.tool===`draw`,{strokeWidth:h,stroke:g,opacity:_,brushType:v}=e.toolOptions,y=d.useCallback(e=>{if(!m||(l(!0),e.cancelBubble=!0,!e.target.getStage()))return;let t=p.current.getRelativePointerPosition();t&&f([{x:t.x,y:t.y}])},[m,i,a,o,s]),b=d.useCallback(e=>{if(!m||!c||(e.cancelBubble=!0,!e.target.getStage()))return;let t=p.current.getRelativePointerPosition();t&&f(e=>[...e,{x:t.x,y:t.y}])},[m,c,i,a,o,s]),x=d.useCallback(()=>{if(m&&c){if(l(!1),u.length>=1)try{let n=nA(u,{stroke:g,strokeWidth:h,smooth:!0}),r=e.selectedElementsIds.slice();e.history.transaction(()=>{t.addElement({type:`svg`,x:n.x,y:n.y,width:n.width,height:n.height,src:n.src,opacity:_},{skipSelect:!0})}),e.selectElements(r)}catch(e){console.error(`Error creating path SVG:`,e)}f([])}},[m,c,u,g,h,_,t,e.history,e]),S=d.useMemo(()=>u.flatMap(e=>[e.x,e.y]),[u]);return d.useEffect(()=>{if(m&&p.current){let e=p.current.getStage();if(!e)return;let t=h*i;if(t>100||t<4)e.container().style.cursor=`crosshair`;else{let n=t/2,r=t/2,i=`data:image/svg+xml;base64,${btoa(`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}" viewBox="0 0 ${t} ${t}">\n <circle cx="${r}" cy="${r}" r="${n-1}" fill="${g}" opacity="${_}" stroke="white" stroke-width="1"/>\n <circle cx="${r}" cy="${r}" r="${n-1}" fill="none" stroke="black" stroke-width="1" opacity="0.3"/>\n </svg>`)}`;e.container().style.cursor=`url("${i}") ${r} ${r}, crosshair`}return()=>{e.container()&&(e.container().style.cursor=``)}}},[m,g,h,_,i]),m?d.createElement(Kd,{ref:p,listening:m,x:a+s*i,y:o+s*i,scaleX:i,scaleY:i},d.createElement(Jd,{x:-(a+s*i)/i,y:-(o+s*i)/i,width:n/i,height:r/i,fill:`transparent`,onMouseDown:y,onMouseMove:b,onMouseUp:x,onTouchStart:y,onTouchMove:b,onTouchEnd:x}),u.length>0&&d.createElement(`Line`,{points:S,stroke:g,strokeWidth:h,lineCap:`round`,lineJoin:`round`,opacity:_,tension:.5,listening:!1})):null});function iA(e,t,n=`scale`){let r=t.width/t.height,i,a;r>=e.width/e.height?(i=e.width,a=e.width/r):(i=e.height*r,a=e.height);let o=0,s=0;return n===`left-top`?(o=0,s=0):n===`left-middle`?(o=0,s=(e.height-a)/2):n===`left-bottom`?(o=0,s=e.height-a):n===`center-top`?(o=(e.width-i)/2,s=0):n===`center-middle`?(o=(e.width-i)/2,s=(e.height-a)/2):n===`center-bottom`?(o=(e.width-i)/2,s=e.height-a):n===`right-top`?(o=e.width-i,s=0):n===`right-middle`?(o=e.width-i,s=(e.height-a)/2):n===`right-bottom`?(o=e.width-i,s=e.height-a):n===`scale`?(o=0,s=0,i=e.width,a=e.height):console.error(Error(`Unknown clip position property - `+n)),{cropX:o,cropY:s,cropWidth:i,cropHeight:a}}var aA=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n},oA=e=>tf.batchedUpdates(e,null);Gi(e=>{tf.isAlreadyRendering()?queueMicrotask(()=>oA(e)):oA(e)});var sA=Du.DD._drag;window.removeEventListener(`mousemove`,sA),Du.DD._drag=function(e){Un(()=>{sA.call(this,e)})},window.addEventListener(`mousemove`,Du.DD._drag);var cA=new Du.Group,lA=20;cA.add(new Du.Rect({width:lA,height:lA,fill:`white`})),cA.add(new Du.Path({scaleX:lA/24,scaleY:lA/24,data:`M4.98313549,11.0001422 C5.49589839,10.9914935 5.92501998,11.3703506 5.99116425,11.8666444 L5.99985778,11.9831355 L6.00348884,12.2068855 C6.11245031,15.4321748 8.76323537,17.9999971 11.9999971,17.9999971 C12.1869612,17.9999971 12.3726725,17.9914753 12.5567465,17.9745765 L12.2928932,17.7071068 C11.9023689,17.3165825 11.9023689,16.6834175 12.2928932,16.2928932 C12.6834175,15.9023689 13.3165825,15.9023689 13.7071068,16.2928932 L15.7071068,18.2928932 C16.0976311,18.6834175 16.0976311,19.3165825 15.7071068,19.7071068 L13.7071068,21.7071068 C13.3165825,22.0976311 12.6834175,22.0976311 12.2928932,21.7071068 C11.9023689,21.3165825 11.9023689,20.6834175 12.2928932,20.2928932 L12.6111505,19.9769552 C12.4086045,19.9922816 12.2047796,19.9999971 11.9999971,19.9999971 C7.7687005,19.9999971 4.28886152,16.7094374 4.01666425,12.5105203 L4.00420123,12.2575143 L4.00014222,12.0168645 C3.9908282,11.4646583 4.43092928,11.0094562 4.98313549,11.0001422 Z M11.7071068,2.29289322 C12.0675907,2.65337718 12.0953203,3.22060824 11.7902954,3.61289944 L11.7071068,3.70710678 L11.3891629,4.0230186 C11.5916051,4.00770767 11.7953244,4 12,4 C16.418278,4 20,7.581722 20,12 C20,12.5522847 19.5522847,13 19,13 C18.4477153,13 18,12.5522847 18,12 C18,8.6862915 15.3137085,6 12,6 C11.8129339,6 11.6271216,6.00853145 11.4429483,6.02544919 L11.7071068,6.29289322 C12.0976311,6.68341751 12.0976311,7.31658249 11.7071068,7.70710678 C11.3466228,8.06759074 10.7793918,8.09532028 10.3871006,7.79029539 L10.2928932,7.70710678 L8.29289322,5.70710678 C7.93240926,5.34662282 7.90467972,4.77939176 8.20970461,4.38710056 L8.29289322,4.29289322 L10.2928932,2.29289322 C10.6834175,1.90236893 11.3165825,1.90236893 11.7071068,2.29289322 Z`,fill:`black`}));var uA=cA.toCanvas({pixelRatio:2,width:lA,height:lA}),dA={enabledAnchors:[`top-left`,`top-center`,`top-right`,`middle-left`,`bottom-left`,`bottom-right`,`bottom-center`,`middle-right`],borderEnabled:!0,rotateEnabled:!0,rotationSnaps:[0,45,90,135,180,225,270,315],ignoreStroke:!0,flipEnabled:!1,anchorStrokeWidth:2,borderStrokeWidth:2,rotateAnchorOffset:30,keepRatio:!0,anchorStyleFunc:e=>{e.hasName(`rotater`)&&e.setAttrs({width:20,height:20,cornerRadius:20/2,offsetX:20/2,offsetY:20/2,fillPatternImage:uA,fillPatternScaleX:20/lA/2,fillPatternScaleY:20/lA/2,fillPriority:`pattern`,fillPatternRepeat:`no-repeat`})}},fA={text:{enabledAnchors:[`top-left`,`top-right`,`middle-left`,`bottom-left`,`bottom-right`,`middle-right`]},svg:{enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`]},gif:{enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`]},line:{enabledAnchors:[],borderEnabled:!1,rotateEnabled:!1},image:{enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`]},many:{enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`]},group:{enabledAnchors:[`top-left`,`top-right`,`bottom-left`,`bottom-right`]},table:{keepRatio:!1,enabledAnchors:[`top-left`,`top-right`,`middle-left`,`middle-right`,`bottom-left`,`bottom-right`]}},pA=e=>d.createElement(Jd,Object.assign({},e,{preventDefault:!1})),mA=e=>{var{url:t}=e,n=aA(e,[`url`]);let[r,i]=(0,rf.default)(t,`anonymous`),a=r?iA(r,{width:n.width,height:n.height},`center-middle`):{};return mv(i,t,`page background`),d.createElement(Xd,Object.assign({image:r},n,a))},hA=e=>{let t=Pf({a:{width:e.width,height:e.height},width:e.width,height:e.height},e.fill);return d.createElement(Jd,Object.assign({},e,t))},gA=e=>{let{background:t,scale:n,borderColor:r,transparencyBackgroundColor:i}=e,a=aA(e,[`background`,`scale`,`borderColor`,`transparencyBackgroundColor`]),o=d.useMemo(()=>!!Du.Util.colorToRGBA(t)||jf(t),[t]),s=d.useMemo(()=>{if(jf(t))return!0;let e=Du.Util.colorToRGBA(t);return!e||e.a<1},[t]),c=d.useMemo(()=>{if(!s||i)return null;let e=document.createElement(`canvas`);e.width=60,e.height=60;let t=e.getContext(`2d`);return t&&(t.fillStyle=`black`,t.fillRect(30,0,30,30),t.fillRect(0,30,30,30)),e},[s,i]);return d.createElement(d.Fragment,null,s&&(i?d.createElement(`Rect`,Object.assign({fill:i},a,{hideInExport:!0})):d.createElement(`Rect`,Object.assign({fillPatternImage:c},a,{opacity:.1,hideInExport:!0}))),o?d.createElement(hA,Object.assign({fill:t},a)):d.createElement(mA,Object.assign({url:t},a)))},_A=sa(({selection:e,fill:t=`rgba(0, 161, 255, 0.3)`,stroke:n=`rgb(0, 161, 255)`,strokeWidth:r=1})=>e.visible?d.createElement(Jd,{name:`selection`,x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),width:Math.abs(e.x1-e.x2),height:Math.abs(e.y1-e.y2),fill:t,stroke:n,strokeWidth:r}):null);function vA(e){let t=180*e/Math.PI;return t%=360,t>180?t-=360:t<-180&&(t+=360),Math.round(t)}var yA=sa(({x:e,y:t,width:n,height:r,rotation:i,anchor:a,store:o,tagFill:s,textFill:c})=>{if(e===void 0||t===void 0||n===void 0||r===void 0||i===void 0||a===void 0)return null;let l=cb({x:e,y:t,width:n,height:r,rotation:Du.Util.radToDeg(i)}),u=(r/2+70)*Math.cos(i-Math.PI/2),f=(r/2+70)*Math.sin(i-Math.PI/2),p=SO({unit:o.unit,dpi:o.dpi,px:n/o.scale,precious:o.unit===`px`?0:1})+` x `+SO({unit:o.unit,dpi:o.dpi,px:r/o.scale,precious:o.unit===`px`?0:1})+(o.unit===`px`?``:` `+o.unit);return d.createElement(d.Fragment,null,d.createElement(qd,{x:(l.minX+l.maxX)/2+u,y:(l.minY+l.maxY)/2+f,offsetX:14,offsetY:14,visible:a===`rotater`},d.createElement(`Tag`,{cornerRadius:5,fill:s||`rgb(0, 161, 255)`}),d.createElement(Zd,{align:`center`,verticalAlign:`middle`,fill:c||`white`,padding:8,text:vA(i).toString()+`°`})),d.createElement(qd,{x:(l.minX+l.maxX)/2,y:l.maxY+20,visible:a!==`rotater`},d.createElement(`Tag`,{cornerRadius:5,fill:s||`rgb(0, 161, 255)`,pointerDirection:`up`,pointerHeight:0,pointerWidth:0}),d.createElement(Zd,{align:`center`,verticalAlign:`middle`,fill:c||`white`,padding:8,text:p})))}),bA=sa(({elements:e,store:t})=>{let n=e.filter(e=>e.alwaysOnTop),r=e.filter(e=>!e.alwaysOnTop).concat(n);return d.createElement(d.Fragment,null,r.map(e=>d.createElement(Qk,{key:e.id,store:t,element:e,onClick:()=>{console.warn(`Polotno warning: onClick callback is deprecated. Just stop using it. Polotno will do selection automatically.`)}})))}),xA=({store:e})=>{let[t,n]=d.useState(!1),[r,i]=d.useState({x:0,y:0});return{open:d.useCallback(e=>{n(!0),i(e)},[]),close:d.useCallback(()=>{n(!1)},[]),props:{isOpen:t,offset:r,setIsOpen:n}}},SA=null,CA=atob(`UG9sb3RubyBmcmVlIGxpY2Vuc2UgbGltaXRhdGlvbiBleGNlZWRlZCAtIFBsZWFzZSB1cGdyYWRlIHlvdXIgYWNjb3VudC4=`),wA=atob(`I2MwMzkyYg==`),TA=atob(`djAuOS4y`),EA=e=>d.createElement(d.Fragment,null,d.createElement(qd,{fill:wA,height:200},d.createElement(`Tag`,{fill:wA}),d.createElement(Zd,Object.assign({},e,{fill:`white`,text:CA,height:void 0,padding:10,fontSize:20})))),DA=atob(`RlJFRSAgVFJJQUwgIExJQ0VOU0U=`),OA=(atob(`UG93ZXJlZCBieSBQb2xvdG5v`),atob(`TElDRU5TRSAgS0VZICBJUyAgTUlTU0lORw==`)),kA=atob(`UGxlYXNlIGFjdGl2YXRlIHlvdXIgbGljZW5zZS4KTGljZW5zZSByZWxhdGVkIHF1ZXN0aW9uczoKcG9sb3Ruby5jb20vY29udGFjdA==`),AA=e=>{let t=oO()===1,n=t?OA:DA,r=t?230:195;return d.createElement(Kd,Object.assign({},e,{listening:!1}),d.createElement(Jd,{fill:wA,width:r,height:24,cornerRadius:2}),d.createElement(Zd,{text:n,fill:`white`,fontSize:13,fontFamily:`monospace`,width:r,align:`center`,y:5,listening:!1}),t&&d.createElement(`Text`,{text:kA,fill:`rgba(0,0,0,0.6)`,fontSize:14,y:30,listening:!1}))},jA=sa(({store:e,page:t,width:n,height:r,pageControlsEnabled:i,backColor:a,transparencyBackgroundColor:o,pageBorderColor:s,activePageBorderColor:c,components:l,bleedColor:u,altCloneEnabled:f,viewportSize:p,selectionRectFill:m,selectionRectStroke:h,selectionRectStrokeWidth:g,snapGuideStroke:_,snapGuideStrokeWidth:v,snapGuideDash:y,transformLabelFill:b,transformLabelTextFill:x,distanceGuideStroke:S,distanceLabelFill:C,distanceLabelTextFill:w,layout:T=`vertical`,tooltipSafeArea:E,transformerSafeArea:D})=>{let O=e.bleedVisible?t.bleed:0,k=t.computedWidth+2*O,A=t.computedHeight+2*O,j=(n-k*e.scale)/2,M=(r-A*e.scale)/2,N=d.useRef(null),P=d.useRef(null),F=d.useRef(null),ee=i==null||i,te=d.useRef(!1),[ne,re]=d.useState(null),[ie,I]=d.useState({}),[ae,oe]=d.useState(0),se=xA({store:e}),ce=e.selectedElements.find(e=>e._cropModeEnabled),le=e.selectedElements.find(e=>e.curveEnabled),ue=e.selectedShapes.filter(e=>!e.resizable).length>0,de=e.selectedShapes.filter(e=>!e.draggable).length>0,fe=e.selectedElements.filter(e=>!e.visible).length>0;d.useLayoutEffect(()=>{var t;if(!N.current)return;let n=N.current.getStage(),r=e.selectedShapes.map(e=>e._cropModeEnabled?null:n.findOne(`#`+e.id)).filter(e=>!!e),i=e.selectedElements.length===1,a=i&&e.selectedElements[0]?.type||`many`;fA[a]?(N.current.setAttrs(Object.assign(Object.assign({},dA),fA[a])),a!==`svg`&&a!==`image`&&a!==`gif`||e.selectedElements[0].keepRatio||N.current.setAttrs({enabledAnchors:dA.enabledAnchors}),a===`text`&&Sp.textVerticalResizeEnabled&&N.current.setAttrs({enabledAnchors:fA.text.enabledAnchors?.concat([`bottom-center`])}),a===`text`&&i&&e.selectedElements[0].curveEnabled&&N.current.setAttrs({enabledAnchors:fA.many.enabledAnchors})):N.current.setAttrs(dA),ue&&N.current.enabledAnchors([]),de&&N.current.rotateEnabled(!1),r.find(e=>e?.isDragging())&&r.forEach(e=>{e.isDragging()||e==null||e.startDrag()}),N.current.nodes(r),_b(),(t=N.current.getLayer())==null||t.batchDraw()},[e.selectedShapes,ce,ue,fe,de,le]);let pe=()=>{let e=N.current;if(!e)return;if(!e.isTransforming()){I({});return}if(!e.nodes().length||!e.isTransforming())return;let t=e.__getNodeRect(),n=e?.getActiveAnchor(),r=e.getStage();I({anchor:n,x:t.x-(r?.x()??0),y:t.y-(r?.y()??0),rotation:t.rotation,width:t.width,height:t.height})},me=d.useCallback(()=>{if(N.current?.isTransforming())return;let e=N.current;if(!e||!e.nodes().length){oe(0);return}let t=e.getClientRect();e.getStage()&&oe(function(e,t,n,r=0){let i=e.x+e.width/2,a=e.y+e.height/2,o=e.width/2,s=e.height/2,c=r*Math.PI/180,l=e=>{let t=e*Math.PI/180,r=(e%360+360)%360,l;l=r===0||r===180?s:o;let u=Math.sin(t)*(l+n),d=-Math.cos(t)*(l+n),f=u*Math.cos(c)-d*Math.sin(c),p=u*Math.sin(c)+d*Math.cos(c);return{x:i+f,y:a+p}},u=e=>e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom;if(u(l(0)))return 0;for(let e of[180,270,90])if(u(l(e)))return e;return 0}(t,{top:D?.top||0,bottom:r-(D?.bottom||0),left:D?.left||0,right:n-(D?.right||0)},dA.rotateAnchorOffset||30,e.rotation()))},[D,n,r]);d.useEffect(()=>{var e;(e=N.current)==null||e.update(),pe(),me()},[e.scale,me]),d.useEffect(()=>{me()},[e.selectedShapes,me]);let he=da(()=>({visible:!1,x1:0,y1:0,x2:0,y2:0})),ge=d.useRef(!1),_e=Up(),ve=Vn(e=>{if(_e)return;ge.current=!1;let t=e.target.findAncestor(`.elements-container`),n=e.target.findAncestor(`Transformer`),r=e.target.findAncestor(`.page-abs-container`);if(t||n||r)return;let i=e.target.getStage()?.getPointerPosition();i&&(i.x-=e.target.getStage()?.x()??0,i.y-=e.target.getStage()?.y()??0,he.visible=!0,he.x1=i.x,he.y1=i.y,he.x2=i.x,he.y2=i.y,(e.target.getStage()?.getPointersPositions().length??0)>=2&&(he.visible=!1))});(({stageRef:e,containerRef:t,viewportSize:n})=>{d.useEffect(()=>{let n=t.current?.closest(`.polotno-workspace-inner`);function r(){if(!e.current)return;let r=t.current?.getBoundingClientRect(),i=n?.getBoundingClientRect();if(!r||!i)return;let a=Math.max(0,i.left-r.left-100),o=Math.max(0,i.top-r.top-100);e.current.position({x:-a,y:-o}),e.current.container().style.transform=`translate(${a}px, ${o}px)`}return r(),n?.addEventListener(`scroll`,r),()=>{n?.removeEventListener(`scroll`,r)}},[n.width,n.height])})({stageRef:P,containerRef:F,viewportSize:p}),d.useEffect(()=>{let t=Vn(e=>{var t;if(!he.visible)return;(t=P.current)==null||t.setPointersPositions(e);let n=P.current?.getPointerPosition();n?(n.x-=P.current?.x()??0,n.y-=P.current?.y()??0):n={x:he.x2,y:he.y2},he.x2=n.x,he.y2=n.y}),n=Vn(()=>{if(!he.visible||!P.current)return;let t=P.current.findOne(`.selection`),n=t?t.getClientRect({skipStroke:!0}):{width:0,height:0,x:0,y:0};if(n.width&&n.height){let t=[];P.current.find(`.element`).forEach(r=>{let i=r.getClientRect(),a=e.getElementById(r.id()),o=a?.draggable,s=a?.selectable;Du.Util.haveIntersection(n,i)&&o&&s&&t.push(a.top.id)});let r=[...new Set(t)];ge.current=!0,e.selectElements(r)}he.visible=!1});return window.addEventListener(`mousemove`,t),window.addEventListener(`touchmove`,t),window.addEventListener(`mouseup`,n,{capture:!0}),window.addEventListener(`touchend`,n,{capture:!0}),()=>{window.removeEventListener(`mousemove`,t),window.removeEventListener(`touchmove`,t),window.removeEventListener(`mouseup`,n),window.removeEventListener(`touchend`,n)}},[]);let ye=d.useCallback(n=>{if(!e.selectedElements[0]||n&&e.selectedElementsIds.includes(n))return;let r=lb(e.selectedShapes),i=cb(n?e.getElementById(n):{x:0,y:0,width:t.computedWidth,height:t.computedHeight,rotation:0}),a=[];r.minX>i.maxX&&a.push({distance:r.minX-i.maxX,box1:r,box2:i,points:[{x:r.minX,y:r.minY+r.height/2},{x:i.maxX,y:r.minY+r.height/2},{x:i.maxX,y:i.minY+i.height/2}]}),r.maxX<i.minX&&a.push({distance:i.minX-r.maxX,box1:r,box2:i,points:[{x:r.maxX,y:r.minY+r.height/2},{x:i.minX,y:r.minY+r.height/2},{x:i.minX,y:i.minY+i.height/2}]}),r.minY>i.maxY&&a.push({box1:r,box2:i,distance:r.minY-i.maxY,points:[{x:r.minX+r.width/2,y:r.minY},{x:r.minX+r.width/2,y:i.maxY},{x:i.minX+i.width/2,y:i.maxY}]}),r.maxY<i.minY&&a.push({box1:r,box2:i,distance:i.minY-r.maxY,points:[{x:r.minX+r.width/2,y:r.maxY},{x:r.minX+r.width/2,y:i.minY},{x:i.minX+i.width/2,y:i.minY}]});let o=r.minX>=i.minX&&r.maxX<=i.maxX&&r.minY>=i.minY&&r.maxY<=i.maxY;if(o&&(a.push({distance:r.minX-i.minX,box1:r,box2:i,points:[{x:r.minX,y:r.minY+r.height/2},{x:i.minX,y:r.minY+r.height/2},{x:i.minX,y:i.minY+i.height/2}]}),a.push({distance:i.maxX-r.maxX,box1:r,box2:i,points:[{x:r.maxX,y:r.minY+r.height/2},{x:i.maxX,y:r.minY+r.height/2},{x:i.maxX,y:i.minY+i.height/2}]}),a.push({box1:r,box2:i,distance:r.minY-i.minY,points:[{x:r.minX+r.width/2,y:r.minY},{x:r.minX+r.width/2,y:i.minY},{x:i.minX+i.width/2,y:i.minY}]}),a.push({box1:r,box2:i,distance:i.maxY-r.maxY,points:[{x:r.minX+r.width/2,y:r.maxY},{x:r.minX+r.width/2,y:i.maxY},{x:i.minX+i.width/2,y:i.maxY}]})),a.length===0&&!o){let e=r.minX<i.maxX&&r.maxX>i.minX,t=r.minY<i.maxY&&r.maxY>i.minY;if(e&&t){let e=(Math.max(r.minY,i.minY)+Math.min(r.maxY,i.maxY))/2,t=(Math.max(r.minX,i.minX)+Math.min(r.maxX,i.maxX))/2;r.minX<i.minX?a.push({distance:i.minX-r.minX,box1:r,box2:i,points:[{x:r.minX,y:e},{x:i.minX,y:e},{x:i.minX,y:e}]}):a.push({distance:r.minX-i.minX,box1:r,box2:i,points:[{x:r.minX,y:e},{x:i.minX,y:e},{x:i.minX,y:e}]}),r.maxX>i.maxX?a.push({distance:r.maxX-i.maxX,box1:r,box2:i,points:[{x:i.maxX,y:e},{x:r.maxX,y:e},{x:i.maxX,y:e}]}):a.push({distance:i.maxX-r.maxX,box1:r,box2:i,points:[{x:r.maxX,y:e},{x:i.maxX,y:e},{x:i.maxX,y:e}]}),r.minY<i.minY?a.push({box1:r,box2:i,distance:i.minY-r.minY,points:[{x:t,y:r.minY},{x:t,y:i.minY},{x:t,y:i.minY}]}):a.push({box1:r,box2:i,distance:r.minY-i.minY,points:[{x:t,y:r.minY},{x:t,y:i.minY},{x:t,y:i.minY}]}),r.maxY>i.maxY?a.push({box1:r,box2:i,distance:r.maxY-i.maxY,points:[{x:t,y:i.maxY},{x:t,y:r.maxY},{x:t,y:i.maxY}]}):a.push({box1:r,box2:i,distance:i.maxY-r.maxY,points:[{x:t,y:r.maxY},{x:t,y:i.maxY},{x:t,y:i.maxY}]})}}JSON.stringify(ne)!==JSON.stringify(a)&&re(a)},[e,t]);d.useEffect(()=>{e.distanceGuidesVisible?ye():ne&&re(null)},[e.distanceGuidesVisible,ye,e.selectedShapes.map(e=>`${e.x},${e.y},${e.width},${e.height},${e.rotation}`).join(`|`)]);let be=d.useRef(!1);d.useEffect(()=>{let e,t=F.current?.closest(`.polotno-workspace-inner`),n=()=>{be.current=!0,clearTimeout(e),e=setTimeout(()=>{be.current=!1},300)};return t?.addEventListener(`scroll`,n),()=>{clearTimeout(e),t?.removeEventListener(`scroll`,n)}},[]),d.useEffect(()=>{let e=P.current;if(!e)return;let t=e.container(),n=e=>{var t,n;e.touches.length>=2&&((t=N.current)!=null&&t.isDragging()&&N.current.stopDrag(),(n=N.current)==null||n.nodes().forEach(e=>{e.isDragging()&&e.stopDrag()}))};return t.addEventListener(`touchstart`,n,{passive:!0}),t.addEventListener(`touchmove`,n,{passive:!0}),()=>{t.removeEventListener(`touchstart`,n),t.removeEventListener(`touchmove`,n)}},[]);let xe=n=>{if(e.activePage!==t&&t.select(),be.current||ge.current)return;let r=n.evt.ctrlKey||n.evt.metaKey||n.evt.shiftKey,i=n.target.findAncestor(`.elements-container`),a=n.target.findAncestor(`.page-abs-container`),o=n.target.findAncestor(`Transformer`);if(!(r||i||o||a||he.visible)){e.selectElements([]);return}let s=n.target.findAncestor(`.element-container`,!0)?.findOne(`.element`)||n.target.findAncestor(`.element`,!0),c=e.getElementById(s?.id())?.top?.id,l=e.selectedElementsIds.indexOf(c)>=0,u=n.target.findAncestor(`.page-container`,!0);c&&r&&!l?e.selectElements(e.selectedElementsIds.concat([c])):c&&r&&l?e.selectElements(e.selectedElementsIds.filter(e=>e!==c)):!c||r||l?u?e.selectPages([t.id]):e.selectPages([]):e.selectElements([c])};vb(N,e,{stroke:_,strokeWidth:v,dash:y});let Se=e.activePage===t,Ce=e._selectedPagesIds.includes(t.id),we=l?.PageControls,Te=l?.Tooltip,Ee=l?.ContextMenu,De=1/e.scale,Oe=0/e.scale;return d.createElement(`div`,{ref:F,onDragOver:e=>e.preventDefault(),onDrop:n=>{if(n.preventDefault(),!P.current)return;P.current.setPointersPositions(n);let r=P.current.findOne(`.elements-container`)?.getRelativePointerPosition(),i=P.current.getPointerPosition(),a=P.current.getAllIntersections(i).map(e=>e.findAncestor(`.element`,!0)).filter(Boolean),o=[...new Set(a.reverse())].map(t=>e.getElementById(t.id())).filter(e=>!!e),s=o[0];SA&&r&&(SA(r,s,{elements:o,page:t}),SA=null)},style:{position:`relative`,width:n+`px`,height:r+`px`,overflow:`hidden`,flexShrink:0},className:`polotno-page-container`+(Se?` active-page`:``)},d.createElement(nf,{ref:P,width:Math.min(n,p.width+200),height:Math.min(p.height+200,r),onClick:xe,onTap:xe,onContextMenu:t=>{t.evt.preventDefault();let n=t.target.findAncestor(`.element`,!0),r=e.getElementById(n?.id())?.top?.id;r?e.selectedElementsIds.indexOf(r)>=0||e.selectElements([r]):e.selectElements([]),se.open({x:t.evt.clientX,y:t.evt.clientY})},onMouseDown:ve,onMouseMove:t=>{if(!e.distanceGuidesVisible&&!t.evt.altKey){ne&&re(null);return}ye(t.target.findAncestor(`.element`,!0)?.id())},onDragStart:t=>{var n;let r=t.target.getStage();if(r&&r.getPointersPositions().length>=2){t.target.stopDrag();return}let i=t.target.findAncestor(`.element`,!0);if(i){let r=e.getElementById(i?.id())?.top?.id;!(e.selectedElementsIds.indexOf(r)>=0)&&r&&(e.selectElements([r]),t.target.stopDrag(),t.target.startDrag(t),(n=N.current)==null||n.startDrag(t))}ne&&re(null)},pageId:t.id,style:{position:`absolute`,overflow:`hidden`,top:0,left:0}},d.createElement(Gd,null,d.createElement(pA,{width:n,height:r,fill:a}),d.createElement(Kd,{x:j,y:M,scaleX:e.scale,scaleY:e.scale,name:`page-container`},d.createElement(Kd,{name:`page-container-2`},d.createElement(Kd,{name:`page-background-group`,x:O,y:O},d.createElement(gA,{x:-t.bleed,y:-t.bleed,width:t.computedWidth+2*t.bleed,height:t.computedHeight+2*t.bleed,background:t.background,transparencyBackgroundColor:o,name:`page-background`,preventDefault:!1,scale:e.scale})),d.createElement(Kd,{x:O,y:O,name:`elements-container`,listening:!e.isPlaying},d.createElement(Jd,{name:`elements-area`,width:t.computedWidth,height:t.computedHeight,listening:!1}),d.createElement(bA,{elements:t.children,store:e})),d.createElement(Jd,{stroke:u,name:`bleed`,strokeWidth:t.bleed,x:t.bleed/2,y:t.bleed/2,width:t.computedWidth+t.bleed,height:t.computedHeight+t.bleed,listening:!1,visible:t.bleed>0&&e.bleedVisible,hideInExport:!0}),iO()===TA&&d.createElement(EA,{name:`hit-detection`,x:-De/2-Oe,y:-De/2-Oe,width:k+De+2*Oe,height:A+De+2*Oe}))),d.createElement(Yd,{name:`workspace-background`,points:[0,0,n,0,n,r,0,r,0,0,j,M,j,r-M,n-j,r-M,n-j,M,j,M],listening:!1,closed:!0,fill:a}),d.createElement(Kd,{x:j,y:M,scaleX:e.scale,scaleY:e.scale},d.createElement(Jd,{name:`page-highlight`,hideInExport:!0,x:-De/2-Oe,y:-De/2-Oe,width:k+De+2*Oe,height:A+De+2*Oe,stroke:Ce?c:s,strokeWidth:2,listening:!1,strokeScaleEnabled:!1})),d.createElement(Kd,{x:j+O*e.scale,y:M+O*e.scale,scaleX:e.scale,scaleY:e.scale,name:`page-abs-container`},d.createElement(ef,{ref:N,rotateAnchorAngle:ae,onDragStart:n=>{var r;let i=n.target.getStage();i&&i.getPointersPositions().length>=2?n.target.stopDrag():((r=n.evt)!=null&&r.altKey&&f&&e.selectedElements.forEach(e=>{let n=e.clone({},{skipSelect:!0}),r=t.children.indexOf(e);t.setElementZIndex(n.id,r)}),te.current=!0,e.history.startTransaction())},onDragEnd:()=>{te.current&&=(e.history.endTransaction(),!1),me()},onTransformStart:()=>{e.history.startTransaction(),re(null)},boundBoxFunc:(t,n)=>{let r=Math.abs(n.width)<1||Math.abs(n.height)<1,i=Math.abs(t.width)<1||Math.abs(t.height)<1;if(r&&!i)return t;let a=e.selectedElements;if(a.length===1&&a[0]?.type===`table`){let e=a[0],r=Math.abs(t.width),i=Math.abs(t.height);if(r>0&&i>0){let a=Math.abs(n.width)/r,o=Math.abs(n.height)/i,s=e.width*a,c=e.height*o;if(s<e.minWidth||c<e.minHeight)return t}}return n},onTransform:e=>{let t=N.current.nodes(),n=t[t.length-1];e.target===n&&setTimeout(()=>{pe()},0)},onTransformEnd:t=>{I({}),e.history.endTransaction(),me()},visible:!e.isPlaying}),ne&&ne.map(({points:t,distance:n,box1:r,box2:i},a)=>d.createElement(`Group`,{name:`distances-container`,hideInExport:!0,key:a,listening:!1},d.createElement(`Rect`,Object.assign({},r,{stroke:S,strokeWidth:1,strokeScaleEnabled:!1})),d.createElement(`Rect`,Object.assign({},i,{stroke:S,strokeWidth:1,strokeScaleEnabled:!1})),d.createElement(`Line`,{points:[t[0].x,t[0].y,t[1].x,t[1].y],stroke:S,strokeWidth:1,strokeScaleEnabled:!1}),d.createElement(`Line`,{points:[t[1].x,t[1].y,t[2].x,t[2].y],stroke:S,strokeWidth:1,strokeScaleEnabled:!1}),d.createElement(`Label`,{x:(t[0].x+t[1].x)/2,y:(t[0].y+t[1].y)/2,offsetY:-10,scaleX:1/e.scale,scaleY:1/e.scale},d.createElement(`Tag`,{cornerRadius:5,fill:C,pointerDirection:`down`}),d.createElement(`Text`,{align:`center`,verticalAlign:`middle`,fill:w,padding:5,text:wO({unit:e.unit,dpi:e.dpi,px:n})})))),t._rendering&&d.createElement(`Group`,null,d.createElement(`Rect`,{width:k,height:A,fill:`rgba(255,255,255,0.9)`}),d.createElement(`Text`,{text:`Rendering...`,fontSize:60,width:k,height:A,align:`center`,verticalAlign:`middle`})),Te&&d.createElement(Te,{components:l,store:e,page:t,stageRef:P,tooltipSafeArea:E}),Ee&&d.createElement(cf,null,d.createElement(Ee,Object.assign({components:l,store:e},se.props)))),d.createElement(rA,{store:e,page:t,width:n,height:r,scale:e.scale,xPadding:j,yPadding:M,bleed:O}),d.createElement(yA,Object.assign({},ie,{store:e,tagFill:b,textFill:x})),d.createElement(_A,{selection:he,fill:m,stroke:h,strokeWidth:g}),oO()>0&&d.createElement(`Group`,{hideInExport:!0},d.createElement(AA,{name:`cache-bounds`,x:n-(oO()===1?250:210),y:r-(oO()===1?95:45)}),d.createElement(AA,{name:`cache-bounds-t`,x:10,y:10})),sO()&&d.createElement(`Text`,{text:`Powered by polotno.com`,fontSize:14,fill:`rgba(0,0,0,0.6)`,x:n-170,y:r-18,onMouseEnter:e=>{e.target.getStage().container().style.cursor=`pointer`},onMouseLeave:e=>{e.target.getStage().container().style.cursor=``},onTouchStart:e=>{e.cancelBubble=!0},onMouseDown:e=>{e.cancelBubble=!0},onClick:()=>{window.open(`https://polotno.com`)},onTap:()=>{window.open(`https://polotno.com`)}}),d.createElement(Kd,{name:`line-guides`}))),ee&&we&&d.createElement(we,{store:e,page:t,xPadding:j,yPadding:M,layout:T}))}),MA=qy(`div`,d.forwardRef)`
291
291
  position: absolute;
292
292
  top: 0;
293
293
  left: 0;
294
294
  pointer-events: none;
295
- `,AA=Wy(`div`,d.forwardRef)`
295
+ `,NA=qy(`div`,d.forwardRef)`
296
296
  height: 14px;
297
297
  position: sticky;
298
298
  font-size: 8px;
@@ -303,7 +303,7 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
303
303
  border-bottom: 1px solid grey;
304
304
  background-color: #e8e8e8;
305
305
  overflow: hidden;
306
- `,jA=Wy(`div`,d.forwardRef)`
306
+ `,PA=qy(`div`,d.forwardRef)`
307
307
  left: 0;
308
308
  width: 14px;
309
309
  position: sticky;
@@ -313,11 +313,11 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
313
313
  border-right: 1px solid grey;
314
314
  background-color: #e8e8e8;
315
315
  overflow: hidden;
316
- `,MA=Wy(`div`,d.forwardRef)`
316
+ `,FA=qy(`div`,d.forwardRef)`
317
317
  position: absolute;
318
318
  border-left: 1px solid grey;
319
319
  padding-left: 2px;
320
- `,NA=Wy(`div`,d.forwardRef)`
320
+ `,IA=qy(`div`,d.forwardRef)`
321
321
  position: absolute;
322
322
  left: 14px;
323
323
  border-left: 1px solid grey;
@@ -325,8 +325,8 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
325
325
  transform: rotate(90deg);
326
326
  transform-origin: left top;
327
327
  overflow: hidden;
328
- `,PA=[.1,.2,.5,1,2,5,10,20,25,50,100,200,500,1e3,2e3,5e3,1e4],FA=sa(({store:e,width:t,height:n,pageSizes:r,layout:i=`vertical`,renderOnlyActivePage:a,rulerBackgroundColor:o,rulerTextColor:s,rulerBorderColor:c,rulerBorderSize:l,rulerTickColor:u,rulerTickSize:f})=>{let p=d.useRef(null);if(!e.activePage)return null;let m=i===`horizontal`,h=e.activePage,g=(e.bleedVisible&&h.bleed,h.computedWidth*e.scale),_=h.computedHeight*e.scale,v=(t-g)/2,y=(n-_)/2,b=(x=t=>bO({unitVal:t,dpi:e.dpi,unit:e.unit})*e.scale,PA.find(e=>x(e)>30)||1e4);var x;let S=bO({unitVal:b,dpi:e.dpi,unit:e.unit})*e.scale,C=Math.round(g/S)+1,w=Math.round(_/S)+1,T=ob(e.selectedShapes),E=o||`#e8e8e8`,D=s||`grey`,O=c||`grey`,k=l??1,A=u||`grey`,j=f??1;return d.createElement(kA,{ref:p,className:`polotno-rulers`,style:{display:`flex`,flexDirection:`column`}},m?d.createElement(d.Fragment,null,d.createElement(`div`,{style:{display:`flex`,flexDirection:`row`,position:`sticky`,top:0,zIndex:1}},d.createElement(`div`,{className:`polotno-ruler-corner`,style:{width:`14px`,height:`14px`,flexShrink:0,backgroundColor:E,borderRight:`${k}px solid ${O}`,borderBottom:`${k}px solid ${O}`,position:`sticky`,left:0,zIndex:2}}),(a?[e.activePage]:e.pages).map((n,i)=>{if(!n)return null;let a=r?r[i]:t,o=(a-n.computedWidth*e.scale)/2;return d.createElement(AA,{key:n.id,style:{width:a+`px`,flexShrink:0,position:`relative`,backgroundColor:E,color:D,borderBottom:`${k}px solid ${O}`},className:`polotno-x-ruler`},[...Array(C)].map((t,n)=>d.createElement(MA,{key:n,className:`polotno-ruler-tick`,style:{left:o+n*S+`px`,width:S+`px`,borderLeft:`${j}px solid ${A}`}},e.unit===`px`||b>=1?Math.round(b*n):(b*n).toFixed(1))),e.selectedShapes[0]?.page===n&&d.createElement(`div`,{className:`polotno-ruler-selection`,style:{position:`absolute`,left:o+T.x*e.scale+`px`,height:`14px`,width:T.width*e.scale,backgroundColor:`rgba(0,0,0,0.15)`}}))})),d.createElement(jA,{style:{height:n+`px`,position:`sticky`,left:0,marginTop:`-14px`,backgroundColor:E,color:D,borderRight:`${k}px solid ${O}`},className:`polotno-y-ruler`},[...Array(w)].map((t,n)=>d.createElement(NA,{key:n,className:`polotno-ruler-tick`,style:{top:y+n*S+`px`,width:S+`px`,borderLeft:`${j}px solid ${A}`}},e.unit===`px`||b>=1?Math.round(b*n):(b*n).toFixed(1))),!!e.selectedShapes.length&&d.createElement(`div`,{className:`polotno-ruler-selection`,style:{position:`absolute`,top:y+T.y*e.scale+`px`,width:`14px`,height:T.height*e.scale,backgroundColor:`rgba(0,0,0,0.15)`}}))):d.createElement(d.Fragment,null,d.createElement(AA,{style:{width:t+`px`,backgroundColor:E,color:D,borderBottom:`${k}px solid ${O}`},className:`polotno-x-ruler`},[...Array(C)].map((t,n)=>d.createElement(MA,{key:n,className:`polotno-ruler-tick`,style:{left:v+n*S+`px`,width:S+`px`,borderLeft:`${j}px solid ${A}`}},e.unit===`px`||b>=1?Math.round(b*n):(b*n).toFixed(1))),!!e.selectedShapes.length&&d.createElement(`div`,{className:`polotno-ruler-selection`,style:{position:`absolute`,left:v+T.x*e.scale+`px`,height:`14px`,width:T.width*e.scale,backgroundColor:`rgba(0,0,0,0.15)`}})),(a?[e.activePage]:e.pages).map((t,i)=>{if(!t)return null;let a=r?r[i]:n,o=(a-t.computedHeight*e.scale)/2,s=i===0?14:0;return d.createElement(jA,{key:t.id,style:{height:a-s+`px`,backgroundColor:E,color:D,borderRight:`${k}px solid ${O}`},className:`polotno-y-ruler`},[...Array(w)].map((t,n)=>d.createElement(NA,{key:n,className:`polotno-ruler-tick`,style:{top:o+n*S-s+`px`,width:S+`px`,borderLeft:`${j}px solid ${A}`}},e.unit===`px`||b>=1?Math.round(b*n):(b*n).toFixed(1))),e.selectedShapes[0]?.page===t&&d.createElement(`div`,{className:`polotno-ruler-selection`,style:{position:`absolute`,top:o+T.y*e.scale-s+`px`,width:`14px`,height:T.height*e.scale,backgroundColor:`rgba(0,0,0,0.15)`}}))})))}),IA=sa(({audio:e,store:t})=>{let[n,r]=function(e){let[t,n]=d.useState(null),[r,i]=d.useState(`loading`);return d.useEffect(()=>{let t=new Audio(e),r=()=>{i(`loaded`),n(t)},a=()=>{i(`failed`),n(null)};return t.addEventListener(`canplay`,r),t.addEventListener(`error`,a),()=>{t.removeEventListener(`canplay`,r),t.removeEventListener(`error`,a)}},[e]),[t,r]}(e.src);return d.useEffect(()=>{n&&t.history.ignore(()=>{e.set({duration:1e3*n.duration})})},[n,e,t.history]),d.useEffect(()=>{if(!n)return;let r=()=>{n.currentTime=e.startTime*e.duration/1e3},i=()=>{let t=e.endTime*e.duration/1e3;n.currentTime>=t&&(n.pause(),n.currentTime=e.startTime*e.duration/1e3)};n.addEventListener(`ended`,r),n.addEventListener(`timeupdate`,i);let a=Gn(()=>{let r=t.animatedElementsIds;if(r.length&&!r.includes(e.id))return;let i=t.currentTime-e.delay,a=e.duration*(e.endTime-e.startTime),o=i>=0&&i<a;if(!t.isPlaying||t.animatedElementsIds.length!==0||!o){n.pause();return}n.volume=e.volume,n.paused&&n.play();let s=i%a/1e3+e.startTime*e.duration/1e3,c=n.currentTime;Math.abs(c-s)>.5&&s!==c&&(n.currentTime=s)});return()=>{n.pause(),n.removeEventListener(`ended`,r),n.removeEventListener(`timeupdate`,i),a()}},[t.isPlaying,e.startTime,e.endTime,e.volume,n]),null}),LA={data:[],pageId:``},RA=`polotno_clipboard`,zA=(e,t)=>{LA={data:JSON.parse(JSON.stringify(e)),pageId:t||``};try{localStorage.setItem(RA,JSON.stringify(e)),localStorage.setItem(RA+`_page`,t||``)}catch{}},BA=()=>{try{let e=localStorage.getItem(RA),t=localStorage.getItem(RA+`_page`);if(e)return{data:JSON.parse(e),pageId:t}}catch{}return LA},VA=e=>{e.selectedElements.length!==0&&zA(e.selectedElements.map(e=>e.toJSON()),e.activePage?.id)},HA=e=>{zA(e.selectedElements.map(e=>e.toJSON()),e.activePage?.id);let t=e.selectedElements.filter(e=>e.removable).map(e=>e.id);e.deleteElements(t)},UA=e=>{e.history.transaction(()=>{let t=0,n=0,{data:r,pageId:i}=BA();if(i===e.activePage?.id)t=e.width/20,n=e.height/20;else{let i=[];Bk({children:r},e=>{e.type!==`group`&&i.push(e)});let a=ob(i);a.maxX>e.width&&(t=-a.minX),a.maxY>e.height&&(n=-a.minY)}let a=[];Bk({children:r},e=>{delete e.id,e.type!==`group`&&(e.x+=t,e.y+=n)}),r.forEach(t=>{let n=e.activePage?.addElement(t);n&&a.push(n.id)}),zA(r,e.activePage?.id),e.selectElements(a)})};function WA(e,t){let n=[];e.forEach(e=>{if(!1===e.removable)return;let t=e.clone();e.type===`group`?t.children.forEach(e=>{e.set({x:e.x+50,y:e.y+50})}):t.set({x:e.x+50,y:e.y+50}),n.push(t.id)}),t.selectElements(n)}var GA=e=>{if(e.type!==`group`)return ab(e);let t=1/0,n=1/0,r=-1/0,i=-1/0;return e.children.forEach(e=>{let a=GA(e);t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.width),i=Math.max(i,a.y+a.height)}),{x:t,y:n,width:r-t,height:i-n}},KA=(e,t,n)=>{if(e.type!==`group`){let r=ab(e),i=t-r.x,a=n-r.y;e.set({x:e.x+i,y:e.y+a})}else{let r=t-GA(e).x,i=n-GA(e).y;e.children.forEach(e=>{let t=GA(e);KA(e,t.x+r,t.y+i)})}};function qA(e){let t=e.activePage?.computedWidth;e.selectedElements.forEach(e=>{t=Math.min(t,GA(e).x)}),e.selectedElements.length===1&&(t=0),e.selectedElements.forEach(e=>{let n=GA(e);KA(e,n.x-n.x+t,n.y)})}function JA(e){let t=0;e.selectedElements.forEach(e=>{let n=GA(e);t=Math.max(t,n.x+n.width)}),e.selectedElements.length===1&&(t=e.activePage?.computedWidth),e.selectedElements.forEach(e=>{let n=GA(e);KA(e,t-n.width,n.y)})}function YA(e){let t=e.activePage?.computedHeight;e.selectedElements.forEach(e=>{t=Math.min(t,GA(e).y)}),e.selectedElements.length===1&&(t=0),e.selectedElements.forEach(e=>{let n=GA(e);KA(e,n.x,n.y-n.y+t)})}function XA(e){let t=e.activePage?.computedHeight,n=0;e.selectedElements.forEach(e=>{let r=GA(e);t=Math.min(t,r.y),n=Math.max(n,r.y+r.height)});let r=(n+t)/2;e.selectedElements.length===1&&(r=e.activePage?.computedHeight/2),e.selectedElements.forEach(e=>{let t=GA(e);KA(e,t.x,r-t.height/2)})}function ZA(e){let t=0;e.selectedElements.forEach(e=>{let n=GA(e);t=Math.max(t,n.y+n.height)}),e.selectedElements.length===1&&(t=e.activePage?.computedHeight),e.selectedElements.forEach(e=>{let n=GA(e);KA(e,n.x,t-n.height)})}function QA(e){let t=e.activePage?.computedWidth,n=0;e.selectedElements.forEach(e=>{let r=GA(e);t=Math.min(t,r.x),n=Math.max(n,r.x+r.width)});let r=(n+t)/2;e.selectedElements.length===1&&(r=e.activePage?.computedWidth/2),e.selectedElements.forEach(e=>{let t=GA(e);KA(e,r-t.width/2,t.y)})}var $A=`rgba(191, 191, 191, 100)`;function ej(e,t,n){let r=e.getCell(t,n);r&&e.focusCell(r.id)}function tj(e,t,n){let r=e.getCell(t,n);r&&e.enterCellEdit(r.id)}function nj(e,t){var n,r,i,a,o,s,c,l;let u=function(e){if(e.selectedElements.length!==1)return null;let t=e.selectedElements[0];return t.type===`table`?t:null}(t);if(u&&function(e,t){let n=t._focusedCellIds.length>0,r=!!t._editingCellId;if(!n&&!r)return!1;if(r){if(e.key===`Escape`)return e.preventDefault(),t.exitCellEdit(),!0;if(e.key===`Tab`){e.preventDefault();let n=t.editingCell;if(t.exitCellEdit(),n)if(e.shiftKey){let e=n.col-1,r=n.row;e<0&&(--r,e=t.cols-1),r<0&&(r=t.rows-1,e=t.cols-1),tj(t,r,e)}else{let e=n.col+1,r=n.row;e>=t.cols&&(r+=1,e=0),r>=t.rows&&(r=0,e=0),tj(t,r,e)}return!0}if(e.metaKey||e.ctrlKey){let n=t.editingCell;if(n){if(e.key===`b`)return e.preventDefault(),n.set({fontWeight:n.fontWeight===`bold`?`normal`:`bold`}),!0;if(e.key===`i`)return e.preventDefault(),n.set({fontStyle:n.fontStyle===`italic`?`normal`:`italic`}),!0;if(e.key===`u`){e.preventDefault();let t=n.textDecoration.split(` `).filter(Boolean),r=t.includes(`underline`);return n.set({textDecoration:r?t.filter(e=>e!==`underline`).join(` `):[...t,`underline`].join(` `)}),!0}}}return!0}if(e.key===`Escape`)return e.preventDefault(),t.clearCellFocus(),!0;let i=t.focusedCells[0];if(!i)return!1;let a=i.row,o=i.col;if(e.key===`Enter`)return e.preventDefault(),t.enterCellEdit(i.id),!0;if(e.key===`Tab`){if(e.preventDefault(),e.shiftKey){let e=o-1,n=a;e<0&&(--n,e=t.cols-1),n<0&&(n=t.rows-1,e=t.cols-1),ej(t,n,e)}else{let e=o+1,n=a;e>=t.cols&&(n+=1,e=0),n>=t.rows&&(n=0,e=0),ej(t,n,e)}return!0}if(e.key===`ArrowRight`||e.key===`ArrowLeft`||e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),e.shiftKey){let n=function(e){let t=e.cells.find(t=>t.id===e._anchorCellId);if(!t)return null;let n=e.focusedCells;if(n.length<=1)return{row:t.row,col:t.col};let r=1/0,i=-1,a=1/0,o=-1;for(let e of n)e.row<r&&(r=e.row),e.row>i&&(i=e.row),e.col<a&&(a=e.col),e.col>o&&(o=e.col);return{row:t.row===r?i:r,col:t.col===a?o:a}}(t)||{row:a,col:o},r=n.row,i=n.col;e.key===`ArrowRight`&&(i=Math.min(n.col+1,t.cols-1)),e.key===`ArrowLeft`&&(i=Math.max(n.col-1,0)),e.key===`ArrowDown`&&(r=Math.min(n.row+1,t.rows-1)),e.key===`ArrowUp`&&(r=Math.max(n.row-1,0)),t.focusCellRange(r,i)}else e.key===`ArrowRight`&&ej(t,a,Math.min(o+1,t.cols-1)),e.key===`ArrowLeft`&&ej(t,a,Math.max(o-1,0)),e.key===`ArrowDown`&&ej(t,Math.min(a+1,t.rows-1),o),e.key===`ArrowUp`&&ej(t,Math.max(a-1,0),o);return!0}if(e.key===`Delete`||e.key===`Backspace`)return e.preventDefault(),t.focusedCells.forEach(e=>{e.set({text:``})}),!0;let s=e.ctrlKey||e.metaKey;if(s&&e.code===`KeyC`){e.preventDefault();let n=t.focusedCells.map(e=>Qf(e.text));return navigator.clipboard.writeText(n.join(`
329
- `)),!0}return s&&e.code===`KeyV`?(e.preventDefault(),navigator.clipboard.readText().then(e=>{let n=t.focusedCells[0];n&&n.set({text:e})}),!0):!(!s||e.code!==`KeyA`||(e.preventDefault(),t.cells.forEach(e=>{t.focusCell(e.id,!0)}),0))}(e,u)||document.activeElement?.tagName===`INPUT`||document.activeElement?.tagName===`TEXTAREA`||document.activeElement?.contentEditable===`true`)return;let d=document.querySelector(`.polotno-workspace-container`);if(document.activeElement!==d&&!d?.contains(document.activeElement)){let e=window.getSelection();if(e&&e.toString().length>0)return}let f=t.selectedElements.filter(e=>e.removable).map(e=>e.id);e.keyCode!==46&&e.keyCode!==8||t.deleteElements(f);let p=e.ctrlKey||e.metaKey,m=e.shiftKey,h=e.altKey;if(e.key===`Escape`){e.preventDefault(),t.tool===`draw`?t.setTool(`selection`):t.selectElements([]);return}if(!p||m||e.key.toLowerCase()!==`z`&&e.key.toLowerCase()!==`y`||(e.preventDefault(),t.history.undo()),p&&m&&(e.key.toLowerCase()===`z`||e.key.toLowerCase()===`y`)&&(e.preventDefault(),t.history.redo()),p&&e.code===`KeyA`){e.preventDefault();let n=(t.activePage?.children.filter(e=>e.selectable))?.map(e=>e.id)||[];t.selectElements(n)}if(p&&e.code===`KeyC`&&(e.preventDefault(),VA(t)),p&&e.code===`KeyX`&&(e.preventDefault(),HA(t)),p&&e.code===`KeyV`&&(e.preventDefault(),UA(t)),e.code===`ArrowDown`){e.preventDefault();let n=e.shiftKey?10:1;t.selectedShapes.forEach(e=>{e.draggable&&e.set({y:e.y+n})})}if(e.code===`ArrowUp`){e.preventDefault();let n=e.shiftKey?10:1;t.selectedShapes.forEach(e=>{e.draggable&&e.set({y:e.y-n})})}if(e.code===`ArrowLeft`){e.preventDefault();let n=e.shiftKey?10:1;t.selectedShapes.forEach(e=>{e.draggable&&e.set({x:e.x-n})})}if(e.code===`ArrowRight`){e.preventDefault();let n=e.shiftKey?10:1;t.selectedShapes.forEach(e=>{e.draggable&&e.set({x:e.x+n})})}if(p&&e.code===`KeyG`){e.preventDefault();let n=t.selectedElements[0];if(n&&n.type===`group`){let e=n;t.ungroupElements([e.id])}else t.groupElements(t.selectedElements.map(e=>e.id))}if(p&&e.code===`KeyD`&&(e.preventDefault(),WA(t.selectedElements,t)),e.code===`KeyT`&&!p){e.preventDefault();let r=t.width/2,i=t.width/2-r/2,a=t.height/2-30/2,o=(t.width+t.height)/2160;(n=t.activePage)==null||n.addElement({type:`text`,x:i,y:a,width:r,fontSize:30*o,text:`Sample Text`,fontFamily:`Roboto`})}if(e.code===`KeyR`&&!p){e.preventDefault();let n={type:`figure`,x:t.width/4,y:t.height/4,width:300,height:300,fill:$A,stroke:`#0c0c0c`,strokeWidth:0,subType:`rect`};(r=t.activePage)==null||r.addElement(n)}if(e.code===`KeyL`&&!p){e.preventDefault();let n=(t.activePage?.computedWidth??0)/3,r={type:`line`,x:(t.activePage?.computedWidth??0)/2-n/2,y:(t.activePage?.computedHeight??0)/2,width:n,color:$A};(i=t.activePage)==null||i.addElement(r)}if(e.code===`KeyO`&&!p){e.preventDefault(),e.preventDefault();let n={type:`figure`,x:t.width/4,y:t.height/4,width:300,height:300,fill:$A,stroke:`#0c0c0c`,strokeWidth:0,subType:`circle`};(a=t.activePage)==null||a.addElement(n)}p&&e.code===`Equal`&&(e.preventDefault(),t.setScale(t.scale+.1)),p&&e.code===`Minus`&&(e.preventDefault(),t.setScale(t.scale-.1)),h&&(e.code===`KeyA`&&(e.preventDefault(),qA(t)),e.code===`KeyD`&&(e.preventDefault(),JA(t)),e.code===`KeyS`&&(e.preventDefault(),ZA(t)),e.code===`KeyW`&&(e.preventDefault(),YA(t)),e.code===`KeyV`&&(e.preventDefault(),XA(t)),e.code===`KeyH`&&(e.preventDefault(),QA(t))),e.code===`BracketRight`&&(e.preventDefault(),p?(o=t.activePage)==null||o.moveElementsUp(t.selectedElementsIds):(s=t.activePage)==null||s.moveElementsTop(t.selectedElementsIds)),e.code===`BracketLeft`&&(e.preventDefault(),p?(c=t.activePage)==null||c.moveElementsDown(t.selectedElementsIds):(l=t.activePage)==null||l.moveElementsBottom(t.selectedElementsIds))}var rj=L({toolbar:{duration:`Duration`,opacity:`Opacity`,effects:`Effects`,blur:`Blur`,curvedText:`Curved text`,curvePower:`Power`,temperature:`Temperature`,saturation:`Saturation`,contrast:`Contrast`,shadows:`Shadows`,white:`White`,black:`Black`,vibrance:`Vibrance`,textBackground:`Background`,backgroundCornerRadius:`Corner radius`,backgroundOpacity:`Opacity`,backgroundPadding:`Padding`,brightness:`Brightness`,filters:`Filters`,sepia:`Sepia`,grayscale:`Grayscale`,cold:`Cold`,natural:`Natural`,warm:`Warm`,textStroke:`Text Stroke`,shadow:`Shadow`,border:`Border`,cornerRadius:`Corner Radius`,copyStyle:`Copy style`,uppercase:`Uppercase`,position:`Position`,layering:`Layering`,toForward:`To Front`,up:`Forward`,down:`Backward`,toBottom:`To back`,alignLeft:`Align left`,alignCenter:`Align center`,alignRight:`Align right`,alignTop:`Align top`,alignMiddle:`Align middle`,alignBottom:`Align bottom`,flip:`Flip`,flipHorizontally:`Flip horizontally`,flipVertically:`Flip vertically`,fitToBackground:`Fit to page`,removeBackground:`Remove background`,removeBackgroundTitle:`Remove background from image`,cancelRemoveBackground:`Cancel`,confirmRemoveBackground:`Confirm`,crop:`Crop`,cropDone:`Done`,cropCancel:`Cancel`,clip:`Apply mask`,removeClip:`Remove mask`,removeMask:`Remove mask`,transparency:`Transparency`,lockedDescription:`Object is locked. Unlock it to allow changes from canvas.`,unlockedDescription:`Object is unlocked. Lock it to prevent changes from canvas.`,removeElements:`Remove elements`,duplicateElements:`Duplicate elements`,download:`Download`,saveAsImage:`Save as image`,saveAsPDF:`Save as PDF`,lineHeight:`Line height`,letterSpacing:`Letter spacing`,offsetX:`Offset X`,offsetY:`Offset Y`,color:`Color`,selectable:`Selectable`,draggable:`Draggable`,removable:`Removable`,resizable:`Resizable`,contentEditable:`Can change content`,styleEditable:`Can change style`,alwaysOnTop:`Always on top`,showInExport:`Show in export`,ungroupElements:`Ungroup`,groupElements:`Group`,lineSize:`Line size`,fade:`Fade`,move:`Move`,zoom:`Zoom`,animate:`Animate`,rotate:`Rotate`,none:`None`,bounce:`Bounce`,blink:`Blink`,strength:`Strength`,spaceEvenly:`Space evenly`,horizontalDistribution:`Horizontally`,verticalDistribution:`Vertically`,strokeWidth:`Stroke Width`,strokeSettings:`Stroke settings`,spacing:`Spacing`,volume:`Volume`,lineStyle:`Line style`,lineStartHead:`Line start`,lineEndHead:`Line end`,textDirection:`Text direction`,fontSize:`Font size`,fontFamily:`Font family`,textAlign:`Text align`,verticalAlign:`Vertical align`,bold:`Bold`,italic:`Italic`,underline:`Underline`,strikethrough:`Strikethrough`,cellBackground:`Cell background`,tableBorderSettings:`Border settings`,tableBorderColor:`Border color`,tableBorderWidth:`Border width`,tableBorderStyle:`Border style`,borderAllSides:`All sides`,borderTop:`Top`,borderBottom:`Bottom`,borderLeft:`Left`,borderRight:`Right`,borderNone:`No border`,tableStructure:`Table structure`,tableRows:`Rows`,tableColumns:`Columns`,insertRowAbove:`Insert row above`,insertRowBelow:`Insert row below`,deleteRow:`Delete row`,insertColumnLeft:`Insert column left`,insertColumnRight:`Insert column right`,deleteColumn:`Delete column`,distributeRowsEvenly:`Distribute rows evenly`,distributeColumnsEvenly:`Distribute columns evenly`,cellPadding:`Cell padding`,listFormat:`List`,colorPicker:{solid:`Solid`,linear:`Linear`,angle:`Angle`},aiText:{aiWrite:`AI write`,rewrite:`Rewrite`,shorten:`Shorten`,continue:`Continue writing`,proofread:`Proofread`,tones:`Tones`,friendly:`Friendly`,professional:`Professional`,humorous:`Humorous`,formal:`Formal`,customPrompt:`Custom prompt`,generatedResult:`Generated result`,cancel:`Cancel`,generate:`Generate`,back:`Back`,tryAgain:`Try Again`,insert:`Insert`,promptPlaceholder:`Describe what you want to generate`}},workspace:{noPages:`There are no pages yet...`,addPage:`Add page`,removePage:`Remove page`,duplicatePage:`Duplicate page`,moveUp:`Move up`,moveDown:`Move down`,moveLeft:`Move left`,moveRight:`Move right`},scale:{reset:`Reset`},error:{removeBackground:`Ops! Something went wrong. Background can not be removed.`},sidePanel:{templates:`Templates`,searchTemplatesWithSameSize:`Show templates with the same size`,searchPlaceholder:`Search...`,otherFormats:`Other formats`,noResults:`No results`,error:`Loading is failed...`,text:`Text`,uploadFont:`Upload font`,myFonts:`My fonts`,photos:`Photos`,videos:`Videos`,animations:`Animations`,effects:`Effects`,elements:`Elements`,shapes:`Shapes`,tables:`Tables`,lines:`Lines`,draw:`Draw`,upload:`Upload`,uploadImage:`Add file`,uploadTip:`Upload your assets`,background:`Background`,resize:`Resize`,layers:`Layers`,animate:`Animate`,layerTypes:{image:`Image`,text:`Text`,svg:`SVG`,line:`Line`,figure:`Figure`,group:`Group`},layersTip:`Elements on your active page:`,noLayers:`No elements on the page...`,namePlaceholder:`Type element name...`,useMagicResize:`Use magic resize`,clipImage:`Mask image`,width:`Width`,height:`Height`,magicResizeDescription:`Magic resize will automatically resize and move all elements on the canvas`,headerText:`Header`,createHeader:`Create header`,subHeaderText:`Sub Header`,createSubHeader:`Create sub header`,bodyText:`Body text`,createBody:`Create body text`},pagesTimeline:{pages:`Pages`,removePage:`Remove page`,addPage:`Add page`,duplicatePage:`Duplicate page`,removeAudio:`Remove audio`,duplicateAudio:`Duplicate audio`,muteAudio:`Mute`,unmuteAudio:`Unmute`,volume:`Volume`},contextMenu:{duplicate:`Duplicate`,remove:`Remove`,lock:`Lock`,unlock:`Unlock`,copy:`Copy`,paste:`Paste`,copyStyle:`Copy style`,moveUp:`Move up`,moveDown:`Move down`,moveBack:`Move back`,moveForward:`Move forward`}}),ij=e=>e&&typeof e==`object`;function aj(e,t){Object.keys(t).forEach(n=>{let r=e[n],i=t[n];ij(i)&&ij(r)?aj(r,i):e[n]=i})}function oj(e,t,n=``){Object.keys(t).forEach(r=>{let i=t[r],a=n?`${n}.${r}`:r;ij(i)?ij(e[r])?oj(e[r],i,a):console.warn(`Missing nested translation object at '${a}'`):e[r]===void 0&&console.warn(`Missing translation '${a}'`)})}Vn((e,{validate:t=!1}={})=>{t&&oj(e,rj),aj(rj,e)});var sj={},cj=e=>{let t=function(e,t){var n,r=t.split(`.`),i=e;for(n=0;n<r.length;++n){if(i[r[n]]==null)return;i=i[r[n]]}return i}(rj,e);if(t!==void 0)return t;sj[e]||(sj[e]=!0,console.warn(`Missing translation '${e}'`));let n=e.split(`.`),r=n[n.length-1]||` `;return r.charAt(0).toUpperCase()+r.slice(1)},lj=(e,t,n)=>Math.max(t,Math.min(n,e)),uj=(e,t)=>Math.sqrt((t.clientX-e.clientX)**2+(t.clientY-e.clientY)**2),dj=({store:e})=>d.createElement(`div`,{style:{position:`absolute`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,textAlign:`center`}},d.createElement(`p`,null,cj(`workspace.noPages`)),d.createElement(`button`,{onClick:()=>{e.addPage()}},cj(`workspace.addPage`))),fj=({width:e,height:t,xPadding:n,yPadding:r,backgroundColor:i})=>d.createElement(`div`,{style:{width:e+`px`,height:t+`px`,backgroundColor:i,paddingLeft:n+`px`,paddingRight:n+`px`,paddingTop:r+`px`,paddingBottom:r+`px`,flexShrink:0}},d.createElement(`div`,{style:{width:` 100%`,height:`100%`,backgroundColor:`white`}})),pj=[4,6],mj=sa(({store:e,layout:t=`vertical`,pageControlsEnabled:n,backgroundColor:r,transparencyBackgroundColor:i,pageBorderColor:a,activePageBorderColor:o,bleedColor:s,snapGuideStroke:c,snapGuideStrokeWidth:l,snapGuideDash:u,selectionRectFill:f,selectionRectStroke:p,selectionRectStrokeWidth:m,transformLabelFill:h,transformLabelTextFill:g,distanceGuideStroke:_,distanceLabelFill:v,distanceLabelTextFill:y,rulerBackgroundColor:b,rulerTextColor:x,rulerBorderColor:S,rulerBorderSize:C,rulerTickColor:w,rulerTickSize:T,components:E,onKeyDown:D,paddingX:O,paddingY:k,pageGap:A,altCloneEnabled:j=!0,visiblePagesOffset:M,renderOnlyActivePage:N,tooltipSafeArea:P})=>{let F=t===`horizontal`,ee=O??20,te=k??55,[ne,re]=d.useState({width:100,height:100}),ie=d.useRef(ne),I=d.useRef(null),ae=d.useRef(null),oe=d.useRef(0),se=e.bleedVisible?Math.max(0,...e.pages.map(e=>e.bleed)):0,ce=Math.max(...e.pages.map(e=>e.computedWidth)),le=Math.max(...e.pages.map(e=>e.computedHeight)),ue=e.activePage?.computedHeight||0,de=ce+2*se,fe=(N?ue:le)+2*se,pe=async({skipTimeout:t}={skipTimeout:!1})=>{if(t||await new Promise(e=>setTimeout(e,50)),I.current===null)return;let n=I.current.getBoundingClientRect();n.width!==0&&n.height!==0||(console.warn(`Polotno warning: <Workspace /> component can not automatically detect its size.
328
+ `,LA=[.1,.2,.5,1,2,5,10,20,25,50,100,200,500,1e3,2e3,5e3,1e4],RA=sa(({store:e,width:t,height:n,pageSizes:r,layout:i=`vertical`,renderOnlyActivePage:a,rulerBackgroundColor:o,rulerTextColor:s,rulerBorderColor:c,rulerBorderSize:l,rulerTickColor:u,rulerTickSize:f})=>{let p=d.useRef(null);if(!e.activePage)return null;let m=i===`horizontal`,h=e.activePage,g=(e.bleedVisible&&h.bleed,h.computedWidth*e.scale),_=h.computedHeight*e.scale,v=(t-g)/2,y=(n-_)/2,b=(x=t=>CO({unitVal:t,dpi:e.dpi,unit:e.unit})*e.scale,LA.find(e=>x(e)>30)||1e4);var x;let S=CO({unitVal:b,dpi:e.dpi,unit:e.unit})*e.scale,C=Math.round(g/S)+1,w=Math.round(_/S)+1,T=lb(e.selectedShapes),E=o||`#e8e8e8`,D=s||`grey`,O=c||`grey`,k=l??1,A=u||`grey`,j=f??1;return d.createElement(MA,{ref:p,className:`polotno-rulers`,style:{display:`flex`,flexDirection:`column`}},m?d.createElement(d.Fragment,null,d.createElement(`div`,{style:{display:`flex`,flexDirection:`row`,position:`sticky`,top:0,zIndex:1}},d.createElement(`div`,{className:`polotno-ruler-corner`,style:{width:`14px`,height:`14px`,flexShrink:0,backgroundColor:E,borderRight:`${k}px solid ${O}`,borderBottom:`${k}px solid ${O}`,position:`sticky`,left:0,zIndex:2}}),(a?[e.activePage]:e.pages).map((n,i)=>{if(!n)return null;let a=r?r[i]:t,o=(a-n.computedWidth*e.scale)/2;return d.createElement(NA,{key:n.id,style:{width:a+`px`,flexShrink:0,position:`relative`,backgroundColor:E,color:D,borderBottom:`${k}px solid ${O}`},className:`polotno-x-ruler`},[...Array(C)].map((t,n)=>d.createElement(FA,{key:n,className:`polotno-ruler-tick`,style:{left:o+n*S+`px`,width:S+`px`,borderLeft:`${j}px solid ${A}`}},e.unit===`px`||b>=1?Math.round(b*n):(b*n).toFixed(1))),e.selectedShapes[0]?.page===n&&d.createElement(`div`,{className:`polotno-ruler-selection`,style:{position:`absolute`,left:o+T.x*e.scale+`px`,height:`14px`,width:T.width*e.scale,backgroundColor:`rgba(0,0,0,0.15)`}}))})),d.createElement(PA,{style:{height:n+`px`,position:`sticky`,left:0,marginTop:`-14px`,backgroundColor:E,color:D,borderRight:`${k}px solid ${O}`},className:`polotno-y-ruler`},[...Array(w)].map((t,n)=>d.createElement(IA,{key:n,className:`polotno-ruler-tick`,style:{top:y+n*S+`px`,width:S+`px`,borderLeft:`${j}px solid ${A}`}},e.unit===`px`||b>=1?Math.round(b*n):(b*n).toFixed(1))),!!e.selectedShapes.length&&d.createElement(`div`,{className:`polotno-ruler-selection`,style:{position:`absolute`,top:y+T.y*e.scale+`px`,width:`14px`,height:T.height*e.scale,backgroundColor:`rgba(0,0,0,0.15)`}}))):d.createElement(d.Fragment,null,d.createElement(NA,{style:{width:t+`px`,backgroundColor:E,color:D,borderBottom:`${k}px solid ${O}`},className:`polotno-x-ruler`},[...Array(C)].map((t,n)=>d.createElement(FA,{key:n,className:`polotno-ruler-tick`,style:{left:v+n*S+`px`,width:S+`px`,borderLeft:`${j}px solid ${A}`}},e.unit===`px`||b>=1?Math.round(b*n):(b*n).toFixed(1))),!!e.selectedShapes.length&&d.createElement(`div`,{className:`polotno-ruler-selection`,style:{position:`absolute`,left:v+T.x*e.scale+`px`,height:`14px`,width:T.width*e.scale,backgroundColor:`rgba(0,0,0,0.15)`}})),(a?[e.activePage]:e.pages).map((t,i)=>{if(!t)return null;let a=r?r[i]:n,o=(a-t.computedHeight*e.scale)/2,s=i===0?14:0;return d.createElement(PA,{key:t.id,style:{height:a-s+`px`,backgroundColor:E,color:D,borderRight:`${k}px solid ${O}`},className:`polotno-y-ruler`},[...Array(w)].map((t,n)=>d.createElement(IA,{key:n,className:`polotno-ruler-tick`,style:{top:o+n*S-s+`px`,width:S+`px`,borderLeft:`${j}px solid ${A}`}},e.unit===`px`||b>=1?Math.round(b*n):(b*n).toFixed(1))),e.selectedShapes[0]?.page===t&&d.createElement(`div`,{className:`polotno-ruler-selection`,style:{position:`absolute`,top:o+T.y*e.scale-s+`px`,width:`14px`,height:T.height*e.scale,backgroundColor:`rgba(0,0,0,0.15)`}}))})))}),zA=sa(({audio:e,store:t})=>{let[n,r]=function(e){let[t,n]=d.useState(null),[r,i]=d.useState(`loading`);return d.useEffect(()=>{let t=new Audio(e),r=()=>{i(`loaded`),n(t)},a=()=>{i(`failed`),n(null)};return t.addEventListener(`canplay`,r),t.addEventListener(`error`,a),()=>{t.removeEventListener(`canplay`,r),t.removeEventListener(`error`,a)}},[e]),[t,r]}(e.src);return d.useEffect(()=>{n&&t.history.ignore(()=>{e.set({duration:1e3*n.duration})})},[n,e,t.history]),d.useEffect(()=>{if(!n)return;let r=()=>{n.currentTime=e.startTime*e.duration/1e3},i=()=>{let t=e.endTime*e.duration/1e3;n.currentTime>=t&&(n.pause(),n.currentTime=e.startTime*e.duration/1e3)};n.addEventListener(`ended`,r),n.addEventListener(`timeupdate`,i);let a=Gn(()=>{let r=t.animatedElementsIds;if(r.length&&!r.includes(e.id))return;let i=t.currentTime-e.delay,a=e.duration*(e.endTime-e.startTime),o=i>=0&&i<a;if(!t.isPlaying||t.animatedElementsIds.length!==0||!o){n.pause();return}n.volume=e.volume,n.paused&&n.play();let s=i%a/1e3+e.startTime*e.duration/1e3,c=n.currentTime;Math.abs(c-s)>.5&&s!==c&&(n.currentTime=s)});return()=>{n.pause(),n.removeEventListener(`ended`,r),n.removeEventListener(`timeupdate`,i),a()}},[t.isPlaying,e.startTime,e.endTime,e.volume,n]),null}),BA={data:[],pageId:``},VA=`polotno_clipboard`,HA=(e,t)=>{BA={data:JSON.parse(JSON.stringify(e)),pageId:t||``};try{localStorage.setItem(VA,JSON.stringify(e)),localStorage.setItem(VA+`_page`,t||``)}catch{}},UA=()=>{try{let e=localStorage.getItem(VA),t=localStorage.getItem(VA+`_page`);if(e)return{data:JSON.parse(e),pageId:t}}catch{}return BA},WA=e=>{e.selectedElements.length!==0&&HA(e.selectedElements.map(e=>e.toJSON()),e.activePage?.id)},GA=e=>{HA(e.selectedElements.map(e=>e.toJSON()),e.activePage?.id);let t=e.selectedElements.filter(e=>e.removable).map(e=>e.id);e.deleteElements(t)},KA=e=>{e.history.transaction(()=>{let t=0,n=0,{data:r,pageId:i}=UA();if(i===e.activePage?.id)t=e.width/20,n=e.height/20;else{let i=[];Uk({children:r},e=>{e.type!==`group`&&i.push(e)});let a=lb(i);a.maxX>e.width&&(t=-a.minX),a.maxY>e.height&&(n=-a.minY)}let a=[];Uk({children:r},e=>{delete e.id,e.type!==`group`&&(e.x+=t,e.y+=n)}),r.forEach(t=>{let n=e.activePage?.addElement(t);n&&a.push(n.id)}),HA(r,e.activePage?.id),e.selectElements(a)})};function qA(e,t){let n=[];e.forEach(e=>{if(!1===e.removable)return;let t=e.clone();e.type===`group`?t.children.forEach(e=>{e.set({x:e.x+50,y:e.y+50})}):t.set({x:e.x+50,y:e.y+50}),n.push(t.id)}),t.selectElements(n)}var JA=e=>{if(e.type!==`group`)return cb(e);let t=1/0,n=1/0,r=-1/0,i=-1/0;return e.children.forEach(e=>{let a=JA(e);t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.width),i=Math.max(i,a.y+a.height)}),{x:t,y:n,width:r-t,height:i-n}},YA=(e,t,n)=>{if(e.type!==`group`){let r=cb(e),i=t-r.x,a=n-r.y;e.set({x:e.x+i,y:e.y+a})}else{let r=t-JA(e).x,i=n-JA(e).y;e.children.forEach(e=>{let t=JA(e);YA(e,t.x+r,t.y+i)})}};function XA(e){let t=e.activePage?.computedWidth;e.selectedElements.forEach(e=>{t=Math.min(t,JA(e).x)}),e.selectedElements.length===1&&(t=0),e.selectedElements.forEach(e=>{let n=JA(e);YA(e,n.x-n.x+t,n.y)})}function ZA(e){let t=0;e.selectedElements.forEach(e=>{let n=JA(e);t=Math.max(t,n.x+n.width)}),e.selectedElements.length===1&&(t=e.activePage?.computedWidth),e.selectedElements.forEach(e=>{let n=JA(e);YA(e,t-n.width,n.y)})}function QA(e){let t=e.activePage?.computedHeight;e.selectedElements.forEach(e=>{t=Math.min(t,JA(e).y)}),e.selectedElements.length===1&&(t=0),e.selectedElements.forEach(e=>{let n=JA(e);YA(e,n.x,n.y-n.y+t)})}function $A(e){let t=e.activePage?.computedHeight,n=0;e.selectedElements.forEach(e=>{let r=JA(e);t=Math.min(t,r.y),n=Math.max(n,r.y+r.height)});let r=(n+t)/2;e.selectedElements.length===1&&(r=e.activePage?.computedHeight/2),e.selectedElements.forEach(e=>{let t=JA(e);YA(e,t.x,r-t.height/2)})}function ej(e){let t=0;e.selectedElements.forEach(e=>{let n=JA(e);t=Math.max(t,n.y+n.height)}),e.selectedElements.length===1&&(t=e.activePage?.computedHeight),e.selectedElements.forEach(e=>{let n=JA(e);YA(e,n.x,t-n.height)})}function tj(e){let t=e.activePage?.computedWidth,n=0;e.selectedElements.forEach(e=>{let r=JA(e);t=Math.min(t,r.x),n=Math.max(n,r.x+r.width)});let r=(n+t)/2;e.selectedElements.length===1&&(r=e.activePage?.computedWidth/2),e.selectedElements.forEach(e=>{let t=JA(e);YA(e,r-t.width/2,t.y)})}var nj=`rgba(191, 191, 191, 100)`;function rj(e,t,n){let r=e.getCell(t,n);r&&e.focusCell(r.id)}function ij(e,t,n){let r=e.getCell(t,n);r&&e.enterCellEdit(r.id)}function aj(e,t){var n,r,i,a,o,s,c,l;let u=function(e){if(e.selectedElements.length!==1)return null;let t=e.selectedElements[0];return t.type===`table`?t:null}(t);if(u&&function(e,t){let n=t._focusedCellIds.length>0,r=!!t._editingCellId;if(!n&&!r)return!1;if(r){if(e.key===`Escape`)return e.preventDefault(),t.exitCellEdit(),!0;if(e.key===`Tab`){e.preventDefault();let n=t.editingCell;if(t.exitCellEdit(),n)if(e.shiftKey){let e=n.col-1,r=n.row;e<0&&(--r,e=t.cols-1),r<0&&(r=t.rows-1,e=t.cols-1),ij(t,r,e)}else{let e=n.col+1,r=n.row;e>=t.cols&&(r+=1,e=0),r>=t.rows&&(r=0,e=0),ij(t,r,e)}return!0}if(e.metaKey||e.ctrlKey){let n=t.editingCell;if(n){if(e.key===`b`)return e.preventDefault(),n.set({fontWeight:n.fontWeight===`bold`?`normal`:`bold`}),!0;if(e.key===`i`)return e.preventDefault(),n.set({fontStyle:n.fontStyle===`italic`?`normal`:`italic`}),!0;if(e.key===`u`){e.preventDefault();let t=n.textDecoration.split(` `).filter(Boolean),r=t.includes(`underline`);return n.set({textDecoration:r?t.filter(e=>e!==`underline`).join(` `):[...t,`underline`].join(` `)}),!0}}}return!0}if(e.key===`Escape`)return e.preventDefault(),t.clearCellFocus(),!0;let i=t.focusedCells[0];if(!i)return!1;let a=i.row,o=i.col;if(e.key===`Enter`)return e.preventDefault(),t.enterCellEdit(i.id),!0;if(e.key===`Tab`){if(e.preventDefault(),e.shiftKey){let e=o-1,n=a;e<0&&(--n,e=t.cols-1),n<0&&(n=t.rows-1,e=t.cols-1),rj(t,n,e)}else{let e=o+1,n=a;e>=t.cols&&(n+=1,e=0),n>=t.rows&&(n=0,e=0),rj(t,n,e)}return!0}if(e.key===`ArrowRight`||e.key===`ArrowLeft`||e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),e.shiftKey){let n=function(e){let t=e.cells.find(t=>t.id===e._anchorCellId);if(!t)return null;let n=e.focusedCells;if(n.length<=1)return{row:t.row,col:t.col};let r=1/0,i=-1,a=1/0,o=-1;for(let e of n)e.row<r&&(r=e.row),e.row>i&&(i=e.row),e.col<a&&(a=e.col),e.col>o&&(o=e.col);return{row:t.row===r?i:r,col:t.col===a?o:a}}(t)||{row:a,col:o},r=n.row,i=n.col;e.key===`ArrowRight`&&(i=Math.min(n.col+1,t.cols-1)),e.key===`ArrowLeft`&&(i=Math.max(n.col-1,0)),e.key===`ArrowDown`&&(r=Math.min(n.row+1,t.rows-1)),e.key===`ArrowUp`&&(r=Math.max(n.row-1,0)),t.focusCellRange(r,i)}else e.key===`ArrowRight`&&rj(t,a,Math.min(o+1,t.cols-1)),e.key===`ArrowLeft`&&rj(t,a,Math.max(o-1,0)),e.key===`ArrowDown`&&rj(t,Math.min(a+1,t.rows-1),o),e.key===`ArrowUp`&&rj(t,Math.max(a-1,0),o);return!0}if(e.key===`Delete`||e.key===`Backspace`)return e.preventDefault(),t.focusedCells.forEach(e=>{e.set({text:``})}),!0;let s=e.ctrlKey||e.metaKey;if(s&&e.code===`KeyC`){e.preventDefault();let n=t.focusedCells.map(e=>Qf(e.text));return navigator.clipboard.writeText(n.join(`
329
+ `)),!0}return s&&e.code===`KeyV`?(e.preventDefault(),navigator.clipboard.readText().then(e=>{let n=t.focusedCells[0];n&&n.set({text:e})}),!0):!(!s||e.code!==`KeyA`||(e.preventDefault(),t.cells.forEach(e=>{t.focusCell(e.id,!0)}),0))}(e,u)||document.activeElement?.tagName===`INPUT`||document.activeElement?.tagName===`TEXTAREA`||document.activeElement?.contentEditable===`true`)return;let d=document.querySelector(`.polotno-workspace-container`);if(document.activeElement!==d&&!d?.contains(document.activeElement)){let e=window.getSelection();if(e&&e.toString().length>0)return}let f=t.selectedElements.filter(e=>e.removable).map(e=>e.id);e.keyCode!==46&&e.keyCode!==8||t.deleteElements(f);let p=e.ctrlKey||e.metaKey,m=e.shiftKey,h=e.altKey;if(e.key===`Escape`){e.preventDefault(),t.tool===`draw`?t.setTool(`selection`):t.selectElements([]);return}if(!p||m||e.key.toLowerCase()!==`z`&&e.key.toLowerCase()!==`y`||(e.preventDefault(),t.history.undo()),p&&m&&(e.key.toLowerCase()===`z`||e.key.toLowerCase()===`y`)&&(e.preventDefault(),t.history.redo()),p&&e.code===`KeyA`){e.preventDefault();let n=(t.activePage?.children.filter(e=>e.selectable))?.map(e=>e.id)||[];t.selectElements(n)}if(p&&e.code===`KeyC`&&(e.preventDefault(),WA(t)),p&&e.code===`KeyX`&&(e.preventDefault(),GA(t)),p&&e.code===`KeyV`&&(e.preventDefault(),KA(t)),e.code===`ArrowDown`){e.preventDefault();let n=e.shiftKey?10:1;t.selectedShapes.forEach(e=>{e.draggable&&e.set({y:e.y+n})})}if(e.code===`ArrowUp`){e.preventDefault();let n=e.shiftKey?10:1;t.selectedShapes.forEach(e=>{e.draggable&&e.set({y:e.y-n})})}if(e.code===`ArrowLeft`){e.preventDefault();let n=e.shiftKey?10:1;t.selectedShapes.forEach(e=>{e.draggable&&e.set({x:e.x-n})})}if(e.code===`ArrowRight`){e.preventDefault();let n=e.shiftKey?10:1;t.selectedShapes.forEach(e=>{e.draggable&&e.set({x:e.x+n})})}if(p&&e.code===`KeyG`){e.preventDefault();let n=t.selectedElements[0];if(n&&n.type===`group`){let e=n;t.ungroupElements([e.id])}else t.groupElements(t.selectedElements.map(e=>e.id))}if(p&&e.code===`KeyD`&&(e.preventDefault(),qA(t.selectedElements,t)),e.code===`KeyT`&&!p){e.preventDefault();let r=t.width/2,i=t.width/2-r/2,a=t.height/2-30/2,o=(t.width+t.height)/2160;(n=t.activePage)==null||n.addElement({type:`text`,x:i,y:a,width:r,fontSize:30*o,text:`Sample Text`,fontFamily:`Roboto`})}if(e.code===`KeyR`&&!p){e.preventDefault();let n={type:`figure`,x:t.width/4,y:t.height/4,width:300,height:300,fill:nj,stroke:`#0c0c0c`,strokeWidth:0,subType:`rect`};(r=t.activePage)==null||r.addElement(n)}if(e.code===`KeyL`&&!p){e.preventDefault();let n=(t.activePage?.computedWidth??0)/3,r={type:`line`,x:(t.activePage?.computedWidth??0)/2-n/2,y:(t.activePage?.computedHeight??0)/2,width:n,color:nj};(i=t.activePage)==null||i.addElement(r)}if(e.code===`KeyO`&&!p){e.preventDefault(),e.preventDefault();let n={type:`figure`,x:t.width/4,y:t.height/4,width:300,height:300,fill:nj,stroke:`#0c0c0c`,strokeWidth:0,subType:`circle`};(a=t.activePage)==null||a.addElement(n)}p&&e.code===`Equal`&&(e.preventDefault(),t.setScale(t.scale+.1)),p&&e.code===`Minus`&&(e.preventDefault(),t.setScale(t.scale-.1)),h&&(e.code===`KeyA`&&(e.preventDefault(),XA(t)),e.code===`KeyD`&&(e.preventDefault(),ZA(t)),e.code===`KeyS`&&(e.preventDefault(),ej(t)),e.code===`KeyW`&&(e.preventDefault(),QA(t)),e.code===`KeyV`&&(e.preventDefault(),$A(t)),e.code===`KeyH`&&(e.preventDefault(),tj(t))),e.code===`BracketRight`&&(e.preventDefault(),p?(o=t.activePage)==null||o.moveElementsUp(t.selectedElementsIds):(s=t.activePage)==null||s.moveElementsTop(t.selectedElementsIds)),e.code===`BracketLeft`&&(e.preventDefault(),p?(c=t.activePage)==null||c.moveElementsDown(t.selectedElementsIds):(l=t.activePage)==null||l.moveElementsBottom(t.selectedElementsIds))}var oj=L({toolbar:{duration:`Duration`,opacity:`Opacity`,effects:`Effects`,blur:`Blur`,curvedText:`Curved text`,curvePower:`Power`,temperature:`Temperature`,saturation:`Saturation`,contrast:`Contrast`,shadows:`Shadows`,white:`White`,black:`Black`,vibrance:`Vibrance`,textBackground:`Background`,backgroundCornerRadius:`Corner radius`,backgroundOpacity:`Opacity`,backgroundPadding:`Padding`,brightness:`Brightness`,filters:`Filters`,sepia:`Sepia`,grayscale:`Grayscale`,cold:`Cold`,natural:`Natural`,warm:`Warm`,textStroke:`Text Stroke`,shadow:`Shadow`,border:`Border`,cornerRadius:`Corner Radius`,copyStyle:`Copy style`,uppercase:`Uppercase`,position:`Position`,layering:`Layering`,toForward:`To Front`,up:`Forward`,down:`Backward`,toBottom:`To back`,alignLeft:`Align left`,alignCenter:`Align center`,alignRight:`Align right`,alignTop:`Align top`,alignMiddle:`Align middle`,alignBottom:`Align bottom`,flip:`Flip`,flipHorizontally:`Flip horizontally`,flipVertically:`Flip vertically`,fitToBackground:`Fit to page`,removeBackground:`Remove background`,removeBackgroundTitle:`Remove background from image`,cancelRemoveBackground:`Cancel`,confirmRemoveBackground:`Confirm`,crop:`Crop`,cropDone:`Done`,cropCancel:`Cancel`,clip:`Apply mask`,removeClip:`Remove mask`,removeMask:`Remove mask`,transparency:`Transparency`,lockedDescription:`Object is locked. Unlock it to allow changes from canvas.`,unlockedDescription:`Object is unlocked. Lock it to prevent changes from canvas.`,removeElements:`Remove elements`,duplicateElements:`Duplicate elements`,download:`Download`,saveAsImage:`Save as image`,saveAsPDF:`Save as PDF`,lineHeight:`Line height`,letterSpacing:`Letter spacing`,offsetX:`Offset X`,offsetY:`Offset Y`,color:`Color`,selectable:`Selectable`,draggable:`Draggable`,removable:`Removable`,resizable:`Resizable`,contentEditable:`Can change content`,styleEditable:`Can change style`,alwaysOnTop:`Always on top`,showInExport:`Show in export`,ungroupElements:`Ungroup`,groupElements:`Group`,lineSize:`Line size`,fade:`Fade`,move:`Move`,zoom:`Zoom`,animate:`Animate`,rotate:`Rotate`,none:`None`,bounce:`Bounce`,blink:`Blink`,strength:`Strength`,spaceEvenly:`Space evenly`,horizontalDistribution:`Horizontally`,verticalDistribution:`Vertically`,strokeWidth:`Stroke Width`,strokeSettings:`Stroke settings`,spacing:`Spacing`,volume:`Volume`,lineStyle:`Line style`,lineStartHead:`Line start`,lineEndHead:`Line end`,textDirection:`Text direction`,fontSize:`Font size`,fontFamily:`Font family`,textAlign:`Text align`,verticalAlign:`Vertical align`,bold:`Bold`,italic:`Italic`,underline:`Underline`,strikethrough:`Strikethrough`,cellBackground:`Cell background`,tableBorderSettings:`Border settings`,tableBorderColor:`Border color`,tableBorderWidth:`Border width`,tableBorderStyle:`Border style`,borderAllSides:`All sides`,borderTop:`Top`,borderBottom:`Bottom`,borderLeft:`Left`,borderRight:`Right`,borderNone:`No border`,tableStructure:`Table structure`,tableRows:`Rows`,tableColumns:`Columns`,insertRowAbove:`Insert row above`,insertRowBelow:`Insert row below`,deleteRow:`Delete row`,insertColumnLeft:`Insert column left`,insertColumnRight:`Insert column right`,deleteColumn:`Delete column`,distributeRowsEvenly:`Distribute rows evenly`,distributeColumnsEvenly:`Distribute columns evenly`,cellPadding:`Cell padding`,listFormat:`List`,colorPicker:{solid:`Solid`,linear:`Linear`,angle:`Angle`},aiText:{aiWrite:`AI write`,rewrite:`Rewrite`,shorten:`Shorten`,continue:`Continue writing`,proofread:`Proofread`,tones:`Tones`,friendly:`Friendly`,professional:`Professional`,humorous:`Humorous`,formal:`Formal`,customPrompt:`Custom prompt`,generatedResult:`Generated result`,cancel:`Cancel`,generate:`Generate`,back:`Back`,tryAgain:`Try Again`,insert:`Insert`,promptPlaceholder:`Describe what you want to generate`}},workspace:{noPages:`There are no pages yet...`,addPage:`Add page`,removePage:`Remove page`,duplicatePage:`Duplicate page`,moveUp:`Move up`,moveDown:`Move down`,moveLeft:`Move left`,moveRight:`Move right`},scale:{reset:`Reset`},error:{removeBackground:`Ops! Something went wrong. Background can not be removed.`},sidePanel:{templates:`Templates`,searchTemplatesWithSameSize:`Show templates with the same size`,searchPlaceholder:`Search...`,otherFormats:`Other formats`,noResults:`No results`,error:`Loading is failed...`,text:`Text`,uploadFont:`Upload font`,myFonts:`My fonts`,photos:`Photos`,videos:`Videos`,animations:`Animations`,effects:`Effects`,elements:`Elements`,shapes:`Shapes`,tables:`Tables`,lines:`Lines`,draw:`Draw`,upload:`Upload`,uploadImage:`Add file`,uploadTip:`Upload your assets`,background:`Background`,resize:`Resize`,layers:`Layers`,animate:`Animate`,layerTypes:{image:`Image`,text:`Text`,svg:`SVG`,line:`Line`,figure:`Figure`,group:`Group`},layersTip:`Elements on your active page:`,noLayers:`No elements on the page...`,namePlaceholder:`Type element name...`,useMagicResize:`Use magic resize`,clipImage:`Mask image`,width:`Width`,height:`Height`,magicResizeDescription:`Magic resize will automatically resize and move all elements on the canvas`,headerText:`Header`,createHeader:`Create header`,subHeaderText:`Sub Header`,createSubHeader:`Create sub header`,bodyText:`Body text`,createBody:`Create body text`},pagesTimeline:{pages:`Pages`,removePage:`Remove page`,addPage:`Add page`,duplicatePage:`Duplicate page`,removeAudio:`Remove audio`,duplicateAudio:`Duplicate audio`,muteAudio:`Mute`,unmuteAudio:`Unmute`,volume:`Volume`},contextMenu:{duplicate:`Duplicate`,remove:`Remove`,lock:`Lock`,unlock:`Unlock`,copy:`Copy`,paste:`Paste`,copyStyle:`Copy style`,moveUp:`Move up`,moveDown:`Move down`,moveBack:`Move back`,moveForward:`Move forward`}}),sj=e=>e&&typeof e==`object`;function cj(e,t){Object.keys(t).forEach(n=>{let r=e[n],i=t[n];sj(i)&&sj(r)?cj(r,i):e[n]=i})}function lj(e,t,n=``){Object.keys(t).forEach(r=>{let i=t[r],a=n?`${n}.${r}`:r;sj(i)?sj(e[r])?lj(e[r],i,a):console.warn(`Missing nested translation object at '${a}'`):e[r]===void 0&&console.warn(`Missing translation '${a}'`)})}Vn((e,{validate:t=!1}={})=>{t&&lj(e,oj),cj(oj,e)});var uj={},dj=e=>{let t=function(e,t){var n,r=t.split(`.`),i=e;for(n=0;n<r.length;++n){if(i[r[n]]==null)return;i=i[r[n]]}return i}(oj,e);if(t!==void 0)return t;uj[e]||(uj[e]=!0,console.warn(`Missing translation '${e}'`));let n=e.split(`.`),r=n[n.length-1]||` `;return r.charAt(0).toUpperCase()+r.slice(1)},fj=(e,t,n)=>Math.max(t,Math.min(n,e)),pj=(e,t)=>Math.sqrt((t.clientX-e.clientX)**2+(t.clientY-e.clientY)**2),mj=({store:e})=>d.createElement(`div`,{style:{position:`absolute`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,textAlign:`center`}},d.createElement(`p`,null,dj(`workspace.noPages`)),d.createElement(`button`,{onClick:()=>{e.addPage()}},dj(`workspace.addPage`))),hj=({width:e,height:t,xPadding:n,yPadding:r,backgroundColor:i})=>d.createElement(`div`,{style:{width:e+`px`,height:t+`px`,backgroundColor:i,paddingLeft:n+`px`,paddingRight:n+`px`,paddingTop:r+`px`,paddingBottom:r+`px`,flexShrink:0}},d.createElement(`div`,{style:{width:` 100%`,height:`100%`,backgroundColor:`white`}})),gj=[4,6],_j=sa(({store:e,layout:t=`vertical`,pageControlsEnabled:n,backgroundColor:r,transparencyBackgroundColor:i,pageBorderColor:a,activePageBorderColor:o,bleedColor:s,snapGuideStroke:c,snapGuideStrokeWidth:l,snapGuideDash:u,selectionRectFill:f,selectionRectStroke:p,selectionRectStrokeWidth:m,transformLabelFill:h,transformLabelTextFill:g,distanceGuideStroke:_,distanceLabelFill:v,distanceLabelTextFill:y,rulerBackgroundColor:b,rulerTextColor:x,rulerBorderColor:S,rulerBorderSize:C,rulerTickColor:w,rulerTickSize:T,components:E,onKeyDown:D,paddingX:O,paddingY:k,pageGap:A,altCloneEnabled:j=!0,visiblePagesOffset:M,renderOnlyActivePage:N,tooltipSafeArea:P})=>{let F=t===`horizontal`,ee=O??20,te=k??55,[ne,re]=d.useState({width:100,height:100}),ie=d.useRef(ne),I=d.useRef(null),ae=d.useRef(null),oe=d.useRef(0),se=e.bleedVisible?Math.max(0,...e.pages.map(e=>e.bleed)):0,ce=Math.max(...e.pages.map(e=>e.computedWidth)),le=Math.max(...e.pages.map(e=>e.computedHeight)),ue=e.activePage?.computedHeight||0,de=ce+2*se,fe=(N?ue:le)+2*se,pe=async({skipTimeout:t}={skipTimeout:!1})=>{if(t||await new Promise(e=>setTimeout(e,50)),I.current===null)return;let n=I.current.getBoundingClientRect();n.width!==0&&n.height!==0||(console.warn(`Polotno warning: <Workspace /> component can not automatically detect its size.
330
330
  Width or height of parent elements is equal 0.
331
331
  Please make sure it has non-zero size. You may need to adjust it with your styles. <Workspace /> will automatically fit into parent container.
332
- For simpler debugging here is the log of the parent element:`),console.log(I.current));let r=ae.current.clientWidth||n.width,i={width:r,height:n.height};(ie.current.width!==i.width||ie.current.height!==i.height)&&(re(i),ie.current=i);let a=(r-2*ee)/de,o=e.pages.length>1?3.1:2,s=(n.height-te*o)/fe,c=(r-ee*(e.pages.length>1?3.1:2))/de,l=(n.height-2*te)/fe,u=e.pages.length?Math.max(Math.min(F?c:a,F?l:s),.01):1;e.scaleToFit!==u&&(e.setScale(u),e._setScaleToFit(u))};d.useLayoutEffect(()=>{pe({skipTimeout:!0})},[]),d.useEffect(()=>{pe()},[de,fe,k,O]),d.useLayoutEffect(()=>{pe({skipTimeout:!0})},[e.openedSidePanel]),d.useEffect(()=>{e.__()},[]),d.useEffect(()=>{let e=I.current;if(window.ResizeObserver){let t=new ResizeObserver(()=>{pe({skipTimeout:!0})});return t.observe(e),()=>t.unobserve(e)}{let e=setInterval(()=>{pe({skipTimeout:!0})},100);return()=>clearInterval(e)}},[de,fe]);let me=N?1:e.pages.length,he,ge;if(F){let t=de*e.scale*me;he=Math.max(ee,(ne.width-t)/me/2),ge=Math.max(te,(ne.height-fe*e.scale)/2)}else{he=Math.max(ee,(ne.width-de*e.scale)/2);let t=fe*e.scale*me;ge=Math.max(te,(ne.height-t)/me/2)}Number.isNaN(he)&&(he=ee),Number.isNaN(ge)&&(ge=te),d.useEffect(()=>{let t=t=>{(D||nj)(t,e)};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[]),d.useEffect(()=>{let t=t=>{if(t.ctrlKey||t.metaKey){t.preventDefault();let n=Math.max(5,e.scaleToFit),r=Math.min(.1,e.scaleToFit);F&&de>0&&Number.isFinite(de)&&(r=Math.max(r,300/de)),r=Math.max(r,.01);let i=.03,a=lj(t.deltaY<0?e.scale*(1+i):e.scale/(1+i),r,n);e.setScale(a);return}},n=ae.current;return n?.addEventListener(`wheel`,t),()=>n?.removeEventListener(`wheel`,t)},[F,de,e]),d.useEffect(()=>{let t=ae.current;if(!t)return;let n=e=>{e.touches.length===2&&(oe.current=uj(e.touches[0],e.touches[1]))},r=n=>{if(n.touches.length===2&&oe.current>0){n.preventDefault();let r=uj(n.touches[0],n.touches[1]),i=r/oe.current,a=Math.max(5,e.scaleToFit),o=Math.min(.1,e.scaleToFit);F&&de>0&&Number.isFinite(de)&&(o=Math.max(o,300/de)),o=Math.max(o,.01);let s=e.scale,c=lj(s*i,o,a),l=c/s,u=t.getBoundingClientRect(),d=(n.touches[0].clientX+n.touches[1].clientX)/2-u.left,f=(n.touches[0].clientY+n.touches[1].clientY)/2-u.top,p=t.scrollLeft+d,m=t.scrollTop+f;Ce.current=!0,e.setScale(c),t.scrollLeft=p*l-d,t.scrollTop=m*l-f,oe.current=r}},i=()=>{oe.current=0};return t.addEventListener(`touchstart`,n,{passive:!0}),t.addEventListener(`touchmove`,r,{passive:!1}),t.addEventListener(`touchend`,i,{passive:!0}),()=>{t.removeEventListener(`touchstart`,n),t.removeEventListener(`touchmove`,r),t.removeEventListener(`touchend`,i)}},[F,de,e]);let _e=A!==void 0,ve=e.pages.map(t=>{if(F){let n=(t.computedWidth+2*se)*e.scale;return _e?n+A:n+2*he}{let n=(t.computedHeight+2*se)*e.scale;return _e?n+A:n+2*ge}}),ye=[],be=_e?F?he:ge:0;for(let e=0;e<ve.length;e++)ye.push(be),be+=ve[e];let xe=ve.reduce((e,t)=>e+t,0),Se=_e?xe+(F?2*he:2*ge):xe,Ce=d.useRef(!1),[,we]=d.useReducer(e=>e+1,0);((e,t,n,r,i)=>{let a=d.useRef(0),o=d.useRef(0),s=d.useRef(null),c=d.useRef(null),l=d.useRef(!1),u=d.useRef(r.pages.length);l.current=u.current!==r.pages.length,u.current=r.pages.length,d.useEffect(()=>{let t=e.current,n=()=>{a.current=t.scrollLeft,o.current=t.scrollTop,s.current=t.scrollWidth,c.current=t.scrollHeight};return t.addEventListener(`scroll`,n),n(),()=>{t.removeEventListener(`scroll`,n)}},[]),d.useLayoutEffect(()=>{if(!e.current||l.current)return;let t=e.current,n=s.current,r=c.current;if(n===null||r===null){s.current=t.scrollWidth,c.current=t.scrollHeight,a.current=t.scrollLeft,o.current=t.scrollTop;return}i.current=!0;let u=t.offsetWidth,d=t.offsetHeight,f=(a.current+u/2)/n,p=(o.current+d/2)/r,m=Math.max(0,t.scrollWidth-u),h=Math.max(0,t.scrollHeight-d);t.scrollLeft=lj(f*t.scrollWidth-u/2,0,m),t.scrollTop=lj(p*t.scrollHeight-d/2,0,h),s.current=t.scrollWidth,c.current=t.scrollHeight,a.current=t.scrollLeft,o.current=t.scrollTop},[n,t])})(ae,Se,e.scale,e,Ce);let{handleScroll:Te}=((e,t,n,r,i,a,o,s,c)=>{let l=d.useRef(!1),u=d.useRef(null),f=d.useRef(!1),p=s===`horizontal`;d.useEffect(()=>{let t=e.current,n=()=>{a.current};return t.addEventListener(`scroll`,n),()=>{t.removeEventListener(`scroll`,n)}},[]);let m=r.pages.indexOf(r.activePage);return d.useLayoutEffect(()=>{if(o||!r.activePage||!e.current||l.current)return;let i=e.current,a=r.pages.indexOf(r.activePage),s=t[a]||0,u=p?i.scrollLeft:i.scrollTop,d=p?i.scrollWidth-i.clientWidth:i.scrollHeight-i.clientHeight,m=Math.min(s,Math.max(0,d)),h=n[a]||n[0]||0,g=()=>{};return(Math.abs(m-u)>.5*h||f.current)&&(f.current=!0,g=(({element:e,scrollTop:t,scrollLeft:n,duration:r=300,onFinish:i=()=>{}})=>{let a=t!==void 0,o=a?e.scrollTop:e.scrollLeft,s=a?t:n,c=s-o,l=0,u=!1;if(r===0)return a?e.scrollTop=s:e.scrollLeft=s,()=>{};let d=()=>{if(u)return;l+=20;let t=f(l,o,c,r);a?e.scrollTop=t:e.scrollLeft=t,l<r?setTimeout(d,20):i()},f=(e,t,n,r)=>(e/=r/2)<1?n/2*e*e+t:-n/2*(--e*(e-2)-1)+t;return d(),()=>{u=!0}})(Object.assign(Object.assign({element:i},p?{scrollLeft:m}:{scrollTop:m}),{onFinish:()=>{f.current=!1,c?.()},duration:r.isPlaying?0:300}))),g},[r.activePage,m,r.isPlaying,o,s,t,n]),{handleScroll:e=>{if(o||f.current)return;l.current=!0,clearTimeout(u.current),u.current=setTimeout(()=>{l.current=!1},300);let n=(p?e.currentTarget.scrollLeft:e.currentTarget.scrollTop)+(p?i.width:i.height)/3,a=0;for(let e=t.length-1;e>=0;e--)if(n>=t[e]){a=e;break}let s=r.pages[a];s&&r.activePage!==s&&s.select()}}})(ae,ye,ve,e,ne,Ce,N,t,we),Ee=ne.width>=de*e.scale+2*he,De=ne.height>=fe*e.scale+2*ge,Oe=r||`rgba(232, 232, 232, 0.9)`,ke=E?.NoPages||dj,Ae=F?ne.width:ne.height,je=ae.current?F?ae.current.scrollLeft:ae.current.scrollTop:0,Me=e=>{for(let t=ye.length-1;t>=0;t--)if(e>=ye[t])return t;return 0},Ne=Math.max(0,Me(je)),Pe=Math.min(e.pages.length-1,Me(je+Ae)),Fe=M??1,Ie=Math.max(0,Ne-Fe),Le=Math.min(e.pages.length-1,Pe+Fe);return d.createElement(`div`,{ref:I,style:{width:`100%`,height:`100%`,position:`relative`,outline:`none`,flex:1,backgroundColor:Oe,overflow:`hidden`},tabIndex:0,className:`polotno-workspace-container`},d.createElement(`div`,{ref:ae,onScroll:Te,style:Object.assign({position:`absolute`,top:0,left:0,width:`100%`,height:`100%`,display:`flex`,flexDirection:F?`row`:`column`,overflow:`auto`,overflowX:F?`auto`:Ee?`hidden`:`auto`,overflowY:F&&De?`hidden`:`auto`},_e&&{paddingTop:F?0:ge,paddingBottom:F?0:ge,paddingLeft:F?he:0,paddingRight:F?he:0,boxSizing:`border-box`}),className:`polotno-workspace-inner`},e.pages.map((r,b)=>{let x=r===e.activePage;if(N&&!x&&!r._exportingOrRendering&&!r._forceMount)return null;let S=x||b>=Ie&&b<=Le||r._exportingOrRendering||r._forceMount,C=F?ve[b]:de*e.scale+2*he,w=F?fe*e.scale+2*ge:ve[b];if(!S)return d.createElement(`div`,{key:r.id,style:{flexShrink:0}},d.createElement(fj,{width:C,height:w,backgroundColor:Oe,xPadding:he,yPadding:ge}));let T=d.createElement(OA,{key:r.id,page:r,xPadding:he,yPadding:ge,width:C,height:w,store:e,pageControlsEnabled:n,backColor:Oe,transparencyBackgroundColor:i,pageBorderColor:a||`lightgrey`,activePageBorderColor:o||`rgb(0, 161, 255)`,altCloneEnabled:j,bleedColor:s||`rgba(255, 0, 0, 0.1)`,selectionRectFill:f,selectionRectStroke:p,selectionRectStrokeWidth:m,snapGuideStroke:c||`rgb(0, 161, 255)`,snapGuideStrokeWidth:l||1,snapGuideDash:u||pj,transformLabelFill:h,transformLabelTextFill:g,distanceGuideStroke:_||`rgb(0, 161, 255)`,distanceLabelFill:v||`rgb(0, 161, 255)`,distanceLabelTextFill:y||`white`,components:E,viewportSize:ne,layout:t,tooltipSafeArea:P});return(r._exportingOrRendering||r._forceMount)&&!x&&N?d.createElement(`div`,{style:{display:`none`,flexShrink:0},key:r.id},T):T}),e.rulesVisible&&d.createElement(FA,{store:e,xPadding:he,yPadding:ge,width:de*e.scale+2*he,height:fe*e.scale+2*ge,pageSizes:ve,layout:t,renderOnlyActivePage:N,rulerBackgroundColor:b,rulerTextColor:x,rulerBorderColor:S,rulerBorderSize:C,rulerTickColor:w,rulerTickSize:T}),e.pages.length===0&&d.createElement(ke,{store:e}),e.audios.map(t=>d.createElement(IA,{key:t.id,audio:t,store:e}))))}),hj=`modulepreload`,gj=function(e,t){return new URL(e,t).href},_j={},vj=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=gj(t,n),t in _j)return;_j[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:hj,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};W.prototype._requestDraw=()=>{},If(!1),Tp(`change-font-size`);var yj=rk({key:new URLSearchParams(location.search).get(`key`)});window.store=yj;var bj=null;window.__polotnoLoadJspdf=async()=>(bj||=vj(()=>import(`./jspdf.es.min-B7BbMBrq.js`),__vite__mapDeps([0,1,2]),import.meta.url),await bj);var xj=null;window.__polotnoLoadVideoExport=async()=>(xj||=vj(()=>import(`./lib-C0YGJINc.js`),__vite__mapDeps([3,1]),import.meta.url),await xj),window.config={addGlobalFont:rp,setRichTextEnabled:Cp,setTextVerticalResizeEnabled:xp,setTextOverflow:Tp,onLoadError:Xf,setAssetLoadTimeout:Hf,setFontLoadTimeout:Wf,unstable_setTextSplitAllowed:Ep},u.createRoot(document.getElementById(`root`)).render(d.createElement(mj,{visiblePagesOffset:0,renderOnlyActivePage:!0,store:yj,components:{PageControls:()=>null,Tooltip:()=>null}}));export{Fb as $,Ux as A,gS as B,oC as C,Gx as D,Kx as E,lS as F,Rx as G,zx as H,cS as I,Lx as J,Nx as K,sS as L,eS as M,tS as N,Wx as O,uS as P,Lb as Q,vS as R,vC as S,nC as T,Hx as U,Bx as V,Vx as W,Nb as X,Vb as Y,gx as Z,LS as _,Z_ as _t,CE as a,bx as at,AS as b,vw as c,Dx as ct,RC as d,nx as dt,J as et,jC as f,tx as ft,TC as g,gv as gt,EC as h,Ob as ht,bE as i,hx as it,rS as j,qx as k,mw as l,Tb as lt,OC as m,jb as mt,kE as n,ix as nt,vE as o,ux as ot,kC as p,jx as pt,Fx as q,EE as r,zb as rt,OT as s,Eb as st,vj as t,Qb as tt,qC as u,qb as ut,zS as v,BS as w,mC as x,JS as y,yS as z};
332
+ For simpler debugging here is the log of the parent element:`),console.log(I.current));let r=ae.current.clientWidth||n.width,i={width:r,height:n.height};(ie.current.width!==i.width||ie.current.height!==i.height)&&(re(i),ie.current=i);let a=(r-2*ee)/de,o=e.pages.length>1?3.1:2,s=(n.height-te*o)/fe,c=(r-ee*(e.pages.length>1?3.1:2))/de,l=(n.height-2*te)/fe,u=e.pages.length?Math.max(Math.min(F?c:a,F?l:s),.01):1;e.scaleToFit!==u&&(e.setScale(u),e._setScaleToFit(u))};d.useLayoutEffect(()=>{pe({skipTimeout:!0})},[]),d.useEffect(()=>{pe()},[de,fe,k,O]),d.useLayoutEffect(()=>{pe({skipTimeout:!0})},[e.openedSidePanel]),d.useEffect(()=>{e.__()},[]),d.useEffect(()=>{let e=I.current;if(window.ResizeObserver){let t=new ResizeObserver(()=>{pe({skipTimeout:!0})});return t.observe(e),()=>t.unobserve(e)}{let e=setInterval(()=>{pe({skipTimeout:!0})},100);return()=>clearInterval(e)}},[de,fe]);let me=N?1:e.pages.length,he,ge;if(F){let t=de*e.scale*me;he=Math.max(ee,(ne.width-t)/me/2),ge=Math.max(te,(ne.height-fe*e.scale)/2)}else{he=Math.max(ee,(ne.width-de*e.scale)/2);let t=fe*e.scale*me;ge=Math.max(te,(ne.height-t)/me/2)}Number.isNaN(he)&&(he=ee),Number.isNaN(ge)&&(ge=te),d.useEffect(()=>{let t=t=>{(D||aj)(t,e)};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[]),d.useEffect(()=>{let t=t=>{if(t.ctrlKey||t.metaKey){t.preventDefault();let n=Math.max(5,e.scaleToFit),r=Math.min(.1,e.scaleToFit);F&&de>0&&Number.isFinite(de)&&(r=Math.max(r,300/de)),r=Math.max(r,.01);let i=.03,a=fj(t.deltaY<0?e.scale*(1+i):e.scale/(1+i),r,n);e.setScale(a);return}},n=ae.current;return n?.addEventListener(`wheel`,t),()=>n?.removeEventListener(`wheel`,t)},[F,de,e]),d.useEffect(()=>{let t=ae.current;if(!t)return;let n=e=>{e.touches.length===2&&(oe.current=pj(e.touches[0],e.touches[1]))},r=n=>{if(n.touches.length===2&&oe.current>0){n.preventDefault();let r=pj(n.touches[0],n.touches[1]),i=r/oe.current,a=Math.max(5,e.scaleToFit),o=Math.min(.1,e.scaleToFit);F&&de>0&&Number.isFinite(de)&&(o=Math.max(o,300/de)),o=Math.max(o,.01);let s=e.scale,c=fj(s*i,o,a),l=c/s,u=t.getBoundingClientRect(),d=(n.touches[0].clientX+n.touches[1].clientX)/2-u.left,f=(n.touches[0].clientY+n.touches[1].clientY)/2-u.top,p=t.scrollLeft+d,m=t.scrollTop+f;Ce.current=!0,e.setScale(c),t.scrollLeft=p*l-d,t.scrollTop=m*l-f,oe.current=r}},i=()=>{oe.current=0};return t.addEventListener(`touchstart`,n,{passive:!0}),t.addEventListener(`touchmove`,r,{passive:!1}),t.addEventListener(`touchend`,i,{passive:!0}),()=>{t.removeEventListener(`touchstart`,n),t.removeEventListener(`touchmove`,r),t.removeEventListener(`touchend`,i)}},[F,de,e]);let _e=A!==void 0,ve=e.pages.map(t=>{if(F){let n=(t.computedWidth+2*se)*e.scale;return _e?n+A:n+2*he}{let n=(t.computedHeight+2*se)*e.scale;return _e?n+A:n+2*ge}}),ye=[],be=_e?F?he:ge:0;for(let e=0;e<ve.length;e++)ye.push(be),be+=ve[e];let xe=ve.reduce((e,t)=>e+t,0),Se=_e?xe+(F?2*he:2*ge):xe,Ce=d.useRef(!1),[,we]=d.useReducer(e=>e+1,0);((e,t,n,r,i)=>{let a=d.useRef(0),o=d.useRef(0),s=d.useRef(null),c=d.useRef(null),l=d.useRef(!1),u=d.useRef(r.pages.length);l.current=u.current!==r.pages.length,u.current=r.pages.length,d.useEffect(()=>{let t=e.current,n=()=>{a.current=t.scrollLeft,o.current=t.scrollTop,s.current=t.scrollWidth,c.current=t.scrollHeight};return t.addEventListener(`scroll`,n),n(),()=>{t.removeEventListener(`scroll`,n)}},[]),d.useLayoutEffect(()=>{if(!e.current||l.current)return;let t=e.current,n=s.current,r=c.current;if(n===null||r===null){s.current=t.scrollWidth,c.current=t.scrollHeight,a.current=t.scrollLeft,o.current=t.scrollTop;return}i.current=!0;let u=t.offsetWidth,d=t.offsetHeight,f=(a.current+u/2)/n,p=(o.current+d/2)/r,m=Math.max(0,t.scrollWidth-u),h=Math.max(0,t.scrollHeight-d);t.scrollLeft=fj(f*t.scrollWidth-u/2,0,m),t.scrollTop=fj(p*t.scrollHeight-d/2,0,h),s.current=t.scrollWidth,c.current=t.scrollHeight,a.current=t.scrollLeft,o.current=t.scrollTop},[n,t])})(ae,Se,e.scale,e,Ce);let{handleScroll:Te}=((e,t,n,r,i,a,o,s,c)=>{let l=d.useRef(!1),u=d.useRef(null),f=d.useRef(!1),p=s===`horizontal`;d.useEffect(()=>{let t=e.current,n=()=>{a.current};return t.addEventListener(`scroll`,n),()=>{t.removeEventListener(`scroll`,n)}},[]);let m=r.pages.indexOf(r.activePage);return d.useLayoutEffect(()=>{if(o||!r.activePage||!e.current||l.current)return;let i=e.current,a=r.pages.indexOf(r.activePage),s=t[a]||0,u=p?i.scrollLeft:i.scrollTop,d=p?i.scrollWidth-i.clientWidth:i.scrollHeight-i.clientHeight,m=Math.min(s,Math.max(0,d)),h=n[a]||n[0]||0,g=()=>{};return(Math.abs(m-u)>.5*h||f.current)&&(f.current=!0,g=(({element:e,scrollTop:t,scrollLeft:n,duration:r=300,onFinish:i=()=>{}})=>{let a=t!==void 0,o=a?e.scrollTop:e.scrollLeft,s=a?t:n,c=s-o,l=0,u=!1;if(r===0)return a?e.scrollTop=s:e.scrollLeft=s,()=>{};let d=()=>{if(u)return;l+=20;let t=f(l,o,c,r);a?e.scrollTop=t:e.scrollLeft=t,l<r?setTimeout(d,20):i()},f=(e,t,n,r)=>(e/=r/2)<1?n/2*e*e+t:-n/2*(--e*(e-2)-1)+t;return d(),()=>{u=!0}})(Object.assign(Object.assign({element:i},p?{scrollLeft:m}:{scrollTop:m}),{onFinish:()=>{f.current=!1,c?.()},duration:r.isPlaying?0:300}))),g},[r.activePage,m,r.isPlaying,o,s,t,n]),{handleScroll:e=>{if(o||f.current)return;l.current=!0,clearTimeout(u.current),u.current=setTimeout(()=>{l.current=!1},300);let n=(p?e.currentTarget.scrollLeft:e.currentTarget.scrollTop)+(p?i.width:i.height)/3,a=0;for(let e=t.length-1;e>=0;e--)if(n>=t[e]){a=e;break}let s=r.pages[a];s&&r.activePage!==s&&s.select()}}})(ae,ye,ve,e,ne,Ce,N,t,we),Ee=ne.width>=de*e.scale+2*he,De=ne.height>=fe*e.scale+2*ge,Oe=r||`rgba(232, 232, 232, 0.9)`,ke=E?.NoPages||mj,Ae=F?ne.width:ne.height,je=ae.current?F?ae.current.scrollLeft:ae.current.scrollTop:0,Me=e=>{for(let t=ye.length-1;t>=0;t--)if(e>=ye[t])return t;return 0},Ne=Math.max(0,Me(je)),Pe=Math.min(e.pages.length-1,Me(je+Ae)),Fe=M??1,Ie=Math.max(0,Ne-Fe),Le=Math.min(e.pages.length-1,Pe+Fe);return d.createElement(`div`,{ref:I,style:{width:`100%`,height:`100%`,position:`relative`,outline:`none`,flex:1,backgroundColor:Oe,overflow:`hidden`},tabIndex:0,className:`polotno-workspace-container`},d.createElement(`div`,{ref:ae,onScroll:Te,style:Object.assign({position:`absolute`,top:0,left:0,width:`100%`,height:`100%`,display:`flex`,flexDirection:F?`row`:`column`,overflow:`auto`,overflowX:F?`auto`:Ee?`hidden`:`auto`,overflowY:F&&De?`hidden`:`auto`},_e&&{paddingTop:F?0:ge,paddingBottom:F?0:ge,paddingLeft:F?he:0,paddingRight:F?he:0,boxSizing:`border-box`}),className:`polotno-workspace-inner`},e.pages.map((r,b)=>{let x=r===e.activePage;if(N&&!x&&!r._exportingOrRendering&&!r._forceMount)return null;let S=x||b>=Ie&&b<=Le||r._exportingOrRendering||r._forceMount,C=F?ve[b]:de*e.scale+2*he,w=F?fe*e.scale+2*ge:ve[b];if(!S)return d.createElement(`div`,{key:r.id,style:{flexShrink:0}},d.createElement(hj,{width:C,height:w,backgroundColor:Oe,xPadding:he,yPadding:ge}));let T=d.createElement(jA,{key:r.id,page:r,xPadding:he,yPadding:ge,width:C,height:w,store:e,pageControlsEnabled:n,backColor:Oe,transparencyBackgroundColor:i,pageBorderColor:a||`lightgrey`,activePageBorderColor:o||`rgb(0, 161, 255)`,altCloneEnabled:j,bleedColor:s||`rgba(255, 0, 0, 0.1)`,selectionRectFill:f,selectionRectStroke:p,selectionRectStrokeWidth:m,snapGuideStroke:c||`rgb(0, 161, 255)`,snapGuideStrokeWidth:l||1,snapGuideDash:u||gj,transformLabelFill:h,transformLabelTextFill:g,distanceGuideStroke:_||`rgb(0, 161, 255)`,distanceLabelFill:v||`rgb(0, 161, 255)`,distanceLabelTextFill:y||`white`,components:E,viewportSize:ne,layout:t,tooltipSafeArea:P});return(r._exportingOrRendering||r._forceMount)&&!x&&N?d.createElement(`div`,{style:{display:`none`,flexShrink:0},key:r.id},T):T}),e.rulesVisible&&d.createElement(RA,{store:e,xPadding:he,yPadding:ge,width:de*e.scale+2*he,height:fe*e.scale+2*ge,pageSizes:ve,layout:t,renderOnlyActivePage:N,rulerBackgroundColor:b,rulerTextColor:x,rulerBorderColor:S,rulerBorderSize:C,rulerTickColor:w,rulerTickSize:T}),e.pages.length===0&&d.createElement(ke,{store:e}),e.audios.map(t=>d.createElement(zA,{key:t.id,audio:t,store:e}))))}),vj=`modulepreload`,yj=function(e,t){return new URL(e,t).href},bj={},xj=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=yj(t,n),t in bj)return;bj[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:vj,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};W.prototype._requestDraw=()=>{},If(!1),Op(`change-font-size`);var Sj=ok({key:new URLSearchParams(location.search).get(`key`)});window.store=Sj;var Cj=null;window.__polotnoLoadJspdf=async()=>(Cj||=xj(()=>import(`./jspdf.es.min-CBRoYge0.js`),__vite__mapDeps([0,1,2]),import.meta.url),await Cj);var wj=null;window.__polotnoLoadVideoExport=async()=>(wj||=xj(()=>import(`./lib-Cm7bIAAZ.js`),__vite__mapDeps([3,1]),import.meta.url),await wj),window.config={addGlobalFont:rp,setRichTextEnabled:Ep,setTextVerticalResizeEnabled:wp,setTextOverflow:Op,onLoadError:Xf,setAssetLoadTimeout:Hf,setFontLoadTimeout:Wf,unstable_setTextSplitAllowed:kp},u.createRoot(document.getElementById(`root`)).render(d.createElement(_j,{visiblePagesOffset:0,renderOnlyActivePage:!0,store:Sj,components:{PageControls:()=>null,Tooltip:()=>null}}));export{Rb as $,Kx as A,yS as B,lC as C,Jx as D,Yx as E,fS as F,Vx as G,Hx as H,dS as I,Bx as J,Ix as K,uS as L,rS as M,iS as N,qx as O,pS as P,Bb as Q,xS as R,xC as S,aC as T,Gx as U,Ux as V,Wx as W,Ib as X,Wb as Y,yx as Z,BS as _,ev as _t,EE as a,Cx as at,NS as b,xw as c,Ax as ct,VC as d,ax as dt,J as et,PC as f,ix as ft,OC as g,yv as gt,kC as h,jb as ht,CE as i,vx as it,oS as j,Xx as k,_w as l,Ob as lt,jC as m,Pb as mt,ME as n,sx as nt,xE as o,px as ot,MC as p,Px as pt,Rx as q,kE as r,Hb as rt,jT as s,kb as st,xj as t,tx as tt,XC as u,Xb as ut,HS as v,US as w,_C as x,ZS as y,SS as z};