@pmate/account-sdk 0.0.1

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.
Files changed (48) hide show
  1. package/dist/api/AccountService.d.ts +11 -0
  2. package/dist/api/Api.d.ts +11 -0
  3. package/dist/api/EntityService.d.ts +9 -0
  4. package/dist/api/ProfileService.d.ts +28 -0
  5. package/dist/api/cacheInMem.d.ts +1 -0
  6. package/dist/api/index.d.ts +4 -0
  7. package/dist/app.config.d.ts +16 -0
  8. package/dist/atoms/accountAtom.d.ts +5 -0
  9. package/dist/atoms/accountProfileAtom.d.ts +3 -0
  10. package/dist/atoms/createProfileAtom.d.ts +7 -0
  11. package/dist/atoms/index.d.ts +16 -0
  12. package/dist/atoms/learningLangAtom.d.ts +1 -0
  13. package/dist/atoms/localStorageAtom.d.ts +8 -0
  14. package/dist/atoms/loginAtom.d.ts +3 -0
  15. package/dist/atoms/motherTongueAtom.d.ts +1 -0
  16. package/dist/atoms/profileAtom.d.ts +6 -0
  17. package/dist/atoms/profileDraftAtom.d.ts +7 -0
  18. package/dist/atoms/profilesAtom.d.ts +2 -0
  19. package/dist/atoms/sessionCheckAtom.d.ts +3 -0
  20. package/dist/atoms/switchProfileAtom.d.ts +4 -0
  21. package/dist/atoms/updateProfileAtom.d.ts +3 -0
  22. package/dist/atoms/uploadAvatarAtom.d.ts +8 -0
  23. package/dist/atoms/userLogoutAtom.d.ts +3 -0
  24. package/dist/atoms/userSettingsAtom.d.ts +3 -0
  25. package/dist/components/AuthProviderV2.d.ts +15 -0
  26. package/dist/components/index.d.ts +1 -0
  27. package/dist/hooks/index.d.ts +3 -0
  28. package/dist/hooks/useAppBackgroundStyle.d.ts +3 -0
  29. package/dist/hooks/useAuthApp.d.ts +21 -0
  30. package/dist/hooks/useAuthSnapshot.d.ts +8 -0
  31. package/dist/hooks/useProfileStepFlow.d.ts +13 -0
  32. package/dist/index.cjs.js +22 -0
  33. package/dist/index.cjs.js.map +1 -0
  34. package/dist/index.d.ts +8 -0
  35. package/dist/index.es.js +2800 -0
  36. package/dist/index.es.js.map +1 -0
  37. package/dist/types/account.types.d.ts +25 -0
  38. package/dist/types/profile.d.ts +5 -0
  39. package/dist/utils/AccountManagerV2.d.ts +43 -0
  40. package/dist/utils/Redirect.d.ts +4 -0
  41. package/dist/utils/accountStorage.d.ts +5 -0
  42. package/dist/utils/errors.d.ts +2 -0
  43. package/dist/utils/index.d.ts +6 -0
  44. package/dist/utils/profileStep.d.ts +6 -0
  45. package/dist/utils/resolveAppId.d.ts +1 -0
  46. package/dist/utils/selectedProfileStorage.d.ts +4 -0
  47. package/dist/utils/tokenStorage.d.ts +4 -0
  48. package/package.json +50 -0
