@taole/giftstage-plugin-multi-gift 0.0.58 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +823 -774
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});require("@taole/giftstage");const pe=.42,Z=8192,de="LOTTIE_EFFECT_PARTICLE_CAPACITY_EXCEEDED",ve=Object.freeze([Object.freeze({batch:"main",rate:105,phase:"launch"}),Object.freeze({batch:"main",rate:78,phase:"launch"}),Object.freeze({batch:"main",rate:48,phase:"launch"}),Object.freeze({batch:"smoke",rate:18,phase:"launch"}),Object.freeze({batch:"main",rate:390,phase:"burst"}),Object.freeze({batch:"main",rate:275,phase:"burst"}),Object.freeze({batch:"main",rate:145,phase:"burst"}),Object.freeze({batch:"main",rate:265,phase:"secondary"}),Object.freeze({batch:"main",rate:175,phase:"secondary"}),Object.freeze({batch:"main",rate:48,phase:"secondary"})]);function tt(e,t,i){return Math.max(t,Math.min(i,e))}function $e(e={}){const t=e.quality??"auto";if(typeof t=="number")return tt(t,.25,1.25);if(t==="low")return .46;if(t==="medium")return .72;if(t==="high")return 1;const i=Number.isFinite(e.deviceMemory)?e.deviceMemory:8,s=Number.isFinite(e.hardwareConcurrency)?e.hardwareConcurrency:8;return i<=4||s<=4?.52:/Android|iPhone|iPad|iPod/i.test(e.userAgent||"")?.72:1}function Ue({launchDuration:e,density:t=1,resolvedQualityScale:i=1}){if(!Number.isFinite(e)||e<0||!Number.isFinite(t)||t<0||!Number.isFinite(i)||i<0)throw new Error("firework 粒子数量规划参数必须是有限非负数");const s=t*i;if(!Number.isFinite(s))throw new Error("firework 粒子数量规划结果不是有限数值");const r={launch:e*.84,burst:.11,secondary:.14},n=ve.map(({rate:o,phase:c})=>Math.max(1,Math.round(o*r[c]*s)));let l=0,a=0;return n.forEach((o,c)=>{ve[c].batch==="smoke"?l+=o:a+=o}),Object.freeze({emitterCounts:Object.freeze(n),smokeCount:l,mainCount:a,totalCount:l+a,flashCount:1})}function je(e,t=Z){if(!Number.isSafeInteger(e==null?void 0:e.smokeCount)||e.smokeCount<0||!Number.isSafeInteger(e==null?void 0:e.mainCount)||e.mainCount<0)throw new Error("firework smoke/main 粒子数量必须是非负安全整数");if(!Number.isSafeInteger(t)||t<1)throw new Error("firework maxInstancesPerBatch 必须是正安全整数");if(e.smokeCount>t||e.mainCount>t){const i=new RangeError(`firework 粒子批次超过上限 ${t}(smoke=${e.smokeCount}, main=${e.mainCount})`);throw i.code=de,i.counts=e,i.maxInstancesPerBatch=t,i}return e}function Ge({frameRate:e,dismissFrame:t,durationSeconds:i=pe}){if(!Number.isFinite(e)||!(e>0)||!Number.isFinite(t)||!Number.isFinite(i)||!(i>0))throw new Error("firework dismissDuration 必须生成有限且严格递增的毫秒区间");const s=t/e,r=s*1e3,n=(s+i)*1e3;if(!Number.isFinite(r)||!Number.isFinite(n)||!(n>r))throw new Error("firework dismissDuration 必须生成有限且严格递增的毫秒区间");return Object.freeze({durationSeconds:i,startSeconds:s,startMs:r,endMs:n})}const Te=150,Re=new WeakMap;function te(e,t){return Array.isArray(e)?e:e!=null?[e]:Array.isArray(t)?t:[t]}function le(e,t,i){const s=e==null?void 0:e[t];if(!s)return null;if(Array.isArray(s))return{x:s[0],y:s[1]??s[0]};if(typeof s=="object"){const r=a=>{const o=s[a];return o==null?null:Array.isArray(o)?o[i]??o[0]:o},n=r("x"),l=r("y");return n==null||l==null?null:{x:n,y:l}}return null}function it(e,t,i){const s=1-e;return 3*s*s*e*t+3*s*e*e*i+e*e*e}function st(e,t,i){const s=1-e;return 3*s*s*e*t+3*s*e*e*i+e*e*e}class ne extends Error{constructor(t,i,s=[],r=!1){super(i),this.name="MultiGiftValidationError",this.code=t,this.findings=s,this.recoverable=r}}function F(e,t,i={}){return{code:e,severity:i.severity||"error",scope:i.scope||"slot",where:t,...i.layer?{layer:i.layer}:{},...Number.isInteger(i.effectIndex)?{effectIndex:i.effectIndex}:{}}}function L(e,t){e.some(i=>i.code===t.code&&i.where===t.where)||e.push(t)}function ie(e){return!e||typeof e!="object"?[]:e.a===1?Array.isArray(e.k)?e.k.flatMap(t=>[t==null?void 0:t.s,t==null?void 0:t.e]).filter(t=>t!==void 0):[]:e.k===void 0?[]:[e.k]}function V(e){const t=Array.isArray(e)?e:[e];return t.length>0&&t.every(Number.isFinite)?t:null}function Ye(e,t=new Set){return!e||typeof e!="object"||t.has(e)?!1:(t.add(e),typeof e.x=="string"?!0:Object.values(e).some(i=>Ye(i,t)))}function J(e,t,i,s,r){if(e==null)return;const n=()=>L(i,F("LOTTIE_INVALID_KEYFRAME",t,{layer:s}));if(typeof e!="object"||e.k===void 0){n();return}if(typeof e.x=="string"&&L(i,F("LOTTIE_UNSUPPORTED_TRANSFORM",`${t}.x`,{layer:s})),e.a!==1){const o=V(e.k);(!o||!r.includes(o.length))&&n();return}if(!Array.isArray(e.k)||e.k.length===0){n();return}let l=-1/0,a=null;for(let o=0;o<e.k.length;o+=1){const c=e.k[o];if(!c||!Number.isFinite(c.t)||c.t<l){n();return}l=c.t;const d=[c.s,c.e].filter(m=>m!==void 0);if(c.s===void 0||d.length===0){n();return}for(const m of d){const p=V(m);if(!p||!r.includes(p.length)){n();return}if(a==null&&(a=p.length),a!==p.length){n();return}}}}function me(e){var n,l,a,o,c,d;const t=[],i=e.nm||`ind_${e.ind}`,s={layer:i};e.parent!==void 0&&t.push(F("LOTTIE_UNSUPPORTED_PARENT",i,s)),e.ddd===1&&t.push(F("LOTTIE_UNSUPPORTED_3D",i,s));const r=(n=e.ks)==null?void 0:n.p;return r&&(r.s===!0||r.x!==void 0||r.y!==void 0)&&t.push(F("LOTTIE_UNSUPPORTED_SPLIT_POSITION",i,s)),(((l=e.ks)==null?void 0:l.rx)!==void 0||((a=e.ks)==null?void 0:a.ry)!==void 0||((o=e.ks)==null?void 0:o.or)!==void 0||((c=e.ks)==null?void 0:c.sk)!==void 0||((d=e.ks)==null?void 0:d.sa)!==void 0||e.ao===1||e.sr!==void 0&&e.sr!==1||e.st!==void 0&&e.st!==0||e.tm!==void 0||e.bm!==void 0&&e.bm!==0||e.tt!==void 0||e.td!==void 0||e.hasMask===!0||Array.isArray(e.masksProperties)&&e.masksProperties.length>0||Array.isArray(e.ef)&&e.ef.length>0||Ye(e))&&t.push(F("LOTTIE_UNSUPPORTED_TRANSFORM",i,s)),(r==null?void 0:r.a)===1&&Array.isArray(r.k)&&r.k.forEach((m,p)=>{var w;const v=(m==null?void 0:m.to)!==void 0,y=(m==null?void 0:m.ti)!==void 0;if(!v&&!y)return;const b=m==null?void 0:m.s,g=(m==null?void 0:m.e)??((w=r.k[p+1])==null?void 0:w.s),h=Array.isArray(b)?b.length:-1,u=M=>Array.isArray(M)&&M.length===h&&M.every(Number.isFinite);(!u(b)||!u(g)||!u(m.to)||!u(m.ti))&&t.push(F("LOTTIE_INVALID_KEYFRAME",`${i}.ks.p[${p}]`,s))}),t}function Ke(e,t,i){let s=0,r=1;for(let l=0;l<32;l+=1){const a=(s+r)/2;it(a,t.x,i.x)<e?s=a:r=a}const n=(s+r)/2;return st(n,t.y,i.y)}function rt(e){return((e==null?void 0:e.layers)||[]).flatMap(me)}function We(e,t={}){var d,m,p,v,y,b,g;const i=[],s=Array.isArray(e==null?void 0:e.layers)?e.layers:[];(!Number.isFinite(e==null?void 0:e.w)||e.w<=0||!Number.isFinite(e==null?void 0:e.h)||e.h<=0||!Number.isFinite(e==null?void 0:e.fr)||e.fr<=0||!Number.isFinite(e==null?void 0:e.ip)||!Number.isFinite(e==null?void 0:e.op)||e.op<=e.ip)&&i.push(F("LOTTIE_INVALID_COMPOSITION","composition",{scope:"composition"}));const r=/^(slot|img_slot)_(\d+)$/,n=s.filter(h=>r.test((h==null?void 0:h.nm)||""));n.filter(h=>/^slot_\d+$/.test(h.nm)).length===0&&i.push(F("LOTTIE_SLOT_MISSING","layers",{scope:"composition"}));for(const h of["slot","img_slot"]){const u=n.filter(O=>O.nm.startsWith(`${h}_`)),w=new Set,M=[];for(const O of u)w.has(O.nm)&&L(i,F("LOTTIE_SLOT_DUPLICATED",O.nm,{scope:"composition"})),w.add(O.nm),M.push(Number((d=r.exec(O.nm))==null?void 0:d[2]));Array.from(new Set(M)).sort((O,_)=>O-_).some((O,_)=>O!==_+1)&&i.push(F("LOTTIE_SLOT_INDEX_GAP",h,{scope:"composition"}))}for(const h of n){const u=h.nm;for(const k of me(h))L(i,k);h.ty!==3&&L(i,F("LOTTIE_UNSUPPORTED_LAYER_TYPE",u,{layer:u})),(!Number.isFinite(h.ip)||!Number.isFinite(h.op)||h.op<=h.ip)&&L(i,F("LOTTIE_INVALID_KEYFRAME",`${u}.ip/op`,{layer:u}));const w=h.ks||{};J(w.p,`${u}.ks.p`,i,u,[2,3]),J(w.s,`${u}.ks.s`,i,u,[2,3]),J(w.r,`${u}.ks.r`,i,u,[1]),J(w.rz,`${u}.ks.rz`,i,u,[1]),J(w.o,`${u}.ks.o`,i,u,[1]),w.r!==void 0&&w.rz!==void 0&&L(i,F("LOTTIE_UNSUPPORTED_TRANSFORM",`${u}.ks.r/rz`,{layer:u}));const M=w.a,E=ie(M);((M==null?void 0:M.a)===1||E.some(k=>{const T=V(k);return!T||T.some(R=>R!==0)}))&&L(i,F("LOTTIE_UNSUPPORTED_ANCHOR",`${u}.ks.a`,{layer:u})),ie(w.p).some(k=>{const T=V(k);return!!T&&T.length>2&&T[2]!==0})&&L(i,F("LOTTIE_UNSUPPORTED_3D",`${u}.ks.p`,{layer:u})),ie(w.s).some(k=>{const T=V(k);return!!T&&(T[0]<0||T[1]<0||T.length>2&&T[2]!==100)})&&L(i,F("LOTTIE_UNSUPPORTED_TRANSFORM",`${u}.ks.s`,{layer:u}))}const a=oe(e==null?void 0:e.markers,"target_flight");(!a||!Number.isFinite(a.tm)||!Number.isFinite(a.dr)||a.dr<=0||a.tm<e.ip||a.tm+a.dr>e.op)&&i.push(F("LOTTIE_TARGET_MARKER_MISSING","markers.target_flight",{scope:"composition",severity:"warning"}));const o=new Map(((e==null?void 0:e.markers)||[]).map(h=>[h==null?void 0:h.cm,h])),c=new Map(s.map(h=>[h==null?void 0:h.nm,h]));for(const[h,u]of(t.effects||[]).entries()){if((u==null?void 0:u.type)!=="firework")continue;for(const R of["launch","burst"]){const S=(m=u.anchors)==null?void 0:m[R],N=c.get(S);if(!S||!((p=N==null?void 0:N.ks)!=null&&p.p)){L(i,F("LOTTIE_EFFECT_ANCHOR_MISSING",`effects[${h}].anchors.${R}`,{scope:"effect",severity:"warning",effectIndex:h}));continue}const z=me(N),P=[];J(N.ks.p,`${S}.ks.p`,P,S,[2,3]),ie(N.ks.p).some(f=>{const A=V(f);return!!A&&A.length>2&&A[2]!==0})&&z.push(F("LOTTIE_UNSUPPORTED_3D",`${S}.ks.p`,{layer:S}));for(const[f,A]of[["s",[100,100,100]],["r",[0]],["rz",[0]],["o",[100]],["a",[0,0,0]]]){const C=N.ks[f];if(C==null)continue;const D=ie(C);C.a!==1&&D.length>0&&D.every(Y=>{const W=V(Y);return!!W&&W.length===A.length&&W.every((X,$)=>X===A[$])})||z.push(F("LOTTIE_UNSUPPORTED_TRANSFORM",`${S}.ks.${f}`,{layer:S}))}N.ty!==3&&z.push(F("LOTTIE_UNSUPPORTED_LAYER_TYPE",S,{layer:S}));for(const f of[...z,...P])L(i,F(f.code,f.where,{scope:"effect",severity:"warning",effectIndex:h,layer:S}))}for(const R of["launch","burst","dismiss"]){const S=(v=u.markers)==null?void 0:v[R],N=o.get(S);!S||!N?L(i,F("LOTTIE_EFFECT_MARKER_MISSING",`effects[${h}].markers.${R}`,{scope:"effect",severity:"warning",effectIndex:h})):(!Number.isFinite(N.tm)||!Number.isFinite(N.dr)||N.dr<0||R==="launch"&&N.dr<=0)&&L(i,F("LOTTIE_EFFECT_MARKER_INVALID",`effects[${h}].markers.${R}`,{scope:"effect",severity:"warning",effectIndex:h}))}const w=o.get((y=u.markers)==null?void 0:y.launch),M=o.get((b=u.markers)==null?void 0:b.burst),E=o.get((g=u.markers)==null?void 0:g.dismiss),O=u.dismissDuration??pe,_=Number.isFinite(O)&&O>0;let k=null,T=_;if(_&&E&&Number.isFinite(E.tm)&&Number.isFinite(e.fr)&&e.fr>0)try{k=Ge({frameRate:e.fr,dismissFrame:E.tm,durationSeconds:O})}catch{T=!1}if(T||L(i,F("LOTTIE_EFFECT_DISMISS_DURATION_INVALID",`effects[${h}].dismissDuration`,{scope:"effect",severity:"warning",effectIndex:h})),w&&Number.isFinite(w.dr)&&w.dr>0&&Number.isFinite(e.fr)&&e.fr>0)try{const R=t.fireworkEnvironment||{},S=$e({...R,quality:u.quality??R.quality??"auto"});je(Ue({launchDuration:w.dr/e.fr,density:u.density??1,resolvedQualityScale:S}),t.maxInstancesPerBatch??Z)}catch(R){L(i,F((R==null?void 0:R.code)===de?de:"LOTTIE_EFFECT_PARTICLE_CONFIG_INVALID",`effects[${h}]`,{scope:"effect",severity:"warning",effectIndex:h}))}w&&M&&E&&Number.isFinite(w.tm)&&Number.isFinite(M.tm)&&Number.isFinite(E.tm)&&Number.isFinite(e.fr)&&e.fr>0&&k&&!(w.tm/e.fr*1e3<=M.tm/e.fr*1e3&&M.tm/e.fr*1e3<k.endMs)&&L(i,F("LOTTIE_EFFECT_TIMING_INVALID",`effects[${h}].markers`,{scope:"effect",severity:"warning",effectIndex:h}))}return i}function Xe(e,t,i,s){const r=Math.max(e.length,t.length,i.length,s.length),n=[];let l=0,a=null;for(let o=0;o<Te;o+=1){const c=o/(Te-1),d=1-c,m=Array.from({length:r},(v,y)=>{const b=e[y]??0,g=t[y]??b,h=b+(i[y]??0),u=g+(s[y]??0);return d**3*b+3*d**2*c*h+3*d*c**2*u+c**3*g}),p=a?Math.sqrt(m.reduce((v,y,b)=>v+(y-a[b])**2,0)):0;l+=p,n.push({partialLength:p,point:m}),a=m}return{points:n,segmentLength:l}}function nt(e,t,i){let s=Re.get(e);return s||(s=Xe(t,i,e.to,e.ti),Re.set(e,s)),s}function Ve(e,t){const i=Math.max(0,Math.min(1,e)),s=t.segmentLength*i;let r=0;for(let n=0;n<t.points.length;n+=1){const l=t.points[n];if(r+=l.partialLength,s===0||i===0||n===t.points.length-1)return l.point.slice();const a=t.points[n+1];if(s>=r&&s<r+a.partialLength){const o=(s-r)/a.partialLength;return l.point.map((c,d)=>c+(a.point[d]-c)*o)}}return t.points[t.points.length-1].point.slice()}function ot(e,t,i,s,r){return Ve(e,Xe(t,i,s,r))}function B(e,t,i){if(!e||e.a===0)return te(e==null?void 0:e.k,i);const s=e.k,r=s.findIndex((v,y)=>{const b=s[y+1];return!b||t<b.t}),n=s[Math.max(r,0)],l=s[r+1];if(!l||t<=n.t||n.h===1)return te(n.s,i);const a=te(n.s,i),o=te(n.e||l.s,a),c=Math.max(0,Math.min(1,(t-n.t)/(l.t-n.t))),d=le(n,"o",0),m=le(n,"i",0)||le(l,"i",0),p=d&&m?Ke(c,d,m):c;return Array.isArray(n.to)&&Array.isArray(n.ti)?Ve(p,nt(n,a,o)):a.map((v,y)=>v+((o[y]??v)-v)*p)}function Be(e){return 1-(1-e)**3}function at(e){return e<.5?4*e*e*e:1-(-2*e+2)**3/2}function oe(e,t){return e==null?void 0:e.find(i=>i.cm===t)}const ce=Math.PI*2,lt=Object.freeze({glow:[22,22],spark:[10,22],star:[24,24],smoke:[26,26],petal:[18,24],flash:[96,96]});function ct(e,{type:t,color:i,width:s,height:r},n=0,l=0){e.save(),e.translate(n,l);const a=s/2,o=r/2;if(t==="glow"||t==="smoke"||t==="flash"){const c=e.createRadialGradient(a,o,0,a,o,s/2);c.addColorStop(0,t==="smoke"?i:"#ffffff"),c.addColorStop(t==="flash"?.22:.3,i),c.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=c,e.fillRect(0,0,s,r)}else if(t==="spark"){const c=e.createLinearGradient(a,r,a,0);c.addColorStop(0,"rgba(255,255,255,0)"),c.addColorStop(.46,i),c.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=c,e.fillRect(0,0,s,r),e.fillStyle="#ffffff",e.beginPath(),e.arc(a,o*.72,5,0,ce),e.fill()}else if(t==="star")e.strokeStyle=i,e.fillStyle="#ffffff",e.lineCap="round",e.lineWidth=2,e.beginPath(),e.moveTo(a,1),e.lineTo(a,r-1),e.moveTo(1,o),e.lineTo(s-1,o),e.moveTo(5,5),e.lineTo(s-5,r-5),e.moveTo(s-5,5),e.lineTo(5,r-5),e.stroke(),e.beginPath(),e.arc(a,o,4,0,ce),e.fill();else if(t==="petal"){e.save(),e.translate(a,o),e.rotate(-.32),e.scale(.72,1);const c=e.createLinearGradient(0,-r/2,0,r/2);c.addColorStop(0,"#ffffff"),c.addColorStop(.42,i),c.addColorStop(1,"rgba(105, 0, 25, 0.5)"),e.fillStyle=c,e.beginPath(),e.ellipse(0,0,8,15,0,0,ce),e.fill(),e.restore()}else throw e.restore(),new Error(`未知 firework texture 类型:${t}`);e.restore()}const K=Math.PI*2,ft=Object.freeze(["#ff385c","#ffad38","#ffe095"]),ht=20260808;function ut(e,t=0,i=1){return Math.max(t,Math.min(i,e))}function dt(e){let t=e>>>0;return()=>{t+=1831565813;let i=t;return i=Math.imul(i^i>>>15,i|1),i^=i+Math.imul(i^i>>>7,i|61),((i^i>>>14)>>>0)/4294967296}}function mt(e){const t=e??ht;if(!Number.isInteger(t)||t<0||t>4294967295)throw new Error("firework seed 必须是 0 到 4294967295 之间的整数");return t}function Ae(e,t,i=1,s=!1){if(!Number.isFinite(t))throw new Error("firework envelope 时间必须是有限毫秒值");if(!(e!=null&&e.length))return i;const r=s?t-1e-6:t;if(r<e[0].startMs)return e[0].from;let n=e[0].from;for(const l of e){if(r<l.startMs)return n;if(r<l.endMs){if(l.interpolation==="hold")return l.from;const a=(r-l.startMs)/(l.endMs-l.startMs);return l.from+(l.to-l.from)*a}n=l.to}return n}function gt(e,t,i,s,r){const n=1-r,l=n**3,a=3*n*n*r,o=3*n*r*r,c=r**3;return{x:l*e.x+a*t.x+o*i.x+c*s.x,y:l*e.y+a*t.y+o*i.y+c*s.y}}function fe(e,t){var r;const i=e.markers||((r=e.lottie)==null?void 0:r.markers)||[],s=i instanceof Map?i.get(t):oe(i,t);if(!s)throw new Error(`Lottie 中缺少效果 marker:${t}`);return s}function Oe(e,t,i,s){var a,o;if(typeof e.resolveAnchor=="function"){const c=e.resolveAnchor(t,i);return{x:c.x*s.scale+s.offsetX,y:c.y*s.scale+s.offsetY}}const r=(a=e.layers)==null?void 0:a.get(t);if(!((o=r==null?void 0:r.ks)!=null&&o.p))throw new Error(`Lottie 中缺少效果锚点图层:${t}`);const[n,l]=B(r.ks.p,i,[0,0,0]);return{x:n*s.scale+s.offsetX,y:l*s.scale+s.offsetY}}function ge(e,t){return`${e}:${String(t).trim().toLowerCase()}`}function Je(e){return Object.freeze(ft.map((t,i)=>{const s=e==null?void 0:e[i];return typeof s=="string"&&s.trim()?s.trim():t}))}function qe(e={}){const t=Je(e.colors),i=[["glow","#ffffff"],["spark",t[1]],["glow",t[0]],["smoke","rgba(184, 184, 184, 0.24)"],["spark",t[0]],["star","#ffffff"],["glow",t[2]||t[1]],["petal",t[0]],["flash",t[0]]],s=[],r=new Set;for(const[n,l]of i){const a=ge(n,l);if(r.has(a))continue;r.add(a);const[o,c]=lt[n];s.push(Object.freeze({key:a,type:n,color:l,width:o,height:c}))}return Object.freeze({key:JSON.stringify(s.map(({key:n,width:l,height:a})=>[n,l,a])),cells:Object.freeze(s)})}function pt({startMs:e,endMs:t}){return Object.freeze([Object.freeze({startMs:e,endMs:t,from:1,to:0,interpolation:"linear"})])}function wt(e){const t=e*1e3;return Object.freeze([Object.freeze({startMs:t,endMs:t+28.8,from:0,to:1,interpolation:"linear"}),Object.freeze({startMs:t+28.8,endMs:t+100.8,from:1,to:.72,interpolation:"linear"}),Object.freeze({startMs:t+100.8,endMs:t+360,from:.5184,to:0,interpolation:"linear"})])}function bt(e){const t=e*1e3;return Object.freeze([Object.freeze({startMs:t,endMs:t+43.2,from:.18,to:1.35,interpolation:"linear"}),Object.freeze({startMs:t+43.2,endMs:t+115.2,from:1.35,to:.78,interpolation:"linear"}),Object.freeze({startMs:t+115.2,endMs:t+360,from:.78,to:2.25,interpolation:"linear"})])}function yt({effect:e,composition:t,layout:i={scale:1,offsetX:0,offsetY:0},resolvedQualityScale:s=1,seed:r=e==null?void 0:e.seed,maxParticleCount:n=Z*2,maxInstancesPerBatch:l=Z}){var X,$,se,we,be,ye,Ee;const a=mt(r),o=t.frameRate??((X=t.lottie)==null?void 0:X.fr);if(![o,i.scale,i.offsetX,i.offsetY,s].every(Number.isFinite)||!(o>0))throw new Error("firework 编译参数包含非有限数值");const c=fe(t,($=e.markers)==null?void 0:$.launch),d=fe(t,(se=e.markers)==null?void 0:se.burst),m=fe(t,(we=e.markers)==null?void 0:we.dismiss);for(const U of[c,d,m])if(!Number.isFinite(U.tm)||!Number.isFinite(U.dr)||U.dr<0)throw new Error(`firework marker 无效:${U.cm}`);const p=e.dismissDuration??pe,v=e.density??1,y=e.formationRadius??200;if(!Number.isFinite(p)||p<=0||!Number.isFinite(v)||v<0||!Number.isFinite(y)||y<0)throw new Error("firework dismissDuration 必须是正数,其他效果参数必须是有限非负数");const b=c.tm/o,g=c.dr/o,h=d.tm/o,u=Ge({frameRate:o,dismissFrame:m.tm,durationSeconds:p}),w=u.startSeconds;if(!(b<=h&&h*1e3<u.endMs))throw new Error("firework marker 时间顺序无效");const M=Oe(t,(be=e.anchors)==null?void 0:be.launch,c.tm,i),E=Oe(t,(ye=e.anchors)==null?void 0:ye.burst,d.tm,i),O=(t.width??((Ee=t.lottie)==null?void 0:Ee.w)??0)*i.scale,_=y*i.scale,k=Je(e.colors),T=v*s;if(!Number.isFinite(T))throw new Error("firework quality 参数无效");const R=je(Ue({launchDuration:g,density:v,resolvedQualityScale:s}),l);if(R.totalCount>n)throw new Error(`firework 粒子数量超过安全上限:${n}`);const S=dt(a),N=[],z=U=>{const I=ut((U-b)/Math.max(g,.001)),ae=I*I,Q=Math.min(O*.08,30*i.scale),ee=Math.abs(M.y-E.y);return gt(M,{x:M.x-Q,y:M.y-ee*.34},{x:E.x+Q*.55,y:E.y+ee*.28},E,ae)},P=(U,I)=>{const ae=R.emitterCounts[U];for(let Q=0;Q<ae;Q+=1){const ee=I.start+S()*(I.end-I.start),Se=I.angle+(S()-.5)*I.angleRange,Me=Math.max(0,I.velocity+(S()-.5)*2*I.velocityRange),ke=I.origin(ee);N.push(Object.freeze({emitterIndex:U,type:I.type,color:I.color,cellKey:ge(I.type,I.color),blend:I.blend,birthTime:ee,lifetime:Math.max(.08,I.lifetime+(S()-.5)*2*I.lifetimeRange),x:ke.x,y:ke.y,vx:Math.cos(Se)*Me,vy:Math.sin(Se)*Me,ax:I.gravityX||0,ay:I.gravityY||0,scale:Math.max(.08,I.scale+(S()-.5)*2*(I.scaleRange||0)),scaleSpeed:I.scaleSpeed||-.16,rotation:S()*K,spin:(I.spin||0)+(S()-.5)*2*(I.spinRange||0)}))}},j=b+g*.84;P(0,{type:"glow",color:"#ffffff",blend:"lighter",rate:105,start:b,end:j,lifetime:.24,lifetimeRange:.08,velocity:24*i.scale,velocityRange:10*i.scale,angle:0,angleRange:K,gravityY:0,scale:.72,scaleRange:.24,origin:z}),P(1,{type:"spark",color:k[1],blend:"lighter",rate:78,start:b,end:j,lifetime:.42,lifetimeRange:.12,velocity:38*i.scale,velocityRange:18*i.scale,angle:Math.PI/2,angleRange:Math.PI*.72,gravityY:38*i.scale,scale:.9,scaleRange:.32,spin:1.4,spinRange:2.8,origin:z}),P(2,{type:"glow",color:k[0],blend:"lighter",rate:48,start:b,end:j,lifetime:.5,lifetimeRange:.16,velocity:30*i.scale,velocityRange:16*i.scale,angle:Math.PI/2,angleRange:Math.PI*.88,gravityY:32*i.scale,scale:.5,scaleRange:.2,origin:z}),P(3,{type:"smoke",color:"rgba(184, 184, 184, 0.24)",blend:"source-over",rate:18,start:b,end:j,lifetime:.72,lifetimeRange:.18,velocity:18*i.scale,velocityRange:9*i.scale,angle:0,angleRange:K,gravityY:-8*i.scale,scale:.9,scaleRange:.32,scaleSpeed:.24,origin:z});const f=Math.max(_*1.22,118*i.scale);P(4,{type:"spark",color:k[1],blend:"lighter",rate:390,start:h,end:h+.11,lifetime:1.18,lifetimeRange:.28,velocity:f,velocityRange:f*.42,angle:0,angleRange:K,gravityY:72*i.scale,scale:.5,scaleRange:.19,scaleSpeed:-.1,spin:1.8,spinRange:4.2,origin:()=>E}),P(5,{type:"spark",color:k[0],blend:"lighter",rate:275,start:h,end:h+.11,lifetime:1.38,lifetimeRange:.34,velocity:f*.82,velocityRange:f*.46,angle:0,angleRange:K,gravityY:84*i.scale,scale:.4,scaleRange:.15,scaleSpeed:-.1,spin:-1.2,spinRange:4.8,origin:()=>E}),P(6,{type:"glow",color:"#ffffff",blend:"lighter",rate:145,start:h,end:h+.11,lifetime:.62,lifetimeRange:.12,velocity:f*.68,velocityRange:f*.26,angle:0,angleRange:K,gravityY:46*i.scale,scale:.44,scaleRange:.17,scaleSpeed:-.1,origin:()=>E});const A=h+.12,C=Math.max(_*.74,76*i.scale);P(7,{type:"star",color:"#ffffff",blend:"lighter",rate:265,start:A,end:A+.14,lifetime:1.5,lifetimeRange:.38,velocity:C,velocityRange:C*.48,angle:0,angleRange:K,gravityY:62*i.scale,scale:.4,scaleRange:.18,scaleSpeed:-.055,spin:1.8,spinRange:5.6,origin:()=>E}),P(8,{type:"glow",color:k[2]||k[1],blend:"lighter",rate:175,start:A,end:A+.14,lifetime:1.72,lifetimeRange:.42,velocity:C*.72,velocityRange:C*.5,angle:0,angleRange:K,gravityY:74*i.scale,scale:.24,scaleRange:.12,scaleSpeed:-.035,origin:()=>E}),P(9,{type:"petal",color:k[0],blend:"lighter",rate:48,start:A,end:A+.14,lifetime:1.55,lifetimeRange:.32,velocity:C*.62,velocityRange:C*.38,angle:0,angleRange:K,gravityX:5*i.scale,gravityY:86*i.scale,scale:.62,scaleRange:.26,scaleSpeed:-.08,spin:2.4,spinRange:6.2,origin:()=>E});const D=[],G=[];for(const U of N)(U.blend==="source-over"?D:G).push(U);const Y=pt(u),W=Object.freeze({type:"flash",color:k[0],cellKey:ge("flash",k[0]),x:E.x,y:E.y,birthTime:h,lifetime:.36,opacityEnvelope:wt(h),sizeEnvelope:bt(h)});return Object.freeze({seed:a,palette:k,atlasRecipeKey:qe(e).key,timeline:Object.freeze({launchStart:b,launchDuration:g,burstStart:h,dismissStart:w,dismissDuration:p}),launchPoint:Object.freeze(M),burstPoint:Object.freeze(E),particles:Object.freeze(N),smoke:Object.freeze(D),main:Object.freeze(G),flash:W,dismissEnvelope:Y})}function Fe(e){return typeof e=="string"?e.trim():""}function Ze(e={}){const t=e.playConfig||e,i=t.multiGiftEffect||{},s=t.giftUrl||t.assetUrl||"",r=t.giftRealSize||t.giftBodySize||null;let n=t.assetType;n||(s==="box"?n="box":typeof s=="string"&&(/\.(png|jpe?g|webp|gif|bmp)($|\?)/i.test(s)||s.startsWith("data:image/"))?n="image":n="svga");const l=i.lottie||t.lottieUrl||t.lottie,a=i.slotSize||t.slotSize||{width:60,height:60},o=Array.isArray(i.effects)?i.effects:Array.isArray(t.effects)?t.effects:[],c=Array.isArray(i.imgs)?i.imgs:Array.isArray(t.imgs)?t.imgs:[],d=e.imageSlots&&e.imageSlots.length?e.imageSlots:c.map(p=>({slot:p.slot,width:p.width,height:p.height,radius:p.radius})),m={...e.imageUrls||{},...Object.fromEntries(c.filter(p=>p.url!==void 0&&p.url!==null).map(p=>[p.slot,p.url]))};return{giftUrl:s,giftRealSize:r,giftBodySize:r,assetType:n,assetUrl:s,lottie:l,lottieUrl:l,slotSize:a,effects:o,imgs:c,imageSlots:d,imageUrls:m}}const Et=16,Ie=24;function he(e,t,i){if(!Number.isFinite(t)||t<1)throw new Error("firework GPU capability maxInstancesPerBatch 无效");if(e>t)throw new Error(`${i} 粒子数量超过 GPU batch 上限:${t}`)}function St(e,t,i){e.set([i.birthTime,i.lifetime,i.x,i.y,i.vx,i.vy,i.ax,i.ay,i.scale,i.scaleSpeed,i.rotation,i.spin,1,1,1,1],t)}function ue(e,t,i){const s=new Float32Array(e.length*Ie);return e.forEach((r,n)=>{const l=t.get(r.cellKey);if(!l)throw new Error(`firework atlas 缺少 cell:${r.cellKey}`);const a=n*Ie;St(s,a,r),s.set([l.width*i,l.height*i,.5,.5,l.u0,l.v0,l.u1,l.v1],a+Et)}),s}function Mt(e,t){var a,o;const i=((a=e[0])==null?void 0:a.startMs)??1/0,s=((o=e.at(-1))==null?void 0:o.endMs)??-1/0;if(!Number.isFinite(i)||!Number.isFinite(s)||!(s>i))return[];const r=new Set([i,s]);for(const c of[...e,...t])c.startMs>i&&c.startMs<s&&r.add(c.startMs),c.endMs>i&&c.endMs<s&&r.add(c.endMs);const n=[...r].sort((c,d)=>c-d),l=[];for(let c=0;c<n.length-1;c+=1){const d=n[c],m=n[c+1];if(!(m>d))continue;const p=(u,w=!1)=>Ae(e,u,1,w)*Ae(t,u,1,w),v=p(d),y=p(m,!0),b=(d+m)*.5,h=Math.abs(p(b)-(v+y)*.5)>1e-6?4:m-d;for(let u=d;u<m;u+=h){const w=Math.min(m,u+h);l.push({startMs:u,endMs:w,from:p(u),to:p(w,!0),interpolation:"linear"})}}return l}function kt({effect:e,composition:t,layout:i,resolvedQualityScale:s,seed:r,atlas:n,atlasCells:l,maxInstancesPerBatch:a}){const o=yt({effect:e,composition:t,layout:i,resolvedQualityScale:s,seed:r,maxParticleCount:a*2,maxInstancesPerBatch:a});he(o.smoke.length,a,"firework smoke"),he(o.main.length,a,"firework main"),he(1,a,"firework flash");const c={birthTime:o.flash.birthTime,lifetime:o.flash.lifetime,x:o.flash.x,y:o.flash.y,vx:0,vy:0,ax:0,ay:0,scale:1,scaleSpeed:0,rotation:0,spin:0,cellKey:o.flash.cellKey},d={format:"sprite-v2",atlas:n,opacity:1,compositeLayer:"behind-media"};return Object.freeze({model:o,descriptors:Object.freeze([Object.freeze({...d,count:o.smoke.length,instances:ue(o.smoke,l,i.scale),fadeMode:"lifetime",envelope:{opacity:o.dismissEnvelope},zIndex:0,blend:"normal",label:"multi-gift-firework-smoke"}),Object.freeze({...d,count:o.main.length,instances:ue(o.main,l,i.scale),fadeMode:"lifetime",envelope:{opacity:o.dismissEnvelope},zIndex:1,blend:"additive",label:"multi-gift-firework-main"}),Object.freeze({...d,count:1,instances:ue([c],l,i.scale),fadeMode:"none",envelope:{opacity:Mt(o.flash.opacityEnvelope,o.dismissEnvelope),size:o.flash.sizeEnvelope},zIndex:2,blend:"additive",label:"multi-gift-firework-flash"})])})}const re=4,x=256;function vt(e,t,i){if(i)return i(e,t);if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(e,t);if(typeof document<"u"){const s=document.createElement("canvas");return s.width=e,s.height=t,s}throw new Error("当前环境无法生成 firework sprite atlas")}function Tt(e){const t=new Map;let i=0,s=0,r=0;for(const n of e.cells){const l=n.width+re*2,a=n.height+re*2;if(i+l>x&&(i=0,s+=r,r=0),s+a>x)throw new Error("firework atlas recipe exceeds 256x256");const o=i+re,c=s+re;t.set(n.key,Object.freeze({...n,x:o,y:c,u0:o/x,v0:c/x,u1:(o+n.width)/x,v1:(c+n.height)/x})),i+=l,r=Math.max(r,a)}return t}function Rt(e,t={}){const i=qe(e),s=Tt(i),r=vt(x,x,t.canvasFactory);r.width=x,r.height=x;const n=r.getContext("2d",{willReadFrequently:!0});if(!n)throw new Error("无法创建 firework atlas Canvas2D context");n.clearRect(0,0,x,x);for(const o of s.values())ct(n,o,o.x,o.y);const l=n.getImageData(0,0,x,x),a=new Uint8Array(l.data.length);for(let o=0;o<l.data.length;o+=4){const c=l.data[o+3];a[o+3]=c,c===0?(a[o]=0,a[o+1]=0,a[o+2]=0):(a[o]=Math.round(l.data[o]*c/255),a[o+1]=Math.round(l.data[o+1]*c/255),a[o+2]=Math.round(l.data[o+2]*c/255))}return Object.freeze({key:i.key,width:x,height:x,pixels:a,cells:s})}const Ne=8,Ce=10;function At(e){const t=new RegExp(`^${e}_(\\d+)$`);return(i,s)=>{var l,a;const r=Number(((l=t.exec(i.nm))==null?void 0:l[1])??Number.MAX_SAFE_INTEGER),n=Number(((a=t.exec(s.nm))==null?void 0:a[1])??Number.MAX_SAFE_INTEGER);return r-n}}function _e(e,t,i,s){return!e||!t||!i||!s?1:Math.min(i/e,s/t)}function Ot(e){return Number.isFinite(e==null?void 0:e.x)&&Number.isFinite(e==null?void 0:e.y)?{x:e.x,y:e.y}:null}function q(e){const t=new Error(e);return t.name="AbortError",t}function Pe(e){var i,s,r,n;const t=(i=e==null?void 0:e.capabilities)==null?void 0:i.particles;return(t==null?void 0:t.backend)==="unavailable"||!((s=t==null?void 0:t.formats)!=null&&s.includes("sprite-v2"))||((r=t==null?void 0:t.spriteAtlas)==null?void 0:r.source)!=="rgba8-premultiplied"||!((n=t==null?void 0:t.compositeLayers)!=null&&n.includes("behind-media"))||(t==null?void 0:t.batchEnvelope)!==!0||(t==null?void 0:t.atomicBatchGroup)!==!0||!Number.isFinite(t==null?void 0:t.maxInstancesPerBatch)||typeof(e==null?void 0:e.createParticleAtlas)!="function"?null:t}function Le(e){const t=typeof navigator<"u"?navigator:{};return{quality:e,deviceMemory:t.deviceMemory,hardwareConcurrency:t.hardwareConcurrency,userAgent:t.userAgent}}function Ft(e,t){if(!Number.isFinite(e))return t;let i=t;for(;i-e>Math.PI;)i-=Math.PI*2;for(;i-e<-Math.PI;)i+=Math.PI*2;return i}async function It(e,t){if(e&&typeof e=="object")return e;if(typeof e=="string"&&e.trim().startsWith("{"))try{return JSON.parse(e)}catch(s){throw new Error(`Lottie JSON 解析失败:${s.message||"格式错误"}`)}if(typeof e!="string"||!e.trim())throw new Error("未提供有效的 Lottie 轨迹配置");const i=await fetch(e,{signal:t});if(!i.ok)throw new Error(`Lottie 加载失败 (${i.status})`);return i.json()}function ze(e,t,i){var l;const s=(l=e==null?void 0:e.capabilities)==null?void 0:l.motionTrack,r=(s==null?void 0:s.gpuMediaTypes)||[];return(s==null?void 0:s.mode)==="gpu-table"&&t==="svga"&&r.includes(t)?"gpu-table":"cpu-reference"}function Nt(e){if(!e||typeof e.getRenderInfo!="function")return null;try{return e.getRenderInfo()}catch{return null}}function Ct(e,t){var s,r;const i=[];return e.forEach((n,l)=>{if(n.kind!=="svga")return;const a=t[l],o=Nt(a),c={slotId:n.id,giftId:(a==null?void 0:a.id)??n.id,svgaFramePath:(o==null?void 0:o.svgaFramePath)??(o==null?void 0:o.selectedPath)??(o==null?void 0:o.path)??null};o!=null&&o.parentMotionMode&&(c.parentMotionMode=o.parentMotionMode);for(const d of["backend","pathState","frameTableBytes","commandTableBytes","drawBatchMode","drawCompatibleInstanceCount","fallbackReasons"])(o==null?void 0:o[d])!=null&&(c[d]=o[d]);i.push(c)}),{svgaFramePath:((s=i.find(n=>n.svgaFramePath!=null))==null?void 0:s.svgaFramePath)??null,parentMotionMode:((r=i.find(n=>n.parentMotionMode!=null))==null?void 0:r.parentMotionMode)??null,svgaFramePaths:i}}class _t{constructor(t,i,s,r,n){this.id=t,this.scope=i,this.completion=s,this.onStop=r,this.diagnosticsProvider=n}get diagnostics(){return this.diagnosticsProvider()}get state(){return this.scope.state}pause(){this.scope.pause()}resume(){this.scope.resume()}seek(t){this.scope.seek(t)}stop(){this.onStop()}destroy(){this.onStop()}}class He{constructor(t,i={}){this.host=t,this.options=i,this.sampleRate=Math.max(30,Math.min(120,i.sampleRate||60)),this.onStateChange=i.onStateChange||(()=>{}),this.onRenderFrame=i.onRenderFrame||(()=>{}),this.disabledSlotIds=new Set(i.disabledSlotIds||[]),this.playConfig=null,this.composition=null,this.assetLease=null,this.imageLeases=new Map,this.activePlayback=null,this.pendingScope=null,this.playEpoch=0,this.playIntentEpoch=0,this.preloadController=null,this.preloadEpoch=0,this._preloadDiagnostics=null,this.fireworkAtlas=null,this.fireworkAtlasCells=null,this.fireworkAtlasRecipeKey=null,this.fireworkQualityScale=1,this.particleCapabilityWarningEmitted=!1,this.destroyed=!1}get capabilities(){return this.host.capabilities}get preloadDiagnostics(){return this._preloadDiagnostics}async preload(t=this.options.playConfig,i=!1){var v,y,b;if(this.assertAlive(),!t)throw new Error("未提供 playConfig");this.cancelPlayback(!i),this.releaseLeases(),this.playConfig=null,this.composition=null,this._preloadDiagnostics=null;const s=Ze({...this.options,playConfig:t});if(s.assetType!=="svga"&&s.assetType!=="image")throw new Error(`GiftStage 插件不支持的礼物类型:${s.assetType}`);this.emitStateChange({status:"loading",message:"正在预加载 Lottie 与共享礼物资源"});const r=new AbortController;(v=this.preloadController)==null||v.abort(),this.preloadController=r;const n=++this.preloadEpoch;let l=null,a=new Map,o=null,c=null,d=null,m=1,p=!1;try{const g=await It(s.lottieUrl,r.signal);this.assertCurrentPreload(r,n);const h=Pe(this.host),u=We(g,{effects:s.effects,fireworkEnvironment:Le("auto"),maxInstancesPerBatch:Math.min(Z,(h==null?void 0:h.maxInstancesPerBatch)??Z)});u.length&&this.emitStateChange({validationFindings:u});const w=u.find(f=>f.code==="LOTTIE_TARGET_MARKER_MISSING");if(w)throw this.emitStateChange({status:"fallback",reason:w.code,message:"多礼物编排缺少 target_flight,交由宿主降级普通单礼物"}),new ne(w.code,"Lottie 中缺少有效的 target_flight marker",u,!0);const M=u.filter(f=>f.scope==="composition"&&f.severity==="error");if(M.length)throw new ne(M[0].code,`Lottie 合成校验失败:${M.map(f=>`${f.code}@${f.where}`).join(", ")}`,u);const E=new Set(u.filter(f=>f.scope==="slot"&&f.severity==="error"&&f.layer).map(f=>f.layer)),O=new Set(u.filter(f=>f.scope==="effect"&&Number.isInteger(f.effectIndex)).map(f=>f.effectIndex)),_=new Map((g.layers||[]).map(f=>[f.nm,f])),k=(g.layers||[]).filter(f=>/^slot_\d+$/.test(f.nm)&&f.ks&&!E.has(f.nm)).sort(At("slot"));if(!k.length)throw new ne("LOTTIE_SLOT_MISSING","Lottie 中没有可播放的 slot_N 礼物插槽图层",u);const T=oe(g.markers,"target_flight"),R=s.effects.filter((f,A)=>!O.has(A));l=await this.host.preload(s.assetType,s.assetUrl,r.signal),this.assertCurrentPreload(r,n);for(const f of s.imageSlots){const A=Fe(s.imageUrls[f.slot]);if(!A||!((y=_.get(f.slot))!=null&&y.ks)||E.has(f.slot))continue;const C=await this.host.preload("image",A,r.signal);(b=a.get(f.slot))==null||b.release(),a.set(f.slot,C),this.assertCurrentPreload(r,n)}const S={startFrame:T.tm,endFrame:T.tm+T.dr},N=new Map(k.map(f=>{var W,X;const A=((X=(W=f.ks)==null?void 0:W.s)==null?void 0:X.a)===1&&Array.isArray(f.ks.s.k)?f.ks.s.k.filter($=>Number.isFinite($==null?void 0:$.t)&&$.t>=S.startFrame&&$.t<=S.endFrame).sort(($,se)=>$.t-se.t):[],C=A[0],D=A[A.length-1];let G=Number.isFinite(C==null?void 0:C.t)?C.t:S.startFrame,Y=Number.isFinite(D==null?void 0:D.t)?D.t:S.endFrame;return G=Math.max(S.startFrame,Math.min(S.endFrame,G)),Y=Math.max(S.startFrame,Math.min(S.endFrame,Y)),Y>G||(G=S.startFrame,Y=S.endFrame),[f.nm,{start:G,end:Y}]})),z={lottie:g,width:g.w,height:g.h,frameRate:g.fr,inFrame:g.ip,outFrame:g.op,durationMs:(g.op-g.ip)/g.fr*1e3,layers:_,timeline:k,targetFlight:S,flightWindows:N},P=R.find(f=>f.type==="firework");if(P&&h){m=$e(Le(P.quality??"auto"));const f=Rt(P);if(f.width>h.spriteAtlas.maxSize||f.height>h.spriteAtlas.maxSize)throw new Error("firework atlas 超过当前 GPU capability");o=await this.host.createParticleAtlas({width:f.width,height:f.height,pixels:f.pixels,colorSpace:"srgb",alphaMode:"premultiplied",filter:"linear",label:`multi-gift-firework:${f.key}`}),c=f.cells,d=f.key,this.assertCurrentPreload(r,n)}this.assertCurrentPreload(r,n),this.playConfig={...s,effects:R},this.assetLease=l,this.imageLeases=a,this.composition=z,this.fireworkAtlas=o,this.fireworkAtlasCells=c,this.fireworkAtlasRecipeKey=d,this.fireworkQualityScale=m,p=!0;const j=ze(this.host,s.assetType,l.metadata);this._preloadDiagnostics=Object.freeze({parentMotionMode:j,motionMode:j}),this.emitStateChange({status:"ready",message:`${k.length} 个礼物轨道已就绪`,slotCount:k.length,backend:this.host.capabilities.backend,...this._preloadDiagnostics})}catch(g){if(!p){l==null||l.release();for(const h of a.values())h.release();o==null||o.destroy()}throw(g==null?void 0:g.name)==="AbortError"||this.destroyed||this.preloadEpoch!==n||r.signal.aborted?q("多礼物资源预加载已取消"):g}finally{this.preloadController===r&&(this.preloadController=null)}}async play(t={}){var v,y,b;if(this.assertAlive(),!Object.prototype.hasOwnProperty.call(t,"target"))throw new Error("play() 必须显式传入 target,值可为 null 或 undefined");const i=++this.playIntentEpoch;if(!this.composition&&(await this.preload(void 0,!0),this.playIntentEpoch!==i)||(this.assertAlive(),this.playIntentEpoch!==i))throw q("多礼物播放已取消");this.cancelPlayback(!1);const s=this.composition,r=this.playConfig,n=Ot(t.target),l=this.host.getViewport(),a=s.width>0?l.width/s.width:1,o=0,c=(l.height-s.height*a)*.5,d=this.host.createPlaybackScope(`multi-gift-${Date.now()}`),m=this.playEpoch;this.pendingScope={scope:d,playEpoch:m};const p=s.timeline.map((g,h)=>{var u,w,M,E,O,_,k,T;return{id:g.nm,layer:g,kind:r.assetType,source:r.assetUrl,width:this.assetLease.metadata.width*_e((u=r.giftBodySize)==null?void 0:u.width,(w=r.giftBodySize)==null?void 0:w.height,(M=r.slotSize)==null?void 0:M.width,(E=r.slotSize)==null?void 0:E.height)*a,height:this.assetLease.metadata.height*_e((O=r.giftBodySize)==null?void 0:O.width,(_=r.giftBodySize)==null?void 0:_.height,(k=r.slotSize)==null?void 0:k.width,(T=r.slotSize)==null?void 0:T.height)*a,zIndex:Ce+h,redirect:!0}});for(const g of r.imageSlots){const h=this.imageLeases.get(g.slot),u=s.layers.get(g.slot);!h||!(u!=null&&u.ks)||p.push({id:g.slot,layer:u,kind:"image",source:Fe(r.imageUrls[g.slot]),width:g.width*a,height:g.height*a,zIndex:Ce+p.length,redirect:!1})}try{const g=await Promise.all(p.map(f=>d.addGift({type:f.kind,source:f.source,x:0,y:0,width:f.width,height:f.height,zIndex:f.zIndex,opacity:0,loop:f.kind==="svga"?0:void 0,mute:f.kind==="svga"?!0:void 0,clearsAfterStop:!1})));this.assertCurrentPlay(d,m);const h=this.compileMotionTrack(p,n,{scale:a,offsetX:o,offsetY:c}),u=d.createMotionTrack(h);g.forEach((f,A)=>d.bindMotion(f,u,A));const w=()=>{var C,D;const f=Ct(p,g),A=f.parentMotionMode??((C=this._preloadDiagnostics)==null?void 0:C.parentMotionMode)??ze(this.host,r.assetType,(D=this.assetLease)==null?void 0:D.metadata);return Object.freeze({...f,parentMotionMode:A,motionMode:A})},M=w(),E=(v=r.effects)==null?void 0:v.find(f=>f.type==="firework"),O=Pe(this.host);if(E&&O&&this.fireworkAtlas&&this.fireworkAtlasCells&&typeof d.createParticleBatchGroup=="function")try{const f=kt({effect:E,composition:s,layout:{scale:a,offsetX:o,offsetY:c},resolvedQualityScale:this.fireworkQualityScale,seed:E.seed,atlas:this.fireworkAtlas,atlasCells:this.fireworkAtlasCells,maxInstancesPerBatch:O.maxInstancesPerBatch});d.createParticleBatchGroup(f.descriptors)}catch(f){this.emitStateChange({effectWarning:`firework 编译失败,已跳过:${f instanceof Error?f.message:String(f)}`})}else E&&(this.particleCapabilityWarningEmitted||(this.particleCapabilityWarningEmitted=!0,this.emitStateChange({effectWarning:"当前核心缺少 sprite-v2/atlas/envelope/atomic group 能力,已跳过 firework;未创建 Canvas2D 后端"})));let _;const k=new Promise(f=>{_=f});let T=!1,R;const S=f=>{T||(T=!0,_({status:f}))},N=()=>{d.state!=="destroyed"&&d.destroy(),this.activePlayback===R&&(this.activePlayback=null),T||(this.emitStateChange({status:"stopped",message:"播放已停止"}),S("stopped"))};R=new _t(d.id,d,k,N,w),this.assertCurrentPlay(d,m),this.pendingScope=null,this.activePlayback=R;let z=0,P=0,j=!1;return d.onFrame(({nowMs:f,deltaMs:A})=>{const C=Math.min(s.outFrame,s.inFrame+f*s.frameRate/1e3);this.emitRenderFrame(C),j||(j=!0,this.emitStateChange({status:"playing",diagnosticsRefreshed:!0,...R.diagnostics})),z+=A,P+=1,z>=500&&(this.emitStateChange({fps:Math.round(P*1e3/z)}),z=0,P=0)}),d.onFinish(()=>{T||(this.activePlayback===R&&(this.activePlayback=null),d.destroy(),this.emitStateChange({status:"finished",message:"本轮编排播放完成"}),S("finished"))}),d.start({durationMs:s.durationMs}),this.emitStateChange({status:"playing",message:`${g.length} 个实例由 GiftStage 统一时钟驱动`,...M}),R}catch(g){throw((y=this.pendingScope)==null?void 0:y.scope)===d&&(this.pendingScope=null),((b=this.activePlayback)==null?void 0:b.scope)===d?this.activePlayback.stop():d.state!=="destroyed"&&d.destroy(),(g==null?void 0:g.name)==="AbortError"||this.destroyed||this.playEpoch!==m?q("多礼物播放已取消"):g}}compileMotionTrack(t,i,s){const r=this.composition,n=1e3/this.sampleRate,l=Math.ceil(r.durationMs/n)+1,a=new Float32Array(t.length*l*Ne);return t.forEach((o,c)=>{let d=Number.NaN;for(let m=0;m<l;m+=1){const p=Math.min(r.durationMs,m*n),v=r.inFrame+p*r.frameRate/1e3,y=this.evaluateLayer(o,v,i,s);y.rotation=Ft(d,y.rotation),d=y.rotation;const b=(c*l+m)*Ne;a[b]=y.x,a[b+1]=y.y,a[b+2]=y.scaleX,a[b+3]=y.scaleY,a[b+4]=y.rotation,a[b+5]=y.opacity,a[b+6]=y.visible?1:0,a[b+7]=m+1<l&&y.interpolateToNext?1:0}}),{trackCount:t.length,sampleCount:l,sampleIntervalMs:n,durationMs:r.durationMs,samples:a,label:"lottie-multi-gift"}}evaluateLayer(t,i,s,r){const n=t.layer;let[l,a]=B(n.ks.p,i,[0,0,0]);const[o,c]=B(n.ks.s,i,[100,100,100]),d=n.ks.r??n.ks.rz,[m]=B(d,i,[0]),[p]=B(n.ks.o,i,[100]),v=i>=n.ip&&i<n.op&&p>0&&!this.disabledSlotIds.has(t.id);let y=l*r.scale+r.offsetX,b=a*r.scale+r.offsetY;if(t.redirect){const h=this.composition.flightWindows.get(n.nm)||this.composition.targetFlight;if(i>=h.start){const[u,w]=B(n.ks.p,h.start,[l,a,0]),M=u*r.scale+r.offsetX,E=w*r.scale+r.offsetY;if(s){const O=h.end-h.start,_=O>0?Math.max(0,Math.min(1,(i-h.start)/O)):0,k=Be(_);y=M+(s.x-M)*k,b=E+(s.y-E)*k}else y=M,b=E}}const g=[n.ks.p,n.ks.s,d,n.ks.o].some(h=>{if((h==null?void 0:h.a)!==1)return!1;const u=h.k||[];return u.some((w,M)=>{const E=u[M+1];return E&&i>=w.t&&i<E.t&&w.h===1})});return{x:y,y:b,scaleX:o/100,scaleY:c/100,rotation:m*Math.PI/180,opacity:Math.max(0,Math.min(1,p/100)),visible:v,interpolateToNext:!g}}setDisabledSlots(t=[]){this.disabledSlotIds=new Set(t)}stop(){this.cancelPlayback(!0)}cancelPlayback(t){t&&(this.playIntentEpoch+=1),this.playEpoch+=1;const i=this.pendingScope;this.pendingScope=null,i&&i.scope.state!=="destroyed"&&i.scope.destroy();const s=this.activePlayback;this.activePlayback=null,s==null||s.stop()}destroy(){var t;this.destroyed||(this.destroyed=!0,this.preloadEpoch+=1,(t=this.preloadController)==null||t.abort(),this.preloadController=null,this.stop(),this.releaseLeases(),this.composition=null,this._preloadDiagnostics=null)}releaseLeases(){var t,i;(t=this.assetLease)==null||t.release(),this.assetLease=null;for(const s of this.imageLeases.values())s.release();this.imageLeases.clear(),(i=this.fireworkAtlas)==null||i.destroy(),this.fireworkAtlas=null,this.fireworkAtlasCells=null,this.fireworkAtlasRecipeKey=null}assertAlive(){if(this.destroyed)throw new Error("GiftStage multi-gift plugin is destroyed")}emitStateChange(t){try{this.onStateChange(t)}catch{}}emitRenderFrame(t){try{this.onRenderFrame(t)}catch{}}assertCurrentPlay(t,i){var s;if(this.destroyed||this.playEpoch!==i||((s=this.pendingScope)==null?void 0:s.scope)!==t||t.state==="destroyed")throw q("多礼物播放已取消")}assertCurrentPreload(t,i){if(this.destroyed||t.signal.aborted||this.preloadEpoch!==i||this.preloadController!==t)throw q("多礼物资源预加载已取消")}}function Qe(e={}){return{name:"giftstage-plugin-multi-gift",apiVersion:1,setup(t){return new He(t,e)}}}function H(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function xe(e,t){let i;try{i=JSON.parse(e)}catch{throw new Error(`${t}不是合法 JSON`)}if(!H(i))throw new Error(`${t}必须是 JSON 对象`);return i}function et(e,t){if(!H(e)||!Number.isFinite(e.width)||e.width<=0||!Number.isFinite(e.height)||e.height<=0)throw new Error(`${t}必须包含大于 0 的 width 和 height`);return{width:e.width,height:e.height}}function Pt(e){if(e===void 0)return[];if(!Array.isArray(e))throw new Error("multiGiftEffect.imgs 必须是数组");return e.map((t,i)=>{if(!H(t)||typeof t.slot!="string"||!/^img_slot_\d+$/.test(t.slot))throw new Error(`multiGiftEffect.imgs[${i}].slot 必须是 img_slot_xx`);if(et(t,`multiGiftEffect.imgs[${i}]`),t.radius!==void 0&&(!Number.isFinite(t.radius)||t.radius<0))throw new Error(`multiGiftEffect.imgs[${i}].radius 必须是大于等于 0 的数字`);return{...t}})}function De(e){if(!H(e)||!Array.isArray(e.layers))throw new Error("multiGiftEffect.lottie 必须包含 layers 数组");let t=0;for(const i of e.layers){const s=/^slot_(\d+)$/.exec((i==null?void 0:i.nm)||"");s&&(t=Math.max(t,Number(s[1])))}if(!t)throw new Error("multiGiftEffect.lottie 中至少需要一个 slot_xx 礼物插槽");return t}function Lt(e){const t=typeof e=="string"?xe(e,"本地特效配置"):e;if(!H(t))throw new Error("本地特效配置必须是 JSON 对象");if(!Object.prototype.hasOwnProperty.call(t,"lottie"))throw Array.isArray(t.layers)?new Error("请上传 multiGiftEffect 配置,不能直接上传纯 Lottie JSON"):new Error("multiGiftEffect.lottie 不能为空");let i,s;if(H(t.lottie))i=t.lottie;else if(typeof t.lottie=="string"&&t.lottie.trim()){const l=t.lottie.trim();l.startsWith("{")?i=xe(l,"multiGiftEffect.lottie"):s=l}else throw new Error("multiGiftEffect.lottie 必须是 Lottie JSON 对象、JSON 字符串或 URL");const r=et(t.slotSize,"multiGiftEffect.slotSize"),n=t.effects===void 0?[]:t.effects;if(!Array.isArray(n))throw new Error("multiGiftEffect.effects 必须是数组");return{lottieJson:i,lottieUrl:s,slotSize:r,effects:n.map(l=>({...l})),imgs:Pt(t.imgs)}}async function zt(e,t=fetch){if(e.lottieJson)return{lottieJson:e.lottieJson,slotCount:De(e.lottieJson)};let i;try{i=await t(e.lottieUrl)}catch(r){throw new Error(`无法加载 lottie URL:${r.message||"网络错误"}`)}if(!i.ok)throw new Error(`无法加载 lottie URL(${i.status})`);let s;try{s=await i.json()}catch{throw new Error("lottie URL 返回的内容不是合法 JSON")}return{lottieJson:s,slotCount:De(s)}}exports.GiftStageMultiGiftPluginApi=He;exports.MultiGiftValidationError=ne;exports.bezierEase=Ke;exports.createGiftStageMultiGiftPlugin=Qe;exports.default=Qe;exports.easeInOutCubic=at;exports.easeOutCubic=Be;exports.findMarker=oe;exports.findUnsupportedCapabilities=rt;exports.inspectLocalLottie=zt;exports.normalizePlayConfig=Ze;exports.parseLocalMultiGiftEffect=Lt;exports.spatialBezierPoint=ot;exports.validateMultiGiftComposition=We;exports.valueAt=B;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});require("@taole/giftstage");const be=.42,Z=8192,ge="LOTTIE_EFFECT_PARTICLE_CAPACITY_EXCEEDED",Te=Object.freeze([Object.freeze({batch:"main",rate:105,phase:"launch"}),Object.freeze({batch:"main",rate:78,phase:"launch"}),Object.freeze({batch:"main",rate:48,phase:"launch"}),Object.freeze({batch:"smoke",rate:18,phase:"launch"}),Object.freeze({batch:"main",rate:390,phase:"burst"}),Object.freeze({batch:"main",rate:275,phase:"burst"}),Object.freeze({batch:"main",rate:145,phase:"burst"}),Object.freeze({batch:"main",rate:265,phase:"secondary"}),Object.freeze({batch:"main",rate:175,phase:"secondary"}),Object.freeze({batch:"main",rate:48,phase:"secondary"})]);function it(e,t,i){return Math.max(t,Math.min(i,e))}function $e(e={}){const t=e.quality??"auto";if(typeof t=="number")return it(t,.25,1.25);if(t==="low")return .46;if(t==="medium")return .72;if(t==="high")return 1;const i=Number.isFinite(e.deviceMemory)?e.deviceMemory:8,r=Number.isFinite(e.hardwareConcurrency)?e.hardwareConcurrency:8;return i<=4||r<=4?.52:/Android|iPhone|iPad|iPod/i.test(e.userAgent||"")?.72:1}function Ge({launchDuration:e,density:t=1,resolvedQualityScale:i=1}){if(!Number.isFinite(e)||e<0||!Number.isFinite(t)||t<0||!Number.isFinite(i)||i<0)throw new Error("firework 粒子数量规划参数必须是有限非负数");const r=t*i;if(!Number.isFinite(r))throw new Error("firework 粒子数量规划结果不是有限数值");const s={launch:e*.84,burst:.11,secondary:.14},n=Te.map(({rate:o,phase:l})=>Math.max(1,Math.round(o*s[l]*r)));let c=0,a=0;return n.forEach((o,l)=>{Te[l].batch==="smoke"?c+=o:a+=o}),Object.freeze({emitterCounts:Object.freeze(n),smokeCount:c,mainCount:a,totalCount:c+a,flashCount:1})}function je(e,t=Z){if(!Number.isSafeInteger(e==null?void 0:e.smokeCount)||e.smokeCount<0||!Number.isSafeInteger(e==null?void 0:e.mainCount)||e.mainCount<0)throw new Error("firework smoke/main 粒子数量必须是非负安全整数");if(!Number.isSafeInteger(t)||t<1)throw new Error("firework maxInstancesPerBatch 必须是正安全整数");if(e.smokeCount>t||e.mainCount>t){const i=new RangeError(`firework 粒子批次超过上限 ${t}(smoke=${e.smokeCount}, main=${e.mainCount})`);throw i.code=ge,i.counts=e,i.maxInstancesPerBatch=t,i}return e}function Ye({frameRate:e,dismissFrame:t,durationSeconds:i=be}){if(!Number.isFinite(e)||!(e>0)||!Number.isFinite(t)||!Number.isFinite(i)||!(i>0))throw new Error("firework dismissDuration 必须生成有限且严格递增的毫秒区间");const r=t/e,s=r*1e3,n=(r+i)*1e3;if(!Number.isFinite(s)||!Number.isFinite(n)||!(n>s))throw new Error("firework dismissDuration 必须生成有限且严格递增的毫秒区间");return Object.freeze({durationSeconds:i,startSeconds:r,startMs:s,endMs:n})}const Re=150,Ae=new WeakMap;function ie(e,t){return Array.isArray(e)?e:e!=null?[e]:Array.isArray(t)?t:[t]}function fe(e,t,i){const r=e==null?void 0:e[t];if(!r)return null;if(Array.isArray(r))return{x:r[0],y:r[1]??r[0]};if(typeof r=="object"){const s=a=>{const o=r[a];return o==null?null:Array.isArray(o)?o[i]??o[0]:o},n=s("x"),c=s("y");return n==null||c==null?null:{x:n,y:c}}return null}function rt(e,t,i){const r=1-e;return 3*r*r*e*t+3*r*e*e*i+e*e*e}function st(e,t,i){const r=1-e;return 3*r*r*e*t+3*r*e*e*i+e*e*e}class ae extends Error{constructor(t,i,r=[],s=!1){super(i),this.name="MultiGiftValidationError",this.code=t,this.findings=r,this.recoverable=s}}function F(e,t,i={}){return{code:e,severity:i.severity||"error",scope:i.scope||"slot",where:t,...i.layer?{layer:i.layer}:{},...Number.isInteger(i.effectIndex)?{effectIndex:i.effectIndex}:{}}}function x(e,t){e.some(i=>i.code===t.code&&i.where===t.where)||e.push(t)}function re(e){return!e||typeof e!="object"?[]:e.a===1?Array.isArray(e.k)?e.k.flatMap(t=>[t==null?void 0:t.s,t==null?void 0:t.e]).filter(t=>t!==void 0):[]:e.k===void 0?[]:[e.k]}function B(e){const t=Array.isArray(e)?e:[e];return t.length>0&&t.every(Number.isFinite)?t:null}function We(e,t=new Set){return!e||typeof e!="object"||t.has(e)?!1:(t.add(e),typeof e.x=="string"?!0:Object.values(e).some(i=>We(i,t)))}function q(e,t,i,r,s){if(e==null)return;const n=()=>x(i,F("LOTTIE_INVALID_KEYFRAME",t,{layer:r}));if(typeof e!="object"||e.k===void 0){n();return}if(typeof e.x=="string"&&x(i,F("LOTTIE_UNSUPPORTED_TRANSFORM",`${t}.x`,{layer:r})),e.a!==1){const o=B(e.k);(!o||!s.includes(o.length))&&n();return}if(!Array.isArray(e.k)||e.k.length===0){n();return}let c=-1/0,a=null;for(let o=0;o<e.k.length;o+=1){const l=e.k[o];if(!l||!Number.isFinite(l.t)||l.t<c){n();return}c=l.t;const d=[l.s,l.e].filter(m=>m!==void 0);if(l.s===void 0||d.length===0){n();return}for(const m of d){const g=B(m);if(!g||!s.includes(g.length)){n();return}if(a==null&&(a=g.length),a!==g.length){n();return}}}}function pe(e){var n,c,a,o,l,d;const t=[],i=e.nm||`ind_${e.ind}`,r={layer:i};e.parent!==void 0&&t.push(F("LOTTIE_UNSUPPORTED_PARENT",i,r)),e.ddd===1&&t.push(F("LOTTIE_UNSUPPORTED_3D",i,r));const s=(n=e.ks)==null?void 0:n.p;return s&&(s.s===!0||s.x!==void 0||s.y!==void 0)&&t.push(F("LOTTIE_UNSUPPORTED_SPLIT_POSITION",i,r)),(((c=e.ks)==null?void 0:c.rx)!==void 0||((a=e.ks)==null?void 0:a.ry)!==void 0||((o=e.ks)==null?void 0:o.or)!==void 0||((l=e.ks)==null?void 0:l.sk)!==void 0||((d=e.ks)==null?void 0:d.sa)!==void 0||e.ao===1||e.sr!==void 0&&e.sr!==1||e.st!==void 0&&e.st!==0||e.tm!==void 0||e.bm!==void 0&&e.bm!==0||e.tt!==void 0||e.td!==void 0||e.hasMask===!0||Array.isArray(e.masksProperties)&&e.masksProperties.length>0||Array.isArray(e.ef)&&e.ef.length>0||We(e))&&t.push(F("LOTTIE_UNSUPPORTED_TRANSFORM",i,r)),(s==null?void 0:s.a)===1&&Array.isArray(s.k)&&s.k.forEach((m,g)=>{var p;const v=(m==null?void 0:m.to)!==void 0,b=(m==null?void 0:m.ti)!==void 0;if(!v&&!b)return;const w=m==null?void 0:m.s,k=(m==null?void 0:m.e)??((p=s.k[g+1])==null?void 0:p.s),f=Array.isArray(w)?w.length:-1,h=M=>Array.isArray(M)&&M.length===f&&M.every(Number.isFinite);(!h(w)||!h(k)||!h(m.to)||!h(m.ti))&&t.push(F("LOTTIE_INVALID_KEYFRAME",`${i}.ks.p[${g}]`,r))}),t}function Ke(e,t,i){let r=0,s=1;for(let c=0;c<32;c+=1){const a=(r+s)/2;rt(a,t.x,i.x)<e?r=a:s=a}const n=(r+s)/2;return st(n,t.y,i.y)}function nt(e){return((e==null?void 0:e.layers)||[]).flatMap(pe)}function Xe(e,t={}){var d,m,g,v,b,w,k;const i=[],r=Array.isArray(e==null?void 0:e.layers)?e.layers:[];(!Number.isFinite(e==null?void 0:e.w)||e.w<=0||!Number.isFinite(e==null?void 0:e.h)||e.h<=0||!Number.isFinite(e==null?void 0:e.fr)||e.fr<=0||!Number.isFinite(e==null?void 0:e.ip)||!Number.isFinite(e==null?void 0:e.op)||e.op<=e.ip)&&i.push(F("LOTTIE_INVALID_COMPOSITION","composition",{scope:"composition"}));const s=/^(slot|img_slot)_(\d+)$/,n=r.filter(f=>s.test((f==null?void 0:f.nm)||""));n.filter(f=>/^slot_\d+$/.test(f.nm)).length===0&&i.push(F("LOTTIE_SLOT_MISSING","layers",{scope:"composition"}));for(const f of["slot","img_slot"]){const h=n.filter(I=>I.nm.startsWith(`${f}_`)),p=new Set,M=[];for(const I of h)p.has(I.nm)&&x(i,F("LOTTIE_SLOT_DUPLICATED",I.nm,{scope:"composition"})),p.add(I.nm),M.push(Number((d=s.exec(I.nm))==null?void 0:d[2]));Array.from(new Set(M)).sort((I,C)=>I-C).some((I,C)=>I!==C+1)&&i.push(F("LOTTIE_SLOT_INDEX_GAP",f,{scope:"composition"}))}for(const f of n){const h=f.nm;for(const S of pe(f))x(i,S);f.ty!==3&&x(i,F("LOTTIE_UNSUPPORTED_LAYER_TYPE",h,{layer:h})),(!Number.isFinite(f.ip)||!Number.isFinite(f.op)||f.op<=f.ip)&&x(i,F("LOTTIE_INVALID_KEYFRAME",`${h}.ip/op`,{layer:h}));const p=f.ks||{};q(p.p,`${h}.ks.p`,i,h,[2,3]),q(p.s,`${h}.ks.s`,i,h,[2,3]),q(p.r,`${h}.ks.r`,i,h,[1]),q(p.rz,`${h}.ks.rz`,i,h,[1]),q(p.o,`${h}.ks.o`,i,h,[1]),p.r!==void 0&&p.rz!==void 0&&x(i,F("LOTTIE_UNSUPPORTED_TRANSFORM",`${h}.ks.r/rz`,{layer:h}));const M=p.a,y=re(M);((M==null?void 0:M.a)===1||y.some(S=>{const R=B(S);return!R||R.some(O=>O!==0)}))&&x(i,F("LOTTIE_UNSUPPORTED_ANCHOR",`${h}.ks.a`,{layer:h})),re(p.p).some(S=>{const R=B(S);return!!R&&R.length>2&&R[2]!==0})&&x(i,F("LOTTIE_UNSUPPORTED_3D",`${h}.ks.p`,{layer:h})),re(p.s).some(S=>{const R=B(S);return!!R&&(R[0]<0||R[1]<0||R.length>2&&R[2]!==100)})&&x(i,F("LOTTIE_UNSUPPORTED_TRANSFORM",`${h}.ks.s`,{layer:h}))}const a=ce(e==null?void 0:e.markers,"target_flight");(!a||!Number.isFinite(a.tm)||!Number.isFinite(a.dr)||a.dr<=0||a.tm<e.ip||a.tm+a.dr>e.op)&&i.push(F("LOTTIE_TARGET_MARKER_MISSING","markers.target_flight",{scope:"composition",severity:"warning"}));const o=new Map(((e==null?void 0:e.markers)||[]).map(f=>[f==null?void 0:f.cm,f])),l=new Map(r.map(f=>[f==null?void 0:f.nm,f]));for(const[f,h]of(t.effects||[]).entries()){if((h==null?void 0:h.type)!=="firework")continue;for(const O of["launch","burst"]){const A=(m=h.anchors)==null?void 0:m[O],T=l.get(A);if(!A||!((g=T==null?void 0:T.ks)!=null&&g.p)){x(i,F("LOTTIE_EFFECT_ANCHOR_MISSING",`effects[${f}].anchors.${O}`,{scope:"effect",severity:"warning",effectIndex:f}));continue}const L=pe(T),_=[];q(T.ks.p,`${A}.ks.p`,_,A,[2,3]),re(T.ks.p).some(E=>{const u=B(E);return!!u&&u.length>2&&u[2]!==0})&&L.push(F("LOTTIE_UNSUPPORTED_3D",`${A}.ks.p`,{layer:A}));for(const[E,u]of[["s",[100,100,100]],["r",[0]],["rz",[0]],["o",[100]],["a",[0,0,0]]]){const N=T.ks[E];if(N==null)continue;const z=re(N);N.a!==1&&z.length>0&&z.every(W=>{const G=B(W);return!!G&&G.length===u.length&&G.every((X,V)=>X===u[V])})||L.push(F("LOTTIE_UNSUPPORTED_TRANSFORM",`${A}.ks.${E}`,{layer:A}))}T.ty!==3&&L.push(F("LOTTIE_UNSUPPORTED_LAYER_TYPE",A,{layer:A}));for(const E of[...L,..._])x(i,F(E.code,E.where,{scope:"effect",severity:"warning",effectIndex:f,layer:A}))}for(const O of["launch","burst","dismiss"]){const A=(v=h.markers)==null?void 0:v[O],T=o.get(A);!A||!T?x(i,F("LOTTIE_EFFECT_MARKER_MISSING",`effects[${f}].markers.${O}`,{scope:"effect",severity:"warning",effectIndex:f})):(!Number.isFinite(T.tm)||!Number.isFinite(T.dr)||T.dr<0||O==="launch"&&T.dr<=0)&&x(i,F("LOTTIE_EFFECT_MARKER_INVALID",`effects[${f}].markers.${O}`,{scope:"effect",severity:"warning",effectIndex:f}))}const p=o.get((b=h.markers)==null?void 0:b.launch),M=o.get((w=h.markers)==null?void 0:w.burst),y=o.get((k=h.markers)==null?void 0:k.dismiss),I=h.dismissDuration??be,C=Number.isFinite(I)&&I>0;let S=null,R=C;if(C&&y&&Number.isFinite(y.tm)&&Number.isFinite(e.fr)&&e.fr>0)try{S=Ye({frameRate:e.fr,dismissFrame:y.tm,durationSeconds:I})}catch{R=!1}if(R||x(i,F("LOTTIE_EFFECT_DISMISS_DURATION_INVALID",`effects[${f}].dismissDuration`,{scope:"effect",severity:"warning",effectIndex:f})),p&&Number.isFinite(p.dr)&&p.dr>0&&Number.isFinite(e.fr)&&e.fr>0)try{const O=t.fireworkEnvironment||{},A=$e({...O,quality:h.quality??O.quality??"auto"});je(Ge({launchDuration:p.dr/e.fr,density:h.density??1,resolvedQualityScale:A}),t.maxInstancesPerBatch??Z)}catch(O){x(i,F((O==null?void 0:O.code)===ge?ge:"LOTTIE_EFFECT_PARTICLE_CONFIG_INVALID",`effects[${f}]`,{scope:"effect",severity:"warning",effectIndex:f}))}p&&M&&y&&Number.isFinite(p.tm)&&Number.isFinite(M.tm)&&Number.isFinite(y.tm)&&Number.isFinite(e.fr)&&e.fr>0&&S&&!(p.tm/e.fr*1e3<=M.tm/e.fr*1e3&&M.tm/e.fr*1e3<S.endMs)&&x(i,F("LOTTIE_EFFECT_TIMING_INVALID",`effects[${f}].markers`,{scope:"effect",severity:"warning",effectIndex:f}))}return i}function Ve(e,t,i,r){const s=Math.max(e.length,t.length,i.length,r.length),n=[];let c=0,a=null;for(let o=0;o<Re;o+=1){const l=o/(Re-1),d=1-l,m=Array.from({length:s},(v,b)=>{const w=e[b]??0,k=t[b]??w,f=w+(i[b]??0),h=k+(r[b]??0);return d**3*w+3*d**2*l*f+3*d*l**2*h+l**3*k}),g=a?Math.sqrt(m.reduce((v,b,w)=>v+(b-a[w])**2,0)):0;c+=g,n.push({partialLength:g,point:m}),a=m}return{points:n,segmentLength:c}}function ot(e,t,i){let r=Ae.get(e);return r||(r=Ve(t,i,e.to,e.ti),Ae.set(e,r)),r}function Be(e,t){const i=Math.max(0,Math.min(1,e)),r=t.segmentLength*i;let s=0;for(let n=0;n<t.points.length;n+=1){const c=t.points[n];if(s+=c.partialLength,r===0||i===0||n===t.points.length-1)return c.point.slice();const a=t.points[n+1];if(r>=s&&r<s+a.partialLength){const o=(r-s)/a.partialLength;return c.point.map((l,d)=>l+(a.point[d]-l)*o)}}return t.points[t.points.length-1].point.slice()}function at(e,t,i,r,s){return Be(e,Ve(t,i,r,s))}function J(e,t,i){if(!e||e.a===0)return ie(e==null?void 0:e.k,i);const r=e.k,s=r.findIndex((v,b)=>{const w=r[b+1];return!w||t<w.t}),n=r[Math.max(s,0)],c=r[s+1];if(!c||t<=n.t||n.h===1)return ie(n.s,i);const a=ie(n.s,i),o=ie(n.e||c.s,a),l=Math.max(0,Math.min(1,(t-n.t)/(c.t-n.t))),d=fe(n,"o",0),m=fe(n,"i",0)||fe(c,"i",0),g=d&&m?Ke(l,d,m):l;return Array.isArray(n.to)&&Array.isArray(n.ti)?Be(g,ot(n,a,o)):a.map((v,b)=>v+((o[b]??v)-v)*g)}function Je(e){return 1-(1-e)**3}function ct(e){return e<.5?4*e*e*e:1-(-2*e+2)**3/2}function ce(e,t){return e==null?void 0:e.find(i=>i.cm===t)}const he=Math.PI*2,lt=Object.freeze({glow:[22,22],spark:[10,22],star:[24,24],smoke:[26,26],petal:[18,24],flash:[96,96]});function ft(e,{type:t,color:i,width:r,height:s},n=0,c=0){e.save(),e.translate(n,c);const a=r/2,o=s/2;if(t==="glow"||t==="smoke"||t==="flash"){const l=e.createRadialGradient(a,o,0,a,o,r/2);l.addColorStop(0,t==="smoke"?i:"#ffffff"),l.addColorStop(t==="flash"?.22:.3,i),l.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=l,e.fillRect(0,0,r,s)}else if(t==="spark"){const l=e.createLinearGradient(a,s,a,0);l.addColorStop(0,"rgba(255,255,255,0)"),l.addColorStop(.46,i),l.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=l,e.fillRect(0,0,r,s),e.fillStyle="#ffffff",e.beginPath(),e.arc(a,o*.72,5,0,he),e.fill()}else if(t==="star")e.strokeStyle=i,e.fillStyle="#ffffff",e.lineCap="round",e.lineWidth=2,e.beginPath(),e.moveTo(a,1),e.lineTo(a,s-1),e.moveTo(1,o),e.lineTo(r-1,o),e.moveTo(5,5),e.lineTo(r-5,s-5),e.moveTo(r-5,5),e.lineTo(5,s-5),e.stroke(),e.beginPath(),e.arc(a,o,4,0,he),e.fill();else if(t==="petal"){e.save(),e.translate(a,o),e.rotate(-.32),e.scale(.72,1);const l=e.createLinearGradient(0,-s/2,0,s/2);l.addColorStop(0,"#ffffff"),l.addColorStop(.42,i),l.addColorStop(1,"rgba(105, 0, 25, 0.5)"),e.fillStyle=l,e.beginPath(),e.ellipse(0,0,8,15,0,0,he),e.fill(),e.restore()}else throw e.restore(),new Error(`未知 firework texture 类型:${t}`);e.restore()}const K=Math.PI*2,ht=Object.freeze(["#ff385c","#ffad38","#ffe095"]),dt=20260808;function ut(e,t=0,i=1){return Math.max(t,Math.min(i,e))}function mt(e){let t=e>>>0;return()=>{t+=1831565813;let i=t;return i=Math.imul(i^i>>>15,i|1),i^=i+Math.imul(i^i>>>7,i|61),((i^i>>>14)>>>0)/4294967296}}function gt(e){const t=e??dt;if(!Number.isInteger(t)||t<0||t>4294967295)throw new Error("firework seed 必须是 0 到 4294967295 之间的整数");return t}function Oe(e,t,i=1,r=!1){if(!Number.isFinite(t))throw new Error("firework envelope 时间必须是有限毫秒值");if(!(e!=null&&e.length))return i;const s=r?t-1e-6:t;if(s<e[0].startMs)return e[0].from;let n=e[0].from;for(const c of e){if(s<c.startMs)return n;if(s<c.endMs){if(c.interpolation==="hold")return c.from;const a=(s-c.startMs)/(c.endMs-c.startMs);return c.from+(c.to-c.from)*a}n=c.to}return n}function pt(e,t,i,r,s){const n=1-s,c=n**3,a=3*n*n*s,o=3*n*s*s,l=s**3;return{x:c*e.x+a*t.x+o*i.x+l*r.x,y:c*e.y+a*t.y+o*i.y+l*r.y}}function de(e,t){var s;const i=e.markers||((s=e.lottie)==null?void 0:s.markers)||[],r=i instanceof Map?i.get(t):ce(i,t);if(!r)throw new Error(`Lottie 中缺少效果 marker:${t}`);return r}function Ie(e,t,i,r){var a,o;if(typeof e.resolveAnchor=="function"){const l=e.resolveAnchor(t,i);return{x:l.x*r.scale+r.offsetX,y:l.y*r.scale+r.offsetY}}const s=(a=e.layers)==null?void 0:a.get(t);if(!((o=s==null?void 0:s.ks)!=null&&o.p))throw new Error(`Lottie 中缺少效果锚点图层:${t}`);const[n,c]=J(s.ks.p,i,[0,0,0]);return{x:n*r.scale+r.offsetX,y:c*r.scale+r.offsetY}}function we(e,t){return`${e}:${String(t).trim().toLowerCase()}`}function qe(e){return Object.freeze(ht.map((t,i)=>{const r=e==null?void 0:e[i];return typeof r=="string"&&r.trim()?r.trim():t}))}function He(e={}){const t=qe(e.colors),i=[["glow","#ffffff"],["spark",t[1]],["glow",t[0]],["smoke","rgba(184, 184, 184, 0.24)"],["spark",t[0]],["star","#ffffff"],["glow",t[2]||t[1]],["petal",t[0]],["flash",t[0]]],r=[],s=new Set;for(const[n,c]of i){const a=we(n,c);if(s.has(a))continue;s.add(a);const[o,l]=lt[n];r.push(Object.freeze({key:a,type:n,color:c,width:o,height:l}))}return Object.freeze({key:JSON.stringify(r.map(({key:n,width:c,height:a})=>[n,c,a])),cells:Object.freeze(r)})}function wt({startMs:e,endMs:t}){return Object.freeze([Object.freeze({startMs:e,endMs:t,from:1,to:0,interpolation:"linear"})])}function bt(e){const t=e*1e3;return Object.freeze([Object.freeze({startMs:t,endMs:t+28.8,from:0,to:1,interpolation:"linear"}),Object.freeze({startMs:t+28.8,endMs:t+100.8,from:1,to:.72,interpolation:"linear"}),Object.freeze({startMs:t+100.8,endMs:t+360,from:.5184,to:0,interpolation:"linear"})])}function yt(e){const t=e*1e3;return Object.freeze([Object.freeze({startMs:t,endMs:t+43.2,from:.18,to:1.35,interpolation:"linear"}),Object.freeze({startMs:t+43.2,endMs:t+115.2,from:1.35,to:.78,interpolation:"linear"}),Object.freeze({startMs:t+115.2,endMs:t+360,from:.78,to:2.25,interpolation:"linear"})])}function Et({effect:e,composition:t,layout:i={scale:1,offsetX:0,offsetY:0},resolvedQualityScale:r=1,seed:s=e==null?void 0:e.seed,maxParticleCount:n=Z*2,maxInstancesPerBatch:c=Z}){var X,V,Y,se,ye,Ee,Se;const a=gt(s),o=t.frameRate??((X=t.lottie)==null?void 0:X.fr);if(![o,i.scale,i.offsetX,i.offsetY,r].every(Number.isFinite)||!(o>0))throw new Error("firework 编译参数包含非有限数值");const l=de(t,(V=e.markers)==null?void 0:V.launch),d=de(t,(Y=e.markers)==null?void 0:Y.burst),m=de(t,(se=e.markers)==null?void 0:se.dismiss);for(const $ of[l,d,m])if(!Number.isFinite($.tm)||!Number.isFinite($.dr)||$.dr<0)throw new Error(`firework marker 无效:${$.cm}`);const g=e.dismissDuration??be,v=e.density??1,b=e.formationRadius??200;if(!Number.isFinite(g)||g<=0||!Number.isFinite(v)||v<0||!Number.isFinite(b)||b<0)throw new Error("firework dismissDuration 必须是正数,其他效果参数必须是有限非负数");const w=l.tm/o,k=l.dr/o,f=d.tm/o,h=Ye({frameRate:o,dismissFrame:m.tm,durationSeconds:g}),p=h.startSeconds;if(!(w<=f&&f*1e3<h.endMs))throw new Error("firework marker 时间顺序无效");const M=Ie(t,(ye=e.anchors)==null?void 0:ye.launch,l.tm,i),y=Ie(t,(Ee=e.anchors)==null?void 0:Ee.burst,d.tm,i),I=(t.width??((Se=t.lottie)==null?void 0:Se.w)??0)*i.scale,C=b*i.scale,S=qe(e.colors),R=v*r;if(!Number.isFinite(R))throw new Error("firework quality 参数无效");const O=je(Ge({launchDuration:k,density:v,resolvedQualityScale:r}),c);if(O.totalCount>n)throw new Error(`firework 粒子数量超过安全上限:${n}`);const A=mt(a),T=[],L=$=>{const P=ut(($-w)/Math.max(k,.001)),le=P*P,ee=Math.min(I*.08,30*i.scale),te=Math.abs(M.y-y.y);return pt(M,{x:M.x-ee,y:M.y-te*.34},{x:y.x+ee*.55,y:y.y+te*.28},y,le)},_=($,P)=>{const le=O.emitterCounts[$];for(let ee=0;ee<le;ee+=1){const te=P.start+A()*(P.end-P.start),Me=P.angle+(A()-.5)*P.angleRange,ke=Math.max(0,P.velocity+(A()-.5)*2*P.velocityRange),ve=P.origin(te);T.push(Object.freeze({emitterIndex:$,type:P.type,color:P.color,cellKey:we(P.type,P.color),blend:P.blend,birthTime:te,lifetime:Math.max(.08,P.lifetime+(A()-.5)*2*P.lifetimeRange),x:ve.x,y:ve.y,vx:Math.cos(Me)*ke,vy:Math.sin(Me)*ke,ax:P.gravityX||0,ay:P.gravityY||0,scale:Math.max(.08,P.scale+(A()-.5)*2*(P.scaleRange||0)),scaleSpeed:P.scaleSpeed||-.16,rotation:A()*K,spin:(P.spin||0)+(A()-.5)*2*(P.spinRange||0)}))}},U=w+k*.84;_(0,{type:"glow",color:"#ffffff",blend:"lighter",rate:105,start:w,end:U,lifetime:.24,lifetimeRange:.08,velocity:24*i.scale,velocityRange:10*i.scale,angle:0,angleRange:K,gravityY:0,scale:.72,scaleRange:.24,origin:L}),_(1,{type:"spark",color:S[1],blend:"lighter",rate:78,start:w,end:U,lifetime:.42,lifetimeRange:.12,velocity:38*i.scale,velocityRange:18*i.scale,angle:Math.PI/2,angleRange:Math.PI*.72,gravityY:38*i.scale,scale:.9,scaleRange:.32,spin:1.4,spinRange:2.8,origin:L}),_(2,{type:"glow",color:S[0],blend:"lighter",rate:48,start:w,end:U,lifetime:.5,lifetimeRange:.16,velocity:30*i.scale,velocityRange:16*i.scale,angle:Math.PI/2,angleRange:Math.PI*.88,gravityY:32*i.scale,scale:.5,scaleRange:.2,origin:L}),_(3,{type:"smoke",color:"rgba(184, 184, 184, 0.24)",blend:"source-over",rate:18,start:w,end:U,lifetime:.72,lifetimeRange:.18,velocity:18*i.scale,velocityRange:9*i.scale,angle:0,angleRange:K,gravityY:-8*i.scale,scale:.9,scaleRange:.32,scaleSpeed:.24,origin:L});const E=Math.max(C*1.22,118*i.scale);_(4,{type:"spark",color:S[1],blend:"lighter",rate:390,start:f,end:f+.11,lifetime:1.18,lifetimeRange:.28,velocity:E,velocityRange:E*.42,angle:0,angleRange:K,gravityY:72*i.scale,scale:.5,scaleRange:.19,scaleSpeed:-.1,spin:1.8,spinRange:4.2,origin:()=>y}),_(5,{type:"spark",color:S[0],blend:"lighter",rate:275,start:f,end:f+.11,lifetime:1.38,lifetimeRange:.34,velocity:E*.82,velocityRange:E*.46,angle:0,angleRange:K,gravityY:84*i.scale,scale:.4,scaleRange:.15,scaleSpeed:-.1,spin:-1.2,spinRange:4.8,origin:()=>y}),_(6,{type:"glow",color:"#ffffff",blend:"lighter",rate:145,start:f,end:f+.11,lifetime:.62,lifetimeRange:.12,velocity:E*.68,velocityRange:E*.26,angle:0,angleRange:K,gravityY:46*i.scale,scale:.44,scaleRange:.17,scaleSpeed:-.1,origin:()=>y});const u=f+.12,N=Math.max(C*.74,76*i.scale);_(7,{type:"star",color:"#ffffff",blend:"lighter",rate:265,start:u,end:u+.14,lifetime:1.5,lifetimeRange:.38,velocity:N,velocityRange:N*.48,angle:0,angleRange:K,gravityY:62*i.scale,scale:.4,scaleRange:.18,scaleSpeed:-.055,spin:1.8,spinRange:5.6,origin:()=>y}),_(8,{type:"glow",color:S[2]||S[1],blend:"lighter",rate:175,start:u,end:u+.14,lifetime:1.72,lifetimeRange:.42,velocity:N*.72,velocityRange:N*.5,angle:0,angleRange:K,gravityY:74*i.scale,scale:.24,scaleRange:.12,scaleSpeed:-.035,origin:()=>y}),_(9,{type:"petal",color:S[0],blend:"lighter",rate:48,start:u,end:u+.14,lifetime:1.55,lifetimeRange:.32,velocity:N*.62,velocityRange:N*.38,angle:0,angleRange:K,gravityX:5*i.scale,gravityY:86*i.scale,scale:.62,scaleRange:.26,scaleSpeed:-.08,spin:2.4,spinRange:6.2,origin:()=>y});const z=[],j=[];for(const $ of T)($.blend==="source-over"?z:j).push($);const W=wt(h),G=Object.freeze({type:"flash",color:S[0],cellKey:we("flash",S[0]),x:y.x,y:y.y,birthTime:f,lifetime:.36,opacityEnvelope:bt(f),sizeEnvelope:yt(f)});return Object.freeze({seed:a,palette:S,atlasRecipeKey:He(e).key,timeline:Object.freeze({launchStart:w,launchDuration:k,burstStart:f,dismissStart:p,dismissDuration:g}),launchPoint:Object.freeze(M),burstPoint:Object.freeze(y),particles:Object.freeze(T),smoke:Object.freeze(z),main:Object.freeze(j),flash:G,dismissEnvelope:W})}function Fe(e){return typeof e=="string"?e.trim():""}function ne(){const e=new Error("圆角图片处理已取消");return e.name="AbortError",e}async function St(e,t,i,r,s){if(typeof e!="string"||!e.trim()||!r||r<=0)return typeof e=="string"?e.trim():"";if(s!=null&&s.aborted)throw ne();if(typeof document>"u"||typeof Image>"u")return e.trim();try{const n=await new Promise((I,C)=>{const S=new Image;let R=!1;const O=()=>{S.onload=null,S.onerror=null,s==null||s.removeEventListener("abort",T)},A=(L,_)=>{R||(R=!0,O(),L(_))},T=()=>{S.src="",A(C,ne())};S.crossOrigin="anonymous",S.onload=()=>A(I,S),S.onerror=()=>A(C,new Error(`图片加载失败: ${e}`)),s==null||s.addEventListener("abort",T,{once:!0}),S.src=e});if(s!=null&&s.aborted)throw ne();const c=t||n.naturalWidth||n.width||100,a=i||n.naturalHeight||n.height||100,o=2,l=document.createElement("canvas");l.width=Math.round(c*o),l.height=Math.round(a*o);const d=l.getContext("2d");if(!d)return e;const m=l.width,g=l.height,v=Math.min(r*o,m/2,g/2);d.beginPath(),typeof d.roundRect=="function"?d.roundRect(0,0,m,g,v):(d.moveTo(v,0),d.arcTo(m,0,m,g,v),d.arcTo(m,g,0,g,v),d.arcTo(0,g,0,0,v),d.arcTo(0,0,m,0,v),d.closePath()),d.clip();const b=n.naturalWidth||n.width||m,w=n.naturalHeight||n.height||g,k=b/w,f=m/g;let h=0,p=0,M=b,y=w;if(k>f?(M=w*f,h=(b-M)/2):(y=b/f,p=(w-y)/2),d.drawImage(n,h,p,M,y,0,0,m,g),s!=null&&s.aborted)throw ne();return l.toDataURL("image/png")}catch(n){if((n==null?void 0:n.name)==="AbortError")throw n;return e}}function Ze(e={}){const t=e.playConfig||e,i=t.multiGiftEffect||{},r=t.giftUrl||t.assetUrl||"",s=t.giftRealSize||t.giftBodySize||null;let n=t.assetType;n||(r==="box"?n="box":typeof r=="string"&&(/\.(png|jpe?g|webp|gif|bmp)($|\?)/i.test(r)||r.startsWith("data:image/"))?n="image":n="svga");const c=i.lottie||t.lottieUrl||t.lottie,a=i.slotSize||t.slotSize||{width:60,height:60},o=Array.isArray(i.effects)?i.effects:Array.isArray(t.effects)?t.effects:[],l=Array.isArray(i.imgs)?i.imgs:Array.isArray(t.imgs)?t.imgs:[],d=e.imageSlots&&e.imageSlots.length?e.imageSlots:l.map(g=>({slot:g.slot,width:g.width,height:g.height,radius:g.radius})),m={...e.imageUrls||{},...Object.fromEntries(l.filter(g=>g.url!==void 0&&g.url!==null).map(g=>[g.slot,g.url]))};return{giftUrl:r,giftRealSize:s,giftBodySize:s,assetType:n,assetUrl:r,lottie:c,lottieUrl:c,slotSize:a,effects:o,imgs:l,imageSlots:d,imageUrls:m}}const Mt=16,Ne=24;function ue(e,t,i){if(!Number.isFinite(t)||t<1)throw new Error("firework GPU capability maxInstancesPerBatch 无效");if(e>t)throw new Error(`${i} 粒子数量超过 GPU batch 上限:${t}`)}function kt(e,t,i){e.set([i.birthTime,i.lifetime,i.x,i.y,i.vx,i.vy,i.ax,i.ay,i.scale,i.scaleSpeed,i.rotation,i.spin,1,1,1,1],t)}function me(e,t,i){const r=new Float32Array(e.length*Ne);return e.forEach((s,n)=>{const c=t.get(s.cellKey);if(!c)throw new Error(`firework atlas 缺少 cell:${s.cellKey}`);const a=n*Ne;kt(r,a,s),r.set([c.width*i,c.height*i,.5,.5,c.u0,c.v0,c.u1,c.v1],a+Mt)}),r}function vt(e,t){var a,o;const i=((a=e[0])==null?void 0:a.startMs)??1/0,r=((o=e.at(-1))==null?void 0:o.endMs)??-1/0;if(!Number.isFinite(i)||!Number.isFinite(r)||!(r>i))return[];const s=new Set([i,r]);for(const l of[...e,...t])l.startMs>i&&l.startMs<r&&s.add(l.startMs),l.endMs>i&&l.endMs<r&&s.add(l.endMs);const n=[...s].sort((l,d)=>l-d),c=[];for(let l=0;l<n.length-1;l+=1){const d=n[l],m=n[l+1];if(!(m>d))continue;const g=(h,p=!1)=>Oe(e,h,1,p)*Oe(t,h,1,p),v=g(d),b=g(m,!0),w=(d+m)*.5,f=Math.abs(g(w)-(v+b)*.5)>1e-6?4:m-d;for(let h=d;h<m;h+=f){const p=Math.min(m,h+f);c.push({startMs:h,endMs:p,from:g(h),to:g(p,!0),interpolation:"linear"})}}return c}function Tt({effect:e,composition:t,layout:i,resolvedQualityScale:r,seed:s,atlas:n,atlasCells:c,maxInstancesPerBatch:a}){const o=Et({effect:e,composition:t,layout:i,resolvedQualityScale:r,seed:s,maxParticleCount:a*2,maxInstancesPerBatch:a});ue(o.smoke.length,a,"firework smoke"),ue(o.main.length,a,"firework main"),ue(1,a,"firework flash");const l={birthTime:o.flash.birthTime,lifetime:o.flash.lifetime,x:o.flash.x,y:o.flash.y,vx:0,vy:0,ax:0,ay:0,scale:1,scaleSpeed:0,rotation:0,spin:0,cellKey:o.flash.cellKey},d={format:"sprite-v2",atlas:n,opacity:1,compositeLayer:"behind-media"};return Object.freeze({model:o,descriptors:Object.freeze([Object.freeze({...d,count:o.smoke.length,instances:me(o.smoke,c,i.scale),fadeMode:"lifetime",envelope:{opacity:o.dismissEnvelope},zIndex:0,blend:"normal",label:"multi-gift-firework-smoke"}),Object.freeze({...d,count:o.main.length,instances:me(o.main,c,i.scale),fadeMode:"lifetime",envelope:{opacity:o.dismissEnvelope},zIndex:1,blend:"additive",label:"multi-gift-firework-main"}),Object.freeze({...d,count:1,instances:me([l],c,i.scale),fadeMode:"none",envelope:{opacity:vt(o.flash.opacityEnvelope,o.dismissEnvelope),size:o.flash.sizeEnvelope},zIndex:2,blend:"additive",label:"multi-gift-firework-flash"})])})}const oe=4,D=256;function Rt(e,t,i){if(i)return i(e,t);if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(e,t);if(typeof document<"u"){const r=document.createElement("canvas");return r.width=e,r.height=t,r}throw new Error("当前环境无法生成 firework sprite atlas")}function At(e){const t=new Map;let i=0,r=0,s=0;for(const n of e.cells){const c=n.width+oe*2,a=n.height+oe*2;if(i+c>D&&(i=0,r+=s,s=0),r+a>D)throw new Error("firework atlas recipe exceeds 256x256");const o=i+oe,l=r+oe;t.set(n.key,Object.freeze({...n,x:o,y:l,u0:o/D,v0:l/D,u1:(o+n.width)/D,v1:(l+n.height)/D})),i+=c,s=Math.max(s,a)}return t}function Ot(e,t={}){const i=He(e),r=At(i),s=Rt(D,D,t.canvasFactory);s.width=D,s.height=D;const n=s.getContext("2d",{willReadFrequently:!0});if(!n)throw new Error("无法创建 firework atlas Canvas2D context");n.clearRect(0,0,D,D);for(const o of r.values())ft(n,o,o.x,o.y);const c=n.getImageData(0,0,D,D),a=new Uint8Array(c.data.length);for(let o=0;o<c.data.length;o+=4){const l=c.data[o+3];a[o+3]=l,l===0?(a[o]=0,a[o+1]=0,a[o+2]=0):(a[o]=Math.round(c.data[o]*l/255),a[o+1]=Math.round(c.data[o+1]*l/255),a[o+2]=Math.round(c.data[o+2]*l/255))}return Object.freeze({key:i.key,width:D,height:D,pixels:a,cells:r})}const Pe=8,Ce=10;function It(e){const t=new RegExp(`^${e}_(\\d+)$`);return(i,r)=>{var c,a;const s=Number(((c=t.exec(i.nm))==null?void 0:c[1])??Number.MAX_SAFE_INTEGER),n=Number(((a=t.exec(r.nm))==null?void 0:a[1])??Number.MAX_SAFE_INTEGER);return s-n}}function _e(e,t,i,r){return!e||!t||!i||!r?1:Math.min(i/e,r/t)}function Ft(e){return Number.isFinite(e==null?void 0:e.x)&&Number.isFinite(e==null?void 0:e.y)?{x:e.x,y:e.y}:null}function H(e){const t=new Error(e);return t.name="AbortError",t}function Le(e){var i,r,s,n;const t=(i=e==null?void 0:e.capabilities)==null?void 0:i.particles;return(t==null?void 0:t.backend)==="unavailable"||!((r=t==null?void 0:t.formats)!=null&&r.includes("sprite-v2"))||((s=t==null?void 0:t.spriteAtlas)==null?void 0:s.source)!=="rgba8-premultiplied"||!((n=t==null?void 0:t.compositeLayers)!=null&&n.includes("behind-media"))||(t==null?void 0:t.batchEnvelope)!==!0||(t==null?void 0:t.atomicBatchGroup)!==!0||!Number.isFinite(t==null?void 0:t.maxInstancesPerBatch)||typeof(e==null?void 0:e.createParticleAtlas)!="function"?null:t}function ze(e){const t=typeof navigator<"u"?navigator:{};return{quality:e,deviceMemory:t.deviceMemory,hardwareConcurrency:t.hardwareConcurrency,userAgent:t.userAgent}}function Nt(e,t){if(!Number.isFinite(e))return t;let i=t;for(;i-e>Math.PI;)i-=Math.PI*2;for(;i-e<-Math.PI;)i+=Math.PI*2;return i}async function Pt(e,t){if(e&&typeof e=="object")return e;if(typeof e=="string"&&e.trim().startsWith("{"))try{return JSON.parse(e)}catch(r){throw new Error(`Lottie JSON 解析失败:${r.message||"格式错误"}`)}if(typeof e!="string"||!e.trim())throw new Error("未提供有效的 Lottie 轨迹配置");const i=await fetch(e,{signal:t});if(!i.ok)throw new Error(`Lottie 加载失败 (${i.status})`);return i.json()}function xe(e,t,i){var c;const r=(c=e==null?void 0:e.capabilities)==null?void 0:c.motionTrack,s=(r==null?void 0:r.gpuMediaTypes)||[];return(r==null?void 0:r.mode)==="gpu-table"&&t==="svga"&&s.includes(t)?"gpu-table":"cpu-reference"}function Ct(e){if(!e||typeof e.getRenderInfo!="function")return null;try{return e.getRenderInfo()}catch{return null}}function _t(e,t){var r,s;const i=[];return e.forEach((n,c)=>{if(n.kind!=="svga")return;const a=t[c],o=Ct(a),l={slotId:n.id,giftId:(a==null?void 0:a.id)??n.id,svgaFramePath:(o==null?void 0:o.svgaFramePath)??(o==null?void 0:o.selectedPath)??(o==null?void 0:o.path)??null};o!=null&&o.parentMotionMode&&(l.parentMotionMode=o.parentMotionMode);for(const d of["backend","pathState","frameTableBytes","commandTableBytes","drawBatchMode","drawCompatibleInstanceCount","fallbackReasons"])(o==null?void 0:o[d])!=null&&(l[d]=o[d]);i.push(l)}),{svgaFramePath:((r=i.find(n=>n.svgaFramePath!=null))==null?void 0:r.svgaFramePath)??null,parentMotionMode:((s=i.find(n=>n.parentMotionMode!=null))==null?void 0:s.parentMotionMode)??null,svgaFramePaths:i}}class Lt{constructor(t,i,r,s,n){this.id=t,this.scope=i,this.completion=r,this.onStop=s,this.diagnosticsProvider=n}get diagnostics(){return this.diagnosticsProvider()}get state(){return this.scope.state}pause(){this.scope.pause()}resume(){this.scope.resume()}seek(t){this.scope.seek(t)}stop(){this.onStop()}destroy(){this.onStop()}}class Qe{constructor(t,i={}){this.host=t,this.options=i,this.sampleRate=Math.max(30,Math.min(120,i.sampleRate||60)),this.onStateChange=i.onStateChange||(()=>{}),this.onRenderFrame=i.onRenderFrame||(()=>{}),this.disabledSlotIds=new Set(i.disabledSlotIds||[]),this.playConfig=null,this.composition=null,this.assetLease=null,this.imageLeases=new Map,this.activePlayback=null,this.pendingScope=null,this.playEpoch=0,this.playIntentEpoch=0,this.preloadController=null,this.preloadEpoch=0,this._preloadDiagnostics=null,this.fireworkAtlas=null,this.fireworkAtlasCells=null,this.fireworkAtlasRecipeKey=null,this.fireworkQualityScale=1,this.particleCapabilityWarningEmitted=!1,this.destroyed=!1}get capabilities(){return this.host.capabilities}get preloadDiagnostics(){return this._preloadDiagnostics}async preload(t=this.options.playConfig,i=!1){var b,w,k;if(this.assertAlive(),!t)throw new Error("未提供 playConfig");this.cancelPlayback(!i),this.releaseLeases(),this.playConfig=null,this.composition=null,this._preloadDiagnostics=null;const r=Ze({...this.options,playConfig:t});if(r.assetType!=="svga"&&r.assetType!=="image")throw new Error(`GiftStage 插件不支持的礼物类型:${r.assetType}`);this.emitStateChange({status:"loading",message:"正在预加载 Lottie 与共享礼物资源"});const s=new AbortController;(b=this.preloadController)==null||b.abort(),this.preloadController=s;const n=++this.preloadEpoch;let c=null,a=new Map;const o={...r.imageUrls};let l=null,d=null,m=null,g=1,v=!1;try{const f=await Pt(r.lottieUrl,s.signal);this.assertCurrentPreload(s,n);const h=Le(this.host),p=Xe(f,{effects:r.effects,fireworkEnvironment:ze("auto"),maxInstancesPerBatch:Math.min(Z,(h==null?void 0:h.maxInstancesPerBatch)??Z)});p.length&&this.emitStateChange({validationFindings:p});const M=p.find(u=>u.code==="LOTTIE_TARGET_MARKER_MISSING");if(M)throw this.emitStateChange({status:"fallback",reason:M.code,message:"多礼物编排缺少 target_flight,交由宿主降级普通单礼物"}),new ae(M.code,"Lottie 中缺少有效的 target_flight marker",p,!0);const y=p.filter(u=>u.scope==="composition"&&u.severity==="error");if(y.length)throw new ae(y[0].code,`Lottie 合成校验失败:${y.map(u=>`${u.code}@${u.where}`).join(", ")}`,p);const I=new Set(p.filter(u=>u.scope==="slot"&&u.severity==="error"&&u.layer).map(u=>u.layer)),C=new Set(p.filter(u=>u.scope==="effect"&&Number.isInteger(u.effectIndex)).map(u=>u.effectIndex)),S=new Map((f.layers||[]).map(u=>[u.nm,u])),R=(f.layers||[]).filter(u=>/^slot_\d+$/.test(u.nm)&&u.ks&&!I.has(u.nm)).sort(It("slot"));if(!R.length)throw new ae("LOTTIE_SLOT_MISSING","Lottie 中没有可播放的 slot_N 礼物插槽图层",p);const O=ce(f.markers,"target_flight"),A=r.effects.filter((u,N)=>!C.has(N));c=await this.host.preload(r.assetType,r.assetUrl,s.signal),this.assertCurrentPreload(s,n);for(const u of r.imageSlots){const N=Fe(r.imageUrls[u.slot]);let z=N;if(N&&u.radius>0&&(z=await St(N,u.width,u.height,u.radius,s.signal),this.assertCurrentPreload(s,n)),!z||!((w=S.get(u.slot))!=null&&w.ks)||I.has(u.slot))continue;o[u.slot]=z;const j=await this.host.preload("image",z,s.signal);(k=a.get(u.slot))==null||k.release(),a.set(u.slot,j),this.assertCurrentPreload(s,n)}const T={startFrame:O.tm,endFrame:O.tm+O.dr},L=new Map(R.map(u=>{var X,V;const N=((V=(X=u.ks)==null?void 0:X.s)==null?void 0:V.a)===1&&Array.isArray(u.ks.s.k)?u.ks.s.k.filter(Y=>Number.isFinite(Y==null?void 0:Y.t)&&Y.t>=T.startFrame&&Y.t<=T.endFrame).sort((Y,se)=>Y.t-se.t):[],z=N[0],j=N[N.length-1];let W=Number.isFinite(z==null?void 0:z.t)?z.t:T.startFrame,G=Number.isFinite(j==null?void 0:j.t)?j.t:T.endFrame;return W=Math.max(T.startFrame,Math.min(T.endFrame,W)),G=Math.max(T.startFrame,Math.min(T.endFrame,G)),G>W||(W=T.startFrame,G=T.endFrame),[u.nm,{start:W,end:G}]})),_={lottie:f,width:f.w,height:f.h,frameRate:f.fr,inFrame:f.ip,outFrame:f.op,durationMs:(f.op-f.ip)/f.fr*1e3,layers:S,timeline:R,targetFlight:T,flightWindows:L},U=A.find(u=>u.type==="firework");if(U&&h){g=$e(ze(U.quality??"auto"));const u=Ot(U);if(u.width>h.spriteAtlas.maxSize||u.height>h.spriteAtlas.maxSize)throw new Error("firework atlas 超过当前 GPU capability");l=await this.host.createParticleAtlas({width:u.width,height:u.height,pixels:u.pixels,colorSpace:"srgb",alphaMode:"premultiplied",filter:"linear",label:`multi-gift-firework:${u.key}`}),d=u.cells,m=u.key,this.assertCurrentPreload(s,n)}this.assertCurrentPreload(s,n),this.playConfig={...r,effects:A,imageUrls:o},this.assetLease=c,this.imageLeases=a,this.composition=_,this.fireworkAtlas=l,this.fireworkAtlasCells=d,this.fireworkAtlasRecipeKey=m,this.fireworkQualityScale=g,v=!0;const E=xe(this.host,r.assetType,c.metadata);this._preloadDiagnostics=Object.freeze({parentMotionMode:E,motionMode:E}),this.emitStateChange({status:"ready",message:`${R.length} 个礼物轨道已就绪`,slotCount:R.length,backend:this.host.capabilities.backend,...this._preloadDiagnostics})}catch(f){if(!v){c==null||c.release();for(const h of a.values())h.release();l==null||l.destroy()}throw(f==null?void 0:f.name)==="AbortError"||this.destroyed||this.preloadEpoch!==n||s.signal.aborted?H("多礼物资源预加载已取消"):f}finally{this.preloadController===s&&(this.preloadController=null)}}async play(t={}){var v,b,w;if(this.assertAlive(),!Object.prototype.hasOwnProperty.call(t,"target"))throw new Error("play() 必须显式传入 target,值可为 null 或 undefined");const i=++this.playIntentEpoch;if(!this.composition&&(await this.preload(void 0,!0),this.playIntentEpoch!==i)||(this.assertAlive(),this.playIntentEpoch!==i))throw H("多礼物播放已取消");this.cancelPlayback(!1);const r=this.composition,s=this.playConfig,n=Ft(t.target),c=this.host.getViewport(),a=r.width>0?c.width/r.width:1,o=0,l=(c.height-r.height*a)*.5,d=this.host.createPlaybackScope(`multi-gift-${Date.now()}`),m=this.playEpoch;this.pendingScope={scope:d,playEpoch:m};const g=r.timeline.map((k,f)=>{var h,p,M,y,I,C,S,R;return{id:k.nm,layer:k,kind:s.assetType,source:s.assetUrl,width:this.assetLease.metadata.width*_e((h=s.giftBodySize)==null?void 0:h.width,(p=s.giftBodySize)==null?void 0:p.height,(M=s.slotSize)==null?void 0:M.width,(y=s.slotSize)==null?void 0:y.height)*a,height:this.assetLease.metadata.height*_e((I=s.giftBodySize)==null?void 0:I.width,(C=s.giftBodySize)==null?void 0:C.height,(S=s.slotSize)==null?void 0:S.width,(R=s.slotSize)==null?void 0:R.height)*a,zIndex:Ce+f,redirect:!0}});for(const k of s.imageSlots){const f=this.imageLeases.get(k.slot),h=r.layers.get(k.slot);!f||!(h!=null&&h.ks)||g.push({id:k.slot,layer:h,kind:"image",source:Fe(s.imageUrls[k.slot]),width:k.width*a,height:k.height*a,zIndex:Ce+g.length,redirect:!1})}try{const k=await Promise.all(g.map(E=>d.addGift({type:E.kind,source:E.source,x:0,y:0,width:E.width,height:E.height,zIndex:E.zIndex,opacity:0,loop:E.kind==="svga"?0:void 0,mute:E.kind==="svga"?!0:void 0,clearsAfterStop:!1})));this.assertCurrentPlay(d,m);const f=this.compileMotionTrack(g,n,{scale:a,offsetX:o,offsetY:l}),h=d.createMotionTrack(f);k.forEach((E,u)=>d.bindMotion(E,h,u));const p=()=>{var N,z;const E=_t(g,k),u=E.parentMotionMode??((N=this._preloadDiagnostics)==null?void 0:N.parentMotionMode)??xe(this.host,s.assetType,(z=this.assetLease)==null?void 0:z.metadata);return Object.freeze({...E,parentMotionMode:u,motionMode:u})},M=p(),y=(v=s.effects)==null?void 0:v.find(E=>E.type==="firework"),I=Le(this.host);if(y&&I&&this.fireworkAtlas&&this.fireworkAtlasCells&&typeof d.createParticleBatchGroup=="function")try{const E=Tt({effect:y,composition:r,layout:{scale:a,offsetX:o,offsetY:l},resolvedQualityScale:this.fireworkQualityScale,seed:y.seed,atlas:this.fireworkAtlas,atlasCells:this.fireworkAtlasCells,maxInstancesPerBatch:I.maxInstancesPerBatch});d.createParticleBatchGroup(E.descriptors)}catch(E){this.emitStateChange({effectWarning:`firework 编译失败,已跳过:${E instanceof Error?E.message:String(E)}`})}else y&&(this.particleCapabilityWarningEmitted||(this.particleCapabilityWarningEmitted=!0,this.emitStateChange({effectWarning:"当前核心缺少 sprite-v2/atlas/envelope/atomic group 能力,已跳过 firework;未创建 Canvas2D 后端"})));let C;const S=new Promise(E=>{C=E});let R=!1,O;const A=E=>{R||(R=!0,C({status:E}))},T=()=>{d.state!=="destroyed"&&d.destroy(),this.activePlayback===O&&(this.activePlayback=null),R||(this.emitStateChange({status:"stopped",message:"播放已停止"}),A("stopped"))};O=new Lt(d.id,d,S,T,p),this.assertCurrentPlay(d,m),this.pendingScope=null,this.activePlayback=O;let L=0,_=0,U=!1;return d.onFrame(({nowMs:E,deltaMs:u})=>{const N=Math.min(r.outFrame,r.inFrame+E*r.frameRate/1e3);this.emitRenderFrame(N),U||(U=!0,this.emitStateChange({status:"playing",diagnosticsRefreshed:!0,...O.diagnostics})),L+=u,_+=1,L>=500&&(this.emitStateChange({fps:Math.round(_*1e3/L)}),L=0,_=0)}),d.onFinish(()=>{R||(this.activePlayback===O&&(this.activePlayback=null),d.destroy(),this.emitStateChange({status:"finished",message:"本轮编排播放完成"}),A("finished"))}),d.start({durationMs:r.durationMs}),this.emitStateChange({status:"playing",message:`${k.length} 个实例由 GiftStage 统一时钟驱动`,...M}),O}catch(k){throw((b=this.pendingScope)==null?void 0:b.scope)===d&&(this.pendingScope=null),((w=this.activePlayback)==null?void 0:w.scope)===d?this.activePlayback.stop():d.state!=="destroyed"&&d.destroy(),(k==null?void 0:k.name)==="AbortError"||this.destroyed||this.playEpoch!==m?H("多礼物播放已取消"):k}}compileMotionTrack(t,i,r){const s=this.composition,n=1e3/this.sampleRate,c=Math.ceil(s.durationMs/n)+1,a=new Float32Array(t.length*c*Pe);return t.forEach((o,l)=>{let d=Number.NaN;for(let m=0;m<c;m+=1){const g=Math.min(s.durationMs,m*n),v=s.inFrame+g*s.frameRate/1e3,b=this.evaluateLayer(o,v,i,r);b.rotation=Nt(d,b.rotation),d=b.rotation;const w=(l*c+m)*Pe;a[w]=b.x,a[w+1]=b.y,a[w+2]=b.scaleX,a[w+3]=b.scaleY,a[w+4]=b.rotation,a[w+5]=b.opacity,a[w+6]=b.visible?1:0,a[w+7]=m+1<c&&b.interpolateToNext?1:0}}),{trackCount:t.length,sampleCount:c,sampleIntervalMs:n,durationMs:s.durationMs,samples:a,label:"lottie-multi-gift"}}evaluateLayer(t,i,r,s){const n=t.layer;let[c,a]=J(n.ks.p,i,[0,0,0]);const[o,l]=J(n.ks.s,i,[100,100,100]),d=n.ks.r??n.ks.rz,[m]=J(d,i,[0]),[g]=J(n.ks.o,i,[100]),v=i>=n.ip&&i<n.op&&g>0&&!this.disabledSlotIds.has(t.id);let b=c*s.scale+s.offsetX,w=a*s.scale+s.offsetY;if(t.redirect){const f=this.composition.flightWindows.get(n.nm)||this.composition.targetFlight;if(i>=f.start){const[h,p]=J(n.ks.p,f.start,[c,a,0]),M=h*s.scale+s.offsetX,y=p*s.scale+s.offsetY;if(r){const I=f.end-f.start,C=I>0?Math.max(0,Math.min(1,(i-f.start)/I)):0,S=Je(C);b=M+(r.x-M)*S,w=y+(r.y-y)*S}else b=M,w=y}}const k=[n.ks.p,n.ks.s,d,n.ks.o].some(f=>{if((f==null?void 0:f.a)!==1)return!1;const h=f.k||[];return h.some((p,M)=>{const y=h[M+1];return y&&i>=p.t&&i<y.t&&p.h===1})});return{x:b,y:w,scaleX:o/100,scaleY:l/100,rotation:m*Math.PI/180,opacity:Math.max(0,Math.min(1,g/100)),visible:v,interpolateToNext:!k}}setDisabledSlots(t=[]){this.disabledSlotIds=new Set(t)}stop(){this.cancelPlayback(!0)}cancelPlayback(t){t&&(this.playIntentEpoch+=1),this.playEpoch+=1;const i=this.pendingScope;this.pendingScope=null,i&&i.scope.state!=="destroyed"&&i.scope.destroy();const r=this.activePlayback;this.activePlayback=null,r==null||r.stop()}destroy(){var t;this.destroyed||(this.destroyed=!0,this.preloadEpoch+=1,(t=this.preloadController)==null||t.abort(),this.preloadController=null,this.stop(),this.releaseLeases(),this.composition=null,this._preloadDiagnostics=null)}releaseLeases(){var t,i;(t=this.assetLease)==null||t.release(),this.assetLease=null;for(const r of this.imageLeases.values())r.release();this.imageLeases.clear(),(i=this.fireworkAtlas)==null||i.destroy(),this.fireworkAtlas=null,this.fireworkAtlasCells=null,this.fireworkAtlasRecipeKey=null}assertAlive(){if(this.destroyed)throw new Error("GiftStage multi-gift plugin is destroyed")}emitStateChange(t){try{this.onStateChange(t)}catch{}}emitRenderFrame(t){try{this.onRenderFrame(t)}catch{}}assertCurrentPlay(t,i){var r;if(this.destroyed||this.playEpoch!==i||((r=this.pendingScope)==null?void 0:r.scope)!==t||t.state==="destroyed")throw H("多礼物播放已取消")}assertCurrentPreload(t,i){if(this.destroyed||t.signal.aborted||this.preloadEpoch!==i||this.preloadController!==t)throw H("多礼物资源预加载已取消")}}function et(e={}){return{name:"giftstage-plugin-multi-gift",apiVersion:1,setup(t){return new Qe(t,e)}}}function Q(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function De(e,t){let i;try{i=JSON.parse(e)}catch{throw new Error(`${t}不是合法 JSON`)}if(!Q(i))throw new Error(`${t}必须是 JSON 对象`);return i}function tt(e,t){if(!Q(e)||!Number.isFinite(e.width)||e.width<=0||!Number.isFinite(e.height)||e.height<=0)throw new Error(`${t}必须包含大于 0 的 width 和 height`);return{width:e.width,height:e.height}}function zt(e){if(e===void 0)return[];if(!Array.isArray(e))throw new Error("multiGiftEffect.imgs 必须是数组");return e.map((t,i)=>{if(!Q(t)||typeof t.slot!="string"||!/^img_slot_\d+$/.test(t.slot))throw new Error(`multiGiftEffect.imgs[${i}].slot 必须是 img_slot_xx`);if(tt(t,`multiGiftEffect.imgs[${i}]`),t.radius!==void 0&&(!Number.isFinite(t.radius)||t.radius<0))throw new Error(`multiGiftEffect.imgs[${i}].radius 必须是大于等于 0 的数字`);return{...t}})}function Ue(e){if(!Q(e)||!Array.isArray(e.layers))throw new Error("multiGiftEffect.lottie 必须包含 layers 数组");let t=0;for(const i of e.layers){const r=/^slot_(\d+)$/.exec((i==null?void 0:i.nm)||"");r&&(t=Math.max(t,Number(r[1])))}if(!t)throw new Error("multiGiftEffect.lottie 中至少需要一个 slot_xx 礼物插槽");return t}function xt(e){const t=typeof e=="string"?De(e,"本地特效配置"):e;if(!Q(t))throw new Error("本地特效配置必须是 JSON 对象");if(!Object.prototype.hasOwnProperty.call(t,"lottie"))throw Array.isArray(t.layers)?new Error("请上传 multiGiftEffect 配置,不能直接上传纯 Lottie JSON"):new Error("multiGiftEffect.lottie 不能为空");let i,r;if(Q(t.lottie))i=t.lottie;else if(typeof t.lottie=="string"&&t.lottie.trim()){const c=t.lottie.trim();c.startsWith("{")?i=De(c,"multiGiftEffect.lottie"):r=c}else throw new Error("multiGiftEffect.lottie 必须是 Lottie JSON 对象、JSON 字符串或 URL");const s=tt(t.slotSize,"multiGiftEffect.slotSize"),n=t.effects===void 0?[]:t.effects;if(!Array.isArray(n))throw new Error("multiGiftEffect.effects 必须是数组");return{lottieJson:i,lottieUrl:r,slotSize:s,effects:n.map(c=>({...c})),imgs:zt(t.imgs)}}async function Dt(e,t=fetch){if(e.lottieJson)return{lottieJson:e.lottieJson,slotCount:Ue(e.lottieJson)};let i;try{i=await t(e.lottieUrl)}catch(s){throw new Error(`无法加载 lottie URL:${s.message||"网络错误"}`)}if(!i.ok)throw new Error(`无法加载 lottie URL(${i.status})`);let r;try{r=await i.json()}catch{throw new Error("lottie URL 返回的内容不是合法 JSON")}return{lottieJson:r,slotCount:Ue(r)}}exports.GiftStageMultiGiftPluginApi=Qe;exports.MultiGiftValidationError=ae;exports.bezierEase=Ke;exports.createGiftStageMultiGiftPlugin=et;exports.default=et;exports.easeInOutCubic=ct;exports.easeOutCubic=Je;exports.findMarker=ce;exports.findUnsupportedCapabilities=nt;exports.inspectLocalLottie=Dt;exports.normalizePlayConfig=Ze;exports.parseLocalMultiGiftEffect=xt;exports.spatialBezierPoint=at;exports.validateMultiGiftComposition=Xe;exports.valueAt=J;
|