narraleaf-react
Version:
A React visual novel player framework
6 lines • 211 kB
JavaScript
var ae={action:"displayable:action",applyTransform:"displayable:applyTransform",applyTransition:"displayable:applyTransition",init:"displayable:init"},Dn={say:"character:say",action:"character:action",setName:"character:setName"},_={action:"scene:action",init:"scene:init",exit:"scene:exit",jumpTo:"scene:jumpTo",setBackgroundMusic:"scene:setBackgroundMusic",preUnmount:"scene:preUnmount",transitionToScene:"scene:transitionToScene"};var we={action:"image:action",setSrc:"image:setSrc",flush:"image:flush",initWearable:"image:initWearable",setAppearance:"image:setAppearance",setDarkness:"image:setDarkness"},Ei={action:"condition:action"},Di={action:"script:action"},Ri={action:"menu:action"},mt={action:"sound:action",play:"sound:play",stop:"sound:stop",setVolume:"sound:setVolume",setRate:"sound:setRate",pause:"sound:pause",resume:"sound:resume"},Oe={action:"control:action",do:"control:do",doAsync:"control:doAsync",any:"control:any",all:"control:all",allAsync:"control:allAsync",repeat:"control:repeat",sleep:"control:sleep"},Rn={action:"text:action",setText:"text:setText",setFontSize:"text:setFontSize"},Jt={action:"persistent:action",set:"persistent:set",assign:"persistent:assign"},At={action:"layer:action",setZIndex:"layer:setZIndex"},Gt={action:"video:action",show:"video:show",hide:"video:hide",play:"video:play",pause:"video:pause",resume:"video:resume",stop:"video:stop",seek:"video:seek"};var Li=(d=>(d[d.string=0]="string",d[d.number=1]="number",d[d.boolean=2]="boolean",d[d.object=3]="object",d[d.array=4]="array",d[d.function=5]="function",d[d.symbol=6]="symbol",d[d.undefined=7]="undefined",d[d.null=8]="null",d[d.date=9]="date",d[d.regexp=10]="regexp",d[d.other=11]="other",d))(Li||{}),Go=function(s){return typeof s=="string"?0:typeof s=="number"?1:typeof s=="boolean"?2:typeof s=="object"?Array.isArray(s)?4:s===null?8:s instanceof Date?9:s instanceof RegExp?10:3:typeof s=="function"?5:typeof s=="symbol"?6:typeof s>"u"?7:11};Go.DataTypes=Li;function D(s,e,...t){let n=(r,a)=>Object.prototype.hasOwnProperty.call(r,a),o={},i=(r,a,c)=>Go(a)===3&&Go(c)===3?a.constructor!==Object||c.constructor!==Object?c||a:D(a,c):Array.isArray(a)&&Array.isArray(c)?c&&c.length>0?[...c]:[...a]:a===void 0&&Array.isArray(c)?[...c]:c===void 0?Array.isArray(a)?[...a]:a:Array.isArray(c)?[...c]:c;for(let r in s)n(s,r)&&(o[r]=i(r,s[r],e[r]));for(let r in e)n(e,r)&&!n(o,r)&&(typeof e[r]=="object"&&e[r]!==null?e[r].constructor===Object?o[r]=D({},e[r]):Array.isArray(e[r])?o[r]=[...e[r]]:o[r]=e[r]:o[r]=e[r]);if(t.length){let[r,...a]=t;return D(o,r,...a)}return o}var he=class he{constructor(e=n=>n,t){this.solved=!1;this.aborted=!1;this.listeners=[];this.onRegisterSkipController=[];this.receiver=e,this.skipController=t,this.__stack=No()}static isAwaitable(e){return e instanceof he}static fromPromise(e){let t=new he;return e.then(n=>t.resolve(n)),t}static resolve(e){let t=new he;return t.resolve(e),t}static delay(e){let t=new he;return setTimeout(()=>t.resolve(),e),t}static create(e){let t=new he;return e(t),t}static wait(e){let t=new he;return e.then(()=>t.resolve()),t}static race(e){let t=new he;return e.length===0?(t.resolve(void 0),t):(e.forEach(n=>{n.then(o=>{e.forEach(i=>{i!==n&&i.skipController?.abort()}),t.resolve(o)})}),t.registerSkipController(new L(()=>{e.forEach(n=>n.skipController?.abort())})),t)}static forward(e,t,n){let o=new he().registerSkipController(n||new L(()=>t));e.then(()=>o.resolve(t));let i=e.skipController?.onAbort(()=>{o.skipController?.abort(),i?.cancel(),r?.cancel()}),r=o.skipController?.onAbort(()=>{e.skipController?.abort(),i?.cancel(),r?.cancel()});return o}static toPromise(e){return new Promise(t=>{e.then(t)})}static toPromiseForce(e){return new Promise(t=>{e.onSettled(t)})}static any(...e){let t=new he;return e.forEach(n=>{n.onSettled(()=>t.resolve())}),t}static all(...e){let t=new he,n=0;return e.forEach(o=>{o.onSettled(()=>{n++,n===e.length&&t.resolve()})}),t}registerSkipController(e){this.skipController=e;for(let t of this.onRegisterSkipController)t(e);return this}resolve(e){if(!this.solved){this.result=this.receiver(e),this.solved=!0,this.skipController&&this.skipController.cancel();for(let t of this.listeners)t(this.result)}}then(e){return this.solved?e(this.result):this.pushListener(e),this}onSettled(e){if(this.solved)e();else{this.pushListener(e);let t=[];return t.push(this.onSkipControllerRegister(n=>{t.push(n.onAbort(()=>{e()}))})),{cancel:()=>{t.forEach(n=>n.cancel()),this.offListener(e)}}}return{cancel:()=>{}}}onSkipControllerRegister(e){return this.skipController?e(this.skipController):this.onRegisterSkipController.push(e),{cancel:()=>{this.offSkipControllerRegister(e)}}}offSkipControllerRegister(e){let t=this.onRegisterSkipController.indexOf(e);return t!==-1&&this.onRegisterSkipController.splice(t,1),this}abort(){return this.aborted=!0,this.skipController?this.skipController.abort():this.result}isSolved(){return this.solved&&!this.aborted}isAborted(){return this.aborted}isSettled(){return this.solved||this.aborted}pushListener(e){return this.listeners.length>=he.maxListeners&&console.warn("NarraLeaf-React: Awaitable has too many listeners, this may cause performance issues."),this.listeners.push(e),this}offListener(e){let t=this.listeners.indexOf(e);return t!==-1&&this.listeners.splice(t,1),this}};he.nothing=e=>e,he.maxListeners=8;var h=he;function Ii(s){let e=new WeakSet;function t(n){if(n===null||typeof n!="object")return n;if(e.has(n))return;if(e.add(n),Array.isArray(n)){let i=[];for(let r of n)i.push(t(r));return i}let o={};for(let i in n)Object.prototype.hasOwnProperty.call(n,i)&&(o[i]=t(n[i]));return o}return t(s)}function vt(s){return typeof s=="string"?s:`#${(s.r||0).toString(16).padStart(2,"0")}${(s.g||0).toString(16).padStart(2,"0")}${(s.b||0).toString(16).padStart(2,"0")}${s.a===void 0?"":s.a.toString(16).padStart(2,"0")}`}var K=class{constructor(){this.events={};this.maxListeners=10}on(e,t){return this.events[e]||(this.events[e]=[]),this.events[e].push(t),this.events[e].length>this.maxListeners&&console.warn(`NarraLeaf-React: Event ${e} has more than ${this.maxListeners} listeners (total: ${this.events[e].length}), this may cause performance issues.`),this.emit("event:EventDispatcher.register",e,t),{type:e,listener:t,cancel:()=>{this.off(e,t)}}}depends(e){return{cancel:()=>{e.forEach(t=>t.cancel())}}}off(e,t){this.events[e]&&(this.events[e]=this.events[e].filter(n=>n!==t))}emit(e,...t){if(!this.events[e])return 0;let n=this.events[e].length;return this.events[e].forEach(o=>{o(...t)}),n}once(e,t){let n=(...o)=>{t(...o),this.off(e,n)};return this.on(e,n)}async any(e,...t){if(this.events[e]||(this.events[e]=[]),this.events[e].length>0){await Promise.all(this.events[e].map(n=>n(...t)));return}return new Promise(n=>{let o="event:EventDispatcher.register",i=this.on(o,(r,a)=>{if(r===e){this.off(o,i);let c=a?.(...t);c!==null&&typeof c=="object"&&c.then?c.then(n):n(c)}}).listener})}setMaxListeners(e){return this.maxListeners=e,this}hasListeners(e){return this.events[e]?.length>0}clear(){this.events={}}};function No(s=1){let e=new Error().stack;return e?e.split(`
`).slice(s+1).join(`
`).trim():""}function Un(s){return new Promise(e=>setTimeout(e,s))}var Hn=class Hn{constructor(e){this.abortHandler=e;this.events=new K;this.aborted=!1}abort(...e){this.aborted||(this.aborted=!0,this.abortHandler(...e),this.events.emit(Hn.EventTypes["event:skipController.abort"]))}isAborted(){return this.aborted}cancel(){this.aborted=!0}onAbort(e){return this.events.on("event:skipController.abort",e)}};Hn.EventTypes={"event:skipController.abort":"event:skipController.abort"};var L=Hn;var Xt=class{constructor(){this.locked=!1;this.listeners=[];this.unlockListeners=[]}lock(){return this.locked=!0,this}unlock(){this.locked=!1;for(let e of this.listeners)e();for(let e of this.unlockListeners)e();return this.listeners=[],this}onUnlock(e){return this.unlockListeners.push(e),e}offUnlock(e){this.unlockListeners=this.unlockListeners.filter(t=>t!==e)}async nextUnlock(){if(this.locked)return new Promise(e=>{this.listeners.push(e)})}isLocked(){return this.locked}},Nt=class{constructor(){this.locks=[]}unlock(e){return e.unlock(),this.off(e),e}register(e){let t=e||new Xt;return this.locks.push(t),t}off(e){this.locks=this.locks.filter(t=>t!==e)}async nextUnlock(){let e=this.locks.map(t=>t.nextUnlock());return Promise.all(e)}isLocked(){return this.locks.some(e=>e.isLocked())}};function Kn(s,e,t={}){return s?e:t}function Mi(s,e){if(e<=0)return s;let t=null;return function(...n){t&&clearTimeout(t),t=setTimeout(()=>{s(...n)},e)}}var Ln=class{constructor(){this.taskToken=null}scheduleTask(e,t){this.taskToken&&this.taskToken.cancel();let n=!1,o=setTimeout(()=>{n||e()},t);return this.taskToken={cancel:()=>{clearTimeout(o),n=!0},isCancelled:()=>n},this.taskToken}cancelTask(){return this.taskToken&&(this.taskToken.cancel(),this.taskToken=null),this}};function Gi(s,e){let t=[];for(let n=0;n<Math.max(s.length,e.length);n++)n<s.length&&t.push(s[n]),n<e.length&&t.push(e[n]);return t}async function Ni(s,e){return new Promise((t,n)=>{fetch(s,e).then(o=>o.blob()).then(o=>{let i=new FileReader;i.onload=()=>{t(i.result)},i.readAsDataURL(o)}).catch(n)})}var Yt=class{constructor(e,t){this.concurrency=e;this.delay=t;this.tasks=[]}addTask(e){this.tasks.push(e)}async start(){let e=async()=>{if(this.tasks.length===0)return;let t=this.tasks.splice(0,this.concurrency);await Promise.all(t.map(n=>n())),await Un(this.delay),await e()};await e()}};function Ie(s){let e,t=Promise.resolve().then(()=>{e=s()});return()=>{t.then(()=>{e&&e()})}}function Hi(s,e){let t={};for(let n in s)e.includes(n)||(t[n]=s[n]);return t}var Se=class s{constructor(e={},t={}){this.serializer=e;this.deserializer=t}serialize(e){let t={};for(let n of Object.keys(e))n in this.serializer&&e[n]!==void 0?t[n]=this.serializer[n]?.(e[n]):t[n]=e[n];return t}deserialize(e){let t={};for(let n of Object.keys(e))typeof this.deserializer[n]=="function"&&e[n]!==void 0?t[n]=this.deserializer[n](e[n]):t[n]=e[n];return t}extend(e,t){let n={...this.serializer,...e},o={...this.deserializer,...t};return new s(n,o)}};function Ui(s){return["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","transparent","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"].includes(s)}var dt=class extends h{constructor(t){super();this.tasks=[];t&&this.registerSkipController(t)}addTask(t){return t?(this.tasks.push(t),this):this}abort(){this.current&&this.current.abort(),this.tasks.forEach(([t,n])=>{n&&n.abort()}),super.abort()}resolve(){}run(){return this.current?this:(this.onTaskComplete(),this)}onTaskComplete(){if(this.tasks.length===0){super.resolve();return}let[t,n]=this.tasks.shift(),o=new h(h.nothing,n);this.current=o,this.current.then(()=>this.onTaskComplete()),t(o)}};function Ki(s){return s.constructor.name==="AsyncFunction"||Object.prototype.toString.call(s)==="[object AsyncFunction]"}function Ho(s){let e={};for(let t in s)s[t]!==void 0&&(e[t]=s[t]);return e}function Uo(s,e=new WeakSet){if(s===null||typeof s!="object"||Array.isArray(s)||s instanceof Date||s instanceof RegExp||Object.getPrototypeOf(s)!==Object.prototype||e.has(s))return!1;e.add(s);for(let t in s)if(Object.prototype.hasOwnProperty.call(s,t)){let n=s[t];if(n!==null&&typeof n=="object"&&!Uo(n,e)||typeof n=="function"||typeof n=="symbol")return!1}return!0}var In=class{constructor(e=""){this.prefix=e;this.counter=0}next(){return`${this.prefix?this.prefix+"-":""}${this.counter++}`}};function Fi(s=16){let e="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=t.length;for(let o=0;o<s;o++)e+=t.charAt(Math.floor(Math.random()*n));return e}function Oi(s=16){let e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",t="";for(let n=0;n<s;n++)t+=e[Math.floor(Math.random()*e.length)];return t}var Mn=class{constructor(e=""){this.prefix=e;this.counter=0}generateId(){return`${this.prefix?this.prefix+"-":""}${this.counter++}`}},Gn=class{constructor(){this.hooks={}}hook(e,t){return this.hooks[e]=this.hooks[e]||[],this.hooks[e].push(t),{cancel:()=>this.unhook(e,t)}}unhook(e,t){this.hooks[e]=this.hooks[e]?.filter(n=>n!==t)||[]}trigger(e,t){let n=this.hooks[e];if(!n)return()=>{};let o=n.map(i=>i(...t));return()=>{o.forEach(i=>i&&i())}}rawTrigger(e,t){let n=this.hooks[e];if(!n)return()=>{};let o=n.map(i=>i(...t()));return()=>{o.forEach(i=>i&&i())}}};var Nn=class{constructor(e){this.items=[];this.pushValidator=[];e&&(this.items=[...e])}addPushValidator(e){return this.pushValidator.push(e),this}removePushValidator(e){this.pushValidator=this.pushValidator.filter(t=>t!==e)}push(...e){for(let t of e)this.pushValidator.some(n=>!n(t))||this.items.push(t)}pop(){return this.items.pop()}peek(){return this.items[this.items.length-1]}isEmpty(){return this.items.length===0}size(){return this.items.length}clear(){this.items=[]}toArray(){return[...this.items]}forEach(e){this.items.forEach(e)}forEachReverse(e){for(let t=this.items.length-1;t>=0;t--)e(this.items[t])}map(e){return this.items.map(e)}get(e){return this.items[e]}};function Wi(s,e){let t={},n=[];for(let o in s)Object.prototype.hasOwnProperty.call(s,o)&&(e.includes(o)?n.push(o):t[o]=s[o]);return[t,n]}function Vi(s){let e=3421674724,t=2216829733;for(let n=0;n<s.length;n++){let o=s.charCodeAt(n);e^=o;let i=e>>>0,r=t>>>0,a=435,c=16777216,l=i*a>>>0,m=i*c+r*a>>>0,p=r*c+(m>>>0)>>>0;e=l,t=p}return("00000000"+t.toString(16)).slice(-8)+("00000000"+e.toString(16)).slice(-8)}var Zt=class{constructor(e,t,n){this.callee=e,this.type=t,this.contentNode=n,this.__stack=No(),this._id=""}executeAction(e,t){return{type:this.type,node:this.contentNode.getChild()}}getId(){return this._id}setId(e){this._id=e}setContent(e){return this.contentNode.setContent(e),this}setContentNode(e){return this.contentNode=e,this}getFutureActions(e,t){let n=this.contentNode.getChild();return n&&n.action?[n.action]:[]}};Zt.ActionTypes={action:"action"};var M=class extends Zt{constructor(e,t,n){super(e,t,n),this.callee=e.getSelf(),this.contentNode.action=this}unknownTypeError(){throw new Error("Unknown action type: "+this.type)}resolveAwaitable(e,t){let n=t||new h(o=>o);return(async()=>await e(n.resolve.bind(n),n))(),n}is(e,t){return this instanceof e&&this.type===t}stringify(e,t,n){return this.stringifyWithName("Action")}stringifyWithName(e){return`${e}#${this._id}(${this.type})`}stringifyWithContent(e,t){return`${e}#${this._id}(${this.type}){${t}}`}};var Ko=class{constructor(e){this.type=e,this.content=void 0}setContent(e){return this.content=e,this}getContent(){return this.content}},y=class s extends Ko{static create(e){return new s().setContent(e)}static forEachParent(e,t){let n=new Set,o=e;for(;o&&!n.has(o);)n.add(o),t(o),o=o.getParent()}static forEachChild(e,t){let n=new Set,o=e;for(;o&&!n.has(o);)n.add(o),t(o),o=o.getChild()}constructor(e,t,n){super("ContentNode"),this.child=n||null,this.parent=t||null,this.action=e||null}setParent(e){if(e===this)throw new Error("Cannot set parent to itself");return this.parent&&this.parent.setChild(null),this.parent=e,this}setChild(e){if(e===this)throw new Error("Cannot set child to itself");return this.child&&(this.child.parent=null),this.child=e,e&&e.parent!==this&&(e.remove(),e.parent=this),this}getChild(){return this.child||null}getParent(){return this.parent||null}addChild(e){return this.setChild(e),this}removeChild(e){return e&&this.child===e?(this.child=null,e.setParent(null)):e||(this.child=null),this}remove(){return this.parent&&this.parent.removeChild(this),this.child&&this.child.setParent(null),this}hasChild(){return!!this.child}};var Fn={center:"center",left:"left",right:"right"};import{animate as _r}from"motion/react";var _t=(n=>(n.Left="left",n.Center="center",n.Right="right",n))(_t||{}),zi={left:"33.33%",center:"50%",right:"66.66%"},Me=class Me{static isUnknown(e){return e===Me.Unknown}static D2PositionToCSS(e,t=!1,n=!1){let o=this.calc(e.y,e.yoffset),i=this.calc(e.x,e.xoffset),r=n?{bottom:o}:{top:o},a=t?{right:i}:{left:i};return this.wrap({...r,...a})}static calc(e,t){return!e||Me.isUnknown(e)?"auto":t===void 0||Me.isUnknown(t)?`calc(${e} + 0px)`:`calc(${typeof e=="number"?`${e}px`:e} + ${t}px)`}static toCoord2D(e){if(Ge.isCommonPositionType(e))return be.fromCommonPosition(e);if(be.isCoord2DPosition(e))return e;if(Ct.isAlignPosition(e))return be.fromAlignPosition(e);if(typeof e=="object"&&["x","y","xoffset","yoffset"].some(t=>t in e)){let t=e;return new be(t)}else throw new Error("Invalid position type")}static orUnknown(e){return Me.isUnknown(e)||e===void 0?Me.Unknown:e}static mergePosition(e,t){let n=this.toCoord2D(e),o=this.toCoord2D(t);return be.merge(n,o)}static serializePosition(e){let t=this.toCoord2D(e);return{x:Me.isUnknown(t.x)?0:t.x,y:Me.isUnknown(t.y)?0:t.y,xoffset:Me.isUnknown(t.xoffset)?0:t.xoffset,yoffset:Me.isUnknown(t.yoffset)?0:t.yoffset}}static isRawCommonPositionType(e){return Object.values(_t).includes(e)}static isRawCoord2DPosition(e){return typeof e=="object"&&("x"in e||"y"in e||"xoffset"in e||"yoffset"in e)}static isRawAlignPosition(e){return typeof e=="object"&&("xalign"in e||"yalign"in e||"xoffset"in e||"yoffset"in e)}static isRawPosition(e){return this.isRawCommonPositionType(e)||this.isRawCoord2DPosition(e)||this.isRawAlignPosition(e)}static isPosition(e){return e instanceof Ge||e instanceof be||e instanceof Ct}static rawPositionToCoord2D(e){if(this.isRawCommonPositionType(e))return be.fromCommonPosition(new Ge(e));if(this.isRawCoord2DPosition(e))return new be(e);if(this.isRawAlignPosition(e))return be.fromAlignPosition(e);throw new Error("Invalid position type")}static tryParsePosition(e){if(this.isPosition(e))return e;if(this.isRawPosition(e))return this.rawPositionToCoord2D(e);throw new Error("Invalid position type")}static wrap(e){return{left:"auto",top:"auto",right:"auto",bottom:"auto",...e}}};Me.Unknown=Symbol("Unknown");var C=Me,On=class On{static isCommonPositionType(e){return e instanceof On}constructor(e){this.position=e}toCSS(){return{x:zi[this.position],y:"50%",xoffset:0,yoffset:0}}};On.Positions=_t;var Ge=On,be=class s{static isCoord2DPosition(e){return e instanceof s}static fromCommonPosition(e){return new s({x:zi[e.position],y:"50%"})}static fromAlignPosition(e){let t=n=>!n||C.isUnknown(n)?C.Unknown:`${n*100}%`;return new s({x:t(e.xalign),y:t(e.yalign),xoffset:e.xoffset,yoffset:e.yoffset})}static merge(e,t){return new s({x:C.isUnknown(t.x)?e.x:t.x,y:C.isUnknown(t.y)?e.y:t.y,xoffset:C.isUnknown(t.xoffset)?e.xoffset:t.xoffset,yoffset:C.isUnknown(t.yoffset)?e.yoffset:t.yoffset})}constructor(e,t){typeof e=="object"?(this.x=C.orUnknown(e.x),this.y=C.orUnknown(e.y),this.xoffset=C.orUnknown(e.xoffset),this.yoffset=C.orUnknown(e.yoffset)):(this.x=C.orUnknown(e),this.y=C.orUnknown(t),this.xoffset=C.Unknown,this.yoffset=C.Unknown),this.check()}check(){let e=t=>/^-?\d+(\.\d+)?%$/.test(t);if(typeof this.x=="string"&&!e(this.x))throw new Error(`Invalid x position: ${this.x}`);if(typeof this.y=="string"&&!e(this.y))throw new Error(`Invalid y position: ${this.y}`)}toCSS(){return{x:this.x,y:this.y,xoffset:this.xoffset,yoffset:this.yoffset}}},Ct=class s{static isAlignPosition(e){return e instanceof s}constructor(e,t){typeof e=="object"?(this.xalign=C.orUnknown(e.xalign),this.yalign=C.orUnknown(e.yalign),this.xoffset=C.orUnknown(e.xoffset),this.yoffset=C.orUnknown(e.yoffset)):(this.xalign=C.orUnknown(e),this.yalign=C.orUnknown(t),this.xoffset=C.Unknown,this.yoffset=C.Unknown),this.check()}check(){if(typeof this.xalign=="number"&&isNaN(this.xalign))throw new Error("Invalid xalign position: "+this.xalign);if(typeof this.yalign=="number"&&isNaN(this.yalign))throw new Error("Invalid yalign position: "+this.yalign)}toCSS(){return{x:C.isUnknown(this.xalign)?this.xalign:`${this.xalign*100}%`,y:C.isUnknown(this.yalign)?this.yalign:`${this.yalign*100}%`,xoffset:this.xoffset,yoffset:this.yoffset}}};var N=class s{constructor(e,t){this.defaultConfig=e;this.handlers=t||{}}create(e={}){return new Fo(this.mergeWithDefaultConfig(e))}copy(){return new s(D({},this.defaultConfig),this.handlers)}keys(){return Object.keys(this.defaultConfig)}getDefaultConfig(){return this.defaultConfig}mergeWithDefaultConfig(e){return Object.fromEntries(Object.entries(this.defaultConfig).map(([t,n])=>[t,this.mergeValue(t,n,e[t])]))}mergeValue(e,t,n){return this.isPlainObject(n)?D({},n):Array.isArray(t)?Array.isArray(n)&&n.length>0?[...n]:[...t]:n!==void 0?this.applyHandler(e,n):t}isPlainObject(e){return typeof e=="object"&&!Array.isArray(e)&&e!==null&&Object.getPrototypeOf(e)===Object.prototype}applyHandler(e,t){return typeof this.handlers[e]=="function"?this.handlers[e](t):t}},Fo=class s{constructor(e){this.config=e}get(){return this.config}copy(){return new s(D({},this.config))}join(e){let t=Hi(this.config,Object.keys(e));return new s(Object.assign(t,e instanceof s?e.get():e))}extract(e){let t={},n={};for(let o of e)t[o]=this.config[o];for(let o in this.config)e.includes(o)||(n[o]=this.config[o]);return[new s(t),new s(n)]}assign(e){return new s(Object.assign({},this.config,e))}};var es={[Fn.left]:"25.33%",[Fn.center]:"50%",[Fn.right]:"75.66%"},We=class We{constructor(e={}){this.state={};this.locked=null;this.frozen=!1;this.state=e}static deserialize(e){return new We(We.TransformStateSerializer.deserialize(e))}static mergePosition(e,t){if(!e&&!t)throw new Error("No position found.");return!e||!t?C.toCoord2D(C.tryParsePosition(e||t)):C.mergePosition(C.tryParsePosition(e),C.tryParsePosition(t))}static mergeState(e,t){if("position"in e&&"position"in t){let n=this.mergePosition(e.position,t.position);return{...Object.assign({},e,t),position:n}}return{...Object.assign({},e,t)}}get(){return this.state}freeze(){return this.frozen=!0,this}assign(e,t){if(this.frozen)throw new Error("Trying to write a frozen transform state.");if(!this.canWrite(e))throw new Error("Trying to write a locked transform state.");return this.state=We.mergeState(this.state,t),this}lock(){if(this.locked)throw new Error("Transform state is already locked.");return this.locked=Symbol(),this.locked}isLocked(){return!!this.locked}canWrite(e){return this.locked===null||this.locked===e}unlock(e){return this.locked===e&&(this.locked=null),this}toFramesDefinition(e,t){return Ho($.constructStyle(e,this.state,t))}toStyle(e,t){return Ho($.constructStyle(e,this.state,t))}serialize(){return We.TransformStateSerializer.serialize(this.state)}clone(){return new We(We.mergeState({},this.state))}overwrite(e,t){if(this.frozen)throw new Error("Trying to write a frozen transform state.");if(!this.canWrite(e))throw new Error("Trying to write a locked transform state.");return this.state=We.mergeState(this.state,t),this}forceOverwrite(e){return this.state=e,this}};We.DefaultTransformState=new N({scale:1,rotation:0,position:new Ge("center"),opacity:0,alt:""}),We.TransformStateSerializer=new Se({position:e=>C.serializePosition(C.tryParsePosition(e))},{position:e=>C.toCoord2D(e)});var ie=We,oe=class oe{constructor(e,t){this.sequences=[];this.stagedChanges=[];if(Array.isArray(e))this.sequences.push(...e),this.config=Object.assign({},oe.defaultConfig,t||{});else{let[n,o]=[e,t||oe.defaultOptions];this.sequences.push({props:n,options:o||oe.defaultOptions}),this.config=Object.assign({},oe.defaultConfig)}}static isPosition(e){return Ge.isCommonPositionType(e)||be.isCoord2DPosition(e)||Ct.isAlignPosition(e)}static immediate(e){return new oe(e,{duration:0,ease:"linear"})}static left(e,t){return new oe({position:Ge.Positions.Left},{duration:e,ease:t})}static right(e,t){return new oe({position:Ge.Positions.Right},{duration:e,ease:t})}static center(e,t){return new oe({position:Ge.Positions.Center},{duration:e,ease:t})}static create(e){return new oe([],e)}static positionToCSS(e,t,n){return e?C.isRawPosition(e)?C.D2PositionToCSS(C.rawPositionToCoord2D(e),n,t):C.D2PositionToCSS(e.toCSS(),n,t):{}}static mergePosition(e,t){if(!e&&!t)throw new Error("No position found.");return!e||!t?C.toCoord2D(C.tryParsePosition(e||t)):C.mergePosition(C.tryParsePosition(e),C.tryParsePosition(t))}static mergeState(e,t){let n=this.mergePosition(e.position,t.position);return{...D(e,t),position:n}}static propToCSSTransform(e,t,{translate:n=[],scale:o=1}={}){let i=t.scale!==void 0?t.scale:1,{invertY:r,invertX:a}=e.getStory().getInversionConfig();return[`translate(${n[0]||(a?"":"-")+"50%"}, ${n[1]||(r?"":"-")+"50%"})`,t.rotation!==void 0&&`rotate(${t.rotation}deg)`,`scale(${i*o})`].filter(Boolean).join(" ")}static constructStyle(e,t,n){let{invertY:o,invertX:i}=e.getStory().getInversionConfig(),{transform:r,scale:a,overwrite:c}=n||{};return{...oe.positionToCSS(t.position,o,i),opacity:t.opacity,color:"fontColor"in t&&t.fontColor?vt(t.fontColor):void 0,transform:r?r(t):oe.propToCSSTransform(e,t),scale:a?a(t):void 0,...c?c(t):{}}}animate(e,{gameState:t,ref:n,overwrites:o}){if(!n.current)throw new Error("No ref found when animating.");this.commit();let{finalState:i,sequences:r,options:a}=this.constructAnimation({gameState:t,transformState:e,overwrites:o,current:n.current});r.length||t.logger.warn("Transform","No sequences to animate.");let c=!1,l=e.lock(),m=_r(r,a),p=()=>{e.overwrite(l,i.get()).unlock(l),m.complete(),c=!0},d=new h().registerSkipController(new L(p)),g=()=>{c||e.overwrite(l,i.get()).unlock(l),c=!0,t.logger.debug("Transform","Transform Completed",e.toStyle(t,o)),d.resolve()};return m.then(g,u=>{t.logger.error("Failed to animate transform. "+(u?.toString?.()||""))}),m.play(),t.logger.debug("Transform","Ready to animate transform.",{finalState:i,sequences:r,options:a},this),d}repeat(e){let t=this.copy();return t.config.repeat||(t.config.repeat=1),t.config.repeat*=e,t}getOptions(e){if(!e)return{...oe.defaultOptions};let{duration:t,ease:n,delay:o,at:i}=e;return{duration:this.toSeconds(t,void 0),ease:n,delay:this.toSeconds(o,void 0),at:this.atToSeconds(i)}}constructAnimation({gameState:e,transformState:t,overwrites:n={},current:o}){let i=t.clone(),r=i.lock(),a=this.sequences.map(({props:c,options:l})=>{let m=i.assign(r,c).toFramesDefinition(e,n);return[o,m,this.getOptions(l)]});return{finalState:i.unlock(r).freeze(),sequences:a,options:this.getSequenceOptions()}}getSequenceOptions(){let{repeat:e,repeatDelay:t}=this.config;return{repeat:e,repeatDelay:this.toSeconds(t,void 0)}}copy(){return new oe(this.sequences,this.config)}commit(e){if(!this.stagedChanges.length)return this;let t=this.constructCommit(this.stagedChanges,this.getSequenceOptions());return this.sequences.push({props:t.props,options:{...this.getSequenceOptions(),...e}}),this.stagedChanges=[],this}scale(e){return this.pushChange({key:"scale",props:e})}rotation(e){return this.pushChange({key:"rotation",props:e})}position(e){return this.pushChange({key:"position",props:e})}opacity(e){return this.pushChange({key:"opacity",props:e})}fontColor(e){return this.pushChange({key:"fontColor",props:e})}constructCommit(e,t){let n={props:{},options:t};for(let o of e)n.props[o.key]=o.props;return n}pushChange(e){return this.stagedChanges.push(e),this}toSeconds(e,t){return typeof e>"u"?t:e/1e3}atToSeconds(e){if(typeof e>"u")return e;if(typeof e=="number")return e/1e3;let n=/^([+-])(\d+)$/.exec(e);if(!n)throw new Q("Invalid at definition. At definition must be a number or a string in the format of `+n` or `-n`.");let[o,i,r]=n,a=Number(r);if(isNaN(a))throw new Q("Invalid number in at definition.");let c=a/1e3;return i==="+"?`+${c}`:`-${c}`}};oe.defaultConfig={sync:!0},oe.defaultOptions={duration:0,ease:"linear"},oe.CommonImagePositionMap=es;var $=oe;var mC={};var Wn=class{constructor(){this.id=""}setId(e){this.id=e}getId(){return this.id}reset(){}fromData(e){return this}construct(e){for(let t=0;t<e.length;t++){let n=e[t];t!==0&&e[t-1]?.contentNode.setChild(n.contentNode)}return e}};var Vn=class{constructor(e){this.config=e;this.watching=null;this.warnings=[]}observe(e){return this.watching=e,this}warn(e,t){return this.warnings.push([e,t]),this.watching?.logger.warn(t),t}getWarnings(){return[...this.warnings]}};var re=class s{constructor(e,t){this.awaitable=e;this.guard=t;this.children=[];this._onResolved=[];this._onCancelled=[];this._onTimelineRegistered=[];this._ableToAttach=!0;this._status="pending";e.onSettled(()=>{this.resolveStatus()}),Ie(()=>{this.preventAttach()})}static proxy(e){let t=new h,n=new h,o=new s(n);return o.onTimelineRegistered(()=>{n.resolve()}).onSettled(()=>{let[i,r]=o.catSettled();e(i,r)}),t.onSkipControllerRegister(i=>{i.onAbort(()=>{o.abort()})}),[t,o]}static any(e){if(e.length===0)throw new b("Cannot create an 'any' timeline with no awaitables.");let t=new h,n=new h,o=new s(n),i=!1;for(let r of e)o.attachChild(r),r.then(a=>{i||(i=!0,t.resolve(a))});return t.onSkipControllerRegister(r=>{r.onAbort(()=>{o.abort()})}),[t,o]}static all(e){if(e.length===0)throw new b("Cannot create an 'all' timeline with no awaitables.");let t=new h,n=new h,o=new s(n),i=new Array(e.length),r=0;for(let a=0;a<e.length;a++){let c=e[a];o.attachChild(c),c.then(l=>{i[a]=l,r++,r===e.length&&t.resolve(i)})}return t.onSkipControllerRegister(a=>{a.onAbort(()=>{o.abort()})}),[t,o]}static sequence(e,t){let n=t,o=null,i=new h,r=()=>{if(o){let a;o.onSkipControllerRegister(c=>{a=c.onAbort(()=>{i.abort()})}),o.then(c=>{a?.cancel(),n=c,o=e(c),o?Ie(()=>r()):i.resolve(n)})}else i.resolve(n)};return i.registerSkipController(new L(()=>(o&&o.abort(),t))),o=e(t),o?Ie(()=>r()):Ie(()=>i.resolve(n)),i}get status(){return this._status}isSettled(){return this._status!=="pending"}isResolved(){return this._status==="resolved"}isCancelled(){return this._status==="cancelled"}onResolved(e){this._onResolved.push(e)}onCancelled(e){this._onCancelled.push(e)}onSettled(e){this.isSettled()?Ie(e):(this.onResolved(e),this.onCancelled(e))}abort(){this.isSettled()||(this.awaitable.abort(),this.setStatus("cancelled",this.emitEvents.bind(this)),this.children.forEach(e=>e.abort()))}attachChild(e){if(!this._ableToAttach)throw new b(`Attaching to this timeline violates the timeline's state.
Timeline attaching is only allowed synchronously after the timeline is created.
Current _ableToAttach: `+this._ableToAttach);let t=h.isAwaitable(e)?new s(e,this.guard):e;return this.children.push(t),this.guard&&t.setGuard(this.guard),t.onSettled(()=>{this.resolveStatus()}),this}setGuard(e){return this.guard=e,this}catSettled(){return this.children.reduce(([e,t],n)=>(n.isResolved()?e.push(n):n.isCancelled()&&t.push(n),[e,t]),[[],[]])}onTimelineRegistered(e){return this._onTimelineRegistered.push(e),this}resolveStatus(){this.awaitable.solved&&this.children.every(e=>e.isSettled())?this.setStatus("resolved",this.emitEvents.bind(this)):this.awaitable.skipController?.isAborted()&&this.setStatus("cancelled",this.emitEvents.bind(this))}emitEvents(){this.isResolved()?this._onResolved.forEach(e=>e()):this.isCancelled()&&this._onCancelled.forEach(e=>e()),this._onResolved=[],this._onCancelled=[]}setStatus(e,t){if(this.isSettled()){this.guard&&this.guard.warn("unexpectedTimelineStatusChange",`Trying to resolve a settled timeline: ${this._status} -> ${e}`);return}e!==this._status&&t?(this._status=e,t()):this._status=e}preventAttach(){this._ableToAttach=!1,this._onTimelineRegistered.forEach(e=>e())}},zn=class{constructor(e){this.guard=e;this.timelines=[]}attachTimeline(e){this.cleanupSettled();let t=e instanceof re?e:new re(e);return this.timelines.push(t),this.guard&&t.setGuard(this.guard),t}abortAll(){for(let e of this.timelines)e.abort();this.cleanupSettled()}cleanupSettled(){this.timelines=this.timelines.filter(e=>!e.isSettled())}};var en=class en extends M{static executeActionsAsync(e,t){return e.game.getLiveGame().requestAsyncStackModel([{type:t.type,node:t.contentNode}]).execute()}checkActionChain(e){if(e.some(t=>!!t.contentNode.getChild()))throw new Error("Invalid action chain. Actions are chained unexpectedly.");return e}executeAction(e,t){let n=this.contentNode,[o]=n.getContent();if(this.type===Oe.do)return[{type:this.type,node:this.contentNode.getChild()},{type:this.type,node:o[0].contentNode}];if(this.type===Oe.doAsync){let i=en.executeActionsAsync(e,o[0]);return e.timelines.attachTimeline(i),super.executeAction(e,t)}else if(this.type===Oe.any){if(o.length===0)return{type:this.type,node:this.contentNode.getChild()};let i=this.checkActionChain(o).map(r=>e.game.getLiveGame().requestAsyncStackModel([{type:r.type,node:r.contentNode}]));return{type:this.type,node:this.contentNode.getChild(),wait:{type:"any",stackModels:i}}}else if(this.type===Oe.all){if(o.length===0)return{type:this.type,node:this.contentNode.getChild()};let i=this.checkActionChain(o).map(r=>e.game.getLiveGame().requestAsyncStackModel([{type:r.type,node:r.contentNode}]));return{type:this.type,node:this.contentNode.getChild(),wait:{type:"all",stackModels:i}}}else if(this.type===Oe.allAsync){if(o.length===0)return{type:this.type,node:this.contentNode.getChild()};let i=this.checkActionChain(o).map(r=>e.game.getLiveGame().requestAsyncStackModel([{type:r.type,node:r.contentNode}]));return e.timelines.attachTimeline(h.all(...i.map(r=>r.execute()))),super.executeAction(e,t)}else if(this.type===Oe.repeat){let[i,r]=this.contentNode.getContent();if(r<=0)return super.executeAction(e,t);let a=re.sequence(c=>{if(c>=r)return null;let l=en.executeActionsAsync(e,i[0]);return e.timelines.attachTimeline(l),h.forward(l,c+1)},0);return e.logger.debug("ControlAction","repeat",i,r),h.forward(a,{type:this.type,node:this.contentNode.getChild()})}else if(this.type===Oe.sleep){let[,i]=this.contentNode.getContent(),r;typeof i=="number"?r=h.delay(i):h.isAwaitable(i)?r=i:r=h.fromPromise(i);let a=new h,c=new re(r);return e.timelines.attachTimeline(c),r.then(()=>{a.resolve({type:this.type,node:this.contentNode.getChild()})}),a.onSkipControllerRegister(l=>{l.onAbort(()=>{c.abort()})}),a}throw new Error("Unknown control action type: "+this.type)}getFutureActions(e,t){if(this.callee.config.allowFutureScene===!1&&t.allowFutureScene===!1)return[...super.getFutureActions(e,t)];let n=this.contentNode.getContent()[0],o=super.getFutureActions(e,t);return[...n,...o]}stringify(e,t,n){let o=this.contentNode,[i]=o.getContent();return super.stringifyWithContent("Control",i.map(r=>r.stringify(e,t,n)).join(";"))}};en.ActionTypes=Oe;var ee=en;var $i=Symbol("_Chained"),ji;ji=$i;var Oo=class Oo{constructor(e){this[ji]=!0;this.__actions=[];this.__self=e}static isChained(e){return e&&e[$i]}static toActions(e){return e.flat(2).map(t=>Oo.isChained(t)?t.fromChained(t):t).flat(3)}push(...e){this.__actions.push(...e)}getActions(){return this.__actions}getSelf(){return this.__self}newChain(){return this.getSelf().chain()}},me=Oo,Ht=class extends Wn{chain(e){let t=me.isChained(this)?this:this.proxy(this,new me(this));if(!e)return t;let n=Array.isArray(e)?e:[e];return t.push(...n),t}proxy(e,t){let n=new Proxy(e,{get:function(o,i){if(i in t)return t[i];let r=o[i];return typeof r=="function"?r.bind(n):r},set:function(o,i,r){return o[i]=r,!0}});return n}combineActions(e,t){let n=t(this.chain().newChain()),o=new ee(e.chain(),ee.ActionTypes.do,new y().setContent([this.construct(me.toActions([n]))]));return this.chain(o)}};var j=class extends Ht{constructor(){super()}toData(){return null}fromChained(e){return e.getActions()}};var ye=class s{static from(e){return s.isPauseConstructor(e)?new s:e}static wait(e){return new s({duration:e})}static isPause(e){return this.isPauseConstructor(e)||e instanceof s}static isPauseConstructor(e){return e===s}constructor(e={}){this.config=e}};var ce=class ce{static isWord(e){return e instanceof ce}static color(e,t){return ce.isWord(e)?e.copy().assign({color:t}):new ce(e,{color:t})}static bold(e){return ce.isWord(e)?e.copy().assign({bold:!0}):new ce(e,{bold:!0})}static italic(e){return ce.isWord(e)?e.copy().assign({italic:!0}):new ce(e,{italic:!0})}static getText(e){return e.filter(t=>!t.isPause()).map(t=>t.toString()).join("")}constructor(e,t={}){this.text=e,this.config=D(ce.defaultConfig,t)}evaluate(e){if(ye.isPause(this.text))return[this];if(typeof this.text=="function"){let t=this.text(e);return Array.isArray(t)?t.map(n=>ce.isWord(n)?n.inherit(this.config).evaluate(e):new ce(n,this.config)).flat():ce.isWord(t)?t.inherit(this.config).evaluate(e):[new ce(t,this.config)]}return[this]}inherit(e){return this.config.color=this.config.color||e.color,this.config.italic=this.config.italic??e.italic,this.config.bold=this.config.bold??e.bold,this.config.cps=this.config.cps??e.cps,this}assign(e){return this.config=D(this.config,e),this}copy(){return new ce(this.text,this.config)}isPause(){return ye.isPause(this.text)}toString(){return typeof this.text=="string"?this.text:""}};ce.defaultConfig={},ce.defaultColor="#000";var H=ce;var ke=class extends M{executeAction(e,t){let n={action:this,stackModel:t.stackModel};if(this.type===mt.play){let[o]=this.contentNode.getContent(),i=this.callee.toData(),r=h.forward(e.audioManager.play(this.callee,o),{type:this.type,node:this.contentNode?.getChild()});return e.timelines.attachTimeline(r),e.actionHistory.push(n,a=>{a&&this.callee.fromData(a)},[i]),r}else if(this.type===mt.stop){let[o]=this.contentNode.getContent(),i=this.callee.toData(),r=h.forward(e.audioManager.stop(this.callee,o.duration),{type:this.type,node:this.contentNode?.getChild()});return e.timelines.attachTimeline(r),e.actionHistory.push(n,a=>{a&&this.callee.fromData(a)},[i]),r}else if(this.type===mt.setVolume){let[o,i]=this.contentNode.getContent(),r=this.callee.toData(),a=h.forward(e.audioManager.setVolume(this.callee,o,i),{type:this.type,node:this.contentNode?.getChild()});return e.timelines.attachTimeline(a),e.actionHistory.push(n,c=>{c&&this.callee.fromData(c)},[r]),a}else if(this.type===mt.setRate){let[o]=this.contentNode.getContent(),i=this.callee.toData(),r=h.forward(e.audioManager.setRate(this.callee,o),{type:this.type,node:this.contentNode?.getChild()});return e.timelines.attachTimeline(r),e.actionHistory.push(n,a=>{a&&this.callee.fromData(a)},[i]),r}else if(this.type===mt.pause){let[o]=this.contentNode.getContent(),i=this.callee.toData(),r=h.forward(e.audioManager.pause(this.callee,o.duration),{type:this.type,node:this.contentNode?.getChild()});return e.timelines.attachTimeline(r),e.actionHistory.push(n,a=>{a&&this.callee.fromData(a)},[i]),r}else if(this.type===mt.resume){let[o]=this.contentNode.getContent(),i=this.callee.toData(),r=h.forward(e.audioManager.resume(this.callee,o.duration),{type:this.type,node:this.contentNode?.getChild()});return e.timelines.attachTimeline(r),e.actionHistory.push(n,a=>{a&&this.callee.fromData(a)},[i]),r}throw super.unknownTypeError()}stringify(e,t,n){return super.stringifyWithName("SoundAction")}};ke.ActionTypes=mt;var tn=(n=>(n.Voice="voice",n.Bgm="bgm",n.Sound="sound",n))(tn||{}),X=class X extends j{static toSound(e){return e==null?null:typeof e=="string"?new X({src:e}):e}static isSound(e){return e instanceof X}static voice(e){let t=typeof e=="string"?{src:e}:e;return new X({...t,type:"voice"})}static bgm(e){let t=typeof e=="string"?{src:e}:e;return new X({...t,type:"bgm"})}static sound(e){let t=typeof e=="string"?{src:e}:e;return new X({...t,type:"sound"})}constructor(e={}){super();let t=typeof e=="string"?{src:e}:e,n=X.DefaultUserConfig.create(t),[o]=n.extract(X.DefaultConfig.keys());this.config=o.get(),this.state=this.getInitialState(n),this.userConfig=n}play(e){if(this.config.type==="bgm")throw new ve(`Sound (src: ${this.config.src}) is marked as bgm, but it is being played as a normal sound.
To prevent unintended behavior, the sound marked as bgm cannot be played using \`play()\`.`);return this.pushAction(ke.ActionTypes.play,[{end:this.state.volume,duration:e||0}])}stop(e){return this.pushAction(ke.ActionTypes.stop,[{end:0,duration:e||0}])}setVolume(e,t){return this.pushAction(ke.ActionTypes.setVolume,[e,t||0])}setRate(e){return this.pushAction(ke.ActionTypes.setRate,[e])}pause(e){return this.pushAction(ke.ActionTypes.pause,[{end:0,duration:e||0}])}resume(e){return this.pushAction(ke.ActionTypes.resume,[{end:this.state.volume,duration:e||0}])}getSrc(){return this.config.src}toData(){return{state:X.StateSerializer.serialize(this.state)}}fromData(e){return this.state=X.StateSerializer.deserialize(e.state),this}copy(){return new X(this.userConfig.get())}reset(){return this.state=this.getInitialState(this.userConfig),this}getInitialState(e){return X.DefaultState.create({...e.get()}).get()}pushAction(e,t){return this.chain(new ke(this.chain(),e,new y().setContent(t)))}};X.noSound="data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgA",X.DefaultUserConfig=new N({src:X.noSound,loop:!1,volume:1,streaming:!1,rate:1,seek:0,type:"sound"}),X.DefaultConfig=new N({src:X.noSound,loop:!1,streaming:!1,seek:0,type:"sound"}),X.DefaultState=new N({volume:1,rate:1,paused:!1}),X.StateSerializer=new Se;var Ae=X;var Ce=class Ce{static isSentence(e){return e instanceof Ce}static toSentence(e){return Ce.isSentence(e)?e:new Ce(e)}static format(e){let t=[];if(Array.isArray(e))for(let n=0;n<e.length;n++)t.push(this.formatWord(e[n]));else t.push(this.formatWord(e));return t}static formatWord(e){return H.isWord(e)?e:new H(e)}static formatStaticWord(e,t){return Array.isArray(e)?e.map(n=>this.formatStaticWord(n,t)).flat(2):[H.isWord(e)?e:new H(e,t)]}static isSentencePrompt(e){return Array.isArray(e)?e.every(Ce.isSingleWord):Ce.isSingleWord(e)}static isSingleWord(e){return typeof e=="string"||H.isWord(e)||ye.isPause(e)||typeof e=="function"}constructor(e,t={}){this.text=Ce.format(e),this.config=D(Ce.defaultConfig,{...t,voice:Ae.toSound(t.voice)}),this.state=Ii(Ce.defaultState)}toData(){return null}fromData(e){return this.state=D(this.state,e),this}toString(){return this.text.map(e=>e.text).join("")}setCharacter(e){return this.config.character=e,this}evaluate(e){let t=[];for(let n=0;n<this.text.length;n++){let o=this.text[n].evaluate(e);t.push(...Ce.formatStaticWord(o))}return t}copy(){return new Ce([...this.text],this.config)}};Ce.defaultConfig={pause:!0,voice:null,character:null,voiceId:null},Ce.defaultState={};var te=Ce;var Bn=class Bn extends M{static getVoice(e,t){let n=e.getLastScene();if(!n)throw new Error("No scene found when trying to play voice");let{voiceId:o,voice:i}=t.config;return!o&&!i?null:Ae.toSound(n.getVoice(o)||i)}executeAction(e,t){if(this.type===Dn.say){let n=new h(m=>m).registerSkipController(new L(()=>{c.cancel()})),o=new re(n),i=this.contentNode.getContent(),r=Bn.getVoice(e,i);if(r){let m=e.audioManager.play(r);o.attachChild(m)}let a=e.idManager.generateId(),c=e.createDialog(a,i,()=>{if(r){let m=e.audioManager.stop(r);e.timelines.attachTimeline(m)}e.gameHistory.resolvePending(l),n.resolve({type:this.type,node:this.contentNode.getChild()})});e.getLiveGame().setLastDialog(c.text,this.callee.state.name),e.timelines.attachTimeline(o);let{id:l}=e.actionHistory.push({action:this,stackModel:t.stackModel,timeline:o},()=>{if(r&&e.audioManager.isPlaying(r)){let m=e.audioManager.stop(r);o.attachChild(m)}c.cancel()});return e.gameHistory.push({token:l,action:this,element:{type:"say",text:c.text,voice:r?r.getSrc():null,character:this.callee.state.name},isPending:!0}),n}else if(this.type===Dn.setName){let n=this.callee.state.name;return this.callee.state.name=this.contentNode.getContent()[0],e.actionHistory.push({action:this,stackModel:t.stackModel},o=>{this.callee.state.name=o},[n]),super.executeAction(e,t)}throw super.unknownTypeError()}stringify(e,t,n){return super.stringifyWithName("CharacterAction")}};Bn.ActionTypes=Dn;var tt=Bn;var nn=class nn extends j{constructor(e,t={}){super(),this.config=D(nn.defaultConfig,t),this.state={name:e||""};let n=this,o=function(i,r,...a){return n.call(i,r,...a)};return new Proxy(o,{get(i,r){return n[r]},set(i,r,a){return n[r]=a,!0},has(i,r){return r in n}})}say(e,t,...n){if(Array.isArray(e)&&e.every(c=>typeof c=="string")&&[t,...n].length>0&&[t,...n].every(c=>te.isSingleWord(c))){let c=e,l=te.format([t,...n]),m=new te(Gi(c,l),{character:this}),p=new tt(this.chain(),tt.ActionTypes.say,new y().setContent(m));return this.chain(p)}let o=t||{},i=e,r=Array.isArray(i)?new te(i,{...o,character:this}):(te.isSentence(i)?i:new te(i,{...o,character:this})).copy();r.setCharacter(this);let a=new tt(this.chain(),tt.ActionTypes.say,new y().setContent(r));return this.chain(a)}setName(e){let t=new tt(this.chain(),tt.ActionTypes.setName,new y().setContent([e]));return this.chain(t)}apply(e,t,...n){return this.say.apply(this,[e,t,...n])}call(e,t,...n){return Array.isArray(e)&&"raw"in e?t&&te.isSingleWord(t)?this.say(e,t,...n):this.say(e):typeof e=="string"?this.say(e,t):te.isSentence(e)?this.say(e):this.say(e,t)}};nn.defaultCharacterColor="#000",nn.defaultConfig={};var $n=nn,ft=new $n(null);var je=class s extends j{constructor(t={}){super();this.config=t}static do(t){return new s().do(t)}static doAsync(t){return new s().doAsync(t)}static any(t){return new s().any(t)}static all(t){return new s().all(t)}static allAsync(t){return new s().allAsync(t)}static repeat(t,n){return new s().repeat(t,n)}static sleep(t){return new s().sleep(t)}do(t){return this.push(ee.ActionTypes.do,t)}doAsync(t){return this.push(ee.ActionTypes.doAsync,t)}any(t){return this.pushUnchained(ee.ActionTypes.any,t)}all(t){return this.pushUnchained(ee.ActionTypes.all,t)}allAsync(t){return this.pushUnchained(ee.ActionTypes.allAsync,t)}repeat(t,n){return this.push(ee.ActionTypes.repeat,n,t)}sleep(t){return this.push(ee.ActionTypes.sleep,[],t)}push(t,n,...o){let i=this.narrativeToActions(n),r=new ee(this.chain(),t,new y().setContent([this.construct(i),...o]));return this.chain(r)}pushUnchained(t,n,...o){let i=this.narrativeToActions(n),r=new ee(this.chain(),t,new y().setContent([i,...o]));return this.chain(r)}narrativeToActions(t){return t.flatMap(n=>typeof n=="string"?ft.say(n).getActions():me.toActions([n]))}};var le=class extends M{executeAction(e,t){if(this.type===ae.applyTransform){let[n]=this.contentNode.getContent(),o=this.callee;return this.applyTransform(e,o,n,t)}else if(this.type===ae.applyTransition){let[n,o]=this.contentNode.getContent(),i=this.callee,r=o?o(n):n;return this.applyTransition(e,i,r,t)}else if(this.type===ae.init){let[n,o,i]=this.contentNode.getContent(),r=this.callee;return this.initDisplayable(e,n,r,o||null,i,t)}throw this.unknownTypeError()}applyTransform(e,t,n,o,i){let r=new h().registerSkipController(new L(()=>(e.logger.info("Displayable Transition","Skipped"),super.executeAction(e,o)))),a=e.getExposedStateForce(t),c=t.transformState.clone(),l=a.applyTransform(n,()=>{i?.(),r.resolve(super.executeAction(e,o))}),m=e.timelines.attachTimeline(r).attachChild(l);return e.actionHistory.push({action:this,stackModel:o.stackModel,timeline:m},p=>{r.isSettled()||r.abort(),l.abort(),t.transformState.forceOverwrite(p.state)},[c]),r}applyTransition(e,t,n,o,i){let r=new h().registerSkipController(new L(()=>(e.logger.info("Displayable Transition","Skipped"),super.executeAction(e,o)))),c=e.getExposedStateForce(t).applyTransition(n,()=>{i?.(),r.resolve(super.executeAction(e,o))}),l=e.timelines.attachTimeline(r).attachChild(c);return e.actionHistory.push({action:this,stackModel:o.stackModel,timeline:l},()=>{r.isSettled()||r.abort(),c.abort()}),r}initDisplayable(e,t,n,o,i=!0,r){if(i!==!1){let l=e.findElementByDisplayable(this.callee,o);l&&e.disposeDisplayable(n,l.scene,o),e.createDisplayable(n,t,o)}e.flush();let a=new h().registerSkipController(new L(()=>super.executeAction(e,r)));e.getExposedStateAsync(n,l=>{l.initDisplayable(()=>{a.resolve(super.executeAction(e,r))})});let c=e.timelines.attachTimeline(a);return e.actionHistory.push({action:this,stackModel:r.stackModel,timeline:c},()=>{i!==!1&&e.findElementByDisplayable(n,o)&&e.disposeDisplayable(n,t,o)}),a}stringify(e,t,n){return super.stringifyWithName("DisplayableAction")}};le.ActionTypes=ae;var xt=class xt{constructor(){this.src=[];this.future=[]}static catSrc(e){let t=new Set,n=new Set,o=new Set;return e.forEach(({type:i,src:r})=>{i===xt.SrcTypes.image?t.add(r):i===xt.SrcTypes.video?n.add(r):o.add(r)}),{image:Array.from(t),video:Array.from(n),audio:Array.from(o)}}static getSrc(e){return typeof e=="string"?e:e instanceof I?I.getSrcURL(e):e.type==="image"?I.getSrcURL(e.src):e.type==="video"?e.src:e.type==="audio"?e.src.getSrc():""}static getPreloadableSrc(e,t){if(t.is(se,_.jumpTo)){let n=t.contentNode.getContent()[0],i=e.getScene(n,!0).state.backgroundImage;if(S.isImageURL(i.config.src))return{type:"image",src:i.config.src,activeType:"once"}}else if(t instanceof W){let n=t;if(t.is(W,we.setSrc))