paged-react 0.2.5 → 0.3.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 +78 -6
- package/dist/components/document.d.ts +6 -2
- package/dist/components/document.d.ts.map +1 -1
- package/dist/components/document.js +6 -6
- package/dist/components/document.js.map +1 -1
- package/dist/components/page-number.d.ts +19 -2
- package/dist/components/page-number.d.ts.map +1 -1
- package/dist/components/page-number.js +11 -4
- package/dist/components/page-number.js.map +1 -1
- package/dist/core/avoid-break.d.ts +2 -0
- package/dist/core/avoid-break.d.ts.map +1 -1
- package/dist/core/avoid-break.js +22 -9
- package/dist/core/avoid-break.js.map +1 -1
- package/dist/core/computed-style.d.ts +2 -0
- package/dist/core/computed-style.d.ts.map +1 -1
- package/dist/core/computed-style.js +4 -0
- package/dist/core/computed-style.js.map +1 -1
- package/dist/core/line-boxes.d.ts +22 -0
- package/dist/core/line-boxes.d.ts.map +1 -0
- package/dist/core/line-boxes.js +48 -0
- package/dist/core/line-boxes.js.map +1 -0
- package/dist/core/measure-range.d.ts +7 -0
- package/dist/core/measure-range.d.ts.map +1 -0
- package/dist/core/measure-range.js +15 -0
- package/dist/core/measure-range.js.map +1 -0
- package/dist/core/page-number-format.d.ts +28 -0
- package/dist/core/page-number-format.d.ts.map +1 -0
- package/dist/core/page-number-format.js +63 -0
- package/dist/core/page-number-format.js.map +1 -0
- package/dist/core/paginate.d.ts.map +1 -1
- package/dist/core/paginate.js +676 -84
- package/dist/core/paginate.js.map +1 -1
- package/dist/core/table-window.d.ts +8 -0
- package/dist/core/table-window.d.ts.map +1 -0
- package/dist/core/table-window.js +119 -0
- package/dist/core/table-window.js.map +1 -0
- package/dist/core/text-break.d.ts +6 -4
- package/dist/core/text-break.d.ts.map +1 -1
- package/dist/core/text-break.js +24 -61
- package/dist/core/text-break.js.map +1 -1
- package/dist/core/utils.d.ts.map +1 -1
- package/dist/core/utils.js +2 -1
- package/dist/core/utils.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/styles.css +16 -9
- package/dist/types.d.ts +17 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -150,12 +150,13 @@ The package CSS handles the document structure. Add this optional CSS in your ap
|
|
|
150
150
|
|
|
151
151
|
- `Document`: the root component. Attach your print ref here.
|
|
152
152
|
- `Document.Segment`: one paginated section with its own page size.
|
|
153
|
-
- `Document.Header`: repeated at the top of every generated page in the segment.
|
|
153
|
+
- `Document.Header`: repeated at the top of every generated page in the segment; `pages="first" | "odd" | "even"` adds a variant for those pages.
|
|
154
154
|
- `Document.Body`: the content that gets split across pages.
|
|
155
|
-
- `Document.Footer`: repeated at the bottom of every generated page in the segment.
|
|
155
|
+
- `Document.Footer`: repeated at the bottom of every generated page in the segment; takes the same `pages` variants.
|
|
156
156
|
- `PageBreak`: starts following content on a new page.
|
|
157
157
|
- `PageNumber`: renders the current page number.
|
|
158
158
|
- `TotalPages`: renders the total number of generated pages.
|
|
159
|
+
- `TargetPageNumber`: renders the page another element starts on, for a table of contents.
|
|
159
160
|
- `Watermark`: renders a watermark inside one document segment.
|
|
160
161
|
- `pageSizes`: built-in page sizes, including A-series, B4, B5, Letter, Legal, and Ledger.
|
|
161
162
|
|
|
@@ -177,7 +178,7 @@ Use `Watermark` as a direct child of `Document.Segment` for static page decorati
|
|
|
177
178
|
</Document>
|
|
178
179
|
```
|
|
179
180
|
|
|
180
|
-
Use `PageNumber` and `TotalPages` anywhere in document content, including headers, footers, and watermarks. They render as spans and accept normal span props.
|
|
181
|
+
Use `PageNumber` and `TotalPages` anywhere in document content, including headers, footers, and watermarks. They render as spans and accept normal span props. The numbers are written into them as text once pagination is done (earlier versions used CSS counters in `::before`, so styles that targeted `::before` no longer apply).
|
|
181
182
|
|
|
182
183
|
```tsx
|
|
183
184
|
<Document.Footer>
|
|
@@ -185,6 +186,75 @@ Use `PageNumber` and `TotalPages` anywhere in document content, including header
|
|
|
185
186
|
</Document.Footer>
|
|
186
187
|
```
|
|
187
188
|
|
|
189
|
+
Pass `format` to write a number in a CSS counter style: `decimal` (default), `decimal-leading-zero`, `lower-roman`, `upper-roman`, `lower-alpha`, `upper-alpha`, or native digits such as `bengali`, `devanagari`, `arabic-indic`, `persian`, `thai`. Numbers outside a style's range are written in decimal.
|
|
190
|
+
|
|
191
|
+
Page numbers run on across segments. Set `pageNumberStart` on a `Document.Segment` to restart them, for example after roman-numbered front matter. `TotalPages` always counts every page.
|
|
192
|
+
|
|
193
|
+
```tsx
|
|
194
|
+
<Document.Segment pageSize={pageSizes.A4} pageNumberStart={1}>
|
|
195
|
+
<Document.Footer>
|
|
196
|
+
<PageNumber format="lower-roman" />
|
|
197
|
+
</Document.Footer>
|
|
198
|
+
<Document.Body>Preface</Document.Body>
|
|
199
|
+
</Document.Segment>
|
|
200
|
+
<Document.Segment pageSize={pageSizes.A4} pageNumberStart={1}>
|
|
201
|
+
<Document.Body>Chapter 1</Document.Body>
|
|
202
|
+
</Document.Segment>
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Header and Footer Placement
|
|
206
|
+
|
|
207
|
+
By default the header and footer sit inside the page margins, right above and below the body. Set `bandPlacement="margin"` on `Document.Segment` to put them in the top and bottom margins instead, from the page edge, as Chrome's print headers do. The body then starts and ends exactly at the margins; a header or footer taller than its margin grows that margin.
|
|
208
|
+
|
|
209
|
+
```tsx
|
|
210
|
+
<Document.Segment pageSize={pageSizes.A4} pageMargins={{ top: "20mm", right: "15mm", bottom: "15mm", left: "15mm" }} bandPlacement="margin">
|
|
211
|
+
<Document.Header>Annual report</Document.Header>
|
|
212
|
+
<Document.Body>Report content</Document.Body>
|
|
213
|
+
</Document.Segment>
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## First, Odd, and Even Pages
|
|
217
|
+
|
|
218
|
+
Add a `Document.Header` or `Document.Footer` with `pages="first"`, `"odd"`, or `"even"` next to the default one. A `first` variant is used on the segment's first page, then `odd`/`even` by page number, then the default. An empty variant leaves that page without a header or footer. Each page's body gets the height its own header and footer leave.
|
|
219
|
+
|
|
220
|
+
```tsx
|
|
221
|
+
<Document.Segment pageSize={pageSizes.A4}>
|
|
222
|
+
<Document.Header>Annual report 2026</Document.Header>
|
|
223
|
+
<Document.Header pages="first" />
|
|
224
|
+
<Document.Footer pages="odd" style={{ textAlign: "right" }}>
|
|
225
|
+
<PageNumber />
|
|
226
|
+
</Document.Footer>
|
|
227
|
+
<Document.Footer pages="even">
|
|
228
|
+
<PageNumber />
|
|
229
|
+
</Document.Footer>
|
|
230
|
+
<Document.Body>Report content</Document.Body>
|
|
231
|
+
</Document.Segment>
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Table of Contents
|
|
235
|
+
|
|
236
|
+
`TargetPageNumber` renders the page that the element with the given `id` starts on.
|
|
237
|
+
|
|
238
|
+
```tsx
|
|
239
|
+
<Document.Body>
|
|
240
|
+
<nav>
|
|
241
|
+
{chapters.map((chapter) => (
|
|
242
|
+
<a key={chapter.id} href={`#${chapter.id}`}>
|
|
243
|
+
{chapter.title} <TargetPageNumber href={`#${chapter.id}`} />
|
|
244
|
+
</a>
|
|
245
|
+
))}
|
|
246
|
+
</nav>
|
|
247
|
+
{chapters.map((chapter) => (
|
|
248
|
+
<section key={chapter.id}>
|
|
249
|
+
<h2 id={chapter.id}>{chapter.title}</h2>
|
|
250
|
+
{chapter.content}
|
|
251
|
+
</section>
|
|
252
|
+
))}
|
|
253
|
+
</Document.Body>
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Give the number a fixed width (for example `display: inline-block; width: 3ch; font-variant-numeric: tabular-nums`) so a longer number does not rewrap its line. If a number does rewrap a line and a page overflows, the document is paginated again with the numbers in place (up to three passes). A target that is not in the document keeps the placeholder `0`.
|
|
257
|
+
|
|
188
258
|
## Tables
|
|
189
259
|
|
|
190
260
|
Direct child `<table>` elements inside `Document.Body` can be split by row when they overflow a page.
|
|
@@ -197,15 +267,17 @@ Direct child `<table>` elements inside `Document.Body` can be split by row when
|
|
|
197
267
|
</Document.Segment>
|
|
198
268
|
```
|
|
199
269
|
|
|
200
|
-
If a table has a `<thead>`, the first table fragment
|
|
270
|
+
If a table has a `<thead>`, only the first table fragment shows it when `repeatTableHeader` is not set. Use `repeatTableHeader` on `Document.Segment` when continuation pages should also repeat the original `<thead>`; a `<tfoot>` is then repeated at the bottom of every fragment too, like Chrome prints it.
|
|
201
271
|
|
|
202
272
|
## Page Breaks
|
|
203
273
|
|
|
204
274
|
Use `PageBreak` for an explicit new page. This is the supported way to force a page break.
|
|
205
275
|
|
|
206
|
-
`page-break-inside: avoid` is supported as a keep-together hint. Use it when a block should move to the next page instead of being split across pages.
|
|
276
|
+
`break-inside: avoid` / `page-break-inside: avoid` is supported as a keep-together hint. Use it when a block should move to the next page instead of being split across pages. A block taller than a page is still split, starting on a fresh page.
|
|
277
|
+
|
|
278
|
+
`break-before: avoid` and `break-after: avoid` keep blocks together (for example a heading with the paragraph after it), and `orphans` / `widows` set the minimum lines of a paragraph at the bottom and top of a page.
|
|
207
279
|
|
|
208
|
-
`break-before`, `page-break-before`, `break-after`, and `page-break-after` are intentionally ignored. Use `PageBreak` so there is only one explicit way to force a new page.
|
|
280
|
+
Forcing values of `break-before`, `page-break-before`, `break-after`, and `page-break-after` (such as `page`) are intentionally ignored. Use `PageBreak` so there is only one explicit way to force a new page.
|
|
209
281
|
|
|
210
282
|
## Limitations
|
|
211
283
|
|
|
@@ -11,15 +11,19 @@ export declare const DocumentSegment: import("react").ForwardRefExoticComponent<
|
|
|
11
11
|
pageSize: import("../types.js").PageSize;
|
|
12
12
|
pageMargins?: import("../types.js").PageMargins;
|
|
13
13
|
repeatTableHeader?: boolean;
|
|
14
|
+
pageNumberStart?: number;
|
|
15
|
+
bandPlacement?: "content" | "margin";
|
|
14
16
|
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
15
17
|
export declare const DocumentHeader: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
16
|
-
children
|
|
18
|
+
children?: import("react").ReactNode;
|
|
19
|
+
pages?: import("../types.js").BandPages;
|
|
17
20
|
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
18
21
|
export declare const DocumentBody: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
19
22
|
children: import("react").ReactNode;
|
|
20
23
|
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
21
24
|
export declare const DocumentFooter: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
22
|
-
children
|
|
25
|
+
children?: import("react").ReactNode;
|
|
26
|
+
pages?: import("../types.js").BandPages;
|
|
23
27
|
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
24
28
|
export declare const Document: DocumentComponent;
|
|
25
29
|
export {};
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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;;;;;;;kDAsC1B,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"}
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
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
|
-
export const DocumentSegment = forwardRef(function DocumentSegment({ children, pageSize, pageMargins, repeatTableHeader, style, ...props }, ref) {
|
|
5
|
+
export const DocumentSegment = forwardRef(function DocumentSegment({ children, pageSize, pageMargins, repeatTableHeader, pageNumberStart, bandPlacement, style, ...props }, ref) {
|
|
6
6
|
const resolvedPageSize = resolvePageSize(pageSize);
|
|
7
7
|
const segmentStyle = { ...style };
|
|
8
8
|
if (pageMargins) {
|
|
@@ -15,20 +15,20 @@ export const DocumentSegment = forwardRef(function DocumentSegment({ children, p
|
|
|
15
15
|
padding: "var(--paged-react-page-margin-top) var(--paged-react-page-margin-right) var(--paged-react-page-margin-bottom) var(--paged-react-page-margin-left)",
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
return (_jsx("div", { ...props, ref: ref, "data-paged-react-repeat-table-header": String(repeatTableHeader === true), "data-paged-react-page-height": resolvedPageSize.height, "data-paged-react-page-width": resolvedPageSize.width, "data-paged-react-segment-source": "", style: {
|
|
18
|
+
return (_jsx("div", { ...props, ref: ref, "data-paged-react-repeat-table-header": String(repeatTableHeader === true), "data-paged-react-page-number-start": pageNumberStart, "data-paged-react-band-placement": bandPlacement, "data-paged-react-page-height": resolvedPageSize.height, "data-paged-react-page-width": resolvedPageSize.width, "data-paged-react-segment-source": "", style: {
|
|
19
19
|
...segmentStyle,
|
|
20
20
|
minHeight: resolvedPageSize.height,
|
|
21
21
|
width: resolvedPageSize.width,
|
|
22
22
|
}, children: children }));
|
|
23
23
|
});
|
|
24
|
-
export const DocumentHeader = forwardRef(function DocumentHeader({ children, ...props }, ref) {
|
|
25
|
-
return (_jsx("div", { ...props, ref: ref, "data-paged-react-header-source": "", children: children }));
|
|
24
|
+
export const DocumentHeader = forwardRef(function DocumentHeader({ children, pages, ...props }, ref) {
|
|
25
|
+
return (_jsx("div", { ...props, ref: ref, "data-paged-react-header-source": "", "data-paged-react-pages": pages, children: children }));
|
|
26
26
|
});
|
|
27
27
|
export const DocumentBody = forwardRef(function DocumentBody({ children, ...props }, ref) {
|
|
28
28
|
return (_jsx("div", { ...props, ref: ref, "data-paged-react-body-source": "", children: children }));
|
|
29
29
|
});
|
|
30
|
-
export const DocumentFooter = forwardRef(function DocumentFooter({ children, ...props }, ref) {
|
|
31
|
-
return (_jsx("div", { ...props, ref: ref, "data-paged-react-footer-source": "", children: children }));
|
|
30
|
+
export const DocumentFooter = forwardRef(function DocumentFooter({ children, pages, ...props }, ref) {
|
|
31
|
+
return (_jsx("div", { ...props, ref: ref, "data-paged-react-footer-source": "", "data-paged-react-pages": pages, children: children }));
|
|
32
32
|
});
|
|
33
33
|
const DocumentRoot = forwardRef(function Document({ children, afterPaginate, paginate = true, doNotHideSource = false, scale = 1, ...props }, ref) {
|
|
34
34
|
const sourceRef = useRef(null);
|
|
@@ -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,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,
|
|
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,eAAe,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EACvG,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,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,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnC,OAAO;YACT,CAAC;YACD,aAAa,EAAE,EAAE,CAAC;QACpB,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,eAAe,CAAC,KAAK,EAAE,CAAC;QAC1B,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"}
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
1
|
+
import type { PageNumberFormat } from "../core/page-number-format.js";
|
|
2
|
+
export declare const PageNumber: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
|
|
3
|
+
/** CSS counter style name, e.g. `lower-roman` or `bengali`. Defaults to decimal. */
|
|
4
|
+
format?: PageNumberFormat;
|
|
5
|
+
} & import("react").RefAttributes<HTMLSpanElement>>;
|
|
6
|
+
/**
|
|
7
|
+
* The page number of the element `href` (`#id`) points to, e.g. in a table of contents. Give it
|
|
8
|
+
* a fixed width (`display: inline-block; width: 3ch`) so a longer number does not rewrap its line.
|
|
9
|
+
*/
|
|
10
|
+
export declare const TargetPageNumber: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
|
|
11
|
+
/** CSS counter style name, e.g. `lower-roman` or `bengali`. Defaults to decimal. */
|
|
12
|
+
format?: PageNumberFormat;
|
|
13
|
+
} & {
|
|
14
|
+
href: string;
|
|
15
|
+
} & import("react").RefAttributes<HTMLSpanElement>>;
|
|
16
|
+
export declare const TotalPages: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
|
|
17
|
+
/** CSS counter style name, e.g. `lower-roman` or `bengali`. Defaults to decimal. */
|
|
18
|
+
format?: PageNumberFormat;
|
|
19
|
+
} & import("react").RefAttributes<HTMLSpanElement>>;
|
|
3
20
|
//# sourceMappingURL=page-number.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-number.d.ts","sourceRoot":"","sources":["../../src/components/page-number.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"page-number.d.ts","sourceRoot":"","sources":["../../src/components/page-number.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAOtE,eAAO,MAAM,UAAU;IAJrB,oFAAoF;aAC3E,gBAAgB;mDAQzB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,gBAAgB;IAf3B,oFAAoF;aAC3E,gBAAgB;;UAc2D,MAAM;mDAM3F,CAAC;AAEF,eAAO,MAAM,UAAU;IAvBrB,oFAAoF;aAC3E,gBAAgB;mDA2BzB,CAAC"}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
|
-
export const PageNumber = forwardRef(function PageNumber(props, ref) {
|
|
4
|
-
return _jsx("span", { ...props, ref: ref, "data-paged-react-page-number": "" });
|
|
3
|
+
export const PageNumber = forwardRef(function PageNumber({ format, ...props }, ref) {
|
|
4
|
+
return _jsx("span", { ...props, ref: ref, "data-paged-react-page-number": "", "data-paged-react-format": format });
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The page number of the element `href` (`#id`) points to, e.g. in a table of contents. Give it
|
|
8
|
+
* a fixed width (`display: inline-block; width: 3ch`) so a longer number does not rewrap its line.
|
|
9
|
+
*/
|
|
10
|
+
export const TargetPageNumber = forwardRef(function TargetPageNumber({ href, format, ...props }, ref) {
|
|
11
|
+
return (_jsx("span", { ...props, ref: ref, "data-paged-react-target-page": href, "data-paged-react-format": format }));
|
|
12
|
+
});
|
|
13
|
+
export const TotalPages = forwardRef(function TotalPages({ format, ...props }, ref) {
|
|
14
|
+
return _jsx("span", { ...props, ref: ref, "data-paged-react-total-pages": "", "data-paged-react-format": format });
|
|
8
15
|
});
|
|
9
16
|
//# sourceMappingURL=page-number.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-number.js","sourceRoot":"","sources":["../../src/components/page-number.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"page-number.js","sourceRoot":"","sources":["../../src/components/page-number.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AASnC,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAmC,SAAS,UAAU,CACxF,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,EACpB,GAAG;IAEH,OAAO,kBAAU,KAAK,EAAE,GAAG,EAAE,GAAG,kCAA+B,EAAE,6BAA0B,MAAM,GAAI,CAAC;AACxG,CAAC,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CACxC,SAAS,gBAAgB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG;IACvD,OAAO,CACL,kBAAU,KAAK,EAAE,GAAG,EAAE,GAAG,kCAAgC,IAAI,6BAA2B,MAAM,GAAI,CACnG,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAmC,SAAS,UAAU,CACxF,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,EACpB,GAAG;IAEH,OAAO,kBAAU,KAAK,EAAE,GAAG,EAAE,GAAG,kCAA+B,EAAE,6BAA0B,MAAM,GAAI,CAAC;AACxG,CAAC,CAAC,CAAC"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
/** Replaced content, form controls and non-HTML elements (SVG): they cannot be split at all. */
|
|
2
|
+
export declare function isMonolithic(element: Element): boolean;
|
|
1
3
|
export declare function canBreakElement(element: Element): boolean;
|
|
2
4
|
//# sourceMappingURL=avoid-break.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avoid-break.d.ts","sourceRoot":"","sources":["../../src/core/avoid-break.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"avoid-break.d.ts","sourceRoot":"","sources":["../../src/core/avoid-break.ts"],"names":[],"mappings":"AAcA,gGAAgG;AAChG,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAOtD;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAgBzD"}
|
package/dist/core/avoid-break.js
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
const MONOLITHIC_TAGS = [
|
|
2
|
+
"SVG",
|
|
3
|
+
"IMG",
|
|
4
|
+
"CANVAS",
|
|
5
|
+
"VIDEO",
|
|
6
|
+
"IFRAME",
|
|
7
|
+
"OBJECT",
|
|
8
|
+
"EMBED",
|
|
9
|
+
"INPUT",
|
|
10
|
+
"TEXTAREA",
|
|
11
|
+
"SELECT",
|
|
12
|
+
"BUTTON",
|
|
13
|
+
];
|
|
14
|
+
/** Replaced content, form controls and non-HTML elements (SVG): they cannot be split at all. */
|
|
15
|
+
export function isMonolithic(element) {
|
|
2
16
|
const view = element.ownerDocument.defaultView;
|
|
3
|
-
if (!view) {
|
|
4
|
-
return
|
|
5
|
-
}
|
|
6
|
-
if (!(element instanceof view.HTMLElement)) {
|
|
7
|
-
return false;
|
|
17
|
+
if (!view || !(element instanceof view.HTMLElement)) {
|
|
18
|
+
return true;
|
|
8
19
|
}
|
|
9
|
-
|
|
10
|
-
|
|
20
|
+
return MONOLITHIC_TAGS.includes(element.tagName.toUpperCase());
|
|
21
|
+
}
|
|
22
|
+
export function canBreakElement(element) {
|
|
23
|
+
if (isMonolithic(element)) {
|
|
11
24
|
return false;
|
|
12
25
|
}
|
|
13
|
-
const computedStyle =
|
|
26
|
+
const computedStyle = element.ownerDocument.defaultView.getComputedStyle(element);
|
|
14
27
|
if (["avoid", "avoid-page", "avoid-column"].includes(computedStyle.breakInside)) {
|
|
15
28
|
return false;
|
|
16
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avoid-break.js","sourceRoot":"","sources":["../../src/core/avoid-break.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"avoid-break.js","sourceRoot":"","sources":["../../src/core/avoid-break.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG;IACtB,KAAK;IACL,KAAK;IACL,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,OAAO;IACP,UAAU;IACV,QAAQ;IACR,QAAQ;CACT,CAAC;AAEF,gGAAgG;AAChG,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC;IAC/C,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,YAAY,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;QACpD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;AACjE,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,aAAa,GAAI,OAAO,CAAC,aAAa,CAAC,WAAsB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE9F,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;QAChF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,aAAa,CAAC,eAAe,KAAK,OAAO,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -19,5 +19,7 @@ export declare function createComputedStyleCache(): {
|
|
|
19
19
|
paddingBottom: number;
|
|
20
20
|
paddingTop: number;
|
|
21
21
|
};
|
|
22
|
+
/** Forget an element's style after pagination changed it. */
|
|
23
|
+
invalidate(element: Element): void;
|
|
22
24
|
};
|
|
23
25
|
//# sourceMappingURL=computed-style.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computed-style.d.ts","sourceRoot":"","sources":["../../src/core/computed-style.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,wBAAgB,wBAAwB;iBAIvB,OAAO;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"computed-style.d.ts","sourceRoot":"","sources":["../../src/core/computed-style.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,wBAAgB,wBAAwB;iBAIvB,OAAO;;;;;;;;;;IAYpB,6DAA6D;wBACzC,OAAO;EAI9B"}
|
|
@@ -11,6 +11,10 @@ export function createComputedStyleCache() {
|
|
|
11
11
|
styles.set(element, boxStyle);
|
|
12
12
|
return boxStyle;
|
|
13
13
|
},
|
|
14
|
+
/** Forget an element's style after pagination changed it. */
|
|
15
|
+
invalidate(element) {
|
|
16
|
+
styles.delete(element);
|
|
17
|
+
},
|
|
14
18
|
};
|
|
15
19
|
}
|
|
16
20
|
//# sourceMappingURL=computed-style.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computed-style.js","sourceRoot":"","sources":["../../src/core/computed-style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAazC,MAAM,UAAU,wBAAwB;IACtC,MAAM,MAAM,GAAG,IAAI,OAAO,EAAqB,CAAC;IAEhD,OAAO;QACL,GAAG,CAAC,OAAgB;YAClB,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAExC,IAAI,WAAW,EAAE,CAAC;gBAChB,OAAO,WAAW,CAAC;YACrB,CAAC;YAED,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;YAEtC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAC9B,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"computed-style.js","sourceRoot":"","sources":["../../src/core/computed-style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAazC,MAAM,UAAU,wBAAwB;IACtC,MAAM,MAAM,GAAG,IAAI,OAAO,EAAqB,CAAC;IAEhD,OAAO;QACL,GAAG,CAAC,OAAgB;YAClB,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAExC,IAAI,WAAW,EAAE,CAAC;gBAChB,OAAO,WAAW,CAAC;YACrB,CAAC;YAED,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;YAEtC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAC9B,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,6DAA6D;QAC7D,UAAU,CAAC,OAAgB;YACzB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type LineBox = {
|
|
2
|
+
top: number;
|
|
3
|
+
bottom: number;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Line boxes of a block that holds only inline content (text, spans, inline-blocks),
|
|
7
|
+
* in viewport coordinates. Returns null for blocks with block-level children, whose
|
|
8
|
+
* fragmentation is decided by those children instead.
|
|
9
|
+
*/
|
|
10
|
+
export declare function inlineLineBoxes(element: HTMLElement, view: Window): LineBox[] | null;
|
|
11
|
+
/**
|
|
12
|
+
* Groups fragment rects into line boxes, top to bottom. Rects on the same line are merged: for
|
|
13
|
+
* `white-space: pre` text Chrome reports a zero-width rect for each newline next to the line's text.
|
|
14
|
+
* A zero-height rect on a line of its own stays a separate line.
|
|
15
|
+
*/
|
|
16
|
+
export declare function groupLineBoxes(fragments: Iterable<{
|
|
17
|
+
top: number;
|
|
18
|
+
bottom: number;
|
|
19
|
+
}>): LineBox[];
|
|
20
|
+
/** Parses a computed `orphans` / `widows` value; CSS's initial value is 2. */
|
|
21
|
+
export declare function lineCount(value: string): number;
|
|
22
|
+
//# sourceMappingURL=line-boxes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-boxes.d.ts","sourceRoot":"","sources":["../../src/core/line-boxes.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,GAAG,IAAI,CAcpF;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,OAAO,EAAE,CAiB9F;AAED,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAG/C"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { measureRange } from "./measure-range.js";
|
|
2
|
+
/**
|
|
3
|
+
* Line boxes of a block that holds only inline content (text, spans, inline-blocks),
|
|
4
|
+
* in viewport coordinates. Returns null for blocks with block-level children, whose
|
|
5
|
+
* fragmentation is decided by those children instead.
|
|
6
|
+
*/
|
|
7
|
+
export function inlineLineBoxes(element, view) {
|
|
8
|
+
for (const child of Array.from(element.children)) {
|
|
9
|
+
if (!view.getComputedStyle(child).display.startsWith("inline"))
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (!element.textContent?.trim())
|
|
13
|
+
return null;
|
|
14
|
+
const range = measureRange(element.ownerDocument);
|
|
15
|
+
// Layout-less DOMs (jsdom) have no Range geometry; skip the adjustment there.
|
|
16
|
+
if (typeof range.getClientRects !== "function")
|
|
17
|
+
return null;
|
|
18
|
+
range.selectNodeContents(element);
|
|
19
|
+
return groupLineBoxes(Array.from(range.getClientRects()).filter((rect) => rect.width > 0 && rect.height > 0));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Groups fragment rects into line boxes, top to bottom. Rects on the same line are merged: for
|
|
23
|
+
* `white-space: pre` text Chrome reports a zero-width rect for each newline next to the line's text.
|
|
24
|
+
* A zero-height rect on a line of its own stays a separate line.
|
|
25
|
+
*/
|
|
26
|
+
export function groupLineBoxes(fragments) {
|
|
27
|
+
const rects = Array.from(fragments).sort((a, b) => a.top - b.top);
|
|
28
|
+
const lines = [];
|
|
29
|
+
for (const rect of rects) {
|
|
30
|
+
const line = lines.at(-1);
|
|
31
|
+
const overlapNeeded = Math.min(rect.bottom - rect.top, line ? line.bottom - line.top : 0) / 2;
|
|
32
|
+
// Fragments that overlap the previous line by more than half belong to it.
|
|
33
|
+
if (line && rect.top < line.bottom - overlapNeeded) {
|
|
34
|
+
line.top = Math.min(line.top, rect.top);
|
|
35
|
+
line.bottom = Math.max(line.bottom, rect.bottom);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
lines.push({ top: rect.top, bottom: rect.bottom });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return lines;
|
|
42
|
+
}
|
|
43
|
+
/** Parses a computed `orphans` / `widows` value; CSS's initial value is 2. */
|
|
44
|
+
export function lineCount(value) {
|
|
45
|
+
const count = Number.parseInt(value, 10);
|
|
46
|
+
return Number.isFinite(count) && count > 0 ? count : 2;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=line-boxes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-boxes.js","sourceRoot":"","sources":["../../src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CAAC,CAAC,CAAC,CAAC,CAAC;QAC1B,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAE9F,2EAA2E;QAC3E,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,aAAa,EAAE,CAAC;YACnD,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;YACxC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACnD,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One reusable Range per document for geometry reads. Every live Range must be updated by the
|
|
3
|
+
* browser on each DOM mutation until it is garbage collected, so creating one per measurement makes
|
|
4
|
+
* the many removals pagination performs progressively slower.
|
|
5
|
+
*/
|
|
6
|
+
export declare function measureRange(document: Document): Range;
|
|
7
|
+
//# sourceMappingURL=measure-range.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measure-range.d.ts","sourceRoot":"","sources":["../../src/core/measure-range.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,KAAK,CAOtD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const ranges = new WeakMap();
|
|
2
|
+
/**
|
|
3
|
+
* One reusable Range per document for geometry reads. Every live Range must be updated by the
|
|
4
|
+
* browser on each DOM mutation until it is garbage collected, so creating one per measurement makes
|
|
5
|
+
* the many removals pagination performs progressively slower.
|
|
6
|
+
*/
|
|
7
|
+
export function measureRange(document) {
|
|
8
|
+
let range = ranges.get(document);
|
|
9
|
+
if (!range) {
|
|
10
|
+
range = document.createRange();
|
|
11
|
+
ranges.set(document, range);
|
|
12
|
+
}
|
|
13
|
+
return range;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=measure-range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measure-range.js","sourceRoot":"","sources":["../../src/core/measure-range.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,IAAI,OAAO,EAAmB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,QAAkB;IAC7C,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC/B,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
declare const NUMBERING_SYSTEMS: {
|
|
2
|
+
readonly "arabic-indic": "arab";
|
|
3
|
+
readonly bengali: "beng";
|
|
4
|
+
readonly devanagari: "deva";
|
|
5
|
+
readonly gujarati: "gujr";
|
|
6
|
+
readonly gurmukhi: "guru";
|
|
7
|
+
readonly kannada: "knda";
|
|
8
|
+
readonly khmer: "khmr";
|
|
9
|
+
readonly lao: "laoo";
|
|
10
|
+
readonly malayalam: "mlym";
|
|
11
|
+
readonly mongolian: "mong";
|
|
12
|
+
readonly myanmar: "mymr";
|
|
13
|
+
readonly oriya: "orya";
|
|
14
|
+
readonly persian: "arabext";
|
|
15
|
+
readonly tamil: "tamldec";
|
|
16
|
+
readonly telugu: "telu";
|
|
17
|
+
readonly thai: "thai";
|
|
18
|
+
readonly tibetan: "tibt";
|
|
19
|
+
};
|
|
20
|
+
/** CSS counter style names a page number can be written in. */
|
|
21
|
+
export type PageNumberFormat = "decimal" | "decimal-leading-zero" | "lower-roman" | "upper-roman" | "lower-alpha" | "upper-alpha" | keyof typeof NUMBERING_SYSTEMS;
|
|
22
|
+
/**
|
|
23
|
+
* Writes a page number in a CSS counter style. Like CSS, roman numerals cover 1-3999 and letters
|
|
24
|
+
* start at 1; outside that range, and for unknown names, the number is written in decimal.
|
|
25
|
+
*/
|
|
26
|
+
export declare function formatPageNumber(value: number, format: string | null): string;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=page-number-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-number-format.d.ts","sourceRoot":"","sources":["../../src/core/page-number-format.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;CAkBb,CAAC;AAEX,+DAA+D;AAC/D,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,sBAAsB,GACtB,aAAa,GACb,aAAa,GACb,aAAa,GACb,aAAa,GACb,MAAM,OAAO,iBAAiB,CAAC;AAOnC;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAkC7E"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// CSS counter style names for native digits, mapped to Intl numbering systems.
|
|
2
|
+
const NUMBERING_SYSTEMS = {
|
|
3
|
+
"arabic-indic": "arab",
|
|
4
|
+
bengali: "beng",
|
|
5
|
+
devanagari: "deva",
|
|
6
|
+
gujarati: "gujr",
|
|
7
|
+
gurmukhi: "guru",
|
|
8
|
+
kannada: "knda",
|
|
9
|
+
khmer: "khmr",
|
|
10
|
+
lao: "laoo",
|
|
11
|
+
malayalam: "mlym",
|
|
12
|
+
mongolian: "mong",
|
|
13
|
+
myanmar: "mymr",
|
|
14
|
+
oriya: "orya",
|
|
15
|
+
persian: "arabext",
|
|
16
|
+
tamil: "tamldec",
|
|
17
|
+
telugu: "telu",
|
|
18
|
+
thai: "thai",
|
|
19
|
+
tibetan: "tibt",
|
|
20
|
+
};
|
|
21
|
+
const ROMAN = [
|
|
22
|
+
[1000, "m"], [900, "cm"], [500, "d"], [400, "cd"], [100, "c"], [90, "xc"],
|
|
23
|
+
[50, "l"], [40, "xl"], [10, "x"], [9, "ix"], [5, "v"], [4, "iv"], [1, "i"],
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* Writes a page number in a CSS counter style. Like CSS, roman numerals cover 1-3999 and letters
|
|
27
|
+
* start at 1; outside that range, and for unknown names, the number is written in decimal.
|
|
28
|
+
*/
|
|
29
|
+
export function formatPageNumber(value, format) {
|
|
30
|
+
if ((format === "lower-roman" || format === "upper-roman") && value >= 1 && value <= 3999) {
|
|
31
|
+
let rest = value;
|
|
32
|
+
let roman = "";
|
|
33
|
+
for (const [amount, letters] of ROMAN) {
|
|
34
|
+
while (rest >= amount) {
|
|
35
|
+
roman += letters;
|
|
36
|
+
rest -= amount;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (format === "upper-roman")
|
|
40
|
+
return roman.toUpperCase();
|
|
41
|
+
return roman;
|
|
42
|
+
}
|
|
43
|
+
if ((format === "lower-alpha" || format === "upper-alpha") && value >= 1) {
|
|
44
|
+
let rest = value;
|
|
45
|
+
let letters = "";
|
|
46
|
+
while (rest > 0) {
|
|
47
|
+
rest -= 1;
|
|
48
|
+
letters = String.fromCharCode(97 + (rest % 26)) + letters;
|
|
49
|
+
rest = Math.floor(rest / 26);
|
|
50
|
+
}
|
|
51
|
+
if (format === "upper-alpha")
|
|
52
|
+
return letters.toUpperCase();
|
|
53
|
+
return letters;
|
|
54
|
+
}
|
|
55
|
+
if (format === "decimal-leading-zero" && value >= 0 && value < 10)
|
|
56
|
+
return `0${value}`;
|
|
57
|
+
if (format !== null && format in NUMBERING_SYSTEMS) {
|
|
58
|
+
const numberingSystem = NUMBERING_SYSTEMS[format];
|
|
59
|
+
return new Intl.NumberFormat("en", { numberingSystem, useGrouping: false }).format(value);
|
|
60
|
+
}
|
|
61
|
+
return String(value);
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=page-number-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-number-format.js","sourceRoot":"","sources":["../../src/core/page-number-format.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,MAAM,iBAAiB,GAAG;IACxB,cAAc,EAAE,MAAM;IACtB,OAAO,EAAE,MAAM;IACf,UAAU,EAAE,MAAM;IAClB,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,MAAM;IAChB,OAAO,EAAE,MAAM;IACf,KAAK,EAAE,MAAM;IACb,GAAG,EAAE,MAAM;IACX,SAAS,EAAE,MAAM;IACjB,SAAS,EAAE,MAAM;IACjB,OAAO,EAAE,MAAM;IACf,KAAK,EAAE,MAAM;IACb,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,MAAM;CACP,CAAC;AAYX,MAAM,KAAK,GAA4B;IACrC,CAAC,IAAI,EAAE,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AAE,CAAC;YAChB,IAAI,IAAI,CAAC,CAAC;YACV,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC;YAC1D,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;QAC/B,CAAC;QACD,IAAI,MAAM,KAAK,aAAa;YAAE,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC;QAC3D,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,MAAM,KAAK,sBAAsB,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,EAAE;QAAE,OAAO,IAAI,KAAK,EAAE,CAAC;IAEtF,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,IAAI,iBAAiB,EAAE,CAAC;QACnD,MAAM,eAAe,GAAG,iBAAiB,CAAC,MAAwC,CAAC,CAAC;QACpF,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,eAAe,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5F,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginate.d.ts","sourceRoot":"","sources":["../../src/core/paginate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paginate.d.ts","sourceRoot":"","sources":["../../src/core/paginate.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAkB3D,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,uBAAuB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CA4B3F"}
|