Skip to content
This repository was archived by the owner on Aug 20, 2026. It is now read-only.
This repository was archived by the owner on Aug 20, 2026. It is now read-only.

Re-charter around the package artefact: decompose/flatten with bijection tests, then builder migration #2

Description

@Mearman

Companion to the DocumentPackage promotion (umbrella in ExaDev/document-schema.js#20). This package becomes the migration path and then re-charters around the artefact.

Phase 1 (now): add decompose(pkg: DocumentPackage): PackageNode[] and flatten(nodes): ContentDocument over the current package shape, with the bijection property tests (decompose(flatten(x)) === x and both ways) run over real corpus documents of all five kinds -- these tests are the gate for the whole promotion. Hashing and equality helpers resolve over effective properties so they are stable across serialisation choices. The existing buildOutline stays; it is the TOC projection and can be expressed over decompose's output.

Phase 2 (at promotion): the builder logic migrates into documents.js's package boundary (one implementation, one authority -- no second copy of the grouping semantics); buildOutline deprecates in favour of the boundary's decompose. The package survives as artefact utilities for consumers holding a package JSON without importing the producer: TOC projection, flatten-to-leaves, leaf text, stable content hash -- the small, tree-shakeable dependency shape the edge-runtime consumers are asking for (ExaDev/documents.js#582's read-only pressure).

The grouping semantics (stack behaviour on headingLevel skips, list nesting resets at plain paragraphs, synthetic group labels) are already implemented and reviewed here; phase 2 ports rather than redesigns them, so the bijection tests travel unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions