Files
Pandona-Engine/dist-template/assets/index-a09a4142.js
2025-10-03 16:49:53 +08:00

92 lines
46 KiB
JavaScript

(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))s(n);new MutationObserver(n=>{for(const i of n)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&s(o)}).observe(document,{childList:!0,subtree:!0});function t(n){const i={};return n.integrity&&(i.integrity=n.integrity),n.referrerPolicy&&(i.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?i.credentials="include":n.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(n){if(n.ep)return;n.ep=!0;const i=t(n);fetch(n.href,i)}})();const T="modulepreload",L=function(c){return"/"+c},P={},N=function(e,t,s){if(!t||t.length===0)return e();const n=document.getElementsByTagName("link");return Promise.all(t.map(i=>{if(i=L(i),i in P)return;P[i]=!0;const o=i.endsWith(".css"),r=o?'[rel="stylesheet"]':"";if(!!s)for(let d=n.length-1;d>=0;d--){const h=n[d];if(h.href===i&&(!o||h.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${i}"]${r}`))return;const l=document.createElement("link");if(l.rel=o?"stylesheet":T,o||(l.as="script",l.crossOrigin=""),l.href=i,document.head.appendChild(l),o)return new Promise((d,h)=>{l.addEventListener("load",d),l.addEventListener("error",()=>h(new Error(`Unable to preload CSS for ${i}`)))})})).then(()=>e()).catch(i=>{const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=i,window.dispatchEvent(o),!o.defaultPrevented)throw i})},A=(c,e)=>{const t=c[e];return t?typeof t=="function"?t():Promise.resolve(t):new Promise((s,n)=>{(typeof queueMicrotask=="function"?queueMicrotask:setTimeout)(n.bind(null,new Error("Unknown variable dynamic import: "+e)))})};class ${constructor(){this.events={}}on(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}off(e,t){if(!this.events[e])return;const s=this.events[e].indexOf(t);s>-1&&this.events[e].splice(s,1)}emit(e,t){this.events[e]&&this.events[e].forEach(s=>s(t))}once(e,t){const s=n=>{t(n),this.off(e,s)};this.on(e,s)}}class F{constructor(){this.resources=new Map,this.loading=new Map}load(e){if(this.resources.has(e))return Promise.resolve(this.resources.get(e));if(this.loading.has(e))return this.loading.get(e);const t=new Promise((s,n)=>{if(this.isImage(e)){const i=new Image;i.onload=()=>{this.resources.set(e,i),this.loading.delete(e),s(i)},i.onerror=o=>{this.loading.delete(e),n(o)},i.src=e}else n(new Error(`Unsupported resource type: ${e}`))});return this.loading.set(e,t),t}isImage(e){return/\.(jpeg|jpg|png|gif|svg|webp)$/i.test(e)}get(e){return this.resources.get(e)}clear(){this.resources.clear(),this.loading.clear()}}class O{constructor(){this.sounds=new Map,this.music=new Map,this.masterVolume=1,this.soundVolume=1,this.musicVolume=1,this.enabled=!0}loadSound(e,t,s={}){return new Promise((n,i)=>{const o=new Audio;o.src=t,o.preload="auto",o.loop=s.loop||!1,o.volume=(s.volume||1)*this.soundVolume*this.masterVolume,o.addEventListener("canplaythrough",()=>{this.sounds.set(e,{audio:o,volume:s.volume||1,loop:s.loop||!1}),n(o)}),o.addEventListener("error",r=>{i(new Error(`Failed to load sound: ${t}`))})})}loadMusic(e,t,s={}){return new Promise((n,i)=>{const o=new Audio;o.src=t,o.preload="auto",o.loop=s.loop||!1,o.volume=(s.volume||1)*this.musicVolume*this.masterVolume,o.addEventListener("canplaythrough",()=>{this.music.set(e,{audio:o,volume:s.volume||1,loop:s.loop||!1}),n(o)}),o.addEventListener("error",r=>{i(new Error(`Failed to load music: ${t}`))})})}playSound(e,t={}){if(!this.enabled)return;const s=this.sounds.get(e);if(!s){console.warn(`Sound ${e} not found`);return}const n=s.audio.cloneNode();return n.volume=(t.volume||s.volume)*this.soundVolume*this.masterVolume,n.loop=t.loop||s.loop,n.play().catch(i=>{console.warn(`Failed to play sound ${e}:`,i)}),n}playMusic(e,t={}){if(!this.enabled)return;const s=this.music.get(e);if(!s){console.warn(`Music ${e} not found`);return}return s.audio.volume=(t.volume||s.volume)*this.musicVolume*this.masterVolume,s.audio.loop=t.loop||s.loop,s.audio.play().catch(n=>{console.warn(`Failed to play music ${e}:`,n)}),s.audio}stopMusic(e){const t=this.music.get(e);t&&(t.audio.pause(),t.audio.currentTime=0)}pauseMusic(e){const t=this.music.get(e);t&&t.audio.pause()}resumeMusic(e){const t=this.music.get(e);t&&t.audio.play().catch(s=>{console.warn(`Failed to resume music ${e}:`,s)})}setMasterVolume(e){this.masterVolume=Math.max(0,Math.min(1,e));for(const[t,s]of this.sounds)s.audio.volume=s.volume*this.soundVolume*this.masterVolume;for(const[t,s]of this.music)s.audio.volume=s.volume*this.musicVolume*this.masterVolume}setSoundVolume(e){this.soundVolume=Math.max(0,Math.min(1,e))}setMusicVolume(e){this.musicVolume=Math.max(0,Math.min(1,e))}setEnabled(e){if(this.enabled=e,!e)for(const[t,s]of this.music)s.audio.pause()}preload(e){const t=[];for(const[s,n]of Object.entries(e))n.type==="sound"?t.push(this.loadSound(s,n.src,n.options)):n.type==="music"&&t.push(this.loadMusic(s,n.src,n.options));return Promise.all(t)}}class _{constructor(e){this.engine=e,this.currentTransition=null,this.isTransitioning=!1}fade(e,t=1e3,s={}){if(this.isTransitioning)return;this.isTransitioning=!0;const n=document.createElement("div");return n.style.position="absolute",n.style.top="0",n.style.left="0",n.style.width="100%",n.style.height="100%",n.style.backgroundColor=s.color||"#000000",n.style.opacity="0",n.style.zIndex="9999",n.style.pointerEvents="none",this.engine.stage.appendChild(n),this.engine.tween(n.style,t/2,"easeInOutQuad").to({opacity:1}).onComplete(()=>{this.engine.switchScene(e),this.engine.tween(n.style,t/2,"easeInOutQuad").to({opacity:0}).onComplete(()=>{n.parentNode&&n.parentNode.removeChild(n),this.isTransitioning=!1,s.onComplete&&s.onComplete()}).start()}).start(),this}slide(e,t="left",s=1e3,n={}){if(this.isTransitioning)return;this.isTransitioning=!0;const i=this.engine.stage,o=document.createElement("div");o.style.position="absolute",o.style.top="0",o.style.left="0",o.style.width="100%",o.style.height="100%",o.style.overflow="hidden";const r=this.engine.width,a=this.engine.height;switch(t){case"left":o.style.transform=`translateX(${r}px)`;break;case"right":o.style.transform=`translateX(${-r}px)`;break;case"up":o.style.transform=`translateY(${a}px)`;break;case"down":o.style.transform=`translateY(${-a}px)`;break}return i.parentNode.appendChild(o),this.engine.createScene(`temp_${Date.now()}`),this.engine.tween(o.style,s,"easeInOutQuad").to({transform:"translateX(0) translateY(0)"}).onComplete(()=>{this.engine.switchScene(e),o.parentNode&&o.parentNode.removeChild(o),this.isTransitioning=!1,n.onComplete&&n.onComplete()}).start(),this}zoom(e,t=1e3,s={}){if(this.isTransitioning)return;this.isTransitioning=!0;const n=document.createElement("div");return n.style.position="absolute",n.style.top="0",n.style.left="0",n.style.width="100%",n.style.height="100%",n.style.backgroundColor=s.color||"#000000",n.style.transform="scale(0)",n.style.transformOrigin="center center",n.style.zIndex="9999",n.style.pointerEvents="none",this.engine.stage.appendChild(n),this.engine.tween(n.style,t,"easeInOutQuad").to({transform:"scale(1)"}).onComplete(()=>{this.engine.switchScene(e),n.style.transform="scale(1)",this.engine.tween(n.style,t,"easeInOutQuad").to({transform:"scale(0)"}).onComplete(()=>{n.parentNode&&n.parentNode.removeChild(n),this.isTransitioning=!1,s.onComplete&&s.onComplete()}).start()}).start(),this}flip(e,t=1e3,s={}){if(this.isTransitioning)return;this.isTransitioning=!0;const n=document.createElement("div");n.style.position="relative",n.style.width="100%",n.style.height="100%",n.style.perspective="1000px";const i=document.createElement("div");i.style.position="absolute",i.style.width="100%",i.style.height="100%",i.style.transformStyle="preserve-3d",i.style.transition=`transform ${t}ms ease-in-out`;const o=document.createElement("div");o.style.position="absolute",o.style.width="100%",o.style.height="100%",o.style.backfaceVisibility="hidden",o.style.backgroundColor=s.color||"#000000";const r=document.createElement("div");return r.style.position="absolute",r.style.width="100%",r.style.height="100%",r.style.backfaceVisibility="hidden",r.style.backgroundColor=s.color||"#000000",r.style.transform="rotateY(180deg)",i.appendChild(o),i.appendChild(r),n.appendChild(i),this.engine.stage.appendChild(n),setTimeout(()=>{i.style.transform="rotateY(180deg)",setTimeout(()=>{this.engine.switchScene(e),i.style.transform="rotateY(0deg)",setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),this.isTransitioning=!1,s.onComplete&&s.onComplete()},t)},t)},50),this}}class B{constructor(e,t={}){this.engine=e,this.x=t.x||0,this.y=t.y||0,this.width=t.width||e.width,this.height=t.height||e.height,this.zoom=t.zoom||1,this.rotation=t.rotation||0,this.following=null,this.followOffset={x:0,y:0},this.bounds=t.bounds||null,this.shakeIntensity=0,this.shakeDuration=0,this.shakeTimer=0}setPosition(e,t){return this.x=e,this.y=t,this.applyBounds(),this}move(e,t){return this.x+=e,this.y+=t,this.applyBounds(),this}setZoom(e){return this.zoom=e,this}setRotation(e){return this.rotation=e,this}follow(e,t={x:0,y:0}){return this.following=e,this.followOffset=t,this}unfollow(){return this.following=null,this}setBounds(e){return this.bounds=e,this.applyBounds(),this}applyBounds(){if(this.bounds){const{minX:e,minY:t,maxX:s,maxY:n}=this.bounds;this.x=Math.max(e,Math.min(s,this.x)),this.y=Math.max(t,Math.min(n,this.y))}}shake(e,t){return this.shakeIntensity=e,this.shakeDuration=t,this.shakeTimer=t,this}update(e){this.following&&(this.x=this.following.x-this.width/2/this.zoom+this.followOffset.x,this.y=this.following.y-this.height/2/this.zoom+this.followOffset.y,this.applyBounds()),this.shakeTimer>0&&(this.shakeTimer-=e,this.shakeTimer<=0&&(this.shakeTimer=0,this.shakeIntensity=0))}apply(){if(!this.engine.stage)return;const e=this.width/2,t=this.height/2;let s=0,n=0;this.shakeIntensity>0&&this.shakeTimer>0&&(s=(Math.random()-.5)*this.shakeIntensity*2,n=(Math.random()-.5)*this.shakeIntensity*2);const i=e-this.x*this.zoom+s,o=t-this.y*this.zoom+n;let r=`translate(${i}px, ${o}px)`;this.zoom!==1&&(r+=` scale(${this.zoom})`),this.rotation!==0&&(r+=` rotate(${this.rotation}deg)`),this.engine.stage.style.transform=r,this.engine.stage.style.transformOrigin=`${e}px ${t}px`}worldToScreen(e,t){return{x:(e-this.x)*this.zoom+this.width/2,y:(t-this.y)*this.zoom+this.height/2}}screenToWorld(e,t){return{x:(e-this.width/2)/this.zoom+this.x,y:(t-this.height/2)/this.zoom+this.y}}getViewBounds(){const e=this.width/2/this.zoom,t=this.height/2/this.zoom;return{left:this.x-e,right:this.x+e,top:this.y-t,bottom:this.y+t,width:e*2,height:t*2}}}class H{constructor(e){this.engine=e,this.elements=[],this.canvas=null,this.context=null,this.setupCanvas(),this.setupEventListeners()}setupCanvas(){this.canvas=document.createElement("canvas"),this.canvas.width=this.engine.width,this.canvas.height=this.engine.height,this.canvas.style.position="absolute",this.canvas.style.top="0",this.canvas.style.left="0",this.canvas.style.pointerEvents="none",this.context=this.canvas.getContext("2d"),this.engine.stage.appendChild(this.canvas)}setupEventListeners(){this.engine.stage.addEventListener("mousemove",e=>{const t=this.engine.stage.getBoundingClientRect(),s=e.clientX-t.left,n=e.clientY-t.top;this.handleMouseMove(s,n)}),this.engine.stage.addEventListener("mousedown",e=>{const t=this.engine.stage.getBoundingClientRect(),s=e.clientX-t.left,n=e.clientY-t.top;this.handleMouseDown(s,n)}),this.engine.stage.addEventListener("mouseup",e=>{const t=this.engine.stage.getBoundingClientRect(),s=e.clientX-t.left,n=e.clientY-t.top;this.handleMouseUp(s,n)})}handleMouseMove(e,t){this.elements.forEach(s=>{if(s.enabled&&s.visible){const n=s.isHovered,i=s.containsPoint(e,t);i&&!n&&s.onMouseEnter?s.onMouseEnter():!i&&n&&s.onMouseLeave&&s.onMouseLeave(),s.isDragging&&s.onMouseMove&&s.onMouseMove(e,t)}})}handleMouseDown(e,t){for(let s=this.elements.length-1;s>=0;s--){const n=this.elements[s];if(n.enabled&&n.visible&&n.containsPoint(e,t)){n.onMouseDown&&n.onMouseDown(e,t);break}}}handleMouseUp(e,t){this.elements.forEach(s=>{s.enabled&&s.visible&&s.onMouseUp&&s.onMouseUp(e,t)})}addElement(e){return this.elements.push(e),this}removeElement(e){const t=this.elements.indexOf(e);return t!==-1&&this.elements.splice(t,1),this}update(e){this.elements.forEach(t=>{t.update&&t.update(e)})}render(){this.context&&(this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.elements.forEach(e=>{e.visible&&e.render&&e.render(this.context)}))}resize(e,t){this.canvas&&(this.canvas.width=e,this.canvas.height=t)}destroy(){this.elements.forEach(e=>{e.destroy&&e.destroy()}),this.elements=[],this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas),this.canvas=null,this.context=null}}class V{constructor(e,t,s="linear"){this.target=e,this.duration=t,this.easing=this.getEasingFunction(s),this.startTime=null,this.startValues={},this.endValues={},this.onUpdate=null,this.onComplete=null,this.onRepeat=null,this.delayTime=0,this.repeatCount=0,this.yoyo=!1,this.isYoyoBack=!1,this.isPaused=!1,this.isReversed=!1,this.progress=0}to(e){for(let t in e)if(typeof this.target[t]=="number")this.startValues[t]=this.target[t];else if(this.target.element&&this.target.element.style){const s=getComputedStyle(this.target.element);if(t==="opacity")this.startValues[t]=parseFloat(s[t])||1;else if(t==="scale"){const i=s.transform.match(/scale\(([^)]+)\)/);this.startValues[t]=i?parseFloat(i[1]):1}else if(t==="rotate"){const i=s.transform.match(/rotate\(([^)]+)deg\)/);this.startValues[t]=i?parseFloat(i[1]):0}else this.startValues[t]=parseFloat(s[t])||0}return this.endValues=e,this}from(e){for(let t in e)typeof this.target[t]=="number"?(this.startValues[t]=e[t],this.target[t]=e[t]):this.target.element&&this.target.element.style&&(t==="opacity"?(this.startValues[t]=e[t],this.target.element.style[t]=e[t]):t==="scale"?(this.startValues[t]=e[t],this.target.element.style.transform=`scale(${e[t]})`):t==="rotate"?(this.startValues[t]=e[t],this.target.element.style.transform=`rotate(${e[t]}deg)`):(this.startValues[t]=e[t],this.target.element.style[t]=`${e[t]}px`));return this}delay(e){return this.delayTime=e,this}repeat(e){return this.repeatCount=e,this}yoyo(e=!0){return this.yoyo=e,this}reverse(){return this.isReversed=!this.isReversed,this}pause(){return this.isPaused=!0,this}resume(){return this.isPaused&&(this.isPaused=!1,this.startTime=performance.now()-this.progress*this.duration,this.animate()),this}stop(){return this.startTime=null,this}start(){return this.delayTime>0?setTimeout(()=>{this._startAnimation()},this.delayTime):this._startAnimation(),this}_startAnimation(){return this.startTime=performance.now(),this.isPaused=!1,this.isReversed=!1,this.isYoyoBack=!1,this.animate(),this}animate(){if(this.isPaused||!this.startTime)return;const t=performance.now()-this.startTime;let s=Math.min(t/this.duration,1);this.isReversed&&(s=1-s),this.yoyo&&this.isYoyoBack&&(s=1-s),this.progress=s;const n=this.easing(s);for(let i in this.endValues){const o=this.startValues[i],r=this.endValues[i],a=o+(r-o)*n;if(typeof this.target[i]=="number")this.target[i]=a;else if(this.target.element&&this.target.element.style)if(i==="opacity")this.target.element.style[i]=a;else if(i==="scale"){const d=(this.target.element.style.transform||"").replace(/scale\([^)]+\)/,"")+` scale(${a})`;this.target.element.style.transform=d}else if(i==="rotate"){const d=(this.target.element.style.transform||"").replace(/rotate\([^)]+\)/,"")+` rotate(${a}deg)`;this.target.element.style.transform=d}else this.target.element.style[i]=`${a}px`}this.onUpdate&&this.onUpdate(n,this.target),s<1?requestAnimationFrame(()=>this.animate()):this.repeatCount>0?(this.repeatCount--,this.yoyo&&(this.isYoyoBack=!this.isYoyoBack),this.startTime=performance.now(),this.onRepeat&&this.onRepeat(),requestAnimationFrame(()=>this.animate())):this.repeatCount===-1?(this.yoyo&&(this.isYoyoBack=!this.isYoyoBack),this.startTime=performance.now(),this.onRepeat&&this.onRepeat(),requestAnimationFrame(()=>this.animate())):this.onComplete&&this.onComplete(this.target)}onUpdate(e){return this.onUpdate=e,this}onComplete(e){return this.onComplete=e,this}onRepeat(e){return this.onRepeat=e,this}chain(...e){if(this.onComplete){const t=this.onComplete;this.onComplete=s=>{t(s),e.forEach(n=>n.start())}}else this.onComplete=()=>{e.forEach(t=>t.start())};return this}getEasingFunction(e){const t={linear:s=>s,easeInQuad:s=>s*s,easeOutQuad:s=>s*(2-s),easeInOutQuad:s=>s<.5?2*s*s:-1+(4-2*s)*s,easeInCubic:s=>s*s*s,easeOutCubic:s=>--s*s*s+1,easeInOutCubic:s=>s<.5?4*s*s*s:(s-1)*(2*s-2)*(2*s-2)+1,easeInQuart:s=>s*s*s*s,easeOutQuart:s=>1- --s*s*s*s,easeInOutQuart:s=>s<.5?8*s*s*s*s:1-8*--s*s*s*s,easeInQuint:s=>s*s*s*s*s,easeOutQuint:s=>1+--s*s*s*s*s,easeInOutQuint:s=>s<.5?16*s*s*s*s*s:1+16*--s*s*s*s*s,easeInSine:s=>1-Math.cos(s*Math.PI/2),easeOutSine:s=>Math.sin(s*Math.PI/2),easeInOutSine:s=>-(Math.cos(Math.PI*s)-1)/2,easeInExpo:s=>s===0?0:Math.pow(2,10*(s-1)),easeOutExpo:s=>s===1?1:1-Math.pow(2,-10*s),easeInOutExpo:s=>s===0?0:s===1?1:s<.5?Math.pow(2,20*s-10)/2:(2-Math.pow(2,-20*s+10))/2,easeInCirc:s=>1-Math.sqrt(1-s*s),easeOutCirc:s=>Math.sqrt(1- --s*s),easeInOutCirc:s=>s<.5?(1-Math.sqrt(1-4*s*s))/2:(Math.sqrt(1-4*--s*s)+1)/2,easeInBack:s=>s*s*(2.70158*s-1.70158),easeOutBack:s=>--s*s*(2.70158*s+1.70158)+1,easeInOutBack:s=>{const n=2.5949095;return s<.5?s*s*(2*s*n+2*s-n)/2:(2*(s-1)*(s-1)*(2*(s-1)*n+2*(s-1)+n)+2)/2},easeInElastic:s=>s===0?0:s===1?1:-Math.pow(2,10*(s-1))*Math.sin((s-1.1)*5*Math.PI),easeOutElastic:s=>s===0?0:s===1?1:Math.pow(2,-10*s)*Math.sin((s-.1)*5*Math.PI)+1,easeInOutElastic:s=>s===0?0:s===1?1:s<.5?-(Math.pow(2,20*s-10)*Math.sin((20*s-11.125)*Math.PI/4.5))/2:Math.pow(2,-20*s+10)*Math.sin((20*s-11.125)*Math.PI/4.5)/2+1,easeInBounce:s=>1-this.getEasingFunction("easeOutBounce")(1-s),easeOutBounce:s=>s<.36363636363636365?7.5625*s*s:s<.7272727272727273?7.5625*(s-=.5454545454545454)*s+.75:s<.9090909090909091?7.5625*(s-=.8181818181818182)*s+.9375:7.5625*(s-=.9545454545454546)*s+.984375,easeInOutBounce:s=>s<.5?(1-this.getEasingFunction("easeOutBounce")(1-2*s))/2:(1+this.getEasingFunction("easeOutBounce")(2*s-1))/2};return t[e]||t.linear}}class G{constructor(){this.tweens=[],this.groups=new Map,this.timelines=[]}tween(e,t,s){const n=new V(e,t,s);return this.tweens.push(n),n}createGroup(e){const t={name:e,tweens:[],paused:!1};return this.groups.set(e,t),t}addToGroup(e,t){const s=this.groups.get(e);return s&&s.tweens.push(t),this}playGroup(e){const t=this.groups.get(e);return t&&(t.paused=!1,t.tweens.forEach(s=>{s.isPaused?s.resume():s.startTime||s.start()})),this}pauseGroup(e){const t=this.groups.get(e);return t&&(t.paused=!0,t.tweens.forEach(s=>s.pause())),this}stopGroup(e){const t=this.groups.get(e);return t&&(t.tweens.forEach(s=>s.stop()),t.tweens=[]),this}createTimeline(){const e={tweens:[],currentTime:0,duration:0,playing:!1,onComplete:null};return this.timelines.push(e),e}addtoTimeline(e,t,s=0){return e.tweens.push({tween:t,startTime:s,endTime:s+t.duration}),e.duration=Math.max(e.duration,s+t.duration),this}playTimeline(e){e.playing=!0;const t=performance.now(),s=()=>{if(!e.playing)return;const n=performance.now()-t;e.currentTime=n,e.tweens.forEach(i=>{const{tween:o,startTime:r}=i;if(n>=r&&n<i.endTime){const a=(n-r)/o.duration;o.startTime||(o.startTime=performance.now()-a*o.duration),o.progress=a}}),n<e.duration?requestAnimationFrame(s):(e.playing=!1,e.onComplete&&e.onComplete())};return s(),this}pauseTimeline(e){return e.playing=!1,this}stopTimeline(e){return e.playing=!1,e.currentTime=0,e.tweens.forEach(t=>{t.tween.stop()}),this}update(){this.tweens=this.tweens.filter(e=>e.startTime!==null&&performance.now()-e.startTime<e.duration);for(const[e,t]of this.groups)t.tweens=t.tweens.filter(s=>s.startTime!==null&&performance.now()-s.startTime<s.duration)}stop(e){this.tweens=this.tweens.filter(t=>t.target!==e);for(const[t,s]of this.groups)s.tweens=s.tweens.filter(n=>n.target!==e);return this}pause(e){return this.tweens.filter(t=>t.target===e).forEach(t=>t.pause()),this}resume(e){return this.tweens.filter(t=>t.target===e).forEach(t=>t.resume()),this}stopAll(){this.tweens.forEach(e=>e.stop()),this.tweens=[];for(const[e,t]of this.groups)t.tweens.forEach(s=>s.stop()),t.tweens=[];return this.timelines.forEach(e=>this.stopTimeline(e)),this}pauseAll(){this.tweens.forEach(e=>e.pause());for(const[e,t]of this.groups)t.tweens.forEach(s=>s.pause()),t.paused=!0;return this.timelines.forEach(e=>this.pauseTimeline(e)),this}resumeAll(){this.tweens.forEach(e=>e.resume());for(const[e,t]of this.groups)t.tweens.forEach(s=>s.resume()),t.paused=!1;return this.timelines.forEach(e=>{e.currentTime<e.duration&&this.playTimeline(e)}),this}}class z{constructor(e){this.engine=e,this.animations=new Map,this.sequences=new Map,this.currentSequence=null}createFrameAnimation(e,t,s=10){const n={name:e,frames:t,frameRate:s,currentFrame:0,duration:t.length/s*1e3,loop:!1,onComplete:null,onLoop:null};return this.animations.set(e,n),n}playFrameAnimation(e,t,s=!1){const n=this.animations.get(t);if(!n){console.warn(`Animation ${t} not found`);return}n.loop=s,n.currentFrame=0,n.playing=!0;const i=()=>{if(!n.playing)return;const o=n.frames[n.currentFrame];if(o&&e.imgElement&&(e.imgElement.src=o),n.currentFrame++,n.currentFrame>=n.frames.length)if(n.loop)n.currentFrame=0,n.onLoop&&n.onLoop();else{n.playing=!1,n.onComplete&&n.onComplete();return}setTimeout(i,1e3/n.frameRate)};return i(),n}stopFrameAnimation(e){const t=this.animations.get(e);return t&&(t.playing=!1),this}createSequence(e,t){const s={name:e,animations:t,currentIndex:0,loop:!1,onComplete:null,onLoop:null};return this.sequences.set(e,s),s}playSequence(e,t=!1){const s=this.sequences.get(e);if(!s){console.warn(`Sequence ${e} not found`);return}s.loop=t,s.currentIndex=0,this.currentSequence=s;const n=()=>{if(s.currentIndex>=s.animations.length)if(s.loop)s.currentIndex=0,s.onLoop&&s.onLoop();else{this.currentSequence=null,s.onComplete&&s.onComplete();return}const i=s.animations[s.currentIndex],{sprite:o,animationName:r,duration:a}=i;this.playFrameAnimation(o,r),setTimeout(()=>{s.currentIndex++,n()},a||1e3)};return n(),s}stopSequence(){return this.currentSequence&&(this.currentSequence.currentIndex=this.currentSequence.animations.length,this.currentSequence=null),this}onAnimationComplete(e,t){const s=this.animations.get(e);return s&&(s.onComplete=t),this}onSequenceComplete(e,t){const s=this.sequences.get(e);return s&&(s.onComplete=t),this}onLoop(e,t){const s=this.animations.get(e);return s&&(s.onLoop=t),this}}class y{constructor(e="div",t){this.element=document.createElement(e),this.element.style.position="absolute",this.engineId=t,this.x=0,this.y=0,this.width=0,this.height=0}setPosition(e=0,t=0){this.element.style.left=`${e}px`,this.element.style.top=`${t}px`,this.x=e,this.y=t}setSize(e=0,t=0){e&&(this.element.style.width=typeof e=="number"?`${e}px`:e,this.width=e),t&&(this.element.style.height=typeof t=="number"?`${t}px`:t,this.height=t)}setStyle(e){Object.assign(this.element.style,e)}add(e){e&&this.element.appendChild(e.element||e)}remove(e){e&&this.element.removeChild(e.element||e)}on(e,t){this.element.addEventListener(e,t)}off(e,t){this.element.removeEventListener(e,t)}hide(){this.element.style.display="none"}show(){this.element.style.display="block"}}class R extends y{constructor(e,t,s,n,i,o){super("div",o),this.imgElement=document.createElement("img"),e&&e.src?this.imgElement.src=e.src:(this.imgElement.style.backgroundColor="blue",this.imgElement.style.borderRadius="50%",this.imgElement.style.width="100%",this.imgElement.style.height="100%"),this.imgElement.style.cssText="-webkit-user-drag: none; user-drag: none;",this.element.appendChild(this.imgElement),this.setPosition(t,s),this.setSize(n,i),this.element.setAttribute("data-sprite-id",o),this.element.style.zIndex="100",this.element.style.overflow="hidden",this.name=r=>this.element.setAttribute("data-name",r),this.animate=r=>this.element.style.animation=r}}class q extends y{constructor(e,t,s,n,i){super("div",i),this.setPosition(e,t),this.setSize(s,n),this.element.setAttribute("data-box-id",i),this.element.style.zIndex="100",this.element.style.backgroundColor="lightgray",this.element.style.border="1px solid black"}}class D extends y{constructor(e,t,s,n){super("div",n),this.element.innerText=e,this.setPosition(t,s),this.element.setAttribute("data-text-id",n),this.element.style.zIndex="100",this.element.style.color="black",this.element.style.fontSize="16px",this.set=i=>this.element.innerText=i,this.setColor=i=>this.element.style.color=i,this.setFont=i=>this.element.style.font=i}}class Y extends y{constructor(e,t,s,n){super("div",n),this.element.innerHTML=e,this.setPosition(t,s),this.element.setAttribute("data-html-id",n),this.set=i=>this.element.innerHTML=i,this.get=()=>this.element.innerHTML,this.getSize=()=>{const i=this.element.getBoundingClientRect();return{width:i.width,height:i.height}}}}class X extends y{constructor(e,t,s,n,i,o){super("div",o),this.element.innerHTML=i,this.setPosition(e,t),this.setSize(s,n),this.element.setAttribute("data-svg-id",o),this.setContent=r=>this.element.innerHTML=r}}class U{constructor(){typeof window<"u"&&(window.PE_ENGINE=this);const e={width:800,height:600,background:"#f0f0f0",fps:60};this.options={...e},this.width=this.options.width,this.height=this.options.height,this.element=document.body,this.id=Date.now().toString(16),this.fps=this.options.fps,this.frameTime=1e3/this.fps,this.lastFrameTime=0,this.running=!1,this.eventBus=new $,this.resourceManager=new F,this.audioManager=new O,this.transitionManager=new _(this),this.camera=new B(this),this.animationSystem=new G,this.animationController=new z(this),this.routes=[],this.scenes=new Map,this.currentScene=null,this.currentPath=null,this.onLoadCallbacks=[],this.onShowCallbacks=[],this.onHideCallbacks=[],this.onDestoryCallbacks=[],this.gameObjects=[],this.timers=[],this.intervals=[],this.input={mouse:{x:0,y:0,isDown:!1},keyboard:{}},this.plugins=new Map,this.createStage(),this.uiManager=new H(this),this.setupInputHandlers(),this.startGameLoop(),this.loadRoutesFromConfig()}createStage(){for(;this.element.firstChild;)this.element.removeChild(this.element.firstChild);this.stage=document.createElement("div"),this.stage.setAttribute("data-engine-id",this.id),Object.assign(this.stage.style,{width:`${this.options.width}px`,height:`${this.options.height}px`,position:"relative",userSelect:"none",overflow:"hidden",background:this.options.background,transform:"translateZ(0)",border:"2px solid red",margin:"0 auto",zIndex:"1"}),this.stage.add=e=>e&&this.stage.appendChild(e.element||e),this.stage.remove=e=>e&&this.stage.removeChild(e.element||e),this.element.appendChild(this.stage),console.log("Stage created")}setupInputHandlers(){this.stage.addEventListener("mousemove",e=>{const t=this.stage.getBoundingClientRect();this.input.mouse.x=e.clientX-t.left,this.input.mouse.y=e.clientY-t.top,this.eventBus.emit("mouseMove",{x:this.input.mouse.x,y:this.input.mouse.y})}),this.stage.addEventListener("mousedown",e=>{this.input.mouse.isDown=!0,this.eventBus.emit("mouseDown",{x:this.input.mouse.x,y:this.input.mouse.y})}),this.stage.addEventListener("mouseup",e=>{this.input.mouse.isDown=!1,this.eventBus.emit("mouseUp",{x:this.input.mouse.x,y:this.input.mouse.y})}),document.addEventListener("keydown",e=>{this.input.keyboard[e.key]=!0,this.eventBus.emit("keyDown",{key:e.key,code:e.code})}),document.addEventListener("keyup",e=>{this.input.keyboard[e.key]=!1,this.eventBus.emit("keyUp",{key:e.key,code:e.code})})}async loadRoutesFromConfig(){try{const e=await N(()=>import("./sences-2e06be56.js"),[]);if(this.routes=e.default.sence||e.sence||[],console.log("Routes loaded:",this.routes),this.routes&&this.routes.length>0){const t=this.routes[0];setTimeout(()=>{console.log("Switching to default route:",t.path),this.switchToPath(t.path)},100)}}catch(e){console.warn("Failed to load routes config:",e)}}startGameLoop(){this.running=!0;const e=t=>{if(!this.running)return;this.lastFrameTime||(this.lastFrameTime=t);const s=t-this.lastFrameTime;this.lastFrameTime=t,s>=this.frameTime&&(this.update(s),this.render()),requestAnimationFrame(e)};requestAnimationFrame(e)}stopGameLoop(){this.running=!1}update(e){this.camera.update(e),this.uiManager.update(e),this.animationSystem.update(),this.gameObjects.forEach(t=>{t.update&&t.update(e)}),this.timers=this.timers.filter(t=>(t.remaining-=e,t.remaining<=0?(t.callback(),!1):!0))}render(){this.camera.apply(),this.gameObjects.forEach(e=>{e.render&&e.render()}),this.uiManager.render()}addGameObject(e){return this.gameObjects.push(e),e.element&&this.stage.add(e),this}removeGameObject(e){const t=this.gameObjects.indexOf(e);return t!==-1&&(this.gameObjects.splice(t,1),e.element&&e.element.parentNode&&this.stage.remove(e)),this}setTimeout(e,t){const s={callback:e,remaining:t};return this.timers.push(s),s}clearTimeout(e){const t=this.timers.indexOf(e);return t!==-1&&this.timers.splice(t,1),this}setInterval(e,t){const s=setInterval(e,t);return this.intervals.push(s),s}clearInterval(e){const t=this.intervals.indexOf(e);return t!==-1&&(clearInterval(e),this.intervals.splice(t,1)),this}checkCollision(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}use(e,t={}){return this.plugins.has(e.name)?(console.warn(`Plugin ${e.name} is already installed.`),this):(typeof e.install=="function"&&(e.install(this,t),this.plugins.set(e.name,e)),this)}load(e){return this.resourceManager.load(e)}loadSound(e,t,s){return this.audioManager.loadSound(e,t,s)}loadMusic(e,t,s){return this.audioManager.loadMusic(e,t,s)}playSound(e,t){return this.audioManager.playSound(e,t)}playMusic(e,t){return this.audioManager.playMusic(e,t)}stopMusic(e){return this.audioManager.stopMusic(e)}pauseMusic(e){return this.audioManager.pauseMusic(e)}resumeMusic(e){return this.audioManager.resumeMusic(e)}setMasterVolume(e){return this.audioManager.setMasterVolume(e)}setSoundVolume(e){return this.audioManager.setSoundVolume(e)}setMusicVolume(e){return this.audioManager.setMusicVolume(e)}addUIElement(e){return this.uiManager.addElement(e)}removeUIElement(e){return this.uiManager.removeElement(e)}findRouteByPath(e){const t=s=>{for(const n of s){if(n.path===e)return n;if(n.extend){const i=t(n.extend);if(i)return i}}return null};return t(this.routes)}async loadSceneByPath(e){if(this.scenes.has(e)){const s=this.scenes.get(e);return s&&s.container&&(s.container.style.display="block",s.container.style.visibility="visible"),s}if(!this.findRouteByPath(e))throw new Error(`Route not found for path: ${e}`);try{const s=e==="/"?"/index":e,n=`/sence${s}/index.pe`;console.log("Loading scene from:",n);const i=await fetch(n).then(l=>{if(!l.ok)throw new Error(`Failed to load scene: ${l.status} ${l.statusText}`);return l.text()}),o=`/sence${s}/index.less`;console.log("Loading scene style from:",o);let r="";try{try{const l=await A(Object.assign({}),`../../template-example/compiled-styles${s}/index.js`);r=l.default||l.style||"",console.log("Loaded compiled scene style")}catch{console.log("Compiled style not found, falling back to dynamic loading"),r=await fetch(o).then(d=>d.ok?d.text():(console.warn(`Failed to load scene style: ${d.status} ${d.statusText}`),"")),o.endsWith(".less")&&r.includes("{")&&(r=this.compileLessToCss(r))}}catch(l){console.warn(`Failed to load scene style for path: ${e}`,l)}const a=this.parseSceneFile(i,r,e);return this.scenes.set(e,a),a}catch(s){throw console.error(`Failed to load scene for path: ${e}`,s),s}}parseSceneFile(e,t,s){console.log("Parsing scene file for path:",s);const n=e.match(/<sence>([\s\S]*?)<\/sence>/i),i=n?n[1].trim():"",o=e.match(/<script>([\s\S]*?)<\/script>/i),r=o?o[1].trim():"",a={path:s,template:i,script:r,style:t,data:{},elements:new Map,container:null,callbacks:{onLoad:[],onShow:[],onHide:[],onDestory:[]}};return a.container=document.createElement("div"),a.container.classList.add("pe-scene-container"),a.container.setAttribute("data-scene-path",s),this.stage.appendChild(a.container),console.log("Scene container created for path:",s),t&&this.applySceneStyle(a,t),r&&this.parseSceneScript(a,r),i&&this.parseSceneTemplate(a,i),console.log("Scene parsed, container children:",a.container.children.length),a}applySceneStyle(e,t){const s=`pe-scene-${Date.now()}-${Math.random().toString(36).substr(2,9)}`;e.sceneId=s;const n=`
[data-scene-id="${s}"] {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: block;
border: 2px dashed green;
z-index: 10;
background-color: rgba(255, 255, 255, 0.9);
visibility: visible;
overflow: hidden;
}
[data-scene-id="${s}"].pe-scene-inactive {
display: none;
visibility: hidden;
}
[data-scene-id="${s}"].pe-scene-active {
display: block;
visibility: visible;
z-index: 20;
background-color: white;
}
[data-scene-id="${s}"] .pe-element {
position: absolute;
}
${t}
`,i=document.createElement("style");i.textContent=n,e.container.appendChild(i),e.container.setAttribute("data-scene-id",s),e.container.classList.add("pe-scene-container")}parseSceneTemplate(e,t){console.log("Parsing scene template");const s=document.createElement("div");s.innerHTML=t.trim();const n=Array.from(s.children);for(let i=0;i<n.length;i++){const o=n[i];this.parseElement(e,o,i)}console.log("Scene template parsed, container children:",e.container.children.length)}parseElement(e,t,s,n=null){const i=t.tagName.toLowerCase(),o=t.className,r=t.getAttribute("@click"),a=t.getAttribute("for");if(console.log(`Parsing element: ${i}, class: ${o}, for: ${a}`),a){this.parseForLoop(e,t,a,s,n);return}let l;switch(i){case"sprite":const h=parseInt(t.getAttribute("x"))||100,u=parseInt(t.getAttribute("y"))||100,p=parseInt(t.getAttribute("width"))||100,f=parseInt(t.getAttribute("height"))||100;l=this.create("sprite",{x:h,y:u,width:p,height:f});break;case"box":const g=parseInt(t.getAttribute("x"))||100,E=parseInt(t.getAttribute("y"))||250,x=parseInt(t.getAttribute("width"))||200,b=parseInt(t.getAttribute("height"))||100;l=this.create("box",{x:g,y:E,width:x,height:b});break;case"text":const v=parseInt(t.getAttribute("x"))||100,C=parseInt(t.getAttribute("y"))||400;l=this.create("text",{text:t.textContent.trim()||"Text Element",x:v,y:C});break;default:const m=document.createElement("div");m.style.position="absolute";const M=parseInt(t.getAttribute("x"))||100,k=parseInt(t.getAttribute("y"))||500,I=parseInt(t.getAttribute("width"))||150,S=parseInt(t.getAttribute("height"))||100;m.style.left=M+"px",m.style.top=k+"px",m.style.width=I+"px",m.style.height=S+"px",m.style.zIndex="100",m.style.display="flex",m.style.alignItems="center",m.style.justifyContent="center",m.textContent=`Default ${i}`,l=m}if(o){const h=l.element||l;h instanceof HTMLElement&&h.classList.add(o)}if(t.textContent&&i!=="text"){const h=t.textContent.trim();if(h){const u=l.element||l;u instanceof HTMLElement&&(u.textContent=h)}}if(r){const h=l.element||l;if(h instanceof HTMLElement)try{h.addEventListener("click",u=>{try{const p=window.PE_ENGINE.currentScene,f={event:u};p&&p.data&&Object.assign(f,p.data),n&&Object.assign(f,n),new Function("scope","event",`
with (scope) {
${r}
}
`)(f,u)}catch(p){console.error("Error in click handler:",p)}})}catch(u){console.error("Error binding click handler:",u)}}const d=l.element||l;if(d instanceof HTMLElement&&(d.classList.add("pe-element"),o&&o.split(" ").forEach(u=>{u.trim()&&d.classList.add(u.trim())}),e.elements.set(o||`element_${s}`,{element:d,peElement:l,type:i}),e.container.appendChild(d),d.style.zIndex="100",console.log(`Added element: ${i} with class: ${o}`)),!a){const h=Array.from(t.children);for(let u=0;u<h.length;u++)this.parseElement(e,h[u],`${s}_${u}`,n)}}parseForLoop(e,t,s,n,i){console.log("Parsing for loop:",s);const o=s.match(/\{([^}]+)\}\s+in\s+(\w+)/);if(!o){console.warn("Invalid for loop syntax:",s),this.parseElement(e,t,n,i);return}const r=o[1].split(",").map(l=>l.trim()),a=o[2];this.processSingleLoop(e,t,r,a,n)}processSingleLoop(e,t,s,n,i){console.log("Processing loop for array:",n);let o=e.data[n];!o&&typeof window<"u"&&(o=window[n]),Array.isArray(o)?(console.log(`Found array with ${o.length} items`),o.forEach((r,a)=>{console.log("Processing item:",r);const l=t.cloneNode(!0),d=typeof r=="object"?r:{item:r};this.replaceInterpolations(l,d),this.parseElementWithoutForLoop(e,l,`${i}_${a}`,d)})):(console.warn(`Loop array ${n} is not an array or not found`),this.parseElementWithoutForLoop(e,t,i,null))}parseElementWithoutForLoop(e,t,s,n=null){const i=t.tagName.toLowerCase(),o=t.className,r=t.getAttribute("@click");console.log(`Parsing element without for loop: ${i}, class: ${o}`);let a;switch(i){case"sprite":const h=parseInt(t.getAttribute("x"))||100,u=parseInt(t.getAttribute("y"))||100,p=parseInt(t.getAttribute("width"))||100,f=parseInt(t.getAttribute("height"))||100;a=this.create("sprite",{x:h,y:u,width:p,height:f});break;case"box":const g=parseInt(t.getAttribute("x"))||100,E=parseInt(t.getAttribute("y"))||250,x=parseInt(t.getAttribute("width"))||200,b=parseInt(t.getAttribute("height"))||100;a=this.create("box",{x:g,y:E,width:x,height:b});break;case"text":const v=parseInt(t.getAttribute("x"))||100,C=parseInt(t.getAttribute("y"))||400;a=this.create("text",{text:t.textContent.trim()||"Text Element",x:v,y:C});break;default:const m=document.createElement("div");m.style.position="absolute";const M=parseInt(t.getAttribute("x"))||100,k=parseInt(t.getAttribute("y"))||500,I=parseInt(t.getAttribute("width"))||150,S=parseInt(t.getAttribute("height"))||100;m.style.left=M+"px",m.style.top=k+"px",m.style.width=I+"px",m.style.height=S+"px",m.style.zIndex="100",m.style.display="flex",m.style.alignItems="center",m.style.justifyContent="center",m.textContent=`Default ${i}`,a=m}if(o){const h=a.element||a;h instanceof HTMLElement&&h.classList.add(o)}if(t.textContent&&i!=="text"){const h=t.textContent.trim();if(h){const u=a.element||a;u instanceof HTMLElement&&(u.textContent=h)}}if(r){const h=a.element||a;if(h instanceof HTMLElement)try{h.addEventListener("click",u=>{try{const p=window.PE_ENGINE.currentScene,f={event:u};p&&p.data&&Object.assign(f,p.data),n&&Object.assign(f,n),new Function("scope","event",`
with (scope) {
${r}
}
`)(f,u)}catch(p){console.error("Error in click handler:",p)}})}catch(u){console.error("Error binding click handler:",u)}}const l=a.element||a;l instanceof HTMLElement&&(l.classList.add("pe-element"),o&&o.split(" ").forEach(u=>{u.trim()&&l.classList.add(u.trim())}),e.elements.set(o||`element_${s}`,{element:l,peElement:a,type:i}),e.container.appendChild(l),l.style.zIndex="100",console.log(`Added element: ${i} with class: ${o}`));const d=Array.from(t.children);for(let h=0;h<d.length;h++)d[h].getAttribute("for")||this.parseElementWithoutForLoop(e,d[h],`${s}_${h}`,n)}replaceInterpolations(e,t){if(e.textContent){let n=e.textContent;Object.keys(t).forEach(i=>{const o=new RegExp(`{{\\s*${i}\\s*}}`,"g");n=n.replace(o,t[i])}),e.textContent=n}const s=Array.from(e.children);for(let n=0;n<s.length;n++)this.replaceInterpolations(s[n],t)}parseSceneScript(e,t){console.log("Parsing scene script");try{const n=new Function(`
// 提供PE全局对象
const PE = window.PE;
// 定义生命周期函数
const onLoad = (callback) => {
if (typeof window !== 'undefined' && window.PE_ENGINE) {
// 将回调函数存储在全局变量中,稍后在场景创建完成后移动到场景对象中
if (!window.PE_ENGINE.pendingCallbacks) {
window.PE_ENGINE.pendingCallbacks = { onLoad: [], onShow: [], onHide: [], onDestory: [] };
}
window.PE_ENGINE.pendingCallbacks.onLoad.push(callback);
}
};
const onShow = (callback) => {
if (typeof window !== 'undefined' && window.PE_ENGINE) {
if (!window.PE_ENGINE.pendingCallbacks) {
window.PE_ENGINE.pendingCallbacks = { onLoad: [], onShow: [], onHide: [], onDestory: [] };
}
window.PE_ENGINE.pendingCallbacks.onShow.push(callback);
}
};
const onHide = (callback) => {
if (typeof window !== 'undefined' && window.PE_ENGINE) {
if (!window.PE_ENGINE.pendingCallbacks) {
window.PE_ENGINE.pendingCallbacks = { onLoad: [], onShow: [], onHide: [], onDestory: [] };
}
window.PE_ENGINE.pendingCallbacks.onHide.push(callback);
}
};
const onDestory = (callback) => {
if (typeof window !== 'undefined' && window.PE_ENGINE) {
if (!window.PE_ENGINE.pendingCallbacks) {
window.PE_ENGINE.pendingCallbacks = { onLoad: [], onShow: [], onHide: [], onDestory: [] };
}
window.PE_ENGINE.pendingCallbacks.onDestory.push(callback);
}
};
// 执行脚本
${t}
// 返回脚本中定义的变量和函数
return {
boxList: typeof boxList !== 'undefined' ? boxList : undefined,
onMenuClick: typeof onMenuClick !== 'undefined' ? onMenuClick : undefined
};
`)();if(n.boxList&&(e.data.boxList=n.boxList,console.log("BoxList loaded:",e.data.boxList)),n.onMenuClick&&(e.data.onMenuClick=n.onMenuClick),typeof window<"u"&&window.PE_ENGINE&&window.PE_ENGINE.pendingCallbacks){const i=window.PE_ENGINE.pendingCallbacks;e.callbacks.onLoad.push(...i.onLoad),e.callbacks.onShow.push(...i.onShow),e.callbacks.onHide.push(...i.onHide),e.callbacks.onDestory.push(...i.onDestory),window.PE_ENGINE.pendingCallbacks=null}}catch(s){console.error("Error executing scene script:",s)}}async switchToPath(e){try{console.log("Switching to path:",e),this.currentScene&&(this.currentScene.container.classList.remove("pe-scene-active"),this.currentScene.container.classList.add("pe-scene-inactive"),console.log("Hid current scene"));const t=await this.loadSceneByPath(e);return t.container.classList.remove("pe-scene-inactive"),t.container.classList.add("pe-scene-active"),console.log("Showing new scene, children:",t.container.children.length),t.callbacks.onShow.forEach(s=>{try{s()}catch(n){console.error("Error in onShow callback:",n)}}),t.loaded||(t.callbacks.onLoad.forEach(s=>{try{s()}catch(n){console.error("Error in onLoad callback:",n)}}),t.loaded=!0),this.currentScene=t,this.currentPath=e,this.eventBus.emit("sceneChanged",{path:e,scene:t}),t}catch(t){throw console.error(`Failed to switch to scene: ${e}`,t),t}}async preloadScenes(e){const s=(Array.isArray(e)?e:[e]).map(n=>this.loadSceneByPath(n));return Promise.all(s)}getCurrentPath(){return this.currentPath}getCurrentScene(){return this.currentScene}getSceneElement(e){if(this.currentScene&&this.currentScene.elements.has(e)){const t=this.currentScene.elements.get(e);return t.peElement||t.element}return null}getElement(e){return this.getSceneElement(e)}setCameraPosition(e,t){return this.camera.setPosition(e,t)}moveCamera(e,t){return this.camera.move(e,t)}setCameraZoom(e){return this.camera.setZoom(e)}setCameraRotation(e){return this.camera.setRotation(e)}follow(e,t){return this.camera.follow(e,t)}unfollow(){return this.camera.unfollow()}setCameraBounds(e){return this.camera.setBounds(e)}shakeCamera(e,t){return this.camera.shake(e,t)}getCamera(){return this.camera}tween(e,t,s){return this.animationSystem.tween(e,t,s)}createFrameAnimation(e,t,s){return this.animationController.createFrameAnimation(e,t,s)}playFrameAnimation(e,t,s){return this.animationController.playFrameAnimation(e,t,s)}stopFrameAnimation(e){return this.animationController.stopFrameAnimation(e)}createSequence(e,t){return this.animationController.createSequence(e,t)}playSequence(e,t){return this.animationController.playSequence(e,t)}stopSequence(){return this.animationController.stopSequence()}create(e,t={}){switch(e.toLowerCase()){case"sprite":return this.createSprite(t.image,t.x||0,t.y||0,t.width||100,t.height||100);case"box":return this.createBox(t.x||0,t.y||0,t.width||100,t.height||100);case"text":const s=this.createText(t.text||"",t.x||0,t.y||0);return t.style&&s.setStyle(t.style),s;case"html":return this.createHtml(t.html||"",t.x||0,t.y||0);case"svg":return this.createSvg(t.x||0,t.y||0,t.width||100,t.height||100,t.content||"");default:throw new Error(`Unsupported element type: ${e}`)}}createSprite(e,t=0,s=0,n=100,i=100){if(!e){const r=document.createElement("div");return r.style.position="absolute",r.style.left=t+"px",r.style.top=s+"px",r.style.width=n+"px",r.style.height=i+"px",r.setPosition=function(a,l){this.style.left=a+"px",this.style.top=l+"px"},r.setSize=function(a,l){this.style.width=a+"px",this.style.height=l+"px"},{element:r,setPosition:function(a,l){r.setPosition(a,l)},setSize:function(a,l){r.setSize(a,l)}}}return new R(e,t,s,n,i,this.id)}createBox(e=0,t=0,s=100,n=100){const i=new q(e,t,s,n,this.id);return i.element.style.zIndex="100",i.element.style.position="absolute",i}createText(e="",t=0,s=0){const n=new D(e,t,s,this.id);return n.element.style.zIndex="100",n.element.style.position="absolute",n}createHtml(e="",t=0,s=0){return new Y(e,t,s,this.id)}createSvg(e=0,t=0,s=100,n=100,i=""){return new X(e,t,s,n,i,this.id)}destroy(){this.stopGameLoop(),this.scenes.forEach(e=>{e.callbacks&&e.callbacks.onDestory&&e.callbacks.onDestory.forEach(t=>{try{t()}catch(s){console.error("Error in onDestory callback:",s)}})}),this.stage&&this.stage.parentNode&&this.stage.parentNode.removeChild(this.stage),this.resourceManager.clear(),this.animationSystem.stopAll(),this.uiManager.destroy(),this.intervals.forEach(e=>clearInterval(e)),this.intervals=[],this.stage=null,this.element=null,this.options=null,this.gameObjects=[],this.timers=[],typeof window<"u"&&window.PE_ENGINE===this&&(window.PE_ENGINE=null)}}class W{static create(){return new U}static get version(){return"1.0.0"}static navigateTo(e){typeof window<"u"&&window.PE_ENGINE?window.PE_ENGINE.switchToPath(e):console.warn("PE engine not initialized")}}const w={onLoad:c=>{typeof window<"u"&&window.PE_ENGINE?window.PE_ENGINE.onLoadCallbacks.push(c):console.warn("PE engine not initialized")},onShow:c=>{typeof window<"u"&&window.PE_ENGINE?window.PE_ENGINE.onShowCallbacks.push(c):console.warn("PE engine not initialized")},onHide:c=>{typeof window<"u"&&window.PE_ENGINE?window.PE_ENGINE.onHideCallbacks.push(c):console.warn("PE engine not initialized")},onDestory:c=>{typeof window<"u"&&window.PE_ENGINE?window.PE_ENGINE.onDestoryCallbacks.push(c):console.warn("PE engine not initialized")}};typeof window<"u"&&(window.onLoad=w.onLoad,window.onShow=w.onShow,window.onHide=w.onHide,window.onDestory=w.onDestory);function Q(){return{game:W.create()}}Q();