melies-video-editor 0.1.0
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/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/index.cjs +14 -0
- package/dist/index.js +2033 -0
- package/dist/style.css +1 -0
- package/dist/types/App.d.ts +10 -0
- package/dist/types/audioControl.d.ts +29 -0
- package/dist/types/custom.d.ts +14 -0
- package/dist/types/footageBin.d.ts +12 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/lib/index.d.ts +3 -0
- package/dist/types/lottieControl.d.ts +28 -0
- package/dist/types/mediaCache.d.ts +20 -0
- package/dist/types/mock.d.ts +23 -0
- package/dist/types/player.d.ts +15 -0
- package/dist/types/useCoarsePointer.d.ts +1 -0
- package/dist/types/videoControl.d.ts +30 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Video Editor GUI (React)
|
|
2
|
+
|
|
3
|
+
This repo builds and publishes a reusable React video timeline editor GUI.
|
|
4
|
+
|
|
5
|
+
**Upstream credit:** The timeline editor UI and data model are built on top of **@xzdarcy/react-timeline-editor** (MIT License) by **zdarcy**.
|
|
6
|
+
- NPM: https://www.npmjs.com/package/@xzdarcy/react-timeline-editor
|
|
7
|
+
- License: MIT (see the upstream package for the full text)
|
|
8
|
+
|
|
9
|
+
This project is not affiliated with the upstream author.
|
|
10
|
+
|
|
11
|
+
## Local development
|
|
12
|
+
|
|
13
|
+
- Start the UI (demo app): `pnpm dev`
|
|
14
|
+
|
|
15
|
+
## Build (library)
|
|
16
|
+
|
|
17
|
+
- Build the npm package output into `dist/`: `pnpm build`
|
|
18
|
+
|
|
19
|
+
## Export server (local-only)
|
|
20
|
+
|
|
21
|
+
This repo also contains a simple Express + ffmpeg export server used for local development.
|
|
22
|
+
|
|
23
|
+
- Start the export server (separate terminal): `pnpm dev:server`
|
|
24
|
+
|
|
25
|
+
Notes:
|
|
26
|
+
- Requires `ffmpeg` available on `PATH` (or set `FFMPEG_PATH`).
|
|
27
|
+
- Vite dev server proxies `/export` to `http://localhost:5174` (see `vite.config.ts`).
|
|
28
|
+
- The `server/` folder is **not** included in the published npm package.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("react"),Bt=require("@xzdarcy/react-timeline-editor"),_t=require("howler"),Ft=require("antd"),ve=require("@dnd-kit/core");var gt={exports:{}},et={};var jt;function Ut(){if(jt)return et;jt=1;var u=R,a=Symbol.for("react.element"),m=Symbol.for("react.fragment"),d=Object.prototype.hasOwnProperty,g=u.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,S={key:!0,ref:!0,__self:!0,__source:!0};function E(T,x,A){var P,N={},q=null,z=null;A!==void 0&&(q=""+A),x.key!==void 0&&(q=""+x.key),x.ref!==void 0&&(z=x.ref);for(P in x)d.call(x,P)&&!S.hasOwnProperty(P)&&(N[P]=x[P]);if(T&&T.defaultProps)for(P in x=T.defaultProps,x)N[P]===void 0&&(N[P]=x[P]);return{$$typeof:a,type:T,key:q,ref:z,props:N,_owner:g.current}}return et.Fragment=m,et.jsx=E,et.jsxs=E,et}var tt={};var Ot;function Vt(){return Ot||(Ot=1,process.env.NODE_ENV!=="production"&&(function(){var u=R,a=Symbol.for("react.element"),m=Symbol.for("react.portal"),d=Symbol.for("react.fragment"),g=Symbol.for("react.strict_mode"),S=Symbol.for("react.profiler"),E=Symbol.for("react.provider"),T=Symbol.for("react.context"),x=Symbol.for("react.forward_ref"),A=Symbol.for("react.suspense"),P=Symbol.for("react.suspense_list"),N=Symbol.for("react.memo"),q=Symbol.for("react.lazy"),z=Symbol.for("react.offscreen"),ue=Symbol.iterator,X="@@iterator";function V(t){if(t===null||typeof t!="object")return null;var l=ue&&t[ue]||t[X];return typeof l=="function"?l:null}var K=u.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function M(t){{for(var l=arguments.length,e=new Array(l>1?l-1:0),n=1;n<l;n++)e[n-1]=arguments[n];de("error",t,e)}}function de(t,l,e){{var n=K.ReactDebugCurrentFrame,r=n.getStackAddendum();r!==""&&(l+="%s",e=e.concat([r]));var s=e.map(function(i){return String(i)});s.unshift("Warning: "+l),Function.prototype.apply.call(console[t],console,s)}}var be=!1,ie=!1,fe=!1,ot=!1,Ne=!1,ke;ke=Symbol.for("react.module.reference");function Ye(t){return!!(typeof t=="string"||typeof t=="function"||t===d||t===S||Ne||t===g||t===A||t===P||ot||t===z||be||ie||fe||typeof t=="object"&&t!==null&&(t.$$typeof===q||t.$$typeof===N||t.$$typeof===E||t.$$typeof===T||t.$$typeof===x||t.$$typeof===ke||t.getModuleId!==void 0))}function qe(t,l,e){var n=t.displayName;if(n)return n;var r=l.displayName||l.name||"";return r!==""?e+"("+r+")":e}function De(t){return t.displayName||"Context"}function oe(t){if(t==null)return null;if(typeof t.tag=="number"&&M("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case d:return"Fragment";case m:return"Portal";case S:return"Profiler";case g:return"StrictMode";case A:return"Suspense";case P:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case T:var l=t;return De(l)+".Consumer";case E:var e=t;return De(e._context)+".Provider";case x:return qe(t,t.render,"ForwardRef");case N:var n=t.displayName||null;return n!==null?n:oe(t.type)||"Memo";case q:{var r=t,s=r._payload,i=r._init;try{return oe(i(s))}catch{return null}}}return null}var se=Object.assign,ee=0,Me,ye,y,O,D,F,_;function L(){}L.__reactDisabledLog=!0;function H(){{if(ee===0){Me=console.log,ye=console.info,y=console.warn,O=console.error,D=console.group,F=console.groupCollapsed,_=console.groupEnd;var t={configurable:!0,enumerable:!0,value:L,writable:!0};Object.defineProperties(console,{info:t,log:t,warn:t,error:t,group:t,groupCollapsed:t,groupEnd:t})}ee++}}function Se(){{if(ee--,ee===0){var t={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:se({},t,{value:Me}),info:se({},t,{value:ye}),warn:se({},t,{value:y}),error:se({},t,{value:O}),group:se({},t,{value:D}),groupCollapsed:se({},t,{value:F}),groupEnd:se({},t,{value:_})})}ee<0&&M("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var me=K.ReactCurrentDispatcher,ae;function Pe(t,l,e){{if(ae===void 0)try{throw Error()}catch(r){var n=r.stack.trim().match(/\n( *(at )?)/);ae=n&&n[1]||""}return`
|
|
2
|
+
`+ae+t}}var Le=!1,ze;{var pe=typeof WeakMap=="function"?WeakMap:Map;ze=new pe}function J(t,l){if(!t||Le)return"";{var e=ze.get(t);if(e!==void 0)return e}var n;Le=!0;var r=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var s;s=me.current,me.current=null,H();try{if(l){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(w){n=w}Reflect.construct(t,[],i)}else{try{i.call()}catch(w){n=w}t.call(i.prototype)}}else{try{throw Error()}catch(w){n=w}t()}}catch(w){if(w&&n&&typeof w.stack=="string"){for(var o=w.stack.split(`
|
|
3
|
+
`),c=n.stack.split(`
|
|
4
|
+
`),f=o.length-1,p=c.length-1;f>=1&&p>=0&&o[f]!==c[p];)p--;for(;f>=1&&p>=0;f--,p--)if(o[f]!==c[p]){if(f!==1||p!==1)do if(f--,p--,p<0||o[f]!==c[p]){var h=`
|
|
5
|
+
`+o[f].replace(" at new "," at ");return t.displayName&&h.includes("<anonymous>")&&(h=h.replace("<anonymous>",t.displayName)),typeof t=="function"&&ze.set(t,h),h}while(f>=1&&p>=0);break}}}finally{Le=!1,me.current=s,Se(),Error.prepareStackTrace=r}var b=t?t.displayName||t.name:"",k=b?Pe(b):"";return typeof t=="function"&&ze.set(t,k),k}function te(t,l,e){return J(t,!1)}function $e(t){var l=t.prototype;return!!(l&&l.isReactComponent)}function Be(t,l,e){if(t==null)return"";if(typeof t=="function")return J(t,$e(t));if(typeof t=="string")return Pe(t);switch(t){case A:return Pe("Suspense");case P:return Pe("SuspenseList")}if(typeof t=="object")switch(t.$$typeof){case x:return te(t.render);case N:return Be(t.type,l,e);case q:{var n=t,r=n._payload,s=n._init;try{return Be(s(r),l,e)}catch{}}}return""}var Ie=Object.prototype.hasOwnProperty,G={},W=K.ReactDebugCurrentFrame;function Ce(t){if(t){var l=t._owner,e=Be(t.type,t._source,l?l.type:null);W.setExtraStackFrame(e)}else W.setExtraStackFrame(null)}function Ue(t,l,e,n,r){{var s=Function.call.bind(Ie);for(var i in t)if(s(t,i)){var o=void 0;try{if(typeof t[i]!="function"){var c=Error((n||"React class")+": "+e+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof t[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw c.name="Invariant Violation",c}o=t[i](l,i,n,e,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(f){o=f}o&&!(o instanceof Error)&&(Ce(r),M("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",e,i,typeof o),Ce(null)),o instanceof Error&&!(o.message in G)&&(G[o.message]=!0,Ce(r),M("Failed %s type: %s",e,o.message),Ce(null))}}}var Fe=Array.isArray;function Ve(t){return Fe(t)}function ge(t){{var l=typeof Symbol=="function"&&Symbol.toStringTag,e=l&&t[Symbol.toStringTag]||t.constructor.name||"Object";return e}}function Xe(t){try{return Re(t),!1}catch{return!0}}function Re(t){return""+t}function st(t){if(Xe(t))return M("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ge(t)),Re(t)}var We=K.ReactCurrentOwner,Je={key:!0,ref:!0,__self:!0,__source:!0},Ge,Ze;function at(t){if(Ie.call(t,"ref")){var l=Object.getOwnPropertyDescriptor(t,"ref").get;if(l&&l.isReactWarning)return!1}return t.ref!==void 0}function bt(t){if(Ie.call(t,"key")){var l=Object.getOwnPropertyDescriptor(t,"key").get;if(l&&l.isReactWarning)return!1}return t.key!==void 0}function yt(t,l){typeof t.ref=="string"&&We.current}function St(t,l){{var e=function(){Ge||(Ge=!0,M("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",l))};e.isReactWarning=!0,Object.defineProperty(t,"key",{get:e,configurable:!0})}}function He(t,l){{var e=function(){Ze||(Ze=!0,M("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",l))};e.isReactWarning=!0,Object.defineProperty(t,"ref",{get:e,configurable:!0})}}var Rt=function(t,l,e,n,r,s,i){var o={$$typeof:a,type:t,key:l,ref:e,props:i,_owner:s};return o._store={},Object.defineProperty(o._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(o,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(o,"_source",{configurable:!1,enumerable:!1,writable:!1,value:r}),Object.freeze&&(Object.freeze(o.props),Object.freeze(o)),o};function wt(t,l,e,n,r){{var s,i={},o=null,c=null;e!==void 0&&(st(e),o=""+e),bt(l)&&(st(l.key),o=""+l.key),at(l)&&(c=l.ref,yt(l,r));for(s in l)Ie.call(l,s)&&!Je.hasOwnProperty(s)&&(i[s]=l[s]);if(t&&t.defaultProps){var f=t.defaultProps;for(s in f)i[s]===void 0&&(i[s]=f[s])}if(o||c){var p=typeof t=="function"?t.displayName||t.name||"Unknown":t;o&&St(i,p),c&&He(i,p)}return Rt(t,o,c,r,n,We.current,i)}}var _e=K.ReactCurrentOwner,ct=K.ReactDebugCurrentFrame;function ce(t){if(t){var l=t._owner,e=Be(t.type,t._source,l?l.type:null);ct.setExtraStackFrame(e)}else ct.setExtraStackFrame(null)}var Ke;Ke=!1;function Qe(t){return typeof t=="object"&&t!==null&&t.$$typeof===a}function lt(){{if(_e.current){var t=oe(_e.current.type);if(t)return`
|
|
6
|
+
|
|
7
|
+
Check the render method of \``+t+"`."}return""}}function Et(t){return""}var ut={};function xt(t){{var l=lt();if(!l){var e=typeof t=="string"?t:t.displayName||t.name;e&&(l=`
|
|
8
|
+
|
|
9
|
+
Check the top-level render call using <`+e+">.")}return l}}function dt(t,l){{if(!t._store||t._store.validated||t.key!=null)return;t._store.validated=!0;var e=xt(l);if(ut[e])return;ut[e]=!0;var n="";t&&t._owner&&t._owner!==_e.current&&(n=" It was passed a child from "+oe(t._owner.type)+"."),ce(t),M('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',e,n),ce(null)}}function ft(t,l){{if(typeof t!="object")return;if(Ve(t))for(var e=0;e<t.length;e++){var n=t[e];Qe(n)&&dt(n,l)}else if(Qe(t))t._store&&(t._store.validated=!0);else if(t){var r=V(t);if(typeof r=="function"&&r!==t.entries)for(var s=r.call(t),i;!(i=s.next()).done;)Qe(i.value)&&dt(i.value,l)}}}function Tt(t){{var l=t.type;if(l==null||typeof l=="string")return;var e;if(typeof l=="function")e=l.propTypes;else if(typeof l=="object"&&(l.$$typeof===x||l.$$typeof===N))e=l.propTypes;else return;if(e){var n=oe(l);Ue(e,t.props,"prop",n,t)}else if(l.PropTypes!==void 0&&!Ke){Ke=!0;var r=oe(l);M("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",r||"Unknown")}typeof l.getDefaultProps=="function"&&!l.getDefaultProps.isReactClassApproved&&M("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function At(t){{for(var l=Object.keys(t.props),e=0;e<l.length;e++){var n=l[e];if(n!=="children"&&n!=="key"){ce(t),M("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),ce(null);break}}t.ref!==null&&(ce(t),M("Invalid attribute `ref` supplied to `React.Fragment`."),ce(null))}}var mt={};function pt(t,l,e,n,r,s){{var i=Ye(t);if(!i){var o="";(t===void 0||typeof t=="object"&&t!==null&&Object.keys(t).length===0)&&(o+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var c=Et();c?o+=c:o+=lt();var f;t===null?f="null":Ve(t)?f="array":t!==void 0&&t.$$typeof===a?(f="<"+(oe(t.type)||"Unknown")+" />",o=" Did you accidentally export a JSX literal instead of a component?"):f=typeof t,M("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",f,o)}var p=wt(t,l,e,r,s);if(p==null)return p;if(i){var h=l.children;if(h!==void 0)if(n)if(Ve(h)){for(var b=0;b<h.length;b++)ft(h[b],t);Object.freeze&&Object.freeze(h)}else M("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ft(h,t)}if(Ie.call(l,"key")){var k=oe(t),w=Object.keys(l).filter(function(C){return C!=="key"}),I=w.length>0?"{key: someKey, "+w.join(": ..., ")+": ...}":"{key: someKey}";if(!mt[k+I]){var j=w.length>0?"{"+w.join(": ..., ")+": ...}":"{}";M(`A props object containing a "key" prop is being spread into JSX:
|
|
10
|
+
let props = %s;
|
|
11
|
+
<%s {...props} />
|
|
12
|
+
React keys must be passed directly to JSX without using spread:
|
|
13
|
+
let props = %s;
|
|
14
|
+
<%s key={someKey} {...props} />`,I,k,j,k),mt[k+I]=!0}}return t===d?At(p):Tt(p),p}}function Nt(t,l,e){return pt(t,l,e,!0)}function kt(t,l,e){return pt(t,l,e,!1)}var we=kt,Pt=Nt;tt.Fragment=d,tt.jsx=we,tt.jsxs=Pt})()),tt}var Dt;function Wt(){return Dt||(Dt=1,process.env.NODE_ENV==="production"?gt.exports=Ut():gt.exports=Vt()),gt.exports}var v=Wt();const Ht=({action:u,row:a})=>v.jsx("div",{className:"effect0","data-action-id":u.id,"data-row-id":a.id,children:v.jsx("div",{className:"effect0-text",children:`Audio: ${u.data.name}`})}),Yt=({action:u,row:a})=>v.jsx("div",{className:"effect1","data-action-id":u.id,"data-row-id":a.id,children:v.jsx("div",{className:"effect1-text",children:`Video: ${u.data.name}`})}),qt=({action:u,row:a})=>v.jsx("div",{className:"effect2","data-action-id":u.id,"data-row-id":a.id,children:v.jsx("div",{className:"effect2-text",children:`Video audio: ${u.data.name}`})}),zt=u=>{const a=u.toLowerCase();return a.endsWith(".mp4")||a.endsWith(".webm")||a.endsWith(".mov")||a.endsWith(".m4v")?"video":a.endsWith(".mp3")||a.endsWith(".wav")||a.endsWith(".ogg")||a.endsWith(".m4a")||a.endsWith(".aac")?"audio":"other"};class Xt{blobUrlBySrc=new Map;pendingBySrc=new Map;async preloadToBlobUrl(a){if(!a)return a;const m=this.blobUrlBySrc.get(a);if(m)return m;const d=this.pendingBySrc.get(a);if(d)return d;const g=(async()=>{const S=await fetch(a,{cache:"force-cache"});if(!S.ok)throw new Error(`Failed to fetch ${a}: ${S.status}`);const E=await S.blob(),T=URL.createObjectURL(E);return this.blobUrlBySrc.set(a,T),T})().catch(S=>(console.warn("[mediaCache] preload failed:",a,S),a)).finally(()=>{this.pendingBySrc.delete(a)});return this.pendingBySrc.set(a,g),g}resolve(a){return this.blobUrlBySrc.get(a)??a}warm(a){this.preloadToBlobUrl(a)}warmFromEditorData(a){const m=new Set,d=Array.isArray(a)?a:[];for(const g of d){const S=g?.actions;if(Array.isArray(S))for(const E of S){const T=E?.data?.src;typeof T=="string"&&T&&m.add(T)}}for(const g of m){const S=zt(g);(S==="video"||S==="audio")&&this.warm(g)}}}const it=new Xt,Jt=u=>{if(!u)return;const m=u.split("#")[0].split("?")[0].toLowerCase(),d=m.lastIndexOf(".");if(d<0)return;const g=m.slice(d+1);if(g)return g==="m4a"||g==="m4v"?"mp4":g};class Kt{howlBySrc={};activeByActionId={};getHowl(a){const m=it.resolve(a),d=m.startsWith("blob:")?a:m,g=d;if(this.howlBySrc[g])return this.howlBySrc[g];const S=Jt(a),E=new _t.Howl({src:[d],format:S?[S]:void 0,loop:!0,autoplay:!1,preload:!0});return this.howlBySrc[g]=E,E}unlock(){try{const a=_t.Howler.ctx;a&&a.state==="suspended"&&a.resume()}catch{}}warm(a){a&&(it.warm(a),this.getHowl(a))}seekForEngineTime(a,m,d,g,S){const E=Number(S),T=Number.isFinite(E)?E:0,x=a.duration();if(!Number.isFinite(x)||x<=0){a.seek(Math.max(0,g-d+T),m);return}const A=(g-d+T)%x,P=A<0?A+x:A;a.seek(P,m)}start(a){const{actionId:m,src:d,startTime:g,time:S,engine:E}=a,T=Number(a.offset??0),x=Number.isFinite(T)?T:0,A=this.activeByActionId[m];if(A){const X=this.getHowl(A.src);X.rate(E.getPlayRate(),A.soundId);try{X.playing(A.soundId)||X.play(A.soundId)}catch{}E.isPlaying||this.seekForEngineTime(X,A.soundId,A.startTime,S,A.offset);return}const P=this.getHowl(d),N=P.play();P.rate(E.getPlayRate(),N),this.seekForEngineTime(P,N,g,S,x);let q=performance.now();const z=({time:X})=>{if(!E.isPlaying){this.seekForEngineTime(P,N,g,X,x);return}const V=performance.now();if(!(V-q<500)){q=V;try{const K=Math.max(0,X-g+x),M=Number(P.seek(N));Number.isFinite(M)&&Math.abs(M-K)>.25&&this.seekForEngineTime(P,N,g,X,x)}catch{}}},ue=({rate:X})=>{P.rate(X,N)};E.on("afterSetTime",z),E.on("afterSetPlayRate",ue),this.activeByActionId[m]={src:d,startTime:g,offset:x,soundId:N,engine:E,lastResyncAtMs:q,time:z,rate:ue}}stop(a){const{actionId:m}=a,d=this.activeByActionId[m];if(!d)return;const g=this.getHowl(d.src);try{g.stop(d.soundId)}catch{}d.time&&d.engine.off("afterSetTime",d.time),d.rate&&d.engine.off("afterSetPlayRate",d.rate),delete this.activeByActionId[m]}}const re=new Kt;class Gt{videoEl=null;currentSrc=null;lastSeekAtMs=0;lastRate=null;boundEngine=null;boundActionStart=0;vfcHandle=null;rafHandle=null;attach(a){this.videoEl=a,this.currentSrc=a?.currentSrc||a?.getAttribute("src")||null,this.lastSeekAtMs=0,this.lastRate=null,this.unbindEngine(),this.setActive(!1)}setActive(a){this.videoEl&&(this.videoEl.style.opacity=a?"1":"0")}bindEngine(a,m){this.unbindEngine(),this.boundEngine=a,this.boundActionStart=m,this.tickFromVideo()}unbindEngine(){const a=this.videoEl;if(this.vfcHandle!=null&&a?.cancelVideoFrameCallback)try{a.cancelVideoFrameCallback(this.vfcHandle)}catch{}this.rafHandle!=null&&cancelAnimationFrame(this.rafHandle),this.vfcHandle=null,this.rafHandle=null,this.boundEngine=null}tickFromVideo=()=>{if(!this.videoEl||!this.boundEngine||this.videoEl.paused)return;const a=this.boundActionStart+this.videoEl.currentTime;Math.abs(this.boundEngine.getTime()-a)>.03&&this.boundEngine.setTime(a,!0);const m=this.videoEl;m?.requestVideoFrameCallback?this.vfcHandle=m.requestVideoFrameCallback(()=>this.tickFromVideo()):this.rafHandle=requestAnimationFrame(()=>this.tickFromVideo())};setSource(a){if(!this.videoEl||!a)return;const m=it.resolve(a);if(!((this.videoEl.currentSrc||this.videoEl.getAttribute("src")||"")===m||this.currentSrc===m)){this.currentSrc=m,this.videoEl.preload="auto",this.videoEl.src=m;try{this.videoEl.load()}catch{}}}warm(a){a&&it.warm(a)}setRate(a){this.videoEl&&this.lastRate!==a&&(this.lastRate=a,this.videoEl.playbackRate=a)}seek(a,m){if(this.videoEl)try{const d=performance.now(),g=m?.force===!0,S=this.videoEl.currentTime;if(!g&&!this.videoEl.paused&&(Math.abs(S-a)<.12||d-this.lastSeekAtMs<150))return;const E=this.videoEl.duration;Number.isFinite(E)&&E>0?this.videoEl.currentTime=Math.min(a,Math.max(0,E-.05)):this.videoEl.currentTime=Math.max(0,a),this.lastSeekAtMs=d}catch{}}async play(){if(this.videoEl)try{await this.videoEl.play(),this.boundEngine&&this.tickFromVideo()}catch{}}pause(){this.videoEl&&this.videoEl.pause()}}const $=new Gt,nt=160,rt=5,vt=20,Zt={effect0:{id:"effect0",name:"Play audio",source:{start:({action:u,engine:a,isPlaying:m,time:d})=>{if(m){const{src:g,offset:S}=u.data;re.warm(g),re.start({actionId:u.id,src:g,startTime:u.start,engine:a,time:d,offset:S})}},enter:({action:u,engine:a,isPlaying:m,time:d})=>{if(m){const{src:g,offset:S}=u.data;re.warm(g),re.start({actionId:u.id,src:g,startTime:u.start,engine:a,time:d,offset:S})}},leave:({action:u})=>{re.stop({actionId:u.id})},stop:({action:u})=>{re.stop({actionId:u.id})}}},effect2:{id:"effect2",name:"Play video audio",source:{start:({action:u,engine:a,isPlaying:m,time:d})=>{if(m){const{src:g,offset:S}=u.data;re.warm(g),re.start({actionId:u.id,src:g,startTime:u.start,engine:a,time:d,offset:S})}},enter:({action:u,engine:a,isPlaying:m,time:d})=>{if(m){const{src:g,offset:S}=u.data;re.warm(g),re.start({actionId:u.id,src:g,startTime:u.start,engine:a,time:d,offset:S})}},leave:({action:u})=>{re.stop({actionId:u.id})},stop:({action:u})=>{re.stop({actionId:u.id})}}},effect1:{id:"effect1",name:"Play video",source:{start:({action:u,engine:a,isPlaying:m,time:d})=>{const{src:g,previewSrc:S,offset:E}=u.data??{},T=S||g;T&&($.warm(T),$.setSource(T)),$.setActive(!0),$.setRate(a.getPlayRate());const x=Number(E??0);$.seek(Math.max(0,d-u.start+(Number.isFinite(x)?x:0)),{force:!0}),m&&$.play()},enter:({action:u,engine:a,isPlaying:m,time:d})=>{const{src:g,previewSrc:S,offset:E}=u.data??{},T=S||g;T&&($.warm(T),$.setSource(T)),$.setActive(!0),$.setRate(a.getPlayRate());const x=Number(E??0);$.seek(Math.max(0,d-u.start+(Number.isFinite(x)?x:0)),{force:!0}),m&&$.play()},update:({action:u,engine:a,time:m,isPlaying:d})=>{const{src:g,previewSrc:S,offset:E}=u.data??{},T=S||g;if(T&&$.setSource(T),$.setActive(!0),$.setRate(a.getPlayRate()),!d){const x=Number(E??0);$.seek(Math.max(0,m-u.start+(Number.isFinite(x)?x:0)),{force:!0})}},leave:()=>{$.pause(),$.unbindEngine(),$.setActive(!1)},stop:()=>{$.pause(),$.unbindEngine(),$.setActive(!1)}}}},Qt=[{id:"0",actions:[{id:"action0",start:0,end:10,effectId:"effect1",data:{src:"/footage/Big_Buck_Bunny_720_10s_5MB.mp4",name:"Big Buck Bunny (10s)"}}]},{id:"1",actions:[]},{id:"2",actions:[{id:"action1",start:0,end:10,effectId:"effect0",data:{src:"/footage/file_example_MP3_700KB.mp3",name:"Example MP3 (looped)"}}]},{id:"3",actions:[]}],{Option:en}=Ft.Select,tn=[.2,.5,1,1.5,2],nn=({timelineState:u,autoScrollWhenPlay:a,editorData:m,selectedActionId:d,onDeleteSelectedClip:g,onSplitSelectedClip:S,canUndo:E,canRedo:T,onUndo:x,onRedo:A})=>{const[P,N]=R.useState(!1),[q,z]=R.useState(0),[ue,X]=R.useState(!1),V=R.useRef(0),K=R.useRef(0),M=R.useRef(0),de=R.useRef(0),be=R.useRef(0),ie=R.useRef(0),fe=!!d,Ne=(()=>{if(!d)return null;const y=Array.isArray(m)?m:[];for(const O of y){const D=O?.actions;if(Array.isArray(D))for(const F of D){if(String(F?.id)!==d)continue;const _=Number(F?.start),L=Number(F?.end);return!Number.isFinite(_)||!Number.isFinite(L)?null:{start:_,end:L}}}return null})(),ke=!!(Ne&&q>Ne.start&&q<Ne.end),Ye=y=>{const O=Array.isArray(m)?m:[];for(const D of O){const F=D?.actions;if(Array.isArray(F))for(const _ of F){if(_?.effectId!=="effect1")continue;const L=Number(_?.start),H=Number(_?.end);if(!(!Number.isFinite(L)||!Number.isFinite(H))&&y>=L&&y<H)return!0}}return!1},qe=y=>{Ye(y)||($.pause(),$.unbindEngine(),$.setActive(!1))};R.useEffect(()=>{if(!u.current)return;const y=u.current,O=()=>N(!0),D=()=>N(!1),F=({time:L})=>{z(L),qe(L)},_=({time:L})=>{const H=performance.now();if(!(H-V.current<33)&&(V.current=H,z(L),qe(L),a.current)){const me=L*(nt/rt)+vt-500,ae=u.current;ae&&ae.setScrollLeft(me)}};return y.listener.on("play",O),y.listener.on("paused",D),y.listener.on("afterSetTime",F),y.listener.on("setTimeByTick",_),()=>{y.listener.off("play",O),y.listener.off("paused",D),y.listener.off("afterSetTime",F),y.listener.off("setTimeByTick",_)}},[m]);const De=()=>{u.current&&(u.current.isPlaying?u.current.pause():(re.unlock(),u.current.play({autoEnd:!0})))},oe=y=>{u.current&&u.current.setPlayRate(y)},se=y=>{const O=(parseInt(y%1*100+"")+"").padStart(2,"0"),D=(parseInt(y/60+"")+"").padStart(2,"0"),F=(parseInt(y%60+"")+"").padStart(2,"0");return v.jsx(v.Fragment,{children:`${D}:${F}.${O.replace("0.","")}`})},ee=()=>{const y=[],O=new Set,D=Array.isArray(m)?m:[];for(const F of D){const _=F?.actions;if(Array.isArray(_))for(const L of _){const H=L?.data?.src;if(!H)continue;const Se=String(H);O.has(Se)||(O.add(Se),y.push(Se))}}return y},Me=(y,O)=>{const D=URL.createObjectURL(y),F=document.createElement("a");F.href=D,F.download=O,document.body.appendChild(F),F.click(),F.remove(),setTimeout(()=>URL.revokeObjectURL(D),3e3)},ye=async()=>{if(!ue){X(!0);try{const y=ee(),O=new FormData;O.append("timeline",JSON.stringify({editorData:m}));for(const _ of y){const L=await fetch(_);if(!L.ok)throw new Error(`Failed to fetch asset: ${_} (${L.status})`);const H=await L.blob();O.append("assets",H,encodeURIComponent(_))}const D=await fetch("/export",{method:"POST",body:O});if(!D.ok){const _=await D.text().catch(()=>"");throw new Error(_||`Export failed (${D.status})`)}const F=await D.blob();Me(F,"export.mp4")}finally{X(!1)}}};return v.jsxs("div",{className:"timeline-player",children:[v.jsx("div",{className:"play-control",role:"button",tabIndex:0,"aria-label":P?"Pause":"Play",onClick:()=>{Date.now()-K.current<450||De()},onPointerUp:y=>{y.pointerType!=="mouse"&&(K.current=Date.now(),De())},children:v.jsx("img",{src:P?"/pause-button.png":"/play-button.png",alt:"",draggable:!1})}),v.jsx("div",{className:"time",children:se(q)}),v.jsxs("div",{className:"history-tools",children:[v.jsx("button",{type:"button",className:"history-tool",disabled:!E,"aria-label":"Undo",onClick:()=>{Date.now()-be.current<450||E&&x()},onPointerUp:y=>{y.pointerType!=="mouse"&&(be.current=Date.now(),E&&x())},children:v.jsx("img",{src:"/undo.png",alt:"",draggable:!1})}),v.jsx("button",{type:"button",className:"history-tool",disabled:!T,"aria-label":"Redo",onClick:()=>{Date.now()-ie.current<450||T&&A()},onPointerUp:y=>{y.pointerType!=="mouse"&&(ie.current=Date.now(),T&&A())},children:v.jsx("img",{src:"/redo.png",alt:"",draggable:!1})})]}),v.jsx("div",{className:"rate-control",children:v.jsx(Ft.Select,{size:"small",defaultValue:1,style:{width:120},onChange:oe,children:tn.map(y=>v.jsx(en,{value:y,children:`${y.toFixed(1)}x`},y))})}),v.jsxs("div",{className:"clip-tools",children:[v.jsx("button",{type:"button",className:"clip-tool clip-tool-delete",disabled:!fe,"aria-label":"Delete selected clip",onClick:()=>{Date.now()-M.current<450||fe&&g()},onPointerUp:y=>{y.pointerType!=="mouse"&&(M.current=Date.now(),fe&&g())},children:v.jsx("img",{src:"/bin.png",alt:"",draggable:!1})}),v.jsx("button",{type:"button",className:"clip-tool clip-tool-split",disabled:!ke,"aria-label":"Split selected clip at cursor",onClick:()=>{Date.now()-de.current<450||ke&&S()},onPointerUp:y=>{y.pointerType!=="mouse"&&(de.current=Date.now(),ke&&S())},children:v.jsx("img",{src:"/split.png",alt:"",draggable:!1})})]}),v.jsx("div",{className:"export-control",children:v.jsx(Ft.Button,{size:"small",type:"primary",loading:ue,onClick:ye,children:"Export"})})]})};function rn(){const u=()=>typeof window>"u"?!1:typeof navigator<"u"&&(navigator.maxTouchPoints??0)>0,[a,m]=R.useState(u);return R.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const d=window.matchMedia("(pointer: coarse)"),g=()=>m(!!d.matches||u());return g(),typeof d.addEventListener=="function"?(d.addEventListener("change",g),()=>d.removeEventListener("change",g)):(d.addListener(g),()=>d.removeListener(g))},[]),a}const on=structuredClone(Qt),ht=5,Mt=({item:u,hint:a,isDragging:m})=>v.jsxs("div",{className:`footage-card${m?" is-dragging":""}`,children:[v.jsx("div",{className:"footage-name",children:u.name}),u.kind==="video"?v.jsx("video",{className:"footage-preview",src:u.src,muted:!0,preload:"metadata",draggable:!1,onDragStart:d=>d.preventDefault(),playsInline:!0}):v.jsx("audio",{className:"footage-audio",src:u.src,controls:!0,preload:"metadata",draggable:!1,onDragStart:d=>d.preventDefault()}),v.jsx("div",{className:"footage-kind",children:a})]}),sn=({item:u,hint:a})=>{const{attributes:m,listeners:d,setNodeRef:g,transform:S,isDragging:E}=ve.useDraggable({id:`footage-${u.id}`,data:{item:u}}),T=S?{transform:`translate3d(${S.x}px, ${S.y}px, 0)`}:void 0;return v.jsx("div",{ref:g,style:T,...d,...m,children:v.jsx(Mt,{item:u,hint:a,isDragging:E})})},an=u=>String(u??"").toLowerCase().match(/\.(mp3|wav|m4a|aac|ogg)(\?|#|$)/)?"audio":"video",cn=(u,a)=>{try{const m=String(u??"").split("/").pop()||"";return decodeURIComponent(m.split("?")[0].split("#")[0])||`Footage ${a+1}`}catch{return`Footage ${a+1}`}},ln=({footageUrls:u})=>{const[a,m]=R.useState(on),[d,g]=R.useState(null),[S,E]=R.useState([]),[T,x]=R.useState([]),A=R.useRef(a),P=rn(),N=R.useRef(null),q=R.useRef(null),z=R.useRef(null),ue=R.useRef(!0),X=R.useMemo(()=>{const e=Array.isArray(u)?u.filter(Boolean):[];return e.length?e.map((n,r)=>({id:`url-${r}`,kind:an(n),name:cn(n,r),src:n,defaultDuration:10})):[]},[u]),[V,K]=R.useState(null),[M,de]=R.useState(null),[be,ie]=R.useState(null),[fe,ot]=R.useState(0),[Ne,ke]=R.useState(0),[Ye,qe]=R.useState(0),[De,oe]=R.useState(0),[se,ee]=R.useState(!1),[Me,ye]=R.useState(null),y=R.useRef(null),O=R.useRef(null),D=R.useRef(null),F=R.useRef(null),_=P?48:32,L=[0,1],H=[2,3],Se=["V1","V2","A1","A2"],me=(e,n)=>{if(n.length===0)return null;if(e==null)return n[0];let r=n[0],s=Math.abs(e-r);for(const i of n){const o=Math.abs(e-i);o<s&&(r=i,s=o)}return r},ae=(e,n)=>e?e.kind==="video"?me(n,L):me(n,H):null,Pe=e=>e===L[1]?H[1]:H[0];R.useEffect(()=>{it.warmFromEditorData(a)},[a]),R.useEffect(()=>{A.current=a},[a]),R.useLayoutEffect(()=>{const e=z.current;if(!e)return;const n=()=>{const s=e.getBoundingClientRect(),i=e.querySelector(".timeline-editor-edit-area");if(!i)return;const o=i.getBoundingClientRect();qe(o.top-s.top),oe(o.left-s.left)},r=requestAnimationFrame(n);return window.addEventListener("resize",n),()=>{cancelAnimationFrame(r),window.removeEventListener("resize",n)}},[P,a.length]);const Le=e=>{const n=z.current;if(!n||!e)return!1;const r=n.getBoundingClientRect();return e.x>=r.left&&e.x<=r.right&&e.y>=r.top&&e.y<=r.bottom},ze=R.useRef(0),pe=()=>globalThis.crypto?.randomUUID?globalThis.crypto.randomUUID():`uid-${++ze.current}`,J=R.useRef(null),te=R.useRef(null),$e=R.useRef(null),Be=.9,Ie=1.05,G=R.useRef({actionId:null,edge:null}),W=R.useRef({actionId:null,mode:null,dir:null,basePointerTime:null,lastPointerTime:null,initialStart:0,initialEnd:0,takeover:!1}),Ce=R.useRef(!1),Ue=e=>e.map(n=>{const r=(n.actions??[]).map(s=>`${String(s.id)}@${Number(s.start)}-${Number(s.end)}`).join("|");return`${String(n.id)}:${r}`}).join("||"),Fe=e=>{const n=structuredClone(e);E(r=>{const s=[...r,n];return s.length>ht&&s.splice(0,s.length-ht),s}),x([])},Ve=(e,n,r,s)=>e<s&&n>r,ge=(e,n,r,s)=>{const i=Array.isArray(e?.actions)?e.actions:[];for(const o of i)if(!(!o||o.id===n)&&Ve(r,s,Number(o.start),Number(o.end)))return!0;return!1},Xe=(e,n)=>{for(let r=0;r<e.length;r++){const s=e[r],i=Array.isArray(s?.actions)?s.actions:[];for(let o=0;o<i.length;o++){const c=i[o];if(String(c?.id)===n)return{rowIndex:r,actionIndex:o,action:c}}}return null},Re=(e,n)=>{const r=Xe(e,n),s=r?.action?.data?.linkId;if(!r||!s)return null;for(let i=0;i<e.length;i++){const o=e[i],c=Array.isArray(o?.actions)?o.actions:[];for(let f=0;f<c.length;f++){const p=c[f];if(p?.data?.linkId&&String(p.data.linkId)===String(s)&&String(p.id)!==String(n))return{rowIndex:i,actionIndex:f,action:p}}}return null},st=(e,n)=>{const r=Xe(e,n);if(!r)return e;const s=Re(e,n);if(!s)return e;const i=Number(r.action.start),o=Number(r.action.end);if(!Number.isFinite(i)||!Number.isFinite(o)||o<=i||Number(s.action.start)===i&&Number(s.action.end)===o)return e;const c=structuredClone(e),f=c[s.rowIndex],p=Array.isArray(f.actions)?[...f.actions]:[],h={...p[s.actionIndex],start:i,end:o};return p.splice(s.actionIndex,1,h),f.actions=p,c},We=(e,n,r,s)=>{if(!Number.isFinite(r)||!Number.isFinite(s)||s<=r)return e;const i=Xe(e,n);if(!i)return e;const o=Re(e,n);if(!o)return e;const c=structuredClone(e),f=c[i.rowIndex],p=Array.isArray(f.actions)?[...f.actions]:[],h={...p[i.actionIndex],start:r,end:s};p.splice(i.actionIndex,1,h),f.actions=p;const b=c[o.rowIndex],k=Array.isArray(b.actions)?[...b.actions]:[],w={...k[o.actionIndex],start:r,end:s};return k.splice(o.actionIndex,1,w),b.actions=k,c},Je=(e,n,r,s)=>{if(!Number.isFinite(r)||!Number.isFinite(s)||s<=r)return e;const i=Xe(e,n);if(!i)return e;const o=Number(i.action.start),c=Number(i.action.end);if(o===r&&c===s)return e;const f=structuredClone(e),p=f[i.rowIndex],h=Array.isArray(p.actions)?[...p.actions]:[],b={...h[i.actionIndex],start:r,end:s};return h.splice(i.actionIndex,1,b),p.actions=h,f},Ge=()=>{const e=N.current?.getTime?Number(N.current.getTime()):0;return Number.isFinite(e)?Math.max(0,e):0},Ze=(e,n,r)=>{const s=Ge(),i=r-n;if(!Number.isFinite(i)||i<=0)return{start:n,end:r,snapped:!1,edge:null};const o=Math.abs(n-s),c=Math.abs(r-s),f=o<=c?"start":"end",p=Math.min(o,c),h=G.current;if(h.actionId===e&&h.edge!=null){if((h.edge==="start"?o:c)>Ie)return G.current={actionId:e,edge:null},{start:n,end:r,snapped:!1,edge:null}}else{if(p>Be)return{start:n,end:r,snapped:!1,edge:null};G.current={actionId:e,edge:f}}const w=G.current.edge;if(w==="start"){const C=s,B=C+i;return{start:Math.max(0,C),end:Math.max(Math.max(0,C),B),snapped:!0,edge:w}}const I=s,j=I-i;return{start:Math.max(0,j),end:Math.max(0,I),snapped:!0,edge:w}},at=(e,n,r,s)=>{const i=Ge(),o=s==="left"?"start":"end",c=Math.abs(o==="start"?n-i:r-i),f=G.current;if(f.actionId===e&&f.edge===o){if(c>Ie)return G.current={actionId:e,edge:null},{start:n,end:r,snapped:!1}}else{if(c>Be)return{start:n,end:r,snapped:!1};G.current={actionId:e,edge:o}}if(o==="start"){const w=Math.max(0,i),I=Math.max(w+.01,r);return{start:w,end:I,snapped:!0}}const b=Math.max(0,i),k=Math.min(n,b-.01);return{start:Math.max(0,k),end:b,snapped:!0}},bt=(e,n,r)=>{const s=e.defaultDuration??10;let i=Math.max(0,n),o=i+s;const c=N.current;c?.isPlaying&&c.pause(),m(f=>{Fe(f);const p=structuredClone(f);for(;p.length<4;)p.push({id:`${p.length}`,actions:[]});const h=Number.isFinite(Number(r))?Number(r):null,b=me(h,L)??L[0],k=me(h,H)??H[0],w=I=>{const j=[];for(const C of I){const B=Array.isArray(p[C]?.actions)?p[C].actions:[];for(const Z of B){const he=Number(Z?.start),Ee=Number(Z?.end);!Number.isFinite(he)||!Number.isFinite(Ee)||j.push({start:he,end:Ee})}}j.sort((C,B)=>C.start-B.start);for(const C of j)Ve(i,o,C.start,C.end)&&(i=C.end,o=i+s)};if(e.kind==="video"){const I=b,j=Pe(I);w([I,j]);const C=`link-${pe()}`,B=`video-${pe()}`,Z=`video-audio-${pe()}`;p[I].actions=[...p[I].actions??[],{id:B,start:i,end:o,effectId:"effect1",data:{src:e.src,previewSrc:e.previewSrc,name:e.name,linkId:C}}],p[j].actions=[...p[j].actions??[],{id:Z,start:i,end:o,effectId:"effect2",data:{src:e.src,name:e.name,linkId:C}}]}else{const I=k;w([I]),p[I].actions=[...p[I].actions??[],{id:`audio-${pe()}`,start:i,end:o,effectId:"effect0",data:{src:e.src,name:e.name}}]}return p})},yt=()=>{const e=z.current;return e?e.querySelector(".timeline-editor-edit-area .ReactVirtualized__Grid")?.scrollLeft??0:0},St=()=>fe,He=e=>{const n=z.current;if(!n)return 0;const s=(n.querySelector(".timeline-editor-edit-area")??n).getBoundingClientRect(),c=(e-s.x+yt()-vt)*rt/nt;return Math.max(0,c)},Rt=e=>{const n=Number(e);return Number.isFinite(n)?vt+n*nt/rt:0},wt=(e,n,r,s)=>{const i=e.defaultDuration??10;let o=Math.max(0,n),c=o+i;const f=[];if(e.kind==="video"){const h=r,b=Pe(h);f.push(h,b)}else f.push(r);const p=[];for(const h of f){const b=Array.isArray(s[h]?.actions)?s[h].actions:[];for(const k of b){const w=Number(k?.start),I=Number(k?.end);!Number.isFinite(w)||!Number.isFinite(I)||p.push({start:w,end:I})}}p.sort((h,b)=>h.start-b.start);for(const h of p)Ve(o,c,h.start,h.end)&&(o=h.end,c=o+i);return Math.max(0,o)},_e=e=>{const n=z.current;if(!n)return null;const r=n.querySelector(".timeline-editor-edit-area");if(!r)return null;const s=r.getBoundingClientRect(),i=e-s.y;if(i<0||i>s.height)return null;const o=i+St(),c=Math.floor(o/_);if(!Number.isFinite(c))return null;const f=Math.max(0,A.current.length-1);return Math.min(Math.max(0,c),f)},ct=e=>{if(!e)return null;if("clientX"in e&&"clientY"in e){const i=Number(e.clientX),o=Number(e.clientY);if(Number.isFinite(i)&&Number.isFinite(o))return{x:i,y:o}}const n=e.touches,r=e.changedTouches,s=(n&&n.length?n[0]:null)||(r&&r.length?r[0]:null);if(s){const i=Number(s.clientX),o=Number(s.clientY);if(Number.isFinite(i)&&Number.isFinite(o))return{x:i,y:o}}return null},ce=()=>{if(Ce.current)return;Ce.current=!0;const e=r=>{const s=W.current;if(!s.actionId||!s.mode||r.isPrimary===!1)return;const i=He(r.clientX);s.basePointerTime==null&&(s.basePointerTime=i),s.lastPointerTime=i},n=()=>{W.current={actionId:null,mode:null,dir:null,basePointerTime:null,lastPointerTime:null,initialStart:0,initialEnd:0,takeover:!1},G.current={actionId:null,edge:null}};window.addEventListener("pointermove",e,{capture:!0}),window.addEventListener("pointerup",n,{capture:!0}),window.addEventListener("pointercancel",n,{capture:!0}),W.current._removePointerListeners=()=>{window.removeEventListener("pointermove",e,{capture:!0}),window.removeEventListener("pointerup",n,{capture:!0}),window.removeEventListener("pointercancel",n,{capture:!0}),Ce.current=!1}},Ke=()=>{const e=W.current?._removePointerListeners;e?.(),delete W.current._removePointerListeners},Qe=e=>e.map(n=>({...n,selected:void 0,actions:(n.actions??[]).map(r=>({...r,selected:void 0}))})),lt=R.useMemo(()=>a.map((e,n)=>{const r=d?(e.actions??[]).some(c=>String(c.id)===d):!1,s=V!=null&&be!=null&&n===be,i=Array.isArray(e.classNames)?e.classNames:[],o=s?[...i,"dnd-drop-hover"]:i;return{...e,classNames:o,selected:r,actions:(e.actions??[]).map(c=>({...c,selected:d?String(c.id)===d:!1}))}}),[a,d,V,be]),Et=()=>{if(!d)return;const e=N.current;e?.isPlaying&&e.pause(),m(n=>{Fe(n);let r=null;for(const i of n){const o=Array.isArray(i?.actions)?i.actions:[];for(const c of o){if(String(c?.id)!==d)continue;const f=c?.data?.linkId;f!=null&&(r=String(f));break}if(r!=null)break}return n.map(i=>({...i,actions:(i.actions??[]).filter(o=>!(String(o?.id)===d||r&&String(o?.data?.linkId??"")===r))}))}),g(null)},ut=()=>{if(!d)return;const e=N.current,n=e?.getTime?e.getTime():null;if(n==null)return;const r=Number(n);Number.isFinite(r)&&(e?.isPlaying&&e.pause(),J.current=null,te.current=null,m(s=>{let i=-1,o=-1,c=null;for(let U=0;U<s.length;U++){const Y=s[U],ne=Array.isArray(Y?.actions)?Y.actions:[];for(let Q=0;Q<ne.length;Q++){const Oe=ne[Q];if(String(Oe?.id)===d){i=U,o=Q,c=Oe;break}}if(c)break}if(!c)return s;const f=c?.data?.linkId?String(c.data.linkId):null;let p=-1,h=-1,b=null;if(f)for(let U=0;U<s.length;U++){const Y=s[U],ne=Array.isArray(Y?.actions)?Y.actions:[];for(let Q=0;Q<ne.length;Q++){const Oe=ne[Q];if(String(Oe?.id)!==d&&String(Oe?.data?.linkId??"")===f){p=U,h=Q,b=Oe;break}}if(b)break}const k=Number(c.start),w=Number(c.end);if(!Number.isFinite(k)||!Number.isFinite(w)||!(k<r&&r<w))return s;Fe(s);const I=f&&b?`link-${pe()}`:f,j=f&&b?`link-${pe()}`:f,C=`${String(c.id)}-r-${pe()}`,B=Number(c?.data?.offset??0),Z=Number.isFinite(B)?B:0,he=r-k,Ee=Z+(Number.isFinite(he)?he:0),je={...c,start:k,end:r,id:c.id,data:{...c.data,offset:Z,linkId:I??void 0}},xe={...c,start:r,end:w,id:C,data:{...c.data,offset:Ee,linkId:j??void 0}},Te=structuredClone(s),le=Te[i],Ae=Array.isArray(le.actions)?[...le.actions]:[];if(Ae.splice(o,1,je,xe),Ae.sort((U,Y)=>Number(U.start)-Number(Y.start)),le.actions=Ae,b&&p>=0&&h>=0){const U=Number(b.start),Y=Number(b.end);if(Number.isFinite(U)&&Number.isFinite(Y)&&U===k&&Y===w){const ne=`${String(b.id)}-r-${pe()}`,Q={...b,start:k,end:r,id:b.id,data:{...b.data,linkId:I??void 0}},Oe={...b,start:r,end:w,id:ne,data:{...b.data,linkId:j??void 0}},It=Te[p],Ct=Array.isArray(It.actions)?[...It.actions]:[];Ct.splice(h,1,Q,Oe),Ct.sort((Lt,$t)=>Number(Lt.start)-Number($t.start)),It.actions=Ct}}return Te}))},xt=()=>{const e=N.current,n=e?.getTime?e.getTime():null;e?.isPlaying&&e.pause(),J.current=null,te.current=null,g(null),E(r=>{if(r.length===0)return r;const s=r[r.length-1],i=structuredClone(A.current);return x(o=>[...o,i]),m(structuredClone(s)),r.slice(0,-1)}),n!=null&&requestAnimationFrame(()=>{const r=N.current;r?.setTime&&r.setTime(n)})},dt=()=>{const e=N.current,n=e?.getTime?e.getTime():null;e?.isPlaying&&e.pause(),J.current=null,te.current=null,g(null),x(r=>{if(r.length===0)return r;const s=r[r.length-1],i=structuredClone(A.current);return E(o=>{const c=[...o,i];return c.length>ht&&c.splice(0,c.length-ht),c}),m(structuredClone(s)),r.slice(0,-1)}),n!=null&&requestAnimationFrame(()=>{const r=N.current;r?.setTime&&r.setTime(n)})},ft=ve.useSensors(ve.useSensor(ve.PointerSensor,{activationConstraint:{distance:6}}),ve.useSensor(ve.TouchSensor,{activationConstraint:{delay:180,tolerance:6}})),{setNodeRef:Tt,isOver:At}=ve.useDroppable({id:"timeline-drop"}),mt=e=>{const n=e.active.data.current?.item;K(n??null);const r=ct(e.activatorEvent);if(y.current=r,O.current=r,ye(r),r){const i=Le(r);ee(i);const o=_e(r.y);ie(i?ae(n??null,o):null)}else ie(null),ee(!1);const s=e.active.rect.current.initial;de(s?{width:s.width,height:s.height}:null)},pt=e=>{const n=e.active.rect.current.initial;!M&&n&&de({width:n.width,height:n.height});const r=O.current;if(!r){ie(null);return}const s=Number(e?.delta?.x??0),i=Number(e?.delta?.y??0),o={x:r.x+(Number.isFinite(s)?s:0),y:r.y+(Number.isFinite(i)?i:0)};y.current=o,ye(o);const c=Le(o);ee(c);const f=_e(o.y);ie(c?ae(V,f):null)},Nt=e=>{const n=e.active.data.current?.item,r=O.current,s=Number(e?.delta?.x??0),i=Number(e?.delta?.y??0),o=r?{x:r.x+(Number.isFinite(s)?s:0),y:r.y+(Number.isFinite(i)?i:0)}:y.current;y.current=o;const f=String(e.over?.id??"")==="timeline-drop"||Le(o);if(n&&f&&o){const p=He(o.x),h=_e(o.y),b=ae(n,h);ie(b),bt(n,Math.max(0,p),b)}K(null),de(null),ie(null),ee(!1),ye(null),O.current=null},kt=()=>{K(null),de(null),ie(null),ee(!1),ye(null),O.current=null},we=R.useMemo(()=>{if(!V||!se)return null;const e=Me;if(!e)return null;const n=_e(e.y),r=ae(V,n);if(r==null)return null;const s=He(e.x),i=wt(V,s,r,A.current),o=V.defaultDuration??10;return{laneRow:r,desiredStart:s,start:i,end:i+o,duration:o,kind:V.kind}},[V,se,Me,Ne,fe,_]),Pt=e=>{if(!P||e.pointerType==="mouse"||V)return;if(!!e.target?.closest?.(".timeline-editor-cursor-area, .timeline-editor-cursor")){F.current={pointerId:e.pointerId},D.current=null;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}e.preventDefault();return}D.current={x:e.clientX,y:e.clientY}},t=e=>{if(!P||e.pointerType==="mouse"||V||!F.current||F.current.pointerId!==e.pointerId)return;const n=He(e.clientX);N.current&&N.current.setTime(n),e.preventDefault()},l=e=>{if(!P||e.pointerType==="mouse"||V)return;if(F.current&&F.current.pointerId===e.pointerId){F.current=null;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}e.preventDefault();return}const n=D.current;D.current=null;const r=n?Math.abs(e.clientX-n.x):0,s=n?Math.abs(e.clientY-n.y):0;if(r>10||s>10)return;const o=e.target?.closest?.("[data-action-id]"),c=o?.getAttribute("data-row-id"),f=o?.getAttribute("data-action-id");if(c&&f){g(f);return}const p=He(e.clientX);g(null),N.current&&N.current.setTime(p)};return v.jsx(ve.DndContext,{sensors:ft,collisionDetection:ve.rectIntersection,onDragStart:mt,onDragMove:pt,onDragEnd:Nt,onDragCancel:kt,children:v.jsxs("div",{className:"timeline-editor-engine",children:[v.jsx("div",{className:"player-config",children:v.jsx("div",{className:"footage-bin",children:X.map(e=>v.jsx(sn,{item:e,hint:P?"Press-hold, then drag into timeline":"Drag into timeline"},e.id))})}),v.jsx("div",{className:"player-panel",ref:q,children:v.jsx("video",{className:"player-video",preload:"auto",playsInline:!0,muted:!0,controls:!1,disablePictureInPicture:!0,disableRemotePlayback:!0,controlsList:"nodownload noplaybackrate noremoteplayback",tabIndex:-1,onContextMenu:e=>e.preventDefault(),ref:e=>$.attach(e)})}),v.jsx(nn,{timelineState:N,autoScrollWhenPlay:ue,editorData:a,selectedActionId:d,onDeleteSelectedClip:Et,onSplitSelectedClip:ut,canUndo:S.length>0,canRedo:T.length>0,onUndo:xt,onRedo:dt}),v.jsxs("div",{className:`timeline-drop${At?" is-over":""}`,ref:e=>{z.current=e,Tt(e)},onPointerDown:Pt,onPointerMove:t,onPointerUp:l,children:[v.jsx("div",{className:"timeline-lane-labels",style:{top:Ye,transform:`translateY(${-fe}px)`,height:_*Se.length},children:Se.map((e,n)=>v.jsx("div",{className:`timeline-lane-label${be===n?" is-hover":""}`,style:{height:_},children:e},e))}),we?v.jsx("div",{className:"timeline-ghost-layer",style:{top:Ye,left:De},children:(()=>{const e=nt/rt,n=we.duration*e,r=Rt(we.start)-Ne,s=[];return we.kind==="video"?(s.push({row:we.laneRow,kind:"video"}),s.push({row:Pe(we.laneRow),kind:"audio"})):s.push({row:we.laneRow,kind:"audio"}),s.map(i=>v.jsx("div",{className:`timeline-ghost-clip${i.kind==="video"?" is-video":" is-audio"}`,style:{left:r,top:i.row*_-fe,width:n,height:_}},`${i.kind}-${i.row}`))})()}):null,v.jsx(Bt.Timeline,{scale:rt,scaleWidth:nt,startLeft:vt,rowHeight:_,autoScroll:!0,ref:N,editorData:lt,effects:Zt,onScroll:e=>{const n=Number(e?.scrollTop??0),r=Number(e?.scrollLeft??0);Number.isFinite(n)&&ot(n),Number.isFinite(r)&&ke(r)},onClickTimeArea:(e,n)=>{g(null)},onClickRow:e=>{e.target?.closest?.(".timeline-editor-action")||g(null)},onClickActionOnly:(e,{action:n})=>{const r=n;r?.id&&g(String(r.id))},onActionMoveStart:({action:e})=>{$e.current=String(e?.id??""),G.current={actionId:String(e?.id??""),edge:null};const n=Number(e?.start),r=Number(e?.end);W.current={actionId:String(e?.id??""),mode:"move",dir:null,basePointerTime:null,lastPointerTime:null,initialStart:Number.isFinite(n)?n:0,initialEnd:Number.isFinite(r)?r:0,takeover:!1},ce(),!J.current&&(J.current=structuredClone(a),te.current=Ue(a))},onActionMoveEnd:()=>{const e=J.current,n=te.current;e&&n&&Ue(A.current)!==n&&Fe(e),J.current=null,te.current=null,$e.current=null,G.current={actionId:null,edge:null},W.current={actionId:null,mode:null,dir:null,basePointerTime:null,lastPointerTime:null,initialStart:0,initialEnd:0,takeover:!1},Ke()},onActionResizeStart:({action:e})=>{$e.current=String(e?.id??""),G.current={actionId:String(e?.id??""),edge:null};const n=Number(e?.start),r=Number(e?.end);W.current={actionId:String(e?.id??""),mode:"resize",dir:null,basePointerTime:null,lastPointerTime:null,initialStart:Number.isFinite(n)?n:0,initialEnd:Number.isFinite(r)?r:0,takeover:!1},ce(),!J.current&&(J.current=structuredClone(a),te.current=Ue(a))},onActionResizeEnd:()=>{const e=J.current,n=te.current;e&&n&&Ue(A.current)!==n&&Fe(e),J.current=null,te.current=null,$e.current=null,G.current={actionId:null,edge:null},W.current={actionId:null,mode:null,dir:null,basePointerTime:null,lastPointerTime:null,initialStart:0,initialEnd:0,takeover:!1},Ke()},onActionMoving:({action:e,row:n,start:r,end:s})=>{const i=String(e?.id??""),o=W.current;if(o.takeover&&o.mode==="move"&&o.actionId===i){const j=o.basePointerTime,C=o.lastPointerTime,B=j!=null&&C!=null?C-j:0,Z=o.initialStart+B,he=o.initialEnd+B,Ee=Ze(i,Z,he),je=Ee.start,xe=Ee.end;if(ge(n,String(e.id),je,xe))return!1;const le=A.current,Ae=Re(le,String(e.id));if(Ae){const U=le[Ae.rowIndex];if(U&&ge(U,String(Ae.action.id),je,xe))return!1}return m(U=>{const Y=Ae?We(U,String(e.id),je,xe):Je(U,String(e.id),je,xe);return A.current=Y,Y}),!1}const c=Number(r),f=Number(s);if(!Number.isFinite(c)||!Number.isFinite(f)||f<=c)return!1;const p=Ze(i,c,f),h=p.start,b=p.end;if(!Number.isFinite(h)||!Number.isFinite(b)||b<=h||ge(n,String(e.id),h,b))return!1;const w=A.current,I=Re(w,String(e.id));if(I){const j=w[I.rowIndex];if(j&&ge(j,String(I.action.id),h,b))return!1}if((I||p.snapped)&&m(j=>{const C=I?We(j,String(e.id),h,b):Je(j,String(e.id),h,b);return A.current=C,C}),p.snapped){const j=W.current.lastPointerTime;return W.current={actionId:i,mode:"move",dir:null,basePointerTime:j,lastPointerTime:W.current.lastPointerTime,initialStart:c,initialEnd:f,takeover:!0},ce(),!1}},onActionResizing:({action:e,row:n,start:r,end:s,dir:i})=>{const o=String(e?.id??""),c=W.current,f=i??"right";if(c.takeover&&c.mode==="resize"&&c.actionId===o){const B=c.basePointerTime,Z=c.lastPointerTime,he=B!=null&&Z!=null?Z-B:0,Ee=f==="left"?c.initialStart+he:c.initialStart,je=f==="right"?c.initialEnd+he:c.initialEnd,xe=at(o,Ee,je,f),Te=xe.start,le=xe.end;if(ge(n,String(e.id),Te,le))return!1;const U=A.current,Y=Re(U,String(e.id));if(Y){const ne=U[Y.rowIndex];if(ne&&ge(ne,String(Y.action.id),Te,le))return!1}return m(ne=>{const Q=Y?We(ne,String(e.id),Te,le):Je(ne,String(e.id),Te,le);return A.current=Q,Q}),!1}const p=Number(r),h=Number(s);if(!Number.isFinite(p)||!Number.isFinite(h)||h<=p)return!1;const b=at(o,p,h,f),k=b.start,w=b.end;if(!Number.isFinite(k)||!Number.isFinite(w)||w<=k||ge(n,String(e.id),k,w))return!1;const j=A.current,C=Re(j,String(e.id));if(C){const B=j[C.rowIndex];if(B&&ge(B,String(C.action.id),k,w))return!1}if((C||b.snapped)&&m(B=>{const Z=C?We(B,String(e.id),k,w):Je(B,String(e.id),k,w);return A.current=Z,Z}),b.snapped){const B=W.current.lastPointerTime;return W.current={actionId:o,mode:"resize",dir:f,basePointerTime:B,lastPointerTime:W.current.lastPointerTime,initialStart:p,initialEnd:h,takeover:!0},ce(),!1}},onChange:e=>{const n=Qe(e),r=$e.current,s=r?st(n,r):n;m(s);const i=J.current,o=te.current;i&&o&&(Ue(s)!==o&&Fe(i),J.current=null,te.current=null)},getActionRender:(e,n)=>{if(e.effectId==="effect0")return v.jsx(Ht,{action:e,row:n});if(e.effectId==="effect2")return v.jsx(qt,{action:e,row:n});if(e.effectId==="effect1")return v.jsx(Yt,{action:e,row:n})}})]}),v.jsx(ve.DragOverlay,{children:V?v.jsx("div",{className:"footage-overlay",style:M?{width:M.width,height:M.height}:void 0,children:v.jsx(Mt,{item:V,hint:"Drop on timeline",isDragging:!0})}):null})]})})};exports.MeliesVideoEditor=ln;
|