diff --git a/internal/app/archieui/compose.go b/internal/app/archieui/compose.go index b96d8a687..edb1c0715 100644 --- a/internal/app/archieui/compose.go +++ b/internal/app/archieui/compose.go @@ -76,6 +76,9 @@ func compose(d deps) *webui.Server { // client already carries them: withholding them would degrade two pages // that have an owner, which is a different thing from the intake surfaces // below. + if policies, ok := d.Store.(access.PolicyStore); ok { + srv.Policies = policies + } if presence, ok := d.Store.(storecontract.PresenceStore); ok { srv.Presence = presence } diff --git a/internal/app/statestore/policy_guard.go b/internal/app/statestore/policy_guard.go new file mode 100644 index 000000000..cb9258d50 --- /dev/null +++ b/internal/app/statestore/policy_guard.go @@ -0,0 +1,111 @@ +package statestore + +import ( + "context" + "slices" + + "github.com/samcharles93/archie-core/internal/domain/access" + "github.com/samcharles93/archie-core/internal/domain/identity" + "github.com/samcharles93/archie-core/internal/domain/org" + accessengine "github.com/samcharles93/archie-core/internal/infrastructure/access" +) + +// ownerDirectory is what the guard needs from the store beyond policies. +type ownerDirectory interface { + access.PrincipalSource + ListOrgs(ctx context.Context) ([]org.Org, error) + OrgOwners(ctx context.Context, orgID org.OrgID) ([]identity.IdentityID, error) +} + +// guardedPolicies checks every policy change before it is stored: the text +// must compile against the schema, and the resulting chain must leave each +// org an owner who may still manage its policies. +type guardedPolicies struct { + access.PolicyStore + owners ownerDirectory +} + +func (g guardedPolicies) PutPolicy(ctx context.Context, p access.Policy) (int64, error) { + validator, err := accessengine.New(nil) + if err != nil { + return 0, err + } + if err := validator.Validate(p); err != nil { + return 0, err + } + if err := g.checkLockout(ctx, func(current []access.Policy) []access.Policy { + return append(slices.DeleteFunc(current, func(c access.Policy) bool { return samePolicy(c, p) }), p) + }); err != nil { + return 0, err + } + return g.PolicyStore.PutPolicy(ctx, p) +} + +func (g guardedPolicies) DeletePolicy(ctx context.Context, p access.Policy) error { + if err := g.checkLockout(ctx, func(current []access.Policy) []access.Policy { + return slices.DeleteFunc(current, func(c access.Policy) bool { return samePolicy(c, p) }) + }); err != nil { + return err + } + return g.PolicyStore.DeletePolicy(ctx, p) +} + +func (g guardedPolicies) checkLockout(ctx context.Context, change func([]access.Policy) []access.Policy) error { + current, err := g.ListPolicies(ctx) + if err != nil { + return err + } + engine, err := accessengine.New(change(current)) + if err != nil { + return err + } + orgs, err := g.owners.ListOrgs(ctx) + if err != nil { + return err + } + for _, o := range orgs { + ok, err := g.ownerCanManage(ctx, engine, o.ID) + if err != nil { + return err + } + if !ok { + return access.ErrPolicyLockout + } + } + return nil +} + +func (g guardedPolicies) ownerCanManage(ctx context.Context, engine *accessengine.Engine, orgID org.OrgID) (bool, error) { + owners, err := g.owners.OrgOwners(ctx, orgID) + if err != nil { + return false, err + } + principals := make([]access.Principal, 0, len(owners)+1) + if orgID == org.DefaultOrgID { + principals = append(principals, access.SharedTokenOwner()) + } + for _, id := range owners { + principal, err := g.owners.PrincipalFor(ctx, id) + if err != nil { + return false, err + } + principal.Org = orgID + principals = append(principals, principal) + } + if len(principals) == 0 { + // An org nobody owns cannot be locked out by a policy change. + return true, nil + } + resource := access.Resource{Kind: access.KindPolicy, Org: orgID} + for _, principal := range principals { + if engine.Authorize(principal, access.ActionManagePolicies, resource, access.Context{}).Allowed { + return true, nil + } + } + return false, nil +} + +func samePolicy(a, b access.Policy) bool { + return a.ID == b.ID && a.Level == b.Level && a.OrgID == b.OrgID && + a.WorkspaceID == b.WorkspaceID && a.ObjectKind == b.ObjectKind && a.ObjectID == b.ObjectID +} diff --git a/internal/app/statestore/policy_guard_test.go b/internal/app/statestore/policy_guard_test.go new file mode 100644 index 000000000..74b2e913b --- /dev/null +++ b/internal/app/statestore/policy_guard_test.go @@ -0,0 +1,79 @@ +package statestore + +import ( + "context" + "errors" + "slices" + "testing" + + "github.com/samcharles93/archie-core/internal/domain/access" + "github.com/samcharles93/archie-core/internal/domain/identity" + "github.com/samcharles93/archie-core/internal/domain/org" +) + +type memPolicies struct { + access.PolicyStore + policies []access.Policy +} + +func (m *memPolicies) ListPolicies(context.Context) ([]access.Policy, error) { + return slices.Clone(m.policies), nil +} + +func (m *memPolicies) PutPolicy(_ context.Context, p access.Policy) (int64, error) { + m.policies = append(slices.DeleteFunc(m.policies, func(c access.Policy) bool { return samePolicy(c, p) }), p) + return 1, nil +} + +func (m *memPolicies) DeletePolicy(_ context.Context, p access.Policy) error { + m.policies = slices.DeleteFunc(m.policies, func(c access.Policy) bool { return samePolicy(c, p) }) + return nil +} + +type oneOwnerOrg struct{} + +const testOrg org.OrgID = "default" + +func (oneOwnerOrg) ListOrgs(context.Context) ([]org.Org, error) { return []org.Org{{ID: testOrg}}, nil } + +func (oneOwnerOrg) OrgOwners(context.Context, org.OrgID) ([]identity.IdentityID, error) { + return []identity.IdentityID{"sam"}, nil +} + +func (oneOwnerOrg) PrincipalFor(_ context.Context, id identity.IdentityID) (access.Principal, error) { + return access.Principal{IdentityID: id, Org: testOrg, Memberships: []org.Membership{{IdentityID: id, OrgID: testOrg, Role: org.RoleOwner}}}, nil +} + +func TestPolicyGuard(t *testing.T) { + shipped := access.ShippedOrgPolicies(testOrg) + orgPolicy := func(id, text string) access.Policy { + return access.Policy{ID: id, Level: access.LevelOrg, OrgID: testOrg, Text: text} + } + tests := []struct { + name string + put *access.Policy + delete *access.Policy + want error + }{ + {name: "harmless addition", put: new(orgPolicy("viewers-read", `permit(principal, action == Archie::Action::"read", resource);`))}, + {name: "text that does not compile", put: new(orgPolicy("broken", `permit(principal, action == Archie::Action::"nope", resource);`)), want: access.ErrPolicyInvalidText}, + {name: "forbid locks owners out", put: new(orgPolicy("lock", `forbid(principal, action == Archie::Action::"manage_policies", resource);`)), want: access.ErrPolicyLockout}, + {name: "deleting the owner policy while the admin policy still covers owners", delete: &shipped[3]}, + {name: "deleting the read policy", delete: &shipped[0]}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + store := &memPolicies{policies: slices.Clone(shipped)} + guard := guardedPolicies{PolicyStore: store, owners: oneOwnerOrg{}} + var err error + if tt.put != nil { + _, err = guard.PutPolicy(t.Context(), *tt.put) + } else { + err = guard.DeletePolicy(t.Context(), *tt.delete) + } + if !errors.Is(err, tt.want) { + t.Fatalf("err = %v, want %v", err, tt.want) + } + }) + } +} diff --git a/internal/app/statestore/server.go b/internal/app/statestore/server.go index 9427ea788..b05a864b7 100644 --- a/internal/app/statestore/server.go +++ b/internal/app/statestore/server.go @@ -379,6 +379,9 @@ func (b *server) accessDeps(deps *staterpc.Deps) { } if ps, ok := b.st.(access.PolicyStore); ok { deps.Policies = ps + if owners, ok := b.st.(ownerDirectory); ok { + deps.Policies = guardedPolicies{PolicyStore: ps, owners: owners} + } } if ds, ok := b.st.(access.DenialStore); ok { deps.Denials = ds diff --git a/internal/domain/access/access.go b/internal/domain/access/access.go index 0ff63ee76..bd6ed76f0 100644 --- a/internal/domain/access/access.go +++ b/internal/domain/access/access.go @@ -176,4 +176,7 @@ var ( ErrPolicyNotFound = errors.New("access: policy not found") // ErrPolicyInvalidText is returned when a policy's text does not parse. ErrPolicyInvalidText = errors.New("access: policy text does not parse") + // ErrPolicyLockout is returned when a change would leave an org with no + // owner who may manage its policies. + ErrPolicyLockout = errors.New("access: change leaves no owner able to manage policies") ) diff --git a/internal/domain/access/request.go b/internal/domain/access/request.go index 73997e0f0..12bb5700e 100644 --- a/internal/domain/access/request.go +++ b/internal/domain/access/request.go @@ -150,3 +150,14 @@ type Denial struct { // coalesces identical denials within a minute into one row with a count. Count int64 `json:"count"` } + +// SharedTokenOwner is the principal the single-operator shared token acts as: +// the system identity, owner of the default org, with no membership row. +func SharedTokenOwner() Principal { + return Principal{ + IdentityID: identity.SystemID, + Kind: identity.KindSystem, + Org: org.DefaultOrgID, + Memberships: []org.Membership{{IdentityID: identity.SystemID, OrgID: org.DefaultOrgID, Role: org.RoleOwner}}, + } +} diff --git a/internal/infrastructure/postgres/orgs.go b/internal/infrastructure/postgres/orgs.go index cfdffef4f..6896b5d0f 100644 --- a/internal/infrastructure/postgres/orgs.go +++ b/internal/infrastructure/postgres/orgs.go @@ -264,3 +264,16 @@ func (s *Store) runUpgradePhase(ctx context.Context, name string, stamps []func( } return tx.Commit(ctx) } + +// OrgOwners returns the identities holding the org-wide owner role. +func (s *Store) OrgOwners(ctx context.Context, orgID org.OrgID) ([]identity.IdentityID, error) { + rows, err := s.queries().ListOrgOwners(ctx, string(orgID)) + if err != nil { + return nil, fmt.Errorf("store: list org owners: %w", err) + } + out := make([]identity.IdentityID, 0, len(rows)) + for _, id := range rows { + out = append(out, identity.IdentityID(id)) + } + return out, nil +} diff --git a/internal/infrastructure/postgres/postgresdb/orgs.sql.go b/internal/infrastructure/postgres/postgresdb/orgs.sql.go index f67643b44..439a5f491 100644 --- a/internal/infrastructure/postgres/postgresdb/orgs.sql.go +++ b/internal/infrastructure/postgres/postgresdb/orgs.sql.go @@ -137,6 +137,32 @@ func (q *Queries) ListMembershipsByIdentity(ctx context.Context, identityID stri return items, nil } +const listOrgOwners = `-- name: ListOrgOwners :many +SELECT identity_id FROM memberships +WHERE org_id = $1 AND workspace_id IS NULL AND role = 'owner' +ORDER BY identity_id +` + +func (q *Queries) ListOrgOwners(ctx context.Context, orgID string) ([]string, error) { + rows, err := q.db.Query(ctx, listOrgOwners, orgID) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var identity_id string + if err := rows.Scan(&identity_id); err != nil { + return nil, err + } + items = append(items, identity_id) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const listOrgs = `-- name: ListOrgs :many SELECT id, name, created_at, updated_at FROM orgs ORDER BY created_at, id ` diff --git a/internal/infrastructure/postgres/queries/orgs.sql b/internal/infrastructure/postgres/queries/orgs.sql index 42bc601d8..bf69a4b46 100644 --- a/internal/infrastructure/postgres/queries/orgs.sql +++ b/internal/infrastructure/postgres/queries/orgs.sql @@ -50,3 +50,8 @@ SELECT COALESCE( INSERT INTO memberships (identity_id, org_id, role) SELECT a.identity_id, a.org_id, 'developer' FROM org_agents a ON CONFLICT (identity_id, org_id, COALESCE(workspace_id, '')) DO NOTHING; + +-- name: ListOrgOwners :many +SELECT identity_id FROM memberships +WHERE org_id = $1 AND workspace_id IS NULL AND role = 'owner' +ORDER BY identity_id; diff --git a/internal/infrastructure/staterpc/access.go b/internal/infrastructure/staterpc/access.go index f515e9ac6..e2642af14 100644 --- a/internal/infrastructure/staterpc/access.go +++ b/internal/infrastructure/staterpc/access.go @@ -170,6 +170,9 @@ func accessStatus(err error) error { if errors.Is(err, access.ErrPolicyNotFound) { return status.Error(codes.NotFound, access.ErrPolicyNotFound.Error()) } + if errors.Is(err, access.ErrPolicyInvalidText) { + return status.Error(codes.InvalidArgument, err.Error()) + } if errors.Is(err, access.ErrInvalidPolicy) { return status.Error(codes.InvalidArgument, access.ErrInvalidPolicy.Error()) } diff --git a/internal/infrastructure/staterpc/values.go b/internal/infrastructure/staterpc/values.go index 58d1c82cd..de72f7636 100644 --- a/internal/infrastructure/staterpc/values.go +++ b/internal/infrastructure/staterpc/values.go @@ -13,6 +13,7 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" pb "github.com/samcharles93/archie-core/internal/contracts/state/v1" + "github.com/samcharles93/archie-core/internal/domain/access" "github.com/samcharles93/archie-core/internal/domain/binding" "github.com/samcharles93/archie-core/internal/domain/eventtype" "github.com/samcharles93/archie-core/internal/domain/harnesssecret" @@ -478,6 +479,7 @@ var wireErrors = []struct { message string }{ {storecontract.ErrStaleTransition, codes.FailedPrecondition, msgStaleTransition}, + {access.ErrPolicyLockout, codes.FailedPrecondition, access.ErrPolicyLockout.Error()}, {storecontract.ErrIllegalTransition, codes.FailedPrecondition, msgIllegalTransition}, {storecontract.ErrInvalidStep, codes.InvalidArgument, msgInvalidStep}, {storecontract.ErrBindingOverlap, codes.FailedPrecondition, msgBindingOverlap}, diff --git a/internal/webui/api_access_policies.go b/internal/webui/api_access_policies.go new file mode 100644 index 000000000..cb8d49d0c --- /dev/null +++ b/internal/webui/api_access_policies.go @@ -0,0 +1,97 @@ +package webui + +import ( + "encoding/json" + "errors" + "net/http" + + "github.com/samcharles93/archie-core/internal/domain/access" + "github.com/samcharles93/archie-core/internal/domain/org" +) + +// policyOrg is the org a policy request acts in: the caller's. +func policyOrg(r *http.Request) org.OrgID { + if principal, ok := RequestPrincipal(r.Context()); ok { + return principal.Org + } + return access.SharedTokenOwner().Org +} + +// handleListPolicies lists the caller's org policies at every level an org +// edits. Instance policies span orgs and are not listed. +func (s *Server) handleListPolicies(w http.ResponseWriter, r *http.Request) { + if s.Policies == nil { + http.Error(w, "policies unavailable", http.StatusServiceUnavailable) + return + } + policies, err := s.Policies.ListPolicies(r.Context()) + if err != nil { + writeControlPlaneError(w, err) + return + } + orgID := policyOrg(r) + out := []access.Policy{} + for _, p := range policies { + if p.Level != access.LevelInstance && p.OrgID == orgID { + out = append(out, p) + } + } + writeJSON(w, map[string]any{"policies": out, "shipped": shippedPolicyIDs()}) +} + +func (s *Server) handlePutPolicy(w http.ResponseWriter, r *http.Request) { + p, ok := s.decodePolicy(w, r) + if !ok { + return + } + version, err := s.Policies.PutPolicy(r.Context(), p) + if err != nil { + writePolicyError(w, err) + return + } + writeJSON(w, map[string]int64{"version": version}) +} + +func (s *Server) handleDeletePolicy(w http.ResponseWriter, r *http.Request) { + p, ok := s.decodePolicy(w, r) + if !ok { + return + } + if err := s.Policies.DeletePolicy(r.Context(), p); err != nil { + writePolicyError(w, err) + return + } + w.WriteHeader(http.StatusNoContent) +} + +// decodePolicy reads a policy and pins it to the caller's org: no request +// field chooses the org, and instance policies are not edited here. +func (s *Server) decodePolicy(w http.ResponseWriter, r *http.Request) (access.Policy, bool) { + if s.Policies == nil { + http.Error(w, "policies unavailable", http.StatusServiceUnavailable) + return access.Policy{}, false + } + var p access.Policy + if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, 64<<10)).Decode(&p); err != nil { + http.Error(w, "invalid policy: "+err.Error(), http.StatusBadRequest) + return access.Policy{}, false + } + if p.Level == access.LevelInstance { + http.Error(w, "instance policies are not edited from an org", http.StatusForbidden) + return access.Policy{}, false + } + p.OrgID = policyOrg(r) + return p, true +} + +func writePolicyError(w http.ResponseWriter, err error) { + if errors.Is(err, access.ErrPolicyLockout) { + http.Error(w, err.Error(), http.StatusConflict) + return + } + writeControlPlaneError(w, err) +} + +func shippedPolicyIDs() []string { + return []string{access.PolicyOrgRead, access.PolicyOrgEdit, access.PolicyOrgAdmin, access.PolicyOrgOwner} +} diff --git a/internal/webui/authorize.go b/internal/webui/authorize.go index 94c3fc0f8..667a6d02a 100644 --- a/internal/webui/authorize.go +++ b/internal/webui/authorize.go @@ -7,23 +7,9 @@ import ( "strings" "github.com/samcharles93/archie-core/internal/domain/access" - "github.com/samcharles93/archie-core/internal/domain/identity" "github.com/samcharles93/archie-core/internal/domain/org" ) -// TokenOwnerPrincipal is the principal the shared token acts as: the owner -// of the default org, per the single-operator credential rule. -func TokenOwnerPrincipal() access.Principal { - return access.Principal{ - IdentityID: identity.SystemID, - Kind: identity.KindSystem, - Org: org.DefaultOrgID, - Memberships: []org.Membership{ - {IdentityID: identity.SystemID, OrgID: org.DefaultOrgID, Role: org.RoleOwner}, - }, - } -} - // principalContextKey carries the assembled principal of a request. type principalContextKey struct{} @@ -91,7 +77,7 @@ func (s *Server) requestPrincipal(ctx context.Context) (access.Principal, error) } return s.Principals.PrincipalFor(ctx, acting.ID) } - return TokenOwnerPrincipal(), nil + return access.SharedTokenOwner(), nil } func (s *Server) recordDenial(ctx context.Context, p access.Principal, action access.Action, r access.Resource, decision access.Decision) { @@ -151,6 +137,8 @@ func routeOverride(action access.Action, path string) (access.Action, access.Res return access.ActionApprove, access.KindBinding, segmentValue(path, 2), true case matchSegment(path, "/api/tasks/", "/logs"): return access.ActionReadLogs, access.KindTask, segmentValue(path, 2), true + case matchPrefix(path, "/api/access/policies"): + return policyAction(action), access.KindPolicy, "", true case matchPrefix(path, "/api/identities"): return actionManage(action), access.KindIdentity, segmentValue(path, 2), true case matchPrefix(path, "/api/extensions"): @@ -200,6 +188,14 @@ func kindOf(path string) access.ResourceKind { // actionManage lifts a create or update on a managed surface to the manage // action the role vocabulary carries. +// policyAction lifts every write on the policy routes to manage_policies. +func policyAction(action access.Action) access.Action { + if action == access.ActionRead { + return action + } + return access.ActionManagePolicies +} + func actionManage(action access.Action) access.Action { switch action { case access.ActionCreate, access.ActionUpdate: diff --git a/internal/webui/authorize_test.go b/internal/webui/authorize_test.go index 65e6c9456..a4a937f58 100644 --- a/internal/webui/authorize_test.go +++ b/internal/webui/authorize_test.go @@ -9,9 +9,9 @@ import ( ) // Installing, accepting, enabling or removing an extension runs or stops a -// process on the host, so every extensions route is policy administration, not -// a dashboard read. -func TestExtensionRoutesAreAdministration(t *testing.T) { +// process on the host, and editing a policy changes who may do anything, so +// every write on these routes is policy administration, not a dashboard read. +func TestAdministrationRoutes(t *testing.T) { tests := []struct { method, path string action access.Action @@ -21,6 +21,9 @@ func TestExtensionRoutesAreAdministration(t *testing.T) { {http.MethodPost, "/api/extensions/bws/accept", access.ActionManageIdentities}, {http.MethodPut, "/api/extensions/bws/enabled", access.ActionManageIdentities}, {http.MethodDelete, "/api/extensions/bws", access.ActionDelete}, + {http.MethodGet, "/api/access/policies", access.ActionRead}, + {http.MethodPut, "/api/access/policies", access.ActionManagePolicies}, + {http.MethodDelete, "/api/access/policies", access.ActionManagePolicies}, } for _, tt := range tests { t.Run(tt.method+" "+tt.path, func(t *testing.T) { diff --git a/internal/webui/server.go b/internal/webui/server.go index 47d1e0980..872ff7428 100644 --- a/internal/webui/server.go +++ b/internal/webui/server.go @@ -92,6 +92,10 @@ type Server struct { // Presence lists every service instance's record, behind the services // card. Nil answers 503. Presence storecontract.PresenceStore + + // Policies is the stored access policy chain, behind the policies page. + // Nil answers 503. + Policies access.PolicyStore // now is the clock applyState reads staleness against. Nil means // time.Now; tests set it to pin a record's age. now func() time.Time @@ -289,6 +293,9 @@ func (s *Server) registerConfigAndLogRoutes(mux *http.ServeMux) { mux.HandleFunc("GET /api/control-plane/catalog", s.handleControlPlaneCatalog) mux.HandleFunc("GET /api/control-plane/apply-status", s.handleApplyStatus) mux.HandleFunc("GET /api/services", s.handleServices) + mux.HandleFunc("GET /api/access/policies", s.handleListPolicies) + mux.HandleFunc("PUT /api/access/policies", s.handlePutPolicy) + mux.HandleFunc("DELETE /api/access/policies", s.handleDeletePolicy) mux.HandleFunc("GET /api/control-plane/resources/{kind}", s.handleControlPlaneQuery) mux.HandleFunc("GET /api/control-plane/resources/{kind}/history", s.handleControlPlaneHistory) mux.HandleFunc("POST /api/control-plane/resources/{kind}/commands/{command}", s.handleControlPlaneCommand) diff --git a/ui/dist/assets/index.js b/ui/dist/assets/index.js index 1390fd7a9..35dc1f5d8 100644 --- a/ui/dist/assets/index.js +++ b/ui/dist/assets/index.js @@ -3,7 +3,7 @@ var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],en `&&(e.tagName===`PRE`||e.tagName===`TEXTAREA`)&&(n=n.slice(1));let{textContent:r}=e;r!==n&&r!==n.replace(/\r\n|\r/g,` `)&&(ki(e,0)||yi(),e.textContent=t.children)}if(d){if(_||b||!o||f&48){let t=e.tagName.includes(`-`),i=e.namespaceURI.includes(`svg`)?`svg`:e.namespaceURI.includes(`MathML`)?`mathml`:void 0;for(let a in d)if(_&&(a.endsWith(`value`)||a===`indeterminate`)||s(a)&&!re(a)||a[0]===`.`||t&&!re(a)||u&&u.includes(a)){if(Ei(e,a,d[a]))continue;r(e,a,null,d[a],i,n)}}else if(d.onClick)r(e,`onClick`,null,d.onClick,void 0,n);else if(f&4&&cn(d.style))for(let e in d.style)d.style[e]}let x;(x=d&&d.onVnodeBeforeMount)&&Ms(x,n,t),h&&wr(t,null,n,`beforeMount`),((x=d&&d.onVnodeMounted)||h||l)&&cs(()=>{x&&Ms(x,n,t),l&&g.enter(e),h&&wr(t,null,n,`mounted`)},i)}return e.nextSibling},m=(e,t,r,o,s,c,u)=>{u||=!!t.dynamicChildren;let d=t.children,p=d.length,m=!1;for(let t=0;t
{let{slotScopeIds:c}=t;c&&(i=i?i.concat(c):c);let d=o(e),f=m(a(e),t,d,n,r,i,s);return f&&Ci(f)&&f.data===`]`?a(t.anchor=f):(yi(),l(t.anchor=u(`]`),d,f),f)},g=(e,t,r,i,s,l)=>{if(ji(e,t)||yi(),t.el=null,l){let t=_(e);for(;;){let n=a(e);if(n&&n!==t)c(n);else break}}let u=a(e),d=o(e);return c(e),n(null,t,d,u,r,i,Si(d),s),r&&(r.vnode.el=t.el,xo(r,t.el)),u},_=(e,t=`[`,n=`]`)=>{let r=0;for(;e;)if(e=a(e),e&&Ci(e)&&(e.data===t&&r++,e.data===n)){if(r===0)return a(e);r--}return e},v=(e,t,n)=>{let r=t.parentNode;r&&r.replaceChild(e,t);let i=n;for(;i;)i.vnode.el===t&&(i.vnode.el=i.subTree.el=e),i=i.parent},y=e=>e.nodeType===1&&e.tagName===`TEMPLATE`;return[d,f]}var Ti=new Set([`src`,`srcset`,`href`,`poster`]);function Ei(e,t,n){return Ti.has(t)?e.getAttribute(t)===(n==null?null:`${n}`):!1}var Di=`data-allow-mismatch`,Oi={0:`text`,1:`children`,2:`class`,3:`style`,4:`attribute`};function ki(e,t){if(t===0||t===1)for(;e&&!e.hasAttribute(Di);)e=e.parentElement;return Ai(e&&e.getAttribute(Di),t)}function Ai(e,t){if(e==null)return!1;if(e===``)return!0;{let n=e.split(`,`);return t===0&&n.includes(`children`)?!0:n.includes(Oi[t])}}function ji(e,t){return ki(e.parentElement,1)||Mi(e)||Ni(t)}function Mi(e){return e.nodeType===1&&Ai(e.getAttribute(Di),1)}function Ni({props:e}){let t=e&&e[Di];return typeof t==`string`&&Ai(t,1)}var Pi=ge().requestIdleCallback||(e=>setTimeout(e,1)),Fi=ge().cancelIdleCallback||(e=>clearTimeout(e)),Ii=(e=1e4)=>t=>{let n=Pi(t,{timeout:e});return()=>Fi(n)};function Li(e){let{top:t,left:n,bottom:r,right:i}=e.getBoundingClientRect(),{innerHeight:a,innerWidth:o}=window;return(t>0&&t0&&r0&&n {{ error }}e.slice(1,-1).indexOf(`:`)===-1?void 0:(()=>{let t=e.slice(1,-1),n=t.indexOf(`:`),r=t.slice(0,n);return r?_f+r:void 0})(),xf=e=>{let{theme:t,classGroups:n}=e;return Sf(n,t)},Sf=(e,t)=>{let n=mf();for(let r in e){let i=e[r];Cf(i,n,r,t)}return n},Cf=(e,t,n,r)=>{let i=e.length;for(let a=0;a{if(typeof e==`string`){Tf(e,t,n);return}if(typeof e==`function`){Ef(e,t,n,r);return}Df(e,t,n,r)},Tf=(e,t,n)=>{let r=e===``?t:Of(t,e);r.classGroupId=n},Ef=(e,t,n,r)=>{if(kf(e)){Cf(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(pf(n,e))},Df=(e,t,n,r)=>{let i=Object.entries(e),a=i.length;for(let e=0;e{let n=e,r=t.split(hf),i=r.length;for(let e=0;e`isThemeGetter`in e&&e.isThemeGetter===!0,Af=e=>{if(e<1)return{get:()=>void 0,set:()=>{}};let t=0,n=Object.create(null),r=Object.create(null),i=(i,a)=>{n[i]=a,t++,t>e&&(t=0,r=n,n=Object.create(null))};return{get(e){let t=n[e];if(t!==void 0)return t;if((t=r[e])!==void 0)return i(e,t),t},set(e,t){e in n?n[e]=t:i(e,t)}}},jf=`!`,Mf=`:`,Nf=[],Pf=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),Ff=e=>{let{prefix:t,experimentalParseClassName:n}=e,r=e=>{let t=[],n=0,r=0,i=0,a,o=e.length;for(let s=0;se&&(e.type===`block-map`||e.type===`block-seq`);function NX({composeNode:e,composeEmptyNode:t},n,r,i,a){let o=r.start.source===`{`,s=o?`flow map`:`flow sequence`,c=new((a?.nodeClass)??(o?mY:gY))(n.schema);c.flow=!0;let l=n.atRoot;l&&(n.atRoot=!1),n.atKey&&=!1;let u=r.offset+r.start.source.length;for(let a=0;ae&&(e.type===`block-map`||e.type===`block-seq`);function UX({composeNode:e,composeEmptyNode:t},n,r,i,a){let o=r.start.source===`{`,s=o?`flow map`:`flow sequence`,c=new((a?.nodeClass)??(o?wY:EY))(n.schema);c.flow=!0;let l=n.atRoot;l&&(n.atRoot=!1),n.atKey&&=!1;let u=r.offset+r.start.source.length;for(let a=0;ac&&(c=r.length);else{r.length{{ p.text }}
+