postext 0.0.1 → 0.0.2
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.
- package/README.md +203 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# postext
|
|
2
|
+
|
|
3
|
+
**A programmable typesetter for the web.**
|
|
4
|
+
|
|
5
|
+
postext is a layout engine that takes semantic content — enriched markdown with referenced resources — and applies professional editorial layout rules to produce publication-grade output. Built on top of [`@chenglou/pretext`](https://github.com/chenglou/pretext) for DOM-free, pixel-perfect text measurement.
|
|
6
|
+
|
|
7
|
+
> **Early stage** — postext is at v0.0.1. The API is under active design and not yet stable.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install postext
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires React >= 18 as a peer dependency.
|
|
16
|
+
|
|
17
|
+
## Quick Example
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { createLayout } from 'postext';
|
|
21
|
+
import type { PostextContent, PostextConfig } from 'postext';
|
|
22
|
+
|
|
23
|
+
const content: PostextContent = {
|
|
24
|
+
markdown: '# My Article\n\nFirst paragraph of the article...',
|
|
25
|
+
resources: [
|
|
26
|
+
{
|
|
27
|
+
id: 'hero',
|
|
28
|
+
type: 'image',
|
|
29
|
+
src: '/images/hero.jpg',
|
|
30
|
+
alt: 'Hero image',
|
|
31
|
+
caption: 'Photo by Jane Doe',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
notes: [
|
|
35
|
+
{
|
|
36
|
+
id: 'note-1',
|
|
37
|
+
type: 'footnote',
|
|
38
|
+
content: 'See the original study for details.',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const config: PostextConfig = {
|
|
44
|
+
columns: 3,
|
|
45
|
+
gutter: '24px',
|
|
46
|
+
typography: {
|
|
47
|
+
orphans: 2,
|
|
48
|
+
widows: 2,
|
|
49
|
+
hyphenation: true,
|
|
50
|
+
},
|
|
51
|
+
references: {
|
|
52
|
+
footnotes: { placement: 'columnBottom', marker: 'number' },
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const Layout = createLayout(content, config);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## With pretext
|
|
60
|
+
|
|
61
|
+
postext is designed to work alongside [`@chenglou/pretext`](https://github.com/chenglou/pretext). **pretext** measures how much space text needs (DOM-free, 300-600x faster than DOM measurement). **postext** uses those measurements to make editorial layout decisions.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { prepare, layout } from '@chenglou/pretext';
|
|
65
|
+
import { createLayout } from 'postext';
|
|
66
|
+
|
|
67
|
+
// pretext: measure text dimensions
|
|
68
|
+
const prepared = prepare(paragraphText, '16px/1.5 Inter');
|
|
69
|
+
const { height } = layout(prepared, columnWidth, 24);
|
|
70
|
+
|
|
71
|
+
// postext: apply layout rules
|
|
72
|
+
const Layout = createLayout(content, config);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API
|
|
76
|
+
|
|
77
|
+
### `createLayout(content, config?)`
|
|
78
|
+
|
|
79
|
+
Returns a React component that renders the laid-out content.
|
|
80
|
+
|
|
81
|
+
| Parameter | Type | Description |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| `content` | `PostextContent` | The semantic content to lay out |
|
|
84
|
+
| `config` | `PostextConfig` | Optional layout configuration |
|
|
85
|
+
|
|
86
|
+
### Types
|
|
87
|
+
|
|
88
|
+
#### `PostextContent`
|
|
89
|
+
|
|
90
|
+
The input content structure.
|
|
91
|
+
|
|
92
|
+
| Field | Type | Description |
|
|
93
|
+
|---|---|---|
|
|
94
|
+
| `markdown` | `string` | Main content in enriched markdown |
|
|
95
|
+
| `resources?` | `PostextResource[]` | Images, tables, figures, pull quotes |
|
|
96
|
+
| `notes?` | `PostextNote[]` | Footnotes, endnotes, margin notes |
|
|
97
|
+
|
|
98
|
+
#### `PostextResource`
|
|
99
|
+
|
|
100
|
+
An embeddable resource referenced within the content.
|
|
101
|
+
|
|
102
|
+
| Field | Type | Description |
|
|
103
|
+
|---|---|---|
|
|
104
|
+
| `id` | `string` | Unique identifier |
|
|
105
|
+
| `type` | `'image' \| 'table' \| 'figure' \| 'pullQuote'` | Resource type |
|
|
106
|
+
| `src?` | `string` | Source URL (for images) |
|
|
107
|
+
| `alt?` | `string` | Alt text |
|
|
108
|
+
| `caption?` | `string` | Caption text |
|
|
109
|
+
| `content?` | `string` | Inline content (for tables/pull quotes) |
|
|
110
|
+
| `width?` | `number` | Width in pixels |
|
|
111
|
+
| `height?` | `number` | Height in pixels |
|
|
112
|
+
|
|
113
|
+
#### `PostextNote`
|
|
114
|
+
|
|
115
|
+
A reference note attached to the content.
|
|
116
|
+
|
|
117
|
+
| Field | Type | Description |
|
|
118
|
+
|---|---|---|
|
|
119
|
+
| `id` | `string` | Unique identifier |
|
|
120
|
+
| `type` | `'footnote' \| 'endnote' \| 'marginNote'` | Note type |
|
|
121
|
+
| `content` | `string` | Note content |
|
|
122
|
+
| `marker?` | `string` | Custom marker (defaults to auto-numbering) |
|
|
123
|
+
|
|
124
|
+
#### `PostextConfig`
|
|
125
|
+
|
|
126
|
+
Top-level layout configuration.
|
|
127
|
+
|
|
128
|
+
| Field | Type | Description |
|
|
129
|
+
|---|---|---|
|
|
130
|
+
| `columns?` | `number` | Number of columns |
|
|
131
|
+
| `gutter?` | `string` | Space between columns (e.g., `'24px'`) |
|
|
132
|
+
| `columnConfig?` | `ColumnConfig` | Detailed column settings |
|
|
133
|
+
| `resourcePlacement?` | `ResourcePlacementConfig` | Resource placement strategy |
|
|
134
|
+
| `typography?` | `TypographyConfig` | Typographic quality rules |
|
|
135
|
+
| `references?` | `ReferenceConfig` | Footnote/endnote/numbering settings |
|
|
136
|
+
| `sectionOverrides?` | `PostextSectionOverride[]` | Per-section rule overrides |
|
|
137
|
+
| `renderer?` | `'web' \| 'pdf'` | Output format |
|
|
138
|
+
|
|
139
|
+
#### `ColumnConfig`
|
|
140
|
+
|
|
141
|
+
| Field | Type | Description |
|
|
142
|
+
|---|---|---|
|
|
143
|
+
| `count?` | `number` | Number of columns |
|
|
144
|
+
| `gutter?` | `string` | Space between columns |
|
|
145
|
+
| `columnRule?` | `{ width?, style?, color? }` | Visual rule between columns |
|
|
146
|
+
| `balancing?` | `boolean` | Equalize column heights |
|
|
147
|
+
|
|
148
|
+
#### `ResourcePlacementConfig`
|
|
149
|
+
|
|
150
|
+
| Field | Type | Description |
|
|
151
|
+
|---|---|---|
|
|
152
|
+
| `defaultStrategy?` | `PlacementStrategy` | Default placement strategy |
|
|
153
|
+
| `deferPlacement?` | `boolean` | Find next available position if resource doesn't fit |
|
|
154
|
+
| `preserveAspectRatio?` | `boolean` | Maintain aspect ratio when sizing |
|
|
155
|
+
|
|
156
|
+
#### `PlacementStrategy`
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
type PlacementStrategy =
|
|
160
|
+
| 'topOfColumn'
|
|
161
|
+
| 'inline'
|
|
162
|
+
| 'floatLeft'
|
|
163
|
+
| 'floatRight'
|
|
164
|
+
| 'fullWidthBreak'
|
|
165
|
+
| 'margin';
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### `TypographyConfig`
|
|
169
|
+
|
|
170
|
+
| Field | Type | Description |
|
|
171
|
+
|---|---|---|
|
|
172
|
+
| `orphans?` | `number` | Min lines at top of column |
|
|
173
|
+
| `widows?` | `number` | Min lines at bottom of column |
|
|
174
|
+
| `hyphenation?` | `boolean` | Enable hyphenation |
|
|
175
|
+
| `ragOptimization?` | `boolean` | Minimize ragged right edges |
|
|
176
|
+
| `spacing?` | `object` | Space before/after headings, figures, block quotes |
|
|
177
|
+
| `keepTogether?` | `object` | Keep heading with paragraph, figure with caption |
|
|
178
|
+
|
|
179
|
+
#### `ReferenceConfig`
|
|
180
|
+
|
|
181
|
+
| Field | Type | Description |
|
|
182
|
+
|---|---|---|
|
|
183
|
+
| `footnotes?` | `{ placement?, marker? }` | Footnote placement and marker style |
|
|
184
|
+
| `figureNumbering?` | `boolean` | Auto-number figures |
|
|
185
|
+
| `tableNumbering?` | `boolean` | Auto-number tables |
|
|
186
|
+
| `marginNotes?` | `boolean` | Enable margin notes |
|
|
187
|
+
|
|
188
|
+
#### `PostextSectionOverride`
|
|
189
|
+
|
|
190
|
+
| Field | Type | Description |
|
|
191
|
+
|---|---|---|
|
|
192
|
+
| `selector` | `string` | CSS selector or content marker |
|
|
193
|
+
| `columns?` | `ColumnConfig` | Column overrides for this section |
|
|
194
|
+
| `typography?` | `TypographyConfig` | Typography overrides |
|
|
195
|
+
| `resourcePlacement?` | `ResourcePlacementConfig` | Placement overrides |
|
|
196
|
+
|
|
197
|
+
## Full Documentation
|
|
198
|
+
|
|
199
|
+
For the project vision, architecture, roadmap, and contributing guidelines, see the [project README](https://github.com/AUsername/postext#readme).
|
|
200
|
+
|
|
201
|
+
## License
|
|
202
|
+
|
|
203
|
+
MIT
|