uhuu-components 0.3.10 → 0.3.12
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/index.d.ts +120 -0
- package/package.json +1 -1
- package/uhuu-components.es.js +3866 -3251
- package/uhuu-components.es.js.map +1 -1
- package/uhuu-components.umd.cjs +24 -20
- package/uhuu-components.umd.cjs.map +1 -1
package/index.d.ts
CHANGED
|
@@ -14,10 +14,56 @@ export interface StaticFlowItemMeta {
|
|
|
14
14
|
breakBefore?: boolean;
|
|
15
15
|
breakAfter?: boolean;
|
|
16
16
|
keepWithNext?: boolean | number;
|
|
17
|
+
/** Never split the item; with `groupKey`, also move its avoid-break group as one. */
|
|
17
18
|
avoidBreakInside?: boolean;
|
|
18
19
|
groupKey?: string;
|
|
20
|
+
/** An item split between the lines of its `Static.FlowText`: fewest lines on a piece that ends a page. Default 2. */
|
|
21
|
+
orphans?: number;
|
|
22
|
+
/** An item split between the lines of its `Static.FlowText`: fewest lines on the piece that starts the next page. Default 2. */
|
|
23
|
+
widows?: number;
|
|
19
24
|
}
|
|
20
25
|
|
|
26
|
+
/**
|
|
27
|
+
* The lines of an item's `Static.FlowText` (`Static.flowMeasure.readFlowTextLines`), in layout px
|
|
28
|
+
* from the item's measured origin: each line box's top and bottom, and the UTF-16 text offset
|
|
29
|
+
* (across the FlowText's text nodes in order) where it starts. `end`: the text's length.
|
|
30
|
+
*/
|
|
31
|
+
export interface StaticFlowItemLines {
|
|
32
|
+
/** `hyphen`: the line ends with a hyphen the browser drew (`hyphens: auto`, a soft hyphen). */
|
|
33
|
+
lines: Array<{ top: number; bottom: number; start: number; hyphen?: boolean }>;
|
|
34
|
+
end: number;
|
|
35
|
+
justify: boolean;
|
|
36
|
+
/** The text's computed CSS `orphans` / `widows`, where the browser reports them; the item's meta wins. */
|
|
37
|
+
orphans?: number;
|
|
38
|
+
widows?: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** One piece of an item split between the lines of its `Static.FlowText`. */
|
|
42
|
+
export interface StaticFlowTextSplit {
|
|
43
|
+
/** 0-based piece number. */
|
|
44
|
+
part: number;
|
|
45
|
+
parts: number;
|
|
46
|
+
/** The piece's text: UTF-16 offsets `[from, to)` across the FlowText's text. */
|
|
47
|
+
from: number;
|
|
48
|
+
to: number;
|
|
49
|
+
/** Justified text: a piece that ends mid-paragraph justifies its last line too. */
|
|
50
|
+
justify?: boolean;
|
|
51
|
+
/** The planned height of the piece's lines, in layout px. */
|
|
52
|
+
textHeight?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Text offsets where the piece's measured lines broke with a hyphen (`hyphens: auto`, a soft
|
|
55
|
+
* hyphen), its own end included: the piece breaks there again, and ends with a hyphen there.
|
|
56
|
+
*/
|
|
57
|
+
hyphens?: number[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Why an item's FlowText cannot split, or splits but may not match its plan. */
|
|
61
|
+
export type StaticFlowTextIssue =
|
|
62
|
+
| "multiple-flow-text"
|
|
63
|
+
| "inline-flow-text"
|
|
64
|
+
| "unsupported-content"
|
|
65
|
+
| "rewrapping-text-wrap";
|
|
66
|
+
|
|
21
67
|
/** A separately measured group whose header may repeat on virtual continuation pages. */
|
|
22
68
|
export interface StaticFlowItemGroup {
|
|
23
69
|
key: string;
|
|
@@ -42,6 +88,11 @@ export interface StaticFlowFragmentContext<TItem = unknown> {
|
|
|
42
88
|
isContinuation: boolean;
|
|
43
89
|
/** The group resumed from the preceding virtual page. */
|
|
44
90
|
isGroupContinuation: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Present on every piece of an item split between the lines of its `Static.FlowText`; absent for
|
|
93
|
+
* an item rendered whole and in the measurement copy, which renders the whole item.
|
|
94
|
+
*/
|
|
95
|
+
split?: { part: number; parts: number; from: number; to: number };
|
|
45
96
|
}
|
|
46
97
|
|
|
47
98
|
export interface StaticFlowUnplaceableItem {
|
|
@@ -79,6 +130,8 @@ export interface StaticFlowChunk {
|
|
|
79
130
|
groupHeaders?: StaticFlowGroupHeaderFragment[];
|
|
80
131
|
unplaceable?: StaticFlowUnplaceableItem;
|
|
81
132
|
layout?: StaticFlowLayoutFragment[];
|
|
133
|
+
/** The pieces of items split between lines on this page, by item index. */
|
|
134
|
+
splits?: Record<number, StaticFlowTextSplit>;
|
|
82
135
|
}
|
|
83
136
|
|
|
84
137
|
export interface StaticFlowColumn {
|
|
@@ -151,8 +204,34 @@ export interface StaticFlowMeasureApi {
|
|
|
151
204
|
readUnwrappedHeights: (area: HTMLElement, flow: HTMLElement, scale?: number) => Map<HTMLElement, number>;
|
|
152
205
|
/** Every measured leaf under `root`, in document order. */
|
|
153
206
|
readFlowItemElements: (root: HTMLElement) => HTMLElement[];
|
|
207
|
+
/**
|
|
208
|
+
* The first of `items` that does not lie below the item before it in `area` (beside it, in
|
|
209
|
+
* another column), or `null`: such a flow cannot be planned (`unstacked-flow-items`).
|
|
210
|
+
*/
|
|
211
|
+
readUnstackedItem: (area: HTMLElement, flow: HTMLElement, items: HTMLElement[]) => HTMLElement | null;
|
|
212
|
+
/**
|
|
213
|
+
* A CSS length with an absolute unit (`"20mm"`, `"12px"`) or a number of px, in CSS px;
|
|
214
|
+
* `undefined` for anything else. What `breakReserve` is read with.
|
|
215
|
+
*/
|
|
216
|
+
parseAbsoluteLength: (value: number | string | undefined) => number | undefined;
|
|
154
217
|
parseKeepWithNext: (value: string | undefined) => boolean | number;
|
|
155
218
|
serializeKeepWithNext: (value: StaticFlowItemMeta['keepWithNext']) => string | undefined;
|
|
219
|
+
/** `orphans` / `widows` attribute values: a positive whole number, else `undefined`. */
|
|
220
|
+
parseLineCount: (value: string | undefined) => number | undefined;
|
|
221
|
+
serializeLineCount: (value: number | undefined) => string | undefined;
|
|
222
|
+
/** The `Static.FlowText` elements of `item` itself (not those of a Flow nested in it). */
|
|
223
|
+
readItemFlowTexts: (item: HTMLElement) => HTMLElement[];
|
|
224
|
+
/**
|
|
225
|
+
* The lines of the one `Static.FlowText` in a measured item, for `planFlowChunks({ lines })`, or
|
|
226
|
+
* `undefined` when it has none or cannot split (`report` says why). `height` is the item's
|
|
227
|
+
* measured height (`getOuterHeight`, or `readUnwrappedHeights` for `asChild`).
|
|
228
|
+
*/
|
|
229
|
+
readFlowTextLines: (
|
|
230
|
+
item: HTMLElement,
|
|
231
|
+
height: number,
|
|
232
|
+
scale?: number,
|
|
233
|
+
report?: (issue: StaticFlowTextIssue, element: HTMLElement) => void
|
|
234
|
+
) => StaticFlowItemLines | undefined;
|
|
156
235
|
/** FNV-1a. For opaque change-detection tokens compared only for equality. */
|
|
157
236
|
hashString: (value: string) => string;
|
|
158
237
|
}
|
|
@@ -171,6 +250,18 @@ export interface StaticFlowPlanInput {
|
|
|
171
250
|
headerGroupRepeats?: Record<string, boolean>;
|
|
172
251
|
onUnplaceableItem?: (item: StaticFlowUnplaceableItem) => void;
|
|
173
252
|
metrics?: StaticFlowPlanMetrics;
|
|
253
|
+
/**
|
|
254
|
+
* Line metrics per item (`flowMeasure.readFlowTextLines`); `undefined` for items that do not
|
|
255
|
+
* split. An item that does not fit the room left is split at a line (chunks gain `splits`).
|
|
256
|
+
* Without `lines` the plan is item-level. `planFlowColumnChunks` does not split.
|
|
257
|
+
*/
|
|
258
|
+
lines?: Array<StaticFlowItemLines | undefined>;
|
|
259
|
+
/**
|
|
260
|
+
* Room kept free at the bottom of every page the flow breaks from, in px; the page it ends on
|
|
261
|
+
* keeps its full region, so a flow that fits one page plans as without it. 0 by default; a
|
|
262
|
+
* reserve of a page or more is ignored. `planFlowColumnChunks` does not take it.
|
|
263
|
+
*/
|
|
264
|
+
breakReserve?: number;
|
|
174
265
|
}
|
|
175
266
|
|
|
176
267
|
/** Input for `Static.planFlowColumnChunks`, using globally indexed leaf measurements. */
|
|
@@ -797,6 +888,13 @@ export interface StaticFlowAreaProps {
|
|
|
797
888
|
* and plans every later sheet with that height. Default: every sheet has the first one's height.
|
|
798
889
|
*/
|
|
799
890
|
measureContinuation?: boolean;
|
|
891
|
+
/**
|
|
892
|
+
* Room kept free at the bottom of every sheet the flow continues from, so a break never sits on
|
|
893
|
+
* the sheet's edge; the sheet the flow ends on keeps its full area, and a flow that fits one
|
|
894
|
+
* sheet lays out as without it. A CSS length with an absolute unit (`"20mm"`, `"12px"`) or a
|
|
895
|
+
* number of px. `Static.FlowColumns` does not keep it.
|
|
896
|
+
*/
|
|
897
|
+
breakReserve?: number | string;
|
|
800
898
|
}
|
|
801
899
|
|
|
802
900
|
export interface StaticFlowPageProps {
|
|
@@ -810,6 +908,8 @@ export interface StaticFlowPageProps {
|
|
|
810
908
|
onFlowMeasurement?: (measurement: StaticFlowMeasurement) => void;
|
|
811
909
|
/** See `StaticFlowAreaProps.measureContinuation`. */
|
|
812
910
|
measureContinuation?: boolean;
|
|
911
|
+
/** See `StaticFlowAreaProps.breakReserve`. */
|
|
912
|
+
breakReserve?: number | string;
|
|
813
913
|
}
|
|
814
914
|
|
|
815
915
|
export interface StaticFlowProps<TItem = unknown> {
|
|
@@ -854,6 +954,19 @@ export interface StaticFlowProps<TItem = unknown> {
|
|
|
854
954
|
as?: keyof HTMLElementTagNameMap;
|
|
855
955
|
}
|
|
856
956
|
|
|
957
|
+
export interface StaticFlowTextProps {
|
|
958
|
+
/**
|
|
959
|
+
* A string (may contain `\n`) or inline content: text, `span`, `strong`, `em`, `b`, `i`, `a`,
|
|
960
|
+
* `small`, `sub`, `sup`, `br` (and other inline text elements) and fragments. Anything else
|
|
961
|
+
* renders, with a development warning, but its item is not split.
|
|
962
|
+
*/
|
|
963
|
+
children?: ReactNode;
|
|
964
|
+
/** Default `div`: a block, so its line boxes are its own. */
|
|
965
|
+
as?: keyof HTMLElementTagNameMap;
|
|
966
|
+
className?: string;
|
|
967
|
+
style?: CSSProperties;
|
|
968
|
+
}
|
|
969
|
+
|
|
857
970
|
export interface StaticFlowColumnsRenderContext {
|
|
858
971
|
/** Stable identity only: column geometry callbacks must be page-invariant. */
|
|
859
972
|
flowId: string;
|
|
@@ -914,6 +1027,8 @@ export interface StaticFlowDocumentProps {
|
|
|
914
1027
|
flowAreaStyle?: CSSProperties;
|
|
915
1028
|
/** See `StaticFlowAreaProps.measureContinuation`. */
|
|
916
1029
|
measureContinuation?: boolean;
|
|
1030
|
+
/** See `StaticFlowAreaProps.breakReserve`. */
|
|
1031
|
+
breakReserve?: number | string;
|
|
917
1032
|
id?: string;
|
|
918
1033
|
idPrefix?: string;
|
|
919
1034
|
flowClassName?: string;
|
|
@@ -1000,6 +1115,11 @@ export const Static: {
|
|
|
1000
1115
|
FlowPage: ComponentType<StaticFlowPageProps>;
|
|
1001
1116
|
Flow: <TItem = unknown>(props: StaticFlowProps<TItem>) => ReactElement | null;
|
|
1002
1117
|
FlowColumns: <TItem = unknown>(props: StaticFlowColumnsProps<TItem>) => ReactElement | null;
|
|
1118
|
+
/**
|
|
1119
|
+
* Text a `Static.Flow` item may split between lines when it does not fit the room left on its
|
|
1120
|
+
* sheet (one per item; `orphans`/`widows` in the item's meta). Renders `<as data-uhuu-flow-text>`.
|
|
1121
|
+
*/
|
|
1122
|
+
FlowText: ComponentType<StaticFlowTextProps>;
|
|
1003
1123
|
planFlowChunks: (input?: StaticFlowPlanInput) => StaticFlowChunk[];
|
|
1004
1124
|
planFlowColumnChunks: (input?: StaticFlowColumnPlanInput) => StaticFlowChunk[];
|
|
1005
1125
|
createFlowPlanMetrics: () => StaticFlowPlanMetrics;
|
package/package.json
CHANGED