@shadow-garden/bapbong-layout-engine 0.1.0

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.
@@ -0,0 +1,73 @@
1
+ import { Node as PMNode } from 'prosemirror-model';
2
+ import type { FlowBlock, FontSpec, LayoutConfig, LayoutImageSegment, LayoutSegment, ResolvedLayout, ResolvedTable } from '@shadow-garden/bapbong-contracts';
3
+ /** Flatten a ProseMirror doc into FlowBlocks (paragraphs + tables). */
4
+ export declare function toFlowBlocks(doc: PMNode, defaultFont?: Partial<FontSpec>, allowFloats?: boolean): FlowBlock[];
5
+ /** A laid-out line whose vertical position is not yet assigned (the page/cell
6
+ * placer fills in `y`). */
7
+ interface LineDraft {
8
+ x: number;
9
+ width: number;
10
+ height: number;
11
+ baseline: number;
12
+ segments: LayoutSegment[];
13
+ images: LayoutImageSegment[];
14
+ from?: number;
15
+ to?: number;
16
+ }
17
+ /** Lay out already-flattened blocks into paginated pages. Pure (no DOM);
18
+ * measurement is injected. */
19
+ export declare function layoutBlocks(blocks: FlowBlock[], config: LayoutConfig): ResolvedLayout;
20
+ interface ParagraphCacheEntry {
21
+ left: number;
22
+ right: number;
23
+ /** Content-start position the cached drafts were computed at. */
24
+ basePos: number;
25
+ /** List marker the drafts were computed with — renumbering invalidates. */
26
+ marker?: string;
27
+ drafts: LineDraft[];
28
+ }
29
+ interface TableCacheEntry {
30
+ left: number;
31
+ right: number;
32
+ /** Table node position the cached layout was computed at. */
33
+ basePos: number;
34
+ /** Canonical layout (y = 0, column-0 x, positions at basePos). Cloned per
35
+ * paint so the placer can mutate (offset/shift/split) without corrupting it. */
36
+ table: ResolvedTable;
37
+ }
38
+ /**
39
+ * Layout cache keyed on ProseMirror node identity (PM keeps unchanged nodes
40
+ * identical across transactions). An unchanged paragraph/table skips
41
+ * measuring/wrapping entirely; one that merely moved gets its positions
42
+ * shifted. Tables that host list paragraphs are not cached (they advance the
43
+ * live numbering counter).
44
+ */
45
+ export declare class LayoutCache {
46
+ readonly paragraphs: WeakMap<PMNode, ParagraphCacheEntry>;
47
+ readonly tables: WeakMap<PMNode, TableCacheEntry>;
48
+ }
49
+ export declare function createLayoutCache(): LayoutCache;
50
+ /** Repeating page furniture passed alongside the body document. `header`/
51
+ * `footer` are the default (odd-page) bands; the `*First`/`*Even` variants
52
+ * apply on page 1 (when `titlePg`) and even pages (when `evenAndOdd`). */
53
+ export interface PageChrome {
54
+ header?: PMNode;
55
+ footer?: PMNode;
56
+ headerFirst?: PMNode;
57
+ footerFirst?: PMNode;
58
+ headerEven?: PMNode;
59
+ footerEven?: PMNode;
60
+ /** w:titlePg — page 1 uses the first variant (blank if none declared). */
61
+ titlePg?: boolean;
62
+ /** w:evenAndOddHeaders — even pages use the even variant (blank if none). */
63
+ evenAndOdd?: boolean;
64
+ }
65
+ /** Lay out a ProseMirror document into paint-ready pages. With a `cache`,
66
+ * only paragraphs whose node changed since the previous call are re-measured.
67
+ * `chrome` (page header/footer documents) repeats on every page; the body
68
+ * band shrinks when a chrome band is taller than the page margin. `footnotes`
69
+ * (note bodies keyed by display number) are laid out at the bottom of the page
70
+ * their reference falls on. */
71
+ export declare function layout(doc: PMNode, config: LayoutConfig, cache?: LayoutCache, chrome?: PageChrome, footnotes?: Record<number, PMNode>): ResolvedLayout;
72
+ export {};
73
+ //# sourceMappingURL=layout-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-engine.d.ts","sourceRoot":"","sources":["../../src/lib/layout-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,IAAI,IAAI,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAMzD,OAAO,KAAK,EAIV,SAAS,EAOT,QAAQ,EAIR,YAAY,EACZ,kBAAkB,EAElB,aAAa,EASb,cAAc,EAEd,aAAa,EAId,MAAM,kCAAkC,CAAC;AA8Q1C,uEAAuE;AACvE,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,WAAW,GAAE,OAAO,C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AM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,6EAA6E;IAC7E,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAgGD;;;;;gCAKgC;AAChC,wBAAgB,MAAM,CACpB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,YAAY,EACpB,KAAK,CAAC,EAAE,WAAW,EACnB,MAAM,CAAC,EAAE,UAAU,EACnB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC,cAAc,CAqIhB"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@shadow-garden/bapbong-layout-engine",
3
+ "version": "0.1.0",
4
+ "description": "bapbong — line-breaking + pagination: ProseMirror doc → ResolvedLayout",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/shadowgarden-app/bapbong.git",
9
+ "directory": "packages/layout-engine"
10
+ },
11
+ "type": "module",
12
+ "main": "./dist/index.cjs",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ "./package.json": "./package.json",
17
+ ".": {
18
+ "@shadow-garden/source": "./src/index.ts",
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs",
22
+ "default": "./dist/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "!**/*.tsbuildinfo"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "nx": {
33
+ "tags": [
34
+ "scope:engine"
35
+ ],
36
+ "targets": {
37
+ "build": {
38
+ "executor": "@nx/esbuild:esbuild",
39
+ "outputs": [
40
+ "{options.outputPath}"
41
+ ],
42
+ "options": {
43
+ "outputPath": "packages/layout-engine/dist",
44
+ "main": "packages/layout-engine/src/index.ts",
45
+ "tsConfig": "packages/layout-engine/tsconfig.lib.json",
46
+ "format": [
47
+ "esm",
48
+ "cjs"
49
+ ],
50
+ "declarationRootDir": "packages/layout-engine/src",
51
+ "external": [
52
+ "@shadow-garden/bapbong-contracts",
53
+ "@shadow-garden/bapbong-model"
54
+ ]
55
+ }
56
+ }
57
+ }
58
+ },
59
+ "dependencies": {
60
+ "prosemirror-model": "^1.25.7",
61
+ "@shadow-garden/bapbong-contracts": "^0.1.0",
62
+ "@shadow-garden/bapbong-model": "^0.1.0"
63
+ }
64
+ }