@makefully/fancifully 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +9 -7
- package/dist/Storybook.d.ts.map +1 -1
- package/dist/fancifully.css +1 -1
- package/dist/fancifully.iife.js +2 -2
- package/dist/fancifully.js +1394 -1346
- package/dist/flip/DefaultFlipStyle.d.ts +2 -0
- package/dist/flip/DefaultFlipStyle.d.ts.map +1 -1
- package/dist/flip/FlipStyle.d.ts +8 -0
- package/dist/flip/FlipStyle.d.ts.map +1 -1
- package/dist/flip/index.d.ts +2 -2
- package/dist/flip/index.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/nav/Pager.d.ts.map +1 -1
- package/dist/nav/layoutMode.d.ts +18 -8
- package/dist/nav/layoutMode.d.ts.map +1 -1
- package/dist/render/SpreadView.d.ts +3 -1
- package/dist/render/SpreadView.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/fancifully.iife.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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,`
|
|
1
|
+
var Fancifully=(function(w){"use strict";var xa=Object.defineProperty;var Ca=(w,be,Te)=>be in w?xa(w,be,{enumerable:!0,configurable:!0,writable:!0,value:Te}):w[be]=Te;var y=(w,be,Te)=>Ca(w,typeof be!="symbol"?be+"":be,Te);class be{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]=Te(t),this.applyAll()}getVolume(e){return Te(this.volumes.sound)*Te(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 Te(s){return Number.isNaN(s)?0:Math.min(1,Math.max(0,s))}class zs{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(`#${js(e)}, [data-cue-id="${Zs(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(`#${js(r)}, [data-cue-id="${Zs(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 js(s){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(s):s.replace(/[^a-zA-Z0-9_-]/g,"\\$&")}function Zs(s){return s.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}class ii{constructor(e){y(this,"bus");y(this,"audio");y(this,"timeline",new zs);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 Je=new Map;function ni(s,e){Je.set(s,e)}function Us(s){return Je.get(s)}function ai(){return[...Je.keys()]}function oi(s){Je.delete(s)}function li(){Je.clear()}function Ds(s){return s.some(e=>e.requireComplete&&!e.complete)}function ci(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 Hs(s){var t;const e=((t=s.split(".").pop())==null?void 0:t.toLowerCase())??"";return/^[a-z0-9]{1,8}$/.test(e)?e:""}function Wt(s){const e=Hs(s.name),t=(s.type||"").toLowerCase();return e==="fanci"||t==="application/x-fanci"||t==="application/fanci"}function di(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(Wt(t))return t;return null}var R;(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})(R||(R={}));var Ws;(function(s){s.mergeShapes=(e,t)=>({...e,...t})})(Ws||(Ws={}));const x=R.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Le=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}},g=R.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 ke 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 ke))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,R.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()}}ke.create=s=>new ke(s);const qt=(s,e)=>{let t;switch(s.code){case g.invalid_type:s.received===x.undefined?t="Required":t=`Expected ${s.expected}, received ${s.received}`;break;case g.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(s.expected,R.jsonStringifyReplacer)}`;break;case g.unrecognized_keys:t=`Unrecognized key(s) in object: ${R.joinValues(s.keys,", ")}`;break;case g.invalid_union:t="Invalid input";break;case g.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${R.joinValues(s.options)}`;break;case g.invalid_enum_value:t=`Invalid enum value. Expected ${R.joinValues(s.options)}, received '${s.received}'`;break;case g.invalid_arguments:t="Invalid function arguments";break;case g.invalid_return_type:t="Invalid function return type";break;case g.invalid_date:t="Invalid date";break;case g.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}"`:R.assertNever(s.validation):s.validation!=="regex"?t=`Invalid ${s.validation}`:t="Invalid";break;case g.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 g.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 g.custom:t="Invalid input";break;case g.invalid_intersection_types:t="Intersection results could not be merged";break;case g.not_multiple_of:t=`Number must be a multiple of ${s.multipleOf}`;break;case g.not_finite:t="Number must be finite";break;default:t=e.defaultError,R.assertNever(s)}return{message:t}};let hi=qt;function ui(){return hi}const fi=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=ui(),r=fi({issueData:e,data:s.data,path:s.path,errorMaps:[s.common.contextualErrorMap,s.schemaErrorMap,t,t===qt?void 0:qt].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"}),Xe=s=>({status:"dirty",value:s}),ne=s=>({status:"valid",value:s}),qs=s=>s.status==="aborted",Gs=s=>s.status==="dirty",Be=s=>s.status==="valid",mt=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 he{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 Ys=(s,e)=>{if(Be(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 ke(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 Le(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:Le(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:Le(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(mt(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:Le(e)},i=this._parseSync({data:e,path:r.path,parent:r});return Ys(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:Le(e)};if(!this["~standard"].async)try{const n=this._parseSync({data:e,path:[],parent:t});return Be(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=>Be(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:Le(e)},i=this._parse({data:e,path:r.path,parent:r}),n=await(mt(i)?i:Promise.resolve(i));return Ys(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:g.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 Re({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 _e.create(this,this._def)}nullable(){return Fe.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ue.create(this)}promise(){return St.create(this,this._def)}or(e){return vt.create([this,e],this._def)}and(e){return bt.create(this,e,this._def)}transform(e){return new Re({...M(this._def),schema:this,typeName:L.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new _t({...M(this._def),innerType:this,defaultValue:t,typeName:L.ZodDefault})}brand(){return new ir({typeName:L.ZodBranded,type:this,...M(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new xt({...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 rs.create(this,e)}readonly(){return Ct.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const pi=/^c[^\s-]{8,}$/i,gi=/^[0-9a-z]+$/,mi=/^[0-9A-HJKMNP-TV-Z]{26}$/i,yi=/^[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,vi=/^[a-z0-9_-]{21}$/i,bi=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ki=/^[-+]?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)?)??$/,wi=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Si="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Gt;const _i=/^(?:(?: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])$/,xi=/^(?:(?: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])$/,Ci=/^(([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]))$/,Ai=/^(([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])$/,Ti=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Li=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Js="((\\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])))",Ei=new RegExp(`^${Js}$`);function Xs(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 Pi(s){return new RegExp(`^${Xs(s)}$`)}function Mi(s){let e=`${Js}T${Xs(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 Ni(s,e){return!!((e==="v4"||!e)&&_i.test(s)||(e==="v6"||!e)&&Ci.test(s))}function Ii(s,e){if(!bi.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 $i(s,e){return!!((e==="v4"||!e)&&xi.test(s)||(e==="v6"||!e)&&Ai.test(s))}class we 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:g.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:g.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:g.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:g.too_big,maximum:n.value,type:"string",inclusive:!0,exact:!0,message:n.message}):o&&S(i,{code:g.too_small,minimum:n.value,type:"string",inclusive:!0,exact:!0,message:n.message}),r.dirty())}else if(n.kind==="email")wi.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"email",code:g.invalid_string,message:n.message}),r.dirty());else if(n.kind==="emoji")Gt||(Gt=new RegExp(Si,"u")),Gt.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"emoji",code:g.invalid_string,message:n.message}),r.dirty());else if(n.kind==="uuid")yi.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"uuid",code:g.invalid_string,message:n.message}),r.dirty());else if(n.kind==="nanoid")vi.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"nanoid",code:g.invalid_string,message:n.message}),r.dirty());else if(n.kind==="cuid")pi.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"cuid",code:g.invalid_string,message:n.message}),r.dirty());else if(n.kind==="cuid2")gi.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"cuid2",code:g.invalid_string,message:n.message}),r.dirty());else if(n.kind==="ulid")mi.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"ulid",code:g.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:g.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:g.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:g.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:g.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:g.invalid_string,validation:{endsWith:n.value},message:n.message}),r.dirty()):n.kind==="datetime"?Mi(n).test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{code:g.invalid_string,validation:"datetime",message:n.message}),r.dirty()):n.kind==="date"?Ei.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{code:g.invalid_string,validation:"date",message:n.message}),r.dirty()):n.kind==="time"?Pi(n).test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{code:g.invalid_string,validation:"time",message:n.message}),r.dirty()):n.kind==="duration"?ki.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"duration",code:g.invalid_string,message:n.message}),r.dirty()):n.kind==="ip"?Ni(e.data,n.version)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"ip",code:g.invalid_string,message:n.message}),r.dirty()):n.kind==="jwt"?Ii(e.data,n.alg)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"jwt",code:g.invalid_string,message:n.message}),r.dirty()):n.kind==="cidr"?$i(e.data,n.version)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"cidr",code:g.invalid_string,message:n.message}),r.dirty()):n.kind==="base64"?Ti.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"base64",code:g.invalid_string,message:n.message}),r.dirty()):n.kind==="base64url"?Li.test(e.data)||(i=this._getOrReturnCtx(e,i),S(i,{validation:"base64url",code:g.invalid_string,message:n.message}),r.dirty()):R.assertNever(n);return{status:r.value,value:e.data}}_regex(e,t,r){return this.refinement(i=>e.test(i),{validation:t,code:g.invalid_string,...C.errToObj(r)})}_addCheck(e){return new we({...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 we({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new we({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new we({...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}}we.create=s=>new we({checks:[],typeName:L.ZodString,coerce:(s==null?void 0:s.coerce)??!1,...M(s)});function Ri(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 Ve 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:g.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"?R.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),S(r,{code:g.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:g.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:g.too_big,maximum:n.value,type:"number",inclusive:n.inclusive,exact:!1,message:n.message}),i.dirty()):n.kind==="multipleOf"?Ri(e.data,n.value)!==0&&(r=this._getOrReturnCtx(e,r),S(r,{code:g.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:g.not_finite,message:n.message}),i.dirty()):R.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 Ve({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:C.toString(i)}]})}_addCheck(e){return new Ve({...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"&&R.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)}}Ve.create=s=>new Ve({checks:[],typeName:L.ZodNumber,coerce:(s==null?void 0:s.coerce)||!1,...M(s)});class Ke 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:g.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:g.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:g.not_multiple_of,multipleOf:n.value,message:n.message}),i.dirty()):R.assertNever(n);return{status:i.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return S(t,{code:g.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 Ke({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:C.toString(i)}]})}_addCheck(e){return new Ke({...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}}Ke.create=s=>new Ke({checks:[],typeName:L.ZodBigInt,coerce:(s==null?void 0:s.coerce)??!1,...M(s)});class Yt 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:g.invalid_type,expected:x.boolean,received:r.parsedType}),T}return ne(e.data)}}Yt.create=s=>new Yt({typeName:L.ZodBoolean,coerce:(s==null?void 0:s.coerce)||!1,...M(s)});class yt 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:g.invalid_type,expected:x.date,received:n.parsedType}),T}if(Number.isNaN(e.data.getTime())){const n=this._getOrReturnCtx(e);return S(n,{code:g.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:g.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:g.too_big,message:n.message,inclusive:!0,exact:!1,maximum:n.value,type:"date"}),r.dirty()):R.assertNever(n);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new yt({...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}}yt.create=s=>new yt({checks:[],coerce:(s==null?void 0:s.coerce)||!1,typeName:L.ZodDate,...M(s)});class Ks extends ${_parse(e){if(this._getType(e)!==x.symbol){const r=this._getOrReturnCtx(e);return S(r,{code:g.invalid_type,expected:x.symbol,received:r.parsedType}),T}return ne(e.data)}}Ks.create=s=>new Ks({typeName:L.ZodSymbol,...M(s)});class Jt extends ${_parse(e){if(this._getType(e)!==x.undefined){const r=this._getOrReturnCtx(e);return S(r,{code:g.invalid_type,expected:x.undefined,received:r.parsedType}),T}return ne(e.data)}}Jt.create=s=>new Jt({typeName:L.ZodUndefined,...M(s)});class Xt extends ${_parse(e){if(this._getType(e)!==x.null){const r=this._getOrReturnCtx(e);return S(r,{code:g.invalid_type,expected:x.null,received:r.parsedType}),T}return ne(e.data)}}Xt.create=s=>new Xt({typeName:L.ZodNull,...M(s)});class Qs extends ${constructor(){super(...arguments),this._any=!0}_parse(e){return ne(e.data)}}Qs.create=s=>new Qs({typeName:L.ZodAny,...M(s)});class Kt extends ${constructor(){super(...arguments),this._unknown=!0}_parse(e){return ne(e.data)}}Kt.create=s=>new Kt({typeName:L.ZodUnknown,...M(s)});class Ee extends ${_parse(e){const t=this._getOrReturnCtx(e);return S(t,{code:g.invalid_type,expected:x.never,received:t.parsedType}),T}}Ee.create=s=>new Ee({typeName:L.ZodNever,...M(s)});class er extends ${_parse(e){if(this._getType(e)!==x.undefined){const r=this._getOrReturnCtx(e);return S(r,{code:g.invalid_type,expected:x.void,received:r.parsedType}),T}return ne(e.data)}}er.create=s=>new er({typeName:L.ZodVoid,...M(s)});class ue extends ${_parse(e){const{ctx:t,status:r}=this._processInputParams(e),i=this._def;if(t.parsedType!==x.array)return S(t,{code:g.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?g.too_big:g.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:g.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:g.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 he(t,a,t.path,o)))).then(a=>ee.mergeArray(r,a));const n=[...t.data].map((a,o)=>i.type._parseSync(new he(t,a,t.path,o)));return ee.mergeArray(r,n)}get element(){return this._def.type}min(e,t){return new ue({...this._def,minLength:{value:e,message:C.toString(t)}})}max(e,t){return new ue({...this._def,maxLength:{value:e,message:C.toString(t)}})}length(e,t){return new ue({...this._def,exactLength:{value:e,message:C.toString(t)}})}nonempty(e){return this.min(1,e)}}ue.create=(s,e)=>new ue({type:s,minLength:null,maxLength:null,exactLength:null,typeName:L.ZodArray,...M(e)});function ze(s){if(s instanceof G){const e={};for(const t in s.shape){const r=s.shape[t];e[t]=_e.create(ze(r))}return new G({...s._def,shape:()=>e})}else return s instanceof ue?new ue({...s._def,type:ze(s.element)}):s instanceof _e?_e.create(ze(s.unwrap())):s instanceof Fe?Fe.create(ze(s.unwrap())):s instanceof Ie?Ie.create(s.items.map(e=>ze(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=R.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:g.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 Ee&&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 he(i,c,i.path,d)),alwaysSet:d in i.data})}if(this._def.catchall instanceof Ee){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:g.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 he(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 R.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 R.objectKeys(this.shape))e[r]||(t[r]=this.shape[r]);return new G({...this._def,shape:()=>t})}deepPartial(){return ze(this)}partial(e){const t={};for(const r of R.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 R.objectKeys(this.shape))if(e&&!e[r])t[r]=this.shape[r];else{let n=this.shape[r];for(;n instanceof _e;)n=n._def.innerType;t[r]=n}return new G({...this._def,shape:()=>t})}keyof(){return sr(R.objectKeys(this.shape))}}G.create=(s,e)=>new G({shape:()=>s,unknownKeys:"strip",catchall:Ee.create(),typeName:L.ZodObject,...M(e)}),G.strictCreate=(s,e)=>new G({shape:()=>s,unknownKeys:"strict",catchall:Ee.create(),typeName:L.ZodObject,...M(e)}),G.lazycreate=(s,e)=>new G({shape:s,unknownKeys:"strip",catchall:Ee.create(),typeName:L.ZodObject,...M(e)});class vt 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 ke(o.ctx.common.issues));return S(t,{code:g.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 ke(l));return S(t,{code:g.invalid_union,unionErrors:o}),T}}get options(){return this._def.options}}vt.create=(s,e)=>new vt({options:s,typeName:L.ZodUnion,...M(e)});const Se=s=>s instanceof ts?Se(s.schema):s instanceof Re?Se(s.innerType()):s instanceof wt?[s.value]:s instanceof $e?s.options:s instanceof ss?R.objectValues(s.enum):s instanceof _t?Se(s._def.innerType):s instanceof Jt?[void 0]:s instanceof Xt?[null]:s instanceof _e?[void 0,...Se(s.unwrap())]:s instanceof Fe?[null,...Se(s.unwrap())]:s instanceof ir||s instanceof Ct?Se(s.unwrap()):s instanceof xt?Se(s._def.innerType):[];class Qt extends ${_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==x.object)return S(t,{code:g.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:g.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=Se(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 Qt({typeName:L.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:i,...M(r)})}}function es(s,e){const t=Le(s),r=Le(e);if(s===e)return{valid:!0,data:s};if(t===x.object&&r===x.object){const i=R.objectKeys(e),n=R.objectKeys(s).filter(o=>i.indexOf(o)!==-1),a={...s,...e};for(const o of n){const l=es(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=es(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 bt extends ${_parse(e){const{status:t,ctx:r}=this._processInputParams(e),i=(n,a)=>{if(qs(n)||qs(a))return T;const o=es(n.value,a.value);return o.valid?((Gs(n)||Gs(a))&&t.dirty(),{status:t.value,value:o.data}):(S(r,{code:g.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}))}}bt.create=(s,e,t)=>new bt({left:s,right:e,typeName:L.ZodIntersection,...M(t)});class Ie extends ${_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==x.array)return S(r,{code:g.invalid_type,expected:x.array,received:r.parsedType}),T;if(r.data.length<this._def.items.length)return S(r,{code:g.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:g.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 he(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 Ie({...this._def,rest:e})}}Ie.create=(s,e)=>{if(!Array.isArray(s))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Ie({items:s,typeName:L.ZodTuple,rest:null,...M(e)})};class kt 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:g.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 he(r,o,r.path,o)),value:a._parse(new he(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 kt({keyType:e,valueType:t,typeName:L.ZodRecord,...M(r)}):new kt({keyType:we.create(),valueType:e,typeName:L.ZodRecord,...M(t)})}}class tr 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:g.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 he(r,o,r.path,[d,"key"])),value:n._parse(new he(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}}}}tr.create=(s,e,t)=>new tr({valueType:e,keyType:s,typeName:L.ZodMap,...M(t)});class Qe extends ${_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==x.set)return S(r,{code:g.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:g.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:g.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 he(r,l,r.path,d)));return r.common.async?Promise.all(o).then(l=>a(l)):a(o)}min(e,t){return new Qe({...this._def,minSize:{value:e,message:C.toString(t)}})}max(e,t){return new Qe({...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)}}Qe.create=(s,e)=>new Qe({valueType:s,minSize:null,maxSize:null,typeName:L.ZodSet,...M(e)});class ts 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})}}ts.create=(s,e)=>new ts({getter:s,typeName:L.ZodLazy,...M(e)});class wt extends ${_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return S(t,{received:t.data,code:g.invalid_literal,expected:this._def.value}),T}return{status:"valid",value:e.data}}get value(){return this._def.value}}wt.create=(s,e)=>new wt({value:s,typeName:L.ZodLiteral,...M(e)});function sr(s,e){return new $e({values:s,typeName:L.ZodEnum,...M(e)})}class $e extends ${_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),r=this._def.values;return S(t,{expected:R.joinValues(r),received:t.parsedType,code:g.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:g.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 $e.create(e,{...this._def,...t})}exclude(e,t=this._def){return $e.create(this.options.filter(r=>!e.includes(r)),{...this._def,...t})}}$e.create=sr;class ss extends ${_parse(e){const t=R.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==x.string&&r.parsedType!==x.number){const i=R.objectValues(t);return S(r,{expected:R.joinValues(i),received:r.parsedType,code:g.invalid_type}),T}if(this._cache||(this._cache=new Set(R.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const i=R.objectValues(t);return S(r,{received:r.data,code:g.invalid_enum_value,options:i}),T}return ne(e.data)}get enum(){return this._def.values}}ss.create=(s,e)=>new ss({values:s,typeName:L.ZodNativeEnum,...M(e)});class St 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:g.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})))}}St.create=(s,e)=>new St({type:s,typeName:L.ZodPromise,...M(e)});class Re 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"?Xe(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"?Xe(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(!Be(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=>Be(a)?Promise.resolve(i.transform(a.value,n)).then(o=>({status:t.value,value:o})):T);R.assertNever(i)}}Re.create=(s,e,t)=>new Re({schema:s,typeName:L.ZodEffects,effect:e,...M(t)}),Re.createWithPreprocess=(s,e,t)=>new Re({schema:e,effect:{type:"preprocess",transform:s},typeName:L.ZodEffects,...M(t)});class _e extends ${_parse(e){return this._getType(e)===x.undefined?ne(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}_e.create=(s,e)=>new _e({innerType:s,typeName:L.ZodOptional,...M(e)});class Fe extends ${_parse(e){return this._getType(e)===x.null?ne(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Fe.create=(s,e)=>new Fe({innerType:s,typeName:L.ZodNullable,...M(e)});class _t 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}}_t.create=(s,e)=>new _t({innerType:s,typeName:L.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...M(e)});class xt 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 mt(i)?i.then(n=>({status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new ke(r.common.issues)},input:r.data})})):{status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new ke(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}xt.create=(s,e)=>new xt({innerType:s,typeName:L.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...M(e)});class rr extends ${_parse(e){if(this._getType(e)!==x.nan){const r=this._getOrReturnCtx(e);return S(r,{code:g.invalid_type,expected:x.nan,received:r.parsedType}),T}return{status:"valid",value:e.data}}}rr.create=s=>new rr({typeName:L.ZodNaN,...M(s)});class ir 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 rs 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(),Xe(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 rs({in:e,out:t,typeName:L.ZodPipeline})}}class Ct extends ${_parse(e){const t=this._def.innerType._parse(e),r=i=>(Be(i)&&(i.value=Object.freeze(i.value)),i);return mt(t)?t.then(i=>r(i)):r(t)}unwrap(){return this._def.innerType}}Ct.create=(s,e)=>new Ct({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=we.create,te=Ve.create,At=Yt.create,Fi=Kt.create;Ee.create;const je=ue.create,V=G.create,et=vt.create,nr=Qt.create;bt.create,Ie.create;const ar=kt.create,Pe=wt.create,tt=$e.create;St.create,_e.create,Fe.create;const Tt=et([te(),N()]),Lt=V({x:Tt.optional().default(0),y:Tt.optional().default(0),width:Tt.optional(),height:Tt.optional(),fit:tt(["contain","cover","fill","none"]).optional(),horizontalAlign:tt(["left","center","right"]).optional(),verticalAlign:tt(["top","center","bottom"]).optional()}),Oi=V({id:N(),start:te(),end:te(),text:N().optional()}),Bi=nr("type",[V({type:Pe("image"),src:N()}),V({type:Pe("audio"),src:N(),channel:tt(["vo","sfx","music"]).optional().default("vo")}),V({type:Pe("vtt"),src:N()}),V({type:Pe("html"),src:N()})]),Et=V({target:N(),className:N()}),or=et([V({play:N()}),V({toggleClass:Et}),V({addClass:Et}),V({removeClass:Et}),V({replayClass:Et})]),Vi=V({id:N(),type:Pe("text"),layout:Lt.optional().default({}),html:N().optional(),htmlSrc:N().optional(),style:V({fontFamily:N().optional(),fontSize:N().optional(),color:N().optional(),textAlign:tt(["left","center","right"]).optional(),lineHeight:et([N(),te()]).optional(),fontWeight:N().optional(),fontStyle:N().optional()}).optional()}),zi=V({id:N(),type:Pe("image"),asset:N(),layout:Lt.optional().default({}),className:N().optional()}),ji=V({id:N(),type:Pe("hotspot"),layout:Lt.optional().default({}),onTap:je(or).optional().default([]),requiredTaps:te().int().positive().optional(),onComplete:je(or).optional().default([]),ariaLabel:N().optional()}),Zi=V({id:N(),type:Pe("area"),layout:Lt.optional().default({}),game:N().min(1),params:ar(Fi()).optional(),ariaLabel:N().optional(),requireComplete:At().optional().default(!1)}),Ui=nr("type",[Vi,zi,ji,Zi]),Di=V({id:N(),background:V({asset:N().optional(),color:N().optional(),innerColor:N().optional()}).optional(),readAloud:V({audio:N(),cues:et([N(),je(Oi)]).optional()}).optional(),blocks:je(Ui).optional().default([])}),lr=V({id:N(),title:N().optional(),pageSize:V({width:te().positive(),height:te().positive()}),frontCover:At().optional().default(!1),backCover:At().optional().default(!1),hardback:At().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:je(V({family:N(),src:N(),weight:et([N(),te()]).optional(),style:N().optional()})).optional().default([]),assets:ar(Bi).optional().default({}),pages:je(Di).min(1)});function Ze(s){return lr.parse(s)}function is(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(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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").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"}),_})({});
|
|
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=cr(u[0]),k=cr(u[1]),b=c.join(" ").trim(),f=d||b||`cue-${n++}`;i.push({id:f,start:v,end:k,text:b||void 0})}return i}function cr(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 Ue(s,e){if(/^(?:[a-z]+:)?\/\//i.test(e)||e.startsWith("data:")||e.startsWith("blob:")||!s)return e;try{return new URL(e,ns(s)).href}catch{return`${ns(s)}${e.replace(/^\//,"")}`}}function ns(s){return s.endsWith("/")||s.includes("?")?s.endsWith("/")?s:`${s}/`:/\.[a-z0-9]+$/i.test(s.split("/").pop()??"")?s.replace(/[^/]+$/,""):`${s}/`}function Hi(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 ns(s.replace(/[^/]+$/,""))}}async function st(s,e){typeof document>"u"||!("fonts"in document)||await Promise.all(s.fonts.map(async t=>{const r=Ue(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,as=Int32Array,Pt=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]),Mt=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]),os=new H([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),dr=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 as(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}},hr=dr(Pt,2),ur=hr.b,ls=hr.r;ur[28]=258,ls[258]=28;for(var fr=dr(Mt,0),Wi=fr.b,pr=fr.r,cs=new se(32768),z=0;z<32768;++z){var Me=(z&43690)>>1|(z&21845)<<1;Me=(Me&52428)>>2|(Me&13107)<<2,Me=(Me&61680)>>4|(Me&3855)<<4,cs[z]=((Me&65280)>>8|(Me&255)<<8)>>1}for(var fe=(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[cs[c]>>l]=d}else for(o=new se(r),i=0;i<r;++i)s[i]&&(o[i]=cs[a[s[i]-1]++]>>15-s[i]);return o}),Ne=new H(288),z=0;z<144;++z)Ne[z]=8;for(var z=144;z<256;++z)Ne[z]=9;for(var z=256;z<280;++z)Ne[z]=7;for(var z=280;z<288;++z)Ne[z]=8;for(var rt=new H(32),z=0;z<32;++z)rt[z]=5;var qi=fe(Ne,9,0),Gi=fe(Ne,9,1),Yi=fe(rt,5,0),Ji=fe(rt,5,1),ds=function(s){for(var e=s[0],t=1;t<s.length;++t)s[t]>e&&(e=s[t]);return e},de=function(s,e,t){var r=e/8|0;return(s[r]|s[r+1]<<8)>>(e&7)&t},hs=function(s,e){var t=e/8|0;return(s[t]|s[t+1]<<8|s[t+2]<<16)>>(e&7)},us=function(s){return(s+7)/8|0},it=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))},Xi=["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||Xi[s]);if(r.code=s,Error.captureStackTrace&&Error.captureStackTrace(r,Q),!t)throw r;return r},Ki=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(pt){var gt=t.length;if(pt>gt){var Ye=new H(Math.max(gt*2,pt));Ye.set(t),t=Ye}},h=e.f||0,c=e.p||0,u=e.b||0,v=e.l,k=e.d,b=e.m,f=e.n,m=i*8;do{if(!v){h=de(s,c,1);var A=de(s,c+1,3);if(c+=3,A)if(A==1)v=Gi,k=Ji,b=9,f=5;else if(A==2){var O=de(s,c,31)+257,E=de(s,c+10,15)+4,I=O+de(s,c+5,31)+1;c+=14;for(var P=new H(I),W=new H(19),U=0;U<E;++U)W[os[U]]=de(s,c+U*3,7);c+=E*3;for(var Y=ds(W),le=(1<<Y)-1,B=fe(W,Y,1),U=0;U<I;){var Z=B[de(s,c,le)];c+=Z&15;var p=Z>>4;if(p<16)P[U++]=p;else{var q=0,j=0;for(p==16?(j=3+de(s,c,3),c+=2,q=P[U-1]):p==17?(j=3+de(s,c,7),c+=3):p==18&&(j=11+de(s,c,127),c+=7);j--;)P[U++]=q}}var X=P.subarray(0,O),K=P.subarray(O);b=ds(X),f=ds(K),v=fe(X,b,1),k=fe(K,f,1)}else Q(1);else{var p=us(c)+4,_=s[p-4]|s[p-3]<<8,F=p+_;if(F>i){l&&Q(0);break}o&&d(u+_),t.set(s.subarray(p,F),u),e.b=u+=_,e.p=c=F*8,e.f=h;continue}if(c>m){l&&Q(0);break}}o&&d(u+131072);for(var ft=(1<<b)-1,ce=(1<<f)-1,Ae=c;;Ae=c){var q=v[hs(s,c)&ft],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){Ae=c,v=null;break}else{var ie=re-254;if(re>264){var U=re-257,D=Pt[U];ie=de(s,c,(1<<D)-1)+ur[U],c+=D}var ve=k[hs(s,c)&ce],qe=ve>>4;ve||Q(3),c+=ve&15;var K=Wi[qe];if(qe>3){var D=Mt[qe];K+=hs(s,c)&(1<<D)-1,c+=D}if(c>m){l&&Q(0);break}o&&d(u+131072);var Ge=u+ie;if(u<K){var Dt=n-K,Ht=Math.min(K,Ge);for(Dt+u<0&&Q(3);u<Ht;++u)t[u]=r[Dt+u]}for(;u<Ge;++u)t[u]=t[u-K]}}e.l=v,e.p=Ae,e.b=u,e.f=h,v&&(h=1,e.m=b,e.d=k,e.n=f)}while(!h);return u!=t.length&&a?it(t,0,u):t.subarray(0,u)},xe=function(s,e,t){t<<=e&7;var r=e/8|0;s[r]|=t,s[r+1]|=t>>8},nt=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},fs=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:vr,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(F,O){return F.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),k=ps(t[h-1],v,0);if(k>e){var r=0,b=0,f=k-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)b+=m-(1<<k-v[A]),v[A]=e;else break}for(b>>=f;b>0;){var p=n[r].s;v[p]<e?b-=1<<e-v[p]++-1:++r}for(;r>=0&&b;--r){var _=n[r].s;v[_]==e&&(--v[_],++b)}k=e}return{t:new H(v),l:k}},ps=function(s,e,t){return s.s==-1?Math.max(ps(s.l,e,t+1),ps(s.r,e,t+1)):e[s.s]=t},gr=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}},at=function(s,e){for(var t=0,r=0;r<e.length;++r)t+=s[r]*e[r];return t},mr=function(s,e,t){var r=t.length,i=us(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},yr=function(s,e,t,r,i,n,a,o,l,d,h){xe(e,h++,t),++i[256];for(var c=fs(i,15),u=c.t,v=c.l,k=fs(n,15),b=k.t,f=k.l,m=gr(u),A=m.c,p=m.n,_=gr(b),F=_.c,O=_.n,E=new se(19),I=0;I<A.length;++I)++E[A[I]&31];for(var I=0;I<F.length;++I)++E[F[I]&31];for(var P=fs(E,7),W=P.t,U=P.l,Y=19;Y>4&&!W[os[Y-1]];--Y);var le=d+5<<3,B=at(i,Ne)+at(n,rt)+a,Z=at(i,u)+at(n,b)+a+14+3*Y+at(E,W)+2*E[16]+3*E[17]+7*E[18];if(l>=0&&le<=B&&le<=Z)return mr(e,h,s.subarray(l,l+d));var q,j,X,K;if(xe(e,h,1+(Z<B)),h+=2,Z<B){q=fe(u,v,0),j=u,X=fe(b,f,0),K=b;var ft=fe(W,U,0);xe(e,h,p-257),xe(e,h+5,O-1),xe(e,h+10,Y-4),h+=14;for(var I=0;I<Y;++I)xe(e,h+3*I,W[os[I]]);h+=3*Y;for(var ce=[A,F],Ae=0;Ae<2;++Ae)for(var re=ce[Ae],I=0;I<re.length;++I){var ie=re[I]&31;xe(e,h,ft[ie]),h+=W[ie],ie>15&&(xe(e,h,re[I]>>5&127),h+=re[I]>>12)}}else q=qi,j=Ne,X=Yi,K=rt;for(var I=0;I<o;++I){var D=r[I];if(D>255){var ie=D>>18&31;nt(e,h,q[ie+257]),h+=j[ie+257],ie>7&&(xe(e,h,D>>23&31),h+=Pt[ie]);var ve=D&31;nt(e,h,X[ve]),h+=K[ve],ve>3&&(nt(e,h,D>>5&8191),h+=Mt[ve])}else nt(e,h,q[D]),h+=j[D]}return nt(e,h,q[256]),h+j[256]},Qi=new as([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),vr=new H(0),en=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=Qi[e-1],u=c>>13,v=c&8191,k=(1<<t)-1,b=n.p||new se(32768),f=n.h||new se(k+1),m=Math.ceil(t/3),A=2*m,p=function(Vs){return(s[Vs]^s[Vs+1]<<m^s[Vs+2]<<A)&k},_=new as(25e3),F=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 le=p(P),B=P&32767,Z=f[le];if(b[B]=Z,f[le]=B,U<=P){var q=a-P;if((E>7e3||W>24576)&&(q>423||!d)){h=yr(s,l,0,_,F,O,I,W,Y,P-Y,h),W=E=I=0,Y=P;for(var j=0;j<286;++j)F[j]=0;for(var j=0;j<30;++j)O[j]=0}var X=2,K=0,ft=v,ce=B-Z&32767;if(q>2&&le==p(P-ce))for(var Ae=Math.min(u,q)-1,re=Math.min(32767,P),ie=Math.min(258,q);ce<=re&&--ft&&B!=Z;){if(s[P+X]==s[P+X-ce]){for(var D=0;D<ie&&s[P+D]==s[P+D-ce];++D);if(D>X){if(X=D,K=ce,D>Ae)break;for(var ve=Math.min(ce,D-2),qe=0,j=0;j<ve;++j){var Ge=P-ce+j&32767,Dt=b[Ge],Ht=Ge-Dt&32767;Ht>qe&&(qe=Ht,Z=Ge)}}}B=Z,Z=b[B],ce+=B-Z&32767}if(K){_[W++]=268435456|ls[X]<<18|pr[K];var pt=ls[X]&31,gt=pr[K]&31;I+=Pt[pt]+Mt[gt],++F[257+pt],++O[gt],U=P+X,++E}else _[W++]=s[P],++F[s[P]]}}for(P=Math.max(P,U);P<a;++P)_[W++]=s[P],++F[s[P]];h=yr(s,l,d,_,F,O,I,W,Y,P-Y,h),d||(n.r=h&7|l[h/8|0]<<3,h-=7,n.h=f,n.p=b,n.i=P,n.w=U)}else{for(var P=n.w||0;P<a+d;P+=65535){var Ye=P+65535;Ye>=a&&(l[h/8|0]=d,Ye=a),h=mr(l,h+1,s.subarray(P,Ye))}n.i=a}return it(o,0,r+us(h)+i)},tn=(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})(),sn=function(){var s=-1;return{p:function(e){for(var t=s,r=0;r<e.length;++r)t=tn[t&255^e[r]]^t>>>8;s=t},d:function(){return~s}}},rn=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 en(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)},br=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},pe=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},gs=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 nn(s,e){return rn(s,e||{},0,0)}function an(s,e){return Ki(s,{i:2},e&&e.out,e&&e.dictionary)}var kr=function(s,e,t,r){for(var i in s){var n=s[i],a=e+i,o=r;Array.isArray(n)&&(o=br(r,n[1]),n=n[0]),ArrayBuffer.isView(n)?t[a]=[n,o]:(t[a+="/"]=[new H(0),o],kr(n,a,t,r))}},wr=typeof TextEncoder<"u"&&new TextEncoder,ms=typeof TextDecoder<"u"&&new TextDecoder,on=0;try{ms.decode(vr,{stream:!0}),on=1}catch{}var ln=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:it(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 ys(s,e){var t;if(wr)return wr.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 it(i,0,n)}function Sr(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(ms)return ms.decode(s);var i=ln(s),n=i.s,t=i.r;return t.length&&Q(8),n}}var cn=function(s,e){return e+30+pe(s,e+26)+pe(s,e+28)},dn=function(s,e,t){var r=pe(s,e+28),i=pe(s,e+30),n=Sr(s.subarray(e+46,e+46+r),!(pe(s,e+8)&2048)),a=e+46+r,o=hn(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[pe(s,e+10),l,d,n,a+i+pe(s,e+32),h]},hn=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+pe(s,e+2))if(pe(s,e)==1)return[o?gs(s,e+4+8*l):i,l?gs(s,e+4):n,d?gs(s,e+4+8*(l+o)):a,1];r<2&&Q(13)}return[i,n,a,0]},vs=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},_r=function(s,e,t,r,i,n,a,o){var l=r.length,d=t.extra,h=o&&o.length,c=vs(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 k in d){var b=d[k],f=b.length;J(s,e,+k),J(s,e+2,f),s.set(b,e+4),e+=4+f}return h&&(s.set(o,e),e+=h),e},un=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 fn(s,e){e||(e={});var t={},r=[];kr(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=ys(a),u=c.length,v=d.comment,k=v&&ys(v),b=k&&k.length,f=vs(d.extra);u>65535&&Q(11);var m=h?nn(l,d):l,A=m.length,p=sn();p.p(l),r.push(br(d,{size:l.length,crc:p.d(),c:m,f:c,m:k,u:u!=a.length||k&&v.length!=b,o:i,compression:h})),i+=30+u+f+A,n+=76+2*(u+f)+(b||0)+A}for(var _=new H(n+22),F=i,O=n-i,E=0;E<r.length;++E){var c=r[E];_r(_,c.o,c,c.f,c.u,c.c.length);var I=30+c.f.length+vs(c.extra);_.set(c.c,c.o+I),_r(_,i,c,c.f,c.u,c.c.length,c.o,c.m),i+=16+I+(c.m?c.m.length:0)}return un(_,i,r.length,O,F),_}function pn(s,e){for(var t={},r=s.length-22;ae(s,r)!=101010256;--r)(!r||s.length-r>65558)&&Q(13);var i=pe(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=dn(s,n,a),h=d[0],c=d[1],u=d[2],v=d[3],k=d[4],b=d[5],f=cn(s,b);n=k,h?h==8?t[v]=an(s.subarray(f,f+c),{out:new H(u)}):Q(14,"unknown compression type "+h):t[v]=it(s,f,f+c)}return t}const xr=[80,75];function bs(s){return s.length>=2&&s[0]===xr[0]&&s[1]===xr[1]}function ks(s){const e=s instanceof Uint8Array?s:new Uint8Array(s);if(!bs(e))throw new Error("Not a ZIP archive");const t=pn(e),r=new Map;for(const[i,n]of Object.entries(t))!n||i.endsWith("/")||r.set(ge(i),n);return r}function ge(s){return s.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"")}function ot(s,e){const t=Nt(s,e);if(!t)throw new Error(`Missing zip entry: ${e}`);return Sr(t)}function Nt(s,e){const t=ge(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 gn(s){return[...s.keys()]}function mn(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 Cr(s,e){const t=new Uint8Array(s.byteLength);t.set(s);const r=new Blob([t.buffer],{type:mn(e)});return URL.createObjectURL(r)}async function yn(s){const e=await fetch(s);if(!e.ok)throw new Error(`Failed to fetch ${s}: ${e.status}`);return e.arrayBuffer()}function vn(s){return ws(ks(s))}function ws(s){const e=ot(s,"META-INF/container.xml"),t=me(e,/full-path\s*=\s*"([^"]+)"/i);if(!t)throw new Error("Invalid EPUB: missing rootfile in container.xml");const r=ge(t),i=r.includes("/")?r.replace(/\/[^/]+$/,"/"):"",n=ot(s,r),a=Lr(n,"dc:title")||Lr(n,"title")||"EPUB Story",o=Sn(n)??{width:768,height:1024},l=kn(n,i),d=wn(n),h=[],c=new Map,u=f=>{const m=ge(f);if(c.has(m))return c.get(m);const A=Nt(s,m);if(!A)throw new Error(`EPUB missing file: ${m}`);const p=Cr(A,m);return h.push(p),c.set(m,p),p},v={},k=[];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 p=A.href,_=ot(s,p),F=p.includes("/")?p.replace(/\/[^/]+$/,"/"):"",O=`page-${m+1}`,E=xn(_),{html:I,imageHrefs:P}=Cn(E,F,B=>{const Z=ge(B.includes(":")?B:`${F}${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 le;if(A.mediaOverlay){const B=l.get(A.mediaOverlay);if(B){const Z=_n(ot(s,B.href),B.href);if(Z.audioHref){const q=`vo-${m}`,j=ge(Z.audioHref.includes("/")||Z.audioHref.startsWith(".")?Tr(B.href,Z.audioHref):`${i}${Z.audioHref}`);v[q]={type:"audio",src:u(j),channel:"vo"};const X=Z.cues;X.length?le={audio:q,cues:X}:le={audio:q}}}}k.push({id:O,background:Y,readAloud:le,blocks:W})}),k.length===0)throw new Error("Invalid EPUB: no spine HTML documents found");return{story:Ze({id:`epub-${An(a)}`,title:a,pageSize:o,fonts:[],assets:v,pages:k}),blobUrls:h}}function bn(s){return!!Nt(s,"META-INF/container.xml")}function kn(s,e){const t=new Map,r=/<item\b[^>]*>/gi;let i;for(;i=r.exec(s);){const n=i[0],a=me(n,/\bid\s*=\s*"([^"]+)"/i),o=me(n,/\bhref\s*=\s*"([^"]+)"/i),l=me(n,/\bmedia-type\s*=\s*"([^"]+)"/i)??"",d=me(n,/\bmedia-overlay\s*=\s*"([^"]+)"/i)??void 0,h=me(n,/\bproperties\s*=\s*"([^"]+)"/i)??void 0;!a||!o||t.set(a,{id:a,href:ge(`${e}${o}`),mediaType:l,mediaOverlay:d,properties:h})}return t}function wn(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 Sn(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 _n(s,e){const t=[];let r;const i=me(s,/<audio\b[^>]*\bsrc\s*=\s*"([^"]+)"/i);i&&(r=Tr(e,i));const n=/<par\b[^>]*>([\s\S]*?)<\/par>/gi;let a,o=0;for(;a=n.exec(s);){const l=a[1],d=me(l,/<text\b[^>]*\bsrc\s*=\s*"([^"]+)"/i),h=me(l,/\bclipBegin\s*=\s*"([^"]+)"/i),c=me(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:Ar(h),end:Ar(c)}),o+=1)}return{audioHref:r,cues:t}}function Ar(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 xn(s){const e=s.match(/<body\b[^>]*>([\s\S]*?)<\/body>/i);return e?e[1].trim():s}function Cn(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=ge(`${e}${o}`);/\.(png|jpe?g|gif|webp|svg)$/i.test(o)&&r.push(l);const d=t(o);return`${a}="${d}"`}),imageHrefs:r}}function Tr(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 me(s,e){const t=s.match(e);return t?t[1]:null}function Lr(s,e){const t=new RegExp(`<${e.replace(":",":")}[^>]*>([^<]*)</${e.replace(":",":")}>`,"i"),r=s.match(t);return r?r[1].trim():null}function An(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,48)||"book"}function Ss(s){const e=gn(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 _s(s){const e=Ss(s),t=e.includes("/")?e.replace(/\/[^/]+$/,"/"):"",r=Ze(JSON.parse(ot(s,e))),i=new Map,n=[];for(const[a,o]of s){if(a===e)continue;const l=Cr(o,a);n.push(l),i.set(a,l),t&&a.startsWith(t)&&i.set(a.slice(t.length),l)}return En(r,a=>Ln(i,t,a)),{story:r,pathUrls:i,blobUrls:n,storyDir:t}}function Tn(s){return _s(ks(s))}function Ln(s,e,t){const r=ge(t);if(s.has(r))return s.get(r);const i=ge(`${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 En(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 Pn(s){if(Nt(s,"META-INF/container.xml"))return!1;try{return Ss(s),!0}catch{return!1}}const It=".fanci";function xs(s){const e=s.split("?")[0].split("#")[0],t=e.split("/").pop()??e,r=t.lastIndexOf(".");return r>=0?t.slice(r).toLowerCase():""}function Mn(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=xs(t);return r===It||r===".fanci.zip"?"fanci":r===".epub"?"epub":"json"}async function Nn(s){return s instanceof ArrayBuffer?s:s instanceof Uint8Array?s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength):s.arrayBuffer()}async function $t(s,e){const t=typeof e=="string"?{baseUrl:e}:e??{},r=t.onProgress??(()=>{});if($n(s)){r({stage:"parse",progress:.1,detail:"story object"});const i=Ze(s),n=t.baseUrl??(typeof location<"u"?location.href:"");r({stage:"assets",progress:.2,detail:"fonts"}),await st(i,n);const a=await lt(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&&!Er(s)){const i=s;return $t(i.story,{baseUrl:t.baseUrl??i.baseUrl,name:t.name,onProgress:t.onProgress})}if(typeof s=="string")return In(s,t,r);if(Er(s)){r({stage:"fetch",progress:.05,detail:"bytes"});const i=await Nn(s),n=t.name??(s instanceof File?s.name:void 0)??"";return Cs(i,n,t.baseUrl,r)}throw new Error("Unsupported story source")}async function In(s,e,t){const r=xs(s),i=Mn(s,e.name??s);if(t({stage:"fetch",progress:.02,detail:s}),r===It||r===".epub"||i==="fanci"||i==="epub"){const u=await yn(s);return t({stage:"fetch",progress:.15,detail:"package downloaded"}),Cs(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(bs(o))return t({stage:"fetch",progress:.15,detail:"zip downloaded"}),Cs(a,e.name??s,e.baseUrl,t);t({stage:"parse",progress:.2,detail:"json"});const l=new TextDecoder().decode(o),d=Ze(JSON.parse(l)),h=e.baseUrl??Hi(new URL(s,location.href).href);await st(d,h);const c=await lt(d,h,t,.3,1);return t({stage:"complete",progress:1}),{story:d,baseUrl:h,assets:c,blobUrls:[],kind:"json"}}async function Cs(s,e,t,r){const i=new Uint8Array(s),n=xs(e);if(bs(i)){r({stage:"unpack",progress:.2,detail:"unzip"});const d=ks(i);if(r({stage:"unpack",progress:.35,detail:`${d.size} entries`}),n===".epub"||bn(d)){r({stage:"parse",progress:.4,detail:"epub"});const{story:h,blobUrls:c}=ws(d);await st(h,t??"");const u=await lt(h,t??"",r,.5,1);return r({stage:"complete",progress:1}),{story:h,baseUrl:t??"",assets:u,blobUrls:c,kind:"epub"}}if(n===It||Pn(d)){r({stage:"parse",progress:.4,detail:"fanci"});const{story:h,blobUrls:c}=_s(d);await st(h,t??"");const u=await lt(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=Ze(JSON.parse(new TextDecoder().decode(i))),o=t??(typeof location<"u"?location.href:"");await st(a,o);const l=await lt(a,o,r,.35,1);return r({stage:"complete",progress:1}),{story:a,baseUrl:o,assets:l,blobUrls:[],kind:"json"}}function $n(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 Er(s){return s instanceof ArrayBuffer||s instanceof Uint8Array||s instanceof Blob||typeof File<"u"&&s instanceof File}async function lt(s,e,t,r,i){var k;const n=new Map,a=new Map,o=new Map,l=new Map,d=Object.entries(s.assets),h=[];for(const b of s.pages)for(const f of b.blocks)if(f.type==="text"&&f.htmlSrc&&!f.html&&h.push(async()=>{const m=Ue(e,f.htmlSrc);l.set(`htmlSrc:${f.id}`,await Rt(m))}),(k=b.readAloud)!=null&&k.cues&&typeof b.readAloud.cues=="string"){const m=b.readAloud.cues;s.assets[m]||h.push(async()=>{const A=Ue(e,m);try{o.set(m,is(await Rt(A)))}catch{}})}const c=d.length+h.length||1;let u=0;const v=b=>{u+=1;const f=u/c,m=r+(i-r)*Math.min(1,f);t({stage:"assets",progress:m,count:u,total:c,detail:b})};return await Promise.all(d.map(async([b,f])=>{const m=Ue(e,f.src);f.type==="image"?n.set(b,await Rn(m)):f.type==="audio"?a.set(b,{url:m,channel:f.channel??"vo"}):f.type==="vtt"?o.set(b,is(await Rt(m))):f.type==="html"&&l.set(b,await Rt(m)),v(b)})),await Promise.all(h.map(async b=>{await b(),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 Rn(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 Rt(s){const e=await fetch(s);if(!e.ok)throw new Error(`Failed to load ${s}: ${e.status}`);return e.text()}function As(s){for(const e of s.blobUrls)try{URL.revokeObjectURL(e)}catch{}s.blobUrls.length=0}const Pr="auto",Mr=900;function oe(s){return s==="single"||s==="single-right"||s==="single-left"}function Ts(s){return s==="single"?"alternate":s==="single-right"?"right":s==="single-left"?"left":null}function Nr(s,e,t,r){return s==="responsive"?e>=t?"two-page":"single":s==="auto"?e>=r?"two-page":"single":s}function Ce(s,e){return{kind:"page",pageIndex:e,pageId:s[e].id}}const ye={kind:"blank"};function Ir(s){return{index:-1,left:ye,right:Ce(s,0)}}function $r(s){const e=s.length-1;return{index:-2,left:ye,right:Ce(s,e)}}function Rr(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:ye,right:Ce(s,n)}),n=1);n<a;){if(n+1<a){i.push({index:i.length,left:Ce(s,n),right:Ce(s,n+1)}),n+=2;continue}i.push({index:i.length,left:Ce(s,n),right:ye}),n+=1}return i}function Fr(s,e={},t="alternate"){if(s.length===0)return[];if(t==="right")return s.map((a,o)=>({index:o,left:ye,right:Ce(s,o)}));if(t==="left")return s.map((a,o)=>({index:o,left:Ce(s,o),right:ye}));const r=!!e.frontCover,i=!!e.backCover,n=s.length-1;return s.map((a,o)=>{const l=Ce(s,o);return r&&o===0?{index:o,left:l,right:ye}:i&&o===n?{index:o,left:ye,right:l}:o%2===0?{index:o,left:ye,right:l}:{index:o,left:l,right:ye}})}function Ft(s,e="two-page",t={}){const r=Ts(e);return r?Fr(s,t,r):Rr(s,t)}function Or(s){const e=[];return s.left.kind==="page"&&e.push(s.left.pageId),s.right.kind==="page"&&e.push(s.right.pageId),e}function Br(s){return s?s.left.kind==="page"?s.left.pageId:s.right.kind==="page"?s.right.pageId:null:null}function De(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 Fn{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??Pr,this.breakpoint=r.singleBreakpoint??Mr,this.covers={frontCover:!!e.frontCover,backCover:!!e.backCover},this.bookState=this.covers.frontCover?"closed-front":"open",this.rebuildCoverSpreads(),this.spreads=Ft(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 Or(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=Nr(this.preferredMode,e,t,this.breakpoint);if(!(!this.hasResolvedLayout||i!==this.resolvedMode)){this.spreadView.setLayoutMode(i);return}const a=this.currentPageIds[0]??Br(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=Ft(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);oe(i)?(this.bookState="open",this.spreadIndex=a?De(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?De(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=Ft(this.story.pages,this.resolvedMode,this.covers);const t=e??this.currentPageIds[0]??((r=this.story.pages[0])==null?void 0:r.id)??null;oe(this.resolvedMode)?(this.bookState="open",this.spreadIndex=t?De(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?De(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=De(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?Ir(this.story.pages):null,this.backCoverSpread=this.covers.backCover?$r(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 Ot(s){return s.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"")}function Bt(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 Vt(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 Vr(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"?Bt(l,"png"):o.type==="audio"?Bt(l,"mp3"):o.type==="vtt"?"vtt":Bt(l,"bin"),u=Ot(`assets/${a}.${c}`);t[u]||(t[u]=await Vt(l)),o.src=u;continue}const h=Ot(l);if(!t[h]){const c=Ue(i,l);t[h]=await Vt(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=Ot(`fonts/${a.family.replace(/\s+/g,"-")}.${Bt(o,"woff2")}`);t[d]||(t[d]=await Vt(o)),a.src=d}else{const d=Ot(o);t[d]||(t[d]=await Vt(Ue(i,o))),a.src=d}}t["story.json"]=ys(JSON.stringify(r,null,2));const n=fn(t,{level:6});return new Blob([n],{type:"application/zip"})}function zr(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 ct{cancel(e){}}y(ct,"id","base");const dt=new Map;function jr(s,e){dt.set(s,e)}function On(s){return dt.get(s)}function Zr(){return[...dt.keys()]}function Bn(s){return typeof s=="function"&&s.prototype instanceof ct}function Ls(s){if(s==null||s===""){const e=dt.get("default");if(!e)throw new Error('FlipStyle "default" is not registered');return new e}if(typeof s=="string"){const e=dt.get(s);if(!e){const t=Zr().join(", ")||"(none)";throw new Error(`Unknown flipStyle "${s}". Registered: ${t}`)}return new e}if(s instanceof ct)return s;if(Bn(s))return new s;throw new Error("flipStyle must be a string id, FlipStyle instance, or FlipStyle subclass")}const Ur=400;function Es(s){return s==null||!Number.isFinite(s)||s<=0?Ur:s}const Vn=["fc-turn-next","fc-turn-prev","fc-turn-next-right","fc-turn-prev-right","fc-turn-next-left","fc-turn-prev-left"];function Dr(s,e="both"){const t=e??"both";return t==="right"?s==="next"?"fc-turn-next-right":"fc-turn-prev-right":t==="left"?s==="next"?"fc-turn-next-left":"fc-turn-prev-left":s==="next"?"fc-turn-next":"fc-turn-prev"}function zn(s){return Dr(s.direction,s.contentSide)}function Ps(s){s.classList.remove(...Vn)}class zt extends ct{play(e){const{bookEl:t,durationMs:r}=e,i=zn(e);return t.style.setProperty("--fc-flip-duration",`${r}ms`),Ps(t),t.offsetWidth,t.classList.add(i),new Promise(n=>{const a=()=>{t.removeEventListener("animationend",o),Ps(t),n()},o=l=>{l.target!==e.rightLeaf&&l.target!==e.leftLeaf||a()};t.addEventListener("animationend",o),window.setTimeout(a,r+50)})}cancel(e){Ps(e.bookEl)}}y(zt,"id","default"),jr(zt.id,zt);const Ms=.035;function Hr(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*Ms)),y:Math.max(1,Math.round(s.height*Ms))}}function Ns(s){return!!(s.hardback&&(s.frontCover||s.backCover))}function jn(s){const e=s??{},t={left:He(e.x??0),top:He(e.y??0)};return e.width!=null&&(t.width=He(e.width)),e.height!=null&&(t.height=He(e.height)),t}function jt(s,e){const t=jn(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=He(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=He(e.y??0)):(e==null?void 0:e.verticalAlign)==="center"&&(s.style.top="50%",s.style.transform=`${s.style.transform||""} translateY(-50%)`.trim())}function He(s){return typeof s=="number"?`${s}px`:/^-?\d+(\.\d+)?$/.test(s)?`${s}px`:s}function Zn(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),jt(e,s.layout),e}function Un(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 Dn(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),jt(t,s.layout);let r=0,i=!1;return t.addEventListener("click",n=>{n.stopPropagation(),e(s.onTap??[]);const a=Un(r,i,s.requiredTaps);r=a.taps,i=a.completed,a.fireComplete&&e(s.onComplete??[])}),t}function Hn(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,jt(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 Wn(s,e){const t=document.createElement("div");return t.className="fc-block fc-block-text",t.dataset.blockId=s.id,jt(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 Is{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(Wn(a,o))}else a.type==="image"?this.element.appendChild(Hn(a,t.images.get(a.asset))):a.type==="hotspot"?this.element.appendChild(Dn(a,o=>r.onTapActions(o,this.element))):a.type==="area"&&this.element.appendChild(Zn(a))}destroy(){this.element.remove()}}class qn{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=Ls(i.flipStyle),this.flipSpeedMs=Es(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=Ls(e)}setFlipSpeed(e){this.flipSpeedMs=Es(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",oe(e)),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 i,n;if(t==="none"||this.turning)return(n=(i=this.flipStyle).cancel)==null||n.call(i,{bookEl:this.bookEl,viewportEl:this.element,leftLeaf:this.leftSlot,rightLeaf:this.rightSlot}),this.turning=!1,this.mountSpread(e),Promise.resolve();this.turning=!0;const r=this.flipContentSide();return this.flipStyle.play({bookEl:this.bookEl,viewportEl:this.element,leftLeaf:this.leftSlot,rightLeaf:this.rightSlot,direction:t,durationMs:this.flipSpeedMs,contentSide:r}).then(()=>{this.mountSpread(e),this.turning=!1}).catch(()=>{this.mountSpread(e),this.turning=!1})}flipContentSide(){const e=Ts(this.layoutMode);return e==="right"||e==="left"?e:"both"}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=Ns(this.story),d=l?Hr(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,k,b,f=0,m=0,A=0;if(l&&h)k=i+2*d.x,b=n+2*d.y,v=this.sizedScale(Math.min(e/k,t/b),i,n,e,t),this.bookEl.style.setProperty("--fc-page-width",`${k}px`),this.bookEl.style.setProperty("--fc-page-height",`${b}px`),this.bookEl.style.width=`${u?k:k*2}px`,this.bookEl.style.height=`${b}px`,f=u?0:-k*v,m=0,A=0,this.hardbackEl.hidden=!0;else if(c){k=(oe(a)?i:i*2)+2*d.x,b=n+2*d.y,v=this.sizedScale(Math.min(e/k,t/b),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=`${k}px`,this.hardbackEl.style.height=`${b}px`;const W=oe(a)?(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,oe(a)&&(r==null?void 0:r.left.kind)==="blank"?f=-i*v:f=0}else k=i*2,b=n,oe(a)||h?v=this.sizedScale(Math.min(e/i,t/n),i,n,e,t):v=this.sizedScale(Math.min(e/k,t/b),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:k}px`,this.bookEl.style.height=`${b}px`,this.hardbackEl.hidden=!0,u?f=0:(h||oe(a)&&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 p=l&&h?(i+2*d.x)*v:c?(oe(a)?i+2*d.x:i*2+2*d.x)*v:oe(a)||h?i*v:i*2*v,_=l&&(h||c)?(n+2*d.y)*v:n*v,F=0,O=0;this.stageZoom.mode==="fit-page"&&(_>t&&(O=(_-t)/2,_=t),(oe(a)||h||u?i:i*2)*v<=e&&p>e&&(F=(p-e)/2,p=e));const E=(c?m*v:0)-F,I=(c?A*v:0)-O;this.hardbackEl.style.left=`${-F}px`,this.hardbackEl.style.top=`${-O}px`,this.bookEl.style.left=`${E}px`,this.bookEl.style.top=`${I}px`,this.element.style.width=`${p}px`,this.element.style.height=`${_}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(!Ns(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 Is(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 Is(null,this.assets,{onTapActions:this.onTapActions});const t=this.story.pages[e.pageIndex];return new Is(t,this.assets,{onTapActions:this.onTapActions})}}function Wr(s,e){const t=s==null?void 0:s.container;if(!(t!=null&&t.send))return;const r=Jn(e.progress);t.send("progress",r),t.send("loading",{stage:e.stage,progress:r,count:e.count,total:e.total,detail:e.detail})}function Gn(s){var e,t;(t=(e=s==null?void 0:s.container)==null?void 0:e.send)==null||t.call(e,"loaded")}function Yn(){let s;return{promise:new Promise(t=>{s=t}),resolve:s}}function Jn(s){return Number.isNaN(s)?0:Math.min(1,Math.max(0,s))}function qr(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 Gr(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=Yn(),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 Yr(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 Xn=Object.freeze({left:0,top:0,width:16,height:16}),Zt=Object.freeze({rotate:0,vFlip:!1,hFlip:!1}),Jr=Object.freeze({...Xn,...Zt}),Kn=Object.freeze({...Jr,body:"",hidden:!1}),Qn=Object.freeze({width:null,height:null}),ea=Object.freeze({...Qn,...Zt});function ta(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 Xr(s,e){const t=ta(s,e);for(const r in Kn)r in Zt?r in s&&!(r in t)&&(t[r]=Zt[r]):r in e?t[r]=e[r]:r in s&&(t[r]=s[r]);return t}function sa(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 Kr(s,e,t){const r=s.icons,i=s.aliases||Object.create(null);let n={};function a(o){n=Xr(r[o]||i[o],n)}return a(e),t.forEach(a),Xr(s,n)}function ra(s,e){if(s.icons[e])return Kr(s,e,[]);const t=sa(s,[e])[e];return t?Kr(s,e,t):null}const ia=/(-?[0-9.]*[0-9]+[0-9.]*)/g,na=/^-?[0-9.]*[0-9]+[0-9.]*$/g;function Qr(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(ia);if(r===null||!r.length)return s;const i=[];let n=r.shift(),a=na.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 aa(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 oa(s,e){return s?"<defs>"+s+"</defs>"+e:e}function la(s,e,t){const r=aa(s);return oa(r.defs,e+r.content+t)}const ca=s=>s==="unset"||s==="undefined"||s==="none";function da(s,e){const t={...Jr,...s},r={...ea,...e},i={left:t.left,top:t.top,width:t.width,height:t.height};let n=t.body;[t,r].forEach(b=>{const f=[],m=b.hFlip,A=b.vFlip;let p=b.rotate;m?A?p+=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 _;switch(p<0&&(p-=Math.floor(p/4)*4),p=p%4,p){case 1:_=i.height/2+i.top,f.unshift("rotate(90 "+_.toString()+" "+_.toString()+")");break;case 2:f.unshift("rotate(180 "+(i.width/2+i.left).toString()+" "+(i.height/2+i.top).toString()+")");break;case 3:_=i.width/2+i.left,f.unshift("rotate(-90 "+_.toString()+" "+_.toString()+")")}p%2===1&&(i.left!==i.top&&(_=i.left,i.left=i.top,i.top=_),i.width!==i.height&&(_=i.width,i.width=i.height,i.height=_)),f.length&&(n=la(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=Qr(c,l/d)):(h=a==="auto"?l:a,c=o===null?Qr(h,d/l):o==="auto"?d:o);const u={},v=(b,f)=>{ca(f)||(u[b]=f.toString())};v("width",h),v("height",c);const k=[i.left,i.top,l,d];return u.viewBox=k.join(" "),{attributes:u,viewBox:k,body:n}}function ha(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 ua={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 fa(s,e={}){const t=ra(ua,s);if(!t)throw new Error(`Unknown MDI icon in subset: ${s}`);const r=e.size??"1.15rem",i=da(t,{height:r,width:r}),n=document.createElement("span");return n.className=e.className??"fc-icon",n.setAttribute("aria-hidden","true"),n.innerHTML=ha(i.body,i.attributes),n}function $s(s,e){const t=fa(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 pa={sound:!0,soundVolume:!0,vo:!0,voVolume:!0,sfx:!0,sfxVolume:!0,music:!0,musicVolume:!0,captions:!0};class Rs{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 be);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 v,k,b,f,m,A;if(this.root=e,this.loaded=t,this.springroll=r,this.chromeHiddenByOptions=!!n.hidden,h)for(const[p,_]of Object.entries(h))this.pageGames.set(p,_);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:((v=n.labels)==null?void 0:v.prev)??"Prev",read:((k=n.labels)==null?void 0:k.read)??"Read",next:((b=n.labels)==null?void 0:b.next)??"Next"},u={prev:((f=n.ariaLabels)==null?void 0:f.prev)??"Previous page",read:((m=n.ariaLabels)==null?void 0:m.read)??"Read aloud",next:((A=n.ariaLabels)==null?void 0:A.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),$s(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),$s(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),$s(this.btnNext,{icon:"chevron-right",label:c.next,iconOnly:!0}),this.chrome.append(this.btnPrev,this.btnRead,this.btnNext),this.spreadView=new qn(t.story,t.assets,(p,_)=>this.handleTapActions(p,_),{flipStyle:a??"default",flipSpeed:o}),this.pager=new Fn(t.story,this.spreadView,{mode:l,singleBreakpoint:d}),this.readAloud=new ii(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=ci(this.stage,{onSwipeLeft:()=>{this.isReaderNavBlocked()||this.next()},onSwipeRight:()=>{this.isReaderNavBlocked()||this.prev()}}),this.element.addEventListener("keydown",p=>{this.isReaderNavBlocked()||(p.key==="ArrowRight"?(p.preventDefault(),this.next()):p.key==="ArrowLeft"?(p.preventDefault(),this.prev()):p.key===" "&&(p.preventDefault(),this.playReadAloud()))}),this.readAloud.onCaption(p=>{this.captionsEl.textContent=p??"",this.captionsEl.hidden=!p})}static async create(e,t){const r={...pa,...t.features};let i=t.springroll??null,n=null;if(!i){const h=await Gr(r);h&&(i=h.app,n=h.loadGate,ma(i))}const a=[];t.onProgress&&a.push(t.onProgress);const o=h=>{Wr(i,h);for(const c of a)c(h)};o({stage:"fetch",progress:0,detail:"start"});const l=await $t(t.story,{baseUrl:t.baseUrl,name:t.storyName,onProgress:o});n==null||n.resolve(),await Yr(i);const d=new Rs(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 Ds(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 $t(e,{name:t??(e instanceof File?e.name:void 0)});As(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(!Wt(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=ga(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 Vr(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();zr(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(),As(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=qr(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!=="two-page"&&(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)??Us(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 ga(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 ma(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 We(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 Oe(s,e){const{width:t,height:r}=e;return{x:Math.round(We(s==null?void 0:s.x,0,t)),y:Math.round(We(s==null?void 0:s.y,0,r)),width:Math.round(We(s==null?void 0:s.width,t,t)),height:Math.round(We(s==null?void 0:s.height,r*.25,r))}}function Ut(s){return typeof s=="string"&&/%$/.test(s.trim())}function ht(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 ut(s,e,t,r,i,n,a={}){const o=Oe(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=Ut(i==null?void 0:i.x)||Ut(i==null?void 0:i.y)||Ut(i==null?void 0:i.width)||Ut(i==null?void 0:i.height),c=a.preserveHeight&&(i==null?void 0:i.height)!=null?i.height:r;return h?{...i,x:ht(s,n.width),y:ht(e,n.height),width:ht(t,n.width),height:typeof c=="string"||typeof c=="number"?typeof c=="number"?ht(c,n.height):c:ht(r,n.height)}:{...i,x:s,y:e,width:t,height:typeof c=="number"?Math.round(c):c}}function ei(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 ya=1;function va(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=Oe(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 Fs(s){return typeof DOMParser>"u"?s.replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim():(new DOMParser().parseFromString(s,"text/html").body.textContent??"").replace(/\u00a0/g," ")}function ti(s){return`<p>${s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/\n/g,"<br/>")}</p>`}function si(s){return s.type==="text"||s.type==="image"||s.type==="hotspot"||s.type==="area"}function Os(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 k=o.get(u),b=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),p=c.text??"",_=k&&k.type==="text"?k:void 0,F=_?Fs(_.html??""):"",O=_&&F===p&&_.html?_.html:ti(p),E=_==null?void 0:_.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:ut(b,f,m,A,_==null?void 0:_.layout,t,{preserveHeight:!0}),html:O,style:I,htmlSrc:_==null?void 0:_.htmlSrc})}else if(v==="image"){const m=Math.round((c.width??0)*(c.scaleX??1)),A=Math.round((c.height??0)*(c.scaleY??1)),p=c.assetId??(k&&k.type==="image"?k.asset:void 0);if(!p)continue;const _=k&&k.type==="image"?k:void 0,F=ut(b,f,m,A,_==null?void 0:_.layout,t),O=c.fit??((h=_==null?void 0:_.layout)==null?void 0:h.fit);O&&(F.fit=O),l.push({id:u,type:"image",asset:p,layout:F,className:_==null?void 0:_.className})}else if(v==="hotspot"){const m=Math.round((c.width??0)*(c.scaleX??1)),A=Math.round((c.height??0)*(c.scaleY??1)),p=k&&k.type==="hotspot"?k:void 0;l.push({id:u,type:"hotspot",layout:ut(b,f,m,A,p==null?void 0:p.layout,t),onTap:c.onTap??(p==null?void 0:p.onTap)??[],onComplete:c.onComplete??(p==null?void 0:p.onComplete)??[],requiredTaps:c.requiredTaps??(p==null?void 0:p.requiredTaps),ariaLabel:c.ariaLabel??(p==null?void 0:p.ariaLabel)})}else if(v==="area"){const m=Math.round((c.width??0)*(c.scaleX??1)),A=Math.round((c.height??0)*(c.scaleY??1)),p=k&&k.type==="area"?k:void 0,_=c.game??(p==null?void 0:p.game);if(!_)continue;l.push({id:u,type:"area",layout:ut(b,f,m,A,p==null?void 0:p.layout,t),game:_,params:c.params??(p==null?void 0:p.params),ariaLabel:c.ariaLabel??(p==null?void 0:p.ariaLabel),requireComplete:c.requireComplete??(p==null?void 0:p.requireComplete)??!1})}}for(const c of e.blocks)si(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 Bs(s,e,t){var n,a,o,l,d,h,c,u,v,k,b;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(si(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=Oe(f.layout,t),p=We((l=f.style)==null?void 0:l.fontSize,18)||18;i.push({kind:"text",blockId:f.id,text:Fs(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:p,fill:((h=f.style)==null?void 0:h.color)??"#1f1a14",textAlign:((c=f.style)==null?void 0:c.textAlign)??"left",lineHeight:ei((u=f.style)==null?void 0:u.lineHeight,p,1.35),fontWeight:(v=f.style)==null?void 0:v.fontWeight,fontStyle:(k=f.style)==null?void 0:k.fontStyle})}else if(f.type==="image"){const m=e.images.get(f.asset);if(!(m!=null&&m.src))continue;const A=Oe(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:(b=f.layout)==null?void 0:b.fit})}else if(f.type==="hotspot"){const m=Oe(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=Oe(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 ba(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 ri(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 ka(s){return`${s}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function wa(s,e){return{...s,left:s.left+e}}function Sa(s,e,t,r){const i=[];let n=null,a=null;if(s){const o=Bs(s,t,r);n=o.background,i.push(...o.objects)}if(e){const o=Bs(e,t,r);a=o.background;for(const l of o.objects)i.push(wa(l,r.width))}return{pageSize:r,spreadWidth:r.width*2,leftBackground:n,rightBackground:a,objects:i}}function _a(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=ba(c),k=u+v,b=k<=a+.5,f=u>=a-.5;if(b){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(k-a));o.push({...c,width:m,scaleX:1,scaleY:1,height:ri(c)}),l.push({...c,blockId:ka(c.blockId),left:0,width:A,scaleX:1,scaleY:1,height:ri(c)})}const d=e!=null?Os(o,e,r,i==null?void 0:i.left,n):null,h=t!=null?Os(l,t,r,i==null?void 0:i.right,n):null;return{left:d,right:h}}return w.CueTimeline=zs,w.DEFAULT_FLIP_SPEED_MS=Ur,w.DEFAULT_LAYOUT_MODE=Pr,w.DEFAULT_SINGLE_BREAKPOINT=Mr,w.DefaultFlipStyle=zt,w.FABRIC_CSS_FONT_SIZE_MULT=ya,w.FANCI_EXTENSION=It,w.FlipStyle=ct,w.HARDBACK_EDGE_RATIO=Ms,w.Storybook=Rs,w.bindApplication=qr,w.boxToPixels=Oe,w.buildBackCoverSpread=$r,w.buildFrontCoverSpread=Ir,w.buildSingleSpreads=Fr,w.buildSpreads=Ft,w.buildTwoPageSpreads=Rr,w.clearPageGameRegistry=li,w.contentPageIds=Or,w.createFlipStyle=Ls,w.createSpringrollApplication=Gr,w.downloadBlob=zr,w.extensionOf=Hs,w.fabricLikeToPage=Os,w.findFanciFile=di,w.findSpreadIndexForPage=De,w.findStoryJsonPath=Ss,w.flipTurnClass=Dr,w.getRegisteredFlipStyle=On,w.getRegisteredPageGame=Us,w.hardbackEnabled=Ns,w.hardbackOverhang=Hr,w.htmlToPlainText=Fs,w.isAreaNavGated=Ds,w.isFanciFile=Wt,w.isSingleLayout=oe,w.listRegisteredFlipStyles=Zr,w.listRegisteredPageGames=ai,w.loadEpubFromBytes=vn,w.loadEpubFromZip=ws,w.loadFanciFromBytes=Tn,w.loadFanciFromZip=_s,w.loadStory=$t,w.packFanci=Vr,w.pageToFabricLike=Bs,w.pagesToSpreadFabricLike=Sa,w.parseStory=Ze,w.parseVtt=is,w.plainTextToHtml=ti,w.primaryPageId=Br,w.registerFlipStyle=jr,w.registerPageGame=ni,w.reportSpringrollLoaded=Gn,w.reportSpringrollProgress=Wr,w.resolveCssLineHeight=ei,w.resolveFlipSpeedMs=Es,w.resolveLayoutMode=Nr,w.revokeLoadedStory=As,w.scaleBlocksToPageSize=va,w.serializeLayoutBox=ut,w.singlePageSide=Ts,w.spreadFabricLikeToPages=_a,w.storySchema=lr,w.toPx=We,w.unregisterPageGame=oi,w.waitForSpringrollReady=Yr,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"}),w})({});
|