@graphrefly/graphrefly 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +234 -0
- package/dist/chunk-5X3LAO3B.js +1571 -0
- package/dist/chunk-5X3LAO3B.js.map +1 -0
- package/dist/chunk-6W5SGIGB.js +1793 -0
- package/dist/chunk-6W5SGIGB.js.map +1 -0
- package/dist/chunk-CP6MNKAA.js +97 -0
- package/dist/chunk-CP6MNKAA.js.map +1 -0
- package/dist/chunk-HP7OKEOE.js +107 -0
- package/dist/chunk-HP7OKEOE.js.map +1 -0
- package/dist/chunk-KWXPDASV.js +781 -0
- package/dist/chunk-KWXPDASV.js.map +1 -0
- package/dist/chunk-O3PI7W45.js +68 -0
- package/dist/chunk-O3PI7W45.js.map +1 -0
- package/dist/chunk-QW7H3ICI.js +1372 -0
- package/dist/chunk-QW7H3ICI.js.map +1 -0
- package/dist/chunk-VPS7L64N.js +4785 -0
- package/dist/chunk-VPS7L64N.js.map +1 -0
- package/dist/chunk-Z4Y4FMQN.js +1097 -0
- package/dist/chunk-Z4Y4FMQN.js.map +1 -0
- package/dist/compat/nestjs/index.cjs +4883 -0
- package/dist/compat/nestjs/index.cjs.map +1 -0
- package/dist/compat/nestjs/index.d.cts +7 -0
- package/dist/compat/nestjs/index.d.ts +7 -0
- package/dist/compat/nestjs/index.js +84 -0
- package/dist/compat/nestjs/index.js.map +1 -0
- package/dist/core/index.cjs +1632 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +2 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +90 -0
- package/dist/core/index.js.map +1 -0
- package/dist/extra/index.cjs +6885 -0
- package/dist/extra/index.cjs.map +1 -0
- package/dist/extra/index.d.cts +5 -0
- package/dist/extra/index.d.ts +5 -0
- package/dist/extra/index.js +290 -0
- package/dist/extra/index.js.map +1 -0
- package/dist/graph/index.cjs +3225 -0
- package/dist/graph/index.cjs.map +1 -0
- package/dist/graph/index.d.cts +3 -0
- package/dist/graph/index.d.ts +3 -0
- package/dist/graph/index.js +25 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph-CL_ZDAj9.d.cts +605 -0
- package/dist/graph-D18qmsNm.d.ts +605 -0
- package/dist/index-B6SsZs2h.d.cts +3463 -0
- package/dist/index-B7eOdgEx.d.ts +449 -0
- package/dist/index-BHUvlQ3v.d.ts +3463 -0
- package/dist/index-BtK55IE2.d.ts +231 -0
- package/dist/index-BvhgZRHK.d.cts +231 -0
- package/dist/index-Bvy_6CaN.d.ts +452 -0
- package/dist/index-C3BMRmmp.d.cts +449 -0
- package/dist/index-C5mqLhMX.d.cts +452 -0
- package/dist/index-CP_QvbWu.d.ts +940 -0
- package/dist/index-D_geH2Bm.d.cts +940 -0
- package/dist/index.cjs +14843 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1517 -0
- package/dist/index.d.ts +1517 -0
- package/dist/index.js +3649 -0
- package/dist/index.js.map +1 -0
- package/dist/meta-BsF6Sag9.d.cts +607 -0
- package/dist/meta-BsF6Sag9.d.ts +607 -0
- package/dist/patterns/reactive-layout/index.cjs +4143 -0
- package/dist/patterns/reactive-layout/index.cjs.map +1 -0
- package/dist/patterns/reactive-layout/index.d.cts +3 -0
- package/dist/patterns/reactive-layout/index.d.ts +3 -0
- package/dist/patterns/reactive-layout/index.js +38 -0
- package/dist/patterns/reactive-layout/index.js.map +1 -0
- package/dist/reactive-log-BfvfNWQh.d.cts +137 -0
- package/dist/reactive-log-ohLmTXoZ.d.ts +137 -0
- package/package.json +256 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { N as Node } from './meta-BsF6Sag9.cjs';
|
|
2
|
+
import { G as Graph } from './graph-CL_ZDAj9.cjs';
|
|
3
|
+
|
|
4
|
+
/** Pluggable measurement backend. */
|
|
5
|
+
interface MeasurementAdapter {
|
|
6
|
+
measureSegment(text: string, font: string): {
|
|
7
|
+
width: number;
|
|
8
|
+
};
|
|
9
|
+
/** Optional; adapters may omit for read-only / stateless measurement. */
|
|
10
|
+
clearCache?(): void;
|
|
11
|
+
}
|
|
12
|
+
/** Mutable counters for `analyzeAndMeasure` cache hit ratio (hits / (hits + misses)). */
|
|
13
|
+
type SegmentMeasureStats = {
|
|
14
|
+
hits: number;
|
|
15
|
+
misses: number;
|
|
16
|
+
};
|
|
17
|
+
/** Break kind for each segment (ported from Pretext analysis.ts). */
|
|
18
|
+
type SegmentBreakKind = "text" | "space" | "zero-width-break" | "soft-hyphen" | "hard-break";
|
|
19
|
+
/** A measured text segment ready for line breaking. */
|
|
20
|
+
type PreparedSegment = {
|
|
21
|
+
text: string;
|
|
22
|
+
width: number;
|
|
23
|
+
kind: SegmentBreakKind;
|
|
24
|
+
/** Grapheme widths for overflow-wrap: break-word (null if single grapheme). */
|
|
25
|
+
graphemeWidths: number[] | null;
|
|
26
|
+
};
|
|
27
|
+
/** A laid-out line with start/end cursors. */
|
|
28
|
+
type LayoutLine = {
|
|
29
|
+
text: string;
|
|
30
|
+
width: number;
|
|
31
|
+
startSegment: number;
|
|
32
|
+
startGrapheme: number;
|
|
33
|
+
endSegment: number;
|
|
34
|
+
endGrapheme: number;
|
|
35
|
+
};
|
|
36
|
+
/** Per-character position for hit testing. */
|
|
37
|
+
type CharPosition = {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
line: number;
|
|
43
|
+
};
|
|
44
|
+
/** Full layout result from the line-breaks derived node. */
|
|
45
|
+
type LineBreaksResult = {
|
|
46
|
+
lines: LayoutLine[];
|
|
47
|
+
lineCount: number;
|
|
48
|
+
};
|
|
49
|
+
/** Result of the reactive layout graph's describe-accessible state. */
|
|
50
|
+
type ReactiveLayoutBundle = {
|
|
51
|
+
graph: Graph;
|
|
52
|
+
/** Set input text. */
|
|
53
|
+
setText: (text: string) => void;
|
|
54
|
+
/** Set CSS font string. */
|
|
55
|
+
setFont: (font: string) => void;
|
|
56
|
+
/** Set line height (px). */
|
|
57
|
+
setLineHeight: (lineHeight: number) => void;
|
|
58
|
+
/** Set max width constraint (px). */
|
|
59
|
+
setMaxWidth: (maxWidth: number) => void;
|
|
60
|
+
/** Segments node. */
|
|
61
|
+
segments: Node<PreparedSegment[]>;
|
|
62
|
+
/** Line breaks node. */
|
|
63
|
+
lineBreaks: Node<LineBreaksResult>;
|
|
64
|
+
/** Total height node. */
|
|
65
|
+
height: Node<number>;
|
|
66
|
+
/** Per-character positions node. */
|
|
67
|
+
charPositions: Node<CharPosition[]>;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Merge segmentation pieces: sticky punctuation, CJK per-grapheme splitting,
|
|
71
|
+
* and produce the final measured segment list.
|
|
72
|
+
*/
|
|
73
|
+
declare function analyzeAndMeasure(text: string, font: string, adapter: MeasurementAdapter, cache: Map<string, Map<string, number>>, stats?: SegmentMeasureStats): PreparedSegment[];
|
|
74
|
+
/**
|
|
75
|
+
* Greedy line-breaking algorithm.
|
|
76
|
+
*
|
|
77
|
+
* Walks segments left to right, accumulating width. Breaks when a segment would
|
|
78
|
+
* overflow maxWidth. Supports:
|
|
79
|
+
* - Trailing space hang (spaces don't trigger breaks)
|
|
80
|
+
* - overflow-wrap: break-word via grapheme widths
|
|
81
|
+
* - Soft hyphens (break opportunity, adds visible hyphen width)
|
|
82
|
+
* - Hard breaks (forced newline)
|
|
83
|
+
*/
|
|
84
|
+
declare function computeLineBreaks(segments: PreparedSegment[], maxWidth: number, adapter: MeasurementAdapter, font: string, cache: Map<string, Map<string, number>>): LineBreaksResult;
|
|
85
|
+
/** Compute per-character x,y positions from line breaks and segments. */
|
|
86
|
+
declare function computeCharPositions(lineBreaks: LineBreaksResult, segments: PreparedSegment[], lineHeight: number): CharPosition[];
|
|
87
|
+
type ReactiveLayoutOptions = {
|
|
88
|
+
/** Measurement backend (required). */
|
|
89
|
+
adapter: MeasurementAdapter;
|
|
90
|
+
/** Graph name (default: "reactive-layout"). */
|
|
91
|
+
name?: string;
|
|
92
|
+
/** Initial text. */
|
|
93
|
+
text?: string;
|
|
94
|
+
/** Initial CSS font string. */
|
|
95
|
+
font?: string;
|
|
96
|
+
/** Initial line height in px. */
|
|
97
|
+
lineHeight?: number;
|
|
98
|
+
/** Initial max width in px (clamped to ≥ 0). */
|
|
99
|
+
maxWidth?: number;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Create a reactive text layout graph.
|
|
103
|
+
*
|
|
104
|
+
* ```
|
|
105
|
+
* Graph("reactive-layout")
|
|
106
|
+
* ├── state("text")
|
|
107
|
+
* ├── state("font")
|
|
108
|
+
* ├── state("line-height")
|
|
109
|
+
* ├── state("max-width")
|
|
110
|
+
* ├── derived("segments") — text + font → PreparedSegment[]
|
|
111
|
+
* ├── derived("line-breaks") — segments + max-width → LineBreaksResult
|
|
112
|
+
* ├── derived("height") — line-breaks → number
|
|
113
|
+
* └── derived("char-positions") — line-breaks + segments → CharPosition[]
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare function reactiveLayout(opts: ReactiveLayoutOptions): ReactiveLayoutBundle;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* MeasurementAdapter implementations (roadmap §7.1 — pluggable backends).
|
|
120
|
+
*
|
|
121
|
+
* All adapters implement {@link MeasurementAdapter} from `reactive-layout.ts`.
|
|
122
|
+
* Sync constructors, sync `measureSegment()` — no async, no polling.
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
type CliMeasureAdapterOptions = {
|
|
126
|
+
/** Pixel width per terminal cell (default: 8). */
|
|
127
|
+
cellPx?: number;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Monospace terminal measurement adapter.
|
|
131
|
+
*
|
|
132
|
+
* Width = cell count × `cellPx`. CJK / fullwidth characters count as 2 cells.
|
|
133
|
+
* No external dependencies. Works in any JS environment.
|
|
134
|
+
*/
|
|
135
|
+
declare class CliMeasureAdapter implements MeasurementAdapter {
|
|
136
|
+
private readonly cellPx;
|
|
137
|
+
constructor(opts?: CliMeasureAdapterOptions);
|
|
138
|
+
measureSegment(text: string, _font: string): {
|
|
139
|
+
width: number;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
type PrecomputedAdapterOptions = {
|
|
143
|
+
/**
|
|
144
|
+
* Pre-computed metrics: `{ font: { segment: widthPx } }`.
|
|
145
|
+
* Outer key is the CSS font string; inner key is the text segment.
|
|
146
|
+
*/
|
|
147
|
+
metrics: Record<string, Record<string, number>>;
|
|
148
|
+
/**
|
|
149
|
+
* Fallback when a segment is not found in the metrics map.
|
|
150
|
+
* - `"per-char"`: sum individual character widths from the same font map (default)
|
|
151
|
+
* - `"error"`: throw an error for unknown segments
|
|
152
|
+
*/
|
|
153
|
+
fallback?: "per-char" | "error";
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Pre-computed measurement adapter for SSR / snapshot replay.
|
|
157
|
+
*
|
|
158
|
+
* Reads from a static metrics object — zero measurement at runtime.
|
|
159
|
+
* Ideal for server-side rendering or replaying snapshotted layouts.
|
|
160
|
+
*/
|
|
161
|
+
declare class PrecomputedAdapter implements MeasurementAdapter {
|
|
162
|
+
private readonly metrics;
|
|
163
|
+
private readonly fallback;
|
|
164
|
+
constructor(opts: PrecomputedAdapterOptions);
|
|
165
|
+
measureSegment(text: string, font: string): {
|
|
166
|
+
width: number;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
type CanvasMeasureAdapterOptions = {
|
|
170
|
+
/** Emoji width correction factor (default: 1, no correction). */
|
|
171
|
+
emojiCorrection?: number;
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Browser measurement adapter using `OffscreenCanvas.measureText()`.
|
|
175
|
+
*
|
|
176
|
+
* Lazily creates an OffscreenCanvas and 2D context on first call.
|
|
177
|
+
* Requires a browser environment with OffscreenCanvas support.
|
|
178
|
+
*/
|
|
179
|
+
declare class CanvasMeasureAdapter implements MeasurementAdapter {
|
|
180
|
+
private ctx;
|
|
181
|
+
private currentFont;
|
|
182
|
+
private readonly emojiCorrection;
|
|
183
|
+
constructor(opts?: CanvasMeasureAdapterOptions);
|
|
184
|
+
private getContext;
|
|
185
|
+
measureSegment(text: string, font: string): {
|
|
186
|
+
width: number;
|
|
187
|
+
};
|
|
188
|
+
clearCache(): void;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Canvas API subset expected from `@napi-rs/canvas` or `skia-canvas`.
|
|
192
|
+
* Passed via dependency injection — no dynamic import, no polling.
|
|
193
|
+
*/
|
|
194
|
+
type CanvasModule = {
|
|
195
|
+
createCanvas(width: number, height: number): {
|
|
196
|
+
getContext(type: "2d"): {
|
|
197
|
+
font: string;
|
|
198
|
+
measureText(text: string): {
|
|
199
|
+
width: number;
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Node.js measurement adapter using an injected canvas module.
|
|
206
|
+
*
|
|
207
|
+
* ```ts
|
|
208
|
+
* import * as canvas from "@napi-rs/canvas";
|
|
209
|
+
* const adapter = new NodeCanvasMeasureAdapter(canvas);
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* Works with `@napi-rs/canvas`, `skia-canvas`, or any module exposing
|
|
213
|
+
* `createCanvas(w, h).getContext("2d").measureText(text)`.
|
|
214
|
+
*/
|
|
215
|
+
declare class NodeCanvasMeasureAdapter implements MeasurementAdapter {
|
|
216
|
+
private ctx;
|
|
217
|
+
private currentFont;
|
|
218
|
+
private readonly canvasModule;
|
|
219
|
+
constructor(canvasModule: CanvasModule);
|
|
220
|
+
private getContext;
|
|
221
|
+
measureSegment(text: string, font: string): {
|
|
222
|
+
width: number;
|
|
223
|
+
};
|
|
224
|
+
clearCache(): void;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* SVG measurement adapter — extracts dimensions from `viewBox` attribute
|
|
228
|
+
* or explicit `width`/`height` attributes in the SVG string.
|
|
229
|
+
*
|
|
230
|
+
* Pure arithmetic: parses the SVG string for dimension attributes.
|
|
231
|
+
* No DOM required. Works in any JS environment.
|
|
232
|
+
*
|
|
233
|
+
* Browser users who need `getBBox()` should pre-measure and pass explicit
|
|
234
|
+
* `viewBox` on the content block instead.
|
|
235
|
+
*/
|
|
236
|
+
declare class SvgBoundsAdapter {
|
|
237
|
+
measureSvg(content: string): {
|
|
238
|
+
width: number;
|
|
239
|
+
height: number;
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Image measurement adapter — returns pre-registered dimensions by src key.
|
|
244
|
+
*
|
|
245
|
+
* Sync-only: dimensions must be provided upfront via the `sizes` map.
|
|
246
|
+
* No I/O, no polling, no async. For browser use, pre-measure via
|
|
247
|
+
* `Image.onload` and pass natural dimensions on the content block directly,
|
|
248
|
+
* or register them here.
|
|
249
|
+
*
|
|
250
|
+
* ```ts
|
|
251
|
+
* const adapter = new ImageSizeAdapter({
|
|
252
|
+
* "hero.png": { width: 1200, height: 630 },
|
|
253
|
+
* "logo.svg": { width: 120, height: 40 },
|
|
254
|
+
* });
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
declare class ImageSizeAdapter {
|
|
258
|
+
private readonly sizes;
|
|
259
|
+
constructor(sizes: Record<string, {
|
|
260
|
+
width: number;
|
|
261
|
+
height: number;
|
|
262
|
+
}>);
|
|
263
|
+
measureImage(src: string): {
|
|
264
|
+
width: number;
|
|
265
|
+
height: number;
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Pluggable measurement backend for SVG content. */
|
|
270
|
+
interface SvgMeasurer {
|
|
271
|
+
measureSvg(content: string): {
|
|
272
|
+
width: number;
|
|
273
|
+
height: number;
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/** Pluggable measurement backend for image content. */
|
|
277
|
+
interface ImageMeasurer {
|
|
278
|
+
measureImage(src: string): {
|
|
279
|
+
width: number;
|
|
280
|
+
height: number;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
/** Adapters map for `reactiveBlockLayout`. */
|
|
284
|
+
type BlockAdapters = {
|
|
285
|
+
/** Text measurement adapter (required — delegates to `reactiveLayout` internals). */
|
|
286
|
+
text: MeasurementAdapter;
|
|
287
|
+
/** SVG measurement (optional — required only if SVG blocks are present). */
|
|
288
|
+
svg?: SvgMeasurer;
|
|
289
|
+
/** Image measurement (optional — required only if image blocks without explicit dimensions are present). */
|
|
290
|
+
image?: ImageMeasurer;
|
|
291
|
+
};
|
|
292
|
+
/** A content block — text, image, or SVG. */
|
|
293
|
+
type ContentBlock = {
|
|
294
|
+
type: "text";
|
|
295
|
+
text: string;
|
|
296
|
+
font?: string;
|
|
297
|
+
lineHeight?: number;
|
|
298
|
+
} | {
|
|
299
|
+
type: "image";
|
|
300
|
+
src: string;
|
|
301
|
+
/** Natural width in px. Required if no ImageMeasurer adapter is provided. */
|
|
302
|
+
naturalWidth?: number;
|
|
303
|
+
/** Natural height in px. Required if no ImageMeasurer adapter is provided. */
|
|
304
|
+
naturalHeight?: number;
|
|
305
|
+
} | {
|
|
306
|
+
type: "svg";
|
|
307
|
+
content: string;
|
|
308
|
+
/** Explicit viewBox dimensions. Required if no SvgMeasurer adapter is provided. */
|
|
309
|
+
viewBox?: {
|
|
310
|
+
width: number;
|
|
311
|
+
height: number;
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* A block after measurement — knows its natural dimensions.
|
|
316
|
+
*
|
|
317
|
+
* **Equality note:** The reactive `measured-blocks` node uses dimension-only equality
|
|
318
|
+
* (`type`, `width`, `height`, `index`). Inner text layout data (`textSegments`,
|
|
319
|
+
* `textLineBreaks`, `textCharPositions`) is NOT compared for change detection.
|
|
320
|
+
* If you need text-level reactivity, use `reactiveLayout()` directly per text block.
|
|
321
|
+
*/
|
|
322
|
+
type MeasuredBlock = {
|
|
323
|
+
index: number;
|
|
324
|
+
type: "text" | "image" | "svg";
|
|
325
|
+
width: number;
|
|
326
|
+
height: number;
|
|
327
|
+
/** For text blocks: the inner layout results. */
|
|
328
|
+
textSegments?: PreparedSegment[];
|
|
329
|
+
textLineBreaks?: LineBreaksResult;
|
|
330
|
+
textCharPositions?: CharPosition[];
|
|
331
|
+
};
|
|
332
|
+
/** A block after flow — positioned in the container. */
|
|
333
|
+
type PositionedBlock = MeasuredBlock & {
|
|
334
|
+
x: number;
|
|
335
|
+
y: number;
|
|
336
|
+
};
|
|
337
|
+
/** Options for `reactiveBlockLayout`. */
|
|
338
|
+
type ReactiveBlockLayoutOptions = {
|
|
339
|
+
adapters: BlockAdapters;
|
|
340
|
+
name?: string;
|
|
341
|
+
blocks?: ContentBlock[];
|
|
342
|
+
/** Container max width in px (clamped to ≥ 0 on init and `setMaxWidth`). */
|
|
343
|
+
maxWidth?: number;
|
|
344
|
+
/** Vertical gap between blocks in px (default 0). */
|
|
345
|
+
gap?: number;
|
|
346
|
+
/** Default font for text blocks that don't specify one. */
|
|
347
|
+
defaultFont?: string;
|
|
348
|
+
/** Default line height for text blocks that don't specify one. */
|
|
349
|
+
defaultLineHeight?: number;
|
|
350
|
+
};
|
|
351
|
+
/** Result bundle from `reactiveBlockLayout`. */
|
|
352
|
+
type ReactiveBlockLayoutBundle = {
|
|
353
|
+
graph: Graph;
|
|
354
|
+
setBlocks: (blocks: ContentBlock[]) => void;
|
|
355
|
+
setMaxWidth: (maxWidth: number) => void;
|
|
356
|
+
setGap: (gap: number) => void;
|
|
357
|
+
measuredBlocks: Node<MeasuredBlock[]>;
|
|
358
|
+
blockFlow: Node<PositionedBlock[]>;
|
|
359
|
+
totalHeight: Node<number>;
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Measure a single content block, returning natural (unconstrained) dimensions.
|
|
363
|
+
* Text blocks use the text layout pipeline; image/SVG use adapters or explicit dims.
|
|
364
|
+
*/
|
|
365
|
+
declare function measureBlock(block: ContentBlock, maxWidth: number, adapters: BlockAdapters, measureCache: Map<string, Map<string, number>>, defaultFont: string, defaultLineHeight: number, index: number): MeasuredBlock;
|
|
366
|
+
/**
|
|
367
|
+
* Measure all blocks in a content array.
|
|
368
|
+
*/
|
|
369
|
+
declare function measureBlocks(blocks: ContentBlock[], maxWidth: number, adapters: BlockAdapters, measureCache: Map<string, Map<string, number>>, defaultFont: string, defaultLineHeight: number): MeasuredBlock[];
|
|
370
|
+
/**
|
|
371
|
+
* Vertical stacking flow: blocks are placed top-to-bottom, left-aligned,
|
|
372
|
+
* separated by `gap` pixels. Pure arithmetic over measured sizes.
|
|
373
|
+
*/
|
|
374
|
+
declare function computeBlockFlow(measured: MeasuredBlock[], gap: number): PositionedBlock[];
|
|
375
|
+
/**
|
|
376
|
+
* Compute total height from positioned blocks.
|
|
377
|
+
*/
|
|
378
|
+
declare function computeTotalHeight(flow: PositionedBlock[]): number;
|
|
379
|
+
/**
|
|
380
|
+
* Create a reactive block layout graph for mixed content (text + image + SVG).
|
|
381
|
+
*
|
|
382
|
+
* ```
|
|
383
|
+
* Graph("reactive-block-layout")
|
|
384
|
+
* ├── state("blocks") — ContentBlock[] input
|
|
385
|
+
* ├── state("max-width") — container constraint
|
|
386
|
+
* ├── state("gap") — vertical gap (px)
|
|
387
|
+
* ├── derived("measured-blocks") — blocks + max-width → MeasuredBlock[]
|
|
388
|
+
* ├── derived("block-flow") — measured-blocks + gap → PositionedBlock[]
|
|
389
|
+
* ├── derived("total-height") — block-flow → number
|
|
390
|
+
* └── meta: { block-count, layout-time-ns }
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
declare function reactiveBlockLayout(opts: ReactiveBlockLayoutOptions): ReactiveBlockLayoutBundle;
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Reactive layout pattern — standalone subpath export.
|
|
397
|
+
*
|
|
398
|
+
* ```ts
|
|
399
|
+
* import { reactiveLayout, CliMeasureAdapter } from "@graphrefly/graphrefly-ts/reactive-layout";
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
|
|
403
|
+
type index_BlockAdapters = BlockAdapters;
|
|
404
|
+
type index_CanvasMeasureAdapter = CanvasMeasureAdapter;
|
|
405
|
+
declare const index_CanvasMeasureAdapter: typeof CanvasMeasureAdapter;
|
|
406
|
+
type index_CanvasMeasureAdapterOptions = CanvasMeasureAdapterOptions;
|
|
407
|
+
type index_CanvasModule = CanvasModule;
|
|
408
|
+
type index_CharPosition = CharPosition;
|
|
409
|
+
type index_CliMeasureAdapter = CliMeasureAdapter;
|
|
410
|
+
declare const index_CliMeasureAdapter: typeof CliMeasureAdapter;
|
|
411
|
+
type index_CliMeasureAdapterOptions = CliMeasureAdapterOptions;
|
|
412
|
+
type index_ContentBlock = ContentBlock;
|
|
413
|
+
type index_ImageMeasurer = ImageMeasurer;
|
|
414
|
+
type index_ImageSizeAdapter = ImageSizeAdapter;
|
|
415
|
+
declare const index_ImageSizeAdapter: typeof ImageSizeAdapter;
|
|
416
|
+
type index_LayoutLine = LayoutLine;
|
|
417
|
+
type index_LineBreaksResult = LineBreaksResult;
|
|
418
|
+
type index_MeasuredBlock = MeasuredBlock;
|
|
419
|
+
type index_MeasurementAdapter = MeasurementAdapter;
|
|
420
|
+
type index_NodeCanvasMeasureAdapter = NodeCanvasMeasureAdapter;
|
|
421
|
+
declare const index_NodeCanvasMeasureAdapter: typeof NodeCanvasMeasureAdapter;
|
|
422
|
+
type index_PositionedBlock = PositionedBlock;
|
|
423
|
+
type index_PrecomputedAdapter = PrecomputedAdapter;
|
|
424
|
+
declare const index_PrecomputedAdapter: typeof PrecomputedAdapter;
|
|
425
|
+
type index_PrecomputedAdapterOptions = PrecomputedAdapterOptions;
|
|
426
|
+
type index_PreparedSegment = PreparedSegment;
|
|
427
|
+
type index_ReactiveBlockLayoutBundle = ReactiveBlockLayoutBundle;
|
|
428
|
+
type index_ReactiveBlockLayoutOptions = ReactiveBlockLayoutOptions;
|
|
429
|
+
type index_ReactiveLayoutBundle = ReactiveLayoutBundle;
|
|
430
|
+
type index_ReactiveLayoutOptions = ReactiveLayoutOptions;
|
|
431
|
+
type index_SegmentBreakKind = SegmentBreakKind;
|
|
432
|
+
type index_SegmentMeasureStats = SegmentMeasureStats;
|
|
433
|
+
type index_SvgBoundsAdapter = SvgBoundsAdapter;
|
|
434
|
+
declare const index_SvgBoundsAdapter: typeof SvgBoundsAdapter;
|
|
435
|
+
type index_SvgMeasurer = SvgMeasurer;
|
|
436
|
+
declare const index_analyzeAndMeasure: typeof analyzeAndMeasure;
|
|
437
|
+
declare const index_computeBlockFlow: typeof computeBlockFlow;
|
|
438
|
+
declare const index_computeCharPositions: typeof computeCharPositions;
|
|
439
|
+
declare const index_computeLineBreaks: typeof computeLineBreaks;
|
|
440
|
+
declare const index_computeTotalHeight: typeof computeTotalHeight;
|
|
441
|
+
declare const index_measureBlock: typeof measureBlock;
|
|
442
|
+
declare const index_measureBlocks: typeof measureBlocks;
|
|
443
|
+
declare const index_reactiveBlockLayout: typeof reactiveBlockLayout;
|
|
444
|
+
declare const index_reactiveLayout: typeof reactiveLayout;
|
|
445
|
+
declare namespace index {
|
|
446
|
+
export { type index_BlockAdapters as BlockAdapters, index_CanvasMeasureAdapter as CanvasMeasureAdapter, type index_CanvasMeasureAdapterOptions as CanvasMeasureAdapterOptions, type index_CanvasModule as CanvasModule, type index_CharPosition as CharPosition, index_CliMeasureAdapter as CliMeasureAdapter, type index_CliMeasureAdapterOptions as CliMeasureAdapterOptions, type index_ContentBlock as ContentBlock, type index_ImageMeasurer as ImageMeasurer, index_ImageSizeAdapter as ImageSizeAdapter, type index_LayoutLine as LayoutLine, type index_LineBreaksResult as LineBreaksResult, type index_MeasuredBlock as MeasuredBlock, type index_MeasurementAdapter as MeasurementAdapter, index_NodeCanvasMeasureAdapter as NodeCanvasMeasureAdapter, type index_PositionedBlock as PositionedBlock, index_PrecomputedAdapter as PrecomputedAdapter, type index_PrecomputedAdapterOptions as PrecomputedAdapterOptions, type index_PreparedSegment as PreparedSegment, type index_ReactiveBlockLayoutBundle as ReactiveBlockLayoutBundle, type index_ReactiveBlockLayoutOptions as ReactiveBlockLayoutOptions, type index_ReactiveLayoutBundle as ReactiveLayoutBundle, type index_ReactiveLayoutOptions as ReactiveLayoutOptions, type index_SegmentBreakKind as SegmentBreakKind, type index_SegmentMeasureStats as SegmentMeasureStats, index_SvgBoundsAdapter as SvgBoundsAdapter, type index_SvgMeasurer as SvgMeasurer, index_analyzeAndMeasure as analyzeAndMeasure, index_computeBlockFlow as computeBlockFlow, index_computeCharPositions as computeCharPositions, index_computeLineBreaks as computeLineBreaks, index_computeTotalHeight as computeTotalHeight, index_measureBlock as measureBlock, index_measureBlocks as measureBlocks, index_reactiveBlockLayout as reactiveBlockLayout, index_reactiveLayout as reactiveLayout };
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
export { reactiveBlockLayout as A, type BlockAdapters as B, CanvasMeasureAdapter as C, reactiveLayout as D, type ImageMeasurer as I, type LayoutLine as L, type MeasuredBlock as M, NodeCanvasMeasureAdapter as N, type PositionedBlock as P, type ReactiveBlockLayoutBundle as R, type SegmentBreakKind as S, type CanvasMeasureAdapterOptions as a, type CanvasModule as b, type CharPosition as c, CliMeasureAdapter as d, type CliMeasureAdapterOptions as e, type ContentBlock as f, ImageSizeAdapter as g, type LineBreaksResult as h, index as i, type MeasurementAdapter as j, PrecomputedAdapter as k, type PrecomputedAdapterOptions as l, type PreparedSegment as m, type ReactiveBlockLayoutOptions as n, type ReactiveLayoutBundle as o, type ReactiveLayoutOptions as p, type SegmentMeasureStats as q, SvgBoundsAdapter as r, type SvgMeasurer as s, analyzeAndMeasure as t, computeBlockFlow as u, computeCharPositions as v, computeLineBreaks as w, computeTotalHeight as x, measureBlock as y, measureBlocks as z };
|