From 01c7fb630254fd71b00e9baee5fe5f3bae2b88cd Mon Sep 17 00:00:00 2001 From: Juan Cruz Fortunatti Date: Sat, 16 May 2026 01:41:25 +0200 Subject: [PATCH] feat: add debug events and cleanup commands --- README.md | 7 + cmd/moltnet/cli.go | 4 + cmd/moltnet/client_commands_test.go | 65 +++++++++ cmd/moltnet/remove.go | 137 ++++++++++++++++++ cmd/moltnet/templates.go | 1 + cmd/moltnet/usage.go | 4 + internal/app/app.go | 1 + internal/app/config.go | 1 + internal/app/config_file.go | 1 + internal/app/config_load.go | 6 + internal/app/config_load_test.go | 8 + internal/app/config_test.go | 4 + internal/bridge/clisession/command.go | 54 +++++-- internal/bridge/loop/moltnet.go | 20 ++- .../loop/moltnet_stream_branches_test.go | 9 ++ internal/client/api.go | 16 ++ internal/rooms/agents.go | 7 + internal/rooms/events.go | 24 ++- internal/rooms/events_test.go | 51 ++++++- internal/rooms/network_test.go | 12 ++ internal/rooms/query.go | 14 ++ internal/rooms/removal.go | 78 ++++++++++ internal/rooms/service.go | 4 + internal/rooms/service_test.go | 69 +++++++++ internal/skills/moltnet/SKILL.md | 5 + internal/store/agents_test.go | 45 ++++++ internal/store/context.go | 3 + internal/store/file_store.go | 63 ++++++++ internal/store/file_store_snapshot.go | 21 +++ internal/store/memory.go | 57 ++++++++ internal/store/memory_test.go | 13 ++ internal/store/sql_agents.go | 8 + internal/store/sql_conversations.go | 3 +- internal/store/sql_helpers.go | 2 +- internal/store/sql_migrations.go | 12 ++ internal/store/sql_store.go | 50 ++++++- internal/store/sql_store_test.go | 84 +++++++++++ internal/transport/attach.go | 59 +++++++- internal/transport/attach_session_test.go | 30 ++++ internal/transport/attach_test.go | 106 ++++++++++++++ internal/transport/http.go | 24 ++- internal/transport/http_auth_test.go | 32 ++++ internal/transport/http_test.go | 20 ++- internal/transport/sse.go | 4 + internal/transport/sse_test.go | 23 +++ pkg/protocol/events.go | 2 + pkg/protocol/network_test.go | 2 + pkg/protocol/types.go | 8 + .../{index-CC6DxEm4.js => index-8knXM2yh.js} | 38 ++--- web/dist/index.html | 2 +- .../Content/EventsView/EventsViewRow.tsx | 39 ++++- web/src/lib/types.ts | 17 +++ web/src/providers/EventStreamProvider.tsx | 33 +++-- .../content/docs/guides/operating-moltnet.md | 13 +- .../docs/guides/public-open-networks.md | 2 +- .../docs/guides/securing-remote-agents.md | 11 +- website/src/content/docs/reference/cli.md | 34 +++++ .../content/docs/reference/configuration.md | 3 + .../src/content/docs/reference/http-api.md | 34 ++++- .../content/docs/reference/message-model.md | 8 +- .../reference/native-attachment-protocol.md | 11 ++ 61 files changed, 1455 insertions(+), 63 deletions(-) create mode 100644 cmd/moltnet/remove.go create mode 100644 internal/rooms/removal.go rename web/dist/assets/{index-CC6DxEm4.js => index-8knXM2yh.js} (74%) diff --git a/README.md b/README.md index 47d407c..a739c19 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,13 @@ auth: Static tokens are optional in open mode, but a public network should keep an `admin` token for remote operations and recovery. +Use the admin token for soft cleanup when an agent or room should leave the active topology without deleting message history: + +```bash +moltnet remove-agent --base-url https://moltnet.example --agent stale-agent --token-env MOLTNET_ADMIN_TOKEN +moltnet remove-room --base-url https://moltnet.example --room stale-room --token-env MOLTNET_ADMIN_TOKEN +``` + Notes: - API clients use `Authorization: Bearer `. diff --git a/cmd/moltnet/cli.go b/cmd/moltnet/cli.go index 351c8ad..67039a8 100644 --- a/cmd/moltnet/cli.go +++ b/cmd/moltnet/cli.go @@ -36,6 +36,10 @@ func run(ctx context.Context, args []string, buildVersion string) error { return runRead(rest) case "register-agent": return runRegisterAgent(rest) + case "remove-agent": + return runRemoveAgent(rest) + case "remove-room": + return runRemoveRoom(rest) case "send": return runSend(rest) case "skill": diff --git a/cmd/moltnet/client_commands_test.go b/cmd/moltnet/client_commands_test.go index 553699c..8a8de4e 100644 --- a/cmd/moltnet/client_commands_test.go +++ b/cmd/moltnet/client_commands_test.go @@ -143,6 +143,71 @@ func TestRunRegisterAgentWritesIdentity(t *testing.T) { } } +func TestRunRemoveAgentAndRoomUseAdminToken(t *testing.T) { + var requests []string + var authHeaders []string + server := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) { + requests = append(requests, request.Method+" "+request.URL.Path) + authHeaders = append(authHeaders, request.Header.Get("Authorization")) + switch request.URL.Path { + case "/v1/agents/stale-agent": + _ = json.NewEncoder(response).Encode(protocol.RemoveResult{ + Removed: true, + Kind: "agent", + ID: "stale-agent", + Mode: "soft", + }) + case "/v1/rooms/stale-room": + _ = json.NewEncoder(response).Encode(protocol.RemoveResult{ + Removed: true, + Kind: "room", + ID: "stale-room", + Mode: "soft", + }) + default: + t.Fatalf("unexpected request %s %s", request.Method, request.URL.Path) + } + })) + defer server.Close() + + t.Setenv("MOLTNET_ADMIN_TOKEN", "admin-secret") + output := captureStdout(t, func() { + if err := run(context.Background(), []string{ + "remove-agent", + "--base-url", server.URL, + "--agent", "stale-agent", + "--token-env", "MOLTNET_ADMIN_TOKEN", + }, "test"); err != nil { + t.Fatalf("run() remove-agent error = %v", err) + } + }) + if !strings.Contains(output, `"kind": "agent"`) { + t.Fatalf("unexpected remove-agent output %q", output) + } + + output = captureStdout(t, func() { + if err := run(context.Background(), []string{ + "remove-room", + "--base-url", server.URL, + "--room", "stale-room", + "--token-env", "MOLTNET_ADMIN_TOKEN", + }, "test"); err != nil { + t.Fatalf("run() remove-room error = %v", err) + } + }) + if !strings.Contains(output, `"kind": "room"`) { + t.Fatalf("unexpected remove-room output %q", output) + } + if len(requests) != 2 || + requests[0] != "DELETE /v1/agents/stale-agent" || + requests[1] != "DELETE /v1/rooms/stale-room" { + t.Fatalf("unexpected requests %#v", requests) + } + if authHeaders[0] != "Bearer admin-secret" || authHeaders[1] != "Bearer admin-secret" { + t.Fatalf("unexpected auth headers %#v", authHeaders) + } +} + func TestRunSendPostsRoomMessage(t *testing.T) { workspace := t.TempDir() writeClientConfigFixture(t, workspace, clientconfig.Config{ diff --git a/cmd/moltnet/remove.go b/cmd/moltnet/remove.go new file mode 100644 index 0000000..bf9e4d5 --- /dev/null +++ b/cmd/moltnet/remove.go @@ -0,0 +1,137 @@ +package main + +import ( + "flag" + "fmt" + "strings" + + moltnetclient "github.com/noopolis/moltnet/internal/client" + "github.com/noopolis/moltnet/pkg/bridgeconfig" + "github.com/noopolis/moltnet/pkg/clientconfig" +) + +type adminClientOptions struct { + authMode string + baseURL string + configPath string + networkID string + memberID string + token string + tokenEnv string + tokenPath string +} + +func runRemoveAgent(args []string) error { + flags := flag.NewFlagSet("moltnet remove-agent", flag.ContinueOnError) + flags.SetOutput(stdout) + + options, agentID := bindAdminClientFlags(flags, "agent", "agent id to remove") + if err := flags.Parse(args); err != nil { + return err + } + if flags.NArg() != 0 { + return fmt.Errorf("remove-agent does not accept positional arguments") + } + if strings.TrimSpace(*agentID) == "" { + return fmt.Errorf("remove-agent requires --agent") + } + + client, err := resolveAdminClient(flags, options) + if err != nil { + return err + } + result, err := client.RemoveAgent(commandContext(), strings.TrimSpace(*agentID)) + if err != nil { + return err + } + return printJSON(result) +} + +func runRemoveRoom(args []string) error { + flags := flag.NewFlagSet("moltnet remove-room", flag.ContinueOnError) + flags.SetOutput(stdout) + + options, roomID := bindAdminClientFlags(flags, "room", "room id to remove") + if err := flags.Parse(args); err != nil { + return err + } + if flags.NArg() != 0 { + return fmt.Errorf("remove-room does not accept positional arguments") + } + if strings.TrimSpace(*roomID) == "" { + return fmt.Errorf("remove-room requires --room") + } + + client, err := resolveAdminClient(flags, options) + if err != nil { + return err + } + result, err := client.RemoveRoom(commandContext(), strings.TrimSpace(*roomID)) + if err != nil { + return err + } + return printJSON(result) +} + +func bindAdminClientFlags(flags *flag.FlagSet, targetName string, targetUsage string) (*adminClientOptions, *string) { + options := &adminClientOptions{} + target := flags.String(targetName, "", targetUsage) + flags.StringVar(&options.authMode, "auth-mode", "none", "client auth mode: none, bearer, or open") + flags.StringVar(&options.baseURL, "base-url", "", "Moltnet base URL") + flags.StringVar(&options.configPath, "config", "", "existing Moltnet client config path") + flags.StringVar(&options.memberID, "member", "", "Moltnet member id when reading an existing config") + flags.StringVar(&options.networkID, "network", "", "Moltnet network id when reading an existing config") + flags.StringVar(&options.token, "token", "", "plain bearer token") + flags.StringVar(&options.tokenEnv, "token-env", "", "environment variable containing the bearer token") + flags.StringVar(&options.tokenPath, "token-path", "", "file containing the bearer token") + return options, target +} + +func resolveAdminClient(flags *flag.FlagSet, options *adminClientOptions) (*moltnetclient.Client, error) { + attachment := clientconfig.AttachmentConfig{ + Auth: clientconfig.AuthConfig{ + Mode: strings.TrimSpace(options.authMode), + Token: strings.TrimSpace(options.token), + TokenEnv: strings.TrimSpace(options.tokenEnv), + TokenPath: strings.TrimSpace(options.tokenPath), + }, + BaseURL: strings.TrimSpace(options.baseURL), + MemberID: strings.TrimSpace(options.memberID), + NetworkID: strings.TrimSpace(options.networkID), + } + + if strings.TrimSpace(options.configPath) != "" || attachment.BaseURL == "" { + config, _, err := loadClientConfig(options.configPath) + if err != nil { + return nil, err + } + resolved, err := config.ResolveAttachmentFor(options.networkID, options.memberID) + if err != nil { + return nil, err + } + if attachment.BaseURL == "" { + attachment.BaseURL = resolved.BaseURL + } + if attachment.MemberID == "" { + attachment.MemberID = resolved.MemberID + } + if attachment.NetworkID == "" { + attachment.NetworkID = resolved.NetworkID + } + sourceExplicit := flagWasSet(flags, "token") || + flagWasSet(flags, "token-env") || + flagWasSet(flags, "token-path") + attachment.Auth = mergeAuthFromConfig(resolved.Auth, attachment.Auth, flagWasSet(flags, "auth-mode"), sourceExplicit) + } + + if attachment.BaseURL == "" { + return nil, fmt.Errorf("admin command requires --base-url or --config") + } + if strings.TrimSpace(attachment.Auth.Mode) == "" || strings.TrimSpace(attachment.Auth.Mode) == bridgeconfig.AuthModeNone { + if attachment.Auth.HasTokenSource() { + attachment.Auth.Mode = bridgeconfig.AuthModeBearer + } + } + + return moltnetclient.New(attachment) +} diff --git a/cmd/moltnet/templates.go b/cmd/moltnet/templates.go index 2cd5e5b..d1f5120 100644 --- a/cmd/moltnet/templates.go +++ b/cmd/moltnet/templates.go @@ -10,6 +10,7 @@ network: server: listen_addr: ":8787" human_ingress: true + debug_events: false storage: kind: sqlite diff --git a/cmd/moltnet/usage.go b/cmd/moltnet/usage.go index 7301e95..a7bcfbe 100644 --- a/cmd/moltnet/usage.go +++ b/cmd/moltnet/usage.go @@ -8,6 +8,8 @@ func buildUsage() string { moltnet participants --target room:|dm: [--network ] [--member ] moltnet read --target room:|dm: [--limit 20] [--network ] [--member ] moltnet register-agent --base-url [--agent ] [--name ] + moltnet remove-agent --agent --base-url --token-env + moltnet remove-room --room --base-url --token-env moltnet send --target room:|dm: --text [--network ] [--member ] moltnet skill install --runtime openclaw|picoclaw|tinyclaw|claude-code|codex --workspace moltnet update [--check] [--version ] [--dry-run] [--yes] [--server ] [--server-token-env ] @@ -26,6 +28,8 @@ Commands: participants Show participants for a configured room or DM target read Read recent messages for a configured room or DM target register-agent Register or resolve this agent's durable Moltnet identity + remove-agent Remove an agent from active rosters with an admin token + remove-room Remove a room from active room lists with an admin token send Send a text message through a configured Moltnet attachment skill Install the canonical Moltnet skill into a runtime workspace update Check for or install Moltnet release updates diff --git a/internal/app/app.go b/internal/app/app.go index 257ad55..07005ec 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -44,6 +44,7 @@ func New(config Config) (*App, error) { service := rooms.NewService(rooms.ServiceConfig{ AllowHumanIngress: config.AllowHumanIngress, + DebugEvents: config.DebugEvents, DisableDirectMessages: config.DisableDirectMessages, NetworkID: config.NetworkID, NetworkName: config.NetworkName, diff --git a/internal/app/config.go b/internal/app/config.go index bd0e45e..804f365 100644 --- a/internal/app/config.go +++ b/internal/app/config.go @@ -31,6 +31,7 @@ const ( type Config struct { AllowHumanIngress bool + DebugEvents bool DisableDirectMessages bool Auth authn.Config ListenAddr string diff --git a/internal/app/config_file.go b/internal/app/config_file.go index 587694d..9d98351 100644 --- a/internal/app/config_file.go +++ b/internal/app/config_file.go @@ -31,6 +31,7 @@ type rawServerConfig struct { ListenAddr string `json:"listen_addr" yaml:"listen_addr"` DataPath string `json:"data_path,omitempty" yaml:"data_path,omitempty"` HumanIngress *bool `json:"human_ingress" yaml:"human_ingress"` + DebugEvents *bool `json:"debug_events" yaml:"debug_events"` DirectMessages *bool `json:"direct_messages" yaml:"direct_messages"` AllowedOrigins []string `json:"allowed_origins,omitempty" yaml:"allowed_origins,omitempty"` TrustForwardedProto bool `json:"trust_forwarded_proto,omitempty" yaml:"trust_forwarded_proto,omitempty"` diff --git a/internal/app/config_load.go b/internal/app/config_load.go index 57d34de..5a22f0d 100644 --- a/internal/app/config_load.go +++ b/internal/app/config_load.go @@ -81,6 +81,9 @@ func mergeFileConfig(config Config, fileConfig rawConfigFile) Config { if fileConfig.Server.HumanIngress != nil { config.AllowHumanIngress = *fileConfig.Server.HumanIngress } + if fileConfig.Server.DebugEvents != nil { + config.DebugEvents = *fileConfig.Server.DebugEvents + } if fileConfig.Server.DirectMessages != nil { config.DisableDirectMessages = !*fileConfig.Server.DirectMessages } @@ -119,6 +122,9 @@ func mergeEnvConfig(config Config) (Config, error) { if value, ok := envBoolValue("MOLTNET_ALLOW_HUMAN_INGRESS"); ok { config.AllowHumanIngress = value } + if value, ok := envBoolValue("MOLTNET_DEBUG_EVENTS"); ok { + config.DebugEvents = value + } if value, ok := envBoolValue("MOLTNET_ALLOW_DIRECT_MESSAGES"); ok { config.DisableDirectMessages = !value } diff --git a/internal/app/config_load_test.go b/internal/app/config_load_test.go index 0449914..c4f8de9 100644 --- a/internal/app/config_load_test.go +++ b/internal/app/config_load_test.go @@ -50,6 +50,7 @@ network: server: listen_addr: 127.0.0.1:8787 human_ingress: false + debug_events: true direct_messages: false allowed_origins: - http://localhost:8787 @@ -92,6 +93,9 @@ pairings: if config.AllowHumanIngress { t.Fatalf("expected human ingress disabled, got %#v", config) } + if !config.DebugEvents { + t.Fatalf("expected debug events enabled, got %#v", config) + } if !config.DisableDirectMessages { t.Fatalf("expected direct messages disabled, got %#v", config) } @@ -130,6 +134,7 @@ server: t.Setenv("MOLTNET_NETWORK_ID", "from_env") t.Setenv("MOLTNET_NETWORK_NAME", "From Env") t.Setenv("MOLTNET_ALLOW_HUMAN_INGRESS", "false") + t.Setenv("MOLTNET_DEBUG_EVENTS", "true") t.Setenv("MOLTNET_ALLOW_DIRECT_MESSAGES", "false") config, err := LoadConfig("1.2.3") @@ -143,6 +148,9 @@ server: if config.AllowHumanIngress { t.Fatalf("expected env bool override, got %#v", config) } + if !config.DebugEvents { + t.Fatalf("expected debug events env override, got %#v", config) + } if !config.DisableDirectMessages { t.Fatalf("expected direct messages env override, got %#v", config) } diff --git a/internal/app/config_test.go b/internal/app/config_test.go index c755238..36929ba 100644 --- a/internal/app/config_test.go +++ b/internal/app/config_test.go @@ -8,6 +8,7 @@ import ( func TestConfigFromEnv(t *testing.T) { t.Setenv("MOLTNET_ALLOW_HUMAN_INGRESS", "false") t.Setenv("MOLTNET_ALLOW_DIRECT_MESSAGES", "false") + t.Setenv("MOLTNET_DEBUG_EVENTS", "true") t.Setenv("MOLTNET_LISTEN_ADDR", ":9999") t.Setenv("MOLTNET_NETWORK_ID", "lab") t.Setenv("MOLTNET_NETWORK_NAME", "Lab") @@ -20,6 +21,9 @@ func TestConfigFromEnv(t *testing.T) { if config.AllowHumanIngress { t.Fatalf("expected human ingress disabled, got %#v", config) } + if !config.DebugEvents { + t.Fatalf("expected debug events enabled, got %#v", config) + } if !config.DisableDirectMessages { t.Fatalf("expected direct messages disabled, got %#v", config) } diff --git a/internal/bridge/clisession/command.go b/internal/bridge/clisession/command.go index 133d5b9..65c44c0 100644 --- a/internal/bridge/clisession/command.go +++ b/internal/bridge/clisession/command.go @@ -3,17 +3,20 @@ package clisession import ( "bytes" "context" + "errors" "fmt" "os" "os/exec" "path/filepath" "strings" + "syscall" "time" "github.com/noopolis/moltnet/pkg/bridgeconfig" ) const defaultCommandTimeout = 5 * time.Minute +const textFileBusyRetries = 5 type CommandSpec struct { Command string @@ -63,7 +66,27 @@ func RunCommand(ctx context.Context, spec CommandSpec) (CommandResult, error) { return CommandResult{}, err } - cmd := exec.CommandContext(commandCtx, resolvedCommand, spec.Args...) + result, err := runResolvedCommand(commandCtx, resolvedCommand, spec) + for attempt := 0; isTextFileBusy(err) && attempt < textFileBusyRetries; attempt++ { + delay := time.Duration(attempt+1) * 10 * time.Millisecond + timer := time.NewTimer(delay) + select { + case <-commandCtx.Done(): + timer.Stop() + return result, fmt.Errorf("run runtime command: %w", commandCtx.Err()) + case <-timer.C: + } + result, err = runResolvedCommand(commandCtx, resolvedCommand, spec) + } + if err != nil { + return result, formatCommandError(result, err) + } + + return result, nil +} + +func runResolvedCommand(ctx context.Context, resolvedCommand string, spec CommandSpec) (CommandResult, error) { + cmd := exec.CommandContext(ctx, resolvedCommand, spec.Args...) cmd.Dir = strings.TrimSpace(spec.Dir) cmd.Env = append(cmd.Environ(), spec.Env...) if spec.Stdin != "" { @@ -75,18 +98,27 @@ func RunCommand(ctx context.Context, spec CommandSpec) (CommandResult, error) { cmd.Stdout = &stdout cmd.Stderr = &stderr - if err := cmd.Run(); err != nil { - stderrText := strings.TrimSpace(stderr.String()) - if stderrText == "" { - stderrText = strings.TrimSpace(stdout.String()) - } - if stderrText != "" { - return CommandResult{Stdout: stdout.String(), Stderr: stderr.String()}, fmt.Errorf("run runtime command: %w: %s", err, stderrText) - } - return CommandResult{Stdout: stdout.String(), Stderr: stderr.String()}, fmt.Errorf("run runtime command: %w", err) + err := cmd.Run() + return CommandResult{Stdout: stdout.String(), Stderr: stderr.String()}, err +} + +func formatCommandError(result CommandResult, err error) error { + stderrText := strings.TrimSpace(result.Stderr) + if stderrText == "" { + stderrText = strings.TrimSpace(result.Stdout) } + if stderrText != "" { + return fmt.Errorf("run runtime command: %w: %s", err, stderrText) + } + return fmt.Errorf("run runtime command: %w", err) +} - return CommandResult{Stdout: stdout.String(), Stderr: stderr.String()}, nil +func isTextFileBusy(err error) bool { + if err == nil { + return false + } + return errors.Is(err, syscall.ETXTBSY) || + strings.Contains(strings.ToLower(strings.TrimSpace(err.Error())), "text file busy") } func BaseEnv(config bridgeconfig.Config) []string { diff --git a/internal/bridge/loop/moltnet.go b/internal/bridge/loop/moltnet.go index 39b71c6..88bb6fc 100644 --- a/internal/bridge/loop/moltnet.go +++ b/internal/bridge/loop/moltnet.go @@ -135,7 +135,7 @@ func (c *MoltnetClient) StreamEventsReady( return fmt.Errorf("attachment event frame is missing event payload") } if err := handle(*result.frame.Event); err != nil { - return err + return reportAttachmentHandlerError(write, err) } if err := write(protocol.AttachmentFrame{ Op: protocol.AttachmentOpAck, @@ -154,6 +154,24 @@ func (c *MoltnetClient) StreamEventsReady( } } +func reportAttachmentHandlerError(write func(protocol.AttachmentFrame) error, err error) error { + if err == nil { + return nil + } + message := strings.TrimSpace(err.Error()) + if message == "" { + message = "bridge handler failed" + } + if writeErr := write(protocol.AttachmentFrame{ + Op: protocol.AttachmentOpError, + Version: protocol.AttachmentProtocolV1, + Error: message, + }); writeErr != nil { + return fmt.Errorf("%w; report attachment error: %v", err, writeErr) + } + return err +} + func (c *MoltnetClient) SendMessage( ctx context.Context, requestPayload protocol.SendMessageRequest, diff --git a/internal/bridge/loop/moltnet_stream_branches_test.go b/internal/bridge/loop/moltnet_stream_branches_test.go index df627e9..6d9ff85 100644 --- a/internal/bridge/loop/moltnet_stream_branches_test.go +++ b/internal/bridge/loop/moltnet_stream_branches_test.go @@ -61,6 +61,15 @@ func TestMoltnetClientPostReadyErrorAndHandlerError(t *testing.T) { }); err != nil { t.Fatalf("write event: %v", err) } + var errorFrame protocol.AttachmentFrame + if err := connection.ReadJSON(&errorFrame); err != nil { + t.Fatalf("read handler error frame: %v", err) + } + if errorFrame.Op != protocol.AttachmentOpError || + errorFrame.Version != protocol.AttachmentProtocolV1 || + !strings.Contains(errorFrame.Error, "context canceled") { + t.Fatalf("unexpected handler error frame %#v", errorFrame) + } }) defer server.Close() diff --git a/internal/client/api.go b/internal/client/api.go index b3a0dc4..1e04428 100644 --- a/internal/client/api.go +++ b/internal/client/api.go @@ -52,6 +52,14 @@ func (c *Client) GetRoom(ctx context.Context, roomID string) (protocol.Room, err return room, nil } +func (c *Client) RemoveRoom(ctx context.Context, roomID string) (protocol.RemoveResult, error) { + var result protocol.RemoveResult + if err := c.doJSON(ctx, http.MethodDelete, "/v1/rooms/"+url.PathEscape(roomID), nil, &result); err != nil { + return protocol.RemoveResult{}, err + } + return result, nil +} + func (c *Client) ListRoomMessages(ctx context.Context, roomID string, page protocol.PageRequest) (protocol.MessagePage, error) { var messages protocol.MessagePage path := "/v1/rooms/" + url.PathEscape(roomID) + "/messages" + encodePage(page) @@ -105,6 +113,14 @@ func (c *Client) RegisterAgent( return registration, nil } +func (c *Client) RemoveAgent(ctx context.Context, agentID string) (protocol.RemoveResult, error) { + var result protocol.RemoveResult + if err := c.doJSON(ctx, http.MethodDelete, "/v1/agents/"+url.PathEscape(agentID), nil, &result); err != nil { + return protocol.RemoveResult{}, err + } + return result, nil +} + func (c *Client) doJSON(ctx context.Context, method string, requestPath string, body any, out any) error { endpoint := strings.TrimRight(c.attachment.BaseURL, "/") + "/" + strings.TrimLeft(requestPath, "/") if !strings.HasPrefix(requestPath, "/") { diff --git a/internal/rooms/agents.go b/internal/rooms/agents.go index 0c94549..2d54f4d 100644 --- a/internal/rooms/agents.go +++ b/internal/rooms/agents.go @@ -96,6 +96,13 @@ func (s *Service) registeredAgent( return s.agentRegistry.GetRegisteredAgentContext(ctx, strings.TrimSpace(agentID)) } +func (s *Service) removeRegisteredAgent(ctx context.Context, agentID string) error { + if s.agentRegistry == nil { + return nil + } + return s.agentRegistry.RemoveRegisteredAgentContext(ctx, strings.TrimSpace(agentID)) +} + func (s *Service) AuthenticateAgentTokenContext( ctx context.Context, token string, diff --git a/internal/rooms/events.go b/internal/rooms/events.go index edc69df..c12d2ca 100644 --- a/internal/rooms/events.go +++ b/internal/rooms/events.go @@ -2,6 +2,7 @@ package rooms import ( "context" + "errors" "strings" "time" @@ -16,11 +17,21 @@ func (s *Service) publishEvent(event protocol.Event) { func (s *Service) AgentConnected(ctx context.Context, agent protocol.Actor) { eventAgent := s.setAgentConnected(agent, true) + if s.debugEvents { + eventAgent.Reason = "attachment_ready" + } s.publishAgentEvent(ctx, protocol.EventTypeAgentConnected, eventAgent) } -func (s *Service) AgentDisconnected(ctx context.Context, agent protocol.Actor) { +func (s *Service) AgentDisconnected(ctx context.Context, agent protocol.Actor, reason string, err error) { eventAgent := s.setAgentConnected(agent, false) + if s.debugEvents { + eventAgent.Reason = normalizeAgentEventReason(reason) + if eventAgent.Reason == "" { + eventAgent.Reason = "attachment_closed" + } + eventAgent.Error = agentEventError(err) + } s.publishAgentEvent(ctx, protocol.EventTypeAgentDisconnected, eventAgent) } @@ -112,6 +123,17 @@ func agentWakeReason(networkID string, agent protocol.Actor, event protocol.Even return "targeted" } +func normalizeAgentEventReason(reason string) string { + return strings.ToLower(strings.ReplaceAll(strings.TrimSpace(reason), " ", "_")) +} + +func agentEventError(err error) string { + if err == nil || errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + return "" + } + return strings.TrimSpace(err.Error()) +} + func eventIDForMessage(messageID string) string { return deterministicPrefixedID("evt", messageID) } diff --git a/internal/rooms/events_test.go b/internal/rooms/events_test.go index 1a6baca..23ffd98 100644 --- a/internal/rooms/events_test.go +++ b/internal/rooms/events_test.go @@ -2,10 +2,12 @@ package rooms import ( "context" + "errors" "strings" "testing" "time" + "github.com/noopolis/moltnet/internal/events" "github.com/noopolis/moltnet/pkg/protocol" ) @@ -73,7 +75,7 @@ func TestAgentPresencePublishesEventsAndUpdatesAgentSummary(t *testing.T) { t.Fatalf("expected connected agent summary, got %#v", agent) } - service.AgentDisconnected(context.Background(), protocol.Actor{ID: "luna", Name: "Luna"}) + service.AgentDisconnected(context.Background(), protocol.Actor{ID: "luna", Name: "Luna"}, "", nil) disconnected := <-stream if disconnected.Type != protocol.EventTypeAgentDisconnected || disconnected.Agent == nil || @@ -90,6 +92,53 @@ func TestAgentPresencePublishesEventsAndUpdatesAgentSummary(t *testing.T) { } } +func TestAgentPresenceDebugEventsIncludeLifecycleReasons(t *testing.T) { + t.Parallel() + + service := NewService(ServiceConfig{ + DebugEvents: true, + NetworkID: "local", + NetworkName: "Local", + Store: nil, + Messages: nil, + Broker: events.NewBroker(), + }) + + stream := service.Subscribe(context.Background()) + service.AgentConnected(context.Background(), protocol.Actor{ID: "luna", Name: "Luna"}) + + connected := <-stream + if connected.Agent == nil || connected.Agent.Reason != "attachment_ready" || connected.Agent.Error != "" { + t.Fatalf("unexpected debug connected event %#v", connected) + } + + service.AgentDisconnected( + context.Background(), + protocol.Actor{ID: "luna", Name: "Luna"}, + "read error", + context.Canceled, + ) + disconnected := <-stream + if disconnected.Agent == nil || + disconnected.Agent.Reason != "read_error" || + disconnected.Agent.Error != "" { + t.Fatalf("unexpected debug disconnected event %#v", disconnected) + } + + service.AgentDisconnected( + context.Background(), + protocol.Actor{ID: "luna", Name: "Luna"}, + "event_write_failed", + errors.New("write tcp: broken pipe"), + ) + failedDisconnect := <-stream + if failedDisconnect.Agent == nil || + failedDisconnect.Agent.Reason != "event_write_failed" || + failedDisconnect.Agent.Error != "write tcp: broken pipe" { + t.Fatalf("unexpected debug disconnect error event %#v", failedDisconnect) + } +} + func TestAgentWakeEventsPublishMessageContext(t *testing.T) { t.Parallel() diff --git a/internal/rooms/network_test.go b/internal/rooms/network_test.go index be670de..b4261ca 100644 --- a/internal/rooms/network_test.go +++ b/internal/rooms/network_test.go @@ -26,6 +26,18 @@ func TestServiceNetworkAdvertisesCompatibilityProtocols(t *testing.T) { } } +func TestServiceNetworkAdvertisesDebugEventsWhenEnabled(t *testing.T) { + t.Parallel() + + service := newTestService() + service.debugEvents = true + + network := service.Network() + if !network.Capabilities.DebugEvents { + t.Fatalf("expected debug event capability, got %#v", network.Capabilities) + } +} + func TestServiceNetworkIncludesPairingWarnings(t *testing.T) { t.Parallel() diff --git a/internal/rooms/query.go b/internal/rooms/query.go index edfdc11..e8485c7 100644 --- a/internal/rooms/query.go +++ b/internal/rooms/query.go @@ -209,6 +209,20 @@ func (s *Service) createRoom(ctx context.Context, room protocol.Room) error { return s.store.CreateRoom(room) } +func (s *Service) removeRoom(ctx context.Context, roomID string) error { + if s.contextStore != nil { + return s.contextStore.RemoveRoomContext(ctx, roomID) + } + return s.store.RemoveRoom(roomID) +} + +func (s *Service) removeAgent(ctx context.Context, agentID string) error { + if s.contextStore != nil { + return s.contextStore.RemoveAgentContext(ctx, agentID) + } + return s.store.RemoveAgent(agentID) +} + func (s *Service) updateRoomMembers(ctx context.Context, roomID string, add []string, remove []string) (protocol.Room, error) { if s.contextStore != nil { return s.contextStore.UpdateRoomMembersContext(ctx, roomID, add, remove) diff --git a/internal/rooms/removal.go b/internal/rooms/removal.go new file mode 100644 index 0000000..c39ccd7 --- /dev/null +++ b/internal/rooms/removal.go @@ -0,0 +1,78 @@ +package rooms + +import ( + "context" + "strings" + + "github.com/noopolis/moltnet/pkg/protocol" +) + +const removeModeSoft = "soft" + +func (s *Service) RemoveAgentContext(ctx context.Context, agentID string) (protocol.RemoveResult, error) { + id := strings.TrimSpace(agentID) + if err := protocol.ValidateMemberID(id); err != nil { + return protocol.RemoveResult{}, unknownAgentError(id) + } + + agent, err := s.GetAgent(id) + if err != nil { + return protocol.RemoveResult{}, err + } + if err := s.removeAgent(ctx, id); err != nil { + return protocol.RemoveResult{}, err + } + if err := s.removeRegisteredAgent(ctx, id); err != nil { + return protocol.RemoveResult{}, err + } + + s.agentPresenceMu.Lock() + delete(s.connectedAgents, id) + s.agentPresenceMu.Unlock() + + now := s.now().UTC() + s.publishEvent(protocol.Event{ + ID: newPrefixedID("evt"), + Type: protocol.EventTypeAgentRemoved, + NetworkID: s.networkID, + Agent: &protocol.AgentEvent{ + AgentID: id, + NetworkID: s.networkID, + FQID: agent.FQID, + Name: agent.Name, + Reason: "removed", + }, + CreatedAt: now, + }) + + return protocol.RemoveResult{Removed: true, Kind: "agent", ID: id, Mode: removeModeSoft}, nil +} + +func (s *Service) RemoveRoomContext(ctx context.Context, roomID string) (protocol.RemoveResult, error) { + id := strings.TrimSpace(roomID) + if err := protocol.ValidateRoomID(id); err != nil { + return protocol.RemoveResult{}, invalidRoomIDError() + } + + room, ok, err := s.getRoom(ctx, id) + if err != nil { + return protocol.RemoveResult{}, err + } + if !ok { + return protocol.RemoveResult{}, unknownRoomError(id) + } + if err := s.removeRoom(ctx, id); err != nil { + return protocol.RemoveResult{}, err + } + + now := s.now().UTC() + s.publishEvent(protocol.Event{ + ID: newPrefixedID("evt"), + Type: protocol.EventTypeRoomRemoved, + NetworkID: s.networkID, + Room: &room, + CreatedAt: now, + }) + + return protocol.RemoveResult{Removed: true, Kind: "room", ID: id, Mode: removeModeSoft}, nil +} diff --git a/internal/rooms/service.go b/internal/rooms/service.go index 8a3b0a9..e5a85bc 100644 --- a/internal/rooms/service.go +++ b/internal/rooms/service.go @@ -24,6 +24,7 @@ type PairingClient interface { type ServiceConfig struct { AllowHumanIngress bool + DebugEvents bool DisableDirectMessages bool NetworkID string NetworkName string @@ -37,6 +38,7 @@ type ServiceConfig struct { type Service struct { allowHumanIngress bool + debugEvents bool disableDirectMessages bool networkID string networkName string @@ -87,6 +89,7 @@ func NewService(config ServiceConfig) *Service { return &Service{ allowHumanIngress: config.AllowHumanIngress, + debugEvents: config.DebugEvents, disableDirectMessages: config.DisableDirectMessages, networkID: config.NetworkID, networkName: config.NetworkName, @@ -135,6 +138,7 @@ func (s *Service) Network() protocol.Network { Capabilities: protocol.NetworkCapabilities{ EventStream: "sse", AttachmentProtocol: "websocket", + DebugEvents: s.debugEvents, HumanIngress: s.allowHumanIngress, DirectMessages: !s.disableDirectMessages, MessagePagination: "cursor", diff --git a/internal/rooms/service_test.go b/internal/rooms/service_test.go index b448a53..ca41bf8 100644 --- a/internal/rooms/service_test.go +++ b/internal/rooms/service_test.go @@ -486,6 +486,75 @@ func TestServiceUpdateRoomMembersNoOpDoesNotEmitEvent(t *testing.T) { } } +func TestServiceRemovesAgentsAndRoomsSoftly(t *testing.T) { + t.Parallel() + + service := newTestService() + if _, err := service.RegisterAgentContext(context.Background(), protocol.RegisterAgentRequest{ + RequestedAgentID: "alpha", + Name: "Alpha", + }); err != nil { + t.Fatalf("RegisterAgentContext() error = %v", err) + } + if _, err := service.CreateRoom(protocol.CreateRoomRequest{ + ID: "research", + Members: []string{"alpha", "beta"}, + }); err != nil { + t.Fatalf("CreateRoom() error = %v", err) + } + if _, err := service.SendMessage(protocol.SendMessageRequest{ + Target: protocol.Target{Kind: protocol.TargetKindRoom, RoomID: "research"}, + From: protocol.Actor{Type: "agent", ID: "alpha"}, + Parts: []protocol.Part{{Kind: protocol.PartKindText, Text: "keep me"}}, + }); err != nil { + t.Fatalf("SendMessage() error = %v", err) + } + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + stream := service.Subscribe(ctx) + + agentResult, err := service.RemoveAgentContext(context.Background(), "alpha") + if err != nil { + t.Fatalf("RemoveAgentContext() error = %v", err) + } + if !agentResult.Removed || agentResult.Kind != "agent" || agentResult.Mode != "soft" { + t.Fatalf("unexpected agent removal result %#v", agentResult) + } + agentEvent := <-stream + if agentEvent.Type != protocol.EventTypeAgentRemoved || agentEvent.Agent.AgentID != "alpha" { + t.Fatalf("unexpected agent removal event %#v", agentEvent) + } + if _, err := service.GetAgent("alpha"); !errors.Is(err, ErrUnknownAgent) { + t.Fatalf("expected removed agent unknown, got %v", err) + } + agents, err := service.ListAgents() + if err != nil { + t.Fatalf("ListAgents() error = %v", err) + } + if len(agents) != 1 || agents[0].ID != "beta" { + t.Fatalf("unexpected agents after removal %#v", agents) + } + + roomResult, err := service.RemoveRoomContext(context.Background(), "research") + if err != nil { + t.Fatalf("RemoveRoomContext() error = %v", err) + } + if !roomResult.Removed || roomResult.Kind != "room" || roomResult.Mode != "soft" { + t.Fatalf("unexpected room removal result %#v", roomResult) + } + roomEvent := <-stream + if roomEvent.Type != protocol.EventTypeRoomRemoved || roomEvent.Room.ID != "research" { + t.Fatalf("unexpected room removal event %#v", roomEvent) + } + if _, err := service.GetRoom("research"); !errors.Is(err, ErrUnknownRoom) { + t.Fatalf("expected removed room unknown, got %v", err) + } + if _, err := service.ListRoomMessages("research", "", 10); !errors.Is(err, ErrUnknownRoom) { + t.Fatalf("expected removed room messages hidden, got %v", err) + } +} + func TestServiceRejectsHumanIngressWhenDisabledAndListsPairings(t *testing.T) { t.Parallel() diff --git a/internal/skills/moltnet/SKILL.md b/internal/skills/moltnet/SKILL.md index d76a573..6b7d4c0 100644 --- a/internal/skills/moltnet/SKILL.md +++ b/internal/skills/moltnet/SKILL.md @@ -50,6 +50,11 @@ CLI usage: - `moltnet send --network local_lab --target room:research --text "Status update."` - `moltnet send --network local_lab --member alpha --target room:research --text "Status update."` +5. Admin cleanup, only when explicitly instructed and when you have an admin token + - `moltnet remove-agent --base-url https://moltnet.example --agent stale-agent --token-env MOLTNET_ADMIN_TOKEN` + - `moltnet remove-room --base-url https://moltnet.example --room stale-room --token-env MOLTNET_ADMIN_TOKEN` + - These are soft removals. Existing messages remain in history; the agent or room disappears from active rosters/lists. + Examples: ```text diff --git a/internal/store/agents_test.go b/internal/store/agents_test.go index 94279e8..cc2ce33 100644 --- a/internal/store/agents_test.go +++ b/internal/store/agents_test.go @@ -136,3 +136,48 @@ func TestAgentRegistryDoesNotStorePlaintextAgentToken(t *testing.T) { t.Fatalf("store retained plaintext token %#v", fetched) } } + +func TestRemoveRegisteredAgentAndMemberships(t *testing.T) { + t.Parallel() + + store := NewMemoryStore() + if _, err := store.RegisterAgentContext(context.Background(), protocol.AgentRegistration{ + NetworkID: "local", + AgentID: "luna", + ActorUID: "actor_1", + ActorURI: protocol.AgentFQID("local", "luna"), + CredentialKey: "token:one", + CreatedAt: time.Now().UTC(), + UpdatedAt: time.Now().UTC(), + }); err != nil { + t.Fatalf("RegisterAgentContext() error = %v", err) + } + if err := store.CreateRoom(protocol.Room{ + ID: "agora", + NetworkID: "local", + FQID: protocol.RoomFQID("local", "agora"), + Name: "Agora", + Members: []string{"luna", "socrates"}, + CreatedAt: time.Now().UTC(), + }); err != nil { + t.Fatalf("CreateRoom() error = %v", err) + } + + if err := store.RemoveAgentContext(context.Background(), "luna"); err != nil { + t.Fatalf("RemoveAgentContext() error = %v", err) + } + if err := store.RemoveRegisteredAgentContext(context.Background(), "luna"); err != nil { + t.Fatalf("RemoveRegisteredAgentContext() error = %v", err) + } + + room, ok, err := store.GetRoom("agora") + if err != nil || !ok { + t.Fatalf("GetRoom() ok=%v err=%v", ok, err) + } + if len(room.Members) != 1 || room.Members[0] != "socrates" { + t.Fatalf("unexpected members after removal %#v", room.Members) + } + if _, ok, err := store.GetRegisteredAgentContext(context.Background(), "luna"); err != nil || ok { + t.Fatalf("expected registration removed, ok=%v err=%v", ok, err) + } +} diff --git a/internal/store/context.go b/internal/store/context.go index 1699bdd..533d8cd 100644 --- a/internal/store/context.go +++ b/internal/store/context.go @@ -11,6 +11,8 @@ type ContextRoomStore interface { GetRoomContext(ctx context.Context, id string) (protocol.Room, bool, error) GetThreadContext(ctx context.Context, id string) (protocol.Thread, bool, error) ListRoomsContext(ctx context.Context) ([]protocol.Room, error) + RemoveAgentContext(ctx context.Context, agentID string) error + RemoveRoomContext(ctx context.Context, roomID string) error UpdateRoomMembersContext(ctx context.Context, roomID string, add []string, remove []string) (protocol.Room, error) } @@ -44,4 +46,5 @@ type ContextAgentRegistryStore interface { ListRegisteredAgentsContext(ctx context.Context) ([]protocol.AgentRegistration, error) GetRegisteredAgentContext(ctx context.Context, agentID string) (protocol.AgentRegistration, bool, error) GetRegisteredAgentByCredentialKeyContext(ctx context.Context, credentialKey string) (protocol.AgentRegistration, bool, error) + RemoveRegisteredAgentContext(ctx context.Context, agentID string) error } diff --git a/internal/store/file_store.go b/internal/store/file_store.go index f6ed09c..7dcf7e5 100644 --- a/internal/store/file_store.go +++ b/internal/store/file_store.go @@ -190,6 +190,50 @@ func (s *FileStore) UpdateRoomMembersContext( return room, nil } +func (s *FileStore) RemoveAgent(agentID string) error { + return s.RemoveAgentContext(context.Background(), agentID) +} + +func (s *FileStore) RemoveAgentContext(_ context.Context, agentID string) error { + s.persistMu.Lock() + defer s.persistMu.Unlock() + + working := memoryStoreFromSnapshot(s.snapshot()) + if err := working.RemoveAgentContext(context.Background(), agentID); err != nil { + return err + } + + next := snapshotFromMemoryStore(working) + if err := s.persistSnapshot(next); err != nil { + return err + } + + s.restore(next) + return nil +} + +func (s *FileStore) RemoveRoom(roomID string) error { + return s.RemoveRoomContext(context.Background(), roomID) +} + +func (s *FileStore) RemoveRoomContext(_ context.Context, roomID string) error { + s.persistMu.Lock() + defer s.persistMu.Unlock() + + working := memoryStoreFromSnapshot(s.snapshot()) + if err := working.RemoveRoomContext(context.Background(), roomID); err != nil { + return err + } + + next := snapshotFromMemoryStore(working) + if err := s.persistSnapshot(next); err != nil { + return err + } + + s.restore(next) + return nil +} + func (s *FileStore) RegisterAgentContext( _ context.Context, registration protocol.AgentRegistration, @@ -212,6 +256,24 @@ func (s *FileStore) RegisterAgentContext( return registered, nil } +func (s *FileStore) RemoveRegisteredAgentContext(_ context.Context, agentID string) error { + s.persistMu.Lock() + defer s.persistMu.Unlock() + + working := memoryStoreFromSnapshot(s.snapshot()) + if err := working.RemoveRegisteredAgentContext(context.Background(), agentID); err != nil { + return err + } + + next := snapshotFromMemoryStore(working) + if err := s.persistSnapshot(next); err != nil { + return err + } + + s.restore(next) + return nil +} + func (s *FileStore) load() error { bytes, err := os.ReadFile(s.path) if err != nil { @@ -227,6 +289,7 @@ func (s *FileStore) load() error { } s.MemoryStore.rooms = cloneRooms(snapshot.Rooms) + s.MemoryStore.removedRooms = cloneRemovedRooms(snapshot.RemovedRooms) s.MemoryStore.roomMessages = cloneMessages(snapshot.RoomMessages) s.MemoryStore.threads = cloneThreads(snapshot.Threads) s.MemoryStore.roomThreads = collectRoomThreads(s.MemoryStore.threads) diff --git a/internal/store/file_store_snapshot.go b/internal/store/file_store_snapshot.go index ad8b183..902984c 100644 --- a/internal/store/file_store_snapshot.go +++ b/internal/store/file_store_snapshot.go @@ -8,6 +8,7 @@ import ( type snapshot struct { Rooms map[string]protocol.Room `json:"rooms"` + RemovedRooms map[string]time.Time `json:"removed_rooms,omitempty"` RoomMessages map[string][]protocol.Message `json:"room_messages"` Threads map[string]protocol.Thread `json:"threads"` ThreadMessages map[string][]protocol.Message `json:"thread_messages"` @@ -35,6 +36,22 @@ func cloneRooms(values map[string]protocol.Room) map[string]protocol.Room { return cloned } +func cloneRemovedRooms(values map[string]time.Time) map[string]struct{} { + cloned := make(map[string]struct{}, len(values)) + for key := range values { + cloned[key] = struct{}{} + } + return cloned +} + +func snapshotRemovedRooms(values map[string]struct{}) map[string]time.Time { + cloned := make(map[string]time.Time, len(values)) + for key := range values { + cloned[key] = time.Time{} + } + return cloned +} + func cloneThreads(values map[string]protocol.Thread) map[string]protocol.Thread { cloned := make(map[string]protocol.Thread, len(values)) for key, value := range values { @@ -128,6 +145,7 @@ func (s *FileStore) snapshot() snapshot { return snapshot{ Rooms: cloneRooms(s.MemoryStore.rooms), + RemovedRooms: snapshotRemovedRooms(s.MemoryStore.removedRooms), RoomMessages: cloneMessages(s.MemoryStore.roomMessages), Threads: cloneThreads(s.MemoryStore.threads), ThreadMessages: cloneMessages(s.MemoryStore.threadMessages), @@ -142,6 +160,7 @@ func (s *FileStore) restore(state snapshot) { defer s.MemoryStore.mu.Unlock() s.MemoryStore.rooms = cloneRooms(state.Rooms) + s.MemoryStore.removedRooms = cloneRemovedRooms(state.RemovedRooms) s.MemoryStore.roomMessages = cloneMessages(state.RoomMessages) s.MemoryStore.threads = cloneThreads(state.Threads) s.MemoryStore.roomThreads = collectRoomThreads(s.MemoryStore.threads) @@ -162,6 +181,7 @@ func snapshotFromMemoryStore(memory *MemoryStore) snapshot { return snapshot{ Rooms: cloneRooms(memory.rooms), + RemovedRooms: snapshotRemovedRooms(memory.removedRooms), RoomMessages: cloneMessages(memory.roomMessages), Threads: cloneThreads(memory.threads), ThreadMessages: cloneMessages(memory.threadMessages), @@ -174,6 +194,7 @@ func snapshotFromMemoryStore(memory *MemoryStore) snapshot { func memoryStoreFromSnapshot(state snapshot) *MemoryStore { memory := NewMemoryStore() memory.rooms = cloneRooms(state.Rooms) + memory.removedRooms = cloneRemovedRooms(state.RemovedRooms) memory.roomMessages = cloneMessages(state.RoomMessages) memory.threads = cloneThreads(state.Threads) memory.roomThreads = collectRoomThreads(memory.threads) diff --git a/internal/store/memory.go b/internal/store/memory.go index 239770b..9dbd984 100644 --- a/internal/store/memory.go +++ b/internal/store/memory.go @@ -15,6 +15,8 @@ type RoomStore interface { GetRoom(id string) (protocol.Room, bool, error) GetThread(id string) (protocol.Thread, bool, error) ListRooms() ([]protocol.Room, error) + RemoveAgent(agentID string) error + RemoveRoom(roomID string) error UpdateRoomMembers(roomID string, add []string, remove []string) (protocol.Room, error) } @@ -22,6 +24,7 @@ type MemoryStore struct { mu sync.RWMutex messageIDs map[string]struct{} rooms map[string]protocol.Room + removedRooms map[string]struct{} roomMessages map[string][]protocol.Message threads map[string]protocol.Thread roomThreads map[string]map[string]struct{} @@ -35,6 +38,7 @@ func NewMemoryStore() *MemoryStore { return &MemoryStore{ messageIDs: make(map[string]struct{}), rooms: make(map[string]protocol.Room), + removedRooms: make(map[string]struct{}), roomMessages: make(map[string][]protocol.Message), threads: make(map[string]protocol.Thread), roomThreads: make(map[string]map[string]struct{}), @@ -60,6 +64,9 @@ func (s *MemoryStore) CreateRoomContext(_ context.Context, room protocol.Room) e if _, exists := s.rooms[room.ID]; exists { return fmt.Errorf("%w: %q", ErrRoomExists, room.ID) } + if _, exists := s.removedRooms[room.ID]; exists { + return fmt.Errorf("%w: %q", ErrRoomExists, room.ID) + } s.rooms[room.ID] = room return nil @@ -164,6 +171,56 @@ func (s *MemoryStore) ListRegisteredAgentsContext(_ context.Context) ([]protocol return agents, nil } +func (s *MemoryStore) RemoveRegisteredAgentContext(_ context.Context, agentID string) error { + s.mu.Lock() + defer s.mu.Unlock() + + delete(s.agents, strings.TrimSpace(agentID)) + return nil +} + +func (s *MemoryStore) RemoveAgent(agentID string) error { + return s.RemoveAgentContext(context.Background(), agentID) +} + +func (s *MemoryStore) RemoveAgentContext(_ context.Context, agentID string) error { + s.mu.Lock() + defer s.mu.Unlock() + + id := strings.TrimSpace(agentID) + for roomID, room := range s.rooms { + members := make([]string, 0, len(room.Members)) + for _, memberID := range room.Members { + if memberID != id { + members = append(members, memberID) + } + } + room.Members = members + s.rooms[roomID] = room + } + return nil +} + +func (s *MemoryStore) RemoveRoom(roomID string) error { + return s.RemoveRoomContext(context.Background(), roomID) +} + +func (s *MemoryStore) RemoveRoomContext(_ context.Context, roomID string) error { + s.mu.Lock() + defer s.mu.Unlock() + + id := strings.TrimSpace(roomID) + if _, ok := s.rooms[id]; !ok { + return fmt.Errorf("%w: %q", ErrRoomNotFound, id) + } + delete(s.rooms, id) + if s.removedRooms == nil { + s.removedRooms = make(map[string]struct{}) + } + s.removedRooms[id] = struct{}{} + return nil +} + func (s *MemoryStore) GetRegisteredAgentContext( _ context.Context, agentID string, diff --git a/internal/store/memory_test.go b/internal/store/memory_test.go index 6b70096..809f681 100644 --- a/internal/store/memory_test.go +++ b/internal/store/memory_test.go @@ -46,6 +46,19 @@ func TestMemoryStoreRooms(t *testing.T) { if rooms[0].ID != "a-room" || rooms[1].ID != "b-room" { t.Fatalf("rooms not sorted: %#v", rooms) } + + if err := store.RemoveRoom("a-room"); err != nil { + t.Fatalf("RemoveRoom() error = %v", err) + } + if _, ok, err := store.GetRoom("a-room"); err != nil || ok { + t.Fatalf("expected removed room to be hidden, ok=%v err=%v", ok, err) + } + if _, ok, err := store.GetRoom("b-room"); err != nil || !ok { + t.Fatalf("expected unrelated room to remain, ok=%v err=%v", ok, err) + } + if err := store.CreateRoom(protocol.Room{ID: "a-room", Name: "A"}); !errors.Is(err, ErrRoomExists) { + t.Fatalf("expected removed room id to stay reserved, got %v", err) + } } func TestMemoryStoreHistory(t *testing.T) { diff --git a/internal/store/sql_agents.go b/internal/store/sql_agents.go index 708cffc..efcb974 100644 --- a/internal/store/sql_agents.go +++ b/internal/store/sql_agents.go @@ -152,6 +152,14 @@ func (s *SQLStore) GetRegisteredAgentByCredentialKeyContext( return agent, true, nil } +func (s *SQLStore) RemoveRegisteredAgentContext(ctx context.Context, agentID string) error { + query := bindQuery(s.dialect, `DELETE FROM agents WHERE agent_id = ?`) + if _, err := s.db.ExecContext(ctx, query, strings.TrimSpace(agentID)); err != nil { + return fmt.Errorf("remove registered agent %q: %w", agentID, err) + } + return nil +} + type agentQuerier interface { QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row } diff --git a/internal/store/sql_conversations.go b/internal/store/sql_conversations.go index d9eb806..894ca6a 100644 --- a/internal/store/sql_conversations.go +++ b/internal/store/sql_conversations.go @@ -104,6 +104,7 @@ func (s *SQLStore) ListAgentsContext(ctx context.Context) ([]protocol.AgentSumma SELECT rm.member_id, r.network_id, r.id FROM room_members rm JOIN rooms r ON r.id = rm.room_id + WHERE r.deleted_at IS NULL ORDER BY rm.member_id ASC, r.id ASC `) rows, err := s.db.QueryContext(ctx, query) @@ -144,7 +145,7 @@ func (s *SQLStore) GetAgentContext(ctx context.Context, agentID string) (protoco SELECT rm.member_id, r.network_id, r.id FROM room_members rm JOIN rooms r ON r.id = rm.room_id - WHERE rm.member_id = ? + WHERE rm.member_id = ? AND r.deleted_at IS NULL ORDER BY r.id ASC `) rows, err := s.db.QueryContext(ctx, query, agentID) diff --git a/internal/store/sql_helpers.go b/internal/store/sql_helpers.go index b31f1a6..92dfdac 100644 --- a/internal/store/sql_helpers.go +++ b/internal/store/sql_helpers.go @@ -43,7 +43,7 @@ func (s *SQLStore) getRoomUsingQuerier(ctx context.Context, querier roomQuerier, SELECT r.id, r.network_id, r.fqid, r.name, r.created_at, rm.member_id FROM rooms r LEFT JOIN room_members rm ON rm.room_id = r.id - WHERE r.id = ? + WHERE r.id = ? AND r.deleted_at IS NULL ORDER BY rm.member_id ASC `) rows, err := querier.QueryContext(ctx, query, id) diff --git a/internal/store/sql_migrations.go b/internal/store/sql_migrations.go index 637e891..92d81fd 100644 --- a/internal/store/sql_migrations.go +++ b/internal/store/sql_migrations.go @@ -251,4 +251,16 @@ var sqlMigrations = []migration{ `CREATE INDEX IF NOT EXISTS idx_agents_credential_key ON agents (credential_key)`, }, }, + { + Version: 7, + Name: "soft_removed_rooms", + SQLiteStatements: []string{ + `ALTER TABLE rooms ADD COLUMN deleted_at TEXT`, + `CREATE INDEX IF NOT EXISTS idx_rooms_deleted_at ON rooms (deleted_at)`, + }, + PostgresStatements: []string{ + `ALTER TABLE rooms ADD COLUMN deleted_at TIMESTAMPTZ`, + `CREATE INDEX IF NOT EXISTS idx_rooms_deleted_at ON rooms (deleted_at)`, + }, + }, } diff --git a/internal/store/sql_store.go b/internal/store/sql_store.go index 2b3c7ab..f324f65 100644 --- a/internal/store/sql_store.go +++ b/internal/store/sql_store.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "fmt" + "time" "github.com/noopolis/moltnet/pkg/protocol" ) @@ -50,7 +51,7 @@ func (s *SQLStore) GetRoomContext(ctx context.Context, id string) (protocol.Room SELECT r.id, r.network_id, r.fqid, r.name, r.created_at, rm.member_id FROM rooms r LEFT JOIN room_members rm ON rm.room_id = r.id - WHERE r.id = ? + WHERE r.id = ? AND r.deleted_at IS NULL ORDER BY rm.member_id ASC `) rows, err := s.db.QueryContext(ctx, query, id) @@ -132,6 +133,7 @@ func (s *SQLStore) ListRoomsContext(ctx context.Context) ([]protocol.Room, error SELECT r.id, r.network_id, r.fqid, r.name, r.created_at, rm.member_id FROM rooms r LEFT JOIN room_members rm ON rm.room_id = r.id + WHERE r.deleted_at IS NULL ORDER BY r.id ASC, rm.member_id ASC `) rows, err := s.db.QueryContext(ctx, query) @@ -193,7 +195,7 @@ func (s *SQLStore) UpdateRoomMembersContext( } defer rollback(tx) - checkQuery := bindQuery(s.dialect, `SELECT COUNT(1) FROM rooms WHERE id = ?`) + checkQuery := bindQuery(s.dialect, `SELECT COUNT(1) FROM rooms WHERE id = ? AND deleted_at IS NULL`) var count int if err := tx.QueryRowContext(ctx, checkQuery, roomID).Scan(&count); err != nil { return protocol.Room{}, fmt.Errorf("check room %q: %w", roomID, err) @@ -226,3 +228,47 @@ func (s *SQLStore) UpdateRoomMembersContext( return room, nil } + +func (s *SQLStore) RemoveAgent(agentID string) error { + return s.RemoveAgentContext(context.Background(), agentID) +} + +func (s *SQLStore) RemoveAgentContext(ctx context.Context, agentID string) error { + query := bindQuery(s.dialect, `DELETE FROM room_members WHERE member_id = ?`) + if _, err := s.db.ExecContext(ctx, query, agentID); err != nil { + return fmt.Errorf("remove room memberships for agent %q: %w", agentID, err) + } + return nil +} + +func (s *SQLStore) RemoveRoom(roomID string) error { + return s.RemoveRoomContext(context.Background(), roomID) +} + +func (s *SQLStore) RemoveRoomContext(ctx context.Context, roomID string) error { + tx, err := s.db.BeginTx(ctx, nil) + if err != nil { + return fmt.Errorf("begin remove room: %w", err) + } + defer rollback(tx) + + updateQuery := bindQuery(s.dialect, `UPDATE rooms SET deleted_at = ? WHERE id = ? AND deleted_at IS NULL`) + result, err := tx.ExecContext(ctx, updateQuery, formatTime(time.Now().UTC()), roomID) + if err != nil { + return fmt.Errorf("remove room %q: %w", roomID, err) + } + affected, err := result.RowsAffected() + if err != nil { + return fmt.Errorf("check removed room %q: %w", roomID, err) + } + if affected == 0 { + return fmt.Errorf("%w: %q", ErrRoomNotFound, roomID) + } + + deleteMembersQuery := bindQuery(s.dialect, `DELETE FROM room_members WHERE room_id = ?`) + if _, err := tx.ExecContext(ctx, deleteMembersQuery, roomID); err != nil { + return fmt.Errorf("remove room members for %q: %w", roomID, err) + } + + return tx.Commit() +} diff --git a/internal/store/sql_store_test.go b/internal/store/sql_store_test.go index 80ff667..bc79d79 100644 --- a/internal/store/sql_store_test.go +++ b/internal/store/sql_store_test.go @@ -296,6 +296,90 @@ func TestSQLiteStoreContextWrappersAndRoomMemberUpdates(t *testing.T) { } } +func TestSQLiteStoreSoftRemovesRoomsAndAgents(t *testing.T) { + t.Parallel() + + store, err := NewSQLiteStore(filepath.Join(t.TempDir(), "moltnet.db")) + if err != nil { + t.Fatalf("NewSQLiteStore() error = %v", err) + } + defer store.Close() + + room := protocol.Room{ + ID: "research", + NetworkID: "local", + FQID: protocol.RoomFQID("local", "research"), + Name: "Research", + Members: []string{"alpha", "beta"}, + CreatedAt: time.Now().UTC(), + } + if err := store.CreateRoom(room); err != nil { + t.Fatalf("CreateRoom() error = %v", err) + } + if _, err := store.RegisterAgentContext(t.Context(), protocol.AgentRegistration{ + NetworkID: "local", + AgentID: "alpha", + ActorUID: "actor_1", + ActorURI: protocol.AgentFQID("local", "alpha"), + CredentialKey: "token:alpha", + CreatedAt: time.Now().UTC(), + UpdatedAt: time.Now().UTC(), + }); err != nil { + t.Fatalf("RegisterAgentContext() error = %v", err) + } + if err := store.AppendMessage(protocol.Message{ + ID: "msg_keep", + NetworkID: "local", + Target: protocol.Target{Kind: protocol.TargetKindRoom, RoomID: "research"}, + From: protocol.Actor{Type: "agent", ID: "alpha"}, + Parts: []protocol.Part{{Kind: protocol.PartKindText, Text: "keep"}}, + CreatedAt: time.Now().UTC(), + }); err != nil { + t.Fatalf("AppendMessage() error = %v", err) + } + + if err := store.RemoveAgentContext(t.Context(), "alpha"); err != nil { + t.Fatalf("RemoveAgentContext() error = %v", err) + } + if err := store.RemoveRegisteredAgentContext(t.Context(), "alpha"); err != nil { + t.Fatalf("RemoveRegisteredAgentContext() error = %v", err) + } + agents, err := store.ListAgentsContext(t.Context()) + if err != nil { + t.Fatalf("ListAgentsContext() error = %v", err) + } + if len(agents) != 1 || agents[0].ID != "beta" { + t.Fatalf("unexpected agents after removal %#v", agents) + } + if _, ok, err := store.GetRegisteredAgentContext(t.Context(), "alpha"); err != nil || ok { + t.Fatalf("expected registration removed ok=%v err=%v", ok, err) + } + + if err := store.RemoveRoomContext(t.Context(), "research"); err != nil { + t.Fatalf("RemoveRoomContext() error = %v", err) + } + if _, ok, err := store.GetRoomContext(t.Context(), "research"); err != nil || ok { + t.Fatalf("expected removed room hidden ok=%v err=%v", ok, err) + } + rooms, err := store.ListRoomsContext(t.Context()) + if err != nil { + t.Fatalf("ListRoomsContext() error = %v", err) + } + if len(rooms) != 0 { + t.Fatalf("expected no active rooms, got %#v", rooms) + } + page, err := store.ListRoomMessagesContext(t.Context(), "research", protocol.PageRequest{Limit: 10}) + if err != nil { + t.Fatalf("ListRoomMessagesContext() error = %v", err) + } + if len(page.Messages) != 1 || page.Messages[0].ID != "msg_keep" { + t.Fatalf("expected soft removal to preserve messages, got %#v", page) + } + if err := store.RemoveRoomContext(t.Context(), "research"); !errors.Is(err, ErrRoomNotFound) { + t.Fatalf("expected ErrRoomNotFound for already removed room, got %v", err) + } +} + func TestSQLiteStoreAgentQueries(t *testing.T) { t.Parallel() diff --git a/internal/transport/attach.go b/internal/transport/attach.go index 2cbab59..45afd36 100644 --- a/internal/transport/attach.go +++ b/internal/transport/attach.go @@ -118,7 +118,11 @@ func handleAttachment( return } service.AgentConnected(request.Context(), agent) - defer service.AgentDisconnected(context.Background(), agent) + disconnectReason := "attachment_closed" + var disconnectErr error + defer func() { + service.AgentDisconnected(context.Background(), agent, disconnectReason, disconnectErr) + }() ctx, cancel := context.WithCancel(request.Context()) defer cancel() @@ -138,8 +142,11 @@ func handleAttachment( for { select { case <-ctx.Done(): + disconnectReason = "request_context_done" + disconnectErr = ctx.Err() return case err := <-readErrCh: + disconnectReason, disconnectErr = attachmentDisconnectCause(err) if err != nil && !websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway) { observability.Logger(request.Context(), "transport.attach", "agent_id", agent.ID). Warn("attachment websocket read error", "error", err) @@ -151,10 +158,19 @@ func handleAttachment( Op: protocol.AttachmentOpPing, Version: protocol.AttachmentProtocolV1, }); err != nil { + disconnectReason = "heartbeat_write_failed" + disconnectErr = err + publishPendingWakeFailures(service, agent, session, err) return } case event, ok := <-stream: if !ok { + disconnectReason = "event_stream_closed" + return + } + if attachmentRemovedEvent(event, service.Network().ID, agent.ID) { + disconnectReason = "agent_removed" + disconnectErr = writeAttachmentError(writer, "agent was removed from the network") return } if filter != nil && !filter(event) { @@ -172,6 +188,8 @@ func handleAttachment( Cursor: event.ID, Event: &event, }); err != nil { + disconnectReason = "event_write_failed" + disconnectErr = err publishPendingWakeFailures(service, agent, session, err) return } @@ -179,6 +197,27 @@ func handleAttachment( } } +func attachmentDisconnectCause(err error) (string, error) { + if err == nil { + return "client_closed", nil + } + var clientErr attachmentClientError + switch { + case errors.As(err, &clientErr): + return "client_error", err + case websocket.IsCloseError(err, websocket.CloseNormalClosure): + return "client_closed", nil + case websocket.IsCloseError(err, websocket.CloseGoingAway): + return "client_going_away", nil + case errors.Is(err, context.Canceled): + return "request_context_done", nil + case errors.Is(err, context.DeadlineExceeded): + return "read_timeout", err + default: + return "read_error", err + } +} + func publishPendingWakeFailures(service Service, agent protocol.Actor, session *attachmentSession, err error) { for _, event := range session.PendingWakes() { service.AgentWakeFailed(context.Background(), agent, event, err) @@ -284,6 +323,12 @@ func attachmentWakeEvent(event protocol.Event, networkID string, agent protocol. return false } +func attachmentRemovedEvent(event protocol.Event, networkID string, agentID string) bool { + return event.Type == protocol.EventTypeAgentRemoved && + event.Agent != nil && + protocol.ActorMatches(networkID, agentID, event.Agent.AgentID) +} + func participantsIncludeAttachedAgent(participants []string, networkID string, agentID string) bool { for _, participantID := range participants { if protocol.ActorMatches(networkID, agentID, participantID) { @@ -343,6 +388,8 @@ func consumeAttachmentFrames( }); err != nil { return err } + case protocol.AttachmentOpError: + return attachmentClientError(strings.TrimSpace(frame.Error)) default: if err := writeAttachmentError(writer, fmt.Sprintf("unexpected frame op %q", frame.Op)); err != nil { return err @@ -401,6 +448,16 @@ func invalidAttachmentFrameError(message string, err error) error { } } +type attachmentClientError string + +func (e attachmentClientError) Error() string { + message := strings.TrimSpace(string(e)) + if message == "" { + return "attachment client error" + } + return "attachment client error: " + message +} + func attachmentFrameErrorMessage(err error) (string, bool) { var frameErr *attachmentFrameError if !errors.As(err, &frameErr) || strings.TrimSpace(frameErr.message) == "" { diff --git a/internal/transport/attach_session_test.go b/internal/transport/attach_session_test.go index bba73ea..0e64d1e 100644 --- a/internal/transport/attach_session_test.go +++ b/internal/transport/attach_session_test.go @@ -209,6 +209,36 @@ func TestConsumeAttachmentFramesHandlesAckPingAndUnexpectedOp(t *testing.T) { } } +func TestConsumeAttachmentFramesAcceptsClientErrorFrame(t *testing.T) { + t.Parallel() + + clientConn, serverConn := newAttachmentFrameTestPair(t) + session := newAttachmentSession("") + writer := &attachmentWriter{connection: serverConn} + + errCh := make(chan error, 1) + go func() { + errCh <- consumeAttachmentFrames(context.Background(), serverConn, writer, session, time.Second, nil) + }() + + if err := clientConn.WriteJSON(protocol.AttachmentFrame{ + Op: protocol.AttachmentOpError, + Version: protocol.AttachmentProtocolV1, + Error: "runtime command failed", + }); err != nil { + t.Fatalf("write client error: %v", err) + } + + select { + case err := <-errCh: + if err == nil || !strings.Contains(err.Error(), "runtime command failed") { + t.Fatalf("expected client error, got %v", err) + } + case <-time.After(time.Second): + t.Fatal("timed out waiting for client error") + } +} + func TestConsumeAttachmentFramesAllowsLegacyAckAndPongVersionOmission(t *testing.T) { t.Parallel() diff --git a/internal/transport/attach_test.go b/internal/transport/attach_test.go index 14afff8..47746ff 100644 --- a/internal/transport/attach_test.go +++ b/internal/transport/attach_test.go @@ -110,6 +110,112 @@ func TestAttachmentEndpoint(t *testing.T) { }) } +func TestAttachmentEndpointRecordsDisconnectReason(t *testing.T) { + t.Parallel() + + service := &fakeService{ + network: protocol.Network{ID: "local"}, + stream: make(chan protocol.Event), + } + + server := httptest.NewServer(NewHTTPHandler(service, nil)) + defer server.Close() + + endpoint := "ws" + server.URL[len("http"):] + "/v1/attach" + connection := dialAndIdentifyAttachment(t, endpoint, "local", "researcher") + deadline := time.Now().Add(time.Second) + if err := connection.WriteControl( + websocket.CloseMessage, + websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""), + deadline, + ); err != nil { + t.Fatalf("write close control: %v", err) + } + _ = connection.Close() + + waitForCondition(t, func() bool { + service.mu.Lock() + defer service.mu.Unlock() + return len(service.disconnectReasons) == 1 && + service.disconnectReasons[0] == "client_closed" && + service.disconnectErrors[0] == "" + }) +} + +func TestAttachmentEndpointRecordsClientReportedError(t *testing.T) { + t.Parallel() + + service := &fakeService{ + network: protocol.Network{ID: "local"}, + stream: make(chan protocol.Event), + } + + server := httptest.NewServer(NewHTTPHandler(service, nil)) + defer server.Close() + + endpoint := "ws" + server.URL[len("http"):] + "/v1/attach" + connection := dialAndIdentifyAttachment(t, endpoint, "local", "researcher") + defer connection.Close() + + if err := connection.WriteJSON(protocol.AttachmentFrame{ + Op: protocol.AttachmentOpError, + Version: protocol.AttachmentProtocolV1, + Error: "runtime session already in use", + }); err != nil { + t.Fatalf("write client error: %v", err) + } + + waitForCondition(t, func() bool { + service.mu.Lock() + defer service.mu.Unlock() + return len(service.disconnectReasons) == 1 && + service.disconnectReasons[0] == "client_error" && + strings.Contains(service.disconnectErrors[0], "runtime session already in use") + }) +} + +func TestAttachmentEndpointClosesRemovedAgent(t *testing.T) { + t.Parallel() + + stream := make(chan protocol.Event, 1) + service := &fakeService{ + network: protocol.Network{ID: "local"}, + stream: stream, + } + + server := httptest.NewServer(NewHTTPHandler(service, nil)) + defer server.Close() + + endpoint := "ws" + server.URL[len("http"):] + "/v1/attach" + connection := dialAndIdentifyAttachment(t, endpoint, "local", "researcher") + defer connection.Close() + + stream <- protocol.Event{ + ID: "evt_removed", + Type: protocol.EventTypeAgentRemoved, + NetworkID: "local", + Agent: &protocol.AgentEvent{ + AgentID: "researcher", + NetworkID: "local", + }, + } + + var errorFrame protocol.AttachmentFrame + if err := connection.ReadJSON(&errorFrame); err != nil { + t.Fatalf("read removal error frame: %v", err) + } + if errorFrame.Op != protocol.AttachmentOpError || + !strings.Contains(errorFrame.Error, "removed") { + t.Fatalf("unexpected removal error frame %#v", errorFrame) + } + waitForCondition(t, func() bool { + service.mu.Lock() + defer service.mu.Unlock() + return len(service.disconnectReasons) == 1 && + service.disconnectReasons[0] == "agent_removed" + }) +} + func TestAttachmentEndpointPublishesWakeFailedWhenTargetedEventIsNotAcked(t *testing.T) { t.Parallel() diff --git a/internal/transport/http.go b/internal/transport/http.go index a94bce2..0ef9341 100644 --- a/internal/transport/http.go +++ b/internal/transport/http.go @@ -24,10 +24,12 @@ type Service interface { PairingAgentsContext(ctx context.Context, pairingID string, page protocol.PageRequest) (protocol.AgentPage, error) ListRoomsContext(ctx context.Context, page protocol.PageRequest) (protocol.RoomPage, error) CreateRoomContext(ctx context.Context, request protocol.CreateRoomRequest) (protocol.Room, error) + RemoveRoomContext(ctx context.Context, roomID string) (protocol.RemoveResult, error) UpdateRoomMembers(ctx context.Context, roomID string, request protocol.UpdateRoomMembersRequest) (protocol.Room, error) RegisterAgentContext(ctx context.Context, request protocol.RegisterAgentRequest) (protocol.AgentRegistration, error) + RemoveAgentContext(ctx context.Context, agentID string) (protocol.RemoveResult, error) AgentConnected(ctx context.Context, agent protocol.Actor) - AgentDisconnected(ctx context.Context, agent protocol.Actor) + AgentDisconnected(ctx context.Context, agent protocol.Actor, reason string, err error) AgentWakeDelivered(ctx context.Context, agent protocol.Actor, event protocol.Event) AgentWakeFailed(ctx context.Context, agent protocol.Actor, event protocol.Event, err error) ListRoomMessagesContext(ctx context.Context, roomID string, page protocol.PageRequest) (protocol.MessagePage, error) @@ -128,6 +130,16 @@ func NewHTTPHandler(service Service, policy *authn.Policy) http.Handler { mux.HandleFunc("POST /v1/agents/register", handleRegisterAgent(service, policy)) + mux.HandleFunc("DELETE /v1/agents/{agentID}", authorizedWithVerifier(policy, service, authn.ScopeAdmin, func(response http.ResponseWriter, request *http.Request) { + result, err := service.RemoveAgentContext(request.Context(), request.PathValue("agentID")) + if err != nil { + writeError(response, statusForError(err), err) + return + } + + writeJSON(response, http.StatusOK, result) + })) + mux.HandleFunc("GET /v1/pairings", authorizedWithVerifier(policy, service, authn.ScopeObserve, func(response http.ResponseWriter, request *http.Request) { pageRequest, err := readPageRequest(request) if err != nil { @@ -195,6 +207,16 @@ func NewHTTPHandler(service Service, policy *authn.Policy) http.Handler { writeJSON(response, http.StatusCreated, room) })) + mux.HandleFunc("DELETE /v1/rooms/{roomID}", authorizedWithVerifier(policy, service, authn.ScopeAdmin, func(response http.ResponseWriter, request *http.Request) { + result, err := service.RemoveRoomContext(request.Context(), request.PathValue("roomID")) + if err != nil { + writeError(response, statusForError(err), err) + return + } + + writeJSON(response, http.StatusOK, result) + })) + mux.HandleFunc("PATCH /v1/rooms/{roomID}/members", authorizedWithVerifier(policy, service, authn.ScopeAdmin, func(response http.ResponseWriter, request *http.Request) { var payload protocol.UpdateRoomMembersRequest if err := decodeJSON(response, request, &payload); err != nil { diff --git a/internal/transport/http_auth_test.go b/internal/transport/http_auth_test.go index 1b8e12c..65633b0 100644 --- a/internal/transport/http_auth_test.go +++ b/internal/transport/http_auth_test.go @@ -188,6 +188,38 @@ func TestHTTPHandlerAuthScopes(t *testing.T) { t.Fatalf("expected admin token to create room, got %d", response.Code) } + request = httptest.NewRequest(http.MethodDelete, "/v1/rooms/research", nil) + request.Header.Set("Authorization", "Bearer write-secret") + response = httptest.NewRecorder() + handler.ServeHTTP(response, request) + if response.Code != http.StatusForbidden { + t.Fatalf("expected write token to be forbidden for room removal, got %d", response.Code) + } + + request = httptest.NewRequest(http.MethodDelete, "/v1/rooms/research", nil) + request.Header.Set("Authorization", "Bearer admin-secret") + response = httptest.NewRecorder() + handler.ServeHTTP(response, request) + if response.Code != http.StatusOK { + t.Fatalf("expected admin token to remove room, got %d", response.Code) + } + + request = httptest.NewRequest(http.MethodDelete, "/v1/agents/writer", nil) + request.Header.Set("Authorization", "Bearer write-secret") + response = httptest.NewRecorder() + handler.ServeHTTP(response, request) + if response.Code != http.StatusForbidden { + t.Fatalf("expected write token to be forbidden for agent removal, got %d", response.Code) + } + + request = httptest.NewRequest(http.MethodDelete, "/v1/agents/writer", nil) + request.Header.Set("Authorization", "Bearer admin-secret") + response = httptest.NewRecorder() + handler.ServeHTTP(response, request) + if response.Code != http.StatusOK { + t.Fatalf("expected admin token to remove agent, got %d", response.Code) + } + request = httptest.NewRequest(http.MethodGet, "/v1/rooms", nil) request.Header.Set("Authorization", "Bearer pair-secret") response = httptest.NewRecorder() diff --git a/internal/transport/http_test.go b/internal/transport/http_test.go index 7fee184..8b41bca 100644 --- a/internal/transport/http_test.go +++ b/internal/transport/http_test.go @@ -48,8 +48,12 @@ type fakeService struct { artifactPage protocol.ArtifactPage createdRoom protocol.CreateRoomRequest registeredAgent protocol.RegisterAgentRequest + removedAgentID string + removedRoomID string connectedAgents []protocol.Actor disconnectedAgents []protocol.Actor + disconnectReasons []string + disconnectErrors []string deliveredWakes []protocol.Event failedWakes []protocol.Event updatedRoom protocol.UpdateRoomMembersRequest @@ -127,10 +131,16 @@ func (f *fakeService) AgentConnected(ctx context.Context, agent protocol.Actor) defer f.mu.Unlock() f.connectedAgents = append(f.connectedAgents, agent) } -func (f *fakeService) AgentDisconnected(ctx context.Context, agent protocol.Actor) { +func (f *fakeService) AgentDisconnected(ctx context.Context, agent protocol.Actor, reason string, err error) { f.mu.Lock() defer f.mu.Unlock() f.disconnectedAgents = append(f.disconnectedAgents, agent) + f.disconnectReasons = append(f.disconnectReasons, reason) + if err != nil { + f.disconnectErrors = append(f.disconnectErrors, err.Error()) + return + } + f.disconnectErrors = append(f.disconnectErrors, "") } func (f *fakeService) AgentWakeDelivered(ctx context.Context, agent protocol.Actor, event protocol.Event) { f.mu.Lock() @@ -216,6 +226,14 @@ func (f *fakeService) RegisterAgentContext(ctx context.Context, request protocol DisplayName: request.Name, }, nil } +func (f *fakeService) RemoveAgentContext(ctx context.Context, agentID string) (protocol.RemoveResult, error) { + f.removedAgentID = agentID + return protocol.RemoveResult{Removed: true, Kind: "agent", ID: agentID, Mode: "soft"}, nil +} +func (f *fakeService) RemoveRoomContext(ctx context.Context, roomID string) (protocol.RemoveResult, error) { + f.removedRoomID = roomID + return protocol.RemoveResult{Removed: true, Kind: "room", ID: roomID, Mode: "soft"}, nil +} func (f *fakeService) ListRoomMessagesContext(ctx context.Context, roomID string, page protocol.PageRequest) (protocol.MessagePage, error) { f.roomID = roomID f.roomBefore = page.Before diff --git a/internal/transport/sse.go b/internal/transport/sse.go index 4019b97..599ed11 100644 --- a/internal/transport/sse.go +++ b/internal/transport/sse.go @@ -193,6 +193,10 @@ func publicOpenEvent(event protocol.Event) bool { return event.Thread != nil && strings.TrimSpace(event.Thread.RoomID) != "" case protocol.EventTypeAgentConnected, protocol.EventTypeAgentDisconnected: return event.Agent != nil + case protocol.EventTypeRoomRemoved: + return event.Room != nil + case protocol.EventTypeAgentRemoved: + return event.Agent != nil case protocol.EventTypeReplayGap: return true default: diff --git a/internal/transport/sse_test.go b/internal/transport/sse_test.go index 411a71d..b73aa23 100644 --- a/internal/transport/sse_test.go +++ b/internal/transport/sse_test.go @@ -317,6 +317,29 @@ func TestEventStreamSkipsUnsafeEventFields(t *testing.T) { }) } +func TestPublicOpenEventsIncludeCleanupTopology(t *testing.T) { + t.Parallel() + + events := []protocol.Event{ + { + Type: protocol.EventTypeRoomRemoved, + Room: &protocol.Room{ID: "stale-room"}, + }, + { + Type: protocol.EventTypeAgentRemoved, + Agent: &protocol.AgentEvent{ + AgentID: "stale-agent", + }, + }, + } + + for _, event := range events { + if !publicOpenEvent(event) { + t.Fatalf("expected cleanup event to be public %#v", event) + } + } +} + func TestStreamIdentityPrefersTokenThenRemoteAddr(t *testing.T) { t.Parallel() diff --git a/pkg/protocol/events.go b/pkg/protocol/events.go index eade6b8..8f38ddb 100644 --- a/pkg/protocol/events.go +++ b/pkg/protocol/events.go @@ -3,12 +3,14 @@ package protocol const ( EventTypeMessageCreated = "message.created" EventTypeRoomCreated = "room.created" + EventTypeRoomRemoved = "room.removed" EventTypeRoomMembersUpdated = "room.members.updated" EventTypeThreadCreated = "thread.created" EventTypeDMCreated = "dm.created" EventTypePairingUpdated = "pairing.updated" EventTypeAgentConnected = "agent.connected" EventTypeAgentDisconnected = "agent.disconnected" + EventTypeAgentRemoved = "agent.removed" EventTypeAgentWakeDelivered = "agent.wake.delivered" EventTypeAgentWakeFailed = "agent.wake.failed" EventTypeReplayGap = "stream.replay_gap" diff --git a/pkg/protocol/network_test.go b/pkg/protocol/network_test.go index 6b6f38b..88689b2 100644 --- a/pkg/protocol/network_test.go +++ b/pkg/protocol/network_test.go @@ -22,6 +22,7 @@ func TestNetworkCompatibilityMetadataJSON(t *testing.T) { Capabilities: NetworkCapabilities{ EventStream: "sse", AttachmentProtocol: "websocket", + DebugEvents: true, HumanIngress: true, DirectMessages: false, MessagePagination: "cursor", @@ -47,6 +48,7 @@ func TestNetworkCompatibilityMetadataJSON(t *testing.T) { `"pair":["moltnet.pair.v1"]`, `"docs_url":"https://moltnet.dev/docs/guides/operating-moltnet/"`, `"direct_messages":false`, + `"debug_events":true`, `"attachment_protocol":"websocket"`, } { if !strings.Contains(text, want) { diff --git a/pkg/protocol/types.go b/pkg/protocol/types.go index 36bac83..3b7e713 100644 --- a/pkg/protocol/types.go +++ b/pkg/protocol/types.go @@ -29,6 +29,7 @@ type NetworkConsole struct { type NetworkCapabilities struct { EventStream string `json:"event_stream,omitempty"` AttachmentProtocol string `json:"attachment_protocol,omitempty"` + DebugEvents bool `json:"debug_events,omitempty"` HumanIngress bool `json:"human_ingress"` DirectMessages bool `json:"direct_messages"` MessagePagination string `json:"message_pagination,omitempty"` @@ -157,6 +158,13 @@ type UpdateRoomMembersRequest struct { Remove []string `json:"remove,omitempty"` } +type RemoveResult struct { + Removed bool `json:"removed"` + Kind string `json:"kind"` + ID string `json:"id"` + Mode string `json:"mode"` +} + type SendMessageRequest struct { ID string `json:"id,omitempty"` Origin MessageOrigin `json:"origin,omitempty"` diff --git a/web/dist/assets/index-CC6DxEm4.js b/web/dist/assets/index-8knXM2yh.js similarity index 74% rename from web/dist/assets/index-CC6DxEm4.js rename to web/dist/assets/index-8knXM2yh.js index 31f5fe4..91ef208 100644 --- a/web/dist/assets/index-CC6DxEm4.js +++ b/web/dist/assets/index-8knXM2yh.js @@ -1,4 +1,4 @@ -function rS(t,e){for(var r=0;rs[l]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))s(l);new MutationObserver(l=>{for(const u of l)if(u.type==="childList")for(const c of u.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&s(c)}).observe(document,{childList:!0,subtree:!0});function r(l){const u={};return l.integrity&&(u.integrity=l.integrity),l.referrerPolicy&&(u.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?u.credentials="include":l.crossOrigin==="anonymous"?u.credentials="omit":u.credentials="same-origin",u}function s(l){if(l.ep)return;l.ep=!0;const u=r(l);fetch(l.href,u)}})();function ky(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Sc={exports:{}},Fs={},wc={exports:{}},ke={};/** +function iS(t,e){for(var r=0;rs[l]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))s(l);new MutationObserver(l=>{for(const u of l)if(u.type==="childList")for(const c of u.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&s(c)}).observe(document,{childList:!0,subtree:!0});function r(l){const u={};return l.integrity&&(u.integrity=l.integrity),l.referrerPolicy&&(u.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?u.credentials="include":l.crossOrigin==="anonymous"?u.credentials="omit":u.credentials="same-origin",u}function s(l){if(l.ep)return;l.ep=!0;const u=r(l);fetch(l.href,u)}})();function Ey(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Sc={exports:{}},Fs={},wc={exports:{}},ke={};/** * @license React * react.production.min.js * @@ -6,7 +6,7 @@ function rS(t,e){for(var r=0;r>>1,U=Z[P];if(0>>1;Pl(we,Q))Cel(Me,we)?(Z[P]=Me,Z[Ce]=Q,P=Ce):(Z[P]=we,Z[ve]=Q,P=ve);else if(Cel(Me,Q))Z[P]=Me,Z[Ce]=Q,P=Ce;else break e}}return W}function l(Z,W){var Q=Z.sortIndex-W.sortIndex;return Q!==0?Q:Z.id-W.id}if(typeof performance=="object"&&typeof performance.now=="function"){var u=performance;t.unstable_now=function(){return u.now()}}else{var c=Date,f=c.now();t.unstable_now=function(){return c.now()-f}}var h=[],g=[],m=1,v=null,y=3,S=!1,_=!1,w=!1,C=typeof setTimeout=="function"?setTimeout:null,T=typeof clearTimeout=="function"?clearTimeout:null,N=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function M(Z){for(var W=r(g);W!==null;){if(W.callback===null)s(g);else if(W.startTime<=Z)s(g),W.sortIndex=W.expirationTime,e(h,W);else break;W=r(g)}}function L(Z){if(w=!1,M(Z),!_)if(r(h)!==null)_=!0,ye(j);else{var W=r(g);W!==null&&_e(L,W.startTime-Z)}}function j(Z,W){_=!1,w&&(w=!1,T(F),F=-1),S=!0;var Q=y;try{for(M(W),v=r(h);v!==null&&(!(v.expirationTime>W)||Z&&!te());){var P=v.callback;if(typeof P=="function"){v.callback=null,y=v.priorityLevel;var U=P(v.expirationTime<=W);W=t.unstable_now(),typeof U=="function"?v.callback=U:v===r(h)&&s(h),M(W)}else s(h);v=r(h)}if(v!==null)var he=!0;else{var ve=r(g);ve!==null&&_e(L,ve.startTime-W),he=!1}return he}finally{v=null,y=Q,S=!1}}var D=!1,$=null,F=-1,z=5,J=-1;function te(){return!(t.unstable_now()-JZ||125P?(Z.sortIndex=Q,e(g,Z),r(h)===null&&Z===r(g)&&(w?(T(F),F=-1):w=!0,_e(L,Q-P))):(Z.sortIndex=U,e(h,Z),_||S||(_=!0,ye(j))),Z},t.unstable_shouldYield=te,t.unstable_wrapCallback=function(Z){var W=y;return function(){var Q=y;y=W;try{return Z.apply(this,arguments)}finally{y=Q}}}})(Ec)),Ec}var Ng;function aS(){return Ng||(Ng=1,kc.exports=uS()),kc.exports}/** + */var Eg;function aS(){return Eg||(Eg=1,(function(t){function e(Z,W){var Q=Z.length;Z.push(W);e:for(;0>>1,U=Z[P];if(0>>1;Pl(we,Q))Cel(Me,we)?(Z[P]=Me,Z[Ce]=Q,P=Ce):(Z[P]=we,Z[ve]=Q,P=ve);else if(Cel(Me,Q))Z[P]=Me,Z[Ce]=Q,P=Ce;else break e}}return W}function l(Z,W){var Q=Z.sortIndex-W.sortIndex;return Q!==0?Q:Z.id-W.id}if(typeof performance=="object"&&typeof performance.now=="function"){var u=performance;t.unstable_now=function(){return u.now()}}else{var c=Date,f=c.now();t.unstable_now=function(){return c.now()-f}}var h=[],g=[],m=1,v=null,y=3,_=!1,S=!1,w=!1,C=typeof setTimeout=="function"?setTimeout:null,T=typeof clearTimeout=="function"?clearTimeout:null,N=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function M(Z){for(var W=r(g);W!==null;){if(W.callback===null)s(g);else if(W.startTime<=Z)s(g),W.sortIndex=W.expirationTime,e(h,W);else break;W=r(g)}}function L(Z){if(w=!1,M(Z),!S)if(r(h)!==null)S=!0,ye(j);else{var W=r(g);W!==null&&_e(L,W.startTime-Z)}}function j(Z,W){S=!1,w&&(w=!1,T(F),F=-1),_=!0;var Q=y;try{for(M(W),v=r(h);v!==null&&(!(v.expirationTime>W)||Z&&!te());){var P=v.callback;if(typeof P=="function"){v.callback=null,y=v.priorityLevel;var U=P(v.expirationTime<=W);W=t.unstable_now(),typeof U=="function"?v.callback=U:v===r(h)&&s(h),M(W)}else s(h);v=r(h)}if(v!==null)var he=!0;else{var ve=r(g);ve!==null&&_e(L,ve.startTime-W),he=!1}return he}finally{v=null,y=Q,_=!1}}var D=!1,$=null,F=-1,z=5,J=-1;function te(){return!(t.unstable_now()-JZ||125P?(Z.sortIndex=Q,e(g,Z),r(h)===null&&Z===r(g)&&(w?(T(F),F=-1):w=!0,_e(L,Q-P))):(Z.sortIndex=U,e(h,Z),S||_||(S=!0,ye(j))),Z},t.unstable_shouldYield=te,t.unstable_wrapCallback=function(Z){var W=y;return function(){var Q=y;y=W;try{return Z.apply(this,arguments)}finally{y=Q}}}})(Ec)),Ec}var Ng;function cS(){return Ng||(Ng=1,kc.exports=aS()),kc.exports}/** * @license React * react-dom.production.min.js * @@ -30,14 +30,14 @@ function rS(t,e){for(var r=0;r"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),h=Object.prototype.hasOwnProperty,g=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,m={},v={};function y(n){return h.call(v,n)?!0:h.call(m,n)?!1:g.test(n)?v[n]=!0:(m[n]=!0,!1)}function S(n,i,o,a){if(o!==null&&o.type===0)return!1;switch(typeof i){case"function":case"symbol":return!0;case"boolean":return a?!1:o!==null?!o.acceptsBooleans:(n=n.toLowerCase().slice(0,5),n!=="data-"&&n!=="aria-");default:return!1}}function _(n,i,o,a){if(i===null||typeof i>"u"||S(n,i,o,a))return!0;if(a)return!1;if(o!==null)switch(o.type){case 3:return!i;case 4:return i===!1;case 5:return isNaN(i);case 6:return isNaN(i)||1>i}return!1}function w(n,i,o,a,d,p,x){this.acceptsBooleans=i===2||i===3||i===4,this.attributeName=a,this.attributeNamespace=d,this.mustUseProperty=o,this.propertyName=n,this.type=i,this.sanitizeURL=p,this.removeEmptyString=x}var C={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(n){C[n]=new w(n,0,!1,n,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(n){var i=n[0];C[i]=new w(i,1,!1,n[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(n){C[n]=new w(n,2,!1,n.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(n){C[n]=new w(n,2,!1,n,null,!1,!1)}),"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(n){C[n]=new w(n,3,!1,n.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(n){C[n]=new w(n,3,!0,n,null,!1,!1)}),["capture","download"].forEach(function(n){C[n]=new w(n,4,!1,n,null,!1,!1)}),["cols","rows","size","span"].forEach(function(n){C[n]=new w(n,6,!1,n,null,!1,!1)}),["rowSpan","start"].forEach(function(n){C[n]=new w(n,5,!1,n.toLowerCase(),null,!1,!1)});var T=/[\-:]([a-z])/g;function N(n){return n[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(n){var i=n.replace(T,N);C[i]=new w(i,1,!1,n,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(n){var i=n.replace(T,N);C[i]=new w(i,1,!1,n,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(n){var i=n.replace(T,N);C[i]=new w(i,1,!1,n,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(n){C[n]=new w(n,1,!1,n.toLowerCase(),null,!1,!1)}),C.xlinkHref=new w("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(n){C[n]=new w(n,1,!1,n.toLowerCase(),null,!0,!0)});function M(n,i,o,a){var d=C.hasOwnProperty(i)?C[i]:null;(d!==null?d.type!==0:a||!(2"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),h=Object.prototype.hasOwnProperty,g=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,m={},v={};function y(n){return h.call(v,n)?!0:h.call(m,n)?!1:g.test(n)?v[n]=!0:(m[n]=!0,!1)}function _(n,i,o,a){if(o!==null&&o.type===0)return!1;switch(typeof i){case"function":case"symbol":return!0;case"boolean":return a?!1:o!==null?!o.acceptsBooleans:(n=n.toLowerCase().slice(0,5),n!=="data-"&&n!=="aria-");default:return!1}}function S(n,i,o,a){if(i===null||typeof i>"u"||_(n,i,o,a))return!0;if(a)return!1;if(o!==null)switch(o.type){case 3:return!i;case 4:return i===!1;case 5:return isNaN(i);case 6:return isNaN(i)||1>i}return!1}function w(n,i,o,a,d,p,x){this.acceptsBooleans=i===2||i===3||i===4,this.attributeName=a,this.attributeNamespace=d,this.mustUseProperty=o,this.propertyName=n,this.type=i,this.sanitizeURL=p,this.removeEmptyString=x}var C={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(n){C[n]=new w(n,0,!1,n,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(n){var i=n[0];C[i]=new w(i,1,!1,n[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(n){C[n]=new w(n,2,!1,n.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(n){C[n]=new w(n,2,!1,n,null,!1,!1)}),"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(n){C[n]=new w(n,3,!1,n.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(n){C[n]=new w(n,3,!0,n,null,!1,!1)}),["capture","download"].forEach(function(n){C[n]=new w(n,4,!1,n,null,!1,!1)}),["cols","rows","size","span"].forEach(function(n){C[n]=new w(n,6,!1,n,null,!1,!1)}),["rowSpan","start"].forEach(function(n){C[n]=new w(n,5,!1,n.toLowerCase(),null,!1,!1)});var T=/[\-:]([a-z])/g;function N(n){return n[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(n){var i=n.replace(T,N);C[i]=new w(i,1,!1,n,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(n){var i=n.replace(T,N);C[i]=new w(i,1,!1,n,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(n){var i=n.replace(T,N);C[i]=new w(i,1,!1,n,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(n){C[n]=new w(n,1,!1,n.toLowerCase(),null,!1,!1)}),C.xlinkHref=new w("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(n){C[n]=new w(n,1,!1,n.toLowerCase(),null,!0,!0)});function M(n,i,o,a){var d=C.hasOwnProperty(i)?C[i]:null;(d!==null?d.type!==0:a||!(2E||d[x]!==p[E]){var O=` -`+d[x].replace(" at new "," at ");return n.displayName&&O.includes("")&&(O=O.replace("",n.displayName)),O}while(1<=x&&0<=E);break}}}finally{he=!1,Error.prepareStackTrace=o}return(n=n?n.displayName||n.name:"")?U(n):""}function we(n){switch(n.tag){case 5:return U(n.type);case 16:return U("Lazy");case 13:return U("Suspense");case 19:return U("SuspenseList");case 0:case 2:case 15:return n=ve(n.type,!1),n;case 11:return n=ve(n.type.render,!1),n;case 1:return n=ve(n.type,!0),n;default:return""}}function Ce(n){if(n==null)return null;if(typeof n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case $:return"Fragment";case D:return"Portal";case z:return"Profiler";case F:return"StrictMode";case X:return"Suspense";case ae:return"SuspenseList"}if(typeof n=="object")switch(n.$$typeof){case te:return(n.displayName||"Context")+".Consumer";case J:return(n._context.displayName||"Context")+".Provider";case ne:var i=n.render;return n=n.displayName,n||(n=i.displayName||i.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case Se:return i=n.displayName||null,i!==null?i:Ce(n.type)||"Memo";case ye:i=n._payload,n=n._init;try{return Ce(n(i))}catch{}}return null}function Me(n){var i=n.type;switch(n.tag){case 24:return"Cache";case 9:return(i.displayName||"Context")+".Consumer";case 10:return(i._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return n=i.render,n=n.displayName||n.name||"",i.displayName||(n!==""?"ForwardRef("+n+")":"ForwardRef");case 7:return"Fragment";case 5:return i;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Ce(i);case 8:return i===F?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof i=="function")return i.displayName||i.name||null;if(typeof i=="string")return i}return null}function Ee(n){switch(typeof n){case"boolean":case"number":case"string":case"undefined":return n;case"object":return n;default:return""}}function Te(n){var i=n.type;return(n=n.nodeName)&&n.toLowerCase()==="input"&&(i==="checkbox"||i==="radio")}function qe(n){var i=Te(n)?"checked":"value",o=Object.getOwnPropertyDescriptor(n.constructor.prototype,i),a=""+n[i];if(!n.hasOwnProperty(i)&&typeof o<"u"&&typeof o.get=="function"&&typeof o.set=="function"){var d=o.get,p=o.set;return Object.defineProperty(n,i,{configurable:!0,get:function(){return d.call(this)},set:function(x){a=""+x,p.call(this,x)}}),Object.defineProperty(n,i,{enumerable:o.enumerable}),{getValue:function(){return a},setValue:function(x){a=""+x},stopTracking:function(){n._valueTracker=null,delete n[i]}}}}function xr(n){n._valueTracker||(n._valueTracker=qe(n))}function Td(n){if(!n)return!1;var i=n._valueTracker;if(!i)return!0;var o=i.getValue(),a="";return n&&(a=Te(n)?n.checked?"true":"false":n.value),n=a,n!==o?(i.setValue(n),!0):!1}function yo(n){if(n=n||(typeof document<"u"?document:void 0),typeof n>"u")return null;try{return n.activeElement||n.body}catch{return n.body}}function Ou(n,i){var o=i.checked;return Q({},i,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:o??n._wrapperState.initialChecked})}function Od(n,i){var o=i.defaultValue==null?"":i.defaultValue,a=i.checked!=null?i.checked:i.defaultChecked;o=Ee(i.value!=null?i.value:o),n._wrapperState={initialChecked:a,initialValue:o,controlled:i.type==="checkbox"||i.type==="radio"?i.checked!=null:i.value!=null}}function Md(n,i){i=i.checked,i!=null&&M(n,"checked",i,!1)}function Mu(n,i){Md(n,i);var o=Ee(i.value),a=i.type;if(o!=null)a==="number"?(o===0&&n.value===""||n.value!=o)&&(n.value=""+o):n.value!==""+o&&(n.value=""+o);else if(a==="submit"||a==="reset"){n.removeAttribute("value");return}i.hasOwnProperty("value")?Pu(n,i.type,o):i.hasOwnProperty("defaultValue")&&Pu(n,i.type,Ee(i.defaultValue)),i.checked==null&&i.defaultChecked!=null&&(n.defaultChecked=!!i.defaultChecked)}function Pd(n,i,o){if(i.hasOwnProperty("value")||i.hasOwnProperty("defaultValue")){var a=i.type;if(!(a!=="submit"&&a!=="reset"||i.value!==void 0&&i.value!==null))return;i=""+n._wrapperState.initialValue,o||i===n.value||(n.value=i),n.defaultValue=i}o=n.name,o!==""&&(n.name=""),n.defaultChecked=!!n._wrapperState.initialChecked,o!==""&&(n.name=o)}function Pu(n,i,o){(i!=="number"||yo(n.ownerDocument)!==n)&&(o==null?n.defaultValue=""+n._wrapperState.initialValue:n.defaultValue!==""+o&&(n.defaultValue=""+o))}var Ji=Array.isArray;function Zr(n,i,o,a){if(n=n.options,i){i={};for(var d=0;d"+i.valueOf().toString()+"",i=vo.firstChild;n.firstChild;)n.removeChild(n.firstChild);for(;i.firstChild;)n.appendChild(i.firstChild)}});function Yi(n,i){if(i){var o=n.firstChild;if(o&&o===n.lastChild&&o.nodeType===3){o.nodeValue=i;return}}n.textContent=i}var Xi={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},lx=["Webkit","ms","Moz","O"];Object.keys(Xi).forEach(function(n){lx.forEach(function(i){i=i+n.charAt(0).toUpperCase()+n.substring(1),Xi[i]=Xi[n]})});function Id(n,i,o){return i==null||typeof i=="boolean"||i===""?"":o||typeof i!="number"||i===0||Xi.hasOwnProperty(n)&&Xi[n]?(""+i).trim():i+"px"}function Ld(n,i){n=n.style;for(var o in i)if(i.hasOwnProperty(o)){var a=o.indexOf("--")===0,d=Id(o,i[o],a);o==="float"&&(o="cssFloat"),a?n.setProperty(o,d):n[o]=d}}var ux=Q({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function Du(n,i){if(i){if(ux[n]&&(i.children!=null||i.dangerouslySetInnerHTML!=null))throw Error(r(137,n));if(i.dangerouslySetInnerHTML!=null){if(i.children!=null)throw Error(r(60));if(typeof i.dangerouslySetInnerHTML!="object"||!("__html"in i.dangerouslySetInnerHTML))throw Error(r(61))}if(i.style!=null&&typeof i.style!="object")throw Error(r(62))}}function ju(n,i){if(n.indexOf("-")===-1)return typeof i.is=="string";switch(n){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Fu=null;function Iu(n){return n=n.target||n.srcElement||window,n.correspondingUseElement&&(n=n.correspondingUseElement),n.nodeType===3?n.parentNode:n}var Lu=null,ei=null,ti=null;function Ad(n){if(n=_s(n)){if(typeof Lu!="function")throw Error(r(280));var i=n.stateNode;i&&(i=Bo(i),Lu(n.stateNode,n.type,i))}}function zd(n){ei?ti?ti.push(n):ti=[n]:ei=n}function $d(){if(ei){var n=ei,i=ti;if(ti=ei=null,Ad(n),i)for(n=0;n>>=0,n===0?32:31-(xx(n)/_x|0)|0}var Co=64,ko=4194304;function ns(n){switch(n&-n){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return n&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return n&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return n}}function Eo(n,i){var o=n.pendingLanes;if(o===0)return 0;var a=0,d=n.suspendedLanes,p=n.pingedLanes,x=o&268435455;if(x!==0){var E=x&~d;E!==0?a=ns(E):(p&=x,p!==0&&(a=ns(p)))}else x=o&~d,x!==0?a=ns(x):p!==0&&(a=ns(p));if(a===0)return 0;if(i!==0&&i!==a&&(i&d)===0&&(d=a&-a,p=i&-i,d>=p||d===16&&(p&4194240)!==0))return i;if((a&4)!==0&&(a|=o&16),i=n.entangledLanes,i!==0)for(n=n.entanglements,i&=a;0o;o++)i.push(n);return i}function rs(n,i,o){n.pendingLanes|=i,i!==536870912&&(n.suspendedLanes=0,n.pingedLanes=0),n=n.eventTimes,i=31-Wt(i),n[i]=o}function kx(n,i){var o=n.pendingLanes&~i;n.pendingLanes=i,n.suspendedLanes=0,n.pingedLanes=0,n.expiredLanes&=i,n.mutableReadLanes&=i,n.entangledLanes&=i,i=n.entanglements;var a=n.eventTimes;for(n=n.expirationTimes;0=fs),ph=" ",gh=!1;function mh(n,i){switch(n){case"keyup":return Xx.indexOf(i.keyCode)!==-1;case"keydown":return i.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function yh(n){return n=n.detail,typeof n=="object"&&"data"in n?n.data:null}var ii=!1;function e_(n,i){switch(n){case"compositionend":return yh(i);case"keypress":return i.which!==32?null:(gh=!0,ph);case"textInput":return n=i.data,n===ph&&gh?null:n;default:return null}}function t_(n,i){if(ii)return n==="compositionend"||!ta&&mh(n,i)?(n=uh(),Po=Gu=Wn=null,ii=!1,n):null;switch(n){case"paste":return null;case"keypress":if(!(i.ctrlKey||i.altKey||i.metaKey)||i.ctrlKey&&i.altKey){if(i.char&&1=i)return{node:o,offset:i-n};n=a}e:{for(;o;){if(o.nextSibling){o=o.nextSibling;break e}o=o.parentNode}o=void 0}o=kh(o)}}function Nh(n,i){return n&&i?n===i?!0:n&&n.nodeType===3?!1:i&&i.nodeType===3?Nh(n,i.parentNode):"contains"in n?n.contains(i):n.compareDocumentPosition?!!(n.compareDocumentPosition(i)&16):!1:!1}function Th(){for(var n=window,i=yo();i instanceof n.HTMLIFrameElement;){try{var o=typeof i.contentWindow.location.href=="string"}catch{o=!1}if(o)n=i.contentWindow;else break;i=yo(n.document)}return i}function ia(n){var i=n&&n.nodeName&&n.nodeName.toLowerCase();return i&&(i==="input"&&(n.type==="text"||n.type==="search"||n.type==="tel"||n.type==="url"||n.type==="password")||i==="textarea"||n.contentEditable==="true")}function c_(n){var i=Th(),o=n.focusedElem,a=n.selectionRange;if(i!==o&&o&&o.ownerDocument&&Nh(o.ownerDocument.documentElement,o)){if(a!==null&&ia(o)){if(i=a.start,n=a.end,n===void 0&&(n=i),"selectionStart"in o)o.selectionStart=i,o.selectionEnd=Math.min(n,o.value.length);else if(n=(i=o.ownerDocument||document)&&i.defaultView||window,n.getSelection){n=n.getSelection();var d=o.textContent.length,p=Math.min(a.start,d);a=a.end===void 0?p:Math.min(a.end,d),!n.extend&&p>a&&(d=a,a=p,p=d),d=Eh(o,p);var x=Eh(o,a);d&&x&&(n.rangeCount!==1||n.anchorNode!==d.node||n.anchorOffset!==d.offset||n.focusNode!==x.node||n.focusOffset!==x.offset)&&(i=i.createRange(),i.setStart(d.node,d.offset),n.removeAllRanges(),p>a?(n.addRange(i),n.extend(x.node,x.offset)):(i.setEnd(x.node,x.offset),n.addRange(i)))}}for(i=[],n=o;n=n.parentNode;)n.nodeType===1&&i.push({element:n,left:n.scrollLeft,top:n.scrollTop});for(typeof o.focus=="function"&&o.focus(),o=0;o=document.documentMode,si=null,sa=null,gs=null,oa=!1;function Oh(n,i,o){var a=o.window===o?o.document:o.nodeType===9?o:o.ownerDocument;oa||si==null||si!==yo(a)||(a=si,"selectionStart"in a&&ia(a)?a={start:a.selectionStart,end:a.selectionEnd}:(a=(a.ownerDocument&&a.ownerDocument.defaultView||window).getSelection(),a={anchorNode:a.anchorNode,anchorOffset:a.anchorOffset,focusNode:a.focusNode,focusOffset:a.focusOffset}),gs&&ps(gs,a)||(gs=a,a=Ao(sa,"onSelect"),0ci||(n.current=va[ci],va[ci]=null,ci--)}function Fe(n,i){ci++,va[ci]=n.current,n.current=i}var qn={},ht=Vn(qn),Ct=Vn(!1),wr=qn;function fi(n,i){var o=n.type.contextTypes;if(!o)return qn;var a=n.stateNode;if(a&&a.__reactInternalMemoizedUnmaskedChildContext===i)return a.__reactInternalMemoizedMaskedChildContext;var d={},p;for(p in o)d[p]=i[p];return a&&(n=n.stateNode,n.__reactInternalMemoizedUnmaskedChildContext=i,n.__reactInternalMemoizedMaskedChildContext=d),d}function kt(n){return n=n.childContextTypes,n!=null}function Uo(){ze(Ct),ze(ht)}function Kh(n,i,o){if(ht.current!==qn)throw Error(r(168));Fe(ht,i),Fe(Ct,o)}function Wh(n,i,o){var a=n.stateNode;if(i=i.childContextTypes,typeof a.getChildContext!="function")return o;a=a.getChildContext();for(var d in a)if(!(d in i))throw Error(r(108,Me(n)||"Unknown",d));return Q({},o,a)}function Ko(n){return n=(n=n.stateNode)&&n.__reactInternalMemoizedMergedChildContext||qn,wr=ht.current,Fe(ht,n),Fe(Ct,Ct.current),!0}function Hh(n,i,o){var a=n.stateNode;if(!a)throw Error(r(169));o?(n=Wh(n,i,wr),a.__reactInternalMemoizedMergedChildContext=n,ze(Ct),ze(ht),Fe(ht,n)):ze(Ct),Fe(Ct,o)}var kn=null,Wo=!1,xa=!1;function Qh(n){kn===null?kn=[n]:kn.push(n)}function w_(n){Wo=!0,Qh(n)}function Gn(){if(!xa&&kn!==null){xa=!0;var n=0,i=be;try{var o=kn;for(be=1;n>=x,d-=x,En=1<<32-Wt(i)+d|o<me?(it=ge,ge=null):it=ge.sibling;var Oe=H(R,ge,I[me],Y);if(Oe===null){ge===null&&(ge=it);break}n&&ge&&Oe.alternate===null&&i(R,ge),b=p(Oe,b,me),pe===null?ce=Oe:pe.sibling=Oe,pe=Oe,ge=it}if(me===I.length)return o(R,ge),$e&&kr(R,me),ce;if(ge===null){for(;meme?(it=ge,ge=null):it=ge.sibling;var ir=H(R,ge,Oe.value,Y);if(ir===null){ge===null&&(ge=it);break}n&&ge&&ir.alternate===null&&i(R,ge),b=p(ir,b,me),pe===null?ce=ir:pe.sibling=ir,pe=ir,ge=it}if(Oe.done)return o(R,ge),$e&&kr(R,me),ce;if(ge===null){for(;!Oe.done;me++,Oe=I.next())Oe=G(R,Oe.value,Y),Oe!==null&&(b=p(Oe,b,me),pe===null?ce=Oe:pe.sibling=Oe,pe=Oe);return $e&&kr(R,me),ce}for(ge=a(R,ge);!Oe.done;me++,Oe=I.next())Oe=se(ge,R,me,Oe.value,Y),Oe!==null&&(n&&Oe.alternate!==null&&ge.delete(Oe.key===null?me:Oe.key),b=p(Oe,b,me),pe===null?ce=Oe:pe.sibling=Oe,pe=Oe);return n&&ge.forEach(function(nS){return i(R,nS)}),$e&&kr(R,me),ce}function Qe(R,b,I,Y){if(typeof I=="object"&&I!==null&&I.type===$&&I.key===null&&(I=I.props.children),typeof I=="object"&&I!==null){switch(I.$$typeof){case j:e:{for(var ce=I.key,pe=b;pe!==null;){if(pe.key===ce){if(ce=I.type,ce===$){if(pe.tag===7){o(R,pe.sibling),b=d(pe,I.props.children),b.return=R,R=b;break e}}else if(pe.elementType===ce||typeof ce=="object"&&ce!==null&&ce.$$typeof===ye&&Xh(ce)===pe.type){o(R,pe.sibling),b=d(pe,I.props),b.ref=Ss(R,pe,I),b.return=R,R=b;break e}o(R,pe);break}else i(R,pe);pe=pe.sibling}I.type===$?(b=Rr(I.props.children,R.mode,Y,I.key),b.return=R,R=b):(Y=vl(I.type,I.key,I.props,null,R.mode,Y),Y.ref=Ss(R,b,I),Y.return=R,R=Y)}return x(R);case D:e:{for(pe=I.key;b!==null;){if(b.key===pe)if(b.tag===4&&b.stateNode.containerInfo===I.containerInfo&&b.stateNode.implementation===I.implementation){o(R,b.sibling),b=d(b,I.children||[]),b.return=R,R=b;break e}else{o(R,b);break}else i(R,b);b=b.sibling}b=mc(I,R.mode,Y),b.return=R,R=b}return x(R);case ye:return pe=I._init,Qe(R,b,pe(I._payload),Y)}if(Ji(I))return le(R,b,I,Y);if(W(I))return ue(R,b,I,Y);qo(R,I)}return typeof I=="string"&&I!==""||typeof I=="number"?(I=""+I,b!==null&&b.tag===6?(o(R,b.sibling),b=d(b,I),b.return=R,R=b):(o(R,b),b=gc(I,R.mode,Y),b.return=R,R=b),x(R)):o(R,b)}return Qe}var gi=Zh(!0),ep=Zh(!1),Go=Vn(null),Jo=null,mi=null,Ea=null;function Na(){Ea=mi=Jo=null}function Ta(n){var i=Go.current;ze(Go),n._currentValue=i}function Oa(n,i,o){for(;n!==null;){var a=n.alternate;if((n.childLanes&i)!==i?(n.childLanes|=i,a!==null&&(a.childLanes|=i)):a!==null&&(a.childLanes&i)!==i&&(a.childLanes|=i),n===o)break;n=n.return}}function yi(n,i){Jo=n,Ea=mi=null,n=n.dependencies,n!==null&&n.firstContext!==null&&((n.lanes&i)!==0&&(Et=!0),n.firstContext=null)}function $t(n){var i=n._currentValue;if(Ea!==n)if(n={context:n,memoizedValue:i,next:null},mi===null){if(Jo===null)throw Error(r(308));mi=n,Jo.dependencies={lanes:0,firstContext:n}}else mi=mi.next=n;return i}var Er=null;function Ma(n){Er===null?Er=[n]:Er.push(n)}function tp(n,i,o,a){var d=i.interleaved;return d===null?(o.next=o,Ma(i)):(o.next=d.next,d.next=o),i.interleaved=o,Tn(n,a)}function Tn(n,i){n.lanes|=i;var o=n.alternate;for(o!==null&&(o.lanes|=i),o=n,n=n.return;n!==null;)n.childLanes|=i,o=n.alternate,o!==null&&(o.childLanes|=i),o=n,n=n.return;return o.tag===3?o.stateNode:null}var Jn=!1;function Pa(n){n.updateQueue={baseState:n.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function np(n,i){n=n.updateQueue,i.updateQueue===n&&(i.updateQueue={baseState:n.baseState,firstBaseUpdate:n.firstBaseUpdate,lastBaseUpdate:n.lastBaseUpdate,shared:n.shared,effects:n.effects})}function On(n,i){return{eventTime:n,lane:i,tag:0,payload:null,callback:null,next:null}}function Yn(n,i,o){var a=n.updateQueue;if(a===null)return null;if(a=a.shared,(Ne&2)!==0){var d=a.pending;return d===null?i.next=i:(i.next=d.next,d.next=i),a.pending=i,Tn(n,o)}return d=a.interleaved,d===null?(i.next=i,Ma(a)):(i.next=d.next,d.next=i),a.interleaved=i,Tn(n,o)}function Yo(n,i,o){if(i=i.updateQueue,i!==null&&(i=i.shared,(o&4194240)!==0)){var a=i.lanes;a&=n.pendingLanes,o|=a,i.lanes=o,Wu(n,o)}}function rp(n,i){var o=n.updateQueue,a=n.alternate;if(a!==null&&(a=a.updateQueue,o===a)){var d=null,p=null;if(o=o.firstBaseUpdate,o!==null){do{var x={eventTime:o.eventTime,lane:o.lane,tag:o.tag,payload:o.payload,callback:o.callback,next:null};p===null?d=p=x:p=p.next=x,o=o.next}while(o!==null);p===null?d=p=i:p=p.next=i}else d=p=i;o={baseState:a.baseState,firstBaseUpdate:d,lastBaseUpdate:p,shared:a.shared,effects:a.effects},n.updateQueue=o;return}n=o.lastBaseUpdate,n===null?o.firstBaseUpdate=i:n.next=i,o.lastBaseUpdate=i}function Xo(n,i,o,a){var d=n.updateQueue;Jn=!1;var p=d.firstBaseUpdate,x=d.lastBaseUpdate,E=d.shared.pending;if(E!==null){d.shared.pending=null;var O=E,B=O.next;O.next=null,x===null?p=B:x.next=B,x=O;var V=n.alternate;V!==null&&(V=V.updateQueue,E=V.lastBaseUpdate,E!==x&&(E===null?V.firstBaseUpdate=B:E.next=B,V.lastBaseUpdate=O))}if(p!==null){var G=d.baseState;x=0,V=B=O=null,E=p;do{var H=E.lane,se=E.eventTime;if((a&H)===H){V!==null&&(V=V.next={eventTime:se,lane:0,tag:E.tag,payload:E.payload,callback:E.callback,next:null});e:{var le=n,ue=E;switch(H=i,se=o,ue.tag){case 1:if(le=ue.payload,typeof le=="function"){G=le.call(se,G,H);break e}G=le;break e;case 3:le.flags=le.flags&-65537|128;case 0:if(le=ue.payload,H=typeof le=="function"?le.call(se,G,H):le,H==null)break e;G=Q({},G,H);break e;case 2:Jn=!0}}E.callback!==null&&E.lane!==0&&(n.flags|=64,H=d.effects,H===null?d.effects=[E]:H.push(E))}else se={eventTime:se,lane:H,tag:E.tag,payload:E.payload,callback:E.callback,next:null},V===null?(B=V=se,O=G):V=V.next=se,x|=H;if(E=E.next,E===null){if(E=d.shared.pending,E===null)break;H=E,E=H.next,H.next=null,d.lastBaseUpdate=H,d.shared.pending=null}}while(!0);if(V===null&&(O=G),d.baseState=O,d.firstBaseUpdate=B,d.lastBaseUpdate=V,i=d.shared.interleaved,i!==null){d=i;do x|=d.lane,d=d.next;while(d!==i)}else p===null&&(d.shared.lanes=0);Or|=x,n.lanes=x,n.memoizedState=G}}function ip(n,i,o){if(n=i.effects,i.effects=null,n!==null)for(i=0;io?o:4,n(!0);var a=Fa.transition;Fa.transition={};try{n(!1),i()}finally{be=o,Fa.transition=a}}function Cp(){return Bt().memoizedState}function N_(n,i,o){var a=tr(n);if(o={lane:a,action:o,hasEagerState:!1,eagerState:null,next:null},kp(n))Ep(i,o);else if(o=tp(n,i,o,a),o!==null){var d=xt();Jt(o,n,a,d),Np(o,i,a)}}function T_(n,i,o){var a=tr(n),d={lane:a,action:o,hasEagerState:!1,eagerState:null,next:null};if(kp(n))Ep(i,d);else{var p=n.alternate;if(n.lanes===0&&(p===null||p.lanes===0)&&(p=i.lastRenderedReducer,p!==null))try{var x=i.lastRenderedState,E=p(x,o);if(d.hasEagerState=!0,d.eagerState=E,Ht(E,x)){var O=i.interleaved;O===null?(d.next=d,Ma(i)):(d.next=O.next,O.next=d),i.interleaved=d;return}}catch{}finally{}o=tp(n,i,d,a),o!==null&&(d=xt(),Jt(o,n,a,d),Np(o,i,a))}}function kp(n){var i=n.alternate;return n===Ue||i!==null&&i===Ue}function Ep(n,i){Es=tl=!0;var o=n.pending;o===null?i.next=i:(i.next=o.next,o.next=i),n.pending=i}function Np(n,i,o){if((o&4194240)!==0){var a=i.lanes;a&=n.pendingLanes,o|=a,i.lanes=o,Wu(n,o)}}var il={readContext:$t,useCallback:pt,useContext:pt,useEffect:pt,useImperativeHandle:pt,useInsertionEffect:pt,useLayoutEffect:pt,useMemo:pt,useReducer:pt,useRef:pt,useState:pt,useDebugValue:pt,useDeferredValue:pt,useTransition:pt,useMutableSource:pt,useSyncExternalStore:pt,useId:pt,unstable_isNewReconciler:!1},O_={readContext:$t,useCallback:function(n,i){return dn().memoizedState=[n,i===void 0?null:i],n},useContext:$t,useEffect:gp,useImperativeHandle:function(n,i,o){return o=o!=null?o.concat([n]):null,nl(4194308,4,vp.bind(null,i,n),o)},useLayoutEffect:function(n,i){return nl(4194308,4,n,i)},useInsertionEffect:function(n,i){return nl(4,2,n,i)},useMemo:function(n,i){var o=dn();return i=i===void 0?null:i,n=n(),o.memoizedState=[n,i],n},useReducer:function(n,i,o){var a=dn();return i=o!==void 0?o(i):i,a.memoizedState=a.baseState=i,n={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:n,lastRenderedState:i},a.queue=n,n=n.dispatch=N_.bind(null,Ue,n),[a.memoizedState,n]},useRef:function(n){var i=dn();return n={current:n},i.memoizedState=n},useState:hp,useDebugValue:Ua,useDeferredValue:function(n){return dn().memoizedState=n},useTransition:function(){var n=hp(!1),i=n[0];return n=E_.bind(null,n[1]),dn().memoizedState=n,[i,n]},useMutableSource:function(){},useSyncExternalStore:function(n,i,o){var a=Ue,d=dn();if($e){if(o===void 0)throw Error(r(407));o=o()}else{if(o=i(),rt===null)throw Error(r(349));(Tr&30)!==0||up(a,i,o)}d.memoizedState=o;var p={value:o,getSnapshot:i};return d.queue=p,gp(cp.bind(null,a,p,n),[n]),a.flags|=2048,Os(9,ap.bind(null,a,p,o,i),void 0,null),o},useId:function(){var n=dn(),i=rt.identifierPrefix;if($e){var o=Nn,a=En;o=(a&~(1<<32-Wt(a)-1)).toString(32)+o,i=":"+i+"R"+o,o=Ns++,0")&&(O=O.replace("",n.displayName)),O}while(1<=x&&0<=E);break}}}finally{he=!1,Error.prepareStackTrace=o}return(n=n?n.displayName||n.name:"")?U(n):""}function we(n){switch(n.tag){case 5:return U(n.type);case 16:return U("Lazy");case 13:return U("Suspense");case 19:return U("SuspenseList");case 0:case 2:case 15:return n=ve(n.type,!1),n;case 11:return n=ve(n.type.render,!1),n;case 1:return n=ve(n.type,!0),n;default:return""}}function Ce(n){if(n==null)return null;if(typeof n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case $:return"Fragment";case D:return"Portal";case z:return"Profiler";case F:return"StrictMode";case X:return"Suspense";case ae:return"SuspenseList"}if(typeof n=="object")switch(n.$$typeof){case te:return(n.displayName||"Context")+".Consumer";case J:return(n._context.displayName||"Context")+".Provider";case ne:var i=n.render;return n=n.displayName,n||(n=i.displayName||i.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case Se:return i=n.displayName||null,i!==null?i:Ce(n.type)||"Memo";case ye:i=n._payload,n=n._init;try{return Ce(n(i))}catch{}}return null}function Me(n){var i=n.type;switch(n.tag){case 24:return"Cache";case 9:return(i.displayName||"Context")+".Consumer";case 10:return(i._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return n=i.render,n=n.displayName||n.name||"",i.displayName||(n!==""?"ForwardRef("+n+")":"ForwardRef");case 7:return"Fragment";case 5:return i;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Ce(i);case 8:return i===F?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof i=="function")return i.displayName||i.name||null;if(typeof i=="string")return i}return null}function Ee(n){switch(typeof n){case"boolean":case"number":case"string":case"undefined":return n;case"object":return n;default:return""}}function Te(n){var i=n.type;return(n=n.nodeName)&&n.toLowerCase()==="input"&&(i==="checkbox"||i==="radio")}function qe(n){var i=Te(n)?"checked":"value",o=Object.getOwnPropertyDescriptor(n.constructor.prototype,i),a=""+n[i];if(!n.hasOwnProperty(i)&&typeof o<"u"&&typeof o.get=="function"&&typeof o.set=="function"){var d=o.get,p=o.set;return Object.defineProperty(n,i,{configurable:!0,get:function(){return d.call(this)},set:function(x){a=""+x,p.call(this,x)}}),Object.defineProperty(n,i,{enumerable:o.enumerable}),{getValue:function(){return a},setValue:function(x){a=""+x},stopTracking:function(){n._valueTracker=null,delete n[i]}}}}function xr(n){n._valueTracker||(n._valueTracker=qe(n))}function Td(n){if(!n)return!1;var i=n._valueTracker;if(!i)return!0;var o=i.getValue(),a="";return n&&(a=Te(n)?n.checked?"true":"false":n.value),n=a,n!==o?(i.setValue(n),!0):!1}function yo(n){if(n=n||(typeof document<"u"?document:void 0),typeof n>"u")return null;try{return n.activeElement||n.body}catch{return n.body}}function Ou(n,i){var o=i.checked;return Q({},i,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:o??n._wrapperState.initialChecked})}function Od(n,i){var o=i.defaultValue==null?"":i.defaultValue,a=i.checked!=null?i.checked:i.defaultChecked;o=Ee(i.value!=null?i.value:o),n._wrapperState={initialChecked:a,initialValue:o,controlled:i.type==="checkbox"||i.type==="radio"?i.checked!=null:i.value!=null}}function Md(n,i){i=i.checked,i!=null&&M(n,"checked",i,!1)}function Mu(n,i){Md(n,i);var o=Ee(i.value),a=i.type;if(o!=null)a==="number"?(o===0&&n.value===""||n.value!=o)&&(n.value=""+o):n.value!==""+o&&(n.value=""+o);else if(a==="submit"||a==="reset"){n.removeAttribute("value");return}i.hasOwnProperty("value")?Pu(n,i.type,o):i.hasOwnProperty("defaultValue")&&Pu(n,i.type,Ee(i.defaultValue)),i.checked==null&&i.defaultChecked!=null&&(n.defaultChecked=!!i.defaultChecked)}function Pd(n,i,o){if(i.hasOwnProperty("value")||i.hasOwnProperty("defaultValue")){var a=i.type;if(!(a!=="submit"&&a!=="reset"||i.value!==void 0&&i.value!==null))return;i=""+n._wrapperState.initialValue,o||i===n.value||(n.value=i),n.defaultValue=i}o=n.name,o!==""&&(n.name=""),n.defaultChecked=!!n._wrapperState.initialChecked,o!==""&&(n.name=o)}function Pu(n,i,o){(i!=="number"||yo(n.ownerDocument)!==n)&&(o==null?n.defaultValue=""+n._wrapperState.initialValue:n.defaultValue!==""+o&&(n.defaultValue=""+o))}var Ji=Array.isArray;function Zr(n,i,o,a){if(n=n.options,i){i={};for(var d=0;d"+i.valueOf().toString()+"",i=vo.firstChild;n.firstChild;)n.removeChild(n.firstChild);for(;i.firstChild;)n.appendChild(i.firstChild)}});function Yi(n,i){if(i){var o=n.firstChild;if(o&&o===n.lastChild&&o.nodeType===3){o.nodeValue=i;return}}n.textContent=i}var Xi={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},ux=["Webkit","ms","Moz","O"];Object.keys(Xi).forEach(function(n){ux.forEach(function(i){i=i+n.charAt(0).toUpperCase()+n.substring(1),Xi[i]=Xi[n]})});function Id(n,i,o){return i==null||typeof i=="boolean"||i===""?"":o||typeof i!="number"||i===0||Xi.hasOwnProperty(n)&&Xi[n]?(""+i).trim():i+"px"}function Ld(n,i){n=n.style;for(var o in i)if(i.hasOwnProperty(o)){var a=o.indexOf("--")===0,d=Id(o,i[o],a);o==="float"&&(o="cssFloat"),a?n.setProperty(o,d):n[o]=d}}var ax=Q({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function Du(n,i){if(i){if(ax[n]&&(i.children!=null||i.dangerouslySetInnerHTML!=null))throw Error(r(137,n));if(i.dangerouslySetInnerHTML!=null){if(i.children!=null)throw Error(r(60));if(typeof i.dangerouslySetInnerHTML!="object"||!("__html"in i.dangerouslySetInnerHTML))throw Error(r(61))}if(i.style!=null&&typeof i.style!="object")throw Error(r(62))}}function ju(n,i){if(n.indexOf("-")===-1)return typeof i.is=="string";switch(n){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Fu=null;function Iu(n){return n=n.target||n.srcElement||window,n.correspondingUseElement&&(n=n.correspondingUseElement),n.nodeType===3?n.parentNode:n}var Lu=null,ei=null,ti=null;function Ad(n){if(n=_s(n)){if(typeof Lu!="function")throw Error(r(280));var i=n.stateNode;i&&(i=Bo(i),Lu(n.stateNode,n.type,i))}}function zd(n){ei?ti?ti.push(n):ti=[n]:ei=n}function $d(){if(ei){var n=ei,i=ti;if(ti=ei=null,Ad(n),i)for(n=0;n>>=0,n===0?32:31-(_x(n)/Sx|0)|0}var Co=64,ko=4194304;function ns(n){switch(n&-n){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return n&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return n&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return n}}function Eo(n,i){var o=n.pendingLanes;if(o===0)return 0;var a=0,d=n.suspendedLanes,p=n.pingedLanes,x=o&268435455;if(x!==0){var E=x&~d;E!==0?a=ns(E):(p&=x,p!==0&&(a=ns(p)))}else x=o&~d,x!==0?a=ns(x):p!==0&&(a=ns(p));if(a===0)return 0;if(i!==0&&i!==a&&(i&d)===0&&(d=a&-a,p=i&-i,d>=p||d===16&&(p&4194240)!==0))return i;if((a&4)!==0&&(a|=o&16),i=n.entangledLanes,i!==0)for(n=n.entanglements,i&=a;0o;o++)i.push(n);return i}function rs(n,i,o){n.pendingLanes|=i,i!==536870912&&(n.suspendedLanes=0,n.pingedLanes=0),n=n.eventTimes,i=31-Wt(i),n[i]=o}function Ex(n,i){var o=n.pendingLanes&~i;n.pendingLanes=i,n.suspendedLanes=0,n.pingedLanes=0,n.expiredLanes&=i,n.mutableReadLanes&=i,n.entangledLanes&=i,i=n.entanglements;var a=n.eventTimes;for(n=n.expirationTimes;0=fs),ph=" ",gh=!1;function mh(n,i){switch(n){case"keyup":return Zx.indexOf(i.keyCode)!==-1;case"keydown":return i.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function yh(n){return n=n.detail,typeof n=="object"&&"data"in n?n.data:null}var ii=!1;function t_(n,i){switch(n){case"compositionend":return yh(i);case"keypress":return i.which!==32?null:(gh=!0,ph);case"textInput":return n=i.data,n===ph&&gh?null:n;default:return null}}function n_(n,i){if(ii)return n==="compositionend"||!ta&&mh(n,i)?(n=uh(),Po=Gu=Wn=null,ii=!1,n):null;switch(n){case"paste":return null;case"keypress":if(!(i.ctrlKey||i.altKey||i.metaKey)||i.ctrlKey&&i.altKey){if(i.char&&1=i)return{node:o,offset:i-n};n=a}e:{for(;o;){if(o.nextSibling){o=o.nextSibling;break e}o=o.parentNode}o=void 0}o=kh(o)}}function Nh(n,i){return n&&i?n===i?!0:n&&n.nodeType===3?!1:i&&i.nodeType===3?Nh(n,i.parentNode):"contains"in n?n.contains(i):n.compareDocumentPosition?!!(n.compareDocumentPosition(i)&16):!1:!1}function Th(){for(var n=window,i=yo();i instanceof n.HTMLIFrameElement;){try{var o=typeof i.contentWindow.location.href=="string"}catch{o=!1}if(o)n=i.contentWindow;else break;i=yo(n.document)}return i}function ia(n){var i=n&&n.nodeName&&n.nodeName.toLowerCase();return i&&(i==="input"&&(n.type==="text"||n.type==="search"||n.type==="tel"||n.type==="url"||n.type==="password")||i==="textarea"||n.contentEditable==="true")}function f_(n){var i=Th(),o=n.focusedElem,a=n.selectionRange;if(i!==o&&o&&o.ownerDocument&&Nh(o.ownerDocument.documentElement,o)){if(a!==null&&ia(o)){if(i=a.start,n=a.end,n===void 0&&(n=i),"selectionStart"in o)o.selectionStart=i,o.selectionEnd=Math.min(n,o.value.length);else if(n=(i=o.ownerDocument||document)&&i.defaultView||window,n.getSelection){n=n.getSelection();var d=o.textContent.length,p=Math.min(a.start,d);a=a.end===void 0?p:Math.min(a.end,d),!n.extend&&p>a&&(d=a,a=p,p=d),d=Eh(o,p);var x=Eh(o,a);d&&x&&(n.rangeCount!==1||n.anchorNode!==d.node||n.anchorOffset!==d.offset||n.focusNode!==x.node||n.focusOffset!==x.offset)&&(i=i.createRange(),i.setStart(d.node,d.offset),n.removeAllRanges(),p>a?(n.addRange(i),n.extend(x.node,x.offset)):(i.setEnd(x.node,x.offset),n.addRange(i)))}}for(i=[],n=o;n=n.parentNode;)n.nodeType===1&&i.push({element:n,left:n.scrollLeft,top:n.scrollTop});for(typeof o.focus=="function"&&o.focus(),o=0;o=document.documentMode,si=null,sa=null,gs=null,oa=!1;function Oh(n,i,o){var a=o.window===o?o.document:o.nodeType===9?o:o.ownerDocument;oa||si==null||si!==yo(a)||(a=si,"selectionStart"in a&&ia(a)?a={start:a.selectionStart,end:a.selectionEnd}:(a=(a.ownerDocument&&a.ownerDocument.defaultView||window).getSelection(),a={anchorNode:a.anchorNode,anchorOffset:a.anchorOffset,focusNode:a.focusNode,focusOffset:a.focusOffset}),gs&&ps(gs,a)||(gs=a,a=Ao(sa,"onSelect"),0ci||(n.current=va[ci],va[ci]=null,ci--)}function Fe(n,i){ci++,va[ci]=n.current,n.current=i}var qn={},ht=Vn(qn),Ct=Vn(!1),wr=qn;function fi(n,i){var o=n.type.contextTypes;if(!o)return qn;var a=n.stateNode;if(a&&a.__reactInternalMemoizedUnmaskedChildContext===i)return a.__reactInternalMemoizedMaskedChildContext;var d={},p;for(p in o)d[p]=i[p];return a&&(n=n.stateNode,n.__reactInternalMemoizedUnmaskedChildContext=i,n.__reactInternalMemoizedMaskedChildContext=d),d}function kt(n){return n=n.childContextTypes,n!=null}function Uo(){ze(Ct),ze(ht)}function Kh(n,i,o){if(ht.current!==qn)throw Error(r(168));Fe(ht,i),Fe(Ct,o)}function Wh(n,i,o){var a=n.stateNode;if(i=i.childContextTypes,typeof a.getChildContext!="function")return o;a=a.getChildContext();for(var d in a)if(!(d in i))throw Error(r(108,Me(n)||"Unknown",d));return Q({},o,a)}function Ko(n){return n=(n=n.stateNode)&&n.__reactInternalMemoizedMergedChildContext||qn,wr=ht.current,Fe(ht,n),Fe(Ct,Ct.current),!0}function Hh(n,i,o){var a=n.stateNode;if(!a)throw Error(r(169));o?(n=Wh(n,i,wr),a.__reactInternalMemoizedMergedChildContext=n,ze(Ct),ze(ht),Fe(ht,n)):ze(Ct),Fe(Ct,o)}var kn=null,Wo=!1,xa=!1;function Qh(n){kn===null?kn=[n]:kn.push(n)}function C_(n){Wo=!0,Qh(n)}function Gn(){if(!xa&&kn!==null){xa=!0;var n=0,i=be;try{var o=kn;for(be=1;n>=x,d-=x,En=1<<32-Wt(i)+d|o<me?(it=ge,ge=null):it=ge.sibling;var Oe=H(R,ge,I[me],Y);if(Oe===null){ge===null&&(ge=it);break}n&&ge&&Oe.alternate===null&&i(R,ge),b=p(Oe,b,me),pe===null?ce=Oe:pe.sibling=Oe,pe=Oe,ge=it}if(me===I.length)return o(R,ge),$e&&kr(R,me),ce;if(ge===null){for(;meme?(it=ge,ge=null):it=ge.sibling;var ir=H(R,ge,Oe.value,Y);if(ir===null){ge===null&&(ge=it);break}n&&ge&&ir.alternate===null&&i(R,ge),b=p(ir,b,me),pe===null?ce=ir:pe.sibling=ir,pe=ir,ge=it}if(Oe.done)return o(R,ge),$e&&kr(R,me),ce;if(ge===null){for(;!Oe.done;me++,Oe=I.next())Oe=G(R,Oe.value,Y),Oe!==null&&(b=p(Oe,b,me),pe===null?ce=Oe:pe.sibling=Oe,pe=Oe);return $e&&kr(R,me),ce}for(ge=a(R,ge);!Oe.done;me++,Oe=I.next())Oe=se(ge,R,me,Oe.value,Y),Oe!==null&&(n&&Oe.alternate!==null&&ge.delete(Oe.key===null?me:Oe.key),b=p(Oe,b,me),pe===null?ce=Oe:pe.sibling=Oe,pe=Oe);return n&&ge.forEach(function(rS){return i(R,rS)}),$e&&kr(R,me),ce}function Qe(R,b,I,Y){if(typeof I=="object"&&I!==null&&I.type===$&&I.key===null&&(I=I.props.children),typeof I=="object"&&I!==null){switch(I.$$typeof){case j:e:{for(var ce=I.key,pe=b;pe!==null;){if(pe.key===ce){if(ce=I.type,ce===$){if(pe.tag===7){o(R,pe.sibling),b=d(pe,I.props.children),b.return=R,R=b;break e}}else if(pe.elementType===ce||typeof ce=="object"&&ce!==null&&ce.$$typeof===ye&&Xh(ce)===pe.type){o(R,pe.sibling),b=d(pe,I.props),b.ref=Ss(R,pe,I),b.return=R,R=b;break e}o(R,pe);break}else i(R,pe);pe=pe.sibling}I.type===$?(b=Rr(I.props.children,R.mode,Y,I.key),b.return=R,R=b):(Y=vl(I.type,I.key,I.props,null,R.mode,Y),Y.ref=Ss(R,b,I),Y.return=R,R=Y)}return x(R);case D:e:{for(pe=I.key;b!==null;){if(b.key===pe)if(b.tag===4&&b.stateNode.containerInfo===I.containerInfo&&b.stateNode.implementation===I.implementation){o(R,b.sibling),b=d(b,I.children||[]),b.return=R,R=b;break e}else{o(R,b);break}else i(R,b);b=b.sibling}b=mc(I,R.mode,Y),b.return=R,R=b}return x(R);case ye:return pe=I._init,Qe(R,b,pe(I._payload),Y)}if(Ji(I))return le(R,b,I,Y);if(W(I))return ue(R,b,I,Y);qo(R,I)}return typeof I=="string"&&I!==""||typeof I=="number"?(I=""+I,b!==null&&b.tag===6?(o(R,b.sibling),b=d(b,I),b.return=R,R=b):(o(R,b),b=gc(I,R.mode,Y),b.return=R,R=b),x(R)):o(R,b)}return Qe}var gi=Zh(!0),ep=Zh(!1),Go=Vn(null),Jo=null,mi=null,Ea=null;function Na(){Ea=mi=Jo=null}function Ta(n){var i=Go.current;ze(Go),n._currentValue=i}function Oa(n,i,o){for(;n!==null;){var a=n.alternate;if((n.childLanes&i)!==i?(n.childLanes|=i,a!==null&&(a.childLanes|=i)):a!==null&&(a.childLanes&i)!==i&&(a.childLanes|=i),n===o)break;n=n.return}}function yi(n,i){Jo=n,Ea=mi=null,n=n.dependencies,n!==null&&n.firstContext!==null&&((n.lanes&i)!==0&&(Et=!0),n.firstContext=null)}function $t(n){var i=n._currentValue;if(Ea!==n)if(n={context:n,memoizedValue:i,next:null},mi===null){if(Jo===null)throw Error(r(308));mi=n,Jo.dependencies={lanes:0,firstContext:n}}else mi=mi.next=n;return i}var Er=null;function Ma(n){Er===null?Er=[n]:Er.push(n)}function tp(n,i,o,a){var d=i.interleaved;return d===null?(o.next=o,Ma(i)):(o.next=d.next,d.next=o),i.interleaved=o,Tn(n,a)}function Tn(n,i){n.lanes|=i;var o=n.alternate;for(o!==null&&(o.lanes|=i),o=n,n=n.return;n!==null;)n.childLanes|=i,o=n.alternate,o!==null&&(o.childLanes|=i),o=n,n=n.return;return o.tag===3?o.stateNode:null}var Jn=!1;function Pa(n){n.updateQueue={baseState:n.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function np(n,i){n=n.updateQueue,i.updateQueue===n&&(i.updateQueue={baseState:n.baseState,firstBaseUpdate:n.firstBaseUpdate,lastBaseUpdate:n.lastBaseUpdate,shared:n.shared,effects:n.effects})}function On(n,i){return{eventTime:n,lane:i,tag:0,payload:null,callback:null,next:null}}function Yn(n,i,o){var a=n.updateQueue;if(a===null)return null;if(a=a.shared,(Ne&2)!==0){var d=a.pending;return d===null?i.next=i:(i.next=d.next,d.next=i),a.pending=i,Tn(n,o)}return d=a.interleaved,d===null?(i.next=i,Ma(a)):(i.next=d.next,d.next=i),a.interleaved=i,Tn(n,o)}function Yo(n,i,o){if(i=i.updateQueue,i!==null&&(i=i.shared,(o&4194240)!==0)){var a=i.lanes;a&=n.pendingLanes,o|=a,i.lanes=o,Wu(n,o)}}function rp(n,i){var o=n.updateQueue,a=n.alternate;if(a!==null&&(a=a.updateQueue,o===a)){var d=null,p=null;if(o=o.firstBaseUpdate,o!==null){do{var x={eventTime:o.eventTime,lane:o.lane,tag:o.tag,payload:o.payload,callback:o.callback,next:null};p===null?d=p=x:p=p.next=x,o=o.next}while(o!==null);p===null?d=p=i:p=p.next=i}else d=p=i;o={baseState:a.baseState,firstBaseUpdate:d,lastBaseUpdate:p,shared:a.shared,effects:a.effects},n.updateQueue=o;return}n=o.lastBaseUpdate,n===null?o.firstBaseUpdate=i:n.next=i,o.lastBaseUpdate=i}function Xo(n,i,o,a){var d=n.updateQueue;Jn=!1;var p=d.firstBaseUpdate,x=d.lastBaseUpdate,E=d.shared.pending;if(E!==null){d.shared.pending=null;var O=E,B=O.next;O.next=null,x===null?p=B:x.next=B,x=O;var V=n.alternate;V!==null&&(V=V.updateQueue,E=V.lastBaseUpdate,E!==x&&(E===null?V.firstBaseUpdate=B:E.next=B,V.lastBaseUpdate=O))}if(p!==null){var G=d.baseState;x=0,V=B=O=null,E=p;do{var H=E.lane,se=E.eventTime;if((a&H)===H){V!==null&&(V=V.next={eventTime:se,lane:0,tag:E.tag,payload:E.payload,callback:E.callback,next:null});e:{var le=n,ue=E;switch(H=i,se=o,ue.tag){case 1:if(le=ue.payload,typeof le=="function"){G=le.call(se,G,H);break e}G=le;break e;case 3:le.flags=le.flags&-65537|128;case 0:if(le=ue.payload,H=typeof le=="function"?le.call(se,G,H):le,H==null)break e;G=Q({},G,H);break e;case 2:Jn=!0}}E.callback!==null&&E.lane!==0&&(n.flags|=64,H=d.effects,H===null?d.effects=[E]:H.push(E))}else se={eventTime:se,lane:H,tag:E.tag,payload:E.payload,callback:E.callback,next:null},V===null?(B=V=se,O=G):V=V.next=se,x|=H;if(E=E.next,E===null){if(E=d.shared.pending,E===null)break;H=E,E=H.next,H.next=null,d.lastBaseUpdate=H,d.shared.pending=null}}while(!0);if(V===null&&(O=G),d.baseState=O,d.firstBaseUpdate=B,d.lastBaseUpdate=V,i=d.shared.interleaved,i!==null){d=i;do x|=d.lane,d=d.next;while(d!==i)}else p===null&&(d.shared.lanes=0);Or|=x,n.lanes=x,n.memoizedState=G}}function ip(n,i,o){if(n=i.effects,i.effects=null,n!==null)for(i=0;io?o:4,n(!0);var a=Fa.transition;Fa.transition={};try{n(!1),i()}finally{be=o,Fa.transition=a}}function Cp(){return Bt().memoizedState}function T_(n,i,o){var a=tr(n);if(o={lane:a,action:o,hasEagerState:!1,eagerState:null,next:null},kp(n))Ep(i,o);else if(o=tp(n,i,o,a),o!==null){var d=xt();Jt(o,n,a,d),Np(o,i,a)}}function O_(n,i,o){var a=tr(n),d={lane:a,action:o,hasEagerState:!1,eagerState:null,next:null};if(kp(n))Ep(i,d);else{var p=n.alternate;if(n.lanes===0&&(p===null||p.lanes===0)&&(p=i.lastRenderedReducer,p!==null))try{var x=i.lastRenderedState,E=p(x,o);if(d.hasEagerState=!0,d.eagerState=E,Ht(E,x)){var O=i.interleaved;O===null?(d.next=d,Ma(i)):(d.next=O.next,O.next=d),i.interleaved=d;return}}catch{}finally{}o=tp(n,i,d,a),o!==null&&(d=xt(),Jt(o,n,a,d),Np(o,i,a))}}function kp(n){var i=n.alternate;return n===Ue||i!==null&&i===Ue}function Ep(n,i){Es=tl=!0;var o=n.pending;o===null?i.next=i:(i.next=o.next,o.next=i),n.pending=i}function Np(n,i,o){if((o&4194240)!==0){var a=i.lanes;a&=n.pendingLanes,o|=a,i.lanes=o,Wu(n,o)}}var il={readContext:$t,useCallback:pt,useContext:pt,useEffect:pt,useImperativeHandle:pt,useInsertionEffect:pt,useLayoutEffect:pt,useMemo:pt,useReducer:pt,useRef:pt,useState:pt,useDebugValue:pt,useDeferredValue:pt,useTransition:pt,useMutableSource:pt,useSyncExternalStore:pt,useId:pt,unstable_isNewReconciler:!1},M_={readContext:$t,useCallback:function(n,i){return dn().memoizedState=[n,i===void 0?null:i],n},useContext:$t,useEffect:gp,useImperativeHandle:function(n,i,o){return o=o!=null?o.concat([n]):null,nl(4194308,4,vp.bind(null,i,n),o)},useLayoutEffect:function(n,i){return nl(4194308,4,n,i)},useInsertionEffect:function(n,i){return nl(4,2,n,i)},useMemo:function(n,i){var o=dn();return i=i===void 0?null:i,n=n(),o.memoizedState=[n,i],n},useReducer:function(n,i,o){var a=dn();return i=o!==void 0?o(i):i,a.memoizedState=a.baseState=i,n={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:n,lastRenderedState:i},a.queue=n,n=n.dispatch=T_.bind(null,Ue,n),[a.memoizedState,n]},useRef:function(n){var i=dn();return n={current:n},i.memoizedState=n},useState:hp,useDebugValue:Ua,useDeferredValue:function(n){return dn().memoizedState=n},useTransition:function(){var n=hp(!1),i=n[0];return n=N_.bind(null,n[1]),dn().memoizedState=n,[i,n]},useMutableSource:function(){},useSyncExternalStore:function(n,i,o){var a=Ue,d=dn();if($e){if(o===void 0)throw Error(r(407));o=o()}else{if(o=i(),rt===null)throw Error(r(349));(Tr&30)!==0||up(a,i,o)}d.memoizedState=o;var p={value:o,getSnapshot:i};return d.queue=p,gp(cp.bind(null,a,p,n),[n]),a.flags|=2048,Os(9,ap.bind(null,a,p,o,i),void 0,null),o},useId:function(){var n=dn(),i=rt.identifierPrefix;if($e){var o=Nn,a=En;o=(a&~(1<<32-Wt(a)-1)).toString(32)+o,i=":"+i+"R"+o,o=Ns++,0<\/script>",n=n.removeChild(n.firstChild)):typeof a.is=="string"?n=x.createElement(o,{is:a.is}):(n=x.createElement(o),o==="select"&&(x=n,a.multiple?x.multiple=!0:a.size&&(x.size=a.size))):n=x.createElementNS(n,o),n[cn]=i,n[xs]=a,Qp(n,i,!1,!1),i.stateNode=n;e:{switch(x=ju(o,a),o){case"dialog":Ae("cancel",n),Ae("close",n),d=a;break;case"iframe":case"object":case"embed":Ae("load",n),d=a;break;case"video":case"audio":for(d=0;dwi&&(i.flags|=128,a=!0,Ms(p,!1),i.lanes=4194304)}else{if(!a)if(n=Zo(x),n!==null){if(i.flags|=128,a=!0,o=n.updateQueue,o!==null&&(i.updateQueue=o,i.flags|=4),Ms(p,!0),p.tail===null&&p.tailMode==="hidden"&&!x.alternate&&!$e)return gt(i),null}else 2*He()-p.renderingStartTime>wi&&o!==1073741824&&(i.flags|=128,a=!0,Ms(p,!1),i.lanes=4194304);p.isBackwards?(x.sibling=i.child,i.child=x):(o=p.last,o!==null?o.sibling=x:i.child=x,p.last=x)}return p.tail!==null?(i=p.tail,p.rendering=i,p.tail=i.sibling,p.renderingStartTime=He(),i.sibling=null,o=Be.current,Fe(Be,a?o&1|2:o&1),i):(gt(i),null);case 22:case 23:return dc(),a=i.memoizedState!==null,n!==null&&n.memoizedState!==null!==a&&(i.flags|=8192),a&&(i.mode&1)!==0?(jt&1073741824)!==0&&(gt(i),i.subtreeFlags&6&&(i.flags|=8192)):gt(i),null;case 24:return null;case 25:return null}throw Error(r(156,i.tag))}function I_(n,i){switch(Sa(i),i.tag){case 1:return kt(i.type)&&Uo(),n=i.flags,n&65536?(i.flags=n&-65537|128,i):null;case 3:return vi(),ze(Ct),ze(ht),ja(),n=i.flags,(n&65536)!==0&&(n&128)===0?(i.flags=n&-65537|128,i):null;case 5:return Ra(i),null;case 13:if(ze(Be),n=i.memoizedState,n!==null&&n.dehydrated!==null){if(i.alternate===null)throw Error(r(340));pi()}return n=i.flags,n&65536?(i.flags=n&-65537|128,i):null;case 19:return ze(Be),null;case 4:return vi(),null;case 10:return Ta(i.type._context),null;case 22:case 23:return dc(),null;case 24:return null;default:return null}}var ul=!1,mt=!1,L_=typeof WeakSet=="function"?WeakSet:Set,oe=null;function _i(n,i){var o=n.ref;if(o!==null)if(typeof o=="function")try{o(null)}catch(a){We(n,i,a)}else o.current=null}function ec(n,i,o){try{o()}catch(a){We(n,i,a)}}var Gp=!1;function A_(n,i){if(da=Oo,n=Th(),ia(n)){if("selectionStart"in n)var o={start:n.selectionStart,end:n.selectionEnd};else e:{o=(o=n.ownerDocument)&&o.defaultView||window;var a=o.getSelection&&o.getSelection();if(a&&a.rangeCount!==0){o=a.anchorNode;var d=a.anchorOffset,p=a.focusNode;a=a.focusOffset;try{o.nodeType,p.nodeType}catch{o=null;break e}var x=0,E=-1,O=-1,B=0,V=0,G=n,H=null;t:for(;;){for(var se;G!==o||d!==0&&G.nodeType!==3||(E=x+d),G!==p||a!==0&&G.nodeType!==3||(O=x+a),G.nodeType===3&&(x+=G.nodeValue.length),(se=G.firstChild)!==null;)H=G,G=se;for(;;){if(G===n)break t;if(H===o&&++B===d&&(E=x),H===p&&++V===a&&(O=x),(se=G.nextSibling)!==null)break;G=H,H=G.parentNode}G=se}o=E===-1||O===-1?null:{start:E,end:O}}else o=null}o=o||{start:0,end:0}}else o=null;for(ha={focusedElem:n,selectionRange:o},Oo=!1,oe=i;oe!==null;)if(i=oe,n=i.child,(i.subtreeFlags&1028)!==0&&n!==null)n.return=i,oe=n;else for(;oe!==null;){i=oe;try{var le=i.alternate;if((i.flags&1024)!==0)switch(i.tag){case 0:case 11:case 15:break;case 1:if(le!==null){var ue=le.memoizedProps,Qe=le.memoizedState,R=i.stateNode,b=R.getSnapshotBeforeUpdate(i.elementType===i.type?ue:Vt(i.type,ue),Qe);R.__reactInternalSnapshotBeforeUpdate=b}break;case 3:var I=i.stateNode.containerInfo;I.nodeType===1?I.textContent="":I.nodeType===9&&I.documentElement&&I.removeChild(I.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(r(163))}}catch(Y){We(i,i.return,Y)}if(n=i.sibling,n!==null){n.return=i.return,oe=n;break}oe=i.return}return le=Gp,Gp=!1,le}function Ps(n,i,o){var a=i.updateQueue;if(a=a!==null?a.lastEffect:null,a!==null){var d=a=a.next;do{if((d.tag&n)===n){var p=d.destroy;d.destroy=void 0,p!==void 0&&ec(i,o,p)}d=d.next}while(d!==a)}}function al(n,i){if(i=i.updateQueue,i=i!==null?i.lastEffect:null,i!==null){var o=i=i.next;do{if((o.tag&n)===n){var a=o.create;o.destroy=a()}o=o.next}while(o!==i)}}function tc(n){var i=n.ref;if(i!==null){var o=n.stateNode;switch(n.tag){case 5:n=o;break;default:n=o}typeof i=="function"?i(n):i.current=n}}function Jp(n){var i=n.alternate;i!==null&&(n.alternate=null,Jp(i)),n.child=null,n.deletions=null,n.sibling=null,n.tag===5&&(i=n.stateNode,i!==null&&(delete i[cn],delete i[xs],delete i[ya],delete i[__],delete i[S_])),n.stateNode=null,n.return=null,n.dependencies=null,n.memoizedProps=null,n.memoizedState=null,n.pendingProps=null,n.stateNode=null,n.updateQueue=null}function Yp(n){return n.tag===5||n.tag===3||n.tag===4}function Xp(n){e:for(;;){for(;n.sibling===null;){if(n.return===null||Yp(n.return))return null;n=n.return}for(n.sibling.return=n.return,n=n.sibling;n.tag!==5&&n.tag!==6&&n.tag!==18;){if(n.flags&2||n.child===null||n.tag===4)continue e;n.child.return=n,n=n.child}if(!(n.flags&2))return n.stateNode}}function nc(n,i,o){var a=n.tag;if(a===5||a===6)n=n.stateNode,i?o.nodeType===8?o.parentNode.insertBefore(n,i):o.insertBefore(n,i):(o.nodeType===8?(i=o.parentNode,i.insertBefore(n,o)):(i=o,i.appendChild(n)),o=o._reactRootContainer,o!=null||i.onclick!==null||(i.onclick=$o));else if(a!==4&&(n=n.child,n!==null))for(nc(n,i,o),n=n.sibling;n!==null;)nc(n,i,o),n=n.sibling}function rc(n,i,o){var a=n.tag;if(a===5||a===6)n=n.stateNode,i?o.insertBefore(n,i):o.appendChild(n);else if(a!==4&&(n=n.child,n!==null))for(rc(n,i,o),n=n.sibling;n!==null;)rc(n,i,o),n=n.sibling}var ut=null,qt=!1;function Xn(n,i,o){for(o=o.child;o!==null;)Zp(n,i,o),o=o.sibling}function Zp(n,i,o){if(an&&typeof an.onCommitFiberUnmount=="function")try{an.onCommitFiberUnmount(wo,o)}catch{}switch(o.tag){case 5:mt||_i(o,i);case 6:var a=ut,d=qt;ut=null,Xn(n,i,o),ut=a,qt=d,ut!==null&&(qt?(n=ut,o=o.stateNode,n.nodeType===8?n.parentNode.removeChild(o):n.removeChild(o)):ut.removeChild(o.stateNode));break;case 18:ut!==null&&(qt?(n=ut,o=o.stateNode,n.nodeType===8?ma(n.parentNode,o):n.nodeType===1&&ma(n,o),us(n)):ma(ut,o.stateNode));break;case 4:a=ut,d=qt,ut=o.stateNode.containerInfo,qt=!0,Xn(n,i,o),ut=a,qt=d;break;case 0:case 11:case 14:case 15:if(!mt&&(a=o.updateQueue,a!==null&&(a=a.lastEffect,a!==null))){d=a=a.next;do{var p=d,x=p.destroy;p=p.tag,x!==void 0&&((p&2)!==0||(p&4)!==0)&&ec(o,i,x),d=d.next}while(d!==a)}Xn(n,i,o);break;case 1:if(!mt&&(_i(o,i),a=o.stateNode,typeof a.componentWillUnmount=="function"))try{a.props=o.memoizedProps,a.state=o.memoizedState,a.componentWillUnmount()}catch(E){We(o,i,E)}Xn(n,i,o);break;case 21:Xn(n,i,o);break;case 22:o.mode&1?(mt=(a=mt)||o.memoizedState!==null,Xn(n,i,o),mt=a):Xn(n,i,o);break;default:Xn(n,i,o)}}function eg(n){var i=n.updateQueue;if(i!==null){n.updateQueue=null;var o=n.stateNode;o===null&&(o=n.stateNode=new L_),i.forEach(function(a){var d=V_.bind(null,n,a);o.has(a)||(o.add(a),a.then(d,d))})}}function Gt(n,i){var o=i.deletions;if(o!==null)for(var a=0;ad&&(d=x),a&=~p}if(a=d,a=He()-a,a=(120>a?120:480>a?480:1080>a?1080:1920>a?1920:3e3>a?3e3:4320>a?4320:1960*$_(a/1960))-a,10n?16:n,er===null)var a=!1;else{if(n=er,er=null,pl=0,(Ne&6)!==0)throw Error(r(331));var d=Ne;for(Ne|=4,oe=n.current;oe!==null;){var p=oe,x=p.child;if((oe.flags&16)!==0){var E=p.deletions;if(E!==null){for(var O=0;OHe()-oc?Pr(n,0):sc|=o),Tt(n,i)}function hg(n,i){i===0&&((n.mode&1)===0?i=1:(i=ko,ko<<=1,(ko&130023424)===0&&(ko=4194304)));var o=xt();n=Tn(n,i),n!==null&&(rs(n,i,o),Tt(n,o))}function Q_(n){var i=n.memoizedState,o=0;i!==null&&(o=i.retryLane),hg(n,o)}function V_(n,i){var o=0;switch(n.tag){case 13:var a=n.stateNode,d=n.memoizedState;d!==null&&(o=d.retryLane);break;case 19:a=n.stateNode;break;default:throw Error(r(314))}a!==null&&a.delete(i),hg(n,o)}var pg;pg=function(n,i,o){if(n!==null)if(n.memoizedProps!==i.pendingProps||Ct.current)Et=!0;else{if((n.lanes&o)===0&&(i.flags&128)===0)return Et=!1,j_(n,i,o);Et=(n.flags&131072)!==0}else Et=!1,$e&&(i.flags&1048576)!==0&&Vh(i,Qo,i.index);switch(i.lanes=0,i.tag){case 2:var a=i.type;ll(n,i),n=i.pendingProps;var d=fi(i,ht.current);yi(i,o),d=La(null,i,a,n,d,o);var p=Aa();return i.flags|=1,typeof d=="object"&&d!==null&&typeof d.render=="function"&&d.$$typeof===void 0?(i.tag=1,i.memoizedState=null,i.updateQueue=null,kt(a)?(p=!0,Ko(i)):p=!1,i.memoizedState=d.state!==null&&d.state!==void 0?d.state:null,Pa(i),d.updater=sl,i.stateNode=d,d._reactInternals=i,Wa(i,a,n,o),i=qa(null,i,a,!0,p,o)):(i.tag=0,$e&&p&&_a(i),vt(null,i,d,o),i=i.child),i;case 16:a=i.elementType;e:{switch(ll(n,i),n=i.pendingProps,d=a._init,a=d(a._payload),i.type=a,d=i.tag=G_(a),n=Vt(a,n),d){case 0:i=Va(null,i,a,n,o);break e;case 1:i=$p(null,i,a,n,o);break e;case 11:i=Fp(null,i,a,n,o);break e;case 14:i=Ip(null,i,a,Vt(a.type,n),o);break e}throw Error(r(306,a,""))}return i;case 0:return a=i.type,d=i.pendingProps,d=i.elementType===a?d:Vt(a,d),Va(n,i,a,d,o);case 1:return a=i.type,d=i.pendingProps,d=i.elementType===a?d:Vt(a,d),$p(n,i,a,d,o);case 3:e:{if(Bp(i),n===null)throw Error(r(387));a=i.pendingProps,p=i.memoizedState,d=p.element,np(n,i),Xo(i,a,null,o);var x=i.memoizedState;if(a=x.element,p.isDehydrated)if(p={element:a,isDehydrated:!1,cache:x.cache,pendingSuspenseBoundaries:x.pendingSuspenseBoundaries,transitions:x.transitions},i.updateQueue.baseState=p,i.memoizedState=p,i.flags&256){d=xi(Error(r(423)),i),i=Up(n,i,a,o,d);break e}else if(a!==d){d=xi(Error(r(424)),i),i=Up(n,i,a,o,d);break e}else for(Dt=Qn(i.stateNode.containerInfo.firstChild),Rt=i,$e=!0,Qt=null,o=ep(i,null,a,o),i.child=o;o;)o.flags=o.flags&-3|4096,o=o.sibling;else{if(pi(),a===d){i=Mn(n,i,o);break e}vt(n,i,a,o)}i=i.child}return i;case 5:return sp(i),n===null&&Ca(i),a=i.type,d=i.pendingProps,p=n!==null?n.memoizedProps:null,x=d.children,pa(a,d)?x=null:p!==null&&pa(a,p)&&(i.flags|=32),zp(n,i),vt(n,i,x,o),i.child;case 6:return n===null&&Ca(i),null;case 13:return Kp(n,i,o);case 4:return ba(i,i.stateNode.containerInfo),a=i.pendingProps,n===null?i.child=gi(i,null,a,o):vt(n,i,a,o),i.child;case 11:return a=i.type,d=i.pendingProps,d=i.elementType===a?d:Vt(a,d),Fp(n,i,a,d,o);case 7:return vt(n,i,i.pendingProps,o),i.child;case 8:return vt(n,i,i.pendingProps.children,o),i.child;case 12:return vt(n,i,i.pendingProps.children,o),i.child;case 10:e:{if(a=i.type._context,d=i.pendingProps,p=i.memoizedProps,x=d.value,Fe(Go,a._currentValue),a._currentValue=x,p!==null)if(Ht(p.value,x)){if(p.children===d.children&&!Ct.current){i=Mn(n,i,o);break e}}else for(p=i.child,p!==null&&(p.return=i);p!==null;){var E=p.dependencies;if(E!==null){x=p.child;for(var O=E.firstContext;O!==null;){if(O.context===a){if(p.tag===1){O=On(-1,o&-o),O.tag=2;var B=p.updateQueue;if(B!==null){B=B.shared;var V=B.pending;V===null?O.next=O:(O.next=V.next,V.next=O),B.pending=O}}p.lanes|=o,O=p.alternate,O!==null&&(O.lanes|=o),Oa(p.return,o,i),E.lanes|=o;break}O=O.next}}else if(p.tag===10)x=p.type===i.type?null:p.child;else if(p.tag===18){if(x=p.return,x===null)throw Error(r(341));x.lanes|=o,E=x.alternate,E!==null&&(E.lanes|=o),Oa(x,o,i),x=p.sibling}else x=p.child;if(x!==null)x.return=p;else for(x=p;x!==null;){if(x===i){x=null;break}if(p=x.sibling,p!==null){p.return=x.return,x=p;break}x=x.return}p=x}vt(n,i,d.children,o),i=i.child}return i;case 9:return d=i.type,a=i.pendingProps.children,yi(i,o),d=$t(d),a=a(d),i.flags|=1,vt(n,i,a,o),i.child;case 14:return a=i.type,d=Vt(a,i.pendingProps),d=Vt(a.type,d),Ip(n,i,a,d,o);case 15:return Lp(n,i,i.type,i.pendingProps,o);case 17:return a=i.type,d=i.pendingProps,d=i.elementType===a?d:Vt(a,d),ll(n,i),i.tag=1,kt(a)?(n=!0,Ko(i)):n=!1,yi(i,o),Op(i,a,d),Wa(i,a,d,o),qa(null,i,a,!0,n,o);case 19:return Hp(n,i,o);case 22:return Ap(n,i,o)}throw Error(r(156,i.tag))};function gg(n,i){return qd(n,i)}function q_(n,i,o,a){this.tag=n,this.key=o,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=i,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=a,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Kt(n,i,o,a){return new q_(n,i,o,a)}function pc(n){return n=n.prototype,!(!n||!n.isReactComponent)}function G_(n){if(typeof n=="function")return pc(n)?1:0;if(n!=null){if(n=n.$$typeof,n===ne)return 11;if(n===Se)return 14}return 2}function rr(n,i){var o=n.alternate;return o===null?(o=Kt(n.tag,i,n.key,n.mode),o.elementType=n.elementType,o.type=n.type,o.stateNode=n.stateNode,o.alternate=n,n.alternate=o):(o.pendingProps=i,o.type=n.type,o.flags=0,o.subtreeFlags=0,o.deletions=null),o.flags=n.flags&14680064,o.childLanes=n.childLanes,o.lanes=n.lanes,o.child=n.child,o.memoizedProps=n.memoizedProps,o.memoizedState=n.memoizedState,o.updateQueue=n.updateQueue,i=n.dependencies,o.dependencies=i===null?null:{lanes:i.lanes,firstContext:i.firstContext},o.sibling=n.sibling,o.index=n.index,o.ref=n.ref,o}function vl(n,i,o,a,d,p){var x=2;if(a=n,typeof n=="function")pc(n)&&(x=1);else if(typeof n=="string")x=5;else e:switch(n){case $:return Rr(o.children,d,p,i);case F:x=8,d|=8;break;case z:return n=Kt(12,o,i,d|2),n.elementType=z,n.lanes=p,n;case X:return n=Kt(13,o,i,d),n.elementType=X,n.lanes=p,n;case ae:return n=Kt(19,o,i,d),n.elementType=ae,n.lanes=p,n;case _e:return xl(o,d,p,i);default:if(typeof n=="object"&&n!==null)switch(n.$$typeof){case J:x=10;break e;case te:x=9;break e;case ne:x=11;break e;case Se:x=14;break e;case ye:x=16,a=null;break e}throw Error(r(130,n==null?n:typeof n,""))}return i=Kt(x,o,i,d),i.elementType=n,i.type=a,i.lanes=p,i}function Rr(n,i,o,a){return n=Kt(7,n,a,i),n.lanes=o,n}function xl(n,i,o,a){return n=Kt(22,n,a,i),n.elementType=_e,n.lanes=o,n.stateNode={isHidden:!1},n}function gc(n,i,o){return n=Kt(6,n,null,i),n.lanes=o,n}function mc(n,i,o){return i=Kt(4,n.children!==null?n.children:[],n.key,i),i.lanes=o,i.stateNode={containerInfo:n.containerInfo,pendingChildren:null,implementation:n.implementation},i}function J_(n,i,o,a,d){this.tag=i,this.containerInfo=n,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Ku(0),this.expirationTimes=Ku(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Ku(0),this.identifierPrefix=a,this.onRecoverableError=d,this.mutableSourceEagerHydrationData=null}function yc(n,i,o,a,d,p,x,E,O){return n=new J_(n,i,o,E,O),i===1?(i=1,p===!0&&(i|=8)):i=0,p=Kt(3,null,null,i),n.current=p,p.stateNode=n,p.memoizedState={element:a,isDehydrated:o,cache:null,transitions:null,pendingSuspenseBoundaries:null},Pa(p),n}function Y_(n,i,o){var a=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(e){console.error(e)}}return t(),Cc.exports=cS(),Cc.exports}var Mg;function fS(){if(Mg)return Nl;Mg=1;var t=Ey();return Nl.createRoot=t.createRoot,Nl.hydrateRoot=t.hydrateRoot,Nl}var dS=fS();function hS(t,e){if(t instanceof RegExp)return{keys:!1,pattern:t};var r,s,l,u,c=[],f="",h=t.split("/");for(h[0]||h.shift();l=h.shift();)r=l[0],r==="*"?(c.push(r),f+=l[1]==="?"?"(?:/(.*))?":"/(.*)"):r===":"?(s=l.indexOf("?",1),u=l.indexOf(".",1),c.push(l.substring(1,~s?s:~u?u:l.length)),f+=~s&&!~u?"(?:/([^/]+?))?":"/([^/]+?)",~u&&(f+=(~s?"?":"")+"\\"+l.substring(u))):f+="/"+l;return{keys:c,pattern:new RegExp("^"+f+(e?"(?=$|/)":"/?$"),"i")}}var Nc={exports:{}},Tc={};/** +`+p.stack}return{value:n,source:i,stack:d,digest:null}}function Ha(n,i,o){return{value:n,source:null,stack:o??null,digest:i??null}}function Qa(n,i){try{console.error(i.value)}catch(o){setTimeout(function(){throw o})}}var R_=typeof WeakMap=="function"?WeakMap:Map;function Pp(n,i,o){o=On(-1,o),o.tag=3,o.payload={element:null};var a=i.value;return o.callback=function(){dl||(dl=!0,lc=a),Qa(n,i)},o}function bp(n,i,o){o=On(-1,o),o.tag=3;var a=n.type.getDerivedStateFromError;if(typeof a=="function"){var d=i.value;o.payload=function(){return a(d)},o.callback=function(){Qa(n,i)}}var p=n.stateNode;return p!==null&&typeof p.componentDidCatch=="function"&&(o.callback=function(){Qa(n,i),typeof a!="function"&&(Zn===null?Zn=new Set([this]):Zn.add(this));var x=i.stack;this.componentDidCatch(i.value,{componentStack:x!==null?x:""})}),o}function Rp(n,i,o){var a=n.pingCache;if(a===null){a=n.pingCache=new R_;var d=new Set;a.set(i,d)}else d=a.get(i),d===void 0&&(d=new Set,a.set(i,d));d.has(o)||(d.add(o),n=Q_.bind(null,n,i,o),i.then(n,n))}function Dp(n){do{var i;if((i=n.tag===13)&&(i=n.memoizedState,i=i!==null?i.dehydrated!==null:!0),i)return n;n=n.return}while(n!==null);return null}function jp(n,i,o,a,d){return(n.mode&1)===0?(n===i?n.flags|=65536:(n.flags|=128,o.flags|=131072,o.flags&=-52805,o.tag===1&&(o.alternate===null?o.tag=17:(i=On(-1,1),i.tag=2,Yn(o,i,1))),o.lanes|=1),n):(n.flags|=65536,n.lanes=d,n)}var D_=L.ReactCurrentOwner,Et=!1;function vt(n,i,o,a){i.child=n===null?ep(i,null,o,a):gi(i,n.child,o,a)}function Fp(n,i,o,a,d){o=o.render;var p=i.ref;return yi(i,d),a=La(n,i,o,a,p,d),o=Aa(),n!==null&&!Et?(i.updateQueue=n.updateQueue,i.flags&=-2053,n.lanes&=~d,Mn(n,i,d)):($e&&o&&_a(i),i.flags|=1,vt(n,i,a,d),i.child)}function Ip(n,i,o,a,d){if(n===null){var p=o.type;return typeof p=="function"&&!pc(p)&&p.defaultProps===void 0&&o.compare===null&&o.defaultProps===void 0?(i.tag=15,i.type=p,Lp(n,i,p,a,d)):(n=vl(o.type,null,a,i,i.mode,d),n.ref=i.ref,n.return=i,i.child=n)}if(p=n.child,(n.lanes&d)===0){var x=p.memoizedProps;if(o=o.compare,o=o!==null?o:ps,o(x,a)&&n.ref===i.ref)return Mn(n,i,d)}return i.flags|=1,n=rr(p,a),n.ref=i.ref,n.return=i,i.child=n}function Lp(n,i,o,a,d){if(n!==null){var p=n.memoizedProps;if(ps(p,a)&&n.ref===i.ref)if(Et=!1,i.pendingProps=a=p,(n.lanes&d)!==0)(n.flags&131072)!==0&&(Et=!0);else return i.lanes=n.lanes,Mn(n,i,d)}return Va(n,i,o,a,d)}function Ap(n,i,o){var a=i.pendingProps,d=a.children,p=n!==null?n.memoizedState:null;if(a.mode==="hidden")if((i.mode&1)===0)i.memoizedState={baseLanes:0,cachePool:null,transitions:null},Fe(Si,jt),jt|=o;else{if((o&1073741824)===0)return n=p!==null?p.baseLanes|o:o,i.lanes=i.childLanes=1073741824,i.memoizedState={baseLanes:n,cachePool:null,transitions:null},i.updateQueue=null,Fe(Si,jt),jt|=n,null;i.memoizedState={baseLanes:0,cachePool:null,transitions:null},a=p!==null?p.baseLanes:o,Fe(Si,jt),jt|=a}else p!==null?(a=p.baseLanes|o,i.memoizedState=null):a=o,Fe(Si,jt),jt|=a;return vt(n,i,d,o),i.child}function zp(n,i){var o=i.ref;(n===null&&o!==null||n!==null&&n.ref!==o)&&(i.flags|=512,i.flags|=2097152)}function Va(n,i,o,a,d){var p=kt(o)?wr:ht.current;return p=fi(i,p),yi(i,d),o=La(n,i,o,a,p,d),a=Aa(),n!==null&&!Et?(i.updateQueue=n.updateQueue,i.flags&=-2053,n.lanes&=~d,Mn(n,i,d)):($e&&a&&_a(i),i.flags|=1,vt(n,i,o,d),i.child)}function $p(n,i,o,a,d){if(kt(o)){var p=!0;Ko(i)}else p=!1;if(yi(i,d),i.stateNode===null)ll(n,i),Op(i,o,a),Wa(i,o,a,d),a=!0;else if(n===null){var x=i.stateNode,E=i.memoizedProps;x.props=E;var O=x.context,B=o.contextType;typeof B=="object"&&B!==null?B=$t(B):(B=kt(o)?wr:ht.current,B=fi(i,B));var V=o.getDerivedStateFromProps,G=typeof V=="function"||typeof x.getSnapshotBeforeUpdate=="function";G||typeof x.UNSAFE_componentWillReceiveProps!="function"&&typeof x.componentWillReceiveProps!="function"||(E!==a||O!==B)&&Mp(i,x,a,B),Jn=!1;var H=i.memoizedState;x.state=H,Xo(i,a,x,d),O=i.memoizedState,E!==a||H!==O||Ct.current||Jn?(typeof V=="function"&&(Ka(i,o,V,a),O=i.memoizedState),(E=Jn||Tp(i,o,E,a,H,O,B))?(G||typeof x.UNSAFE_componentWillMount!="function"&&typeof x.componentWillMount!="function"||(typeof x.componentWillMount=="function"&&x.componentWillMount(),typeof x.UNSAFE_componentWillMount=="function"&&x.UNSAFE_componentWillMount()),typeof x.componentDidMount=="function"&&(i.flags|=4194308)):(typeof x.componentDidMount=="function"&&(i.flags|=4194308),i.memoizedProps=a,i.memoizedState=O),x.props=a,x.state=O,x.context=B,a=E):(typeof x.componentDidMount=="function"&&(i.flags|=4194308),a=!1)}else{x=i.stateNode,np(n,i),E=i.memoizedProps,B=i.type===i.elementType?E:Vt(i.type,E),x.props=B,G=i.pendingProps,H=x.context,O=o.contextType,typeof O=="object"&&O!==null?O=$t(O):(O=kt(o)?wr:ht.current,O=fi(i,O));var se=o.getDerivedStateFromProps;(V=typeof se=="function"||typeof x.getSnapshotBeforeUpdate=="function")||typeof x.UNSAFE_componentWillReceiveProps!="function"&&typeof x.componentWillReceiveProps!="function"||(E!==G||H!==O)&&Mp(i,x,a,O),Jn=!1,H=i.memoizedState,x.state=H,Xo(i,a,x,d);var le=i.memoizedState;E!==G||H!==le||Ct.current||Jn?(typeof se=="function"&&(Ka(i,o,se,a),le=i.memoizedState),(B=Jn||Tp(i,o,B,a,H,le,O)||!1)?(V||typeof x.UNSAFE_componentWillUpdate!="function"&&typeof x.componentWillUpdate!="function"||(typeof x.componentWillUpdate=="function"&&x.componentWillUpdate(a,le,O),typeof x.UNSAFE_componentWillUpdate=="function"&&x.UNSAFE_componentWillUpdate(a,le,O)),typeof x.componentDidUpdate=="function"&&(i.flags|=4),typeof x.getSnapshotBeforeUpdate=="function"&&(i.flags|=1024)):(typeof x.componentDidUpdate!="function"||E===n.memoizedProps&&H===n.memoizedState||(i.flags|=4),typeof x.getSnapshotBeforeUpdate!="function"||E===n.memoizedProps&&H===n.memoizedState||(i.flags|=1024),i.memoizedProps=a,i.memoizedState=le),x.props=a,x.state=le,x.context=O,a=B):(typeof x.componentDidUpdate!="function"||E===n.memoizedProps&&H===n.memoizedState||(i.flags|=4),typeof x.getSnapshotBeforeUpdate!="function"||E===n.memoizedProps&&H===n.memoizedState||(i.flags|=1024),a=!1)}return qa(n,i,o,a,p,d)}function qa(n,i,o,a,d,p){zp(n,i);var x=(i.flags&128)!==0;if(!a&&!x)return d&&Hh(i,o,!1),Mn(n,i,p);a=i.stateNode,D_.current=i;var E=x&&typeof o.getDerivedStateFromError!="function"?null:a.render();return i.flags|=1,n!==null&&x?(i.child=gi(i,n.child,null,p),i.child=gi(i,null,E,p)):vt(n,i,E,p),i.memoizedState=a.state,d&&Hh(i,o,!0),i.child}function Bp(n){var i=n.stateNode;i.pendingContext?Kh(n,i.pendingContext,i.pendingContext!==i.context):i.context&&Kh(n,i.context,!1),ba(n,i.containerInfo)}function Up(n,i,o,a,d){return pi(),ka(d),i.flags|=256,vt(n,i,o,a),i.child}var Ga={dehydrated:null,treeContext:null,retryLane:0};function Ja(n){return{baseLanes:n,cachePool:null,transitions:null}}function Kp(n,i,o){var a=i.pendingProps,d=Be.current,p=!1,x=(i.flags&128)!==0,E;if((E=x)||(E=n!==null&&n.memoizedState===null?!1:(d&2)!==0),E?(p=!0,i.flags&=-129):(n===null||n.memoizedState!==null)&&(d|=1),Fe(Be,d&1),n===null)return Ca(i),n=i.memoizedState,n!==null&&(n=n.dehydrated,n!==null)?((i.mode&1)===0?i.lanes=1:n.data==="$!"?i.lanes=8:i.lanes=1073741824,null):(x=a.children,n=a.fallback,p?(a=i.mode,p=i.child,x={mode:"hidden",children:x},(a&1)===0&&p!==null?(p.childLanes=0,p.pendingProps=x):p=xl(x,a,0,null),n=Rr(n,a,o,null),p.return=i,n.return=i,p.sibling=n,i.child=p,i.child.memoizedState=Ja(o),i.memoizedState=Ga,n):Ya(i,x));if(d=n.memoizedState,d!==null&&(E=d.dehydrated,E!==null))return j_(n,i,x,a,E,d,o);if(p){p=a.fallback,x=i.mode,d=n.child,E=d.sibling;var O={mode:"hidden",children:a.children};return(x&1)===0&&i.child!==d?(a=i.child,a.childLanes=0,a.pendingProps=O,i.deletions=null):(a=rr(d,O),a.subtreeFlags=d.subtreeFlags&14680064),E!==null?p=rr(E,p):(p=Rr(p,x,o,null),p.flags|=2),p.return=i,a.return=i,a.sibling=p,i.child=a,a=p,p=i.child,x=n.child.memoizedState,x=x===null?Ja(o):{baseLanes:x.baseLanes|o,cachePool:null,transitions:x.transitions},p.memoizedState=x,p.childLanes=n.childLanes&~o,i.memoizedState=Ga,a}return p=n.child,n=p.sibling,a=rr(p,{mode:"visible",children:a.children}),(i.mode&1)===0&&(a.lanes=o),a.return=i,a.sibling=null,n!==null&&(o=i.deletions,o===null?(i.deletions=[n],i.flags|=16):o.push(n)),i.child=a,i.memoizedState=null,a}function Ya(n,i){return i=xl({mode:"visible",children:i},n.mode,0,null),i.return=n,n.child=i}function ol(n,i,o,a){return a!==null&&ka(a),gi(i,n.child,null,o),n=Ya(i,i.pendingProps.children),n.flags|=2,i.memoizedState=null,n}function j_(n,i,o,a,d,p,x){if(o)return i.flags&256?(i.flags&=-257,a=Ha(Error(r(422))),ol(n,i,x,a)):i.memoizedState!==null?(i.child=n.child,i.flags|=128,null):(p=a.fallback,d=i.mode,a=xl({mode:"visible",children:a.children},d,0,null),p=Rr(p,d,x,null),p.flags|=2,a.return=i,p.return=i,a.sibling=p,i.child=a,(i.mode&1)!==0&&gi(i,n.child,null,x),i.child.memoizedState=Ja(x),i.memoizedState=Ga,p);if((i.mode&1)===0)return ol(n,i,x,null);if(d.data==="$!"){if(a=d.nextSibling&&d.nextSibling.dataset,a)var E=a.dgst;return a=E,p=Error(r(419)),a=Ha(p,a,void 0),ol(n,i,x,a)}if(E=(x&n.childLanes)!==0,Et||E){if(a=rt,a!==null){switch(x&-x){case 4:d=2;break;case 16:d=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:d=32;break;case 536870912:d=268435456;break;default:d=0}d=(d&(a.suspendedLanes|x))!==0?0:d,d!==0&&d!==p.retryLane&&(p.retryLane=d,Tn(n,d),Jt(a,n,d,-1))}return hc(),a=Ha(Error(r(421))),ol(n,i,x,a)}return d.data==="$?"?(i.flags|=128,i.child=n.child,i=V_.bind(null,n),d._reactRetry=i,null):(n=p.treeContext,Dt=Qn(d.nextSibling),Rt=i,$e=!0,Qt=null,n!==null&&(At[zt++]=En,At[zt++]=Nn,At[zt++]=Cr,En=n.id,Nn=n.overflow,Cr=i),i=Ya(i,a.children),i.flags|=4096,i)}function Wp(n,i,o){n.lanes|=i;var a=n.alternate;a!==null&&(a.lanes|=i),Oa(n.return,i,o)}function Xa(n,i,o,a,d){var p=n.memoizedState;p===null?n.memoizedState={isBackwards:i,rendering:null,renderingStartTime:0,last:a,tail:o,tailMode:d}:(p.isBackwards=i,p.rendering=null,p.renderingStartTime=0,p.last=a,p.tail=o,p.tailMode=d)}function Hp(n,i,o){var a=i.pendingProps,d=a.revealOrder,p=a.tail;if(vt(n,i,a.children,o),a=Be.current,(a&2)!==0)a=a&1|2,i.flags|=128;else{if(n!==null&&(n.flags&128)!==0)e:for(n=i.child;n!==null;){if(n.tag===13)n.memoizedState!==null&&Wp(n,o,i);else if(n.tag===19)Wp(n,o,i);else if(n.child!==null){n.child.return=n,n=n.child;continue}if(n===i)break e;for(;n.sibling===null;){if(n.return===null||n.return===i)break e;n=n.return}n.sibling.return=n.return,n=n.sibling}a&=1}if(Fe(Be,a),(i.mode&1)===0)i.memoizedState=null;else switch(d){case"forwards":for(o=i.child,d=null;o!==null;)n=o.alternate,n!==null&&Zo(n)===null&&(d=o),o=o.sibling;o=d,o===null?(d=i.child,i.child=null):(d=o.sibling,o.sibling=null),Xa(i,!1,d,o,p);break;case"backwards":for(o=null,d=i.child,i.child=null;d!==null;){if(n=d.alternate,n!==null&&Zo(n)===null){i.child=d;break}n=d.sibling,d.sibling=o,o=d,d=n}Xa(i,!0,o,null,p);break;case"together":Xa(i,!1,null,null,void 0);break;default:i.memoizedState=null}return i.child}function ll(n,i){(i.mode&1)===0&&n!==null&&(n.alternate=null,i.alternate=null,i.flags|=2)}function Mn(n,i,o){if(n!==null&&(i.dependencies=n.dependencies),Or|=i.lanes,(o&i.childLanes)===0)return null;if(n!==null&&i.child!==n.child)throw Error(r(153));if(i.child!==null){for(n=i.child,o=rr(n,n.pendingProps),i.child=o,o.return=i;n.sibling!==null;)n=n.sibling,o=o.sibling=rr(n,n.pendingProps),o.return=i;o.sibling=null}return i.child}function F_(n,i,o){switch(i.tag){case 3:Bp(i),pi();break;case 5:sp(i);break;case 1:kt(i.type)&&Ko(i);break;case 4:ba(i,i.stateNode.containerInfo);break;case 10:var a=i.type._context,d=i.memoizedProps.value;Fe(Go,a._currentValue),a._currentValue=d;break;case 13:if(a=i.memoizedState,a!==null)return a.dehydrated!==null?(Fe(Be,Be.current&1),i.flags|=128,null):(o&i.child.childLanes)!==0?Kp(n,i,o):(Fe(Be,Be.current&1),n=Mn(n,i,o),n!==null?n.sibling:null);Fe(Be,Be.current&1);break;case 19:if(a=(o&i.childLanes)!==0,(n.flags&128)!==0){if(a)return Hp(n,i,o);i.flags|=128}if(d=i.memoizedState,d!==null&&(d.rendering=null,d.tail=null,d.lastEffect=null),Fe(Be,Be.current),a)break;return null;case 22:case 23:return i.lanes=0,Ap(n,i,o)}return Mn(n,i,o)}var Qp,Za,Vp,qp;Qp=function(n,i){for(var o=i.child;o!==null;){if(o.tag===5||o.tag===6)n.appendChild(o.stateNode);else if(o.tag!==4&&o.child!==null){o.child.return=o,o=o.child;continue}if(o===i)break;for(;o.sibling===null;){if(o.return===null||o.return===i)return;o=o.return}o.sibling.return=o.return,o=o.sibling}},Za=function(){},Vp=function(n,i,o,a){var d=n.memoizedProps;if(d!==a){n=i.stateNode,Nr(fn.current);var p=null;switch(o){case"input":d=Ou(n,d),a=Ou(n,a),p=[];break;case"select":d=Q({},d,{value:void 0}),a=Q({},a,{value:void 0}),p=[];break;case"textarea":d=bu(n,d),a=bu(n,a),p=[];break;default:typeof d.onClick!="function"&&typeof a.onClick=="function"&&(n.onclick=$o)}Du(o,a);var x;o=null;for(B in d)if(!a.hasOwnProperty(B)&&d.hasOwnProperty(B)&&d[B]!=null)if(B==="style"){var E=d[B];for(x in E)E.hasOwnProperty(x)&&(o||(o={}),o[x]="")}else B!=="dangerouslySetInnerHTML"&&B!=="children"&&B!=="suppressContentEditableWarning"&&B!=="suppressHydrationWarning"&&B!=="autoFocus"&&(l.hasOwnProperty(B)?p||(p=[]):(p=p||[]).push(B,null));for(B in a){var O=a[B];if(E=d?.[B],a.hasOwnProperty(B)&&O!==E&&(O!=null||E!=null))if(B==="style")if(E){for(x in E)!E.hasOwnProperty(x)||O&&O.hasOwnProperty(x)||(o||(o={}),o[x]="");for(x in O)O.hasOwnProperty(x)&&E[x]!==O[x]&&(o||(o={}),o[x]=O[x])}else o||(p||(p=[]),p.push(B,o)),o=O;else B==="dangerouslySetInnerHTML"?(O=O?O.__html:void 0,E=E?E.__html:void 0,O!=null&&E!==O&&(p=p||[]).push(B,O)):B==="children"?typeof O!="string"&&typeof O!="number"||(p=p||[]).push(B,""+O):B!=="suppressContentEditableWarning"&&B!=="suppressHydrationWarning"&&(l.hasOwnProperty(B)?(O!=null&&B==="onScroll"&&Ae("scroll",n),p||E===O||(p=[])):(p=p||[]).push(B,O))}o&&(p=p||[]).push("style",o);var B=p;(i.updateQueue=B)&&(i.flags|=4)}},qp=function(n,i,o,a){o!==a&&(i.flags|=4)};function Ms(n,i){if(!$e)switch(n.tailMode){case"hidden":i=n.tail;for(var o=null;i!==null;)i.alternate!==null&&(o=i),i=i.sibling;o===null?n.tail=null:o.sibling=null;break;case"collapsed":o=n.tail;for(var a=null;o!==null;)o.alternate!==null&&(a=o),o=o.sibling;a===null?i||n.tail===null?n.tail=null:n.tail.sibling=null:a.sibling=null}}function gt(n){var i=n.alternate!==null&&n.alternate.child===n.child,o=0,a=0;if(i)for(var d=n.child;d!==null;)o|=d.lanes|d.childLanes,a|=d.subtreeFlags&14680064,a|=d.flags&14680064,d.return=n,d=d.sibling;else for(d=n.child;d!==null;)o|=d.lanes|d.childLanes,a|=d.subtreeFlags,a|=d.flags,d.return=n,d=d.sibling;return n.subtreeFlags|=a,n.childLanes=o,i}function I_(n,i,o){var a=i.pendingProps;switch(Sa(i),i.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return gt(i),null;case 1:return kt(i.type)&&Uo(),gt(i),null;case 3:return a=i.stateNode,vi(),ze(Ct),ze(ht),ja(),a.pendingContext&&(a.context=a.pendingContext,a.pendingContext=null),(n===null||n.child===null)&&(Vo(i)?i.flags|=4:n===null||n.memoizedState.isDehydrated&&(i.flags&256)===0||(i.flags|=1024,Qt!==null&&(cc(Qt),Qt=null))),Za(n,i),gt(i),null;case 5:Ra(i);var d=Nr(ks.current);if(o=i.type,n!==null&&i.stateNode!=null)Vp(n,i,o,a,d),n.ref!==i.ref&&(i.flags|=512,i.flags|=2097152);else{if(!a){if(i.stateNode===null)throw Error(r(166));return gt(i),null}if(n=Nr(fn.current),Vo(i)){a=i.stateNode,o=i.type;var p=i.memoizedProps;switch(a[cn]=i,a[xs]=p,n=(i.mode&1)!==0,o){case"dialog":Ae("cancel",a),Ae("close",a);break;case"iframe":case"object":case"embed":Ae("load",a);break;case"video":case"audio":for(d=0;d<\/script>",n=n.removeChild(n.firstChild)):typeof a.is=="string"?n=x.createElement(o,{is:a.is}):(n=x.createElement(o),o==="select"&&(x=n,a.multiple?x.multiple=!0:a.size&&(x.size=a.size))):n=x.createElementNS(n,o),n[cn]=i,n[xs]=a,Qp(n,i,!1,!1),i.stateNode=n;e:{switch(x=ju(o,a),o){case"dialog":Ae("cancel",n),Ae("close",n),d=a;break;case"iframe":case"object":case"embed":Ae("load",n),d=a;break;case"video":case"audio":for(d=0;dwi&&(i.flags|=128,a=!0,Ms(p,!1),i.lanes=4194304)}else{if(!a)if(n=Zo(x),n!==null){if(i.flags|=128,a=!0,o=n.updateQueue,o!==null&&(i.updateQueue=o,i.flags|=4),Ms(p,!0),p.tail===null&&p.tailMode==="hidden"&&!x.alternate&&!$e)return gt(i),null}else 2*He()-p.renderingStartTime>wi&&o!==1073741824&&(i.flags|=128,a=!0,Ms(p,!1),i.lanes=4194304);p.isBackwards?(x.sibling=i.child,i.child=x):(o=p.last,o!==null?o.sibling=x:i.child=x,p.last=x)}return p.tail!==null?(i=p.tail,p.rendering=i,p.tail=i.sibling,p.renderingStartTime=He(),i.sibling=null,o=Be.current,Fe(Be,a?o&1|2:o&1),i):(gt(i),null);case 22:case 23:return dc(),a=i.memoizedState!==null,n!==null&&n.memoizedState!==null!==a&&(i.flags|=8192),a&&(i.mode&1)!==0?(jt&1073741824)!==0&&(gt(i),i.subtreeFlags&6&&(i.flags|=8192)):gt(i),null;case 24:return null;case 25:return null}throw Error(r(156,i.tag))}function L_(n,i){switch(Sa(i),i.tag){case 1:return kt(i.type)&&Uo(),n=i.flags,n&65536?(i.flags=n&-65537|128,i):null;case 3:return vi(),ze(Ct),ze(ht),ja(),n=i.flags,(n&65536)!==0&&(n&128)===0?(i.flags=n&-65537|128,i):null;case 5:return Ra(i),null;case 13:if(ze(Be),n=i.memoizedState,n!==null&&n.dehydrated!==null){if(i.alternate===null)throw Error(r(340));pi()}return n=i.flags,n&65536?(i.flags=n&-65537|128,i):null;case 19:return ze(Be),null;case 4:return vi(),null;case 10:return Ta(i.type._context),null;case 22:case 23:return dc(),null;case 24:return null;default:return null}}var ul=!1,mt=!1,A_=typeof WeakSet=="function"?WeakSet:Set,oe=null;function _i(n,i){var o=n.ref;if(o!==null)if(typeof o=="function")try{o(null)}catch(a){We(n,i,a)}else o.current=null}function ec(n,i,o){try{o()}catch(a){We(n,i,a)}}var Gp=!1;function z_(n,i){if(da=Oo,n=Th(),ia(n)){if("selectionStart"in n)var o={start:n.selectionStart,end:n.selectionEnd};else e:{o=(o=n.ownerDocument)&&o.defaultView||window;var a=o.getSelection&&o.getSelection();if(a&&a.rangeCount!==0){o=a.anchorNode;var d=a.anchorOffset,p=a.focusNode;a=a.focusOffset;try{o.nodeType,p.nodeType}catch{o=null;break e}var x=0,E=-1,O=-1,B=0,V=0,G=n,H=null;t:for(;;){for(var se;G!==o||d!==0&&G.nodeType!==3||(E=x+d),G!==p||a!==0&&G.nodeType!==3||(O=x+a),G.nodeType===3&&(x+=G.nodeValue.length),(se=G.firstChild)!==null;)H=G,G=se;for(;;){if(G===n)break t;if(H===o&&++B===d&&(E=x),H===p&&++V===a&&(O=x),(se=G.nextSibling)!==null)break;G=H,H=G.parentNode}G=se}o=E===-1||O===-1?null:{start:E,end:O}}else o=null}o=o||{start:0,end:0}}else o=null;for(ha={focusedElem:n,selectionRange:o},Oo=!1,oe=i;oe!==null;)if(i=oe,n=i.child,(i.subtreeFlags&1028)!==0&&n!==null)n.return=i,oe=n;else for(;oe!==null;){i=oe;try{var le=i.alternate;if((i.flags&1024)!==0)switch(i.tag){case 0:case 11:case 15:break;case 1:if(le!==null){var ue=le.memoizedProps,Qe=le.memoizedState,R=i.stateNode,b=R.getSnapshotBeforeUpdate(i.elementType===i.type?ue:Vt(i.type,ue),Qe);R.__reactInternalSnapshotBeforeUpdate=b}break;case 3:var I=i.stateNode.containerInfo;I.nodeType===1?I.textContent="":I.nodeType===9&&I.documentElement&&I.removeChild(I.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(r(163))}}catch(Y){We(i,i.return,Y)}if(n=i.sibling,n!==null){n.return=i.return,oe=n;break}oe=i.return}return le=Gp,Gp=!1,le}function Ps(n,i,o){var a=i.updateQueue;if(a=a!==null?a.lastEffect:null,a!==null){var d=a=a.next;do{if((d.tag&n)===n){var p=d.destroy;d.destroy=void 0,p!==void 0&&ec(i,o,p)}d=d.next}while(d!==a)}}function al(n,i){if(i=i.updateQueue,i=i!==null?i.lastEffect:null,i!==null){var o=i=i.next;do{if((o.tag&n)===n){var a=o.create;o.destroy=a()}o=o.next}while(o!==i)}}function tc(n){var i=n.ref;if(i!==null){var o=n.stateNode;switch(n.tag){case 5:n=o;break;default:n=o}typeof i=="function"?i(n):i.current=n}}function Jp(n){var i=n.alternate;i!==null&&(n.alternate=null,Jp(i)),n.child=null,n.deletions=null,n.sibling=null,n.tag===5&&(i=n.stateNode,i!==null&&(delete i[cn],delete i[xs],delete i[ya],delete i[S_],delete i[w_])),n.stateNode=null,n.return=null,n.dependencies=null,n.memoizedProps=null,n.memoizedState=null,n.pendingProps=null,n.stateNode=null,n.updateQueue=null}function Yp(n){return n.tag===5||n.tag===3||n.tag===4}function Xp(n){e:for(;;){for(;n.sibling===null;){if(n.return===null||Yp(n.return))return null;n=n.return}for(n.sibling.return=n.return,n=n.sibling;n.tag!==5&&n.tag!==6&&n.tag!==18;){if(n.flags&2||n.child===null||n.tag===4)continue e;n.child.return=n,n=n.child}if(!(n.flags&2))return n.stateNode}}function nc(n,i,o){var a=n.tag;if(a===5||a===6)n=n.stateNode,i?o.nodeType===8?o.parentNode.insertBefore(n,i):o.insertBefore(n,i):(o.nodeType===8?(i=o.parentNode,i.insertBefore(n,o)):(i=o,i.appendChild(n)),o=o._reactRootContainer,o!=null||i.onclick!==null||(i.onclick=$o));else if(a!==4&&(n=n.child,n!==null))for(nc(n,i,o),n=n.sibling;n!==null;)nc(n,i,o),n=n.sibling}function rc(n,i,o){var a=n.tag;if(a===5||a===6)n=n.stateNode,i?o.insertBefore(n,i):o.appendChild(n);else if(a!==4&&(n=n.child,n!==null))for(rc(n,i,o),n=n.sibling;n!==null;)rc(n,i,o),n=n.sibling}var ut=null,qt=!1;function Xn(n,i,o){for(o=o.child;o!==null;)Zp(n,i,o),o=o.sibling}function Zp(n,i,o){if(an&&typeof an.onCommitFiberUnmount=="function")try{an.onCommitFiberUnmount(wo,o)}catch{}switch(o.tag){case 5:mt||_i(o,i);case 6:var a=ut,d=qt;ut=null,Xn(n,i,o),ut=a,qt=d,ut!==null&&(qt?(n=ut,o=o.stateNode,n.nodeType===8?n.parentNode.removeChild(o):n.removeChild(o)):ut.removeChild(o.stateNode));break;case 18:ut!==null&&(qt?(n=ut,o=o.stateNode,n.nodeType===8?ma(n.parentNode,o):n.nodeType===1&&ma(n,o),us(n)):ma(ut,o.stateNode));break;case 4:a=ut,d=qt,ut=o.stateNode.containerInfo,qt=!0,Xn(n,i,o),ut=a,qt=d;break;case 0:case 11:case 14:case 15:if(!mt&&(a=o.updateQueue,a!==null&&(a=a.lastEffect,a!==null))){d=a=a.next;do{var p=d,x=p.destroy;p=p.tag,x!==void 0&&((p&2)!==0||(p&4)!==0)&&ec(o,i,x),d=d.next}while(d!==a)}Xn(n,i,o);break;case 1:if(!mt&&(_i(o,i),a=o.stateNode,typeof a.componentWillUnmount=="function"))try{a.props=o.memoizedProps,a.state=o.memoizedState,a.componentWillUnmount()}catch(E){We(o,i,E)}Xn(n,i,o);break;case 21:Xn(n,i,o);break;case 22:o.mode&1?(mt=(a=mt)||o.memoizedState!==null,Xn(n,i,o),mt=a):Xn(n,i,o);break;default:Xn(n,i,o)}}function eg(n){var i=n.updateQueue;if(i!==null){n.updateQueue=null;var o=n.stateNode;o===null&&(o=n.stateNode=new A_),i.forEach(function(a){var d=q_.bind(null,n,a);o.has(a)||(o.add(a),a.then(d,d))})}}function Gt(n,i){var o=i.deletions;if(o!==null)for(var a=0;ad&&(d=x),a&=~p}if(a=d,a=He()-a,a=(120>a?120:480>a?480:1080>a?1080:1920>a?1920:3e3>a?3e3:4320>a?4320:1960*B_(a/1960))-a,10n?16:n,er===null)var a=!1;else{if(n=er,er=null,pl=0,(Ne&6)!==0)throw Error(r(331));var d=Ne;for(Ne|=4,oe=n.current;oe!==null;){var p=oe,x=p.child;if((oe.flags&16)!==0){var E=p.deletions;if(E!==null){for(var O=0;OHe()-oc?Pr(n,0):sc|=o),Tt(n,i)}function hg(n,i){i===0&&((n.mode&1)===0?i=1:(i=ko,ko<<=1,(ko&130023424)===0&&(ko=4194304)));var o=xt();n=Tn(n,i),n!==null&&(rs(n,i,o),Tt(n,o))}function V_(n){var i=n.memoizedState,o=0;i!==null&&(o=i.retryLane),hg(n,o)}function q_(n,i){var o=0;switch(n.tag){case 13:var a=n.stateNode,d=n.memoizedState;d!==null&&(o=d.retryLane);break;case 19:a=n.stateNode;break;default:throw Error(r(314))}a!==null&&a.delete(i),hg(n,o)}var pg;pg=function(n,i,o){if(n!==null)if(n.memoizedProps!==i.pendingProps||Ct.current)Et=!0;else{if((n.lanes&o)===0&&(i.flags&128)===0)return Et=!1,F_(n,i,o);Et=(n.flags&131072)!==0}else Et=!1,$e&&(i.flags&1048576)!==0&&Vh(i,Qo,i.index);switch(i.lanes=0,i.tag){case 2:var a=i.type;ll(n,i),n=i.pendingProps;var d=fi(i,ht.current);yi(i,o),d=La(null,i,a,n,d,o);var p=Aa();return i.flags|=1,typeof d=="object"&&d!==null&&typeof d.render=="function"&&d.$$typeof===void 0?(i.tag=1,i.memoizedState=null,i.updateQueue=null,kt(a)?(p=!0,Ko(i)):p=!1,i.memoizedState=d.state!==null&&d.state!==void 0?d.state:null,Pa(i),d.updater=sl,i.stateNode=d,d._reactInternals=i,Wa(i,a,n,o),i=qa(null,i,a,!0,p,o)):(i.tag=0,$e&&p&&_a(i),vt(null,i,d,o),i=i.child),i;case 16:a=i.elementType;e:{switch(ll(n,i),n=i.pendingProps,d=a._init,a=d(a._payload),i.type=a,d=i.tag=J_(a),n=Vt(a,n),d){case 0:i=Va(null,i,a,n,o);break e;case 1:i=$p(null,i,a,n,o);break e;case 11:i=Fp(null,i,a,n,o);break e;case 14:i=Ip(null,i,a,Vt(a.type,n),o);break e}throw Error(r(306,a,""))}return i;case 0:return a=i.type,d=i.pendingProps,d=i.elementType===a?d:Vt(a,d),Va(n,i,a,d,o);case 1:return a=i.type,d=i.pendingProps,d=i.elementType===a?d:Vt(a,d),$p(n,i,a,d,o);case 3:e:{if(Bp(i),n===null)throw Error(r(387));a=i.pendingProps,p=i.memoizedState,d=p.element,np(n,i),Xo(i,a,null,o);var x=i.memoizedState;if(a=x.element,p.isDehydrated)if(p={element:a,isDehydrated:!1,cache:x.cache,pendingSuspenseBoundaries:x.pendingSuspenseBoundaries,transitions:x.transitions},i.updateQueue.baseState=p,i.memoizedState=p,i.flags&256){d=xi(Error(r(423)),i),i=Up(n,i,a,o,d);break e}else if(a!==d){d=xi(Error(r(424)),i),i=Up(n,i,a,o,d);break e}else for(Dt=Qn(i.stateNode.containerInfo.firstChild),Rt=i,$e=!0,Qt=null,o=ep(i,null,a,o),i.child=o;o;)o.flags=o.flags&-3|4096,o=o.sibling;else{if(pi(),a===d){i=Mn(n,i,o);break e}vt(n,i,a,o)}i=i.child}return i;case 5:return sp(i),n===null&&Ca(i),a=i.type,d=i.pendingProps,p=n!==null?n.memoizedProps:null,x=d.children,pa(a,d)?x=null:p!==null&&pa(a,p)&&(i.flags|=32),zp(n,i),vt(n,i,x,o),i.child;case 6:return n===null&&Ca(i),null;case 13:return Kp(n,i,o);case 4:return ba(i,i.stateNode.containerInfo),a=i.pendingProps,n===null?i.child=gi(i,null,a,o):vt(n,i,a,o),i.child;case 11:return a=i.type,d=i.pendingProps,d=i.elementType===a?d:Vt(a,d),Fp(n,i,a,d,o);case 7:return vt(n,i,i.pendingProps,o),i.child;case 8:return vt(n,i,i.pendingProps.children,o),i.child;case 12:return vt(n,i,i.pendingProps.children,o),i.child;case 10:e:{if(a=i.type._context,d=i.pendingProps,p=i.memoizedProps,x=d.value,Fe(Go,a._currentValue),a._currentValue=x,p!==null)if(Ht(p.value,x)){if(p.children===d.children&&!Ct.current){i=Mn(n,i,o);break e}}else for(p=i.child,p!==null&&(p.return=i);p!==null;){var E=p.dependencies;if(E!==null){x=p.child;for(var O=E.firstContext;O!==null;){if(O.context===a){if(p.tag===1){O=On(-1,o&-o),O.tag=2;var B=p.updateQueue;if(B!==null){B=B.shared;var V=B.pending;V===null?O.next=O:(O.next=V.next,V.next=O),B.pending=O}}p.lanes|=o,O=p.alternate,O!==null&&(O.lanes|=o),Oa(p.return,o,i),E.lanes|=o;break}O=O.next}}else if(p.tag===10)x=p.type===i.type?null:p.child;else if(p.tag===18){if(x=p.return,x===null)throw Error(r(341));x.lanes|=o,E=x.alternate,E!==null&&(E.lanes|=o),Oa(x,o,i),x=p.sibling}else x=p.child;if(x!==null)x.return=p;else for(x=p;x!==null;){if(x===i){x=null;break}if(p=x.sibling,p!==null){p.return=x.return,x=p;break}x=x.return}p=x}vt(n,i,d.children,o),i=i.child}return i;case 9:return d=i.type,a=i.pendingProps.children,yi(i,o),d=$t(d),a=a(d),i.flags|=1,vt(n,i,a,o),i.child;case 14:return a=i.type,d=Vt(a,i.pendingProps),d=Vt(a.type,d),Ip(n,i,a,d,o);case 15:return Lp(n,i,i.type,i.pendingProps,o);case 17:return a=i.type,d=i.pendingProps,d=i.elementType===a?d:Vt(a,d),ll(n,i),i.tag=1,kt(a)?(n=!0,Ko(i)):n=!1,yi(i,o),Op(i,a,d),Wa(i,a,d,o),qa(null,i,a,!0,n,o);case 19:return Hp(n,i,o);case 22:return Ap(n,i,o)}throw Error(r(156,i.tag))};function gg(n,i){return qd(n,i)}function G_(n,i,o,a){this.tag=n,this.key=o,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=i,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=a,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Kt(n,i,o,a){return new G_(n,i,o,a)}function pc(n){return n=n.prototype,!(!n||!n.isReactComponent)}function J_(n){if(typeof n=="function")return pc(n)?1:0;if(n!=null){if(n=n.$$typeof,n===ne)return 11;if(n===Se)return 14}return 2}function rr(n,i){var o=n.alternate;return o===null?(o=Kt(n.tag,i,n.key,n.mode),o.elementType=n.elementType,o.type=n.type,o.stateNode=n.stateNode,o.alternate=n,n.alternate=o):(o.pendingProps=i,o.type=n.type,o.flags=0,o.subtreeFlags=0,o.deletions=null),o.flags=n.flags&14680064,o.childLanes=n.childLanes,o.lanes=n.lanes,o.child=n.child,o.memoizedProps=n.memoizedProps,o.memoizedState=n.memoizedState,o.updateQueue=n.updateQueue,i=n.dependencies,o.dependencies=i===null?null:{lanes:i.lanes,firstContext:i.firstContext},o.sibling=n.sibling,o.index=n.index,o.ref=n.ref,o}function vl(n,i,o,a,d,p){var x=2;if(a=n,typeof n=="function")pc(n)&&(x=1);else if(typeof n=="string")x=5;else e:switch(n){case $:return Rr(o.children,d,p,i);case F:x=8,d|=8;break;case z:return n=Kt(12,o,i,d|2),n.elementType=z,n.lanes=p,n;case X:return n=Kt(13,o,i,d),n.elementType=X,n.lanes=p,n;case ae:return n=Kt(19,o,i,d),n.elementType=ae,n.lanes=p,n;case _e:return xl(o,d,p,i);default:if(typeof n=="object"&&n!==null)switch(n.$$typeof){case J:x=10;break e;case te:x=9;break e;case ne:x=11;break e;case Se:x=14;break e;case ye:x=16,a=null;break e}throw Error(r(130,n==null?n:typeof n,""))}return i=Kt(x,o,i,d),i.elementType=n,i.type=a,i.lanes=p,i}function Rr(n,i,o,a){return n=Kt(7,n,a,i),n.lanes=o,n}function xl(n,i,o,a){return n=Kt(22,n,a,i),n.elementType=_e,n.lanes=o,n.stateNode={isHidden:!1},n}function gc(n,i,o){return n=Kt(6,n,null,i),n.lanes=o,n}function mc(n,i,o){return i=Kt(4,n.children!==null?n.children:[],n.key,i),i.lanes=o,i.stateNode={containerInfo:n.containerInfo,pendingChildren:null,implementation:n.implementation},i}function Y_(n,i,o,a,d){this.tag=i,this.containerInfo=n,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Ku(0),this.expirationTimes=Ku(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Ku(0),this.identifierPrefix=a,this.onRecoverableError=d,this.mutableSourceEagerHydrationData=null}function yc(n,i,o,a,d,p,x,E,O){return n=new Y_(n,i,o,E,O),i===1?(i=1,p===!0&&(i|=8)):i=0,p=Kt(3,null,null,i),n.current=p,p.stateNode=n,p.memoizedState={element:a,isDehydrated:o,cache:null,transitions:null,pendingSuspenseBoundaries:null},Pa(p),n}function X_(n,i,o){var a=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(e){console.error(e)}}return t(),Cc.exports=fS(),Cc.exports}var Mg;function dS(){if(Mg)return Nl;Mg=1;var t=Ny();return Nl.createRoot=t.createRoot,Nl.hydrateRoot=t.hydrateRoot,Nl}var hS=dS();function pS(t,e){if(t instanceof RegExp)return{keys:!1,pattern:t};var r,s,l,u,c=[],f="",h=t.split("/");for(h[0]||h.shift();l=h.shift();)r=l[0],r==="*"?(c.push(r),f+=l[1]==="?"?"(?:/(.*))?":"/(.*)"):r===":"?(s=l.indexOf("?",1),u=l.indexOf(".",1),c.push(l.substring(1,~s?s:~u?u:l.length)),f+=~s&&!~u?"(?:/([^/]+?))?":"/([^/]+?)",~u&&(f+=(~s?"?":"")+"\\"+l.substring(u))):f+="/"+l;return{keys:c,pattern:new RegExp("^"+f+(e?"(?=$|/)":"/?$"),"i")}}var Nc={exports:{}},Tc={};/** * @license React * use-sync-external-store-shim.production.js * @@ -45,19 +45,19 @@ Error generating stack: `+p.message+` * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var Pg;function pS(){if(Pg)return Tc;Pg=1;var t=hu();function e(v,y){return v===y&&(v!==0||1/v===1/y)||v!==v&&y!==y}var r=typeof Object.is=="function"?Object.is:e,s=t.useState,l=t.useEffect,u=t.useLayoutEffect,c=t.useDebugValue;function f(v,y){var S=y(),_=s({inst:{value:S,getSnapshot:y}}),w=_[0].inst,C=_[1];return u(function(){w.value=S,w.getSnapshot=y,h(w)&&C({inst:w})},[v,S,y]),l(function(){return h(w)&&C({inst:w}),v(function(){h(w)&&C({inst:w})})},[v]),c(S),S}function h(v){var y=v.getSnapshot;v=v.value;try{var S=y();return!r(v,S)}catch{return!0}}function g(v,y){return y()}var m=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?g:f;return Tc.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:m,Tc}var bg;function gS(){return bg||(bg=1,Nc.exports=pS()),Nc.exports}var mS=gS();const yS=lS.useInsertionEffect,vS=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",xS=vS?A.useLayoutEffect:A.useEffect,_S=yS||xS,Ny=t=>{const e=A.useRef([t,(...r)=>e[0](...r)]).current;return _S(()=>{e[0]=t}),e[1]},SS="popstate",Af="pushState",zf="replaceState",wS="hashchange",Rg=[SS,Af,zf,wS],CS=t=>{for(const e of Rg)addEventListener(e,t);return()=>{for(const e of Rg)removeEventListener(e,t)}},Ty=(t,e)=>mS.useSyncExternalStore(CS,t,e),Dg=()=>location.search,kS=({ssrSearch:t}={})=>Ty(Dg,t!=null?()=>t:Dg),jg=()=>location.pathname,ES=({ssrPath:t}={})=>Ty(jg,t!=null?()=>t:jg),NS=(t,{replace:e=!1,state:r=null}={})=>history[e?zf:Af](r,"",t),TS=(t={})=>[ES(t),NS],Fg=Symbol.for("wouter_v3");if(typeof history<"u"&&typeof window[Fg]>"u"){for(const t of[Af,zf]){const e=history[t];history[t]=function(){const r=e.apply(this,arguments),s=new Event(t);return s.arguments=arguments,dispatchEvent(s),r}}Object.defineProperty(window,Fg,{value:!0})}const OS=(t,e)=>e.toLowerCase().indexOf(t.toLowerCase())?"~"+e:e.slice(t.length)||"/",Oy=(t="")=>t==="/"?"":t,MS=(t,e)=>t[0]==="~"?t.slice(1):Oy(e)+t,PS=(t="",e)=>OS(Ig(Oy(t)),Ig(e)),Ig=t=>{try{return decodeURI(t)}catch{return t}},My={hook:TS,searchHook:kS,parser:hS,base:"",ssrPath:void 0,ssrSearch:void 0,ssrContext:void 0,hrefs:t=>t,aroundNav:(t,e,r)=>t(e,r)},Py=A.createContext(My),$f=()=>A.useContext(Py),bS={};A.createContext(bS);const by=t=>{const[e,r]=t.hook(t);return[PS(t.base,e),Ny((s,l)=>t.aroundNav(r,MS(s,t.base),l))]},RS=()=>by($f()),DS=({children:t,...e})=>{const r=$f(),s=e.hook?My:r;let l=s;const[u,c=e.ssrSearch??""]=e.ssrPath?.split("?")??[];u&&(e.ssrSearch=c,e.ssrPath=u),e.hrefs=e.hrefs??e.hook?.hrefs,e.searchHook=e.searchHook??e.hook?.searchHook;let f=A.useRef({}),h=f.current,g=h;for(let m in s){const v=m==="base"?s[m]+(e[m]??""):e[m]??s[m];h===g&&v!==g[m]&&(f.current=g={...g}),g[m]=v,(v!==s[m]||v!==l[m])&&(l=g)}return A.createElement(Py.Provider,{value:l,children:t})};A.forwardRef((t,e)=>{const r=$f(),[s,l]=by(r),{to:u="",href:c=u,onClick:f,asChild:h,children:g,className:m,replace:v,state:y,transition:S,..._}=t,w=Ny(T=>{T.ctrlKey||T.metaKey||T.altKey||T.shiftKey||T.button!==0||(f?.(T),T.defaultPrevented||(T.preventDefault(),l(c,t)))}),C=r.hrefs(c[0]==="~"?c.slice(1):r.base+c,r);return h&&A.isValidElement(g)?A.cloneElement(g,{onClick:w,href:C}):A.createElement("a",{..._,onClick:w,href:C,className:m?.call?m(s===c):m,children:g,ref:e})});function Br(t){return!!t&&(t.kind==="room"||t.kind==="dm")}var Wi=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(t){return this.listeners.add(t),this.onSubscribe(),()=>{this.listeners.delete(t),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},jS=class extends Wi{#e;#t;#n;constructor(){super(),this.#n=t=>{if(typeof window<"u"&&window.addEventListener){const e=()=>t();return window.addEventListener("visibilitychange",e,!1),()=>{window.removeEventListener("visibilitychange",e)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(t){this.#n=t,this.#t?.(),this.#t=t(e=>{typeof e=="boolean"?this.setFocused(e):this.onFocus()})}setFocused(t){this.#e!==t&&(this.#e=t,this.onFocus())}onFocus(){const t=this.isFocused();this.listeners.forEach(e=>{e(t)})}isFocused(){return typeof this.#e=="boolean"?this.#e:globalThis.document?.visibilityState!=="hidden"}},Bf=new jS,FS={setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t),setInterval:(t,e)=>setInterval(t,e),clearInterval:t=>clearInterval(t)},IS=class{#e=FS;#t=!1;setTimeoutProvider(t){this.#e=t}setTimeout(t,e){return this.#e.setTimeout(t,e)}clearTimeout(t){this.#e.clearTimeout(t)}setInterval(t,e){return this.#e.setInterval(t,e)}clearInterval(t){this.#e.clearInterval(t)}},Ir=new IS;function LS(t){setTimeout(t,0)}var AS=typeof window>"u"||"Deno"in globalThis;function St(){}function zS(t,e){return typeof t=="function"?t(e):t}function Xc(t){return typeof t=="number"&&t>=0&&t!==1/0}function Ry(t,e){return Math.max(t+(e||0)-Date.now(),0)}function ur(t,e){return typeof t=="function"?t(e):t}function Ft(t,e){return typeof t=="function"?t(e):t}function Lg(t,e){const{type:r="all",exact:s,fetchStatus:l,predicate:u,queryKey:c,stale:f}=t;if(c){if(s){if(e.queryHash!==Uf(c,e.options))return!1}else if(!Qs(e.queryKey,c))return!1}if(r!=="all"){const h=e.isActive();if(r==="active"&&!h||r==="inactive"&&h)return!1}return!(typeof f=="boolean"&&e.isStale()!==f||l&&l!==e.state.fetchStatus||u&&!u(e))}function Ag(t,e){const{exact:r,status:s,predicate:l,mutationKey:u}=t;if(u){if(!e.options.mutationKey)return!1;if(r){if(Ur(e.options.mutationKey)!==Ur(u))return!1}else if(!Qs(e.options.mutationKey,u))return!1}return!(s&&e.state.status!==s||l&&!l(e))}function Uf(t,e){return(e?.queryKeyHashFn||Ur)(t)}function Ur(t){return JSON.stringify(t,(e,r)=>Zc(r)?Object.keys(r).sort().reduce((s,l)=>(s[l]=r[l],s),{}):r)}function Qs(t,e){return t===e?!0:typeof t!=typeof e?!1:t&&e&&typeof t=="object"&&typeof e=="object"?Object.keys(e).every(r=>Qs(t[r],e[r])):!1}var $S=Object.prototype.hasOwnProperty;function Dy(t,e,r=0){if(t===e)return t;if(r>500)return e;const s=zg(t)&&zg(e);if(!s&&!(Zc(t)&&Zc(e)))return e;const u=(s?t:Object.keys(t)).length,c=s?e:Object.keys(e),f=c.length,h=s?new Array(f):{};let g=0;for(let m=0;m{Ir.setTimeout(e,t)})}function ef(t,e,r){return typeof r.structuralSharing=="function"?r.structuralSharing(t,e):r.structuralSharing!==!1?Dy(t,e):e}function US(t,e,r=0){const s=[...t,e];return r&&s.length>r?s.slice(1):s}function KS(t,e,r=0){const s=[e,...t];return r&&s.length>r?s.slice(0,-1):s}var Kf=Symbol();function jy(t,e){return!t.queryFn&&e?.initialPromise?()=>e.initialPromise:!t.queryFn||t.queryFn===Kf?()=>Promise.reject(new Error(`Missing queryFn: '${t.queryHash}'`)):t.queryFn}function Wf(t,e){return typeof t=="function"?t(...e):!!t}function WS(t,e,r){let s=!1,l;return Object.defineProperty(t,"signal",{enumerable:!0,get:()=>(l??=e(),s||(s=!0,l.aborted?r():l.addEventListener("abort",r,{once:!0})),l)}),t}var Vs=(()=>{let t=()=>AS;return{isServer(){return t()},setIsServer(e){t=e}}})();function tf(){let t,e;const r=new Promise((l,u)=>{t=l,e=u});r.status="pending",r.catch(()=>{});function s(l){Object.assign(r,l),delete r.resolve,delete r.reject}return r.resolve=l=>{s({status:"fulfilled",value:l}),t(l)},r.reject=l=>{s({status:"rejected",reason:l}),e(l)},r}var HS=LS;function QS(){let t=[],e=0,r=f=>{f()},s=f=>{f()},l=HS;const u=f=>{e?t.push(f):l(()=>{r(f)})},c=()=>{const f=t;t=[],f.length&&l(()=>{s(()=>{f.forEach(h=>{r(h)})})})};return{batch:f=>{let h;e++;try{h=f()}finally{e--,e||c()}return h},batchCalls:f=>(...h)=>{u(()=>{f(...h)})},schedule:u,setNotifyFunction:f=>{r=f},setBatchNotifyFunction:f=>{s=f},setScheduler:f=>{l=f}}}var Xe=QS(),VS=class extends Wi{#e=!0;#t;#n;constructor(){super(),this.#n=t=>{if(typeof window<"u"&&window.addEventListener){const e=()=>t(!0),r=()=>t(!1);return window.addEventListener("online",e,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",r)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(t){this.#n=t,this.#t?.(),this.#t=t(this.setOnline.bind(this))}setOnline(t){this.#e!==t&&(this.#e=t,this.listeners.forEach(r=>{r(t)}))}isOnline(){return this.#e}},Yl=new VS;function qS(t){return Math.min(1e3*2**t,3e4)}function Fy(t){return(t??"online")==="online"?Yl.isOnline():!0}var nf=class extends Error{constructor(t){super("CancelledError"),this.revert=t?.revert,this.silent=t?.silent}};function Iy(t){let e=!1,r=0,s;const l=tf(),u=()=>l.status!=="pending",c=w=>{if(!u()){const C=new nf(w);y(C),t.onCancel?.(C)}},f=()=>{e=!0},h=()=>{e=!1},g=()=>Bf.isFocused()&&(t.networkMode==="always"||Yl.isOnline())&&t.canRun(),m=()=>Fy(t.networkMode)&&t.canRun(),v=w=>{u()||(s?.(),l.resolve(w))},y=w=>{u()||(s?.(),l.reject(w))},S=()=>new Promise(w=>{s=C=>{(u()||g())&&w(C)},t.onPause?.()}).then(()=>{s=void 0,u()||t.onContinue?.()}),_=()=>{if(u())return;let w;const C=r===0?t.initialPromise:void 0;try{w=C??t.fn()}catch(T){w=Promise.reject(T)}Promise.resolve(w).then(v).catch(T=>{if(u())return;const N=t.retry??(Vs.isServer()?0:3),M=t.retryDelay??qS,L=typeof M=="function"?M(r,T):M,j=N===!0||typeof N=="number"&&rg()?void 0:S()).then(()=>{e?y(T):_()})})};return{promise:l,status:()=>l.status,cancel:c,continue:()=>(s?.(),l),cancelRetry:f,continueRetry:h,canStart:m,start:()=>(m()?_():S().then(_),l)}}var Ly=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Xc(this.gcTime)&&(this.#e=Ir.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(t){this.gcTime=Math.max(this.gcTime||0,t??(Vs.isServer()?1/0:300*1e3))}clearGcTimeout(){this.#e!==void 0&&(Ir.clearTimeout(this.#e),this.#e=void 0)}};function GS(t){return{onFetch:(e,r)=>{const s=e.options,l=e.fetchOptions?.meta?.fetchMore?.direction,u=e.state.data?.pages||[],c=e.state.data?.pageParams||[];let f={pages:[],pageParams:[]},h=0;const g=async()=>{let m=!1;const v=_=>{WS(_,()=>e.signal,()=>m=!0)},y=jy(e.options,e.fetchOptions),S=async(_,w,C)=>{if(m)return Promise.reject(e.signal.reason);if(w==null&&_.pages.length)return Promise.resolve(_);const N=(()=>{const D={client:e.client,queryKey:e.queryKey,pageParam:w,direction:C?"backward":"forward",meta:e.options.meta};return v(D),D})(),M=await y(N),{maxPages:L}=e.options,j=C?KS:US;return{pages:j(_.pages,M,L),pageParams:j(_.pageParams,w,L)}};if(l&&u.length){const _=l==="backward",w=_?Ay:rf,C={pages:u,pageParams:c},T=w(s,C);f=await S(C,T,_)}else{const _=t??u.length;do{const w=h===0?c[0]??s.initialPageParam:rf(s,f);if(h>0&&w==null)break;f=await S(f,w),h++}while(h<_)}return f};e.options.persister?e.fetchFn=()=>e.options.persister?.(g,{client:e.client,queryKey:e.queryKey,meta:e.options.meta,signal:e.signal},r):e.fetchFn=g}}}function rf(t,{pages:e,pageParams:r}){const s=e.length-1;return e.length>0?t.getNextPageParam(e[s],e,r[s],r):void 0}function Ay(t,{pages:e,pageParams:r}){return e.length>0?t.getPreviousPageParam?.(e[0],e,r[0],r):void 0}function JS(t,e){return e?rf(t,e)!=null:!1}function YS(t,e){return!e||!t.getPreviousPageParam?!1:Ay(t,e)!=null}var XS=class extends Ly{#e;#t;#n;#r;#s;#i;#l;#o;constructor(t){super(),this.#o=!1,this.#l=t.defaultOptions,this.setOptions(t.options),this.observers=[],this.#s=t.client,this.#r=this.#s.getQueryCache(),this.queryKey=t.queryKey,this.queryHash=t.queryHash,this.#t=Ug(this.options),this.state=t.state??this.#t,this.scheduleGc()}get meta(){return this.options.meta}get queryType(){return this.#e}get promise(){return this.#i?.promise}setOptions(t){if(this.options={...this.#l,...t},t?._type&&(this.#e=t._type),this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){const e=Ug(this.options);e.data!==void 0&&(this.setState(Bg(e.data,e.dataUpdatedAt)),this.#t=e)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&this.#r.remove(this)}setData(t,e){const r=ef(this.state.data,t,this.options);return this.#u({data:r,type:"success",dataUpdatedAt:e?.updatedAt,manual:e?.manual}),r}setState(t){this.#u({type:"setState",state:t})}cancel(t){const e=this.#i?.promise;return this.#i?.cancel(t),e?e.then(St).catch(St):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}get resetState(){return this.#t}reset(){this.destroy(),this.setState(this.resetState)}isActive(){return this.observers.some(t=>Ft(t.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===Kf||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0?this.observers.some(t=>ur(t.options.staleTime,this)==="static"):!1}isStale(){return this.getObserversCount()>0?this.observers.some(t=>t.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(t=0){return this.state.data===void 0?!0:t==="static"?!1:this.state.isInvalidated?!0:!Ry(this.state.dataUpdatedAt,t)}onFocus(){this.observers.find(e=>e.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#i?.continue()}onOnline(){this.observers.find(e=>e.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#i?.continue()}addObserver(t){this.observers.includes(t)||(this.observers.push(t),this.clearGcTimeout(),this.#r.notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){this.observers.includes(t)&&(this.observers=this.observers.filter(e=>e!==t),this.observers.length||(this.#i&&(this.#o||this.#c()?this.#i.cancel({revert:!0}):this.#i.cancelRetry()),this.scheduleGc()),this.#r.notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.observers.length}#c(){return this.state.fetchStatus==="paused"&&this.state.status==="pending"}invalidate(){this.state.isInvalidated||this.#u({type:"invalidate"})}async fetch(t,e){if(this.state.fetchStatus!=="idle"&&this.#i?.status()!=="rejected"){if(this.state.data!==void 0&&e?.cancelRefetch)this.cancel({silent:!0});else if(this.#i)return this.#i.continueRetry(),this.#i.promise}if(t&&this.setOptions(t),!this.options.queryFn){const h=this.observers.find(g=>g.options.queryFn);h&&this.setOptions(h.options)}const r=new AbortController,s=h=>{Object.defineProperty(h,"signal",{enumerable:!0,get:()=>(this.#o=!0,r.signal)})},l=()=>{const h=jy(this.options,e),m=(()=>{const v={client:this.#s,queryKey:this.queryKey,meta:this.meta};return s(v),v})();return this.#o=!1,this.options.persister?this.options.persister(h,m,this):h(m)},c=(()=>{const h={fetchOptions:e,options:this.options,queryKey:this.queryKey,client:this.#s,state:this.state,fetchFn:l};return s(h),h})();(this.#e==="infinite"?GS(this.options.pages):this.options.behavior)?.onFetch(c,this),this.#n=this.state,(this.state.fetchStatus==="idle"||this.state.fetchMeta!==c.fetchOptions?.meta)&&this.#u({type:"fetch",meta:c.fetchOptions?.meta}),this.#i=Iy({initialPromise:e?.initialPromise,fn:c.fetchFn,onCancel:h=>{h instanceof nf&&h.revert&&this.setState({...this.#n,fetchStatus:"idle"}),r.abort()},onFail:(h,g)=>{this.#u({type:"failed",failureCount:h,error:g})},onPause:()=>{this.#u({type:"pause"})},onContinue:()=>{this.#u({type:"continue"})},retry:c.options.retry,retryDelay:c.options.retryDelay,networkMode:c.options.networkMode,canRun:()=>!0});try{const h=await this.#i.start();if(h===void 0)throw new Error(`${this.queryHash} data is undefined`);return this.setData(h),this.#r.config.onSuccess?.(h,this),this.#r.config.onSettled?.(h,this.state.error,this),h}catch(h){if(h instanceof nf){if(h.silent)return this.#i.promise;if(h.revert){if(this.state.data===void 0)throw h;return this.state.data}}throw this.#u({type:"error",error:h}),this.#r.config.onError?.(h,this),this.#r.config.onSettled?.(this.state.data,h,this),h}finally{this.scheduleGc()}}#u(t){const e=r=>{switch(t.type){case"failed":return{...r,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...r,fetchStatus:"paused"};case"continue":return{...r,fetchStatus:"fetching"};case"fetch":return{...r,...zy(r.data,this.options),fetchMeta:t.meta??null};case"success":const s={...r,...Bg(t.data,t.dataUpdatedAt),dataUpdateCount:r.dataUpdateCount+1,...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return this.#n=t.manual?s:void 0,s;case"error":const l=t.error;return{...r,error:l,errorUpdateCount:r.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:r.fetchFailureCount+1,fetchFailureReason:l,fetchStatus:"idle",status:"error",isInvalidated:!0};case"invalidate":return{...r,isInvalidated:!0};case"setState":return{...r,...t.state}}};this.state=e(this.state),Xe.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),this.#r.notify({query:this,type:"updated",action:t})})}};function zy(t,e){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:Fy(e.networkMode)?"fetching":"paused",...t===void 0&&{error:null,status:"pending"}}}function Bg(t,e){return{data:t,dataUpdatedAt:e??Date.now(),error:null,isInvalidated:!1,status:"success"}}function Ug(t){const e=typeof t.initialData=="function"?t.initialData():t.initialData,r=e!==void 0,s=r?typeof t.initialDataUpdatedAt=="function"?t.initialDataUpdatedAt():t.initialDataUpdatedAt:0;return{data:e,dataUpdateCount:0,dataUpdatedAt:r?s??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:r?"success":"pending",fetchStatus:"idle"}}var $y=class extends Wi{constructor(t,e){super(),this.options=e,this.#e=t,this.#o=null,this.#l=tf(),this.bindMethods(),this.setOptions(e)}#e;#t=void 0;#n=void 0;#r=void 0;#s;#i;#l;#o;#c;#u;#p;#f;#d;#a;#g=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#t.addObserver(this),Kg(this.#t,this.options)?this.#h():this.updateResult(),this.#x())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return sf(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return sf(this.#t,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#_(),this.#S(),this.#t.removeObserver(this)}setOptions(t){const e=this.options,r=this.#t;if(this.options=this.#e.defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof Ft(this.options.enabled,this.#t)!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");this.#w(),this.#t.setOptions(this.options),e._defaulted&&!Jl(this.options,e)&&this.#e.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#t,observer:this});const s=this.hasListeners();s&&Wg(this.#t,r,this.options,e)&&this.#h(),this.updateResult(),s&&(this.#t!==r||Ft(this.options.enabled,this.#t)!==Ft(e.enabled,this.#t)||ur(this.options.staleTime,this.#t)!==ur(e.staleTime,this.#t))&&this.#m();const l=this.#y();s&&(this.#t!==r||Ft(this.options.enabled,this.#t)!==Ft(e.enabled,this.#t)||l!==this.#a)&&this.#v(l)}getOptimisticResult(t){const e=this.#e.getQueryCache().build(this.#e,t),r=this.createResult(e,t);return ew(this,r)&&(this.#r=r,this.#i=this.options,this.#s=this.#t.state),r}getCurrentResult(){return this.#r}trackResult(t,e){return new Proxy(t,{get:(r,s)=>(this.trackProp(s),e?.(s),s==="promise"&&(this.trackProp("data"),!this.options.experimental_prefetchInRender&&this.#l.status==="pending"&&this.#l.reject(new Error("experimental_prefetchInRender feature flag is not enabled"))),Reflect.get(r,s))})}trackProp(t){this.#g.add(t)}getCurrentQuery(){return this.#t}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const e=this.#e.defaultQueryOptions(t),r=this.#e.getQueryCache().build(this.#e,e);return r.fetch().then(()=>this.createResult(r,e))}fetch(t){return this.#h({...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#r))}#h(t){this.#w();let e=this.#t.fetch(this.options,t);return t?.throwOnError||(e=e.catch(St)),e}#m(){this.#_();const t=ur(this.options.staleTime,this.#t);if(Vs.isServer()||this.#r.isStale||!Xc(t))return;const r=Ry(this.#r.dataUpdatedAt,t)+1;this.#f=Ir.setTimeout(()=>{this.#r.isStale||this.updateResult()},r)}#y(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(this.#t):this.options.refetchInterval)??!1}#v(t){this.#S(),this.#a=t,!(Vs.isServer()||Ft(this.options.enabled,this.#t)===!1||!Xc(this.#a)||this.#a===0)&&(this.#d=Ir.setInterval(()=>{(this.options.refetchIntervalInBackground||Bf.isFocused())&&this.#h()},this.#a))}#x(){this.#m(),this.#v(this.#y())}#_(){this.#f!==void 0&&(Ir.clearTimeout(this.#f),this.#f=void 0)}#S(){this.#d!==void 0&&(Ir.clearInterval(this.#d),this.#d=void 0)}createResult(t,e){const r=this.#t,s=this.options,l=this.#r,u=this.#s,c=this.#i,h=t!==r?t.state:this.#n,{state:g}=t;let m={...g},v=!1,y;if(e._optimisticResults){const F=this.hasListeners(),z=!F&&Kg(t,e),J=F&&Wg(t,r,e,s);(z||J)&&(m={...m,...zy(g.data,t.options)}),e._optimisticResults==="isRestoring"&&(m.fetchStatus="idle")}let{error:S,errorUpdatedAt:_,status:w}=m;y=m.data;let C=!1;if(e.placeholderData!==void 0&&y===void 0&&w==="pending"){let F;l?.isPlaceholderData&&e.placeholderData===c?.placeholderData?(F=l.data,C=!0):F=typeof e.placeholderData=="function"?e.placeholderData(this.#p?.state.data,this.#p):e.placeholderData,F!==void 0&&(w="success",y=ef(l?.data,F,e),v=!0)}if(e.select&&y!==void 0&&!C)if(l&&y===u?.data&&e.select===this.#c)y=this.#u;else try{this.#c=e.select,y=e.select(y),y=ef(l?.data,y,e),this.#u=y,this.#o=null}catch(F){this.#o=F}this.#o&&(S=this.#o,y=this.#u,_=Date.now(),w="error");const T=m.fetchStatus==="fetching",N=w==="pending",M=w==="error",L=N&&T,j=y!==void 0,$={status:w,fetchStatus:m.fetchStatus,isPending:N,isSuccess:w==="success",isError:M,isInitialLoading:L,isLoading:L,data:y,dataUpdatedAt:m.dataUpdatedAt,error:S,errorUpdatedAt:_,failureCount:m.fetchFailureCount,failureReason:m.fetchFailureReason,errorUpdateCount:m.errorUpdateCount,isFetched:t.isFetched(),isFetchedAfterMount:m.dataUpdateCount>h.dataUpdateCount||m.errorUpdateCount>h.errorUpdateCount,isFetching:T,isRefetching:T&&!N,isLoadingError:M&&!j,isPaused:m.fetchStatus==="paused",isPlaceholderData:v,isRefetchError:M&&j,isStale:Hf(t,e),refetch:this.refetch,promise:this.#l,isEnabled:Ft(e.enabled,t)!==!1};if(this.options.experimental_prefetchInRender){const F=$.data!==void 0,z=$.status==="error"&&!F,J=X=>{z?X.reject($.error):F&&X.resolve($.data)},te=()=>{const X=this.#l=$.promise=tf();J(X)},ne=this.#l;switch(ne.status){case"pending":t.queryHash===r.queryHash&&J(ne);break;case"fulfilled":(z||$.data!==ne.value)&&te();break;case"rejected":(!z||$.error!==ne.reason)&&te();break}}return $}updateResult(){const t=this.#r,e=this.createResult(this.#t,this.options);if(this.#s=this.#t.state,this.#i=this.options,this.#s.data!==void 0&&(this.#p=this.#t),Jl(e,t))return;this.#r=e;const r=()=>{if(!t)return!0;const{notifyOnChangeProps:s}=this.options,l=typeof s=="function"?s():s;if(l==="all"||!l&&!this.#g.size)return!0;const u=new Set(l??this.#g);return this.options.throwOnError&&u.add("error"),Object.keys(this.#r).some(c=>{const f=c;return this.#r[f]!==t[f]&&u.has(f)})};this.#C({listeners:r()})}#w(){const t=this.#e.getQueryCache().build(this.#e,this.options);if(t===this.#t)return;const e=this.#t;this.#t=t,this.#n=t.state,this.hasListeners()&&(e?.removeObserver(this),t.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#x()}#C(t){Xe.batch(()=>{t.listeners&&this.listeners.forEach(e=>{e(this.#r)}),this.#e.getQueryCache().notify({query:this.#t,type:"observerResultsUpdated"})})}};function ZS(t,e){return Ft(e.enabled,t)!==!1&&t.state.data===void 0&&!(t.state.status==="error"&&Ft(e.retryOnMount,t)===!1)}function Kg(t,e){return ZS(t,e)||t.state.data!==void 0&&sf(t,e,e.refetchOnMount)}function sf(t,e,r){if(Ft(e.enabled,t)!==!1&&ur(e.staleTime,t)!=="static"){const s=typeof r=="function"?r(t):r;return s==="always"||s!==!1&&Hf(t,e)}return!1}function Wg(t,e,r,s){return(t!==e||Ft(s.enabled,t)===!1)&&(!r.suspense||t.state.status!=="error")&&Hf(t,r)}function Hf(t,e){return Ft(e.enabled,t)!==!1&&t.isStaleByTime(ur(e.staleTime,t))}function ew(t,e){return!Jl(t.getCurrentResult(),e)}var tw=class extends $y{constructor(t,e){super(t,e)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(t){t._type="infinite",super.setOptions(t)}getOptimisticResult(t){return t._type="infinite",super.getOptimisticResult(t)}fetchNextPage(t){return this.fetch({...t,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(t){return this.fetch({...t,meta:{fetchMore:{direction:"backward"}}})}createResult(t,e){const{state:r}=t,s=super.createResult(t,e),{isFetching:l,isRefetching:u,isError:c,isRefetchError:f}=s,h=r.fetchMeta?.fetchMore?.direction,g=c&&h==="forward",m=l&&h==="forward",v=c&&h==="backward",y=l&&h==="backward";return{...s,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:JS(e,r.data),hasPreviousPage:YS(e,r.data),isFetchNextPageError:g,isFetchingNextPage:m,isFetchPreviousPageError:v,isFetchingPreviousPage:y,isRefetchError:f&&!g&&!v,isRefetching:u&&!m&&!y}}},nw=class extends Ly{#e;#t;#n;#r;constructor(t){super(),this.#e=t.client,this.mutationId=t.mutationId,this.#n=t.mutationCache,this.#t=[],this.state=t.state||By(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){this.#t.includes(t)||(this.#t.push(t),this.clearGcTimeout(),this.#n.notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){this.#t=this.#t.filter(e=>e!==t),this.scheduleGc(),this.#n.notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){this.#t.length||(this.state.status==="pending"?this.scheduleGc():this.#n.remove(this))}continue(){return this.#r?.continue()??this.execute(this.state.variables)}async execute(t){const e=()=>{this.#s({type:"continue"})},r={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#r=Iy({fn:()=>this.options.mutationFn?this.options.mutationFn(t,r):Promise.reject(new Error("No mutationFn found")),onFail:(u,c)=>{this.#s({type:"failed",failureCount:u,error:c})},onPause:()=>{this.#s({type:"pause"})},onContinue:e,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)});const s=this.state.status==="pending",l=!this.#r.canStart();try{if(s)e();else{this.#s({type:"pending",variables:t,isPaused:l}),this.#n.config.onMutate&&await this.#n.config.onMutate(t,this,r);const c=await this.options.onMutate?.(t,r);c!==this.state.context&&this.#s({type:"pending",context:c,variables:t,isPaused:l})}const u=await this.#r.start();return await this.#n.config.onSuccess?.(u,t,this.state.context,this,r),await this.options.onSuccess?.(u,t,this.state.context,r),await this.#n.config.onSettled?.(u,null,this.state.variables,this.state.context,this,r),await this.options.onSettled?.(u,null,t,this.state.context,r),this.#s({type:"success",data:u}),u}catch(u){try{await this.#n.config.onError?.(u,t,this.state.context,this,r)}catch(c){Promise.reject(c)}try{await this.options.onError?.(u,t,this.state.context,r)}catch(c){Promise.reject(c)}try{await this.#n.config.onSettled?.(void 0,u,this.state.variables,this.state.context,this,r)}catch(c){Promise.reject(c)}try{await this.options.onSettled?.(void 0,u,t,this.state.context,r)}catch(c){Promise.reject(c)}throw this.#s({type:"error",error:u}),u}finally{this.#n.runNext(this)}}#s(t){const e=r=>{switch(t.type){case"failed":return{...r,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:t.isPaused,status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...r,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:t.error,failureCount:r.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=e(this.state),Xe.batch(()=>{this.#t.forEach(r=>{r.onMutationUpdate(t)}),this.#n.notify({mutation:this,type:"updated",action:t})})}};function By(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var rw=class extends Wi{constructor(t={}){super(),this.config=t,this.#e=new Set,this.#t=new Map,this.#n=0}#e;#t;#n;build(t,e,r){const s=new nw({client:t,mutationCache:this,mutationId:++this.#n,options:t.defaultMutationOptions(e),state:r});return this.add(s),s}add(t){this.#e.add(t);const e=Tl(t);if(typeof e=="string"){const r=this.#t.get(e);r?r.push(t):this.#t.set(e,[t])}this.notify({type:"added",mutation:t})}remove(t){if(this.#e.delete(t)){const e=Tl(t);if(typeof e=="string"){const r=this.#t.get(e);if(r)if(r.length>1){const s=r.indexOf(t);s!==-1&&r.splice(s,1)}else r[0]===t&&this.#t.delete(e)}}this.notify({type:"removed",mutation:t})}canRun(t){const e=Tl(t);if(typeof e=="string"){const s=this.#t.get(e)?.find(l=>l.state.status==="pending");return!s||s===t}else return!0}runNext(t){const e=Tl(t);return typeof e=="string"?this.#t.get(e)?.find(s=>s!==t&&s.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){Xe.batch(()=>{this.#e.forEach(t=>{this.notify({type:"removed",mutation:t})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(t){const e={exact:!0,...t};return this.getAll().find(r=>Ag(e,r))}findAll(t={}){return this.getAll().filter(e=>Ag(t,e))}notify(t){Xe.batch(()=>{this.listeners.forEach(e=>{e(t)})})}resumePausedMutations(){const t=this.getAll().filter(e=>e.state.isPaused);return Xe.batch(()=>Promise.all(t.map(e=>e.continue().catch(St))))}};function Tl(t){return t.options.scope?.id}var iw=class extends Wi{#e;#t=void 0;#n;#r;constructor(e,r){super(),this.#e=e,this.setOptions(r),this.bindMethods(),this.#s()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(e){const r=this.options;this.options=this.#e.defaultMutationOptions(e),Jl(this.options,r)||this.#e.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#n,observer:this}),r?.mutationKey&&this.options.mutationKey&&Ur(r.mutationKey)!==Ur(this.options.mutationKey)?this.reset():this.#n?.state.status==="pending"&&this.#n.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#n?.removeObserver(this)}onMutationUpdate(e){this.#s(),this.#i(e)}getCurrentResult(){return this.#t}reset(){this.#n?.removeObserver(this),this.#n=void 0,this.#s(),this.#i()}mutate(e,r){return this.#r=r,this.#n?.removeObserver(this),this.#n=this.#e.getMutationCache().build(this.#e,this.options),this.#n.addObserver(this),this.#n.execute(e)}#s(){const e=this.#n?.state??By();this.#t={...e,isPending:e.status==="pending",isSuccess:e.status==="success",isError:e.status==="error",isIdle:e.status==="idle",mutate:this.mutate,reset:this.reset}}#i(e){Xe.batch(()=>{if(this.#r&&this.hasListeners()){const r=this.#t.variables,s=this.#t.context,l={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};if(e?.type==="success"){try{this.#r.onSuccess?.(e.data,r,s,l)}catch(u){Promise.reject(u)}try{this.#r.onSettled?.(e.data,null,r,s,l)}catch(u){Promise.reject(u)}}else if(e?.type==="error"){try{this.#r.onError?.(e.error,r,s,l)}catch(u){Promise.reject(u)}try{this.#r.onSettled?.(void 0,e.error,r,s,l)}catch(u){Promise.reject(u)}}}this.listeners.forEach(r=>{r(this.#t)})})}},sw=class extends Wi{constructor(t={}){super(),this.config=t,this.#e=new Map}#e;build(t,e,r){const s=e.queryKey,l=e.queryHash??Uf(s,e);let u=this.get(l);return u||(u=new XS({client:t,queryKey:s,queryHash:l,options:t.defaultQueryOptions(e),state:r,defaultOptions:t.getQueryDefaults(s)}),this.add(u)),u}add(t){this.#e.has(t.queryHash)||(this.#e.set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const e=this.#e.get(t.queryHash);e&&(t.destroy(),e===t&&this.#e.delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){Xe.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return this.#e.get(t)}getAll(){return[...this.#e.values()]}find(t){const e={exact:!0,...t};return this.getAll().find(r=>Lg(e,r))}findAll(t={}){const e=this.getAll();return Object.keys(t).length>0?e.filter(r=>Lg(t,r)):e}notify(t){Xe.batch(()=>{this.listeners.forEach(e=>{e(t)})})}onFocus(){Xe.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){Xe.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},ow=class{#e;#t;#n;#r;#s;#i;#l;#o;constructor(t={}){this.#e=t.queryCache||new sw,this.#t=t.mutationCache||new rw,this.#n=t.defaultOptions||{},this.#r=new Map,this.#s=new Map,this.#i=0}mount(){this.#i++,this.#i===1&&(this.#l=Bf.subscribe(async t=>{t&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#o=Yl.subscribe(async t=>{t&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#i--,this.#i===0&&(this.#l?.(),this.#l=void 0,this.#o?.(),this.#o=void 0)}isFetching(t){return this.#e.findAll({...t,fetchStatus:"fetching"}).length}isMutating(t){return this.#t.findAll({...t,status:"pending"}).length}getQueryData(t){const e=this.defaultQueryOptions({queryKey:t});return this.#e.get(e.queryHash)?.state.data}ensureQueryData(t){const e=this.defaultQueryOptions(t),r=this.#e.build(this,e),s=r.state.data;return s===void 0?this.fetchQuery(t):(t.revalidateIfStale&&r.isStaleByTime(ur(e.staleTime,r))&&this.prefetchQuery(e),Promise.resolve(s))}getQueriesData(t){return this.#e.findAll(t).map(({queryKey:e,state:r})=>{const s=r.data;return[e,s]})}setQueryData(t,e,r){const s=this.defaultQueryOptions({queryKey:t}),u=this.#e.get(s.queryHash)?.state.data,c=zS(e,u);if(c!==void 0)return this.#e.build(this,s).setData(c,{...r,manual:!0})}setQueriesData(t,e,r){return Xe.batch(()=>this.#e.findAll(t).map(({queryKey:s})=>[s,this.setQueryData(s,e,r)]))}getQueryState(t){const e=this.defaultQueryOptions({queryKey:t});return this.#e.get(e.queryHash)?.state}removeQueries(t){const e=this.#e;Xe.batch(()=>{e.findAll(t).forEach(r=>{e.remove(r)})})}resetQueries(t,e){const r=this.#e;return Xe.batch(()=>(r.findAll(t).forEach(s=>{s.reset()}),this.refetchQueries({type:"active",...t},e)))}cancelQueries(t,e={}){const r={revert:!0,...e},s=Xe.batch(()=>this.#e.findAll(t).map(l=>l.cancel(r)));return Promise.all(s).then(St).catch(St)}invalidateQueries(t,e={}){return Xe.batch(()=>(this.#e.findAll(t).forEach(r=>{r.invalidate()}),t?.refetchType==="none"?Promise.resolve():this.refetchQueries({...t,type:t?.refetchType??t?.type??"active"},e)))}refetchQueries(t,e={}){const r={...e,cancelRefetch:e.cancelRefetch??!0},s=Xe.batch(()=>this.#e.findAll(t).filter(l=>!l.isDisabled()&&!l.isStatic()).map(l=>{let u=l.fetch(void 0,r);return r.throwOnError||(u=u.catch(St)),l.state.fetchStatus==="paused"?Promise.resolve():u}));return Promise.all(s).then(St)}fetchQuery(t){const e=this.defaultQueryOptions(t);e.retry===void 0&&(e.retry=!1);const r=this.#e.build(this,e);return r.isStaleByTime(ur(e.staleTime,r))?r.fetch(e):Promise.resolve(r.state.data)}prefetchQuery(t){return this.fetchQuery(t).then(St).catch(St)}fetchInfiniteQuery(t){return t._type="infinite",this.fetchQuery(t)}prefetchInfiniteQuery(t){return this.fetchInfiniteQuery(t).then(St).catch(St)}ensureInfiniteQueryData(t){return t._type="infinite",this.ensureQueryData(t)}resumePausedMutations(){return Yl.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(t){this.#n=t}setQueryDefaults(t,e){this.#r.set(Ur(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){const e=[...this.#r.values()],r={};return e.forEach(s=>{Qs(t,s.queryKey)&&Object.assign(r,s.defaultOptions)}),r}setMutationDefaults(t,e){this.#s.set(Ur(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){const e=[...this.#s.values()],r={};return e.forEach(s=>{Qs(t,s.mutationKey)&&Object.assign(r,s.defaultOptions)}),r}defaultQueryOptions(t){if(t._defaulted)return t;const e={...this.#n.queries,...this.getQueryDefaults(t.queryKey),...t,_defaulted:!0};return e.queryHash||(e.queryHash=Uf(e.queryKey,e)),e.refetchOnReconnect===void 0&&(e.refetchOnReconnect=e.networkMode!=="always"),e.throwOnError===void 0&&(e.throwOnError=!!e.suspense),!e.networkMode&&e.persister&&(e.networkMode="offlineFirst"),e.queryFn===Kf&&(e.enabled=!1),e}defaultMutationOptions(t){return t?._defaulted?t:{...this.#n.mutations,...t?.mutationKey&&this.getMutationDefaults(t.mutationKey),...t,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},Uy=A.createContext(void 0),Qf=t=>{const e=A.useContext(Uy);if(!e)throw new Error("No QueryClient set, use QueryClientProvider to set one");return e},lw=({client:t,children:e})=>(A.useEffect(()=>(t.mount(),()=>{t.unmount()}),[t]),k.jsx(Uy.Provider,{value:t,children:e})),Ky=A.createContext(!1),uw=()=>A.useContext(Ky);Ky.Provider;function aw(){let t=!1;return{clearReset:()=>{t=!1},reset:()=>{t=!0},isReset:()=>t}}var cw=A.createContext(aw()),fw=()=>A.useContext(cw),dw=(t,e,r)=>{const s=r?.state.error&&typeof t.throwOnError=="function"?Wf(t.throwOnError,[r.state.error,r]):t.throwOnError;(t.suspense||t.experimental_prefetchInRender||s)&&(e.isReset()||(t.retryOnMount=!1))},hw=t=>{A.useEffect(()=>{t.clearReset()},[t])},pw=({result:t,errorResetBoundary:e,throwOnError:r,query:s,suspense:l})=>t.isError&&!e.isReset()&&!t.isFetching&&s&&(l&&t.data===void 0||Wf(r,[t.error,s])),gw=t=>{if(t.suspense){const r=l=>l==="static"?l:Math.max(l??1e3,1e3),s=t.staleTime;t.staleTime=typeof s=="function"?(...l)=>r(s(...l)):r(s),typeof t.gcTime=="number"&&(t.gcTime=Math.max(t.gcTime,1e3))}},mw=(t,e)=>t.isLoading&&t.isFetching&&!e,yw=(t,e)=>t?.suspense&&e.isPending,Hg=(t,e,r)=>e.fetchOptimistic(t).catch(()=>{r.clearReset()});function Wy(t,e,r){const s=uw(),l=fw(),u=Qf(),c=u.defaultQueryOptions(t);u.getDefaultOptions().queries?._experimental_beforeQuery?.(c);const f=u.getQueryCache().get(c.queryHash);c._optimisticResults=s?"isRestoring":"optimistic",gw(c),dw(c,l,f),hw(l);const h=!u.getQueryCache().get(c.queryHash),[g]=A.useState(()=>new e(u,c)),m=g.getOptimisticResult(c),v=!s&&t.subscribed!==!1;if(A.useSyncExternalStore(A.useCallback(y=>{const S=v?g.subscribe(Xe.batchCalls(y)):St;return g.updateResult(),S},[g,v]),()=>g.getCurrentResult(),()=>g.getCurrentResult()),A.useEffect(()=>{g.setOptions(c)},[c,g]),yw(c,m))throw Hg(c,g,l);if(pw({result:m,errorResetBoundary:l,throwOnError:c.throwOnError,query:f,suspense:c.suspense}))throw m.error;return u.getDefaultOptions().queries?._experimental_afterQuery?.(c,m),c.experimental_prefetchInRender&&!Vs.isServer()&&mw(m,s)&&(h?Hg(c,g,l):f?.promise)?.catch(St).finally(()=>{g.updateResult()}),c.notifyOnChangeProps?m:g.trackResult(m)}function gr(t,e){return Wy(t,$y)}function vw(t,e){const r=Qf(),[s]=A.useState(()=>new iw(r,t));A.useEffect(()=>{s.setOptions(t)},[s,t]);const l=A.useSyncExternalStore(A.useCallback(c=>s.subscribe(Xe.batchCalls(c)),[s]),()=>s.getCurrentResult(),()=>s.getCurrentResult()),u=A.useCallback((c,f)=>{s.mutate(c,f).catch(St)},[s]);if(l.error&&Wf(s.options.throwOnError,[l.error]))throw l.error;return{...l,mutate:u,mutateAsync:l.mutate}}function xw(t,e){return Wy(t,tw)}function _w({children:t}){const e=A.useMemo(()=>new ow({defaultOptions:{queries:{refetchOnWindowFocus:!1,staleTime:5e3,retry:1}}}),[]);return k.jsx(lw,{client:e,children:t})}const Sw=/^\/room\/(.+)$/,ww=/^\/dm\/(.+)$/,Cw=/^\/agent\/(.+)$/,kw=/^\/pairing\/(.+)$/;function Ew(t){if(t==="/events")return{kind:"events"};const e=t.match(Sw);if(e)return{kind:"room",id:decodeURIComponent(e[1])};const r=t.match(ww);if(r)return{kind:"dm",id:decodeURIComponent(r[1])};const s=t.match(Cw);if(s)return{kind:"agent",id:decodeURIComponent(s[1])};const l=t.match(kw);return l?{kind:"pairing",id:decodeURIComponent(l[1])}:null}function Nw(t){return t?t.kind==="events"?"/events":`/${t.kind}/${encodeURIComponent(t.id)}`:"/"}function Tw({children:t}){return k.jsx(k.Fragment,{children:t})}function wt(){const[t,e]=RS(),r=A.useMemo(()=>Ew(t),[t]),s=A.useCallback(l=>{e(Nw(l))},[e]);return{selected:r,select:s}}const of=new Set;function Hy(t){for(const e of of)e(t)}function Ow(t){return of.add(t),()=>{of.delete(t)}}const Oc=Number.parseInt("",10),Qg=Number.isFinite(Oc)&&Oc>0?Oc:0;class Qy extends Error{status;code;constructor(e,r,s){super(r),this.name="ApiError",this.status=e,this.code=s}}async function pn(t){await Mw();const e=performance.now(),r=await fetch(t);if(Hy(Math.round(performance.now()-e)),!r.ok)throw new Error(`${t} returned ${r.status}`);return await r.json()}function Mw(){return Qg<=0?Promise.resolve():new Promise(t=>window.setTimeout(t,Qg))}function Vg(t){return{...t,messages:t.messages??[]}}function Mc(t,e){if(t===null||typeof t!="object")return;const r=t[e];return typeof r=="string"&&r.trim()!==""?r:void 0}async function Pw(t,e){if((t.headers.get("content-type")??"").includes("application/json")){const l=await t.json().catch(()=>null);return{message:Mc(l,"error")??Mc(l,"message")??e,code:Mc(l,"code")}}return{message:(await t.text().catch(()=>"")).trim()||e}}const sn={network:()=>pn("/v1/network"),rooms:()=>pn("/v1/rooms").then(t=>t.rooms??[]),dms:()=>pn("/v1/dms").then(t=>t.dms??[]),agents:()=>pn("/v1/agents").then(t=>t.agents??[]),pairings:()=>pn("/v1/pairings").then(t=>t.pairings??[]),pairingNetwork:t=>pn(`/v1/pairings/${encodeURIComponent(t)}/network`),pairingRooms:t=>pn(`/v1/pairings/${encodeURIComponent(t)}/rooms`).then(e=>e.rooms??[]),pairingAgents:t=>pn(`/v1/pairings/${encodeURIComponent(t)}/agents`).then(e=>e.agents??[]),roomMessages:(t,e)=>pn(`/v1/rooms/${encodeURIComponent(t)}/messages?limit=50${e?`&before=${encodeURIComponent(e)}`:""}`).then(Vg),dmMessages:(t,e)=>pn(`/v1/dms/${encodeURIComponent(t)}/messages?limit=50${e?`&before=${encodeURIComponent(e)}`:""}`).then(Vg),sendMessage:async t=>{const e=performance.now(),r=await fetch("/v1/messages",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(Hy(Math.round(performance.now()-e)),!r.ok){const s=await Pw(r,`send failed (${r.status})`);throw new Qy(r.status,s.message,s.code)}return r.json()}};function wn(){return gr({queryKey:["network"],queryFn:sn.network})}const Vy=A.createContext(null),bw=1e3;function Rw({children:t}){const e=Qf(),{data:r,error:s}=wn(),[l,u]=A.useState("connecting"),[c,f]=A.useState(),[h,g]=A.useState([]),m=r?.capabilities?.event_stream,v=!!r,y=s instanceof Error?s.message:s?String(s):void 0;A.useEffect(()=>{if(y){u("error"),f(y);return}if(!v){u("connecting"),f(void 0);return}if(m!=="sse"){u("unsupported"),f(Dw(m));return}u("connecting"),f(void 0);const _=new EventSource("/v1/events/stream");_.onopen=()=>{u("open"),f(void 0)},_.onerror=()=>{u("error"),f("event stream disconnected; browser is retrying")};const w=C=>{let T;try{T=JSON.parse(C.data)}catch(M){console.error("invalid event payload",M);return}g(M=>[T,...M].slice(0,bw)),e.invalidateQueries({queryKey:["rooms"]}),e.invalidateQueries({queryKey:["dms"]}),e.invalidateQueries({queryKey:["agents"]});const N=T.message?.target;N?.kind==="room"&&N.room_id&&e.invalidateQueries({queryKey:["messages","room",N.room_id]}),N?.kind==="dm"&&N.dm_id&&e.invalidateQueries({queryKey:["messages","dm",N.dm_id]}),T.type==="pairing.updated"&&(e.invalidateQueries({queryKey:["pairings"]}),e.invalidateQueries({queryKey:["network"]}))};return _.addEventListener("message.created",w),_.addEventListener("pairing.updated",w),_.addEventListener("agent.connected",w),_.addEventListener("agent.disconnected",w),_.addEventListener("agent.wake.delivered",w),_.addEventListener("agent.wake.failed",w),()=>{_.removeEventListener("message.created",w),_.removeEventListener("pairing.updated",w),_.removeEventListener("agent.connected",w),_.removeEventListener("agent.disconnected",w),_.removeEventListener("agent.wake.delivered",w),_.removeEventListener("agent.wake.failed",w),_.close()}},[m,v,y,e]);const S=A.useMemo(()=>({status:l,events:h,reason:c}),[l,h,c]);return k.jsx(Vy.Provider,{value:S,children:t})}function Vf(){const t=A.useContext(Vy);if(!t)throw new Error("useEventStream must be used inside ");return t}function Dw(t){const e=t?.trim();return e?`event_stream=${e} is not supported by the console`:"event_stream capability is not advertised"}function qy(){const{data:t}=wn(),{selected:e}=wt(),r=!!t?.capabilities?.human_ingress,s=t?.console?.can_send_human??r;return r&&s&&Br(e)}const Gy=A.createContext(null);function jw(t,e){return{getTheme:function(){return e??null}}}function on(){const t=A.useContext(Gy);return t==null&&(function(e,...r){const s=new URL("https://lexical.dev/docs/error"),l=new URLSearchParams;l.append("code",e);for(const u of r)l.append("v",u);throw s.search=l.toString(),Error(`Minified Lexical error #${e}; visit ${s.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)})(8),t}function q(t,...e){const r=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",t);for(const l of e)s.append("v",l);throw r.search=s.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function Jy(t,...e){const r=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",t);for(const l of e)s.append("v",l);r.search=s.toString(),console.warn(`Minified Lexical warning #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const ln=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0,Fw=ln&&"documentMode"in document?document.documentMode:null,Xt=ln&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),fr=ln&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),Xl=!(!ln||!("InputEvent"in window)||Fw)&&"getTargetRanges"in new window.InputEvent("input"),oo=ln&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,Yy=ln&&/Android/.test(navigator.userAgent),pu=ln&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!Yy,Xy=ln&&/^(?=.*Chrome).*/i.test(navigator.userAgent),lf=ln&&Yy&&Xy,gu=ln&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&Xt&&!Xy,Iw=0,Lw=1,Aw=2,Zy=128,zw=1,$w=2,Bw=3,Uw=4,Kw=5,Ww=6,qs=pu||oo||gu?" ":"​",mu=` + */var Pg;function gS(){if(Pg)return Tc;Pg=1;var t=hu();function e(v,y){return v===y&&(v!==0||1/v===1/y)||v!==v&&y!==y}var r=typeof Object.is=="function"?Object.is:e,s=t.useState,l=t.useEffect,u=t.useLayoutEffect,c=t.useDebugValue;function f(v,y){var _=y(),S=s({inst:{value:_,getSnapshot:y}}),w=S[0].inst,C=S[1];return u(function(){w.value=_,w.getSnapshot=y,h(w)&&C({inst:w})},[v,_,y]),l(function(){return h(w)&&C({inst:w}),v(function(){h(w)&&C({inst:w})})},[v]),c(_),_}function h(v){var y=v.getSnapshot;v=v.value;try{var _=y();return!r(v,_)}catch{return!0}}function g(v,y){return y()}var m=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?g:f;return Tc.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:m,Tc}var bg;function mS(){return bg||(bg=1,Nc.exports=gS()),Nc.exports}var yS=mS();const vS=uS.useInsertionEffect,xS=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",_S=xS?A.useLayoutEffect:A.useEffect,SS=vS||_S,Ty=t=>{const e=A.useRef([t,(...r)=>e[0](...r)]).current;return SS(()=>{e[0]=t}),e[1]},wS="popstate",Af="pushState",zf="replaceState",CS="hashchange",Rg=[wS,Af,zf,CS],kS=t=>{for(const e of Rg)addEventListener(e,t);return()=>{for(const e of Rg)removeEventListener(e,t)}},Oy=(t,e)=>yS.useSyncExternalStore(kS,t,e),Dg=()=>location.search,ES=({ssrSearch:t}={})=>Oy(Dg,t!=null?()=>t:Dg),jg=()=>location.pathname,NS=({ssrPath:t}={})=>Oy(jg,t!=null?()=>t:jg),TS=(t,{replace:e=!1,state:r=null}={})=>history[e?zf:Af](r,"",t),OS=(t={})=>[NS(t),TS],Fg=Symbol.for("wouter_v3");if(typeof history<"u"&&typeof window[Fg]>"u"){for(const t of[Af,zf]){const e=history[t];history[t]=function(){const r=e.apply(this,arguments),s=new Event(t);return s.arguments=arguments,dispatchEvent(s),r}}Object.defineProperty(window,Fg,{value:!0})}const MS=(t,e)=>e.toLowerCase().indexOf(t.toLowerCase())?"~"+e:e.slice(t.length)||"/",My=(t="")=>t==="/"?"":t,PS=(t,e)=>t[0]==="~"?t.slice(1):My(e)+t,bS=(t="",e)=>MS(Ig(My(t)),Ig(e)),Ig=t=>{try{return decodeURI(t)}catch{return t}},Py={hook:OS,searchHook:ES,parser:pS,base:"",ssrPath:void 0,ssrSearch:void 0,ssrContext:void 0,hrefs:t=>t,aroundNav:(t,e,r)=>t(e,r)},by=A.createContext(Py),$f=()=>A.useContext(by),RS={};A.createContext(RS);const Ry=t=>{const[e,r]=t.hook(t);return[bS(t.base,e),Ty((s,l)=>t.aroundNav(r,PS(s,t.base),l))]},DS=()=>Ry($f()),jS=({children:t,...e})=>{const r=$f(),s=e.hook?Py:r;let l=s;const[u,c=e.ssrSearch??""]=e.ssrPath?.split("?")??[];u&&(e.ssrSearch=c,e.ssrPath=u),e.hrefs=e.hrefs??e.hook?.hrefs,e.searchHook=e.searchHook??e.hook?.searchHook;let f=A.useRef({}),h=f.current,g=h;for(let m in s){const v=m==="base"?s[m]+(e[m]??""):e[m]??s[m];h===g&&v!==g[m]&&(f.current=g={...g}),g[m]=v,(v!==s[m]||v!==l[m])&&(l=g)}return A.createElement(by.Provider,{value:l,children:t})};A.forwardRef((t,e)=>{const r=$f(),[s,l]=Ry(r),{to:u="",href:c=u,onClick:f,asChild:h,children:g,className:m,replace:v,state:y,transition:_,...S}=t,w=Ty(T=>{T.ctrlKey||T.metaKey||T.altKey||T.shiftKey||T.button!==0||(f?.(T),T.defaultPrevented||(T.preventDefault(),l(c,t)))}),C=r.hrefs(c[0]==="~"?c.slice(1):r.base+c,r);return h&&A.isValidElement(g)?A.cloneElement(g,{onClick:w,href:C}):A.createElement("a",{...S,onClick:w,href:C,className:m?.call?m(s===c):m,children:g,ref:e})});function Br(t){return!!t&&(t.kind==="room"||t.kind==="dm")}var Wi=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(t){return this.listeners.add(t),this.onSubscribe(),()=>{this.listeners.delete(t),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},FS=class extends Wi{#e;#t;#n;constructor(){super(),this.#n=t=>{if(typeof window<"u"&&window.addEventListener){const e=()=>t();return window.addEventListener("visibilitychange",e,!1),()=>{window.removeEventListener("visibilitychange",e)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(t){this.#n=t,this.#t?.(),this.#t=t(e=>{typeof e=="boolean"?this.setFocused(e):this.onFocus()})}setFocused(t){this.#e!==t&&(this.#e=t,this.onFocus())}onFocus(){const t=this.isFocused();this.listeners.forEach(e=>{e(t)})}isFocused(){return typeof this.#e=="boolean"?this.#e:globalThis.document?.visibilityState!=="hidden"}},Bf=new FS,IS={setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t),setInterval:(t,e)=>setInterval(t,e),clearInterval:t=>clearInterval(t)},LS=class{#e=IS;#t=!1;setTimeoutProvider(t){this.#e=t}setTimeout(t,e){return this.#e.setTimeout(t,e)}clearTimeout(t){this.#e.clearTimeout(t)}setInterval(t,e){return this.#e.setInterval(t,e)}clearInterval(t){this.#e.clearInterval(t)}},Ir=new LS;function AS(t){setTimeout(t,0)}var zS=typeof window>"u"||"Deno"in globalThis;function St(){}function $S(t,e){return typeof t=="function"?t(e):t}function Xc(t){return typeof t=="number"&&t>=0&&t!==1/0}function Dy(t,e){return Math.max(t+(e||0)-Date.now(),0)}function ur(t,e){return typeof t=="function"?t(e):t}function Ft(t,e){return typeof t=="function"?t(e):t}function Lg(t,e){const{type:r="all",exact:s,fetchStatus:l,predicate:u,queryKey:c,stale:f}=t;if(c){if(s){if(e.queryHash!==Uf(c,e.options))return!1}else if(!Qs(e.queryKey,c))return!1}if(r!=="all"){const h=e.isActive();if(r==="active"&&!h||r==="inactive"&&h)return!1}return!(typeof f=="boolean"&&e.isStale()!==f||l&&l!==e.state.fetchStatus||u&&!u(e))}function Ag(t,e){const{exact:r,status:s,predicate:l,mutationKey:u}=t;if(u){if(!e.options.mutationKey)return!1;if(r){if(Ur(e.options.mutationKey)!==Ur(u))return!1}else if(!Qs(e.options.mutationKey,u))return!1}return!(s&&e.state.status!==s||l&&!l(e))}function Uf(t,e){return(e?.queryKeyHashFn||Ur)(t)}function Ur(t){return JSON.stringify(t,(e,r)=>Zc(r)?Object.keys(r).sort().reduce((s,l)=>(s[l]=r[l],s),{}):r)}function Qs(t,e){return t===e?!0:typeof t!=typeof e?!1:t&&e&&typeof t=="object"&&typeof e=="object"?Object.keys(e).every(r=>Qs(t[r],e[r])):!1}var BS=Object.prototype.hasOwnProperty;function jy(t,e,r=0){if(t===e)return t;if(r>500)return e;const s=zg(t)&&zg(e);if(!s&&!(Zc(t)&&Zc(e)))return e;const u=(s?t:Object.keys(t)).length,c=s?e:Object.keys(e),f=c.length,h=s?new Array(f):{};let g=0;for(let m=0;m{Ir.setTimeout(e,t)})}function ef(t,e,r){return typeof r.structuralSharing=="function"?r.structuralSharing(t,e):r.structuralSharing!==!1?jy(t,e):e}function KS(t,e,r=0){const s=[...t,e];return r&&s.length>r?s.slice(1):s}function WS(t,e,r=0){const s=[e,...t];return r&&s.length>r?s.slice(0,-1):s}var Kf=Symbol();function Fy(t,e){return!t.queryFn&&e?.initialPromise?()=>e.initialPromise:!t.queryFn||t.queryFn===Kf?()=>Promise.reject(new Error(`Missing queryFn: '${t.queryHash}'`)):t.queryFn}function Wf(t,e){return typeof t=="function"?t(...e):!!t}function HS(t,e,r){let s=!1,l;return Object.defineProperty(t,"signal",{enumerable:!0,get:()=>(l??=e(),s||(s=!0,l.aborted?r():l.addEventListener("abort",r,{once:!0})),l)}),t}var Vs=(()=>{let t=()=>zS;return{isServer(){return t()},setIsServer(e){t=e}}})();function tf(){let t,e;const r=new Promise((l,u)=>{t=l,e=u});r.status="pending",r.catch(()=>{});function s(l){Object.assign(r,l),delete r.resolve,delete r.reject}return r.resolve=l=>{s({status:"fulfilled",value:l}),t(l)},r.reject=l=>{s({status:"rejected",reason:l}),e(l)},r}var QS=AS;function VS(){let t=[],e=0,r=f=>{f()},s=f=>{f()},l=QS;const u=f=>{e?t.push(f):l(()=>{r(f)})},c=()=>{const f=t;t=[],f.length&&l(()=>{s(()=>{f.forEach(h=>{r(h)})})})};return{batch:f=>{let h;e++;try{h=f()}finally{e--,e||c()}return h},batchCalls:f=>(...h)=>{u(()=>{f(...h)})},schedule:u,setNotifyFunction:f=>{r=f},setBatchNotifyFunction:f=>{s=f},setScheduler:f=>{l=f}}}var Xe=VS(),qS=class extends Wi{#e=!0;#t;#n;constructor(){super(),this.#n=t=>{if(typeof window<"u"&&window.addEventListener){const e=()=>t(!0),r=()=>t(!1);return window.addEventListener("online",e,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",r)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(t){this.#n=t,this.#t?.(),this.#t=t(this.setOnline.bind(this))}setOnline(t){this.#e!==t&&(this.#e=t,this.listeners.forEach(r=>{r(t)}))}isOnline(){return this.#e}},Yl=new qS;function GS(t){return Math.min(1e3*2**t,3e4)}function Iy(t){return(t??"online")==="online"?Yl.isOnline():!0}var nf=class extends Error{constructor(t){super("CancelledError"),this.revert=t?.revert,this.silent=t?.silent}};function Ly(t){let e=!1,r=0,s;const l=tf(),u=()=>l.status!=="pending",c=w=>{if(!u()){const C=new nf(w);y(C),t.onCancel?.(C)}},f=()=>{e=!0},h=()=>{e=!1},g=()=>Bf.isFocused()&&(t.networkMode==="always"||Yl.isOnline())&&t.canRun(),m=()=>Iy(t.networkMode)&&t.canRun(),v=w=>{u()||(s?.(),l.resolve(w))},y=w=>{u()||(s?.(),l.reject(w))},_=()=>new Promise(w=>{s=C=>{(u()||g())&&w(C)},t.onPause?.()}).then(()=>{s=void 0,u()||t.onContinue?.()}),S=()=>{if(u())return;let w;const C=r===0?t.initialPromise:void 0;try{w=C??t.fn()}catch(T){w=Promise.reject(T)}Promise.resolve(w).then(v).catch(T=>{if(u())return;const N=t.retry??(Vs.isServer()?0:3),M=t.retryDelay??GS,L=typeof M=="function"?M(r,T):M,j=N===!0||typeof N=="number"&&rg()?void 0:_()).then(()=>{e?y(T):S()})})};return{promise:l,status:()=>l.status,cancel:c,continue:()=>(s?.(),l),cancelRetry:f,continueRetry:h,canStart:m,start:()=>(m()?S():_().then(S),l)}}var Ay=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Xc(this.gcTime)&&(this.#e=Ir.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(t){this.gcTime=Math.max(this.gcTime||0,t??(Vs.isServer()?1/0:300*1e3))}clearGcTimeout(){this.#e!==void 0&&(Ir.clearTimeout(this.#e),this.#e=void 0)}};function JS(t){return{onFetch:(e,r)=>{const s=e.options,l=e.fetchOptions?.meta?.fetchMore?.direction,u=e.state.data?.pages||[],c=e.state.data?.pageParams||[];let f={pages:[],pageParams:[]},h=0;const g=async()=>{let m=!1;const v=S=>{HS(S,()=>e.signal,()=>m=!0)},y=Fy(e.options,e.fetchOptions),_=async(S,w,C)=>{if(m)return Promise.reject(e.signal.reason);if(w==null&&S.pages.length)return Promise.resolve(S);const N=(()=>{const D={client:e.client,queryKey:e.queryKey,pageParam:w,direction:C?"backward":"forward",meta:e.options.meta};return v(D),D})(),M=await y(N),{maxPages:L}=e.options,j=C?WS:KS;return{pages:j(S.pages,M,L),pageParams:j(S.pageParams,w,L)}};if(l&&u.length){const S=l==="backward",w=S?zy:rf,C={pages:u,pageParams:c},T=w(s,C);f=await _(C,T,S)}else{const S=t??u.length;do{const w=h===0?c[0]??s.initialPageParam:rf(s,f);if(h>0&&w==null)break;f=await _(f,w),h++}while(he.options.persister?.(g,{client:e.client,queryKey:e.queryKey,meta:e.options.meta,signal:e.signal},r):e.fetchFn=g}}}function rf(t,{pages:e,pageParams:r}){const s=e.length-1;return e.length>0?t.getNextPageParam(e[s],e,r[s],r):void 0}function zy(t,{pages:e,pageParams:r}){return e.length>0?t.getPreviousPageParam?.(e[0],e,r[0],r):void 0}function YS(t,e){return e?rf(t,e)!=null:!1}function XS(t,e){return!e||!t.getPreviousPageParam?!1:zy(t,e)!=null}var ZS=class extends Ay{#e;#t;#n;#r;#s;#i;#l;#o;constructor(t){super(),this.#o=!1,this.#l=t.defaultOptions,this.setOptions(t.options),this.observers=[],this.#s=t.client,this.#r=this.#s.getQueryCache(),this.queryKey=t.queryKey,this.queryHash=t.queryHash,this.#t=Ug(this.options),this.state=t.state??this.#t,this.scheduleGc()}get meta(){return this.options.meta}get queryType(){return this.#e}get promise(){return this.#i?.promise}setOptions(t){if(this.options={...this.#l,...t},t?._type&&(this.#e=t._type),this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){const e=Ug(this.options);e.data!==void 0&&(this.setState(Bg(e.data,e.dataUpdatedAt)),this.#t=e)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&this.#r.remove(this)}setData(t,e){const r=ef(this.state.data,t,this.options);return this.#u({data:r,type:"success",dataUpdatedAt:e?.updatedAt,manual:e?.manual}),r}setState(t){this.#u({type:"setState",state:t})}cancel(t){const e=this.#i?.promise;return this.#i?.cancel(t),e?e.then(St).catch(St):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}get resetState(){return this.#t}reset(){this.destroy(),this.setState(this.resetState)}isActive(){return this.observers.some(t=>Ft(t.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===Kf||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0?this.observers.some(t=>ur(t.options.staleTime,this)==="static"):!1}isStale(){return this.getObserversCount()>0?this.observers.some(t=>t.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(t=0){return this.state.data===void 0?!0:t==="static"?!1:this.state.isInvalidated?!0:!Dy(this.state.dataUpdatedAt,t)}onFocus(){this.observers.find(e=>e.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#i?.continue()}onOnline(){this.observers.find(e=>e.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#i?.continue()}addObserver(t){this.observers.includes(t)||(this.observers.push(t),this.clearGcTimeout(),this.#r.notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){this.observers.includes(t)&&(this.observers=this.observers.filter(e=>e!==t),this.observers.length||(this.#i&&(this.#o||this.#c()?this.#i.cancel({revert:!0}):this.#i.cancelRetry()),this.scheduleGc()),this.#r.notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.observers.length}#c(){return this.state.fetchStatus==="paused"&&this.state.status==="pending"}invalidate(){this.state.isInvalidated||this.#u({type:"invalidate"})}async fetch(t,e){if(this.state.fetchStatus!=="idle"&&this.#i?.status()!=="rejected"){if(this.state.data!==void 0&&e?.cancelRefetch)this.cancel({silent:!0});else if(this.#i)return this.#i.continueRetry(),this.#i.promise}if(t&&this.setOptions(t),!this.options.queryFn){const h=this.observers.find(g=>g.options.queryFn);h&&this.setOptions(h.options)}const r=new AbortController,s=h=>{Object.defineProperty(h,"signal",{enumerable:!0,get:()=>(this.#o=!0,r.signal)})},l=()=>{const h=Fy(this.options,e),m=(()=>{const v={client:this.#s,queryKey:this.queryKey,meta:this.meta};return s(v),v})();return this.#o=!1,this.options.persister?this.options.persister(h,m,this):h(m)},c=(()=>{const h={fetchOptions:e,options:this.options,queryKey:this.queryKey,client:this.#s,state:this.state,fetchFn:l};return s(h),h})();(this.#e==="infinite"?JS(this.options.pages):this.options.behavior)?.onFetch(c,this),this.#n=this.state,(this.state.fetchStatus==="idle"||this.state.fetchMeta!==c.fetchOptions?.meta)&&this.#u({type:"fetch",meta:c.fetchOptions?.meta}),this.#i=Ly({initialPromise:e?.initialPromise,fn:c.fetchFn,onCancel:h=>{h instanceof nf&&h.revert&&this.setState({...this.#n,fetchStatus:"idle"}),r.abort()},onFail:(h,g)=>{this.#u({type:"failed",failureCount:h,error:g})},onPause:()=>{this.#u({type:"pause"})},onContinue:()=>{this.#u({type:"continue"})},retry:c.options.retry,retryDelay:c.options.retryDelay,networkMode:c.options.networkMode,canRun:()=>!0});try{const h=await this.#i.start();if(h===void 0)throw new Error(`${this.queryHash} data is undefined`);return this.setData(h),this.#r.config.onSuccess?.(h,this),this.#r.config.onSettled?.(h,this.state.error,this),h}catch(h){if(h instanceof nf){if(h.silent)return this.#i.promise;if(h.revert){if(this.state.data===void 0)throw h;return this.state.data}}throw this.#u({type:"error",error:h}),this.#r.config.onError?.(h,this),this.#r.config.onSettled?.(this.state.data,h,this),h}finally{this.scheduleGc()}}#u(t){const e=r=>{switch(t.type){case"failed":return{...r,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...r,fetchStatus:"paused"};case"continue":return{...r,fetchStatus:"fetching"};case"fetch":return{...r,...$y(r.data,this.options),fetchMeta:t.meta??null};case"success":const s={...r,...Bg(t.data,t.dataUpdatedAt),dataUpdateCount:r.dataUpdateCount+1,...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return this.#n=t.manual?s:void 0,s;case"error":const l=t.error;return{...r,error:l,errorUpdateCount:r.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:r.fetchFailureCount+1,fetchFailureReason:l,fetchStatus:"idle",status:"error",isInvalidated:!0};case"invalidate":return{...r,isInvalidated:!0};case"setState":return{...r,...t.state}}};this.state=e(this.state),Xe.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),this.#r.notify({query:this,type:"updated",action:t})})}};function $y(t,e){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:Iy(e.networkMode)?"fetching":"paused",...t===void 0&&{error:null,status:"pending"}}}function Bg(t,e){return{data:t,dataUpdatedAt:e??Date.now(),error:null,isInvalidated:!1,status:"success"}}function Ug(t){const e=typeof t.initialData=="function"?t.initialData():t.initialData,r=e!==void 0,s=r?typeof t.initialDataUpdatedAt=="function"?t.initialDataUpdatedAt():t.initialDataUpdatedAt:0;return{data:e,dataUpdateCount:0,dataUpdatedAt:r?s??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:r?"success":"pending",fetchStatus:"idle"}}var By=class extends Wi{constructor(t,e){super(),this.options=e,this.#e=t,this.#o=null,this.#l=tf(),this.bindMethods(),this.setOptions(e)}#e;#t=void 0;#n=void 0;#r=void 0;#s;#i;#l;#o;#c;#u;#p;#f;#d;#a;#g=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#t.addObserver(this),Kg(this.#t,this.options)?this.#h():this.updateResult(),this.#x())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return sf(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return sf(this.#t,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#_(),this.#S(),this.#t.removeObserver(this)}setOptions(t){const e=this.options,r=this.#t;if(this.options=this.#e.defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof Ft(this.options.enabled,this.#t)!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");this.#w(),this.#t.setOptions(this.options),e._defaulted&&!Jl(this.options,e)&&this.#e.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#t,observer:this});const s=this.hasListeners();s&&Wg(this.#t,r,this.options,e)&&this.#h(),this.updateResult(),s&&(this.#t!==r||Ft(this.options.enabled,this.#t)!==Ft(e.enabled,this.#t)||ur(this.options.staleTime,this.#t)!==ur(e.staleTime,this.#t))&&this.#m();const l=this.#y();s&&(this.#t!==r||Ft(this.options.enabled,this.#t)!==Ft(e.enabled,this.#t)||l!==this.#a)&&this.#v(l)}getOptimisticResult(t){const e=this.#e.getQueryCache().build(this.#e,t),r=this.createResult(e,t);return tw(this,r)&&(this.#r=r,this.#i=this.options,this.#s=this.#t.state),r}getCurrentResult(){return this.#r}trackResult(t,e){return new Proxy(t,{get:(r,s)=>(this.trackProp(s),e?.(s),s==="promise"&&(this.trackProp("data"),!this.options.experimental_prefetchInRender&&this.#l.status==="pending"&&this.#l.reject(new Error("experimental_prefetchInRender feature flag is not enabled"))),Reflect.get(r,s))})}trackProp(t){this.#g.add(t)}getCurrentQuery(){return this.#t}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const e=this.#e.defaultQueryOptions(t),r=this.#e.getQueryCache().build(this.#e,e);return r.fetch().then(()=>this.createResult(r,e))}fetch(t){return this.#h({...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#r))}#h(t){this.#w();let e=this.#t.fetch(this.options,t);return t?.throwOnError||(e=e.catch(St)),e}#m(){this.#_();const t=ur(this.options.staleTime,this.#t);if(Vs.isServer()||this.#r.isStale||!Xc(t))return;const r=Dy(this.#r.dataUpdatedAt,t)+1;this.#f=Ir.setTimeout(()=>{this.#r.isStale||this.updateResult()},r)}#y(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(this.#t):this.options.refetchInterval)??!1}#v(t){this.#S(),this.#a=t,!(Vs.isServer()||Ft(this.options.enabled,this.#t)===!1||!Xc(this.#a)||this.#a===0)&&(this.#d=Ir.setInterval(()=>{(this.options.refetchIntervalInBackground||Bf.isFocused())&&this.#h()},this.#a))}#x(){this.#m(),this.#v(this.#y())}#_(){this.#f!==void 0&&(Ir.clearTimeout(this.#f),this.#f=void 0)}#S(){this.#d!==void 0&&(Ir.clearInterval(this.#d),this.#d=void 0)}createResult(t,e){const r=this.#t,s=this.options,l=this.#r,u=this.#s,c=this.#i,h=t!==r?t.state:this.#n,{state:g}=t;let m={...g},v=!1,y;if(e._optimisticResults){const F=this.hasListeners(),z=!F&&Kg(t,e),J=F&&Wg(t,r,e,s);(z||J)&&(m={...m,...$y(g.data,t.options)}),e._optimisticResults==="isRestoring"&&(m.fetchStatus="idle")}let{error:_,errorUpdatedAt:S,status:w}=m;y=m.data;let C=!1;if(e.placeholderData!==void 0&&y===void 0&&w==="pending"){let F;l?.isPlaceholderData&&e.placeholderData===c?.placeholderData?(F=l.data,C=!0):F=typeof e.placeholderData=="function"?e.placeholderData(this.#p?.state.data,this.#p):e.placeholderData,F!==void 0&&(w="success",y=ef(l?.data,F,e),v=!0)}if(e.select&&y!==void 0&&!C)if(l&&y===u?.data&&e.select===this.#c)y=this.#u;else try{this.#c=e.select,y=e.select(y),y=ef(l?.data,y,e),this.#u=y,this.#o=null}catch(F){this.#o=F}this.#o&&(_=this.#o,y=this.#u,S=Date.now(),w="error");const T=m.fetchStatus==="fetching",N=w==="pending",M=w==="error",L=N&&T,j=y!==void 0,$={status:w,fetchStatus:m.fetchStatus,isPending:N,isSuccess:w==="success",isError:M,isInitialLoading:L,isLoading:L,data:y,dataUpdatedAt:m.dataUpdatedAt,error:_,errorUpdatedAt:S,failureCount:m.fetchFailureCount,failureReason:m.fetchFailureReason,errorUpdateCount:m.errorUpdateCount,isFetched:t.isFetched(),isFetchedAfterMount:m.dataUpdateCount>h.dataUpdateCount||m.errorUpdateCount>h.errorUpdateCount,isFetching:T,isRefetching:T&&!N,isLoadingError:M&&!j,isPaused:m.fetchStatus==="paused",isPlaceholderData:v,isRefetchError:M&&j,isStale:Hf(t,e),refetch:this.refetch,promise:this.#l,isEnabled:Ft(e.enabled,t)!==!1};if(this.options.experimental_prefetchInRender){const F=$.data!==void 0,z=$.status==="error"&&!F,J=X=>{z?X.reject($.error):F&&X.resolve($.data)},te=()=>{const X=this.#l=$.promise=tf();J(X)},ne=this.#l;switch(ne.status){case"pending":t.queryHash===r.queryHash&&J(ne);break;case"fulfilled":(z||$.data!==ne.value)&&te();break;case"rejected":(!z||$.error!==ne.reason)&&te();break}}return $}updateResult(){const t=this.#r,e=this.createResult(this.#t,this.options);if(this.#s=this.#t.state,this.#i=this.options,this.#s.data!==void 0&&(this.#p=this.#t),Jl(e,t))return;this.#r=e;const r=()=>{if(!t)return!0;const{notifyOnChangeProps:s}=this.options,l=typeof s=="function"?s():s;if(l==="all"||!l&&!this.#g.size)return!0;const u=new Set(l??this.#g);return this.options.throwOnError&&u.add("error"),Object.keys(this.#r).some(c=>{const f=c;return this.#r[f]!==t[f]&&u.has(f)})};this.#C({listeners:r()})}#w(){const t=this.#e.getQueryCache().build(this.#e,this.options);if(t===this.#t)return;const e=this.#t;this.#t=t,this.#n=t.state,this.hasListeners()&&(e?.removeObserver(this),t.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#x()}#C(t){Xe.batch(()=>{t.listeners&&this.listeners.forEach(e=>{e(this.#r)}),this.#e.getQueryCache().notify({query:this.#t,type:"observerResultsUpdated"})})}};function ew(t,e){return Ft(e.enabled,t)!==!1&&t.state.data===void 0&&!(t.state.status==="error"&&Ft(e.retryOnMount,t)===!1)}function Kg(t,e){return ew(t,e)||t.state.data!==void 0&&sf(t,e,e.refetchOnMount)}function sf(t,e,r){if(Ft(e.enabled,t)!==!1&&ur(e.staleTime,t)!=="static"){const s=typeof r=="function"?r(t):r;return s==="always"||s!==!1&&Hf(t,e)}return!1}function Wg(t,e,r,s){return(t!==e||Ft(s.enabled,t)===!1)&&(!r.suspense||t.state.status!=="error")&&Hf(t,r)}function Hf(t,e){return Ft(e.enabled,t)!==!1&&t.isStaleByTime(ur(e.staleTime,t))}function tw(t,e){return!Jl(t.getCurrentResult(),e)}var nw=class extends By{constructor(t,e){super(t,e)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(t){t._type="infinite",super.setOptions(t)}getOptimisticResult(t){return t._type="infinite",super.getOptimisticResult(t)}fetchNextPage(t){return this.fetch({...t,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(t){return this.fetch({...t,meta:{fetchMore:{direction:"backward"}}})}createResult(t,e){const{state:r}=t,s=super.createResult(t,e),{isFetching:l,isRefetching:u,isError:c,isRefetchError:f}=s,h=r.fetchMeta?.fetchMore?.direction,g=c&&h==="forward",m=l&&h==="forward",v=c&&h==="backward",y=l&&h==="backward";return{...s,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:YS(e,r.data),hasPreviousPage:XS(e,r.data),isFetchNextPageError:g,isFetchingNextPage:m,isFetchPreviousPageError:v,isFetchingPreviousPage:y,isRefetchError:f&&!g&&!v,isRefetching:u&&!m&&!y}}},rw=class extends Ay{#e;#t;#n;#r;constructor(t){super(),this.#e=t.client,this.mutationId=t.mutationId,this.#n=t.mutationCache,this.#t=[],this.state=t.state||Uy(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){this.#t.includes(t)||(this.#t.push(t),this.clearGcTimeout(),this.#n.notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){this.#t=this.#t.filter(e=>e!==t),this.scheduleGc(),this.#n.notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){this.#t.length||(this.state.status==="pending"?this.scheduleGc():this.#n.remove(this))}continue(){return this.#r?.continue()??this.execute(this.state.variables)}async execute(t){const e=()=>{this.#s({type:"continue"})},r={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#r=Ly({fn:()=>this.options.mutationFn?this.options.mutationFn(t,r):Promise.reject(new Error("No mutationFn found")),onFail:(u,c)=>{this.#s({type:"failed",failureCount:u,error:c})},onPause:()=>{this.#s({type:"pause"})},onContinue:e,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)});const s=this.state.status==="pending",l=!this.#r.canStart();try{if(s)e();else{this.#s({type:"pending",variables:t,isPaused:l}),this.#n.config.onMutate&&await this.#n.config.onMutate(t,this,r);const c=await this.options.onMutate?.(t,r);c!==this.state.context&&this.#s({type:"pending",context:c,variables:t,isPaused:l})}const u=await this.#r.start();return await this.#n.config.onSuccess?.(u,t,this.state.context,this,r),await this.options.onSuccess?.(u,t,this.state.context,r),await this.#n.config.onSettled?.(u,null,this.state.variables,this.state.context,this,r),await this.options.onSettled?.(u,null,t,this.state.context,r),this.#s({type:"success",data:u}),u}catch(u){try{await this.#n.config.onError?.(u,t,this.state.context,this,r)}catch(c){Promise.reject(c)}try{await this.options.onError?.(u,t,this.state.context,r)}catch(c){Promise.reject(c)}try{await this.#n.config.onSettled?.(void 0,u,this.state.variables,this.state.context,this,r)}catch(c){Promise.reject(c)}try{await this.options.onSettled?.(void 0,u,t,this.state.context,r)}catch(c){Promise.reject(c)}throw this.#s({type:"error",error:u}),u}finally{this.#n.runNext(this)}}#s(t){const e=r=>{switch(t.type){case"failed":return{...r,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:t.isPaused,status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...r,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:t.error,failureCount:r.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=e(this.state),Xe.batch(()=>{this.#t.forEach(r=>{r.onMutationUpdate(t)}),this.#n.notify({mutation:this,type:"updated",action:t})})}};function Uy(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var iw=class extends Wi{constructor(t={}){super(),this.config=t,this.#e=new Set,this.#t=new Map,this.#n=0}#e;#t;#n;build(t,e,r){const s=new rw({client:t,mutationCache:this,mutationId:++this.#n,options:t.defaultMutationOptions(e),state:r});return this.add(s),s}add(t){this.#e.add(t);const e=Tl(t);if(typeof e=="string"){const r=this.#t.get(e);r?r.push(t):this.#t.set(e,[t])}this.notify({type:"added",mutation:t})}remove(t){if(this.#e.delete(t)){const e=Tl(t);if(typeof e=="string"){const r=this.#t.get(e);if(r)if(r.length>1){const s=r.indexOf(t);s!==-1&&r.splice(s,1)}else r[0]===t&&this.#t.delete(e)}}this.notify({type:"removed",mutation:t})}canRun(t){const e=Tl(t);if(typeof e=="string"){const s=this.#t.get(e)?.find(l=>l.state.status==="pending");return!s||s===t}else return!0}runNext(t){const e=Tl(t);return typeof e=="string"?this.#t.get(e)?.find(s=>s!==t&&s.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){Xe.batch(()=>{this.#e.forEach(t=>{this.notify({type:"removed",mutation:t})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(t){const e={exact:!0,...t};return this.getAll().find(r=>Ag(e,r))}findAll(t={}){return this.getAll().filter(e=>Ag(t,e))}notify(t){Xe.batch(()=>{this.listeners.forEach(e=>{e(t)})})}resumePausedMutations(){const t=this.getAll().filter(e=>e.state.isPaused);return Xe.batch(()=>Promise.all(t.map(e=>e.continue().catch(St))))}};function Tl(t){return t.options.scope?.id}var sw=class extends Wi{#e;#t=void 0;#n;#r;constructor(e,r){super(),this.#e=e,this.setOptions(r),this.bindMethods(),this.#s()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(e){const r=this.options;this.options=this.#e.defaultMutationOptions(e),Jl(this.options,r)||this.#e.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#n,observer:this}),r?.mutationKey&&this.options.mutationKey&&Ur(r.mutationKey)!==Ur(this.options.mutationKey)?this.reset():this.#n?.state.status==="pending"&&this.#n.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#n?.removeObserver(this)}onMutationUpdate(e){this.#s(),this.#i(e)}getCurrentResult(){return this.#t}reset(){this.#n?.removeObserver(this),this.#n=void 0,this.#s(),this.#i()}mutate(e,r){return this.#r=r,this.#n?.removeObserver(this),this.#n=this.#e.getMutationCache().build(this.#e,this.options),this.#n.addObserver(this),this.#n.execute(e)}#s(){const e=this.#n?.state??Uy();this.#t={...e,isPending:e.status==="pending",isSuccess:e.status==="success",isError:e.status==="error",isIdle:e.status==="idle",mutate:this.mutate,reset:this.reset}}#i(e){Xe.batch(()=>{if(this.#r&&this.hasListeners()){const r=this.#t.variables,s=this.#t.context,l={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};if(e?.type==="success"){try{this.#r.onSuccess?.(e.data,r,s,l)}catch(u){Promise.reject(u)}try{this.#r.onSettled?.(e.data,null,r,s,l)}catch(u){Promise.reject(u)}}else if(e?.type==="error"){try{this.#r.onError?.(e.error,r,s,l)}catch(u){Promise.reject(u)}try{this.#r.onSettled?.(void 0,e.error,r,s,l)}catch(u){Promise.reject(u)}}}this.listeners.forEach(r=>{r(this.#t)})})}},ow=class extends Wi{constructor(t={}){super(),this.config=t,this.#e=new Map}#e;build(t,e,r){const s=e.queryKey,l=e.queryHash??Uf(s,e);let u=this.get(l);return u||(u=new ZS({client:t,queryKey:s,queryHash:l,options:t.defaultQueryOptions(e),state:r,defaultOptions:t.getQueryDefaults(s)}),this.add(u)),u}add(t){this.#e.has(t.queryHash)||(this.#e.set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const e=this.#e.get(t.queryHash);e&&(t.destroy(),e===t&&this.#e.delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){Xe.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return this.#e.get(t)}getAll(){return[...this.#e.values()]}find(t){const e={exact:!0,...t};return this.getAll().find(r=>Lg(e,r))}findAll(t={}){const e=this.getAll();return Object.keys(t).length>0?e.filter(r=>Lg(t,r)):e}notify(t){Xe.batch(()=>{this.listeners.forEach(e=>{e(t)})})}onFocus(){Xe.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){Xe.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},lw=class{#e;#t;#n;#r;#s;#i;#l;#o;constructor(t={}){this.#e=t.queryCache||new ow,this.#t=t.mutationCache||new iw,this.#n=t.defaultOptions||{},this.#r=new Map,this.#s=new Map,this.#i=0}mount(){this.#i++,this.#i===1&&(this.#l=Bf.subscribe(async t=>{t&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#o=Yl.subscribe(async t=>{t&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#i--,this.#i===0&&(this.#l?.(),this.#l=void 0,this.#o?.(),this.#o=void 0)}isFetching(t){return this.#e.findAll({...t,fetchStatus:"fetching"}).length}isMutating(t){return this.#t.findAll({...t,status:"pending"}).length}getQueryData(t){const e=this.defaultQueryOptions({queryKey:t});return this.#e.get(e.queryHash)?.state.data}ensureQueryData(t){const e=this.defaultQueryOptions(t),r=this.#e.build(this,e),s=r.state.data;return s===void 0?this.fetchQuery(t):(t.revalidateIfStale&&r.isStaleByTime(ur(e.staleTime,r))&&this.prefetchQuery(e),Promise.resolve(s))}getQueriesData(t){return this.#e.findAll(t).map(({queryKey:e,state:r})=>{const s=r.data;return[e,s]})}setQueryData(t,e,r){const s=this.defaultQueryOptions({queryKey:t}),u=this.#e.get(s.queryHash)?.state.data,c=$S(e,u);if(c!==void 0)return this.#e.build(this,s).setData(c,{...r,manual:!0})}setQueriesData(t,e,r){return Xe.batch(()=>this.#e.findAll(t).map(({queryKey:s})=>[s,this.setQueryData(s,e,r)]))}getQueryState(t){const e=this.defaultQueryOptions({queryKey:t});return this.#e.get(e.queryHash)?.state}removeQueries(t){const e=this.#e;Xe.batch(()=>{e.findAll(t).forEach(r=>{e.remove(r)})})}resetQueries(t,e){const r=this.#e;return Xe.batch(()=>(r.findAll(t).forEach(s=>{s.reset()}),this.refetchQueries({type:"active",...t},e)))}cancelQueries(t,e={}){const r={revert:!0,...e},s=Xe.batch(()=>this.#e.findAll(t).map(l=>l.cancel(r)));return Promise.all(s).then(St).catch(St)}invalidateQueries(t,e={}){return Xe.batch(()=>(this.#e.findAll(t).forEach(r=>{r.invalidate()}),t?.refetchType==="none"?Promise.resolve():this.refetchQueries({...t,type:t?.refetchType??t?.type??"active"},e)))}refetchQueries(t,e={}){const r={...e,cancelRefetch:e.cancelRefetch??!0},s=Xe.batch(()=>this.#e.findAll(t).filter(l=>!l.isDisabled()&&!l.isStatic()).map(l=>{let u=l.fetch(void 0,r);return r.throwOnError||(u=u.catch(St)),l.state.fetchStatus==="paused"?Promise.resolve():u}));return Promise.all(s).then(St)}fetchQuery(t){const e=this.defaultQueryOptions(t);e.retry===void 0&&(e.retry=!1);const r=this.#e.build(this,e);return r.isStaleByTime(ur(e.staleTime,r))?r.fetch(e):Promise.resolve(r.state.data)}prefetchQuery(t){return this.fetchQuery(t).then(St).catch(St)}fetchInfiniteQuery(t){return t._type="infinite",this.fetchQuery(t)}prefetchInfiniteQuery(t){return this.fetchInfiniteQuery(t).then(St).catch(St)}ensureInfiniteQueryData(t){return t._type="infinite",this.ensureQueryData(t)}resumePausedMutations(){return Yl.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(t){this.#n=t}setQueryDefaults(t,e){this.#r.set(Ur(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){const e=[...this.#r.values()],r={};return e.forEach(s=>{Qs(t,s.queryKey)&&Object.assign(r,s.defaultOptions)}),r}setMutationDefaults(t,e){this.#s.set(Ur(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){const e=[...this.#s.values()],r={};return e.forEach(s=>{Qs(t,s.mutationKey)&&Object.assign(r,s.defaultOptions)}),r}defaultQueryOptions(t){if(t._defaulted)return t;const e={...this.#n.queries,...this.getQueryDefaults(t.queryKey),...t,_defaulted:!0};return e.queryHash||(e.queryHash=Uf(e.queryKey,e)),e.refetchOnReconnect===void 0&&(e.refetchOnReconnect=e.networkMode!=="always"),e.throwOnError===void 0&&(e.throwOnError=!!e.suspense),!e.networkMode&&e.persister&&(e.networkMode="offlineFirst"),e.queryFn===Kf&&(e.enabled=!1),e}defaultMutationOptions(t){return t?._defaulted?t:{...this.#n.mutations,...t?.mutationKey&&this.getMutationDefaults(t.mutationKey),...t,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},Ky=A.createContext(void 0),Qf=t=>{const e=A.useContext(Ky);if(!e)throw new Error("No QueryClient set, use QueryClientProvider to set one");return e},uw=({client:t,children:e})=>(A.useEffect(()=>(t.mount(),()=>{t.unmount()}),[t]),k.jsx(Ky.Provider,{value:t,children:e})),Wy=A.createContext(!1),aw=()=>A.useContext(Wy);Wy.Provider;function cw(){let t=!1;return{clearReset:()=>{t=!1},reset:()=>{t=!0},isReset:()=>t}}var fw=A.createContext(cw()),dw=()=>A.useContext(fw),hw=(t,e,r)=>{const s=r?.state.error&&typeof t.throwOnError=="function"?Wf(t.throwOnError,[r.state.error,r]):t.throwOnError;(t.suspense||t.experimental_prefetchInRender||s)&&(e.isReset()||(t.retryOnMount=!1))},pw=t=>{A.useEffect(()=>{t.clearReset()},[t])},gw=({result:t,errorResetBoundary:e,throwOnError:r,query:s,suspense:l})=>t.isError&&!e.isReset()&&!t.isFetching&&s&&(l&&t.data===void 0||Wf(r,[t.error,s])),mw=t=>{if(t.suspense){const r=l=>l==="static"?l:Math.max(l??1e3,1e3),s=t.staleTime;t.staleTime=typeof s=="function"?(...l)=>r(s(...l)):r(s),typeof t.gcTime=="number"&&(t.gcTime=Math.max(t.gcTime,1e3))}},yw=(t,e)=>t.isLoading&&t.isFetching&&!e,vw=(t,e)=>t?.suspense&&e.isPending,Hg=(t,e,r)=>e.fetchOptimistic(t).catch(()=>{r.clearReset()});function Hy(t,e,r){const s=aw(),l=dw(),u=Qf(),c=u.defaultQueryOptions(t);u.getDefaultOptions().queries?._experimental_beforeQuery?.(c);const f=u.getQueryCache().get(c.queryHash);c._optimisticResults=s?"isRestoring":"optimistic",mw(c),hw(c,l,f),pw(l);const h=!u.getQueryCache().get(c.queryHash),[g]=A.useState(()=>new e(u,c)),m=g.getOptimisticResult(c),v=!s&&t.subscribed!==!1;if(A.useSyncExternalStore(A.useCallback(y=>{const _=v?g.subscribe(Xe.batchCalls(y)):St;return g.updateResult(),_},[g,v]),()=>g.getCurrentResult(),()=>g.getCurrentResult()),A.useEffect(()=>{g.setOptions(c)},[c,g]),vw(c,m))throw Hg(c,g,l);if(gw({result:m,errorResetBoundary:l,throwOnError:c.throwOnError,query:f,suspense:c.suspense}))throw m.error;return u.getDefaultOptions().queries?._experimental_afterQuery?.(c,m),c.experimental_prefetchInRender&&!Vs.isServer()&&yw(m,s)&&(h?Hg(c,g,l):f?.promise)?.catch(St).finally(()=>{g.updateResult()}),c.notifyOnChangeProps?m:g.trackResult(m)}function gr(t,e){return Hy(t,By)}function xw(t,e){const r=Qf(),[s]=A.useState(()=>new sw(r,t));A.useEffect(()=>{s.setOptions(t)},[s,t]);const l=A.useSyncExternalStore(A.useCallback(c=>s.subscribe(Xe.batchCalls(c)),[s]),()=>s.getCurrentResult(),()=>s.getCurrentResult()),u=A.useCallback((c,f)=>{s.mutate(c,f).catch(St)},[s]);if(l.error&&Wf(s.options.throwOnError,[l.error]))throw l.error;return{...l,mutate:u,mutateAsync:l.mutate}}function _w(t,e){return Hy(t,nw)}function Sw({children:t}){const e=A.useMemo(()=>new lw({defaultOptions:{queries:{refetchOnWindowFocus:!1,staleTime:5e3,retry:1}}}),[]);return k.jsx(uw,{client:e,children:t})}const ww=/^\/room\/(.+)$/,Cw=/^\/dm\/(.+)$/,kw=/^\/agent\/(.+)$/,Ew=/^\/pairing\/(.+)$/;function Nw(t){if(t==="/events")return{kind:"events"};const e=t.match(ww);if(e)return{kind:"room",id:decodeURIComponent(e[1])};const r=t.match(Cw);if(r)return{kind:"dm",id:decodeURIComponent(r[1])};const s=t.match(kw);if(s)return{kind:"agent",id:decodeURIComponent(s[1])};const l=t.match(Ew);return l?{kind:"pairing",id:decodeURIComponent(l[1])}:null}function Tw(t){return t?t.kind==="events"?"/events":`/${t.kind}/${encodeURIComponent(t.id)}`:"/"}function Ow({children:t}){return k.jsx(k.Fragment,{children:t})}function wt(){const[t,e]=DS(),r=A.useMemo(()=>Nw(t),[t]),s=A.useCallback(l=>{e(Tw(l))},[e]);return{selected:r,select:s}}const of=new Set;function Qy(t){for(const e of of)e(t)}function Mw(t){return of.add(t),()=>{of.delete(t)}}const Oc=Number.parseInt("",10),Qg=Number.isFinite(Oc)&&Oc>0?Oc:0;class Vy extends Error{status;code;constructor(e,r,s){super(r),this.name="ApiError",this.status=e,this.code=s}}async function pn(t){await Pw();const e=performance.now(),r=await fetch(t);if(Qy(Math.round(performance.now()-e)),!r.ok)throw new Error(`${t} returned ${r.status}`);return await r.json()}function Pw(){return Qg<=0?Promise.resolve():new Promise(t=>window.setTimeout(t,Qg))}function Vg(t){return{...t,messages:t.messages??[]}}function Mc(t,e){if(t===null||typeof t!="object")return;const r=t[e];return typeof r=="string"&&r.trim()!==""?r:void 0}async function bw(t,e){if((t.headers.get("content-type")??"").includes("application/json")){const l=await t.json().catch(()=>null);return{message:Mc(l,"error")??Mc(l,"message")??e,code:Mc(l,"code")}}return{message:(await t.text().catch(()=>"")).trim()||e}}const sn={network:()=>pn("/v1/network"),rooms:()=>pn("/v1/rooms").then(t=>t.rooms??[]),dms:()=>pn("/v1/dms").then(t=>t.dms??[]),agents:()=>pn("/v1/agents").then(t=>t.agents??[]),pairings:()=>pn("/v1/pairings").then(t=>t.pairings??[]),pairingNetwork:t=>pn(`/v1/pairings/${encodeURIComponent(t)}/network`),pairingRooms:t=>pn(`/v1/pairings/${encodeURIComponent(t)}/rooms`).then(e=>e.rooms??[]),pairingAgents:t=>pn(`/v1/pairings/${encodeURIComponent(t)}/agents`).then(e=>e.agents??[]),roomMessages:(t,e)=>pn(`/v1/rooms/${encodeURIComponent(t)}/messages?limit=50${e?`&before=${encodeURIComponent(e)}`:""}`).then(Vg),dmMessages:(t,e)=>pn(`/v1/dms/${encodeURIComponent(t)}/messages?limit=50${e?`&before=${encodeURIComponent(e)}`:""}`).then(Vg),sendMessage:async t=>{const e=performance.now(),r=await fetch("/v1/messages",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(Qy(Math.round(performance.now()-e)),!r.ok){const s=await bw(r,`send failed (${r.status})`);throw new Vy(r.status,s.message,s.code)}return r.json()}};function wn(){return gr({queryKey:["network"],queryFn:sn.network})}const qy=A.createContext(null),Rw=1e3,qg=["message.created","room.created","room.removed","room.members.updated","thread.created","dm.created","pairing.updated","agent.connected","agent.disconnected","agent.removed","agent.wake.delivered","agent.wake.failed","stream.replay_gap"];function Dw({children:t}){const e=Qf(),{data:r,error:s}=wn(),[l,u]=A.useState("connecting"),[c,f]=A.useState(),[h,g]=A.useState([]),m=r?.capabilities?.event_stream,v=!!r,y=s instanceof Error?s.message:s?String(s):void 0;A.useEffect(()=>{if(y){u("error"),f(y);return}if(!v){u("connecting"),f(void 0);return}if(m!=="sse"){u("unsupported"),f(jw(m));return}u("connecting"),f(void 0);const S=new EventSource("/v1/events/stream");S.onopen=()=>{u("open"),f(void 0)},S.onerror=()=>{u("error"),f("event stream disconnected; browser is retrying")};const w=C=>{let T;try{T=JSON.parse(C.data)}catch(M){console.error("invalid event payload",M);return}g(M=>[T,...M].slice(0,Rw)),e.invalidateQueries({queryKey:["rooms"]}),e.invalidateQueries({queryKey:["dms"]}),e.invalidateQueries({queryKey:["agents"]});const N=T.message?.target;N?.kind==="room"&&N.room_id&&e.invalidateQueries({queryKey:["messages","room",N.room_id]}),N?.kind==="dm"&&N.dm_id&&e.invalidateQueries({queryKey:["messages","dm",N.dm_id]}),T.type==="pairing.updated"&&(e.invalidateQueries({queryKey:["pairings"]}),e.invalidateQueries({queryKey:["network"]}))};return qg.forEach(C=>{S.addEventListener(C,w)}),()=>{qg.forEach(C=>{S.removeEventListener(C,w)}),S.close()}},[m,v,y,e]);const _=A.useMemo(()=>({status:l,events:h,reason:c}),[l,h,c]);return k.jsx(qy.Provider,{value:_,children:t})}function Vf(){const t=A.useContext(qy);if(!t)throw new Error("useEventStream must be used inside ");return t}function jw(t){const e=t?.trim();return e?`event_stream=${e} is not supported by the console`:"event_stream capability is not advertised"}function Gy(){const{data:t}=wn(),{selected:e}=wt(),r=!!t?.capabilities?.human_ingress,s=t?.console?.can_send_human??r;return r&&s&&Br(e)}const Jy=A.createContext(null);function Fw(t,e){return{getTheme:function(){return e??null}}}function on(){const t=A.useContext(Jy);return t==null&&(function(e,...r){const s=new URL("https://lexical.dev/docs/error"),l=new URLSearchParams;l.append("code",e);for(const u of r)l.append("v",u);throw s.search=l.toString(),Error(`Minified Lexical error #${e}; visit ${s.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)})(8),t}function q(t,...e){const r=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",t);for(const l of e)s.append("v",l);throw r.search=s.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function Yy(t,...e){const r=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",t);for(const l of e)s.append("v",l);r.search=s.toString(),console.warn(`Minified Lexical warning #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const ln=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0,Iw=ln&&"documentMode"in document?document.documentMode:null,Xt=ln&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),fr=ln&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),Xl=!(!ln||!("InputEvent"in window)||Iw)&&"getTargetRanges"in new window.InputEvent("input"),oo=ln&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,Xy=ln&&/Android/.test(navigator.userAgent),pu=ln&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!Xy,Zy=ln&&/^(?=.*Chrome).*/i.test(navigator.userAgent),lf=ln&&Xy&&Zy,gu=ln&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&Xt&&!Zy,Lw=0,Aw=1,zw=2,ev=128,$w=1,Bw=2,Uw=3,Kw=4,Ww=5,Hw=6,qs=pu||oo||gu?" ":"​",mu=` -`,qf=fr?" ":qs,Kr={bold:1,capitalize:1024,code:16,highlight:Zy,italic:2,lowercase:256,strikethrough:4,subscript:32,superscript:64,underline:8,uppercase:512},Hw={directionless:1,unmergeable:2},uf={center:2,end:6,justify:4,left:1,right:3,start:5},Qw={[$w]:"center",[Ww]:"end",[Uw]:"justify",[zw]:"left",[Bw]:"right",[Kw]:"start"},Vw={normal:0,segmented:2,token:1},qw={[Iw]:"normal",[Aw]:"segmented",[Lw]:"token"},qg="$config";let Is=class{_front=new Set;_back=new Set;_cache;get size(){return this._front.size+this._back.size}addBack(e){return delete this._cache,this._front.has(e)||this._back.add(e),this}addFront(e){return delete this._cache,this._back.has(e)||this._front.add(e),this}delete(e){return delete this._cache,this._front.delete(e)||this._back.delete(e)}toArray(){const e=Array.from(this._front).reverse();for(const r of this._back)e.push(r);return e}toReadonlyArray(){return this._cache=this._cache||this.toArray(),this._cache}[Symbol.iterator](){return this.toReadonlyArray()[Symbol.iterator]()}};function ev(t,e,r,s,l,u){let c=t.getFirstChild();for(;c!==null;){const f=c.__key;c.__parent===e&&(K(c)&&ev(c,f,r,s,l,u),r.has(f)||u.delete(f),l.push(f)),c=c.getNextSibling()}}let af=!1,Gf=0;function Gw(t){Gf=t.timeStamp}function Pc(t,e,r){const s=t.nodeName==="BR",l=e.__lexicalLineBreak;return l&&(t===l||s&&t.previousSibling===l)||s&&Cu(t,r)!==void 0}function Jw(t,e,r){const s=un(Lt(r));let l=null,u=null;s!==null&&s.anchorNode===t&&(l=s.anchorOffset,u=s.focusOffset);const c=t.nodeValue;c!==null&&fd(e,c,l,u,!1)}function Yw(t,e,r){if(ee(t)){const s=t.anchor.getNode();if(s.is(r)&&t.format!==s.getFormat())return!1}return zn(e)&&r.isAttached()}function Xw(t,e,r,s){for(let l=t;l&&!l1(l);l=fo(l)){const u=Cu(l,e);if(u!==void 0){const c=et(u,r);if(c)return Ie(c)||!Pt(l)?void 0:[l,c]}else if(l===s)return[s,d0(r)]}}function tv(t,e,r){af=!0;const s=performance.now()-Gf>100;try{vn(t,()=>{const l=de()||(function(y){return y.getEditorState().read(()=>{const S=de();return S!==null?S.clone():null})})(t),u=new Map,c=t.getRootElement(),f=t._editorState,h=t._blockCursorElement;let g=!1,m="";for(let y=0;y0){let D=0;for(let $=0;$0)for(const[y,S]of u)S.reconcileObservedMutation(y,t);const v=r.takeRecords();if(v.length>0){for(let y=0;y{tv(t,e,r)})}let Zw=class{key;parse;unparse;isEqual;defaultValue;resetOnCopyNode;constructor(e,r){this.key=e,this.parse=r.parse.bind(r),this.unparse=(r.unparse||rC).bind(r),this.isEqual=(r.isEqual||Object.is).bind(r),this.defaultValue=this.parse(void 0),this.resetOnCopyNode=r.resetOnCopyNode||!1}};function iv(t,e){return new Zw(t,e)}function eC(t){const e=new Map,r=new Set;for(let s=typeof t=="function"?t:t.replace;s.prototype&&s.prototype.getType!==void 0;s=Object.getPrototypeOf(s)){const{ownNodeConfig:l}=qi(s);if(l&&l.stateConfigs)for(const u of l.stateConfigs){let c;"stateConfig"in u?(c=u.stateConfig,u.flat&&r.add(c.key)):c=u,e.set(c.key,c)}}return{flatKeys:r,sharedConfigMap:e}}let tC=class sv{node;knownState;unknownState;sharedNodeState;size;constructor(e,r,s=void 0,l=new Map,u=void 0){this.node=e,this.sharedNodeState=r,this.unknownState=s,this.knownState=l;const{sharedConfigMap:c}=this.sharedNodeState,f=u!==void 0?u:(function(h,g,m){let v=m.size;if(g)for(const y in g){const S=h.get(y);S&&m.has(S)||v++}return v})(c,s,l);this.size=f}getValue(e){const r=this.knownState.get(e);if(r!==void 0)return r;this.sharedNodeState.sharedConfigMap.set(e.key,e);let s=e.defaultValue;if(this.unknownState&&e.key in this.unknownState){const l=this.unknownState[e.key];l!==void 0&&(s=e.parse(l)),this.updateFromKnown(e,s)}return s}getInternalState(){return[this.unknownState,this.knownState]}toJSON(){const e={...this.unknownState},r={};for(const[s,l]of this.knownState)s.isEqual(l,s.defaultValue)?delete e[s.key]:e[s.key]=s.unparse(l);for(const s of this.sharedNodeState.flatKeys)s in e&&(r[s]=e[s],delete e[s]);return Gg(e)&&(r.$=e),r}getWritable(e){if(this.node===e)return this;const{sharedNodeState:r,unknownState:s}=this,l=new Map(this.knownState);return new sv(e,r,(function(u,c,f){let h;if(f)for(const[g,m]of Object.entries(f)){const v=u.get(g);v?c.has(v)||c.set(v,v.parse(m)):(h=h||{},h[g]=m)}return h})(r.sharedConfigMap,l,s),l,this.size)}resetOnCopyNode(){for(const e of this.knownState.keys())e.resetOnCopyNode&&this.knownState.set(e,e.defaultValue);return this}updateFromKnown(e,r){const s=e.key;this.sharedNodeState.sharedConfigMap.set(s,e);const{knownState:l,unknownState:u}=this;l.has(e)||u&&s in u||(u&&(delete u[s],this.unknownState=Gg(u)),this.size++),l.set(e,r)}updateFromUnknown(e,r){const s=this.sharedNodeState.sharedConfigMap.get(e);s?this.updateFromKnown(s,s.parse(r)):(this.unknownState=this.unknownState||{},e in this.unknownState||this.size++,this.unknownState[e]=r)}updateFromJSON(e){const{knownState:r}=this;for(const s of r.keys())r.set(s,s.defaultValue);if(this.size=r.size,this.unknownState=void 0,e)for(const[s,l]of Object.entries(e))this.updateFromUnknown(s,l)}};function nC(t){const e=t.getWritable(),r=e.__state?e.__state.getWritable(e):new tC(e,ov(e));return e.__state=r,r}function ov(t){return t.__state?t.__state.sharedNodeState:s0(Ui(),t.getType()).sharedNodeState}function Gg(t){if(t)for(const e in t)return t}function rC(t){return t}function Jg(t,e,r){for(const[s,l]of e.knownState){if(t.has(s.key))continue;t.add(s.key);const u=r?r.getValue(s):s.defaultValue;if(u!==l&&!s.isEqual(u,l))return!0}return!1}function Yg(t,e,r){const{unknownState:s}=e,l=r?r.unknownState:void 0;if(s){for(const[u,c]of Object.entries(s))if(!t.has(u)&&(t.add(u),c!==(l?l[u]:void 0)))return!0}return!1}function Xg(t,e){const r=t.__state;return r&&r.node===t?r.getWritable(e):r}function Zg(t,e){const r=t.__mode,s=t.__format,l=t.__style,u=e.__mode,c=e.__format,f=e.__style,h=t.__state,g=e.__state;return(r===null||r===u)&&(s===null||s===c)&&(l===null||l===f)&&(t.__state===null||h===g||(function(m,v){if(m===v)return!0;const y=new Set;return!(m&&Jg(y,m,v)||v&&Jg(y,v,m)||m&&Yg(y,m,v)||v&&Yg(y,v,m))})(h,g))}function em(t,e){const r=t.mergeWithSibling(e),s=Le()._normalizedNodes;return s.add(t.__key),s.add(e.__key),r}function tm(t){let e,r,s=t;if(s.__text!==""||!s.isSimpleText()||s.isUnmergeable()){for(;(e=s.getPreviousSibling())!==null&&re(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(e.__text!==""){if(Zg(e,s)){s=em(e,s);break}break}e.remove()}for(;(r=s.getNextSibling())!==null&&re(r)&&r.isSimpleText()&&!r.isUnmergeable();){if(r.__text!==""){if(Zg(s,r)){s=em(s,r);break}break}r.remove()}}else s.remove()}function cf(t){return nm(t.anchor),nm(t.focus),t}function nm(t){for(;t.type==="element";){const e=t.getNode(),r=t.offset;let s,l;if(r===e.getChildrenSize()?(s=e.getChildAtIndex(r-1),l=!0):(s=e.getChildAtIndex(r),l=!1),re(s)){t.set(s.__key,l?s.getTextContentSize():0,"text",!0);break}if(!K(s))break;t.set(s.__key,l?s.getChildrenSize():0,"element",!0)}}let Gs,Ke,Js,yu,ff,df,Wr,en,hf,Ys,In,Ze="",mn=null,jr=null,Oi=!1,Zl=!1;function eu(t,e){const r=Wr.get(t);if(e!==null){const s=yf(t);s.parentNode===e&&e.removeChild(s)}if(en.has(t)||Ke._keyToDOMMap.delete(t),K(r)){const s=au(r,Wr);pf(s,0,s.length-1,null)}r!==void 0&&dd(Ys,Js,yu,r,"destroyed")}function pf(t,e,r,s){for(let l=e;l<=r;++l){const u=t[l];u!==void 0&&eu(u,s)}}function Dr(t,e){t.setProperty("text-align",e)}const iC="40px";function lv(t,e){const r=Gs.theme.indent;if(typeof r=="string"){const l=t.classList.contains(r);e>0&&!l?t.classList.add(r):e<1&&l&&t.classList.remove(r)}if(e===0)return void t.style.setProperty("padding-inline-start","");const s=getComputedStyle(Ke._rootElement||t).getPropertyValue("--lexical-indent-base-value")||iC;t.style.setProperty("padding-inline-start",`calc(${e} * ${s})`)}function uv(t,e){const r=t.style;e===0?Dr(r,""):e===1?Dr(r,"left"):e===2?Dr(r,"center"):e===3?Dr(r,"right"):e===4?Dr(r,"justify"):e===5?Dr(r,"start"):e===6&&Dr(r,"end")}function gf(t,e){const r=(function(s){const l=s.__dir;if(l!==null)return l;if(lt(s))return null;const u=s.getParentOrThrow();return lt(u)&&u.__dir===null?"auto":null})(e);r!==null?t.dir=r:t.removeAttribute("dir")}function tu(t,e){const r=en.get(t);r===void 0&&q(60);const s=In.$createDOM(r,Ke);if((function(l,u,c){const f=c._keyToDOMMap;(function(h,g,m){const v=`__lexicalKey_${g._key}`;h[v]=m})(u,c,l),f.set(l,u)})(t,s,Ke),re(r)?s.setAttribute("data-lexical-text","true"):Ie(r)&&s.setAttribute("data-lexical-decorator","true"),K(r)){const l=r.__indent,u=r.__size;if(gf(s,r),l!==0&&lv(s,l),u!==0){const f=u-1;mf(au(r,en),r,0,f,In.$getDOMSlot(r,s,Ke))}const c=r.__format;c!==0&&uv(s,c),r.isInline()||av(null,r,s)}else{const l=r.getTextContent();if(Ie(r)){const u=r.decorate(Ke,Gs);u!==null&&cv(t,u),s.contentEditable="false"}Ze+=l}return e!==null&&e.insertChild(s),In.$decorateDOM(r,null,s,Ke),dd(Ys,Js,yu,r,"created"),s}function mf(t,e,r,s,l){const u=Ze;Ze="";let c=r;for(;c<=s;++c){tu(t[c],l);const f=en.get(t[c]);f!==null&&re(f)?mn===null&&(mn=f.getFormat(),jr=f.getStyle()):K(f)&&cM,te=z>L;if(J&&!te){const ne=w[L+1],X=ne===void 0?null:Ke.getElementByKey(ne);mf(w,0,z,L,N.withBefore(X))}else te&&!J&&pf(_,F,M,N.element)})(0,v,y,h,g,c)}m.__lexicalTextContent=Ze,Ze=f+Ze})(t,e,In.$getDOMSlot(e,r,Ke)),s=e,mn==null||mn===s.__textFormat||Zl||s.setTextFormat(mn),(function(l){jr==null||jr===l.__textStyle||Zl||l.setTextStyle(jr)})(e)}function $l(t,e){const r=Wr.get(t);let s=en.get(t);r!==void 0&&s!==void 0||q(61);const l=Oi||df.has(t)||ff.has(t),u=Bi(Ke,t);if(r===s&&!l){let c;if(K(r)){const f=u.__lexicalTextContent;typeof f=="string"?c=f:(c=r.getTextContent(),u.__lexicalTextContent=c)}else c=r.getTextContent();return Ze+=c,u}if(r!==s&&l&&dd(Ys,Js,yu,s,"updated"),In.$updateDOM(s,r,u,Ke)){const c=tu(t,null);return e===null&&q(62),e.replaceChild(c,u),eu(t,null),c}if(K(r)){K(s)||q(334,t);const c=s.__indent;(Oi||c!==r.__indent)&&lv(u,c);const f=s.__format;if((Oi||f!==r.__format)&&uv(u,f),l)sC(r,s,u),lt(s)||s.isInline()||av(r,s,u);else{const h=u.__lexicalTextContent;let g;typeof h=="string"?g=h:(g=r.getTextContent(),u.__lexicalTextContent=g),Ze+=g}if((Oi||s.__dir!==r.__dir)&&(gf(u,s),lt(s)&&!Oi))for(const h of s.getChildren())K(h)&&gf(Bi(Ke,h.getKey()),h)}else{const c=s.getTextContent();if(Ie(s)){const f=s.decorate(Ke,Gs);f!==null&&cv(t,f)}Ze+=c}if(!Zl&<(s)&&s.__cachedText!==Ze){const c=s.getWritable();c.__cachedText=Ze,s=c}return In.$decorateDOM(s,r,u,Ke),u}function cv(t,e){let r=Ke._pendingDecorators;const s=Ke._decorators;if(r===null){if(s[t]===e)return;r=f0(Ke)}r[t]=e}function bc(t){let e=t.nextSibling;return e!==null&&e===Ke._blockCursorElement&&(e=e.nextSibling),e}function im(t,e){const r=new Set;for(let s=e;s{o0(r)||(Cf=!0)})}],["compositionstart",function(t,e){ie(e,pv,t)}],["compositionend",function(t,e){fr?$s=!0:oo||!pu&&!gu?ie(e,gv,t):(Ul=!0,Kl=t.data)}],["input",function(t,e){t.stopPropagation(),vn(e,()=>{e.dispatchCommand(hv,t)},{event:t}),Mi=null}],["click",function(t,e){vn(e,()=>{const r=de(),s=un(Lt(e)),l=lo();if(s){if(ee(r)){const u=r.anchor,c=u.getNode();if(u.type==="element"&&u.offset===0&&r.isCollapsed()&&!lt(c)&&tt().getChildrenSize()===1&&c.getTopLevelElementOrThrow().isEmpty()&&l!==null&&r.is(l))s.removeAllRanges(),r.dirty=!0;else if(t.detail===3&&!r.isCollapsed()&&c!==r.focus.getNode()){const f=Ql(c,h=>K(h)&&!h.isInline());K(f)&&f.select(0)}}else if(t.pointerType==="touch"||t.pointerType==="pen"){const u=s.anchorNode;(Pt(u)||zn(u))&&It(id(l,s,e,t))}}ie(e,lC,t)})}],["cut",bn],["copy",bn],["dragstart",bn],["dragover",bn],["dragend",bn],["paste",bn],["focus",bn],["blur",bn],["drop",bn]];Xl&&_f.push(["beforeinput",(t,e)=>(function(r,s){const l=r.inputType;l==="deleteCompositionText"||fr&&m0(s)||l!=="insertCompositionText"&&ie(s,dv,r)})(t,e)]);let eo=0,Tv=null,Ov=0,Mi=null;const Sf=new WeakMap,nu=new WeakMap;let wf=!1,Cf=!1,Bs=!1,$s=!1,Ul=!1,Kl="",Fr=null,Mv=[0,"",0,"root",0];function Pv(t,e,r,s,l){const u=t.anchor,c=t.focus,f=u.getNode(),h=Le(),g=un(Lt(h)),m=g!==null?g.anchorNode:null,v=u.key,y=h.getElementByKey(v),S=r.length;return v!==c.key||!re(f)||(!l&&(!Xl||Ov1||(l||!Xl)&&y!==null&&!f.isComposing()&&m!==$i(y)||g!==null&&e!==null&&(!e.collapsed||e.startContainer!==g.anchorNode||e.startOffset!==g.anchorOffset)||!f.isComposing()&&(f.getFormat()!==t.format||f.getStyle()!==t.style)||(function(_,w){if(w.isSegmented())return!0;if(!_.isCollapsed())return!1;const C=_.anchor.offset,T=w.getParentOrThrow(),N=zr(w);return C===0?!w.canInsertTextBefore()||!T.canInsertTextBefore()&&!w.isComposing()||N||(function(M){const L=M.getPreviousSibling();return(re(L)||K(L)&&L.isInline())&&!L.canInsertTextAfter()})(w):C===w.getTextContentSize()&&(!w.canInsertTextAfter()||!T.canInsertTextAfter()&&!w.isComposing()||N)})(t,f)}function sm(t,e){return zn(t)&&t.nodeValue!==null&&e!==0&&e!==t.nodeValue.length}function om(t,e,r){const{anchorNode:s,anchorOffset:l,focusNode:u,focusOffset:c}=t;wf&&(wf=!1,sm(s,l)&&sm(u,c)&&!Fr)||vn(e,()=>{if(!r)return void It(null);if(!Su(e,s,u))return;let f=de();if(Fr&&ee(f)&&f.isCollapsed()){const h=f.anchor,g=Fr.anchor;(h.key===g.key&&h.offset===g.offset+1||h.offset===1&&g.getNode().is(h.getNode().getPreviousSibling()))&&(f=Fr.clone(),It(f))}if(Fr=null,ee(f)){const h=f.anchor,g=h.getNode();if(f.isCollapsed()){t.type==="Range"&&t.anchorNode===t.focusNode&&(f.dirty=!0);const m=Lt(e).event,v=m?m.timeStamp:performance.now(),[y,S,_,w,C]=Mv,T=tt(),N=e.isComposing()===!1&&T.getTextContent()==="";if(v{vn(s,()=>{ft(null)})},30),ee(l)){const y=l.anchor.getNode();y.markDirty(),re(y)||q(142),bv(l,y)}}else{ft(null),t.preventDefault();const y=l.anchor.getNode(),S=y.getTextContent(),_=y.canInsertTextAfter(),w=l.anchor.offset===0&&l.focus.offset===S.length;let C=lf&&v&&!w&&_;if(C&&l.isCollapsed()&&(C=!Ie(YC(l.anchor,!0))),!C){ie(s,Ar,!0);const T=de();lf&&ee(T)&&T.isCollapsed()&&(Fr=T,setTimeout(()=>Fr=null))}}return!0}}var u;if(!ee(l))return!0;const c=t.data;Mi!==null&&cd(!1,s,Mi),l.dirty&&Mi===null||!l.isCollapsed()||lt(l.anchor.getNode())||r===null||l.applyDOMRange(r),Mi=null;const f=l.anchor,h=l.focus,g=f.getNode(),m=h.getNode();if(e==="insertText"||e==="insertTranspose"){if(c===` -`)t.preventDefault(),ie(s,Ri,!1);else if(c===mu)t.preventDefault(),ie(s,vf,void 0);else if(c==null&&t.dataTransfer){const v=t.dataTransfer.getData("text/plain");t.preventDefault(),l.insertRawText(v)}else c!=null&&Pv(l,r,c,t.timeStamp,!0)?(t.preventDefault(),ie(s,Di,c)):Mi=c;return Ov=t.timeStamp,!0}switch(t.preventDefault(),e){case"insertFromYank":case"insertFromDrop":case"insertReplacementText":ie(s,Di,t);break;case"insertFromComposition":ft(null),ie(s,Di,t);break;case"insertLineBreak":ft(null),ie(s,Ri,!1);break;case"insertParagraph":ft(null),Bs&&!oo?(Bs=!1,ie(s,Ri,!1)):ie(s,vf,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":ie(s,Jf,t);break;case"deleteByComposition":(function(v,y){return v!==y||K(v)||K(y)||!zr(v)||!zr(y)})(g,m)&&ie(s,Bl,t);break;case"deleteByDrag":Eu(Nf),ie(s,Bl,t);break;case"deleteByCut":ie(s,Bl,t);break;case"deleteContent":ie(s,Ar,!1);break;case"deleteWordBackward":ie(s,Xs,!0);break;case"deleteWordForward":ie(s,Xs,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":ie(s,Zs,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":ie(s,Zs,!1);break;case"formatStrikeThrough":ie(s,Lr,"strikethrough");break;case"formatBold":ie(s,Lr,"bold");break;case"formatItalic":ie(s,Lr,"italic");break;case"formatUnderline":ie(s,Lr,"underline");break;case"historyUndo":ie(s,Yf,void 0);break;case"historyRedo":ie(s,Xf,void 0)}return!0}function vC(t){if(Pt(t.target)&&o0(t.target))return!0;const e=Le(),r=de(),s=t.data,l=Rv(t);if(s!=null&&ee(r)&&Pv(r,l,s,t.timeStamp,!1)){$s&&(ru(e,s),$s=!1);const u=r.anchor.getNode(),c=un(Lt(e));if(c===null)return!0;const f=r.isBackward(),h=f?r.anchor.offset:r.focus.offset,g=f?r.focus.offset:r.anchor.offset;Xl&&!r.isCollapsed()&&re(u)&&c.anchorNode!==null&&u.getTextContent().slice(0,h)+s+u.getTextContent().slice(h+g)===g0(c.anchorNode)||ie(e,Di,s);const m=s.length;fr&&m>1&&t.inputType==="insertCompositionText"&&!e.isComposing()&&(r.anchor.offset-=m),lf&&e.isComposing()&&(eo=0,ft(null))}else cd(!1,e,s!==null?s:void 0),$s&&(ru(e,s||void 0),$s=!1);return(function(){yt();const u=Le();nv(u)})(),!0}function xC(t){const e=Le(),r=de();if(ee(r)&&!e.isComposing()){const s=r.anchor,l=r.anchor.getNode();ft(s.key),Eu(Iv),(t.timeStamp{ru(e,Kl)}),Ul=!1,Kl="",!0;Ul=!1,Kl=""}if((function(r){return Re(r,"ArrowRight",{shiftKey:"any"})})(t))ie(e,yv,t);else if((function(r){return Re(r,"ArrowRight",Dn)})(t))ie(e,uC,t);else if((function(r){return Re(r,"ArrowLeft",{shiftKey:"any"})})(t))ie(e,vv,t);else if((function(r){return Re(r,"ArrowLeft",Dn)})(t))ie(e,aC,t);else if((function(r){return Re(r,"ArrowUp",{altKey:"any",shiftKey:"any"})})(t))ie(e,xv,t);else if((function(r){return Re(r,"ArrowDown",{altKey:"any",shiftKey:"any"})})(t))ie(e,_v,t);else if((function(r){return Re(r,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any",shiftKey:!0})})(t))Bs=!0,ie(e,Ai,t);else if((function(r){return r.key===" "})(t))ie(e,cC,t);else if((function(r){return Xt&&Re(r,"o",{ctrlKey:!0})})(t))t.preventDefault(),Bs=!0,ie(e,Ri,!0);else if((function(r){return Re(r,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any"})})(t))Bs=!1,ie(e,Ai,t);else if((function(r){return Re(r,"Backspace",{shiftKey:"any"})||Xt&&Re(r,"h",{ctrlKey:!0})})(t))Im(t)?ie(e,Sv,t):(t.preventDefault(),ie(e,Ar,!0));else if((function(r){return r.key==="Escape"})(t))ie(e,wv,t);else if((function(r){return Re(r,"Delete",{})||Xt&&Re(r,"d",{ctrlKey:!0})})(t))(function(r){return r.key==="Delete"})(t)?ie(e,Cv,t):(t.preventDefault(),ie(e,Ar,!1));else if((function(r){return Re(r,"Backspace",Fm)})(t))t.preventDefault(),ie(e,Xs,!0);else if((function(r){return Re(r,"Delete",Fm)})(t))t.preventDefault(),ie(e,Xs,!1);else if((function(r){return Xt&&Re(r,"Backspace",{metaKey:!0})})(t))t.preventDefault(),ie(e,Zs,!0);else if((function(r){return Xt&&(Re(r,"Delete",{metaKey:!0})||Re(r,"k",{ctrlKey:!0}))})(t))t.preventDefault(),ie(e,Zs,!1);else if((function(r){return Re(r,"b",Dn)})(t))t.preventDefault(),ie(e,Lr,"bold");else if((function(r){return Re(r,"u",Dn)})(t))t.preventDefault(),ie(e,Lr,"underline");else if((function(r){return Re(r,"i",Dn)})(t))t.preventDefault(),ie(e,Lr,"italic");else if((function(r){return Re(r,"Tab",{shiftKey:"any"})})(t))ie(e,kv,t);else if((function(r){return Re(r,"z",Dn)})(t))t.preventDefault(),ie(e,Yf,void 0);else if((function(r){return Xt?Re(r,"z",{metaKey:!0,shiftKey:!0}):Re(r,"y",{ctrlKey:!0})||Re(r,"z",{ctrlKey:!0,shiftKey:!0})})(t))t.preventDefault(),ie(e,Xf,void 0);else{const r=e._editorState._selection;r===null||ee(r)?Lm(t)&&(t.preventDefault(),ie(e,xf,t)):(function(s){return Re(s,"c",Dn)})(t)?(t.preventDefault(),ie(e,Zf,t)):(function(s){return Re(s,"x",Dn)})(t)?(t.preventDefault(),ie(e,ed,t)):Lm(t)&&(t.preventDefault(),ie(e,xf,t))}return(function(r){return r.ctrlKey||r.shiftKey||r.altKey||r.metaKey})(t)&&e.dispatchCommand(mC,t),!0}function Dv(t){let e=t.__lexicalEventHandles;return e===void 0&&(e=[],t.__lexicalEventHandles=e),e}const ji=new Map;function jv(t){const e=n1(t.target);if(e===null)return;const r=u0(e.anchorNode);if(r===null)return;Cf&&(Cf=!1,vn(r,()=>{const h=lo(),g=e.anchorNode;(Pt(g)||zn(g))&&It(id(h,e,r,t))}));const s=ad(r),l=s[s.length-1],u=l._key,c=ji.get(u),f=c||l;f!==r&&om(e,f,!1),om(e,r,!0),r!==l?ji.set(u,r):c&&ji.delete(u)}function lm(t){t._lexicalHandled=!0}function um(t){return t._lexicalHandled===!0}function wC(t){const e=Sf.get(t);if(e===void 0)return;const r=nu.get(e);if(r===void 0)return;const s=r-1;s>=0||q(164),Sf.delete(t),nu.set(e,s),s===0&&e.removeEventListener("selectionchange",jv);const l=wu(t);ud(l)?((function(c){if(c._parentEditor!==null){const f=ad(c),h=f[f.length-1]._key;ji.get(h)===c&&ji.delete(h)}else ji.delete(c._key)})(l),t.__lexicalEditor=null):l&&q(198);const u=Dv(t);for(let c=0;cl.__key===this.__key);if(re(this))return s;if(ee(r)&&r.anchor.type==="element"&&r.focus.type==="element"){if(r.isCollapsed())return!1;const l=this.getParent();if(Ie(this)&&this.isInline()&&l){const u=r.isBackward()?r.focus:r.anchor;if(l.is(u.getNode())&&u.offset===l.getChildrenSize()&&this.is(l.getLastChild()))return!1}}return s}getKey(){return this.__key}getIndexWithinParent(){const e=this.getParent();if(e===null)return-1;let r=e.getFirstChild(),s=0;for(;r!==null;){if(this.is(r))return s;s++,r=r.getNextSibling()}return-1}getParent(){const e=this.getLatest().__parent;return e===null?null:et(e)}getParentOrThrow(){const e=this.getParent();return e===null&&q(66,this.__key),e}getTopLevelElement(){let e=this;for(;e!==null;){const r=e.getParent();if(An(r))return K(e)||e===this&&Ie(e)||q(194),e;e=r}return null}getTopLevelElementOrThrow(){const e=this.getTopLevelElement();return e===null&&q(67,this.__key),e}getParents(){const e=[];let r=this.getParent();for(;r!==null;)e.push(r),r=r.getParent();return e}getParentKeys(){const e=[];let r=this.getParent();for(;r!==null;)e.push(r.__key),r=r.getParent();return e}getPreviousSibling(){const e=this.getLatest().__prev;return e===null?null:et(e)}getPreviousSiblings(){const e=[],r=this.getParent();if(r===null)return e;let s=r.getFirstChild();for(;s!==null&&!s.is(this);)e.push(s),s=s.getNextSibling();return e}getNextSibling(){const e=this.getLatest().__next;return e===null?null:et(e)}getNextSiblings(){const e=[];let r=this.getNextSibling();for(;r!==null;)e.push(r),r=r.getNextSibling();return e}getCommonAncestor(e){const r=K(this)?this:this.getParent(),s=K(e)?e:e.getParent(),l=r&&s?Vl(r,s):null;return l?l.commonAncestor:null}is(e){return e!=null&&this.__key===e.__key}isBefore(e){const r=Vl(this,e);return r!==null&&(r.type==="descendant"||(r.type==="branch"?S0(r)===-1:(r.type!=="same"&&r.type!=="ancestor"&&q(279),!1)))}isParentOf(e){const r=Vl(this,e);return r!==null&&r.type==="ancestor"}getNodesBetween(e){const r=this.isBefore(e),s=[],l=new Set;let u=this;for(;u!==null;){const c=u.__key;if(l.has(c)||(l.add(c),s.push(u)),u===e)break;const f=K(u)?r?u.getFirstChild():u.getLastChild():null;if(f!==null){u=f;continue}const h=r?u.getNextSibling():u.getPreviousSibling();if(h!==null){u=h;continue}const g=u.getParentOrThrow();if(l.has(g.__key)||s.push(g),g===e)break;let m=null,v=g;do{if(v===null&&q(68),m=r?v.getNextSibling():v.getPreviousSibling(),v=v.getParent(),v===null)break;m!==null||l.has(v.__key)||s.push(v)}while(m===null);u=m}return r||s.reverse(),s}isDirty(){const e=Le()._dirtyLeaves;return e!==null&&e.has(this.__key)}getLatest(){if(iu(this))return this;const e=et(this.__key);return e===null&&q(113),e}getWritable(){if(iu(this))return this;yt();const e=yr(),r=Le(),s=e._nodeMap,l=this.__key,u=this.getLatest(),c=r._cloneNotNeeded,f=de();if(f!==null&&f.setCachedNodes(null),c.has(l))return uu(u),u;const h=v0(u);return c.add(l),uu(h),s.set(l,h),h}getTextContent(){return""}getTextContentSize(){return this.getTextContent().length}createDOM(e,r){q(70)}updateDOM(e,r,s){q(71)}exportDOM(e){return{element:this.createDOM(e._config,e)}}exportJSON(){const e=this.__state?this.__state.toJSON():void 0;return{type:this.__type,version:1,...e}}static importJSON(e){q(18,this.name)}updateFromJSON(e){return(function(r,s){const l=r.getWritable(),u=s.$;let c=u;for(const f of ov(l).flatKeys)f in s&&(c!==void 0&&c!==u||(c={...u}),c[f]=s[f]);return(l.__state||c)&&nC(r).updateFromJSON(c),l})(this,e)}static transform(){return null}remove(e){kf(this,!0,e)}replace(e,r){yt();let s=de();s!==null&&(s=s.clone()),Ac(this,e);const l=this.getLatest(),u=this.__key,c=e.__key,f=e.getWritable(),h=this.getParentOrThrow().getWritable(),g=h.__size;$r(f);const m=l.getPreviousSibling(),v=l.getNextSibling(),y=l.__prev,S=l.__next,_=l.__parent;if(kf(l,!1,!0),m===null?h.__first=c:m.getWritable().__next=c,f.__prev=y,v===null?h.__last=c:v.getWritable().__prev=c,f.__next=S,f.__parent=_,h.__size=g,r&&(K(this)&&K(f)||q(139),this.getChildren().forEach(w=>{f.append(w)})),ee(s)){It(s);const w=s.anchor,C=s.focus;w.key===u&&gm(w,f),C.key===u&&gm(C,f)}return lr()===u&&ft(c),f}insertAfter(e,r=!0){yt(),Ac(this,e);const s=this.getWritable(),l=e.getWritable(),u=l.getParent(),c=de();let f=!1,h=!1;if(u!==null){const S=e.getIndexWithinParent();if($r(l),ee(c)){const _=u.__key,w=c.anchor,C=c.focus;f=w.type==="element"&&w.key===_&&w.offset===S+1,h=C.type==="element"&&C.key===_&&C.offset===S+1}}const g=this.getNextSibling(),m=this.getParentOrThrow().getWritable(),v=l.__key,y=s.__next;if(g===null?m.__last=v:g.getWritable().__prev=v,m.__size++,s.__next=v,l.__next=y,l.__prev=s.__key,l.__parent=s.__parent,r&&ee(c)){const S=this.getIndexWithinParent();su(c,m,S+1);const _=m.__key;f&&c.anchor.set(_,S+2,"element"),h&&c.focus.set(_,S+2,"element")}return e}insertBefore(e,r=!0){yt(),Ac(this,e);const s=this.getWritable(),l=e.getWritable(),u=l.__key;$r(l);const c=this.getPreviousSibling(),f=this.getParentOrThrow().getWritable(),h=s.__prev,g=this.getIndexWithinParent();c===null?f.__first=u:c.getWritable().__next=u,f.__size++,s.__prev=u,l.__prev=h,l.__next=s.__key,l.__parent=s.__parent;const m=de();return r&&ee(m)&&su(m,this.getParentOrThrow(),g),e}isParentRequired(){return!1}createParentElementNode(){return nn()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(e,r){yt();const s=this.getPreviousSibling(),l=this.getParentOrThrow();if(s===null)return l.select(0,0);if(K(s))return s.select();if(!re(s)){const u=s.getIndexWithinParent()+1;return l.select(u,u)}return s.select(e,r)}selectNext(e,r){yt();const s=this.getNextSibling(),l=this.getParentOrThrow();if(s===null)return l.select();if(K(s))return s.select(0,0);if(!re(s)){const u=s.getIndexWithinParent();return l.select(u,u)}return s.select(e,r)}markDirty(){this.getWritable()}reconcileObservedMutation(e,r){this.markDirty()}}function Rc(t){return t instanceof tn}const Ef="historic",CC="history-push",Fi="history-merge",kC="paste",EC="collaboration",NC="skip-scroll-into-view",TC="skip-dom-selection",Nf="skip-selection-focus",Iv="composition-start",Lv="composition-end",am=/\s*!important\s*$/i;function cm(t){const e={};if(!t)return e;let r="",s="",l=null,u=!1,c=!1,f=!1,h=0;for(let v=0;v(function(r){const s=r.parentElement;if(s!==null&&zm(s)){const l=s.firstChild;if(l===r||l.nextSibling===r&&Pl(l)){const u=s.lastChild;if(u===r||u.previousSibling===r&&Pl(u))return!0}}return!1})(e)||(function(r){const s=r.parentElement;if(s!==null&&zm(s)){const l=s.firstChild;if(l===r||l.nextSibling===r&&Pl(l))return!1;const u=s.lastChild;if(u===r||u.previousSibling===r&&Pl(u))return!0}return!1})(e)?null:{conversion:MC,priority:0}}}static importJSON(e){return to().updateFromJSON(e)}}function MC(t){return{node:to()}}function to(){return Nu(new Hi)}function Us(t){return t instanceof Hi}function Pl(t){return zn(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function Dc(t,e){return 16&e?"code":e&Zy?"mark":32&e?"sub":64&e?"sup":null}function jc(t,e){return 1&e?"strong":2&e?"em":"span"}function Av(t,e,r,s,l){const u=s.classList;let c=Ii(l,"base");c!==void 0&&u.add(...c),c=Ii(l,"underlineStrikethrough");let f=!1;const h=8&e&&4&e;c!==void 0&&(8&r&&4&r?(f=!0,h||u.add(...c)):h&&u.remove(...c));for(const g in Kr){const m=Kr[g];if(c=Ii(l,g),c!==void 0)if(r&m){if(f&&(g==="underline"||g==="strikethrough")){e&m&&u.remove(...c);continue}((e&m)===0||h&&g==="underline"||g==="strikethrough")&&u.add(...c)}else e&m&&u.remove(...c)}}function zv(t,e,r){const s=e.firstChild,l=r.isComposing(),u=t+(l?qs:"");if(s==null)e.textContent=u;else{const c=s.nodeValue;if(c!==u)if(l||fr){const[f,h,g]=(function(m,v){const y=m.length,S=v.length;let _=0,w=0;for(;_({conversion:DC,priority:0}),b:()=>({conversion:bC,priority:0}),code:()=>({conversion:Rn,priority:0}),em:()=>({conversion:Rn,priority:0}),i:()=>({conversion:Rn,priority:0}),mark:()=>({conversion:Rn,priority:0}),s:()=>({conversion:Rn,priority:0}),span:()=>({conversion:PC,priority:0}),strong:()=>({conversion:Rn,priority:0}),sub:()=>({conversion:Rn,priority:0}),sup:()=>({conversion:Rn,priority:0}),u:()=>({conversion:Rn,priority:0})}}static importJSON(e){return ct().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setTextContent(e.text).setFormat(e.format).setDetail(e.detail).setMode(e.mode).setStyle(e.style)}exportDOM(e){let{element:r}=super.exportDOM(e);return Pt(r)||q(132),r.style.whiteSpace="pre-wrap",this.hasFormat("lowercase")?r.style.textTransform="lowercase":this.hasFormat("uppercase")?r.style.textTransform="uppercase":this.hasFormat("capitalize")&&(r.style.textTransform="capitalize"),this.hasFormat("bold")&&(r=bl(r,"b")),this.hasFormat("italic")&&(r=bl(r,"i")),this.hasFormat("strikethrough")&&(r=bl(r,"s")),this.hasFormat("underline")&&(r=bl(r,"u")),{element:r}}exportJSON(){return{detail:this.getDetail(),format:this.getFormat(),mode:this.getMode(),style:this.getStyle(),text:this.getTextContent(),...super.exportJSON()}}selectionTransform(e,r){}setFormat(e){const r=this.getWritable();return r.__format=typeof e=="string"?Kr[e]:e,r}setDetail(e){const r=this.getWritable();return r.__detail=typeof e=="string"?Hw[e]:e,r}setStyle(e){const r=this.getWritable();return r.__style=e,r}toggleFormat(e){const r=lu(this.getFormat(),e,null);return this.setFormat(r)}toggleDirectionless(){const e=this.getWritable();return e.__detail^=1,e}toggleUnmergeable(){const e=this.getWritable();return e.__detail^=2,e}setMode(e){const r=Vw[e];if(this.__mode===r)return this;const s=this.getWritable();return s.__mode=r,s}setTextContent(e){if(this.__text===e)return this;const r=this.getWritable();return r.__text=e,r}select(e,r){yt();let s=e,l=r;const u=de(),c=this.getTextContent(),f=this.__key;if(typeof c=="string"){const h=c.length;s===void 0&&(s=h),l===void 0&&(l=h)}else s=0,l=0;if(!ee(u))return Kv(f,s,f,l,"text","text");{const h=lr();h!==u.anchor.key&&h!==u.focus.key||ft(f),u.setTextNodeRange(this,s,this,l)}return u}selectStart(){return this.select(0,0)}selectEnd(){const e=this.getTextContentSize();return this.select(e,e)}spliceText(e,r,s,l){const u=this.getWritable(),c=u.__text,f=s.length;let h=e;h<0&&(h=f+h,h<0&&(h=0));const g=de();if(l&&ee(g)){const v=e+f;g.setTextNodeRange(u,v,u,v)}const m=c.slice(0,h)+s+c.slice(h+r);return u.__text=m,u}canInsertTextBefore(){return!0}canInsertTextAfter(){return!0}splitText(...e){yt();const r=this.getLatest(),s=r.getTextContent();if(s==="")return[];const l=r.__key,u=lr(),c=s.length;e.sort((F,z)=>F-z),e.push(c);const f=[],h=e.length;for(let F=0,z=0;FF&&(f.push(s.slice(F,J)),F=J)}const g=f.length;if(g===1)return[r];const m=f[0],v=r.getParent();let y;const S=r.getFormat(),_=r.getStyle(),w=r.__detail;let C=!1,T=null,N=null;const M=de();if(ee(M)){const[F,z]=M.isBackward()?[M.focus,M.anchor]:[M.anchor,M.focus];F.type==="text"&&F.key===l&&(T=F),z.type==="text"&&z.key===l&&(N=z)}r.isSegmented()?(y=ct(m),y.__format=S,y.__style=_,y.__detail=w,y.__state=Xg(r,y),C=!0):y=r.setTextContent(m);const L=[y];for(let F=1;F=$&&(T.set(F.getKey(),j-$,"text"),j=$){N.set(F.getKey(),D-$,"text");break}$=z}if(v!==null){(function(J){const te=J.getPreviousSibling(),ne=J.getNextSibling();te!==null&&uu(te),ne!==null&&uu(ne)})(this);const F=v.getWritable(),z=this.getIndexWithinParent();C?(F.splice(z,0,L),this.remove()):F.splice(z,1,L),ee(M)&&su(M,v,z,g-1)}return L}mergeWithSibling(e){const r=e===this.getPreviousSibling();r||e===this.getNextSibling()||q(50);const s=this.__key,l=e.__key,u=this.__text,c=u.length;lr()===l&&ft(s);const f=de();if(ee(f)){const v=f.anchor,y=f.focus;v!==null&&v.key===l&&wm(v,r,s,e,c),y!==null&&y.key===l&&wm(y,r,s,e,c)}const h=e.__text,g=r?h+u:u+h;this.setTextContent(g);const m=this.getWritable();return e.remove(),m}isTextEntity(){return!1}}function PC(t){return{forChild:nd(t.style),node:null}}function bC(t){const e=t,r=e.style.fontWeight==="normal";return{forChild:nd(e.style,r?void 0:"bold"),node:null}}const hm=new WeakMap;function RC(t){if(!Pt(t))return!1;if(t.nodeName==="PRE")return!0;const e=t.style.whiteSpace;return typeof e=="string"&&e.startsWith("pre")}function DC(t){const e=t;t.parentElement===null&&q(129);let r=e.textContent||"";if((function(s){let l,u=s.parentNode;const c=[s];for(;u!==null&&(l=hm.get(u))===void 0&&!RC(u);)c.push(u),u=u.parentNode;const f=l===void 0?u:l;for(let h=0;h100;try{vn(t,()=>{const l=de()||(function(y){return y.getEditorState().read(()=>{const _=de();return _!==null?_.clone():null})})(t),u=new Map,c=t.getRootElement(),f=t._editorState,h=t._blockCursorElement;let g=!1,m="";for(let y=0;y0){let D=0;for(let $=0;$0)for(const[y,_]of u)_.reconcileObservedMutation(y,t);const v=r.takeRecords();if(v.length>0){for(let y=0;y{nv(t,e,r)})}let eC=class{key;parse;unparse;isEqual;defaultValue;resetOnCopyNode;constructor(e,r){this.key=e,this.parse=r.parse.bind(r),this.unparse=(r.unparse||iC).bind(r),this.isEqual=(r.isEqual||Object.is).bind(r),this.defaultValue=this.parse(void 0),this.resetOnCopyNode=r.resetOnCopyNode||!1}};function sv(t,e){return new eC(t,e)}function tC(t){const e=new Map,r=new Set;for(let s=typeof t=="function"?t:t.replace;s.prototype&&s.prototype.getType!==void 0;s=Object.getPrototypeOf(s)){const{ownNodeConfig:l}=qi(s);if(l&&l.stateConfigs)for(const u of l.stateConfigs){let c;"stateConfig"in u?(c=u.stateConfig,u.flat&&r.add(c.key)):c=u,e.set(c.key,c)}}return{flatKeys:r,sharedConfigMap:e}}let nC=class ov{node;knownState;unknownState;sharedNodeState;size;constructor(e,r,s=void 0,l=new Map,u=void 0){this.node=e,this.sharedNodeState=r,this.unknownState=s,this.knownState=l;const{sharedConfigMap:c}=this.sharedNodeState,f=u!==void 0?u:(function(h,g,m){let v=m.size;if(g)for(const y in g){const _=h.get(y);_&&m.has(_)||v++}return v})(c,s,l);this.size=f}getValue(e){const r=this.knownState.get(e);if(r!==void 0)return r;this.sharedNodeState.sharedConfigMap.set(e.key,e);let s=e.defaultValue;if(this.unknownState&&e.key in this.unknownState){const l=this.unknownState[e.key];l!==void 0&&(s=e.parse(l)),this.updateFromKnown(e,s)}return s}getInternalState(){return[this.unknownState,this.knownState]}toJSON(){const e={...this.unknownState},r={};for(const[s,l]of this.knownState)s.isEqual(l,s.defaultValue)?delete e[s.key]:e[s.key]=s.unparse(l);for(const s of this.sharedNodeState.flatKeys)s in e&&(r[s]=e[s],delete e[s]);return Jg(e)&&(r.$=e),r}getWritable(e){if(this.node===e)return this;const{sharedNodeState:r,unknownState:s}=this,l=new Map(this.knownState);return new ov(e,r,(function(u,c,f){let h;if(f)for(const[g,m]of Object.entries(f)){const v=u.get(g);v?c.has(v)||c.set(v,v.parse(m)):(h=h||{},h[g]=m)}return h})(r.sharedConfigMap,l,s),l,this.size)}resetOnCopyNode(){for(const e of this.knownState.keys())e.resetOnCopyNode&&this.knownState.set(e,e.defaultValue);return this}updateFromKnown(e,r){const s=e.key;this.sharedNodeState.sharedConfigMap.set(s,e);const{knownState:l,unknownState:u}=this;l.has(e)||u&&s in u||(u&&(delete u[s],this.unknownState=Jg(u)),this.size++),l.set(e,r)}updateFromUnknown(e,r){const s=this.sharedNodeState.sharedConfigMap.get(e);s?this.updateFromKnown(s,s.parse(r)):(this.unknownState=this.unknownState||{},e in this.unknownState||this.size++,this.unknownState[e]=r)}updateFromJSON(e){const{knownState:r}=this;for(const s of r.keys())r.set(s,s.defaultValue);if(this.size=r.size,this.unknownState=void 0,e)for(const[s,l]of Object.entries(e))this.updateFromUnknown(s,l)}};function rC(t){const e=t.getWritable(),r=e.__state?e.__state.getWritable(e):new nC(e,lv(e));return e.__state=r,r}function lv(t){return t.__state?t.__state.sharedNodeState:o0(Ui(),t.getType()).sharedNodeState}function Jg(t){if(t)for(const e in t)return t}function iC(t){return t}function Yg(t,e,r){for(const[s,l]of e.knownState){if(t.has(s.key))continue;t.add(s.key);const u=r?r.getValue(s):s.defaultValue;if(u!==l&&!s.isEqual(u,l))return!0}return!1}function Xg(t,e,r){const{unknownState:s}=e,l=r?r.unknownState:void 0;if(s){for(const[u,c]of Object.entries(s))if(!t.has(u)&&(t.add(u),c!==(l?l[u]:void 0)))return!0}return!1}function Zg(t,e){const r=t.__state;return r&&r.node===t?r.getWritable(e):r}function em(t,e){const r=t.__mode,s=t.__format,l=t.__style,u=e.__mode,c=e.__format,f=e.__style,h=t.__state,g=e.__state;return(r===null||r===u)&&(s===null||s===c)&&(l===null||l===f)&&(t.__state===null||h===g||(function(m,v){if(m===v)return!0;const y=new Set;return!(m&&Yg(y,m,v)||v&&Yg(y,v,m)||m&&Xg(y,m,v)||v&&Xg(y,v,m))})(h,g))}function tm(t,e){const r=t.mergeWithSibling(e),s=Le()._normalizedNodes;return s.add(t.__key),s.add(e.__key),r}function nm(t){let e,r,s=t;if(s.__text!==""||!s.isSimpleText()||s.isUnmergeable()){for(;(e=s.getPreviousSibling())!==null&&re(e)&&e.isSimpleText()&&!e.isUnmergeable();){if(e.__text!==""){if(em(e,s)){s=tm(e,s);break}break}e.remove()}for(;(r=s.getNextSibling())!==null&&re(r)&&r.isSimpleText()&&!r.isUnmergeable();){if(r.__text!==""){if(em(s,r)){s=tm(s,r);break}break}r.remove()}}else s.remove()}function cf(t){return rm(t.anchor),rm(t.focus),t}function rm(t){for(;t.type==="element";){const e=t.getNode(),r=t.offset;let s,l;if(r===e.getChildrenSize()?(s=e.getChildAtIndex(r-1),l=!0):(s=e.getChildAtIndex(r),l=!1),re(s)){t.set(s.__key,l?s.getTextContentSize():0,"text",!0);break}if(!K(s))break;t.set(s.__key,l?s.getChildrenSize():0,"element",!0)}}let Gs,Ke,Js,yu,ff,df,Wr,en,hf,Ys,In,Ze="",mn=null,jr=null,Oi=!1,Zl=!1;function eu(t,e){const r=Wr.get(t);if(e!==null){const s=yf(t);s.parentNode===e&&e.removeChild(s)}if(en.has(t)||Ke._keyToDOMMap.delete(t),K(r)){const s=au(r,Wr);pf(s,0,s.length-1,null)}r!==void 0&&dd(Ys,Js,yu,r,"destroyed")}function pf(t,e,r,s){for(let l=e;l<=r;++l){const u=t[l];u!==void 0&&eu(u,s)}}function Dr(t,e){t.setProperty("text-align",e)}const sC="40px";function uv(t,e){const r=Gs.theme.indent;if(typeof r=="string"){const l=t.classList.contains(r);e>0&&!l?t.classList.add(r):e<1&&l&&t.classList.remove(r)}if(e===0)return void t.style.setProperty("padding-inline-start","");const s=getComputedStyle(Ke._rootElement||t).getPropertyValue("--lexical-indent-base-value")||sC;t.style.setProperty("padding-inline-start",`calc(${e} * ${s})`)}function av(t,e){const r=t.style;e===0?Dr(r,""):e===1?Dr(r,"left"):e===2?Dr(r,"center"):e===3?Dr(r,"right"):e===4?Dr(r,"justify"):e===5?Dr(r,"start"):e===6&&Dr(r,"end")}function gf(t,e){const r=(function(s){const l=s.__dir;if(l!==null)return l;if(lt(s))return null;const u=s.getParentOrThrow();return lt(u)&&u.__dir===null?"auto":null})(e);r!==null?t.dir=r:t.removeAttribute("dir")}function tu(t,e){const r=en.get(t);r===void 0&&q(60);const s=In.$createDOM(r,Ke);if((function(l,u,c){const f=c._keyToDOMMap;(function(h,g,m){const v=`__lexicalKey_${g._key}`;h[v]=m})(u,c,l),f.set(l,u)})(t,s,Ke),re(r)?s.setAttribute("data-lexical-text","true"):Ie(r)&&s.setAttribute("data-lexical-decorator","true"),K(r)){const l=r.__indent,u=r.__size;if(gf(s,r),l!==0&&uv(s,l),u!==0){const f=u-1;mf(au(r,en),r,0,f,In.$getDOMSlot(r,s,Ke))}const c=r.__format;c!==0&&av(s,c),r.isInline()||cv(null,r,s)}else{const l=r.getTextContent();if(Ie(r)){const u=r.decorate(Ke,Gs);u!==null&&fv(t,u),s.contentEditable="false"}Ze+=l}return e!==null&&e.insertChild(s),In.$decorateDOM(r,null,s,Ke),dd(Ys,Js,yu,r,"created"),s}function mf(t,e,r,s,l){const u=Ze;Ze="";let c=r;for(;c<=s;++c){tu(t[c],l);const f=en.get(t[c]);f!==null&&re(f)?mn===null&&(mn=f.getFormat(),jr=f.getStyle()):K(f)&&cM,te=z>L;if(J&&!te){const ne=w[L+1],X=ne===void 0?null:Ke.getElementByKey(ne);mf(w,0,z,L,N.withBefore(X))}else te&&!J&&pf(S,F,M,N.element)})(0,v,y,h,g,c)}m.__lexicalTextContent=Ze,Ze=f+Ze})(t,e,In.$getDOMSlot(e,r,Ke)),s=e,mn==null||mn===s.__textFormat||Zl||s.setTextFormat(mn),(function(l){jr==null||jr===l.__textStyle||Zl||l.setTextStyle(jr)})(e)}function $l(t,e){const r=Wr.get(t);let s=en.get(t);r!==void 0&&s!==void 0||q(61);const l=Oi||df.has(t)||ff.has(t),u=Bi(Ke,t);if(r===s&&!l){let c;if(K(r)){const f=u.__lexicalTextContent;typeof f=="string"?c=f:(c=r.getTextContent(),u.__lexicalTextContent=c)}else c=r.getTextContent();return Ze+=c,u}if(r!==s&&l&&dd(Ys,Js,yu,s,"updated"),In.$updateDOM(s,r,u,Ke)){const c=tu(t,null);return e===null&&q(62),e.replaceChild(c,u),eu(t,null),c}if(K(r)){K(s)||q(334,t);const c=s.__indent;(Oi||c!==r.__indent)&&uv(u,c);const f=s.__format;if((Oi||f!==r.__format)&&av(u,f),l)oC(r,s,u),lt(s)||s.isInline()||cv(r,s,u);else{const h=u.__lexicalTextContent;let g;typeof h=="string"?g=h:(g=r.getTextContent(),u.__lexicalTextContent=g),Ze+=g}if((Oi||s.__dir!==r.__dir)&&(gf(u,s),lt(s)&&!Oi))for(const h of s.getChildren())K(h)&&gf(Bi(Ke,h.getKey()),h)}else{const c=s.getTextContent();if(Ie(s)){const f=s.decorate(Ke,Gs);f!==null&&fv(t,f)}Ze+=c}if(!Zl&<(s)&&s.__cachedText!==Ze){const c=s.getWritable();c.__cachedText=Ze,s=c}return In.$decorateDOM(s,r,u,Ke),u}function fv(t,e){let r=Ke._pendingDecorators;const s=Ke._decorators;if(r===null){if(s[t]===e)return;r=d0(Ke)}r[t]=e}function bc(t){let e=t.nextSibling;return e!==null&&e===Ke._blockCursorElement&&(e=e.nextSibling),e}function sm(t,e){const r=new Set;for(let s=e;s{l0(r)||(Cf=!0)})}],["compositionstart",function(t,e){ie(e,gv,t)}],["compositionend",function(t,e){fr?$s=!0:oo||!pu&&!gu?ie(e,mv,t):(Ul=!0,Kl=t.data)}],["input",function(t,e){t.stopPropagation(),vn(e,()=>{e.dispatchCommand(pv,t)},{event:t}),Mi=null}],["click",function(t,e){vn(e,()=>{const r=de(),s=un(Lt(e)),l=lo();if(s){if(ee(r)){const u=r.anchor,c=u.getNode();if(u.type==="element"&&u.offset===0&&r.isCollapsed()&&!lt(c)&&tt().getChildrenSize()===1&&c.getTopLevelElementOrThrow().isEmpty()&&l!==null&&r.is(l))s.removeAllRanges(),r.dirty=!0;else if(t.detail===3&&!r.isCollapsed()&&c!==r.focus.getNode()){const f=Ql(c,h=>K(h)&&!h.isInline());K(f)&&f.select(0)}}else if(t.pointerType==="touch"||t.pointerType==="pen"){const u=s.anchorNode;(Pt(u)||zn(u))&&It(id(l,s,e,t))}}ie(e,uC,t)})}],["cut",bn],["copy",bn],["dragstart",bn],["dragover",bn],["dragend",bn],["paste",bn],["focus",bn],["blur",bn],["drop",bn]];Xl&&_f.push(["beforeinput",(t,e)=>(function(r,s){const l=r.inputType;l==="deleteCompositionText"||fr&&y0(s)||l!=="insertCompositionText"&&ie(s,hv,r)})(t,e)]);let eo=0,Ov=null,Mv=0,Mi=null;const Sf=new WeakMap,nu=new WeakMap;let wf=!1,Cf=!1,Bs=!1,$s=!1,Ul=!1,Kl="",Fr=null,Pv=[0,"",0,"root",0];function bv(t,e,r,s,l){const u=t.anchor,c=t.focus,f=u.getNode(),h=Le(),g=un(Lt(h)),m=g!==null?g.anchorNode:null,v=u.key,y=h.getElementByKey(v),_=r.length;return v!==c.key||!re(f)||(!l&&(!Xl||Mv1||(l||!Xl)&&y!==null&&!f.isComposing()&&m!==$i(y)||g!==null&&e!==null&&(!e.collapsed||e.startContainer!==g.anchorNode||e.startOffset!==g.anchorOffset)||!f.isComposing()&&(f.getFormat()!==t.format||f.getStyle()!==t.style)||(function(S,w){if(w.isSegmented())return!0;if(!S.isCollapsed())return!1;const C=S.anchor.offset,T=w.getParentOrThrow(),N=zr(w);return C===0?!w.canInsertTextBefore()||!T.canInsertTextBefore()&&!w.isComposing()||N||(function(M){const L=M.getPreviousSibling();return(re(L)||K(L)&&L.isInline())&&!L.canInsertTextAfter()})(w):C===w.getTextContentSize()&&(!w.canInsertTextAfter()||!T.canInsertTextAfter()&&!w.isComposing()||N)})(t,f)}function om(t,e){return zn(t)&&t.nodeValue!==null&&e!==0&&e!==t.nodeValue.length}function lm(t,e,r){const{anchorNode:s,anchorOffset:l,focusNode:u,focusOffset:c}=t;wf&&(wf=!1,om(s,l)&&om(u,c)&&!Fr)||vn(e,()=>{if(!r)return void It(null);if(!Su(e,s,u))return;let f=de();if(Fr&&ee(f)&&f.isCollapsed()){const h=f.anchor,g=Fr.anchor;(h.key===g.key&&h.offset===g.offset+1||h.offset===1&&g.getNode().is(h.getNode().getPreviousSibling()))&&(f=Fr.clone(),It(f))}if(Fr=null,ee(f)){const h=f.anchor,g=h.getNode();if(f.isCollapsed()){t.type==="Range"&&t.anchorNode===t.focusNode&&(f.dirty=!0);const m=Lt(e).event,v=m?m.timeStamp:performance.now(),[y,_,S,w,C]=Pv,T=tt(),N=e.isComposing()===!1&&T.getTextContent()==="";if(v{vn(s,()=>{ft(null)})},30),ee(l)){const y=l.anchor.getNode();y.markDirty(),re(y)||q(142),Rv(l,y)}}else{ft(null),t.preventDefault();const y=l.anchor.getNode(),_=y.getTextContent(),S=y.canInsertTextAfter(),w=l.anchor.offset===0&&l.focus.offset===_.length;let C=lf&&v&&!w&&S;if(C&&l.isCollapsed()&&(C=!Ie(XC(l.anchor,!0))),!C){ie(s,Ar,!0);const T=de();lf&&ee(T)&&T.isCollapsed()&&(Fr=T,setTimeout(()=>Fr=null))}}return!0}}var u;if(!ee(l))return!0;const c=t.data;Mi!==null&&cd(!1,s,Mi),l.dirty&&Mi===null||!l.isCollapsed()||lt(l.anchor.getNode())||r===null||l.applyDOMRange(r),Mi=null;const f=l.anchor,h=l.focus,g=f.getNode(),m=h.getNode();if(e==="insertText"||e==="insertTranspose"){if(c===` +`)t.preventDefault(),ie(s,Ri,!1);else if(c===mu)t.preventDefault(),ie(s,vf,void 0);else if(c==null&&t.dataTransfer){const v=t.dataTransfer.getData("text/plain");t.preventDefault(),l.insertRawText(v)}else c!=null&&bv(l,r,c,t.timeStamp,!0)?(t.preventDefault(),ie(s,Di,c)):Mi=c;return Mv=t.timeStamp,!0}switch(t.preventDefault(),e){case"insertFromYank":case"insertFromDrop":case"insertReplacementText":ie(s,Di,t);break;case"insertFromComposition":ft(null),ie(s,Di,t);break;case"insertLineBreak":ft(null),ie(s,Ri,!1);break;case"insertParagraph":ft(null),Bs&&!oo?(Bs=!1,ie(s,Ri,!1)):ie(s,vf,void 0);break;case"insertFromPaste":case"insertFromPasteAsQuotation":ie(s,Jf,t);break;case"deleteByComposition":(function(v,y){return v!==y||K(v)||K(y)||!zr(v)||!zr(y)})(g,m)&&ie(s,Bl,t);break;case"deleteByDrag":Eu(Nf),ie(s,Bl,t);break;case"deleteByCut":ie(s,Bl,t);break;case"deleteContent":ie(s,Ar,!1);break;case"deleteWordBackward":ie(s,Xs,!0);break;case"deleteWordForward":ie(s,Xs,!1);break;case"deleteHardLineBackward":case"deleteSoftLineBackward":ie(s,Zs,!0);break;case"deleteContentForward":case"deleteHardLineForward":case"deleteSoftLineForward":ie(s,Zs,!1);break;case"formatStrikeThrough":ie(s,Lr,"strikethrough");break;case"formatBold":ie(s,Lr,"bold");break;case"formatItalic":ie(s,Lr,"italic");break;case"formatUnderline":ie(s,Lr,"underline");break;case"historyUndo":ie(s,Yf,void 0);break;case"historyRedo":ie(s,Xf,void 0)}return!0}function xC(t){if(Pt(t.target)&&l0(t.target))return!0;const e=Le(),r=de(),s=t.data,l=Dv(t);if(s!=null&&ee(r)&&bv(r,l,s,t.timeStamp,!1)){$s&&(ru(e,s),$s=!1);const u=r.anchor.getNode(),c=un(Lt(e));if(c===null)return!0;const f=r.isBackward(),h=f?r.anchor.offset:r.focus.offset,g=f?r.focus.offset:r.anchor.offset;Xl&&!r.isCollapsed()&&re(u)&&c.anchorNode!==null&&u.getTextContent().slice(0,h)+s+u.getTextContent().slice(h+g)===m0(c.anchorNode)||ie(e,Di,s);const m=s.length;fr&&m>1&&t.inputType==="insertCompositionText"&&!e.isComposing()&&(r.anchor.offset-=m),lf&&e.isComposing()&&(eo=0,ft(null))}else cd(!1,e,s!==null?s:void 0),$s&&(ru(e,s||void 0),$s=!1);return(function(){yt();const u=Le();rv(u)})(),!0}function _C(t){const e=Le(),r=de();if(ee(r)&&!e.isComposing()){const s=r.anchor,l=r.anchor.getNode();ft(s.key),Eu(Lv),(t.timeStamp{ru(e,Kl)}),Ul=!1,Kl="",!0;Ul=!1,Kl=""}if((function(r){return Re(r,"ArrowRight",{shiftKey:"any"})})(t))ie(e,vv,t);else if((function(r){return Re(r,"ArrowRight",Dn)})(t))ie(e,aC,t);else if((function(r){return Re(r,"ArrowLeft",{shiftKey:"any"})})(t))ie(e,xv,t);else if((function(r){return Re(r,"ArrowLeft",Dn)})(t))ie(e,cC,t);else if((function(r){return Re(r,"ArrowUp",{altKey:"any",shiftKey:"any"})})(t))ie(e,_v,t);else if((function(r){return Re(r,"ArrowDown",{altKey:"any",shiftKey:"any"})})(t))ie(e,Sv,t);else if((function(r){return Re(r,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any",shiftKey:!0})})(t))Bs=!0,ie(e,Ai,t);else if((function(r){return r.key===" "})(t))ie(e,fC,t);else if((function(r){return Xt&&Re(r,"o",{ctrlKey:!0})})(t))t.preventDefault(),Bs=!0,ie(e,Ri,!0);else if((function(r){return Re(r,"Enter",{altKey:"any",ctrlKey:"any",metaKey:"any"})})(t))Bs=!1,ie(e,Ai,t);else if((function(r){return Re(r,"Backspace",{shiftKey:"any"})||Xt&&Re(r,"h",{ctrlKey:!0})})(t))Lm(t)?ie(e,wv,t):(t.preventDefault(),ie(e,Ar,!0));else if((function(r){return r.key==="Escape"})(t))ie(e,Cv,t);else if((function(r){return Re(r,"Delete",{})||Xt&&Re(r,"d",{ctrlKey:!0})})(t))(function(r){return r.key==="Delete"})(t)?ie(e,kv,t):(t.preventDefault(),ie(e,Ar,!1));else if((function(r){return Re(r,"Backspace",Im)})(t))t.preventDefault(),ie(e,Xs,!0);else if((function(r){return Re(r,"Delete",Im)})(t))t.preventDefault(),ie(e,Xs,!1);else if((function(r){return Xt&&Re(r,"Backspace",{metaKey:!0})})(t))t.preventDefault(),ie(e,Zs,!0);else if((function(r){return Xt&&(Re(r,"Delete",{metaKey:!0})||Re(r,"k",{ctrlKey:!0}))})(t))t.preventDefault(),ie(e,Zs,!1);else if((function(r){return Re(r,"b",Dn)})(t))t.preventDefault(),ie(e,Lr,"bold");else if((function(r){return Re(r,"u",Dn)})(t))t.preventDefault(),ie(e,Lr,"underline");else if((function(r){return Re(r,"i",Dn)})(t))t.preventDefault(),ie(e,Lr,"italic");else if((function(r){return Re(r,"Tab",{shiftKey:"any"})})(t))ie(e,Ev,t);else if((function(r){return Re(r,"z",Dn)})(t))t.preventDefault(),ie(e,Yf,void 0);else if((function(r){return Xt?Re(r,"z",{metaKey:!0,shiftKey:!0}):Re(r,"y",{ctrlKey:!0})||Re(r,"z",{ctrlKey:!0,shiftKey:!0})})(t))t.preventDefault(),ie(e,Xf,void 0);else{const r=e._editorState._selection;r===null||ee(r)?Am(t)&&(t.preventDefault(),ie(e,xf,t)):(function(s){return Re(s,"c",Dn)})(t)?(t.preventDefault(),ie(e,Zf,t)):(function(s){return Re(s,"x",Dn)})(t)?(t.preventDefault(),ie(e,ed,t)):Am(t)&&(t.preventDefault(),ie(e,xf,t))}return(function(r){return r.ctrlKey||r.shiftKey||r.altKey||r.metaKey})(t)&&e.dispatchCommand(yC,t),!0}function jv(t){let e=t.__lexicalEventHandles;return e===void 0&&(e=[],t.__lexicalEventHandles=e),e}const ji=new Map;function Fv(t){const e=r1(t.target);if(e===null)return;const r=a0(e.anchorNode);if(r===null)return;Cf&&(Cf=!1,vn(r,()=>{const h=lo(),g=e.anchorNode;(Pt(g)||zn(g))&&It(id(h,e,r,t))}));const s=ad(r),l=s[s.length-1],u=l._key,c=ji.get(u),f=c||l;f!==r&&lm(e,f,!1),lm(e,r,!0),r!==l?ji.set(u,r):c&&ji.delete(u)}function um(t){t._lexicalHandled=!0}function am(t){return t._lexicalHandled===!0}function CC(t){const e=Sf.get(t);if(e===void 0)return;const r=nu.get(e);if(r===void 0)return;const s=r-1;s>=0||q(164),Sf.delete(t),nu.set(e,s),s===0&&e.removeEventListener("selectionchange",Fv);const l=wu(t);ud(l)?((function(c){if(c._parentEditor!==null){const f=ad(c),h=f[f.length-1]._key;ji.get(h)===c&&ji.delete(h)}else ji.delete(c._key)})(l),t.__lexicalEditor=null):l&&q(198);const u=jv(t);for(let c=0;cl.__key===this.__key);if(re(this))return s;if(ee(r)&&r.anchor.type==="element"&&r.focus.type==="element"){if(r.isCollapsed())return!1;const l=this.getParent();if(Ie(this)&&this.isInline()&&l){const u=r.isBackward()?r.focus:r.anchor;if(l.is(u.getNode())&&u.offset===l.getChildrenSize()&&this.is(l.getLastChild()))return!1}}return s}getKey(){return this.__key}getIndexWithinParent(){const e=this.getParent();if(e===null)return-1;let r=e.getFirstChild(),s=0;for(;r!==null;){if(this.is(r))return s;s++,r=r.getNextSibling()}return-1}getParent(){const e=this.getLatest().__parent;return e===null?null:et(e)}getParentOrThrow(){const e=this.getParent();return e===null&&q(66,this.__key),e}getTopLevelElement(){let e=this;for(;e!==null;){const r=e.getParent();if(An(r))return K(e)||e===this&&Ie(e)||q(194),e;e=r}return null}getTopLevelElementOrThrow(){const e=this.getTopLevelElement();return e===null&&q(67,this.__key),e}getParents(){const e=[];let r=this.getParent();for(;r!==null;)e.push(r),r=r.getParent();return e}getParentKeys(){const e=[];let r=this.getParent();for(;r!==null;)e.push(r.__key),r=r.getParent();return e}getPreviousSibling(){const e=this.getLatest().__prev;return e===null?null:et(e)}getPreviousSiblings(){const e=[],r=this.getParent();if(r===null)return e;let s=r.getFirstChild();for(;s!==null&&!s.is(this);)e.push(s),s=s.getNextSibling();return e}getNextSibling(){const e=this.getLatest().__next;return e===null?null:et(e)}getNextSiblings(){const e=[];let r=this.getNextSibling();for(;r!==null;)e.push(r),r=r.getNextSibling();return e}getCommonAncestor(e){const r=K(this)?this:this.getParent(),s=K(e)?e:e.getParent(),l=r&&s?Vl(r,s):null;return l?l.commonAncestor:null}is(e){return e!=null&&this.__key===e.__key}isBefore(e){const r=Vl(this,e);return r!==null&&(r.type==="descendant"||(r.type==="branch"?w0(r)===-1:(r.type!=="same"&&r.type!=="ancestor"&&q(279),!1)))}isParentOf(e){const r=Vl(this,e);return r!==null&&r.type==="ancestor"}getNodesBetween(e){const r=this.isBefore(e),s=[],l=new Set;let u=this;for(;u!==null;){const c=u.__key;if(l.has(c)||(l.add(c),s.push(u)),u===e)break;const f=K(u)?r?u.getFirstChild():u.getLastChild():null;if(f!==null){u=f;continue}const h=r?u.getNextSibling():u.getPreviousSibling();if(h!==null){u=h;continue}const g=u.getParentOrThrow();if(l.has(g.__key)||s.push(g),g===e)break;let m=null,v=g;do{if(v===null&&q(68),m=r?v.getNextSibling():v.getPreviousSibling(),v=v.getParent(),v===null)break;m!==null||l.has(v.__key)||s.push(v)}while(m===null);u=m}return r||s.reverse(),s}isDirty(){const e=Le()._dirtyLeaves;return e!==null&&e.has(this.__key)}getLatest(){if(iu(this))return this;const e=et(this.__key);return e===null&&q(113),e}getWritable(){if(iu(this))return this;yt();const e=yr(),r=Le(),s=e._nodeMap,l=this.__key,u=this.getLatest(),c=r._cloneNotNeeded,f=de();if(f!==null&&f.setCachedNodes(null),c.has(l))return uu(u),u;const h=x0(u);return c.add(l),uu(h),s.set(l,h),h}getTextContent(){return""}getTextContentSize(){return this.getTextContent().length}createDOM(e,r){q(70)}updateDOM(e,r,s){q(71)}exportDOM(e){return{element:this.createDOM(e._config,e)}}exportJSON(){const e=this.__state?this.__state.toJSON():void 0;return{type:this.__type,version:1,...e}}static importJSON(e){q(18,this.name)}updateFromJSON(e){return(function(r,s){const l=r.getWritable(),u=s.$;let c=u;for(const f of lv(l).flatKeys)f in s&&(c!==void 0&&c!==u||(c={...u}),c[f]=s[f]);return(l.__state||c)&&rC(r).updateFromJSON(c),l})(this,e)}static transform(){return null}remove(e){kf(this,!0,e)}replace(e,r){yt();let s=de();s!==null&&(s=s.clone()),Ac(this,e);const l=this.getLatest(),u=this.__key,c=e.__key,f=e.getWritable(),h=this.getParentOrThrow().getWritable(),g=h.__size;$r(f);const m=l.getPreviousSibling(),v=l.getNextSibling(),y=l.__prev,_=l.__next,S=l.__parent;if(kf(l,!1,!0),m===null?h.__first=c:m.getWritable().__next=c,f.__prev=y,v===null?h.__last=c:v.getWritable().__prev=c,f.__next=_,f.__parent=S,h.__size=g,r&&(K(this)&&K(f)||q(139),this.getChildren().forEach(w=>{f.append(w)})),ee(s)){It(s);const w=s.anchor,C=s.focus;w.key===u&&mm(w,f),C.key===u&&mm(C,f)}return lr()===u&&ft(c),f}insertAfter(e,r=!0){yt(),Ac(this,e);const s=this.getWritable(),l=e.getWritable(),u=l.getParent(),c=de();let f=!1,h=!1;if(u!==null){const _=e.getIndexWithinParent();if($r(l),ee(c)){const S=u.__key,w=c.anchor,C=c.focus;f=w.type==="element"&&w.key===S&&w.offset===_+1,h=C.type==="element"&&C.key===S&&C.offset===_+1}}const g=this.getNextSibling(),m=this.getParentOrThrow().getWritable(),v=l.__key,y=s.__next;if(g===null?m.__last=v:g.getWritable().__prev=v,m.__size++,s.__next=v,l.__next=y,l.__prev=s.__key,l.__parent=s.__parent,r&&ee(c)){const _=this.getIndexWithinParent();su(c,m,_+1);const S=m.__key;f&&c.anchor.set(S,_+2,"element"),h&&c.focus.set(S,_+2,"element")}return e}insertBefore(e,r=!0){yt(),Ac(this,e);const s=this.getWritable(),l=e.getWritable(),u=l.__key;$r(l);const c=this.getPreviousSibling(),f=this.getParentOrThrow().getWritable(),h=s.__prev,g=this.getIndexWithinParent();c===null?f.__first=u:c.getWritable().__next=u,f.__size++,s.__prev=u,l.__prev=h,l.__next=s.__key,l.__parent=s.__parent;const m=de();return r&&ee(m)&&su(m,this.getParentOrThrow(),g),e}isParentRequired(){return!1}createParentElementNode(){return nn()}selectStart(){return this.selectPrevious()}selectEnd(){return this.selectNext(0,0)}selectPrevious(e,r){yt();const s=this.getPreviousSibling(),l=this.getParentOrThrow();if(s===null)return l.select(0,0);if(K(s))return s.select();if(!re(s)){const u=s.getIndexWithinParent()+1;return l.select(u,u)}return s.select(e,r)}selectNext(e,r){yt();const s=this.getNextSibling(),l=this.getParentOrThrow();if(s===null)return l.select();if(K(s))return s.select(0,0);if(!re(s)){const u=s.getIndexWithinParent();return l.select(u,u)}return s.select(e,r)}markDirty(){this.getWritable()}reconcileObservedMutation(e,r){this.markDirty()}}function Rc(t){return t instanceof tn}const Ef="historic",kC="history-push",Fi="history-merge",EC="paste",NC="collaboration",TC="skip-scroll-into-view",OC="skip-dom-selection",Nf="skip-selection-focus",Lv="composition-start",Av="composition-end",cm=/\s*!important\s*$/i;function fm(t){const e={};if(!t)return e;let r="",s="",l=null,u=!1,c=!1,f=!1,h=0;for(let v=0;v(function(r){const s=r.parentElement;if(s!==null&&$m(s)){const l=s.firstChild;if(l===r||l.nextSibling===r&&Pl(l)){const u=s.lastChild;if(u===r||u.previousSibling===r&&Pl(u))return!0}}return!1})(e)||(function(r){const s=r.parentElement;if(s!==null&&$m(s)){const l=s.firstChild;if(l===r||l.nextSibling===r&&Pl(l))return!1;const u=s.lastChild;if(u===r||u.previousSibling===r&&Pl(u))return!0}return!1})(e)?null:{conversion:PC,priority:0}}}static importJSON(e){return to().updateFromJSON(e)}}function PC(t){return{node:to()}}function to(){return Nu(new Hi)}function Us(t){return t instanceof Hi}function Pl(t){return zn(t)&&/^( |\t|\r?\n)+$/.test(t.textContent||"")}function Dc(t,e){return 16&e?"code":e&ev?"mark":32&e?"sub":64&e?"sup":null}function jc(t,e){return 1&e?"strong":2&e?"em":"span"}function zv(t,e,r,s,l){const u=s.classList;let c=Ii(l,"base");c!==void 0&&u.add(...c),c=Ii(l,"underlineStrikethrough");let f=!1;const h=8&e&&4&e;c!==void 0&&(8&r&&4&r?(f=!0,h||u.add(...c)):h&&u.remove(...c));for(const g in Kr){const m=Kr[g];if(c=Ii(l,g),c!==void 0)if(r&m){if(f&&(g==="underline"||g==="strikethrough")){e&m&&u.remove(...c);continue}((e&m)===0||h&&g==="underline"||g==="strikethrough")&&u.add(...c)}else e&m&&u.remove(...c)}}function $v(t,e,r){const s=e.firstChild,l=r.isComposing(),u=t+(l?qs:"");if(s==null)e.textContent=u;else{const c=s.nodeValue;if(c!==u)if(l||fr){const[f,h,g]=(function(m,v){const y=m.length,_=v.length;let S=0,w=0;for(;S({conversion:jC,priority:0}),b:()=>({conversion:RC,priority:0}),code:()=>({conversion:Rn,priority:0}),em:()=>({conversion:Rn,priority:0}),i:()=>({conversion:Rn,priority:0}),mark:()=>({conversion:Rn,priority:0}),s:()=>({conversion:Rn,priority:0}),span:()=>({conversion:bC,priority:0}),strong:()=>({conversion:Rn,priority:0}),sub:()=>({conversion:Rn,priority:0}),sup:()=>({conversion:Rn,priority:0}),u:()=>({conversion:Rn,priority:0})}}static importJSON(e){return ct().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setTextContent(e.text).setFormat(e.format).setDetail(e.detail).setMode(e.mode).setStyle(e.style)}exportDOM(e){let{element:r}=super.exportDOM(e);return Pt(r)||q(132),r.style.whiteSpace="pre-wrap",this.hasFormat("lowercase")?r.style.textTransform="lowercase":this.hasFormat("uppercase")?r.style.textTransform="uppercase":this.hasFormat("capitalize")&&(r.style.textTransform="capitalize"),this.hasFormat("bold")&&(r=bl(r,"b")),this.hasFormat("italic")&&(r=bl(r,"i")),this.hasFormat("strikethrough")&&(r=bl(r,"s")),this.hasFormat("underline")&&(r=bl(r,"u")),{element:r}}exportJSON(){return{detail:this.getDetail(),format:this.getFormat(),mode:this.getMode(),style:this.getStyle(),text:this.getTextContent(),...super.exportJSON()}}selectionTransform(e,r){}setFormat(e){const r=this.getWritable();return r.__format=typeof e=="string"?Kr[e]:e,r}setDetail(e){const r=this.getWritable();return r.__detail=typeof e=="string"?Qw[e]:e,r}setStyle(e){const r=this.getWritable();return r.__style=e,r}toggleFormat(e){const r=lu(this.getFormat(),e,null);return this.setFormat(r)}toggleDirectionless(){const e=this.getWritable();return e.__detail^=1,e}toggleUnmergeable(){const e=this.getWritable();return e.__detail^=2,e}setMode(e){const r=qw[e];if(this.__mode===r)return this;const s=this.getWritable();return s.__mode=r,s}setTextContent(e){if(this.__text===e)return this;const r=this.getWritable();return r.__text=e,r}select(e,r){yt();let s=e,l=r;const u=de(),c=this.getTextContent(),f=this.__key;if(typeof c=="string"){const h=c.length;s===void 0&&(s=h),l===void 0&&(l=h)}else s=0,l=0;if(!ee(u))return Wv(f,s,f,l,"text","text");{const h=lr();h!==u.anchor.key&&h!==u.focus.key||ft(f),u.setTextNodeRange(this,s,this,l)}return u}selectStart(){return this.select(0,0)}selectEnd(){const e=this.getTextContentSize();return this.select(e,e)}spliceText(e,r,s,l){const u=this.getWritable(),c=u.__text,f=s.length;let h=e;h<0&&(h=f+h,h<0&&(h=0));const g=de();if(l&&ee(g)){const v=e+f;g.setTextNodeRange(u,v,u,v)}const m=c.slice(0,h)+s+c.slice(h+r);return u.__text=m,u}canInsertTextBefore(){return!0}canInsertTextAfter(){return!0}splitText(...e){yt();const r=this.getLatest(),s=r.getTextContent();if(s==="")return[];const l=r.__key,u=lr(),c=s.length;e.sort((F,z)=>F-z),e.push(c);const f=[],h=e.length;for(let F=0,z=0;FF&&(f.push(s.slice(F,J)),F=J)}const g=f.length;if(g===1)return[r];const m=f[0],v=r.getParent();let y;const _=r.getFormat(),S=r.getStyle(),w=r.__detail;let C=!1,T=null,N=null;const M=de();if(ee(M)){const[F,z]=M.isBackward()?[M.focus,M.anchor]:[M.anchor,M.focus];F.type==="text"&&F.key===l&&(T=F),z.type==="text"&&z.key===l&&(N=z)}r.isSegmented()?(y=ct(m),y.__format=_,y.__style=S,y.__detail=w,y.__state=Zg(r,y),C=!0):y=r.setTextContent(m);const L=[y];for(let F=1;F=$&&(T.set(F.getKey(),j-$,"text"),j=$){N.set(F.getKey(),D-$,"text");break}$=z}if(v!==null){(function(J){const te=J.getPreviousSibling(),ne=J.getNextSibling();te!==null&&uu(te),ne!==null&&uu(ne)})(this);const F=v.getWritable(),z=this.getIndexWithinParent();C?(F.splice(z,0,L),this.remove()):F.splice(z,1,L),ee(M)&&su(M,v,z,g-1)}return L}mergeWithSibling(e){const r=e===this.getPreviousSibling();r||e===this.getNextSibling()||q(50);const s=this.__key,l=e.__key,u=this.__text,c=u.length;lr()===l&&ft(s);const f=de();if(ee(f)){const v=f.anchor,y=f.focus;v!==null&&v.key===l&&Cm(v,r,s,e,c),y!==null&&y.key===l&&Cm(y,r,s,e,c)}const h=e.__text,g=r?h+u:u+h;this.setTextContent(g);const m=this.getWritable();return e.remove(),m}isTextEntity(){return!1}}function bC(t){return{forChild:nd(t.style),node:null}}function RC(t){const e=t,r=e.style.fontWeight==="normal";return{forChild:nd(e.style,r?void 0:"bold"),node:null}}const pm=new WeakMap;function DC(t){if(!Pt(t))return!1;if(t.nodeName==="PRE")return!0;const e=t.style.whiteSpace;return typeof e=="string"&&e.startsWith("pre")}function jC(t){const e=t;t.parentElement===null&&q(129);let r=e.textContent||"";if((function(s){let l,u=s.parentNode;const c=[s];for(;u!==null&&(l=pm.get(u))===void 0&&!DC(u);)c.push(u),u=u.parentNode;const f=l===void 0?u:l;for(let h=0;h0){/[ \t\n]$/.test(u)&&(r=r.slice(1)),l=!1;break}}l&&(r=r.slice(1))}if(r[r.length-1]===" "){let s=e,l=!0;for(;s!==null&&(s=pm(s,!0))!==null;)if((s.textContent||"").replace(/^( |\t|\r?\n)+/,"").length>0){l=!1;break}l&&(r=r.slice(0,r.length-1))}return r===""?{node:null}:{node:ct(r)}}function pm(t,e){let r=t;for(;;){let s;for(;(s=e?r.nextSibling:r.previousSibling)===null;){const u=r.parentElement;if(u===null)return null;r=u}if(r=s,Pt(r)){const u=r.style.display;if(u===""&&!r1(r)||u!==""&&!u.startsWith("inline"))return null}let l=r;for(;(l=e?r.firstChild:r.lastChild)!==null;)r=l;if(zn(r))return r;if(r.nodeName==="BR")return null}}const jC={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function Rn(t){const e=jC[t.nodeName.toLowerCase()];return e===void 0?{node:null}:{forChild:nd(t.style,e),node:null}}function ct(t=""){return Nu(new mr(t))}function re(t){return t instanceof mr}function nd(t,e){const r=t.fontWeight,s=t.textDecoration.split(" "),l=r==="700"||r==="bold",u=s.includes("line-through"),c=t.fontStyle==="italic",f=s.includes("underline"),h=t.verticalAlign;return g=>(re(g)&&(l&&!g.hasFormat("bold")&&g.toggleFormat("bold"),u&&!g.hasFormat("strikethrough")&&g.toggleFormat("strikethrough"),c&&!g.hasFormat("italic")&&g.toggleFormat("italic"),f&&!g.hasFormat("underline")&&g.toggleFormat("underline"),h!=="sub"||g.hasFormat("subscript")||g.toggleFormat("subscript"),h!=="super"||g.hasFormat("superscript")||g.toggleFormat("superscript"),e&&!g.hasFormat(e)&&g.toggleFormat(e)),g)}class Qi extends mr{static getType(){return"tab"}static clone(e){return new Qi(e.__key)}constructor(e){super(" ",e),this.__detail=2}static importDOM(){return null}createDOM(e){const r=super.createDOM(e),s=Ii(e.theme,"tab");return s!==void 0&&r.classList.add(...s),r}static importJSON(e){return rd().updateFromJSON(e)}setTextContent(e){return e!==" "&&e!==""&&Jy(126),super.setTextContent(" ")}spliceText(e,r,s,l){return s===""&&r===0||s===" "&&r===1||q(286),this}setDetail(e){return e!==2&&q(127),this}setMode(e){return e!=="normal"&&q(128),this}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}}function rd(){return Nu(new Qi)}function $v(t){return t instanceof Qi}class FC{key;offset;type;_selection;constructor(e,r,s){this._selection=null,this.key=e,this.offset=r,this.type=s}is(e){return this.key===e.key&&this.offset===e.offset&&this.type===e.type}isBefore(e){return this.key===e.key?this.offsetu&&(s=u)}else if(!K(e)){const u=e.getNextSibling();if(re(u))r=u.__key,s=0,l="text";else{const c=e.getParent();c&&(r=c.__key,s=e.getIndexWithinParent()+1)}}t.set(r,s,l)}function gm(t,e){if(K(e)){const r=e.getLastDescendant();K(r)||re(r)?Fc(t,r):Fc(t,e)}else Fc(t,e)}class vu{_nodes;_cachedNodes;dirty;constructor(e){this._cachedNodes=null,this._nodes=e,this.dirty=!1}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){if(!xu(e))return!1;const r=this._nodes,s=e._nodes;return r.size===s.size&&Array.from(r).every(l=>s.has(l))}isCollapsed(){return!1}isBackward(){return!1}getStartEndPoints(){return null}add(e){this.dirty=!0,this._nodes.add(e),this._cachedNodes=null}delete(e){this.dirty=!0,this._nodes.delete(e),this._cachedNodes=null}clear(){this.dirty=!0,this._nodes.clear(),this._cachedNodes=null}has(e){return this._nodes.has(e)}clone(){return new vu(new Set(this._nodes))}extract(){return this.getNodes()}insertRawText(e){}insertText(){}insertNodes(e){const r=this.getNodes(),s=r.length,l=r[s-1];let u;if(re(l))u=l.select();else{const c=l.getIndexWithinParent()+1;u=l.getParentOrThrow().select(c,c)}u.insertNodes(e);for(let c=0;c1;){const g=l[l.length-1];if(!K(g)||h.has(g)||g.isEmpty()||f.has(g))break;l.pop()}if(l.length===0&&s.isCollapsed()){const g=yn(s.anchor),m=yn(s.anchor.getFlipped()),v=S=>ar(S)?S.origin:S.getNodeAtCaret(),y=v(g)||v(m)||(s.anchor.getNodeAtCaret()?g.origin:m.origin);l.push(y)}return l})(xd(Rf(this),"next"));return uo()||(this._cachedNodes=r),r}setTextNodeRange(e,r,s,l){this.anchor.set(e.__key,r,"text"),this.focus.set(s.__key,l,"text")}getTextContent(){const e=this.getNodes();if(e.length===0)return"";const r=e[0],s=e[e.length-1],l=this.anchor,u=this.focus,c=l.isBefore(u),[f,h]=Tf(this);let g="",m=!0;for(let v=0;v0){/[ \t\n]$/.test(u)&&(r=r.slice(1)),l=!1;break}}l&&(r=r.slice(1))}if(r[r.length-1]===" "){let s=e,l=!0;for(;s!==null&&(s=gm(s,!0))!==null;)if((s.textContent||"").replace(/^( |\t|\r?\n)+/,"").length>0){l=!1;break}l&&(r=r.slice(0,r.length-1))}return r===""?{node:null}:{node:ct(r)}}function gm(t,e){let r=t;for(;;){let s;for(;(s=e?r.nextSibling:r.previousSibling)===null;){const u=r.parentElement;if(u===null)return null;r=u}if(r=s,Pt(r)){const u=r.style.display;if(u===""&&!i1(r)||u!==""&&!u.startsWith("inline"))return null}let l=r;for(;(l=e?r.firstChild:r.lastChild)!==null;)r=l;if(zn(r))return r;if(r.nodeName==="BR")return null}}const FC={code:"code",em:"italic",i:"italic",mark:"highlight",s:"strikethrough",strong:"bold",sub:"subscript",sup:"superscript",u:"underline"};function Rn(t){const e=FC[t.nodeName.toLowerCase()];return e===void 0?{node:null}:{forChild:nd(t.style,e),node:null}}function ct(t=""){return Nu(new mr(t))}function re(t){return t instanceof mr}function nd(t,e){const r=t.fontWeight,s=t.textDecoration.split(" "),l=r==="700"||r==="bold",u=s.includes("line-through"),c=t.fontStyle==="italic",f=s.includes("underline"),h=t.verticalAlign;return g=>(re(g)&&(l&&!g.hasFormat("bold")&&g.toggleFormat("bold"),u&&!g.hasFormat("strikethrough")&&g.toggleFormat("strikethrough"),c&&!g.hasFormat("italic")&&g.toggleFormat("italic"),f&&!g.hasFormat("underline")&&g.toggleFormat("underline"),h!=="sub"||g.hasFormat("subscript")||g.toggleFormat("subscript"),h!=="super"||g.hasFormat("superscript")||g.toggleFormat("superscript"),e&&!g.hasFormat(e)&&g.toggleFormat(e)),g)}class Qi extends mr{static getType(){return"tab"}static clone(e){return new Qi(e.__key)}constructor(e){super(" ",e),this.__detail=2}static importDOM(){return null}createDOM(e){const r=super.createDOM(e),s=Ii(e.theme,"tab");return s!==void 0&&r.classList.add(...s),r}static importJSON(e){return rd().updateFromJSON(e)}setTextContent(e){return e!==" "&&e!==""&&Yy(126),super.setTextContent(" ")}spliceText(e,r,s,l){return s===""&&r===0||s===" "&&r===1||q(286),this}setDetail(e){return e!==2&&q(127),this}setMode(e){return e!=="normal"&&q(128),this}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}}function rd(){return Nu(new Qi)}function Bv(t){return t instanceof Qi}class IC{key;offset;type;_selection;constructor(e,r,s){this._selection=null,this.key=e,this.offset=r,this.type=s}is(e){return this.key===e.key&&this.offset===e.offset&&this.type===e.type}isBefore(e){return this.key===e.key?this.offsetu&&(s=u)}else if(!K(e)){const u=e.getNextSibling();if(re(u))r=u.__key,s=0,l="text";else{const c=e.getParent();c&&(r=c.__key,s=e.getIndexWithinParent()+1)}}t.set(r,s,l)}function mm(t,e){if(K(e)){const r=e.getLastDescendant();K(r)||re(r)?Fc(t,r):Fc(t,e)}else Fc(t,e)}class vu{_nodes;_cachedNodes;dirty;constructor(e){this._cachedNodes=null,this._nodes=e,this.dirty=!1}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){if(!xu(e))return!1;const r=this._nodes,s=e._nodes;return r.size===s.size&&Array.from(r).every(l=>s.has(l))}isCollapsed(){return!1}isBackward(){return!1}getStartEndPoints(){return null}add(e){this.dirty=!0,this._nodes.add(e),this._cachedNodes=null}delete(e){this.dirty=!0,this._nodes.delete(e),this._cachedNodes=null}clear(){this.dirty=!0,this._nodes.clear(),this._cachedNodes=null}has(e){return this._nodes.has(e)}clone(){return new vu(new Set(this._nodes))}extract(){return this.getNodes()}insertRawText(e){}insertText(){}insertNodes(e){const r=this.getNodes(),s=r.length,l=r[s-1];let u;if(re(l))u=l.select();else{const c=l.getIndexWithinParent()+1;u=l.getParentOrThrow().select(c,c)}u.insertNodes(e);for(let c=0;c1;){const g=l[l.length-1];if(!K(g)||h.has(g)||g.isEmpty()||f.has(g))break;l.pop()}if(l.length===0&&s.isCollapsed()){const g=yn(s.anchor),m=yn(s.anchor.getFlipped()),v=_=>ar(_)?_.origin:_.getNodeAtCaret(),y=v(g)||v(m)||(s.anchor.getNodeAtCaret()?g.origin:m.origin);l.push(y)}return l})(xd(Rf(this),"next"));return uo()||(this._cachedNodes=r),r}setTextNodeRange(e,r,s,l){this.anchor.set(e.__key,r,"text"),this.focus.set(s.__key,l,"text")}getTextContent(){const e=this.getNodes();if(e.length===0)return"";const r=e[0],s=e[e.length-1],l=this.anchor,u=this.focus,c=l.isBefore(u),[f,h]=Tf(this);let g="",m=!0;for(let v=0;v=0;F--){const z=L[F];if(z.is(y)||K(z)&&z.isParentOf(y))break;z.isAttached()&&(!j.has(z)||z.is(M)?D||$.insertAfter(z,!1):z.remove())}if(!D){let F=N,z=null;for(;F!==null;){const J=F.getChildren(),te=J.length;(te===0||J[te-1].is(z))&&(C.delete(F.__key),z=F),F=F.getParent()}}if(zr(y))if(h===S)y.select();else{const F=ct(e);F.select(),y.replace(F)}else y=y.spliceText(h,S-h,e,!0),y.getTextContent()===""?y.remove():this.anchor.type==="text"&&(this.format=y.getFormat(),this.style=y.getStyle(),y.isComposing()&&(this.anchor.offset-=e.length));for(let F=1;F{s.forEach(j=>{if(K(j)){const D=j.getFormatFlags(e,L);j.setTextFormat(D)}})},c=l.length;if(c===0)return this.toggleFormat(e),ft(null),void u(r);const f=this.anchor,h=this.focus,g=this.isBackward(),m=g?h:f,v=g?f:h;let y=0,S=l[0],_=m.type==="element"?0:m.offset;if(m.type==="text"&&_===S.getTextContentSize()&&(y=1,S=l[1],_=0),S==null)return;const w=S.getFormatFlags(e,r);u(w);const C=c-1;let T=l[C];const N=v.type==="text"?v.offset:T.getTextContentSize();if(S.is(T)){if(_===N)return;if(jn(S)||_===0&&N===S.getTextContentSize())S.setFormat(w);else{const L=S.splitText(_,N),j=_===0?L[0]:L[1];j.setFormat(w),m.type==="text"&&m.set(j.__key,0,"text"),v.type==="text"&&v.set(j.__key,N-_,"text")}return void(this.format=w)}_===0||jn(S)||([,S]=S.splitText(_),_=0),S.setFormat(w);const M=T.getFormatFlags(e,w);N>0&&(N===T.getTextContentSize()||jn(T)||([T]=T.splitText(N)),T.setFormat(M));for(let L=y+1;L(K(_)||Ie(_))&&!_.isInline())){K(s)||q(211,r.constructor.name,r.getType());const _=Ic(this);return s.splice(_,0,e),void l.selectEnd()}const u=(function(_){const w=nn();let C=null;for(let T=0;T<_.length;T++){const N=_[T],M=Us(N);if(M||Ie(N)&&N.isInline()||K(N)&&N.isInline()||re(N)||N.isParentRequired()){if(C===null&&(C=N.createParentElementNode(),w.append(C),M))continue;C!==null&&C.append(N)}else w.append(N),C=null}return w})(e),c=u.getLastDescendant(),f=u.getChildren(),h=!K(s)||!s.isEmpty()?this.insertParagraph():null,g=f[f.length-1];let m=f[0];var v;K(v=m)&&or(v)&&!v.isEmpty()&&K(s)&&(!s.isEmpty()||s.canMergeWhenEmpty())&&(K(s)||q(211,r.constructor.name,r.getType()),s.append(...m.getChildren()),m=f[1]),m&&(s===null&&q(212,r.constructor.name,r.getType()),(function(_,w){const C=w.getParentOrThrow().getLastChild();let T=w;const N=[w];for(;T!==C;)T.getNextSibling()||q(140),T=T.getNextSibling(),N.push(T);let M=_;for(const L of N)M=M.insertAfter(L)})(s,m));const y=Ql(c,or);h&&K(y)&&(h.canMergeWhenEmpty()||or(g))&&(y.append(...h.getChildren()),h.remove()),K(s)&&s.isEmpty()&&s.remove(),c.selectEnd();const S=K(s)?s.getLastChild():null;Us(S)&&y!==s&&S.remove()}insertParagraph(){if(this.anchor.key==="root"){const c=nn();return tt().splice(this.anchor.offset,0,[c]),c.select(),c}const e=Ic(this),r=Ql(this.anchor.getNode(),or);K(r)||q(213);const s=r.getChildAtIndex(e),l=s?[s,...s.getNextSiblings()]:[],u=r.insertNewAfter(this,!1);return u?(u.append(...l),u.selectStart(),u):null}insertLineBreak(e){const r=to();if(this.insertNodes([r]),e){const s=r.getParentOrThrow(),l=r.getIndexWithinParent();s.select(l,l)}}extract(){const e=[...this.getNodes()],r=e.length;let s=e[0],l=e[r-1];const[u,c]=Tf(this),f=this.isBackward(),[h,g]=f?[this.focus,this.anchor]:[this.anchor,this.focus],[m,v]=f?[c,u]:[u,c];if(r===0)return[];if(r===1){if(re(s)&&!this.isCollapsed()){const y=s.splitText(m,v),S=m===0?y[0]:y[1];return S?(h.set(S.getKey(),0,"text"),g.set(S.getKey(),S.getTextContentSize(),"text"),[S]):[]}return[s]}if(re(s)&&(m===s.getTextContentSize()?e.shift():m!==0&&([,s]=s.splitText(m),e[0]=s,h.set(s.getKey(),0,"text"))),re(l)){const y=l.getTextContent().length;v===0?e.pop():v!==y&&([l]=l.splitText(v),e[e.length-1]=l,g.set(l.getKey(),l.getTextContentSize(),"text"))}return e}modify(e,r,s){if(km(this,e,r,s))return;const l=e==="move",u=Le(),c=un(Lt(u));if(!c)return;const f=u._blockCursorElement,h=u._rootElement,g=this.focus.getNode();if(h===null||f===null||!K(g)||g.isInline()||g.canBeEmpty()||Pf(f,u,h),this.dirty){let m=Bi(u,this.anchor.key),v=Bi(u,this.focus.key);this.anchor.type==="text"&&(m=$i(m)),this.focus.type==="text"&&(v=$i(v)),m&&v&&Hv(c,m,this.anchor.offset,v,this.focus.offset)}if((function(m,v,y,S){m.modify(v,y,S)})(c,e,r?"backward":"forward",s),c.rangeCount>0){const m=c.getRangeAt(0),v=this.anchor.getNode(),y=lt(v)?v:ZC(v);if(this.applyDOMRange(m),this.dirty=!0,!l){const S=this.getNodes(),_=[];let w=!1;for(let C=0;C0)if(r){const C=_[0];K(C)?C.selectStart():C.getParentOrThrow().selectStart()}else{const C=_[_.length-1];K(C)?C.selectEnd():C.getParentOrThrow().selectEnd()}c.anchorNode===m.startContainer&&c.anchorOffset===m.startOffset||(function(C){const T=C.focus,N=C.anchor,M=N.key,L=N.offset,j=N.type;N.set(T.key,T.offset,T.type,!0),T.set(M,L,j,!0)})(this)}}s==="lineboundary"&&km(this,e,r,s,"decorators")}forwardDeletion(e,r,s){if(!s&&(e.type==="element"&&K(r)&&e.offset===r.getChildrenSize()||e.type==="text"&&e.offset===r.getTextContentSize())){const l=r.getParent(),u=r.getNextSibling()||(l===null?null:l.getNextSibling());if(K(u)&&u.isShadowRoot())return!0}return!1}deleteCharacter(e){const r=this.isCollapsed();if(this.isCollapsed()){const s=this.anchor;let l=s.getNode();if(this.forwardDeletion(s,l,e))return;const u=vd(pr(s,e?"previous":"next"));if(u.getTextSlices().every(f=>f===null||f.distance===0)){let f={type:"initial"};for(const h of u.iterNodeCarets("shadowRoot"))if(rn(h)){if(!h.origin.isInline()){if(h.origin.isShadowRoot()){if(f.type==="merge-block")break;if(K(u.anchor.origin)&&u.anchor.origin.isEmpty()){const g=yn(h);ql(this,Vr(g,g)),u.anchor.origin.remove()}return}f.type!=="merge-next-block"&&f.type!=="merge-block"||(f={block:f.block,caret:h,type:"merge-block"})}}else{if(f.type==="merge-block")break;if(Ki(h)){if(K(h.origin)){if(h.origin.isInline()){if(!h.origin.isParentOf(u.anchor.origin))break}else f={block:h.origin,type:"merge-next-block"};continue}if(Ie(h.origin)){if(!h.origin.isIsolated())if(f.type==="merge-next-block"&&(h.origin.isKeyboardSelectable()||!h.origin.isInline())&&K(u.anchor.origin)&&u.anchor.origin.isEmpty()){u.anchor.origin.remove();const g=Wv();g.add(h.origin.getKey()),It(g)}else h.origin.remove();return}break}}if(f.type==="merge-block"){const{caret:h,block:g}=f;return ql(this,Vr(!h.origin.isEmpty()&&g.isEmpty()?go(dt(g,h.direction)):u.anchor,h)),this.removeText()}}const c=this.focus;if(this.modify("extend",e,"character"),this.isCollapsed()){if(e&&s.offset===0&&ym(this,s.getNode()))return}else{const f=c.type==="text"?c.getNode():null;if(l=s.type==="text"?s.getNode():null,f!==null&&f.isSegmented()){const h=c.offset,g=f.getTextContentSize();if(f.is(l)||e&&h!==g||!e&&h!==0)return void vm(f,e,h)}else if(l!==null&&l.isSegmented()){const h=s.offset,g=l.getTextContentSize();if(l.is(f)||e&&h!==0||!e&&h!==g)return void vm(l,e,h)}(function(h,g){const m=h.anchor,v=h.focus,y=m.getNode(),S=v.getNode();if(y===S&&m.type==="text"&&v.type==="text"){const _=m.offset,w=v.offset,C=_{try{const t=new RegExp("\\p{Emoji}","u"),e=t.test.bind(t);if(e("❤️")&&e("#️⃣")&&e("👍"))return e}catch{}return()=>!1})();function vm(t,e,r){const s=t,l=s.getTextContent().split(/(?=\s)/g),u=l.length;let c=0,f=0;for(let g=0;gr||m){l.splice(g,1),m&&(f=void 0);break}}const h=l.join("").trim();h===""?s.remove():(s.setTextContent(h),s.select(f,f))}function xm(t,e,r,s){let l,u=e;if(Pt(t)){let c=!1;const f=t.childNodes,h=f.length,g=s._blockCursorElement;u===h&&(c=!0,u=h-1);let m=f[u],v=!1;if(m===g)m=f[u+1],v=!0;else if(g!==null){const y=g.parentNode;t===y&&e>Array.prototype.indexOf.call(y.children,g)&&u--}if(l=bi(m),re(l))u=xn(l,c?"next":"previous");else{let y=bi(t);if(y===null)return null;if(K(y)){const S=s.getElementByKey(y.getKey());S===null&&q(214),[y,u]=po(s).$getDOMSlot(y,S,s).resolveChildIndex(y,S,t,e),K(y)||q(215),c&&u>=y.getChildrenSize()&&(u=Math.max(0,y.getChildrenSize()-1));let w=y.getChildAtIndex(u);if(K(w)&&(function(C,T,N){const M=C.getParent();return N===null||M===null||!M.canBeEmpty()||M!==N.getNode()})(w,0,r)){const C=c?w.getLastDescendant():w.getFirstDescendant();C===null?y=w:(w=C,y=K(w)?w:w.getParentOrThrow()),u=0}re(w)?(l=w,y=null,u=xn(w,c?"next":"previous")):w!==y&&c&&!v&&(K(y)||q(216),u=Math.min(y.getChildrenSize(),u+1))}else{const S=y.getIndexWithinParent();u=e===0&&Ie(y)&&bi(t)===y?S:S+1,y=y.getParentOrThrow()}if(K(y))return _n(y.__key,u,"element")}}else l=bi(t);return re(l)?_n(l.__key,xn(l,u,"clamp"),"text"):null}function _m(t,e,r){const s=t.offset,l=t.getNode();if(s===0){const u=l.getPreviousSibling(),c=l.getParent();if(e){if((r||!e)&&u===null&&K(c)&&c.isInline()){const f=c.getPreviousSibling();re(f)&&t.set(f.__key,f.getTextContent().length,"text")}}else K(u)&&!r&&u.isInline()?t.set(u.__key,u.getChildrenSize(),"element"):re(u)&&t.set(u.__key,u.getTextContent().length,"text")}else if(s===l.getTextContent().length){const u=l.getNextSibling(),c=l.getParent();if(e&&K(u)&&u.isInline())t.set(u.__key,0,"element");else if((r||e)&&u===null&&K(c)&&c.isInline()&&!c.canInsertTextAfter()){const f=c.getNextSibling();re(f)&&t.set(f.__key,0,"text")}}}function Bv(t,e,r){if(t.type==="text"&&e.type==="text"){const s=t.isBefore(e),l=t.is(e);_m(t,s,l),_m(e,!s,l),l&&e.set(t.key,t.offset,t.type)}}function Uv(t,e,r,s,l,u){if(t===null||r===null||!Su(l,t,r))return null;const c=xm(t,e,ee(u)?u.anchor:null,l);if(c===null)return null;const f=xm(r,s,ee(u)?u.focus:null,l);if(f===null)return null;if(c.type==="element"&&f.type==="element"){const h=bi(t),g=bi(r);if(Ie(h)&&Ie(g))return null}return Bv(c,f),[c,f]}function Kv(t,e,r,s,l,u){const c=yr(),f=new Jr(_n(t,e,l),_n(r,s,u),0,"");return f.dirty=!0,c._selection=f,f}function LC(){const t=_n("root",0,"element"),e=_n("root",0,"element");return new Jr(t,e,0,"")}function Wv(){return new vu(new Set)}function id(t,e,r,s){const l=r._window;if(l===null)return null;const u=s||l.event,c=u?u.type:void 0,f=c==="selectionchange",h=!af&&(f||c==="beforeinput"||c==="compositionstart"||c==="compositionend"||c==="click"&&u&&u.detail===3||c==="drop"||c===void 0);let g,m,v,y;if(ee(t)&&!h)return t.clone();if(e===null)return null;if(g=e.anchorNode,m=e.focusNode,v=e.anchorOffset,y=e.focusOffset,(f||c===void 0)&&ee(t)&&!Su(r,g,m))return t.clone();const S=Uv(g,v,m,y,r,t);if(S===null)return null;const[_,w]=S;let C=0,T="";if(ee(t)){const N=t.anchor;if(_.key===N.key)C=t.format,T=t.style;else{const M=_.getNode();re(M)?(C=M.getFormat(),T=M.getStyle()):K(M)&&(C=M.getTextFormat(),T=M.getTextStyle())}}return new Jr(_,w,C,T)}function de(){return yr()._selection}function lo(){return Le()._editorState._selection}function su(t,e,r,s=1){const l=t.anchor,u=t.focus,c=l.getNode(),f=u.getNode();if(!e.is(c)&&!e.is(f))return;const h=e.__key;if(t.isCollapsed()){const g=l.offset;if(r<=g&&s>0||r0||r<_&&s<0)&&m.set(h,Math.max(0,_+s),"element")}if(e.is(S)){const _=y.offset;(r<=_&&s>0||r<_&&s<0)&&y.set(h,Math.max(0,_+s),"element")}}Sm(t)}function Sm(t){const e=t.anchor,r=e.offset,s=t.focus,l=s.offset,u=e.getNode(),c=s.getNode();if(t.isCollapsed()){if(!K(u))return;const f=u.getChildrenSize(),h=r>=f,g=h?u.getChildAtIndex(f-1):u.getChildAtIndex(r);if(re(g)){let m=0;h&&(m=g.getTextContentSize()),e.set(g.__key,m,"text"),s.set(g.__key,m,"text")}return}if(K(u)){const f=u.getChildrenSize(),h=r>=f,g=h?u.getChildAtIndex(f-1):u.getChildAtIndex(r);if(re(g)){let m=0;h&&(m=g.getTextContentSize()),e.set(g.__key,m,"text")}}if(K(c)){const f=c.getChildrenSize(),h=l>=f,g=h?c.getChildAtIndex(f-1):c.getChildAtIndex(l);if(re(g)){let m=0;h&&(m=g.getTextContentSize()),s.set(g.__key,m,"text")}}}function ou(t,e,r,s,l){let u=null,c=0,f=null;s!==null?(u=s.__key,re(s)?(c=s.getTextContentSize(),f="text"):K(s)&&(c=s.getChildrenSize(),f="element")):l!==null&&(u=l.__key,re(l)?f="text":K(l)&&(f="element")),u!==null&&f!==null?t.set(u,c,f):(c=e.getIndexWithinParent(),c===-1&&(c=r.getChildrenSize()),t.set(r.__key,c,"element"))}function wm(t,e,r,s,l){t.type==="text"?t.set(r,t.offset+(e?0:l),"text"):t.offset>s.getIndexWithinParent()&&t.set(t.key,t.offset-1,"element")}function Hv(t,e,r,s,l){try{t.setBaseAndExtent(e,r,s,l)}catch{}}function Cm(t,e,r){const s=Bi(t,e.getKey());if(K(e)){const l=po(t).$getDOMSlot(e,s,t);return[l.element,r+l.getFirstChildOffset()]}return[s,r]}function AC(t,e,r,s,l,u,c){const f=s.anchorNode,h=s.focusNode,g=s.anchorOffset,m=s.focusOffset,v=document.activeElement;if(l.has(EC)&&v!==u||v!==null&&l0(v))return;if(!ee(e))return void(t!==null&&Su(r,f,h)&&s.removeAllRanges());const y=e.anchor,S=e.focus,_=y.getNode(),w=S.getNode(),[C,T]=Cm(r,_,y.offset),[N,M]=Cm(r,w,S.offset),L=e.format,j=e.style,D=e.isCollapsed();let $=C,F=N,z=!1;var J,te,ne,X,ae;if(y.type==="text"?($=$i(C),z=_.getFormat()!==L||_.getStyle()!==j):ee(t)&&t.anchor.type==="text"&&(z=!0),S.type==="text"&&(F=$i(N)),$!==null&&F!==null&&(D&&(t===null||z||ee(t)&&(t.format!==L||t.style!==j))&&(J=L,te=j,ne=T,X=y.key,ae=performance.now(),Mv=[J,te,ne,X,ae]),g!==T||m!==M||f!==$||h!==F||s.type==="Range"&&D||(v!==null&&u.contains(v)||l.has(Nf)||u.focus({preventScroll:!0}),y.type==="element"))){if(Hv(s,$,T,F,M),!fr||!e.isCollapsed()||u===null||l.has(Nf)||document.activeElement!==null&&u.contains(document.activeElement)||u.focus({preventScroll:!0}),!l.has(NC)&&e.isCollapsed()&&u!==null&&u===document.activeElement){const Se=ee(e)&&e.anchor.type==="element"?$.childNodes[T]||null:s.rangeCount>0?s.getRangeAt(0):null;if(Se!==null){let ye;if(Se instanceof Text){const _e=document.createRange();_e.selectNode(Se),ye=_e.getBoundingClientRect()}else ye=Se.getBoundingClientRect();(function(_e,Z,W){const Q=y0(W),P=hd(Q);if(Q===null||P===null)return;let{top:U,bottom:he}=Z,ve=0,we=0,Ce=W;for(;Ce!==null;){const Me=Ce===Q.body;if(Me){ve=0,we=Lt(_e).innerHeight;const Te=P.getComputedStyle(Q.documentElement),qe=parseFloat(Te.scrollPaddingTop),xr=parseFloat(Te.scrollPaddingBottom);isFinite(qe)&&(ve+=qe),isFinite(xr)&&(we-=xr)}else{const Te=Ce.getBoundingClientRect();ve=Te.top,we=Te.bottom}let Ee=0;if(Uwe&&(Ee=he-we),Ee!==0)if(Me)P.scrollBy(0,Ee);else{const Te=Ce.scrollTop;Ce.scrollTop+=Ee;const qe=Ce.scrollTop-Te;U-=qe,he-=qe}if(Me)break;Ce=fo(Ce)}})(r,ye,u)}}wf=!0}}function Ic(t){let e=t;t.isCollapsed()||e.removeText();const r=de();ee(r)&&(e=r),ee(e)||q(161);const s=e.anchor;let l=s.getNode(),u=s.offset;for(;!or(l);){const c=l;if([l,u]=zC(l,u),c.is(l))break}return u}function zC(t,e){const r=t.getParent();if(!r){const l=nn();return tt().append(l),l.select(),[tt(),0]}if(re(t)){const l=t.splitText(e);if(l.length===0)return[r,t.getIndexWithinParent()];const u=e===0?0:1;return[r,l[0].getIndexWithinParent()+u]}if(!K(t)||e===0)return[r,t.getIndexWithinParent()];const s=t.getChildAtIndex(e);if(s){const l=new Jr(_n(t.__key,e,"element"),_n(t.__key,e,"element"),0,""),u=t.insertNewAfter(l);u&&u.append(s,...s.getNextSiblings())}return[r,t.getIndexWithinParent()+1]}function km(t,e,r,s,l="decorators-and-blocks"){if(e==="move"&&s==="character"&&!t.isCollapsed()){const[m,v]=r===t.isBackward()?[t.focus,t.anchor]:[t.anchor,t.focus];return v.set(m.key,m.offset,m.type),!0}const u=pr(t.focus,r?"previous":"next"),c=s==="lineboundary",f=e==="move";let h=u,g=l==="decorators-and-blocks";if(!C0(h)){for(const m of h){g=!1;const{origin:v}=m;if(!Ie(v)||v.isIsolated()||(h=m,!c||!v.isInline()))break}if(g)for(const m of vd(u).iterNodeCarets(e==="extend"?"shadowRoot":"root")){if(rn(m))m.origin.isInline()||(h=m);else{if(K(m.origin))continue;Ie(m.origin)&&!m.origin.isInline()&&(h=m)}break}}if(h===u)return!1;if(f&&!c&&Ie(h.origin)&&h.origin.isKeyboardSelectable()){const m=Wv();return m.add(h.origin.getKey()),It(m),!0}return h=yn(h),f&&io(t.anchor,h),io(t.focus,h),g||!c}let st=null,ot=null,Mt=!1,Lc=!1,Hl=0;const Em={characterData:!0,childList:!0,subtree:!0};function uo(){return Mt||st!==null&&st._readOnly}function yt(){Mt&&q(13)}function Qv(){Hl>99&&q(14)}function yr(){return st===null&&q(195,Vv()),st}function Le(){return ot===null&&q(337,Vv()),ot}function Vv(){let t=0;const e=new Set,r=zi.version;if(typeof window<"u")for(const l of document.querySelectorAll("[contenteditable]")){const u=wu(l);if(ud(u))t++;else if(u){let c=String(u.constructor.version||"<0.17.1");c===r&&(c+=" (separately built, likely a bundler configuration issue)"),e.add(c)}}let s=` Detected on the page: ${t} compatible editor(s) with version ${r}`;return e.size&&(s+=` and incompatible editors with versions ${Array.from(e).join(", ")}`),s}function $C(){return ot}function Nm(t,e,r){const s=e.__type,l=s0(t,s);let u=r.get(s);u===void 0&&(u=Array.from(l.transforms),r.set(s,u));const c=u.length;for(let f=0;f0&&Mm(t,t._deferred));const u=t._editorState,c=u._selection,f=r._selection,h=t._dirtyType!==0,g=st,m=Mt,v=ot,y=t._updating,S=t._observer;let _=null;if(t._pendingEditorState=null,t._editorState=r,!l&&h&&S!==null){ot=t,st=r,Mt=!1,t._updating=!0;try{const D=t._dirtyType,$=t._dirtyElements,F=t._dirtyLeaves;S.disconnect(),_=oC(u,r,t,D,$,F)}catch(D){if(D instanceof Error&&t._onError(D),Lc)throw D;return r0(t,null,s,r),rv(t),t._dirtyType=2,Lc=!0,Fn(t,u),void(Lc=!1)}finally{S.observe(s,Em),t._updating=y,st=g,Mt=m,ot=v}}r._readOnly||(r._readOnly=!0);const w=t._dirtyLeaves,C=t._dirtyElements,T=t._normalizedNodes,N=t._updateTags,M=t._deferred;h&&(t._dirtyType=0,t._cloneNotNeeded.clear(),t._dirtyLeaves=new Set,t._dirtyElements=new Map,t._normalizedNodes=new Set,t._updateTags=new Set),(function(D,$){const F=D._decorators;let z=D._pendingDecorators||F;const J=$._nodeMap;let te;for(te in z)J.has(te)||(z===F&&(z=f0(D)),delete z[te])})(t,r);const L=l?null:un(Lt(t));if(t._editable&&L!==null&&(h||f===null||f.dirty||!f.is(c))&&s!==null&&!N.has(TC)){ot=t,st=r;try{if(S!==null&&S.disconnect(),h||f===null||f.dirty){const D=t._blockCursorElement;D!==null&&Pf(D,t,s),AC(c,f,t,L,N,s)}(function(D,$,F){let z=D._blockCursorElement;if(ee(F)&&F.isCollapsed()&&F.anchor.type==="element"&&$.contains(document.activeElement)){const J=F.anchor,te=J.getNode(),ne=J.offset;let X=!1,ae=null;if(ne===te.getChildrenSize())zc(te.getChildAtIndex(ne-1))&&(X=!0);else{const Se=te.getChildAtIndex(ne);if(Se!==null&&zc(Se)){const ye=Se.getPreviousSibling();(ye===null||zc(ye))&&(X=!0,ae=D.getElementByKey(Se.__key))}}if(X){const Se=D.getElementByKey(te.__key);return z===null&&(D._blockCursorElement=z=(function(ye){const _e=ye.theme,Z=document.createElement("div");Z.contentEditable="false",Z.setAttribute("data-lexical-cursor","true");let W=_e.blockCursor;if(W!==void 0){if(typeof W=="string"){const Q=E0(W);W=_e.blockCursor=Q}W!==void 0&&Z.classList.add(...W)}return Z})(D._config)),$.style.caretColor="transparent",void(ae===null?Se.appendChild(z):Se.insertBefore(z,ae))}}z!==null&&Pf(z,D,$)})(t,s,f)}finally{S!==null&&S.observe(s,Em),ot=v,st=g}}_!==null&&(function(D,$,F,z,J){const te=Array.from(D._listeners.mutation),ne=te.length;for(let X=0;X=0;c--)for(let f=0;f0&&h._updating){u=h;break}const g=h._commands.get(e);if(g!==void 0){const m=g[c];if(m.size>0){let v=!1;if(vn(h,()=>{for(const y of m)if(y(r,s))return void(v=!0)}),v)return v}}}return u&&u.update(()=>{Jv(u,e,r,s)}),!1}function Mm(t,e){if(t._deferred=[],e.length!==0){const r=t._updating;t._updating=!0;try{for(let s=0;s0||ne>0;){if(J>0){M._dirtyLeaves=new Set;for(const X of z){const ae=D.get(X);re(ae)&&ae.isAttached()&&ae.isSimpleText()&&!ae.isUnmergeable()&&tm(ae),ae!==void 0&&Tm(ae,$)&&Nm(M,ae,F),L.add(X)}if(z=M._dirtyLeaves,J=z.size,J>0){Hl++;continue}}M._dirtyLeaves=new Set,M._dirtyElements=new Map,te.delete("root")&&te.set("root",!0);for(const X of te){const ae=X[0],Se=X[1];if(j.set(ae,Se),!Se)continue;const ye=D.get(ae);ye!==void 0&&Tm(ye,$)&&Nm(M,ye,F)}z=M._dirtyLeaves,J=z.size,te=M._dirtyElements,ne=te.size,Hl++}M._dirtyLeaves=L,M._dirtyElements=j})(h,t),Pm(t),(function(N,M,L,j){const D=N._nodeMap,$=M._nodeMap,F=[];for(const[z]of j){const J=$.get(z);J!==void 0&&(J.isAttached()||(K(J)&&ev(J,z,D,$,F,j),D.has(z)||j.delete(z),F.push(z)))}for(const z of F)$.delete(z);for(const z of L){const J=$.get(z);J===void 0||J.isAttached()||(D.has(z)||L.delete(z),$.delete(z))}})(f,h,t._dirtyLeaves,t._dirtyElements)),C!==t._compositionKey&&(h._flushSync=!0);const T=h._selection;if(ee(T)){const N=h._nodeMap,M=T.anchor.key,L=T.focus.key;N.get(M)!==void 0&&N.get(L)!==void 0||q(19)}else xu(T)&&T._nodes.size===0&&(h._selection=null)}catch(C){return C instanceof Error&&t._onError(C),t._pendingEditorState=f,t._dirtyType=2,t._cloneNotNeeded.clear(),t._dirtyLeaves=new Set,t._dirtyElements.clear(),void Fn(t)}finally{st=m,Mt=v,ot=y,t._updating=S,Hl=0}t._dirtyType!==0||t._deferred.length>0||(function(C,T){const N=T.getEditorState()._selection,M=C._selection;if(M!==null){if(M.dirty||!M.is(N))return!0}else if(N!==null)return!0;return!1})(h,t)?h._flushSync?(h._flushSync=!1,Fn(t)):g&&VC(()=>{Fn(t)}):(h._flushSync=!1,g&&(s.clear(),t._deferred=[],t._pendingEditorState=null))}function vn(t,e,r){ot===t&&r===void 0?e():_u(t,e,r)}class Ws{element;before;after;constructor(e,r,s){this.element=e,this.before=r||null,this.after=s||null}withBefore(e){return new Ws(this.element,e,this.after)}withAfter(e){return new Ws(this.element,this.before,e)}withElement(e){return this.element===e?this:new Ws(e,this.before,this.after)}insertChild(e){const r=this.before||this.getManagedLineBreak();return r!==null&&r.parentElement!==this.element&&q(222),this.element.insertBefore(e,r),this}removeChild(e){return e.parentElement!==this.element&&q(223),this.element.removeChild(e),this}replaceChild(e,r){return r.parentElement!==this.element&&q(224),this.element.replaceChild(e,r),this}getFirstChild(){const e=this.after?this.after.nextSibling:this.element.firstChild;return e===this.before||e===this.getManagedLineBreak()?null:e}getManagedLineBreak(){return this.element.__lexicalLineBreak||null}setManagedLineBreak(e){if(e===null)this.removeManagedLineBreak();else{const r=e==="decorator"&&(gu||oo||pu);this.insertManagedLineBreak(r)}}removeManagedLineBreak(){const e=this.getManagedLineBreak();if(e){const r=this.element,s=e.nodeName==="IMG"?e.nextSibling:null;s&&r.removeChild(s),r.removeChild(e),r.__lexicalLineBreak=void 0}}insertManagedLineBreak(e){const r=this.getManagedLineBreak();if(r){if(e===(r.nodeName==="IMG"))return;this.removeManagedLineBreak()}const s=this.element,l=this.before,u=document.createElement("br");if(s.insertBefore(u,l),e){const c=document.createElement("img");c.setAttribute("data-lexical-linebreak","true"),c.style.setProperty("display","inline","important"),c.style.setProperty("border","0px","important"),c.style.setProperty("margin","0px","important"),c.alt="",s.insertBefore(c,u),s.__lexicalLineBreak=c}else s.__lexicalLineBreak=u}getFirstChildOffset(){let e=0;for(let r=this.after;r!==null;r=r.previousSibling)e++;return e}resolveChildIndex(e,r,s,l){if(s===this.element){const h=this.getFirstChildOffset();return[e,Math.min(h+e.getChildrenSize(),Math.max(h,l))]}const u=bm(r,s);u.push(l);const c=bm(r,this.element);let f=e.getIndexWithinParent();for(let h=0;hm){f+=1;break}}return[e.getParentOrThrow(),f]}}function bm(t,e){const r=[];let s=e;for(;s!==t&&s!==null;s=s.parentNode){let l=0;for(let u=s.previousSibling;u!==null;u=u.previousSibling)l++;r.push(l)}return s!==t&&q(225),r.reverse()}class ao extends tn{__first;__last;__size;__format;__style;__indent;__dir;__textFormat;__textStyle;constructor(e){super(e),this.__first=null,this.__last=null,this.__size=0,this.__format=0,this.__style="",this.__indent=0,this.__dir=null,this.__textFormat=0,this.__textStyle=""}afterCloneFrom(e){super.afterCloneFrom(e),this.__key===e.__key&&(this.__first=e.__first,this.__last=e.__last,this.__size=e.__size),this.__indent=e.__indent,this.__format=e.__format,this.__style=e.__style,this.__dir=e.__dir,this.__textFormat=e.__textFormat,this.__textStyle=e.__textStyle}getFormat(){return this.getLatest().__format}getFormatType(){const e=this.getFormat();return Qw[e]||""}getStyle(){return this.getLatest().__style}getIndent(){return this.getLatest().__indent}getChildren(){const e=[];let r=this.getFirstChild();for(;r!==null;)e.push(r),r=r.getNextSibling();return e}getChildrenKeys(){const e=[];let r=this.getFirstChild();for(;r!==null;)e.push(r.__key),r=r.getNextSibling();return e}getChildrenSize(){return this.getLatest().__size}isEmpty(){return this.getChildrenSize()===0}isDirty(){const e=Le()._dirtyElements;return e!==null&&e.has(this.__key)}isLastChild(){const e=this.getLatest(),r=this.getParentOrThrow().getLastChild();return r!==null&&r.is(e)}getAllTextNodes(){const e=[];let r=this.getFirstChild();for(;r!==null;){if(re(r)&&e.push(r),K(r)){const s=r.getAllTextNodes();e.push(...s)}r=r.getNextSibling()}return e}getFirstDescendant(){let e=this.getFirstChild();for(;K(e);){const r=e.getFirstChild();if(r===null)break;e=r}return e}getLastDescendant(){let e=this.getLastChild();for(;K(e);){const r=e.getLastChild();if(r===null)break;e=r}return e}getDescendantByIndex(e){const r=this.getChildren(),s=r.length;if(e>=s){const u=r[s-1];return K(u)&&u.getLastDescendant()||u||null}const l=r[e];return K(l)&&l.getFirstDescendant()||l||null}getFirstChild(){const e=this.getLatest().__first;return e===null?null:et(e)}getFirstChildOrThrow(){const e=this.getFirstChild();return e===null&&q(45,this.__key),e}getLastChild(){const e=this.getLatest().__last;return e===null?null:et(e)}getLastChildOrThrow(){const e=this.getLastChild();return e===null&&q(96,this.__key),e}getChildAtIndex(e){const r=this.getChildrenSize();let s,l;if(e=e;){if(l===e)return s;s=s.getPreviousSibling(),l--}return null}getTextContent(){let e="";const r=this.getChildren(),s=r.length;for(let l=0;lr.remove()),e}append(...e){return this.splice(this.getChildrenSize(),0,e)}setDirection(e){const r=this.getWritable();return r.__dir=e,r}setFormat(e){return this.getWritable().__format=e!==""&&uf[e]||0,this}setStyle(e){return this.getWritable().__style=e||"",this}setTextFormat(e){const r=this.getWritable();return r.__textFormat=e,r}setTextStyle(e){const r=this.getWritable();return r.__textStyle=e,r}setIndent(e){return this.getWritable().__indent=e,this}splice(e,r,s){iu(this)&&q(324,this.__key,this.__type);const l=this.getChildrenSize(),u=this.getWritable();e+r<=l||q(226,String(e),String(r),String(l));const c=u.__key,f=[],h=[],g=this.getChildAtIndex(e+r);let m=null,v=l-r+s.length;if(e!==0)if(e===l)m=this.getLastChild();else{const S=this.getChildAtIndex(e);S!==null&&(m=S.getPreviousSibling())}if(r>0){let S=m===null?this.getFirstChild():m.getNextSibling();for(let _=0;_0&&(r.style.paddingInlineStart=40*s+"px");const l=this.getDirection();l&&(r.dir=l)}return{element:r}}exportJSON(){const e={children:[],direction:this.getDirection(),format:this.getFormatType(),indent:this.getIndent(),...super.exportJSON()},r=this.getTextFormat(),s=this.getTextStyle();return r===0&&s===""||An(this)||this.getChildren().some(re)||(r!==0&&(e.textFormat=r),s!==""&&(e.textStyle=s)),e}updateFromJSON(e){return super.updateFromJSON(e).setFormat(e.format).setIndent(e.indent).setDirection(e.direction).setTextFormat(e.textFormat||0).setTextStyle(e.textStyle||"")}insertNewAfter(e,r){return null}canIndent(){return!0}collapseAtStart(e){return!1}excludeFromCopy(e){return!1}canReplaceWith(e){return!0}canInsertAfter(e){return!0}canBeEmpty(){return!0}canInsertTextBefore(){return!0}canInsertTextAfter(){return!0}isInline(){return!1}isShadowRoot(){return!1}canMergeWith(e){return!1}extractWithChild(e,r,s){return!1}canMergeWhenEmpty(){return!1}reconcileObservedMutation(e,r){const s=po(r).$getDOMSlot(this,e,r);let l=s.getFirstChild();for(let u=this.getFirstChild();u;u=u.getNextSibling()){const c=r.getElementByKey(u.getKey());c!==null&&(l==null?(s.insertChild(c),l=c):l!==c&&s.replaceChild(c,l),l=l.nextSibling)}}}function K(t){return t instanceof ao}function Rm(t,e,r){let s=t.getNode();for(;s;){const l=s.__key;if(e.has(l)&&!r.has(l))return!0;s=s.getParent()}return!1}class Yv extends tn{decorate(e,r){return null}isIsolated(){return!1}isInline(){return!0}isKeyboardSelectable(){return!0}}function Ie(t){return t instanceof Yv}class Yr extends ao{__cachedText;static getType(){return"root"}static clone(){return new Yr}constructor(){super("root"),this.__cachedText=null}getTopLevelElementOrThrow(){q(51)}getTextContent(){const e=this.__cachedText;return!uo()&&Le()._dirtyType!==0||e===null?super.getTextContent():e}remove(){q(52)}replace(e){q(53)}insertBefore(e){q(54)}insertAfter(e){q(55)}updateDOM(e,r){return!1}splice(e,r,s){for(const l of s)K(l)||Ie(l)||q(282);return super.splice(e,r,s)}static importJSON(e){return tt().updateFromJSON(e)}collapseAtStart(){return!0}}function lt(t){return t instanceof Yr}function Xv(t){return new co(new Map(t._nodeMap))}function sd(){return new co(new Map([["root",new Yr]]))}function Zv(t){const e=t.exportJSON(),r=t.constructor;if(e.type!==r.getType()&&q(130,r.name),K(t)){const s=e.children;Array.isArray(s)||q(59,r.name);const l=t.getChildren();for(let u=0;u({root:Zv(tt())}))}}class UC extends ao{static getType(){return"artificial"}createDOM(e){return document.createElement("div")}}class Vi extends ao{static getType(){return"paragraph"}static clone(e){return new Vi(e.__key)}createDOM(e){const r=document.createElement("p"),s=Ii(e.theme,"paragraph");return s!==void 0&&r.classList.add(...s),r}updateDOM(e,r,s){return!1}static importDOM(){return{p:e=>({conversion:KC,priority:0})}}exportDOM(e){const{element:r}=super.exportDOM(e);if(Pt(r)){this.isEmpty()&&r.append(document.createElement("br"));const s=this.getFormatType();s&&(r.style.textAlign=s)}return{element:r}}static importJSON(e){return nn().updateFromJSON(e)}exportJSON(){const e=super.exportJSON();if(e.textFormat===void 0||e.textStyle===void 0){const r=this.getChildren().find(re);r?(e.textFormat=r.getFormat(),e.textStyle=r.getStyle()):(e.textFormat=this.getTextFormat(),e.textStyle=this.getTextStyle())}return e}insertNewAfter(e,r){const s=nn();s.setTextFormat(e.format),s.setTextStyle(e.style);const l=this.getDirection();return s.setDirection(l),s.setFormat(this.getFormatType()),s.setStyle(this.getStyle()),this.insertAfter(s,r),s}collapseAtStart(){const e=this.getChildren();if(e.length===0||re(e[0])&&e[0].getTextContent().trim()===""){if(this.getNextSibling()!==null)return this.selectNext(),this.remove(),!0;if(this.getPreviousSibling()!==null)return this.selectPrevious(),this.remove(),!0}return!1}}function KC(t){const e=nn();if(t.style&&(e.setFormat(t.style.textAlign),o1(t,e)),e.getFormatType()===""){const r=t.getAttribute("align");r&&r&&r in uf&&e.setFormat(r)}return{node:e}}function nn(){return Nu(new Vi)}function e0(t){return t instanceof Vi}const De=0,t0=1,n0=3;function r0(t,e,r,s){const l=t._keyToDOMMap;l.clear(),t._editorState=sd(),t._pendingEditorState=s,t._compositionKey=null,t._dirtyType=0,t._cloneNotNeeded.clear(),t._dirtyLeaves=new Set,t._dirtyElements.clear(),t._normalizedNodes=new Set,t._updateTags=new Set,t._updates=[],t._blockCursorElement=null;const u=t._observer;u!==null&&(u.disconnect(),t._observer=null),e!==null&&(e.textContent=""),r!==null&&(r.textContent="",l.set("root",r))}function WC(t){const e=new Set,r=new Set;let s=t;for(;s;){const{ownNodeConfig:l}=qi(s),u=s.transform;if(!r.has(u)){r.add(u);const c=s.transform();c&&e.add(c)}if(l){const c=l.$transform;c&&e.add(c),s=l.extends}else{const c=Object.getPrototypeOf(s);s=c.prototype instanceof tn&&c!==tn?c:void 0}}return e}const no={$createDOM:(t,e)=>t.createDOM(e._config,e),$decorateDOM:(t,e,r,s)=>{},$exportDOM:(t,e)=>{const r=ld(e,t.getType());return r&&r.exportDOM!==void 0?r.exportDOM(e,t):t.exportDOM(e)},$extractWithChild:(t,e,r,s,l)=>K(t)&&t.extractWithChild(e,r,s),$getDOMSlot:(t,e,r)=>(K(t)||q(336,t.getKey(),t.getType()),t.getDOMSlot(e)),$shouldExclude:(t,e,r)=>K(t)&&t.excludeFromCopy("html"),$shouldInclude:(t,e,r)=>!e||t.isSelected(e),$updateDOM:(t,e,r,s)=>t.updateDOM(e,r,s._config)};function i0(t){const e=t||{},r=$C(),s=e.theme||{},l=t===void 0?r:e.parentEditor||null,u=e.disableEvents||!1,c=sd(),f=e.namespace||(l!==null?l._config.namespace:p0()),h=e.editorState,g=[Yr,mr,Hi,Qi,Vi,UC,...e.nodes||[]],{onError:m,html:v}=e,y=e.editable===void 0||e.editable;let S;if(t===void 0&&r!==null)S=r._nodes;else{S=new Map;for(let w=0;w{Object.keys(L).forEach(j=>{let D=T.get(j);D===void 0&&(D=[],T.set(j,D)),D.push(L[j])})};return w.forEach(L=>{const j=L.klass.importDOM;if(j==null||N.has(j))return;N.add(j);const D=j.call(L.klass);D!==null&&M(D)}),C&&M(C),T})(S,v?v.import:void 0),y,t);return h!==void 0&&(_._pendingEditorState=h,_._dirtyType=2),(function(w){w.registerCommand(dv,yC,De),w.registerCommand(hv,vC,De),w.registerCommand(pv,xC,De),w.registerCommand(gv,_C,De),w.registerCommand(mv,SC,De)})(_),_}function HC(t,e){const r=t.get(e);t.delete(e),r&&r()}function Ls(t,e,r){return t.set(e,r),HC.bind(null,t,e)}class zi{static version;_headless;_parentEditor;_rootElement;_editorState;_pendingEditorState;_compositionKey;_deferred;_keyToDOMMap;_updates;_updating;_listeners;_commands;_nodes;_decorators;_pendingDecorators;_config;_dirtyType;_cloneNotNeeded;_dirtyLeaves;_dirtyElements;_normalizedNodes;_updateTags;_observer;_key;_onError;_htmlConversions;_window;_editable;_blockCursorElement;_createEditorArgs;constructor(e,r,s,l,u,c,f,h){this._createEditorArgs=h,this._parentEditor=r,this._rootElement=null,this._editorState=e,this._pendingEditorState=null,this._compositionKey=null,this._deferred=[],this._keyToDOMMap=new Map,this._updates=[],this._updating=!1,this._listeners={decorator:new Map,editable:new Map,mutation:new Map,root:new Map,textcontent:new Map,update:new Map},this._commands=new Map,this._config=l,this._nodes=s,this._decorators={},this._pendingDecorators=null,this._dirtyType=0,this._cloneNotNeeded=new Set,this._dirtyLeaves=new Set,this._dirtyElements=new Map,this._normalizedNodes=new Set,this._updateTags=new Set,this._observer=null,this._key=p0(),this._onError=u,this._htmlConversions=c,this._editable=f,this._headless=r!==null&&r._headless,this._window=null,this._blockCursorElement=null}isComposing(){return this._compositionKey!=null}registerUpdateListener(e){return Ls(this._listeners.update,e)}registerEditableListener(e){return Ls(this._listeners.editable,e)}registerDecoratorListener(e){return Ls(this._listeners.decorator,e)}registerTextContentListener(e){return Ls(this._listeners.textcontent,e)}registerRootListener(e){const r=this._listeners.root;return Sn(Ls(r,e,e(this._rootElement,null)||void 0),()=>(function(s,l,u){const c=s.get(l);c&&c(),s.set(l,l(...u)||void 0)})(r,e,[null,this._rootElement]))}registerCommand(e,r,s){s===void 0&&q(35);const l=this._commands;l.has(e)||l.set(e,[new Is,new Is,new Is,new Is,new Is]);const u=l.get(e);u===void 0&&q(36,String(e));const c=(function(h){return 7&h})(s),f=u[c];return c!==s?f.addFront(r):f.addBack(r),()=>{f.delete(r),u.every(h=>h.size===0)&&l.delete(e)}}registerMutationListener(e,r,s){const l=this.resolveRegisteredNodeAfterReplacements(this.getRegisteredNode(e)).klass,u=this._listeners.mutation;let c=u.get(r);c===void 0&&(c=new Set,u.set(r,c)),c.add(l);const f=s&&s.skipInitialization;return f!==void 0&&f||this.initializeMutationListener(r,l),()=>{c.delete(l),c.size===0&&u.delete(r)}}getRegisteredNode(e){const r=this._nodes.get(e.getType());return r===void 0&&q(37,e.name),r}resolveRegisteredNodeAfterReplacements(e){for(;e.replaceWithKlass;)e=this.getRegisteredNode(e.replaceWithKlass);return e}initializeMutationListener(e,r){const s=this._editorState,l=Bm(s).get(r.getType());if(!l)return;const u=new Map;for(const c of l.keys())u.set(c,"created");u.size>0&&e(u,{dirtyLeaves:new Set,prevEditorState:s,updateTags:new Set(["registerMutationListener"])})}registerNodeTransformToKlass(e,r){const s=this.getRegisteredNode(e);return s.transforms.add(r),s}registerNodeTransform(e,r){const s=this.registerNodeTransformToKlass(e,r),l=[s],u=s.replaceWithKlass;if(u!=null){const c=this.registerNodeTransformToKlass(u,r);l.push(c)}return(function(c,f){const h=Bm(c.getEditorState()),g=[];for(const m of f){const v=h.get(m);v&&g.push(v)}g.length!==0&&c.update(()=>{for(const m of g)for(const v of m.keys()){const y=et(v);y&&y.markDirty()}},c._pendingEditorState===null?{tag:Fi}:void 0)})(this,l.map(c=>c.klass.getType())),()=>{l.forEach(c=>c.transforms.delete(r))}}hasNode(e){return this._nodes.has(e.getType())}hasNodes(e){return e.every(this.hasNode.bind(this))}dispatchCommand(e,r){return ie(this,e,r)}getDecorators(){return this._decorators}getRootElement(){return this._rootElement}getKey(){return this._key}setRootElement(e){const r=this._rootElement;if(e!==r){const s=Ii(this._config.theme,"root"),l=this._pendingEditorState||this._editorState;if(this._rootElement=e,r0(this,r,e,l),r!==null&&(this._config.disableEvents||wC(r),s!=null&&r.classList.remove(...s)),e!==null){const u=hd(e),c=e.style;c.userSelect="text",c.whiteSpace="pre-wrap",c.wordBreak="break-word",e.setAttribute("data-lexical-editor","true"),this._window=u,this._dirtyType=2,rv(this),this._updateTags.add(Fi),Fn(this),this._config.disableEvents||(function(f,h){const g=f.ownerDocument;Sf.set(f,g);const m=nu.get(g)??0;m<1&&g.addEventListener("selectionchange",jv),nu.set(g,m+1),f.__lexicalEditor=h;const v=Dv(f);for(let y=0;y<_f.length;y++){const[S,_]=_f[y],w=typeof _=="function"?C=>{um(C)||(lm(C),(h.isEditable()||S==="click")&&_(C,h))}:C=>{if(um(C))return;lm(C);const T=h.isEditable();switch(S){case"cut":return T&&ie(h,ed,C);case"copy":return ie(h,Zf,C);case"paste":return T&&ie(h,Jf,C);case"dragstart":return T&&ie(h,Nv,C);case"dragover":return T&&ie(h,fC,C);case"dragend":return T&&ie(h,dC,C);case"focus":return T&&ie(h,pC,C);case"blur":return T&&ie(h,gC,C);case"drop":return T&&ie(h,Ev,C)}};f.addEventListener(S,w),v.push(()=>{f.removeEventListener(S,w)})}})(e,this),s!=null&&e.classList.add(...s)}else this._window=null,this._updateTags.add(Fi),Fn(this);Ks("root",this,!1,e,r)}}getElementByKey(e){return this._keyToDOMMap.get(e)||null}getEditorState(){return this._editorState}setEditorState(e,r){e.isEmpty()&&q(38);let s=e;s._readOnly&&(s=Xv(e),s._selection=e._selection?e._selection.clone():null),nv(this);const l=this._pendingEditorState,u=this._updateTags,c=r!==void 0?r.tag:null;l===null||l.isEmpty()||(c!=null&&u.add(c),Fn(this)),this._pendingEditorState=s,this._dirtyType=2,this._dirtyElements.set("root",!1),this._compositionKey=null,c!=null&&u.add(c),this._updating||Fn(this)}parseEditorState(e,r){return(function(s,l,u){const c=sd(),f=st,h=Mt,g=ot,m=l._dirtyElements,v=l._dirtyLeaves,y=l._cloneNotNeeded,S=l._dirtyType;l._dirtyElements=new Map,l._dirtyLeaves=new Set,l._cloneNotNeeded=new Set,l._dirtyType=0,st=c,Mt=!1,ot=l,od(null);try{const _=l._nodes;Gv(s.root,_),u&&u(),c._readOnly=!0}catch(_){_ instanceof Error&&l._onError(_)}finally{l._dirtyElements=m,l._dirtyLeaves=v,l._cloneNotNeeded=y,l._dirtyType=S,st=f,Mt=h,ot=g}return c})(typeof e=="string"?JSON.parse(e):e,this,r)}read(e){return Fn(this),this.getEditorState().read(e,{editor:this})}update(e,r){(function(s,l,u){s._updating?s._updates.push([l,u]):_u(s,l,u)})(this,e,r)}focus(e,r={}){const s=this._rootElement;s!==null&&(s.setAttribute("autocapitalize","off"),vn(this,()=>{const l=de(),u=tt();l!==null?l.dirty||It(l.clone()):u.getChildrenSize()!==0&&(r.defaultSelection==="rootStart"?u.selectStart():u.selectEnd()),Eu("focus"),XC(()=>{s.removeAttribute("autocapitalize"),e&&e()})}),this._pendingEditorState===null&&s.removeAttribute("autocapitalize"))}blur(){const e=this._rootElement;e!==null&&e.blur();const r=un(this._window);r!==null&&r.removeAllRanges()}isEditable(){return this._editable}setEditable(e){this._editable!==e&&(this._editable=e,Ks("editable",this,!0,e))}toJSON(){return{editorState:this._editorState.toJSON()}}}zi.version="0.44.0+prod.esm";let Of=null;function od(t){Of=t}let QC=1;function s0(t,e){const r=ld(t,e);return r===void 0&&q(30,e),r}function ld(t,e){return t._nodes.get(e)}const VC=typeof queueMicrotask=="function"?queueMicrotask:t=>{Promise.resolve().then(t)};function o0(t){return Ie(ku(t))}function l0(t){const e=document.activeElement;if(!Pt(e))return!1;const r=e.nodeName;return Ie(ku(t))&&(r==="INPUT"||r==="TEXTAREA"||e.contentEditable==="true"&&wu(e)==null)}function Su(t,e,r){const s=t.getRootElement();try{return s!==null&&s.contains(e)&&s.contains(r)&&e!==null&&!l0(e)&&u0(e)===t}catch{return!1}}function ud(t){return t instanceof zi}function u0(t){let e=t;for(;e!=null;){const r=wu(e);if(ud(r))return r;e=fo(e)}return null}function wu(t){return t?t.__lexicalEditor:null}function zr(t){return $v(t)||t.isToken()}function jn(t){return zr(t)||t.isSegmented()}function zn(t){return ho(t)&&t.nodeType===3}function qC(t){return ho(t)&&t.nodeType===9}function $i(t){let e=t;for(;e!=null;){if(zn(e))return e;e=e.firstChild}return null}function lu(t,e,r){const s=Kr[e];if(r!==null&&(t&s)===(r&s))return t;let l=t^s;return e==="subscript"?l&=-65:e==="superscript"?l&=-33:e==="lowercase"?(l&=-513,l&=-1025):e==="uppercase"?(l&=-257,l&=-1025):e==="capitalize"&&(l&=-257,l&=-513),l}function a0(t,e){const r=(function(){const c=Of;return Of=null,c})();if((e=e||r&&r.__key)!=null)return void(t.__key=e);yt(),Qv();const s=Le(),l=yr(),u=""+QC++;l._nodeMap.set(u,t),K(t)?s._dirtyElements.set(u,!0):s._dirtyLeaves.add(u),s._cloneNotNeeded.add(u),s._dirtyType=1,t.__key=u}function $r(t){const e=t.getParent();if(e!==null){const r=t.getWritable(),s=e.getWritable(),l=t.getPreviousSibling(),u=t.getNextSibling(),c=u!==null?u.__key:null,f=l!==null?l.__key:null,h=l!==null?l.getWritable():null,g=u!==null?u.getWritable():null;l===null&&(s.__first=c),u===null&&(s.__last=f),h!==null&&(h.__next=c),g!==null&&(g.__prev=f),r.__prev=null,r.__next=null,r.__parent=null,s.__size--}}function uu(t){Qv(),iu(t)&&q(323,t.__key,t.__type);const e=t.getLatest(),r=e.__parent,s=yr(),l=Le(),u=s._nodeMap,c=l._dirtyElements;r!==null&&(function(h,g,m){let v=h;for(;v!==null;){if(m.has(v))return;const y=g.get(v);if(y===void 0)break;m.set(v,!1),v=y.__parent}})(r,u,c);const f=e.__key;l._dirtyType=1,K(t)?c.set(f,!0):l._dirtyLeaves.add(f)}function ft(t){yt();const e=Le(),r=e._compositionKey;if(t!==r){if(e._compositionKey=t,r!==null){const s=et(r);s!==null&&s.getWritable()}if(t!==null){const s=et(t);s!==null&&s.getWritable()}}}function lr(){return uo()?null:Le()._compositionKey}function et(t,e){const r=(e||yr())._nodeMap.get(t);return r===void 0?null:r}function c0(t,e){const r=Cu(t,Le());return r!==void 0?et(r,e):null}function Cu(t,e){return t[`__lexicalKey_${e._key}`]}function ku(t,e){let r=t;for(;r!=null;){const s=c0(r,e);if(s!==null)return s;r=fo(r)}return null}function f0(t){const e=t._decorators,r=Object.assign({},e);return t._pendingDecorators=r,r}function Dm(t){return t.read(()=>tt().getTextContent())}function tt(){return d0(yr())}function d0(t){return t._nodeMap.get("root")}function It(t){yt();const e=yr();t!==null&&(t.dirty=!0,t.setCachedNodes(null)),e._selection=t}function bi(t){const e=Le(),r=(function(s,l){let u=s;for(;u!=null;){const c=Cu(u,l);if(c!==void 0)return c;u=fo(u)}return null})(t,e);return r===null?t===e.getRootElement()?et("root"):null:et(r)}function h0(t){return/[\uD800-\uDBFF][\uDC00-\uDFFF]/g.test(t)}function ad(t){const e=[];for(let r=t;r!==null;r=r._parentEditor)e.push(r);return e}function p0(){return Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,5)}function g0(t){return zn(t)?t.nodeValue:null}function cd(t,e,r){const s=un(Lt(e));if(s===null)return;const l=s.anchorNode;let{anchorOffset:u,focusOffset:c}=s;if(l!==null){let f=g0(l);const h=ku(l);if(f!==null&&re(h)){if((f===qs||f===qf)&&r){const g=r.length;f=r,u=g,c=g}f!==null&&fd(h,f,u,c,t)}}}function fd(t,e,r,s,l){let u=t;if(u.isAttached()&&(l||!u.isDirty())){const c=u.isComposing();let f=e;if((c||l)&&(e.endsWith(qs)&&(f=e.slice(0,-qs.length)),l)){const g=qf;let m;for(;(m=f.indexOf(g))!==-1;)f=f.slice(0,m)+f.slice(m+g.length),r!==null&&r>m&&(r=Math.max(m,r-g.length)),s!==null&&s>m&&(s=Math.max(m,s-g.length))}const h=u.getTextContent();if(l||f!==h){if(f===""){if(ft(null),pu||oo||gu)u.remove();else{const w=Le();setTimeout(()=>{w.update(()=>{u.isAttached()&&u.remove()})},20)}return}const g=u.getParent(),m=lo(),v=u.getTextContentSize(),y=lr(),S=u.getKey();if(u.isToken()||y!==null&&S===y&&!c||ee(m)&&(g!==null&&!g.canInsertTextBefore()&&m.anchor.offset===0||m.anchor.key===t.__key&&m.anchor.offset===0&&!u.canInsertTextBefore()&&!c||m.focus.key===t.__key&&m.focus.offset===v&&!u.canInsertTextAfter()&&!c))return void u.markDirty();const _=de();if(!ee(_)||r===null||s===null)return void jm(u,f,_);if(_.setTextNodeRange(u,r,u,s),u.isSegmented()){const w=ct(u.getTextContent());u.replace(w),u=w}jm(u,f,_)}}}function jm(t,e,r){if(t.setTextContent(e),ee(r)){const s=t.getKey();for(const l of["anchor","focus"]){const u=r[l];u.type==="text"&&u.key===s&&(u.offset=xn(t,u.offset,"clamp"))}}}function Rl(t,e,r){const s=e[r]||!1;return s==="any"||s===t[r]}function GC(t,e){return Rl(t,e,"altKey")&&Rl(t,e,"ctrlKey")&&Rl(t,e,"shiftKey")&&Rl(t,e,"metaKey")}function Re(t,e,r){if(!GC(t,r))return!1;if(t.key.toLowerCase()===e.toLowerCase())return!0;if(e.length>1||t.key.length===1&&t.key.charCodeAt(0)<=127)return!1;if(t.code.startsWith("Digit")&&/^\d$/.test(e))return t.code===`Digit${e}`;const s="Key"+e.toUpperCase();return t.code===s}const Dn={ctrlKey:!Xt,metaKey:Xt},Fm={altKey:Xt,ctrlKey:!Xt};function Im(t){return t.key==="Backspace"}function Lm(t){return Re(t,"a",Dn)}function JC(t){const e=tt();if(ee(t)){const r=t.anchor,s=t.focus,l=r.getNode().getTopLevelElementOrThrow().getParentOrThrow();return r.set(l.getKey(),0,"element"),s.set(l.getKey(),l.getChildrenSize(),"element"),cf(t),t}{const r=e.select(0,e.getChildrenSize());return It(cf(r)),r}}function Ii(t,e){t.__lexicalClassNameCache===void 0&&(t.__lexicalClassNameCache={});const r=t.__lexicalClassNameCache,s=r[e];if(s!==void 0)return s;const l=t[e];if(typeof l=="string"){const u=E0(l);return r[e]=u,u}return l}function dd(t,e,r,s,l){if(r.size===0)return;const u=s.__type,c=s.__key,f=e.get(u);f===void 0&&q(33,u);const h=f.klass;let g=t.get(h);g===void 0&&(g=new Map,t.set(h,g));const m=g.get(c),v=m==="destroyed"&&l==="created";(m===void 0||v)&&g.set(c,v?"updated":l)}function Am(t,e,r){const s=t.getParent();let l=r,u=t;return s!==null&&(r===0&&(l=u.getIndexWithinParent(),u=s)),u.getChildAtIndex(l-1)}function YC(t,e){const r=t.offset;if(t.type==="element")return Am(t.getNode(),e,r);{const s=t.getNode();if(r===0||!e){const l=s.getPreviousSibling();return l===null?Am(s.getParentOrThrow(),e,s.getIndexWithinParent()+0):l}}return null}function m0(t){const e=Lt(t).event,r=e&&e.inputType;return r==="insertFromPaste"||r==="insertFromPasteAsQuotation"}function ie(t,e,r){return Jv(t,e,r,t)}function Bi(t,e){const r=t._keyToDOMMap.get(e);return r===void 0&&q(75,e),r}function fo(t){const e=t.assignedSlot||t.parentElement;return bf(e)?e.host:e}function y0(t){return qC(t)?t:Pt(t)?t.ownerDocument:null}function Eu(t){yt(),Le()._updateTags.add(t)}function XC(t){yt(),Le()._deferred.push(t)}function Mf(t,e){let r=t.getParent();for(;r!==null;){if(r.is(e))return!0;r=r.getParent()}return!1}function hd(t){const e=y0(t);return e?e.defaultView:null}function Lt(t){const e=t._window;return e===null&&q(78),e}function ZC(t){let e=t.getParentOrThrow();for(;e!==null;){if(An(e))return e;e=e.getParentOrThrow()}return e}function An(t){return lt(t)||K(t)&&t.isShadowRoot()}function e1(t,e=!1){const r=t.constructor.clone(t);return a0(r,null),r.afterCloneFrom(t),e||r.resetOnCopyNodeFrom(t),r}function Nu(t){const e=Le(),r=t.getType(),s=ld(e,r);s===void 0&&q(200,t.constructor.name,r);const{replace:l,replaceWithKlass:u}=s;if(l!==null){const c=l(t),f=c.constructor;return u!==null?c instanceof u||q(201,u.name,u.getType(),f.name,f.getType(),t.constructor.name,r):c instanceof t.constructor&&f!==t.constructor||q(202,f.name,f.getType(),t.constructor.name,r),c.__key===t.__key&&q(203,t.constructor.name,r,f.name,f.getType()),c}return t}function Ac(t,e){!lt(t.getParent())||K(e)||Ie(e)||q(99)}function t1(t){const e=et(t);return e===null&&q(63,t),e}function zc(t){return(Ie(t)||K(t)&&!t.canBeEmpty())&&!t.isInline()}function Pf(t,e,r){r.style.removeProperty("caret-color"),e._blockCursorElement=null;const s=t.parentElement;s!==null&&s.removeChild(t)}function un(t){return ln?(t||window).getSelection():null}function n1(t){const e=hd(t);return e?e.getSelection():null}function Pt(t){return ho(t)&&t.nodeType===1}function ho(t){return typeof t=="object"&&t!==null&&"nodeType"in t&&typeof t.nodeType=="number"}function bf(t){return ho(t)&&t.nodeType===11}function r1(t){const e=new RegExp(/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|mark|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var|#text)$/,"i");return t.nodeName.match(e)!==null}function zm(t){const e=new RegExp(/^(address|article|aside|blockquote|canvas|dd|div|dl|dt|fieldset|figcaption|figure|footer|form|h1|h2|h3|h4|h5|h6|header|hr|li|main|nav|noscript|ol|p|pre|section|table|td|tfoot|ul|video)$/,"i");return t.nodeName.match(e)!==null}function or(t){if(Ie(t)&&!t.isInline())return!0;if(!K(t)||An(t))return!1;const e=t.getFirstChild(),r=e===null||Us(e)||re(e)||e.isInline();return!t.isInline()&&t.canBeEmpty()!==!1&&r}function Ui(){return Le()}function po(t=Ui()){return t._config.dom||no}const $m=new WeakMap,i1=new Map;function Bm(t){if(!t._readOnly&&t.isEmpty())return i1;t._readOnly||q(192);let e=$m.get(t);return e||(e=(function(r){const s=new Map;for(const[l,u]of r._nodeMap){const c=u.__type;let f=s.get(c);f||(f=new Map,s.set(c,f)),f.set(l,u)}return s})(t),$m.set(t,e)),e}function v0(t){const e=t.constructor.clone(t);return e.afterCloneFrom(t),e}function s1(t){return(e=v0(t))[Fv]=!0,e;var e}function o1(t,e){const r=parseInt(t.style.paddingInlineStart,10)||0,s=Math.round(r/40);e.setIndent(s)}function l1(t){return t.__lexicalUnmanaged===!0}function As(t,e){return(function(r,s){return Object.prototype.hasOwnProperty.call(r,s)})(t,e)&&t[e]!==tn[e]}function qi(t){const e=qg in t.prototype?t.prototype[qg]():void 0,r=(function(c){if(!(c===tn||c.prototype instanceof tn)){let f="",h="";try{f=c.getType()}catch{}try{zi.version&&(h=JSON.parse(zi.version))}catch{}q(290,c.name,f,h)}return c===Yv||c===ao||c===tn})(t),s=!r&&As(t,"getType")?t.getType():void 0;let l,u=s;if(e)if(s)l=e[s];else for(const[c,f]of Object.entries(e))u=c,l=f;if(!r&&u&&(As(t,"getType")||(t.getType=()=>u),As(t,"clone")||(t.clone=c=>(od(c),new t)),As(t,"importJSON")||(t.importJSON=l&&l.$importJSON||(c=>new t().updateFromJSON(c))),!As(t,"importDOM")&&l)){const{importDOM:c}=l;c&&(t.importDOM=()=>c)}return{ownNodeConfig:l,ownNodeType:u}}const Ql=(t,e)=>{let r=t;for(;r!=null&&!lt(r);){if(e(r))return r;r=r.getParent()}return null};function au(t,e){const r=[];let s=t.__first;for(;s!==null;){const l=e===null?et(s):e.get(s);l==null&&q(174),r.push(s),s=l.__next}return r}const u1={next:"previous",previous:"next"};class pd{origin;constructor(e){this.origin=e}[Symbol.iterator](){return _0({hasNext:Ki,initial:this.getAdjacentCaret(),map:e=>e,step:e=>e.getAdjacentCaret()})}getAdjacentCaret(){return dt(this.getNodeAtCaret(),this.direction)}getSiblingCaret(){return dt(this.origin,this.direction)}remove(){const e=this.getNodeAtCaret();return e&&e.remove(),this}replaceOrInsert(e,r){const s=this.getNodeAtCaret();return e.is(this.origin)||e.is(s)||(s===null?this.insert(e):s.replace(e,r)),this}splice(e,r,s="next"){const l=s===this.direction?r:Array.from(r).reverse();let u=this;const c=this.getParentAtCaret(),f=new Map;for(let h=u.getAdjacentCaret();h!==null&&f.size0){const g=u.getNodeAtCaret();if(g){if(f.delete(g.getKey()),f.delete(h.getKey()),!(g.is(h)||u.origin.is(h))){const m=h.getParent();m&&m.is(c)&&h.remove(),g.replace(h)}}else g===null&&q(263,Array.from(f).join(" "))}else u.insert(h);u=dt(h,this.direction)}for(const h of f.values())h.remove();return this}}class ro extends pd{type="child";getLatest(){const e=this.origin.getLatest();return e===this.origin?this:hr(e,this.direction)}getParentCaret(e="root"){return dt(gd(this.getParentAtCaret(),e),this.direction)}getFlipped(){const e=Xr(this.direction);return dt(this.getNodeAtCaret(),e)||hr(this.origin,e)}getParentAtCaret(){return this.origin}getChildCaret(){return this}isSameNodeCaret(e){return e instanceof ro&&this.direction===e.direction&&this.origin.is(e.origin)}isSamePointCaret(e){return this.isSameNodeCaret(e)}}const a1={root:lt,shadowRoot:An};function Xr(t){return u1[t]}function gd(t,e="root"){return a1[e](t)?null:t}class Hr extends pd{type="sibling";getLatest(){const e=this.origin.getLatest();return e===this.origin?this:dt(e,this.direction)}getSiblingCaret(){return this}getParentAtCaret(){return this.origin.getParent()}getChildCaret(){return K(this.origin)?hr(this.origin,this.direction):null}getParentCaret(e="root"){return dt(gd(this.getParentAtCaret(),e),this.direction)}getFlipped(){const e=Xr(this.direction);return dt(this.getNodeAtCaret(),e)||hr(this.origin.getParentOrThrow(),e)}isSamePointCaret(e){return e instanceof Hr&&this.direction===e.direction&&this.origin.is(e.origin)}isSameNodeCaret(e){return(e instanceof Hr||e instanceof Qr)&&this.direction===e.direction&&this.origin.is(e.origin)}}class Qr extends pd{type="text";offset;constructor(e,r){super(e),this.offset=r}getLatest(){const e=this.origin.getLatest();return e===this.origin?this:dr(e,this.direction,this.offset)}getParentAtCaret(){return this.origin.getParent()}getChildCaret(){return null}getParentCaret(e="root"){return dt(gd(this.getParentAtCaret(),e),this.direction)}getFlipped(){return dr(this.origin,Xr(this.direction),this.offset)}isSamePointCaret(e){return e instanceof Qr&&this.direction===e.direction&&this.origin.is(e.origin)&&this.offset===e.offset}isSameNodeCaret(e){return(e instanceof Hr||e instanceof Qr)&&this.direction===e.direction&&this.origin.is(e.origin)}getSiblingCaret(){return dt(this.origin,this.direction)}}function ar(t){return t instanceof Qr}function Ki(t){return t instanceof Hr}function rn(t){return t instanceof ro}const c1={next:class extends Qr{direction="next";getNodeAtCaret(){return this.origin.getNextSibling()}insert(t){return this.origin.insertAfter(t),this}},previous:class extends Qr{direction="previous";getNodeAtCaret(){return this.origin.getPreviousSibling()}insert(t){return this.origin.insertBefore(t),this}}},f1={next:class extends Hr{direction="next";getNodeAtCaret(){return this.origin.getNextSibling()}insert(t){return this.origin.insertAfter(t),this}},previous:class extends Hr{direction="previous";getNodeAtCaret(){return this.origin.getPreviousSibling()}insert(t){return this.origin.insertBefore(t),this}}},d1={next:class extends ro{direction="next";getNodeAtCaret(){return this.origin.getFirstChild()}insert(t){return this.origin.splice(0,0,[t]),this}},previous:class extends ro{direction="previous";getNodeAtCaret(){return this.origin.getLastChild()}insert(t){return this.origin.splice(this.origin.getChildrenSize(),0,[t]),this}}};function dt(t,e){return t?new f1[e](t):null}function dr(t,e,r){return t?new c1[e](t,xn(t,r)):null}function xn(t,e,r="error"){const s=t.getTextContentSize();let l=e==="next"?s:e==="previous"?0:e;return(l<0||l>s)&&(r!=="clamp"&&Jy(284,String(e),String(s),t.getKey()),l=l<0?0:s),l}function Um(t,e){return new p1(t,e)}function hr(t,e){return K(t)?new d1[e](t):null}function h1(t){return t&&t.getChildCaret()||t}function md(t){return t&&h1(t.getAdjacentCaret())}class yd{type="node-caret-range";direction;anchor;focus;constructor(e,r,s){this.anchor=e,this.focus=r,this.direction=s}getLatest(){const e=this.anchor.getLatest(),r=this.focus.getLatest();return e===this.anchor&&r===this.focus?this:new yd(e,r,this.direction)}isCollapsed(){return this.anchor.isSamePointCaret(this.focus)}getTextSlices(){const e=l=>{const u=this[l].getLatest();return ar(u)?(function(c,f){const{direction:h,origin:g}=c,m=xn(g,f==="focus"?Xr(h):h);return Um(c,m-c.offset)})(u,l):null},r=e("anchor"),s=e("focus");if(r&&s){const{caret:l}=r,{caret:u}=s;if(l.isSameNodeCaret(u))return[Um(l,u.offset-l.offset),null]}return[r,s]}iterNodeCarets(e="root"){const r=ar(this.anchor)?this.anchor.getSiblingCaret():this.anchor.getLatest(),s=this.focus.getLatest(),l=ar(s),u=c=>c.isSameNodeCaret(s)?null:md(c)||c.getParentCaret(e);return _0({hasNext:c=>c!==null&&!(l&&s.isSameNodeCaret(c)),initial:r.isSameNodeCaret(s)?null:u(r),map:c=>c,step:u})}[Symbol.iterator](){return this.iterNodeCarets("root")}}class p1{type="slice";caret;distance;constructor(e,r){this.caret=e,this.distance=r}getSliceIndices(){const{distance:e,caret:{offset:r}}=this,s=r+e;return s{let ne;for(let X=D;XC.has(J.getKey())&&or(J));return F&&z?[F,z]:null})(m,v,h);if(y){const[_,w]=y;hr(_,"previous").splice(0,w.getChildren());let C=w.getParent();for(w.remove(!0);C&&C.isEmpty();){const T=C;C=C.getParent(),T.remove(!0)}}const S=[m,v,...c,...f].find($c);if(S)return x0(qr(yn(S),t.direction));q(269,JSON.stringify(c.map(_=>_.origin.__key)))}function yn(t){const e=(function(l){let u=l;for(;rn(u);){const c=md(u);if(!rn(c))break;u=c}return u})(t.getLatest()),{direction:r}=e;if(re(e.origin))return ar(e)?e:dr(e.origin,r,r);const s=e.getAdjacentCaret();return Ki(s)&&re(s.origin)?dr(s.origin,r,Xr(r)):e}function C0(t){return ar(t)&&t.offset!==xn(t.origin,t.direction)}function qr(t,e){return t.direction===e?t:t.getFlipped()}function xd(t,e){return t.direction===e?t:Vr(qr(t.focus,e),qr(t.anchor,e))}function Df(t,e,r){let s=hr(t,"next");for(let l=0;l0||!u&&f.canBeEmpty()&&l(f,"last"))&&c.insert(e(f).splice(0,0,h))}return c}function x1(...t){return t}function k0(t,e){if(!e||t===e)return t;for(const r in e)if(t[r]!==e[r])return{...t,...e};return t}function E0(...t){const e=[];for(const r of t)if(r&&typeof r=="string")for(const[s]of r.matchAll(/\S+/g))e.push(s);return e}function Sn(...t){return()=>{for(let e=t.length-1;e>=0;e--)t[e]();t.length=0}}const N0=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0,_1=N0?A.useLayoutEffect:A.useEffect,jl={tag:Fi};function S1({initialConfig:t,children:e}){const r=A.useMemo(()=>{const{theme:s,namespace:l,nodes:u,onError:c,editorState:f,html:h}=t,g=jw(null,s),m=i0({editable:t.editable,html:h,namespace:l,nodes:u,onError:v=>c(v,m),theme:s});return(function(v,y){if(y!==null){if(y===void 0)v.update(()=>{const S=tt();if(S.isEmpty()){const _=nn();S.append(_);const w=N0?document.activeElement:null;(de()!==null||w!==null&&w===v.getRootElement())&&_.select()}},jl);else if(y!==null)switch(typeof y){case"string":{const S=v.parseEditorState(y);v.setEditorState(S,jl);break}case"object":v.setEditorState(y,jl);break;case"function":v.update(()=>{tt().isEmpty()&&y(v)},jl)}}})(m,f),[m,g]},[]);return _1(()=>{const s=t.editable,[l]=r;l.setEditable(s===void 0||s)},[]),k.jsx(Gy.Provider,{value:r,children:e})}function w1({children:t,className:e=""}){return k.jsx("section",{className:`relative flex flex-col min-h-0 border border-line rounded bg-bg ${e}`.trim(),children:t})}function C1({children:t}){return k.jsx("div",{className:"absolute -top-2 left-0 right-0 flex justify-between pointer-events-none px-4 z-10",children:t})}function k1({children:t}){return k.jsxs("span",{className:"bg-bg px-2 text-[11px] tracking-[0.12em] text-green",children:["[ ",t," ]"]})}function E1({children:t}){return k.jsxs("span",{className:"bg-bg px-2 text-[11px] text-green",children:["( ",t," )"]})}function N1({children:t,className:e=""}){return k.jsx("div",{className:`flex-1 flex flex-col overflow-auto pt-4 px-3.5 pb-3 min-h-0 ${e}`.trim(),children:t})}function T1({children:t,className:e=""}){return k.jsx("div",{className:`border-t border-dashed border-white/[0.06] pt-2.5 px-3.5 pb-2 text-[11px] text-faint ${e}`.trim(),children:t})}const fe=Object.assign(w1,{Header:C1,Title:k1,Count:E1,Body:N1,Footer:T1});function T0(t){const e=Ui().getElementByKey(t.getKey());if(e===null)return null;const r=e.ownerDocument.defaultView;return r===null?null:r.getComputedStyle(e)}function O1(t){return T0(lt(t)?t:t.getParentOrThrow())}function M1(t,e,r="self"){const s=t.getStartEndPoints();if(e.isSelected(t)&&!jn(e)&&s!==null){const[l,u]=s,c=t.isBackward(),f=l.getNode(),h=u.getNode(),g=e.is(f),m=e.is(h);if(g||m){const[v,y]=Tf(t),S=f.is(h),_=e.is(c?h:f),w=e.is(c?f:h);let C,T=0;S?(T=v>y?y:v,C=v>y?v:y):_?(T=c?y:v,C=void 0):w&&(T=0,C=c?v:y);const N=e.__text.slice(T,C);N!==e.__text&&(r==="clone"&&(e=s1(e)),e.__text=N)}}return e}function O0(t){const e=M0(t);return e!==null&&e.writingMode==="vertical-rl"}function M0(t){const e=t.anchor.getNode();return K(e)?T0(e):O1(e)}function Hm(t,e){let r=O0(t)?!e:e;P0(t)&&(r=!r);const s=pr(t.focus,r?"previous":"next");if(C0(s))return!1;for(const l of vd(s)){if(rn(l))return!l.origin.isInline();if(!K(l.origin)){if(Ie(l.origin))return!0;break}}return!1}function P1(t,e,r,s){t.modify(e?"extend":"move",r,s)}function P0(t){const e=M0(t);return e!==null&&e.direction==="rtl"}function Qm(t,e,r){const s=P0(t);let l;l=O0(t)||s?!r:r,P1(t,e,l,"character")}const b0=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0,b1=b0&&"documentMode"in document?document.documentMode:null;!(!b0||!("InputEvent"in window)||b1)&&"getTargetRanges"in new window.InputEvent("input");function R0(t,e){return t!==null&&Object.getPrototypeOf(t).constructor.name===e.name}const R1=Symbol.for("preact-signals");function Tu(){if(Ln>1)return void Ln--;let t,e=!1;for(!(function(){let r=fu;for(fu=void 0;r!==void 0;)r.S.v===r.v&&(r.S.i=r.i),r=r.o})();Hs!==void 0;){let r=Hs;for(Hs=void 0,du++;r!==void 0;){const s=r.u;if(r.u=void 0,r.f&=-3,!(8&r.f)&&D0(r))try{r.c()}catch(l){e||(t=l,e=!0)}r=s}}if(du=0,Ln--,e)throw t}function D1(t){if(Ln>0)return t();jf=++j1,Ln++;try{return t()}finally{Tu()}}let Pe,Hs;function Vm(t){const e=Pe;Pe=void 0;try{return t()}finally{Pe=e}}let fu,Ln=0,du=0,j1=0,jf=0,Gl=0;function qm(t){if(Pe===void 0)return;let e=t.n;return e===void 0||e.t!==Pe?(e={i:0,S:t,p:Pe.s,n:void 0,t:Pe,e:void 0,x:void 0,r:e},Pe.s!==void 0&&(Pe.s.n=e),Pe.s=e,t.n=e,32&Pe.f&&t.S(e),e):e.i===-1?(e.i=0,e.n!==void 0&&(e.n.p=e.p,e.p!==void 0&&(e.p.n=e.n),e.p=Pe.s,e.n=void 0,Pe.s.n=e,Pe.s=e),e):void 0}function _t(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=e?.watched,this.Z=e?.unwatched,this.name=e?.name}function F1(t,e){return new _t(t,e)}function D0(t){for(let e=t.s;e!==void 0;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function Gm(t){for(let e=t.s;e!==void 0;e=e.n){const r=e.S.n;if(r!==void 0&&(e.r=r),e.S.n=e,e.i=-1,e.n===void 0){t.s=e;break}}}function j0(t){let e,r=t.s;for(;r!==void 0;){const s=r.p;r.i===-1?(r.S.U(r),s!==void 0&&(s.n=r.n),r.n!==void 0&&(r.n.p=s)):e=r,r.S.n=r.r,r.r!==void 0&&(r.r=void 0),r=s}t.s=e}function ki(t,e){_t.call(this,void 0),this.x=t,this.s=void 0,this.g=Gl-1,this.f=4,this.W=e?.watched,this.Z=e?.unwatched,this.name=e?.name}function F0(t){const e=t.m;if(t.m=void 0,typeof e=="function"){Ln++;const r=Pe;Pe=void 0;try{e()}catch(s){throw t.f&=-2,t.f|=8,_d(t),s}finally{Pe=r,Tu()}}}function _d(t){for(let e=t.s;e!==void 0;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,F0(t)}function I1(t){if(Pe!==this)throw new Error("Out-of-order effect");j0(this),Pe=t,this.f&=-2,8&this.f&&_d(this),Tu()}function Pi(t,e){this.x=t,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=e?.name}function Sd(t,e){const r=new Pi(t,e);try{r.c()}catch(l){throw r.d(),l}const s=r.d.bind(r);return s[Symbol.dispose]=s,s}function I0(t,e={}){const r={};for(const s in t){const l=e[s],u=F1(l===void 0?t[s]:l);r[s]=u}return r}_t.prototype.brand=R1,_t.prototype.h=function(){return!0},_t.prototype.S=function(t){const e=this.t;e!==t&&t.e===void 0&&(t.x=e,this.t=t,e!==void 0?e.e=t:Vm(()=>{var r;(r=this.W)==null||r.call(this)}))},_t.prototype.U=function(t){if(this.t!==void 0){const e=t.e,r=t.x;e!==void 0&&(e.x=r,t.e=void 0),r!==void 0&&(r.e=e,t.x=void 0),t===this.t&&(this.t=r,r===void 0&&Vm(()=>{var s;(s=this.Z)==null||s.call(this)}))}},_t.prototype.subscribe=function(t){return Sd(()=>{const e=this.value,r=Pe;Pe=void 0;try{t(e)}finally{Pe=r}},{name:"sub"})},_t.prototype.valueOf=function(){return this.value},_t.prototype.toString=function(){return this.value+""},_t.prototype.toJSON=function(){return this.value},_t.prototype.peek=function(){const t=Pe;Pe=void 0;try{return this.value}finally{Pe=t}},Object.defineProperty(_t.prototype,"value",{get(){const t=qm(this);return t!==void 0&&(t.i=this.i),this.v},set(t){if(t!==this.v){if(du>100)throw new Error("Cycle detected");(function(e){Ln!==0&&du===0&&e.l!==jf&&(e.l=jf,fu={S:e,v:e.v,i:e.i,o:fu})})(this),this.v=t,this.i++,Gl++,Ln++;try{for(let e=this.t;e!==void 0;e=e.x)e.t.N()}finally{Tu()}}}}),ki.prototype=new _t,ki.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Gl))return!0;if(this.g=Gl,this.f|=1,this.i>0&&!D0(this))return this.f&=-2,!0;const t=Pe;try{Gm(this),Pe=this;const e=this.x();(16&this.f||this.v!==e||this.i===0)&&(this.v=e,this.f&=-17,this.i++)}catch(e){this.v=e,this.f|=16,this.i++}return Pe=t,j0(this),this.f&=-2,!0},ki.prototype.S=function(t){if(this.t===void 0){this.f|=36;for(let e=this.s;e!==void 0;e=e.n)e.S.S(e)}_t.prototype.S.call(this,t)},ki.prototype.U=function(t){if(this.t!==void 0&&(_t.prototype.U.call(this,t),this.t===void 0)){this.f&=-33;for(let e=this.s;e!==void 0;e=e.n)e.S.U(e)}},ki.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(let t=this.t;t!==void 0;t=t.x)t.t.N()}},Object.defineProperty(ki.prototype,"value",{get(){if(1&this.f)throw new Error("Cycle detected");const t=qm(this);if(this.h(),t!==void 0&&(t.i=this.i),16&this.f)throw this.v;return this.v}}),Pi.prototype.c=function(){const t=this.S();try{if(8&this.f||this.x===void 0)return;const e=this.x();typeof e=="function"&&(this.m=e)}finally{t()}},Pi.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,F0(this),Gm(this),Ln++;const t=Pe;return Pe=this,I1.bind(this,t)},Pi.prototype.N=function(){2&this.f||(this.f|=2,this.u=Hs,Hs=this)},Pi.prototype.d=function(){this.f|=8,1&this.f||_d(this)},Pi.prototype.dispose=function(){this.d()};function L1(){const t=tt(),e=de(),r=nn();t.clear(),t.append(r),e!==null&&r.select(),ee(e)&&(e.format=0)}function A1(t,e=L1){return t.registerCommand(td,r=>(t.update(e),!0),De)}function z1(t){const e=new Set,r=new Set;for(const s of L0(t)){const l=typeof s=="function"?s:s.replace;qi(l),e.add(l.getType()),r.add(l)}return{nodes:r,types:e}}function L0(t){return(typeof t.nodes=="function"?t.nodes():t.nodes)||[]}iv("format",{parse:t=>typeof t=="number"?t:0});function je(t,...e){const r=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",t);for(const l of e)s.append("v",l);throw r.search=s.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function A0(t,e){if(t&&e&&!Array.isArray(e)&&typeof t=="object"&&typeof e=="object"){const r=t,s=e;for(const l in s)r[l]=A0(r[l],s[l]);return t}return e}const wd=0,Ff=1,z0=2,Bc=3,Fl=4,Ei=5,Uc=6,zs=7;function Kc(t){return t.id===wd}function $0(t){return t.id===z0}function $1(t){return(function(e){return e.id===Ff})(t)||je(305,String(t.id),String(Ff)),Object.assign(t,{id:z0})}const B1=new Set;class U1{builder;configs;_dependency;_peerNameSet;extension;state;_signal;constructor(e,r){this.builder=e,this.extension=r,this.configs=new Set,this.state={id:wd}}mergeConfigs(){let e=this.extension.config||{};const r=this.extension.mergeConfig?this.extension.mergeConfig.bind(this.extension):k0;for(const s of this.configs)e=r(e,s);return e}init(e){const r=this.state;$0(r)||je(306,String(r.id));const s={getDependency:this.getInitDependency.bind(this),getDirectDependentNames:this.getDirectDependentNames.bind(this),getPeer:this.getInitPeer.bind(this),getPeerNameSet:this.getPeerNameSet.bind(this)},l={...s,getDependency:this.getDependency.bind(this),getInitResult:this.getInitResult.bind(this),getPeer:this.getPeer.bind(this)},u=(function(f,h,g){return Object.assign(f,{config:h,id:Bc,registerState:g})})(r,this.mergeConfigs(),s);let c;this.state=u,this.extension.init&&(c=this.extension.init(e,u.config,s)),this.state=(function(f,h,g){return Object.assign(f,{id:Fl,initResult:h,registerState:g})})(u,c,l)}build(e){const r=this.state;let s;r.id!==Fl&&je(307,String(r.id),String(Ei)),this.extension.build&&(s=this.extension.build(e,r.config,r.registerState));const l={...r.registerState,getOutput:()=>s,getSignal:this.getSignal.bind(this)};this.state=(function(u,c,f){return Object.assign(u,{id:Ei,output:c,registerState:f})})(r,s,l)}register(e,r){this._signal=r;const s=this.state;s.id!==Ei&&je(308,String(s.id),String(Ei));const l=this.extension.register&&this.extension.register(e,s.config,s.registerState);return this.state=(function(u){return Object.assign(u,{id:Uc})})(s),()=>{const u=this.state;u.id!==zs&&je(309,String(s.id),String(zs)),this.state=(function(c){return Object.assign(c,{id:Ei})})(u),l&&l()}}afterRegistration(e){const r=this.state;let s;return r.id!==Uc&&je(310,String(r.id),String(Uc)),this.extension.afterRegistration&&(s=this.extension.afterRegistration(e,r.config,r.registerState)),this.state=(function(l){return Object.assign(l,{id:zs})})(r),s}getSignal(){return this._signal===void 0&&je(311),this._signal}getInitResult(){this.extension.init===void 0&&je(312,this.extension.name);const e=this.state;return(function(r){return r.id>=Fl})(e)||je(313,String(e.id),String(Fl)),e.initResult}getInitPeer(e){const r=this.builder.extensionNameMap.get(e);return r?r.getExtensionInitDependency():void 0}getExtensionInitDependency(){const e=this.state;return(function(r){return r.id>=Bc})(e)||je(314,String(e.id),String(Bc)),{config:e.config}}getPeer(e){const r=this.builder.extensionNameMap.get(e);return r?r.getExtensionDependency():void 0}getInitDependency(e){const r=this.builder.getExtensionRep(e);return r===void 0&&je(315,this.extension.name,e.name),r.getExtensionInitDependency()}getDependency(e){const r=this.builder.getExtensionRep(e);return r===void 0&&je(315,this.extension.name,e.name),r.getExtensionDependency()}getState(){const e=this.state;return(function(r){return r.id>=zs})(e)||je(316,String(e.id),String(zs)),e}getDirectDependentNames(){return this.builder.incomingEdges.get(this.extension.name)||B1}getPeerNameSet(){let e=this._peerNameSet;return e||(e=new Set((this.extension.peerDependencies||[]).map(([r])=>r)),this._peerNameSet=e),e}getExtensionDependency(){if(!this._dependency){const e=this.state;(function(r){return r.id>=Ei})(e)||je(317,this.extension.name),this._dependency={config:e.config,init:e.initResult,output:e.output}}return this._dependency}}const Jm={tag:Fi};function K1(){const t=tt();t.isEmpty()&&t.append(nn())}const W1={config:{setOptions:Jm,updateOptions:Jm},init:({$initialEditorState:t=K1})=>({$initialEditorState:t,initialized:!1}),afterRegistration(t,{updateOptions:e,setOptions:r},s){const l=s.getInitResult();if(!l.initialized){l.initialized=!0;const{$initialEditorState:u}=l;if(BC(u))t.setEditorState(u,r);else if(typeof u=="function")t.update(()=>{u(t)},e);else if(u&&(typeof u=="string"||typeof u=="object")){const c=t.parseEditorState(u);t.setEditorState(c,r)}}return()=>{}},name:"@lexical/extension/InitialState",nodes:[Yr,mr,Hi,Qi,Vi]},Ym=Symbol.for("@lexical/extension/LexicalBuilder");function Xm(){}function H1(t){throw t}function Il(t){return Array.isArray(t)?t:[t]}const Wc="0.44.0+prod.esm";class cr{roots;extensionNameMap;outgoingConfigEdges;incomingEdges;conflicts;_sortedExtensionReps;PACKAGE_VERSION;constructor(e){this.outgoingConfigEdges=new Map,this.incomingEdges=new Map,this.extensionNameMap=new Map,this.conflicts=new Map,this.PACKAGE_VERSION=Wc,this.roots=e;for(const r of e)this.addExtension(r)}static fromExtensions(e){const r=[Il(W1)];for(const s of e)r.push(Il(s));return new cr(r)}static maybeFromEditor(e){const r=e[Ym];return r&&(r.PACKAGE_VERSION!==Wc&&je(292,r.PACKAGE_VERSION,Wc),r instanceof cr||je(293)),r}static fromEditor(e){const r=cr.maybeFromEditor(e);return r===void 0&&je(294),r}constructEditor(){const{$initialEditorState:e,onError:r,...s}=this.buildCreateEditorArgs(),l=Object.assign(i0({...s,...r?{onError:u=>{r(u,l)}}:{}}),{[Ym]:this});for(const u of this.sortedExtensionReps())u.build(l);return l}buildEditor(){let e=Xm;function r(){try{e()}finally{e=Xm}}const s=Object.assign(this.constructEditor(),{dispose:r,[Symbol.dispose]:r});return e=Sn(this.registerEditor(s),()=>s.setRootElement(null)),s}hasExtensionByName(e){return this.extensionNameMap.has(e)}getExtensionRep(e){const r=this.extensionNameMap.get(e.name);if(r)return r.extension!==e&&je(295,e.name),r}addEdge(e,r,s){const l=this.outgoingConfigEdges.get(e);l?l.set(r,s):this.outgoingConfigEdges.set(e,new Map([[r,s]]));const u=this.incomingEdges.get(r);u?u.add(e):this.incomingEdges.set(r,new Set([e]))}addExtension(e){this._sortedExtensionReps!==void 0&&je(296);const r=Il(e),[s]=r;typeof s.name!="string"&&je(297,typeof s.name);let l=this.extensionNameMap.get(s.name);if(l!==void 0&&l.extension!==s&&je(298,s.name),!l){l=new U1(this,s),this.extensionNameMap.set(s.name,l);const u=this.conflicts.get(s.name);typeof u=="string"&&je(299,s.name,u);for(const c of s.conflictsWith||[])this.extensionNameMap.has(c)&&je(299,s.name,c),this.conflicts.set(c,s.name);for(const c of s.dependencies||[]){const f=Il(c);this.addEdge(s.name,f[0].name,f.slice(1)),this.addExtension(f)}for(const[c,f]of s.peerDependencies||[])this.addEdge(s.name,c,f?[f]:[])}}sortedExtensionReps(){if(this._sortedExtensionReps)return this._sortedExtensionReps;const e=[],r=(s,l)=>{let u=s.state;if($0(u))return;const c=s.extension.name;var f;Kc(u)||je(300,c,l||"[unknown]"),Kc(f=u)||je(304,String(f.id),String(wd)),u=Object.assign(f,{id:Ff}),s.state=u;const h=this.outgoingConfigEdges.get(c);if(h)for(const g of h.keys()){const m=this.extensionNameMap.get(g);m&&r(m,c)}u=$1(u),s.state=u,e.push(s)};for(const s of this.extensionNameMap.values())Kc(s.state)&&r(s);for(const s of e)for(const[l,u]of this.outgoingConfigEdges.get(s.extension.name)||[])if(u.length>0){const c=this.extensionNameMap.get(l);if(c)for(const f of u)c.configs.add(f)}for(const[s,...l]of this.roots)if(l.length>0){const u=this.extensionNameMap.get(s.name);u===void 0&&je(301,s.name);for(const c of l)u.configs.add(c)}return this._sortedExtensionReps=e,this._sortedExtensionReps}registerEditor(e){const r=this.sortedExtensionReps(),s=new AbortController,l=[()=>s.abort()],u=s.signal;for(const c of r){const f=c.register(e,u);f&&l.push(f)}for(const c of r){const f=c.afterRegistration(e);f&&l.push(f)}return Sn(...l)}buildCreateEditorArgs(){const e={},r=new Set,s=new Map,l=new Map,u={},c={},f=this.sortedExtensionReps();for(const m of f){const{extension:v}=m;if(v.onError!==void 0&&(e.onError=v.onError),v.disableEvents!==void 0&&(e.disableEvents=v.disableEvents),v.parentEditor!==void 0&&(e.parentEditor=v.parentEditor),v.editable!==void 0&&(e.editable=v.editable),v.namespace!==void 0&&(e.namespace=v.namespace),v.$initialEditorState!==void 0&&(e.$initialEditorState=v.$initialEditorState),v.nodes)for(const y of L0(v)){if(typeof y!="function"){const S=s.get(y.replace);S&&je(302,v.name,y.replace.name,S.extension.name),s.set(y.replace,m)}r.add(y)}if(v.html){if(v.html.export)for(const[y,S]of v.html.export.entries())l.set(y,S);v.html.import&&Object.assign(u,v.html.import)}v.theme&&A0(c,v.theme)}Object.keys(c).length>0&&(e.theme=c),r.size&&(e.nodes=[...r]);const h=Object.keys(u).length>0,g=l.size>0;(h||g)&&(e.html={},h&&(e.html.import=u),g&&(e.html.export=l));for(const m of f)m.init(e);return e.onError||(e.onError=H1),e}}function Q1(t,e){const r=cr.fromEditor(t).getExtensionRep(e);return r===void 0&&je(303,e.name),r.getExtensionDependency()}function V1(t,e){const r=cr.maybeFromEditor(t);if(!r)return;const s=r.extensionNameMap.get(e);return s?s.getExtensionDependency():void 0}const q1=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0?A.useLayoutEffect:A.useEffect;function G1({onClear:t}){const[e]=on();return q1(()=>A1(e,t),[e,t]),null}function J1(){return tt().getTextContent()}function Y1(t,e=!0){if(t)return!1;let r=J1();return e&&(r=r.trim()),r===""}function X1(t){if(!Y1(t,!1))return!1;const e=tt().getChildren(),r=e.length;if(r>1)return!1;for(let s=0;sX1(t)}const U0=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0?A.useLayoutEffect:A.useEffect;function Z1({editor:t,ariaActiveDescendant:e,ariaAutoComplete:r,ariaControls:s,ariaDescribedBy:l,ariaErrorMessage:u,ariaExpanded:c,ariaInvalid:f,ariaLabel:h,ariaLabelledBy:g,ariaMultiline:m,ariaOwns:v,ariaRequired:y,autoCapitalize:S,className:_,id:w,role:C="textbox",spellCheck:T=!0,style:N,tabIndex:M,"data-testid":L,...j},D){const[$,F]=A.useState(t.isEditable()),z=A.useCallback(te=>{te&&te.ownerDocument&&te.ownerDocument.defaultView?t.setRootElement(te):t.setRootElement(null)},[t]),J=A.useMemo(()=>(function(...te){return ne=>{for(const X of te)typeof X=="function"?X(ne):X!=null&&(X.current=ne)}})(D,z),[z,D]);return U0(()=>(F(t.isEditable()),t.registerEditableListener(te=>{F(te)})),[t]),k.jsx("div",{"aria-activedescendant":$?e:void 0,"aria-autocomplete":$?r:"none","aria-controls":$?s:void 0,"aria-describedby":l,...u!=null?{"aria-errormessage":u}:{},"aria-expanded":$&&C==="combobox"?!!c:void 0,...f!=null?{"aria-invalid":f}:{},"aria-label":h,"aria-labelledby":g,"aria-multiline":m,"aria-owns":$?v:void 0,"aria-readonly":!$||void 0,"aria-required":y,autoCapitalize:S,className:_,contentEditable:$,"data-testid":L,id:w,ref:J,role:C,spellCheck:T,style:N,tabIndex:M,...j})}const ek=A.forwardRef(Z1);function Zm(t){return t.getEditorState().read(B0(t.isComposing()))}const tk=A.forwardRef(nk);function nk(t,e){const{placeholder:r,...s}=t,[l]=on();return k.jsxs(k.Fragment,{children:[k.jsx(ek,{editor:l,...s,ref:e}),r!=null&&k.jsx(rk,{editor:l,content:r})]})}function rk({content:t,editor:e}){const r=(function(c){const[f,h]=A.useState(()=>Zm(c));return U0(()=>{function g(){const m=Zm(c);h(m)}return g(),Sn(c.registerUpdateListener(()=>{g()}),c.registerEditableListener(()=>{g()}))},[c]),f})(e),[s,l]=A.useState(e.isEditable());if(A.useLayoutEffect(()=>(l(e.isEditable()),e.registerEditableListener(c=>{l(c)})),[e]),!r)return null;let u=null;return typeof t=="function"?u=t(s):t!==null&&(u=t),u===null?null:k.jsx("div",{"aria-hidden":!0,children:u})}const ik=A.createContext(null),Hc={didCatch:!1,error:null};class sk extends A.Component{constructor(e){super(e),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=Hc}static getDerivedStateFromError(e){return{didCatch:!0,error:e}}resetErrorBoundary(...e){const{error:r}=this.state;r!==null&&(this.props.onReset?.({args:e,reason:"imperative-api"}),this.setState(Hc))}componentDidCatch(e,r){this.props.onError?.(e,r)}componentDidUpdate(e,r){const{didCatch:s}=this.state,{resetKeys:l}=this.props;s&&r.error!==null&&ok(e.resetKeys,l)&&(this.props.onReset?.({next:l,prev:e.resetKeys,reason:"keys"}),this.setState(Hc))}render(){const{children:e,fallbackRender:r,FallbackComponent:s,fallback:l}=this.props,{didCatch:u,error:c}=this.state;let f=e;if(u){const h={error:c,resetErrorBoundary:this.resetErrorBoundary};if(typeof r=="function")f=r(h);else if(s)f=A.createElement(s,h);else if(l!==void 0)f=l;else throw c}return A.createElement(ik.Provider,{value:{didCatch:u,error:c,resetErrorBoundary:this.resetErrorBoundary}},f)}}function ok(t=[],e=[]){return t.length!==e.length||t.some((r,s)=>!Object.is(r,e[s]))}function lk({children:t,onError:e}){return k.jsx(sk,{fallback:k.jsx("div",{style:{border:"1px solid #f00",color:"#f00",padding:"8px"},children:"An error was thrown."}),onError:e,children:t})}function uk(t,e,r,s,l){if(t===null||r.size===0&&s.size===0&&!l)return 0;const u=e._selection,c=t._selection;if(l)return 1;if(!(ee(u)&&ee(c)&&c.isCollapsed()&&u.isCollapsed()))return 0;const f=(function(T,N,M){const L=T._nodeMap,j=[];for(const D of N){const $=L.get(D);$!==void 0&&j.push($)}for(const[D,$]of M){if(!$)continue;const F=L.get(D);F===void 0||lt(F)||j.push(F)}return j})(e,r,s);if(f.length===0)return 0;if(f.length>1){const T=e._nodeMap,N=T.get(u.anchor.key),M=T.get(c.anchor.key);return N&&M&&!t._nodeMap.has(N.__key)&&re(N)&&N.__text.length===1&&u.anchor.offset===1?2:0}const h=f[0],g=t._nodeMap.get(h.__key);if(!re(g)||!re(h)||g.__mode!==h.__mode)return 0;const m=g.__text,v=h.__text;if(m===v)return 0;const y=u.anchor,S=c.anchor;if(y.key!==S.key||y.type!=="text")return 0;const _=y.offset,w=S.offset,C=v.length-m.length;return C===1&&w===_-1?2:C===-1&&w===_+1?3:C===-1&&w===_?4:0}function ak(t,e,r){let s=r(),l=0,u=s,c=0,f=null;return(h,g,m,v,y,S)=>{const _=r();if(S.has(Iv)&&(u=s,c=l,f=h),S.has(Ef))return l=0,s=_,2;S.has(Lv)&&f&&(s=u,l=c,h=f);const w=uk(h,g,v,y,t.isComposing()),C=(()=>{const T=m===null||m.editor===t,N=S.has(CC);if(!N&&T&&S.has(Fi))return 0;if(w===1)return 2;if(h===null)return 1;const M=g._selection;if(!(v.size>0||y.size>0))return M!==null?0:2;const L=typeof e=="number"?e:e.peek();return N===!1&&w!==0&&w===l&&_F.exportJSON()))===JSON.stringify($.read(()=>z.exportJSON()))})(Array.from(v)[0],h,g)?0:1})();return s=_,l=w,C}}function ey(t){t.undoStack=[],t.redoStack=[],t.current=null}function K0(t,e,r,s=Date.now){const l=ak(t,r,s);return Sn(t.registerCommand(Yf,()=>((function(u,c){const f=c.redoStack,h=c.undoStack;if(h.length!==0){const g=c.current,m=h.pop();g!==null&&(f.push(g),u.dispatchCommand(Ol,!0)),h.length===0&&u.dispatchCommand(Ml,!1),c.current=m||null,m&&m.editor.setEditorState(m.editorState,{tag:Ef})}})(t,e),!0),De),t.registerCommand(Xf,()=>((function(u,c){const f=c.redoStack,h=c.undoStack;if(f.length!==0){const g=c.current;g!==null&&(h.push(g),u.dispatchCommand(Ml,!0));const m=f.pop();f.length===0&&u.dispatchCommand(Ol,!1),c.current=m||null,m&&m.editor.setEditorState(m.editorState,{tag:Ef})}})(t,e),!0),De),t.registerCommand(td,()=>(ey(e),!1),De),t.registerCommand(hC,()=>(ey(e),t.dispatchCommand(Ol,!1),t.dispatchCommand(Ml,!1),!0),De),t.registerUpdateListener(({editorState:u,prevEditorState:c,dirtyLeaves:f,dirtyElements:h,tags:g})=>{const m=e.current,v=e.redoStack,y=e.undoStack,S=m===null?null:m.editorState;if(m!==null&&u===S)return;const _=l(c,u,m,f,h,g);if(_===1)v.length!==0&&(e.redoStack=[],t.dispatchCommand(Ol,!1)),m!==null&&(y.push({...m}),t.dispatchCommand(Ml,!0));else if(_===2)return;e.current={editor:t,editorState:u}}))}function W0(){return{current:null,redoStack:[],undoStack:[]}}const Qc={build:(t,{delay:e,createInitialHistoryState:r,disabled:s,now:l})=>I0({delay:e,disabled:s,historyState:r(t),now:l}),config:{createInitialHistoryState:W0,delay:300,disabled:typeof window>"u",now:Date.now},name:"@lexical/history/History",register:(t,e,r)=>{const s=r.getOutput();return Sd(()=>s.disabled.value?void 0:K0(t,s.historyState.value,s.delay,()=>s.now.peek()()))}};x1(Qc,{disabled:!0});function ck({delay:t,externalHistoryState:e}){const[r]=on();return(function(s,l,u=1e3){const c=A.useMemo(()=>l||W0(),[l]);A.useEffect(()=>K0(s,c,u),[u,s,c])})(r,e,t),null}const fk=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0?A.useLayoutEffect:A.useEffect;function dk(t){return{initialValueFn:()=>t.isEditable(),subscribe:e=>t.registerEditableListener(e)}}function hk(){return(function(t){const[e]=on(),r=A.useMemo(()=>t(e),[e,t]),[s,l]=A.useState(()=>r.initialValueFn()),u=A.useRef(s);return fk(()=>{const{initialValueFn:c,subscribe:f}=r,h=c();return u.current!==h&&(u.current=h,l(h)),f(g=>{u.current=g,l(g)})},[r,t]),s})(dk)}const pk={name:"@lexical/react/ReactProvider"};var so=Ey();const gk=ky(so);function mk(t){const e=window.location.origin,r=s=>{if(s.origin!==e)return;const l=t.getRootElement();if(document.activeElement!==l)return;const u=s.data;if(typeof u=="string"){let c;try{c=JSON.parse(u)}catch{return}if(c&&c.protocol==="nuanria_messaging"&&c.type==="request"){const f=c.payload;if(f&&f.functionId==="makeChanges"){const h=f.args;if(h){const[g,m,v,y,S]=h;t.update(()=>{const _=de();if(ee(_)){const w=_.anchor;let C=w.getNode(),T=0,N=0;if(re(C)&&g>=0&&m>=0&&(T=g,N=g+m,_.setTextNodeRange(C,T,C,N)),T===N&&v===""||(_.insertRawText(v),C=w.getNode()),re(C)){T=y,N=y+S;const M=C.getTextContentSize();T=T>M?M:T,N=N>M?M:N,_.setTextNodeRange(C,T,C,N)}s.stopImmediatePropagation()}})}}}}};return window.addEventListener("message",r,!0),()=>{window.removeEventListener("message",r,!0)}}function H0(t,...e){const r=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",t);for(const l of e)s.append("v",l);throw r.search=s.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}let Li;function Q0(t,e){const{key:r}=e;return t&&r in t?t[r]:e.defaultValue}function ty(t){return Li&&Li.editor===t?Li:void 0}function yk(t,e){if("cfg"in e){const{cfg:r,updater:s}=e;return[r,s(Q0(t,r))]}return e}function V0(t,e){let r=e;for(const s of t){const[l,u]=yk(r,s),c=l.key;if(r===e&&Q0(r,l)===u)continue;const f=r||vk(e);f[c]=u,r=f}return r}function vk(t){return Object.create(t||null)}function xk(t,e){return[t,e]}const q0="@lexical/html/DOM",G0=Symbol.for("@lexical/html/DOMExportContext"),_k=()=>!0;function Sk(t){return e=>e instanceof t}function wk(t,{nodes:e}){if(e==="*")return _k;let r={};const s=[];for(const l of e)if("getType"in l){const u=l.getType();if(r){const c=t[u];c===void 0&&H0(339,l.name,u),r=Object.assign(r,c.types)}s.push(Sk(l))}else r=void 0,s.push(l);return r||(s.length===1?s[0]:l=>{for(const u of s)if(u(l))return!0;return!1})}function ny(t){return(e,r,s)=>t(e,s)}function Vc(t){return(e,r,s,l)=>t(e,r,l)}function Ck(t){return(e,r,s,l,u)=>t(e,r,s,u)}function kk(t){return(e,r,s,l,u,c)=>t(e,r,s,l,c)}function ry(t,e){return(r,s)=>{const l=()=>t(r,s),u=e(r);return u?u(r,l,s):l()}}function qc(t,e){return(r,s,l)=>{const u=()=>t(r,s,l),c=e(r);return c?c(r,s,u,l):u()}}function Ek(t,e){return(r,s,l,u)=>{const c=()=>t(r,s,l,u),f=e(r);return f?f(r,s,l,c,u):c()}}function Nk(t,e){return(r,s,l,u,c)=>{const f=()=>t(r,s,l,u,c),h=e(r);return h?h(r,s,l,u,f,c):f()}}function Tk(t,e){return(r,s,l,u)=>{t(r,s,l,u);const c=e(r);c&&c(r,s,l,u)}}function sr(t,e,r,s,l){let u=r[e];for(const c of t[e])if(typeof c[0]=="function"){const[f,h]=c;u=s(u,g=>f(g)&&h||void 0)}else{const f=c[1],h={};for(const g in f){const m=f[g];m&&(h[g]=m.reduce((v,y)=>s(v,()=>y),u))}u=s(u,g=>{const m=h[g.getType()];return m&&l(m)})}r[e]=u}function Ok(t,e,r,s){if(!s)return;const l=t[e];if(typeof r=="function")l.push([r,s]);else{const u=l[l.length-1];let c;u&&u[0]==="types"?c=u[1]:(c={},l.push(["types",c]));for(const f in r){const h=c[f]||[];c[f]=h,h.push(s)}}}function Mk(t){return t.nodes==="*"}function Pk(t,e){const r=(function(l){const u={},{nodes:c}=z1(l);for(const f of c)u[f.getType()]={klass:f,types:{}};for(const f of Object.values(u))if(f){const h=f.klass.getType();for(let{klass:g}=f;Rc(g.prototype);g=Object.getPrototypeOf(g)){const{ownNodeType:m}=qi(g),v=m&&u[m];v&&(v.types[h]=!0)}}return u})(t),s={$createDOM:[],$decorateDOM:[],$exportDOM:[],$extractWithChild:[],$getDOMSlot:[],$shouldExclude:[],$shouldInclude:[],$updateDOM:[]};for(const l of(function(u){const c=[],f=[],h=[];for(const v of u)if(Mk(v))c.push(v);else if(Array.isArray(v.nodes))for(const y of v.nodes)Rc(y.prototype)?h.push(v.nodes.length===1?v:{...v,nodes:[y]}):f.push(v.nodes.length===1?v:{...v,nodes:[y]});const g=new Map,m=v=>{let y=g.get(v);if(y===void 0){y=0;for(let S=v;Rc(S.prototype);S=Object.getPrototypeOf(S))y++;g.set(v,y)}return y};return h.sort((v,y)=>m(v.nodes[0])-m(y.nodes[0])),[...h,...f,...c]})(e)){const u=wk(r,l);for(const c in s)Ok(s,c,u,l[c])}return s}function bk(t){return t}const Rk={build:(t,e,r)=>({defaults:V0(e.contextDefaults,void 0)}),config:{contextDefaults:[],overrides:[]},html:{export:new Map([[Yr,()=>{const t=document.createElement("div");return t.role="textbox",{element:t}}]])},init(t,e){t.dom=(function(r,{overrides:s}){const l=Pk(r,s),u={...no,...r.dom};return sr(l,"$createDOM",u,ry,ny),sr(l,"$exportDOM",u,ry,ny),sr(l,"$extractWithChild",u,Nk,kk),sr(l,"$getDOMSlot",u,qc,Vc),sr(l,"$shouldExclude",u,qc,Vc),sr(l,"$shouldInclude",u,qc,Vc),sr(l,"$updateDOM",u,Ek,Ck),sr(l,"$decorateDOM",u,Tk,bk),u})(t,e)},mergeConfig(t,e){const r=k0(t,e);for(const s of["overrides","contextDefaults"])e[s]&&(r[s]=[...t[s],...e[s]]);return r},name:q0};function J0(t,e,r){return(function(s,l,u,c){return Object.assign(iv(Symbol(l),{isEqual:c,parse:u}),{[s]:!0})})(G0,t,e,r)}J0("root",Boolean);const Dk=J0("isExport",Boolean);function jk(t){const e=cr.maybeFromEditor(t);return e&&e.hasExtensionByName(q0)?Q1(t,Rk).output.defaults:void 0}const Fk=(function(t,e=()=>{}){return(r,s=Ui())=>l=>{const u=ty(s),c=u&&u[t],f=V0(r,c||e(s));return f&&f!==c?(function(h,g,m,v=Ui()){const y=Li,S=ty(v);try{return Li={...S,editor:v,[h]:g},m()}finally{Li=y}})(t,f,l,s):l()}})(G0,jk);function Ik(t,e=null,r=Ui()){return Fk([xk(Dk,!0)],r)(()=>{const s=tt(),l=po(r),u=t.append.bind(t);for(const c of s.getChildren())Y0(r,c,u,e,l);return t})}function Lk(t,e=null){return(typeof document>"u"||typeof window>"u"&&global.window===void 0)&&H0(338),Ik(document.createElement("div"),e,t).innerHTML}function Y0(t,e,r,s=null,l=po(t)){let u=l.$shouldInclude(e,s,t);const c=l.$shouldExclude(e,s,t);let f=e;s!==null&&re(e)&&(f=M1(s,e,"clone"));const h=l.$exportDOM(f,t),{element:g,after:m,append:v,$getChildNodes:y}=h;if(!g)return!1;const S=document.createDocumentFragment(),_=y?y():K(f)?f.getChildren():[],w=S.append.bind(S);for(const C of _){const T=Y0(t,C,w,s,l);!u&&T&&l.$extractWithChild(e,C,s,"html",t)&&(u=!0)}if(u&&!c){if((Pt(g)||bf(g))&&(v?v(S):g.append(S)),r(g),m){const C=m.call(f,g);C&&(bf(g)?g.replaceChildren(C):g.replaceWith(C))}}else r(S);return u}function Ak(t,...e){const r=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",t);for(const l of e)s.append("v",l);throw r.search=s.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function zk(t,e=de()){return e==null&&Ak(166),ee(e)&&e.isCollapsed()||e.getNodes().length===0?"":Lk(t,e)}function If(t,e){const r=t.getData("text/plain")||t.getData("text/uri-list");r!=null&&e.insertRawText(r)}const X0="application/x-lexical-drag";function $k(t,e){const r={editorKey:e.getKey()};t.setData(X0,JSON.stringify(r))}function Bk(t){const e=(function(l,u){if(document.caretRangeFromPoint!==void 0){const c=document.caretRangeFromPoint(l,u);return c===null?null:{node:c.startContainer,offset:c.startOffset}}if(document.caretPositionFromPoint!=="undefined"){const c=document.caretPositionFromPoint(l,u);return c===null?null:{node:c.offsetNode,offset:c.offset}}return null})(t.clientX,t.clientY);if(e===null)return null;const r=ku(e.node);if(r===null)return null;if(re(r))return dr(r,"next",e.offset);if(K(r))return Df(r,e.offset,"next");const s=r.getParent();return s===null?null:Df(s,r.getIndexWithinParent()+1,"next")}function Uk(t,e,r){const s=t.dataTransfer;if(s===null)return!1;const l=(function(g){const m=g.getData(X0);if(!m)return null;let v;try{v=JSON.parse(m)}catch{return null}return(y=v)!==null&&typeof y=="object"&&"editorKey"in y&&typeof y.editorKey=="string"?v:null;var y})(s);if(l===null)return!1;const u=Bk(t);if(u===null)return!1;const c=v1(u);if(c===null)return!1;const f=l.editorKey===e.getKey(),h=de();if(f){if(!ee(h)||h.isCollapsed())return!1;if((function(g,m){const{anchor:v,focus:y}=xd(Rf(m),"next");return cu(v,g)<0&&cu(g,y)<0})(u,h))return t.preventDefault(),!0;h.removeText()}if(!c.origin.isAttached())return t.preventDefault(),!0;if(r(s,w0(x0(c)),e),!f){const g=e.getRootElement(),m=g?g.ownerDocument:null,v=m?(function(y,S){const _=S.querySelectorAll('[data-lexical-editor="true"]');for(const w of Array.from(_)){const C=w.__lexicalEditor;if(C&&C.getKey()===y)return w}return null})(l.editorKey,m):null;v!==null&&v.dispatchEvent(new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,inputType:"deleteByDrag"}))}return t.preventDefault(),!0}function Kk(t,e){return Uk(t,e,(r,s)=>If(r,s))}const vr=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0,Wk=vr&&"documentMode"in document?document.documentMode:null,Hk=vr&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),Qk=!(!vr||!("InputEvent"in window)||Wk)&&"getTargetRanges"in new window.InputEvent("input"),iy=vr&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,Vk=vr&&/Android/.test(navigator.userAgent),qk=vr&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!Vk,Gk=vr&&/^(?=.*Chrome).*/i.test(navigator.userAgent),Jk=vr&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&Hk&&!Gk;function sy(t,e){e.update(()=>{if(t!==null){const r=R0(t,KeyboardEvent)?null:t.clipboardData,s=de();if(s!==null&&!s.isCollapsed()&&r!=null){t.preventDefault();const l=zk(e);l!==null&&r.setData("text/html",l),r.setData("text/plain",s.getTextContent())}}})}function Yk(t){return Sn(t.registerCommand(Ar,e=>{const r=de();return!!ee(r)&&(r.deleteCharacter(e),!0)},De),t.registerCommand(Xs,e=>{const r=de();return!!ee(r)&&(r.deleteWord(e),!0)},De),t.registerCommand(Zs,e=>{const r=de();return!!ee(r)&&(r.deleteLine(e),!0)},De),t.registerCommand(Di,e=>{const r=de();if(!ee(r))return!1;if(typeof e=="string")r.insertText(e);else{const s=e.dataTransfer;if(s!=null)If(s,r);else{const l=e.data;l&&r.insertText(l)}}return!0},De),t.registerCommand(Bl,()=>{const e=de();return!!ee(e)&&(e.removeText(),!0)},De),t.registerCommand(Ri,e=>{const r=de();return!!ee(r)&&(r.insertLineBreak(e),!0)},De),t.registerCommand(vf,()=>{const e=de();return!!ee(e)&&(e.insertLineBreak(),!0)},De),t.registerCommand(vv,e=>{const r=de();if(!ee(r))return!1;const s=e,l=s.shiftKey;return!!Hm(r,!0)&&(s.preventDefault(),Qm(r,l,!0),!0)},De),t.registerCommand(yv,e=>{const r=de();if(!ee(r))return!1;const s=e,l=s.shiftKey;return!!Hm(r,!1)&&(s.preventDefault(),Qm(r,l,!1),!0)},De),t.registerCommand(Sv,e=>{const r=de();return!!ee(r)&&(!iy||navigator.language!=="ko-KR")&&(e.preventDefault(),t.dispatchCommand(Ar,!0))},De),t.registerCommand(Cv,e=>{const r=de();return!!ee(r)&&(e.preventDefault(),t.dispatchCommand(Ar,!1))},De),t.registerCommand(Ai,e=>{const r=de();if(!ee(r))return!1;if(e!==null){if((iy||qk||Jk)&&Qk)return!1;e.preventDefault()}return t.dispatchCommand(Ri,!1)},De),t.registerCommand(xf,()=>(JC(),!0),De),t.registerCommand(Zf,e=>{const r=de();return!!ee(r)&&(sy(e,t),!0)},De),t.registerCommand(ed,e=>{const r=de();return!!ee(r)&&((function(s,l){sy(s,l),l.update(()=>{const u=de();ee(u)&&u.removeText()})})(e,t),!0)},De),t.registerCommand(Jf,e=>{const r=de();return!!ee(r)&&((function(s,l){s.preventDefault(),l.update(()=>{const u=de(),c=R0(s,ClipboardEvent)?s.clipboardData:null;c!=null&&ee(u)&&If(c,u)},{tag:kC})})(e,t),!0)},De),t.registerCommand(Ev,e=>Kk(e,t),De),t.registerCommand(Nv,e=>{const r=de();return!!ee(r)&&(r.isCollapsed()||e.dataTransfer===null||$k(e.dataTransfer,t),!0)},De))}function Xk(t,...e){const r=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",t);for(const l of e)s.append("v",l);throw r.search=s.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const Cd=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0?A.useLayoutEffect:A.useEffect;function Zk({editor:t,ErrorBoundary:e}){return(function(r,s){const[l,u]=A.useState(()=>r.getDecorators());return Cd(()=>r.registerDecoratorListener(c=>{so.flushSync(()=>{u(c)})}),[r]),A.useEffect(()=>{u(r.getDecorators())},[r]),A.useMemo(()=>{const c=[],f=Object.keys(l);for(let h=0;hr._onError(y),children:k.jsx(A.Suspense,{fallback:null,children:l[g]})}),v=r.getElementByKey(g);v!==null&&c.push(so.createPortal(m,v,g))}return c},[s,l,r])})(t,e)}function eE({editor:t,ErrorBoundary:e}){return(function(r){const s=cr.maybeFromEditor(r);if(s&&s.hasExtensionByName(pk.name)){for(const l of["@lexical/plain-text","@lexical/rich-text"])s.hasExtensionByName(l)&&Xk(320,l);return!0}return!1})(t)?null:k.jsx(Zk,{editor:t,ErrorBoundary:e})}function oy(t){return t.getEditorState().read(B0(t.isComposing()))}function tE({contentEditable:t,placeholder:e=null,ErrorBoundary:r}){const[s]=on();return(function(l){Cd(()=>Sn(Yk(l),mk(l)),[l])})(s),k.jsxs(k.Fragment,{children:[t,k.jsx(nE,{content:e}),k.jsx(eE,{editor:s,ErrorBoundary:r})]})}function nE({content:t}){const[e]=on(),r=(function(l){const[u,c]=A.useState(()=>oy(l));return Cd(()=>{function f(){const h=oy(l);c(h)}return f(),Sn(l.registerUpdateListener(()=>{f()}),l.registerEditableListener(()=>{f()}))},[l]),u})(e),s=hk();return r?typeof t=="function"?t(s):t:null}const ly="startTransition",Lf=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0,rE=Lf?A.useLayoutEffect:A.useEffect;class iE{key;ref;icon;title;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}const uy=t=>{const e=document.getElementById("typeahead-menu");if(!e)return;const r=e.getBoundingClientRect();r.top+r.height>window.innerHeight&&e.scrollIntoView({block:"center"}),r.top<0&&e.scrollIntoView({block:"center"}),t.scrollIntoView({block:"nearest"})};function ay(t,e){const r=t.getBoundingClientRect(),s=e.getBoundingClientRect();return r.top>=s.top-6&&r.top<=s.bottom+6}function sE(t,e,r,s){const[l]=on();A.useEffect(()=>{if(e!=null&&t!=null){const u=l.getRootElement(),c=u!=null?(function(v){let y=getComputedStyle(v);const S=y.position==="absolute",_=/(auto|scroll)/;if(y.position==="fixed")return document.body;for(let w=v;w=w.parentElement;)if(y=getComputedStyle(w),(!S||y.position!=="static")&&_.test(y.overflow+y.overflowY+y.overflowX))return w;return document.body})(u):document.body;let f=!1,h=ay(e,c);const g=function(){f||(window.requestAnimationFrame(function(){r(),f=!1}),f=!0);const v=ay(e,c);v!==h&&(h=v,s?.(v))},m=new ResizeObserver(r);return window.addEventListener("resize",r),document.addEventListener("scroll",g,{capture:!0,passive:!0}),m.observe(e),()=>{m.unobserve(e),window.removeEventListener("resize",r),document.removeEventListener("scroll",g,!0)}}},[e,l,s,r,t])}const cy=xe("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function oE({index:t,isSelected:e,onClick:r,onMouseEnter:s,option:l}){let u="item";return e&&(u+=" selected"),k.jsxs("li",{tabIndex:-1,className:u,ref:l.setRefElement,role:"option","aria-selected":e,id:"typeahead-item-"+t,onMouseEnter:s,onClick:r,children:[l.icon,k.jsx("span",{className:"text",children:l.title})]},l.key)}function lE({close:t,editor:e,anchorElementRef:r,resolution:s,options:l,menuRenderFn:u,onSelectOption:c,shouldSplitNodeWithQuery:f=!1,commandPriority:h=t0,preselectFirstItem:g=!0}){const[m,v]=A.useState(null),y=m!==null?Math.min(l.length-1,m):null,S=s.match&&s.match.matchingString;A.useEffect(()=>{g&&v(0)},[S,g]);const _=A.useCallback(N=>{e.update(()=>{const M=s.match!=null&&f?(function(L){const j=de();if(!ee(j)||!j.isCollapsed())return null;const D=j.anchor;if(D.type!=="text")return null;const $=D.getNode();if(!$.isSimpleText())return null;const F=D.offset,z=$.getTextContent().slice(0,F),J=L.replaceableString.length,te=F-(function(X,ae,Se){let ye=Se;for(let _e=ye;_e<=ae.length;_e++)X.slice(-_e)===ae.substring(0,_e)&&(ye=_e);return ye})(z,L.matchingString,J);if(te<0)return null;let ne;return te===0?[ne]=$.splitText(F):[,ne]=$.splitText(te,F),ne})(s.match):null;c(N,M,t,s.match?s.match.matchingString:"")})},[e,f,s.match,c,t]),w=A.useCallback(N=>{const M=e.getRootElement();M!==null&&(M.setAttribute("aria-activedescendant","typeahead-item-"+N),v(N))},[e]),C=A.useCallback(()=>r.current&&l.length?gk.createPortal(k.jsx("div",{className:"typeahead-popover mentions-menu",children:k.jsx("ul",{children:l.map((N,M)=>k.jsx(oE,{index:M,isSelected:y===M,onClick:()=>{v(M),_(N)},onMouseEnter:()=>{v(M)},option:N},N.key))})}),r.current):null,[r,l,y,_,v]);A.useEffect(()=>()=>{const N=e.getRootElement();N!==null&&N.removeAttribute("aria-activedescendant")},[e]),rE(()=>{l===null?v(null):y===null&&g&&w(0)},[l,y,w,g]),A.useEffect(()=>Sn(e.registerCommand(cy,({option:N})=>!(!N.ref||N.ref.current==null)&&(uy(N.ref.current),!0),h)),[e,w,h]),A.useEffect(()=>Sn(e.registerCommand(_v,N=>{const M=N;if(l!==null&&l.length){const L=y===null?0:y!==l.length-1?y+1:0;w(L);const j=l[L];if(!j)return w(-1),M.preventDefault(),M.stopImmediatePropagation(),!0;j.ref&&j.ref.current&&e.dispatchCommand(cy,{index:L,option:j}),M.preventDefault(),M.stopImmediatePropagation()}return!0},h),e.registerCommand(xv,N=>{const M=N;if(l!==null&&l.length){const L=y===null?l.length-1:y!==0?y-1:l.length-1;w(L);const j=l[L];if(!j)return w(-1),M.preventDefault(),M.stopImmediatePropagation(),!0;j.ref&&j.ref.current&&uy(j.ref.current),M.preventDefault(),M.stopImmediatePropagation()}return!0},h),e.registerCommand(wv,N=>{const M=N;return M.preventDefault(),M.stopImmediatePropagation(),t(),!0},h),e.registerCommand(kv,N=>{const M=N;return l!==null&&y!==null&&l[y]!=null&&(M.preventDefault(),M.stopImmediatePropagation(),_(l[y]),!0)},h),e.registerCommand(Ai,N=>l!==null&&y!==null&&l[y]!=null&&(N!==null&&(N.preventDefault(),N.stopImmediatePropagation()),_(l[y]),!0),h)),[_,t,e,l,y,w,h]);const T=A.useMemo(()=>({options:l,selectOptionAndCleanUp:_,selectedIndex:y,setHighlightedIndex:v}),[_,y,l]);return u!=null?u(r,T,s.match?s.match.matchingString:""):C()}function fy(t,e){e!=null&&(t.className=e),t.setAttribute("aria-label","Typeahead menu"),t.setAttribute("role","listbox"),t.style.display="block",t.style.position="absolute"}const uE=`\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'"~=<>_:;`;function aE(t,{minLength:e=1,maxLength:r=75,punctuation:s=uE,allowWhitespace:l=!1}){return A.useCallback(u=>{const c=new RegExp("(^|\\s|\\()(["+t+"]((?:"+("[^"+t+s+(l?"":"\\s")+"]")+"){0,"+r+"}))$").exec(u);if(c!==null){const f=c[1],h=c[3];if(h.length>=e)return{leadOffset:c.index+f.length,matchingString:h,replaceableString:c[2]}}return null},[l,t,s,r,e])}function cE({options:t,onQueryChange:e,onSelectOption:r,onOpen:s,onClose:l,menuRenderFn:u,triggerFn:c,anchorClassName:f,commandPriority:h=t0,parent:g,preselectFirstItem:m=!0,ignoreEntityBoundary:v=!1}){const[y]=on(),[S,_]=A.useState(null),w=(function(N,M,L,j=Lf?document.body:void 0,D=!0){const[$]=on(),F=Lf?document.createElement("div"):null,z=A.useRef(F),J=A.useCallback(()=>{if(z.current===null||j===void 0)return;z.current.style.top=z.current.style.bottom;const ne=$.getRootElement(),X=z.current,ae=X.firstChild;if(ne!==null&&N!==null){const{left:Se,top:ye,width:_e,height:Z}=N.getRect(),W=z.current.offsetHeight;if(X.style.top=`${ye+W+3+(D?window.pageYOffset:0)}px`,X.style.left=`${Se+window.pageXOffset}px`,X.style.height=`${Z}px`,X.style.width=`${_e}px`,ae!==null){ae.style.top=`${ye}`;const Q=ae.getBoundingClientRect(),P=Q.height,U=Q.width,he=ne.getBoundingClientRect();Se+U>he.right&&(X.style.left=`${he.right-U+window.pageXOffset}px`),(ye+P>window.innerHeight||ye+P>he.bottom)&&ye-he.top>P+Z&&(X.style.top=`${ye-P-Z+(D?window.pageYOffset:0)}px`)}X.isConnected||(fy(X,L),j.append(X)),X.setAttribute("id","typeahead-menu"),ne.setAttribute("aria-controls","typeahead-menu")}},[$,N,D,L,j]);A.useEffect(()=>{const ne=$.getRootElement();return N!==null&&J(),()=>{ne!==null&&ne.removeAttribute("aria-controls");const X=z.current;X!==null&&X.isConnected&&(X.remove(),X.removeAttribute("id"))}},[$,J,N]);const te=A.useCallback(ne=>{N!==null&&(ne||M(null))},[N,M]);return sE(N,z.current,J,te),F!=null&&F===z.current&&(fy(F,L),j?.append(F)),z})(S,_,f,g),C=A.useCallback(()=>{_(null),l!=null&&S!==null&&l()},[l,S]),T=A.useCallback(N=>{_(N),s!=null&&S===null&&s(N)},[s,S]);return A.useEffect(()=>{const N=y.registerUpdateListener(()=>{y.getEditorState().read(()=>{if(!y.isEditable())return void C();if(y.isComposing())return;const M=y._window||window,L=M.document.createRange(),j=de(),D=(function(z){let J=null;return z.getEditorState().read(()=>{const te=de();ee(te)&&(J=(function(ne){const X=ne.anchor;if(X.type!=="text")return null;const ae=X.getNode();if(!ae.isSimpleText())return null;const Se=X.offset;return ae.getTextContent().slice(0,Se)})(te))}),J})(y);if(!ee(j)||!j.isCollapsed()||D===null||L===null)return void C();const $=c(D,y);if(e($?$.matchingString:null),$!==null&&(v||!(function(z,J){return J===0&&z.getEditorState().read(()=>{const te=de();if(ee(te)){const ne=te.anchor.getNode().getPreviousSibling();return re(ne)&&ne.isTextEntity()}return!1})})(y,$.leadOffset))&&(function(J,te,ne){const X=un(ne);if(X===null||!X.isCollapsed)return!1;const ae=X.anchorNode,Se=J,ye=X.anchorOffset;if(ae==null||ye==null)return!1;try{te.setStart(ae,Se),te.setEnd(ae,ye)}catch{return!1}return!0})($.leadOffset,L,M)!==null)return F=()=>T({getRect:()=>L.getBoundingClientRect(),match:$}),void(ly in Yc?Yc[ly](F):F());var F;C()})});return()=>{N()}},[y,c,e,S,C,T,v]),A.useEffect(()=>y.registerEditableListener(N=>{N||C()}),[y,C]),S===null||y===null||w.current===null?null:k.jsx(lE,{close:C,resolution:S,editor:y,anchorElementRef:w,options:t,menuRenderFn:u,shouldSplitNodeWithQuery:!0,onSelectOption:r,commandPriority:h,preselectFirstItem:m})}function kd(){return gr({queryKey:["agents"],queryFn:sn.agents})}function Ed(){return gr({queryKey:["rooms"],queryFn:sn.rooms})}class mo extends mr{__mention;static getType(){return"mention"}static clone(e){return new mo(e.__mention,e.__text,e.__key)}static importJSON(e){const r=Z0(e.mentionName);return r.setFormat(e.format),r.setDetail(e.detail),r.setMode(e.mode),r.setStyle(e.style),r}constructor(e,r,s){super(r??`@${e}`,s),this.__mention=e}exportJSON(){return{...super.exportJSON(),mentionName:this.__mention,type:"mention",version:1}}createDOM(e){const r=super.createDOM(e);return r.style.color="var(--color-green)",r.style.background="var(--color-tint)",r.style.padding="0 4px",r.style.borderRadius="3px",r}isTextEntity(){return!0}isToken(){return!0}getMentionName(){return this.__mention}}function Z0(t){const e=new mo(t);return e.setMode("token"),e}function fE(t){return t instanceof mo}const dE=5,Ll=6,gn=8,Al=360,hE=220,dy=360,pE=260,hy=3;class gE extends iE{agent;constructor(e){super(e.id),this.agent=e}}function mE(t,e,r){return r{const g=u.current;if(!g)return;const m=()=>{const S=t.getBoundingClientRect();if(!(S.left>gn&&S.top>gn)){h(ae=>({...ae,left:-1e4,top:-1e4,visibility:"hidden"}));return}c.current??={bottom:S.bottom,top:S.top};const w=c.current,C=window.innerWidth,T=window.innerHeight,N=Math.min(dy,Math.max(hE,C-gn*2)),M=Math.max(gn,w.top-hy),L=Math.max(M,w.bottom+hy),j=Math.max(0,M-gn-Ll),D=Math.max(0,T-L-gn-Ll),$=Math.min(g.scrollHeight,Al),F=Math.min(Math.max($,pE),Al),J=(D>=F?"down":j>=F||j>D?"up":"down")==="up",te=Math.max(96,Math.min(Al,J?j:D)),ne=Math.min($,te),X=J?Math.max(gn,M-ne-Ll):Math.min(L+Ll,T-gn-ne);h({left:mE(S.left,gn,C-N-gn),maxHeight:te,overflowY:$>te?"auto":"hidden",position:"fixed",top:X,visibility:"visible",width:N,zIndex:60})};m();const v=window.requestAnimationFrame(m);window.addEventListener("resize",m),document.addEventListener("scroll",m,{capture:!0,passive:!0});const y=new ResizeObserver(m);return y.observe(g),()=>{window.cancelAnimationFrame(v),y.disconnect(),window.removeEventListener("resize",m),document.removeEventListener("scroll",m,!0)}},[t,e.length]),k.jsx("div",{ref:u,"data-mention-menu":"true",role:"listbox",className:"bg-bg border border-line rounded shadow-lg p-1 overflow-auto",style:f,onMouseDown:g=>g.preventDefault(),children:e.map((g,m)=>k.jsxs("div",{ref:g.setRefElement,role:"option","aria-selected":m===r,tabIndex:-1,title:g.agent.fqid??g.agent.id,className:`px-2.5 py-1.5 cursor-pointer text-xs rounded ${m===r?"bg-tint text-green":"text-sub"}`,onClick:()=>s(g),onMouseEnter:()=>l(m),children:[k.jsxs("span",{className:"block font-semibold break-words leading-relaxed",children:["@",g.agent.id]}),g.agent.fqid?k.jsx("span",{className:"block text-faint text-[11px] break-all",children:g.agent.fqid}):null]},g.agent.id))})}function vE(){const[t]=on(),[e,r]=A.useState(null),{data:s=[]}=kd(),{data:l=[]}=Ed(),{selected:u}=wt(),c=A.useMemo(()=>{if(!u||u.kind!=="room")return s;const m=l.find(y=>y.id===u.id);if(!m)return[];const v=new Set(m.members??[]);return s.filter(y=>v.has(y.id)||(y.rooms??[]).includes(u.id))},[s,l,u]),f=A.useMemo(()=>{if(e===null)return[];const m=e.toLowerCase();return c.filter(v=>v.id.toLowerCase().includes(m)||(v.fqid?.toLowerCase().includes(m)??!1)).slice(0,dE).map(v=>new gE(v))},[c,e]),h=aE("@",{minLength:0}),g=A.useCallback((m,v,y)=>{t.update(()=>{const S=Z0(m.agent.id);v&&v.replace(S),S.select(),y()})},[t]);return k.jsx(cE,{onQueryChange:r,onSelectOption:g,triggerFn:h,options:f,commandPriority:n0,menuRenderFn:(m,{selectedIndex:v,selectOptionAndCleanUp:y,setHighlightedIndex:S})=>!m.current||f.length===0?null:so.createPortal(k.jsx(yE,{anchorElement:m.current,options:f,selectedIndex:v,selectOptionAndCleanUp:y,setHighlightedIndex:S}),document.body)})}function xE(t){return t?.capabilities?.event_stream==="sse"}function Gi(t){return t?.capabilities?.direct_messages===!0}function _E(t){return t?.capabilities?.message_pagination==="cursor"}function py(t){if(typeof t=="boolean")return t?"enabled":"disabled";const e=t?.trim();return e||"unsupported"}function Nd(){const{data:t}=wn(),e=Gi(t),r=gr({queryKey:["dms"],queryFn:sn.dms,enabled:e});return{...r,data:e?r.data:[],directMessagesEnabled:e}}function SE(){return document.querySelector('[data-mention-menu="true"]')!==null}function wE(){const t=[],e=[],r=tt();for(const s of r.getChildren()){if(!K(s))continue;let l="";for(const u of s.getChildren())fE(u)?(e.push(u.getMentionName()),l+=u.getTextContent()):re(u)&&(l+=u.getTextContent());t.push(l)}return{text:t.join(` -`),mentions:e}}function CE(t){return t instanceof Qy?t.status===401?"Sending requires a console token with write scope.":t.status===403?t.message||"This console token cannot send here.":t.message||`Message send failed (${t.status}).`:t instanceof Error&&t.message.trim()!==""?t.message:"Message could not be sent."}function kE(){const[t]=on(),{selected:e}=wt(),{data:r=[]}=Nd(),{data:s}=wn(),l=Gi(s),[u,c]=A.useState(null),f=vw({mutationFn:sn.sendMessage,onSuccess:()=>{c(null),t.dispatchCommand(td,void 0)},onError:h=>{c(CE(h))}});return A.useEffect(()=>t.registerCommand(Ai,h=>{if(h===null||h.ctrlKey||h.metaKey||h.shiftKey||SE()||!Br(e))return!1;h.preventDefault();const{text:g,mentions:m}=t.getEditorState().read(()=>wE()),v=g.trim();if(!v||e.kind==="dm"&&!l)return!0;const S={target:e.kind==="room"?{kind:"room",room_id:e.id}:{kind:"dm",dm_id:e.id,participant_ids:r.find(_=>_.id===e.id)?.participant_ids??[]},from:{type:"human",id:"operator",name:"Operator"},parts:[{kind:"text",text:v}],...m.length>0?{mentions:m}:{}};return c(null),f.mutate(S),!0},n0),[t,e,r,f,l]),u?k.jsx("div",{role:"status",className:"mt-2 text-[11px] text-coral",children:u}):null}function EE(){return k.jsxs("div",{className:"flex gap-2.5 items-start",children:[k.jsx("span",{className:"text-green font-bold pt-1 select-none",children:">"}),k.jsxs("div",{className:"flex-1 relative min-w-0",children:[k.jsx(tE,{contentEditable:k.jsx(tk,{"data-composer-input":"true",className:"min-h-[28px] outline-none text-ink whitespace-pre-wrap break-words py-1","aria-label":"Compose a message"}),placeholder:k.jsx("span",{className:"absolute top-1 left-0 text-faint pointer-events-none",children:"Send a room or DM message into this network."}),ErrorBoundary:lk}),k.jsx(ck,{}),k.jsx(G1,{}),k.jsx(vE,{}),k.jsx(kE,{})]})]})}function NE(){const{selected:t}=wt(),e=Br(t)?`target: ${t.kind} ${t.id}`:"no target selected.";return k.jsxs("div",{className:"flex justify-between items-center gap-4 text-[11px] text-faint",children:[k.jsx("span",{children:e}),k.jsxs("div",{className:"flex gap-3.5",children:[k.jsxs("span",{children:[k.jsx("kbd",{className:"text-green",children:"[enter]"})," send"]}),k.jsxs("span",{children:[k.jsx("kbd",{className:"text-green",children:"[ctrl+enter]"})," newline"]})]})]})}function TE(){const{data:t}=wn(),{selected:e}=wt();if(!Br(e))return null;const r=t?.id??"moltnet",s=`/${e.kind}/${e.id}`;return k.jsxs("div",{className:"text-xs text-ink pb-2.5",children:[k.jsxs("span",{className:"text-green",children:[r,"@moltnet"]})," ",k.jsxs("span",{className:"text-sub",children:["~ ",s]})]})}const OE={paragraph:"m-0 leading-relaxed",text:{base:""}},ME={namespace:"moltnet-composer",theme:OE,nodes:[mo],onError(t){console.error("[lexical]",t)}};function PE(){return qy()?k.jsxs(fe,{children:[k.jsx(fe.Header,{children:k.jsx(fe.Title,{children:"HUMAN INGRESS"})}),k.jsxs(fe.Body,{children:[k.jsx(TE,{}),k.jsx(S1,{initialConfig:ME,children:k.jsx(EE,{})})]}),k.jsx(fe.Footer,{children:k.jsx(NE,{})})]}):null}function Ye({label:t,value:e}){return k.jsxs("div",{className:"grid grid-cols-[110px_1fr] items-baseline gap-2",children:[k.jsxs("span",{className:"text-mute",children:[t," :"]}),k.jsx("span",{className:"text-sub break-all",children:e})]})}function Gr({active:t=!1,showMarker:e=!0,marker:r,markerClassName:s="",onClick:l,title:u,subtitle:c,trailing:f}){const h=["block w-full text-left bg-transparent border px-2.5 py-1 cursor-pointer rounded text-xs transition-colors",t?"bg-tint border-line-bright text-ink":"border-transparent text-sub hover:bg-tint/70 hover:text-ink"].join(" ");return k.jsx("button",{type:"button",className:h,onClick:l,children:k.jsxs("div",{className:"flex justify-between items-baseline gap-3",children:[k.jsxs("span",{className:"flex-1 min-w-0",children:[k.jsxs("span",{className:"block truncate",children:[e?k.jsx("span",{"aria-hidden":"true",className:`mr-1 inline-block ${s} ${t||r!==void 0?"":"invisible"}`,children:t?">":r}):null,u]}),c!==void 0?k.jsx("span",{className:"block truncate text-faint text-[11px] mt-0.5",children:c}):null]}),f!==void 0?k.jsx("span",{className:"text-faint text-[11px] shrink-0",children:f}):null]})})}function bE(){const{selected:t,select:e}=wt(),{data:r=[]}=kd(),{data:s=[]}=Ed(),{data:l=[],directMessagesEnabled:u}=Nd(),c=t?.kind==="agent"?t.id:null,f=A.useMemo(()=>c?r.find(m=>m.id===c):null,[r,c]),h=A.useMemo(()=>c?s.filter(m=>(m.members??[]).includes(c)||(f?.rooms??[]).includes(m.id)):[],[s,f,c]),g=A.useMemo(()=>c?l.filter(m=>(m.participant_ids??[]).includes(c)):[],[l,c]);return!f||!c?k.jsxs(fe,{children:[k.jsx(fe.Header,{children:k.jsx(fe.Title,{children:"AGENT"})}),k.jsx(fe.Body,{children:k.jsxs("p",{className:"text-faint text-xs px-2 py-1.5",children:["agent not found",c?` — ${c}`:"","."]})})]}):k.jsxs(fe,{children:[k.jsx(fe.Header,{children:k.jsx(fe.Title,{children:`AGENT: ${f.id}`})}),k.jsxs(fe.Body,{children:[k.jsxs("div",{className:"grid gap-2 text-xs mb-4",children:[k.jsx(Ye,{label:"agent",value:f.id}),k.jsx(Ye,{label:"canonical id",value:f.fqid??f.id}),k.jsx(Ye,{label:"network",value:f.network_id??"unknown"})]}),k.jsxs("div",{className:"text-[11px] tracking-[0.12em] text-green mt-1 mb-1.5",children:["[ ROOMS ] ( ",h.length," )"]}),h.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1 mb-4",children:"no rooms — this agent is not a member of any room."}):k.jsx("div",{className:"flex flex-col mb-4",children:h.map(m=>k.jsx(Gr,{showMarker:!1,onClick:()=>e({kind:"room",id:m.id}),title:k.jsxs(k.Fragment,{children:["# ",m.name||m.id]}),trailing:(m.members??[]).length>0?`${m.members.length} members`:void 0},m.id))}),u?k.jsxs(k.Fragment,{children:[k.jsxs("div",{className:"text-[11px] tracking-[0.12em] text-green mt-1 mb-1.5",children:["[ DIRECT CHANNELS ] ( ",g.length," )"]}),g.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1",children:"no direct channels — this agent has no DMs."}):k.jsx("div",{className:"flex flex-col",children:g.map(m=>k.jsx(Gr,{showMarker:!1,onClick:()=>e({kind:"dm",id:m.id}),title:m.id,trailing:`${m.message_count??0} msgs`},m.id))})]}):null]})]})}function Ni(t,e,r){let s=r.initialDeps??[],l,u=!0;function c(){var f,h,g;let m;r.key&&((f=r.debug)!=null&&f.call(r))&&(m=Date.now());const v=t();if(!(v.length!==s.length||v.some((_,w)=>s[w]!==_)))return l;s=v;let S;if(r.key&&((h=r.debug)!=null&&h.call(r))&&(S=Date.now()),l=e(...v),r.key&&((g=r.debug)!=null&&g.call(r))){const _=Math.round((Date.now()-m)*100)/100,w=Math.round((Date.now()-S)*100)/100,C=w/16,T=(N,M)=>{for(N=String(N);N.length=0;F--){const z=L[F];if(z.is(y)||K(z)&&z.isParentOf(y))break;z.isAttached()&&(!j.has(z)||z.is(M)?D||$.insertAfter(z,!1):z.remove())}if(!D){let F=N,z=null;for(;F!==null;){const J=F.getChildren(),te=J.length;(te===0||J[te-1].is(z))&&(C.delete(F.__key),z=F),F=F.getParent()}}if(zr(y))if(h===_)y.select();else{const F=ct(e);F.select(),y.replace(F)}else y=y.spliceText(h,_-h,e,!0),y.getTextContent()===""?y.remove():this.anchor.type==="text"&&(this.format=y.getFormat(),this.style=y.getStyle(),y.isComposing()&&(this.anchor.offset-=e.length));for(let F=1;F{s.forEach(j=>{if(K(j)){const D=j.getFormatFlags(e,L);j.setTextFormat(D)}})},c=l.length;if(c===0)return this.toggleFormat(e),ft(null),void u(r);const f=this.anchor,h=this.focus,g=this.isBackward(),m=g?h:f,v=g?f:h;let y=0,_=l[0],S=m.type==="element"?0:m.offset;if(m.type==="text"&&S===_.getTextContentSize()&&(y=1,_=l[1],S=0),_==null)return;const w=_.getFormatFlags(e,r);u(w);const C=c-1;let T=l[C];const N=v.type==="text"?v.offset:T.getTextContentSize();if(_.is(T)){if(S===N)return;if(jn(_)||S===0&&N===_.getTextContentSize())_.setFormat(w);else{const L=_.splitText(S,N),j=S===0?L[0]:L[1];j.setFormat(w),m.type==="text"&&m.set(j.__key,0,"text"),v.type==="text"&&v.set(j.__key,N-S,"text")}return void(this.format=w)}S===0||jn(_)||([,_]=_.splitText(S),S=0),_.setFormat(w);const M=T.getFormatFlags(e,w);N>0&&(N===T.getTextContentSize()||jn(T)||([T]=T.splitText(N)),T.setFormat(M));for(let L=y+1;L(K(S)||Ie(S))&&!S.isInline())){K(s)||q(211,r.constructor.name,r.getType());const S=Ic(this);return s.splice(S,0,e),void l.selectEnd()}const u=(function(S){const w=nn();let C=null;for(let T=0;T0){const m=c.getRangeAt(0),v=this.anchor.getNode(),y=lt(v)?v:e1(v);if(this.applyDOMRange(m),this.dirty=!0,!l){const _=this.getNodes(),S=[];let w=!1;for(let C=0;C<_.length;C++){const T=_[C];Mf(T,y)?S.push(T):w=!0}if(w&&S.length>0)if(r){const C=S[0];K(C)?C.selectStart():C.getParentOrThrow().selectStart()}else{const C=S[S.length-1];K(C)?C.selectEnd():C.getParentOrThrow().selectEnd()}c.anchorNode===m.startContainer&&c.anchorOffset===m.startOffset||(function(C){const T=C.focus,N=C.anchor,M=N.key,L=N.offset,j=N.type;N.set(T.key,T.offset,T.type,!0),T.set(M,L,j,!0)})(this)}}s==="lineboundary"&&Em(this,e,r,s,"decorators")}forwardDeletion(e,r,s){if(!s&&(e.type==="element"&&K(r)&&e.offset===r.getChildrenSize()||e.type==="text"&&e.offset===r.getTextContentSize())){const l=r.getParent(),u=r.getNextSibling()||(l===null?null:l.getNextSibling());if(K(u)&&u.isShadowRoot())return!0}return!1}deleteCharacter(e){const r=this.isCollapsed();if(this.isCollapsed()){const s=this.anchor;let l=s.getNode();if(this.forwardDeletion(s,l,e))return;const u=vd(pr(s,e?"previous":"next"));if(u.getTextSlices().every(f=>f===null||f.distance===0)){let f={type:"initial"};for(const h of u.iterNodeCarets("shadowRoot"))if(rn(h)){if(!h.origin.isInline()){if(h.origin.isShadowRoot()){if(f.type==="merge-block")break;if(K(u.anchor.origin)&&u.anchor.origin.isEmpty()){const g=yn(h);ql(this,Vr(g,g)),u.anchor.origin.remove()}return}f.type!=="merge-next-block"&&f.type!=="merge-block"||(f={block:f.block,caret:h,type:"merge-block"})}}else{if(f.type==="merge-block")break;if(Ki(h)){if(K(h.origin)){if(h.origin.isInline()){if(!h.origin.isParentOf(u.anchor.origin))break}else f={block:h.origin,type:"merge-next-block"};continue}if(Ie(h.origin)){if(!h.origin.isIsolated())if(f.type==="merge-next-block"&&(h.origin.isKeyboardSelectable()||!h.origin.isInline())&&K(u.anchor.origin)&&u.anchor.origin.isEmpty()){u.anchor.origin.remove();const g=Hv();g.add(h.origin.getKey()),It(g)}else h.origin.remove();return}break}}if(f.type==="merge-block"){const{caret:h,block:g}=f;return ql(this,Vr(!h.origin.isEmpty()&&g.isEmpty()?go(dt(g,h.direction)):u.anchor,h)),this.removeText()}}const c=this.focus;if(this.modify("extend",e,"character"),this.isCollapsed()){if(e&&s.offset===0&&vm(this,s.getNode()))return}else{const f=c.type==="text"?c.getNode():null;if(l=s.type==="text"?s.getNode():null,f!==null&&f.isSegmented()){const h=c.offset,g=f.getTextContentSize();if(f.is(l)||e&&h!==g||!e&&h!==0)return void xm(f,e,h)}else if(l!==null&&l.isSegmented()){const h=s.offset,g=l.getTextContentSize();if(l.is(f)||e&&h!==0||!e&&h!==g)return void xm(l,e,h)}(function(h,g){const m=h.anchor,v=h.focus,y=m.getNode(),_=v.getNode();if(y===_&&m.type==="text"&&v.type==="text"){const S=m.offset,w=v.offset,C=S{try{const t=new RegExp("\\p{Emoji}","u"),e=t.test.bind(t);if(e("❤️")&&e("#️⃣")&&e("👍"))return e}catch{}return()=>!1})();function xm(t,e,r){const s=t,l=s.getTextContent().split(/(?=\s)/g),u=l.length;let c=0,f=0;for(let g=0;gr||m){l.splice(g,1),m&&(f=void 0);break}}const h=l.join("").trim();h===""?s.remove():(s.setTextContent(h),s.select(f,f))}function _m(t,e,r,s){let l,u=e;if(Pt(t)){let c=!1;const f=t.childNodes,h=f.length,g=s._blockCursorElement;u===h&&(c=!0,u=h-1);let m=f[u],v=!1;if(m===g)m=f[u+1],v=!0;else if(g!==null){const y=g.parentNode;t===y&&e>Array.prototype.indexOf.call(y.children,g)&&u--}if(l=bi(m),re(l))u=xn(l,c?"next":"previous");else{let y=bi(t);if(y===null)return null;if(K(y)){const _=s.getElementByKey(y.getKey());_===null&&q(214),[y,u]=po(s).$getDOMSlot(y,_,s).resolveChildIndex(y,_,t,e),K(y)||q(215),c&&u>=y.getChildrenSize()&&(u=Math.max(0,y.getChildrenSize()-1));let w=y.getChildAtIndex(u);if(K(w)&&(function(C,T,N){const M=C.getParent();return N===null||M===null||!M.canBeEmpty()||M!==N.getNode()})(w,0,r)){const C=c?w.getLastDescendant():w.getFirstDescendant();C===null?y=w:(w=C,y=K(w)?w:w.getParentOrThrow()),u=0}re(w)?(l=w,y=null,u=xn(w,c?"next":"previous")):w!==y&&c&&!v&&(K(y)||q(216),u=Math.min(y.getChildrenSize(),u+1))}else{const _=y.getIndexWithinParent();u=e===0&&Ie(y)&&bi(t)===y?_:_+1,y=y.getParentOrThrow()}if(K(y))return _n(y.__key,u,"element")}}else l=bi(t);return re(l)?_n(l.__key,xn(l,u,"clamp"),"text"):null}function Sm(t,e,r){const s=t.offset,l=t.getNode();if(s===0){const u=l.getPreviousSibling(),c=l.getParent();if(e){if((r||!e)&&u===null&&K(c)&&c.isInline()){const f=c.getPreviousSibling();re(f)&&t.set(f.__key,f.getTextContent().length,"text")}}else K(u)&&!r&&u.isInline()?t.set(u.__key,u.getChildrenSize(),"element"):re(u)&&t.set(u.__key,u.getTextContent().length,"text")}else if(s===l.getTextContent().length){const u=l.getNextSibling(),c=l.getParent();if(e&&K(u)&&u.isInline())t.set(u.__key,0,"element");else if((r||e)&&u===null&&K(c)&&c.isInline()&&!c.canInsertTextAfter()){const f=c.getNextSibling();re(f)&&t.set(f.__key,0,"text")}}}function Uv(t,e,r){if(t.type==="text"&&e.type==="text"){const s=t.isBefore(e),l=t.is(e);Sm(t,s,l),Sm(e,!s,l),l&&e.set(t.key,t.offset,t.type)}}function Kv(t,e,r,s,l,u){if(t===null||r===null||!Su(l,t,r))return null;const c=_m(t,e,ee(u)?u.anchor:null,l);if(c===null)return null;const f=_m(r,s,ee(u)?u.focus:null,l);if(f===null)return null;if(c.type==="element"&&f.type==="element"){const h=bi(t),g=bi(r);if(Ie(h)&&Ie(g))return null}return Uv(c,f),[c,f]}function Wv(t,e,r,s,l,u){const c=yr(),f=new Jr(_n(t,e,l),_n(r,s,u),0,"");return f.dirty=!0,c._selection=f,f}function AC(){const t=_n("root",0,"element"),e=_n("root",0,"element");return new Jr(t,e,0,"")}function Hv(){return new vu(new Set)}function id(t,e,r,s){const l=r._window;if(l===null)return null;const u=s||l.event,c=u?u.type:void 0,f=c==="selectionchange",h=!af&&(f||c==="beforeinput"||c==="compositionstart"||c==="compositionend"||c==="click"&&u&&u.detail===3||c==="drop"||c===void 0);let g,m,v,y;if(ee(t)&&!h)return t.clone();if(e===null)return null;if(g=e.anchorNode,m=e.focusNode,v=e.anchorOffset,y=e.focusOffset,(f||c===void 0)&&ee(t)&&!Su(r,g,m))return t.clone();const _=Kv(g,v,m,y,r,t);if(_===null)return null;const[S,w]=_;let C=0,T="";if(ee(t)){const N=t.anchor;if(S.key===N.key)C=t.format,T=t.style;else{const M=S.getNode();re(M)?(C=M.getFormat(),T=M.getStyle()):K(M)&&(C=M.getTextFormat(),T=M.getTextStyle())}}return new Jr(S,w,C,T)}function de(){return yr()._selection}function lo(){return Le()._editorState._selection}function su(t,e,r,s=1){const l=t.anchor,u=t.focus,c=l.getNode(),f=u.getNode();if(!e.is(c)&&!e.is(f))return;const h=e.__key;if(t.isCollapsed()){const g=l.offset;if(r<=g&&s>0||r0||r0||r=f,g=h?u.getChildAtIndex(f-1):u.getChildAtIndex(r);if(re(g)){let m=0;h&&(m=g.getTextContentSize()),e.set(g.__key,m,"text"),s.set(g.__key,m,"text")}return}if(K(u)){const f=u.getChildrenSize(),h=r>=f,g=h?u.getChildAtIndex(f-1):u.getChildAtIndex(r);if(re(g)){let m=0;h&&(m=g.getTextContentSize()),e.set(g.__key,m,"text")}}if(K(c)){const f=c.getChildrenSize(),h=l>=f,g=h?c.getChildAtIndex(f-1):c.getChildAtIndex(l);if(re(g)){let m=0;h&&(m=g.getTextContentSize()),s.set(g.__key,m,"text")}}}function ou(t,e,r,s,l){let u=null,c=0,f=null;s!==null?(u=s.__key,re(s)?(c=s.getTextContentSize(),f="text"):K(s)&&(c=s.getChildrenSize(),f="element")):l!==null&&(u=l.__key,re(l)?f="text":K(l)&&(f="element")),u!==null&&f!==null?t.set(u,c,f):(c=e.getIndexWithinParent(),c===-1&&(c=r.getChildrenSize()),t.set(r.__key,c,"element"))}function Cm(t,e,r,s,l){t.type==="text"?t.set(r,t.offset+(e?0:l),"text"):t.offset>s.getIndexWithinParent()&&t.set(t.key,t.offset-1,"element")}function Qv(t,e,r,s,l){try{t.setBaseAndExtent(e,r,s,l)}catch{}}function km(t,e,r){const s=Bi(t,e.getKey());if(K(e)){const l=po(t).$getDOMSlot(e,s,t);return[l.element,r+l.getFirstChildOffset()]}return[s,r]}function zC(t,e,r,s,l,u,c){const f=s.anchorNode,h=s.focusNode,g=s.anchorOffset,m=s.focusOffset,v=document.activeElement;if(l.has(NC)&&v!==u||v!==null&&u0(v))return;if(!ee(e))return void(t!==null&&Su(r,f,h)&&s.removeAllRanges());const y=e.anchor,_=e.focus,S=y.getNode(),w=_.getNode(),[C,T]=km(r,S,y.offset),[N,M]=km(r,w,_.offset),L=e.format,j=e.style,D=e.isCollapsed();let $=C,F=N,z=!1;var J,te,ne,X,ae;if(y.type==="text"?($=$i(C),z=S.getFormat()!==L||S.getStyle()!==j):ee(t)&&t.anchor.type==="text"&&(z=!0),_.type==="text"&&(F=$i(N)),$!==null&&F!==null&&(D&&(t===null||z||ee(t)&&(t.format!==L||t.style!==j))&&(J=L,te=j,ne=T,X=y.key,ae=performance.now(),Pv=[J,te,ne,X,ae]),g!==T||m!==M||f!==$||h!==F||s.type==="Range"&&D||(v!==null&&u.contains(v)||l.has(Nf)||u.focus({preventScroll:!0}),y.type==="element"))){if(Qv(s,$,T,F,M),!fr||!e.isCollapsed()||u===null||l.has(Nf)||document.activeElement!==null&&u.contains(document.activeElement)||u.focus({preventScroll:!0}),!l.has(TC)&&e.isCollapsed()&&u!==null&&u===document.activeElement){const Se=ee(e)&&e.anchor.type==="element"?$.childNodes[T]||null:s.rangeCount>0?s.getRangeAt(0):null;if(Se!==null){let ye;if(Se instanceof Text){const _e=document.createRange();_e.selectNode(Se),ye=_e.getBoundingClientRect()}else ye=Se.getBoundingClientRect();(function(_e,Z,W){const Q=v0(W),P=hd(Q);if(Q===null||P===null)return;let{top:U,bottom:he}=Z,ve=0,we=0,Ce=W;for(;Ce!==null;){const Me=Ce===Q.body;if(Me){ve=0,we=Lt(_e).innerHeight;const Te=P.getComputedStyle(Q.documentElement),qe=parseFloat(Te.scrollPaddingTop),xr=parseFloat(Te.scrollPaddingBottom);isFinite(qe)&&(ve+=qe),isFinite(xr)&&(we-=xr)}else{const Te=Ce.getBoundingClientRect();ve=Te.top,we=Te.bottom}let Ee=0;if(Uwe&&(Ee=he-we),Ee!==0)if(Me)P.scrollBy(0,Ee);else{const Te=Ce.scrollTop;Ce.scrollTop+=Ee;const qe=Ce.scrollTop-Te;U-=qe,he-=qe}if(Me)break;Ce=fo(Ce)}})(r,ye,u)}}wf=!0}}function Ic(t){let e=t;t.isCollapsed()||e.removeText();const r=de();ee(r)&&(e=r),ee(e)||q(161);const s=e.anchor;let l=s.getNode(),u=s.offset;for(;!or(l);){const c=l;if([l,u]=$C(l,u),c.is(l))break}return u}function $C(t,e){const r=t.getParent();if(!r){const l=nn();return tt().append(l),l.select(),[tt(),0]}if(re(t)){const l=t.splitText(e);if(l.length===0)return[r,t.getIndexWithinParent()];const u=e===0?0:1;return[r,l[0].getIndexWithinParent()+u]}if(!K(t)||e===0)return[r,t.getIndexWithinParent()];const s=t.getChildAtIndex(e);if(s){const l=new Jr(_n(t.__key,e,"element"),_n(t.__key,e,"element"),0,""),u=t.insertNewAfter(l);u&&u.append(s,...s.getNextSiblings())}return[r,t.getIndexWithinParent()+1]}function Em(t,e,r,s,l="decorators-and-blocks"){if(e==="move"&&s==="character"&&!t.isCollapsed()){const[m,v]=r===t.isBackward()?[t.focus,t.anchor]:[t.anchor,t.focus];return v.set(m.key,m.offset,m.type),!0}const u=pr(t.focus,r?"previous":"next"),c=s==="lineboundary",f=e==="move";let h=u,g=l==="decorators-and-blocks";if(!k0(h)){for(const m of h){g=!1;const{origin:v}=m;if(!Ie(v)||v.isIsolated()||(h=m,!c||!v.isInline()))break}if(g)for(const m of vd(u).iterNodeCarets(e==="extend"?"shadowRoot":"root")){if(rn(m))m.origin.isInline()||(h=m);else{if(K(m.origin))continue;Ie(m.origin)&&!m.origin.isInline()&&(h=m)}break}}if(h===u)return!1;if(f&&!c&&Ie(h.origin)&&h.origin.isKeyboardSelectable()){const m=Hv();return m.add(h.origin.getKey()),It(m),!0}return h=yn(h),f&&io(t.anchor,h),io(t.focus,h),g||!c}let st=null,ot=null,Mt=!1,Lc=!1,Hl=0;const Nm={characterData:!0,childList:!0,subtree:!0};function uo(){return Mt||st!==null&&st._readOnly}function yt(){Mt&&q(13)}function Vv(){Hl>99&&q(14)}function yr(){return st===null&&q(195,qv()),st}function Le(){return ot===null&&q(337,qv()),ot}function qv(){let t=0;const e=new Set,r=zi.version;if(typeof window<"u")for(const l of document.querySelectorAll("[contenteditable]")){const u=wu(l);if(ud(u))t++;else if(u){let c=String(u.constructor.version||"<0.17.1");c===r&&(c+=" (separately built, likely a bundler configuration issue)"),e.add(c)}}let s=` Detected on the page: ${t} compatible editor(s) with version ${r}`;return e.size&&(s+=` and incompatible editors with versions ${Array.from(e).join(", ")}`),s}function BC(){return ot}function Tm(t,e,r){const s=e.__type,l=o0(t,s);let u=r.get(s);u===void 0&&(u=Array.from(l.transforms),r.set(s,u));const c=u.length;for(let f=0;f0&&Pm(t,t._deferred));const u=t._editorState,c=u._selection,f=r._selection,h=t._dirtyType!==0,g=st,m=Mt,v=ot,y=t._updating,_=t._observer;let S=null;if(t._pendingEditorState=null,t._editorState=r,!l&&h&&_!==null){ot=t,st=r,Mt=!1,t._updating=!0;try{const D=t._dirtyType,$=t._dirtyElements,F=t._dirtyLeaves;_.disconnect(),S=lC(u,r,t,D,$,F)}catch(D){if(D instanceof Error&&t._onError(D),Lc)throw D;return i0(t,null,s,r),iv(t),t._dirtyType=2,Lc=!0,Fn(t,u),void(Lc=!1)}finally{_.observe(s,Nm),t._updating=y,st=g,Mt=m,ot=v}}r._readOnly||(r._readOnly=!0);const w=t._dirtyLeaves,C=t._dirtyElements,T=t._normalizedNodes,N=t._updateTags,M=t._deferred;h&&(t._dirtyType=0,t._cloneNotNeeded.clear(),t._dirtyLeaves=new Set,t._dirtyElements=new Map,t._normalizedNodes=new Set,t._updateTags=new Set),(function(D,$){const F=D._decorators;let z=D._pendingDecorators||F;const J=$._nodeMap;let te;for(te in z)J.has(te)||(z===F&&(z=d0(D)),delete z[te])})(t,r);const L=l?null:un(Lt(t));if(t._editable&&L!==null&&(h||f===null||f.dirty||!f.is(c))&&s!==null&&!N.has(OC)){ot=t,st=r;try{if(_!==null&&_.disconnect(),h||f===null||f.dirty){const D=t._blockCursorElement;D!==null&&Pf(D,t,s),zC(c,f,t,L,N,s)}(function(D,$,F){let z=D._blockCursorElement;if(ee(F)&&F.isCollapsed()&&F.anchor.type==="element"&&$.contains(document.activeElement)){const J=F.anchor,te=J.getNode(),ne=J.offset;let X=!1,ae=null;if(ne===te.getChildrenSize())zc(te.getChildAtIndex(ne-1))&&(X=!0);else{const Se=te.getChildAtIndex(ne);if(Se!==null&&zc(Se)){const ye=Se.getPreviousSibling();(ye===null||zc(ye))&&(X=!0,ae=D.getElementByKey(Se.__key))}}if(X){const Se=D.getElementByKey(te.__key);return z===null&&(D._blockCursorElement=z=(function(ye){const _e=ye.theme,Z=document.createElement("div");Z.contentEditable="false",Z.setAttribute("data-lexical-cursor","true");let W=_e.blockCursor;if(W!==void 0){if(typeof W=="string"){const Q=N0(W);W=_e.blockCursor=Q}W!==void 0&&Z.classList.add(...W)}return Z})(D._config)),$.style.caretColor="transparent",void(ae===null?Se.appendChild(z):Se.insertBefore(z,ae))}}z!==null&&Pf(z,D,$)})(t,s,f)}finally{_!==null&&_.observe(s,Nm),ot=v,st=g}}S!==null&&(function(D,$,F,z,J){const te=Array.from(D._listeners.mutation),ne=te.length;for(let X=0;X=0;c--)for(let f=0;f0&&h._updating){u=h;break}const g=h._commands.get(e);if(g!==void 0){const m=g[c];if(m.size>0){let v=!1;if(vn(h,()=>{for(const y of m)if(y(r,s))return void(v=!0)}),v)return v}}}return u&&u.update(()=>{Yv(u,e,r,s)}),!1}function Pm(t,e){if(t._deferred=[],e.length!==0){const r=t._updating;t._updating=!0;try{for(let s=0;s0||ne>0;){if(J>0){M._dirtyLeaves=new Set;for(const X of z){const ae=D.get(X);re(ae)&&ae.isAttached()&&ae.isSimpleText()&&!ae.isUnmergeable()&&nm(ae),ae!==void 0&&Om(ae,$)&&Tm(M,ae,F),L.add(X)}if(z=M._dirtyLeaves,J=z.size,J>0){Hl++;continue}}M._dirtyLeaves=new Set,M._dirtyElements=new Map,te.delete("root")&&te.set("root",!0);for(const X of te){const ae=X[0],Se=X[1];if(j.set(ae,Se),!Se)continue;const ye=D.get(ae);ye!==void 0&&Om(ye,$)&&Tm(M,ye,F)}z=M._dirtyLeaves,J=z.size,te=M._dirtyElements,ne=te.size,Hl++}M._dirtyLeaves=L,M._dirtyElements=j})(h,t),bm(t),(function(N,M,L,j){const D=N._nodeMap,$=M._nodeMap,F=[];for(const[z]of j){const J=$.get(z);J!==void 0&&(J.isAttached()||(K(J)&&tv(J,z,D,$,F,j),D.has(z)||j.delete(z),F.push(z)))}for(const z of F)$.delete(z);for(const z of L){const J=$.get(z);J===void 0||J.isAttached()||(D.has(z)||L.delete(z),$.delete(z))}})(f,h,t._dirtyLeaves,t._dirtyElements)),C!==t._compositionKey&&(h._flushSync=!0);const T=h._selection;if(ee(T)){const N=h._nodeMap,M=T.anchor.key,L=T.focus.key;N.get(M)!==void 0&&N.get(L)!==void 0||q(19)}else xu(T)&&T._nodes.size===0&&(h._selection=null)}catch(C){return C instanceof Error&&t._onError(C),t._pendingEditorState=f,t._dirtyType=2,t._cloneNotNeeded.clear(),t._dirtyLeaves=new Set,t._dirtyElements.clear(),void Fn(t)}finally{st=m,Mt=v,ot=y,t._updating=_,Hl=0}t._dirtyType!==0||t._deferred.length>0||(function(C,T){const N=T.getEditorState()._selection,M=C._selection;if(M!==null){if(M.dirty||!M.is(N))return!0}else if(N!==null)return!0;return!1})(h,t)?h._flushSync?(h._flushSync=!1,Fn(t)):g&&qC(()=>{Fn(t)}):(h._flushSync=!1,g&&(s.clear(),t._deferred=[],t._pendingEditorState=null))}function vn(t,e,r){ot===t&&r===void 0?e():_u(t,e,r)}class Ws{element;before;after;constructor(e,r,s){this.element=e,this.before=r||null,this.after=s||null}withBefore(e){return new Ws(this.element,e,this.after)}withAfter(e){return new Ws(this.element,this.before,e)}withElement(e){return this.element===e?this:new Ws(e,this.before,this.after)}insertChild(e){const r=this.before||this.getManagedLineBreak();return r!==null&&r.parentElement!==this.element&&q(222),this.element.insertBefore(e,r),this}removeChild(e){return e.parentElement!==this.element&&q(223),this.element.removeChild(e),this}replaceChild(e,r){return r.parentElement!==this.element&&q(224),this.element.replaceChild(e,r),this}getFirstChild(){const e=this.after?this.after.nextSibling:this.element.firstChild;return e===this.before||e===this.getManagedLineBreak()?null:e}getManagedLineBreak(){return this.element.__lexicalLineBreak||null}setManagedLineBreak(e){if(e===null)this.removeManagedLineBreak();else{const r=e==="decorator"&&(gu||oo||pu);this.insertManagedLineBreak(r)}}removeManagedLineBreak(){const e=this.getManagedLineBreak();if(e){const r=this.element,s=e.nodeName==="IMG"?e.nextSibling:null;s&&r.removeChild(s),r.removeChild(e),r.__lexicalLineBreak=void 0}}insertManagedLineBreak(e){const r=this.getManagedLineBreak();if(r){if(e===(r.nodeName==="IMG"))return;this.removeManagedLineBreak()}const s=this.element,l=this.before,u=document.createElement("br");if(s.insertBefore(u,l),e){const c=document.createElement("img");c.setAttribute("data-lexical-linebreak","true"),c.style.setProperty("display","inline","important"),c.style.setProperty("border","0px","important"),c.style.setProperty("margin","0px","important"),c.alt="",s.insertBefore(c,u),s.__lexicalLineBreak=c}else s.__lexicalLineBreak=u}getFirstChildOffset(){let e=0;for(let r=this.after;r!==null;r=r.previousSibling)e++;return e}resolveChildIndex(e,r,s,l){if(s===this.element){const h=this.getFirstChildOffset();return[e,Math.min(h+e.getChildrenSize(),Math.max(h,l))]}const u=Rm(r,s);u.push(l);const c=Rm(r,this.element);let f=e.getIndexWithinParent();for(let h=0;hm){f+=1;break}}return[e.getParentOrThrow(),f]}}function Rm(t,e){const r=[];let s=e;for(;s!==t&&s!==null;s=s.parentNode){let l=0;for(let u=s.previousSibling;u!==null;u=u.previousSibling)l++;r.push(l)}return s!==t&&q(225),r.reverse()}class ao extends tn{__first;__last;__size;__format;__style;__indent;__dir;__textFormat;__textStyle;constructor(e){super(e),this.__first=null,this.__last=null,this.__size=0,this.__format=0,this.__style="",this.__indent=0,this.__dir=null,this.__textFormat=0,this.__textStyle=""}afterCloneFrom(e){super.afterCloneFrom(e),this.__key===e.__key&&(this.__first=e.__first,this.__last=e.__last,this.__size=e.__size),this.__indent=e.__indent,this.__format=e.__format,this.__style=e.__style,this.__dir=e.__dir,this.__textFormat=e.__textFormat,this.__textStyle=e.__textStyle}getFormat(){return this.getLatest().__format}getFormatType(){const e=this.getFormat();return Vw[e]||""}getStyle(){return this.getLatest().__style}getIndent(){return this.getLatest().__indent}getChildren(){const e=[];let r=this.getFirstChild();for(;r!==null;)e.push(r),r=r.getNextSibling();return e}getChildrenKeys(){const e=[];let r=this.getFirstChild();for(;r!==null;)e.push(r.__key),r=r.getNextSibling();return e}getChildrenSize(){return this.getLatest().__size}isEmpty(){return this.getChildrenSize()===0}isDirty(){const e=Le()._dirtyElements;return e!==null&&e.has(this.__key)}isLastChild(){const e=this.getLatest(),r=this.getParentOrThrow().getLastChild();return r!==null&&r.is(e)}getAllTextNodes(){const e=[];let r=this.getFirstChild();for(;r!==null;){if(re(r)&&e.push(r),K(r)){const s=r.getAllTextNodes();e.push(...s)}r=r.getNextSibling()}return e}getFirstDescendant(){let e=this.getFirstChild();for(;K(e);){const r=e.getFirstChild();if(r===null)break;e=r}return e}getLastDescendant(){let e=this.getLastChild();for(;K(e);){const r=e.getLastChild();if(r===null)break;e=r}return e}getDescendantByIndex(e){const r=this.getChildren(),s=r.length;if(e>=s){const u=r[s-1];return K(u)&&u.getLastDescendant()||u||null}const l=r[e];return K(l)&&l.getFirstDescendant()||l||null}getFirstChild(){const e=this.getLatest().__first;return e===null?null:et(e)}getFirstChildOrThrow(){const e=this.getFirstChild();return e===null&&q(45,this.__key),e}getLastChild(){const e=this.getLatest().__last;return e===null?null:et(e)}getLastChildOrThrow(){const e=this.getLastChild();return e===null&&q(96,this.__key),e}getChildAtIndex(e){const r=this.getChildrenSize();let s,l;if(e=e;){if(l===e)return s;s=s.getPreviousSibling(),l--}return null}getTextContent(){let e="";const r=this.getChildren(),s=r.length;for(let l=0;lr.remove()),e}append(...e){return this.splice(this.getChildrenSize(),0,e)}setDirection(e){const r=this.getWritable();return r.__dir=e,r}setFormat(e){return this.getWritable().__format=e!==""&&uf[e]||0,this}setStyle(e){return this.getWritable().__style=e||"",this}setTextFormat(e){const r=this.getWritable();return r.__textFormat=e,r}setTextStyle(e){const r=this.getWritable();return r.__textStyle=e,r}setIndent(e){return this.getWritable().__indent=e,this}splice(e,r,s){iu(this)&&q(324,this.__key,this.__type);const l=this.getChildrenSize(),u=this.getWritable();e+r<=l||q(226,String(e),String(r),String(l));const c=u.__key,f=[],h=[],g=this.getChildAtIndex(e+r);let m=null,v=l-r+s.length;if(e!==0)if(e===l)m=this.getLastChild();else{const _=this.getChildAtIndex(e);_!==null&&(m=_.getPreviousSibling())}if(r>0){let _=m===null?this.getFirstChild():m.getNextSibling();for(let S=0;S0&&(r.style.paddingInlineStart=40*s+"px");const l=this.getDirection();l&&(r.dir=l)}return{element:r}}exportJSON(){const e={children:[],direction:this.getDirection(),format:this.getFormatType(),indent:this.getIndent(),...super.exportJSON()},r=this.getTextFormat(),s=this.getTextStyle();return r===0&&s===""||An(this)||this.getChildren().some(re)||(r!==0&&(e.textFormat=r),s!==""&&(e.textStyle=s)),e}updateFromJSON(e){return super.updateFromJSON(e).setFormat(e.format).setIndent(e.indent).setDirection(e.direction).setTextFormat(e.textFormat||0).setTextStyle(e.textStyle||"")}insertNewAfter(e,r){return null}canIndent(){return!0}collapseAtStart(e){return!1}excludeFromCopy(e){return!1}canReplaceWith(e){return!0}canInsertAfter(e){return!0}canBeEmpty(){return!0}canInsertTextBefore(){return!0}canInsertTextAfter(){return!0}isInline(){return!1}isShadowRoot(){return!1}canMergeWith(e){return!1}extractWithChild(e,r,s){return!1}canMergeWhenEmpty(){return!1}reconcileObservedMutation(e,r){const s=po(r).$getDOMSlot(this,e,r);let l=s.getFirstChild();for(let u=this.getFirstChild();u;u=u.getNextSibling()){const c=r.getElementByKey(u.getKey());c!==null&&(l==null?(s.insertChild(c),l=c):l!==c&&s.replaceChild(c,l),l=l.nextSibling)}}}function K(t){return t instanceof ao}function Dm(t,e,r){let s=t.getNode();for(;s;){const l=s.__key;if(e.has(l)&&!r.has(l))return!0;s=s.getParent()}return!1}class Xv extends tn{decorate(e,r){return null}isIsolated(){return!1}isInline(){return!0}isKeyboardSelectable(){return!0}}function Ie(t){return t instanceof Xv}class Yr extends ao{__cachedText;static getType(){return"root"}static clone(){return new Yr}constructor(){super("root"),this.__cachedText=null}getTopLevelElementOrThrow(){q(51)}getTextContent(){const e=this.__cachedText;return!uo()&&Le()._dirtyType!==0||e===null?super.getTextContent():e}remove(){q(52)}replace(e){q(53)}insertBefore(e){q(54)}insertAfter(e){q(55)}updateDOM(e,r){return!1}splice(e,r,s){for(const l of s)K(l)||Ie(l)||q(282);return super.splice(e,r,s)}static importJSON(e){return tt().updateFromJSON(e)}collapseAtStart(){return!0}}function lt(t){return t instanceof Yr}function Zv(t){return new co(new Map(t._nodeMap))}function sd(){return new co(new Map([["root",new Yr]]))}function e0(t){const e=t.exportJSON(),r=t.constructor;if(e.type!==r.getType()&&q(130,r.name),K(t)){const s=e.children;Array.isArray(s)||q(59,r.name);const l=t.getChildren();for(let u=0;u({root:e0(tt())}))}}class KC extends ao{static getType(){return"artificial"}createDOM(e){return document.createElement("div")}}class Vi extends ao{static getType(){return"paragraph"}static clone(e){return new Vi(e.__key)}createDOM(e){const r=document.createElement("p"),s=Ii(e.theme,"paragraph");return s!==void 0&&r.classList.add(...s),r}updateDOM(e,r,s){return!1}static importDOM(){return{p:e=>({conversion:WC,priority:0})}}exportDOM(e){const{element:r}=super.exportDOM(e);if(Pt(r)){this.isEmpty()&&r.append(document.createElement("br"));const s=this.getFormatType();s&&(r.style.textAlign=s)}return{element:r}}static importJSON(e){return nn().updateFromJSON(e)}exportJSON(){const e=super.exportJSON();if(e.textFormat===void 0||e.textStyle===void 0){const r=this.getChildren().find(re);r?(e.textFormat=r.getFormat(),e.textStyle=r.getStyle()):(e.textFormat=this.getTextFormat(),e.textStyle=this.getTextStyle())}return e}insertNewAfter(e,r){const s=nn();s.setTextFormat(e.format),s.setTextStyle(e.style);const l=this.getDirection();return s.setDirection(l),s.setFormat(this.getFormatType()),s.setStyle(this.getStyle()),this.insertAfter(s,r),s}collapseAtStart(){const e=this.getChildren();if(e.length===0||re(e[0])&&e[0].getTextContent().trim()===""){if(this.getNextSibling()!==null)return this.selectNext(),this.remove(),!0;if(this.getPreviousSibling()!==null)return this.selectPrevious(),this.remove(),!0}return!1}}function WC(t){const e=nn();if(t.style&&(e.setFormat(t.style.textAlign),l1(t,e)),e.getFormatType()===""){const r=t.getAttribute("align");r&&r&&r in uf&&e.setFormat(r)}return{node:e}}function nn(){return Nu(new Vi)}function t0(t){return t instanceof Vi}const De=0,n0=1,r0=3;function i0(t,e,r,s){const l=t._keyToDOMMap;l.clear(),t._editorState=sd(),t._pendingEditorState=s,t._compositionKey=null,t._dirtyType=0,t._cloneNotNeeded.clear(),t._dirtyLeaves=new Set,t._dirtyElements.clear(),t._normalizedNodes=new Set,t._updateTags=new Set,t._updates=[],t._blockCursorElement=null;const u=t._observer;u!==null&&(u.disconnect(),t._observer=null),e!==null&&(e.textContent=""),r!==null&&(r.textContent="",l.set("root",r))}function HC(t){const e=new Set,r=new Set;let s=t;for(;s;){const{ownNodeConfig:l}=qi(s),u=s.transform;if(!r.has(u)){r.add(u);const c=s.transform();c&&e.add(c)}if(l){const c=l.$transform;c&&e.add(c),s=l.extends}else{const c=Object.getPrototypeOf(s);s=c.prototype instanceof tn&&c!==tn?c:void 0}}return e}const no={$createDOM:(t,e)=>t.createDOM(e._config,e),$decorateDOM:(t,e,r,s)=>{},$exportDOM:(t,e)=>{const r=ld(e,t.getType());return r&&r.exportDOM!==void 0?r.exportDOM(e,t):t.exportDOM(e)},$extractWithChild:(t,e,r,s,l)=>K(t)&&t.extractWithChild(e,r,s),$getDOMSlot:(t,e,r)=>(K(t)||q(336,t.getKey(),t.getType()),t.getDOMSlot(e)),$shouldExclude:(t,e,r)=>K(t)&&t.excludeFromCopy("html"),$shouldInclude:(t,e,r)=>!e||t.isSelected(e),$updateDOM:(t,e,r,s)=>t.updateDOM(e,r,s._config)};function s0(t){const e=t||{},r=BC(),s=e.theme||{},l=t===void 0?r:e.parentEditor||null,u=e.disableEvents||!1,c=sd(),f=e.namespace||(l!==null?l._config.namespace:g0()),h=e.editorState,g=[Yr,mr,Hi,Qi,Vi,KC,...e.nodes||[]],{onError:m,html:v}=e,y=e.editable===void 0||e.editable;let _;if(t===void 0&&r!==null)_=r._nodes;else{_=new Map;for(let w=0;w{Object.keys(L).forEach(j=>{let D=T.get(j);D===void 0&&(D=[],T.set(j,D)),D.push(L[j])})};return w.forEach(L=>{const j=L.klass.importDOM;if(j==null||N.has(j))return;N.add(j);const D=j.call(L.klass);D!==null&&M(D)}),C&&M(C),T})(_,v?v.import:void 0),y,t);return h!==void 0&&(S._pendingEditorState=h,S._dirtyType=2),(function(w){w.registerCommand(hv,vC,De),w.registerCommand(pv,xC,De),w.registerCommand(gv,_C,De),w.registerCommand(mv,SC,De),w.registerCommand(yv,wC,De)})(S),S}function QC(t,e){const r=t.get(e);t.delete(e),r&&r()}function Ls(t,e,r){return t.set(e,r),QC.bind(null,t,e)}class zi{static version;_headless;_parentEditor;_rootElement;_editorState;_pendingEditorState;_compositionKey;_deferred;_keyToDOMMap;_updates;_updating;_listeners;_commands;_nodes;_decorators;_pendingDecorators;_config;_dirtyType;_cloneNotNeeded;_dirtyLeaves;_dirtyElements;_normalizedNodes;_updateTags;_observer;_key;_onError;_htmlConversions;_window;_editable;_blockCursorElement;_createEditorArgs;constructor(e,r,s,l,u,c,f,h){this._createEditorArgs=h,this._parentEditor=r,this._rootElement=null,this._editorState=e,this._pendingEditorState=null,this._compositionKey=null,this._deferred=[],this._keyToDOMMap=new Map,this._updates=[],this._updating=!1,this._listeners={decorator:new Map,editable:new Map,mutation:new Map,root:new Map,textcontent:new Map,update:new Map},this._commands=new Map,this._config=l,this._nodes=s,this._decorators={},this._pendingDecorators=null,this._dirtyType=0,this._cloneNotNeeded=new Set,this._dirtyLeaves=new Set,this._dirtyElements=new Map,this._normalizedNodes=new Set,this._updateTags=new Set,this._observer=null,this._key=g0(),this._onError=u,this._htmlConversions=c,this._editable=f,this._headless=r!==null&&r._headless,this._window=null,this._blockCursorElement=null}isComposing(){return this._compositionKey!=null}registerUpdateListener(e){return Ls(this._listeners.update,e)}registerEditableListener(e){return Ls(this._listeners.editable,e)}registerDecoratorListener(e){return Ls(this._listeners.decorator,e)}registerTextContentListener(e){return Ls(this._listeners.textcontent,e)}registerRootListener(e){const r=this._listeners.root;return Sn(Ls(r,e,e(this._rootElement,null)||void 0),()=>(function(s,l,u){const c=s.get(l);c&&c(),s.set(l,l(...u)||void 0)})(r,e,[null,this._rootElement]))}registerCommand(e,r,s){s===void 0&&q(35);const l=this._commands;l.has(e)||l.set(e,[new Is,new Is,new Is,new Is,new Is]);const u=l.get(e);u===void 0&&q(36,String(e));const c=(function(h){return 7&h})(s),f=u[c];return c!==s?f.addFront(r):f.addBack(r),()=>{f.delete(r),u.every(h=>h.size===0)&&l.delete(e)}}registerMutationListener(e,r,s){const l=this.resolveRegisteredNodeAfterReplacements(this.getRegisteredNode(e)).klass,u=this._listeners.mutation;let c=u.get(r);c===void 0&&(c=new Set,u.set(r,c)),c.add(l);const f=s&&s.skipInitialization;return f!==void 0&&f||this.initializeMutationListener(r,l),()=>{c.delete(l),c.size===0&&u.delete(r)}}getRegisteredNode(e){const r=this._nodes.get(e.getType());return r===void 0&&q(37,e.name),r}resolveRegisteredNodeAfterReplacements(e){for(;e.replaceWithKlass;)e=this.getRegisteredNode(e.replaceWithKlass);return e}initializeMutationListener(e,r){const s=this._editorState,l=Um(s).get(r.getType());if(!l)return;const u=new Map;for(const c of l.keys())u.set(c,"created");u.size>0&&e(u,{dirtyLeaves:new Set,prevEditorState:s,updateTags:new Set(["registerMutationListener"])})}registerNodeTransformToKlass(e,r){const s=this.getRegisteredNode(e);return s.transforms.add(r),s}registerNodeTransform(e,r){const s=this.registerNodeTransformToKlass(e,r),l=[s],u=s.replaceWithKlass;if(u!=null){const c=this.registerNodeTransformToKlass(u,r);l.push(c)}return(function(c,f){const h=Um(c.getEditorState()),g=[];for(const m of f){const v=h.get(m);v&&g.push(v)}g.length!==0&&c.update(()=>{for(const m of g)for(const v of m.keys()){const y=et(v);y&&y.markDirty()}},c._pendingEditorState===null?{tag:Fi}:void 0)})(this,l.map(c=>c.klass.getType())),()=>{l.forEach(c=>c.transforms.delete(r))}}hasNode(e){return this._nodes.has(e.getType())}hasNodes(e){return e.every(this.hasNode.bind(this))}dispatchCommand(e,r){return ie(this,e,r)}getDecorators(){return this._decorators}getRootElement(){return this._rootElement}getKey(){return this._key}setRootElement(e){const r=this._rootElement;if(e!==r){const s=Ii(this._config.theme,"root"),l=this._pendingEditorState||this._editorState;if(this._rootElement=e,i0(this,r,e,l),r!==null&&(this._config.disableEvents||CC(r),s!=null&&r.classList.remove(...s)),e!==null){const u=hd(e),c=e.style;c.userSelect="text",c.whiteSpace="pre-wrap",c.wordBreak="break-word",e.setAttribute("data-lexical-editor","true"),this._window=u,this._dirtyType=2,iv(this),this._updateTags.add(Fi),Fn(this),this._config.disableEvents||(function(f,h){const g=f.ownerDocument;Sf.set(f,g);const m=nu.get(g)??0;m<1&&g.addEventListener("selectionchange",Fv),nu.set(g,m+1),f.__lexicalEditor=h;const v=jv(f);for(let y=0;y<_f.length;y++){const[_,S]=_f[y],w=typeof S=="function"?C=>{am(C)||(um(C),(h.isEditable()||_==="click")&&S(C,h))}:C=>{if(am(C))return;um(C);const T=h.isEditable();switch(_){case"cut":return T&&ie(h,ed,C);case"copy":return ie(h,Zf,C);case"paste":return T&&ie(h,Jf,C);case"dragstart":return T&&ie(h,Tv,C);case"dragover":return T&&ie(h,dC,C);case"dragend":return T&&ie(h,hC,C);case"focus":return T&&ie(h,gC,C);case"blur":return T&&ie(h,mC,C);case"drop":return T&&ie(h,Nv,C)}};f.addEventListener(_,w),v.push(()=>{f.removeEventListener(_,w)})}})(e,this),s!=null&&e.classList.add(...s)}else this._window=null,this._updateTags.add(Fi),Fn(this);Ks("root",this,!1,e,r)}}getElementByKey(e){return this._keyToDOMMap.get(e)||null}getEditorState(){return this._editorState}setEditorState(e,r){e.isEmpty()&&q(38);let s=e;s._readOnly&&(s=Zv(e),s._selection=e._selection?e._selection.clone():null),rv(this);const l=this._pendingEditorState,u=this._updateTags,c=r!==void 0?r.tag:null;l===null||l.isEmpty()||(c!=null&&u.add(c),Fn(this)),this._pendingEditorState=s,this._dirtyType=2,this._dirtyElements.set("root",!1),this._compositionKey=null,c!=null&&u.add(c),this._updating||Fn(this)}parseEditorState(e,r){return(function(s,l,u){const c=sd(),f=st,h=Mt,g=ot,m=l._dirtyElements,v=l._dirtyLeaves,y=l._cloneNotNeeded,_=l._dirtyType;l._dirtyElements=new Map,l._dirtyLeaves=new Set,l._cloneNotNeeded=new Set,l._dirtyType=0,st=c,Mt=!1,ot=l,od(null);try{const S=l._nodes;Jv(s.root,S),u&&u(),c._readOnly=!0}catch(S){S instanceof Error&&l._onError(S)}finally{l._dirtyElements=m,l._dirtyLeaves=v,l._cloneNotNeeded=y,l._dirtyType=_,st=f,Mt=h,ot=g}return c})(typeof e=="string"?JSON.parse(e):e,this,r)}read(e){return Fn(this),this.getEditorState().read(e,{editor:this})}update(e,r){(function(s,l,u){s._updating?s._updates.push([l,u]):_u(s,l,u)})(this,e,r)}focus(e,r={}){const s=this._rootElement;s!==null&&(s.setAttribute("autocapitalize","off"),vn(this,()=>{const l=de(),u=tt();l!==null?l.dirty||It(l.clone()):u.getChildrenSize()!==0&&(r.defaultSelection==="rootStart"?u.selectStart():u.selectEnd()),Eu("focus"),ZC(()=>{s.removeAttribute("autocapitalize"),e&&e()})}),this._pendingEditorState===null&&s.removeAttribute("autocapitalize"))}blur(){const e=this._rootElement;e!==null&&e.blur();const r=un(this._window);r!==null&&r.removeAllRanges()}isEditable(){return this._editable}setEditable(e){this._editable!==e&&(this._editable=e,Ks("editable",this,!0,e))}toJSON(){return{editorState:this._editorState.toJSON()}}}zi.version="0.44.0+prod.esm";let Of=null;function od(t){Of=t}let VC=1;function o0(t,e){const r=ld(t,e);return r===void 0&&q(30,e),r}function ld(t,e){return t._nodes.get(e)}const qC=typeof queueMicrotask=="function"?queueMicrotask:t=>{Promise.resolve().then(t)};function l0(t){return Ie(ku(t))}function u0(t){const e=document.activeElement;if(!Pt(e))return!1;const r=e.nodeName;return Ie(ku(t))&&(r==="INPUT"||r==="TEXTAREA"||e.contentEditable==="true"&&wu(e)==null)}function Su(t,e,r){const s=t.getRootElement();try{return s!==null&&s.contains(e)&&s.contains(r)&&e!==null&&!u0(e)&&a0(e)===t}catch{return!1}}function ud(t){return t instanceof zi}function a0(t){let e=t;for(;e!=null;){const r=wu(e);if(ud(r))return r;e=fo(e)}return null}function wu(t){return t?t.__lexicalEditor:null}function zr(t){return Bv(t)||t.isToken()}function jn(t){return zr(t)||t.isSegmented()}function zn(t){return ho(t)&&t.nodeType===3}function GC(t){return ho(t)&&t.nodeType===9}function $i(t){let e=t;for(;e!=null;){if(zn(e))return e;e=e.firstChild}return null}function lu(t,e,r){const s=Kr[e];if(r!==null&&(t&s)===(r&s))return t;let l=t^s;return e==="subscript"?l&=-65:e==="superscript"?l&=-33:e==="lowercase"?(l&=-513,l&=-1025):e==="uppercase"?(l&=-257,l&=-1025):e==="capitalize"&&(l&=-257,l&=-513),l}function c0(t,e){const r=(function(){const c=Of;return Of=null,c})();if((e=e||r&&r.__key)!=null)return void(t.__key=e);yt(),Vv();const s=Le(),l=yr(),u=""+VC++;l._nodeMap.set(u,t),K(t)?s._dirtyElements.set(u,!0):s._dirtyLeaves.add(u),s._cloneNotNeeded.add(u),s._dirtyType=1,t.__key=u}function $r(t){const e=t.getParent();if(e!==null){const r=t.getWritable(),s=e.getWritable(),l=t.getPreviousSibling(),u=t.getNextSibling(),c=u!==null?u.__key:null,f=l!==null?l.__key:null,h=l!==null?l.getWritable():null,g=u!==null?u.getWritable():null;l===null&&(s.__first=c),u===null&&(s.__last=f),h!==null&&(h.__next=c),g!==null&&(g.__prev=f),r.__prev=null,r.__next=null,r.__parent=null,s.__size--}}function uu(t){Vv(),iu(t)&&q(323,t.__key,t.__type);const e=t.getLatest(),r=e.__parent,s=yr(),l=Le(),u=s._nodeMap,c=l._dirtyElements;r!==null&&(function(h,g,m){let v=h;for(;v!==null;){if(m.has(v))return;const y=g.get(v);if(y===void 0)break;m.set(v,!1),v=y.__parent}})(r,u,c);const f=e.__key;l._dirtyType=1,K(t)?c.set(f,!0):l._dirtyLeaves.add(f)}function ft(t){yt();const e=Le(),r=e._compositionKey;if(t!==r){if(e._compositionKey=t,r!==null){const s=et(r);s!==null&&s.getWritable()}if(t!==null){const s=et(t);s!==null&&s.getWritable()}}}function lr(){return uo()?null:Le()._compositionKey}function et(t,e){const r=(e||yr())._nodeMap.get(t);return r===void 0?null:r}function f0(t,e){const r=Cu(t,Le());return r!==void 0?et(r,e):null}function Cu(t,e){return t[`__lexicalKey_${e._key}`]}function ku(t,e){let r=t;for(;r!=null;){const s=f0(r,e);if(s!==null)return s;r=fo(r)}return null}function d0(t){const e=t._decorators,r=Object.assign({},e);return t._pendingDecorators=r,r}function jm(t){return t.read(()=>tt().getTextContent())}function tt(){return h0(yr())}function h0(t){return t._nodeMap.get("root")}function It(t){yt();const e=yr();t!==null&&(t.dirty=!0,t.setCachedNodes(null)),e._selection=t}function bi(t){const e=Le(),r=(function(s,l){let u=s;for(;u!=null;){const c=Cu(u,l);if(c!==void 0)return c;u=fo(u)}return null})(t,e);return r===null?t===e.getRootElement()?et("root"):null:et(r)}function p0(t){return/[\uD800-\uDBFF][\uDC00-\uDFFF]/g.test(t)}function ad(t){const e=[];for(let r=t;r!==null;r=r._parentEditor)e.push(r);return e}function g0(){return Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,5)}function m0(t){return zn(t)?t.nodeValue:null}function cd(t,e,r){const s=un(Lt(e));if(s===null)return;const l=s.anchorNode;let{anchorOffset:u,focusOffset:c}=s;if(l!==null){let f=m0(l);const h=ku(l);if(f!==null&&re(h)){if((f===qs||f===qf)&&r){const g=r.length;f=r,u=g,c=g}f!==null&&fd(h,f,u,c,t)}}}function fd(t,e,r,s,l){let u=t;if(u.isAttached()&&(l||!u.isDirty())){const c=u.isComposing();let f=e;if((c||l)&&(e.endsWith(qs)&&(f=e.slice(0,-qs.length)),l)){const g=qf;let m;for(;(m=f.indexOf(g))!==-1;)f=f.slice(0,m)+f.slice(m+g.length),r!==null&&r>m&&(r=Math.max(m,r-g.length)),s!==null&&s>m&&(s=Math.max(m,s-g.length))}const h=u.getTextContent();if(l||f!==h){if(f===""){if(ft(null),pu||oo||gu)u.remove();else{const w=Le();setTimeout(()=>{w.update(()=>{u.isAttached()&&u.remove()})},20)}return}const g=u.getParent(),m=lo(),v=u.getTextContentSize(),y=lr(),_=u.getKey();if(u.isToken()||y!==null&&_===y&&!c||ee(m)&&(g!==null&&!g.canInsertTextBefore()&&m.anchor.offset===0||m.anchor.key===t.__key&&m.anchor.offset===0&&!u.canInsertTextBefore()&&!c||m.focus.key===t.__key&&m.focus.offset===v&&!u.canInsertTextAfter()&&!c))return void u.markDirty();const S=de();if(!ee(S)||r===null||s===null)return void Fm(u,f,S);if(S.setTextNodeRange(u,r,u,s),u.isSegmented()){const w=ct(u.getTextContent());u.replace(w),u=w}Fm(u,f,S)}}}function Fm(t,e,r){if(t.setTextContent(e),ee(r)){const s=t.getKey();for(const l of["anchor","focus"]){const u=r[l];u.type==="text"&&u.key===s&&(u.offset=xn(t,u.offset,"clamp"))}}}function Rl(t,e,r){const s=e[r]||!1;return s==="any"||s===t[r]}function JC(t,e){return Rl(t,e,"altKey")&&Rl(t,e,"ctrlKey")&&Rl(t,e,"shiftKey")&&Rl(t,e,"metaKey")}function Re(t,e,r){if(!JC(t,r))return!1;if(t.key.toLowerCase()===e.toLowerCase())return!0;if(e.length>1||t.key.length===1&&t.key.charCodeAt(0)<=127)return!1;if(t.code.startsWith("Digit")&&/^\d$/.test(e))return t.code===`Digit${e}`;const s="Key"+e.toUpperCase();return t.code===s}const Dn={ctrlKey:!Xt,metaKey:Xt},Im={altKey:Xt,ctrlKey:!Xt};function Lm(t){return t.key==="Backspace"}function Am(t){return Re(t,"a",Dn)}function YC(t){const e=tt();if(ee(t)){const r=t.anchor,s=t.focus,l=r.getNode().getTopLevelElementOrThrow().getParentOrThrow();return r.set(l.getKey(),0,"element"),s.set(l.getKey(),l.getChildrenSize(),"element"),cf(t),t}{const r=e.select(0,e.getChildrenSize());return It(cf(r)),r}}function Ii(t,e){t.__lexicalClassNameCache===void 0&&(t.__lexicalClassNameCache={});const r=t.__lexicalClassNameCache,s=r[e];if(s!==void 0)return s;const l=t[e];if(typeof l=="string"){const u=N0(l);return r[e]=u,u}return l}function dd(t,e,r,s,l){if(r.size===0)return;const u=s.__type,c=s.__key,f=e.get(u);f===void 0&&q(33,u);const h=f.klass;let g=t.get(h);g===void 0&&(g=new Map,t.set(h,g));const m=g.get(c),v=m==="destroyed"&&l==="created";(m===void 0||v)&&g.set(c,v?"updated":l)}function zm(t,e,r){const s=t.getParent();let l=r,u=t;return s!==null&&(r===0&&(l=u.getIndexWithinParent(),u=s)),u.getChildAtIndex(l-1)}function XC(t,e){const r=t.offset;if(t.type==="element")return zm(t.getNode(),e,r);{const s=t.getNode();if(r===0||!e){const l=s.getPreviousSibling();return l===null?zm(s.getParentOrThrow(),e,s.getIndexWithinParent()+0):l}}return null}function y0(t){const e=Lt(t).event,r=e&&e.inputType;return r==="insertFromPaste"||r==="insertFromPasteAsQuotation"}function ie(t,e,r){return Yv(t,e,r,t)}function Bi(t,e){const r=t._keyToDOMMap.get(e);return r===void 0&&q(75,e),r}function fo(t){const e=t.assignedSlot||t.parentElement;return bf(e)?e.host:e}function v0(t){return GC(t)?t:Pt(t)?t.ownerDocument:null}function Eu(t){yt(),Le()._updateTags.add(t)}function ZC(t){yt(),Le()._deferred.push(t)}function Mf(t,e){let r=t.getParent();for(;r!==null;){if(r.is(e))return!0;r=r.getParent()}return!1}function hd(t){const e=v0(t);return e?e.defaultView:null}function Lt(t){const e=t._window;return e===null&&q(78),e}function e1(t){let e=t.getParentOrThrow();for(;e!==null;){if(An(e))return e;e=e.getParentOrThrow()}return e}function An(t){return lt(t)||K(t)&&t.isShadowRoot()}function t1(t,e=!1){const r=t.constructor.clone(t);return c0(r,null),r.afterCloneFrom(t),e||r.resetOnCopyNodeFrom(t),r}function Nu(t){const e=Le(),r=t.getType(),s=ld(e,r);s===void 0&&q(200,t.constructor.name,r);const{replace:l,replaceWithKlass:u}=s;if(l!==null){const c=l(t),f=c.constructor;return u!==null?c instanceof u||q(201,u.name,u.getType(),f.name,f.getType(),t.constructor.name,r):c instanceof t.constructor&&f!==t.constructor||q(202,f.name,f.getType(),t.constructor.name,r),c.__key===t.__key&&q(203,t.constructor.name,r,f.name,f.getType()),c}return t}function Ac(t,e){!lt(t.getParent())||K(e)||Ie(e)||q(99)}function n1(t){const e=et(t);return e===null&&q(63,t),e}function zc(t){return(Ie(t)||K(t)&&!t.canBeEmpty())&&!t.isInline()}function Pf(t,e,r){r.style.removeProperty("caret-color"),e._blockCursorElement=null;const s=t.parentElement;s!==null&&s.removeChild(t)}function un(t){return ln?(t||window).getSelection():null}function r1(t){const e=hd(t);return e?e.getSelection():null}function Pt(t){return ho(t)&&t.nodeType===1}function ho(t){return typeof t=="object"&&t!==null&&"nodeType"in t&&typeof t.nodeType=="number"}function bf(t){return ho(t)&&t.nodeType===11}function i1(t){const e=new RegExp(/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|mark|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var|#text)$/,"i");return t.nodeName.match(e)!==null}function $m(t){const e=new RegExp(/^(address|article|aside|blockquote|canvas|dd|div|dl|dt|fieldset|figcaption|figure|footer|form|h1|h2|h3|h4|h5|h6|header|hr|li|main|nav|noscript|ol|p|pre|section|table|td|tfoot|ul|video)$/,"i");return t.nodeName.match(e)!==null}function or(t){if(Ie(t)&&!t.isInline())return!0;if(!K(t)||An(t))return!1;const e=t.getFirstChild(),r=e===null||Us(e)||re(e)||e.isInline();return!t.isInline()&&t.canBeEmpty()!==!1&&r}function Ui(){return Le()}function po(t=Ui()){return t._config.dom||no}const Bm=new WeakMap,s1=new Map;function Um(t){if(!t._readOnly&&t.isEmpty())return s1;t._readOnly||q(192);let e=Bm.get(t);return e||(e=(function(r){const s=new Map;for(const[l,u]of r._nodeMap){const c=u.__type;let f=s.get(c);f||(f=new Map,s.set(c,f)),f.set(l,u)}return s})(t),Bm.set(t,e)),e}function x0(t){const e=t.constructor.clone(t);return e.afterCloneFrom(t),e}function o1(t){return(e=x0(t))[Iv]=!0,e;var e}function l1(t,e){const r=parseInt(t.style.paddingInlineStart,10)||0,s=Math.round(r/40);e.setIndent(s)}function u1(t){return t.__lexicalUnmanaged===!0}function As(t,e){return(function(r,s){return Object.prototype.hasOwnProperty.call(r,s)})(t,e)&&t[e]!==tn[e]}function qi(t){const e=Gg in t.prototype?t.prototype[Gg]():void 0,r=(function(c){if(!(c===tn||c.prototype instanceof tn)){let f="",h="";try{f=c.getType()}catch{}try{zi.version&&(h=JSON.parse(zi.version))}catch{}q(290,c.name,f,h)}return c===Xv||c===ao||c===tn})(t),s=!r&&As(t,"getType")?t.getType():void 0;let l,u=s;if(e)if(s)l=e[s];else for(const[c,f]of Object.entries(e))u=c,l=f;if(!r&&u&&(As(t,"getType")||(t.getType=()=>u),As(t,"clone")||(t.clone=c=>(od(c),new t)),As(t,"importJSON")||(t.importJSON=l&&l.$importJSON||(c=>new t().updateFromJSON(c))),!As(t,"importDOM")&&l)){const{importDOM:c}=l;c&&(t.importDOM=()=>c)}return{ownNodeConfig:l,ownNodeType:u}}const Ql=(t,e)=>{let r=t;for(;r!=null&&!lt(r);){if(e(r))return r;r=r.getParent()}return null};function au(t,e){const r=[];let s=t.__first;for(;s!==null;){const l=e===null?et(s):e.get(s);l==null&&q(174),r.push(s),s=l.__next}return r}const a1={next:"previous",previous:"next"};class pd{origin;constructor(e){this.origin=e}[Symbol.iterator](){return S0({hasNext:Ki,initial:this.getAdjacentCaret(),map:e=>e,step:e=>e.getAdjacentCaret()})}getAdjacentCaret(){return dt(this.getNodeAtCaret(),this.direction)}getSiblingCaret(){return dt(this.origin,this.direction)}remove(){const e=this.getNodeAtCaret();return e&&e.remove(),this}replaceOrInsert(e,r){const s=this.getNodeAtCaret();return e.is(this.origin)||e.is(s)||(s===null?this.insert(e):s.replace(e,r)),this}splice(e,r,s="next"){const l=s===this.direction?r:Array.from(r).reverse();let u=this;const c=this.getParentAtCaret(),f=new Map;for(let h=u.getAdjacentCaret();h!==null&&f.size0){const g=u.getNodeAtCaret();if(g){if(f.delete(g.getKey()),f.delete(h.getKey()),!(g.is(h)||u.origin.is(h))){const m=h.getParent();m&&m.is(c)&&h.remove(),g.replace(h)}}else g===null&&q(263,Array.from(f).join(" "))}else u.insert(h);u=dt(h,this.direction)}for(const h of f.values())h.remove();return this}}class ro extends pd{type="child";getLatest(){const e=this.origin.getLatest();return e===this.origin?this:hr(e,this.direction)}getParentCaret(e="root"){return dt(gd(this.getParentAtCaret(),e),this.direction)}getFlipped(){const e=Xr(this.direction);return dt(this.getNodeAtCaret(),e)||hr(this.origin,e)}getParentAtCaret(){return this.origin}getChildCaret(){return this}isSameNodeCaret(e){return e instanceof ro&&this.direction===e.direction&&this.origin.is(e.origin)}isSamePointCaret(e){return this.isSameNodeCaret(e)}}const c1={root:lt,shadowRoot:An};function Xr(t){return a1[t]}function gd(t,e="root"){return c1[e](t)?null:t}class Hr extends pd{type="sibling";getLatest(){const e=this.origin.getLatest();return e===this.origin?this:dt(e,this.direction)}getSiblingCaret(){return this}getParentAtCaret(){return this.origin.getParent()}getChildCaret(){return K(this.origin)?hr(this.origin,this.direction):null}getParentCaret(e="root"){return dt(gd(this.getParentAtCaret(),e),this.direction)}getFlipped(){const e=Xr(this.direction);return dt(this.getNodeAtCaret(),e)||hr(this.origin.getParentOrThrow(),e)}isSamePointCaret(e){return e instanceof Hr&&this.direction===e.direction&&this.origin.is(e.origin)}isSameNodeCaret(e){return(e instanceof Hr||e instanceof Qr)&&this.direction===e.direction&&this.origin.is(e.origin)}}class Qr extends pd{type="text";offset;constructor(e,r){super(e),this.offset=r}getLatest(){const e=this.origin.getLatest();return e===this.origin?this:dr(e,this.direction,this.offset)}getParentAtCaret(){return this.origin.getParent()}getChildCaret(){return null}getParentCaret(e="root"){return dt(gd(this.getParentAtCaret(),e),this.direction)}getFlipped(){return dr(this.origin,Xr(this.direction),this.offset)}isSamePointCaret(e){return e instanceof Qr&&this.direction===e.direction&&this.origin.is(e.origin)&&this.offset===e.offset}isSameNodeCaret(e){return(e instanceof Hr||e instanceof Qr)&&this.direction===e.direction&&this.origin.is(e.origin)}getSiblingCaret(){return dt(this.origin,this.direction)}}function ar(t){return t instanceof Qr}function Ki(t){return t instanceof Hr}function rn(t){return t instanceof ro}const f1={next:class extends Qr{direction="next";getNodeAtCaret(){return this.origin.getNextSibling()}insert(t){return this.origin.insertAfter(t),this}},previous:class extends Qr{direction="previous";getNodeAtCaret(){return this.origin.getPreviousSibling()}insert(t){return this.origin.insertBefore(t),this}}},d1={next:class extends Hr{direction="next";getNodeAtCaret(){return this.origin.getNextSibling()}insert(t){return this.origin.insertAfter(t),this}},previous:class extends Hr{direction="previous";getNodeAtCaret(){return this.origin.getPreviousSibling()}insert(t){return this.origin.insertBefore(t),this}}},h1={next:class extends ro{direction="next";getNodeAtCaret(){return this.origin.getFirstChild()}insert(t){return this.origin.splice(0,0,[t]),this}},previous:class extends ro{direction="previous";getNodeAtCaret(){return this.origin.getLastChild()}insert(t){return this.origin.splice(this.origin.getChildrenSize(),0,[t]),this}}};function dt(t,e){return t?new d1[e](t):null}function dr(t,e,r){return t?new f1[e](t,xn(t,r)):null}function xn(t,e,r="error"){const s=t.getTextContentSize();let l=e==="next"?s:e==="previous"?0:e;return(l<0||l>s)&&(r!=="clamp"&&Yy(284,String(e),String(s),t.getKey()),l=l<0?0:s),l}function Km(t,e){return new g1(t,e)}function hr(t,e){return K(t)?new h1[e](t):null}function p1(t){return t&&t.getChildCaret()||t}function md(t){return t&&p1(t.getAdjacentCaret())}class yd{type="node-caret-range";direction;anchor;focus;constructor(e,r,s){this.anchor=e,this.focus=r,this.direction=s}getLatest(){const e=this.anchor.getLatest(),r=this.focus.getLatest();return e===this.anchor&&r===this.focus?this:new yd(e,r,this.direction)}isCollapsed(){return this.anchor.isSamePointCaret(this.focus)}getTextSlices(){const e=l=>{const u=this[l].getLatest();return ar(u)?(function(c,f){const{direction:h,origin:g}=c,m=xn(g,f==="focus"?Xr(h):h);return Km(c,m-c.offset)})(u,l):null},r=e("anchor"),s=e("focus");if(r&&s){const{caret:l}=r,{caret:u}=s;if(l.isSameNodeCaret(u))return[Km(l,u.offset-l.offset),null]}return[r,s]}iterNodeCarets(e="root"){const r=ar(this.anchor)?this.anchor.getSiblingCaret():this.anchor.getLatest(),s=this.focus.getLatest(),l=ar(s),u=c=>c.isSameNodeCaret(s)?null:md(c)||c.getParentCaret(e);return S0({hasNext:c=>c!==null&&!(l&&s.isSameNodeCaret(c)),initial:r.isSameNodeCaret(s)?null:u(r),map:c=>c,step:u})}[Symbol.iterator](){return this.iterNodeCarets("root")}}class g1{type="slice";caret;distance;constructor(e,r){this.caret=e,this.distance=r}getSliceIndices(){const{distance:e,caret:{offset:r}}=this,s=r+e;return s{let ne;for(let X=D;XC.has(J.getKey())&&or(J));return F&&z?[F,z]:null})(m,v,h);if(y){const[S,w]=y;hr(S,"previous").splice(0,w.getChildren());let C=w.getParent();for(w.remove(!0);C&&C.isEmpty();){const T=C;C=C.getParent(),T.remove(!0)}}const _=[m,v,...c,...f].find($c);if(_)return _0(qr(yn(_),t.direction));q(269,JSON.stringify(c.map(S=>S.origin.__key)))}function yn(t){const e=(function(l){let u=l;for(;rn(u);){const c=md(u);if(!rn(c))break;u=c}return u})(t.getLatest()),{direction:r}=e;if(re(e.origin))return ar(e)?e:dr(e.origin,r,r);const s=e.getAdjacentCaret();return Ki(s)&&re(s.origin)?dr(s.origin,r,Xr(r)):e}function k0(t){return ar(t)&&t.offset!==xn(t.origin,t.direction)}function qr(t,e){return t.direction===e?t:t.getFlipped()}function xd(t,e){return t.direction===e?t:Vr(qr(t.focus,e),qr(t.anchor,e))}function Df(t,e,r){let s=hr(t,"next");for(let l=0;l0||!u&&f.canBeEmpty()&&l(f,"last"))&&c.insert(e(f).splice(0,0,h))}return c}function _1(...t){return t}function E0(t,e){if(!e||t===e)return t;for(const r in e)if(t[r]!==e[r])return{...t,...e};return t}function N0(...t){const e=[];for(const r of t)if(r&&typeof r=="string")for(const[s]of r.matchAll(/\S+/g))e.push(s);return e}function Sn(...t){return()=>{for(let e=t.length-1;e>=0;e--)t[e]();t.length=0}}const T0=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0,S1=T0?A.useLayoutEffect:A.useEffect,jl={tag:Fi};function w1({initialConfig:t,children:e}){const r=A.useMemo(()=>{const{theme:s,namespace:l,nodes:u,onError:c,editorState:f,html:h}=t,g=Fw(null,s),m=s0({editable:t.editable,html:h,namespace:l,nodes:u,onError:v=>c(v,m),theme:s});return(function(v,y){if(y!==null){if(y===void 0)v.update(()=>{const _=tt();if(_.isEmpty()){const S=nn();_.append(S);const w=T0?document.activeElement:null;(de()!==null||w!==null&&w===v.getRootElement())&&S.select()}},jl);else if(y!==null)switch(typeof y){case"string":{const _=v.parseEditorState(y);v.setEditorState(_,jl);break}case"object":v.setEditorState(y,jl);break;case"function":v.update(()=>{tt().isEmpty()&&y(v)},jl)}}})(m,f),[m,g]},[]);return S1(()=>{const s=t.editable,[l]=r;l.setEditable(s===void 0||s)},[]),k.jsx(Jy.Provider,{value:r,children:e})}function C1({children:t,className:e=""}){return k.jsx("section",{className:`relative flex flex-col min-h-0 border border-line rounded bg-bg ${e}`.trim(),children:t})}function k1({children:t}){return k.jsx("div",{className:"absolute -top-2 left-0 right-0 flex justify-between pointer-events-none px-4 z-10",children:t})}function E1({children:t}){return k.jsxs("span",{className:"bg-bg px-2 text-[11px] tracking-[0.12em] text-green",children:["[ ",t," ]"]})}function N1({children:t}){return k.jsxs("span",{className:"bg-bg px-2 text-[11px] text-green",children:["( ",t," )"]})}function T1({children:t,className:e=""}){return k.jsx("div",{className:`flex-1 flex flex-col overflow-auto pt-4 px-3.5 pb-3 min-h-0 ${e}`.trim(),children:t})}function O1({children:t,className:e=""}){return k.jsx("div",{className:`border-t border-dashed border-white/[0.06] pt-2.5 px-3.5 pb-2 text-[11px] text-faint ${e}`.trim(),children:t})}const fe=Object.assign(C1,{Header:k1,Title:E1,Count:N1,Body:T1,Footer:O1});function O0(t){const e=Ui().getElementByKey(t.getKey());if(e===null)return null;const r=e.ownerDocument.defaultView;return r===null?null:r.getComputedStyle(e)}function M1(t){return O0(lt(t)?t:t.getParentOrThrow())}function P1(t,e,r="self"){const s=t.getStartEndPoints();if(e.isSelected(t)&&!jn(e)&&s!==null){const[l,u]=s,c=t.isBackward(),f=l.getNode(),h=u.getNode(),g=e.is(f),m=e.is(h);if(g||m){const[v,y]=Tf(t),_=f.is(h),S=e.is(c?h:f),w=e.is(c?f:h);let C,T=0;_?(T=v>y?y:v,C=v>y?v:y):S?(T=c?y:v,C=void 0):w&&(T=0,C=c?v:y);const N=e.__text.slice(T,C);N!==e.__text&&(r==="clone"&&(e=o1(e)),e.__text=N)}}return e}function M0(t){const e=P0(t);return e!==null&&e.writingMode==="vertical-rl"}function P0(t){const e=t.anchor.getNode();return K(e)?O0(e):M1(e)}function Qm(t,e){let r=M0(t)?!e:e;b0(t)&&(r=!r);const s=pr(t.focus,r?"previous":"next");if(k0(s))return!1;for(const l of vd(s)){if(rn(l))return!l.origin.isInline();if(!K(l.origin)){if(Ie(l.origin))return!0;break}}return!1}function b1(t,e,r,s){t.modify(e?"extend":"move",r,s)}function b0(t){const e=P0(t);return e!==null&&e.direction==="rtl"}function Vm(t,e,r){const s=b0(t);let l;l=M0(t)||s?!r:r,b1(t,e,l,"character")}const R0=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0,R1=R0&&"documentMode"in document?document.documentMode:null;!(!R0||!("InputEvent"in window)||R1)&&"getTargetRanges"in new window.InputEvent("input");function D0(t,e){return t!==null&&Object.getPrototypeOf(t).constructor.name===e.name}const D1=Symbol.for("preact-signals");function Tu(){if(Ln>1)return void Ln--;let t,e=!1;for(!(function(){let r=fu;for(fu=void 0;r!==void 0;)r.S.v===r.v&&(r.S.i=r.i),r=r.o})();Hs!==void 0;){let r=Hs;for(Hs=void 0,du++;r!==void 0;){const s=r.u;if(r.u=void 0,r.f&=-3,!(8&r.f)&&j0(r))try{r.c()}catch(l){e||(t=l,e=!0)}r=s}}if(du=0,Ln--,e)throw t}function j1(t){if(Ln>0)return t();jf=++F1,Ln++;try{return t()}finally{Tu()}}let Pe,Hs;function qm(t){const e=Pe;Pe=void 0;try{return t()}finally{Pe=e}}let fu,Ln=0,du=0,F1=0,jf=0,Gl=0;function Gm(t){if(Pe===void 0)return;let e=t.n;return e===void 0||e.t!==Pe?(e={i:0,S:t,p:Pe.s,n:void 0,t:Pe,e:void 0,x:void 0,r:e},Pe.s!==void 0&&(Pe.s.n=e),Pe.s=e,t.n=e,32&Pe.f&&t.S(e),e):e.i===-1?(e.i=0,e.n!==void 0&&(e.n.p=e.p,e.p!==void 0&&(e.p.n=e.n),e.p=Pe.s,e.n=void 0,Pe.s.n=e,Pe.s=e),e):void 0}function _t(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=e?.watched,this.Z=e?.unwatched,this.name=e?.name}function I1(t,e){return new _t(t,e)}function j0(t){for(let e=t.s;e!==void 0;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function Jm(t){for(let e=t.s;e!==void 0;e=e.n){const r=e.S.n;if(r!==void 0&&(e.r=r),e.S.n=e,e.i=-1,e.n===void 0){t.s=e;break}}}function F0(t){let e,r=t.s;for(;r!==void 0;){const s=r.p;r.i===-1?(r.S.U(r),s!==void 0&&(s.n=r.n),r.n!==void 0&&(r.n.p=s)):e=r,r.S.n=r.r,r.r!==void 0&&(r.r=void 0),r=s}t.s=e}function ki(t,e){_t.call(this,void 0),this.x=t,this.s=void 0,this.g=Gl-1,this.f=4,this.W=e?.watched,this.Z=e?.unwatched,this.name=e?.name}function I0(t){const e=t.m;if(t.m=void 0,typeof e=="function"){Ln++;const r=Pe;Pe=void 0;try{e()}catch(s){throw t.f&=-2,t.f|=8,_d(t),s}finally{Pe=r,Tu()}}}function _d(t){for(let e=t.s;e!==void 0;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,I0(t)}function L1(t){if(Pe!==this)throw new Error("Out-of-order effect");F0(this),Pe=t,this.f&=-2,8&this.f&&_d(this),Tu()}function Pi(t,e){this.x=t,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=e?.name}function Sd(t,e){const r=new Pi(t,e);try{r.c()}catch(l){throw r.d(),l}const s=r.d.bind(r);return s[Symbol.dispose]=s,s}function L0(t,e={}){const r={};for(const s in t){const l=e[s],u=I1(l===void 0?t[s]:l);r[s]=u}return r}_t.prototype.brand=D1,_t.prototype.h=function(){return!0},_t.prototype.S=function(t){const e=this.t;e!==t&&t.e===void 0&&(t.x=e,this.t=t,e!==void 0?e.e=t:qm(()=>{var r;(r=this.W)==null||r.call(this)}))},_t.prototype.U=function(t){if(this.t!==void 0){const e=t.e,r=t.x;e!==void 0&&(e.x=r,t.e=void 0),r!==void 0&&(r.e=e,t.x=void 0),t===this.t&&(this.t=r,r===void 0&&qm(()=>{var s;(s=this.Z)==null||s.call(this)}))}},_t.prototype.subscribe=function(t){return Sd(()=>{const e=this.value,r=Pe;Pe=void 0;try{t(e)}finally{Pe=r}},{name:"sub"})},_t.prototype.valueOf=function(){return this.value},_t.prototype.toString=function(){return this.value+""},_t.prototype.toJSON=function(){return this.value},_t.prototype.peek=function(){const t=Pe;Pe=void 0;try{return this.value}finally{Pe=t}},Object.defineProperty(_t.prototype,"value",{get(){const t=Gm(this);return t!==void 0&&(t.i=this.i),this.v},set(t){if(t!==this.v){if(du>100)throw new Error("Cycle detected");(function(e){Ln!==0&&du===0&&e.l!==jf&&(e.l=jf,fu={S:e,v:e.v,i:e.i,o:fu})})(this),this.v=t,this.i++,Gl++,Ln++;try{for(let e=this.t;e!==void 0;e=e.x)e.t.N()}finally{Tu()}}}}),ki.prototype=new _t,ki.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Gl))return!0;if(this.g=Gl,this.f|=1,this.i>0&&!j0(this))return this.f&=-2,!0;const t=Pe;try{Jm(this),Pe=this;const e=this.x();(16&this.f||this.v!==e||this.i===0)&&(this.v=e,this.f&=-17,this.i++)}catch(e){this.v=e,this.f|=16,this.i++}return Pe=t,F0(this),this.f&=-2,!0},ki.prototype.S=function(t){if(this.t===void 0){this.f|=36;for(let e=this.s;e!==void 0;e=e.n)e.S.S(e)}_t.prototype.S.call(this,t)},ki.prototype.U=function(t){if(this.t!==void 0&&(_t.prototype.U.call(this,t),this.t===void 0)){this.f&=-33;for(let e=this.s;e!==void 0;e=e.n)e.S.U(e)}},ki.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(let t=this.t;t!==void 0;t=t.x)t.t.N()}},Object.defineProperty(ki.prototype,"value",{get(){if(1&this.f)throw new Error("Cycle detected");const t=Gm(this);if(this.h(),t!==void 0&&(t.i=this.i),16&this.f)throw this.v;return this.v}}),Pi.prototype.c=function(){const t=this.S();try{if(8&this.f||this.x===void 0)return;const e=this.x();typeof e=="function"&&(this.m=e)}finally{t()}},Pi.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,I0(this),Jm(this),Ln++;const t=Pe;return Pe=this,L1.bind(this,t)},Pi.prototype.N=function(){2&this.f||(this.f|=2,this.u=Hs,Hs=this)},Pi.prototype.d=function(){this.f|=8,1&this.f||_d(this)},Pi.prototype.dispose=function(){this.d()};function A1(){const t=tt(),e=de(),r=nn();t.clear(),t.append(r),e!==null&&r.select(),ee(e)&&(e.format=0)}function z1(t,e=A1){return t.registerCommand(td,r=>(t.update(e),!0),De)}function $1(t){const e=new Set,r=new Set;for(const s of A0(t)){const l=typeof s=="function"?s:s.replace;qi(l),e.add(l.getType()),r.add(l)}return{nodes:r,types:e}}function A0(t){return(typeof t.nodes=="function"?t.nodes():t.nodes)||[]}sv("format",{parse:t=>typeof t=="number"?t:0});function je(t,...e){const r=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",t);for(const l of e)s.append("v",l);throw r.search=s.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function z0(t,e){if(t&&e&&!Array.isArray(e)&&typeof t=="object"&&typeof e=="object"){const r=t,s=e;for(const l in s)r[l]=z0(r[l],s[l]);return t}return e}const wd=0,Ff=1,$0=2,Bc=3,Fl=4,Ei=5,Uc=6,zs=7;function Kc(t){return t.id===wd}function B0(t){return t.id===$0}function B1(t){return(function(e){return e.id===Ff})(t)||je(305,String(t.id),String(Ff)),Object.assign(t,{id:$0})}const U1=new Set;class K1{builder;configs;_dependency;_peerNameSet;extension;state;_signal;constructor(e,r){this.builder=e,this.extension=r,this.configs=new Set,this.state={id:wd}}mergeConfigs(){let e=this.extension.config||{};const r=this.extension.mergeConfig?this.extension.mergeConfig.bind(this.extension):E0;for(const s of this.configs)e=r(e,s);return e}init(e){const r=this.state;B0(r)||je(306,String(r.id));const s={getDependency:this.getInitDependency.bind(this),getDirectDependentNames:this.getDirectDependentNames.bind(this),getPeer:this.getInitPeer.bind(this),getPeerNameSet:this.getPeerNameSet.bind(this)},l={...s,getDependency:this.getDependency.bind(this),getInitResult:this.getInitResult.bind(this),getPeer:this.getPeer.bind(this)},u=(function(f,h,g){return Object.assign(f,{config:h,id:Bc,registerState:g})})(r,this.mergeConfigs(),s);let c;this.state=u,this.extension.init&&(c=this.extension.init(e,u.config,s)),this.state=(function(f,h,g){return Object.assign(f,{id:Fl,initResult:h,registerState:g})})(u,c,l)}build(e){const r=this.state;let s;r.id!==Fl&&je(307,String(r.id),String(Ei)),this.extension.build&&(s=this.extension.build(e,r.config,r.registerState));const l={...r.registerState,getOutput:()=>s,getSignal:this.getSignal.bind(this)};this.state=(function(u,c,f){return Object.assign(u,{id:Ei,output:c,registerState:f})})(r,s,l)}register(e,r){this._signal=r;const s=this.state;s.id!==Ei&&je(308,String(s.id),String(Ei));const l=this.extension.register&&this.extension.register(e,s.config,s.registerState);return this.state=(function(u){return Object.assign(u,{id:Uc})})(s),()=>{const u=this.state;u.id!==zs&&je(309,String(s.id),String(zs)),this.state=(function(c){return Object.assign(c,{id:Ei})})(u),l&&l()}}afterRegistration(e){const r=this.state;let s;return r.id!==Uc&&je(310,String(r.id),String(Uc)),this.extension.afterRegistration&&(s=this.extension.afterRegistration(e,r.config,r.registerState)),this.state=(function(l){return Object.assign(l,{id:zs})})(r),s}getSignal(){return this._signal===void 0&&je(311),this._signal}getInitResult(){this.extension.init===void 0&&je(312,this.extension.name);const e=this.state;return(function(r){return r.id>=Fl})(e)||je(313,String(e.id),String(Fl)),e.initResult}getInitPeer(e){const r=this.builder.extensionNameMap.get(e);return r?r.getExtensionInitDependency():void 0}getExtensionInitDependency(){const e=this.state;return(function(r){return r.id>=Bc})(e)||je(314,String(e.id),String(Bc)),{config:e.config}}getPeer(e){const r=this.builder.extensionNameMap.get(e);return r?r.getExtensionDependency():void 0}getInitDependency(e){const r=this.builder.getExtensionRep(e);return r===void 0&&je(315,this.extension.name,e.name),r.getExtensionInitDependency()}getDependency(e){const r=this.builder.getExtensionRep(e);return r===void 0&&je(315,this.extension.name,e.name),r.getExtensionDependency()}getState(){const e=this.state;return(function(r){return r.id>=zs})(e)||je(316,String(e.id),String(zs)),e}getDirectDependentNames(){return this.builder.incomingEdges.get(this.extension.name)||U1}getPeerNameSet(){let e=this._peerNameSet;return e||(e=new Set((this.extension.peerDependencies||[]).map(([r])=>r)),this._peerNameSet=e),e}getExtensionDependency(){if(!this._dependency){const e=this.state;(function(r){return r.id>=Ei})(e)||je(317,this.extension.name),this._dependency={config:e.config,init:e.initResult,output:e.output}}return this._dependency}}const Ym={tag:Fi};function W1(){const t=tt();t.isEmpty()&&t.append(nn())}const H1={config:{setOptions:Ym,updateOptions:Ym},init:({$initialEditorState:t=W1})=>({$initialEditorState:t,initialized:!1}),afterRegistration(t,{updateOptions:e,setOptions:r},s){const l=s.getInitResult();if(!l.initialized){l.initialized=!0;const{$initialEditorState:u}=l;if(UC(u))t.setEditorState(u,r);else if(typeof u=="function")t.update(()=>{u(t)},e);else if(u&&(typeof u=="string"||typeof u=="object")){const c=t.parseEditorState(u);t.setEditorState(c,r)}}return()=>{}},name:"@lexical/extension/InitialState",nodes:[Yr,mr,Hi,Qi,Vi]},Xm=Symbol.for("@lexical/extension/LexicalBuilder");function Zm(){}function Q1(t){throw t}function Il(t){return Array.isArray(t)?t:[t]}const Wc="0.44.0+prod.esm";class cr{roots;extensionNameMap;outgoingConfigEdges;incomingEdges;conflicts;_sortedExtensionReps;PACKAGE_VERSION;constructor(e){this.outgoingConfigEdges=new Map,this.incomingEdges=new Map,this.extensionNameMap=new Map,this.conflicts=new Map,this.PACKAGE_VERSION=Wc,this.roots=e;for(const r of e)this.addExtension(r)}static fromExtensions(e){const r=[Il(H1)];for(const s of e)r.push(Il(s));return new cr(r)}static maybeFromEditor(e){const r=e[Xm];return r&&(r.PACKAGE_VERSION!==Wc&&je(292,r.PACKAGE_VERSION,Wc),r instanceof cr||je(293)),r}static fromEditor(e){const r=cr.maybeFromEditor(e);return r===void 0&&je(294),r}constructEditor(){const{$initialEditorState:e,onError:r,...s}=this.buildCreateEditorArgs(),l=Object.assign(s0({...s,...r?{onError:u=>{r(u,l)}}:{}}),{[Xm]:this});for(const u of this.sortedExtensionReps())u.build(l);return l}buildEditor(){let e=Zm;function r(){try{e()}finally{e=Zm}}const s=Object.assign(this.constructEditor(),{dispose:r,[Symbol.dispose]:r});return e=Sn(this.registerEditor(s),()=>s.setRootElement(null)),s}hasExtensionByName(e){return this.extensionNameMap.has(e)}getExtensionRep(e){const r=this.extensionNameMap.get(e.name);if(r)return r.extension!==e&&je(295,e.name),r}addEdge(e,r,s){const l=this.outgoingConfigEdges.get(e);l?l.set(r,s):this.outgoingConfigEdges.set(e,new Map([[r,s]]));const u=this.incomingEdges.get(r);u?u.add(e):this.incomingEdges.set(r,new Set([e]))}addExtension(e){this._sortedExtensionReps!==void 0&&je(296);const r=Il(e),[s]=r;typeof s.name!="string"&&je(297,typeof s.name);let l=this.extensionNameMap.get(s.name);if(l!==void 0&&l.extension!==s&&je(298,s.name),!l){l=new K1(this,s),this.extensionNameMap.set(s.name,l);const u=this.conflicts.get(s.name);typeof u=="string"&&je(299,s.name,u);for(const c of s.conflictsWith||[])this.extensionNameMap.has(c)&&je(299,s.name,c),this.conflicts.set(c,s.name);for(const c of s.dependencies||[]){const f=Il(c);this.addEdge(s.name,f[0].name,f.slice(1)),this.addExtension(f)}for(const[c,f]of s.peerDependencies||[])this.addEdge(s.name,c,f?[f]:[])}}sortedExtensionReps(){if(this._sortedExtensionReps)return this._sortedExtensionReps;const e=[],r=(s,l)=>{let u=s.state;if(B0(u))return;const c=s.extension.name;var f;Kc(u)||je(300,c,l||"[unknown]"),Kc(f=u)||je(304,String(f.id),String(wd)),u=Object.assign(f,{id:Ff}),s.state=u;const h=this.outgoingConfigEdges.get(c);if(h)for(const g of h.keys()){const m=this.extensionNameMap.get(g);m&&r(m,c)}u=B1(u),s.state=u,e.push(s)};for(const s of this.extensionNameMap.values())Kc(s.state)&&r(s);for(const s of e)for(const[l,u]of this.outgoingConfigEdges.get(s.extension.name)||[])if(u.length>0){const c=this.extensionNameMap.get(l);if(c)for(const f of u)c.configs.add(f)}for(const[s,...l]of this.roots)if(l.length>0){const u=this.extensionNameMap.get(s.name);u===void 0&&je(301,s.name);for(const c of l)u.configs.add(c)}return this._sortedExtensionReps=e,this._sortedExtensionReps}registerEditor(e){const r=this.sortedExtensionReps(),s=new AbortController,l=[()=>s.abort()],u=s.signal;for(const c of r){const f=c.register(e,u);f&&l.push(f)}for(const c of r){const f=c.afterRegistration(e);f&&l.push(f)}return Sn(...l)}buildCreateEditorArgs(){const e={},r=new Set,s=new Map,l=new Map,u={},c={},f=this.sortedExtensionReps();for(const m of f){const{extension:v}=m;if(v.onError!==void 0&&(e.onError=v.onError),v.disableEvents!==void 0&&(e.disableEvents=v.disableEvents),v.parentEditor!==void 0&&(e.parentEditor=v.parentEditor),v.editable!==void 0&&(e.editable=v.editable),v.namespace!==void 0&&(e.namespace=v.namespace),v.$initialEditorState!==void 0&&(e.$initialEditorState=v.$initialEditorState),v.nodes)for(const y of A0(v)){if(typeof y!="function"){const _=s.get(y.replace);_&&je(302,v.name,y.replace.name,_.extension.name),s.set(y.replace,m)}r.add(y)}if(v.html){if(v.html.export)for(const[y,_]of v.html.export.entries())l.set(y,_);v.html.import&&Object.assign(u,v.html.import)}v.theme&&z0(c,v.theme)}Object.keys(c).length>0&&(e.theme=c),r.size&&(e.nodes=[...r]);const h=Object.keys(u).length>0,g=l.size>0;(h||g)&&(e.html={},h&&(e.html.import=u),g&&(e.html.export=l));for(const m of f)m.init(e);return e.onError||(e.onError=Q1),e}}function V1(t,e){const r=cr.fromEditor(t).getExtensionRep(e);return r===void 0&&je(303,e.name),r.getExtensionDependency()}function q1(t,e){const r=cr.maybeFromEditor(t);if(!r)return;const s=r.extensionNameMap.get(e);return s?s.getExtensionDependency():void 0}const G1=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0?A.useLayoutEffect:A.useEffect;function J1({onClear:t}){const[e]=on();return G1(()=>z1(e,t),[e,t]),null}function Y1(){return tt().getTextContent()}function X1(t,e=!0){if(t)return!1;let r=Y1();return e&&(r=r.trim()),r===""}function Z1(t){if(!X1(t,!1))return!1;const e=tt().getChildren(),r=e.length;if(r>1)return!1;for(let s=0;sZ1(t)}const K0=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0?A.useLayoutEffect:A.useEffect;function ek({editor:t,ariaActiveDescendant:e,ariaAutoComplete:r,ariaControls:s,ariaDescribedBy:l,ariaErrorMessage:u,ariaExpanded:c,ariaInvalid:f,ariaLabel:h,ariaLabelledBy:g,ariaMultiline:m,ariaOwns:v,ariaRequired:y,autoCapitalize:_,className:S,id:w,role:C="textbox",spellCheck:T=!0,style:N,tabIndex:M,"data-testid":L,...j},D){const[$,F]=A.useState(t.isEditable()),z=A.useCallback(te=>{te&&te.ownerDocument&&te.ownerDocument.defaultView?t.setRootElement(te):t.setRootElement(null)},[t]),J=A.useMemo(()=>(function(...te){return ne=>{for(const X of te)typeof X=="function"?X(ne):X!=null&&(X.current=ne)}})(D,z),[z,D]);return K0(()=>(F(t.isEditable()),t.registerEditableListener(te=>{F(te)})),[t]),k.jsx("div",{"aria-activedescendant":$?e:void 0,"aria-autocomplete":$?r:"none","aria-controls":$?s:void 0,"aria-describedby":l,...u!=null?{"aria-errormessage":u}:{},"aria-expanded":$&&C==="combobox"?!!c:void 0,...f!=null?{"aria-invalid":f}:{},"aria-label":h,"aria-labelledby":g,"aria-multiline":m,"aria-owns":$?v:void 0,"aria-readonly":!$||void 0,"aria-required":y,autoCapitalize:_,className:S,contentEditable:$,"data-testid":L,id:w,ref:J,role:C,spellCheck:T,style:N,tabIndex:M,...j})}const tk=A.forwardRef(ek);function ey(t){return t.getEditorState().read(U0(t.isComposing()))}const nk=A.forwardRef(rk);function rk(t,e){const{placeholder:r,...s}=t,[l]=on();return k.jsxs(k.Fragment,{children:[k.jsx(tk,{editor:l,...s,ref:e}),r!=null&&k.jsx(ik,{editor:l,content:r})]})}function ik({content:t,editor:e}){const r=(function(c){const[f,h]=A.useState(()=>ey(c));return K0(()=>{function g(){const m=ey(c);h(m)}return g(),Sn(c.registerUpdateListener(()=>{g()}),c.registerEditableListener(()=>{g()}))},[c]),f})(e),[s,l]=A.useState(e.isEditable());if(A.useLayoutEffect(()=>(l(e.isEditable()),e.registerEditableListener(c=>{l(c)})),[e]),!r)return null;let u=null;return typeof t=="function"?u=t(s):t!==null&&(u=t),u===null?null:k.jsx("div",{"aria-hidden":!0,children:u})}const sk=A.createContext(null),Hc={didCatch:!1,error:null};class ok extends A.Component{constructor(e){super(e),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=Hc}static getDerivedStateFromError(e){return{didCatch:!0,error:e}}resetErrorBoundary(...e){const{error:r}=this.state;r!==null&&(this.props.onReset?.({args:e,reason:"imperative-api"}),this.setState(Hc))}componentDidCatch(e,r){this.props.onError?.(e,r)}componentDidUpdate(e,r){const{didCatch:s}=this.state,{resetKeys:l}=this.props;s&&r.error!==null&&lk(e.resetKeys,l)&&(this.props.onReset?.({next:l,prev:e.resetKeys,reason:"keys"}),this.setState(Hc))}render(){const{children:e,fallbackRender:r,FallbackComponent:s,fallback:l}=this.props,{didCatch:u,error:c}=this.state;let f=e;if(u){const h={error:c,resetErrorBoundary:this.resetErrorBoundary};if(typeof r=="function")f=r(h);else if(s)f=A.createElement(s,h);else if(l!==void 0)f=l;else throw c}return A.createElement(sk.Provider,{value:{didCatch:u,error:c,resetErrorBoundary:this.resetErrorBoundary}},f)}}function lk(t=[],e=[]){return t.length!==e.length||t.some((r,s)=>!Object.is(r,e[s]))}function uk({children:t,onError:e}){return k.jsx(ok,{fallback:k.jsx("div",{style:{border:"1px solid #f00",color:"#f00",padding:"8px"},children:"An error was thrown."}),onError:e,children:t})}function ak(t,e,r,s,l){if(t===null||r.size===0&&s.size===0&&!l)return 0;const u=e._selection,c=t._selection;if(l)return 1;if(!(ee(u)&&ee(c)&&c.isCollapsed()&&u.isCollapsed()))return 0;const f=(function(T,N,M){const L=T._nodeMap,j=[];for(const D of N){const $=L.get(D);$!==void 0&&j.push($)}for(const[D,$]of M){if(!$)continue;const F=L.get(D);F===void 0||lt(F)||j.push(F)}return j})(e,r,s);if(f.length===0)return 0;if(f.length>1){const T=e._nodeMap,N=T.get(u.anchor.key),M=T.get(c.anchor.key);return N&&M&&!t._nodeMap.has(N.__key)&&re(N)&&N.__text.length===1&&u.anchor.offset===1?2:0}const h=f[0],g=t._nodeMap.get(h.__key);if(!re(g)||!re(h)||g.__mode!==h.__mode)return 0;const m=g.__text,v=h.__text;if(m===v)return 0;const y=u.anchor,_=c.anchor;if(y.key!==_.key||y.type!=="text")return 0;const S=y.offset,w=_.offset,C=v.length-m.length;return C===1&&w===S-1?2:C===-1&&w===S+1?3:C===-1&&w===S?4:0}function ck(t,e,r){let s=r(),l=0,u=s,c=0,f=null;return(h,g,m,v,y,_)=>{const S=r();if(_.has(Lv)&&(u=s,c=l,f=h),_.has(Ef))return l=0,s=S,2;_.has(Av)&&f&&(s=u,l=c,h=f);const w=ak(h,g,v,y,t.isComposing()),C=(()=>{const T=m===null||m.editor===t,N=_.has(kC);if(!N&&T&&_.has(Fi))return 0;if(w===1)return 2;if(h===null)return 1;const M=g._selection;if(!(v.size>0||y.size>0))return M!==null?0:2;const L=typeof e=="number"?e:e.peek();return N===!1&&w!==0&&w===l&&SF.exportJSON()))===JSON.stringify($.read(()=>z.exportJSON()))})(Array.from(v)[0],h,g)?0:1})();return s=S,l=w,C}}function ty(t){t.undoStack=[],t.redoStack=[],t.current=null}function W0(t,e,r,s=Date.now){const l=ck(t,r,s);return Sn(t.registerCommand(Yf,()=>((function(u,c){const f=c.redoStack,h=c.undoStack;if(h.length!==0){const g=c.current,m=h.pop();g!==null&&(f.push(g),u.dispatchCommand(Ol,!0)),h.length===0&&u.dispatchCommand(Ml,!1),c.current=m||null,m&&m.editor.setEditorState(m.editorState,{tag:Ef})}})(t,e),!0),De),t.registerCommand(Xf,()=>((function(u,c){const f=c.redoStack,h=c.undoStack;if(f.length!==0){const g=c.current;g!==null&&(h.push(g),u.dispatchCommand(Ml,!0));const m=f.pop();f.length===0&&u.dispatchCommand(Ol,!1),c.current=m||null,m&&m.editor.setEditorState(m.editorState,{tag:Ef})}})(t,e),!0),De),t.registerCommand(td,()=>(ty(e),!1),De),t.registerCommand(pC,()=>(ty(e),t.dispatchCommand(Ol,!1),t.dispatchCommand(Ml,!1),!0),De),t.registerUpdateListener(({editorState:u,prevEditorState:c,dirtyLeaves:f,dirtyElements:h,tags:g})=>{const m=e.current,v=e.redoStack,y=e.undoStack,_=m===null?null:m.editorState;if(m!==null&&u===_)return;const S=l(c,u,m,f,h,g);if(S===1)v.length!==0&&(e.redoStack=[],t.dispatchCommand(Ol,!1)),m!==null&&(y.push({...m}),t.dispatchCommand(Ml,!0));else if(S===2)return;e.current={editor:t,editorState:u}}))}function H0(){return{current:null,redoStack:[],undoStack:[]}}const Qc={build:(t,{delay:e,createInitialHistoryState:r,disabled:s,now:l})=>L0({delay:e,disabled:s,historyState:r(t),now:l}),config:{createInitialHistoryState:H0,delay:300,disabled:typeof window>"u",now:Date.now},name:"@lexical/history/History",register:(t,e,r)=>{const s=r.getOutput();return Sd(()=>s.disabled.value?void 0:W0(t,s.historyState.value,s.delay,()=>s.now.peek()()))}};_1(Qc,{disabled:!0});function fk({delay:t,externalHistoryState:e}){const[r]=on();return(function(s,l,u=1e3){const c=A.useMemo(()=>l||H0(),[l]);A.useEffect(()=>W0(s,c,u),[u,s,c])})(r,e,t),null}const dk=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0?A.useLayoutEffect:A.useEffect;function hk(t){return{initialValueFn:()=>t.isEditable(),subscribe:e=>t.registerEditableListener(e)}}function pk(){return(function(t){const[e]=on(),r=A.useMemo(()=>t(e),[e,t]),[s,l]=A.useState(()=>r.initialValueFn()),u=A.useRef(s);return dk(()=>{const{initialValueFn:c,subscribe:f}=r,h=c();return u.current!==h&&(u.current=h,l(h)),f(g=>{u.current=g,l(g)})},[r,t]),s})(hk)}const gk={name:"@lexical/react/ReactProvider"};var so=Ny();const mk=Ey(so);function yk(t){const e=window.location.origin,r=s=>{if(s.origin!==e)return;const l=t.getRootElement();if(document.activeElement!==l)return;const u=s.data;if(typeof u=="string"){let c;try{c=JSON.parse(u)}catch{return}if(c&&c.protocol==="nuanria_messaging"&&c.type==="request"){const f=c.payload;if(f&&f.functionId==="makeChanges"){const h=f.args;if(h){const[g,m,v,y,_]=h;t.update(()=>{const S=de();if(ee(S)){const w=S.anchor;let C=w.getNode(),T=0,N=0;if(re(C)&&g>=0&&m>=0&&(T=g,N=g+m,S.setTextNodeRange(C,T,C,N)),T===N&&v===""||(S.insertRawText(v),C=w.getNode()),re(C)){T=y,N=y+_;const M=C.getTextContentSize();T=T>M?M:T,N=N>M?M:N,S.setTextNodeRange(C,T,C,N)}s.stopImmediatePropagation()}})}}}}};return window.addEventListener("message",r,!0),()=>{window.removeEventListener("message",r,!0)}}function Q0(t,...e){const r=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",t);for(const l of e)s.append("v",l);throw r.search=s.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}let Li;function V0(t,e){const{key:r}=e;return t&&r in t?t[r]:e.defaultValue}function ny(t){return Li&&Li.editor===t?Li:void 0}function vk(t,e){if("cfg"in e){const{cfg:r,updater:s}=e;return[r,s(V0(t,r))]}return e}function q0(t,e){let r=e;for(const s of t){const[l,u]=vk(r,s),c=l.key;if(r===e&&V0(r,l)===u)continue;const f=r||xk(e);f[c]=u,r=f}return r}function xk(t){return Object.create(t||null)}function _k(t,e){return[t,e]}const G0="@lexical/html/DOM",J0=Symbol.for("@lexical/html/DOMExportContext"),Sk=()=>!0;function wk(t){return e=>e instanceof t}function Ck(t,{nodes:e}){if(e==="*")return Sk;let r={};const s=[];for(const l of e)if("getType"in l){const u=l.getType();if(r){const c=t[u];c===void 0&&Q0(339,l.name,u),r=Object.assign(r,c.types)}s.push(wk(l))}else r=void 0,s.push(l);return r||(s.length===1?s[0]:l=>{for(const u of s)if(u(l))return!0;return!1})}function ry(t){return(e,r,s)=>t(e,s)}function Vc(t){return(e,r,s,l)=>t(e,r,l)}function kk(t){return(e,r,s,l,u)=>t(e,r,s,u)}function Ek(t){return(e,r,s,l,u,c)=>t(e,r,s,l,c)}function iy(t,e){return(r,s)=>{const l=()=>t(r,s),u=e(r);return u?u(r,l,s):l()}}function qc(t,e){return(r,s,l)=>{const u=()=>t(r,s,l),c=e(r);return c?c(r,s,u,l):u()}}function Nk(t,e){return(r,s,l,u)=>{const c=()=>t(r,s,l,u),f=e(r);return f?f(r,s,l,c,u):c()}}function Tk(t,e){return(r,s,l,u,c)=>{const f=()=>t(r,s,l,u,c),h=e(r);return h?h(r,s,l,u,f,c):f()}}function Ok(t,e){return(r,s,l,u)=>{t(r,s,l,u);const c=e(r);c&&c(r,s,l,u)}}function sr(t,e,r,s,l){let u=r[e];for(const c of t[e])if(typeof c[0]=="function"){const[f,h]=c;u=s(u,g=>f(g)&&h||void 0)}else{const f=c[1],h={};for(const g in f){const m=f[g];m&&(h[g]=m.reduce((v,y)=>s(v,()=>y),u))}u=s(u,g=>{const m=h[g.getType()];return m&&l(m)})}r[e]=u}function Mk(t,e,r,s){if(!s)return;const l=t[e];if(typeof r=="function")l.push([r,s]);else{const u=l[l.length-1];let c;u&&u[0]==="types"?c=u[1]:(c={},l.push(["types",c]));for(const f in r){const h=c[f]||[];c[f]=h,h.push(s)}}}function Pk(t){return t.nodes==="*"}function bk(t,e){const r=(function(l){const u={},{nodes:c}=$1(l);for(const f of c)u[f.getType()]={klass:f,types:{}};for(const f of Object.values(u))if(f){const h=f.klass.getType();for(let{klass:g}=f;Rc(g.prototype);g=Object.getPrototypeOf(g)){const{ownNodeType:m}=qi(g),v=m&&u[m];v&&(v.types[h]=!0)}}return u})(t),s={$createDOM:[],$decorateDOM:[],$exportDOM:[],$extractWithChild:[],$getDOMSlot:[],$shouldExclude:[],$shouldInclude:[],$updateDOM:[]};for(const l of(function(u){const c=[],f=[],h=[];for(const v of u)if(Pk(v))c.push(v);else if(Array.isArray(v.nodes))for(const y of v.nodes)Rc(y.prototype)?h.push(v.nodes.length===1?v:{...v,nodes:[y]}):f.push(v.nodes.length===1?v:{...v,nodes:[y]});const g=new Map,m=v=>{let y=g.get(v);if(y===void 0){y=0;for(let _=v;Rc(_.prototype);_=Object.getPrototypeOf(_))y++;g.set(v,y)}return y};return h.sort((v,y)=>m(v.nodes[0])-m(y.nodes[0])),[...h,...f,...c]})(e)){const u=Ck(r,l);for(const c in s)Mk(s,c,u,l[c])}return s}function Rk(t){return t}const Dk={build:(t,e,r)=>({defaults:q0(e.contextDefaults,void 0)}),config:{contextDefaults:[],overrides:[]},html:{export:new Map([[Yr,()=>{const t=document.createElement("div");return t.role="textbox",{element:t}}]])},init(t,e){t.dom=(function(r,{overrides:s}){const l=bk(r,s),u={...no,...r.dom};return sr(l,"$createDOM",u,iy,ry),sr(l,"$exportDOM",u,iy,ry),sr(l,"$extractWithChild",u,Tk,Ek),sr(l,"$getDOMSlot",u,qc,Vc),sr(l,"$shouldExclude",u,qc,Vc),sr(l,"$shouldInclude",u,qc,Vc),sr(l,"$updateDOM",u,Nk,kk),sr(l,"$decorateDOM",u,Ok,Rk),u})(t,e)},mergeConfig(t,e){const r=E0(t,e);for(const s of["overrides","contextDefaults"])e[s]&&(r[s]=[...t[s],...e[s]]);return r},name:G0};function Y0(t,e,r){return(function(s,l,u,c){return Object.assign(sv(Symbol(l),{isEqual:c,parse:u}),{[s]:!0})})(J0,t,e,r)}Y0("root",Boolean);const jk=Y0("isExport",Boolean);function Fk(t){const e=cr.maybeFromEditor(t);return e&&e.hasExtensionByName(G0)?V1(t,Dk).output.defaults:void 0}const Ik=(function(t,e=()=>{}){return(r,s=Ui())=>l=>{const u=ny(s),c=u&&u[t],f=q0(r,c||e(s));return f&&f!==c?(function(h,g,m,v=Ui()){const y=Li,_=ny(v);try{return Li={..._,editor:v,[h]:g},m()}finally{Li=y}})(t,f,l,s):l()}})(J0,Fk);function Lk(t,e=null,r=Ui()){return Ik([_k(jk,!0)],r)(()=>{const s=tt(),l=po(r),u=t.append.bind(t);for(const c of s.getChildren())X0(r,c,u,e,l);return t})}function Ak(t,e=null){return(typeof document>"u"||typeof window>"u"&&global.window===void 0)&&Q0(338),Lk(document.createElement("div"),e,t).innerHTML}function X0(t,e,r,s=null,l=po(t)){let u=l.$shouldInclude(e,s,t);const c=l.$shouldExclude(e,s,t);let f=e;s!==null&&re(e)&&(f=P1(s,e,"clone"));const h=l.$exportDOM(f,t),{element:g,after:m,append:v,$getChildNodes:y}=h;if(!g)return!1;const _=document.createDocumentFragment(),S=y?y():K(f)?f.getChildren():[],w=_.append.bind(_);for(const C of S){const T=X0(t,C,w,s,l);!u&&T&&l.$extractWithChild(e,C,s,"html",t)&&(u=!0)}if(u&&!c){if((Pt(g)||bf(g))&&(v?v(_):g.append(_)),r(g),m){const C=m.call(f,g);C&&(bf(g)?g.replaceChildren(C):g.replaceWith(C))}}else r(_);return u}function zk(t,...e){const r=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",t);for(const l of e)s.append("v",l);throw r.search=s.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function $k(t,e=de()){return e==null&&zk(166),ee(e)&&e.isCollapsed()||e.getNodes().length===0?"":Ak(t,e)}function If(t,e){const r=t.getData("text/plain")||t.getData("text/uri-list");r!=null&&e.insertRawText(r)}const Z0="application/x-lexical-drag";function Bk(t,e){const r={editorKey:e.getKey()};t.setData(Z0,JSON.stringify(r))}function Uk(t){const e=(function(l,u){if(document.caretRangeFromPoint!==void 0){const c=document.caretRangeFromPoint(l,u);return c===null?null:{node:c.startContainer,offset:c.startOffset}}if(document.caretPositionFromPoint!=="undefined"){const c=document.caretPositionFromPoint(l,u);return c===null?null:{node:c.offsetNode,offset:c.offset}}return null})(t.clientX,t.clientY);if(e===null)return null;const r=ku(e.node);if(r===null)return null;if(re(r))return dr(r,"next",e.offset);if(K(r))return Df(r,e.offset,"next");const s=r.getParent();return s===null?null:Df(s,r.getIndexWithinParent()+1,"next")}function Kk(t,e,r){const s=t.dataTransfer;if(s===null)return!1;const l=(function(g){const m=g.getData(Z0);if(!m)return null;let v;try{v=JSON.parse(m)}catch{return null}return(y=v)!==null&&typeof y=="object"&&"editorKey"in y&&typeof y.editorKey=="string"?v:null;var y})(s);if(l===null)return!1;const u=Uk(t);if(u===null)return!1;const c=x1(u);if(c===null)return!1;const f=l.editorKey===e.getKey(),h=de();if(f){if(!ee(h)||h.isCollapsed())return!1;if((function(g,m){const{anchor:v,focus:y}=xd(Rf(m),"next");return cu(v,g)<0&&cu(g,y)<0})(u,h))return t.preventDefault(),!0;h.removeText()}if(!c.origin.isAttached())return t.preventDefault(),!0;if(r(s,C0(_0(c)),e),!f){const g=e.getRootElement(),m=g?g.ownerDocument:null,v=m?(function(y,_){const S=_.querySelectorAll('[data-lexical-editor="true"]');for(const w of Array.from(S)){const C=w.__lexicalEditor;if(C&&C.getKey()===y)return w}return null})(l.editorKey,m):null;v!==null&&v.dispatchEvent(new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,inputType:"deleteByDrag"}))}return t.preventDefault(),!0}function Wk(t,e){return Kk(t,e,(r,s)=>If(r,s))}const vr=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0,Hk=vr&&"documentMode"in document?document.documentMode:null,Qk=vr&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),Vk=!(!vr||!("InputEvent"in window)||Hk)&&"getTargetRanges"in new window.InputEvent("input"),sy=vr&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,qk=vr&&/Android/.test(navigator.userAgent),Gk=vr&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!qk,Jk=vr&&/^(?=.*Chrome).*/i.test(navigator.userAgent),Yk=vr&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&Qk&&!Jk;function oy(t,e){e.update(()=>{if(t!==null){const r=D0(t,KeyboardEvent)?null:t.clipboardData,s=de();if(s!==null&&!s.isCollapsed()&&r!=null){t.preventDefault();const l=$k(e);l!==null&&r.setData("text/html",l),r.setData("text/plain",s.getTextContent())}}})}function Xk(t){return Sn(t.registerCommand(Ar,e=>{const r=de();return!!ee(r)&&(r.deleteCharacter(e),!0)},De),t.registerCommand(Xs,e=>{const r=de();return!!ee(r)&&(r.deleteWord(e),!0)},De),t.registerCommand(Zs,e=>{const r=de();return!!ee(r)&&(r.deleteLine(e),!0)},De),t.registerCommand(Di,e=>{const r=de();if(!ee(r))return!1;if(typeof e=="string")r.insertText(e);else{const s=e.dataTransfer;if(s!=null)If(s,r);else{const l=e.data;l&&r.insertText(l)}}return!0},De),t.registerCommand(Bl,()=>{const e=de();return!!ee(e)&&(e.removeText(),!0)},De),t.registerCommand(Ri,e=>{const r=de();return!!ee(r)&&(r.insertLineBreak(e),!0)},De),t.registerCommand(vf,()=>{const e=de();return!!ee(e)&&(e.insertLineBreak(),!0)},De),t.registerCommand(xv,e=>{const r=de();if(!ee(r))return!1;const s=e,l=s.shiftKey;return!!Qm(r,!0)&&(s.preventDefault(),Vm(r,l,!0),!0)},De),t.registerCommand(vv,e=>{const r=de();if(!ee(r))return!1;const s=e,l=s.shiftKey;return!!Qm(r,!1)&&(s.preventDefault(),Vm(r,l,!1),!0)},De),t.registerCommand(wv,e=>{const r=de();return!!ee(r)&&(!sy||navigator.language!=="ko-KR")&&(e.preventDefault(),t.dispatchCommand(Ar,!0))},De),t.registerCommand(kv,e=>{const r=de();return!!ee(r)&&(e.preventDefault(),t.dispatchCommand(Ar,!1))},De),t.registerCommand(Ai,e=>{const r=de();if(!ee(r))return!1;if(e!==null){if((sy||Gk||Yk)&&Vk)return!1;e.preventDefault()}return t.dispatchCommand(Ri,!1)},De),t.registerCommand(xf,()=>(YC(),!0),De),t.registerCommand(Zf,e=>{const r=de();return!!ee(r)&&(oy(e,t),!0)},De),t.registerCommand(ed,e=>{const r=de();return!!ee(r)&&((function(s,l){oy(s,l),l.update(()=>{const u=de();ee(u)&&u.removeText()})})(e,t),!0)},De),t.registerCommand(Jf,e=>{const r=de();return!!ee(r)&&((function(s,l){s.preventDefault(),l.update(()=>{const u=de(),c=D0(s,ClipboardEvent)?s.clipboardData:null;c!=null&&ee(u)&&If(c,u)},{tag:EC})})(e,t),!0)},De),t.registerCommand(Nv,e=>Wk(e,t),De),t.registerCommand(Tv,e=>{const r=de();return!!ee(r)&&(r.isCollapsed()||e.dataTransfer===null||Bk(e.dataTransfer,t),!0)},De))}function Zk(t,...e){const r=new URL("https://lexical.dev/docs/error"),s=new URLSearchParams;s.append("code",t);for(const l of e)s.append("v",l);throw r.search=s.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const Cd=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0?A.useLayoutEffect:A.useEffect;function eE({editor:t,ErrorBoundary:e}){return(function(r,s){const[l,u]=A.useState(()=>r.getDecorators());return Cd(()=>r.registerDecoratorListener(c=>{so.flushSync(()=>{u(c)})}),[r]),A.useEffect(()=>{u(r.getDecorators())},[r]),A.useMemo(()=>{const c=[],f=Object.keys(l);for(let h=0;hr._onError(y),children:k.jsx(A.Suspense,{fallback:null,children:l[g]})}),v=r.getElementByKey(g);v!==null&&c.push(so.createPortal(m,v,g))}return c},[s,l,r])})(t,e)}function tE({editor:t,ErrorBoundary:e}){return(function(r){const s=cr.maybeFromEditor(r);if(s&&s.hasExtensionByName(gk.name)){for(const l of["@lexical/plain-text","@lexical/rich-text"])s.hasExtensionByName(l)&&Zk(320,l);return!0}return!1})(t)?null:k.jsx(eE,{editor:t,ErrorBoundary:e})}function ly(t){return t.getEditorState().read(U0(t.isComposing()))}function nE({contentEditable:t,placeholder:e=null,ErrorBoundary:r}){const[s]=on();return(function(l){Cd(()=>Sn(Xk(l),yk(l)),[l])})(s),k.jsxs(k.Fragment,{children:[t,k.jsx(rE,{content:e}),k.jsx(tE,{editor:s,ErrorBoundary:r})]})}function rE({content:t}){const[e]=on(),r=(function(l){const[u,c]=A.useState(()=>ly(l));return Cd(()=>{function f(){const h=ly(l);c(h)}return f(),Sn(l.registerUpdateListener(()=>{f()}),l.registerEditableListener(()=>{f()}))},[l]),u})(e),s=pk();return r?typeof t=="function"?t(s):t:null}const uy="startTransition",Lf=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0,iE=Lf?A.useLayoutEffect:A.useEffect;class sE{key;ref;icon;title;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}const ay=t=>{const e=document.getElementById("typeahead-menu");if(!e)return;const r=e.getBoundingClientRect();r.top+r.height>window.innerHeight&&e.scrollIntoView({block:"center"}),r.top<0&&e.scrollIntoView({block:"center"}),t.scrollIntoView({block:"nearest"})};function cy(t,e){const r=t.getBoundingClientRect(),s=e.getBoundingClientRect();return r.top>=s.top-6&&r.top<=s.bottom+6}function oE(t,e,r,s){const[l]=on();A.useEffect(()=>{if(e!=null&&t!=null){const u=l.getRootElement(),c=u!=null?(function(v){let y=getComputedStyle(v);const _=y.position==="absolute",S=/(auto|scroll)/;if(y.position==="fixed")return document.body;for(let w=v;w=w.parentElement;)if(y=getComputedStyle(w),(!_||y.position!=="static")&&S.test(y.overflow+y.overflowY+y.overflowX))return w;return document.body})(u):document.body;let f=!1,h=cy(e,c);const g=function(){f||(window.requestAnimationFrame(function(){r(),f=!1}),f=!0);const v=cy(e,c);v!==h&&(h=v,s?.(v))},m=new ResizeObserver(r);return window.addEventListener("resize",r),document.addEventListener("scroll",g,{capture:!0,passive:!0}),m.observe(e),()=>{m.unobserve(e),window.removeEventListener("resize",r),document.removeEventListener("scroll",g,!0)}}},[e,l,s,r,t])}const fy=xe("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function lE({index:t,isSelected:e,onClick:r,onMouseEnter:s,option:l}){let u="item";return e&&(u+=" selected"),k.jsxs("li",{tabIndex:-1,className:u,ref:l.setRefElement,role:"option","aria-selected":e,id:"typeahead-item-"+t,onMouseEnter:s,onClick:r,children:[l.icon,k.jsx("span",{className:"text",children:l.title})]},l.key)}function uE({close:t,editor:e,anchorElementRef:r,resolution:s,options:l,menuRenderFn:u,onSelectOption:c,shouldSplitNodeWithQuery:f=!1,commandPriority:h=n0,preselectFirstItem:g=!0}){const[m,v]=A.useState(null),y=m!==null?Math.min(l.length-1,m):null,_=s.match&&s.match.matchingString;A.useEffect(()=>{g&&v(0)},[_,g]);const S=A.useCallback(N=>{e.update(()=>{const M=s.match!=null&&f?(function(L){const j=de();if(!ee(j)||!j.isCollapsed())return null;const D=j.anchor;if(D.type!=="text")return null;const $=D.getNode();if(!$.isSimpleText())return null;const F=D.offset,z=$.getTextContent().slice(0,F),J=L.replaceableString.length,te=F-(function(X,ae,Se){let ye=Se;for(let _e=ye;_e<=ae.length;_e++)X.slice(-_e)===ae.substring(0,_e)&&(ye=_e);return ye})(z,L.matchingString,J);if(te<0)return null;let ne;return te===0?[ne]=$.splitText(F):[,ne]=$.splitText(te,F),ne})(s.match):null;c(N,M,t,s.match?s.match.matchingString:"")})},[e,f,s.match,c,t]),w=A.useCallback(N=>{const M=e.getRootElement();M!==null&&(M.setAttribute("aria-activedescendant","typeahead-item-"+N),v(N))},[e]),C=A.useCallback(()=>r.current&&l.length?mk.createPortal(k.jsx("div",{className:"typeahead-popover mentions-menu",children:k.jsx("ul",{children:l.map((N,M)=>k.jsx(lE,{index:M,isSelected:y===M,onClick:()=>{v(M),S(N)},onMouseEnter:()=>{v(M)},option:N},N.key))})}),r.current):null,[r,l,y,S,v]);A.useEffect(()=>()=>{const N=e.getRootElement();N!==null&&N.removeAttribute("aria-activedescendant")},[e]),iE(()=>{l===null?v(null):y===null&&g&&w(0)},[l,y,w,g]),A.useEffect(()=>Sn(e.registerCommand(fy,({option:N})=>!(!N.ref||N.ref.current==null)&&(ay(N.ref.current),!0),h)),[e,w,h]),A.useEffect(()=>Sn(e.registerCommand(Sv,N=>{const M=N;if(l!==null&&l.length){const L=y===null?0:y!==l.length-1?y+1:0;w(L);const j=l[L];if(!j)return w(-1),M.preventDefault(),M.stopImmediatePropagation(),!0;j.ref&&j.ref.current&&e.dispatchCommand(fy,{index:L,option:j}),M.preventDefault(),M.stopImmediatePropagation()}return!0},h),e.registerCommand(_v,N=>{const M=N;if(l!==null&&l.length){const L=y===null?l.length-1:y!==0?y-1:l.length-1;w(L);const j=l[L];if(!j)return w(-1),M.preventDefault(),M.stopImmediatePropagation(),!0;j.ref&&j.ref.current&&ay(j.ref.current),M.preventDefault(),M.stopImmediatePropagation()}return!0},h),e.registerCommand(Cv,N=>{const M=N;return M.preventDefault(),M.stopImmediatePropagation(),t(),!0},h),e.registerCommand(Ev,N=>{const M=N;return l!==null&&y!==null&&l[y]!=null&&(M.preventDefault(),M.stopImmediatePropagation(),S(l[y]),!0)},h),e.registerCommand(Ai,N=>l!==null&&y!==null&&l[y]!=null&&(N!==null&&(N.preventDefault(),N.stopImmediatePropagation()),S(l[y]),!0),h)),[S,t,e,l,y,w,h]);const T=A.useMemo(()=>({options:l,selectOptionAndCleanUp:S,selectedIndex:y,setHighlightedIndex:v}),[S,y,l]);return u!=null?u(r,T,s.match?s.match.matchingString:""):C()}function dy(t,e){e!=null&&(t.className=e),t.setAttribute("aria-label","Typeahead menu"),t.setAttribute("role","listbox"),t.style.display="block",t.style.position="absolute"}const aE=`\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'"~=<>_:;`;function cE(t,{minLength:e=1,maxLength:r=75,punctuation:s=aE,allowWhitespace:l=!1}){return A.useCallback(u=>{const c=new RegExp("(^|\\s|\\()(["+t+"]((?:"+("[^"+t+s+(l?"":"\\s")+"]")+"){0,"+r+"}))$").exec(u);if(c!==null){const f=c[1],h=c[3];if(h.length>=e)return{leadOffset:c.index+f.length,matchingString:h,replaceableString:c[2]}}return null},[l,t,s,r,e])}function fE({options:t,onQueryChange:e,onSelectOption:r,onOpen:s,onClose:l,menuRenderFn:u,triggerFn:c,anchorClassName:f,commandPriority:h=n0,parent:g,preselectFirstItem:m=!0,ignoreEntityBoundary:v=!1}){const[y]=on(),[_,S]=A.useState(null),w=(function(N,M,L,j=Lf?document.body:void 0,D=!0){const[$]=on(),F=Lf?document.createElement("div"):null,z=A.useRef(F),J=A.useCallback(()=>{if(z.current===null||j===void 0)return;z.current.style.top=z.current.style.bottom;const ne=$.getRootElement(),X=z.current,ae=X.firstChild;if(ne!==null&&N!==null){const{left:Se,top:ye,width:_e,height:Z}=N.getRect(),W=z.current.offsetHeight;if(X.style.top=`${ye+W+3+(D?window.pageYOffset:0)}px`,X.style.left=`${Se+window.pageXOffset}px`,X.style.height=`${Z}px`,X.style.width=`${_e}px`,ae!==null){ae.style.top=`${ye}`;const Q=ae.getBoundingClientRect(),P=Q.height,U=Q.width,he=ne.getBoundingClientRect();Se+U>he.right&&(X.style.left=`${he.right-U+window.pageXOffset}px`),(ye+P>window.innerHeight||ye+P>he.bottom)&&ye-he.top>P+Z&&(X.style.top=`${ye-P-Z+(D?window.pageYOffset:0)}px`)}X.isConnected||(dy(X,L),j.append(X)),X.setAttribute("id","typeahead-menu"),ne.setAttribute("aria-controls","typeahead-menu")}},[$,N,D,L,j]);A.useEffect(()=>{const ne=$.getRootElement();return N!==null&&J(),()=>{ne!==null&&ne.removeAttribute("aria-controls");const X=z.current;X!==null&&X.isConnected&&(X.remove(),X.removeAttribute("id"))}},[$,J,N]);const te=A.useCallback(ne=>{N!==null&&(ne||M(null))},[N,M]);return oE(N,z.current,J,te),F!=null&&F===z.current&&(dy(F,L),j?.append(F)),z})(_,S,f,g),C=A.useCallback(()=>{S(null),l!=null&&_!==null&&l()},[l,_]),T=A.useCallback(N=>{S(N),s!=null&&_===null&&s(N)},[s,_]);return A.useEffect(()=>{const N=y.registerUpdateListener(()=>{y.getEditorState().read(()=>{if(!y.isEditable())return void C();if(y.isComposing())return;const M=y._window||window,L=M.document.createRange(),j=de(),D=(function(z){let J=null;return z.getEditorState().read(()=>{const te=de();ee(te)&&(J=(function(ne){const X=ne.anchor;if(X.type!=="text")return null;const ae=X.getNode();if(!ae.isSimpleText())return null;const Se=X.offset;return ae.getTextContent().slice(0,Se)})(te))}),J})(y);if(!ee(j)||!j.isCollapsed()||D===null||L===null)return void C();const $=c(D,y);if(e($?$.matchingString:null),$!==null&&(v||!(function(z,J){return J===0&&z.getEditorState().read(()=>{const te=de();if(ee(te)){const ne=te.anchor.getNode().getPreviousSibling();return re(ne)&&ne.isTextEntity()}return!1})})(y,$.leadOffset))&&(function(J,te,ne){const X=un(ne);if(X===null||!X.isCollapsed)return!1;const ae=X.anchorNode,Se=J,ye=X.anchorOffset;if(ae==null||ye==null)return!1;try{te.setStart(ae,Se),te.setEnd(ae,ye)}catch{return!1}return!0})($.leadOffset,L,M)!==null)return F=()=>T({getRect:()=>L.getBoundingClientRect(),match:$}),void(uy in Yc?Yc[uy](F):F());var F;C()})});return()=>{N()}},[y,c,e,_,C,T,v]),A.useEffect(()=>y.registerEditableListener(N=>{N||C()}),[y,C]),_===null||y===null||w.current===null?null:k.jsx(uE,{close:C,resolution:_,editor:y,anchorElementRef:w,options:t,menuRenderFn:u,shouldSplitNodeWithQuery:!0,onSelectOption:r,commandPriority:h,preselectFirstItem:m})}function kd(){return gr({queryKey:["agents"],queryFn:sn.agents})}function Ed(){return gr({queryKey:["rooms"],queryFn:sn.rooms})}class mo extends mr{__mention;static getType(){return"mention"}static clone(e){return new mo(e.__mention,e.__text,e.__key)}static importJSON(e){const r=ex(e.mentionName);return r.setFormat(e.format),r.setDetail(e.detail),r.setMode(e.mode),r.setStyle(e.style),r}constructor(e,r,s){super(r??`@${e}`,s),this.__mention=e}exportJSON(){return{...super.exportJSON(),mentionName:this.__mention,type:"mention",version:1}}createDOM(e){const r=super.createDOM(e);return r.style.color="var(--color-green)",r.style.background="var(--color-tint)",r.style.padding="0 4px",r.style.borderRadius="3px",r}isTextEntity(){return!0}isToken(){return!0}getMentionName(){return this.__mention}}function ex(t){const e=new mo(t);return e.setMode("token"),e}function dE(t){return t instanceof mo}const hE=5,Ll=6,gn=8,Al=360,pE=220,hy=360,gE=260,py=3;class mE extends sE{agent;constructor(e){super(e.id),this.agent=e}}function yE(t,e,r){return r{const g=u.current;if(!g)return;const m=()=>{const _=t.getBoundingClientRect();if(!(_.left>gn&&_.top>gn)){h(ae=>({...ae,left:-1e4,top:-1e4,visibility:"hidden"}));return}c.current??={bottom:_.bottom,top:_.top};const w=c.current,C=window.innerWidth,T=window.innerHeight,N=Math.min(hy,Math.max(pE,C-gn*2)),M=Math.max(gn,w.top-py),L=Math.max(M,w.bottom+py),j=Math.max(0,M-gn-Ll),D=Math.max(0,T-L-gn-Ll),$=Math.min(g.scrollHeight,Al),F=Math.min(Math.max($,gE),Al),J=(D>=F?"down":j>=F||j>D?"up":"down")==="up",te=Math.max(96,Math.min(Al,J?j:D)),ne=Math.min($,te),X=J?Math.max(gn,M-ne-Ll):Math.min(L+Ll,T-gn-ne);h({left:yE(_.left,gn,C-N-gn),maxHeight:te,overflowY:$>te?"auto":"hidden",position:"fixed",top:X,visibility:"visible",width:N,zIndex:60})};m();const v=window.requestAnimationFrame(m);window.addEventListener("resize",m),document.addEventListener("scroll",m,{capture:!0,passive:!0});const y=new ResizeObserver(m);return y.observe(g),()=>{window.cancelAnimationFrame(v),y.disconnect(),window.removeEventListener("resize",m),document.removeEventListener("scroll",m,!0)}},[t,e.length]),k.jsx("div",{ref:u,"data-mention-menu":"true",role:"listbox",className:"bg-bg border border-line rounded shadow-lg p-1 overflow-auto",style:f,onMouseDown:g=>g.preventDefault(),children:e.map((g,m)=>k.jsxs("div",{ref:g.setRefElement,role:"option","aria-selected":m===r,tabIndex:-1,title:g.agent.fqid??g.agent.id,className:`px-2.5 py-1.5 cursor-pointer text-xs rounded ${m===r?"bg-tint text-green":"text-sub"}`,onClick:()=>s(g),onMouseEnter:()=>l(m),children:[k.jsxs("span",{className:"block font-semibold break-words leading-relaxed",children:["@",g.agent.id]}),g.agent.fqid?k.jsx("span",{className:"block text-faint text-[11px] break-all",children:g.agent.fqid}):null]},g.agent.id))})}function xE(){const[t]=on(),[e,r]=A.useState(null),{data:s=[]}=kd(),{data:l=[]}=Ed(),{selected:u}=wt(),c=A.useMemo(()=>{if(!u||u.kind!=="room")return s;const m=l.find(y=>y.id===u.id);if(!m)return[];const v=new Set(m.members??[]);return s.filter(y=>v.has(y.id)||(y.rooms??[]).includes(u.id))},[s,l,u]),f=A.useMemo(()=>{if(e===null)return[];const m=e.toLowerCase();return c.filter(v=>v.id.toLowerCase().includes(m)||(v.fqid?.toLowerCase().includes(m)??!1)).slice(0,hE).map(v=>new mE(v))},[c,e]),h=cE("@",{minLength:0}),g=A.useCallback((m,v,y)=>{t.update(()=>{const _=ex(m.agent.id);v&&v.replace(_),_.select(),y()})},[t]);return k.jsx(fE,{onQueryChange:r,onSelectOption:g,triggerFn:h,options:f,commandPriority:r0,menuRenderFn:(m,{selectedIndex:v,selectOptionAndCleanUp:y,setHighlightedIndex:_})=>!m.current||f.length===0?null:so.createPortal(k.jsx(vE,{anchorElement:m.current,options:f,selectedIndex:v,selectOptionAndCleanUp:y,setHighlightedIndex:_}),document.body)})}function _E(t){return t?.capabilities?.event_stream==="sse"}function Gi(t){return t?.capabilities?.direct_messages===!0}function SE(t){return t?.capabilities?.message_pagination==="cursor"}function gy(t){if(typeof t=="boolean")return t?"enabled":"disabled";const e=t?.trim();return e||"unsupported"}function Nd(){const{data:t}=wn(),e=Gi(t),r=gr({queryKey:["dms"],queryFn:sn.dms,enabled:e});return{...r,data:e?r.data:[],directMessagesEnabled:e}}function wE(){return document.querySelector('[data-mention-menu="true"]')!==null}function CE(){const t=[],e=[],r=tt();for(const s of r.getChildren()){if(!K(s))continue;let l="";for(const u of s.getChildren())dE(u)?(e.push(u.getMentionName()),l+=u.getTextContent()):re(u)&&(l+=u.getTextContent());t.push(l)}return{text:t.join(` +`),mentions:e}}function kE(t){return t instanceof Vy?t.status===401?"Sending requires a console token with write scope.":t.status===403?t.message||"This console token cannot send here.":t.message||`Message send failed (${t.status}).`:t instanceof Error&&t.message.trim()!==""?t.message:"Message could not be sent."}function EE(){const[t]=on(),{selected:e}=wt(),{data:r=[]}=Nd(),{data:s}=wn(),l=Gi(s),[u,c]=A.useState(null),f=xw({mutationFn:sn.sendMessage,onSuccess:()=>{c(null),t.dispatchCommand(td,void 0)},onError:h=>{c(kE(h))}});return A.useEffect(()=>t.registerCommand(Ai,h=>{if(h===null||h.ctrlKey||h.metaKey||h.shiftKey||wE()||!Br(e))return!1;h.preventDefault();const{text:g,mentions:m}=t.getEditorState().read(()=>CE()),v=g.trim();if(!v||e.kind==="dm"&&!l)return!0;const _={target:e.kind==="room"?{kind:"room",room_id:e.id}:{kind:"dm",dm_id:e.id,participant_ids:r.find(S=>S.id===e.id)?.participant_ids??[]},from:{type:"human",id:"operator",name:"Operator"},parts:[{kind:"text",text:v}],...m.length>0?{mentions:m}:{}};return c(null),f.mutate(_),!0},r0),[t,e,r,f,l]),u?k.jsx("div",{role:"status",className:"mt-2 text-[11px] text-coral",children:u}):null}function NE(){return k.jsxs("div",{className:"flex gap-2.5 items-start",children:[k.jsx("span",{className:"text-green font-bold pt-1 select-none",children:">"}),k.jsxs("div",{className:"flex-1 relative min-w-0",children:[k.jsx(nE,{contentEditable:k.jsx(nk,{"data-composer-input":"true",className:"min-h-[28px] outline-none text-ink whitespace-pre-wrap break-words py-1","aria-label":"Compose a message"}),placeholder:k.jsx("span",{className:"absolute top-1 left-0 text-faint pointer-events-none",children:"Send a room or DM message into this network."}),ErrorBoundary:uk}),k.jsx(fk,{}),k.jsx(J1,{}),k.jsx(xE,{}),k.jsx(EE,{})]})]})}function TE(){const{selected:t}=wt(),e=Br(t)?`target: ${t.kind} ${t.id}`:"no target selected.";return k.jsxs("div",{className:"flex justify-between items-center gap-4 text-[11px] text-faint",children:[k.jsx("span",{children:e}),k.jsxs("div",{className:"flex gap-3.5",children:[k.jsxs("span",{children:[k.jsx("kbd",{className:"text-green",children:"[enter]"})," send"]}),k.jsxs("span",{children:[k.jsx("kbd",{className:"text-green",children:"[ctrl+enter]"})," newline"]})]})]})}function OE(){const{data:t}=wn(),{selected:e}=wt();if(!Br(e))return null;const r=t?.id??"moltnet",s=`/${e.kind}/${e.id}`;return k.jsxs("div",{className:"text-xs text-ink pb-2.5",children:[k.jsxs("span",{className:"text-green",children:[r,"@moltnet"]})," ",k.jsxs("span",{className:"text-sub",children:["~ ",s]})]})}const ME={paragraph:"m-0 leading-relaxed",text:{base:""}},PE={namespace:"moltnet-composer",theme:ME,nodes:[mo],onError(t){console.error("[lexical]",t)}};function bE(){return Gy()?k.jsxs(fe,{children:[k.jsx(fe.Header,{children:k.jsx(fe.Title,{children:"HUMAN INGRESS"})}),k.jsxs(fe.Body,{children:[k.jsx(OE,{}),k.jsx(w1,{initialConfig:PE,children:k.jsx(NE,{})})]}),k.jsx(fe.Footer,{children:k.jsx(TE,{})})]}):null}function Ye({label:t,value:e}){return k.jsxs("div",{className:"grid grid-cols-[110px_1fr] items-baseline gap-2",children:[k.jsxs("span",{className:"text-mute",children:[t," :"]}),k.jsx("span",{className:"text-sub break-all",children:e})]})}function Gr({active:t=!1,showMarker:e=!0,marker:r,markerClassName:s="",onClick:l,title:u,subtitle:c,trailing:f}){const h=["block w-full text-left bg-transparent border px-2.5 py-1 cursor-pointer rounded text-xs transition-colors",t?"bg-tint border-line-bright text-ink":"border-transparent text-sub hover:bg-tint/70 hover:text-ink"].join(" ");return k.jsx("button",{type:"button",className:h,onClick:l,children:k.jsxs("div",{className:"flex justify-between items-baseline gap-3",children:[k.jsxs("span",{className:"flex-1 min-w-0",children:[k.jsxs("span",{className:"block truncate",children:[e?k.jsx("span",{"aria-hidden":"true",className:`mr-1 inline-block ${s} ${t||r!==void 0?"":"invisible"}`,children:t?">":r}):null,u]}),c!==void 0?k.jsx("span",{className:"block truncate text-faint text-[11px] mt-0.5",children:c}):null]}),f!==void 0?k.jsx("span",{className:"text-faint text-[11px] shrink-0",children:f}):null]})})}function RE(){const{selected:t,select:e}=wt(),{data:r=[]}=kd(),{data:s=[]}=Ed(),{data:l=[],directMessagesEnabled:u}=Nd(),c=t?.kind==="agent"?t.id:null,f=A.useMemo(()=>c?r.find(m=>m.id===c):null,[r,c]),h=A.useMemo(()=>c?s.filter(m=>(m.members??[]).includes(c)||(f?.rooms??[]).includes(m.id)):[],[s,f,c]),g=A.useMemo(()=>c?l.filter(m=>(m.participant_ids??[]).includes(c)):[],[l,c]);return!f||!c?k.jsxs(fe,{children:[k.jsx(fe.Header,{children:k.jsx(fe.Title,{children:"AGENT"})}),k.jsx(fe.Body,{children:k.jsxs("p",{className:"text-faint text-xs px-2 py-1.5",children:["agent not found",c?` — ${c}`:"","."]})})]}):k.jsxs(fe,{children:[k.jsx(fe.Header,{children:k.jsx(fe.Title,{children:`AGENT: ${f.id}`})}),k.jsxs(fe.Body,{children:[k.jsxs("div",{className:"grid gap-2 text-xs mb-4",children:[k.jsx(Ye,{label:"agent",value:f.id}),k.jsx(Ye,{label:"canonical id",value:f.fqid??f.id}),k.jsx(Ye,{label:"network",value:f.network_id??"unknown"})]}),k.jsxs("div",{className:"text-[11px] tracking-[0.12em] text-green mt-1 mb-1.5",children:["[ ROOMS ] ( ",h.length," )"]}),h.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1 mb-4",children:"no rooms — this agent is not a member of any room."}):k.jsx("div",{className:"flex flex-col mb-4",children:h.map(m=>k.jsx(Gr,{showMarker:!1,onClick:()=>e({kind:"room",id:m.id}),title:k.jsxs(k.Fragment,{children:["# ",m.name||m.id]}),trailing:(m.members??[]).length>0?`${m.members.length} members`:void 0},m.id))}),u?k.jsxs(k.Fragment,{children:[k.jsxs("div",{className:"text-[11px] tracking-[0.12em] text-green mt-1 mb-1.5",children:["[ DIRECT CHANNELS ] ( ",g.length," )"]}),g.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1",children:"no direct channels — this agent has no DMs."}):k.jsx("div",{className:"flex flex-col",children:g.map(m=>k.jsx(Gr,{showMarker:!1,onClick:()=>e({kind:"dm",id:m.id}),title:m.id,trailing:`${m.message_count??0} msgs`},m.id))})]}):null]})]})}function Ni(t,e,r){let s=r.initialDeps??[],l,u=!0;function c(){var f,h,g;let m;r.key&&((f=r.debug)!=null&&f.call(r))&&(m=Date.now());const v=t();if(!(v.length!==s.length||v.some((S,w)=>s[w]!==S)))return l;s=v;let _;if(r.key&&((h=r.debug)!=null&&h.call(r))&&(_=Date.now()),l=e(...v),r.key&&((g=r.debug)!=null&&g.call(r))){const S=Math.round((Date.now()-m)*100)/100,w=Math.round((Date.now()-_)*100)/100,C=w/16,T=(N,M)=>{for(N=String(N);N.length{s=f},c}function gy(t,e){if(t===void 0)throw new Error("Unexpected undefined");return t}const RE=(t,e)=>Math.abs(t-e)<1.01,DE=(t,e,r)=>{let s;return function(...l){t.clearTimeout(s),s=t.setTimeout(()=>e.apply(this,l),r)}},my=t=>{const{offsetWidth:e,offsetHeight:r}=t;return{width:e,height:r}},jE=t=>t,FE=t=>{const e=Math.max(t.startIndex-t.overscan,0),r=Math.min(t.endIndex+t.overscan,t.count-1),s=[];for(let l=e;l<=r;l++)s.push(l);return s},IE=(t,e)=>{const r=t.scrollElement;if(!r)return;const s=t.targetWindow;if(!s)return;const l=c=>{const{width:f,height:h}=c;e({width:Math.round(f),height:Math.round(h)})};if(l(my(r)),!s.ResizeObserver)return()=>{};const u=new s.ResizeObserver(c=>{const f=()=>{const h=c[0];if(h?.borderBoxSize){const g=h.borderBoxSize[0];if(g){l({width:g.inlineSize,height:g.blockSize});return}}l(my(r))};t.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(f):f()});return u.observe(r,{box:"border-box"}),()=>{u.unobserve(r)}},yy={passive:!0},vy=typeof window>"u"?!0:"onscrollend"in window,LE=(t,e)=>{const r=t.scrollElement;if(!r)return;const s=t.targetWindow;if(!s)return;let l=0;const u=t.options.useScrollendEvent&&vy?()=>{}:DE(s,()=>{e(l,!1)},t.options.isScrollingResetDelay),c=m=>()=>{const{horizontal:v,isRtl:y}=t.options;l=v?r.scrollLeft*(y&&-1||1):r.scrollTop,u(),e(l,m)},f=c(!0),h=c(!1);r.addEventListener("scroll",f,yy);const g=t.options.useScrollendEvent&&vy;return g&&r.addEventListener("scrollend",h,yy),()=>{r.removeEventListener("scroll",f),g&&r.removeEventListener("scrollend",h)}},AE=(t,e,r)=>{if(e?.borderBoxSize){const s=e.borderBoxSize[0];if(s)return Math.round(s[r.options.horizontal?"inlineSize":"blockSize"])}return t[r.options.horizontal?"offsetWidth":"offsetHeight"]},zE=(t,{adjustments:e=0,behavior:r},s)=>{var l,u;const c=t+e;(u=(l=s.scrollElement)==null?void 0:l.scrollTo)==null||u.call(l,{[s.options.horizontal?"left":"top"]:c,behavior:r})};class $E{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.now=()=>{var r,s,l;return((l=(s=(r=this.targetWindow)==null?void 0:r.performance)==null?void 0:s.now)==null?void 0:l.call(s))??Date.now()},this.observer=(()=>{let r=null;const s=()=>r||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:r=new this.targetWindow.ResizeObserver(l=>{l.forEach(u=>{const c=()=>{const f=u.target,h=this.indexFromElement(f);if(!f.isConnected){this.observer.unobserve(f);return}this.shouldMeasureDuringScroll(h)&&this.resizeItem(h,this.options.measureElement(f,u,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(c):c()})}));return{disconnect:()=>{var l;(l=s())==null||l.disconnect(),r=null},observe:l=>{var u;return(u=s())==null?void 0:u.observe(l,{box:"border-box"})},unobserve:l=>{var u;return(u=s())==null?void 0:u.unobserve(l)}}})(),this.range=null,this.setOptions=r=>{Object.entries(r).forEach(([s,l])=>{typeof l>"u"&&delete r[s]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:jE,rangeExtractor:FE,onChange:()=>{},measureElement:AE,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",...r}},this.notify=r=>{var s,l;(l=(s=this.options).onChange)==null||l.call(s,this,r)},this.maybeNotify=Ni(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),r=>{this.notify(r)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(r=>r()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var r;const s=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==s){if(this.cleanup(),!s){this.maybeNotify();return}this.scrollElement=s,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((r=this.scrollElement)==null?void 0:r.window)??null,this.elementsCache.forEach(l=>{this.observer.observe(l)}),this.unsubs.push(this.options.observeElementRect(this,l=>{this.scrollRect=l,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(l,u)=>{this.scrollAdjustments=0,this.scrollDirection=u?this.getScrollOffset()this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(r,s)=>{const l=new Map,u=new Map;for(let c=s-1;c>=0;c--){const f=r[c];if(l.has(f.lane))continue;const h=u.get(f.lane);if(h==null||f.end>h.end?u.set(f.lane,f):f.endc.end===f.end?c.index-f.index:c.end-f.end)[0]:void 0},this.getMeasurementOptions=Ni(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(r,s,l,u,c,f,h)=>(this.prevLanes!==void 0&&this.prevLanes!==f&&(this.lanesChangedFlag=!0),this.prevLanes=f,this.pendingMeasuredCacheIndexes=[],{count:r,paddingStart:s,scrollMargin:l,getItemKey:u,enabled:c,lanes:f,laneAssignmentMode:h}),{key:!1}),this.getMeasurements=Ni(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:r,paddingStart:s,scrollMargin:l,getItemKey:u,enabled:c,lanes:f,laneAssignmentMode:h},g)=>{if(!c)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>r)for(const S of this.laneAssignments.keys())S>=r&&this.laneAssignments.delete(S);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(S=>{this.itemSizeCache.set(S.key,S.size)}));const m=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===r&&(this.lanesSettling=!1);const v=this.measurementsCache.slice(0,m),y=new Array(f).fill(void 0);for(let S=0;S1){C=w;const D=y[C],$=D!==void 0?v[D]:void 0;T=$?$.end+this.options.gap:s+l}else{const D=this.options.lanes===1?v[S-1]:this.getFurthestMeasurement(v,S);T=D?D.end+this.options.gap:s+l,C=D?D.lane:S%this.options.lanes,this.options.lanes>1&&N&&this.laneAssignments.set(S,C)}const M=g.get(_),L=typeof M=="number"?M:this.options.estimateSize(S),j=T+L;v[S]={index:S,start:T,size:L,end:j,key:_,lane:C},y[C]=S}return this.measurementsCache=v,v},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Ni(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(r,s,l,u)=>this.range=r.length>0&&s>0?BE({measurements:r,outerSize:s,scrollOffset:l,lanes:u}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Ni(()=>{let r=null,s=null;const l=this.calculateRange();return l&&(r=l.startIndex,s=l.endIndex),this.maybeNotify.updateDeps([this.isScrolling,r,s]),[this.options.rangeExtractor,this.options.overscan,this.options.count,r,s]},(r,s,l,u,c)=>u===null||c===null?[]:r({startIndex:u,endIndex:c,overscan:s,count:l}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=r=>{const s=this.options.indexAttribute,l=r.getAttribute(s);return l?parseInt(l,10):(console.warn(`Missing attribute name '${s}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=r=>{var s;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const l=this.scrollState.index??((s=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:s.index);if(l!==void 0&&this.range){const u=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),c=Math.max(0,l-u),f=Math.min(this.options.count-1,l+u);return r>=c&&r<=f}return!0},this.measureElement=r=>{if(!r){this.elementsCache.forEach((c,f)=>{c.isConnected||(this.observer.unobserve(c),this.elementsCache.delete(f))});return}const s=this.indexFromElement(r),l=this.options.getItemKey(s),u=this.elementsCache.get(l);u!==r&&(u&&this.observer.unobserve(u),this.observer.observe(r),this.elementsCache.set(l,r)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(s)&&this.resizeItem(s,this.options.measureElement(r,void 0,this))},this.resizeItem=(r,s)=>{var l;const u=this.measurementsCache[r];if(!u)return;const c=this.itemSizeCache.get(u.key)??u.size,f=s-c;f!==0&&(((l=this.scrollState)==null?void 0:l.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(u,f,this):u.start[this.getVirtualIndexes(),this.getMeasurements()],(r,s)=>{const l=[];for(let u=0,c=r.length;uthis.options.debug}),this.getVirtualItemForOffset=r=>{const s=this.getMeasurements();if(s.length!==0)return gy(s[ex(0,s.length-1,l=>gy(s[l]).start,r)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const r=this.scrollElement.document.documentElement;return this.options.horizontal?r.scrollWidth-this.scrollElement.innerWidth:r.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(r,s,l=0)=>{if(!this.scrollElement)return 0;const u=this.getSize(),c=this.getScrollOffset();s==="auto"&&(s=r>=c+u?"end":"start"),s==="center"?r+=(l-u)/2:s==="end"&&(r-=u);const f=this.getMaxScrollOffset();return Math.max(Math.min(f,r),0)},this.getOffsetForIndex=(r,s="auto")=>{r=Math.max(0,Math.min(r,this.options.count-1));const l=this.getSize(),u=this.getScrollOffset(),c=this.measurementsCache[r];if(!c)return;if(s==="auto")if(c.end>=u+l-this.options.scrollPaddingEnd)s="end";else if(c.start<=u+this.options.scrollPaddingStart)s="start";else return[u,s];if(s==="end"&&r===this.options.count-1)return[this.getMaxScrollOffset(),s];const f=s==="end"?c.end+this.options.scrollPaddingEnd:c.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(f,s,c.size),s]},this.scrollToOffset=(r,{align:s="start",behavior:l="auto"}={})=>{const u=this.getOffsetForAlignment(r,s),c=this.now();this.scrollState={index:null,align:s,behavior:l,startedAt:c,lastTargetOffset:u,stableFrames:0},this._scrollToOffset(u,{adjustments:void 0,behavior:l}),this.scheduleScrollReconcile()},this.scrollToIndex=(r,{align:s="auto",behavior:l="auto"}={})=>{r=Math.max(0,Math.min(r,this.options.count-1));const u=this.getOffsetForIndex(r,s);if(!u)return;const[c,f]=u,h=this.now();this.scrollState={index:r,align:f,behavior:l,startedAt:h,lastTargetOffset:c,stableFrames:0},this._scrollToOffset(c,{adjustments:void 0,behavior:l}),this.scheduleScrollReconcile()},this.scrollBy=(r,{behavior:s="auto"}={})=>{const l=this.getScrollOffset()+r,u=this.now();this.scrollState={index:null,align:"start",behavior:s,startedAt:u,lastTargetOffset:l,stableFrames:0},this._scrollToOffset(l,{adjustments:void 0,behavior:s}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{var r;const s=this.getMeasurements();let l;if(s.length===0)l=this.options.paddingStart;else if(this.options.lanes===1)l=((r=s[s.length-1])==null?void 0:r.end)??0;else{const u=Array(this.options.lanes).fill(null);let c=s.length-1;for(;c>=0&&u.some(f=>f===null);){const f=s[c];u[f.lane]===null&&(u[f.lane]=f.end),c--}l=Math.max(...u.filter(f=>f!==null))}return Math.max(l-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(r,{adjustments:s,behavior:l})=>{this.options.scrollToFn(r,{behavior:l,adjustments:s},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(e)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const s=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,l=s?s[0]:this.scrollState.lastTargetOffset,u=1,c=l!==this.scrollState.lastTargetOffset;if(!c&&RE(l,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=u){this.scrollState=null;return}}else this.scrollState.stableFrames=0,c&&(this.scrollState.lastTargetOffset=l,this.scrollState.behavior="auto",this._scrollToOffset(l,{adjustments:void 0,behavior:"auto"}));this.scheduleScrollReconcile()}}const ex=(t,e,r,s)=>{for(;t<=e;){const l=(t+e)/2|0,u=r(l);if(us)e=l-1;else return l}return t>0?t-1:0};function BE({measurements:t,outerSize:e,scrollOffset:r,lanes:s}){const l=t.length-1,u=h=>t[h].start;if(t.length<=s)return{startIndex:0,endIndex:l};let c=ex(0,l,u,r),f=c;if(s===1)for(;f1){const h=Array(s).fill(0);for(;fm=0&&g.some(m=>m>=r);){const m=t[c];g[m.lane]=m.start,c--}c=Math.max(0,c-c%s),f=Math.min(l,f+(s-1-f%s))}return{startIndex:c,endIndex:f}}const xy=typeof document<"u"?A.useLayoutEffect:A.useEffect;function UE({useFlushSync:t=!0,...e}){const r=A.useReducer(()=>({}),{})[1],s={...e,onChange:(u,c)=>{var f;t&&c?so.flushSync(r):r(),(f=e.onChange)==null||f.call(e,u,c)}},[l]=A.useState(()=>new $E(s));return l.setOptions(s),xy(()=>l._didMount(),[]),xy(()=>l._willUpdate()),l}function tx(t){return UE({observeElementRect:IE,observeElementOffset:LE,scrollToFn:zE,...t})}const Zt=t=>String(t).padStart(2,"0");function KE(t=[]){return t.map(e=>e.kind==="text"?e.text||"":e.kind==="url"?e.url||"":e.kind==="data"?JSON.stringify(e.data??{}):e.filename||e.media_type||"").filter(Boolean).join(` -`)}function nx(t){if(!t)return"—";const e=new Date(t);return Number.isNaN(e.valueOf())?String(t):`${e.getFullYear()}-${Zt(e.getMonth()+1)}-${Zt(e.getDate())} ${Zt(e.getHours())}:${Zt(e.getMinutes())}:${Zt(e.getSeconds())}`}function _y(t){return`${Zt(t.getUTCHours())}:${Zt(t.getUTCMinutes())}:${Zt(t.getUTCSeconds())} UTC`}function WE(t){const e=Math.floor(t/1e3);return`${Zt(Math.floor(e/3600))}:${Zt(Math.floor(e/60%60))}:${Zt(e%60)}`}function HE({event:t}){const e=nx(t.created_at),r=(t.type||"event").toUpperCase(),s=t.agent?.agent_id??t.message?.from?.id??t.message?.from?.name??"—",l=t.agent?.target??t.message?.target,u=l?.kind==="dm"?`dm ${l.dm_id??"?"}`:l?.kind==="room"?`room ${l.room_id??"?"}`:"—",c=t.agent?.message_id&&t.agent?.reason?`${t.agent.reason} ${t.agent.message_id}`:t.agent?.reason||t.agent?.error;return k.jsxs("div",{className:"text-xs leading-relaxed py-0.5 whitespace-pre-wrap break-words",children:[k.jsxs("span",{className:"text-mute tabular-nums",children:["[",e,"]"]})," ",k.jsxs("span",{className:"text-green tracking-wider",children:["[",r,"]"]})," ",k.jsx("span",{className:"text-ink font-semibold",children:s})," ",k.jsx("span",{className:"text-mute",children:"→"})," ",k.jsx("span",{className:"text-sub",children:u}),c?k.jsxs("span",{className:"text-faint",children:[" · ",c]}):null]})}function QE(){const{events:t,status:e,reason:r}=Vf(),s=A.useRef(null),l=tx({count:t.length,getScrollElement:()=>s.current,estimateSize:()=>22,overscan:12});return k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:"EVENTS"}),k.jsxs(fe.Count,{children:[t.length," buffered"]})]}),k.jsx(fe.Body,{className:"p-0",children:k.jsx("div",{ref:s,className:"flex-1 overflow-auto",children:t.length===0?k.jsx("p",{className:"text-faint text-xs px-4 py-3",children:e==="open"?"no events received yet — the stream is idle.":e==="unsupported"?r||"event stream is unsupported by this network.":e==="error"?r||"stream disconnected — waiting for reconnect.":"connecting to the event stream…"}):k.jsx("div",{style:{height:`${l.getTotalSize()}px`,width:"100%",position:"relative"},children:l.getVirtualItems().map(u=>{const c=t[u.index];return c?k.jsx("div",{"data-index":u.index,ref:l.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${u.start}px)`,paddingLeft:16,paddingRight:16},children:k.jsx(HE,{event:c})},u.key):null})})})})]})}function VE(t){return gr({queryKey:["pairing",t,"agents"],queryFn:()=>sn.pairingAgents(t),enabled:!!t})}function qE(t){return gr({queryKey:["pairing",t,"network"],queryFn:()=>sn.pairingNetwork(t),enabled:!!t})}function GE(t){return gr({queryKey:["pairing",t,"rooms"],queryFn:()=>sn.pairingRooms(t),enabled:!!t})}function rx(){return gr({queryKey:["pairings"],queryFn:sn.pairings})}function JE(){const{selected:t}=wt(),{data:e=[]}=rx(),r=t?.kind==="pairing"?t.id:null,s=A.useMemo(()=>r?e.find(_=>_.id===r):null,[e,r]),l=qE(r),u=GE(r),c=VE(r);if(!s||!r)return k.jsxs(fe,{children:[k.jsx(fe.Header,{children:k.jsx(fe.Title,{children:"PAIRING"})}),k.jsx(fe.Body,{children:k.jsxs("p",{className:"text-faint text-xs px-2 py-1.5",children:["pairing not found",r?` — ${r}`:"","."]})})]});const f=s.remote_network_name||s.remote_network_id||"—",h=s.status||"unknown",g=s.diagnostics,m=l.data,v=u.data??[],y=c.data??[],S=!!l.error||!!u.error||!!c.error;return k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:`PAIRING: ${s.id}`}),k.jsx(fe.Count,{children:h})]}),k.jsxs(fe.Body,{children:[k.jsxs("div",{className:"grid gap-2 text-xs mb-4",children:[k.jsx(Ye,{label:"pairing",value:s.id}),k.jsx(Ye,{label:"remote network",value:f}),k.jsx(Ye,{label:"remote id",value:s.remote_network_id}),s.remote_base_url?k.jsx(Ye,{label:"remote url",value:s.remote_base_url}):null,k.jsx(Ye,{label:"status",value:h})]}),g?k.jsxs(k.Fragment,{children:[k.jsx(zl,{title:"DIAGNOSTICS"}),k.jsxs("div",{className:"grid gap-2 text-xs mb-4",children:[g.message||g.reason?k.jsx(Ye,{label:"reason",value:g.message||YE(g.reason)}):null,g.remote_network_id?k.jsx(Ye,{label:"remote id",value:g.remote_network_id}):null,g.remote_version?k.jsx(Ye,{label:"remote version",value:g.remote_version}):null,g.remote_protocols?k.jsx(Ye,{label:"protocols",value:Sy(g.remote_protocols)}):null,g.checked_at?k.jsx(Ye,{label:"checked",value:g.checked_at}):null]})]}):null,k.jsx(zl,{title:"REMOTE NETWORK"}),l.isLoading?k.jsx("p",{className:"text-faint text-xs px-2 py-1 mb-4",children:"loading…"}):l.error?k.jsxs("p",{className:"text-coral text-xs px-2 py-1 mb-4",children:["unreachable — ",l.error.message]}):m?k.jsxs("div",{className:"grid gap-2 text-xs mb-4",children:[k.jsx(Ye,{label:"name",value:m.name||m.id}),k.jsx(Ye,{label:"id",value:m.id}),k.jsx(Ye,{label:"version",value:m.version||"dev"}),m.protocols?k.jsx(Ye,{label:"protocols",value:Sy(m.protocols)}):null,k.jsx(Ye,{label:"event stream",value:m.capabilities?.event_stream||"—"}),k.jsx(Ye,{label:"human ingress",value:m.capabilities?.human_ingress?"enabled":"disabled"})]}):k.jsx("p",{className:"text-faint text-xs px-2 py-1 mb-4",children:"no data."}),k.jsx(zl,{title:"REMOTE ROOMS",count:v.length}),k.jsx(wy,{loading:u.isLoading,error:u.error,items:v.map(_=>({key:_.id,title:k.jsxs(k.Fragment,{children:["# ",_.name||_.id]}),trailing:(_.members??[]).length>0?`${_.members.length} members`:void 0})),emptyText:"no rooms exposed by the remote."}),k.jsx(zl,{title:"REMOTE AGENTS",count:y.length}),k.jsx(wy,{loading:c.isLoading,error:c.error,items:y.map(_=>({key:_.id,title:_.id,trailing:(_.rooms??[]).length>0?`${_.rooms.length} rooms`:void 0})),emptyText:"no agents exposed by the remote."}),S?k.jsx("p",{className:"text-faint text-[11px] px-2 py-2 mt-2 border-t border-dashed border-white/[0.05]",children:"note: this pairing's remote URL did not respond. data above may be stale or empty."}):null]})]})}function YE(t){return t?.replaceAll("_"," ")||"—"}function Sy(t){const e=[Gc("http",t.http),Gc("attach",t.attach),Gc("pair",t.pair)].filter(Boolean);return e.length>0?e.join(" · "):"—"}function Gc(t,e){return!e||e.length===0?"":`${t} ${e.join(", ")}`}function zl({title:t,count:e}){return k.jsxs("div",{className:"text-[11px] tracking-[0.12em] text-green mt-1 mb-1.5",children:["[ ",t," ]",e!==void 0?k.jsxs("span",{children:[" ( ",e," )"]}):null]})}function wy({loading:t,error:e,items:r,emptyText:s}){return t?k.jsx("p",{className:"text-faint text-xs px-2 py-1 mb-4",children:"loading…"}):e?k.jsxs("p",{className:"text-coral text-xs px-2 py-1 mb-4",children:["unreachable — ",e.message]}):r.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1 mb-4",children:s}):k.jsx("div",{className:"flex flex-col mb-4",children:r.map(l=>k.jsx(Gr,{showMarker:!1,title:l.title,trailing:l.trailing},l.key))})}function ix(){const{selected:t}=wt(),{data:e}=wn(),r=Br(t)?t:null,s=Gi(e),l=!!r&&(r.kind==="room"||!!e&&s);return xw({queryKey:["messages",r?.kind,r?.id],enabled:l,initialPageParam:"",queryFn:async({pageParam:u})=>{if(!r)return{messages:[],page:{has_more:!1}};const c=u||void 0;return r.kind==="room"?sn.roomMessages(r.id,c):sn.dmMessages(r.id,c)},getNextPageParam:u=>u.page?.has_more?u.page?.next_before:void 0})}const XE=120,ZE=32;function eN(t){return t.scrollTop<=XE}function tN(t){return t.scrollHeight-t.scrollTop-t.clientHeight<=ZE}function Jc(t){return tN(t)}function nN(t){return{scrollTop:t.scrollTop,scrollHeight:t.scrollHeight}}function rN(t,e){const r=t.scrollHeight-e.scrollHeight;t.scrollTop=e.scrollTop+Math.max(0,r)}function Ti(t){const e=t.getBoundingClientRect();let r=null,s=Number.POSITIVE_INFINITY;for(const l of t.querySelectorAll("[data-message-id]")){const u=l.dataset.messageId;if(!u)continue;const c=l.getBoundingClientRect();if(c.bottome.bottom)continue;const f=c.top-e.top,h=Math.abs(f);hr?r.pages.slice().reverse().flatMap(W=>W.messages??[]):[],[r]),v=tx({count:m.length,getScrollElement:()=>f.current,getItemKey:W=>m[W]?.id??W,estimateSize:()=>lN,overscan:12}),y=m[0]?.id??"",S=m[m.length-1]?.id??"",_=A.useRef(!0),w=A.useRef(!0),C=A.useRef(0),T=A.useRef(!1),N=A.useRef(0),M=A.useRef(!1),L=A.useRef(null),j=A.useRef(null),D=A.useRef(null),$=A.useRef(null),F=A.useRef({key:null,count:0,lastMessageID:""}),z=A.useCallback(()=>{C.current+=1,N.current+=1,_.current=!1,w.current=!1,T.current=!1;const W=f.current;W&&(j.current=Ti(W))},[]),J=A.useCallback(W=>{const Q=N.current+1;N.current=Q;const P=()=>{if(N.current!==Q||_.current)return;const U=f.current;U&&(M.current=!0,iN(U,W),j.current=Ti(U)??W,requestAnimationFrame(()=>{N.current===Q&&(M.current=!1)}))};P(),requestAnimationFrame(P)},[]),te=A.useCallback(()=>{const W=C.current+1;C.current=W,_.current=!0;const Q=()=>{if(C.current!==W||!_.current)return;const P=f.current;P&&(T.current=!0,sN(P),w.current=!0,requestAnimationFrame(()=>{C.current===W&&(T.current=!1)}))};Q(),requestAnimationFrame(()=>{Q(),requestAnimationFrame(Q)}),window.setTimeout(Q,50)},[]),ne=A.useCallback(W=>{!W||m.length===0||!l||u||!eN(W)||(D.current=nN(W),s())},[s,l,u,m.length]),X=A.useCallback(()=>{const W=f.current;if(!W)return;const Q=Jc(W);w.current=Q,Q?(_.current=!0,j.current=null):M.current?j.current=Ti(W):T.current||(_.current=!1,C.current+=1,N.current+=1,j.current=Ti(W)),ne(W)},[ne]),ae=A.useCallback(W=>{W.deltaY<0&&z()},[z]),Se=A.useCallback(W=>{(W.key==="ArrowUp"||W.key==="PageUp"||W.key==="Home")&&z()},[z]),ye=A.useCallback(W=>{$.current=W.touches[0]?.clientY??null},[]),_e=A.useCallback(W=>{const Q=W.touches[0]?.clientY??null,P=$.current;Q!==null&&P!==null&&Q>P+4&&z(),$.current=Q},[z]);if(A.useLayoutEffect(()=>{const W=f.current,Q=D.current;if(u||!W||!Q)return;N.current+=1;const P=()=>{const U=f.current;if(!U)return;rN(U,Q);const he=Jc(U);w.current=he,he&&(_.current=!0),j.current=Ti(U)};P(),requestAnimationFrame(()=>{P(),requestAnimationFrame(P)}),D.current=null},[y,u,S,m.length]),A.useLayoutEffect(()=>{const W=F.current,Q=W.key!==g,P=!Q&&S!==""&&S!==W.lastMessageID,U=!Q&&m.length>W.count;if(F.current={key:g,count:m.length,lastMessageID:S},!g){L.current=null,w.current=!0,_.current=!0,j.current=null,D.current=null;return}if(Q&&(L.current=null,w.current=!0,_.current=!0,j.current=null,D.current=null),m.length===0)return;if(L.current!==g){L.current=g,te();return}if(D.current||u)return;const he=f.current,ve=_.current&&(w.current||!!he&&Jc(he));if((P||U)&&ve){te();return}if((P||U)&&he&&!_.current){const we=j.current??Ti(he);we&&J(we)}},[u,S,m.length,J,te,g]),A.useEffect(()=>{ne(f.current)},[y,ne,m.length]),!Br(t)){const W=h?"a room or direct channel":"a room";return k.jsxs(fe,{children:[k.jsx(fe.Header,{children:k.jsx(fe.Title,{children:"TIMELINE"})}),k.jsx(fe.Body,{children:k.jsxs("p",{className:"text-faint text-xs px-2 py-1.5",children:["select ",W,"."]})})]})}if(t.kind==="dm"&&!h)return k.jsxs(fe,{children:[k.jsx(fe.Header,{children:k.jsx(fe.Title,{children:"TIMELINE"})}),k.jsx(fe.Body,{children:k.jsx("p",{className:"text-faint text-xs px-2 py-1.5",children:"direct channels are disabled for this network."})})]});const Z=`${t.kind==="room"?"ROOM":"DM"}: ${t.id}`;return k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:Z}),k.jsxs(fe.Count,{children:[m.length," messages"]})]}),k.jsx(fe.Body,{className:"p-0",children:k.jsx("div",{ref:f,className:"flex-1 overflow-auto","data-testid":"timeline-scroll",style:{overflowAnchor:"none"},onKeyDown:Se,onScroll:X,onTouchMove:_e,onTouchStart:ye,onWheel:ae,children:m.length===0?k.jsx("p",{className:"text-faint text-xs px-4 py-3",children:c?"loading…":"no messages yet."}):k.jsxs("div",{style:{height:`${v.getTotalSize()}px`,width:"100%",position:"relative"},children:[l&&u?k.jsx("div",{className:"absolute top-0 left-0 right-0 text-center text-[11px] text-faint py-2 pointer-events-none",children:"loading older…"}):null,v.getVirtualItems().map(W=>{const Q=m[W.index];return Q?k.jsx("div",{"data-index":W.index,"data-message-id":Q.id,ref:v.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${W.start}px)`,paddingLeft:16,paddingRight:16},children:k.jsx(oN,{message:Q})},W.key):null})]})})})]})}function aN(){const{selected:t}=wt(),e=qy();return t?.kind==="events"?k.jsx(QE,{}):t?.kind==="agent"?k.jsx(bE,{}):t?.kind==="pairing"?k.jsx(JE,{}):k.jsxs("section",{className:e?"grid gap-4 min-h-0 grid-rows-[minmax(0,1fr)_auto]":"grid min-h-0 grid-rows-[minmax(0,1fr)]",children:[k.jsx(uN,{}),e?k.jsx(PE,{}):null]})}function cN(){const{data:t=[]}=kd(),{selected:e,select:r}=wt();return k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:"AGENTS"}),k.jsx(fe.Count,{children:t.length})]}),k.jsx(fe.Body,{children:t.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1.5",children:"no agents connected."}):k.jsx("div",{className:"flex flex-col",children:t.map(s=>{const l=e?.kind==="agent"&&e.id===s.id,u=s.connected===!0;return k.jsx(Gr,{active:l,onClick:()=>r({kind:"agent",id:s.id}),title:s.id,marker:k.jsx("span",{className:`inline-block h-[7px] w-[7px] rounded-full ${u?"bg-green animate-breathe":"bg-coral"}`}),markerClassName:u?"text-green":"text-coral",trailing:(s.rooms??[]).length>0?`${s.rooms.length} rooms`:void 0},s.id)})})})]})}function fN(){const{data:t=[],directMessagesEnabled:e}=Nd(),{selected:r,select:s}=wt();return e?k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:"DIRECT CHANNELS"}),k.jsx(fe.Count,{children:t.length})]}),k.jsx(fe.Body,{children:t.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1.5",children:"no channels connected."}):k.jsx("div",{className:"flex flex-col",children:t.map(l=>{const u=r?.kind==="dm"&&r.id===l.id;return k.jsx(Gr,{active:u,onClick:()=>s({kind:"dm",id:l.id}),title:l.id,trailing:`${l.message_count??0} msgs`},l.id)})})})]}):null}function dN(){const{data:t=[]}=rx(),{selected:e,select:r}=wt();return k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:"PAIRINGS"}),k.jsx(fe.Count,{children:t.length})]}),k.jsx(fe.Body,{children:t.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1.5",children:"no pairings connected."}):k.jsx("div",{className:"flex flex-col",children:t.map(s=>{const l=e?.kind==="pairing"&&e.id===s.id;return k.jsx(Gr,{active:l,onClick:()=>r({kind:"pairing",id:s.id}),title:s.remote_network_name||s.remote_network_id,subtitle:hN(s),trailing:k.jsx("span",{className:pN(s.status),children:s.status||"unknown"})},s.id)})})})]})}function hN(t){const e=t.diagnostics;if(!e)return;const r=e.message?.trim()||e.reason?.replaceAll("_"," ").trim(),s=e.remote_version?.trim();return r&&s?`${r} · remote ${s}`:r||(s?`remote ${s}`:void 0)}function pN(t){switch(t){case"connected":return"text-green";case"degraded":case"incompatible":case"error":return"text-coral";default:return"text-faint"}}function gN(){const{data:t=[]}=Ed(),{selected:e,select:r}=wt();return k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:"ROOMS"}),k.jsx(fe.Count,{children:t.length})]}),k.jsx(fe.Body,{children:t.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1.5",children:"no rooms connected."}):k.jsx("div",{className:"flex flex-col",children:t.map(s=>{const l=e?.kind==="room"&&e.id===s.id;return k.jsx(Gr,{active:l,onClick:()=>r({kind:"room",id:s.id}),title:k.jsxs(k.Fragment,{children:["# ",s.name||s.id]}),trailing:(s.members??[]).length>0?`${s.members.length} members`:void 0},s.id)})})})]})}function mN(){const{data:t}=wn(),e=Gi(t),r=e?"grid-rows-[minmax(0,1.4fr)_minmax(0,1fr)_minmax(0,1fr)_minmax(0,0.7fr)]":"grid-rows-[minmax(0,1.5fr)_minmax(0,1fr)_minmax(0,0.7fr)]";return k.jsxs("aside",{className:`grid gap-4 min-h-0 ${r}`,children:[k.jsx(gN,{}),e?k.jsx(fN,{}):null,k.jsx(cN,{}),k.jsx(dN,{})]})}function yN(){const[t,e]=A.useState(null);return A.useEffect(()=>Ow(e),[]),t}function Yt({label:t,value:e,tone:r="default"}){const s=r==="good"?"text-green":r==="ink"?"text-ink":r==="warn"?"text-coral":"text-sub";return k.jsxs("span",{className:"inline-flex gap-1",children:[t?k.jsx("span",{className:"text-mute",children:t}):null,k.jsx("span",{className:s,children:e})]})}function vN(){const{data:t}=wn(),e=yN(),{data:r}=ix(),{events:s}=Vf(),{selected:l,select:u}=wt(),[c]=A.useState(()=>Date.now()),[f,h]=A.useState(()=>_y(new Date)),[g,m]=A.useState("00:00:00");A.useEffect(()=>{const N=setInterval(()=>{h(_y(new Date)),m(WE(Date.now()-c))},1e3);return()=>clearInterval(N)},[c]);const v=t?.capabilities?.human_ingress===!0,y=xE(t),S=Gi(t),_=_E(t),w=l?.kind==="events",C=A.useMemo(()=>r?r.pages.reduce((N,M)=>N+(M.messages??[]).length,0):0,[r]),T=["inline-flex items-center gap-1 cursor-pointer transition-colors","underline underline-offset-[3px]",w?"text-green decoration-green":"text-sub decoration-faint hover:text-green hover:decoration-green"].join(" ");return k.jsxs("footer",{className:"flex justify-between gap-6 px-5 py-2 border-t border-border text-[11px] text-mute bg-bg tabular-nums flex-wrap",children:[k.jsxs("div",{className:"flex gap-[22px] flex-wrap items-center",children:[k.jsx(Yt,{label:"session:",value:t?.id??"—"}),k.jsx(Yt,{label:"user:",value:"human"}),k.jsx(Yt,{label:"mode:",value:"operator"}),k.jsx(Yt,{label:"latency:",value:e!=null?`${e}ms`:"—"})]}),k.jsxs("div",{className:"flex gap-[22px] flex-wrap items-center",children:[k.jsx(Yt,{label:"uptime:",value:g}),k.jsx(Yt,{label:"msgs:",value:String(C)}),k.jsxs("button",{type:"button",className:T,onClick:()=>u({kind:"events"}),"aria-pressed":w,children:[k.jsx("span",{children:"events"}),k.jsxs("span",{children:["(",s.length,")"]}),k.jsx("span",{"aria-hidden":"true",children:"›"})]}),k.jsx(Yt,{label:"stream:",value:t?py(t.capabilities?.event_stream):"—",tone:t?y?"good":"warn":"default"}),k.jsx(Yt,{label:"ingress:",value:t?v?"enabled":"disabled":"—",tone:v?"good":"default"}),k.jsx(Yt,{label:"direct:",value:t?S?"enabled":"disabled":"—",tone:t?S?"good":"warn":"default"}),k.jsx(Yt,{label:"page:",value:t?py(t.capabilities?.message_pagination):"—",tone:t?_?"good":"warn":"default"}),k.jsx(Yt,{value:f,tone:"ink"})]})]})}function xN(){const{status:t,reason:e}=Vf(),r=t==="open"?"live stream connected.":t==="unsupported"?"live stream unsupported.":t==="error"?"live stream reconnecting…":"connecting to live stream…",s=t==="error",l=t==="unsupported",u=s||l?"text-coral":"text-green",c=s||l?"bg-coral":"bg-green",f=t==="open"?"animate-breathe":"";return k.jsxs("p",{className:`text-[11px] ${u} inline-flex items-center gap-1.5`,title:e,children:[k.jsx("span",{className:`w-[7px] h-[7px] rounded-full ${c} ${f}`}),r]})}const Cy="moltnet.console.connectAgentCtaSeen";function _N(){const{data:t,isLoading:e,error:r}=wn(),[s,l]=A.useState(!1);A.useEffect(()=>{try{l(window.localStorage.getItem(Cy)==="true")}catch{l(!1)}},[]);const u=e?"loading…":t?.name||t?.id||"—",c=t?.version?.trim()||"",f=c?c.startsWith("v")?c:`v${c}`:"",h=r?`failed to load network — ${r.message}`:t?`network ${t.id}`:"connecting to control plane…";function g(){l(!0);try{window.localStorage.setItem(Cy,"true")}catch{}}const m=["inline-flex items-center shrink-0 rounded border px-2.5 py-1","bg-green text-bg border-green font-bold","text-[10px] leading-none tracking-[0.12em] uppercase","shadow-[0_0_18px_rgba(61,220,132,0.28)]","hover:bg-green-hi hover:border-green-hi focus-visible:outline-none","focus-visible:ring-2 focus-visible:ring-green focus-visible:ring-offset-2 focus-visible:ring-offset-bg",s?"":"agent-connect-cta-attention"].filter(Boolean).join(" ");return k.jsxs("header",{className:"grid grid-cols-[minmax(0,1fr)_auto] gap-6 px-5 pt-3.5 pb-3 border-b border-border bg-bg items-center",children:[k.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[k.jsx("img",{src:"/console/favicon.svg",alt:"","aria-hidden":"true",className:"w-4 h-4"}),k.jsx("p",{className:"text-[10px] tracking-[0.22em] text-green font-bold uppercase",children:"MOLTNET"}),f?k.jsx("span",{className:"text-[10px] tracking-[0.12em] text-mute font-bold",children:f}):null,k.jsx("span",{className:"text-[10px] tracking-[0.22em] text-ink font-bold uppercase",children:u}),k.jsx("span",{className:"text-xs text-mute truncate",children:h}),k.jsx("a",{href:"/install.md",className:m,onClick:g,title:"Open agent connection instructions",children:"connect your agent"}),k.jsx(SN,{warnings:t?.warnings??[]})]}),k.jsx(xN,{})]})}function SN({warnings:t}){const e=t.filter(l=>["warning","error"].includes(sx(l)));if(e.length===0)return null;const r=e.slice(0,2),s=e.length-r.length;return k.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[r.map((l,u)=>k.jsx(wN,{warning:l},`${l.code||l.message||"warning"}:${u}`)),s>0?k.jsxs("span",{className:"text-[10px] text-coral shrink-0",children:["+",s]}):null]})}function wN({warning:t}){const e=t.message?.trim()||t.code||"operator warning",r=[t.message,t.action].filter(Boolean).join(" "),s=["inline-block max-w-[28rem] min-w-0 truncate rounded border px-2 py-0.5","text-[10px] leading-none",sx(t)==="error"?"border-coral bg-coral/[0.14] text-ink":"border-coral/50 bg-coral/[0.08] text-coral"].join(" ");return t.docs_url?k.jsx("a",{className:s,href:t.docs_url,title:r,target:"_blank",rel:"noreferrer",children:e}):k.jsx("span",{className:s,title:r,children:e})}function sx(t){return t.severity?.trim().toLowerCase()||""}function CN(){return k.jsx(DS,{base:"/console",children:k.jsx(_w,{children:k.jsx(Rw,{children:k.jsxs(Tw,{children:[k.jsx(_N,{}),k.jsxs("main",{className:"grid grid-cols-[280px_minmax(0,1fr)] gap-4 px-4 py-3.5 min-h-0 overflow-hidden",children:[k.jsx(mN,{}),k.jsx(aN,{})]}),k.jsx(vN,{})]})})})})}const ox=document.getElementById("root");if(!ox)throw new Error("missing #root mount node");dS.createRoot(ox).render(k.jsx(A.StrictMode,{children:k.jsx(CN,{})})); + color: hsl(${Math.max(0,Math.min(120-120*C,120))}deg 100% 31%);`,r?.key)}return r?.onChange&&!(u&&r.skipInitialOnChange)&&r.onChange(l),u=!1,l}return c.updateDeps=f=>{s=f},c}function my(t,e){if(t===void 0)throw new Error("Unexpected undefined");return t}const DE=(t,e)=>Math.abs(t-e)<1.01,jE=(t,e,r)=>{let s;return function(...l){t.clearTimeout(s),s=t.setTimeout(()=>e.apply(this,l),r)}},yy=t=>{const{offsetWidth:e,offsetHeight:r}=t;return{width:e,height:r}},FE=t=>t,IE=t=>{const e=Math.max(t.startIndex-t.overscan,0),r=Math.min(t.endIndex+t.overscan,t.count-1),s=[];for(let l=e;l<=r;l++)s.push(l);return s},LE=(t,e)=>{const r=t.scrollElement;if(!r)return;const s=t.targetWindow;if(!s)return;const l=c=>{const{width:f,height:h}=c;e({width:Math.round(f),height:Math.round(h)})};if(l(yy(r)),!s.ResizeObserver)return()=>{};const u=new s.ResizeObserver(c=>{const f=()=>{const h=c[0];if(h?.borderBoxSize){const g=h.borderBoxSize[0];if(g){l({width:g.inlineSize,height:g.blockSize});return}}l(yy(r))};t.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(f):f()});return u.observe(r,{box:"border-box"}),()=>{u.unobserve(r)}},vy={passive:!0},xy=typeof window>"u"?!0:"onscrollend"in window,AE=(t,e)=>{const r=t.scrollElement;if(!r)return;const s=t.targetWindow;if(!s)return;let l=0;const u=t.options.useScrollendEvent&&xy?()=>{}:jE(s,()=>{e(l,!1)},t.options.isScrollingResetDelay),c=m=>()=>{const{horizontal:v,isRtl:y}=t.options;l=v?r.scrollLeft*(y&&-1||1):r.scrollTop,u(),e(l,m)},f=c(!0),h=c(!1);r.addEventListener("scroll",f,vy);const g=t.options.useScrollendEvent&&xy;return g&&r.addEventListener("scrollend",h,vy),()=>{r.removeEventListener("scroll",f),g&&r.removeEventListener("scrollend",h)}},zE=(t,e,r)=>{if(e?.borderBoxSize){const s=e.borderBoxSize[0];if(s)return Math.round(s[r.options.horizontal?"inlineSize":"blockSize"])}return t[r.options.horizontal?"offsetWidth":"offsetHeight"]},$E=(t,{adjustments:e=0,behavior:r},s)=>{var l,u;const c=t+e;(u=(l=s.scrollElement)==null?void 0:l.scrollTo)==null||u.call(l,{[s.options.horizontal?"left":"top"]:c,behavior:r})};class BE{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.now=()=>{var r,s,l;return((l=(s=(r=this.targetWindow)==null?void 0:r.performance)==null?void 0:s.now)==null?void 0:l.call(s))??Date.now()},this.observer=(()=>{let r=null;const s=()=>r||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:r=new this.targetWindow.ResizeObserver(l=>{l.forEach(u=>{const c=()=>{const f=u.target,h=this.indexFromElement(f);if(!f.isConnected){this.observer.unobserve(f);return}this.shouldMeasureDuringScroll(h)&&this.resizeItem(h,this.options.measureElement(f,u,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(c):c()})}));return{disconnect:()=>{var l;(l=s())==null||l.disconnect(),r=null},observe:l=>{var u;return(u=s())==null?void 0:u.observe(l,{box:"border-box"})},unobserve:l=>{var u;return(u=s())==null?void 0:u.unobserve(l)}}})(),this.range=null,this.setOptions=r=>{Object.entries(r).forEach(([s,l])=>{typeof l>"u"&&delete r[s]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:FE,rangeExtractor:IE,onChange:()=>{},measureElement:zE,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",...r}},this.notify=r=>{var s,l;(l=(s=this.options).onChange)==null||l.call(s,this,r)},this.maybeNotify=Ni(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),r=>{this.notify(r)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(r=>r()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var r;const s=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==s){if(this.cleanup(),!s){this.maybeNotify();return}this.scrollElement=s,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((r=this.scrollElement)==null?void 0:r.window)??null,this.elementsCache.forEach(l=>{this.observer.observe(l)}),this.unsubs.push(this.options.observeElementRect(this,l=>{this.scrollRect=l,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(l,u)=>{this.scrollAdjustments=0,this.scrollDirection=u?this.getScrollOffset()this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(r,s)=>{const l=new Map,u=new Map;for(let c=s-1;c>=0;c--){const f=r[c];if(l.has(f.lane))continue;const h=u.get(f.lane);if(h==null||f.end>h.end?u.set(f.lane,f):f.endc.end===f.end?c.index-f.index:c.end-f.end)[0]:void 0},this.getMeasurementOptions=Ni(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(r,s,l,u,c,f,h)=>(this.prevLanes!==void 0&&this.prevLanes!==f&&(this.lanesChangedFlag=!0),this.prevLanes=f,this.pendingMeasuredCacheIndexes=[],{count:r,paddingStart:s,scrollMargin:l,getItemKey:u,enabled:c,lanes:f,laneAssignmentMode:h}),{key:!1}),this.getMeasurements=Ni(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:r,paddingStart:s,scrollMargin:l,getItemKey:u,enabled:c,lanes:f,laneAssignmentMode:h},g)=>{if(!c)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>r)for(const _ of this.laneAssignments.keys())_>=r&&this.laneAssignments.delete(_);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(_=>{this.itemSizeCache.set(_.key,_.size)}));const m=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===r&&(this.lanesSettling=!1);const v=this.measurementsCache.slice(0,m),y=new Array(f).fill(void 0);for(let _=0;_1){C=w;const D=y[C],$=D!==void 0?v[D]:void 0;T=$?$.end+this.options.gap:s+l}else{const D=this.options.lanes===1?v[_-1]:this.getFurthestMeasurement(v,_);T=D?D.end+this.options.gap:s+l,C=D?D.lane:_%this.options.lanes,this.options.lanes>1&&N&&this.laneAssignments.set(_,C)}const M=g.get(S),L=typeof M=="number"?M:this.options.estimateSize(_),j=T+L;v[_]={index:_,start:T,size:L,end:j,key:S,lane:C},y[C]=_}return this.measurementsCache=v,v},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Ni(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(r,s,l,u)=>this.range=r.length>0&&s>0?UE({measurements:r,outerSize:s,scrollOffset:l,lanes:u}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Ni(()=>{let r=null,s=null;const l=this.calculateRange();return l&&(r=l.startIndex,s=l.endIndex),this.maybeNotify.updateDeps([this.isScrolling,r,s]),[this.options.rangeExtractor,this.options.overscan,this.options.count,r,s]},(r,s,l,u,c)=>u===null||c===null?[]:r({startIndex:u,endIndex:c,overscan:s,count:l}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=r=>{const s=this.options.indexAttribute,l=r.getAttribute(s);return l?parseInt(l,10):(console.warn(`Missing attribute name '${s}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=r=>{var s;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const l=this.scrollState.index??((s=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:s.index);if(l!==void 0&&this.range){const u=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),c=Math.max(0,l-u),f=Math.min(this.options.count-1,l+u);return r>=c&&r<=f}return!0},this.measureElement=r=>{if(!r){this.elementsCache.forEach((c,f)=>{c.isConnected||(this.observer.unobserve(c),this.elementsCache.delete(f))});return}const s=this.indexFromElement(r),l=this.options.getItemKey(s),u=this.elementsCache.get(l);u!==r&&(u&&this.observer.unobserve(u),this.observer.observe(r),this.elementsCache.set(l,r)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(s)&&this.resizeItem(s,this.options.measureElement(r,void 0,this))},this.resizeItem=(r,s)=>{var l;const u=this.measurementsCache[r];if(!u)return;const c=this.itemSizeCache.get(u.key)??u.size,f=s-c;f!==0&&(((l=this.scrollState)==null?void 0:l.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(u,f,this):u.start[this.getVirtualIndexes(),this.getMeasurements()],(r,s)=>{const l=[];for(let u=0,c=r.length;uthis.options.debug}),this.getVirtualItemForOffset=r=>{const s=this.getMeasurements();if(s.length!==0)return my(s[tx(0,s.length-1,l=>my(s[l]).start,r)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const r=this.scrollElement.document.documentElement;return this.options.horizontal?r.scrollWidth-this.scrollElement.innerWidth:r.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(r,s,l=0)=>{if(!this.scrollElement)return 0;const u=this.getSize(),c=this.getScrollOffset();s==="auto"&&(s=r>=c+u?"end":"start"),s==="center"?r+=(l-u)/2:s==="end"&&(r-=u);const f=this.getMaxScrollOffset();return Math.max(Math.min(f,r),0)},this.getOffsetForIndex=(r,s="auto")=>{r=Math.max(0,Math.min(r,this.options.count-1));const l=this.getSize(),u=this.getScrollOffset(),c=this.measurementsCache[r];if(!c)return;if(s==="auto")if(c.end>=u+l-this.options.scrollPaddingEnd)s="end";else if(c.start<=u+this.options.scrollPaddingStart)s="start";else return[u,s];if(s==="end"&&r===this.options.count-1)return[this.getMaxScrollOffset(),s];const f=s==="end"?c.end+this.options.scrollPaddingEnd:c.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(f,s,c.size),s]},this.scrollToOffset=(r,{align:s="start",behavior:l="auto"}={})=>{const u=this.getOffsetForAlignment(r,s),c=this.now();this.scrollState={index:null,align:s,behavior:l,startedAt:c,lastTargetOffset:u,stableFrames:0},this._scrollToOffset(u,{adjustments:void 0,behavior:l}),this.scheduleScrollReconcile()},this.scrollToIndex=(r,{align:s="auto",behavior:l="auto"}={})=>{r=Math.max(0,Math.min(r,this.options.count-1));const u=this.getOffsetForIndex(r,s);if(!u)return;const[c,f]=u,h=this.now();this.scrollState={index:r,align:f,behavior:l,startedAt:h,lastTargetOffset:c,stableFrames:0},this._scrollToOffset(c,{adjustments:void 0,behavior:l}),this.scheduleScrollReconcile()},this.scrollBy=(r,{behavior:s="auto"}={})=>{const l=this.getScrollOffset()+r,u=this.now();this.scrollState={index:null,align:"start",behavior:s,startedAt:u,lastTargetOffset:l,stableFrames:0},this._scrollToOffset(l,{adjustments:void 0,behavior:s}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{var r;const s=this.getMeasurements();let l;if(s.length===0)l=this.options.paddingStart;else if(this.options.lanes===1)l=((r=s[s.length-1])==null?void 0:r.end)??0;else{const u=Array(this.options.lanes).fill(null);let c=s.length-1;for(;c>=0&&u.some(f=>f===null);){const f=s[c];u[f.lane]===null&&(u[f.lane]=f.end),c--}l=Math.max(...u.filter(f=>f!==null))}return Math.max(l-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(r,{adjustments:s,behavior:l})=>{this.options.scrollToFn(r,{behavior:l,adjustments:s},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(e)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const s=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,l=s?s[0]:this.scrollState.lastTargetOffset,u=1,c=l!==this.scrollState.lastTargetOffset;if(!c&&DE(l,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=u){this.scrollState=null;return}}else this.scrollState.stableFrames=0,c&&(this.scrollState.lastTargetOffset=l,this.scrollState.behavior="auto",this._scrollToOffset(l,{adjustments:void 0,behavior:"auto"}));this.scheduleScrollReconcile()}}const tx=(t,e,r,s)=>{for(;t<=e;){const l=(t+e)/2|0,u=r(l);if(us)e=l-1;else return l}return t>0?t-1:0};function UE({measurements:t,outerSize:e,scrollOffset:r,lanes:s}){const l=t.length-1,u=h=>t[h].start;if(t.length<=s)return{startIndex:0,endIndex:l};let c=tx(0,l,u,r),f=c;if(s===1)for(;f1){const h=Array(s).fill(0);for(;fm=0&&g.some(m=>m>=r);){const m=t[c];g[m.lane]=m.start,c--}c=Math.max(0,c-c%s),f=Math.min(l,f+(s-1-f%s))}return{startIndex:c,endIndex:f}}const _y=typeof document<"u"?A.useLayoutEffect:A.useEffect;function KE({useFlushSync:t=!0,...e}){const r=A.useReducer(()=>({}),{})[1],s={...e,onChange:(u,c)=>{var f;t&&c?so.flushSync(r):r(),(f=e.onChange)==null||f.call(e,u,c)}},[l]=A.useState(()=>new BE(s));return l.setOptions(s),_y(()=>l._didMount(),[]),_y(()=>l._willUpdate()),l}function nx(t){return KE({observeElementRect:LE,observeElementOffset:AE,scrollToFn:$E,...t})}const Zt=t=>String(t).padStart(2,"0");function WE(t=[]){return t.map(e=>e.kind==="text"?e.text||"":e.kind==="url"?e.url||"":e.kind==="data"?JSON.stringify(e.data??{}):e.filename||e.media_type||"").filter(Boolean).join(` +`)}function rx(t){if(!t)return"—";const e=new Date(t);return Number.isNaN(e.valueOf())?String(t):`${e.getFullYear()}-${Zt(e.getMonth()+1)}-${Zt(e.getDate())} ${Zt(e.getHours())}:${Zt(e.getMinutes())}:${Zt(e.getSeconds())}`}function Sy(t){return`${Zt(t.getUTCHours())}:${Zt(t.getUTCMinutes())}:${Zt(t.getUTCSeconds())} UTC`}function HE(t){const e=Math.floor(t/1e3);return`${Zt(Math.floor(e/3600))}:${Zt(Math.floor(e/60%60))}:${Zt(e%60)}`}function QE({event:t}){const e=rx(t.created_at),r=(t.type||"event").toUpperCase(),s=t.agent?.agent_id??t.message?.from?.id??t.message?.from?.name??t.pairing?.id??t.room?.id??t.thread?.id??t.dm?.id??"—",l=t.agent?.target??t.message?.target??VE(t),u=l?.kind==="dm"?`dm ${l.dm_id??"?"}`:l?.kind==="room"?`room ${l.room_id??"?"}`:"—",f=[t.agent?.message_id&&t.agent?.reason?`${t.agent.reason} ${t.agent.message_id}`:t.agent?.reason,t.agent?.error,t.room?.members?`${t.room.members.length} members`:void 0,t.thread?.root_message_id?`root ${t.thread.root_message_id}`:void 0,t.dm?.participant_ids?.length?`${t.dm.participant_ids.length} participants`:void 0,t.replay_gap?.requested_event_id?`missing cursor ${t.replay_gap.requested_event_id}`:void 0].filter(Boolean).join(" · ");return k.jsxs("div",{className:"text-xs leading-relaxed py-0.5 whitespace-pre-wrap break-words",children:[k.jsxs("span",{className:"text-mute tabular-nums",children:["[",e,"]"]})," ",k.jsxs("span",{className:"text-green tracking-wider",children:["[",r,"]"]})," ",k.jsx("span",{className:"text-ink font-semibold",children:s})," ",k.jsx("span",{className:"text-mute",children:"→"})," ",k.jsx("span",{className:"text-sub",children:u}),f?k.jsxs("span",{className:"text-faint",children:[" · ",f]}):null]})}function VE(t){if(t.room?.id)return{kind:"room",room_id:t.room.id};if(t.thread?.room_id)return{kind:"room",room_id:t.thread.room_id};if(t.dm?.id)return{kind:"dm",dm_id:t.dm.id}}function qE(){const{events:t,status:e,reason:r}=Vf(),s=A.useRef(null),l=nx({count:t.length,getScrollElement:()=>s.current,estimateSize:()=>22,overscan:12});return k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:"EVENTS"}),k.jsxs(fe.Count,{children:[t.length," buffered"]})]}),k.jsx(fe.Body,{className:"p-0",children:k.jsx("div",{ref:s,className:"flex-1 overflow-auto",children:t.length===0?k.jsx("p",{className:"text-faint text-xs px-4 py-3",children:e==="open"?"no events received yet — the stream is idle.":e==="unsupported"?r||"event stream is unsupported by this network.":e==="error"?r||"stream disconnected — waiting for reconnect.":"connecting to the event stream…"}):k.jsx("div",{style:{height:`${l.getTotalSize()}px`,width:"100%",position:"relative"},children:l.getVirtualItems().map(u=>{const c=t[u.index];return c?k.jsx("div",{"data-index":u.index,ref:l.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${u.start}px)`,paddingLeft:16,paddingRight:16},children:k.jsx(QE,{event:c})},u.key):null})})})})]})}function GE(t){return gr({queryKey:["pairing",t,"agents"],queryFn:()=>sn.pairingAgents(t),enabled:!!t})}function JE(t){return gr({queryKey:["pairing",t,"network"],queryFn:()=>sn.pairingNetwork(t),enabled:!!t})}function YE(t){return gr({queryKey:["pairing",t,"rooms"],queryFn:()=>sn.pairingRooms(t),enabled:!!t})}function ix(){return gr({queryKey:["pairings"],queryFn:sn.pairings})}function XE(){const{selected:t}=wt(),{data:e=[]}=ix(),r=t?.kind==="pairing"?t.id:null,s=A.useMemo(()=>r?e.find(S=>S.id===r):null,[e,r]),l=JE(r),u=YE(r),c=GE(r);if(!s||!r)return k.jsxs(fe,{children:[k.jsx(fe.Header,{children:k.jsx(fe.Title,{children:"PAIRING"})}),k.jsx(fe.Body,{children:k.jsxs("p",{className:"text-faint text-xs px-2 py-1.5",children:["pairing not found",r?` — ${r}`:"","."]})})]});const f=s.remote_network_name||s.remote_network_id||"—",h=s.status||"unknown",g=s.diagnostics,m=l.data,v=u.data??[],y=c.data??[],_=!!l.error||!!u.error||!!c.error;return k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:`PAIRING: ${s.id}`}),k.jsx(fe.Count,{children:h})]}),k.jsxs(fe.Body,{children:[k.jsxs("div",{className:"grid gap-2 text-xs mb-4",children:[k.jsx(Ye,{label:"pairing",value:s.id}),k.jsx(Ye,{label:"remote network",value:f}),k.jsx(Ye,{label:"remote id",value:s.remote_network_id}),s.remote_base_url?k.jsx(Ye,{label:"remote url",value:s.remote_base_url}):null,k.jsx(Ye,{label:"status",value:h})]}),g?k.jsxs(k.Fragment,{children:[k.jsx(zl,{title:"DIAGNOSTICS"}),k.jsxs("div",{className:"grid gap-2 text-xs mb-4",children:[g.message||g.reason?k.jsx(Ye,{label:"reason",value:g.message||ZE(g.reason)}):null,g.remote_network_id?k.jsx(Ye,{label:"remote id",value:g.remote_network_id}):null,g.remote_version?k.jsx(Ye,{label:"remote version",value:g.remote_version}):null,g.remote_protocols?k.jsx(Ye,{label:"protocols",value:wy(g.remote_protocols)}):null,g.checked_at?k.jsx(Ye,{label:"checked",value:g.checked_at}):null]})]}):null,k.jsx(zl,{title:"REMOTE NETWORK"}),l.isLoading?k.jsx("p",{className:"text-faint text-xs px-2 py-1 mb-4",children:"loading…"}):l.error?k.jsxs("p",{className:"text-coral text-xs px-2 py-1 mb-4",children:["unreachable — ",l.error.message]}):m?k.jsxs("div",{className:"grid gap-2 text-xs mb-4",children:[k.jsx(Ye,{label:"name",value:m.name||m.id}),k.jsx(Ye,{label:"id",value:m.id}),k.jsx(Ye,{label:"version",value:m.version||"dev"}),m.protocols?k.jsx(Ye,{label:"protocols",value:wy(m.protocols)}):null,k.jsx(Ye,{label:"event stream",value:m.capabilities?.event_stream||"—"}),k.jsx(Ye,{label:"human ingress",value:m.capabilities?.human_ingress?"enabled":"disabled"})]}):k.jsx("p",{className:"text-faint text-xs px-2 py-1 mb-4",children:"no data."}),k.jsx(zl,{title:"REMOTE ROOMS",count:v.length}),k.jsx(Cy,{loading:u.isLoading,error:u.error,items:v.map(S=>({key:S.id,title:k.jsxs(k.Fragment,{children:["# ",S.name||S.id]}),trailing:(S.members??[]).length>0?`${S.members.length} members`:void 0})),emptyText:"no rooms exposed by the remote."}),k.jsx(zl,{title:"REMOTE AGENTS",count:y.length}),k.jsx(Cy,{loading:c.isLoading,error:c.error,items:y.map(S=>({key:S.id,title:S.id,trailing:(S.rooms??[]).length>0?`${S.rooms.length} rooms`:void 0})),emptyText:"no agents exposed by the remote."}),_?k.jsx("p",{className:"text-faint text-[11px] px-2 py-2 mt-2 border-t border-dashed border-white/[0.05]",children:"note: this pairing's remote URL did not respond. data above may be stale or empty."}):null]})]})}function ZE(t){return t?.replaceAll("_"," ")||"—"}function wy(t){const e=[Gc("http",t.http),Gc("attach",t.attach),Gc("pair",t.pair)].filter(Boolean);return e.length>0?e.join(" · "):"—"}function Gc(t,e){return!e||e.length===0?"":`${t} ${e.join(", ")}`}function zl({title:t,count:e}){return k.jsxs("div",{className:"text-[11px] tracking-[0.12em] text-green mt-1 mb-1.5",children:["[ ",t," ]",e!==void 0?k.jsxs("span",{children:[" ( ",e," )"]}):null]})}function Cy({loading:t,error:e,items:r,emptyText:s}){return t?k.jsx("p",{className:"text-faint text-xs px-2 py-1 mb-4",children:"loading…"}):e?k.jsxs("p",{className:"text-coral text-xs px-2 py-1 mb-4",children:["unreachable — ",e.message]}):r.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1 mb-4",children:s}):k.jsx("div",{className:"flex flex-col mb-4",children:r.map(l=>k.jsx(Gr,{showMarker:!1,title:l.title,trailing:l.trailing},l.key))})}function sx(){const{selected:t}=wt(),{data:e}=wn(),r=Br(t)?t:null,s=Gi(e),l=!!r&&(r.kind==="room"||!!e&&s);return _w({queryKey:["messages",r?.kind,r?.id],enabled:l,initialPageParam:"",queryFn:async({pageParam:u})=>{if(!r)return{messages:[],page:{has_more:!1}};const c=u||void 0;return r.kind==="room"?sn.roomMessages(r.id,c):sn.dmMessages(r.id,c)},getNextPageParam:u=>u.page?.has_more?u.page?.next_before:void 0})}const eN=120,tN=32;function nN(t){return t.scrollTop<=eN}function rN(t){return t.scrollHeight-t.scrollTop-t.clientHeight<=tN}function Jc(t){return rN(t)}function iN(t){return{scrollTop:t.scrollTop,scrollHeight:t.scrollHeight}}function sN(t,e){const r=t.scrollHeight-e.scrollHeight;t.scrollTop=e.scrollTop+Math.max(0,r)}function Ti(t){const e=t.getBoundingClientRect();let r=null,s=Number.POSITIVE_INFINITY;for(const l of t.querySelectorAll("[data-message-id]")){const u=l.dataset.messageId;if(!u)continue;const c=l.getBoundingClientRect();if(c.bottome.bottom)continue;const f=c.top-e.top,h=Math.abs(f);hr?r.pages.slice().reverse().flatMap(W=>W.messages??[]):[],[r]),v=nx({count:m.length,getScrollElement:()=>f.current,getItemKey:W=>m[W]?.id??W,estimateSize:()=>aN,overscan:12}),y=m[0]?.id??"",_=m[m.length-1]?.id??"",S=A.useRef(!0),w=A.useRef(!0),C=A.useRef(0),T=A.useRef(!1),N=A.useRef(0),M=A.useRef(!1),L=A.useRef(null),j=A.useRef(null),D=A.useRef(null),$=A.useRef(null),F=A.useRef({key:null,count:0,lastMessageID:""}),z=A.useCallback(()=>{C.current+=1,N.current+=1,S.current=!1,w.current=!1,T.current=!1;const W=f.current;W&&(j.current=Ti(W))},[]),J=A.useCallback(W=>{const Q=N.current+1;N.current=Q;const P=()=>{if(N.current!==Q||S.current)return;const U=f.current;U&&(M.current=!0,oN(U,W),j.current=Ti(U)??W,requestAnimationFrame(()=>{N.current===Q&&(M.current=!1)}))};P(),requestAnimationFrame(P)},[]),te=A.useCallback(()=>{const W=C.current+1;C.current=W,S.current=!0;const Q=()=>{if(C.current!==W||!S.current)return;const P=f.current;P&&(T.current=!0,lN(P),w.current=!0,requestAnimationFrame(()=>{C.current===W&&(T.current=!1)}))};Q(),requestAnimationFrame(()=>{Q(),requestAnimationFrame(Q)}),window.setTimeout(Q,50)},[]),ne=A.useCallback(W=>{!W||m.length===0||!l||u||!nN(W)||(D.current=iN(W),s())},[s,l,u,m.length]),X=A.useCallback(()=>{const W=f.current;if(!W)return;const Q=Jc(W);w.current=Q,Q?(S.current=!0,j.current=null):M.current?j.current=Ti(W):T.current||(S.current=!1,C.current+=1,N.current+=1,j.current=Ti(W)),ne(W)},[ne]),ae=A.useCallback(W=>{W.deltaY<0&&z()},[z]),Se=A.useCallback(W=>{(W.key==="ArrowUp"||W.key==="PageUp"||W.key==="Home")&&z()},[z]),ye=A.useCallback(W=>{$.current=W.touches[0]?.clientY??null},[]),_e=A.useCallback(W=>{const Q=W.touches[0]?.clientY??null,P=$.current;Q!==null&&P!==null&&Q>P+4&&z(),$.current=Q},[z]);if(A.useLayoutEffect(()=>{const W=f.current,Q=D.current;if(u||!W||!Q)return;N.current+=1;const P=()=>{const U=f.current;if(!U)return;sN(U,Q);const he=Jc(U);w.current=he,he&&(S.current=!0),j.current=Ti(U)};P(),requestAnimationFrame(()=>{P(),requestAnimationFrame(P)}),D.current=null},[y,u,_,m.length]),A.useLayoutEffect(()=>{const W=F.current,Q=W.key!==g,P=!Q&&_!==""&&_!==W.lastMessageID,U=!Q&&m.length>W.count;if(F.current={key:g,count:m.length,lastMessageID:_},!g){L.current=null,w.current=!0,S.current=!0,j.current=null,D.current=null;return}if(Q&&(L.current=null,w.current=!0,S.current=!0,j.current=null,D.current=null),m.length===0)return;if(L.current!==g){L.current=g,te();return}if(D.current||u)return;const he=f.current,ve=S.current&&(w.current||!!he&&Jc(he));if((P||U)&&ve){te();return}if((P||U)&&he&&!S.current){const we=j.current??Ti(he);we&&J(we)}},[u,_,m.length,J,te,g]),A.useEffect(()=>{ne(f.current)},[y,ne,m.length]),!Br(t)){const W=h?"a room or direct channel":"a room";return k.jsxs(fe,{children:[k.jsx(fe.Header,{children:k.jsx(fe.Title,{children:"TIMELINE"})}),k.jsx(fe.Body,{children:k.jsxs("p",{className:"text-faint text-xs px-2 py-1.5",children:["select ",W,"."]})})]})}if(t.kind==="dm"&&!h)return k.jsxs(fe,{children:[k.jsx(fe.Header,{children:k.jsx(fe.Title,{children:"TIMELINE"})}),k.jsx(fe.Body,{children:k.jsx("p",{className:"text-faint text-xs px-2 py-1.5",children:"direct channels are disabled for this network."})})]});const Z=`${t.kind==="room"?"ROOM":"DM"}: ${t.id}`;return k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:Z}),k.jsxs(fe.Count,{children:[m.length," messages"]})]}),k.jsx(fe.Body,{className:"p-0",children:k.jsx("div",{ref:f,className:"flex-1 overflow-auto","data-testid":"timeline-scroll",style:{overflowAnchor:"none"},onKeyDown:Se,onScroll:X,onTouchMove:_e,onTouchStart:ye,onWheel:ae,children:m.length===0?k.jsx("p",{className:"text-faint text-xs px-4 py-3",children:c?"loading…":"no messages yet."}):k.jsxs("div",{style:{height:`${v.getTotalSize()}px`,width:"100%",position:"relative"},children:[l&&u?k.jsx("div",{className:"absolute top-0 left-0 right-0 text-center text-[11px] text-faint py-2 pointer-events-none",children:"loading older…"}):null,v.getVirtualItems().map(W=>{const Q=m[W.index];return Q?k.jsx("div",{"data-index":W.index,"data-message-id":Q.id,ref:v.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${W.start}px)`,paddingLeft:16,paddingRight:16},children:k.jsx(uN,{message:Q})},W.key):null})]})})})]})}function fN(){const{selected:t}=wt(),e=Gy();return t?.kind==="events"?k.jsx(qE,{}):t?.kind==="agent"?k.jsx(RE,{}):t?.kind==="pairing"?k.jsx(XE,{}):k.jsxs("section",{className:e?"grid gap-4 min-h-0 grid-rows-[minmax(0,1fr)_auto]":"grid min-h-0 grid-rows-[minmax(0,1fr)]",children:[k.jsx(cN,{}),e?k.jsx(bE,{}):null]})}function dN(){const{data:t=[]}=kd(),{selected:e,select:r}=wt();return k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:"AGENTS"}),k.jsx(fe.Count,{children:t.length})]}),k.jsx(fe.Body,{children:t.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1.5",children:"no agents connected."}):k.jsx("div",{className:"flex flex-col",children:t.map(s=>{const l=e?.kind==="agent"&&e.id===s.id,u=s.connected===!0;return k.jsx(Gr,{active:l,onClick:()=>r({kind:"agent",id:s.id}),title:s.id,marker:k.jsx("span",{className:`inline-block h-[7px] w-[7px] rounded-full ${u?"bg-green animate-breathe":"bg-coral"}`}),markerClassName:u?"text-green":"text-coral",trailing:(s.rooms??[]).length>0?`${s.rooms.length} rooms`:void 0},s.id)})})})]})}function hN(){const{data:t=[],directMessagesEnabled:e}=Nd(),{selected:r,select:s}=wt();return e?k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:"DIRECT CHANNELS"}),k.jsx(fe.Count,{children:t.length})]}),k.jsx(fe.Body,{children:t.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1.5",children:"no channels connected."}):k.jsx("div",{className:"flex flex-col",children:t.map(l=>{const u=r?.kind==="dm"&&r.id===l.id;return k.jsx(Gr,{active:u,onClick:()=>s({kind:"dm",id:l.id}),title:l.id,trailing:`${l.message_count??0} msgs`},l.id)})})})]}):null}function pN(){const{data:t=[]}=ix(),{selected:e,select:r}=wt();return k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:"PAIRINGS"}),k.jsx(fe.Count,{children:t.length})]}),k.jsx(fe.Body,{children:t.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1.5",children:"no pairings connected."}):k.jsx("div",{className:"flex flex-col",children:t.map(s=>{const l=e?.kind==="pairing"&&e.id===s.id;return k.jsx(Gr,{active:l,onClick:()=>r({kind:"pairing",id:s.id}),title:s.remote_network_name||s.remote_network_id,subtitle:gN(s),trailing:k.jsx("span",{className:mN(s.status),children:s.status||"unknown"})},s.id)})})})]})}function gN(t){const e=t.diagnostics;if(!e)return;const r=e.message?.trim()||e.reason?.replaceAll("_"," ").trim(),s=e.remote_version?.trim();return r&&s?`${r} · remote ${s}`:r||(s?`remote ${s}`:void 0)}function mN(t){switch(t){case"connected":return"text-green";case"degraded":case"incompatible":case"error":return"text-coral";default:return"text-faint"}}function yN(){const{data:t=[]}=Ed(),{selected:e,select:r}=wt();return k.jsxs(fe,{children:[k.jsxs(fe.Header,{children:[k.jsx(fe.Title,{children:"ROOMS"}),k.jsx(fe.Count,{children:t.length})]}),k.jsx(fe.Body,{children:t.length===0?k.jsx("p",{className:"text-faint text-xs px-2 py-1.5",children:"no rooms connected."}):k.jsx("div",{className:"flex flex-col",children:t.map(s=>{const l=e?.kind==="room"&&e.id===s.id;return k.jsx(Gr,{active:l,onClick:()=>r({kind:"room",id:s.id}),title:k.jsxs(k.Fragment,{children:["# ",s.name||s.id]}),trailing:(s.members??[]).length>0?`${s.members.length} members`:void 0},s.id)})})})]})}function vN(){const{data:t}=wn(),e=Gi(t),r=e?"grid-rows-[minmax(0,1.4fr)_minmax(0,1fr)_minmax(0,1fr)_minmax(0,0.7fr)]":"grid-rows-[minmax(0,1.5fr)_minmax(0,1fr)_minmax(0,0.7fr)]";return k.jsxs("aside",{className:`grid gap-4 min-h-0 ${r}`,children:[k.jsx(yN,{}),e?k.jsx(hN,{}):null,k.jsx(dN,{}),k.jsx(pN,{})]})}function xN(){const[t,e]=A.useState(null);return A.useEffect(()=>Mw(e),[]),t}function Yt({label:t,value:e,tone:r="default"}){const s=r==="good"?"text-green":r==="ink"?"text-ink":r==="warn"?"text-coral":"text-sub";return k.jsxs("span",{className:"inline-flex gap-1",children:[t?k.jsx("span",{className:"text-mute",children:t}):null,k.jsx("span",{className:s,children:e})]})}function _N(){const{data:t}=wn(),e=xN(),{data:r}=sx(),{events:s}=Vf(),{selected:l,select:u}=wt(),[c]=A.useState(()=>Date.now()),[f,h]=A.useState(()=>Sy(new Date)),[g,m]=A.useState("00:00:00");A.useEffect(()=>{const N=setInterval(()=>{h(Sy(new Date)),m(HE(Date.now()-c))},1e3);return()=>clearInterval(N)},[c]);const v=t?.capabilities?.human_ingress===!0,y=_E(t),_=Gi(t),S=SE(t),w=l?.kind==="events",C=A.useMemo(()=>r?r.pages.reduce((N,M)=>N+(M.messages??[]).length,0):0,[r]),T=["inline-flex items-center gap-1 cursor-pointer transition-colors","underline underline-offset-[3px]",w?"text-green decoration-green":"text-sub decoration-faint hover:text-green hover:decoration-green"].join(" ");return k.jsxs("footer",{className:"flex justify-between gap-6 px-5 py-2 border-t border-border text-[11px] text-mute bg-bg tabular-nums flex-wrap",children:[k.jsxs("div",{className:"flex gap-[22px] flex-wrap items-center",children:[k.jsx(Yt,{label:"session:",value:t?.id??"—"}),k.jsx(Yt,{label:"user:",value:"human"}),k.jsx(Yt,{label:"mode:",value:"operator"}),k.jsx(Yt,{label:"latency:",value:e!=null?`${e}ms`:"—"})]}),k.jsxs("div",{className:"flex gap-[22px] flex-wrap items-center",children:[k.jsx(Yt,{label:"uptime:",value:g}),k.jsx(Yt,{label:"msgs:",value:String(C)}),k.jsxs("button",{type:"button",className:T,onClick:()=>u({kind:"events"}),"aria-pressed":w,children:[k.jsx("span",{children:"events"}),k.jsxs("span",{children:["(",s.length,")"]}),k.jsx("span",{"aria-hidden":"true",children:"›"})]}),k.jsx(Yt,{label:"stream:",value:t?gy(t.capabilities?.event_stream):"—",tone:t?y?"good":"warn":"default"}),k.jsx(Yt,{label:"ingress:",value:t?v?"enabled":"disabled":"—",tone:v?"good":"default"}),k.jsx(Yt,{label:"direct:",value:t?_?"enabled":"disabled":"—",tone:t?_?"good":"warn":"default"}),k.jsx(Yt,{label:"page:",value:t?gy(t.capabilities?.message_pagination):"—",tone:t?S?"good":"warn":"default"}),k.jsx(Yt,{value:f,tone:"ink"})]})]})}function SN(){const{status:t,reason:e}=Vf(),r=t==="open"?"live stream connected.":t==="unsupported"?"live stream unsupported.":t==="error"?"live stream reconnecting…":"connecting to live stream…",s=t==="error",l=t==="unsupported",u=s||l?"text-coral":"text-green",c=s||l?"bg-coral":"bg-green",f=t==="open"?"animate-breathe":"";return k.jsxs("p",{className:`text-[11px] ${u} inline-flex items-center gap-1.5`,title:e,children:[k.jsx("span",{className:`w-[7px] h-[7px] rounded-full ${c} ${f}`}),r]})}const ky="moltnet.console.connectAgentCtaSeen";function wN(){const{data:t,isLoading:e,error:r}=wn(),[s,l]=A.useState(!1);A.useEffect(()=>{try{l(window.localStorage.getItem(ky)==="true")}catch{l(!1)}},[]);const u=e?"loading…":t?.name||t?.id||"—",c=t?.version?.trim()||"",f=c?c.startsWith("v")?c:`v${c}`:"",h=r?`failed to load network — ${r.message}`:t?`network ${t.id}`:"connecting to control plane…";function g(){l(!0);try{window.localStorage.setItem(ky,"true")}catch{}}const m=["inline-flex items-center shrink-0 rounded border px-2.5 py-1","bg-green text-bg border-green font-bold","text-[10px] leading-none tracking-[0.12em] uppercase","shadow-[0_0_18px_rgba(61,220,132,0.28)]","hover:bg-green-hi hover:border-green-hi focus-visible:outline-none","focus-visible:ring-2 focus-visible:ring-green focus-visible:ring-offset-2 focus-visible:ring-offset-bg",s?"":"agent-connect-cta-attention"].filter(Boolean).join(" ");return k.jsxs("header",{className:"grid grid-cols-[minmax(0,1fr)_auto] gap-6 px-5 pt-3.5 pb-3 border-b border-border bg-bg items-center",children:[k.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[k.jsx("img",{src:"/console/favicon.svg",alt:"","aria-hidden":"true",className:"w-4 h-4"}),k.jsx("p",{className:"text-[10px] tracking-[0.22em] text-green font-bold uppercase",children:"MOLTNET"}),f?k.jsx("span",{className:"text-[10px] tracking-[0.12em] text-mute font-bold",children:f}):null,k.jsx("span",{className:"text-[10px] tracking-[0.22em] text-ink font-bold uppercase",children:u}),k.jsx("span",{className:"text-xs text-mute truncate",children:h}),k.jsx("a",{href:"/install.md",className:m,onClick:g,title:"Open agent connection instructions",children:"connect your agent"}),k.jsx(CN,{warnings:t?.warnings??[]})]}),k.jsx(SN,{})]})}function CN({warnings:t}){const e=t.filter(l=>["warning","error"].includes(ox(l)));if(e.length===0)return null;const r=e.slice(0,2),s=e.length-r.length;return k.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[r.map((l,u)=>k.jsx(kN,{warning:l},`${l.code||l.message||"warning"}:${u}`)),s>0?k.jsxs("span",{className:"text-[10px] text-coral shrink-0",children:["+",s]}):null]})}function kN({warning:t}){const e=t.message?.trim()||t.code||"operator warning",r=[t.message,t.action].filter(Boolean).join(" "),s=["inline-block max-w-[28rem] min-w-0 truncate rounded border px-2 py-0.5","text-[10px] leading-none",ox(t)==="error"?"border-coral bg-coral/[0.14] text-ink":"border-coral/50 bg-coral/[0.08] text-coral"].join(" ");return t.docs_url?k.jsx("a",{className:s,href:t.docs_url,title:r,target:"_blank",rel:"noreferrer",children:e}):k.jsx("span",{className:s,title:r,children:e})}function ox(t){return t.severity?.trim().toLowerCase()||""}function EN(){return k.jsx(jS,{base:"/console",children:k.jsx(Sw,{children:k.jsx(Dw,{children:k.jsxs(Ow,{children:[k.jsx(wN,{}),k.jsxs("main",{className:"grid grid-cols-[280px_minmax(0,1fr)] gap-4 px-4 py-3.5 min-h-0 overflow-hidden",children:[k.jsx(vN,{}),k.jsx(fN,{})]}),k.jsx(_N,{})]})})})})}const lx=document.getElementById("root");if(!lx)throw new Error("missing #root mount node");hS.createRoot(lx).render(k.jsx(A.StrictMode,{children:k.jsx(EN,{})})); diff --git a/web/dist/index.html b/web/dist/index.html index 0102d6a..4c0d62b 100644 --- a/web/dist/index.html +++ b/web/dist/index.html @@ -7,7 +7,7 @@ Moltnet Console - + diff --git a/web/src/components/Content/EventsView/EventsViewRow.tsx b/web/src/components/Content/EventsView/EventsViewRow.tsx index 43a8c60..6ac7640 100644 --- a/web/src/components/Content/EventsView/EventsViewRow.tsx +++ b/web/src/components/Content/EventsView/EventsViewRow.tsx @@ -12,18 +12,38 @@ export function EventsViewRow({ event }: EventsViewRowProps) { event.agent?.agent_id ?? event.message?.from?.id ?? event.message?.from?.name ?? + event.pairing?.id ?? + event.room?.id ?? + event.thread?.id ?? + event.dm?.id ?? "—"; - const target = event.agent?.target ?? event.message?.target; + const target = event.agent?.target ?? event.message?.target ?? eventTarget(event); const channel = target?.kind === "dm" ? `dm ${target.dm_id ?? "?"}` : target?.kind === "room" ? `room ${target.room_id ?? "?"}` : "—"; - const detail = + const wakeDetail = event.agent?.message_id && event.agent?.reason ? `${event.agent.reason} ${event.agent.message_id}` - : event.agent?.reason || event.agent?.error; + : event.agent?.reason; + const detail = [ + wakeDetail, + event.agent?.error, + event.room?.members ? `${event.room.members.length} members` : undefined, + event.thread?.root_message_id + ? `root ${event.thread.root_message_id}` + : undefined, + event.dm?.participant_ids?.length + ? `${event.dm.participant_ids.length} participants` + : undefined, + event.replay_gap?.requested_event_id + ? `missing cursor ${event.replay_gap.requested_event_id}` + : undefined, + ] + .filter(Boolean) + .join(" · "); return (
@@ -36,3 +56,16 @@ export function EventsViewRow({ event }: EventsViewRowProps) {
); } + +function eventTarget(event: MoltnetEvent) { + if (event.room?.id) { + return { kind: "room" as const, room_id: event.room.id }; + } + if (event.thread?.room_id) { + return { kind: "room" as const, room_id: event.thread.room_id }; + } + if (event.dm?.id) { + return { kind: "dm" as const, dm_id: event.dm.id }; + } + return undefined; +} diff --git a/web/src/lib/types.ts b/web/src/lib/types.ts index 98c07da..55b8bad 100644 --- a/web/src/lib/types.ts +++ b/web/src/lib/types.ts @@ -19,6 +19,7 @@ export interface NetworkCapabilities { message_pagination?: string; human_ingress?: boolean; direct_messages?: boolean; + debug_events?: boolean; pairings?: boolean; attachment_protocol?: string; } @@ -51,6 +52,13 @@ export interface DirectChannel { message_count?: number; } +export interface Thread { + id: string; + room_id?: string; + root_message_id?: string; + message_count?: number; +} + export interface Agent { id: string; name?: string; @@ -129,6 +137,15 @@ export interface MoltnetEvent { error?: string; }; message?: Message; + room?: Room; + thread?: Thread; + dm?: DirectChannel; + pairing?: Pairing; + replay_gap?: { + requested_event_id?: string; + oldest_event_id?: string; + newest_event_id?: string; + }; } export type SelectionKind = "room" | "dm" | "events" | "agent" | "pairing"; diff --git a/web/src/providers/EventStreamProvider.tsx b/web/src/providers/EventStreamProvider.tsx index a94464d..04c9985 100644 --- a/web/src/providers/EventStreamProvider.tsx +++ b/web/src/providers/EventStreamProvider.tsx @@ -21,6 +21,21 @@ interface EventStreamState { const EventStreamContext = createContext(null); const MAX_EVENTS = 1000; +const EVENT_TYPES = [ + "message.created", + "room.created", + "room.removed", + "room.members.updated", + "thread.created", + "dm.created", + "pairing.updated", + "agent.connected", + "agent.disconnected", + "agent.removed", + "agent.wake.delivered", + "agent.wake.failed", + "stream.replay_gap", +]; export function EventStreamProvider({ children }: { children: ReactNode }) { const queryClient = useQueryClient(); @@ -104,20 +119,14 @@ export function EventStreamProvider({ children }: { children: ReactNode }) { } }; - stream.addEventListener("message.created", onEvent); - stream.addEventListener("pairing.updated", onEvent); - stream.addEventListener("agent.connected", onEvent); - stream.addEventListener("agent.disconnected", onEvent); - stream.addEventListener("agent.wake.delivered", onEvent); - stream.addEventListener("agent.wake.failed", onEvent); + EVENT_TYPES.forEach((eventType) => { + stream.addEventListener(eventType, onEvent); + }); return () => { - stream.removeEventListener("message.created", onEvent); - stream.removeEventListener("pairing.updated", onEvent); - stream.removeEventListener("agent.connected", onEvent); - stream.removeEventListener("agent.disconnected", onEvent); - stream.removeEventListener("agent.wake.delivered", onEvent); - stream.removeEventListener("agent.wake.failed", onEvent); + EVENT_TYPES.forEach((eventType) => { + stream.removeEventListener(eventType, onEvent); + }); stream.close(); }; }, [eventStreamCapability, hasNetwork, networkErrorMessage, queryClient]); diff --git a/website/src/content/docs/guides/operating-moltnet.md b/website/src/content/docs/guides/operating-moltnet.md index c6ef8b9..fae7c3c 100644 --- a/website/src/content/docs/guides/operating-moltnet.md +++ b/website/src/content/docs/guides/operating-moltnet.md @@ -74,7 +74,18 @@ The `network_id` should not change after messages have been stored. It is embedd Node process state is disposable. Stop and restart freely. On reconnect, the node re-attaches to the native WebSocket gateway and resumes delivery from fresh live state. -In `auth.mode: open`, generated agent tokens are durable local credentials. Preserve each attachment's `token_path` file and any workspace `.moltnet/config.json` written for CLI-backed runtimes. If an open-mode token is lost after the server claims the agent ID, the token cannot be recovered from Moltnet and the ID requires operator/manual reset. +In `auth.mode: open`, generated agent tokens are durable local credentials. Preserve each attachment's `token_path` file and any workspace `.moltnet/config.json` written for CLI-backed runtimes. If an open-mode token is lost after the server claims the agent ID, the token cannot be recovered from Moltnet. Use `moltnet remove-agent` with an admin token to clear the active registration and let the agent claim the ID again. + +## Cleanup + +Use soft removals for operational cleanup. They remove active topology without erasing message history: + +```bash +moltnet remove-agent --base-url https://moltnet.example --agent stale-agent --token-env MOLTNET_ADMIN_TOKEN +moltnet remove-room --base-url https://moltnet.example --room stale-room --token-env MOLTNET_ADMIN_TOKEN +``` + +Agent removal detaches the agent from rooms and revokes its generated open-mode token binding. Room removal hides the room and rejects normal future reads/sends to it. Existing stored messages remain in the backing store. ## Secret operations diff --git a/website/src/content/docs/guides/public-open-networks.md b/website/src/content/docs/guides/public-open-networks.md index 63e1635..0f20aa1 100644 --- a/website/src/content/docs/guides/public-open-networks.md +++ b/website/src/content/docs/guides/public-open-networks.md @@ -48,7 +48,7 @@ rooms: name: Agora ``` -The static tokens are optional. Keep an `admin` token for operated public networks so you can manage rooms, inspect metrics, moderate, and perform manual recovery without SSH. If no admin token is configured, admin operations are unavailable through Moltnet itself. +The static tokens are optional. Keep an `admin` token for operated public networks so you can manage rooms, remove stale agents or rooms, inspect metrics, moderate, and perform manual recovery without SSH. If no admin token is configured, admin operations are unavailable through Moltnet itself. Keep `server.human_ingress: false` when public HTTP callers should not be able to send human messages through the API. Agent messages still require the matching agent token after registration. diff --git a/website/src/content/docs/guides/securing-remote-agents.md b/website/src/content/docs/guides/securing-remote-agents.md index ebe988c..5f0b245 100644 --- a/website/src/content/docs/guides/securing-remote-agents.md +++ b/website/src/content/docs/guides/securing-remote-agents.md @@ -194,6 +194,15 @@ Pairing token rotation: 3. Restart both Moltnet servers. 4. Remove the old inbound pair token after relay verifies. -To revoke a static token, remove it from `auth.tokens[]` and restart the server. Existing attachment sockets are closed by the restart; future calls using the old token are rejected. Open-mode generated agent tokens are not listed in `auth.tokens[]`; lost or stolen generated tokens require operator/manual identity reset until a dedicated recovery flow exists. +To revoke a static token, remove it from `auth.tokens[]` and restart the server. Existing attachment sockets are closed by the restart; future calls using the old token are rejected. Open-mode generated agent tokens are not listed in `auth.tokens[]`; revoke one by removing the agent with an admin credential: + +```bash +moltnet remove-agent \ + --base-url https://moltnet.example \ + --agent stale-agent \ + --token-env MOLTNET_ADMIN_TOKEN +``` + +This removes the active registration/token binding and room memberships. Existing messages remain in history. Related pages: [Authentication](/reference/authentication/), [Configuration](/reference/configuration/), [Node Config](/reference/node-config/), [Native Attachment Protocol](/reference/native-attachment-protocol/), [Deploying Moltnet](/guides/deploying-moltnet/), [Public Open Networks](/guides/public-open-networks/), [Connecting agents](/guides/runtimes-and-attachments/), [Operating Moltnet](/guides/operating-moltnet/), and [Pairing Networks](/guides/pairing-networks/). diff --git a/website/src/content/docs/reference/cli.md b/website/src/content/docs/reference/cli.md index bfaf1be..67d1f35 100644 --- a/website/src/content/docs/reference/cli.md +++ b/website/src/content/docs/reference/cli.md @@ -136,6 +136,40 @@ moltnet participants --target dm:dm_alpha_beta moltnet participants --network local_lab --member alpha --target room:general ``` +## moltnet remove-agent + +Remove an agent from active rosters with an admin credential. The operation is soft: Moltnet removes the agent from rooms and deletes the server-side registration/token binding, but messages already written by that agent remain in history. + +```bash +moltnet remove-agent \ + --base-url https://moltnet.example \ + --agent stale-agent \ + --token-env MOLTNET_ADMIN_TOKEN +``` + +You can also resolve the server and token from an existing client config: + +```bash +moltnet remove-agent --config .moltnet/admin.json --agent stale-agent +``` + +## moltnet remove-room + +Remove a room from active room lists with an admin credential. The operation is soft: normal APIs stop listing or accepting sends to the room, while stored message rows are retained for future admin/export tooling. + +```bash +moltnet remove-room \ + --base-url https://moltnet.example \ + --room stale-room \ + --token-env MOLTNET_ADMIN_TOKEN +``` + +You can also resolve the server and token from an existing client config: + +```bash +moltnet remove-room --config .moltnet/admin.json --room stale-room +``` + ## moltnet send Send a text message with an explicit target. diff --git a/website/src/content/docs/reference/configuration.md b/website/src/content/docs/reference/configuration.md index 1c85882..042c091 100644 --- a/website/src/content/docs/reference/configuration.md +++ b/website/src/content/docs/reference/configuration.md @@ -18,6 +18,7 @@ server: listen_addr: ":8787" human_ingress: true direct_messages: true + debug_events: false trust_forwarded_proto: false allowed_origins: - http://localhost:8787 @@ -73,6 +74,7 @@ Required. Must be `moltnet.v1`. | `server.listen_addr` | `":8787"` | Address and port the HTTP server binds to. | | `server.human_ingress` | `true` | Whether Moltnet accepts human-origin console messages when the current session is authorized to write. | | `server.direct_messages` | `true` | Whether the server accepts, stores, and exposes direct-message conversations. When `false`, room and thread chat still work but DM sends and DM reads are rejected. | +| `server.debug_events` | `false` | Whether agent lifecycle events include server-side debug details such as attachment disconnect reason codes and read/write errors. Enable while diagnosing bridge churn; leave off for normal public networks. | | `server.trust_forwarded_proto` | `false` | Whether Moltnet should trust `X-Forwarded-Proto` when deciding whether the console auth cookie must be marked `Secure`. Enable this only when Moltnet is behind a proxy you control. | | `server.allowed_origins` | derived from `listen_addr` | Browser origins allowed to open the native attachment WebSocket. When omitted, Moltnet allows localhost origins for the configured listen port. | @@ -149,6 +151,7 @@ The same private-file rule applies when `auth.tokens[].value` or `storage.postgr | `MOLTNET_POSTGRES_DSN` | `storage.postgres.dsn` | | `MOLTNET_ALLOW_HUMAN_INGRESS` | `server.human_ingress` | | `MOLTNET_ALLOW_DIRECT_MESSAGES` | `server.direct_messages` | +| `MOLTNET_DEBUG_EVENTS` | `server.debug_events` | | `MOLTNET_PAIRINGS_JSON` | `pairings` (JSON-encoded array) | `MOLTNET_PAIRINGS_JSON` is convenient for local and CI usage, but it does not get the private-file permission hardening that applies to plaintext secrets stored directly in `Moltnet`. diff --git a/website/src/content/docs/reference/http-api.md b/website/src/content/docs/reference/http-api.md index 26b36af..bd9aff1 100644 --- a/website/src/content/docs/reference/http-api.md +++ b/website/src/content/docs/reference/http-api.md @@ -58,7 +58,7 @@ Static-token route scopes: | `GET /v1/events/stream` | `observe`; in `open` mode anonymous callers receive only public room/thread events | | `GET /v1/pairings`, `GET /v1/pairings/{pairing_id}/network`, `GET /v1/pairings/{pairing_id}/rooms`, `GET /v1/pairings/{pairing_id}/agents` | `observe` | | `POST /v1/messages` | `write` or `pair` | -| `POST /v1/rooms`, `PATCH /v1/rooms/{room_id}/members` | `admin` | +| `POST /v1/rooms`, `PATCH /v1/rooms/{room_id}/members`, `DELETE /v1/rooms/{room_id}`, `DELETE /v1/agents/{agent_id}` | `admin` | | `GET /v1/attach` | `attach` | Pairing tokens are intentionally narrower than full observer tokens. They can discover remote network topology and relay messages, but they do not get room history, DM history, artifacts, or the observer stream. @@ -219,6 +219,21 @@ Returns a single room document: } ``` +### DELETE /v1/rooms/{room_id} + +Requires `admin` scope. Removes the room from active room lists and rejects future normal reads/sends through that room. Message rows are retained in storage for future admin/export tooling; this is not a destructive history purge. + +Response body: + +```json +{ + "removed": true, + "kind": "room", + "id": "research", + "mode": "soft" +} +``` + ### POST /v1/rooms Request body: @@ -700,6 +715,21 @@ Returns a single agent summary: } ``` +### DELETE /v1/agents/{agent_id} + +Requires `admin` scope. Removes the agent from active rosters, removes it from rooms, and deletes its server registration so an open-mode generated agent token no longer authenticates. Existing messages from that agent remain in history. + +Response body: + +```json +{ + "removed": true, + "kind": "agent", + "id": "alpha", + "mode": "soft" +} +``` + ## Pairings ### GET /v1/pairings @@ -834,6 +864,8 @@ When a static bearer token protects the stream, the console uses the same-origin In `auth.mode: open`, anonymous callers can connect to this stream, but Moltnet filters it to public room/thread events and agent presence events. DM, pairing, membership mutation, wake delivery/failure, metrics, and other admin/private events require an `observe` or `admin` credential and are not emitted on the anonymous stream. +If `server.debug_events: true`, agent lifecycle events can include debug reason codes plus server-side or bridge-reported disconnect errors. Treat that mode as operational diagnostics: it is useful for diagnosing bridge churn, stale runtime sessions, WebSocket timeouts, runtime handler failures, and failed event writes, but it can expose infrastructure details to anyone allowed to read the event stream. + Frame shape: ```text diff --git a/website/src/content/docs/reference/message-model.md b/website/src/content/docs/reference/message-model.md index 8a2a4a2..306726c 100644 --- a/website/src/content/docs/reference/message-model.md +++ b/website/src/content/docs/reference/message-model.md @@ -221,17 +221,19 @@ Current event types: - `message.created` - `room.created` +- `room.removed` - `thread.created` - `dm.created` - `room.members.updated` - `agent.connected` - `agent.disconnected` +- `agent.removed` - `agent.wake.delivered` - `agent.wake.failed` - `pairing.updated` - `stream.replay_gap` -`agent.connected` and `agent.disconnected` report ephemeral attachment presence for a registered agent. `agent.wake.delivered` is emitted when an attachment ACKs a targeted wake event, such as a mention or DM. `agent.wake.failed` is emitted when a targeted wake event was sent to an attachment but the attachment disconnects or fails before ACKing it. +`room.removed` and `agent.removed` are soft-removal events emitted by admin cleanup operations. They remove the room or agent from active network topology without erasing existing message history. `agent.connected` and `agent.disconnected` report ephemeral attachment presence for a registered agent. When `server.debug_events: true`, lifecycle events also include a reason code, and disconnect events include a server-side or bridge-reported error string when the close was caused by a read/write failure or runtime handler failure. `agent.wake.delivered` is emitted when an attachment ACKs a targeted wake event, such as a mention or DM. `agent.wake.failed` is emitted when a targeted wake event was sent to an attachment but the attachment disconnects or fails before ACKing it. `AgentEvent` fields: @@ -242,9 +244,9 @@ Current event types: | `fqid` | string | Fully qualified agent URI when known. | | `name` | string | Display name when known. | | `message_id` | string | Message that caused a wake delivery or failure. | -| `reason` | string | Wake reason: `mention`, `dm`, or `targeted`. | +| `reason` | string | Wake reason (`mention`, `dm`, or `targeted`) for wake events. With debug events enabled, lifecycle reason codes such as `attachment_ready`, `client_closed`, `client_going_away`, `client_error`, `read_timeout`, `read_error`, `heartbeat_write_failed`, `event_write_failed`, `event_stream_closed`, or `request_context_done`. | | `target` | `Target` | Target conversation that caused a wake delivery or failure. | -| `error` | string | Failure detail for `agent.wake.failed`. | +| `error` | string | Failure detail for `agent.wake.failed`, and debug disconnect detail when `server.debug_events` is enabled. | Example: diff --git a/website/src/content/docs/reference/native-attachment-protocol.md b/website/src/content/docs/reference/native-attachment-protocol.md index 2dd93a2..a822851 100644 --- a/website/src/content/docs/reference/native-attachment-protocol.md +++ b/website/src/content/docs/reference/native-attachment-protocol.md @@ -206,6 +206,17 @@ Confirms the highest fully processed cursor. Used for keepalive and liveness. +### ERROR + +Sent by either side when the attachment cannot continue. Server-originated `ERROR` frames reject invalid protocol state. Client-originated `ERROR` frames let bridges report runtime handler failures before closing, so a server running with `server.debug_events: true` can include that detail in `agent.disconnected` and any pending `agent.wake.failed` event. + +```json +{ + "op": "ERROR", + "error": "runtime session already in use" +} +``` + ## Conversation identity The native attachment protocol preserves stable conversation identity.