@sobree/core 0.1.32 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -143,6 +143,11 @@ export declare class PaperStack {
143
143
  * flow instead of accumulating inter-fragment margins.
144
144
  */
145
145
  repaginate(): void;
146
+ /** Adapter exposing the DOM-owning steps the repagination orchestrator
147
+ * needs, without making PaperStack's internals public. Caret save/restore
148
+ * is model-based (block id + offset + cell) so it survives the paper
149
+ * rebuild — see `positionMap`'s selection descriptor. */
150
+ private get repaginationHost();
146
151
  /**
147
152
  * One round of consolidate → merge → paginate → distribute.
148
153
  * Re-entrant: each call re-collects blocks from every paper, so the
@@ -0,0 +1,2 @@
1
+ export { MAX_REPAGINATE_RETRIES, OVERFLOW_TOLERANCE_PX, repaginate } from './run';
2
+ export type { RepaginationHost } from './types';
@@ -0,0 +1,31 @@
1
+ import { RepaginationHost } from './types';
2
+ /** Cap on iterative repagination retries. Each iteration shrinks the
3
+ * budget by the observed overflow, so convergence is exponential —
4
+ * 3 is plenty for any realistic doc and prevents accidental infinite
5
+ * loops on pathological content. */
6
+ export declare const MAX_REPAGINATE_RETRIES = 3;
7
+ /** "Is this page actually overflowing enough to warrant a re-pack?"
8
+ * Set to ~one body line — sub-line overflows are visually
9
+ * imperceptible and re-paginating to fix them tends to shift page
10
+ * breaks by a full line elsewhere, drifting AWAY from Word/LibreOffice
11
+ * break points rather than toward them. We only iterate when the
12
+ * overflow exceeds a typical line height. (~28px ≈ 21pt at 12pt
13
+ * body — covers the common case where split-slippage adds a line.) */
14
+ export declare const OVERFLOW_TOLERANCE_PX = 28;
15
+ /**
16
+ * Redistribute blocks across papers until the page set is stable.
17
+ *
18
+ * 1. collect all blocks; if none, ensure one paper, render zones, emit, done.
19
+ * 2. save selection; compute the baseline page-height budget.
20
+ * 3. iterate (bounded by {@link MAX_REPAGINATE_RETRIES}):
21
+ * a. paginate once with the current per-page budgets,
22
+ * b. distribute footnotes (populates per-page zones),
23
+ * c. rebuild per-page budgets from observed footnote-zone heights,
24
+ * d. stop when the budgets are stable AND no paper overflows beyond
25
+ * {@link OVERFLOW_TOLERANCE_PX}.
26
+ * 4. restore selection, render zones, apply per-section settings, emit.
27
+ *
28
+ * Each iteration's shrunken budget reserves footnote space, so the body
29
+ * re-flows to fit; convergence is exponential.
30
+ */
31
+ export declare function repaginate(host: RepaginationHost): void;
@@ -0,0 +1,30 @@
1
+ import { SelectionDescriptor } from '../../editor/internal/positionMap';
2
+ export interface RepaginationHost {
3
+ /** Every block element currently distributed across all papers. */
4
+ collectAllBlocks(): HTMLElement[];
5
+ /** Snapshot the live caret/selection as a model descriptor (block id +
6
+ * offset + cell) that survives the paper DOM rebuild, or null. */
7
+ captureSelection(): SelectionDescriptor | null;
8
+ /** Re-apply a snapshot captured by {@link captureSelection} after the rebuild. */
9
+ restoreSelection(saved: SelectionDescriptor | null): void;
10
+ /** Create or remove papers so there are exactly `count` of them. */
11
+ ensurePaperCount(count: number): void;
12
+ /** The baseline per-page content height budget, in CSS px. */
13
+ pageContentHeightPx(): number;
14
+ /** Run ONE consolidate→merge→paginate→distribute pass at the given
15
+ * baseline budget and per-page height overrides. */
16
+ runPaginationOnce(baselineBudgetPx: number, pageHeights: readonly number[]): void;
17
+ /** Populate each paper's footnote zone from the refs that landed on it. */
18
+ distributeFootnotes(): void;
19
+ /** Per-page budgets after subtracting observed footnote-zone heights;
20
+ * trailing full-baseline entries trimmed (length 0 ⇒ no overrides). */
21
+ footnotePageHeights(baselineBudgetPx: number): number[];
22
+ /** The largest amount (px) any single paper currently overflows by. */
23
+ maxPaperOverflowPx(): number;
24
+ /** Re-render header/footer (and anchor) zones on every paper. */
25
+ renderAllZones(): void;
26
+ /** Apply per-section property overrides (e.g. vertical alignment). */
27
+ applyPerSectionSettings(): void;
28
+ /** Fire the `paginate` event to listeners. */
29
+ emitPaginate(): void;
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sobree/core",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },