@shotstack/shotstack-studio 2.0.0-beta.20 → 2.0.0-beta.21

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.
package/dist/index.d.ts CHANGED
@@ -616,6 +616,9 @@ export declare class Edit {
616
616
 
617
617
  declare type Edit_2 = components["schemas"]["Edit"];
618
618
 
619
+ /** Configuration for defining an edit - the structure passed to EditSession */
620
+ export declare type EditConfig = Edit_2;
621
+
619
622
  export declare const EditEvent: {
620
623
  readonly PlaybackPlay: "playback:play";
621
624
  readonly PlaybackPause: "playback:pause";
@@ -1826,9 +1829,6 @@ export declare interface UIRegistration {
1826
1829
  dispose(): void;
1827
1830
  }
1828
1831
 
1829
- /** Alias for Edit type - represents an edit before timing values are resolved */
1830
- export declare type UnresolvedEdit = Edit_2;
1831
-
1832
1832
  export declare const VERSION: string;
1833
1833
 
1834
1834
  export declare type VideoAsset = components["schemas"]["VideoAsset"];
@@ -616,6 +616,9 @@ export declare class Edit {
616
616
 
617
617
  declare type Edit_2 = components["schemas"]["Edit"];
618
618
 
619
+ /** Configuration for defining an edit - the structure passed to EditSession */
620
+ export declare type EditConfig = Edit_2;
621
+
619
622
  export declare const EditEvent: {
620
623
  readonly PlaybackPlay: "playback:play";
621
624
  readonly PlaybackPause: "playback:pause";
@@ -1826,9 +1829,6 @@ export declare interface UIRegistration {
1826
1829
  dispose(): void;
1827
1830
  }
1828
1831
 
1829
- /** Alias for Edit type - represents an edit before timing values are resolved */
1830
- export declare type UnresolvedEdit = Edit_2;
1831
-
1832
1832
  export declare const VERSION: string;
1833
1833
 
1834
1834
  export declare type VideoAsset = components["schemas"]["VideoAsset"];
@@ -2,7 +2,7 @@ import * as Q from "pixi.js";
2
2
  import { Filter as xx, deprecation as Cx, GpuProgram as kx, GlProgram as Sx, Color as _x } from "pixi.js";
3
3
  import * as Tx from "howler";
4
4
  import * as Mh from "opentype.js";
5
- const Ax = "2.0.0-beta.20", Ix = {
5
+ const Ax = "2.0.0-beta.21", Ix = {
6
6
  version: Ax
7
7
  };
8
8
  class Ex {
@@ -1,4 +1,4 @@
1
- (function(ve,ji){typeof exports=="object"&&typeof module<"u"?ji(exports,require("pixi.js"),require("howler"),require("opentype.js")):typeof define=="function"&&define.amd?define(["exports","pixi.js","howler","opentype.js"],ji):(ve=typeof globalThis<"u"?globalThis:ve||self,ji(ve.ShotstackStudio={},ve.PIXI,ve.Howler,ve.opentype))})(this,function(ve,ji,zx,Ox){"use strict";var bs=typeof document<"u"?document.currentScript:null;function su(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const Q=su(ji),Rx=su(zx),ru=su(Ox),Lx={version:"2.0.0-beta.20"};class Dx{curves={};constructor(){this.initializeCurves()}initializeCurves(){this.curves={smooth:[[.5,0],[.5,1]],ease:[[.25,.1],[.25,1]],easeIn:[[.42,0],[1,1]],easeOut:[[0,0],[.58,1]],easeInOut:[[.42,0],[.58,1]],easeInQuad:[[.55,.085],[.68,.53]],easeInCubic:[[.55,.055],[.675,.19]],easeInQuart:[[.895,.03],[.685,.22]],easeInQuint:[[.755,.05],[.855,.06]],easeInSine:[[.47,0],[.745,.715]],easeInExpo:[[.95,.05],[.795,.035]],easeInCirc:[[.6,.04],[.98,.335]],easeInBack:[[.6,-.28],[.735,.045]],easeOutQuad:[[.25,.46],[.45,.94]],easeOutCubic:[[.215,.61],[.355,1]],easeOutQuart:[[.165,.84],[.44,1]],easeOutQuint:[[.23,1],[.32,1]],easeOutSine:[[.39,.575],[.565,1]],easeOutExpo:[[.19,1],[.22,1]],easeOutCirc:[[.075,.82],[.165,1]],easeOutBack:[[.175,.885],[.32,1.275]],easeInOutQuad:[[.455,.03],[.515,.955]],easeInOutCubic:[[.645,.045],[.355,1]],easeInOutQuart:[[.77,0],[.175,1]],easeInOutQuint:[[.86,0],[.07,1]],easeInOutSine:[[.445,.05],[.55,.95]],easeInOutExpo:[[1,0],[0,1]],easeInOutCirc:[[.785,.135],[.15,.86]],easeInOutBack:[[.68,-.55],[.265,1.55]]}}getValue(e,t,s,r){const a=this.curves[r??""]??this.curves.ease,[[n,o],[l,c]]=a,u=s+(3*n-3*l+1)*s*(1-s),h=e,d=e+(t-e)*o,f=e+(t-e)*c,p=t,m=u,y=1-m;return y**3*h+3*y**2*m*d+3*y*m**2*f+m**3*p}}class sn{property;length;cubicBuilder;cachedIndex=0;constructor(e,t,s=0){this.property=this.createKeyframes(e,t,s),this.length=t,this.cubicBuilder=new Dx}getValue(e){const t=this.findKeyframe(e);if(!t){if(this.property.length>0){if(e>=this.length)return this.property[this.property.length-1].to;if(e<0)return this.property[0].from}return 1}const s=(e-t.start)/t.length;switch(t.interpolation){case"bezier":return this.cubicBuilder.getValue(t.from,t.to,s,t.easing);case"constant":return t.from;case"linear":default:return t.from+(t.to-t.from)*s}}findKeyframe(e){const t=this.property;if(t.length===0)return;const s=t[this.cachedIndex];if(s){const o=s.start+s.length;if(Number.isFinite(o)&&e>=s.start&&e<o)return s}const r=this.cachedIndex+1;if(r<t.length){const o=t[r],l=o.start+o.length;if(Number.isFinite(l)&&e>=o.start&&e<l)return this.cachedIndex=r,o}const a=this.cachedIndex-1;if(a>=0){const o=t[a],l=o.start+o.length;if(Number.isFinite(l)&&e>=o.start&&e<l)return this.cachedIndex=a,o}const n=this.binarySearchKeyframe(e);if(n!==-1)return this.cachedIndex=n,t[n]}binarySearchKeyframe(e){const t=this.property;let s=0,r=t.length-1;for(;s<=r;){const a=Math.floor((s+r)/2),n=t[a],o=n.start+n.length;if(!Number.isFinite(o)||e>=o)s=a+1;else if(e<n.start)r=a-1;else return a}return-1}createKeyframes(e,t,s=0){if(typeof e=="number")return[{start:0,length:t,from:e,to:e}];if(!e.length)throw new Error("Keyframes should have at least one value.");const r=this.createNormalizedKeyframes(e);return this.validateKeyframes(r),this.insertFillerKeyframes(r,t,s)}createNormalizedKeyframes(e){return e.filter(t=>typeof t.start=="number"&&typeof t.length=="number").toSorted((t,s)=>t.start-s.start).map(t=>({start:t.start,length:t.length,from:typeof t.from=="number"?t.from:0,to:typeof t.to=="number"?t.to:0,interpolation:t.interpolation,easing:t.easing}))}validateKeyframes(e){for(let t=0;t<e.length;t+=1){const s=e[t],r=e[t+1];if(!r){if(s.start+s.length>this.length)throw new Error("Last keyframe exceeds the maximum duration.");break}if(s.start+s.length>r.start)throw new Error("Overlapping keyframes detected.")}}insertFillerKeyframes(e,t,s=0){const r=[];for(let a=0;a<e.length;a+=1){const n=e[a],o=e[a+1];if(a===0&&n.start!==0){const u={start:0,length:n.start,from:s,to:n.from};r.push(u)}if(r.push(n),!o){if(n.start+n.length<t){const h=n.start+n.length,d={start:h,length:t-h,from:n.to,to:n.to};r.push(d)}break}if(n.start+n.length!==o.start){const u=n.start+n.length,h=o.start-u,d={start:u,length:h,from:n.to,to:o.from};r.push(d)}}return r}}class br{baseValue;mode;layers=[];length;clampRange;constructor(e,t,s,r){this.baseValue=e,this.length=t,this.mode=s,this.clampRange=r}addLayer(e){if(e.length===0)return;const t=this.mode==="additive"?0:1;this.layers.push(new sn(e,this.length,t))}getValue(e){if(this.layers.length===0)return this.baseValue;if(this.mode==="additive"){let s=this.baseValue;for(const r of this.layers)s+=r.getValue(e);return s}let t=this.baseValue;for(const s of this.layers)t*=s.getValue(e);return this.clampRange&&(t=Math.max(this.clampRange.min,Math.min(this.clampRange.max,t))),t}}class Ux{clipConfiguration;effectPreset;constructor(e){this.clipConfiguration=e;const[t,s]=(e.effect??"").split(/(Slow|Fast)/);this.effectPreset={name:t,speed:s}}buildRelative(e,t){const s=[],r=[],a=[],n=[],o=[],{effect:l,length:c}=this.clipConfiguration;if(!l)return{offsetXKeyframes:s,offsetYKeyframes:r,opacityKeyframes:a,scaleKeyframes:n,rotationKeyframes:o};const u=0,h=this.getPresetName();switch(h){case"zoomIn":{const d=this.getZoomSpeed();n.push({from:1,to:d,start:u,length:c,interpolation:"linear"});break}case"zoomOut":{const d=this.getZoomSpeed();n.push({from:d,to:1,start:u,length:c,interpolation:"linear"});break}case"slideLeft":case"slideRight":case"slideUp":case"slideDown":{const d=h==="slideLeft"||h==="slideRight",f=h==="slideLeft"||h==="slideUp",p=this.getFittedSize(e,t),m=d?e.width:e.height,y=d?p.width:p.height;let x=this.getSlideStart();const k=m+m*x*2;if(y<k){const T=k/y;n.push({from:T,to:T,start:u,length:c,interpolation:"linear"})}else x=(y-m)/2/m;const[b,S]=f?[x,-x]:[-x,x];(d?s:r).push({from:b,to:S,start:u,length:c});break}}return{offsetXKeyframes:s,offsetYKeyframes:r,opacityKeyframes:a,scaleKeyframes:n,rotationKeyframes:o}}getPresetName(){return this.effectPreset.name}getZoomSpeed(){const{name:e,speed:t}=this.effectPreset;if(e.startsWith("zoom"))switch(t){case"Slow":return 1.1;case"Fast":return 1.7;default:return 1.3}return 0}getSlideStart(){const{name:e,speed:t}=this.effectPreset;if(e.startsWith("slide"))switch(t){case"Slow":return .03;case"Fast":return .2;default:return .12}return 0}getFittedSize(e,t){switch(this.clipConfiguration.fit??"crop"){case"cover":case"crop":{const r=Math.max(e.width/t.width,e.height/t.height);return{width:t.width*r,height:t.height*r}}case"contain":{const r=Math.min(e.width/t.width,e.height/t.height);return{width:t.width*r,height:t.height*r}}case"none":default:return t}}}class Zx{clipConfiguration;inPreset;outPreset;constructor(e){this.clipConfiguration=e,this.inPreset=this.parseTransition(e.transition?.in),this.outPreset=this.parseTransition(e.transition?.out)}parseTransition(e){const[t,s]=(e??"").split(/(Slow|Fast|VeryFast)/);return{name:t,speed:s}}buildRelative(){return{in:this.buildTransitionKeyframes("in"),out:this.buildTransitionKeyframes("out")}}createEmptyKeyframeSet(){return{offsetXKeyframes:[],offsetYKeyframes:[],opacityKeyframes:[],scaleKeyframes:[],rotationKeyframes:[],maskXKeyframes:[]}}buildTransitionKeyframes(e){const t=this.createEmptyKeyframeSet();if(!(e==="in"?this.clipConfiguration.transition?.in:this.clipConfiguration.transition?.out))return t;const r=this.getPresetLength(e),a=e==="in"?0:this.clipConfiguration.length-r,n=this.getPresetName(e),o=e==="in";switch(n){case"fade":{const[l,c]=o?[0,1]:[1,0];t.opacityKeyframes.push({from:l,to:c,start:a,length:r,interpolation:"bezier",easing:"ease"});break}case"zoom":{const[l,c]=o?[10,1]:[1,10],[u,h]=o?[0,1]:[1,0],d=o?"easeIn":"easeOut";t.scaleKeyframes.push({from:l,to:c,start:a,length:r,interpolation:"bezier",easing:d}),t.opacityKeyframes.push({from:u,to:h,start:a,length:r,interpolation:"bezier",easing:d});break}case"slideLeft":case"slideRight":case"slideUp":case"slideDown":{const l=n==="slideLeft"||n==="slideRight",c=n==="slideLeft"||n==="slideUp",u=.025,[h,d]=o?[c?u:-u,0]:[0,c?-u:u],f=o?"linear":"bezier",[p,m]=o?[0,1]:[1,0];(l?t.offsetXKeyframes:t.offsetYKeyframes).push(o?{from:h,to:d,start:a,length:r,interpolation:f}:{from:h,to:d,start:a,length:r,interpolation:f,easing:"ease"}),t.opacityKeyframes.push({from:p,to:m,start:a,length:r,interpolation:"bezier",easing:"ease"});break}case"carouselLeft":case"carouselRight":case"carouselUp":case"carouselDown":{const l=n==="carouselLeft"||n==="carouselRight",c=n==="carouselLeft"||n==="carouselUp",u=l&&1||(o?1.05:1.1),[h,d]=o?[c?u:-u,0]:[0,c?-u:u];(l?t.offsetXKeyframes:t.offsetYKeyframes).push(o?{from:h,to:d,start:a,length:r,interpolation:"linear"}:{from:h,to:d,start:a,length:r,interpolation:"bezier",easing:"ease"});break}case"reveal":case"wipeRight":{const[l,c]=o?[0,1]:[1,0];t.maskXKeyframes.push({from:l,to:c,start:a,length:r,interpolation:"bezier",easing:"ease"});break}case"wipeLeft":{const[l,c]=o?[1,0]:[0,1];t.maskXKeyframes.push({from:l,to:c,start:a,length:r,interpolation:"bezier",easing:"ease"});break}}return t}getPresetName(e){return e==="in"?this.inPreset.name:this.outPreset.name}getPresetLength(e){const{name:t,speed:s}=e==="in"?this.inPreset:this.outPreset,r=t.startsWith("carousel"),a=t.startsWith("slide");if(t==="zoom")return .4;switch(s){case"Slow":return 2;case"Fast":return r||a?.25:.5;case"VeryFast":return .25;default:return r||a?.5:1}}}const Y={PlaybackPlay:"playback:play",PlaybackPause:"playback:pause",TimelineUpdated:"timeline:updated",TimelineBackgroundChanged:"timeline:backgroundChanged",ClipAdded:"clip:added",ClipSplit:"clip:split",ClipSelected:"clip:selected",ClipUpdated:"clip:updated",ClipDeleted:"clip:deleted",ClipRestored:"clip:restored",ClipCopied:"clip:copied",ClipLoadFailed:"clip:loadFailed",ClipUnresolved:"clip:unresolved",SelectionCleared:"selection:cleared",EditChanged:"edit:changed",EditUndo:"edit:undo",EditRedo:"edit:redo",TrackAdded:"track:added",TrackRemoved:"track:removed",DurationChanged:"duration:changed",OutputResized:"output:resized",OutputResolutionChanged:"output:resolutionChanged",OutputAspectRatioChanged:"output:aspectRatioChanged",OutputFpsChanged:"output:fpsChanged",OutputFormatChanged:"output:formatChanged",OutputDestinationsChanged:"output:destinationsChanged",MergeFieldRegistered:"mergefield:registered",MergeFieldUpdated:"mergefield:updated",MergeFieldRemoved:"mergefield:removed",MergeFieldChanged:"mergefield:changed",MergeFieldApplied:"mergefield:applied",TranscriptionProgress:"transcription:progress",TranscriptionCompleted:"transcription:completed",TranscriptionFailed:"transcription:failed",LumaAttached:"luma:attached",LumaDetached:"luma:detached"},ht={CanvasClipClicked:"canvas:clipClicked",CanvasBackgroundClicked:"canvas:backgroundClicked",FontCapabilitiesChanged:"font:capabilitiesChanged",Resolved:"resolved",PlayerAddedToTrack:"player:addedToTrack",PlayerMovedBetweenTracks:"player:movedBetweenTracks",PlayerRemovedFromTrack:"player:removedFromTrack",TrackContainerRemoved:"track:containerRemoved",ViewportSizeChanged:"viewport:sizeChanged",ViewportNeedsZoomToFit:"viewport:needsZoomToFit"};function Wx(i,e,t){const s=e.width/i.width,r=e.height/i.height;switch(t??"crop"){case"crop":case"cover":return Math.max(s,r);case"contain":return Math.min(s,r);case"none":default:return 1}}function Gx(i,e,t,s,r){if(r)return{x:s,y:s};if(i.width===0||i.height===0)return{x:s,y:s};const a=e.width/i.width,n=e.height/i.height;switch(t??"crop"){case"contain":{const o=Math.min(a,n)*s;return{x:o,y:o}}case"crop":{const o=Math.max(a,n)*s;return{x:o,y:o}}case"cover":return{x:a*s,y:n*s};case"none":default:return{x:s,y:s}}}function Hx(i,e,t){const s=e.width/2,r=e.height/2;switch(t??"crop"){case"cover":{const a=e.width/i.width,n=e.height/i.height;return{scaleX:a,scaleY:n,positionX:s,positionY:r}}case"crop":{const a=Math.max(e.width/i.width,e.height/i.height);return{scaleX:a,scaleY:a,positionX:s,positionY:r}}case"contain":{const a=Math.min(e.width/i.width,e.height/i.height);return{scaleX:a,scaleY:a,positionX:s,positionY:r}}case"none":default:return{scaleX:1,scaleY:1,positionX:s,positionY:r}}}function $f(i){return i*1e3}function au(i){return i/1e3}function LW(i){return i}function DW(i){return i}function Yi(i){return typeof i=="string"&&/^alias:\/\/[a-zA-Z0-9_-]+$/.test(i)}function Mo(i){return i.replace(/^alias:\/\//,"")}let Qf=class{static ButtonLeftClick=0;static ButtonRightClick=3};class Jf{containerSize;constructor(e){this.containerSize=e}relativeToAbsolute(e,t,s){switch(t){case"topLeft":return{x:s.x*this.containerSize.width,y:-s.y*this.containerSize.height};case"topRight":return{x:(s.x+1)*this.containerSize.width-e.width,y:-s.y*this.containerSize.height};case"bottomLeft":return{x:s.x*this.containerSize.width,y:(-s.y+1)*this.containerSize.height-e.height};case"bottomRight":return{x:(s.x+1)*this.containerSize.width-e.width,y:(-s.y+1)*this.containerSize.height-e.height};case"left":return{x:s.x*this.containerSize.width,y:(-s.y+.5)*this.containerSize.height-e.height/2};case"right":return{x:(s.x+1)*this.containerSize.width-e.width,y:(-s.y+.5)*this.containerSize.height-e.height/2};case"top":return{x:(s.x+.5)*this.containerSize.width-e.width/2,y:-s.y*this.containerSize.height};case"bottom":return{x:(s.x+.5)*this.containerSize.width-e.width/2,y:(-s.y+1)*this.containerSize.height-e.height};case"center":default:return{x:(s.x+.5)*this.containerSize.width-e.width/2,y:(-s.y+.5)*this.containerSize.height-e.height/2}}}absoluteToRelative(e,t,s){switch(t){case"topLeft":return{x:s.x/this.containerSize.width,y:-(s.y/this.containerSize.height)};case"topRight":return{x:(s.x+e.width)/this.containerSize.width-1,y:-(s.y/this.containerSize.height)};case"bottomLeft":return{x:s.x/this.containerSize.width,y:-((s.y+e.height)/this.containerSize.height-1)};case"bottomRight":return{x:(s.x+e.width)/this.containerSize.width-1,y:-((s.y+e.height)/this.containerSize.height-1)};case"left":return{x:s.x/this.containerSize.width,y:-((s.y+e.height/2)/this.containerSize.height-.5)};case"right":return{x:(s.x+e.width)/this.containerSize.width-1,y:-((s.y+e.height/2)/this.containerSize.height-.5)};case"top":return{x:(s.x+e.width/2)/this.containerSize.width-.5,y:-(s.y/this.containerSize.height)};case"bottom":return{x:(s.x+e.width/2)/this.containerSize.width-.5,y:-((s.y+e.height)/this.containerSize.height-1)};case"center":default:return{x:(s.x+e.width/2)/this.containerSize.width-.5,y:-((s.y+e.height/2)/this.containerSize.height-.5)}}}}class ep{container;constructor(){this.container=new Q.Container}getContainer(){return this.container}}var tt=(i=>(i.Video="video",i.Image="image",i.Audio="audio",i.Text="text",i.RichText="rich-text",i.Luma="luma",i.Html="html",i.Shape="shape",i.Caption="caption",i.Svg="svg",i.TextToImage="text-to-image",i.ImageToVideo="image-to-video",i.TextToSpeech="text-to-speech",i))(tt||{});class li extends ep{static DiscardedFrameCount=0;layer;shouldDispose;playerType;clipId=null;edit;clipConfiguration;resolvedTiming;positionBuilder;offsetXKeyframeBuilder;offsetYKeyframeBuilder;scaleKeyframeBuilder;opacityKeyframeBuilder;rotationKeyframeBuilder;skewXKeyframeBuilder;skewYKeyframeBuilder;maskXKeyframeBuilder;wipeMask;contentContainer;constructor(e,t,s){super(),this.edit=e,this.layer=0,this.shouldDispose=!1,this.playerType=s,this.clipConfiguration=t,this.positionBuilder=new Jf(e.size),this.resolvedTiming={start:t.start,length:t.length},this.wipeMask=null,this.contentContainer=new Q.Container,this.getContainer().addChild(this.contentContainer)}reconfigureAfterRestore(){this.configureKeyframes()}async reloadAsset(){}configureKeyframes(){const e=this.getLength(),t=this.clipConfiguration,s=typeof t.offset?.x=="number"?t.offset.x:0,r=typeof t.offset?.y=="number"?t.offset.y:0,a=typeof t.scale=="number"?t.scale:1,n=typeof t.opacity=="number"?t.opacity:1,o=typeof t.transform?.rotate?.angle=="number"?t.transform.rotate.angle:0,l=typeof t.transform?.skew?.x=="number"?t.transform.skew.x:0,c=typeof t.transform?.skew?.y=="number"?t.transform.skew.y:0;if(this.offsetXKeyframeBuilder=new br(s,e,"additive"),this.offsetYKeyframeBuilder=new br(r,e,"additive"),this.scaleKeyframeBuilder=new br(a,e,"multiplicative"),this.opacityKeyframeBuilder=new br(n,e,"multiplicative",{min:0,max:1}),this.rotationKeyframeBuilder=new br(o,e,"additive"),this.skewXKeyframeBuilder=new br(l,e,"additive"),this.skewYKeyframeBuilder=new br(c,e,"additive"),this.clipHasKeyframes()){Array.isArray(t.scale)&&this.scaleKeyframeBuilder.addLayer(t.scale),Array.isArray(t.opacity)&&this.opacityKeyframeBuilder.addLayer(t.opacity),Array.isArray(t.offset?.x)&&this.offsetXKeyframeBuilder.addLayer(t.offset.x),Array.isArray(t.offset?.y)&&this.offsetYKeyframeBuilder.addLayer(t.offset.y),Array.isArray(t.transform?.rotate?.angle)&&this.rotationKeyframeBuilder.addLayer(t.transform.rotate.angle),Array.isArray(t.transform?.skew?.x)&&this.skewXKeyframeBuilder.addLayer(t.transform.skew.x),Array.isArray(t.transform?.skew?.y)&&this.skewYKeyframeBuilder.addLayer(t.transform.skew.y);return}const u={...t,start:this.getStart(),length:e},h=new Ux(u).buildRelative(this.edit.size,this.getSize()),d=new Zx(u).buildRelative();this.offsetXKeyframeBuilder.addLayer(h.offsetXKeyframes),this.offsetYKeyframeBuilder.addLayer(h.offsetYKeyframes),this.scaleKeyframeBuilder.addLayer(h.scaleKeyframes),this.opacityKeyframeBuilder.addLayer(h.opacityKeyframes),this.rotationKeyframeBuilder.addLayer(h.rotationKeyframes),this.offsetXKeyframeBuilder.addLayer(d.in.offsetXKeyframes),this.offsetYKeyframeBuilder.addLayer(d.in.offsetYKeyframes),this.scaleKeyframeBuilder.addLayer(d.in.scaleKeyframes),this.opacityKeyframeBuilder.addLayer(d.in.opacityKeyframes),this.rotationKeyframeBuilder.addLayer(d.in.rotationKeyframes),this.offsetXKeyframeBuilder.addLayer(d.out.offsetXKeyframes),this.offsetYKeyframeBuilder.addLayer(d.out.offsetYKeyframes),this.scaleKeyframeBuilder.addLayer(d.out.scaleKeyframes),this.opacityKeyframeBuilder.addLayer(d.out.opacityKeyframes),this.rotationKeyframeBuilder.addLayer(d.out.rotationKeyframes);const f=[...d.in.maskXKeyframes,...d.out.maskXKeyframes];f.length&&(this.maskXKeyframeBuilder=new sn(f,e))}async load(){this.contentContainer?.destroyed&&(this.contentContainer=new Q.Container,this.getContainer().addChild(this.contentContainer)),this.getContainer().sortableChildren=!0,this.getContainer().cursor="pointer",this.getContainer().eventMode="static",this.getContainer().on?.("pointerdown",this.onPointerDown.bind(this))}update(e,t){if(this.getContainer().visible=this.isActive(),this.getContainer().zIndex=1e5-this.layer*100,!this.isActive())return;const s=this.getPivot(),r=this.getPosition(),a=this.getContainerScale();this.getContainer().scale.set(a.x,a.y),this.getContainer().pivot.set(s.x,s.y),this.getContainer().position.set(r.x+s.x,r.y+s.y);const n=this.getRotation();this.contentContainer.alpha=this.getOpacity(),this.getContainer().angle=n;const o=this.getSkew();this.getContainer().skew?.set(o.x*(Math.PI/180),o.y*(Math.PI/180)),this.clipConfiguration.width&&this.clipConfiguration.height&&this.applyFixedDimensions(),this.updateWipeMask(),this.shouldDiscardFrame()&&(this.contentContainer.alpha=0)}updateWipeMask(){if(!this.maskXKeyframeBuilder){this.wipeMask&&(this.getContainer().mask=null,this.wipeMask.destroy(),this.wipeMask=null);return}const e=this.maskXKeyframeBuilder.getValue(this.getPlaybackTime()),t=this.getSize();this.wipeMask||(this.wipeMask=new Q.Graphics,this.getContainer().addChild(this.wipeMask),this.getContainer().mask=this.wipeMask),this.wipeMask.clear(),this.wipeMask.rect(0,0,t.width*e,t.height),this.wipeMask.fill(16777215)}dispose(){this.wipeMask?.destroy(),this.wipeMask=null,this.contentContainer?.destroy()}getStart(){return this.resolvedTiming.start}getLength(){return this.resolvedTiming.length}getEnd(){return this.resolvedTiming.start+this.resolvedTiming.length}getTimingIntent(){if(this.clipId){const e=this.edit.getDocumentClipById(this.clipId);if(e){let t;e.start==="auto"?t="auto":(Yi(e.start),t=e.start);let s;return e.length==="auto"||e.length==="end"||Yi(e.length),s=e.length,{start:t,length:s}}}return{start:this.clipConfiguration.start,length:this.clipConfiguration.length}}getResolvedTiming(){return{...this.resolvedTiming}}setResolvedTiming(e){this.resolvedTiming={...e},this.clipConfiguration.start=e.start,this.clipConfiguration.length=e.length}getExportableClip(){const e=structuredClone(this.clipConfiguration),t=this.getTimingIntent();return e.start=t.start,e.length=t.length,e}getPlaybackTime(){const e=this.edit.playbackTime-this.getStart();return e<0?0:e>this.getLength()?this.getLength():e}getContentSize(){return this.getSize()}getContentContainer(){return this.contentContainer}getOpacity(){return this.opacityKeyframeBuilder?.getValue(this.getPlaybackTime())??1}getPosition(){const e={x:this.offsetXKeyframeBuilder?.getValue(this.getPlaybackTime())??0,y:this.offsetYKeyframeBuilder?.getValue(this.getPlaybackTime())??0};return this.positionBuilder.relativeToAbsolute(this.getSize(),this.clipConfiguration.position??"center",e)}getPivot(){const e=this.getSize();return{x:e.width/2,y:e.height/2}}calculateMoveOffset(e,t){const s=this.getPosition(),r={x:s.x+e,y:s.y+t},a=this.positionBuilder.absoluteToRelative(this.getSize(),this.clipConfiguration.position??"center",r);return{x:a.x,y:a.y}}getFitScale(){const e={width:this.clipConfiguration.width??this.edit.size.width,height:this.clipConfiguration.height??this.edit.size.height},t=this.getContentSize(),s=this.clipConfiguration.fit??"crop";return Wx(t,e,s)}getScale(){return(this.scaleKeyframeBuilder?.getValue(this.getPlaybackTime())??1)*this.getFitScale()}getContainerScale(){const e=this.scaleKeyframeBuilder?.getValue(this.getPlaybackTime())??1,t=this.getContentSize(),s=this.clipConfiguration.fit??"crop",r=!!(this.clipConfiguration.width&&this.clipConfiguration.height);return Gx(t,this.edit.size,s,e,r)}getRotation(){return this.rotationKeyframeBuilder?.getValue(this.getPlaybackTime())??0}getSkew(){return{x:this.skewXKeyframeBuilder?.getValue(this.getPlaybackTime())??0,y:this.skewYKeyframeBuilder?.getValue(this.getPlaybackTime())??0}}isActive(){return this.edit.playbackTime>=this.getStart()&&this.edit.playbackTime<this.getEnd()}shouldDiscardFrame(){return this.getPlaybackTime()<li.DiscardedFrameCount}onPointerDown(e){e.button===Qf.ButtonLeftClick&&this.edit.events.emit(ht.CanvasClipClicked,{player:this})}clipHasKeyframes(){return[this.clipConfiguration.scale,this.clipConfiguration.opacity,this.clipConfiguration.offset?.x,this.clipConfiguration.offset?.y,this.clipConfiguration.transform?.rotate?.angle,this.clipConfiguration.transform?.skew?.x,this.clipConfiguration.transform?.skew?.y].some(e=>e&&typeof e!="number")}applyFixedDimensions(){const e=this.clipConfiguration.width,t=this.clipConfiguration.height;if(!e||!t)return;const s=this.contentContainer.children.find(f=>f instanceof Q.Sprite);if(!s?.texture)return;const r=s.texture.width,a=s.texture.height,n=this.clipConfiguration.fit||"crop",o=this.contentContainer.mask;let l=null;o instanceof Q.Graphics?l=o:o||(l=new Q.Graphics,this.contentContainer.addChild(l),this.contentContainer.mask=l),l&&(l.clear(),l.rect(0,0,e,t),l.fill(16777215));const c=this.scaleKeyframeBuilder?.getValue(this.getPlaybackTime())??1;s.anchor.set(.5,.5);const d=Hx({width:r,height:a},{width:e,height:t},n);s.scale.set(d.scaleX,d.scaleY),s.position.set(d.positionX,d.positionY),this.contentContainer.scale.set(c,c),this.contentContainer.position.set(e/2*(1-c),t/2*(1-c))}applyAnchorPositioning(e,t,s,r){const a=r.width,n=r.height;if(!!r.mask){r.position.set(0,0);return}const l=(e??"center").toLowerCase();let c=0,u=0;l.includes("left")||l==="left"?c=0:l.includes("right")||l==="right"?c=t-a:c=(t-a)/2,l.includes("top")||l==="top"?u=0:l.includes("bottom")||l==="bottom"?u=s-n:u=(s-n)/2,r.position.set(c,u)}supportsEdgeResize(){return!1}onDimensionsChanged(){}notifyDimensionsChanged(){this.onDimensionsChanged()}}class rn{static Name="AudioLoadParser";id;name;extension;validAudioExtensions;constructor(){this.id=rn.Name,this.name=rn.Name,this.extension={type:[Q.ExtensionType.LoadParser],priority:Q.LoaderParserPriority.Normal,ref:null},this.validAudioExtensions=["mp3","mpeg","ogg","wav"]}test(e){const t=e.split("?")[0]?.split(".").pop()??"";return this.validAudioExtensions.includes(t)}async load(e,t,s){return new Promise(r=>{const a={src:e},n=new Howl(a);n.on("load",()=>r(n)),n.on("loaderror",()=>r(null))})}unload(e){e?.unload()}}class jx extends li{audioResource;isPlaying;volumeKeyframeBuilder;syncTimer;constructor(e,t){super(e,t,tt.Audio),this.audioResource=null,this.isPlaying=!1,this.syncTimer=0}async load(){await super.load();const e=this.clipConfiguration.asset,t=e.src,s={src:t,parser:rn.Name},r=await this.edit.assetLoader.load(t,s);if(!(r instanceof Rx.Howl))throw new Error(`Invalid audio source '${e.src}'.`);this.audioResource=r;const n=typeof e.volume=="number"?e.volume:1;this.volumeKeyframeBuilder=new sn(this.createVolumeKeyframes(e,n),this.getLength(),n),this.configureKeyframes()}update(e,t){super.update(e,t);const{trim:s=0}=this.clipConfiguration.asset;if(this.syncTimer+=t,this.getContainer().alpha=0,!this.audioResource)return;const r=this.edit.isPlaying&&this.isActive(),a=this.getPlaybackTime();r&&(this.isPlaying||(this.isPlaying=!0,this.audioResource.seek(a+s),this.audioResource.play()),this.audioResource.volume()!==this.getVolume()&&this.audioResource.volume(this.getVolume()),Math.abs(this.audioResource.seek()-s-a)>.1&&(this.audioResource.seek(a+s),this.edit.recordSyncCorrection())),this.isPlaying&&!r&&(this.isPlaying=!1,this.audioResource.pause());const n=this.syncTimer>100;!this.edit.isPlaying&&this.isActive()&&n&&(this.syncTimer=0,this.audioResource.seek(a+s))}dispose(){this.audioResource?.unload(),this.audioResource=null}reconfigureAfterRestore(){super.reconfigureAfterRestore();const e=this.clipConfiguration.asset,t=typeof e.volume=="number"?e.volume:1;this.volumeKeyframeBuilder=new sn(this.createVolumeKeyframes(e,t),this.getLength(),t)}getSize(){return{width:0,height:0}}getVolume(){return this.volumeKeyframeBuilder.getValue(this.getPlaybackTime())}getCurrentDrift(){if(!this.audioResource)return 0;const{trim:e=0}=this.clipConfiguration.asset,t=this.audioResource.seek(),s=this.getPlaybackTime();return Math.abs(t-e-s)}createVolumeKeyframes(e,t){const{effect:s,volume:r}=e;if(!s||s==="none"||Array.isArray(r))return r??1;const a=this.getLength()/1e3,n=Math.min(2,a/2);return s==="fadeIn"?[{from:0,to:t,start:0,length:n}]:s==="fadeOut"?[{from:t,to:0,start:a-n,length:n}]:[{from:0,to:t,start:0,length:n},{from:t,to:0,start:a-n,length:n}]}}function Vo(i){const e=i.trim().replace(",","."),t=e.split(":");if(t.length===3){const s=parseInt(t[0],10),r=parseInt(t[1],10),a=parseFloat(t[2]);return s*3600+r*60+a}if(t.length===2){const s=parseInt(t[0],10),r=parseFloat(t[1]);return s*60+r}return parseFloat(e)||0}function Yx(i){const e=[],t=i.split(/\r?\n/);let s=0;for(;s<t.length&&!t[s].includes("-->");)s+=1;for(;s<t.length;){const r=t[s].trim();if(r.includes("-->")){const[a,n]=r.split("-->").map(u=>u.trim().split(" ")[0]),o=Vo(a),l=Vo(n),c=[];for(s+=1;s<t.length&&t[s].trim()!==""&&!t[s].includes("-->");){const u=t[s].trim();u.startsWith("NOTE")||c.push(u),s+=1}c.length>0&&e.push({start:o,end:l,text:c.join(`
1
+ (function(ve,ji){typeof exports=="object"&&typeof module<"u"?ji(exports,require("pixi.js"),require("howler"),require("opentype.js")):typeof define=="function"&&define.amd?define(["exports","pixi.js","howler","opentype.js"],ji):(ve=typeof globalThis<"u"?globalThis:ve||self,ji(ve.ShotstackStudio={},ve.PIXI,ve.Howler,ve.opentype))})(this,function(ve,ji,zx,Ox){"use strict";var bs=typeof document<"u"?document.currentScript:null;function su(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const Q=su(ji),Rx=su(zx),ru=su(Ox),Lx={version:"2.0.0-beta.21"};class Dx{curves={};constructor(){this.initializeCurves()}initializeCurves(){this.curves={smooth:[[.5,0],[.5,1]],ease:[[.25,.1],[.25,1]],easeIn:[[.42,0],[1,1]],easeOut:[[0,0],[.58,1]],easeInOut:[[.42,0],[.58,1]],easeInQuad:[[.55,.085],[.68,.53]],easeInCubic:[[.55,.055],[.675,.19]],easeInQuart:[[.895,.03],[.685,.22]],easeInQuint:[[.755,.05],[.855,.06]],easeInSine:[[.47,0],[.745,.715]],easeInExpo:[[.95,.05],[.795,.035]],easeInCirc:[[.6,.04],[.98,.335]],easeInBack:[[.6,-.28],[.735,.045]],easeOutQuad:[[.25,.46],[.45,.94]],easeOutCubic:[[.215,.61],[.355,1]],easeOutQuart:[[.165,.84],[.44,1]],easeOutQuint:[[.23,1],[.32,1]],easeOutSine:[[.39,.575],[.565,1]],easeOutExpo:[[.19,1],[.22,1]],easeOutCirc:[[.075,.82],[.165,1]],easeOutBack:[[.175,.885],[.32,1.275]],easeInOutQuad:[[.455,.03],[.515,.955]],easeInOutCubic:[[.645,.045],[.355,1]],easeInOutQuart:[[.77,0],[.175,1]],easeInOutQuint:[[.86,0],[.07,1]],easeInOutSine:[[.445,.05],[.55,.95]],easeInOutExpo:[[1,0],[0,1]],easeInOutCirc:[[.785,.135],[.15,.86]],easeInOutBack:[[.68,-.55],[.265,1.55]]}}getValue(e,t,s,r){const a=this.curves[r??""]??this.curves.ease,[[n,o],[l,c]]=a,u=s+(3*n-3*l+1)*s*(1-s),h=e,d=e+(t-e)*o,f=e+(t-e)*c,p=t,m=u,y=1-m;return y**3*h+3*y**2*m*d+3*y*m**2*f+m**3*p}}class sn{property;length;cubicBuilder;cachedIndex=0;constructor(e,t,s=0){this.property=this.createKeyframes(e,t,s),this.length=t,this.cubicBuilder=new Dx}getValue(e){const t=this.findKeyframe(e);if(!t){if(this.property.length>0){if(e>=this.length)return this.property[this.property.length-1].to;if(e<0)return this.property[0].from}return 1}const s=(e-t.start)/t.length;switch(t.interpolation){case"bezier":return this.cubicBuilder.getValue(t.from,t.to,s,t.easing);case"constant":return t.from;case"linear":default:return t.from+(t.to-t.from)*s}}findKeyframe(e){const t=this.property;if(t.length===0)return;const s=t[this.cachedIndex];if(s){const o=s.start+s.length;if(Number.isFinite(o)&&e>=s.start&&e<o)return s}const r=this.cachedIndex+1;if(r<t.length){const o=t[r],l=o.start+o.length;if(Number.isFinite(l)&&e>=o.start&&e<l)return this.cachedIndex=r,o}const a=this.cachedIndex-1;if(a>=0){const o=t[a],l=o.start+o.length;if(Number.isFinite(l)&&e>=o.start&&e<l)return this.cachedIndex=a,o}const n=this.binarySearchKeyframe(e);if(n!==-1)return this.cachedIndex=n,t[n]}binarySearchKeyframe(e){const t=this.property;let s=0,r=t.length-1;for(;s<=r;){const a=Math.floor((s+r)/2),n=t[a],o=n.start+n.length;if(!Number.isFinite(o)||e>=o)s=a+1;else if(e<n.start)r=a-1;else return a}return-1}createKeyframes(e,t,s=0){if(typeof e=="number")return[{start:0,length:t,from:e,to:e}];if(!e.length)throw new Error("Keyframes should have at least one value.");const r=this.createNormalizedKeyframes(e);return this.validateKeyframes(r),this.insertFillerKeyframes(r,t,s)}createNormalizedKeyframes(e){return e.filter(t=>typeof t.start=="number"&&typeof t.length=="number").toSorted((t,s)=>t.start-s.start).map(t=>({start:t.start,length:t.length,from:typeof t.from=="number"?t.from:0,to:typeof t.to=="number"?t.to:0,interpolation:t.interpolation,easing:t.easing}))}validateKeyframes(e){for(let t=0;t<e.length;t+=1){const s=e[t],r=e[t+1];if(!r){if(s.start+s.length>this.length)throw new Error("Last keyframe exceeds the maximum duration.");break}if(s.start+s.length>r.start)throw new Error("Overlapping keyframes detected.")}}insertFillerKeyframes(e,t,s=0){const r=[];for(let a=0;a<e.length;a+=1){const n=e[a],o=e[a+1];if(a===0&&n.start!==0){const u={start:0,length:n.start,from:s,to:n.from};r.push(u)}if(r.push(n),!o){if(n.start+n.length<t){const h=n.start+n.length,d={start:h,length:t-h,from:n.to,to:n.to};r.push(d)}break}if(n.start+n.length!==o.start){const u=n.start+n.length,h=o.start-u,d={start:u,length:h,from:n.to,to:o.from};r.push(d)}}return r}}class br{baseValue;mode;layers=[];length;clampRange;constructor(e,t,s,r){this.baseValue=e,this.length=t,this.mode=s,this.clampRange=r}addLayer(e){if(e.length===0)return;const t=this.mode==="additive"?0:1;this.layers.push(new sn(e,this.length,t))}getValue(e){if(this.layers.length===0)return this.baseValue;if(this.mode==="additive"){let s=this.baseValue;for(const r of this.layers)s+=r.getValue(e);return s}let t=this.baseValue;for(const s of this.layers)t*=s.getValue(e);return this.clampRange&&(t=Math.max(this.clampRange.min,Math.min(this.clampRange.max,t))),t}}class Ux{clipConfiguration;effectPreset;constructor(e){this.clipConfiguration=e;const[t,s]=(e.effect??"").split(/(Slow|Fast)/);this.effectPreset={name:t,speed:s}}buildRelative(e,t){const s=[],r=[],a=[],n=[],o=[],{effect:l,length:c}=this.clipConfiguration;if(!l)return{offsetXKeyframes:s,offsetYKeyframes:r,opacityKeyframes:a,scaleKeyframes:n,rotationKeyframes:o};const u=0,h=this.getPresetName();switch(h){case"zoomIn":{const d=this.getZoomSpeed();n.push({from:1,to:d,start:u,length:c,interpolation:"linear"});break}case"zoomOut":{const d=this.getZoomSpeed();n.push({from:d,to:1,start:u,length:c,interpolation:"linear"});break}case"slideLeft":case"slideRight":case"slideUp":case"slideDown":{const d=h==="slideLeft"||h==="slideRight",f=h==="slideLeft"||h==="slideUp",p=this.getFittedSize(e,t),m=d?e.width:e.height,y=d?p.width:p.height;let x=this.getSlideStart();const k=m+m*x*2;if(y<k){const T=k/y;n.push({from:T,to:T,start:u,length:c,interpolation:"linear"})}else x=(y-m)/2/m;const[b,S]=f?[x,-x]:[-x,x];(d?s:r).push({from:b,to:S,start:u,length:c});break}}return{offsetXKeyframes:s,offsetYKeyframes:r,opacityKeyframes:a,scaleKeyframes:n,rotationKeyframes:o}}getPresetName(){return this.effectPreset.name}getZoomSpeed(){const{name:e,speed:t}=this.effectPreset;if(e.startsWith("zoom"))switch(t){case"Slow":return 1.1;case"Fast":return 1.7;default:return 1.3}return 0}getSlideStart(){const{name:e,speed:t}=this.effectPreset;if(e.startsWith("slide"))switch(t){case"Slow":return .03;case"Fast":return .2;default:return .12}return 0}getFittedSize(e,t){switch(this.clipConfiguration.fit??"crop"){case"cover":case"crop":{const r=Math.max(e.width/t.width,e.height/t.height);return{width:t.width*r,height:t.height*r}}case"contain":{const r=Math.min(e.width/t.width,e.height/t.height);return{width:t.width*r,height:t.height*r}}case"none":default:return t}}}class Zx{clipConfiguration;inPreset;outPreset;constructor(e){this.clipConfiguration=e,this.inPreset=this.parseTransition(e.transition?.in),this.outPreset=this.parseTransition(e.transition?.out)}parseTransition(e){const[t,s]=(e??"").split(/(Slow|Fast|VeryFast)/);return{name:t,speed:s}}buildRelative(){return{in:this.buildTransitionKeyframes("in"),out:this.buildTransitionKeyframes("out")}}createEmptyKeyframeSet(){return{offsetXKeyframes:[],offsetYKeyframes:[],opacityKeyframes:[],scaleKeyframes:[],rotationKeyframes:[],maskXKeyframes:[]}}buildTransitionKeyframes(e){const t=this.createEmptyKeyframeSet();if(!(e==="in"?this.clipConfiguration.transition?.in:this.clipConfiguration.transition?.out))return t;const r=this.getPresetLength(e),a=e==="in"?0:this.clipConfiguration.length-r,n=this.getPresetName(e),o=e==="in";switch(n){case"fade":{const[l,c]=o?[0,1]:[1,0];t.opacityKeyframes.push({from:l,to:c,start:a,length:r,interpolation:"bezier",easing:"ease"});break}case"zoom":{const[l,c]=o?[10,1]:[1,10],[u,h]=o?[0,1]:[1,0],d=o?"easeIn":"easeOut";t.scaleKeyframes.push({from:l,to:c,start:a,length:r,interpolation:"bezier",easing:d}),t.opacityKeyframes.push({from:u,to:h,start:a,length:r,interpolation:"bezier",easing:d});break}case"slideLeft":case"slideRight":case"slideUp":case"slideDown":{const l=n==="slideLeft"||n==="slideRight",c=n==="slideLeft"||n==="slideUp",u=.025,[h,d]=o?[c?u:-u,0]:[0,c?-u:u],f=o?"linear":"bezier",[p,m]=o?[0,1]:[1,0];(l?t.offsetXKeyframes:t.offsetYKeyframes).push(o?{from:h,to:d,start:a,length:r,interpolation:f}:{from:h,to:d,start:a,length:r,interpolation:f,easing:"ease"}),t.opacityKeyframes.push({from:p,to:m,start:a,length:r,interpolation:"bezier",easing:"ease"});break}case"carouselLeft":case"carouselRight":case"carouselUp":case"carouselDown":{const l=n==="carouselLeft"||n==="carouselRight",c=n==="carouselLeft"||n==="carouselUp",u=l&&1||(o?1.05:1.1),[h,d]=o?[c?u:-u,0]:[0,c?-u:u];(l?t.offsetXKeyframes:t.offsetYKeyframes).push(o?{from:h,to:d,start:a,length:r,interpolation:"linear"}:{from:h,to:d,start:a,length:r,interpolation:"bezier",easing:"ease"});break}case"reveal":case"wipeRight":{const[l,c]=o?[0,1]:[1,0];t.maskXKeyframes.push({from:l,to:c,start:a,length:r,interpolation:"bezier",easing:"ease"});break}case"wipeLeft":{const[l,c]=o?[1,0]:[0,1];t.maskXKeyframes.push({from:l,to:c,start:a,length:r,interpolation:"bezier",easing:"ease"});break}}return t}getPresetName(e){return e==="in"?this.inPreset.name:this.outPreset.name}getPresetLength(e){const{name:t,speed:s}=e==="in"?this.inPreset:this.outPreset,r=t.startsWith("carousel"),a=t.startsWith("slide");if(t==="zoom")return .4;switch(s){case"Slow":return 2;case"Fast":return r||a?.25:.5;case"VeryFast":return .25;default:return r||a?.5:1}}}const Y={PlaybackPlay:"playback:play",PlaybackPause:"playback:pause",TimelineUpdated:"timeline:updated",TimelineBackgroundChanged:"timeline:backgroundChanged",ClipAdded:"clip:added",ClipSplit:"clip:split",ClipSelected:"clip:selected",ClipUpdated:"clip:updated",ClipDeleted:"clip:deleted",ClipRestored:"clip:restored",ClipCopied:"clip:copied",ClipLoadFailed:"clip:loadFailed",ClipUnresolved:"clip:unresolved",SelectionCleared:"selection:cleared",EditChanged:"edit:changed",EditUndo:"edit:undo",EditRedo:"edit:redo",TrackAdded:"track:added",TrackRemoved:"track:removed",DurationChanged:"duration:changed",OutputResized:"output:resized",OutputResolutionChanged:"output:resolutionChanged",OutputAspectRatioChanged:"output:aspectRatioChanged",OutputFpsChanged:"output:fpsChanged",OutputFormatChanged:"output:formatChanged",OutputDestinationsChanged:"output:destinationsChanged",MergeFieldRegistered:"mergefield:registered",MergeFieldUpdated:"mergefield:updated",MergeFieldRemoved:"mergefield:removed",MergeFieldChanged:"mergefield:changed",MergeFieldApplied:"mergefield:applied",TranscriptionProgress:"transcription:progress",TranscriptionCompleted:"transcription:completed",TranscriptionFailed:"transcription:failed",LumaAttached:"luma:attached",LumaDetached:"luma:detached"},ht={CanvasClipClicked:"canvas:clipClicked",CanvasBackgroundClicked:"canvas:backgroundClicked",FontCapabilitiesChanged:"font:capabilitiesChanged",Resolved:"resolved",PlayerAddedToTrack:"player:addedToTrack",PlayerMovedBetweenTracks:"player:movedBetweenTracks",PlayerRemovedFromTrack:"player:removedFromTrack",TrackContainerRemoved:"track:containerRemoved",ViewportSizeChanged:"viewport:sizeChanged",ViewportNeedsZoomToFit:"viewport:needsZoomToFit"};function Wx(i,e,t){const s=e.width/i.width,r=e.height/i.height;switch(t??"crop"){case"crop":case"cover":return Math.max(s,r);case"contain":return Math.min(s,r);case"none":default:return 1}}function Gx(i,e,t,s,r){if(r)return{x:s,y:s};if(i.width===0||i.height===0)return{x:s,y:s};const a=e.width/i.width,n=e.height/i.height;switch(t??"crop"){case"contain":{const o=Math.min(a,n)*s;return{x:o,y:o}}case"crop":{const o=Math.max(a,n)*s;return{x:o,y:o}}case"cover":return{x:a*s,y:n*s};case"none":default:return{x:s,y:s}}}function Hx(i,e,t){const s=e.width/2,r=e.height/2;switch(t??"crop"){case"cover":{const a=e.width/i.width,n=e.height/i.height;return{scaleX:a,scaleY:n,positionX:s,positionY:r}}case"crop":{const a=Math.max(e.width/i.width,e.height/i.height);return{scaleX:a,scaleY:a,positionX:s,positionY:r}}case"contain":{const a=Math.min(e.width/i.width,e.height/i.height);return{scaleX:a,scaleY:a,positionX:s,positionY:r}}case"none":default:return{scaleX:1,scaleY:1,positionX:s,positionY:r}}}function $f(i){return i*1e3}function au(i){return i/1e3}function LW(i){return i}function DW(i){return i}function Yi(i){return typeof i=="string"&&/^alias:\/\/[a-zA-Z0-9_-]+$/.test(i)}function Mo(i){return i.replace(/^alias:\/\//,"")}let Qf=class{static ButtonLeftClick=0;static ButtonRightClick=3};class Jf{containerSize;constructor(e){this.containerSize=e}relativeToAbsolute(e,t,s){switch(t){case"topLeft":return{x:s.x*this.containerSize.width,y:-s.y*this.containerSize.height};case"topRight":return{x:(s.x+1)*this.containerSize.width-e.width,y:-s.y*this.containerSize.height};case"bottomLeft":return{x:s.x*this.containerSize.width,y:(-s.y+1)*this.containerSize.height-e.height};case"bottomRight":return{x:(s.x+1)*this.containerSize.width-e.width,y:(-s.y+1)*this.containerSize.height-e.height};case"left":return{x:s.x*this.containerSize.width,y:(-s.y+.5)*this.containerSize.height-e.height/2};case"right":return{x:(s.x+1)*this.containerSize.width-e.width,y:(-s.y+.5)*this.containerSize.height-e.height/2};case"top":return{x:(s.x+.5)*this.containerSize.width-e.width/2,y:-s.y*this.containerSize.height};case"bottom":return{x:(s.x+.5)*this.containerSize.width-e.width/2,y:(-s.y+1)*this.containerSize.height-e.height};case"center":default:return{x:(s.x+.5)*this.containerSize.width-e.width/2,y:(-s.y+.5)*this.containerSize.height-e.height/2}}}absoluteToRelative(e,t,s){switch(t){case"topLeft":return{x:s.x/this.containerSize.width,y:-(s.y/this.containerSize.height)};case"topRight":return{x:(s.x+e.width)/this.containerSize.width-1,y:-(s.y/this.containerSize.height)};case"bottomLeft":return{x:s.x/this.containerSize.width,y:-((s.y+e.height)/this.containerSize.height-1)};case"bottomRight":return{x:(s.x+e.width)/this.containerSize.width-1,y:-((s.y+e.height)/this.containerSize.height-1)};case"left":return{x:s.x/this.containerSize.width,y:-((s.y+e.height/2)/this.containerSize.height-.5)};case"right":return{x:(s.x+e.width)/this.containerSize.width-1,y:-((s.y+e.height/2)/this.containerSize.height-.5)};case"top":return{x:(s.x+e.width/2)/this.containerSize.width-.5,y:-(s.y/this.containerSize.height)};case"bottom":return{x:(s.x+e.width/2)/this.containerSize.width-.5,y:-((s.y+e.height)/this.containerSize.height-1)};case"center":default:return{x:(s.x+e.width/2)/this.containerSize.width-.5,y:-((s.y+e.height/2)/this.containerSize.height-.5)}}}}class ep{container;constructor(){this.container=new Q.Container}getContainer(){return this.container}}var tt=(i=>(i.Video="video",i.Image="image",i.Audio="audio",i.Text="text",i.RichText="rich-text",i.Luma="luma",i.Html="html",i.Shape="shape",i.Caption="caption",i.Svg="svg",i.TextToImage="text-to-image",i.ImageToVideo="image-to-video",i.TextToSpeech="text-to-speech",i))(tt||{});class li extends ep{static DiscardedFrameCount=0;layer;shouldDispose;playerType;clipId=null;edit;clipConfiguration;resolvedTiming;positionBuilder;offsetXKeyframeBuilder;offsetYKeyframeBuilder;scaleKeyframeBuilder;opacityKeyframeBuilder;rotationKeyframeBuilder;skewXKeyframeBuilder;skewYKeyframeBuilder;maskXKeyframeBuilder;wipeMask;contentContainer;constructor(e,t,s){super(),this.edit=e,this.layer=0,this.shouldDispose=!1,this.playerType=s,this.clipConfiguration=t,this.positionBuilder=new Jf(e.size),this.resolvedTiming={start:t.start,length:t.length},this.wipeMask=null,this.contentContainer=new Q.Container,this.getContainer().addChild(this.contentContainer)}reconfigureAfterRestore(){this.configureKeyframes()}async reloadAsset(){}configureKeyframes(){const e=this.getLength(),t=this.clipConfiguration,s=typeof t.offset?.x=="number"?t.offset.x:0,r=typeof t.offset?.y=="number"?t.offset.y:0,a=typeof t.scale=="number"?t.scale:1,n=typeof t.opacity=="number"?t.opacity:1,o=typeof t.transform?.rotate?.angle=="number"?t.transform.rotate.angle:0,l=typeof t.transform?.skew?.x=="number"?t.transform.skew.x:0,c=typeof t.transform?.skew?.y=="number"?t.transform.skew.y:0;if(this.offsetXKeyframeBuilder=new br(s,e,"additive"),this.offsetYKeyframeBuilder=new br(r,e,"additive"),this.scaleKeyframeBuilder=new br(a,e,"multiplicative"),this.opacityKeyframeBuilder=new br(n,e,"multiplicative",{min:0,max:1}),this.rotationKeyframeBuilder=new br(o,e,"additive"),this.skewXKeyframeBuilder=new br(l,e,"additive"),this.skewYKeyframeBuilder=new br(c,e,"additive"),this.clipHasKeyframes()){Array.isArray(t.scale)&&this.scaleKeyframeBuilder.addLayer(t.scale),Array.isArray(t.opacity)&&this.opacityKeyframeBuilder.addLayer(t.opacity),Array.isArray(t.offset?.x)&&this.offsetXKeyframeBuilder.addLayer(t.offset.x),Array.isArray(t.offset?.y)&&this.offsetYKeyframeBuilder.addLayer(t.offset.y),Array.isArray(t.transform?.rotate?.angle)&&this.rotationKeyframeBuilder.addLayer(t.transform.rotate.angle),Array.isArray(t.transform?.skew?.x)&&this.skewXKeyframeBuilder.addLayer(t.transform.skew.x),Array.isArray(t.transform?.skew?.y)&&this.skewYKeyframeBuilder.addLayer(t.transform.skew.y);return}const u={...t,start:this.getStart(),length:e},h=new Ux(u).buildRelative(this.edit.size,this.getSize()),d=new Zx(u).buildRelative();this.offsetXKeyframeBuilder.addLayer(h.offsetXKeyframes),this.offsetYKeyframeBuilder.addLayer(h.offsetYKeyframes),this.scaleKeyframeBuilder.addLayer(h.scaleKeyframes),this.opacityKeyframeBuilder.addLayer(h.opacityKeyframes),this.rotationKeyframeBuilder.addLayer(h.rotationKeyframes),this.offsetXKeyframeBuilder.addLayer(d.in.offsetXKeyframes),this.offsetYKeyframeBuilder.addLayer(d.in.offsetYKeyframes),this.scaleKeyframeBuilder.addLayer(d.in.scaleKeyframes),this.opacityKeyframeBuilder.addLayer(d.in.opacityKeyframes),this.rotationKeyframeBuilder.addLayer(d.in.rotationKeyframes),this.offsetXKeyframeBuilder.addLayer(d.out.offsetXKeyframes),this.offsetYKeyframeBuilder.addLayer(d.out.offsetYKeyframes),this.scaleKeyframeBuilder.addLayer(d.out.scaleKeyframes),this.opacityKeyframeBuilder.addLayer(d.out.opacityKeyframes),this.rotationKeyframeBuilder.addLayer(d.out.rotationKeyframes);const f=[...d.in.maskXKeyframes,...d.out.maskXKeyframes];f.length&&(this.maskXKeyframeBuilder=new sn(f,e))}async load(){this.contentContainer?.destroyed&&(this.contentContainer=new Q.Container,this.getContainer().addChild(this.contentContainer)),this.getContainer().sortableChildren=!0,this.getContainer().cursor="pointer",this.getContainer().eventMode="static",this.getContainer().on?.("pointerdown",this.onPointerDown.bind(this))}update(e,t){if(this.getContainer().visible=this.isActive(),this.getContainer().zIndex=1e5-this.layer*100,!this.isActive())return;const s=this.getPivot(),r=this.getPosition(),a=this.getContainerScale();this.getContainer().scale.set(a.x,a.y),this.getContainer().pivot.set(s.x,s.y),this.getContainer().position.set(r.x+s.x,r.y+s.y);const n=this.getRotation();this.contentContainer.alpha=this.getOpacity(),this.getContainer().angle=n;const o=this.getSkew();this.getContainer().skew?.set(o.x*(Math.PI/180),o.y*(Math.PI/180)),this.clipConfiguration.width&&this.clipConfiguration.height&&this.applyFixedDimensions(),this.updateWipeMask(),this.shouldDiscardFrame()&&(this.contentContainer.alpha=0)}updateWipeMask(){if(!this.maskXKeyframeBuilder){this.wipeMask&&(this.getContainer().mask=null,this.wipeMask.destroy(),this.wipeMask=null);return}const e=this.maskXKeyframeBuilder.getValue(this.getPlaybackTime()),t=this.getSize();this.wipeMask||(this.wipeMask=new Q.Graphics,this.getContainer().addChild(this.wipeMask),this.getContainer().mask=this.wipeMask),this.wipeMask.clear(),this.wipeMask.rect(0,0,t.width*e,t.height),this.wipeMask.fill(16777215)}dispose(){this.wipeMask?.destroy(),this.wipeMask=null,this.contentContainer?.destroy()}getStart(){return this.resolvedTiming.start}getLength(){return this.resolvedTiming.length}getEnd(){return this.resolvedTiming.start+this.resolvedTiming.length}getTimingIntent(){if(this.clipId){const e=this.edit.getDocumentClipById(this.clipId);if(e){let t;e.start==="auto"?t="auto":(Yi(e.start),t=e.start);let s;return e.length==="auto"||e.length==="end"||Yi(e.length),s=e.length,{start:t,length:s}}}return{start:this.clipConfiguration.start,length:this.clipConfiguration.length}}getResolvedTiming(){return{...this.resolvedTiming}}setResolvedTiming(e){this.resolvedTiming={...e},this.clipConfiguration.start=e.start,this.clipConfiguration.length=e.length}getExportableClip(){const e=structuredClone(this.clipConfiguration),t=this.getTimingIntent();return e.start=t.start,e.length=t.length,e}getPlaybackTime(){const e=this.edit.playbackTime-this.getStart();return e<0?0:e>this.getLength()?this.getLength():e}getContentSize(){return this.getSize()}getContentContainer(){return this.contentContainer}getOpacity(){return this.opacityKeyframeBuilder?.getValue(this.getPlaybackTime())??1}getPosition(){const e={x:this.offsetXKeyframeBuilder?.getValue(this.getPlaybackTime())??0,y:this.offsetYKeyframeBuilder?.getValue(this.getPlaybackTime())??0};return this.positionBuilder.relativeToAbsolute(this.getSize(),this.clipConfiguration.position??"center",e)}getPivot(){const e=this.getSize();return{x:e.width/2,y:e.height/2}}calculateMoveOffset(e,t){const s=this.getPosition(),r={x:s.x+e,y:s.y+t},a=this.positionBuilder.absoluteToRelative(this.getSize(),this.clipConfiguration.position??"center",r);return{x:a.x,y:a.y}}getFitScale(){const e={width:this.clipConfiguration.width??this.edit.size.width,height:this.clipConfiguration.height??this.edit.size.height},t=this.getContentSize(),s=this.clipConfiguration.fit??"crop";return Wx(t,e,s)}getScale(){return(this.scaleKeyframeBuilder?.getValue(this.getPlaybackTime())??1)*this.getFitScale()}getContainerScale(){const e=this.scaleKeyframeBuilder?.getValue(this.getPlaybackTime())??1,t=this.getContentSize(),s=this.clipConfiguration.fit??"crop",r=!!(this.clipConfiguration.width&&this.clipConfiguration.height);return Gx(t,this.edit.size,s,e,r)}getRotation(){return this.rotationKeyframeBuilder?.getValue(this.getPlaybackTime())??0}getSkew(){return{x:this.skewXKeyframeBuilder?.getValue(this.getPlaybackTime())??0,y:this.skewYKeyframeBuilder?.getValue(this.getPlaybackTime())??0}}isActive(){return this.edit.playbackTime>=this.getStart()&&this.edit.playbackTime<this.getEnd()}shouldDiscardFrame(){return this.getPlaybackTime()<li.DiscardedFrameCount}onPointerDown(e){e.button===Qf.ButtonLeftClick&&this.edit.events.emit(ht.CanvasClipClicked,{player:this})}clipHasKeyframes(){return[this.clipConfiguration.scale,this.clipConfiguration.opacity,this.clipConfiguration.offset?.x,this.clipConfiguration.offset?.y,this.clipConfiguration.transform?.rotate?.angle,this.clipConfiguration.transform?.skew?.x,this.clipConfiguration.transform?.skew?.y].some(e=>e&&typeof e!="number")}applyFixedDimensions(){const e=this.clipConfiguration.width,t=this.clipConfiguration.height;if(!e||!t)return;const s=this.contentContainer.children.find(f=>f instanceof Q.Sprite);if(!s?.texture)return;const r=s.texture.width,a=s.texture.height,n=this.clipConfiguration.fit||"crop",o=this.contentContainer.mask;let l=null;o instanceof Q.Graphics?l=o:o||(l=new Q.Graphics,this.contentContainer.addChild(l),this.contentContainer.mask=l),l&&(l.clear(),l.rect(0,0,e,t),l.fill(16777215));const c=this.scaleKeyframeBuilder?.getValue(this.getPlaybackTime())??1;s.anchor.set(.5,.5);const d=Hx({width:r,height:a},{width:e,height:t},n);s.scale.set(d.scaleX,d.scaleY),s.position.set(d.positionX,d.positionY),this.contentContainer.scale.set(c,c),this.contentContainer.position.set(e/2*(1-c),t/2*(1-c))}applyAnchorPositioning(e,t,s,r){const a=r.width,n=r.height;if(!!r.mask){r.position.set(0,0);return}const l=(e??"center").toLowerCase();let c=0,u=0;l.includes("left")||l==="left"?c=0:l.includes("right")||l==="right"?c=t-a:c=(t-a)/2,l.includes("top")||l==="top"?u=0:l.includes("bottom")||l==="bottom"?u=s-n:u=(s-n)/2,r.position.set(c,u)}supportsEdgeResize(){return!1}onDimensionsChanged(){}notifyDimensionsChanged(){this.onDimensionsChanged()}}class rn{static Name="AudioLoadParser";id;name;extension;validAudioExtensions;constructor(){this.id=rn.Name,this.name=rn.Name,this.extension={type:[Q.ExtensionType.LoadParser],priority:Q.LoaderParserPriority.Normal,ref:null},this.validAudioExtensions=["mp3","mpeg","ogg","wav"]}test(e){const t=e.split("?")[0]?.split(".").pop()??"";return this.validAudioExtensions.includes(t)}async load(e,t,s){return new Promise(r=>{const a={src:e},n=new Howl(a);n.on("load",()=>r(n)),n.on("loaderror",()=>r(null))})}unload(e){e?.unload()}}class jx extends li{audioResource;isPlaying;volumeKeyframeBuilder;syncTimer;constructor(e,t){super(e,t,tt.Audio),this.audioResource=null,this.isPlaying=!1,this.syncTimer=0}async load(){await super.load();const e=this.clipConfiguration.asset,t=e.src,s={src:t,parser:rn.Name},r=await this.edit.assetLoader.load(t,s);if(!(r instanceof Rx.Howl))throw new Error(`Invalid audio source '${e.src}'.`);this.audioResource=r;const n=typeof e.volume=="number"?e.volume:1;this.volumeKeyframeBuilder=new sn(this.createVolumeKeyframes(e,n),this.getLength(),n),this.configureKeyframes()}update(e,t){super.update(e,t);const{trim:s=0}=this.clipConfiguration.asset;if(this.syncTimer+=t,this.getContainer().alpha=0,!this.audioResource)return;const r=this.edit.isPlaying&&this.isActive(),a=this.getPlaybackTime();r&&(this.isPlaying||(this.isPlaying=!0,this.audioResource.seek(a+s),this.audioResource.play()),this.audioResource.volume()!==this.getVolume()&&this.audioResource.volume(this.getVolume()),Math.abs(this.audioResource.seek()-s-a)>.1&&(this.audioResource.seek(a+s),this.edit.recordSyncCorrection())),this.isPlaying&&!r&&(this.isPlaying=!1,this.audioResource.pause());const n=this.syncTimer>100;!this.edit.isPlaying&&this.isActive()&&n&&(this.syncTimer=0,this.audioResource.seek(a+s))}dispose(){this.audioResource?.unload(),this.audioResource=null}reconfigureAfterRestore(){super.reconfigureAfterRestore();const e=this.clipConfiguration.asset,t=typeof e.volume=="number"?e.volume:1;this.volumeKeyframeBuilder=new sn(this.createVolumeKeyframes(e,t),this.getLength(),t)}getSize(){return{width:0,height:0}}getVolume(){return this.volumeKeyframeBuilder.getValue(this.getPlaybackTime())}getCurrentDrift(){if(!this.audioResource)return 0;const{trim:e=0}=this.clipConfiguration.asset,t=this.audioResource.seek(),s=this.getPlaybackTime();return Math.abs(t-e-s)}createVolumeKeyframes(e,t){const{effect:s,volume:r}=e;if(!s||s==="none"||Array.isArray(r))return r??1;const a=this.getLength()/1e3,n=Math.min(2,a/2);return s==="fadeIn"?[{from:0,to:t,start:0,length:n}]:s==="fadeOut"?[{from:t,to:0,start:a-n,length:n}]:[{from:0,to:t,start:0,length:n},{from:t,to:0,start:a-n,length:n}]}}function Vo(i){const e=i.trim().replace(",","."),t=e.split(":");if(t.length===3){const s=parseInt(t[0],10),r=parseInt(t[1],10),a=parseFloat(t[2]);return s*3600+r*60+a}if(t.length===2){const s=parseInt(t[0],10),r=parseFloat(t[1]);return s*60+r}return parseFloat(e)||0}function Yx(i){const e=[],t=i.split(/\r?\n/);let s=0;for(;s<t.length&&!t[s].includes("-->");)s+=1;for(;s<t.length;){const r=t[s].trim();if(r.includes("-->")){const[a,n]=r.split("-->").map(u=>u.trim().split(" ")[0]),o=Vo(a),l=Vo(n),c=[];for(s+=1;s<t.length&&t[s].trim()!==""&&!t[s].includes("-->");){const u=t[s].trim();u.startsWith("NOTE")||c.push(u),s+=1}c.length>0&&e.push({start:o,end:l,text:c.join(`
2
2
  `)})}else s+=1}return e}function Xx(i){const e=[],t=i.split(/\r?\n/);let s=0;for(;s<t.length;){const r=t[s].trim();if(/^\d+$/.test(r)||r==="")s+=1;else if(r.includes("-->")){const[a,n]=r.split("-->").map(u=>u.trim()),o=Vo(a),l=Vo(n),c=[];for(s+=1;s<t.length&&t[s].trim()!=="";)c.push(t[s].trim()),s+=1;c.length>0&&e.push({start:o,end:l,text:c.join(`
3
3
  `)})}else s+=1}return e}function qx(i){return i.trim().startsWith("WEBVTT")?Yx(i):Xx(i)}function Kx(i,e){return i.find(t=>e>=t.start&&e<=t.end)??null}const $x=`
4
4
  let transcriber = null;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "cpuccino",
6
6
  "dazzatron"
7
7
  ],
8
- "version": "2.0.0-beta.20",
8
+ "version": "2.0.0-beta.21",
9
9
  "description": "A video editing library for creating and editing videos with Shotstack",
10
10
  "type": "module",
11
11
  "main": "dist/shotstack-studio.umd.js",