xvai-loi 0.1.74 → 0.1.75

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.
Files changed (3) hide show
  1. package/co.txt +1 -1
  2. package/package.json +1 -1
  3. package/xvai-loi.js +564 -558
package/co.txt CHANGED
@@ -1 +1 @@
1
- xvaiLoi111930
1
+ xvaiLoi112023
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xvai-loi",
3
- "version": "0.1.74",
3
+ "version": "0.1.75",
4
4
  "description": "Loi dung video (Edit Video Tu Dong) nap vao tool Google Flow qua o cam engine/oCam.ts",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
package/xvai-loi.js CHANGED
@@ -17720,534 +17720,123 @@ var DE_CM = 'B\u1EA1n l\xE0 \u0111\u1EA1o di\u1EC5n h\xECnh cho video d\u1ECDc n
17720
17720
  var DE_SUA = 'B\u1EA1n l\xE0 bi\xEAn t\u1EADp vi\xEAn so\xE1t ph\u1EE5 \u0111\u1EC1 ti\u1EBFng Vi\u1EC7t do m\xE1y nghe ch\xE9p l\u1EA1i t\u1EEB m\u1ED9t video n\xF3i tr\u01B0\u1EDBc m\xE1y. T\xECm M\u1ECCI c\u1EE5m b\u1ECB nghe nh\u1EA7m (t\xEAn ri\xEAng, t\xEAn c\xF4ng c\u1EE5, t\u1EEB ti\u1EBFng Anh b\u1ECB phi\xEAn \xE2m, sai d\u1EA5u, t\u1EEB v\xF4 ngh\u0129a so v\u1EDBi ng\u1EEF c\u1EA3nh, con s\u1ED1 \u0111\u1ECDc b\u1EB1ng ch\u1EEF) r\u1ED3i tr\u1EA3 v\u1EC1 \u0110\xDANG M\u1ED8T JSON {"sua":[["c\u1EE5m SAI nguy\xEAn v\u0103n 1-4 t\u1EEB \u0111\xFAng nh\u01B0 trong l\u1EDDi","c\u1EE5m \u0110\xDANG"]]}, t\u1ED1i \u0111a 40 c\u1EB7p, kh\xF4ng gi\u1EA3i th\xEDch. L\u1EDDi: ';
17721
17721
  var DE_CANH = 'B\u1EA1n l\xE0 \u0111\u1EA1o di\u1EC5n h\xECnh cho video d\u1ECDc n\xF3i tr\u01B0\u1EDBc m\xE1y ki\u1EC3u "Top N c\xF4ng c\u1EE5". D\u01B0\u1EDBi \u0111\xE2y l\xE0 l\u1EDDi n\xF3i c\xF3 m\u1ED1c gi\xE2y [gi\xE2y]. H\xE3y l\u1EADp DANH S\xC1CH C\u1EA2NH D\xC0Y: 1 c\u1EA3nh m\u1ED7i 2,5-3,5 gi\xE2y l\u1EDDi, ph\u1EE7 \u0111\u1EC1u t\u1EEB \u0111\u1EA7u t\u1EDBi cu\u1ED1i, m\u1ED7i c\u1EA3nh neo v\xE0o \u0111\xFAng c\u1EE5m t\u1EEB \u0111ang n\xF3i. Tr\u1EA3 v\u1EC1 \u0110\xDANG M\u1ED8T JSON {"canh":[{"tu":"2-4 t\u1EEB NGUY\xCAN V\u0102N li\u1EC1n nhau trong l\u1EDDi","kieu":"anh|vat|chu|so|ds","dong":["kieu ds: 2-3 \xFD NGUY\xCAN V\u0102N \u2264 3 t\u1EEB m\u1ED7i \xFD, \u0111\xFAng th\u1EE9 t\u1EF1 n\xF3i"],"chu":"ch\u1EEF kh\xF3a \u2264 3 t\u1EEB IN HOA t\xF3m \xFD","chu2":"d\xF2ng ph\u1EE5 \u2264 3 t\u1EEB ho\u1EB7c r\u1ED7ng","icon":"tien|dongho|canhbao|tich|bieudo|tim|lua|tenlua|bongden|qua|giohang|nha|sach|dienthoai|cup|khien|la|giot|kinhlup|sai|khong \u2014 bi\u1EC3u t\u01B0\u1EE3ng nh\u1ECF CH\u1EC8 khi \u0111\xFAng ngh\u0129a c\xE2u n\xF3i (vd: t\u1ED1n ti\u1EC1n \u2192 tien; tri\u1EC7u view \u2192 bieudo; xong vi\u1EC7c \u2192 tich), kh\xF4ng ch\u1EAFc \u2192 khong","en":"kieu anh: 1 \u1EA3nh ch\u1EE5p th\u1EADt b\u1EB1ng ti\u1EBFng Anh MINH HO\u1EA0 \u0110\xDANG NGH\u0128A c\u1EE5m \u0111ang n\xF3i (vd \u0111i\u1EC7p vi\xEAn \u0111\u1ED1i th\u1EE7 \u2192 a man in dark hoodie secretly studying competitor ads on several monitors; l\u01B0\u1EDBt \u0111i\u1EC7n tho\u1EA1i \u2192 a woman lying on sofa scrolling her phone), ng\u01B0\u1EDDi Vi\u1EC7t, KH\xD4NG ch\u1EEF; kieu vat: 1 v\u1EADt/bi\u1EC3u t\u01B0\u1EE3ng 3D b\u1EB1ng ti\u1EBFng Anh; chu/so: r\u1ED7ng"}]}, kh\xF4ng gi\u1EA3i th\xEDch. KH\xD4NG \u0111\u1EB7t c\u1EA3nh tr\xF9ng 3 gi\xE2y \u0111\u1EA7u m\u1ED7i m\u1EE5c c\xF4ng c\u1EE5 (\u0111\xE3 c\xF3 th\u1EBB c\xF4ng c\u1EE5); con s\u1ED1 trong l\u1EDDi (x10, 1 ph\xFAt, 2 ng\u01B0\u1EDDi) \u2192 kieu so. anh cho n\u1ED7i \u0111au, b\u1ED1i c\u1EA3nh, \u1EA9n d\u1EE5 (ph\u1EA7n m\u1EDF: 3-4 \u1EA3nh n\u1ED1i nhau); vat cho \u0111\u1ED3 v\u1EADt, bi\u1EC3u t\u01B0\u1EE3ng; chu cho c\xE2u \u0111\u1EAFt; so cho con s\u1ED1 c\xF3 trong l\u1EDDi. Kh\xF4ng b\u1ECBa s\u1ED1. L\u1EDDi: ';
17722
17722
 