@@ -0,0 +1,11 @@
1
+ import { AuthLoginResponse, AuthRequest, AuthSession, VCodeIssueRequest, VCodeIssueResult } from "@pmate/meta";
2
+ export declare class AccountService {
3
+ private static sessionCached;
4
+ static vcode(payload: VCodeIssueRequest): Promise<VCodeIssueResult>;
5
+ static login(request: AuthRequest): Promise<AuthLoginResponse>;
6
+ static logout(token?: string): Promise<{
7
+ success: boolean;
8
+ }>;
9
+ static session(token?: string): Promise<AuthSession | null>;
10
+ private static authRequest;
11
+ }
@@ -0,0 +1,11 @@
1
+ import { Maybe } from "@pchip/utils";
2
+ export declare class Api {
3
+ static get<T>(url: string): Promise<T | null>;
4
+ static post<T>(url: string, body: unknown): Promise<T>;
5
+ static put<T>(url: string, body: unknown): Promise<Maybe<T>>;
6
+ static getFile<T>(url: string): Promise<T | null>;
7
+ static getFile<T>(url: string, type: "json"): Promise<T | null>;
8
+ static getFile(url: string, type: "text"): Promise<string | null>;
9
+ static getFile<T>(url: string, type: "log"): Promise<Maybe<T[]>>;
10
+ static exists(url: string | Maybe<string>): Promise<boolean>;
11
+ }
@@ -0,0 +1,9 @@
1
+ import { GroupInfo, Profile } from "@pmate/meta";
2
+ export declare class EntityService {
3
+ static entity<T>(id: string): Promise<T | null>;
4
+ static getProfile(id: string): Promise<Profile | null>;
5
+ static getGroup(id: string): Promise<GroupInfo | null>;
6
+ static entities<T extends {
7
+ id?: string;
8
+ }>(ids: string[]): Promise<Record<string, T>>;
9
+ }
@@ -0,0 +1,28 @@
1
+ import { AccountState, CreateProfileRequest, Profile, ProfileScope, UpdateProfileRequest } from "@pmate/meta";
2
+ export declare class ProfileService {
3
+ static createProfile(req: CreateProfileRequest): Promise<Profile>;
4
+ static updateProfile(req: UpdateProfileRequest): Promise<void>;
5
+ static getProfiles(account: AccountState): Promise<Profile[]>;
6
+ static getProfilesByScope(scope: ProfileScope): Promise<Profile[]>;
7
+ static updateAvatar(req: {
8
+ user: string;
9
+ base64: string;
10
+ filename: string;
11
+ }): Promise<string>;
12
+ static uploadMsgImage(req: {
13
+ user: string;
14
+ base64: string;
15
+ filename: string;
16
+ }): Promise<string>;
17
+ static updateMyVoice(req: {
18
+ user: string;
19
+ base64: string;
20
+ text: string;
21
+ }): Promise<string>;
22
+ static uploadUserFile(req: {
23
+ user: string;
24
+ base64: string;
25
+ filename: string;
26
+ }): Promise<string>;
27
+ private static uploadToUploaderService;
28
+ }
@@ -0,0 +1 @@
1
+ export declare const cacheInMem: <T extends (...args: any[]) => Promise<any>>(fn: T, prefix: string, timeout: number) => T;
@@ -0,0 +1,4 @@
1
+ export * from "./Api";
2
+ export * from "./AccountService";
3
+ export * from "./ProfileService";
4
+ export * from "./EntityService";
@@ -0,0 +1,16 @@
1
+ export declare const DEFAULT_APP_ID = "@pmate/chat";
2
+ export declare const SHUANG_APP_ID = "shuang";
3
+ export interface ProfileStep {
4
+ type: "nickname" | "learning-language" | "mother-tongue" | "gender" | "is-adult" | "age";
5
+ title: string;
6
+ required: boolean;
7
+ }
8
+ export interface AppConfig {
9
+ id: string;
10
+ name: string;
11
+ icon: string;
12
+ background: string;
13
+ welcomeText: string;
14
+ profiles: ProfileStep[];
15
+ }
16
+ export declare const getAppConfig: (appId: string | null) => AppConfig;
@@ -0,0 +1,5 @@
1
+ import { AccountSnapshot as AccountSnapshotType } from "../types/account.types";
2
+ export type AccountSnapshot = AccountSnapshotType;
3
+ export declare const accountAtom: import("jotai").PrimitiveAtom<AccountSnapshotType> & {
4
+ init: AccountSnapshotType;
5
+ };
@@ -0,0 +1,3 @@
1
+ import { AccountState, Profile } from "@pmate/meta";
2
+ export declare const accountStateAtom: import("jotai").Atom<AccountState | undefined>;
3
+ export declare const profileAtom: import("jotai").Atom<Profile | undefined>;
@@ -0,0 +1,7 @@
1
+ type CreateProfileParams = {
2
+ nickName: string;
3
+ };
4
+ export declare const createProfileAtom: import("jotai").WritableAtom<null, [CreateProfileParams], Promise<import("@pmate/meta").Profile>> & {
5
+ init: null;
6
+ };
7
+ export {};
@@ -0,0 +1,16 @@
1
+ export * from "./uploadAvatarAtom";
2
+ export * from "./accountAtom";
3
+ export * from "./accountProfileAtom";
4
+ export * from "./switchProfileAtom";
5
+ export * from "./createProfileAtom";
6
+ export * from "./profileDraftAtom";
7
+ export * from "./profileAtom";
8
+ export * from "./profilesAtom";
9
+ export * from "./updateProfileAtom";
10
+ export * from "./loginAtom";
11
+ export * from "./sessionCheckAtom";
12
+ export * from "./userLogoutAtom";
13
+ export * from "./motherTongueAtom";
14
+ export * from "./learningLangAtom";
15
+ export * from "./userSettingsAtom";
16
+ export * from "./localStorageAtom";
@@ -0,0 +1 @@
1
+ export declare const learningLangAtom: import("jotai").Atom<"en" | "zh-CN" | "zh-TW" | "ko-KR" | "es-ES" | "fr-FR" | "ja-JP" | "de-DE" | "ar-SA" | "el-GR" | "fi-FI" | "fil-PH" | "hi-IN" | "pt-BR" | "pt-PT" | "ru-RU" | "ta-IN" | "uk-UA">;
@@ -0,0 +1,8 @@
1
+ import { type AtomFamily } from "jotai-family";
2
+ import type { WritableAtom } from "jotai";
3
+ export declare enum LSKEYS {
4
+ USER_SETTINGS = "user-settings"
5
+ }
6
+ type LocalStorageJsonAtomFamily = AtomFamily<LSKEYS, WritableAtom<any, [any], void>>;
7
+ export declare const localStorageJsonAtom: LocalStorageJsonAtomFamily;
8
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const loginAtom: import("jotai").WritableAtom<null, [], Promise<import("@pmate/meta").AccountState>> & {
2
+ init: null;
3
+ };
@@ -0,0 +1 @@
1
+ export declare const motherTongueAtom: import("jotai").Atom<"en" | "zh-CN" | "zh-TW" | "ko-KR" | "es-ES" | "fr-FR" | "ja-JP" | "de-DE" | "ar-SA" | "el-GR" | "fi-FI" | "fil-PH" | "hi-IN" | "pt-BR" | "pt-PT" | "ru-RU" | "ta-IN" | "uk-UA">;
@@ -0,0 +1,6 @@
1
+ import { Profile } from "@pmate/meta";
2
+ import { type AtomFamily } from "jotai-family";
3
+ import type { WritableAtom } from "jotai";
4
+ type ProfileByIdAtomFamily = AtomFamily<string, WritableAtom<Promise<Profile | null>, [], void>>;
5
+ export declare const profileByIdAtom: ProfileByIdAtomFamily;
6
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { ProfileDraft } from "../types/profile";
2
+ /**
3
+ * Temporary profile info during registration flow
4
+ */
5
+ export declare const profileDraftAtom: import("jotai").PrimitiveAtom<ProfileDraft> & {
6
+ init: ProfileDraft;
7
+ };
@@ -0,0 +1,2 @@
1
+ import { Profile } from "@pmate/meta";
2
+ export declare const profilesAtom: import("jotai").Atom<import("@pchip/utils").Loadable<Profile[]>>;
@@ -0,0 +1,3 @@
1
+ export declare const sessionCheckAtom: import("jotai").WritableAtom<null, [], Promise<import("@pmate/meta").AuthSession | null>> & {
2
+ init: null;
3
+ };
@@ -0,0 +1,4 @@
1
+ import { Profile } from "@pmate/meta";
2
+ export declare const switchProfileAtom: import("jotai").WritableAtom<null, [profile: Profile], void> & {
3
+ init: null;
4
+ };
@@ -0,0 +1,3 @@
1
+ export declare const updateProfileAtom: import("jotai").WritableAtom<null, [profileId: string, updates: Record<string, any>], Promise<void>> & {
2
+ init: null;
3
+ };
@@ -0,0 +1,8 @@
1
+ type UploadAvatarParams = {
2
+ file: File;
3
+ userId: string;
4
+ };
5
+ export declare const uploadAvatarAtom: import("jotai").WritableAtom<null, [UploadAvatarParams], Promise<string>> & {
6
+ init: null;
7
+ };
8
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const userLogoutAtom: import("jotai").WritableAtom<null, [], Promise<void>> & {
2
+ init: null;
3
+ };
@@ -0,0 +1,3 @@
1
+ import { UserSettings } from "@pmate/meta";
2
+ import { WritableAtom } from "jotai";
3
+ export declare const userSettingsAtom: <T extends keyof UserSettings>(key: T) => WritableAtom<UserSettings[T], [value: UserSettings[T]], void>;
@@ -0,0 +1,15 @@
1
+ import { PropsWithChildren } from "react";
2
+ export type AuthRoute = string | {
3
+ path: string;
4
+ behavior?: "redirect" | "prompt";
5
+ };
6
+ type AuthProviderV2Props = PropsWithChildren<{
7
+ app: string;
8
+ authRoutes?: AuthRoute[];
9
+ onLoginSuccess?: () => void | Promise<void>;
10
+ rtcProvider?: React.ComponentType<{
11
+ children: React.ReactNode;
12
+ }>;
13
+ }>;
14
+ export declare const AuthProviderV2: ({ app, authRoutes, rtcProvider: RtcProvider, children, }: AuthProviderV2Props) => string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
15
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./AuthProviderV2";
@@ -0,0 +1,3 @@
1
+ export * from "./useProfileStepFlow";
2
+ export * from "./useAuthApp";
3
+ export * from "./useAppBackgroundStyle";
@@ -0,0 +1,3 @@
1
+ export declare const useAppBackgroundStyle: () => {
2
+ background: string;
3
+ };
@@ -0,0 +1,21 @@
1
+ import type { ProfileStepType } from "../utils/profileStep";
2
+ type UseAuthAppOptions = {
3
+ app?: string;
4
+ redirect?: string;
5
+ };
6
+ type AuthAppRedirectOptions = {
7
+ app?: string;
8
+ redirect?: string;
9
+ };
10
+ type AuthProfileRedirectOptions = AuthAppRedirectOptions & {
11
+ step?: ProfileStepType;
12
+ };
13
+ export declare const useAuthApp: (options?: UseAuthAppOptions) => {
14
+ app: string;
15
+ login: (overrides?: AuthAppRedirectOptions) => void;
16
+ logout: (overrides?: AuthAppRedirectOptions) => void;
17
+ selectProfile: (overrides?: AuthAppRedirectOptions) => void;
18
+ createProfile: (overrides?: AuthProfileRedirectOptions) => void;
19
+ updateProfile: (overrides?: AuthProfileRedirectOptions) => void;
20
+ };
21
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { AccountSnapshot, AuthBehaviors } from "../types/account.types";
2
+ export declare const useAuthSnapshot: ({ app, behaviors, }: {
3
+ app: string;
4
+ behaviors: AuthBehaviors;
5
+ }) => {
6
+ loading: boolean;
7
+ snapshot: AccountSnapshot;
8
+ };
@@ -0,0 +1,13 @@
1
+ import { ProfileStepType } from "../utils/profileStep";
2
+ type UseProfileStepFlowParams = {
3
+ params: URLSearchParams;
4
+ };
5
+ export declare const useProfileStepFlow: ({ params, }: UseProfileStepFlowParams) => {
6
+ activeStep: "nickname" | "learning-language" | "mother-tongue" | "gender" | "is-adult" | "age";
7
+ appProfileSteps: ("nickname" | "learning-language" | "mother-tongue" | "gender" | "is-adult" | "age")[];
8
+ buildStepUrl: (next: ProfileStepType) => string;
9
+ createSteps: ProfileStepType[];
10
+ isCreateFlowStep: boolean;
11
+ nextStep: ProfileStepType | undefined;
12
+ };
13
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const oe=require("jotai"),Pe=require("@pchip/utils"),ut=require("jotai-family"),Qe=require("@pmate/uikit"),je=require("@pmate/lang"),bt=require("@pmate/meta"),ne=require("react/jsx-runtime"),q=require("react"),et=require("react-router-dom");function Yt(p,s){return s.forEach((function(g){g&&typeof g!="string"&&!Array.isArray(g)&&Object.keys(g).forEach((function(o){if(o!=="default"&&!(o in p)){var e=Object.getOwnPropertyDescriptor(g,o);Object.defineProperty(p,o,e.get?e:{enumerable:!0,get:function(){return g[o]}})}}))})),Object.freeze(p)}function Rt(p,s){return new Promise((function(g,o){let e;return Zt(p).then((function(t){try{return e=t,g(new Blob([s.slice(0,2),e,s.slice(2)],{type:"image/jpeg"}))}catch(l){return o(l)}}),o)}))}const Zt=p=>new Promise(((s,g)=>{const o=new FileReader;o.addEventListener("load",(({target:{result:e}})=>{const t=new DataView(e);let l=0;if(t.getUint16(l)!==65496)return g("not a valid JPEG");for(l+=2;;){const a=t.getUint16(l);if(a===65498)break;const w=t.getUint16(l+2);if(a===65505&&t.getUint32(l+4)===1165519206){const y=l+10;let r;switch(t.getUint16(y)){case 18761:r=!0;break;case 19789:r=!1;break;default:return g("TIFF header contains invalid endian")}if(t.getUint16(y+2,r)!==42)return g("TIFF header contains invalid version");const i=t.getUint32(y+4,r),n=y+i+2+12*t.getUint16(y+i,r);for(let c=y+i+2;c<n;c+=12)if(t.getUint16(c,r)==274){if(t.getUint16(c+2,r)!==3)return g("Orientation data type is invalid");if(t.getUint32(c+4,r)!==1)return g("Orientation data count is invalid");t.setUint16(c+8,1,r);break}return s(e.slice(l,l+2+w))}l+=2+w}return s(new Blob)})),o.readAsArrayBuffer(p)}));var Ke={},Xt={get exports(){return Ke},set exports(p){Ke=p}};(function(p){var s,g,o={};Xt.exports=o,o.parse=function(e,t){for(var l=o.bin.readUshort,a=o.bin.readUint,w=0,y={},r=new Uint8Array(e),i=r.length-4;a(r,i)!=101010256;)i--;w=i,w+=4;var n=l(r,w+=4);l(r,w+=2);var c=a(r,w+=2),m=a(r,w+=4);w+=4,w=m;for(var v=0;v<n;v++){a(r,w),w+=4,w+=4,w+=4,a(r,w+=4),c=a(r,w+=4);var T=a(r,w+=4),b=l(r,w+=4),M=l(r,w+2),k=l(r,w+4);w+=6;var x=a(r,w+=8);w+=4,w+=b+M+k,o._readLocal(r,x,y,c,T,t)}return y},o._readLocal=function(e,t,l,a,w,y){var r=o.bin.readUshort,i=o.bin.readUint;i(e,t),r(e,t+=4),r(e,t+=2);var n=r(e,t+=2);i(e,t+=2),i(e,t+=4),t+=4;var c=r(e,t+=8),m=r(e,t+=2);t+=2;var v=o.bin.readUTF8(e,t,c);if(t+=c,t+=m,y)l[v]={size:w,csize:a};else{var T=new Uint8Array(e.buffer,t);if(n==0)l[v]=new Uint8Array(T.buffer.slice(t,t+a));else{if(n!=8)throw"unknown compression method: "+n;var b=new Uint8Array(w);o.inflateRaw(T,b),l[v]=b}}},o.inflateRaw=function(e,t){return o.F.inflate(e,t)},o.inflate=function(e,t){return e[0],e[1],o.inflateRaw(new Uint8Array(e.buffer,e.byteOffset+2,e.length-6),t)},o.deflate=function(e,t){t==null&&(t={level:6});var l=0,a=new Uint8Array(50+Math.floor(1.1*e.length));a[l]=120,a[l+1]=156,l+=2,l=o.F.deflateRaw(e,a,l,t.level);var w=o.adler(e,0,e.length);return a[l+0]=w>>>24&255,a[l+1]=w>>>16&255,a[l+2]=w>>>8&255,a[l+3]=w>>>0&255,new Uint8Array(a.buffer,0,l+4)},o.deflateRaw=function(e,t){t==null&&(t={level:6});var l=new Uint8Array(50+Math.floor(1.1*e.length)),a=o.F.deflateRaw(e,l,a,t.level);return new Uint8Array(l.buffer,0,a)},o.encode=function(e,t){t==null&&(t=!1);var l=0,a=o.bin.writeUint,w=o.bin.writeUshort,y={};for(var r in e){var i=!o._noNeed(r)&&!t,n=e[r],c=o.crc.crc(n,0,n.length);y[r]={cpr:i,usize:n.length,crc:c,file:i?o.deflateRaw(n):n}}for(var r in y)l+=y[r].file.length+30+46+2*o.bin.sizeUTF8(r);l+=22;var m=new Uint8Array(l),v=0,T=[];for(var r in y){var b=y[r];T.push(v),v=o._writeHeader(m,v,r,b,0)}var M=0,k=v;for(var r in y)b=y[r],T.push(v),v=o._writeHeader(m,v,r,b,1,T[M++]);var x=v-k;return a(m,v,101010256),v+=4,w(m,v+=4,M),w(m,v+=2,M),a(m,v+=2,x),a(m,v+=4,k),v+=4,v+=2,m.buffer},o._noNeed=function(e){var t=e.split(".").pop().toLowerCase();return"png,jpg,jpeg,zip".indexOf(t)!=-1},o._writeHeader=function(e,t,l,a,w,y){var r=o.bin.writeUint,i=o.bin.writeUshort,n=a.file;return r(e,t,w==0?67324752:33639248),t+=4,w==1&&(t+=2),i(e,t,20),i(e,t+=2,0),i(e,t+=2,a.cpr?8:0),r(e,t+=2,0),r(e,t+=4,a.crc),r(e,t+=4,n.length),r(e,t+=4,a.usize),i(e,t+=4,o.bin.sizeUTF8(l)),i(e,t+=2,0),t+=2,w==1&&(t+=2,t+=2,r(e,t+=6,y),t+=4),t+=o.bin.writeUTF8(e,t,l),w==0&&(e.set(n,t),t+=n.length),t},o.crc={table:(function(){for(var e=new Uint32Array(256),t=0;t<256;t++){for(var l=t,a=0;a<8;a++)1&l?l=3988292384^l>>>1:l>>>=1;e[t]=l}return e})(),update:function(e,t,l,a){for(var w=0;w<a;w++)e=o.crc.table[255&(e^t[l+w])]^e>>>8;return e},crc:function(e,t,l){return 4294967295^o.crc.update(4294967295,e,t,l)}},o.adler=function(e,t,l){for(var a=1,w=0,y=t,r=t+l;y<r;){for(var i=Math.min(y+5552,r);y<i;)w+=a+=e[y++];a%=65521,w%=65521}return w<<16|a},o.bin={readUshort:function(e,t){return e[t]|e[t+1]<<8},writeUshort:function(e,t,l){e[t]=255&l,e[t+1]=l>>8&255},readUint:function(e,t){return 16777216*e[t+3]+(e[t+2]<<16|e[t+1]<<8|e[t])},writeUint:function(e,t,l){e[t]=255&l,e[t+1]=l>>8&255,e[t+2]=l>>16&255,e[t+3]=l>>24&255},readASCII:function(e,t,l){for(var a="",w=0;w<l;w++)a+=String.fromCharCode(e[t+w]);return a},writeASCII:function(e,t,l){for(var a=0;a<l.length;a++)e[t+a]=l.charCodeAt(a)},pad:function(e){return e.length<2?"0"+e:e},readUTF8:function(e,t,l){for(var a,w="",y=0;y<l;y++)w+="%"+o.bin.pad(e[t+y].toString(16));try{a=decodeURIComponent(w)}catch{return o.bin.readASCII(e,t,l)}return a},writeUTF8:function(e,t,l){for(var a=l.length,w=0,y=0;y<a;y++){var r=l.charCodeAt(y);if((4294967168&r)==0)e[t+w]=r,w++;else if((4294965248&r)==0)e[t+w]=192|r>>6,e[t+w+1]=128|r>>0&63,w+=2;else if((4294901760&r)==0)e[t+w]=224|r>>12,e[t+w+1]=128|r>>6&63,e[t+w+2]=128|r>>0&63,w+=3;else{if((4292870144&r)!=0)throw"e";e[t+w]=240|r>>18,e[t+w+1]=128|r>>12&63,e[t+w+2]=128|r>>6&63,e[t+w+3]=128|r>>0&63,w+=4}}return w},sizeUTF8:function(e){for(var t=e.length,l=0,a=0;a<t;a++){var w=e.charCodeAt(a);if((4294967168&w)==0)l++;else if((4294965248&w)==0)l+=2;else if((4294901760&w)==0)l+=3;else{if((4292870144&w)!=0)throw"e";l+=4}}return l}},o.F={},o.F.deflateRaw=function(e,t,l,a){var w=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]][a],y=o.F.U,r=o.F._goodIndex;o.F._hash;var i=o.F._putsE,n=0,c=l<<3,m=0,v=e.length;if(a==0){for(;n<v;)i(t,c,n+(P=Math.min(65535,v-n))==v?1:0),c=o.F._copyExact(e,n,P,t,c+8),n+=P;return c>>>3}var T=y.lits,b=y.strt,M=y.prev,k=0,x=0,N=0,A=0,F=0,d=0;for(v>2&&(b[d=o.F._hash(e,0)]=0),n=0;n<v;n++){if(F=d,n+1<v-2){d=o.F._hash(e,n+1);var u=n+1&32767;M[u]=b[d],b[d]=u}if(m<=n){(k>14e3||x>26697)&&v-n>100&&(m<n&&(T[k]=n-m,k+=2,m=n),c=o.F._writeBlock(n==v-1||m==v?1:0,T,k,A,e,N,n-N,t,c),k=x=A=0,N=n);var E=0;n<v-2&&(E=o.F._bestMatch(e,n,M,F,Math.min(w[2],v-n),w[3]));var P=E>>>16,U=65535&E;if(E!=0){U=65535&E;var I=r(P=E>>>16,y.of0);y.lhst[257+I]++;var S=r(U,y.df0);y.dhst[S]++,A+=y.exb[I]+y.dxb[S],T[k]=P<<23|n-m,T[k+1]=U<<16|I<<8|S,k+=2,m=n+P}else y.lhst[e[n]]++;x++}}for(N==n&&e.length!=0||(m<n&&(T[k]=n-m,k+=2,m=n),c=o.F._writeBlock(1,T,k,A,e,N,n-N,t,c),k=0,x=0,k=x=A=0,N=n);(7&c)!=0;)c++;return c>>>3},o.F._bestMatch=function(e,t,l,a,w,y){var r=32767&t,i=l[r],n=r-i+32768&32767;if(i==r||a!=o.F._hash(e,t-n))return 0;for(var c=0,m=0,v=Math.min(32767,t);n<=v&&--y!=0&&i!=r;){if(c==0||e[t+c]==e[t+c-n]){var T=o.F._howLong(e,t,n);if(T>c){if(m=n,(c=T)>=w)break;n+2<T&&(T=n+2);for(var b=0,M=0;M<T-2;M++){var k=t-n+M+32768&32767,x=k-l[k]+32768&32767;x>b&&(b=x,i=k)}}}n+=(r=i)-(i=l[r])+32768&32767}return c<<16|m},o.F._howLong=function(e,t,l){if(e[t]!=e[t-l]||e[t+1]!=e[t+1-l]||e[t+2]!=e[t+2-l])return 0;var a=t,w=Math.min(e.length,t+258);for(t+=3;t<w&&e[t]==e[t-l];)t++;return t-a},o.F._hash=function(e,t){return(e[t]<<8|e[t+1])+(e[t+2]<<4)&65535},o.saved=0,o.F._writeBlock=function(e,t,l,a,w,y,r,i,n){var c,m,v,T,b,M,k,x,N,A=o.F.U,F=o.F._putsF,d=o.F._putsE;A.lhst[256]++,m=(c=o.F.getTrees())[0],v=c[1],T=c[2],b=c[3],M=c[4],k=c[5],x=c[6],N=c[7];var u=32+((n+3&7)==0?0:8-(n+3&7))+(r<<3),E=a+o.F.contSize(A.fltree,A.lhst)+o.F.contSize(A.fdtree,A.dhst),P=a+o.F.contSize(A.ltree,A.lhst)+o.F.contSize(A.dtree,A.dhst);P+=14+3*k+o.F.contSize(A.itree,A.ihst)+(2*A.ihst[16]+3*A.ihst[17]+7*A.ihst[18]);for(var U=0;U<286;U++)A.lhst[U]=0;for(U=0;U<30;U++)A.dhst[U]=0;for(U=0;U<19;U++)A.ihst[U]=0;var I=u<E&&u<P?0:E<P?1:2;if(F(i,n,e),F(i,n+1,I),n+=3,I==0){for(;(7&n)!=0;)n++;n=o.F._copyExact(w,y,r,i,n)}else{var S,_;if(I==1&&(S=A.fltree,_=A.fdtree),I==2){o.F.makeCodes(A.ltree,m),o.F.revCodes(A.ltree,m),o.F.makeCodes(A.dtree,v),o.F.revCodes(A.dtree,v),o.F.makeCodes(A.itree,T),o.F.revCodes(A.itree,T),S=A.ltree,_=A.dtree,d(i,n,b-257),d(i,n+=5,M-1),d(i,n+=5,k-4),n+=4;for(var h=0;h<k;h++)d(i,n+3*h,A.itree[1+(A.ordr[h]<<1)]);n+=3*k,n=o.F._codeTiny(x,A.itree,i,n),n=o.F._codeTiny(N,A.itree,i,n)}for(var f=y,L=0;L<l;L+=2){for(var C=t[L],O=C>>>23,H=f+(8388607&C);f<H;)n=o.F._writeLit(w[f++],S,i,n);if(O!=0){var j=t[L+1],B=j>>16,D=j>>8&255,R=255&j;d(i,n=o.F._writeLit(257+D,S,i,n),O-A.of0[D]),n+=A.exb[D],F(i,n=o.F._writeLit(R,_,i,n),B-A.df0[R]),n+=A.dxb[R],f+=O}}n=o.F._writeLit(256,S,i,n)}return n},o.F._copyExact=function(e,t,l,a,w){var y=w>>>3;return a[y]=l,a[y+1]=l>>>8,a[y+2]=255-a[y],a[y+3]=255-a[y+1],y+=4,a.set(new Uint8Array(e.buffer,t,l),y),w+(l+4<<3)},o.F.getTrees=function(){for(var e=o.F.U,t=o.F._hufTree(e.lhst,e.ltree,15),l=o.F._hufTree(e.dhst,e.dtree,15),a=[],w=o.F._lenCodes(e.ltree,a),y=[],r=o.F._lenCodes(e.dtree,y),i=0;i<a.length;i+=2)e.ihst[a[i]]++;for(i=0;i<y.length;i+=2)e.ihst[y[i]]++;for(var n=o.F._hufTree(e.ihst,e.itree,7),c=19;c>4&&e.itree[1+(e.ordr[c-1]<<1)]==0;)c--;return[t,l,n,w,r,c,a,y]},o.F.getSecond=function(e){for(var t=[],l=0;l<e.length;l+=2)t.push(e[l+1]);return t},o.F.nonZero=function(e){for(var t="",l=0;l<e.length;l+=2)e[l+1]!=0&&(t+=(l>>1)+",");return t},o.F.contSize=function(e,t){for(var l=0,a=0;a<t.length;a++)l+=t[a]*e[1+(a<<1)];return l},o.F._codeTiny=function(e,t,l,a){for(var w=0;w<e.length;w+=2){var y=e[w],r=e[w+1];a=o.F._writeLit(y,t,l,a);var i=y==16?2:y==17?3:7;y>15&&(o.F._putsE(l,a,r,i),a+=i)}return a},o.F._lenCodes=function(e,t){for(var l=e.length;l!=2&&e[l-1]==0;)l-=2;for(var a=0;a<l;a+=2){var w=e[a+1],y=a+3<l?e[a+3]:-1,r=a+5<l?e[a+5]:-1,i=a==0?-1:e[a-1];if(w==0&&y==w&&r==w){for(var n=a+5;n+2<l&&e[n+2]==w;)n+=2;(c=Math.min(n+1-a>>>1,138))<11?t.push(17,c-3):t.push(18,c-11),a+=2*c-2}else if(w==i&&y==w&&r==w){for(n=a+5;n+2<l&&e[n+2]==w;)n+=2;var c=Math.min(n+1-a>>>1,6);t.push(16,c-3),a+=2*c-2}else t.push(w,0)}return l>>>1},o.F._hufTree=function(e,t,l){var a=[],w=e.length,y=t.length,r=0;for(r=0;r<y;r+=2)t[r]=0,t[r+1]=0;for(r=0;r<w;r++)e[r]!=0&&a.push({lit:r,f:e[r]});var i=a.length,n=a.slice(0);if(i==0)return 0;if(i==1){var c=a[0].lit;return n=c==0?1:0,t[1+(c<<1)]=1,t[1+(n<<1)]=1,1}a.sort((function(x,N){return x.f-N.f}));var m=a[0],v=a[1],T=0,b=1,M=2;for(a[0]={lit:-1,f:m.f+v.f,l:m,r:v,d:0};b!=i-1;)m=T!=b&&(M==i||a[T].f<a[M].f)?a[T++]:a[M++],v=T!=b&&(M==i||a[T].f<a[M].f)?a[T++]:a[M++],a[b++]={lit:-1,f:m.f+v.f,l:m,r:v};var k=o.F.setDepth(a[b-1],0);for(k>l&&(o.F.restrictDepth(n,l,k),k=l),r=0;r<i;r++)t[1+(n[r].lit<<1)]=n[r].d;return k},o.F.setDepth=function(e,t){return e.lit!=-1?(e.d=t,t):Math.max(o.F.setDepth(e.l,t+1),o.F.setDepth(e.r,t+1))},o.F.restrictDepth=function(e,t,l){var a=0,w=1<<l-t,y=0;for(e.sort((function(i,n){return n.d==i.d?i.f-n.f:n.d-i.d})),a=0;a<e.length&&e[a].d>t;a++){var r=e[a].d;e[a].d=t,y+=w-(1<<l-r)}for(y>>>=l-t;y>0;)(r=e[a].d)<t?(e[a].d++,y-=1<<t-r-1):a++;for(;a>=0;a--)e[a].d==t&&y<0&&(e[a].d--,y++);y!=0&&console.log("debt left")},o.F._goodIndex=function(e,t){var l=0;return t[16|l]<=e&&(l|=16),t[8|l]<=e&&(l|=8),t[4|l]<=e&&(l|=4),t[2|l]<=e&&(l|=2),t[1|l]<=e&&(l|=1),l},o.F._writeLit=function(e,t,l,a){return o.F._putsF(l,a,t[e<<1]),a+t[1+(e<<1)]},o.F.inflate=function(e,t){var l=Uint8Array;if(e[0]==3&&e[1]==0)return t||new l(0);var a=o.F,w=a._bitsF,y=a._bitsE,r=a._decodeTiny,i=a.makeCodes,n=a.codes2map,c=a._get17,m=a.U,v=t==null;v&&(t=new l(e.length>>>2<<3));for(var T,b,M=0,k=0,x=0,N=0,A=0,F=0,d=0,u=0,E=0;M==0;)if(M=w(e,E,1),k=w(e,E+1,2),E+=3,k!=0){if(v&&(t=o.F._check(t,u+(1<<17))),k==1&&(T=m.flmap,b=m.fdmap,F=511,d=31),k==2){x=y(e,E,5)+257,N=y(e,E+5,5)+1,A=y(e,E+10,4)+4,E+=14;for(var P=0;P<38;P+=2)m.itree[P]=0,m.itree[P+1]=0;var U=1;for(P=0;P<A;P++){var I=y(e,E+3*P,3);m.itree[1+(m.ordr[P]<<1)]=I,I>U&&(U=I)}E+=3*A,i(m.itree,U),n(m.itree,U,m.imap),T=m.lmap,b=m.dmap,E=r(m.imap,(1<<U)-1,x+N,e,E,m.ttree);var S=a._copyOut(m.ttree,0,x,m.ltree);F=(1<<S)-1;var _=a._copyOut(m.ttree,x,N,m.dtree);d=(1<<_)-1,i(m.ltree,S),n(m.ltree,S,T),i(m.dtree,_),n(m.dtree,_,b)}for(;;){var h=T[c(e,E)&F];E+=15&h;var f=h>>>4;if(!(f>>>8))t[u++]=f;else{if(f==256)break;var L=u+f-254;if(f>264){var C=m.ldef[f-257];L=u+(C>>>3)+y(e,E,7&C),E+=7&C}var O=b[c(e,E)&d];E+=15&O;var H=O>>>4,j=m.ddef[H],B=(j>>>4)+w(e,E,15&j);for(E+=15&j,v&&(t=o.F._check(t,u+(1<<17)));u<L;)t[u]=t[u++-B],t[u]=t[u++-B],t[u]=t[u++-B],t[u]=t[u++-B];u=L}}}else{(7&E)!=0&&(E+=8-(7&E));var D=4+(E>>>3),R=e[D-4]|e[D-3]<<8;v&&(t=o.F._check(t,u+R)),t.set(new l(e.buffer,e.byteOffset+D,R),u),E=D+R<<3,u+=R}return t.length==u?t:t.slice(0,u)},o.F._check=function(e,t){var l=e.length;if(t<=l)return e;var a=new Uint8Array(Math.max(l<<1,t));return a.set(e,0),a},o.F._decodeTiny=function(e,t,l,a,w,y){for(var r=o.F._bitsE,i=o.F._get17,n=0;n<l;){var c=e[i(a,w)&t];w+=15&c;var m=c>>>4;if(m<=15)y[n]=m,n++;else{var v=0,T=0;m==16?(T=3+r(a,w,2),w+=2,v=y[n-1]):m==17?(T=3+r(a,w,3),w+=3):m==18&&(T=11+r(a,w,7),w+=7);for(var b=n+T;n<b;)y[n]=v,n++}}return w},o.F._copyOut=function(e,t,l,a){for(var w=0,y=0,r=a.length>>>1;y<l;){var i=e[y+t];a[y<<1]=0,a[1+(y<<1)]=i,i>w&&(w=i),y++}for(;y<r;)a[y<<1]=0,a[1+(y<<1)]=0,y++;return w},o.F.makeCodes=function(e,t){for(var l,a,w,y,r=o.F.U,i=e.length,n=r.bl_count,c=0;c<=t;c++)n[c]=0;for(c=1;c<i;c+=2)n[e[c]]++;var m=r.next_code;for(l=0,n[0]=0,a=1;a<=t;a++)l=l+n[a-1]<<1,m[a]=l;for(w=0;w<i;w+=2)(y=e[w+1])!=0&&(e[w]=m[y],m[y]++)},o.F.codes2map=function(e,t,l){for(var a=e.length,w=o.F.U.rev15,y=0;y<a;y+=2)if(e[y+1]!=0)for(var r=y>>1,i=e[y+1],n=r<<4|i,c=t-i,m=e[y]<<c,v=m+(1<<c);m!=v;)l[w[m]>>>15-t]=n,m++},o.F.revCodes=function(e,t){for(var l=o.F.U.rev15,a=15-t,w=0;w<e.length;w+=2){var y=e[w]<<t-e[w+1];e[w]=l[y]>>>a}},o.F._putsE=function(e,t,l){l<<=7&t;var a=t>>>3;e[a]|=l,e[a+1]|=l>>>8},o.F._putsF=function(e,t,l){l<<=7&t;var a=t>>>3;e[a]|=l,e[a+1]|=l>>>8,e[a+2]|=l>>>16},o.F._bitsE=function(e,t,l){return(e[t>>>3]|e[1+(t>>>3)]<<8)>>>(7&t)&(1<<l)-1},o.F._bitsF=function(e,t,l){return(e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16)>>>(7&t)&(1<<l)-1},o.F._get17=function(e,t){return(e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16)>>>(7&t)},o.F._get25=function(e,t){return(e[t>>>3]|e[1+(t>>>3)]<<8|e[2+(t>>>3)]<<16|e[3+(t>>>3)]<<24)>>>(7&t)},o.F.U=(s=Uint16Array,g=Uint32Array,{next_code:new s(16),bl_count:new s(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],exb:[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],ldef:new s(32),df0:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],dxb:[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],ddef:new g(32),flmap:new s(512),fltree:[],fdmap:new s(32),fdtree:[],lmap:new s(32768),ltree:[],ttree:[],dmap:new s(32768),dtree:[],imap:new s(512),itree:[],rev15:new s(32768),lhst:new g(286),dhst:new g(30),ihst:new g(19),lits:new g(15e3),strt:new s(65536),prev:new s(32768)}),(function(){for(var e=o.F.U,t=0;t<32768;t++){var l=t;l=(4278255360&(l=(4042322160&(l=(3435973836&(l=(2863311530&l)>>>1|(1431655765&l)<<1))>>>2|(858993459&l)<<2))>>>4|(252645135&l)<<4))>>>8|(16711935&l)<<8,e.rev15[t]=(l>>>16|l<<16)>>>17}function a(w,y,r){for(;y--!=0;)w.push(0,r)}for(t=0;t<32;t++)e.ldef[t]=e.of0[t]<<3|e.exb[t],e.ddef[t]=e.df0[t]<<4|e.dxb[t];a(e.fltree,144,8),a(e.fltree,112,9),a(e.fltree,24,7),a(e.fltree,8,8),o.F.makeCodes(e.fltree,9),o.F.codes2map(e.fltree,9,e.flmap),o.F.revCodes(e.fltree,9),a(e.fdtree,32,5),o.F.makeCodes(e.fdtree,5),o.F.codes2map(e.fdtree,5,e.fdmap),o.F.revCodes(e.fdtree,5),a(e.itree,19,0),a(e.ltree,286,0),a(e.dtree,30,0),a(e.ttree,320,0)})()})();var en=Yt({__proto__:null,default:Ke},[Ke]);const Ae=(function(){var p={nextZero(r,i){for(;r[i]!=0;)i++;return i},readUshort:(r,i)=>r[i]<<8|r[i+1],writeUshort(r,i,n){r[i]=n>>8&255,r[i+1]=255&n},readUint:(r,i)=>16777216*r[i]+(r[i+1]<<16|r[i+2]<<8|r[i+3]),writeUint(r,i,n){r[i]=n>>24&255,r[i+1]=n>>16&255,r[i+2]=n>>8&255,r[i+3]=255&n},readASCII(r,i,n){let c="";for(let m=0;m<n;m++)c+=String.fromCharCode(r[i+m]);return c},writeASCII(r,i,n){for(let c=0;c<n.length;c++)r[i+c]=n.charCodeAt(c)},readBytes(r,i,n){const c=[];for(let m=0;m<n;m++)c.push(r[i+m]);return c},pad:r=>r.length<2?`0${r}`:r,readUTF8(r,i,n){let c,m="";for(let v=0;v<n;v++)m+=`%${p.pad(r[i+v].toString(16))}`;try{c=decodeURIComponent(m)}catch{return p.readASCII(r,i,n)}return c}};function s(r,i,n,c){const m=i*n,v=t(c),T=Math.ceil(i*v/8),b=new Uint8Array(4*m),M=new Uint32Array(b.buffer),{ctype:k}=c,{depth:x}=c,N=p.readUshort;if(k==6){const C=m<<2;if(x==8)for(var A=0;A<C;A+=4)b[A]=r[A],b[A+1]=r[A+1],b[A+2]=r[A+2],b[A+3]=r[A+3];if(x==16)for(A=0;A<C;A++)b[A]=r[A<<1]}else if(k==2){const C=c.tabs.tRNS;if(C==null){if(x==8)for(A=0;A<m;A++){var F=3*A;M[A]=255<<24|r[F+2]<<16|r[F+1]<<8|r[F]}if(x==16)for(A=0;A<m;A++)F=6*A,M[A]=255<<24|r[F+4]<<16|r[F+2]<<8|r[F]}else{var d=C[0];const O=C[1],H=C[2];if(x==8)for(A=0;A<m;A++){var u=A<<2;F=3*A,M[A]=255<<24|r[F+2]<<16|r[F+1]<<8|r[F],r[F]==d&&r[F+1]==O&&r[F+2]==H&&(b[u+3]=0)}if(x==16)for(A=0;A<m;A++)u=A<<2,F=6*A,M[A]=255<<24|r[F+4]<<16|r[F+2]<<8|r[F],N(r,F)==d&&N(r,F+2)==O&&N(r,F+4)==H&&(b[u+3]=0)}}else if(k==3){const C=c.tabs.PLTE,O=c.tabs.tRNS,H=O?O.length:0;if(x==1)for(var E=0;E<n;E++){var P=E*T,U=E*i;for(A=0;A<i;A++){u=U+A<<2;var I=3*(S=r[P+(A>>3)]>>7-((7&A)<<0)&1);b[u]=C[I],b[u+1]=C[I+1],b[u+2]=C[I+2],b[u+3]=S<H?O[S]:255}}if(x==2)for(E=0;E<n;E++)for(P=E*T,U=E*i,A=0;A<i;A++)u=U+A<<2,I=3*(S=r[P+(A>>2)]>>6-((3&A)<<1)&3),b[u]=C[I],b[u+1]=C[I+1],b[u+2]=C[I+2],b[u+3]=S<H?O[S]:255;if(x==4)for(E=0;E<n;E++)for(P=E*T,U=E*i,A=0;A<i;A++)u=U+A<<2,I=3*(S=r[P+(A>>1)]>>4-((1&A)<<2)&15),b[u]=C[I],b[u+1]=C[I+1],b[u+2]=C[I+2],b[u+3]=S<H?O[S]:255;if(x==8)for(A=0;A<m;A++){var S;u=A<<2,I=3*(S=r[A]),b[u]=C[I],b[u+1]=C[I+1],b[u+2]=C[I+2],b[u+3]=S<H?O[S]:255}}else if(k==4){if(x==8)for(A=0;A<m;A++){u=A<<2;var _=r[h=A<<1];b[u]=_,b[u+1]=_,b[u+2]=_,b[u+3]=r[h+1]}if(x==16)for(A=0;A<m;A++){var h;u=A<<2,_=r[h=A<<2],b[u]=_,b[u+1]=_,b[u+2]=_,b[u+3]=r[h+2]}}else if(k==0)for(d=c.tabs.tRNS?c.tabs.tRNS:-1,E=0;E<n;E++){const C=E*T,O=E*i;if(x==1)for(var f=0;f<i;f++){var L=(_=255*(r[C+(f>>>3)]>>>7-(7&f)&1))==255*d?0:255;M[O+f]=L<<24|_<<16|_<<8|_}else if(x==2)for(f=0;f<i;f++)L=(_=85*(r[C+(f>>>2)]>>>6-((3&f)<<1)&3))==85*d?0:255,M[O+f]=L<<24|_<<16|_<<8|_;else if(x==4)for(f=0;f<i;f++)L=(_=17*(r[C+(f>>>1)]>>>4-((1&f)<<2)&15))==17*d?0:255,M[O+f]=L<<24|_<<16|_<<8|_;else if(x==8)for(f=0;f<i;f++)L=(_=r[C+f])==d?0:255,M[O+f]=L<<24|_<<16|_<<8|_;else if(x==16)for(f=0;f<i;f++)_=r[C+(f<<1)],L=N(r,C+(f<<1))==d?0:255,M[O+f]=L<<24|_<<16|_<<8|_}return b}function g(r,i,n,c){const m=t(r),v=Math.ceil(n*m/8),T=new Uint8Array((v+1+r.interlace)*c);return i=r.tabs.CgBI?e(i,T):o(i,T),r.interlace==0?i=l(i,r,0,n,c):r.interlace==1&&(i=(function(M,k){const x=k.width,N=k.height,A=t(k),F=A>>3,d=Math.ceil(x*A/8),u=new Uint8Array(N*d);let E=0;const P=[0,0,4,0,2,0,1],U=[0,4,0,2,0,1,0],I=[8,8,8,4,4,2,2],S=[8,8,4,4,2,2,1];let _=0;for(;_<7;){const f=I[_],L=S[_];let C=0,O=0,H=P[_];for(;H<N;)H+=f,O++;let j=U[_];for(;j<x;)j+=L,C++;const B=Math.ceil(C*A/8);l(M,k,E,C,O);let D=0,R=P[_];for(;R<N;){let z=U[_],G=E+D*B<<3;for(;z<x;){var h;if(A==1&&(h=(h=M[G>>3])>>7-(7&G)&1,u[R*d+(z>>3)]|=h<<7-((7&z)<<0)),A==2&&(h=(h=M[G>>3])>>6-(7&G)&3,u[R*d+(z>>2)]|=h<<6-((3&z)<<1)),A==4&&(h=(h=M[G>>3])>>4-(7&G)&15,u[R*d+(z>>1)]|=h<<4-((1&z)<<2)),A>=8){const V=R*d+z*F;for(let $=0;$<F;$++)u[V+$]=M[(G>>3)+$]}G+=A,z+=L}D++,R+=f}C*O!=0&&(E+=O*(1+B)),_+=1}return u})(i,r)),i}function o(r,i){return e(new Uint8Array(r.buffer,2,r.length-6),i)}var e=(function(){const r={H:{}};return r.H.N=function(i,n){const c=Uint8Array;let m,v,T=0,b=0,M=0,k=0,x=0,N=0,A=0,F=0,d=0;if(i[0]==3&&i[1]==0)return n||new c(0);const u=r.H,E=u.b,P=u.e,U=u.R,I=u.n,S=u.A,_=u.Z,h=u.m,f=n==null;for(f&&(n=new c(i.length>>>2<<5));T==0;)if(T=E(i,d,1),b=E(i,d+1,2),d+=3,b!=0){if(f&&(n=r.H.W(n,F+(1<<17))),b==1&&(m=h.J,v=h.h,N=511,A=31),b==2){M=P(i,d,5)+257,k=P(i,d+5,5)+1,x=P(i,d+10,4)+4,d+=14;let C=1;for(var L=0;L<38;L+=2)h.Q[L]=0,h.Q[L+1]=0;for(L=0;L<x;L++){const j=P(i,d+3*L,3);h.Q[1+(h.X[L]<<1)]=j,j>C&&(C=j)}d+=3*x,I(h.Q,C),S(h.Q,C,h.u),m=h.w,v=h.d,d=U(h.u,(1<<C)-1,M+k,i,d,h.v);const O=u.V(h.v,0,M,h.C);N=(1<<O)-1;const H=u.V(h.v,M,k,h.D);A=(1<<H)-1,I(h.C,O),S(h.C,O,m),I(h.D,H),S(h.D,H,v)}for(;;){const C=m[_(i,d)&N];d+=15&C;const O=C>>>4;if(!(O>>>8))n[F++]=O;else{if(O==256)break;{let H=F+O-254;if(O>264){const z=h.q[O-257];H=F+(z>>>3)+P(i,d,7&z),d+=7&z}const j=v[_(i,d)&A];d+=15&j;const B=j>>>4,D=h.c[B],R=(D>>>4)+E(i,d,15&D);for(d+=15&D;F<H;)n[F]=n[F++-R],n[F]=n[F++-R],n[F]=n[F++-R],n[F]=n[F++-R];F=H}}}}else{(7&d)!=0&&(d+=8-(7&d));const C=4+(d>>>3),O=i[C-4]|i[C-3]<<8;f&&(n=r.H.W(n,F+O)),n.set(new c(i.buffer,i.byteOffset+C,O),F),d=C+O<<3,F+=O}return n.length==F?n:n.slice(0,F)},r.H.W=function(i,n){const c=i.length;if(n<=c)return i;const m=new Uint8Array(c<<1);return m.set(i,0),m},r.H.R=function(i,n,c,m,v,T){const b=r.H.e,M=r.H.Z;let k=0;for(;k<c;){const x=i[M(m,v)&n];v+=15&x;const N=x>>>4;if(N<=15)T[k]=N,k++;else{let A=0,F=0;N==16?(F=3+b(m,v,2),v+=2,A=T[k-1]):N==17?(F=3+b(m,v,3),v+=3):N==18&&(F=11+b(m,v,7),v+=7);const d=k+F;for(;k<d;)T[k]=A,k++}}return v},r.H.V=function(i,n,c,m){let v=0,T=0;const b=m.length>>>1;for(;T<c;){const M=i[T+n];m[T<<1]=0,m[1+(T<<1)]=M,M>v&&(v=M),T++}for(;T<b;)m[T<<1]=0,m[1+(T<<1)]=0,T++;return v},r.H.n=function(i,n){const c=r.H.m,m=i.length;let v,T,b,M;const k=c.j;for(var x=0;x<=n;x++)k[x]=0;for(x=1;x<m;x+=2)k[i[x]]++;const N=c.K;for(v=0,k[0]=0,T=1;T<=n;T++)v=v+k[T-1]<<1,N[T]=v;for(b=0;b<m;b+=2)M=i[b+1],M!=0&&(i[b]=N[M],N[M]++)},r.H.A=function(i,n,c){const m=i.length,v=r.H.m.r;for(let T=0;T<m;T+=2)if(i[T+1]!=0){const b=T>>1,M=i[T+1],k=b<<4|M,x=n-M;let N=i[T]<<x;const A=N+(1<<x);for(;N!=A;)c[v[N]>>>15-n]=k,N++}},r.H.l=function(i,n){const c=r.H.m.r,m=15-n;for(let v=0;v<i.length;v+=2){const T=i[v]<<n-i[v+1];i[v]=c[T]>>>m}},r.H.M=function(i,n,c){c<<=7&n;const m=n>>>3;i[m]|=c,i[m+1]|=c>>>8},r.H.I=function(i,n,c){c<<=7&n;const m=n>>>3;i[m]|=c,i[m+1]|=c>>>8,i[m+2]|=c>>>16},r.H.e=function(i,n,c){return(i[n>>>3]|i[1+(n>>>3)]<<8)>>>(7&n)&(1<<c)-1},r.H.b=function(i,n,c){return(i[n>>>3]|i[1+(n>>>3)]<<8|i[2+(n>>>3)]<<16)>>>(7&n)&(1<<c)-1},r.H.Z=function(i,n){return(i[n>>>3]|i[1+(n>>>3)]<<8|i[2+(n>>>3)]<<16)>>>(7&n)},r.H.i=function(i,n){return(i[n>>>3]|i[1+(n>>>3)]<<8|i[2+(n>>>3)]<<16|i[3+(n>>>3)]<<24)>>>(7&n)},r.H.m=(function(){const i=Uint16Array,n=Uint32Array;return{K:new i(16),j:new i(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[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],q:new i(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[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],c:new n(32),J:new i(512),_:[],h:new i(32),$:[],w:new i(32768),C:[],v:[],d:new i(32768),D:[],u:new i(512),Q:[],r:new i(32768),s:new n(286),Y:new n(30),a:new n(19),t:new n(15e3),k:new i(65536),g:new i(32768)}})(),(function(){const i=r.H.m;for(var n=0;n<32768;n++){let m=n;m=(2863311530&m)>>>1|(1431655765&m)<<1,m=(3435973836&m)>>>2|(858993459&m)<<2,m=(4042322160&m)>>>4|(252645135&m)<<4,m=(4278255360&m)>>>8|(16711935&m)<<8,i.r[n]=(m>>>16|m<<16)>>>17}function c(m,v,T){for(;v--!=0;)m.push(0,T)}for(n=0;n<32;n++)i.q[n]=i.S[n]<<3|i.T[n],i.c[n]=i.p[n]<<4|i.z[n];c(i._,144,8),c(i._,112,9),c(i._,24,7),c(i._,8,8),r.H.n(i._,9),r.H.A(i._,9,i.J),r.H.l(i._,9),c(i.$,32,5),r.H.n(i.$,5),r.H.A(i.$,5,i.h),r.H.l(i.$,5),c(i.Q,19,0),c(i.C,286,0),c(i.D,30,0),c(i.v,320,0)})(),r.H.N})();function t(r){return[1,null,3,1,2,null,4][r.ctype]*r.depth}function l(r,i,n,c,m){let v=t(i);const T=Math.ceil(c*v/8);let b,M;v=Math.ceil(v/8);let k=r[n],x=0;if(k>1&&(r[n]=[0,0,1][k-2]),k==3)for(x=v;x<T;x++)r[x+1]=r[x+1]+(r[x+1-v]>>>1)&255;for(let N=0;N<m;N++)if(b=n+N*T,M=b+N+1,k=r[M-1],x=0,k==0)for(;x<T;x++)r[b+x]=r[M+x];else if(k==1){for(;x<v;x++)r[b+x]=r[M+x];for(;x<T;x++)r[b+x]=r[M+x]+r[b+x-v]}else if(k==2)for(;x<T;x++)r[b+x]=r[M+x]+r[b+x-T];else if(k==3){for(;x<v;x++)r[b+x]=r[M+x]+(r[b+x-T]>>>1);for(;x<T;x++)r[b+x]=r[M+x]+(r[b+x-T]+r[b+x-v]>>>1)}else{for(;x<v;x++)r[b+x]=r[M+x]+a(0,r[b+x-T],0);for(;x<T;x++)r[b+x]=r[M+x]+a(r[b+x-v],r[b+x-T],r[b+x-v-T])}return r}function a(r,i,n){const c=r+i-n,m=c-r,v=c-i,T=c-n;return m*m<=v*v&&m*m<=T*T?r:v*v<=T*T?i:n}function w(r,i,n){n.width=p.readUint(r,i),i+=4,n.height=p.readUint(r,i),i+=4,n.depth=r[i],i++,n.ctype=r[i],i++,n.compress=r[i],i++,n.filter=r[i],i++,n.interlace=r[i],i++}function y(r,i,n,c,m,v,T,b,M){const k=Math.min(i,m),x=Math.min(n,v);let N=0,A=0;for(let _=0;_<x;_++)for(let h=0;h<k;h++)if(T>=0&&b>=0?(N=_*i+h<<2,A=(b+_)*m+T+h<<2):(N=(-b+_)*i-T+h<<2,A=_*m+h<<2),M==0)c[A]=r[N],c[A+1]=r[N+1],c[A+2]=r[N+2],c[A+3]=r[N+3];else if(M==1){var F=r[N+3]*.00392156862745098,d=r[N]*F,u=r[N+1]*F,E=r[N+2]*F,P=c[A+3]*(1/255),U=c[A]*P,I=c[A+1]*P,S=c[A+2]*P;const f=1-F,L=F+P*f,C=L==0?0:1/L;c[A+3]=255*L,c[A+0]=(d+U*f)*C,c[A+1]=(u+I*f)*C,c[A+2]=(E+S*f)*C}else if(M==2)F=r[N+3],d=r[N],u=r[N+1],E=r[N+2],P=c[A+3],U=c[A],I=c[A+1],S=c[A+2],F==P&&d==U&&u==I&&E==S?(c[A]=0,c[A+1]=0,c[A+2]=0,c[A+3]=0):(c[A]=d,c[A+1]=u,c[A+2]=E,c[A+3]=F);else if(M==3){if(F=r[N+3],d=r[N],u=r[N+1],E=r[N+2],P=c[A+3],U=c[A],I=c[A+1],S=c[A+2],F==P&&d==U&&u==I&&E==S)continue;if(F<220&&P>20)return!1}return!0}return{decode:function(i){const n=new Uint8Array(i);let c=8;const m=p,v=m.readUshort,T=m.readUint,b={tabs:{},frames:[]},M=new Uint8Array(n.length);let k,x=0,N=0;const A=[137,80,78,71,13,10,26,10];for(var F=0;F<8;F++)if(n[F]!=A[F])throw"The input is not a PNG file!";for(;c<n.length;){const _=m.readUint(n,c);c+=4;const h=m.readASCII(n,c,4);if(c+=4,h=="IHDR")w(n,c,b);else if(h=="iCCP"){for(var d=c;n[d]!=0;)d++;m.readASCII(n,c,d-c),n[d+1];const f=n.slice(d+2,c+_);let L=null;try{L=o(f)}catch{L=e(f)}b.tabs[h]=L}else if(h=="CgBI")b.tabs[h]=n.slice(c,c+4);else if(h=="IDAT"){for(F=0;F<_;F++)M[x+F]=n[c+F];x+=_}else if(h=="acTL")b.tabs[h]={num_frames:T(n,c),num_plays:T(n,c+4)},k=new Uint8Array(n.length);else if(h=="fcTL"){N!=0&&((S=b.frames[b.frames.length-1]).data=g(b,k.slice(0,N),S.rect.width,S.rect.height),N=0);const f={x:T(n,c+12),y:T(n,c+16),width:T(n,c+4),height:T(n,c+8)};let L=v(n,c+22);L=v(n,c+20)/(L==0?100:L);const C={rect:f,delay:Math.round(1e3*L),dispose:n[c+24],blend:n[c+25]};b.frames.push(C)}else if(h=="fdAT"){for(F=0;F<_-4;F++)k[N+F]=n[c+F+4];N+=_-4}else if(h=="pHYs")b.tabs[h]=[m.readUint(n,c),m.readUint(n,c+4),n[c+8]];else if(h=="cHRM")for(b.tabs[h]=[],F=0;F<8;F++)b.tabs[h].push(m.readUint(n,c+4*F));else if(h=="tEXt"||h=="zTXt"){b.tabs[h]==null&&(b.tabs[h]={});var u=m.nextZero(n,c),E=m.readASCII(n,c,u-c),P=c+_-u-1;if(h=="tEXt")I=m.readASCII(n,u+1,P);else{var U=o(n.slice(u+2,u+2+P));I=m.readUTF8(U,0,U.length)}b.tabs[h][E]=I}else if(h=="iTXt"){b.tabs[h]==null&&(b.tabs[h]={}),u=0,d=c,u=m.nextZero(n,d),E=m.readASCII(n,d,u-d);const f=n[d=u+1];var I;n[d+1],d+=2,u=m.nextZero(n,d),m.readASCII(n,d,u-d),d=u+1,u=m.nextZero(n,d),m.readUTF8(n,d,u-d),P=_-((d=u+1)-c),f==0?I=m.readUTF8(n,d,P):(U=o(n.slice(d,d+P)),I=m.readUTF8(U,0,U.length)),b.tabs[h][E]=I}else if(h=="PLTE")b.tabs[h]=m.readBytes(n,c,_);else if(h=="hIST"){const f=b.tabs.PLTE.length/3;for(b.tabs[h]=[],F=0;F<f;F++)b.tabs[h].push(v(n,c+2*F))}else if(h=="tRNS")b.ctype==3?b.tabs[h]=m.readBytes(n,c,_):b.ctype==0?b.tabs[h]=v(n,c):b.ctype==2&&(b.tabs[h]=[v(n,c),v(n,c+2),v(n,c+4)]);else if(h=="gAMA")b.tabs[h]=m.readUint(n,c)/1e5;else if(h=="sRGB")b.tabs[h]=n[c];else if(h=="bKGD")b.ctype==0||b.ctype==4?b.tabs[h]=[v(n,c)]:b.ctype==2||b.ctype==6?b.tabs[h]=[v(n,c),v(n,c+2),v(n,c+4)]:b.ctype==3&&(b.tabs[h]=n[c]);else if(h=="IEND")break;c+=_,m.readUint(n,c),c+=4}var S;return N!=0&&((S=b.frames[b.frames.length-1]).data=g(b,k.slice(0,N),S.rect.width,S.rect.height)),b.data=g(b,M,b.width,b.height),delete b.compress,delete b.interlace,delete b.filter,b},toRGBA8:function(i){const n=i.width,c=i.height;if(i.tabs.acTL==null)return[s(i.data,n,c,i).buffer];const m=[];i.frames[0].data==null&&(i.frames[0].data=i.data);const v=n*c*4,T=new Uint8Array(v),b=new Uint8Array(v),M=new Uint8Array(v);for(let x=0;x<i.frames.length;x++){const N=i.frames[x],A=N.rect.x,F=N.rect.y,d=N.rect.width,u=N.rect.height,E=s(N.data,d,u,i);if(x!=0)for(var k=0;k<v;k++)M[k]=T[k];if(N.blend==0?y(E,d,u,T,n,c,A,F,0):N.blend==1&&y(E,d,u,T,n,c,A,F,1),m.push(T.buffer.slice(0)),N.dispose!=0){if(N.dispose==1)y(b,d,u,T,n,c,A,F,0);else if(N.dispose==2)for(k=0;k<v;k++)T[k]=M[k]}}return m},_paeth:a,_copyTile:y,_bin:p}})();(function(){const{_copyTile:p}=Ae,{_bin:s}=Ae,g=Ae._paeth;var o={table:(function(){const d=new Uint32Array(256);for(let u=0;u<256;u++){let E=u;for(let P=0;P<8;P++)1&E?E=3988292384^E>>>1:E>>>=1;d[u]=E}return d})(),update(d,u,E,P){for(let U=0;U<P;U++)d=o.table[255&(d^u[E+U])]^d>>>8;return d},crc:(d,u,E)=>4294967295^o.update(4294967295,d,u,E)};function e(d,u,E,P){u[E]+=d[0]*P>>4,u[E+1]+=d[1]*P>>4,u[E+2]+=d[2]*P>>4,u[E+3]+=d[3]*P>>4}function t(d){return Math.max(0,Math.min(255,d))}function l(d,u){const E=d[0]-u[0],P=d[1]-u[1],U=d[2]-u[2],I=d[3]-u[3];return E*E+P*P+U*U+I*I}function a(d,u,E,P,U,I,S){S==null&&(S=1);const _=P.length,h=[];for(var f=0;f<_;f++){const R=P[f];h.push([R>>>0&255,R>>>8&255,R>>>16&255,R>>>24&255])}for(f=0;f<_;f++){let R=4294967295;for(var L=0,C=0;C<_;C++){var O=l(h[f],h[C]);C!=f&&O<R&&(R=O,L=C)}}const H=new Uint32Array(U.buffer),j=new Int16Array(u*E*4),B=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5];for(f=0;f<B.length;f++)B[f]=255*((B[f]+.5)/16-.5);for(let R=0;R<E;R++)for(let z=0;z<u;z++){var D;f=4*(R*u+z),S!=2?D=[t(d[f]+j[f]),t(d[f+1]+j[f+1]),t(d[f+2]+j[f+2]),t(d[f+3]+j[f+3])]:(O=B[4*(3&R)+(3&z)],D=[t(d[f]+O),t(d[f+1]+O),t(d[f+2]+O),t(d[f+3]+O)]),L=0;let G=16777215;for(C=0;C<_;C++){const Q=l(D,h[C]);Q<G&&(G=Q,L=C)}const V=h[L],$=[D[0]-V[0],D[1]-V[1],D[2]-V[2],D[3]-V[3]];S==1&&(z!=u-1&&e($,j,f+4,7),R!=E-1&&(z!=0&&e($,j,f+4*u-4,3),e($,j,f+4*u,5),z!=u-1&&e($,j,f+4*u+4,1))),I[f>>2]=L,H[f>>2]=P[L]}}function w(d,u,E,P,U){U==null&&(U={});const{crc:I}=o,S=s.writeUint,_=s.writeUshort,h=s.writeASCII;let f=8;const L=d.frames.length>1;let C,O=!1,H=33+(L?20:0);if(U.sRGB!=null&&(H+=13),U.pHYs!=null&&(H+=21),U.iCCP!=null&&(C=pako.deflate(U.iCCP),H+=21+C.length+4),d.ctype==3){for(var j=d.plte.length,B=0;B<j;B++)d.plte[B]>>>24!=255&&(O=!0);H+=8+3*j+4+(O?8+1*j+4:0)}for(var D=0;D<d.frames.length;D++)L&&(H+=38),H+=(V=d.frames[D]).cimg.length+12,D!=0&&(H+=4);H+=12;const R=new Uint8Array(H),z=[137,80,78,71,13,10,26,10];for(B=0;B<8;B++)R[B]=z[B];if(S(R,f,13),f+=4,h(R,f,"IHDR"),f+=4,S(R,f,u),f+=4,S(R,f,E),f+=4,R[f]=d.depth,f++,R[f]=d.ctype,f++,R[f]=0,f++,R[f]=0,f++,R[f]=0,f++,S(R,f,I(R,f-17,17)),f+=4,U.sRGB!=null&&(S(R,f,1),f+=4,h(R,f,"sRGB"),f+=4,R[f]=U.sRGB,f++,S(R,f,I(R,f-5,5)),f+=4),U.iCCP!=null){const $=13+C.length;S(R,f,$),f+=4,h(R,f,"iCCP"),f+=4,h(R,f,"ICC profile"),f+=11,f+=2,R.set(C,f),f+=C.length,S(R,f,I(R,f-($+4),$+4)),f+=4}if(U.pHYs!=null&&(S(R,f,9),f+=4,h(R,f,"pHYs"),f+=4,S(R,f,U.pHYs[0]),f+=4,S(R,f,U.pHYs[1]),f+=4,R[f]=U.pHYs[2],f++,S(R,f,I(R,f-13,13)),f+=4),L&&(S(R,f,8),f+=4,h(R,f,"acTL"),f+=4,S(R,f,d.frames.length),f+=4,S(R,f,U.loop!=null?U.loop:0),f+=4,S(R,f,I(R,f-12,12)),f+=4),d.ctype==3){for(S(R,f,3*(j=d.plte.length)),f+=4,h(R,f,"PLTE"),f+=4,B=0;B<j;B++){const $=3*B,Q=d.plte[B],Z=255&Q,te=Q>>>8&255,Te=Q>>>16&255;R[f+$+0]=Z,R[f+$+1]=te,R[f+$+2]=Te}if(f+=3*j,S(R,f,I(R,f-3*j-4,3*j+4)),f+=4,O){for(S(R,f,j),f+=4,h(R,f,"tRNS"),f+=4,B=0;B<j;B++)R[f+B]=d.plte[B]>>>24&255;f+=j,S(R,f,I(R,f-j-4,j+4)),f+=4}}let G=0;for(D=0;D<d.frames.length;D++){var V=d.frames[D];L&&(S(R,f,26),f+=4,h(R,f,"fcTL"),f+=4,S(R,f,G++),f+=4,S(R,f,V.rect.width),f+=4,S(R,f,V.rect.height),f+=4,S(R,f,V.rect.x),f+=4,S(R,f,V.rect.y),f+=4,_(R,f,P[D]),f+=2,_(R,f,1e3),f+=2,R[f]=V.dispose,f++,R[f]=V.blend,f++,S(R,f,I(R,f-30,30)),f+=4);const $=V.cimg;S(R,f,(j=$.length)+(D==0?0:4)),f+=4;const Q=f;h(R,f,D==0?"IDAT":"fdAT"),f+=4,D!=0&&(S(R,f,G++),f+=4),R.set($,f),f+=j,S(R,f,I(R,Q,f-Q)),f+=4}return S(R,f,0),f+=4,h(R,f,"IEND"),f+=4,S(R,f,I(R,f-4,4)),f+=4,R.buffer}function y(d,u,E){for(let P=0;P<d.frames.length;P++){const U=d.frames[P];U.rect.width;const I=U.rect.height,S=new Uint8Array(I*U.bpl+I);U.cimg=c(U.img,I,U.bpp,U.bpl,S,u,E)}}function r(d,u,E,P,U){const I=U[0],S=U[1],_=U[2],h=U[3],f=U[4],L=U[5];let C=6,O=8,H=255;for(var j=0;j<d.length;j++){const ie=new Uint8Array(d[j]);for(var B=ie.length,D=0;D<B;D+=4)H&=ie[D+3]}const R=H!=255,z=(function(K,W,re,ce,X,de){const ee=[];for(var J=0;J<K.length;J++){const le=new Uint8Array(K[J]),ye=new Uint32Array(le.buffer);var he;let ge=0,Ue=0,Se=W,Re=re,ot=ce?1:0;if(J!=0){const Gt=de||ce||J==1||ee[J-2].dispose!=0?1:2;let it=0,At=1e9;for(let Be=0;Be<Gt;Be++){var Ie=new Uint8Array(K[J-1-Be]);const Kt=new Uint32Array(K[J-1-Be]);let Ce=W,_e=re,Oe=-1,He=-1;for(let Fe=0;Fe<re;Fe++)for(let ke=0;ke<W;ke++)ye[ae=Fe*W+ke]!=Kt[ae]&&(ke<Ce&&(Ce=ke),ke>Oe&&(Oe=ke),Fe<_e&&(_e=Fe),Fe>He&&(He=Fe));Oe==-1&&(Ce=_e=Oe=He=0),X&&((1&Ce)==1&&Ce--,(1&_e)==1&&_e--);const vt=(Oe-Ce+1)*(He-_e+1);vt<At&&(At=vt,it=Be,ge=Ce,Ue=_e,Se=Oe-Ce+1,Re=He-_e+1)}Ie=new Uint8Array(K[J-1-it]),it==1&&(ee[J-1].dispose=2),he=new Uint8Array(Se*Re*4),p(Ie,W,re,he,Se,Re,-ge,-Ue,0),ot=p(le,W,re,he,Se,Re,-ge,-Ue,3)?1:0,ot==1?n(le,W,re,he,{x:ge,y:Ue,width:Se,height:Re}):p(le,W,re,he,Se,Re,-ge,-Ue,0)}else he=le.slice(0);ee.push({rect:{x:ge,y:Ue,width:Se,height:Re},img:he,blend:ot,dispose:0})}if(ce)for(J=0;J<ee.length;J++){if((xe=ee[J]).blend==1)continue;const le=xe.rect,ye=ee[J-1].rect,ge=Math.min(le.x,ye.x),Ue=Math.min(le.y,ye.y),Se={x:ge,y:Ue,width:Math.max(le.x+le.width,ye.x+ye.width)-ge,height:Math.max(le.y+le.height,ye.y+ye.height)-Ue};ee[J-1].dispose=1,J-1!=0&&i(K,W,re,ee,J-1,Se,X),i(K,W,re,ee,J,Se,X)}let Ve=0;if(K.length!=1)for(var ae=0;ae<ee.length;ae++){var xe;Ve+=(xe=ee[ae]).rect.width*xe.rect.height}return ee})(d,u,E,I,S,_),G={},V=[],$=[];if(P!=0){const ie=[];for(D=0;D<z.length;D++)ie.push(z[D].img.buffer);const K=(function(X){let de=0;for(var ee=0;ee<X.length;ee++)de+=X[ee].byteLength;const J=new Uint8Array(de);let he=0;for(ee=0;ee<X.length;ee++){const Ie=new Uint8Array(X[ee]),Ve=Ie.length;for(let ae=0;ae<Ve;ae+=4){let xe=Ie[ae],le=Ie[ae+1],ye=Ie[ae+2];const ge=Ie[ae+3];ge==0&&(xe=le=ye=0),J[he+ae]=xe,J[he+ae+1]=le,J[he+ae+2]=ye,J[he+ae+3]=ge}he+=Ve}return J.buffer})(ie),W=v(K,P);for(D=0;D<W.plte.length;D++)V.push(W.plte[D].est.rgba);let re=0;for(D=0;D<z.length;D++){const ce=(Z=z[D]).img.length;var Q=new Uint8Array(W.inds.buffer,re>>2,ce>>2);$.push(Q);const X=new Uint8Array(W.abuf,re,ce);L&&a(Z.img,Z.rect.width,Z.rect.height,V,X,Q),Z.img.set(X),re+=ce}}else for(j=0;j<z.length;j++){var Z=z[j];const ie=new Uint32Array(Z.img.buffer);var te=Z.rect.width;for(B=ie.length,Q=new Uint8Array(B),$.push(Q),D=0;D<B;D++){const K=ie[D];if(D!=0&&K==ie[D-1])Q[D]=Q[D-1];else if(D>te&&K==ie[D-te])Q[D]=Q[D-te];else{let W=G[K];if(W==null&&(G[K]=W=V.length,V.push(K),V.length>=300))break;Q[D]=W}}}const Te=V.length;for(Te<=256&&f==0&&(O=Te<=2?1:Te<=4?2:Te<=16?4:8,O=Math.max(O,h)),j=0;j<z.length;j++){(Z=z[j]).rect.x,Z.rect.y,te=Z.rect.width;const ie=Z.rect.height;let K=Z.img;new Uint32Array(K.buffer);let W=4*te,re=4;if(Te<=256&&f==0){W=Math.ceil(O*te/8);var be=new Uint8Array(W*ie);const ce=$[j];for(let X=0;X<ie;X++){D=X*W;const de=X*te;if(O==8)for(var Y=0;Y<te;Y++)be[D+Y]=ce[de+Y];else if(O==4)for(Y=0;Y<te;Y++)be[D+(Y>>1)]|=ce[de+Y]<<4-4*(1&Y);else if(O==2)for(Y=0;Y<te;Y++)be[D+(Y>>2)]|=ce[de+Y]<<6-2*(3&Y);else if(O==1)for(Y=0;Y<te;Y++)be[D+(Y>>3)]|=ce[de+Y]<<7-1*(7&Y)}K=be,C=3,re=1}else if(R==0&&z.length==1){be=new Uint8Array(te*ie*3);const ce=te*ie;for(D=0;D<ce;D++){const X=3*D,de=4*D;be[X]=K[de],be[X+1]=K[de+1],be[X+2]=K[de+2]}K=be,C=2,re=3,W=3*te}Z.img=K,Z.bpl=W,Z.bpp=re}return{ctype:C,depth:O,plte:V,frames:z}}function i(d,u,E,P,U,I,S){const _=Uint8Array,h=Uint32Array,f=new _(d[U-1]),L=new h(d[U-1]),C=U+1<d.length?new _(d[U+1]):null,O=new _(d[U]),H=new h(O.buffer);let j=u,B=E,D=-1,R=-1;for(let G=0;G<I.height;G++)for(let V=0;V<I.width;V++){const $=I.x+V,Q=I.y+G,Z=Q*u+$,te=H[Z];te==0||P[U-1].dispose==0&&L[Z]==te&&(C==null||C[4*Z+3]!=0)||($<j&&(j=$),$>D&&(D=$),Q<B&&(B=Q),Q>R&&(R=Q))}D==-1&&(j=B=D=R=0),S&&((1&j)==1&&j--,(1&B)==1&&B--),I={x:j,y:B,width:D-j+1,height:R-B+1};const z=P[U];z.rect=I,z.blend=1,z.img=new Uint8Array(I.width*I.height*4),P[U-1].dispose==0?(p(f,u,E,z.img,I.width,I.height,-I.x,-I.y,0),n(O,u,E,z.img,I)):p(O,u,E,z.img,I.width,I.height,-I.x,-I.y,0)}function n(d,u,E,P,U){p(d,u,E,P,U.width,U.height,-U.x,-U.y,2)}function c(d,u,E,P,U,I,S){const _=[];let h,f=[0,1,2,3,4];I!=-1?f=[I]:(u*P>5e5||E==1)&&(f=[0]),S&&(h={level:0});const L=en;for(var C=0;C<f.length;C++){for(let j=0;j<u;j++)m(U,d,j,P,E,f[C]);_.push(L.deflate(U,h))}let O,H=1e9;for(C=0;C<_.length;C++)_[C].length<H&&(O=C,H=_[C].length);return _[O]}function m(d,u,E,P,U,I){const S=E*P;let _=S+E;if(d[_]=I,_++,I==0)if(P<500)for(var h=0;h<P;h++)d[_+h]=u[S+h];else d.set(new Uint8Array(u.buffer,S,P),_);else if(I==1){for(h=0;h<U;h++)d[_+h]=u[S+h];for(h=U;h<P;h++)d[_+h]=u[S+h]-u[S+h-U]+256&255}else if(E==0){for(h=0;h<U;h++)d[_+h]=u[S+h];if(I==2)for(h=U;h<P;h++)d[_+h]=u[S+h];if(I==3)for(h=U;h<P;h++)d[_+h]=u[S+h]-(u[S+h-U]>>1)+256&255;if(I==4)for(h=U;h<P;h++)d[_+h]=u[S+h]-g(u[S+h-U],0,0)+256&255}else{if(I==2)for(h=0;h<P;h++)d[_+h]=u[S+h]+256-u[S+h-P]&255;if(I==3){for(h=0;h<U;h++)d[_+h]=u[S+h]+256-(u[S+h-P]>>1)&255;for(h=U;h<P;h++)d[_+h]=u[S+h]+256-(u[S+h-P]+u[S+h-U]>>1)&255}if(I==4){for(h=0;h<U;h++)d[_+h]=u[S+h]+256-g(0,u[S+h-P],0)&255;for(h=U;h<P;h++)d[_+h]=u[S+h]+256-g(u[S+h-U],u[S+h-P],u[S+h-U-P])&255}}}function v(d,u){const E=new Uint8Array(d),P=E.slice(0),U=new Uint32Array(P.buffer),I=T(P,u),S=I[0],_=I[1],h=E.length,f=new Uint8Array(h>>2);let L;if(E.length<2e7)for(var C=0;C<h;C+=4)L=b(S,O=E[C]*(1/255),H=E[C+1]*(1/255),j=E[C+2]*(1/255),B=E[C+3]*(1/255)),f[C>>2]=L.ind,U[C>>2]=L.est.rgba;else for(C=0;C<h;C+=4){var O=E[C]*.00392156862745098,H=E[C+1]*(1/255),j=E[C+2]*(1/255),B=E[C+3]*(1/255);for(L=S;L.left;)L=M(L.est,O,H,j,B)<=0?L.left:L.right;f[C>>2]=L.ind,U[C>>2]=L.est.rgba}return{abuf:P.buffer,inds:f,plte:_}}function T(d,u,E){E==null&&(E=1e-4);const P=new Uint32Array(d.buffer),U={i0:0,i1:d.length,bst:null,est:null,tdst:0,left:null,right:null};U.bst=N(d,U.i0,U.i1),U.est=A(U.bst);const I=[U];for(;I.length<u;){let _=0,h=0;for(var S=0;S<I.length;S++)I[S].est.L>_&&(_=I[S].est.L,h=S);if(_<E)break;const f=I[h],L=k(d,P,f.i0,f.i1,f.est.e,f.est.eMq255);if(f.i0>=L||f.i1<=L){f.est.L=0;continue}const C={i0:f.i0,i1:L,bst:null,est:null,tdst:0,left:null,right:null};C.bst=N(d,C.i0,C.i1),C.est=A(C.bst);const O={i0:L,i1:f.i1,bst:null,est:null,tdst:0,left:null,right:null};for(O.bst={R:[],m:[],N:f.bst.N-C.bst.N},S=0;S<16;S++)O.bst.R[S]=f.bst.R[S]-C.bst.R[S];for(S=0;S<4;S++)O.bst.m[S]=f.bst.m[S]-C.bst.m[S];O.est=A(O.bst),f.left=C,f.right=O,I[h]=C,I.push(O)}for(I.sort(((_,h)=>h.bst.N-_.bst.N)),S=0;S<I.length;S++)I[S].ind=S;return[U,I]}function b(d,u,E,P,U){if(d.left==null)return d.tdst=(function(C,O,H,j,B){const D=O-C[0],R=H-C[1],z=j-C[2],G=B-C[3];return D*D+R*R+z*z+G*G})(d.est.q,u,E,P,U),d;const I=M(d.est,u,E,P,U);let S=d.left,_=d.right;I>0&&(S=d.right,_=d.left);const h=b(S,u,E,P,U);if(h.tdst<=I*I)return h;const f=b(_,u,E,P,U);return f.tdst<h.tdst?f:h}function M(d,u,E,P,U){const{e:I}=d;return I[0]*u+I[1]*E+I[2]*P+I[3]*U-d.eMq}function k(d,u,E,P,U,I){for(P-=4;E<P;){for(;x(d,E,U)<=I;)E+=4;for(;x(d,P,U)>I;)P-=4;if(E>=P)break;const S=u[E>>2];u[E>>2]=u[P>>2],u[P>>2]=S,E+=4,P-=4}for(;x(d,E,U)>I;)E-=4;return E+4}function x(d,u,E){return d[u]*E[0]+d[u+1]*E[1]+d[u+2]*E[2]+d[u+3]*E[3]}function N(d,u,E){const P=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],U=[0,0,0,0],I=E-u>>2;for(let S=u;S<E;S+=4){const _=d[S]*.00392156862745098,h=d[S+1]*(1/255),f=d[S+2]*(1/255),L=d[S+3]*(1/255);U[0]+=_,U[1]+=h,U[2]+=f,U[3]+=L,P[0]+=_*_,P[1]+=_*h,P[2]+=_*f,P[3]+=_*L,P[5]+=h*h,P[6]+=h*f,P[7]+=h*L,P[10]+=f*f,P[11]+=f*L,P[15]+=L*L}return P[4]=P[1],P[8]=P[2],P[9]=P[6],P[12]=P[3],P[13]=P[7],P[14]=P[11],{R:P,m:U,N:I}}function A(d){const{R:u}=d,{m:E}=d,{N:P}=d,U=E[0],I=E[1],S=E[2],_=E[3],h=P==0?0:1/P,f=[u[0]-U*U*h,u[1]-U*I*h,u[2]-U*S*h,u[3]-U*_*h,u[4]-I*U*h,u[5]-I*I*h,u[6]-I*S*h,u[7]-I*_*h,u[8]-S*U*h,u[9]-S*I*h,u[10]-S*S*h,u[11]-S*_*h,u[12]-_*U*h,u[13]-_*I*h,u[14]-_*S*h,u[15]-_*_*h],L=f,C=F;let O=[Math.random(),Math.random(),Math.random(),Math.random()],H=0,j=0;if(P!=0)for(let D=0;D<16&&(O=C.multVec(L,O),j=Math.sqrt(C.dot(O,O)),O=C.sml(1/j,O),!(D!=0&&Math.abs(j-H)<1e-9));D++)H=j;const B=[U*h,I*h,S*h,_*h];return{Cov:f,q:B,e:O,L:H,eMq255:C.dot(C.sml(255,B),O),eMq:C.dot(O,B),rgba:(Math.round(255*B[3])<<24|Math.round(255*B[2])<<16|Math.round(255*B[1])<<8|Math.round(255*B[0])<<0)>>>0}}var F={multVec:(d,u)=>[d[0]*u[0]+d[1]*u[1]+d[2]*u[2]+d[3]*u[3],d[4]*u[0]+d[5]*u[1]+d[6]*u[2]+d[7]*u[3],d[8]*u[0]+d[9]*u[1]+d[10]*u[2]+d[11]*u[3],d[12]*u[0]+d[13]*u[1]+d[14]*u[2]+d[15]*u[3]],dot:(d,u)=>d[0]*u[0]+d[1]*u[1]+d[2]*u[2]+d[3]*u[3],sml:(d,u)=>[d*u[0],d*u[1],d*u[2],d*u[3]]};Ae.encode=function(u,E,P,U,I,S,_){U==null&&(U=0),_==null&&(_=!1);const h=r(u,E,P,U,[!1,!1,!1,0,_,!1]);return y(h,-1),w(h,E,P,I,S)},Ae.encodeLL=function(u,E,P,U,I,S,_,h){const f={ctype:0+(U==1?0:2)+(I==0?0:4),depth:S,frames:[]},L=(U+I)*S,C=L*E;for(let O=0;O<u.length;O++)f.frames.push({rect:{x:0,y:0,width:E,height:P},img:new Uint8Array(u[O]),blend:0,dispose:1,bpp:Math.ceil(L/8),bpl:Math.ceil(C/8)});return y(f,0,!0),w(f,E,P,_,h)},Ae.encode.compress=r,Ae.encode.dither=a,Ae.quantize=v,Ae.quantize.getKDtree=T,Ae.quantize.getNearest=b})();const Ft={toArrayBuffer(p,s){const g=p.width,o=p.height,e=g<<2,t=p.getContext("2d").getImageData(0,0,g,o),l=new Uint32Array(t.data.buffer),a=(32*g+31)/32<<2,w=a*o,y=122+w,r=new ArrayBuffer(y),i=new DataView(r),n=1<<20;let c,m,v,T,b=n,M=0,k=0,x=0;function N(d){i.setUint16(k,d,!0),k+=2}function A(d){i.setUint32(k,d,!0),k+=4}function F(d){k+=d}N(19778),A(y),F(4),A(122),A(108),A(g),A(-o>>>0),N(1),N(32),A(3),A(w),A(2835),A(2835),F(8),A(16711680),A(65280),A(255),A(4278190080),A(1466527264),(function d(){for(;M<o&&b>0;){for(T=122+M*a,c=0;c<e;)b--,m=l[x++],v=m>>>24,i.setUint32(T+c,m<<8|v),c+=4;M++}x<l.length?(b=n,setTimeout(d,Ft._dly)):s(r)})()},toBlob(p,s){this.toArrayBuffer(p,(g=>{s(new Blob([g],{type:"image/bmp"}))}))},_dly:9};var ue={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},tn={[ue.CHROME]:16384,[ue.FIREFOX]:11180,[ue.DESKTOP_SAFARI]:16384,[ue.IE]:8192,[ue.IOS]:4096,[ue.ETC]:8192};const dt=typeof window<"u",kt=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,Ye=dt&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),nn=(dt||kt)&&(Ye&&Ye.getOriginalSymbol(window,"File")||typeof File<"u"&&File),Lt=(dt||kt)&&(Ye&&Ye.getOriginalSymbol(window,"FileReader")||typeof FileReader<"u"&&FileReader);function ht(p,s,g=Date.now()){return new Promise((o=>{const e=p.split(","),t=e[0].match(/:(.*?);/)[1],l=globalThis.atob(e[1]);let a=l.length;const w=new Uint8Array(a);for(;a--;)w[a]=l.charCodeAt(a);const y=new Blob([w],{type:t});y.name=s,y.lastModified=g,o(y)}))}function Ot(p){return new Promise(((s,g)=>{const o=new Lt;o.onload=()=>s(o.result),o.onerror=e=>g(e),o.readAsDataURL(p)}))}function Nt(p){return new Promise(((s,g)=>{const o=new Image;o.onload=()=>s(o),o.onerror=e=>g(e),o.src=p}))}function Le(){if(Le.cachedResult!==void 0)return Le.cachedResult;let p=ue.ETC;const{userAgent:s}=navigator;return/Chrom(e|ium)/i.test(s)?p=ue.CHROME:/iP(ad|od|hone)/i.test(s)&&/WebKit/i.test(s)?p=ue.IOS:/Safari/i.test(s)?p=ue.DESKTOP_SAFARI:/Firefox/i.test(s)?p=ue.FIREFOX:(/MSIE/i.test(s)||document.documentMode)&&(p=ue.IE),Le.cachedResult=p,Le.cachedResult}function Mt(p,s){const g=Le(),o=tn[g];let e=p,t=s,l=e*t;const a=e>t?t/e:e/t;for(;l>o*o;){const w=(o+e)/2,y=(o+t)/2;w<y?(t=y,e=y*a):(t=w*a,e=w),l=e*t}return{width:e,height:t}}function tt(p,s){let g,o;try{if(g=new OffscreenCanvas(p,s),o=g.getContext("2d"),o===null)throw new Error("getContext of OffscreenCanvas returns null")}catch{g=document.createElement("canvas"),o=g.getContext("2d")}return g.width=p,g.height=s,[g,o]}function Dt(p,s){const{width:g,height:o}=Mt(p.width,p.height),[e,t]=tt(g,o);return s&&/jpe?g/.test(s)&&(t.fillStyle="white",t.fillRect(0,0,e.width,e.height)),t.drawImage(p,0,0,e.width,e.height),e}function We(){return We.cachedResult!==void 0||(We.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&typeof document<"u"&&"ontouchend"in document),We.cachedResult}function Ze(p,s={}){return new Promise((function(g,o){let e,t;var l=function(){try{return t=Dt(e,s.fileType||p.type),g([e,t])}catch(w){return o(w)}},a=function(w){try{var y=function(r){try{throw r}catch(i){return o(i)}};try{let r;return Ot(p).then((function(i){try{return r=i,Nt(r).then((function(n){try{return e=n,(function(){try{return l()}catch(c){return o(c)}})()}catch(c){return y(c)}}),y)}catch(n){return y(n)}}),y)}catch(r){y(r)}}catch(r){return o(r)}};try{if(We()||[ue.DESKTOP_SAFARI,ue.MOBILE_SAFARI].includes(Le()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(p).then((function(w){try{return e=w,l()}catch{return a()}}),a)}catch{a()}}))}function Xe(p,s,g,o,e=1){return new Promise((function(t,l){let a;if(s==="image/png"){let y,r,i;return y=p.getContext("2d"),{data:r}=y.getImageData(0,0,p.width,p.height),i=Ae.encode([r.buffer],p.width,p.height,4096*e),a=new Blob([i],{type:s}),a.name=g,a.lastModified=o,w.call(this)}{let y=function(){return w.call(this)};if(s==="image/bmp")return new Promise((r=>Ft.toBlob(p,r))).then((function(r){try{return a=r,a.name=g,a.lastModified=o,y.call(this)}catch(i){return l(i)}}).bind(this),l);{let r=function(){return y.call(this)};if(typeof OffscreenCanvas=="function"&&p instanceof OffscreenCanvas)return p.convertToBlob({type:s,quality:e}).then((function(i){try{return a=i,a.name=g,a.lastModified=o,r.call(this)}catch(n){return l(n)}}).bind(this),l);{let i;return i=p.toDataURL(s,e),ht(i,g,o).then((function(n){try{return a=n,r.call(this)}catch(c){return l(c)}}).bind(this),l)}}}function w(){return t(a)}}))}function Ee(p){p.width=0,p.height=0}function Ne(){return new Promise((function(p,s){let g,o,e,t;return Ne.cachedResult!==void 0?p(Ne.cachedResult):ht("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(l){try{return g=l,Ze(g).then((function(a){try{return o=a[1],Xe(o,g.type,g.name,g.lastModified).then((function(w){try{return e=w,Ee(o),Ze(e).then((function(y){try{return t=y[0],Ne.cachedResult=t.width===1&&t.height===2,p(Ne.cachedResult)}catch(r){return s(r)}}),s)}catch(y){return s(y)}}),s)}catch(w){return s(w)}}),s)}catch(a){return s(a)}}),s)}))}function jt(p){return new Promise(((s,g)=>{const o=new Lt;o.onload=e=>{const t=new DataView(e.target.result);if(t.getUint16(0,!1)!=65496)return s(-2);const l=t.byteLength;let a=2;for(;a<l;){if(t.getUint16(a+2,!1)<=8)return s(-1);const w=t.getUint16(a,!1);if(a+=2,w==65505){if(t.getUint32(a+=2,!1)!=1165519206)return s(-1);const y=t.getUint16(a+=6,!1)==18761;a+=t.getUint32(a+4,y);const r=t.getUint16(a,y);a+=2;for(let i=0;i<r;i++)if(t.getUint16(a+12*i,y)==274)return s(t.getUint16(a+12*i+8,y))}else{if((65280&w)!=65280)break;a+=t.getUint16(a,!1)}}return s(-1)},o.onerror=e=>g(e),o.readAsArrayBuffer(p)}))}function Bt(p,s){const{width:g}=p,{height:o}=p,{maxWidthOrHeight:e}=s;let t,l=p;return isFinite(e)&&(g>e||o>e)&&([l,t]=tt(g,o),g>o?(l.width=e,l.height=o/g*e):(l.width=g/o*e,l.height=e),t.drawImage(p,0,0,l.width,l.height),Ee(p)),l}function Ht(p,s){const{width:g}=p,{height:o}=p,[e,t]=tt(g,o);switch(s>4&&s<9?(e.width=o,e.height=g):(e.width=g,e.height=o),s){case 2:t.transform(-1,0,0,1,g,0);break;case 3:t.transform(-1,0,0,-1,g,o);break;case 4:t.transform(1,0,0,-1,0,o);break;case 5:t.transform(0,1,1,0,0,0);break;case 6:t.transform(0,1,-1,0,o,0);break;case 7:t.transform(0,-1,-1,0,o,g);break;case 8:t.transform(0,-1,1,0,0,g)}return t.drawImage(p,0,0,g,o),Ee(p),e}function St(p,s,g=0){return new Promise((function(o,e){let t,l,a,w,y,r,i,n,c,m,v,T,b,M,k,x,N,A,F,d;function u(P=5){if(s.signal&&s.signal.aborted)throw s.signal.reason;t+=P,s.onProgress(Math.min(t,100))}function E(P){if(s.signal&&s.signal.aborted)throw s.signal.reason;t=Math.min(Math.max(P,t),100),s.onProgress(t)}return t=g,l=s.maxIteration||10,a=1024*s.maxSizeMB*1024,u(),Ze(p,s).then((function(P){try{return[,w]=P,u(),y=Bt(w,s),u(),new Promise((function(U,I){var S;if(!(S=s.exifOrientation))return jt(p).then((function(h){try{return S=h,_.call(this)}catch(f){return I(f)}}).bind(this),I);function _(){return U(S)}return _.call(this)})).then((function(U){try{return r=U,u(),Ne().then((function(I){try{return i=I?y:Ht(y,r),u(),n=s.initialQuality||1,c=s.fileType||p.type,Xe(i,c,p.name,p.lastModified,n).then((function(S){try{{let h=function(){if(l--&&(k>a||k>b)){let L,C;return L=d?.95*F.width:F.width,C=d?.95*F.height:F.height,[N,A]=tt(L,C),A.drawImage(F,0,0,L,C),n*=c==="image/png"?.85:.95,Xe(N,c,p.name,p.lastModified,n).then((function(O){try{return x=O,Ee(F),F=N,k=x.size,E(Math.min(99,Math.floor((M-k)/(M-a)*100))),h}catch(H){return e(H)}}),e)}return[1]},f=function(){return Ee(F),Ee(N),Ee(y),Ee(i),Ee(w),E(100),o(x)};if(m=S,u(),v=m.size>a,T=m.size>p.size,!v&&!T)return E(100),o(m);var _;return b=p.size,M=m.size,k=M,F=i,d=!s.alwaysKeepResolution&&v,(_=(function(L){for(;L;){if(L.then)return void L.then(_,e);try{if(L.pop){if(L.length)return L.pop()?f.call(this):L;L=h}else L=L.call(this)}catch(C){return e(C)}}}).bind(this))(h)}}catch(h){return e(h)}}).bind(this),e)}catch(S){return e(S)}}).bind(this),e)}catch(I){return e(I)}}).bind(this),e)}catch(U){return e(U)}}).bind(this),e)}))}const rn=`
2
+ let scriptImported = false
3
+ self.addEventListener('message', async (e) => {
4
+ const { file, id, imageCompressionLibUrl, options } = e.data
5
+ options.onProgress = (progress) => self.postMessage({ progress, id })
6
+ try {
7
+ if (!scriptImported) {
8
+ // console.log('[worker] importScripts', imageCompressionLibUrl)
9
+ self.importScripts(imageCompressionLibUrl)
10
+ scriptImported = true
11
+ }
12
+ // console.log('[worker] self', self)
13
+ const compressedFile = await imageCompression(file, options)
14
+ self.postMessage({ file: compressedFile, id })
15
+ } catch (e) {
16
+ // console.error('[worker] error', e)
17
+ self.postMessage({ error: e.message + '\\n' + e.stack, id })
18
+ }
19
+ })
20
+ `;let at;function on(p,s){return new Promise(((g,o)=>{at||(at=(function(l){const a=[];return a.push(l),URL.createObjectURL(new Blob(a))})(rn));const e=new Worker(at);e.addEventListener("message",(function(l){if(s.signal&&s.signal.aborted)e.terminate();else if(l.data.progress===void 0){if(l.data.error)return o(new Error(l.data.error)),void e.terminate();g(l.data.file),e.terminate()}else s.onProgress(l.data.progress)})),e.addEventListener("error",o),s.signal&&s.signal.addEventListener("abort",(()=>{o(s.signal.reason),e.terminate()})),e.postMessage({file:p,imageCompressionLibUrl:s.libURL,options:{...s,onProgress:void 0,signal:void 0}})}))}function se(p,s){return new Promise((function(g,o){let e,t,l,a,w,y;if(e={...s},l=0,{onProgress:a}=e,e.maxSizeMB=e.maxSizeMB||Number.POSITIVE_INFINITY,w=typeof e.useWebWorker!="boolean"||e.useWebWorker,delete e.useWebWorker,e.onProgress=c=>{l=c,typeof a=="function"&&a(l)},!(p instanceof Blob||p instanceof nn))return o(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(p.type))return o(new Error("The file given is not an image"));if(y=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,!w||typeof Worker!="function"||y)return St(p,e).then((function(c){try{return t=c,n.call(this)}catch(m){return o(m)}}).bind(this),o);var r=(function(){try{return n.call(this)}catch(c){return o(c)}}).bind(this),i=function(c){try{return St(p,e).then((function(m){try{return t=m,r()}catch(v){return o(v)}}),o)}catch(m){return o(m)}};try{return e.libURL=e.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",on(p,e).then((function(c){try{return t=c,r()}catch{return i()}}),i)}catch{i()}function n(){try{t.name=p.name,t.lastModified=p.lastModified}catch{}try{e.preserveExif&&p.type==="image/jpeg"&&(!e.fileType||e.fileType&&e.fileType===p.type)&&(t=Rt(p,t))}catch{}return g(t)}}))}se.getDataUrlFromFile=Ot,se.getFilefromDataUrl=ht,se.loadImage=Nt,se.drawImageInCanvas=Dt,se.drawFileInCanvas=Ze,se.canvasToFile=Xe,se.getExifOrientation=jt,se.handleMaxWidthOrHeight=Bt,se.followExifOrientation=Ht,se.cleanupCanvasMemory=Ee,se.isAutoOrientationInBrowser=Ne,se.approximateBelowMaximumCanvasSizeOfBrowser=Mt,se.copyExifWithoutOrientation=Rt,se.getBrowserName=Le,se.version="2.0.2";const we=p=>{const s=process.env.VITE_PUBLIC_APP;if(s)return s;if(typeof window<"u"){const g=new URLSearchParams(window.location.search).get("app");if(g)return g}return p||"pmate"},an=(p,s,g)=>{const o=new Map,e=new Map;return(async(...t)=>{const l=t.map(n=>n instanceof Pe.Maybe?n.map(c=>JSON.stringify(c)).unwrapOr(""):JSON.stringify(n)).join("--"),a=await Pe.calculateSHA1Hash(l),w=`${s}:${a}`,y=o.get(w);if(y&&y.expiry>Date.now())return y.value;const r=e.get(w);if(r)return r;const i=(async()=>{try{const n=await p(...t);return n&&o.set(w,{value:n,expiry:Date.now()+g}),n}finally{setTimeout(()=>e.delete(w),50)}})();return e.set(w,i),i})},sn=async p=>{if(Pe.isMaybe(p)){if(p.isNothing())return!1;p=p.unwrap()}try{return(await fetch(p,{method:"HEAD"})).ok}catch{return!1}},cn=an(sn,"link",3600*1e3);class Me{static async get(s){const g=await fetch(s);return g.ok?(await g.json()).data??null:null}static async post(s,g){const e=await(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)})).json();if(!e.success)throw e;return e.data}static async put(s,g){const e=await(await fetch(s,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)})).json();if(!e.success)throw e;return Pe.Maybe.Just(e.data)}static async getFile(s,g="json"){try{const o=await fetch(s);if(g==="log"){if(!o.ok)return Pe.Maybe.Nothing();try{const t=(await o.text()).split(`
21
+ `).filter(Boolean).map(l=>JSON.parse(l));return Pe.Maybe.Just(t)}catch{return Pe.Maybe.Nothing()}}return o.ok?g==="text"?o.text():await o.json():null}catch(o){return console.warn(o),null}}static exists(s){return cn(s)}}const ln=process.env.VITE_PUBLIC_ACCOUNT_SERVICE,st=process.env.VITE_PUBLIC_PROFILE_SERVICE??process.env.VITE_PUBLIC_AUTH_SERVER_ENDPOINT??ln,fn=(process.env.VITE_PUBLIC_UPLOADER_SERVICE_URL??process.env.PUBLIC_UPLOADER_SERVICE_URL??"https://fc-uploader.skedo.cn").replace(/\/+$/,""),un={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",webp:"image/webp",gif:"image/gif",svg:"image/svg+xml",ico:"image/x-icon",bmp:"image/bmp",pdf:"application/pdf",mobi:"application/x-mobipocket-ebook",epub:"application/epub+zip",txt:"text/plain",json:"application/json",mp3:"audio/mpeg",wav:"audio/wav",webm:"audio/webm",weba:"audio/webm",m4a:"audio/mp4"};class me{static async createProfile(s){return Me.post(`${st}/profile`,s)}static async updateProfile(s){await Me.put(`${st}/profile`,s)}static async getProfiles(s){const g={app:we(s.app),account:s.accountId};return me.getProfilesByScope(g)}static async getProfilesByScope(s){const g=new URLSearchParams({app:s.app,account:s.account}).toString();return await Me.get(`${st}/profiles?${g}`)||[]}static async updateAvatar(s){return me.uploadToUploaderService("/avatar",s)}static async uploadMsgImage(s){return me.uploadToUploaderService("/msg",s)}static async updateMyVoice(s){return me.uploadToUploaderService("/my-voice",{...s,filename:"voice.wav",contentType:"audio/wav"})}static async uploadUserFile(s){return me.uploadToUploaderService("/file",s)}static async uploadToUploaderService(s,g){const{filename:o,...e}=g,t=o??"upload",l=t.split(".").pop()?.toLowerCase()??"",a=g.contentType??un[l],w=await fetch(`${fn}${s}`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-file-content-type":a}:{}},body:JSON.stringify({...e,filename:t})});if(!w.ok)throw new Error("Upload failed");const y=await w.json();if(!y.data)throw new Error("Upload failed");return y.data}}const dn=p=>new Promise((s,g)=>{const o=new FileReader;o.onloadend=()=>{const e=o.result;if(typeof e!="string"){g(new Error("Failed to read file"));return}const[,t]=e.split(",");if(!t){g(new Error("Failed to parse base64 data"));return}s(t)},o.onerror=()=>{g(new Error("Failed to read file"))},o.readAsDataURL(p)}),hn=oe.atom(null,async(p,s,{file:g,userId:o})=>{const e=await se(g,{maxSizeMB:1,maxWidthOrHeight:128,useWebWorker:!0}),t=await dn(e);return me.updateAvatar({user:o,base64:t,filename:e.name})});var fe=(p=>(p.Idle="idle",p.Checking="checking",p.Authenticated="authenticated",p.Unauthenticated="unauthenticated",p.ProfileUninitialized="profile-uninitialized",p.ProfileInitializing="profile-initializing",p.ProfileReady="profile-ready",p.LoggingIn="logging-in",p.LoggingOut="logging-out",p.Error="error",p))(fe||{});const pn={state:fe.Idle,profiles:[],profile:null,accountId:null,account:null,error:null},nt=oe.atom(pn),gn=oe.atom(p=>p(nt).account??void 0),rt=oe.atom(p=>p(nt).profile??void 0),pt="pmate-auth-token",gt=()=>typeof localStorage<"u",ze=()=>{if(!gt())return null;try{const p=localStorage.getItem(pt);if(!p)return null;const s=JSON.parse(p);return typeof s=="string"?s:null}catch{return null}},mn=p=>{if(gt())try{localStorage.setItem(pt,JSON.stringify(p))}catch{}},wn=()=>{if(gt())try{localStorage.removeItem(pt)}catch{}},yn=process.env.VITE_PUBLIC_AUTH_SERVER_ENDPOINT;class ve{static sessionCached=Pe.lru(s=>ve.authRequest("/session",{method:"GET",token:s}),{ttl:3e3,key:s=>s??ze()??"default"});static async vcode(s){return ve.authRequest("/vcode",{method:"POST",body:JSON.stringify(s)})}static async login(s){return ve.authRequest("/login",{method:"POST",body:JSON.stringify(s),token:s.nonce})}static async logout(s){return ve.authRequest("/logout",{method:"POST",token:s})}static async session(s){return ve.sessionCached(s)}static async authRequest(s,g){const{token:o,headers:e,...t}=g,l=o??ze(),a=await fetch(`${yn.replace(/\/+$/,"")}${s}`,{credentials:"include",...t,headers:{"Content-Type":"application/json",...l?{Authorization:`Bearer ${l}`}:{},...e??{}}}),w=await a.json();if(!a.ok||!w.success)throw w;return w.data}}const Et=process.env.VITE_PUBLIC_ACCOUNT_SERVICE;class qe{static async entity(s){return await Me.get(`${Et}/entity/${s}`)||null}static getProfile(s){return qe.entity(s)}static getGroup(s){return qe.entity(s)}static async entities(s){if(!s.length)return{};const g=`${Et}/entities`;return(await Me.post(g,{ids:s})||[]).reduce((e,t,l)=>{if(!t)return e;const a=t.id??s[l];return a&&(e[a]=t),e},{})}}const zt="account-state",$t=()=>typeof localStorage<"u",An=p=>{if($t())try{localStorage.setItem(zt,JSON.stringify(p))}catch{}},vn=()=>{if($t())try{localStorage.removeItem(zt)}catch{}},mt="selected-profile",wt=()=>typeof localStorage<"u",Ut=()=>{if(!wt())return null;try{const p=localStorage.getItem(mt);if(!p)return null;const s=JSON.parse(p);return typeof s=="string"?s:null}catch{return null}},bn=p=>{if(wt())try{localStorage.setItem(mt,JSON.stringify(p))}catch{}},Sn=()=>{if(wt())try{localStorage.removeItem(mt)}catch{}};var qt=(p=>(p.StateChange="stateChange",p))(qt||{});class pe extends Pe.Emitter{constructor(s){super(),this.app=s}static instances=new Map;static get(s){const g=we(s),o=pe.instances.get(g);if(o)return o;const e=new pe(g);return pe.instances.set(g,e),e}async session(){try{return await ve.session()}catch{return null}}async login(){this.transition(fe.LoggingIn,null);try{const s=await ve.session();if(!s)throw new Error("Session not found");const g=Date.parse(s.issuedAt),o={accountId:s.identity.accountId,token:"",signTime:Number.isNaN(g)?Date.now():g,app:this.app};this.setAccountState(o),this.transition(fe.Authenticated,null),this.transition(fe.ProfileInitializing,null);const e=await this.prepareProfiles(o);return this.transition(e.length>0?fe.ProfileReady:fe.ProfileUninitialized,null),o}catch(s){const g=s instanceof Error?s:new Error("Login failed");throw this.transition(fe.Error,g),g}}hasUrlSession(){return typeof window>"u"?!1:new URLSearchParams(window.location.search).has("sessionId")}async loginUrlSessionOverride(){if(typeof window>"u")return this.login();const s=new URLSearchParams(window.location.search),g=s.get("sessionId");g&&this.setAuthToken(g);const o=await this.login();if(g){s.delete("sessionId");const e=s.toString(),t=`${window.location.pathname}${e?`?${e}`:""}${window.location.hash}`;window.history.replaceState(null,"",t)}return o}async logout(){this.transition(fe.LoggingOut,null);try{await ve.logout(ze()||void 0)}catch{}finally{this.clearSession(),this.transition(fe.Unauthenticated,null)}}async getSnapshot(){const s=await this.getAccountState();if(!s)return{state:fe.Unauthenticated,account:null,accountId:null,error:null,profiles:[],profile:null};const g=await this.getProfiles(),o=await this.getSelectedProfile(g);return{state:g.length>0?fe.ProfileReady:fe.ProfileUninitialized,account:s,accountId:s.accountId??null,error:null,profiles:g,profile:o}}transition(s,g){this.emit("stateChange")}async getAccountState(){const s=await this.session();if(!s)return null;const g=Date.parse(s.issuedAt);return{accountId:s.identity.accountId,token:ze()||"",signTime:Number.isNaN(g)?Date.now():g,app:this.app}}setAccountState(s){An(s)}clearAccountState(){vn()}async getSelectedProfile(s){const g=Ut();return g?(s??await this.getProfiles()).find(e=>e.id===g)??null:null}setSelectedProfile(s){const g=typeof s=="string"?s:s.id;bn(g),this.emit("stateChange")}clearSelectedProfile(){Sn(),this.emit("stateChange")}async getProfiles(){const s=await this.getAccountState();if(!s)return[];try{return await this.prepareProfiles(s)}catch{return[]}}clearProfiles(){this.emit("stateChange")}clearSession(){this.clearAccountState(),this.clearSelectedProfile(),this.clearProfiles(),this.clearAuthToken()}getAuthToken(){return ze()}setAuthToken(s){mn(s)}clearAuthToken(){wn()}async getLocalProfile(){const s=await this.getAccountState(),g=await this.getSelectedProfile();if(!s||!g)return null;const{id:o,...e}=g;return{...s,...e,id:o}}async getCurrentPeer(){const s=await this.getLocalProfile();if(s)return{...s,gender:s.gender??"",email:s.email||"",isOnline:!0}}async createProfile(s){const g=await this.getAccountState();if(!g)throw new Error("Account info is missing for profile creation");const o=await me.createProfile({app:we(g.app),account:g.accountId,nickName:s.nickName,learningTargetLang:s.learningTargetLang});return await this.prepareProfiles(g),await this.getSelectedProfile()||this.setSelectedProfile(o),o}async prepareProfiles(s){const g=await me.getProfiles(s),o=Ut();if(o&&g.some(t=>t.id===o))return g;const e=g[0];return e?this.setSelectedProfile(e):this.clearSelectedProfile(),g}}const En=oe.atom(null,(p,s,g)=>{const o=we(g.app);pe.get(o).setSelectedProfile(g)}),Vt=oe.atom({}),Un=oe.atom(null,async(p,s,{nickName:g})=>{const o=p(Vt),t=await pe.get(we()).getAccountState();if(!t)throw new Error("Account info is missing for profile creation");return pe.get(we(t.app)).createProfile({nickName:g,learningTargetLang:o.learningTargetLang})}),Pn={};let In=0;function Pt(p,s){const g=`atom${++In}`,o={toString(){return(Pn?"production":void 0)!=="production"&&this.debugLabel?g+":"+this.debugLabel:g}};return typeof p=="function"?o.read=p:(o.init=p,o.read=Cn,o.write=_n),s&&(o.write=s),o}function Cn(p){return p(this)}function _n(p,s,g){return s(this,typeof g=="function"?g(p(this)):g)}const ft={},Tn=p=>typeof p?.then=="function";function xn(p=()=>{try{return window.localStorage}catch(g){(ft?"production":void 0)!=="production"&&typeof window<"u"&&console.warn(g);return}},s){var g;let o,e;const t={getItem:(w,y)=>{var r,i;const n=m=>{if(m=m||"",o!==m){try{e=JSON.parse(m,s?.reviver)}catch{return y}o=m}return e},c=(i=(r=p())==null?void 0:r.getItem(w))!=null?i:null;return Tn(c)?c.then(n):n(c)},setItem:(w,y)=>{var r;return(r=p())==null?void 0:r.setItem(w,JSON.stringify(y,void 0))},removeItem:w=>{var y;return(y=p())==null?void 0:y.removeItem(w)}},l=w=>(y,r,i)=>w(y,n=>{let c;try{c=JSON.parse(n||"")}catch{c=i}r(c)});let a;try{a=(g=p())==null?void 0:g.subscribe}catch{}return!a&&typeof window<"u"&&typeof window.addEventListener=="function"&&window.Storage&&(a=(w,y)=>{if(!(p()instanceof window.Storage))return()=>{};const r=i=>{i.storageArea===p()&&i.key===w&&y(i.newValue)};return window.addEventListener("storage",r),()=>{window.removeEventListener("storage",r)}}),a&&(t.subscribe=l(a)),t}xn();function Rn(p,s){const g=Pt(0);return(ft?"production":void 0)!=="production"&&(g.debugPrivate=!0),Pt((o,e)=>(o(g),p(o,e)),(o,e,...t)=>{if(t.length===0)e(g,l=>l+1);else if((ft?"production":void 0)!=="production")throw new Error("refresh must be called without arguments")})}const Qt=ut.atomFamily(p=>Rn(async()=>{if(!p)return null;try{return await qe.entity(p)}catch{return null}})),Fn=Qe.atomWithLoadable(async p=>{p(nt);const g=await pe.get(we()).getAccountState();if(!g)return[];try{return await me.getProfiles(g)}catch{return[]}}),kn=oe.atom(null,async(p,s,g,o)=>{const e=p(rt),t=e&&e.id===g?e:await p(Qt(g));if(!t)return;await me.updateProfile({profileId:t.id,...o});const l=we(t.app),a=pe.get(l),w={...t,...o};e&&e.id===g&&a.setSelectedProfile(w),await a.getProfiles()}),Ln=oe.atom(null,async()=>pe.get(we()).login()),On=oe.atom(null,async()=>{try{return await ve.session()}catch{return null}}),Wt=oe.atom(null,async()=>{await pe.get(we()).logout()}),Nn=oe.atom(p=>{const s=p(rt);return je.normalizeLang(s?.motherTongue,"zh-CN")}),Mn=oe.atom(p=>{const s=p(rt);return je.normalizeLang(s?.learningTargetLang)});var $e=(p=>(p.USER_SETTINGS="user-settings",p))($e||{});const It=ut.atomFamily(p=>oe.atom(void 0)),Je=ut.atomFamily(p=>oe.atom(s=>{const g=s(It(p));if(g)return g;try{const o=localStorage.getItem(p);return o?JSON.parse(o):null}catch{return null}},(s,g,o)=>{localStorage.setItem(p,JSON.stringify(o)),g(It(p),o)})),Ct={intensive:!1,bilingual:!0,fontColor:"#000000",backgroundColor:"white",books:[],advancedMode:!1,autoread:!0,playSpeed:1,scrollDirection:"vertical",companion:"",difficulty:bt.Difficulty.Medium,"chatVoice@v2":bt.VoiceList.KOKORO_af_alloy,uiLang:"zh-CN",motherTongue:"zh-CN"},ct=new Map,Dn=p=>{if(ct.has(p))return ct.get(p);const s=oe.atom(g=>{const o=g(Je($e.USER_SETTINGS));return o&&p in o?o[p]:Ct[p]},(g,o,e)=>{const l={...g(Je($e.USER_SETTINGS))??Ct,[p]:e};o(Je($e.USER_SETTINGS),l)});return ct.set(p,s),s};var jn=function(p){q.useEffect(p,[])};const Bn=async({app:p,behaviors:s})=>{const g=pe.get(p);if(s.requiresAuth===!1)return g.getSnapshot();try{if(await g.loginUrlSessionOverride()){const e=await g.getProfiles();e.length>0&&g.setSelectedProfile(e[0].id)}return g.getSnapshot()}catch(o){return console.error(o),g.getSnapshot()}},Hn=({app:p,behaviors:s})=>{const[g,o]=q.useState(!0),[e,t]=q.useState({state:fe.Idle,profiles:[],profile:null,accountId:null,account:null,error:null});return jn(()=>{(async()=>{o(!0);const a=await Bn({app:p,behaviors:s});t(a),o(!1)})()}),{loading:g,snapshot:e}},_t="https://auth.pmate.chat";class Ge{static toLogin(s,g){if(typeof window>"u")return;const o=new URL(_t);o.searchParams.set("redirect",g??window.location.href),o.searchParams.set("app",s),window.location.href=o.toString()}static toCreateProfile(s,g){if(typeof window>"u")return;const o=new URL("/create-profile",_t);o.searchParams.set("redirect",g??window.location.href),o.searchParams.set("app",s),window.location.href=o.toString()}}class Jt extends Error{}const zn=(p,s)=>{const g=p?.find(t=>{const l=typeof t=="string"?t:t.path;return et.matchPath({path:l,end:!0},s)});return{authBehavior:g&&typeof g!="string"?g.behavior??"prompt":"prompt",requiresAuth:!!g}},$n=({app:p,authRoutes:s,rtcProvider:g,children:o})=>{const e=et.useLocation(),[t,l]=q.useState(!1),[a,w]=q.useState(!1),{authBehavior:y,requiresAuth:r}=zn(s,e.pathname),{loading:i,snapshot:n}=Hn({app:p,behaviors:{requiresAuth:r}}),c=n.error,m=n.state===fe.Idle?null:!!n.account;q.useEffect(()=>{if(!(!r||i)){if(n.account&&n.profiles.length===0&&e.pathname!=="/create-profile"){Ge.toCreateProfile(p);return}!n.account&&y==="redirect"&&Ge.toLogin(p)}},[p,y,i,e.pathname,r,n.account,n.profiles.length]),q.useEffect(()=>{i||l(r&&!n.account&&y==="prompt")},[y,i,r,n.account]),q.useEffect(()=>{c||w(!1)},[c]);const v=()=>{if(l(!1),window.history.length>1){window.history.back();return}};if(i&&r)return null;if(c&&r&&!a)return ne.jsx("div",{className:"flex min-h-screen items-center justify-center bg-slate-50 p-6",children:ne.jsxs("div",{className:"w-full max-w-md rounded-xl border border-rose-200 bg-white p-6 shadow-sm",children:[ne.jsx("div",{className:"text-sm font-semibold text-rose-600",children:"Login failed"}),ne.jsx("p",{className:"mt-2 text-sm text-slate-600",children:"We could not restore your session. Please try again."}),ne.jsx("div",{className:"mt-3 text-xs text-rose-500",children:c.message}),ne.jsx("div",{className:"mt-4 flex flex-wrap gap-3",children:ne.jsx("button",{className:"rounded-md bg-rose-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-rose-700",type:"button",onClick:()=>window.location.reload(),children:"Reload"})})]})});if(r&&m===null)return null;if(r&&m===!1&&y==="prompt")return ne.jsx(Qe.Drawer,{open:t,onClose:v,anchor:"bottom",overlayClassName:"bg-black/40",children:ne.jsxs("div",{className:"rounded-t-2xl px-6 pb-6 pt-4",children:[ne.jsx("div",{className:"mx-auto mb-3 h-1.5 w-12 rounded-full bg-slate-200"}),ne.jsx("div",{className:"text-lg font-semibold text-slate-900",children:"You need login to continue ?"}),ne.jsxs("div",{className:"mt-5 flex items-center justify-end gap-3",children:[ne.jsx(Qe.Button,{type:"button",variant:"plain",className:"min-w-[96px] justify-center",onClick:v,children:"Back"}),ne.jsx(Qe.Button,{type:"button",className:"min-w-[96px] justify-center",onClick:()=>Ge.toLogin(p),children:"Login"})]})]})});if(!r)return o;const T=g??(({children:b})=>ne.jsx(ne.Fragment,{children:b}));return ne.jsx(Vn,{children:ne.jsx(T,{children:o})})};class qn extends q.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(s){if(s instanceof Jt){this.props.onAuthError().then(()=>{this.setState({hasError:!1})});return}console.error(s)}render(){return this.state.hasError?null:this.props.children}}const Vn=({children:p})=>{const s=et.useNavigate(),g=oe.useSetAtom(Wt),o=q.useCallback(async()=>{await g(),s("/login",{replace:!0})},[g,s]);return ne.jsx(qn,{onAuthError:o,children:p})},Tt="https://parrot-static.pmate.chat",De="@pmate/chat",Qn="shuang",lt={[De]:{name:"Parrot Mate",icon:`${Tt}/parrot-logo.png`,background:"linear-gradient(135deg, #F472B6 0%, #8B5CF6 100%)",welcomeText:"Welcome!Parrot mate",profiles:[{type:"learning-language",title:"Learning Language",required:!0},{type:"nickname",title:"Nickname",required:!0}]},[Qn]:{name:"爽歪歪大王恋爱聊天机器人",icon:`${Tt}/shuang.webp`,background:"linear-gradient(180deg, #3b2ea8 0%, #0b0b0b 100%)",welcomeText:"欢迎来到爽歪歪大王恋爱聊天机器人~先选择角色开始聊天吧。",profiles:[{type:"gender",title:"您的性别",required:!0},{type:"is-adult",title:"是否成年",required:!0}]}},yt=p=>{const s=p??De,g=lt[s]??lt[De];return{id:lt[s]?s:De,...g}},xt="learning-language",Wn=({params:p})=>{const s=p.get("app"),g=p.get("redirect"),o=q.useMemo(()=>yt(s),[s]),e=q.useMemo(()=>o.profiles.map(m=>m.type),[o.profiles]),t=p.get("step"),l=e.find(m=>m===t)??null,a=e[0]??xt,w=l??a,y=q.useMemo(()=>e.length>0?e:[xt],[e]),r=y.indexOf(w),i=r>=0?y[r+1]:void 0,n=y.includes(w),c=q.useCallback(m=>{const v=new URLSearchParams;return v.set("step",m),s&&v.set("app",s),g&&v.set("redirect",g),`/create-profile?${v.toString()}`},[s,g]);return{activeStep:w,appProfileSteps:e,buildStepUrl:c,createSteps:y,isCreateFlowStep:n,nextStep:i}},Jn="https://auth.pmate.chat",Gn=()=>typeof window>"u"?"":window.location.href,Kn=(p={})=>{const s=we(p.app??De),g=q.useMemo(()=>p.redirect??Gn(),[p.redirect]),o=q.useCallback((v="/",T={})=>{const b=T.redirect??g,M=T.app??s,k=new URL(v,Jn);return b&&k.searchParams.set("redirect",b),M&&k.searchParams.set("app",M),k.toString()},[s,g]),e=q.useCallback((v,T={})=>{const b=new URL(o(v,T));return T.step&&b.searchParams.set("step",T.step),b.toString()},[o]),t=q.useCallback(v=>o("/logout",v),[o]),l=q.useCallback(v=>o("/",v),[o]),a=q.useCallback(v=>e("/create-profile",v),[e]),w=q.useCallback(v=>o("/select-profile",v),[o]),y=q.useCallback(v=>e("/edit-profile",v),[e]),r=q.useCallback(v=>{typeof window>"u"||window.location.assign(l(v))},[l]),i=q.useCallback(v=>{typeof window>"u"||window.location.assign(t(v))},[t]),n=q.useCallback(v=>{typeof window>"u"||window.location.assign(a(v))},[a]),c=q.useCallback(v=>{typeof window>"u"||window.location.assign(w(v))},[w]),m=q.useCallback(v=>{typeof window>"u"||window.location.assign(y(v))},[y]);return{app:s,login:r,logout:i,selectProfile:c,createProfile:n,updateProfile:m}},Yn=()=>{const[p]=et.useSearchParams(),s=p.get("app");return q.useMemo(()=>({background:yt(s).background}),[s])};Object.defineProperty(exports,"getLangFull",{enumerable:!0,get:()=>je.getLangFull});Object.defineProperty(exports,"isNicknameValid",{enumerable:!0,get:()=>je.isNicknameValid});Object.defineProperty(exports,"legacyLangMap",{enumerable:!0,get:()=>je.legacyLangMap});Object.defineProperty(exports,"normalizeLang",{enumerable:!0,get:()=>je.normalizeLang});exports.AccountManagerEvent=qt;exports.AccountManagerV2=pe;exports.AccountService=ve;exports.Api=Me;exports.AuthProviderV2=$n;exports.DEFAULT_APP_ID=De;exports.EntityService=qe;exports.LSKEYS=$e;exports.NotAuthenticatedError=Jt;exports.ProfileService=me;exports.Redirect=Ge;exports.accountAtom=nt;exports.accountStateAtom=gn;exports.createProfileAtom=Un;exports.getAppConfig=yt;exports.learningLangAtom=Mn;exports.localStorageJsonAtom=Je;exports.loginAtom=Ln;exports.motherTongueAtom=Nn;exports.profileAtom=rt;exports.profileByIdAtom=Qt;exports.profileDraftAtom=Vt;exports.profilesAtom=Fn;exports.resolveAppId=we;exports.sessionCheckAtom=On;exports.switchProfileAtom=En;exports.updateProfileAtom=kn;exports.uploadAvatarAtom=hn;exports.useAppBackgroundStyle=Yn;exports.useAuthApp=Kn;exports.useProfileStepFlow=Wn;exports.userLogoutAtom=Wt;exports.userSettingsAtom=Dn;
22
+ //# sourceMappingURL=index.cjs.js.map