@bylqwjc/media-editor-video 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{mountVideoEditor as _r}from"./legacy.js";import{FILTER_PRESETS as jr,buildFilterCss as Yr,evenize as Vt,outputSize as jo}from"@media-editor/core";import{fitStickerBox as Vr,getOverlayRotation as un,overlayBBox as Gt,scaleOverlay as Yo,translateOverlay as Vo}from"@media-editor/core/browser";import{VideoEditorEngine as Xr}from"@media-editor/core/engine";import{VideoEditorEngine as Ka}from"@media-editor/core/engine";const
|
|
1
|
+
import{mountVideoEditor as _r}from"./legacy.js";import{FILTER_PRESETS as jr,buildFilterCss as Yr,evenize as Vt,outputSize as jo}from"@media-editor/core";import{fitStickerBox as Vr,getOverlayRotation as un,overlayBBox as Gt,scaleOverlay as Yo,translateOverlay as Vo}from"@media-editor/core/browser";import{VideoEditorEngine as Xr}from"@media-editor/core/engine";import{VideoEditorEngine as Ka}from"@media-editor/core/engine";const Wn='-apple-system, "PingFang SC", "Microsoft YaHei", sans-serif',Xo=["Arial","Segoe UI","Microsoft YaHei","Microsoft JhengHei","PingFang SC","Helvetica","Verdana","Tahoma","Trebuchet MS","Georgia","Times New Roman","Courier New","NSimSun","SimSun","SimHei","KaiTi","FangSong","Noto Sans SC"],qr={"Microsoft YaHei":"\u5FAE\u8F6F\u96C5\u9ED1","Microsoft JhengHei":"\u5FAE\u8F6F\u6B63\u9ED1\u4F53","PingFang SC":"\u82F9\u65B9",SimSun:"\u5B8B\u4F53",NSimSun:"\u65B0\u5B8B\u4F53",SimHei:"\u9ED1\u4F53",KaiTi:"\u6977\u4F53",FangSong:"\u4EFF\u5B8B","Noto Sans SC":"\u601D\u6E90\u9ED1\u4F53","Songti SC":"\u5B8B\u4F53-\u7B80","Heiti SC":"\u9ED1\u4F53-\u7B80","Kaiti SC":"\u6977\u4F53-\u7B80",STSong:"\u534E\u6587\u5B8B\u4F53",STHeiti:"\u534E\u6587\u9ED1\u4F53",STKaiti:"\u534E\u6587\u6977\u4F53",STFangsong:"\u534E\u6587\u4EFF\u5B8B",STZhongsong:"\u534E\u6587\u4E2D\u5B8B",YouYuan:"\u5E7C\u5706",LiSu:"\u96B6\u4E66"},Wr=["microsoft yahei","microsoft jhenghei","pingfang","simsun","nsimsun","simhei","kaiti","fangsong","noto sans sc","songti","heiti","stsong","stheiti","stkaiti","stfangsong","stzhongsong","youyuan","lisu"],qo={heading:{text:"Heading and some body",fontSize:120,width:600,fontWeight:"700",textAlign:"center",color:"#ffffff",backgroundColor:"transparent",borderColor:"#000000",borderWidth:0,boxShadow:{color:"rgba(0,0,0,0.35)",x:0,y:4,blur:18}},subtitle:{text:"Subtitle line",fontSize:72,width:560,fontWeight:"600",textAlign:"center",color:"#ffffff",backgroundColor:"transparent",borderColor:"#000000",borderWidth:0,boxShadow:{color:"rgba(0,0,0,0.28)",x:0,y:2,blur:12}},label:{text:"Label",fontSize:44,width:300,fontWeight:"700",textAlign:"center",color:"#ffffff",backgroundColor:"rgba(8,8,10,0.72)",borderColor:"#000000",borderWidth:0,boxShadow:{color:"rgba(0,0,0,0.18)",x:0,y:2,blur:8},paddingX:24,paddingY:16}},vo=[{key:"none",label:"Cut",short:"Cut",duration:0},{key:"fade",label:"Fade",short:"Fade",duration:.45},{key:"slide",label:"Slide",short:"Slide",duration:.45},{key:"wipe",label:"Wipe",short:"Wipe",duration:.45},{key:"flip",label:"Flip",short:"Flip",duration:.35},{key:"clockWipe",label:"Clock",short:"Clock",duration:.5},{key:"star",label:"Star",short:"Star",duration:.35},{key:"circle",label:"Circle",short:"Circle",duration:.45},{key:"rectangle",label:"Rectangle",short:"Rect",duration:.45}];let Wo=!1,Ko=!1;const Ht="me-video-timeline-selectionchange",Uo="Aa Sample 123";let Kn=null;function Qt(){if(Wo||typeof document>"u")return;const e=document.createElement("style");e.id="me-video-text-enhancer-style",e.textContent=`
|
|
2
2
|
.me-video-inspector-rail {
|
|
3
3
|
flex: 0 0 min(380px, 32vw);
|
|
4
4
|
min-width: 320px;
|
|
@@ -30,7 +30,7 @@ import{mountVideoEditor as _r}from"./legacy.js";import{FILTER_PRESETS as jr,buil
|
|
|
30
30
|
color: var(--me-fg, #ededf0);
|
|
31
31
|
box-shadow: none;
|
|
32
32
|
backdrop-filter: none;
|
|
33
|
-
font: 13px/1.45 ${
|
|
33
|
+
font: 13px/1.45 ${Wn};
|
|
34
34
|
box-sizing: border-box;
|
|
35
35
|
overflow: auto;
|
|
36
36
|
}
|
|
@@ -197,7 +197,7 @@ import{mountVideoEditor as _r}from"./legacy.js";import{FILTER_PRESETS as jr,buil
|
|
|
197
197
|
background: var(--me-surface, #141416);
|
|
198
198
|
color: var(--me-fg-muted, #9a9aa3);
|
|
199
199
|
cursor: pointer;
|
|
200
|
-
font: 12px/1.2 ${
|
|
200
|
+
font: 12px/1.2 ${Wn};
|
|
201
201
|
box-shadow: inset 0 0 0 1px transparent;
|
|
202
202
|
transition: transform 120ms ease, color 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
|
|
203
203
|
}
|
|
@@ -394,7 +394,7 @@ import{mountVideoEditor as _r}from"./legacy.js";import{FILTER_PRESETS as jr,buil
|
|
|
394
394
|
border-radius: 10px;
|
|
395
395
|
background: var(--me-chip, #f1f1f3);
|
|
396
396
|
color: var(--me-fg, #0a0a0a);
|
|
397
|
-
font: 600 14px/1 ${
|
|
397
|
+
font: 600 14px/1 ${Wn};
|
|
398
398
|
cursor: pointer;
|
|
399
399
|
display: inline-flex;
|
|
400
400
|
align-items: center;
|
|
@@ -2032,7 +2032,7 @@ import{mountVideoEditor as _r}from"./legacy.js";import{FILTER_PRESETS as jr,buil
|
|
|
2032
2032
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
2033
2033
|
}
|
|
2034
2034
|
}
|
|
2035
|
-
`,document.head.appendChild(e),Ko=!0}function ae(e,t,n){return Math.min(Math.max(e,t),n)}function In(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 Kn(e="auto"){return e!=="auto"?e:typeof window<"u"&&window.matchMedia?.("(prefers-color-scheme: light)").matches?"light":"dark"}function Go(e){if(!e)return null;const t=String(e).toLowerCase();return t==="zh-hant"||/^zh-(tw|hk|mo)/.test(t)?"zh-Hant":t==="zh"||t.startsWith("zh-")?"zh":(t.startsWith("en"),"en")}function Xt(e){const t=Go(e);return t||(typeof navigator<"u"?Go(navigator.language)??"en":"en")}const ho={en:{untitledText:"Untitled text",textPresets:{heading:"Heading and some body",subtitle:"Subtitle line",label:"Label"},text:{tool:"Text",addText:"Add text",moveOnCanvas:"Move on canvas",close:"Close",hint:"Match the reference text styling here first. This version renders text as a full-length overlay, so font, shadow, stroke, background and alignment will export exactly.",empty:"No text overlay yet. Add one to start editing.",heading:"Heading",subtitle:"Subtitle",label:"Label",placeholder:"Type your text",content:"Content",font:"Font",weight:"Weight",fontSize:"Font Size",boxWidth:"Box Width",color:"Color",background:"Background",stroke:"Stroke",strokeColor:"Stroke Color",opacity:"Opacity",shadowBlur:"Shadow Blur",align:"Align",duplicate:"Duplicate",delete:"Delete",addLabel:"Add label"},transitions:{tool:"Transitions",title:"Transitions",fadeAll:"Fade all",close:"Close",hint:"Pick a cut between clips on the timeline. These transitions are exported through ffmpeg xfade/acrossfade, so the result is baked into the final video.",empty:"Need at least 2 clips to place a transition. Split or duplicate a clip first.",duration:"Duration",clearSelected:"Clear selected",clearAll:"Clear all",cut:"Cut",instantCut:"Instant cut",selection:(e,t)=>`Between clip ${e} and clip ${t}`,selectionEmpty:"Open Trim to place transitions on the timeline.",boundary:(e,t,n)=>`${e}\u2192${t} ${n}`,boundaryTitle:(e,t)=>`Between clip ${e} and clip ${t}`,markerTitle:(e,t,n,r)=>`Clip ${e} \u2192 ${t}: ${n}${r?` (${r})`:""}`,options:{none:{label:"Cut",short:"Cut"},fade:{label:"Fade",short:"Fade"},slide:{label:"Slide",short:"Slide"},wipe:{label:"Wipe",short:"Wipe"},flip:{label:"Flip",short:"Flip"},clockWipe:{label:"Clock",short:"Clock"},star:{label:"Star",short:"Star"},circle:{label:"Circle",short:"Circle"},rectangle:{label:"Rectangle",short:"Rect"}}}},zh:{untitledText:"\u672A\u547D\u540D\u6587\u5B57",textPresets:{heading:"\u4E3B\u6807\u9898\u548C\u6B63\u6587",subtitle:"\u5B57\u5E55\u6587\u6848",label:"\u6807\u7B7E"},text:{tool:"\u6587\u5B57",addText:"\u6DFB\u52A0\u6587\u5B57",moveOnCanvas:"\u753B\u5E03\u5B9A\u4F4D",close:"\u5173\u95ED",hint:"\u5148\u5728\u8FD9\u91CC\u628A\u6587\u5B57\u6837\u5F0F\u8C03\u5230\u548C\u53C2\u8003\u4E00\u81F4\u3002\u8BE5\u7248\u672C\u4F1A\u628A\u6587\u5B57\u4F5C\u4E3A\u5B8C\u6574\u8986\u76D6\u5C42\u5BFC\u51FA\uFF0C\u5B57\u4F53\u3001\u9634\u5F71\u3001\u63CF\u8FB9\u3001\u80CC\u666F\u548C\u5BF9\u9F50\u65B9\u5F0F\u90FD\u4F1A\u88AB\u51C6\u786E\u4FDD\u7559\u3002",empty:"\u8FD8\u6CA1\u6709\u6587\u5B57\u56FE\u5C42\uFF0C\u5148\u6DFB\u52A0\u4E00\u4E2A\u5F00\u59CB\u7F16\u8F91\u3002",heading:"\u6807\u9898",subtitle:"\u5B57\u5E55",label:"\u6807\u7B7E",placeholder:"\u8F93\u5165\u6587\u5B57\u5185\u5BB9",content:"\u5185\u5BB9",font:"\u5B57\u4F53",weight:"\u5B57\u91CD",fontSize:"\u5B57\u53F7",boxWidth:"\u6587\u672C\u5BBD\u5EA6",color:"\u989C\u8272",background:"\u80CC\u666F",stroke:"\u63CF\u8FB9",strokeColor:"\u63CF\u8FB9\u989C\u8272",opacity:"\u900F\u660E\u5EA6",shadowBlur:"\u9634\u5F71\u6A21\u7CCA",align:"\u5BF9\u9F50",duplicate:"\u590D\u5236",delete:"\u5220\u9664",addLabel:"\u6DFB\u52A0\u6807\u7B7E"},transitions:{tool:"\u8F6C\u573A",title:"\u8F6C\u573A",fadeAll:"\u5168\u90E8\u6DE1\u5165\u6DE1\u51FA",close:"\u5173\u95ED",hint:"\u5728\u65F6\u95F4\u8F74\u4E0A\u9009\u62E9\u4E24\u4E2A\u7247\u6BB5\u4E4B\u95F4\u7684\u5207\u70B9\u3002\u8F6C\u573A\u4F1A\u901A\u8FC7 ffmpeg \u7684 xfade/acrossfade \u70D8\u7119\u8FDB\u6700\u7EC8\u5BFC\u51FA\u89C6\u9891\u3002",empty:"\u81F3\u5C11\u9700\u8981 2 \u4E2A\u7247\u6BB5\u624D\u80FD\u8BBE\u7F6E\u8F6C\u573A\u3002\u53EF\u4EE5\u5148\u5206\u5272\u6216\u590D\u5236\u7247\u6BB5\u3002",duration:"\u65F6\u957F",clearSelected:"\u6E05\u9664\u5F53\u524D",clearAll:"\u6E05\u9664\u5168\u90E8",cut:"\u786C\u5207",instantCut:"\u76F4\u63A5\u5207\u6362",selection:(e,t)=>`\u7B2C ${e} \u6BB5 \u2192 \u7B2C ${t} \u6BB5`,selectionEmpty:"\u6253\u5F00\u526A\u8F91\u5DE5\u5177\u540E\uFF0C\u53EF\u5728\u65F6\u95F4\u8F74\u4E0A\u8BBE\u7F6E\u8F6C\u573A\u3002",boundary:(e,t,n)=>`${e}\u2192${t} ${n}`,boundaryTitle:(e,t)=>`\u7B2C ${e} \u6BB5\u5230\u7B2C ${t} \u6BB5\u4E4B\u95F4`,markerTitle:(e,t,n,r)=>`\u7B2C ${e} \u6BB5 \u2192 \u7B2C ${t} \u6BB5\uFF1A${n}${r?`\uFF08${r}\uFF09`:""}`,options:{none:{label:"\u786C\u5207",short:"\u786C\u5207"},fade:{label:"\u6DE1\u5316",short:"\u6DE1\u5316"},slide:{label:"\u6ED1\u52A8",short:"\u6ED1\u52A8"},wipe:{label:"\u64E6\u9664",short:"\u64E6\u9664"},flip:{label:"\u7FFB\u8F6C",short:"\u7FFB\u8F6C"},clockWipe:{label:"\u65F6\u949F",short:"\u65F6\u949F"},star:{label:"\u661F\u5F62",short:"\u661F\u5F62"},circle:{label:"\u5706\u5F62",short:"\u5706\u5F62"},rectangle:{label:"\u77E9\u5F62",short:"\u77E9\u5F62"}}}},"zh-Hant":{untitledText:"\u672A\u547D\u540D\u6587\u5B57",textPresets:{heading:"\u4E3B\u6A19\u984C\u548C\u6B63\u6587",subtitle:"\u5B57\u5E55\u6587\u6848",label:"\u6A19\u7C64"},text:{tool:"\u6587\u5B57",addText:"\u65B0\u589E\u6587\u5B57",moveOnCanvas:"\u756B\u5E03\u5B9A\u4F4D",close:"\u95DC\u9589",hint:"\u5148\u5728\u9019\u88E1\u628A\u6587\u5B57\u6A23\u5F0F\u8ABF\u5230\u548C\u53C3\u8003\u4E00\u81F4\u3002\u9019\u500B\u7248\u672C\u6703\u628A\u6587\u5B57\u4F5C\u70BA\u5B8C\u6574\u8986\u84CB\u5C64\u5C0E\u51FA\uFF0C\u5B57\u9AD4\u3001\u9670\u5F71\u3001\u63CF\u908A\u3001\u80CC\u666F\u548C\u5C0D\u9F4A\u65B9\u5F0F\u90FD\u6703\u88AB\u6E96\u78BA\u4FDD\u7559\u3002",empty:"\u9084\u6C92\u6709\u6587\u5B57\u5716\u5C64\uFF0C\u5148\u65B0\u589E\u4E00\u500B\u958B\u59CB\u7DE8\u8F2F\u3002",heading:"\u6A19\u984C",subtitle:"\u5B57\u5E55",label:"\u6A19\u7C64",placeholder:"\u8F38\u5165\u6587\u5B57\u5167\u5BB9",content:"\u5167\u5BB9",font:"\u5B57\u9AD4",weight:"\u5B57\u91CD",fontSize:"\u5B57\u7D1A",boxWidth:"\u6587\u5B57\u5BEC\u5EA6",color:"\u984F\u8272",background:"\u80CC\u666F",stroke:"\u63CF\u908A",strokeColor:"\u63CF\u908A\u984F\u8272",opacity:"\u900F\u660E\u5EA6",shadowBlur:"\u9670\u5F71\u6A21\u7CCA",align:"\u5C0D\u9F4A",duplicate:"\u8907\u88FD",delete:"\u522A\u9664",addLabel:"\u65B0\u589E\u6A19\u7C64"},transitions:{tool:"\u8F49\u5834",title:"\u8F49\u5834",fadeAll:"\u5168\u90E8\u6DE1\u5316",close:"\u95DC\u9589",hint:"\u5728\u6642\u9593\u8EF8\u4E0A\u9078\u64C7\u5169\u500B\u7247\u6BB5\u4E4B\u9593\u7684\u5207\u9EDE\u3002\u8F49\u5834\u6703\u900F\u904E ffmpeg \u7684 xfade/acrossfade \u70D8\u7119\u9032\u6700\u7D42\u5C0E\u51FA\u5F71\u7247\u3002",empty:"\u81F3\u5C11\u9700\u8981 2 \u500B\u7247\u6BB5\u624D\u80FD\u8A2D\u5B9A\u8F49\u5834\u3002\u53EF\u4EE5\u5148\u5206\u5272\u6216\u8907\u88FD\u7247\u6BB5\u3002",duration:"\u6642\u9577",clearSelected:"\u6E05\u9664\u76EE\u524D",clearAll:"\u6E05\u9664\u5168\u90E8",cut:"\u786C\u5207",instantCut:"\u76F4\u63A5\u5207\u63DB",selection:(e,t)=>`\u7B2C ${e} \u6BB5 \u2192 \u7B2C ${t} \u6BB5`,selectionEmpty:"\u6253\u958B\u526A\u8F2F\u5DE5\u5177\u5F8C\uFF0C\u53EF\u5728\u6642\u9593\u8EF8\u4E0A\u8A2D\u5B9A\u8F49\u5834\u3002",boundary:(e,t,n)=>`${e}\u2192${t} ${n}`,boundaryTitle:(e,t)=>`\u7B2C ${e} \u6BB5\u5230\u7B2C ${t} \u6BB5\u4E4B\u9593`,markerTitle:(e,t,n,r)=>`\u7B2C ${e} \u6BB5 \u2192 \u7B2C ${t} \u6BB5\uFF1A${n}${r?`\uFF08${r}\uFF09`:""}`,options:{none:{label:"\u786C\u5207",short:"\u786C\u5207"},fade:{label:"\u6DE1\u5316",short:"\u6DE1\u5316"},slide:{label:"\u6ED1\u52D5",short:"\u6ED1\u52D5"},wipe:{label:"\u64E6\u9664",short:"\u64E6\u9664"},flip:{label:"\u7FFB\u8F49",short:"\u7FFB\u8F49"},clockWipe:{label:"\u6642\u9418",short:"\u6642\u9418"},star:{label:"\u661F\u5F62",short:"\u661F\u5F62"},circle:{label:"\u5713\u5F62",short:"\u5713\u5F62"},rectangle:{label:"\u77E9\u5F62",short:"\u77E9\u5F62"}}}}};function Zo(e){const t=Xt(e);return ho[t]??ho.en}const Jo={en:{tool:"Effects",title:"Effects",close:"Close",hint:"Adjust color, tone, and finishing details here.",details:"Details",empty:"No effect settings yet."},zh:{tool:"\u7279\u6548",title:"\u7279\u6548",close:"\u5173\u95ED",hint:"\u5728\u8FD9\u91CC\u53EF\u4EE5\u8C03\u6574\u8272\u5F69\u3001\u660E\u5EA6\u548C\u6548\u679C\u7EC6\u8282\u3002",details:"\u7EC6\u8282\u8C03\u6574",empty:"\u6682\u65E0\u53EF\u8C03\u6574\u9879"},"zh-Hant":{tool:"\u7279\u6548",title:"\u7279\u6548",close:"\u95DC\u9589",hint:"\u5728\u9019\u88E1\u53EF\u4EE5\u8ABF\u6574\u8272\u5F69\u3001\u660E\u5EA6\u8207\u6548\u679C\u7D30\u7BC0\u3002",details:"\u7D30\u7BC0\u8ABF\u6574",empty:"\u66AB\u7121\u53EF\u8ABF\u6574\u9805"}};function Kr(e){const t=Xt(e);return Jo[t]??Jo.en}const Qo={en:{title:"Audio",close:"Close",source:"Source",speed:"Speed",duration:"Duration",volume:"Volume",fadeIn:"Fade In",fadeOut:"Fade Out",speedHint:"Speed can be adjusted here and will be used when exporting audio."},zh:{title:"\u97F3\u8F68",close:"\u5173\u95ED",source:"\u6765\u6E90",speed:"\u500D\u6570",duration:"\u65F6\u957F",volume:"\u97F3\u91CF",fadeIn:"\u6DE1\u5165\u65F6\u957F",fadeOut:"\u6DE1\u51FA\u65F6\u957F",speedHint:"\u8FD9\u91CC\u53EF\u4EE5\u76F4\u63A5\u8C03\u6574\u97F3\u9891\u500D\u6570\uFF0C\u5BFC\u51FA\u65F6\u4F1A\u6309\u8BE5\u500D\u6570\u5904\u7406\u3002"},"zh-Hant":{title:"\u97F3\u8ECC",close:"\u95DC\u9589",source:"\u4F86\u6E90",speed:"\u500D\u6578",duration:"\u6642\u9577",volume:"\u97F3\u91CF",fadeIn:"\u6DE1\u5165\u6642\u9577",fadeOut:"\u6DE1\u51FA\u6642\u9577",speedHint:"\u9019\u88E1\u53EF\u4EE5\u76F4\u63A5\u8ABF\u6574\u97F3\u8A0A\u500D\u6578\uFF0C\u5C0E\u51FA\u6642\u6703\u6309\u8A72\u500D\u6578\u8655\u7406\u3002"}};function Ur(e){const t=Xt(e);return Qo[t]??Qo.en}const er={en:{tool:"Adjust",title:"Adjust",close:"Close",hint:"Select an adjustment layer to edit its controls here.",details:"Details",placeholder:"Select an adjustment layer to start editing.",videoInfoHint:"Default video details are shown here when no adjustment layer is selected.",videoInfoTitle:"Video details",videoName:"Name",ratio:"Ratio",canvasSize:"Canvas",resolution:"Resolution",frameRate:"Frame rate",bitrate:"Bitrate",format:"Format",fileSize:"File size",codec:"Codec",sourceSize:"Source size",videoLength:"Duration",notAvailable:"-"},zh:{tool:"\u8C03\u8282",title:"\u8C03\u8282",close:"\u5173\u95ED",hint:"\u9009\u4E2D\u8C03\u8282\u56FE\u5C42\u540E\uFF0C\u53EF\u4EE5\u5728\u8FD9\u91CC\u7EE7\u7EED\u8C03\u6574\u53C2\u6570\u3002",details:"\u7EC6\u8282\u8C03\u6574",placeholder:"\u8BF7\u5148\u9009\u4E2D\u4E00\u4E2A\u8C03\u8282\u56FE\u5C42\u518D\u7EE7\u7EED\u7F16\u8F91\u3002",videoInfoHint:"\u5F53\u524D\u672A\u9009\u4E2D\u8C03\u8282\u56FE\u5C42\uFF0C\u8FD9\u91CC\u663E\u793A\u9ED8\u8BA4\u89C6\u9891\u4FE1\u606F\u3002",videoInfoTitle:"\u89C6\u9891\u4FE1\u606F",videoName:"\u540D\u79F0",ratio:"\u6BD4\u4F8B",canvasSize:"\u753B\u5E03\u5927\u5C0F",resolution:"\u5206\u8FA8\u7387",frameRate:"\u5E27\u7387",bitrate:"\u7801\u7387",format:"\u683C\u5F0F",fileSize:"\u6587\u4EF6\u5927\u5C0F",codec:"\u7F16\u7801",sourceSize:"\u6E90\u5C3A\u5BF8",videoLength:"\u89C6\u9891\u65F6\u957F",notAvailable:"-"},"zh-Hant":{tool:"\u8ABF\u7BC0",title:"\u8ABF\u7BC0",close:"\u95DC\u9589",hint:"\u9078\u4E2D\u8ABF\u7BC0\u5716\u5C64\u5F8C\uFF0C\u53EF\u4EE5\u5728\u9019\u88E1\u7E7C\u7E8C\u8ABF\u6574\u53C3\u6578\u3002",details:"\u7D30\u7BC0\u8ABF\u6574",placeholder:"\u8ACB\u5148\u9078\u4E2D\u4E00\u500B\u8ABF\u7BC0\u5716\u5C64\u518D\u7E7C\u7E8C\u7DE8\u8F2F\u3002",videoInfoHint:"\u76EE\u524D\u672A\u9078\u4E2D\u8ABF\u7BC0\u5716\u5C64\uFF0C\u9019\u88E1\u986F\u793A\u9810\u8A2D\u8996\u983B\u8CC7\u8A0A\u3002",videoInfoTitle:"\u8996\u983B\u8CC7\u8A0A",videoName:"\u540D\u7A31",ratio:"\u6BD4\u4F8B",canvasSize:"\u756B\u5E03\u5927\u5C0F",resolution:"\u89E3\u6790\u5EA6",frameRate:"\u5E40\u7387",bitrate:"\u78BC\u7387",format:"\u683C\u5F0F",fileSize:"\u6A94\u6848\u5927\u5C0F",codec:"\u7DE8\u78BC",sourceSize:"\u4F86\u6E90\u5C3A\u5BF8",videoLength:"\u8996\u983B\u6642\u9577",notAvailable:"-"}};function Gr(e){const t=Xt(e);return er[t]??er.en}function Zr(){return`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
2035
|
+
`,document.head.appendChild(e),Ko=!0}function ue(e,t,n){return Math.min(Math.max(e,t),n)}function In(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 Rn(e="auto"){return e!=="auto"?e:typeof window<"u"&&window.matchMedia?.("(prefers-color-scheme: light)").matches?"light":"dark"}function Go(e){if(!e)return null;const t=String(e).toLowerCase();return t==="zh-hant"||/^zh-(tw|hk|mo)/.test(t)?"zh-Hant":t==="zh"||t.startsWith("zh-")?"zh":(t.startsWith("en"),"en")}function Xt(e){const t=Go(e);return t||(typeof navigator<"u"?Go(navigator.language)??"en":"en")}const ho={en:{untitledText:"Untitled text",textPresets:{heading:"Heading and some body",subtitle:"Subtitle line",label:"Label"},text:{tool:"Text",addText:"Add text",moveOnCanvas:"Move on canvas",close:"Close",hint:"Match the reference text styling here first. This version renders text as a full-length overlay, so font, shadow, stroke, background and alignment will export exactly.",empty:"No text overlay yet. Add one to start editing.",heading:"Heading",subtitle:"Subtitle",label:"Label",placeholder:"Type your text",content:"Content",font:"Font",weight:"Weight",fontSize:"Font Size",boxWidth:"Box Width",color:"Color",background:"Background",stroke:"Stroke",strokeColor:"Stroke Color",opacity:"Opacity",shadowBlur:"Shadow Blur",align:"Align",duplicate:"Duplicate",delete:"Delete",addLabel:"Add label"},transitions:{tool:"Transitions",title:"Transitions",fadeAll:"Fade all",close:"Close",hint:"Pick a cut between clips on the timeline. These transitions are exported through ffmpeg xfade/acrossfade, so the result is baked into the final video.",empty:"Need at least 2 clips to place a transition. Split or duplicate a clip first.",duration:"Duration",clearSelected:"Clear selected",clearAll:"Clear all",cut:"Cut",instantCut:"Instant cut",selection:(e,t)=>`Between clip ${e} and clip ${t}`,selectionEmpty:"Open Trim to place transitions on the timeline.",boundary:(e,t,n)=>`${e}\u2192${t} ${n}`,boundaryTitle:(e,t)=>`Between clip ${e} and clip ${t}`,markerTitle:(e,t,n,r)=>`Clip ${e} \u2192 ${t}: ${n}${r?` (${r})`:""}`,options:{none:{label:"Cut",short:"Cut"},fade:{label:"Fade",short:"Fade"},slide:{label:"Slide",short:"Slide"},wipe:{label:"Wipe",short:"Wipe"},flip:{label:"Flip",short:"Flip"},clockWipe:{label:"Clock",short:"Clock"},star:{label:"Star",short:"Star"},circle:{label:"Circle",short:"Circle"},rectangle:{label:"Rectangle",short:"Rect"}}}},zh:{untitledText:"\u672A\u547D\u540D\u6587\u5B57",textPresets:{heading:"\u4E3B\u6807\u9898\u548C\u6B63\u6587",subtitle:"\u5B57\u5E55\u6587\u6848",label:"\u6807\u7B7E"},text:{tool:"\u6587\u5B57",addText:"\u6DFB\u52A0\u6587\u5B57",moveOnCanvas:"\u753B\u5E03\u5B9A\u4F4D",close:"\u5173\u95ED",hint:"\u5148\u5728\u8FD9\u91CC\u628A\u6587\u5B57\u6837\u5F0F\u8C03\u5230\u548C\u53C2\u8003\u4E00\u81F4\u3002\u8BE5\u7248\u672C\u4F1A\u628A\u6587\u5B57\u4F5C\u4E3A\u5B8C\u6574\u8986\u76D6\u5C42\u5BFC\u51FA\uFF0C\u5B57\u4F53\u3001\u9634\u5F71\u3001\u63CF\u8FB9\u3001\u80CC\u666F\u548C\u5BF9\u9F50\u65B9\u5F0F\u90FD\u4F1A\u88AB\u51C6\u786E\u4FDD\u7559\u3002",empty:"\u8FD8\u6CA1\u6709\u6587\u5B57\u56FE\u5C42\uFF0C\u5148\u6DFB\u52A0\u4E00\u4E2A\u5F00\u59CB\u7F16\u8F91\u3002",heading:"\u6807\u9898",subtitle:"\u5B57\u5E55",label:"\u6807\u7B7E",placeholder:"\u8F93\u5165\u6587\u5B57\u5185\u5BB9",content:"\u5185\u5BB9",font:"\u5B57\u4F53",weight:"\u5B57\u91CD",fontSize:"\u5B57\u53F7",boxWidth:"\u6587\u672C\u5BBD\u5EA6",color:"\u989C\u8272",background:"\u80CC\u666F",stroke:"\u63CF\u8FB9",strokeColor:"\u63CF\u8FB9\u989C\u8272",opacity:"\u900F\u660E\u5EA6",shadowBlur:"\u9634\u5F71\u6A21\u7CCA",align:"\u5BF9\u9F50",duplicate:"\u590D\u5236",delete:"\u5220\u9664",addLabel:"\u6DFB\u52A0\u6807\u7B7E"},transitions:{tool:"\u8F6C\u573A",title:"\u8F6C\u573A",fadeAll:"\u5168\u90E8\u6DE1\u5165\u6DE1\u51FA",close:"\u5173\u95ED",hint:"\u5728\u65F6\u95F4\u8F74\u4E0A\u9009\u62E9\u4E24\u4E2A\u7247\u6BB5\u4E4B\u95F4\u7684\u5207\u70B9\u3002\u8F6C\u573A\u4F1A\u901A\u8FC7 ffmpeg \u7684 xfade/acrossfade \u70D8\u7119\u8FDB\u6700\u7EC8\u5BFC\u51FA\u89C6\u9891\u3002",empty:"\u81F3\u5C11\u9700\u8981 2 \u4E2A\u7247\u6BB5\u624D\u80FD\u8BBE\u7F6E\u8F6C\u573A\u3002\u53EF\u4EE5\u5148\u5206\u5272\u6216\u590D\u5236\u7247\u6BB5\u3002",duration:"\u65F6\u957F",clearSelected:"\u6E05\u9664\u5F53\u524D",clearAll:"\u6E05\u9664\u5168\u90E8",cut:"\u786C\u5207",instantCut:"\u76F4\u63A5\u5207\u6362",selection:(e,t)=>`\u7B2C ${e} \u6BB5 \u2192 \u7B2C ${t} \u6BB5`,selectionEmpty:"\u6253\u5F00\u526A\u8F91\u5DE5\u5177\u540E\uFF0C\u53EF\u5728\u65F6\u95F4\u8F74\u4E0A\u8BBE\u7F6E\u8F6C\u573A\u3002",boundary:(e,t,n)=>`${e}\u2192${t} ${n}`,boundaryTitle:(e,t)=>`\u7B2C ${e} \u6BB5\u5230\u7B2C ${t} \u6BB5\u4E4B\u95F4`,markerTitle:(e,t,n,r)=>`\u7B2C ${e} \u6BB5 \u2192 \u7B2C ${t} \u6BB5\uFF1A${n}${r?`\uFF08${r}\uFF09`:""}`,options:{none:{label:"\u786C\u5207",short:"\u786C\u5207"},fade:{label:"\u6DE1\u5316",short:"\u6DE1\u5316"},slide:{label:"\u6ED1\u52A8",short:"\u6ED1\u52A8"},wipe:{label:"\u64E6\u9664",short:"\u64E6\u9664"},flip:{label:"\u7FFB\u8F6C",short:"\u7FFB\u8F6C"},clockWipe:{label:"\u65F6\u949F",short:"\u65F6\u949F"},star:{label:"\u661F\u5F62",short:"\u661F\u5F62"},circle:{label:"\u5706\u5F62",short:"\u5706\u5F62"},rectangle:{label:"\u77E9\u5F62",short:"\u77E9\u5F62"}}}},"zh-Hant":{untitledText:"\u672A\u547D\u540D\u6587\u5B57",textPresets:{heading:"\u4E3B\u6A19\u984C\u548C\u6B63\u6587",subtitle:"\u5B57\u5E55\u6587\u6848",label:"\u6A19\u7C64"},text:{tool:"\u6587\u5B57",addText:"\u65B0\u589E\u6587\u5B57",moveOnCanvas:"\u756B\u5E03\u5B9A\u4F4D",close:"\u95DC\u9589",hint:"\u5148\u5728\u9019\u88E1\u628A\u6587\u5B57\u6A23\u5F0F\u8ABF\u5230\u548C\u53C3\u8003\u4E00\u81F4\u3002\u9019\u500B\u7248\u672C\u6703\u628A\u6587\u5B57\u4F5C\u70BA\u5B8C\u6574\u8986\u84CB\u5C64\u5C0E\u51FA\uFF0C\u5B57\u9AD4\u3001\u9670\u5F71\u3001\u63CF\u908A\u3001\u80CC\u666F\u548C\u5C0D\u9F4A\u65B9\u5F0F\u90FD\u6703\u88AB\u6E96\u78BA\u4FDD\u7559\u3002",empty:"\u9084\u6C92\u6709\u6587\u5B57\u5716\u5C64\uFF0C\u5148\u65B0\u589E\u4E00\u500B\u958B\u59CB\u7DE8\u8F2F\u3002",heading:"\u6A19\u984C",subtitle:"\u5B57\u5E55",label:"\u6A19\u7C64",placeholder:"\u8F38\u5165\u6587\u5B57\u5167\u5BB9",content:"\u5167\u5BB9",font:"\u5B57\u9AD4",weight:"\u5B57\u91CD",fontSize:"\u5B57\u7D1A",boxWidth:"\u6587\u5B57\u5BEC\u5EA6",color:"\u984F\u8272",background:"\u80CC\u666F",stroke:"\u63CF\u908A",strokeColor:"\u63CF\u908A\u984F\u8272",opacity:"\u900F\u660E\u5EA6",shadowBlur:"\u9670\u5F71\u6A21\u7CCA",align:"\u5C0D\u9F4A",duplicate:"\u8907\u88FD",delete:"\u522A\u9664",addLabel:"\u65B0\u589E\u6A19\u7C64"},transitions:{tool:"\u8F49\u5834",title:"\u8F49\u5834",fadeAll:"\u5168\u90E8\u6DE1\u5316",close:"\u95DC\u9589",hint:"\u5728\u6642\u9593\u8EF8\u4E0A\u9078\u64C7\u5169\u500B\u7247\u6BB5\u4E4B\u9593\u7684\u5207\u9EDE\u3002\u8F49\u5834\u6703\u900F\u904E ffmpeg \u7684 xfade/acrossfade \u70D8\u7119\u9032\u6700\u7D42\u5C0E\u51FA\u5F71\u7247\u3002",empty:"\u81F3\u5C11\u9700\u8981 2 \u500B\u7247\u6BB5\u624D\u80FD\u8A2D\u5B9A\u8F49\u5834\u3002\u53EF\u4EE5\u5148\u5206\u5272\u6216\u8907\u88FD\u7247\u6BB5\u3002",duration:"\u6642\u9577",clearSelected:"\u6E05\u9664\u76EE\u524D",clearAll:"\u6E05\u9664\u5168\u90E8",cut:"\u786C\u5207",instantCut:"\u76F4\u63A5\u5207\u63DB",selection:(e,t)=>`\u7B2C ${e} \u6BB5 \u2192 \u7B2C ${t} \u6BB5`,selectionEmpty:"\u6253\u958B\u526A\u8F2F\u5DE5\u5177\u5F8C\uFF0C\u53EF\u5728\u6642\u9593\u8EF8\u4E0A\u8A2D\u5B9A\u8F49\u5834\u3002",boundary:(e,t,n)=>`${e}\u2192${t} ${n}`,boundaryTitle:(e,t)=>`\u7B2C ${e} \u6BB5\u5230\u7B2C ${t} \u6BB5\u4E4B\u9593`,markerTitle:(e,t,n,r)=>`\u7B2C ${e} \u6BB5 \u2192 \u7B2C ${t} \u6BB5\uFF1A${n}${r?`\uFF08${r}\uFF09`:""}`,options:{none:{label:"\u786C\u5207",short:"\u786C\u5207"},fade:{label:"\u6DE1\u5316",short:"\u6DE1\u5316"},slide:{label:"\u6ED1\u52D5",short:"\u6ED1\u52D5"},wipe:{label:"\u64E6\u9664",short:"\u64E6\u9664"},flip:{label:"\u7FFB\u8F49",short:"\u7FFB\u8F49"},clockWipe:{label:"\u6642\u9418",short:"\u6642\u9418"},star:{label:"\u661F\u5F62",short:"\u661F\u5F62"},circle:{label:"\u5713\u5F62",short:"\u5713\u5F62"},rectangle:{label:"\u77E9\u5F62",short:"\u77E9\u5F62"}}}}};function Zo(e){const t=Xt(e);return ho[t]??ho.en}const Jo={en:{tool:"Effects",title:"Effects",close:"Close",hint:"Adjust color, tone, and finishing details here.",details:"Details",empty:"No effect settings yet."},zh:{tool:"\u7279\u6548",title:"\u7279\u6548",close:"\u5173\u95ED",hint:"\u5728\u8FD9\u91CC\u53EF\u4EE5\u8C03\u6574\u8272\u5F69\u3001\u660E\u5EA6\u548C\u6548\u679C\u7EC6\u8282\u3002",details:"\u7EC6\u8282\u8C03\u6574",empty:"\u6682\u65E0\u53EF\u8C03\u6574\u9879"},"zh-Hant":{tool:"\u7279\u6548",title:"\u7279\u6548",close:"\u95DC\u9589",hint:"\u5728\u9019\u88E1\u53EF\u4EE5\u8ABF\u6574\u8272\u5F69\u3001\u660E\u5EA6\u8207\u6548\u679C\u7D30\u7BC0\u3002",details:"\u7D30\u7BC0\u8ABF\u6574",empty:"\u66AB\u7121\u53EF\u8ABF\u6574\u9805"}};function Kr(e){const t=Xt(e);return Jo[t]??Jo.en}const Qo={en:{title:"Audio",close:"Close",source:"Source",speed:"Speed",duration:"Duration",volume:"Volume",fadeIn:"Fade In",fadeOut:"Fade Out",speedHint:"Speed can be adjusted here and will be used when exporting audio."},zh:{title:"\u97F3\u8F68",close:"\u5173\u95ED",source:"\u6765\u6E90",speed:"\u500D\u6570",duration:"\u65F6\u957F",volume:"\u97F3\u91CF",fadeIn:"\u6DE1\u5165\u65F6\u957F",fadeOut:"\u6DE1\u51FA\u65F6\u957F",speedHint:"\u8FD9\u91CC\u53EF\u4EE5\u76F4\u63A5\u8C03\u6574\u97F3\u9891\u500D\u6570\uFF0C\u5BFC\u51FA\u65F6\u4F1A\u6309\u8BE5\u500D\u6570\u5904\u7406\u3002"},"zh-Hant":{title:"\u97F3\u8ECC",close:"\u95DC\u9589",source:"\u4F86\u6E90",speed:"\u500D\u6578",duration:"\u6642\u9577",volume:"\u97F3\u91CF",fadeIn:"\u6DE1\u5165\u6642\u9577",fadeOut:"\u6DE1\u51FA\u6642\u9577",speedHint:"\u9019\u88E1\u53EF\u4EE5\u76F4\u63A5\u8ABF\u6574\u97F3\u8A0A\u500D\u6578\uFF0C\u5C0E\u51FA\u6642\u6703\u6309\u8A72\u500D\u6578\u8655\u7406\u3002"}};function Ur(e){const t=Xt(e);return Qo[t]??Qo.en}const er={en:{tool:"Adjust",title:"Adjust",close:"Close",hint:"Select an adjustment layer to edit its controls here.",details:"Details",placeholder:"Select an adjustment layer to start editing.",videoInfoHint:"Default video details are shown here when no adjustment layer is selected.",videoInfoTitle:"Video details",videoName:"Name",ratio:"Ratio",canvasSize:"Canvas",resolution:"Resolution",frameRate:"Frame rate",bitrate:"Bitrate",format:"Format",fileSize:"File size",codec:"Codec",sourceSize:"Source size",videoLength:"Duration",notAvailable:"-"},zh:{tool:"\u8C03\u8282",title:"\u8C03\u8282",close:"\u5173\u95ED",hint:"\u9009\u4E2D\u8C03\u8282\u56FE\u5C42\u540E\uFF0C\u53EF\u4EE5\u5728\u8FD9\u91CC\u7EE7\u7EED\u8C03\u6574\u53C2\u6570\u3002",details:"\u7EC6\u8282\u8C03\u6574",placeholder:"\u8BF7\u5148\u9009\u4E2D\u4E00\u4E2A\u8C03\u8282\u56FE\u5C42\u518D\u7EE7\u7EED\u7F16\u8F91\u3002",videoInfoHint:"\u5F53\u524D\u672A\u9009\u4E2D\u8C03\u8282\u56FE\u5C42\uFF0C\u8FD9\u91CC\u663E\u793A\u9ED8\u8BA4\u89C6\u9891\u4FE1\u606F\u3002",videoInfoTitle:"\u89C6\u9891\u4FE1\u606F",videoName:"\u540D\u79F0",ratio:"\u6BD4\u4F8B",canvasSize:"\u753B\u5E03\u5927\u5C0F",resolution:"\u5206\u8FA8\u7387",frameRate:"\u5E27\u7387",bitrate:"\u7801\u7387",format:"\u683C\u5F0F",fileSize:"\u6587\u4EF6\u5927\u5C0F",codec:"\u7F16\u7801",sourceSize:"\u6E90\u5C3A\u5BF8",videoLength:"\u89C6\u9891\u65F6\u957F",notAvailable:"-"},"zh-Hant":{tool:"\u8ABF\u7BC0",title:"\u8ABF\u7BC0",close:"\u95DC\u9589",hint:"\u9078\u4E2D\u8ABF\u7BC0\u5716\u5C64\u5F8C\uFF0C\u53EF\u4EE5\u5728\u9019\u88E1\u7E7C\u7E8C\u8ABF\u6574\u53C3\u6578\u3002",details:"\u7D30\u7BC0\u8ABF\u6574",placeholder:"\u8ACB\u5148\u9078\u4E2D\u4E00\u500B\u8ABF\u7BC0\u5716\u5C64\u518D\u7E7C\u7E8C\u7DE8\u8F2F\u3002",videoInfoHint:"\u76EE\u524D\u672A\u9078\u4E2D\u8ABF\u7BC0\u5716\u5C64\uFF0C\u9019\u88E1\u986F\u793A\u9810\u8A2D\u8996\u983B\u8CC7\u8A0A\u3002",videoInfoTitle:"\u8996\u983B\u8CC7\u8A0A",videoName:"\u540D\u7A31",ratio:"\u6BD4\u4F8B",canvasSize:"\u756B\u5E03\u5927\u5C0F",resolution:"\u89E3\u6790\u5EA6",frameRate:"\u5E40\u7387",bitrate:"\u78BC\u7387",format:"\u683C\u5F0F",fileSize:"\u6A94\u6848\u5927\u5C0F",codec:"\u7DE8\u78BC",sourceSize:"\u4F86\u6E90\u5C3A\u5BF8",videoLength:"\u8996\u983B\u6642\u9577",notAvailable:"-"}};function Gr(e){const t=Xt(e);return er[t]??er.en}function Zr(){return`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
2036
2036
|
<path d="M9 15l6-6" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/>
|
|
2037
2037
|
<path d="M7.6 16.4l-1.2 2.4a.7.7 0 0 0 .93.93L9.7 18.5" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/>
|
|
2038
2038
|
<path d="M14.4 8.4l1.2-2.4a.7.7 0 0 1 .93-.93l1.47 1.47a.7.7 0 0 1-.05 1.04L15.6 8.8" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/>
|
|
@@ -2044,7 +2044,7 @@ import{mountVideoEditor as _r}from"./legacy.js";import{FILTER_PRESETS as jr,buil
|
|
|
2044
2044
|
<path d="M18 6v12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
|
|
2045
2045
|
<rect x="4.2" y="8" width="3.6" height="4.8" rx="1.8" fill="currentColor"/>
|
|
2046
2046
|
<rect x="16.2" y="11.2" width="3.6" height="4.8" rx="1.8" fill="currentColor"/>
|
|
2047
|
-
</svg>`}function En(e,t){const n=xo(t),r=e.transitions.options[n.key]??e.transitions.options.none;return{...n,label:r.label,short:r.short}}function Un(e,t=ho.en.untitledText){return String(e??"").replace(/\s+/g," ").trim()||t}function Da(e){if(!e)return!1;const t=String(e).trim().toLowerCase();return t!==""&&t!=="transparent"}function xo(e){return vo.find(t=>t.key===e)??vo[0]}function mn(e){const t=Number(e)||0;return`${t.toFixed(t>=1?1:2).replace(/0+$/,"").replace(/\.$/,"")}s`}function Dt(e){return Math.max(0,(Number(e?.out)||0)-(Number(e?.in)||0))}function bn(e){return ae(Number(e)||1,.5,2)}function Qr(e){return`${bn(e).toFixed(2)}x`}function ei(e,t=1){const n=String(e??"").trim().replace(/x$/i,""),r=Number(n);return Number.isFinite(r)?bn(r):bn(t)}function ti(e,t=0){const n=String(e??"").trim().replace(/s$/i,""),r=Number(n);return Number.isFinite(r)?Math.max(0,r):Math.max(0,t)}function Gn(e,t=.4,n=.4){const r=xo(e?.type??"none"),a=Math.max(0,Math.min(1.2,t-.05,n-.05));if(r.key==="none"||a<=.05)return{type:"none",duration:0};const s=Number(e?.duration),u=ae(Number.isFinite(s)?s:r.duration,.1,a);return{type:r.key,duration:u}}function bo(e){const t=e?.clips??[],n=Math.max(0,t.length-1),r=Array.isArray(e?.transitions)?e.transitions:[],a=[];for(let s=0;s<n;s++)a.push(Gn(r[s],Dt(t[s]),Dt(t[s+1])));return a}function tr(e,t,n="heading"){const a=e.getState().canvas??{w:1080,h:1920},s=qo[n]??qo.heading,u=Math.min(s.width,Math.max(240,a.w-64)),f=Math.min(s.fontSize,Math.max(32,Math.round(a.w*.11))),v=ae(Math.round(a.h*.18),32,Math.max(32,a.h-180));return{type:"text",x:Math.round((a.w-u)/2),y:v,text:t.textPresets[n]??s.text,color:s.color,fontSize:f,fontFamily:"Arial",fontWeight:s.fontWeight,fontStyle:"normal",textAlign:s.textAlign,width:u,backgroundColor:s.backgroundColor,borderColor:s.borderColor,borderWidth:s.borderWidth,paddingX:s.paddingX??Math.max(14,Math.round(f*.18)),paddingY:s.paddingY??Math.max(10,Math.round(f*.14)),boxShadow:s.boxShadow?{...s.boxShadow}:void 0,lineHeight:1.1,textPreset:n,textDecoration:"",textTransform:void 0,animation:"none",rotation:0}}const qt=3,je=.5,Wt=.1,gn=99,go=36,nr=6;function lt(e,t=0){return Number.isFinite(e?.startAt)?Math.max(0,Number(e.startAt)):Math.max(0,t)}function Bt(e,t=0,n=qt){const r=lt(e,t);return Number.isFinite(e?.endAt)?Math.max(r+je,Number(e.endAt)):r+Math.max(je,n)}function Sn(e,t=qt){return Math.max(je,Bt(e,0,t)-lt(e,0))}function vt(e,t=0){return Number.isFinite(e?.timelineTrack)?ae(Math.round(Number(e.timelineTrack)),0,gn):Math.max(0,t)}function ni(e){return e==="pen"||e==="line"||e==="arrow"||e==="rect"||e==="ellipse"}function nn(e){return ni(e?.type)}function Zt(e){return e?.type==="text"||e?.type==="sticker"||e?.type==="filter"||e?.type==="adjust"||nn(e)}function Ln(e){return e*(go+nr)}function yo(e){const t=Array.isArray(e)?e:e?.overlays;return[...new Set((t??[]).filter(n=>Zt(n)).map(n=>vt(n)))].sort((n,r)=>n-r)}function Rn(e){const t=new Map;return yo(e).forEach((n,r)=>{t.set(n,r)}),t}function oi(e){return yo(e).length}function ri(e){const t=oi(e);return t?Ln(t-1)+go:0}function ii(e){return e instanceof HTMLElement&&(e.dataset.meTimelineCoverSlot==="true"||e.classList.contains("me-video-timeline-cover-slot"))}function ai(e){const t=e.querySelector(".me-video-timeline-scroll");return t instanceof HTMLElement?t:null}function Fn(e){const t=ai(e);return t?[...t.children].find(n=>n instanceof HTMLElement&&!ii(n))??null:null}function or(e){const n=Fn(e)?.firstElementChild;return n instanceof HTMLElement?n:null}function Bn(e,t){const n=Fn(e);if(!n)return{timelineInner:null,timelineHost:null};n.style.position="relative";const r=n.firstElementChild,a=ri(t),s=[];for(const k of n.children)k instanceof HTMLElement&&k.classList.contains("me-video-overlay-track-host")&&s.push(k);const u=[...n.children].find(k=>k!==r&&!(k instanceof HTMLElement&&k.classList.contains("me-video-overlay-track-host")))??null;if(!u)return s.forEach(k=>k.remove()),{timelineInner:n,timelineHost:null};const f=s.shift()??null;if(s.forEach(k=>k.remove()),a<=0)return f?.remove(),{timelineInner:n,timelineHost:null};const v=f??document.createElement("div");return f||(v.className="me-video-overlay-track-host"),v.style.height=`${a}px`,(v.parentElement!==n||v.nextElementSibling!==u)&&n.insertBefore(v,u),{timelineInner:n,timelineHost:v}}function si(e){return((Array.isArray(e)?e:e?.overlays)??[]).reduce((n,r)=>Zt(r)?Math.max(n,Bt(r)):n,0)}function rr(e,t,n,r){return e<r-1e-6&&n<t-1e-6}function _a(e,t,n,r=-1){const a=new Map;(e??[]).forEach((s,u)=>{if(u===r||!Zt(s))return;const f=vt(s);let v=a.get(f);v||(v=[],a.set(f,v)),v.push({startAt:lt(s),endAt:Bt(s)})});for(let s=0;s<=gn;s++)if((a.get(s)??[]).every(f=>!rr(t,n,f.startAt,f.endAt)))return s;return gn}function li(e,t,n,r,a){const s=ae(Math.round(Number(a)||0),0,gn);return(e??[]).every((u,f)=>f===t||!Zt(u)||vt(u)!==s?!0:!rr(n,r,lt(u),Bt(u)))}function pt(e,t,n,r,a,s,u){if(!e)return u;const f=e.getBoundingClientRect(),v=Math.max(0,s-f.top),k=yo(t),H=ae(Math.floor(v/(go+nr)),0,k.length),G=H<k.length?k[H]:ae((k[k.length-1]??-1)+1,0,gn);return li(t,n,r,a,G)?G:u}function Jt(e,t,n={}){const r=lt(e,0),a=Sn(e),s=Number.isFinite(n.startAt)?Number(n.startAt):r,u=Number.isFinite(n.endAt)?Number(n.endAt):s+a,f=Math.max(0,s),v=Math.max(f+je,u),k=Math.max(je,Number(t)||qt,v),H=ae(f,0,Math.max(0,k-je)),G=ae(v,H+je,Math.max(H+je,k));return{startAt:H,endAt:G,timelineTrack:vt({timelineTrack:n.timelineTrack??e?.timelineTrack})}}function ir(e,t=1){const n=Math.max(0,Math.round(Number(t)||0));return n?(e??[]).map(r=>Zt(r)?{...r,timelineTrack:ae(vt(r)+n,0,gn)}:r):[...e??[]]}function on(e){return ir(e,1)}function ar(e){return(e.overlays??[]).map((t,n)=>({overlay:t,index:n})).filter(t=>t.overlay?.type==="text").sort((t,n)=>{const r=vt(t.overlay)-vt(n.overlay);if(r!==0)return r;const a=lt(t.overlay)-lt(n.overlay);return Math.abs(a)>1e-6?a:t.index-n.index})}function sr(e){return(e.overlays??[]).map((t,n)=>({overlay:t,index:n})).filter(t=>t.overlay?.type==="sticker").sort((t,n)=>{const r=vt(t.overlay)-vt(n.overlay);if(r!==0)return r;const a=lt(t.overlay)-lt(n.overlay);return Math.abs(a)>1e-6?a:t.index-n.index})}function lr(e){return(e.overlays??[]).map((t,n)=>({overlay:t,index:n})).filter(t=>t.overlay?.type==="filter").sort((t,n)=>{const r=vt(t.overlay)-vt(n.overlay);if(r!==0)return r;const a=lt(t.overlay)-lt(n.overlay);return Math.abs(a)>1e-6?a:t.index-n.index})}function cr(e){return(e.overlays??[]).map((t,n)=>({overlay:t,index:n})).filter(t=>t.overlay?.type==="adjust").sort((t,n)=>{const r=vt(t.overlay)-vt(n.overlay);if(r!==0)return r;const a=lt(t.overlay)-lt(n.overlay);return Math.abs(a)>1e-6?a:t.index-n.index})}function wo(e){return(e.overlays??[]).map((t,n)=>({overlay:t,index:n})).filter(t=>nn(t.overlay)).sort((t,n)=>{const r=vt(t.overlay)-vt(n.overlay);if(r!==0)return r;const a=lt(t.overlay)-lt(n.overlay);return Math.abs(a)>1e-6?a:t.index-n.index})}function ci(e){return(e.overlays??[]).map((t,n)=>({overlay:t,index:n})).filter(t=>Zt(t.overlay)).sort((t,n)=>{const r=vt(t.overlay)-vt(n.overlay);if(r!==0)return r;const a=lt(t.overlay)-lt(n.overlay);return Math.abs(a)>1e-6?a:t.index-n.index})}function yt(e){return[...new Set((e??[]).map(t=>Number(t)).filter(t=>Number.isInteger(t)&&t>=0))].sort((t,n)=>t-n)}function Zn(e){if(e.__meVideoTimelineSelectionStore)return e.__meVideoTimelineSelectionStore;const t={video:new Set,text:new Set,audio:new Set,anchors:{video:null,text:null,audio:null},initialized:!1};return e.__meVideoTimelineSelectionStore=t,t}function di(e,t){return t==="text"?e.text:t==="audio"?e.audio:e.video}function dr(){return["video","text","audio"]}function _t(e,t){return yt([...di(Zn(e),t)])}function ko(e,t){const n=yt(t),r=yt([...e]);return r.length===n.length&&r.every((a,s)=>a===n[s])?!1:(e.clear(),n.forEach(a=>e.add(a)),!0)}function ui(e){e.dispatchEvent(new CustomEvent(zt))}function pn(e,t={},n={}){const r=Zn(e);let a=!1;if(Object.prototype.hasOwnProperty.call(t,"video")&&(a=ko(r.video,t.video)||a),Object.prototype.hasOwnProperty.call(t,"text")&&(a=ko(r.text,t.text)||a),Object.prototype.hasOwnProperty.call(t,"audio")&&(a=ko(r.audio,t.audio)||a),Object.prototype.hasOwnProperty.call(n,"video")){const s=Number.isInteger(n.video)&&n.video>=0?n.video:null;r.anchors.video!==s&&(r.anchors.video=s,a=!0)}if(Object.prototype.hasOwnProperty.call(n,"text")){const s=Number.isInteger(n.text)&&n.text>=0?n.text:null;r.anchors.text!==s&&(r.anchors.text=s,a=!0)}if(Object.prototype.hasOwnProperty.call(n,"audio")){const s=Number.isInteger(n.audio)&&n.audio>=0?n.audio:null;r.anchors.audio!==s&&(r.anchors.audio=s,a=!0)}return a&&ui(e),r}function bt(e,t,n,r={}){const a=yt(n),s={[t]:a},u={[t]:a.length?r.anchor??a[a.length-1]:null};if(!r.preserveOther)for(const f of dr())f!==t&&(s[f]=[],u[f]=null);return pn(e,s,u),a}function Eo(e){pn(e,{video:[],text:[],audio:[]},{video:null,text:null,audio:null})}function So(e){return _t(e,"video").length>0||_t(e,"text").length>0||_t(e,"audio").length>0}function Lo(e,t,n){const r=new Set(yt(n)),a=_t(e,t),s=a.filter(u=>r.has(u));return a.length!==s.length&&pn(e,{[t]:s},{[t]:s.length?s[s.length-1]:null}),s}function Pt(e,t,n,r,a=[]){const s=yt(a),u=!!(r?.ctrlKey||r?.metaKey),f=!!r?.shiftKey,v=Zn(e),k=_t(e,t);let H=k,G=n;if(f){const j=v.anchors[t],oe=s.indexOf(j),Q=s.indexOf(n);if(oe!==-1&&Q!==-1){const Z=Math.min(oe,Q),ie=Math.max(oe,Q),he=s.slice(Z,ie+1);H=u?yt([...k,...he]):he,G=j}else u?H=k.includes(n)?k.filter(Z=>Z!==n):[...k,n]:H=[n]}else u?H=k.includes(n)?k.filter(j=>j!==n):[...k,n]:H=[n];H=yt(H);const T={[t]:H},F={[t]:H.length?G:null};if(!u)for(const j of dr())j!==t&&(T[j]=[],F[j]=null);return pn(e,T,F),H}function mi(e,t){const n=Zn(e);n.initialized||(n.initialized=!0)}function Tn(e){const t=typeof e.getState=="function"?e.getState():null;return Math.max(typeof e.contentDuration=="function"?e.contentDuration():0,si(t),je)}function Jn(e){const t=String(e??"").trim();if(!t)return NaN;const n=t.split(":").map(a=>a.trim()).filter(Boolean);if(!n.length)return NaN;let r=0;for(const a of n){const s=Number(a);if(!Number.isFinite(s))return NaN;r=r*60+s}return r}function Qn(e){return e instanceof HTMLElement?String(e.dataset.meRawTimeText||e.textContent||"").trim():""}function yn(e){const t=or(e);if(t){const a=[...t.children].find(u=>u instanceof HTMLElement&&String(u.style.transform||"").includes("translateX(-50%)")),s=Jn(Qn(a));if(Number.isFinite(s))return s}const n=[...e.querySelectorAll(".me-video-trim-actions span")].find(a=>Qn(a).includes("/")),r=Qn(n);if(r){const a=Jn(r.split("/")[0]);if(Number.isFinite(a))return a}return 0}function $n(e,t){return Lo(e,"video",(t??[]).map((n,r)=>r)).filter(n=>!!t[n])}function To(e,t){return _t(e,"text").filter(n=>t.overlays?.[n]?.type==="text")}function ur(e,t){return _t(e,"text").filter(n=>t.overlays?.[n]?.type==="sticker")}function mr(e,t){return _t(e,"text").filter(n=>t.overlays?.[n]?.type==="filter")}function eo(e,t){return _t(e,"text").filter(n=>t.overlays?.[n]?.type==="adjust")}function pr(e,t){return _t(e,"text").filter(n=>nn(t.overlays?.[n]))}function Dn(e,t){const n=ci(t).map(r=>r.index);return Lo(e,"text",n).filter(r=>Zt(t.overlays?.[r]))}function Mn(e,t){return Lo(e,"audio",(t??[]).map((n,r)=>r)).filter(n=>!!t[n])}function pi(e,t){const n=yt(t).filter(s=>!!e[s]);if(!n.length)return{clips:e,selection:[],changed:!1};const r=n[n.length-1]+1,a=n.map(s=>({...e[s]}));return{clips:[...e.slice(0,r),...a,...e.slice(r)],selection:a.map((s,u)=>r+u),changed:!0}}function Mo(e,t){const n=yt(t).filter(f=>Zt(e[f]));if(!n.length)return{overlays:e,selection:[],changed:!1};const r=n.map(f=>{const v=e[f];return v?.type==="pen"?{...v,points:(v.points??[]).map((k,H)=>(H%2===0,(Number(k)||0)+24))}:v?.type==="line"||v?.type==="arrow"?{...v,x1:(Number(v.x1)||0)+24,y1:(Number(v.y1)||0)+24,x2:(Number(v.x2)||0)+24,y2:(Number(v.y2)||0)+24}:{...v,x:(Number(v.x)||0)+24,y:(Number(v.y)||0)+24}}),s=[...ir(e,r.length),...r.map((f,v)=>({...f,timelineTrack:ae(v,0,gn)}))],u=s.length-r.length;return{overlays:s,selection:r.map((f,v)=>u+v),changed:!0}}function fi(e,t){const n=yt(t).filter(s=>!!e[s]);if(!n.length)return{audioClips:e,selection:[],changed:!1};const r=n[n.length-1]+1,a=n.map(s=>{const u=e[s];return{...u,track:Number.isInteger(u?.track)&&u.track>=0?u.track:s,startAt:Math.max(0,(Number(u.startAt)||0)+.2)}});return{audioClips:[...e.slice(0,r),...a,...e.slice(r)],selection:a.map((s,u)=>r+u),changed:!0}}function vi(e,t){const n=yt(t).filter(a=>!!e[a]);if(!n.length||n.length>=e.length)return{clips:e,selection:n,changed:!1};const r=new Set(n);return{clips:e.filter((a,s)=>!r.has(s)),selection:[],changed:!0}}function Co(e,t){const n=new Set(yt(t).filter(r=>Zt(e[r])));return n.size?{overlays:e.filter((r,a)=>!n.has(a)),selection:[],changed:!0}:{overlays:e,selection:[],changed:!1}}function hi(e,t){const n=new Set(yt(t).filter(r=>!!e[r]));return n.size?{audioClips:e.filter((r,a)=>!n.has(a)),selection:[],changed:!0}:{audioClips:e,selection:[],changed:!1}}function xi(e,t,n){const r=new Set(yt(t).filter(v=>!!e[v]));if(!r.size)return{clips:e,selection:[],changed:!1};let a=0,s=!1;const u=[],f=[];for(let v=0;v<e.length;v++){const k=e[v],H=Math.max(0,(Number(k?.out)||0)-(Number(k?.in)||0)),G=a+H;if(r.has(v)&&n>a+Wt&&n<G-Wt){const T=(Number(k.in)||0)+(n-a);f.push(u.length),u.push({...k,out:T}),f.push(u.length),u.push({...k,in:T}),s=!0}else r.has(v)&&f.push(u.length),u.push(k);a=G}return{clips:s?u:e,selection:s?f:yt(t),changed:s}}function bi(e,t,n,r){const a=new Set(yt(t).filter(v=>Zt(e[v])));if(!a.size)return{overlays:e,selection:[],changed:!1};let s=!1;const u=[],f=[];for(let v=0;v<e.length;v++){const k=e[v];if(Zt(k)&&a.has(v)){const H=lt(k),G=Bt(k,H),T=ae(r,H+je,G-je);if(T>H+1e-6&&T<G-1e-6){f.push(u.length),u.push({...k,...Jt(k,n,{startAt:H,endAt:T,timelineTrack:vt(k)})}),f.push(u.length),u.push({...k,...Jt(k,n,{startAt:T,endAt:G,timelineTrack:vt(k)})}),s=!0;continue}f.push(u.length)}u.push(k)}return{overlays:s?u:e,selection:s?f:yt(t),changed:s}}function gi(e,t,n){const r=new Set(yt(t).filter(f=>!!e[f]));if(!r.size)return{audioClips:e,selection:[],changed:!1};let a=!1;const s=[],u=[];for(let f=0;f<e.length;f++){const v=e[f],k=Math.max(0,Number(v?.startAt)||0),H=Dt(v),G=k+H;if(r.has(f)&&n>k+Wt&&n<G-Wt){const T=(Number(v.in)||0)+(n-k),F=Math.max(0,T-(Number(v.in)||0)),j=Math.max(0,(Number(v.out)||0)-T);u.push(s.length),s.push({...v,track:Number.isInteger(v?.track)&&v.track>=0?v.track:f,out:T,fadeIn:Math.min(Number(v.fadeIn)||0,F),fadeOut:0}),u.push(s.length),s.push({...v,track:Number.isInteger(v?.track)&&v.track>=0?v.track:f,in:T,startAt:n,fadeIn:0,fadeOut:Math.min(Number(v.fadeOut)||0,j)}),a=!0;continue}r.has(f)&&u.push(s.length),s.push(v)}return{audioClips:a?s:e,selection:a?u:yt(t),changed:a}}function yi(e,t,n){const r=new Set(yt(t));let a=0;for(let s=0;s<e.length;s++){const u=e[s],f=Math.max(0,(Number(u?.out)||0)-(Number(u?.in)||0)),v=a+f;if(r.has(s)&&n>a+Wt&&n<v-Wt)return!0;a=v}return!1}function wi(e,t,n){return yt(t).some(r=>{const a=e[r];if(!Zt(a))return!1;const s=lt(a),u=Bt(a,s);return n>s+je&&n<u-je})}function ki(e,t,n){return yt(t).some(r=>{const a=e[r];if(!a)return!1;const s=Math.max(0,Number(a.startAt)||0),u=s+Dt(a);return n>s+Wt&&n<u-Wt})}function Ei(e,t){const n=t.getState(),r=n.clips??[],a=n.audioClips??[],s=n.overlays??[],u=$n(e,r),f=Mn(e,a),v=Dn(e,n);if(!u.length&&!f.length&&!v.length)return!1;let k=r,H=a,G=s,T=u,F=f,j=v,oe=!1;if(u.length){const Q=pi(k,u);k=Q.clips,T=Q.selection,oe=Q.changed||oe}if(f.length){const Q=fi(H,f);H=Q.audioClips,F=Q.selection,oe=Q.changed||oe}if(v.length){const Q=Mo(G,v);G=Q.overlays,j=Q.selection,oe=Q.changed||oe}return oe?(t.commit({clips:k,audioClips:H,overlays:G}),pn(e,{video:T,audio:F,text:j},{video:T.length?T[T.length-1]:null,audio:F.length?F[F.length-1]:null,text:j.length?j[j.length-1]:null}),!0):!1}function fr(e,t){const n=t.getState(),r=n.clips??[],a=n.audioClips??[],s=n.overlays??[],u=$n(e,r),f=Mn(e,a),v=Dn(e,n);let k=r,H=a,G=s,T=u,F=f,j=v,oe=!1;const Q=vi(k,u);Q.changed&&(k=Q.clips,T=Q.selection,oe=!0);const Z=Co(G,v);Z.changed&&(G=Z.overlays,j=Z.selection,oe=!0);const ie=hi(H,f);return ie.changed&&(H=ie.audioClips,F=ie.selection,oe=!0),oe?(t.commit({clips:k,audioClips:H,overlays:G}),pn(e,{video:T,audio:F,text:j},{video:T.length?T[T.length-1]:null,audio:F.length?F[F.length-1]:null,text:j.length?j[j.length-1]:null}),!0):!1}function Si(e,t){const n=t.getState(),r=n.clips??[],a=n.audioClips??[],s=n.overlays??[],u=yn(e),f=$n(e,r),v=Mn(e,a),k=Dn(e,n);let H=r,G=a,T=s,F=f,j=v,oe=k,Q=!1;if(f.length){const Z=xi(H,f,u);H=Z.clips,F=Z.selection,Q=Z.changed||Q}if(v.length){const Z=gi(G,v,u);G=Z.audioClips,j=Z.selection,Q=Z.changed||Q}if(k.length){const Z=bi(T,k,Math.max(Tn(t),u+je),u);T=Z.overlays,oe=Z.selection,Q=Z.changed||Q}return Q?(t.commit({clips:H,audioClips:G,overlays:T}),pn(e,{video:F,audio:j,text:oe},{video:F.length?F[F.length-1]:null,audio:j.length?j[j.length-1]:null,text:oe.length?oe[oe.length-1]:null}),!0):!1}function to(e,t){const n=document.createElement("div");n.className="me-video-text-field";const r=document.createElement("label");return r.textContent=e,n.append(r,t),n}function Yt(e){const t=document.createElement("button");return t.type="button",t.className="me-video-text-mini",t.textContent=e,t}function Li(e,t){const n=document.createElement("button");return n.type="button",n.className="me-video-text-preset",n.dataset.preset=t,n.textContent=e,n}const Ti=[{value:"300",label:"Light"},{value:"400",label:"Regular"},{value:"500",label:"Medium"},{value:"600",label:"Semibold"},{value:"700",label:"Bold"},{value:"800",label:"Extra Bold"}],vr={en:{content:"Content",preset:"Preset",styles:"Styles",size:"Size",fill:"Fill",decoration:"Decoration",italic:"Italic",underline:"Underline",strike:"Strike",case:"Case",caseNone:"None",uppercase:"Uppercase",lowercase:"Lowercase",capitalize:"Capitalize",alignLeft:"Left",alignCenter:"Center",alignRight:"Right",animations:"Animations",animation:"Animation",fontStroke:"Font stroke",fontShadow:"Font shadow",x:"X",y:"Y",blur:"Blur",transparent:"Transparent",none:"None"},zh:{content:"\u5185\u5BB9",preset:"\u9884\u8BBE",styles:"\u6837\u5F0F",size:"\u5927\u5C0F",fill:"\u586B\u5145",decoration:"\u4FEE\u9970",italic:"\u659C\u4F53",underline:"\u4E0B\u5212\u7EBF",strike:"\u5220\u9664\u7EBF",case:"\u5927\u5C0F\u5199",caseNone:"\u65E0",uppercase:"\u5168\u90E8\u5927\u5199",lowercase:"\u5168\u90E8\u5C0F\u5199",capitalize:"\u9996\u5B57\u6BCD\u5927\u5199",alignLeft:"\u5DE6\u5BF9\u9F50",alignCenter:"\u5C45\u4E2D",alignRight:"\u53F3\u5BF9\u9F50",animations:"\u52A8\u753B",animation:"\u52A8\u753B",fontStroke:"\u6587\u5B57\u63CF\u8FB9",fontShadow:"\u6587\u5B57\u9634\u5F71",x:"X",y:"Y",blur:"\u6A21\u7CCA",transparent:"\u900F\u660E",none:"\u65E0"},"zh-Hant":{content:"\u5167\u5BB9",preset:"\u9810\u8A2D",styles:"\u6A23\u5F0F",size:"\u5927\u5C0F",fill:"\u586B\u5145",decoration:"\u4FEE\u98FE",italic:"\u659C\u9AD4",underline:"\u5E95\u7DDA",strike:"\u522A\u9664\u7DDA",case:"\u5927\u5C0F\u5BEB",caseNone:"\u7121",uppercase:"\u5168\u90E8\u5927\u5BEB",lowercase:"\u5168\u90E8\u5C0F\u5BEB",capitalize:"\u9996\u5B57\u6BCD\u5927\u5BEB",alignLeft:"\u9760\u5DE6",alignCenter:"\u7F6E\u4E2D",alignRight:"\u9760\u53F3",animations:"\u52D5\u756B",animation:"\u52D5\u756B",fontStroke:"\u6587\u5B57\u63CF\u908A",fontShadow:"\u6587\u5B57\u9670\u5F71",x:"X",y:"Y",blur:"\u6A21\u7CCA",transparent:"\u900F\u660E",none:"\u7121"}},hr={en:{tool:"Ratio",title:"Ratio & canvas size",restore:"Restore",close:"Close",commonPresets:"Platform ratio presets",customSize:"Custom resolution",fitMode:"Canvas fill mode",width:"Width (px)",height:"Height (px)",lockRatio:"Lock ratio",unlockRatio:"Unlock ratio",quickPortrait:"1080p Portrait",quickLandscape:"1080p Landscape",summary:"Current output",baseOutput:"Base output",cover:"Crop to fill",contain:"Fit inside",force:"Stretch to fill",coverHint:"Fills the canvas and crops any overflow.",containHint:"Keeps the full frame and may add letterboxing.",forceHint:"Stretches the frame to the target size without cropping.",cinematic:"Cinematic",tablet:"Tablet"},zh:{tool:"\u6BD4\u4F8B",title:"\u6BD4\u4F8B\u4E0E\u753B\u5E03\u5C3A\u5BF8",restore:"\u6062\u590D",close:"\u5173\u95ED",commonPresets:"\u5E73\u53F0\u6BD4\u4F8B\u9884\u8BBE",customSize:"\u81EA\u5B9A\u4E49\u5206\u8FA8\u7387",fitMode:"\u753B\u9762\u586B\u5145\u9009\u9879",width:"\u5BBD\u5EA6 (px)",height:"\u9AD8\u5EA6 (px)",lockRatio:"\u9501\u5B9A\u6BD4\u4F8B",unlockRatio:"\u89E3\u9501\u6BD4\u4F8B",quickPortrait:"1080p \u7AD6\u5C4F",quickLandscape:"1080p \u6A2A\u5C4F",summary:"\u5F53\u524D\u8F93\u51FA",baseOutput:"\u539F\u59CB\u8F93\u51FA",cover:"\u88C1\u526A\u94FA\u6EE1",contain:"\u5B8C\u6574\u663E\u793A",force:"\u62C9\u4F38\u94FA\u6EE1",coverHint:"\u94FA\u6EE1\u753B\u5E03\uFF0C\u591A\u4F59\u533A\u57DF\u4F1A\u88AB\u88C1\u526A\u3002",containHint:"\u5B8C\u6574\u4FDD\u7559\u753B\u9762\uFF0C\u53EF\u80FD\u51FA\u73B0\u7559\u767D\u3002",forceHint:"\u5F3A\u5236\u62C9\u4F38\u5230\u76EE\u6807\u5C3A\u5BF8\uFF0C\u4E0D\u88C1\u526A\u3002",cinematic:"\u7535\u5F71\u5BBD\u5C4F",tablet:"\u5E73\u677F"},"zh-Hant":{tool:"\u6BD4\u4F8B",title:"\u6BD4\u4F8B\u8207\u756B\u5E03\u5C3A\u5BF8",restore:"\u9084\u539F",close:"\u95DC\u9589",commonPresets:"\u5E73\u53F0\u6BD4\u4F8B\u9810\u8A2D",customSize:"\u81EA\u8A02\u89E3\u6790\u5EA6",fitMode:"\u756B\u9762\u586B\u5145\u9078\u9805",width:"\u5BEC\u5EA6 (px)",height:"\u9AD8\u5EA6 (px)",lockRatio:"\u9396\u5B9A\u6BD4\u4F8B",unlockRatio:"\u89E3\u9396\u6BD4\u4F8B",quickPortrait:"1080p \u76F4\u5F0F",quickLandscape:"1080p \u6A6B\u5F0F",summary:"\u76EE\u524D\u8F38\u51FA",baseOutput:"\u539F\u59CB\u8F38\u51FA",cover:"\u88C1\u5207\u92EA\u6EFF",contain:"\u5B8C\u6574\u986F\u793A",force:"\u62C9\u4F38\u92EA\u6EFF",coverHint:"\u92EA\u6EFF\u756B\u5E03\uFF0C\u591A\u9918\u5340\u57DF\u6703\u88AB\u88C1\u5207\u3002",containHint:"\u5B8C\u6574\u4FDD\u7559\u756B\u9762\uFF0C\u53EF\u80FD\u51FA\u73FE\u7559\u767D\u3002",forceHint:"\u5F37\u5236\u62C9\u4F38\u81F3\u76EE\u6A19\u5C3A\u5BF8\uFF0C\u4E0D\u88C1\u5207\u3002",cinematic:"\u96FB\u5F71\u5BEC\u87A2\u5E55",tablet:"\u5E73\u677F"}},Mi=[{id:"facebook-post",platform:"Facebook",type:"Post",iconText:"f",iconTheme:"facebook",ratios:["1:1","4:5","16:9"]},{id:"facebook-story",platform:"Facebook",type:"Story",iconText:"f",iconTheme:"facebook",ratios:["9:16"]},{id:"instagram-post",platform:"Instagram",type:"Post",iconText:"IG",iconTheme:"instagram",ratios:["1:1","4:5","16:9"]},{id:"instagram-story",platform:"Instagram",type:"Story",iconText:"IG",iconTheme:"instagram",ratios:["9:16"]},{id:"tiktok-photo",platform:"TikTok",type:"Photo",iconText:"T",iconTheme:"tiktok",ratios:["1:1","4:5","9:16"]},{id:"x-post",platform:"X",type:"Post",iconText:"X",iconTheme:"x",ratios:["1:1","16:9"]},{id:"linkedin-post",platform:"LinkedIn",type:"Post",iconText:"in",iconTheme:"linkedin",ratios:["1:1","16:9"]},{id:"pinterest-post",platform:"Pinterest",type:"Post",iconText:"P",iconTheme:"pinterest",ratios:["2:3","1:1"]},{id:"reddit-media",platform:"Reddit",type:"Media",iconText:"R",iconTheme:"reddit",ratios:["1:1","16:9"]},{id:"threads-post",platform:"Threads",type:"Post",iconText:"@",iconTheme:"threads",ratios:["1:1","4:5","16:9"]},{id:"telegram-post",platform:"Telegram",type:"Post",iconText:"TG",iconTheme:"telegram",ratios:["1:1","16:9"]}],Ci=["9:16","16:9","1:1","4:5","2:3","3:2"],xr={en:{tool:"Sticker",title:"Stickers",uploadTitle:"Upload sticker",uploadHint:"Click or drop an image here",uploadFormats:"Supports PNG, JPG, WEBP, SVG",libraryTitle:"Built-in sticker library",classicTitle:"Classic stickers",vibeTitle:"Vibe stickers",shapeTitle:"Shape stickers",defaultLabel:"Sticker",uploadedLabel:"Image sticker",emojiLabel:"Emoji sticker"},zh:{tool:"\u8D34\u7EB8",title:"\u8D34\u7EB8",uploadTitle:"\u81EA\u5B9A\u4E49\u672C\u5730\u56FE\u7247\u8D34\u7EB8",uploadHint:"\u70B9\u51FB\u6216\u62D6\u62FD\u56FE\u7247\u5230\u8FD9\u91CC",uploadFormats:"\u652F\u6301 PNG\u3001JPG\u3001WEBP\u3001SVG",libraryTitle:"\u5185\u7F6E\u7ECF\u5178\u8D34\u7EB8\u5E93",classicTitle:"\u7ECF\u5178\u8D34\u7EB8",vibeTitle:"\u6C1B\u56F4\u8D34\u7EB8",shapeTitle:"\u5F62\u72B6\u8D34\u7EB8",defaultLabel:"\u8D34\u7EB8",uploadedLabel:"\u56FE\u7247\u8D34\u7EB8",emojiLabel:"\u8868\u60C5\u8D34\u7EB8"},"zh-Hant":{tool:"\u8CBC\u7D19",title:"\u8CBC\u7D19",uploadTitle:"\u81EA\u8A02\u672C\u6A5F\u5716\u7247\u8CBC\u7D19",uploadHint:"\u9EDE\u64CA\u6216\u62D6\u62FD\u5716\u7247\u5230\u9019\u88E1",uploadFormats:"\u652F\u63F4 PNG\u3001JPG\u3001WEBP\u3001SVG",libraryTitle:"\u5167\u5EFA\u7D93\u5178\u8CBC\u7D19\u5EAB",classicTitle:"\u7D93\u5178\u8CBC\u7D19",vibeTitle:"\u6C1B\u570D\u8CBC\u7D19",shapeTitle:"\u5F62\u72C0\u8CBC\u7D19",defaultLabel:"\u8CBC\u7D19",uploadedLabel:"\u5716\u7247\u8CBC\u7D19",emojiLabel:"\u8868\u60C5\u8CBC\u7D19"}},No={en:{tool:"Color",title:"Color",filterTool:"Filter",filterTitle:"Filter",presets:"Filter presets",adjustments:"Adjustments",reset:"Reset",brightness:"Brightness",contrast:"Contrast",saturation:"Saturation",temperature:"Temperature",tint:"Tint",vibrance:"Vibrance",gamma:"Gamma",colorSection:"Color",toneSection:"Brightness",effectsSection:"Effects",highlights:"Highlights",shadows:"Shadows",whites:"Whites",blacks:"Blacks",lightSense:"Light Sense",sharpen:"Sharpen",clarity:"Clarity",grain:"Grain",fade:"Fade",vignette:"Vignette",presetNames:{none:"Normal",sepia:"Retro",cool:"Cold",warm:"Warm",vivid:"Cyber",bw:"B&W"}},zh:{tool:"\u8C03\u8272",title:"\u8C03\u8272",filterTool:"\u6EE4\u955C",filterTitle:"\u6EE4\u955C",presets:"\u6EE4\u955C\u9884\u8BBE",adjustments:"\u753B\u9762\u5FAE\u8C03",reset:"\u91CD\u7F6E",brightness:"\u4EAE\u5EA6",contrast:"\u5BF9\u6BD4\u5EA6",saturation:"\u9971\u548C\u5EA6",temperature:"\u8272\u6E29",tint:"\u8272\u8C03",vibrance:"\u81EA\u7136\u9971\u548C\u5EA6",gamma:"Gamma",colorSection:"\u8272\u5F69",toneSection:"\u660E\u5EA6",effectsSection:"\u6548\u679C",highlights:"\u9AD8\u5149",shadows:"\u9634\u5F71",whites:"\u767D\u8272",blacks:"\u9ED1\u8272",lightSense:"\u5149\u611F",sharpen:"\u9510\u5316",clarity:"\u6E05\u6670",grain:"\u9897\u7C92",fade:"\u892A\u8272",vignette:"\u6697\u89D2",presetNames:{none:"\u539F\u753B (Normal)",sepia:"\u590D\u53E4 (Retro)",cool:"\u51B7\u8272 (Cold)",warm:"\u6696\u9633 (Warm)",vivid:"\u8D5B\u535A (Cyber)",bw:"\u9ED1\u767D (B&W)"}},"zh-Hant":{tool:"\u8ABF\u8272",title:"\u8ABF\u8272",filterTool:"\u6FFE\u93E1",filterTitle:"\u6FFE\u93E1",presets:"\u6FFE\u93E1\u9810\u8A2D",adjustments:"\u756B\u9762\u5FAE\u8ABF",reset:"\u91CD\u8A2D",brightness:"\u4EAE\u5EA6",contrast:"\u5C0D\u6BD4\u5EA6",saturation:"\u98FD\u548C\u5EA6",temperature:"\u8272\u6EAB",tint:"\u8272\u8ABF",vibrance:"\u81EA\u7136\u98FD\u548C\u5EA6",gamma:"Gamma",colorSection:"\u8272\u5F69",toneSection:"\u660E\u5EA6",effectsSection:"\u6548\u679C",highlights:"\u9AD8\u5149",shadows:"\u9670\u5F71",whites:"\u767D\u8272",blacks:"\u9ED1\u8272",lightSense:"\u5149\u611F",sharpen:"\u92B3\u5316",clarity:"\u6E05\u6670",grain:"\u9846\u7C92",fade:"\u892A\u8272",vignette:"\u6697\u89D2",presetNames:{none:"\u539F\u756B (Normal)",sepia:"\u5FA9\u53E4 (Retro)",cool:"\u51B7\u8272 (Cold)",warm:"\u6696\u967D (Warm)",vivid:"\u8CFD\u535A (Cyber)",bw:"\u9ED1\u767D (B&W)"}}};function Ni(e){const t=Xt(e);return{...xr.en,...xr[t]??{}}}function Ao(e){const t=Xt(e),n=No[t]??{};return{...No.en,...n,presetNames:{...No.en.presetNames,...n.presetNames??{}}}}function Cn(e,t,n="rgba(255,255,255,0.16)"){let r="";return e==="triangle"?r=`<polygon points="128,28 224,220 32,220" fill="${t}" stroke="${n}" stroke-width="8" stroke-linejoin="round"/>`:e==="circle"?r=`<circle cx="128" cy="128" r="94" fill="${t}" stroke="${n}" stroke-width="8"/>`:e==="square"?r=`<rect x="40" y="40" width="176" height="176" rx="40" fill="${t}" stroke="${n}" stroke-width="8"/>`:e==="diamond"?r=`<polygon points="128,24 224,128 128,232 32,128" fill="${t}" stroke="${n}" stroke-width="8" stroke-linejoin="round"/>`:e==="star"?r=`<polygon points="128,24 154,92 228,96 170,142 188,220 128,176 68,220 86,142 28,96 102,92" fill="${t}" stroke="${n}" stroke-width="8" stroke-linejoin="round"/>`:e==="heart"?r=`<path d="M128 220c-7-7-18-16-30-27C64 165 38 141 38 102c0-28 20-50 48-50 18 0 33 10 42 24 9-14 24-24 42-24 28 0 48 22 48 50 0 39-26 63-60 91-12 11-23 20-30 27Z" fill="${t}" stroke="${n}" stroke-width="8" stroke-linejoin="round"/>`:r=`<rect x="40" y="40" width="176" height="176" rx="40" fill="${t}" stroke="${n}" stroke-width="8"/>`,`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">${r}</svg>`)}`}function Ai(e){return[{id:"classic",title:e.classicTitle,items:[{id:"heart-eyes",emoji:"\u{1F60D}",label:`${e.emojiLabel} 1`},{id:"joy",emoji:"\u{1F602}",label:`${e.emojiLabel} 2`},{id:"grin",emoji:"\u{1F603}",label:`${e.emojiLabel} 3`},{id:"pray",emoji:"\u{1F64F}",label:`${e.emojiLabel} 4`},{id:"thumbs-up",emoji:"\u{1F44D}",label:`${e.emojiLabel} 5`},{id:"hundred",emoji:"\u{1F4AF}",label:`${e.emojiLabel} 6`},{id:"cat-smile",emoji:"\u{1F63A}",label:`${e.emojiLabel} 7`},{id:"cat-happy",emoji:"\u{1F638}",label:`${e.emojiLabel} 8`},{id:"paw",emoji:"\u{1F43E}",label:`${e.emojiLabel} 9`},{id:"fish",emoji:"\u{1F41F}",label:`${e.emojiLabel} 10`}]},{id:"vibe",title:e.vibeTitle,items:[{id:"sparkles",emoji:"\u2728",label:`${e.emojiLabel} 5`},{id:"heart",emoji:"\u{1F497}",label:`${e.emojiLabel} 6`},{id:"fire",emoji:"\u{1F525}",label:`${e.emojiLabel} 7`},{id:"party",emoji:"\u{1F389}",label:`${e.emojiLabel} 8`}]},{id:"shape",title:e.shapeTitle,items:[{id:"triangle",src:Cn("triangle","#f97316"),label:"Triangle"},{id:"circle",src:Cn("circle","#22c55e"),label:"Circle"},{id:"square",src:Cn("square","#3b82f6"),label:"Square"},{id:"diamond",src:Cn("diamond","#8b5cf6"),label:"Diamond"},{id:"star",src:Cn("star","#facc15"),label:"Star"},{id:"heart-shape",src:Cn("heart","#fb7185"),label:"Heart"}]}]}function Oi(e){const t=Xt(e),n={...vr.en,...vr[t]??{}};return n.searchFont||(n.searchFont=t==="zh-Hant"?"\u641C\u5C0B\u5B57\u9AD4...":t==="zh"?"\u641C\u7D22\u5B57\u4F53...":"Search font..."),n.loadingFonts||(n.loadingFonts=t==="zh-Hant"?"\u6B63\u5728\u8B80\u53D6\u5B57\u9AD4...":t==="zh"?"\u6B63\u5728\u8BFB\u53D6\u5B57\u4F53...":"Loading fonts..."),n.noFonts||(n.noFonts=t==="zh-Hant"?"\u627E\u4E0D\u5230\u5B57\u9AD4":t==="zh"?"\u6CA1\u6709\u627E\u5230\u5B57\u4F53":"No fonts found"),n.sampleText||(n.sampleText=Uo),n}function zi(e){const t=Xt(e);return{...hr.en,...hr[t]??{}}}const br={en:{tool:"Annotate",title:"Annotate",hint:"Configure the annotation tools here.",tools:"Tools",color:"Color",custom:"Custom",width:"Line width",reset:"Reset",brush:"Brush",eraser:"Eraser",line:"Line",arrow:"Arrow",rectangle:"Rectangle",ellipse:"Ellipse"},zh:{tool:"\u6807\u6CE8",title:"\u6807\u6CE8",hint:"\u5728\u8FD9\u91CC\u914D\u7F6E\u6807\u6CE8\u5DE5\u5177\u7684\u6837\u5F0F\u53C2\u6570\u3002",tools:"\u5DE5\u5177",color:"\u989C\u8272",custom:"\u81EA\u5B9A\u4E49",width:"\u7EBF\u5BBD",reset:"\u91CD\u7F6E",brush:"\u753B\u7B14",eraser:"\u6A61\u76AE",line:"\u76F4\u7EBF",arrow:"\u7BAD\u5934",rectangle:"\u77E9\u5F62",ellipse:"\u692D\u5706"},"zh-Hant":{tool:"\u6A19\u8A3B",title:"\u6A19\u8A3B",hint:"\u5728\u9019\u88E1\u8A2D\u5B9A\u6A19\u8A3B\u5DE5\u5177\u7684\u6A23\u5F0F\u53C3\u6578\u3002",tools:"\u5DE5\u5177",color:"\u984F\u8272",custom:"\u81EA\u8A02",width:"\u7DDA\u5BEC",reset:"\u91CD\u8A2D",brush:"\u756B\u7B46",eraser:"\u6A61\u76AE",line:"\u76F4\u7DDA",arrow:"\u7BAD\u982D",rectangle:"\u77E9\u5F62",ellipse:"\u6A62\u5713"}};function Pi(e){const t=Xt(e);return br[t]??br.en}const gr=[{key:"brush"},{key:"eraser"},{key:"line"},{key:"arrow"},{key:"rectangle"},{key:"ellipse"}],_n=2,jn=24,Nn=14,ja=["pen","line","arrow","rect","ellipse"],Hi={brush:"pen",line:"line",arrow:"arrow",rectangle:"rect",ellipse:"ellipse"},yr=["#ffffff","#ff4d4f","#ff7a45","#ffa940","#fadb14","#95de64","#52c41a","#13c2c2","#40a9ff","#2f54eb","#7c7cf0","#eb2f96","#722ed1","#000000"],sn={tool:"brush",color:"#ff4d4f",width:4};function Ii(e){switch(e){case"eraser":return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M7.2 15.8 14.9 8a1.8 1.8 0 0 1 2.6 0l2.6 2.6a1.8 1.8 0 0 1 0 2.6l-5.3 5.3a2.4 2.4 0 0 1-1.7.7h-4a2.4 2.4 0 0 1-1.7-.7l-1-1a1.2 1.2 0 0 1 0-1.7Z" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"/><path d="M13.1 19.2h6.2" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/></svg>';case"line":return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M5 19 19 5" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/></svg>';case"arrow":return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M5 16 15 6" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/><path d="M10.5 6H15v4.5" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/></svg>';case"rectangle":return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="5.5" y="5.5" width="13" height="13" rx="1.8" fill="none" stroke="currentColor" stroke-width="1.8"/></svg>';case"ellipse":return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><ellipse cx="12" cy="12" rx="6.6" ry="6.6" fill="none" stroke="currentColor" stroke-width="1.8"/></svg>';default:return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m8.2 15.8 7.9-7.9a1.9 1.9 0 0 1 2.7 2.7l-7.9 7.9" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/><path d="M7.5 16.5c-.5 2.5-2.4 3.8-3.8 4 .2-1.5 1.5-3.3 4-3.8Z" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/></svg>'}}function Ri(){return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m5 19 3.9-1 9.2-9.2a1.8 1.8 0 0 0 0-2.6l-.3-.3a1.8 1.8 0 0 0-2.6 0L6 15.1 5 19Z" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/><path d="m13.7 7.3 3 3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><path d="m5 19 3.3-3.3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>'}function wr(e,t){switch(e?.type){case"pen":return t.brush;case"line":return t.line;case"arrow":return t.arrow;case"rect":return t.rectangle;case"ellipse":return t.ellipse;default:return t.tool}}function Ya(e){switch(e?.type){case"pen":return"brush";case"line":return"line";case"arrow":return"arrow";case"rect":return"rectangle";case"ellipse":return"ellipse";default:return sn.tool}}function no(e=sn){const t=gr.some(r=>r.key===e?.tool)?e.tool:sn.tool,n=Er(e?.color);return{tool:t,color:n,width:ae(Math.round(Number(e?.width)||sn.width),_n,jn)}}function Oo(e,t){return e?.tool===t?.tool&&e?.color===t?.color&&Number(e?.width)===Number(t?.width)}function kr(e){return Oo(e,sn)}function Fi(e){return`${ae(Math.round(Number(e)||sn.width),_n,jn)}px`}function Er(e){const t=String(e??"").trim().toLowerCase();return/^#?[0-9a-f]{3}$/.test(t)?`#${t.replace("#","").split("").map(r=>`${r}${r}`).join("")}`:/^#?[0-9a-f]{6}$/.test(t)?`#${t.replace("#","")}`:sn.color}function oo(e){const t=Er(e);return{r:Number.parseInt(t.slice(1,3),16),g:Number.parseInt(t.slice(3,5),16),b:Number.parseInt(t.slice(5,7),16)}}function ro(e,t,n){return`#${[e,t,n].map(r=>ae(Math.round(Number(r)||0),0,255).toString(16).padStart(2,"0")).join("")}`}function zo(e,t,n){const r=ae(Number(e)||0,0,255)/255,a=ae(Number(t)||0,0,255)/255,s=ae(Number(n)||0,0,255)/255,u=Math.max(r,a,s),f=Math.min(r,a,s),v=u-f;let k=0;return v>0&&(u===r?k=60*((a-s)/v%6):u===a?k=60*((s-r)/v+2):k=60*((r-a)/v+4)),k<0&&(k+=360),{h:k,s:u<=0?0:v/u,v:u}}function Po(e,t,n){const r=((Number(e)||0)%360+360)%360,a=ae(Number(t)||0,0,1),s=ae(Number(n)||0,0,1),u=s*a,f=r/60,v=u*(1-Math.abs(f%2-1));let k=0,H=0,G=0;f>=0&&f<1?(k=u,H=v):f<2?(k=v,H=u):f<3?(H=u,G=v):f<4?(H=v,G=u):f<5?(k=v,G=u):(k=u,G=v);const T=s-u;return{r:Math.round((k+T)*255),g:Math.round((H+T)*255),b:Math.round((G+T)*255)}}function Bi(e){const t=Po(e,1,1);return ro(t.r,t.g,t.b)}const $i=["none","sepia","cool","warm","vivid","bw"],Va=["brightness","contrast","saturation","temperature","tint","vibrance","gamma"],An={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},Ho=Object.keys(An);function Sr(e){return[{title:e.colorSection,items:[{key:"temperature",label:e.temperature,format:"offset",min:-1,max:1},{key:"tint",label:e.tint,format:"offset",min:-1,max:1},{key:"saturation",label:e.saturation,format:"percent",min:-1,max:1},{key:"vibrance",label:e.vibrance,format:"offset",min:-1,max:1},{key:"gamma",label:e.gamma,format:"percent",min:-1,max:1}]},{title:e.toneSection,items:[{key:"brightness",label:e.brightness,format:"percent",min:-1,max:1},{key:"contrast",label:e.contrast,format:"percent",min:-1,max:1},{key:"highlights",label:e.highlights,format:"offset",min:-1,max:1},{key:"shadows",label:e.shadows,format:"offset",min:-1,max:1},{key:"whites",label:e.whites,format:"offset",min:-1,max:1},{key:"blacks",label:e.blacks,format:"offset",min:-1,max:1},{key:"lightSense",label:e.lightSense,format:"offset",min:-1,max:1}]},{title:e.effectsSection,items:[{key:"sharpen",label:e.sharpen,format:"amount",min:0,max:1},{key:"clarity",label:e.clarity,format:"amount",min:0,max:1},{key:"grain",label:e.grain,format:"amount",min:0,max:1},{key:"fade",label:e.fade,format:"amount",min:0,max:1},{key:"vignette",label:e.vignette,format:"amount",min:0,max:1}]}]}function Di(e){if(typeof e.applyMut=="function"){e.applyMut(t=>({...t,filters:{...t.filters,...An}}));return}e.setFilters({...An})}function _i(e){const t=new Map(jr.map(n=>[n.id,n]));return $i.map(n=>{if(n==="none")return{id:"",css:"",label:e.presetNames.none};const r=t.get(n);return r?{...r,label:e.presetNames[n]??r.label??n}:null}).filter(Boolean)}function Lr(e,t="percent"){if(t==="offset"){const n=Math.round((Number(e)||0)*100);return n>0?`+${n}`:`${n}`}return t==="amount"?`${Math.round((Number(e)||0)*100)}%`:`${Math.round((1+(Number(e)||0))*100)}%`}function Io(e){return[e?.textContent,e?.getAttribute?.("title"),e?.getAttribute?.("aria-label")].filter(Boolean).join(" ").trim().toLowerCase()}function Ro(e){return e instanceof HTMLButtonElement?(e.dataset.meTrimHidden="true",e):e??null}function ji(e){return e instanceof HTMLButtonElement?(e.dataset.meAnnotateHidden="true",e):e??null}function io(e){const t=["trim","timeline","\u526A\u8F91","\u65F6\u95F4\u8F74"];return Ro(e.find(n=>{const r=Io(n);return t.some(a=>r.includes(a))})??e[0]??null)}function Yi(e){const t=["annotate","annotation","markup","draw","doodle","\u6807\u6CE8","\u5857\u9E26","\u5857\u9D09"];return ji(e.find(n=>{const r=Io(n);return t.some(a=>r.includes(a))})??null)}function Tr(e,t,n){try{const r=document.createElement("canvas");r.width=208,r.height=118;const a=r.getContext("2d");if(!a)return"";const s=t/n,u=r.width/r.height;let f=0,v=0,k=t,H=n;return s>u?(k=n*u,f=(t-k)/2):s<u&&(H=t/u,v=(n-H)/2),a.drawImage(e,f,v,k,H,0,0,r.width,r.height),r.toDataURL("image/jpeg",.82)}catch{return""}}function Vi(e){const t=e.querySelector(".me-video-canvas-stage canvas");if(t instanceof HTMLCanvasElement&&t.width>8&&t.height>8)return Tr(t,t.width,t.height);const n=e.querySelector("video");return n instanceof HTMLVideoElement&&n.videoWidth>8&&n.videoHeight>8?Tr(n,n.videoWidth,n.videoHeight):""}function Xi(e){const t=String(e??"").split(":").map(a=>Number(a));if(t.length!==2)return null;const[n,r]=t;return!(n>0)||!(r>0)?null:n/r}function ao(e,t=1080){const n=Xi(e)??1;return n>=1?{w:Math.max(2,Vt(t*n)),h:Math.max(2,Vt(t))}:{w:Math.max(2,Vt(t)),h:Math.max(2,Vt(t/n))}}function qi(){return Mi.map(e=>({...e,ratios:e.ratios.map(t=>({ratio:t,...ao(t)}))}))}function Mr(e){return`${e.platform} ${e.type}`}function Wi(e){switch(e.id){case"facebook-post":return"FB Post";case"facebook-story":return"FB Story";case"instagram-post":return"IG Post";case"instagram-story":return"IG Story";case"tiktok-photo":return"TikTok";case"x-post":return"X Post";case"linkedin-post":return"LinkedIn";case"pinterest-post":return"Pinterest";case"reddit-media":return"Reddit";case"threads-post":return"Threads";case"telegram-post":return"Telegram";default:return Mr(e)}}function Ki(e){return Ci.map(t=>{const n=ao(t),r=e.filter(a=>a.ratios.some(s=>s.ratio===t));return r.length?{ratio:t,...n,groups:r,hint:r.map(a=>Mr(a)).join(" / "),tags:r.map(a=>Wi(a))}:null}).filter(Boolean)}function On(e){return`${Math.max(2,Vt(e?.w??0))} x ${Math.max(2,Vt(e?.h??0))} px`}function Cr(e){const t=e?.canvas??{w:1080,h:1920};return jo(t,{...e,scale:void 0})}function Yn(e){return e?.scale?{w:Math.max(2,Vt(e.scale.width)),h:Math.max(2,Vt(e.scale.height))}:Cr(e)}function Fo(e){return e==="contain"||e==="force"?e:"cover"}function fn(e,t){const n=Number(e),r=Number.isFinite(n)&&n>0?n:t;return Math.max(2,Vt(r||2))}function Ui(e,t){const n=Math.max(2,Vt(t?.w??0)),r=Math.max(2,Vt(t?.h??0));return e.find(a=>Math.abs(a.w-n)<=2&&Math.abs(a.h-r)<=2)??null}function Gi(e,t){switch(Fo(t)){case"contain":return e.containHint;case"force":return e.forceHint;default:return e.coverHint}}function so(e,t){e.replaceChildren();for(const n of t){const r=document.createElement("option");r.value=n.value,r.textContent=n.label,e.appendChild(r)}}function Vn(e=[],t=[]){const n=typeof Intl<"u"?new Intl.Collator(void 0,{sensitivity:"base",numeric:!0}):null,r=new Set;return[...e,...t].map(a=>String(a??"").trim()).filter(Boolean).filter(a=>{const s=a.toLowerCase();return r.has(s)?!1:(r.add(s),!0)}).sort((a,s)=>n?n.compare(a,s):a.localeCompare(s))}function Bo(e){return`"${String(e??"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}", ${qn}`}function lo(e){const t=String(e??"").trim();return qr[t]||t}function $o(e){const t=String(e??"").trim(),n=lo(t);return n&&n!==t?`${n} (${t})`:t}function Zi(e){const t=String(e??"").trim();return`${t} ${lo(t)} ${$o(t)}`.toLowerCase()}function Nr(e){return/[\u3400-\u9fff\uf900-\ufaff]/.test(String(e??""))}function Ji(e){const t=String(e??"").trim().toLowerCase();return t?Wr.some(n=>t.includes(n))?!0:Nr(lo(e)):!1}function Qi(e,t=!1){const n=Vn(e);if(!t)return n;const r=[],a=[];for(const s of n)Ji(s)?r.push(s):a.push(s);return[...r,...a]}async function ea(){return Wn||(Wn=(async()=>{const e=Vn(Xo);if(typeof window>"u"||typeof window.queryLocalFonts!="function")return e;try{const n=(await window.queryLocalFonts()).map(r=>r?.family||r?.fullName||"").filter(Boolean);return Vn(n,e)}catch{return e}})(),Wn)}function ta(e){const t=document.createElement("div");t.className="me-video-font-picker";const n=document.createElement("button");n.type="button",n.className="me-video-font-picker-trigger";const r=document.createElement("span");r.className="me-video-font-picker-label";const a=document.createElement("span");a.className="me-video-font-picker-chevron",a.textContent="v",n.append(r,a);const s=document.createElement("div");s.className="me-video-font-picker-dropdown",s.hidden=!0;const u=document.createElement("label");u.className="me-video-font-picker-search";const f=document.createElement("span");f.className="me-video-font-picker-search-icon",f.innerHTML='<svg viewBox="0 0 16 16" fill="none" aria-hidden="true"><circle cx="7" cy="7" r="4.5" stroke="currentColor" stroke-width="1.4"></circle><path d="M10.5 10.5L14 14" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"></path></svg>';const v=document.createElement("input");v.type="search",v.className="me-video-font-picker-search-input",v.placeholder=e.searchFont,v.autocomplete="off",v.spellcheck=!1;const k=document.createElement("div");k.className="me-video-font-picker-list",u.append(f,v),s.append(u,k),t.append(n,s);let H=!1,G=!1,T=!1,F="Arial",j=Vn(Xo),oe=!1;const Q=typeof requestAnimationFrame=="function"?requestAnimationFrame:Y=>setTimeout(Y,0);function Z(){F||(F="Arial"),j=Vn(j,[F])}function ie(Y){const L=document.createElement("div");return L.className="me-video-font-picker-message",L.textContent=Y,L}function he(Y){const L=document.createElement("button");L.type="button",L.className="me-video-font-picker-option",Y===F&&L.classList.add("is-active"),L.dataset.family=Y;const B=document.createElement("span");B.className="me-video-font-picker-option-name",B.textContent=$o(Y),B.style.fontFamily=Bo(Y);const q=document.createElement("span");return q.className="me-video-font-picker-option-preview",q.textContent=e.sampleText||Uo,q.style.fontFamily=Bo(Y),L.append(B,q),L.addEventListener("click",()=>{x(Y),t.dispatchEvent(new CustomEvent("fontchange",{detail:{value:Y}})),te(!1),n.focus()}),L}function ne(){const Y=F||"Arial";r.textContent=lo(Y),r.style.fontFamily=Bo(F||"Arial"),n.title=$o(Y),n.disabled=G}function xe(){if(k.replaceChildren(),!H)return;if(T){k.appendChild(ie(e.loadingFonts));return}Z();const Y=String(v.value??"").trim().toLowerCase(),L=Qi(j.filter(B=>!Y||Zi(B).includes(Y)),oe);if(!L.length){k.appendChild(ie(e.noFonts));return}for(const B of L)k.appendChild(he(B))}function te(Y){G&&Y||(H=!!Y,t.classList.toggle("is-open",H),s.hidden=!H,H?Q(()=>{v.focus(),v.select()}):v.value="",xe())}async function w(){if(!T){T=!0,xe();try{j=await ea(),Z()}finally{T=!1,xe()}}}function x(Y,{silent:L=!1}={}){F=String(Y??"").trim()||"Arial",Z(),ne(),!L&&H&&xe()}function E(){return F||"Arial"}function C(Y){G=!!Y,G&&te(!1),ne(),v.disabled=G}function y(Y){const L=Nr(Y);oe!==L&&(oe=L,H&&xe())}function O(Y){H&&(t.contains(Y.target)||te(!1))}return n.addEventListener("click",async()=>{const Y=!H;te(Y),Y&&await w()}),v.addEventListener("input",()=>xe()),document.addEventListener("pointerdown",O,!0),x("Arial",{silent:!0}),C(!1),{wrap:t,setValue:x,getValue:E,setDisabled:C,setContextText:y,destroy(){document.removeEventListener("pointerdown",O,!0)}}}function na(e){const t=String(e??"").trim().toLowerCase();return/^#([0-9a-f]{3}|[0-9a-f]{6})$/.test(t)?t.length===7?t:`#${t.slice(1).split("").map(n=>`${n}${n}`).join("")}`:null}function vn(e,t="#ffffff"){const n=String(e??"").trim();if(!n)return t;if(n.toLowerCase()==="transparent")return"transparent";const r=na(n);if(r)return r;const a=n.match(/^rgba?\(([^)]+)\)$/i);if(a){const s=a[1].split(",").slice(0,3).map(u=>ae(Math.round(Number(u.trim())||0),0,255));if(s.length===3)return`#${s.map(u=>u.toString(16).padStart(2,"0")).join("")}`}return t}function Tt(e,t,n=""){const r=document.createElement("div");r.className=`me-video-text-row${n?` ${n}`:""}`;const a=document.createElement("label");return a.className="me-video-text-row-label",a.textContent=e,r.append(a,t),r}function Kt(e){const t=document.createElement("section");t.className="me-video-text-section";const n=document.createElement("h4");n.className="me-video-text-section-title",n.textContent=e;const r=document.createElement("div");return r.className="me-video-text-section-body",t.append(n,r),{section:t,body:r,title:n}}function co({allowTransparent:e=!1,fallback:t="#ffffff",transparentLabel:n="Transparent"}={}){const r=document.createElement("div");r.className="me-video-text-color-control";const a=document.createElement("input");a.type="color",a.className="me-video-text-color-swatch",a.value=vn(t,"#ffffff");const s=document.createElement("input");s.type="text",s.className="me-video-text-input me-video-text-color-text",s.spellcheck=!1,r.append(a,s);let u=null;e&&(u=document.createElement("button"),u.type="button",u.className="me-video-text-toggle me-video-text-transparent-toggle",u.textContent=n,r.appendChild(u));function f(){return r.dataset.transparent==="true"}function v(T){r.dataset.transparent=T?"true":"false",u?.classList.toggle("is-active",T),a.disabled=T,T?s.value="transparent":(!s.value||s.value==="transparent")&&(s.value=a.value||vn(t,"#ffffff"))}function k(T){if(e&&String(T??"").trim().toLowerCase()==="transparent"){v(!0);return}const F=vn(T,vn(t,"#ffffff"));a.value=F==="transparent"?vn(t,"#ffffff"):F,s.value=F==="transparent"?"transparent":F,e&&v(F==="transparent")}function H(){return e&&f()?"transparent":vn(s.value||a.value,a.value||vn(t,"#ffffff"))}function G(T){a.disabled=T||e&&f(),s.disabled=T,u&&(u.disabled=T)}return k(t),{wrap:r,swatch:a,text:s,transparentButton:u,setTransparent:v,setValue:k,getValue:H,setDisabled:G}}function uo(e){const t=e.querySelector(".me-video-workspace");if(!t)return null;let n=t.querySelector(".me-video-inspector-rail");return n||(n=document.createElement("aside"),n.className="me-video-inspector-rail",n.hidden=!0,t.appendChild(n)),n}function rn(e,t){const n=uo(e);return n?(t.parentElement!==n&&n.appendChild(t),n):null}function Ht(e){const t=uo(e);if(!t)return;const n=[...t.children].some(r=>r instanceof HTMLElement&&!r.hidden);t.hidden=!n}function Ar(e,t,n){const r=uo(e);if(!(!r||!(t instanceof HTMLElement))){for(const a of r.children)if(!(!(a instanceof HTMLElement)||a===t)){if(n){a.dataset.meInspectorPrevHidden||(a.dataset.meInspectorPrevHidden=a.hidden?"true":"false"),a.hidden=!0;continue}Object.prototype.hasOwnProperty.call(a.dataset,"meInspectorPrevHidden")&&(a.hidden=a.dataset.meInspectorPrevHidden==="true",delete a.dataset.meInspectorPrevHidden)}}}function Or(e){return new Set(String(e??"").split(/\s+/).map(t=>t.trim()).filter(Boolean))}function oa(e){return[...e].join(" ").trim()}function ra(e,t,n,r){Qt(),kn();const a=r(),s=Zo(a),u=s.text,f=Oi(a),v=document.createElement("div");v.className="me-video-text-panel",v.hidden=!0,e.appendChild(v);const k=document.createElement("div");k.className="me-video-text-toolbar";const H=document.createElement("strong");H.textContent=u.tool;const G=Yt(u.addText),T=Yt(u.moveOnCanvas),F=Yt(u.duplicate),j=Yt(u.delete);j.classList.add("me-video-text-danger");const oe=Yt(u.close);k.append(H);const Q=document.createElement("div");Q.className="me-video-text-list";const Z=document.createElement("div");Z.className="me-video-text-empty",Z.textContent=u.empty;const ie=document.createElement("textarea");ie.className="me-video-text-input me-video-text-textarea",ie.placeholder=u.placeholder;const he=document.createElement("select");he.className="me-video-text-select",so(he,[{value:"none",label:f.none},{value:"heading",label:u.heading},{value:"subtitle",label:u.subtitle},{value:"label",label:u.label}]);const ne=ta(f),xe=document.createElement("select");xe.className="me-video-text-select",so(xe,Ti);const te=document.createElement("input");te.type="number",te.min="8",te.max="320",te.step="1",te.className="me-video-text-input";const w=co({fallback:"#ffffff"}),x=co({allowTransparent:!0,fallback:"#111111",transparentLabel:f.transparent}),E=document.createElement("div");E.className="me-video-text-inline";const C=[{value:"left",label:f.alignLeft},{value:"center",label:f.alignCenter},{value:"right",label:f.alignRight}].map(m=>{const P=document.createElement("button");return P.type="button",P.className="me-video-text-align",P.dataset.align=m.value,P.textContent=m.label,E.appendChild(P),{value:m.value,button:P}}),y=document.createElement("div");y.className="me-video-text-toggle-group";const O=document.createElement("button");O.type="button",O.className="me-video-text-toggle is-italic",O.title=f.italic,O.textContent="I";const Y=document.createElement("button");Y.type="button",Y.className="me-video-text-toggle is-underline",Y.title=f.underline,Y.textContent="U";const L=document.createElement("button");L.type="button",L.className="me-video-text-toggle is-strike",L.title=f.strike,L.textContent="S",y.append(O,Y,L);const B=document.createElement("select");B.className="me-video-text-select",so(B,[{value:"none",label:f.caseNone},{value:"uppercase",label:f.uppercase},{value:"lowercase",label:f.lowercase},{value:"capitalize",label:f.capitalize}]);const q=document.createElement("div");q.className="me-video-text-slider-row";const V=document.createElement("input");V.type="number",V.min="0",V.max="100",V.step="1",V.className="me-video-text-input";const X=document.createElement("input");X.type="range",X.min="0",X.max="100",X.step="1",q.append(V,X);const re=document.createElement("select");re.className="me-video-text-select",so(re,[{value:"none",label:f.none}]);const pe=co({fallback:"#000000"}),se=document.createElement("input");se.type="number",se.min="0",se.max="32",se.step="1",se.className="me-video-text-input";const N=co({fallback:"#000000"}),b=document.createElement("input");b.type="number",b.min="-80",b.max="80",b.step="1",b.className="me-video-text-input";const le=document.createElement("input");le.type="number",le.min="-80",le.max="80",le.step="1",le.className="me-video-text-input";const Le=document.createElement("input");Le.type="number",Le.min="0",Le.max="80",Le.step="1",Le.className="me-video-text-input";const ve=document.createElement("div");ve.className="me-video-text-section-body",ve.append(Tt(u.content,ie,"is-area"),Tt(f.preset,he));const Ie=Kt(f.styles);Ie.body.append(Tt(u.font,ne.wrap),Tt(u.weight,xe),Tt(f.size,te),Tt(u.color,w.wrap),Tt(f.fill,x.wrap),Tt(u.align,E),Tt(f.decoration,y),Tt(f.case,B),Tt(u.opacity,q));const D=Kt(f.animations);D.body.append(Tt(f.animation,re));const ee=Kt(f.fontStroke);ee.body.append(Tt(u.color,pe.wrap),Tt(f.size,se));const _=Kt(f.fontShadow);_.body.append(Tt(u.color,N.wrap),Tt(f.x,b),Tt(f.y,le),Tt(f.blur,Le)),v.append(k,Z,ve,Ie.section,D.section,ee.section,_.section);let K=null,fe=null,qe=null,Oe=null,Je=null,Ge=null,Ye=null,dt=null,rt=!1,ze=null,it=!1,xt=!1;const wt="text",we=typeof requestAnimationFrame=="function"?requestAnimationFrame:m=>setTimeout(m,16),Re=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>ce()),Me=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>ce()),et=[{key:"tl",x:0,y:0},{key:"tm",x:.5,y:0},{key:"tr",x:1,y:0},{key:"mr",x:1,y:.5},{key:"br",x:1,y:1},{key:"bm",x:.5,y:1},{key:"bl",x:0,y:1},{key:"ml",x:0,y:.5}],tt={key:"rotate",x:.5,y:0};function ht(){Promise.resolve().then(()=>{xt=!1;const m=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,m-1)})}function gt(m){xt=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return m()}finally{ht()}}function ce(){it||(it=!0,we(()=>{it=!1,Ke()}))}function Se(m){const P=!!m;if(P===rt){Ke();return}rt=P,rt&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:wt}})),Ke()}function Ve(){return fe?[...fe.querySelectorAll("button")].filter(m=>m!==K&&!m.classList.contains("me-video-text-tool")):[]}function Ze(){Ve()[0]?.click()}function at(){if(!K)return;const m=Kn(n());K.dataset.theme=m}function Et(){rn(e,v),Ht(e)}function St(){v.hidden=!rt,K&&K.classList.toggle("is-active",rt),Et()}function Rt(m){if(!m.length){ze=null;return}const P=To(e,t.getState());ze=P.length?P[P.length-1]:null}function ut(){const m=t.getState().overlays??[];if(ze==null)return null;const P=m[ze];return P?.type==="text"?P:null}function It(){return Tn(t)}function Lt(){return yn(e)}function jt(){if(!t.history?.present)return;const m=Lt(),P=Number(t.history.present.__mePreviewTimelineTime);Math.abs((Number.isFinite(P)?P:-1)-m)<.001||(t.history={...t.history,present:{...t.history.present,__mePreviewTimelineTime:m}},typeof t.emit=="function"&&t.emit())}function At(m,P,W={}){const d=(t.getState().overlays??[])[m];!d||d.type!=="text"||t.updateOverlay(m,Jt(d,It(),P),W)}function Mt(m){if(typeof t.applyMut=="function"){t.applyMut(W=>({...W,overlays:[...on(W.overlays),{...m,timelineTrack:0}]}));return}const P=on(t.getState().overlays);t.commit?.({overlays:[...P,{...m,timelineTrack:0}]})}function mt(m,P={}){if(ze==null)return;const W=P.preservePreset||Object.prototype.hasOwnProperty.call(m,"textPreset")?m:{...m,textPreset:"none"};t.updateOverlay(ze,W)}function Ut(m="heading"){const P=It();let W=ae(Lt(),0,Math.max(0,P-je)),l=Math.min(P,W+qt);l-W<je&&(W=ae(P-qt,0,Math.max(0,P-je)),l=Math.max(W+je,P));const d={...tr(t,s,m),...Jt(null,P,{startAt:W,endAt:l,timelineTrack:0})};Mt(d);const o=t.getState().overlays??[];ze=o.length?o.length-1:null,ze!=null&&bt(e,"text",[ze]),Ze(),Se(!0)}function S(){const m=t.getState(),P=Mo(m.overlays??[],To(e,m));P.changed&&(t.commit({overlays:P.overlays}),ze=P.selection.length?P.selection[P.selection.length-1]:null,bt(e,"text",P.selection),Ke())}function R(){const m=t.getState(),P=Co(m.overlays??[],To(e,m));P.changed&&(t.commit({overlays:P.overlays}),ze=null,bt(e,"text",[]),Ke())}function U(m){if(!ut()){Ut(m);return}const W=tr(t,s,m);mt({text:W.text,fontSize:W.fontSize,width:W.width,fontWeight:W.fontWeight,fontFamily:W.fontFamily,fontStyle:W.fontStyle,textAlign:W.textAlign,color:W.color,backgroundColor:W.backgroundColor,borderColor:W.borderColor,borderWidth:W.borderWidth,paddingX:W.paddingX,paddingY:W.paddingY,lineHeight:W.lineHeight,boxShadow:W.boxShadow?{...W.boxShadow}:void 0,textDecoration:W.textDecoration??"",textTransform:W.textTransform,animation:"none",textPreset:m},{preservePreset:!0})}function Te(){const{timelineInner:m,timelineHost:P}=Bn(e,t.getState());if(!m||!P){Oe?.remove(),Oe=null,Re&&Je&&(Re.unobserve(Je),Je=null),qe=null;return}qe=m,(!Oe||!Oe.isConnected||Oe.parentElement!==P)&&(Oe?.remove(),Oe=document.createElement("div"),Oe.className="me-video-text-timeline me-video-overlay-timeline me-video-text-overlay-layer");for(const W of[...P.children])W!==Oe&&W instanceof HTMLElement&&W.classList.contains("me-video-text-overlay-layer")&&W.remove();(Oe.parentElement!==P||P.lastElementChild!==Oe)&&P.appendChild(Oe),Re&&Je!==qe&&(Je&&Re.unobserve(Je),Je=qe,Re.observe(qe))}function Fe(){const m=e.querySelector(".me-video-canvas-stage");if(!m){Ye?.remove(),Ye=null,Me&&dt&&(Me.unobserve(dt),dt=null),Ge=null;return}Ge=m,Ge.style.position="relative",!Ye||!Ye.isConnected||Ye.parentElement!==Ge?(Ye?.remove(),Ye=document.createElement("div"),Ye.className="me-video-text-canvas-layer",Ye.addEventListener("pointerdown",P=>{P.target===Ye&&(P.preventDefault(),P.stopPropagation())}),Ye.addEventListener("click",P=>{P.target===Ye&&(P.preventDefault(),P.stopPropagation(),ze=null,Eo(e),rt?Se(!1):Ke())}),Ge.appendChild(Ye)):Ge.lastElementChild!==Ye&&Ge.appendChild(Ye),Me&&dt!==Ge&&(dt&&Me.unobserve(dt),dt=Ge,Me.observe(Ge))}function p(){if(!Ge)return null;const P=t.getState().canvas??{},W=Math.max(1,Number(P.w)||0),l=Math.max(1,Number(P.h)||0);if(!W||!l)return null;const d=Ge.getBoundingClientRect(),o=Ge.querySelector("canvas, video, img")||[...Ge.children].find(A=>A!==Ye)||null;let i=0,c=0,h=Ge.clientWidth||W,I=Ge.clientHeight||l;if(o instanceof HTMLElement){const A=o.getBoundingClientRect();A.width>0&&A.height>0&&(i=A.left-d.left,c=A.top-d.top,h=A.width,I=A.height)}if(!(h>0&&I>0)){const A=Ge.clientWidth||W,J=Ge.clientHeight||l,M=Math.min(A/W,J/l)||1;h=W*M,I=l*M,i=Math.max(0,(A-h)/2),c=Math.max(0,(J-I)/2)}return{stageLeft:d.left,stageTop:d.top,left:i,top:c,scaleX:h/W,scaleY:I/l}}function g(m,P){const W=lt(m),l=Bt(m,W);return P>=W-.001&&P<=l+.001}function $(m,P,W){const l=Pt(e,"text",m,P,W);ze=l.length?l[l.length-1]:null,Se(!0),Ke()}function de(m,P,W){return{x:(m-W.stageLeft-W.left)/W.scaleX,y:(P-W.stageTop-W.top)/W.scaleY}}function be(m,P,W,l){return{x:W,y:l,fontSize:P.fontSize,width:P.width,paddingX:P.paddingX,paddingY:P.paddingY,borderWidth:P.borderWidth,boxShadow:P.boxShadow}}function ye(m,P,W){const l=(t.getState().overlays??[])[m];if(!l||l.type!=="text")return;const d=t.getState().canvas??{w:1080,h:1920},o=Gt(l);if(!o)return;const i=P.clientX,c=P.clientY,h=Math.max(0,(Number(d.w)||0)-o.w),I=Math.max(0,(Number(d.h)||0)-o.h),A=(z,me,ue)=>{const Ce=(z-i)/W.scaleX,ke=(me-c)/W.scaleY,ge=ae(o.x+Ce,0,h),Ae=ae(o.y+ke,0,I);t.updateOverlay(m,{x:ge,y:Ae},ue?{transient:!0}:void 0)},J=z=>{z.preventDefault(),A(z.clientX,z.clientY,!0)},M=z=>{window.removeEventListener("pointermove",J),window.removeEventListener("pointerup",M),window.removeEventListener("pointercancel",M),A(z.clientX,z.clientY,!1)};window.addEventListener("pointermove",J),window.addEventListener("pointerup",M),window.addEventListener("pointercancel",M)}function Be(m,P,W,l){const d=(t.getState().overlays??[])[m];if(!d||d.type!=="text")return;const o=Gt(d);if(!o)return;const i=t.getState().canvas??{w:1080,h:1920},c=P.x===.5?.5:1-P.x,h=P.y===.5?.5:1-P.y,I=o.x+o.w*c,A=o.y+o.h*h,J=Math.max(.1,24/Math.max(24,o.w),24/Math.max(24,o.h)),M=P.x===.5?1/0:Math.max(.1,(c===0?(Number(i.w)||0)-I:I)/Math.max(1,o.w)),z=P.y===.5?1/0:Math.max(.1,(h===0?(Number(i.h)||0)-A:A)/Math.max(1,o.h)),me=Math.max(J,Math.min(M,z,8)),ue=(ge,Ae,_e)=>{const Xe=de(ge,Ae,l),We=[];P.x!==.5&&We.push(Math.abs(Xe.x-I)/Math.max(1,o.w)),P.y!==.5&&We.push(Math.abs(Xe.y-A)/Math.max(1,o.h));const st=We.length?Math.max(...We):1,Nt=ae(st,J,me),$t=Yo(d,Nt),cn=Gt($t);if(!cn)return;const dn=I-cn.w*c,Hn=A-cn.h*h;t.updateOverlay(m,be(d,$t,dn,Hn),_e?{transient:!0}:void 0)},Ce=ge=>{ge.preventDefault(),ue(ge.clientX,ge.clientY,!0)},ke=ge=>{window.removeEventListener("pointermove",Ce),window.removeEventListener("pointerup",ke),window.removeEventListener("pointercancel",ke),ue(ge.clientX,ge.clientY,!1)};window.addEventListener("pointermove",Ce),window.addEventListener("pointerup",ke),window.addEventListener("pointercancel",ke)}function Ee(m,P,W){const l=(t.getState().overlays??[])[m];if(!l||l.type!=="text")return;const d=Gt(l);if(!d)return;const o=W.stageLeft+W.left+(d.x+d.w/2)*W.scaleX,i=W.stageTop+W.top+(d.y+d.h/2)*W.scaleY,c=Math.atan2(P.clientY-i,P.clientX-o),h=un(l),I=(M,z,me,ue)=>{const Ce=Math.atan2(z-i,M-o);let ke=In(h+(Ce-c)*180/Math.PI);ue&&(ke=Math.round(ke/15)*15),t.updateOverlay(m,{rotation:ke},me?{transient:!0}:void 0)},A=M=>{M.preventDefault(),I(M.clientX,M.clientY,!0,M.shiftKey)},J=M=>{window.removeEventListener("pointermove",A),window.removeEventListener("pointerup",J),window.removeEventListener("pointercancel",J),I(M.clientX,M.clientY,!1,M.shiftKey)};window.addEventListener("pointermove",A),window.addEventListener("pointerup",J),window.addEventListener("pointercancel",J)}function $e(m,P){if(Fe(),!Ye)return;Ye.replaceChildren();const W=p();if(!W){Ye.hidden=!0;return}Ye.hidden=!1;const l=Lt(),d=m.map(i=>i.index),o=m.filter(i=>g(i.overlay,l));for(const i of o){const c=Gt(i.overlay);if(!c)continue;const h=document.createElement("button");h.type="button",h.className="me-video-text-canvas-hit";const I=P.has(i.index),A=I&&ze===i.index;I&&h.classList.add("is-active"),h.title=Un(i.overlay.text,s.untitledText),h.style.left=`${W.left+c.x*W.scaleX}px`,h.style.top=`${W.top+c.y*W.scaleY}px`,h.style.width=`${Math.max(18,c.w*W.scaleX)}px`,h.style.height=`${Math.max(18,c.h*W.scaleY)}px`;const J=un(i.overlay);if(J&&(h.style.transform=`rotate(${J}deg)`,h.style.transformOrigin="center center"),h.addEventListener("pointerdown",M=>{if(M.preventDefault(),M.stopPropagation(),M.shiftKey||M.ctrlKey||M.metaKey){$(i.index,M,d);return}ze=i.index,bt(e,"text",[i.index]),Se(!0),ye(i.index,M,W)}),A){for(const z of et){const me=document.createElement("span");me.className="me-video-text-canvas-handle",me.dataset.handle=z.key,me.style.left=`${z.x*100}%`,me.style.top=`${z.y*100}%`,me.addEventListener("pointerdown",ue=>{ue.preventDefault(),ue.stopPropagation(),ze=i.index,bt(e,"text",[i.index]),Se(!0),Be(i.index,z,ue,W)}),h.appendChild(me)}const M=document.createElement("span");M.className="me-video-text-canvas-handle",M.dataset.handle=tt.key,M.style.left=`${tt.x*100}%`,M.style.top=`${tt.y*100}%`,M.addEventListener("pointerdown",z=>{z.preventDefault(),z.stopPropagation(),ze=i.index,bt(e,"text",[i.index]),Se(!0),Ee(i.index,z,W)}),h.appendChild(M)}Ye.appendChild(h)}}function Ne(m,P,W){if(!qe)return;const l=(t.getState().overlays??[])[m];if(!l||l.type!=="text")return;if(W.shiftKey||W.ctrlKey||W.metaKey){W.preventDefault(),W.stopPropagation();const z=Pt(e,"text",m,W,ar(t.getState()).map(me=>me.index));ze=z.length?z[z.length-1]:null,Ze(),Se(!0);return}W.preventDefault(),W.stopPropagation(),ze=m,bt(e,"text",[m]),Ze(),rt||Se(!0);const d=It(),o=Math.max(qe.clientWidth/d,.001),i=lt(l),c=Bt(l,i),h=Math.max(je,c-i),I=vt(l),A=W.clientX,J=z=>{const me=(z.clientX-A)/o,ue=t.getState().overlays??[];if(P==="move"){const ge=Math.max(0,i+me),Ae=ge+h,_e=pt(Oe,ue,m,ge,Ae,z.clientY,I);At(m,{startAt:ge,endAt:Ae,timelineTrack:_e},{transient:!0});return}if(P==="start"){const ge=ae(i+me,0,c-je),Ae=pt(Oe,ue,m,ge,c,z.clientY,I);At(m,{startAt:ge,endAt:c,timelineTrack:Ae},{transient:!0});return}const Ce=Math.max(i+je,c+me),ke=pt(Oe,ue,m,i,Ce,z.clientY,I);At(m,{startAt:i,endAt:Ce,timelineTrack:ke},{transient:!0})},M=z=>{window.removeEventListener("pointermove",J),window.removeEventListener("pointerup",M),window.removeEventListener("pointercancel",M);const me=(z.clientX-A)/o,ue=t.getState().overlays??[];if(P==="move"){const ge=Math.max(0,i+me),Ae=ge+h,_e=pt(Oe,ue,m,ge,Ae,z.clientY,I);At(m,{startAt:ge,endAt:Ae,timelineTrack:_e});return}if(P==="start"){const ge=ae(i+me,0,c-je),Ae=pt(Oe,ue,m,ge,c,z.clientY,I);At(m,{startAt:ge,endAt:c,timelineTrack:Ae});return}const Ce=Math.max(i+je,c+me),ke=pt(Oe,ue,m,i,Ce,z.clientY,I);At(m,{startAt:i,endAt:Ce,timelineTrack:ke})};window.addEventListener("pointermove",J),window.addEventListener("pointerup",M),window.addEventListener("pointercancel",M),Ke()}function De(m,P){if(Te(),!Oe||!qe||(Oe.replaceChildren(),Oe.hidden=m.length===0,!m.length))return;const W=It(),l=qe.clientWidth/W,d=Rn(t.getState()),o=new Map;for(const i of m){const c=vt(i.overlay),h=d.get(c)??c;let I=o.get(c);I||(I=document.createElement("div"),I.className="me-video-overlay-track-row",I.dataset.track=String(c),I.style.top=`${Ln(h)}px`,o.set(c,I),Oe.appendChild(I));const A=document.createElement("div");A.className="me-video-text-track-clip",P.has(i.index)&&A.classList.add("is-active");const J=lt(i.overlay),M=Sn(i.overlay);A.style.left=`${J*l}px`,A.style.width=`${Math.max(36,M*l)}px`;const z=document.createElement("span");z.className="me-video-text-track-icon",z.textContent="Aa";const me=document.createElement("span");me.className="me-video-text-track-label",me.textContent=Un(i.overlay.text,s.untitledText),me.title=me.textContent;const ue=document.createElement("span");ue.className="me-video-text-track-handle is-start";const Ce=document.createElement("span");Ce.className="me-video-text-track-handle is-end",A.append(z,me,ue,Ce),A.addEventListener("pointerdown",ke=>Ne(i.index,"move",ke)),ue.addEventListener("pointerdown",ke=>Ne(i.index,"start",ke)),Ce.addEventListener("pointerdown",ke=>Ne(i.index,"end",ke)),A.addEventListener("click",ke=>{if(ke.preventDefault(),ke.stopPropagation(),ke.shiftKey||ke.ctrlKey||ke.metaKey){Ze(),Ke();return}const ge=Pt(e,"text",i.index,ke,m.map(Ae=>Ae.index));ze=ge.length?ge[ge.length-1]:null,Ze(),Se(!0),Ke()}),I.appendChild(A)}}function Qe(m,P){Q.replaceChildren(),Q.hidden=m.length===0,Z.hidden=m.length>0;for(const W of m){const l=document.createElement("button");l.type="button",l.className="me-video-text-chip",P.has(W.index)&&l.classList.add("is-active"),l.textContent=Un(W.overlay.text,s.untitledText),l.title=Un(W.overlay.text,s.untitledText),l.addEventListener("click",d=>{const o=Pt(e,"text",W.index,d,m.map(i=>i.index));ze=o.length?o[o.length-1]:null,Ke()}),Q.appendChild(l)}}function He(m){ie.disabled=m,ne.setDisabled(m),xe.disabled=m,te.disabled=m,C.forEach(({button:P})=>P.disabled=m),B.disabled=m,re.disabled=m,V.disabled=m,X.disabled=m,se.disabled=m,b.disabled=m,le.disabled=m,Le.disabled=m,w.setDisabled(m),x.setDisabled(m),pe.setDisabled(m),N.setDisabled(m),F.disabled=m,j.disabled=m,T.disabled=m,O.disabled=m,Y.disabled=m,L.disabled=m}function Pe(m){const P=String(ae(Math.round(Number(m)||0),0,100));V.value=P,X.value=P}function Ue(m){const P=Or(m?.textDecoration);O.classList.toggle("is-active",!!m&&String(m.fontStyle??"normal")==="italic"),Y.classList.toggle("is-active",!!m&&P.has("underline")),L.classList.toggle("is-active",!!m&&P.has("line-through"))}function ct(m="left"){C.forEach(({value:P,button:W})=>{})}function ft(m){if(He(!!!m),!m){he.value="none",ie.value="",ne.setContextText(""),ne.setValue("Arial",{silent:!0}),xe.value="700",te.value="72",w.setValue("#ffffff"),x.setValue("transparent"),ct("center"),B.value="none",re.value="none",pe.setValue("#000000"),se.value="0",N.setValue("#000000"),b.value="0",le.value="4",Le.value="18",Pe(100),Ue(null);return}const W=m.boxShadow??{};he.value=String(m.textPreset??"none"),ie.value=String(m.text??""),ne.setContextText(m.text??""),ne.setValue(String(m.fontFamily??"Arial"),{silent:!0}),xe.value=String(m.fontWeight??"700"),te.value=String(Math.round(Number(m.fontSize)||72)),w.setValue(m.color??"#ffffff"),x.setValue(m.backgroundColor??"transparent"),ct(m.textAlign==="right"||m.textAlign==="center"?m.textAlign:"left"),B.value=m.textTransform?String(m.textTransform):"none",re.value=m.animation?String(m.animation):"none",pe.setValue(m.borderColor??"#000000"),se.value=String(Math.round(Number(m.borderWidth)||0)),N.setValue(W.color??"#000000"),b.value=String(Math.round(Number(W.x)||0)),le.value=String(Math.round(Number(W.y)||0)),Le.value=String(Math.round(Number(W.blur)||0)),Pe(Number.isFinite(m.opacity)?m.opacity:100),Ue(m)}function Ke(){gt(()=>{const m=ar(t.getState());Rt(m);const P=new Set(_t(e,"text"));De(m,P),$e(m,P),Qe(m,P),ft(ut()),St(),Et(),at()}),jt()}function nt(){gt(()=>{const m=e.querySelector(".me-video-toolrail");m&&(fe=m,Yi([...fe.querySelectorAll("button")].filter(P=>P instanceof HTMLButtonElement&&P!==K&&!P.classList.contains("me-video-text-tool"))),(!K||!K.isConnected)&&(K=document.createElement("button"),K.type="button",K.className="me-video-text-tool",K.innerHTML=`<span class="me-video-text-tool-icon">T</span><span class="me-video-text-tool-label">${u.tool}</span>`,K.addEventListener("click",()=>{Ut("heading")})),K.isConnected||fe.appendChild(K),at(),Et())})}function ot(m){return!!m&&(m===v||v.contains(m)||m===K||m===Oe||Oe?.contains?.(m)||m===Ye||Ye?.contains?.(m))}function Ot(m){return m.some(P=>{if(!ot(P.target))return!0;for(const W of P.addedNodes)if(!ot(W))return!0;for(const W of P.removedNodes)if(!ot(W))return!0;return!1})}function Ft(m,P){m.swatch.addEventListener("input",()=>{m.transparentButton&&m.wrap.dataset.transparent==="true"&&m.setTransparent(!1),m.text.value=m.swatch.value,P(m.getValue())}),m.text.addEventListener("change",()=>{const W=String(m.text.value??"").trim();if(m.transparentButton&&W.toLowerCase()==="transparent"){m.setTransparent(!0),P("transparent");return}const l=vn(W,m.swatch.value||"#ffffff");m.swatch.value=l==="transparent"?m.swatch.value||"#ffffff":l,m.text.value=l,m.transparentButton&&m.setTransparent(!1),P(l)}),m.transparentButton?.addEventListener("click",()=>{const W=m.wrap.dataset.transparent!=="true";m.setTransparent(W),P(m.getValue())})}function kt(m){const P=ut();if(!P)return;const W={color:"#000000",x:0,y:4,blur:18,...P.boxShadow??{}};mt({boxShadow:{...W,...m}})}function ln(m){const P=ut();if(!P)return;const W=Or(P.textDecoration);W.has(m)?W.delete(m):W.add(m),mt({textDecoration:oa(W)||void 0})}const an=new MutationObserver(m=>{xt||e.__meVideoEnhancerObserverLock||Ot(m)&&(nt(),ce())}),en=m=>{m?.detail?.id!==wt&&rt&&(rt=!1,Ke())},Ct=()=>{Ke()};an.observe(e,{childList:!0,subtree:!0,characterData:!0}),e.addEventListener("me-video-inspector-open",en),e.addEventListener(zt,Ct),window.addEventListener("resize",Et);const tn=t.subscribe(()=>{Ke()});return G.addEventListener("click",()=>Ut("heading")),T.addEventListener("click",()=>{Ze(),Se(!0)}),F.addEventListener("click",S),j.addEventListener("click",R),oe.addEventListener("click",()=>{Se(!1)}),ie.addEventListener("input",()=>{ne.setContextText(ie.value),mt({text:ie.value})}),he.addEventListener("change",()=>{if(he.value==="none"){ut()&&mt({textPreset:"none"},{preservePreset:!0});return}U(he.value)}),ne.wrap.addEventListener("fontchange",()=>mt({fontFamily:ne.getValue()})),xe.addEventListener("change",()=>mt({fontWeight:xe.value})),te.addEventListener("change",()=>mt({fontSize:ae(Number(te.value)||72,8,320)})),Ft(w,m=>mt({color:m})),Ft(x,m=>mt({backgroundColor:m})),C.forEach(({value:m,button:P})=>{P.addEventListener("click",()=>{ct(m),mt({textAlign:m})})}),B.addEventListener("change",()=>mt({textTransform:B.value==="none"?void 0:B.value})),re.addEventListener("change",()=>mt({animation:re.value==="none"?void 0:re.value})),se.addEventListener("change",()=>mt({borderWidth:ae(Number(se.value)||0,0,32)})),Ft(pe,m=>mt({borderColor:m})),Ft(N,m=>kt({color:m})),b.addEventListener("change",()=>kt({x:ae(Number(b.value)||0,-80,80)})),le.addEventListener("change",()=>kt({y:ae(Number(le.value)||0,-80,80)})),Le.addEventListener("change",()=>kt({blur:ae(Number(Le.value)||0,0,80)})),V.addEventListener("input",()=>{const m=ae(Number(V.value)||0,0,100);Pe(m),mt({opacity:m})}),X.addEventListener("input",()=>{const m=ae(Number(X.value)||0,0,100);Pe(m),mt({opacity:m})}),O.addEventListener("click",()=>{const m=ut();m&&mt({fontStyle:String(m.fontStyle??"normal")==="italic"?"normal":"italic"})}),Y.addEventListener("click",()=>ln("underline")),L.addEventListener("click",()=>ln("line-through")),nt(),Ke(),{destroy(){an.disconnect(),Re&&Je&&Re.unobserve(Je),Me&&dt&&Me.unobserve(dt),tn(),e.removeEventListener("me-video-inspector-open",en),e.removeEventListener(zt,Ct),window.removeEventListener("resize",Et),ne.destroy(),K?.remove(),Oe?.remove(),Ye?.remove(),v.remove(),Ht(e)}}}function ia(e,t,n){Qt(),kn();const r=Ni(n()),a=Ai(r),s=document.createElement("div");s.className="me-video-text-panel me-video-sticker-panel",s.hidden=!0,e.appendChild(s);const u=document.createElement("div");u.className="me-video-text-toolbar";const f=document.createElement("strong");f.textContent=r.title,u.append(f);const v=Kt(r.uploadTitle),k=document.createElement("label");k.className="me-video-sticker-upload-zone";const H=document.createElement("span");H.className="me-video-sticker-upload-icon",H.textContent="\u{1F5BC}";const G=document.createElement("span");G.className="me-video-sticker-upload-text",G.textContent=r.uploadHint;const T=document.createElement("span");T.className="me-video-sticker-upload-subtext",T.textContent=r.uploadFormats;const F=document.createElement("input");F.type="file",F.accept="image/png,image/jpeg,image/webp,image/svg+xml",k.append(H,G,T,F),v.body.appendChild(k);const j=Kt(r.libraryTitle),oe=document.createElement("div");oe.className="me-video-sticker-library",j.body.appendChild(oe),s.append(u,v.section,j.section);let Q=null,Z=null,ie=null,he=null,ne=null,xe=null,te=null,w=null,x=null,E=!1,C=null,y=!1,O=!1;const Y="sticker",L=typeof requestAnimationFrame=="function"?requestAnimationFrame:S=>setTimeout(S,16),B=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>se()),q=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>se()),V=[{key:"tl",x:0,y:0},{key:"tm",x:.5,y:0},{key:"tr",x:1,y:0},{key:"mr",x:1,y:.5},{key:"br",x:1,y:1},{key:"bm",x:.5,y:1},{key:"bl",x:0,y:1},{key:"ml",x:0,y:.5}],X={key:"rotate",x:.5,y:0};function re(){Promise.resolve().then(()=>{O=!1;const S=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,S-1)})}function pe(S){O=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return S()}finally{re()}}function se(){y||(y=!0,L(()=>{y=!1,ut()}))}function N(S){const R=!!S;if(R===E){ut();return}E=R,E&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:Y}})),ut()}function b(S=Z){return S?[...S.children].filter(R=>R instanceof HTMLButtonElement&&!R.classList.contains("me-video-text-tool")):[]}function le(S){return[S?.textContent,S?.getAttribute?.("title"),S?.getAttribute?.("aria-label")].filter(Boolean).join(" ").trim().toLowerCase()}function Le(S){const R=["trim","timeline","\u526A\u8F91","\u65F6\u95F4\u8F74"];return Ro(S.find(U=>{const Te=le(U);return R.some(Fe=>Te.includes(Fe))})??S[0]??null)}function ve(S){const R=[r.tool,r.title,"sticker","stickers","\u8D34\u7EB8","\u8CBC\u7D19"].map(U=>String(U??"").trim().toLowerCase()).filter(Boolean);return S.find(U=>{const Te=le(U);return R.some(Fe=>Te.includes(Fe))})??S[Math.min(5,Math.max(0,S.length-1))]??null}function Ie(){if(Q?.classList.toggle("is-active",E),!!ie&&E){ie.classList.remove("is-active");return}}function D(){ie&&(ie.classList.contains("is-active")||ie.click())}function ee(){rn(e,s),Ht(e)}function _(){s.hidden=!E,Ie(),ee()}function K(S){if(!S.length){C=null;return}const R=ur(e,t.getState());C=R.length?R[R.length-1]:null}function fe(){return Tn(t)}function qe(){return yn(e)}function Oe(){if(!t.history?.present)return;const S=qe(),R=Number(t.history.present.__mePreviewTimelineTime);Math.abs((Number.isFinite(R)?R:-1)-S)<.001||(t.history={...t.history,present:{...t.history.present,__mePreviewTimelineTime:S}},typeof t.emit=="function"&&t.emit())}function Je(S){return S?.emoji?`${r.defaultLabel} ${S.emoji}`:S?.src?r.uploadedLabel:r.defaultLabel}function Ge(S){const R=Gt(S);if(!R)return null;if(!S?.emoji)return R;const U=.84,Te=R.w*(1-U)/2,Fe=R.h*(1-U)/2;return{x:R.x+Te,y:R.y+Fe,w:R.w*U,h:R.h*U}}function Ye(S,R){if(!S?.emoji)return R;const Te=1/.84,Fe=(Te-1)/2;return{x:R.x-R.w*Fe,y:R.y-R.h*Fe,w:R.w*Te,h:R.h*Te}}function dt(S,R){const U=Math.max(1,Number(R?.w)||1080),Te=Math.max(1,Number(R?.h)||1920),Fe=ae(Number.isFinite(S?.w)?S.w:8,8,Math.max(8,U)),p=ae(Number.isFinite(S?.h)?S.h:8,8,Math.max(8,Te));return{x:ae(Number.isFinite(S?.x)?S.x:0,0,Math.max(0,U-Fe)),y:ae(Number.isFinite(S?.y)?S.y:0,0,Math.max(0,Te-p)),w:Fe,h:p}}function rt(S){return S?.emoji||"\u2726"}function ze(S,R,U={}){const Fe=(t.getState().overlays??[])[S];!Fe||Fe.type!=="sticker"||t.updateOverlay(S,Jt(Fe,fe(),R),U)}function it(S){if(typeof t.applyMut=="function"){t.applyMut(U=>({...U,overlays:[...on(U.overlays),{...S,timelineTrack:0}]}));return}const R=on(t.getState().overlays);t.commit?.({overlays:[...R,{...S,timelineTrack:0}]})}function xt(S){return new Promise(R=>{const U=new Image;U.onload=()=>R({w:U.naturalWidth||256,h:U.naturalHeight||256}),U.onerror=()=>R({w:256,h:256}),U.src=S})}async function wt(S){const R=fe();let U=ae(qe(),0,Math.max(0,R-je)),Te=Math.min(R,U+qt);Te-U<je&&(U=ae(R-qt,0,Math.max(0,R-je)),Te=Math.max(U+je,R));const Fe=t.getState().canvas??{w:1080,h:1920},p=S.emoji?{w:256,h:256}:await xt(S.src),g=Math.max(96,Math.round(Math.min(Fe.w,Fe.h)*.24)),$=Vr(p.w,p.h,g),de={type:"sticker",x:Math.round((Fe.w-$.w)/2),y:Math.round((Fe.h-$.h)/2),w:$.w,h:$.h,rotation:0,...S.emoji?{emoji:S.emoji}:{src:S.src},...Jt(null,R,{startAt:U,endAt:Te,timelineTrack:0})};it(de);const be=t.getState().overlays??[];C=be.length?be.length-1:null,C!=null&&bt(e,"text",[C]),D(),N(!0)}async function we(S){const R=S?.[0];if(!R||!String(R.type||"").startsWith("image/")&&!/\.(png|jpe?g|webp|svg)$/i.test(R.name||""))return;const U=await new Promise((Te,Fe)=>{const p=new FileReader;p.onload=()=>Te(String(p.result||"")),p.onerror=()=>Fe(p.error||new Error("Failed to read sticker file")),p.readAsDataURL(R)}).catch(()=>"");U&&(F.value="",await wt({src:U}))}function Re(){oe.replaceChildren();for(const S of a){const R=document.createElement("div");R.className="me-video-sticker-library-group";const U=document.createElement("div");U.className="me-video-sticker-library-title",U.textContent=S.title;const Te=document.createElement("div");Te.className="me-video-sticker-grid";for(const Fe of S.items){const p=document.createElement("button");if(p.type="button",p.className="me-video-sticker-card",p.title=Fe.label,p.setAttribute("aria-label",Fe.label),Fe.emoji){const g=document.createElement("span");g.className="me-video-sticker-card-emoji",g.textContent=Fe.emoji,p.appendChild(g)}else if(Fe.src){const g=document.createElement("img");g.src=Fe.src,g.alt=Fe.label,p.appendChild(g)}p.addEventListener("click",()=>{wt(Fe)}),Te.appendChild(p)}R.append(U,Te),oe.appendChild(R)}}function Me(){pe(()=>{const S=e.querySelector(".me-video-toolrail");S&&(Z=S,(!Q||!Q.isConnected)&&(Q=document.createElement("button"),Q.type="button",Q.className="me-video-text-tool",Q.innerHTML=`<span class="me-video-text-tool-icon">\u2726</span><span class="me-video-text-tool-label">${r.tool}</span>`,Q.title=r.tool,Q.setAttribute("aria-label",r.tool),Q.addEventListener("click",()=>{const R=!E;R&&D(),N(R)})),Q.isConnected||Z.appendChild(Q),ee())})}function et(){const{timelineInner:S,timelineHost:R}=Bn(e,t.getState());if(!S||!R){ne?.remove(),ne=null,B&&xe&&(B.unobserve(xe),xe=null),he=null;return}he=S,(!ne||!ne.isConnected||ne.parentElement!==R)&&(ne?.remove(),ne=document.createElement("div"),ne.className="me-video-text-timeline me-video-sticker-timeline me-video-overlay-timeline me-video-sticker-overlay-layer");for(const U of[...R.children])U!==ne&&U instanceof HTMLElement&&U.classList.contains("me-video-sticker-overlay-layer")&&U.remove();(ne.parentElement!==R||R.lastElementChild!==ne)&&R.appendChild(ne),B&&xe!==he&&(xe&&B.unobserve(xe),xe=he,B.observe(he))}function tt(){const S=e.querySelector(".me-video-canvas-stage");if(!S){w?.remove(),w=null,q&&x&&(q.unobserve(x),x=null),te=null;return}te=S,te.style.position="relative",!w||!w.isConnected||w.parentElement!==te?(w?.remove(),w=document.createElement("div"),w.className="me-video-text-canvas-layer me-video-sticker-canvas-layer",w.addEventListener("pointerdown",R=>{R.target===w&&(R.preventDefault(),R.stopPropagation())}),w.addEventListener("click",R=>{R.target===w&&(R.preventDefault(),R.stopPropagation(),C=null,Eo(e),E?N(!1):ut())}),te.appendChild(w)):te.lastElementChild!==w&&te.appendChild(w),q&&x!==te&&(x&&q.unobserve(x),x=te,q.observe(te))}function ht(){if(!te)return null;const R=t.getState().canvas??{},U=Math.max(1,Number(R.w)||0),Te=Math.max(1,Number(R.h)||0);if(!U||!Te)return null;const Fe=te.getBoundingClientRect(),p=te.querySelector("canvas, video, img")||[...te.children].find(ye=>ye!==w)||null;let g=0,$=0,de=te.clientWidth||U,be=te.clientHeight||Te;if(p instanceof HTMLElement){const ye=p.getBoundingClientRect();ye.width>0&&ye.height>0&&(g=ye.left-Fe.left,$=ye.top-Fe.top,de=ye.width,be=ye.height)}if(!(de>0&&be>0)){const ye=te.clientWidth||U,Be=te.clientHeight||Te,Ee=Math.min(ye/U,Be/Te)||1;de=U*Ee,be=Te*Ee,g=Math.max(0,(ye-de)/2),$=Math.max(0,(Be-be)/2)}return{stageLeft:Fe.left,stageTop:Fe.top,left:g,top:$,scaleX:de/U,scaleY:be/Te}}function gt(S,R){const U=lt(S),Te=Bt(S,U);return R>=U-.001&&R<=Te+.001}function ce(S,R,U){const Te=Pt(e,"text",S,R,U);C=Te.length?Te[Te.length-1]:null,N(!0),ut()}function Se(S,R,U){return{x:(S-U.stageLeft-U.left)/U.scaleX,y:(R-U.stageTop-U.top)/U.scaleY}}function Ve(S,R,U){const Te=(t.getState().overlays??[])[S];if(!Te||Te.type!=="sticker")return;const Fe=t.getState().canvas??{w:1080,h:1920},p=Gt(Te);if(!p)return;const g=R.clientX,$=R.clientY,de=Math.max(0,(Number(Fe.w)||0)-p.w),be=Math.max(0,(Number(Fe.h)||0)-p.h),ye=($e,Ne,De)=>{const Qe=($e-g)/U.scaleX,He=(Ne-$)/U.scaleY,Pe=ae(p.x+Qe,0,de),Ue=ae(p.y+He,0,be);t.updateOverlay(S,{x:Pe,y:Ue},De?{transient:!0}:void 0)},Be=$e=>{$e.preventDefault(),ye($e.clientX,$e.clientY,!0)},Ee=$e=>{window.removeEventListener("pointermove",Be),window.removeEventListener("pointerup",Ee),window.removeEventListener("pointercancel",Ee),ye($e.clientX,$e.clientY,!1)};window.addEventListener("pointermove",Be),window.addEventListener("pointerup",Ee),window.addEventListener("pointercancel",Ee)}function Ze(S,R,U,Te){const Fe=(t.getState().overlays??[])[S];if(!Fe||Fe.type!=="sticker")return;const p=Ge(Fe);if(!p)return;const g=t.getState().canvas??{w:1080,h:1920},$=R.x===.5?.5:1-R.x,de=R.y===.5?.5:1-R.y,be=p.x+p.w*$,ye=p.y+p.h*de,Be=Math.max(.1,24/Math.max(24,p.w),24/Math.max(24,p.h)),Ee=R.x===.5?1/0:Math.max(.1,($===0?(Number(g.w)||0)-be:be)/Math.max(1,p.w)),$e=R.y===.5?1/0:Math.max(.1,(de===0?(Number(g.h)||0)-ye:ye)/Math.max(1,p.h)),Ne=Math.max(Be,Math.min(Ee,$e,8)),De=(Pe,Ue,ct)=>{const ft=Se(Pe,Ue,Te),Ke=[];R.x!==.5&&Ke.push(Math.abs(ft.x-be)/Math.max(1,p.w)),R.y!==.5&&Ke.push(Math.abs(ft.y-ye)/Math.max(1,p.h));const nt=Ke.filter(Number.isFinite),ot=nt.length?Math.max(...nt):1,Ot=ae(ot,Be,Ne),Ft={x:be-p.w*Ot*$,y:ye-p.h*Ot*de,w:Math.max(8,p.w*Ot),h:Math.max(8,p.h*Ot)},kt=dt(Ye(Fe,Ft),g);t.updateOverlay(S,{x:kt.x,y:kt.y,w:kt.w,h:kt.h},ct?{transient:!0}:void 0)},Qe=Pe=>{Pe.preventDefault(),De(Pe.clientX,Pe.clientY,!0)},He=Pe=>{window.removeEventListener("pointermove",Qe),window.removeEventListener("pointerup",He),window.removeEventListener("pointercancel",He),De(Pe.clientX,Pe.clientY,!1)};window.addEventListener("pointermove",Qe),window.addEventListener("pointerup",He),window.addEventListener("pointercancel",He)}function at(S,R,U){const Te=(t.getState().overlays??[])[S];if(!Te||Te.type!=="sticker")return;const Fe=Ge(Te);if(!Fe)return;const p=U.stageLeft+U.left+(Fe.x+Fe.w/2)*U.scaleX,g=U.stageTop+U.top+(Fe.y+Fe.h/2)*U.scaleY,$=Math.atan2(R.clientY-g,R.clientX-p),de=un(Te),be=(Ee,$e,Ne,De)=>{const Qe=Math.atan2($e-g,Ee-p);let He=In(de+(Qe-$)*180/Math.PI);De&&(He=Math.round(He/15)*15),t.updateOverlay(S,{rotation:He},Ne?{transient:!0}:void 0)},ye=Ee=>{Ee.preventDefault(),be(Ee.clientX,Ee.clientY,!0,Ee.shiftKey)},Be=Ee=>{window.removeEventListener("pointermove",ye),window.removeEventListener("pointerup",Be),window.removeEventListener("pointercancel",Be),be(Ee.clientX,Ee.clientY,!1,Ee.shiftKey)};window.addEventListener("pointermove",ye),window.addEventListener("pointerup",Be),window.addEventListener("pointercancel",Be)}function Et(S,R){if(tt(),!w)return;w.replaceChildren();const U=ht();if(!U){w.hidden=!0;return}w.hidden=!1;const Te=qe(),Fe=S.map(g=>g.index),p=S.filter(g=>gt(g.overlay,Te));for(const g of p){const $=Ge(g.overlay);if(!$)continue;const de=document.createElement("button");de.type="button",de.className="me-video-text-canvas-hit me-video-sticker-canvas-hit";const be=R.has(g.index),ye=be&&C===g.index;be&&de.classList.add("is-active"),de.title=Je(g.overlay),de.style.left=`${U.left+$.x*U.scaleX}px`,de.style.top=`${U.top+$.y*U.scaleY}px`,de.style.width=`${Math.max(18,$.w*U.scaleX)}px`,de.style.height=`${Math.max(18,$.h*U.scaleY)}px`;const Be=un(g.overlay);if(Be&&(de.style.transform=`rotate(${Be}deg)`,de.style.transformOrigin="center center"),de.addEventListener("pointerdown",Ee=>{if(Ee.preventDefault(),Ee.stopPropagation(),Ee.shiftKey||Ee.ctrlKey||Ee.metaKey){ce(g.index,Ee,Fe);return}C=g.index,bt(e,"text",[g.index]),N(!0),Ve(g.index,Ee,U)}),ye){for(const $e of V){const Ne=document.createElement("span");Ne.className="me-video-text-canvas-handle",Ne.dataset.handle=$e.key,Ne.style.left=`${$e.x*100}%`,Ne.style.top=`${$e.y*100}%`,Ne.addEventListener("pointerdown",De=>{De.preventDefault(),De.stopPropagation(),C=g.index,bt(e,"text",[g.index]),N(!0),Ze(g.index,$e,De,U)}),de.appendChild(Ne)}const Ee=document.createElement("span");Ee.className="me-video-text-canvas-handle",Ee.dataset.handle=X.key,Ee.style.left=`${X.x*100}%`,Ee.style.top=`${X.y*100}%`,Ee.addEventListener("pointerdown",$e=>{$e.preventDefault(),$e.stopPropagation(),C=g.index,bt(e,"text",[g.index]),N(!0),at(g.index,$e,U)}),de.appendChild(Ee)}w.appendChild(de)}}function St(S,R,U){if(!he)return;const Te=(t.getState().overlays??[])[S];if(!Te||Te.type!=="sticker")return;if(U.shiftKey||U.ctrlKey||U.metaKey){U.preventDefault(),U.stopPropagation();const $e=Pt(e,"text",S,U,sr(t.getState()).map(Ne=>Ne.index));C=$e.length?$e[$e.length-1]:null,D(),N(!0);return}U.preventDefault(),U.stopPropagation(),C=S,bt(e,"text",[S]),D(),E||N(!0);const Fe=fe(),p=Math.max(he.clientWidth/Fe,.001),g=lt(Te),$=Bt(Te,g),de=Math.max(je,$-g),be=vt(Te),ye=U.clientX,Be=$e=>{const Ne=($e.clientX-ye)/p,De=t.getState().overlays??[];if(R==="move"){const Pe=Math.max(0,g+Ne),Ue=Pe+de,ct=pt(ne,De,S,Pe,Ue,$e.clientY,be);ze(S,{startAt:Pe,endAt:Ue,timelineTrack:ct},{transient:!0});return}if(R==="start"){const Pe=ae(g+Ne,0,$-je),Ue=pt(ne,De,S,Pe,$,$e.clientY,be);ze(S,{startAt:Pe,endAt:$,timelineTrack:Ue},{transient:!0});return}const Qe=Math.max(g+je,$+Ne),He=pt(ne,De,S,g,Qe,$e.clientY,be);ze(S,{startAt:g,endAt:Qe,timelineTrack:He},{transient:!0})},Ee=$e=>{window.removeEventListener("pointermove",Be),window.removeEventListener("pointerup",Ee),window.removeEventListener("pointercancel",Ee);const Ne=($e.clientX-ye)/p,De=t.getState().overlays??[];if(R==="move"){const Pe=Math.max(0,g+Ne),Ue=Pe+de,ct=pt(ne,De,S,Pe,Ue,$e.clientY,be);ze(S,{startAt:Pe,endAt:Ue,timelineTrack:ct});return}if(R==="start"){const Pe=ae(g+Ne,0,$-je),Ue=pt(ne,De,S,Pe,$,$e.clientY,be);ze(S,{startAt:Pe,endAt:$,timelineTrack:Ue});return}const Qe=Math.max(g+je,$+Ne),He=pt(ne,De,S,g,Qe,$e.clientY,be);ze(S,{startAt:g,endAt:Qe,timelineTrack:He})};window.addEventListener("pointermove",Be),window.addEventListener("pointerup",Ee),window.addEventListener("pointercancel",Ee),ut()}function Rt(S,R){if(et(),!ne||!he||(ne.replaceChildren(),ne.hidden=S.length===0,!S.length))return;const U=fe(),Te=he.clientWidth/U,Fe=Rn(t.getState()),p=new Map;for(const g of S){const $=vt(g.overlay),de=Fe.get($)??$;let be=p.get($);be||(be=document.createElement("div"),be.className="me-video-overlay-track-row",be.dataset.track=String($),be.style.top=`${Ln(de)}px`,p.set($,be),ne.appendChild(be));const ye=document.createElement("div");ye.className="me-video-text-track-clip me-video-sticker-track-clip",R.has(g.index)&&ye.classList.add("is-active");const Be=lt(g.overlay),Ee=Sn(g.overlay);ye.style.left=`${Be*Te}px`,ye.style.width=`${Math.max(36,Ee*Te)}px`;const $e=document.createElement("span");$e.className="me-video-text-track-icon",$e.textContent=rt(g.overlay);const Ne=document.createElement("span");Ne.className="me-video-text-track-label",Ne.textContent=Je(g.overlay),Ne.title=Ne.textContent;const De=document.createElement("span");De.className="me-video-text-track-handle is-start";const Qe=document.createElement("span");Qe.className="me-video-text-track-handle is-end",ye.append($e,Ne,De,Qe),ye.addEventListener("pointerdown",He=>St(g.index,"move",He)),De.addEventListener("pointerdown",He=>St(g.index,"start",He)),Qe.addEventListener("pointerdown",He=>St(g.index,"end",He)),ye.addEventListener("click",He=>{if(He.preventDefault(),He.stopPropagation(),He.shiftKey||He.ctrlKey||He.metaKey){D(),ut();return}const Pe=Pt(e,"text",g.index,He,S.map(Ue=>Ue.index));C=Pe.length?Pe[Pe.length-1]:null,D(),N(!0),ut()}),be.appendChild(ye)}}function ut(){pe(()=>{Me();const S=b().find(Te=>Te.classList.contains("is-active"))??null;E&&S&&S!==ie&&S!==Q&&(D(),se());const R=sr(t.getState());K(R);const U=new Set(ur(e,t.getState()));Rt(R,U),Et(R,U),_(),ee()}),Oe()}function It(S){return!!S&&(S===s||s.contains(S)||S===Q||Q?.contains?.(S)||S===ne||ne?.contains?.(S)||S===w||w?.contains?.(S))}function Lt(S){return S.some(R=>{if(!It(R.target))return!0;for(const U of R.addedNodes)if(!It(U))return!0;for(const U of R.removedNodes)if(!It(U))return!0;return!1})}const jt=new MutationObserver(S=>{O||e.__meVideoEnhancerObserverLock||Lt(S)&&(Me(),se())}),At=S=>{S?.detail?.id!==Y&&E&&(E=!1,ut())},Mt=()=>{ut()},mt=S=>{const R=S.target;if(!(R instanceof Node)||!Q||!Q.contains(R))return;S.preventDefault(),S.stopPropagation(),S.stopImmediatePropagation?.();const U=!E;U&&(D(),se()),N(U)};jt.observe(e,{childList:!0,subtree:!0,characterData:!0}),e.addEventListener("me-video-inspector-open",At),e.addEventListener(zt,Mt),e.addEventListener("click",mt,!0),window.addEventListener("resize",ee);const Ut=t.subscribe(()=>{ut()});return F.addEventListener("change",()=>{we(F.files)}),k.addEventListener("dragenter",S=>{S.preventDefault(),k.classList.add("is-dragover")}),k.addEventListener("dragover",S=>{S.preventDefault(),k.classList.add("is-dragover")}),k.addEventListener("dragleave",S=>{S.target===k&&k.classList.remove("is-dragover")}),k.addEventListener("drop",S=>{S.preventDefault(),k.classList.remove("is-dragover"),we(S.dataTransfer?.files)}),Re(),Me=function(){pe(()=>{const S=e.querySelector(".me-video-toolrail");if(!S)return;Z=S;const R=b(Z);ie=Le(R),Q=ve(R),Ie(),ee()})},Me(),ut(),{destroy(){jt.disconnect(),B&&xe&&B.unobserve(xe),q&&x&&q.unobserve(x),Ut(),e.removeEventListener("me-video-inspector-open",At),e.removeEventListener(zt,Mt),e.removeEventListener("click",mt,!0),window.removeEventListener("resize",ee),E=!1,Ie(),ne?.remove(),w?.remove(),s.remove(),Ht(e)}}}function aa(e,t,n){Qt(),kn();const r=Ao(n()),a=_i(r),s=new Map(a.map(p=>[String(p.id??""),p])),u=a.find(p=>p.id)?.id??"",f=document.createElement("div");f.className="me-video-text-panel me-video-color-panel me-video-filter-panel",f.hidden=!0,e.appendChild(f);const v=document.createElement("div");v.className="me-video-text-toolbar";const k=document.createElement("strong");k.textContent=r.filterTitle;const H=Yt(r.reset);v.append(k,H);const G=Kt(r.presets),T=document.createElement("div");T.className="me-video-color-grid",G.body.appendChild(T);const F=a.map(p=>{const g=document.createElement("button");g.type="button",g.className="me-video-color-card",g.dataset.presetId=p.id??"";const $=document.createElement("div");$.className="me-video-color-preview",$.style.filter=p.css||"none";const de=document.createElement("img");de.alt="",de.draggable=!1,de.hidden=!0,$.appendChild(de);const be=document.createElement("div");return be.className="me-video-color-card-title",be.textContent=p.label,g.append($,be),T.appendChild(g),{entry:p,buttonEl:g,previewImage:de}});f.append(v,G.section);let j=null,oe=null,Q=null,Z=null,ie=null,he=null,ne=null,xe=null,te=null,w=null,x=null,E=null,C=!1,y=null,O=!1,Y=!1,L="";const B="filter",q=typeof requestAnimationFrame=="function"?requestAnimationFrame:p=>setTimeout(p,16),V=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>b()),X=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>b()),re=[{key:"tl",x:0,y:0},{key:"tm",x:.5,y:0},{key:"tr",x:1,y:0},{key:"mr",x:1,y:.5},{key:"br",x:1,y:1},{key:"bm",x:.5,y:1},{key:"bl",x:0,y:1},{key:"ml",x:0,y:.5}],pe={key:"rotate",x:.5,y:0};function se(){Promise.resolve().then(()=>{Y=!1;const p=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,p-1)})}function N(p){Y=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return p()}finally{se()}}function b(){O||(O=!0,q(()=>{O=!1,Mt()}))}function le(p=oe){return p?[...p.children].filter(g=>g instanceof HTMLButtonElement&&g!==Z&&!g.classList.contains("me-video-text-tool")):[]}function Le(p){const g=[r.filterTool,r.filterTitle,"filter","filters","\u6EE4\u955C","\u6FFE\u93E1"].map($=>String($??"").trim().toLowerCase()).filter(Boolean);return p.find($=>{const de=Io($);return g.some(be=>de.includes(be))})??p[3]??null}function ve(){Q&&(Q.classList.contains("is-active")||Q.click())}function Ie(){rn(e,f),Ht(e)}function D(p){const g=!!p;if(g===C){Mt();return}C=g,C&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:B}})),Mt()}function ee(){if(j?.classList.toggle("is-active",C),!!Q&&C){Q.classList.remove("is-active");return}}function _(){f.hidden=!C,ee(),Ie()}function K(){const p=t.getState().overlays??[];if(y==null)return null;const g=p[y];return g?.type==="filter"?g:null}function fe(){return Tn(t)}function qe(){return yn(e)}function Oe(){if(!t.history?.present)return;const p=qe(),g=Number(t.history.present.__mePreviewTimelineTime);Math.abs((Number.isFinite(g)?g:-1)-p)<.001||(t.history={...t.history,present:{...t.history.present,__mePreviewTimelineTime:p}},typeof t.emit=="function"&&t.emit())}function Je(p){if(!p.length){y=null;return}const g=mr(e,t.getState());y=g.length?g[g.length-1]:null}function Ge(p){return String(p?.filterPreset??"").trim()}function Ye(p){return s.get(Ge(p))??null}function dt(p){return Ye(p)?.css||"none"}function rt(p){return Ye(p)?.label||r.filterTitle}function ze(p){const g=Number(p?.w),$=Number(p?.h);return!(g>0)||!($>0)?null:{x:Number(p?.x)||0,y:Number(p?.y)||0,w:Math.max(48,g),h:Math.max(48,$)}}function it(p,g){const $=ze(p);if(!$)return p;const de=Math.max(.1,Number(g)||1);return{...p,w:Math.max(48,$.w*de),h:Math.max(48,$.h*de)}}function xt(p,g,$={}){const be=(t.getState().overlays??[])[p];!be||be.type!=="filter"||t.updateOverlay(p,Jt(be,fe(),g),$)}function wt(p,g){y!=null&&t.updateOverlay(y,p,g)}function we(p){if(typeof t.applyMut=="function"){t.applyMut($=>({...$,overlays:[...on($.overlays),{...p,timelineTrack:0}]}));return}const g=on(t.getState().overlays);t.commit?.({overlays:[...g,{...p,timelineTrack:0}]})}function Re(p=u){const g=t.getState().canvas??{w:1080,h:1920},$=ae(Math.round((Number(g.w)||1080)*.68),180,Math.max(180,(Number(g.w)||1080)-48)),de=ae(Math.round((Number(g.h)||1920)*.3),120,Math.max(120,(Number(g.h)||1920)-48));return{type:"filter",x:Math.round(((Number(g.w)||1080)-$)/2),y:Math.round(((Number(g.h)||1920)-de)/2),w:$,h:de,rotation:0,filterPreset:p||void 0}}function Me(p=u){const g=fe();let $=ae(qe(),0,Math.max(0,g-je)),de=Math.min(g,$+qt);de-$<je&&($=ae(g-qt,0,Math.max(0,g-je)),de=Math.max($+je,g));const be={...Re(p),...Jt(null,g,{startAt:$,endAt:de,timelineTrack:0})};we(be);const ye=t.getState().overlays??[];y=ye.length?ye.length-1:null,y!=null&&bt(e,"text",[y]),ht(!0),ve(),D(!0)}function et(p){if(!K()){Me(p);return}wt({filterPreset:p||void 0}),D(!0)}function tt(p){if(p){if(!L){p.hidden=!0,p.removeAttribute("src");return}p.src!==L&&(p.src=L),p.hidden=!1}}function ht(p=!1){if(L&&!p)return;const g=Vi(e);g&&(g===L&&!p||(L=g,F.forEach(({previewImage:$})=>tt($))))}function gt(){K()&&wt({filterPreset:void 0})}function ce(){N(()=>{const p=e.querySelector(".me-video-toolrail");if(!p)return;oe=p;const g=le(oe);Q=io(g),ie=Le(g),ie?(Z?.remove(),j=ie):((!Z||!Z.isConnected)&&(Z=document.createElement("button"),Z.type="button",Z.className="me-video-text-tool me-video-filter-tool",Z.innerHTML=`<span class="me-video-text-tool-icon">\u25A3</span><span class="me-video-text-tool-label">${r.filterTool}</span>`),Z.title=r.filterTool,Z.setAttribute("aria-label",r.filterTool),Z.isConnected?ie?.parentElement===oe&&Z.nextSibling!==ie&&oe.insertBefore(Z,ie):ie?.parentElement===oe?oe.insertBefore(Z,ie):oe.appendChild(Z),j=Z),j?.setAttribute?.("title",r.filterTool),j?.setAttribute?.("aria-label",r.filterTool),ee(),Ie()})}function Se(){const{timelineInner:p,timelineHost:g}=Bn(e,t.getState());if(!p||!g){ne?.remove(),ne=null,V&&xe&&(V.unobserve(xe),xe=null),he=null;return}he=p,(!ne||!ne.isConnected||ne.parentElement!==g)&&(ne?.remove(),ne=document.createElement("div"),ne.className="me-video-text-timeline me-video-overlay-timeline me-video-filter-overlay-layer");for(const $ of[...g.children])$!==ne&&$ instanceof HTMLElement&&$.classList.contains("me-video-filter-overlay-layer")&&$.remove();(ne.parentElement!==g||g.lastElementChild!==ne)&&g.appendChild(ne),V&&xe!==he&&(xe&&V.unobserve(xe),xe=he,V.observe(he))}function Ve(){const p=e.querySelector(".me-video-canvas-stage");if(!p){w?.remove(),w=null,x?.remove(),x=null,X&&E&&(X.unobserve(E),E=null),te=null;return}te=p,te.style.position="relative",(!w||!w.isConnected||w.parentElement!==te)&&(w?.remove(),w=document.createElement("div"),w.className="me-video-filter-effect-layer",te.appendChild(w)),(!x||!x.isConnected||x.parentElement!==te)&&(x?.remove(),x=document.createElement("div"),x.className="me-video-filter-control-layer",te.appendChild(x)),te.lastElementChild!==x&&te.appendChild(x),X&&E!==te&&(E&&X.unobserve(E),E=te,X.observe(te))}function Ze(){if(!te)return null;const g=t.getState().canvas??{},$=Math.max(1,Number(g.w)||0),de=Math.max(1,Number(g.h)||0);if(!$||!de)return null;const be=te.getBoundingClientRect(),ye=te.querySelector("canvas, video, img")||[...te.children].find(De=>De!==w&&De!==x)||null;let Be=0,Ee=0,$e=te.clientWidth||$,Ne=te.clientHeight||de;if(ye instanceof HTMLElement){const De=ye.getBoundingClientRect();De.width>0&&De.height>0&&(Be=De.left-be.left,Ee=De.top-be.top,$e=De.width,Ne=De.height)}if(!($e>0&&Ne>0)){const De=te.clientWidth||$,Qe=te.clientHeight||de,He=Math.min(De/$,Qe/de)||1;$e=$*He,Ne=de*He,Be=Math.max(0,(De-$e)/2),Ee=Math.max(0,(Qe-Ne)/2)}return{stageLeft:be.left,stageTop:be.top,left:Be,top:Ee,scaleX:$e/$,scaleY:Ne/de}}function at(p,g){const $=lt(p),de=Bt(p,$);return g>=$-.001&&g<=de+.001}function Et(p,g,$){const de=Pt(e,"text",p,g,$);y=de.length?de[de.length-1]:null,D(!0),Mt()}function St(p,g,$){return{x:(p-$.stageLeft-$.left)/$.scaleX,y:(g-$.stageTop-$.top)/$.scaleY}}function Rt(p,g,$){const de=(t.getState().overlays??[])[p];if(!de||de.type!=="filter")return;const be=t.getState().canvas??{w:1080,h:1920},ye=ze(de);if(!ye)return;const Be=g.clientX,Ee=g.clientY,$e=Math.max(0,(Number(be.w)||0)-ye.w),Ne=Math.max(0,(Number(be.h)||0)-ye.h),De=(Pe,Ue,ct)=>{const ft=(Pe-Be)/$.scaleX,Ke=(Ue-Ee)/$.scaleY,nt=ae(ye.x+ft,0,$e),ot=ae(ye.y+Ke,0,Ne);t.updateOverlay(p,{x:nt,y:ot},ct?{transient:!0}:void 0)},Qe=Pe=>{Pe.preventDefault(),De(Pe.clientX,Pe.clientY,!0)},He=Pe=>{window.removeEventListener("pointermove",Qe),window.removeEventListener("pointerup",He),window.removeEventListener("pointercancel",He),De(Pe.clientX,Pe.clientY,!1)};window.addEventListener("pointermove",Qe),window.addEventListener("pointerup",He),window.addEventListener("pointercancel",He)}function ut(p,g,$,de){const be=(t.getState().overlays??[])[p];if(!be||be.type!=="filter")return;const ye=ze(be);if(!ye)return;const Be=t.getState().canvas??{w:1080,h:1920},Ee=g.x===.5?.5:1-g.x,$e=g.y===.5?.5:1-g.y,Ne=ye.x+ye.w*Ee,De=ye.y+ye.h*$e,Qe=Math.max(.1,48/Math.max(48,ye.w),48/Math.max(48,ye.h)),He=g.x===.5?1/0:Math.max(.1,(Ee===0?(Number(Be.w)||0)-Ne:Ne)/Math.max(1,ye.w)),Pe=g.y===.5?1/0:Math.max(.1,($e===0?(Number(Be.h)||0)-De:De)/Math.max(1,ye.h)),Ue=Math.max(Qe,Math.min(He,Pe,8)),ct=(nt,ot,Ot)=>{const Ft=St(nt,ot,de),kt=[];g.x!==.5&&kt.push(Math.abs(Ft.x-Ne)/Math.max(1,ye.w)),g.y!==.5&&kt.push(Math.abs(Ft.y-De)/Math.max(1,ye.h));const ln=kt.length?Math.max(...kt):1,an=ae(ln,Qe,Ue),en=it(be,an),Ct=ze(en);if(!Ct)return;const tn=Ne-Ct.w*Ee,m=De-Ct.h*$e;t.updateOverlay(p,{x:tn,y:m,w:Ct.w,h:Ct.h},Ot?{transient:!0}:void 0)},ft=nt=>{nt.preventDefault(),ct(nt.clientX,nt.clientY,!0)},Ke=nt=>{window.removeEventListener("pointermove",ft),window.removeEventListener("pointerup",Ke),window.removeEventListener("pointercancel",Ke),ct(nt.clientX,nt.clientY,!1)};window.addEventListener("pointermove",ft),window.addEventListener("pointerup",Ke),window.addEventListener("pointercancel",Ke)}function It(p,g,$){const de=(t.getState().overlays??[])[p];if(!de||de.type!=="filter")return;const be=ze(de);if(!be)return;const ye=$.stageLeft+$.left+(be.x+be.w/2)*$.scaleX,Be=$.stageTop+$.top+(be.y+be.h/2)*$.scaleY,Ee=Math.atan2(g.clientY-Be,g.clientX-ye),$e=un(de),Ne=(He,Pe,Ue,ct)=>{const ft=Math.atan2(Pe-Be,He-ye);let Ke=In($e+(ft-Ee)*180/Math.PI);ct&&(Ke=Math.round(Ke/15)*15),t.updateOverlay(p,{rotation:Ke},Ue?{transient:!0}:void 0)},De=He=>{He.preventDefault(),Ne(He.clientX,He.clientY,!0,He.shiftKey)},Qe=He=>{window.removeEventListener("pointermove",De),window.removeEventListener("pointerup",Qe),window.removeEventListener("pointercancel",Qe),Ne(He.clientX,He.clientY,!1,He.shiftKey)};window.addEventListener("pointermove",De),window.addEventListener("pointerup",Qe),window.addEventListener("pointercancel",Qe)}function Lt(p,g){if(Ve(),!w||!x)return;if(w.replaceChildren(),x.replaceChildren(),!Ze()){w.hidden=!0,x.hidden=!0;return}x.hidden=!0;const de=qe();if(!p.filter(ye=>at(ye.overlay,de)).length){w.hidden=!0;return}w.hidden=!0}function jt(p,g,$){if(!he)return;const de=(t.getState().overlays??[])[p];if(!de||de.type!=="filter")return;if($.shiftKey||$.ctrlKey||$.metaKey){$.preventDefault(),$.stopPropagation();const Pe=Pt(e,"text",p,$,lr(t.getState()).map(Ue=>Ue.index));y=Pe.length?Pe[Pe.length-1]:null,ve(),D(!0);return}$.preventDefault(),$.stopPropagation(),y=p,bt(e,"text",[p]),ve(),C||D(!0);const be=fe(),ye=Math.max(he.clientWidth/be,.001),Be=lt(de),Ee=Bt(de,Be),$e=Math.max(je,Ee-Be),Ne=vt(de),De=$.clientX,Qe=Pe=>{const Ue=(Pe.clientX-De)/ye,ct=t.getState().overlays??[];if(g==="move"){const nt=Math.max(0,Be+Ue),ot=nt+$e,Ot=pt(ne,ct,p,nt,ot,Pe.clientY,Ne);xt(p,{startAt:nt,endAt:ot,timelineTrack:Ot},{transient:!0});return}if(g==="start"){const nt=ae(Be+Ue,0,Ee-je),ot=pt(ne,ct,p,nt,Ee,Pe.clientY,Ne);xt(p,{startAt:nt,endAt:Ee,timelineTrack:ot},{transient:!0});return}const ft=Math.max(Be+je,Ee+Ue),Ke=pt(ne,ct,p,Be,ft,Pe.clientY,Ne);xt(p,{startAt:Be,endAt:ft,timelineTrack:Ke},{transient:!0})},He=Pe=>{window.removeEventListener("pointermove",Qe),window.removeEventListener("pointerup",He),window.removeEventListener("pointercancel",He);const Ue=(Pe.clientX-De)/ye,ct=t.getState().overlays??[];if(g==="move"){const nt=Math.max(0,Be+Ue),ot=nt+$e,Ot=pt(ne,ct,p,nt,ot,Pe.clientY,Ne);xt(p,{startAt:nt,endAt:ot,timelineTrack:Ot});return}if(g==="start"){const nt=ae(Be+Ue,0,Ee-je),ot=pt(ne,ct,p,nt,Ee,Pe.clientY,Ne);xt(p,{startAt:nt,endAt:Ee,timelineTrack:ot});return}const ft=Math.max(Be+je,Ee+Ue),Ke=pt(ne,ct,p,Be,ft,Pe.clientY,Ne);xt(p,{startAt:Be,endAt:ft,timelineTrack:Ke})};window.addEventListener("pointermove",Qe),window.addEventListener("pointerup",He),window.addEventListener("pointercancel",He),Mt()}function At(p,g){if(Se(),!ne||!he||(ne.replaceChildren(),ne.hidden=p.length===0,!p.length))return;const $=fe(),de=he.clientWidth/$,be=Rn(t.getState()),ye=new Map;for(const Be of p){const Ee=vt(Be.overlay),$e=be.get(Ee)??Ee;let Ne=ye.get(Ee);Ne||(Ne=document.createElement("div"),Ne.className="me-video-overlay-track-row",Ne.dataset.track=String(Ee),Ne.style.top=`${Ln($e)}px`,ye.set(Ee,Ne),ne.appendChild(Ne));const De=document.createElement("div");De.className="me-video-text-track-clip me-video-filter-track-clip",g.has(Be.index)&&De.classList.add("is-active");const Qe=lt(Be.overlay),He=Sn(Be.overlay);De.style.left=`${Qe*de}px`,De.style.width=`${Math.max(36,He*de)}px`;const Pe=document.createElement("span");Pe.className="me-video-text-track-icon",Pe.textContent="Fx";const Ue=document.createElement("span");Ue.className="me-video-text-track-label",Ue.textContent=rt(Be.overlay),Ue.title=Ue.textContent;const ct=document.createElement("span");ct.className="me-video-text-track-handle is-start";const ft=document.createElement("span");ft.className="me-video-text-track-handle is-end",De.append(Pe,Ue,ct,ft),De.addEventListener("pointerdown",Ke=>jt(Be.index,"move",Ke)),ct.addEventListener("pointerdown",Ke=>jt(Be.index,"start",Ke)),ft.addEventListener("pointerdown",Ke=>jt(Be.index,"end",Ke)),De.addEventListener("click",Ke=>{if(Ke.preventDefault(),Ke.stopPropagation(),Ke.shiftKey||Ke.ctrlKey||Ke.metaKey){ve(),Mt();return}const nt=Pt(e,"text",Be.index,Ke,p.map(ot=>ot.index));y=nt.length?nt[nt.length-1]:null,ve(),D(!0),Mt()}),Ne.appendChild(De)}}function Mt(){N(()=>{ce(),ht();const p=lr(t.getState());Je(p);const g=new Set(mr(e,t.getState()));At(p,g),Lt(p,g);const $=Ge(K());F.forEach(({entry:de,buttonEl:be,previewImage:ye})=>{be.classList.toggle("is-active",String(de.id??"")===$),tt(ye)}),H.disabled=!$,_(),Ie()}),Oe()}function mt(p){return!!p&&(p===f||f.contains(p)||p===j||j?.contains?.(p)||p===Z||Z?.contains?.(p)||p===ne||ne?.contains?.(p)||p===w||w?.contains?.(p)||p===x||x?.contains?.(p))}function Ut(p){return p.some(g=>{if(!mt(g.target))return!0;for(const $ of g.addedNodes)if(!mt($))return!0;for(const $ of g.removedNodes)if(!mt($))return!0;return!1})}const S=new MutationObserver(p=>{Y||e.__meVideoEnhancerObserverLock||Ut(p)&&(ce(),b())}),R=p=>{const g=p.target;!(g instanceof Node)||!j||!j.contains(g)||(p.preventDefault(),p.stopPropagation(),p.stopImmediatePropagation?.(),Me(u))},U=p=>{p?.detail?.id!==B&&C&&(C=!1,Mt())},Te=()=>{Mt()};S.observe(e,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["class","style","hidden"]}),e.addEventListener("me-video-inspector-open",U),e.addEventListener(zt,Te),e.addEventListener("click",R,!0),window.addEventListener("resize",Ie);const Fe=t.subscribe(()=>{Mt()});return F.forEach(({entry:p,buttonEl:g})=>{g.addEventListener("click",()=>{et(p.id||"")})}),H.addEventListener("click",()=>{gt()}),ce(),Mt(),{destroy(){S.disconnect(),V&&xe&&V.unobserve(xe),X&&E&&X.unobserve(E),Fe(),e.removeEventListener("me-video-inspector-open",U),e.removeEventListener(zt,Te),e.removeEventListener("click",R,!0),window.removeEventListener("resize",Ie),Z?.remove(),ne?.remove(),w?.remove(),x?.remove(),f.remove(),Ht(e)}}}function sa(e,t,n,r){Qt();const a=Ao(r()),s=Kr(r()),u=Sr(a),f=document.createElement("div");f.className="me-video-text-panel me-video-color-panel me-video-effects-panel",f.hidden=!0,e.appendChild(f);const v=document.createElement("div");v.className="me-video-text-toolbar";const k=document.createElement("strong");k.textContent=s.title;const H=Yt(a.reset),G=Yt(s.close);v.append(k,H,G),f.appendChild(v);const T=document.createElement("p");T.className="me-video-text-hint",T.textContent=s.hint,f.appendChild(T);const F=u.map(D=>{const ee=Kt(D.title),_=D.items.map(K=>{const fe=document.createElement("div");fe.className="me-video-color-slider-control";const qe=document.createElement("span");qe.className="me-video-color-slider-value";const Oe=document.createElement("input");return Oe.type="range",Oe.min=String(K.min),Oe.max=String(K.max),Oe.step="0.02",Oe.dataset.adjustment=K.key,fe.append(qe,Oe),ee.body.appendChild(Tt(K.label,fe)),{...K,value:qe,range:Oe}});return f.appendChild(ee.section),{...D,controls:_}});let j=null,oe=null,Q=null,Z=null,ie=!1,he=!1,ne=!1;const xe="effects",te=typeof requestAnimationFrame=="function"?requestAnimationFrame:D=>setTimeout(D,16);function w(){Promise.resolve().then(()=>{ne=!1;const D=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,D-1)})}function x(D){ne=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return D()}finally{w()}}function E(){he||(he=!0,te(()=>{he=!1,pe()}))}function C(D=oe){return D?[...D.children].filter(ee=>ee instanceof HTMLButtonElement&&ee!==j&&!ee.classList.contains("me-video-text-tool")):[]}function y(){Z&&(Z.isConnected&&(Z.style.display=Z.dataset.meTrimDisplay??"",Z.hidden=Z.dataset.meTrimHidden==="true",delete Z.dataset.meTrimDisplay,delete Z.dataset.meTrimHidden),Z=null)}function O(D){if(!D){y();return}Z!==D&&(y(),D.classList.remove("is-active"),D.dataset.meTrimDisplay=D.style.display??"",D.dataset.meTrimHidden=D.hidden?"true":"false",D.hidden=!0,D.style.display="none",Z=D)}function Y(){if(Q&&!Q.classList.contains("is-active")){Q.click();return}const D=C()[0];D&&!D.classList.contains("is-active")&&D.click()}function L(D){if(!j||!(D instanceof HTMLButtonElement))return;const ee=D.getAttribute("style");ee?j.setAttribute("style",ee):j.removeAttribute("style"),j.hidden=!1,j.style.display=""}function B(){j&&(j.dataset.theme=Kn(n()))}function q(){rn(e,f),Ht(e)}function V(D){const ee=!!D;if(ee===ie){pe();return}ie=ee,ie&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:xe}})),pe()}function X(){if(j?.classList.toggle("is-active",ie),!!Q&&ie){Q.classList.remove("is-active");return}}function re(){f.hidden=!ie,X(),q()}function pe(){x(()=>{C().find(K=>K!==Q&&!K.hidden&&K.style.display!=="none"&&K.classList.contains("is-active"))&&(ie=!1),ie&&Y();const ee=t.getState().filters??{},_=Ho.some(K=>Math.abs(Number(ee[K])||0)>1e-4);F.forEach(K=>{K.controls.forEach(fe=>{const qe=ae(Number(ee[fe.key])||0,fe.min,fe.max);fe.range.value=String(qe),fe.value.textContent=Lr(qe,fe.format)})}),H.disabled=!_,re(),B()})}function se(){x(()=>{const D=e.querySelector(".me-video-toolrail");if(!D)return;oe=D;const ee=C(oe);Q=io(ee),O(Q);const _=Q??ee[0]??null;(!j||!j.isConnected)&&(j=document.createElement("button"),j.type="button",j.className="me-video-text-tool me-video-effects-tool",j.innerHTML=`<span class="me-video-text-tool-icon">${Zr()}</span><span class="me-video-text-tool-label">${s.tool}</span>`),j.setAttribute("title",s.tool),j.setAttribute("aria-label",s.tool),L(_),j.isConnected?_?.parentElement===oe&&j.nextSibling!==_&&oe.insertBefore(j,_):_?.parentElement===oe?oe.insertBefore(j,_):oe.appendChild(j),B(),X(),q()})}function N(D){return!!D&&(D===f||f.contains(D)||D===j||j?.contains?.(D))}function b(D){return D.some(ee=>{if(!N(ee.target))return!0;for(const _ of ee.addedNodes)if(!N(_))return!0;for(const _ of ee.removedNodes)if(!N(_))return!0;return!1})}const le=new MutationObserver(D=>{ne||e.__meVideoEnhancerObserverLock||b(D)&&(se(),E())}),Le=D=>{D?.detail?.id!==xe&&ie&&(ie=!1,pe())},ve=D=>{const ee=D.target;if(!(ee instanceof Node)||!j||!j.contains(ee))return;D.preventDefault(),D.stopPropagation(),D.stopImmediatePropagation?.();const _=!ie;_&&Y(),V(_)};le.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","style","hidden"]}),e.addEventListener("me-video-inspector-open",Le),e.addEventListener("click",ve,!0),window.addEventListener("resize",E);const Ie=t.subscribe(()=>{E()});return F.forEach(D=>{D.controls.forEach(ee=>{ee.range.addEventListener("input",()=>{const _=ae(Number(ee.range.value)||0,ee.min,ee.max);ee.value.textContent=Lr(_,ee.format),t.setFilter(ee.key,_,{transient:!0})}),ee.range.addEventListener("change",()=>{const _=ae(Number(ee.range.value)||0,ee.min,ee.max);t.setFilter(ee.key,_)})})}),H.addEventListener("click",()=>{Di(t)}),G.addEventListener("click",()=>{V(!1)}),se(),pe(),{destroy(){le.disconnect(),Ie(),e.removeEventListener("me-video-inspector-open",Le),e.removeEventListener("click",ve,!0),window.removeEventListener("resize",E),y(),j?.remove(),f.remove(),Ht(e)}}}function la(e,t,n,r){Qt(),kn();const a=Ao(r()),s=Gr(r()),u=Sr(a),f=new Set(["brightness","contrast","saturation","temperature","tint","vibrance","gamma","highlights","shadows","whites","blacks","lightSense"]);function v(l,d,o){return l==="percent"?{min:(1+d)*100,max:(1+o)*100}:{min:d*100,max:o*100}}function k(l,d){const o=Number(l)||0;return d==="percent"?(1+o)*100:o*100}function H(l,d){const o=Number(l)||0;return d==="percent"?o/100-1:o/100}function G(l,d){const o=Math.round(k(l,d)*10)/10;return Number.isInteger(o),String(o)}function T(l,d){let o=Math.abs(Math.round(Number(l)||0)),i=Math.abs(Math.round(Number(d)||0));for(;i;){const c=o%i;o=i,i=c}return o||1}function F(l){const d=Math.max(1,Vt(l?.w??0)),o=Math.max(1,Vt(l?.h??0)),i=T(d,o);return`${d/i}:${o/i}`}function j(l){const d=Number(l);if(!(d>0))return s.notAvailable;const o=["B","KB","MB","GB","TB"];let i=d,c=0;for(;i>=1024&&c<o.length-1;)i/=1024,c+=1;const h=i>=100||c===0?0:i>=10?1:2;return`${i.toFixed(h)} ${o[c]}`}function oe(l){const d=Number(l);return d>0?`${d.toFixed(2)} fps`:s.notAvailable}function Q(l,d){const o=Number(l),i=Number(d);if(!(o>0)||!(i>0))return s.notAvailable;const c=o*8/i;return c>=1e6?`${(c/1e6).toFixed(2)} Mbps`:c>=1e3?`${Math.round(c/1e3)} Kbps`:`${Math.round(c)} bps`}function Z(l){const d=String(l?.file?.type||l?.type||l?.mime||"").trim();if(d.includes("/"))return d.split("/").pop().toUpperCase();const i=String(l?.file?.name||l?.name||"").trim().match(/\.([a-z0-9]+)$/i);return i?i[1].toUpperCase():s.notAvailable}function ie(l){return String(l?.codec||l?.videoCodec||l?.codecName||l?.encoding||"").trim()||s.notAvailable}function he(l){const d=Math.max(0,Math.round(Number(l?.width??l?.dims?.w)||0)),o=Math.max(0,Math.round(Number(l?.height??l?.dims?.h)||0));return!(d>0)||!(o>0)?s.notAvailable:`${d} x ${o} px`}function ne(){const d=t.getState().clips??[],o=_t(e,"video").filter(I=>!!d[I]),c=(d[o[o.length-1]]??d[0]??null)?.srcIdx??0;return{source:(typeof t.getVideoSource=="function"?t.getVideoSource(c):null)??t.videoSources?.[c]??t.videoSources?.[0]??null,sourceIndex:c}}function xe(){const l=t.getState(),{source:d,sourceIndex:o}=ne(),i=l.canvas??{w:1080,h:1920},c=Yn(l),h=Number(d?.frameRate??d?.fps)||30,I=Number(d?.duration)||Me()||0,A=Number(d?.file?.size??d?.size)||0;return{videoName:String(d?.file?.name||d?.name||"").trim()||(d?`video-${o+1}`:s.notAvailable),ratio:F(c),canvasSize:On(i),resolution:On(c),frameRate:oe(h),bitrate:Q(A,I),format:Z(d),fileSize:j(A),codec:ie(d),sourceSize:he(d),videoLength:mn(Me())}}const te=document.createElement("div");te.className="me-video-text-panel me-video-color-panel me-video-effects-panel me-video-feature-one-panel",te.hidden=!0,e.appendChild(te);const w=document.createElement("div");w.className="me-video-text-toolbar";const x=document.createElement("strong");x.textContent=s.title;const E=Yt(a.reset);w.append(x,E);const C=document.createElement("p");C.className="me-video-text-hint",C.textContent=s.hint;const y=document.createElement("div");y.className="me-video-text-empty",y.textContent=s.placeholder;const O=document.createElement("div");O.className="me-video-text-panel me-video-feature-one-info-panel",O.hidden=!0,e.appendChild(O);const Y=document.createElement("div");Y.className="me-video-text-toolbar";const L=document.createElement("strong");L.textContent=s.videoInfoTitle,Y.append(L);const B=Kt(s.videoInfoTitle);B.section.classList.add("me-video-feature-one-meta-section"),B.title.remove();const q=[{key:"videoName",label:s.videoName},{key:"ratio",label:s.ratio},{key:"canvasSize",label:s.canvasSize},{key:"resolution",label:s.resolution},{key:"frameRate",label:s.frameRate},{key:"bitrate",label:s.bitrate},{key:"format",label:s.format},{key:"fileSize",label:s.fileSize},{key:"codec",label:s.codec},{key:"sourceSize",label:s.sourceSize},{key:"videoLength",label:s.videoLength}].map(l=>{const d=document.createElement("div");return d.className="me-video-feature-one-meta-value",B.body.appendChild(Tt(l.label,d)),{...l,valueEl:d}});te.append(w,C,y),O.append(Y,B.section);const V=u.map(l=>{const d=Kt(l.title),o=l.items.map(i=>{const c=v(i.format,i.min,i.max),h=document.createElement("div");h.className="me-video-color-slider-control me-video-color-number-control";const I=document.createElement("input");I.type="range",I.min=String(i.min),I.max=String(i.max),I.step="0.01",I.dataset.adjustment=i.key;const A=document.createElement("input");return A.type="number",A.min=String(c.min),A.max=String(c.max),A.step="1",A.inputMode="decimal",A.dataset.adjustment=i.key,h.append(I,A),d.body.appendChild(Tt(i.label,h)),{...i,range:I,input:A,displayMin:c.min,displayMax:c.max}});return te.appendChild(d.section),{...l,section:d.section,controls:o}});let X=null,re=null,pe=null,se=null,N=null,b=null,le=null,Le=null,ve=null,Ie=null,D=null,ee=!1,_=null,K=!1,fe=!1;const qe="adjust",Oe=typeof requestAnimationFrame=="function"?requestAnimationFrame:l=>setTimeout(l,16),Je=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>it()),Ge=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>it()),Ye=[{key:"tl",x:0,y:0},{key:"tm",x:.5,y:0},{key:"tr",x:1,y:0},{key:"mr",x:1,y:.5},{key:"br",x:1,y:1},{key:"bm",x:.5,y:1},{key:"bl",x:0,y:1},{key:"ml",x:0,y:.5}],dt={key:"rotate",x:.5,y:0};function rt(){Promise.resolve().then(()=>{fe=!1;const l=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,l-1)})}function ze(l){fe=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return l()}finally{rt()}}function it(){K||(K=!0,Oe(()=>{K=!1,ot()}))}function xt(l=re){return l?[...l.children].filter(d=>d instanceof HTMLButtonElement&&d!==X&&!d.classList.contains("me-video-text-tool")):[]}function wt(){se&&(se.isConnected&&(se.style.display=se.dataset.meTrimDisplay??"",se.hidden=se.dataset.meTrimHidden==="true",delete se.dataset.meTrimDisplay,delete se.dataset.meTrimHidden),se=null)}function we(l){if(!l){wt();return}se!==l&&(wt(),l.classList.remove("is-active"),l.dataset.meTrimDisplay=l.style.display??"",l.dataset.meTrimHidden=l.hidden?"true":"false",l.hidden=!0,l.style.display="none",se=l)}function Re(){if(pe&&!pe.classList.contains("is-active")){pe.click();return}const l=xt()[0];l&&!l.classList.contains("is-active")&&l.click()}function Me(){return Tn(t)}function et(){return yn(e)}function tt(){if(!t.history?.present)return;const l=et(),d=Number(t.history.present.__mePreviewTimelineTime);Math.abs((Number.isFinite(d)?d:-1)-l)<.001||(t.history={...t.history,present:{...t.history.present,__mePreviewTimelineTime:l}},typeof t.emit=="function"&&t.emit())}function ht(l){const d={...An};for(const o of Ho){const i=Number(l?.[o]);Number.isFinite(i)&&(d[o]=f.has(o)?ae(i,-1,1):ae(i,0,1))}return d}function gt(l){const d=ht(l);return Ho.some(o=>Math.abs(Number(d[o])||0)>1e-4)}function ce(l){const d=ht(l),o=[],i=Yr(d,"");return i&&o.push(i),Math.abs(d.vibrance)>1e-4&&o.push(`saturate(${(1+d.vibrance*.65).toFixed(3)})`),Math.abs(d.temperature)>1e-4&&(d.temperature>0&&o.push(`sepia(${Math.min(.36,d.temperature*.28).toFixed(3)})`),o.push(`hue-rotate(${(-d.temperature*14).toFixed(2)}deg)`)),Math.abs(d.tint)>1e-4&&o.push(`hue-rotate(${(d.tint*10).toFixed(2)}deg)`),Math.abs(d.gamma)>1e-4&&o.push(`brightness(${(1+d.gamma*.08).toFixed(3)})`),(d.clarity>1e-4||d.sharpen>1e-4)&&o.push(`contrast(${(1+d.clarity*.16+d.sharpen*.1).toFixed(3)})`),o.join(" ").trim()||"none"}function Se(l){const d=ht(l),o=[];if(d.fade>1e-4&&o.push(`linear-gradient(0deg, rgba(255,245,235,${(d.fade*.18).toFixed(3)}), rgba(255,245,235,${(d.fade*.18).toFixed(3)}))`),d.vignette>1e-4){const i=(.28+d.vignette*.3).toFixed(3),c=(.16+d.vignette*.22).toFixed(3);o.push(`radial-gradient(circle at center, rgba(0,0,0,0) ${i}, rgba(0,0,0,${c}) 100%)`)}return d.grain>1e-4&&o.push(`linear-gradient(135deg, rgba(255,255,255,${(d.grain*.05).toFixed(3)}) 0%, rgba(0,0,0,${(d.grain*.05).toFixed(3)}) 100%)`),o.join(", ")}function Ve(){const l=t.getState().overlays??[];if(_==null)return null;const d=l[_];return d?.type==="adjust"?d:null}function Ze(l){if(!l.length){_=null;return}const d=eo(e,t.getState());_=d.length?d[d.length-1]:null}function at(l){const d=Number(l?.w),o=Number(l?.h);return!(d>0)||!(o>0)?null:{x:Number(l?.x)||0,y:Number(l?.y)||0,w:Math.max(48,d),h:Math.max(48,o)}}function Et(l,d){const o=at(l);if(!o)return l;const i=Math.max(.1,Number(d)||1);return{...l,w:Math.max(48,o.w*i),h:Math.max(48,o.h*i)}}function St(l,d,o={}){const c=(t.getState().overlays??[])[l];!c||c.type!=="adjust"||t.updateOverlay(l,Jt(c,Me(),d),o)}function Rt(l,d){_!=null&&t.updateOverlay(_,l,d)}function ut(l){const d=t.getState().overlays??[],o=d.length;if(typeof t.applyMut=="function")return t.applyMut(c=>({...c,overlays:[...on(c.overlays),{...l,timelineTrack:0}]})),o;const i=on(d);return t.commit?.({overlays:[...i,{...l,timelineTrack:0}]}),o}function It(){const l=t.getState().canvas??{w:1080,h:1920};return{type:"adjust",x:0,y:0,w:Math.max(1,Number(l.w)||1080),h:Math.max(1,Number(l.h)||1920),rotation:0,...An}}function Lt(){const l=Me();let d=ae(et(),0,Math.max(0,l-je)),o=Math.min(l,d+qt);o-d<je&&(d=ae(l-qt,0,Math.max(0,l-je)),o=Math.max(d+je,l));const i={...It(),...Jt(null,l,{startAt:d,endAt:o,timelineTrack:0})},c=ut(i);_=Number.isInteger(c)?c:null,bt(e,"text",_==null?[]:[_],{preserveOther:!0}),Re(),ft(_!=null)}function jt(){const l=t.getState(),d=Mo(l.overlays??[],eo(e,l));d.changed&&(t.commit({overlays:d.overlays}),_=d.selection.length?d.selection[d.selection.length-1]:null,bt(e,"text",d.selection),ot())}function At(){const l=t.getState(),d=Co(l.overlays??[],eo(e,l));d.changed&&(t.commit({overlays:d.overlays}),_=null,bt(e,"text",[]),ot())}function Mt(){Ve()&&Rt({...An})}function mt(l){if(!X||!(l instanceof HTMLButtonElement))return;const d=l.getAttribute("style");d?X.setAttribute("style",d):X.removeAttribute("style"),X.hidden=!1,X.style.display=""}function Ut(){X&&(X.dataset.theme=Kn(n()))}function S(){rn(e,te),rn(e,O),Ht(e)}function R(){const{timelineInner:l,timelineHost:d}=Bn(e,t.getState());if(!l||!d){b?.remove(),b=null,Je&&le&&(Je.unobserve(le),le=null),N=null;return}N=l,(!b||!b.isConnected||b.parentElement!==d)&&(b?.remove(),b=document.createElement("div"),b.className="me-video-text-timeline me-video-overlay-timeline me-video-feature-one-overlay-layer");for(const o of[...d.children])o!==b&&o instanceof HTMLElement&&o.classList.contains("me-video-feature-one-overlay-layer")&&o.remove();(b.parentElement!==d||d.lastElementChild!==b)&&d.appendChild(b),Je&&le!==N&&(le&&Je.unobserve(le),le=N,Je.observe(N))}function U(){const l=e.querySelector(".me-video-canvas-stage");if(!l){ve?.remove(),ve=null,Ie?.remove(),Ie=null,Ge&&D&&(Ge.unobserve(D),D=null),Le=null;return}Le=l,Le.style.position="relative",(!ve||!ve.isConnected||ve.parentElement!==Le)&&(ve?.remove(),ve=document.createElement("div"),ve.className="me-video-filter-effect-layer",Le.appendChild(ve)),(!Ie||!Ie.isConnected||Ie.parentElement!==Le)&&(Ie?.remove(),Ie=document.createElement("div"),Ie.className="me-video-filter-control-layer",Le.appendChild(Ie)),Le.lastElementChild!==Ie&&Le.appendChild(Ie),Ge&&D!==Le&&(D&&Ge.unobserve(D),D=Le,Ge.observe(Le))}function Te(){if(!Le)return null;const d=t.getState().canvas??{},o=Math.max(1,Number(d.w)||0),i=Math.max(1,Number(d.h)||0);if(!o||!i)return null;const c=Le.getBoundingClientRect(),h=Le.querySelector("canvas, video, img")||[...Le.children].find(z=>z!==ve&&z!==Ie)||null;let I=0,A=0,J=Le.clientWidth||o,M=Le.clientHeight||i;if(h instanceof HTMLElement){const z=h.getBoundingClientRect();z.width>0&&z.height>0&&(I=z.left-c.left,A=z.top-c.top,J=z.width,M=z.height)}if(!(J>0&&M>0)){const z=Le.clientWidth||o,me=Le.clientHeight||i,ue=Math.min(z/o,me/i)||1;J=o*ue,M=i*ue,I=Math.max(0,(z-J)/2),A=Math.max(0,(me-M)/2)}return{stageLeft:c.left,stageTop:c.top,left:I,top:A,scaleX:J/o,scaleY:M/i}}function Fe(l,d){const o=lt(l),i=Bt(l,o);return d>=o-.001&&d<=i+.001}function p(l,d,o){const i=Pt(e,"text",l,d,o);_=i.length?i[i.length-1]:null,ft(!0),ot()}function g(l,d,o){return{x:(l-o.stageLeft-o.left)/o.scaleX,y:(d-o.stageTop-o.top)/o.scaleY}}function $(l,d,o){const i=(t.getState().overlays??[])[l];if(!i||i.type!=="adjust")return;const c=t.getState().canvas??{w:1080,h:1920},h=at(i);if(!h)return;const I=d.clientX,A=d.clientY,J=Math.max(0,(Number(c.w)||0)-h.w),M=Math.max(0,(Number(c.h)||0)-h.h),z=(Ce,ke,ge)=>{const Ae=(Ce-I)/o.scaleX,_e=(ke-A)/o.scaleY,Xe=ae(h.x+Ae,0,J),We=ae(h.y+_e,0,M);t.updateOverlay(l,{x:Xe,y:We},ge?{transient:!0}:void 0)},me=Ce=>{Ce.preventDefault(),z(Ce.clientX,Ce.clientY,!0)},ue=Ce=>{window.removeEventListener("pointermove",me),window.removeEventListener("pointerup",ue),window.removeEventListener("pointercancel",ue),z(Ce.clientX,Ce.clientY,!1)};window.addEventListener("pointermove",me),window.addEventListener("pointerup",ue),window.addEventListener("pointercancel",ue)}function de(l,d,o,i){const c=(t.getState().overlays??[])[l];if(!c||c.type!=="adjust")return;const h=at(c);if(!h)return;const I=t.getState().canvas??{w:1080,h:1920},A=d.x===.5?.5:1-d.x,J=d.y===.5?.5:1-d.y,M=h.x+h.w*A,z=h.y+h.h*J,me=Math.max(.1,48/Math.max(48,h.w),48/Math.max(48,h.h)),ue=d.x===.5?1/0:Math.max(.1,(A===0?(Number(I.w)||0)-M:M)/Math.max(1,h.w)),Ce=d.y===.5?1/0:Math.max(.1,(J===0?(Number(I.h)||0)-z:z)/Math.max(1,h.h)),ke=Math.max(me,Math.min(ue,Ce,8)),ge=(Xe,We,st)=>{const Nt=g(Xe,We,i),$t=[];d.x!==.5&&$t.push(Math.abs(Nt.x-M)/Math.max(1,h.w)),d.y!==.5&&$t.push(Math.abs(Nt.y-z)/Math.max(1,h.h));const cn=$t.length?Math.max(...$t):1,dn=ae(cn,me,ke),Hn=Et(c,dn),hn=at(Hn);if(!hn)return;const Xn=M-hn.w*A,xn=z-hn.h*J;t.updateOverlay(l,{x:Xn,y:xn,w:hn.w,h:hn.h},st?{transient:!0}:void 0)},Ae=Xe=>{Xe.preventDefault(),ge(Xe.clientX,Xe.clientY,!0)},_e=Xe=>{window.removeEventListener("pointermove",Ae),window.removeEventListener("pointerup",_e),window.removeEventListener("pointercancel",_e),ge(Xe.clientX,Xe.clientY,!1)};window.addEventListener("pointermove",Ae),window.addEventListener("pointerup",_e),window.addEventListener("pointercancel",_e)}function be(l,d,o){const i=(t.getState().overlays??[])[l];if(!i||i.type!=="adjust")return;const c=at(i);if(!c)return;const h=o.stageLeft+o.left+(c.x+c.w/2)*o.scaleX,I=o.stageTop+o.top+(c.y+c.h/2)*o.scaleY,A=Math.atan2(d.clientY-I,d.clientX-h),J=un(i),M=(ue,Ce,ke,ge)=>{const Ae=Math.atan2(Ce-I,ue-h);let _e=In(J+(Ae-A)*180/Math.PI);ge&&(_e=Math.round(_e/15)*15),t.updateOverlay(l,{rotation:_e},ke?{transient:!0}:void 0)},z=ue=>{ue.preventDefault(),M(ue.clientX,ue.clientY,!0,ue.shiftKey)},me=ue=>{window.removeEventListener("pointermove",z),window.removeEventListener("pointerup",me),window.removeEventListener("pointercancel",me),M(ue.clientX,ue.clientY,!1,ue.shiftKey)};window.addEventListener("pointermove",z),window.addEventListener("pointerup",me),window.addEventListener("pointercancel",me)}function ye(l,d){if(U(),!ve||!Ie)return;if(ve.replaceChildren(),Ie.replaceChildren(),!Te()){ve.hidden=!0,Ie.hidden=!0;return}Ie.hidden=!0;const i=et();if(!l.filter(h=>Fe(h.overlay,i)).length){ve.hidden=!0;return}ve.hidden=!0}function Be(l,d,o){if(!N)return;const i=(t.getState().overlays??[])[l];if(!i||i.type!=="adjust")return;if(o.shiftKey||o.ctrlKey||o.metaKey){o.preventDefault(),o.stopPropagation();const Ce=Pt(e,"text",l,o,cr(t.getState()).map(ke=>ke.index));_=Ce.length?Ce[Ce.length-1]:null,Re(),ft(!0);return}o.preventDefault(),o.stopPropagation(),_=l,bt(e,"text",[l]),Re(),ee||ft(!0);const c=Me(),h=Math.max(N.clientWidth/c,.001),I=lt(i),A=Bt(i,I),J=Math.max(je,A-I),M=vt(i),z=o.clientX,me=Ce=>{const ke=(Ce.clientX-z)/h,ge=t.getState().overlays??[];if(d==="move"){const Xe=Math.max(0,I+ke),We=Xe+J,st=pt(b,ge,l,Xe,We,Ce.clientY,M);St(l,{startAt:Xe,endAt:We,timelineTrack:st},{transient:!0});return}if(d==="start"){const Xe=ae(I+ke,0,A-je),We=pt(b,ge,l,Xe,A,Ce.clientY,M);St(l,{startAt:Xe,endAt:A,timelineTrack:We},{transient:!0});return}const Ae=Math.max(I+je,A+ke),_e=pt(b,ge,l,I,Ae,Ce.clientY,M);St(l,{startAt:I,endAt:Ae,timelineTrack:_e},{transient:!0})},ue=Ce=>{window.removeEventListener("pointermove",me),window.removeEventListener("pointerup",ue),window.removeEventListener("pointercancel",ue);const ke=(Ce.clientX-z)/h,ge=t.getState().overlays??[];if(d==="move"){const Xe=Math.max(0,I+ke),We=Xe+J,st=pt(b,ge,l,Xe,We,Ce.clientY,M);St(l,{startAt:Xe,endAt:We,timelineTrack:st});return}if(d==="start"){const Xe=ae(I+ke,0,A-je),We=pt(b,ge,l,Xe,A,Ce.clientY,M);St(l,{startAt:Xe,endAt:A,timelineTrack:We});return}const Ae=Math.max(I+je,A+ke),_e=pt(b,ge,l,I,Ae,Ce.clientY,M);St(l,{startAt:I,endAt:Ae,timelineTrack:_e})};window.addEventListener("pointermove",me),window.addEventListener("pointerup",ue),window.addEventListener("pointercancel",ue),ot()}function Ee(l,d){if(R(),!b||!N||(b.replaceChildren(),b.hidden=l.length===0,!l.length))return;const o=Me(),i=N.clientWidth/o,c=Rn(t.getState()),h=new Map;for(const I of l){const A=vt(I.overlay),J=c.get(A)??A;let M=h.get(A);M||(M=document.createElement("div"),M.className="me-video-overlay-track-row",M.dataset.track=String(A),M.style.top=`${Ln(J)}px`,h.set(A,M),b.appendChild(M));const z=document.createElement("div");z.className="me-video-text-track-clip me-video-filter-track-clip",d.has(I.index)&&z.classList.add("is-active");const me=lt(I.overlay),ue=Sn(I.overlay);z.style.left=`${me*i}px`,z.style.width=`${Math.max(36,ue*i)}px`;const Ce=document.createElement("span");Ce.className="me-video-text-track-icon",Ce.textContent="Adj";const ke=document.createElement("span");ke.className="me-video-text-track-label",ke.textContent=s.tool,ke.title=ke.textContent;const ge=document.createElement("span");ge.className="me-video-text-track-handle is-start";const Ae=document.createElement("span");Ae.className="me-video-text-track-handle is-end",z.append(Ce,ke,ge,Ae),z.addEventListener("pointerdown",_e=>Be(I.index,"move",_e)),ge.addEventListener("pointerdown",_e=>Be(I.index,"start",_e)),Ae.addEventListener("pointerdown",_e=>Be(I.index,"end",_e)),z.addEventListener("click",_e=>{if(_e.preventDefault(),_e.stopPropagation(),_e.shiftKey||_e.ctrlKey||_e.metaKey){Re(),ot();return}const Xe=Pt(e,"text",I.index,_e,l.map(We=>We.index));_=Xe.length?Xe[Xe.length-1]:null,Re(),ft(!0),ot()}),M.appendChild(z)}}function $e(l){V.forEach(d=>{d.controls.forEach(o=>{o.range.disabled=l,o.input.disabled=l})}),E.disabled=l}function Ne(){const l=xe();q.forEach(d=>{const o=String(l[d.key]??s.notAvailable);d.valueEl.textContent=o,d.valueEl.title=o})}function De(l){const d=!!l;if($e(!d),E.hidden=!d,y.hidden=d,V.forEach(i=>{i.section.hidden=!d}),Ne(),!d)return;const o=ht(l);V.forEach(i=>{i.controls.forEach(c=>{const h=ae(Number(o[c.key])||0,c.min,c.max);c.range.value=String(h),c.input.value=G(h,c.format)})}),d&&(E.disabled=!gt(l))}function Qe(){return ee&&!!Ve()}function He(){return xt().some(o=>o!==pe&&!o.hidden&&o.style.display!=="none"&&o.classList.contains("is-active"))?!0:[...e.querySelectorAll(".me-video-toolrail .me-video-text-tool.is-active")].some(o=>o!==X)}function Pe(){const l=uo(e);return l instanceof HTMLElement?[...l.children].some(d=>d instanceof HTMLElement&&d!==te&&d!==O&&!d.hidden):!1}function Ue(){return ee&&!!Ve()&&!He()}function ct(){const l=Mn(e,t.getState().audioClips??[]).length>0;return!He()&&!Pe()&&!l&&!Ve()}function ft(l){const d=!!l;if(d===ee){ot();return}ee=d,ee&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:qe}})),ot()}function Ke(){ee=!1,_=null,e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:"video-info"}})),te.hidden=!0,Ne(),O.hidden=!1,Ft(),S()}function nt(){te.hidden=!Ue(),O.hidden=!ct(),Ft(),S()}function ot(){ze(()=>{He()&&(ee=!1),ee&&Re(),Ot();const l=cr(t.getState());Ze(l);const d=new Set(eo(e,t.getState()));Ee(l,d),ye(l,d),De(Ve()),nt(),Ut()}),tt()}function Ot(){ze(()=>{const l=e.querySelector(".me-video-toolrail");if(!l)return;re=l;const d=xt(re);pe=io(d),we(pe);const o=pe??d[0]??null;(!X||!X.isConnected)&&(X=document.createElement("button"),X.type="button",X.className="me-video-text-tool me-video-feature-one-tool",X.innerHTML=`<span class="me-video-text-tool-icon">${Jr()}</span><span class="me-video-text-tool-label">${s.tool}</span>`,X.addEventListener("click",()=>{Lt()})),X.setAttribute("title",s.tool),X.setAttribute("aria-label",s.tool),mt(o),X.isConnected?o?.parentElement===re&&X.nextSibling!==o&&re.insertBefore(X,o):o?.parentElement===re?re.insertBefore(X,o):re.appendChild(X),Ut(),X.classList.toggle("is-active",Qe()),Ft(),S()})}function Ft(){if(X?.classList.toggle("is-active",Qe()),!!pe){if(Qe()){pe.classList.remove("is-active");return}pe.classList.remove("is-active")}}function kt(l){return!!l&&(l===te||te.contains(l)||l===O||O.contains(l)||l===X||X?.contains?.(l)||l===b||b?.contains?.(l)||l===ve||ve?.contains?.(l)||l===Ie||Ie?.contains?.(l))}function ln(l){return l.some(d=>{if(!kt(d.target))return!0;for(const o of d.addedNodes)if(!kt(o))return!0;for(const o of d.removedNodes)if(!kt(o))return!0;return!1})}const an=new MutationObserver(l=>{fe||e.__meVideoEnhancerObserverLock||ln(l)&&(Ot(),it())}),en=l=>{l?.detail?.id===qe||l?.detail?.id==="video-info"||(ee=!1,te.hidden=!0,O.hidden=!0,Ft(),S(),it())},Ct=l=>{const d=l.target;d instanceof Element&&d.closest(".me-video-toolrail button")&&it()},tn=()=>{if(!So(e)){Ke();return}ot()};an.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","style","hidden"]}),e.addEventListener("me-video-inspector-open",en),e.addEventListener("click",Ct,!0),e.addEventListener(zt,tn),window.addEventListener("resize",S);const m=t.subscribe(()=>{ot()});function P(l){const d=Number(l.input.value);if(!Number.isFinite(d))return null;const o=ae(d,l.displayMin,l.displayMax),i=ae(H(o,l.format),l.min,l.max);return{displayValue:o,internalValue:i}}function W(l){const d=Number(l.range.value);if(!Number.isFinite(d))return null;const o=ae(d,l.min,l.max);return{internalValue:o,displayValue:ae(k(o,l.format),l.displayMin,l.displayMax)}}return V.forEach(l=>{l.controls.forEach(d=>{d.range.addEventListener("input",()=>{const o=W(d);o&&(d.input.value=G(o.internalValue,d.format),Rt({[d.key]:o.internalValue},{transient:!0}))}),d.range.addEventListener("change",()=>{const o=W(d);if(!o){ot();return}d.input.value=G(o.internalValue,d.format),Rt({[d.key]:o.internalValue})}),d.input.addEventListener("input",()=>{const o=P(d);o&&(d.range.value=String(o.internalValue),Rt({[d.key]:o.internalValue},{transient:!0}))}),d.input.addEventListener("change",()=>{const o=P(d);if(!o){ot();return}d.range.value=String(o.internalValue),d.input.value=G(o.internalValue,d.format),Rt({[d.key]:o.internalValue})}),d.input.addEventListener("blur",()=>{const o=P(d);if(!o){ot();return}d.range.value=String(o.internalValue),d.input.value=G(o.internalValue,d.format)})})}),E.addEventListener("click",()=>{Mt()}),Ot(),ot(),{destroy(){an.disconnect(),m(),Je&&le&&Je.unobserve(le),Ge&&D&&Ge.unobserve(D),e.removeEventListener("me-video-inspector-open",en),e.removeEventListener("click",Ct,!0),e.removeEventListener(zt,tn),window.removeEventListener("resize",S),wt(),X?.remove(),b?.remove(),ve?.remove(),Ie?.remove(),te.remove(),O.remove(),Ht(e)}}}function ca(e,t,n){Qt();const r=zi(n()),a=qi(),s=Ki(a),u=document.createElement("div");u.className="me-video-text-panel me-video-ratio-panel",u.hidden=!0,e.appendChild(u);const f=document.createElement("div");f.className="me-video-text-toolbar";const v=document.createElement("strong");v.textContent=r.title,f.append(v);const k=Kt(r.commonPresets),H=document.createElement("div");H.className="me-video-ratio-card-grid",k.body.appendChild(H);const G=Kt(r.customSize),T=document.createElement("input");T.type="number",T.min="2",T.step="2",T.className="me-video-text-input";const F=document.createElement("input");F.type="number",F.min="2",F.step="2",F.className="me-video-text-input";const j=to(r.width,T),oe=to(r.height,F),Q=document.createElement("div");Q.className="me-video-ratio-dimension-grid";const Z=document.createElement("div");Z.className="me-video-ratio-cross",Z.textContent="x",Q.append(j,Z,oe);const ie=document.createElement("div");ie.className="me-video-ratio-lock-row";const he=document.createElement("button");he.type="button",he.className="me-video-ratio-lock-toggle me-video-ratio-lock-inline";const ne=document.createElement("button");ne.type="button",ne.className="me-video-ratio-quick",ne.textContent=r.quickPortrait;const xe=document.createElement("button");xe.type="button",xe.className="me-video-ratio-quick",xe.textContent=r.quickLandscape,G.title.appendChild(he),ie.append(ne,xe);const te=document.createElement("p");te.className="me-video-ratio-summary",G.body.append(Q,ie,te);const w=Kt(r.fitMode),x=document.createElement("div");x.className="me-video-ratio-fit-group";const E=[{fit:"cover",label:r.cover},{fit:"contain",label:r.contain},{fit:"force",label:r.force}].map(ce=>{const Se=document.createElement("button");return Se.type="button",Se.className="me-video-ratio-fit-button",Se.dataset.fit=ce.fit,Se.textContent=ce.label,x.appendChild(Se),{fit:ce.fit,button:Se}}),C=document.createElement("p");C.className="me-video-ratio-note",w.body.append(x,C),u.append(f,G.section,w.section,k.section);let y=null,O=null,Y=null,L=null,B=null,q=!1,V=!0,X=!1,re=!1;const pe="resize",se=ao("9:16"),N=ao("16:9"),b=typeof requestAnimationFrame=="function"?requestAnimationFrame:ce=>setTimeout(ce,16);function le(){Promise.resolve().then(()=>{re=!1;const ce=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,ce-1)})}function Le(ce){re=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return ce()}finally{le()}}function ve(){X||(X=!0,b(()=>{X=!1,Re()}))}function Ie(ce=O){return ce?[...ce.children].filter(Se=>Se instanceof HTMLButtonElement&&Se!==y&&!Se.classList.contains("me-video-text-tool")):[]}function D(ce){return[ce?.textContent,ce?.getAttribute?.("title"),ce?.getAttribute?.("aria-label")].filter(Boolean).join(" ").trim().toLowerCase()}function ee(ce){const Se=["trim","timeline","\u526A\u8F91","\u65F6\u95F4\u8F74"];return Ro(ce.find(Ve=>{const Ze=D(Ve);return Se.some(at=>Ze.includes(at))})??ce[0]??null)}function _(){if(L&&q){L.classList.remove("is-active");return}}function K(ce){const Se=[r.tool,r.title,"ratio","resize","\u6BD4\u4F8B","\u756B\u5E03","\u753B\u5E03"].map(Ve=>String(Ve??"").trim().toLowerCase()).filter(Boolean);return ce.find(Ve=>{const Ze=D(Ve);return Se.some(at=>Ze.includes(at))})??ce[ce.length-1]??null}function fe(){B&&(B.isConnected&&(B.style.display=B.dataset.meResizeDisplay??"",B.hidden=B.dataset.meResizeHidden==="true",delete B.dataset.meResizeDisplay,delete B.dataset.meResizeHidden),B=null)}function qe(ce){if(!ce){fe();return}B!==ce&&(fe(),ce.dataset.meResizeDisplay=ce.style.display??"",ce.dataset.meResizeHidden=ce.hidden?"true":"false",ce.hidden=!0,ce.style.display="none",B=ce)}function Oe(){L&&(L.classList.contains("is-active")||L.click())}function Je(){rn(e,u),Ht(e)}function Ge(ce){const Se=!!ce;if(Se===q){Re();return}q=Se,q&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:pe}})),Re()}function Ye(){const ce=e.querySelector(".me-video-toolrail");if(!ce)return;O=ce;const Se=Ie(O);L=ee(Se),Y=K(Se),qe(Y),(!y||!y.isConnected)&&(y=document.createElement("button"),y.type="button",y.className="me-video-text-tool me-video-ratio-tool",y.innerHTML=`<span class="me-video-text-tool-icon">\u2922</span><span class="me-video-text-tool-label">${r.tool}</span>`,y.title=r.tool,y.setAttribute("aria-label",r.tool),y.addEventListener("click",()=>{const Ve=!q;Ve&&(Oe(),ve()),Ge(Ve)})),y.isConnected?Y?.parentElement===O&&y.nextSibling!==Y&&O.insertBefore(y,Y):Y?.parentElement===O?O.insertBefore(y,Y):O.appendChild(y),y.classList.toggle("is-active",q),_(),Je()}function dt(){u.hidden=!q,y?.classList.toggle("is-active",q),_(),Je()}function rt(ce=t.getState()){return Fo(ce?.scale?.fit)}function ze(){he.textContent=V?"\u{1F512}":"\u{1F513}",he.title=V?r.lockRatio:r.unlockRatio,he.setAttribute("aria-label",he.title),he.classList.toggle("is-active",V)}function it(ce,Se,Ve=rt(),Ze=!1){const at={width:fn(ce,2),height:fn(Se,2),fit:Fo(Ve)};if(Ze){t.patch({scale:at},{transient:!0});return}t.commit({scale:at})}function xt(ce){const Se=Yn(t.getState()),Ve=fn(ce,Se.w);if(!V)return{width:Ve,height:fn(F.value,Se.h)};const Ze=Se.w>0&&Se.h>0?Se.w/Se.h:1;return{width:Ve,height:fn(Ve/Ze,Se.h)}}function wt(ce){const Se=Yn(t.getState()),Ve=fn(ce,Se.h);if(!V)return{width:fn(T.value,Se.w),height:Ve};const Ze=Se.w>0&&Se.h>0?Se.w/Se.h:1;return{width:fn(Ve*Ze,Se.w),height:Ve}}function we(ce){const Se=Ui(s,ce);H.replaceChildren();for(const Ve of s){const Ze=document.createElement("button");Ze.type="button",Ze.className="me-video-ratio-preset-group",Ze.title=`${Ve.ratio} (${On(Ve)})`,Se&&Se.ratio===Ve.ratio&&Ze.classList.add("is-active");const at=document.createElement("div");at.className="me-video-ratio-preset-head";const Et=document.createElement("div");Et.className="me-video-ratio-preset-title";const St=document.createElement("strong");St.className="me-video-ratio-preset-ratio",St.textContent=Ve.ratio;const Rt=document.createElement("span");Rt.className="me-video-ratio-preset-size",Rt.textContent=`(${On(Ve)})`,Et.append(St,Rt);const ut=document.createElement("span");ut.className="me-video-ratio-preset-marker",ut.setAttribute("aria-hidden","true"),at.append(Et,ut);const It=document.createElement("p");It.className="me-video-ratio-preset-hint",It.textContent=Ve.hint,Ze.addEventListener("click",()=>{it(Ve.w,Ve.h,rt())}),Ze.append(at,It),H.appendChild(Ze)}}function Re(){Le(()=>{Ye();const ce=t.getState(),Se=Ie().find(Et=>Et.classList.contains("is-active"))??null;q&&Se&&Se!==L&&(Oe(),ve());const Ve=Yn(ce),Ze=Cr(ce),at=rt(ce);T.value=String(Ve.w),F.value=String(Ve.h),ze(),te.innerHTML=`<strong>${r.summary}:</strong> ${On(Ve)}${ce.scale?` | ${r.baseOutput}: ${On(Ze)}`:""}`,C.textContent=Gi(r,at),E.forEach(Et=>{Et.button.classList.toggle("is-active",Et.fit===at)}),we(Ve),dt()})}function Me(ce){return!!ce&&(ce===u||u.contains(ce))}function et(ce){return ce.some(Se=>{if(!Me(Se.target))return!0;for(const Ve of Se.addedNodes)if(!Me(Ve))return!0;for(const Ve of Se.removedNodes)if(!Me(Ve))return!0;return!1})}const tt=new MutationObserver(ce=>{re||e.__meVideoEnhancerObserverLock||et(ce)&&(Le(()=>{Ye()}),ve())}),ht=ce=>{ce?.detail?.id!==pe&&(q&&(q=!1,dt()),ve())};tt.observe(e,{childList:!0,subtree:!0}),e.addEventListener("me-video-inspector-open",ht),window.addEventListener("resize",ve);const gt=t.subscribe(()=>{ve()});return T.addEventListener("input",()=>{const ce=xt(T.value);it(ce.width,ce.height,rt(),!0)}),T.addEventListener("change",()=>{const ce=xt(T.value);it(ce.width,ce.height,rt())}),F.addEventListener("input",()=>{const ce=wt(F.value);it(ce.width,ce.height,rt(),!0)}),F.addEventListener("change",()=>{const ce=wt(F.value);it(ce.width,ce.height,rt())}),he.addEventListener("click",()=>{V=!V,Re()}),ne.addEventListener("click",()=>{it(se.w,se.h,rt())}),xe.addEventListener("click",()=>{it(N.w,N.h,rt())}),E.forEach(ce=>{ce.button.addEventListener("click",()=>{const Se=Yn(t.getState());it(Se.w,Se.h,ce.fit)})}),Ye(),Re(),{destroy(){tt.disconnect(),gt(),e.removeEventListener("me-video-inspector-open",ht),window.removeEventListener("resize",ve),fe(),y?.remove(),u.remove(),Ht(e)}}}function da(e,t,n,r){Qt(),kn();const a=Zo(r()),s=a.transitions,u=document.createElement("div");u.className="me-video-text-panel me-video-transition-panel",u.hidden=!0,e.appendChild(u);const f=document.createElement("div");f.className="me-video-text-toolbar";const v=document.createElement("strong");v.textContent=s.title;const k=Yt(s.fadeAll),H=Yt(s.close);f.append(v,k,H);const G=document.createElement("p");G.className="me-video-text-hint",G.textContent=s.hint;const T=document.createElement("div");T.className="me-video-text-list";const F=document.createElement("div");F.className="me-video-text-empty",F.textContent=s.empty;const j=document.createElement("div");j.className="me-video-transition-selection";const oe=document.createElement("div");oe.className="me-video-transition-grid";const Q=vo.map(we=>{const Re=En(a,we.key),Me=document.createElement("button");return Me.type="button",Me.className="me-video-transition-choice",Me.dataset.transition=we.key,Me.innerHTML=`<strong>${Re.label}</strong><span>${we.key==="none"?s.instantCut:`${s.duration} ${mn(we.duration)}`}</span>`,oe.appendChild(Me),Me}),Z=document.createElement("input");Z.type="range",Z.min="0.1",Z.max="1.2",Z.step="0.05";const ie=document.createElement("div");ie.className="me-video-text-inline";const he=document.createElement("span");ie.append(Z,he);const ne=to(s.duration,ie);ne.classList.add("is-span-2");const xe=document.createElement("div");xe.className="me-video-transition-actions";const te=Yt(s.clearSelected),w=Li(s.clearAll,"clear");w.classList.add("me-video-text-cta"),xe.append(w,te),u.append(f,G,T,F,j,oe,ne,xe);let x=null,E=null,C=null,y=null,O=null,Y=!1,L=0,B=!1,q=!1;const V="transition",X=typeof requestAnimationFrame=="function"?requestAnimationFrame:we=>setTimeout(we,16),re=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>N());function pe(){Promise.resolve().then(()=>{q=!1;const we=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,we-1)})}function se(we){q=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return we()}finally{pe()}}function N(){B||(B=!0,X(()=>{B=!1,Ye()}))}function b(we){const Re=!!we;if(Re===Y){Ye();return}Y=Re,Y&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:V}})),Ye()}function le(){return E?[...E.querySelectorAll("button")].filter(we=>we!==x):[]}function Le(){le()[0]?.click()}function ve(){x&&(x.dataset.theme=Kn(n()))}function Ie(){rn(e,u),Ht(e)}function D(){u.hidden=!Y,x&&x.classList.toggle("is-active",Y),Ie()}function ee(we){const Re=Math.max(0,(we.clips??[]).length-1);if(!Re){L=0;return}L=ae(L,0,Re-1)}function _(we,Re=!1){if(Re){t.patch({transitions:we},{transient:!0});return}t.commit({transitions:we})}function K(we,Re=!1){const Me=t.getState(),et=bo(Me),tt=Me.clips??[];ee(Me),!(!et.length||!tt[L]||!tt[L+1])&&(et[L]=Gn({...et[L],...we},Dt(tt[L]),Dt(tt[L+1])),_(et,Re))}function fe(we){const Re=t.getState(),Me=bo(Re),et=Re.clips??[];if(ee(Re),!Me.length||!et[L]||!et[L+1])return;const tt=En(a,we);Me[L]=Gn({type:we,duration:we==="none"?0:Me[L]?.duration||tt.duration},Dt(et[L]),Dt(et[L+1])),_(Me)}function qe(we){const Me=t.getState().clips??[];if(Me.length<2)return;const et=En(a,we),tt=[];for(let ht=0;ht<Me.length-1;ht++)tt.push(Gn({type:we,duration:we==="none"?0:et.duration},Dt(Me[ht]),Dt(Me[ht+1])));_(tt)}function Oe(){const we=Fn(e);if(!we){y?.remove(),y=null,re&&O&&(re.unobserve(O),O=null),C=null;return}C=we,C.style.position="relative",(!y||!y.isConnected||y.parentElement!==C)&&(y?.remove(),y=document.createElement("div"),y.className="me-video-transition-track",C.appendChild(y)),re&&O!==C&&(O&&re.unobserve(O),O=C,re.observe(C))}function Je(we,Re){T.replaceChildren();const Me=Math.max(0,(we.clips??[]).length-1);for(let et=0;et<Me;et++){const tt=document.createElement("button");tt.type="button",tt.className="me-video-text-chip",et===L&&tt.classList.add("is-active");const ht=Re[et],gt=En(a,ht?.type??"none");tt.textContent=s.boundary(et+1,et+2,gt.short),tt.title=s.boundaryTitle(et+1,et+2),tt.addEventListener("click",()=>{L=et,Le(),b(!0)}),T.appendChild(tt)}}function Ge(we,Re){if(Oe(),!y||!C)return;y.replaceChildren();const Me=we.clips??[];if(Me.length<2)return;const et=Math.max(typeof t.contentDuration=="function"?t.contentDuration():0,.001),tt=C.clientWidth/et;let ht=0;for(let gt=0;gt<Me.length-1;gt++){ht+=Dt(Me[gt]);const ce=Re[gt],Se=En(a,ce?.type??"none"),Ve=ce?.type==="none",Ze=document.createElement("button");Ze.type="button",Ze.className="me-video-transition-marker",Ve&&Ze.classList.add("is-cut-only"),ce?.type!=="none"&&Ze.classList.add("is-enabled"),gt===L&&Ze.classList.add("is-active"),Ze.style.left=`${ht*tt}px`,Ze.title=s.markerTitle(gt+1,gt+2,Se.label,ce?.type!=="none"?mn(ce.duration):"");const at=document.createElement("span");at.className="me-video-transition-pill",at.textContent=Ve?"":Se.short,Ze.appendChild(at),Ze.addEventListener("click",()=>{L=gt,Le(),b(!0)}),y.appendChild(Ze)}}function Ye(){se(()=>{const we=t.getState(),Re=bo(we);ee(we),Je(we,Re),Ge(we,Re);const Me=Re[L]??null,et=En(a,Me?.type??"none");F.hidden=Re.length>0,j.textContent=Me?s.selection(L+1,L+2):s.selectionEmpty,Z.disabled=!Me||et.key==="none",te.disabled=!Me,w.disabled=Re.length===0,k.disabled=Re.length===0,Z.value=String(Me&&et.key!=="none"?Me.duration:xo("fade").duration),he.textContent=Me&&et.key!=="none"?mn(Me.duration):s.cut,Q.forEach(tt=>{const ht=!!Me&&tt.dataset.transition===et.key;tt.classList.toggle("is-active",ht),tt.disabled=!Me}),D(),Ie(),ve()})}function dt(){se(()=>{const we=e.querySelector(".me-video-toolrail");we&&(E=we,(!x||!x.isConnected)&&(x=document.createElement("button"),x.type="button",x.className="me-video-text-tool",x.innerHTML=`<span class="me-video-text-tool-icon">Fx</span><span class="me-video-text-tool-label">${s.tool}</span>`,x.addEventListener("click",()=>{const Re=!Y;Re&&Le(),b(Re)})),x.isConnected||E.appendChild(x),ve(),Ie())})}function rt(we){return!!we&&(we===u||u.contains(we)||we===x||we===y||y?.contains(we))}function ze(we){return we.some(Re=>{if(!rt(Re.target))return!0;for(const Me of Re.addedNodes)if(!rt(Me))return!0;for(const Me of Re.removedNodes)if(!rt(Me))return!0;return!1})}const it=new MutationObserver(we=>{q||e.__meVideoEnhancerObserverLock||ze(we)&&(dt(),N())}),xt=we=>{we?.detail?.id!==V&&Y&&(Y=!1,Ye())};it.observe(e,{childList:!0,subtree:!0}),e.addEventListener("me-video-inspector-open",xt),window.addEventListener("resize",N);const wt=t.subscribe(()=>{N()});return Q.forEach(we=>{we.addEventListener("click",()=>{fe(we.dataset.transition??"none")})}),Z.addEventListener("input",()=>{he.textContent=mn(Z.value),K({duration:Number(Z.value)||.4},!0)}),Z.addEventListener("change",()=>{K({duration:Number(Z.value)||.4})}),k.addEventListener("click",()=>qe("fade")),te.addEventListener("click",()=>fe("none")),w.addEventListener("click",()=>qe("none")),H.addEventListener("click",()=>{b(!1)}),dt(),Ye(),{destroy(){it.disconnect(),wt(),re?.disconnect(),e.removeEventListener("me-video-inspector-open",xt),window.removeEventListener("resize",N),x?.remove(),y?.remove(),u.remove(),Ht(e)}}}function ua(e,t,n){Qt();const r=Pi(n()),a=typeof requestAnimationFrame=="function"?requestAnimationFrame:o=>setTimeout(o,16),s=document.createElement("div");s.className="me-video-text-panel me-video-add-panel",s.hidden=!0,e.appendChild(s);const u=document.createElement("div");u.className="me-video-text-toolbar";const f=document.createElement("strong");f.textContent=r.title;const v=Yt(r.reset);u.append(f,v);const k=document.createElement("p");k.className="me-video-text-hint",k.textContent=r.hint;const H=document.createElement("div");H.className="me-video-add-body";const G=document.createElement("section");G.className="me-video-add-section";const T=document.createElement("div");T.className="me-video-add-section-head";const F=document.createElement("span");F.className="me-video-add-section-title",F.textContent=r.tools,T.appendChild(F);const j=document.createElement("div");j.className="me-video-add-tool-grid";const oe=document.createElement("section");oe.className="me-video-add-section";const Q=document.createElement("div");Q.className="me-video-add-section-head";const Z=document.createElement("span");Z.className="me-video-add-section-title",Z.textContent=r.color,Q.appendChild(Z);const ie=document.createElement("div");ie.className="me-video-add-color-grid";const he=document.createElement("div");he.className="me-video-add-custom-color";const ne=document.createElement("div");ne.className="me-video-add-custom-head";const xe=document.createElement("div");xe.className="me-video-add-custom-preview";const te=document.createElement("span");te.className="me-video-add-custom-label",te.textContent=r.custom,ne.append(xe,te);const w=document.createElement("div");w.className="me-video-add-spectrum";const x=document.createElement("span");x.className="me-video-add-spectrum-thumb",w.appendChild(x);const E=document.createElement("div");E.className="me-video-add-hue-row";const C=document.createElement("div");C.className="me-video-add-custom-preview";const y=document.createElement("input");y.type="range",y.min="0",y.max="360",y.step="1",y.className="me-video-add-hue-slider",E.append(C,y);const O=document.createElement("div");O.className="me-video-add-rgb-grid";const Y={};["r","g","b"].forEach(o=>{const i=document.createElement("label");i.className="me-video-add-rgb-field";const c=document.createElement("input");c.type="number",c.min="0",c.max="255",c.step="1",c.inputMode="numeric",c.className="me-video-add-rgb-input";const h=document.createElement("span");h.className="me-video-add-rgb-label",h.textContent=o.toUpperCase(),i.append(c,h),O.appendChild(i),Y[o]=c}),he.append(ne,w,E,O);const L=document.createElement("section");L.className="me-video-add-section";const B=document.createElement("div");B.className="me-video-add-section-head";const q=document.createElement("span");q.className="me-video-add-section-title",q.textContent=r.width;const V=document.createElement("span");V.className="me-video-add-section-value",B.append(q,V);const X=document.createElement("input");X.type="range",X.min=String(_n),X.max=String(jn),X.step="1",X.className="me-video-add-slider",G.append(T,j),oe.append(Q,ie,he),L.append(B,X),H.append(G,oe,L),s.append(u,k,H);let re=null,pe=null,se=null,N=null,b=null,le=null,Le=null,ve=null,Ie=null,D=!1,ee=!1,_=null,K=no(),fe=null,qe=null,Oe=null,Je=0,Ge=0;const Ye="add",dt=[{key:"tl",x:0,y:0},{key:"tm",x:.5,y:0},{key:"tr",x:1,y:0},{key:"ml",x:0,y:.5},{key:"mr",x:1,y:.5},{key:"bl",x:0,y:1},{key:"bm",x:.5,y:1},{key:"br",x:1,y:1}],rt={key:"rotate",x:.5,y:0},ze=typeof ResizeObserver=="function"?new ResizeObserver(()=>{Lt()}):null,it=typeof ResizeObserver=="function"?new ResizeObserver(()=>{Lt()}):null,xt=gr.map(o=>{const i=document.createElement("button");return i.type="button",i.className="me-video-add-tool-card",i.dataset.tool=o.key,i.innerHTML=`<span class="me-video-add-tool-icon">${Ii(o.key)}</span><span class="me-video-add-tool-label">${r[o.key]}</span>`,i.addEventListener("click",()=>{At({tool:o.key})}),j.appendChild(i),i}),wt=yr.map(o=>{const i=document.createElement("button");return i.type="button",i.className="me-video-add-color-chip",i.dataset.color=o,i.dataset.tone=o==="#ffffff"?"light":"dark",i.style.background=o,i.title=o,i.setAttribute("aria-label",o),i.addEventListener("click",()=>{At({color:o})}),ie.appendChild(i),i});function we(o,i,c){Oe?.();const h=o==="mouse"?["mousemove"]:["pointermove"],I=o==="mouse"?["mouseup"]:["pointerup","pointercancel"],A=M=>{i(M)},J=M=>{h.forEach(z=>window.removeEventListener(z,A)),I.forEach(z=>window.removeEventListener(z,J)),Oe=null,c(M)};Oe=()=>{h.forEach(M=>window.removeEventListener(M,A)),I.forEach(M=>window.removeEventListener(M,J))},h.forEach(M=>window.addEventListener(M,A)),I.forEach(M=>window.addEventListener(M,J))}function Re(o,i){const c=w.getBoundingClientRect();if(!(c.width>0&&c.height>0))return;const h=ae((o-c.left)/c.width,0,1),I=1-ae((i-c.top)/c.height,0,1),A=oo(K.color),J=zo(A.r,A.g,A.b),M=Po(J.h,h,I);At({color:ro(M.r,M.g,M.b)})}function Me(o){const i=typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now(),c=o.type==="mousedown"?"mouse":"pointer";if(c==="mouse"){if(i<Ge)return}else Ge=i+80;o.preventDefault(),o.stopPropagation(),Re(o.clientX,o.clientY),we(c,h=>{h.preventDefault(),Re(h.clientX,h.clientY)},()=>{})}function et(o){const i=oo(K.color),c=zo(i.r,i.g,i.b),h=Po(ae(Number(o)||0,0,360),c.s,c.v);At({color:ro(h.r,h.g,h.b)})}function tt(o,i){const c=oo(K.color),h={r:c.r,g:c.g,b:c.b};Number.isFinite(Number(i))&&(h[o]=ae(Number(i),0,255)),At({color:ro(h.r,h.g,h.b)})}function ht(){return(t.getState().overlays??[]).map((o,i)=>({overlay:o,index:i})).filter(o=>nn(o.overlay))}function gt(){const o=t.getState().overlays??[];if(_==null)return null;const i=o[_];return nn(i)?i:null}function ce(){const o=gt();if(!o)return!1;const i=no({tool:K.tool,color:o.color,width:o.width});return Oo(K,i)?!1:(K=i,!0)}function Se(o,i,c={}){if(!gt()||_==null)return;const I={};Object.prototype.hasOwnProperty.call(i,"color")&&(I.color=o.color),Object.prototype.hasOwnProperty.call(i,"width")&&(I.width=o.width),Object.keys(I).length&&t.updateOverlay(_,I,c)}function Ve(){return Tn(t)}function Ze(){return yn(e)}function at(o,i,c={}){const I=(t.getState().overlays??[])[o];nn(I)&&t.updateOverlay(o,Jt(I,Ve(),i),c)}function Et(o){const i=t.getState().overlays??[],c=i.length;if(typeof t.applyMut=="function")return t.applyMut(I=>({...I,overlays:[...on(I.overlays),{...o,timelineTrack:0}]})),c;const h=on(i);return t.commit?.({overlays:[...h,{...o,timelineTrack:0}]}),c}function St(o){const i=Ve();let c=ae(Ze(),0,Math.max(0,i-je)),h=Math.min(i,c+qt);h-c<je&&(c=ae(i-qt,0,Math.max(0,i-je)),h=Math.max(c+je,i));const I={...o,...Jt(null,i,{startAt:c,endAt:h,timelineTrack:0})},A=Et(I);_=Number.isInteger(A)?A:null,bt(e,"text",_==null?[]:[_]),S(),p(!0)}function Rt(){const{timelineInner:o,timelineHost:i}=Bn(e,t.getState());if(!o||!i){ve?.remove(),ve=null,ze&&Ie&&(ze.unobserve(Ie),Ie=null),Le=null;return}Le=o,(!ve||!ve.isConnected||ve.parentElement!==i)&&(ve?.remove(),ve=document.createElement("div"),ve.className="me-video-text-timeline me-video-overlay-timeline me-video-add-overlay-layer");for(const c of[...i.children])c!==ve&&c instanceof HTMLElement&&c.classList.contains("me-video-add-overlay-layer")&&c.remove();(ve.parentElement!==i||i.lastElementChild!==ve)&&i.appendChild(ve),ze&&Ie!==Le&&(Ie&&ze.unobserve(Ie),Ie=Le,ze.observe(Le))}function ut(o,i,c){if(!Le)return;const h=(t.getState().overlays??[])[o];if(!nn(h))return;if(c.shiftKey||c.ctrlKey||c.metaKey){c.preventDefault(),c.stopPropagation();const ge=Pt(e,"text",o,c,wo(t.getState()).map(Ae=>Ae.index));_=ge.length?ge[ge.length-1]:null,S(),p(!0);return}c.preventDefault(),c.stopPropagation(),_=o,bt(e,"text",[o]),S(),D||p(!0);const I=Ve(),A=Math.max(Le.clientWidth/I,.001),J=lt(h),M=Bt(h,J),z=Math.max(je,M-J),me=vt(h),ue=c.clientX,Ce=ge=>{const Ae=(ge.clientX-ue)/A,_e=t.getState().overlays??[];if(i==="move"){const st=Math.max(0,J+Ae),Nt=st+z,$t=pt(ve,_e,o,st,Nt,ge.clientY,me);at(o,{startAt:st,endAt:Nt,timelineTrack:$t},{transient:!0});return}if(i==="start"){const st=ae(J+Ae,0,M-je),Nt=pt(ve,_e,o,st,M,ge.clientY,me);at(o,{startAt:st,endAt:M,timelineTrack:Nt},{transient:!0});return}const Xe=Math.max(J+je,M+Ae),We=pt(ve,_e,o,J,Xe,ge.clientY,me);at(o,{startAt:J,endAt:Xe,timelineTrack:We},{transient:!0})},ke=ge=>{window.removeEventListener("pointermove",Ce),window.removeEventListener("pointerup",ke),window.removeEventListener("pointercancel",ke);const Ae=(ge.clientX-ue)/A,_e=t.getState().overlays??[];if(i==="move"){const st=Math.max(0,J+Ae),Nt=st+z,$t=pt(ve,_e,o,st,Nt,ge.clientY,me);at(o,{startAt:st,endAt:Nt,timelineTrack:$t});return}if(i==="start"){const st=ae(J+Ae,0,M-je),Nt=pt(ve,_e,o,st,M,ge.clientY,me);at(o,{startAt:st,endAt:M,timelineTrack:Nt});return}const Xe=Math.max(J+je,M+Ae),We=pt(ve,_e,o,J,Xe,ge.clientY,me);at(o,{startAt:J,endAt:Xe,timelineTrack:We})};window.addEventListener("pointermove",Ce),window.addEventListener("pointerup",ke),window.addEventListener("pointercancel",ke),Ct()}function It(o,i){if(Rt(),!ve||!Le||(ve.replaceChildren(),ve.hidden=o.length===0,!o.length))return;const c=Ve(),h=Le.clientWidth/c,I=Rn(t.getState()),A=new Map;for(const J of o){const M=vt(J.overlay),z=I.get(M)??M;let me=A.get(M);me||(me=document.createElement("div"),me.className="me-video-overlay-track-row",me.dataset.track=String(M),me.style.top=`${Ln(z)}px`,A.set(M,me),ve.appendChild(me));const ue=document.createElement("div");ue.className="me-video-text-track-clip me-video-add-track-clip",i.has(J.index)&&ue.classList.add("is-active");const Ce=lt(J.overlay),ke=Sn(J.overlay);ue.style.left=`${Ce*h}px`,ue.style.width=`${Math.max(36,ke*h)}px`;const ge=document.createElement("span");ge.className="me-video-text-track-icon",ge.textContent="+";const Ae=document.createElement("span");Ae.className="me-video-text-track-label",Ae.textContent=wr(J.overlay,r),Ae.title=Ae.textContent;const _e=document.createElement("span");_e.className="me-video-text-track-handle is-start";const Xe=document.createElement("span");Xe.className="me-video-text-track-handle is-end",ue.append(ge,Ae,_e,Xe),ue.addEventListener("pointerdown",We=>ut(J.index,"move",We)),_e.addEventListener("pointerdown",We=>ut(J.index,"start",We)),Xe.addEventListener("pointerdown",We=>ut(J.index,"end",We)),ue.addEventListener("click",We=>{if(We.preventDefault(),We.stopPropagation(),We.shiftKey||We.ctrlKey||We.metaKey){S(),Ct();return}const st=Pt(e,"text",J.index,We,o.map(Nt=>Nt.index));_=st.length?st[st.length-1]:null,S(),p(!0),Ct()}),me.appendChild(ue)}}function Lt(){ee||(ee=!0,a(()=>{ee=!1,Ct()}))}function jt(){xt.forEach(c=>{c.classList.toggle("is-active",c.dataset.tool===K.tool)}),wt.forEach(c=>{c.classList.toggle("is-active",c.dataset.color===K.color)});const o=oo(K.color),i=zo(o.r,o.g,o.b);he.classList.toggle("is-active",!yr.includes(K.color)),he.style.setProperty("--me-add-color-current",K.color),he.style.setProperty("--me-add-color-hue",Bi(i.h)),xe.style.background=K.color,C.style.background=K.color,x.style.left=`${i.s*100}%`,x.style.top=`${(1-i.v)*100}%`,y.value=String(Math.round(i.h)),Y.r.value=String(o.r),Y.g.value=String(o.g),Y.b.value=String(o.b),X.value=String(ae(Math.round(Number(K.width)||sn.width),_n,jn)),V.textContent=Fi(K.width),v.disabled=kr(K)}function At(o,i={}){const c=no({...K,...o});if(Oo(K,c)){i.applyToSelected&&Se(c,o,i.overlayOptions);return}K=c,i.applyToSelected!==!1&&Se(c,o,i.overlayOptions),jt(),Lt()}function Mt(){if(kr(K)){jt();return}K=no(),jt(),Lt()}function mt(o=pe){return o?[...o.children].filter(i=>i instanceof HTMLButtonElement&&i!==re&&!i.classList.contains("me-video-text-tool")):[]}function Ut(){re?.classList.toggle("is-active",D)}function S(){se&&(se.classList.contains("is-active")||se.click())}function R(){rn(e,s),Ht(e)}function U(){fe=null}function Te(){qe?.(),qe=null,U()}function Fe(){s.hidden=!D,Ut(),R()}function p(o){const i=!!o;if(i===D){Ct();return}D=i,D?(e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:Ye}})),S()):(Te(),Oe?.(),Oe=null),Ct()}function g(){const o=e.querySelector(".me-video-toolrail");o&&(pe=o,se=io(mt(o)),(!re||!re.isConnected)&&(re=document.createElement("button"),re.type="button",re.className="me-video-text-tool me-video-add-tool",re.innerHTML=`<span class="me-video-text-tool-icon">${Ri()}</span><span class="me-video-text-tool-label">${r.tool}</span>`,re.title=r.tool,re.setAttribute("aria-label",r.tool),re.addEventListener("click",()=>{const i=!D;i&&S(),p(i)})),re.isConnected?re.parentElement===pe&&re!==pe.lastElementChild&&pe.appendChild(re):pe.appendChild(re),Fe())}function $(){const o=e.querySelector(".me-video-canvas-stage");if(!o){b?.remove(),b=null,it&&le&&(it.unobserve(le),le=null),N=null;return}N=o,N.style.position="relative",!b||!b.isConnected||b.parentElement!==N?(b?.remove(),b=document.createElement("div"),b.className="me-video-add-canvas-layer",b.addEventListener("pointerdown",en),b.addEventListener("mousedown",en),b.addEventListener("click",i=>{i.preventDefault(),i.stopPropagation()}),N.appendChild(b)):N.lastElementChild!==b&&N.appendChild(b),it&&le!==N&&(le&&it.unobserve(le),le=N,it.observe(N)),b.hidden=!D,b.dataset.tool=K.tool}function de(){if(!N)return null;const o=t.getState().canvas??{},i=Math.max(1,Number(o.w)||0),c=Math.max(1,Number(o.h)||0);if(!i||!c)return null;const h=N.getBoundingClientRect(),I=N.querySelector("canvas, video, img")||[...N.children].find(me=>me!==b)||null;let A=0,J=0,M=N.clientWidth||i,z=N.clientHeight||c;if(I instanceof HTMLElement){const me=I.getBoundingClientRect();me.width>0&&me.height>0&&(A=me.left-h.left,J=me.top-h.top,M=me.width,z=me.height)}if(!(M>0&&z>0)){const me=N.clientWidth||i,ue=N.clientHeight||c,Ce=Math.min(me/i,ue/c)||1;M=i*Ce,z=c*Ce,A=Math.max(0,(me-M)/2),J=Math.max(0,(ue-z)/2)}return{stageLeft:h.left,stageTop:h.top,left:A,top:J,width:M,height:z,canvasWidth:i,canvasHeight:c,scaleX:M/i,scaleY:z/c}}function be(o,i,c){return{x:ae((o-c.stageLeft-c.left)/c.scaleX,0,c.canvasWidth),y:ae((i-c.stageTop-c.top)/c.scaleY,0,c.canvasHeight)}}function ye(o,i,c){return Number.isFinite(o?.clientX)&&Number.isFinite(o?.clientY)?be(o.clientX,o.clientY,i):c}function Be(o,i){return{x:Math.min(o.x,i.x),y:Math.min(o.y,i.y),w:Math.abs(i.x-o.x),h:Math.abs(i.y-o.y)}}function Ee(o,i){const c=lt(o),h=Bt(o,c);return i>=c-.001&&i<=h+.001}function $e(o,i,c){const h=Pt(e,"text",o,i,c);_=h.length?h[h.length-1]:null,p(!0),Ct()}function Ne(o,i,c,h,I){const A=Math.atan2(h-i,c-o),J=Math.max(12,I*3.5),M=c-J*Math.cos(A-Math.PI/7),z=h-J*Math.sin(A-Math.PI/7),me=c-J*Math.cos(A+Math.PI/7),ue=h-J*Math.sin(A+Math.PI/7);return`M ${M} ${z} L ${c} ${h} L ${me} ${ue}`}function De(o){if(!Array.isArray(o)||o.length<4)return"";let i=`M ${o[0]} ${o[1]}`;for(let c=2;c<o.length;c+=2)i+=` L ${o[c]} ${o[c+1]}`;return i}function Qe(o){const i=document.createElementNS("http://www.w3.org/2000/svg","svg");return i.classList.add("me-video-add-preview-svg"),i.setAttribute("viewBox",`0 0 ${o.canvasWidth} ${o.canvasHeight}`),i.setAttribute("width",String(o.width)),i.setAttribute("height",String(o.height)),i.style.left=`${o.left}px`,i.style.top=`${o.top}px`,i.style.width=`${o.width}px`,i.style.height=`${o.height}px`,i}function He(o,i,c){const h=document.createElementNS("http://www.w3.org/2000/svg",o);return h.classList.add("me-video-add-preview-shape"),h.setAttribute("stroke",i),h.setAttribute("stroke-width",String(c)),h}function Pe(o){if(!fe)return null;const i=Qe(o);if(fe.type==="pen"){const c=De(fe.points);if(!c)return i;const h=He("path",fe.color,fe.width);return h.setAttribute("d",c),i.appendChild(h),i}if(fe.type==="line"||fe.type==="arrow"){const c=He("line",fe.color,fe.width);if(c.setAttribute("x1",String(fe.x1)),c.setAttribute("y1",String(fe.y1)),c.setAttribute("x2",String(fe.x2)),c.setAttribute("y2",String(fe.y2)),i.appendChild(c),fe.type==="arrow"){const h=He("path",fe.color,fe.width);h.setAttribute("d",Ne(fe.x1,fe.y1,fe.x2,fe.y2,fe.width)),i.appendChild(h)}return i}if(fe.type==="rect"){const c=He("rect",fe.color,fe.width);return c.setAttribute("x",String(fe.x)),c.setAttribute("y",String(fe.y)),c.setAttribute("width",String(fe.w)),c.setAttribute("height",String(fe.h)),i.appendChild(c),i}if(fe.type==="ellipse"){const c=He("ellipse",fe.color,fe.width);return c.setAttribute("cx",String(fe.x+fe.w/2)),c.setAttribute("cy",String(fe.y+fe.h/2)),c.setAttribute("rx",String(Math.abs(fe.w/2))),c.setAttribute("ry",String(Math.abs(fe.h/2))),i.appendChild(c),i}return i}function Ue(){if($(),!b)return;const o=de();if(b.hidden=!D||!o,!D||!o){b.replaceChildren();return}b.dataset.tool=K.tool,b.replaceChildren();const i=Pe(o);i&&b.appendChild(i);const c=wo(t.getState()),h=new Set(pr(e,t.getState())),I=Ze(),A=c.map(z=>z.index),J=c.filter(z=>Ee(z.overlay,I)),M=K.tool==="eraser"?[]:h.size?J.filter(z=>h.has(z.index)):J;for(const z of M){const me=Gt(z.overlay);if(!me)continue;const ue=document.createElement("button");ue.type="button",ue.className="me-video-text-canvas-hit";const Ce=h.has(z.index),ke=Ce&&_===z.index;Ce&&ue.classList.add("is-active"),ue.title=wr(z.overlay,r),ue.style.left=`${o.left+me.x*o.scaleX}px`,ue.style.top=`${o.top+me.y*o.scaleY}px`,ue.style.width=`${Math.max(18,me.w*o.scaleX)}px`,ue.style.height=`${Math.max(18,me.h*o.scaleY)}px`;const ge=un(z.overlay);if(ge&&(ue.style.transform=`rotate(${ge}deg)`,ue.style.transformOrigin="center center"),ue.addEventListener("pointerdown",Ae=>{if(Ae.preventDefault(),Ae.stopPropagation(),Ae.shiftKey||Ae.ctrlKey||Ae.metaKey){$e(z.index,Ae,A);return}_=z.index,bt(e,"text",[z.index]),p(!0),ct(z.index,Ae,o)}),ke){for(const _e of dt){const Xe=document.createElement("span");Xe.className="me-video-text-canvas-handle",Xe.dataset.handle=_e.key,Xe.style.left=`${_e.x*100}%`,Xe.style.top=`${_e.y*100}%`,Xe.addEventListener("pointerdown",We=>{We.preventDefault(),We.stopPropagation(),_=z.index,bt(e,"text",[z.index]),p(!0),ft(z.index,_e,We,o)}),ue.appendChild(Xe)}const Ae=document.createElement("span");Ae.className="me-video-text-canvas-handle",Ae.dataset.handle=rt.key,Ae.style.left=`${rt.x*100}%`,Ae.style.top=`${rt.y*100}%`,Ae.addEventListener("pointerdown",_e=>{_e.preventDefault(),_e.stopPropagation(),_=z.index,bt(e,"text",[z.index]),p(!0),Ke(z.index,_e,o)}),ue.appendChild(Ae)}b.appendChild(ue)}}function ct(o,i,c){const h=(t.getState().overlays??[])[o];if(!nn(h))return;const I=t.getState().canvas??{w:1080,h:1920},A=Gt(h);if(!A)return;const J=i.clientX,M=i.clientY,z=Math.max(0,(Number(I.w)||0)-A.w),me=Math.max(0,(Number(I.h)||0)-A.h),ue=(ge,Ae,_e)=>{const Xe=(ge-J)/c.scaleX,We=(Ae-M)/c.scaleY,st=ae(A.x+Xe,0,z),Nt=ae(A.y+We,0,me),$t=Vo(h,st-A.x,Nt-A.y);t.updateOverlay(o,$t,_e?{transient:!0}:void 0)},Ce=ge=>{ge.preventDefault(),ue(ge.clientX,ge.clientY,!0)},ke=ge=>{window.removeEventListener("pointermove",Ce),window.removeEventListener("pointerup",ke),window.removeEventListener("pointercancel",ke),ue(ge.clientX,ge.clientY,!1)};window.addEventListener("pointermove",Ce),window.addEventListener("pointerup",ke),window.addEventListener("pointercancel",ke)}function ft(o,i,c,h){const I=(t.getState().overlays??[])[o];if(!nn(I))return;const A=Gt(I);if(!A)return;const J=t.getState().canvas??{w:1080,h:1920},M=i.x===.5?.5:1-i.x,z=i.y===.5?.5:1-i.y,me=A.x+A.w*M,ue=A.y+A.h*z,Ce=Math.max(.1,24/Math.max(24,A.w),24/Math.max(24,A.h)),ke=i.x===.5?1/0:Math.max(.1,(M===0?(Number(J.w)||0)-me:me)/Math.max(1,A.w)),ge=i.y===.5?1/0:Math.max(.1,(z===0?(Number(J.h)||0)-ue:ue)/Math.max(1,A.h)),Ae=Math.max(Ce,Math.min(ke,ge,8)),_e=(st,Nt,$t)=>{const cn=be(st,Nt,h),dn=[];i.x!==.5&&dn.push(Math.abs(cn.x-me)/Math.max(1,A.w)),i.y!==.5&&dn.push(Math.abs(cn.y-ue)/Math.max(1,A.h));const Hn=dn.length?Math.max(...dn):1,hn=ae(Hn,Ce,Ae),Xn=Yo(I,hn),xn=Gt(Xn);if(!xn)return;const Br=me-xn.w*M,$r=ue-xn.h*z,Dr=Vo(Xn,Br-xn.x,$r-xn.y);t.updateOverlay(o,Dr,$t?{transient:!0}:void 0)},Xe=st=>{st.preventDefault(),_e(st.clientX,st.clientY,!0)},We=st=>{window.removeEventListener("pointermove",Xe),window.removeEventListener("pointerup",We),window.removeEventListener("pointercancel",We),_e(st.clientX,st.clientY,!1)};window.addEventListener("pointermove",Xe),window.addEventListener("pointerup",We),window.addEventListener("pointercancel",We)}function Ke(o,i,c){const h=(t.getState().overlays??[])[o];if(!nn(h))return;const I=Gt(h);if(!I)return;const A=c.stageLeft+c.left+(I.x+I.w/2)*c.scaleX,J=c.stageTop+c.top+(I.y+I.h/2)*c.scaleY,M=Math.atan2(i.clientY-J,i.clientX-A),z=un(h),me=(ke,ge,Ae,_e)=>{const Xe=Math.atan2(ge-J,ke-A);let We=In(z+(Xe-M)*180/Math.PI);_e&&(We=Math.round(We/15)*15),t.updateOverlay(o,{rotation:We},Ae?{transient:!0}:void 0)},ue=ke=>{ke.preventDefault(),me(ke.clientX,ke.clientY,!0,ke.shiftKey)},Ce=ke=>{window.removeEventListener("pointermove",ue),window.removeEventListener("pointerup",Ce),window.removeEventListener("pointercancel",Ce),me(ke.clientX,ke.clientY,!1,ke.shiftKey)};window.addEventListener("pointermove",ue),window.addEventListener("pointerup",Ce),window.addEventListener("pointercancel",Ce)}function nt(o,i,c,h,I,A,J){const M=I-c,z=A-h,me=M*M+z*z||1,ue=ae(((o-c)*M+(i-h)*z)/me,0,1),Ce=c+ue*M,ke=h+ue*z;return(o-Ce)**2+(i-ke)**2<=J*J}function ot(o,i,c){if(!o)return!1;if(o.type==="pen"){for(let h=0;h+3<o.points.length;h+=2)if(nt(i,c,o.points[h],o.points[h+1],o.points[h+2],o.points[h+3],Nn+(Number(o.width)||0)/2))return!0;return!1}return o.type==="line"||o.type==="arrow"?nt(i,c,o.x1,o.y1,o.x2,o.y2,Nn+(Number(o.width)||0)/2):o.type==="rect"||o.type==="ellipse"?i>=o.x-Nn&&i<=o.x+o.w+Nn&&c>=o.y-Nn&&c<=o.y+o.h+Nn:!1}function Ot(o){const i=ht();for(let c=i.length-1;c>=0;c--)if(ot(i[c].overlay,o.x,o.y)){t.removeOverlay(i[c].index),Lt();return}}function Ft(o,i,c){Ot(o),kt(c,h=>{h.preventDefault(),Ot(be(h.clientX,h.clientY,i))},()=>{})}function kt(o,i,c){Te();const h=o==="mouse"?["mousemove"]:["pointermove"],I=o==="mouse"?["mouseup"]:["pointerup","pointercancel"],A=M=>{i(M)},J=M=>{h.forEach(z=>window.removeEventListener(z,A)),I.forEach(z=>window.removeEventListener(z,J)),qe=null,c(M)};qe=()=>{h.forEach(M=>window.removeEventListener(M,A)),I.forEach(M=>window.removeEventListener(M,J))},h.forEach(M=>window.addEventListener(M,A)),I.forEach(M=>window.addEventListener(M,J))}function ln(o,i,c){const h=[o.x,o.y],I=A=>{const J=h[h.length-2],M=h[h.length-1];Math.hypot(A.x-J,A.y-M)<1||h.push(A.x,A.y)};fe={type:"pen",points:[...h],color:K.color,width:K.width},Ue(),kt(c,A=>{A.preventDefault();const J=be(A.clientX,A.clientY,i);I(J),fe={type:"pen",points:[...h],color:K.color,width:K.width},Ue()},A=>{const J=ye(A,i,{x:h[h.length-2],y:h[h.length-1]});I(J);const M=[...h];U(),Ue(),!(M.length<4)&&(St({type:"pen",points:M,color:K.color,width:K.width,rotation:0}),Lt())})}function an(o,i,c,h){const I=Hi[o];if(!I)return;const A=J=>{if(I==="line"||I==="arrow")return{type:I,x1:i.x,y1:i.y,x2:J.x,y2:J.y,color:K.color,width:K.width};const M=Be(i,J);return{type:I,x:M.x,y:M.y,w:M.w,h:M.h,color:K.color,width:K.width}};fe=A(i),Ue(),kt(h,J=>{J.preventDefault();const M=be(J.clientX,J.clientY,c);fe=A(M),Ue()},J=>{const M=ye(J,c,i),z=A(M);U(),Ue(),z&&((z.type==="line"||z.type==="arrow")&&Math.hypot(z.x2-z.x1,z.y2-z.y1)<2||(z.type==="rect"||z.type==="ellipse")&&(z.w<2||z.h<2)||St({...z,rotation:0}))})}function en(o){if(!D)return;const i=typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now(),c=o.type==="mousedown"?"mouse":"pointer";if(c==="mouse"){if(i<Je)return}else Je=i+80;if(typeof o.button=="number"&&o.button!==0)return;o.preventDefault(),o.stopPropagation();const h=de();if(!h)return;const I=be(o.clientX,o.clientY,h);if(K.tool==="eraser"){Ft(I,h,c);return}if(K.tool==="brush"){ln(I,h,c);return}an(K.tool,I,h,c)}function Ct(){const o=pr(e,t.getState());_=o.length?o[o.length-1]:null,ce(),mt().find(c=>c!==se&&!c.hidden&&c.style.display!=="none"&&c.classList.contains("is-active"))&&(D=!1,Te()),D&&S(),jt(),Fe(),Ue(),It(wo(t.getState()),new Set(o)),R()}function tn(o){return!!o&&(o===s||s.contains(o)||o===re||re?.contains?.(o)||o===ve||ve?.contains?.(o)||o===b||b?.contains?.(o))}function m(o){return o.some(i=>{if(!tn(i.target))return!0;for(const c of i.addedNodes)if(!tn(c))return!0;for(const c of i.removedNodes)if(!tn(c))return!0;return!1})}const P=new MutationObserver(o=>{m(o)&&(g(),Lt())}),W=o=>{o?.detail?.id!==Ye&&D&&p(!1)},l=()=>{Lt()};P.observe(e,{childList:!0,subtree:!0}),e.addEventListener("me-video-inspector-open",W),e.addEventListener(zt,l),window.addEventListener("resize",Lt);const d=t.subscribe(()=>{Lt()});return v.addEventListener("click",()=>{Mt()}),w.addEventListener("pointerdown",Me),w.addEventListener("mousedown",Me),y.addEventListener("input",()=>{et(y.value)}),Object.entries(Y).forEach(([o,i])=>{i.addEventListener("input",()=>{tt(o,i.value)})}),X.addEventListener("input",()=>{At({width:ae(Number(X.value)||sn.width,_n,jn)})}),g(),Ct(),{destroy(){P.disconnect(),d(),Te(),Oe?.(),Oe=null,ze&&Ie&&ze.unobserve(Ie),ze?.disconnect?.(),it&&le&&it.unobserve(le),it?.disconnect?.(),e.removeEventListener("me-video-inspector-open",W),e.removeEventListener(zt,l),window.removeEventListener("resize",Lt),re?.remove(),ve?.remove(),b?.remove(),s.remove(),Ht(e)}}}function ma(e,t,n){Qt();const r=Ur(n()),a=document.createElement("div");a.className="me-video-text-panel me-video-audio-panel",a.hidden=!0;const s=document.createElement("div");s.className="me-video-text-toolbar";const u=document.createElement("strong");u.textContent=r.title;const f=Yt(r.close);s.append(u,f);const v=document.createElement("div");v.className="me-video-audio-source";const k=document.createElement("div");k.className="me-video-text-grid";function H(_=""){const K=document.createElement("input");return K.type="text",K.readOnly=!0,K.className=["me-video-audio-value",_].filter(Boolean).join(" "),K}function G(_,K,fe){const qe=document.createElement("div");return qe.className="me-video-text-inline",qe.append(K,fe),to(_,qe)}const T=document.createElement("input");T.type="range",T.min="50",T.max="200",T.step="1",T.disabled=!1,T.value="100",T.title=r.speedHint;const F=H("is-compact is-readonly");F.readOnly=!1,F.classList.remove("is-readonly"),F.inputMode="decimal",F.title=r.speedHint;const j=G(r.speed,T,F),oe=document.createElement("input");oe.type="range",oe.min=String(Wt),oe.max="1",oe.step="0.01",oe.disabled=!1,oe.value="1";const Q=H("is-readonly");Q.readOnly=!1,Q.classList.remove("is-readonly"),Q.inputMode="decimal";const Z=G(r.duration,oe,Q),ie=document.createElement("input");ie.type="range",ie.min="0",ie.max="2",ie.step="0.01";const he=H(),ne=G(r.volume,ie,he),xe=document.createElement("input");xe.type="range",xe.min="0",xe.max="0.1",xe.step="0.05";const te=H(),w=G(r.fadeIn,xe,te),x=document.createElement("input");x.type="range",x.min="0",x.max="0.1",x.step="0.05";const E=H(),C=G(r.fadeOut,x,E);k.append(j,Z,ne,w,C),a.append(s,v,k);let y=null,O=!1,Y=!1;const L="audio",B=typeof requestAnimationFrame=="function"?requestAnimationFrame:_=>setTimeout(_,16);function q(_){const K=Math.max(0,Number(_)||0);return K<=1e-4?"-\u221EdB":`${(20*Math.log10(K)).toFixed(1)}dB`}function V(){const _=e.querySelector(".me-video-trim-panel");if(_ instanceof HTMLElement)for(const K of[..._.children].slice(2))K instanceof HTMLElement&&K.querySelector('input[type="range"]')&&/♪/.test(K.textContent??"")&&(K.style.display="none")}function X(){a.hidden=!O,rn(e,a),Ar(e,a,O),Ht(e)}function re(_){const K=!!_;if(K===O){X();return}O=K,O&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:L}})),X()}function pe(){pn(e,{audio:[]},{audio:null})}function se(_,K,fe,qe){let Oe=ae(Number(K)||0,0,_),Je=ae(Number(fe)||0,0,_);return Oe+Je<=_?{fadeIn:Oe,fadeOut:Je}:(qe==="fadeOut"?Oe=Math.max(0,_-Je):Je=Math.max(0,_-Oe),{fadeIn:Oe,fadeOut:Je})}function N(_){const K=t.getAudioSource?.(_?.srcIdx);return Math.max(Dt(_),Number(K?.duration)||0)}function b(_,K=!1,fe="fadeIn"){const qe=t.getState(),Oe=qe.audioClips??[];if(y==null||!Oe[y])return;const Je=Oe[y],Ge=Dt({...Je,..._}),Ye=se(Ge,_.fadeIn??Je.fadeIn,_.fadeOut??Je.fadeOut,fe),dt=ze=>({...ze,..._,speed:bn(_.speed??ze.speed),volume:ae(Number(_.volume??ze.volume)||0,0,2),fadeIn:Ye.fadeIn,fadeOut:Ye.fadeOut}),rt=typeof t.patchAudio=="function"?t.patchAudio(qe,y,dt).audioClips??Oe:Oe.map((ze,it)=>it===y?dt(ze):ze);if(K){t.patch({audioClips:rt},{transient:!0});return}t.commit({audioClips:rt})}function le(_,K=!1){const qe=t.getState().audioClips??[];if(y==null||!qe[y])return;const Oe=qe[y],Je=N(Oe),Ge=Math.max(0,Number(Oe.in)||0),Ye=Math.max(Wt,Je-Ge),dt=ae(Number(_)||0,Wt,Ye);b({out:Ge+dt},K,"fadeIn")}function Le(){if(V(),!(e.querySelector(".me-video-trim-panel")instanceof HTMLElement)){O&&re(!1),y=null;return}const K=t.getState(),fe=K.audioClips??[],qe=Mn(e,fe),Oe=$n(e,K.clips??[]),Je=Dn(e,K),Ge=qe.length===1&&Oe.length===0&&Je.length===0?qe[0]:null;if(y=Number.isInteger(Ge)&&fe[Ge]?Ge:null,y==null){O&&re(!1);return}const Ye=fe[y],dt=t.getAudioSource?.(Ye.srcIdx),rt=dt?.file?.name||dt?.name||`${r.source} ${y+1}`,ze=Dt(Ye),it=Math.max(ze,Number(dt?.duration)||0),xt=Math.max(ze,Math.max(Wt,it-Math.max(0,Number(Ye.in)||0))),wt=bn(Ye.speed),we=ae(Number(Ye.fadeIn)||0,0,ze),Re=ae(Number(Ye.fadeOut)||0,0,Math.max(0,ze-we));v.textContent=`${r.source}: ${rt}`,T.value=String(Math.round(wt*100)),F.value=Qr(wt),oe.max=String(xt),oe.value=String(ae(ze,Wt,xt)),Q.value=mn(ze),ie.value=String(ae(Number(Ye.volume)||0,0,2)),he.value=q(Ye.volume),xe.max=String(Math.max(.1,ze)),x.max=String(Math.max(.1,ze)),xe.value=String(we),x.value=String(Re),te.value=mn(we),E.value=mn(Re),xe.disabled=ze<=1e-4,x.disabled=ze<=1e-4,re(!0)}function ve(){Y||(Y=!0,B(()=>{Y=!1,Le()}))}const Ie=_=>{if(_?.detail?.id!==L){if(_t(e,"audio").length>0){pe();return}O&&re(!1)}},D=new MutationObserver(()=>{ve()});D.observe(e,{childList:!0,subtree:!0}),e.addEventListener("me-video-inspector-open",Ie),e.addEventListener(zt,ve);const ee=t.subscribe(()=>{ve()});return f.addEventListener("click",()=>{pe()}),T.addEventListener("input",()=>{b({speed:bn((Number(T.value)||100)/100)},!0,"fadeIn")}),T.addEventListener("change",()=>{b({speed:bn((Number(T.value)||100)/100)},!1,"fadeIn")}),F.addEventListener("change",()=>{const _=y==null?null:(t.getState().audioClips??[])[y]??null;b({speed:ei(F.value,_?.speed??1)},!1,"fadeIn")}),F.addEventListener("keydown",_=>{_.key==="Enter"&&(_.preventDefault(),F.blur())}),oe.addEventListener("input",()=>{le(Number(oe.value)||0,!0)}),oe.addEventListener("change",()=>{le(Number(oe.value)||0,!1)}),Q.addEventListener("change",()=>{const _=y==null?null:(t.getState().audioClips??[])[y]??null;le(ti(Q.value,Dt(_)),!1)}),Q.addEventListener("keydown",_=>{_.key==="Enter"&&(_.preventDefault(),Q.blur())}),ie.addEventListener("input",()=>{b({volume:Number(ie.value)||0},!0,"fadeIn")}),ie.addEventListener("change",()=>{b({volume:Number(ie.value)||0},!1,"fadeIn")}),xe.addEventListener("input",()=>{b({fadeIn:Number(xe.value)||0},!0,"fadeIn")}),xe.addEventListener("change",()=>{b({fadeIn:Number(xe.value)||0},!1,"fadeIn")}),x.addEventListener("input",()=>{b({fadeOut:Number(x.value)||0},!0,"fadeOut")}),x.addEventListener("change",()=>{b({fadeOut:Number(x.value)||0},!1,"fadeOut")}),Le(),{destroy(){D.disconnect(),ee(),e.removeEventListener("me-video-inspector-open",Ie),e.removeEventListener(zt,ve),Ar(e,a,!1),a.remove(),Ht(e)}}}function pa(e,t,n=()=>null){Qt();let r=!1,a=null,s=null,u=null,f=null;const v=typeof requestAnimationFrame=="function"?requestAnimationFrame:x=>setTimeout(x,16);function k(){r||(r=!0,v(()=>{r=!1,te()}))}function H(){return Xt(typeof n=="function"?n():null)==="en"?"Cover":"\u5C01\u9762"}function G(x){return[x.textContent,x.title,x.getAttribute("aria-label"),x.getAttribute("data-tool"),x.getAttribute("data-testid")].filter(Boolean).join(" ").replace(/\s+/g," ").trim()}function T(x){if(!(x instanceof HTMLElement)||x===a||x.classList.contains("me-video-cover-set-btn")||x.classList.contains("me-video-cover-upload-btn")||x.closest(".me-video-timeline-area"))return!1;for(let C=x.parentElement,y=0;C&&y<8;y+=1,C=C.parentElement){const O=String(C.textContent||"");if(O.includes("\u9009\u62E9\u5C01\u9762\u5E27")||/select\s+cover\s+frame/i.test(O))return!1}const E=G(x);return E?!!(E.includes("\u5C01\u9762")||/\b(cover|poster|thumbnail)\b/i.test(E)):!1}function F(){const x=e.querySelector(".me-video-toolrail"),C=(x?[...x.querySelectorAll('button,[role="button"]')]:[]).find(T);return C instanceof HTMLElement?C:[...e.querySelectorAll('button,[role="button"]')].find(T)}function j(){const x=e.querySelector(".me-video-timeline-scroll");return x instanceof HTMLElement?x:null}function oe(x){return[...x.children].find(E=>E instanceof HTMLElement&&E!==f&&E.dataset.meTimelineCoverSlot!=="true")}function Q(x){const C=x?.querySelector("[data-clipblock]")?.parentElement;return C instanceof HTMLElement?C:null}function Z(x,E){return f instanceof HTMLElement||(f=document.createElement("div"),f.className="me-video-timeline-cover-slot",f.dataset.meTimelineCoverSlot="true"),x.style.display="flex",x.style.alignItems="flex-start",E instanceof HTMLElement&&(E.style.flex="0 0 auto"),(f.parentElement!==x||x.firstElementChild!==f)&&x.insertBefore(f,E??x.firstChild),f}function ie(){return a instanceof HTMLButtonElement||(a=document.createElement("button"),a.type="button",a.className="me-video-timeline-cover-proxy",a.innerHTML='<img alt="" draggable="false"><svg class="me-video-timeline-cover-proxy-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 20h16"/><path d="M6 18l9.5-9.5a2.1 2.1 0 0 1 3 3L9 21H5v-4z"/><path d="M14 6l4 4"/></svg><span class="me-video-timeline-cover-proxy-label"></span>',a.addEventListener("click",x=>{x.preventDefault(),x.stopPropagation(),u?.click()})),a}function he(){typeof t?.commit=="function"&&t.commit({poster:void 0}),k()}function ne(){return s instanceof HTMLButtonElement||(s=document.createElement("button"),s.type="button",s.className="me-video-timeline-cover-clear",s.innerHTML='<svg viewBox="0 0 12 12" aria-hidden="true"><path d="M3 3l6 6M9 3L3 9"/></svg>',s.addEventListener("click",x=>{x.preventDefault(),x.stopPropagation(),he()})),s}function xe(x,E,C){const y=H(),O=ie(),Y=ne(),L=O.querySelector(".me-video-timeline-cover-proxy-label");L&&(L.textContent=y);const B=O.querySelector("img"),q=typeof t?.getState=="function"?t.getState():{},V=q?.poster?.useAsVideoCover&&typeof q.poster.preview=="string"?q.poster.preview:"";B instanceof HTMLImageElement&&(V?B.src=V:B.removeAttribute("src")),O.classList.toggle("has-cover-image",!!V),O.title=x.title||x.getAttribute("aria-label")||y,O.setAttribute("aria-label",O.title),O.classList.toggle("is-active",x.classList.contains("is-active")||x.getAttribute("aria-pressed")==="true"),O.parentElement!==E&&E.insertBefore(O,E.firstChild),Y.hidden=!V,Y.title=Xt(typeof n=="function"?n():null)==="en"?"Remove cover":"\u53D6\u6D88\u5C01\u9762",Y.setAttribute("aria-label",Y.title),Y.parentElement!==E&&E.appendChild(Y),E.style.overflow="visible"}function te(){const x=F(),E=j(),C=E instanceof HTMLElement?oe(E):null,y=C instanceof HTMLElement?Q(C):null;if(!(x instanceof HTMLElement)||!(E instanceof HTMLElement)||!(C instanceof HTMLElement)||!(y instanceof HTMLElement)){u&&(u.removeAttribute("data-me-cover-hidden"),u=null),a?.remove(),s?.remove(),f?.remove(),f=null;return}u&&u!==x&&u.removeAttribute("data-me-cover-hidden"),u=x,u.setAttribute("data-me-cover-hidden","true");const O=Z(E,C);xe(x,O,y)}const w=new MutationObserver(()=>{k()});return w.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","style","title","aria-label","aria-pressed"]}),k(),{destroy(){w.disconnect(),u?.removeAttribute("data-me-cover-hidden"),a?.remove(),s?.remove(),f?.remove()}}}function fa(e,t,n=()=>null){Qt();let r=!1,a=null,s=null,u=null;const f=typeof requestAnimationFrame=="function"?requestAnimationFrame:L=>setTimeout(L,16);function v(){r||(r=!0,f(()=>{r=!1,y()}))}function k(){return Xt(typeof n=="function"?n():null)==="en"}function H(){const B=[...e.querySelectorAll("button")].filter(q=>{const V=String(q.textContent||q.title||"").trim();return V.includes("\u5BFC\u51FA\u5C01\u9762")||/export\s+cover/i.test(V)});for(const q of B){if(!(q instanceof HTMLButtonElement))continue;let V=q.parentElement;for(let X=0;V&&X<8;X+=1,V=V.parentElement){const re=String(V.textContent||"");if(re.includes("\u9009\u62E9\u5C01\u9762\u5E27")||/select\s+cover\s+frame/i.test(re))return{root:V,exportButton:q}}}return null}function G(L){const q=String(L.textContent||"").match(/(\d{1,2}:\d{2}(?:\.\d+)?)\s*\//);if(q){const X=Jn(q[1]);if(Number.isFinite(X))return X}const V=L.querySelector('input[type="range"]');if(V instanceof HTMLInputElement){const X=Number(V.value);if(Number.isFinite(X))return Math.max(0,X)}return 0}function T(L){return new Promise((B,q)=>{const V=new Image;V.onload=()=>B(V),V.onerror=q,V.src=L})}function F(L,B){const q=Math.max(1,Math.round(Number(L)||0)),V=Math.max(1,Math.round(Number(B)||0));if(!q||!V)return null;const re=Math.min(1,1920/Math.max(q,V));return{width:Math.max(1,Math.round(q*re)),height:Math.max(1,Math.round(V*re))}}function j(L,B=null){const q=L instanceof HTMLImageElement?L.naturalWidth:L.videoWidth,V=L instanceof HTMLImageElement?L.naturalHeight:L.videoHeight;if(!q||!V)return"";const X=B?F(B.width,B.height):null,re=X?.width??q,pe=X?.height??V,se=document.createElement("canvas");se.width=re,se.height=pe;const N=se.getContext("2d");if(!N)return"";if(X){const b=Math.max(re/q,pe/V),le=re/b,Le=pe/b,ve=Math.max(0,(q-le)/2),Ie=Math.max(0,(V-Le)/2);N.drawImage(L,ve,Ie,Math.min(q,le),Math.min(V,Le),0,0,re,pe)}else N.drawImage(L,0,0,q,V);return se.toDataURL("image/png")}async function oe(L){const B=String(L||"").trim();if(!B)return"";if(/^data:image\/(?:png|jpe?g);base64,/i.test(B))return B;try{const V=await(await fetch(B)).blob(),X=URL.createObjectURL(V);try{const re=await T(X);return j(re)}finally{URL.revokeObjectURL(X)}}catch{try{const q=await T(B);return j(q)}catch{return""}}}async function Q(L){const B=L.getBoundingClientRect(),q=B.top+B.height*.68;function V(b){const le=b.getBoundingClientRect();return le.width<80||le.height<120||le.top>q?null:le}const X=[...L.querySelectorAll("*")].map(b=>{if(!(b instanceof HTMLElement))return null;const le=V(b);if(!le)return null;const ve=getComputedStyle(b).backgroundImage.match(/url\(["']?(.+?)["']?\)/);return ve?{node:b,rect:le,src:ve[1]}:null}).filter(Boolean).sort((b,le)=>le.rect.width*le.rect.height-b.rect.width*b.rect.height)[0];if(X?.src){const b=await oe(X.src);if(b)return b}const re=[...L.querySelectorAll("canvas")].map(b=>{const le=V(b);return le?{node:b,rect:le}:null}).filter(Boolean).sort((b,le)=>le.rect.width*le.rect.height-b.rect.width*b.rect.height)[0]?.node;if(re instanceof HTMLCanvasElement)try{return re.toDataURL("image/png")}catch{return""}const se=[...L.querySelectorAll("video")].map(b=>{const le=V(b);return b instanceof HTMLVideoElement&&le?{node:b,rect:le}:null}).filter(Boolean).sort((b,le)=>le.rect.width*le.rect.height-b.rect.width*b.rect.height)[0]?.node;if(se instanceof HTMLVideoElement&&se.videoWidth&&se.videoHeight)try{const b=document.createElement("canvas");b.width=se.videoWidth,b.height=se.videoHeight;const le=b.getContext("2d");return le?(le.drawImage(se,0,0,b.width,b.height),b.toDataURL("image/png")):""}catch{return""}const N=[...L.querySelectorAll("img")].map(b=>{const le=V(b);return b instanceof HTMLImageElement&&b.src&&le?{node:b,rect:le}:null}).filter(Boolean).sort((b,le)=>le.rect.width*le.rect.height-b.rect.width*b.rect.height)[0]?.node;if(N instanceof HTMLImageElement){try{const b=j(N);if(b)return b}catch{}return oe(N.src)}return""}function Z(L){const B=L.getBoundingClientRect(),q=B.top+B.height*.68;function V(pe){const se=pe.getBoundingClientRect();return se.width<80||se.height<120||se.top>q?null:se}const X=[];for(const pe of L.querySelectorAll("video,canvas,img")){const se=V(pe);se&&(pe instanceof HTMLVideoElement&&pe.videoWidth&&pe.videoHeight?X.push({width:pe.videoWidth,height:pe.videoHeight,area:se.width*se.height}):pe instanceof HTMLCanvasElement&&pe.width&&pe.height?X.push({width:pe.width,height:pe.height,area:se.width*se.height}):pe instanceof HTMLImageElement&&X.push({width:pe.naturalWidth||se.width,height:pe.naturalHeight||se.height,area:se.width*se.height}))}const re=X.filter(pe=>pe.width>0&&pe.height>0).sort((pe,se)=>se.area-pe.area)[0];return re?F(re.width,re.height):null}function ie(L){return new Promise((B,q)=>{const V=new FileReader;V.onload=()=>B(String(V.result||"")),V.onerror=()=>q(V.error),V.readAsDataURL(L)})}async function he(L,B){const q=String(L?.name||"");if(!(!!L&&(/^image\//.test(L.type||"")||/\.(png|jpe?g|webp|gif|bmp)$/i.test(q))))return"";const X=await ie(L);if(!X)return"";const re=await T(X);return j(re,Z(B))}function ne(L){const B=[...L.querySelectorAll("button")],q=B.find(X=>{if(X===a)return!1;const re=String(X.textContent||X.title||X.getAttribute("aria-label")||"").trim();return re==="\xD7"||re==="\xD7"||re.includes("\u5173\u95ED")||/\b(close|dismiss)\b/i.test(re)});if(q instanceof HTMLButtonElement){q.click();return}const V=B.find(X=>{const re=String(X.textContent||"").trim();return re==="\u53D6\u6D88"||/^cancel$/i.test(re)});if(V instanceof HTMLButtonElement){V.click();return}document.dispatchEvent(new KeyboardEvent("keydown",{key:"Escape",bubbles:!0}))}function xe(L,B){const q=G(L),V={time:q,useAsVideoCover:!0,...B?{preview:B}:{}};typeof t?.commit=="function"?t.commit({poster:V}):typeof t?.setPoster=="function"&&t.setPoster(q),ne(L),v()}async function te(L){const B=await Q(L);xe(L,B)}async function w(L,B){const q=await he(B,L);q&&xe(L,q)}function x(L){a instanceof HTMLButtonElement||(a=document.createElement("button"),a.type="button",a.className="me-video-cover-set-btn",a.addEventListener("click",async V=>{V.preventDefault(),V.stopPropagation();const X=H();if(X?.root){a.disabled=!0;try{await te(X.root)}finally{a.disabled=!1}}}));const q=!!(typeof t?.getState=="function"?t.getState():{})?.poster?.useAsVideoCover;return a.textContent=q?k()?"Cover set":"\u5DF2\u8BBE\u4E3A\u5C01\u9762":k()?"Set as cover":"\u8BBE\u4E3A\u5C01\u9762",a.classList.toggle("is-set",q),a.title=a.textContent,a.setAttribute("aria-label",a.textContent),a}function E(){return u instanceof HTMLInputElement||(u=document.createElement("input"),u.type="file",u.accept="image/png,image/jpeg,image/webp,image/*",u.hidden=!0,u.setAttribute("aria-hidden","true"),u.addEventListener("change",async()=>{const L=u.files?.[0];if(u.value="",!L)return;const B=H();if(B?.root){s instanceof HTMLButtonElement&&(s.disabled=!0);try{await w(B.root,L)}finally{s instanceof HTMLButtonElement&&(s.disabled=!1)}}}),e.appendChild(u)),u}function C(L){return s instanceof HTMLButtonElement||(s=document.createElement("button"),s.type="button",s.className="me-video-cover-upload-btn",s.addEventListener("click",B=>{B.preventDefault(),B.stopPropagation(),E().click()})),s.textContent=k()?"Upload cover":"\u4E0A\u4F20\u5C01\u9762",s.title=s.textContent,s.setAttribute("aria-label",s.textContent),s}function y(){const L=H();if(!L?.root||!L.exportButton){a?.remove(),s?.remove();return}const B=x(L.root),q=C(L.root),V=L.exportButton.parentElement;V instanceof HTMLElement&&((B.parentElement!==L.exportButton.parentElement||B.nextElementSibling!==L.exportButton)&&V.insertBefore(B,L.exportButton),(q.parentElement!==V||q.nextElementSibling!==B)&&V.insertBefore(q,B))}const O=new MutationObserver(v);O.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","style","hidden","value"]});const Y=typeof t?.subscribe=="function"?t.subscribe(v):null;return v(),{destroy(){O.disconnect(),Y?.(),a?.remove(),s?.remove(),u?.remove()}}}function va(e,t,n=()=>null){kn();let r=!1;const a=typeof requestAnimationFrame=="function"?requestAnimationFrame:w=>setTimeout(w,16);function s(w){return!!w.closest(["[data-clipblock]","[data-audioclip]",".me-video-text-track-clip",".me-video-text-canvas-hit",".me-video-text-chip",".me-video-trim-action-btn",".me-video-transition-marker",".me-video-text-panel",".me-video-inspector-rail",".me-video-toolrail button",".me-video-timeline-zoom button","input","select","textarea","button","label"].join(","))}function u(w){return!!w.closest(["input","select","textarea",'[contenteditable="true"]','[contenteditable=""]'].join(","))}function f(){r||(r=!0,a(()=>{r=!1,oe()}))}function v(){const w=e.querySelector(".me-video-timeline-scroll");if(!(w instanceof HTMLElement))return;const x=Xt(typeof n=="function"?n():null);w.title=x==="en"?"Hold Ctrl or Shift to select multiple layers.":"\u6309\u4F4F Ctrl \u6216 Shift \u53EF\u591A\u9009\u56FE\u5C42\u3002"}function k(){const w=new Set(_t(e,"video"));for(const x of e.querySelectorAll("[data-clipblock]")){const E=Number(x.getAttribute("data-clipblock"));x.classList.toggle("me-video-multi-selected",Number.isInteger(E)&&w.has(E))}}function H(w=1/0){const x=Fn(e);if(!(x instanceof HTMLElement))return[];const E=[];for(const C of x.querySelectorAll("span")){if(!String(C.textContent??"").trim().startsWith("\u266A"))continue;const O=C.parentElement;!(O instanceof HTMLElement)||E.includes(O)||E.push(O)}return Number.isFinite(w)?E.slice(0,Math.max(0,w)):E}function G(){const w=t.getState().audioClips??[],x=new Set(_t(e,"audio")),E=H(),C=E.slice(0,w.length);E.slice(w.length).forEach(y=>{y instanceof HTMLElement&&(y.removeAttribute("data-audioclip"),y.classList.remove("me-video-multi-selected"),y.style.removeProperty("background"),y.style.removeProperty("border"),y.style.removeProperty("box-shadow"),y.style.removeProperty("color"),y.style.removeProperty("transform"),y.style.removeProperty("opacity"))}),C.forEach((y,O)=>{y.dataset.audioclip=String(O);const Y=x.has(O),L=[...y.children].filter(N=>N instanceof HTMLElement),B=L.length>1?1:0,q=L[B]??null,V=L.filter((N,b)=>b!==B),X=[...y.querySelectorAll("span")],re=Y?"linear-gradient(180deg, rgba(34,197,94,0.96) 0%, rgba(21,128,61,0.94) 100%)":"linear-gradient(180deg, rgba(220,252,231,0.98) 0%, rgba(187,247,208,0.94) 100%)",pe=Y?"2px solid rgba(21,128,61,0.96)":"2px solid rgba(34,197,94,0.5)",se="#166534";y.classList.toggle("me-video-multi-selected",Y),y.style.boxShadow=Y?"0 0 0 2px rgba(34,197,94,0.22), 0 8px 18px rgba(22,101,52,0.16)":"0 1px 6px rgba(22,101,52,0.08)",y.style.background=re,y.style.border=pe,y.style.color=se,y.style.transform=Y?"translateY(-1px)":"none",y.style.opacity=Y?"1":"0.98",q instanceof HTMLElement&&(q.style.background=re,q.style.border=pe,q.style.color=se,q.style.boxShadow=Y?"0 0 0 1px rgba(21,128,61,0.14), 0 8px 18px rgba(22,101,52,0.14)":"0 1px 6px rgba(22,101,52,0.08)"),V.forEach(N=>{N.style.background=Y?"rgba(21,128,61,0.92)":"rgba(34,197,94,0.72)",N.style.opacity="1"}),X.forEach((N,b)=>{N.style.color=b===0?se:"rgba(22,101,52,0.9)",N.style.opacity="1"})})}function T(){return[...e.querySelectorAll(".me-video-trim-actions .me-video-trim-action-btn")].map(w=>{if(!(w instanceof HTMLElement)||w.tagName.toLowerCase()!=="button")return w;const x=document.createElement("div");for(const E of[...w.attributes])E.name==="type"||E.name==="disabled"||x.setAttribute(E.name,E.value);return x.innerHTML=w.innerHTML,x.style.cssText=w.style.cssText,x.style.display="flex",x.style.justifyContent="center",x.style.alignItems="center",x.setAttribute("role","button"),x.tabIndex=w.disabled?-1:0,x.setAttribute("aria-disabled",w.disabled?"true":"false"),w.disabled&&(x.dataset.disabled="true"),w.replaceWith(x),x})}function F(w,x,E,C){const y=T();if(y.length<3)return;const O=w.clips??[],Y=w.audioClips??[],L=yn(e),B=x.length>0||E.length>0||C.length>0,q=yi(O,x,L)||ki(Y,E,L)||wi(w.overlays??[],C,L),V=B,X=E.length>0||C.length>0||x.length>0&&x.length<O.length,re=[q,V,X];y.forEach((pe,se)=>{const N=re[se];pe.setAttribute("aria-disabled",N?"false":"true"),pe.tabIndex=N?0:-1,N?delete pe.dataset.disabled:pe.dataset.disabled="true",pe.style.opacity=N?"1":"0.5",se===2?(pe.style.color=N?"#dc2626":"var(--me-fg-muted, #9a9aa3)",pe.style.background="",pe.style.boxShadow=""):(pe.style.color=N?"var(--me-fg, #ededf0)":"var(--me-fg-muted, #9a9aa3)",pe.style.background="",pe.style.boxShadow="")})}function j(w){w===0?Si(e,t):w===1?Ei(e,t):w===2&&fr(e,t),f()}function oe(){const w=t.getState();mi(e,w),v();const x=$n(e,w.clips??[]),E=Mn(e,w.audioClips??[]),C=Dn(e,w);k(),G(),F(w,x,E,C)}function Q(w){if(!(w.target instanceof Element))return;const x=w.target.closest("[data-clipblock]");if(!x||!e.contains(x))return;const E=Number(x.getAttribute("data-clipblock"));if(!Number.isInteger(E))return;const C=(t.getState().clips??[]).map((y,O)=>O);if(w.shiftKey||w.ctrlKey||w.metaKey){w.preventDefault(),w.stopPropagation(),Pt(e,"video",E,w,C),f();return}bt(e,"video",[E]),f()}function Z(w){if(!(w.target instanceof Element))return;const x=w.target.closest("[data-audioclip]");if(!x||!e.contains(x))return;const E=Number(x.getAttribute("data-audioclip"));if(!Number.isInteger(E))return;const C=(t.getState().audioClips??[]).map((y,O)=>O);if(w.shiftKey||w.ctrlKey||w.metaKey){w.preventDefault(),w.stopPropagation(),Pt(e,"audio",E,w,C),f();return}bt(e,"audio",[E]),f()}function ie(w){w.target instanceof Element&&e.contains(w.target)&&(s(w.target)||So(e)&&(Eo(e),f()))}function he(w){if(!(w.target instanceof Element))return;const x=w.target.closest("[data-clipblock]");if(x&&e.contains(x)&&(w.shiftKey||w.ctrlKey||w.metaKey)){w.preventDefault(),w.stopPropagation();return}const E=w.target.closest(".me-video-trim-actions .me-video-trim-action-btn");if(!E||!e.contains(E))return;const y=[...e.querySelectorAll(".me-video-trim-actions .me-video-trim-action-btn")].indexOf(E);y!==-1&&(w.preventDefault(),w.stopPropagation(),E.getAttribute("aria-disabled")!=="true"&&j(y))}function ne(w){if(!(w.target instanceof Element))return;if((w.key==="Delete"||w.key==="Backspace")&&!u(w.target)&&So(e)){w.preventDefault(),w.stopPropagation(),fr(e,t),f();return}if(w.key!=="Enter"&&w.key!==" ")return;const x=w.target.closest(".me-video-trim-actions .me-video-trim-action-btn");if(!x||!e.contains(x))return;const C=[...e.querySelectorAll(".me-video-trim-actions .me-video-trim-action-btn")].indexOf(x);C!==-1&&(w.preventDefault(),w.stopPropagation(),x.getAttribute("aria-disabled")!=="true"&&j(C))}const xe=new MutationObserver(()=>{f()});xe.observe(e,{childList:!0,subtree:!0}),e.addEventListener("pointerdown",Q,!0),e.addEventListener("pointerdown",Z,!0),e.addEventListener("pointerdown",ie,!0),e.addEventListener("click",he,!0),e.addEventListener("keydown",ne,!0),e.addEventListener(zt,f),window.addEventListener("resize",f);const te=t.subscribe(()=>{f()});return oe(),{destroy(){xe.disconnect(),te(),e.removeEventListener("pointerdown",Q,!0),e.removeEventListener("pointerdown",Z,!0),e.removeEventListener("pointerdown",ie,!0),e.removeEventListener("click",he,!0),e.removeEventListener("keydown",ne,!0),e.removeEventListener(zt,f),window.removeEventListener("resize",f)}}}const mo=[{key:"480p",label:"480P",shortEdge:480},{key:"720p",label:"720P",shortEdge:720},{key:"1080p",label:"1080P",shortEdge:1080},{key:"2k",label:"2K",shortEdge:1440},{key:"4k",label:"4K",shortEdge:2160},{key:"8k",label:"8K",shortEdge:4320},{key:"source",label:"\u539F\u59CB"},{key:"custom",label:"\u81EA\u5B9A\u4E49"}],ha=[{key:"mov",label:"MOV",extension:"mov"},{key:"mp4",label:"MP4",extension:"mp4"},{key:"mxf",label:"MXF",extension:"mxf"}],xa=[24,25,30,50,60],ba=[{key:"aac",label:"AAC"},{key:"mp3",label:"MP3"}],ga=[96,128,192,256,320],zr="me-video-export-enhancer-styles";function ya(){if(document.getElementById(zr))return;const e=document.createElement("style");e.id=zr,e.textContent=`
|
|
2047
|
+
</svg>`}function En(e,t){const n=xo(t),r=e.transitions.options[n.key]??e.transitions.options.none;return{...n,label:r.label,short:r.short}}function Un(e,t=ho.en.untitledText){return String(e??"").replace(/\s+/g," ").trim()||t}function Da(e){if(!e)return!1;const t=String(e).trim().toLowerCase();return t!==""&&t!=="transparent"}function xo(e){return vo.find(t=>t.key===e)??vo[0]}function mn(e){const t=Number(e)||0;return`${t.toFixed(t>=1?1:2).replace(/0+$/,"").replace(/\.$/,"")}s`}function Dt(e){return Math.max(0,(Number(e?.out)||0)-(Number(e?.in)||0))}function bn(e){return ue(Number(e)||1,.5,2)}function Qr(e){return`${bn(e).toFixed(2)}x`}function ei(e,t=1){const n=String(e??"").trim().replace(/x$/i,""),r=Number(n);return Number.isFinite(r)?bn(r):bn(t)}function ti(e,t=0){const n=String(e??"").trim().replace(/s$/i,""),r=Number(n);return Number.isFinite(r)?Math.max(0,r):Math.max(0,t)}function Gn(e,t=.4,n=.4){const r=xo(e?.type??"none"),i=Math.max(0,Math.min(1.2,t-.05,n-.05));if(r.key==="none"||i<=.05)return{type:"none",duration:0};const s=Number(e?.duration),u=ue(Number.isFinite(s)?s:r.duration,.1,i);return{type:r.key,duration:u}}function bo(e){const t=e?.clips??[],n=Math.max(0,t.length-1),r=Array.isArray(e?.transitions)?e.transitions:[],i=[];for(let s=0;s<n;s++)i.push(Gn(r[s],Dt(t[s]),Dt(t[s+1])));return i}function tr(e,t,n="heading"){const i=e.getState().canvas??{w:1080,h:1920},s=qo[n]??qo.heading,u=Math.min(s.width,Math.max(240,i.w-64)),p=Math.min(s.fontSize,Math.max(32,Math.round(i.w*.11))),v=ue(Math.round(i.h*.18),32,Math.max(32,i.h-180));return{type:"text",x:Math.round((i.w-u)/2),y:v,text:t.textPresets[n]??s.text,color:s.color,fontSize:p,fontFamily:"Arial",fontWeight:s.fontWeight,fontStyle:"normal",textAlign:s.textAlign,width:u,backgroundColor:s.backgroundColor,borderColor:s.borderColor,borderWidth:s.borderWidth,paddingX:s.paddingX??Math.max(14,Math.round(p*.18)),paddingY:s.paddingY??Math.max(10,Math.round(p*.14)),boxShadow:s.boxShadow?{...s.boxShadow}:void 0,lineHeight:1.1,textPreset:n,textDecoration:"",textTransform:void 0,animation:"none",rotation:0}}const qt=3,je=.5,Wt=.1,gn=99,go=36,nr=6;function lt(e,t=0){return Number.isFinite(e?.startAt)?Math.max(0,Number(e.startAt)):Math.max(0,t)}function Bt(e,t=0,n=qt){const r=lt(e,t);return Number.isFinite(e?.endAt)?Math.max(r+je,Number(e.endAt)):r+Math.max(je,n)}function Sn(e,t=qt){return Math.max(je,Bt(e,0,t)-lt(e,0))}function vt(e,t=0){return Number.isFinite(e?.timelineTrack)?ue(Math.round(Number(e.timelineTrack)),0,gn):Math.max(0,t)}function ni(e){return e==="pen"||e==="line"||e==="arrow"||e==="rect"||e==="ellipse"}function nn(e){return ni(e?.type)}function Zt(e){return e?.type==="text"||e?.type==="sticker"||e?.type==="filter"||e?.type==="adjust"||nn(e)}function Ln(e){return e*(go+nr)}function yo(e){const t=Array.isArray(e)?e:e?.overlays;return[...new Set((t??[]).filter(n=>Zt(n)).map(n=>vt(n)))].sort((n,r)=>n-r)}function Fn(e){const t=new Map;return yo(e).forEach((n,r)=>{t.set(n,r)}),t}function oi(e){return yo(e).length}function ri(e){const t=oi(e);return t?Ln(t-1)+go:0}function ii(e){return e instanceof HTMLElement&&(e.dataset.meTimelineCoverSlot==="true"||e.classList.contains("me-video-timeline-cover-slot"))}function ai(e){const t=e.querySelector(".me-video-timeline-scroll");return t instanceof HTMLElement?t:null}function Bn(e){const t=ai(e);return t?[...t.children].find(n=>n instanceof HTMLElement&&!ii(n))??null:null}function or(e){const n=Bn(e)?.firstElementChild;return n instanceof HTMLElement?n:null}function $n(e,t){const n=Bn(e);if(!n)return{timelineInner:null,timelineHost:null};n.style.position="relative";const r=n.firstElementChild,i=ri(t),s=[];for(const w of n.children)w instanceof HTMLElement&&w.classList.contains("me-video-overlay-track-host")&&s.push(w);const u=[...n.children].find(w=>w!==r&&!(w instanceof HTMLElement&&w.classList.contains("me-video-overlay-track-host")))??null;if(!u)return s.forEach(w=>w.remove()),{timelineInner:n,timelineHost:null};const p=s.shift()??null;if(s.forEach(w=>w.remove()),i<=0)return p?.remove(),{timelineInner:n,timelineHost:null};const v=p??document.createElement("div");return p||(v.className="me-video-overlay-track-host"),v.style.height=`${i}px`,(v.parentElement!==n||v.nextElementSibling!==u)&&n.insertBefore(v,u),{timelineInner:n,timelineHost:v}}function si(e){return((Array.isArray(e)?e:e?.overlays)??[]).reduce((n,r)=>Zt(r)?Math.max(n,Bt(r)):n,0)}function rr(e,t,n,r){return e<r-1e-6&&n<t-1e-6}function _a(e,t,n,r=-1){const i=new Map;(e??[]).forEach((s,u)=>{if(u===r||!Zt(s))return;const p=vt(s);let v=i.get(p);v||(v=[],i.set(p,v)),v.push({startAt:lt(s),endAt:Bt(s)})});for(let s=0;s<=gn;s++)if((i.get(s)??[]).every(p=>!rr(t,n,p.startAt,p.endAt)))return s;return gn}function li(e,t,n,r,i){const s=ue(Math.round(Number(i)||0),0,gn);return(e??[]).every((u,p)=>p===t||!Zt(u)||vt(u)!==s?!0:!rr(n,r,lt(u),Bt(u)))}function ft(e,t,n,r,i,s,u){if(!e)return u;const p=e.getBoundingClientRect(),v=Math.max(0,s-p.top),w=yo(t),z=ue(Math.floor(v/(go+nr)),0,w.length),te=z<w.length?w[z]:ue((w[w.length-1]??-1)+1,0,gn);return li(t,n,r,i,te)?te:u}function Jt(e,t,n={}){const r=lt(e,0),i=Sn(e),s=Number.isFinite(n.startAt)?Number(n.startAt):r,u=Number.isFinite(n.endAt)?Number(n.endAt):s+i,p=Math.max(0,s),v=Math.max(p+je,u),w=Math.max(je,Number(t)||qt,v),z=ue(p,0,Math.max(0,w-je)),te=ue(v,z+je,Math.max(z+je,w));return{startAt:z,endAt:te,timelineTrack:vt({timelineTrack:n.timelineTrack??e?.timelineTrack})}}function ir(e,t=1){const n=Math.max(0,Math.round(Number(t)||0));return n?(e??[]).map(r=>Zt(r)?{...r,timelineTrack:ue(vt(r)+n,0,gn)}:r):[...e??[]]}function on(e){return ir(e,1)}function ar(e){return(e.overlays??[]).map((t,n)=>({overlay:t,index:n})).filter(t=>t.overlay?.type==="text").sort((t,n)=>{const r=vt(t.overlay)-vt(n.overlay);if(r!==0)return r;const i=lt(t.overlay)-lt(n.overlay);return Math.abs(i)>1e-6?i:t.index-n.index})}function sr(e){return(e.overlays??[]).map((t,n)=>({overlay:t,index:n})).filter(t=>t.overlay?.type==="sticker").sort((t,n)=>{const r=vt(t.overlay)-vt(n.overlay);if(r!==0)return r;const i=lt(t.overlay)-lt(n.overlay);return Math.abs(i)>1e-6?i:t.index-n.index})}function lr(e){return(e.overlays??[]).map((t,n)=>({overlay:t,index:n})).filter(t=>t.overlay?.type==="filter").sort((t,n)=>{const r=vt(t.overlay)-vt(n.overlay);if(r!==0)return r;const i=lt(t.overlay)-lt(n.overlay);return Math.abs(i)>1e-6?i:t.index-n.index})}function cr(e){return(e.overlays??[]).map((t,n)=>({overlay:t,index:n})).filter(t=>t.overlay?.type==="adjust").sort((t,n)=>{const r=vt(t.overlay)-vt(n.overlay);if(r!==0)return r;const i=lt(t.overlay)-lt(n.overlay);return Math.abs(i)>1e-6?i:t.index-n.index})}function wo(e){return(e.overlays??[]).map((t,n)=>({overlay:t,index:n})).filter(t=>nn(t.overlay)).sort((t,n)=>{const r=vt(t.overlay)-vt(n.overlay);if(r!==0)return r;const i=lt(t.overlay)-lt(n.overlay);return Math.abs(i)>1e-6?i:t.index-n.index})}function ci(e){return(e.overlays??[]).map((t,n)=>({overlay:t,index:n})).filter(t=>Zt(t.overlay)).sort((t,n)=>{const r=vt(t.overlay)-vt(n.overlay);if(r!==0)return r;const i=lt(t.overlay)-lt(n.overlay);return Math.abs(i)>1e-6?i:t.index-n.index})}function yt(e){return[...new Set((e??[]).map(t=>Number(t)).filter(t=>Number.isInteger(t)&&t>=0))].sort((t,n)=>t-n)}function Zn(e){if(e.__meVideoTimelineSelectionStore)return e.__meVideoTimelineSelectionStore;const t={video:new Set,text:new Set,audio:new Set,anchors:{video:null,text:null,audio:null},initialized:!1};return e.__meVideoTimelineSelectionStore=t,t}function di(e,t){return t==="text"?e.text:t==="audio"?e.audio:e.video}function dr(){return["video","text","audio"]}function _t(e,t){return yt([...di(Zn(e),t)])}function ko(e,t){const n=yt(t),r=yt([...e]);return r.length===n.length&&r.every((i,s)=>i===n[s])?!1:(e.clear(),n.forEach(i=>e.add(i)),!0)}function ui(e){e.dispatchEvent(new CustomEvent(Ht))}function fn(e,t={},n={}){const r=Zn(e);let i=!1;if(Object.prototype.hasOwnProperty.call(t,"video")&&(i=ko(r.video,t.video)||i),Object.prototype.hasOwnProperty.call(t,"text")&&(i=ko(r.text,t.text)||i),Object.prototype.hasOwnProperty.call(t,"audio")&&(i=ko(r.audio,t.audio)||i),Object.prototype.hasOwnProperty.call(n,"video")){const s=Number.isInteger(n.video)&&n.video>=0?n.video:null;r.anchors.video!==s&&(r.anchors.video=s,i=!0)}if(Object.prototype.hasOwnProperty.call(n,"text")){const s=Number.isInteger(n.text)&&n.text>=0?n.text:null;r.anchors.text!==s&&(r.anchors.text=s,i=!0)}if(Object.prototype.hasOwnProperty.call(n,"audio")){const s=Number.isInteger(n.audio)&&n.audio>=0?n.audio:null;r.anchors.audio!==s&&(r.anchors.audio=s,i=!0)}return i&&ui(e),r}function bt(e,t,n,r={}){const i=yt(n),s={[t]:i},u={[t]:i.length?r.anchor??i[i.length-1]:null};if(!r.preserveOther)for(const p of dr())p!==t&&(s[p]=[],u[p]=null);return fn(e,s,u),i}function Eo(e){fn(e,{video:[],text:[],audio:[]},{video:null,text:null,audio:null})}function So(e){return _t(e,"video").length>0||_t(e,"text").length>0||_t(e,"audio").length>0}function Lo(e,t,n){const r=new Set(yt(n)),i=_t(e,t),s=i.filter(u=>r.has(u));return i.length!==s.length&&fn(e,{[t]:s},{[t]:s.length?s[s.length-1]:null}),s}function zt(e,t,n,r,i=[]){const s=yt(i),u=!!(r?.ctrlKey||r?.metaKey),p=!!r?.shiftKey,v=Zn(e),w=_t(e,t);let z=w,te=n;if(p){const V=v.anchors[t],ie=s.indexOf(V),J=s.indexOf(n);if(ie!==-1&&J!==-1){const oe=Math.min(ie,J),le=Math.max(ie,J),xe=s.slice(oe,le+1);z=u?yt([...w,...xe]):xe,te=V}else u?z=w.includes(n)?w.filter(oe=>oe!==n):[...w,n]:z=[n]}else u?z=w.includes(n)?w.filter(V=>V!==n):[...w,n]:z=[n];z=yt(z);const S={[t]:z},B={[t]:z.length?te:null};if(!u)for(const V of dr())V!==t&&(S[V]=[],B[V]=null);return fn(e,S,B),z}function mi(e,t){const n=Zn(e);n.initialized||(n.initialized=!0)}function Tn(e){const t=typeof e.getState=="function"?e.getState():null;return Math.max(typeof e.contentDuration=="function"?e.contentDuration():0,si(t),je)}function Jn(e){const t=String(e??"").trim();if(!t)return NaN;const n=t.split(":").map(i=>i.trim()).filter(Boolean);if(!n.length)return NaN;let r=0;for(const i of n){const s=Number(i);if(!Number.isFinite(s))return NaN;r=r*60+s}return r}function Qn(e){return e instanceof HTMLElement?String(e.dataset.meRawTimeText||e.textContent||"").trim():""}function yn(e){const t=or(e);if(t){const i=[...t.children].find(u=>u instanceof HTMLElement&&String(u.style.transform||"").includes("translateX(-50%)")),s=Jn(Qn(i));if(Number.isFinite(s))return s}const n=[...e.querySelectorAll(".me-video-trim-actions span")].find(i=>Qn(i).includes("/")),r=Qn(n);if(r){const i=Jn(r.split("/")[0]);if(Number.isFinite(i))return i}return 0}function Dn(e,t){return Lo(e,"video",(t??[]).map((n,r)=>r)).filter(n=>!!t[n])}function To(e,t){return _t(e,"text").filter(n=>t.overlays?.[n]?.type==="text")}function ur(e,t){return _t(e,"text").filter(n=>t.overlays?.[n]?.type==="sticker")}function mr(e,t){return _t(e,"text").filter(n=>t.overlays?.[n]?.type==="filter")}function eo(e,t){return _t(e,"text").filter(n=>t.overlays?.[n]?.type==="adjust")}function fr(e,t){return _t(e,"text").filter(n=>nn(t.overlays?.[n]))}function _n(e,t){const n=ci(t).map(r=>r.index);return Lo(e,"text",n).filter(r=>Zt(t.overlays?.[r]))}function Mn(e,t){return Lo(e,"audio",(t??[]).map((n,r)=>r)).filter(n=>!!t[n])}function fi(e,t){const n=yt(t).filter(s=>!!e[s]);if(!n.length)return{clips:e,selection:[],changed:!1};const r=n[n.length-1]+1,i=n.map(s=>({...e[s]}));return{clips:[...e.slice(0,r),...i,...e.slice(r)],selection:i.map((s,u)=>r+u),changed:!0}}function Mo(e,t){const n=yt(t).filter(p=>Zt(e[p]));if(!n.length)return{overlays:e,selection:[],changed:!1};const r=n.map(p=>{const v=e[p];return v?.type==="pen"?{...v,points:(v.points??[]).map((w,z)=>(z%2===0,(Number(w)||0)+24))}:v?.type==="line"||v?.type==="arrow"?{...v,x1:(Number(v.x1)||0)+24,y1:(Number(v.y1)||0)+24,x2:(Number(v.x2)||0)+24,y2:(Number(v.y2)||0)+24}:{...v,x:(Number(v.x)||0)+24,y:(Number(v.y)||0)+24}}),s=[...ir(e,r.length),...r.map((p,v)=>({...p,timelineTrack:ue(v,0,gn)}))],u=s.length-r.length;return{overlays:s,selection:r.map((p,v)=>u+v),changed:!0}}function pi(e,t){const n=yt(t).filter(s=>!!e[s]);if(!n.length)return{audioClips:e,selection:[],changed:!1};const r=n[n.length-1]+1,i=n.map(s=>{const u=e[s];return{...u,track:Number.isInteger(u?.track)&&u.track>=0?u.track:s,startAt:Math.max(0,(Number(u.startAt)||0)+.2)}});return{audioClips:[...e.slice(0,r),...i,...e.slice(r)],selection:i.map((s,u)=>r+u),changed:!0}}function vi(e,t){const n=yt(t).filter(i=>!!e[i]);if(!n.length||n.length>=e.length)return{clips:e,selection:n,changed:!1};const r=new Set(n);return{clips:e.filter((i,s)=>!r.has(s)),selection:[],changed:!0}}function Co(e,t){const n=new Set(yt(t).filter(r=>Zt(e[r])));return n.size?{overlays:e.filter((r,i)=>!n.has(i)),selection:[],changed:!0}:{overlays:e,selection:[],changed:!1}}function hi(e,t){const n=new Set(yt(t).filter(r=>!!e[r]));return n.size?{audioClips:e.filter((r,i)=>!n.has(i)),selection:[],changed:!0}:{audioClips:e,selection:[],changed:!1}}function xi(e,t,n){const r=new Set(yt(t).filter(v=>!!e[v]));if(!r.size)return{clips:e,selection:[],changed:!1};let i=0,s=!1;const u=[],p=[];for(let v=0;v<e.length;v++){const w=e[v],z=Math.max(0,(Number(w?.out)||0)-(Number(w?.in)||0)),te=i+z;if(r.has(v)&&n>i+Wt&&n<te-Wt){const S=(Number(w.in)||0)+(n-i);p.push(u.length),u.push({...w,out:S}),p.push(u.length),u.push({...w,in:S}),s=!0}else r.has(v)&&p.push(u.length),u.push(w);i=te}return{clips:s?u:e,selection:s?p:yt(t),changed:s}}function bi(e,t,n,r){const i=new Set(yt(t).filter(v=>Zt(e[v])));if(!i.size)return{overlays:e,selection:[],changed:!1};let s=!1;const u=[],p=[];for(let v=0;v<e.length;v++){const w=e[v];if(Zt(w)&&i.has(v)){const z=lt(w),te=Bt(w,z),S=ue(r,z+je,te-je);if(S>z+1e-6&&S<te-1e-6){p.push(u.length),u.push({...w,...Jt(w,n,{startAt:z,endAt:S,timelineTrack:vt(w)})}),p.push(u.length),u.push({...w,...Jt(w,n,{startAt:S,endAt:te,timelineTrack:vt(w)})}),s=!0;continue}p.push(u.length)}u.push(w)}return{overlays:s?u:e,selection:s?p:yt(t),changed:s}}function gi(e,t,n){const r=new Set(yt(t).filter(p=>!!e[p]));if(!r.size)return{audioClips:e,selection:[],changed:!1};let i=!1;const s=[],u=[];for(let p=0;p<e.length;p++){const v=e[p],w=Math.max(0,Number(v?.startAt)||0),z=Dt(v),te=w+z;if(r.has(p)&&n>w+Wt&&n<te-Wt){const S=(Number(v.in)||0)+(n-w),B=Math.max(0,S-(Number(v.in)||0)),V=Math.max(0,(Number(v.out)||0)-S);u.push(s.length),s.push({...v,track:Number.isInteger(v?.track)&&v.track>=0?v.track:p,out:S,fadeIn:Math.min(Number(v.fadeIn)||0,B),fadeOut:0}),u.push(s.length),s.push({...v,track:Number.isInteger(v?.track)&&v.track>=0?v.track:p,in:S,startAt:n,fadeIn:0,fadeOut:Math.min(Number(v.fadeOut)||0,V)}),i=!0;continue}r.has(p)&&u.push(s.length),s.push(v)}return{audioClips:i?s:e,selection:i?u:yt(t),changed:i}}function yi(e,t,n){const r=new Set(yt(t));let i=0;for(let s=0;s<e.length;s++){const u=e[s],p=Math.max(0,(Number(u?.out)||0)-(Number(u?.in)||0)),v=i+p;if(r.has(s)&&n>i+Wt&&n<v-Wt)return!0;i=v}return!1}function wi(e,t,n){return yt(t).some(r=>{const i=e[r];if(!Zt(i))return!1;const s=lt(i),u=Bt(i,s);return n>s+je&&n<u-je})}function ki(e,t,n){return yt(t).some(r=>{const i=e[r];if(!i)return!1;const s=Math.max(0,Number(i.startAt)||0),u=s+Dt(i);return n>s+Wt&&n<u-Wt})}function Ei(e,t){const n=t.getState(),r=n.clips??[],i=n.audioClips??[],s=n.overlays??[],u=Dn(e,r),p=Mn(e,i),v=_n(e,n);if(!u.length&&!p.length&&!v.length)return!1;let w=r,z=i,te=s,S=u,B=p,V=v,ie=!1;if(u.length){const J=fi(w,u);w=J.clips,S=J.selection,ie=J.changed||ie}if(p.length){const J=pi(z,p);z=J.audioClips,B=J.selection,ie=J.changed||ie}if(v.length){const J=Mo(te,v);te=J.overlays,V=J.selection,ie=J.changed||ie}return ie?(t.commit({clips:w,audioClips:z,overlays:te}),fn(e,{video:S,audio:B,text:V},{video:S.length?S[S.length-1]:null,audio:B.length?B[B.length-1]:null,text:V.length?V[V.length-1]:null}),!0):!1}function pr(e,t){const n=t.getState(),r=n.clips??[],i=n.audioClips??[],s=n.overlays??[],u=Dn(e,r),p=Mn(e,i),v=_n(e,n);let w=r,z=i,te=s,S=u,B=p,V=v,ie=!1;const J=vi(w,u);J.changed&&(w=J.clips,S=J.selection,ie=!0);const oe=Co(te,v);oe.changed&&(te=oe.overlays,V=oe.selection,ie=!0);const le=hi(z,p);return le.changed&&(z=le.audioClips,B=le.selection,ie=!0),ie?(t.commit({clips:w,audioClips:z,overlays:te}),fn(e,{video:S,audio:B,text:V},{video:S.length?S[S.length-1]:null,audio:B.length?B[B.length-1]:null,text:V.length?V[V.length-1]:null}),!0):!1}function Si(e,t){const n=t.getState(),r=n.clips??[],i=n.audioClips??[],s=n.overlays??[],u=yn(e),p=Dn(e,r),v=Mn(e,i),w=_n(e,n);let z=r,te=i,S=s,B=p,V=v,ie=w,J=!1;if(p.length){const oe=xi(z,p,u);z=oe.clips,B=oe.selection,J=oe.changed||J}if(v.length){const oe=gi(te,v,u);te=oe.audioClips,V=oe.selection,J=oe.changed||J}if(w.length){const oe=bi(S,w,Math.max(Tn(t),u+je),u);S=oe.overlays,ie=oe.selection,J=oe.changed||J}return J?(t.commit({clips:z,audioClips:te,overlays:S}),fn(e,{video:B,audio:V,text:ie},{video:B.length?B[B.length-1]:null,audio:V.length?V[V.length-1]:null,text:ie.length?ie[ie.length-1]:null}),!0):!1}function to(e,t){const n=document.createElement("div");n.className="me-video-text-field";const r=document.createElement("label");return r.textContent=e,n.append(r,t),n}function Yt(e){const t=document.createElement("button");return t.type="button",t.className="me-video-text-mini",t.textContent=e,t}function Li(e,t){const n=document.createElement("button");return n.type="button",n.className="me-video-text-preset",n.dataset.preset=t,n.textContent=e,n}const Ti=[{value:"300",label:"Light"},{value:"400",label:"Regular"},{value:"500",label:"Medium"},{value:"600",label:"Semibold"},{value:"700",label:"Bold"},{value:"800",label:"Extra Bold"}],vr={en:{content:"Content",preset:"Preset",styles:"Styles",size:"Size",fill:"Fill",decoration:"Decoration",italic:"Italic",underline:"Underline",strike:"Strike",case:"Case",caseNone:"None",uppercase:"Uppercase",lowercase:"Lowercase",capitalize:"Capitalize",alignLeft:"Left",alignCenter:"Center",alignRight:"Right",animations:"Animations",animation:"Animation",fontStroke:"Font stroke",fontShadow:"Font shadow",x:"X",y:"Y",blur:"Blur",transparent:"Transparent",none:"None"},zh:{content:"\u5185\u5BB9",preset:"\u9884\u8BBE",styles:"\u6837\u5F0F",size:"\u5927\u5C0F",fill:"\u586B\u5145",decoration:"\u4FEE\u9970",italic:"\u659C\u4F53",underline:"\u4E0B\u5212\u7EBF",strike:"\u5220\u9664\u7EBF",case:"\u5927\u5C0F\u5199",caseNone:"\u65E0",uppercase:"\u5168\u90E8\u5927\u5199",lowercase:"\u5168\u90E8\u5C0F\u5199",capitalize:"\u9996\u5B57\u6BCD\u5927\u5199",alignLeft:"\u5DE6\u5BF9\u9F50",alignCenter:"\u5C45\u4E2D",alignRight:"\u53F3\u5BF9\u9F50",animations:"\u52A8\u753B",animation:"\u52A8\u753B",fontStroke:"\u6587\u5B57\u63CF\u8FB9",fontShadow:"\u6587\u5B57\u9634\u5F71",x:"X",y:"Y",blur:"\u6A21\u7CCA",transparent:"\u900F\u660E",none:"\u65E0"},"zh-Hant":{content:"\u5167\u5BB9",preset:"\u9810\u8A2D",styles:"\u6A23\u5F0F",size:"\u5927\u5C0F",fill:"\u586B\u5145",decoration:"\u4FEE\u98FE",italic:"\u659C\u9AD4",underline:"\u5E95\u7DDA",strike:"\u522A\u9664\u7DDA",case:"\u5927\u5C0F\u5BEB",caseNone:"\u7121",uppercase:"\u5168\u90E8\u5927\u5BEB",lowercase:"\u5168\u90E8\u5C0F\u5BEB",capitalize:"\u9996\u5B57\u6BCD\u5927\u5BEB",alignLeft:"\u9760\u5DE6",alignCenter:"\u7F6E\u4E2D",alignRight:"\u9760\u53F3",animations:"\u52D5\u756B",animation:"\u52D5\u756B",fontStroke:"\u6587\u5B57\u63CF\u908A",fontShadow:"\u6587\u5B57\u9670\u5F71",x:"X",y:"Y",blur:"\u6A21\u7CCA",transparent:"\u900F\u660E",none:"\u7121"}},hr={en:{tool:"Ratio",title:"Ratio & canvas size",restore:"Restore",close:"Close",commonPresets:"Platform ratio presets",customSize:"Custom resolution",fitMode:"Canvas fill mode",width:"Width (px)",height:"Height (px)",lockRatio:"Lock ratio",unlockRatio:"Unlock ratio",quickPortrait:"1080p Portrait",quickLandscape:"1080p Landscape",summary:"Current output",baseOutput:"Base output",cover:"Crop to fill",contain:"Fit inside",force:"Stretch to fill",coverHint:"Fills the canvas and crops any overflow.",containHint:"Keeps the full frame and may add letterboxing.",forceHint:"Stretches the frame to the target size without cropping.",cinematic:"Cinematic",tablet:"Tablet"},zh:{tool:"\u6BD4\u4F8B",title:"\u6BD4\u4F8B\u4E0E\u753B\u5E03\u5C3A\u5BF8",restore:"\u6062\u590D",close:"\u5173\u95ED",commonPresets:"\u5E73\u53F0\u6BD4\u4F8B\u9884\u8BBE",customSize:"\u81EA\u5B9A\u4E49\u5206\u8FA8\u7387",fitMode:"\u753B\u9762\u586B\u5145\u9009\u9879",width:"\u5BBD\u5EA6 (px)",height:"\u9AD8\u5EA6 (px)",lockRatio:"\u9501\u5B9A\u6BD4\u4F8B",unlockRatio:"\u89E3\u9501\u6BD4\u4F8B",quickPortrait:"1080p \u7AD6\u5C4F",quickLandscape:"1080p \u6A2A\u5C4F",summary:"\u5F53\u524D\u8F93\u51FA",baseOutput:"\u539F\u59CB\u8F93\u51FA",cover:"\u88C1\u526A\u94FA\u6EE1",contain:"\u5B8C\u6574\u663E\u793A",force:"\u62C9\u4F38\u94FA\u6EE1",coverHint:"\u94FA\u6EE1\u753B\u5E03\uFF0C\u591A\u4F59\u533A\u57DF\u4F1A\u88AB\u88C1\u526A\u3002",containHint:"\u5B8C\u6574\u4FDD\u7559\u753B\u9762\uFF0C\u53EF\u80FD\u51FA\u73B0\u7559\u767D\u3002",forceHint:"\u5F3A\u5236\u62C9\u4F38\u5230\u76EE\u6807\u5C3A\u5BF8\uFF0C\u4E0D\u88C1\u526A\u3002",cinematic:"\u7535\u5F71\u5BBD\u5C4F",tablet:"\u5E73\u677F"},"zh-Hant":{tool:"\u6BD4\u4F8B",title:"\u6BD4\u4F8B\u8207\u756B\u5E03\u5C3A\u5BF8",restore:"\u9084\u539F",close:"\u95DC\u9589",commonPresets:"\u5E73\u53F0\u6BD4\u4F8B\u9810\u8A2D",customSize:"\u81EA\u8A02\u89E3\u6790\u5EA6",fitMode:"\u756B\u9762\u586B\u5145\u9078\u9805",width:"\u5BEC\u5EA6 (px)",height:"\u9AD8\u5EA6 (px)",lockRatio:"\u9396\u5B9A\u6BD4\u4F8B",unlockRatio:"\u89E3\u9396\u6BD4\u4F8B",quickPortrait:"1080p \u76F4\u5F0F",quickLandscape:"1080p \u6A6B\u5F0F",summary:"\u76EE\u524D\u8F38\u51FA",baseOutput:"\u539F\u59CB\u8F38\u51FA",cover:"\u88C1\u5207\u92EA\u6EFF",contain:"\u5B8C\u6574\u986F\u793A",force:"\u62C9\u4F38\u92EA\u6EFF",coverHint:"\u92EA\u6EFF\u756B\u5E03\uFF0C\u591A\u9918\u5340\u57DF\u6703\u88AB\u88C1\u5207\u3002",containHint:"\u5B8C\u6574\u4FDD\u7559\u756B\u9762\uFF0C\u53EF\u80FD\u51FA\u73FE\u7559\u767D\u3002",forceHint:"\u5F37\u5236\u62C9\u4F38\u81F3\u76EE\u6A19\u5C3A\u5BF8\uFF0C\u4E0D\u88C1\u5207\u3002",cinematic:"\u96FB\u5F71\u5BEC\u87A2\u5E55",tablet:"\u5E73\u677F"}},Mi=[{id:"facebook-post",platform:"Facebook",type:"Post",iconText:"f",iconTheme:"facebook",ratios:["1:1","4:5","16:9"]},{id:"facebook-story",platform:"Facebook",type:"Story",iconText:"f",iconTheme:"facebook",ratios:["9:16"]},{id:"instagram-post",platform:"Instagram",type:"Post",iconText:"IG",iconTheme:"instagram",ratios:["1:1","4:5","16:9"]},{id:"instagram-story",platform:"Instagram",type:"Story",iconText:"IG",iconTheme:"instagram",ratios:["9:16"]},{id:"tiktok-photo",platform:"TikTok",type:"Photo",iconText:"T",iconTheme:"tiktok",ratios:["1:1","4:5","9:16"]},{id:"x-post",platform:"X",type:"Post",iconText:"X",iconTheme:"x",ratios:["1:1","16:9"]},{id:"linkedin-post",platform:"LinkedIn",type:"Post",iconText:"in",iconTheme:"linkedin",ratios:["1:1","16:9"]},{id:"pinterest-post",platform:"Pinterest",type:"Post",iconText:"P",iconTheme:"pinterest",ratios:["2:3","1:1"]},{id:"reddit-media",platform:"Reddit",type:"Media",iconText:"R",iconTheme:"reddit",ratios:["1:1","16:9"]},{id:"threads-post",platform:"Threads",type:"Post",iconText:"@",iconTheme:"threads",ratios:["1:1","4:5","16:9"]},{id:"telegram-post",platform:"Telegram",type:"Post",iconText:"TG",iconTheme:"telegram",ratios:["1:1","16:9"]}],Ci=["9:16","16:9","1:1","4:5","2:3","3:2"],xr={en:{tool:"Sticker",title:"Stickers",uploadTitle:"Upload sticker",uploadHint:"Click or drop an image here",uploadFormats:"Supports PNG, JPG, WEBP, SVG",libraryTitle:"Built-in sticker library",classicTitle:"Classic stickers",vibeTitle:"Vibe stickers",shapeTitle:"Shape stickers",defaultLabel:"Sticker",uploadedLabel:"Image sticker",emojiLabel:"Emoji sticker"},zh:{tool:"\u8D34\u7EB8",title:"\u8D34\u7EB8",uploadTitle:"\u81EA\u5B9A\u4E49\u672C\u5730\u56FE\u7247\u8D34\u7EB8",uploadHint:"\u70B9\u51FB\u6216\u62D6\u62FD\u56FE\u7247\u5230\u8FD9\u91CC",uploadFormats:"\u652F\u6301 PNG\u3001JPG\u3001WEBP\u3001SVG",libraryTitle:"\u5185\u7F6E\u7ECF\u5178\u8D34\u7EB8\u5E93",classicTitle:"\u7ECF\u5178\u8D34\u7EB8",vibeTitle:"\u6C1B\u56F4\u8D34\u7EB8",shapeTitle:"\u5F62\u72B6\u8D34\u7EB8",defaultLabel:"\u8D34\u7EB8",uploadedLabel:"\u56FE\u7247\u8D34\u7EB8",emojiLabel:"\u8868\u60C5\u8D34\u7EB8"},"zh-Hant":{tool:"\u8CBC\u7D19",title:"\u8CBC\u7D19",uploadTitle:"\u81EA\u8A02\u672C\u6A5F\u5716\u7247\u8CBC\u7D19",uploadHint:"\u9EDE\u64CA\u6216\u62D6\u62FD\u5716\u7247\u5230\u9019\u88E1",uploadFormats:"\u652F\u63F4 PNG\u3001JPG\u3001WEBP\u3001SVG",libraryTitle:"\u5167\u5EFA\u7D93\u5178\u8CBC\u7D19\u5EAB",classicTitle:"\u7D93\u5178\u8CBC\u7D19",vibeTitle:"\u6C1B\u570D\u8CBC\u7D19",shapeTitle:"\u5F62\u72C0\u8CBC\u7D19",defaultLabel:"\u8CBC\u7D19",uploadedLabel:"\u5716\u7247\u8CBC\u7D19",emojiLabel:"\u8868\u60C5\u8CBC\u7D19"}},No={en:{tool:"Color",title:"Color",filterTool:"Filter",filterTitle:"Filter",presets:"Filter presets",adjustments:"Adjustments",reset:"Reset",brightness:"Brightness",contrast:"Contrast",saturation:"Saturation",temperature:"Temperature",tint:"Tint",vibrance:"Vibrance",gamma:"Gamma",colorSection:"Color",toneSection:"Brightness",effectsSection:"Effects",highlights:"Highlights",shadows:"Shadows",whites:"Whites",blacks:"Blacks",lightSense:"Light Sense",sharpen:"Sharpen",clarity:"Clarity",grain:"Grain",fade:"Fade",vignette:"Vignette",presetNames:{none:"Normal",sepia:"Retro",cool:"Cold",warm:"Warm",vivid:"Cyber",bw:"B&W"}},zh:{tool:"\u8C03\u8272",title:"\u8C03\u8272",filterTool:"\u6EE4\u955C",filterTitle:"\u6EE4\u955C",presets:"\u6EE4\u955C\u9884\u8BBE",adjustments:"\u753B\u9762\u5FAE\u8C03",reset:"\u91CD\u7F6E",brightness:"\u4EAE\u5EA6",contrast:"\u5BF9\u6BD4\u5EA6",saturation:"\u9971\u548C\u5EA6",temperature:"\u8272\u6E29",tint:"\u8272\u8C03",vibrance:"\u81EA\u7136\u9971\u548C\u5EA6",gamma:"Gamma",colorSection:"\u8272\u5F69",toneSection:"\u660E\u5EA6",effectsSection:"\u6548\u679C",highlights:"\u9AD8\u5149",shadows:"\u9634\u5F71",whites:"\u767D\u8272",blacks:"\u9ED1\u8272",lightSense:"\u5149\u611F",sharpen:"\u9510\u5316",clarity:"\u6E05\u6670",grain:"\u9897\u7C92",fade:"\u892A\u8272",vignette:"\u6697\u89D2",presetNames:{none:"\u539F\u753B (Normal)",sepia:"\u590D\u53E4 (Retro)",cool:"\u51B7\u8272 (Cold)",warm:"\u6696\u9633 (Warm)",vivid:"\u8D5B\u535A (Cyber)",bw:"\u9ED1\u767D (B&W)"}},"zh-Hant":{tool:"\u8ABF\u8272",title:"\u8ABF\u8272",filterTool:"\u6FFE\u93E1",filterTitle:"\u6FFE\u93E1",presets:"\u6FFE\u93E1\u9810\u8A2D",adjustments:"\u756B\u9762\u5FAE\u8ABF",reset:"\u91CD\u8A2D",brightness:"\u4EAE\u5EA6",contrast:"\u5C0D\u6BD4\u5EA6",saturation:"\u98FD\u548C\u5EA6",temperature:"\u8272\u6EAB",tint:"\u8272\u8ABF",vibrance:"\u81EA\u7136\u98FD\u548C\u5EA6",gamma:"Gamma",colorSection:"\u8272\u5F69",toneSection:"\u660E\u5EA6",effectsSection:"\u6548\u679C",highlights:"\u9AD8\u5149",shadows:"\u9670\u5F71",whites:"\u767D\u8272",blacks:"\u9ED1\u8272",lightSense:"\u5149\u611F",sharpen:"\u92B3\u5316",clarity:"\u6E05\u6670",grain:"\u9846\u7C92",fade:"\u892A\u8272",vignette:"\u6697\u89D2",presetNames:{none:"\u539F\u756B (Normal)",sepia:"\u5FA9\u53E4 (Retro)",cool:"\u51B7\u8272 (Cold)",warm:"\u6696\u967D (Warm)",vivid:"\u8CFD\u535A (Cyber)",bw:"\u9ED1\u767D (B&W)"}}};function Ni(e){const t=Xt(e);return{...xr.en,...xr[t]??{}}}function Ao(e){const t=Xt(e),n=No[t]??{};return{...No.en,...n,presetNames:{...No.en.presetNames,...n.presetNames??{}}}}function Cn(e,t,n="rgba(255,255,255,0.16)"){let r="";return e==="triangle"?r=`<polygon points="128,28 224,220 32,220" fill="${t}" stroke="${n}" stroke-width="8" stroke-linejoin="round"/>`:e==="circle"?r=`<circle cx="128" cy="128" r="94" fill="${t}" stroke="${n}" stroke-width="8"/>`:e==="square"?r=`<rect x="40" y="40" width="176" height="176" rx="40" fill="${t}" stroke="${n}" stroke-width="8"/>`:e==="diamond"?r=`<polygon points="128,24 224,128 128,232 32,128" fill="${t}" stroke="${n}" stroke-width="8" stroke-linejoin="round"/>`:e==="star"?r=`<polygon points="128,24 154,92 228,96 170,142 188,220 128,176 68,220 86,142 28,96 102,92" fill="${t}" stroke="${n}" stroke-width="8" stroke-linejoin="round"/>`:e==="heart"?r=`<path d="M128 220c-7-7-18-16-30-27C64 165 38 141 38 102c0-28 20-50 48-50 18 0 33 10 42 24 9-14 24-24 42-24 28 0 48 22 48 50 0 39-26 63-60 91-12 11-23 20-30 27Z" fill="${t}" stroke="${n}" stroke-width="8" stroke-linejoin="round"/>`:r=`<rect x="40" y="40" width="176" height="176" rx="40" fill="${t}" stroke="${n}" stroke-width="8"/>`,`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">${r}</svg>`)}`}function Ai(e){return[{id:"classic",title:e.classicTitle,items:[{id:"heart-eyes",emoji:"\u{1F60D}",label:`${e.emojiLabel} 1`},{id:"joy",emoji:"\u{1F602}",label:`${e.emojiLabel} 2`},{id:"grin",emoji:"\u{1F603}",label:`${e.emojiLabel} 3`},{id:"pray",emoji:"\u{1F64F}",label:`${e.emojiLabel} 4`},{id:"thumbs-up",emoji:"\u{1F44D}",label:`${e.emojiLabel} 5`},{id:"hundred",emoji:"\u{1F4AF}",label:`${e.emojiLabel} 6`},{id:"cat-smile",emoji:"\u{1F63A}",label:`${e.emojiLabel} 7`},{id:"cat-happy",emoji:"\u{1F638}",label:`${e.emojiLabel} 8`},{id:"paw",emoji:"\u{1F43E}",label:`${e.emojiLabel} 9`},{id:"fish",emoji:"\u{1F41F}",label:`${e.emojiLabel} 10`}]},{id:"vibe",title:e.vibeTitle,items:[{id:"sparkles",emoji:"\u2728",label:`${e.emojiLabel} 5`},{id:"heart",emoji:"\u{1F497}",label:`${e.emojiLabel} 6`},{id:"fire",emoji:"\u{1F525}",label:`${e.emojiLabel} 7`},{id:"party",emoji:"\u{1F389}",label:`${e.emojiLabel} 8`}]},{id:"shape",title:e.shapeTitle,items:[{id:"triangle",src:Cn("triangle","#f97316"),label:"Triangle"},{id:"circle",src:Cn("circle","#22c55e"),label:"Circle"},{id:"square",src:Cn("square","#3b82f6"),label:"Square"},{id:"diamond",src:Cn("diamond","#8b5cf6"),label:"Diamond"},{id:"star",src:Cn("star","#facc15"),label:"Star"},{id:"heart-shape",src:Cn("heart","#fb7185"),label:"Heart"}]}]}function Oi(e){const t=Xt(e),n={...vr.en,...vr[t]??{}};return n.searchFont||(n.searchFont=t==="zh-Hant"?"\u641C\u5C0B\u5B57\u9AD4...":t==="zh"?"\u641C\u7D22\u5B57\u4F53...":"Search font..."),n.loadingFonts||(n.loadingFonts=t==="zh-Hant"?"\u6B63\u5728\u8B80\u53D6\u5B57\u9AD4...":t==="zh"?"\u6B63\u5728\u8BFB\u53D6\u5B57\u4F53...":"Loading fonts..."),n.noFonts||(n.noFonts=t==="zh-Hant"?"\u627E\u4E0D\u5230\u5B57\u9AD4":t==="zh"?"\u6CA1\u6709\u627E\u5230\u5B57\u4F53":"No fonts found"),n.sampleText||(n.sampleText=Uo),n}function Hi(e){const t=Xt(e);return{...hr.en,...hr[t]??{}}}const br={en:{tool:"Annotate",title:"Annotate",hint:"Configure the annotation tools here.",tools:"Tools",color:"Color",custom:"Custom",width:"Line width",reset:"Reset",brush:"Brush",eraser:"Eraser",line:"Line",arrow:"Arrow",rectangle:"Rectangle",ellipse:"Ellipse"},zh:{tool:"\u6807\u6CE8",title:"\u6807\u6CE8",hint:"\u5728\u8FD9\u91CC\u914D\u7F6E\u6807\u6CE8\u5DE5\u5177\u7684\u6837\u5F0F\u53C2\u6570\u3002",tools:"\u5DE5\u5177",color:"\u989C\u8272",custom:"\u81EA\u5B9A\u4E49",width:"\u7EBF\u5BBD",reset:"\u91CD\u7F6E",brush:"\u753B\u7B14",eraser:"\u6A61\u76AE",line:"\u76F4\u7EBF",arrow:"\u7BAD\u5934",rectangle:"\u77E9\u5F62",ellipse:"\u692D\u5706"},"zh-Hant":{tool:"\u6A19\u8A3B",title:"\u6A19\u8A3B",hint:"\u5728\u9019\u88E1\u8A2D\u5B9A\u6A19\u8A3B\u5DE5\u5177\u7684\u6A23\u5F0F\u53C3\u6578\u3002",tools:"\u5DE5\u5177",color:"\u984F\u8272",custom:"\u81EA\u8A02",width:"\u7DDA\u5BEC",reset:"\u91CD\u8A2D",brush:"\u756B\u7B46",eraser:"\u6A61\u76AE",line:"\u76F4\u7DDA",arrow:"\u7BAD\u982D",rectangle:"\u77E9\u5F62",ellipse:"\u6A62\u5713"}};function zi(e){const t=Xt(e);return br[t]??br.en}const gr=[{key:"brush"},{key:"eraser"},{key:"line"},{key:"arrow"},{key:"rectangle"},{key:"ellipse"}],jn=2,Yn=24,Nn=14,ja=["pen","line","arrow","rect","ellipse"],Pi={brush:"pen",line:"line",arrow:"arrow",rectangle:"rect",ellipse:"ellipse"},yr=["#ffffff","#ff4d4f","#ff7a45","#ffa940","#fadb14","#95de64","#52c41a","#13c2c2","#40a9ff","#2f54eb","#7c7cf0","#eb2f96","#722ed1","#000000"],sn={tool:"brush",color:"#ff4d4f",width:4};function Ii(e){switch(e){case"eraser":return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M7.2 15.8 14.9 8a1.8 1.8 0 0 1 2.6 0l2.6 2.6a1.8 1.8 0 0 1 0 2.6l-5.3 5.3a2.4 2.4 0 0 1-1.7.7h-4a2.4 2.4 0 0 1-1.7-.7l-1-1a1.2 1.2 0 0 1 0-1.7Z" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"/><path d="M13.1 19.2h6.2" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/></svg>';case"line":return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M5 19 19 5" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/></svg>';case"arrow":return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M5 16 15 6" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/><path d="M10.5 6H15v4.5" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/></svg>';case"rectangle":return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="5.5" y="5.5" width="13" height="13" rx="1.8" fill="none" stroke="currentColor" stroke-width="1.8"/></svg>';case"ellipse":return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><ellipse cx="12" cy="12" rx="6.6" ry="6.6" fill="none" stroke="currentColor" stroke-width="1.8"/></svg>';default:return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m8.2 15.8 7.9-7.9a1.9 1.9 0 0 1 2.7 2.7l-7.9 7.9" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/><path d="M7.5 16.5c-.5 2.5-2.4 3.8-3.8 4 .2-1.5 1.5-3.3 4-3.8Z" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/></svg>'}}function Ri(){return'<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m5 19 3.9-1 9.2-9.2a1.8 1.8 0 0 0 0-2.6l-.3-.3a1.8 1.8 0 0 0-2.6 0L6 15.1 5 19Z" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/><path d="m13.7 7.3 3 3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><path d="m5 19 3.3-3.3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>'}function wr(e,t){switch(e?.type){case"pen":return t.brush;case"line":return t.line;case"arrow":return t.arrow;case"rect":return t.rectangle;case"ellipse":return t.ellipse;default:return t.tool}}function Ya(e){switch(e?.type){case"pen":return"brush";case"line":return"line";case"arrow":return"arrow";case"rect":return"rectangle";case"ellipse":return"ellipse";default:return sn.tool}}function no(e=sn){const t=gr.some(r=>r.key===e?.tool)?e.tool:sn.tool,n=Er(e?.color);return{tool:t,color:n,width:ue(Math.round(Number(e?.width)||sn.width),jn,Yn)}}function Oo(e,t){return e?.tool===t?.tool&&e?.color===t?.color&&Number(e?.width)===Number(t?.width)}function kr(e){return Oo(e,sn)}function Fi(e){return`${ue(Math.round(Number(e)||sn.width),jn,Yn)}px`}function Er(e){const t=String(e??"").trim().toLowerCase();return/^#?[0-9a-f]{3}$/.test(t)?`#${t.replace("#","").split("").map(r=>`${r}${r}`).join("")}`:/^#?[0-9a-f]{6}$/.test(t)?`#${t.replace("#","")}`:sn.color}function oo(e){const t=Er(e);return{r:Number.parseInt(t.slice(1,3),16),g:Number.parseInt(t.slice(3,5),16),b:Number.parseInt(t.slice(5,7),16)}}function ro(e,t,n){return`#${[e,t,n].map(r=>ue(Math.round(Number(r)||0),0,255).toString(16).padStart(2,"0")).join("")}`}function Ho(e,t,n){const r=ue(Number(e)||0,0,255)/255,i=ue(Number(t)||0,0,255)/255,s=ue(Number(n)||0,0,255)/255,u=Math.max(r,i,s),p=Math.min(r,i,s),v=u-p;let w=0;return v>0&&(u===r?w=60*((i-s)/v%6):u===i?w=60*((s-r)/v+2):w=60*((r-i)/v+4)),w<0&&(w+=360),{h:w,s:u<=0?0:v/u,v:u}}function zo(e,t,n){const r=((Number(e)||0)%360+360)%360,i=ue(Number(t)||0,0,1),s=ue(Number(n)||0,0,1),u=s*i,p=r/60,v=u*(1-Math.abs(p%2-1));let w=0,z=0,te=0;p>=0&&p<1?(w=u,z=v):p<2?(w=v,z=u):p<3?(z=u,te=v):p<4?(z=v,te=u):p<5?(w=v,te=u):(w=u,te=v);const S=s-u;return{r:Math.round((w+S)*255),g:Math.round((z+S)*255),b:Math.round((te+S)*255)}}function Bi(e){const t=zo(e,1,1);return ro(t.r,t.g,t.b)}const $i=["none","sepia","cool","warm","vivid","bw"],Va=["brightness","contrast","saturation","temperature","tint","vibrance","gamma"],An={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},Po=Object.keys(An);function Sr(e){return[{title:e.colorSection,items:[{key:"temperature",label:e.temperature,format:"offset",min:-1,max:1},{key:"tint",label:e.tint,format:"offset",min:-1,max:1},{key:"saturation",label:e.saturation,format:"percent",min:-1,max:1},{key:"vibrance",label:e.vibrance,format:"offset",min:-1,max:1},{key:"gamma",label:e.gamma,format:"percent",min:-1,max:1}]},{title:e.toneSection,items:[{key:"brightness",label:e.brightness,format:"percent",min:-1,max:1},{key:"contrast",label:e.contrast,format:"percent",min:-1,max:1},{key:"highlights",label:e.highlights,format:"offset",min:-1,max:1},{key:"shadows",label:e.shadows,format:"offset",min:-1,max:1},{key:"whites",label:e.whites,format:"offset",min:-1,max:1},{key:"blacks",label:e.blacks,format:"offset",min:-1,max:1},{key:"lightSense",label:e.lightSense,format:"offset",min:-1,max:1}]},{title:e.effectsSection,items:[{key:"sharpen",label:e.sharpen,format:"amount",min:0,max:1},{key:"clarity",label:e.clarity,format:"amount",min:0,max:1},{key:"grain",label:e.grain,format:"amount",min:0,max:1},{key:"fade",label:e.fade,format:"amount",min:0,max:1},{key:"vignette",label:e.vignette,format:"amount",min:0,max:1}]}]}function Di(e){if(typeof e.applyMut=="function"){e.applyMut(t=>({...t,filters:{...t.filters,...An}}));return}e.setFilters({...An})}function _i(e){const t=new Map(jr.map(n=>[n.id,n]));return $i.map(n=>{if(n==="none")return{id:"",css:"",label:e.presetNames.none};const r=t.get(n);return r?{...r,label:e.presetNames[n]??r.label??n}:null}).filter(Boolean)}function Lr(e,t="percent"){if(t==="offset"){const n=Math.round((Number(e)||0)*100);return n>0?`+${n}`:`${n}`}return t==="amount"?`${Math.round((Number(e)||0)*100)}%`:`${Math.round((1+(Number(e)||0))*100)}%`}function Io(e){return[e?.textContent,e?.getAttribute?.("title"),e?.getAttribute?.("aria-label")].filter(Boolean).join(" ").trim().toLowerCase()}function Ro(e){return e instanceof HTMLButtonElement?(e.dataset.meTrimHidden="true",e):e??null}function ji(e){return e instanceof HTMLButtonElement?(e.dataset.meAnnotateHidden="true",e):e??null}function io(e){const t=["trim","timeline","\u526A\u8F91","\u65F6\u95F4\u8F74"];return Ro(e.find(n=>{const r=Io(n);return t.some(i=>r.includes(i))})??e[0]??null)}function Yi(e){const t=["annotate","annotation","markup","draw","doodle","\u6807\u6CE8","\u5857\u9E26","\u5857\u9D09"];return ji(e.find(n=>{const r=Io(n);return t.some(i=>r.includes(i))})??null)}function Tr(e,t,n){try{const r=document.createElement("canvas");r.width=208,r.height=118;const i=r.getContext("2d");if(!i)return"";const s=t/n,u=r.width/r.height;let p=0,v=0,w=t,z=n;return s>u?(w=n*u,p=(t-w)/2):s<u&&(z=t/u,v=(n-z)/2),i.drawImage(e,p,v,w,z,0,0,r.width,r.height),r.toDataURL("image/jpeg",.82)}catch{return""}}function Vi(e){const t=e.querySelector(".me-video-canvas-stage canvas");if(t instanceof HTMLCanvasElement&&t.width>8&&t.height>8)return Tr(t,t.width,t.height);const n=e.querySelector("video");return n instanceof HTMLVideoElement&&n.videoWidth>8&&n.videoHeight>8?Tr(n,n.videoWidth,n.videoHeight):""}function Xi(e){const t=String(e??"").split(":").map(i=>Number(i));if(t.length!==2)return null;const[n,r]=t;return!(n>0)||!(r>0)?null:n/r}function ao(e,t=1080){const n=Xi(e)??1;return n>=1?{w:Math.max(2,Vt(t*n)),h:Math.max(2,Vt(t))}:{w:Math.max(2,Vt(t)),h:Math.max(2,Vt(t/n))}}function qi(){return Mi.map(e=>({...e,ratios:e.ratios.map(t=>({ratio:t,...ao(t)}))}))}function Mr(e){return`${e.platform} ${e.type}`}function Wi(e){switch(e.id){case"facebook-post":return"FB Post";case"facebook-story":return"FB Story";case"instagram-post":return"IG Post";case"instagram-story":return"IG Story";case"tiktok-photo":return"TikTok";case"x-post":return"X Post";case"linkedin-post":return"LinkedIn";case"pinterest-post":return"Pinterest";case"reddit-media":return"Reddit";case"threads-post":return"Threads";case"telegram-post":return"Telegram";default:return Mr(e)}}function Ki(e){return Ci.map(t=>{const n=ao(t),r=e.filter(i=>i.ratios.some(s=>s.ratio===t));return r.length?{ratio:t,...n,groups:r,hint:r.map(i=>Mr(i)).join(" / "),tags:r.map(i=>Wi(i))}:null}).filter(Boolean)}function On(e){return`${Math.max(2,Vt(e?.w??0))} x ${Math.max(2,Vt(e?.h??0))} px`}function Cr(e){const t=e?.canvas??{w:1080,h:1920};return jo(t,{...e,scale:void 0})}function Vn(e){return e?.scale?{w:Math.max(2,Vt(e.scale.width)),h:Math.max(2,Vt(e.scale.height))}:Cr(e)}function Fo(e){return e==="contain"||e==="force"?e:"cover"}function pn(e,t){const n=Number(e),r=Number.isFinite(n)&&n>0?n:t;return Math.max(2,Vt(r||2))}function Ui(e,t){const n=Math.max(2,Vt(t?.w??0)),r=Math.max(2,Vt(t?.h??0));return e.find(i=>Math.abs(i.w-n)<=2&&Math.abs(i.h-r)<=2)??null}function Gi(e,t){switch(Fo(t)){case"contain":return e.containHint;case"force":return e.forceHint;default:return e.coverHint}}function so(e,t){e.replaceChildren();for(const n of t){const r=document.createElement("option");r.value=n.value,r.textContent=n.label,e.appendChild(r)}}function Xn(e=[],t=[]){const n=typeof Intl<"u"?new Intl.Collator(void 0,{sensitivity:"base",numeric:!0}):null,r=new Set;return[...e,...t].map(i=>String(i??"").trim()).filter(Boolean).filter(i=>{const s=i.toLowerCase();return r.has(s)?!1:(r.add(s),!0)}).sort((i,s)=>n?n.compare(i,s):i.localeCompare(s))}function Bo(e){return`"${String(e??"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}", ${Wn}`}function lo(e){const t=String(e??"").trim();return qr[t]||t}function $o(e){const t=String(e??"").trim(),n=lo(t);return n&&n!==t?`${n} (${t})`:t}function Zi(e){const t=String(e??"").trim();return`${t} ${lo(t)} ${$o(t)}`.toLowerCase()}function Nr(e){return/[\u3400-\u9fff\uf900-\ufaff]/.test(String(e??""))}function Ji(e){const t=String(e??"").trim().toLowerCase();return t?Wr.some(n=>t.includes(n))?!0:Nr(lo(e)):!1}function Qi(e,t=!1){const n=Xn(e);if(!t)return n;const r=[],i=[];for(const s of n)Ji(s)?r.push(s):i.push(s);return[...r,...i]}async function ea(){return Kn||(Kn=(async()=>{const e=Xn(Xo);if(typeof window>"u"||typeof window.queryLocalFonts!="function")return e;try{const n=(await window.queryLocalFonts()).map(r=>r?.family||r?.fullName||"").filter(Boolean);return Xn(n,e)}catch{return e}})(),Kn)}function ta(e){const t=document.createElement("div");t.className="me-video-font-picker";const n=document.createElement("button");n.type="button",n.className="me-video-font-picker-trigger";const r=document.createElement("span");r.className="me-video-font-picker-label";const i=document.createElement("span");i.className="me-video-font-picker-chevron",i.textContent="v",n.append(r,i);const s=document.createElement("div");s.className="me-video-font-picker-dropdown",s.hidden=!0;const u=document.createElement("label");u.className="me-video-font-picker-search";const p=document.createElement("span");p.className="me-video-font-picker-search-icon",p.innerHTML='<svg viewBox="0 0 16 16" fill="none" aria-hidden="true"><circle cx="7" cy="7" r="4.5" stroke="currentColor" stroke-width="1.4"></circle><path d="M10.5 10.5L14 14" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"></path></svg>';const v=document.createElement("input");v.type="search",v.className="me-video-font-picker-search-input",v.placeholder=e.searchFont,v.autocomplete="off",v.spellcheck=!1;const w=document.createElement("div");w.className="me-video-font-picker-list",u.append(p,v),s.append(u,w),t.append(n,s);let z=!1,te=!1,S=!1,B="Arial",V=Xn(Xo),ie=!1;const J=typeof requestAnimationFrame=="function"?requestAnimationFrame:j=>setTimeout(j,0);function oe(){B||(B="Arial"),V=Xn(V,[B])}function le(j){const re=document.createElement("div");return re.className="me-video-font-picker-message",re.textContent=j,re}function xe(j){const re=document.createElement("button");re.type="button",re.className="me-video-font-picker-option",j===B&&re.classList.add("is-active"),re.dataset.family=j;const I=document.createElement("span");I.className="me-video-font-picker-option-name",I.textContent=$o(j),I.style.fontFamily=Bo(j);const D=document.createElement("span");return D.className="me-video-font-picker-option-preview",D.textContent=e.sampleText||Uo,D.style.fontFamily=Bo(j),re.append(I,D),re.addEventListener("click",()=>{b(j),t.dispatchEvent(new CustomEvent("fontchange",{detail:{value:j}})),se(!1),n.focus()}),re}function ae(){const j=B||"Arial";r.textContent=lo(j),r.style.fontFamily=Bo(B||"Arial"),n.title=$o(j),n.disabled=te}function be(){if(w.replaceChildren(),!z)return;if(S){w.appendChild(le(e.loadingFonts));return}oe();const j=String(v.value??"").trim().toLowerCase(),re=Qi(V.filter(I=>!j||Zi(I).includes(j)),ie);if(!re.length){w.appendChild(le(e.noFonts));return}for(const I of re)w.appendChild(xe(I))}function se(j){te&&j||(z=!!j,t.classList.toggle("is-open",z),s.hidden=!z,z?J(()=>{v.focus(),v.select()}):v.value="",be())}async function k(){if(!S){S=!0,be();try{V=await ea(),oe()}finally{S=!1,be()}}}function b(j,{silent:re=!1}={}){B=String(j??"").trim()||"Arial",oe(),ae(),!re&&z&&be()}function _(){return B||"Arial"}function h(j){te=!!j,te&&se(!1),ae(),v.disabled=te}function y(j){const re=Nr(j);ie!==re&&(ie=re,z&&be())}function N(j){z&&(t.contains(j.target)||se(!1))}return n.addEventListener("click",async()=>{const j=!z;se(j),j&&await k()}),v.addEventListener("input",()=>be()),document.addEventListener("pointerdown",N,!0),b("Arial",{silent:!0}),h(!1),{wrap:t,setValue:b,getValue:_,setDisabled:h,setContextText:y,destroy(){document.removeEventListener("pointerdown",N,!0)}}}function na(e){const t=String(e??"").trim().toLowerCase();return/^#([0-9a-f]{3}|[0-9a-f]{6})$/.test(t)?t.length===7?t:`#${t.slice(1).split("").map(n=>`${n}${n}`).join("")}`:null}function vn(e,t="#ffffff"){const n=String(e??"").trim();if(!n)return t;if(n.toLowerCase()==="transparent")return"transparent";const r=na(n);if(r)return r;const i=n.match(/^rgba?\(([^)]+)\)$/i);if(i){const s=i[1].split(",").slice(0,3).map(u=>ue(Math.round(Number(u.trim())||0),0,255));if(s.length===3)return`#${s.map(u=>u.toString(16).padStart(2,"0")).join("")}`}return t}function Tt(e,t,n=""){const r=document.createElement("div");r.className=`me-video-text-row${n?` ${n}`:""}`;const i=document.createElement("label");return i.className="me-video-text-row-label",i.textContent=e,r.append(i,t),r}function Kt(e){const t=document.createElement("section");t.className="me-video-text-section";const n=document.createElement("h4");n.className="me-video-text-section-title",n.textContent=e;const r=document.createElement("div");return r.className="me-video-text-section-body",t.append(n,r),{section:t,body:r,title:n}}function co({allowTransparent:e=!1,fallback:t="#ffffff",transparentLabel:n="Transparent"}={}){const r=document.createElement("div");r.className="me-video-text-color-control";const i=document.createElement("input");i.type="color",i.className="me-video-text-color-swatch",i.value=vn(t,"#ffffff");const s=document.createElement("input");s.type="text",s.className="me-video-text-input me-video-text-color-text",s.spellcheck=!1,r.append(i,s);let u=null;e&&(u=document.createElement("button"),u.type="button",u.className="me-video-text-toggle me-video-text-transparent-toggle",u.textContent=n,r.appendChild(u));function p(){return r.dataset.transparent==="true"}function v(S){r.dataset.transparent=S?"true":"false",u?.classList.toggle("is-active",S),i.disabled=S,S?s.value="transparent":(!s.value||s.value==="transparent")&&(s.value=i.value||vn(t,"#ffffff"))}function w(S){if(e&&String(S??"").trim().toLowerCase()==="transparent"){v(!0);return}const B=vn(S,vn(t,"#ffffff"));i.value=B==="transparent"?vn(t,"#ffffff"):B,s.value=B==="transparent"?"transparent":B,e&&v(B==="transparent")}function z(){return e&&p()?"transparent":vn(s.value||i.value,i.value||vn(t,"#ffffff"))}function te(S){i.disabled=S||e&&p(),s.disabled=S,u&&(u.disabled=S)}return w(t),{wrap:r,swatch:i,text:s,transparentButton:u,setTransparent:v,setValue:w,getValue:z,setDisabled:te}}function uo(e){const t=e.querySelector(".me-video-workspace");if(!t)return null;let n=t.querySelector(".me-video-inspector-rail");return n||(n=document.createElement("aside"),n.className="me-video-inspector-rail",n.hidden=!0,t.appendChild(n)),n}function rn(e,t){const n=uo(e);return n?(t.parentElement!==n&&n.appendChild(t),n):null}function Pt(e){const t=uo(e);if(!t)return;const n=[...t.children].some(r=>r instanceof HTMLElement&&!r.hidden);t.hidden=!n}function Ar(e,t,n){const r=uo(e);if(!(!r||!(t instanceof HTMLElement))){for(const i of r.children)if(!(!(i instanceof HTMLElement)||i===t)){if(n){i.dataset.meInspectorPrevHidden||(i.dataset.meInspectorPrevHidden=i.hidden?"true":"false"),i.hidden=!0;continue}Object.prototype.hasOwnProperty.call(i.dataset,"meInspectorPrevHidden")&&(i.hidden=i.dataset.meInspectorPrevHidden==="true",delete i.dataset.meInspectorPrevHidden)}}}function Or(e){return new Set(String(e??"").split(/\s+/).map(t=>t.trim()).filter(Boolean))}function oa(e){return[...e].join(" ").trim()}function ra(e,t,n,r){Qt(),kn();const i=r(),s=Zo(i),u=s.text,p=Oi(i),v=document.createElement("div");v.className="me-video-text-panel",v.hidden=!0,e.appendChild(v);const w=document.createElement("div");w.className="me-video-text-toolbar";const z=document.createElement("strong");z.textContent=u.tool;const te=Yt(u.addText),S=Yt(u.moveOnCanvas),B=Yt(u.duplicate),V=Yt(u.delete);V.classList.add("me-video-text-danger");const ie=Yt(u.close);w.append(z);const J=document.createElement("div");J.className="me-video-text-list";const oe=document.createElement("div");oe.className="me-video-text-empty",oe.textContent=u.empty;const le=document.createElement("textarea");le.className="me-video-text-input me-video-text-textarea",le.placeholder=u.placeholder;const xe=document.createElement("select");xe.className="me-video-text-select",so(xe,[{value:"none",label:p.none},{value:"heading",label:u.heading},{value:"subtitle",label:u.subtitle},{value:"label",label:u.label}]);const ae=ta(p),be=document.createElement("select");be.className="me-video-text-select",so(be,Ti);const se=document.createElement("input");se.type="number",se.min="8",se.max="320",se.step="1",se.className="me-video-text-input";const k=co({fallback:"#ffffff"}),b=co({allowTransparent:!0,fallback:"#111111",transparentLabel:p.transparent}),_=document.createElement("div");_.className="me-video-text-inline";const h=[{value:"left",label:p.alignLeft},{value:"center",label:p.alignCenter},{value:"right",label:p.alignRight}].map(m=>{const H=document.createElement("button");return H.type="button",H.className="me-video-text-align",H.dataset.align=m.value,H.textContent=m.label,_.appendChild(H),{value:m.value,button:H}}),y=document.createElement("div");y.className="me-video-text-toggle-group";const N=document.createElement("button");N.type="button",N.className="me-video-text-toggle is-italic",N.title=p.italic,N.textContent="I";const j=document.createElement("button");j.type="button",j.className="me-video-text-toggle is-underline",j.title=p.underline,j.textContent="U";const re=document.createElement("button");re.type="button",re.className="me-video-text-toggle is-strike",re.title=p.strike,re.textContent="S",y.append(N,j,re);const I=document.createElement("select");I.className="me-video-text-select",so(I,[{value:"none",label:p.caseNone},{value:"uppercase",label:p.uppercase},{value:"lowercase",label:p.lowercase},{value:"capitalize",label:p.capitalize}]);const D=document.createElement("div");D.className="me-video-text-slider-row";const K=document.createElement("input");K.type="number",K.min="0",K.max="100",K.step="1",K.className="me-video-text-input";const M=document.createElement("input");M.type="range",M.min="0",M.max="100",M.step="1",D.append(K,M);const X=document.createElement("select");X.className="me-video-text-select",so(X,[{value:"none",label:p.none}]);const Q=co({fallback:"#000000"}),ce=document.createElement("input");ce.type="number",ce.min="0",ce.max="32",ce.step="1",ce.className="me-video-text-input";const W=co({fallback:"#000000"}),U=document.createElement("input");U.type="number",U.min="-80",U.max="80",U.step="1",U.className="me-video-text-input";const T=document.createElement("input");T.type="number",T.min="-80",T.max="80",T.step="1",T.className="me-video-text-input";const A=document.createElement("input");A.type="number",A.min="0",A.max="80",A.step="1",A.className="me-video-text-input";const de=document.createElement("div");de.className="me-video-text-section-body",de.append(Tt(u.content,le,"is-area"),Tt(p.preset,xe));const Ne=Kt(p.styles);Ne.body.append(Tt(u.font,ae.wrap),Tt(u.weight,be),Tt(p.size,se),Tt(u.color,k.wrap),Tt(p.fill,b.wrap),Tt(u.align,_),Tt(p.decoration,y),Tt(p.case,I),Tt(u.opacity,D));const R=Kt(p.animations);R.body.append(Tt(p.animation,X));const ee=Kt(p.fontStroke);ee.body.append(Tt(u.color,Q.wrap),Tt(p.size,ce));const Y=Kt(p.fontShadow);Y.body.append(Tt(u.color,W.wrap),Tt(p.x,U),Tt(p.y,T),Tt(p.blur,A)),v.append(w,oe,de,Ne.section,R.section,ee.section,Y.section);let G=null,pe=null,qe=null,He=null,Je=null,Ge=null,Ye=null,dt=null,rt=!1,ze=null,it=!1,xt=!1;const wt="text",ke=typeof requestAnimationFrame=="function"?requestAnimationFrame:m=>setTimeout(m,16),Re=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>me()),Me=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>me()),et=[{key:"tl",x:0,y:0},{key:"tm",x:.5,y:0},{key:"tr",x:1,y:0},{key:"mr",x:1,y:.5},{key:"br",x:1,y:1},{key:"bm",x:.5,y:1},{key:"bl",x:0,y:1},{key:"ml",x:0,y:.5}],tt={key:"rotate",x:.5,y:0};function ht(){Promise.resolve().then(()=>{xt=!1;const m=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,m-1)})}function gt(m){xt=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return m()}finally{ht()}}function me(){it||(it=!0,ke(()=>{it=!1,Ke()}))}function Le(m){const H=!!m;if(H===rt){Ke();return}rt=H,rt&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:wt}})),Ke()}function Ve(){return pe?[...pe.querySelectorAll("button")].filter(m=>m!==G&&!m.classList.contains("me-video-text-tool")):[]}function Ze(){Ve()[0]?.click()}function at(){if(!G)return;const m=Rn(n());G.dataset.theme=m}function Et(){rn(e,v),Pt(e)}function St(){v.hidden=!rt,G&&G.classList.toggle("is-active",rt),Et()}function Rt(m){if(!m.length){ze=null;return}const H=To(e,t.getState());ze=H.length?H[H.length-1]:null}function ut(){const m=t.getState().overlays??[];if(ze==null)return null;const H=m[ze];return H?.type==="text"?H:null}function It(){return Tn(t)}function Lt(){return yn(e)}function jt(){if(!t.history?.present)return;const m=Lt(),H=Number(t.history.present.__mePreviewTimelineTime);Math.abs((Number.isFinite(H)?H:-1)-m)<.001||(t.history={...t.history,present:{...t.history.present,__mePreviewTimelineTime:m}},typeof t.emit=="function"&&t.emit())}function At(m,H,q={}){const d=(t.getState().overlays??[])[m];!d||d.type!=="text"||t.updateOverlay(m,Jt(d,It(),H),q)}function Mt(m){if(typeof t.applyMut=="function"){t.applyMut(q=>({...q,overlays:[...on(q.overlays),{...m,timelineTrack:0}]}));return}const H=on(t.getState().overlays);t.commit?.({overlays:[...H,{...m,timelineTrack:0}]})}function mt(m,H={}){if(ze==null)return;const q=H.preservePreset||Object.prototype.hasOwnProperty.call(m,"textPreset")?m:{...m,textPreset:"none"};t.updateOverlay(ze,q)}function Ut(m="heading"){const H=It();let q=ue(Lt(),0,Math.max(0,H-je)),l=Math.min(H,q+qt);l-q<je&&(q=ue(H-qt,0,Math.max(0,H-je)),l=Math.max(q+je,H));const d={...tr(t,s,m),...Jt(null,H,{startAt:q,endAt:l,timelineTrack:0})};Mt(d);const o=t.getState().overlays??[];ze=o.length?o.length-1:null,ze!=null&&bt(e,"text",[ze]),Ze(),Le(!0)}function E(){const m=t.getState(),H=Mo(m.overlays??[],To(e,m));H.changed&&(t.commit({overlays:H.overlays}),ze=H.selection.length?H.selection[H.selection.length-1]:null,bt(e,"text",H.selection),Ke())}function F(){const m=t.getState(),H=Co(m.overlays??[],To(e,m));H.changed&&(t.commit({overlays:H.overlays}),ze=null,bt(e,"text",[]),Ke())}function Z(m){if(!ut()){Ut(m);return}const q=tr(t,s,m);mt({text:q.text,fontSize:q.fontSize,width:q.width,fontWeight:q.fontWeight,fontFamily:q.fontFamily,fontStyle:q.fontStyle,textAlign:q.textAlign,color:q.color,backgroundColor:q.backgroundColor,borderColor:q.borderColor,borderWidth:q.borderWidth,paddingX:q.paddingX,paddingY:q.paddingY,lineHeight:q.lineHeight,boxShadow:q.boxShadow?{...q.boxShadow}:void 0,textDecoration:q.textDecoration??"",textTransform:q.textTransform,animation:"none",textPreset:m},{preservePreset:!0})}function Te(){const{timelineInner:m,timelineHost:H}=$n(e,t.getState());if(!m||!H){He?.remove(),He=null,Re&&Je&&(Re.unobserve(Je),Je=null),qe=null;return}qe=m,(!He||!He.isConnected||He.parentElement!==H)&&(He?.remove(),He=document.createElement("div"),He.className="me-video-text-timeline me-video-overlay-timeline me-video-text-overlay-layer");for(const q of[...H.children])q!==He&&q instanceof HTMLElement&&q.classList.contains("me-video-text-overlay-layer")&&q.remove();(He.parentElement!==H||H.lastElementChild!==He)&&H.appendChild(He),Re&&Je!==qe&&(Je&&Re.unobserve(Je),Je=qe,Re.observe(qe))}function Fe(){const m=e.querySelector(".me-video-canvas-stage");if(!m){Ye?.remove(),Ye=null,Me&&dt&&(Me.unobserve(dt),dt=null),Ge=null;return}Ge=m,Ge.style.position="relative",!Ye||!Ye.isConnected||Ye.parentElement!==Ge?(Ye?.remove(),Ye=document.createElement("div"),Ye.className="me-video-text-canvas-layer",Ye.addEventListener("pointerdown",H=>{H.target===Ye&&(H.preventDefault(),H.stopPropagation())}),Ye.addEventListener("click",H=>{H.target===Ye&&(H.preventDefault(),H.stopPropagation(),ze=null,Eo(e),rt?Le(!1):Ke())}),Ge.appendChild(Ye)):Ge.lastElementChild!==Ye&&Ge.appendChild(Ye),Me&&dt!==Ge&&(dt&&Me.unobserve(dt),dt=Ge,Me.observe(Ge))}function f(){if(!Ge)return null;const H=t.getState().canvas??{},q=Math.max(1,Number(H.w)||0),l=Math.max(1,Number(H.h)||0);if(!q||!l)return null;const d=Ge.getBoundingClientRect(),o=Ge.querySelector("canvas, video, img")||[...Ge.children].find(C=>C!==Ye)||null;let a=0,c=0,x=Ge.clientWidth||q,P=Ge.clientHeight||l;if(o instanceof HTMLElement){const C=o.getBoundingClientRect();C.width>0&&C.height>0&&(a=C.left-d.left,c=C.top-d.top,x=C.width,P=C.height)}if(!(x>0&&P>0)){const C=Ge.clientWidth||q,ne=Ge.clientHeight||l,L=Math.min(C/q,ne/l)||1;x=q*L,P=l*L,a=Math.max(0,(C-x)/2),c=Math.max(0,(ne-P)/2)}return{stageLeft:d.left,stageTop:d.top,left:a,top:c,scaleX:x/q,scaleY:P/l}}function g(m,H){const q=lt(m),l=Bt(m,q);return H>=q-.001&&H<=l+.001}function $(m,H,q){const l=zt(e,"text",m,H,q);ze=l.length?l[l.length-1]:null,Le(!0),Ke()}function fe(m,H,q){return{x:(m-q.stageLeft-q.left)/q.scaleX,y:(H-q.stageTop-q.top)/q.scaleY}}function ge(m,H,q,l){return{x:q,y:l,fontSize:H.fontSize,width:H.width,paddingX:H.paddingX,paddingY:H.paddingY,borderWidth:H.borderWidth,boxShadow:H.boxShadow}}function we(m,H,q){const l=(t.getState().overlays??[])[m];if(!l||l.type!=="text")return;const d=t.getState().canvas??{w:1080,h:1920},o=Gt(l);if(!o)return;const a=H.clientX,c=H.clientY,x=Math.max(0,(Number(d.w)||0)-o.w),P=Math.max(0,(Number(d.h)||0)-o.h),C=(O,he,ve)=>{const Ce=(O-a)/q.scaleX,Ee=(he-c)/q.scaleY,ye=ue(o.x+Ce,0,x),Oe=ue(o.y+Ee,0,P);t.updateOverlay(m,{x:ye,y:Oe},ve?{transient:!0}:void 0)},ne=O=>{O.preventDefault(),C(O.clientX,O.clientY,!0)},L=O=>{window.removeEventListener("pointermove",ne),window.removeEventListener("pointerup",L),window.removeEventListener("pointercancel",L),C(O.clientX,O.clientY,!1)};window.addEventListener("pointermove",ne),window.addEventListener("pointerup",L),window.addEventListener("pointercancel",L)}function Be(m,H,q,l){const d=(t.getState().overlays??[])[m];if(!d||d.type!=="text")return;const o=Gt(d);if(!o)return;const a=t.getState().canvas??{w:1080,h:1920},c=H.x===.5?.5:1-H.x,x=H.y===.5?.5:1-H.y,P=o.x+o.w*c,C=o.y+o.h*x,ne=Math.max(.1,24/Math.max(24,o.w),24/Math.max(24,o.h)),L=H.x===.5?1/0:Math.max(.1,(c===0?(Number(a.w)||0)-P:P)/Math.max(1,o.w)),O=H.y===.5?1/0:Math.max(.1,(x===0?(Number(a.h)||0)-C:C)/Math.max(1,o.h)),he=Math.max(ne,Math.min(L,O,8)),ve=(ye,Oe,_e)=>{const Xe=fe(ye,Oe,l),We=[];H.x!==.5&&We.push(Math.abs(Xe.x-P)/Math.max(1,o.w)),H.y!==.5&&We.push(Math.abs(Xe.y-C)/Math.max(1,o.h));const st=We.length?Math.max(...We):1,Nt=ue(st,ne,he),$t=Yo(d,Nt),cn=Gt($t);if(!cn)return;const dn=P-cn.w*c,Pn=C-cn.h*x;t.updateOverlay(m,ge(d,$t,dn,Pn),_e?{transient:!0}:void 0)},Ce=ye=>{ye.preventDefault(),ve(ye.clientX,ye.clientY,!0)},Ee=ye=>{window.removeEventListener("pointermove",Ce),window.removeEventListener("pointerup",Ee),window.removeEventListener("pointercancel",Ee),ve(ye.clientX,ye.clientY,!1)};window.addEventListener("pointermove",Ce),window.addEventListener("pointerup",Ee),window.addEventListener("pointercancel",Ee)}function Se(m,H,q){const l=(t.getState().overlays??[])[m];if(!l||l.type!=="text")return;const d=Gt(l);if(!d)return;const o=q.stageLeft+q.left+(d.x+d.w/2)*q.scaleX,a=q.stageTop+q.top+(d.y+d.h/2)*q.scaleY,c=Math.atan2(H.clientY-a,H.clientX-o),x=un(l),P=(L,O,he,ve)=>{const Ce=Math.atan2(O-a,L-o);let Ee=In(x+(Ce-c)*180/Math.PI);ve&&(Ee=Math.round(Ee/15)*15),t.updateOverlay(m,{rotation:Ee},he?{transient:!0}:void 0)},C=L=>{L.preventDefault(),P(L.clientX,L.clientY,!0,L.shiftKey)},ne=L=>{window.removeEventListener("pointermove",C),window.removeEventListener("pointerup",ne),window.removeEventListener("pointercancel",ne),P(L.clientX,L.clientY,!1,L.shiftKey)};window.addEventListener("pointermove",C),window.addEventListener("pointerup",ne),window.addEventListener("pointercancel",ne)}function $e(m,H){if(Fe(),!Ye)return;Ye.replaceChildren();const q=f();if(!q){Ye.hidden=!0;return}Ye.hidden=!1;const l=Lt(),d=m.map(a=>a.index),o=m.filter(a=>g(a.overlay,l));for(const a of o){const c=Gt(a.overlay);if(!c)continue;const x=document.createElement("button");x.type="button",x.className="me-video-text-canvas-hit";const P=H.has(a.index),C=P&&ze===a.index;P&&x.classList.add("is-active"),x.title=Un(a.overlay.text,s.untitledText),x.style.left=`${q.left+c.x*q.scaleX}px`,x.style.top=`${q.top+c.y*q.scaleY}px`,x.style.width=`${Math.max(18,c.w*q.scaleX)}px`,x.style.height=`${Math.max(18,c.h*q.scaleY)}px`;const ne=un(a.overlay);if(ne&&(x.style.transform=`rotate(${ne}deg)`,x.style.transformOrigin="center center"),x.addEventListener("pointerdown",L=>{if(L.preventDefault(),L.stopPropagation(),L.shiftKey||L.ctrlKey||L.metaKey){$(a.index,L,d);return}ze=a.index,bt(e,"text",[a.index]),Le(!0),we(a.index,L,q)}),C){for(const O of et){const he=document.createElement("span");he.className="me-video-text-canvas-handle",he.dataset.handle=O.key,he.style.left=`${O.x*100}%`,he.style.top=`${O.y*100}%`,he.addEventListener("pointerdown",ve=>{ve.preventDefault(),ve.stopPropagation(),ze=a.index,bt(e,"text",[a.index]),Le(!0),Be(a.index,O,ve,q)}),x.appendChild(he)}const L=document.createElement("span");L.className="me-video-text-canvas-handle",L.dataset.handle=tt.key,L.style.left=`${tt.x*100}%`,L.style.top=`${tt.y*100}%`,L.addEventListener("pointerdown",O=>{O.preventDefault(),O.stopPropagation(),ze=a.index,bt(e,"text",[a.index]),Le(!0),Se(a.index,O,q)}),x.appendChild(L)}Ye.appendChild(x)}}function Ae(m,H,q){if(!qe)return;const l=(t.getState().overlays??[])[m];if(!l||l.type!=="text")return;if(q.shiftKey||q.ctrlKey||q.metaKey){q.preventDefault(),q.stopPropagation();const O=zt(e,"text",m,q,ar(t.getState()).map(he=>he.index));ze=O.length?O[O.length-1]:null,Ze(),Le(!0);return}q.preventDefault(),q.stopPropagation(),ze=m,bt(e,"text",[m]),Ze(),rt||Le(!0);const d=It(),o=Math.max(qe.clientWidth/d,.001),a=lt(l),c=Bt(l,a),x=Math.max(je,c-a),P=vt(l),C=q.clientX,ne=O=>{const he=(O.clientX-C)/o,ve=t.getState().overlays??[];if(H==="move"){const ye=Math.max(0,a+he),Oe=ye+x,_e=ft(He,ve,m,ye,Oe,O.clientY,P);At(m,{startAt:ye,endAt:Oe,timelineTrack:_e},{transient:!0});return}if(H==="start"){const ye=ue(a+he,0,c-je),Oe=ft(He,ve,m,ye,c,O.clientY,P);At(m,{startAt:ye,endAt:c,timelineTrack:Oe},{transient:!0});return}const Ce=Math.max(a+je,c+he),Ee=ft(He,ve,m,a,Ce,O.clientY,P);At(m,{startAt:a,endAt:Ce,timelineTrack:Ee},{transient:!0})},L=O=>{window.removeEventListener("pointermove",ne),window.removeEventListener("pointerup",L),window.removeEventListener("pointercancel",L);const he=(O.clientX-C)/o,ve=t.getState().overlays??[];if(H==="move"){const ye=Math.max(0,a+he),Oe=ye+x,_e=ft(He,ve,m,ye,Oe,O.clientY,P);At(m,{startAt:ye,endAt:Oe,timelineTrack:_e});return}if(H==="start"){const ye=ue(a+he,0,c-je),Oe=ft(He,ve,m,ye,c,O.clientY,P);At(m,{startAt:ye,endAt:c,timelineTrack:Oe});return}const Ce=Math.max(a+je,c+he),Ee=ft(He,ve,m,a,Ce,O.clientY,P);At(m,{startAt:a,endAt:Ce,timelineTrack:Ee})};window.addEventListener("pointermove",ne),window.addEventListener("pointerup",L),window.addEventListener("pointercancel",L),Ke()}function De(m,H){if(Te(),!He||!qe||(He.replaceChildren(),He.hidden=m.length===0,!m.length))return;const q=It(),l=qe.clientWidth/q,d=Fn(t.getState()),o=new Map;for(const a of m){const c=vt(a.overlay),x=d.get(c)??c;let P=o.get(c);P||(P=document.createElement("div"),P.className="me-video-overlay-track-row",P.dataset.track=String(c),P.style.top=`${Ln(x)}px`,o.set(c,P),He.appendChild(P));const C=document.createElement("div");C.className="me-video-text-track-clip",H.has(a.index)&&C.classList.add("is-active");const ne=lt(a.overlay),L=Sn(a.overlay);C.style.left=`${ne*l}px`,C.style.width=`${Math.max(36,L*l)}px`;const O=document.createElement("span");O.className="me-video-text-track-icon",O.textContent="Aa";const he=document.createElement("span");he.className="me-video-text-track-label",he.textContent=Un(a.overlay.text,s.untitledText),he.title=he.textContent;const ve=document.createElement("span");ve.className="me-video-text-track-handle is-start";const Ce=document.createElement("span");Ce.className="me-video-text-track-handle is-end",C.append(O,he,ve,Ce),C.addEventListener("pointerdown",Ee=>Ae(a.index,"move",Ee)),ve.addEventListener("pointerdown",Ee=>Ae(a.index,"start",Ee)),Ce.addEventListener("pointerdown",Ee=>Ae(a.index,"end",Ee)),C.addEventListener("click",Ee=>{if(Ee.preventDefault(),Ee.stopPropagation(),Ee.shiftKey||Ee.ctrlKey||Ee.metaKey){Ze(),Ke();return}const ye=zt(e,"text",a.index,Ee,m.map(Oe=>Oe.index));ze=ye.length?ye[ye.length-1]:null,Ze(),Le(!0),Ke()}),P.appendChild(C)}}function Qe(m,H){J.replaceChildren(),J.hidden=m.length===0,oe.hidden=m.length>0;for(const q of m){const l=document.createElement("button");l.type="button",l.className="me-video-text-chip",H.has(q.index)&&l.classList.add("is-active"),l.textContent=Un(q.overlay.text,s.untitledText),l.title=Un(q.overlay.text,s.untitledText),l.addEventListener("click",d=>{const o=zt(e,"text",q.index,d,m.map(a=>a.index));ze=o.length?o[o.length-1]:null,Ke()}),J.appendChild(l)}}function Ie(m){le.disabled=m,ae.setDisabled(m),be.disabled=m,se.disabled=m,h.forEach(({button:H})=>H.disabled=m),I.disabled=m,X.disabled=m,K.disabled=m,M.disabled=m,ce.disabled=m,U.disabled=m,T.disabled=m,A.disabled=m,k.setDisabled(m),b.setDisabled(m),Q.setDisabled(m),W.setDisabled(m),B.disabled=m,V.disabled=m,S.disabled=m,N.disabled=m,j.disabled=m,re.disabled=m}function Pe(m){const H=String(ue(Math.round(Number(m)||0),0,100));K.value=H,M.value=H}function Ue(m){const H=Or(m?.textDecoration);N.classList.toggle("is-active",!!m&&String(m.fontStyle??"normal")==="italic"),j.classList.toggle("is-active",!!m&&H.has("underline")),re.classList.toggle("is-active",!!m&&H.has("line-through"))}function ct(m="left"){h.forEach(({value:H,button:q})=>{})}function pt(m){if(Ie(!!!m),!m){xe.value="none",le.value="",ae.setContextText(""),ae.setValue("Arial",{silent:!0}),be.value="700",se.value="72",k.setValue("#ffffff"),b.setValue("transparent"),ct("center"),I.value="none",X.value="none",Q.setValue("#000000"),ce.value="0",W.setValue("#000000"),U.value="0",T.value="4",A.value="18",Pe(100),Ue(null);return}const q=m.boxShadow??{};xe.value=String(m.textPreset??"none"),le.value=String(m.text??""),ae.setContextText(m.text??""),ae.setValue(String(m.fontFamily??"Arial"),{silent:!0}),be.value=String(m.fontWeight??"700"),se.value=String(Math.round(Number(m.fontSize)||72)),k.setValue(m.color??"#ffffff"),b.setValue(m.backgroundColor??"transparent"),ct(m.textAlign==="right"||m.textAlign==="center"?m.textAlign:"left"),I.value=m.textTransform?String(m.textTransform):"none",X.value=m.animation?String(m.animation):"none",Q.setValue(m.borderColor??"#000000"),ce.value=String(Math.round(Number(m.borderWidth)||0)),W.setValue(q.color??"#000000"),U.value=String(Math.round(Number(q.x)||0)),T.value=String(Math.round(Number(q.y)||0)),A.value=String(Math.round(Number(q.blur)||0)),Pe(Number.isFinite(m.opacity)?m.opacity:100),Ue(m)}function Ke(){gt(()=>{const m=ar(t.getState());Rt(m);const H=new Set(_t(e,"text"));De(m,H),$e(m,H),Qe(m,H),pt(ut()),St(),Et(),at()}),jt()}function nt(){gt(()=>{const m=e.querySelector(".me-video-toolrail");m&&(pe=m,Yi([...pe.querySelectorAll("button")].filter(H=>H instanceof HTMLButtonElement&&H!==G&&!H.classList.contains("me-video-text-tool"))),(!G||!G.isConnected)&&(G=document.createElement("button"),G.type="button",G.className="me-video-text-tool",G.innerHTML=`<span class="me-video-text-tool-icon">T</span><span class="me-video-text-tool-label">${u.tool}</span>`,G.addEventListener("click",()=>{Ut("heading")})),G.isConnected||pe.appendChild(G),at(),Et())})}function ot(m){return!!m&&(m===v||v.contains(m)||m===G||m===He||He?.contains?.(m)||m===Ye||Ye?.contains?.(m))}function Ot(m){return m.some(H=>{if(!ot(H.target))return!0;for(const q of H.addedNodes)if(!ot(q))return!0;for(const q of H.removedNodes)if(!ot(q))return!0;return!1})}function Ft(m,H){m.swatch.addEventListener("input",()=>{m.transparentButton&&m.wrap.dataset.transparent==="true"&&m.setTransparent(!1),m.text.value=m.swatch.value,H(m.getValue())}),m.text.addEventListener("change",()=>{const q=String(m.text.value??"").trim();if(m.transparentButton&&q.toLowerCase()==="transparent"){m.setTransparent(!0),H("transparent");return}const l=vn(q,m.swatch.value||"#ffffff");m.swatch.value=l==="transparent"?m.swatch.value||"#ffffff":l,m.text.value=l,m.transparentButton&&m.setTransparent(!1),H(l)}),m.transparentButton?.addEventListener("click",()=>{const q=m.wrap.dataset.transparent!=="true";m.setTransparent(q),H(m.getValue())})}function kt(m){const H=ut();if(!H)return;const q={color:"#000000",x:0,y:4,blur:18,...H.boxShadow??{}};mt({boxShadow:{...q,...m}})}function ln(m){const H=ut();if(!H)return;const q=Or(H.textDecoration);q.has(m)?q.delete(m):q.add(m),mt({textDecoration:oa(q)||void 0})}const an=new MutationObserver(m=>{xt||e.__meVideoEnhancerObserverLock||Ot(m)&&(nt(),me())}),en=m=>{m?.detail?.id!==wt&&rt&&(rt=!1,Ke())},Ct=()=>{Ke()};an.observe(e,{childList:!0,subtree:!0,characterData:!0}),e.addEventListener("me-video-inspector-open",en),e.addEventListener(Ht,Ct),window.addEventListener("resize",Et);const tn=t.subscribe(()=>{Ke()});return te.addEventListener("click",()=>Ut("heading")),S.addEventListener("click",()=>{Ze(),Le(!0)}),B.addEventListener("click",E),V.addEventListener("click",F),ie.addEventListener("click",()=>{Le(!1)}),le.addEventListener("input",()=>{ae.setContextText(le.value),mt({text:le.value})}),xe.addEventListener("change",()=>{if(xe.value==="none"){ut()&&mt({textPreset:"none"},{preservePreset:!0});return}Z(xe.value)}),ae.wrap.addEventListener("fontchange",()=>mt({fontFamily:ae.getValue()})),be.addEventListener("change",()=>mt({fontWeight:be.value})),se.addEventListener("change",()=>mt({fontSize:ue(Number(se.value)||72,8,320)})),Ft(k,m=>mt({color:m})),Ft(b,m=>mt({backgroundColor:m})),h.forEach(({value:m,button:H})=>{H.addEventListener("click",()=>{ct(m),mt({textAlign:m})})}),I.addEventListener("change",()=>mt({textTransform:I.value==="none"?void 0:I.value})),X.addEventListener("change",()=>mt({animation:X.value==="none"?void 0:X.value})),ce.addEventListener("change",()=>mt({borderWidth:ue(Number(ce.value)||0,0,32)})),Ft(Q,m=>mt({borderColor:m})),Ft(W,m=>kt({color:m})),U.addEventListener("change",()=>kt({x:ue(Number(U.value)||0,-80,80)})),T.addEventListener("change",()=>kt({y:ue(Number(T.value)||0,-80,80)})),A.addEventListener("change",()=>kt({blur:ue(Number(A.value)||0,0,80)})),K.addEventListener("input",()=>{const m=ue(Number(K.value)||0,0,100);Pe(m),mt({opacity:m})}),M.addEventListener("input",()=>{const m=ue(Number(M.value)||0,0,100);Pe(m),mt({opacity:m})}),N.addEventListener("click",()=>{const m=ut();m&&mt({fontStyle:String(m.fontStyle??"normal")==="italic"?"normal":"italic"})}),j.addEventListener("click",()=>ln("underline")),re.addEventListener("click",()=>ln("line-through")),nt(),Ke(),{destroy(){an.disconnect(),Re&&Je&&Re.unobserve(Je),Me&&dt&&Me.unobserve(dt),tn(),e.removeEventListener("me-video-inspector-open",en),e.removeEventListener(Ht,Ct),window.removeEventListener("resize",Et),ae.destroy(),G?.remove(),He?.remove(),Ye?.remove(),v.remove(),Pt(e)}}}function ia(e,t,n){Qt(),kn();const r=Ni(n()),i=Ai(r),s=document.createElement("div");s.className="me-video-text-panel me-video-sticker-panel",s.hidden=!0,e.appendChild(s);const u=document.createElement("div");u.className="me-video-text-toolbar";const p=document.createElement("strong");p.textContent=r.title,u.append(p);const v=Kt(r.uploadTitle),w=document.createElement("label");w.className="me-video-sticker-upload-zone";const z=document.createElement("span");z.className="me-video-sticker-upload-icon",z.textContent="\u{1F5BC}";const te=document.createElement("span");te.className="me-video-sticker-upload-text",te.textContent=r.uploadHint;const S=document.createElement("span");S.className="me-video-sticker-upload-subtext",S.textContent=r.uploadFormats;const B=document.createElement("input");B.type="file",B.accept="image/png,image/jpeg,image/webp,image/svg+xml",w.append(z,te,S,B),v.body.appendChild(w);const V=Kt(r.libraryTitle),ie=document.createElement("div");ie.className="me-video-sticker-library",V.body.appendChild(ie),s.append(u,v.section,V.section);let J=null,oe=null,le=null,xe=null,ae=null,be=null,se=null,k=null,b=null,_=!1,h=null,y=!1,N=!1;const j="sticker",re=typeof requestAnimationFrame=="function"?requestAnimationFrame:E=>setTimeout(E,16),I=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>ce()),D=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>ce()),K=[{key:"tl",x:0,y:0},{key:"tm",x:.5,y:0},{key:"tr",x:1,y:0},{key:"mr",x:1,y:.5},{key:"br",x:1,y:1},{key:"bm",x:.5,y:1},{key:"bl",x:0,y:1},{key:"ml",x:0,y:.5}],M={key:"rotate",x:.5,y:0};function X(){Promise.resolve().then(()=>{N=!1;const E=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,E-1)})}function Q(E){N=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return E()}finally{X()}}function ce(){y||(y=!0,re(()=>{y=!1,ut()}))}function W(E){const F=!!E;if(F===_){ut();return}_=F,_&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:j}})),ut()}function U(E=oe){return E?[...E.children].filter(F=>F instanceof HTMLButtonElement&&!F.classList.contains("me-video-text-tool")):[]}function T(E){return[E?.textContent,E?.getAttribute?.("title"),E?.getAttribute?.("aria-label")].filter(Boolean).join(" ").trim().toLowerCase()}function A(E){const F=["trim","timeline","\u526A\u8F91","\u65F6\u95F4\u8F74"];return Ro(E.find(Z=>{const Te=T(Z);return F.some(Fe=>Te.includes(Fe))})??E[0]??null)}function de(E){const F=[r.tool,r.title,"sticker","stickers","\u8D34\u7EB8","\u8CBC\u7D19"].map(Z=>String(Z??"").trim().toLowerCase()).filter(Boolean);return E.find(Z=>{const Te=T(Z);return F.some(Fe=>Te.includes(Fe))})??E[Math.min(5,Math.max(0,E.length-1))]??null}function Ne(){if(J?.classList.toggle("is-active",_),!!le&&_){le.classList.remove("is-active");return}}function R(){le&&(le.classList.contains("is-active")||le.click())}function ee(){rn(e,s),Pt(e)}function Y(){s.hidden=!_,Ne(),ee()}function G(E){if(!E.length){h=null;return}const F=ur(e,t.getState());h=F.length?F[F.length-1]:null}function pe(){return Tn(t)}function qe(){return yn(e)}function He(){if(!t.history?.present)return;const E=qe(),F=Number(t.history.present.__mePreviewTimelineTime);Math.abs((Number.isFinite(F)?F:-1)-E)<.001||(t.history={...t.history,present:{...t.history.present,__mePreviewTimelineTime:E}},typeof t.emit=="function"&&t.emit())}function Je(E){return E?.emoji?`${r.defaultLabel} ${E.emoji}`:E?.src?r.uploadedLabel:r.defaultLabel}function Ge(E){const F=Gt(E);if(!F)return null;if(!E?.emoji)return F;const Z=.84,Te=F.w*(1-Z)/2,Fe=F.h*(1-Z)/2;return{x:F.x+Te,y:F.y+Fe,w:F.w*Z,h:F.h*Z}}function Ye(E,F){if(!E?.emoji)return F;const Te=1/.84,Fe=(Te-1)/2;return{x:F.x-F.w*Fe,y:F.y-F.h*Fe,w:F.w*Te,h:F.h*Te}}function dt(E,F){const Z=Math.max(1,Number(F?.w)||1080),Te=Math.max(1,Number(F?.h)||1920),Fe=ue(Number.isFinite(E?.w)?E.w:8,8,Math.max(8,Z)),f=ue(Number.isFinite(E?.h)?E.h:8,8,Math.max(8,Te));return{x:ue(Number.isFinite(E?.x)?E.x:0,0,Math.max(0,Z-Fe)),y:ue(Number.isFinite(E?.y)?E.y:0,0,Math.max(0,Te-f)),w:Fe,h:f}}function rt(E){return E?.emoji||"\u2726"}function ze(E,F,Z={}){const Fe=(t.getState().overlays??[])[E];!Fe||Fe.type!=="sticker"||t.updateOverlay(E,Jt(Fe,pe(),F),Z)}function it(E){if(typeof t.applyMut=="function"){t.applyMut(Z=>({...Z,overlays:[...on(Z.overlays),{...E,timelineTrack:0}]}));return}const F=on(t.getState().overlays);t.commit?.({overlays:[...F,{...E,timelineTrack:0}]})}function xt(E){return new Promise(F=>{const Z=new Image;Z.onload=()=>F({w:Z.naturalWidth||256,h:Z.naturalHeight||256}),Z.onerror=()=>F({w:256,h:256}),Z.src=E})}async function wt(E){const F=pe();let Z=ue(qe(),0,Math.max(0,F-je)),Te=Math.min(F,Z+qt);Te-Z<je&&(Z=ue(F-qt,0,Math.max(0,F-je)),Te=Math.max(Z+je,F));const Fe=t.getState().canvas??{w:1080,h:1920},f=E.emoji?{w:256,h:256}:await xt(E.src),g=Math.max(96,Math.round(Math.min(Fe.w,Fe.h)*.24)),$=Vr(f.w,f.h,g),fe={type:"sticker",x:Math.round((Fe.w-$.w)/2),y:Math.round((Fe.h-$.h)/2),w:$.w,h:$.h,rotation:0,...E.emoji?{emoji:E.emoji}:{src:E.src},...Jt(null,F,{startAt:Z,endAt:Te,timelineTrack:0})};it(fe);const ge=t.getState().overlays??[];h=ge.length?ge.length-1:null,h!=null&&bt(e,"text",[h]),R(),W(!0)}async function ke(E){const F=E?.[0];if(!F||!String(F.type||"").startsWith("image/")&&!/\.(png|jpe?g|webp|svg)$/i.test(F.name||""))return;const Z=await new Promise((Te,Fe)=>{const f=new FileReader;f.onload=()=>Te(String(f.result||"")),f.onerror=()=>Fe(f.error||new Error("Failed to read sticker file")),f.readAsDataURL(F)}).catch(()=>"");Z&&(B.value="",await wt({src:Z}))}function Re(){ie.replaceChildren();for(const E of i){const F=document.createElement("div");F.className="me-video-sticker-library-group";const Z=document.createElement("div");Z.className="me-video-sticker-library-title",Z.textContent=E.title;const Te=document.createElement("div");Te.className="me-video-sticker-grid";for(const Fe of E.items){const f=document.createElement("button");if(f.type="button",f.className="me-video-sticker-card",f.title=Fe.label,f.setAttribute("aria-label",Fe.label),Fe.emoji){const g=document.createElement("span");g.className="me-video-sticker-card-emoji",g.textContent=Fe.emoji,f.appendChild(g)}else if(Fe.src){const g=document.createElement("img");g.src=Fe.src,g.alt=Fe.label,f.appendChild(g)}f.addEventListener("click",()=>{wt(Fe)}),Te.appendChild(f)}F.append(Z,Te),ie.appendChild(F)}}function Me(){Q(()=>{const E=e.querySelector(".me-video-toolrail");E&&(oe=E,(!J||!J.isConnected)&&(J=document.createElement("button"),J.type="button",J.className="me-video-text-tool",J.innerHTML=`<span class="me-video-text-tool-icon">\u2726</span><span class="me-video-text-tool-label">${r.tool}</span>`,J.title=r.tool,J.setAttribute("aria-label",r.tool),J.addEventListener("click",()=>{const F=!_;F&&R(),W(F)})),J.isConnected||oe.appendChild(J),ee())})}function et(){const{timelineInner:E,timelineHost:F}=$n(e,t.getState());if(!E||!F){ae?.remove(),ae=null,I&&be&&(I.unobserve(be),be=null),xe=null;return}xe=E,(!ae||!ae.isConnected||ae.parentElement!==F)&&(ae?.remove(),ae=document.createElement("div"),ae.className="me-video-text-timeline me-video-sticker-timeline me-video-overlay-timeline me-video-sticker-overlay-layer");for(const Z of[...F.children])Z!==ae&&Z instanceof HTMLElement&&Z.classList.contains("me-video-sticker-overlay-layer")&&Z.remove();(ae.parentElement!==F||F.lastElementChild!==ae)&&F.appendChild(ae),I&&be!==xe&&(be&&I.unobserve(be),be=xe,I.observe(xe))}function tt(){const E=e.querySelector(".me-video-canvas-stage");if(!E){k?.remove(),k=null,D&&b&&(D.unobserve(b),b=null),se=null;return}se=E,se.style.position="relative",!k||!k.isConnected||k.parentElement!==se?(k?.remove(),k=document.createElement("div"),k.className="me-video-text-canvas-layer me-video-sticker-canvas-layer",k.addEventListener("pointerdown",F=>{F.target===k&&(F.preventDefault(),F.stopPropagation())}),k.addEventListener("click",F=>{F.target===k&&(F.preventDefault(),F.stopPropagation(),h=null,Eo(e),_?W(!1):ut())}),se.appendChild(k)):se.lastElementChild!==k&&se.appendChild(k),D&&b!==se&&(b&&D.unobserve(b),b=se,D.observe(se))}function ht(){if(!se)return null;const F=t.getState().canvas??{},Z=Math.max(1,Number(F.w)||0),Te=Math.max(1,Number(F.h)||0);if(!Z||!Te)return null;const Fe=se.getBoundingClientRect(),f=se.querySelector("canvas, video, img")||[...se.children].find(we=>we!==k)||null;let g=0,$=0,fe=se.clientWidth||Z,ge=se.clientHeight||Te;if(f instanceof HTMLElement){const we=f.getBoundingClientRect();we.width>0&&we.height>0&&(g=we.left-Fe.left,$=we.top-Fe.top,fe=we.width,ge=we.height)}if(!(fe>0&&ge>0)){const we=se.clientWidth||Z,Be=se.clientHeight||Te,Se=Math.min(we/Z,Be/Te)||1;fe=Z*Se,ge=Te*Se,g=Math.max(0,(we-fe)/2),$=Math.max(0,(Be-ge)/2)}return{stageLeft:Fe.left,stageTop:Fe.top,left:g,top:$,scaleX:fe/Z,scaleY:ge/Te}}function gt(E,F){const Z=lt(E),Te=Bt(E,Z);return F>=Z-.001&&F<=Te+.001}function me(E,F,Z){const Te=zt(e,"text",E,F,Z);h=Te.length?Te[Te.length-1]:null,W(!0),ut()}function Le(E,F,Z){return{x:(E-Z.stageLeft-Z.left)/Z.scaleX,y:(F-Z.stageTop-Z.top)/Z.scaleY}}function Ve(E,F,Z){const Te=(t.getState().overlays??[])[E];if(!Te||Te.type!=="sticker")return;const Fe=t.getState().canvas??{w:1080,h:1920},f=Gt(Te);if(!f)return;const g=F.clientX,$=F.clientY,fe=Math.max(0,(Number(Fe.w)||0)-f.w),ge=Math.max(0,(Number(Fe.h)||0)-f.h),we=($e,Ae,De)=>{const Qe=($e-g)/Z.scaleX,Ie=(Ae-$)/Z.scaleY,Pe=ue(f.x+Qe,0,fe),Ue=ue(f.y+Ie,0,ge);t.updateOverlay(E,{x:Pe,y:Ue},De?{transient:!0}:void 0)},Be=$e=>{$e.preventDefault(),we($e.clientX,$e.clientY,!0)},Se=$e=>{window.removeEventListener("pointermove",Be),window.removeEventListener("pointerup",Se),window.removeEventListener("pointercancel",Se),we($e.clientX,$e.clientY,!1)};window.addEventListener("pointermove",Be),window.addEventListener("pointerup",Se),window.addEventListener("pointercancel",Se)}function Ze(E,F,Z,Te){const Fe=(t.getState().overlays??[])[E];if(!Fe||Fe.type!=="sticker")return;const f=Ge(Fe);if(!f)return;const g=t.getState().canvas??{w:1080,h:1920},$=F.x===.5?.5:1-F.x,fe=F.y===.5?.5:1-F.y,ge=f.x+f.w*$,we=f.y+f.h*fe,Be=Math.max(.1,24/Math.max(24,f.w),24/Math.max(24,f.h)),Se=F.x===.5?1/0:Math.max(.1,($===0?(Number(g.w)||0)-ge:ge)/Math.max(1,f.w)),$e=F.y===.5?1/0:Math.max(.1,(fe===0?(Number(g.h)||0)-we:we)/Math.max(1,f.h)),Ae=Math.max(Be,Math.min(Se,$e,8)),De=(Pe,Ue,ct)=>{const pt=Le(Pe,Ue,Te),Ke=[];F.x!==.5&&Ke.push(Math.abs(pt.x-ge)/Math.max(1,f.w)),F.y!==.5&&Ke.push(Math.abs(pt.y-we)/Math.max(1,f.h));const nt=Ke.filter(Number.isFinite),ot=nt.length?Math.max(...nt):1,Ot=ue(ot,Be,Ae),Ft={x:ge-f.w*Ot*$,y:we-f.h*Ot*fe,w:Math.max(8,f.w*Ot),h:Math.max(8,f.h*Ot)},kt=dt(Ye(Fe,Ft),g);t.updateOverlay(E,{x:kt.x,y:kt.y,w:kt.w,h:kt.h},ct?{transient:!0}:void 0)},Qe=Pe=>{Pe.preventDefault(),De(Pe.clientX,Pe.clientY,!0)},Ie=Pe=>{window.removeEventListener("pointermove",Qe),window.removeEventListener("pointerup",Ie),window.removeEventListener("pointercancel",Ie),De(Pe.clientX,Pe.clientY,!1)};window.addEventListener("pointermove",Qe),window.addEventListener("pointerup",Ie),window.addEventListener("pointercancel",Ie)}function at(E,F,Z){const Te=(t.getState().overlays??[])[E];if(!Te||Te.type!=="sticker")return;const Fe=Ge(Te);if(!Fe)return;const f=Z.stageLeft+Z.left+(Fe.x+Fe.w/2)*Z.scaleX,g=Z.stageTop+Z.top+(Fe.y+Fe.h/2)*Z.scaleY,$=Math.atan2(F.clientY-g,F.clientX-f),fe=un(Te),ge=(Se,$e,Ae,De)=>{const Qe=Math.atan2($e-g,Se-f);let Ie=In(fe+(Qe-$)*180/Math.PI);De&&(Ie=Math.round(Ie/15)*15),t.updateOverlay(E,{rotation:Ie},Ae?{transient:!0}:void 0)},we=Se=>{Se.preventDefault(),ge(Se.clientX,Se.clientY,!0,Se.shiftKey)},Be=Se=>{window.removeEventListener("pointermove",we),window.removeEventListener("pointerup",Be),window.removeEventListener("pointercancel",Be),ge(Se.clientX,Se.clientY,!1,Se.shiftKey)};window.addEventListener("pointermove",we),window.addEventListener("pointerup",Be),window.addEventListener("pointercancel",Be)}function Et(E,F){if(tt(),!k)return;k.replaceChildren();const Z=ht();if(!Z){k.hidden=!0;return}k.hidden=!1;const Te=qe(),Fe=E.map(g=>g.index),f=E.filter(g=>gt(g.overlay,Te));for(const g of f){const $=Ge(g.overlay);if(!$)continue;const fe=document.createElement("button");fe.type="button",fe.className="me-video-text-canvas-hit me-video-sticker-canvas-hit";const ge=F.has(g.index),we=ge&&h===g.index;ge&&fe.classList.add("is-active"),fe.title=Je(g.overlay),fe.style.left=`${Z.left+$.x*Z.scaleX}px`,fe.style.top=`${Z.top+$.y*Z.scaleY}px`,fe.style.width=`${Math.max(18,$.w*Z.scaleX)}px`,fe.style.height=`${Math.max(18,$.h*Z.scaleY)}px`;const Be=un(g.overlay);if(Be&&(fe.style.transform=`rotate(${Be}deg)`,fe.style.transformOrigin="center center"),fe.addEventListener("pointerdown",Se=>{if(Se.preventDefault(),Se.stopPropagation(),Se.shiftKey||Se.ctrlKey||Se.metaKey){me(g.index,Se,Fe);return}h=g.index,bt(e,"text",[g.index]),W(!0),Ve(g.index,Se,Z)}),we){for(const $e of K){const Ae=document.createElement("span");Ae.className="me-video-text-canvas-handle",Ae.dataset.handle=$e.key,Ae.style.left=`${$e.x*100}%`,Ae.style.top=`${$e.y*100}%`,Ae.addEventListener("pointerdown",De=>{De.preventDefault(),De.stopPropagation(),h=g.index,bt(e,"text",[g.index]),W(!0),Ze(g.index,$e,De,Z)}),fe.appendChild(Ae)}const Se=document.createElement("span");Se.className="me-video-text-canvas-handle",Se.dataset.handle=M.key,Se.style.left=`${M.x*100}%`,Se.style.top=`${M.y*100}%`,Se.addEventListener("pointerdown",$e=>{$e.preventDefault(),$e.stopPropagation(),h=g.index,bt(e,"text",[g.index]),W(!0),at(g.index,$e,Z)}),fe.appendChild(Se)}k.appendChild(fe)}}function St(E,F,Z){if(!xe)return;const Te=(t.getState().overlays??[])[E];if(!Te||Te.type!=="sticker")return;if(Z.shiftKey||Z.ctrlKey||Z.metaKey){Z.preventDefault(),Z.stopPropagation();const $e=zt(e,"text",E,Z,sr(t.getState()).map(Ae=>Ae.index));h=$e.length?$e[$e.length-1]:null,R(),W(!0);return}Z.preventDefault(),Z.stopPropagation(),h=E,bt(e,"text",[E]),R(),_||W(!0);const Fe=pe(),f=Math.max(xe.clientWidth/Fe,.001),g=lt(Te),$=Bt(Te,g),fe=Math.max(je,$-g),ge=vt(Te),we=Z.clientX,Be=$e=>{const Ae=($e.clientX-we)/f,De=t.getState().overlays??[];if(F==="move"){const Pe=Math.max(0,g+Ae),Ue=Pe+fe,ct=ft(ae,De,E,Pe,Ue,$e.clientY,ge);ze(E,{startAt:Pe,endAt:Ue,timelineTrack:ct},{transient:!0});return}if(F==="start"){const Pe=ue(g+Ae,0,$-je),Ue=ft(ae,De,E,Pe,$,$e.clientY,ge);ze(E,{startAt:Pe,endAt:$,timelineTrack:Ue},{transient:!0});return}const Qe=Math.max(g+je,$+Ae),Ie=ft(ae,De,E,g,Qe,$e.clientY,ge);ze(E,{startAt:g,endAt:Qe,timelineTrack:Ie},{transient:!0})},Se=$e=>{window.removeEventListener("pointermove",Be),window.removeEventListener("pointerup",Se),window.removeEventListener("pointercancel",Se);const Ae=($e.clientX-we)/f,De=t.getState().overlays??[];if(F==="move"){const Pe=Math.max(0,g+Ae),Ue=Pe+fe,ct=ft(ae,De,E,Pe,Ue,$e.clientY,ge);ze(E,{startAt:Pe,endAt:Ue,timelineTrack:ct});return}if(F==="start"){const Pe=ue(g+Ae,0,$-je),Ue=ft(ae,De,E,Pe,$,$e.clientY,ge);ze(E,{startAt:Pe,endAt:$,timelineTrack:Ue});return}const Qe=Math.max(g+je,$+Ae),Ie=ft(ae,De,E,g,Qe,$e.clientY,ge);ze(E,{startAt:g,endAt:Qe,timelineTrack:Ie})};window.addEventListener("pointermove",Be),window.addEventListener("pointerup",Se),window.addEventListener("pointercancel",Se),ut()}function Rt(E,F){if(et(),!ae||!xe||(ae.replaceChildren(),ae.hidden=E.length===0,!E.length))return;const Z=pe(),Te=xe.clientWidth/Z,Fe=Fn(t.getState()),f=new Map;for(const g of E){const $=vt(g.overlay),fe=Fe.get($)??$;let ge=f.get($);ge||(ge=document.createElement("div"),ge.className="me-video-overlay-track-row",ge.dataset.track=String($),ge.style.top=`${Ln(fe)}px`,f.set($,ge),ae.appendChild(ge));const we=document.createElement("div");we.className="me-video-text-track-clip me-video-sticker-track-clip",F.has(g.index)&&we.classList.add("is-active");const Be=lt(g.overlay),Se=Sn(g.overlay);we.style.left=`${Be*Te}px`,we.style.width=`${Math.max(36,Se*Te)}px`;const $e=document.createElement("span");$e.className="me-video-text-track-icon",$e.textContent=rt(g.overlay);const Ae=document.createElement("span");Ae.className="me-video-text-track-label",Ae.textContent=Je(g.overlay),Ae.title=Ae.textContent;const De=document.createElement("span");De.className="me-video-text-track-handle is-start";const Qe=document.createElement("span");Qe.className="me-video-text-track-handle is-end",we.append($e,Ae,De,Qe),we.addEventListener("pointerdown",Ie=>St(g.index,"move",Ie)),De.addEventListener("pointerdown",Ie=>St(g.index,"start",Ie)),Qe.addEventListener("pointerdown",Ie=>St(g.index,"end",Ie)),we.addEventListener("click",Ie=>{if(Ie.preventDefault(),Ie.stopPropagation(),Ie.shiftKey||Ie.ctrlKey||Ie.metaKey){R(),ut();return}const Pe=zt(e,"text",g.index,Ie,E.map(Ue=>Ue.index));h=Pe.length?Pe[Pe.length-1]:null,R(),W(!0),ut()}),ge.appendChild(we)}}function ut(){Q(()=>{Me();const E=U().find(Te=>Te.classList.contains("is-active"))??null;_&&E&&E!==le&&E!==J&&(R(),ce());const F=sr(t.getState());G(F);const Z=new Set(ur(e,t.getState()));Rt(F,Z),Et(F,Z),Y(),ee()}),He()}function It(E){return!!E&&(E===s||s.contains(E)||E===J||J?.contains?.(E)||E===ae||ae?.contains?.(E)||E===k||k?.contains?.(E))}function Lt(E){return E.some(F=>{if(!It(F.target))return!0;for(const Z of F.addedNodes)if(!It(Z))return!0;for(const Z of F.removedNodes)if(!It(Z))return!0;return!1})}const jt=new MutationObserver(E=>{N||e.__meVideoEnhancerObserverLock||Lt(E)&&(Me(),ce())}),At=E=>{E?.detail?.id!==j&&_&&(_=!1,ut())},Mt=()=>{ut()},mt=E=>{const F=E.target;if(!(F instanceof Node)||!J||!J.contains(F))return;E.preventDefault(),E.stopPropagation(),E.stopImmediatePropagation?.();const Z=!_;Z&&(R(),ce()),W(Z)};jt.observe(e,{childList:!0,subtree:!0,characterData:!0}),e.addEventListener("me-video-inspector-open",At),e.addEventListener(Ht,Mt),e.addEventListener("click",mt,!0),window.addEventListener("resize",ee);const Ut=t.subscribe(()=>{ut()});return B.addEventListener("change",()=>{ke(B.files)}),w.addEventListener("dragenter",E=>{E.preventDefault(),w.classList.add("is-dragover")}),w.addEventListener("dragover",E=>{E.preventDefault(),w.classList.add("is-dragover")}),w.addEventListener("dragleave",E=>{E.target===w&&w.classList.remove("is-dragover")}),w.addEventListener("drop",E=>{E.preventDefault(),w.classList.remove("is-dragover"),ke(E.dataTransfer?.files)}),Re(),Me=function(){Q(()=>{const E=e.querySelector(".me-video-toolrail");if(!E)return;oe=E;const F=U(oe);le=A(F),J=de(F),Ne(),ee()})},Me(),ut(),{destroy(){jt.disconnect(),I&&be&&I.unobserve(be),D&&b&&D.unobserve(b),Ut(),e.removeEventListener("me-video-inspector-open",At),e.removeEventListener(Ht,Mt),e.removeEventListener("click",mt,!0),window.removeEventListener("resize",ee),_=!1,Ne(),ae?.remove(),k?.remove(),s.remove(),Pt(e)}}}function aa(e,t,n){Qt(),kn();const r=Ao(n()),i=_i(r),s=new Map(i.map(f=>[String(f.id??""),f])),u=i.find(f=>f.id)?.id??"",p=document.createElement("div");p.className="me-video-text-panel me-video-color-panel me-video-filter-panel",p.hidden=!0,e.appendChild(p);const v=document.createElement("div");v.className="me-video-text-toolbar";const w=document.createElement("strong");w.textContent=r.filterTitle;const z=Yt(r.reset);v.append(w,z);const te=Kt(r.presets),S=document.createElement("div");S.className="me-video-color-grid",te.body.appendChild(S);const B=i.map(f=>{const g=document.createElement("button");g.type="button",g.className="me-video-color-card",g.dataset.presetId=f.id??"";const $=document.createElement("div");$.className="me-video-color-preview",$.style.filter=f.css||"none";const fe=document.createElement("img");fe.alt="",fe.draggable=!1,fe.hidden=!0,$.appendChild(fe);const ge=document.createElement("div");return ge.className="me-video-color-card-title",ge.textContent=f.label,g.append($,ge),S.appendChild(g),{entry:f,buttonEl:g,previewImage:fe}});p.append(v,te.section);let V=null,ie=null,J=null,oe=null,le=null,xe=null,ae=null,be=null,se=null,k=null,b=null,_=null,h=!1,y=null,N=!1,j=!1,re="";const I="filter",D=typeof requestAnimationFrame=="function"?requestAnimationFrame:f=>setTimeout(f,16),K=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>U()),M=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>U()),X=[{key:"tl",x:0,y:0},{key:"tm",x:.5,y:0},{key:"tr",x:1,y:0},{key:"mr",x:1,y:.5},{key:"br",x:1,y:1},{key:"bm",x:.5,y:1},{key:"bl",x:0,y:1},{key:"ml",x:0,y:.5}],Q={key:"rotate",x:.5,y:0};function ce(){Promise.resolve().then(()=>{j=!1;const f=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,f-1)})}function W(f){j=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return f()}finally{ce()}}function U(){N||(N=!0,D(()=>{N=!1,Mt()}))}function T(f=ie){return f?[...f.children].filter(g=>g instanceof HTMLButtonElement&&g!==oe&&!g.classList.contains("me-video-text-tool")):[]}function A(f){const g=[r.filterTool,r.filterTitle,"filter","filters","\u6EE4\u955C","\u6FFE\u93E1"].map($=>String($??"").trim().toLowerCase()).filter(Boolean);return f.find($=>{const fe=Io($);return g.some(ge=>fe.includes(ge))})??f[3]??null}function de(){J&&(J.classList.contains("is-active")||J.click())}function Ne(){rn(e,p),Pt(e)}function R(f){const g=!!f;if(g===h){Mt();return}h=g,h&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:I}})),Mt()}function ee(){if(V?.classList.toggle("is-active",h),!!J&&h){J.classList.remove("is-active");return}}function Y(){p.hidden=!h,ee(),Ne()}function G(){const f=t.getState().overlays??[];if(y==null)return null;const g=f[y];return g?.type==="filter"?g:null}function pe(){return Tn(t)}function qe(){return yn(e)}function He(){if(!t.history?.present)return;const f=qe(),g=Number(t.history.present.__mePreviewTimelineTime);Math.abs((Number.isFinite(g)?g:-1)-f)<.001||(t.history={...t.history,present:{...t.history.present,__mePreviewTimelineTime:f}},typeof t.emit=="function"&&t.emit())}function Je(f){if(!f.length){y=null;return}const g=mr(e,t.getState());y=g.length?g[g.length-1]:null}function Ge(f){return String(f?.filterPreset??"").trim()}function Ye(f){return s.get(Ge(f))??null}function dt(f){return Ye(f)?.css||"none"}function rt(f){return Ye(f)?.label||r.filterTitle}function ze(f){const g=Number(f?.w),$=Number(f?.h);return!(g>0)||!($>0)?null:{x:Number(f?.x)||0,y:Number(f?.y)||0,w:Math.max(48,g),h:Math.max(48,$)}}function it(f,g){const $=ze(f);if(!$)return f;const fe=Math.max(.1,Number(g)||1);return{...f,w:Math.max(48,$.w*fe),h:Math.max(48,$.h*fe)}}function xt(f,g,$={}){const ge=(t.getState().overlays??[])[f];!ge||ge.type!=="filter"||t.updateOverlay(f,Jt(ge,pe(),g),$)}function wt(f,g){y!=null&&t.updateOverlay(y,f,g)}function ke(f){if(typeof t.applyMut=="function"){t.applyMut($=>({...$,overlays:[...on($.overlays),{...f,timelineTrack:0}]}));return}const g=on(t.getState().overlays);t.commit?.({overlays:[...g,{...f,timelineTrack:0}]})}function Re(f=u){const g=t.getState().canvas??{w:1080,h:1920},$=ue(Math.round((Number(g.w)||1080)*.68),180,Math.max(180,(Number(g.w)||1080)-48)),fe=ue(Math.round((Number(g.h)||1920)*.3),120,Math.max(120,(Number(g.h)||1920)-48));return{type:"filter",x:Math.round(((Number(g.w)||1080)-$)/2),y:Math.round(((Number(g.h)||1920)-fe)/2),w:$,h:fe,rotation:0,filterPreset:f||void 0}}function Me(f=u){const g=pe();let $=ue(qe(),0,Math.max(0,g-je)),fe=Math.min(g,$+qt);fe-$<je&&($=ue(g-qt,0,Math.max(0,g-je)),fe=Math.max($+je,g));const ge={...Re(f),...Jt(null,g,{startAt:$,endAt:fe,timelineTrack:0})};ke(ge);const we=t.getState().overlays??[];y=we.length?we.length-1:null,y!=null&&bt(e,"text",[y]),ht(!0),de(),R(!0)}function et(f){if(!G()){Me(f);return}wt({filterPreset:f||void 0}),R(!0)}function tt(f){if(f){if(!re){f.hidden=!0,f.removeAttribute("src");return}f.src!==re&&(f.src=re),f.hidden=!1}}function ht(f=!1){if(re&&!f)return;const g=Vi(e);g&&(g===re&&!f||(re=g,B.forEach(({previewImage:$})=>tt($))))}function gt(){G()&&wt({filterPreset:void 0})}function me(){W(()=>{const f=e.querySelector(".me-video-toolrail");if(!f)return;ie=f;const g=T(ie);J=io(g),le=A(g),le?(oe?.remove(),V=le):((!oe||!oe.isConnected)&&(oe=document.createElement("button"),oe.type="button",oe.className="me-video-text-tool me-video-filter-tool",oe.innerHTML=`<span class="me-video-text-tool-icon">\u25A3</span><span class="me-video-text-tool-label">${r.filterTool}</span>`),oe.title=r.filterTool,oe.setAttribute("aria-label",r.filterTool),oe.isConnected?le?.parentElement===ie&&oe.nextSibling!==le&&ie.insertBefore(oe,le):le?.parentElement===ie?ie.insertBefore(oe,le):ie.appendChild(oe),V=oe),V?.setAttribute?.("title",r.filterTool),V?.setAttribute?.("aria-label",r.filterTool),ee(),Ne()})}function Le(){const{timelineInner:f,timelineHost:g}=$n(e,t.getState());if(!f||!g){ae?.remove(),ae=null,K&&be&&(K.unobserve(be),be=null),xe=null;return}xe=f,(!ae||!ae.isConnected||ae.parentElement!==g)&&(ae?.remove(),ae=document.createElement("div"),ae.className="me-video-text-timeline me-video-overlay-timeline me-video-filter-overlay-layer");for(const $ of[...g.children])$!==ae&&$ instanceof HTMLElement&&$.classList.contains("me-video-filter-overlay-layer")&&$.remove();(ae.parentElement!==g||g.lastElementChild!==ae)&&g.appendChild(ae),K&&be!==xe&&(be&&K.unobserve(be),be=xe,K.observe(xe))}function Ve(){const f=e.querySelector(".me-video-canvas-stage");if(!f){k?.remove(),k=null,b?.remove(),b=null,M&&_&&(M.unobserve(_),_=null),se=null;return}se=f,se.style.position="relative",(!k||!k.isConnected||k.parentElement!==se)&&(k?.remove(),k=document.createElement("div"),k.className="me-video-filter-effect-layer",se.appendChild(k)),(!b||!b.isConnected||b.parentElement!==se)&&(b?.remove(),b=document.createElement("div"),b.className="me-video-filter-control-layer",se.appendChild(b)),se.lastElementChild!==b&&se.appendChild(b),M&&_!==se&&(_&&M.unobserve(_),_=se,M.observe(se))}function Ze(){if(!se)return null;const g=t.getState().canvas??{},$=Math.max(1,Number(g.w)||0),fe=Math.max(1,Number(g.h)||0);if(!$||!fe)return null;const ge=se.getBoundingClientRect(),we=se.querySelector("canvas, video, img")||[...se.children].find(De=>De!==k&&De!==b)||null;let Be=0,Se=0,$e=se.clientWidth||$,Ae=se.clientHeight||fe;if(we instanceof HTMLElement){const De=we.getBoundingClientRect();De.width>0&&De.height>0&&(Be=De.left-ge.left,Se=De.top-ge.top,$e=De.width,Ae=De.height)}if(!($e>0&&Ae>0)){const De=se.clientWidth||$,Qe=se.clientHeight||fe,Ie=Math.min(De/$,Qe/fe)||1;$e=$*Ie,Ae=fe*Ie,Be=Math.max(0,(De-$e)/2),Se=Math.max(0,(Qe-Ae)/2)}return{stageLeft:ge.left,stageTop:ge.top,left:Be,top:Se,scaleX:$e/$,scaleY:Ae/fe}}function at(f,g){const $=lt(f),fe=Bt(f,$);return g>=$-.001&&g<=fe+.001}function Et(f,g,$){const fe=zt(e,"text",f,g,$);y=fe.length?fe[fe.length-1]:null,R(!0),Mt()}function St(f,g,$){return{x:(f-$.stageLeft-$.left)/$.scaleX,y:(g-$.stageTop-$.top)/$.scaleY}}function Rt(f,g,$){const fe=(t.getState().overlays??[])[f];if(!fe||fe.type!=="filter")return;const ge=t.getState().canvas??{w:1080,h:1920},we=ze(fe);if(!we)return;const Be=g.clientX,Se=g.clientY,$e=Math.max(0,(Number(ge.w)||0)-we.w),Ae=Math.max(0,(Number(ge.h)||0)-we.h),De=(Pe,Ue,ct)=>{const pt=(Pe-Be)/$.scaleX,Ke=(Ue-Se)/$.scaleY,nt=ue(we.x+pt,0,$e),ot=ue(we.y+Ke,0,Ae);t.updateOverlay(f,{x:nt,y:ot},ct?{transient:!0}:void 0)},Qe=Pe=>{Pe.preventDefault(),De(Pe.clientX,Pe.clientY,!0)},Ie=Pe=>{window.removeEventListener("pointermove",Qe),window.removeEventListener("pointerup",Ie),window.removeEventListener("pointercancel",Ie),De(Pe.clientX,Pe.clientY,!1)};window.addEventListener("pointermove",Qe),window.addEventListener("pointerup",Ie),window.addEventListener("pointercancel",Ie)}function ut(f,g,$,fe){const ge=(t.getState().overlays??[])[f];if(!ge||ge.type!=="filter")return;const we=ze(ge);if(!we)return;const Be=t.getState().canvas??{w:1080,h:1920},Se=g.x===.5?.5:1-g.x,$e=g.y===.5?.5:1-g.y,Ae=we.x+we.w*Se,De=we.y+we.h*$e,Qe=Math.max(.1,48/Math.max(48,we.w),48/Math.max(48,we.h)),Ie=g.x===.5?1/0:Math.max(.1,(Se===0?(Number(Be.w)||0)-Ae:Ae)/Math.max(1,we.w)),Pe=g.y===.5?1/0:Math.max(.1,($e===0?(Number(Be.h)||0)-De:De)/Math.max(1,we.h)),Ue=Math.max(Qe,Math.min(Ie,Pe,8)),ct=(nt,ot,Ot)=>{const Ft=St(nt,ot,fe),kt=[];g.x!==.5&&kt.push(Math.abs(Ft.x-Ae)/Math.max(1,we.w)),g.y!==.5&&kt.push(Math.abs(Ft.y-De)/Math.max(1,we.h));const ln=kt.length?Math.max(...kt):1,an=ue(ln,Qe,Ue),en=it(ge,an),Ct=ze(en);if(!Ct)return;const tn=Ae-Ct.w*Se,m=De-Ct.h*$e;t.updateOverlay(f,{x:tn,y:m,w:Ct.w,h:Ct.h},Ot?{transient:!0}:void 0)},pt=nt=>{nt.preventDefault(),ct(nt.clientX,nt.clientY,!0)},Ke=nt=>{window.removeEventListener("pointermove",pt),window.removeEventListener("pointerup",Ke),window.removeEventListener("pointercancel",Ke),ct(nt.clientX,nt.clientY,!1)};window.addEventListener("pointermove",pt),window.addEventListener("pointerup",Ke),window.addEventListener("pointercancel",Ke)}function It(f,g,$){const fe=(t.getState().overlays??[])[f];if(!fe||fe.type!=="filter")return;const ge=ze(fe);if(!ge)return;const we=$.stageLeft+$.left+(ge.x+ge.w/2)*$.scaleX,Be=$.stageTop+$.top+(ge.y+ge.h/2)*$.scaleY,Se=Math.atan2(g.clientY-Be,g.clientX-we),$e=un(fe),Ae=(Ie,Pe,Ue,ct)=>{const pt=Math.atan2(Pe-Be,Ie-we);let Ke=In($e+(pt-Se)*180/Math.PI);ct&&(Ke=Math.round(Ke/15)*15),t.updateOverlay(f,{rotation:Ke},Ue?{transient:!0}:void 0)},De=Ie=>{Ie.preventDefault(),Ae(Ie.clientX,Ie.clientY,!0,Ie.shiftKey)},Qe=Ie=>{window.removeEventListener("pointermove",De),window.removeEventListener("pointerup",Qe),window.removeEventListener("pointercancel",Qe),Ae(Ie.clientX,Ie.clientY,!1,Ie.shiftKey)};window.addEventListener("pointermove",De),window.addEventListener("pointerup",Qe),window.addEventListener("pointercancel",Qe)}function Lt(f,g){if(Ve(),!k||!b)return;if(k.replaceChildren(),b.replaceChildren(),!Ze()){k.hidden=!0,b.hidden=!0;return}b.hidden=!0;const fe=qe();if(!f.filter(we=>at(we.overlay,fe)).length){k.hidden=!0;return}k.hidden=!0}function jt(f,g,$){if(!xe)return;const fe=(t.getState().overlays??[])[f];if(!fe||fe.type!=="filter")return;if($.shiftKey||$.ctrlKey||$.metaKey){$.preventDefault(),$.stopPropagation();const Pe=zt(e,"text",f,$,lr(t.getState()).map(Ue=>Ue.index));y=Pe.length?Pe[Pe.length-1]:null,de(),R(!0);return}$.preventDefault(),$.stopPropagation(),y=f,bt(e,"text",[f]),de(),h||R(!0);const ge=pe(),we=Math.max(xe.clientWidth/ge,.001),Be=lt(fe),Se=Bt(fe,Be),$e=Math.max(je,Se-Be),Ae=vt(fe),De=$.clientX,Qe=Pe=>{const Ue=(Pe.clientX-De)/we,ct=t.getState().overlays??[];if(g==="move"){const nt=Math.max(0,Be+Ue),ot=nt+$e,Ot=ft(ae,ct,f,nt,ot,Pe.clientY,Ae);xt(f,{startAt:nt,endAt:ot,timelineTrack:Ot},{transient:!0});return}if(g==="start"){const nt=ue(Be+Ue,0,Se-je),ot=ft(ae,ct,f,nt,Se,Pe.clientY,Ae);xt(f,{startAt:nt,endAt:Se,timelineTrack:ot},{transient:!0});return}const pt=Math.max(Be+je,Se+Ue),Ke=ft(ae,ct,f,Be,pt,Pe.clientY,Ae);xt(f,{startAt:Be,endAt:pt,timelineTrack:Ke},{transient:!0})},Ie=Pe=>{window.removeEventListener("pointermove",Qe),window.removeEventListener("pointerup",Ie),window.removeEventListener("pointercancel",Ie);const Ue=(Pe.clientX-De)/we,ct=t.getState().overlays??[];if(g==="move"){const nt=Math.max(0,Be+Ue),ot=nt+$e,Ot=ft(ae,ct,f,nt,ot,Pe.clientY,Ae);xt(f,{startAt:nt,endAt:ot,timelineTrack:Ot});return}if(g==="start"){const nt=ue(Be+Ue,0,Se-je),ot=ft(ae,ct,f,nt,Se,Pe.clientY,Ae);xt(f,{startAt:nt,endAt:Se,timelineTrack:ot});return}const pt=Math.max(Be+je,Se+Ue),Ke=ft(ae,ct,f,Be,pt,Pe.clientY,Ae);xt(f,{startAt:Be,endAt:pt,timelineTrack:Ke})};window.addEventListener("pointermove",Qe),window.addEventListener("pointerup",Ie),window.addEventListener("pointercancel",Ie),Mt()}function At(f,g){if(Le(),!ae||!xe||(ae.replaceChildren(),ae.hidden=f.length===0,!f.length))return;const $=pe(),fe=xe.clientWidth/$,ge=Fn(t.getState()),we=new Map;for(const Be of f){const Se=vt(Be.overlay),$e=ge.get(Se)??Se;let Ae=we.get(Se);Ae||(Ae=document.createElement("div"),Ae.className="me-video-overlay-track-row",Ae.dataset.track=String(Se),Ae.style.top=`${Ln($e)}px`,we.set(Se,Ae),ae.appendChild(Ae));const De=document.createElement("div");De.className="me-video-text-track-clip me-video-filter-track-clip",g.has(Be.index)&&De.classList.add("is-active");const Qe=lt(Be.overlay),Ie=Sn(Be.overlay);De.style.left=`${Qe*fe}px`,De.style.width=`${Math.max(36,Ie*fe)}px`;const Pe=document.createElement("span");Pe.className="me-video-text-track-icon",Pe.textContent="Fx";const Ue=document.createElement("span");Ue.className="me-video-text-track-label",Ue.textContent=rt(Be.overlay),Ue.title=Ue.textContent;const ct=document.createElement("span");ct.className="me-video-text-track-handle is-start";const pt=document.createElement("span");pt.className="me-video-text-track-handle is-end",De.append(Pe,Ue,ct,pt),De.addEventListener("pointerdown",Ke=>jt(Be.index,"move",Ke)),ct.addEventListener("pointerdown",Ke=>jt(Be.index,"start",Ke)),pt.addEventListener("pointerdown",Ke=>jt(Be.index,"end",Ke)),De.addEventListener("click",Ke=>{if(Ke.preventDefault(),Ke.stopPropagation(),Ke.shiftKey||Ke.ctrlKey||Ke.metaKey){de(),Mt();return}const nt=zt(e,"text",Be.index,Ke,f.map(ot=>ot.index));y=nt.length?nt[nt.length-1]:null,de(),R(!0),Mt()}),Ae.appendChild(De)}}function Mt(){W(()=>{me(),ht();const f=lr(t.getState());Je(f);const g=new Set(mr(e,t.getState()));At(f,g),Lt(f,g);const $=Ge(G());B.forEach(({entry:fe,buttonEl:ge,previewImage:we})=>{ge.classList.toggle("is-active",String(fe.id??"")===$),tt(we)}),z.disabled=!$,Y(),Ne()}),He()}function mt(f){return!!f&&(f===p||p.contains(f)||f===V||V?.contains?.(f)||f===oe||oe?.contains?.(f)||f===ae||ae?.contains?.(f)||f===k||k?.contains?.(f)||f===b||b?.contains?.(f))}function Ut(f){return f.some(g=>{if(!mt(g.target))return!0;for(const $ of g.addedNodes)if(!mt($))return!0;for(const $ of g.removedNodes)if(!mt($))return!0;return!1})}const E=new MutationObserver(f=>{j||e.__meVideoEnhancerObserverLock||Ut(f)&&(me(),U())}),F=f=>{const g=f.target;!(g instanceof Node)||!V||!V.contains(g)||(f.preventDefault(),f.stopPropagation(),f.stopImmediatePropagation?.(),Me(u))},Z=f=>{f?.detail?.id!==I&&h&&(h=!1,Mt())},Te=()=>{Mt()};E.observe(e,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["class","style","hidden"]}),e.addEventListener("me-video-inspector-open",Z),e.addEventListener(Ht,Te),e.addEventListener("click",F,!0),window.addEventListener("resize",Ne);const Fe=t.subscribe(()=>{Mt()});return B.forEach(({entry:f,buttonEl:g})=>{g.addEventListener("click",()=>{et(f.id||"")})}),z.addEventListener("click",()=>{gt()}),me(),Mt(),{destroy(){E.disconnect(),K&&be&&K.unobserve(be),M&&_&&M.unobserve(_),Fe(),e.removeEventListener("me-video-inspector-open",Z),e.removeEventListener(Ht,Te),e.removeEventListener("click",F,!0),window.removeEventListener("resize",Ne),oe?.remove(),ae?.remove(),k?.remove(),b?.remove(),p.remove(),Pt(e)}}}function sa(e,t,n,r){Qt();const i=Ao(r()),s=Kr(r()),u=Sr(i),p=document.createElement("div");p.className="me-video-text-panel me-video-color-panel me-video-effects-panel",p.hidden=!0,e.appendChild(p);const v=document.createElement("div");v.className="me-video-text-toolbar";const w=document.createElement("strong");w.textContent=s.title;const z=Yt(i.reset),te=Yt(s.close);v.append(w,z,te),p.appendChild(v);const S=document.createElement("p");S.className="me-video-text-hint",S.textContent=s.hint,p.appendChild(S);const B=u.map(R=>{const ee=Kt(R.title),Y=R.items.map(G=>{const pe=document.createElement("div");pe.className="me-video-color-slider-control";const qe=document.createElement("span");qe.className="me-video-color-slider-value";const He=document.createElement("input");return He.type="range",He.min=String(G.min),He.max=String(G.max),He.step="0.02",He.dataset.adjustment=G.key,pe.append(qe,He),ee.body.appendChild(Tt(G.label,pe)),{...G,value:qe,range:He}});return p.appendChild(ee.section),{...R,controls:Y}});let V=null,ie=null,J=null,oe=null,le=!1,xe=!1,ae=!1;const be="effects",se=typeof requestAnimationFrame=="function"?requestAnimationFrame:R=>setTimeout(R,16);function k(){Promise.resolve().then(()=>{ae=!1;const R=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,R-1)})}function b(R){ae=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return R()}finally{k()}}function _(){xe||(xe=!0,se(()=>{xe=!1,Q()}))}function h(R=ie){return R?[...R.children].filter(ee=>ee instanceof HTMLButtonElement&&ee!==V&&!ee.classList.contains("me-video-text-tool")):[]}function y(){oe&&(oe.isConnected&&(oe.style.display=oe.dataset.meTrimDisplay??"",oe.hidden=oe.dataset.meTrimHidden==="true",delete oe.dataset.meTrimDisplay,delete oe.dataset.meTrimHidden),oe=null)}function N(R){if(!R){y();return}oe!==R&&(y(),R.classList.remove("is-active"),R.dataset.meTrimDisplay=R.style.display??"",R.dataset.meTrimHidden=R.hidden?"true":"false",R.hidden=!0,R.style.display="none",oe=R)}function j(){if(J&&!J.classList.contains("is-active")){J.click();return}const R=h()[0];R&&!R.classList.contains("is-active")&&R.click()}function re(R){if(!V||!(R instanceof HTMLButtonElement))return;const ee=R.getAttribute("style");ee?V.setAttribute("style",ee):V.removeAttribute("style"),V.hidden=!1,V.style.display=""}function I(){V&&(V.dataset.theme=Rn(n()))}function D(){rn(e,p),Pt(e)}function K(R){const ee=!!R;if(ee===le){Q();return}le=ee,le&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:be}})),Q()}function M(){if(V?.classList.toggle("is-active",le),!!J&&le){J.classList.remove("is-active");return}}function X(){p.hidden=!le,M(),D()}function Q(){b(()=>{h().find(G=>G!==J&&!G.hidden&&G.style.display!=="none"&&G.classList.contains("is-active"))&&(le=!1),le&&j();const ee=t.getState().filters??{},Y=Po.some(G=>Math.abs(Number(ee[G])||0)>1e-4);B.forEach(G=>{G.controls.forEach(pe=>{const qe=ue(Number(ee[pe.key])||0,pe.min,pe.max);pe.range.value=String(qe),pe.value.textContent=Lr(qe,pe.format)})}),z.disabled=!Y,X(),I()})}function ce(){b(()=>{const R=e.querySelector(".me-video-toolrail");if(!R)return;ie=R;const ee=h(ie);J=io(ee),N(J);const Y=J??ee[0]??null;(!V||!V.isConnected)&&(V=document.createElement("button"),V.type="button",V.className="me-video-text-tool me-video-effects-tool",V.innerHTML=`<span class="me-video-text-tool-icon">${Zr()}</span><span class="me-video-text-tool-label">${s.tool}</span>`),V.setAttribute("title",s.tool),V.setAttribute("aria-label",s.tool),re(Y),V.isConnected?Y?.parentElement===ie&&V.nextSibling!==Y&&ie.insertBefore(V,Y):Y?.parentElement===ie?ie.insertBefore(V,Y):ie.appendChild(V),I(),M(),D()})}function W(R){return!!R&&(R===p||p.contains(R)||R===V||V?.contains?.(R))}function U(R){return R.some(ee=>{if(!W(ee.target))return!0;for(const Y of ee.addedNodes)if(!W(Y))return!0;for(const Y of ee.removedNodes)if(!W(Y))return!0;return!1})}const T=new MutationObserver(R=>{ae||e.__meVideoEnhancerObserverLock||U(R)&&(ce(),_())}),A=R=>{R?.detail?.id!==be&&le&&(le=!1,Q())},de=R=>{const ee=R.target;if(!(ee instanceof Node)||!V||!V.contains(ee))return;R.preventDefault(),R.stopPropagation(),R.stopImmediatePropagation?.();const Y=!le;Y&&j(),K(Y)};T.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","style","hidden"]}),e.addEventListener("me-video-inspector-open",A),e.addEventListener("click",de,!0),window.addEventListener("resize",_);const Ne=t.subscribe(()=>{_()});return B.forEach(R=>{R.controls.forEach(ee=>{ee.range.addEventListener("input",()=>{const Y=ue(Number(ee.range.value)||0,ee.min,ee.max);ee.value.textContent=Lr(Y,ee.format),t.setFilter(ee.key,Y,{transient:!0})}),ee.range.addEventListener("change",()=>{const Y=ue(Number(ee.range.value)||0,ee.min,ee.max);t.setFilter(ee.key,Y)})})}),z.addEventListener("click",()=>{Di(t)}),te.addEventListener("click",()=>{K(!1)}),ce(),Q(),{destroy(){T.disconnect(),Ne(),e.removeEventListener("me-video-inspector-open",A),e.removeEventListener("click",de,!0),window.removeEventListener("resize",_),y(),V?.remove(),p.remove(),Pt(e)}}}function la(e,t,n,r){Qt(),kn();const i=Ao(r()),s=Gr(r()),u=Sr(i),p=new Set(["brightness","contrast","saturation","temperature","tint","vibrance","gamma","highlights","shadows","whites","blacks","lightSense"]);function v(l,d,o){return l==="percent"?{min:(1+d)*100,max:(1+o)*100}:{min:d*100,max:o*100}}function w(l,d){const o=Number(l)||0;return d==="percent"?(1+o)*100:o*100}function z(l,d){const o=Number(l)||0;return d==="percent"?o/100-1:o/100}function te(l,d){const o=Math.round(w(l,d)*10)/10;return Number.isInteger(o),String(o)}function S(l,d){let o=Math.abs(Math.round(Number(l)||0)),a=Math.abs(Math.round(Number(d)||0));for(;a;){const c=o%a;o=a,a=c}return o||1}function B(l){const d=Math.max(1,Vt(l?.w??0)),o=Math.max(1,Vt(l?.h??0)),a=S(d,o);return`${d/a}:${o/a}`}function V(l){const d=Number(l);if(!(d>0))return s.notAvailable;const o=["B","KB","MB","GB","TB"];let a=d,c=0;for(;a>=1024&&c<o.length-1;)a/=1024,c+=1;const x=a>=100||c===0?0:a>=10?1:2;return`${a.toFixed(x)} ${o[c]}`}function ie(l){const d=Number(l);return d>0?`${d.toFixed(2)} fps`:s.notAvailable}function J(l,d){const o=Number(l),a=Number(d);if(!(o>0)||!(a>0))return s.notAvailable;const c=o*8/a;return c>=1e6?`${(c/1e6).toFixed(2)} Mbps`:c>=1e3?`${Math.round(c/1e3)} Kbps`:`${Math.round(c)} bps`}function oe(l){const d=String(l?.file?.type||l?.type||l?.mime||"").trim();if(d.includes("/"))return d.split("/").pop().toUpperCase();const a=String(l?.file?.name||l?.name||"").trim().match(/\.([a-z0-9]+)$/i);return a?a[1].toUpperCase():s.notAvailable}function le(l){return String(l?.codec||l?.videoCodec||l?.codecName||l?.encoding||"").trim()||s.notAvailable}function xe(l){const d=Math.max(0,Math.round(Number(l?.width??l?.dims?.w)||0)),o=Math.max(0,Math.round(Number(l?.height??l?.dims?.h)||0));return!(d>0)||!(o>0)?s.notAvailable:`${d} x ${o} px`}function ae(){const d=t.getState().clips??[],o=_t(e,"video").filter(P=>!!d[P]),c=(d[o[o.length-1]]??d[0]??null)?.srcIdx??0;return{source:(typeof t.getVideoSource=="function"?t.getVideoSource(c):null)??t.videoSources?.[c]??t.videoSources?.[0]??null,sourceIndex:c}}function be(){const l=t.getState(),{source:d,sourceIndex:o}=ae(),a=l.canvas??{w:1080,h:1920},c=Vn(l),x=Number(d?.frameRate??d?.fps)||30,P=Number(d?.duration)||Me()||0,C=Number(d?.file?.size??d?.size)||0;return{videoName:String(d?.file?.name||d?.name||"").trim()||(d?`video-${o+1}`:s.notAvailable),ratio:B(c),canvasSize:On(a),resolution:On(c),frameRate:ie(x),bitrate:J(C,P),format:oe(d),fileSize:V(C),codec:le(d),sourceSize:xe(d),videoLength:mn(Me())}}const se=document.createElement("div");se.className="me-video-text-panel me-video-color-panel me-video-effects-panel me-video-feature-one-panel",se.hidden=!0,e.appendChild(se);const k=document.createElement("div");k.className="me-video-text-toolbar";const b=document.createElement("strong");b.textContent=s.title;const _=Yt(i.reset);k.append(b,_);const h=document.createElement("p");h.className="me-video-text-hint",h.textContent=s.hint;const y=document.createElement("div");y.className="me-video-text-empty",y.textContent=s.placeholder;const N=document.createElement("div");N.className="me-video-text-panel me-video-feature-one-info-panel",N.hidden=!0,e.appendChild(N);const j=document.createElement("div");j.className="me-video-text-toolbar";const re=document.createElement("strong");re.textContent=s.videoInfoTitle,j.append(re);const I=Kt(s.videoInfoTitle);I.section.classList.add("me-video-feature-one-meta-section"),I.title.remove();const D=[{key:"videoName",label:s.videoName},{key:"ratio",label:s.ratio},{key:"canvasSize",label:s.canvasSize},{key:"resolution",label:s.resolution},{key:"frameRate",label:s.frameRate},{key:"bitrate",label:s.bitrate},{key:"format",label:s.format},{key:"fileSize",label:s.fileSize},{key:"codec",label:s.codec},{key:"sourceSize",label:s.sourceSize},{key:"videoLength",label:s.videoLength}].map(l=>{const d=document.createElement("div");return d.className="me-video-feature-one-meta-value",I.body.appendChild(Tt(l.label,d)),{...l,valueEl:d}});se.append(k,h,y),N.append(j,I.section);const K=u.map(l=>{const d=Kt(l.title),o=l.items.map(a=>{const c=v(a.format,a.min,a.max),x=document.createElement("div");x.className="me-video-color-slider-control me-video-color-number-control";const P=document.createElement("input");P.type="range",P.min=String(a.min),P.max=String(a.max),P.step="0.01",P.dataset.adjustment=a.key;const C=document.createElement("input");return C.type="number",C.min=String(c.min),C.max=String(c.max),C.step="1",C.inputMode="decimal",C.dataset.adjustment=a.key,x.append(P,C),d.body.appendChild(Tt(a.label,x)),{...a,range:P,input:C,displayMin:c.min,displayMax:c.max}});return se.appendChild(d.section),{...l,section:d.section,controls:o}});let M=null,X=null,Q=null,ce=null,W=null,U=null,T=null,A=null,de=null,Ne=null,R=null,ee=!1,Y=null,G=!1,pe=!1;const qe="adjust",He=typeof requestAnimationFrame=="function"?requestAnimationFrame:l=>setTimeout(l,16),Je=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>it()),Ge=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>it()),Ye=[{key:"tl",x:0,y:0},{key:"tm",x:.5,y:0},{key:"tr",x:1,y:0},{key:"mr",x:1,y:.5},{key:"br",x:1,y:1},{key:"bm",x:.5,y:1},{key:"bl",x:0,y:1},{key:"ml",x:0,y:.5}],dt={key:"rotate",x:.5,y:0};function rt(){Promise.resolve().then(()=>{pe=!1;const l=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,l-1)})}function ze(l){pe=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return l()}finally{rt()}}function it(){G||(G=!0,He(()=>{G=!1,ot()}))}function xt(l=X){return l?[...l.children].filter(d=>d instanceof HTMLButtonElement&&d!==M&&!d.classList.contains("me-video-text-tool")):[]}function wt(){ce&&(ce.isConnected&&(ce.style.display=ce.dataset.meTrimDisplay??"",ce.hidden=ce.dataset.meTrimHidden==="true",delete ce.dataset.meTrimDisplay,delete ce.dataset.meTrimHidden),ce=null)}function ke(l){if(!l){wt();return}ce!==l&&(wt(),l.classList.remove("is-active"),l.dataset.meTrimDisplay=l.style.display??"",l.dataset.meTrimHidden=l.hidden?"true":"false",l.hidden=!0,l.style.display="none",ce=l)}function Re(){if(Q&&!Q.classList.contains("is-active")){Q.click();return}const l=xt()[0];l&&!l.classList.contains("is-active")&&l.click()}function Me(){return Tn(t)}function et(){return yn(e)}function tt(){if(!t.history?.present)return;const l=et(),d=Number(t.history.present.__mePreviewTimelineTime);Math.abs((Number.isFinite(d)?d:-1)-l)<.001||(t.history={...t.history,present:{...t.history.present,__mePreviewTimelineTime:l}},typeof t.emit=="function"&&t.emit())}function ht(l){const d={...An};for(const o of Po){const a=Number(l?.[o]);Number.isFinite(a)&&(d[o]=p.has(o)?ue(a,-1,1):ue(a,0,1))}return d}function gt(l){const d=ht(l);return Po.some(o=>Math.abs(Number(d[o])||0)>1e-4)}function me(l){const d=ht(l),o=[],a=Yr(d,"");return a&&o.push(a),Math.abs(d.vibrance)>1e-4&&o.push(`saturate(${(1+d.vibrance*.65).toFixed(3)})`),Math.abs(d.temperature)>1e-4&&(d.temperature>0&&o.push(`sepia(${Math.min(.36,d.temperature*.28).toFixed(3)})`),o.push(`hue-rotate(${(-d.temperature*14).toFixed(2)}deg)`)),Math.abs(d.tint)>1e-4&&o.push(`hue-rotate(${(d.tint*10).toFixed(2)}deg)`),Math.abs(d.gamma)>1e-4&&o.push(`brightness(${(1+d.gamma*.08).toFixed(3)})`),(d.clarity>1e-4||d.sharpen>1e-4)&&o.push(`contrast(${(1+d.clarity*.16+d.sharpen*.1).toFixed(3)})`),o.join(" ").trim()||"none"}function Le(l){const d=ht(l),o=[];if(d.fade>1e-4&&o.push(`linear-gradient(0deg, rgba(255,245,235,${(d.fade*.18).toFixed(3)}), rgba(255,245,235,${(d.fade*.18).toFixed(3)}))`),d.vignette>1e-4){const a=(.28+d.vignette*.3).toFixed(3),c=(.16+d.vignette*.22).toFixed(3);o.push(`radial-gradient(circle at center, rgba(0,0,0,0) ${a}, rgba(0,0,0,${c}) 100%)`)}return d.grain>1e-4&&o.push(`linear-gradient(135deg, rgba(255,255,255,${(d.grain*.05).toFixed(3)}) 0%, rgba(0,0,0,${(d.grain*.05).toFixed(3)}) 100%)`),o.join(", ")}function Ve(){const l=t.getState().overlays??[];if(Y==null)return null;const d=l[Y];return d?.type==="adjust"?d:null}function Ze(l){if(!l.length){Y=null;return}const d=eo(e,t.getState());Y=d.length?d[d.length-1]:null}function at(l){const d=Number(l?.w),o=Number(l?.h);return!(d>0)||!(o>0)?null:{x:Number(l?.x)||0,y:Number(l?.y)||0,w:Math.max(48,d),h:Math.max(48,o)}}function Et(l,d){const o=at(l);if(!o)return l;const a=Math.max(.1,Number(d)||1);return{...l,w:Math.max(48,o.w*a),h:Math.max(48,o.h*a)}}function St(l,d,o={}){const c=(t.getState().overlays??[])[l];!c||c.type!=="adjust"||t.updateOverlay(l,Jt(c,Me(),d),o)}function Rt(l,d){Y!=null&&t.updateOverlay(Y,l,d)}function ut(l){const d=t.getState().overlays??[],o=d.length;if(typeof t.applyMut=="function")return t.applyMut(c=>({...c,overlays:[...on(c.overlays),{...l,timelineTrack:0}]})),o;const a=on(d);return t.commit?.({overlays:[...a,{...l,timelineTrack:0}]}),o}function It(){const l=t.getState().canvas??{w:1080,h:1920};return{type:"adjust",x:0,y:0,w:Math.max(1,Number(l.w)||1080),h:Math.max(1,Number(l.h)||1920),rotation:0,...An}}function Lt(){const l=Me();let d=ue(et(),0,Math.max(0,l-je)),o=Math.min(l,d+qt);o-d<je&&(d=ue(l-qt,0,Math.max(0,l-je)),o=Math.max(d+je,l));const a={...It(),...Jt(null,l,{startAt:d,endAt:o,timelineTrack:0})},c=ut(a);Y=Number.isInteger(c)?c:null,bt(e,"text",Y==null?[]:[Y],{preserveOther:!0}),Re(),pt(Y!=null)}function jt(){const l=t.getState(),d=Mo(l.overlays??[],eo(e,l));d.changed&&(t.commit({overlays:d.overlays}),Y=d.selection.length?d.selection[d.selection.length-1]:null,bt(e,"text",d.selection),ot())}function At(){const l=t.getState(),d=Co(l.overlays??[],eo(e,l));d.changed&&(t.commit({overlays:d.overlays}),Y=null,bt(e,"text",[]),ot())}function Mt(){Ve()&&Rt({...An})}function mt(l){if(!M||!(l instanceof HTMLButtonElement))return;const d=l.getAttribute("style");d?M.setAttribute("style",d):M.removeAttribute("style"),M.hidden=!1,M.style.display=""}function Ut(){M&&(M.dataset.theme=Rn(n()))}function E(){rn(e,se),rn(e,N),Pt(e)}function F(){const{timelineInner:l,timelineHost:d}=$n(e,t.getState());if(!l||!d){U?.remove(),U=null,Je&&T&&(Je.unobserve(T),T=null),W=null;return}W=l,(!U||!U.isConnected||U.parentElement!==d)&&(U?.remove(),U=document.createElement("div"),U.className="me-video-text-timeline me-video-overlay-timeline me-video-feature-one-overlay-layer");for(const o of[...d.children])o!==U&&o instanceof HTMLElement&&o.classList.contains("me-video-feature-one-overlay-layer")&&o.remove();(U.parentElement!==d||d.lastElementChild!==U)&&d.appendChild(U),Je&&T!==W&&(T&&Je.unobserve(T),T=W,Je.observe(W))}function Z(){const l=e.querySelector(".me-video-canvas-stage");if(!l){de?.remove(),de=null,Ne?.remove(),Ne=null,Ge&&R&&(Ge.unobserve(R),R=null),A=null;return}A=l,A.style.position="relative",(!de||!de.isConnected||de.parentElement!==A)&&(de?.remove(),de=document.createElement("div"),de.className="me-video-filter-effect-layer",A.appendChild(de)),(!Ne||!Ne.isConnected||Ne.parentElement!==A)&&(Ne?.remove(),Ne=document.createElement("div"),Ne.className="me-video-filter-control-layer",A.appendChild(Ne)),A.lastElementChild!==Ne&&A.appendChild(Ne),Ge&&R!==A&&(R&&Ge.unobserve(R),R=A,Ge.observe(A))}function Te(){if(!A)return null;const d=t.getState().canvas??{},o=Math.max(1,Number(d.w)||0),a=Math.max(1,Number(d.h)||0);if(!o||!a)return null;const c=A.getBoundingClientRect(),x=A.querySelector("canvas, video, img")||[...A.children].find(O=>O!==de&&O!==Ne)||null;let P=0,C=0,ne=A.clientWidth||o,L=A.clientHeight||a;if(x instanceof HTMLElement){const O=x.getBoundingClientRect();O.width>0&&O.height>0&&(P=O.left-c.left,C=O.top-c.top,ne=O.width,L=O.height)}if(!(ne>0&&L>0)){const O=A.clientWidth||o,he=A.clientHeight||a,ve=Math.min(O/o,he/a)||1;ne=o*ve,L=a*ve,P=Math.max(0,(O-ne)/2),C=Math.max(0,(he-L)/2)}return{stageLeft:c.left,stageTop:c.top,left:P,top:C,scaleX:ne/o,scaleY:L/a}}function Fe(l,d){const o=lt(l),a=Bt(l,o);return d>=o-.001&&d<=a+.001}function f(l,d,o){const a=zt(e,"text",l,d,o);Y=a.length?a[a.length-1]:null,pt(!0),ot()}function g(l,d,o){return{x:(l-o.stageLeft-o.left)/o.scaleX,y:(d-o.stageTop-o.top)/o.scaleY}}function $(l,d,o){const a=(t.getState().overlays??[])[l];if(!a||a.type!=="adjust")return;const c=t.getState().canvas??{w:1080,h:1920},x=at(a);if(!x)return;const P=d.clientX,C=d.clientY,ne=Math.max(0,(Number(c.w)||0)-x.w),L=Math.max(0,(Number(c.h)||0)-x.h),O=(Ce,Ee,ye)=>{const Oe=(Ce-P)/o.scaleX,_e=(Ee-C)/o.scaleY,Xe=ue(x.x+Oe,0,ne),We=ue(x.y+_e,0,L);t.updateOverlay(l,{x:Xe,y:We},ye?{transient:!0}:void 0)},he=Ce=>{Ce.preventDefault(),O(Ce.clientX,Ce.clientY,!0)},ve=Ce=>{window.removeEventListener("pointermove",he),window.removeEventListener("pointerup",ve),window.removeEventListener("pointercancel",ve),O(Ce.clientX,Ce.clientY,!1)};window.addEventListener("pointermove",he),window.addEventListener("pointerup",ve),window.addEventListener("pointercancel",ve)}function fe(l,d,o,a){const c=(t.getState().overlays??[])[l];if(!c||c.type!=="adjust")return;const x=at(c);if(!x)return;const P=t.getState().canvas??{w:1080,h:1920},C=d.x===.5?.5:1-d.x,ne=d.y===.5?.5:1-d.y,L=x.x+x.w*C,O=x.y+x.h*ne,he=Math.max(.1,48/Math.max(48,x.w),48/Math.max(48,x.h)),ve=d.x===.5?1/0:Math.max(.1,(C===0?(Number(P.w)||0)-L:L)/Math.max(1,x.w)),Ce=d.y===.5?1/0:Math.max(.1,(ne===0?(Number(P.h)||0)-O:O)/Math.max(1,x.h)),Ee=Math.max(he,Math.min(ve,Ce,8)),ye=(Xe,We,st)=>{const Nt=g(Xe,We,a),$t=[];d.x!==.5&&$t.push(Math.abs(Nt.x-L)/Math.max(1,x.w)),d.y!==.5&&$t.push(Math.abs(Nt.y-O)/Math.max(1,x.h));const cn=$t.length?Math.max(...$t):1,dn=ue(cn,he,Ee),Pn=Et(c,dn),hn=at(Pn);if(!hn)return;const qn=L-hn.w*C,xn=O-hn.h*ne;t.updateOverlay(l,{x:qn,y:xn,w:hn.w,h:hn.h},st?{transient:!0}:void 0)},Oe=Xe=>{Xe.preventDefault(),ye(Xe.clientX,Xe.clientY,!0)},_e=Xe=>{window.removeEventListener("pointermove",Oe),window.removeEventListener("pointerup",_e),window.removeEventListener("pointercancel",_e),ye(Xe.clientX,Xe.clientY,!1)};window.addEventListener("pointermove",Oe),window.addEventListener("pointerup",_e),window.addEventListener("pointercancel",_e)}function ge(l,d,o){const a=(t.getState().overlays??[])[l];if(!a||a.type!=="adjust")return;const c=at(a);if(!c)return;const x=o.stageLeft+o.left+(c.x+c.w/2)*o.scaleX,P=o.stageTop+o.top+(c.y+c.h/2)*o.scaleY,C=Math.atan2(d.clientY-P,d.clientX-x),ne=un(a),L=(ve,Ce,Ee,ye)=>{const Oe=Math.atan2(Ce-P,ve-x);let _e=In(ne+(Oe-C)*180/Math.PI);ye&&(_e=Math.round(_e/15)*15),t.updateOverlay(l,{rotation:_e},Ee?{transient:!0}:void 0)},O=ve=>{ve.preventDefault(),L(ve.clientX,ve.clientY,!0,ve.shiftKey)},he=ve=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",he),window.removeEventListener("pointercancel",he),L(ve.clientX,ve.clientY,!1,ve.shiftKey)};window.addEventListener("pointermove",O),window.addEventListener("pointerup",he),window.addEventListener("pointercancel",he)}function we(l,d){if(Z(),!de||!Ne)return;if(de.replaceChildren(),Ne.replaceChildren(),!Te()){de.hidden=!0,Ne.hidden=!0;return}Ne.hidden=!0;const a=et();if(!l.filter(x=>Fe(x.overlay,a)).length){de.hidden=!0;return}de.hidden=!0}function Be(l,d,o){if(!W)return;const a=(t.getState().overlays??[])[l];if(!a||a.type!=="adjust")return;if(o.shiftKey||o.ctrlKey||o.metaKey){o.preventDefault(),o.stopPropagation();const Ce=zt(e,"text",l,o,cr(t.getState()).map(Ee=>Ee.index));Y=Ce.length?Ce[Ce.length-1]:null,Re(),pt(!0);return}o.preventDefault(),o.stopPropagation(),Y=l,bt(e,"text",[l]),Re(),ee||pt(!0);const c=Me(),x=Math.max(W.clientWidth/c,.001),P=lt(a),C=Bt(a,P),ne=Math.max(je,C-P),L=vt(a),O=o.clientX,he=Ce=>{const Ee=(Ce.clientX-O)/x,ye=t.getState().overlays??[];if(d==="move"){const Xe=Math.max(0,P+Ee),We=Xe+ne,st=ft(U,ye,l,Xe,We,Ce.clientY,L);St(l,{startAt:Xe,endAt:We,timelineTrack:st},{transient:!0});return}if(d==="start"){const Xe=ue(P+Ee,0,C-je),We=ft(U,ye,l,Xe,C,Ce.clientY,L);St(l,{startAt:Xe,endAt:C,timelineTrack:We},{transient:!0});return}const Oe=Math.max(P+je,C+Ee),_e=ft(U,ye,l,P,Oe,Ce.clientY,L);St(l,{startAt:P,endAt:Oe,timelineTrack:_e},{transient:!0})},ve=Ce=>{window.removeEventListener("pointermove",he),window.removeEventListener("pointerup",ve),window.removeEventListener("pointercancel",ve);const Ee=(Ce.clientX-O)/x,ye=t.getState().overlays??[];if(d==="move"){const Xe=Math.max(0,P+Ee),We=Xe+ne,st=ft(U,ye,l,Xe,We,Ce.clientY,L);St(l,{startAt:Xe,endAt:We,timelineTrack:st});return}if(d==="start"){const Xe=ue(P+Ee,0,C-je),We=ft(U,ye,l,Xe,C,Ce.clientY,L);St(l,{startAt:Xe,endAt:C,timelineTrack:We});return}const Oe=Math.max(P+je,C+Ee),_e=ft(U,ye,l,P,Oe,Ce.clientY,L);St(l,{startAt:P,endAt:Oe,timelineTrack:_e})};window.addEventListener("pointermove",he),window.addEventListener("pointerup",ve),window.addEventListener("pointercancel",ve),ot()}function Se(l,d){if(F(),!U||!W||(U.replaceChildren(),U.hidden=l.length===0,!l.length))return;const o=Me(),a=W.clientWidth/o,c=Fn(t.getState()),x=new Map;for(const P of l){const C=vt(P.overlay),ne=c.get(C)??C;let L=x.get(C);L||(L=document.createElement("div"),L.className="me-video-overlay-track-row",L.dataset.track=String(C),L.style.top=`${Ln(ne)}px`,x.set(C,L),U.appendChild(L));const O=document.createElement("div");O.className="me-video-text-track-clip me-video-filter-track-clip",d.has(P.index)&&O.classList.add("is-active");const he=lt(P.overlay),ve=Sn(P.overlay);O.style.left=`${he*a}px`,O.style.width=`${Math.max(36,ve*a)}px`;const Ce=document.createElement("span");Ce.className="me-video-text-track-icon",Ce.textContent="Adj";const Ee=document.createElement("span");Ee.className="me-video-text-track-label",Ee.textContent=s.tool,Ee.title=Ee.textContent;const ye=document.createElement("span");ye.className="me-video-text-track-handle is-start";const Oe=document.createElement("span");Oe.className="me-video-text-track-handle is-end",O.append(Ce,Ee,ye,Oe),O.addEventListener("pointerdown",_e=>Be(P.index,"move",_e)),ye.addEventListener("pointerdown",_e=>Be(P.index,"start",_e)),Oe.addEventListener("pointerdown",_e=>Be(P.index,"end",_e)),O.addEventListener("click",_e=>{if(_e.preventDefault(),_e.stopPropagation(),_e.shiftKey||_e.ctrlKey||_e.metaKey){Re(),ot();return}const Xe=zt(e,"text",P.index,_e,l.map(We=>We.index));Y=Xe.length?Xe[Xe.length-1]:null,Re(),pt(!0),ot()}),L.appendChild(O)}}function $e(l){K.forEach(d=>{d.controls.forEach(o=>{o.range.disabled=l,o.input.disabled=l})}),_.disabled=l}function Ae(){const l=be();D.forEach(d=>{const o=String(l[d.key]??s.notAvailable);d.valueEl.textContent=o,d.valueEl.title=o})}function De(l){const d=!!l;if($e(!d),_.hidden=!d,y.hidden=d,K.forEach(a=>{a.section.hidden=!d}),Ae(),!d)return;const o=ht(l);K.forEach(a=>{a.controls.forEach(c=>{const x=ue(Number(o[c.key])||0,c.min,c.max);c.range.value=String(x),c.input.value=te(x,c.format)})}),d&&(_.disabled=!gt(l))}function Qe(){return ee&&!!Ve()}function Ie(){return xt().some(o=>o!==Q&&!o.hidden&&o.style.display!=="none"&&o.classList.contains("is-active"))?!0:[...e.querySelectorAll(".me-video-toolrail .me-video-text-tool.is-active")].some(o=>o!==M)}function Pe(){const l=uo(e);return l instanceof HTMLElement?[...l.children].some(d=>d instanceof HTMLElement&&d!==se&&d!==N&&!d.hidden):!1}function Ue(){return ee&&!!Ve()&&!Ie()}function ct(){const l=Mn(e,t.getState().audioClips??[]).length>0;return!Ie()&&!Pe()&&!l&&!Ve()}function pt(l){const d=!!l;if(d===ee){ot();return}ee=d,ee&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:qe}})),ot()}function Ke(){ee=!1,Y=null,e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:"video-info"}})),se.hidden=!0,Ae(),N.hidden=!1,Ft(),E()}function nt(){se.hidden=!Ue(),N.hidden=!ct(),Ft(),E()}function ot(){ze(()=>{Ie()&&(ee=!1),ee&&Re(),Ot();const l=cr(t.getState());Ze(l);const d=new Set(eo(e,t.getState()));Se(l,d),we(l,d),De(Ve()),nt(),Ut()}),tt()}function Ot(){ze(()=>{const l=e.querySelector(".me-video-toolrail");if(!l)return;X=l;const d=xt(X);Q=io(d),ke(Q);const o=Q??d[0]??null;(!M||!M.isConnected)&&(M=document.createElement("button"),M.type="button",M.className="me-video-text-tool me-video-feature-one-tool",M.innerHTML=`<span class="me-video-text-tool-icon">${Jr()}</span><span class="me-video-text-tool-label">${s.tool}</span>`,M.addEventListener("click",()=>{Lt()})),M.setAttribute("title",s.tool),M.setAttribute("aria-label",s.tool),mt(o),M.isConnected?o?.parentElement===X&&M.nextSibling!==o&&X.insertBefore(M,o):o?.parentElement===X?X.insertBefore(M,o):X.appendChild(M),Ut(),M.classList.toggle("is-active",Qe()),Ft(),E()})}function Ft(){if(M?.classList.toggle("is-active",Qe()),!!Q){if(Qe()){Q.classList.remove("is-active");return}Q.classList.remove("is-active")}}function kt(l){return!!l&&(l===se||se.contains(l)||l===N||N.contains(l)||l===M||M?.contains?.(l)||l===U||U?.contains?.(l)||l===de||de?.contains?.(l)||l===Ne||Ne?.contains?.(l))}function ln(l){return l.some(d=>{if(!kt(d.target))return!0;for(const o of d.addedNodes)if(!kt(o))return!0;for(const o of d.removedNodes)if(!kt(o))return!0;return!1})}const an=new MutationObserver(l=>{pe||e.__meVideoEnhancerObserverLock||ln(l)&&(Ot(),it())}),en=l=>{l?.detail?.id===qe||l?.detail?.id==="video-info"||(ee=!1,se.hidden=!0,N.hidden=!0,Ft(),E(),it())},Ct=l=>{const d=l.target;d instanceof Element&&d.closest(".me-video-toolrail button")&&it()},tn=()=>{if(!So(e)){Ke();return}ot()};an.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","style","hidden"]}),e.addEventListener("me-video-inspector-open",en),e.addEventListener("click",Ct,!0),e.addEventListener(Ht,tn),window.addEventListener("resize",E);const m=t.subscribe(()=>{ot()});function H(l){const d=Number(l.input.value);if(!Number.isFinite(d))return null;const o=ue(d,l.displayMin,l.displayMax),a=ue(z(o,l.format),l.min,l.max);return{displayValue:o,internalValue:a}}function q(l){const d=Number(l.range.value);if(!Number.isFinite(d))return null;const o=ue(d,l.min,l.max);return{internalValue:o,displayValue:ue(w(o,l.format),l.displayMin,l.displayMax)}}return K.forEach(l=>{l.controls.forEach(d=>{d.range.addEventListener("input",()=>{const o=q(d);o&&(d.input.value=te(o.internalValue,d.format),Rt({[d.key]:o.internalValue},{transient:!0}))}),d.range.addEventListener("change",()=>{const o=q(d);if(!o){ot();return}d.input.value=te(o.internalValue,d.format),Rt({[d.key]:o.internalValue})}),d.input.addEventListener("input",()=>{const o=H(d);o&&(d.range.value=String(o.internalValue),Rt({[d.key]:o.internalValue},{transient:!0}))}),d.input.addEventListener("change",()=>{const o=H(d);if(!o){ot();return}d.range.value=String(o.internalValue),d.input.value=te(o.internalValue,d.format),Rt({[d.key]:o.internalValue})}),d.input.addEventListener("blur",()=>{const o=H(d);if(!o){ot();return}d.range.value=String(o.internalValue),d.input.value=te(o.internalValue,d.format)})})}),_.addEventListener("click",()=>{Mt()}),Ot(),ot(),{destroy(){an.disconnect(),m(),Je&&T&&Je.unobserve(T),Ge&&R&&Ge.unobserve(R),e.removeEventListener("me-video-inspector-open",en),e.removeEventListener("click",Ct,!0),e.removeEventListener(Ht,tn),window.removeEventListener("resize",E),wt(),M?.remove(),U?.remove(),de?.remove(),Ne?.remove(),se.remove(),N.remove(),Pt(e)}}}function ca(e,t,n){Qt();const r=Hi(n()),i=qi(),s=Ki(i),u=document.createElement("div");u.className="me-video-text-panel me-video-ratio-panel",u.hidden=!0,e.appendChild(u);const p=document.createElement("div");p.className="me-video-text-toolbar";const v=document.createElement("strong");v.textContent=r.title,p.append(v);const w=Kt(r.commonPresets),z=document.createElement("div");z.className="me-video-ratio-card-grid",w.body.appendChild(z);const te=Kt(r.customSize),S=document.createElement("input");S.type="number",S.min="2",S.step="2",S.className="me-video-text-input";const B=document.createElement("input");B.type="number",B.min="2",B.step="2",B.className="me-video-text-input";const V=to(r.width,S),ie=to(r.height,B),J=document.createElement("div");J.className="me-video-ratio-dimension-grid";const oe=document.createElement("div");oe.className="me-video-ratio-cross",oe.textContent="x",J.append(V,oe,ie);const le=document.createElement("div");le.className="me-video-ratio-lock-row";const xe=document.createElement("button");xe.type="button",xe.className="me-video-ratio-lock-toggle me-video-ratio-lock-inline";const ae=document.createElement("button");ae.type="button",ae.className="me-video-ratio-quick",ae.textContent=r.quickPortrait;const be=document.createElement("button");be.type="button",be.className="me-video-ratio-quick",be.textContent=r.quickLandscape,te.title.appendChild(xe),le.append(ae,be);const se=document.createElement("p");se.className="me-video-ratio-summary",te.body.append(J,le,se);const k=Kt(r.fitMode),b=document.createElement("div");b.className="me-video-ratio-fit-group";const _=[{fit:"cover",label:r.cover},{fit:"contain",label:r.contain},{fit:"force",label:r.force}].map(me=>{const Le=document.createElement("button");return Le.type="button",Le.className="me-video-ratio-fit-button",Le.dataset.fit=me.fit,Le.textContent=me.label,b.appendChild(Le),{fit:me.fit,button:Le}}),h=document.createElement("p");h.className="me-video-ratio-note",k.body.append(b,h),u.append(p,te.section,k.section,w.section);let y=null,N=null,j=null,re=null,I=null,D=!1,K=!0,M=!1,X=!1;const Q="resize",ce=ao("9:16"),W=ao("16:9"),U=typeof requestAnimationFrame=="function"?requestAnimationFrame:me=>setTimeout(me,16);function T(){Promise.resolve().then(()=>{X=!1;const me=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,me-1)})}function A(me){X=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return me()}finally{T()}}function de(){M||(M=!0,U(()=>{M=!1,Re()}))}function Ne(me=N){return me?[...me.children].filter(Le=>Le instanceof HTMLButtonElement&&Le!==y&&!Le.classList.contains("me-video-text-tool")):[]}function R(me){return[me?.textContent,me?.getAttribute?.("title"),me?.getAttribute?.("aria-label")].filter(Boolean).join(" ").trim().toLowerCase()}function ee(me){const Le=["trim","timeline","\u526A\u8F91","\u65F6\u95F4\u8F74"];return Ro(me.find(Ve=>{const Ze=R(Ve);return Le.some(at=>Ze.includes(at))})??me[0]??null)}function Y(){if(re&&D){re.classList.remove("is-active");return}}function G(me){const Le=[r.tool,r.title,"ratio","resize","\u6BD4\u4F8B","\u756B\u5E03","\u753B\u5E03"].map(Ve=>String(Ve??"").trim().toLowerCase()).filter(Boolean);return me.find(Ve=>{const Ze=R(Ve);return Le.some(at=>Ze.includes(at))})??me[me.length-1]??null}function pe(){I&&(I.isConnected&&(I.style.display=I.dataset.meResizeDisplay??"",I.hidden=I.dataset.meResizeHidden==="true",delete I.dataset.meResizeDisplay,delete I.dataset.meResizeHidden),I=null)}function qe(me){if(!me){pe();return}I!==me&&(pe(),me.dataset.meResizeDisplay=me.style.display??"",me.dataset.meResizeHidden=me.hidden?"true":"false",me.hidden=!0,me.style.display="none",I=me)}function He(){re&&(re.classList.contains("is-active")||re.click())}function Je(){rn(e,u),Pt(e)}function Ge(me){const Le=!!me;if(Le===D){Re();return}D=Le,D&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:Q}})),Re()}function Ye(){const me=e.querySelector(".me-video-toolrail");if(!me)return;N=me;const Le=Ne(N);re=ee(Le),j=G(Le),qe(j),(!y||!y.isConnected)&&(y=document.createElement("button"),y.type="button",y.className="me-video-text-tool me-video-ratio-tool",y.innerHTML=`<span class="me-video-text-tool-icon">\u2922</span><span class="me-video-text-tool-label">${r.tool}</span>`,y.title=r.tool,y.setAttribute("aria-label",r.tool),y.addEventListener("click",()=>{const Ve=!D;Ve&&(He(),de()),Ge(Ve)})),y.isConnected?j?.parentElement===N&&y.nextSibling!==j&&N.insertBefore(y,j):j?.parentElement===N?N.insertBefore(y,j):N.appendChild(y),y.classList.toggle("is-active",D),Y(),Je()}function dt(){u.hidden=!D,y?.classList.toggle("is-active",D),Y(),Je()}function rt(me=t.getState()){return Fo(me?.scale?.fit)}function ze(){xe.textContent=K?"\u{1F512}":"\u{1F513}",xe.title=K?r.lockRatio:r.unlockRatio,xe.setAttribute("aria-label",xe.title),xe.classList.toggle("is-active",K)}function it(me,Le,Ve=rt(),Ze=!1){const at={width:pn(me,2),height:pn(Le,2),fit:Fo(Ve)};if(Ze){t.patch({scale:at},{transient:!0});return}t.commit({scale:at})}function xt(me){const Le=Vn(t.getState()),Ve=pn(me,Le.w);if(!K)return{width:Ve,height:pn(B.value,Le.h)};const Ze=Le.w>0&&Le.h>0?Le.w/Le.h:1;return{width:Ve,height:pn(Ve/Ze,Le.h)}}function wt(me){const Le=Vn(t.getState()),Ve=pn(me,Le.h);if(!K)return{width:pn(S.value,Le.w),height:Ve};const Ze=Le.w>0&&Le.h>0?Le.w/Le.h:1;return{width:pn(Ve*Ze,Le.w),height:Ve}}function ke(me){const Le=Ui(s,me);z.replaceChildren();for(const Ve of s){const Ze=document.createElement("button");Ze.type="button",Ze.className="me-video-ratio-preset-group",Ze.title=`${Ve.ratio} (${On(Ve)})`,Le&&Le.ratio===Ve.ratio&&Ze.classList.add("is-active");const at=document.createElement("div");at.className="me-video-ratio-preset-head";const Et=document.createElement("div");Et.className="me-video-ratio-preset-title";const St=document.createElement("strong");St.className="me-video-ratio-preset-ratio",St.textContent=Ve.ratio;const Rt=document.createElement("span");Rt.className="me-video-ratio-preset-size",Rt.textContent=`(${On(Ve)})`,Et.append(St,Rt);const ut=document.createElement("span");ut.className="me-video-ratio-preset-marker",ut.setAttribute("aria-hidden","true"),at.append(Et,ut);const It=document.createElement("p");It.className="me-video-ratio-preset-hint",It.textContent=Ve.hint,Ze.addEventListener("click",()=>{it(Ve.w,Ve.h,rt())}),Ze.append(at,It),z.appendChild(Ze)}}function Re(){A(()=>{Ye();const me=t.getState(),Le=Ne().find(Et=>Et.classList.contains("is-active"))??null;D&&Le&&Le!==re&&(He(),de());const Ve=Vn(me),Ze=Cr(me),at=rt(me);S.value=String(Ve.w),B.value=String(Ve.h),ze(),se.innerHTML=`<strong>${r.summary}:</strong> ${On(Ve)}${me.scale?` | ${r.baseOutput}: ${On(Ze)}`:""}`,h.textContent=Gi(r,at),_.forEach(Et=>{Et.button.classList.toggle("is-active",Et.fit===at)}),ke(Ve),dt()})}function Me(me){return!!me&&(me===u||u.contains(me))}function et(me){return me.some(Le=>{if(!Me(Le.target))return!0;for(const Ve of Le.addedNodes)if(!Me(Ve))return!0;for(const Ve of Le.removedNodes)if(!Me(Ve))return!0;return!1})}const tt=new MutationObserver(me=>{X||e.__meVideoEnhancerObserverLock||et(me)&&(A(()=>{Ye()}),de())}),ht=me=>{me?.detail?.id!==Q&&(D&&(D=!1,dt()),de())};tt.observe(e,{childList:!0,subtree:!0}),e.addEventListener("me-video-inspector-open",ht),window.addEventListener("resize",de);const gt=t.subscribe(()=>{de()});return S.addEventListener("input",()=>{const me=xt(S.value);it(me.width,me.height,rt(),!0)}),S.addEventListener("change",()=>{const me=xt(S.value);it(me.width,me.height,rt())}),B.addEventListener("input",()=>{const me=wt(B.value);it(me.width,me.height,rt(),!0)}),B.addEventListener("change",()=>{const me=wt(B.value);it(me.width,me.height,rt())}),xe.addEventListener("click",()=>{K=!K,Re()}),ae.addEventListener("click",()=>{it(ce.w,ce.h,rt())}),be.addEventListener("click",()=>{it(W.w,W.h,rt())}),_.forEach(me=>{me.button.addEventListener("click",()=>{const Le=Vn(t.getState());it(Le.w,Le.h,me.fit)})}),Ye(),Re(),{destroy(){tt.disconnect(),gt(),e.removeEventListener("me-video-inspector-open",ht),window.removeEventListener("resize",de),pe(),y?.remove(),u.remove(),Pt(e)}}}function da(e,t,n,r){Qt(),kn();const i=Zo(r()),s=i.transitions,u=document.createElement("div");u.className="me-video-text-panel me-video-transition-panel",u.hidden=!0,e.appendChild(u);const p=document.createElement("div");p.className="me-video-text-toolbar";const v=document.createElement("strong");v.textContent=s.title;const w=Yt(s.fadeAll),z=Yt(s.close);p.append(v,w,z);const te=document.createElement("p");te.className="me-video-text-hint",te.textContent=s.hint;const S=document.createElement("div");S.className="me-video-text-list";const B=document.createElement("div");B.className="me-video-text-empty",B.textContent=s.empty;const V=document.createElement("div");V.className="me-video-transition-selection";const ie=document.createElement("div");ie.className="me-video-transition-grid";const J=vo.map(ke=>{const Re=En(i,ke.key),Me=document.createElement("button");return Me.type="button",Me.className="me-video-transition-choice",Me.dataset.transition=ke.key,Me.innerHTML=`<strong>${Re.label}</strong><span>${ke.key==="none"?s.instantCut:`${s.duration} ${mn(ke.duration)}`}</span>`,ie.appendChild(Me),Me}),oe=document.createElement("input");oe.type="range",oe.min="0.1",oe.max="1.2",oe.step="0.05";const le=document.createElement("div");le.className="me-video-text-inline";const xe=document.createElement("span");le.append(oe,xe);const ae=to(s.duration,le);ae.classList.add("is-span-2");const be=document.createElement("div");be.className="me-video-transition-actions";const se=Yt(s.clearSelected),k=Li(s.clearAll,"clear");k.classList.add("me-video-text-cta"),be.append(k,se),u.append(p,te,S,B,V,ie,ae,be);let b=null,_=null,h=null,y=null,N=null,j=!1,re=0,I=!1,D=!1;const K="transition",M=typeof requestAnimationFrame=="function"?requestAnimationFrame:ke=>setTimeout(ke,16),X=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>W());function Q(){Promise.resolve().then(()=>{D=!1;const ke=e.__meVideoEnhancerObserverLock??0;e.__meVideoEnhancerObserverLock=Math.max(0,ke-1)})}function ce(ke){D=!0,e.__meVideoEnhancerObserverLock=(e.__meVideoEnhancerObserverLock??0)+1;try{return ke()}finally{Q()}}function W(){I||(I=!0,M(()=>{I=!1,Ye()}))}function U(ke){const Re=!!ke;if(Re===j){Ye();return}j=Re,j&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:K}})),Ye()}function T(){return _?[..._.querySelectorAll("button")].filter(ke=>ke!==b):[]}function A(){T()[0]?.click()}function de(){b&&(b.dataset.theme=Rn(n()))}function Ne(){rn(e,u),Pt(e)}function R(){u.hidden=!j,b&&b.classList.toggle("is-active",j),Ne()}function ee(ke){const Re=Math.max(0,(ke.clips??[]).length-1);if(!Re){re=0;return}re=ue(re,0,Re-1)}function Y(ke,Re=!1){if(Re){t.patch({transitions:ke},{transient:!0});return}t.commit({transitions:ke})}function G(ke,Re=!1){const Me=t.getState(),et=bo(Me),tt=Me.clips??[];ee(Me),!(!et.length||!tt[re]||!tt[re+1])&&(et[re]=Gn({...et[re],...ke},Dt(tt[re]),Dt(tt[re+1])),Y(et,Re))}function pe(ke){const Re=t.getState(),Me=bo(Re),et=Re.clips??[];if(ee(Re),!Me.length||!et[re]||!et[re+1])return;const tt=En(i,ke);Me[re]=Gn({type:ke,duration:ke==="none"?0:Me[re]?.duration||tt.duration},Dt(et[re]),Dt(et[re+1])),Y(Me)}function qe(ke){const Me=t.getState().clips??[];if(Me.length<2)return;const et=En(i,ke),tt=[];for(let ht=0;ht<Me.length-1;ht++)tt.push(Gn({type:ke,duration:ke==="none"?0:et.duration},Dt(Me[ht]),Dt(Me[ht+1])));Y(tt)}function He(){const ke=Bn(e);if(!ke){y?.remove(),y=null,X&&N&&(X.unobserve(N),N=null),h=null;return}h=ke,h.style.position="relative",(!y||!y.isConnected||y.parentElement!==h)&&(y?.remove(),y=document.createElement("div"),y.className="me-video-transition-track",h.appendChild(y)),X&&N!==h&&(N&&X.unobserve(N),N=h,X.observe(h))}function Je(ke,Re){S.replaceChildren();const Me=Math.max(0,(ke.clips??[]).length-1);for(let et=0;et<Me;et++){const tt=document.createElement("button");tt.type="button",tt.className="me-video-text-chip",et===re&&tt.classList.add("is-active");const ht=Re[et],gt=En(i,ht?.type??"none");tt.textContent=s.boundary(et+1,et+2,gt.short),tt.title=s.boundaryTitle(et+1,et+2),tt.addEventListener("click",()=>{re=et,A(),U(!0)}),S.appendChild(tt)}}function Ge(ke,Re){if(He(),!y||!h)return;y.replaceChildren();const Me=ke.clips??[];if(Me.length<2)return;const et=Math.max(typeof t.contentDuration=="function"?t.contentDuration():0,.001),tt=h.clientWidth/et;let ht=0;for(let gt=0;gt<Me.length-1;gt++){ht+=Dt(Me[gt]);const me=Re[gt],Le=En(i,me?.type??"none"),Ve=me?.type==="none",Ze=document.createElement("button");Ze.type="button",Ze.className="me-video-transition-marker",Ve&&Ze.classList.add("is-cut-only"),me?.type!=="none"&&Ze.classList.add("is-enabled"),gt===re&&Ze.classList.add("is-active"),Ze.style.left=`${ht*tt}px`,Ze.title=s.markerTitle(gt+1,gt+2,Le.label,me?.type!=="none"?mn(me.duration):"");const at=document.createElement("span");at.className="me-video-transition-pill",at.textContent=Ve?"":Le.short,Ze.appendChild(at),Ze.addEventListener("click",()=>{re=gt,A(),U(!0)}),y.appendChild(Ze)}}function Ye(){ce(()=>{const ke=t.getState(),Re=bo(ke);ee(ke),Je(ke,Re),Ge(ke,Re);const Me=Re[re]??null,et=En(i,Me?.type??"none");B.hidden=Re.length>0,V.textContent=Me?s.selection(re+1,re+2):s.selectionEmpty,oe.disabled=!Me||et.key==="none",se.disabled=!Me,k.disabled=Re.length===0,w.disabled=Re.length===0,oe.value=String(Me&&et.key!=="none"?Me.duration:xo("fade").duration),xe.textContent=Me&&et.key!=="none"?mn(Me.duration):s.cut,J.forEach(tt=>{const ht=!!Me&&tt.dataset.transition===et.key;tt.classList.toggle("is-active",ht),tt.disabled=!Me}),R(),Ne(),de()})}function dt(){ce(()=>{const ke=e.querySelector(".me-video-toolrail");ke&&(_=ke,(!b||!b.isConnected)&&(b=document.createElement("button"),b.type="button",b.className="me-video-text-tool",b.innerHTML=`<span class="me-video-text-tool-icon">Fx</span><span class="me-video-text-tool-label">${s.tool}</span>`,b.addEventListener("click",()=>{const Re=!j;Re&&A(),U(Re)})),b.isConnected||_.appendChild(b),de(),Ne())})}function rt(ke){return!!ke&&(ke===u||u.contains(ke)||ke===b||ke===y||y?.contains(ke))}function ze(ke){return ke.some(Re=>{if(!rt(Re.target))return!0;for(const Me of Re.addedNodes)if(!rt(Me))return!0;for(const Me of Re.removedNodes)if(!rt(Me))return!0;return!1})}const it=new MutationObserver(ke=>{D||e.__meVideoEnhancerObserverLock||ze(ke)&&(dt(),W())}),xt=ke=>{ke?.detail?.id!==K&&j&&(j=!1,Ye())};it.observe(e,{childList:!0,subtree:!0}),e.addEventListener("me-video-inspector-open",xt),window.addEventListener("resize",W);const wt=t.subscribe(()=>{W()});return J.forEach(ke=>{ke.addEventListener("click",()=>{pe(ke.dataset.transition??"none")})}),oe.addEventListener("input",()=>{xe.textContent=mn(oe.value),G({duration:Number(oe.value)||.4},!0)}),oe.addEventListener("change",()=>{G({duration:Number(oe.value)||.4})}),w.addEventListener("click",()=>qe("fade")),se.addEventListener("click",()=>pe("none")),k.addEventListener("click",()=>qe("none")),z.addEventListener("click",()=>{U(!1)}),dt(),Ye(),{destroy(){it.disconnect(),wt(),X?.disconnect(),e.removeEventListener("me-video-inspector-open",xt),window.removeEventListener("resize",W),b?.remove(),y?.remove(),u.remove(),Pt(e)}}}function ua(e,t,n){Qt();const r=zi(n()),i=typeof requestAnimationFrame=="function"?requestAnimationFrame:o=>setTimeout(o,16),s=document.createElement("div");s.className="me-video-text-panel me-video-add-panel",s.hidden=!0,e.appendChild(s);const u=document.createElement("div");u.className="me-video-text-toolbar";const p=document.createElement("strong");p.textContent=r.title;const v=Yt(r.reset);u.append(p,v);const w=document.createElement("p");w.className="me-video-text-hint",w.textContent=r.hint;const z=document.createElement("div");z.className="me-video-add-body";const te=document.createElement("section");te.className="me-video-add-section";const S=document.createElement("div");S.className="me-video-add-section-head";const B=document.createElement("span");B.className="me-video-add-section-title",B.textContent=r.tools,S.appendChild(B);const V=document.createElement("div");V.className="me-video-add-tool-grid";const ie=document.createElement("section");ie.className="me-video-add-section";const J=document.createElement("div");J.className="me-video-add-section-head";const oe=document.createElement("span");oe.className="me-video-add-section-title",oe.textContent=r.color,J.appendChild(oe);const le=document.createElement("div");le.className="me-video-add-color-grid";const xe=document.createElement("div");xe.className="me-video-add-custom-color";const ae=document.createElement("div");ae.className="me-video-add-custom-head";const be=document.createElement("div");be.className="me-video-add-custom-preview";const se=document.createElement("span");se.className="me-video-add-custom-label",se.textContent=r.custom,ae.append(be,se);const k=document.createElement("div");k.className="me-video-add-spectrum";const b=document.createElement("span");b.className="me-video-add-spectrum-thumb",k.appendChild(b);const _=document.createElement("div");_.className="me-video-add-hue-row";const h=document.createElement("div");h.className="me-video-add-custom-preview";const y=document.createElement("input");y.type="range",y.min="0",y.max="360",y.step="1",y.className="me-video-add-hue-slider",_.append(h,y);const N=document.createElement("div");N.className="me-video-add-rgb-grid";const j={};["r","g","b"].forEach(o=>{const a=document.createElement("label");a.className="me-video-add-rgb-field";const c=document.createElement("input");c.type="number",c.min="0",c.max="255",c.step="1",c.inputMode="numeric",c.className="me-video-add-rgb-input";const x=document.createElement("span");x.className="me-video-add-rgb-label",x.textContent=o.toUpperCase(),a.append(c,x),N.appendChild(a),j[o]=c}),xe.append(ae,k,_,N);const re=document.createElement("section");re.className="me-video-add-section";const I=document.createElement("div");I.className="me-video-add-section-head";const D=document.createElement("span");D.className="me-video-add-section-title",D.textContent=r.width;const K=document.createElement("span");K.className="me-video-add-section-value",I.append(D,K);const M=document.createElement("input");M.type="range",M.min=String(jn),M.max=String(Yn),M.step="1",M.className="me-video-add-slider",te.append(S,V),ie.append(J,le,xe),re.append(I,M),z.append(te,ie,re),s.append(u,w,z);let X=null,Q=null,ce=null,W=null,U=null,T=null,A=null,de=null,Ne=null,R=!1,ee=!1,Y=null,G=no(),pe=null,qe=null,He=null,Je=0,Ge=0;const Ye="add",dt=[{key:"tl",x:0,y:0},{key:"tm",x:.5,y:0},{key:"tr",x:1,y:0},{key:"ml",x:0,y:.5},{key:"mr",x:1,y:.5},{key:"bl",x:0,y:1},{key:"bm",x:.5,y:1},{key:"br",x:1,y:1}],rt={key:"rotate",x:.5,y:0},ze=typeof ResizeObserver=="function"?new ResizeObserver(()=>{Lt()}):null,it=typeof ResizeObserver=="function"?new ResizeObserver(()=>{Lt()}):null,xt=gr.map(o=>{const a=document.createElement("button");return a.type="button",a.className="me-video-add-tool-card",a.dataset.tool=o.key,a.innerHTML=`<span class="me-video-add-tool-icon">${Ii(o.key)}</span><span class="me-video-add-tool-label">${r[o.key]}</span>`,a.addEventListener("click",()=>{At({tool:o.key})}),V.appendChild(a),a}),wt=yr.map(o=>{const a=document.createElement("button");return a.type="button",a.className="me-video-add-color-chip",a.dataset.color=o,a.dataset.tone=o==="#ffffff"?"light":"dark",a.style.background=o,a.title=o,a.setAttribute("aria-label",o),a.addEventListener("click",()=>{At({color:o})}),le.appendChild(a),a});function ke(o,a,c){He?.();const x=o==="mouse"?["mousemove"]:["pointermove"],P=o==="mouse"?["mouseup"]:["pointerup","pointercancel"],C=L=>{a(L)},ne=L=>{x.forEach(O=>window.removeEventListener(O,C)),P.forEach(O=>window.removeEventListener(O,ne)),He=null,c(L)};He=()=>{x.forEach(L=>window.removeEventListener(L,C)),P.forEach(L=>window.removeEventListener(L,ne))},x.forEach(L=>window.addEventListener(L,C)),P.forEach(L=>window.addEventListener(L,ne))}function Re(o,a){const c=k.getBoundingClientRect();if(!(c.width>0&&c.height>0))return;const x=ue((o-c.left)/c.width,0,1),P=1-ue((a-c.top)/c.height,0,1),C=oo(G.color),ne=Ho(C.r,C.g,C.b),L=zo(ne.h,x,P);At({color:ro(L.r,L.g,L.b)})}function Me(o){const a=typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now(),c=o.type==="mousedown"?"mouse":"pointer";if(c==="mouse"){if(a<Ge)return}else Ge=a+80;o.preventDefault(),o.stopPropagation(),Re(o.clientX,o.clientY),ke(c,x=>{x.preventDefault(),Re(x.clientX,x.clientY)},()=>{})}function et(o){const a=oo(G.color),c=Ho(a.r,a.g,a.b),x=zo(ue(Number(o)||0,0,360),c.s,c.v);At({color:ro(x.r,x.g,x.b)})}function tt(o,a){const c=oo(G.color),x={r:c.r,g:c.g,b:c.b};Number.isFinite(Number(a))&&(x[o]=ue(Number(a),0,255)),At({color:ro(x.r,x.g,x.b)})}function ht(){return(t.getState().overlays??[]).map((o,a)=>({overlay:o,index:a})).filter(o=>nn(o.overlay))}function gt(){const o=t.getState().overlays??[];if(Y==null)return null;const a=o[Y];return nn(a)?a:null}function me(){const o=gt();if(!o)return!1;const a=no({tool:G.tool,color:o.color,width:o.width});return Oo(G,a)?!1:(G=a,!0)}function Le(o,a,c={}){if(!gt()||Y==null)return;const P={};Object.prototype.hasOwnProperty.call(a,"color")&&(P.color=o.color),Object.prototype.hasOwnProperty.call(a,"width")&&(P.width=o.width),Object.keys(P).length&&t.updateOverlay(Y,P,c)}function Ve(){return Tn(t)}function Ze(){return yn(e)}function at(o,a,c={}){const P=(t.getState().overlays??[])[o];nn(P)&&t.updateOverlay(o,Jt(P,Ve(),a),c)}function Et(o){const a=t.getState().overlays??[],c=a.length;if(typeof t.applyMut=="function")return t.applyMut(P=>({...P,overlays:[...on(P.overlays),{...o,timelineTrack:0}]})),c;const x=on(a);return t.commit?.({overlays:[...x,{...o,timelineTrack:0}]}),c}function St(o){const a=Ve();let c=ue(Ze(),0,Math.max(0,a-je)),x=Math.min(a,c+qt);x-c<je&&(c=ue(a-qt,0,Math.max(0,a-je)),x=Math.max(c+je,a));const P={...o,...Jt(null,a,{startAt:c,endAt:x,timelineTrack:0})},C=Et(P);Y=Number.isInteger(C)?C:null,bt(e,"text",Y==null?[]:[Y]),E(),f(!0)}function Rt(){const{timelineInner:o,timelineHost:a}=$n(e,t.getState());if(!o||!a){de?.remove(),de=null,ze&&Ne&&(ze.unobserve(Ne),Ne=null),A=null;return}A=o,(!de||!de.isConnected||de.parentElement!==a)&&(de?.remove(),de=document.createElement("div"),de.className="me-video-text-timeline me-video-overlay-timeline me-video-add-overlay-layer");for(const c of[...a.children])c!==de&&c instanceof HTMLElement&&c.classList.contains("me-video-add-overlay-layer")&&c.remove();(de.parentElement!==a||a.lastElementChild!==de)&&a.appendChild(de),ze&&Ne!==A&&(Ne&&ze.unobserve(Ne),Ne=A,ze.observe(A))}function ut(o,a,c){if(!A)return;const x=(t.getState().overlays??[])[o];if(!nn(x))return;if(c.shiftKey||c.ctrlKey||c.metaKey){c.preventDefault(),c.stopPropagation();const ye=zt(e,"text",o,c,wo(t.getState()).map(Oe=>Oe.index));Y=ye.length?ye[ye.length-1]:null,E(),f(!0);return}c.preventDefault(),c.stopPropagation(),Y=o,bt(e,"text",[o]),E(),R||f(!0);const P=Ve(),C=Math.max(A.clientWidth/P,.001),ne=lt(x),L=Bt(x,ne),O=Math.max(je,L-ne),he=vt(x),ve=c.clientX,Ce=ye=>{const Oe=(ye.clientX-ve)/C,_e=t.getState().overlays??[];if(a==="move"){const st=Math.max(0,ne+Oe),Nt=st+O,$t=ft(de,_e,o,st,Nt,ye.clientY,he);at(o,{startAt:st,endAt:Nt,timelineTrack:$t},{transient:!0});return}if(a==="start"){const st=ue(ne+Oe,0,L-je),Nt=ft(de,_e,o,st,L,ye.clientY,he);at(o,{startAt:st,endAt:L,timelineTrack:Nt},{transient:!0});return}const Xe=Math.max(ne+je,L+Oe),We=ft(de,_e,o,ne,Xe,ye.clientY,he);at(o,{startAt:ne,endAt:Xe,timelineTrack:We},{transient:!0})},Ee=ye=>{window.removeEventListener("pointermove",Ce),window.removeEventListener("pointerup",Ee),window.removeEventListener("pointercancel",Ee);const Oe=(ye.clientX-ve)/C,_e=t.getState().overlays??[];if(a==="move"){const st=Math.max(0,ne+Oe),Nt=st+O,$t=ft(de,_e,o,st,Nt,ye.clientY,he);at(o,{startAt:st,endAt:Nt,timelineTrack:$t});return}if(a==="start"){const st=ue(ne+Oe,0,L-je),Nt=ft(de,_e,o,st,L,ye.clientY,he);at(o,{startAt:st,endAt:L,timelineTrack:Nt});return}const Xe=Math.max(ne+je,L+Oe),We=ft(de,_e,o,ne,Xe,ye.clientY,he);at(o,{startAt:ne,endAt:Xe,timelineTrack:We})};window.addEventListener("pointermove",Ce),window.addEventListener("pointerup",Ee),window.addEventListener("pointercancel",Ee),Ct()}function It(o,a){if(Rt(),!de||!A||(de.replaceChildren(),de.hidden=o.length===0,!o.length))return;const c=Ve(),x=A.clientWidth/c,P=Fn(t.getState()),C=new Map;for(const ne of o){const L=vt(ne.overlay),O=P.get(L)??L;let he=C.get(L);he||(he=document.createElement("div"),he.className="me-video-overlay-track-row",he.dataset.track=String(L),he.style.top=`${Ln(O)}px`,C.set(L,he),de.appendChild(he));const ve=document.createElement("div");ve.className="me-video-text-track-clip me-video-add-track-clip",a.has(ne.index)&&ve.classList.add("is-active");const Ce=lt(ne.overlay),Ee=Sn(ne.overlay);ve.style.left=`${Ce*x}px`,ve.style.width=`${Math.max(36,Ee*x)}px`;const ye=document.createElement("span");ye.className="me-video-text-track-icon",ye.textContent="+";const Oe=document.createElement("span");Oe.className="me-video-text-track-label",Oe.textContent=wr(ne.overlay,r),Oe.title=Oe.textContent;const _e=document.createElement("span");_e.className="me-video-text-track-handle is-start";const Xe=document.createElement("span");Xe.className="me-video-text-track-handle is-end",ve.append(ye,Oe,_e,Xe),ve.addEventListener("pointerdown",We=>ut(ne.index,"move",We)),_e.addEventListener("pointerdown",We=>ut(ne.index,"start",We)),Xe.addEventListener("pointerdown",We=>ut(ne.index,"end",We)),ve.addEventListener("click",We=>{if(We.preventDefault(),We.stopPropagation(),We.shiftKey||We.ctrlKey||We.metaKey){E(),Ct();return}const st=zt(e,"text",ne.index,We,o.map(Nt=>Nt.index));Y=st.length?st[st.length-1]:null,E(),f(!0),Ct()}),he.appendChild(ve)}}function Lt(){ee||(ee=!0,i(()=>{ee=!1,Ct()}))}function jt(){xt.forEach(c=>{c.classList.toggle("is-active",c.dataset.tool===G.tool)}),wt.forEach(c=>{c.classList.toggle("is-active",c.dataset.color===G.color)});const o=oo(G.color),a=Ho(o.r,o.g,o.b);xe.classList.toggle("is-active",!yr.includes(G.color)),xe.style.setProperty("--me-add-color-current",G.color),xe.style.setProperty("--me-add-color-hue",Bi(a.h)),be.style.background=G.color,h.style.background=G.color,b.style.left=`${a.s*100}%`,b.style.top=`${(1-a.v)*100}%`,y.value=String(Math.round(a.h)),j.r.value=String(o.r),j.g.value=String(o.g),j.b.value=String(o.b),M.value=String(ue(Math.round(Number(G.width)||sn.width),jn,Yn)),K.textContent=Fi(G.width),v.disabled=kr(G)}function At(o,a={}){const c=no({...G,...o});if(Oo(G,c)){a.applyToSelected&&Le(c,o,a.overlayOptions);return}G=c,a.applyToSelected!==!1&&Le(c,o,a.overlayOptions),jt(),Lt()}function Mt(){if(kr(G)){jt();return}G=no(),jt(),Lt()}function mt(o=Q){return o?[...o.children].filter(a=>a instanceof HTMLButtonElement&&a!==X&&!a.classList.contains("me-video-text-tool")):[]}function Ut(){X?.classList.toggle("is-active",R)}function E(){ce&&(ce.classList.contains("is-active")||ce.click())}function F(){rn(e,s),Pt(e)}function Z(){pe=null}function Te(){qe?.(),qe=null,Z()}function Fe(){s.hidden=!R,Ut(),F()}function f(o){const a=!!o;if(a===R){Ct();return}R=a,R?(e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:Ye}})),E()):(Te(),He?.(),He=null),Ct()}function g(){const o=e.querySelector(".me-video-toolrail");o&&(Q=o,ce=io(mt(o)),(!X||!X.isConnected)&&(X=document.createElement("button"),X.type="button",X.className="me-video-text-tool me-video-add-tool",X.innerHTML=`<span class="me-video-text-tool-icon">${Ri()}</span><span class="me-video-text-tool-label">${r.tool}</span>`,X.title=r.tool,X.setAttribute("aria-label",r.tool),X.addEventListener("click",()=>{const a=!R;a&&E(),f(a)})),X.isConnected?X.parentElement===Q&&X!==Q.lastElementChild&&Q.appendChild(X):Q.appendChild(X),Fe())}function $(){const o=e.querySelector(".me-video-canvas-stage");if(!o){U?.remove(),U=null,it&&T&&(it.unobserve(T),T=null),W=null;return}W=o,W.style.position="relative",!U||!U.isConnected||U.parentElement!==W?(U?.remove(),U=document.createElement("div"),U.className="me-video-add-canvas-layer",U.addEventListener("pointerdown",en),U.addEventListener("mousedown",en),U.addEventListener("click",a=>{a.preventDefault(),a.stopPropagation()}),W.appendChild(U)):W.lastElementChild!==U&&W.appendChild(U),it&&T!==W&&(T&&it.unobserve(T),T=W,it.observe(W)),U.hidden=!R,U.dataset.tool=G.tool}function fe(){if(!W)return null;const o=t.getState().canvas??{},a=Math.max(1,Number(o.w)||0),c=Math.max(1,Number(o.h)||0);if(!a||!c)return null;const x=W.getBoundingClientRect(),P=W.querySelector("canvas, video, img")||[...W.children].find(he=>he!==U)||null;let C=0,ne=0,L=W.clientWidth||a,O=W.clientHeight||c;if(P instanceof HTMLElement){const he=P.getBoundingClientRect();he.width>0&&he.height>0&&(C=he.left-x.left,ne=he.top-x.top,L=he.width,O=he.height)}if(!(L>0&&O>0)){const he=W.clientWidth||a,ve=W.clientHeight||c,Ce=Math.min(he/a,ve/c)||1;L=a*Ce,O=c*Ce,C=Math.max(0,(he-L)/2),ne=Math.max(0,(ve-O)/2)}return{stageLeft:x.left,stageTop:x.top,left:C,top:ne,width:L,height:O,canvasWidth:a,canvasHeight:c,scaleX:L/a,scaleY:O/c}}function ge(o,a,c){return{x:ue((o-c.stageLeft-c.left)/c.scaleX,0,c.canvasWidth),y:ue((a-c.stageTop-c.top)/c.scaleY,0,c.canvasHeight)}}function we(o,a,c){return Number.isFinite(o?.clientX)&&Number.isFinite(o?.clientY)?ge(o.clientX,o.clientY,a):c}function Be(o,a){return{x:Math.min(o.x,a.x),y:Math.min(o.y,a.y),w:Math.abs(a.x-o.x),h:Math.abs(a.y-o.y)}}function Se(o,a){const c=lt(o),x=Bt(o,c);return a>=c-.001&&a<=x+.001}function $e(o,a,c){const x=zt(e,"text",o,a,c);Y=x.length?x[x.length-1]:null,f(!0),Ct()}function Ae(o,a,c,x,P){const C=Math.atan2(x-a,c-o),ne=Math.max(12,P*3.5),L=c-ne*Math.cos(C-Math.PI/7),O=x-ne*Math.sin(C-Math.PI/7),he=c-ne*Math.cos(C+Math.PI/7),ve=x-ne*Math.sin(C+Math.PI/7);return`M ${L} ${O} L ${c} ${x} L ${he} ${ve}`}function De(o){if(!Array.isArray(o)||o.length<4)return"";let a=`M ${o[0]} ${o[1]}`;for(let c=2;c<o.length;c+=2)a+=` L ${o[c]} ${o[c+1]}`;return a}function Qe(o){const a=document.createElementNS("http://www.w3.org/2000/svg","svg");return a.classList.add("me-video-add-preview-svg"),a.setAttribute("viewBox",`0 0 ${o.canvasWidth} ${o.canvasHeight}`),a.setAttribute("width",String(o.width)),a.setAttribute("height",String(o.height)),a.style.left=`${o.left}px`,a.style.top=`${o.top}px`,a.style.width=`${o.width}px`,a.style.height=`${o.height}px`,a}function Ie(o,a,c){const x=document.createElementNS("http://www.w3.org/2000/svg",o);return x.classList.add("me-video-add-preview-shape"),x.setAttribute("stroke",a),x.setAttribute("stroke-width",String(c)),x}function Pe(o){if(!pe)return null;const a=Qe(o);if(pe.type==="pen"){const c=De(pe.points);if(!c)return a;const x=Ie("path",pe.color,pe.width);return x.setAttribute("d",c),a.appendChild(x),a}if(pe.type==="line"||pe.type==="arrow"){const c=Ie("line",pe.color,pe.width);if(c.setAttribute("x1",String(pe.x1)),c.setAttribute("y1",String(pe.y1)),c.setAttribute("x2",String(pe.x2)),c.setAttribute("y2",String(pe.y2)),a.appendChild(c),pe.type==="arrow"){const x=Ie("path",pe.color,pe.width);x.setAttribute("d",Ae(pe.x1,pe.y1,pe.x2,pe.y2,pe.width)),a.appendChild(x)}return a}if(pe.type==="rect"){const c=Ie("rect",pe.color,pe.width);return c.setAttribute("x",String(pe.x)),c.setAttribute("y",String(pe.y)),c.setAttribute("width",String(pe.w)),c.setAttribute("height",String(pe.h)),a.appendChild(c),a}if(pe.type==="ellipse"){const c=Ie("ellipse",pe.color,pe.width);return c.setAttribute("cx",String(pe.x+pe.w/2)),c.setAttribute("cy",String(pe.y+pe.h/2)),c.setAttribute("rx",String(Math.abs(pe.w/2))),c.setAttribute("ry",String(Math.abs(pe.h/2))),a.appendChild(c),a}return a}function Ue(){if($(),!U)return;const o=fe();if(U.hidden=!R||!o,!R||!o){U.replaceChildren();return}U.dataset.tool=G.tool,U.replaceChildren();const a=Pe(o);a&&U.appendChild(a);const c=wo(t.getState()),x=new Set(fr(e,t.getState())),P=Ze(),C=c.map(O=>O.index),ne=c.filter(O=>Se(O.overlay,P)),L=G.tool==="eraser"?[]:x.size?ne.filter(O=>x.has(O.index)):ne;for(const O of L){const he=Gt(O.overlay);if(!he)continue;const ve=document.createElement("button");ve.type="button",ve.className="me-video-text-canvas-hit";const Ce=x.has(O.index),Ee=Ce&&Y===O.index;Ce&&ve.classList.add("is-active"),ve.title=wr(O.overlay,r),ve.style.left=`${o.left+he.x*o.scaleX}px`,ve.style.top=`${o.top+he.y*o.scaleY}px`,ve.style.width=`${Math.max(18,he.w*o.scaleX)}px`,ve.style.height=`${Math.max(18,he.h*o.scaleY)}px`;const ye=un(O.overlay);if(ye&&(ve.style.transform=`rotate(${ye}deg)`,ve.style.transformOrigin="center center"),ve.addEventListener("pointerdown",Oe=>{if(Oe.preventDefault(),Oe.stopPropagation(),Oe.shiftKey||Oe.ctrlKey||Oe.metaKey){$e(O.index,Oe,C);return}Y=O.index,bt(e,"text",[O.index]),f(!0),ct(O.index,Oe,o)}),Ee){for(const _e of dt){const Xe=document.createElement("span");Xe.className="me-video-text-canvas-handle",Xe.dataset.handle=_e.key,Xe.style.left=`${_e.x*100}%`,Xe.style.top=`${_e.y*100}%`,Xe.addEventListener("pointerdown",We=>{We.preventDefault(),We.stopPropagation(),Y=O.index,bt(e,"text",[O.index]),f(!0),pt(O.index,_e,We,o)}),ve.appendChild(Xe)}const Oe=document.createElement("span");Oe.className="me-video-text-canvas-handle",Oe.dataset.handle=rt.key,Oe.style.left=`${rt.x*100}%`,Oe.style.top=`${rt.y*100}%`,Oe.addEventListener("pointerdown",_e=>{_e.preventDefault(),_e.stopPropagation(),Y=O.index,bt(e,"text",[O.index]),f(!0),Ke(O.index,_e,o)}),ve.appendChild(Oe)}U.appendChild(ve)}}function ct(o,a,c){const x=(t.getState().overlays??[])[o];if(!nn(x))return;const P=t.getState().canvas??{w:1080,h:1920},C=Gt(x);if(!C)return;const ne=a.clientX,L=a.clientY,O=Math.max(0,(Number(P.w)||0)-C.w),he=Math.max(0,(Number(P.h)||0)-C.h),ve=(ye,Oe,_e)=>{const Xe=(ye-ne)/c.scaleX,We=(Oe-L)/c.scaleY,st=ue(C.x+Xe,0,O),Nt=ue(C.y+We,0,he),$t=Vo(x,st-C.x,Nt-C.y);t.updateOverlay(o,$t,_e?{transient:!0}:void 0)},Ce=ye=>{ye.preventDefault(),ve(ye.clientX,ye.clientY,!0)},Ee=ye=>{window.removeEventListener("pointermove",Ce),window.removeEventListener("pointerup",Ee),window.removeEventListener("pointercancel",Ee),ve(ye.clientX,ye.clientY,!1)};window.addEventListener("pointermove",Ce),window.addEventListener("pointerup",Ee),window.addEventListener("pointercancel",Ee)}function pt(o,a,c,x){const P=(t.getState().overlays??[])[o];if(!nn(P))return;const C=Gt(P);if(!C)return;const ne=t.getState().canvas??{w:1080,h:1920},L=a.x===.5?.5:1-a.x,O=a.y===.5?.5:1-a.y,he=C.x+C.w*L,ve=C.y+C.h*O,Ce=Math.max(.1,24/Math.max(24,C.w),24/Math.max(24,C.h)),Ee=a.x===.5?1/0:Math.max(.1,(L===0?(Number(ne.w)||0)-he:he)/Math.max(1,C.w)),ye=a.y===.5?1/0:Math.max(.1,(O===0?(Number(ne.h)||0)-ve:ve)/Math.max(1,C.h)),Oe=Math.max(Ce,Math.min(Ee,ye,8)),_e=(st,Nt,$t)=>{const cn=ge(st,Nt,x),dn=[];a.x!==.5&&dn.push(Math.abs(cn.x-he)/Math.max(1,C.w)),a.y!==.5&&dn.push(Math.abs(cn.y-ve)/Math.max(1,C.h));const Pn=dn.length?Math.max(...dn):1,hn=ue(Pn,Ce,Oe),qn=Yo(P,hn),xn=Gt(qn);if(!xn)return;const Br=he-xn.w*L,$r=ve-xn.h*O,Dr=Vo(qn,Br-xn.x,$r-xn.y);t.updateOverlay(o,Dr,$t?{transient:!0}:void 0)},Xe=st=>{st.preventDefault(),_e(st.clientX,st.clientY,!0)},We=st=>{window.removeEventListener("pointermove",Xe),window.removeEventListener("pointerup",We),window.removeEventListener("pointercancel",We),_e(st.clientX,st.clientY,!1)};window.addEventListener("pointermove",Xe),window.addEventListener("pointerup",We),window.addEventListener("pointercancel",We)}function Ke(o,a,c){const x=(t.getState().overlays??[])[o];if(!nn(x))return;const P=Gt(x);if(!P)return;const C=c.stageLeft+c.left+(P.x+P.w/2)*c.scaleX,ne=c.stageTop+c.top+(P.y+P.h/2)*c.scaleY,L=Math.atan2(a.clientY-ne,a.clientX-C),O=un(x),he=(Ee,ye,Oe,_e)=>{const Xe=Math.atan2(ye-ne,Ee-C);let We=In(O+(Xe-L)*180/Math.PI);_e&&(We=Math.round(We/15)*15),t.updateOverlay(o,{rotation:We},Oe?{transient:!0}:void 0)},ve=Ee=>{Ee.preventDefault(),he(Ee.clientX,Ee.clientY,!0,Ee.shiftKey)},Ce=Ee=>{window.removeEventListener("pointermove",ve),window.removeEventListener("pointerup",Ce),window.removeEventListener("pointercancel",Ce),he(Ee.clientX,Ee.clientY,!1,Ee.shiftKey)};window.addEventListener("pointermove",ve),window.addEventListener("pointerup",Ce),window.addEventListener("pointercancel",Ce)}function nt(o,a,c,x,P,C,ne){const L=P-c,O=C-x,he=L*L+O*O||1,ve=ue(((o-c)*L+(a-x)*O)/he,0,1),Ce=c+ve*L,Ee=x+ve*O;return(o-Ce)**2+(a-Ee)**2<=ne*ne}function ot(o,a,c){if(!o)return!1;if(o.type==="pen"){for(let x=0;x+3<o.points.length;x+=2)if(nt(a,c,o.points[x],o.points[x+1],o.points[x+2],o.points[x+3],Nn+(Number(o.width)||0)/2))return!0;return!1}return o.type==="line"||o.type==="arrow"?nt(a,c,o.x1,o.y1,o.x2,o.y2,Nn+(Number(o.width)||0)/2):o.type==="rect"||o.type==="ellipse"?a>=o.x-Nn&&a<=o.x+o.w+Nn&&c>=o.y-Nn&&c<=o.y+o.h+Nn:!1}function Ot(o){const a=ht();for(let c=a.length-1;c>=0;c--)if(ot(a[c].overlay,o.x,o.y)){t.removeOverlay(a[c].index),Lt();return}}function Ft(o,a,c){Ot(o),kt(c,x=>{x.preventDefault(),Ot(ge(x.clientX,x.clientY,a))},()=>{})}function kt(o,a,c){Te();const x=o==="mouse"?["mousemove"]:["pointermove"],P=o==="mouse"?["mouseup"]:["pointerup","pointercancel"],C=L=>{a(L)},ne=L=>{x.forEach(O=>window.removeEventListener(O,C)),P.forEach(O=>window.removeEventListener(O,ne)),qe=null,c(L)};qe=()=>{x.forEach(L=>window.removeEventListener(L,C)),P.forEach(L=>window.removeEventListener(L,ne))},x.forEach(L=>window.addEventListener(L,C)),P.forEach(L=>window.addEventListener(L,ne))}function ln(o,a,c){const x=[o.x,o.y],P=C=>{const ne=x[x.length-2],L=x[x.length-1];Math.hypot(C.x-ne,C.y-L)<1||x.push(C.x,C.y)};pe={type:"pen",points:[...x],color:G.color,width:G.width},Ue(),kt(c,C=>{C.preventDefault();const ne=ge(C.clientX,C.clientY,a);P(ne),pe={type:"pen",points:[...x],color:G.color,width:G.width},Ue()},C=>{const ne=we(C,a,{x:x[x.length-2],y:x[x.length-1]});P(ne);const L=[...x];Z(),Ue(),!(L.length<4)&&(St({type:"pen",points:L,color:G.color,width:G.width,rotation:0}),Lt())})}function an(o,a,c,x){const P=Pi[o];if(!P)return;const C=ne=>{if(P==="line"||P==="arrow")return{type:P,x1:a.x,y1:a.y,x2:ne.x,y2:ne.y,color:G.color,width:G.width};const L=Be(a,ne);return{type:P,x:L.x,y:L.y,w:L.w,h:L.h,color:G.color,width:G.width}};pe=C(a),Ue(),kt(x,ne=>{ne.preventDefault();const L=ge(ne.clientX,ne.clientY,c);pe=C(L),Ue()},ne=>{const L=we(ne,c,a),O=C(L);Z(),Ue(),O&&((O.type==="line"||O.type==="arrow")&&Math.hypot(O.x2-O.x1,O.y2-O.y1)<2||(O.type==="rect"||O.type==="ellipse")&&(O.w<2||O.h<2)||St({...O,rotation:0}))})}function en(o){if(!R)return;const a=typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now(),c=o.type==="mousedown"?"mouse":"pointer";if(c==="mouse"){if(a<Je)return}else Je=a+80;if(typeof o.button=="number"&&o.button!==0)return;o.preventDefault(),o.stopPropagation();const x=fe();if(!x)return;const P=ge(o.clientX,o.clientY,x);if(G.tool==="eraser"){Ft(P,x,c);return}if(G.tool==="brush"){ln(P,x,c);return}an(G.tool,P,x,c)}function Ct(){const o=fr(e,t.getState());Y=o.length?o[o.length-1]:null,me(),mt().find(c=>c!==ce&&!c.hidden&&c.style.display!=="none"&&c.classList.contains("is-active"))&&(R=!1,Te()),R&&E(),jt(),Fe(),Ue(),It(wo(t.getState()),new Set(o)),F()}function tn(o){return!!o&&(o===s||s.contains(o)||o===X||X?.contains?.(o)||o===de||de?.contains?.(o)||o===U||U?.contains?.(o))}function m(o){return o.some(a=>{if(!tn(a.target))return!0;for(const c of a.addedNodes)if(!tn(c))return!0;for(const c of a.removedNodes)if(!tn(c))return!0;return!1})}const H=new MutationObserver(o=>{m(o)&&(g(),Lt())}),q=o=>{o?.detail?.id!==Ye&&R&&f(!1)},l=()=>{Lt()};H.observe(e,{childList:!0,subtree:!0}),e.addEventListener("me-video-inspector-open",q),e.addEventListener(Ht,l),window.addEventListener("resize",Lt);const d=t.subscribe(()=>{Lt()});return v.addEventListener("click",()=>{Mt()}),k.addEventListener("pointerdown",Me),k.addEventListener("mousedown",Me),y.addEventListener("input",()=>{et(y.value)}),Object.entries(j).forEach(([o,a])=>{a.addEventListener("input",()=>{tt(o,a.value)})}),M.addEventListener("input",()=>{At({width:ue(Number(M.value)||sn.width,jn,Yn)})}),g(),Ct(),{destroy(){H.disconnect(),d(),Te(),He?.(),He=null,ze&&Ne&&ze.unobserve(Ne),ze?.disconnect?.(),it&&T&&it.unobserve(T),it?.disconnect?.(),e.removeEventListener("me-video-inspector-open",q),e.removeEventListener(Ht,l),window.removeEventListener("resize",Lt),X?.remove(),de?.remove(),U?.remove(),s.remove(),Pt(e)}}}function ma(e,t,n){Qt();const r=Ur(n()),i=document.createElement("div");i.className="me-video-text-panel me-video-audio-panel",i.hidden=!0;const s=document.createElement("div");s.className="me-video-text-toolbar";const u=document.createElement("strong");u.textContent=r.title;const p=Yt(r.close);s.append(u,p);const v=document.createElement("div");v.className="me-video-audio-source";const w=document.createElement("div");w.className="me-video-text-grid";function z(Y=""){const G=document.createElement("input");return G.type="text",G.readOnly=!0,G.className=["me-video-audio-value",Y].filter(Boolean).join(" "),G}function te(Y,G,pe){const qe=document.createElement("div");return qe.className="me-video-text-inline",qe.append(G,pe),to(Y,qe)}const S=document.createElement("input");S.type="range",S.min="50",S.max="200",S.step="1",S.disabled=!1,S.value="100",S.title=r.speedHint;const B=z("is-compact is-readonly");B.readOnly=!1,B.classList.remove("is-readonly"),B.inputMode="decimal",B.title=r.speedHint;const V=te(r.speed,S,B),ie=document.createElement("input");ie.type="range",ie.min=String(Wt),ie.max="1",ie.step="0.01",ie.disabled=!1,ie.value="1";const J=z("is-readonly");J.readOnly=!1,J.classList.remove("is-readonly"),J.inputMode="decimal";const oe=te(r.duration,ie,J),le=document.createElement("input");le.type="range",le.min="0",le.max="2",le.step="0.01";const xe=z(),ae=te(r.volume,le,xe),be=document.createElement("input");be.type="range",be.min="0",be.max="0.1",be.step="0.05";const se=z(),k=te(r.fadeIn,be,se),b=document.createElement("input");b.type="range",b.min="0",b.max="0.1",b.step="0.05";const _=z(),h=te(r.fadeOut,b,_);w.append(V,oe,ae,k,h),i.append(s,v,w);let y=null,N=!1,j=!1;const re="audio",I=typeof requestAnimationFrame=="function"?requestAnimationFrame:Y=>setTimeout(Y,16);function D(Y){const G=Math.max(0,Number(Y)||0);return G<=1e-4?"-\u221EdB":`${(20*Math.log10(G)).toFixed(1)}dB`}function K(){const Y=e.querySelector(".me-video-trim-panel");if(Y instanceof HTMLElement)for(const G of[...Y.children].slice(2))G instanceof HTMLElement&&G.querySelector('input[type="range"]')&&/♪/.test(G.textContent??"")&&(G.style.display="none")}function M(){i.hidden=!N,rn(e,i),Ar(e,i,N),Pt(e)}function X(Y){const G=!!Y;if(G===N){M();return}N=G,N&&e.dispatchEvent(new CustomEvent("me-video-inspector-open",{detail:{id:re}})),M()}function Q(){fn(e,{audio:[]},{audio:null})}function ce(Y,G,pe,qe){let He=ue(Number(G)||0,0,Y),Je=ue(Number(pe)||0,0,Y);return He+Je<=Y?{fadeIn:He,fadeOut:Je}:(qe==="fadeOut"?He=Math.max(0,Y-Je):Je=Math.max(0,Y-He),{fadeIn:He,fadeOut:Je})}function W(Y){const G=t.getAudioSource?.(Y?.srcIdx);return Math.max(Dt(Y),Number(G?.duration)||0)}function U(Y,G=!1,pe="fadeIn"){const qe=t.getState(),He=qe.audioClips??[];if(y==null||!He[y])return;const Je=He[y],Ge=Dt({...Je,...Y}),Ye=ce(Ge,Y.fadeIn??Je.fadeIn,Y.fadeOut??Je.fadeOut,pe),dt=ze=>({...ze,...Y,speed:bn(Y.speed??ze.speed),volume:ue(Number(Y.volume??ze.volume)||0,0,2),fadeIn:Ye.fadeIn,fadeOut:Ye.fadeOut}),rt=typeof t.patchAudio=="function"?t.patchAudio(qe,y,dt).audioClips??He:He.map((ze,it)=>it===y?dt(ze):ze);if(G){t.patch({audioClips:rt},{transient:!0});return}t.commit({audioClips:rt})}function T(Y,G=!1){const qe=t.getState().audioClips??[];if(y==null||!qe[y])return;const He=qe[y],Je=W(He),Ge=Math.max(0,Number(He.in)||0),Ye=Math.max(Wt,Je-Ge),dt=ue(Number(Y)||0,Wt,Ye);U({out:Ge+dt},G,"fadeIn")}function A(){if(K(),!(e.querySelector(".me-video-trim-panel")instanceof HTMLElement)){N&&X(!1),y=null;return}const G=t.getState(),pe=G.audioClips??[],qe=Mn(e,pe),He=Dn(e,G.clips??[]),Je=_n(e,G),Ge=qe.length===1&&He.length===0&&Je.length===0?qe[0]:null;if(y=Number.isInteger(Ge)&&pe[Ge]?Ge:null,y==null){N&&X(!1);return}const Ye=pe[y],dt=t.getAudioSource?.(Ye.srcIdx),rt=dt?.file?.name||dt?.name||`${r.source} ${y+1}`,ze=Dt(Ye),it=Math.max(ze,Number(dt?.duration)||0),xt=Math.max(ze,Math.max(Wt,it-Math.max(0,Number(Ye.in)||0))),wt=bn(Ye.speed),ke=ue(Number(Ye.fadeIn)||0,0,ze),Re=ue(Number(Ye.fadeOut)||0,0,Math.max(0,ze-ke));v.textContent=`${r.source}: ${rt}`,S.value=String(Math.round(wt*100)),B.value=Qr(wt),ie.max=String(xt),ie.value=String(ue(ze,Wt,xt)),J.value=mn(ze),le.value=String(ue(Number(Ye.volume)||0,0,2)),xe.value=D(Ye.volume),be.max=String(Math.max(.1,ze)),b.max=String(Math.max(.1,ze)),be.value=String(ke),b.value=String(Re),se.value=mn(ke),_.value=mn(Re),be.disabled=ze<=1e-4,b.disabled=ze<=1e-4,X(!0)}function de(){j||(j=!0,I(()=>{j=!1,A()}))}const Ne=Y=>{if(Y?.detail?.id!==re){if(_t(e,"audio").length>0){Q();return}N&&X(!1)}},R=new MutationObserver(()=>{de()});R.observe(e,{childList:!0,subtree:!0}),e.addEventListener("me-video-inspector-open",Ne),e.addEventListener(Ht,de);const ee=t.subscribe(()=>{de()});return p.addEventListener("click",()=>{Q()}),S.addEventListener("input",()=>{U({speed:bn((Number(S.value)||100)/100)},!0,"fadeIn")}),S.addEventListener("change",()=>{U({speed:bn((Number(S.value)||100)/100)},!1,"fadeIn")}),B.addEventListener("change",()=>{const Y=y==null?null:(t.getState().audioClips??[])[y]??null;U({speed:ei(B.value,Y?.speed??1)},!1,"fadeIn")}),B.addEventListener("keydown",Y=>{Y.key==="Enter"&&(Y.preventDefault(),B.blur())}),ie.addEventListener("input",()=>{T(Number(ie.value)||0,!0)}),ie.addEventListener("change",()=>{T(Number(ie.value)||0,!1)}),J.addEventListener("change",()=>{const Y=y==null?null:(t.getState().audioClips??[])[y]??null;T(ti(J.value,Dt(Y)),!1)}),J.addEventListener("keydown",Y=>{Y.key==="Enter"&&(Y.preventDefault(),J.blur())}),le.addEventListener("input",()=>{U({volume:Number(le.value)||0},!0,"fadeIn")}),le.addEventListener("change",()=>{U({volume:Number(le.value)||0},!1,"fadeIn")}),be.addEventListener("input",()=>{U({fadeIn:Number(be.value)||0},!0,"fadeIn")}),be.addEventListener("change",()=>{U({fadeIn:Number(be.value)||0},!1,"fadeIn")}),b.addEventListener("input",()=>{U({fadeOut:Number(b.value)||0},!0,"fadeOut")}),b.addEventListener("change",()=>{U({fadeOut:Number(b.value)||0},!1,"fadeOut")}),A(),{destroy(){R.disconnect(),ee(),e.removeEventListener("me-video-inspector-open",Ne),e.removeEventListener(Ht,de),Ar(e,i,!1),i.remove(),Pt(e)}}}function fa(e,t,n=()=>null){Qt();let r=!1,i=null,s=null,u=null,p=null;const v=typeof requestAnimationFrame=="function"?requestAnimationFrame:b=>setTimeout(b,16);function w(){r||(r=!0,v(()=>{r=!1,se()}))}function z(){return Xt(typeof n=="function"?n():null)==="en"?"Cover":"\u5C01\u9762"}function te(b){return[b.textContent,b.title,b.getAttribute("aria-label"),b.getAttribute("data-tool"),b.getAttribute("data-testid")].filter(Boolean).join(" ").replace(/\s+/g," ").trim()}function S(b){if(!(b instanceof HTMLElement)||b===i||b.classList.contains("me-video-cover-set-btn")||b.classList.contains("me-video-cover-upload-btn")||b.closest(".me-video-timeline-area"))return!1;for(let h=b.parentElement,y=0;h&&y<8;y+=1,h=h.parentElement){const N=String(h.textContent||"");if(N.includes("\u9009\u62E9\u5C01\u9762\u5E27")||/select\s+cover\s+frame/i.test(N))return!1}const _=te(b);return _?!!(_.includes("\u5C01\u9762")||/\b(cover|poster|thumbnail)\b/i.test(_)):!1}function B(){const b=e.querySelector(".me-video-toolrail"),h=(b?[...b.querySelectorAll('button,[role="button"]')]:[]).find(S);return h instanceof HTMLElement?h:[...e.querySelectorAll('button,[role="button"]')].find(S)}function V(){const b=e.querySelector(".me-video-timeline-scroll");return b instanceof HTMLElement?b:null}function ie(b){return[...b.children].find(_=>_ instanceof HTMLElement&&_!==p&&_.dataset.meTimelineCoverSlot!=="true")}function J(b){const h=b?.querySelector("[data-clipblock]")?.parentElement;return h instanceof HTMLElement?h:null}function oe(b,_){return p instanceof HTMLElement||(p=document.createElement("div"),p.className="me-video-timeline-cover-slot",p.dataset.meTimelineCoverSlot="true"),b.style.display="flex",b.style.alignItems="flex-start",_ instanceof HTMLElement&&(_.style.flex="0 0 auto"),(p.parentElement!==b||b.firstElementChild!==p)&&b.insertBefore(p,_??b.firstChild),p}function le(){return i instanceof HTMLButtonElement||(i=document.createElement("button"),i.type="button",i.className="me-video-timeline-cover-proxy",i.innerHTML='<img alt="" draggable="false"><svg class="me-video-timeline-cover-proxy-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 20h16"/><path d="M6 18l9.5-9.5a2.1 2.1 0 0 1 3 3L9 21H5v-4z"/><path d="M14 6l4 4"/></svg><span class="me-video-timeline-cover-proxy-label"></span>',i.addEventListener("click",b=>{b.preventDefault(),b.stopPropagation(),u?.click()})),i}function xe(){typeof t?.commit=="function"&&t.commit({poster:void 0}),w()}function ae(){return s instanceof HTMLButtonElement||(s=document.createElement("button"),s.type="button",s.className="me-video-timeline-cover-clear",s.innerHTML='<svg viewBox="0 0 12 12" aria-hidden="true"><path d="M3 3l6 6M9 3L3 9"/></svg>',s.addEventListener("click",b=>{b.preventDefault(),b.stopPropagation(),xe()})),s}function be(b,_,h){const y=z(),N=le(),j=ae(),re=N.querySelector(".me-video-timeline-cover-proxy-label");re&&(re.textContent=y);const I=N.querySelector("img"),D=typeof t?.getState=="function"?t.getState():{},K=D?.poster?.useAsVideoCover&&typeof D.poster.preview=="string"?D.poster.preview:"";I instanceof HTMLImageElement&&(K?I.src=K:I.removeAttribute("src")),N.classList.toggle("has-cover-image",!!K),N.title=b.title||b.getAttribute("aria-label")||y,N.setAttribute("aria-label",N.title),N.classList.toggle("is-active",b.classList.contains("is-active")||b.getAttribute("aria-pressed")==="true"),N.parentElement!==_&&_.insertBefore(N,_.firstChild),j.hidden=!K,j.title=Xt(typeof n=="function"?n():null)==="en"?"Remove cover":"\u53D6\u6D88\u5C01\u9762",j.setAttribute("aria-label",j.title),j.parentElement!==_&&_.appendChild(j),_.style.overflow="visible"}function se(){const b=B(),_=V(),h=_ instanceof HTMLElement?ie(_):null,y=h instanceof HTMLElement?J(h):null;if(!(b instanceof HTMLElement)||!(_ instanceof HTMLElement)||!(h instanceof HTMLElement)||!(y instanceof HTMLElement)){u&&(u.removeAttribute("data-me-cover-hidden"),u=null),i?.remove(),s?.remove(),p?.remove(),p=null;return}u&&u!==b&&u.removeAttribute("data-me-cover-hidden"),u=b,u.setAttribute("data-me-cover-hidden","true");const N=oe(_,h);be(b,N,y)}const k=new MutationObserver(()=>{w()});return k.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","style","title","aria-label","aria-pressed"]}),w(),{destroy(){k.disconnect(),u?.removeAttribute("data-me-cover-hidden"),i?.remove(),s?.remove(),p?.remove()}}}function pa(e,t,n=()=>null){Qt();let r=!1,i=null,s=null,u=null;const p=typeof requestAnimationFrame=="function"?requestAnimationFrame:I=>setTimeout(I,16);function v(){r||(r=!0,p(()=>{r=!1,N()}))}function w(){return Xt(typeof n=="function"?n():null)==="en"}function z(){const I=[...e.querySelectorAll('[role="dialog"], [aria-modal="true"]')];for(const K of I){if(!(K instanceof HTMLElement))continue;const M=String(K.textContent||"");if(M.includes("\u9009\u62E9\u5C01\u9762\u5E27")||/select\s+cover\s+frame/i.test(M))return{root:K}}const D=[...e.querySelectorAll("strong,h1,h2,h3,span,div")];for(const K of D){if(!(K instanceof HTMLElement))continue;const M=String(K.textContent||"").trim();if(!M.includes("\u9009\u62E9\u5C01\u9762\u5E27")&&!/select\s+cover\s+frame/i.test(M))continue;let X=K.parentElement;for(let Q=0;X&&Q<8;Q+=1,X=X.parentElement){if(!(X instanceof HTMLElement))continue;const W=[...X.querySelectorAll("button")].some(A=>{const de=String(A.textContent||A.title||A.getAttribute("aria-label")||"").trim();return de.includes("\u53D6\u6D88")||/cancel/i.test(de)||de==="\xD7"||de==="\xD7"}),U=!!X.querySelector('input[type="range"]'),T=!!X.querySelector("video,canvas,img")||[...X.querySelectorAll("div")].some(A=>/url\(["']?.+["']?\)/.test(String(A.style.backgroundImage||"")));if(W||U||T)return{root:X}}}return null}function te(I){const D=[...I.querySelectorAll("button")].filter(Q=>Q instanceof HTMLButtonElement&&Q!==i&&Q!==s),M=D.find(Q=>{const ce=String(Q.textContent||Q.title||"").trim();return ce.includes("\u5BFC\u51FA\u5C01\u9762")||/export\s+cover/i.test(ce)})??[...D].reverse().find(Q=>{const ce=String(Q.textContent||Q.title||"").trim();return!ce.includes("\u53D6\u6D88")&&!/cancel/i.test(ce)&&ce!=="\xD7"&&ce!=="\xD7"})??null;return{row:M?.parentElement??[...I.querySelectorAll("div")].filter(Q=>Q instanceof HTMLElement).sort((Q,ce)=>{const W=Q.getBoundingClientRect();return ce.getBoundingClientRect().bottom-W.bottom}).find(Q=>Q.querySelector("button"))??null,primaryButton:M}}function S(I){const K=String(I.textContent||"").match(/(\d{1,2}:\d{2}(?:\.\d+)?)\s*\//);if(K){const X=Jn(K[1]);if(Number.isFinite(X))return X}const M=I.querySelector('input[type="range"]');if(M instanceof HTMLInputElement){const X=Number(M.value);if(Number.isFinite(X))return Math.max(0,X)}return 0}function B(I){return new Promise((D,K)=>{const M=new Image;M.onload=()=>D(M),M.onerror=K,M.src=I})}function V(I,D){const K=Math.max(1,Math.round(Number(I)||0)),M=Math.max(1,Math.round(Number(D)||0));if(!K||!M)return null;const Q=Math.min(1,1920/Math.max(K,M));return{width:Math.max(1,Math.round(K*Q)),height:Math.max(1,Math.round(M*Q))}}function ie(I,D=null){const K=I instanceof HTMLImageElement?I.naturalWidth:I.videoWidth,M=I instanceof HTMLImageElement?I.naturalHeight:I.videoHeight;if(!K||!M)return"";const X=D?V(D.width,D.height):null,Q=X?.width??K,ce=X?.height??M,W=document.createElement("canvas");W.width=Q,W.height=ce;const U=W.getContext("2d");if(!U)return"";if(X){const T=Math.max(Q/K,ce/M),A=Q/T,de=ce/T,Ne=Math.max(0,(K-A)/2),R=Math.max(0,(M-de)/2);U.drawImage(I,Ne,R,Math.min(K,A),Math.min(M,de),0,0,Q,ce)}else U.drawImage(I,0,0,K,M);return W.toDataURL("image/png")}async function J(I){const D=String(I||"").trim();if(!D)return"";if(/^data:image\/(?:png|jpe?g);base64,/i.test(D))return D;try{const M=await(await fetch(D)).blob(),X=URL.createObjectURL(M);try{const Q=await B(X);return ie(Q)}finally{URL.revokeObjectURL(X)}}catch{try{const K=await B(D);return ie(K)}catch{return""}}}async function oe(I){const D=I.getBoundingClientRect(),K=D.top+D.height*.68;function M(T){const A=T.getBoundingClientRect();return A.width<80||A.height<120||A.top>K?null:A}const X=[...I.querySelectorAll("*")].map(T=>{if(!(T instanceof HTMLElement))return null;const A=M(T);if(!A)return null;const Ne=getComputedStyle(T).backgroundImage.match(/url\(["']?(.+?)["']?\)/);return Ne?{node:T,rect:A,src:Ne[1]}:null}).filter(Boolean).sort((T,A)=>A.rect.width*A.rect.height-T.rect.width*T.rect.height)[0];if(X?.src){const T=await J(X.src);if(T)return T}const Q=[...I.querySelectorAll("canvas")].map(T=>{const A=M(T);return A?{node:T,rect:A}:null}).filter(Boolean).sort((T,A)=>A.rect.width*A.rect.height-T.rect.width*T.rect.height)[0]?.node;if(Q instanceof HTMLCanvasElement)try{return Q.toDataURL("image/png")}catch{return""}const W=[...I.querySelectorAll("video")].map(T=>{const A=M(T);return T instanceof HTMLVideoElement&&A?{node:T,rect:A}:null}).filter(Boolean).sort((T,A)=>A.rect.width*A.rect.height-T.rect.width*T.rect.height)[0]?.node;if(W instanceof HTMLVideoElement&&W.videoWidth&&W.videoHeight)try{const T=document.createElement("canvas");T.width=W.videoWidth,T.height=W.videoHeight;const A=T.getContext("2d");return A?(A.drawImage(W,0,0,T.width,T.height),T.toDataURL("image/png")):""}catch{return""}const U=[...I.querySelectorAll("img")].map(T=>{const A=M(T);return T instanceof HTMLImageElement&&T.src&&A?{node:T,rect:A}:null}).filter(Boolean).sort((T,A)=>A.rect.width*A.rect.height-T.rect.width*T.rect.height)[0]?.node;if(U instanceof HTMLImageElement){try{const T=ie(U);if(T)return T}catch{}return J(U.src)}return""}function le(I){const D=I.getBoundingClientRect(),K=D.top+D.height*.68;function M(ce){const W=ce.getBoundingClientRect();return W.width<80||W.height<120||W.top>K?null:W}const X=[];for(const ce of I.querySelectorAll("video,canvas,img")){const W=M(ce);W&&(ce instanceof HTMLVideoElement&&ce.videoWidth&&ce.videoHeight?X.push({width:ce.videoWidth,height:ce.videoHeight,area:W.width*W.height}):ce instanceof HTMLCanvasElement&&ce.width&&ce.height?X.push({width:ce.width,height:ce.height,area:W.width*W.height}):ce instanceof HTMLImageElement&&X.push({width:ce.naturalWidth||W.width,height:ce.naturalHeight||W.height,area:W.width*W.height}))}const Q=X.filter(ce=>ce.width>0&&ce.height>0).sort((ce,W)=>W.area-ce.area)[0];return Q?V(Q.width,Q.height):null}function xe(I){return new Promise((D,K)=>{const M=new FileReader;M.onload=()=>D(String(M.result||"")),M.onerror=()=>K(M.error),M.readAsDataURL(I)})}async function ae(I,D){const K=String(I?.name||"");if(!(!!I&&(/^image\//.test(I.type||"")||/\.(png|jpe?g|webp|gif|bmp)$/i.test(K))))return"";const X=await xe(I);if(!X)return"";const Q=await B(X);return ie(Q,le(D))}function be(I){const D=[...I.querySelectorAll("button")],K=D.find(X=>{if(X===i)return!1;const Q=String(X.textContent||X.title||X.getAttribute("aria-label")||"").trim();return Q==="\xD7"||Q==="\xD7"||Q.includes("\u5173\u95ED")||/\b(close|dismiss)\b/i.test(Q)});if(K instanceof HTMLButtonElement){K.click();return}const M=D.find(X=>{const Q=String(X.textContent||"").trim();return Q==="\u53D6\u6D88"||/^cancel$/i.test(Q)});if(M instanceof HTMLButtonElement){M.click();return}document.dispatchEvent(new KeyboardEvent("keydown",{key:"Escape",bubbles:!0}))}function se(I,D){const K=S(I),M={time:K,useAsVideoCover:!0,...D?{preview:D}:{}};typeof t?.commit=="function"?t.commit({poster:M}):typeof t?.setPoster=="function"&&t.setPoster(K),be(I),v()}async function k(I){const D=await oe(I);se(I,D)}async function b(I,D){const K=await ae(D,I);K&&se(I,K)}function _(I){i instanceof HTMLButtonElement||(i=document.createElement("button"),i.type="button",i.className="me-video-cover-set-btn",i.addEventListener("click",async M=>{M.preventDefault(),M.stopPropagation();const X=z();if(X?.root){i.disabled=!0;try{await k(X.root)}finally{i.disabled=!1}}}));const K=!!(typeof t?.getState=="function"?t.getState():{})?.poster?.useAsVideoCover;return i.textContent=K?w()?"Cover set":"\u5DF2\u8BBE\u4E3A\u5C01\u9762":w()?"Set as cover":"\u8BBE\u4E3A\u5C01\u9762",i.classList.toggle("is-set",K),i.title=i.textContent,i.setAttribute("aria-label",i.textContent),i}function h(){return u instanceof HTMLInputElement||(u=document.createElement("input"),u.type="file",u.accept="image/png,image/jpeg,image/webp,image/*",u.hidden=!0,u.setAttribute("aria-hidden","true"),u.addEventListener("change",async()=>{const I=u.files?.[0];if(u.value="",!I)return;const D=z();if(D?.root){s instanceof HTMLButtonElement&&(s.disabled=!0);try{await b(D.root,I)}finally{s instanceof HTMLButtonElement&&(s.disabled=!1)}}}),e.appendChild(u)),u}function y(I){return s instanceof HTMLButtonElement||(s=document.createElement("button"),s.type="button",s.className="me-video-cover-upload-btn",s.addEventListener("click",D=>{D.preventDefault(),D.stopPropagation(),h().click()})),s.textContent=w()?"Upload cover":"\u4E0A\u4F20\u5C01\u9762",s.title=s.textContent,s.setAttribute("aria-label",s.textContent),s}function N(){const I=z();if(!I?.root){i?.remove(),s?.remove();return}const D=_(I.root),K=y(I.root),{row:M,primaryButton:X}=te(I.root);if(!(M instanceof HTMLElement))return;const Q=X instanceof HTMLElement&&X.parentElement===M?X:null;(D.parentElement!==M||Q&&D.nextElementSibling!==Q)&&M.insertBefore(D,Q),(K.parentElement!==M||K.nextElementSibling!==D)&&M.insertBefore(K,D)}const j=new MutationObserver(v);j.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","style","hidden","value"]});const re=typeof t?.subscribe=="function"?t.subscribe(v):null;return v(),{destroy(){j.disconnect(),re?.(),i?.remove(),s?.remove(),u?.remove()}}}function va(e,t,n=()=>null){kn();let r=!1;const i=typeof requestAnimationFrame=="function"?requestAnimationFrame:k=>setTimeout(k,16);function s(k){return!!k.closest(["[data-clipblock]","[data-audioclip]",".me-video-text-track-clip",".me-video-text-canvas-hit",".me-video-text-chip",".me-video-trim-action-btn",".me-video-transition-marker",".me-video-text-panel",".me-video-inspector-rail",".me-video-toolrail button",".me-video-timeline-zoom button","input","select","textarea","button","label"].join(","))}function u(k){return!!k.closest(["input","select","textarea",'[contenteditable="true"]','[contenteditable=""]'].join(","))}function p(){r||(r=!0,i(()=>{r=!1,ie()}))}function v(){const k=e.querySelector(".me-video-timeline-scroll");if(!(k instanceof HTMLElement))return;const b=Xt(typeof n=="function"?n():null);k.title=b==="en"?"Hold Ctrl or Shift to select multiple layers.":"\u6309\u4F4F Ctrl \u6216 Shift \u53EF\u591A\u9009\u56FE\u5C42\u3002"}function w(){const k=new Set(_t(e,"video"));for(const b of e.querySelectorAll("[data-clipblock]")){const _=Number(b.getAttribute("data-clipblock"));b.classList.toggle("me-video-multi-selected",Number.isInteger(_)&&k.has(_))}}function z(k=1/0){const b=Bn(e);if(!(b instanceof HTMLElement))return[];const _=[];for(const h of b.querySelectorAll("span")){if(!String(h.textContent??"").trim().startsWith("\u266A"))continue;const N=h.parentElement;!(N instanceof HTMLElement)||_.includes(N)||_.push(N)}return Number.isFinite(k)?_.slice(0,Math.max(0,k)):_}function te(){const k=t.getState().audioClips??[],b=new Set(_t(e,"audio")),_=z(),h=_.slice(0,k.length);_.slice(k.length).forEach(y=>{y instanceof HTMLElement&&(y.removeAttribute("data-audioclip"),y.classList.remove("me-video-multi-selected"),y.style.removeProperty("background"),y.style.removeProperty("border"),y.style.removeProperty("box-shadow"),y.style.removeProperty("color"),y.style.removeProperty("transform"),y.style.removeProperty("opacity"))}),h.forEach((y,N)=>{y.dataset.audioclip=String(N);const j=b.has(N),re=[...y.children].filter(W=>W instanceof HTMLElement),I=re.length>1?1:0,D=re[I]??null,K=re.filter((W,U)=>U!==I),M=[...y.querySelectorAll("span")],X=j?"linear-gradient(180deg, rgba(34,197,94,0.96) 0%, rgba(21,128,61,0.94) 100%)":"linear-gradient(180deg, rgba(220,252,231,0.98) 0%, rgba(187,247,208,0.94) 100%)",Q=j?"2px solid rgba(21,128,61,0.96)":"2px solid rgba(34,197,94,0.5)",ce="#166534";y.classList.toggle("me-video-multi-selected",j),y.style.boxShadow=j?"0 0 0 2px rgba(34,197,94,0.22), 0 8px 18px rgba(22,101,52,0.16)":"0 1px 6px rgba(22,101,52,0.08)",y.style.background=X,y.style.border=Q,y.style.color=ce,y.style.transform=j?"translateY(-1px)":"none",y.style.opacity=j?"1":"0.98",D instanceof HTMLElement&&(D.style.background=X,D.style.border=Q,D.style.color=ce,D.style.boxShadow=j?"0 0 0 1px rgba(21,128,61,0.14), 0 8px 18px rgba(22,101,52,0.14)":"0 1px 6px rgba(22,101,52,0.08)"),K.forEach(W=>{W.style.background=j?"rgba(21,128,61,0.92)":"rgba(34,197,94,0.72)",W.style.opacity="1"}),M.forEach((W,U)=>{W.style.color=U===0?ce:"rgba(22,101,52,0.9)",W.style.opacity="1"})})}function S(){return[...e.querySelectorAll(".me-video-trim-actions .me-video-trim-action-btn")].map(k=>{if(!(k instanceof HTMLElement)||k.tagName.toLowerCase()!=="button")return k;const b=document.createElement("div");for(const _ of[...k.attributes])_.name==="type"||_.name==="disabled"||b.setAttribute(_.name,_.value);return b.innerHTML=k.innerHTML,b.style.cssText=k.style.cssText,b.style.display="flex",b.style.justifyContent="center",b.style.alignItems="center",b.setAttribute("role","button"),b.tabIndex=k.disabled?-1:0,b.setAttribute("aria-disabled",k.disabled?"true":"false"),k.disabled&&(b.dataset.disabled="true"),k.replaceWith(b),b})}function B(k,b,_,h){const y=S();if(y.length<3)return;const N=k.clips??[],j=k.audioClips??[],re=yn(e),I=b.length>0||_.length>0||h.length>0,D=yi(N,b,re)||ki(j,_,re)||wi(k.overlays??[],h,re),K=I,M=_.length>0||h.length>0||b.length>0&&b.length<N.length,X=[D,K,M];y.forEach((Q,ce)=>{const W=X[ce];Q.setAttribute("aria-disabled",W?"false":"true"),Q.tabIndex=W?0:-1,W?delete Q.dataset.disabled:Q.dataset.disabled="true",Q.style.opacity=W?"1":"0.5",ce===2?(Q.style.color=W?"#dc2626":"var(--me-fg-muted, #9a9aa3)",Q.style.background="",Q.style.boxShadow=""):(Q.style.color=W?"var(--me-fg, #ededf0)":"var(--me-fg-muted, #9a9aa3)",Q.style.background="",Q.style.boxShadow="")})}function V(k){k===0?Si(e,t):k===1?Ei(e,t):k===2&&pr(e,t),p()}function ie(){const k=t.getState();mi(e,k),v();const b=Dn(e,k.clips??[]),_=Mn(e,k.audioClips??[]),h=_n(e,k);w(),te(),B(k,b,_,h)}function J(k){if(!(k.target instanceof Element))return;const b=k.target.closest("[data-clipblock]");if(!b||!e.contains(b))return;const _=Number(b.getAttribute("data-clipblock"));if(!Number.isInteger(_))return;const h=(t.getState().clips??[]).map((y,N)=>N);if(k.shiftKey||k.ctrlKey||k.metaKey){k.preventDefault(),k.stopPropagation(),zt(e,"video",_,k,h),p();return}bt(e,"video",[_]),p()}function oe(k){if(!(k.target instanceof Element))return;const b=k.target.closest("[data-audioclip]");if(!b||!e.contains(b))return;const _=Number(b.getAttribute("data-audioclip"));if(!Number.isInteger(_))return;const h=(t.getState().audioClips??[]).map((y,N)=>N);if(k.shiftKey||k.ctrlKey||k.metaKey){k.preventDefault(),k.stopPropagation(),zt(e,"audio",_,k,h),p();return}bt(e,"audio",[_]),p()}function le(k){k.target instanceof Element&&e.contains(k.target)&&(s(k.target)||So(e)&&(Eo(e),p()))}function xe(k){if(!(k.target instanceof Element))return;const b=k.target.closest("[data-clipblock]");if(b&&e.contains(b)&&(k.shiftKey||k.ctrlKey||k.metaKey)){k.preventDefault(),k.stopPropagation();return}const _=k.target.closest(".me-video-trim-actions .me-video-trim-action-btn");if(!_||!e.contains(_))return;const y=[...e.querySelectorAll(".me-video-trim-actions .me-video-trim-action-btn")].indexOf(_);y!==-1&&(k.preventDefault(),k.stopPropagation(),_.getAttribute("aria-disabled")!=="true"&&V(y))}function ae(k){if(!(k.target instanceof Element))return;if((k.key==="Delete"||k.key==="Backspace")&&!u(k.target)&&So(e)){k.preventDefault(),k.stopPropagation(),pr(e,t),p();return}if(k.key!=="Enter"&&k.key!==" ")return;const b=k.target.closest(".me-video-trim-actions .me-video-trim-action-btn");if(!b||!e.contains(b))return;const h=[...e.querySelectorAll(".me-video-trim-actions .me-video-trim-action-btn")].indexOf(b);h!==-1&&(k.preventDefault(),k.stopPropagation(),b.getAttribute("aria-disabled")!=="true"&&V(h))}const be=new MutationObserver(()=>{p()});be.observe(e,{childList:!0,subtree:!0}),e.addEventListener("pointerdown",J,!0),e.addEventListener("pointerdown",oe,!0),e.addEventListener("pointerdown",le,!0),e.addEventListener("click",xe,!0),e.addEventListener("keydown",ae,!0),e.addEventListener(Ht,p),window.addEventListener("resize",p);const se=t.subscribe(()=>{p()});return ie(),{destroy(){be.disconnect(),se(),e.removeEventListener("pointerdown",J,!0),e.removeEventListener("pointerdown",oe,!0),e.removeEventListener("pointerdown",le,!0),e.removeEventListener("click",xe,!0),e.removeEventListener("keydown",ae,!0),e.removeEventListener(Ht,p),window.removeEventListener("resize",p)}}}const mo=[{key:"480p",label:"480P",shortEdge:480},{key:"720p",label:"720P",shortEdge:720},{key:"1080p",label:"1080P",shortEdge:1080},{key:"2k",label:"2K",shortEdge:1440},{key:"4k",label:"4K",shortEdge:2160},{key:"8k",label:"8K",shortEdge:4320},{key:"source",label:"\u539F\u59CB"},{key:"custom",label:"\u81EA\u5B9A\u4E49"}],ha=[{key:"mov",label:"MOV",extension:"mov"},{key:"mp4",label:"MP4",extension:"mp4"},{key:"mxf",label:"MXF",extension:"mxf"}],xa=[24,25,30,50,60],ba=[{key:"aac",label:"AAC"},{key:"mp3",label:"MP3"}],ga=[96,128,192,256,320],Hr="me-video-export-enhancer-styles";function ya(){if(document.getElementById(Hr))return;const e=document.createElement("style");e.id=Hr,e.textContent=`
|
|
2048
2048
|
.me-video-export-overlay {
|
|
2049
2049
|
position: absolute;
|
|
2050
2050
|
inset: 0;
|
|
@@ -2059,6 +2059,34 @@ import{mountVideoEditor as _r}from"./legacy.js";import{FILTER_PRESETS as jr,buil
|
|
|
2059
2059
|
.me-video-export-overlay[hidden] {
|
|
2060
2060
|
display: none !important;
|
|
2061
2061
|
}
|
|
2062
|
+
.me-video-export-overlay[data-theme="dark"] {
|
|
2063
|
+
--me-bg: #08080a;
|
|
2064
|
+
--me-surface: #141416;
|
|
2065
|
+
--me-chip: #1c1c20;
|
|
2066
|
+
--me-elevated: #1c1c20;
|
|
2067
|
+
--me-border: #26262b;
|
|
2068
|
+
--me-border-strong: #34343a;
|
|
2069
|
+
--me-fg: #ededf0;
|
|
2070
|
+
--me-fg-muted: #9a9aa3;
|
|
2071
|
+
--me-accent: #7c7cf0;
|
|
2072
|
+
--me-accent-hover: #8f8ff5;
|
|
2073
|
+
--me-accent-fg: #ffffff;
|
|
2074
|
+
color-scheme: dark;
|
|
2075
|
+
}
|
|
2076
|
+
.me-video-export-overlay[data-theme="light"] {
|
|
2077
|
+
--me-bg: #ffffff;
|
|
2078
|
+
--me-surface: #fafafa;
|
|
2079
|
+
--me-chip: #f1f1f3;
|
|
2080
|
+
--me-elevated: #ffffff;
|
|
2081
|
+
--me-border: #e6e6e8;
|
|
2082
|
+
--me-border-strong: #d4d4d8;
|
|
2083
|
+
--me-fg: #0a0a0a;
|
|
2084
|
+
--me-fg-muted: #6b6b76;
|
|
2085
|
+
--me-accent: #5b5bd6;
|
|
2086
|
+
--me-accent-hover: #4f4fc9;
|
|
2087
|
+
--me-accent-fg: #ffffff;
|
|
2088
|
+
color-scheme: light;
|
|
2089
|
+
}
|
|
2062
2090
|
.me-video-export-card {
|
|
2063
2091
|
width: min(920px, 100%);
|
|
2064
2092
|
max-height: min(760px, calc(100vh - 48px));
|
|
@@ -2301,7 +2329,7 @@ import{mountVideoEditor as _r}from"./legacy.js";import{FILTER_PRESETS as jr,buil
|
|
|
2301
2329
|
justify-content: flex-end;
|
|
2302
2330
|
}
|
|
2303
2331
|
}
|
|
2304
|
-
`,document.head.appendChild(e)}function Pr(e){return String(e??"").trim().replace(/\.[a-z0-9]+$/i,"")}function Do(e,t="video"){return String(e??"").replace(/[\\/:*?"<>|]+/g," ").replace(/\s+/g," ").trim()||t}function wn(e,t,n,r){const a=Math.round(Number(e));return Number.isFinite(a)?Math.min(n,Math.max(t,a)):r}function zn(e,t){const n=wn(e,2,8192,t);return n%2===0?n:n-1}function Hr(e){return jo(e.canvas,e)}function Xa(e){const t=Math.max(0,Math.round(Number(e)||0)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),a=t%60;return n>0?`${n}:${String(r).padStart(2,"0")}:${String(a).padStart(2,"0")}`:`${r}:${String(a).padStart(2,"0")}`}function wa(e){const t=Math.max(0,Math.round(Number(e)||0)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),a=t%60;return n>0?a>0?`${n} \u5C0F\u65F6 ${r} \u5206 ${a} \u79D2`:`${n} \u5C0F\u65F6 ${r} \u5206`:r>0?a>0?`${r} \u5206 ${a} \u79D2`:`${r} \u5206`:`${a} \u79D2`}function ka(e){const t=Math.max(0,Number(e)||0);return t>=1024*1024*1024?`${(t/(1024*1024*1024)).toFixed(2).replace(/\.?0+$/,"")} GB`:t>=1024*1024?`${(t/(1024*1024)).toFixed(t>=10*1024*1024?0:1).replace(/\.?0+$/,"")} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${Math.round(t)} B`}function po(e){return`${e.w}\xD7${e.h}`}function Pn(e,t="mp4"){const n=String(e??"").toLowerCase();return n==="mov"||n==="mxf"||n==="mp4"?n:t}function Ea(e,t="mp4"){const n=String(e??"").match(/\.([a-z0-9]+)$/i);return Pn(n?.[1],t)}function Sa(e,t,n,r){const a=fo(e,t.key,n,r);return`${t.label} \xB7 ${po(a)}`}function fo(e,t,n,r){const a=Hr(e);if(t==="source")return a;if(t==="custom")return{w:zn(n,a.w),h:zn(r,a.h)};const s=mo.find(v=>v.key===t);if(!s?.shortEdge)return a;const u=a.w>0&&a.h>0?a.w/a.h:1;if(a.w<=a.h){const v=zn(s.shortEdge,a.w);return{w:v,h:zn(v/u,a.h)}}const f=zn(s.shortEdge,a.h);return{w:zn(f*u,a.w),h:f}}function _o(e,t){const n=Math.min(e.w,e.h);let r=2200;return n<=480?r=1400:n<=720?r=3200:n<=1080?r=6800:n<=1440?r=12e3:n<=2160?r=22e3:r=48e3,t>=50&&(r=Math.round(r*1.35)),r}function La(e){const t=e.exportSettings;if(!t?.width||!t?.height)return"source";const n=Math.min(t.width,t.height);return mo.find(a=>a.shortEdge&&Math.abs(a.shortEdge-n)<=6)?.key??"custom"}function Ta(e,t,n){const r=String(t||n||"video.mp4"),a=Pn(e.exportSettings?.format,Ea(r,"mp4"));return`${Do(e.exportSettings?.fileName||Pr(r),"video")}.${a}`}function Ir(e,t,n){return typeof e.onExported!="function"?e:{...e,onExported(r,a){e.onExported(r,Ta(t.getState(),a,n()))}}}function Ma(e){let t=!1;const n=typeof requestAnimationFrame=="function"?requestAnimationFrame:v=>setTimeout(v,16),r=[".me-video-preview-footer span"].join(",");function a(v){return String(v??"").replace(/(\d+:\d{2})\.\d+/g,"$1")}function s(){for(const v of e.querySelectorAll(r)){if(v instanceof HTMLElement&&v.childElementCount>0)continue;const k=String(v.textContent??"");if(!/^\s*\d+:\d{2}(?:\.\d+)?(?:\s*\/\s*\d+:\d{2}(?:\.\d+)?)?\s*$/.test(k))continue;if(v instanceof HTMLElement){const G=String(v.dataset.meRawTimeText||""),T=a(G);(!G||k!==T)&&(v.dataset.meRawTimeText=k)}const H=a(k);H!==v.textContent&&(v.textContent=H)}}function u(){t||(t=!0,n(()=>{t=!1,s()}))}const f=new MutationObserver(()=>{u()});return f.observe(e,{childList:!0,subtree:!0,characterData:!0}),u(),{destroy(){f.disconnect()}}}function Ca(e){let t=!1,n=null;const r=new Set,a=typeof requestAnimationFrame=="function"?requestAnimationFrame:k=>setTimeout(k,16);function s(k){!n||!(k instanceof HTMLElement)||r.has(k)||(n.observe(k),r.add(k))}function u(){const k=e.querySelector(".me-video-workspace");k instanceof HTMLElement&&k.style.setProperty("padding","0","important");const H=e.querySelector(".me-video-preview-shell");if(!(H instanceof HTMLElement))return;const G=H.querySelector(".me-video-preview-scroll");if(!(G instanceof HTMLElement))return;const T=H.querySelector(".me-video-preview-footer"),F=G.querySelector(".me-video-canvas-stage"),j=T instanceof HTMLElement?Math.ceil(T.getBoundingClientRect().height):0,oe=Math.max(0,H.clientHeight-j);H.style.display="grid",H.style.gridTemplateRows=T instanceof HTMLElement?"minmax(0, 1fr) auto":"minmax(0, 1fr)",H.style.height="100%",H.style.minHeight="0",H.style.gap="0",H.style.overflow="hidden",H.style.boxSizing="border-box",G.style.alignSelf="stretch",G.style.justifySelf="stretch",G.style.flex="1 1 0",G.style.minHeight="0",G.style.maxHeight="none",G.style.height=oe>0?`${oe}px`:"100%",F instanceof HTMLElement&&(F.style.minHeight="100%",F.style.boxSizing="border-box"),s(H),s(G),s(T),s(F)}function f(){t||(t=!0,a(()=>{t=!1,u()}))}typeof ResizeObserver=="function"&&(n=new ResizeObserver(()=>{f()}));const v=new MutationObserver(()=>{f()});return v.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("resize",f),f(),{destroy(){v.disconnect(),n?.disconnect?.(),window.removeEventListener("resize",f)}}}function Na(e,t){let a=!1,s=null;const u=typeof requestAnimationFrame=="function"?requestAnimationFrame:C=>setTimeout(C,16);function f(C,y){return Number.isInteger(C?.track)&&C.track>=0?C.track:y}function v(C){const y=[...new Set((C??[]).map(f))].sort((O,Y)=>O-Y);return y.length?y:[0]}function k(C){const y=v(C);return new Map(y.map((O,Y)=>[O,Y]))}function H(C,y){const O=v(C);return y<O.length?O[y]:Math.max(...O)+1}function G(C,y,O=!1){const Y=Math.max(0,Math.round(Number(y)||0)),B=t.getState().audioClips??[],q=B[C];if(!q||f(q,C)===Y)return;const V=B.map((X,re)=>re===C?{...X,track:Y}:X);if(O){t.patch({audioClips:V},{transient:!0});return}t.commit({audioClips:V})}function T(){return Fn(e)}function F(C){if(!(C instanceof HTMLElement))return null;const y=[...C.children].filter(Y=>Y instanceof HTMLElement),O=y.findIndex(Y=>Y.querySelector("[data-clipblock]"));return O===-1?null:y[O+1]instanceof HTMLElement?y[O+1]:null}function j(C,y=1/0){if(!(C instanceof HTMLElement))return[];const O=[...C.children].filter(Y=>Y instanceof HTMLElement&&/♪/.test(Y.textContent??"")&&!!Y.querySelector("span"));return Number.isFinite(y)?O.slice(0,Math.max(0,y)):O}function oe(C,y){if(!(C instanceof HTMLElement)||!(y instanceof HTMLElement))return!1;let O=C;for(;O&&O!==y;){if(`${O.style?.cursor||""} ${typeof window<"u"&&window.getComputedStyle?window.getComputedStyle(O).cursor:""}`.includes("ew-resize"))return!0;O=O.parentElement}return!1}function Q(C,y,O){if(!(C instanceof HTMLElement)||!Number.isFinite(O))return null;const Y=C.getBoundingClientRect(),L=32,q=v(y).length,V=Math.floor(Math.max(0,O-Y.top)/L),X=ae(V,0,q);return H(y,X)}function Z(){const y=t.getState().audioClips??[],O=e.querySelector(".me-video-timeline-area"),Y=e.querySelector(".me-video-timeline-scroll"),L=e.querySelector(".me-video-trim-panel"),B=T(),q=F(B);if(!(O instanceof HTMLElement)||!(Y instanceof HTMLElement)||!(q instanceof HTMLElement))return;const V=k(y),X=Math.max(1,V.size||y.length||1),re=32,pe=X>0?X*28+Math.max(0,X-1)*4:28;O.style.setProperty("max-height","none","important"),O.style.setProperty("overflow","visible","important"),Y.style.setProperty("overflow-y","visible","important"),L instanceof HTMLElement&&L.style.setProperty("overflow","visible","important"),q.style.height=`${pe}px`,q.style.minHeight=`${pe}px`,q.style.overflow="visible";const se="color-mix(in srgb, var(--me-chip, #f1f1f3) 90%, var(--me-border, #d4d4d8) 10%)",N="color-mix(in srgb, var(--me-fg, #374151) 82%, var(--me-fg-muted, #6b7280) 18%)",b="transparent";q.style.background=X>1?`repeating-linear-gradient(to bottom, ${se} 0px, ${se} 28px, color-mix(in srgb, var(--me-border, #d4d4d8) 42%, transparent) 28px, color-mix(in srgb, var(--me-border, #d4d4d8) 42%, transparent) ${re}px)`:se,q.style.backgroundSize=`100% ${re}px`;const le=j(q,y.length),Le=new Set(le),ve=y.length===0;q.style.color=ve?N:"",[...q.children].forEach(D=>{if(D instanceof HTMLElement&&!Le.has(D)){if(ve){D.style.background="transparent",D.style.border="none",D.style.boxShadow="none",D.style.borderColor=b,D.style.color=N,D.querySelectorAll("span, label, button, strong, small").forEach(ee=>{ee instanceof HTMLElement&&(ee.style.color=N,ee.style.background="transparent",ee.style.border="none",ee.style.borderColor=b,ee.style.boxShadow="none")});return}D.style.removeProperty("background"),D.style.removeProperty("border"),D.style.removeProperty("box-shadow"),D.style.removeProperty("border-color"),D.style.removeProperty("color"),D.querySelectorAll("span, label, button, strong, small").forEach(ee=>{ee instanceof HTMLElement&&(ee.style.removeProperty("color"),ee.style.removeProperty("background"),ee.style.removeProperty("border"),ee.style.removeProperty("border-color"),ee.style.removeProperty("box-shadow"))})}}),le.forEach((D,ee)=>{const _=y[ee],K=f(_,ee),fe=V.get(K)??ee;D.style.top=`${fe*re+2}px`,D.style.bottom="auto",D.style.height="24px"});const Ie=O.lastElementChild;if(Ie instanceof HTMLElement){const ee=Ie.querySelectorAll("label")[1];ee instanceof HTMLElement&&(ee.style.height=`${pe}px`,ee.style.minHeight=`${pe}px`,ve?(ee.style.background=se,ee.style.border="none",ee.style.borderColor=b,ee.style.boxShadow="none",ee.style.color=N,ee.querySelectorAll("span, strong, small").forEach(_=>{_ instanceof HTMLElement&&(_.style.color=N,_.style.border="none")})):(ee.style.removeProperty("background"),ee.style.removeProperty("border"),ee.style.removeProperty("border-color"),ee.style.removeProperty("box-shadow"),ee.style.removeProperty("color"),ee.querySelectorAll("span, strong, small").forEach(_=>{_ instanceof HTMLElement&&(_.style.removeProperty("color"),_.style.removeProperty("border"))})))}}function ie(){a||(a=!0,u(()=>{a=!1,Z()}))}function he(C){if(C.button!==0||!(C.target instanceof Element))return;const y=C.target.closest("[data-audioclip]");if(!(y instanceof HTMLElement)||!e.contains(y)||oe(C.target,y))return;const O=Number(y.getAttribute("data-audioclip"));if(!Number.isInteger(O))return;const L=(t.getState().audioClips??[])[O];L&&(s={index:O,pointerId:C.pointerId,startTrack:f(L,O),currentTrack:f(L,O)})}function ne(C){if(!s||C.pointerId!==s.pointerId)return;const y=T(),O=F(y),Y=t.getState().audioClips??[],L=Q(O,Y,C.clientY);!Number.isInteger(L)||L===s.currentTrack||(s.currentTrack=L,G(s.index,L,!0),ie())}function xe(C,y=!1){if(!s||C!==s.pointerId)return;const O=s;if(s=null,y){O.currentTrack!==O.startTrack&&G(O.index,O.startTrack,!1);return}O.currentTrack!==O.startTrack&&(G(O.index,O.currentTrack,!1),ie())}function te(C){xe(C.pointerId,!1)}function w(C){xe(C.pointerId,!0)}const x=new MutationObserver(()=>{ie()});x.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"]}),e.addEventListener(zt,ie),e.addEventListener("pointerdown",he,!0),window.addEventListener("pointermove",ne),window.addEventListener("pointerup",te),window.addEventListener("pointercancel",w),window.addEventListener("resize",ie);const E=t.subscribe(()=>{ie()});return ie(),{destroy(){x.disconnect(),E(),e.removeEventListener(zt,ie),e.removeEventListener("pointerdown",he,!0),window.removeEventListener("resize",ie),window.removeEventListener("pointermove",ne),window.removeEventListener("pointerup",te),window.removeEventListener("pointercancel",w)}}}function Aa(e){let t=!1;const n=typeof requestAnimationFrame=="function"?requestAnimationFrame:f=>setTimeout(f,16);function r(){t||(t=!0,n(()=>{t=!1,s()}))}function a(f){return String(f?.style?.transform||"").includes("translateX(-50%)")}function s(){const f=or(e);if(f instanceof HTMLElement)for(const v of[...f.children]){if(!(v instanceof HTMLElement)||a(v))continue;const k=Jn(Qn(v));Number.isFinite(k)&&Math.abs(k-Math.round(k))>.001?(v.dataset.meIntegerTickHidden="true",v.style.setProperty("display","none","important")):v.dataset.meIntegerTickHidden==="true"&&(v.style.removeProperty("display"),delete v.dataset.meIntegerTickHidden)}}const u=new MutationObserver(()=>{r()});return u.observe(e,{childList:!0,subtree:!0,characterData:!0}),e.addEventListener(zt,r),window.addEventListener("resize",r),r(),{destroy(){u.disconnect(),e.removeEventListener(zt,r),window.removeEventListener("resize",r)}}}let Rr=!1;function Oa(){if(Rr||typeof document>"u")return;const e=document.createElement("style");e.id="me-video-trim-history-enhancer-style",e.textContent=`
|
|
2332
|
+
`,document.head.appendChild(e)}function zr(e){return String(e??"").trim().replace(/\.[a-z0-9]+$/i,"")}function Do(e,t="video"){return String(e??"").replace(/[\\/:*?"<>|]+/g," ").replace(/\s+/g," ").trim()||t}function wn(e,t,n,r){const i=Math.round(Number(e));return Number.isFinite(i)?Math.min(n,Math.max(t,i)):r}function Hn(e,t){const n=wn(e,2,8192,t);return n%2===0?n:n-1}function Pr(e){return jo(e.canvas,e)}function Xa(e){const t=Math.max(0,Math.round(Number(e)||0)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(r).padStart(2,"0")}:${String(i).padStart(2,"0")}`:`${r}:${String(i).padStart(2,"0")}`}function wa(e){const t=Math.max(0,Math.round(Number(e)||0)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?i>0?`${n} \u5C0F\u65F6 ${r} \u5206 ${i} \u79D2`:`${n} \u5C0F\u65F6 ${r} \u5206`:r>0?i>0?`${r} \u5206 ${i} \u79D2`:`${r} \u5206`:`${i} \u79D2`}function ka(e){const t=Math.max(0,Number(e)||0);return t>=1024*1024*1024?`${(t/(1024*1024*1024)).toFixed(2).replace(/\.?0+$/,"")} GB`:t>=1024*1024?`${(t/(1024*1024)).toFixed(t>=10*1024*1024?0:1).replace(/\.?0+$/,"")} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${Math.round(t)} B`}function fo(e){return`${e.w}\xD7${e.h}`}function zn(e,t="mp4"){const n=String(e??"").toLowerCase();return n==="mov"||n==="mxf"||n==="mp4"?n:t}function Ea(e,t="mp4"){const n=String(e??"").match(/\.([a-z0-9]+)$/i);return zn(n?.[1],t)}function Sa(e,t,n,r){const i=po(e,t.key,n,r);return`${t.label} \xB7 ${fo(i)}`}function po(e,t,n,r){const i=Pr(e);if(t==="source")return i;if(t==="custom")return{w:Hn(n,i.w),h:Hn(r,i.h)};const s=mo.find(v=>v.key===t);if(!s?.shortEdge)return i;const u=i.w>0&&i.h>0?i.w/i.h:1;if(i.w<=i.h){const v=Hn(s.shortEdge,i.w);return{w:v,h:Hn(v/u,i.h)}}const p=Hn(s.shortEdge,i.h);return{w:Hn(p*u,i.w),h:p}}function _o(e,t){const n=Math.min(e.w,e.h);let r=2200;return n<=480?r=1400:n<=720?r=3200:n<=1080?r=6800:n<=1440?r=12e3:n<=2160?r=22e3:r=48e3,t>=50&&(r=Math.round(r*1.35)),r}function La(e){const t=e.exportSettings;if(!t?.width||!t?.height)return"source";const n=Math.min(t.width,t.height);return mo.find(i=>i.shortEdge&&Math.abs(i.shortEdge-n)<=6)?.key??"custom"}function Ta(e,t,n){const r=String(t||n||"video.mp4"),i=zn(e.exportSettings?.format,Ea(r,"mp4"));return`${Do(e.exportSettings?.fileName||zr(r),"video")}.${i}`}function Ir(e,t,n){return typeof e.onExported!="function"?e:{...e,onExported(r,i){e.onExported(r,Ta(t.getState(),i,n()))}}}function Ma(e){let t=!1;const n=typeof requestAnimationFrame=="function"?requestAnimationFrame:v=>setTimeout(v,16),r=[".me-video-preview-footer span"].join(",");function i(v){return String(v??"").replace(/(\d+:\d{2})\.\d+/g,"$1")}function s(){for(const v of e.querySelectorAll(r)){if(v instanceof HTMLElement&&v.childElementCount>0)continue;const w=String(v.textContent??"");if(!/^\s*\d+:\d{2}(?:\.\d+)?(?:\s*\/\s*\d+:\d{2}(?:\.\d+)?)?\s*$/.test(w))continue;if(v instanceof HTMLElement){const te=String(v.dataset.meRawTimeText||""),S=i(te);(!te||w!==S)&&(v.dataset.meRawTimeText=w)}const z=i(w);z!==v.textContent&&(v.textContent=z)}}function u(){t||(t=!0,n(()=>{t=!1,s()}))}const p=new MutationObserver(()=>{u()});return p.observe(e,{childList:!0,subtree:!0,characterData:!0}),u(),{destroy(){p.disconnect()}}}function Ca(e){let t=!1,n=null;const r=new Set,i=typeof requestAnimationFrame=="function"?requestAnimationFrame:w=>setTimeout(w,16);function s(w){!n||!(w instanceof HTMLElement)||r.has(w)||(n.observe(w),r.add(w))}function u(){const w=e.querySelector(".me-video-workspace");w instanceof HTMLElement&&w.style.setProperty("padding","0","important");const z=e.querySelector(".me-video-preview-shell");if(!(z instanceof HTMLElement))return;const te=z.querySelector(".me-video-preview-scroll");if(!(te instanceof HTMLElement))return;const S=z.querySelector(".me-video-preview-footer"),B=te.querySelector(".me-video-canvas-stage"),V=S instanceof HTMLElement?Math.ceil(S.getBoundingClientRect().height):0,ie=Math.max(0,z.clientHeight-V);z.style.display="grid",z.style.gridTemplateRows=S instanceof HTMLElement?"minmax(0, 1fr) auto":"minmax(0, 1fr)",z.style.height="100%",z.style.minHeight="0",z.style.gap="0",z.style.overflow="hidden",z.style.boxSizing="border-box",te.style.alignSelf="stretch",te.style.justifySelf="stretch",te.style.flex="1 1 0",te.style.minHeight="0",te.style.maxHeight="none",te.style.height=ie>0?`${ie}px`:"100%",B instanceof HTMLElement&&(B.style.minHeight="100%",B.style.boxSizing="border-box"),s(z),s(te),s(S),s(B)}function p(){t||(t=!0,i(()=>{t=!1,u()}))}typeof ResizeObserver=="function"&&(n=new ResizeObserver(()=>{p()}));const v=new MutationObserver(()=>{p()});return v.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("resize",p),p(),{destroy(){v.disconnect(),n?.disconnect?.(),window.removeEventListener("resize",p)}}}function Na(e,t){let i=!1,s=null;const u=typeof requestAnimationFrame=="function"?requestAnimationFrame:h=>setTimeout(h,16);function p(h,y){return Number.isInteger(h?.track)&&h.track>=0?h.track:y}function v(h){const y=[...new Set((h??[]).map(p))].sort((N,j)=>N-j);return y.length?y:[0]}function w(h){const y=v(h);return new Map(y.map((N,j)=>[N,j]))}function z(h,y){const N=v(h);return y<N.length?N[y]:Math.max(...N)+1}function te(h,y,N=!1){const j=Math.max(0,Math.round(Number(y)||0)),I=t.getState().audioClips??[],D=I[h];if(!D||p(D,h)===j)return;const K=I.map((M,X)=>X===h?{...M,track:j}:M);if(N){t.patch({audioClips:K},{transient:!0});return}t.commit({audioClips:K})}function S(){return Bn(e)}function B(h){if(!(h instanceof HTMLElement))return null;const y=[...h.children].filter(j=>j instanceof HTMLElement),N=y.findIndex(j=>j.querySelector("[data-clipblock]"));return N===-1?null:y[N+1]instanceof HTMLElement?y[N+1]:null}function V(h,y=1/0){if(!(h instanceof HTMLElement))return[];const N=[...h.children].filter(j=>j instanceof HTMLElement&&/♪/.test(j.textContent??"")&&!!j.querySelector("span"));return Number.isFinite(y)?N.slice(0,Math.max(0,y)):N}function ie(h,y){if(!(h instanceof HTMLElement)||!(y instanceof HTMLElement))return!1;let N=h;for(;N&&N!==y;){if(`${N.style?.cursor||""} ${typeof window<"u"&&window.getComputedStyle?window.getComputedStyle(N).cursor:""}`.includes("ew-resize"))return!0;N=N.parentElement}return!1}function J(h,y,N){if(!(h instanceof HTMLElement)||!Number.isFinite(N))return null;const j=h.getBoundingClientRect(),re=32,D=v(y).length,K=Math.floor(Math.max(0,N-j.top)/re),M=ue(K,0,D);return z(y,M)}function oe(){const y=t.getState().audioClips??[],N=e.querySelector(".me-video-timeline-area"),j=e.querySelector(".me-video-timeline-scroll"),re=e.querySelector(".me-video-trim-panel"),I=S(),D=B(I);if(!(N instanceof HTMLElement)||!(j instanceof HTMLElement)||!(D instanceof HTMLElement))return;const K=w(y),M=Math.max(1,K.size||y.length||1),X=32,Q=M>0?M*28+Math.max(0,M-1)*4:28;N.style.setProperty("max-height","none","important"),N.style.setProperty("overflow","visible","important"),j.style.setProperty("overflow-y","visible","important"),re instanceof HTMLElement&&re.style.setProperty("overflow","visible","important"),D.style.height=`${Q}px`,D.style.minHeight=`${Q}px`,D.style.overflow="visible";const ce="color-mix(in srgb, var(--me-chip, #f1f1f3) 90%, var(--me-border, #d4d4d8) 10%)",W="color-mix(in srgb, var(--me-fg, #374151) 82%, var(--me-fg-muted, #6b7280) 18%)",U="transparent";D.style.background=M>1?`repeating-linear-gradient(to bottom, ${ce} 0px, ${ce} 28px, color-mix(in srgb, var(--me-border, #d4d4d8) 42%, transparent) 28px, color-mix(in srgb, var(--me-border, #d4d4d8) 42%, transparent) ${X}px)`:ce,D.style.backgroundSize=`100% ${X}px`;const T=V(D,y.length),A=new Set(T),de=y.length===0;D.style.color=de?W:"",[...D.children].forEach(R=>{if(R instanceof HTMLElement&&!A.has(R)){if(de){R.style.background="transparent",R.style.border="none",R.style.boxShadow="none",R.style.borderColor=U,R.style.color=W,R.querySelectorAll("span, label, button, strong, small").forEach(ee=>{ee instanceof HTMLElement&&(ee.style.color=W,ee.style.background="transparent",ee.style.border="none",ee.style.borderColor=U,ee.style.boxShadow="none")});return}R.style.removeProperty("background"),R.style.removeProperty("border"),R.style.removeProperty("box-shadow"),R.style.removeProperty("border-color"),R.style.removeProperty("color"),R.querySelectorAll("span, label, button, strong, small").forEach(ee=>{ee instanceof HTMLElement&&(ee.style.removeProperty("color"),ee.style.removeProperty("background"),ee.style.removeProperty("border"),ee.style.removeProperty("border-color"),ee.style.removeProperty("box-shadow"))})}}),T.forEach((R,ee)=>{const Y=y[ee],G=p(Y,ee),pe=K.get(G)??ee;R.style.top=`${pe*X+2}px`,R.style.bottom="auto",R.style.height="24px"});const Ne=N.lastElementChild;if(Ne instanceof HTMLElement){const ee=Ne.querySelectorAll("label")[1];ee instanceof HTMLElement&&(ee.style.height=`${Q}px`,ee.style.minHeight=`${Q}px`,de?(ee.style.background=ce,ee.style.border="none",ee.style.borderColor=U,ee.style.boxShadow="none",ee.style.color=W,ee.querySelectorAll("span, strong, small").forEach(Y=>{Y instanceof HTMLElement&&(Y.style.color=W,Y.style.border="none")})):(ee.style.removeProperty("background"),ee.style.removeProperty("border"),ee.style.removeProperty("border-color"),ee.style.removeProperty("box-shadow"),ee.style.removeProperty("color"),ee.querySelectorAll("span, strong, small").forEach(Y=>{Y instanceof HTMLElement&&(Y.style.removeProperty("color"),Y.style.removeProperty("border"))})))}}function le(){i||(i=!0,u(()=>{i=!1,oe()}))}function xe(h){if(h.button!==0||!(h.target instanceof Element))return;const y=h.target.closest("[data-audioclip]");if(!(y instanceof HTMLElement)||!e.contains(y)||ie(h.target,y))return;const N=Number(y.getAttribute("data-audioclip"));if(!Number.isInteger(N))return;const re=(t.getState().audioClips??[])[N];re&&(s={index:N,pointerId:h.pointerId,startTrack:p(re,N),currentTrack:p(re,N)})}function ae(h){if(!s||h.pointerId!==s.pointerId)return;const y=S(),N=B(y),j=t.getState().audioClips??[],re=J(N,j,h.clientY);!Number.isInteger(re)||re===s.currentTrack||(s.currentTrack=re,te(s.index,re,!0),le())}function be(h,y=!1){if(!s||h!==s.pointerId)return;const N=s;if(s=null,y){N.currentTrack!==N.startTrack&&te(N.index,N.startTrack,!1);return}N.currentTrack!==N.startTrack&&(te(N.index,N.currentTrack,!1),le())}function se(h){be(h.pointerId,!1)}function k(h){be(h.pointerId,!0)}const b=new MutationObserver(()=>{le()});b.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"]}),e.addEventListener(Ht,le),e.addEventListener("pointerdown",xe,!0),window.addEventListener("pointermove",ae),window.addEventListener("pointerup",se),window.addEventListener("pointercancel",k),window.addEventListener("resize",le);const _=t.subscribe(()=>{le()});return le(),{destroy(){b.disconnect(),_(),e.removeEventListener(Ht,le),e.removeEventListener("pointerdown",xe,!0),window.removeEventListener("resize",le),window.removeEventListener("pointermove",ae),window.removeEventListener("pointerup",se),window.removeEventListener("pointercancel",k)}}}function Aa(e){let t=!1;const n=typeof requestAnimationFrame=="function"?requestAnimationFrame:p=>setTimeout(p,16);function r(){t||(t=!0,n(()=>{t=!1,s()}))}function i(p){return String(p?.style?.transform||"").includes("translateX(-50%)")}function s(){const p=or(e);if(p instanceof HTMLElement)for(const v of[...p.children]){if(!(v instanceof HTMLElement)||i(v))continue;const w=Jn(Qn(v));Number.isFinite(w)&&Math.abs(w-Math.round(w))>.001?(v.dataset.meIntegerTickHidden="true",v.style.setProperty("display","none","important")):v.dataset.meIntegerTickHidden==="true"&&(v.style.removeProperty("display"),delete v.dataset.meIntegerTickHidden)}}const u=new MutationObserver(()=>{r()});return u.observe(e,{childList:!0,subtree:!0,characterData:!0}),e.addEventListener(Ht,r),window.addEventListener("resize",r),r(),{destroy(){u.disconnect(),e.removeEventListener(Ht,r),window.removeEventListener("resize",r)}}}let Rr=!1;function Oa(){if(Rr||typeof document>"u")return;const e=document.createElement("style");e.id="me-video-trim-history-enhancer-style",e.textContent=`
|
|
2305
2333
|
.me-video-history[data-trim-proxy-hidden="true"] {
|
|
2306
2334
|
display: none !important;
|
|
2307
2335
|
}
|
|
@@ -2373,7 +2401,7 @@ import{mountVideoEditor as _r}from"./legacy.js";import{FILTER_PRESETS as jr,buil
|
|
|
2373
2401
|
display: none;
|
|
2374
2402
|
}
|
|
2375
2403
|
}
|
|
2376
|
-
`,document.head.appendChild(e),Rr=!0}function
|
|
2404
|
+
`,document.head.appendChild(e),Rr=!0}function Ha(e){Oa();let t=!1,n=null;const r=typeof requestAnimationFrame=="function"?requestAnimationFrame:S=>setTimeout(S,16);function i(){return e.querySelector(".me-video-topbar .me-video-history")}function s(){const S=i();return S instanceof HTMLElement?[...S.querySelectorAll("button")]:[]}function u(S){n instanceof HTMLElement||(n=document.createElement("div"),n.className="me-video-trim-history-proxy");const B=S.querySelector(".me-video-trim-action-btn");return n.parentElement!==S?S.insertBefore(n,B??S.firstChild):B&&n.nextElementSibling!==B&&S.insertBefore(n,B),n}function p(S,B){const V=String(S??"").trim();if(!V)return"";if(B===0){if(/\s/.test(V))return V.split(/\s+/)[0];if(V.length>2)return V.slice(0,2)}return V}function v(S,B,V){S.dataset.historyIndex=String(V);const ie=S.querySelector(".me-video-trim-history-proxy-icon"),J=S.querySelector(".me-video-trim-history-proxy-label");ie instanceof HTMLElement&&ie.innerHTML!==B.innerHTML&&(ie.innerHTML=B.innerHTML),S.disabled=B.disabled,S.title=B.title||"";const oe=B.getAttribute("aria-label"),le=(oe||B.title||"").trim();J instanceof HTMLElement&&(J.textContent=p(le,V)),oe?S.setAttribute("aria-label",oe):S.removeAttribute("aria-label")}function w(){const S=i(),B=e.querySelector(".me-video-trim-actions");if(!(S instanceof HTMLElement)||!(B instanceof HTMLElement)){S?.removeAttribute("data-trim-proxy-hidden"),n?.remove();return}const V=s();if(!V.length){S.removeAttribute("data-trim-proxy-hidden"),n?.remove();return}S.setAttribute("data-trim-proxy-hidden","true");const ie=u(B),J=[];for(V.forEach((oe,le)=>{let xe=ie.children[le];if(!(xe instanceof HTMLButtonElement)){xe=document.createElement("button"),xe.type="button",xe.className="me-video-trim-history-proxy-btn";const ae=document.createElement("span");ae.className="me-video-trim-history-proxy-icon";const be=document.createElement("span");be.className="me-video-trim-history-proxy-label",xe.append(ae,be),xe.addEventListener("click",()=>{const se=s()[le];!se||se.disabled||(se.click(),z())}),ie.appendChild(xe)}v(xe,oe,le),J.push(xe)});ie.children.length>J.length;)ie.lastElementChild?.remove()}function z(){t||(t=!0,r(()=>{t=!1,w()}))}const te=new MutationObserver(()=>{z()});return te.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["disabled","style","class","hidden","title","aria-label"]}),window.addEventListener("resize",z),z(),{destroy(){te.disconnect(),window.removeEventListener("resize",z),i()?.removeAttribute("data-trim-proxy-hidden"),n?.remove()}}}function za(e,t,n,r=()=>null){ya();const i=document.createElement("div");i.className="me-video-export-overlay",i.hidden=!0,i.innerHTML=`
|
|
2377
2405
|
<div class="me-video-export-card" role="dialog" aria-modal="true" aria-label="\u5BFC\u51FA\u8BBE\u7F6E">
|
|
2378
2406
|
<div class="me-video-export-head">
|
|
2379
2407
|
<strong class="me-video-export-title">\u5BFC\u51FA\u8BBE\u7F6E</strong>
|
|
@@ -2454,4 +2482,4 @@ import{mountVideoEditor as _r}from"./legacy.js";import{FILTER_PRESETS as jr,buil
|
|
|
2454
2482
|
</div>
|
|
2455
2483
|
</div>
|
|
2456
2484
|
</div>
|
|
2457
|
-
`,e.appendChild(
|
|
2485
|
+
`,e.appendChild(i);const s=i.querySelector(".me-video-export-close"),u=i.querySelector('[data-action="cancel"]'),p=i.querySelector('[data-action="confirm"]'),v=i.querySelector("img"),w=i.querySelector(".me-video-export-preview-empty"),z=i.querySelector(".me-video-export-preview-note"),te=i.querySelector(".me-video-export-summary-value"),S=i.querySelector("[data-custom-resolution]"),B=i.querySelector('[data-field="title"]'),V=i.querySelector('[data-field="resolutionPreset"]'),ie=i.querySelector('[data-field="customWidth"]'),J=i.querySelector('[data-field="customHeight"]'),oe=i.querySelector('[data-field="customResolutionHint"]'),le=i.querySelector('[data-field="format"]'),xe=i.querySelector('[data-field="frameRate"]'),ae=i.querySelector('[data-field="bitrateMode"]'),be=i.querySelector('[data-field="videoBitrateKbps"]'),se=i.querySelector('[data-field="videoBitrateHint"]'),k=i.querySelector('[data-field="audioCodec"]'),b=i.querySelector('[data-field="audioBitrateKbps"]'),_=new Map;for(const T of mo){const A=document.createElement("option");A.value=T.key,A.textContent=T.label,V.appendChild(A),_.set(T.key,A)}for(const T of ha){const A=document.createElement("option");A.value=T.key,A.textContent=T.label,le.appendChild(A)}for(const T of xa){const A=document.createElement("option");A.value=String(T),A.textContent=`${T} FPS`,xe.appendChild(A)}for(const T of ba){const A=document.createElement("option");A.value=T.key,A.textContent=T.label,k.appendChild(A)}for(const T of ga){const A=document.createElement("option");A.value=String(T),A.textContent=`${T} kbps`,b.appendChild(A)}let h=null,y=!1;function N(){i.dataset.theme=Rn(typeof r=="function"?r():null)}function j(){const T=e.querySelector(".me-video-canvas-stage canvas, .me-video-preview-scroll canvas");if(!(T instanceof HTMLCanvasElement))return"";try{return T.toDataURL("image/png")}catch{return""}}function re(){const T=j();if(T){v.src=T,v.hidden=!1,w.hidden=!0;return}v.hidden=!0,w.hidden=!1}function I(){const T=t.getState(),A=Pr(T),de=La(T),Ne=po(T,de,T.exportSettings?.width??A.w,T.exportSettings?.height??A.h),R=wn(T.exportSettings?.frameRate,12,120,30),ee=_o(Ne,R);return{title:Do(T.exportSettings?.fileName||zr(n()),"video"),resolutionPreset:de,customWidth:T.exportSettings?.width??A.w,customHeight:T.exportSettings?.height??A.h,format:zn(T.exportSettings?.format,"mp4"),frameRate:R,bitrateMode:T.exportSettings?.videoBitrateKbps!=null?"custom":"auto",videoBitrateKbps:T.exportSettings?.videoBitrateKbps??ee,audioCodec:T.exportSettings?.audioCodec??"aac",audioBitrateKbps:T.exportSettings?.audioBitrateKbps??192}}function D(){const T=t.getState(),A=wn(h.frameRate,12,120,30),de=po(T,h.resolutionPreset,h.customWidth,h.customHeight),Ne=_o(de,A);return{fileName:Do(h.title,"video"),width:h.resolutionPreset==="source"?void 0:de.w,height:h.resolutionPreset==="source"?void 0:de.h,format:zn(h.format,"mp4"),frameRate:A,videoBitrateKbps:h.bitrateMode==="custom"?wn(h.videoBitrateKbps,100,5e4,Ne):void 0,audioBitrateKbps:wn(h.audioBitrateKbps,32,320,192),audioCodec:h.audioCodec==="mp3"?"mp3":"aac"}}function K(){if(!h)return;N();const T=t.getState(),A=po(T,h.resolutionPreset,h.customWidth,h.customHeight),de=_o(A,h.frameRate),Ne=h.bitrateMode==="custom"?wn(h.videoBitrateKbps,100,5e4,de):de,R=wn(h.audioBitrateKbps,32,320,192),ee=Math.max(0,Number(t.contentDuration())||0),Y=ee>0?(Ne+R)*1e3*ee/8:0;for(const G of mo){const pe=_.get(G.key);pe&&(pe.textContent=Sa(T,G,h.customWidth,h.customHeight))}B.value=h.title,V.value=h.resolutionPreset,ie.value=String(h.customWidth),J.value=String(h.customHeight),le.value=zn(h.format,"mp4"),xe.value=String(h.frameRate),ae.value=h.bitrateMode,be.value=String(Ne),be.disabled=h.bitrateMode!=="custom",k.value=h.audioCodec,b.value=String(R),S.dataset.active=h.resolutionPreset==="custom"?"true":"false",oe.textContent=h.resolutionPreset==="custom"?`\u5F53\u524D\u6309\u81EA\u5B9A\u4E49\u5927\u5C0F\u5BFC\u51FA\uFF1A${fo(A)}`:`\u4FEE\u6539\u5BBD\u9AD8\u4F1A\u81EA\u52A8\u5207\u6362\u4E3A\u81EA\u5B9A\u4E49\u5927\u5C0F\uFF0C\u5F53\u524D\u9884\u8BBE\u8F93\u51FA\uFF1A${fo(A)}`,se.textContent=h.bitrateMode==="custom"?`\u5EFA\u8BAE\u503C ${de} kbps`:`\u81EA\u52A8\u7801\u7387\u5C06\u6309 ${de} kbps \u4F30\u7B97`,z.textContent=`\u8F93\u51FA\u5C3A\u5BF8 ${fo(A)} \xB7 ${h.frameRate} FPS \xB7 ${zn(h.format,"mp4").toUpperCase()} \xB7 \u97F3\u9891 ${R} kbps`,te.textContent=`\u65F6\u957F: ${wa(ee)} | \u5927\u5C0F: ${ka(Y)}\uFF08\u4F30\u8BA1\uFF09`,re()}function M(){N(),h=I(),i.hidden=!1,K()}function X(){i.hidden=!0,h=null}function Q(){!h||!(e.querySelector(".me-video-done")instanceof HTMLButtonElement)||(t.commit({exportSettings:D()}),y=!0,X(),requestAnimationFrame(()=>{const A=e.querySelector(".me-video-done");A instanceof HTMLButtonElement&&A.click()}))}function ce(T){if(!(T.target instanceof Element))return;const A=T.target.closest(".me-video-done");if(!(!A||!e.contains(A))&&!(!(A instanceof HTMLButtonElement)||A.disabled)){if(y){y=!1;return}T.preventDefault(),T.stopPropagation(),M()}}function W(T){T.key==="Escape"&&!i.hidden&&(T.preventDefault(),X())}function U(T,A){h&&(h={...h,[T]:A},K())}return s.addEventListener("click",X),u.addEventListener("click",X),p.addEventListener("click",Q),i.addEventListener("click",T=>{T.target===i&&X()}),B.addEventListener("input",()=>U("title",B.value)),V.addEventListener("change",()=>U("resolutionPreset",V.value)),le.addEventListener("change",()=>U("format",le.value)),ie.addEventListener("input",()=>{h&&(h={...h,resolutionPreset:"custom",customWidth:ie.value},K())}),J.addEventListener("input",()=>{h&&(h={...h,resolutionPreset:"custom",customHeight:J.value},K())}),xe.addEventListener("change",()=>U("frameRate",xe.value)),ae.addEventListener("change",()=>U("bitrateMode",ae.value)),be.addEventListener("input",()=>U("videoBitrateKbps",be.value)),k.addEventListener("change",()=>U("audioCodec",k.value)),b.addEventListener("change",()=>U("audioBitrateKbps",b.value)),e.addEventListener("click",ce,!0),window.addEventListener("keydown",W),{destroy(){e.removeEventListener("click",ce,!0),window.removeEventListener("keydown",W),i.remove()}}}function Fr(e,t={}){const n=t.height??"100vh",r=()=>{document.fullscreenElement!==e&&e.style.setProperty("--me-editor-shell-height",n)};return r(),requestAnimationFrame(r),window.addEventListener("resize",r),document.addEventListener("fullscreenchange",r),()=>{window.removeEventListener("resize",r),document.removeEventListener("fullscreenchange",r)}}function Pa(e,t={}){const{append:n=!0,backButton:r="\u8FD4\u56DE",className:i="editor-shell",fitToViewport:s=!0,height:u="auto",hostClassName:p="editor-host",actionsClassName:v="editor-actions",onBack:w}=t,z=document.createElement("div");z.className=i,u!=="auto"&&(z.style.height=u);const te=document.createElement("div");te.className=v;let S=null;r!==!1&&(r instanceof HTMLElement?S=r:(S=document.createElement("button"),S.type="button",S.className="btn btn-ghost",S.textContent=typeof r=="string"?r:"\u8FD4\u56DE"),S&&typeof w=="function"&&S.addEventListener("click",w),S&&te.appendChild(S));const B=document.createElement("div");B.className=p,z.append(te,B),n!==!1&&e.appendChild(z);const V=s?Fr(z):()=>{};return{shell:z,actions:te,host:B,backButton:S,destroy(){V(),S&&typeof w=="function"&&S.removeEventListener("click",w),z.remove()}}}function Ia(e,t={}){e.style.position||(e.style.position="relative");const n=document.createElement("div");n.style.cssText="position:relative;width:100%;height:100%;min-height:0;overflow:hidden",e.appendChild(n);const r=document.createElement("div");r.style.cssText="width:100%;height:100%;min-height:0",n.appendChild(r);const i=t.engine??new Xr,s=()=>{const h=u.source;return h&&typeof h=="object"&&"name"in h&&typeof h.name=="string"?h.name:"video.mp4"};let u={...t,engine:i},p=_r(r,Ir(u,i,s));const v=ra(n,i,()=>u.theme,()=>u.locale),w=la(n,i,()=>u.theme,()=>u.locale),z=aa(n,i,()=>u.locale),te=sa(n,i,()=>u.theme,()=>u.locale),S=ia(n,i,()=>u.locale),B=da(n,i,()=>u.theme,()=>u.locale),V=ca(n,i,()=>u.locale),ie=ua(n,i,()=>u.locale),J=ma(n,i,()=>u.locale),oe=fa(n,i,()=>u.locale),le=pa(n,i,()=>u.locale),xe=va(n,i,()=>u.locale),ae=Ha(n),be=Ca(n),se=Ma(n),k=Na(n,i),b=Aa(n),_=za(n,i,s,()=>u.theme);return{update(h={}){u={...u,...h,engine:i},p.update(Ir(u,i,s))},destroy(){_.destroy(),k.destroy(),se.destroy(),be.destroy(),ae.destroy(),b.destroy(),xe.destroy(),le.destroy(),oe.destroy(),J.destroy(),ie.destroy(),V.destroy(),B.destroy(),S.destroy(),te.destroy(),z.destroy(),w.destroy(),v.destroy(),p.destroy(),n.remove()}}}export{Ka as VideoEditorEngine,Pa as createVideoEditorShell,Fr as fitVideoEditorShellToViewport,Ia as mountVideoEditor};
|