@bylqwjc/media-editor-server 1.0.19 → 1.0.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/README.md +5 -5
- package/core/dist/browser.cjs +1 -1
- package/core/dist/browser.js +1 -3
- package/core/dist/chunk-MGKYVYOH.js +1 -1
- package/core/dist/chunk-USY6UDGL.js +1 -1
- package/core/dist/chunk-XCBM7P7N.js +1 -1
- package/core/dist/engine.cjs +1 -1
- package/core/dist/engine.js +1 -1
- package/core/dist/filerobot.cjs +1 -1
- package/core/dist/filerobot.js +1 -1
- package/core/dist/index.cjs +1 -1
- package/core/dist/index.js +1 -1
- package/core/package.json +1 -1
- package/core/zod/index.cjs +1 -1
- package/core/zod/index.js +1 -1
- package/core/zod/v3/ZodError.cjs +1 -1
- package/core/zod/v3/ZodError.js +1 -1
- package/core/zod/v3/errors.cjs +1 -1
- package/core/zod/v3/errors.js +1 -1
- package/core/zod/v3/external.cjs +1 -1
- package/core/zod/v3/external.js +1 -1
- package/core/zod/v3/helpers/enumUtil.cjs +1 -1
- package/core/zod/v3/helpers/errorUtil.cjs +1 -1
- package/core/zod/v3/helpers/errorUtil.js +1 -1
- package/core/zod/v3/helpers/parseUtil.cjs +1 -1
- package/core/zod/v3/helpers/parseUtil.js +1 -1
- package/core/zod/v3/helpers/partialUtil.cjs +1 -1
- package/core/zod/v3/helpers/typeAliases.cjs +1 -1
- package/core/zod/v3/helpers/util.cjs +1 -1
- package/core/zod/v3/helpers/util.js +1 -1
- package/core/zod/v3/index.cjs +1 -1
- package/core/zod/v3/index.js +1 -1
- package/core/zod/v3/locales/en.cjs +1 -1
- package/core/zod/v3/locales/en.js +1 -1
- package/core/zod/v3/standard-schema.cjs +1 -1
- package/core/zod/v3/types.cjs +1 -1
- package/core/zod/v3/types.js +1 -1
- package/dist/adapters/express.cjs +1 -1
- package/dist/adapters/express.js +1 -1
- package/dist/adapters/web.cjs +1 -1
- package/dist/adapters/web.js +1 -1
- package/dist/index.cjs +1 -4
- package/dist/index.js +1 -4
- package/express/express/index.cjs +1 -0
- package/express/express/index.d.ts +1 -0
- package/express/express/index.js +1 -0
- package/express/index.cjs +1 -1
- package/express/index.js +1 -1
- package/package.json +1 -1
- package/web/index.cjs +1 -1
- package/web/index.js +1 -1
- package/web/web/index.cjs +1 -0
- package/web/web/index.d.ts +1 -0
- package/web/web/index.js +1 -0
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @media-editor/server
|
|
2
2
|
|
|
3
3
|
Node 侧视频导出和封面抽取处理器。内置 Web 标准适配器和 Express 适配器,依赖 `ffmpeg-static`。
|
|
4
4
|
|
|
5
5
|
## Next.js App Router
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
|
-
import { createVideoExportHandler } from '@
|
|
9
|
-
import { toWebVideoHandler } from '@
|
|
8
|
+
import { createVideoExportHandler } from '@media-editor/server';
|
|
9
|
+
import { toWebVideoHandler } from '@media-editor/server/web';
|
|
10
10
|
|
|
11
11
|
export const runtime = 'nodejs';
|
|
12
12
|
export const maxDuration = 300;
|
|
@@ -19,8 +19,8 @@ export const POST = toWebVideoHandler(createVideoExportHandler());
|
|
|
19
19
|
```ts
|
|
20
20
|
import express from 'express';
|
|
21
21
|
import multer from 'multer';
|
|
22
|
-
import { createPosterHandler, createVideoExportHandler } from '@
|
|
23
|
-
import { expressPoster, expressVideoExport } from '@
|
|
22
|
+
import { createPosterHandler, createVideoExportHandler } from '@media-editor/server';
|
|
23
|
+
import { expressPoster, expressVideoExport } from '@media-editor/server/express';
|
|
24
24
|
|
|
25
25
|
const app = express();
|
|
26
26
|
const upload = multer();
|
package/core/dist/browser.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var v=Math.PI/180;function y(e,t,a){e.strokeStyle=t,e.lineWidth=a,e.lineCap="round",e.lineJoin="round"}function $(e,t,a,n,r,s){const i=Math.atan2(r-a,n-t),c=Math.max(12,s*3.5);e.beginPath(),e.moveTo(n,r),e.lineTo(n-c*Math.cos(i-Math.PI/7),r-c*Math.sin(i-Math.PI/7)),e.moveTo(n,r),e.lineTo(n-c*Math.cos(i+Math.PI/7),r-c*Math.sin(i+Math.PI/7)),e.stroke()}function b(e){if(!Number.isFinite(e))return 0;let t=e%360;return t>180&&(t-=360),t<-180&&(t+=360),Math.abs(t)<.001?0:t}function m(e){return b(e.rotation??0)}function k(e){switch(e.type){case"pen":{let t=1/0,a=1/0,n=-1/0,r=-1/0;for(let s=0;s<e.points.length;s+=2)t=Math.min(t,e.points[s]),n=Math.max(n,e.points[s]),a=Math.min(a,e.points[s+1]),r=Math.max(r,e.points[s+1]);return{x:t,y:a,w:n-t,h:r-a}}case"line":case"arrow":return{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),w:Math.abs(e.x2-e.x1),h:Math.abs(e.y2-e.y1)};case"rect":case"ellipse":case"sticker":return{x:e.x,y:e.y,w:e.w,h:e.h};case"text":return{x:e.x,y:e.y,w:e.text.length*e.fontSize*.6,h:e.fontSize*1.2}}}function g(e){const t=k(e);return{x:t.x+t.w/2,y:t.y+t.h/2}}function A(e,t,a,n,r){const s=r*v,i=Math.cos(s),c=Math.sin(s),h=e-a,o=t-n;return{x:a+h*i-o*c,y:n+h*c+o*i}}function S(e,t,a,n,r){return{x:a+(e-a)*r,y:n+(t-n)*r}}function P(e,t,a){const n=m(t);if(n){const r=g(t);e.save(),e.translate(r.x,r.y),e.rotate(n*v),e.translate(-r.x,-r.y),T(e,t,a),e.restore();return}T(e,t,a)}function T(e,t,a){switch(t.type){case"pen":{y(e,t.color,t.width),e.beginPath(),e.moveTo(t.points[0],t.points[1]);for(let n=2;n<t.points.length;n+=2)e.lineTo(t.points[n],t.points[n+1]);e.stroke();break}case"line":case"arrow":{y(e,t.color,t.width),e.beginPath(),e.moveTo(t.x1,t.y1),e.lineTo(t.x2,t.y2),e.stroke(),t.type==="arrow"&&$(e,t.x1,t.y1,t.x2,t.y2,t.width);break}case"rect":{y(e,t.color,t.width),e.strokeRect(t.x,t.y,t.w,t.h);break}case"ellipse":{y(e,t.color,t.width),e.beginPath(),e.ellipse(t.x+t.w/2,t.y+t.h/2,Math.abs(t.w/2),Math.abs(t.h/2),0,0,Math.PI*2),e.stroke();break}case"text":{e.fillStyle=t.color,e.font=`bold ${t.fontSize}px -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif`,e.textBaseline="top",e.strokeStyle="rgba(0,0,0,0.45)",e.lineWidth=Math.max(2,t.fontSize/16),e.lineJoin="round",e.strokeText(t.text,t.x,t.y),e.fillText(t.text,t.x,t.y);break}case"sticker":{if(t.emoji)e.font=`${Math.min(t.w,t.h)}px -apple-system, "Apple Color Emoji", "Segoe UI Emoji", sans-serif`,e.textBaseline="top",e.fillText(t.emoji,t.x,t.y);else if(t.src){const n=a?.get(t.src);n&&e.drawImage(n,t.x,t.y,t.w,t.h)}break}}}function M(e,t,a){for(const n of t)P(e,n,a)}async function E(e){const t=new Map,a=[...new Set(e.filter(n=>n.type==="sticker"&&n.src).map(n=>n.src))];return await Promise.all(a.map(n=>new Promise(r=>{const s=new Image;s.onload=()=>{t.set(n,s),r()},s.onerror=()=>r(),s.src=n}))),t}async function F(e,t,a){if(!e?.length)return null;const n=document.createElement("canvas");n.width=t,n.height=a;const r=n.getContext("2d");if(!r)return null;const s=await E(e);return M(r,e,s),new Promise(i=>n.toBlob(c=>i(c),"image/png"))}function D(e,t,a,n=12){for(let r=e.length-1;r>=0;r--){const s=e[r];if(R(s,t,a,n))return r}return-1}function N(e,t,a,n,r){return Math.abs(e-a)<=r&&Math.abs(t-n)<=r}function C(e,t,a,n,r,s,i){const c=r-a,h=s-n,o=c*c+h*h||1,u=Math.max(0,Math.min(1,((e-a)*c+(t-n)*h)/o)),l=a+u*c,x=n+u*h;return(e-l)**2+(t-x)**2<=i*i}function R(e,t,a,n){const r=m(e);if(r){const s=g(e),i=A(t,a,s.x,s.y,-r);return I(e,i.x,i.y,n)}return I(e,t,a,n)}function I(e,t,a,n){switch(e.type){case"pen":{for(let r=0;r+3<e.points.length;r+=2)if(C(t,a,e.points[r],e.points[r+1],e.points[r+2],e.points[r+3],n+e.width/2))return!0;return!1}case"line":case"arrow":return C(t,a,e.x1,e.y1,e.x2,e.y2,n+e.width/2);case"rect":case"ellipse":return t>=e.x-n&&t<=e.x+e.w+n&&a>=e.y-n&&a<=e.y+e.h+n;case"text":return t>=e.x-n&&t<=e.x+e.text.length*e.fontSize*.6+n&&a>=e.y-n&&a<=e.y+e.fontSize+n;case"sticker":return N(t,a,e.x+e.w/2,e.y+e.h/2,Math.max(e.w,e.h)/2+n)}}function _(e,t,a){const n=Math.max(8,a);if(!(e>0)||!(t>0))return{w:n,h:n};const r=n/Math.max(e,t);return{w:Math.max(8,Math.round(e*r)),h:Math.max(8,Math.round(t*r))}}function J(e,t){const a=Math.max(.05,t),n=g(e);switch(e.type){case"pen":return{...e,points:e.points.map((r,s)=>s%2===0?n.x+(r-n.x)*a:n.y+(r-n.y)*a)};case"line":case"arrow":{const r=S(e.x1,e.y1,n.x,n.y,a),s=S(e.x2,e.y2,n.x,n.y,a);return{...e,x1:r.x,y1:r.y,x2:s.x,y2:s.y}}case"rect":case"ellipse":case"sticker":return{...e,w:Math.max(8,e.w*a),h:Math.max(8,e.h*a)};case"text":return{...e,fontSize:Math.min(512,Math.max(8,e.fontSize*a))};default:return e}}function U(e,t){return{...e,rotation:b(t)}}function V(e,t,a){switch(e.type){case"pen":{const n=e.points.map((r,s)=>s%2===0?r+t:r+a);return{...e,points:n}}case"line":case"arrow":return{...e,x1:e.x1+t,y1:e.y1+a,x2:e.x2+t,y2:e.y2+a};case"rect":case"ellipse":case"sticker":return{...e,x:e.x+t,y:e.y+a};case"text":return{...e,x:e.x+t,y:e.y+a}}}var O=Math.PI/180;function z(e,t,a){const n=W(a);if(n===0||n===180)return{w:e,h:t};if(n===90||n===270)return{w:t,h:e};const r=n*O;return{w:Math.round(Math.abs(e*Math.cos(r))+Math.abs(t*Math.sin(r))),h:Math.round(Math.abs(e*Math.sin(r))+Math.abs(t*Math.cos(r)))}}function W(e){return(e%360+360)%360}function f(e){const t=Math.round(e);return t-t%2}function L(e,t){let a=e.w,n=a/t;return n>e.h&&(n=e.h,a=n*t),{x:Math.round((e.w-a)/2),y:Math.round((e.h-n)/2),width:Math.round(a),height:Math.round(n)}}function j(e,t,a){const n={x:0,y:0,width:e.width,height:e.height},r={x:0,y:0,width:t.w,height:t.h};return a==="cover"?{src:L({w:e.width,h:e.height},t.w/t.h),dst:r}:a==="contain"?{src:n,dst:L({w:t.w,h:t.h},e.width/e.height)}:{src:n,dst:r}}function B(e,t){if(t.scale)return{w:f(t.scale.width),h:f(t.scale.height)};if(t.crop)return{w:f(t.crop.width),h:f(t.crop.height)};const a=z(e.w,e.h,t.rotation);return{w:f(a.w),h:f(a.h)}}function q(e){const t=String(e??"").match(/^data:(image\/(?:png|jpe?g));base64,([a-z0-9+/=]+)$/i);if(!t)return null;const a=atob(t[2]),n=new Uint8Array(a.length);for(let r=0;r<a.length;r++)n[r]=a.charCodeAt(r);return new Blob([n],{type:t[1].toLowerCase()})}async function H(e,t,a=[]){const n=e.getExportPlan(),r=new FormData;n.videoSrcOrder.forEach((o,u)=>{const l=t[o];l&&r.append(`video_${u}`,l,l.name||`video_${u}.mp4`)}),n.audioSrcOrder.forEach((o,u)=>{const l=a[o];l&&r.append(`audio_${u}`,l,l.name||`audio_${u}`)});const s=B(n.state.canvas,n.state),i=await F(n.state.overlays,s.w,s.h);i&&r.append("overlay",i,"overlay.png");const c=n.state.poster?.useAsVideoCover?q(n.state.poster.preview):null;c&&r.append("videoCover",c,"video-cover.png");const h=n.state.poster?.preview?{...n.state,poster:{...n.state.poster,preview:void 0}}:n.state;return r.append("editState",JSON.stringify(h)),r}var Y=[{id:"bw",label:"\u9ED1\u767D",vf:"hue=s=0",css:"grayscale(1)"},{id:"sepia",label:"\u590D\u53E4",vf:"colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131",css:"sepia(0.85)"},{id:"warm",label:"\u6696\u9633",vf:"colorbalance=rs=.15:gs=.04:bs=-.15",css:"sepia(0.25) saturate(1.25) brightness(1.03)"},{id:"cool",label:"\u51B7\u8C03",vf:"colorbalance=rs=-.14:bs=.16",css:"hue-rotate(12deg) saturate(0.95) brightness(1.02)"},{id:"vivid",label:"\u9C9C\u8273",vf:"eq=saturation=1.45:contrast=1.08",css:"saturate(1.45) contrast(1.08)"}];function X(e){return e?Y.find(t=>t.id===e):void 0}function G(e,t){const a=X(t)?.css??"";return[`brightness(${1+e.brightness})`,`contrast(${1+e.contrast})`,`saturate(${1+e.saturation})`,a].filter(Boolean).join(" ")}function K(e,t,a,n,r,s=1,i,c=!0){const h=B(n,r);e.width=Math.max(2,Math.round(h.w*s)),e.height=Math.max(2,Math.round(h.h*s));const o=e.getContext("2d");if(!o)return;const u=z(n.w,n.h,r.rotation),l=r.crop??{x:0,y:0,width:u.w,height:u.h},x=r.scale?.fit??"force",{src:p,dst:d}=j({width:l.width,height:l.height},h,x);x==="contain"&&(o.fillStyle="#000",o.fillRect(0,0,e.width,e.height)),o.filter=G(r.filters,r.filterPreset),o.save(),x==="contain"&&(o.beginPath(),o.rect(s*d.x,s*d.y,s*d.width,s*d.height),o.clip()),o.translate(s*d.x,s*d.y),o.scale(s*d.width/p.width,s*d.height/p.height),o.translate(-(l.x+p.x),-(l.y+p.y)),o.translate(u.w/2,u.h/2),o.rotate(r.rotation*O),o.scale(r.flipX?-1:1,r.flipY?-1:1);const w=j({width:a.w,height:a.h},{w:n.w,h:n.h},"cover");o.drawImage(t,w.src.x,w.src.y,w.src.width,w.src.height,-n.w/2,-n.h/2,n.w,n.h),o.restore(),o.filter="none",c&&r.overlays?.length&&(o.setTransform(s,0,0,s,0,0),M(o,r.overlays,i),o.setTransform(1,0,0,1,0,0))}function Q(e,t){return new Promise(a=>{const n=()=>{e.removeEventListener("seeked",n),a()};e.addEventListener("seeked",n),e.currentTime=Math.min(Math.max(0,t),e.duration||t)})}async function Z(e,t,a=160){const n=e.duration;if(!n||!isFinite(n)||t<=0)return[];const r=e.videoWidth||16,s=e.videoHeight||9,i=Math.min(a,r),c=Math.max(1,Math.round(i*s/r)),h=document.createElement("canvas");h.width=i,h.height=c;const o=h.getContext("2d");if(!o)return[];const u=[];for(let l=0;l<t;l++)await Q(e,n*(l+.5)/t),o.drawImage(e,0,0,i,c),u.push(h.toDataURL("image/jpeg",.6));return u}function ee(e,t={}){const a=t.mode??"overlay",n=document.createElement("button");n.type="button",n.className=["me-fullscreen-toggle",t.className].filter(Boolean).join(" "),n.dataset.meFullscreenToggle="true",n.dataset.mode=a,n.title="\u5168\u5C4F / \u9000\u51FA\u5168\u5C4F",n.style.cssText=[a==="overlay"?"position:absolute;left:8px;bottom:8px;z-index:30;":"position:static;","width:32px;height:32px;padding:0;","display:inline-flex;align-items:center;justify-content:center;","border:1px solid var(--me-border,#26262b);border-radius:6px;","background:var(--me-chip,#1c1c20);color:var(--me-fg,#e7e7ee);","cursor:pointer;font-size:15px;line-height:1;opacity:0.9;font:inherit;"].join(""),e.classList.add("me-fullscreen-host");const r=()=>{const c=document.fullscreenElement===e;n.textContent=c?"\xD7":"\u26F6",n.setAttribute("aria-label",c?"\u9000\u51FA\u5168\u5C4F":"\u5168\u5C4F"),e.classList.toggle("me-is-fullscreen",c),e.dataset.meFullscreen=c?"true":"false"};r();const s=()=>r(),i=()=>{(document.fullscreenElement===e?document.exitFullscreen?.():e.requestFullscreen?.())?.catch?.(()=>{})};return n.addEventListener("click",i),document.addEventListener("fullscreenchange",s),{button:n,dispose:()=>{document.removeEventListener("fullscreenchange",s),n.removeEventListener("click",i),n.remove(),e.classList.remove("me-fullscreen-host","me-is-fullscreen"),delete e.dataset.meFullscreen}}}exports.buildVideoExportFormData=H,exports.createFullscreenToggle=ee,exports.drawOverlay=P,exports.drawOverlays=M,exports.drawVideoFrame=K,exports.fitStickerBox=_,exports.generateThumbnails=Z,exports.getOverlayRotation=m,exports.hitTestOverlay=D,exports.loadOverlayImages=E,exports.overlayBBox=k,exports.renderOverlaysToPng=F,exports.rotateOverlay=U,exports.scaleOverlay=J,exports.translateOverlay=V;
|
|
1
|
+
"use strict";var v=Math.PI/180;function y(t,e,n){t.strokeStyle=e,t.lineWidth=n,t.lineCap="round",t.lineJoin="round"}function $(t,e,n,r,a,o){const s=Math.atan2(a-n,r-e),i=Math.max(12,3.5*o);t.beginPath(),t.moveTo(r,a),t.lineTo(r-i*Math.cos(s-Math.PI/7),a-i*Math.sin(s-Math.PI/7)),t.moveTo(r,a),t.lineTo(r-i*Math.cos(s+Math.PI/7),a-i*Math.sin(s+Math.PI/7)),t.stroke()}function b(t){if(!Number.isFinite(t))return 0;let e=t%360;return e>180&&(e-=360),e<-180&&(e+=360),Math.abs(e)<.001?0:e}function m(t){return b(t.rotation??0)}function k(t){switch(t.type){case"pen":{let e=1/0,n=1/0,r=-1/0,a=-1/0;for(let o=0;o<t.points.length;o+=2)e=Math.min(e,t.points[o]),r=Math.max(r,t.points[o]),n=Math.min(n,t.points[o+1]),a=Math.max(a,t.points[o+1]);return{x:e,y:n,w:r-e,h:a-n}}case"line":case"arrow":return{x:Math.min(t.x1,t.x2),y:Math.min(t.y1,t.y2),w:Math.abs(t.x2-t.x1),h:Math.abs(t.y2-t.y1)};case"rect":case"ellipse":case"sticker":return{x:t.x,y:t.y,w:t.w,h:t.h};case"text":return{x:t.x,y:t.y,w:t.text.length*t.fontSize*.6,h:1.2*t.fontSize}}}function g(t){const e=k(t);return{x:e.x+e.w/2,y:e.y+e.h/2}}function A(t,e,n,r,a){const o=a*v,s=Math.cos(o),i=Math.sin(o),c=t-n,h=e-r;return{x:n+c*s-h*i,y:r+c*i+h*s}}function S(t,e,n,r,a){return{x:n+(t-n)*a,y:r+(e-r)*a}}function P(t,e,n){const r=m(e);if(r){const a=g(e);return t.save(),t.translate(a.x,a.y),t.rotate(r*v),t.translate(-a.x,-a.y),T(t,e,n),void t.restore()}T(t,e,n)}function T(t,e,n){switch(e.type){case"pen":y(t,e.color,e.width),t.beginPath(),t.moveTo(e.points[0],e.points[1]);for(let n=2;n<e.points.length;n+=2)t.lineTo(e.points[n],e.points[n+1]);t.stroke();break;case"line":case"arrow":y(t,e.color,e.width),t.beginPath(),t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.stroke(),"arrow"===e.type&&$(t,e.x1,e.y1,e.x2,e.y2,e.width);break;case"rect":y(t,e.color,e.width),t.strokeRect(e.x,e.y,e.w,e.h);break;case"ellipse":y(t,e.color,e.width),t.beginPath(),t.ellipse(e.x+e.w/2,e.y+e.h/2,Math.abs(e.w/2),Math.abs(e.h/2),0,0,2*Math.PI),t.stroke();break;case"text":t.fillStyle=e.color,t.font=`bold ${e.fontSize}px -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif`,t.textBaseline="top",t.strokeStyle="rgba(0,0,0,0.45)",t.lineWidth=Math.max(2,e.fontSize/16),t.lineJoin="round",t.strokeText(e.text,e.x,e.y),t.fillText(e.text,e.x,e.y);break;case"sticker":if(e.emoji)t.font=`${Math.min(e.w,e.h)}px -apple-system, "Apple Color Emoji", "Segoe UI Emoji", sans-serif`,t.textBaseline="top",t.fillText(e.emoji,e.x,e.y);else if(e.src){const r=n?.get(e.src);r&&t.drawImage(r,e.x,e.y,e.w,e.h)}}}function M(t,e,n){for(const r of e)P(t,r,n)}async function E(t){const e=new Map,n=[...new Set(t.filter(t=>"sticker"===t.type&&t.src).map(t=>t.src))];return await Promise.all(n.map(t=>new Promise(n=>{const r=new Image;r.onload=()=>{e.set(t,r),n()},r.onerror=()=>n(),r.src=t}))),e}async function F(t,e,n){if(!t?.length)return null;const r=document.createElement("canvas");r.width=e,r.height=n;const a=r.getContext("2d");return a?(M(a,t,await E(t)),new Promise(t=>r.toBlob(e=>t(e),"image/png"))):null}function D(t,e,n,r=12){for(let a=t.length-1;a>=0;a--)if(R(t[a],e,n,r))return a;return-1}function N(t,e,n,r,a){return Math.abs(t-n)<=a&&Math.abs(e-r)<=a}function C(t,e,n,r,a,o,s){const i=a-n,c=o-r,h=i*i+c*c||1,l=Math.max(0,Math.min(1,((t-n)*i+(e-r)*c)/h));return(t-(n+l*i))**2+(e-(r+l*c))**2<=s*s}function R(t,e,n,r){const a=m(t);if(a){const o=g(t),s=A(e,n,o.x,o.y,-a);return I(t,s.x,s.y,r)}return I(t,e,n,r)}function I(t,e,n,r){switch(t.type){case"pen":for(let a=0;a+3<t.points.length;a+=2)if(C(e,n,t.points[a],t.points[a+1],t.points[a+2],t.points[a+3],r+t.width/2))return!0;return!1;case"line":case"arrow":return C(e,n,t.x1,t.y1,t.x2,t.y2,r+t.width/2);case"rect":case"ellipse":return e>=t.x-r&&e<=t.x+t.w+r&&n>=t.y-r&&n<=t.y+t.h+r;case"text":return e>=t.x-r&&e<=t.x+t.text.length*t.fontSize*.6+r&&n>=t.y-r&&n<=t.y+t.fontSize+r;case"sticker":return N(e,n,t.x+t.w/2,t.y+t.h/2,Math.max(t.w,t.h)/2+r)}}function _(t,e,n){const r=Math.max(8,n);if(!(t>0&&e>0))return{w:r,h:r};const a=r/Math.max(t,e);return{w:Math.max(8,Math.round(t*a)),h:Math.max(8,Math.round(e*a))}}function J(t,e){const n=Math.max(.05,e),r=g(t);switch(t.type){case"pen":return{...t,points:t.points.map((t,e)=>e%2==0?r.x+(t-r.x)*n:r.y+(t-r.y)*n)};case"line":case"arrow":{const e=S(t.x1,t.y1,r.x,r.y,n),a=S(t.x2,t.y2,r.x,r.y,n);return{...t,x1:e.x,y1:e.y,x2:a.x,y2:a.y}}case"rect":case"ellipse":case"sticker":return{...t,w:Math.max(8,t.w*n),h:Math.max(8,t.h*n)};case"text":return{...t,fontSize:Math.min(512,Math.max(8,t.fontSize*n))};default:return t}}function U(t,e){return{...t,rotation:b(e)}}function V(t,e,n){switch(t.type){case"pen":{const r=t.points.map((t,r)=>r%2==0?t+e:t+n);return{...t,points:r}}case"line":case"arrow":return{...t,x1:t.x1+e,y1:t.y1+n,x2:t.x2+e,y2:t.y2+n};case"rect":case"ellipse":case"sticker":case"text":return{...t,x:t.x+e,y:t.y+n}}}var O=Math.PI/180;function z(t,e,n){const r=W(n);if(0===r||180===r)return{w:t,h:e};if(90===r||270===r)return{w:e,h:t};const a=r*O;return{w:Math.round(Math.abs(t*Math.cos(a))+Math.abs(e*Math.sin(a))),h:Math.round(Math.abs(t*Math.sin(a))+Math.abs(e*Math.cos(a)))}}function W(t){return(t%360+360)%360}function f(t){const e=Math.round(t);return e-e%2}function L(t,e){let n=t.w,r=n/e;return r>t.h&&(r=t.h,n=r*e),{x:Math.round((t.w-n)/2),y:Math.round((t.h-r)/2),width:Math.round(n),height:Math.round(r)}}function j(t,e,n){const r={x:0,y:0,width:t.width,height:t.height},a={x:0,y:0,width:e.w,height:e.h};return"cover"===n?{src:L({w:t.width,h:t.height},e.w/e.h),dst:a}:"contain"===n?{src:r,dst:L({w:e.w,h:e.h},t.width/t.height)}:{src:r,dst:a}}function B(t,e){if(e.scale)return{w:f(e.scale.width),h:f(e.scale.height)};if(e.crop)return{w:f(e.crop.width),h:f(e.crop.height)};const n=z(t.w,t.h,e.rotation);return{w:f(n.w),h:f(n.h)}}function q(t){const e=String(t??"").match(/^data:(image\/(?:png|jpe?g));base64,([a-z0-9+/=]+)$/i);if(!e)return null;const n=atob(e[2]),r=new Uint8Array(n.length);for(let t=0;t<n.length;t++)r[t]=n.charCodeAt(t);return new Blob([r],{type:e[1].toLowerCase()})}async function H(t,e,n=[]){const r=t.getExportPlan(),a=new FormData;r.videoSrcOrder.forEach((t,n)=>{const r=e[t];r&&a.append(`video_${n}`,r,r.name||`video_${n}.mp4`)}),r.audioSrcOrder.forEach((t,e)=>{const r=n[t];r&&a.append(`audio_${e}`,r,r.name||`audio_${e}`)});const o=B(r.state.canvas,r.state),s=await F(r.state.overlays,o.w,o.h);s&&a.append("overlay",s,"overlay.png");const i=r.state.poster?.useAsVideoCover?q(r.state.poster.preview):null;i&&a.append("videoCover",i,"video-cover.png");const c=r.state.poster?.preview?{...r.state,poster:{...r.state.poster,preview:void 0}}:r.state;return a.append("editState",JSON.stringify(c)),a}var Y=[{id:"bw",label:"黑白",vf:"hue=s=0",css:"grayscale(1)"},{id:"sepia",label:"复古",vf:"colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131",css:"sepia(0.85)"},{id:"warm",label:"暖阳",vf:"colorbalance=rs=.15:gs=.04:bs=-.15",css:"sepia(0.25) saturate(1.25) brightness(1.03)"},{id:"cool",label:"冷调",vf:"colorbalance=rs=-.14:bs=.16",css:"hue-rotate(12deg) saturate(0.95) brightness(1.02)"},{id:"vivid",label:"鲜艳",vf:"eq=saturation=1.45:contrast=1.08",css:"saturate(1.45) contrast(1.08)"}];function X(t){return t?Y.find(e=>e.id===t):void 0}function G(t,e){const n=X(e)?.css??"";return[`brightness(${1+t.brightness})`,`contrast(${1+t.contrast})`,`saturate(${1+t.saturation})`,n].filter(Boolean).join(" ")}function K(t,e,n,r,a,o=1,s,i=!0){const c=B(r,a);t.width=Math.max(2,Math.round(c.w*o)),t.height=Math.max(2,Math.round(c.h*o));const h=t.getContext("2d");if(!h)return;const l=z(r.w,r.h,a.rotation),u=a.crop??{x:0,y:0,width:l.w,height:l.h},d=a.scale?.fit??"force",{src:x,dst:f}=j({width:u.width,height:u.height},c,d);"contain"===d&&(h.fillStyle="#000",h.fillRect(0,0,t.width,t.height)),h.filter=G(a.filters,a.filterPreset),h.save(),"contain"===d&&(h.beginPath(),h.rect(o*f.x,o*f.y,o*f.width,o*f.height),h.clip()),h.translate(o*f.x,o*f.y),h.scale(o*f.width/x.width,o*f.height/x.height),h.translate(-(u.x+x.x),-(u.y+x.y)),h.translate(l.w/2,l.h/2),h.rotate(a.rotation*O),h.scale(a.flipX?-1:1,a.flipY?-1:1);const p=j({width:n.w,height:n.h},{w:r.w,h:r.h},"cover");h.drawImage(e,p.src.x,p.src.y,p.src.width,p.src.height,-r.w/2,-r.h/2,r.w,r.h),h.restore(),h.filter="none",i&&a.overlays?.length&&(h.setTransform(o,0,0,o,0,0),M(h,a.overlays,s),h.setTransform(1,0,0,1,0,0))}function Q(t,e){return new Promise(n=>{const r=()=>{t.removeEventListener("seeked",r),n()};t.addEventListener("seeked",r),t.currentTime=Math.min(Math.max(0,e),t.duration||e)})}async function Z(t,e,n=160){const r=t.duration;if(!r||!isFinite(r)||e<=0)return[];const a=t.videoWidth||16,o=t.videoHeight||9,s=Math.min(n,a),i=Math.max(1,Math.round(s*o/a)),c=document.createElement("canvas");c.width=s,c.height=i;const h=c.getContext("2d");if(!h)return[];const l=[];for(let n=0;n<e;n++)await Q(t,r*(n+.5)/e),h.drawImage(t,0,0,s,i),l.push(c.toDataURL("image/jpeg",.6));return l}function tt(t,e={}){const n=e.mode??"overlay",r=document.createElement("button");r.type="button",r.className=["me-fullscreen-toggle",e.className].filter(Boolean).join(" "),r.dataset.meFullscreenToggle="true",r.dataset.mode=n,r.title="全屏 / 退出全屏",r.style.cssText=["overlay"===n?"position:absolute;left:8px;bottom:8px;z-index:30;":"position:static;","width:32px;height:32px;padding:0;","display:inline-flex;align-items:center;justify-content:center;","border:1px solid var(--me-border,#26262b);border-radius:6px;","background:var(--me-chip,#1c1c20);color:var(--me-fg,#e7e7ee);","cursor:pointer;font-size:15px;line-height:1;opacity:0.9;font:inherit;"].join(""),t.classList.add("me-fullscreen-host");const a=()=>{const e=document.fullscreenElement===t;r.textContent=e?"×":"⛶",r.setAttribute("aria-label",e?"退出全屏":"全屏"),t.classList.toggle("me-is-fullscreen",e),t.dataset.meFullscreen=e?"true":"false"};a();const o=()=>a(),s=()=>{(document.fullscreenElement===t?document.exitFullscreen?.():t.requestFullscreen?.())?.catch?.(()=>{})};return r.addEventListener("click",s),document.addEventListener("fullscreenchange",o),{button:r,dispose:()=>{document.removeEventListener("fullscreenchange",o),r.removeEventListener("click",s),r.remove(),t.classList.remove("me-fullscreen-host","me-is-fullscreen"),delete t.dataset.meFullscreen}}}exports.buildVideoExportFormData=H,exports.createFullscreenToggle=tt,exports.drawOverlay=P,exports.drawOverlays=M,exports.drawVideoFrame=K,exports.fitStickerBox=_,exports.generateThumbnails=Z,exports.getOverlayRotation=m,exports.hitTestOverlay=D,exports.loadOverlayImages=E,exports.overlayBBox=k,exports.renderOverlaysToPng=F,exports.rotateOverlay=U,exports.scaleOverlay=J,exports.translateOverlay=V;
|
package/core/dist/browser.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
import{outputSize as q,rotatedSize as St,fitRects as at,buildFilterCss as it,DEG2RAD as Ft,findFilterPreset as Tt}from"./chunk-USY6UDGL.js";var ot=Math.PI/180;function R(t,e,r){t.strokeStyle=e,t.lineWidth=r,t.lineCap="round",t.lineJoin="round"}function Nt(t,e,r,n,a,i){const s=Math.atan2(a-r,n-e),c=Math.max(12,i*3.5);t.beginPath(),t.moveTo(n,a),t.lineTo(n-c*Math.cos(s-Math.PI/7),a-c*Math.sin(s-Math.PI/7)),t.moveTo(n,a),t.lineTo(n-c*Math.cos(s+Math.PI/7),a-c*Math.sin(s+Math.PI/7)),t.stroke()}function st(t){if(!Number.isFinite(t))return 0;let e=t%360;return e>180&&(e-=360),e<-180&&(e+=360),Math.abs(e)<.001?0:e}var kt=.84;function Ct(t){const e=Math.max(8,Number(t?.w)||0),r=Math.max(8,Number(t?.h)||0),n=Math.max(8,Math.min(e,r)*kt);return{x:(Number(t?.x)||0)+(e-n)/2,y:(Number(t?.y)||0)+(r-n)/2,size:n}}var J=null;function Pt(){return typeof document>"u"?null:(J??(J=document.createElement("canvas")),J.getContext("2d"))}function ct(t){return Math.min(512,Math.max(8,Number(t.fontSize)||24))}function At(t,e){return Number.isFinite(t.paddingX)?Math.max(0,t.paddingX):Math.max(8,Math.round(e*.18))}function Et(t,e){return Number.isFinite(t.paddingY)?Math.max(0,t.paddingY):Math.max(6,Math.round(e*.14))}function It(t,e){return(Number.isFinite(t.lineHeight)?Math.max(.9,t.lineHeight):1.1)*e}function Wt(t){return t.textAlign==="center"||t.textAlign==="right"?t.textAlign:"left"}function Ot(t){const e=ct(t),r=t.fontStyle||"normal",n=t.fontWeight||"700",a=t.fontFamily||'-apple-system, "PingFang SC", "Microsoft YaHei", sans-serif';return`${r} ${n} ${e}px ${a}`}function zt(t,e){const r=t==null?"":String(t);switch(e){case"uppercase":return r.toUpperCase();case"lowercase":return r.toLowerCase();case"capitalize":return r.toLowerCase().replace(/(^|\s)(\S)/g,(n,a,i)=>`${a}${i.toUpperCase()}`);default:return r}}function $t(t,e){const r=zt(t,e).replace(/\r\n/g,`
|
|
2
|
-
`).split(`
|
|
3
|
-
`);return r.length?r:[""]}function X(t){return Number.isFinite(t)&&t>=0}function Lt(t){if(!V(t))return null;const e=X(t.startAt)?Number(t.startAt):null,r=X(t.endAt)?Number(t.endAt):null;if(e==null&&r==null)return null;const n=Math.max(0,e??0),a=Math.max(n,r??n);return{start:n,end:a}}function lt(t){const e=Lt(t);return!!e&&e.end>e.start}function V(t){return t?.type==="pen"||t?.type==="line"||t?.type==="arrow"||t?.type==="rect"||t?.type==="ellipse"||t?.type==="text"||t?.type==="sticker"}function jt(t){if(!V(t)&&t?.type!=="filter"&&t?.type!=="adjust")return null;const e=X(t.startAt)?Number(t.startAt):null,r=X(t.endAt)?Number(t.endAt):null;if(e==null&&r==null)return null;const n=Math.max(0,e??0),a=Math.max(n,r??n);return{start:n,end:a}}function Xt(t,e){const r=jt(t);return r?Number.isFinite(e)?e>=r.start&&e<=r.end:!1:!0}function Yt(t,e){return t?.length?Number.isFinite(e)?t.filter(r=>Xt(r,e)):t:[]}function ht(t){return t?.type==="text"||t?.type==="sticker"||t?.type==="filter"||t?.type==="adjust"}function ut(t){return Number.isFinite(t?.timelineTrack)?Math.max(0,Math.round(Number(t.timelineTrack))):0}function dt(t){return X(t?.startAt)?Number(t.startAt):0}function G(t){const e=ct(t),r=At(t,e),n=Et(t,e),a=It(t,e),i=$t(t.text,t.textTransform),s=Pt(),c=Ot(t);s&&(s.font=c);const m=i.map(b=>{const g=b===""?" ":b;return s?s.measureText(g).width:Math.max(1,g.length)*e*.6}),o=m.length?Math.max(...m):e*.6,y=Math.max(e,i.length*a),w=Math.max(Number.isFinite(t.width)?t.width:0,o+r*2),f=y+n*2;return{font:c,fontSize:e,paddingX:r,paddingY:n,lineHeight:a,lines:i,widths:m,boxWidth:w,boxHeight:f,align:Wt(t)}}function Dt(t,e,r){return e.align==="center"?t.x+e.boxWidth/2-r/2:e.align==="right"?t.x+e.boxWidth-e.paddingX-r:t.x+e.paddingX}function Ht(t,e,r,n,a,i){if(!e.textDecoration||i<=0)return;const s=r.fontSize,c=String(e.textDecoration).includes("underline"),m=String(e.textDecoration).includes("line-through");if(!(!c&&!m)){if(t.save(),t.strokeStyle=e.color||"#fff",t.lineWidth=Math.max(1,s/18),c){const o=a+s+Math.max(1,s*.08);t.beginPath(),t.moveTo(n,o),t.lineTo(n+i,o),t.stroke()}if(m){const o=a+s*.56;t.beginPath(),t.moveTo(n,o),t.lineTo(n+i,o),t.stroke()}t.restore()}}function K(t){return st(t.rotation??0)}function mt(t){switch(t.type){case"pen":{let e=1/0,r=1/0,n=-1/0,a=-1/0;for(let i=0;i<t.points.length;i+=2)e=Math.min(e,t.points[i]),n=Math.max(n,t.points[i]),r=Math.min(r,t.points[i+1]),a=Math.max(a,t.points[i+1]);return{x:e,y:r,w:n-e,h:a-r}}case"line":case"arrow":return{x:Math.min(t.x1,t.x2),y:Math.min(t.y1,t.y2),w:Math.abs(t.x2-t.x1),h:Math.abs(t.y2-t.y1)};case"rect":case"ellipse":case"sticker":return{x:t.x,y:t.y,w:t.w,h:t.h};case"text":{const e=G(t);return{x:t.x,y:t.y,w:e.boxWidth,h:e.boxHeight}}}}function Q(t){const e=mt(t);return{x:e.x+e.w/2,y:e.y+e.h/2}}function Rt(t,e,r,n,a){const i=a*ot,s=Math.cos(i),c=Math.sin(i),m=t-r,o=e-n;return{x:r+m*s-o*c,y:n+m*c+o*s}}function ft(t,e,r,n,a){return{x:r+(t-r)*a,y:n+(e-n)*a}}function Z(t,e,r){const n=K(e);if(n){const a=Q(e);t.save(),t.translate(a.x,a.y),t.rotate(n*ot),t.translate(-a.x,-a.y),xt(t,e,r),t.restore();return}xt(t,e,r)}function xt(t,e,r){switch(e.type){case"pen":{R(t,e.color,e.width),t.beginPath(),t.moveTo(e.points[0],e.points[1]);for(let n=2;n<e.points.length;n+=2)t.lineTo(e.points[n],e.points[n+1]);t.stroke();break}case"line":case"arrow":{R(t,e.color,e.width),t.beginPath(),t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.stroke(),e.type==="arrow"&&Nt(t,e.x1,e.y1,e.x2,e.y2,e.width);break}case"rect":{R(t,e.color,e.width),t.strokeRect(e.x,e.y,e.w,e.h);break}case"ellipse":{R(t,e.color,e.width),t.beginPath(),t.ellipse(e.x+e.w/2,e.y+e.h/2,Math.abs(e.w/2),Math.abs(e.h/2),0,0,Math.PI*2),t.stroke();break}case"text":{const n=G(e),a=Number.isFinite(e.opacity)?Math.min(1,Math.max(0,e.opacity/100)):1,i=Number.isFinite(e.borderWidth)?Math.max(0,e.borderWidth):0,s=e.autoOutline!==!1;t.save(),t.globalAlpha*=a,e.backgroundColor&&e.backgroundColor!=="transparent"&&(t.fillStyle=e.backgroundColor,t.fillRect(e.x,e.y,n.boxWidth,n.boxHeight)),t.fillStyle=e.color||"#fff",t.font=n.font,t.textBaseline="top",t.lineJoin="round";const c=e.boxShadow;c&&(t.shadowColor=c.color||"transparent",t.shadowOffsetX=c.x||0,t.shadowOffsetY=c.y||0,t.shadowBlur=c.blur||0),n.lines.forEach((m,o)=>{const y=n.widths[o]??0,w=Dt(e,n,y),f=e.y+n.paddingY+o*n.lineHeight;(i>0||s)&&(t.strokeStyle=i>0?e.borderColor||"#000":e.strokeColor||"rgba(0,0,0,0.45)",t.lineWidth=i>0?i:Math.max(1,n.fontSize/18),t.strokeText(m,w,f)),t.fillText(m,w,f),Ht(t,e,n,w,f,y)}),t.restore();break}case"sticker":{if(e.emoji){const n=Ct(e);t.save(),t.font=`${n.size}px -apple-system, "Apple Color Emoji", "Segoe UI Emoji", sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(e.emoji,n.x+n.size/2,n.y+n.size/2),t.restore()}else if(e.src){const n=r?.get(e.src);n&&t.drawImage(n,e.x,e.y,e.w,e.h)}break}}}function tt(t,e,r){for(const n of e)Z(t,n,r)}async function pt(t){const e=new Map,r=[...new Set(t.filter(n=>n.type==="sticker"&&n.src).map(n=>n.src))];return await Promise.all(r.map(n=>new Promise(a=>{const i=new Image;i.onload=()=>{e.set(n,i),a()},i.onerror=()=>a(),i.src=n}))),e}async function et(t,e,r){if(!t?.length)return null;const n=document.createElement("canvas");n.width=e,n.height=r;const a=n.getContext("2d");if(!a)return null;const i=await pt(t);return tt(a,t,i),new Promise(s=>n.toBlob(c=>s(c),"image/png"))}function Bt(t,e,r,n=12){for(let a=t.length-1;a>=0;a--){const i=t[a];if(Ut(i,e,r,n))return a}return-1}function _t(t,e,r,n,a){return Math.abs(t-r)<=a&&Math.abs(e-n)<=a}function gt(t,e,r,n,a,i,s){const c=a-r,m=i-n,o=c*c+m*m||1,y=Math.max(0,Math.min(1,((t-r)*c+(e-n)*m)/o)),w=r+y*c,f=n+y*m;return(t-w)**2+(e-f)**2<=s*s}function Ut(t,e,r,n){const a=K(t);if(a){const i=Q(t),s=Rt(e,r,i.x,i.y,-a);return yt(t,s.x,s.y,n)}return yt(t,e,r,n)}function yt(t,e,r,n){switch(t.type){case"pen":{for(let a=0;a+3<t.points.length;a+=2)if(gt(e,r,t.points[a],t.points[a+1],t.points[a+2],t.points[a+3],n+t.width/2))return!0;return!1}case"line":case"arrow":return gt(e,r,t.x1,t.y1,t.x2,t.y2,n+t.width/2);case"rect":case"ellipse":return e>=t.x-n&&e<=t.x+t.w+n&&r>=t.y-n&&r<=t.y+t.h+n;case"text":{const a=G(t);return e>=t.x-n&&e<=t.x+a.boxWidth+n&&r>=t.y-n&&r<=t.y+a.boxHeight+n}case"sticker":return _t(e,r,t.x+t.w/2,t.y+t.h/2,Math.max(t.w,t.h)/2+n)}}function qt(t,e,r){const n=Math.max(8,r);if(!(t>0)||!(e>0))return{w:n,h:n};const a=n/Math.max(t,e);return{w:Math.max(8,Math.round(t*a)),h:Math.max(8,Math.round(e*a))}}function Jt(t,e){const r=Math.max(.05,e),n=Q(t);switch(t.type){case"pen":return{...t,points:t.points.map((a,i)=>i%2===0?n.x+(a-n.x)*r:n.y+(a-n.y)*r)};case"line":case"arrow":{const a=ft(t.x1,t.y1,n.x,n.y,r),i=ft(t.x2,t.y2,n.x,n.y,r);return{...t,x1:a.x,y1:a.y,x2:i.x,y2:i.y}}case"rect":case"ellipse":case"sticker":return{...t,w:Math.max(8,t.w*r),h:Math.max(8,t.h*r)};case"text":return{...t,fontSize:Math.min(512,Math.max(8,t.fontSize*r)),width:Number.isFinite(t.width)?Math.max(80,t.width*r):t.width,paddingX:Number.isFinite(t.paddingX)?Math.max(0,t.paddingX*r):t.paddingX,paddingY:Number.isFinite(t.paddingY)?Math.max(0,t.paddingY*r):t.paddingY,borderWidth:Number.isFinite(t.borderWidth)?Math.max(0,t.borderWidth*r):t.borderWidth,boxShadow:t.boxShadow?{...t.boxShadow,x:(t.boxShadow.x||0)*r,y:(t.boxShadow.y||0)*r,blur:(t.boxShadow.blur||0)*r}:t.boxShadow};default:return t}}function Vt(t,e){return{...t,rotation:st(e)}}function Gt(t,e,r){switch(t.type){case"pen":{const n=t.points.map((a,i)=>i%2===0?a+e:a+r);return{...t,points:n}}case"line":case"arrow":return{...t,x1:t.x1+e,y1:t.y1+r,x2:t.x2+e,y2:t.y2+r};case"rect":case"ellipse":case"sticker":return{...t,x:t.x+e,y:t.y+r};case"text":return{...t,x:t.x+e,y:t.y+r}}}function L(t,e){const r=Math.min(8192,Math.max(2,Math.round(Number(t)||e)));return r%2===0?r:r-1}function ce(t){const e=q(t.canvas,t),r=t?.exportSettings??null;if(!r)return e;const n=Number.isFinite(Number(r.width))&&Number(r.width)>0,a=Number.isFinite(Number(r.height))&&Number(r.height)>0;if(!n&&!a)return e;const i=e.w>0&&e.h>0?e.w/e.h:1;if(n&&a)return{w:L(r.width,e.w),h:L(r.height,e.h)};if(n){const c=L(r.width,e.w);return{w:c,h:L(c/i,e.h)}}const s=L(r.height,e.h);return{w:L(s*i,e.w),h:s}}function Kt(t){const e=String(t??"").match(/^data:(image\/(?:png|jpe?g));base64,([a-z0-9+/=]+)$/i);if(!e)return null;const r=atob(e[2]),n=new Uint8Array(r.length);for(let a=0;a<r.length;a++)n[a]=r.charCodeAt(a);return new Blob([n],{type:e[1].toLowerCase()})}async function Qt(t,e,r=[]){const n=t.getExportPlan(),a=new FormData;n.videoSrcOrder.forEach((f,b)=>{const g=e[f];g&&a.append(`video_${b}`,g,g.name||`video_${b}.mp4`)}),n.audioSrcOrder.forEach((f,b)=>{const g=r[f];g&&a.append(`audio_${b}`,g,g.name||`audio_${b}`)});const i=q(n.state.canvas,n.state),s=n.state.overlays??[],c=s.filter(f=>lt(f)),m=s.filter(f=>!lt(f)&&V(f)),o=await et(m,i.w,i.h);o&&a.append("overlay",o,"overlay.png");for(let f=0;f<c.length;f++){const b=await et([c[f]],i.w,i.h);b&&a.append(`textOverlay_${f}`,b,`text-overlay-${f}.png`)}const y=n.state.poster?.useAsVideoCover?Kt(n.state.poster.preview):null;y&&a.append("videoCover",y,"video-cover.png");const w=n.state.poster?.preview?{...n.state,poster:{...n.state.poster,preview:void 0}}:n.state;return a.append("editState",JSON.stringify(w)),a}function N(t){return Math.max(-1,Math.min(1,Number(t)||0))}function j(t){return Math.max(0,Math.min(1,Number(t)||0))}function S(t){return Math.max(0,Math.min(1,t))}function P(t){return Math.max(0,Math.min(255,t))}function W(t,e,r){if(t===e)return r<t?0:1;const n=Math.max(0,Math.min(1,(r-t)/(e-t)));return n*n*(3-2*n)}function nt(t){const e=W(.08,.4,t),r=1-W(.6,.92,t);return S(e*r*2.2)}function wt(t,e,r=0){const n=Math.sin(t*12.9898+e*78.233+r*37.719)*43758.5453;return n-Math.floor(n)}var O=null;function Zt(t,e){return typeof document>"u"?null:(O??(O=document.createElement("canvas")),O.width!==t&&(O.width=t),O.height!==e&&(O.height=e),O)}function bt(t,e,r,n){if(!n||n==="none")return;const a=Zt(e,r),i=a?.getContext("2d");!a||!i||(i.setTransform(1,0,0,1,0,0),i.clearRect(0,0,e,r),i.drawImage(t.canvas,0,0,e,r),t.save(),t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,e,r),t.filter=n,t.drawImage(a,0,0,e,r),t.restore(),t.filter="none")}function te(t,e,r,n){const a=Tt(n?.filterPreset)?.css??"";bt(t,e,r,a)}function ee(t,e,r,n){bt(t,e,r,it(n??{},"")),Mt(t,e,r,n??{})}function ne(t={}){return["temperature","tint","vibrance","gamma","highlights","shadows","whites","blacks","lightSense"].some(e=>Math.abs(N(t[e]))>1e-4)?!0:["sharpen","clarity","grain","fade","vignette"].some(e=>j(t[e])>1e-4)}function Mt(t,e,r,n={}){if(!ne(n))return;let a;try{a=t.getImageData(0,0,e,r)}catch{return}const i=N(n.temperature),s=N(n.tint),c=N(n.vibrance),m=N(n.gamma),o=N(n.highlights),y=N(n.shadows),w=N(n.whites),f=N(n.blacks),b=N(n.lightSense),g=j(n.sharpen),A=j(n.clarity),z=j(n.grain),E=j(n.fade),Y=j(n.vignette),B=1+m*(m>0?1:.5),M=m===0?1:1/Math.max(.01,B),I=i*.18,D=i*.02,H=-i*.18,rt=s*.1,vt=-s*.12,p=a.data;for(let h=0;h<p.length;h+=4){let d=p[h]/255,x=p[h+1]/255,u=p[h+2]/255;if((i!==0||s!==0)&&(d=S(d+I+rt),x=S(x+D+vt),u=S(u+H+rt)),c!==0){const l=Math.max(d,x,u),F=Math.min(d,x,u),T=l-F,v=(d+x+u)/3,k=c>0?c*(1-T):c*(.35+T*.65);d=S(v+(d-v)*(1+k)),x=S(v+(x-v)*(1+k)),u=S(v+(u-v)*(1+k))}if(m!==0&&(d=S(Math.pow(d,M)),x=S(Math.pow(x,M)),u=S(Math.pow(u,M))),o!==0||y!==0||w!==0||f!==0||b!==0||E!==0){const l=.2126*d+.7152*x+.0722*u,F=1-W(.18,.62,l),T=1-W(.04,.32,l),v=W(.38,.84,l),k=W(.7,.98,l),C=nt(l),_=y*F*.28+o*v*.24+f*T*.2+w*k*.2+b*C*.18+E*(.12+F*.06);if(d=S(d+_),x=S(x+_),u=S(u+_),E>0){const U=(d+x+u)/3,$=E*.16;d=S(d*(1-$)+U*$),x=S(x*(1-$)+U*$),u=S(u*(1-$)+U*$)}}p[h]=Math.round(d*255),p[h+1]=Math.round(x*255),p[h+2]=Math.round(u*255)}if(g>1e-4||A>1e-4){const h=new Uint8ClampedArray(p),d=e*4;for(let x=1;x<r-1;x++)for(let u=1;u<e-1;u++){const l=x*d+u*4,F=(h[l-4]+h[l+4]+h[l-d]+h[l+d]+h[l]*4)/8,T=(h[l-3]+h[l+5]+h[l-d+1]+h[l+d+1]+h[l+1]*4)/8,v=(h[l-2]+h[l+6]+h[l-d+2]+h[l+d+2]+h[l+2]*4)/8,k=(.2126*h[l]+.7152*h[l+1]+.0722*h[l+2])/255,C=Math.min(1.8,g*1.45+A*.9*nt(k));p[l]=P(h[l]+(h[l]-F)*C),p[l+1]=P(h[l+1]+(h[l+1]-T)*C),p[l+2]=P(h[l+2]+(h[l+2]-v)*C)}}if(z>1e-4){const h=z*26;for(let d=0;d<r;d++)for(let x=0;x<e;x++){const u=(d*e+x)*4,l=(.2126*p[u]+.7152*p[u+1]+.0722*p[u+2])/255,F=.4+nt(l)*.9,T=(wt(x,d)-.5)*h*F,v=(wt(x,d,1)-.5)*h*.22*z;p[u]=P(p[u]+T+v),p[u+1]=P(p[u+1]+T*.88),p[u+2]=P(p[u+2]+T-v)}}if(Y>1e-4){const h=(e-1)/2,d=(r-1)/2,x=Math.sqrt(h*h+d*d)||1;for(let u=0;u<r;u++)for(let l=0;l<e;l++){const F=(u*e+l)*4,T=l-h,v=u-d,k=Math.sqrt(T*T+v*v)/x,C=1-W(.32,1,k)*Y*.62;p[F]=P(p[F]*C),p[F+1]=P(p[F+1]*C),p[F+2]=P(p[F+2]*C)}}t.putImageData(a,0,0)}function re(t,e,r,n,a,i=1,s,c=!0){const m=q(n,a);t.width=Math.max(2,Math.round(m.w*i)),t.height=Math.max(2,Math.round(m.h*i));const o=t.getContext("2d");if(!o)return;const y=St(n.w,n.h,a.rotation),w=a.crop??{x:0,y:0,width:y.w,height:y.h},f=a.scale?.fit??"force",{src:b,dst:g}=at({width:w.width,height:w.height},m,f);f==="contain"&&(o.fillStyle="#000",o.fillRect(0,0,t.width,t.height)),o.filter=it(a.filters,a.filterPreset),o.save(),f==="contain"&&(o.beginPath(),o.rect(i*g.x,i*g.y,i*g.width,i*g.height),o.clip()),o.translate(i*g.x,i*g.y),o.scale(i*g.width/b.width,i*g.height/b.height),o.translate(-(w.x+b.x),-(w.y+b.y)),o.translate(y.w/2,y.h/2),o.rotate(a.rotation*Ft),o.scale(a.flipX?-1:1,a.flipY?-1:1);const A=at({width:r.w,height:r.h},{w:n.w,h:n.h},"cover");if(o.drawImage(e,A.src.x,A.src.y,A.src.width,A.src.height,-n.w/2,-n.h/2,n.w,n.h),o.restore(),o.filter="none",Mt(o,t.width,t.height,a.filters),c&&a.overlays?.length){const z=Number.isFinite(a?.__mePreviewTimelineTime)?Number(a.__mePreviewTimelineTime):null,E=z==null?a.overlays:Yt(a.overlays,z),Y=E.map((M,I)=>({overlay:M,index:I})).filter(M=>ht(M.overlay)).sort((M,I)=>{const D=ut(I.overlay)-ut(M.overlay);if(D!==0)return D;const H=dt(M.overlay)-dt(I.overlay);return Math.abs(H)>1e-6?H:M.index-I.index}),B=E.filter(M=>!ht(M));o.setTransform(i,0,0,i,0,0),Y.forEach(M=>{if(M.overlay?.type==="filter"){o.setTransform(1,0,0,1,0,0),te(o,t.width,t.height,M.overlay),o.setTransform(i,0,0,i,0,0);return}if(M.overlay?.type==="adjust"){o.setTransform(1,0,0,1,0,0),ee(o,t.width,t.height,M.overlay),o.setTransform(i,0,0,i,0,0);return}Z(o,M.overlay,s)}),tt(o,B,s),o.setTransform(1,0,0,1,0,0)}}function ae(t,e){return new Promise(r=>{const n=()=>{t.removeEventListener("seeked",n),r()};t.addEventListener("seeked",n),t.currentTime=Math.min(Math.max(0,e),t.duration||e)})}async function ie(t,e,r=160){const n=t.duration;if(!n||!isFinite(n)||e<=0)return[];const a=t.videoWidth||16,i=t.videoHeight||9,s=Math.min(r,a),c=Math.max(1,Math.round(s*i/a)),m=document.createElement("canvas");m.width=s,m.height=c;const o=m.getContext("2d");if(!o)return[];const y=[];for(let w=0;w<e;w++)await ae(t,n*(w+.5)/e),o.drawImage(t,0,0,s,c),y.push(m.toDataURL("image/jpeg",.6));return y}function oe(t,e={}){const r=e.mode??"overlay",n=document.createElement("button");n.type="button",n.className=["me-fullscreen-toggle",e.className].filter(Boolean).join(" "),n.dataset.meFullscreenToggle="true",n.dataset.mode=r,n.title="\u5168\u5C4F / \u9000\u51FA\u5168\u5C4F",n.style.cssText=[r==="overlay"?"position:absolute;left:8px;bottom:8px;z-index:30;":"position:static;","width:32px;height:32px;padding:0;","display:inline-flex;align-items:center;justify-content:center;","border:1px solid var(--me-border,#26262b);border-radius:6px;","background:var(--me-chip,#1c1c20);color:var(--me-fg,#e7e7ee);","cursor:pointer;font-size:15px;line-height:1;opacity:0.9;font:inherit;"].join(""),t.classList.add("me-fullscreen-host");const a=()=>{const c=document.fullscreenElement===t;n.textContent=c?"\xD7":"\u26F6",n.setAttribute("aria-label",c?"\u9000\u51FA\u5168\u5C4F":"\u5168\u5C4F"),t.classList.toggle("me-is-fullscreen",c),t.dataset.meFullscreen=c?"true":"false"};a();const i=()=>a(),s=()=>{(document.fullscreenElement===t?document.exitFullscreen?.():t.requestFullscreen?.())?.catch?.(()=>{})};return n.addEventListener("click",s),document.addEventListener("fullscreenchange",i),{button:n,dispose:()=>{document.removeEventListener("fullscreenchange",i),n.removeEventListener("click",s),n.remove(),t.classList.remove("me-fullscreen-host","me-is-fullscreen"),delete t.dataset.meFullscreen}}}export{Qt as buildVideoExportFormData,oe as createFullscreenToggle,Z as drawOverlay,tt as drawOverlays,re as drawVideoFrame,qt as fitStickerBox,ie as generateThumbnails,K as getOverlayRotation,Bt as hitTestOverlay,pt as loadOverlayImages,mt as overlayBBox,et as renderOverlaysToPng,Vt as rotateOverlay,Jt as scaleOverlay,Gt as translateOverlay};
|
|
1
|
+
import{outputSize as t,rotatedSize as e,fitRects as n,buildFilterCss as r,DEG2RAD as a,findFilterPreset as i}from"./chunk-USY6UDGL.js";var o=Math.PI/180;function s(t,e,n){t.strokeStyle=e,t.lineWidth=n,t.lineCap="round",t.lineJoin="round"}function c(t){if(!Number.isFinite(t))return 0;let e=t%360;return e>180&&(e-=360),e<-180&&(e+=360),Math.abs(e)<.001?0:e}var l=null;function h(t){return Math.min(512,Math.max(8,Number(t.fontSize)||24))}function u(t){return"center"===t.textAlign||"right"===t.textAlign?t.textAlign:"left"}function d(t){return Number.isFinite(t)&&t>=0}function m(t){const e=function(t){if(!f(t))return null;const e=d(t.startAt)?Number(t.startAt):null,n=d(t.endAt)?Number(t.endAt):null;if(null==e&&null==n)return null;const r=Math.max(0,e??0);return{start:r,end:Math.max(r,n??r)}}(t);return!!e&&e.end>e.start}function f(t){return"pen"===t?.type||"line"===t?.type||"arrow"===t?.type||"rect"===t?.type||"ellipse"===t?.type||"text"===t?.type||"sticker"===t?.type}function x(t){return"text"===t?.type||"sticker"===t?.type||"filter"===t?.type||"adjust"===t?.type}function p(t){return Number.isFinite(t?.timelineTrack)?Math.max(0,Math.round(Number(t.timelineTrack))):0}function g(t){return d(t?.startAt)?Number(t.startAt):0}function y(t){const e=h(t),n=function(t,e){return Number.isFinite(t.paddingX)?Math.max(0,t.paddingX):Math.max(8,Math.round(.18*e))}(t,e),r=function(t,e){return Number.isFinite(t.paddingY)?Math.max(0,t.paddingY):Math.max(6,Math.round(.14*e))}(t,e),a=function(t,e){return(Number.isFinite(t.lineHeight)?Math.max(.9,t.lineHeight):1.1)*e}(t,e),i=function(t,e){const n=function(t,e){const n=null==t?"":String(t);switch(e){case"uppercase":return n.toUpperCase();case"lowercase":return n.toLowerCase();case"capitalize":return n.toLowerCase().replace(/(^|\s)(\S)/g,(t,e,n)=>`${e}${n.toUpperCase()}`);default:return n}}(t,e).replace(/\r\n/g,"\n").split("\n");return n.length?n:[""]}(t.text,t.textTransform),o=typeof document>"u"?null:(l??(l=document.createElement("canvas")),l.getContext("2d")),s=function(t){const e=h(t);return`${t.fontStyle||"normal"} ${t.fontWeight||"700"} ${e}px ${t.fontFamily||'-apple-system, "PingFang SC", "Microsoft YaHei", sans-serif'}`}(t);o&&(o.font=s);const c=i.map(t=>{const n=""===t?" ":t;return o?o.measureText(n).width:Math.max(1,n.length)*e*.6}),d=c.length?Math.max(...c):.6*e,m=Math.max(e,i.length*a),f=Math.max(Number.isFinite(t.width)?t.width:0,d+2*n);return{font:s,fontSize:e,paddingX:n,paddingY:r,lineHeight:a,lines:i,widths:c,boxWidth:f,boxHeight:m+2*r,align:u(t)}}function w(t){return c(t.rotation??0)}function M(t){switch(t.type){case"pen":{let e=1/0,n=1/0,r=-1/0,a=-1/0;for(let i=0;i<t.points.length;i+=2)e=Math.min(e,t.points[i]),r=Math.max(r,t.points[i]),n=Math.min(n,t.points[i+1]),a=Math.max(a,t.points[i+1]);return{x:e,y:n,w:r-e,h:a-n}}case"line":case"arrow":return{x:Math.min(t.x1,t.x2),y:Math.min(t.y1,t.y2),w:Math.abs(t.x2-t.x1),h:Math.abs(t.y2-t.y1)};case"rect":case"ellipse":case"sticker":return{x:t.x,y:t.y,w:t.w,h:t.h};case"text":{const e=y(t);return{x:t.x,y:t.y,w:e.boxWidth,h:e.boxHeight}}}}function b(t){const e=M(t);return{x:e.x+e.w/2,y:e.y+e.h/2}}function v(t,e,n,r,a){return{x:n+(t-n)*a,y:r+(e-r)*a}}function k(t,e,n){const r=w(e);if(r){const a=b(e);return t.save(),t.translate(a.x,a.y),t.rotate(r*o),t.translate(-a.x,-a.y),S(t,e,n),void t.restore()}S(t,e,n)}function S(t,e,n){switch(e.type){case"pen":s(t,e.color,e.width),t.beginPath(),t.moveTo(e.points[0],e.points[1]);for(let n=2;n<e.points.length;n+=2)t.lineTo(e.points[n],e.points[n+1]);t.stroke();break;case"line":case"arrow":s(t,e.color,e.width),t.beginPath(),t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.stroke(),"arrow"===e.type&&function(t,e,n,r,a,i){const o=Math.atan2(a-n,r-e),s=Math.max(12,3.5*i);t.beginPath(),t.moveTo(r,a),t.lineTo(r-s*Math.cos(o-Math.PI/7),a-s*Math.sin(o-Math.PI/7)),t.moveTo(r,a),t.lineTo(r-s*Math.cos(o+Math.PI/7),a-s*Math.sin(o+Math.PI/7)),t.stroke()}(t,e.x1,e.y1,e.x2,e.y2,e.width);break;case"rect":s(t,e.color,e.width),t.strokeRect(e.x,e.y,e.w,e.h);break;case"ellipse":s(t,e.color,e.width),t.beginPath(),t.ellipse(e.x+e.w/2,e.y+e.h/2,Math.abs(e.w/2),Math.abs(e.h/2),0,0,2*Math.PI),t.stroke();break;case"text":{const n=y(e),r=Number.isFinite(e.opacity)?Math.min(1,Math.max(0,e.opacity/100)):1,a=Number.isFinite(e.borderWidth)?Math.max(0,e.borderWidth):0,i=!1!==e.autoOutline;t.save(),t.globalAlpha*=r,e.backgroundColor&&"transparent"!==e.backgroundColor&&(t.fillStyle=e.backgroundColor,t.fillRect(e.x,e.y,n.boxWidth,n.boxHeight)),t.fillStyle=e.color||"#fff",t.font=n.font,t.textBaseline="top",t.lineJoin="round";const o=e.boxShadow;o&&(t.shadowColor=o.color||"transparent",t.shadowOffsetX=o.x||0,t.shadowOffsetY=o.y||0,t.shadowBlur=o.blur||0),n.lines.forEach((r,o)=>{const s=n.widths[o]??0,c=function(t,e,n){return"center"===e.align?t.x+e.boxWidth/2-n/2:"right"===e.align?t.x+e.boxWidth-e.paddingX-n:t.x+e.paddingX}(e,n,s),l=e.y+n.paddingY+o*n.lineHeight;(a>0||i)&&(t.strokeStyle=a>0?e.borderColor||"#000":e.strokeColor||"rgba(0,0,0,0.45)",t.lineWidth=a>0?a:Math.max(1,n.fontSize/18),t.strokeText(r,c,l)),t.fillText(r,c,l),function(t,e,n,r,a,i){if(!e.textDecoration||i<=0)return;const o=n.fontSize,s=String(e.textDecoration).includes("underline"),c=String(e.textDecoration).includes("line-through");if(s||c){if(t.save(),t.strokeStyle=e.color||"#fff",t.lineWidth=Math.max(1,o/18),s){const e=a+o+Math.max(1,.08*o);t.beginPath(),t.moveTo(r,e),t.lineTo(r+i,e),t.stroke()}if(c){const e=a+.56*o;t.beginPath(),t.moveTo(r,e),t.lineTo(r+i,e),t.stroke()}t.restore()}}(t,e,n,c,l,s)}),t.restore();break}case"sticker":if(e.emoji){const n=function(t){const e=Math.max(8,Number(t?.w)||0),n=Math.max(8,Number(t?.h)||0),r=Math.max(8,.84*Math.min(e,n));return{x:(Number(t?.x)||0)+(e-r)/2,y:(Number(t?.y)||0)+(n-r)/2,size:r}}(e);t.save(),t.font=`${n.size}px -apple-system, "Apple Color Emoji", "Segoe UI Emoji", sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(e.emoji,n.x+n.size/2,n.y+n.size/2),t.restore()}else if(e.src){const r=n?.get(e.src);r&&t.drawImage(r,e.x,e.y,e.w,e.h)}}}function T(t,e,n){for(const r of e)k(t,r,n)}async function N(t){const e=new Map,n=[...new Set(t.filter(t=>"sticker"===t.type&&t.src).map(t=>t.src))];return await Promise.all(n.map(t=>new Promise(n=>{const r=new Image;r.onload=()=>{e.set(t,r),n()},r.onerror=()=>n(),r.src=t}))),e}async function F(t,e,n){if(!t?.length)return null;const r=document.createElement("canvas");r.width=e,r.height=n;const a=r.getContext("2d");return a?(T(a,t,await N(t)),new Promise(t=>r.toBlob(e=>t(e),"image/png"))):null}function C(t,e,n,r=12){for(let a=t.length-1;a>=0;a--)if(A(t[a],e,n,r))return a;return-1}function P(t,e,n,r,a,i,o){const s=a-n,c=i-r,l=s*s+c*c||1,h=Math.max(0,Math.min(1,((t-n)*s+(e-r)*c)/l));return(t-(n+h*s))**2+(e-(r+h*c))**2<=o*o}function A(t,e,n,r){const a=w(t);if(a){const i=b(t),s=function(t,e,n,r,a){const i=a*o,s=Math.cos(i),c=Math.sin(i),l=t-n,h=e-r;return{x:n+l*s-h*c,y:r+l*c+h*s}}(e,n,i.x,i.y,-a);return E(t,s.x,s.y,r)}return E(t,e,n,r)}function E(t,e,n,r){switch(t.type){case"pen":for(let a=0;a+3<t.points.length;a+=2)if(P(e,n,t.points[a],t.points[a+1],t.points[a+2],t.points[a+3],r+t.width/2))return!0;return!1;case"line":case"arrow":return P(e,n,t.x1,t.y1,t.x2,t.y2,r+t.width/2);case"rect":case"ellipse":return e>=t.x-r&&e<=t.x+t.w+r&&n>=t.y-r&&n<=t.y+t.h+r;case"text":{const a=y(t);return e>=t.x-r&&e<=t.x+a.boxWidth+r&&n>=t.y-r&&n<=t.y+a.boxHeight+r}case"sticker":return function(t,e,n,r,a){return Math.abs(t-n)<=a&&Math.abs(e-r)<=a}(e,n,t.x+t.w/2,t.y+t.h/2,Math.max(t.w,t.h)/2+r)}}function W(t,e,n){const r=Math.max(8,n);if(!(t>0&&e>0))return{w:r,h:r};const a=r/Math.max(t,e);return{w:Math.max(8,Math.round(t*a)),h:Math.max(8,Math.round(e*a))}}function z(t,e){const n=Math.max(.05,e),r=b(t);switch(t.type){case"pen":return{...t,points:t.points.map((t,e)=>e%2==0?r.x+(t-r.x)*n:r.y+(t-r.y)*n)};case"line":case"arrow":{const e=v(t.x1,t.y1,r.x,r.y,n),a=v(t.x2,t.y2,r.x,r.y,n);return{...t,x1:e.x,y1:e.y,x2:a.x,y2:a.y}}case"rect":case"ellipse":case"sticker":return{...t,w:Math.max(8,t.w*n),h:Math.max(8,t.h*n)};case"text":return{...t,fontSize:Math.min(512,Math.max(8,t.fontSize*n)),width:Number.isFinite(t.width)?Math.max(80,t.width*n):t.width,paddingX:Number.isFinite(t.paddingX)?Math.max(0,t.paddingX*n):t.paddingX,paddingY:Number.isFinite(t.paddingY)?Math.max(0,t.paddingY*n):t.paddingY,borderWidth:Number.isFinite(t.borderWidth)?Math.max(0,t.borderWidth*n):t.borderWidth,boxShadow:t.boxShadow?{...t.boxShadow,x:(t.boxShadow.x||0)*n,y:(t.boxShadow.y||0)*n,blur:(t.boxShadow.blur||0)*n}:t.boxShadow};default:return t}}function I(t,e){return{...t,rotation:c(e)}}function O(t,e,n){switch(t.type){case"pen":{const r=t.points.map((t,r)=>r%2==0?t+e:t+n);return{...t,points:r}}case"line":case"arrow":return{...t,x1:t.x1+e,y1:t.y1+n,x2:t.x2+e,y2:t.y2+n};case"rect":case"ellipse":case"sticker":case"text":return{...t,x:t.x+e,y:t.y+n}}}async function L(e,n,r=[]){const a=e.getExportPlan(),i=new FormData;a.videoSrcOrder.forEach((t,e)=>{const r=n[t];r&&i.append(`video_${e}`,r,r.name||`video_${e}.mp4`)}),a.audioSrcOrder.forEach((t,e)=>{const n=r[t];n&&i.append(`audio_${e}`,n,n.name||`audio_${e}`)});const o=t(a.state.canvas,a.state),s=a.state.overlays??[],c=s.filter(t=>m(t)),l=s.filter(t=>!m(t)&&f(t)),h=await F(l,o.w,o.h);h&&i.append("overlay",h,"overlay.png");for(let t=0;t<c.length;t++){const e=await F([c[t]],o.w,o.h);e&&i.append(`textOverlay_${t}`,e,`text-overlay-${t}.png`)}const u=a.state.poster?.useAsVideoCover?function(t){const e=String(t??"").match(/^data:(image\/(?:png|jpe?g));base64,([a-z0-9+/=]+)$/i);if(!e)return null;const n=atob(e[2]),r=new Uint8Array(n.length);for(let t=0;t<n.length;t++)r[t]=n.charCodeAt(t);return new Blob([r],{type:e[1].toLowerCase()})}(a.state.poster.preview):null;u&&i.append("videoCover",u,"video-cover.png");const d=a.state.poster?.preview?{...a.state,poster:{...a.state.poster,preview:void 0}}:a.state;return i.append("editState",JSON.stringify(d)),i}function $(t){return Math.max(-1,Math.min(1,Number(t)||0))}function j(t){return Math.max(0,Math.min(1,Number(t)||0))}function Y(t){return Math.max(0,Math.min(1,t))}function D(t){return Math.max(0,Math.min(255,t))}function X(t,e,n){if(t===e)return n<t?0:1;const r=Math.max(0,Math.min(1,(n-t)/(e-t)));return r*r*(3-2*r)}function H(t){return Y(X(.08,.4,t)*(1-X(.6,.92,t))*2.2)}function B(t,e,n=0){const r=43758.5453*Math.sin(12.9898*t+78.233*e+37.719*n);return r-Math.floor(r)}var R=null;function _(t,e,n,r){if(!r||"none"===r)return;const a=function(t,e){return typeof document>"u"?null:(R??(R=document.createElement("canvas")),R.width!==t&&(R.width=t),R.height!==e&&(R.height=e),R)}(e,n),i=a?.getContext("2d");!a||!i||(i.setTransform(1,0,0,1,0,0),i.clearRect(0,0,e,n),i.drawImage(t.canvas,0,0,e,n),t.save(),t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,e,n),t.filter=r,t.drawImage(a,0,0,e,n),t.restore(),t.filter="none")}function U(t,e,n,r={}){if(!function(t={}){return!!["temperature","tint","vibrance","gamma","highlights","shadows","whites","blacks","lightSense"].some(e=>Math.abs($(t[e]))>1e-4)||["sharpen","clarity","grain","fade","vignette"].some(e=>j(t[e])>1e-4)}(r))return;let a;try{a=t.getImageData(0,0,e,n)}catch{return}const i=$(r.temperature),o=$(r.tint),s=$(r.vibrance),c=$(r.gamma),l=$(r.highlights),h=$(r.shadows),u=$(r.whites),d=$(r.blacks),m=$(r.lightSense),f=j(r.sharpen),x=j(r.clarity),p=j(r.grain),g=j(r.fade),y=j(r.vignette),w=1+c*(c>0?1:.5),M=0===c?1:1/Math.max(.01,w),b=.18*i,v=.02*i,k=.18*-i,S=.1*o,T=.12*-o,N=a.data;for(let t=0;t<N.length;t+=4){let e=N[t]/255,n=N[t+1]/255,r=N[t+2]/255;if((0!==i||0!==o)&&(e=Y(e+b+S),n=Y(n+v+T),r=Y(r+k+S)),0!==s){const t=Math.max(e,n,r)-Math.min(e,n,r),a=(e+n+r)/3,i=s>0?s*(1-t):s*(.35+.65*t);e=Y(a+(e-a)*(1+i)),n=Y(a+(n-a)*(1+i)),r=Y(a+(r-a)*(1+i))}if(0!==c&&(e=Y(Math.pow(e,M)),n=Y(Math.pow(n,M)),r=Y(Math.pow(r,M))),0!==l||0!==h||0!==u||0!==d||0!==m||0!==g){const t=.2126*e+.7152*n+.0722*r,a=1-X(.18,.62,t),i=1-X(.04,.32,t),o=h*a*.28+l*X(.38,.84,t)*.24+d*i*.2+u*X(.7,.98,t)*.2+m*H(t)*.18+g*(.12+.06*a);if(e=Y(e+o),n=Y(n+o),r=Y(r+o),g>0){const t=(e+n+r)/3,a=.16*g;e=Y(e*(1-a)+t*a),n=Y(n*(1-a)+t*a),r=Y(r*(1-a)+t*a)}}N[t]=Math.round(255*e),N[t+1]=Math.round(255*n),N[t+2]=Math.round(255*r)}if(f>1e-4||x>1e-4){const t=new Uint8ClampedArray(N),r=4*e;for(let a=1;a<n-1;a++)for(let n=1;n<e-1;n++){const e=a*r+4*n,i=(t[e-4]+t[e+4]+t[e-r]+t[e+r]+4*t[e])/8,o=(t[e-3]+t[e+5]+t[e-r+1]+t[e+r+1]+4*t[e+1])/8,s=(t[e-2]+t[e+6]+t[e-r+2]+t[e+r+2]+4*t[e+2])/8,c=(.2126*t[e]+.7152*t[e+1]+.0722*t[e+2])/255,l=Math.min(1.8,1.45*f+.9*x*H(c));N[e]=D(t[e]+(t[e]-i)*l),N[e+1]=D(t[e+1]+(t[e+1]-o)*l),N[e+2]=D(t[e+2]+(t[e+2]-s)*l)}}if(p>1e-4){const t=26*p;for(let r=0;r<n;r++)for(let n=0;n<e;n++){const a=4*(r*e+n),i=.4+.9*H((.2126*N[a]+.7152*N[a+1]+.0722*N[a+2])/255),o=(B(n,r)-.5)*t*i,s=(B(n,r,1)-.5)*t*.22*p;N[a]=D(N[a]+o+s),N[a+1]=D(N[a+1]+.88*o),N[a+2]=D(N[a+2]+o-s)}}if(y>1e-4){const t=(e-1)/2,r=(n-1)/2,a=Math.sqrt(t*t+r*r)||1;for(let i=0;i<n;i++)for(let n=0;n<e;n++){const o=4*(i*e+n),s=n-t,c=i-r,l=1-X(.32,1,Math.sqrt(s*s+c*c)/a)*y*.62;N[o]=D(N[o]*l),N[o+1]=D(N[o+1]*l),N[o+2]=D(N[o+2]*l)}}t.putImageData(a,0,0)}function q(o,s,c,l,h,u=1,m,y=!0){const w=t(l,h);o.width=Math.max(2,Math.round(w.w*u)),o.height=Math.max(2,Math.round(w.h*u));const M=o.getContext("2d");if(!M)return;const b=e(l.w,l.h,h.rotation),v=h.crop??{x:0,y:0,width:b.w,height:b.h},S=h.scale?.fit??"force",{src:N,dst:F}=n({width:v.width,height:v.height},w,S);"contain"===S&&(M.fillStyle="#000",M.fillRect(0,0,o.width,o.height)),M.filter=r(h.filters,h.filterPreset),M.save(),"contain"===S&&(M.beginPath(),M.rect(u*F.x,u*F.y,u*F.width,u*F.height),M.clip()),M.translate(u*F.x,u*F.y),M.scale(u*F.width/N.width,u*F.height/N.height),M.translate(-(v.x+N.x),-(v.y+N.y)),M.translate(b.w/2,b.h/2),M.rotate(h.rotation*a),M.scale(h.flipX?-1:1,h.flipY?-1:1);const C=n({width:c.w,height:c.h},{w:l.w,h:l.h},"cover");if(M.drawImage(s,C.src.x,C.src.y,C.src.width,C.src.height,-l.w/2,-l.h/2,l.w,l.h),M.restore(),M.filter="none",U(M,o.width,o.height,h.filters),y&&h.overlays?.length){const t=Number.isFinite(h?.__mePreviewTimelineTime)?Number(h.__mePreviewTimelineTime):null,e=null==t?h.overlays:function(t,e){return t?.length?Number.isFinite(e)?t.filter(t=>function(t,e){const n=function(t){if(!f(t)&&"filter"!==t?.type&&"adjust"!==t?.type)return null;const e=d(t.startAt)?Number(t.startAt):null,n=d(t.endAt)?Number(t.endAt):null;if(null==e&&null==n)return null;const r=Math.max(0,e??0);return{start:r,end:Math.max(r,n??r)}}(t);return!n||!!Number.isFinite(e)&&e>=n.start&&e<=n.end}(t,e)):t:[]}(h.overlays,t),n=e.map((t,e)=>({overlay:t,index:e})).filter(t=>x(t.overlay)).sort((t,e)=>{const n=p(e.overlay)-p(t.overlay);if(0!==n)return n;const r=g(t.overlay)-g(e.overlay);return Math.abs(r)>1e-6?r:t.index-e.index}),a=e.filter(t=>!x(t));M.setTransform(u,0,0,u,0,0),n.forEach(t=>"filter"===t.overlay?.type?(M.setTransform(1,0,0,1,0,0),function(t,e,n,r){_(t,e,n,i(r?.filterPreset)?.css??"")}(M,o.width,o.height,t.overlay),void M.setTransform(u,0,0,u,0,0)):"adjust"===t.overlay?.type?(M.setTransform(1,0,0,1,0,0),function(t,e,n,a){_(t,e,n,r(a??{},"")),U(t,e,n,a??{})}(M,o.width,o.height,t.overlay),void M.setTransform(u,0,0,u,0,0)):void k(M,t.overlay,m)),T(M,a,m),M.setTransform(1,0,0,1,0,0)}}function J(t,e){return new Promise(n=>{const r=()=>{t.removeEventListener("seeked",r),n()};t.addEventListener("seeked",r),t.currentTime=Math.min(Math.max(0,e),t.duration||e)})}async function V(t,e,n=160){const r=t.duration;if(!r||!isFinite(r)||e<=0)return[];const a=t.videoWidth||16,i=t.videoHeight||9,o=Math.min(n,a),s=Math.max(1,Math.round(o*i/a)),c=document.createElement("canvas");c.width=o,c.height=s;const l=c.getContext("2d");if(!l)return[];const h=[];for(let n=0;n<e;n++)await J(t,r*(n+.5)/e),l.drawImage(t,0,0,o,s),h.push(c.toDataURL("image/jpeg",.6));return h}function G(t,e={}){const n=e.mode??"overlay",r=document.createElement("button");r.type="button",r.className=["me-fullscreen-toggle",e.className].filter(Boolean).join(" "),r.dataset.meFullscreenToggle="true",r.dataset.mode=n,r.title="全屏 / 退出全屏",r.style.cssText=["overlay"===n?"position:absolute;left:8px;bottom:8px;z-index:30;":"position:static;","width:32px;height:32px;padding:0;","display:inline-flex;align-items:center;justify-content:center;","border:1px solid var(--me-border,#26262b);border-radius:6px;","background:var(--me-chip,#1c1c20);color:var(--me-fg,#e7e7ee);","cursor:pointer;font-size:15px;line-height:1;opacity:0.9;font:inherit;"].join(""),t.classList.add("me-fullscreen-host");const a=()=>{const e=document.fullscreenElement===t;r.textContent=e?"×":"⛶",r.setAttribute("aria-label",e?"退出全屏":"全屏"),t.classList.toggle("me-is-fullscreen",e),t.dataset.meFullscreen=e?"true":"false"};a();const i=()=>a(),o=()=>{(document.fullscreenElement===t?document.exitFullscreen?.():t.requestFullscreen?.())?.catch?.(()=>{})};return r.addEventListener("click",o),document.addEventListener("fullscreenchange",i),{button:r,dispose:()=>{document.removeEventListener("fullscreenchange",i),r.removeEventListener("click",o),r.remove(),t.classList.remove("me-fullscreen-host","me-is-fullscreen"),delete t.dataset.meFullscreen}}}export{L as buildVideoExportFormData,G as createFullscreenToggle,k as drawOverlay,T as drawOverlays,q as drawVideoFrame,W as fitStickerBox,V as generateThumbnails,w as getOverlayRotation,C as hitTestOverlay,N as loadOverlayImages,M as overlayBBox,F as renderOverlaysToPng,I as rotateOverlay,z as scaleOverlay,O as translateOverlay};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z as t}from"../zod/index.js";var
|
|
1
|
+
import{z as t}from"../zod/index.js";var e={color:t.string().max(32),width:t.number().positive().max(200)},n={rotation:t.number().min(-180).max(180).optional()},a={startAt:t.number().min(0).optional(),endAt:t.number().min(0).optional(),timelineTrack:t.number().int().min(0).max(99).optional()},i=t.discriminatedUnion("type",[t.object({type:t.literal("pen"),points:t.array(t.number()).min(4),...e,...a,...n}),t.object({type:t.literal("line"),x1:t.number(),y1:t.number(),x2:t.number(),y2:t.number(),...e,...a,...n}),t.object({type:t.literal("arrow"),x1:t.number(),y1:t.number(),x2:t.number(),y2:t.number(),...e,...a,...n}),t.object({type:t.literal("rect"),x:t.number(),y:t.number(),w:t.number(),h:t.number(),...e,...a,...n}),t.object({type:t.literal("ellipse"),x:t.number(),y:t.number(),w:t.number(),h:t.number(),...e,...a,...n}),t.object({type:t.literal("text"),x:t.number(),y:t.number(),text:t.string().max(500),color:t.string().max(32),fontSize:t.number().positive().max(512),startAt:t.number().min(0).optional(),endAt:t.number().min(0).optional(),timelineTrack:t.number().int().min(0).max(99).optional(),...n}),t.object({type:t.literal("sticker"),x:t.number().optional(),y:t.number().optional(),w:t.number().positive().optional(),h:t.number().positive().optional(),emoji:t.string().max(16).optional(),src:t.string().optional(),startAt:t.number().min(0).optional(),endAt:t.number().min(0).optional(),timelineTrack:t.number().int().min(0).max(99).optional(),...n}),t.object({type:t.literal("filter"),x:t.number().optional(),y:t.number().optional(),w:t.number().positive().optional(),h:t.number().positive().optional(),filterPreset:t.string().max(32).optional(),...a,...n}),t.object({type:t.literal("adjust"),x:t.number(),y:t.number(),w:t.number().positive(),h:t.number().positive(),brightness:t.number().min(-1).max(1).default(0),contrast:t.number().min(-1).max(1).default(0),saturation:t.number().min(-1).max(1).default(0),temperature:t.number().min(-1).max(1).default(0),tint:t.number().min(-1).max(1).default(0),vibrance:t.number().min(-1).max(1).default(0),gamma:t.number().min(-1).max(1).default(0),highlights:t.number().min(-1).max(1).default(0),shadows:t.number().min(-1).max(1).default(0),whites:t.number().min(-1).max(1).default(0),blacks:t.number().min(-1).max(1).default(0),lightSense:t.number().min(-1).max(1).default(0),sharpen:t.number().min(0).max(1).default(0),clarity:t.number().min(0).max(1).default(0),grain:t.number().min(0).max(1).default(0),fade:t.number().min(0).max(1).default(0),vignette:t.number().min(0).max(1).default(0),...a,...n})]),r=t.object({srcIdx:t.number().int().min(0).max(7),in:t.number().min(0),out:t.number().min(0)}),m=t.object({srcIdx:t.number().int().min(0).max(2),track:t.number().int().min(0).default(0),startAt:t.number().min(0),in:t.number().min(0),out:t.number().min(0),speed:t.number().min(.5).max(2).default(1),volume:t.number().min(0).max(2),fadeIn:t.number().min(0).default(0),fadeOut:t.number().min(0).default(0)}),u=t.object({type:t.enum(["none","fade","slide","wipe","flip","clockWipe","star","circle","rectangle"]).default("none"),duration:t.number().min(0).max(2).default(.4)}),o=t.object({fileName:t.string().max(120).optional(),format:t.enum(["mp4","mov","mxf"]).default("mp4"),width:t.number().int().min(2).max(8192).optional(),height:t.number().int().min(2).max(8192).optional(),frameRate:t.number().int().min(12).max(120).default(30),videoBitrateKbps:t.number().int().min(100).max(5e4).optional(),audioBitrateKbps:t.number().int().min(32).max(1024).optional(),audioCodec:t.enum(["aac","mp3"]).default("aac")}).optional(),s=t.object({clips:t.array(r).min(1).max(50),audioClips:t.array(m).max(8).default([]),canvas:t.object({w:t.number().int().min(2).max(4096),h:t.number().int().min(2).max(4096)}),crop:t.object({x:t.number().min(0),y:t.number().min(0),width:t.number().positive(),height:t.number().positive()}).optional(),scale:t.object({width:t.number().positive(),height:t.number().positive(),fit:t.enum(["contain","cover","force"])}).optional(),rotation:t.number().min(-180).max(180).default(0),flipX:t.boolean().default(!1),flipY:t.boolean().default(!1),filters:t.object({brightness:t.number().min(-1).max(1).default(0),contrast:t.number().min(-1).max(1).default(0),saturation:t.number().min(-1).max(1).default(0),temperature:t.number().min(-1).max(1).default(0),tint:t.number().min(-1).max(1).default(0),vibrance:t.number().min(-1).max(1).default(0),gamma:t.number().min(-1).max(1).default(0),highlights:t.number().min(-1).max(1).default(0),shadows:t.number().min(-1).max(1).default(0),whites:t.number().min(-1).max(1).default(0),blacks:t.number().min(-1).max(1).default(0),lightSense:t.number().min(-1).max(1).default(0),sharpen:t.number().min(0).max(1).default(0),clarity:t.number().min(0).max(1).default(0),grain:t.number().min(0).max(1).default(0),fade:t.number().min(0).max(1).default(0),vignette:t.number().min(0).max(1).default(0)}).default({brightness:0,contrast:0,saturation:0,temperature:0,tint:0,vibrance:0,gamma:0,highlights:0,shadows:0,whites:0,blacks:0,lightSense:0,sharpen:0,clarity:0,grain:0,fade:0,vignette:0}),filterPreset:t.string().max(32).optional(),overlays:t.array(i).max(200).optional(),transitions:t.array(u).max(49).default([]),keepAudio:t.boolean().default(!0),poster:t.object({time:t.number().min(0),useAsVideoCover:t.boolean().optional(),preview:t.string().optional()}).optional(),exportSettings:o}).superRefine((e,n)=>{e.clips.forEach((e,a)=>{e.out<=e.in&&n.addIssue({code:t.ZodIssueCode.custom,message:`clips[${a}].out 必须大于 in`,path:["clips",a,"out"]})}),e.audioClips?.forEach((e,a)=>{e.out<=e.in&&n.addIssue({code:t.ZodIssueCode.custom,message:`audioClips[${a}].out 必须大于 in`,path:["audioClips",a,"out"]})}),(e.canvas.w%2!=0||e.canvas.h%2!=0)&&n.addIssue({code:t.ZodIssueCode.custom,message:"canvas 宽高必须为偶数",path:["canvas"]}),null!=e.exportSettings?.width&&e.exportSettings.width%2!=0&&n.addIssue({code:t.ZodIssueCode.custom,message:"exportSettings.width 必须为偶数",path:["exportSettings","width"]}),null!=e.exportSettings?.height&&e.exportSettings.height%2!=0&&n.addIssue({code:t.ZodIssueCode.custom,message:"exportSettings.height 必须为偶数",path:["exportSettings","height"]})});function l(){return{clips:[],audioClips:[],canvas:{w:2,h:2},rotation:0,flipX:!1,flipY:!1,filters:{brightness:0,contrast:0,saturation:0,temperature:0,tint:0,vibrance:0,gamma:0,highlights:0,shadows:0,whites:0,blacks:0,lightSense:0,sharpen:0,clarity:0,grain:0,fade:0,vignette:0},transitions:[],keepAudio:!0}}var p=.1;function c(t){return t.out-t.in}function d(t){return t.reduce((t,e)=>t+c(e),0)}function b(t,e){let n=0;for(let a=0;a<e&&a<t.length;a++)n+=c(t[a]);return n}function f(t,e){if(!t.length||e<0)return null;let n=0;for(let a=0;a<t.length;a++){const i=c(t[a]);if(e<n+i)return{idx:a,srcTime:t[a].in+(e-n)};n+=i}if(Math.abs(e-n)<1e-9||e<=n){const e=t.length-1;return{idx:e,srcTime:t[e].out}}return null}function x(t,e){const n=f(t,e);if(!n)return t;const a=t[n.idx];return n.srcTime<a.in+p||n.srcTime>a.out-p?t:[...t.slice(0,n.idx),{...a,out:n.srcTime},{...a,in:n.srcTime},...t.slice(n.idx+1)]}function h(t,e){return t.length<=1||!t[e]?t:t.filter((t,n)=>n!==e)}function g(t,e){const n=t[e];return n?[...t.slice(0,e+1),{...n},...t.slice(e+1)]:t}function v(t,e,n){if(e===n||!t[e]||n<0||n>=t.length)return t;const a=[...t],[i]=a.splice(e,1);return a.splice(n,0,i),a}function y(t,e,n,a,i){if(!t[e])return t;const r=t.map(t=>({...t}));return"in"===n?r[e].in=Math.min(Math.max(a,0),r[e].out-p):r[e].out=Math.max(Math.min(a,i),r[e].in+p),r}function w(t,e,n){const a=Math.max(Math.min(t.out,e),p),i=Math.min(Math.max(t.in,0),a-p),r=Math.min(Math.max(t.startAt,0),Math.max(0,n-p)),m=Math.max(p,a-i),u=Math.min(Math.max(Number(t.speed)||1,.5),2),o=Number.isInteger(t.track)&&t.track>=0?t.track:0,s=Math.min(Math.max(Number(t.fadeIn)||0,0),m),l=Math.min(Math.max(Number(t.fadeOut)||0,0),Math.max(0,m-s));return{...t,track:o,in:i,out:a,startAt:r,speed:u,fadeIn:s,fadeOut:l}}function M(t,e=[],n=[]){const a=d(t),i=e.reduce((t,e)=>Math.max(t,e.startAt+(e.out-e.in)),0),r=function(t=[]){return(t??[]).reduce((t,e)=>{if("text"!==e?.type&&"sticker"!==e?.type)return t;const n=Number.isFinite(e?.startAt)?Math.max(0,Number(e.startAt)):0,a=Number.isFinite(e?.endAt)?Math.max(n,Number(e.endAt)):n;return Math.max(t,a)},0)}(n);return Math.max(a,i,r)}function I(t){return[...new Set(t.map(t=>t.srcIdx))].sort((t,e)=>t-e)}function j(t,e){const n=new Map(e.map((t,e)=>[t,e]));return t.map(t=>({...t,srcIdx:n.get(t.srcIdx)??0}))}function A(t){return{past:[],present:t,future:[]}}function C(t,e){if(e===t.present)return t;const n=[...t.past,t.present];return n.length>100&&n.shift(),{past:n,present:e,future:[]}}function S(t,e){return e===t.present?t:{...t,present:e}}function k(t){return t.past.length>0}function N(t){return t.future.length>0}function T(t){return k(t)?{past:t.past.slice(0,-1),present:t.past[t.past.length-1],future:[t.present,...t.future]}:t}function O(t){if(!N(t))return t;const[e,...n]=t.future;return{past:[...t.past,t.present],present:e,future:n}}export{m as AudioClip,r as Clip,p as MIN_CLIP,i as Overlay,s as VideoEditState,N as canRedo,k as canUndo,w as clampAudioClip,c as clipDuration,b as clipStartsAt,M as contentDuration,A as createHistory,l as defaultVideoEditState,g as duplicateClip,f as locateOutput,C as pushHistory,O as redo,j as remapSrcIndices,h as removeClip,v as reorderClips,S as replacePresent,x as splitAtOutput,d as totalDuration,y as trimClipEdge,T as undo,I as usedVideoSrcIndices};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var t=Math.PI/180;function a(a,n,s){const r=h(s);if(0===r||180===r)return{w:a,h:n};if(90===r||270===r)return{w:n,h:a};const e=r*t;return{w:Math.round(Math.abs(a*Math.cos(e))+Math.abs(n*Math.sin(e))),h:Math.round(Math.abs(a*Math.sin(e))+Math.abs(n*Math.cos(e)))}}function h(t){return(t%360+360)%360}function n(t){const a=Math.round(t);return a-a%2}function s(t,a,h=40){const n=Math.min(Math.max(h,t.width),a.w),s=Math.min(Math.max(h,t.height),a.h),r=Math.min(Math.max(0,t.x),a.w-n),e=Math.min(Math.max(0,t.y),a.h-s);return{x:Math.round(r),y:Math.round(e),width:Math.round(n),height:Math.round(s)}}function r(t,a){let h=t.w,n=h/a;return n>t.h&&(n=t.h,h=n*a),{x:Math.round((t.w-h)/2),y:Math.round((t.h-n)/2),width:Math.round(h),height:Math.round(n)}}function e(t,a,h){const n={x:0,y:0,width:t.width,height:t.height},s={x:0,y:0,width:a.w,height:a.h};return"cover"===h?{src:r({w:t.width,h:t.height},a.w/a.h),dst:s}:"contain"===h?{src:n,dst:r({w:a.w,h:a.h},t.width/t.height)}:{src:n,dst:s}}function i(t,h){if(h.scale)return{w:n(h.scale.width),h:n(h.scale.height)};if(h.crop)return{w:n(h.crop.width),h:n(h.crop.height)};const s=a(t.w,t.h,h.rotation);return{w:n(s.w),h:n(s.h)}}var o=[{id:"bw",label:"黑白",vf:"hue=s=0",css:"grayscale(1)"},{id:"sepia",label:"复古",vf:"colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131",css:"sepia(0.85)"},{id:"warm",label:"暖阳",vf:"colorbalance=rs=.15:gs=.04:bs=-.15",css:"sepia(0.25) saturate(1.25) brightness(1.03)"},{id:"cool",label:"冷调",vf:"colorbalance=rs=-.14:bs=.16",css:"hue-rotate(12deg) saturate(0.95) brightness(1.02)"},{id:"vivid",label:"鲜艳",vf:"eq=saturation=1.45:contrast=1.08",css:"saturate(1.45) contrast(1.08)"}];function c(t){return t?o.find(a=>a.id===t):void 0}function u(t,a){const h=c(a)?.css??"";return[`brightness(${1+t.brightness})`,`contrast(${1+t.contrast})`,`saturate(${1+t.saturation})`,h].filter(Boolean).join(" ")}export{t as DEG2RAD,o as FILTER_PRESETS,u as buildFilterCss,r as centeredMaxRect,s as clampRect,n as evenize,c as findFilterPreset,e as fitRects,h as normalizeDeg,i as outputSize,a as rotatedSize};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var c={"tool.trim":"\u526A\u8F91","tool.crop":"\u88C1\u526A","tool.tune":"\u8C03\u8272","tool.filter":"\u6EE4\u955C","tool.annotate":"\u6807\u6CE8","tool.sticker":"\u8D34\u7EB8","tool.resize":"\u6BD4\u4F8B","tune.brightness":"\u4EAE\u5EA6","tune.contrast":"\u5BF9\u6BD4","tune.saturation":"\u9971\u548C","tune.gamma":"Gamma","overlay.select":"\u9009\u62E9","overlay.pen":"\u753B\u7B14","overlay.eraser":"\u6A61\u76AE","overlay.line":"\u76F4\u7EBF","overlay.arrow":"\u7BAD\u5934","overlay.rect":"\u77E9\u5F62","overlay.ellipse":"\u692D\u5706","overlay.text":"\u6587\u5B57","overlay.color":"\u7EBF\u8272","overlay.width":"\u7EBF\u5BBD","overlay.copySelected":"\u590D\u5236","overlay.delSelected":"\u5220\u9664\u9009\u4E2D","overlay.editSelected":"\u7F16\u8F91","overlay.pickImage":"\u9009\u62E9\u56FE\u7247","overlay.hint":"\u70B9 emoji/\u56FE\u7247\u6DFB\u52A0 \u2192 \u753B\u5E03\u4E0A\u62D6\u52A8\u6446\u4F4D,\u62D6\u53F3\u4E0B\u89D2\u7D2B\u8272\u628A\u624B\u7F29\u653E","overlay.textPlaceholder":"\u8F93\u5165\u6587\u5B57,\u56DE\u8F66\u786E\u8BA4","filter.none":"\u539F\u56FE","filter.bw":"\u9ED1\u767D","filter.sepia":"\u590D\u53E4","filter.warm":"\u6696\u9633","filter.cool":"\u51B7\u8C03","filter.vivid":"\u9C9C\u8273","ratio.orig":"\u539F\u59CB","ratio.free":"\u81EA\u7531\u6BD4\u4F8B","ratio.9:16":"\u7AD6\u5C4F 9:16","ratio.16:9":"\u6A2A\u5C4F 16:9","ratio.1:1":"\u65B9\u5F62 1:1","ratio.4:5":"\u7AD6\u56FE 4:5","act.fit":"\u9002\u5E94","act.zoomFit":"\u7F29\u653E\u81F3\u9002\u5F53\u5927\u5C0F","act.zoomTo":"\u7F29\u653E\u81F3 {value}%","act.split":"\u5206\u5272","act.copy":"\u590D\u5236","act.delete":"\u5220\u9664","act.restore":"\u8FD8\u539F","act.deleteMusic":"\u5220\u9664\u97F3\u4E50","act.cancel":"\u53D6\u6D88","act.exportPoster":"\u5BFC\u51FA\u5C01\u9762","act.exporting":"\u5BFC\u51FA\u4E2D\u2026","act.poster":"\u{1F5BC} \u5C01\u9762","act.again":"\u518D\u6B21\u4E0B\u8F7D","act.saveDrive":"\u5B58\u7F51\u76D8","act.changeImage":"\u2190 \u6362\u4E00\u5F20","act.changeVideo":"\u2190 \u6362\u4E00\u4E2A","crop.rotateLeft":"\u21BA \u5411\u5DE6\u65CB\u8F6C","crop.flipX":"\u21CB \u6C34\u5E73\u7FFB\u8F6C","crop.flipY":"\u21F5 \u5782\u76F4\u7FFB\u8F6C","crop.rotateLeftShort":"\u5DE6\u8F6C","crop.flipXShort":"\u6A2A\u7FFB","crop.flipYShort":"\u7AD6\u7FFB","tip.close":"\u5173\u95ED(\u6362\u6587\u4EF6)","tip.undo":"\u64A4\u9500","tip.redo":"\u91CD\u505A","tip.resetOpened":"\u91CD\u7F6E\u5230\u6253\u5F00\u6587\u4EF6\u65F6","tip.previewZoom":"\u9884\u89C8\u7F29\u653E\u6BD4\u4F8B","tip.previewZoomOut":"\u7F29\u5C0F\u9884\u89C8","tip.previewZoomIn":"\u653E\u5927\u9884\u89C8","tip.previewZoomFit":"\u9002\u5E94\u9884\u89C8","tip.previewPointer":"\u6307\u9488\u5DE5\u5177","tip.previewPan":"\u624B\u5DE5\u5177\uFF1A\u62D6\u52A8\u753B\u9762","tip.poster":"\u9884\u89C8\u5E76\u9009\u62E9\u5C01\u9762\u5E27","tip.keepAudio":"\u539F\u89C6\u9891\u58F0\u97F3\u5F00\u5173(\u4E0E\u97F3\u4E50\u6DF7\u97F3;\u9884\u89C8\u540C\u6B65)","tip.split":"\u5728\u64AD\u653E\u5934\u5904\u628A\u5F53\u524D\u7247\u6BB5\u4E00\u5206\u4E3A\u4E8C","tip.zoomOut":"\u7F29\u5C0F\u65F6\u95F4\u8F74(Ctrl+\u6EDA\u8F6E)","tip.zoomIn":"\u653E\u5927\u65F6\u95F4\u8F74(Ctrl+\u6EDA\u8F6E)","tip.fit":"\u7F29\u653E\u5230\u9002\u5E94\u5BBD\u5EA6","tip.addVideo":"\u6DFB\u52A0\u89C6\u9891\u7247\u6BB5","tip.addAudio":"\u6DFB\u52A0\u97F3\u4E50(\u97F3\u9891\u6587\u4EF6,\u6216\u9009\u542B\u58F0\u97F3\u7684\u89C6\u9891\u81EA\u52A8\u63D0\u53D6\u97F3\u8F68;\u4E0E\u539F\u58F0\u6DF7\u97F3)","tip.dupClip":"\u590D\u5236\u8BE5\u7247\u6BB5(\u63D2\u5230\u5176\u540E)","tip.delClip":"\u5220\u9664\u8BE5\u7247\u6BB5","tip.lockAspect":"\u9501\u5B9A\u7EB5\u6A2A\u6BD4","tip.dblConfirm":"\u53CC\u51FB\u786E\u8BA4\u88C1\u526A","err.notVideo":"\u8BF7\u9009\u62E9\u89C6\u9891\u6587\u4EF6","err.maxVideo":"\u6700\u591A {max} \u4E2A\u89C6\u9891\u7D20\u6750","err.videoLoad":"\u89C6\u9891\u52A0\u8F7D\u5931\u8D25,\u8BF7\u6362\u4E00\u4E2A\u6587\u4EF6","err.notAudio":"\u8BF7\u9009\u62E9\u97F3\u9891\u6587\u4EF6(mp3/wav/m4a),\u6216\u542B\u58F0\u97F3\u7684\u89C6\u9891(\u81EA\u52A8\u63D0\u53D6\u97F3\u8F68)","err.maxAudio":"\u6700\u591A {max} \u4E2A\u97F3\u9891\u7D20\u6750","err.audioLoad":"\u97F3\u9891\u52A0\u8F7D\u5931\u8D25,\u8BF7\u6362\u4E00\u4E2A\u6587\u4EF6","err.processFailed":"\u5904\u7406\u5931\u8D25","err.posterFailed":"\u5C01\u9762\u6E32\u67D3\u5931\u8D25","err.canvas":"canvas \u4E0D\u53EF\u7528","err.imageRead":"\u56FE\u7247\u8BFB\u53D6\u5931\u8D25,\u8BF7\u6362\u4E00\u5F20","err.notImage":"\u8BF7\u9009\u62E9\u56FE\u7247\u6587\u4EF6","err.fileType":"\u53EA\u652F\u6301\u56FE\u7247\u6216\u89C6\u9891\u6587\u4EF6","err.saveDrive":"\u5B58\u7F51\u76D8\u5931\u8D25","msg.processing":"\u6B63\u5728\u5BFC\u51FA\u4E2D\u2026","msg.exportingHint":"\u8BF7\u7A0D\u5019\uFF0C\u5BFC\u51FA\u5B8C\u6210\u540E\u4F1A\u81EA\u52A8\u8FD4\u56DE\u7ED3\u679C\u3002","msg.done":"\u5B8C\u6210 \u2713","msg.loading":"\u7D20\u6750\u52A0\u8F7D\u4E2D\u2026","msg.exported":"\u5DF2\u5BFC\u51FA\uFF1A","msg.saving":"\u5B58\u7F51\u76D8\u4E2D\u2026","msg.saved":"\u5DF2\u5B58\u5230\u7F51\u76D8 \u2713","lbl.ratioSection":"\u753B\u9762\u6BD4\u4F8B(\u88C1\u526A,\u4E0D\u53D8\u5F62)","lbl.dragToReposition":"\u2194 \u62D6\u52A8\u9884\u89C8\u53EF\u8C03\u6574\u88C1\u526A\u4F4D\u7F6E","lbl.sizeSection":"\u5BFC\u51FA\u5C3A\u5BF8(\u50CF\u7D20;\u6BD4\u4F8B\u4E0D\u7B26\u65F6 cover \u5C45\u4E2D\u88C1\u526A)","lbl.currentOut":"\u5F53\u524D\u8F93\u51FA","lbl.zoomSize":"\u5927\u5C0F","lbl.noScale":"(\u672A\u7F29\u653E)","lbl.coverNote":"\xB7 \u6BD4\u4F8B\u4E0D\u4E00\u81F4\u65F6\u5C45\u4E2D\u88C1\u526A(cover),\u4E0D\u53D8\u5F62","lbl.audioTrackHint":"\u266A \u97F3\u9891\u8F68(\u53F3\u4FA7 \uFF0B \u6DFB\u52A0\u97F3\u4E50,\u4E0E\u539F\u58F0\u6DF7\u97F3)","lbl.volume":"\u97F3\u91CF","lbl.volNote":"(\u9884\u89C8\u6700\u5927 100%,\u5BFC\u51FA\u6309\u8BBE\u5B9A\u503C)","lbl.music":"\u97F3\u4E50","kbd.fit":"\u21E7 F","poster.title":"\u9009\u62E9\u5C01\u9762\u5E27","panel.title":"\u5A92\u4F53\u7F16\u8F91\u5668","panel.subtitle":"\u4E0A\u4F20\u56FE\u7247 / \u89C6\u9891\uFF0C\u88C1\u526A \xB7 \u6EE4\u955C \xB7 \u6587\u5B57 \xB7 \u5BFC\u51FA","panel.pick":"\u70B9\u51FB\u9009\u62E9\u56FE\u7247\u6216\u89C6\u9891","panel.pickHint":"\u56FE\u7247\u7528 Filerobot \xB7 \u89C6\u9891\u53EF\u88C1\u526A/\u9759\u97F3/\u5C01\u9762"},B={"tool.trim":"Trim","tool.crop":"Crop","tool.tune":"Tune","tool.filter":"Filters","tool.annotate":"Annotate","tool.sticker":"Stickers","tool.resize":"Ratio","tune.brightness":"Brightness","tune.contrast":"Contrast","tune.saturation":"Saturation","tune.gamma":"Gamma","overlay.select":"Select","overlay.pen":"Pen","overlay.eraser":"Eraser","overlay.line":"Line","overlay.arrow":"Arrow","overlay.rect":"Rect","overlay.ellipse":"Ellipse","overlay.text":"Text","overlay.color":"Color","overlay.width":"Width","overlay.copySelected":"Copy","overlay.delSelected":"Delete selected","overlay.editSelected":"Edit","overlay.pickImage":"Pick image","overlay.hint":"Tap emoji/image to add \u2192 drag to place, drag the purple corner handle to scale","overlay.textPlaceholder":"Type text, Enter to confirm","filter.none":"Original","filter.bw":"B&W","filter.sepia":"Sepia","filter.warm":"Warm","filter.cool":"Cool","filter.vivid":"Vivid","ratio.orig":"Original","ratio.free":"Free ratio","ratio.9:16":"Portrait 9:16","ratio.16:9":"Landscape 16:9","ratio.1:1":"Square 1:1","ratio.4:5":"Vertical 4:5","act.fit":"Fit","act.zoomFit":"Zoom to fit","act.zoomTo":"Zoom to {value}%","act.split":"Split","act.copy":"Copy","act.delete":"Delete","act.restore":"Reset","act.deleteMusic":"Remove music","act.cancel":"Cancel","act.exportPoster":"Export cover","act.exporting":"Exporting\u2026","act.poster":"\u{1F5BC} Cover","act.again":"Download again","act.saveDrive":"Save to drive","act.changeImage":"\u2190 Change image","act.changeVideo":"\u2190 Change file","crop.rotateLeft":"\u21BA Rotate left","crop.flipX":"\u21CB Flip horizontal","crop.flipY":"\u21F5 Flip vertical","crop.rotateLeftShort":"Rot","crop.flipXShort":"Flip","crop.flipYShort":"Flip","tip.close":"Close (change file)","tip.undo":"Undo","tip.redo":"Redo","tip.resetOpened":"Reset to opened file","tip.previewZoom":"Preview zoom","tip.previewZoomOut":"Zoom out preview","tip.previewZoomIn":"Zoom in preview","tip.previewZoomFit":"Fit preview","tip.previewPointer":"Pointer tool","tip.previewPan":"Hand tool: pan canvas","tip.poster":"Preview and pick a cover frame","tip.keepAudio":"Original audio on/off (mixed with music; preview follows)","tip.split":"Split the current clip at the playhead","tip.zoomOut":"Zoom out timeline (Ctrl+wheel)","tip.zoomIn":"Zoom in timeline (Ctrl+wheel)","tip.fit":"Fit to width","tip.addVideo":"Add video clip","tip.addAudio":"Add music (audio file, or a video with sound to extract its track; mixed with original)","tip.dupClip":"Duplicate clip (insert after)","tip.delClip":"Delete clip","tip.lockAspect":"Lock aspect ratio","tip.dblConfirm":"Double-click to confirm crop","err.notVideo":"Please choose a video file","err.maxVideo":"Up to {max} video sources","err.videoLoad":"Failed to load video, try another file","err.notAudio":"Choose an audio file (mp3/wav/m4a), or a video with sound (audio auto-extracted)","err.maxAudio":"Up to {max} audio sources","err.audioLoad":"Failed to load audio, try another file","err.processFailed":"Processing failed","err.posterFailed":"Failed to render cover","err.canvas":"Canvas unavailable","err.imageRead":"Failed to read image, try another","err.notImage":"Please choose an image file","err.fileType":"Only image or video files are supported","err.saveDrive":"Failed to save to drive","msg.processing":"Exporting\u2026","msg.exportingHint":"Please wait. The result will be returned automatically when export finishes.","msg.done":"Done \u2713","msg.loading":"Loading media\u2026","msg.exported":"Exported: ","msg.saving":"Saving\u2026","msg.saved":"Saved to drive \u2713","lbl.ratioSection":"Frame ratio (crop, no distortion)","lbl.dragToReposition":"\u2194 Drag the preview to reposition the crop","lbl.sizeSection":"Export size (px; cover center-crop when ratios differ)","lbl.currentOut":"Output","lbl.zoomSize":"Size","lbl.noScale":"(no scaling)","lbl.coverNote":"\xB7 center-cropped (cover) when ratios differ, no distortion","lbl.audioTrackHint":"\u266A Audio track (\uFF0B on the right to add music, mixed with original)","lbl.volume":"Volume","lbl.volNote":"(preview caps at 100%, export uses the set value)","lbl.music":"Music","kbd.fit":"\u21E7 F","poster.title":"Pick a cover frame","panel.title":"Media Editor","panel.subtitle":"Upload an image / video \u2014 crop \xB7 filters \xB7 text \xB7 export","panel.pick":"Click to choose an image or video","panel.pickHint":"Images via Filerobot \xB7 videos: trim/mute/cover"},D={"tool.trim":"Editar","tool.crop":"Recortar","tool.tune":"Ajustar color","tool.filter":"Filtros","tool.annotate":"Anotar","tool.sticker":"Stickers","tool.resize":"Proporci\xF3n","tune.brightness":"Brillo","tune.contrast":"Contraste","tune.saturation":"Saturaci\xF3n","tune.gamma":"Gamma","overlay.select":"Seleccionar","overlay.pen":"Pincel","overlay.eraser":"Borrador","overlay.line":"L\xEDnea","overlay.arrow":"Flecha","overlay.rect":"Rect\xE1ngulo","overlay.ellipse":"Elipse","overlay.text":"Texto","overlay.color":"Color","overlay.width":"Grosor","overlay.copySelected":"Copiar","overlay.delSelected":"Eliminar seleccionado","overlay.editSelected":"Editar","overlay.pickImage":"Elegir imagen","overlay.hint":"Toca un emoji/imagen para a\xF1adirlo \u2192 arrastra para colocarlo, arrastra el tirador morado para escalar","overlay.textPlaceholder":"Escribe texto, Enter para confirmar","filter.none":"Original","filter.bw":"Blanco y negro","filter.sepia":"Sepia","filter.warm":"C\xE1lido","filter.cool":"Fr\xEDo","filter.vivid":"Intenso","ratio.orig":"Original","ratio.free":"Libre","ratio.9:16":"Vertical 9:16","ratio.16:9":"Horizontal 16:9","ratio.1:1":"Cuadrado 1:1","ratio.4:5":"Vertical 4:5","act.fit":"Ajustar","act.zoomFit":"Ajustar a pantalla","act.zoomTo":"Zoom al {value}%","act.split":"Dividir","act.copy":"Copiar","act.delete":"Eliminar","act.restore":"Restablecer","act.deleteMusic":"Quitar m\xFAsica","act.cancel":"Cancelar","act.exportPoster":"Exportar portada","act.exporting":"Exportando\u2026","act.poster":"\u{1F5BC} Portada","act.again":"Descargar de nuevo","act.saveDrive":"Guardar en disco","act.changeImage":"\u2190 Cambiar imagen","act.changeVideo":"\u2190 Cambiar archivo","crop.rotateLeft":"\u21BA Girar a la izquierda","crop.flipX":"\u21CB Voltear horizontal","crop.flipY":"\u21F5 Voltear vertical","crop.rotateLeftShort":"Giro","crop.flipXShort":"Flip","crop.flipYShort":"Flip","tip.close":"Cerrar (cambiar archivo)","tip.undo":"Deshacer","tip.redo":"Rehacer","tip.resetOpened":"Restablecer al archivo abierto","tip.previewZoom":"Zoom de vista previa","tip.previewZoomOut":"Reducir vista previa","tip.previewZoomIn":"Ampliar vista previa","tip.previewZoomFit":"Ajustar vista previa","tip.previewPointer":"Herramienta de puntero","tip.previewPan":"Mano: desplazar lienzo","tip.poster":"Previsualizar y elegir portada","tip.keepAudio":"Activar/desactivar audio original (mezclado con m\xFAsica; la vista previa lo refleja)","tip.split":"Dividir el clip actual en el cursor","tip.zoomOut":"Reducir l\xEDnea de tiempo (Ctrl+rueda)","tip.zoomIn":"Ampliar l\xEDnea de tiempo (Ctrl+rueda)","tip.fit":"Ajustar al ancho","tip.addVideo":"A\xF1adir clip de v\xEDdeo","tip.addAudio":"A\xF1adir m\xFAsica (archivo de audio o v\xEDdeo con sonido para extraer la pista; se mezcla con el original)","tip.dupClip":"Duplicar clip (insertar despu\xE9s)","tip.delClip":"Eliminar clip","tip.lockAspect":"Bloquear proporci\xF3n","tip.dblConfirm":"Doble clic para confirmar recorte","err.notVideo":"Elige un archivo de v\xEDdeo","err.maxVideo":"M\xE1ximo {max} v\xEDdeos","err.videoLoad":"No se pudo cargar el v\xEDdeo, prueba con otro archivo","err.notAudio":"Elige un audio (mp3/wav/m4a) o un v\xEDdeo con sonido (se extrae autom\xE1ticamente)","err.maxAudio":"M\xE1ximo {max} audios","err.audioLoad":"No se pudo cargar el audio, prueba con otro archivo","err.processFailed":"Error de procesamiento","err.posterFailed":"No se pudo renderizar la portada","err.canvas":"Canvas no disponible","err.imageRead":"No se pudo leer la imagen, prueba con otra","err.notImage":"Elige un archivo de imagen","err.fileType":"Solo se admiten archivos de imagen o v\xEDdeo","err.saveDrive":"No se pudo guardar en disco","msg.processing":"Exportando\u2026","msg.exportingHint":"Espera un momento. El resultado se devolver\xE1 autom\xE1ticamente al finalizar.","msg.done":"Listo \u2713","msg.loading":"Cargando medios\u2026","msg.exported":"Exportado: ","msg.saving":"Guardando\u2026","msg.saved":"Guardado en disco \u2713","lbl.ratioSection":"Proporci\xF3n de imagen (recorte, sin deformar)","lbl.dragToReposition":"\u2194 Arrastra la vista previa para reposicionar el recorte","lbl.sizeSection":"Tama\xF1o de exportaci\xF3n (px; recorte cover centrado si la proporci\xF3n difiere)","lbl.currentOut":"Salida","lbl.zoomSize":"Tama\xF1o","lbl.noScale":"(sin escala)","lbl.coverNote":"\xB7 recorte centrado (cover) cuando la proporci\xF3n difiere, sin deformar","lbl.audioTrackHint":"\u266A Pista de audio (\uFF0B a la derecha para a\xF1adir m\xFAsica, mezclada con el original)","lbl.volume":"Volumen","lbl.volNote":"(la vista previa limita a 100%, la exportaci\xF3n usa el valor definido)","lbl.music":"M\xFAsica","kbd.fit":"\u21E7 F","poster.title":"Elegir portada","panel.title":"Editor multimedia","panel.subtitle":"Sube una imagen / v\xEDdeo \u2014 recorta \xB7 filtros \xB7 texto \xB7 exporta","panel.pick":"Haz clic para elegir una imagen o v\xEDdeo","panel.pickHint":"Im\xE1genes con Filerobot \xB7 v\xEDdeos: cortar/silenciar/portada"},A={\u7B80:"\u7C21",\u4F53:"\u9AD4",\u56FE:"\u5716",\u9891:"\u983B",\u89C6:"\u8996",\u8F91:"\u8F2F",\u8C03:"\u8ABF",\u6EE4:"\u6FFE",\u6807:"\u6A19",\u6CE8:"\u8A3B",\u8D34:"\u8CBC",\u9009:"\u9078",\u62E9:"\u64C7",\u7EBF:"\u7DDA",\u7BAD:"\u7BAD",\u5934:"\u982D",\u590D:"\u8907",\u5220:"\u522A",\u9664:"\u9664",\u7F16:"\u7DE8",\u8FB9:"\u908A",\u8F93:"\u8F38",\u5165:"\u5165",\u786E:"\u78BA",\u8BA4:"\u8A8D",\u9971:"\u98FD",\u5BF9:"\u5C0D",\u6696:"\u6696",\u9633:"\u967D",\u51B7:"\u51B7",\u7EB5:"\u7E31",\u6A2A:"\u6A6B",\u9002:"\u9069",\u5E94:"\u61C9",\u7F29:"\u7E2E",\u5B9E:"\u5BE6",\u9645:"\u969B",\u5BFC:"\u5C0E",\u51FA:"\u51FA",\u5C01:"\u5C01",\u9762:"\u9762",\u6362:"\u63DB",\u5F20:"\u5F35",\u9884:"\u9810",\u89C8:"\u89BD",\u52A8:"\u52D5",\u58F0:"\u8072",\u5F00:"\u958B",\u5173:"\u95DC",\u4E0E:"\u8207",\u4E50:"\u6A02",\u6DF7:"\u6DF7",\u5904:"\u8655",\u8F7D:"\u8F09",\u9519:"\u932F",\u8BEF:"\u8AA4",\u8BFB:"\u8B80",\u4EC5:"\u50C5",\u7EC8:"\u7D42",\u7A0D:"\u7A0D",\u5019:"\u5019",\u8FD4\u56DE:"\u8FD4\u56DE",\u5F53\u524D:"\u76EE\u524D",\u8F93\u51FA:"\u8F38\u51FA",\u753B:"\u756B",\u53D8:"\u8B8A",\u97F3\u9891:"\u97F3\u8A0A",\u97F3\u8F68:"\u97F3\u8ECC",\u6DFB\u52A0:"\u65B0\u589E",\u5220\u9664:"\u522A\u9664",\u4FDD\u5B58:"\u5132\u5B58",\u52A0\u8F7D:"\u8F09\u5165",\u7F51\u76D8:"\u7DB2\u76E4"},d=t=>{let u=t;for(const[o,e]of Object.entries(A).sort((i,a)=>a[0].length-i[0].length))u=u.replaceAll(o,e);return u},g=Object.fromEntries(Object.entries(c).map(([t,u])=>[t,d(u)])),n={zh:c,en:B,es:D,"zh-Hant":g};function x(t,u,o){let e=n[t]?.[u]??n.zh[u]??u;if(o)for(const[i,a]of Object.entries(o))e=e.replaceAll(`{${i}}`,String(a));return e}var l=[{platform:"tiktok",postType:"video",label:"TikTok Video",shortLabel:"TT\xB7Video",ratio:"9:16",imageSize:"1440x2560",videoRatio:"9:16",videoResolution:"720p"},{platform:"instagram",postType:"post",label:"Instagram Post",shortLabel:"IG\xB7Post",ratio:"1:1",imageSize:"2048x2048"},{platform:"instagram",postType:"reels",label:"Instagram Reels",shortLabel:"IG\xB7Reels",ratio:"9:16",imageSize:"1440x2560",videoRatio:"9:16",videoResolution:"720p"},{platform:"instagram",postType:"story",label:"Instagram Story",shortLabel:"IG\xB7Story",ratio:"9:16",imageSize:"1440x2560",videoRatio:"9:16",videoResolution:"720p"},{platform:"facebook",postType:"post",label:"Facebook Post",shortLabel:"FB\xB7Post",ratio:"1:1",imageSize:"2048x2048"},{platform:"facebook",postType:"reels",label:"Facebook Reels",shortLabel:"FB\xB7Reels",ratio:"9:16",imageSize:"1440x2560",videoRatio:"9:16",videoResolution:"720p"},{platform:"youtube",postType:"video",label:"YouTube Video",shortLabel:"YT\xB7Video",ratio:"16:9",imageSize:"2560x1440",videoRatio:"16:9",videoResolution:"1080p"},{platform:"youtube",postType:"shorts",label:"YouTube Shorts",shortLabel:"YT\xB7Shorts",ratio:"9:16",imageSize:"1440x2560",videoRatio:"9:16",videoResolution:"720p"},{platform:"pinterest",postType:"pin",label:"Pinterest Pin",shortLabel:"PIN",ratio:"2:3",imageSize:"1664x2496",videoRatio:"9:16",videoResolution:"720p"},{platform:"x",postType:"post",label:"X Post",shortLabel:"X\xB7Post",ratio:"16:9",imageSize:"2560x1440",videoRatio:"16:9",videoResolution:"720p"},{platform:"linkedin",postType:"post",label:"LinkedIn Post",shortLabel:"LI\xB7Post",ratio:"1:1",imageSize:"2048x2048"},{platform:"linkedin",postType:"video",label:"LinkedIn Video",shortLabel:"LI\xB7Video",ratio:"16:9",imageSize:"2560x1440",videoRatio:"16:9",videoResolution:"1080p"},{platform:"threads",postType:"post",label:"Threads Post",shortLabel:"TH\xB7Post",ratio:"1:1",imageSize:"2048x2048"},{platform:"telegram",postType:"post",label:"Telegram Post",shortLabel:"TG\xB7Post",ratio:"1:1",imageSize:"2048x2048",videoRatio:"9:16",videoResolution:"720p"},{platform:"reddit",postType:"post",label:"Reddit Post",shortLabel:"RD\xB7Post",ratio:"16:9",imageSize:"2560x1440",videoRatio:"16:9",videoResolution:"720p"}],C={"1:1":"\u65B9\u5F62 1:1","4:5":"\u7AD6\u56FE 4:5","3:4":"\u7AD6\u56FE 3:4","9:16":"\u7AD6\u5C4F 9:16","16:9":"\u6A2A\u5C4F 16:9","2:3":"\u7AD6\u56FE 2:3","1.91:1":"\u6A2A\u5E45 1.91:1"};function r(t){const[u,o]=t.split(":").map(Number);return!u||!o?1:u/o}function F(t){const u=new Set,o=[];for(const e of t)!e||u.has(e)||(u.add(e),o.push({ratio:e,value:r(e),label:C[e]??e}));return o}var f=F(["1:1","4:5","3:4","2:3","9:16","16:9","1.91:1"]),b=F(["9:16","16:9","1:1","4:5"]);function m(t=l){const u=new Set,o=[];for(const e of t){if(!e.videoRatio)continue;const i=`${e.platform}:${e.postType}:${e.videoRatio}`;if(u.has(i))continue;u.add(i);const a=e.label.split(" ").slice(0,-1).join(" ")||e.label;o.push({platform:e.platform,postType:e.postType,label:`${a} ${e.videoRatio}`,ratio:e.videoRatio,value:r(e.videoRatio)})}return o}var h=m();function E(t=l){const u=new Map;for(const o of t){const e=u.get(o.platform);(!e||e.postType!=="post"&&o.postType==="post")&&u.set(o.platform,o)}return Array.from(u.values()).map(o=>{const[e,i]=o.imageSize.split("x").map(Number),a=o.label.split(" ").slice(0,-1).join(" ")||o.label;return{platform:o.platform,label:`${a} ${o.ratio}`,ratio:o.ratio,value:r(o.ratio),w:e,h:i}})}var y=E();function S(t,u){return t>=1?{w:Math.round(u*t/2)*2,h:u}:{w:u,h:Math.round(u/t/2)*2}}function v(t=l){const u=new Set,o=[];for(const e of t){if(!e.videoRatio||!e.videoResolution)continue;const i=e.videoResolution==="1080p"?1080:720,{w:a,h:p}=S(r(e.videoRatio),i),s=`${a}x${p}`;u.has(s)||(u.add(s),o.push({label:`${e.shortLabel} ${a}\xD7${p}`,w:a,h:p}))}return o}var R=v();function T(t,u){if(t.isDuplicated)return{};if((t.rotation??0)!==0)return{};const o=u.adjustments?.rotation??0;return o?{rotation:-o}:{}}export{l as DEFAULT_PLATFORM_TARGETS,n as EDITOR_MESSAGES,y as IMAGE_PLATFORM_PRESETS,f as IMAGE_RATIO_PRESETS,h as VIDEO_PLATFORM_RATIO_PRESETS,b as VIDEO_RATIO_PRESETS,R as VIDEO_SIZE_PRESETS,E as buildImagePlatformPresets,m as buildVideoPlatformRatioPresets,v as buildVideoSizePresets,T as compensateAnnotationRotation,r as parseRatio,x as tEditor,d as toHant};
|
|
1
|
+
var e={"tool.trim":"剪辑","tool.crop":"裁剪","tool.tune":"调色","tool.filter":"滤镜","tool.annotate":"标注","tool.sticker":"贴纸","tool.resize":"比例","tune.brightness":"亮度","tune.contrast":"对比","tune.saturation":"饱和","tune.gamma":"Gamma","overlay.select":"选择","overlay.pen":"画笔","overlay.eraser":"橡皮","overlay.line":"直线","overlay.arrow":"箭头","overlay.rect":"矩形","overlay.ellipse":"椭圆","overlay.text":"文字","overlay.color":"线色","overlay.width":"线宽","overlay.copySelected":"复制","overlay.delSelected":"删除选中","overlay.editSelected":"编辑","overlay.pickImage":"选择图片","overlay.hint":"点 emoji/图片添加 → 画布上拖动摆位,拖右下角紫色把手缩放","overlay.textPlaceholder":"输入文字,回车确认","filter.none":"原图","filter.bw":"黑白","filter.sepia":"复古","filter.warm":"暖阳","filter.cool":"冷调","filter.vivid":"鲜艳","ratio.orig":"原始","ratio.free":"自由比例","ratio.9:16":"竖屏 9:16","ratio.16:9":"横屏 16:9","ratio.1:1":"方形 1:1","ratio.4:5":"竖图 4:5","act.fit":"适应","act.zoomFit":"缩放至适当大小","act.zoomTo":"缩放至 {value}%","act.split":"分割","act.copy":"复制","act.delete":"删除","act.restore":"还原","act.deleteMusic":"删除音乐","act.cancel":"取消","act.exportPoster":"导出封面","act.exporting":"导出中…","act.poster":"🖼 封面","act.again":"再次下载","act.saveDrive":"存网盘","act.changeImage":"← 换一张","act.changeVideo":"← 换一个","crop.rotateLeft":"↺ 向左旋转","crop.flipX":"⇋ 水平翻转","crop.flipY":"⇵ 垂直翻转","crop.rotateLeftShort":"左转","crop.flipXShort":"横翻","crop.flipYShort":"竖翻","tip.close":"关闭(换文件)","tip.undo":"撤销","tip.redo":"重做","tip.resetOpened":"重置到打开文件时","tip.previewZoom":"预览缩放比例","tip.previewZoomOut":"缩小预览","tip.previewZoomIn":"放大预览","tip.previewZoomFit":"适应预览","tip.previewPointer":"指针工具","tip.previewPan":"手工具:拖动画面","tip.poster":"预览并选择封面帧","tip.keepAudio":"原视频声音开关(与音乐混音;预览同步)","tip.split":"在播放头处把当前片段一分为二","tip.zoomOut":"缩小时间轴(Ctrl+滚轮)","tip.zoomIn":"放大时间轴(Ctrl+滚轮)","tip.fit":"缩放到适应宽度","tip.addVideo":"添加视频片段","tip.addAudio":"添加音乐(音频文件,或选含声音的视频自动提取音轨;与原声混音)","tip.dupClip":"复制该片段(插到其后)","tip.delClip":"删除该片段","tip.lockAspect":"锁定纵横比","tip.dblConfirm":"双击确认裁剪","err.notVideo":"请选择视频文件","err.maxVideo":"最多 {max} 个视频素材","err.videoLoad":"视频加载失败,请换一个文件","err.notAudio":"请选择音频文件(mp3/wav/m4a),或含声音的视频(自动提取音轨)","err.maxAudio":"最多 {max} 个音频素材","err.audioLoad":"音频加载失败,请换一个文件","err.processFailed":"处理失败","err.posterFailed":"封面渲染失败","err.canvas":"canvas 不可用","err.imageRead":"图片读取失败,请换一张","err.notImage":"请选择图片文件","err.fileType":"只支持图片或视频文件","err.saveDrive":"存网盘失败","msg.processing":"正在导出中…","msg.exportingHint":"请稍候,导出完成后会自动返回结果。","msg.done":"完成 ✓","msg.loading":"素材加载中…","msg.exported":"已导出:","msg.saving":"存网盘中…","msg.saved":"已存到网盘 ✓","lbl.ratioSection":"画面比例(裁剪,不变形)","lbl.dragToReposition":"↔ 拖动预览可调整裁剪位置","lbl.sizeSection":"导出尺寸(像素;比例不符时 cover 居中裁剪)","lbl.currentOut":"当前输出","lbl.zoomSize":"大小","lbl.noScale":"(未缩放)","lbl.coverNote":"· 比例不一致时居中裁剪(cover),不变形","lbl.audioTrackHint":"♪ 音频轨(右侧 + 添加音乐,与原声混音)","lbl.volume":"音量","lbl.volNote":"(预览最大 100%,导出按设定值)","lbl.music":"音乐","kbd.fit":"⇧ F","poster.title":"选择封面帧","panel.title":"媒体编辑器","panel.subtitle":"上传图片 / 视频,裁剪 · 滤镜 · 文字 · 导出","panel.pick":"点击选择图片或视频","panel.pickHint":"图片用 Filerobot · 视频可裁剪/静音/封面"},o={"简":"簡","体":"體","图":"圖","频":"頻","视":"視","辑":"輯","调":"調","滤":"濾","标":"標","注":"註","贴":"貼","选":"選","择":"擇","线":"線","箭":"箭","头":"頭","复":"複","删":"刪","除":"除","编":"編","边":"邊","输":"輸","入":"入","确":"確","认":"認","饱":"飽","对":"對","暖":"暖","阳":"陽","冷":"冷","纵":"縱","横":"橫","适":"適","应":"應","缩":"縮","实":"實","际":"際","导":"導","出":"出","封":"封","面":"面","换":"換","张":"張","预":"預","览":"覽","动":"動","声":"聲","开":"開","关":"關","与":"與","乐":"樂","混":"混","处":"處","载":"載","错":"錯","误":"誤","读":"讀","仅":"僅","终":"終","稍":"稍","候":"候","返回":"返回","当前":"目前","输出":"輸出","画":"畫","变":"變","音频":"音訊","音轨":"音軌","添加":"新增","删除":"刪除","保存":"儲存","加载":"載入","网盘":"網盤"},t=e=>{let t=e;for(const[e,a]of Object.entries(o).sort((e,o)=>o[0].length-e[0].length))t=t.replaceAll(e,a);return t},a={zh:e,en:{"tool.trim":"Trim","tool.crop":"Crop","tool.tune":"Tune","tool.filter":"Filters","tool.annotate":"Annotate","tool.sticker":"Stickers","tool.resize":"Ratio","tune.brightness":"Brightness","tune.contrast":"Contrast","tune.saturation":"Saturation","tune.gamma":"Gamma","overlay.select":"Select","overlay.pen":"Pen","overlay.eraser":"Eraser","overlay.line":"Line","overlay.arrow":"Arrow","overlay.rect":"Rect","overlay.ellipse":"Ellipse","overlay.text":"Text","overlay.color":"Color","overlay.width":"Width","overlay.copySelected":"Copy","overlay.delSelected":"Delete selected","overlay.editSelected":"Edit","overlay.pickImage":"Pick image","overlay.hint":"Tap emoji/image to add → drag to place, drag the purple corner handle to scale","overlay.textPlaceholder":"Type text, Enter to confirm","filter.none":"Original","filter.bw":"B&W","filter.sepia":"Sepia","filter.warm":"Warm","filter.cool":"Cool","filter.vivid":"Vivid","ratio.orig":"Original","ratio.free":"Free ratio","ratio.9:16":"Portrait 9:16","ratio.16:9":"Landscape 16:9","ratio.1:1":"Square 1:1","ratio.4:5":"Vertical 4:5","act.fit":"Fit","act.zoomFit":"Zoom to fit","act.zoomTo":"Zoom to {value}%","act.split":"Split","act.copy":"Copy","act.delete":"Delete","act.restore":"Reset","act.deleteMusic":"Remove music","act.cancel":"Cancel","act.exportPoster":"Export cover","act.exporting":"Exporting…","act.poster":"🖼 Cover","act.again":"Download again","act.saveDrive":"Save to drive","act.changeImage":"← Change image","act.changeVideo":"← Change file","crop.rotateLeft":"↺ Rotate left","crop.flipX":"⇋ Flip horizontal","crop.flipY":"⇵ Flip vertical","crop.rotateLeftShort":"Rot","crop.flipXShort":"Flip","crop.flipYShort":"Flip","tip.close":"Close (change file)","tip.undo":"Undo","tip.redo":"Redo","tip.resetOpened":"Reset to opened file","tip.previewZoom":"Preview zoom","tip.previewZoomOut":"Zoom out preview","tip.previewZoomIn":"Zoom in preview","tip.previewZoomFit":"Fit preview","tip.previewPointer":"Pointer tool","tip.previewPan":"Hand tool: pan canvas","tip.poster":"Preview and pick a cover frame","tip.keepAudio":"Original audio on/off (mixed with music; preview follows)","tip.split":"Split the current clip at the playhead","tip.zoomOut":"Zoom out timeline (Ctrl+wheel)","tip.zoomIn":"Zoom in timeline (Ctrl+wheel)","tip.fit":"Fit to width","tip.addVideo":"Add video clip","tip.addAudio":"Add music (audio file, or a video with sound to extract its track; mixed with original)","tip.dupClip":"Duplicate clip (insert after)","tip.delClip":"Delete clip","tip.lockAspect":"Lock aspect ratio","tip.dblConfirm":"Double-click to confirm crop","err.notVideo":"Please choose a video file","err.maxVideo":"Up to {max} video sources","err.videoLoad":"Failed to load video, try another file","err.notAudio":"Choose an audio file (mp3/wav/m4a), or a video with sound (audio auto-extracted)","err.maxAudio":"Up to {max} audio sources","err.audioLoad":"Failed to load audio, try another file","err.processFailed":"Processing failed","err.posterFailed":"Failed to render cover","err.canvas":"Canvas unavailable","err.imageRead":"Failed to read image, try another","err.notImage":"Please choose an image file","err.fileType":"Only image or video files are supported","err.saveDrive":"Failed to save to drive","msg.processing":"Exporting…","msg.exportingHint":"Please wait. The result will be returned automatically when export finishes.","msg.done":"Done ✓","msg.loading":"Loading media…","msg.exported":"Exported: ","msg.saving":"Saving…","msg.saved":"Saved to drive ✓","lbl.ratioSection":"Frame ratio (crop, no distortion)","lbl.dragToReposition":"↔ Drag the preview to reposition the crop","lbl.sizeSection":"Export size (px; cover center-crop when ratios differ)","lbl.currentOut":"Output","lbl.zoomSize":"Size","lbl.noScale":"(no scaling)","lbl.coverNote":"· center-cropped (cover) when ratios differ, no distortion","lbl.audioTrackHint":"♪ Audio track (+ on the right to add music, mixed with original)","lbl.volume":"Volume","lbl.volNote":"(preview caps at 100%, export uses the set value)","lbl.music":"Music","kbd.fit":"⇧ F","poster.title":"Pick a cover frame","panel.title":"Media Editor","panel.subtitle":"Upload an image / video — crop · filters · text · export","panel.pick":"Click to choose an image or video","panel.pickHint":"Images via Filerobot · videos: trim/mute/cover"},es:{"tool.trim":"Editar","tool.crop":"Recortar","tool.tune":"Ajustar color","tool.filter":"Filtros","tool.annotate":"Anotar","tool.sticker":"Stickers","tool.resize":"Proporción","tune.brightness":"Brillo","tune.contrast":"Contraste","tune.saturation":"Saturación","tune.gamma":"Gamma","overlay.select":"Seleccionar","overlay.pen":"Pincel","overlay.eraser":"Borrador","overlay.line":"Línea","overlay.arrow":"Flecha","overlay.rect":"Rectángulo","overlay.ellipse":"Elipse","overlay.text":"Texto","overlay.color":"Color","overlay.width":"Grosor","overlay.copySelected":"Copiar","overlay.delSelected":"Eliminar seleccionado","overlay.editSelected":"Editar","overlay.pickImage":"Elegir imagen","overlay.hint":"Toca un emoji/imagen para añadirlo → arrastra para colocarlo, arrastra el tirador morado para escalar","overlay.textPlaceholder":"Escribe texto, Enter para confirmar","filter.none":"Original","filter.bw":"Blanco y negro","filter.sepia":"Sepia","filter.warm":"Cálido","filter.cool":"Frío","filter.vivid":"Intenso","ratio.orig":"Original","ratio.free":"Libre","ratio.9:16":"Vertical 9:16","ratio.16:9":"Horizontal 16:9","ratio.1:1":"Cuadrado 1:1","ratio.4:5":"Vertical 4:5","act.fit":"Ajustar","act.zoomFit":"Ajustar a pantalla","act.zoomTo":"Zoom al {value}%","act.split":"Dividir","act.copy":"Copiar","act.delete":"Eliminar","act.restore":"Restablecer","act.deleteMusic":"Quitar música","act.cancel":"Cancelar","act.exportPoster":"Exportar portada","act.exporting":"Exportando…","act.poster":"🖼 Portada","act.again":"Descargar de nuevo","act.saveDrive":"Guardar en disco","act.changeImage":"← Cambiar imagen","act.changeVideo":"← Cambiar archivo","crop.rotateLeft":"↺ Girar a la izquierda","crop.flipX":"⇋ Voltear horizontal","crop.flipY":"⇵ Voltear vertical","crop.rotateLeftShort":"Giro","crop.flipXShort":"Flip","crop.flipYShort":"Flip","tip.close":"Cerrar (cambiar archivo)","tip.undo":"Deshacer","tip.redo":"Rehacer","tip.resetOpened":"Restablecer al archivo abierto","tip.previewZoom":"Zoom de vista previa","tip.previewZoomOut":"Reducir vista previa","tip.previewZoomIn":"Ampliar vista previa","tip.previewZoomFit":"Ajustar vista previa","tip.previewPointer":"Herramienta de puntero","tip.previewPan":"Mano: desplazar lienzo","tip.poster":"Previsualizar y elegir portada","tip.keepAudio":"Activar/desactivar audio original (mezclado con música; la vista previa lo refleja)","tip.split":"Dividir el clip actual en el cursor","tip.zoomOut":"Reducir línea de tiempo (Ctrl+rueda)","tip.zoomIn":"Ampliar línea de tiempo (Ctrl+rueda)","tip.fit":"Ajustar al ancho","tip.addVideo":"Añadir clip de vídeo","tip.addAudio":"Añadir música (archivo de audio o vídeo con sonido para extraer la pista; se mezcla con el original)","tip.dupClip":"Duplicar clip (insertar después)","tip.delClip":"Eliminar clip","tip.lockAspect":"Bloquear proporción","tip.dblConfirm":"Doble clic para confirmar recorte","err.notVideo":"Elige un archivo de vídeo","err.maxVideo":"Máximo {max} vídeos","err.videoLoad":"No se pudo cargar el vídeo, prueba con otro archivo","err.notAudio":"Elige un audio (mp3/wav/m4a) o un vídeo con sonido (se extrae automáticamente)","err.maxAudio":"Máximo {max} audios","err.audioLoad":"No se pudo cargar el audio, prueba con otro archivo","err.processFailed":"Error de procesamiento","err.posterFailed":"No se pudo renderizar la portada","err.canvas":"Canvas no disponible","err.imageRead":"No se pudo leer la imagen, prueba con otra","err.notImage":"Elige un archivo de imagen","err.fileType":"Solo se admiten archivos de imagen o vídeo","err.saveDrive":"No se pudo guardar en disco","msg.processing":"Exportando…","msg.exportingHint":"Espera un momento. El resultado se devolverá automáticamente al finalizar.","msg.done":"Listo ✓","msg.loading":"Cargando medios…","msg.exported":"Exportado: ","msg.saving":"Guardando…","msg.saved":"Guardado en disco ✓","lbl.ratioSection":"Proporción de imagen (recorte, sin deformar)","lbl.dragToReposition":"↔ Arrastra la vista previa para reposicionar el recorte","lbl.sizeSection":"Tamaño de exportación (px; recorte cover centrado si la proporción difiere)","lbl.currentOut":"Salida","lbl.zoomSize":"Tamaño","lbl.noScale":"(sin escala)","lbl.coverNote":"· recorte centrado (cover) cuando la proporción difiere, sin deformar","lbl.audioTrackHint":"♪ Pista de audio (+ a la derecha para añadir música, mezclada con el original)","lbl.volume":"Volumen","lbl.volNote":"(la vista previa limita a 100%, la exportación usa el valor definido)","lbl.music":"Música","kbd.fit":"⇧ F","poster.title":"Elegir portada","panel.title":"Editor multimedia","panel.subtitle":"Sube una imagen / vídeo — recorta · filtros · texto · exporta","panel.pick":"Haz clic para elegir una imagen o vídeo","panel.pickHint":"Imágenes con Filerobot · vídeos: cortar/silenciar/portada"},"zh-Hant":Object.fromEntries(Object.entries(e).map(([e,o])=>[e,t(o)]))};function i(e,o,t){let i=a[e]?.[o]??a.zh[o]??o;if(t)for(const[e,o]of Object.entries(t))i=i.replaceAll(`{${e}}`,String(o));return i}var r=[{platform:"tiktok",postType:"video",label:"TikTok Video",shortLabel:"TT·Video",ratio:"9:16",imageSize:"1440x2560",videoRatio:"9:16",videoResolution:"720p"},{platform:"instagram",postType:"post",label:"Instagram Post",shortLabel:"IG·Post",ratio:"1:1",imageSize:"2048x2048"},{platform:"instagram",postType:"reels",label:"Instagram Reels",shortLabel:"IG·Reels",ratio:"9:16",imageSize:"1440x2560",videoRatio:"9:16",videoResolution:"720p"},{platform:"instagram",postType:"story",label:"Instagram Story",shortLabel:"IG·Story",ratio:"9:16",imageSize:"1440x2560",videoRatio:"9:16",videoResolution:"720p"},{platform:"facebook",postType:"post",label:"Facebook Post",shortLabel:"FB·Post",ratio:"1:1",imageSize:"2048x2048"},{platform:"facebook",postType:"reels",label:"Facebook Reels",shortLabel:"FB·Reels",ratio:"9:16",imageSize:"1440x2560",videoRatio:"9:16",videoResolution:"720p"},{platform:"youtube",postType:"video",label:"YouTube Video",shortLabel:"YT·Video",ratio:"16:9",imageSize:"2560x1440",videoRatio:"16:9",videoResolution:"1080p"},{platform:"youtube",postType:"shorts",label:"YouTube Shorts",shortLabel:"YT·Shorts",ratio:"9:16",imageSize:"1440x2560",videoRatio:"9:16",videoResolution:"720p"},{platform:"pinterest",postType:"pin",label:"Pinterest Pin",shortLabel:"PIN",ratio:"2:3",imageSize:"1664x2496",videoRatio:"9:16",videoResolution:"720p"},{platform:"x",postType:"post",label:"X Post",shortLabel:"X·Post",ratio:"16:9",imageSize:"2560x1440",videoRatio:"16:9",videoResolution:"720p"},{platform:"linkedin",postType:"post",label:"LinkedIn Post",shortLabel:"LI·Post",ratio:"1:1",imageSize:"2048x2048"},{platform:"linkedin",postType:"video",label:"LinkedIn Video",shortLabel:"LI·Video",ratio:"16:9",imageSize:"2560x1440",videoRatio:"16:9",videoResolution:"1080p"},{platform:"threads",postType:"post",label:"Threads Post",shortLabel:"TH·Post",ratio:"1:1",imageSize:"2048x2048"},{platform:"telegram",postType:"post",label:"Telegram Post",shortLabel:"TG·Post",ratio:"1:1",imageSize:"2048x2048",videoRatio:"9:16",videoResolution:"720p"},{platform:"reddit",postType:"post",label:"Reddit Post",shortLabel:"RD·Post",ratio:"16:9",imageSize:"2560x1440",videoRatio:"16:9",videoResolution:"720p"}],l={"1:1":"方形 1:1","4:5":"竖图 4:5","3:4":"竖图 3:4","9:16":"竖屏 9:16","16:9":"横屏 16:9","2:3":"竖图 2:3","1.91:1":"横幅 1.91:1"};function p(e){const[o,t]=e.split(":").map(Number);return o&&t?o/t:1}function n(e){const o=new Set,t=[];for(const a of e)!a||o.has(a)||(o.add(a),t.push({ratio:a,value:p(a),label:l[a]??a}));return t}var s=n(["1:1","4:5","3:4","2:3","9:16","16:9","1.91:1"]),c=n(["9:16","16:9","1:1","4:5"]);function d(e=r){const o=new Set,t=[];for(const a of e){if(!a.videoRatio)continue;const e=`${a.platform}:${a.postType}:${a.videoRatio}`;if(o.has(e))continue;o.add(e);const i=a.label.split(" ").slice(0,-1).join(" ")||a.label;t.push({platform:a.platform,postType:a.postType,label:`${i} ${a.videoRatio}`,ratio:a.videoRatio,value:p(a.videoRatio)})}return t}var m=d();function v(e=r){const o=new Map;for(const t of e){const e=o.get(t.platform);(!e||"post"!==e.postType&&"post"===t.postType)&&o.set(t.platform,t)}return Array.from(o.values()).map(e=>{const[o,t]=e.imageSize.split("x").map(Number),a=e.label.split(" ").slice(0,-1).join(" ")||e.label;return{platform:e.platform,label:`${a} ${e.ratio}`,ratio:e.ratio,value:p(e.ratio),w:o,h:t}})}var u=v();function g(e,o){return e>=1?{w:2*Math.round(o*e/2),h:o}:{w:o,h:2*Math.round(o/e/2)}}function f(e=r){const o=new Set,t=[];for(const a of e){if(!a.videoRatio||!a.videoResolution)continue;const e="1080p"===a.videoResolution?1080:720,{w:i,h:r}=g(p(a.videoRatio),e),l=`${i}x${r}`;o.has(l)||(o.add(l),t.push({label:`${a.shortLabel} ${i}×${r}`,w:i,h:r}))}return t}var b=f();function h(e,o){if(e.isDuplicated)return{};if(0!==(e.rotation??0))return{};const t=o.adjustments?.rotation??0;return t?{rotation:-t}:{}}export{r as DEFAULT_PLATFORM_TARGETS,a as EDITOR_MESSAGES,u as IMAGE_PLATFORM_PRESETS,s as IMAGE_RATIO_PRESETS,m as VIDEO_PLATFORM_RATIO_PRESETS,c as VIDEO_RATIO_PRESETS,b as VIDEO_SIZE_PRESETS,v as buildImagePlatformPresets,d as buildVideoPlatformRatioPresets,f as buildVideoSizePresets,h as compensateAnnotationRotation,p as parseRatio,i as tEditor,t as toHant};
|
package/core/dist/engine.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var s=require("zod"),p={color:s.z.string().max(32),width:s.z.number().positive().max(200)},u={rotation:s.z.number().min(-180).max(180).optional()},A=s.z.discriminatedUnion("type",[s.z.object({type:s.z.literal("pen"),points:s.z.array(s.z.number()).min(4),...p,...u}),s.z.object({type:s.z.literal("line"),x1:s.z.number(),y1:s.z.number(),x2:s.z.number(),y2:s.z.number(),...p,...u}),s.z.object({type:s.z.literal("arrow"),x1:s.z.number(),y1:s.z.number(),x2:s.z.number(),y2:s.z.number(),...p,...u}),s.z.object({type:s.z.literal("rect"),x:s.z.number(),y:s.z.number(),w:s.z.number(),h:s.z.number(),...p,...u}),s.z.object({type:s.z.literal("ellipse"),x:s.z.number(),y:s.z.number(),w:s.z.number(),h:s.z.number(),...p,...u}),s.z.object({type:s.z.literal("text"),x:s.z.number(),y:s.z.number(),text:s.z.string().max(500),color:s.z.string().max(32),fontSize:s.z.number().positive().max(512),...u}),s.z.object({type:s.z.literal("sticker"),x:s.z.number(),y:s.z.number(),w:s.z.number().positive(),h:s.z.number().positive(),emoji:s.z.string().max(16).optional(),src:s.z.string().optional(),...u})]),B=s.z.object({srcIdx:s.z.number().int().min(0).max(7),in:s.z.number().min(0),out:s.z.number().min(0)}),I=s.z.object({srcIdx:s.z.number().int().min(0).max(2),startAt:s.z.number().min(0),in:s.z.number().min(0),out:s.z.number().min(0),volume:s.z.number().min(0).max(2)}),w=s.z.object({type:s.z.enum(["none","fade","slide","wipe","flip","clockWipe","star","circle","rectangle"]).default("none"),duration:s.z.number().min(0).max(2).default(.4)}),j=s.z.object({clips:s.z.array(B).min(1).max(50),audioClips:s.z.array(I).max(8).default([]),canvas:s.z.object({w:s.z.number().int().min(2).max(4096),h:s.z.number().int().min(2).max(4096)}),crop:s.z.object({x:s.z.number().min(0),y:s.z.number().min(0),width:s.z.number().positive(),height:s.z.number().positive()}).optional(),scale:s.z.object({width:s.z.number().positive(),height:s.z.number().positive(),fit:s.z.enum(["contain","cover","force"])}).optional(),rotation:s.z.number().min(-180).max(180).default(0),flipX:s.z.boolean().default(!1),flipY:s.z.boolean().default(!1),filters:s.z.object({brightness:s.z.number().min(-1).max(1),contrast:s.z.number().min(-1).max(1),saturation:s.z.number().min(-1).max(1),gamma:s.z.number().min(-1).max(1).default(0)}).default({brightness:0,contrast:0,saturation:0,gamma:0}),filterPreset:s.z.string().max(32).optional(),overlays:s.z.array(A).max(200).optional(),transitions:s.z.array(w).max(49).default([]),keepAudio:s.z.boolean().default(!0),poster:s.z.object({time:s.z.number().min(0)}).optional()}).superRefine((t,e)=>{t.clips.forEach((i,r)=>{i.out<=i.in&&e.addIssue({code:s.z.ZodIssueCode.custom,message:`clips[${r}].out \u5FC5\u987B\u5927\u4E8E in`,path:["clips",r,"out"]})}),t.audioClips?.forEach((i,r)=>{i.out<=i.in&&e.addIssue({code:s.z.ZodIssueCode.custom,message:`audioClips[${r}].out \u5FC5\u987B\u5927\u4E8E in`,path:["audioClips",r,"out"]})}),(t.canvas.w%2!==0||t.canvas.h%2!==0)&&e.addIssue({code:s.z.ZodIssueCode.custom,message:"canvas \u5BBD\u9AD8\u5FC5\u987B\u4E3A\u5076\u6570",path:["canvas"]})});function c(){return{clips:[],audioClips:[],canvas:{w:2,h:2},rotation:0,flipX:!1,flipY:!1,filters:{brightness:0,contrast:0,saturation:0,gamma:0},transitions:[],keepAudio:!0}}var E=100;function m(t){return{past:[],present:t,future:[]}}function d(t,e){if(e===t.present)return t;const i=[...t.past,t.present];return i.length>E&&i.shift(),{past:i,present:e,future:[]}}function y(t,e){return e===t.present?t:{...t,present:e}}function z(t){return t.past.length>0}function f(t){return t.future.length>0}function P(t){return z(t)?{past:t.past.slice(0,-1),present:t.past[t.past.length-1],future:[t.present,...t.future]}:t}function F(t){if(!f(t))return t;const[e,...i]=t.future;return{past:[...t.past,t.present],present:e,future:i}}var l=.1;function b(t){return t.out-t.in}function h(t){return t.reduce((e,i)=>e+b(i),0)}function x(t,e){if(!t.length||e<0)return null;let i=0;for(let r=0;r<t.length;r++){const n=b(t[r]);if(e<i+n)return{idx:r,srcTime:t[r].in+(e-i)};i+=n}if(Math.abs(e-i)<1e-9||e<=i){const r=t.length-1;return{idx:r,srcTime:t[r].out}}return null}function T(t,e){const i=x(t,e);if(!i)return t;const r=t[i.idx];return i.srcTime<r.in+l||i.srcTime>r.out-l?t:[...t.slice(0,i.idx),{...r,out:i.srcTime},{...r,in:i.srcTime},...t.slice(i.idx+1)]}function k(t,e){return t.length<=1||!t[e]?t:t.filter((i,r)=>r!==e)}function O(t,e){const i=t[e];return i?[...t.slice(0,e+1),{...i},...t.slice(e+1)]:t}function V(t,e,i){if(e===i||!t[e]||i<0||i>=t.length)return t;const r=[...t],[n]=r.splice(e,1);return r.splice(i,0,n),r}function X(t,e,i,r,n){if(!t[e])return t;const o=t.map(a=>({...a}));return i==="in"?o[e].in=Math.min(Math.max(r,0),o[e].out-l):o[e].out=Math.max(Math.min(r,n),o[e].in+l),o}function M(t,e,i){const r=Math.max(Math.min(t.out,e),l),n=Math.min(Math.max(t.in,0),r-l),o=Math.min(Math.max(t.startAt,0),Math.max(0,i-l));return{...t,in:n,out:r,startAt:o}}function Y(t,e=[]){const i=h(t),r=e.reduce((n,o)=>Math.max(n,o.startAt+(o.out-o.in)),0);return Math.max(i,r)}function v(t){return[...new Set(t.map(e=>e.srcIdx))].sort((e,i)=>e-i)}function D(t,e){const i=new Map(e.map((r,n)=>[r,n]));return t.map(r=>({...r,srcIdx:i.get(r.srcIdx)??0}))}function g(t){const e=Math.min(Math.max(Math.round(t),2),4096);return e%2===0?e:e-1}var C=t=>Math.min(Math.max(t,-180),180),R=class{constructor(t=c()){this.videoSources=[],this.audioSources=[],this.listeners=new Set,this.transientBase=null,this.getSnapshot=()=>this.history.present,this.subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e)),this.history=m(t)}getState(){return this.history.present}emit(){const t=this.history.present;for(const e of this.listeners)e(t)}canUndo(){return z(this.history)}canRedo(){return f(this.history)}undo(){this.transientBase=null,this.history=P(this.history),this.emit()}redo(){this.transientBase=null,this.history=F(this.history),this.emit()}applyMut(t,e=!1){if(e)this.transientBase===null&&(this.transientBase=this.history.present),this.history=y(this.history,t(this.transientBase));else{const i=this.transientBase??this.history.present,r=t(i),n=this.transientBase?{...this.history,present:this.transientBase}:this.history;this.history=d(n,r),this.transientBase=null}this.emit()}registerVideoSource(t){const e=this.videoSources.length;this.videoSources.push(t);const i={srcIdx:e,in:0,out:t.duration};return e===0||this.history.present.clips.length===0?(this.transientBase=null,this.history=m({...c(),clips:[i],canvas:{w:g(t.width),h:g(t.height)},poster:{time:Math.min(1,t.duration/2)}}),this.emit()):this.applyMut(r=>({...r,clips:[...r.clips,i]})),e}registerAudioSource(t){const e=this.audioSources.length;return this.audioSources.push(t),this.applyMut(i=>{const r=M({srcIdx:e,startAt:0,in:0,out:t.duration,volume:1},t.duration,h(i.clips));return{...i,audioClips:[...i.audioClips,r]}}),e}getVideoSource(t){return this.videoSources[t]}getAudioSource(t){return this.audioSources[t]}addClipFromSource(t){const e=this.videoSources[t];e&&this.applyMut(i=>({...i,clips:[...i.clips,{srcIdx:t,in:0,out:e.duration}]}))}splitAtPlayhead(t){this.applyMut(e=>({...e,clips:T(e.clips,t)}))}removeClip(t){this.applyMut(e=>({...e,clips:k(e.clips,t)}))}duplicateClip(t){this.applyMut(e=>({...e,clips:O(e.clips,t)}))}reorderClips(t,e){this.applyMut(i=>({...i,clips:V(i.clips,t,e)}))}trimClip(t,e,i,r){this.applyMut(n=>{const o=n.clips[t];if(!o)return n;const a=this.videoSources[o.srcIdx]?.duration??o.out;return{...n,clips:X(n.clips,t,e,i,a)}},r?.transient)}moveAudioClip(t,e,i){this.applyMut(r=>this.patchAudio(r,t,n=>({...n,startAt:e})),i?.transient)}trimAudioClip(t,e,i,r){this.applyMut(n=>this.patchAudio(n,t,o=>{if(e==="in"){const a=i-o.in;return{...o,in:i,startAt:o.startAt+a}}return{...o,out:i}}),r?.transient)}setAudioVolume(t,e,i){this.applyMut(r=>this.patchAudio(r,t,n=>({...n,volume:e}),!1),i?.transient)}removeAudioClip(t){this.applyMut(e=>({...e,audioClips:e.audioClips.filter((i,r)=>r!==t)}))}patchAudio(t,e,i,r=!0){const n=t.audioClips[e];if(!n)return t;let o=i(n);if(r){const a=this.audioSources[n.srcIdx]?.duration??n.out;o=M(o,a,h(t.clips))}return{...t,audioClips:t.audioClips.map((a,S)=>S===e?o:a)}}setCrop(t,e){this.applyMut(i=>({...i,crop:t}),e?.transient)}clearCrop(){this.applyMut(t=>({...t,crop:void 0}))}setScale(t){this.applyMut(e=>({...e,scale:t}))}clearScale(){this.applyMut(t=>({...t,scale:void 0}))}setRotation(t,e){this.applyMut(i=>({...i,rotation:C(t)}),e?.transient)}rotateBy(t){this.applyMut(e=>{let i=e.rotation+t;return i>180&&(i-=360),i<-180&&(i+=360),{...e,rotation:C(i)}})}flipX(){this.applyMut(t=>({...t,flipX:!t.flipX}))}flipY(){this.applyMut(t=>({...t,flipY:!t.flipY}))}setFilter(t,e,i){this.applyMut(r=>({...r,filters:{...r.filters,[t]:e}}),i?.transient)}setFilters(t,e){this.applyMut(i=>({...i,filters:{...i.filters,...t}}),e?.transient)}setFilterPreset(t){this.applyMut(e=>({...e,filterPreset:t}))}addOverlay(t){this.applyMut(e=>({...e,overlays:[...e.overlays??[],t]}))}updateOverlay(t,e,i){this.applyMut(r=>{const n=r.overlays??[];return n[t]?{...r,overlays:n.map((o,a)=>a===t?{...o,...e}:o)}:r},i?.transient)}removeOverlay(t){this.applyMut(e=>({...e,overlays:(e.overlays??[]).filter((i,r)=>r!==t)}))}patch(t,e){e?.transient?(this.transientBase===null&&(this.transientBase=this.history.present),this.history=y(this.history,{...this.transientBase,...t}),this.emit()):this.commit(t)}commit(t){const e=t?{...this.history.present,...t}:this.history.present,i=this.transientBase;this.transientBase=null,this.history=d(i?{...this.history,present:i}:this.history,e),this.emit()}setKeepAudio(t){this.applyMut(e=>({...e,keepAudio:t}))}setPoster(t){this.applyMut(e=>({...e,poster:{time:Math.max(0,t)}}))}totalDuration(){return h(this.history.present.clips)}contentDuration(){const t=this.history.present;return Y(t.clips,t.audioClips)}locate(t){return x(this.history.present.clips,t)}usedVideoSources(){return v(this.history.present.clips)}getExportPlan(){const t=this.history.present,e=v(t.clips),i=[...new Set(t.audioClips.map(n=>n.srcIdx))].sort((n,o)=>n-o),r=new Map(i.map((n,o)=>[n,o]));return{state:{...t,clips:D(t.clips,e),audioClips:t.audioClips.map(n=>({...n,srcIdx:r.get(n.srcIdx)??0}))},videoSrcOrder:e,audioSrcOrder:i}}validate(){return j.safeParse(this.getExportPlan().state)}reset(t=c()){this.transientBase=null,this.history=m(t),this.emit()}};exports.VideoEditorEngine=R;
|
|
1
|
+
"use strict";var s=require("zod"),p={color:s.z.string().max(32),width:s.z.number().positive().max(200)},u={rotation:s.z.number().min(-180).max(180).optional()},A=s.z.discriminatedUnion("type",[s.z.object({type:s.z.literal("pen"),points:s.z.array(s.z.number()).min(4),...p,...u}),s.z.object({type:s.z.literal("line"),x1:s.z.number(),y1:s.z.number(),x2:s.z.number(),y2:s.z.number(),...p,...u}),s.z.object({type:s.z.literal("arrow"),x1:s.z.number(),y1:s.z.number(),x2:s.z.number(),y2:s.z.number(),...p,...u}),s.z.object({type:s.z.literal("rect"),x:s.z.number(),y:s.z.number(),w:s.z.number(),h:s.z.number(),...p,...u}),s.z.object({type:s.z.literal("ellipse"),x:s.z.number(),y:s.z.number(),w:s.z.number(),h:s.z.number(),...p,...u}),s.z.object({type:s.z.literal("text"),x:s.z.number(),y:s.z.number(),text:s.z.string().max(500),color:s.z.string().max(32),fontSize:s.z.number().positive().max(512),...u}),s.z.object({type:s.z.literal("sticker"),x:s.z.number(),y:s.z.number(),w:s.z.number().positive(),h:s.z.number().positive(),emoji:s.z.string().max(16).optional(),src:s.z.string().optional(),...u})]),B=s.z.object({srcIdx:s.z.number().int().min(0).max(7),in:s.z.number().min(0),out:s.z.number().min(0)}),I=s.z.object({srcIdx:s.z.number().int().min(0).max(2),startAt:s.z.number().min(0),in:s.z.number().min(0),out:s.z.number().min(0),volume:s.z.number().min(0).max(2)}),w=s.z.object({type:s.z.enum(["none","fade","slide","wipe","flip","clockWipe","star","circle","rectangle"]).default("none"),duration:s.z.number().min(0).max(2).default(.4)}),j=s.z.object({clips:s.z.array(B).min(1).max(50),audioClips:s.z.array(I).max(8).default([]),canvas:s.z.object({w:s.z.number().int().min(2).max(4096),h:s.z.number().int().min(2).max(4096)}),crop:s.z.object({x:s.z.number().min(0),y:s.z.number().min(0),width:s.z.number().positive(),height:s.z.number().positive()}).optional(),scale:s.z.object({width:s.z.number().positive(),height:s.z.number().positive(),fit:s.z.enum(["contain","cover","force"])}).optional(),rotation:s.z.number().min(-180).max(180).default(0),flipX:s.z.boolean().default(!1),flipY:s.z.boolean().default(!1),filters:s.z.object({brightness:s.z.number().min(-1).max(1),contrast:s.z.number().min(-1).max(1),saturation:s.z.number().min(-1).max(1),gamma:s.z.number().min(-1).max(1).default(0)}).default({brightness:0,contrast:0,saturation:0,gamma:0}),filterPreset:s.z.string().max(32).optional(),overlays:s.z.array(A).max(200).optional(),transitions:s.z.array(w).max(49).default([]),keepAudio:s.z.boolean().default(!0),poster:s.z.object({time:s.z.number().min(0)}).optional()}).superRefine((t,i)=>{t.clips.forEach((t,e)=>{t.out<=t.in&&i.addIssue({code:s.z.ZodIssueCode.custom,message:`clips[${e}].out 必须大于 in`,path:["clips",e,"out"]})}),t.audioClips?.forEach((t,e)=>{t.out<=t.in&&i.addIssue({code:s.z.ZodIssueCode.custom,message:`audioClips[${e}].out 必须大于 in`,path:["audioClips",e,"out"]})}),(t.canvas.w%2!=0||t.canvas.h%2!=0)&&i.addIssue({code:s.z.ZodIssueCode.custom,message:"canvas 宽高必须为偶数",path:["canvas"]})});function c(){return{clips:[],audioClips:[],canvas:{w:2,h:2},rotation:0,flipX:!1,flipY:!1,filters:{brightness:0,contrast:0,saturation:0,gamma:0},transitions:[],keepAudio:!0}}var E=100;function m(t){return{past:[],present:t,future:[]}}function d(t,s){if(s===t.present)return t;const i=[...t.past,t.present];return i.length>E&&i.shift(),{past:i,present:s,future:[]}}function y(t,s){return s===t.present?t:{...t,present:s}}function z(t){return t.past.length>0}function f(t){return t.future.length>0}function P(t){return z(t)?{past:t.past.slice(0,-1),present:t.past[t.past.length-1],future:[t.present,...t.future]}:t}function F(t){if(!f(t))return t;const[s,...i]=t.future;return{past:[...t.past,t.present],present:s,future:i}}var l=.1;function b(t){return t.out-t.in}function h(t){return t.reduce((t,s)=>t+b(s),0)}function x(t,s){if(!t.length||s<0)return null;let i=0;for(let e=0;e<t.length;e++){const r=b(t[e]);if(s<i+r)return{idx:e,srcTime:t[e].in+(s-i)};i+=r}if(Math.abs(s-i)<1e-9||s<=i){const s=t.length-1;return{idx:s,srcTime:t[s].out}}return null}function T(t,s){const i=x(t,s);if(!i)return t;const e=t[i.idx];return i.srcTime<e.in+l||i.srcTime>e.out-l?t:[...t.slice(0,i.idx),{...e,out:i.srcTime},{...e,in:i.srcTime},...t.slice(i.idx+1)]}function k(t,s){return t.length<=1||!t[s]?t:t.filter((t,i)=>i!==s)}function O(t,s){const i=t[s];return i?[...t.slice(0,s+1),{...i},...t.slice(s+1)]:t}function V(t,s,i){if(s===i||!t[s]||i<0||i>=t.length)return t;const e=[...t],[r]=e.splice(s,1);return e.splice(i,0,r),e}function X(t,s,i,e,r){if(!t[s])return t;const n=t.map(t=>({...t}));return"in"===i?n[s].in=Math.min(Math.max(e,0),n[s].out-l):n[s].out=Math.max(Math.min(e,r),n[s].in+l),n}function M(t,s,i){const e=Math.max(Math.min(t.out,s),l),r=Math.min(Math.max(t.in,0),e-l),n=Math.min(Math.max(t.startAt,0),Math.max(0,i-l));return{...t,in:r,out:e,startAt:n}}function Y(t,s=[]){const i=h(t),e=s.reduce((t,s)=>Math.max(t,s.startAt+(s.out-s.in)),0);return Math.max(i,e)}function v(t){return[...new Set(t.map(t=>t.srcIdx))].sort((t,s)=>t-s)}function D(t,s){const i=new Map(s.map((t,s)=>[t,s]));return t.map(t=>({...t,srcIdx:i.get(t.srcIdx)??0}))}function g(t){const s=Math.min(Math.max(Math.round(t),2),4096);return s%2==0?s:s-1}var C=t=>Math.min(Math.max(t,-180),180),R=class{constructor(t=c()){this.videoSources=[],this.audioSources=[],this.listeners=new Set,this.transientBase=null,this.getSnapshot=()=>this.history.present,this.subscribe=t=>(this.listeners.add(t),()=>this.listeners.delete(t)),this.history=m(t)}getState(){return this.history.present}emit(){const t=this.history.present;for(const s of this.listeners)s(t)}canUndo(){return z(this.history)}canRedo(){return f(this.history)}undo(){this.transientBase=null,this.history=P(this.history),this.emit()}redo(){this.transientBase=null,this.history=F(this.history),this.emit()}applyMut(t,s=!1){if(s)null===this.transientBase&&(this.transientBase=this.history.present),this.history=y(this.history,t(this.transientBase));else{const s=t(this.transientBase??this.history.present),i=this.transientBase?{...this.history,present:this.transientBase}:this.history;this.history=d(i,s),this.transientBase=null}this.emit()}registerVideoSource(t){const s=this.videoSources.length;this.videoSources.push(t);const i={srcIdx:s,in:0,out:t.duration};return 0===s||0===this.history.present.clips.length?(this.transientBase=null,this.history=m({...c(),clips:[i],canvas:{w:g(t.width),h:g(t.height)},poster:{time:Math.min(1,t.duration/2)}}),this.emit()):this.applyMut(t=>({...t,clips:[...t.clips,i]})),s}registerAudioSource(t){const s=this.audioSources.length;return this.audioSources.push(t),this.applyMut(i=>{const e=M({srcIdx:s,startAt:0,in:0,out:t.duration,volume:1},t.duration,h(i.clips));return{...i,audioClips:[...i.audioClips,e]}}),s}getVideoSource(t){return this.videoSources[t]}getAudioSource(t){return this.audioSources[t]}addClipFromSource(t){const s=this.videoSources[t];s&&this.applyMut(i=>({...i,clips:[...i.clips,{srcIdx:t,in:0,out:s.duration}]}))}splitAtPlayhead(t){this.applyMut(s=>({...s,clips:T(s.clips,t)}))}removeClip(t){this.applyMut(s=>({...s,clips:k(s.clips,t)}))}duplicateClip(t){this.applyMut(s=>({...s,clips:O(s.clips,t)}))}reorderClips(t,s){this.applyMut(i=>({...i,clips:V(i.clips,t,s)}))}trimClip(t,s,i,e){this.applyMut(e=>{const r=e.clips[t];if(!r)return e;const n=this.videoSources[r.srcIdx]?.duration??r.out;return{...e,clips:X(e.clips,t,s,i,n)}},e?.transient)}moveAudioClip(t,s,i){this.applyMut(i=>this.patchAudio(i,t,t=>({...t,startAt:s})),i?.transient)}trimAudioClip(t,s,i,e){this.applyMut(e=>this.patchAudio(e,t,t=>{if("in"===s){const s=i-t.in;return{...t,in:i,startAt:t.startAt+s}}return{...t,out:i}}),e?.transient)}setAudioVolume(t,s,i){this.applyMut(i=>this.patchAudio(i,t,t=>({...t,volume:s}),!1),i?.transient)}removeAudioClip(t){this.applyMut(s=>({...s,audioClips:s.audioClips.filter((s,i)=>i!==t)}))}patchAudio(t,s,i,e=!0){const r=t.audioClips[s];if(!r)return t;let n=i(r);if(e){const s=this.audioSources[r.srcIdx]?.duration??r.out;n=M(n,s,h(t.clips))}return{...t,audioClips:t.audioClips.map((t,i)=>i===s?n:t)}}setCrop(t,s){this.applyMut(s=>({...s,crop:t}),s?.transient)}clearCrop(){this.applyMut(t=>({...t,crop:void 0}))}setScale(t){this.applyMut(s=>({...s,scale:t}))}clearScale(){this.applyMut(t=>({...t,scale:void 0}))}setRotation(t,s){this.applyMut(s=>({...s,rotation:C(t)}),s?.transient)}rotateBy(t){this.applyMut(s=>{let i=s.rotation+t;return i>180&&(i-=360),i<-180&&(i+=360),{...s,rotation:C(i)}})}flipX(){this.applyMut(t=>({...t,flipX:!t.flipX}))}flipY(){this.applyMut(t=>({...t,flipY:!t.flipY}))}setFilter(t,s,i){this.applyMut(i=>({...i,filters:{...i.filters,[t]:s}}),i?.transient)}setFilters(t,s){this.applyMut(s=>({...s,filters:{...s.filters,...t}}),s?.transient)}setFilterPreset(t){this.applyMut(s=>({...s,filterPreset:t}))}addOverlay(t){this.applyMut(s=>({...s,overlays:[...s.overlays??[],t]}))}updateOverlay(t,s,i){this.applyMut(i=>{const e=i.overlays??[];return e[t]?{...i,overlays:e.map((i,e)=>e===t?{...i,...s}:i)}:i},i?.transient)}removeOverlay(t){this.applyMut(s=>({...s,overlays:(s.overlays??[]).filter((s,i)=>i!==t)}))}patch(t,s){s?.transient?(null===this.transientBase&&(this.transientBase=this.history.present),this.history=y(this.history,{...this.transientBase,...t}),this.emit()):this.commit(t)}commit(t){const s=t?{...this.history.present,...t}:this.history.present,i=this.transientBase;this.transientBase=null,this.history=d(i?{...this.history,present:i}:this.history,s),this.emit()}setKeepAudio(t){this.applyMut(s=>({...s,keepAudio:t}))}setPoster(t){this.applyMut(s=>({...s,poster:{time:Math.max(0,t)}}))}totalDuration(){return h(this.history.present.clips)}contentDuration(){const t=this.history.present;return Y(t.clips,t.audioClips)}locate(t){return x(this.history.present.clips,t)}usedVideoSources(){return v(this.history.present.clips)}getExportPlan(){const t=this.history.present,s=v(t.clips),i=[...new Set(t.audioClips.map(t=>t.srcIdx))].sort((t,s)=>t-s),e=new Map(i.map((t,s)=>[t,s]));return{state:{...t,clips:D(t.clips,s),audioClips:t.audioClips.map(t=>({...t,srcIdx:e.get(t.srcIdx)??0}))},videoSrcOrder:s,audioSrcOrder:i}}validate(){return j.safeParse(this.getExportPlan().state)}reset(t=c()){this.transientBase=null,this.history=m(t),this.emit()}};exports.VideoEditorEngine=R;
|
package/core/dist/engine.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createHistory as
|
|
1
|
+
import{createHistory as t,defaultVideoEditState as s,canUndo as i,canRedo as e,undo as r,redo as a,replacePresent as o,pushHistory as n,clampAudioClip as p,totalDuration as h,splitAtOutput as l,removeClip as u,duplicateClip as c,reorderClips as d,trimClipEdge as y,contentDuration as m,locateOutput as M,usedVideoSrcIndices as S,remapSrcIndices as v,VideoEditState as C}from"./chunk-MGKYVYOH.js";function f(t){const s=Math.min(Math.max(Math.round(t),2),4096);return s%2==0?s:s-1}var A=t=>Math.min(Math.max(t,-180),180),B=class{constructor(i=s()){this.videoSources=[],this.audioSources=[],this.listeners=new Set,this.transientBase=null,this.getSnapshot=()=>this.history.present,this.subscribe=t=>(this.listeners.add(t),()=>this.listeners.delete(t)),this.history=t(i)}getState(){return this.history.present}emit(){const t=this.history.present;for(const s of this.listeners)s(t)}canUndo(){return i(this.history)}canRedo(){return e(this.history)}undo(){this.transientBase=null,this.history=r(this.history),this.emit()}redo(){this.transientBase=null,this.history=a(this.history),this.emit()}applyMut(t,s=!1){if(s)null===this.transientBase&&(this.transientBase=this.history.present),this.history=o(this.history,t(this.transientBase));else{const s=t(this.transientBase??this.history.present),i=this.transientBase?{...this.history,present:this.transientBase}:this.history;this.history=n(i,s),this.transientBase=null}this.emit()}registerVideoSource(i){const e=this.videoSources.length;this.videoSources.push(i);const r={srcIdx:e,in:0,out:i.duration};return 0===e||0===this.history.present.clips.length?(this.transientBase=null,this.history=t({...s(),clips:[r],canvas:{w:f(i.width),h:f(i.height)},poster:{time:Math.min(1,i.duration/2)}}),this.emit()):this.applyMut(t=>({...t,clips:[...t.clips,r]})),e}registerAudioSource(t){const s=this.audioSources.length;return this.audioSources.push(t),this.applyMut(i=>{const e=new Set((i.audioClips??[]).map((t,s)=>Number.isInteger(t?.track)&&t.track>=0?t.track:s));let r=0;for(;e.has(r);)r+=1;const a=p({srcIdx:s,track:r,startAt:0,in:0,out:t.duration,volume:1},t.duration,h(i.clips));return{...i,audioClips:[...i.audioClips,a]}}),s}getVideoSource(t){return this.videoSources[t]}getAudioSource(t){return this.audioSources[t]}addClipFromSource(t){const s=this.videoSources[t];s&&this.applyMut(i=>({...i,clips:[...i.clips,{srcIdx:t,in:0,out:s.duration}]}))}splitAtPlayhead(t){this.applyMut(s=>({...s,clips:l(s.clips,t)}))}removeClip(t){this.applyMut(s=>({...s,clips:u(s.clips,t)}))}duplicateClip(t){this.applyMut(s=>({...s,clips:c(s.clips,t)}))}reorderClips(t,s){this.applyMut(i=>({...i,clips:d(i.clips,t,s)}))}trimClip(t,s,i,e){this.applyMut(e=>{const r=e.clips[t];if(!r)return e;const a=this.videoSources[r.srcIdx]?.duration??r.out;return{...e,clips:y(e.clips,t,s,i,a)}},e?.transient)}moveAudioClip(t,s,i){this.applyMut(i=>this.patchAudio(i,t,t=>({...t,startAt:s})),i?.transient)}trimAudioClip(t,s,i,e){this.applyMut(e=>this.patchAudio(e,t,t=>{if("in"===s){const s=i-t.in;return{...t,in:i,startAt:t.startAt+s}}return{...t,out:i}}),e?.transient)}setAudioVolume(t,s,i){this.applyMut(i=>this.patchAudio(i,t,t=>({...t,volume:s}),!1),i?.transient)}removeAudioClip(t){this.applyMut(s=>({...s,audioClips:s.audioClips.filter((s,i)=>i!==t)}))}patchAudio(t,s,i,e=!0){const r=t.audioClips[s];if(!r)return t;let a=i(r);if(e){const s=this.audioSources[r.srcIdx]?.duration??r.out;a=p(a,s,h(t.clips))}return{...t,audioClips:t.audioClips.map((t,i)=>i===s?a:t)}}setCrop(t,s){this.applyMut(s=>({...s,crop:t}),s?.transient)}clearCrop(){this.applyMut(t=>({...t,crop:void 0}))}setScale(t){this.applyMut(s=>({...s,scale:t}))}clearScale(){this.applyMut(t=>({...t,scale:void 0}))}setRotation(t,s){this.applyMut(s=>({...s,rotation:A(t)}),s?.transient)}rotateBy(t){this.applyMut(s=>{let i=s.rotation+t;return i>180&&(i-=360),i<-180&&(i+=360),{...s,rotation:A(i)}})}flipX(){this.applyMut(t=>({...t,flipX:!t.flipX}))}flipY(){this.applyMut(t=>({...t,flipY:!t.flipY}))}setFilter(t,s,i){this.applyMut(i=>({...i,filters:{...i.filters,[t]:s}}),i?.transient)}setFilters(t,s){this.applyMut(s=>({...s,filters:{...s.filters,...t}}),s?.transient)}setFilterPreset(t){this.applyMut(s=>({...s,filterPreset:t}))}addOverlay(t){this.applyMut(s=>({...s,overlays:[...s.overlays??[],t]}))}updateOverlay(t,s,i){this.applyMut(i=>{const e=i.overlays??[];return e[t]?{...i,overlays:e.map((i,e)=>e===t?{...i,...s}:i)}:i},i?.transient)}removeOverlay(t){this.applyMut(s=>({...s,overlays:(s.overlays??[]).filter((s,i)=>i!==t)}))}patch(t,s){s?.transient?(null===this.transientBase&&(this.transientBase=this.history.present),this.history=o(this.history,{...this.transientBase,...t}),this.emit()):this.commit(t)}commit(t){const s=t?{...this.history.present,...t}:this.history.present,i=this.transientBase;this.transientBase=null,this.history=n(i?{...this.history,present:i}:this.history,s),this.emit()}setKeepAudio(t){this.applyMut(s=>({...s,keepAudio:t}))}setPoster(t){this.applyMut(s=>({...s,poster:{time:Math.max(0,t)}}))}totalDuration(){return h(this.history.present.clips)}contentDuration(){const t=this.history.present;return m(t.clips,t.audioClips,t.overlays)}locate(t){return M(this.history.present.clips,t)}usedVideoSources(){return S(this.history.present.clips)}getExportPlan(){const t=this.history.present,s=S(t.clips),i=[...new Set(t.audioClips.map(t=>t.srcIdx))].sort((t,s)=>t-s),e=new Map(i.map((t,s)=>[t,s]));return{state:{...t,clips:v(t.clips,s),audioClips:t.audioClips.map(t=>({...t,srcIdx:e.get(t.srcIdx)??0}))},videoSrcOrder:s,audioSrcOrder:i}}validate(){return C.safeParse(this.getExportPlan().state)}reset(i=s()){this.transientBase=null,this.history=t(i),this.emit()}};export{B as VideoEditorEngine};
|