postext 0.0.2 → 0.0.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Postext contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=createLayout.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createLayout.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/createLayout.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,141 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { createElement } from "react";
3
+ import { createLayout } from "../createLayout";
4
+ describe("createLayout", () => {
5
+ const minimalContent = {
6
+ markdown: "# Hello\n\nA paragraph of text.",
7
+ };
8
+ it("returns a React function component", () => {
9
+ const Layout = createLayout(minimalContent);
10
+ expect(typeof Layout).toBe("function");
11
+ });
12
+ it("returned component has displayName 'PostextLayout'", () => {
13
+ const Layout = createLayout(minimalContent);
14
+ expect(Layout.displayName).toBe("PostextLayout");
15
+ });
16
+ it("returned component renders without throwing", () => {
17
+ const Layout = createLayout(minimalContent);
18
+ // createElement exercises the component function
19
+ expect(() => createElement(Layout)).not.toThrow();
20
+ });
21
+ it("accepts content with resources", () => {
22
+ const content = {
23
+ markdown: "# Article\n\nSome text with a figure reference.",
24
+ resources: [
25
+ {
26
+ id: "fig-1",
27
+ type: "image",
28
+ src: "/photo.jpg",
29
+ alt: "A photo",
30
+ caption: "Figure 1",
31
+ width: 800,
32
+ height: 600,
33
+ },
34
+ {
35
+ id: "tbl-1",
36
+ type: "table",
37
+ content: "| A | B |\n|---|---|\n| 1 | 2 |",
38
+ },
39
+ {
40
+ id: "pq-1",
41
+ type: "pullQuote",
42
+ content: "A compelling quote.",
43
+ },
44
+ ],
45
+ };
46
+ const Layout = createLayout(content);
47
+ expect(Layout.displayName).toBe("PostextLayout");
48
+ });
49
+ it("accepts content with notes", () => {
50
+ const content = {
51
+ markdown: "Text with a footnote reference.",
52
+ notes: [
53
+ { id: "fn-1", type: "footnote", content: "A footnote.", marker: "1" },
54
+ { id: "en-1", type: "endnote", content: "An endnote." },
55
+ { id: "mn-1", type: "marginNote", content: "A margin note." },
56
+ ],
57
+ };
58
+ const Layout = createLayout(content);
59
+ expect(Layout.displayName).toBe("PostextLayout");
60
+ });
61
+ it("accepts a full config object", () => {
62
+ const config = {
63
+ columns: 2,
64
+ gutter: "2rem",
65
+ columnConfig: {
66
+ count: 2,
67
+ gutter: "2rem",
68
+ columnRule: { width: "1px", style: "solid", color: "#ccc" },
69
+ balancing: true,
70
+ },
71
+ typography: {
72
+ orphans: 2,
73
+ widows: 2,
74
+ hyphenation: true,
75
+ ragOptimization: true,
76
+ spacing: {
77
+ beforeHeading: "1.5em",
78
+ afterHeading: "0.5em",
79
+ beforeFigure: "1em",
80
+ afterFigure: "1em",
81
+ beforeBlockQuote: "1em",
82
+ afterBlockQuote: "1em",
83
+ },
84
+ keepTogether: {
85
+ headingWithParagraph: true,
86
+ figureWithCaption: true,
87
+ },
88
+ },
89
+ resourcePlacement: {
90
+ defaultStrategy: "topOfColumn",
91
+ deferPlacement: false,
92
+ preserveAspectRatio: true,
93
+ },
94
+ references: {
95
+ footnotes: { placement: "columnBottom", marker: "number" },
96
+ figureNumbering: true,
97
+ tableNumbering: true,
98
+ marginNotes: true,
99
+ },
100
+ sectionOverrides: [
101
+ {
102
+ selector: ".intro",
103
+ columns: { count: 1 },
104
+ typography: { orphans: 3 },
105
+ },
106
+ ],
107
+ renderer: "web",
108
+ };
109
+ const Layout = createLayout(minimalContent, config);
110
+ expect(Layout.displayName).toBe("PostextLayout");
111
+ });
112
+ it("accepts config with pdf renderer", () => {
113
+ const Layout = createLayout(minimalContent, { renderer: "pdf" });
114
+ expect(Layout.displayName).toBe("PostextLayout");
115
+ });
116
+ it("works with no config (optional)", () => {
117
+ const Layout = createLayout(minimalContent);
118
+ expect(Layout.displayName).toBe("PostextLayout");
119
+ });
120
+ it("works with empty config", () => {
121
+ const Layout = createLayout(minimalContent, {});
122
+ expect(Layout.displayName).toBe("PostextLayout");
123
+ });
124
+ it("accepts all resource placement strategies", () => {
125
+ const strategies = [
126
+ "topOfColumn",
127
+ "inline",
128
+ "floatLeft",
129
+ "floatRight",
130
+ "fullWidthBreak",
131
+ "margin",
132
+ ];
133
+ for (const strategy of strategies) {
134
+ const Layout = createLayout(minimalContent, {
135
+ resourcePlacement: { defaultStrategy: strategy },
136
+ });
137
+ expect(Layout.displayName).toBe("PostextLayout");
138
+ }
139
+ });
140
+ });
141
+ //# sourceMappingURL=createLayout.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createLayout.test.js","sourceRoot":"","sources":["../../src/__tests__/createLayout.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,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,EAAE,GAAG,EAAE;QACzC,MAAM,MAAM,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;QAC5C,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,MAAM,GAAG,YAAY,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;QAChD,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,UAAU,GAAG;YACjB,aAAa;YACb,QAAQ;YACR,WAAW;YACX,YAAY;YACZ,gBAAgB;YAChB,QAAQ;SACA,CAAC;QAEX,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE,CAAC;YAClC,MAAM,MAAM,GAAG,YAAY,CAAC,cAAc,EAAE;gBAC1C,iBAAiB,EAAE,EAAE,eAAe,EAAE,QAAQ,EAAE;aACjD,CAAC,CAAC;YACH,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACnD,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=exports.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/exports.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import * as postext from "../index";
3
+ describe("package exports", () => {
4
+ it("exports createLayout function", () => {
5
+ expect(postext.createLayout).toBeDefined();
6
+ expect(typeof postext.createLayout).toBe("function");
7
+ });
8
+ it("does not export unexpected values", () => {
9
+ const exportedKeys = Object.keys(postext);
10
+ // Only createLayout should be a runtime export; types are compile-time only
11
+ expect(exportedKeys).toEqual(["createLayout"]);
12
+ });
13
+ });
14
+ //# sourceMappingURL=exports.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.test.js","sourceRoot":"","sources":["../../src/__tests__/exports.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,UAAU,CAAC;AAEpC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACvC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3C,MAAM,CAAC,OAAO,OAAO,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1C,4EAA4E;QAC5E,MAAM,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "postext",
3
- "version": "0.0.2",
4
- "description": "A programmable typesetter for the web",
3
+ "version": "0.0.4",
4
+ "description": "A programmable typesetter for the web. Layout engine that applies professional editorial rules — columns, orphan/widow prevention, resource placement, footnotes — to semantic content. Built on @chenglou/pretext for DOM-free text measurement.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -23,14 +23,19 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/react": "^19",
26
+ "@vitejs/plugin-react": "^6.0.1",
27
+ "eslint": "^9.39.4",
26
28
  "react": "^19.2.4",
27
29
  "typescript": "latest",
30
+ "typescript-eslint": "^8.58.0",
31
+ "vitest": "^4.1.3",
28
32
  "@postext/typescript-config": "0.0.0"
29
33
  },
30
34
  "scripts": {
31
35
  "build": "tsc",
32
36
  "dev": "tsc --watch",
33
37
  "check-types": "tsc --noEmit",
34
- "lint": "eslint ."
38
+ "lint": "eslint .",
39
+ "test": "vitest run"
35
40
  }
36
41
  }