@makefully/fancifully 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var Fancifully=(function(S){"use strict";var aa=Object.defineProperty;var oa=(S,ye,xe)=>ye in S?aa(S,ye,{enumerable:!0,configurable:!0,writable:!0,value:xe}):S[ye]=xe;var y=(S,ye,xe)=>oa(S,typeof ye!="symbol"?ye+"":ye,xe);class ye{constructor(){y(this,"volumes",{sound:1,vo:1,sfx:1,music:1});y(this,"elements",new Set);y(this,"paused",!1)}setVolume(e,t){this.volumes[e]=xe(t),this.applyAll()}getVolume(e){return xe(this.volumes.sound)*xe(this.volumes[e])}setPaused(e){this.paused=e;for(const t of this.elements)e&&t.pause()}get isPaused(){return this.paused}register(e,t){this.elements.add(e),e.volume=this.getVolume(t),e.dataset.fcChannel=t}unregister(e){this.elements.delete(e)}applyTo(e,t){e.volume=this.getVolume(t)}applyAll(){for(const e of this.elements){const t=e.dataset.fcChannel||"vo";e.volume=this.getVolume(t)}}}function xe(s){return Number.isNaN(s)?0:Math.min(1,Math.max(0,s))}class $s{constructor(e=[]){y(this,"cues");y(this,"root",null);y(this,"lastActiveId",null);y(this,"readIds",new Set);this.cues=[...e].sort((t,r)=>t.start-r.start)}setCues(e){this.cues=[...e].sort((t,r)=>t.start-r.start),this.reset()}attach(e){this.root=e,this.resetHighlight()}reset(){this.lastActiveId=null,this.readIds.clear(),this.resetHighlight()}update(e){const t=this.cues.find(r=>e>=r.start&&e<r.end)??null;return this.root&&(t?(this.readIds.add(t.id),t.id!==this.lastActiveId&&(this.applyHighlight(t.id),this.lastActiveId=t.id)):this.lastActiveId&&(this.clearActive(),this.lastActiveId=null)),t}applyHighlight(e){if(!this.root)return;this.root.querySelectorAll(".fc-cue.is-active").forEach(r=>r.classList.remove("is-active"));const t=this.root.querySelector(`#${Fs(e)}, [data-cue-id="${Rs(e)}"]`);t&&t.classList.add("fc-cue","is-active","is-read");for(const r of this.readIds){if(r===e)continue;const i=this.root.querySelector(`#${Fs(r)}, [data-cue-id="${Rs(r)}"]`);i==null||i.classList.add("fc-cue","is-read")}}clearActive(){var e;(e=this.root)==null||e.querySelectorAll(".fc-cue.is-active").forEach(t=>t.classList.remove("is-active"))}resetHighlight(){var e;(e=this.root)==null||e.querySelectorAll(".fc-cue").forEach(t=>{t.classList.remove("is-active","is-read")})}}function Fs(s){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(s):s.replace(/[^a-zA-Z0-9_-]/g,"\\$&")}function Rs(s){return s.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}class Yr{constructor(e){y(this,"bus");y(this,"audio");y(this,"timeline",new $s);y(this,"queue",[]);y(this,"raf",0);y(this,"captionsMuted",!1);y(this,"onCaptionLine",null);y(this,"playing",!1);this.bus=e,this.audio=new Audio,this.audio.preload="auto",this.bus.register(this.audio,"vo"),this.audio.addEventListener("ended",()=>this.playNext())}setCaptionsMuted(e){var t;this.captionsMuted=e,e&&((t=this.onCaptionLine)==null||t.call(this,null))}onCaption(e){this.onCaptionLine=e}async playSequence(e){this.stop(),this.queue=e.filter(t=>!!t.url),this.queue.length!==0&&(this.playing=!0,await this.playNext())}pause(){this.audio.pause(),this.cancelTick()}resume(){!this.playing||this.bus.isPaused||(this.audio.play().catch(()=>{}),this.startTick())}stop(){var e;this.playing=!1,this.queue=[],this.audio.pause(),this.audio.removeAttribute("src"),this.audio.load(),this.timeline.reset(),this.cancelTick(),(e=this.onCaptionLine)==null||e.call(this,null)}destroy(){this.stop(),this.bus.unregister(this.audio)}async playNext(){var t;this.cancelTick();const e=this.queue.shift();if(!e){this.playing=!1,this.timeline.reset(),(t=this.onCaptionLine)==null||t.call(this,null);return}this.timeline.setCues(e.cues),this.timeline.attach(e.root),this.bus.register(this.audio,e.channel),this.audio.src=e.url,this.bus.applyTo(this.audio,e.channel);try{await this.audio.play(),this.startTick()}catch{this.startTick()}}startTick(){this.cancelTick();const e=()=>{var t;if(this.playing){if(!this.bus.isPaused&&!this.audio.paused){const r=this.timeline.update(this.audio.currentTime);this.captionsMuted||(t=this.onCaptionLine)==null||t.call(this,(r==null?void 0:r.text)??(r==null?void 0:r.id)??null)}this.raf=requestAnimationFrame(e)}};this.raf=requestAnimationFrame(e)}cancelTick(){this.raf&&(cancelAnimationFrame(this.raf),this.raf=0)}}function Jr(s,e){let t=0,r=0,i=!1;const n=l=>{l.button!=null&&l.button!==0||(i=!0,t=l.clientX,r=l.clientY)},a=l=>{var h,u;if(!i)return;i=!1;const d=l.clientX-t,c=l.clientY-r;Math.abs(d)<50||Math.abs(d)<Math.abs(c)||(d<0?(h=e.onSwipeLeft)==null||h.call(e):(u=e.onSwipeRight)==null||u.call(e))},o=()=>{i=!1};return s.addEventListener("pointerdown",n),s.addEventListener("pointerup",a),s.addEventListener("pointercancel",o),()=>{s.removeEventListener("pointerdown",n),s.removeEventListener("pointerup",a),s.removeEventListener("pointercancel",o)}}function Os(s){var t;const e=((t=s.split(".").pop())==null?void 0:t.toLowerCase())??"";return/^[a-z0-9]{1,8}$/.test(e)?e:""}function zt(s){const e=Os(s.name),t=(s.type||"").toLowerCase();return e==="fanci"||t==="application/x-fanci"||t==="application/fanci"}function Gr(s){var e;if(!((e=s==null?void 0:s.files)!=null&&e.length))return null;for(const t of Array.from(s.files))if(zt(t))return t;return null}var F;(function(s){s.assertEqual=i=>{};function e(i){}s.assertIs=e;function t(i){throw new Error}s.assertNever=t,s.arrayToEnum=i=>{const n={};for(const a of i)n[a]=a;return n},s.getValidEnumValues=i=>{const n=s.objectKeys(i).filter(o=>typeof i[i[o]]!="number"),a={};for(const o of n)a[o]=i[o];return s.objectValues(a)},s.objectValues=i=>s.objectKeys(i).map(function(n){return i[n]}),s.objectKeys=typeof Object.keys=="function"?i=>Object.keys(i):i=>{const n=[];for(const a in i)Object.prototype.hasOwnProperty.call(i,a)&&n.push(a);return n},s.find=(i,n)=>{for(const a of i)if(n(a))return a},s.isInteger=typeof Number.isInteger=="function"?i=>Number.isInteger(i):i=>typeof i=="number"&&Number.isFinite(i)&&Math.floor(i)===i;function r(i,n=" | "){return i.map(a=>typeof a=="string"?`'${a}'`:a).join(n)}s.joinValues=r,s.jsonStringifyReplacer=(i,n)=>typeof n=="bigint"?n.toString():n})(F||(F={}));var Vs;(function(s){s.mergeShapes=(e,t)=>({...e,...t})})(Vs||(Vs={}));const w=F.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Ce=s=>{switch(typeof s){case"undefined":return w.undefined;case"string":return w.string;case"number":return Number.isNaN(s)?w.nan:w.number;case"boolean":return w.boolean;case"function":return w.function;case"bigint":return w.bigint;case"symbol":return w.symbol;case"object":return Array.isArray(s)?w.array:s===null?w.null:s.then&&typeof s.then=="function"&&s.catch&&typeof s.catch=="function"?w.promise:typeof Map<"u"&&s instanceof Map?w.map:typeof Set<"u"&&s instanceof Set?w.set:typeof Date<"u"&&s instanceof Date?w.date:w.object;default:return w.unknown}},p=F.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class ve extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(n){return n.message},r={_errors:[]},i=n=>{for(const a of n.issues)if(a.code==="invalid_union")a.unionErrors.map(i);else if(a.code==="invalid_return_type")i(a.returnTypeError);else if(a.code==="invalid_arguments")i(a.argumentsError);else if(a.path.length===0)r._errors.push(t(a));else{let o=r,l=0;for(;l<a.path.length;){const d=a.path[l];l===a.path.length-1?(o[d]=o[d]||{_errors:[]},o[d]._errors.push(t(a))):o[d]=o[d]||{_errors:[]},o=o[d],l++}}};return i(this),r}static assert(e){if(!(e instanceof ve))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,F.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},r=[];for(const i of this.issues)if(i.path.length>0){const n=i.path[0];t[n]=t[n]||[],t[n].push(e(i))}else r.push(e(i));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}ve.create=s=>new ve(s);const jt=(s,e)=>{let t;switch(s.code){case p.invalid_type:s.received===w.undefined?t="Required":t=`Expected ${s.expected}, received ${s.received}`;break;case p.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(s.expected,F.jsonStringifyReplacer)}`;break;case p.unrecognized_keys:t=`Unrecognized key(s) in object: ${F.joinValues(s.keys,", ")}`;break;case p.invalid_union:t="Invalid input";break;case p.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${F.joinValues(s.options)}`;break;case p.invalid_enum_value:t=`Invalid enum value. Expected ${F.joinValues(s.options)}, received '${s.received}'`;break;case p.invalid_arguments:t="Invalid function arguments";break;case p.invalid_return_type:t="Invalid function return type";break;case p.invalid_date:t="Invalid date";break;case p.invalid_string:typeof s.validation=="object"?"includes"in s.validation?(t=`Invalid input: must include "${s.validation.includes}"`,typeof s.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${s.validation.position}`)):"startsWith"in s.validation?t=`Invalid input: must start with "${s.validation.startsWith}"`:"endsWith"in s.validation?t=`Invalid input: must end with "${s.validation.endsWith}"`:F.assertNever(s.validation):s.validation!=="regex"?t=`Invalid ${s.validation}`:t="Invalid";break;case p.too_small:s.type==="array"?t=`Array must contain ${s.exact?"exactly":s.inclusive?"at least":"more than"} ${s.minimum} element(s)`:s.type==="string"?t=`String must contain ${s.exact?"exactly":s.inclusive?"at least":"over"} ${s.minimum} character(s)`:s.type==="number"?t=`Number must be ${s.exact?"exactly equal to ":s.inclusive?"greater than or equal to ":"greater than "}${s.minimum}`:s.type==="bigint"?t=`Number must be ${s.exact?"exactly equal to ":s.inclusive?"greater than or equal to ":"greater than "}${s.minimum}`:s.type==="date"?t=`Date must be ${s.exact?"exactly equal to ":s.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(s.minimum))}`:t="Invalid input";break;case p.too_big:s.type==="array"?t=`Array must contain ${s.exact?"exactly":s.inclusive?"at most":"less than"} ${s.maximum} element(s)`:s.type==="string"?t=`String must contain ${s.exact?"exactly":s.inclusive?"at most":"under"} ${s.maximum} character(s)`:s.type==="number"?t=`Number must be ${s.exact?"exactly":s.inclusive?"less than or equal to":"less than"} ${s.maximum}`:s.type==="bigint"?t=`BigInt must be ${s.exact?"exactly":s.inclusive?"less than or equal to":"less than"} ${s.maximum}`:s.type==="date"?t=`Date must be ${s.exact?"exactly":s.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(s.maximum))}`:t="Invalid input";break;case p.custom:t="Invalid input";break;case p.invalid_intersection_types:t="Intersection results could not be merged";break;case p.not_multiple_of:t=`Number must be a multiple of ${s.multipleOf}`;break;case p.not_finite:t="Number must be finite";break;default:t=e.defaultError,F.assertNever(s)}return{message:t}};let Xr=jt;function Kr(){return Xr}const Qr=s=>{const{data:e,path:t,errorMaps:r,issueData:i}=s,n=[...t,...i.path||[]],a={...i,path:n};if(i.message!==void 0)return{...i,path:n,message:i.message};let o="";const l=r.filter(d=>!!d).slice().reverse();for(const d of l)o=d(a,{data:e,defaultError:o}).message;return{...i,path:n,message:o}};function k(s,e){const t=Kr(),r=Qr({issueData:e,data:s.data,path:s.path,errorMaps:[s.common.contextualErrorMap,s.schemaErrorMap,t,t===jt?void 0:jt].filter(i=>!!i)});s.common.issues.push(r)}class ee{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const r=[];for(const i of t){if(i.status==="aborted")return A;i.status==="dirty"&&e.dirty(),r.push(i.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){const r=[];for(const i of t){const n=await i.key,a=await i.value;r.push({key:n,value:a})}return ee.mergeObjectSync(e,r)}static mergeObjectSync(e,t){const r={};for(const i of t){const{key:n,value:a}=i;if(n.status==="aborted"||a.status==="aborted")return A;n.status==="dirty"&&e.dirty(),a.status==="dirty"&&e.dirty(),n.value!=="__proto__"&&(typeof a.value<"u"||i.alwaysSet)&&(r[n.value]=a.value)}return{status:e.value,value:r}}}const A=Object.freeze({status:"aborted"}),Ye=s=>({status:"dirty",value:s}),ne=s=>({status:"valid",value:s}),Bs=s=>s.status==="aborted",zs=s=>s.status==="dirty",Re=s=>s.status==="valid",ft=s=>typeof Promise<"u"&&s instanceof Promise;var C;(function(s){s.errToObj=e=>typeof e=="string"?{message:e}:e||{},s.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(C||(C={}));class de{constructor(e,t,r,i){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=i}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const js=(s,e)=>{if(Re(e))return{success:!0,data:e.value};if(!s.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new ve(s.common.issues);return this._error=t,this._error}}};function P(s){if(!s)return{};const{errorMap:e,invalid_type_error:t,required_error:r,description:i}=s;if(e&&(t||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:i}:{errorMap:(a,o)=>{const{message:l}=s;return a.code==="invalid_enum_value"?{message:l??o.defaultError}:typeof o.data>"u"?{message:l??r??o.defaultError}:a.code!=="invalid_type"?{message:o.defaultError}:{message:l??t??o.defaultError}},description:i}}class N{get description(){return this._def.description}_getType(e){return Ce(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:Ce(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new ee,ctx:{common:e.parent.common,data:e.data,parsedType:Ce(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(ft(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){const r={common:{issues:[],async:(t==null?void 0:t.async)??!1,contextualErrorMap:t==null?void 0:t.errorMap},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ce(e)},i=this._parseSync({data:e,path:r.path,parent:r});return js(r,i)}"~validate"(e){var r,i;const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ce(e)};if(!this["~standard"].async)try{const n=this._parseSync({data:e,path:[],parent:t});return Re(n)?{value:n.value}:{issues:t.common.issues}}catch(n){(i=(r=n==null?void 0:n.message)==null?void 0:r.toLowerCase())!=null&&i.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(n=>Re(n)?{value:n.value}:{issues:t.common.issues})}async parseAsync(e,t){const r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){const r={common:{issues:[],contextualErrorMap:t==null?void 0:t.errorMap,async:!0},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ce(e)},i=this._parse({data:e,path:r.path,parent:r}),n=await(ft(i)?i:Promise.resolve(i));return js(r,n)}refine(e,t){const r=i=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(i):t;return this._refinement((i,n)=>{const a=e(i),o=()=>n.addIssue({code:p.custom,...r(i)});return typeof Promise<"u"&&a instanceof Promise?a.then(l=>l?!0:(o(),!1)):a?!0:(o(),!1)})}refinement(e,t){return this._refinement((r,i)=>e(r)?!0:(i.addIssue(typeof t=="function"?t(r,i):t),!1))}_refinement(e){return new Ie({schema:this,typeName:T.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:t=>this["~validate"](t)}}optional(){return we.create(this,this._def)}nullable(){return Ne.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return he.create(this)}promise(){return bt.create(this,this._def)}or(e){return gt.create([this,e],this._def)}and(e){return mt.create(this,e,this._def)}transform(e){return new Ie({...P(this._def),schema:this,typeName:T.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new kt({...P(this._def),innerType:this,defaultValue:t,typeName:T.ZodDefault})}brand(){return new Xs({typeName:T.ZodBranded,type:this,...P(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new wt({...P(this._def),innerType:this,catchValue:t,typeName:T.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return Gt.create(this,e)}readonly(){return St.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const ei=/^c[^\s-]{8,}$/i,ti=/^[0-9a-z]+$/,si=/^[0-9A-HJKMNP-TV-Z]{26}$/i,ri=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,ii=/^[a-z0-9_-]{21}$/i,ni=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ai=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,oi=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,li="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Zt;const ci=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,di=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,hi=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,ui=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,fi=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,pi=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Zs="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",gi=new RegExp(`^${Zs}$`);function Us(s){let e="[0-5]\\d";s.precision?e=`${e}\\.\\d{${s.precision}}`:s.precision==null&&(e=`${e}(\\.\\d+)?`);const t=s.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`}function mi(s){return new RegExp(`^${Us(s)}$`)}function yi(s){let e=`${Zs}T${Us(s)}`;const t=[];return t.push(s.local?"Z?":"Z"),s.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function vi(s,e){return!!((e==="v4"||!e)&&ci.test(s)||(e==="v6"||!e)&&hi.test(s))}function bi(s,e){if(!ni.test(s))return!1;try{const[t]=s.split(".");if(!t)return!1;const r=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),i=JSON.parse(atob(r));return!(typeof i!="object"||i===null||"typ"in i&&(i==null?void 0:i.typ)!=="JWT"||!i.alg||e&&i.alg!==e)}catch{return!1}}function ki(s,e){return!!((e==="v4"||!e)&&di.test(s)||(e==="v6"||!e)&&ui.test(s))}class be extends N{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==w.string){const n=this._getOrReturnCtx(e);return k(n,{code:p.invalid_type,expected:w.string,received:n.parsedType}),A}const r=new ee;let i;for(const n of this._def.checks)if(n.kind==="min")e.data.length<n.value&&(i=this._getOrReturnCtx(e,i),k(i,{code:p.too_small,minimum:n.value,type:"string",inclusive:!0,exact:!1,message:n.message}),r.dirty());else if(n.kind==="max")e.data.length>n.value&&(i=this._getOrReturnCtx(e,i),k(i,{code:p.too_big,maximum:n.value,type:"string",inclusive:!0,exact:!1,message:n.message}),r.dirty());else if(n.kind==="length"){const a=e.data.length>n.value,o=e.data.length<n.value;(a||o)&&(i=this._getOrReturnCtx(e,i),a?k(i,{code:p.too_big,maximum:n.value,type:"string",inclusive:!0,exact:!0,message:n.message}):o&&k(i,{code:p.too_small,minimum:n.value,type:"string",inclusive:!0,exact:!0,message:n.message}),r.dirty())}else if(n.kind==="email")oi.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"email",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="emoji")Zt||(Zt=new RegExp(li,"u")),Zt.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"emoji",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="uuid")ri.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"uuid",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="nanoid")ii.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"nanoid",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="cuid")ei.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"cuid",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="cuid2")ti.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"cuid2",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="ulid")si.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"ulid",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="url")try{new URL(e.data)}catch{i=this._getOrReturnCtx(e,i),k(i,{validation:"url",code:p.invalid_string,message:n.message}),r.dirty()}else n.kind==="regex"?(n.regex.lastIndex=0,n.regex.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"regex",code:p.invalid_string,message:n.message}),r.dirty())):n.kind==="trim"?e.data=e.data.trim():n.kind==="includes"?e.data.includes(n.value,n.position)||(i=this._getOrReturnCtx(e,i),k(i,{code:p.invalid_string,validation:{includes:n.value,position:n.position},message:n.message}),r.dirty()):n.kind==="toLowerCase"?e.data=e.data.toLowerCase():n.kind==="toUpperCase"?e.data=e.data.toUpperCase():n.kind==="startsWith"?e.data.startsWith(n.value)||(i=this._getOrReturnCtx(e,i),k(i,{code:p.invalid_string,validation:{startsWith:n.value},message:n.message}),r.dirty()):n.kind==="endsWith"?e.data.endsWith(n.value)||(i=this._getOrReturnCtx(e,i),k(i,{code:p.invalid_string,validation:{endsWith:n.value},message:n.message}),r.dirty()):n.kind==="datetime"?yi(n).test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{code:p.invalid_string,validation:"datetime",message:n.message}),r.dirty()):n.kind==="date"?gi.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{code:p.invalid_string,validation:"date",message:n.message}),r.dirty()):n.kind==="time"?mi(n).test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{code:p.invalid_string,validation:"time",message:n.message}),r.dirty()):n.kind==="duration"?ai.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"duration",code:p.invalid_string,message:n.message}),r.dirty()):n.kind==="ip"?vi(e.data,n.version)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"ip",code:p.invalid_string,message:n.message}),r.dirty()):n.kind==="jwt"?bi(e.data,n.alg)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"jwt",code:p.invalid_string,message:n.message}),r.dirty()):n.kind==="cidr"?ki(e.data,n.version)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"cidr",code:p.invalid_string,message:n.message}),r.dirty()):n.kind==="base64"?fi.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"base64",code:p.invalid_string,message:n.message}),r.dirty()):n.kind==="base64url"?pi.test(e.data)||(i=this._getOrReturnCtx(e,i),k(i,{validation:"base64url",code:p.invalid_string,message:n.message}),r.dirty()):F.assertNever(n);return{status:r.value,value:e.data}}_regex(e,t,r){return this.refinement(i=>e.test(i),{validation:t,code:p.invalid_string,...C.errToObj(r)})}_addCheck(e){return new be({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...C.errToObj(e)})}url(e){return this._addCheck({kind:"url",...C.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...C.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...C.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...C.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...C.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...C.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...C.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...C.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...C.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...C.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...C.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...C.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(e==null?void 0:e.offset)??!1,local:(e==null?void 0:e.local)??!1,...C.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...C.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...C.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...C.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...C.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...C.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...C.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...C.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...C.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...C.errToObj(t)})}nonempty(e){return this.min(1,C.errToObj(e))}trim(){return new be({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new be({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new be({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}be.create=s=>new be({checks:[],typeName:T.ZodString,coerce:(s==null?void 0:s.coerce)??!1,...P(s)});function wi(s,e){const t=(s.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,i=t>r?t:r,n=Number.parseInt(s.toFixed(i).replace(".","")),a=Number.parseInt(e.toFixed(i).replace(".",""));return n%a/10**i}class Oe extends N{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==w.number){const n=this._getOrReturnCtx(e);return k(n,{code:p.invalid_type,expected:w.number,received:n.parsedType}),A}let r;const i=new ee;for(const n of this._def.checks)n.kind==="int"?F.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),k(r,{code:p.invalid_type,expected:"integer",received:"float",message:n.message}),i.dirty()):n.kind==="min"?(n.inclusive?e.data<n.value:e.data<=n.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:p.too_small,minimum:n.value,type:"number",inclusive:n.inclusive,exact:!1,message:n.message}),i.dirty()):n.kind==="max"?(n.inclusive?e.data>n.value:e.data>=n.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:p.too_big,maximum:n.value,type:"number",inclusive:n.inclusive,exact:!1,message:n.message}),i.dirty()):n.kind==="multipleOf"?wi(e.data,n.value)!==0&&(r=this._getOrReturnCtx(e,r),k(r,{code:p.not_multiple_of,multipleOf:n.value,message:n.message}),i.dirty()):n.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),k(r,{code:p.not_finite,message:n.message}),i.dirty()):F.assertNever(n);return{status:i.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,C.toString(t))}gt(e,t){return this.setLimit("min",e,!1,C.toString(t))}lte(e,t){return this.setLimit("max",e,!0,C.toString(t))}lt(e,t){return this.setLimit("max",e,!1,C.toString(t))}setLimit(e,t,r,i){return new Oe({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:C.toString(i)}]})}_addCheck(e){return new Oe({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:C.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:C.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:C.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:C.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:C.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:C.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:C.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:C.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:C.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&F.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(t===null||r.value>t)&&(t=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(t)&&Number.isFinite(e)}}Oe.create=s=>new Oe({checks:[],typeName:T.ZodNumber,coerce:(s==null?void 0:s.coerce)||!1,...P(s)});class Je extends N{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==w.bigint)return this._getInvalidInput(e);let r;const i=new ee;for(const n of this._def.checks)n.kind==="min"?(n.inclusive?e.data<n.value:e.data<=n.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:p.too_small,type:"bigint",minimum:n.value,inclusive:n.inclusive,message:n.message}),i.dirty()):n.kind==="max"?(n.inclusive?e.data>n.value:e.data>=n.value)&&(r=this._getOrReturnCtx(e,r),k(r,{code:p.too_big,type:"bigint",maximum:n.value,inclusive:n.inclusive,message:n.message}),i.dirty()):n.kind==="multipleOf"?e.data%n.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),k(r,{code:p.not_multiple_of,multipleOf:n.value,message:n.message}),i.dirty()):F.assertNever(n);return{status:i.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return k(t,{code:p.invalid_type,expected:w.bigint,received:t.parsedType}),A}gte(e,t){return this.setLimit("min",e,!0,C.toString(t))}gt(e,t){return this.setLimit("min",e,!1,C.toString(t))}lte(e,t){return this.setLimit("max",e,!0,C.toString(t))}lt(e,t){return this.setLimit("max",e,!1,C.toString(t))}setLimit(e,t,r,i){return new Je({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:C.toString(i)}]})}_addCheck(e){return new Je({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:C.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:C.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:C.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:C.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:C.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}Je.create=s=>new Je({checks:[],typeName:T.ZodBigInt,coerce:(s==null?void 0:s.coerce)??!1,...P(s)});class Ut extends N{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==w.boolean){const r=this._getOrReturnCtx(e);return k(r,{code:p.invalid_type,expected:w.boolean,received:r.parsedType}),A}return ne(e.data)}}Ut.create=s=>new Ut({typeName:T.ZodBoolean,coerce:(s==null?void 0:s.coerce)||!1,...P(s)});class pt extends N{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==w.date){const n=this._getOrReturnCtx(e);return k(n,{code:p.invalid_type,expected:w.date,received:n.parsedType}),A}if(Number.isNaN(e.data.getTime())){const n=this._getOrReturnCtx(e);return k(n,{code:p.invalid_date}),A}const r=new ee;let i;for(const n of this._def.checks)n.kind==="min"?e.data.getTime()<n.value&&(i=this._getOrReturnCtx(e,i),k(i,{code:p.too_small,message:n.message,inclusive:!0,exact:!1,minimum:n.value,type:"date"}),r.dirty()):n.kind==="max"?e.data.getTime()>n.value&&(i=this._getOrReturnCtx(e,i),k(i,{code:p.too_big,message:n.message,inclusive:!0,exact:!1,maximum:n.value,type:"date"}),r.dirty()):F.assertNever(n);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new pt({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:C.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:C.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}pt.create=s=>new pt({checks:[],coerce:(s==null?void 0:s.coerce)||!1,typeName:T.ZodDate,...P(s)});class Hs extends N{_parse(e){if(this._getType(e)!==w.symbol){const r=this._getOrReturnCtx(e);return k(r,{code:p.invalid_type,expected:w.symbol,received:r.parsedType}),A}return ne(e.data)}}Hs.create=s=>new Hs({typeName:T.ZodSymbol,...P(s)});class Ht extends N{_parse(e){if(this._getType(e)!==w.undefined){const r=this._getOrReturnCtx(e);return k(r,{code:p.invalid_type,expected:w.undefined,received:r.parsedType}),A}return ne(e.data)}}Ht.create=s=>new Ht({typeName:T.ZodUndefined,...P(s)});class Dt extends N{_parse(e){if(this._getType(e)!==w.null){const r=this._getOrReturnCtx(e);return k(r,{code:p.invalid_type,expected:w.null,received:r.parsedType}),A}return ne(e.data)}}Dt.create=s=>new Dt({typeName:T.ZodNull,...P(s)});class Ds extends N{constructor(){super(...arguments),this._any=!0}_parse(e){return ne(e.data)}}Ds.create=s=>new Ds({typeName:T.ZodAny,...P(s)});class Ws extends N{constructor(){super(...arguments),this._unknown=!0}_parse(e){return ne(e.data)}}Ws.create=s=>new Ws({typeName:T.ZodUnknown,...P(s)});class Ae extends N{_parse(e){const t=this._getOrReturnCtx(e);return k(t,{code:p.invalid_type,expected:w.never,received:t.parsedType}),A}}Ae.create=s=>new Ae({typeName:T.ZodNever,...P(s)});class qs extends N{_parse(e){if(this._getType(e)!==w.undefined){const r=this._getOrReturnCtx(e);return k(r,{code:p.invalid_type,expected:w.void,received:r.parsedType}),A}return ne(e.data)}}qs.create=s=>new qs({typeName:T.ZodVoid,...P(s)});class he extends N{_parse(e){const{ctx:t,status:r}=this._processInputParams(e),i=this._def;if(t.parsedType!==w.array)return k(t,{code:p.invalid_type,expected:w.array,received:t.parsedType}),A;if(i.exactLength!==null){const a=t.data.length>i.exactLength.value,o=t.data.length<i.exactLength.value;(a||o)&&(k(t,{code:a?p.too_big:p.too_small,minimum:o?i.exactLength.value:void 0,maximum:a?i.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:i.exactLength.message}),r.dirty())}if(i.minLength!==null&&t.data.length<i.minLength.value&&(k(t,{code:p.too_small,minimum:i.minLength.value,type:"array",inclusive:!0,exact:!1,message:i.minLength.message}),r.dirty()),i.maxLength!==null&&t.data.length>i.maxLength.value&&(k(t,{code:p.too_big,maximum:i.maxLength.value,type:"array",inclusive:!0,exact:!1,message:i.maxLength.message}),r.dirty()),t.common.async)return Promise.all([...t.data].map((a,o)=>i.type._parseAsync(new de(t,a,t.path,o)))).then(a=>ee.mergeArray(r,a));const n=[...t.data].map((a,o)=>i.type._parseSync(new de(t,a,t.path,o)));return ee.mergeArray(r,n)}get element(){return this._def.type}min(e,t){return new he({...this._def,minLength:{value:e,message:C.toString(t)}})}max(e,t){return new he({...this._def,maxLength:{value:e,message:C.toString(t)}})}length(e,t){return new he({...this._def,exactLength:{value:e,message:C.toString(t)}})}nonempty(e){return this.min(1,e)}}he.create=(s,e)=>new he({type:s,minLength:null,maxLength:null,exactLength:null,typeName:T.ZodArray,...P(e)});function Ve(s){if(s instanceof Y){const e={};for(const t in s.shape){const r=s.shape[t];e[t]=we.create(Ve(r))}return new Y({...s._def,shape:()=>e})}else return s instanceof he?new he({...s._def,type:Ve(s.element)}):s instanceof we?we.create(Ve(s.unwrap())):s instanceof Ne?Ne.create(Ve(s.unwrap())):s instanceof Me?Me.create(s.items.map(e=>Ve(e))):s}class Y extends N{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=F.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==w.object){const d=this._getOrReturnCtx(e);return k(d,{code:p.invalid_type,expected:w.object,received:d.parsedType}),A}const{status:r,ctx:i}=this._processInputParams(e),{shape:n,keys:a}=this._getCached(),o=[];if(!(this._def.catchall instanceof Ae&&this._def.unknownKeys==="strip"))for(const d in i.data)a.includes(d)||o.push(d);const l=[];for(const d of a){const c=n[d],h=i.data[d];l.push({key:{status:"valid",value:d},value:c._parse(new de(i,h,i.path,d)),alwaysSet:d in i.data})}if(this._def.catchall instanceof Ae){const d=this._def.unknownKeys;if(d==="passthrough")for(const c of o)l.push({key:{status:"valid",value:c},value:{status:"valid",value:i.data[c]}});else if(d==="strict")o.length>0&&(k(i,{code:p.unrecognized_keys,keys:o}),r.dirty());else if(d!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const d=this._def.catchall;for(const c of o){const h=i.data[c];l.push({key:{status:"valid",value:c},value:d._parse(new de(i,h,i.path,c)),alwaysSet:c in i.data})}}return i.common.async?Promise.resolve().then(async()=>{const d=[];for(const c of l){const h=await c.key,u=await c.value;d.push({key:h,value:u,alwaysSet:c.alwaysSet})}return d}).then(d=>ee.mergeObjectSync(r,d)):ee.mergeObjectSync(r,l)}get shape(){return this._def.shape()}strict(e){return C.errToObj,new Y({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,r)=>{var n,a;const i=((a=(n=this._def).errorMap)==null?void 0:a.call(n,t,r).message)??r.defaultError;return t.code==="unrecognized_keys"?{message:C.errToObj(e).message??i}:{message:i}}}:{}})}strip(){return new Y({...this._def,unknownKeys:"strip"})}passthrough(){return new Y({...this._def,unknownKeys:"passthrough"})}extend(e){return new Y({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new Y({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:T.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new Y({...this._def,catchall:e})}pick(e){const t={};for(const r of F.objectKeys(e))e[r]&&this.shape[r]&&(t[r]=this.shape[r]);return new Y({...this._def,shape:()=>t})}omit(e){const t={};for(const r of F.objectKeys(this.shape))e[r]||(t[r]=this.shape[r]);return new Y({...this._def,shape:()=>t})}deepPartial(){return Ve(this)}partial(e){const t={};for(const r of F.objectKeys(this.shape)){const i=this.shape[r];e&&!e[r]?t[r]=i:t[r]=i.optional()}return new Y({...this._def,shape:()=>t})}required(e){const t={};for(const r of F.objectKeys(this.shape))if(e&&!e[r])t[r]=this.shape[r];else{let n=this.shape[r];for(;n instanceof we;)n=n._def.innerType;t[r]=n}return new Y({...this._def,shape:()=>t})}keyof(){return Js(F.objectKeys(this.shape))}}Y.create=(s,e)=>new Y({shape:()=>s,unknownKeys:"strip",catchall:Ae.create(),typeName:T.ZodObject,...P(e)}),Y.strictCreate=(s,e)=>new Y({shape:()=>s,unknownKeys:"strict",catchall:Ae.create(),typeName:T.ZodObject,...P(e)}),Y.lazycreate=(s,e)=>new Y({shape:s,unknownKeys:"strip",catchall:Ae.create(),typeName:T.ZodObject,...P(e)});class gt extends N{_parse(e){const{ctx:t}=this._processInputParams(e),r=this._def.options;function i(n){for(const o of n)if(o.result.status==="valid")return o.result;for(const o of n)if(o.result.status==="dirty")return t.common.issues.push(...o.ctx.common.issues),o.result;const a=n.map(o=>new ve(o.ctx.common.issues));return k(t,{code:p.invalid_union,unionErrors:a}),A}if(t.common.async)return Promise.all(r.map(async n=>{const a={...t,common:{...t.common,issues:[]},parent:null};return{result:await n._parseAsync({data:t.data,path:t.path,parent:a}),ctx:a}})).then(i);{let n;const a=[];for(const l of r){const d={...t,common:{...t.common,issues:[]},parent:null},c=l._parseSync({data:t.data,path:t.path,parent:d});if(c.status==="valid")return c;c.status==="dirty"&&!n&&(n={result:c,ctx:d}),d.common.issues.length&&a.push(d.common.issues)}if(n)return t.common.issues.push(...n.ctx.common.issues),n.result;const o=a.map(l=>new ve(l));return k(t,{code:p.invalid_union,unionErrors:o}),A}}get options(){return this._def.options}}gt.create=(s,e)=>new gt({options:s,typeName:T.ZodUnion,...P(e)});const ke=s=>s instanceof Yt?ke(s.schema):s instanceof Ie?ke(s.innerType()):s instanceof vt?[s.value]:s instanceof Pe?s.options:s instanceof Jt?F.objectValues(s.enum):s instanceof kt?ke(s._def.innerType):s instanceof Ht?[void 0]:s instanceof Dt?[null]:s instanceof we?[void 0,...ke(s.unwrap())]:s instanceof Ne?[null,...ke(s.unwrap())]:s instanceof Xs||s instanceof St?ke(s.unwrap()):s instanceof wt?ke(s._def.innerType):[];class Wt extends N{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==w.object)return k(t,{code:p.invalid_type,expected:w.object,received:t.parsedType}),A;const r=this.discriminator,i=t.data[r],n=this.optionsMap.get(i);return n?t.common.async?n._parseAsync({data:t.data,path:t.path,parent:t}):n._parseSync({data:t.data,path:t.path,parent:t}):(k(t,{code:p.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),A)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,r){const i=new Map;for(const n of t){const a=ke(n.shape[e]);if(!a.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const o of a){if(i.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);i.set(o,n)}}return new Wt({typeName:T.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:i,...P(r)})}}function qt(s,e){const t=Ce(s),r=Ce(e);if(s===e)return{valid:!0,data:s};if(t===w.object&&r===w.object){const i=F.objectKeys(e),n=F.objectKeys(s).filter(o=>i.indexOf(o)!==-1),a={...s,...e};for(const o of n){const l=qt(s[o],e[o]);if(!l.valid)return{valid:!1};a[o]=l.data}return{valid:!0,data:a}}else if(t===w.array&&r===w.array){if(s.length!==e.length)return{valid:!1};const i=[];for(let n=0;n<s.length;n++){const a=s[n],o=e[n],l=qt(a,o);if(!l.valid)return{valid:!1};i.push(l.data)}return{valid:!0,data:i}}else return t===w.date&&r===w.date&&+s==+e?{valid:!0,data:s}:{valid:!1}}class mt extends N{_parse(e){const{status:t,ctx:r}=this._processInputParams(e),i=(n,a)=>{if(Bs(n)||Bs(a))return A;const o=qt(n.value,a.value);return o.valid?((zs(n)||zs(a))&&t.dirty(),{status:t.value,value:o.data}):(k(r,{code:p.invalid_intersection_types}),A)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([n,a])=>i(n,a)):i(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}mt.create=(s,e,t)=>new mt({left:s,right:e,typeName:T.ZodIntersection,...P(t)});class Me extends N{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==w.array)return k(r,{code:p.invalid_type,expected:w.array,received:r.parsedType}),A;if(r.data.length<this._def.items.length)return k(r,{code:p.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),A;!this._def.rest&&r.data.length>this._def.items.length&&(k(r,{code:p.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const n=[...r.data].map((a,o)=>{const l=this._def.items[o]||this._def.rest;return l?l._parse(new de(r,a,r.path,o)):null}).filter(a=>!!a);return r.common.async?Promise.all(n).then(a=>ee.mergeArray(t,a)):ee.mergeArray(t,n)}get items(){return this._def.items}rest(e){return new Me({...this._def,rest:e})}}Me.create=(s,e)=>{if(!Array.isArray(s))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Me({items:s,typeName:T.ZodTuple,rest:null,...P(e)})};class yt extends N{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==w.object)return k(r,{code:p.invalid_type,expected:w.object,received:r.parsedType}),A;const i=[],n=this._def.keyType,a=this._def.valueType;for(const o in r.data)i.push({key:n._parse(new de(r,o,r.path,o)),value:a._parse(new de(r,r.data[o],r.path,o)),alwaysSet:o in r.data});return r.common.async?ee.mergeObjectAsync(t,i):ee.mergeObjectSync(t,i)}get element(){return this._def.valueType}static create(e,t,r){return t instanceof N?new yt({keyType:e,valueType:t,typeName:T.ZodRecord,...P(r)}):new yt({keyType:be.create(),valueType:e,typeName:T.ZodRecord,...P(t)})}}class Ys extends N{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==w.map)return k(r,{code:p.invalid_type,expected:w.map,received:r.parsedType}),A;const i=this._def.keyType,n=this._def.valueType,a=[...r.data.entries()].map(([o,l],d)=>({key:i._parse(new de(r,o,r.path,[d,"key"])),value:n._parse(new de(r,l,r.path,[d,"value"]))}));if(r.common.async){const o=new Map;return Promise.resolve().then(async()=>{for(const l of a){const d=await l.key,c=await l.value;if(d.status==="aborted"||c.status==="aborted")return A;(d.status==="dirty"||c.status==="dirty")&&t.dirty(),o.set(d.value,c.value)}return{status:t.value,value:o}})}else{const o=new Map;for(const l of a){const d=l.key,c=l.value;if(d.status==="aborted"||c.status==="aborted")return A;(d.status==="dirty"||c.status==="dirty")&&t.dirty(),o.set(d.value,c.value)}return{status:t.value,value:o}}}}Ys.create=(s,e,t)=>new Ys({valueType:e,keyType:s,typeName:T.ZodMap,...P(t)});class Ge extends N{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==w.set)return k(r,{code:p.invalid_type,expected:w.set,received:r.parsedType}),A;const i=this._def;i.minSize!==null&&r.data.size<i.minSize.value&&(k(r,{code:p.too_small,minimum:i.minSize.value,type:"set",inclusive:!0,exact:!1,message:i.minSize.message}),t.dirty()),i.maxSize!==null&&r.data.size>i.maxSize.value&&(k(r,{code:p.too_big,maximum:i.maxSize.value,type:"set",inclusive:!0,exact:!1,message:i.maxSize.message}),t.dirty());const n=this._def.valueType;function a(l){const d=new Set;for(const c of l){if(c.status==="aborted")return A;c.status==="dirty"&&t.dirty(),d.add(c.value)}return{status:t.value,value:d}}const o=[...r.data.values()].map((l,d)=>n._parse(new de(r,l,r.path,d)));return r.common.async?Promise.all(o).then(l=>a(l)):a(o)}min(e,t){return new Ge({...this._def,minSize:{value:e,message:C.toString(t)}})}max(e,t){return new Ge({...this._def,maxSize:{value:e,message:C.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}Ge.create=(s,e)=>new Ge({valueType:s,minSize:null,maxSize:null,typeName:T.ZodSet,...P(e)});class Yt extends N{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}Yt.create=(s,e)=>new Yt({getter:s,typeName:T.ZodLazy,...P(e)});class vt extends N{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return k(t,{received:t.data,code:p.invalid_literal,expected:this._def.value}),A}return{status:"valid",value:e.data}}get value(){return this._def.value}}vt.create=(s,e)=>new vt({value:s,typeName:T.ZodLiteral,...P(e)});function Js(s,e){return new Pe({values:s,typeName:T.ZodEnum,...P(e)})}class Pe extends N{_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),r=this._def.values;return k(t,{expected:F.joinValues(r),received:t.parsedType,code:p.invalid_type}),A}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const t=this._getOrReturnCtx(e),r=this._def.values;return k(t,{received:t.data,code:p.invalid_enum_value,options:r}),A}return ne(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return Pe.create(e,{...this._def,...t})}exclude(e,t=this._def){return Pe.create(this.options.filter(r=>!e.includes(r)),{...this._def,...t})}}Pe.create=Js;class Jt extends N{_parse(e){const t=F.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==w.string&&r.parsedType!==w.number){const i=F.objectValues(t);return k(r,{expected:F.joinValues(i),received:r.parsedType,code:p.invalid_type}),A}if(this._cache||(this._cache=new Set(F.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const i=F.objectValues(t);return k(r,{received:r.data,code:p.invalid_enum_value,options:i}),A}return ne(e.data)}get enum(){return this._def.values}}Jt.create=(s,e)=>new Jt({values:s,typeName:T.ZodNativeEnum,...P(e)});class bt extends N{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==w.promise&&t.common.async===!1)return k(t,{code:p.invalid_type,expected:w.promise,received:t.parsedType}),A;const r=t.parsedType===w.promise?t.data:Promise.resolve(t.data);return ne(r.then(i=>this._def.type.parseAsync(i,{path:t.path,errorMap:t.common.contextualErrorMap})))}}bt.create=(s,e)=>new bt({type:s,typeName:T.ZodPromise,...P(e)});class Ie extends N{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===T.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:r}=this._processInputParams(e),i=this._def.effect||null,n={addIssue:a=>{k(r,a),a.fatal?t.abort():t.dirty()},get path(){return r.path}};if(n.addIssue=n.addIssue.bind(n),i.type==="preprocess"){const a=i.transform(r.data,n);if(r.common.async)return Promise.resolve(a).then(async o=>{if(t.value==="aborted")return A;const l=await this._def.schema._parseAsync({data:o,path:r.path,parent:r});return l.status==="aborted"?A:l.status==="dirty"||t.value==="dirty"?Ye(l.value):l});{if(t.value==="aborted")return A;const o=this._def.schema._parseSync({data:a,path:r.path,parent:r});return o.status==="aborted"?A:o.status==="dirty"||t.value==="dirty"?Ye(o.value):o}}if(i.type==="refinement"){const a=o=>{const l=i.refinement(o,n);if(r.common.async)return Promise.resolve(l);if(l instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?A:(o.status==="dirty"&&t.dirty(),a(o.value),{status:t.value,value:o.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>o.status==="aborted"?A:(o.status==="dirty"&&t.dirty(),a(o.value).then(()=>({status:t.value,value:o.value}))))}if(i.type==="transform")if(r.common.async===!1){const a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Re(a))return A;const o=i.transform(a.value,n);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:o}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>Re(a)?Promise.resolve(i.transform(a.value,n)).then(o=>({status:t.value,value:o})):A);F.assertNever(i)}}Ie.create=(s,e,t)=>new Ie({schema:s,typeName:T.ZodEffects,effect:e,...P(t)}),Ie.createWithPreprocess=(s,e,t)=>new Ie({schema:e,effect:{type:"preprocess",transform:s},typeName:T.ZodEffects,...P(t)});class we extends N{_parse(e){return this._getType(e)===w.undefined?ne(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}we.create=(s,e)=>new we({innerType:s,typeName:T.ZodOptional,...P(e)});class Ne extends N{_parse(e){return this._getType(e)===w.null?ne(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Ne.create=(s,e)=>new Ne({innerType:s,typeName:T.ZodNullable,...P(e)});class kt extends N{_parse(e){const{ctx:t}=this._processInputParams(e);let r=t.data;return t.parsedType===w.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}kt.create=(s,e)=>new kt({innerType:s,typeName:T.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...P(e)});class wt extends N{_parse(e){const{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},i=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return ft(i)?i.then(n=>({status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new ve(r.common.issues)},input:r.data})})):{status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new ve(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}wt.create=(s,e)=>new wt({innerType:s,typeName:T.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...P(e)});class Gs extends N{_parse(e){if(this._getType(e)!==w.nan){const r=this._getOrReturnCtx(e);return k(r,{code:p.invalid_type,expected:w.nan,received:r.parsedType}),A}return{status:"valid",value:e.data}}}Gs.create=s=>new Gs({typeName:T.ZodNaN,...P(s)});class Xs extends N{_parse(e){const{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class Gt extends N{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const n=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return n.status==="aborted"?A:n.status==="dirty"?(t.dirty(),Ye(n.value)):this._def.out._parseAsync({data:n.value,path:r.path,parent:r})})();{const i=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?A:i.status==="dirty"?(t.dirty(),{status:"dirty",value:i.value}):this._def.out._parseSync({data:i.value,path:r.path,parent:r})}}static create(e,t){return new Gt({in:e,out:t,typeName:T.ZodPipeline})}}class St extends N{_parse(e){const t=this._def.innerType._parse(e),r=i=>(Re(i)&&(i.value=Object.freeze(i.value)),i);return ft(t)?t.then(i=>r(i)):r(t)}unwrap(){return this._def.innerType}}St.create=(s,e)=>new St({innerType:s,typeName:T.ZodReadonly,...P(e)});var T;(function(s){s.ZodString="ZodString",s.ZodNumber="ZodNumber",s.ZodNaN="ZodNaN",s.ZodBigInt="ZodBigInt",s.ZodBoolean="ZodBoolean",s.ZodDate="ZodDate",s.ZodSymbol="ZodSymbol",s.ZodUndefined="ZodUndefined",s.ZodNull="ZodNull",s.ZodAny="ZodAny",s.ZodUnknown="ZodUnknown",s.ZodNever="ZodNever",s.ZodVoid="ZodVoid",s.ZodArray="ZodArray",s.ZodObject="ZodObject",s.ZodUnion="ZodUnion",s.ZodDiscriminatedUnion="ZodDiscriminatedUnion",s.ZodIntersection="ZodIntersection",s.ZodTuple="ZodTuple",s.ZodRecord="ZodRecord",s.ZodMap="ZodMap",s.ZodSet="ZodSet",s.ZodFunction="ZodFunction",s.ZodLazy="ZodLazy",s.ZodLiteral="ZodLiteral",s.ZodEnum="ZodEnum",s.ZodEffects="ZodEffects",s.ZodNativeEnum="ZodNativeEnum",s.ZodOptional="ZodOptional",s.ZodNullable="ZodNullable",s.ZodDefault="ZodDefault",s.ZodCatch="ZodCatch",s.ZodPromise="ZodPromise",s.ZodBranded="ZodBranded",s.ZodPipeline="ZodPipeline",s.ZodReadonly="ZodReadonly"})(T||(T={}));const $=be.create,te=Oe.create,Xt=Ut.create;Ae.create;const Xe=he.create,H=Y.create,Ke=gt.create,Ks=Wt.create;mt.create,Me.create;const Si=yt.create,$e=vt.create,Qe=Pe.create;bt.create,we.create,Ne.create;const _t=Ke([te(),$()]),Kt=H({x:_t.optional().default(0),y:_t.optional().default(0),width:_t.optional(),height:_t.optional(),fit:Qe(["contain","cover","fill","none"]).optional(),horizontalAlign:Qe(["left","center","right"]).optional(),verticalAlign:Qe(["top","center","bottom"]).optional()}),_i=H({id:$(),start:te(),end:te(),text:$().optional()}),xi=Ks("type",[H({type:$e("image"),src:$()}),H({type:$e("audio"),src:$(),channel:Qe(["vo","sfx","music"]).optional().default("vo")}),H({type:$e("vtt"),src:$()}),H({type:$e("html"),src:$()})]),Ci=Ke([H({play:$()}),H({toggleClass:H({target:$(),className:$()})})]),Ai=H({id:$(),type:$e("text"),layout:Kt.optional().default({}),html:$().optional(),htmlSrc:$().optional(),style:H({fontFamily:$().optional(),fontSize:$().optional(),color:$().optional(),textAlign:Qe(["left","center","right"]).optional(),lineHeight:Ke([$(),te()]).optional(),fontWeight:$().optional(),fontStyle:$().optional()}).optional()}),Ti=H({id:$(),type:$e("image"),asset:$(),layout:Kt.optional().default({}),className:$().optional()}),Ei=H({id:$(),type:$e("hotspot"),layout:Kt.optional().default({}),onTap:Xe(Ci).optional().default([]),ariaLabel:$().optional()}),Li=Ks("type",[Ai,Ti,Ei]),Mi=H({id:$(),background:H({asset:$().optional(),color:$().optional(),innerColor:$().optional()}).optional(),readAloud:H({audio:$(),cues:Ke([$(),Xe(_i)]).optional()}).optional(),blocks:Xe(Li).optional().default([])}),Qs=H({id:$(),title:$().optional(),pageSize:H({width:te().positive(),height:te().positive()}),frontCover:Xt().optional().default(!1),backCover:Xt().optional().default(!1),hardback:Xt().optional().default(!1),coverSize:H({width:te().positive(),height:te().positive()}).optional(),guides:H({marginTop:te().nonnegative().default(48),marginRight:te().nonnegative().default(48),marginBottom:te().nonnegative().default(48),marginLeft:te().nonnegative().default(48),gutterBand:te().nonnegative().default(8)}).optional(),fonts:Xe(H({family:$(),src:$(),weight:Ke([$(),te()]).optional(),style:$().optional()})).optional().default([]),assets:Si(xi).optional().default({}),pages:Xe(Mi).min(1)});function Be(s){return Qs.parse(s)}function Qt(s){const e=s.replace(/^\uFEFF/,"").replace(/\r\n/g,`
1
+ var Fancifully=(function(_){"use strict";var va=Object.defineProperty;var ba=(_,ye,xe)=>ye in _?va(_,ye,{enumerable:!0,configurable:!0,writable:!0,value:xe}):_[ye]=xe;var y=(_,ye,xe)=>ba(_,typeof ye!="symbol"?ye+"":ye,xe);class ye{constructor(){y(this,"volumes",{sound:1,vo:1,sfx:1,music:1});y(this,"elements",new Set);y(this,"paused",!1)}setVolume(e,t){this.volumes[e]=xe(t),this.applyAll()}getVolume(e){return xe(this.volumes.sound)*xe(this.volumes[e])}setPaused(e){this.paused=e;for(const t of this.elements)e&&t.pause()}get isPaused(){return this.paused}register(e,t){this.elements.add(e),e.volume=this.getVolume(t),e.dataset.fcChannel=t}unregister(e){this.elements.delete(e)}applyTo(e,t){e.volume=this.getVolume(t)}applyAll(){for(const e of this.elements){const t=e.dataset.fcChannel||"vo";e.volume=this.getVolume(t)}}}function xe(s){return Number.isNaN(s)?0:Math.min(1,Math.max(0,s))}class Os{constructor(e=[]){y(this,"cues");y(this,"root",null);y(this,"lastActiveId",null);y(this,"readIds",new Set);this.cues=[...e].sort((t,r)=>t.start-r.start)}setCues(e){this.cues=[...e].sort((t,r)=>t.start-r.start),this.reset()}attach(e){this.root=e,this.resetHighlight()}reset(){this.lastActiveId=null,this.readIds.clear(),this.resetHighlight()}update(e){const t=this.cues.find(r=>e>=r.start&&e<r.end)??null;return this.root&&(t?(this.readIds.add(t.id),t.id!==this.lastActiveId&&(this.applyHighlight(t.id),this.lastActiveId=t.id)):this.lastActiveId&&(this.clearActive(),this.lastActiveId=null)),t}applyHighlight(e){if(!this.root)return;this.root.querySelectorAll(".fc-cue.is-active").forEach(r=>r.classList.remove("is-active"));const t=this.root.querySelector(`#${Bs(e)}, [data-cue-id="${Vs(e)}"]`);t&&t.classList.add("fc-cue","is-active","is-read");for(const r of this.readIds){if(r===e)continue;const i=this.root.querySelector(`#${Bs(r)}, [data-cue-id="${Vs(r)}"]`);i==null||i.classList.add("fc-cue","is-read")}}clearActive(){var e;(e=this.root)==null||e.querySelectorAll(".fc-cue.is-active").forEach(t=>t.classList.remove("is-active"))}resetHighlight(){var e;(e=this.root)==null||e.querySelectorAll(".fc-cue").forEach(t=>{t.classList.remove("is-active","is-read")})}}function Bs(s){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(s):s.replace(/[^a-zA-Z0-9_-]/g,"\\$&")}function Vs(s){return s.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}class ei{constructor(e){y(this,"bus");y(this,"audio");y(this,"timeline",new Os);y(this,"queue",[]);y(this,"raf",0);y(this,"captionsMuted",!1);y(this,"onCaptionLine",null);y(this,"playing",!1);this.bus=e,this.audio=new Audio,this.audio.preload="auto",this.bus.register(this.audio,"vo"),this.audio.addEventListener("ended",()=>this.playNext())}setCaptionsMuted(e){var t;this.captionsMuted=e,e&&((t=this.onCaptionLine)==null||t.call(this,null))}onCaption(e){this.onCaptionLine=e}async playSequence(e){this.stop(),this.queue=e.filter(t=>!!t.url),this.queue.length!==0&&(this.playing=!0,await this.playNext())}pause(){this.audio.pause(),this.cancelTick()}resume(){!this.playing||this.bus.isPaused||(this.audio.play().catch(()=>{}),this.startTick())}stop(){var e;this.playing=!1,this.queue=[],this.audio.pause(),this.audio.removeAttribute("src"),this.audio.load(),this.timeline.reset(),this.cancelTick(),(e=this.onCaptionLine)==null||e.call(this,null)}destroy(){this.stop(),this.bus.unregister(this.audio)}async playNext(){var t;this.cancelTick();const e=this.queue.shift();if(!e){this.playing=!1,this.timeline.reset(),(t=this.onCaptionLine)==null||t.call(this,null);return}this.timeline.setCues(e.cues),this.timeline.attach(e.root),this.bus.register(this.audio,e.channel),this.audio.src=e.url,this.bus.applyTo(this.audio,e.channel);try{await this.audio.play(),this.startTick()}catch{this.startTick()}}startTick(){this.cancelTick();const e=()=>{var t;if(this.playing){if(!this.bus.isPaused&&!this.audio.paused){const r=this.timeline.update(this.audio.currentTime);this.captionsMuted||(t=this.onCaptionLine)==null||t.call(this,(r==null?void 0:r.text)??(r==null?void 0:r.id)??null)}this.raf=requestAnimationFrame(e)}};this.raf=requestAnimationFrame(e)}cancelTick(){this.raf&&(cancelAnimationFrame(this.raf),this.raf=0)}}const Ye=new Map;function ti(s,e){Ye.set(s,e)}function zs(s){return Ye.get(s)}function si(){return[...Ye.keys()]}function ri(s){Ye.delete(s)}function ii(){Ye.clear()}function js(s){return s.some(e=>e.requireComplete&&!e.complete)}function ni(s,e){let t=0,r=0,i=!1;const n=l=>{l.button!=null&&l.button!==0||(i=!0,t=l.clientX,r=l.clientY)},a=l=>{var c,u;if(!i)return;i=!1;const d=l.clientX-t,h=l.clientY-r;Math.abs(d)<50||Math.abs(d)<Math.abs(h)||(d<0?(c=e.onSwipeLeft)==null||c.call(e):(u=e.onSwipeRight)==null||u.call(e))},o=()=>{i=!1};return s.addEventListener("pointerdown",n),s.addEventListener("pointerup",a),s.addEventListener("pointercancel",o),()=>{s.removeEventListener("pointerdown",n),s.removeEventListener("pointerup",a),s.removeEventListener("pointercancel",o)}}function Zs(s){var t;const e=((t=s.split(".").pop())==null?void 0:t.toLowerCase())??"";return/^[a-z0-9]{1,8}$/.test(e)?e:""}function Ht(s){const e=Zs(s.name),t=(s.type||"").toLowerCase();return e==="fanci"||t==="application/x-fanci"||t==="application/fanci"}function ai(s){var e;if(!((e=s==null?void 0:s.files)!=null&&e.length))return null;for(const t of Array.from(s.files))if(Ht(t))return t;return null}var F;(function(s){s.assertEqual=i=>{};function e(i){}s.assertIs=e;function t(i){throw new Error}s.assertNever=t,s.arrayToEnum=i=>{const n={};for(const a of i)n[a]=a;return n},s.getValidEnumValues=i=>{const n=s.objectKeys(i).filter(o=>typeof i[i[o]]!="number"),a={};for(const o of n)a[o]=i[o];return s.objectValues(a)},s.objectValues=i=>s.objectKeys(i).map(function(n){return i[n]}),s.objectKeys=typeof Object.keys=="function"?i=>Object.keys(i):i=>{const n=[];for(const a in i)Object.prototype.hasOwnProperty.call(i,a)&&n.push(a);return n},s.find=(i,n)=>{for(const a of i)if(n(a))return a},s.isInteger=typeof Number.isInteger=="function"?i=>Number.isInteger(i):i=>typeof i=="number"&&Number.isFinite(i)&&Math.floor(i)===i;function r(i,n=" | "){return i.map(a=>typeof a=="string"?`'${a}'`:a).join(n)}s.joinValues=r,s.jsonStringifyReplacer=(i,n)=>typeof n=="bigint"?n.toString():n})(F||(F={}));var Us;(function(s){s.mergeShapes=(e,t)=>({...e,...t})})(Us||(Us={}));const x=F.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Ce=s=>{switch(typeof s){case"undefined":return x.undefined;case"string":return x.string;case"number":return Number.isNaN(s)?x.nan:x.number;case"boolean":return x.boolean;case"function":return x.function;case"bigint":return x.bigint;case"symbol":return x.symbol;case"object":return Array.isArray(s)?x.array:s===null?x.null:s.then&&typeof s.then=="function"&&s.catch&&typeof s.catch=="function"?x.promise:typeof Map<"u"&&s instanceof Map?x.map:typeof Set<"u"&&s instanceof Set?x.set:typeof Date<"u"&&s instanceof Date?x.date:x.object;default:return x.unknown}},p=F.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class ve extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(n){return n.message},r={_errors:[]},i=n=>{for(const a of n.issues)if(a.code==="invalid_union")a.unionErrors.map(i);else if(a.code==="invalid_return_type")i(a.returnTypeError);else if(a.code==="invalid_arguments")i(a.argumentsError);else if(a.path.length===0)r._errors.push(t(a));else{let o=r,l=0;for(;l<a.path.length;){const d=a.path[l];l===a.path.length-1?(o[d]=o[d]||{_errors:[]},o[d]._errors.push(t(a))):o[d]=o[d]||{_errors:[]},o=o[d],l++}}};return i(this),r}static assert(e){if(!(e instanceof ve))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,F.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},r=[];for(const i of this.issues)if(i.path.length>0){const n=i.path[0];t[n]=t[n]||[],t[n].push(e(i))}else r.push(e(i));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}ve.create=s=>new ve(s);const Wt=(s,e)=>{let t;switch(s.code){case p.invalid_type:s.received===x.undefined?t="Required":t=`Expected ${s.expected}, received ${s.received}`;break;case p.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(s.expected,F.jsonStringifyReplacer)}`;break;case p.unrecognized_keys:t=`Unrecognized key(s) in object: ${F.joinValues(s.keys,", ")}`;break;case p.invalid_union:t="Invalid input";break;case p.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${F.joinValues(s.options)}`;break;case p.invalid_enum_value:t=`Invalid enum value. Expected ${F.joinValues(s.options)}, received '${s.received}'`;break;case p.invalid_arguments:t="Invalid function arguments";break;case p.invalid_return_type:t="Invalid function return type";break;case p.invalid_date:t="Invalid date";break;case p.invalid_string:typeof s.validation=="object"?"includes"in s.validation?(t=`Invalid input: must include "${s.validation.includes}"`,typeof s.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${s.validation.position}`)):"startsWith"in s.validation?t=`Invalid input: must start with "${s.validation.startsWith}"`:"endsWith"in s.validation?t=`Invalid input: must end with "${s.validation.endsWith}"`:F.assertNever(s.validation):s.validation!=="regex"?t=`Invalid ${s.validation}`:t="Invalid";break;case p.too_small:s.type==="array"?t=`Array must contain ${s.exact?"exactly":s.inclusive?"at least":"more than"} ${s.minimum} element(s)`:s.type==="string"?t=`String must contain ${s.exact?"exactly":s.inclusive?"at least":"over"} ${s.minimum} character(s)`:s.type==="number"?t=`Number must be ${s.exact?"exactly equal to ":s.inclusive?"greater than or equal to ":"greater than "}${s.minimum}`:s.type==="bigint"?t=`Number must be ${s.exact?"exactly equal to ":s.inclusive?"greater than or equal to ":"greater than "}${s.minimum}`:s.type==="date"?t=`Date must be ${s.exact?"exactly equal to ":s.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(s.minimum))}`:t="Invalid input";break;case p.too_big:s.type==="array"?t=`Array must contain ${s.exact?"exactly":s.inclusive?"at most":"less than"} ${s.maximum} element(s)`:s.type==="string"?t=`String must contain ${s.exact?"exactly":s.inclusive?"at most":"under"} ${s.maximum} character(s)`:s.type==="number"?t=`Number must be ${s.exact?"exactly":s.inclusive?"less than or equal to":"less than"} ${s.maximum}`:s.type==="bigint"?t=`BigInt must be ${s.exact?"exactly":s.inclusive?"less than or equal to":"less than"} ${s.maximum}`:s.type==="date"?t=`Date must be ${s.exact?"exactly":s.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(s.maximum))}`:t="Invalid input";break;case p.custom:t="Invalid input";break;case p.invalid_intersection_types:t="Intersection results could not be merged";break;case p.not_multiple_of:t=`Number must be a multiple of ${s.multipleOf}`;break;case p.not_finite:t="Number must be finite";break;default:t=e.defaultError,F.assertNever(s)}return{message:t}};let oi=Wt;function li(){return oi}const ci=s=>{const{data:e,path:t,errorMaps:r,issueData:i}=s,n=[...t,...i.path||[]],a={...i,path:n};if(i.message!==void 0)return{...i,path:n,message:i.message};let o="";const l=r.filter(d=>!!d).slice().reverse();for(const d of l)o=d(a,{data:e,defaultError:o}).message;return{...i,path:n,message:o}};function S(s,e){const t=li(),r=ci({issueData:e,data:s.data,path:s.path,errorMaps:[s.common.contextualErrorMap,s.schemaErrorMap,t,t===Wt?void 0:Wt].filter(i=>!!i)});s.common.issues.push(r)}class ee{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const r=[];for(const i of t){if(i.status==="aborted")return T;i.status==="dirty"&&e.dirty(),r.push(i.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){const r=[];for(const i of t){const n=await i.key,a=await i.value;r.push({key:n,value:a})}return ee.mergeObjectSync(e,r)}static mergeObjectSync(e,t){const r={};for(const i of t){const{key:n,value:a}=i;if(n.status==="aborted"||a.status==="aborted")return T;n.status==="dirty"&&e.dirty(),a.status==="dirty"&&e.dirty(),n.value!=="__proto__"&&(typeof a.value<"u"||i.alwaysSet)&&(r[n.value]=a.value)}return{status:e.value,value:r}}}const T=Object.freeze({status:"aborted"}),Je=s=>({status:"dirty",value:s}),ne=s=>({status:"valid",value:s}),Ds=s=>s.status==="aborted",Hs=s=>s.status==="dirty",Oe=s=>s.status==="valid",gt=s=>typeof Promise<"u"&&s instanceof Promise;var C;(function(s){s.errToObj=e=>typeof e=="string"?{message:e}:e||{},s.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(C||(C={}));class de{constructor(e,t,r,i){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=i}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Ws=(s,e)=>{if(Oe(e))return{success:!0,data:e.value};if(!s.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new ve(s.common.issues);return this._error=t,this._error}}};function M(s){if(!s)return{};const{errorMap:e,invalid_type_error:t,required_error:r,description:i}=s;if(e&&(t||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:i}:{errorMap:(a,o)=>{const{message:l}=s;return a.code==="invalid_enum_value"?{message:l??o.defaultError}:typeof o.data>"u"?{message:l??r??o.defaultError}:a.code!=="invalid_type"?{message:o.defaultError}:{message:l??t??o.defaultError}},description:i}}class ${get description(){return this._def.description}_getType(e){return Ce(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:Ce(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new ee,ctx:{common:e.parent.common,data:e.data,parsedType:Ce(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(gt(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){const r={common:{issues:[],async:(t==null?void 0:t.async)??!1,contextualErrorMap:t==null?void 0:t.errorMap},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ce(e)},i=this._parseSync({data:e,path:r.path,parent:r});return Ws(r,i)}"~validate"(e){var r,i;const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ce(e)};if(!this["~standard"].async)try{const n=this._parseSync({data:e,path:[],parent:t});return Oe(n)?{value:n.value}:{issues:t.common.issues}}catch(n){(i=(r=n==null?void 0:n.message)==null?void 0:r.toLowerCase())!=null&&i.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(n=>Oe(n)?{value:n.value}:{issues:t.common.issues})}async parseAsync(e,t){const r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){const r={common:{issues:[],contextualErrorMap:t==null?void 0:t.errorMap,async:!0},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ce(e)},i=this._parse({data:e,path:r.path,parent:r}),n=await(gt(i)?i:Promise.resolve(i));return Ws(r,n)}refine(e,t){const r=i=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(i):t;return this._refinement((i,n)=>{const a=e(i),o=()=>n.addIssue({code:p.custom,...r(i)});return typeof Promise<"u"&&a instanceof Promise?a.then(l=>l?!0:(o(),!1)):a?!0:(o(),!1)})}refinement(e,t){return this._refinement((r,i)=>e(r)?!0:(i.addIssue(typeof t=="function"?t(r,i):t),!1))}_refinement(e){return new Ie({schema:this,typeName:L.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:t=>this["~validate"](t)}}optional(){return we.create(this,this._def)}nullable(){return $e.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return he.create(this)}promise(){return wt.create(this,this._def)}or(e){return yt.create([this,e],this._def)}and(e){return vt.create(this,e,this._def)}transform(e){return new Ie({...M(this._def),schema:this,typeName:L.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new St({...M(this._def),innerType:this,defaultValue:t,typeName:L.ZodDefault})}brand(){return new tr({typeName:L.ZodBranded,type:this,...M(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new _t({...M(this._def),innerType:this,catchValue:t,typeName:L.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return ss.create(this,e)}readonly(){return xt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const di=/^c[^\s-]{8,}$/i,hi=/^[0-9a-z]+$/,ui=/^[0-9A-HJKMNP-TV-Z]{26}$/i,fi=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,pi=/^[a-z0-9_-]{21}$/i,gi=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,mi=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,yi=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,vi="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let qt;const bi=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ki=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,wi=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,Si=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,_i=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,xi=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,qs="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",Ci=new RegExp(`^${qs}$`);function Gs(s){let e="[0-5]\\d";s.precision?e=`${e}\\.\\d{${s.precision}}`:s.precision==null&&(e=`${e}(\\.\\d+)?`);const t=s.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`}function Ai(s){return new RegExp(`^${Gs(s)}$`)}function Ti(s){let e=`${qs}T${Gs(s)}`;const t=[];return t.push(s.local?"Z?":"Z"),s.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function Li(s,e){return!!((e==="v4"||!e)&&bi.test(s)||(e==="v6"||!e)&&wi.test(s))}function Ei(s,e){if(!gi.test(s))return!1;try{const[t]=s.split(".");if(!t)return!1;const r=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),i=JSON.parse(atob(r));return!(typeof i!="object"||i===null||"typ"in i&&(i==null?void 0:i.typ)!=="JWT"||!i.alg||e&&i.alg!==e)}catch{return!1}}function Pi(s,e){return!!((e==="v4"||!e)&&ki.test(s)||(e==="v6"||!e)&&Si.test(s))}class be extends ${_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==x.string){const n=this._getOrReturnCtx(e);return S(n,{code:p.invalid_type,expected:x.string,received:n.parsedType}),T}const r=new ee;let i;for(const n of this._def.checks)if(n.kind==="min")e.data.length<n.value&&(i=this._getOrReturnCtx(e,i),S(i,{code:p.too_small,minimum:n.value,type:"string",inclusive:!0,exact:!1,message:n.message}),r.dirty());else if(n.kind==="max")e.data.length>n.value&&(i=this._getOrReturnCtx(e,i),S(i,{code:p.too_big,maximum:n.value,type:"string",inclusive:!0,exact:!1,message:n.message}),r.dirty());else if(n.kind==="length"){const a=e.data.length>n.value,o=e.data.length<n.value;(a||o)&&(i=this._getOrReturnCtx(e,i),a?S(i,{code:p.too_big,maximum:n.value,type:"string",inclusive:!0,exact:!0,message:n.message}):o&&S(i,{code:p.too_small,minimum:n.value,type:"string",inclusive:!0,exact:!0,message:n.message}),r.dirty())}else if(n.kind==="email")yi.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"email",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="emoji")qt||(qt=new RegExp(vi,"u")),qt.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"emoji",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="uuid")fi.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"uuid",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="nanoid")pi.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"nanoid",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="cuid")di.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"cuid",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="cuid2")hi.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"cuid2",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="ulid")ui.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"ulid",code:p.invalid_string,message:n.message}),r.dirty());else if(n.kind==="url")try{new URL(e.data)}catch{i=this._getOrReturnCtx(e,i),S(i,{validation:"url",code:p.invalid_string,message:n.message}),r.dirty()}else n.kind==="regex"?(n.regex.lastIndex=0,n.regex.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"regex",code:p.invalid_string,message:n.message}),r.dirty())):n.kind==="trim"?e.data=e.data.trim():n.kind==="includes"?e.data.includes(n.value,n.position)||(i=this._getOrReturnCtx(e,i),S(i,{code:p.invalid_string,validation:{includes:n.value,position:n.position},message:n.message}),r.dirty()):n.kind==="toLowerCase"?e.data=e.data.toLowerCase():n.kind==="toUpperCase"?e.data=e.data.toUpperCase():n.kind==="startsWith"?e.data.startsWith(n.value)||(i=this._getOrReturnCtx(e,i),S(i,{code:p.invalid_string,validation:{startsWith:n.value},message:n.message}),r.dirty()):n.kind==="endsWith"?e.data.endsWith(n.value)||(i=this._getOrReturnCtx(e,i),S(i,{code:p.invalid_string,validation:{endsWith:n.value},message:n.message}),r.dirty()):n.kind==="datetime"?Ti(n).test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{code:p.invalid_string,validation:"datetime",message:n.message}),r.dirty()):n.kind==="date"?Ci.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{code:p.invalid_string,validation:"date",message:n.message}),r.dirty()):n.kind==="time"?Ai(n).test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{code:p.invalid_string,validation:"time",message:n.message}),r.dirty()):n.kind==="duration"?mi.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"duration",code:p.invalid_string,message:n.message}),r.dirty()):n.kind==="ip"?Li(e.data,n.version)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"ip",code:p.invalid_string,message:n.message}),r.dirty()):n.kind==="jwt"?Ei(e.data,n.alg)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"jwt",code:p.invalid_string,message:n.message}),r.dirty()):n.kind==="cidr"?Pi(e.data,n.version)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"cidr",code:p.invalid_string,message:n.message}),r.dirty()):n.kind==="base64"?_i.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"base64",code:p.invalid_string,message:n.message}),r.dirty()):n.kind==="base64url"?xi.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"base64url",code:p.invalid_string,message:n.message}),r.dirty()):F.assertNever(n);return{status:r.value,value:e.data}}_regex(e,t,r){return this.refinement(i=>e.test(i),{validation:t,code:p.invalid_string,...C.errToObj(r)})}_addCheck(e){return new be({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...C.errToObj(e)})}url(e){return this._addCheck({kind:"url",...C.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...C.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...C.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...C.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...C.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...C.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...C.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...C.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...C.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...C.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...C.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...C.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(e==null?void 0:e.offset)??!1,local:(e==null?void 0:e.local)??!1,...C.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...C.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...C.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...C.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...C.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...C.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...C.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...C.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...C.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...C.errToObj(t)})}nonempty(e){return this.min(1,C.errToObj(e))}trim(){return new be({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new be({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new be({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}be.create=s=>new be({checks:[],typeName:L.ZodString,coerce:(s==null?void 0:s.coerce)??!1,...M(s)});function Mi(s,e){const t=(s.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,i=t>r?t:r,n=Number.parseInt(s.toFixed(i).replace(".","")),a=Number.parseInt(e.toFixed(i).replace(".",""));return n%a/10**i}class Be extends ${constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==x.number){const n=this._getOrReturnCtx(e);return S(n,{code:p.invalid_type,expected:x.number,received:n.parsedType}),T}let r;const i=new ee;for(const n of this._def.checks)n.kind==="int"?F.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),S(r,{code:p.invalid_type,expected:"integer",received:"float",message:n.message}),i.dirty()):n.kind==="min"?(n.inclusive?e.data<n.value:e.data<=n.value)&&(r=this._getOrReturnCtx(e,r),S(r,{code:p.too_small,minimum:n.value,type:"number",inclusive:n.inclusive,exact:!1,message:n.message}),i.dirty()):n.kind==="max"?(n.inclusive?e.data>n.value:e.data>=n.value)&&(r=this._getOrReturnCtx(e,r),S(r,{code:p.too_big,maximum:n.value,type:"number",inclusive:n.inclusive,exact:!1,message:n.message}),i.dirty()):n.kind==="multipleOf"?Mi(e.data,n.value)!==0&&(r=this._getOrReturnCtx(e,r),S(r,{code:p.not_multiple_of,multipleOf:n.value,message:n.message}),i.dirty()):n.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),S(r,{code:p.not_finite,message:n.message}),i.dirty()):F.assertNever(n);return{status:i.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,C.toString(t))}gt(e,t){return this.setLimit("min",e,!1,C.toString(t))}lte(e,t){return this.setLimit("max",e,!0,C.toString(t))}lt(e,t){return this.setLimit("max",e,!1,C.toString(t))}setLimit(e,t,r,i){return new Be({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:C.toString(i)}]})}_addCheck(e){return new Be({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:C.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:C.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:C.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:C.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:C.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:C.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:C.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:C.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:C.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&F.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(t===null||r.value>t)&&(t=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(t)&&Number.isFinite(e)}}Be.create=s=>new Be({checks:[],typeName:L.ZodNumber,coerce:(s==null?void 0:s.coerce)||!1,...M(s)});class Xe extends ${constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==x.bigint)return this._getInvalidInput(e);let r;const i=new ee;for(const n of this._def.checks)n.kind==="min"?(n.inclusive?e.data<n.value:e.data<=n.value)&&(r=this._getOrReturnCtx(e,r),S(r,{code:p.too_small,type:"bigint",minimum:n.value,inclusive:n.inclusive,message:n.message}),i.dirty()):n.kind==="max"?(n.inclusive?e.data>n.value:e.data>=n.value)&&(r=this._getOrReturnCtx(e,r),S(r,{code:p.too_big,type:"bigint",maximum:n.value,inclusive:n.inclusive,message:n.message}),i.dirty()):n.kind==="multipleOf"?e.data%n.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),S(r,{code:p.not_multiple_of,multipleOf:n.value,message:n.message}),i.dirty()):F.assertNever(n);return{status:i.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return S(t,{code:p.invalid_type,expected:x.bigint,received:t.parsedType}),T}gte(e,t){return this.setLimit("min",e,!0,C.toString(t))}gt(e,t){return this.setLimit("min",e,!1,C.toString(t))}lte(e,t){return this.setLimit("max",e,!0,C.toString(t))}lt(e,t){return this.setLimit("max",e,!1,C.toString(t))}setLimit(e,t,r,i){return new Xe({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:C.toString(i)}]})}_addCheck(e){return new Xe({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:C.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:C.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:C.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:C.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:C.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}Xe.create=s=>new Xe({checks:[],typeName:L.ZodBigInt,coerce:(s==null?void 0:s.coerce)??!1,...M(s)});class Gt extends ${_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==x.boolean){const r=this._getOrReturnCtx(e);return S(r,{code:p.invalid_type,expected:x.boolean,received:r.parsedType}),T}return ne(e.data)}}Gt.create=s=>new Gt({typeName:L.ZodBoolean,coerce:(s==null?void 0:s.coerce)||!1,...M(s)});class mt extends ${_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==x.date){const n=this._getOrReturnCtx(e);return S(n,{code:p.invalid_type,expected:x.date,received:n.parsedType}),T}if(Number.isNaN(e.data.getTime())){const n=this._getOrReturnCtx(e);return S(n,{code:p.invalid_date}),T}const r=new ee;let i;for(const n of this._def.checks)n.kind==="min"?e.data.getTime()<n.value&&(i=this._getOrReturnCtx(e,i),S(i,{code:p.too_small,message:n.message,inclusive:!0,exact:!1,minimum:n.value,type:"date"}),r.dirty()):n.kind==="max"?e.data.getTime()>n.value&&(i=this._getOrReturnCtx(e,i),S(i,{code:p.too_big,message:n.message,inclusive:!0,exact:!1,maximum:n.value,type:"date"}),r.dirty()):F.assertNever(n);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new mt({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:C.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:C.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}mt.create=s=>new mt({checks:[],coerce:(s==null?void 0:s.coerce)||!1,typeName:L.ZodDate,...M(s)});class Ys extends ${_parse(e){if(this._getType(e)!==x.symbol){const r=this._getOrReturnCtx(e);return S(r,{code:p.invalid_type,expected:x.symbol,received:r.parsedType}),T}return ne(e.data)}}Ys.create=s=>new Ys({typeName:L.ZodSymbol,...M(s)});class Yt extends ${_parse(e){if(this._getType(e)!==x.undefined){const r=this._getOrReturnCtx(e);return S(r,{code:p.invalid_type,expected:x.undefined,received:r.parsedType}),T}return ne(e.data)}}Yt.create=s=>new Yt({typeName:L.ZodUndefined,...M(s)});class Jt extends ${_parse(e){if(this._getType(e)!==x.null){const r=this._getOrReturnCtx(e);return S(r,{code:p.invalid_type,expected:x.null,received:r.parsedType}),T}return ne(e.data)}}Jt.create=s=>new Jt({typeName:L.ZodNull,...M(s)});class Js extends ${constructor(){super(...arguments),this._any=!0}_parse(e){return ne(e.data)}}Js.create=s=>new Js({typeName:L.ZodAny,...M(s)});class Xt extends ${constructor(){super(...arguments),this._unknown=!0}_parse(e){return ne(e.data)}}Xt.create=s=>new Xt({typeName:L.ZodUnknown,...M(s)});class Ae extends ${_parse(e){const t=this._getOrReturnCtx(e);return S(t,{code:p.invalid_type,expected:x.never,received:t.parsedType}),T}}Ae.create=s=>new Ae({typeName:L.ZodNever,...M(s)});class Xs extends ${_parse(e){if(this._getType(e)!==x.undefined){const r=this._getOrReturnCtx(e);return S(r,{code:p.invalid_type,expected:x.void,received:r.parsedType}),T}return ne(e.data)}}Xs.create=s=>new Xs({typeName:L.ZodVoid,...M(s)});class he extends ${_parse(e){const{ctx:t,status:r}=this._processInputParams(e),i=this._def;if(t.parsedType!==x.array)return S(t,{code:p.invalid_type,expected:x.array,received:t.parsedType}),T;if(i.exactLength!==null){const a=t.data.length>i.exactLength.value,o=t.data.length<i.exactLength.value;(a||o)&&(S(t,{code:a?p.too_big:p.too_small,minimum:o?i.exactLength.value:void 0,maximum:a?i.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:i.exactLength.message}),r.dirty())}if(i.minLength!==null&&t.data.length<i.minLength.value&&(S(t,{code:p.too_small,minimum:i.minLength.value,type:"array",inclusive:!0,exact:!1,message:i.minLength.message}),r.dirty()),i.maxLength!==null&&t.data.length>i.maxLength.value&&(S(t,{code:p.too_big,maximum:i.maxLength.value,type:"array",inclusive:!0,exact:!1,message:i.maxLength.message}),r.dirty()),t.common.async)return Promise.all([...t.data].map((a,o)=>i.type._parseAsync(new de(t,a,t.path,o)))).then(a=>ee.mergeArray(r,a));const n=[...t.data].map((a,o)=>i.type._parseSync(new de(t,a,t.path,o)));return ee.mergeArray(r,n)}get element(){return this._def.type}min(e,t){return new he({...this._def,minLength:{value:e,message:C.toString(t)}})}max(e,t){return new he({...this._def,maxLength:{value:e,message:C.toString(t)}})}length(e,t){return new he({...this._def,exactLength:{value:e,message:C.toString(t)}})}nonempty(e){return this.min(1,e)}}he.create=(s,e)=>new he({type:s,minLength:null,maxLength:null,exactLength:null,typeName:L.ZodArray,...M(e)});function Ve(s){if(s instanceof G){const e={};for(const t in s.shape){const r=s.shape[t];e[t]=we.create(Ve(r))}return new G({...s._def,shape:()=>e})}else return s instanceof he?new he({...s._def,type:Ve(s.element)}):s instanceof we?we.create(Ve(s.unwrap())):s instanceof $e?$e.create(Ve(s.unwrap())):s instanceof Me?Me.create(s.items.map(e=>Ve(e))):s}class G extends ${constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=F.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==x.object){const d=this._getOrReturnCtx(e);return S(d,{code:p.invalid_type,expected:x.object,received:d.parsedType}),T}const{status:r,ctx:i}=this._processInputParams(e),{shape:n,keys:a}=this._getCached(),o=[];if(!(this._def.catchall instanceof Ae&&this._def.unknownKeys==="strip"))for(const d in i.data)a.includes(d)||o.push(d);const l=[];for(const d of a){const h=n[d],c=i.data[d];l.push({key:{status:"valid",value:d},value:h._parse(new de(i,c,i.path,d)),alwaysSet:d in i.data})}if(this._def.catchall instanceof Ae){const d=this._def.unknownKeys;if(d==="passthrough")for(const h of o)l.push({key:{status:"valid",value:h},value:{status:"valid",value:i.data[h]}});else if(d==="strict")o.length>0&&(S(i,{code:p.unrecognized_keys,keys:o}),r.dirty());else if(d!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const d=this._def.catchall;for(const h of o){const c=i.data[h];l.push({key:{status:"valid",value:h},value:d._parse(new de(i,c,i.path,h)),alwaysSet:h in i.data})}}return i.common.async?Promise.resolve().then(async()=>{const d=[];for(const h of l){const c=await h.key,u=await h.value;d.push({key:c,value:u,alwaysSet:h.alwaysSet})}return d}).then(d=>ee.mergeObjectSync(r,d)):ee.mergeObjectSync(r,l)}get shape(){return this._def.shape()}strict(e){return C.errToObj,new G({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,r)=>{var n,a;const i=((a=(n=this._def).errorMap)==null?void 0:a.call(n,t,r).message)??r.defaultError;return t.code==="unrecognized_keys"?{message:C.errToObj(e).message??i}:{message:i}}}:{}})}strip(){return new G({...this._def,unknownKeys:"strip"})}passthrough(){return new G({...this._def,unknownKeys:"passthrough"})}extend(e){return new G({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new G({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:L.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new G({...this._def,catchall:e})}pick(e){const t={};for(const r of F.objectKeys(e))e[r]&&this.shape[r]&&(t[r]=this.shape[r]);return new G({...this._def,shape:()=>t})}omit(e){const t={};for(const r of F.objectKeys(this.shape))e[r]||(t[r]=this.shape[r]);return new G({...this._def,shape:()=>t})}deepPartial(){return Ve(this)}partial(e){const t={};for(const r of F.objectKeys(this.shape)){const i=this.shape[r];e&&!e[r]?t[r]=i:t[r]=i.optional()}return new G({...this._def,shape:()=>t})}required(e){const t={};for(const r of F.objectKeys(this.shape))if(e&&!e[r])t[r]=this.shape[r];else{let n=this.shape[r];for(;n instanceof we;)n=n._def.innerType;t[r]=n}return new G({...this._def,shape:()=>t})}keyof(){return Qs(F.objectKeys(this.shape))}}G.create=(s,e)=>new G({shape:()=>s,unknownKeys:"strip",catchall:Ae.create(),typeName:L.ZodObject,...M(e)}),G.strictCreate=(s,e)=>new G({shape:()=>s,unknownKeys:"strict",catchall:Ae.create(),typeName:L.ZodObject,...M(e)}),G.lazycreate=(s,e)=>new G({shape:s,unknownKeys:"strip",catchall:Ae.create(),typeName:L.ZodObject,...M(e)});class yt extends ${_parse(e){const{ctx:t}=this._processInputParams(e),r=this._def.options;function i(n){for(const o of n)if(o.result.status==="valid")return o.result;for(const o of n)if(o.result.status==="dirty")return t.common.issues.push(...o.ctx.common.issues),o.result;const a=n.map(o=>new ve(o.ctx.common.issues));return S(t,{code:p.invalid_union,unionErrors:a}),T}if(t.common.async)return Promise.all(r.map(async n=>{const a={...t,common:{...t.common,issues:[]},parent:null};return{result:await n._parseAsync({data:t.data,path:t.path,parent:a}),ctx:a}})).then(i);{let n;const a=[];for(const l of r){const d={...t,common:{...t.common,issues:[]},parent:null},h=l._parseSync({data:t.data,path:t.path,parent:d});if(h.status==="valid")return h;h.status==="dirty"&&!n&&(n={result:h,ctx:d}),d.common.issues.length&&a.push(d.common.issues)}if(n)return t.common.issues.push(...n.ctx.common.issues),n.result;const o=a.map(l=>new ve(l));return S(t,{code:p.invalid_union,unionErrors:o}),T}}get options(){return this._def.options}}yt.create=(s,e)=>new yt({options:s,typeName:L.ZodUnion,...M(e)});const ke=s=>s instanceof es?ke(s.schema):s instanceof Ie?ke(s.innerType()):s instanceof kt?[s.value]:s instanceof Ne?s.options:s instanceof ts?F.objectValues(s.enum):s instanceof St?ke(s._def.innerType):s instanceof Yt?[void 0]:s instanceof Jt?[null]:s instanceof we?[void 0,...ke(s.unwrap())]:s instanceof $e?[null,...ke(s.unwrap())]:s instanceof tr||s instanceof xt?ke(s.unwrap()):s instanceof _t?ke(s._def.innerType):[];class Kt extends ${_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==x.object)return S(t,{code:p.invalid_type,expected:x.object,received:t.parsedType}),T;const r=this.discriminator,i=t.data[r],n=this.optionsMap.get(i);return n?t.common.async?n._parseAsync({data:t.data,path:t.path,parent:t}):n._parseSync({data:t.data,path:t.path,parent:t}):(S(t,{code:p.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),T)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,r){const i=new Map;for(const n of t){const a=ke(n.shape[e]);if(!a.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const o of a){if(i.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);i.set(o,n)}}return new Kt({typeName:L.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:i,...M(r)})}}function Qt(s,e){const t=Ce(s),r=Ce(e);if(s===e)return{valid:!0,data:s};if(t===x.object&&r===x.object){const i=F.objectKeys(e),n=F.objectKeys(s).filter(o=>i.indexOf(o)!==-1),a={...s,...e};for(const o of n){const l=Qt(s[o],e[o]);if(!l.valid)return{valid:!1};a[o]=l.data}return{valid:!0,data:a}}else if(t===x.array&&r===x.array){if(s.length!==e.length)return{valid:!1};const i=[];for(let n=0;n<s.length;n++){const a=s[n],o=e[n],l=Qt(a,o);if(!l.valid)return{valid:!1};i.push(l.data)}return{valid:!0,data:i}}else return t===x.date&&r===x.date&&+s==+e?{valid:!0,data:s}:{valid:!1}}class vt extends ${_parse(e){const{status:t,ctx:r}=this._processInputParams(e),i=(n,a)=>{if(Ds(n)||Ds(a))return T;const o=Qt(n.value,a.value);return o.valid?((Hs(n)||Hs(a))&&t.dirty(),{status:t.value,value:o.data}):(S(r,{code:p.invalid_intersection_types}),T)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([n,a])=>i(n,a)):i(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}vt.create=(s,e,t)=>new vt({left:s,right:e,typeName:L.ZodIntersection,...M(t)});class Me extends ${_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==x.array)return S(r,{code:p.invalid_type,expected:x.array,received:r.parsedType}),T;if(r.data.length<this._def.items.length)return S(r,{code:p.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),T;!this._def.rest&&r.data.length>this._def.items.length&&(S(r,{code:p.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const n=[...r.data].map((a,o)=>{const l=this._def.items[o]||this._def.rest;return l?l._parse(new de(r,a,r.path,o)):null}).filter(a=>!!a);return r.common.async?Promise.all(n).then(a=>ee.mergeArray(t,a)):ee.mergeArray(t,n)}get items(){return this._def.items}rest(e){return new Me({...this._def,rest:e})}}Me.create=(s,e)=>{if(!Array.isArray(s))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Me({items:s,typeName:L.ZodTuple,rest:null,...M(e)})};class bt extends ${get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==x.object)return S(r,{code:p.invalid_type,expected:x.object,received:r.parsedType}),T;const i=[],n=this._def.keyType,a=this._def.valueType;for(const o in r.data)i.push({key:n._parse(new de(r,o,r.path,o)),value:a._parse(new de(r,r.data[o],r.path,o)),alwaysSet:o in r.data});return r.common.async?ee.mergeObjectAsync(t,i):ee.mergeObjectSync(t,i)}get element(){return this._def.valueType}static create(e,t,r){return t instanceof $?new bt({keyType:e,valueType:t,typeName:L.ZodRecord,...M(r)}):new bt({keyType:be.create(),valueType:e,typeName:L.ZodRecord,...M(t)})}}class Ks extends ${get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==x.map)return S(r,{code:p.invalid_type,expected:x.map,received:r.parsedType}),T;const i=this._def.keyType,n=this._def.valueType,a=[...r.data.entries()].map(([o,l],d)=>({key:i._parse(new de(r,o,r.path,[d,"key"])),value:n._parse(new de(r,l,r.path,[d,"value"]))}));if(r.common.async){const o=new Map;return Promise.resolve().then(async()=>{for(const l of a){const d=await l.key,h=await l.value;if(d.status==="aborted"||h.status==="aborted")return T;(d.status==="dirty"||h.status==="dirty")&&t.dirty(),o.set(d.value,h.value)}return{status:t.value,value:o}})}else{const o=new Map;for(const l of a){const d=l.key,h=l.value;if(d.status==="aborted"||h.status==="aborted")return T;(d.status==="dirty"||h.status==="dirty")&&t.dirty(),o.set(d.value,h.value)}return{status:t.value,value:o}}}}Ks.create=(s,e,t)=>new Ks({valueType:e,keyType:s,typeName:L.ZodMap,...M(t)});class Ke extends ${_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==x.set)return S(r,{code:p.invalid_type,expected:x.set,received:r.parsedType}),T;const i=this._def;i.minSize!==null&&r.data.size<i.minSize.value&&(S(r,{code:p.too_small,minimum:i.minSize.value,type:"set",inclusive:!0,exact:!1,message:i.minSize.message}),t.dirty()),i.maxSize!==null&&r.data.size>i.maxSize.value&&(S(r,{code:p.too_big,maximum:i.maxSize.value,type:"set",inclusive:!0,exact:!1,message:i.maxSize.message}),t.dirty());const n=this._def.valueType;function a(l){const d=new Set;for(const h of l){if(h.status==="aborted")return T;h.status==="dirty"&&t.dirty(),d.add(h.value)}return{status:t.value,value:d}}const o=[...r.data.values()].map((l,d)=>n._parse(new de(r,l,r.path,d)));return r.common.async?Promise.all(o).then(l=>a(l)):a(o)}min(e,t){return new Ke({...this._def,minSize:{value:e,message:C.toString(t)}})}max(e,t){return new Ke({...this._def,maxSize:{value:e,message:C.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}Ke.create=(s,e)=>new Ke({valueType:s,minSize:null,maxSize:null,typeName:L.ZodSet,...M(e)});class es extends ${get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}es.create=(s,e)=>new es({getter:s,typeName:L.ZodLazy,...M(e)});class kt extends ${_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return S(t,{received:t.data,code:p.invalid_literal,expected:this._def.value}),T}return{status:"valid",value:e.data}}get value(){return this._def.value}}kt.create=(s,e)=>new kt({value:s,typeName:L.ZodLiteral,...M(e)});function Qs(s,e){return new Ne({values:s,typeName:L.ZodEnum,...M(e)})}class Ne extends ${_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),r=this._def.values;return S(t,{expected:F.joinValues(r),received:t.parsedType,code:p.invalid_type}),T}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const t=this._getOrReturnCtx(e),r=this._def.values;return S(t,{received:t.data,code:p.invalid_enum_value,options:r}),T}return ne(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return Ne.create(e,{...this._def,...t})}exclude(e,t=this._def){return Ne.create(this.options.filter(r=>!e.includes(r)),{...this._def,...t})}}Ne.create=Qs;class ts extends ${_parse(e){const t=F.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==x.string&&r.parsedType!==x.number){const i=F.objectValues(t);return S(r,{expected:F.joinValues(i),received:r.parsedType,code:p.invalid_type}),T}if(this._cache||(this._cache=new Set(F.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const i=F.objectValues(t);return S(r,{received:r.data,code:p.invalid_enum_value,options:i}),T}return ne(e.data)}get enum(){return this._def.values}}ts.create=(s,e)=>new ts({values:s,typeName:L.ZodNativeEnum,...M(e)});class wt extends ${unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==x.promise&&t.common.async===!1)return S(t,{code:p.invalid_type,expected:x.promise,received:t.parsedType}),T;const r=t.parsedType===x.promise?t.data:Promise.resolve(t.data);return ne(r.then(i=>this._def.type.parseAsync(i,{path:t.path,errorMap:t.common.contextualErrorMap})))}}wt.create=(s,e)=>new wt({type:s,typeName:L.ZodPromise,...M(e)});class Ie extends ${innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===L.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:r}=this._processInputParams(e),i=this._def.effect||null,n={addIssue:a=>{S(r,a),a.fatal?t.abort():t.dirty()},get path(){return r.path}};if(n.addIssue=n.addIssue.bind(n),i.type==="preprocess"){const a=i.transform(r.data,n);if(r.common.async)return Promise.resolve(a).then(async o=>{if(t.value==="aborted")return T;const l=await this._def.schema._parseAsync({data:o,path:r.path,parent:r});return l.status==="aborted"?T:l.status==="dirty"||t.value==="dirty"?Je(l.value):l});{if(t.value==="aborted")return T;const o=this._def.schema._parseSync({data:a,path:r.path,parent:r});return o.status==="aborted"?T:o.status==="dirty"||t.value==="dirty"?Je(o.value):o}}if(i.type==="refinement"){const a=o=>{const l=i.refinement(o,n);if(r.common.async)return Promise.resolve(l);if(l instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?T:(o.status==="dirty"&&t.dirty(),a(o.value),{status:t.value,value:o.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>o.status==="aborted"?T:(o.status==="dirty"&&t.dirty(),a(o.value).then(()=>({status:t.value,value:o.value}))))}if(i.type==="transform")if(r.common.async===!1){const a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Oe(a))return T;const o=i.transform(a.value,n);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:o}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>Oe(a)?Promise.resolve(i.transform(a.value,n)).then(o=>({status:t.value,value:o})):T);F.assertNever(i)}}Ie.create=(s,e,t)=>new Ie({schema:s,typeName:L.ZodEffects,effect:e,...M(t)}),Ie.createWithPreprocess=(s,e,t)=>new Ie({schema:e,effect:{type:"preprocess",transform:s},typeName:L.ZodEffects,...M(t)});class we extends ${_parse(e){return this._getType(e)===x.undefined?ne(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}we.create=(s,e)=>new we({innerType:s,typeName:L.ZodOptional,...M(e)});class $e extends ${_parse(e){return this._getType(e)===x.null?ne(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}$e.create=(s,e)=>new $e({innerType:s,typeName:L.ZodNullable,...M(e)});class St extends ${_parse(e){const{ctx:t}=this._processInputParams(e);let r=t.data;return t.parsedType===x.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}St.create=(s,e)=>new St({innerType:s,typeName:L.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...M(e)});class _t extends ${_parse(e){const{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},i=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return gt(i)?i.then(n=>({status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new ve(r.common.issues)},input:r.data})})):{status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new ve(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}_t.create=(s,e)=>new _t({innerType:s,typeName:L.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...M(e)});class er extends ${_parse(e){if(this._getType(e)!==x.nan){const r=this._getOrReturnCtx(e);return S(r,{code:p.invalid_type,expected:x.nan,received:r.parsedType}),T}return{status:"valid",value:e.data}}}er.create=s=>new er({typeName:L.ZodNaN,...M(s)});class tr extends ${_parse(e){const{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class ss extends ${_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const n=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return n.status==="aborted"?T:n.status==="dirty"?(t.dirty(),Je(n.value)):this._def.out._parseAsync({data:n.value,path:r.path,parent:r})})();{const i=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?T:i.status==="dirty"?(t.dirty(),{status:"dirty",value:i.value}):this._def.out._parseSync({data:i.value,path:r.path,parent:r})}}static create(e,t){return new ss({in:e,out:t,typeName:L.ZodPipeline})}}class xt extends ${_parse(e){const t=this._def.innerType._parse(e),r=i=>(Oe(i)&&(i.value=Object.freeze(i.value)),i);return gt(t)?t.then(i=>r(i)):r(t)}unwrap(){return this._def.innerType}}xt.create=(s,e)=>new xt({innerType:s,typeName:L.ZodReadonly,...M(e)});var L;(function(s){s.ZodString="ZodString",s.ZodNumber="ZodNumber",s.ZodNaN="ZodNaN",s.ZodBigInt="ZodBigInt",s.ZodBoolean="ZodBoolean",s.ZodDate="ZodDate",s.ZodSymbol="ZodSymbol",s.ZodUndefined="ZodUndefined",s.ZodNull="ZodNull",s.ZodAny="ZodAny",s.ZodUnknown="ZodUnknown",s.ZodNever="ZodNever",s.ZodVoid="ZodVoid",s.ZodArray="ZodArray",s.ZodObject="ZodObject",s.ZodUnion="ZodUnion",s.ZodDiscriminatedUnion="ZodDiscriminatedUnion",s.ZodIntersection="ZodIntersection",s.ZodTuple="ZodTuple",s.ZodRecord="ZodRecord",s.ZodMap="ZodMap",s.ZodSet="ZodSet",s.ZodFunction="ZodFunction",s.ZodLazy="ZodLazy",s.ZodLiteral="ZodLiteral",s.ZodEnum="ZodEnum",s.ZodEffects="ZodEffects",s.ZodNativeEnum="ZodNativeEnum",s.ZodOptional="ZodOptional",s.ZodNullable="ZodNullable",s.ZodDefault="ZodDefault",s.ZodCatch="ZodCatch",s.ZodPromise="ZodPromise",s.ZodBranded="ZodBranded",s.ZodPipeline="ZodPipeline",s.ZodReadonly="ZodReadonly"})(L||(L={}));const N=be.create,te=Be.create,Ct=Gt.create,Ni=Xt.create;Ae.create;const ze=he.create,V=G.create,Qe=yt.create,sr=Kt.create;vt.create,Me.create;const rr=bt.create,Te=kt.create,et=Ne.create;wt.create,we.create,$e.create;const At=Qe([te(),N()]),Tt=V({x:At.optional().default(0),y:At.optional().default(0),width:At.optional(),height:At.optional(),fit:et(["contain","cover","fill","none"]).optional(),horizontalAlign:et(["left","center","right"]).optional(),verticalAlign:et(["top","center","bottom"]).optional()}),Ii=V({id:N(),start:te(),end:te(),text:N().optional()}),$i=sr("type",[V({type:Te("image"),src:N()}),V({type:Te("audio"),src:N(),channel:et(["vo","sfx","music"]).optional().default("vo")}),V({type:Te("vtt"),src:N()}),V({type:Te("html"),src:N()})]),Lt=V({target:N(),className:N()}),ir=Qe([V({play:N()}),V({toggleClass:Lt}),V({addClass:Lt}),V({removeClass:Lt}),V({replayClass:Lt})]),Ri=V({id:N(),type:Te("text"),layout:Tt.optional().default({}),html:N().optional(),htmlSrc:N().optional(),style:V({fontFamily:N().optional(),fontSize:N().optional(),color:N().optional(),textAlign:et(["left","center","right"]).optional(),lineHeight:Qe([N(),te()]).optional(),fontWeight:N().optional(),fontStyle:N().optional()}).optional()}),Fi=V({id:N(),type:Te("image"),asset:N(),layout:Tt.optional().default({}),className:N().optional()}),Oi=V({id:N(),type:Te("hotspot"),layout:Tt.optional().default({}),onTap:ze(ir).optional().default([]),requiredTaps:te().int().positive().optional(),onComplete:ze(ir).optional().default([]),ariaLabel:N().optional()}),Bi=V({id:N(),type:Te("area"),layout:Tt.optional().default({}),game:N().min(1),params:rr(Ni()).optional(),ariaLabel:N().optional(),requireComplete:Ct().optional().default(!1)}),Vi=sr("type",[Ri,Fi,Oi,Bi]),zi=V({id:N(),background:V({asset:N().optional(),color:N().optional(),innerColor:N().optional()}).optional(),readAloud:V({audio:N(),cues:Qe([N(),ze(Ii)]).optional()}).optional(),blocks:ze(Vi).optional().default([])}),nr=V({id:N(),title:N().optional(),pageSize:V({width:te().positive(),height:te().positive()}),frontCover:Ct().optional().default(!1),backCover:Ct().optional().default(!1),hardback:Ct().optional().default(!1),coverSize:V({width:te().positive(),height:te().positive()}).optional(),guides:V({marginTop:te().nonnegative().default(48),marginRight:te().nonnegative().default(48),marginBottom:te().nonnegative().default(48),marginLeft:te().nonnegative().default(48),gutterBand:te().nonnegative().default(8)}).optional(),fonts:ze(V({family:N(),src:N(),weight:Qe([N(),te()]).optional(),style:N().optional()})).optional().default([]),assets:rr($i).optional().default({}),pages:ze(zi).min(1)});function je(s){return nr.parse(s)}function rs(s){const e=s.replace(/^\uFEFF/,"").replace(/\r\n/g,`
2
2
  `).trim();if(!e.startsWith("WEBVTT"))throw new Error("Invalid WebVTT: missing WEBVTT header");const r=e.slice(e.indexOf(`
3
3
  `)+1).split(/\n\n+/),i=[];let n=0;for(const a of r){const o=a.split(`
4
- `).map(b=>b.trim()).filter(b=>b.length>0&&!b.startsWith("NOTE"));if(o.length===0)continue;const l=o.findIndex(b=>b.includes("-->"));if(l===-1)continue;const d=l>0?o[0]:void 0,c=o[l],h=o.slice(l+1),u=c.split("-->").map(b=>b.trim().split(/\s+/)[0]);if(u.length<2)continue;const g=er(u[0]),x=er(u[1]),v=h.join(" ").trim(),f=d||v||`cue-${n++}`;i.push({id:f,start:g,end:x,text:v||void 0})}return i}function er(s){const e=s.trim().split(":");if(e.length===3){const[t,r,i]=e;return Number(t)*3600+Number(r)*60+Number(i)}if(e.length===2){const[t,r]=e;return Number(t)*60+Number(r)}return Number(s)}function ze(s,e){if(/^(?:[a-z]+:)?\/\//i.test(e)||e.startsWith("data:")||e.startsWith("blob:")||!s)return e;try{return new URL(e,es(s)).href}catch{return`${es(s)}${e.replace(/^\//,"")}`}}function es(s){return s.endsWith("/")||s.includes("?")?s.endsWith("/")?s:`${s}/`:/\.[a-z0-9]+$/i.test(s.split("/").pop()??"")?s.replace(/[^/]+$/,""):`${s}/`}function Pi(s){try{const e=new URL(s,typeof location<"u"?location.href:"http://local/");e.hash="";const t=e.pathname;return e.pathname=t.replace(/[^/]+$/,""),e.href}catch{return es(s.replace(/[^/]+$/,""))}}async function et(s,e){typeof document>"u"||!("fonts"in document)||await Promise.all(s.fonts.map(async t=>{const r=ze(e,t.src),n=await new FontFace(t.family,`url(${JSON.stringify(r)})`,{weight:t.weight!=null?String(t.weight):"normal",style:t.style??"normal"}).load();document.fonts.add(n)}))}var D=Uint8Array,se=Uint16Array,ts=Int32Array,xt=new D([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Ct=new D([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),ss=new D([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),tr=function(s,e){for(var t=new se(31),r=0;r<31;++r)t[r]=e+=1<<s[r-1];for(var i=new ts(t[30]),r=1;r<30;++r)for(var n=t[r];n<t[r+1];++n)i[n]=n-t[r]<<5|r;return{b:t,r:i}},sr=tr(xt,2),rr=sr.b,rs=sr.r;rr[28]=258,rs[258]=28;for(var ir=tr(Ct,0),Ii=ir.b,nr=ir.r,is=new se(32768),B=0;B<32768;++B){var Te=(B&43690)>>1|(B&21845)<<1;Te=(Te&52428)>>2|(Te&13107)<<2,Te=(Te&61680)>>4|(Te&3855)<<4,is[B]=((Te&65280)>>8|(Te&255)<<8)>>1}for(var ue=(function(s,e,t){for(var r=s.length,i=0,n=new se(e);i<r;++i)s[i]&&++n[s[i]-1];var a=new se(e);for(i=1;i<e;++i)a[i]=a[i-1]+n[i-1]<<1;var o;if(t){o=new se(1<<e);var l=15-e;for(i=0;i<r;++i)if(s[i])for(var d=i<<4|s[i],c=e-s[i],h=a[s[i]-1]++<<c,u=h|(1<<c)-1;h<=u;++h)o[is[h]>>l]=d}else for(o=new se(r),i=0;i<r;++i)s[i]&&(o[i]=is[a[s[i]-1]++]>>15-s[i]);return o}),Ee=new D(288),B=0;B<144;++B)Ee[B]=8;for(var B=144;B<256;++B)Ee[B]=9;for(var B=256;B<280;++B)Ee[B]=7;for(var B=280;B<288;++B)Ee[B]=8;for(var tt=new D(32),B=0;B<32;++B)tt[B]=5;var Ni=ue(Ee,9,0),$i=ue(Ee,9,1),Fi=ue(tt,5,0),Ri=ue(tt,5,1),ns=function(s){for(var e=s[0],t=1;t<s.length;++t)s[t]>e&&(e=s[t]);return e},ce=function(s,e,t){var r=e/8|0;return(s[r]|s[r+1]<<8)>>(e&7)&t},as=function(s,e){var t=e/8|0;return(s[t]|s[t+1]<<8|s[t+2]<<16)>>(e&7)},os=function(s){return(s+7)/8|0},st=function(s,e,t){return(e==null||e<0)&&(e=0),(t==null||t>s.length)&&(t=s.length),new D(s.subarray(e,t))},Oi=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Q=function(s,e,t){var r=new Error(e||Oi[s]);if(r.code=s,Error.captureStackTrace&&Error.captureStackTrace(r,Q),!t)throw r;return r},Vi=function(s,e,t,r){var i=s.length,n=r?r.length:0;if(!i||e.f&&!e.l)return t||new D(0);var a=!t,o=a||e.i!=2,l=e.i;a&&(t=new D(i*3));var d=function(ht){var ut=t.length;if(ht>ut){var qe=new D(Math.max(ut*2,ht));qe.set(t),t=qe}},c=e.f||0,h=e.p||0,u=e.b||0,g=e.l,x=e.d,v=e.m,f=e.n,b=i*8;do{if(!g){c=ce(s,h,1);var _=ce(s,h+1,3);if(h+=3,_)if(_==1)g=$i,x=Ri,v=9,f=5;else if(_==2){var L=ce(s,h,31)+257,O=ce(s,h+10,15)+4,I=L+ce(s,h+5,31)+1;h+=14;for(var M=new D(I),W=new D(19),Z=0;Z<O;++Z)W[ss[Z]]=ce(s,h+Z*3,7);h+=O*3;for(var J=ns(W),oe=(1<<J)-1,V=ue(W,J,1),Z=0;Z<I;){var j=V[ce(s,h,oe)];h+=j&15;var m=j>>4;if(m<16)M[Z++]=m;else{var q=0,z=0;for(m==16?(z=3+ce(s,h,3),h+=2,q=M[Z-1]):m==17?(z=3+ce(s,h,7),h+=3):m==18&&(z=11+ce(s,h,127),h+=7);z--;)M[Z++]=q}}var X=M.subarray(0,L),K=M.subarray(L);v=ns(X),f=ns(K),g=ue(X,v,1),x=ue(K,f,1)}else Q(1);else{var m=os(h)+4,E=s[m-4]|s[m-3]<<8,R=m+E;if(R>i){l&&Q(0);break}o&&d(u+E),t.set(s.subarray(m,R),u),e.b=u+=E,e.p=h=R*8,e.f=c;continue}if(h>b){l&&Q(0);break}}o&&d(u+131072);for(var dt=(1<<v)-1,le=(1<<f)-1,_e=h;;_e=h){var q=g[as(s,h)&dt],re=q>>4;if(h+=q&15,h>b){l&&Q(0);break}if(q||Q(2),re<256)t[u++]=re;else if(re==256){_e=h,g=null;break}else{var ie=re-254;if(re>264){var Z=re-257,U=xt[Z];ie=ce(s,h,(1<<U)-1)+rr[Z],h+=U}var me=x[as(s,h)&le],De=me>>4;me||Q(3),h+=me&15;var K=Ii[De];if(De>3){var U=Ct[De];K+=as(s,h)&(1<<U)-1,h+=U}if(h>b){l&&Q(0);break}o&&d(u+131072);var We=u+ie;if(u<K){var Vt=n-K,Bt=Math.min(K,We);for(Vt+u<0&&Q(3);u<Bt;++u)t[u]=r[Vt+u]}for(;u<We;++u)t[u]=t[u-K]}}e.l=g,e.p=_e,e.b=u,e.f=c,g&&(c=1,e.m=v,e.d=x,e.n=f)}while(!c);return u!=t.length&&a?st(t,0,u):t.subarray(0,u)},Se=function(s,e,t){t<<=e&7;var r=e/8|0;s[r]|=t,s[r+1]|=t>>8},rt=function(s,e,t){t<<=e&7;var r=e/8|0;s[r]|=t,s[r+1]|=t>>8,s[r+2]|=t>>16},ls=function(s,e){for(var t=[],r=0;r<s.length;++r)s[r]&&t.push({s:r,f:s[r]});var i=t.length,n=t.slice();if(!i)return{t:cr,l:0};if(i==1){var a=new D(t[0].s+1);return a[t[0].s]=1,{t:a,l:1}}t.sort(function(R,L){return R.f-L.f}),t.push({s:-1,f:25001});var o=t[0],l=t[1],d=0,c=1,h=2;for(t[0]={s:-1,f:o.f+l.f,l:o,r:l};c!=i-1;)o=t[t[d].f<t[h].f?d++:h++],l=t[d!=c&&t[d].f<t[h].f?d++:h++],t[c++]={s:-1,f:o.f+l.f,l:o,r:l};for(var u=n[0].s,r=1;r<i;++r)n[r].s>u&&(u=n[r].s);var g=new se(u+1),x=cs(t[c-1],g,0);if(x>e){var r=0,v=0,f=x-e,b=1<<f;for(n.sort(function(L,O){return g[O.s]-g[L.s]||L.f-O.f});r<i;++r){var _=n[r].s;if(g[_]>e)v+=b-(1<<x-g[_]),g[_]=e;else break}for(v>>=f;v>0;){var m=n[r].s;g[m]<e?v-=1<<e-g[m]++-1:++r}for(;r>=0&&v;--r){var E=n[r].s;g[E]==e&&(--g[E],++v)}x=e}return{t:new D(g),l:x}},cs=function(s,e,t){return s.s==-1?Math.max(cs(s.l,e,t+1),cs(s.r,e,t+1)):e[s.s]=t},ar=function(s){for(var e=s.length;e&&!s[--e];);for(var t=new se(++e),r=0,i=s[0],n=1,a=function(l){t[r++]=l},o=1;o<=e;++o)if(s[o]==i&&o!=e)++n;else{if(!i&&n>2){for(;n>138;n-=138)a(32754);n>2&&(a(n>10?n-11<<5|28690:n-3<<5|12305),n=0)}else if(n>3){for(a(i),--n;n>6;n-=6)a(8304);n>2&&(a(n-3<<5|8208),n=0)}for(;n--;)a(i);n=1,i=s[o]}return{c:t.subarray(0,r),n:e}},it=function(s,e){for(var t=0,r=0;r<e.length;++r)t+=s[r]*e[r];return t},or=function(s,e,t){var r=t.length,i=os(e+2);s[i]=r&255,s[i+1]=r>>8,s[i+2]=s[i]^255,s[i+3]=s[i+1]^255;for(var n=0;n<r;++n)s[i+n+4]=t[n];return(i+4+r)*8},lr=function(s,e,t,r,i,n,a,o,l,d,c){Se(e,c++,t),++i[256];for(var h=ls(i,15),u=h.t,g=h.l,x=ls(n,15),v=x.t,f=x.l,b=ar(u),_=b.c,m=b.n,E=ar(v),R=E.c,L=E.n,O=new se(19),I=0;I<_.length;++I)++O[_[I]&31];for(var I=0;I<R.length;++I)++O[R[I]&31];for(var M=ls(O,7),W=M.t,Z=M.l,J=19;J>4&&!W[ss[J-1]];--J);var oe=d+5<<3,V=it(i,Ee)+it(n,tt)+a,j=it(i,u)+it(n,v)+a+14+3*J+it(O,W)+2*O[16]+3*O[17]+7*O[18];if(l>=0&&oe<=V&&oe<=j)return or(e,c,s.subarray(l,l+d));var q,z,X,K;if(Se(e,c,1+(j<V)),c+=2,j<V){q=ue(u,g,0),z=u,X=ue(v,f,0),K=v;var dt=ue(W,Z,0);Se(e,c,m-257),Se(e,c+5,L-1),Se(e,c+10,J-4),c+=14;for(var I=0;I<J;++I)Se(e,c+3*I,W[ss[I]]);c+=3*J;for(var le=[_,R],_e=0;_e<2;++_e)for(var re=le[_e],I=0;I<re.length;++I){var ie=re[I]&31;Se(e,c,dt[ie]),c+=W[ie],ie>15&&(Se(e,c,re[I]>>5&127),c+=re[I]>>12)}}else q=Ni,z=Ee,X=Fi,K=tt;for(var I=0;I<o;++I){var U=r[I];if(U>255){var ie=U>>18&31;rt(e,c,q[ie+257]),c+=z[ie+257],ie>7&&(Se(e,c,U>>23&31),c+=xt[ie]);var me=U&31;rt(e,c,X[me]),c+=K[me],me>3&&(rt(e,c,U>>5&8191),c+=Ct[me])}else rt(e,c,q[U]),c+=z[U]}return rt(e,c,q[256]),c+z[256]},Bi=new ts([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),cr=new D(0),zi=function(s,e,t,r,i,n){var a=n.z||s.length,o=new D(r+a+5*(1+Math.ceil(a/7e3))+i),l=o.subarray(r,o.length-i),d=n.l,c=(n.r||0)&7;if(e){c&&(l[0]=n.r>>3);for(var h=Bi[e-1],u=h>>13,g=h&8191,x=(1<<t)-1,v=n.p||new se(32768),f=n.h||new se(x+1),b=Math.ceil(t/3),_=2*b,m=function(Ns){return(s[Ns]^s[Ns+1]<<b^s[Ns+2]<<_)&x},E=new ts(25e3),R=new se(288),L=new se(32),O=0,I=0,M=n.i||0,W=0,Z=n.w||0,J=0;M+2<a;++M){var oe=m(M),V=M&32767,j=f[oe];if(v[V]=j,f[oe]=V,Z<=M){var q=a-M;if((O>7e3||W>24576)&&(q>423||!d)){c=lr(s,l,0,E,R,L,I,W,J,M-J,c),W=O=I=0,J=M;for(var z=0;z<286;++z)R[z]=0;for(var z=0;z<30;++z)L[z]=0}var X=2,K=0,dt=g,le=V-j&32767;if(q>2&&oe==m(M-le))for(var _e=Math.min(u,q)-1,re=Math.min(32767,M),ie=Math.min(258,q);le<=re&&--dt&&V!=j;){if(s[M+X]==s[M+X-le]){for(var U=0;U<ie&&s[M+U]==s[M+U-le];++U);if(U>X){if(X=U,K=le,U>_e)break;for(var me=Math.min(le,U-2),De=0,z=0;z<me;++z){var We=M-le+z&32767,Vt=v[We],Bt=We-Vt&32767;Bt>De&&(De=Bt,j=We)}}}V=j,j=v[V],le+=V-j&32767}if(K){E[W++]=268435456|rs[X]<<18|nr[K];var ht=rs[X]&31,ut=nr[K]&31;I+=xt[ht]+Ct[ut],++R[257+ht],++L[ut],Z=M+X,++O}else E[W++]=s[M],++R[s[M]]}}for(M=Math.max(M,Z);M<a;++M)E[W++]=s[M],++R[s[M]];c=lr(s,l,d,E,R,L,I,W,J,M-J,c),d||(n.r=c&7|l[c/8|0]<<3,c-=7,n.h=f,n.p=v,n.i=M,n.w=Z)}else{for(var M=n.w||0;M<a+d;M+=65535){var qe=M+65535;qe>=a&&(l[c/8|0]=d,qe=a),c=or(l,c+1,s.subarray(M,qe))}n.i=a}return st(o,0,r+os(c)+i)},ji=(function(){for(var s=new Int32Array(256),e=0;e<256;++e){for(var t=e,r=9;--r;)t=(t&1&&-306674912)^t>>>1;s[e]=t}return s})(),Zi=function(){var s=-1;return{p:function(e){for(var t=s,r=0;r<e.length;++r)t=ji[t&255^e[r]]^t>>>8;s=t},d:function(){return~s}}},Ui=function(s,e,t,r,i){if(!i&&(i={l:1},e.dictionary)){var n=e.dictionary.subarray(-32768),a=new D(n.length+s.length);a.set(n),a.set(s,n.length),s=a,i.w=n.length}return zi(s,e.level==null?6:e.level,e.mem==null?i.l?Math.ceil(Math.max(8,Math.min(13,Math.log(s.length)))*1.5):20:12+e.mem,t,r,i)},dr=function(s,e){var t={};for(var r in s)t[r]=s[r];for(var r in e)t[r]=e[r];return t},fe=function(s,e){return s[e]|s[e+1]<<8},ae=function(s,e){return(s[e]|s[e+1]<<8|s[e+2]<<16|s[e+3]<<24)>>>0},ds=function(s,e){return ae(s,e)+ae(s,e+4)*4294967296},G=function(s,e,t){for(;t;++e)s[e]=t,t>>>=8};function Hi(s,e){return Ui(s,e||{},0,0)}function Di(s,e){return Vi(s,{i:2},e&&e.out,e&&e.dictionary)}var hr=function(s,e,t,r){for(var i in s){var n=s[i],a=e+i,o=r;Array.isArray(n)&&(o=dr(r,n[1]),n=n[0]),ArrayBuffer.isView(n)?t[a]=[n,o]:(t[a+="/"]=[new D(0),o],hr(n,a,t,r))}},ur=typeof TextEncoder<"u"&&new TextEncoder,hs=typeof TextDecoder<"u"&&new TextDecoder,Wi=0;try{hs.decode(cr,{stream:!0}),Wi=1}catch{}var qi=function(s){for(var e="",t=0;;){var r=s[t++],i=(r>127)+(r>223)+(r>239);if(t+i>s.length)return{s:e,r:st(s,t-1)};i?i==3?(r=((r&15)<<18|(s[t++]&63)<<12|(s[t++]&63)<<6|s[t++]&63)-65536,e+=String.fromCharCode(55296|r>>10,56320|r&1023)):i&1?e+=String.fromCharCode((r&31)<<6|s[t++]&63):e+=String.fromCharCode((r&15)<<12|(s[t++]&63)<<6|s[t++]&63):e+=String.fromCharCode(r)}};function us(s,e){var t;if(ur)return ur.encode(s);for(var r=s.length,i=new D(s.length+(s.length>>1)),n=0,a=function(d){i[n++]=d},t=0;t<r;++t){if(n+5>i.length){var o=new D(n+8+(r-t<<1));o.set(i),i=o}var l=s.charCodeAt(t);l<128||e?a(l):l<2048?(a(192|l>>6),a(128|l&63)):l>55295&&l<57344?(l=65536+(l&1047552)|s.charCodeAt(++t)&1023,a(240|l>>18),a(128|l>>12&63),a(128|l>>6&63),a(128|l&63)):(a(224|l>>12),a(128|l>>6&63),a(128|l&63))}return st(i,0,n)}function fr(s,e){if(e){for(var t="",r=0;r<s.length;r+=16384)t+=String.fromCharCode.apply(null,s.subarray(r,r+16384));return t}else{if(hs)return hs.decode(s);var i=qi(s),n=i.s,t=i.r;return t.length&&Q(8),n}}var Yi=function(s,e){return e+30+fe(s,e+26)+fe(s,e+28)},Ji=function(s,e,t){var r=fe(s,e+28),i=fe(s,e+30),n=fr(s.subarray(e+46,e+46+r),!(fe(s,e+8)&2048)),a=e+46+r,o=Gi(s,a,i,t,ae(s,e+20),ae(s,e+24),ae(s,e+42)),l=o[0],d=o[1],c=o[2];return[fe(s,e+10),l,d,n,a+i+fe(s,e+32),c]},Gi=function(s,e,t,r,i,n,a){var o=i==4294967295,l=n==4294967295,d=a==4294967295,c=e+t,h=o+l+d;if(r&&h){for(;e+4<c;e+=4+fe(s,e+2))if(fe(s,e)==1)return[o?ds(s,e+4+8*l):i,l?ds(s,e+4):n,d?ds(s,e+4+8*(l+o)):a,1];r<2&&Q(13)}return[i,n,a,0]},fs=function(s){var e=0;if(s)for(var t in s){var r=s[t].length;r>65535&&Q(9),e+=r+4}return e},pr=function(s,e,t,r,i,n,a,o){var l=r.length,d=t.extra,c=o&&o.length,h=fs(d);G(s,e,a!=null?33639248:67324752),e+=4,a!=null&&(s[e++]=20,s[e++]=t.os),s[e]=20,e+=2,s[e++]=t.flag<<1|(n<0&&8),s[e++]=i&&8,s[e++]=t.compression&255,s[e++]=t.compression>>8;var u=new Date(t.mtime==null?Date.now():t.mtime),g=u.getFullYear()-1980;if((g<0||g>119)&&Q(10),G(s,e,g<<25|u.getMonth()+1<<21|u.getDate()<<16|u.getHours()<<11|u.getMinutes()<<5|u.getSeconds()>>1),e+=4,n!=-1&&(G(s,e,t.crc),G(s,e+4,n<0?-n-2:n),G(s,e+8,t.size)),G(s,e+12,l),G(s,e+14,h),e+=16,a!=null&&(G(s,e,c),G(s,e+6,t.attrs),G(s,e+10,a),e+=14),s.set(r,e),e+=l,h)for(var x in d){var v=d[x],f=v.length;G(s,e,+x),G(s,e+2,f),s.set(v,e+4),e+=4+f}return c&&(s.set(o,e),e+=c),e},Xi=function(s,e,t,r,i){G(s,e,101010256),G(s,e+8,t),G(s,e+10,t),G(s,e+12,r),G(s,e+16,i)};function Ki(s,e){e||(e={});var t={},r=[];hr(s,"",t,e);var i=0,n=0;for(var a in t){var o=t[a],l=o[0],d=o[1],c=d.level==0?0:8,h=us(a),u=h.length,g=d.comment,x=g&&us(g),v=x&&x.length,f=fs(d.extra);u>65535&&Q(11);var b=c?Hi(l,d):l,_=b.length,m=Zi();m.p(l),r.push(dr(d,{size:l.length,crc:m.d(),c:b,f:h,m:x,u:u!=a.length||x&&g.length!=v,o:i,compression:c})),i+=30+u+f+_,n+=76+2*(u+f)+(v||0)+_}for(var E=new D(n+22),R=i,L=n-i,O=0;O<r.length;++O){var h=r[O];pr(E,h.o,h,h.f,h.u,h.c.length);var I=30+h.f.length+fs(h.extra);E.set(h.c,h.o+I),pr(E,i,h,h.f,h.u,h.c.length,h.o,h.m),i+=16+I+(h.m?h.m.length:0)}return Xi(E,i,r.length,L,R),E}function Qi(s,e){for(var t={},r=s.length-22;ae(s,r)!=101010256;--r)(!r||s.length-r>65558)&&Q(13);var i=fe(s,r+8);if(!i)return{};var n=ae(s,r+16),a=ae(s,r-20)==117853008;if(a){var o=ae(s,r-12);a=ae(s,o)==101075792,a&&(i=ae(s,o+32),n=ae(s,o+48))}for(var l=0;l<i;++l){var d=Ji(s,n,a),c=d[0],h=d[1],u=d[2],g=d[3],x=d[4],v=d[5],f=Yi(s,v);n=x,c?c==8?t[g]=Di(s.subarray(f,f+h),{out:new D(u)}):Q(14,"unknown compression type "+c):t[g]=st(s,f,f+h)}return t}const gr=[80,75];function ps(s){return s.length>=2&&s[0]===gr[0]&&s[1]===gr[1]}function gs(s){const e=s instanceof Uint8Array?s:new Uint8Array(s);if(!ps(e))throw new Error("Not a ZIP archive");const t=Qi(e),r=new Map;for(const[i,n]of Object.entries(t))!n||i.endsWith("/")||r.set(pe(i),n);return r}function pe(s){return s.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"")}function nt(s,e){const t=At(s,e);if(!t)throw new Error(`Missing zip entry: ${e}`);return fr(t)}function At(s,e){const t=pe(e);if(s.has(t))return s.get(t);const r=t.toLowerCase();for(const[i,n]of s)if(i.toLowerCase()===r)return n}function en(s){return[...s.keys()]}function tn(s){var t;switch(((t=s.split(".").pop())==null?void 0:t.toLowerCase())??""){case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"webp":return"image/webp";case"svg":return"image/svg+xml";case"mp3":return"audio/mpeg";case"wav":return"audio/wav";case"ogg":return"audio/ogg";case"m4a":return"audio/mp4";case"webm":return"audio/webm";case"vtt":return"text/vtt";case"html":case"xhtml":case"htm":return"application/xhtml+xml";case"css":return"text/css";case"json":return"application/json";case"woff":return"font/woff";case"woff2":return"font/woff2";case"ttf":return"font/ttf";case"otf":return"font/otf";default:return"application/octet-stream"}}function mr(s,e){const t=new Uint8Array(s.byteLength);t.set(s);const r=new Blob([t.buffer],{type:tn(e)});return URL.createObjectURL(r)}async function sn(s){const e=await fetch(s);if(!e.ok)throw new Error(`Failed to fetch ${s}: ${e.status}`);return e.arrayBuffer()}function rn(s){return ms(gs(s))}function ms(s){const e=nt(s,"META-INF/container.xml"),t=ge(e,/full-path\s*=\s*"([^"]+)"/i);if(!t)throw new Error("Invalid EPUB: missing rootfile in container.xml");const r=pe(t),i=r.includes("/")?r.replace(/\/[^/]+$/,"/"):"",n=nt(s,r),a=br(n,"dc:title")||br(n,"title")||"EPUB Story",o=ln(n)??{width:768,height:1024},l=an(n,i),d=on(n),c=[],h=new Map,u=f=>{const b=pe(f);if(h.has(b))return h.get(b);const _=At(s,b);if(!_)throw new Error(`EPUB missing file: ${b}`);const m=mr(_,b);return c.push(m),h.set(b,m),m},g={},x=[];if(d.forEach((f,b)=>{const _=l.get(f);if(!_||!/html|xml/i.test(_.mediaType)&&!_.href.match(/\.x?html?$/i))return;const m=_.href,E=nt(s,m),R=m.includes("/")?m.replace(/\/[^/]+$/,"/"):"",L=`page-${b+1}`,O=dn(E),{html:I,imageHrefs:M}=hn(O,R,V=>{const j=pe(V.includes(":")?V:`${R}${V}`);try{return u(j)}catch{return V}}),W=[{id:`${L}-text`,type:"text",layout:{x:"5%",y:"5%",width:"90%",height:"90%"},html:I}],Z=M[0];let J;if(Z){const V=`img-${b}-0`;g[V]={type:"image",src:u(Z)},J={asset:V,color:"#ffffff"}}else J={color:"#ffffff"};let oe;if(_.mediaOverlay){const V=l.get(_.mediaOverlay);if(V){const j=cn(nt(s,V.href),V.href);if(j.audioHref){const q=`vo-${b}`,z=pe(j.audioHref.includes("/")||j.audioHref.startsWith(".")?vr(V.href,j.audioHref):`${i}${j.audioHref}`);g[q]={type:"audio",src:u(z),channel:"vo"};const X=j.cues;X.length?oe={audio:q,cues:X}:oe={audio:q}}}}x.push({id:L,background:J,readAloud:oe,blocks:W})}),x.length===0)throw new Error("Invalid EPUB: no spine HTML documents found");return{story:Be({id:`epub-${un(a)}`,title:a,pageSize:o,fonts:[],assets:g,pages:x}),blobUrls:c}}function nn(s){return!!At(s,"META-INF/container.xml")}function an(s,e){const t=new Map,r=/<item\b[^>]*>/gi;let i;for(;i=r.exec(s);){const n=i[0],a=ge(n,/\bid\s*=\s*"([^"]+)"/i),o=ge(n,/\bhref\s*=\s*"([^"]+)"/i),l=ge(n,/\bmedia-type\s*=\s*"([^"]+)"/i)??"",d=ge(n,/\bmedia-overlay\s*=\s*"([^"]+)"/i)??void 0,c=ge(n,/\bproperties\s*=\s*"([^"]+)"/i)??void 0;!a||!o||t.set(a,{id:a,href:pe(`${e}${o}`),mediaType:l,mediaOverlay:d,properties:c})}return t}function on(s){const e=s.match(/<spine\b[^>]*>([\s\S]*?)<\/spine>/i);if(!e)return[];const t=[],r=/<itemref\b[^>]*\bidref\s*=\s*"([^"]+)"[^>]*>/gi;let i;for(;i=r.exec(e[1]);)t.push(i[1]);return t}function ln(s){const e=s.match(/<meta\b[^>]*name\s*=\s*"viewport"[^>]*content\s*=\s*"([^"]+)"[^>]*>/i)||s.match(/<meta\b[^>]*content\s*=\s*"([^"]+)"[^>]*name\s*=\s*"viewport"[^>]*>/i);if(!e)return null;const t=e[1],r=t.match(/width\s*=\s*(\d+)/i),i=t.match(/height\s*=\s*(\d+)/i);return!r||!i?null:{width:Number(r[1]),height:Number(i[1])}}function cn(s,e){const t=[];let r;const i=ge(s,/<audio\b[^>]*\bsrc\s*=\s*"([^"]+)"/i);i&&(r=vr(e,i));const n=/<par\b[^>]*>([\s\S]*?)<\/par>/gi;let a,o=0;for(;a=n.exec(s);){const l=a[1],d=ge(l,/<text\b[^>]*\bsrc\s*=\s*"([^"]+)"/i),c=ge(l,/\bclipBegin\s*=\s*"([^"]+)"/i),h=ge(l,/\bclipEnd\s*=\s*"([^"]+)"/i),u=d!=null&&d.includes("#")?d.split("#")[1]:`cue-${o}`;c==null||h==null||(t.push({id:u||`cue-${o}`,start:yr(c),end:yr(h)}),o+=1)}return{audioHref:r,cues:t}}function yr(s){const e=s.replace(/^npt=/i,"").trim();if(/^\d+(\.\d+)?$/.test(e))return Number(e);const t=e.split(":").map(Number);return t.length===3?t[0]*3600+t[1]*60+t[2]:t.length===2?t[0]*60+t[1]:0}function dn(s){const e=s.match(/<body\b[^>]*>([\s\S]*?)<\/body>/i);return e?e[1].trim():s}function hn(s,e,t){const r=[];return{html:s.replace(/\b(src|href)\s*=\s*["']([^"']+)["']/gi,(n,a,o)=>{if(/^(?:[a-z]+:|#|data:)/i.test(o))return n;const l=pe(`${e}${o}`);/\.(png|jpe?g|gif|webp|svg)$/i.test(o)&&r.push(l);const d=t(o);return`${a}="${d}"`}),imageHrefs:r}}function vr(s,e){if(/^(?:[a-z]+:)/i.test(e))return e;const r=((s.includes("/")?s.replace(/\/[^/]+$/,"/"):"")+e).split("/"),i=[];for(const n of r)!n||n==="."||(n===".."?i.pop():i.push(n));return i.join("/")}function ge(s,e){const t=s.match(e);return t?t[1]:null}function br(s,e){const t=new RegExp(`<${e.replace(":",":")}[^>]*>([^<]*)</${e.replace(":",":")}>`,"i"),r=s.match(t);return r?r[1].trim():null}function un(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,48)||"book"}function ys(s){const e=en(s),t=e.find(i=>i==="story.json"||i.toLowerCase()==="story.json");if(t)return t;const r=e.filter(i=>i.toLowerCase().endsWith("/story.json")||i.toLowerCase()==="story.json").sort((i,n)=>i.length-n.length);if(r[0])return r[0];throw new Error("Invalid .fanci package: missing story.json")}function vs(s){const e=ys(s),t=e.includes("/")?e.replace(/\/[^/]+$/,"/"):"",r=Be(JSON.parse(nt(s,e))),i=new Map,n=[];for(const[a,o]of s){if(a===e)continue;const l=mr(o,a);n.push(l),i.set(a,l),t&&a.startsWith(t)&&i.set(a.slice(t.length),l)}return gn(r,a=>pn(i,t,a)),{story:r,pathUrls:i,blobUrls:n,storyDir:t}}function fn(s){return vs(gs(s))}function pn(s,e,t){const r=pe(t);if(s.has(r))return s.get(r);const i=pe(`${e}${r}`);if(s.has(i))return s.get(i);const n=r.toLowerCase();for(const[a,o]of s)if(a.toLowerCase()===n||a.toLowerCase().endsWith(`/${n}`))return o}function gn(s,e){for(const t of s.fonts){const r=e(t.src);r&&(t.src=r)}for(const t of Object.values(s.assets)){const r=e(t.src);r&&(t.src=r)}for(const t of s.pages)for(const r of t.blocks)if(r.type==="text"&&r.htmlSrc){const i=e(r.htmlSrc);i&&(r.htmlSrc=i)}}function mn(s){if(At(s,"META-INF/container.xml"))return!1;try{return ys(s),!0}catch{return!1}}const Tt=".fanci";function bs(s){const e=s.split("?")[0].split("#")[0],t=e.split("/").pop()??e,r=t.lastIndexOf(".");return r>=0?t.slice(r).toLowerCase():""}function yn(s,e){if(typeof s=="object"&&s!==null&&!(s instanceof Blob)&&!(s instanceof ArrayBuffer)&&!(s instanceof Uint8Array)&&!ArrayBuffer.isView(s)&&("story"in s||"id"in s&&"pages"in s))return"object";const t=e??(typeof s=="string"?s:s instanceof File?s.name:""),r=bs(t);return r===Tt||r===".fanci.zip"?"fanci":r===".epub"?"epub":"json"}async function vn(s){return s instanceof ArrayBuffer?s:s instanceof Uint8Array?s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength):s.arrayBuffer()}async function Et(s,e){const t=typeof e=="string"?{baseUrl:e}:e??{},r=t.onProgress??(()=>{});if(kn(s)){r({stage:"parse",progress:.1,detail:"story object"});const i=Be(s),n=t.baseUrl??(typeof location<"u"?location.href:"");r({stage:"assets",progress:.2,detail:"fonts"}),await et(i,n);const a=await at(i,n,r,.25,1);return r({stage:"complete",progress:1}),{story:i,baseUrl:n,assets:a,blobUrls:[],kind:"object"}}if(typeof s=="object"&&s!==null&&"story"in s&&!kr(s)){const i=s;return Et(i.story,{baseUrl:t.baseUrl??i.baseUrl,name:t.name,onProgress:t.onProgress})}if(typeof s=="string")return bn(s,t,r);if(kr(s)){r({stage:"fetch",progress:.05,detail:"bytes"});const i=await vn(s),n=t.name??(s instanceof File?s.name:void 0)??"";return ks(i,n,t.baseUrl,r)}throw new Error("Unsupported story source")}async function bn(s,e,t){const r=bs(s),i=yn(s,e.name??s);if(t({stage:"fetch",progress:.02,detail:s}),r===Tt||r===".epub"||i==="fanci"||i==="epub"){const u=await sn(s);return t({stage:"fetch",progress:.15,detail:"package downloaded"}),ks(u,e.name??s,e.baseUrl,t)}const n=await fetch(s);if(!n.ok)throw new Error(`Failed to load story: ${n.status} ${n.statusText}`);const a=await n.arrayBuffer(),o=new Uint8Array(a);if(ps(o))return t({stage:"fetch",progress:.15,detail:"zip downloaded"}),ks(a,e.name??s,e.baseUrl,t);t({stage:"parse",progress:.2,detail:"json"});const l=new TextDecoder().decode(o),d=Be(JSON.parse(l)),c=e.baseUrl??Pi(new URL(s,location.href).href);await et(d,c);const h=await at(d,c,t,.3,1);return t({stage:"complete",progress:1}),{story:d,baseUrl:c,assets:h,blobUrls:[],kind:"json"}}async function ks(s,e,t,r){const i=new Uint8Array(s),n=bs(e);if(ps(i)){r({stage:"unpack",progress:.2,detail:"unzip"});const d=gs(i);if(r({stage:"unpack",progress:.35,detail:`${d.size} entries`}),n===".epub"||nn(d)){r({stage:"parse",progress:.4,detail:"epub"});const{story:c,blobUrls:h}=ms(d);await et(c,t??"");const u=await at(c,t??"",r,.5,1);return r({stage:"complete",progress:1}),{story:c,baseUrl:t??"",assets:u,blobUrls:h,kind:"epub"}}if(n===Tt||mn(d)){r({stage:"parse",progress:.4,detail:"fanci"});const{story:c,blobUrls:h}=vs(d);await et(c,t??"");const u=await at(c,t??"",r,.5,1);return r({stage:"complete",progress:1}),{story:c,baseUrl:t??"",assets:u,blobUrls:h,kind:"fanci"}}throw new Error("ZIP archive is neither a .fanci package (story.json) nor an EPUB (META-INF/container.xml)")}r({stage:"parse",progress:.25,detail:"json bytes"});const a=Be(JSON.parse(new TextDecoder().decode(i))),o=t??(typeof location<"u"?location.href:"");await et(a,o);const l=await at(a,o,r,.35,1);return r({stage:"complete",progress:1}),{story:a,baseUrl:o,assets:l,blobUrls:[],kind:"json"}}function kn(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)&&!(s instanceof Blob)&&!(s instanceof ArrayBuffer)&&!(s instanceof Uint8Array)&&"id"in s&&"pages"in s&&"pageSize"in s}function kr(s){return s instanceof ArrayBuffer||s instanceof Uint8Array||s instanceof Blob||typeof File<"u"&&s instanceof File}async function at(s,e,t,r,i){var x;const n=new Map,a=new Map,o=new Map,l=new Map,d=Object.entries(s.assets),c=[];for(const v of s.pages)for(const f of v.blocks)if(f.type==="text"&&f.htmlSrc&&!f.html&&c.push(async()=>{const b=ze(e,f.htmlSrc);l.set(`htmlSrc:${f.id}`,await Lt(b))}),(x=v.readAloud)!=null&&x.cues&&typeof v.readAloud.cues=="string"){const b=v.readAloud.cues;s.assets[b]||c.push(async()=>{const _=ze(e,b);try{o.set(b,Qt(await Lt(_)))}catch{}})}const h=d.length+c.length||1;let u=0;const g=v=>{u+=1;const f=u/h,b=r+(i-r)*Math.min(1,f);t({stage:"assets",progress:b,count:u,total:h,detail:v})};return await Promise.all(d.map(async([v,f])=>{const b=ze(e,f.src);f.type==="image"?n.set(v,await wn(b)):f.type==="audio"?a.set(v,{url:b,channel:f.channel??"vo"}):f.type==="vtt"?o.set(v,Qt(await Lt(b))):f.type==="html"&&l.set(v,await Lt(b)),g(v)})),await Promise.all(c.map(async v=>{await v(),g("fragment")})),d.length===0&&c.length===0&&t({stage:"assets",progress:i,count:0,total:0,detail:"none"}),{images:n,audioUrls:a,cues:o,html:l}}function wn(s){return new Promise((e,t)=>{const r=new Image;r.decoding="async",r.onload=()=>e(r),r.onerror=()=>t(new Error(`Failed to load image: ${s}`)),r.src=s})}async function Lt(s){const e=await fetch(s);if(!e.ok)throw new Error(`Failed to load ${s}: ${e.status}`);return e.text()}function ws(s){for(const e of s.blobUrls)try{URL.revokeObjectURL(e)}catch{}s.blobUrls.length=0}const wr="auto",Sr=900;function _r(s,e,t,r){return s==="responsive"?e>=t?"two-page":"single":s==="auto"?e>=r?"two-page":"single":s}function Fe(s,e){return{kind:"page",pageIndex:e,pageId:s[e].id}}const Le={kind:"blank"};function xr(s){return{index:-1,left:Le,right:Fe(s,0)}}function Cr(s){const e=s.length-1;return{index:-2,left:Le,right:Fe(s,e)}}function Ar(s,e={}){if(s.length===0)return[];const t=!!e.frontCover,r=!!e.backCover,i=[];let n=t?1:0;const a=r?Math.max(n,s.length-1):s.length;for(!t&&n<a&&(i.push({index:0,left:Le,right:Fe(s,0)}),n=1);n<a;){if(n+1<a){i.push({index:i.length,left:Fe(s,n),right:Fe(s,n+1)}),n+=2;continue}i.push({index:i.length,left:Fe(s,n),right:Le}),n+=1}return i}function Tr(s,e={}){if(s.length===0)return[];const t=!!e.frontCover,r=!!e.backCover,i=s.length-1;return s.map((n,a)=>{const o=Fe(s,a);return t&&a===0?{index:a,left:o,right:Le}:r&&a===i?{index:a,left:Le,right:o}:a%2===0?{index:a,left:Le,right:o}:{index:a,left:o,right:Le}})}function Mt(s,e="two-page",t={}){return e==="single"?Tr(s,t):Ar(s,t)}function Er(s){const e=[];return s.left.kind==="page"&&e.push(s.left.pageId),s.right.kind==="page"&&e.push(s.right.pageId),e}function Lr(s){return s?s.left.kind==="page"?s.left.pageId:s.right.kind==="page"?s.right.pageId:null:null}function je(s,e){const t=s.findIndex(r=>r.left.kind==="page"&&r.left.pageId===e||r.right.kind==="page"&&r.right.pageId===e);return t<0?0:t}class Sn{constructor(e,t,r={}){y(this,"story");y(this,"spreadView");y(this,"spreads");y(this,"spreadIndex",0);y(this,"preferredMode");y(this,"resolvedMode","two-page");y(this,"breakpoint");y(this,"listeners",new Map);y(this,"busy",!1);y(this,"hasResolvedLayout",!1);y(this,"bookState");y(this,"covers");y(this,"frontCoverSpread",null);y(this,"backCoverSpread",null);this.story=e,this.spreadView=t,this.preferredMode=r.mode??wr,this.breakpoint=r.singleBreakpoint??Sr,this.covers={frontCover:!!e.frontCover,backCover:!!e.backCover},this.bookState=this.covers.frontCover?"closed-front":"open",this.rebuildCoverSpreads(),this.spreads=Mt(e.pages,"two-page",this.covers)}get layoutMode(){return this.resolvedMode}get layoutPreference(){return this.preferredMode}get currentBookState(){return this.bookState}get currentSpread(){return this.bookState==="closed-front"&&this.frontCoverSpread?this.frontCoverSpread:this.bookState==="closed-back"&&this.backCoverSpread?this.backCoverSpread:this.spreads[this.spreadIndex]??this.spreads[0]}get currentPageIds(){var e,t;if(this.bookState==="closed-front"){const r=(e=this.story.pages[0])==null?void 0:e.id;return r?[r]:[]}if(this.bookState==="closed-back"){const r=(t=this.story.pages[this.story.pages.length-1])==null?void 0:t.id;return r?[r]:[]}return Er(this.currentSpread)}get canPrev(){return this.bookState==="closed-front"?!1:this.bookState==="closed-back"||this.spreadIndex>0?!0:!!this.covers.frontCover&&this.resolvedMode==="two-page"}get canNext(){return this.bookState==="closed-back"?!1:this.bookState==="closed-front"?this.spreads.length>0||!!this.covers.backCover:this.spreadIndex<this.spreads.length-1?!0:!!this.covers.backCover&&this.resolvedMode==="two-page"}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{var r;return(r=this.listeners.get(e))==null?void 0:r.delete(t)}}setLayoutMode(e,t,r){this.preferredMode=e,this.updateLayout(t,r,!1)}updateLayout(e,t,r=!0){var l,d,c,h,u;const i=_r(this.preferredMode,e,t,this.breakpoint);if(!(!this.hasResolvedLayout||i!==this.resolvedMode)){this.spreadView.setLayoutMode(i);return}const a=this.currentPageIds[0]??Lr(this.spreads[this.spreadIndex])??((l=this.story.pages[0])==null?void 0:l.id)??null;this.resolvedMode=i,this.hasResolvedLayout=!0,this.rebuildCoverSpreads(),this.spreads=Mt(this.story.pages,i,this.covers);const o=this.covers.frontCover&&a===((d=this.story.pages[0])==null?void 0:d.id)||this.covers.backCover&&a===((c=this.story.pages[this.story.pages.length-1])==null?void 0:c.id);i==="single"?(this.bookState="open",this.spreadIndex=a?je(this.spreads,a):0):this.covers.frontCover&&(this.bookState==="closed-front"||o&&a===((h=this.story.pages[0])==null?void 0:h.id))?(this.bookState="closed-front",this.spreadIndex=0):this.covers.backCover&&(this.bookState==="closed-back"||o&&a===((u=this.story.pages[this.story.pages.length-1])==null?void 0:u.id))?(this.bookState="closed-back",this.spreadIndex=Math.max(0,this.spreads.length-1)):(this.bookState="open",this.spreadIndex=a?je(this.spreads,a):0),this.spreadIndex>=this.spreads.length&&(this.spreadIndex=Math.max(0,this.spreads.length-1)),this.busy=!1,this.spreadView.setLayoutMode(i),this.spreadView.setBookState(this.bookState),this.spreadView.showSpread(this.currentSpread,"none"),r&&(this.emit("layoutchange",{layoutMode:i}),this.emitPageChange())}async showInitial(){this.covers.frontCover&&this.resolvedMode==="two-page"?(this.bookState="closed-front",this.spreadIndex=0):this.bookState="open",await this.spreadView.showSpread(this.currentSpread,"none"),this.spreadView.setBookState(this.bookState),this.emitPageChange()}async next(){if(!(this.busy||!this.canNext)){if(this.busy=!0,this.bookState==="closed-front"){this.spreads.length===0&&this.covers.backCover&&this.backCoverSpread?(this.bookState="closed-back",await this.spreadView.showSpread(this.backCoverSpread,"next"),this.spreadView.setBookState("closed-back")):(this.bookState="open",this.spreadIndex=0,await this.spreadView.showSpread(this.currentSpread,"next"),this.spreadView.setBookState("open")),this.emitPageChange(),this.busy=!1;return}if(this.bookState==="open"&&this.covers.backCover&&this.backCoverSpread&&this.resolvedMode==="two-page"&&this.spreadIndex>=this.spreads.length-1){this.bookState="closed-back",await this.spreadView.showSpread(this.backCoverSpread,"next"),this.spreadView.setBookState("closed-back"),this.emitPageChange(),this.busy=!1;return}this.spreadIndex+=1,await this.spreadView.showSpread(this.currentSpread,"next"),this.emitPageChange(),this.busy=!1}}async prev(){if(!(this.busy||!this.canPrev)){if(this.busy=!0,this.bookState==="closed-back"){this.spreads.length===0&&this.covers.frontCover&&this.frontCoverSpread?(this.bookState="closed-front",await this.spreadView.showSpread(this.frontCoverSpread,"prev"),this.spreadView.setBookState("closed-front")):(this.bookState="open",this.spreadIndex=Math.max(0,this.spreads.length-1),await this.spreadView.showSpread(this.currentSpread,"prev"),this.spreadView.setBookState("open")),this.emitPageChange(),this.busy=!1;return}if(this.bookState==="open"&&this.covers.frontCover&&this.frontCoverSpread&&this.resolvedMode==="two-page"&&this.spreadIndex<=0){this.bookState="closed-front",await this.spreadView.showSpread(this.frontCoverSpread,"prev"),this.spreadView.setBookState("closed-front"),this.emitPageChange(),this.busy=!1;return}this.spreadIndex-=1,await this.spreadView.showSpread(this.currentSpread,"prev"),this.emitPageChange(),this.busy=!1}}replaceStory(e,t){this.story=e,this.bookState=e.frontCover?"closed-front":"open",this.rebuildFromStory(t)}rebuildFromStory(e){var r,i,n;this.covers={frontCover:!!this.story.frontCover,backCover:!!this.story.backCover},this.rebuildCoverSpreads(),this.spreads=Mt(this.story.pages,this.resolvedMode,this.covers);const t=e??this.currentPageIds[0]??((r=this.story.pages[0])==null?void 0:r.id)??null;this.resolvedMode==="single"?(this.bookState="open",this.spreadIndex=t?je(this.spreads,t):0):this.covers.frontCover&&t===((i=this.story.pages[0])==null?void 0:i.id)&&this.bookState==="closed-front"?(this.bookState="closed-front",this.spreadIndex=0):this.covers.backCover&&t===((n=this.story.pages[this.story.pages.length-1])==null?void 0:n.id)&&this.bookState==="closed-back"?(this.bookState="closed-back",this.spreadIndex=Math.max(0,this.spreads.length-1)):(this.bookState="open",this.spreadIndex=t?je(this.spreads,t):0,this.spreadIndex<0&&(this.spreadIndex=0)),this.spreads.length===0?(this.spreadIndex=0,this.covers.frontCover?this.bookState="closed-front":this.covers.backCover&&(this.bookState="closed-back")):this.spreadIndex>=this.spreads.length&&(this.spreadIndex=Math.max(0,this.spreads.length-1)),this.busy=!1,this.spreadView.setLayoutMode(this.resolvedMode),this.spreadView.setBookState(this.bookState),this.spreadView.showSpread(this.currentSpread,"none"),this.emitPageChange()}async goTo(e){var a,o;const t=this.covers.frontCover&&((a=this.story.pages[0])==null?void 0:a.id)===e,r=this.covers.backCover&&((o=this.story.pages[this.story.pages.length-1])==null?void 0:o.id)===e;if(this.busy=!0,t&&this.resolvedMode==="two-page"&&this.frontCoverSpread){this.bookState="closed-front",this.spreadIndex=0,await this.spreadView.showSpread(this.frontCoverSpread,"none"),this.spreadView.setBookState("closed-front"),this.emitPageChange(),this.busy=!1;return}if(r&&this.resolvedMode==="two-page"&&this.backCoverSpread){this.bookState="closed-back",this.spreadIndex=Math.max(0,this.spreads.length-1),await this.spreadView.showSpread(this.backCoverSpread,"none"),this.spreadView.setBookState("closed-back"),this.emitPageChange(),this.busy=!1;return}const i=je(this.spreads,e);if(i===this.spreadIndex&&this.bookState==="open"){this.busy=!1;return}const n=i>this.spreadIndex?"next":"prev";this.bookState="open",this.spreadIndex=i,this.spreadView.setBookState("open"),await this.spreadView.showSpread(this.currentSpread,n),this.emitPageChange(),this.busy=!1}rebuildCoverSpreads(){this.frontCoverSpread=this.covers.frontCover?xr(this.story.pages):null,this.backCoverSpread=this.covers.backCover?Cr(this.story.pages):null}emitPageChange(){this.emit("pagechange",{pageIds:this.currentPageIds,index:this.spreadIndex,layoutMode:this.resolvedMode,bookState:this.bookState})}emit(e,t){const r=this.listeners.get(e);if(r)for(const i of r)i(t)}}function Pt(s){return s.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"")}function It(s,e){var t;try{const i=(t=new URL(s,"http://local/").pathname.split(".").pop())==null?void 0:t.toLowerCase();if(i&&/^[a-z0-9]{1,8}$/.test(i))return i}catch{}return e}async function Nt(s){const e=await fetch(s);if(!e.ok)throw new Error(`Failed to fetch asset ${s}: ${e.status}`);return new Uint8Array(await e.arrayBuffer())}async function Mr(s,e={}){const t={...e.files??{}},r=structuredClone(s),i=e.baseUrl??"";for(const[a,o]of Object.entries(r.assets)){const l=o.src;if(/^(?:[a-z]+:)?\/\//i.test(l)||l.startsWith("blob:")||l.startsWith("data:")){const h=o.type==="image"?It(l,"png"):o.type==="audio"?It(l,"mp3"):o.type==="vtt"?"vtt":It(l,"bin"),u=Pt(`assets/${a}.${h}`);t[u]||(t[u]=await Nt(l)),o.src=u;continue}const c=Pt(l);if(!t[c]){const h=ze(i,l);t[c]=await Nt(h)}o.src=c}for(const a of r.fonts){const o=a.src;if(/^(?:[a-z]+:)?\/\//i.test(o)||o.startsWith("blob:")||o.startsWith("data:")){const d=Pt(`fonts/${a.family.replace(/\s+/g,"-")}.${It(o,"woff2")}`);t[d]||(t[d]=await Nt(o)),a.src=d}else{const d=Pt(o);t[d]||(t[d]=await Nt(ze(i,o))),a.src=d}}t["story.json"]=us(JSON.stringify(r,null,2));const n=Ki(t,{level:6});return new Blob([n],{type:"application/zip"})}function Pr(s,e){const t=URL.createObjectURL(s),r=document.createElement("a");r.href=t,r.download=e,r.rel="noopener",document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(t)}class ot{cancel(e){}}y(ot,"id","base");const lt=new Map;function Ir(s,e){lt.set(s,e)}function _n(s){return lt.get(s)}function Nr(){return[...lt.keys()]}function xn(s){return typeof s=="function"&&s.prototype instanceof ot}function Ss(s){if(s==null||s===""){const e=lt.get("default");if(!e)throw new Error('FlipStyle "default" is not registered');return new e}if(typeof s=="string"){const e=lt.get(s);if(!e){const t=Nr().join(", ")||"(none)";throw new Error(`Unknown flipStyle "${s}". Registered: ${t}`)}return new e}if(s instanceof ot)return s;if(xn(s))return new s;throw new Error("flipStyle must be a string id, FlipStyle instance, or FlipStyle subclass")}const $r=400;function _s(s){return s==null||!Number.isFinite(s)||s<=0?$r:s}class $t extends ot{play(e){const{bookEl:t,direction:r,durationMs:i}=e,n=r==="next"?"fc-turn-next":"fc-turn-prev";return t.style.setProperty("--fc-flip-duration",`${i}ms`),t.classList.remove("fc-turn-next","fc-turn-prev"),t.offsetWidth,t.classList.add(n),new Promise(a=>{const o=()=>{t.removeEventListener("animationend",l),t.classList.remove("fc-turn-next","fc-turn-prev"),a()},l=d=>{d.target!==e.rightLeaf&&d.target!==e.leftLeaf||o()};t.addEventListener("animationend",l),window.setTimeout(o,i+50)})}cancel(e){e.bookEl.classList.remove("fc-turn-next","fc-turn-prev")}}y($t,"id","default"),Ir($t.id,$t);const xs=.035;function Fr(s,e){return e&&e.width>0&&e.height>0?{x:Math.max(0,Math.round((e.width-s.width)/2)),y:Math.max(0,Math.round((e.height-s.height)/2))}:{x:Math.max(1,Math.round(s.width*xs)),y:Math.max(1,Math.round(s.height*xs))}}function Cs(s){return!!(s.hardback&&(s.frontCover||s.backCover))}function Cn(s){const e=s??{},t={left:Ze(e.x??0),top:Ze(e.y??0)};return e.width!=null&&(t.width=Ze(e.width)),e.height!=null&&(t.height=Ze(e.height)),t}function As(s,e){const t=Cn(e);s.style.left=t.left,s.style.top=t.top,t.width&&(s.style.width=t.width),t.height&&(s.style.height=t.height),(e==null?void 0:e.horizontalAlign)==="right"?(s.style.left="auto",s.style.right=Ze(e.x??0)):(e==null?void 0:e.horizontalAlign)==="center"&&(s.style.left="50%",s.style.transform=`${s.style.transform||""} translateX(-50%)`.trim()),(e==null?void 0:e.verticalAlign)==="bottom"?(s.style.top="auto",s.style.bottom=Ze(e.y??0)):(e==null?void 0:e.verticalAlign)==="center"&&(s.style.top="50%",s.style.transform=`${s.style.transform||""} translateY(-50%)`.trim())}function Ze(s){return typeof s=="number"?`${s}px`:/^-?\d+(\.\d+)?$/.test(s)?`${s}px`:s}function An(s,e){const t=document.createElement("button");return t.type="button",t.className="fc-block fc-block-hotspot",t.dataset.blockId=s.id,t.setAttribute("aria-label",s.ariaLabel??s.id),As(t,s.layout),t.addEventListener("click",r=>{r.stopPropagation(),e(s.onTap??[])}),t}function Tn(s,e){var n;const t=document.createElement("div");t.className=`fc-block fc-block-image${s.className?` ${s.className}`:""}`,t.dataset.blockId=s.id,As(t,s.layout);const r=document.createElement("img");r.alt="",r.draggable=!1,e&&(r.src=e.src);const i=((n=s.layout)==null?void 0:n.fit)??"contain";return r.style.objectFit=i,t.appendChild(r),t}function En(s,e){const t=document.createElement("div");return t.className="fc-block fc-block-text",t.dataset.blockId=s.id,As(t,s.layout),t.innerHTML=e,t.querySelectorAll("[id]").forEach(r=>{r.classList.add("fc-cue")}),s.style&&(s.style.fontFamily&&(t.style.fontFamily=s.style.fontFamily),s.style.fontSize&&(t.style.fontSize=s.style.fontSize),s.style.color&&(t.style.color=s.style.color),s.style.textAlign&&(t.style.textAlign=s.style.textAlign),s.style.lineHeight!=null&&(t.style.lineHeight=String(s.style.lineHeight)),s.style.fontWeight&&(t.style.fontWeight=s.style.fontWeight),s.style.fontStyle&&(t.style.fontStyle=s.style.fontStyle)),t}class Ts{constructor(e,t,r){y(this,"element");y(this,"page");y(this,"blank");var i,n;if(this.page=e,this.blank=!e,this.element=document.createElement("article"),this.element.className=`fc-page${this.blank?" fc-page-blank":""}`,this.element.setAttribute("role",this.blank?"presentation":"document"),!e){this.element.dataset.blank="true";return}if(this.element.dataset.pageId=e.id,(i=e.background)!=null&&i.color&&(this.element.style.backgroundColor=e.background.color),(n=e.background)!=null&&n.asset){const a=t.images.get(e.background.asset);a&&(this.element.style.backgroundImage=`url(${JSON.stringify(a.src)})`,this.element.style.backgroundSize="cover",this.element.style.backgroundPosition="center")}for(const a of e.blocks)if(a.type==="text"){const o=a.html??t.html.get(`htmlSrc:${a.id}`)??(a.htmlSrc?t.html.get(a.htmlSrc):void 0)??"";this.element.appendChild(En(a,o))}else a.type==="image"?this.element.appendChild(Tn(a,t.images.get(a.asset))):a.type==="hotspot"&&this.element.appendChild(An(a,o=>r.onTapActions(o,this.element)))}destroy(){this.element.remove()}}class Ln{constructor(e,t,r,i={}){y(this,"element");y(this,"bookEl");y(this,"hardbackEl");y(this,"hardbackLeft");y(this,"hardbackRight");y(this,"hardbackLeftPage",null);y(this,"hardbackRightPage",null);y(this,"leftSlot");y(this,"rightSlot");y(this,"leftPage",null);y(this,"rightPage",null);y(this,"story");y(this,"assets");y(this,"onTapActions");y(this,"turning",!1);y(this,"bookState","open");y(this,"layoutMode","two-page");y(this,"lastSize",{width:0,height:0});y(this,"stageZoom",{mode:"fit-spread"});y(this,"currentSpread",null);y(this,"flipStyle");y(this,"flipSpeedMs");this.story=e,this.assets=t,this.onTapActions=r,this.flipStyle=Ss(i.flipStyle),this.flipSpeedMs=_s(i.flipSpeed),this.element=document.createElement("div"),this.element.className="fc-spread-viewport",this.hardbackEl=document.createElement("div"),this.hardbackEl.className="fc-hardback",this.hardbackEl.setAttribute("aria-hidden","true"),this.hardbackLeft=document.createElement("div"),this.hardbackLeft.className="fc-hardback-board fc-hardback-board-left",this.hardbackRight=document.createElement("div"),this.hardbackRight.className="fc-hardback-board fc-hardback-board-right",this.hardbackEl.append(this.hardbackLeft,this.hardbackRight),this.bookEl=document.createElement("div"),this.bookEl.className="fc-spread",this.leftSlot=document.createElement("div"),this.leftSlot.className="fc-leaf fc-leaf-left",this.rightSlot=document.createElement("div"),this.rightSlot.className="fc-leaf fc-leaf-right",this.bookEl.append(this.leftSlot,this.rightSlot),this.element.append(this.hardbackEl,this.bookEl)}get currentBookState(){return this.bookState}setFlipStyle(e){this.flipStyle=Ss(e)}setFlipSpeed(e){this.flipSpeedMs=_s(e)}setStageZoom(e){this.stageZoom=e,this.lastSize.width>0&&this.lastSize.height>0&&this.applyStageTransform(this.lastSize.width,this.lastSize.height,this.currentSpread??void 0)}setLayoutMode(e){this.layoutMode=e,this.element.dataset.layoutMode=e,this.element.classList.toggle("fc-spread-viewport-single",e==="single"),this.element.classList.toggle("fc-spread-viewport-two",e==="two-page")}setBookState(e){this.bookState=e,this.element.dataset.bookState=e,this.syncHardbackBoards(),this.applyStageTransform(this.lastSize.width,this.lastSize.height,this.currentSpread??void 0)}showSpread(e,t="none"){var r,i;return t==="none"||this.turning?((i=(r=this.flipStyle).cancel)==null||i.call(r,{bookEl:this.bookEl,viewportEl:this.element,leftLeaf:this.leftSlot,rightLeaf:this.rightSlot}),this.turning=!1,this.mountSpread(e),Promise.resolve()):(this.turning=!0,this.flipStyle.play({bookEl:this.bookEl,viewportEl:this.element,leftLeaf:this.leftSlot,rightLeaf:this.rightSlot,direction:t,durationMs:this.flipSpeedMs}).then(()=>{this.mountSpread(e),this.turning=!1}).catch(()=>{this.mountSpread(e),this.turning=!1}))}getPageElement(e){var t,r,i,n;return((r=(t=this.leftPage)==null?void 0:t.page)==null?void 0:r.id)===e?this.leftPage.element:((n=(i=this.rightPage)==null?void 0:i.page)==null?void 0:n.id)===e?this.rightPage.element:null}getLeafSlots(){return{left:this.leftSlot,right:this.rightSlot}}getEditableLeaves(e,t){const r=[],i=(n,a,o)=>{a.kind==="page"&&r.push({side:n,pageIndex:a.pageIndex,slot:o})};return this.bookState==="closed-front"||this.bookState==="closed-back"?(i("right",t.right,this.rightSlot),r):e==="two-page"?(i("left",t.left,this.leftSlot),i("right",t.right,this.rightSlot),r):(t.left.kind==="blank"&&t.right.kind==="page"?i("right",t.right,this.rightSlot):t.right.kind==="blank"&&t.left.kind==="page"?i("left",t.left,this.leftSlot):t.left.kind==="page"?i("left",t.left,this.leftSlot):t.right.kind==="page"&&i("right",t.right,this.rightSlot),r)}setPageViewsHidden(e){this.leftPage&&(this.leftPage.element.hidden=e),this.rightPage&&(this.rightPage.element.hidden=e)}remountCurrent(){this.currentSpread&&this.mountSpread(this.currentSpread)}setStory(e){this.story=e,this.syncHardbackBoards(),this.applyStageTransform(this.lastSize.width,this.lastSize.height,this.currentSpread??void 0)}setLoaded(e,t){this.story=e,this.assets=t,this.syncHardbackBoards(),this.applyStageTransform(this.lastSize.width,this.lastSize.height,this.currentSpread??void 0)}getVisiblePageElements(e,t){if(this.bookState==="closed-front"||this.bookState==="closed-back")return this.rightPage&&t.right.kind==="page"?[this.rightPage.element]:[];const r=[];return e==="two-page"?(t.left.kind==="page"&&this.leftPage&&r.push(this.leftPage.element),t.right.kind==="page"&&this.rightPage&&r.push(this.rightPage.element)):t.left.kind==="blank"&&t.right.kind==="page"&&this.rightPage?r.push(this.rightPage.element):t.right.kind==="blank"&&t.left.kind==="page"&&this.leftPage?r.push(this.leftPage.element):t.left.kind==="page"&&this.leftPage?r.push(this.leftPage.element):t.right.kind==="page"&&this.rightPage&&r.push(this.rightPage.element),r}updateStageSize(e,t,r,i){this.layoutMode=r,this.lastSize={width:e,height:t},this.applyStageTransform(e,t,i)}destroy(){var e,t,r,i;(t=(e=this.flipStyle).cancel)==null||t.call(e,{bookEl:this.bookEl,viewportEl:this.element,leftLeaf:this.leftSlot,rightLeaf:this.rightSlot}),this.clearHardbackBoards(),(r=this.leftPage)==null||r.destroy(),(i=this.rightPage)==null||i.destroy(),this.element.remove()}applyStageTransform(e,t,r){if(e<=0||t<=0)return;const{width:i,height:n}=this.story.pageSize,a=this.layoutMode,o=this.bookState,l=Cs(this.story),d=l?Fr(this.story.pageSize,this.story.coverSize):{x:0,y:0},c=a==="two-page"&&(o==="closed-front"||o==="closed-back"),h=l&&o==="open",u=this.isSoloCover();this.element.classList.toggle("fc-hardback-active",l),this.element.classList.toggle("fc-hardback-open",h),this.element.classList.toggle("fc-hardback-closed",l&&c);let g,x,v,f=0,b=0,_=0;if(l&&c)x=i+2*d.x,v=n+2*d.y,g=this.sizedScale(Math.min(e/x,t/v),i,n,e,t),this.bookEl.style.setProperty("--fc-page-width",`${x}px`),this.bookEl.style.setProperty("--fc-page-height",`${v}px`),this.bookEl.style.width=`${u?x:x*2}px`,this.bookEl.style.height=`${v}px`,f=u?0:-x*g,b=0,_=0,this.hardbackEl.hidden=!0;else if(h){x=(a==="single"?i:i*2)+2*d.x,v=n+2*d.y,g=this.sizedScale(Math.min(e/x,t/v),i,n,e,t),this.bookEl.style.setProperty("--fc-page-width",`${i}px`),this.bookEl.style.setProperty("--fc-page-height",`${n}px`),this.bookEl.style.width=`${i*2}px`,this.bookEl.style.height=`${n}px`,this.hardbackEl.hidden=!1,this.hardbackEl.style.width=`${x}px`,this.hardbackEl.style.height=`${v}px`;const W=a==="single"?(r==null?void 0:r.left.kind)==="blank"?"right":"left":"both";this.sizeHardbackBoards(W,i,n,d.x,d.y),b=d.x,_=d.y,a==="single"&&(r==null?void 0:r.left.kind)==="blank"?f=-i*g:f=0}else x=i*2,v=n,a==="single"||c?g=this.sizedScale(Math.min(e/i,t/n),i,n,e,t):g=this.sizedScale(Math.min(e/x,t/v),i,n,e,t),this.bookEl.style.setProperty("--fc-page-width",`${i}px`),this.bookEl.style.setProperty("--fc-page-height",`${n}px`),this.bookEl.style.width=`${u?i:x}px`,this.bookEl.style.height=`${v}px`,this.hardbackEl.hidden=!0,u?f=0:(c||a==="single"&&r&&r.left.kind==="blank")&&(f=-i*g);this.element.style.setProperty("--fc-hardback-overhang-x",`${d.x}px`),this.element.style.setProperty("--fc-hardback-overhang-y",`${d.y}px`),this.hardbackEl.style.transform=`scale(${g})`,this.hardbackEl.style.transformOrigin="left top",this.bookEl.style.transform=`translateX(${f}px) scale(${g})`,this.bookEl.style.transformOrigin="left top";let m=l&&c?(i+2*d.x)*g:h?(a==="single"?i+2*d.x:i*2+2*d.x)*g:a==="single"||c?i*g:i*2*g,E=l&&(c||h)?(n+2*d.y)*g:n*g,R=0,L=0;this.stageZoom.mode==="fit-page"&&(E>t&&(L=(E-t)/2,E=t),(a==="single"||c||u?i:i*2)*g<=e&&m>e&&(R=(m-e)/2,m=e));const O=(h?b*g:0)-R,I=(h?_*g:0)-L;this.hardbackEl.style.left=`${-R}px`,this.hardbackEl.style.top=`${-L}px`,this.bookEl.style.left=`${O}px`,this.bookEl.style.top=`${I}px`,this.element.style.width=`${m}px`,this.element.style.height=`${E}px`,this.leftSlot.classList.toggle("fc-leaf-dimmed",c&&!u),this.rightSlot.classList.remove("fc-leaf-dimmed"),this.applySoloCover(u)}sizedScale(e,t,r,i,n){return this.stageZoom.mode==="percent"?Math.max(.1,this.stageZoom.percent/100):this.stageZoom.mode==="fit-page"?Math.min(i/t,n/r):e}isSoloCover(){var l,d;if(this.bookState==="closed-front"||this.bookState==="closed-back")return!0;const e=this.currentSpread;if(!e)return!1;const t=e.left.kind==="page",r=e.right.kind==="page";if(t===r)return!1;const i=t&&e.left.kind==="page"?e.left.pageId:e.right.kind==="page"?e.right.pageId:null;if(!i)return!1;const n=this.story.pages,a=!!this.story.frontCover&&((l=n[0])==null?void 0:l.id)===i,o=!!this.story.backCover&&((d=n[n.length-1])==null?void 0:d.id)===i;return a||o}applySoloCover(e){if(this.bookEl.classList.toggle("is-solo-cover",e),!e||!this.currentSpread){this.leftSlot.classList.remove("is-cover-hidden"),this.rightSlot.classList.remove("is-cover-hidden");return}const t=this.currentSpread.left.kind==="page";this.leftSlot.classList.toggle("is-cover-hidden",!t),this.rightSlot.classList.toggle("is-cover-hidden",t)}sizeHardbackBoards(e,t,r,i,n){const a=r+2*n;if(e!=="both"){const o=e==="left";this.hardbackLeft.style.display=o?"":"none",this.hardbackRight.style.display=o?"none":"";const l=o?this.hardbackLeft:this.hardbackRight;l.style.width=`${t+2*i}px`,l.style.height=`${a}px`;return}this.hardbackLeft.style.display="",this.hardbackRight.style.display="",this.hardbackLeft.style.width=`${t+i}px`,this.hardbackLeft.style.height=`${a}px`,this.hardbackRight.style.width=`${t+i}px`,this.hardbackRight.style.height=`${a}px`}syncHardbackBoards(){if(!Cs(this.story)||this.bookState!=="open"){this.clearHardbackBoards();return}const e=this.story.pages,t=this.story.frontCover?e[0]:null,r=this.story.backCover?e[e.length-1]:null,i=t??r,n=r??t;this.mountHardbackBoard("left",i),this.mountHardbackBoard("right",n)}mountHardbackBoard(e,t){var o;const r=e==="left"?this.hardbackLeft:this.hardbackRight,i=e==="left"?this.hardbackLeftPage:this.hardbackRightPage;if(i==null||i.destroy(),!t){r.replaceChildren(),r.style.background="",e==="left"?this.hardbackLeftPage=null:this.hardbackRightPage=null;return}const n=(o=t.background)==null?void 0:o.innerColor;if(n){r.style.background=n,r.replaceChildren(),e==="left"?this.hardbackLeftPage=null:this.hardbackRightPage=null;return}r.style.background="";const a=new Ts(t,this.assets,{onTapActions:()=>{}});a.element.classList.add("fc-hardback-page"),r.replaceChildren(a.element),e==="left"?this.hardbackLeftPage=a:this.hardbackRightPage=a}clearHardbackBoards(){var e,t;(e=this.hardbackLeftPage)==null||e.destroy(),(t=this.hardbackRightPage)==null||t.destroy(),this.hardbackLeftPage=null,this.hardbackRightPage=null,this.hardbackLeft.replaceChildren(),this.hardbackRight.replaceChildren(),this.hardbackLeft.style.background="",this.hardbackRight.style.background=""}mountSpread(e){var t,r;this.currentSpread=e,(t=this.leftPage)==null||t.destroy(),(r=this.rightPage)==null||r.destroy(),this.leftSlot.replaceChildren(),this.rightSlot.replaceChildren(),this.leftPage=this.createLeaf(e.left),this.rightPage=this.createLeaf(e.right),this.leftSlot.appendChild(this.leftPage.element),this.rightSlot.appendChild(this.rightPage.element),this.syncHardbackBoards(),this.applyStageTransform(this.lastSize.width,this.lastSize.height,e)}createLeaf(e){if(e.kind==="blank")return new Ts(null,this.assets,{onTapActions:this.onTapActions});const t=this.story.pages[e.pageIndex];return new Ts(t,this.assets,{onTapActions:this.onTapActions})}}function Rr(s,e){const t=s==null?void 0:s.container;if(!(t!=null&&t.send))return;const r=In(e.progress);t.send("progress",r),t.send("loading",{stage:e.stage,progress:r,count:e.count,total:e.total,detail:e.detail})}function Mn(s){var e,t;(t=(e=s==null?void 0:s.container)==null?void 0:e.send)==null||t.call(e,"loaded")}function Pn(){let s;return{promise:new Promise(t=>{s=t}),resolve:s}}function In(s){return Number.isNaN(s)?0:Math.min(1,Math.max(0,s))}function Or(s,e,t={}){const r=[];let i=!1;const n=(a,o)=>{if(!(a!=null&&a.subscribe))return;const l=a.subscribe(o);typeof l=="function"?r.push(l):l&&typeof l.unsubscribe=="function"&&r.push(()=>{var d;return(d=l.unsubscribe)==null?void 0:d.call(l)})};return s!=null&&s.state&&(n(s.state.pause,a=>{var l;const o=!!a;e.setPaused(o),(l=t.onPause)==null||l.call(t,o)}),n(s.state.soundVolume,a=>e.setVolume("sound",Number(a))),n(s.state.voVolume,a=>e.setVolume("vo",Number(a))),n(s.state.sfxVolume,a=>e.setVolume("sfx",Number(a))),n(s.state.musicVolume,a=>e.setVolume("music",Number(a))),n(s.state.captionsMuted,a=>{var o;i=!!a,(o=t.onCaptionsMuted)==null||o.call(t,i)})),{get captionsMuted(){return i},destroy(){for(const a of r)a()}}}async function Vr(s){var e,t;try{const r=await import("springroll"),i=r.Application??((e=r.default)==null?void 0:e.Application),n=r.ApplicationPlugin??((t=r.default)==null?void 0:t.ApplicationPlugin);if(!i)return null;const a=Pn(),o=`fancifully-story-load-${Math.random().toString(36).slice(2,9)}`;if(n&&typeof i.uses=="function"){const d=new n({name:o});d.preload=()=>a.promise,i.uses(d)}else a.resolve();return{app:new i({features:s}),loadGate:a,owned:!0}}catch{return null}}function Br(s){var e;return!((e=s==null?void 0:s.state)!=null&&e.ready)||s.state.ready.value===!0?Promise.resolve():new Promise(t=>{const r=s.state.ready.subscribe(i=>{i&&(typeof r=="function"&&r(),t())})})}const Nn=Object.freeze({left:0,top:0,width:16,height:16}),Ft=Object.freeze({rotate:0,vFlip:!1,hFlip:!1}),zr=Object.freeze({...Nn,...Ft}),$n=Object.freeze({...zr,body:"",hidden:!1}),Fn=Object.freeze({width:null,height:null}),Rn=Object.freeze({...Fn,...Ft});function On(s,e){const t={};!s.hFlip!=!e.hFlip&&(t.hFlip=!0),!s.vFlip!=!e.vFlip&&(t.vFlip=!0);const r=((s.rotate||0)+(e.rotate||0))%4;return r&&(t.rotate=r),t}function jr(s,e){const t=On(s,e);for(const r in $n)r in Ft?r in s&&!(r in t)&&(t[r]=Ft[r]):r in e?t[r]=e[r]:r in s&&(t[r]=s[r]);return t}function Vn(s,e){const t=s.icons,r=s.aliases||Object.create(null),i=Object.create(null);function n(a){if(t[a])return i[a]=[];if(!(a in i)){i[a]=null;const o=r[a]&&r[a].parent,l=o&&n(o);l&&(i[a]=[o].concat(l))}return i[a]}return(e||Object.keys(t).concat(Object.keys(r))).forEach(n),i}function Zr(s,e,t){const r=s.icons,i=s.aliases||Object.create(null);let n={};function a(o){n=jr(r[o]||i[o],n)}return a(e),t.forEach(a),jr(s,n)}function Bn(s,e){if(s.icons[e])return Zr(s,e,[]);const t=Vn(s,[e])[e];return t?Zr(s,e,t):null}const zn=/(-?[0-9.]*[0-9]+[0-9.]*)/g,jn=/^-?[0-9.]*[0-9]+[0-9.]*$/g;function Ur(s,e,t){if(e===1)return s;if(t=t||100,typeof s=="number")return Math.ceil(s*e*t)/t;if(typeof s!="string")return s;const r=s.split(zn);if(r===null||!r.length)return s;const i=[];let n=r.shift(),a=jn.test(n);for(;;){if(a){const o=parseFloat(n);isNaN(o)?i.push(n):i.push(Math.ceil(o*e*t)/t)}else i.push(n);if(n=r.shift(),n===void 0)return i.join("");a=!a}}function Zn(s,e="defs"){let t="";const r=s.indexOf("<"+e);for(;r>=0;){const i=s.indexOf(">",r),n=s.indexOf("</"+e);if(i===-1||n===-1)break;const a=s.indexOf(">",n);if(a===-1)break;t+=s.slice(i+1,n).trim(),s=s.slice(0,r).trim()+s.slice(a+1)}return{defs:t,content:s}}function Un(s,e){return s?"<defs>"+s+"</defs>"+e:e}function Hn(s,e,t){const r=Zn(s);return Un(r.defs,e+r.content+t)}const Dn=s=>s==="unset"||s==="undefined"||s==="none";function Wn(s,e){const t={...zr,...s},r={...Rn,...e},i={left:t.left,top:t.top,width:t.width,height:t.height};let n=t.body;[t,r].forEach(v=>{const f=[],b=v.hFlip,_=v.vFlip;let m=v.rotate;b?_?m+=2:(f.push("translate("+(i.width+i.left).toString()+" "+(0-i.top).toString()+")"),f.push("scale(-1 1)"),i.top=i.left=0):_&&(f.push("translate("+(0-i.left).toString()+" "+(i.height+i.top).toString()+")"),f.push("scale(1 -1)"),i.top=i.left=0);let E;switch(m<0&&(m-=Math.floor(m/4)*4),m=m%4,m){case 1:E=i.height/2+i.top,f.unshift("rotate(90 "+E.toString()+" "+E.toString()+")");break;case 2:f.unshift("rotate(180 "+(i.width/2+i.left).toString()+" "+(i.height/2+i.top).toString()+")");break;case 3:E=i.width/2+i.left,f.unshift("rotate(-90 "+E.toString()+" "+E.toString()+")")}m%2===1&&(i.left!==i.top&&(E=i.left,i.left=i.top,i.top=E),i.width!==i.height&&(E=i.width,i.width=i.height,i.height=E)),f.length&&(n=Hn(n,'<g transform="'+f.join(" ")+'">',"</g>"))});const a=r.width,o=r.height,l=i.width,d=i.height;let c,h;a===null?(h=o===null?"1em":o==="auto"?d:o,c=Ur(h,l/d)):(c=a==="auto"?l:a,h=o===null?Ur(c,d/l):o==="auto"?d:o);const u={},g=(v,f)=>{Dn(f)||(u[v]=f.toString())};g("width",c),g("height",h);const x=[i.left,i.top,l,d];return u.viewBox=x.join(" "),{attributes:u,viewBox:x,body:n}}function qn(s,e){let t=s.indexOf("xlink:")===-1?"":' xmlns:xlink="http://www.w3.org/1999/xlink"';for(const r in e)t+=" "+r+'="'+e[r]+'"';return'<svg xmlns="http://www.w3.org/2000/svg"'+t+">"+s+"</svg>"}const Yn={prefix:"mdi",icons:{"chevron-left":{body:'<path fill="currentColor" d="M15.41 16.58L10.83 12l4.58-4.59L14 6l-6 6l6 6z"/>'},"chevron-right":{body:'<path fill="currentColor" d="M8.59 16.58L13.17 12L8.59 7.41L10 6l6 6l-6 6z"/>'},"book-open-page-variant":{body:'<path fill="currentColor" d="m19 2l-5 4.5v11l5-4.5zM6.5 5C4.55 5 2.45 5.4 1 6.5v14.66c0 .25.25.5.5.5c.1 0 .15-.07.25-.07c1.35-.65 3.3-1.09 4.75-1.09c1.95 0 4.05.4 5.5 1.5c1.35-.85 3.8-1.5 5.5-1.5c1.65 0 3.35.31 4.75 1.06c.1.05.15.03.25.03c.25 0 .5-.25.5-.5V6.5c-.6-.45-1.25-.75-2-1V19c-1.1-.35-2.3-.5-3.5-.5c-1.7 0-4.15.65-5.5 1.5V6.5C10.55 5.4 8.45 5 6.5 5"/>'},pencil:{body:'<path fill="currentColor" d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83l3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75z"/>'},eye:{body:'<path fill="currentColor" d="M12 9a3 3 0 0 0-3 3a3 3 0 0 0 3 3a3 3 0 0 0 3-3a3 3 0 0 0-3-3m0 8a5 5 0 0 1-5-5a5 5 0 0 1 5-5a5 5 0 0 1 5 5a5 5 0 0 1-5 5m0-12.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5"/>'},download:{body:'<path fill="currentColor" d="M5 20h14v-2H5m14-9h-4V3H9v6H5l7 7z"/>'},cog:{body:'<path fill="currentColor" d="M12 15.5A3.5 3.5 0 0 1 8.5 12A3.5 3.5 0 0 1 12 8.5a3.5 3.5 0 0 1 3.5 3.5a3.5 3.5 0 0 1-3.5 3.5m7.43-2.53c.04-.32.07-.64.07-.97s-.03-.66-.07-1l2.11-1.63c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.31-.61-.22l-2.49 1c-.52-.39-1.06-.73-1.69-.98l-.37-2.65A.506.506 0 0 0 14 2h-4c-.25 0-.46.18-.5.42l-.37 2.65c-.63.25-1.17.59-1.69.98l-2.49-1c-.22-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64L4.57 11c-.04.34-.07.67-.07 1s.03.65.07.97l-2.11 1.66c-.19.15-.25.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1.01c.52.4 1.06.74 1.69.99l.37 2.65c.04.24.25.42.5.42h4c.25 0 .46-.18.5-.42l.37-2.65c.63-.26 1.17-.59 1.69-.99l2.49 1.01c.22.08.49 0 .61-.22l2-3.46c.12-.22.07-.49-.12-.64z"/>'},"file-plus":{body:'<path fill="currentColor" d="M14 2H6c-1.11 0-2 .89-2 2v16c0 1.11.89 2 2 2h7.81c-.53-.91-.81-1.95-.81-3c0-3.31 2.69-6 6-6c.34 0 .67.03 1 .08V8zm-1 7V3.5L18.5 9zm10 11h-3v3h-2v-3h-3v-2h3v-3h2v3h3z"/>'},"file-remove":{body:'<path fill="currentColor" d="M21.12 22.54L19 20.41l-2.12 2.13l-1.41-1.42L17.59 19l-2.12-2.12l1.41-1.41L19 17.59l2.12-2.12l1.42 1.41L20.41 19l2.13 2.12zM14 2H6c-1.11 0-2 .89-2 2v16c0 1.11.89 2 2 2h7.81c-.53-.91-.81-1.95-.81-3c0-3.31 2.69-6 6-6c.34 0 .67.03 1 .08V8zm-1 7V3.5L18.5 9z"/>'},book:{body:'<path fill="currentColor" d="M18 22a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2h-6v7L9.5 7.5L7 9V2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2z"/>'},"book-open-outline":{body:'<path fill="currentColor" d="M21 4H3a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2h18a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2M3 19V6h8v13zm18 0h-8V6h8zm-7-9.5h6V11h-6zm0 2.5h6v1.5h-6zm0 2.5h6V16h-6z"/>'},"book-variant":{body:'<path fill="currentColor" d="M6 4h5v8l-2.5-1.5L6 12M18 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2"/>'},"folder-open":{body:'<path fill="currentColor" d="M19 20H4a2 2 0 0 1-2-2V6c0-1.11.89-2 2-2h6l2 2h7a2 2 0 0 1 2 2H4v10l2.14-8h17.07l-2.28 8.5c-.23.87-1.01 1.5-1.93 1.5"/>'},"drag-vertical":{body:'<path fill="currentColor" d="M9 3h2v2H9zm4 0h2v2h-2zM9 7h2v2H9zm4 0h2v2h-2zm-4 4h2v2H9zm4 0h2v2h-2zm-4 4h2v2H9zm4 0h2v2h-2zm-4 4h2v2H9zm4 0h2v2h-2z"/>'},close:{body:'<path fill="currentColor" d="M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12z"/>'},plus:{body:'<path fill="currentColor" d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6z"/>'}},lastModified:1737398331,width:24,height:24};function Jn(s,e={}){const t=Bn(Yn,s);if(!t)throw new Error(`Unknown MDI icon in subset: ${s}`);const r=e.size??"1.15rem",i=Wn(t,{height:r,width:r}),n=document.createElement("span");return n.className=e.className??"fc-icon",n.setAttribute("aria-hidden","true"),n.innerHTML=qn(i.body,i.attributes),n}function Es(s,e){const t=Jn(e.icon),r=document.createElement("span");r.className=e.iconOnly?"fc-btn-label fc-btn-label--sr":"fc-btn-label",r.textContent=e.label,s.title=e.label,s.setAttribute("aria-label",e.label),s.replaceChildren(t,r)}const Gn={sound:!0,soundVolume:!0,vo:!0,voVolume:!0,sfx:!0,sfxVolume:!0,music:!0,musicVolume:!0,captions:!0};class Ls{constructor(e,t,r,i,n={},a,o,l,d){y(this,"element");y(this,"root");y(this,"stage");y(this,"chrome");y(this,"captionsEl");y(this,"loaded");y(this,"spreadView");y(this,"pager");y(this,"bus",new ye);y(this,"readAloud");y(this,"springroll");y(this,"bindings",null);y(this,"sfxAudio");y(this,"unbindSwipe",null);y(this,"resizeObserver",null);y(this,"listeners",new Map);y(this,"destroyed",!1);y(this,"btnPrev");y(this,"btnRead");y(this,"btnNext");y(this,"chromeHiddenByOptions",!1);y(this,"extraFiles",{});y(this,"defaultFontFamily",null);y(this,"navLocked",!1);var g,x,v,f,b,_;this.root=e,this.loaded=t,this.springroll=r,this.chromeHiddenByOptions=!!n.hidden,this.element=document.createElement("div"),this.element.className="fc-root",this.element.tabIndex=0,this.stage=document.createElement("div"),this.stage.className="fc-stage",this.captionsEl=document.createElement("div"),this.captionsEl.className="fc-captions",this.captionsEl.setAttribute("aria-live","polite");const c={prev:((g=n.labels)==null?void 0:g.prev)??"Prev",read:((x=n.labels)==null?void 0:x.read)??"Read",next:((v=n.labels)==null?void 0:v.next)??"Next"},h={prev:((f=n.ariaLabels)==null?void 0:f.prev)??"Previous page",read:((b=n.ariaLabels)==null?void 0:b.read)??"Read aloud",next:((_=n.ariaLabels)==null?void 0:_.next)??"Next page"};this.chrome=document.createElement("div"),this.chrome.className=["fc-chrome",n.className].filter(Boolean).join(" "),this.chrome.hidden=!!n.hidden,this.btnPrev=document.createElement("button"),this.btnPrev.type="button",this.btnPrev.className="fc-btn fc-btn-prev",this.btnPrev.setAttribute("aria-label",h.prev),Es(this.btnPrev,{icon:"chevron-left",label:c.prev,iconOnly:!0}),this.btnRead=document.createElement("button"),this.btnRead.type="button",this.btnRead.className="fc-btn fc-btn-read",this.btnRead.setAttribute("aria-label",h.read),Es(this.btnRead,{icon:"book-open-page-variant",label:c.read,iconOnly:!0}),this.btnNext=document.createElement("button"),this.btnNext.type="button",this.btnNext.className="fc-btn fc-btn-next",this.btnNext.setAttribute("aria-label",h.next),Es(this.btnNext,{icon:"chevron-right",label:c.next,iconOnly:!0});const u=document.createElement("div");u.className="fc-nav-peapod",u.append(this.btnPrev,this.btnRead,this.btnNext),this.chrome.append(u),this.spreadView=new Ln(t.story,t.assets,(m,E)=>this.handleTapActions(m,E),{flipStyle:a??"default",flipSpeed:o}),this.pager=new Sn(t.story,this.spreadView,{mode:l,singleBreakpoint:d}),this.readAloud=new Yr(this.bus),this.sfxAudio=new Audio,this.bus.register(this.sfxAudio,"sfx"),this.stage.appendChild(this.spreadView.element),this.element.append(this.stage,this.captionsEl,this.chrome),this.root.appendChild(this.element),this.wireChrome(),this.wirePager(i),this.wireSpringroll(),this.wireResize(),this.unbindSwipe=Jr(this.stage,{onSwipeLeft:()=>{this.navLocked||this.next()},onSwipeRight:()=>{this.navLocked||this.prev()}}),this.element.addEventListener("keydown",m=>{this.navLocked||(m.key==="ArrowRight"?(m.preventDefault(),this.next()):m.key==="ArrowLeft"?(m.preventDefault(),this.prev()):m.key===" "&&(m.preventDefault(),this.playReadAloud()))}),this.readAloud.onCaption(m=>{this.captionsEl.textContent=m??"",this.captionsEl.hidden=!m})}static async create(e,t){const r={...Gn,...t.features};let i=t.springroll??null,n=null;if(!i){const c=await Vr(r);c&&(i=c.app,n=c.loadGate,Kn(i))}const a=[];t.onProgress&&a.push(t.onProgress);const o=c=>{Rr(i,c);for(const h of a)h(c)};o({stage:"fetch",progress:0,detail:"start"});const l=await Et(t.story,{baseUrl:t.baseUrl,name:t.storyName,onProgress:o});n==null||n.resolve(),await Br(i);const d=new Ls(e,l,i,t.autoPlayReadAloud??!1,t.chrome??{},t.flipStyle,t.flipSpeed,t.layoutMode,t.singleBreakpoint);return d.pager.updateLayout(e.clientWidth||window.innerWidth,e.clientHeight||window.innerHeight,!1),d.layoutStage(),await d.pager.showInitial(),d.syncChromeNavState(),d.emit("ready",{story:l.story}),d}get story(){return this.loaded.story}get assets(){return this.loaded.assets}get baseUrl(){return this.loaded.baseUrl}get blobUrls(){return this.loaded.blobUrls}get layoutMode(){return this.pager.layoutMode}get layoutPreference(){return this.pager.layoutPreference}get pageIds(){return this.pager.currentPageIds}get spreadIndex(){return this.pager.currentSpread.index}get isNavLocked(){return this.navLocked}getDefaultFontFamily(){return this.defaultFontFamily}setDefaultFontFamily(e){this.defaultFontFamily=e}getExtraFiles(){return this.extraFiles}putExtraFile(e,t){this.extraFiles[e]=t}setNavLocked(e){this.navLocked=e,e?(this.readAloud.stop(),this.chrome.hidden=!0):(this.chrome.hidden=this.chromeHiddenByOptions,this.syncChromeNavState())}getEditableLeaves(){const e=this.pager.currentSpread;return this.spreadView.getEditableLeaves(this.pager.layoutMode,e).map(t=>{var r;return{side:t.side,pageIndex:t.pageIndex,pageId:((r=this.loaded.story.pages[t.pageIndex])==null?void 0:r.id)??"",slot:t.slot}})}getSpreadElement(){return this.spreadView.bookEl}get bookState(){return this.pager.currentBookState}getSpreadPages(){const e=this.pager.currentSpread,t=this.loaded.story.pages;return{left:e.left.kind==="page"?t[e.left.pageIndex]??null:null,right:e.right.kind==="page"?t[e.right.pageIndex]??null:null}}setPageViewsHidden(e){this.spreadView.setPageViewsHidden(e)}remountCurrent(){this.spreadView.remountCurrent(),this.layoutStage()}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{var r;return(r=this.listeners.get(e))==null?void 0:r.delete(t)}}next(){return this.navLocked?Promise.resolve():this.navigate(()=>this.pager.next())}prev(){return this.navLocked?Promise.resolve():this.navigate(()=>this.pager.prev())}goTo(e){return this.navigate(()=>this.pager.goTo(e))}setStageZoom(e){this.spreadView.setStageZoom(e),this.stage.classList.toggle("fc-stage-scroll",e.mode==="percent"),this.stage.classList.toggle("fc-stage-fit-page",e.mode==="fit-page"),this.layoutStage()}setLayoutMode(e){this.pager.setLayoutMode(e,this.root.clientWidth||window.innerWidth,this.root.clientHeight||window.innerHeight),this.layoutStage(),this.syncChromeNavState(),this.emit("layoutchange",{layoutMode:this.pager.layoutMode})}setFlipStyle(e){this.spreadView.setFlipStyle(e)}setFlipSpeed(e){this.spreadView.setFlipSpeed(e)}playReadAloud(){if(this.navLocked)return Promise.resolve();const e=this.buildReadAloudClips();return this.readAloud.playSequence(e)}pause(){this.readAloud.pause(),this.bus.setPaused(!0)}resume(){this.bus.setPaused(!1),this.readAloud.resume()}async replaceStory(e,t){var n;this.readAloud.stop();const r=this.loaded,i=await Et(e,{name:t??(e instanceof File?e.name:void 0)});ws(r),this.loaded=i,this.extraFiles={},this.defaultFontFamily=null,this.spreadView.setLoaded(i.story,i.assets),this.pager.replaceStory(i.story,((n=i.story.pages[0])==null?void 0:n.id)??null),this.layoutStage(),this.syncChromeNavState(),this.emit("ready",{story:i.story})}async openFanciFile(e){if(!zt(e))throw new Error(`Expected a .fanci file, got ${e.name}`);await this.replaceStory(e,e.name)}async updatePage(e){const t=this.loaded.story.pages.findIndex(r=>r.id===e.id);t<0||(this.loaded.story.pages[t]=e,this.spreadView.setStory(this.loaded.story),this.spreadView.remountCurrent(),this.layoutStage())}async setPages(e,t){this.loaded.story.pages=e,this.spreadView.setStory(this.loaded.story),this.pager.rebuildFromStory(t??this.pager.currentPageIds[0]??null),this.layoutStage(),this.syncChromeNavState()}async addPage(){const e=Xn(this.loaded.story);return this.loaded.story.pages.push(e),this.spreadView.setStory(this.loaded.story),this.pager.rebuildFromStory(e.id),this.layoutStage(),this.syncChromeNavState(),e}async removePage(e){var i;if(this.loaded.story.pages.length<=1)return;const t=this.loaded.story.pages.findIndex(n=>n.id===e);if(t<0)return;this.loaded.story.pages.splice(t,1);const r=((i=this.loaded.story.pages[Math.min(t,this.loaded.story.pages.length-1)])==null?void 0:i.id)??null;this.spreadView.setStory(this.loaded.story),this.pager.rebuildFromStory(r),this.layoutStage(),this.syncChromeNavState()}async reorderPages(e,t){const r=this.loaded.story.pages;if(e<0||t<0||e>=r.length||t>=r.length||e===t)return;const[i]=r.splice(e,1);i&&(r.splice(t,0,i),this.spreadView.setStory(this.loaded.story),this.pager.rebuildFromStory(i.id),this.layoutStage(),this.syncChromeNavState())}async setFrontCover(e){this.loaded.story.frontCover=e,this.spreadView.setStory(this.loaded.story),this.pager.rebuildFromStory(this.pager.currentPageIds[0]??null),this.layoutStage(),this.syncChromeNavState()}async setBackCover(e){this.loaded.story.backCover=e,this.spreadView.setStory(this.loaded.story),this.pager.rebuildFromStory(this.pager.currentPageIds[0]??null),this.layoutStage(),this.syncChromeNavState()}async setHardback(e){this.loaded.story.hardback=e,this.spreadView.setStory(this.loaded.story),this.layoutStage()}applyFontToAllText(e){this.defaultFontFamily=e;for(const t of this.loaded.story.pages)for(const r of t.blocks)r.type==="text"&&(r.style={...r.style,fontFamily:e})}async packToBlob(){return Mr(this.loaded.story,{baseUrl:this.loaded.baseUrl,files:{...this.extraFiles}})}async downloadFanci(e){const t=e??`${this.loaded.story.id||"story"}.fanci`,r=await this.packToBlob();Pr(r,t.endsWith(".fanci")?t:`${t}.fanci`)}destroy(){var e,t,r;this.destroyed||(this.destroyed=!0,this.readAloud.destroy(),this.bus.unregister(this.sfxAudio),(e=this.bindings)==null||e.destroy(),(t=this.unbindSwipe)==null||t.call(this),(r=this.resizeObserver)==null||r.disconnect(),this.spreadView.destroy(),this.element.remove(),this.listeners.clear(),ws(this.loaded))}async navigate(e){this.readAloud.stop(),await e(),this.layoutStage()}wireChrome(){this.btnPrev.addEventListener("click",()=>void this.prev()),this.btnNext.addEventListener("click",()=>void this.next()),this.btnRead.addEventListener("click",()=>void this.playReadAloud())}syncChromeNavState(){const e=this.pager.canPrev,t=this.pager.canNext;this.btnPrev.disabled=!e,this.btnNext.disabled=!t,this.btnPrev.classList.toggle("is-disabled",!e),this.btnNext.classList.toggle("is-disabled",!t),this.btnPrev.setAttribute("aria-disabled",String(!e)),this.btnNext.setAttribute("aria-disabled",String(!t))}wirePager(e){this.pager.on("pagechange",t=>{this.syncChromeNavState(),this.emit("pagechange",t),e&&!this.navLocked&&this.playReadAloud()}),this.pager.on("layoutchange",t=>{this.readAloud.stop(),this.layoutStage(),this.syncChromeNavState(),this.emit("layoutchange",t)})}wireSpringroll(){this.bindings=Or(this.springroll,this.bus,{onCaptionsMuted:e=>this.readAloud.setCaptionsMuted(e),onPause:e=>{e?this.readAloud.pause():this.readAloud.resume()}})}wireResize(){const e=()=>{this.pager.updateLayout(this.root.clientWidth||window.innerWidth,this.root.clientHeight||window.innerHeight),this.layoutStage()};typeof ResizeObserver<"u"?(this.resizeObserver=new ResizeObserver(e),this.resizeObserver.observe(this.root)):window.addEventListener("resize",e)}layoutStage(){const e=this.stage.clientWidth||this.root.clientWidth||window.innerWidth;let t=this.stage.clientHeight||Math.max(320,this.root.clientHeight-64);if(this.spreadView.updateStageSize(e,t,this.pager.layoutMode,this.pager.currentSpread),this.stage.classList.contains("fc-stage-fit-page")){const r=this.stage.clientHeight;r>0&&r!==t&&(t=r,this.spreadView.updateStageSize(e,t,this.pager.layoutMode,this.pager.currentSpread))}}buildReadAloudClips(){const e=this.pager.layoutMode,t=this.pager.currentSpread,r=this.pager.currentBookState;let i=[t.left,t.right];r==="closed-front"?i=[t.left]:r==="closed-back"?i=[t.right]:e==="single"&&(i=t.left.kind==="blank"?[t.right]:t.right.kind==="blank"?[t.left]:[t.left]);const n=[];for(const a of i){if(a.kind!=="page")continue;const o=this.loaded.story.pages[a.pageIndex];if(!o.readAloud)continue;const l=this.loaded.assets.audioUrls.get(o.readAloud.audio);if(!l)continue;const d=this.resolveCues(o.readAloud.cues),c=this.spreadView.getPageElement(o.id);n.push({url:l.url,channel:l.channel,cues:d,root:c})}return n}resolveCues(e){return e?Array.isArray(e)?e:this.loaded.assets.cues.get(e)??[]:[]}handleTapActions(e,t){if(!this.navLocked){for(const r of e)if("play"in r){const i=this.loaded.assets.audioUrls.get(r.play);if(!i)continue;this.sfxAudio.src=i.url,this.bus.applyTo(this.sfxAudio,i.channel),this.sfxAudio.play().catch(()=>{})}else if("toggleClass"in r){const i=t.querySelector(`[data-block-id="${r.toggleClass.target}"]`);i==null||i.classList.toggle(r.toggleClass.className)}}}emit(e,t){const r=this.listeners.get(e);if(r)for(const i of r)i(t)}}function Xn(s){let e=s.pages.length+1,t=`page-${e}`;const r=new Set(s.pages.map(i=>i.id));for(;r.has(t);)e+=1,t=`page-${e}`;return{id:t,background:{color:"#faf6ef"},blocks:[]}}function Kn(s){var t,r,i,n,a,o;const e=s.state;e&&((t=e.pause)==null||t.subscribe(()=>{}),(r=e.soundVolume)==null||r.subscribe(()=>{}),(i=e.voVolume)==null||i.subscribe(()=>{}),(n=e.sfxVolume)==null||n.subscribe(()=>{}),(a=e.musicVolume)==null||a.subscribe(()=>{}),(o=e.captionsMuted)==null||o.subscribe(()=>{}))}function Ue(s,e=0,t=0){if(s==null)return e;if(typeof s=="number")return Number.isFinite(s)?s:e;const r=s.trim();if(/^-?\d+(\.\d+)?$/.test(r)){const a=Number(r);return Number.isFinite(a)?a:e}const i=r.match(/^(-?\d+(?:\.\d+)?)%$/);if(i){const a=Number(i[1]);return!Number.isFinite(a)||!(t>0)?e:a/100*t}const n=r.match(/^(-?\d+(?:\.\d+)?)px$/i);if(n){const a=Number(n[1]);return Number.isFinite(a)?a:e}return e}function He(s,e){const{width:t,height:r}=e;return{x:Math.round(Ue(s==null?void 0:s.x,0,t)),y:Math.round(Ue(s==null?void 0:s.y,0,r)),width:Math.round(Ue(s==null?void 0:s.width,t,t)),height:Math.round(Ue(s==null?void 0:s.height,r*.25,r))}}function Rt(s){return typeof s=="string"&&/%$/.test(s.trim())}function ct(s,e){if(!(e>0))return"0%";const t=s/e*100,r=Math.round(t*10)/10;return Number.isInteger(r)?`${r}%`:`${r}%`}function Ot(s,e,t,r,i,n,a={}){const o=He(i,n),l=Math.abs(o.x-s)<=1&&Math.abs(o.y-e)<=1&&Math.abs(o.width-t)<=1,d=Math.abs(o.height-r)<=1;if(l&&(a.preserveHeight||d)&&i)return{...i};const c=Rt(i==null?void 0:i.x)||Rt(i==null?void 0:i.y)||Rt(i==null?void 0:i.width)||Rt(i==null?void 0:i.height),h=a.preserveHeight&&(i==null?void 0:i.height)!=null?i.height:r;return c?{...i,x:ct(s,n.width),y:ct(e,n.height),width:ct(t,n.width),height:typeof h=="string"||typeof h=="number"?typeof h=="number"?ct(h,n.height):h:ct(r,n.height)}:{...i,x:s,y:e,width:t,height:typeof h=="number"?Math.round(h):h}}function Hr(s,e,t=1.35){if(s==null)return t;if(typeof s=="number")return s>0?s:t;const r=s.trim();if(/^-?\d+(\.\d+)?$/.test(r)){const a=Number(r);return a>0?a:t}const i=r.match(/^(-?\d+(?:\.\d+)?)%$/);if(i){const a=Number(i[1])/100;return a>0?a:t}const n=r.match(/^(-?\d+(?:\.\d+)?)px$/i);if(n&&e>0){const a=Number(n[1])/e;return a>0?a:t}return t}const Qn=1;function ea(s,e,t){if(e.width===t.width&&e.height===t.height)return;const r=t.width/e.width,i=t.height/e.height;for(const n of s){const a=He(n.layout,e);n.layout={...n.layout,x:Math.round(a.x*r),y:Math.round(a.y*i),width:Math.max(1,Math.round(a.width*r)),height:Math.max(1,Math.round(a.height*i))}}}function Ms(s){return typeof DOMParser>"u"?s.replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim():(new DOMParser().parseFromString(s,"text/html").body.textContent??"").replace(/\u00a0/g," ")}function Dr(s){return`<p>${s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/\n/g,"<br/>")}</p>`}function Wr(s){return s.type==="text"||s.type==="image"||s.type==="hotspot"}function Ps(s,e,t,r,i){var d;const n=(i==null?void 0:i.syncHotspots)===!0,a=new Map;for(const c of e.blocks)c.type!=="hotspot"&&a.set(c.id,{...c});const o=[];for(const c of s){const h=c.blockId,u=c.blockType;if(!h||!u)continue;const g=a.get(h),x=Math.round(c.left??0),v=Math.round(c.top??0);if(u==="text"){const f=Math.round(c.width??0),b=Math.round(c.height??0),_=c.text??"",m=g&&g.type==="text"?g:void 0,E=m?Ms(m.html??""):"",R=m&&E===_&&m.html?m.html:Dr(_),L=m==null?void 0:m.style,O={fontFamily:c.fontFamily||(L==null?void 0:L.fontFamily),fontSize:c.fontSize!=null?`${Math.round(c.fontSize)}px`:L==null?void 0:L.fontSize,color:typeof c.fill=="string"?c.fill:L==null?void 0:L.color,textAlign:c.textAlign??(L==null?void 0:L.textAlign),lineHeight:c.lineHeight??(L==null?void 0:L.lineHeight),fontWeight:c.fontWeight||(L==null?void 0:L.fontWeight),fontStyle:c.fontStyle||(L==null?void 0:L.fontStyle)};o.push({id:h,type:"text",layout:Ot(x,v,f,b,m==null?void 0:m.layout,t,{preserveHeight:!0}),html:R,style:O,htmlSrc:m==null?void 0:m.htmlSrc})}else if(u==="image"){const f=Math.round((c.width??0)*(c.scaleX??1)),b=Math.round((c.height??0)*(c.scaleY??1)),_=c.assetId??(g&&g.type==="image"?g.asset:void 0);if(!_)continue;const m=g&&g.type==="image"?g:void 0,E=Ot(x,v,f,b,m==null?void 0:m.layout,t),R=c.fit??((d=m==null?void 0:m.layout)==null?void 0:d.fit);R&&(E.fit=R),o.push({id:h,type:"image",asset:_,layout:E,className:m==null?void 0:m.className})}else if(u==="hotspot"){const f=Math.round((c.width??0)*(c.scaleX??1)),b=Math.round((c.height??0)*(c.scaleY??1)),_=g&&g.type==="hotspot"?g:void 0;o.push({id:h,type:"hotspot",layout:Ot(x,v,f,b,_==null?void 0:_.layout,t),onTap:c.onTap??(_==null?void 0:_.onTap)??[],ariaLabel:c.ariaLabel??(_==null?void 0:_.ariaLabel)})}}for(const c of e.blocks)Wr(c)&&(c.type==="hotspot"&&n||o.some(h=>h.id===c.id)||o.push(c));let l=e.background?{...e.background}:void 0;return typeof r=="string"&&r&&(l={...l,color:r}),{...e,background:l,blocks:o}}function Is(s,e,t){var n,a,o,l,d,c,h,u,g,x,v;const r={color:((n=s.background)==null?void 0:n.color)??"#faf6ef"};(a=s.background)!=null&&a.asset&&(r.imageAssetId=s.background.asset,r.imageSrc=(o=e.images.get(s.background.asset))==null?void 0:o.src);const i=[];for(const f of s.blocks)if(Wr(f)){if(f.type==="text"){const b=f.html??e.html.get(`htmlSrc:${f.id}`)??(f.htmlSrc?e.html.get(f.htmlSrc):void 0)??"",_=He(f.layout,t),m=Ue((l=f.style)==null?void 0:l.fontSize,18)||18;i.push({kind:"text",blockId:f.id,text:Ms(b),left:_.x,top:_.y,width:Math.max(20,_.width),fontFamily:((d=f.style)==null?void 0:d.fontFamily)??"Georgia, serif",fontSize:m,fill:((c=f.style)==null?void 0:c.color)??"#1f1a14",textAlign:((h=f.style)==null?void 0:h.textAlign)??"left",lineHeight:Hr((u=f.style)==null?void 0:u.lineHeight,m,1.35),fontWeight:(g=f.style)==null?void 0:g.fontWeight,fontStyle:(x=f.style)==null?void 0:x.fontStyle})}else if(f.type==="image"){const b=e.images.get(f.asset);if(!(b!=null&&b.src))continue;const _=He(f.layout,t);i.push({kind:"image",blockId:f.id,assetId:f.asset,left:_.x,top:_.y,width:_.width,height:_.height,src:b.src,fit:(v=f.layout)==null?void 0:v.fit})}else if(f.type==="hotspot"){const b=He(f.layout,t);i.push({kind:"hotspot",blockId:f.id,left:b.x,top:b.y,width:b.width,height:b.height,ariaLabel:f.ariaLabel,onTap:f.onTap})}}return{background:r,objects:i}}function ta(s){return s.blockType==="image"||s.blockType==="hotspot"?Math.round((s.width??0)*(s.scaleX??1)):Math.round(s.width??0)}function qr(s){return s.blockType==="image"||s.blockType==="hotspot"?Math.round((s.height??0)*(s.scaleY??1)):Math.round(s.height??0)}function sa(s){return`${s}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function ra(s,e){return{...s,left:s.left+e}}function ia(s,e,t,r){const i=[];let n=null,a=null;if(s){const o=Is(s,t,r);n=o.background,i.push(...o.objects)}if(e){const o=Is(e,t,r);a=o.background;for(const l of o.objects)i.push(ra(l,r.width))}return{pageSize:r,spreadWidth:r.width*2,leftBackground:n,rightBackground:a,objects:i}}function na(s,e,t,r,i,n){const a=r.width,o=[],l=[];for(const h of s){if(!h.blockId||!h.blockType)continue;const u=h.left??0,g=ta(h),x=u+g,v=x<=a+.5,f=u>=a-.5;if(v){o.push({...h});continue}if(f){l.push({...h,left:u-a});continue}const b=Math.max(1,Math.round(a-u)),_=Math.max(1,Math.round(x-a));o.push({...h,width:b,scaleX:1,scaleY:1,height:qr(h)}),l.push({...h,blockId:sa(h.blockId),left:0,width:_,scaleX:1,scaleY:1,height:qr(h)})}const d=e!=null?Ps(o,e,r,i==null?void 0:i.left,n):null,c=t!=null?Ps(l,t,r,i==null?void 0:i.right,n):null;return{left:d,right:c}}return S.CueTimeline=$s,S.DEFAULT_FLIP_SPEED_MS=$r,S.DEFAULT_LAYOUT_MODE=wr,S.DEFAULT_SINGLE_BREAKPOINT=Sr,S.DefaultFlipStyle=$t,S.FABRIC_CSS_FONT_SIZE_MULT=Qn,S.FANCI_EXTENSION=Tt,S.FlipStyle=ot,S.HARDBACK_EDGE_RATIO=xs,S.Storybook=Ls,S.bindApplication=Or,S.boxToPixels=He,S.buildBackCoverSpread=Cr,S.buildFrontCoverSpread=xr,S.buildSingleSpreads=Tr,S.buildSpreads=Mt,S.buildTwoPageSpreads=Ar,S.contentPageIds=Er,S.createFlipStyle=Ss,S.createSpringrollApplication=Vr,S.downloadBlob=Pr,S.extensionOf=Os,S.fabricLikeToPage=Ps,S.findFanciFile=Gr,S.findSpreadIndexForPage=je,S.findStoryJsonPath=ys,S.getRegisteredFlipStyle=_n,S.hardbackEnabled=Cs,S.hardbackOverhang=Fr,S.htmlToPlainText=Ms,S.isFanciFile=zt,S.listRegisteredFlipStyles=Nr,S.loadEpubFromBytes=rn,S.loadEpubFromZip=ms,S.loadFanciFromBytes=fn,S.loadFanciFromZip=vs,S.loadStory=Et,S.packFanci=Mr,S.pageToFabricLike=Is,S.pagesToSpreadFabricLike=ia,S.parseStory=Be,S.parseVtt=Qt,S.plainTextToHtml=Dr,S.primaryPageId=Lr,S.registerFlipStyle=Ir,S.reportSpringrollLoaded=Mn,S.reportSpringrollProgress=Rr,S.resolveCssLineHeight=Hr,S.resolveFlipSpeedMs=_s,S.resolveLayoutMode=_r,S.revokeLoadedStory=ws,S.scaleBlocksToPageSize=ea,S.serializeLayoutBox=Ot,S.spreadFabricLikeToPages=na,S.storySchema=Qs,S.toPx=Ue,S.waitForSpringrollReady=Br,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"}),S})({});
4
+ `).map(m=>m.trim()).filter(m=>m.length>0&&!m.startsWith("NOTE"));if(o.length===0)continue;const l=o.findIndex(m=>m.includes("-->"));if(l===-1)continue;const d=l>0?o[0]:void 0,h=o[l],c=o.slice(l+1),u=h.split("-->").map(m=>m.trim().split(/\s+/)[0]);if(u.length<2)continue;const v=ar(u[0]),w=ar(u[1]),k=c.join(" ").trim(),f=d||k||`cue-${n++}`;i.push({id:f,start:v,end:w,text:k||void 0})}return i}function ar(s){const e=s.trim().split(":");if(e.length===3){const[t,r,i]=e;return Number(t)*3600+Number(r)*60+Number(i)}if(e.length===2){const[t,r]=e;return Number(t)*60+Number(r)}return Number(s)}function Ze(s,e){if(/^(?:[a-z]+:)?\/\//i.test(e)||e.startsWith("data:")||e.startsWith("blob:")||!s)return e;try{return new URL(e,is(s)).href}catch{return`${is(s)}${e.replace(/^\//,"")}`}}function is(s){return s.endsWith("/")||s.includes("?")?s.endsWith("/")?s:`${s}/`:/\.[a-z0-9]+$/i.test(s.split("/").pop()??"")?s.replace(/[^/]+$/,""):`${s}/`}function ji(s){try{const e=new URL(s,typeof location<"u"?location.href:"http://local/");e.hash="";const t=e.pathname;return e.pathname=t.replace(/[^/]+$/,""),e.href}catch{return is(s.replace(/[^/]+$/,""))}}async function tt(s,e){typeof document>"u"||!("fonts"in document)||await Promise.all(s.fonts.map(async t=>{const r=Ze(e,t.src),n=await new FontFace(t.family,`url(${JSON.stringify(r)})`,{weight:t.weight!=null?String(t.weight):"normal",style:t.style??"normal"}).load();document.fonts.add(n)}))}var H=Uint8Array,se=Uint16Array,ns=Int32Array,Et=new H([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Pt=new H([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),as=new H([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),or=function(s,e){for(var t=new se(31),r=0;r<31;++r)t[r]=e+=1<<s[r-1];for(var i=new ns(t[30]),r=1;r<30;++r)for(var n=t[r];n<t[r+1];++n)i[n]=n-t[r]<<5|r;return{b:t,r:i}},lr=or(Et,2),cr=lr.b,os=lr.r;cr[28]=258,os[258]=28;for(var dr=or(Pt,0),Zi=dr.b,hr=dr.r,ls=new se(32768),z=0;z<32768;++z){var Le=(z&43690)>>1|(z&21845)<<1;Le=(Le&52428)>>2|(Le&13107)<<2,Le=(Le&61680)>>4|(Le&3855)<<4,ls[z]=((Le&65280)>>8|(Le&255)<<8)>>1}for(var ue=(function(s,e,t){for(var r=s.length,i=0,n=new se(e);i<r;++i)s[i]&&++n[s[i]-1];var a=new se(e);for(i=1;i<e;++i)a[i]=a[i-1]+n[i-1]<<1;var o;if(t){o=new se(1<<e);var l=15-e;for(i=0;i<r;++i)if(s[i])for(var d=i<<4|s[i],h=e-s[i],c=a[s[i]-1]++<<h,u=c|(1<<h)-1;c<=u;++c)o[ls[c]>>l]=d}else for(o=new se(r),i=0;i<r;++i)s[i]&&(o[i]=ls[a[s[i]-1]++]>>15-s[i]);return o}),Ee=new H(288),z=0;z<144;++z)Ee[z]=8;for(var z=144;z<256;++z)Ee[z]=9;for(var z=256;z<280;++z)Ee[z]=7;for(var z=280;z<288;++z)Ee[z]=8;for(var st=new H(32),z=0;z<32;++z)st[z]=5;var Ui=ue(Ee,9,0),Di=ue(Ee,9,1),Hi=ue(st,5,0),Wi=ue(st,5,1),cs=function(s){for(var e=s[0],t=1;t<s.length;++t)s[t]>e&&(e=s[t]);return e},ce=function(s,e,t){var r=e/8|0;return(s[r]|s[r+1]<<8)>>(e&7)&t},ds=function(s,e){var t=e/8|0;return(s[t]|s[t+1]<<8|s[t+2]<<16)>>(e&7)},hs=function(s){return(s+7)/8|0},rt=function(s,e,t){return(e==null||e<0)&&(e=0),(t==null||t>s.length)&&(t=s.length),new H(s.subarray(e,t))},qi=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Q=function(s,e,t){var r=new Error(e||qi[s]);if(r.code=s,Error.captureStackTrace&&Error.captureStackTrace(r,Q),!t)throw r;return r},Gi=function(s,e,t,r){var i=s.length,n=r?r.length:0;if(!i||e.f&&!e.l)return t||new H(0);var a=!t,o=a||e.i!=2,l=e.i;a&&(t=new H(i*3));var d=function(ft){var pt=t.length;if(ft>pt){var Ge=new H(Math.max(pt*2,ft));Ge.set(t),t=Ge}},h=e.f||0,c=e.p||0,u=e.b||0,v=e.l,w=e.d,k=e.m,f=e.n,m=i*8;do{if(!v){h=ce(s,c,1);var A=ce(s,c+1,3);if(c+=3,A)if(A==1)v=Di,w=Wi,k=9,f=5;else if(A==2){var O=ce(s,c,31)+257,E=ce(s,c+10,15)+4,I=O+ce(s,c+5,31)+1;c+=14;for(var P=new H(I),W=new H(19),U=0;U<E;++U)W[as[U]]=ce(s,c+U*3,7);c+=E*3;for(var Y=cs(W),oe=(1<<Y)-1,B=ue(W,Y,1),U=0;U<I;){var Z=B[ce(s,c,oe)];c+=Z&15;var g=Z>>4;if(g<16)P[U++]=g;else{var q=0,j=0;for(g==16?(j=3+ce(s,c,3),c+=2,q=P[U-1]):g==17?(j=3+ce(s,c,7),c+=3):g==18&&(j=11+ce(s,c,127),c+=7);j--;)P[U++]=q}}var X=P.subarray(0,O),K=P.subarray(O);k=cs(X),f=cs(K),v=ue(X,k,1),w=ue(K,f,1)}else Q(1);else{var g=hs(c)+4,b=s[g-4]|s[g-3]<<8,R=g+b;if(R>i){l&&Q(0);break}o&&d(u+b),t.set(s.subarray(g,R),u),e.b=u+=b,e.p=c=R*8,e.f=h;continue}if(c>m){l&&Q(0);break}}o&&d(u+131072);for(var ut=(1<<k)-1,le=(1<<f)-1,_e=c;;_e=c){var q=v[ds(s,c)&ut],re=q>>4;if(c+=q&15,c>m){l&&Q(0);break}if(q||Q(2),re<256)t[u++]=re;else if(re==256){_e=c,v=null;break}else{var ie=re-254;if(re>264){var U=re-257,D=Et[U];ie=ce(s,c,(1<<D)-1)+cr[U],c+=D}var me=w[ds(s,c)&le],We=me>>4;me||Q(3),c+=me&15;var K=Zi[We];if(We>3){var D=Pt[We];K+=ds(s,c)&(1<<D)-1,c+=D}if(c>m){l&&Q(0);break}o&&d(u+131072);var qe=u+ie;if(u<K){var Ut=n-K,Dt=Math.min(K,qe);for(Ut+u<0&&Q(3);u<Dt;++u)t[u]=r[Ut+u]}for(;u<qe;++u)t[u]=t[u-K]}}e.l=v,e.p=_e,e.b=u,e.f=h,v&&(h=1,e.m=k,e.d=w,e.n=f)}while(!h);return u!=t.length&&a?rt(t,0,u):t.subarray(0,u)},Se=function(s,e,t){t<<=e&7;var r=e/8|0;s[r]|=t,s[r+1]|=t>>8},it=function(s,e,t){t<<=e&7;var r=e/8|0;s[r]|=t,s[r+1]|=t>>8,s[r+2]|=t>>16},us=function(s,e){for(var t=[],r=0;r<s.length;++r)s[r]&&t.push({s:r,f:s[r]});var i=t.length,n=t.slice();if(!i)return{t:gr,l:0};if(i==1){var a=new H(t[0].s+1);return a[t[0].s]=1,{t:a,l:1}}t.sort(function(R,O){return R.f-O.f}),t.push({s:-1,f:25001});var o=t[0],l=t[1],d=0,h=1,c=2;for(t[0]={s:-1,f:o.f+l.f,l:o,r:l};h!=i-1;)o=t[t[d].f<t[c].f?d++:c++],l=t[d!=h&&t[d].f<t[c].f?d++:c++],t[h++]={s:-1,f:o.f+l.f,l:o,r:l};for(var u=n[0].s,r=1;r<i;++r)n[r].s>u&&(u=n[r].s);var v=new se(u+1),w=fs(t[h-1],v,0);if(w>e){var r=0,k=0,f=w-e,m=1<<f;for(n.sort(function(O,E){return v[E.s]-v[O.s]||O.f-E.f});r<i;++r){var A=n[r].s;if(v[A]>e)k+=m-(1<<w-v[A]),v[A]=e;else break}for(k>>=f;k>0;){var g=n[r].s;v[g]<e?k-=1<<e-v[g]++-1:++r}for(;r>=0&&k;--r){var b=n[r].s;v[b]==e&&(--v[b],++k)}w=e}return{t:new H(v),l:w}},fs=function(s,e,t){return s.s==-1?Math.max(fs(s.l,e,t+1),fs(s.r,e,t+1)):e[s.s]=t},ur=function(s){for(var e=s.length;e&&!s[--e];);for(var t=new se(++e),r=0,i=s[0],n=1,a=function(l){t[r++]=l},o=1;o<=e;++o)if(s[o]==i&&o!=e)++n;else{if(!i&&n>2){for(;n>138;n-=138)a(32754);n>2&&(a(n>10?n-11<<5|28690:n-3<<5|12305),n=0)}else if(n>3){for(a(i),--n;n>6;n-=6)a(8304);n>2&&(a(n-3<<5|8208),n=0)}for(;n--;)a(i);n=1,i=s[o]}return{c:t.subarray(0,r),n:e}},nt=function(s,e){for(var t=0,r=0;r<e.length;++r)t+=s[r]*e[r];return t},fr=function(s,e,t){var r=t.length,i=hs(e+2);s[i]=r&255,s[i+1]=r>>8,s[i+2]=s[i]^255,s[i+3]=s[i+1]^255;for(var n=0;n<r;++n)s[i+n+4]=t[n];return(i+4+r)*8},pr=function(s,e,t,r,i,n,a,o,l,d,h){Se(e,h++,t),++i[256];for(var c=us(i,15),u=c.t,v=c.l,w=us(n,15),k=w.t,f=w.l,m=ur(u),A=m.c,g=m.n,b=ur(k),R=b.c,O=b.n,E=new se(19),I=0;I<A.length;++I)++E[A[I]&31];for(var I=0;I<R.length;++I)++E[R[I]&31];for(var P=us(E,7),W=P.t,U=P.l,Y=19;Y>4&&!W[as[Y-1]];--Y);var oe=d+5<<3,B=nt(i,Ee)+nt(n,st)+a,Z=nt(i,u)+nt(n,k)+a+14+3*Y+nt(E,W)+2*E[16]+3*E[17]+7*E[18];if(l>=0&&oe<=B&&oe<=Z)return fr(e,h,s.subarray(l,l+d));var q,j,X,K;if(Se(e,h,1+(Z<B)),h+=2,Z<B){q=ue(u,v,0),j=u,X=ue(k,f,0),K=k;var ut=ue(W,U,0);Se(e,h,g-257),Se(e,h+5,O-1),Se(e,h+10,Y-4),h+=14;for(var I=0;I<Y;++I)Se(e,h+3*I,W[as[I]]);h+=3*Y;for(var le=[A,R],_e=0;_e<2;++_e)for(var re=le[_e],I=0;I<re.length;++I){var ie=re[I]&31;Se(e,h,ut[ie]),h+=W[ie],ie>15&&(Se(e,h,re[I]>>5&127),h+=re[I]>>12)}}else q=Ui,j=Ee,X=Hi,K=st;for(var I=0;I<o;++I){var D=r[I];if(D>255){var ie=D>>18&31;it(e,h,q[ie+257]),h+=j[ie+257],ie>7&&(Se(e,h,D>>23&31),h+=Et[ie]);var me=D&31;it(e,h,X[me]),h+=K[me],me>3&&(it(e,h,D>>5&8191),h+=Pt[me])}else it(e,h,q[D]),h+=j[D]}return it(e,h,q[256]),h+j[256]},Yi=new ns([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),gr=new H(0),Ji=function(s,e,t,r,i,n){var a=n.z||s.length,o=new H(r+a+5*(1+Math.ceil(a/7e3))+i),l=o.subarray(r,o.length-i),d=n.l,h=(n.r||0)&7;if(e){h&&(l[0]=n.r>>3);for(var c=Yi[e-1],u=c>>13,v=c&8191,w=(1<<t)-1,k=n.p||new se(32768),f=n.h||new se(w+1),m=Math.ceil(t/3),A=2*m,g=function(Fs){return(s[Fs]^s[Fs+1]<<m^s[Fs+2]<<A)&w},b=new ns(25e3),R=new se(288),O=new se(32),E=0,I=0,P=n.i||0,W=0,U=n.w||0,Y=0;P+2<a;++P){var oe=g(P),B=P&32767,Z=f[oe];if(k[B]=Z,f[oe]=B,U<=P){var q=a-P;if((E>7e3||W>24576)&&(q>423||!d)){h=pr(s,l,0,b,R,O,I,W,Y,P-Y,h),W=E=I=0,Y=P;for(var j=0;j<286;++j)R[j]=0;for(var j=0;j<30;++j)O[j]=0}var X=2,K=0,ut=v,le=B-Z&32767;if(q>2&&oe==g(P-le))for(var _e=Math.min(u,q)-1,re=Math.min(32767,P),ie=Math.min(258,q);le<=re&&--ut&&B!=Z;){if(s[P+X]==s[P+X-le]){for(var D=0;D<ie&&s[P+D]==s[P+D-le];++D);if(D>X){if(X=D,K=le,D>_e)break;for(var me=Math.min(le,D-2),We=0,j=0;j<me;++j){var qe=P-le+j&32767,Ut=k[qe],Dt=qe-Ut&32767;Dt>We&&(We=Dt,Z=qe)}}}B=Z,Z=k[B],le+=B-Z&32767}if(K){b[W++]=268435456|os[X]<<18|hr[K];var ft=os[X]&31,pt=hr[K]&31;I+=Et[ft]+Pt[pt],++R[257+ft],++O[pt],U=P+X,++E}else b[W++]=s[P],++R[s[P]]}}for(P=Math.max(P,U);P<a;++P)b[W++]=s[P],++R[s[P]];h=pr(s,l,d,b,R,O,I,W,Y,P-Y,h),d||(n.r=h&7|l[h/8|0]<<3,h-=7,n.h=f,n.p=k,n.i=P,n.w=U)}else{for(var P=n.w||0;P<a+d;P+=65535){var Ge=P+65535;Ge>=a&&(l[h/8|0]=d,Ge=a),h=fr(l,h+1,s.subarray(P,Ge))}n.i=a}return rt(o,0,r+hs(h)+i)},Xi=(function(){for(var s=new Int32Array(256),e=0;e<256;++e){for(var t=e,r=9;--r;)t=(t&1&&-306674912)^t>>>1;s[e]=t}return s})(),Ki=function(){var s=-1;return{p:function(e){for(var t=s,r=0;r<e.length;++r)t=Xi[t&255^e[r]]^t>>>8;s=t},d:function(){return~s}}},Qi=function(s,e,t,r,i){if(!i&&(i={l:1},e.dictionary)){var n=e.dictionary.subarray(-32768),a=new H(n.length+s.length);a.set(n),a.set(s,n.length),s=a,i.w=n.length}return Ji(s,e.level==null?6:e.level,e.mem==null?i.l?Math.ceil(Math.max(8,Math.min(13,Math.log(s.length)))*1.5):20:12+e.mem,t,r,i)},mr=function(s,e){var t={};for(var r in s)t[r]=s[r];for(var r in e)t[r]=e[r];return t},fe=function(s,e){return s[e]|s[e+1]<<8},ae=function(s,e){return(s[e]|s[e+1]<<8|s[e+2]<<16|s[e+3]<<24)>>>0},ps=function(s,e){return ae(s,e)+ae(s,e+4)*4294967296},J=function(s,e,t){for(;t;++e)s[e]=t,t>>>=8};function en(s,e){return Qi(s,e||{},0,0)}function tn(s,e){return Gi(s,{i:2},e&&e.out,e&&e.dictionary)}var yr=function(s,e,t,r){for(var i in s){var n=s[i],a=e+i,o=r;Array.isArray(n)&&(o=mr(r,n[1]),n=n[0]),ArrayBuffer.isView(n)?t[a]=[n,o]:(t[a+="/"]=[new H(0),o],yr(n,a,t,r))}},vr=typeof TextEncoder<"u"&&new TextEncoder,gs=typeof TextDecoder<"u"&&new TextDecoder,sn=0;try{gs.decode(gr,{stream:!0}),sn=1}catch{}var rn=function(s){for(var e="",t=0;;){var r=s[t++],i=(r>127)+(r>223)+(r>239);if(t+i>s.length)return{s:e,r:rt(s,t-1)};i?i==3?(r=((r&15)<<18|(s[t++]&63)<<12|(s[t++]&63)<<6|s[t++]&63)-65536,e+=String.fromCharCode(55296|r>>10,56320|r&1023)):i&1?e+=String.fromCharCode((r&31)<<6|s[t++]&63):e+=String.fromCharCode((r&15)<<12|(s[t++]&63)<<6|s[t++]&63):e+=String.fromCharCode(r)}};function ms(s,e){var t;if(vr)return vr.encode(s);for(var r=s.length,i=new H(s.length+(s.length>>1)),n=0,a=function(d){i[n++]=d},t=0;t<r;++t){if(n+5>i.length){var o=new H(n+8+(r-t<<1));o.set(i),i=o}var l=s.charCodeAt(t);l<128||e?a(l):l<2048?(a(192|l>>6),a(128|l&63)):l>55295&&l<57344?(l=65536+(l&1047552)|s.charCodeAt(++t)&1023,a(240|l>>18),a(128|l>>12&63),a(128|l>>6&63),a(128|l&63)):(a(224|l>>12),a(128|l>>6&63),a(128|l&63))}return rt(i,0,n)}function br(s,e){if(e){for(var t="",r=0;r<s.length;r+=16384)t+=String.fromCharCode.apply(null,s.subarray(r,r+16384));return t}else{if(gs)return gs.decode(s);var i=rn(s),n=i.s,t=i.r;return t.length&&Q(8),n}}var nn=function(s,e){return e+30+fe(s,e+26)+fe(s,e+28)},an=function(s,e,t){var r=fe(s,e+28),i=fe(s,e+30),n=br(s.subarray(e+46,e+46+r),!(fe(s,e+8)&2048)),a=e+46+r,o=on(s,a,i,t,ae(s,e+20),ae(s,e+24),ae(s,e+42)),l=o[0],d=o[1],h=o[2];return[fe(s,e+10),l,d,n,a+i+fe(s,e+32),h]},on=function(s,e,t,r,i,n,a){var o=i==4294967295,l=n==4294967295,d=a==4294967295,h=e+t,c=o+l+d;if(r&&c){for(;e+4<h;e+=4+fe(s,e+2))if(fe(s,e)==1)return[o?ps(s,e+4+8*l):i,l?ps(s,e+4):n,d?ps(s,e+4+8*(l+o)):a,1];r<2&&Q(13)}return[i,n,a,0]},ys=function(s){var e=0;if(s)for(var t in s){var r=s[t].length;r>65535&&Q(9),e+=r+4}return e},kr=function(s,e,t,r,i,n,a,o){var l=r.length,d=t.extra,h=o&&o.length,c=ys(d);J(s,e,a!=null?33639248:67324752),e+=4,a!=null&&(s[e++]=20,s[e++]=t.os),s[e]=20,e+=2,s[e++]=t.flag<<1|(n<0&&8),s[e++]=i&&8,s[e++]=t.compression&255,s[e++]=t.compression>>8;var u=new Date(t.mtime==null?Date.now():t.mtime),v=u.getFullYear()-1980;if((v<0||v>119)&&Q(10),J(s,e,v<<25|u.getMonth()+1<<21|u.getDate()<<16|u.getHours()<<11|u.getMinutes()<<5|u.getSeconds()>>1),e+=4,n!=-1&&(J(s,e,t.crc),J(s,e+4,n<0?-n-2:n),J(s,e+8,t.size)),J(s,e+12,l),J(s,e+14,c),e+=16,a!=null&&(J(s,e,h),J(s,e+6,t.attrs),J(s,e+10,a),e+=14),s.set(r,e),e+=l,c)for(var w in d){var k=d[w],f=k.length;J(s,e,+w),J(s,e+2,f),s.set(k,e+4),e+=4+f}return h&&(s.set(o,e),e+=h),e},ln=function(s,e,t,r,i){J(s,e,101010256),J(s,e+8,t),J(s,e+10,t),J(s,e+12,r),J(s,e+16,i)};function cn(s,e){e||(e={});var t={},r=[];yr(s,"",t,e);var i=0,n=0;for(var a in t){var o=t[a],l=o[0],d=o[1],h=d.level==0?0:8,c=ms(a),u=c.length,v=d.comment,w=v&&ms(v),k=w&&w.length,f=ys(d.extra);u>65535&&Q(11);var m=h?en(l,d):l,A=m.length,g=Ki();g.p(l),r.push(mr(d,{size:l.length,crc:g.d(),c:m,f:c,m:w,u:u!=a.length||w&&v.length!=k,o:i,compression:h})),i+=30+u+f+A,n+=76+2*(u+f)+(k||0)+A}for(var b=new H(n+22),R=i,O=n-i,E=0;E<r.length;++E){var c=r[E];kr(b,c.o,c,c.f,c.u,c.c.length);var I=30+c.f.length+ys(c.extra);b.set(c.c,c.o+I),kr(b,i,c,c.f,c.u,c.c.length,c.o,c.m),i+=16+I+(c.m?c.m.length:0)}return ln(b,i,r.length,O,R),b}function dn(s,e){for(var t={},r=s.length-22;ae(s,r)!=101010256;--r)(!r||s.length-r>65558)&&Q(13);var i=fe(s,r+8);if(!i)return{};var n=ae(s,r+16),a=ae(s,r-20)==117853008;if(a){var o=ae(s,r-12);a=ae(s,o)==101075792,a&&(i=ae(s,o+32),n=ae(s,o+48))}for(var l=0;l<i;++l){var d=an(s,n,a),h=d[0],c=d[1],u=d[2],v=d[3],w=d[4],k=d[5],f=nn(s,k);n=w,h?h==8?t[v]=tn(s.subarray(f,f+c),{out:new H(u)}):Q(14,"unknown compression type "+h):t[v]=rt(s,f,f+c)}return t}const wr=[80,75];function vs(s){return s.length>=2&&s[0]===wr[0]&&s[1]===wr[1]}function bs(s){const e=s instanceof Uint8Array?s:new Uint8Array(s);if(!vs(e))throw new Error("Not a ZIP archive");const t=dn(e),r=new Map;for(const[i,n]of Object.entries(t))!n||i.endsWith("/")||r.set(pe(i),n);return r}function pe(s){return s.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"")}function at(s,e){const t=Mt(s,e);if(!t)throw new Error(`Missing zip entry: ${e}`);return br(t)}function Mt(s,e){const t=pe(e);if(s.has(t))return s.get(t);const r=t.toLowerCase();for(const[i,n]of s)if(i.toLowerCase()===r)return n}function hn(s){return[...s.keys()]}function un(s){var t;switch(((t=s.split(".").pop())==null?void 0:t.toLowerCase())??""){case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"webp":return"image/webp";case"svg":return"image/svg+xml";case"mp3":return"audio/mpeg";case"wav":return"audio/wav";case"ogg":return"audio/ogg";case"m4a":return"audio/mp4";case"webm":return"audio/webm";case"vtt":return"text/vtt";case"html":case"xhtml":case"htm":return"application/xhtml+xml";case"css":return"text/css";case"json":return"application/json";case"woff":return"font/woff";case"woff2":return"font/woff2";case"ttf":return"font/ttf";case"otf":return"font/otf";default:return"application/octet-stream"}}function Sr(s,e){const t=new Uint8Array(s.byteLength);t.set(s);const r=new Blob([t.buffer],{type:un(e)});return URL.createObjectURL(r)}async function fn(s){const e=await fetch(s);if(!e.ok)throw new Error(`Failed to fetch ${s}: ${e.status}`);return e.arrayBuffer()}function pn(s){return ks(bs(s))}function ks(s){const e=at(s,"META-INF/container.xml"),t=ge(e,/full-path\s*=\s*"([^"]+)"/i);if(!t)throw new Error("Invalid EPUB: missing rootfile in container.xml");const r=pe(t),i=r.includes("/")?r.replace(/\/[^/]+$/,"/"):"",n=at(s,r),a=Cr(n,"dc:title")||Cr(n,"title")||"EPUB Story",o=vn(n)??{width:768,height:1024},l=mn(n,i),d=yn(n),h=[],c=new Map,u=f=>{const m=pe(f);if(c.has(m))return c.get(m);const A=Mt(s,m);if(!A)throw new Error(`EPUB missing file: ${m}`);const g=Sr(A,m);return h.push(g),c.set(m,g),g},v={},w=[];if(d.forEach((f,m)=>{const A=l.get(f);if(!A||!/html|xml/i.test(A.mediaType)&&!A.href.match(/\.x?html?$/i))return;const g=A.href,b=at(s,g),R=g.includes("/")?g.replace(/\/[^/]+$/,"/"):"",O=`page-${m+1}`,E=kn(b),{html:I,imageHrefs:P}=wn(E,R,B=>{const Z=pe(B.includes(":")?B:`${R}${B}`);try{return u(Z)}catch{return B}}),W=[{id:`${O}-text`,type:"text",layout:{x:"5%",y:"5%",width:"90%",height:"90%"},html:I}],U=P[0];let Y;if(U){const B=`img-${m}-0`;v[B]={type:"image",src:u(U)},Y={asset:B,color:"#ffffff"}}else Y={color:"#ffffff"};let oe;if(A.mediaOverlay){const B=l.get(A.mediaOverlay);if(B){const Z=bn(at(s,B.href),B.href);if(Z.audioHref){const q=`vo-${m}`,j=pe(Z.audioHref.includes("/")||Z.audioHref.startsWith(".")?xr(B.href,Z.audioHref):`${i}${Z.audioHref}`);v[q]={type:"audio",src:u(j),channel:"vo"};const X=Z.cues;X.length?oe={audio:q,cues:X}:oe={audio:q}}}}w.push({id:O,background:Y,readAloud:oe,blocks:W})}),w.length===0)throw new Error("Invalid EPUB: no spine HTML documents found");return{story:je({id:`epub-${Sn(a)}`,title:a,pageSize:o,fonts:[],assets:v,pages:w}),blobUrls:h}}function gn(s){return!!Mt(s,"META-INF/container.xml")}function mn(s,e){const t=new Map,r=/<item\b[^>]*>/gi;let i;for(;i=r.exec(s);){const n=i[0],a=ge(n,/\bid\s*=\s*"([^"]+)"/i),o=ge(n,/\bhref\s*=\s*"([^"]+)"/i),l=ge(n,/\bmedia-type\s*=\s*"([^"]+)"/i)??"",d=ge(n,/\bmedia-overlay\s*=\s*"([^"]+)"/i)??void 0,h=ge(n,/\bproperties\s*=\s*"([^"]+)"/i)??void 0;!a||!o||t.set(a,{id:a,href:pe(`${e}${o}`),mediaType:l,mediaOverlay:d,properties:h})}return t}function yn(s){const e=s.match(/<spine\b[^>]*>([\s\S]*?)<\/spine>/i);if(!e)return[];const t=[],r=/<itemref\b[^>]*\bidref\s*=\s*"([^"]+)"[^>]*>/gi;let i;for(;i=r.exec(e[1]);)t.push(i[1]);return t}function vn(s){const e=s.match(/<meta\b[^>]*name\s*=\s*"viewport"[^>]*content\s*=\s*"([^"]+)"[^>]*>/i)||s.match(/<meta\b[^>]*content\s*=\s*"([^"]+)"[^>]*name\s*=\s*"viewport"[^>]*>/i);if(!e)return null;const t=e[1],r=t.match(/width\s*=\s*(\d+)/i),i=t.match(/height\s*=\s*(\d+)/i);return!r||!i?null:{width:Number(r[1]),height:Number(i[1])}}function bn(s,e){const t=[];let r;const i=ge(s,/<audio\b[^>]*\bsrc\s*=\s*"([^"]+)"/i);i&&(r=xr(e,i));const n=/<par\b[^>]*>([\s\S]*?)<\/par>/gi;let a,o=0;for(;a=n.exec(s);){const l=a[1],d=ge(l,/<text\b[^>]*\bsrc\s*=\s*"([^"]+)"/i),h=ge(l,/\bclipBegin\s*=\s*"([^"]+)"/i),c=ge(l,/\bclipEnd\s*=\s*"([^"]+)"/i),u=d!=null&&d.includes("#")?d.split("#")[1]:`cue-${o}`;h==null||c==null||(t.push({id:u||`cue-${o}`,start:_r(h),end:_r(c)}),o+=1)}return{audioHref:r,cues:t}}function _r(s){const e=s.replace(/^npt=/i,"").trim();if(/^\d+(\.\d+)?$/.test(e))return Number(e);const t=e.split(":").map(Number);return t.length===3?t[0]*3600+t[1]*60+t[2]:t.length===2?t[0]*60+t[1]:0}function kn(s){const e=s.match(/<body\b[^>]*>([\s\S]*?)<\/body>/i);return e?e[1].trim():s}function wn(s,e,t){const r=[];return{html:s.replace(/\b(src|href)\s*=\s*["']([^"']+)["']/gi,(n,a,o)=>{if(/^(?:[a-z]+:|#|data:)/i.test(o))return n;const l=pe(`${e}${o}`);/\.(png|jpe?g|gif|webp|svg)$/i.test(o)&&r.push(l);const d=t(o);return`${a}="${d}"`}),imageHrefs:r}}function xr(s,e){if(/^(?:[a-z]+:)/i.test(e))return e;const r=((s.includes("/")?s.replace(/\/[^/]+$/,"/"):"")+e).split("/"),i=[];for(const n of r)!n||n==="."||(n===".."?i.pop():i.push(n));return i.join("/")}function ge(s,e){const t=s.match(e);return t?t[1]:null}function Cr(s,e){const t=new RegExp(`<${e.replace(":",":")}[^>]*>([^<]*)</${e.replace(":",":")}>`,"i"),r=s.match(t);return r?r[1].trim():null}function Sn(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,48)||"book"}function ws(s){const e=hn(s),t=e.find(i=>i==="story.json"||i.toLowerCase()==="story.json");if(t)return t;const r=e.filter(i=>i.toLowerCase().endsWith("/story.json")||i.toLowerCase()==="story.json").sort((i,n)=>i.length-n.length);if(r[0])return r[0];throw new Error("Invalid .fanci package: missing story.json")}function Ss(s){const e=ws(s),t=e.includes("/")?e.replace(/\/[^/]+$/,"/"):"",r=je(JSON.parse(at(s,e))),i=new Map,n=[];for(const[a,o]of s){if(a===e)continue;const l=Sr(o,a);n.push(l),i.set(a,l),t&&a.startsWith(t)&&i.set(a.slice(t.length),l)}return Cn(r,a=>xn(i,t,a)),{story:r,pathUrls:i,blobUrls:n,storyDir:t}}function _n(s){return Ss(bs(s))}function xn(s,e,t){const r=pe(t);if(s.has(r))return s.get(r);const i=pe(`${e}${r}`);if(s.has(i))return s.get(i);const n=r.toLowerCase();for(const[a,o]of s)if(a.toLowerCase()===n||a.toLowerCase().endsWith(`/${n}`))return o}function Cn(s,e){for(const t of s.fonts){const r=e(t.src);r&&(t.src=r)}for(const t of Object.values(s.assets)){const r=e(t.src);r&&(t.src=r)}for(const t of s.pages)for(const r of t.blocks)if(r.type==="text"&&r.htmlSrc){const i=e(r.htmlSrc);i&&(r.htmlSrc=i)}}function An(s){if(Mt(s,"META-INF/container.xml"))return!1;try{return ws(s),!0}catch{return!1}}const Nt=".fanci";function _s(s){const e=s.split("?")[0].split("#")[0],t=e.split("/").pop()??e,r=t.lastIndexOf(".");return r>=0?t.slice(r).toLowerCase():""}function Tn(s,e){if(typeof s=="object"&&s!==null&&!(s instanceof Blob)&&!(s instanceof ArrayBuffer)&&!(s instanceof Uint8Array)&&!ArrayBuffer.isView(s)&&("story"in s||"id"in s&&"pages"in s))return"object";const t=e??(typeof s=="string"?s:s instanceof File?s.name:""),r=_s(t);return r===Nt||r===".fanci.zip"?"fanci":r===".epub"?"epub":"json"}async function Ln(s){return s instanceof ArrayBuffer?s:s instanceof Uint8Array?s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength):s.arrayBuffer()}async function It(s,e){const t=typeof e=="string"?{baseUrl:e}:e??{},r=t.onProgress??(()=>{});if(Pn(s)){r({stage:"parse",progress:.1,detail:"story object"});const i=je(s),n=t.baseUrl??(typeof location<"u"?location.href:"");r({stage:"assets",progress:.2,detail:"fonts"}),await tt(i,n);const a=await ot(i,n,r,.25,1);return r({stage:"complete",progress:1}),{story:i,baseUrl:n,assets:a,blobUrls:[],kind:"object"}}if(typeof s=="object"&&s!==null&&"story"in s&&!Ar(s)){const i=s;return It(i.story,{baseUrl:t.baseUrl??i.baseUrl,name:t.name,onProgress:t.onProgress})}if(typeof s=="string")return En(s,t,r);if(Ar(s)){r({stage:"fetch",progress:.05,detail:"bytes"});const i=await Ln(s),n=t.name??(s instanceof File?s.name:void 0)??"";return xs(i,n,t.baseUrl,r)}throw new Error("Unsupported story source")}async function En(s,e,t){const r=_s(s),i=Tn(s,e.name??s);if(t({stage:"fetch",progress:.02,detail:s}),r===Nt||r===".epub"||i==="fanci"||i==="epub"){const u=await fn(s);return t({stage:"fetch",progress:.15,detail:"package downloaded"}),xs(u,e.name??s,e.baseUrl,t)}const n=await fetch(s);if(!n.ok)throw new Error(`Failed to load story: ${n.status} ${n.statusText}`);const a=await n.arrayBuffer(),o=new Uint8Array(a);if(vs(o))return t({stage:"fetch",progress:.15,detail:"zip downloaded"}),xs(a,e.name??s,e.baseUrl,t);t({stage:"parse",progress:.2,detail:"json"});const l=new TextDecoder().decode(o),d=je(JSON.parse(l)),h=e.baseUrl??ji(new URL(s,location.href).href);await tt(d,h);const c=await ot(d,h,t,.3,1);return t({stage:"complete",progress:1}),{story:d,baseUrl:h,assets:c,blobUrls:[],kind:"json"}}async function xs(s,e,t,r){const i=new Uint8Array(s),n=_s(e);if(vs(i)){r({stage:"unpack",progress:.2,detail:"unzip"});const d=bs(i);if(r({stage:"unpack",progress:.35,detail:`${d.size} entries`}),n===".epub"||gn(d)){r({stage:"parse",progress:.4,detail:"epub"});const{story:h,blobUrls:c}=ks(d);await tt(h,t??"");const u=await ot(h,t??"",r,.5,1);return r({stage:"complete",progress:1}),{story:h,baseUrl:t??"",assets:u,blobUrls:c,kind:"epub"}}if(n===Nt||An(d)){r({stage:"parse",progress:.4,detail:"fanci"});const{story:h,blobUrls:c}=Ss(d);await tt(h,t??"");const u=await ot(h,t??"",r,.5,1);return r({stage:"complete",progress:1}),{story:h,baseUrl:t??"",assets:u,blobUrls:c,kind:"fanci"}}throw new Error("ZIP archive is neither a .fanci package (story.json) nor an EPUB (META-INF/container.xml)")}r({stage:"parse",progress:.25,detail:"json bytes"});const a=je(JSON.parse(new TextDecoder().decode(i))),o=t??(typeof location<"u"?location.href:"");await tt(a,o);const l=await ot(a,o,r,.35,1);return r({stage:"complete",progress:1}),{story:a,baseUrl:o,assets:l,blobUrls:[],kind:"json"}}function Pn(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)&&!(s instanceof Blob)&&!(s instanceof ArrayBuffer)&&!(s instanceof Uint8Array)&&"id"in s&&"pages"in s&&"pageSize"in s}function Ar(s){return s instanceof ArrayBuffer||s instanceof Uint8Array||s instanceof Blob||typeof File<"u"&&s instanceof File}async function ot(s,e,t,r,i){var w;const n=new Map,a=new Map,o=new Map,l=new Map,d=Object.entries(s.assets),h=[];for(const k of s.pages)for(const f of k.blocks)if(f.type==="text"&&f.htmlSrc&&!f.html&&h.push(async()=>{const m=Ze(e,f.htmlSrc);l.set(`htmlSrc:${f.id}`,await $t(m))}),(w=k.readAloud)!=null&&w.cues&&typeof k.readAloud.cues=="string"){const m=k.readAloud.cues;s.assets[m]||h.push(async()=>{const A=Ze(e,m);try{o.set(m,rs(await $t(A)))}catch{}})}const c=d.length+h.length||1;let u=0;const v=k=>{u+=1;const f=u/c,m=r+(i-r)*Math.min(1,f);t({stage:"assets",progress:m,count:u,total:c,detail:k})};return await Promise.all(d.map(async([k,f])=>{const m=Ze(e,f.src);f.type==="image"?n.set(k,await Mn(m)):f.type==="audio"?a.set(k,{url:m,channel:f.channel??"vo"}):f.type==="vtt"?o.set(k,rs(await $t(m))):f.type==="html"&&l.set(k,await $t(m)),v(k)})),await Promise.all(h.map(async k=>{await k(),v("fragment")})),d.length===0&&h.length===0&&t({stage:"assets",progress:i,count:0,total:0,detail:"none"}),{images:n,audioUrls:a,cues:o,html:l}}function Mn(s){return new Promise((e,t)=>{const r=new Image;r.decoding="async",r.onload=()=>e(r),r.onerror=()=>t(new Error(`Failed to load image: ${s}`)),r.src=s})}async function $t(s){const e=await fetch(s);if(!e.ok)throw new Error(`Failed to load ${s}: ${e.status}`);return e.text()}function Cs(s){for(const e of s.blobUrls)try{URL.revokeObjectURL(e)}catch{}s.blobUrls.length=0}const Tr="auto",Lr=900;function Er(s,e,t,r){return s==="responsive"?e>=t?"two-page":"single":s==="auto"?e>=r?"two-page":"single":s}function Re(s,e){return{kind:"page",pageIndex:e,pageId:s[e].id}}const Pe={kind:"blank"};function Pr(s){return{index:-1,left:Pe,right:Re(s,0)}}function Mr(s){const e=s.length-1;return{index:-2,left:Pe,right:Re(s,e)}}function Nr(s,e={}){if(s.length===0)return[];const t=!!e.frontCover,r=!!e.backCover,i=[];let n=t?1:0;const a=r?Math.max(n,s.length-1):s.length;for(!t&&n<a&&(i.push({index:0,left:Pe,right:Re(s,0)}),n=1);n<a;){if(n+1<a){i.push({index:i.length,left:Re(s,n),right:Re(s,n+1)}),n+=2;continue}i.push({index:i.length,left:Re(s,n),right:Pe}),n+=1}return i}function Ir(s,e={}){if(s.length===0)return[];const t=!!e.frontCover,r=!!e.backCover,i=s.length-1;return s.map((n,a)=>{const o=Re(s,a);return t&&a===0?{index:a,left:o,right:Pe}:r&&a===i?{index:a,left:Pe,right:o}:a%2===0?{index:a,left:Pe,right:o}:{index:a,left:o,right:Pe}})}function Rt(s,e="two-page",t={}){return e==="single"?Ir(s,t):Nr(s,t)}function $r(s){const e=[];return s.left.kind==="page"&&e.push(s.left.pageId),s.right.kind==="page"&&e.push(s.right.pageId),e}function Rr(s){return s?s.left.kind==="page"?s.left.pageId:s.right.kind==="page"?s.right.pageId:null:null}function Ue(s,e){const t=s.findIndex(r=>r.left.kind==="page"&&r.left.pageId===e||r.right.kind==="page"&&r.right.pageId===e);return t<0?0:t}class Nn{constructor(e,t,r={}){y(this,"story");y(this,"spreadView");y(this,"spreads");y(this,"spreadIndex",0);y(this,"preferredMode");y(this,"resolvedMode","two-page");y(this,"breakpoint");y(this,"listeners",new Map);y(this,"busy",!1);y(this,"hasResolvedLayout",!1);y(this,"bookState");y(this,"covers");y(this,"frontCoverSpread",null);y(this,"backCoverSpread",null);this.story=e,this.spreadView=t,this.preferredMode=r.mode??Tr,this.breakpoint=r.singleBreakpoint??Lr,this.covers={frontCover:!!e.frontCover,backCover:!!e.backCover},this.bookState=this.covers.frontCover?"closed-front":"open",this.rebuildCoverSpreads(),this.spreads=Rt(e.pages,"two-page",this.covers)}get layoutMode(){return this.resolvedMode}get layoutPreference(){return this.preferredMode}get currentBookState(){return this.bookState}get currentSpread(){return this.bookState==="closed-front"&&this.frontCoverSpread?this.frontCoverSpread:this.bookState==="closed-back"&&this.backCoverSpread?this.backCoverSpread:this.spreads[this.spreadIndex]??this.spreads[0]}get currentPageIds(){var e,t;if(this.bookState==="closed-front"){const r=(e=this.story.pages[0])==null?void 0:e.id;return r?[r]:[]}if(this.bookState==="closed-back"){const r=(t=this.story.pages[this.story.pages.length-1])==null?void 0:t.id;return r?[r]:[]}return $r(this.currentSpread)}get canPrev(){return this.bookState==="closed-front"?!1:this.bookState==="closed-back"||this.spreadIndex>0?!0:!!this.covers.frontCover&&this.resolvedMode==="two-page"}get canNext(){return this.bookState==="closed-back"?!1:this.bookState==="closed-front"?this.spreads.length>0||!!this.covers.backCover:this.spreadIndex<this.spreads.length-1?!0:!!this.covers.backCover&&this.resolvedMode==="two-page"}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{var r;return(r=this.listeners.get(e))==null?void 0:r.delete(t)}}setLayoutMode(e,t,r){this.preferredMode=e,this.updateLayout(t,r,!1)}updateLayout(e,t,r=!0){var l,d,h,c,u;const i=Er(this.preferredMode,e,t,this.breakpoint);if(!(!this.hasResolvedLayout||i!==this.resolvedMode)){this.spreadView.setLayoutMode(i);return}const a=this.currentPageIds[0]??Rr(this.spreads[this.spreadIndex])??((l=this.story.pages[0])==null?void 0:l.id)??null;this.resolvedMode=i,this.hasResolvedLayout=!0,this.rebuildCoverSpreads(),this.spreads=Rt(this.story.pages,i,this.covers);const o=this.covers.frontCover&&a===((d=this.story.pages[0])==null?void 0:d.id)||this.covers.backCover&&a===((h=this.story.pages[this.story.pages.length-1])==null?void 0:h.id);i==="single"?(this.bookState="open",this.spreadIndex=a?Ue(this.spreads,a):0):this.covers.frontCover&&(this.bookState==="closed-front"||o&&a===((c=this.story.pages[0])==null?void 0:c.id))?(this.bookState="closed-front",this.spreadIndex=0):this.covers.backCover&&(this.bookState==="closed-back"||o&&a===((u=this.story.pages[this.story.pages.length-1])==null?void 0:u.id))?(this.bookState="closed-back",this.spreadIndex=Math.max(0,this.spreads.length-1)):(this.bookState="open",this.spreadIndex=a?Ue(this.spreads,a):0),this.spreadIndex>=this.spreads.length&&(this.spreadIndex=Math.max(0,this.spreads.length-1)),this.busy=!1,this.spreadView.setLayoutMode(i),this.spreadView.setBookState(this.bookState),this.spreadView.showSpread(this.currentSpread,"none"),r&&(this.emit("layoutchange",{layoutMode:i}),this.emitPageChange())}async showInitial(){this.covers.frontCover&&this.resolvedMode==="two-page"?(this.bookState="closed-front",this.spreadIndex=0):this.bookState="open",await this.spreadView.showSpread(this.currentSpread,"none"),this.spreadView.setBookState(this.bookState),this.emitPageChange()}async next(){if(!(this.busy||!this.canNext)){if(this.busy=!0,this.bookState==="closed-front"){this.spreads.length===0&&this.covers.backCover&&this.backCoverSpread?(this.bookState="closed-back",await this.spreadView.showSpread(this.backCoverSpread,"next"),this.spreadView.setBookState("closed-back")):(this.bookState="open",this.spreadIndex=0,await this.spreadView.showSpread(this.currentSpread,"next"),this.spreadView.setBookState("open")),this.emitPageChange(),this.busy=!1;return}if(this.bookState==="open"&&this.covers.backCover&&this.backCoverSpread&&this.resolvedMode==="two-page"&&this.spreadIndex>=this.spreads.length-1){this.bookState="closed-back",await this.spreadView.showSpread(this.backCoverSpread,"next"),this.spreadView.setBookState("closed-back"),this.emitPageChange(),this.busy=!1;return}this.spreadIndex+=1,await this.spreadView.showSpread(this.currentSpread,"next"),this.emitPageChange(),this.busy=!1}}async prev(){if(!(this.busy||!this.canPrev)){if(this.busy=!0,this.bookState==="closed-back"){this.spreads.length===0&&this.covers.frontCover&&this.frontCoverSpread?(this.bookState="closed-front",await this.spreadView.showSpread(this.frontCoverSpread,"prev"),this.spreadView.setBookState("closed-front")):(this.bookState="open",this.spreadIndex=Math.max(0,this.spreads.length-1),await this.spreadView.showSpread(this.currentSpread,"prev"),this.spreadView.setBookState("open")),this.emitPageChange(),this.busy=!1;return}if(this.bookState==="open"&&this.covers.frontCover&&this.frontCoverSpread&&this.resolvedMode==="two-page"&&this.spreadIndex<=0){this.bookState="closed-front",await this.spreadView.showSpread(this.frontCoverSpread,"prev"),this.spreadView.setBookState("closed-front"),this.emitPageChange(),this.busy=!1;return}this.spreadIndex-=1,await this.spreadView.showSpread(this.currentSpread,"prev"),this.emitPageChange(),this.busy=!1}}replaceStory(e,t){this.story=e,this.bookState=e.frontCover?"closed-front":"open",this.rebuildFromStory(t)}rebuildFromStory(e){var r,i,n;this.covers={frontCover:!!this.story.frontCover,backCover:!!this.story.backCover},this.rebuildCoverSpreads(),this.spreads=Rt(this.story.pages,this.resolvedMode,this.covers);const t=e??this.currentPageIds[0]??((r=this.story.pages[0])==null?void 0:r.id)??null;this.resolvedMode==="single"?(this.bookState="open",this.spreadIndex=t?Ue(this.spreads,t):0):this.covers.frontCover&&t===((i=this.story.pages[0])==null?void 0:i.id)&&this.bookState==="closed-front"?(this.bookState="closed-front",this.spreadIndex=0):this.covers.backCover&&t===((n=this.story.pages[this.story.pages.length-1])==null?void 0:n.id)&&this.bookState==="closed-back"?(this.bookState="closed-back",this.spreadIndex=Math.max(0,this.spreads.length-1)):(this.bookState="open",this.spreadIndex=t?Ue(this.spreads,t):0,this.spreadIndex<0&&(this.spreadIndex=0)),this.spreads.length===0?(this.spreadIndex=0,this.covers.frontCover?this.bookState="closed-front":this.covers.backCover&&(this.bookState="closed-back")):this.spreadIndex>=this.spreads.length&&(this.spreadIndex=Math.max(0,this.spreads.length-1)),this.busy=!1,this.spreadView.setLayoutMode(this.resolvedMode),this.spreadView.setBookState(this.bookState),this.spreadView.showSpread(this.currentSpread,"none"),this.emitPageChange()}async goTo(e){var a,o;const t=this.covers.frontCover&&((a=this.story.pages[0])==null?void 0:a.id)===e,r=this.covers.backCover&&((o=this.story.pages[this.story.pages.length-1])==null?void 0:o.id)===e;if(this.busy=!0,t&&this.resolvedMode==="two-page"&&this.frontCoverSpread){this.bookState="closed-front",this.spreadIndex=0,await this.spreadView.showSpread(this.frontCoverSpread,"none"),this.spreadView.setBookState("closed-front"),this.emitPageChange(),this.busy=!1;return}if(r&&this.resolvedMode==="two-page"&&this.backCoverSpread){this.bookState="closed-back",this.spreadIndex=Math.max(0,this.spreads.length-1),await this.spreadView.showSpread(this.backCoverSpread,"none"),this.spreadView.setBookState("closed-back"),this.emitPageChange(),this.busy=!1;return}const i=Ue(this.spreads,e);if(i===this.spreadIndex&&this.bookState==="open"){this.busy=!1;return}const n=i>this.spreadIndex?"next":"prev";this.bookState="open",this.spreadIndex=i,this.spreadView.setBookState("open"),await this.spreadView.showSpread(this.currentSpread,n),this.emitPageChange(),this.busy=!1}rebuildCoverSpreads(){this.frontCoverSpread=this.covers.frontCover?Pr(this.story.pages):null,this.backCoverSpread=this.covers.backCover?Mr(this.story.pages):null}emitPageChange(){this.emit("pagechange",{pageIds:this.currentPageIds,index:this.spreadIndex,layoutMode:this.resolvedMode,bookState:this.bookState})}emit(e,t){const r=this.listeners.get(e);if(r)for(const i of r)i(t)}}function Ft(s){return s.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"")}function Ot(s,e){var t;try{const i=(t=new URL(s,"http://local/").pathname.split(".").pop())==null?void 0:t.toLowerCase();if(i&&/^[a-z0-9]{1,8}$/.test(i))return i}catch{}return e}async function Bt(s){const e=await fetch(s);if(!e.ok)throw new Error(`Failed to fetch asset ${s}: ${e.status}`);return new Uint8Array(await e.arrayBuffer())}async function Fr(s,e={}){const t={...e.files??{}},r=structuredClone(s),i=e.baseUrl??"";for(const[a,o]of Object.entries(r.assets)){const l=o.src;if(/^(?:[a-z]+:)?\/\//i.test(l)||l.startsWith("blob:")||l.startsWith("data:")){const c=o.type==="image"?Ot(l,"png"):o.type==="audio"?Ot(l,"mp3"):o.type==="vtt"?"vtt":Ot(l,"bin"),u=Ft(`assets/${a}.${c}`);t[u]||(t[u]=await Bt(l)),o.src=u;continue}const h=Ft(l);if(!t[h]){const c=Ze(i,l);t[h]=await Bt(c)}o.src=h}for(const a of r.fonts){const o=a.src;if(/^(?:[a-z]+:)?\/\//i.test(o)||o.startsWith("blob:")||o.startsWith("data:")){const d=Ft(`fonts/${a.family.replace(/\s+/g,"-")}.${Ot(o,"woff2")}`);t[d]||(t[d]=await Bt(o)),a.src=d}else{const d=Ft(o);t[d]||(t[d]=await Bt(Ze(i,o))),a.src=d}}t["story.json"]=ms(JSON.stringify(r,null,2));const n=cn(t,{level:6});return new Blob([n],{type:"application/zip"})}function Or(s,e){const t=URL.createObjectURL(s),r=document.createElement("a");r.href=t,r.download=e,r.rel="noopener",document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(t)}class lt{cancel(e){}}y(lt,"id","base");const ct=new Map;function Br(s,e){ct.set(s,e)}function In(s){return ct.get(s)}function Vr(){return[...ct.keys()]}function $n(s){return typeof s=="function"&&s.prototype instanceof lt}function As(s){if(s==null||s===""){const e=ct.get("default");if(!e)throw new Error('FlipStyle "default" is not registered');return new e}if(typeof s=="string"){const e=ct.get(s);if(!e){const t=Vr().join(", ")||"(none)";throw new Error(`Unknown flipStyle "${s}". Registered: ${t}`)}return new e}if(s instanceof lt)return s;if($n(s))return new s;throw new Error("flipStyle must be a string id, FlipStyle instance, or FlipStyle subclass")}const zr=400;function Ts(s){return s==null||!Number.isFinite(s)||s<=0?zr:s}class Vt extends lt{play(e){const{bookEl:t,direction:r,durationMs:i}=e,n=r==="next"?"fc-turn-next":"fc-turn-prev";return t.style.setProperty("--fc-flip-duration",`${i}ms`),t.classList.remove("fc-turn-next","fc-turn-prev"),t.offsetWidth,t.classList.add(n),new Promise(a=>{const o=()=>{t.removeEventListener("animationend",l),t.classList.remove("fc-turn-next","fc-turn-prev"),a()},l=d=>{d.target!==e.rightLeaf&&d.target!==e.leftLeaf||o()};t.addEventListener("animationend",l),window.setTimeout(o,i+50)})}cancel(e){e.bookEl.classList.remove("fc-turn-next","fc-turn-prev")}}y(Vt,"id","default"),Br(Vt.id,Vt);const Ls=.035;function jr(s,e){return e&&e.width>0&&e.height>0?{x:Math.max(0,Math.round((e.width-s.width)/2)),y:Math.max(0,Math.round((e.height-s.height)/2))}:{x:Math.max(1,Math.round(s.width*Ls)),y:Math.max(1,Math.round(s.height*Ls))}}function Es(s){return!!(s.hardback&&(s.frontCover||s.backCover))}function Rn(s){const e=s??{},t={left:De(e.x??0),top:De(e.y??0)};return e.width!=null&&(t.width=De(e.width)),e.height!=null&&(t.height=De(e.height)),t}function zt(s,e){const t=Rn(e);s.style.left=t.left,s.style.top=t.top,t.width&&(s.style.width=t.width),t.height&&(s.style.height=t.height),(e==null?void 0:e.horizontalAlign)==="right"?(s.style.left="auto",s.style.right=De(e.x??0)):(e==null?void 0:e.horizontalAlign)==="center"&&(s.style.left="50%",s.style.transform=`${s.style.transform||""} translateX(-50%)`.trim()),(e==null?void 0:e.verticalAlign)==="bottom"?(s.style.top="auto",s.style.bottom=De(e.y??0)):(e==null?void 0:e.verticalAlign)==="center"&&(s.style.top="50%",s.style.transform=`${s.style.transform||""} translateY(-50%)`.trim())}function De(s){return typeof s=="number"?`${s}px`:/^-?\d+(\.\d+)?$/.test(s)?`${s}px`:s}function Fn(s){const e=document.createElement("div");return e.className="fc-block fc-block-area",e.dataset.blockId=s.id,e.dataset.game=s.game,s.requireComplete&&(e.dataset.requireComplete="true"),e.setAttribute("role","group"),e.setAttribute("aria-label",s.ariaLabel??s.game),zt(e,s.layout),e}function On(s,e,t){const r=s+1;return t!=null&&!e&&r>=t?{taps:r,completed:!0,fireComplete:!0}:{taps:r,completed:e,fireComplete:!1}}function Bn(s,e){const t=document.createElement("button");t.type="button",t.className="fc-block fc-block-hotspot",t.dataset.blockId=s.id,t.setAttribute("aria-label",s.ariaLabel??s.id),zt(t,s.layout);let r=0,i=!1;return t.addEventListener("click",n=>{n.stopPropagation(),e(s.onTap??[]);const a=On(r,i,s.requiredTaps);r=a.taps,i=a.completed,a.fireComplete&&e(s.onComplete??[])}),t}function Vn(s,e){var n;const t=document.createElement("div");t.className=`fc-block fc-block-image${s.className?` ${s.className}`:""}`,t.dataset.blockId=s.id,zt(t,s.layout);const r=document.createElement("img");r.alt="",r.draggable=!1,e&&(r.src=e.src);const i=((n=s.layout)==null?void 0:n.fit)??"contain";return r.style.objectFit=i,t.appendChild(r),t}function zn(s,e){const t=document.createElement("div");return t.className="fc-block fc-block-text",t.dataset.blockId=s.id,zt(t,s.layout),t.innerHTML=e,t.querySelectorAll("[id]").forEach(r=>{r.classList.add("fc-cue")}),s.style&&(s.style.fontFamily&&(t.style.fontFamily=s.style.fontFamily),s.style.fontSize&&(t.style.fontSize=s.style.fontSize),s.style.color&&(t.style.color=s.style.color),s.style.textAlign&&(t.style.textAlign=s.style.textAlign),s.style.lineHeight!=null&&(t.style.lineHeight=String(s.style.lineHeight)),s.style.fontWeight&&(t.style.fontWeight=s.style.fontWeight),s.style.fontStyle&&(t.style.fontStyle=s.style.fontStyle)),t}class Ps{constructor(e,t,r){y(this,"element");y(this,"page");y(this,"blank");var i,n;if(this.page=e,this.blank=!e,this.element=document.createElement("article"),this.element.className=`fc-page${this.blank?" fc-page-blank":""}`,this.element.setAttribute("role",this.blank?"presentation":"document"),!e){this.element.dataset.blank="true";return}if(this.element.dataset.pageId=e.id,(i=e.background)!=null&&i.color&&(this.element.style.backgroundColor=e.background.color),(n=e.background)!=null&&n.asset){const a=t.images.get(e.background.asset);a&&(this.element.style.backgroundImage=`url(${JSON.stringify(a.src)})`,this.element.style.backgroundSize="cover",this.element.style.backgroundPosition="center")}for(const a of e.blocks)if(a.type==="text"){const o=a.html??t.html.get(`htmlSrc:${a.id}`)??(a.htmlSrc?t.html.get(a.htmlSrc):void 0)??"";this.element.appendChild(zn(a,o))}else a.type==="image"?this.element.appendChild(Vn(a,t.images.get(a.asset))):a.type==="hotspot"?this.element.appendChild(Bn(a,o=>r.onTapActions(o,this.element))):a.type==="area"&&this.element.appendChild(Fn(a))}destroy(){this.element.remove()}}class jn{constructor(e,t,r,i={}){y(this,"element");y(this,"bookEl");y(this,"hardbackEl");y(this,"hardbackLeft");y(this,"hardbackRight");y(this,"hardbackLeftPage",null);y(this,"hardbackRightPage",null);y(this,"leftSlot");y(this,"rightSlot");y(this,"leftPage",null);y(this,"rightPage",null);y(this,"story");y(this,"assets");y(this,"onTapActions");y(this,"turning",!1);y(this,"bookState","open");y(this,"layoutMode","two-page");y(this,"lastSize",{width:0,height:0});y(this,"stageZoom",{mode:"fit-spread"});y(this,"currentSpread",null);y(this,"flipStyle");y(this,"flipSpeedMs");this.story=e,this.assets=t,this.onTapActions=r,this.flipStyle=As(i.flipStyle),this.flipSpeedMs=Ts(i.flipSpeed),this.element=document.createElement("div"),this.element.className="fc-spread-viewport",this.hardbackEl=document.createElement("div"),this.hardbackEl.className="fc-hardback",this.hardbackEl.setAttribute("aria-hidden","true"),this.hardbackLeft=document.createElement("div"),this.hardbackLeft.className="fc-hardback-board fc-hardback-board-left",this.hardbackRight=document.createElement("div"),this.hardbackRight.className="fc-hardback-board fc-hardback-board-right",this.hardbackEl.append(this.hardbackLeft,this.hardbackRight),this.bookEl=document.createElement("div"),this.bookEl.className="fc-spread",this.leftSlot=document.createElement("div"),this.leftSlot.className="fc-leaf fc-leaf-left",this.rightSlot=document.createElement("div"),this.rightSlot.className="fc-leaf fc-leaf-right",this.bookEl.append(this.leftSlot,this.rightSlot),this.element.append(this.hardbackEl,this.bookEl)}get currentBookState(){return this.bookState}setFlipStyle(e){this.flipStyle=As(e)}setFlipSpeed(e){this.flipSpeedMs=Ts(e)}setStageZoom(e){this.stageZoom=e,this.lastSize.width>0&&this.lastSize.height>0&&this.applyStageTransform(this.lastSize.width,this.lastSize.height,this.currentSpread??void 0)}setLayoutMode(e){this.layoutMode=e,this.element.dataset.layoutMode=e,this.element.classList.toggle("fc-spread-viewport-single",e==="single"),this.element.classList.toggle("fc-spread-viewport-two",e==="two-page")}setBookState(e){this.bookState=e,this.element.dataset.bookState=e,this.syncHardbackBoards(),this.applyStageTransform(this.lastSize.width,this.lastSize.height,this.currentSpread??void 0)}showSpread(e,t="none"){var r,i;return t==="none"||this.turning?((i=(r=this.flipStyle).cancel)==null||i.call(r,{bookEl:this.bookEl,viewportEl:this.element,leftLeaf:this.leftSlot,rightLeaf:this.rightSlot}),this.turning=!1,this.mountSpread(e),Promise.resolve()):(this.turning=!0,this.flipStyle.play({bookEl:this.bookEl,viewportEl:this.element,leftLeaf:this.leftSlot,rightLeaf:this.rightSlot,direction:t,durationMs:this.flipSpeedMs}).then(()=>{this.mountSpread(e),this.turning=!1}).catch(()=>{this.mountSpread(e),this.turning=!1}))}getPageElement(e){var t,r,i,n;return((r=(t=this.leftPage)==null?void 0:t.page)==null?void 0:r.id)===e?this.leftPage.element:((n=(i=this.rightPage)==null?void 0:i.page)==null?void 0:n.id)===e?this.rightPage.element:null}getLeafSlots(){return{left:this.leftSlot,right:this.rightSlot}}getEditableLeaves(e,t){const r=[],i=(n,a,o)=>{a.kind==="page"&&r.push({side:n,pageIndex:a.pageIndex,slot:o})};return this.bookState==="closed-front"||this.bookState==="closed-back"?(i("right",t.right,this.rightSlot),r):e==="two-page"?(i("left",t.left,this.leftSlot),i("right",t.right,this.rightSlot),r):(t.left.kind==="blank"&&t.right.kind==="page"?i("right",t.right,this.rightSlot):t.right.kind==="blank"&&t.left.kind==="page"?i("left",t.left,this.leftSlot):t.left.kind==="page"?i("left",t.left,this.leftSlot):t.right.kind==="page"&&i("right",t.right,this.rightSlot),r)}setPageViewsHidden(e){this.leftPage&&(this.leftPage.element.hidden=e),this.rightPage&&(this.rightPage.element.hidden=e)}remountCurrent(){this.currentSpread&&this.mountSpread(this.currentSpread)}setStory(e){this.story=e,this.syncHardbackBoards(),this.applyStageTransform(this.lastSize.width,this.lastSize.height,this.currentSpread??void 0)}setLoaded(e,t){this.story=e,this.assets=t,this.syncHardbackBoards(),this.applyStageTransform(this.lastSize.width,this.lastSize.height,this.currentSpread??void 0)}getVisiblePageElements(e,t){if(this.bookState==="closed-front"||this.bookState==="closed-back")return this.rightPage&&t.right.kind==="page"?[this.rightPage.element]:[];const r=[];return e==="two-page"?(t.left.kind==="page"&&this.leftPage&&r.push(this.leftPage.element),t.right.kind==="page"&&this.rightPage&&r.push(this.rightPage.element)):t.left.kind==="blank"&&t.right.kind==="page"&&this.rightPage?r.push(this.rightPage.element):t.right.kind==="blank"&&t.left.kind==="page"&&this.leftPage?r.push(this.leftPage.element):t.left.kind==="page"&&this.leftPage?r.push(this.leftPage.element):t.right.kind==="page"&&this.rightPage&&r.push(this.rightPage.element),r}updateStageSize(e,t,r,i){this.layoutMode=r,this.lastSize={width:e,height:t},this.applyStageTransform(e,t,i)}destroy(){var e,t,r,i;(t=(e=this.flipStyle).cancel)==null||t.call(e,{bookEl:this.bookEl,viewportEl:this.element,leftLeaf:this.leftSlot,rightLeaf:this.rightSlot}),this.clearHardbackBoards(),(r=this.leftPage)==null||r.destroy(),(i=this.rightPage)==null||i.destroy(),this.element.remove()}applyStageTransform(e,t,r){if(e<=0||t<=0)return;const{width:i,height:n}=this.story.pageSize,a=this.layoutMode,o=this.bookState,l=Es(this.story),d=l?jr(this.story.pageSize,this.story.coverSize):{x:0,y:0},h=a==="two-page"&&(o==="closed-front"||o==="closed-back"),c=l&&o==="open",u=this.isSoloCover();this.element.classList.toggle("fc-hardback-active",l),this.element.classList.toggle("fc-hardback-open",c),this.element.classList.toggle("fc-hardback-closed",l&&h);let v,w,k,f=0,m=0,A=0;if(l&&h)w=i+2*d.x,k=n+2*d.y,v=this.sizedScale(Math.min(e/w,t/k),i,n,e,t),this.bookEl.style.setProperty("--fc-page-width",`${w}px`),this.bookEl.style.setProperty("--fc-page-height",`${k}px`),this.bookEl.style.width=`${u?w:w*2}px`,this.bookEl.style.height=`${k}px`,f=u?0:-w*v,m=0,A=0,this.hardbackEl.hidden=!0;else if(c){w=(a==="single"?i:i*2)+2*d.x,k=n+2*d.y,v=this.sizedScale(Math.min(e/w,t/k),i,n,e,t),this.bookEl.style.setProperty("--fc-page-width",`${i}px`),this.bookEl.style.setProperty("--fc-page-height",`${n}px`),this.bookEl.style.width=`${i*2}px`,this.bookEl.style.height=`${n}px`,this.hardbackEl.hidden=!1,this.hardbackEl.style.width=`${w}px`,this.hardbackEl.style.height=`${k}px`;const W=a==="single"?(r==null?void 0:r.left.kind)==="blank"?"right":"left":"both";this.sizeHardbackBoards(W,i,n,d.x,d.y),m=d.x,A=d.y,a==="single"&&(r==null?void 0:r.left.kind)==="blank"?f=-i*v:f=0}else w=i*2,k=n,a==="single"||h?v=this.sizedScale(Math.min(e/i,t/n),i,n,e,t):v=this.sizedScale(Math.min(e/w,t/k),i,n,e,t),this.bookEl.style.setProperty("--fc-page-width",`${i}px`),this.bookEl.style.setProperty("--fc-page-height",`${n}px`),this.bookEl.style.width=`${u?i:w}px`,this.bookEl.style.height=`${k}px`,this.hardbackEl.hidden=!0,u?f=0:(h||a==="single"&&r&&r.left.kind==="blank")&&(f=-i*v);this.element.style.setProperty("--fc-hardback-overhang-x",`${d.x}px`),this.element.style.setProperty("--fc-hardback-overhang-y",`${d.y}px`),this.hardbackEl.style.transform=`scale(${v})`,this.hardbackEl.style.transformOrigin="left top",this.bookEl.style.transform=`translateX(${f}px) scale(${v})`,this.bookEl.style.transformOrigin="left top";let g=l&&h?(i+2*d.x)*v:c?(a==="single"?i+2*d.x:i*2+2*d.x)*v:a==="single"||h?i*v:i*2*v,b=l&&(h||c)?(n+2*d.y)*v:n*v,R=0,O=0;this.stageZoom.mode==="fit-page"&&(b>t&&(O=(b-t)/2,b=t),(a==="single"||h||u?i:i*2)*v<=e&&g>e&&(R=(g-e)/2,g=e));const E=(c?m*v:0)-R,I=(c?A*v:0)-O;this.hardbackEl.style.left=`${-R}px`,this.hardbackEl.style.top=`${-O}px`,this.bookEl.style.left=`${E}px`,this.bookEl.style.top=`${I}px`,this.element.style.width=`${g}px`,this.element.style.height=`${b}px`,this.leftSlot.classList.toggle("fc-leaf-dimmed",h&&!u),this.rightSlot.classList.remove("fc-leaf-dimmed"),this.applySoloCover(u)}sizedScale(e,t,r,i,n){return this.stageZoom.mode==="percent"?Math.max(.1,this.stageZoom.percent/100):this.stageZoom.mode==="fit-page"?Math.min(i/t,n/r):e}isSoloCover(){var l,d;if(this.bookState==="closed-front"||this.bookState==="closed-back")return!0;const e=this.currentSpread;if(!e)return!1;const t=e.left.kind==="page",r=e.right.kind==="page";if(t===r)return!1;const i=t&&e.left.kind==="page"?e.left.pageId:e.right.kind==="page"?e.right.pageId:null;if(!i)return!1;const n=this.story.pages,a=!!this.story.frontCover&&((l=n[0])==null?void 0:l.id)===i,o=!!this.story.backCover&&((d=n[n.length-1])==null?void 0:d.id)===i;return a||o}applySoloCover(e){if(this.bookEl.classList.toggle("is-solo-cover",e),!e||!this.currentSpread){this.leftSlot.classList.remove("is-cover-hidden"),this.rightSlot.classList.remove("is-cover-hidden");return}const t=this.currentSpread.left.kind==="page";this.leftSlot.classList.toggle("is-cover-hidden",!t),this.rightSlot.classList.toggle("is-cover-hidden",t)}sizeHardbackBoards(e,t,r,i,n){const a=r+2*n;if(e!=="both"){const o=e==="left";this.hardbackLeft.style.display=o?"":"none",this.hardbackRight.style.display=o?"none":"";const l=o?this.hardbackLeft:this.hardbackRight;l.style.width=`${t+2*i}px`,l.style.height=`${a}px`;return}this.hardbackLeft.style.display="",this.hardbackRight.style.display="",this.hardbackLeft.style.width=`${t+i}px`,this.hardbackLeft.style.height=`${a}px`,this.hardbackRight.style.width=`${t+i}px`,this.hardbackRight.style.height=`${a}px`}syncHardbackBoards(){if(!Es(this.story)||this.bookState!=="open"){this.clearHardbackBoards();return}const e=this.story.pages,t=this.story.frontCover?e[0]:null,r=this.story.backCover?e[e.length-1]:null,i=t??r,n=r??t;this.mountHardbackBoard("left",i),this.mountHardbackBoard("right",n)}mountHardbackBoard(e,t){var o;const r=e==="left"?this.hardbackLeft:this.hardbackRight,i=e==="left"?this.hardbackLeftPage:this.hardbackRightPage;if(i==null||i.destroy(),!t){r.replaceChildren(),r.style.background="",e==="left"?this.hardbackLeftPage=null:this.hardbackRightPage=null;return}const n=(o=t.background)==null?void 0:o.innerColor;if(n){r.style.background=n,r.replaceChildren(),e==="left"?this.hardbackLeftPage=null:this.hardbackRightPage=null;return}r.style.background="";const a=new Ps(t,this.assets,{onTapActions:()=>{}});a.element.classList.add("fc-hardback-page"),r.replaceChildren(a.element),e==="left"?this.hardbackLeftPage=a:this.hardbackRightPage=a}clearHardbackBoards(){var e,t;(e=this.hardbackLeftPage)==null||e.destroy(),(t=this.hardbackRightPage)==null||t.destroy(),this.hardbackLeftPage=null,this.hardbackRightPage=null,this.hardbackLeft.replaceChildren(),this.hardbackRight.replaceChildren(),this.hardbackLeft.style.background="",this.hardbackRight.style.background=""}mountSpread(e){var t,r;this.currentSpread=e,(t=this.leftPage)==null||t.destroy(),(r=this.rightPage)==null||r.destroy(),this.leftSlot.replaceChildren(),this.rightSlot.replaceChildren(),this.leftPage=this.createLeaf(e.left),this.rightPage=this.createLeaf(e.right),this.leftSlot.appendChild(this.leftPage.element),this.rightSlot.appendChild(this.rightPage.element),this.syncHardbackBoards(),this.applyStageTransform(this.lastSize.width,this.lastSize.height,e)}createLeaf(e){if(e.kind==="blank")return new Ps(null,this.assets,{onTapActions:this.onTapActions});const t=this.story.pages[e.pageIndex];return new Ps(t,this.assets,{onTapActions:this.onTapActions})}}function Zr(s,e){const t=s==null?void 0:s.container;if(!(t!=null&&t.send))return;const r=Dn(e.progress);t.send("progress",r),t.send("loading",{stage:e.stage,progress:r,count:e.count,total:e.total,detail:e.detail})}function Zn(s){var e,t;(t=(e=s==null?void 0:s.container)==null?void 0:e.send)==null||t.call(e,"loaded")}function Un(){let s;return{promise:new Promise(t=>{s=t}),resolve:s}}function Dn(s){return Number.isNaN(s)?0:Math.min(1,Math.max(0,s))}function Ur(s,e,t={}){const r=[];let i=!1;const n=(a,o)=>{if(!(a!=null&&a.subscribe))return;const l=a.subscribe(o);typeof l=="function"?r.push(l):l&&typeof l.unsubscribe=="function"&&r.push(()=>{var d;return(d=l.unsubscribe)==null?void 0:d.call(l)})};return s!=null&&s.state&&(n(s.state.pause,a=>{var l;const o=!!a;e.setPaused(o),(l=t.onPause)==null||l.call(t,o)}),n(s.state.soundVolume,a=>e.setVolume("sound",Number(a))),n(s.state.voVolume,a=>e.setVolume("vo",Number(a))),n(s.state.sfxVolume,a=>e.setVolume("sfx",Number(a))),n(s.state.musicVolume,a=>e.setVolume("music",Number(a))),n(s.state.captionsMuted,a=>{var o;i=!!a,(o=t.onCaptionsMuted)==null||o.call(t,i)})),{get captionsMuted(){return i},destroy(){for(const a of r)a()}}}async function Dr(s){var e,t;try{const r=await import("springroll"),i=r.Application??((e=r.default)==null?void 0:e.Application),n=r.ApplicationPlugin??((t=r.default)==null?void 0:t.ApplicationPlugin);if(!i)return null;const a=Un(),o=`fancifully-story-load-${Math.random().toString(36).slice(2,9)}`;if(n&&typeof i.uses=="function"){const d=new n({name:o});d.preload=()=>a.promise,i.uses(d)}else a.resolve();return{app:new i({features:s}),loadGate:a,owned:!0}}catch{return null}}function Hr(s){var e;return!((e=s==null?void 0:s.state)!=null&&e.ready)||s.state.ready.value===!0?Promise.resolve():new Promise(t=>{const r=s.state.ready.subscribe(i=>{i&&(typeof r=="function"&&r(),t())})})}const Hn=Object.freeze({left:0,top:0,width:16,height:16}),jt=Object.freeze({rotate:0,vFlip:!1,hFlip:!1}),Wr=Object.freeze({...Hn,...jt}),Wn=Object.freeze({...Wr,body:"",hidden:!1}),qn=Object.freeze({width:null,height:null}),Gn=Object.freeze({...qn,...jt});function Yn(s,e){const t={};!s.hFlip!=!e.hFlip&&(t.hFlip=!0),!s.vFlip!=!e.vFlip&&(t.vFlip=!0);const r=((s.rotate||0)+(e.rotate||0))%4;return r&&(t.rotate=r),t}function qr(s,e){const t=Yn(s,e);for(const r in Wn)r in jt?r in s&&!(r in t)&&(t[r]=jt[r]):r in e?t[r]=e[r]:r in s&&(t[r]=s[r]);return t}function Jn(s,e){const t=s.icons,r=s.aliases||Object.create(null),i=Object.create(null);function n(a){if(t[a])return i[a]=[];if(!(a in i)){i[a]=null;const o=r[a]&&r[a].parent,l=o&&n(o);l&&(i[a]=[o].concat(l))}return i[a]}return(e||Object.keys(t).concat(Object.keys(r))).forEach(n),i}function Gr(s,e,t){const r=s.icons,i=s.aliases||Object.create(null);let n={};function a(o){n=qr(r[o]||i[o],n)}return a(e),t.forEach(a),qr(s,n)}function Xn(s,e){if(s.icons[e])return Gr(s,e,[]);const t=Jn(s,[e])[e];return t?Gr(s,e,t):null}const Kn=/(-?[0-9.]*[0-9]+[0-9.]*)/g,Qn=/^-?[0-9.]*[0-9]+[0-9.]*$/g;function Yr(s,e,t){if(e===1)return s;if(t=t||100,typeof s=="number")return Math.ceil(s*e*t)/t;if(typeof s!="string")return s;const r=s.split(Kn);if(r===null||!r.length)return s;const i=[];let n=r.shift(),a=Qn.test(n);for(;;){if(a){const o=parseFloat(n);isNaN(o)?i.push(n):i.push(Math.ceil(o*e*t)/t)}else i.push(n);if(n=r.shift(),n===void 0)return i.join("");a=!a}}function ea(s,e="defs"){let t="";const r=s.indexOf("<"+e);for(;r>=0;){const i=s.indexOf(">",r),n=s.indexOf("</"+e);if(i===-1||n===-1)break;const a=s.indexOf(">",n);if(a===-1)break;t+=s.slice(i+1,n).trim(),s=s.slice(0,r).trim()+s.slice(a+1)}return{defs:t,content:s}}function ta(s,e){return s?"<defs>"+s+"</defs>"+e:e}function sa(s,e,t){const r=ea(s);return ta(r.defs,e+r.content+t)}const ra=s=>s==="unset"||s==="undefined"||s==="none";function ia(s,e){const t={...Wr,...s},r={...Gn,...e},i={left:t.left,top:t.top,width:t.width,height:t.height};let n=t.body;[t,r].forEach(k=>{const f=[],m=k.hFlip,A=k.vFlip;let g=k.rotate;m?A?g+=2:(f.push("translate("+(i.width+i.left).toString()+" "+(0-i.top).toString()+")"),f.push("scale(-1 1)"),i.top=i.left=0):A&&(f.push("translate("+(0-i.left).toString()+" "+(i.height+i.top).toString()+")"),f.push("scale(1 -1)"),i.top=i.left=0);let b;switch(g<0&&(g-=Math.floor(g/4)*4),g=g%4,g){case 1:b=i.height/2+i.top,f.unshift("rotate(90 "+b.toString()+" "+b.toString()+")");break;case 2:f.unshift("rotate(180 "+(i.width/2+i.left).toString()+" "+(i.height/2+i.top).toString()+")");break;case 3:b=i.width/2+i.left,f.unshift("rotate(-90 "+b.toString()+" "+b.toString()+")")}g%2===1&&(i.left!==i.top&&(b=i.left,i.left=i.top,i.top=b),i.width!==i.height&&(b=i.width,i.width=i.height,i.height=b)),f.length&&(n=sa(n,'<g transform="'+f.join(" ")+'">',"</g>"))});const a=r.width,o=r.height,l=i.width,d=i.height;let h,c;a===null?(c=o===null?"1em":o==="auto"?d:o,h=Yr(c,l/d)):(h=a==="auto"?l:a,c=o===null?Yr(h,d/l):o==="auto"?d:o);const u={},v=(k,f)=>{ra(f)||(u[k]=f.toString())};v("width",h),v("height",c);const w=[i.left,i.top,l,d];return u.viewBox=w.join(" "),{attributes:u,viewBox:w,body:n}}function na(s,e){let t=s.indexOf("xlink:")===-1?"":' xmlns:xlink="http://www.w3.org/1999/xlink"';for(const r in e)t+=" "+r+'="'+e[r]+'"';return'<svg xmlns="http://www.w3.org/2000/svg"'+t+">"+s+"</svg>"}const aa={prefix:"mdi",icons:{"chevron-left":{body:'<path fill="currentColor" d="M15.41 16.58L10.83 12l4.58-4.59L14 6l-6 6l6 6z"/>'},"chevron-right":{body:'<path fill="currentColor" d="M8.59 16.58L13.17 12L8.59 7.41L10 6l6 6l-6 6z"/>'},"book-open-page-variant":{body:'<path fill="currentColor" d="m19 2l-5 4.5v11l5-4.5zM6.5 5C4.55 5 2.45 5.4 1 6.5v14.66c0 .25.25.5.5.5c.1 0 .15-.07.25-.07c1.35-.65 3.3-1.09 4.75-1.09c1.95 0 4.05.4 5.5 1.5c1.35-.85 3.8-1.5 5.5-1.5c1.65 0 3.35.31 4.75 1.06c.1.05.15.03.25.03c.25 0 .5-.25.5-.5V6.5c-.6-.45-1.25-.75-2-1V19c-1.1-.35-2.3-.5-3.5-.5c-1.7 0-4.15.65-5.5 1.5V6.5C10.55 5.4 8.45 5 6.5 5"/>'},pencil:{body:'<path fill="currentColor" d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83l3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75z"/>'},eye:{body:'<path fill="currentColor" d="M12 9a3 3 0 0 0-3 3a3 3 0 0 0 3 3a3 3 0 0 0 3-3a3 3 0 0 0-3-3m0 8a5 5 0 0 1-5-5a5 5 0 0 1 5-5a5 5 0 0 1 5 5a5 5 0 0 1-5 5m0-12.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5"/>'},download:{body:'<path fill="currentColor" d="M5 20h14v-2H5m14-9h-4V3H9v6H5l7 7z"/>'},cog:{body:'<path fill="currentColor" d="M12 15.5A3.5 3.5 0 0 1 8.5 12A3.5 3.5 0 0 1 12 8.5a3.5 3.5 0 0 1 3.5 3.5a3.5 3.5 0 0 1-3.5 3.5m7.43-2.53c.04-.32.07-.64.07-.97s-.03-.66-.07-1l2.11-1.63c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.31-.61-.22l-2.49 1c-.52-.39-1.06-.73-1.69-.98l-.37-2.65A.506.506 0 0 0 14 2h-4c-.25 0-.46.18-.5.42l-.37 2.65c-.63.25-1.17.59-1.69.98l-2.49-1c-.22-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64L4.57 11c-.04.34-.07.67-.07 1s.03.65.07.97l-2.11 1.66c-.19.15-.25.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1.01c.52.4 1.06.74 1.69.99l.37 2.65c.04.24.25.42.5.42h4c.25 0 .46-.18.5-.42l.37-2.65c.63-.26 1.17-.59 1.69-.99l2.49 1.01c.22.08.49 0 .61-.22l2-3.46c.12-.22.07-.49-.12-.64z"/>'},"file-plus":{body:'<path fill="currentColor" d="M14 2H6c-1.11 0-2 .89-2 2v16c0 1.11.89 2 2 2h7.81c-.53-.91-.81-1.95-.81-3c0-3.31 2.69-6 6-6c.34 0 .67.03 1 .08V8zm-1 7V3.5L18.5 9zm10 11h-3v3h-2v-3h-3v-2h3v-3h2v3h3z"/>'},"file-remove":{body:'<path fill="currentColor" d="M21.12 22.54L19 20.41l-2.12 2.13l-1.41-1.42L17.59 19l-2.12-2.12l1.41-1.41L19 17.59l2.12-2.12l1.42 1.41L20.41 19l2.13 2.12zM14 2H6c-1.11 0-2 .89-2 2v16c0 1.11.89 2 2 2h7.81c-.53-.91-.81-1.95-.81-3c0-3.31 2.69-6 6-6c.34 0 .67.03 1 .08V8zm-1 7V3.5L18.5 9z"/>'},book:{body:'<path fill="currentColor" d="M18 22a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2h-6v7L9.5 7.5L7 9V2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2z"/>'},"book-open-outline":{body:'<path fill="currentColor" d="M21 4H3a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2h18a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2M3 19V6h8v13zm18 0h-8V6h8zm-7-9.5h6V11h-6zm0 2.5h6v1.5h-6zm0 2.5h6V16h-6z"/>'},"book-variant":{body:'<path fill="currentColor" d="M6 4h5v8l-2.5-1.5L6 12M18 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2"/>'},"folder-open":{body:'<path fill="currentColor" d="M19 20H4a2 2 0 0 1-2-2V6c0-1.11.89-2 2-2h6l2 2h7a2 2 0 0 1 2 2H4v10l2.14-8h17.07l-2.28 8.5c-.23.87-1.01 1.5-1.93 1.5"/>'},"drag-vertical":{body:'<path fill="currentColor" d="M9 3h2v2H9zm4 0h2v2h-2zM9 7h2v2H9zm4 0h2v2h-2zm-4 4h2v2H9zm4 0h2v2h-2zm-4 4h2v2H9zm4 0h2v2h-2zm-4 4h2v2H9zm4 0h2v2h-2z"/>'},close:{body:'<path fill="currentColor" d="M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12z"/>'},plus:{body:'<path fill="currentColor" d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6z"/>'}},lastModified:1737398331,width:24,height:24};function oa(s,e={}){const t=Xn(aa,s);if(!t)throw new Error(`Unknown MDI icon in subset: ${s}`);const r=e.size??"1.15rem",i=ia(t,{height:r,width:r}),n=document.createElement("span");return n.className=e.className??"fc-icon",n.setAttribute("aria-hidden","true"),n.innerHTML=na(i.body,i.attributes),n}function Ms(s,e){const t=oa(e.icon),r=document.createElement("span");r.className=e.iconOnly?"fc-btn-label fc-btn-label--sr":"fc-btn-label",r.textContent=e.label,s.title=e.label,s.setAttribute("aria-label",e.label),s.replaceChildren(t,r)}const la={sound:!0,soundVolume:!0,vo:!0,voVolume:!0,sfx:!0,sfxVolume:!0,music:!0,musicVolume:!0,captions:!0};class Ns{constructor(e,t,r,i,n={},a,o,l,d,h){y(this,"element");y(this,"root");y(this,"stage");y(this,"chrome");y(this,"captionsEl");y(this,"loaded");y(this,"spreadView");y(this,"pager");y(this,"bus",new ye);y(this,"readAloud");y(this,"springroll");y(this,"bindings",null);y(this,"sfxAudio");y(this,"unbindSwipe",null);y(this,"resizeObserver",null);y(this,"listeners",new Map);y(this,"destroyed",!1);y(this,"btnPrev");y(this,"btnRead");y(this,"btnNext");y(this,"chromeHiddenByOptions",!1);y(this,"extraFiles",{});y(this,"defaultFontFamily",null);y(this,"navLocked",!1);y(this,"pageGames",new Map);y(this,"areaSessions",[]);var w,k,f,m,A,g;if(this.root=e,this.loaded=t,this.springroll=r,this.chromeHiddenByOptions=!!n.hidden,h)for(const[b,R]of Object.entries(h))this.pageGames.set(b,R);this.element=document.createElement("div"),this.element.className="fc-root",this.element.tabIndex=0,this.stage=document.createElement("div"),this.stage.className="fc-stage",this.captionsEl=document.createElement("div"),this.captionsEl.className="fc-captions",this.captionsEl.setAttribute("aria-live","polite");const c={prev:((w=n.labels)==null?void 0:w.prev)??"Prev",read:((k=n.labels)==null?void 0:k.read)??"Read",next:((f=n.labels)==null?void 0:f.next)??"Next"},u={prev:((m=n.ariaLabels)==null?void 0:m.prev)??"Previous page",read:((A=n.ariaLabels)==null?void 0:A.read)??"Read aloud",next:((g=n.ariaLabels)==null?void 0:g.next)??"Next page"};this.chrome=document.createElement("div"),this.chrome.className=["fc-chrome",n.className].filter(Boolean).join(" "),this.chrome.hidden=!!n.hidden,this.btnPrev=document.createElement("button"),this.btnPrev.type="button",this.btnPrev.className="fc-btn fc-btn-prev",this.btnPrev.setAttribute("aria-label",u.prev),Ms(this.btnPrev,{icon:"chevron-left",label:c.prev,iconOnly:!0}),this.btnRead=document.createElement("button"),this.btnRead.type="button",this.btnRead.className="fc-btn fc-btn-read",this.btnRead.setAttribute("aria-label",u.read),Ms(this.btnRead,{icon:"book-open-page-variant",label:c.read,iconOnly:!0}),this.btnNext=document.createElement("button"),this.btnNext.type="button",this.btnNext.className="fc-btn fc-btn-next",this.btnNext.setAttribute("aria-label",u.next),Ms(this.btnNext,{icon:"chevron-right",label:c.next,iconOnly:!0});const v=document.createElement("div");v.className="fc-nav-peapod",v.append(this.btnPrev,this.btnRead,this.btnNext),this.chrome.append(v),this.spreadView=new jn(t.story,t.assets,(b,R)=>this.handleTapActions(b,R),{flipStyle:a??"default",flipSpeed:o}),this.pager=new Nn(t.story,this.spreadView,{mode:l,singleBreakpoint:d}),this.readAloud=new ei(this.bus),this.sfxAudio=new Audio,this.bus.register(this.sfxAudio,"sfx"),this.stage.appendChild(this.spreadView.element),this.element.append(this.stage,this.captionsEl,this.chrome),this.root.appendChild(this.element),this.wireChrome(),this.wirePager(i),this.wireSpringroll(),this.wireResize(),this.unbindSwipe=ni(this.stage,{onSwipeLeft:()=>{this.isReaderNavBlocked()||this.next()},onSwipeRight:()=>{this.isReaderNavBlocked()||this.prev()}}),this.element.addEventListener("keydown",b=>{this.isReaderNavBlocked()||(b.key==="ArrowRight"?(b.preventDefault(),this.next()):b.key==="ArrowLeft"?(b.preventDefault(),this.prev()):b.key===" "&&(b.preventDefault(),this.playReadAloud()))}),this.readAloud.onCaption(b=>{this.captionsEl.textContent=b??"",this.captionsEl.hidden=!b})}static async create(e,t){const r={...la,...t.features};let i=t.springroll??null,n=null;if(!i){const h=await Dr(r);h&&(i=h.app,n=h.loadGate,da(i))}const a=[];t.onProgress&&a.push(t.onProgress);const o=h=>{Zr(i,h);for(const c of a)c(h)};o({stage:"fetch",progress:0,detail:"start"});const l=await It(t.story,{baseUrl:t.baseUrl,name:t.storyName,onProgress:o});n==null||n.resolve(),await Hr(i);const d=new Ns(e,l,i,t.autoPlayReadAloud??!1,t.chrome??{},t.flipStyle,t.flipSpeed,t.layoutMode,t.singleBreakpoint,t.pageGames);return d.pager.updateLayout(e.clientWidth||window.innerWidth,e.clientHeight||window.innerHeight,!1),d.layoutStage(),await d.pager.showInitial(),await d.syncPageGames(),d.syncChromeNavState(),d.emit("ready",{story:l.story}),d}get story(){return this.loaded.story}get assets(){return this.loaded.assets}get baseUrl(){return this.loaded.baseUrl}get blobUrls(){return this.loaded.blobUrls}get layoutMode(){return this.pager.layoutMode}get layoutPreference(){return this.pager.layoutPreference}get pageIds(){return this.pager.currentPageIds}get spreadIndex(){return this.pager.currentSpread.index}get isNavLocked(){return this.navLocked}isReaderNavBlocked(){return this.navLocked||this.hasIncompleteAreaGate()}hasIncompleteAreaGate(){return js(this.areaSessions)}getDefaultFontFamily(){return this.defaultFontFamily}setDefaultFontFamily(e){this.defaultFontFamily=e}getExtraFiles(){return this.extraFiles}putExtraFile(e,t){this.extraFiles[e]=t}setNavLocked(e){this.navLocked=e,e?(this.readAloud.stop(),this.chrome.hidden=!0):(this.chrome.hidden=this.chromeHiddenByOptions,this.syncChromeNavState())}getEditableLeaves(){const e=this.pager.currentSpread;return this.spreadView.getEditableLeaves(this.pager.layoutMode,e).map(t=>{var r;return{side:t.side,pageIndex:t.pageIndex,pageId:((r=this.loaded.story.pages[t.pageIndex])==null?void 0:r.id)??"",slot:t.slot}})}getSpreadElement(){return this.spreadView.bookEl}get bookState(){return this.pager.currentBookState}getSpreadPages(){const e=this.pager.currentSpread,t=this.loaded.story.pages;return{left:e.left.kind==="page"?t[e.left.pageIndex]??null:null,right:e.right.kind==="page"?t[e.right.pageIndex]??null:null}}setPageViewsHidden(e){this.spreadView.setPageViewsHidden(e)}remountCurrent(){this.spreadView.remountCurrent(),this.layoutStage(),this.syncPageGames()}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{var r;return(r=this.listeners.get(e))==null?void 0:r.delete(t)}}next(){return this.isReaderNavBlocked()?Promise.resolve():this.navigate(()=>this.pager.next())}prev(){return this.isReaderNavBlocked()?Promise.resolve():this.navigate(()=>this.pager.prev())}goTo(e){return this.isReaderNavBlocked()?Promise.resolve():this.navigate(()=>this.pager.goTo(e))}setStageZoom(e){this.spreadView.setStageZoom(e),this.stage.classList.toggle("fc-stage-scroll",e.mode==="percent"),this.stage.classList.toggle("fc-stage-fit-page",e.mode==="fit-page"),this.layoutStage()}setLayoutMode(e){this.pager.setLayoutMode(e,this.root.clientWidth||window.innerWidth,this.root.clientHeight||window.innerHeight),this.layoutStage(),this.syncChromeNavState(),this.emit("layoutchange",{layoutMode:this.pager.layoutMode})}setFlipStyle(e){this.spreadView.setFlipStyle(e)}setFlipSpeed(e){this.spreadView.setFlipSpeed(e)}playReadAloud(){if(this.navLocked)return Promise.resolve();const e=this.buildReadAloudClips();return this.readAloud.playSequence(e)}pause(){this.readAloud.pause(),this.bus.setPaused(!0)}resume(){this.bus.setPaused(!1),this.readAloud.resume()}async replaceStory(e,t){var n;this.readAloud.stop();const r=this.loaded,i=await It(e,{name:t??(e instanceof File?e.name:void 0)});Cs(r),this.loaded=i,this.extraFiles={},this.defaultFontFamily=null,this.spreadView.setLoaded(i.story,i.assets),this.pager.replaceStory(i.story,((n=i.story.pages[0])==null?void 0:n.id)??null),this.layoutStage(),await this.syncPageGames(),this.syncChromeNavState(),this.emit("ready",{story:i.story})}async openFanciFile(e){if(!Ht(e))throw new Error(`Expected a .fanci file, got ${e.name}`);await this.replaceStory(e,e.name)}async updatePage(e){const t=this.loaded.story.pages.findIndex(r=>r.id===e.id);t<0||(this.loaded.story.pages[t]=e,this.spreadView.setStory(this.loaded.story),this.spreadView.remountCurrent(),this.layoutStage())}async setPages(e,t){this.loaded.story.pages=e,this.spreadView.setStory(this.loaded.story),this.pager.rebuildFromStory(t??this.pager.currentPageIds[0]??null),this.layoutStage(),this.syncChromeNavState()}async addPage(){const e=ca(this.loaded.story);return this.loaded.story.pages.push(e),this.spreadView.setStory(this.loaded.story),this.pager.rebuildFromStory(e.id),this.layoutStage(),this.syncChromeNavState(),e}async removePage(e){var i;if(this.loaded.story.pages.length<=1)return;const t=this.loaded.story.pages.findIndex(n=>n.id===e);if(t<0)return;this.loaded.story.pages.splice(t,1);const r=((i=this.loaded.story.pages[Math.min(t,this.loaded.story.pages.length-1)])==null?void 0:i.id)??null;this.spreadView.setStory(this.loaded.story),this.pager.rebuildFromStory(r),this.layoutStage(),this.syncChromeNavState()}async reorderPages(e,t){const r=this.loaded.story.pages;if(e<0||t<0||e>=r.length||t>=r.length||e===t)return;const[i]=r.splice(e,1);i&&(r.splice(t,0,i),this.spreadView.setStory(this.loaded.story),this.pager.rebuildFromStory(i.id),this.layoutStage(),this.syncChromeNavState())}async setFrontCover(e){this.loaded.story.frontCover=e,this.spreadView.setStory(this.loaded.story),this.pager.rebuildFromStory(this.pager.currentPageIds[0]??null),this.layoutStage(),this.syncChromeNavState()}async setBackCover(e){this.loaded.story.backCover=e,this.spreadView.setStory(this.loaded.story),this.pager.rebuildFromStory(this.pager.currentPageIds[0]??null),this.layoutStage(),this.syncChromeNavState()}async setHardback(e){this.loaded.story.hardback=e,this.spreadView.setStory(this.loaded.story),this.layoutStage()}applyFontToAllText(e){this.defaultFontFamily=e;for(const t of this.loaded.story.pages)for(const r of t.blocks)r.type==="text"&&(r.style={...r.style,fontFamily:e})}async packToBlob(){return Fr(this.loaded.story,{baseUrl:this.loaded.baseUrl,files:{...this.extraFiles}})}async downloadFanci(e){const t=e??`${this.loaded.story.id||"story"}.fanci`,r=await this.packToBlob();Or(r,t.endsWith(".fanci")?t:`${t}.fanci`)}destroy(){var e,t,r;this.destroyed||(this.destroyed=!0,this.teardownPageGames(),this.readAloud.destroy(),this.bus.unregister(this.sfxAudio),(e=this.bindings)==null||e.destroy(),(t=this.unbindSwipe)==null||t.call(this),(r=this.resizeObserver)==null||r.disconnect(),this.spreadView.destroy(),this.element.remove(),this.listeners.clear(),Cs(this.loaded))}async navigate(e){this.readAloud.stop(),await e(),this.layoutStage()}wireChrome(){this.btnPrev.addEventListener("click",()=>void this.prev()),this.btnNext.addEventListener("click",()=>void this.next()),this.btnRead.addEventListener("click",()=>void this.playReadAloud())}syncChromeNavState(){const e=this.hasIncompleteAreaGate(),t=this.pager.canPrev&&!e&&!this.navLocked,r=this.pager.canNext&&!e&&!this.navLocked;this.btnPrev.disabled=!t,this.btnNext.disabled=!r,this.btnPrev.classList.toggle("is-disabled",!t),this.btnNext.classList.toggle("is-disabled",!r),this.btnPrev.setAttribute("aria-disabled",String(!t)),this.btnNext.setAttribute("aria-disabled",String(!r))}wirePager(e){this.pager.on("pagechange",t=>{this.syncPageGames().then(()=>{this.syncChromeNavState(),this.emit("pagechange",t),e&&!this.navLocked&&this.playReadAloud()})}),this.pager.on("layoutchange",t=>{this.readAloud.stop(),this.layoutStage(),this.syncPageGames().then(()=>{this.syncChromeNavState(),this.emit("layoutchange",t)})})}wireSpringroll(){this.bindings=Ur(this.springroll,this.bus,{onCaptionsMuted:e=>this.readAloud.setCaptionsMuted(e),onPause:e=>{e?this.readAloud.pause():this.readAloud.resume()}})}wireResize(){const e=()=>{this.pager.updateLayout(this.root.clientWidth||window.innerWidth,this.root.clientHeight||window.innerHeight),this.layoutStage()};typeof ResizeObserver<"u"?(this.resizeObserver=new ResizeObserver(e),this.resizeObserver.observe(this.root)):window.addEventListener("resize",e)}layoutStage(){const e=this.stage.clientWidth||this.root.clientWidth||window.innerWidth;let t=this.stage.clientHeight||Math.max(320,this.root.clientHeight-64);if(this.spreadView.updateStageSize(e,t,this.pager.layoutMode,this.pager.currentSpread),this.stage.classList.contains("fc-stage-fit-page")){const r=this.stage.clientHeight;r>0&&r!==t&&(t=r,this.spreadView.updateStageSize(e,t,this.pager.layoutMode,this.pager.currentSpread))}}buildReadAloudClips(){const e=this.pager.layoutMode,t=this.pager.currentSpread,r=this.pager.currentBookState;let i=[t.left,t.right];r==="closed-front"?i=[t.left]:r==="closed-back"?i=[t.right]:e==="single"&&(i=t.left.kind==="blank"?[t.right]:t.right.kind==="blank"?[t.left]:[t.left]);const n=[];for(const a of i){if(a.kind!=="page")continue;const o=this.loaded.story.pages[a.pageIndex];if(!o.readAloud)continue;const l=this.loaded.assets.audioUrls.get(o.readAloud.audio);if(!l)continue;const d=this.resolveCues(o.readAloud.cues),h=this.spreadView.getPageElement(o.id);n.push({url:l.url,channel:l.channel,cues:d,root:h})}return n}resolveCues(e){return e?Array.isArray(e)?e:this.loaded.assets.cues.get(e)??[]:[]}handleTapActions(e,t){if(!this.navLocked)for(const r of e)if("play"in r){const i=this.loaded.assets.audioUrls.get(r.play);if(!i)continue;this.sfxAudio.src=i.url,this.bus.applyTo(this.sfxAudio,i.channel),this.sfxAudio.play().catch(()=>{})}else"toggleClass"in r?this.applyClassAction(t,r.toggleClass,"toggle"):"addClass"in r?this.applyClassAction(t,r.addClass,"add"):"removeClass"in r?this.applyClassAction(t,r.removeClass,"remove"):"replayClass"in r&&this.applyClassAction(t,r.replayClass,"replay")}applyClassAction(e,t,r){const i=e.querySelector(`[data-block-id="${t.target}"]`);if(i){if(r==="toggle"){i.classList.toggle(t.className);return}if(r==="add"){i.classList.add(t.className);return}if(r==="remove"){i.classList.remove(t.className);return}i.classList.remove(t.className),requestAnimationFrame(()=>{i.classList.add(t.className)})}}resolvePageGame(e){return this.pageGames.get(e)??zs(e)}teardownPageGames(){var e;for(const t of this.areaSessions){t.abort.abort();try{(e=t.handle)==null||e.destroy()}catch{}}this.areaSessions=[]}async syncPageGames(){if(this.teardownPageGames(),this.destroyed)return;const e=this.loaded.story.pages,t=this.pager.currentPageIds;for(const r of t){const i=e.find(a=>a.id===r),n=this.spreadView.getPageElement(r);if(!(!i||!n))for(const a of i.blocks){if(a.type!=="area")continue;const o=[...n.querySelectorAll(".fc-block-area")].find(u=>u.dataset.blockId===a.id);if(!o)continue;const l=this.resolvePageGame(a.game),d=new AbortController,h={blockId:a.id,pageId:i.id,game:a.game,requireComplete:!!a.requireComplete,complete:!a.requireComplete,abort:d,handle:null};if(this.areaSessions.push(h),!l){o.replaceChildren();const u=document.createElement("p");u.className="fc-area-missing",u.textContent=`Missing page game: ${a.game}`,o.append(u);continue}const c=a;try{const u=await l({el:o,page:i,block:c,story:this.loaded.story,assets:this.loaded.assets,signal:d.signal,onComplete:()=>{h.complete||(h.complete=!0,this.syncChromeNavState(),this.emit("areacomplete",{pageId:h.pageId,blockId:h.blockId,game:h.game}))}});d.signal.aborted?u==null||u.destroy():u&&(h.handle=u)}catch(u){console.error(`Page game "${a.game}" failed to mount`,u)}}}this.syncChromeNavState()}emit(e,t){const r=this.listeners.get(e);if(r)for(const i of r)i(t)}}function ca(s){let e=s.pages.length+1,t=`page-${e}`;const r=new Set(s.pages.map(i=>i.id));for(;r.has(t);)e+=1,t=`page-${e}`;return{id:t,background:{color:"#faf6ef"},blocks:[]}}function da(s){var t,r,i,n,a,o;const e=s.state;e&&((t=e.pause)==null||t.subscribe(()=>{}),(r=e.soundVolume)==null||r.subscribe(()=>{}),(i=e.voVolume)==null||i.subscribe(()=>{}),(n=e.sfxVolume)==null||n.subscribe(()=>{}),(a=e.musicVolume)==null||a.subscribe(()=>{}),(o=e.captionsMuted)==null||o.subscribe(()=>{}))}function He(s,e=0,t=0){if(s==null)return e;if(typeof s=="number")return Number.isFinite(s)?s:e;const r=s.trim();if(/^-?\d+(\.\d+)?$/.test(r)){const a=Number(r);return Number.isFinite(a)?a:e}const i=r.match(/^(-?\d+(?:\.\d+)?)%$/);if(i){const a=Number(i[1]);return!Number.isFinite(a)||!(t>0)?e:a/100*t}const n=r.match(/^(-?\d+(?:\.\d+)?)px$/i);if(n){const a=Number(n[1]);return Number.isFinite(a)?a:e}return e}function Fe(s,e){const{width:t,height:r}=e;return{x:Math.round(He(s==null?void 0:s.x,0,t)),y:Math.round(He(s==null?void 0:s.y,0,r)),width:Math.round(He(s==null?void 0:s.width,t,t)),height:Math.round(He(s==null?void 0:s.height,r*.25,r))}}function Zt(s){return typeof s=="string"&&/%$/.test(s.trim())}function dt(s,e){if(!(e>0))return"0%";const t=s/e*100,r=Math.round(t*10)/10;return Number.isInteger(r)?`${r}%`:`${r}%`}function ht(s,e,t,r,i,n,a={}){const o=Fe(i,n),l=Math.abs(o.x-s)<=1&&Math.abs(o.y-e)<=1&&Math.abs(o.width-t)<=1,d=Math.abs(o.height-r)<=1;if(l&&(a.preserveHeight||d)&&i)return{...i};const h=Zt(i==null?void 0:i.x)||Zt(i==null?void 0:i.y)||Zt(i==null?void 0:i.width)||Zt(i==null?void 0:i.height),c=a.preserveHeight&&(i==null?void 0:i.height)!=null?i.height:r;return h?{...i,x:dt(s,n.width),y:dt(e,n.height),width:dt(t,n.width),height:typeof c=="string"||typeof c=="number"?typeof c=="number"?dt(c,n.height):c:dt(r,n.height)}:{...i,x:s,y:e,width:t,height:typeof c=="number"?Math.round(c):c}}function Jr(s,e,t=1.35){if(s==null)return t;if(typeof s=="number")return s>0?s:t;const r=s.trim();if(/^-?\d+(\.\d+)?$/.test(r)){const a=Number(r);return a>0?a:t}const i=r.match(/^(-?\d+(?:\.\d+)?)%$/);if(i){const a=Number(i[1])/100;return a>0?a:t}const n=r.match(/^(-?\d+(?:\.\d+)?)px$/i);if(n&&e>0){const a=Number(n[1])/e;return a>0?a:t}return t}const ha=1;function ua(s,e,t){if(e.width===t.width&&e.height===t.height)return;const r=t.width/e.width,i=t.height/e.height;for(const n of s){const a=Fe(n.layout,e);n.layout={...n.layout,x:Math.round(a.x*r),y:Math.round(a.y*i),width:Math.max(1,Math.round(a.width*r)),height:Math.max(1,Math.round(a.height*i))}}}function Is(s){return typeof DOMParser>"u"?s.replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim():(new DOMParser().parseFromString(s,"text/html").body.textContent??"").replace(/\u00a0/g," ")}function Xr(s){return`<p>${s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/\n/g,"<br/>")}</p>`}function Kr(s){return s.type==="text"||s.type==="image"||s.type==="hotspot"||s.type==="area"}function $s(s,e,t,r,i){var h;const n=(i==null?void 0:i.syncHotspots)===!0,a=(i==null?void 0:i.syncAreas)===!0,o=new Map;for(const c of e.blocks)c.type!=="hotspot"&&c.type!=="area"&&o.set(c.id,{...c});const l=[];for(const c of s){const u=c.blockId,v=c.blockType;if(!u||!v)continue;const w=o.get(u),k=Math.round(c.left??0),f=Math.round(c.top??0);if(v==="text"){const m=Math.round(c.width??0),A=Math.round(c.height??0),g=c.text??"",b=w&&w.type==="text"?w:void 0,R=b?Is(b.html??""):"",O=b&&R===g&&b.html?b.html:Xr(g),E=b==null?void 0:b.style,I={fontFamily:c.fontFamily||(E==null?void 0:E.fontFamily),fontSize:c.fontSize!=null?`${Math.round(c.fontSize)}px`:E==null?void 0:E.fontSize,color:typeof c.fill=="string"?c.fill:E==null?void 0:E.color,textAlign:c.textAlign??(E==null?void 0:E.textAlign),lineHeight:c.lineHeight??(E==null?void 0:E.lineHeight),fontWeight:c.fontWeight||(E==null?void 0:E.fontWeight),fontStyle:c.fontStyle||(E==null?void 0:E.fontStyle)};l.push({id:u,type:"text",layout:ht(k,f,m,A,b==null?void 0:b.layout,t,{preserveHeight:!0}),html:O,style:I,htmlSrc:b==null?void 0:b.htmlSrc})}else if(v==="image"){const m=Math.round((c.width??0)*(c.scaleX??1)),A=Math.round((c.height??0)*(c.scaleY??1)),g=c.assetId??(w&&w.type==="image"?w.asset:void 0);if(!g)continue;const b=w&&w.type==="image"?w:void 0,R=ht(k,f,m,A,b==null?void 0:b.layout,t),O=c.fit??((h=b==null?void 0:b.layout)==null?void 0:h.fit);O&&(R.fit=O),l.push({id:u,type:"image",asset:g,layout:R,className:b==null?void 0:b.className})}else if(v==="hotspot"){const m=Math.round((c.width??0)*(c.scaleX??1)),A=Math.round((c.height??0)*(c.scaleY??1)),g=w&&w.type==="hotspot"?w:void 0;l.push({id:u,type:"hotspot",layout:ht(k,f,m,A,g==null?void 0:g.layout,t),onTap:c.onTap??(g==null?void 0:g.onTap)??[],onComplete:c.onComplete??(g==null?void 0:g.onComplete)??[],requiredTaps:c.requiredTaps??(g==null?void 0:g.requiredTaps),ariaLabel:c.ariaLabel??(g==null?void 0:g.ariaLabel)})}else if(v==="area"){const m=Math.round((c.width??0)*(c.scaleX??1)),A=Math.round((c.height??0)*(c.scaleY??1)),g=w&&w.type==="area"?w:void 0,b=c.game??(g==null?void 0:g.game);if(!b)continue;l.push({id:u,type:"area",layout:ht(k,f,m,A,g==null?void 0:g.layout,t),game:b,params:c.params??(g==null?void 0:g.params),ariaLabel:c.ariaLabel??(g==null?void 0:g.ariaLabel),requireComplete:c.requireComplete??(g==null?void 0:g.requireComplete)??!1})}}for(const c of e.blocks)Kr(c)&&(c.type==="hotspot"&&n||c.type==="area"&&a||l.some(u=>u.id===c.id)||l.push(c));let d=e.background?{...e.background}:void 0;return typeof r=="string"&&r&&(d={...d,color:r}),{...e,background:d,blocks:l}}function Rs(s,e,t){var n,a,o,l,d,h,c,u,v,w,k;const r={color:((n=s.background)==null?void 0:n.color)??"#faf6ef"};(a=s.background)!=null&&a.asset&&(r.imageAssetId=s.background.asset,r.imageSrc=(o=e.images.get(s.background.asset))==null?void 0:o.src);const i=[];for(const f of s.blocks)if(Kr(f)){if(f.type==="text"){const m=f.html??e.html.get(`htmlSrc:${f.id}`)??(f.htmlSrc?e.html.get(f.htmlSrc):void 0)??"",A=Fe(f.layout,t),g=He((l=f.style)==null?void 0:l.fontSize,18)||18;i.push({kind:"text",blockId:f.id,text:Is(m),left:A.x,top:A.y,width:Math.max(20,A.width),fontFamily:((d=f.style)==null?void 0:d.fontFamily)??"Georgia, serif",fontSize:g,fill:((h=f.style)==null?void 0:h.color)??"#1f1a14",textAlign:((c=f.style)==null?void 0:c.textAlign)??"left",lineHeight:Jr((u=f.style)==null?void 0:u.lineHeight,g,1.35),fontWeight:(v=f.style)==null?void 0:v.fontWeight,fontStyle:(w=f.style)==null?void 0:w.fontStyle})}else if(f.type==="image"){const m=e.images.get(f.asset);if(!(m!=null&&m.src))continue;const A=Fe(f.layout,t);i.push({kind:"image",blockId:f.id,assetId:f.asset,left:A.x,top:A.y,width:A.width,height:A.height,src:m.src,fit:(k=f.layout)==null?void 0:k.fit})}else if(f.type==="hotspot"){const m=Fe(f.layout,t);i.push({kind:"hotspot",blockId:f.id,left:m.x,top:m.y,width:m.width,height:m.height,ariaLabel:f.ariaLabel,onTap:f.onTap,onComplete:f.onComplete,requiredTaps:f.requiredTaps})}else if(f.type==="area"){const m=Fe(f.layout,t);i.push({kind:"area",blockId:f.id,left:m.x,top:m.y,width:m.width,height:m.height,game:f.game,ariaLabel:f.ariaLabel,requireComplete:f.requireComplete,params:f.params})}}return{background:r,objects:i}}function fa(s){return s.blockType==="image"||s.blockType==="hotspot"||s.blockType==="area"?Math.round((s.width??0)*(s.scaleX??1)):Math.round(s.width??0)}function Qr(s){return s.blockType==="image"||s.blockType==="hotspot"||s.blockType==="area"?Math.round((s.height??0)*(s.scaleY??1)):Math.round(s.height??0)}function pa(s){return`${s}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function ga(s,e){return{...s,left:s.left+e}}function ma(s,e,t,r){const i=[];let n=null,a=null;if(s){const o=Rs(s,t,r);n=o.background,i.push(...o.objects)}if(e){const o=Rs(e,t,r);a=o.background;for(const l of o.objects)i.push(ga(l,r.width))}return{pageSize:r,spreadWidth:r.width*2,leftBackground:n,rightBackground:a,objects:i}}function ya(s,e,t,r,i,n){const a=r.width,o=[],l=[];for(const c of s){if(!c.blockId||!c.blockType)continue;const u=c.left??0,v=fa(c),w=u+v,k=w<=a+.5,f=u>=a-.5;if(k){o.push({...c});continue}if(f){l.push({...c,left:u-a});continue}const m=Math.max(1,Math.round(a-u)),A=Math.max(1,Math.round(w-a));o.push({...c,width:m,scaleX:1,scaleY:1,height:Qr(c)}),l.push({...c,blockId:pa(c.blockId),left:0,width:A,scaleX:1,scaleY:1,height:Qr(c)})}const d=e!=null?$s(o,e,r,i==null?void 0:i.left,n):null,h=t!=null?$s(l,t,r,i==null?void 0:i.right,n):null;return{left:d,right:h}}return _.CueTimeline=Os,_.DEFAULT_FLIP_SPEED_MS=zr,_.DEFAULT_LAYOUT_MODE=Tr,_.DEFAULT_SINGLE_BREAKPOINT=Lr,_.DefaultFlipStyle=Vt,_.FABRIC_CSS_FONT_SIZE_MULT=ha,_.FANCI_EXTENSION=Nt,_.FlipStyle=lt,_.HARDBACK_EDGE_RATIO=Ls,_.Storybook=Ns,_.bindApplication=Ur,_.boxToPixels=Fe,_.buildBackCoverSpread=Mr,_.buildFrontCoverSpread=Pr,_.buildSingleSpreads=Ir,_.buildSpreads=Rt,_.buildTwoPageSpreads=Nr,_.clearPageGameRegistry=ii,_.contentPageIds=$r,_.createFlipStyle=As,_.createSpringrollApplication=Dr,_.downloadBlob=Or,_.extensionOf=Zs,_.fabricLikeToPage=$s,_.findFanciFile=ai,_.findSpreadIndexForPage=Ue,_.findStoryJsonPath=ws,_.getRegisteredFlipStyle=In,_.getRegisteredPageGame=zs,_.hardbackEnabled=Es,_.hardbackOverhang=jr,_.htmlToPlainText=Is,_.isAreaNavGated=js,_.isFanciFile=Ht,_.listRegisteredFlipStyles=Vr,_.listRegisteredPageGames=si,_.loadEpubFromBytes=pn,_.loadEpubFromZip=ks,_.loadFanciFromBytes=_n,_.loadFanciFromZip=Ss,_.loadStory=It,_.packFanci=Fr,_.pageToFabricLike=Rs,_.pagesToSpreadFabricLike=ma,_.parseStory=je,_.parseVtt=rs,_.plainTextToHtml=Xr,_.primaryPageId=Rr,_.registerFlipStyle=Br,_.registerPageGame=ti,_.reportSpringrollLoaded=Zn,_.reportSpringrollProgress=Zr,_.resolveCssLineHeight=Jr,_.resolveFlipSpeedMs=Ts,_.resolveLayoutMode=Er,_.revokeLoadedStory=Cs,_.scaleBlocksToPageSize=ua,_.serializeLayoutBox=ht,_.spreadFabricLikeToPages=ya,_.storySchema=nr,_.toPx=He,_.unregisterPageGame=ri,_.waitForSpringrollReady=Hr,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"}),_})({});