paged-react 0.2.3 → 0.2.5
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 +15 -6
- package/dist/components/document.d.ts.map +1 -1
- package/dist/components/document.js +6 -9
- package/dist/components/document.js.map +1 -1
- package/dist/core/ir-extract.d.ts +5 -0
- package/dist/core/ir-extract.d.ts.map +1 -0
- package/dist/core/ir-extract.js +152 -0
- package/dist/core/ir-extract.js.map +1 -0
- package/dist/core/ir-style.d.ts +9 -0
- package/dist/core/ir-style.d.ts.map +1 -0
- package/dist/core/ir-style.js +136 -0
- package/dist/core/ir-style.js.map +1 -0
- package/dist/core/ir-types.d.ts +87 -0
- package/dist/core/ir-types.d.ts.map +1 -0
- package/dist/core/ir-types.js +2 -0
- package/dist/core/ir-types.js.map +1 -0
- package/dist/core/ir.d.ts +4 -0
- package/dist/core/ir.d.ts.map +1 -0
- package/dist/core/ir.js +3 -0
- package/dist/core/ir.js.map +1 -0
- package/dist/core/paginate-ir.d.ts +3 -0
- package/dist/core/paginate-ir.d.ts.map +1 -0
- package/dist/core/paginate-ir.js +116 -0
- package/dist/core/paginate-ir.js.map +1 -0
- package/dist/core/paginate.d.ts.map +1 -1
- package/dist/core/paginate.js +52 -5
- package/dist/core/paginate.js.map +1 -1
- package/dist/core/utils.d.ts +4 -1
- package/dist/core/utils.d.ts.map +1 -1
- package/dist/core/utils.js +16 -5
- package/dist/core/utils.js.map +1 -1
- package/dist/export-pdf.d.ts +5 -0
- package/dist/export-pdf.d.ts.map +1 -0
- package/dist/export-pdf.js +7 -0
- package/dist/export-pdf.js.map +1 -0
- package/dist/styles.css +46 -37
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/writers/pdf-color.d.ts +7 -0
- package/dist/writers/pdf-color.d.ts.map +1 -0
- package/dist/writers/pdf-color.js +80 -0
- package/dist/writers/pdf-color.js.map +1 -0
- package/dist/writers/pdf.d.ts +9 -0
- package/dist/writers/pdf.d.ts.map +1 -0
- package/dist/writers/pdf.js +193 -0
- package/dist/writers/pdf.js.map +1 -0
- package/package.json +68 -71
package/README.md
CHANGED
|
@@ -82,11 +82,20 @@ await paginateDocument({
|
|
|
82
82
|
bottom: "5mm",
|
|
83
83
|
left: "5mm",
|
|
84
84
|
},
|
|
85
|
+
scale: 0.8,
|
|
85
86
|
},
|
|
86
87
|
});
|
|
87
88
|
```
|
|
88
89
|
|
|
89
90
|
Runtime options override the corresponding `Document.Segment` values for that pagination run.
|
|
91
|
+
`scale` accepts a factor from `0.1` to `2`. Pagination runs against the scaled logical page
|
|
92
|
+
dimensions, then the generated content is painted onto the selected physical page size.
|
|
93
|
+
|
|
94
|
+
For React documents, pass the same factor to `Document`:
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
<Document scale={0.8}>{children}</Document>
|
|
98
|
+
```
|
|
90
99
|
|
|
91
100
|
## Printing
|
|
92
101
|
|
|
@@ -147,24 +156,24 @@ The package CSS handles the document structure. Add this optional CSS in your ap
|
|
|
147
156
|
- `PageBreak`: starts following content on a new page.
|
|
148
157
|
- `PageNumber`: renders the current page number.
|
|
149
158
|
- `TotalPages`: renders the total number of generated pages.
|
|
150
|
-
- `Watermark`: renders a watermark inside
|
|
159
|
+
- `Watermark`: renders a watermark inside one document segment.
|
|
151
160
|
- `pageSizes`: built-in page sizes, including A-series, B4, B5, Letter, Legal, and Ledger.
|
|
152
161
|
|
|
153
162
|
Slots accept normal `div` props such as `className`, `style`, `id`, `data-*`, and `aria-*`.
|
|
154
163
|
|
|
155
164
|
## Watermark
|
|
156
165
|
|
|
157
|
-
Use `Watermark`
|
|
166
|
+
Use `Watermark` as a direct child of `Document.Segment` for static page decoration. Its source markup is cloned as each page in that segment is created, so it is not rendered through a React portal.
|
|
158
167
|
|
|
159
168
|
```tsx
|
|
160
169
|
<Document>
|
|
161
170
|
<Document.Segment pageSize={pageSizes.A4}>
|
|
171
|
+
<Watermark>
|
|
172
|
+
<div>Draft</div>
|
|
173
|
+
</Watermark>
|
|
174
|
+
|
|
162
175
|
<Document.Body>Report content</Document.Body>
|
|
163
176
|
</Document.Segment>
|
|
164
|
-
|
|
165
|
-
<Watermark>
|
|
166
|
-
<div>Draft</div>
|
|
167
|
-
</Watermark>
|
|
168
177
|
</Document>
|
|
169
178
|
```
|
|
170
179
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/components/document.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/components/document.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA8B,MAAM,OAAO,CAAC;AAG/D,OAAO,KAAK,EAIV,aAAa,EAEd,MAAM,aAAa,CAAC;AAErB,KAAK,iBAAiB,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC,GAAG;IACtF,OAAO,EAAE,OAAO,eAAe,CAAC;IAChC,MAAM,EAAE,OAAO,cAAc,CAAC;IAC9B,IAAI,EAAE,OAAO,YAAY,CAAC;IAC1B,MAAM,EAAE,OAAO,cAAc,CAAC;CAC/B,CAAC;AAEF,eAAO,MAAM,eAAe;;;;;kDAoC1B,CAAC;AAEH,eAAO,MAAM,cAAc;;kDASzB,CAAC;AAEH,eAAO,MAAM,YAAY;;kDASvB,CAAC;AAEH,eAAO,MAAM,cAAc;;kDASzB,CAAC;AA8DH,eAAO,MAAM,QAAQ,EAKf,iBAAiB,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useEffect, useMemo, useRef
|
|
2
|
+
import { forwardRef, useEffect, useMemo, useRef } from "react";
|
|
3
3
|
import { paginateDocument } from "../core/paginate.js";
|
|
4
4
|
import { resolvePageSize } from "../utils/page-size.js";
|
|
5
|
-
import { context } from "./context.js";
|
|
6
5
|
export const DocumentSegment = forwardRef(function DocumentSegment({ children, pageSize, pageMargins, repeatTableHeader, style, ...props }, ref) {
|
|
7
6
|
const resolvedPageSize = resolvePageSize(pageSize);
|
|
8
7
|
const segmentStyle = { ...style };
|
|
@@ -31,10 +30,9 @@ export const DocumentBody = forwardRef(function DocumentBody({ children, ...prop
|
|
|
31
30
|
export const DocumentFooter = forwardRef(function DocumentFooter({ children, ...props }, ref) {
|
|
32
31
|
return (_jsx("div", { ...props, ref: ref, "data-paged-react-footer-source": "", children: children }));
|
|
33
32
|
});
|
|
34
|
-
const DocumentRoot = forwardRef(function Document({ children, afterPaginate, paginate = true, doNotHideSource = false, ...props }, ref) {
|
|
33
|
+
const DocumentRoot = forwardRef(function Document({ children, afterPaginate, paginate = true, doNotHideSource = false, scale = 1, ...props }, ref) {
|
|
35
34
|
const sourceRef = useRef(null);
|
|
36
35
|
const pagesRef = useRef(null);
|
|
37
|
-
const [pages, setPages] = useState(null);
|
|
38
36
|
const mergedRef = useMemo(() => {
|
|
39
37
|
return (node) => {
|
|
40
38
|
pagesRef.current = node;
|
|
@@ -58,23 +56,22 @@ const DocumentRoot = forwardRef(function Document({ children, afterPaginate, pag
|
|
|
58
56
|
return;
|
|
59
57
|
}
|
|
60
58
|
const abortController = new AbortController();
|
|
61
|
-
setPages(null);
|
|
62
59
|
void paginateDocument({
|
|
63
60
|
sourceRoot,
|
|
64
61
|
pagesRoot,
|
|
65
62
|
signal: abortController.signal,
|
|
66
|
-
|
|
63
|
+
options: { scale },
|
|
64
|
+
}).then(() => {
|
|
67
65
|
if (abortController.signal.aborted) {
|
|
68
66
|
return;
|
|
69
67
|
}
|
|
70
68
|
afterPaginate?.();
|
|
71
|
-
setPages(generatedPages);
|
|
72
69
|
});
|
|
73
70
|
return () => {
|
|
74
71
|
abortController.abort();
|
|
75
72
|
};
|
|
76
|
-
}, [children, paginate, afterPaginate]);
|
|
77
|
-
return (
|
|
73
|
+
}, [children, paginate, afterPaginate, scale]);
|
|
74
|
+
return (_jsxs("div", { style: { display: "contents" }, children: [_jsx("div", { "data-paged-react-pages": true, ref: mergedRef, ...props }), _jsx("div", { "data-paged-react-source": true, "data-paged-react-source-hidden": String(!doNotHideSource), ref: sourceRef, children: children })] }));
|
|
78
75
|
});
|
|
79
76
|
export const Document = Object.assign(DocumentRoot, {
|
|
80
77
|
Segment: DocumentSegment,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.js","sourceRoot":"","sources":["../../src/components/document.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"document.js","sourceRoot":"","sources":["../../src/components/document.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAgBxD,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAuC,SAAS,eAAe,CACtG,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,iBAAiB,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EACvE,GAAG;IAEH,MAAM,gBAAgB,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IACnD,MAAM,YAAY,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IAElC,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE;YAC1B,+BAA+B,EAAE,WAAW,CAAC,GAAG;YAChD,iCAAiC,EAAE,WAAW,CAAC,KAAK;YACpD,kCAAkC,EAAE,WAAW,CAAC,MAAM;YACtD,gCAAgC,EAAE,WAAW,CAAC,IAAI;YAClD,SAAS,EAAE,YAAY;YACvB,OAAO,E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AC1B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC;IAE/C,OAAO,CACL,eAAK,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,aACjC,8CAA4B,GAAG,EAAE,SAAS,KAAM,KAAK,GAAI,EACzD,iFAA6D,MAAM,CAAC,CAAC,eAAe,CAAC,EAAE,GAAG,EAAE,SAAS,YAClG,QAAQ,GACL,IACF,CACP,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE;IAClD,OAAO,EAAE,eAAe;IACxB,MAAM,EAAE,cAAc;IACtB,IAAI,EAAE,YAAY;IAClB,MAAM,EAAE,cAAc;CACvB,CAAsB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type PaginatedDocumentIR } from "./ir-types.js";
|
|
2
|
+
export declare function markSourceIds(root: HTMLElement): void;
|
|
3
|
+
export declare function clearSourceIds(pages: HTMLElement[]): void;
|
|
4
|
+
export declare function buildPaginatedDocumentIR(pages: HTMLElement[]): PaginatedDocumentIR;
|
|
5
|
+
//# sourceMappingURL=ir-extract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir-extract.d.ts","sourceRoot":"","sources":["../../src/core/ir-extract.ts"],"names":[],"mappings":"AAUA,OAAO,EAIL,KAAK,mBAAmB,EAGzB,MAAM,eAAe,CAAC;AAEvB,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAMrD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,IAAI,CAOzD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,mBAAmB,CAkJlF"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { textBreaker } from "./text-break.js";
|
|
2
|
+
import { getImageSource, hasVisibleBox, readBreakDirectives, readDimension, readNumberAttribute, readPaintStyle, toPageRect, } from "./ir-style.js";
|
|
3
|
+
import { SOURCE_ID_ATTRIBUTE, } from "./ir-types.js";
|
|
4
|
+
export function markSourceIds(root) {
|
|
5
|
+
const elements = [root, ...Array.from(root.querySelectorAll("*"))];
|
|
6
|
+
for (const [index, element] of elements.entries()) {
|
|
7
|
+
element.setAttribute(SOURCE_ID_ATTRIBUTE, `source-${index}`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function clearSourceIds(pages) {
|
|
11
|
+
for (const page of pages) {
|
|
12
|
+
page.removeAttribute(SOURCE_ID_ATTRIBUTE);
|
|
13
|
+
for (const element of page.querySelectorAll(`[${SOURCE_ID_ATTRIBUTE}]`)) {
|
|
14
|
+
element.removeAttribute(SOURCE_ID_ATTRIBUTE);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function buildPaginatedDocumentIR(pages) {
|
|
19
|
+
const sourceFragments = new Map();
|
|
20
|
+
const pageIR = [];
|
|
21
|
+
for (const [pageIndex, page] of pages.entries()) {
|
|
22
|
+
const pageRect = page.getBoundingClientRect();
|
|
23
|
+
const fragments = [];
|
|
24
|
+
const paint = [];
|
|
25
|
+
let fragmentIndex = 0;
|
|
26
|
+
collectFragment(page, "segment", null);
|
|
27
|
+
const segmentIndex = readNumberAttribute(page, "data-paged-react-segment-index");
|
|
28
|
+
const segmentPageIndex = readNumberAttribute(page, "data-paged-react-body-segment-index");
|
|
29
|
+
const width = readDimension(pageRect.width, page.style.width);
|
|
30
|
+
const height = readDimension(pageRect.height, page.style.height);
|
|
31
|
+
pageIR.push({
|
|
32
|
+
index: pageIndex,
|
|
33
|
+
segmentIndex,
|
|
34
|
+
segmentPageIndex,
|
|
35
|
+
width,
|
|
36
|
+
height,
|
|
37
|
+
fragments,
|
|
38
|
+
paint,
|
|
39
|
+
});
|
|
40
|
+
function collectFragment(element, kind, parentId) {
|
|
41
|
+
const id = `page-${pageIndex}-fragment-${fragmentIndex}`;
|
|
42
|
+
fragmentIndex += 1;
|
|
43
|
+
const sourceId = getSourceId(element, id);
|
|
44
|
+
const fragment = {
|
|
45
|
+
id,
|
|
46
|
+
sourceId,
|
|
47
|
+
kind,
|
|
48
|
+
parentId,
|
|
49
|
+
childIds: [],
|
|
50
|
+
rect: toPageRect(element.getBoundingClientRect(), pageRect),
|
|
51
|
+
breakDirectives: readBreakDirectives(element),
|
|
52
|
+
repeated: kind === "header" || kind === "footer",
|
|
53
|
+
continuationIndex: 0,
|
|
54
|
+
continuationCount: 1,
|
|
55
|
+
};
|
|
56
|
+
fragments.push(fragment);
|
|
57
|
+
let sameSource = sourceFragments.get(sourceId);
|
|
58
|
+
if (sameSource === undefined) {
|
|
59
|
+
sameSource = [];
|
|
60
|
+
sourceFragments.set(sourceId, sameSource);
|
|
61
|
+
}
|
|
62
|
+
sameSource.push(fragment);
|
|
63
|
+
appendElementPaint(element, id, sourceId, pageRect);
|
|
64
|
+
for (const child of Array.from(element.children)) {
|
|
65
|
+
const childKind = kind === "segment" ? getPageChildKind(child) : "element";
|
|
66
|
+
if (childKind === null) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const childId = collectFragment(child, childKind, id);
|
|
70
|
+
fragment.childIds.push(childId);
|
|
71
|
+
}
|
|
72
|
+
return id;
|
|
73
|
+
}
|
|
74
|
+
function appendElementPaint(element, fragmentId, sourceId, rootRect) {
|
|
75
|
+
const style = readPaintStyle(element);
|
|
76
|
+
const rect = toPageRect(element.getBoundingClientRect(), rootRect);
|
|
77
|
+
if (hasVisibleBox(element, style)) {
|
|
78
|
+
paint.push({ type: "box", sourceId, fragmentId, rect, style, zIndex: paint.length });
|
|
79
|
+
}
|
|
80
|
+
if (element.tagName.toUpperCase() === "IMG") {
|
|
81
|
+
const source = getImageSource(element);
|
|
82
|
+
if (source !== null) {
|
|
83
|
+
paint.push({ type: "image", sourceId, fragmentId, rect, source, style, zIndex: paint.length });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (const node of Array.from(element.childNodes)) {
|
|
87
|
+
if (node.nodeType !== 3) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
appendTextPaint(node, fragmentId, sourceId, style, rootRect);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function appendTextPaint(node, fragmentId, sourceId, style, rootRect) {
|
|
94
|
+
const textNode = node;
|
|
95
|
+
if (textNode.textContent === null || textNode.textContent.length === 0) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const range = page.ownerDocument.createRange();
|
|
99
|
+
range.selectNode(textNode);
|
|
100
|
+
const rangeWithRects = range;
|
|
101
|
+
if (typeof rangeWithRects.getClientRects !== "function") {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const rects = Array.from(rangeWithRects.getClientRects());
|
|
105
|
+
if (rects.length === 0) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const lines = textBreaker(textNode, rects);
|
|
109
|
+
for (const line of lines) {
|
|
110
|
+
paint.push({
|
|
111
|
+
type: "text",
|
|
112
|
+
sourceId,
|
|
113
|
+
fragmentId,
|
|
114
|
+
rect: toPageRect(line.rect, rootRect),
|
|
115
|
+
text: line.text,
|
|
116
|
+
sourceStart: line.start,
|
|
117
|
+
sourceEnd: line.end,
|
|
118
|
+
style,
|
|
119
|
+
zIndex: paint.length,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (const fragments of sourceFragments.values()) {
|
|
125
|
+
const continuationCount = fragments.length;
|
|
126
|
+
for (const [continuationIndex, fragment] of fragments.entries()) {
|
|
127
|
+
fragment.continuationIndex = continuationIndex;
|
|
128
|
+
fragment.continuationCount = continuationCount;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { pages: pageIR };
|
|
132
|
+
}
|
|
133
|
+
function getPageChildKind(element) {
|
|
134
|
+
if (element.hasAttribute("data-paged-react-page-header")) {
|
|
135
|
+
return "header";
|
|
136
|
+
}
|
|
137
|
+
if (element.hasAttribute("data-paged-react-page-body")) {
|
|
138
|
+
return "body";
|
|
139
|
+
}
|
|
140
|
+
if (element.hasAttribute("data-paged-react-page-footer")) {
|
|
141
|
+
return "footer";
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
function getSourceId(element, generatedId) {
|
|
146
|
+
const sourceId = element.getAttribute(SOURCE_ID_ATTRIBUTE);
|
|
147
|
+
if (sourceId === null) {
|
|
148
|
+
return generatedId;
|
|
149
|
+
}
|
|
150
|
+
return sourceId;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=ir-extract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir-extract.js","sourceRoot":"","sources":["../../src/core/ir-extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACL,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,UAAU,GACX,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,mBAAmB,GAMpB,MAAM,eAAe,CAAC;AAEvB,MAAM,UAAU,aAAa,CAAC,IAAiB;IAC7C,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAEnE,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QAClD,OAAO,CAAC,YAAY,CAAC,mBAAmB,EAAE,UAAU,KAAK,EAAE,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAoB;IACjD,KAAK,MAAM,IAA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AE,CAAC;QACjD,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,CAAC;QAC3C,KAAK,MAAM,CAAC,iBAAiB,EAAE,QAAQ,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;YAChE,QAAQ,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;YAC/C,QAAQ,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QACjD,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAgB;IACxC,IAAI,OAAO,CAAC,YAAY,CAAC,8BAA8B,CAAC,EAAE,CAAC;QACzD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,OAAO,CAAC,YAAY,CAAC,4BAA4B,CAAC,EAAE,CAAC;QACvD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,OAAO,CAAC,YAAY,CAAC,8BAA8B,CAAC,EAAE,CAAC;QACzD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,WAAW,CAAC,OAAgB,EAAE,WAAmB;IACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC;IAC3D,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BreakDirectives, IRRect, PaintStyle } from "./ir-types.js";
|
|
2
|
+
export declare function readBreakDirectives(element: Element): BreakDirectives;
|
|
3
|
+
export declare function readPaintStyle(element: Element): PaintStyle;
|
|
4
|
+
export declare function hasVisibleBox(element: Element, style: PaintStyle): boolean;
|
|
5
|
+
export declare function getImageSource(element: Element): string | null;
|
|
6
|
+
export declare function toPageRect(rect: DOMRect, pageRect: DOMRect): IRRect;
|
|
7
|
+
export declare function readNumberAttribute(element: Element, name: string): number;
|
|
8
|
+
export declare function readDimension(value: number, styleValue: string): number;
|
|
9
|
+
//# sourceMappingURL=ir-style.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir-style.d.ts","sourceRoot":"","sources":["../../src/core/ir-style.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EACf,MAAM,EACN,UAAU,EACX,MAAM,eAAe,CAAC;AAEvB,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,CAYrE;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CA2C3D;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CA4B1E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAY9D;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAOnE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAW1E;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAUvE"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export function readBreakDirectives(element) {
|
|
2
|
+
const view = element.ownerDocument.defaultView;
|
|
3
|
+
if (view === null) {
|
|
4
|
+
return { before: "auto", after: "auto", inside: "auto" };
|
|
5
|
+
}
|
|
6
|
+
const style = view.getComputedStyle(element);
|
|
7
|
+
return {
|
|
8
|
+
before: normalizeBreak(style.breakBefore, style.pageBreakBefore),
|
|
9
|
+
after: normalizeBreak(style.breakAfter, style.pageBreakAfter),
|
|
10
|
+
inside: normalizeInsideBreak(style.breakInside, style.pageBreakInside),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function readPaintStyle(element) {
|
|
14
|
+
const view = element.ownerDocument.defaultView;
|
|
15
|
+
if (view === null) {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
const computed = view.getComputedStyle(element);
|
|
19
|
+
const style = {};
|
|
20
|
+
const properties = [
|
|
21
|
+
"color",
|
|
22
|
+
"backgroundColor",
|
|
23
|
+
"borderTopColor",
|
|
24
|
+
"borderRightColor",
|
|
25
|
+
"borderBottomColor",
|
|
26
|
+
"borderLeftColor",
|
|
27
|
+
"borderTopWidth",
|
|
28
|
+
"borderRightWidth",
|
|
29
|
+
"borderBottomWidth",
|
|
30
|
+
"borderLeftWidth",
|
|
31
|
+
"borderRadius",
|
|
32
|
+
"fontFamily",
|
|
33
|
+
"fontSize",
|
|
34
|
+
"fontWeight",
|
|
35
|
+
"fontStyle",
|
|
36
|
+
"lineHeight",
|
|
37
|
+
"letterSpacing",
|
|
38
|
+
"textAlign",
|
|
39
|
+
"overflow",
|
|
40
|
+
];
|
|
41
|
+
for (const property of properties) {
|
|
42
|
+
const value = computed[property];
|
|
43
|
+
if (value.length > 0) {
|
|
44
|
+
style[property] = value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const opacity = Number.parseFloat(computed.opacity);
|
|
48
|
+
if (Number.isFinite(opacity)) {
|
|
49
|
+
style.opacity = opacity;
|
|
50
|
+
}
|
|
51
|
+
return style;
|
|
52
|
+
}
|
|
53
|
+
export function hasVisibleBox(element, style) {
|
|
54
|
+
const view = element.ownerDocument.defaultView;
|
|
55
|
+
if (view === null) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const computed = view.getComputedStyle(element);
|
|
59
|
+
if (computed.display === "none" || computed.visibility === "hidden") {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const opacity = style.opacity;
|
|
63
|
+
if (opacity !== undefined && opacity <= 0) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const background = style.backgroundColor;
|
|
67
|
+
if (background !== undefined && background !== "transparent" && background !== "rgba(0, 0, 0, 0)") {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
const borderWidths = [
|
|
71
|
+
style.borderTopWidth,
|
|
72
|
+
style.borderRightWidth,
|
|
73
|
+
style.borderBottomWidth,
|
|
74
|
+
style.borderLeftWidth,
|
|
75
|
+
];
|
|
76
|
+
return borderWidths.some((value) => value !== undefined && Number.parseFloat(value) > 0);
|
|
77
|
+
}
|
|
78
|
+
export function getImageSource(element) {
|
|
79
|
+
const source = element.getAttribute("src");
|
|
80
|
+
if (source !== null && source.length > 0) {
|
|
81
|
+
return source;
|
|
82
|
+
}
|
|
83
|
+
const view = element.ownerDocument.defaultView;
|
|
84
|
+
if (view !== null && element instanceof view.HTMLImageElement && element.currentSrc.length > 0) {
|
|
85
|
+
return element.currentSrc;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
export function toPageRect(rect, pageRect) {
|
|
90
|
+
return {
|
|
91
|
+
x: rect.left - pageRect.left,
|
|
92
|
+
y: rect.top - pageRect.top,
|
|
93
|
+
width: rect.width,
|
|
94
|
+
height: rect.height,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export function readNumberAttribute(element, name) {
|
|
98
|
+
const value = element.getAttribute(name);
|
|
99
|
+
if (value === null) {
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
const number = Number.parseInt(value, 10);
|
|
103
|
+
if (!Number.isFinite(number)) {
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
return number;
|
|
107
|
+
}
|
|
108
|
+
export function readDimension(value, styleValue) {
|
|
109
|
+
if (value > 0) {
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
const parsed = Number.parseFloat(styleValue);
|
|
113
|
+
if (!Number.isFinite(parsed)) {
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
return parsed;
|
|
117
|
+
}
|
|
118
|
+
function normalizeBreak(modern, legacy) {
|
|
119
|
+
if (modern === "page" || modern === "always") {
|
|
120
|
+
return "page";
|
|
121
|
+
}
|
|
122
|
+
if (legacy === "always") {
|
|
123
|
+
return "page";
|
|
124
|
+
}
|
|
125
|
+
return "auto";
|
|
126
|
+
}
|
|
127
|
+
function normalizeInsideBreak(modern, legacy) {
|
|
128
|
+
if (modern === "avoid") {
|
|
129
|
+
return "avoid";
|
|
130
|
+
}
|
|
131
|
+
if (legacy === "avoid") {
|
|
132
|
+
return "avoid";
|
|
133
|
+
}
|
|
134
|
+
return "auto";
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=ir-style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir-style.js","sourceRoot":"","sources":["../../src/core/ir-style.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAClD,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC;IAC/C,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAC3D,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC7C,OAAO;QACL,MAAM,EAAE,cAAc,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,eAAe,CAAC;QAChE,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,cAAc,CAAC;QAC7D,MAAM,EAAE,oBAAoB,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,eAAe,CAAC;KACvE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,WAA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AAM,CAAC;AAChB,CAAC;AAED,SAAS,oBAAoB,CAAC,MAAc,EAAE,MAAc;IAC1D,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;QACvB,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;QACvB,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export declare const SOURCE_ID_ATTRIBUTE = "data-paged-react-ir-source-id";
|
|
2
|
+
export type IRRect = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
};
|
|
8
|
+
export type BreakDirectiveValue = "auto" | "page" | "avoid";
|
|
9
|
+
export type BreakDirectives = {
|
|
10
|
+
before: BreakDirectiveValue;
|
|
11
|
+
after: BreakDirectiveValue;
|
|
12
|
+
inside: BreakDirectiveValue;
|
|
13
|
+
};
|
|
14
|
+
export type FragmentKind = "segment" | "header" | "body" | "footer" | "element";
|
|
15
|
+
export type PaintStyle = {
|
|
16
|
+
color?: string;
|
|
17
|
+
backgroundColor?: string;
|
|
18
|
+
borderTopColor?: string;
|
|
19
|
+
borderRightColor?: string;
|
|
20
|
+
borderBottomColor?: string;
|
|
21
|
+
borderLeftColor?: string;
|
|
22
|
+
borderTopWidth?: string;
|
|
23
|
+
borderRightWidth?: string;
|
|
24
|
+
borderBottomWidth?: string;
|
|
25
|
+
borderLeftWidth?: string;
|
|
26
|
+
borderRadius?: string;
|
|
27
|
+
fontFamily?: string;
|
|
28
|
+
fontSize?: string;
|
|
29
|
+
fontWeight?: string;
|
|
30
|
+
fontStyle?: string;
|
|
31
|
+
lineHeight?: string;
|
|
32
|
+
letterSpacing?: string;
|
|
33
|
+
textAlign?: string;
|
|
34
|
+
opacity?: number;
|
|
35
|
+
overflow?: string;
|
|
36
|
+
};
|
|
37
|
+
export type PaintNode = {
|
|
38
|
+
type: "box";
|
|
39
|
+
sourceId: string;
|
|
40
|
+
fragmentId: string;
|
|
41
|
+
rect: IRRect;
|
|
42
|
+
style: PaintStyle;
|
|
43
|
+
zIndex: number;
|
|
44
|
+
} | {
|
|
45
|
+
type: "text";
|
|
46
|
+
sourceId: string;
|
|
47
|
+
fragmentId: string;
|
|
48
|
+
rect: IRRect;
|
|
49
|
+
text: string;
|
|
50
|
+
sourceStart: number;
|
|
51
|
+
sourceEnd: number;
|
|
52
|
+
style: PaintStyle;
|
|
53
|
+
zIndex: number;
|
|
54
|
+
} | {
|
|
55
|
+
type: "image";
|
|
56
|
+
sourceId: string;
|
|
57
|
+
fragmentId: string;
|
|
58
|
+
rect: IRRect;
|
|
59
|
+
source: string;
|
|
60
|
+
style: PaintStyle;
|
|
61
|
+
zIndex: number;
|
|
62
|
+
};
|
|
63
|
+
export type FragmentIR = {
|
|
64
|
+
id: string;
|
|
65
|
+
sourceId: string;
|
|
66
|
+
kind: FragmentKind;
|
|
67
|
+
parentId: string | null;
|
|
68
|
+
childIds: string[];
|
|
69
|
+
rect: IRRect;
|
|
70
|
+
breakDirectives: BreakDirectives;
|
|
71
|
+
repeated: boolean;
|
|
72
|
+
continuationIndex: number;
|
|
73
|
+
continuationCount: number;
|
|
74
|
+
};
|
|
75
|
+
export type PageIR = {
|
|
76
|
+
index: number;
|
|
77
|
+
segmentIndex: number;
|
|
78
|
+
segmentPageIndex: number;
|
|
79
|
+
width: number;
|
|
80
|
+
height: number;
|
|
81
|
+
fragments: FragmentIR[];
|
|
82
|
+
paint: PaintNode[];
|
|
83
|
+
};
|
|
84
|
+
export type PaginatedDocumentIR = {
|
|
85
|
+
pages: PageIR[];
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=ir-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir-types.d.ts","sourceRoot":"","sources":["../../src/core/ir-types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,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AE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,UAAU,EAAE,CAAC;IACxB,KAAK,EAAE,SAAS,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir-types.js","sourceRoot":"","sources":["../../src/core/ir-types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { buildPaginatedDocumentIR, clearSourceIds, markSourceIds } from "./ir-extract.js";
|
|
2
|
+
export { SOURCE_ID_ATTRIBUTE } from "./ir-types.js";
|
|
3
|
+
export type { BreakDirectiveValue, BreakDirectives, FragmentIR, FragmentKind, IRRect, PageIR, PaginatedDocumentIR, PaintNode, PaintStyle, } from "./ir-types.js";
|
|
4
|
+
//# sourceMappingURL=ir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir.d.ts","sourceRoot":"","sources":["../../src/core/ir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,YAAY,EACZ,MAAM,EACN,MAAM,EACN,mBAAmB,EACnB,SAAS,EACT,UAAU,GACX,MAAM,eAAe,CAAC"}
|
package/dist/core/ir.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir.js","sourceRoot":"","sources":["../../src/core/ir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginate-ir.d.ts","sourceRoot":"","sources":["../../src/core/paginate-ir.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,uBAAuB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAqH7F"}
|