UNPKG

@diffusionstudio/core-v2

Version:
40 lines (37 loc) 98.6 kB
/*! * :::::::: :::::::: ::::::::: :::::::::: * :+: :+: :+: :+: :+: :+: :+: * +:+ +:+ +:+ +:+ +:+ +:+ * +#+ +#+ +:+ +#++:++#: +#++:++# * +#+ +#+ +#+ +#+ +#+ +#+ * #+# #+# #+# #+# #+# #+# #+# * ######## ######## ### ### ########## * ::: ::: :::::::: * :+: :+: :+: :+: * +:+ +:+ +:+ * +#+ +:+ +#+ * +#+ +#+ +#+ * #+#+#+# #+# * ### ########## * * @diffusionstudio/core-v2 v2.0.1 * (c) 2025 Diffusion Studio Inc. * * Licensed under the Diffusion Studio Non-Commercial License. * You may NOT use this software for any commercial purposes. * * For commercial licensing, visit: * https://diffusion.studio */ (function(c,T){typeof exports=="object"&&typeof module<"u"?T(exports,require("mp4-muxer")):typeof define=="function"&&define.amd?define(["exports","mp4-muxer"],T):(c=typeof globalThis<"u"?globalThis:c||self,T(c.core={},c.Mp4Muxer))})(this,function(c,T){"use strict";class H extends Error{message;code;constructor({message:t="",code:e=""},...i){super(t,...i),console.error(t),this.code=e,this.message=t}}class v extends H{}class b extends H{}class _ extends H{}class Wt extends H{}function Pt(n,t=30){if(t<1)throw new b({code:"invalidArgument",message:"FPS must be greater or equal to 1"});return Math.round(n*t)}function Me(n,t=30){if(t<1)throw new b({code:"invalidArgument",message:"FPS must be greater or equal to 1"});return Math.round(n/t*1e3)/1e3}function A(n,t=30){if(t<1)throw new b({code:"invalidArgument",message:"FPS must be greater or equal to 1"});return Math.round(n/t*1e3)}class m{time;constructor(t=0,e=0,i=0,s=0){this.time=Math.round(t+e*1e3+i*6e4+s*36e5)}get millis(){return this.time}set millis(t){this.time=Math.round(t)}get frames(){return Pt(this.millis/1e3)}set frames(t){this.millis=A(t)}get seconds(){return this.millis/1e3}set seconds(t){this.millis=t*1e3}addMillis(t){return this.millis=this.millis+t,this}addFrames(t){const e=A(t);return this.millis=this.millis+e,this}add(t){return new m(t.millis+this.millis)}subtract(t){return new m(this.millis-t.millis)}static fromFrames(t,e){const i=new m;return i.millis=A(t,e),i}copy(){return new m(this.millis)}toJSON(){return this.millis}static fromJSON(t){return new m(t)}}function Oe(n){return Math.floor(n*255).toString(16).padStart(2,"0").toUpperCase()}function Ye(n,t){return n.reduce((e,i)=>{const s=i[t];return e[s]||(e[s]=[]),e[s].push(i),e},{})}function Rt(n,t){return[n.slice(0,t),n.slice(t)].filter(e=>e.length>0)}function Q(n,t){return t?Math.floor(Math.random()*(t-n+1)+n):n}async function Je(n){n<=0||await new Promise(t=>setTimeout(t,n))}function Ie(n){if(!n)throw"Assertion failed!"}function ze(n,t=300){let e;return(...i)=>{clearTimeout(e),e=setTimeout(()=>{n.apply(n,i)},t)}}function Bt(n,t,e){e<0&&(e=0);const i=n[t];n.splice(t,1),n.splice(e,0,i)}function Le(){return crypto.randomUUID().split("-").at(0)}function xt(n){return typeof n!="function"?!1:/^class\s/.test(Function.prototype.toString.call(n))}function Pe(n){return n.charAt(0).toUpperCase()+n.slice(1)}function jt(n){if(n.numberOfChannels===1)return n.getChannelData(0);const t=[];for(let o=0;o<n.numberOfChannels;o++)t.push(n.getChannelData(o));const e=Math.max(...t.map(o=>o.length)),i=new Float32Array(e*n.numberOfChannels);let s=0,r=0;for(;r<e;)t.forEach(o=>{i[s++]=o[r]!==void 0?o[r]:0}),r++;return i}function at(n,t,e){for(let i=0;i<e.length;i++)n.setUint8(t+i,e.charCodeAt(i))}function Ht(n,t,e){for(let i=0;i<t.length;i++,e+=2){const s=Math.max(-1,Math.min(1,t[i]));n.setInt16(e,s<0?s*32768:s*32767,!0)}return n}function Be(n,t,e){const r=t*2,o=8,a=36,l=n.length*2,h=a+l,f=new ArrayBuffer(o+h),d=new DataView(f);return at(d,0,"RIFF"),d.setUint32(4,h,!0),at(d,8,"WAVE"),at(d,12,"fmt "),d.setUint32(16,16,!0),d.setUint16(20,1,!0),d.setUint16(22,t,!0),d.setUint32(24,e,!0),d.setUint32(28,e*r,!0),d.setUint16(32,r,!0),d.setUint16(34,16,!0),at(d,36,"data"),d.setUint32(40,l,!0),Ht(d,n,o+a)}function je(n,t="audio/wav"){const e=jt(n),i=Be(e,n.numberOfChannels,n.sampleRate);return new Blob([i],{type:t})}function _t(n){const t=new Float32Array(n.length*n.numberOfChannels);let e=0;for(let i=0;i<n.numberOfChannels;i++){const s=n.getChannelData(i);t.set(s,e),e+=s.length}return t}function At(n){const t=n.numberOfChannels,e=n.length,i=new Int16Array(e*t);for(let s=0;s<e;s++)for(let r=0;r<t;r++){let o=n.getChannelData(r)[s]*32767;o>32767&&(o=32767),o<-32767&&(o=-32767),i[s*t+r]=o}return i}async function He(n,t=22050,e=Math.sqrt(2)){const i=await n.arrayBuffer(),s=new OfflineAudioContext({sampleRate:t,length:1}),r=await s.decodeAudioData(i),o=s.createBuffer(1,r.length,t);if(r.numberOfChannels>=2){const a=r.getChannelData(0),l=r.getChannelData(1),h=o.getChannelData(0);for(let f=0;f<r.length;++f)h[f]=e*(a[f]+l[f])/2;return o}return r}function _e(n,t=44100,e=2){if(n.sampleRate==t&&n.numberOfChannels==e)return n;const i=Math.floor(n.duration*t),r=new OfflineAudioContext(e,1,t).createBuffer(e,i,t);for(let o=0;o<n.numberOfChannels;o++){const a=n.getChannelData(o),l=r.getChannelData(o),h=n.sampleRate/t;for(let f=0;f<l.length;f++){const d=f*h,g=Math.floor(d),y=Math.ceil(d);if(y>=a.length)l[f]=a[g];else{const w=d-g;l[f]=a[g]*(1-w)+a[y]*w}}}return r}async function Qt(n){const{fps:t,height:e,width:i,bitrate:s}=n,r=["avc1.640034","avc1.4d0034","avc1.640028","avc1.640C32","avc1.64001f","avc1.42001E"],o=["prefer-hardware","prefer-software"],a=[];for(const h of r)for(const f of o)a.push({codec:h,hardwareAcceleration:f,width:i,height:e,bitrate:s,framerate:t});const l=[];if(!("VideoEncoder"in window))return l;for(const h of a){const f=await VideoEncoder.isConfigSupported(h);f.supported&&l.push(f.config??h)}return l.sort($t)}async function Dt(n){const{sampleRate:t,numberOfChannels:e,bitrate:i}=n,s=["mp4a.40.2","opus"],r=[];if(!("AudioEncoder"in window))return r;for(const o of s){const a=await AudioEncoder.isConfigSupported({codec:o,numberOfChannels:e,bitrate:i,sampleRate:t});a.supported&&a.config&&r.push(a.config)}return r}async function Kt(n){const t=await Dt(n.audio),e=await Qt(n.video);if(!e.length)throw new _({message:"Encoder can't be configured with any of the tested codecs",code:"codecsNotSupported"});return[e[0],t[0]]}function $t(n,t){const e=n.hardwareAcceleration??"",i=t.hardwareAcceleration??"";return e<i?-1:e>i?1:0}async function St(n,t="untitled"){const e=document.createElement("a");if(document.head.appendChild(e),e.download=t,typeof n=="string"&&n.startsWith("data:image/svg+xml;base64,")){const i=n.split(",")[1],s=atob(i),r=new Array(s.length);for(let l=0;l<s.length;l++)r[l]=s.charCodeAt(l);const o=new Uint8Array(r),a=new Blob([o],{type:"image/svg+xml"});e.href=URL.createObjectURL(a),e.download=t.split(".")[0]+".svg"}else typeof n=="string"?e.href=n:e.href=URL.createObjectURL(n);e.click(),e.remove()}async function Ae(n,t=!0){return new Promise(e=>{const i=document.createElement("input");i.type="file",i.accept=n,i.multiple=t,i.onchange=s=>{const r=Array.from(s.target?.files??[]);e(r)},i.click()})}function qt(n){return`${n.hours.toString().padStart(2,"0")}:${n.minutes.toString().padStart(2,"0")}:${n.seconds.toString().padStart(2,"0")},`+n.milliseconds.toString().padStart(3,"0")}function te(n){const t=new Date(1970,0,1);return t.setSeconds(n),t.setMilliseconds(Math.round(n%1*1e3)),{hours:t.getHours(),minutes:t.getMinutes(),seconds:t.getSeconds(),milliseconds:t.getMilliseconds()}}class Y{words=[];constructor(t){t&&(this.words=t)}get duration(){return this.stop.subtract(this.start)}get text(){return this.words.map(({text:t})=>t).join(" ")}get start(){return this.words.at(0)?.start??new m}get stop(){return this.words.at(-1)?.stop??new m}}var lt=(n=>(n.en="en",n.de="de",n))(lt||{});class ct{id=crypto.randomUUID();text;start;stop;confidence;constructor(t,e,i,s){this.text=t,this.start=new m(e),this.stop=new m(i),this.confidence=s}get duration(){return this.stop.subtract(this.start)}}class S{id=crypto.randomUUID();language=lt.en;groups=[];get text(){return this.groups.map(({text:t})=>t).join(" ")}get words(){return this.groups.flatMap(({words:t})=>t)}constructor(t=[],e=lt.en){this.groups=t,this.language=e}*iter({count:t,duration:e,length:i}){for(const s of this.groups){let r;for(const[o,a]of s.words.entries())r&&(t&&r.words.length>=Q(...t)?(yield r,r=void 0):e&&r?.duration.seconds>=Q(...e)?(yield r,r=void 0):i&&r.text.length>=Q(...i)&&(yield r,r=void 0)),r?r.words.push(a):r=new Y([a]),o==s.words.length-1&&(yield r)}}optimize(){const t=this.groups.flatMap(e=>e.words);for(let e=0;e<t.length-1;e++){const i=t[e],s=t[e+1];s.start.millis-i.stop.millis<0?s.start.millis=i.stop.millis+1:i.stop.millis=s.start.millis-1}return this}toSRT(t={}){let e=1,i="";for(const s of this.iter(t)){const r=te(s.start.seconds),o=te(s.stop.seconds);i+=`${e} `+qt(r)+" --> "+qt(o)+` ${s.text} `,e+=1}return{text:i,blob:new Blob([i],{type:"text/plain;charset=utf8"})}}toJSON(){return this.groups.map(t=>t.words.map(e=>({token:e.text,start:e.start.millis,stop:e.stop.millis})))}slice(t,e=!0){let i=0;const s=[];for(const r of this.groups)for(const o of r.words)if(s.length==0&&e&&(i=o.start.millis),s.push(new ct(o.text,o.start.millis-i,o.stop.millis-i)),s.length==t)return new S([new Y(s)]);return new S([new Y(s)])}copy(){return S.fromJSON(this.toJSON())}static fromJSON(t){const e=new S;for(const i of t){const s=new Y;for(const r of i)s.words.push(new ct(r.token,r.start,r.stop));e.groups.push(s)}return e}static async from(t,e){if(t instanceof File)return S.fromJSON(JSON.parse(await t.text()));const i=await fetch(t,e);if(!i.ok)throw new v({code:"unexpectedIOError",message:"An unexpected error occurred while fetching the file"});return S.fromJSON(await i.json())}}class Z{id=crypto.randomUUID();toJSON(){const t={};return(this.constructor.__serializableProperties||[]).forEach(({propertyKey:i,serializer:s})=>{const r=this[i];s&&r instanceof s?t[i]=r.toJSON():t[i]=r}),t}static fromJSON(t){const e=new this;return(this.__serializableProperties||[]).forEach(({propertyKey:s,serializer:r})=>{if(t.hasOwnProperty(s))if(r){const o=r.fromJSON(t[s]);e[s]=o}else e[s]=t[s]}),e}}function u(n){return function(t,e){t.constructor.__serializableProperties||(t.constructor.__serializableProperties=[]),t.constructor.__serializableProperties.push({propertyKey:e,serializer:n})}}function X(n){return class extends n{_handlers={};on(e,i){if(typeof i!="function")throw new Error("The callback of an event listener needs to be a function.");const s=crypto.randomUUID();return this._handlers[e]?this._handlers[e][s]=i:this._handlers[e]={[s]:i},s}off(e,...i){if(e){if(e==="*"){this._handlers={};return}for(const s of Object.values(this._handlers))e in s&&delete s[e];for(const s of i)this.off(s)}}emit(e,i){const s=new CustomEvent(e,{detail:i});Object.defineProperty(s,"currentTarget",{writable:!1,value:this});for(const r in this._handlers[e]??{})this._handlers[e]?.[r](s);for(const r in this._handlers["*"]??{})this._handlers["*"]?.[r](s)}bubble(e){return this.on("*",i=>{e.emit(i.type,i.detail)})}resolve(e){return(i,s)=>{this.on("error",s),this.on(e,i)}}}}class ht extends X(Z){_key;_value;_store;loaded=!1;constructor(t,e,i){super(),this._store=t,this._key=e,this.initValue(i)}get key(){return this._key}get value(){return this._value}set value(t){this._value=t,this._store.set(this._key,t),this.emit("update",void 0)}async initValue(t){t instanceof Promise?this._value=await t:this._value=t,this.loaded=!0,this.emit("update",void 0)}}class Qe{storageEngine;namespace;constructor(t,e=localStorage){this.storageEngine=e,this.namespace=t}define(t,e,i){const s=this.get(t);return s===null?(this.set(t,e),new ht(this,t,e)):i&&s!=null?new ht(this,t,i(s)):new ht(this,t,s)}set(t,e){this.storageEngine.setItem(this.getStorageId(t),JSON.stringify({value:e}))}get(t){const e=this.storageEngine.getItem(this.getStorageId(t));return e?JSON.parse(e).value:null}remove(t){this.storageEngine.removeItem(this.getStorageId(t))}getStorageId(t){return this.namespace?`${this.namespace}.${t}`:t}}class De{worker;constructor(t){this.worker=new t,this.worker.onerror=console.error}async run(t,e){return this.worker.postMessage({type:"init",...t??{}}),await new Promise((i,s)=>{this.worker.addEventListener("message",r=>{e?.(r.data),r.data.type=="result"&&(r.data.type=void 0,i(r.data)),r.data.type=="error"&&s(r.data.message)})}).then(i=>({result:i,error:void 0})).catch(i=>({result:void 0,error:i})).finally(()=>{this.worker.terminate()})}}function Ke(n){return async t=>{try{await n(t)}catch(e){self.postMessage({type:"error",message:e?.message??"An unkown worker error occured"})}}}function ee(){return class extends X(class{}){}}function $e(n){const t=n.startsWith("#")?n.slice(1):n,e=parseInt(t,16),i=e>>16&255,s=e>>8&255,r=e&255;return{r:i,g:s,b:r}}function qe(n,t,e){return`#${((1<<24)+(Math.round(n)<<16)+(Math.round(t)<<8)+Math.round(e)).toString(16).slice(1)}`}function Ft(n,t){switch(t){case"ease-in":return n*n;case"ease-out":return n*(2-n);case"ease-in-out":return n<.5?2*n*n:-1+(4-2*n)*n;case"ease-out-in":if(n<.5){const e=n*2;return e*(2-e)/2}else{const e=(n-.5)*2;return e*e/2+.5}default:return n}}function dt(n,t,e){return n+(t-n)*e}function ie(n){const t=$e(n);return ti(t.r,t.g,t.b)}function ti(n,t,e){n/=255,t/=255,e/=255;const i=Math.max(n,t,e),s=Math.min(n,t,e);let r=0,o=0;const a=(i+s)/2;if(i!==s){const l=i-s;switch(o=a>.5?l/(2-i-s):l/(i+s),i){case n:r=(t-e)/l+(t<e?6:0);break;case t:r=(e-n)/l+2;break;case e:r=(n-t)/l+4;break}r/=6}return{h:Math.round(r*360),s:Math.round(o*100),l:Math.round(a*100)}}function ei(n,t,e){t/=100,e/=100,n=(n+360)%360;function i(h,f,d){return d<0&&(d+=1),d>1&&(d-=1),d<1/6?h+(f-h)*6*d:d<1/2?f:d<2/3?h+(f-h)*(2/3-d)*6:h}const s=e<.5?e*(1+t):e+t-e*t,r=2*e-s,o=i(r,s,n/360+1/3),a=i(r,s,n/360),l=i(r,s,n/360-1/3);return qe(Math.round(o*255),Math.round(a*255),Math.round(l*255))}function ii(n,t){const{frames:e,extrapolate:i="clamp",easing:s}=n;if(t<=e[0].frame)return e[0].value;if(t>=e[e.length-1].frame)return e[e.length-1].value;let r,o;for(let y=0;y<e.length-1;y++)if(t>=e[y].frame&&t<=e[y+1].frame){r=e[y],o=e[y+1];break}if(!r||!o)throw new Error("Unexpected error in keyframe interpolation");const a=(t-r.frame)/(o.frame-r.frame),l=Ft(a,r.easing??s),h=ie(r.value),f=ie(o.value);let d=h.h,g=f.h;return Math.abs(g-d)>180&&(d<g?d+=360:g+=360),ei(dt(d,g,l),dt(h.s,f.s,l),dt(h.l,f.l,l))}function se(n,t){const{frames:e,extrapolate:i="clamp",easing:s}=n;if(t<=e[0].frame)return e[0].value;if(t>=e[e.length-1].frame)return e[e.length-1].value;let r,o;for(let h=0;h<e.length-1;h++)if(t>=e[h].frame&&t<=e[h+1].frame){r=e[h],o=e[h+1];break}if(!r||!o)throw new Error("Unexpected error in keyframe interpolation");const a=(t-r.frame)/(o.frame-r.frame),l=Ft(a,r.easing??s);return dt(r.value,o.value,l)}function si(n,t){const{frames:e,extrapolate:i="clamp"}=n,s=e.map(a=>({value:parseFloat(a.value.replace("%","")),frame:a.frame,easing:a.easing})),o=se({key:"",extrapolate:i,frames:s},t);return`${Math.round(o)}%`}function ni(n,t){const{frames:e,extrapolate:i="clamp"}=n;if(t<=e[0].frame)return e[0].value;if(t>=e[e.length-1].frame)return e[e.length-1].value;let s,r;for(let d=0;d<e.length-1;d++)if(t>=e[d].frame&&t<=e[d+1].frame){s=e[d],r=e[d+1];break}if(!s||!r)throw new Error("Unexpected error in keyframe interpolation");const o=(t-s.frame)/(r.frame-s.frame),a=Ft(o,s.easing),l=r.value,h=l.length,f=Math.floor(a*h);return l.slice(0,f)}var ri=Object.defineProperty,J=(n,t,e,i)=>{for(var s=void 0,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=o(t,e,s)||s);return s&&ri(t,e,s),s};const C=class Xe extends X(Z){_name;_delay=new m;_duration=new m(0,16);data={};initialized=!1;type="base";source;rendered=!1;createdAt=new Date;disabled=!1;animations=[];track;get name(){return this._name??this.source?.name}set name(t){this._name=t}get start(){return this._delay}get stop(){return this._delay.add(this._duration)}get delay(){return this._delay}get duration(){return this._duration}constructor(t={}){super(),Object.assign(this,t)}animate(t){const e=t.subtract(this.start).frames;for(const i of this.animations){const s=i?.frames[0].value;typeof s=="number"?this[i.key]=se(i,e):typeof s=="string"&&s.match(/^[0-9]{1,}%$/)?this[i.key]=si(i,e):typeof s=="string"&&s.match(/^#[0-9abcdef]{3,8}$/i)?this[i.key]=ii(i,e):typeof s=="string"&&(this[i.key]=ni(i,e))}return this}async connect(t){this.track=t,this.emit("attach",void 0)}set delay(t){typeof t=="number"?this._delay.frames=t:this._delay=t,this.emit("frame",this._delay.frames)}set duration(t){typeof t=="number"?this._duration.frames=t:this._duration=t,this._duration.millis<=0&&(this._duration.frames=1),this.emit("frame",this._duration.frames)}offset(t){return typeof t=="number"?(this.delay.addFrames(t),this.emit("offset",m.fromFrames(t))):(this.delay.addMillis(t.millis),this.emit("offset",t)),this.emit("frame",void 0),this}async init(){}enter(){}update(t,e,i="pause",s=30){}render(t,e){}exit(){}detach(){return this.track?.remove(this),this}trim(t=this.start,e=this.stop){return typeof e=="number"&&(e=m.fromFrames(e)),typeof t=="number"&&(t=m.fromFrames(t)),this.delay=t,this.duration=e.subtract(t),this}async split(t){if(t||(t=this.track?.composition?.ticker.frame),typeof t=="number"&&(t=m.fromFrames(t)),!t||t.millis<=this.start.millis||t.millis>=this.stop.millis)throw new b({code:"splitOutOfRange",message:"Cannot split clip at the specified time"});if(!this.track)throw new b({code:"trackNotAttached",message:"Track must be attached to a track"});const e=this.animate(t).copy();this.duration=t.subtract(this.delay),e.trim(t.addMillis(1),e.stop),e.animations=[];const i=this.track.clips.findIndex(s=>s.id==this.id);return await this.track.add(e,i+1),e}copy(){return Xe.fromJSON(JSON.parse(JSON.stringify(this)))}};J([u()],C.prototype,"_name"),J([u(m)],C.prototype,"_delay"),J([u(m)],C.prototype,"_duration"),J([u()],C.prototype,"data"),J([u()],C.prototype,"disabled"),J([u()],C.prototype,"animations");let G=C;var oi=Object.defineProperty,M=(n,t,e,i)=>{for(var s=void 0,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=o(t,e,s)||s);return s&&oi(t,e,s),s};class W extends X(Z){duration=new m(0,16);state="IDLE";data={};added=!1;type="base";name="";mimeType;externalURL;external=!1;file;element=new Image;get objectURL(){return this.element.src}async getFile(){if(!this.file&&this.state=="LOADING"&&await new Promise(this.resolve("load")),!this.file)throw new b({code:"fileNotAccessible",message:"The desired file cannot be accessed"});return this.file}async loadElement(){this.state!="READY"&&(this.element.setAttribute("src",URL.createObjectURL(await this.getFile())),await new Promise((t,e)=>{this.element.onload=()=>t(),this.element.onerror=()=>e(new v({code:"sourceNotProcessable",message:"An error occurred while processing the input medium."}))}))}async loadFile(t){this.name=t.name,this.mimeType=bt(t.type),this.external=!1,this.file=t}async loadUrl(t,e){const i=await fetch(t,e);if(!i?.ok)throw new v({code:"unexpectedIOError",message:"An unexpected error occurred while fetching the file"});const s=await i.blob();this.name=t.toString().split("/").at(-1)??"",this.external=!0,this.file=new File([s],this.name,{type:s.type}),this.externalURL=t,this.mimeType=bt(s.type)}async from(t,e){try{this.state="LOADING",t instanceof File?await this.loadFile(t):await this.loadUrl(t,e),await this.loadElement(),this.state="READY",this.emit("load",void 0)}catch(i){throw this.state="ERROR",this.emit("error",new Error(String(i))),i}return this}async loaded(){if(this.state!="READY"){if(this.state=="ERROR")throw new v({code:"sourceNotProcessable",message:"An error occurred while processing the input medium."});this.state=="IDLE"&&this.file?await this.from(this.file):await new Promise(this.resolve("load"))}}async arrayBuffer(){return await(await this.getFile()).arrayBuffer()}async remove(){this.state="IDLE",this.element.removeAttribute("src"),this.externalURL=void 0,delete this.file}async download(){const t=await this.getFile();St(t,this.name)}async thumbnail(){return this.element}static async from(t,e,i=new this){return i.from(t,e)}}M([u()],W.prototype,"duration"),M([u()],W.prototype,"data"),M([u()],W.prototype,"type"),M([u()],W.prototype,"name"),M([u()],W.prototype,"mimeType"),M([u()],W.prototype,"externalURL"),M([u()],W.prototype,"external");const ne="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3C/svg%3E";function ai(n){const t=new TextEncoder().encode(n);let e="";const i=t.byteLength;for(let s=0;s<i;s++)e+=String.fromCharCode(t[s]);return btoa(e)}function li(n){if(!n||!n.body)return ne;const t=n.body.scrollWidth,e=n.body.scrollHeight,i=n.cloneNode(!0),s=i.getElementsByTagName("style").item(0),r=i.getElementsByTagName("body").item(0);if(r?.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),!r)return ne;const o=new XMLSerializer,a=s?o.serializeToString(s):"",l=o.serializeToString(r),h=` <svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${e}"> body { padding: 0; } ${a} <foreignObject width="100%" height="100%"> ${l} </foreignObject> </svg>`;return"data:image/svg+xml;base64,"+ai(h)}function I(n){class t extends n{get height(){return 1080}get width(){return 1920}get aspectRatio(){return this.width/this.height}}return t}class re extends I(W){}class ut extends I(W){type="html";element=document.createElement("iframe");constructor(){super(),this.element.style.position="absolute",this.element.style.width="0",this.element.style.height="0",this.element.style.border="0",this.element.style.visibility="hidden",document.body.appendChild(this.element)}get height(){return this.element.contentWindow?.document.body.scrollHeight??0}get width(){return this.element.contentWindow?.document.body.scrollWidth??0}get document(){return this.element.contentWindow?.document}get imageUrl(){return li(this.document)}async thumbnail(){await this.loaded();const t=new Image;return t.className="object-contain w-full aspect-video h-auto",t.src=this.imageUrl,t}}function ci(n,t={}){const{threshold:e=.02,hopSize:i=1024,minDuration:s=500}=t,r=[],o=n.getChannelData(0),a=n.sampleRate,l=Math.floor(s/1e3*a);let h=null,f=0;for(let d=0;d<o.length;d+=i){let g=0;const y=Math.min(d+i,o.length);for(let w=d;w<y;w++)g+=o[w]*o[w];g=Math.sqrt(g/(y-d)),g<e?(f+=i,h===null&&(h=d)):(h!==null&&f>=l&&r.push({start:new m(0,h/a),stop:new m(0,d/a)}),h=null,f=0)}return h!==null&&f>=l&&r.push({start:new m(0,h/a),stop:new m(0,o.length/a)}),r}const vt=3e3;class U extends I(W){decoding=!1;_silences;duration=new m(0,0,0,1);type="audio";element=new Audio;transcript;audioBuffer;async loadElement(){this.state!="READY"&&(this.element.src=URL.createObjectURL(await this.getFile()),await new Promise((t,e)=>{this.element.onloadedmetadata=()=>{this.duration.seconds=this.element.duration,t()},this.element.onerror=()=>e(new v({code:"sourceNotProcessable",message:"An error occurred while processing the input medium."}))}))}async decode(t=2,e=48e3,i=!1){if(this.decoding&&i&&(await new Promise(this.resolve("update")),this.audioBuffer))return this.audioBuffer;this.decoding=!0;const s=await this.arrayBuffer(),o=await new OfflineAudioContext(t,1,e).decodeAudioData(s);return this.duration.seconds=o.duration,i&&(this.audioBuffer=o),this.decoding=!1,this.emit("update",void 0),o}async sample({length:t=60,start:e=0,stop:i,logarithmic:s=!1}={}){typeof e=="object"&&(e=e.millis),typeof i=="object"&&(i=i.millis);const r=this.audioBuffer??await this.decode(1,vt,!0),o=r.getChannelData(0),a=Math.floor(Math.max(e*vt/1e3,0)),l=i?Math.floor(Math.min(i*vt/1e3,r.length)):r.length,h=Math.floor((l-a)/t),f=new Float32Array(t);for(let d=0;d<t;d++){const g=a+d*h,y=g+h;let w=Number.NEGATIVE_INFINITY;for(let k=g;k<y;k++){const Te=o[k];Te>w&&(w=Te)}f[d]=s?Math.log2(1+w):w}return f}async thumbnail(t={}){const e=await this.sample(t),i=document.createElement("div");i.className="flex flex-row absolute inset-0 audio-samples";for(const s of e){const r=document.createElement("div");r.className="audio-sample-item",r.style.height=`${s*100}%`,i.appendChild(r)}return i}async silences(t={}){if(this._silences)return this._silences;const e=await this.arrayBuffer(),s=await new OfflineAudioContext(1,1,24e3).decodeAudioData(e);return this._silences=ci(s,t),this._silences}}class ft extends I(W){type="image";get height(){return this.element.naturalHeight}get width(){return this.element.naturalWidth}async thumbnail(){return this.element.className="object-cover w-full aspect-video h-auto",this.element}}class mt extends I(U){downloadInProgress=!0;type="video";element=document.createElement("video");get height(){return this.element.videoHeight}get width(){return this.element.videoWidth}async loadElement(){this.state!="READY"&&(this.element.controls=!1,this.element.playsInline=!0,this.element.style.display="hidden",this.element.crossOrigin="anonymous",this.element.src=this.external?`${this.externalURL}`:URL.createObjectURL(await this.getFile()),await new Promise((t,e)=>{this.element.onloadedmetadata=()=>{this.duration.seconds=this.element.duration,t()},this.element.onerror=()=>e(new v({code:"sourceNotProcessable",message:"An error occurred while processing the input medium."}))}))}async loadUrl(t,e){const i=await fetch(t,e);if(!i?.ok)throw new v({code:"unexpectedIOError",message:"An unexpected error occurred while fetching the file"});this.name=t.toString().split("/").at(-1)??"",this.external=!0,this.externalURL=t,this.mimeType=bt(i.headers.get("Content-type")),this.downloadInProgress=!0,i.blob().then(s=>{this.file=new File([s],this.name,{type:s.type}),this.emit("load",void 0)}).finally(()=>{this.downloadInProgress=!1})}async getFile(){if(!this.file&&this.downloadInProgress&&await new Promise(this.resolve("load")),!this.file)throw new b({code:"fileNotAccessible",message:"The desired file cannot be accessed"});return this.file}async thumbnail(){return this.element.className="object-cover w-full aspect-video h-auto",this.element.controls=!1,this.element.addEventListener("mousemove",t=>{const e=this.element.getBoundingClientRect(),i=t.clientX-(e?.left??0),s=this.element.duration;s&&e&&e.width>0&&(this.element.currentTime=Math.round(s*(i/e.width)))}),this.element}}class hi{static fromType(t){switch(t.type){case"video":return new N;case"audio":return new q;case"html":return new tt;case"image":return new K;case"text":return new $;default:return new G}}static fromSource(t){if(t.type=="audio"&&t instanceof U)return new q(t);if(t.type=="video"&&t instanceof mt)return new N(t);if(t.type=="image"&&t instanceof ft)return new K(t);if(t.type=="html"&&t instanceof ut)return new tt(t)}}class di{static fromJSON(t){return[new m(t[0]),new m(t[1])]}}var ui=Object.defineProperty,fi=Object.getOwnPropertyDescriptor,pt=(n,t,e,i)=>{for(var s=i>1?void 0:i?fi(t,e):t,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(t,e,s):o(s))||s);return i&&s&&ui(t,e,s),s};const D=class Ge extends G{source=new U;playing=!1;range=[new m,new m];constructor(t={}){super(),Object.assign(this,t)}get transcript(){if(!this.source.transcript)return;if(!this.duration.millis)return this.source.transcript;const t=new S(this.source.transcript.groups.map(e=>{const i=new Y(e.words.filter(o=>o.stop.millis>this.range[0].millis&&o.start.millis<this.range[1].millis).map(o=>new ct(o.text,o.start.millis,o.stop.millis))),s=i.words[0],r=i.words[i.words.length-1];return s&&s.start.millis<this.range[0].millis&&(s.start.millis=this.range[0].millis),r&&r.stop.millis>this.range[1].millis&&(r.stop.millis=this.range[1].millis),i}).filter(e=>e.words.length>0));return t.id=this.source.transcript.id,t}set transcript(t){this.source.transcript=t}get start(){return this.range[0].add(this._delay)}get stop(){return this.range[1].add(this._delay)}get duration(){return this.range[1].subtract(this.range[0])}set duration(t){typeof t=="number"?this.range[1]=this.range[0].copy().addFrames(t):this.range[1]=this.range[0].add(t),this.range[1].millis<=this.range[0].millis&&(this.range[1]=this.range[0].copy().addMillis(1)),this.range[1].millis>this.source.duration.millis&&(this.range[1]=this.source.duration),this.emit("frame",this.stop.frames)}get muted(){return this.element?.muted??!1}set muted(t){this.element&&(this.element.muted=t)}trim(t=this.start,e=this.stop){return typeof t=="number"&&(t=m.fromFrames(t)),typeof e=="number"&&(e=m.fromFrames(e)),this.subclip(t.subtract(this.delay),e.subtract(this.delay))}seek(t){return new Promise((e,i)=>{if(!this.element)return i(new Wt({code:"elementNotDefined",message:"Cannot seek on undefined element"}));(t.millis<this.start.millis||t.millis>this.stop.millis)&&(t=this.start),this.element.onerror=()=>i(this.element?.error),this.element.pause(),this.element.currentTime=t.subtract(this._delay).seconds,this.element.onseeked=()=>e()})}exit(){this.playing&&this.element?.pause()}subclip(t,e){if(t||(t=this.range[0]),e||(e=this.range[1]),typeof t=="number"&&(t=m.fromFrames(t)),typeof e=="number"&&(e=m.fromFrames(e)),t.millis>=e.millis)throw new b({code:"invalidKeyframe",message:"Start can't lower than or equal the stop"});return t.millis<0&&(this.range[0].millis=0,t=this.range[0]),e.millis>this.source.duration.millis&&this.source.duration.millis&&(e=this.source.duration),this.range=[t,e],this.emit("frame",void 0),this}get volume(){return this.element?.volume??1}set volume(t){this.element&&(this.element.volume=t)}copy(){const t=Ge.fromJSON(JSON.parse(JSON.stringify(this)));return t.source=this.source,t}async split(t){if(t||(t=this.track?.composition?.ticker.frame),typeof t=="number"&&(t=m.fromFrames(t)),!t||t.millis<=this.start.millis||t.millis>=this.stop.millis)throw new b({code:"invalidKeyframe",message:"Cannot split clip at the specified time"});if(!this.track)throw new Wt({code:"trackNotDefined",message:"Clip must be attached to a track"});const e=t.subtract(this._delay),i=this.animate(t).copy();this.range[1]=e.copy(),i.range[0]=e.copy().addMillis(1),i.animations=[];const s=this.track.clips.findIndex(r=>r.id==this.id);return await this.track.add(i,s+1),i}async createCaptions(t){if(!this.track?.composition)throw new b({code:"compositionNotDefined",message:"Captions can only be generated after the clip has been added to the composition"});return await this.track.composition.createTrack("caption").from(this).createCaptions(t)}async removeSilences(t={}){await this.init();const e=(await this.source.silences(t)).filter(r=>oe(r,this.range)).sort((r,o)=>r.start.millis-o.start.millis);if(e.length==0)return[this];const i=t.padding??500,s=[this];for(const r of e){const o=s.at(-1);if(!o)break;if(!oe(r,o.range))continue;const a=new m(Math.min(r.start.millis+i,r.stop.millis));if(r.start.millis>o.range[0].millis&&r.stop.millis<o.range[1].millis){const l=o.copy();o.range[1]=a,l.range[0]=r.stop,s.push(l)}else r.start.millis<=o.range[0].millis?o.range[0]=r.stop:r.stop.millis>=o.range[1].millis&&(o.range[1]=a)}return s}};pt([u(di)],D.prototype,"range",2),pt([u(S)],D.prototype,"transcript",1),pt([u()],D.prototype,"muted",1),pt([u()],D.prototype,"volume",1);let z=D;function oe(n,t){return n.start.millis>=t[0].millis&&n.start.millis<=t[1].millis||n.stop.millis<=t[1].millis&&n.stop.millis>=t[0].millis}function Tt(n,t){return t=="lower"?n.toLocaleLowerCase():t=="upper"?n.toUpperCase():n}function gt(n="#000000",t=100){return`${n}${Math.round(t/100*255).toString(16)}`}function p(n,t){return typeof n=="number"?n:Number.parseInt(n.replace("%",""))*t/100}class yt{canvas=document.createElement("canvas");ctx=this.canvas.getContext("2d");resolution=1;width=1920;height=1080;background="#000000";textScale=4;constructor(t=1920,e=1080,i="#000000",s=1){this.canvas.style.background=i,this.ctx.imageSmoothingEnabled=!1,this.resolution=s,this.background=i,this.resize(t,e)}resize(t,e){return this.width=Math.round(t),this.height=Math.round(e),this.canvas.width=Math.round(this.width*this.resolution),this.canvas.height=Math.round(this.height*this.resolution),this}copy(t=this.resolution){return new yt(this.width,this.height,this.background,t)}clear(t){let e=0,i=0,s=this.width*this.resolution,r=this.height*this.resolution;return this.ctx.fillStyle=this.background,t&&(e=p(t.x??0,this.width)*this.resolution,i=p(t.y??0,this.height)*this.resolution,s=p(t.width,this.width)*this.resolution,r=p(t.height,this.height)*this.resolution),this.ctx.clearRect(e,i,s,r),this.ctx.fillRect(e,i,s,r),this}rect(t){return this.ctx.beginPath(),t.radius?this.ctx.roundRect(p(t.x??0,this.width)*this.resolution,p(t.y??0,this.height)*this.resolution,p(t.width,this.width)*this.resolution,p(t.height,this.height)*this.resolution,t.radius*this.resolution):this.ctx.rect(p(t.x??0,this.width)*this.resolution,p(t.y??0,this.height)*this.resolution,p(t.width,this.width)*this.resolution,p(t.height,this.height)*this.resolution),this.ctx.closePath(),this}circle(t){return this.ctx.beginPath(),this.ctx.arc(p(t.cx,this.width)*this.resolution,p(t.cy,this.height)*this.resolution,t.radius*this.resolution,0,Math.PI*2),this.ctx.closePath(),this}image(t,e){return e.width&&e.height?this.ctx.drawImage(t,p(e.x??0,this.width)*this.resolution,p(e.y??0,this.height)*this.resolution,p(e.width,this.width)*this.resolution,p(e.height,this.height)*this.resolution):this.ctx.drawImage(t,p(e.x??0,this.width)*this.resolution,p(e.y??0,this.height)*this.resolution),this}clip(t,e){return t&&this.ctx.clip(t,e),this}opacity(t){return this.ctx.globalAlpha=t/100,this}text(t){return t.font&&(this.ctx.font=this.createFontString(t.font.style,t.font.weight,t.font.size*this.resolution,t.font.family)),t.color&&(this.ctx.fillStyle=t.color),t.alignment&&(this.ctx.textAlign=t.alignment),t.baseline&&(this.ctx.textBaseline=t.baseline),this}strokeText(t,e){return this.ctx.strokeText(t,p(e.x,this.width)*this.resolution,p(e.y,this.height)*this.resolution),this}fillText(t,e){return this.ctx.fillText(t,p(e.x,this.width)*this.resolution,p(e.y,this.height)*this.resolution),this}measureText(t,e){return this.ctx.font=this.createFontString(e.style,e.weight,e.size,e.family),this.ctx.measureText(t)}transform(t){return t?(t.translate&&this.ctx.translate(p(t.translate.x,this.width)*this.resolution,p(t.translate.y,this.height)*this.resolution),t.rotate&&this.ctx.rotate(t.rotate*Math.PI/180),t.scale&&this.ctx.scale(p(t.scale.x,this.width),p(t.scale.y,this.height)),this):(this.ctx.setTransform(1,0,0,1,0,0),this)}blendMode(t){return t&&(this.ctx.globalCompositeOperation=t),this}save(){return this.ctx.save(),this}restore(){return this.ctx.restore(),this}filter(t){return t?(this.ctx.filter=t,this):this}fill(t,e=!1){if(!t)return this.ctx.fillStyle="transparent",this;if(typeof t.color=="string")this.ctx.fillStyle=gt(t.color,t.opacity);else if("type"in t.color){const i=this.createGradient(t.color);this.ctx.fillStyle=i}else if("image"in t.color){const i=this.ctx.createPattern(t.color.image,t.color.repetition);this.ctx.fillStyle=i??""}return e&&this.ctx.fill(),this}shadow(t){return t?(this.ctx.fillStyle=this.ctx.shadowColor=gt(t.color,t.opacity),this.ctx.shadowOffsetX=(t.offsetX??0)*this.resolution*this.textScale,this.ctx.shadowOffsetY=(t.offsetY??0)*this.resolution*this.textScale,this.ctx.shadowBlur=(t.blur??24)*this.resolution*this.textScale,this):(this.ctx.shadowColor="transparent",this.ctx.shadowBlur=0,this.ctx.shadowOffsetX=0,this.ctx.shadowOffsetY=0,this)}stroke(t,e=!1){return t?(this.ctx.strokeStyle=gt(t.color,t.opacity),this.ctx.lineWidth=(t.width??1)*this.resolution*this.textScale,t.lineCap&&(this.ctx.lineCap=t.lineCap),t.lineJoin&&(this.ctx.lineJoin=t.lineJoin),t.miterLimit&&(this.ctx.miterLimit=t.miterLimit),e&&this.ctx.stroke(),this):(this.ctx.strokeStyle="transparent",this.ctx.lineWidth=0,this.ctx.lineCap="butt",this.ctx.lineJoin="miter",this.ctx.miterLimit=10,this)}mount(t){t.appendChild(this.canvas)}unmount(){this.canvas.parentElement?.removeChild(this.canvas)}createGradient(t){let e;return t.type==="linear"?e=this.ctx.createLinearGradient(0,0,this.canvas.width,0):e=this.ctx.createRadialGradient(this.canvas.width/2,this.canvas.height/2,0,this.canvas.width/2,this.canvas.height/2,this.canvas.width/2),t.stops.forEach(i=>{e.addColorStop(i.offset,i.color)}),e}createFontString(t,e,i,s){return`${t??"normal"} ${e??"400"} ${(i??16)*this.textScale}px ${s??"Arial"}`.trim()}watermark(t){t&&(this.ctx.save(),this.ctx.font=`${46*this.resolution}px Verdana`,this.ctx.fillStyle="#ffffff",this.ctx.textAlign="center",this.ctx.textBaseline="middle",this.ctx.strokeStyle="#000000",this.ctx.lineWidth=8*this.resolution,this.ctx.strokeText(t,this.width*this.resolution*.5,this.height*this.resolution*.9),this.ctx.fillText(t,this.width*this.resolution*.5,this.height*this.resolution*.9),this.ctx.restore())}}var mi=Object.defineProperty,V=(n,t,e,i)=>{for(var s=void 0,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=o(t,e,s)||s);return s&&mi(t,e,s),s};function O(n){class t extends n{source=new re;_height;_width;mask;anchorX=0;anchorY=0;scaleX=1;scaleY=1;translateX=0;translateY=0;freeTransform=!0;x=0;y=0;rotation=0;opacity=100;filter;blendMode;get translate(){return{x:this.translateX,y:this.translateY}}set translate(i){typeof i=="number"?(this.translateX=i,this.translateY=i):(this.translateX=i.x,this.translateY=i.y)}get anchor(){return{x:this.anchorX,y:this.anchorY}}set anchor(i){typeof i=="number"?(this.anchorX=i,this.anchorY=i):(this.anchorX=i.x,this.anchorY=i.y)}get scale(){return{x:this.scaleX,y:this.scaleY}}set scale(i){typeof i=="number"?(this.scaleX=i,this.scaleY=i):(this.scaleX=i.x,this.scaleY=i.y)}get height(){return this._height??this.source.height}set height(i){this._height=i}get width(){return this._width??this.source.width}set width(i){this._width=i}get position(){return{x:this.x,y:this.y}}set position(i){typeof i=="string"?(this.x="50%",this.y="50%",this.anchor=.5):(this.x=i.x,this.y=i.y)}get size(){const i=this.track?.composition?.width??Number.POSITIVE_INFINITY,s=this.track?.composition?.height??Number.POSITIVE_INFINITY;if(this.freeTransform&&this._width&&!this._height){const r=p(this._width,i);return{width:r,height:r/this.source.aspectRatio}}if(this.freeTransform&&!this._width&&this._height){const r=p(this._height,s);return{width:r*this.source.aspectRatio,height:r}}return{width:p(this.width,i),height:p(this.height,s)}}}return V([u()],t.prototype,"_height"),V([u()],t.prototype,"_width"),V([u()],t.prototype,"anchorX"),V([u()],t.prototype,"anchorY"),V([u()],t.prototype,"scaleX"),V([u()],t.prototype,"scaleY"),V([u()],t.prototype,"translateX"),V([u()],t.prototype,"translateY"),V([u()],t.prototype,"freeTransform"),V([u()],t.prototype,"x"),V([u()],t.prototype,"y"),V([u()],t.prototype,"rotation"),V([u()],t.prototype,"opacity"),V([u()],t.prototype,"filter"),V([u()],t.prototype,"blendMode"),t}class K extends O(G){type="image";element=new Image;source=new ft;animations=[];constructor(t,e={}){super(),t instanceof ft&&(this.source=t),t instanceof File&&(this.source.file=t),Object.assign(this,e)}async init(){await this.source.loaded(),this.element=this.source.element.cloneNode()}render(t){const{width:e,height:i}=this.size;t.save().blendMode(this.blendMode).clip(this.mask?.path,this.mask?.fillRule).filter(this.filter).opacity(this.opacity).transform({translate:this}).transform({translate:this.translate,rotate:this.rotation,scale:this.scale}).transform({translate:{x:-this.anchor.x*e,y:-this.anchor.y*i}}).image(this.element,{width:e,height:i}).restore()}copy(){const t=K.fromJSON(JSON.parse(JSON.stringify(this)));return t.source=this.source,t.mask=this.mask,t}}var pi=Object.defineProperty,F=(n,t,e,i)=>{for(var s=void 0,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=o(t,e,s)||s);return s&&pi(t,e,s),s};const R=class Ue extends O(G){type="text";animations=[];text="";color="#FFFFFF";font={family:"Arial",size:16};casing;align="left";baseline="top";stroke;shadow;leading=1.3;glow;constructor(t={}){super(),Object.assign(this,t)}render(t){const{width:e,height:i}=t,s=p(this.x,e)+this.translateX,r=p(this.y,i)+this.translateY,o=Tt(this.text,this.casing).split(` `);t.save().blendMode(this.blendMode).clip(this.mask?.path,this.mask?.fillRule).filter(this.filter).opacity(this.opacity).transform({translate:{x:s,y:r},scale:this.scale,rotate:this.rotation}).transform({translate:{x:-s,y:-r}}).text({alignment:this.align,baseline:this.baseline,font:this.font,color:this.color});var a=r;for(const l of o){if(!this.shadows)break;t.stroke(this.stroke);for(const h of this.shadows)this.stroke?t.shadow(h).strokeText(l,{x:s,y:a}):t.shadow(h).fillText(l,{x:s,y:a});a+=this.font.size*t.textScale*this.leading}t.shadow(void 0).stroke(this.stroke).fill({color:this.color});var a=r;for(const l of o)this.stroke&&t.strokeText(l,{x:s,y:a}),t.fillText(l,{x:s,y:a}),this.glow&&t.fill({color:this.glow.color,opacity:this.glow.opacity}).filter(`blur(${(this.glow.radius??10)*t.resolution}px)`).fillText(l,{x:s,y:a}),a+=this.font.size*t.textScale*this.leading;t.restore()}get fontSize(){return this.font.size}set fontSize(t){this.font.size=t}get name(){return this.text}copy(){const t=Ue.fromJSON(JSON.parse(JSON.stringify(this)));return t.mask=this.mask,t}get shadows(){return Array.isArray(this.shadow)?this.shadow:this.shadow?[this.shadow]:[]}};F([u()],R.prototype,"text"),F([u()],R.prototype,"color"),F([u()],R.prototype,"font"),F([u()],R.prototype,"casing"),F([u()],R.prototype,"align"),F([u()],R.prototype,"baseline"),F([u()],R.prototype,"stroke"),F([u()],R.prototype,"shadow"),F([u()],R.prototype,"leading"),F([u()],R.prototype,"glow");let $=R;function Xt(n){return n.replace(/(^ | $)/g,"").split(" ")}function gi(n,t=[]){const e=[{tokens:Xt(n.substring(0,t?.at(0)?.start))}];for(let i=0;i<t.length;i++)e.push({style:{color:t[i]?.style?.color,font:{size:t[i]?.style?.fontSize,family:t[i]?.style?.font?.family,weight:t[i]?.style?.font?.weight,style:t[i]?.style?.font?.style},stroke:t[i]?.style?.stroke},tokens:Xt(n.substring(t[i].start,t[i].stop))}),!((t[i].stop??n.length)>=n.length)&&e.push({tokens:Xt(n.substring(t[i].stop,t.at(i+1)?.start))});return e.filter(i=>i.tokens.join("").length>0)}const yi={center:.5,left:0,right:1},wi={alphabetic:0,top:0,middle:.5,hanging:1,bottom:1,ideographic:1};class bi{tokens=[];get width(){return this.tokens.reduce((t,e)=>t+e.metrics.width,0)}get height(){return Math.max(...this.tokens.map(t=>t.metrics.hangingBaseline))}}class Zi{lines=[];leading=1;constructor({leading:t=1}={}){this.leading=t}get width(){return Math.max(...this.lines.map(t=>t.width))}get height(){return this.lines.length==1?this.lines[0].height:this.lines.reduce((t,e)=>t+e.height*this.leading,0)}align(t){const e=this.width;for(const i of this.lines){let s=0;t=="center"&&(s=(e-i.width)/2),t=="right"&&(s=e-i.width);for(const r of i.tokens)r.x=s,s+=r.metrics.width}}baseline(t){let e=0;for(let i=0;i<this.lines.length;i++){const s=this.lines[i],r=s.height;for(const o of s.tokens){let a=0;t=="middle"&&(a=(r-o.metrics.hangingBaseline)/2),t=="bottom"&&(a=r-o.metrics.hangingBaseline);for(const l of s.tokens)l.y=e+a}e+=r*this.leading}}}var Vi=Object.defineProperty,Gt=(n,t,e,i)=>{for(var s=void 0,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=o(t,e,s)||s);return s&&Vi(t,e,s),s};const wt=class Ne extends ${model;maxWidth;background;styles;constructor(t={}){super(),Object.assign(this,t)}update(t){const e=p(this.maxWidth??Number.POSITIVE_INFINITY,t.width),i=t.measureText(" ",this.font);this.model=new Zi({leading:this.leading});for(const s of gi(this.text,this.styles)){const r=s.style;for(let o=0;o<s.tokens.length;o++){let a=Tt(s.tokens[o],this.casing);const l=t.measureText(a,{size:r?.font?.size??this.font.size,family:r?.font?.family??this.font.family,weight:r?.font?.weight??this.font.weight,style:r?.font?.style??this.font.style}),h=(this.model.lines.at(-1)?.width??0)+l.width,f=s.tokens[o].match(/(\n|\\n)/);if((h>e||f||!this.model.lines.length)&&this.model.lines.push(new bi),f)continue;const d=this.model.lines.at(-1);d&&d.tokens.length>0&&d.tokens.push({metrics:i,x:0,y:0,text:" ",style:r}),d?.tokens.push({metrics:l,x:0,y:0,text:a,style:r})}}this.model.align(this.align),this.model.baseline(this.baseline)}async render(t){if(!this.model)return;const{width:e,height:i}=t,s=p(this.x,e)+this.translateX,r=p(this.y,i)+this.translateY,o=yi[this.align],a=wi[this.baseline];if(this.background){const l=this.background.padding??{x:30,y:20};t.rect({x:s-this.model.width*o-l.x,y:r-this.model.height*a-l.y,width:this.model.width+l.x*2,height:this.model.height+l.y*2,radius:this.background.borderRadius??20}).fill({color:this.background.fill??"#000000",opacity:this.background.opacity??100},!0)}t.save().blendMode(this.blendMode).clip(this.mask?.path,this.mask?.fillRule).filter(this.filter).opacity(this.opacity).transform({translate:{x:s,y:r},scale:this.scale,rotate:this.rotation}).transform({translate:{x:-(this.model.width*o),y:-(this.model.height*a)}}).text({alignment:"left",baseline:"top"});for(const l of this.model.lines)for(const h of l.tokens)if(h.text!==" "){t.text({font:{size:h.style?.font?.size??this.font.size,family:h.style?.font?.family??this.font.family,weight:h.style?.font?.weight??this.font.weight,style:h.style?.font?.style??this.font.style}}).stroke(h.style?.stroke??this.stroke);for(const f of this.shadows)h.style?.stroke??this.stroke?t.shadow(f).strokeText(h.text,{x:h.x,y:h.y*this.leading}):t.shadow(f).fillText(h.text,{x:h.x,y:h.y*this.leading})}t.shadow(void 0);for(const l of this.model.lines)for(const h of l.tokens)h.text!==" "&&(t.text({font:{size:h.style?.font?.size??this.font.size,family:h.style?.font?.family??this.font.family,weight:h.style?.font?.weight??this.font.weight,style:h.style?.font?.style??this.font.style}}).stroke(h.style?.stroke??this.stroke),(h.style?.stroke??this.stroke)&&t.strokeText(h.text,{x:h.x,y:h.y*this.leading}),t.fill({color:h.style?.color??this.color}).fillText(h.text,{x:h.x,y:h.y*this.leading}));t.restore()}copy(){const t=Ne.fromJSON(JSON.parse(JSON.stringify(this)));return t.mask=this.mask,t}};Gt([u()],wt.prototype,"maxWidth"),Gt([u()],wt.prototype,"background"),Gt([u()],wt.prototype,"styles");let L=wt;const ae="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO3ZhciBtPSh0PT4odFt0LkFWTUVESUFfVFlQRV9VTktOT1dOPS0xXT0iQVZNRURJQV9UWVBFX1VOS05PV04iLHRbdC5BVk1FRElBX1RZUEVfVklERU89MF09IkFWTUVESUFfVFlQRV9WSURFTyIsdFt0LkFWTUVESUFfVFlQRV9BVURJTz0xXT0iQVZNRURJQV9UWVBFX0FVRElPIix0W3QuQVZNRURJQV9UWVBFX0RBVEE9Ml09IkFWTUVESUFfVFlQRV9EQVRBIix0W3QuQVZNRURJQV9UWVBFX1NVQlRJVExFPTNdPSJBVk1FRElBX1RZUEVfU1VCVElUTEUiLHRbdC5BVk1FRElBX1RZUEVfQVRUQUNITUVOVD00XT0iQVZNRURJQV9UWVBFX0FUVEFDSE1FTlQiLHRbdC5BVk1FRElBX1RZUEVfTkI9NV09IkFWTUVESUFfVFlQRV9OQiIsdCkpKG18fHt9KSxvPSh0PT4odC5GRm1wZWdXb3JrZXJMb2FkZWQ9IkZGbXBlZ1dvcmtlckxvYWRlZCIsdC5XQVNNUnVudGltZUluaXRpYWxpemVkPSJXQVNNUnVudGltZUluaXRpYWxpemVkIix0LkxvYWRXQVNNPSJMb2FkV0FTTSIsdC5HZXRBVlBhY2tldD0iR2V0QVZQYWNrZXQiLHQuR2V0QVZQYWNr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