postext 1.102.0 → 1.103.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 +3 -0
- package/dist/__tests__/annotate/anchors.test.d.ts +2 -0
- package/dist/__tests__/annotate/anchors.test.d.ts.map +1 -0
- package/dist/__tests__/annotate/anchors.test.js +161 -0
- package/dist/__tests__/annotate/anchors.test.js.map +1 -0
- package/dist/__tests__/annotate/fontPx.test.d.ts +2 -0
- package/dist/__tests__/annotate/fontPx.test.d.ts.map +1 -0
- package/dist/__tests__/annotate/fontPx.test.js +25 -0
- package/dist/__tests__/annotate/fontPx.test.js.map +1 -0
- package/dist/__tests__/annotate/marks.test.d.ts +2 -0
- package/dist/__tests__/annotate/marks.test.d.ts.map +1 -0
- package/dist/__tests__/annotate/marks.test.js +205 -0
- package/dist/__tests__/annotate/marks.test.js.map +1 -0
- package/dist/__tests__/defaults/headingsBalancing.test.js +8 -0
- package/dist/__tests__/defaults/headingsBalancing.test.js.map +1 -1
- package/dist/__tests__/exports.test.js +8 -0
- package/dist/__tests__/exports.test.js.map +1 -1
- package/dist/__tests__/geometry/rangeGeometry.test.d.ts +2 -0
- package/dist/__tests__/geometry/rangeGeometry.test.d.ts.map +1 -0
- package/dist/__tests__/geometry/rangeGeometry.test.js +167 -0
- package/dist/__tests__/geometry/rangeGeometry.test.js.map +1 -0
- package/dist/__tests__/paint/pageTransform.test.d.ts +2 -0
- package/dist/__tests__/paint/pageTransform.test.d.ts.map +1 -0
- package/dist/__tests__/paint/pageTransform.test.js +39 -0
- package/dist/__tests__/paint/pageTransform.test.js.map +1 -0
- package/dist/__tests__/pipeline/columns/shrinkListSpacing.test.d.ts +2 -0
- package/dist/__tests__/pipeline/columns/shrinkListSpacing.test.d.ts.map +1 -0
- package/dist/__tests__/pipeline/columns/shrinkListSpacing.test.js +91 -0
- package/dist/__tests__/pipeline/columns/shrinkListSpacing.test.js.map +1 -0
- package/dist/annotate/anchors.d.ts +70 -0
- package/dist/annotate/anchors.d.ts.map +1 -0
- package/dist/annotate/anchors.js +99 -0
- package/dist/annotate/anchors.js.map +1 -0
- package/dist/annotate/edits.d.ts +52 -0
- package/dist/annotate/edits.d.ts.map +1 -0
- package/dist/annotate/edits.js +84 -0
- package/dist/annotate/edits.js.map +1 -0
- package/dist/annotate/index.d.ts +17 -0
- package/dist/annotate/index.d.ts.map +1 -0
- package/dist/annotate/index.js +13 -0
- package/dist/annotate/index.js.map +1 -0
- package/dist/annotate/marks.d.ts +103 -0
- package/dist/annotate/marks.d.ts.map +1 -0
- package/dist/annotate/marks.js +398 -0
- package/dist/annotate/marks.js.map +1 -0
- package/dist/annotate/paint.d.ts +58 -0
- package/dist/annotate/paint.d.ts.map +1 -0
- package/dist/annotate/paint.js +130 -0
- package/dist/annotate/paint.js.map +1 -0
- package/dist/canvas-backend/index.d.ts.map +1 -1
- package/dist/canvas-backend/index.js +3 -0
- package/dist/canvas-backend/index.js.map +1 -1
- package/dist/checks/configWarnings/unknownKeys.js +1 -1
- package/dist/checks/configWarnings/unknownKeys.js.map +1 -1
- package/dist/defaults/structure/headings/defaults.d.ts +1 -0
- package/dist/defaults/structure/headings/defaults.d.ts.map +1 -1
- package/dist/defaults/structure/headings/defaults.js +1 -0
- package/dist/defaults/structure/headings/defaults.js.map +1 -1
- package/dist/defaults/structure/headings/resolve.d.ts.map +1 -1
- package/dist/defaults/structure/headings/resolve.js +1 -0
- package/dist/defaults/structure/headings/resolve.js.map +1 -1
- package/dist/defaults/structure/headings/strip.d.ts.map +1 -1
- package/dist/defaults/structure/headings/strip.js +5 -0
- package/dist/defaults/structure/headings/strip.js.map +1 -1
- package/dist/geometry/balloonText.d.ts +75 -0
- package/dist/geometry/balloonText.d.ts.map +1 -0
- package/dist/geometry/balloonText.js +266 -0
- package/dist/geometry/balloonText.js.map +1 -0
- package/dist/geometry/bandTitle.d.ts +53 -0
- package/dist/geometry/bandTitle.d.ts.map +1 -0
- package/dist/geometry/bandTitle.js +171 -0
- package/dist/geometry/bandTitle.js.map +1 -0
- package/dist/geometry/caret.d.ts +23 -0
- package/dist/geometry/caret.d.ts.map +1 -0
- package/dist/geometry/caret.js +62 -0
- package/dist/geometry/caret.js.map +1 -0
- package/dist/geometry/fontPx.d.ts +15 -0
- package/dist/geometry/fontPx.d.ts.map +1 -0
- package/dist/geometry/fontPx.js +38 -0
- package/dist/geometry/fontPx.js.map +1 -0
- package/dist/geometry/frameSpace.d.ts +31 -0
- package/dist/geometry/frameSpace.d.ts.map +1 -0
- package/dist/geometry/frameSpace.js +68 -0
- package/dist/geometry/frameSpace.js.map +1 -0
- package/dist/geometry/hitTest.d.ts +46 -0
- package/dist/geometry/hitTest.d.ts.map +1 -0
- package/dist/geometry/hitTest.js +162 -0
- package/dist/geometry/hitTest.js.map +1 -0
- package/dist/geometry/index.d.ts +25 -0
- package/dist/geometry/index.d.ts.map +1 -0
- package/dist/geometry/index.js +18 -0
- package/dist/geometry/index.js.map +1 -0
- package/dist/geometry/measureLanguage.d.ts +17 -0
- package/dist/geometry/measureLanguage.d.ts.map +1 -0
- package/dist/geometry/measureLanguage.js +116 -0
- package/dist/geometry/measureLanguage.js.map +1 -0
- package/dist/geometry/placement.d.ts +64 -0
- package/dist/geometry/placement.d.ts.map +1 -0
- package/dist/geometry/placement.js +158 -0
- package/dist/geometry/placement.js.map +1 -0
- package/dist/geometry/rangeGeometry.d.ts +147 -0
- package/dist/geometry/rangeGeometry.d.ts.map +1 -0
- package/dist/geometry/rangeGeometry.js +352 -0
- package/dist/geometry/rangeGeometry.js.map +1 -0
- package/dist/geometry/segmentText.d.ts +57 -0
- package/dist/geometry/segmentText.d.ts.map +1 -0
- package/dist/geometry/segmentText.js +145 -0
- package/dist/geometry/segmentText.js.map +1 -0
- package/dist/geometry/textGeometry.d.ts +59 -0
- package/dist/geometry/textGeometry.d.ts.map +1 -0
- package/dist/geometry/textGeometry.js +336 -0
- package/dist/geometry/textGeometry.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/pipeline/build/pass/lines/lineRoom.d.ts.map +1 -1
- package/dist/pipeline/build/pass/lines/lineRoom.js +45 -0
- package/dist/pipeline/build/pass/lines/lineRoom.js.map +1 -1
- package/dist/pipeline/build/pass/lines/listSpacing.d.ts +45 -0
- package/dist/pipeline/build/pass/lines/listSpacing.d.ts.map +1 -0
- package/dist/pipeline/build/pass/lines/listSpacing.js +115 -0
- package/dist/pipeline/build/pass/lines/listSpacing.js.map +1 -0
- package/dist/types/columnBalancing.d.ts +14 -0
- package/dist/types/columnBalancing.d.ts.map +1 -1
- package/dist/types/structure/headings.d.ts +1 -0
- package/dist/types/structure/headings.d.ts.map +1 -1
- package/dist/vdt/blocks.d.ts +7 -2
- package/dist/vdt/blocks.d.ts.map +1 -1
- package/package.json +9 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type VDTDocument } from '../vdt.js';
|
|
2
|
+
import { type VDTLine, type VDTSegment, type VDTBlock } from './segmentText.js';
|
|
3
|
+
/** Page-space position of a resource embed (inline block or float band). */
|
|
4
|
+
export interface ResourceLocation {
|
|
5
|
+
pageIndex: number;
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Find where a resource ended up in the laid-out document. Inline embeds live
|
|
11
|
+
* in `doc.blocks`; floated resources only exist in their page's float band.
|
|
12
|
+
*/
|
|
13
|
+
export declare function findResourceLocation(doc: VDTDocument, resourceId: string): ResourceLocation | null;
|
|
14
|
+
/** Walk already-positioned resource lines (caption / table cells): segments
|
|
15
|
+
* paint one after another from the line origin at natural widths, in
|
|
16
|
+
* `line.order` when the line holds right-to-left runs. */
|
|
17
|
+
export declare function segmentInResourceLines(lines: VDTLine[], xPage: number, yPage: number): VDTSegment | null;
|
|
18
|
+
/** The segment of a body-text line under `xPage` (flow frame), placed
|
|
19
|
+
* where the renderers paint it (see {@link placeLineSegments}). */
|
|
20
|
+
export declare function segmentInBlockLine(block: VDTBlock, line: VDTLine, xPage: number): VDTSegment | null;
|
|
21
|
+
/**
|
|
22
|
+
* A segment of a line where the renderers paint it, in the page's flow
|
|
23
|
+
* frame: `x` and the advance it gets (`width`, a justified space's share of
|
|
24
|
+
* the slack included), and the plain characters it stands for
|
|
25
|
+
* (`plainStart` is relative to the line). `reversed` says its characters
|
|
26
|
+
* run from its right edge to its left in the flow frame: a right-to-left
|
|
27
|
+
* run on a left-to-right page, or a left-to-right run on a mirrored page,
|
|
28
|
+
* whose flow is the sheet turned about its vertical axis.
|
|
29
|
+
*/
|
|
30
|
+
export interface PlacedSegment {
|
|
31
|
+
seg: VDTSegment;
|
|
32
|
+
x: number;
|
|
33
|
+
width: number;
|
|
34
|
+
plainStart: number;
|
|
35
|
+
plainLen: number;
|
|
36
|
+
reversed: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Where each segment of a body-text line is painted, in logical order,
|
|
40
|
+
* following the canvas line painter: from the line's start (its `measure`
|
|
41
|
+
* span on a block set against its frame), justified lines filling their
|
|
42
|
+
* span, centred and right-aligned lines shifted by their slack (as
|
|
43
|
+
* {@link lineTextAlign} reads the block's alignment), and the segments
|
|
44
|
+
* advancing in `line.order` when the line has one — a line holding
|
|
45
|
+
* right-to-left runs, or any line of a mirrored page. A caret or a click
|
|
46
|
+
* inside a bidi line then lands on the character painted there, not on the
|
|
47
|
+
* one at the same distance from the line's logical start. With `fold`, the
|
|
48
|
+
* runs of one `:ref` painted in pieces are one segment (see
|
|
49
|
+
* {@link foldRefRuns}) spanning all of them. `mirrored`: the line is on a
|
|
50
|
+
* right-to-left page (`pageIsMirrored`). Null for a line without segments.
|
|
51
|
+
*/
|
|
52
|
+
export declare function placeLineSegments(block: VDTBlock, line: VDTLine, mirrored: boolean, fold?: boolean): PlacedSegment[] | null;
|
|
53
|
+
/** The x (flow frame) of plain offset `within` of a placed segment. */
|
|
54
|
+
export declare function xInPlaced(p: PlacedSegment, within: number): number;
|
|
55
|
+
/** Whether page `pageIndex` of `doc` is set right to left in a mirrored
|
|
56
|
+
* flow frame. */
|
|
57
|
+
export declare function isMirroredPage(doc: VDTDocument, pageIndex: number): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Every visible resource embed painted on a page: inline `::resource` blocks
|
|
60
|
+
* from `doc.blocks` plus the page's float band(s). Float bands may carry
|
|
61
|
+
* non-resource blocks (fixed callouts); only `resourceBlock` carriers count.
|
|
62
|
+
*/
|
|
63
|
+
export declare function resourceBlocksOnPage(doc: VDTDocument, pageIndex: number): VDTBlock[];
|
|
64
|
+
//# sourceMappingURL=placement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placement.d.ts","sourceRoot":"","sources":["../../src/geometry/placement.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAiC,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAA2E,MAAM,kBAAkB,CAAC;AAEzJ,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,WAAW,EAChB,UAAU,EAAE,MAAM,GACjB,gBAAgB,GAAG,IAAI,CAczB;AAED;;2DAE2D;AAC3D,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EAAE,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,UAAU,GAAG,IAAI,CAenB;AAED;oEACoE;AACpE,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,QAAQ,EACf,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,MAAM,GACZ,UAAU,GAAG,IAAI,CAKnB;AASD;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,UAAU,CAAC;IAChB,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,UAAO,GAAG,aAAa,EAAE,GAAG,IAAI,CAmDxH;AAED,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAGlE;AAED;kBACkB;AAClB,wBAAgB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAG3E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,QAAQ,EAAE,CASpF"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Where things sit on a page: a resource's location, the segments of a
|
|
2
|
+
// line placed in paint order, mirrored pages and a page's resource blocks
|
|
3
|
+
// (#1276: split out of geometry.ts).
|
|
4
|
+
import { lineTextAlign, pageIsMirrored } from '../vdt.js';
|
|
5
|
+
import { segmentPlainLength, addsHyphen, opensWithRepeatedHyphen, xWithinSegment } from './segmentText.js';
|
|
6
|
+
/**
|
|
7
|
+
* Find where a resource ended up in the laid-out document. Inline embeds live
|
|
8
|
+
* in `doc.blocks`; floated resources only exist in their page's float band.
|
|
9
|
+
*/
|
|
10
|
+
export function findResourceLocation(doc, resourceId) {
|
|
11
|
+
for (const b of doc.blocks) {
|
|
12
|
+
if (b.resourceBlock?.resource.id === resourceId) {
|
|
13
|
+
return { pageIndex: b.pageIndex, x: b.bbox.x, y: b.bbox.y };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
for (const page of doc.pages) {
|
|
17
|
+
for (const fb of page.floats ?? []) {
|
|
18
|
+
if (fb.resourceBlock?.resource.id === resourceId) {
|
|
19
|
+
return { pageIndex: page.index, x: fb.bbox.x, y: fb.bbox.y };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
/** Walk already-positioned resource lines (caption / table cells): segments
|
|
26
|
+
* paint one after another from the line origin at natural widths, in
|
|
27
|
+
* `line.order` when the line holds right-to-left runs. */
|
|
28
|
+
export function segmentInResourceLines(lines, xPage, yPage) {
|
|
29
|
+
for (const line of lines) {
|
|
30
|
+
if (yPage < line.bbox.y || yPage > line.bbox.y + line.bbox.height)
|
|
31
|
+
continue;
|
|
32
|
+
const segs = line.segments;
|
|
33
|
+
if (!segs)
|
|
34
|
+
continue;
|
|
35
|
+
let x = line.bbox.x;
|
|
36
|
+
for (const i of paintOrder(line, segs.length)) {
|
|
37
|
+
const seg = segs[i];
|
|
38
|
+
if (xPage >= x && xPage <= x + seg.width) {
|
|
39
|
+
return seg;
|
|
40
|
+
}
|
|
41
|
+
x += seg.width;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
/** The segment of a body-text line under `xPage` (flow frame), placed
|
|
47
|
+
* where the renderers paint it (see {@link placeLineSegments}). */
|
|
48
|
+
export function segmentInBlockLine(block, line, xPage) {
|
|
49
|
+
for (const p of placeLineSegments(block, line, false, false) ?? []) {
|
|
50
|
+
if (xPage >= p.x && xPage <= p.x + p.width)
|
|
51
|
+
return p.seg;
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
/** The indices of `n` segments in the order the renderers advance through
|
|
56
|
+
* them: `line.order` when it lists them all, else logical order. */
|
|
57
|
+
function paintOrder(line, n) {
|
|
58
|
+
if (line.order && line.order.length === n)
|
|
59
|
+
return line.order;
|
|
60
|
+
return Array.from({ length: n }, (_, i) => i);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Where each segment of a body-text line is painted, in logical order,
|
|
64
|
+
* following the canvas line painter: from the line's start (its `measure`
|
|
65
|
+
* span on a block set against its frame), justified lines filling their
|
|
66
|
+
* span, centred and right-aligned lines shifted by their slack (as
|
|
67
|
+
* {@link lineTextAlign} reads the block's alignment), and the segments
|
|
68
|
+
* advancing in `line.order` when the line has one — a line holding
|
|
69
|
+
* right-to-left runs, or any line of a mirrored page. A caret or a click
|
|
70
|
+
* inside a bidi line then lands on the character painted there, not on the
|
|
71
|
+
* one at the same distance from the line's logical start. With `fold`, the
|
|
72
|
+
* runs of one `:ref` painted in pieces are one segment (see
|
|
73
|
+
* {@link foldRefRuns}) spanning all of them. `mirrored`: the line is on a
|
|
74
|
+
* right-to-left page (`pageIsMirrored`). Null for a line without segments.
|
|
75
|
+
*/
|
|
76
|
+
export function placeLineSegments(block, line, mirrored, fold = true) {
|
|
77
|
+
const segs = line.segments;
|
|
78
|
+
if (!segs || segs.length === 0)
|
|
79
|
+
return null;
|
|
80
|
+
const span = line.measure;
|
|
81
|
+
const lineX = span ? span.x : line.bbox.x;
|
|
82
|
+
const effectiveWidth = span ? span.width : block.bbox.x + block.bbox.width - lineX;
|
|
83
|
+
let naturalWidth = 0;
|
|
84
|
+
let wordWidth = 0;
|
|
85
|
+
let spaceCount = 0;
|
|
86
|
+
for (const seg of segs) {
|
|
87
|
+
naturalWidth += seg.width;
|
|
88
|
+
if (seg.kind === 'space')
|
|
89
|
+
spaceCount++;
|
|
90
|
+
else
|
|
91
|
+
wordWidth += seg.width;
|
|
92
|
+
}
|
|
93
|
+
// A line set ragged inside a justified paragraph (a loose CJK line, a
|
|
94
|
+
// line a URL left unfillable) is painted at its natural width; an
|
|
95
|
+
// overfull last line has its spaces compressed to the measure. A line
|
|
96
|
+
// holding a tab stop is set as measured (#622).
|
|
97
|
+
const justify = block.textAlign === 'justify' && spaceCount > 0 && !line.tabbed
|
|
98
|
+
&& ((line.isLastLine === false && !line.ragged) || naturalWidth > effectiveWidth);
|
|
99
|
+
const spaceWidth = justify ? (effectiveWidth - wordWidth) / spaceCount : undefined;
|
|
100
|
+
const align = lineTextAlign(line, block.textAlign);
|
|
101
|
+
const slack = Math.max(0, effectiveWidth - naturalWidth);
|
|
102
|
+
const start = lineX + (justify ? 0 : align === 'center' ? slack / 2 : align === 'right' ? slack : 0);
|
|
103
|
+
const xs = new Array(segs.length).fill(start);
|
|
104
|
+
const widths = segs.map((seg) => (seg.kind === 'space' && spaceWidth !== undefined ? spaceWidth : seg.width));
|
|
105
|
+
let x = start;
|
|
106
|
+
for (const i of paintOrder(line, segs.length)) {
|
|
107
|
+
xs[i] = x;
|
|
108
|
+
x += widths[i];
|
|
109
|
+
}
|
|
110
|
+
const out = [];
|
|
111
|
+
const lastIdx = segs.length - 1;
|
|
112
|
+
let cum = 0;
|
|
113
|
+
for (let i = 0; i < segs.length; i++) {
|
|
114
|
+
const seg = segs[i];
|
|
115
|
+
const plainLen = segmentPlainLength(seg, i === lastIdx && addsHyphen(line), opensWithRepeatedHyphen(line, i));
|
|
116
|
+
const last = out[out.length - 1];
|
|
117
|
+
if (fold && seg.refContinues && last && last.seg.refResourceId === seg.refResourceId) {
|
|
118
|
+
// One reference painted in pieces: one box over all of them.
|
|
119
|
+
const left = Math.min(last.x, xs[i]);
|
|
120
|
+
const right = Math.max(last.x + last.width, xs[i] + widths[i]);
|
|
121
|
+
out[out.length - 1] = { ...last, seg: { ...last.seg, text: last.seg.text + seg.text, width: last.seg.width + seg.width }, x: left, width: right - left };
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
out.push({ seg, x: xs[i], width: widths[i], plainStart: cum, plainLen, reversed: (seg.rtl === true) !== mirrored });
|
|
125
|
+
}
|
|
126
|
+
cum += plainLen;
|
|
127
|
+
}
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
/** The x (flow frame) of plain offset `within` of a placed segment. */
|
|
131
|
+
export function xInPlaced(p, within) {
|
|
132
|
+
const dx = xWithinSegment(p.seg, within, p.plainLen, p.width);
|
|
133
|
+
return p.reversed ? p.x + p.width - dx : p.x + dx;
|
|
134
|
+
}
|
|
135
|
+
/** Whether page `pageIndex` of `doc` is set right to left in a mirrored
|
|
136
|
+
* flow frame. */
|
|
137
|
+
export function isMirroredPage(doc, pageIndex) {
|
|
138
|
+
const page = doc.pages[pageIndex];
|
|
139
|
+
return page ? pageIsMirrored(page) : false;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Every visible resource embed painted on a page: inline `::resource` blocks
|
|
143
|
+
* from `doc.blocks` plus the page's float band(s). Float bands may carry
|
|
144
|
+
* non-resource blocks (fixed callouts); only `resourceBlock` carriers count.
|
|
145
|
+
*/
|
|
146
|
+
export function resourceBlocksOnPage(doc, pageIndex) {
|
|
147
|
+
const out = [];
|
|
148
|
+
for (const b of doc.blocks) {
|
|
149
|
+
if (b.pageIndex === pageIndex && b.resourceBlock && !b.hidden)
|
|
150
|
+
out.push(b);
|
|
151
|
+
}
|
|
152
|
+
for (const fb of doc.pages[pageIndex]?.floats ?? []) {
|
|
153
|
+
if (fb.resourceBlock && !fb.hidden)
|
|
154
|
+
out.push(fb);
|
|
155
|
+
}
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=placement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placement.js","sourceRoot":"","sources":["../../src/geometry/placement.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,0EAA0E;AAC1E,qCAAqC;AACrC,OAAO,EAAoB,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAgD,kBAAkB,EAAE,UAAU,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AASzJ;;;GAGG;AACH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,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text on the page (#1761): where a range of the Markdown is painted, and
|
|
3
|
+
* the caret, the word and the block under a point. The reverse of
|
|
4
|
+
* {@link sourceAt} at the precision of a character, for a host that draws
|
|
5
|
+
* marks over the pages (a highlight, a struck word, a caret) or turns a
|
|
6
|
+
* press on the page into a range of its text.
|
|
7
|
+
*
|
|
8
|
+
* Everything is read from what the layout stamped on the VDT, with the
|
|
9
|
+
* same placement the canvas, the HTML and the PDF paint with
|
|
10
|
+
* ({@link placeLineSegments}): justified spacing, bidi lines, right-to-left
|
|
11
|
+
* and vertical pages, warichu, drop caps, opener band titles, composed
|
|
12
|
+
* frames turned and scaled, comic balloons, text a story carried in from
|
|
13
|
+
* another chapter.
|
|
14
|
+
*
|
|
15
|
+
* Offsets are UTF-16 indices in the chapter's Markdown file, front matter
|
|
16
|
+
* counted, as every `sourceStart` of the VDT and `sourceAt` count them.
|
|
17
|
+
* Coordinates are page px on the sheet, from its top-left corner.
|
|
18
|
+
*/
|
|
19
|
+
import type { BoundingBox, VDTDocument } from '../vdt.js';
|
|
20
|
+
import { type FramePoint } from './frameSpace.js';
|
|
21
|
+
/** A range of a chapter's Markdown, `[start, end)`. */
|
|
22
|
+
export interface TextRange {
|
|
23
|
+
start: number;
|
|
24
|
+
end: number;
|
|
25
|
+
}
|
|
26
|
+
/** Which chapter's Markdown the offsets are in. */
|
|
27
|
+
export interface TextGeometryOptions {
|
|
28
|
+
/** The position in the book of the chapter the offsets are in. Absent:
|
|
29
|
+
* the document's own file. Set it to reach text a story carried in from
|
|
30
|
+
* another chapter (`VDTBlock.sourceChapter`, #943). */
|
|
31
|
+
chapter?: number;
|
|
32
|
+
/** The position in the book of the chapter `doc` lays out, when the host
|
|
33
|
+
* knows it: a `chapter` equal to it means the document's own file. */
|
|
34
|
+
ownChapter?: number;
|
|
35
|
+
/** Only these pages, `[from, to)`: a document stitched from several
|
|
36
|
+
* chapters holds every chapter's offsets, so a host looks a range up
|
|
37
|
+
* among its chapter's pages. */
|
|
38
|
+
pages?: {
|
|
39
|
+
from: number;
|
|
40
|
+
to: number;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Four corners on the sheet, in the order of the text's own frame: the
|
|
44
|
+
* top-left, top-right, bottom-right and bottom-left of the piece as the
|
|
45
|
+
* line runs (on a vertical page the line's "top" is its right side). */
|
|
46
|
+
export type TextQuad = [FramePoint, FramePoint, FramePoint, FramePoint];
|
|
47
|
+
/** One piece of a range: a run of a line painted side by side. */
|
|
48
|
+
export interface TextRect {
|
|
49
|
+
pageIndex: number;
|
|
50
|
+
/** The block the piece is in (a balloon's id for comic lettering). */
|
|
51
|
+
blockId: string;
|
|
52
|
+
/** The piece's bounds on the sheet, axis-aligned. */
|
|
53
|
+
rect: BoundingBox;
|
|
54
|
+
/** Its corners on the sheet; differs from `rect` when the piece is
|
|
55
|
+
* turned (a vertical page, a turned frame, a leaned balloon). */
|
|
56
|
+
quad: TextQuad;
|
|
57
|
+
/** The baseline under the piece, from its left end to its right end in
|
|
58
|
+
* the line's frame, on the sheet. */
|
|
59
|
+
baseline: [FramePoint, FramePoint];
|
|
60
|
+
/** Set when the piece is upright on the sheet (`rect` is the piece). */
|
|
61
|
+
upright?: true;
|
|
62
|
+
/** The size of the text (px, its em), as far as the block says: marks
|
|
63
|
+
* that set text of their own are sized from it. */
|
|
64
|
+
fontSize: number;
|
|
65
|
+
}
|
|
66
|
+
/** A caret: a line across the text at a character boundary, on the sheet. */
|
|
67
|
+
export interface CaretLine {
|
|
68
|
+
pageIndex: number;
|
|
69
|
+
blockId: string;
|
|
70
|
+
/** Where the caret's line starts (the top of the text line in its own
|
|
71
|
+
* frame) and ends (its foot). */
|
|
72
|
+
from: FramePoint;
|
|
73
|
+
to: FramePoint;
|
|
74
|
+
}
|
|
75
|
+
/** What {@link caretAt} found under a point. */
|
|
76
|
+
export interface CaretHit {
|
|
77
|
+
/** The Markdown offset of the character boundary nearest the point. */
|
|
78
|
+
offset: number;
|
|
79
|
+
/** The position in the book of the chapter whose Markdown `offset` is
|
|
80
|
+
* in, when that is not the document's own (text carried in, #943). */
|
|
81
|
+
chapter?: number;
|
|
82
|
+
pageIndex: number;
|
|
83
|
+
blockId: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The pieces a Markdown range covers on the pages: one per run of a line
|
|
87
|
+
* painted side by side (a bidi line shows a range as the pieces its
|
|
88
|
+
* characters are painted in), in page order and, within a page, in the
|
|
89
|
+
* order of the text. Empty when no text of the range is on the pages (a
|
|
90
|
+
* range of front matter, of a resource's own text, of a chapter the
|
|
91
|
+
* document does not lay out).
|
|
92
|
+
*/
|
|
93
|
+
export declare function rangeRects(doc: VDTDocument, range: TextRange, options?: TextGeometryOptions): TextRect[];
|
|
94
|
+
/**
|
|
95
|
+
* Where a caret at Markdown offset `offset` is painted: a line across the
|
|
96
|
+
* text line at that character boundary, on the sheet. Null when no text of
|
|
97
|
+
* the offset is on the pages. An offset between two blocks goes to the
|
|
98
|
+
* nearer one (the one before it on a tie).
|
|
99
|
+
*/
|
|
100
|
+
export declare function caretRect(doc: VDTDocument, offset: number, options?: TextGeometryOptions): CaretLine | null;
|
|
101
|
+
/**
|
|
102
|
+
* The caret under a point of page `pageIndex` (sheet px): the Markdown
|
|
103
|
+
* offset of the character boundary nearest it, in the text line nearest
|
|
104
|
+
* it within the block under it. Null off the text. A point on a drop cap
|
|
105
|
+
* lands before it, or after it on its right half.
|
|
106
|
+
*/
|
|
107
|
+
export declare function caretAt(doc: VDTDocument, pageIndex: number, x: number, y: number, options?: Pick<TextGeometryOptions, 'ownChapter'>): CaretHit | null;
|
|
108
|
+
/** What {@link blockAt} found: the block's whole range of Markdown. */
|
|
109
|
+
export interface BlockHit extends TextRange {
|
|
110
|
+
pageIndex: number;
|
|
111
|
+
blockId: string;
|
|
112
|
+
chapter?: number;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The block under a point (sheet px): its range of Markdown, for a triple
|
|
116
|
+
* click that selects a paragraph. A paragraph split over pages answers
|
|
117
|
+
* with its whole range.
|
|
118
|
+
*/
|
|
119
|
+
export declare function blockAt(doc: VDTDocument, pageIndex: number, x: number, y: number, options?: Pick<TextGeometryOptions, 'ownChapter'>): BlockHit | null;
|
|
120
|
+
/** Options of {@link wordRangeAt}. */
|
|
121
|
+
export interface WordRangeOptions {
|
|
122
|
+
/** The language of the text, for word segmentation (a BCP 47 tag). */
|
|
123
|
+
locale?: string;
|
|
124
|
+
/** Keep the word inside these bounds (a block's range). */
|
|
125
|
+
within?: TextRange;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The word of `markdown` at `offset`: the word-like segment (`Intl.
|
|
129
|
+
* Segmenter`, by `locale`) that holds the offset or ends at it, else the
|
|
130
|
+
* one that starts at it; null between words. Markdown syntax round a word
|
|
131
|
+
* (`**`, `_`) is not part of it.
|
|
132
|
+
*/
|
|
133
|
+
export declare function wordRangeAt(markdown: string, offset: number, options?: WordRangeOptions): TextRange | null;
|
|
134
|
+
/**
|
|
135
|
+
* The word under a point (sheet px), as a range of the chapter's Markdown:
|
|
136
|
+
* {@link caretAt} then {@link wordRangeAt} inside the block hit. The host
|
|
137
|
+
* passes the Markdown of the chapter the hit names (`chapter`), which the
|
|
138
|
+
* laid-out document does not keep.
|
|
139
|
+
*/
|
|
140
|
+
export declare function wordAt(doc: VDTDocument, pageIndex: number, x: number, y: number, markdown: string | ((chapter: number | undefined) => string | undefined), options?: Pick<TextGeometryOptions, 'ownChapter'> & {
|
|
141
|
+
locale?: string;
|
|
142
|
+
}): (TextRange & {
|
|
143
|
+
pageIndex: number;
|
|
144
|
+
blockId: string;
|
|
145
|
+
chapter?: number;
|
|
146
|
+
}) | null;
|
|
147
|
+
//# sourceMappingURL=rangeGeometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rangeGeometry.d.ts","sourceRoot":"","sources":["../../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