@oyerinde/caliper 0.1.4 → 0.2.1

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.
@@ -0,0 +1,964 @@
1
+ import { z } from 'zod';
2
+
3
+ export declare interface AgentBridgeConfig {
4
+ /** Enable the agentic bridge for AI integration (default: false) */
5
+ enabled?: boolean;
6
+ /** WebSocket port for the MCP relay (default: 9876) */
7
+ wsPort?: number;
8
+ /** Callback for agent state changes */
9
+ onStateChange?: (state: CaliperAgentState) => void;
10
+ /** Name of a global window function to call on state changes (IIFE/CDN-safe, JSON-serializable) */
11
+ onStateChangeGlobal?: string;
12
+ }
13
+
14
+ export declare interface AnimationConfig {
15
+ /** Enable smooth lerp animation for boundary box hover (default: true) */
16
+ enabled?: boolean;
17
+ /** Lerp factor for animation smoothness (0-1, lower = smoother, default: 0.25) */
18
+ lerpFactor?: number;
19
+ }
20
+
21
+ declare interface CalculatorIntegration {
22
+ getState: () => CalculatorState;
23
+ open: (baseValue: number) => void;
24
+ handleInput: (key: string) => void;
25
+ handleBackspace: () => void;
26
+ handleDelete: () => void;
27
+ handleEnter: () => void;
28
+ close: () => void;
29
+ syncValue: (value: number) => void;
30
+ getResult: () => number | null;
31
+ }
32
+
33
+ /**
34
+ * Calculator state machine
35
+ */
36
+ declare type CalculatorOperation = "+" | "-" | "*" | "/";
37
+
38
+ /**
39
+ * Keyboard shortcuts for measurement sides.
40
+ */
41
+ declare interface CalculatorShortcuts {
42
+ top?: string;
43
+ bottom?: string;
44
+ left?: string;
45
+ right?: string;
46
+ distance?: string;
47
+ }
48
+
49
+ declare interface CalculatorState {
50
+ baseValue: number;
51
+ operation: CalculatorOperation | null;
52
+ inputValue: string;
53
+ result: number | null;
54
+ isActive: boolean;
55
+ }
56
+
57
+ export declare type CaliperAgentState = z.infer<typeof CaliperAgentStateSchema>;
58
+
59
+ export declare const CaliperAgentStateSchema: z.ZodObject<{
60
+ viewport: z.ZodObject<{
61
+ width: z.ZodNumber;
62
+ height: z.ZodNumber;
63
+ scrollX: z.ZodNumber;
64
+ scrollY: z.ZodNumber;
65
+ }, z.core.$strip>;
66
+ activeSelection: z.ZodNullable<z.ZodObject<{
67
+ rect: z.ZodNullable<z.ZodObject<{
68
+ top: z.ZodNumber;
69
+ right: z.ZodNumber;
70
+ bottom: z.ZodNumber;
71
+ left: z.ZodNumber;
72
+ width: z.ZodNumber;
73
+ height: z.ZodNumber;
74
+ x: z.ZodNumber;
75
+ y: z.ZodNumber;
76
+ }, z.core.$strip>>;
77
+ scrollHierarchy: z.ZodArray<z.ZodObject<{
78
+ initialScrollTop: z.ZodNumber;
79
+ initialScrollLeft: z.ZodNumber;
80
+ containerRect: z.ZodNullable<z.ZodObject<{
81
+ top: z.ZodNumber;
82
+ right: z.ZodNumber;
83
+ bottom: z.ZodNumber;
84
+ left: z.ZodNumber;
85
+ width: z.ZodNumber;
86
+ height: z.ZodNumber;
87
+ x: z.ZodNumber;
88
+ y: z.ZodNumber;
89
+ }, z.core.$strip>>;
90
+ absoluteDepth: z.ZodNumber;
91
+ hasStickyAncestor: z.ZodOptional<z.ZodBoolean>;
92
+ }, z.core.$strip>>;
93
+ position: z.ZodEnum<{
94
+ static: "static";
95
+ relative: "relative";
96
+ absolute: "absolute";
97
+ fixed: "fixed";
98
+ sticky: "sticky";
99
+ }>;
100
+ stickyConfig: z.ZodOptional<z.ZodObject<{
101
+ top: z.ZodNullable<z.ZodNumber>;
102
+ bottom: z.ZodNullable<z.ZodNumber>;
103
+ left: z.ZodNullable<z.ZodNumber>;
104
+ right: z.ZodNullable<z.ZodNumber>;
105
+ naturalTop: z.ZodNumber;
106
+ naturalLeft: z.ZodNumber;
107
+ containerWidth: z.ZodNumber;
108
+ containerHeight: z.ZodNumber;
109
+ elementWidth: z.ZodNumber;
110
+ elementHeight: z.ZodNumber;
111
+ anchorAbsoluteDepth: z.ZodNumber;
112
+ }, z.core.$strip>>;
113
+ initialWindowX: z.ZodNumber;
114
+ initialWindowY: z.ZodNumber;
115
+ depth: z.ZodNumber;
116
+ hasContainingBlock: z.ZodOptional<z.ZodBoolean>;
117
+ }, z.core.$strip>>;
118
+ selectionFingerprint: z.ZodNullable<z.ZodObject<{
119
+ selector: z.ZodString;
120
+ tag: z.ZodString;
121
+ timestamp: z.ZodNumber;
122
+ id: z.ZodOptional<z.ZodString>;
123
+ text: z.ZodOptional<z.ZodString>;
124
+ classes: z.ZodOptional<z.ZodArray<z.ZodString>>;
125
+ tabId: z.ZodOptional<z.ZodString>;
126
+ nthChild: z.ZodOptional<z.ZodNumber>;
127
+ x: z.ZodOptional<z.ZodNumber>;
128
+ y: z.ZodOptional<z.ZodNumber>;
129
+ depth: z.ZodOptional<z.ZodNumber>;
130
+ marker: z.ZodOptional<z.ZodString>;
131
+ scrollHierarchy: z.ZodOptional<z.ZodArray<z.ZodObject<{
132
+ initialScrollTop: z.ZodNumber;
133
+ initialScrollLeft: z.ZodNumber;
134
+ containerRect: z.ZodNullable<z.ZodObject<{
135
+ top: z.ZodNumber;
136
+ right: z.ZodNumber;
137
+ bottom: z.ZodNumber;
138
+ left: z.ZodNumber;
139
+ width: z.ZodNumber;
140
+ height: z.ZodNumber;
141
+ x: z.ZodNumber;
142
+ y: z.ZodNumber;
143
+ }, z.core.$strip>>;
144
+ absoluteDepth: z.ZodNumber;
145
+ hasStickyAncestor: z.ZodOptional<z.ZodBoolean>;
146
+ }, z.core.$strip>>>;
147
+ position: z.ZodOptional<z.ZodEnum<{
148
+ static: "static";
149
+ relative: "relative";
150
+ absolute: "absolute";
151
+ fixed: "fixed";
152
+ sticky: "sticky";
153
+ }>>;
154
+ stickyConfig: z.ZodOptional<z.ZodObject<{
155
+ top: z.ZodNullable<z.ZodNumber>;
156
+ bottom: z.ZodNullable<z.ZodNumber>;
157
+ left: z.ZodNullable<z.ZodNumber>;
158
+ right: z.ZodNullable<z.ZodNumber>;
159
+ naturalTop: z.ZodNumber;
160
+ naturalLeft: z.ZodNumber;
161
+ containerWidth: z.ZodNumber;
162
+ containerHeight: z.ZodNumber;
163
+ elementWidth: z.ZodNumber;
164
+ elementHeight: z.ZodNumber;
165
+ anchorAbsoluteDepth: z.ZodNumber;
166
+ }, z.core.$strip>>;
167
+ initialWindowX: z.ZodOptional<z.ZodNumber>;
168
+ initialWindowY: z.ZodOptional<z.ZodNumber>;
169
+ hasContainingBlock: z.ZodOptional<z.ZodBoolean>;
170
+ rect: z.ZodOptional<z.ZodObject<{
171
+ top: z.ZodNumber;
172
+ right: z.ZodNumber;
173
+ bottom: z.ZodNumber;
174
+ left: z.ZodNumber;
175
+ width: z.ZodNumber;
176
+ height: z.ZodNumber;
177
+ x: z.ZodNumber;
178
+ y: z.ZodNumber;
179
+ }, z.core.$strip>>;
180
+ }, z.core.$strip>>;
181
+ lastMeasurement: z.ZodNullable<z.ZodObject<{
182
+ context: z.ZodNullable<z.ZodEnum<{
183
+ parent: "parent";
184
+ child: "child";
185
+ sibling: "sibling";
186
+ }>>;
187
+ lines: z.ZodArray<z.ZodObject<{
188
+ type: z.ZodEnum<{
189
+ top: "top";
190
+ right: "right";
191
+ bottom: "bottom";
192
+ left: "left";
193
+ distance: "distance";
194
+ }>;
195
+ value: z.ZodNumber;
196
+ start: z.ZodObject<{
197
+ x: z.ZodNumber;
198
+ y: z.ZodNumber;
199
+ }, z.core.$strip>;
200
+ end: z.ZodObject<{
201
+ x: z.ZodNumber;
202
+ y: z.ZodNumber;
203
+ }, z.core.$strip>;
204
+ startSync: z.ZodOptional<z.ZodEnum<{
205
+ primary: "primary";
206
+ secondary: "secondary";
207
+ }>>;
208
+ endSync: z.ZodOptional<z.ZodEnum<{
209
+ primary: "primary";
210
+ secondary: "secondary";
211
+ }>>;
212
+ }, z.core.$strip>>;
213
+ primary: z.ZodObject<{
214
+ top: z.ZodNumber;
215
+ right: z.ZodNumber;
216
+ bottom: z.ZodNumber;
217
+ left: z.ZodNumber;
218
+ width: z.ZodNumber;
219
+ height: z.ZodNumber;
220
+ x: z.ZodNumber;
221
+ y: z.ZodNumber;
222
+ }, z.core.$strip>;
223
+ secondary: z.ZodNullable<z.ZodObject<{
224
+ top: z.ZodNumber;
225
+ right: z.ZodNumber;
226
+ bottom: z.ZodNumber;
227
+ left: z.ZodNumber;
228
+ width: z.ZodNumber;
229
+ height: z.ZodNumber;
230
+ x: z.ZodNumber;
231
+ y: z.ZodNumber;
232
+ }, z.core.$strip>>;
233
+ timestamp: z.ZodNumber;
234
+ primaryHierarchy: z.ZodArray<z.ZodObject<{
235
+ initialScrollTop: z.ZodNumber;
236
+ initialScrollLeft: z.ZodNumber;
237
+ containerRect: z.ZodNullable<z.ZodObject<{
238
+ top: z.ZodNumber;
239
+ right: z.ZodNumber;
240
+ bottom: z.ZodNumber;
241
+ left: z.ZodNumber;
242
+ width: z.ZodNumber;
243
+ height: z.ZodNumber;
244
+ x: z.ZodNumber;
245
+ y: z.ZodNumber;
246
+ }, z.core.$strip>>;
247
+ absoluteDepth: z.ZodNumber;
248
+ hasStickyAncestor: z.ZodOptional<z.ZodBoolean>;
249
+ }, z.core.$strip>>;
250
+ secondaryHierarchy: z.ZodArray<z.ZodObject<{
251
+ initialScrollTop: z.ZodNumber;
252
+ initialScrollLeft: z.ZodNumber;
253
+ containerRect: z.ZodNullable<z.ZodObject<{
254
+ top: z.ZodNumber;
255
+ right: z.ZodNumber;
256
+ bottom: z.ZodNumber;
257
+ left: z.ZodNumber;
258
+ width: z.ZodNumber;
259
+ height: z.ZodNumber;
260
+ x: z.ZodNumber;
261
+ y: z.ZodNumber;
262
+ }, z.core.$strip>>;
263
+ absoluteDepth: z.ZodNumber;
264
+ hasStickyAncestor: z.ZodOptional<z.ZodBoolean>;
265
+ }, z.core.$strip>>;
266
+ primaryPosition: z.ZodEnum<{
267
+ static: "static";
268
+ relative: "relative";
269
+ absolute: "absolute";
270
+ fixed: "fixed";
271
+ sticky: "sticky";
272
+ }>;
273
+ secondaryPosition: z.ZodEnum<{
274
+ static: "static";
275
+ relative: "relative";
276
+ absolute: "absolute";
277
+ fixed: "fixed";
278
+ sticky: "sticky";
279
+ }>;
280
+ primaryWinX: z.ZodNumber;
281
+ primaryWinY: z.ZodNumber;
282
+ secondaryWinX: z.ZodNumber;
283
+ secondaryWinY: z.ZodNumber;
284
+ primarySticky: z.ZodOptional<z.ZodObject<{
285
+ top: z.ZodNullable<z.ZodNumber>;
286
+ bottom: z.ZodNullable<z.ZodNumber>;
287
+ left: z.ZodNullable<z.ZodNumber>;
288
+ right: z.ZodNullable<z.ZodNumber>;
289
+ naturalTop: z.ZodNumber;
290
+ naturalLeft: z.ZodNumber;
291
+ containerWidth: z.ZodNumber;
292
+ containerHeight: z.ZodNumber;
293
+ elementWidth: z.ZodNumber;
294
+ elementHeight: z.ZodNumber;
295
+ anchorAbsoluteDepth: z.ZodNumber;
296
+ }, z.core.$strip>>;
297
+ secondarySticky: z.ZodOptional<z.ZodObject<{
298
+ top: z.ZodNullable<z.ZodNumber>;
299
+ bottom: z.ZodNullable<z.ZodNumber>;
300
+ left: z.ZodNullable<z.ZodNumber>;
301
+ right: z.ZodNullable<z.ZodNumber>;
302
+ naturalTop: z.ZodNumber;
303
+ naturalLeft: z.ZodNumber;
304
+ containerWidth: z.ZodNumber;
305
+ containerHeight: z.ZodNumber;
306
+ elementWidth: z.ZodNumber;
307
+ elementHeight: z.ZodNumber;
308
+ anchorAbsoluteDepth: z.ZodNumber;
309
+ }, z.core.$strip>>;
310
+ primaryHasContainingBlock: z.ZodOptional<z.ZodBoolean>;
311
+ secondaryHasContainingBlock: z.ZodOptional<z.ZodBoolean>;
312
+ }, z.core.$strip>>;
313
+ measurementFingerprint: z.ZodNullable<z.ZodObject<{
314
+ primary: z.ZodObject<{
315
+ selector: z.ZodString;
316
+ tag: z.ZodString;
317
+ timestamp: z.ZodNumber;
318
+ id: z.ZodOptional<z.ZodString>;
319
+ text: z.ZodOptional<z.ZodString>;
320
+ classes: z.ZodOptional<z.ZodArray<z.ZodString>>;
321
+ tabId: z.ZodOptional<z.ZodString>;
322
+ nthChild: z.ZodOptional<z.ZodNumber>;
323
+ x: z.ZodOptional<z.ZodNumber>;
324
+ y: z.ZodOptional<z.ZodNumber>;
325
+ depth: z.ZodOptional<z.ZodNumber>;
326
+ marker: z.ZodOptional<z.ZodString>;
327
+ scrollHierarchy: z.ZodOptional<z.ZodArray<z.ZodObject<{
328
+ initialScrollTop: z.ZodNumber;
329
+ initialScrollLeft: z.ZodNumber;
330
+ containerRect: z.ZodNullable<z.ZodObject<{
331
+ top: z.ZodNumber;
332
+ right: z.ZodNumber;
333
+ bottom: z.ZodNumber;
334
+ left: z.ZodNumber;
335
+ width: z.ZodNumber;
336
+ height: z.ZodNumber;
337
+ x: z.ZodNumber;
338
+ y: z.ZodNumber;
339
+ }, z.core.$strip>>;
340
+ absoluteDepth: z.ZodNumber;
341
+ hasStickyAncestor: z.ZodOptional<z.ZodBoolean>;
342
+ }, z.core.$strip>>>;
343
+ position: z.ZodOptional<z.ZodEnum<{
344
+ static: "static";
345
+ relative: "relative";
346
+ absolute: "absolute";
347
+ fixed: "fixed";
348
+ sticky: "sticky";
349
+ }>>;
350
+ stickyConfig: z.ZodOptional<z.ZodObject<{
351
+ top: z.ZodNullable<z.ZodNumber>;
352
+ bottom: z.ZodNullable<z.ZodNumber>;
353
+ left: z.ZodNullable<z.ZodNumber>;
354
+ right: z.ZodNullable<z.ZodNumber>;
355
+ naturalTop: z.ZodNumber;
356
+ naturalLeft: z.ZodNumber;
357
+ containerWidth: z.ZodNumber;
358
+ containerHeight: z.ZodNumber;
359
+ elementWidth: z.ZodNumber;
360
+ elementHeight: z.ZodNumber;
361
+ anchorAbsoluteDepth: z.ZodNumber;
362
+ }, z.core.$strip>>;
363
+ initialWindowX: z.ZodOptional<z.ZodNumber>;
364
+ initialWindowY: z.ZodOptional<z.ZodNumber>;
365
+ hasContainingBlock: z.ZodOptional<z.ZodBoolean>;
366
+ rect: z.ZodOptional<z.ZodObject<{
367
+ top: z.ZodNumber;
368
+ right: z.ZodNumber;
369
+ bottom: z.ZodNumber;
370
+ left: z.ZodNumber;
371
+ width: z.ZodNumber;
372
+ height: z.ZodNumber;
373
+ x: z.ZodNumber;
374
+ y: z.ZodNumber;
375
+ }, z.core.$strip>>;
376
+ }, z.core.$strip>;
377
+ secondary: z.ZodObject<{
378
+ selector: z.ZodString;
379
+ tag: z.ZodString;
380
+ timestamp: z.ZodNumber;
381
+ id: z.ZodOptional<z.ZodString>;
382
+ text: z.ZodOptional<z.ZodString>;
383
+ classes: z.ZodOptional<z.ZodArray<z.ZodString>>;
384
+ tabId: z.ZodOptional<z.ZodString>;
385
+ nthChild: z.ZodOptional<z.ZodNumber>;
386
+ x: z.ZodOptional<z.ZodNumber>;
387
+ y: z.ZodOptional<z.ZodNumber>;
388
+ depth: z.ZodOptional<z.ZodNumber>;
389
+ marker: z.ZodOptional<z.ZodString>;
390
+ scrollHierarchy: z.ZodOptional<z.ZodArray<z.ZodObject<{
391
+ initialScrollTop: z.ZodNumber;
392
+ initialScrollLeft: z.ZodNumber;
393
+ containerRect: z.ZodNullable<z.ZodObject<{
394
+ top: z.ZodNumber;
395
+ right: z.ZodNumber;
396
+ bottom: z.ZodNumber;
397
+ left: z.ZodNumber;
398
+ width: z.ZodNumber;
399
+ height: z.ZodNumber;
400
+ x: z.ZodNumber;
401
+ y: z.ZodNumber;
402
+ }, z.core.$strip>>;
403
+ absoluteDepth: z.ZodNumber;
404
+ hasStickyAncestor: z.ZodOptional<z.ZodBoolean>;
405
+ }, z.core.$strip>>>;
406
+ position: z.ZodOptional<z.ZodEnum<{
407
+ static: "static";
408
+ relative: "relative";
409
+ absolute: "absolute";
410
+ fixed: "fixed";
411
+ sticky: "sticky";
412
+ }>>;
413
+ stickyConfig: z.ZodOptional<z.ZodObject<{
414
+ top: z.ZodNullable<z.ZodNumber>;
415
+ bottom: z.ZodNullable<z.ZodNumber>;
416
+ left: z.ZodNullable<z.ZodNumber>;
417
+ right: z.ZodNullable<z.ZodNumber>;
418
+ naturalTop: z.ZodNumber;
419
+ naturalLeft: z.ZodNumber;
420
+ containerWidth: z.ZodNumber;
421
+ containerHeight: z.ZodNumber;
422
+ elementWidth: z.ZodNumber;
423
+ elementHeight: z.ZodNumber;
424
+ anchorAbsoluteDepth: z.ZodNumber;
425
+ }, z.core.$strip>>;
426
+ initialWindowX: z.ZodOptional<z.ZodNumber>;
427
+ initialWindowY: z.ZodOptional<z.ZodNumber>;
428
+ hasContainingBlock: z.ZodOptional<z.ZodBoolean>;
429
+ rect: z.ZodOptional<z.ZodObject<{
430
+ top: z.ZodNumber;
431
+ right: z.ZodNumber;
432
+ bottom: z.ZodNumber;
433
+ left: z.ZodNumber;
434
+ width: z.ZodNumber;
435
+ height: z.ZodNumber;
436
+ x: z.ZodNumber;
437
+ y: z.ZodNumber;
438
+ }, z.core.$strip>>;
439
+ }, z.core.$strip>;
440
+ }, z.core.$strip>>;
441
+ lastUpdated: z.ZodNumber;
442
+ }, z.core.$strip>;
443
+
444
+ /**
445
+ * @caliper/agent-bridge
446
+ * Enables AI agents to use Caliper's high-precision measurement engine
447
+ *
448
+ * @example
449
+ * ```typescript
450
+ * import { createMeasurementSystem, createSelectionSystem } from "@oyerinde/caliper/core";
451
+ * import { bridge } from "@oyerinde/caliper-bridge";
452
+ *
453
+ * const measurementSystem = createMeasurementSystem();
454
+ * const selectionSystem = createSelectionSystem();
455
+ *
456
+ * const cleanup = bridge({
457
+ * enabled: true,
458
+ * systems: { measurementSystem, selectionSystem }
459
+ * });
460
+ * ```
461
+ */
462
+
463
+ /**
464
+ * CaliperBridge Plugin Factory
465
+ *
466
+ * Creates a Caliper plugin that enables AI agents to interact with the overlay via
467
+ * a WebSocket bridge (local MCP relay) or direct global intent dispatching.
468
+ *
469
+ * When installed, this plugin:
470
+ * 1. Starts a local WebSocket server (or connects to one) to receive agent commands.
471
+ * 2. Exposes `window.dispatchCaliperIntent` for manual/in-page agentic calls.
472
+ * 3. Syncs the overlay state (camera, selection, measurements) back to the agent.
473
+ *
474
+ * @example
475
+ * ```ts
476
+ * import { init } from "@oyerinde/caliper/preset";
477
+ * import { CaliperBridge } from "@oyerinde/caliper/bridge";
478
+ *
479
+ * init({ ... }, [
480
+ * new CaliperBridge({
481
+ * enabled: true,
482
+ * wsPort: 3010,
483
+ * onStateChange: (state) => console.log("New Agent State:", state)
484
+ * })
485
+ * ]);
486
+ * ```
487
+ *
488
+ * @param config - The bridge configuration settings.
489
+ * @returns A CaliperPlugin that can be used with `caliper.use()` or in `init()`.
490
+ */
491
+ export declare function CaliperBridge(config: AgentBridgeConfig): CaliperPlugin;
492
+
493
+ export declare interface CaliperConfig {
494
+ /** Customize the visual appearance of the overlay (colors, shadows). */
495
+ theme?: ThemeConfig;
496
+ /** Customize keyboard shortcuts for all interactions. */
497
+ commands?: CommandsConfig;
498
+ /** Control the boundary box lerp animation behavior. */
499
+ animation?: AnimationConfig;
500
+ /** Enable debug logging (default: true). All logs are stripped from production builds. */
501
+ debug?: boolean;
502
+ }
503
+
504
+ /**
505
+ * A plugin allows extending Caliper's functionality by accessing the
506
+ * OverlayInstance and internal systems.
507
+ */
508
+ export declare interface CaliperPlugin {
509
+ /** Unique identifier for the plugin. Used for deduplication. */
510
+ name: string;
511
+ /** Called when the plugin is installed on an overlay instance. */
512
+ install: (instance: OverlayInstance) => void;
513
+ /** Optional cleanup logic called when the overlay is disposed. */
514
+ dispose?: () => void;
515
+ }
516
+
517
+ /**
518
+ * A helper function for developers to add stable markers to their components.
519
+ * Returns an object with the data-caliper-marker attribute.
520
+ *
521
+ * @example
522
+ * <div {...caliperProps("main-logo")}>...</div>
523
+ */
524
+ export declare function caliperProps(marker: string): {
525
+ "data-caliper-marker"?: undefined;
526
+ } | {
527
+ "data-caliper-marker": string;
528
+ };
529
+
530
+ export declare interface CommandsConfig {
531
+ /** Key to activate measuring mode (default: Alt) */
532
+ activate?: string;
533
+ /** Key to freeze current measurement (default: Space) */
534
+ freeze?: string;
535
+ /** Key to select an element - must be held + click (default: Control) */
536
+ select?: string;
537
+ /** Key to clear current selection (default: Escape) */
538
+ clear?: string;
539
+ /** Custom keys to trigger calculator for specific sides (default: t, r, b, l) */
540
+ calculator?: CalculatorShortcuts;
541
+ /** Custom keys to trigger projection for specific directions (default: w, a, s, d) */
542
+ projection?: ProjectionShortcuts;
543
+ /** Key to trigger ruler lines - must be Shift + this key (default: r) */
544
+ ruler?: string;
545
+ /** Duration in ms to hold the select key to trigger selection (default: 250) */
546
+ selectionHoldDuration?: number;
547
+ }
548
+
549
+ /**
550
+ * An extension can be either a simple function that receives the Caliper instance,
551
+ * or a full Plugin object with an `install` method.
552
+ */
553
+ export declare type Extension = ((instance: OverlayInstance) => void) | CaliperPlugin;
554
+
555
+ /**
556
+ * High-level initialization for Caliper with support for extensions and plugins.
557
+ *
558
+ * This "preset" initializer streamlines setting up Caliper in development or
559
+ * agentic environments by handling both core configuration and plugin injection
560
+ * in a single call.
561
+ *
562
+ * It accepts two types of extensions:
563
+ * 1. Simple callback functions: `(instance: OverlayInstance) => void`
564
+ * 2. Formal Caliper plugins: Objects with an `install(instance: OverlayInstance)` method.
565
+ *
566
+ * @example
567
+ * ```ts
568
+ * import { init, CaliperBridge } from "@oyerinde/caliper/preset";
569
+ *
570
+ * const caliper = init({
571
+ * theme: { primary: "#18a0fb" }
572
+ * }, [
573
+ * (instance) => console.log("Caliper ready!", instance),
574
+ * CaliperBridge({ wsPort: 3010 })
575
+ * ]);
576
+ * ```
577
+ *
578
+ * @param configuration - Caliper core configuration (theme, commands, settings).
579
+ * @param extensions - An array of functions or plugin objects to install immediately.
580
+ * @returns The initialized Caliper OverlayInstance.
581
+ */
582
+ export declare function init(configuration?: CaliperConfig, extensions?: Array<Extension>): OverlayInstance;
583
+
584
+ declare type MeasurementResult = Remap<MeasurementResult_2, {
585
+ primary: DOMRect;
586
+ secondary: DOMRect | null;
587
+ primaryHierarchy: ScrollState[];
588
+ secondaryHierarchy: ScrollState[];
589
+ secondaryElement: Element | null;
590
+ }>;
591
+
592
+ declare type MeasurementResult_2 = Prettify_2<z.infer<typeof MeasurementResultSchema>>;
593
+
594
+ declare const MeasurementResultSchema: z.ZodObject<{
595
+ context: z.ZodNullable<z.ZodEnum<{
596
+ parent: "parent";
597
+ child: "child";
598
+ sibling: "sibling";
599
+ }>>;
600
+ lines: z.ZodArray<z.ZodObject<{
601
+ type: z.ZodEnum<{
602
+ top: "top";
603
+ right: "right";
604
+ bottom: "bottom";
605
+ left: "left";
606
+ distance: "distance";
607
+ }>;
608
+ value: z.ZodNumber;
609
+ start: z.ZodObject<{
610
+ x: z.ZodNumber;
611
+ y: z.ZodNumber;
612
+ }, z.core.$strip>;
613
+ end: z.ZodObject<{
614
+ x: z.ZodNumber;
615
+ y: z.ZodNumber;
616
+ }, z.core.$strip>;
617
+ startSync: z.ZodOptional<z.ZodEnum<{
618
+ primary: "primary";
619
+ secondary: "secondary";
620
+ }>>;
621
+ endSync: z.ZodOptional<z.ZodEnum<{
622
+ primary: "primary";
623
+ secondary: "secondary";
624
+ }>>;
625
+ }, z.core.$strip>>;
626
+ primary: z.ZodObject<{
627
+ top: z.ZodNumber;
628
+ right: z.ZodNumber;
629
+ bottom: z.ZodNumber;
630
+ left: z.ZodNumber;
631
+ width: z.ZodNumber;
632
+ height: z.ZodNumber;
633
+ x: z.ZodNumber;
634
+ y: z.ZodNumber;
635
+ }, z.core.$strip>;
636
+ secondary: z.ZodNullable<z.ZodObject<{
637
+ top: z.ZodNumber;
638
+ right: z.ZodNumber;
639
+ bottom: z.ZodNumber;
640
+ left: z.ZodNumber;
641
+ width: z.ZodNumber;
642
+ height: z.ZodNumber;
643
+ x: z.ZodNumber;
644
+ y: z.ZodNumber;
645
+ }, z.core.$strip>>;
646
+ timestamp: z.ZodNumber;
647
+ primaryHierarchy: z.ZodArray<z.ZodObject<{
648
+ initialScrollTop: z.ZodNumber;
649
+ initialScrollLeft: z.ZodNumber;
650
+ containerRect: z.ZodNullable<z.ZodObject<{
651
+ top: z.ZodNumber;
652
+ right: z.ZodNumber;
653
+ bottom: z.ZodNumber;
654
+ left: z.ZodNumber;
655
+ width: z.ZodNumber;
656
+ height: z.ZodNumber;
657
+ x: z.ZodNumber;
658
+ y: z.ZodNumber;
659
+ }, z.core.$strip>>;
660
+ absoluteDepth: z.ZodNumber;
661
+ hasStickyAncestor: z.ZodOptional<z.ZodBoolean>;
662
+ }, z.core.$strip>>;
663
+ secondaryHierarchy: z.ZodArray<z.ZodObject<{
664
+ initialScrollTop: z.ZodNumber;
665
+ initialScrollLeft: z.ZodNumber;
666
+ containerRect: z.ZodNullable<z.ZodObject<{
667
+ top: z.ZodNumber;
668
+ right: z.ZodNumber;
669
+ bottom: z.ZodNumber;
670
+ left: z.ZodNumber;
671
+ width: z.ZodNumber;
672
+ height: z.ZodNumber;
673
+ x: z.ZodNumber;
674
+ y: z.ZodNumber;
675
+ }, z.core.$strip>>;
676
+ absoluteDepth: z.ZodNumber;
677
+ hasStickyAncestor: z.ZodOptional<z.ZodBoolean>;
678
+ }, z.core.$strip>>;
679
+ primaryPosition: z.ZodEnum<{
680
+ static: "static";
681
+ relative: "relative";
682
+ absolute: "absolute";
683
+ fixed: "fixed";
684
+ sticky: "sticky";
685
+ }>;
686
+ secondaryPosition: z.ZodEnum<{
687
+ static: "static";
688
+ relative: "relative";
689
+ absolute: "absolute";
690
+ fixed: "fixed";
691
+ sticky: "sticky";
692
+ }>;
693
+ primaryWinX: z.ZodNumber;
694
+ primaryWinY: z.ZodNumber;
695
+ secondaryWinX: z.ZodNumber;
696
+ secondaryWinY: z.ZodNumber;
697
+ primarySticky: z.ZodOptional<z.ZodObject<{
698
+ top: z.ZodNullable<z.ZodNumber>;
699
+ bottom: z.ZodNullable<z.ZodNumber>;
700
+ left: z.ZodNullable<z.ZodNumber>;
701
+ right: z.ZodNullable<z.ZodNumber>;
702
+ naturalTop: z.ZodNumber;
703
+ naturalLeft: z.ZodNumber;
704
+ containerWidth: z.ZodNumber;
705
+ containerHeight: z.ZodNumber;
706
+ elementWidth: z.ZodNumber;
707
+ elementHeight: z.ZodNumber;
708
+ anchorAbsoluteDepth: z.ZodNumber;
709
+ }, z.core.$strip>>;
710
+ secondarySticky: z.ZodOptional<z.ZodObject<{
711
+ top: z.ZodNullable<z.ZodNumber>;
712
+ bottom: z.ZodNullable<z.ZodNumber>;
713
+ left: z.ZodNullable<z.ZodNumber>;
714
+ right: z.ZodNullable<z.ZodNumber>;
715
+ naturalTop: z.ZodNumber;
716
+ naturalLeft: z.ZodNumber;
717
+ containerWidth: z.ZodNumber;
718
+ containerHeight: z.ZodNumber;
719
+ elementWidth: z.ZodNumber;
720
+ elementHeight: z.ZodNumber;
721
+ anchorAbsoluteDepth: z.ZodNumber;
722
+ }, z.core.$strip>>;
723
+ primaryHasContainingBlock: z.ZodOptional<z.ZodBoolean>;
724
+ secondaryHasContainingBlock: z.ZodOptional<z.ZodBoolean>;
725
+ }, z.core.$strip>;
726
+
727
+ /**
728
+ * Measurement state machine
729
+ * IDLE → ARMED → MEASURING → FROZEN → IDLE
730
+ */
731
+ declare type MeasurementState = "IDLE" | "ARMED" | "MEASURING" | "FROZEN";
732
+
733
+ declare interface MeasurementSystem {
734
+ measure: (selectedElement: Element, cursor: {
735
+ x: number;
736
+ y: number;
737
+ }) => void;
738
+ abort: () => void;
739
+ stop: () => void;
740
+ freeze: () => void;
741
+ unfreeze: (isAltDown: boolean) => void;
742
+ cleanup: () => void;
743
+ getState: () => MeasurementState;
744
+ getCurrentResult: () => MeasurementResult | null;
745
+ getSecondaryElement: () => Element | null;
746
+ getCalculator: () => CalculatorIntegration;
747
+ getProjection: () => ProjectionSystem;
748
+ getRuler: () => RulerSystem;
749
+ onStateChange: (listener: MeasurementSystemListener) => () => void;
750
+ updatePrimaryRect: (rect: DOMRect) => void;
751
+ updateSecondaryRect: (rect: DOMRect) => void;
752
+ applyResult: (result: MeasurementResult) => void;
753
+ }
754
+
755
+ declare type MeasurementSystemListener = () => void;
756
+
757
+ /**
758
+ * Handle to a running Caliper overlay.
759
+ */
760
+ export declare interface OverlayInstance {
761
+ /**
762
+ * Mounts the overlay into the DOM.
763
+ * By default, it mounts into document.documentElement (safe for Shadow DOM).
764
+ */
765
+ mount: (container?: HTMLElement) => void;
766
+ /**
767
+ * Removes the overlay from the DOM and cleans up all event listeners and systems.
768
+ */
769
+ dispose: () => void;
770
+ /**
771
+ * Synchronously returns the internal systems if they are initialized.
772
+ */
773
+ getSystems: () => Systems | null;
774
+ /**
775
+ * Asynchronous helper that resolves when the internal systems are ready.
776
+ * Useful for plugins that need to interact with the DOM or state immediately.
777
+ */
778
+ waitForSystems: () => Promise<Systems>;
779
+ /**
780
+ * Registers a plugin with this instance.
781
+ */
782
+ use: (plugin: CaliperPlugin) => OverlayInstance;
783
+ /** Whether the overlay is currently mounted in the document. */
784
+ mounted: boolean;
785
+ }
786
+
787
+ declare type Prettify<T> = {
788
+ [K in keyof T]: T[K];
789
+ } & {};
790
+
791
+ declare type Prettify_2<T> = {
792
+ [K in keyof T]: T[K];
793
+ } & {};
794
+
795
+ declare type ProjectionDirection = "top" | "right" | "bottom" | "left";
796
+
797
+ declare type ProjectionListener = (state: ProjectionState) => void;
798
+
799
+ /**
800
+ * Keyboard shortcuts for projection directions.
801
+ */
802
+ declare interface ProjectionShortcuts {
803
+ top?: string;
804
+ left?: string;
805
+ bottom?: string;
806
+ right?: string;
807
+ }
808
+
809
+ declare interface ProjectionState {
810
+ direction: ProjectionDirection | null;
811
+ value: string;
812
+ element: HTMLElement | null;
813
+ }
814
+
815
+ declare interface ProjectionSystem {
816
+ getState: () => ProjectionState;
817
+ setDirection: (direction: ProjectionDirection | null) => void;
818
+ setElement: (element: HTMLElement | null) => void;
819
+ appendValue: (char: string, max?: number) => void;
820
+ capValue: (max: number) => void;
821
+ backspace: () => void;
822
+ clear: () => void;
823
+ onUpdate: (listener: ProjectionListener) => () => void;
824
+ }
825
+
826
+ declare type Remap<T, U> = Prettify<Omit<T, keyof U> & U>;
827
+
828
+ declare interface RulerLine {
829
+ id: string;
830
+ type: "horizontal" | "vertical";
831
+ position: number;
832
+ }
833
+
834
+ declare type RulerListener = (state: RulerState) => void;
835
+
836
+ declare interface RulerState {
837
+ lines: RulerLine[];
838
+ }
839
+
840
+ declare interface RulerSystem {
841
+ getState: () => RulerState;
842
+ addPair: (x: number, y: number) => string | null;
843
+ updateLine: (id: string, position: number) => void;
844
+ removeLine: (id: string) => void;
845
+ clear: () => void;
846
+ onUpdate: (listener: RulerListener) => () => void;
847
+ }
848
+
849
+ declare interface ScrollState extends ScrollState_2 {
850
+ element?: HTMLElement;
851
+ containerRect: DOMRect | null;
852
+ }
853
+
854
+ declare type ScrollState_2 = Prettify_2<z.infer<typeof ScrollStateSchema>>;
855
+
856
+ declare const ScrollStateSchema: z.ZodObject<{
857
+ initialScrollTop: z.ZodNumber;
858
+ initialScrollLeft: z.ZodNumber;
859
+ containerRect: z.ZodNullable<z.ZodObject<{
860
+ top: z.ZodNumber;
861
+ right: z.ZodNumber;
862
+ bottom: z.ZodNumber;
863
+ left: z.ZodNumber;
864
+ width: z.ZodNumber;
865
+ height: z.ZodNumber;
866
+ x: z.ZodNumber;
867
+ y: z.ZodNumber;
868
+ }, z.core.$strip>>;
869
+ absoluteDepth: z.ZodNumber;
870
+ hasStickyAncestor: z.ZodOptional<z.ZodBoolean>;
871
+ }, z.core.$strip>;
872
+
873
+ /**
874
+ * Selection system for tracking selected elements
875
+ */
876
+ declare type SelectionMetadata = Remap<SelectionMetadata_2, {
877
+ element: Element | null;
878
+ rect: DOMRect | null;
879
+ scrollHierarchy: ScrollState[];
880
+ }>;
881
+
882
+ declare type SelectionMetadata_2 = Prettify_2<z.infer<typeof SelectionMetadataSchema>>;
883
+
884
+ declare const SelectionMetadataSchema: z.ZodObject<{
885
+ rect: z.ZodNullable<z.ZodObject<{
886
+ top: z.ZodNumber;
887
+ right: z.ZodNumber;
888
+ bottom: z.ZodNumber;
889
+ left: z.ZodNumber;
890
+ width: z.ZodNumber;
891
+ height: z.ZodNumber;
892
+ x: z.ZodNumber;
893
+ y: z.ZodNumber;
894
+ }, z.core.$strip>>;
895
+ scrollHierarchy: z.ZodArray<z.ZodObject<{
896
+ initialScrollTop: z.ZodNumber;
897
+ initialScrollLeft: z.ZodNumber;
898
+ containerRect: z.ZodNullable<z.ZodObject<{
899
+ top: z.ZodNumber;
900
+ right: z.ZodNumber;
901
+ bottom: z.ZodNumber;
902
+ left: z.ZodNumber;
903
+ width: z.ZodNumber;
904
+ height: z.ZodNumber;
905
+ x: z.ZodNumber;
906
+ y: z.ZodNumber;
907
+ }, z.core.$strip>>;
908
+ absoluteDepth: z.ZodNumber;
909
+ hasStickyAncestor: z.ZodOptional<z.ZodBoolean>;
910
+ }, z.core.$strip>>;
911
+ position: z.ZodEnum<{
912
+ static: "static";
913
+ relative: "relative";
914
+ absolute: "absolute";
915
+ fixed: "fixed";
916
+ sticky: "sticky";
917
+ }>;
918
+ stickyConfig: z.ZodOptional<z.ZodObject<{
919
+ top: z.ZodNullable<z.ZodNumber>;
920
+ bottom: z.ZodNullable<z.ZodNumber>;
921
+ left: z.ZodNullable<z.ZodNumber>;
922
+ right: z.ZodNullable<z.ZodNumber>;
923
+ naturalTop: z.ZodNumber;
924
+ naturalLeft: z.ZodNumber;
925
+ containerWidth: z.ZodNumber;
926
+ containerHeight: z.ZodNumber;
927
+ elementWidth: z.ZodNumber;
928
+ elementHeight: z.ZodNumber;
929
+ anchorAbsoluteDepth: z.ZodNumber;
930
+ }, z.core.$strip>>;
931
+ initialWindowX: z.ZodNumber;
932
+ initialWindowY: z.ZodNumber;
933
+ depth: z.ZodNumber;
934
+ hasContainingBlock: z.ZodOptional<z.ZodBoolean>;
935
+ }, z.core.$strip>;
936
+
937
+ declare interface SelectionSystem {
938
+ select: (element: Element | null) => void;
939
+ getSelected: () => Element | null;
940
+ getSelectedRect: () => DOMRect | null;
941
+ getMetadata: () => SelectionMetadata;
942
+ clear: () => void;
943
+ onUpdate: (callback: (metadata: SelectionMetadata) => void) => () => void;
944
+ updateRect: (rect: DOMRect) => void;
945
+ }
946
+
947
+ export declare interface Systems {
948
+ measurementSystem: MeasurementSystem;
949
+ selectionSystem: SelectionSystem;
950
+ }
951
+
952
+ export declare interface ThemeConfig {
953
+ primary?: string;
954
+ secondary?: string;
955
+ calcBg?: string;
956
+ calcShadow?: string;
957
+ calcOpHighlight?: string;
958
+ calcText?: string;
959
+ text?: string;
960
+ projection?: string;
961
+ ruler?: string;
962
+ }
963
+
964
+ export { }