(function(d,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@vnve/core")):typeof define=="function"&&define.amd?define(["exports","@vnve/core"],i):(d=typeof globalThis<"u"?globalThis:d||self,i(d.template={},d.VNVE))})(this,function(d,i){"use strict";var C=Object.defineProperty;var S=(d,i,g)=>i in d?C(d,i,{enumerable:!0,configurable:!0,writable:!0,value:g}):d[i]=g;var a=(d,i,g)=>(S(d,typeof i!="symbol"?i+"":i,g),g);function f(o,u=600){if(!o)return 0;o=o.trim();const t=o.match(/[\u4e00-\u9fa5]/g);let e=0;t!=null&&(e=t.length),o=o.replace(/[\u4e00-\u9fa5]/g," "),o=o.replace(/[\r\n]/g," "),o=o.replace(/\W+/g," ");const s=o.trim().split(/\s+/g).length+e,r=u/60;return parseFloat((s/r*1e3).toFixed(1))}function h(o,u){if(u)return o.find(t=>t.uuid===u.uuid)}function l(o,u){return o.find(t=>t.uuid===u)}class T extends i.Scene{constructor(t){super({duration:t.duration});a(this,"titleText");a(this,"subtitleText");a(this,"backgroundImg");this.type="TitleScene";const e=new i.Text(t.title,{fill:16777215,breakWords:!0,fontSize:i.Converter.fontSize(100),fontWeight:"bold"});e.x=i.Converter.width(1920)/2-e.width/2,e.y=i.Converter.width(1080)/2-200,e.addAnimation({name:"EnterFromTop",value:i.PREST_ANIMATION.EnterFromTop}),this.titleText=e,this.addChild(e);const n=new i.Text(t.subtitle??"副标题",{fill:16777215,breakWords:!0,fontSize:i.Converter.fontSize(60)});n.x=i.Converter.width(1920)/2-n.width/2,n.y=i.Converter.width(1080)/2-40,n.addAnimation({name:"EnterFromBottom",value:i.PREST_ANIMATION.EnterFromBottom}),this.subtitleText=n,this.addChild(n),t.backgroundImgSource&&this.setBackgroundImg(new i.Img({source:t.backgroundImgSource})),t.soundSources&&t.soundSources.forEach(s=>{const r=new i.Sound(s);this.addSound(r)})}setBackgroundImg(t){t.width=i.Converter.width(1920),t.height=i.Converter.height(1080),t.x=0,t.y=0,this.removeBackgroundImg(),this.backgroundImg=t,this.addChild(t),this.setChildToBottom(t)}removeBackgroundImg(){this.backgroundImg&&(this.removeChild(this.backgroundImg),this.backgroundImg=void 0)}clone(){const t=new T({title:"",duration:this.duration});return t.removeChildren(),t.cloneFrom(this),t.titleText=h(t.children,this.titleText),t.subtitleText=h(t.children,this.subtitleText),t.backgroundImg=h(t.children,this.backgroundImg),t}toJSON(){var t,e;return{...super.toJSON(),__type:"TitleScene",type:this.type,titleTextID:this.titleText.uuid,subtitleTextID:(t=this.subtitleText)==null?void 0:t.uuid,backgroundImgID:(e=this.backgroundImg)==null?void 0:e.uuid}}static async fromJSON(t){let e=new T({title:"",duration:0});return e.removeChildren(),e=await i.Scene.fromJSON(t,e),e.titleText=l(e.children,t.titleTextID),e.subtitleText=l(e.children,t.subtitleTextID),e.backgroundImg=l(e.children,t.backgroundImgID),e}}class x extends i.Scene{constructor(t){super({duration:0});a(this,"nameText");a(this,"dialogText");a(this,"dialogRect");a(this,"lines");a(this,"characterImgs");a(this,"backgroundImg");a(this,"dialogImg");a(this,"wordsPerMinute");a(this,"lineDisplayEffect");this.type="DialogueScene",this.wordsPerMinute=t.wordsPerMinute||600,this.lineDisplayEffect=t.lineDisplayEffect||"typewriter";const e=new i.Graphics;e.alpha=.7,e.beginFill(0),e.drawRect(0,0,i.Converter.width(1920),i.Converter.height(400)),e.endFill(),e.x=0,e.y=i.Converter.y(680);const n=new i.Text("角色名",{fill:16777215,fontSize:i.Converter.fontSize(44),fontWeight:"bold"});n.x=i.Converter.x(160),n.y=i.Converter.y(700);const s=new i.Text("角色台词",{fill:16777215,wordWrap:!0,breakWords:!0,wordWrapWidth:i.Converter.width(1600),fontSize:i.Converter.fontSize(38),leading:15});s.x=i.Converter.x(160),s.y=i.Converter.y(770),this.addChild(e),this.addChild(s),this.addChild(n),this.dialogRect=e,this.dialogText=s,this.nameText=n,this.characterImgs=[],this.lines=[],this.setLines(t.lines),t.dialogImgSource&&this.setDialogImg(new i.Img({source:t.dialogImgSource})),t.backgroundImgSource&&this.setBackgroundImg(new i.Img({source:t.backgroundImgSource})),t.soundSources&&t.soundSources.forEach(r=>{const c=new i.Sound(r);this.addSound(c)})}setBackgroundImg(t){t.width=i.Converter.width(1920),t.height=i.Converter.height(1080),t.x=0,t.y=0,this.removeBackgroundImg(),this.backgroundImg=t,this.addChild(t),this.setChildToBottom(t)}removeBackgroundImg(){this.backgroundImg&&(this.removeChild(this.backgroundImg),this.backgroundImg=void 0)}setDialogImg(t){t.x=60,t.y=700,this.removeDialogImg(),this.dialogImg=t,this.addChild(t),this.dialogRect&&(this.setChildIndex(t,this.getChildIndex(this.dialogRect)),this.removeChild(this.dialogRect),this.dialogRect=void 0)}removeDialogImg(){this.dialogImg&&(this.removeChild(this.dialogImg),this.dialogImg=void 0)}addCharacterImg(t){this.characterImgs.push(t),this.addChild(t),this.setChildIndex(t,1)}removeCharacterImg(t){this.characterImgs=this.characterImgs.filter(e=>e.uuid!==t.uuid),this.removeChild(t)}setLines(t){this.lines=t,this.clearLinesAnimation(),this.setLinesAnimation(t);const e=this.getLinesDuration();this.setDuration(e)}getLinesDuration(){if(this.lines.length===0)return 0;const t=this.lines[this.lines.length-1];return t.start+t.duration+(t.gapTime??500)}getLinePositionStartTime(t,e){const n=this.lines[t];let s=n.start;return s+=f(n.content.slice(0,e),this.wordsPerMinute),s}clearLinesAnimation(){var t,e;(t=this.nameText)==null||t.removeAllAnimation(),(e=this.dialogText)==null||e.removeAllAnimation()}setLinesAnimation(t){t.forEach((e,n)=>{var c,m,I,v,y,E;const s=f(e.content,e.wordsPerMinute??this.wordsPerMinute);e.duration=s,e.start=n===0?0:t[n-1].start+t[n-1].duration+(t[n-1].gapTime??500);const r=e.displayEffect??this.lineDisplayEffect;r==="typewriter"?((c=this.nameText)==null||c.addAnimation({value:[{text:""},{text:e.name,delay:e.start,ease:i.Power0.easeNone}]}),(m=this.dialogText)==null||m.addAnimation({value:[{text:""},{text:e.content,duration:e.duration,delay:e.start,ease:i.Power0.easeNone}]})):r==="fadeIn"?((I=this.nameText)==null||I.addAnimation({value:[{text:e.name,alpha:0},{alpha:1,duration:e.duration<500?e.duration:500,delay:e.start}]}),(v=this.dialogText)==null||v.addAnimation({value:[{text:e.content,alpha:0},{alpha:1,duration:e.duration<500?e.duration:500,delay:e.start}]})):r==="none"&&((y=this.nameText)==null||y.addAnimation({value:[{text:""},{text:e.name,delay:e.start,ease:i.Power0.easeNone}]}),(E=this.dialogText)==null||E.addAnimation({value:[{text:""},{text:e.content,delay:e.start,ease:i.Power0.easeNone}]}))})}clone(){const t=new x({lines:this.lines.map(e=>({...e})),lineDisplayEffect:this.lineDisplayEffect,wordsPerMinute:this.wordsPerMinute});return t.removeChildren(),t.cloneFrom(this),t.nameText=h(t.children,this.nameText),t.dialogText=h(t.children,this.dialogText),t.dialogImg=h(t.children,this.dialogImg),t.dialogRect=h(t.children,this.dialogRect),t.backgroundImg=h(t.children,this.backgroundImg),t.characterImgs=this.characterImgs.map(e=>h(t.children,e)).filter(e=>!!e),t}toJSON(){var t,e,n,s,r;return{...super.toJSON(),__type:"DialogueScene",type:this.type,lines:this.lines,wordsPerMinute:this.wordsPerMinute,lineDisplayEffect:this.lineDisplayEffect,nameTextID:(t=this.nameText)==null?void 0:t.uuid,dialogTextID:(e=this.dialogText)==null?void 0:e.uuid,dialogRectID:(n=this.dialogRect)==null?void 0:n.uuid,dialogImgID:(s=this.dialogImg)==null?void 0:s.uuid,backgroundImgID:(r=this.backgroundImg)==null?void 0:r.uuid,characterImgIDs:this.characterImgs.map(c=>c.uuid)}}static async fromJSON(t){let e=new x({lines:t.lines,lineDisplayEffect:t.lineDisplayEffect,wordsPerMinute:t.wordsPerMinute});return e.removeChildren(),e=await i.Scene.fromJSON(t,e),e.nameText=l(e.children,t.nameTextID),e.dialogText=l(e.children,t.dialogTextID),e.dialogRect=l(e.children,t.dialogRectID),e.dialogImg=l(e.children,t.dialogImgID),e.backgroundImg=l(e.children,t.backgroundImgID),e.characterImgs=t.characterImgIDs.map(n=>l(e.children,n)),e.setLines(e.lines),e}}class D extends i.Scene{constructor(t){super({duration:0});a(this,"backgroundImg");a(this,"lineText");a(this,"lines");a(this,"wordsPerMinute");a(this,"lineDisplayEffect");this.type="MonologueScene",this.wordsPerMinute=t.wordsPerMinute||600,this.lineDisplayEffect=t.lineDisplayEffect||"typewriter";const e=new i.Graphics;e.alpha=.7,e.beginFill(0),e.drawRect(0,0,i.Converter.width(1920),i.Converter.height(1080)),e.endFill(),e.x=0,e.y=0,this.addChild(e);const n=new i.Text("独白台词",{fill:16777215,breakWords:!0,wordWrap:!0,wordWrapWidth:i.Converter.width(1600),fontSize:i.Converter.fontSize(45),leading:15});n.x=i.Converter.x(160),n.y=i.Converter.y(160),this.addChild(n),this.lineText=n,this.lines=[],this.setLines(t.lines),t.backgroundImgSource&&this.setBackgroundImg(new i.Img({source:t.backgroundImgSource})),t.soundSources&&t.soundSources.forEach(s=>{const r=new i.Sound(s);this.addSound(r)})}setBackgroundImg(t){t.width=i.Converter.width(1920),t.height=i.Converter.height(1080),t.x=0,t.y=0,this.removeBackgroundImg(),this.backgroundImg=t,this.addChild(t),this.setChildToBottom(t)}removeBackgroundImg(){this.backgroundImg&&(this.removeChild(this.backgroundImg),this.backgroundImg=void 0)}setLines(t){this.lines=t,this.clearLinesAnimation(),this.setLinesAnimation(t);const e=this.getLinesDuration();this.setDuration(e)}getLinesDuration(){if(this.lines.length===0)return 0;const t=this.lines[this.lines.length-1];return t.start+t.duration+(t.gapTime??500)}getLinePositionStartTime(t,e){const n=this.lines[t];let s=n.start;return s+=f(n.content.slice(0,e),this.wordsPerMinute),s}clearLinesAnimation(){var t;(t=this.lineText)==null||t.removeAllAnimation()}setLinesAnimation(t){t.forEach((e,n)=>{var c,m,I;const s=f(e.content,e.wordsPerMinute??this.wordsPerMinute);e.duration=s,e.start=n===0?0:t[n-1].start+t[n-1].duration+(t[n-1].gapTime??500);const r=e.displayEffect??this.lineDisplayEffect;r==="typewriter"?(c=this.lineText)==null||c.addAnimation({value:[{text:""},{text:e.content,duration:e.duration,delay:e.start,ease:i.Power0.easeNone}]}):r==="fadeIn"?(m=this.lineText)==null||m.addAnimation({value:[{text:e.content,alpha:0},{alpha:1,duration:e.duration<500?e.duration:500,delay:e.start}]}):r==="none"&&((I=this.lineText)==null||I.addAnimation({value:[{text:""},{text:e.content,delay:e.start}]}))})}clone(){const t=new D({lines:this.lines.map(e=>({...e})),lineDisplayEffect:this.lineDisplayEffect,wordsPerMinute:this.wordsPerMinute});return t.removeChildren(),t.cloneFrom(this),t.lineText=h(t.children,this.lineText),t.backgroundImg=h(t.children,this.backgroundImg),t}toJSON(){var t,e;return{...super.toJSON(),__type:"MonologueScene",type:this.type,lines:this.lines,wordsPerMinute:this.wordsPerMinute,lineDisplayEffect:this.lineDisplayEffect,lineTextID:(t=this.lineText)==null?void 0:t.uuid,backgroundImgID:(e=this.backgroundImg)==null?void 0:e.uuid}}static async fromJSON(t){let e=new D({lines:t.lines,lineDisplayEffect:t.lineDisplayEffect,wordsPerMinute:t.wordsPerMinute});return e.removeChildren(),e=await i.Scene.fromJSON(t,e),e.lineText=l(e.children,t.lineTextID),e.backgroundImg=l(e.children,t.backgroundImgID),e.setLines(e.lines),e}}d.DialogueScene=x,d.MonologueScene=D,d.TitleScene=T,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});