17723
- // flow-src/engine/doanMau.ts
17724
- var DE2 = 'B\u1EA1n l\xE0 bi\xEAn t\u1EADp vi\xEAn k\u1ECBch b\u1EA3n video ng\u1EAFn ti\u1EBFng Vi\u1EC7t. \u0110\u1ECDc l\u1EDDi n\xF3i b\xEAn d\u01B0\u1EDBi r\u1ED3i tr\u1EA3 v\u1EC1 \u0111\xFAng m\u1ED9t d\xF2ng JSON d\u1EA1ng {"moc":"...","chot":"..."}. moc = 2 \u0111\u1EBFn 6 t\u1EEB l\u1EA5y NGUY\xCAN V\u0102N trong c\xE2u \u0111\u1EA7u ti\xEAn, n\xEAu ch\u1EE7 \u0111\u1EC1 video; chot = l\u1EDDi ch\u1ED1t 3 \u0111\u1EBFn 6 t\u1EEB; vat = t\u1ED1i \u0111a 4 \u0111\u1ED3 v\u1EADt c\u1EE5 th\u1EC3 nh\u1EAFc trong l\u1EDDi, d\u1EA1ng {"tu":"t\u1EEB \u0111\xFAng nh\u01B0 trong l\u1EDDi","en":"t\xEAn \u0111\u1ED3 v\u1EADt ti\u1EBFng Anh, c\xF3 ch\u1EA5t li\u1EC7u / m\xE0u"}; tieu = \u0111\xFAng 2 t\u1EEB NGUY\xCAN V\u0102N li\u1EC1n nhau trong c\xE2u \u0111\u1EA7u, l\xE0 danh t\u1EEB ch\u1EE7 \u0111\u1EC1 (vd "l\xF2ng ng\u01B0\u1EDDi"); nhan = 1 t\u1EEB \u0111\u1EAFt nh\u1EA5t g\xE2y ch\xFA \xFD (t\xEDnh t\u1EEB ho\u1EB7c t\u1EEB l\xF3ng, vd "b\u1EA3nh") NGUY\xCAN V\u0102N trong l\u1EDDi. D\xF9ng t\u1EEB c\xF3 trong l\u1EDDi, kh\xF4ng gi\u1EA3i th\xEDch. L\u1EDDi n\xF3i: ';
17725
- var NGUONG_CHU = 3950;
17726
- var chiaKhuc = (x, n) => {
17727
- const ra = [];
17728
- let s = x;
17729
- while (s.length > n) {
17730
- let c = s.lastIndexOf(". ", n);
17731
- if (c < n * 0.5) c = s.lastIndexOf(" ", n);
17732
- if (c < n * 0.5) c = n;
17733
- ra.push(s.slice(0, c + 1).trim());
17734
- s = s.slice(c + 1);
17735
- }
17736
- if (s.trim()) ra.push(s.trim());
17737
- return ra;
17738
- };
17739
- var gopJson = (a, b) => {
17740
- if (!a) return b;
17741
- if (!b) return a;
17742
- const r = { ...a };
17743
- for (const k of Object.keys(b)) {
17744
- if (Array.isArray(b[k])) r[k] = (Array.isArray(a[k]) ? a[k] : []).concat(b[k]);
17745
- else if (!r[k]) r[k] = b[k];
17746
- }
17747
- return r;
17748
- };
17749
- async function hoiChuDai(de, x, opt) {
17750
- const k = "ai:" + bamDem(de + "" + x + "" + JSON.stringify(opt || {})), dem = await docDem(k);
17751
- if (dem && dem.j) {
17752
- globalThis.__kbDem = (globalThis.__kbDem || 0) + 1;
17753
- return JSON.parse(JSON.stringify(dem.j));
17754
- }
17755
- const n = Math.max(600, NGUONG_CHU - de.length - 30), ks = de.length + x.length <= NGUONG_CHU ? [x] : chiaKhuc(x, n);
17756
- let j = null;
17757
- for (let i = 0; i < ks.length; i++) {
17758
- const dau = ks.length > 1 ? "[\u0110o\u1EA1n " + (i + 1) + "/" + ks.length + " c\u1EE7a l\u1EDDi] " : "";
17759
- const r = await Flow.generate.text(de + dau + ks[i], opt), t = String(r && r.text || "");
17760
- j = gopJson(j, JSON.parse(t.slice(t.indexOf("{"), t.lastIndexOf("}") + 1)));
17761
- }
17762
- globalThis.__kbKhuc = ks.length;
17763
- if (j && typeof j === "object") ghiDem(k, { j });
17764
- return j;
17765
- }
17766
- var hoiAI = async (de, x) => hoiChuDai(de, x, { thinkingLevel: "medium" });
17767
- async function kichBanDoan(ws) {
17768
- const loi2 = ws.map((w) => w.text).join(" ");
17769
- let h = 5381;
17770
- for (let i = 0; i < loi2.length; i++) h = (h * 33 ^ loi2.charCodeAt(i)) >>> 0;
17771
- const van = { n: ws.length, dau: loi2.slice(0, 160).toLocaleLowerCase("vi"), cuoi: loi2.slice(-160).toLocaleLowerCase("vi") };
17772
- const cm = String(globalThis.__mauPhuDe || "").indexOf("giong-cuongme") === 0, hp = (() => {
17773
- const t = cm ? DE_CM : DE2;
17774
- let x = 5381;
17775
- for (let i = 0; i < t.length; i++) x = (x * 33 ^ t.charCodeAt(i)) >>> 0;
17776
- return x.toString(36).slice(0, 5);
17777
- })(), khoa3 = (cm ? "xvaiKbCm9" + hp + ":" : "xvaiKb3:") + h.toString(36);
17778
- try {
17779
- const c = JSON.parse(localStorage.getItem(khoa3) || "null");
17780
- if (c && c.moc) {
17781
- globalThis.__kbNguon = "dem";
17782
- return c;
17783
- }
17784
- } catch (e) {
17785
- }
17723
+ // flow-src/engine/khoAnh.ts
17724
+ var laVideo = (b, ten = "") => /^video\/(mp4|webm)/.test(b.type) || /\.(mp4|webm)$/i.test(ten);
17725
+ var db = () => new Promise((ok) => {
17786
17726
  try {
17787
- const b = await docDem("kb:" + khoa3);
17788
- if (b && b.moc) {
17789
- globalThis.__kbNguon = "ben";
17790
- return JSON.parse(JSON.stringify(b));
17791
- }
17727
+ const r = indexedDB.open("xvaiKhoVideo", 1);
17728
+ r.onupgradeneeded = () => r.result.createObjectStore("kho");
17729
+ r.onsuccess = () => ok(r.result);
17730
+ r.onerror = () => ok(null);
17792
17731
  } catch (e) {
17732
+ ok(null);
17793
17733
  }
17794
- if (cm) {
17795
- const dau = van.dau;
17796
- for (const k of Object.keys(localStorage)) {
17797
- if (k.indexOf(khoa3.split(":")[0] + ":") !== 0) continue;
17734
+ });
17735
+ async function themKho(files) {
17736
+ const d = await db();
17737
+ if (!d) return 0;
17738
+ let n = 0;
17739
+ for (const f2 of files) {
17740
+ const v = laVideo(f2, f2.name);
17741
+ if (!v && !/^image\//.test(f2.type)) continue;
17742
+ let dai2 = 0;
17743
+ if (v) {
17798
17744
  try {
17799
- const c = JSON.parse(localStorage.getItem(k) || "null"), v = c && c.van;
17800
- if (c && c.moc && Array.isArray(c.canh) && c.canh.length > 10 && dau.indexOf(String(c.moc).toLocaleLowerCase("vi").slice(0, 18)) >= 0 && v && v.dau === van.dau && v.cuoi === van.cuoi && Math.abs((v.n || 0) - van.n) <= van.n * 0.1) {
17801
- globalThis.__kbNguon = "gan:" + k;
17802
- return c;
17803
- }
17745
+ dai2 = (await khungGiuaVideo(f2)).dai;
17804
17746
  } catch (e) {
17747
+ continue;
17805
17748
  }
17749
+ if (!(dai2 > 0.3) || dai2 > 15.5) continue;
17750
+ }
17751
+ try {
17752
+ d.transaction("kho", "readwrite").objectStore("kho").put({ ten: f2.name, blob: f2, loai: v ? "video" : "anh", dai: dai2 }, f2.name + ":" + f2.size);
17753
+ n++;
17754
+ } catch (e) {
17755
+ }
17756
+ }
17757
+ if (n) {
17758
+ try {
17759
+ const ds2 = await layKho();
17760
+ const L = ds2.map((m) => ({ id: m.id, ten: m.ten, blob: m.blob, loai: m.loai, dai: m.dai || 0 }));
17761
+ globalThis.__khoNgoaiDs = L;
17762
+ hoiNgoai("luu", "khoVideo", L);
17763
+ } catch (e) {
17806
17764
  }
17807
17765
  }
17766
+ return n;
17767
+ }
17768
+ try {
17769
+ globalThis.__themKho = (fs) => themKho(fs);
17770
+ } catch (e) {
17771
+ }
17772
+ async function xoaKho() {
17773
+ const d = await db();
17808
17774
  try {
17809
- let j = null;
17810
- for (let lan2 = 0; lan2 < 5 && !(j && j.moc); lan2++) {
17811
- if (lan2) await new Promise((r) => setTimeout(r, [0, 5e3, 15e3, 3e4, 6e4][lan2]));
17812
- try {
17813
- j = await hoiChuDai(cm ? DE_CM : DE2, cm ? loi2 : loi2.slice(0, 2600), { thinkingLevel: cm ? "medium" : "low" });
17814
- } catch (e) {
17815
- globalThis.__kbLoi = String(e?.message || e).slice(0, 120);
17816
- }
17775
+ d?.transaction("kho", "readwrite").objectStore("kho").clear();
17776
+ } catch (e) {
17777
+ }
17778
+ hoiNgoai("luu", "khoVideo", []);
17779
+ }
17780
+ async function layKho() {
17781
+ const d = await db(), ds2 = [];
17782
+ if (d) await new Promise((ok) => {
17783
+ try {
17784
+ const r = d.transaction("kho").objectStore("kho").openCursor();
17785
+ r.onsuccess = () => {
17786
+ const c = r.result;
17787
+ if (!c) return ok();
17788
+ const b = c.value.blob;
17789
+ ds2.push({ id: String(c.key), ten: String(c.value.ten || ""), blob: b, loai: c.value.loai === "video" || b && laVideo(b, String(c.value.ten || "")) ? "video" : "anh", dai: +c.value.dai || 0 });
17790
+ c.continue();
17791
+ };
17792
+ r.onerror = () => ok();
17793
+ } catch (e) {
17794
+ ok();
17817
17795
  }
17818
- globalThis.__kbNguon = j && j.moc ? "ai" : "loi";
17819
- if (!(j && j.moc)) {
17820
- try {
17821
- globalThis.__canhBaoAI = "AI vi\u1EBFt k\u1ECBch b\u1EA3n \u0111ang l\u1ED7i (" + String(globalThis.__kbLoi || "") + ") \u2014 video d\u1EF1ng KH\xD4NG c\xF3 c\u1EA3nh AI, h\xE3y b\u1EA5m l\xE0m l\u1EA1i sau \xEDt ph\xFAt";
17822
- console.warn(globalThis.__canhBaoAI);
17823
- } catch (e) {
17824
- }
17796
+ });
17797
+ {
17798
+ const G3 = globalThis, rong = !ds2.length;
17799
+ if (!Array.isArray(G3.__khoNgoaiDs) || !G3.__khoNgoaiDs.length) {
17800
+ const ng0 = await hoiNgoai("lay", "khoVideo");
17801
+ G3.__khoNgoaiDs = Array.isArray(ng0) ? ng0 : [];
17825
17802
  }
17826
- if (j && j.moc && cm) {
17827
- try {
17828
- const j2 = await hoiAI(DE_SUA, loi2.slice(0, 3400));
17829
- if (Array.isArray(j2.sua)) j.sua = j2.sua.concat(j.sua || []);
17830
- } catch (e) {
17831
- }
17832
- const nCanh = (ws[ws.length - 1].t1 - ws[0].t0) / 3.6;
17833
- if (!Array.isArray(j.canh) || j.canh.length < nCanh) {
17803
+ const ng = G3.__khoNgoaiDs, coS = new Set(ds2.map((x) => x.id));
17804
+ if (Array.isArray(ng)) for (const m of ng) {
17805
+ if (!m || !m.blob || coS.has(String(m.id))) continue;
17806
+ if (d && rong) {
17834
17807
  try {
17835
- let cau = "", t0 = -9;
17836
- ws.forEach((w) => {
17837
- if (w.t0 - t0 >= 5) {
17838
- cau += " [" + Math.round(w.t0 - ws[0].t0) + "s]";
17839
- t0 = w.t0;
17840
- }
17841
- cau += " " + w.text;
17842
- });
17843
- const j3 = await hoiAI(DE_CANH, cau.slice(0, 5200));
17844
- if (Array.isArray(j3.canh) && j3.canh.length > (j.canh || []).length) j.canh = j3.canh;
17808
+ d.transaction("kho", "readwrite").objectStore("kho").put({ ten: m.ten, blob: m.blob, loai: m.loai, dai: m.dai }, m.id);
17845
17809
  } catch (e) {
17846
17810
  }
17847
17811
  }
17812
+ ds2.push({ id: String(m.id), ten: String(m.ten || ""), blob: m.blob, loai: m.loai === "video" ? "video" : "anh", dai: +m.dai || 0 });
17848
17813
  }
17849
- if (j && j.moc) {
17850
- try {
17851
- localStorage.setItem(khoa3, JSON.stringify({ ...j, van }));
17852
- } catch (e) {
17853
- }
17854
- try {
17855
- ghiDem("kb:" + khoa3, JSON.parse(JSON.stringify({ ...j, van })));
17856
- } catch (e) {
17857
- }
17858
- return j;
17814
+ }
17815
+ const thu2 = globalThis.__khoThu;
17816
+ if (Array.isArray(thu2)) for (const u of thu2) {
17817
+ try {
17818
+ const b = await (await fetch(u)).blob();
17819
+ if (b.size) ds2.push({ id: String(u), ten: String(u).split("/").pop() || "", blob: b, loai: laVideo(b, String(u)) ? "video" : "anh" });
17820
+ } catch (e) {
17859
17821
  }
17860
- } catch (e) {
17861
17822
  }
17862
- return null;
17823
+ return ds2;
17863
17824
  }
17864
- function apDungDoan(p, mau7, kb) {
17865
- const sc = p?.scenes?.[0], tl = [...p?.timeline || []].sort((a, b) => a.order - b.order);
17866
- const ws = (p?.speechDraft?.analysis?.words || []).filter((w) => w && w.t1 > w.t0 && sach(w.text));
17867
- if (!sc || !tl.length || !ws.length || !mau7?.doan) return p;
17868
- const kieu = mau7.doan, fm = p.speechDraft.analysis.faceMap?.samples || [], ar = p.aspectRatio === "16:9" ? 16 / 9 : 9 / 16, capY = mau7.viTri?.y ?? 0.75;
17869
- const ms = sc.text_moments || [], doan2 = [], am = [], moi = /* @__PURE__ */ new Map(), tong = tl.reduce((s, c) => s + c.trimEnd - c.trimStart, 0);
17870
- const anh2 = ms.filter((m) => m.kind === "illustration" && (m.videoBase64 || m.imageBase64) && (m.layout === "full" || m.insertMode === "full"));
17871
- const fTu = (t) => {
17872
- let s = 0;
17873
- for (const c of tl) {
17874
- if (t >= c.trimStart - 0.01 && t < c.trimEnd + 0.01) return s + Math.max(0, t - c.trimStart);
17875
- s += c.trimEnd - c.trimStart;
17876
- }
17877
- return -1;
17878
- };
17879
- const nTu = (f2) => {
17880
- let s = 0;
17881
- for (const c of tl) {
17882
- const L = c.trimEnd - c.trimStart;
17883
- if (f2 <= s + L) return c.trimStart + Math.max(0, f2 - s);
17884
- s += L;
17885
- }
17886
- return tl[tl.length - 1].trimEnd;
17887
- };
17888
- const kw = ms.filter((m) => m.kind === "keyword" && sach(m.text)), the = (t0, t1, d) => {
17889
- const f0 = fTu(t0);
17890
- doan2.push({ kind: "doan", t0, t1: f0 >= 0 ? Math.max(t1, nTu(f0 + t1 - t0)) : t1, doan: { dai: t1 - t0, kieu, ...d } });
17891
- };
17892
- const phim2 = (t, tu = -1) => {
17893
- let s = 0;
17894
- for (const c of tl) {
17895
- if (t >= c.trimStart - 0.01 && t < c.trimEnd && s + t - c.trimStart >= tu) return s + t - c.trimStart;
17896
- s += c.trimEnd - c.trimStart;
17897
- }
17898
- return -1;
17899
- };
17900
- const keu = (t, loai) => {
17901
- am.push({ kind: "am", t0: t, t1: t + 0.1, am: loai });
17902
- };
17903
- const vAI = (kb?.vat || []).map((v) => String(v && v.tu || "").toLocaleLowerCase("vi")).filter(Boolean);
17904
- const dau = (c) => {
17905
- if (phim2(c.t0) >= 0) return c;
17906
- const k2 = tl.find((x) => x.trimStart > c.t0 && x.trimStart - c.t0 <= 1.5 && x.trimStart < c.t1);
17907
- return k2 ? { ...c, t0: k2.trimStart } : c;
17908
- };
17909
- const cs = chiaCau(ws, tong < 15).map(dau).map((c) => ({ ...c, f: phim2(c.t0), d: c.t1 - c.t0, vat: vatTrong(c.chu, vAI) })).filter((c) => {
17910
- const p0 = phim2(c.t0);
17911
- return p0 >= 0 && p0 < tong - 0.2;
17912
- }).sort((a, b) => a.f - b.f);
17913
- cs.forEach((c) => {
17914
- const s = " " + c.chu.join(" ").toLocaleLowerCase("vi") + " ";
17915
- c.vat = [...new Set(vAI.filter((x) => s.indexOf(" " + x + " ") >= 0).map((x) => "vat:" + x).concat(c.vat))].slice(0, 4);
17916
- });
17917
- if (tong < 15) cs.forEach((c, i) => {
17918
- c.vat = [...new Set(c.vat.concat((cs[i - 1] || c).vat, (cs[i + 1] || c).vat))].slice(0, 4);
17919
- });
17920
- if (kieu.khoi) cs.forEach((c) => {
17921
- c.vatThat = vatKhoi(c.chu, kieu, vAI);
17922
- c.vat = c.vatThat.concat(["", ""]).slice(0, Math.max(2, c.vatThat.length));
17923
- });
17924
- anh2.forEach((m) => {
17925
- const c = cs.find((x) => !x.anh && m.t0 >= x.t0 - 0.05 && m.t0 < x.t1 + 0.3);
17926
- if (c) c.anh = m;
17927
- });
17928
- kw.forEach((m) => {
17929
- const c = cs.find((x) => !x.kw && m.t0 >= x.t0 - 0.3 && m.t0 < x.t1);
17930
- if (c) c.kw = m;
17931
- });
17932
- const tam2 = (i) => {
17933
- const v = fm.filter((x) => x && x.face).map((x) => x.face[i ? "y" : "x"] + x.face[i ? "h" : "w"] / 2).sort((p2, q) => p2 - q);
17934
- return v.length < 2 ? [0.5, 0.38][i] : Math.max(i ? 0.2 : 0.3, Math.min(i ? 0.6 : 0.7, v[Math.floor(v.length / 2)]));
17935
- }, zc = [tam2(0), tam2(1)];
17936
- const o = { tl, cs, ws, kw, kb, kieu, fm, ar, capY, zc, tong, the, keu, fTu, nTu, chot: "", anh: anh2, moi, ms, vatNoi: [...new Set(cs.flatMap((c) => c.vat))] };
17937
- const sy = !!kieu.saoY && tong <= 10.5 && new Set(tl.map((c) => c.sceneId)).size === 1, mo4 = sy ? [0, 0] : kieu.khoi ? moKhoi(o) : moKet(o), k = Math.max(0.27, Math.min(1, tong / 30));
17938
- const nguon3 = (f2) => {
17939
- let s = 0;
17940
- for (const c of tl) {
17941
- const L = c.trimEnd - c.trimStart;
17942
- if (f2 < s + L) return c.trimStart + f2 - s;
17943
- s += L;
17944
- }
17945
- return tl[tl.length - 1].trimEnd;
17946
- };
17947
- const N = (x) => Array.isArray(x) ? x.map(nguon3) : typeof x === "number" ? nguon3(x) : x, S0 = kieu.saoY || {};
17948
- const SY = sy ? { ...S0, giay: N(S0.giay), vun: N(S0.vun), vat: N(S0.vat), bao: N(S0.bao), anh: N(S0.anh), tieu: N(S0.tieu) } : S0;
17949
- if (!sy) chonDoan(cs, [phim2(mo4[0])], anh2.length > 0, kieu, k);
17950
- else cs.forEach((c) => {
17951
- c.loai = "th";
17952
- });
17953
- const dz = sy ? saoY({ ...o, kieu: { ...kieu, saoY: SY }, tong: nguon3(tong) }, layMoc(ws, kb, true)) : o.zoom || diemZoom(cs, phim2);
17954
- if (o.zoomMo && !sy) {
17955
- const [f0, z, f1] = o.zoomMo, lv = (dz.filter((x) => x[0] <= f0).pop() || [0, 1])[1];
17956
- dz.splice(0, dz.length, ...dz.filter((x) => x[0] < f0 || x[0] > f1), [f0, z], [f1, lv]);
17957
- }
17958
- const oNguoi2 = (a, b, z) => {
17959
- const F = matRa(fm, a, b, [0, 0, 0, 0], z, zc) || [0.3, 0.3, 0.7, 0.6], s = Math.min(0.95, 1.9 * (F[2] - F[0]));
17960
- return [Math.max(0, Math.min(1 - s, (F[0] + F[2] - s) / 2)), Math.max(0, Math.min(1 - s * ar, (F[1] + F[3] - s * ar) / 2)), s];
17961
- };
17962
- o.oNguoi = oNguoi2;
17963
- let soPol = 0, phu = -1;
17964
- cs.forEach((c, i) => {
17965
- if (kieu.khoi && datKhoi(o, c, i)) return;
17966
- const t0 = c.t0;
17967
- if (c.loai === "tron") {
17968
- const m = c.anh, t1 = t0 + (m.t1 - m.t0), vf = m.videoFace, ct = tl.find((x) => t0 >= x.trimStart - 0.01 && t0 < x.trimEnd);
17969
- moi.set(m, { ...m, t0, t1 });
17970
- if (kieu.am) the(t0, t1, { loai: "am" });
17971
- if (kieu.xeBao) {
17972
- the(Math.max(t0 - 0.3, ct ? ct.trimStart : t0), t0 + 0.12, { loai: "xeBao", hat: 20 + i, lop: 3 });
17973
- keu(t0 - 0.02, "whoosh");
17974
- } else {
17975
- keu(t0, "whoosh-nhanh");
17976
- keu(t1, "whoosh-nhanh");
17977
- }
17978
- phu = t1;
17979
- the(t0, t1, { loai: "tron", o: { x: vf && vf.x + vf.w > 0.58 ? 0.22 : 0.78, y: 0.17, s: 0.36, tron: 1, t: 0.9 }, cat: oNguoi2(t0, t1, c.z) });
17980
- keu(t0 + 0.9, kieu.xeBao ? "whoosh-nhanh" : "pop-cao");
17981
- } else if (c.loai === "polaroid") {
17982
- const t1 = Math.min(c.t1 + 0.15, t0 + 4.2), A2 = anh2[0], B = anh2[1] || anh2[0], tA = (A2.videoTrimStart || 0) + 1 + 1.2 * soPol, tB = (B.videoTrimStart || 0) + (anh2[1] ? 1.6 : 3.2);
17983
- const sw = soPol++ % 2 ? [B, tB, A2, tA] : [A2, tA, B, tB];
17984
- the(t0, t1, {
17985
- loai: "polaroid",
17986
- anh: [{ m: sw[0], t: sw[1], x: 0.36, y: 0.25, s: 0.56, goc: -6, tre: 0.1 }, { m: sw[2], t: sw[3], x: 0.64, y: 0.47, s: 0.54, goc: 5, tre: 0.45 }],
17987
- o: { x: 0.3, y: 0.58, s: 0.4, tron: 0, t: 0.85 },
17988
- cat: oNguoi2(t0, t1, c.z)
17989
- });
17990
- keu(t0 - 0.02, "whoosh");
17991
- keu(t0 + 0.12, "giay");
17992
- keu(t0 + 0.47, "giay");
17993
- keu(t0 + 0.87, "pop-cao");
17994
- } else if (c.loai === "sticker") {
17995
- const t1 = Math.min(c.t1 + 0.1, t0 + 3.6), F = matRa(fm, t0, t1, [0.06, 0.04, 0.06, 0.02], 1.09, zc), vat = F ? datVat(c.vat, F, ar, capY) : [];
17996
- const F0 = matRa(fm, t0, t1, [0, 0, 0, 0], 1.09, zc), vt = vat.map((v, j) => ({ ...v, t: 0.2 + 0.1 * j }));
17997
- if (vt.length) {
17998
- the(t0, t1, { loai: "sticker", vat: vt, vot: 1.15, ra: 0.25, ...vongVun(F0, 0.12) });
17999
- keu(t0, "giay");
18000
- vt.forEach((v) => keu(t0 + v.t, "pop"));
18001
- }
18002
- } else if (c.loai === "nhan") {
18003
- const ns = dongNhan(ngan(c.kw.text), 0.1, 0.1), t1 = t0 + Math.min(c.d + 0.3, Math.max(2.2, go(ns) + 1.3)), q = neNhan(ns, o, t0, t1, [0.12, 0.1, 0.08, 0.06, 0.16]);
18004
- if (q) {
18005
- the(t0, t1, { loai: "nhan", hat: 9, nhan: q, go: 0.03 });
18006
- keu(t0, "pop-nhe");
18007
- }
18008
- } else if (kieu.mo === "tieuDe" && i > 0 && t0 > phu) keu(t0 - 0.02, "whoosh-nhanh");
18009
- });
18010
- const pd = kieu.phuDe || {}, duoi = String(mau7.id).slice(-4) === "-sua" ? "-sua" : "", lay = (id) => id ? layMau(id + duoi) : null;
18011
- const cauCua = (t) => cs.find((c) => t >= c.t0 - 0.05 && t < c.t1 + 0.05), mpd = [lay(pd.mo), lay(pd.dac), lay(pd.ket)];
18012
- const trenDau = (a, b, d) => {
18013
- const F = matRa(fm, a, b, [0, 0.03, 0, 0], 1.12, zc);
18014
- return F ? Math.max(0.09, Math.min(d, F[1] - 0.06)) : d;
18015
- };
18016
- const doiPd = (m) => {
18017
- if (m.kind !== "sub" || !m.tu) return m;
18018
- const c = cauCua(m.t0), x = sy && SY.anh && m.t1 - SY.anh > SY.anh - m.t0 ? mpd[1] : (
18019
- // trang phần lớn sau chỗ cắt sang ảnh
18020
- !c ? null : c === cs[0] && m.t0 < mo4[1] ? mpd[0] : c.loai === "tron" ? mpd[1] : c === cs[cs.length - 1] ? mpd[2] : null
18021
- );
18022
- const Y = !sy && tong >= 15 && kieu.phuDeY, y = Y && c ? c === cs[0] && m.t0 < mo4[1] ? trenDau(m.t0, m.t1, Y.mo) : c.loai === "tron" ? Y.anh : Y.noi : void 0;
18023
- return x ? { ...m, mpd: x, safeY: y } : y ? { ...m, safeY: y } : m;
18024
- };
18025
- const nhip = { cau: cs.map((c) => ({ f: +c.f.toFixed(2), d: +c.d.toFixed(2), loai: c.loai, z: c.z, chu: c.chu.slice(0, 5).join(" ") })) };
18026
- const tm = doan2.concat(am, ms.filter((m) => m.kind !== "keyword").map((m) => doiPd(moi.get(m) || m)));
18027
- return { ...p, timeline: catZoom(tl, dz), nhipDoan: nhip, scenes: p.scenes.map((s, k2) => k2 ? s : { ...s, text_moments: tm }) };
18028
- }
18029
- function lichAm(clips) {
18030
- const ra = [], da = /* @__PURE__ */ new Set();
18031
- let t = 0;
18032
- clips.forEach((c) => {
18033
- (c.textMoments || []).forEach((m) => {
18034
- if (m.kind !== "am" || da.has(m) || m.t0 < c.trimStart - 0.01 || m.t0 >= c.trimEnd) return;
18035
- da.add(m);
18036
- ra.push({ t: t + Math.max(0, m.t0 - c.trimStart), loai: m.am });
18037
- });
18038
- t += Math.max(0, c.trimEnd - c.trimStart);
18039
- });
18040
- globalThis.__amCm = ra.map((x) => [+(+x.t).toFixed(2), x.loai]);
18041
- return ra;
18042
- }
18043
- function lichDoan(clips) {
18044
- const ra = [], da = /* @__PURE__ */ new Map();
18045
- let t = 0;
18046
- clips.forEach((c, i) => {
18047
- const s = c.trimStart, e = c.trimEnd;
18048
- (c.textMoments || []).forEach((m) => {
18049
- if (m.kind !== "doan") return;
18050
- const a = Math.max(s, m.t0), b = Math.min(e, m.t1), L = da.get(m);
18051
- if (b - a < 0.02 || (L ? L.i !== i - 1 || s < L.e - 0.05 : m.t0 < s - 0.05 || m.t0 >= e)) return;
18052
- if (L && Math.abs(s - L.e) < 0.02) {
18053
- ra[L.k].T1 = t + b - s;
18054
- L.i = i;
18055
- L.e = b;
18056
- return;
18057
- }
18058
- const tuL = L ? ra[L.k].tuLech + ra[L.k].T1 - ra[L.k].T0 : a - m.t0;
18059
- da.set(m, { i, e: b, k: ra.length });
18060
- ra.push({ T0: t + a - s, T1: t + b - s, kind: "doan", text: "", doan: m.doan, tuLech: tuL, dayXuong: m.doan.day });
18061
- });
18062
- t += Math.max(0, e - s);
18063
- });
18064
- globalThis.__doanRoi = [...new Set(clips.flatMap((c) => (c.textMoments || []).filter((m) => m.kind === "doan" && !da.has(m))))].map((m) => [+(+m.t0).toFixed(2), +(+m.t1).toFixed(2), m.doan?.loai, m.doan?.bo, m.doan?.giant, clips.filter((c) => c.trimEnd > m.t0 - 1 && c.trimStart < m.t0 + 1).map((c) => [+c.trimStart.toFixed(3), +c.trimEnd.toFixed(3)])]);
18065
- return ra;
18066
- }
18067
-
18068
- // flow-src/engine/omniTram.ts
18069
- var DEM = "xvaiOmniDem";
18070
- var maDuAn = () => {
18071
- try {
18072
- return String(globalThis.__loiApp?.p?.idGoc || globalThis.__loiApp?.p?.id || "x").replace(/[^a-zA-Z0-9]/g, "").slice(0, 8) || "x";
18073
- } catch (e) {
18074
- return "x";
18075
- }
18076
- };
18077
- var cuaDuAn = (ten) => !/^omni-/.test(String(ten || "")) || String(ten).indexOf("omni-" + maDuAn() + "-") === 0;
18078
- var demOmni = () => {
18079
- try {
18080
- return +(localStorage.getItem(DEM) || 0);
18081
- } catch (e) {
18082
- return 0;
18083
- }
18084
- };
18085
- var tangDem = () => {
18086
- try {
18087
- localStorage.setItem(DEM, String(demOmni() + 1));
18088
- } catch (e) {
18089
- }
18090
- };
18091
- var cho = (ms) => new Promise((r) => setTimeout(r, ms));
18092
- var b64Blob = (b64, mime) => {
18093
- const bin = atob(b64), u = new Uint8Array(bin.length);
18094
- for (let i = 0; i < bin.length; i++) u[i] = bin.charCodeAt(i);
18095
- return new Blob([u], { type: mime });
18096
- };
18097
- function chonCanhTram(canh, toiDa) {
18098
- const ds2 = (canh || []).filter((c) => c && (c.kieu === "anh" || c.kieu === "video") && (c.en || c.de)).slice(1);
18099
- if (!ds2.length || toiDa <= 0) return [];
18100
- const buoc = Math.max(1, Math.floor(ds2.length / toiDa)), ra = [];
18101
- for (let i = 0; i < ds2.length && ra.length < toiDa; i += buoc) ra.push(ds2[i]);
18102
- return ra;
18103
- }
18104
- async function taoTramOmni(canh, o) {
18105
- const toiDa = Math.max(0, Math.min(8, Number(o.toiDa ?? 4))), giay2 = [4, 6, 8, 10].indexOf(Number(o.giay)) >= 0 ? Number(o.giay) : 4, tran = Number(o.tran ?? 20), model = o.model || "Omni 1.1 Flash";
18106
- const chon = chonCanhTram(canh, toiDa), ten = [], loi2 = [];
18107
- let tao = 0;
18108
- for (let i = 0; i < chon.length; i++) {
18109
- if (demOmni() >= tran) {
18110
- loi2.push("DA TOI TRAN " + tran + " clip (xvaiOmniDem)");
18111
- break;
18112
- }
18113
- const c = chon[i], de = String(c.en || c.de || ""), prompt = "Vertical 9:16 b-roll clip, " + giay2 + " seconds, realistic, cinematic, natural motion, no text, no captions, no logos: " + de;
18114
- o.bao?.("Omni " + (i + 1) + "/" + chon.length + " \xB7 " + de.slice(0, 60));
18115
- try {
18116
- const r = await Flow.generate.video({ prompt, aspectRatio: "9:16", durationSeconds: giay2, resolution: "720p", modelDisplayName: model });
18117
- if (!r || !r.base64) throw new Error("Flow ch\u01B0a tr\u1EA3 video");
18118
- tangDem();
18119
- const blob = b64Blob(r.base64, r.mimeType || "video/mp4"), f2 = new File([blob], "omni-" + maDuAn() + "-" + String(i + 1).padStart(2, "0") + "-" + String(c.tu || de).slice(0, 24).replace(/[^a-zA-Z0-9À-ỹ]+/g, "-") + ".mp4", { type: "video/mp4" });
18120
- const n = await themKho([f2]);
18121
- ten.push(f2.name + (n ? "" : " (kho khong nhan)"));
18122
- tao++;
18123
- const G3 = globalThis;
18124
- (G3.__omniClips = G3.__omniClips || []).push({ ten: f2.name, blob, de, tu: c.tu });
18125
- } catch (e) {
18126
- loi2.push(de.slice(0, 40) + ": " + String(e && e.message || e).slice(0, 120));
18127
- if (/unusual|bất thường|403/i.test(String(e && e.message || e))) break;
18128
- }
18129
- await cho(5e3);
18130
- }
18131
- return { tao, ten, loi: loi2, dem: demOmni(), chon: chon.length };
18132
- }
18133
-
18134
- // flow-src/engine/khoAnh.ts
18135
- var laVideo = (b, ten = "") => /^video\/(mp4|webm)/.test(b.type) || /\.(mp4|webm)$/i.test(ten);
18136
- var db = () => new Promise((ok) => {
18137
- try {
18138
- const r = indexedDB.open("xvaiKhoVideo", 1);
18139
- r.onupgradeneeded = () => r.result.createObjectStore("kho");
18140
- r.onsuccess = () => ok(r.result);
18141
- r.onerror = () => ok(null);
18142
- } catch (e) {
18143
- ok(null);
18144
- }
18145
- });
18146
- async function themKho(files) {
18147
- const d = await db();
18148
- if (!d) return 0;
18149
- let n = 0;
18150
- for (const f2 of files) {
18151
- const v = laVideo(f2, f2.name);
18152
- if (!v && !/^image\//.test(f2.type)) continue;
18153
- let dai2 = 0;
18154
- if (v) {
18155
- try {
18156
- dai2 = (await khungGiuaVideo(f2)).dai;
18157
- } catch (e) {
18158
- continue;
18159
- }
18160
- if (!(dai2 > 0.3) || dai2 > 15.5) continue;
18161
- }
18162
- try {
18163
- d.transaction("kho", "readwrite").objectStore("kho").put({ ten: f2.name, blob: f2, loai: v ? "video" : "anh", dai: dai2 }, f2.name + ":" + f2.size);
18164
- n++;
18165
- } catch (e) {
18166
- }
18167
- }
18168
- if (n) {
18169
- try {
18170
- const ds2 = await layKho();
18171
- const L = ds2.map((m) => ({ id: m.id, ten: m.ten, blob: m.blob, loai: m.loai, dai: m.dai || 0 }));
18172
- globalThis.__khoNgoaiDs = L;
18173
- hoiNgoai("luu", "khoVideo", L);
18174
- } catch (e) {
18175
- }
18176
- }
18177
- return n;
18178
- }
18179
- try {
18180
- globalThis.__themKho = (fs) => themKho(fs);
18181
- } catch (e) {
18182
- }
18183
- async function xoaKho() {
18184
- const d = await db();
18185
- try {
18186
- d?.transaction("kho", "readwrite").objectStore("kho").clear();
18187
- } catch (e) {
18188
- }
18189
- hoiNgoai("luu", "khoVideo", []);
18190
- }
18191
- async function layKho() {
18192
- const d = await db(), ds2 = [];
18193
- if (d) await new Promise((ok) => {
18194
- try {
18195
- const r = d.transaction("kho").objectStore("kho").openCursor();
18196
- r.onsuccess = () => {
18197
- const c = r.result;
18198
- if (!c) return ok();
18199
- const b = c.value.blob;
18200
- ds2.push({ id: String(c.key), ten: String(c.value.ten || ""), blob: b, loai: c.value.loai === "video" || b && laVideo(b, String(c.value.ten || "")) ? "video" : "anh", dai: +c.value.dai || 0 });
18201
- c.continue();
18202
- };
18203
- r.onerror = () => ok();
18204
- } catch (e) {
18205
- ok();
18206
- }
18207
- });
18208
- {
18209
- const G3 = globalThis, rong = !ds2.length;
18210
- if (!Array.isArray(G3.__khoNgoaiDs) || !G3.__khoNgoaiDs.length) {
18211
- const ng0 = await hoiNgoai("lay", "khoVideo");
18212
- G3.__khoNgoaiDs = Array.isArray(ng0) ? ng0 : [];
18213
- }
18214
- const ng = G3.__khoNgoaiDs, coS = new Set(ds2.map((x) => x.id));
18215
- if (Array.isArray(ng)) for (const m of ng) {
18216
- if (!m || !m.blob || coS.has(String(m.id))) continue;
18217
- if (d && rong) {
18218
- try {
18219
- d.transaction("kho", "readwrite").objectStore("kho").put({ ten: m.ten, blob: m.blob, loai: m.loai, dai: m.dai }, m.id);
18220
- } catch (e) {
18221
- }
18222
- }
18223
- ds2.push({ id: String(m.id), ten: String(m.ten || ""), blob: m.blob, loai: m.loai === "video" ? "video" : "anh", dai: +m.dai || 0 });
18224
- }
18225
- }
18226
- const thu2 = globalThis.__khoThu;
18227
- if (Array.isArray(thu2)) for (const u of thu2) {
18228
- try {
18229
- const b = await (await fetch(u)).blob();
18230
- if (b.size) ds2.push({ id: String(u), ten: String(u).split("/").pop() || "", blob: b, loai: laVideo(b, String(u)) ? "video" : "anh" });
18231
- } catch (e) {
18232
- }
18233
- }
18234
- return ds2;
18235
- }
18236
- var demHetGio = (ten, su, ms) => {
18237
- const g = globalThis;
18238
- g.__vd209c = (g.__vd209c || 0) + 1;
18239
- (g.__vd209cDs = g.__vd209cDs || []).push(ten + ":" + su);
18240
- console.warn("[VD-209c] " + ten + ": h\u1EBFt " + ms + " ms ch\u1EDD " + su + " (tab \u1EA9n?)");
18241
- };
18242
- var choVideo = (v, su, ms, ten) => new Promise((ok) => {
18243
- let t = 0;
18244
- const xong = (r) => {
18245
- clearTimeout(t);
18246
- v.onloadeddata = null;
18247
- v.onseeked = null;
18248
- v.onerror = null;
18249
- if (r === "het") demHetGio(ten, su, ms);
18250
- ok(r);
17825
+ var demHetGio = (ten, su, ms) => {
17826
+ const g = globalThis;
17827
+ g.__vd209c = (g.__vd209c || 0) + 1;
17828
+ (g.__vd209cDs = g.__vd209cDs || []).push(ten + ":" + su);
17829
+ console.warn("[VD-209c] " + ten + ": h\u1EBFt " + ms + " ms ch\u1EDD " + su + " (tab \u1EA9n?)");
17830
+ };
17831
+ var choVideo = (v, su, ms, ten) => new Promise((ok) => {
17832
+ let t = 0;
17833
+ const xong = (r) => {
17834
+ clearTimeout(t);
17835
+ v.onloadeddata = null;
17836
+ v.onseeked = null;
17837
+ v.onerror = null;
17838
+ if (r === "het") demHetGio(ten, su, ms);
17839
+ ok(r);
18251
17840
  };
18252
17841
  v["on" + su] = () => xong("ok");
18253
17842
  v.onerror = () => xong("loi");
@@ -18554,60 +18143,477 @@ async function kiemAnhTao(kb, words, bao) {
18554
18143
  bo4++;
18555
18144
  }
18556
18145
  }
18557
- globalThis.__kiemAnhTao = ghi4;
18558
- return bo4;
18146
+ globalThis.__kiemAnhTao = ghi4;
18147
+ return bo4;
18148
+ } catch (e) {
18149
+ return 0;
18150
+ }
18151
+ }
18152
+ async function chupTrangThieu(kb, bao) {
18153
+ const chup2 = globalThis.__chupTrang;
18154
+ if (typeof chup2 !== "function" || !kb) return 0;
18155
+ let n = 0;
18156
+ const ghi4 = [];
18157
+ for (const m of kb.muc || []) {
18158
+ const k = "trang:" + String(m && m.ten || "").trim().toLocaleLowerCase("vi").replace(/[^\p{L}\p{N}]+/gu, ""), u = String(m && m.url || "");
18159
+ if (!u || taiSan(k) || !/^https:/.test(u)) continue;
18160
+ bao?.("Ch\u1EE5p trang th\u1EADt " + u + "...");
18161
+ try {
18162
+ const b = await chup2(u);
18163
+ if (b) {
18164
+ datTaiSan(k, await createImageBitmap(b));
18165
+ n++;
18166
+ ghi4.push([k, u]);
18167
+ }
18168
+ } catch (e) {
18169
+ ghi4.push([k, u, "loi"]);
18170
+ }
18171
+ }
18172
+ globalThis.__chupDa = ghi4;
18173
+ return n;
18174
+ }
18175
+ async function napVideo(b, bao) {
18176
+ const u = URL.createObjectURL(b), v = document.createElement("video");
18177
+ v.muted = true;
18178
+ v.playsInline = true;
18179
+ v.preload = "auto";
18180
+ v.src = u;
18181
+ const nap = await choVideo(v, "loadeddata", 8e3, "napVideo");
18182
+ if (nap !== "ok") {
18183
+ URL.revokeObjectURL(u);
18184
+ throw new Error(nap === "het" ? "[VD-209c] clip kh\xF4ng n\u1EA1p (tab \u1EA9n?)" : "video h\u1ECFng");
18185
+ }
18186
+ const dai2 = Math.min(8, v.duration || 4), fps = 10, n = Math.max(1, Math.floor(dai2 * fps)), ds2 = [], han = Date.now() + 6e4;
18187
+ for (let i = 0; i < n; i++) {
18188
+ if (Date.now() > han) {
18189
+ demHetGio("napVideo", "v\xF2ng khung", 6e4);
18190
+ break;
18191
+ }
18192
+ v.currentTime = Math.min(dai2 - 0.05, i / fps);
18193
+ if (await choVideo(v, "seeked", 4e3, "napVideo") !== "ok") break;
18194
+ ds2.push(await createImageBitmap(v, { resizeWidth: 432, resizeHeight: 768, resizeQuality: "medium" }));
18195
+ }
18196
+ URL.revokeObjectURL(u);
18197
+ if (!ds2.length) throw new Error("[VD-209c] clip kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c khung n\xE0o");
18198
+ bao?.("N\u1EA1p video tr\xE1m " + (ds2.length < n ? ds2.length + "/" : "") + n + " khung");
18199
+ return { laVideo: true, width: 432, height: 768, dai: ds2.length < n ? ds2.length / fps : dai2, khung: (t) => ds2[Math.max(0, Math.min(ds2.length - 1, Math.floor(t * fps)))] };
18200
+ }
18201
+
18202
+ // flow-src/engine/omniTram.ts
18203
+ var DEM = "xvaiOmniDem";
18204
+ var maDuAn = () => {
18205
+ try {
18206
+ return String(globalThis.__loiApp?.p?.idGoc || globalThis.__loiApp?.p?.id || "x").replace(/[^a-zA-Z0-9]/g, "").slice(0, 8) || "x";
18207
+ } catch (e) {
18208
+ return "x";
18209
+ }
18210
+ };
18211
+ var cuaDuAn = (ten) => !/^omni-/.test(String(ten || "")) || String(ten).indexOf("omni-" + maDuAn() + "-") === 0;
18212
+ var demOmni = () => {
18213
+ try {
18214
+ return +(localStorage.getItem(DEM) || 0);
18215
+ } catch (e) {
18216
+ return 0;
18217
+ }
18218
+ };
18219
+ var tangDem = () => {
18220
+ try {
18221
+ localStorage.setItem(DEM, String(demOmni() + 1));
18222
+ } catch (e) {
18223
+ }
18224
+ };
18225
+ var cho = (ms) => new Promise((r) => setTimeout(r, ms));
18226
+ var b64Blob = (b64, mime) => {
18227
+ const bin = atob(b64), u = new Uint8Array(bin.length);
18228
+ for (let i = 0; i < bin.length; i++) u[i] = bin.charCodeAt(i);
18229
+ return new Blob([u], { type: mime });
18230
+ };
18231
+ function chonCanhTram(canh, toiDa) {
18232
+ const ds2 = (canh || []).filter((c) => c && (c.kieu === "anh" || c.kieu === "video") && (c.en || c.de)).slice(1);
18233
+ if (!ds2.length || toiDa <= 0) return [];
18234
+ const buoc = Math.max(1, Math.floor(ds2.length / toiDa)), ra = [];
18235
+ for (let i = 0; i < ds2.length && ra.length < toiDa; i += buoc) ra.push(ds2[i]);
18236
+ return ra;
18237
+ }
18238
+ async function taoTramOmni(canh, o) {
18239
+ const toiDa = Math.max(0, Math.min(8, Number(o.toiDa ?? 4))), giay2 = [4, 6, 8, 10].indexOf(Number(o.giay)) >= 0 ? Number(o.giay) : 4, tran = Number(o.tran ?? 20), model = o.model || "Omni 1.1 Flash";
18240
+ const chon = chonCanhTram(canh, toiDa), ten = [], loi2 = [];
18241
+ let tao = 0;
18242
+ for (let i = 0; i < chon.length; i++) {
18243
+ if (demOmni() >= tran) {
18244
+ loi2.push("DA TOI TRAN " + tran + " clip (xvaiOmniDem)");
18245
+ break;
18246
+ }
18247
+ const c = chon[i], de = String(c.en || c.de || ""), prompt = "Vertical 9:16 b-roll clip, " + giay2 + " seconds, realistic, cinematic, natural motion, no text, no captions, no logos: " + de;
18248
+ o.bao?.("Omni " + (i + 1) + "/" + chon.length + " \xB7 " + de.slice(0, 60));
18249
+ try {
18250
+ const r = await Flow.generate.video({ prompt, aspectRatio: "9:16", durationSeconds: giay2, resolution: "720p", modelDisplayName: model });
18251
+ if (!r || !r.base64) throw new Error("Flow ch\u01B0a tr\u1EA3 video");
18252
+ tangDem();
18253
+ const blob = b64Blob(r.base64, r.mimeType || "video/mp4"), f2 = new File([blob], "omni-" + maDuAn() + "-" + String(i + 1).padStart(2, "0") + "-" + String(c.tu || de).slice(0, 24).replace(/[^a-zA-Z0-9À-ỹ]+/g, "-") + ".mp4", { type: "video/mp4" });
18254
+ const n = await themKho([f2]);
18255
+ ten.push(f2.name + (n ? "" : " (kho khong nhan)"));
18256
+ tao++;
18257
+ const G3 = globalThis;
18258
+ (G3.__omniClips = G3.__omniClips || []).push({ ten: f2.name, blob, de, tu: c.tu });
18259
+ } catch (e) {
18260
+ loi2.push(de.slice(0, 40) + ": " + String(e && e.message || e).slice(0, 120));
18261
+ if (/unusual|bất thường|403/i.test(String(e && e.message || e))) break;
18262
+ }
18263
+ await cho(5e3);
18264
+ }
18265
+ return { tao, ten, loi: loi2, dem: demOmni(), chon: chon.length };
18266
+ }
18267
+
18268
+ // flow-src/engine/doanMau.ts
18269
+ var DE2 = 'B\u1EA1n l\xE0 bi\xEAn t\u1EADp vi\xEAn k\u1ECBch b\u1EA3n video ng\u1EAFn ti\u1EBFng Vi\u1EC7t. \u0110\u1ECDc l\u1EDDi n\xF3i b\xEAn d\u01B0\u1EDBi r\u1ED3i tr\u1EA3 v\u1EC1 \u0111\xFAng m\u1ED9t d\xF2ng JSON d\u1EA1ng {"moc":"...","chot":"..."}. moc = 2 \u0111\u1EBFn 6 t\u1EEB l\u1EA5y NGUY\xCAN V\u0102N trong c\xE2u \u0111\u1EA7u ti\xEAn, n\xEAu ch\u1EE7 \u0111\u1EC1 video; chot = l\u1EDDi ch\u1ED1t 3 \u0111\u1EBFn 6 t\u1EEB; vat = t\u1ED1i \u0111a 4 \u0111\u1ED3 v\u1EADt c\u1EE5 th\u1EC3 nh\u1EAFc trong l\u1EDDi, d\u1EA1ng {"tu":"t\u1EEB \u0111\xFAng nh\u01B0 trong l\u1EDDi","en":"t\xEAn \u0111\u1ED3 v\u1EADt ti\u1EBFng Anh, c\xF3 ch\u1EA5t li\u1EC7u / m\xE0u"}; tieu = \u0111\xFAng 2 t\u1EEB NGUY\xCAN V\u0102N li\u1EC1n nhau trong c\xE2u \u0111\u1EA7u, l\xE0 danh t\u1EEB ch\u1EE7 \u0111\u1EC1 (vd "l\xF2ng ng\u01B0\u1EDDi"); nhan = 1 t\u1EEB \u0111\u1EAFt nh\u1EA5t g\xE2y ch\xFA \xFD (t\xEDnh t\u1EEB ho\u1EB7c t\u1EEB l\xF3ng, vd "b\u1EA3nh") NGUY\xCAN V\u0102N trong l\u1EDDi. D\xF9ng t\u1EEB c\xF3 trong l\u1EDDi, kh\xF4ng gi\u1EA3i th\xEDch. L\u1EDDi n\xF3i: ';
18270
+ var NGUONG_CHU = 3950;
18271
+ var chiaKhuc = (x, n) => {
18272
+ const ra = [];
18273
+ let s = x;
18274
+ while (s.length > n) {
18275
+ let c = s.lastIndexOf(". ", n);
18276
+ if (c < n * 0.5) c = s.lastIndexOf(" ", n);
18277
+ if (c < n * 0.5) c = n;
18278
+ ra.push(s.slice(0, c + 1).trim());
18279
+ s = s.slice(c + 1);
18280
+ }
18281
+ if (s.trim()) ra.push(s.trim());
18282
+ return ra;
18283
+ };
18284
+ var gopJson = (a, b) => {
18285
+ if (!a) return b;
18286
+ if (!b) return a;
18287
+ const r = { ...a };
18288
+ for (const k of Object.keys(b)) {
18289
+ if (Array.isArray(b[k])) r[k] = (Array.isArray(a[k]) ? a[k] : []).concat(b[k]);
18290
+ else if (!r[k]) r[k] = b[k];
18291
+ }
18292
+ return r;
18293
+ };
18294
+ async function hoiChuDai(de, x, opt) {
18295
+ const k = "ai:" + bamDem(de + "" + x + "" + JSON.stringify(opt || {})), dem = await docDem(k);
18296
+ if (dem && dem.j) {
18297
+ globalThis.__kbDem = (globalThis.__kbDem || 0) + 1;
18298
+ return JSON.parse(JSON.stringify(dem.j));
18299
+ }
18300
+ const n = Math.max(600, NGUONG_CHU - de.length - 30), ks = de.length + x.length <= NGUONG_CHU ? [x] : chiaKhuc(x, n);
18301
+ let j = null;
18302
+ for (let i = 0; i < ks.length; i++) {
18303
+ const dau = ks.length > 1 ? "[\u0110o\u1EA1n " + (i + 1) + "/" + ks.length + " c\u1EE7a l\u1EDDi] " : "";
18304
+ const r = await Flow.generate.text(de + dau + ks[i], opt), t = String(r && r.text || "");
18305
+ j = gopJson(j, JSON.parse(t.slice(t.indexOf("{"), t.lastIndexOf("}") + 1)));
18306
+ }
18307
+ globalThis.__kbKhuc = ks.length;
18308
+ if (j && typeof j === "object") ghiDem(k, { j });
18309
+ return j;
18310
+ }
18311
+ var hoiAI = async (de, x) => hoiChuDai(de, x, { thinkingLevel: "medium" });
18312
+ async function kichBanDoan(ws) {
18313
+ const loi2 = ws.map((w) => w.text).join(" ");
18314
+ let h = 5381;
18315
+ for (let i = 0; i < loi2.length; i++) h = (h * 33 ^ loi2.charCodeAt(i)) >>> 0;
18316
+ const van = { n: ws.length, dau: loi2.slice(0, 160).toLocaleLowerCase("vi"), cuoi: loi2.slice(-160).toLocaleLowerCase("vi") };
18317
+ const cm = String(globalThis.__mauPhuDe || "").indexOf("giong-cuongme") === 0, hp = (() => {
18318
+ const t = cm ? DE_CM : DE2;
18319
+ let x = 5381;
18320
+ for (let i = 0; i < t.length; i++) x = (x * 33 ^ t.charCodeAt(i)) >>> 0;
18321
+ return x.toString(36).slice(0, 5);
18322
+ })(), khoa3 = (cm ? "xvaiKbCm9" + hp + ":" : "xvaiKb3:") + h.toString(36);
18323
+ try {
18324
+ const c = JSON.parse(localStorage.getItem(khoa3) || "null");
18325
+ if (c && c.moc) {
18326
+ globalThis.__kbNguon = "dem";
18327
+ return c;
18328
+ }
18329
+ } catch (e) {
18330
+ }
18331
+ try {
18332
+ const kDa = "kb:" + khoa3.split(":")[0] + ":da:" + maDuAn(), sg = (x) => String(x || "").replace(/[^\p{L}]/gu, "").slice(0, 40);
18333
+ const b = await docDem("kb:" + khoa3) || await (async () => {
18334
+ const c = await docDem(kDa);
18335
+ return c && c.van && sg(c.van.dau) === sg(van.dau) ? c : null;
18336
+ })();
18337
+ if (b && b.moc) {
18338
+ globalThis.__kbNguon = "ben";
18339
+ return JSON.parse(JSON.stringify(b));
18340
+ }
18341
+ } catch (e) {
18342
+ }
18343
+ if (cm) {
18344
+ const dau = van.dau;
18345
+ for (const k of Object.keys(localStorage)) {
18346
+ if (k.indexOf(khoa3.split(":")[0] + ":") !== 0) continue;
18347
+ try {
18348
+ const c = JSON.parse(localStorage.getItem(k) || "null"), v = c && c.van;
18349
+ if (c && c.moc && Array.isArray(c.canh) && c.canh.length > 10 && dau.indexOf(String(c.moc).toLocaleLowerCase("vi").slice(0, 18)) >= 0 && v && v.dau === van.dau && v.cuoi === van.cuoi && Math.abs((v.n || 0) - van.n) <= van.n * 0.1) {
18350
+ globalThis.__kbNguon = "gan:" + k;
18351
+ return c;
18352
+ }
18353
+ } catch (e) {
18354
+ }
18355
+ }
18356
+ }
18357
+ try {
18358
+ let j = null;
18359
+ for (let lan2 = 0; lan2 < 5 && !(j && j.moc); lan2++) {
18360
+ if (lan2) await new Promise((r) => setTimeout(r, [0, 5e3, 15e3, 3e4, 6e4][lan2]));
18361
+ try {
18362
+ j = await hoiChuDai(cm ? DE_CM : DE2, cm ? loi2 : loi2.slice(0, 2600), { thinkingLevel: cm ? "medium" : "low" });
18363
+ } catch (e) {
18364
+ globalThis.__kbLoi = String(e?.message || e).slice(0, 120);
18365
+ }
18366
+ }
18367
+ globalThis.__kbNguon = j && j.moc ? "ai" : "loi";
18368
+ if (!(j && j.moc)) {
18369
+ try {
18370
+ globalThis.__canhBaoAI = "AI vi\u1EBFt k\u1ECBch b\u1EA3n \u0111ang l\u1ED7i (" + String(globalThis.__kbLoi || "") + ") \u2014 video d\u1EF1ng KH\xD4NG c\xF3 c\u1EA3nh AI, h\xE3y b\u1EA5m l\xE0m l\u1EA1i sau \xEDt ph\xFAt";
18371
+ console.warn(globalThis.__canhBaoAI);
18372
+ } catch (e) {
18373
+ }
18374
+ }
18375
+ if (j && j.moc && cm) {
18376
+ try {
18377
+ const j2 = await hoiAI(DE_SUA, loi2.slice(0, 3400));
18378
+ if (Array.isArray(j2.sua)) j.sua = j2.sua.concat(j.sua || []);
18379
+ } catch (e) {
18380
+ }
18381
+ const nCanh = (ws[ws.length - 1].t1 - ws[0].t0) / 3.6;
18382
+ if (!Array.isArray(j.canh) || j.canh.length < nCanh) {
18383
+ try {
18384
+ let cau = "", t0 = -9;
18385
+ ws.forEach((w) => {
18386
+ if (w.t0 - t0 >= 5) {
18387
+ cau += " [" + Math.round(w.t0 - ws[0].t0) + "s]";
18388
+ t0 = w.t0;
18389
+ }
18390
+ cau += " " + w.text;
18391
+ });
18392
+ const j3 = await hoiAI(DE_CANH, cau.slice(0, 5200));
18393
+ if (Array.isArray(j3.canh) && j3.canh.length > (j.canh || []).length) j.canh = j3.canh;
18394
+ } catch (e) {
18395
+ }
18396
+ }
18397
+ }
18398
+ if (j && j.moc) {
18399
+ try {
18400
+ localStorage.setItem(khoa3, JSON.stringify({ ...j, van }));
18401
+ } catch (e) {
18402
+ }
18403
+ try {
18404
+ const v2 = JSON.parse(JSON.stringify({ ...j, van }));
18405
+ ghiDem("kb:" + khoa3, v2);
18406
+ ghiDem("kb:" + khoa3.split(":")[0] + ":da:" + maDuAn(), v2);
18407
+ } catch (e) {
18408
+ }
18409
+ return j;
18410
+ }
18559
18411
  } catch (e) {
18560
- return 0;
18561
18412
  }
18413
+ return null;
18562
18414
  }
18563
- async function chupTrangThieu(kb, bao) {
18564
- const chup2 = globalThis.__chupTrang;
18565
- if (typeof chup2 !== "function" || !kb) return 0;
18566
- let n = 0;
18567
- const ghi4 = [];
18568
- for (const m of kb.muc || []) {
18569
- const k = "trang:" + String(m && m.ten || "").trim().toLocaleLowerCase("vi").replace(/[^\p{L}\p{N}]+/gu, ""), u = String(m && m.url || "");
18570
- if (!u || taiSan(k) || !/^https:/.test(u)) continue;
18571
- bao?.("Ch\u1EE5p trang th\u1EADt " + u + "...");
18572
- try {
18573
- const b = await chup2(u);
18574
- if (b) {
18575
- datTaiSan(k, await createImageBitmap(b));
18576
- n++;
18577
- ghi4.push([k, u]);
18578
- }
18579
- } catch (e) {
18580
- ghi4.push([k, u, "loi"]);
18415
+ function apDungDoan(p, mau7, kb) {
18416
+ const sc = p?.scenes?.[0], tl = [...p?.timeline || []].sort((a, b) => a.order - b.order);
18417
+ const ws = (p?.speechDraft?.analysis?.words || []).filter((w) => w && w.t1 > w.t0 && sach(w.text));
18418
+ if (!sc || !tl.length || !ws.length || !mau7?.doan) return p;
18419
+ const kieu = mau7.doan, fm = p.speechDraft.analysis.faceMap?.samples || [], ar = p.aspectRatio === "16:9" ? 16 / 9 : 9 / 16, capY = mau7.viTri?.y ?? 0.75;
18420
+ const ms = sc.text_moments || [], doan2 = [], am = [], moi = /* @__PURE__ */ new Map(), tong = tl.reduce((s, c) => s + c.trimEnd - c.trimStart, 0);
18421
+ const anh2 = ms.filter((m) => m.kind === "illustration" && (m.videoBase64 || m.imageBase64) && (m.layout === "full" || m.insertMode === "full"));
18422
+ const fTu = (t) => {
18423
+ let s = 0;
18424
+ for (const c of tl) {
18425
+ if (t >= c.trimStart - 0.01 && t < c.trimEnd + 0.01) return s + Math.max(0, t - c.trimStart);
18426
+ s += c.trimEnd - c.trimStart;
18581
18427
  }
18582
- }
18583
- globalThis.__chupDa = ghi4;
18584
- return n;
18585
- }
18586
- async function napVideo(b, bao) {
18587
- const u = URL.createObjectURL(b), v = document.createElement("video");
18588
- v.muted = true;
18589
- v.playsInline = true;
18590
- v.preload = "auto";
18591
- v.src = u;
18592
- const nap = await choVideo(v, "loadeddata", 8e3, "napVideo");
18593
- if (nap !== "ok") {
18594
- URL.revokeObjectURL(u);
18595
- throw new Error(nap === "het" ? "[VD-209c] clip kh\xF4ng n\u1EA1p (tab \u1EA9n?)" : "video h\u1ECFng");
18596
- }
18597
- const dai2 = Math.min(8, v.duration || 4), fps = 10, n = Math.max(1, Math.floor(dai2 * fps)), ds2 = [], han = Date.now() + 6e4;
18598
- for (let i = 0; i < n; i++) {
18599
- if (Date.now() > han) {
18600
- demHetGio("napVideo", "v\xF2ng khung", 6e4);
18601
- break;
18428
+ return -1;
18429
+ };
18430
+ const nTu = (f2) => {
18431
+ let s = 0;
18432
+ for (const c of tl) {
18433
+ const L = c.trimEnd - c.trimStart;
18434
+ if (f2 <= s + L) return c.trimStart + Math.max(0, f2 - s);
18435
+ s += L;
18602
18436
  }
18603
- v.currentTime = Math.min(dai2 - 0.05, i / fps);
18604
- if (await choVideo(v, "seeked", 4e3, "napVideo") !== "ok") break;
18605
- ds2.push(await createImageBitmap(v, { resizeWidth: 432, resizeHeight: 768, resizeQuality: "medium" }));
18437
+ return tl[tl.length - 1].trimEnd;
18438
+ };
18439
+ const kw = ms.filter((m) => m.kind === "keyword" && sach(m.text)), the = (t0, t1, d) => {
18440
+ const f0 = fTu(t0);
18441
+ doan2.push({ kind: "doan", t0, t1: f0 >= 0 ? Math.max(t1, nTu(f0 + t1 - t0)) : t1, doan: { dai: t1 - t0, kieu, ...d } });
18442
+ };
18443
+ const phim2 = (t, tu = -1) => {
18444
+ let s = 0;
18445
+ for (const c of tl) {
18446
+ if (t >= c.trimStart - 0.01 && t < c.trimEnd && s + t - c.trimStart >= tu) return s + t - c.trimStart;
18447
+ s += c.trimEnd - c.trimStart;
18448
+ }
18449
+ return -1;
18450
+ };
18451
+ const keu = (t, loai) => {
18452
+ am.push({ kind: "am", t0: t, t1: t + 0.1, am: loai });
18453
+ };
18454
+ const vAI = (kb?.vat || []).map((v) => String(v && v.tu || "").toLocaleLowerCase("vi")).filter(Boolean);
18455
+ const dau = (c) => {
18456
+ if (phim2(c.t0) >= 0) return c;
18457
+ const k2 = tl.find((x) => x.trimStart > c.t0 && x.trimStart - c.t0 <= 1.5 && x.trimStart < c.t1);
18458
+ return k2 ? { ...c, t0: k2.trimStart } : c;
18459
+ };
18460
+ const cs = chiaCau(ws, tong < 15).map(dau).map((c) => ({ ...c, f: phim2(c.t0), d: c.t1 - c.t0, vat: vatTrong(c.chu, vAI) })).filter((c) => {
18461
+ const p0 = phim2(c.t0);
18462
+ return p0 >= 0 && p0 < tong - 0.2;
18463
+ }).sort((a, b) => a.f - b.f);
18464
+ cs.forEach((c) => {
18465
+ const s = " " + c.chu.join(" ").toLocaleLowerCase("vi") + " ";
18466
+ c.vat = [...new Set(vAI.filter((x) => s.indexOf(" " + x + " ") >= 0).map((x) => "vat:" + x).concat(c.vat))].slice(0, 4);
18467
+ });
18468
+ if (tong < 15) cs.forEach((c, i) => {
18469
+ c.vat = [...new Set(c.vat.concat((cs[i - 1] || c).vat, (cs[i + 1] || c).vat))].slice(0, 4);
18470
+ });
18471
+ if (kieu.khoi) cs.forEach((c) => {
18472
+ c.vatThat = vatKhoi(c.chu, kieu, vAI);
18473
+ c.vat = c.vatThat.concat(["", ""]).slice(0, Math.max(2, c.vatThat.length));
18474
+ });
18475
+ anh2.forEach((m) => {
18476
+ const c = cs.find((x) => !x.anh && m.t0 >= x.t0 - 0.05 && m.t0 < x.t1 + 0.3);
18477
+ if (c) c.anh = m;
18478
+ });
18479
+ kw.forEach((m) => {
18480
+ const c = cs.find((x) => !x.kw && m.t0 >= x.t0 - 0.3 && m.t0 < x.t1);
18481
+ if (c) c.kw = m;
18482
+ });
18483
+ const tam2 = (i) => {
18484
+ const v = fm.filter((x) => x && x.face).map((x) => x.face[i ? "y" : "x"] + x.face[i ? "h" : "w"] / 2).sort((p2, q) => p2 - q);
18485
+ return v.length < 2 ? [0.5, 0.38][i] : Math.max(i ? 0.2 : 0.3, Math.min(i ? 0.6 : 0.7, v[Math.floor(v.length / 2)]));
18486
+ }, zc = [tam2(0), tam2(1)];
18487
+ const o = { tl, cs, ws, kw, kb, kieu, fm, ar, capY, zc, tong, the, keu, fTu, nTu, chot: "", anh: anh2, moi, ms, vatNoi: [...new Set(cs.flatMap((c) => c.vat))] };
18488
+ const sy = !!kieu.saoY && tong <= 10.5 && new Set(tl.map((c) => c.sceneId)).size === 1, mo4 = sy ? [0, 0] : kieu.khoi ? moKhoi(o) : moKet(o), k = Math.max(0.27, Math.min(1, tong / 30));
18489
+ const nguon3 = (f2) => {
18490
+ let s = 0;
18491
+ for (const c of tl) {
18492
+ const L = c.trimEnd - c.trimStart;
18493
+ if (f2 < s + L) return c.trimStart + f2 - s;
18494
+ s += L;
18495
+ }
18496
+ return tl[tl.length - 1].trimEnd;
18497
+ };
18498
+ const N = (x) => Array.isArray(x) ? x.map(nguon3) : typeof x === "number" ? nguon3(x) : x, S0 = kieu.saoY || {};
18499
+ const SY = sy ? { ...S0, giay: N(S0.giay), vun: N(S0.vun), vat: N(S0.vat), bao: N(S0.bao), anh: N(S0.anh), tieu: N(S0.tieu) } : S0;
18500
+ if (!sy) chonDoan(cs, [phim2(mo4[0])], anh2.length > 0, kieu, k);
18501
+ else cs.forEach((c) => {
18502
+ c.loai = "th";
18503
+ });
18504
+ const dz = sy ? saoY({ ...o, kieu: { ...kieu, saoY: SY }, tong: nguon3(tong) }, layMoc(ws, kb, true)) : o.zoom || diemZoom(cs, phim2);
18505
+ if (o.zoomMo && !sy) {
18506
+ const [f0, z, f1] = o.zoomMo, lv = (dz.filter((x) => x[0] <= f0).pop() || [0, 1])[1];
18507
+ dz.splice(0, dz.length, ...dz.filter((x) => x[0] < f0 || x[0] > f1), [f0, z], [f1, lv]);
18606
18508
  }
18607
- URL.revokeObjectURL(u);
18608
- if (!ds2.length) throw new Error("[VD-209c] clip kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c khung n\xE0o");
18609
- bao?.("N\u1EA1p video tr\xE1m " + (ds2.length < n ? ds2.length + "/" : "") + n + " khung");
18610
- return { laVideo: true, width: 432, height: 768, dai: ds2.length < n ? ds2.length / fps : dai2, khung: (t) => ds2[Math.max(0, Math.min(ds2.length - 1, Math.floor(t * fps)))] };
18509
+ const oNguoi2 = (a, b, z) => {
18510
+ const F = matRa(fm, a, b, [0, 0, 0, 0], z, zc) || [0.3, 0.3, 0.7, 0.6], s = Math.min(0.95, 1.9 * (F[2] - F[0]));
18511
+ return [Math.max(0, Math.min(1 - s, (F[0] + F[2] - s) / 2)), Math.max(0, Math.min(1 - s * ar, (F[1] + F[3] - s * ar) / 2)), s];
18512
+ };
18513
+ o.oNguoi = oNguoi2;
18514
+ let soPol = 0, phu = -1;
18515
+ cs.forEach((c, i) => {
18516
+ if (kieu.khoi && datKhoi(o, c, i)) return;
18517
+ const t0 = c.t0;
18518
+ if (c.loai === "tron") {
18519
+ const m = c.anh, t1 = t0 + (m.t1 - m.t0), vf = m.videoFace, ct = tl.find((x) => t0 >= x.trimStart - 0.01 && t0 < x.trimEnd);
18520
+ moi.set(m, { ...m, t0, t1 });
18521
+ if (kieu.am) the(t0, t1, { loai: "am" });
18522
+ if (kieu.xeBao) {
18523
+ the(Math.max(t0 - 0.3, ct ? ct.trimStart : t0), t0 + 0.12, { loai: "xeBao", hat: 20 + i, lop: 3 });
18524
+ keu(t0 - 0.02, "whoosh");
18525
+ } else {
18526
+ keu(t0, "whoosh-nhanh");
18527
+ keu(t1, "whoosh-nhanh");
18528
+ }
18529
+ phu = t1;
18530
+ the(t0, t1, { loai: "tron", o: { x: vf && vf.x + vf.w > 0.58 ? 0.22 : 0.78, y: 0.17, s: 0.36, tron: 1, t: 0.9 }, cat: oNguoi2(t0, t1, c.z) });
18531
+ keu(t0 + 0.9, kieu.xeBao ? "whoosh-nhanh" : "pop-cao");
18532
+ } else if (c.loai === "polaroid") {
18533
+ const t1 = Math.min(c.t1 + 0.15, t0 + 4.2), A2 = anh2[0], B = anh2[1] || anh2[0], tA = (A2.videoTrimStart || 0) + 1 + 1.2 * soPol, tB = (B.videoTrimStart || 0) + (anh2[1] ? 1.6 : 3.2);
18534
+ const sw = soPol++ % 2 ? [B, tB, A2, tA] : [A2, tA, B, tB];
18535
+ the(t0, t1, {
18536
+ loai: "polaroid",
18537
+ anh: [{ m: sw[0], t: sw[1], x: 0.36, y: 0.25, s: 0.56, goc: -6, tre: 0.1 }, { m: sw[2], t: sw[3], x: 0.64, y: 0.47, s: 0.54, goc: 5, tre: 0.45 }],
18538
+ o: { x: 0.3, y: 0.58, s: 0.4, tron: 0, t: 0.85 },
18539
+ cat: oNguoi2(t0, t1, c.z)
18540
+ });
18541
+ keu(t0 - 0.02, "whoosh");
18542
+ keu(t0 + 0.12, "giay");
18543
+ keu(t0 + 0.47, "giay");
18544
+ keu(t0 + 0.87, "pop-cao");
18545
+ } else if (c.loai === "sticker") {
18546
+ const t1 = Math.min(c.t1 + 0.1, t0 + 3.6), F = matRa(fm, t0, t1, [0.06, 0.04, 0.06, 0.02], 1.09, zc), vat = F ? datVat(c.vat, F, ar, capY) : [];
18547
+ const F0 = matRa(fm, t0, t1, [0, 0, 0, 0], 1.09, zc), vt = vat.map((v, j) => ({ ...v, t: 0.2 + 0.1 * j }));
18548
+ if (vt.length) {
18549
+ the(t0, t1, { loai: "sticker", vat: vt, vot: 1.15, ra: 0.25, ...vongVun(F0, 0.12) });
18550
+ keu(t0, "giay");
18551
+ vt.forEach((v) => keu(t0 + v.t, "pop"));
18552
+ }
18553
+ } else if (c.loai === "nhan") {
18554
+ const ns = dongNhan(ngan(c.kw.text), 0.1, 0.1), t1 = t0 + Math.min(c.d + 0.3, Math.max(2.2, go(ns) + 1.3)), q = neNhan(ns, o, t0, t1, [0.12, 0.1, 0.08, 0.06, 0.16]);
18555
+ if (q) {
18556
+ the(t0, t1, { loai: "nhan", hat: 9, nhan: q, go: 0.03 });
18557
+ keu(t0, "pop-nhe");
18558
+ }
18559
+ } else if (kieu.mo === "tieuDe" && i > 0 && t0 > phu) keu(t0 - 0.02, "whoosh-nhanh");
18560
+ });
18561
+ const pd = kieu.phuDe || {}, duoi = String(mau7.id).slice(-4) === "-sua" ? "-sua" : "", lay = (id) => id ? layMau(id + duoi) : null;
18562
+ const cauCua = (t) => cs.find((c) => t >= c.t0 - 0.05 && t < c.t1 + 0.05), mpd = [lay(pd.mo), lay(pd.dac), lay(pd.ket)];
18563
+ const trenDau = (a, b, d) => {
18564
+ const F = matRa(fm, a, b, [0, 0.03, 0, 0], 1.12, zc);
18565
+ return F ? Math.max(0.09, Math.min(d, F[1] - 0.06)) : d;
18566
+ };
18567
+ const doiPd = (m) => {
18568
+ if (m.kind !== "sub" || !m.tu) return m;
18569
+ const c = cauCua(m.t0), x = sy && SY.anh && m.t1 - SY.anh > SY.anh - m.t0 ? mpd[1] : (
18570
+ // trang phần lớn sau chỗ cắt sang ảnh
18571
+ !c ? null : c === cs[0] && m.t0 < mo4[1] ? mpd[0] : c.loai === "tron" ? mpd[1] : c === cs[cs.length - 1] ? mpd[2] : null
18572
+ );
18573
+ const Y = !sy && tong >= 15 && kieu.phuDeY, y = Y && c ? c === cs[0] && m.t0 < mo4[1] ? trenDau(m.t0, m.t1, Y.mo) : c.loai === "tron" ? Y.anh : Y.noi : void 0;
18574
+ return x ? { ...m, mpd: x, safeY: y } : y ? { ...m, safeY: y } : m;
18575
+ };
18576
+ const nhip = { cau: cs.map((c) => ({ f: +c.f.toFixed(2), d: +c.d.toFixed(2), loai: c.loai, z: c.z, chu: c.chu.slice(0, 5).join(" ") })) };
18577
+ const tm = doan2.concat(am, ms.filter((m) => m.kind !== "keyword").map((m) => doiPd(moi.get(m) || m)));
18578
+ return { ...p, timeline: catZoom(tl, dz), nhipDoan: nhip, scenes: p.scenes.map((s, k2) => k2 ? s : { ...s, text_moments: tm }) };
18579
+ }
18580
+ function lichAm(clips) {
18581
+ const ra = [], da = /* @__PURE__ */ new Set();
18582
+ let t = 0;
18583
+ clips.forEach((c) => {
18584
+ (c.textMoments || []).forEach((m) => {
18585
+ if (m.kind !== "am" || da.has(m) || m.t0 < c.trimStart - 0.01 || m.t0 >= c.trimEnd) return;
18586
+ da.add(m);
18587
+ ra.push({ t: t + Math.max(0, m.t0 - c.trimStart), loai: m.am });
18588
+ });
18589
+ t += Math.max(0, c.trimEnd - c.trimStart);
18590
+ });
18591
+ globalThis.__amCm = ra.map((x) => [+(+x.t).toFixed(2), x.loai]);
18592
+ return ra;
18593
+ }
18594
+ function lichDoan(clips) {
18595
+ const ra = [], da = /* @__PURE__ */ new Map();
18596
+ let t = 0;
18597
+ clips.forEach((c, i) => {
18598
+ const s = c.trimStart, e = c.trimEnd;
18599
+ (c.textMoments || []).forEach((m) => {
18600
+ if (m.kind !== "doan") return;
18601
+ const a = Math.max(s, m.t0), b = Math.min(e, m.t1), L = da.get(m);
18602
+ if (b - a < 0.02 || (L ? L.i !== i - 1 || s < L.e - 0.05 : m.t0 < s - 0.05 || m.t0 >= e)) return;
18603
+ if (L && Math.abs(s - L.e) < 0.02) {
18604
+ ra[L.k].T1 = t + b - s;
18605
+ L.i = i;
18606
+ L.e = b;
18607
+ return;
18608
+ }
18609
+ const tuL = L ? ra[L.k].tuLech + ra[L.k].T1 - ra[L.k].T0 : a - m.t0;
18610
+ da.set(m, { i, e: b, k: ra.length });
18611
+ ra.push({ T0: t + a - s, T1: t + b - s, kind: "doan", text: "", doan: m.doan, tuLech: tuL, dayXuong: m.doan.day });
18612
+ });
18613
+ t += Math.max(0, e - s);
18614
+ });
18615
+ globalThis.__doanRoi = [...new Set(clips.flatMap((c) => (c.textMoments || []).filter((m) => m.kind === "doan" && !da.has(m))))].map((m) => [+(+m.t0).toFixed(2), +(+m.t1).toFixed(2), m.doan?.loai, m.doan?.bo, m.doan?.giant, clips.filter((c) => c.trimEnd > m.t0 - 1 && c.trimStart < m.t0 + 1).map((c) => [+c.trimStart.toFixed(3), +c.trimEnd.toFixed(3)])]);
18616
+ return ra;
18611
18617
  }
18612
18618
 
18613
18619
  // flow-src/engine/taiSanAI.ts
@@ -20794,7 +20800,7 @@ function datCauLenh(a) {
20794
20800
  on2 = true;
20795
20801
  window.addEventListener("message", async (ev) => {
20796
20802
  const d = ev.data;
20797
- if (!d || d.xvaiLoi111930 !== true) return;
20803
+ if (!d || d.xvaiLoi112023 !== true) return;
20798
20804
  const o = String(ev.origin || "");
20799
20805
  if (!(o.indexOf("https://flow.google.com") === 0 || o.indexOf("https://labs.google") === 0)) return;
20800
20806
  const tra = (kq) => {