@printedjs/plugin-running-headers 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.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # @printedjs/plugin-running-headers
2
+
3
+ Running headers and footers plugin for Printedjs.
4
+
5
+ Provides support for W3C GCPM `position: running(...)` and `@page` margin box element stamping via `content: element(...)`.
6
+
7
+ ---
8
+
9
+ ## Features
10
+
11
+ - **Element Extraction** — Removes elements from normal document flow using `position: running(ident)`.
12
+ - **Margin Box Insertion** — Places extracted elements into any `@page` margin box using `content: element(ident, policy)`.
13
+ - **Policy Support** — Supports `first`, `start`, `last`, and `first-except` running element selection policies.
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pnpm add @printedjs/plugin-running-headers @printedjs/core
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Usage
26
+
27
+ ```typescript
28
+ import { createRenderer } from "@printedjs/browser";
29
+ import { runningHeadersPlugin } from "@printedjs/plugin-running-headers";
30
+
31
+ const renderer = createRenderer({
32
+ target: document.querySelector("#preview")!,
33
+ plugins: [runningHeadersPlugin()],
34
+ });
35
+
36
+ await renderer.render({
37
+ content: {
38
+ html: `
39
+ <style>
40
+ @page {
41
+ size: A4;
42
+ margin: 25mm 20mm;
43
+ @top-center {
44
+ content: element(currentChapter, first-except);
45
+ }
46
+ }
47
+ h2.chapter-title {
48
+ position: running(currentChapter);
49
+ }
50
+ </style>
51
+ <h2 class="chapter-title">Chapter 1: The Beginning</h2>
52
+ <p>Body copy spanning multiple pages...</p>
53
+ `,
54
+ },
55
+ });
56
+ ```
57
+
58
+ ---
59
+
60
+ ## Supported Assignment Policies
61
+
62
+ - **`first`** (default) — Uses the first assignment of the element on the page.
63
+ - **`start`** — Uses the element if it occurs at the very start of the page, otherwise carries forward from previous page.
64
+ - **`last`** — Uses the last occurrence of the element on the page.
65
+ - **`first-except`** — Displays on subsequent pages, but suppresses the header on the page where the element first appears.
@@ -0,0 +1,9 @@
1
+ import { PrintedjsPlugin } from '@printedjs/core';
2
+
3
+ /**
4
+ * Running headers and footers plugin supporting W3C GCPM `position: running(<ident>)`
5
+ * and `@page` margin box `content: element(<ident>, [first | start | last | first-except])`.
6
+ */
7
+ declare function runningHeadersPlugin(): PrintedjsPlugin;
8
+
9
+ export { runningHeadersPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // src/plugin.ts
2
+ import { generatedContentPlugin } from "@printedjs/plugin-generated-content";
3
+ function runningHeadersPlugin() {
4
+ return generatedContentPlugin();
5
+ }
6
+ export {
7
+ runningHeadersPlugin
8
+ };
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@printedjs/plugin-running-headers",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "dependencies": {
18
+ "@printedjs/core": "0.1.0",
19
+ "@printedjs/plugin-generated-content": "0.1.0"
20
+ },
21
+ "scripts": {
22
+ "build": "tsup",
23
+ "typecheck": "tsc --build"
24
+ }
25
+ }