@embedpdf/plugin-stage 3.0.0-next.1 → 3.0.0-next.10

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/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { CapabilityToken, PageLayout, PageObjectNumber, PdfDestination } from "@embedpdf/core";
2
2
  import { PageRotation, PageTransform, Rect } from "@embedpdf/core-geometry";
3
3
  import { Align, AlignValue, Alignment, Alignment as Alignment$1, AlignmentValue, Anchor, Camera, Direction, Direction as Direction$1, PageBox, PageFrame, PageFrame as PageFrame$1, Point, ScrollMetrics, ScrollMetrics as ScrollMetrics$1, Size, SizingMode, SizingMode as SizingMode$1, SpreadMode, SpreadMode as SpreadMode$1, ZoomMode, ZoomModeValue, ZoomModeValue as ZoomModeValue$1, ZoomSpec, ZoomSpec as ZoomSpec$1 } from "@embedpdf/core-stage";
4
+ import { InteractionCapability, InteractionHandler } from "@embedpdf/plugin-interaction";
4
5
  //#region src/types.d.ts
5
6
  type LayoutKind = 'vertical' | 'horizontal' | 'grid';
6
7
  /** Navigation (goToPage) either tweens the camera or jumps instantly. */
@@ -30,6 +31,53 @@ type GridColumns = 'square' | 'auto' | number;
30
31
  type Gap = number | {
31
32
  px: number;
32
33
  };
34
+ /**
35
+ * The one environmental fact a headless stage has: the box it was told about
36
+ * (`setViewport`). Responsive rules can query nothing else — no user agent, no
37
+ * pointer type (modality is per-event, on `PointerSample`), no window. Space,
38
+ * not device: a narrow pane on a desktop is compact too, and each stage
39
+ * instance resolves against ITS OWN box.
40
+ */
41
+ interface StageBox {
42
+ width: number;
43
+ height: number;
44
+ /** Of the CONTAINER, not the device. A square box is 'portrait' (the CSS rule). */
45
+ orientation: 'portrait' | 'landscape';
46
+ }
47
+ /** Declarative box query — all bounds inclusive, all fields optional (AND-ed). */
48
+ interface BoxQuery {
49
+ minWidth?: number;
50
+ maxWidth?: number;
51
+ minHeight?: number;
52
+ maxHeight?: number;
53
+ orientation?: 'portrait' | 'landscape';
54
+ }
55
+ /**
56
+ * One `@container` block for the settings bag: when the box matches, assert
57
+ * this settings patch. Rules evaluate in source order and ALL matching rules
58
+ * apply, later winning per key (each key replaced whole — no deep merges).
59
+ * Effective settings = base (config + runtime setters) ⊕ matching patches.
60
+ *
61
+ * Semantics, stated honestly:
62
+ * • Runtime setters write the BASE; a matching rule wins over it. Apps
63
+ * needing situational absolute control edit the rules (`setResponsive`).
64
+ * • Rules assert at TRANSITIONS (box/base/rules changes), not continuously —
65
+ * between crossings, interaction owns the state. A rule containing `zoom`
66
+ * re-fits when the box crosses it (the rotate-an-iPad behavior) and then
67
+ * leaves the pinch alone.
68
+ *
69
+ * A rule with a `name` is a queryable fact (`matches(name)`), reactive in
70
+ * every framework; a named rule with NO settings is a pure shared breakpoint
71
+ * the app chrome can key its own presentation off — one definition serving
72
+ * both the layout math and the UI.
73
+ */
74
+ interface ResponsiveRule {
75
+ name?: string;
76
+ /** Declarative box query, or a predicate for anything the box can answer. */
77
+ when: BoxQuery | ((box: StageBox) => boolean);
78
+ /** The settings this situation asserts. Omit for a pure named query. */
79
+ settings?: Partial<StageSettings>;
80
+ }
33
81
  /**
34
82
  * One axis of the ARRIVAL policy — stage-core's AlignValue ('start' |
35
83
  * 'center' | 'end' | viewport fraction 0–1) plus one navigation-only word:
@@ -159,7 +207,7 @@ interface StageSettings {
159
207
  * `x/y/width/height` only to POSITION the page container.
160
208
  * - `transform`: PRESENTATION truth — the single bridge between PDF points,
161
209
  * view px, and device px for this page. Plugins do ALL coordinate work
162
- * through it (`pageToView` / `viewToPage` / `deviceWidth` / `cssMatrix`),
210
+ * through it (`contentToView` / `viewToContent` / `deviceWidth` / `cssMatrix`),
163
211
  * never by re-deriving `x * scale` / `* dpr`. Page-local, so it's
164
212
  * camera/pan-invariant.
165
213
  */
@@ -186,6 +234,29 @@ interface VisiblePage extends PageBox {
186
234
  }
187
235
  interface StageState extends StageSettings {
188
236
  camera: Camera;
237
+ /**
238
+ * One-way render-commit latch. False while the initial viewport-driven
239
+ * placement is unresolved; true only after its camera/settings writes have
240
+ * completed. Page/scroll screen-space selectors refuse to answer while
241
+ * false, so an adapter can never paint the placeholder camera at the origin.
242
+ */
243
+ placed: boolean;
244
+ /**
245
+ * Names of the responsive rules currently matching the box, in source order.
246
+ * State (not derived) so `matches()` is reactive through the ordinary
247
+ * selector machinery in every framework.
248
+ */
249
+ activeRules: readonly string[];
250
+ /**
251
+ * False while the ZOOM is in motion, true once it has rested (~150ms of
252
+ * frames without a zoom write). Device-snapping of page origins is gated
253
+ * on this: a continuous zoom and a snapped origin cannot coexist without
254
+ * the anchor point jittering ±0.5 device px per step (the rounding lands
255
+ * differently every frame), so pages place fractionally while zooming and
256
+ * snap once at rest — when crispness actually matters. Pans always snap
257
+ * (a pure translation snap has no anchor error). Transient like `camera`.
258
+ */
259
+ cameraResting: boolean;
189
260
  vp: Size;
190
261
  /**
191
262
  * Device pixels per view pixel (web: `window.devicePixelRatio`). Reported by
@@ -204,6 +275,11 @@ interface StageState extends StageSettings {
204
275
  type StageAction = {
205
276
  type: 'CAMERA';
206
277
  camera: Camera;
278
+ } | {
279
+ type: 'CAMERA_REST';
280
+ resting: boolean;
281
+ } | {
282
+ type: 'PLACED';
207
283
  } | {
208
284
  type: 'VP';
209
285
  vp: Size;
@@ -216,6 +292,9 @@ type StageAction = {
216
292
  } | {
217
293
  type: 'PATCH';
218
294
  patch: Partial<StageSettings>;
295
+ } | {
296
+ type: 'RESPONSIVE';
297
+ active: readonly string[];
219
298
  };
220
299
  /**
221
300
  * A page-relative view memento: "what I'm looking at and how zoomed". The durable
@@ -309,11 +388,13 @@ type RevealZoom = 'keep' | 'fit' | 'fit-width' | 'fit-height' | {
309
388
  interface RevealOptions {
310
389
  behavior?: ScrollBehaviorKind;
311
390
  /**
312
- * CONTENT-space target rect on the page (y-down, crop-relative, unscaled
313
- * points — the same space selection/search rects live in). Absent → the
314
- * whole page. A zero-size rect is a point (/XYZ).
391
+ * Target rect on the page in the VIEWER's coordinates (y-down,
392
+ * crop-relative, unscaled points — the same `Rect` selection/search rects
393
+ * and `CommentThreadView.contentRect` live in). Absent or `null` → the
394
+ * whole page (null accepted so nullable sources flow in directly). A
395
+ * zero-size rect is a point (/XYZ).
315
396
  */
316
- rect?: Rect;
397
+ rect?: Rect | null;
317
398
  zoom?: RevealZoom;
318
399
  anchor?: RevealAnchor;
319
400
  }
@@ -424,6 +505,45 @@ interface StageCapability {
424
505
  /** `Element.scrollBy`: relative offsets — sugar over `scrollTo`. */
425
506
  scrollBy(opts: StageScrollToOptions): void;
426
507
  zoomAround(screenPt: Point, factor: number): void;
508
+ /**
509
+ * Bracket a continuous direct-manipulation gesture (touch pan / pinch).
510
+ * While a gesture is open the camera writes stay cheap and visually calm:
511
+ * `zoomAround` defers its zoom-intent PATCH (one per gesture instead of one
512
+ * per event), and the camera-rest detector holds un-rested — device
513
+ * snapping and settle-gated rendering wait for the END of the gesture, not
514
+ * for a 150 ms hesitation inside it. Re-entrant (nesting counts). Opening a
515
+ * gesture cancels any running tween or fling — that is how a finger
516
+ * "catches" a moving page.
517
+ *
518
+ * `elastic` opts the gesture into RUBBER-BAND overscroll: pans past the
519
+ * clamp stretch on the iOS resistance curve instead of stopping dead, and
520
+ * ending the gesture (or a fling reaching an edge) springs the camera home
521
+ * on a critically-damped curve. The clamp itself stays the untouched law of
522
+ * REST — elasticity is a transient the gesture is allowed to hold, never a
523
+ * state the camera can settle in. Touch contacts pass it; mouse drags and
524
+ * wheel pans stay rigid (the desktop convention). Default false.
525
+ */
526
+ beginGesture(options?: {
527
+ elastic?: boolean;
528
+ }): void;
529
+ endGesture(): void;
530
+ /**
531
+ * Momentum scroll: keep panning from a release velocity (screen px/s, the
532
+ * same sign convention as `panBy` deltas), decelerating on UIScrollView's
533
+ * curve. Every other camera verb — including `beginGesture` from the next
534
+ * touch — cancels it. No-op without host frames (SSR/tests without a
535
+ * scheduler jump nowhere: momentum is presentation, not state).
536
+ */
537
+ fling(velocityX: number, velocityY: number): void;
538
+ /** True while the camera is animating (navigation tween or fling) — the
539
+ * input layer reads it to tell a "catch" from a tap. */
540
+ cameraInMotion(): boolean;
541
+ /**
542
+ * The touch double-tap toggle: zoomed out → animate to ~2.5× the automatic
543
+ * fit around `screenPt`; already zoomed past that → animate back to the fit
544
+ * level, same focal point. Lands as a fixed zoom level either way.
545
+ */
546
+ doubleTapZoom(screenPt: Point): void;
427
547
  zoomIn(): void;
428
548
  zoomOut(): void;
429
549
  zoomTo(spec: ZoomSpec$1): void;
@@ -459,9 +579,26 @@ interface StageCapability {
459
579
  next(opts?: GoToOptions): void;
460
580
  /** Step backward by the navigation unit. */
461
581
  prev(opts?: GoToOptions): void;
582
+ /**
583
+ * This lens's identity — the stage plugin id it was registered under
584
+ * ('stage' for the main lens; a custom id per additional lens). The surface
585
+ * binding stamps it on every pointer sample (`PointerSample.source`) and
586
+ * lens-scoped interaction handlers register under it, so two stages on one
587
+ * document can never capture each other's input.
588
+ */
589
+ lensId(): string;
462
590
  /** Set any subset of settings at once — ONE anchor-preserving update. The way to
463
- * apply a customer preset: `update(myPreset)`. */
591
+ * apply a customer preset: `update(myPreset)`. Writes the responsive BASE:
592
+ * a matching rule's key wins until its rule stops matching. */
464
593
  update(patch: Partial<StageSettings>): void;
594
+ /** Replace the responsive rules (see {@link ResponsiveRule}); re-resolves
595
+ * immediately with the usual anchor-preserving reactions. */
596
+ setResponsive(rules: readonly ResponsiveRule[]): void;
597
+ /** Is the named responsive rule currently matching? Reactive: recomputed
598
+ * whenever the box crosses a rule boundary. */
599
+ matches(name: string): boolean;
600
+ /** Names of all currently-matching rules, in source order. */
601
+ activeRules(): readonly string[];
465
602
  setFlow(flow: FlowMode): void;
466
603
  setLayout(layout: LayoutKind): void;
467
604
  setSpread(spread: SpreadMode$1): void;
@@ -495,6 +632,12 @@ interface StageCapability {
495
632
  interface StageConfig extends Partial<StageSettings> {
496
633
  /** Override the host timing seam (tests/SSR). Defaults to browser rAF. */
497
634
  scheduler?: Scheduler;
635
+ /**
636
+ * Container queries for the settings bag (see {@link ResponsiveRule}).
637
+ * Defaults to `DEFAULT_RESPONSIVE` (compact containers get the thin phone
638
+ * gutter); pass `[]` to opt out entirely.
639
+ */
640
+ responsive?: readonly ResponsiveRule[];
498
641
  }
499
642
  declare const StageToken: import("@embedpdf/core").CapabilityToken<StageCapability>;
500
643
  //#endregion
@@ -518,20 +661,6 @@ declare const StageToken: import("@embedpdf/core").CapabilityToken<StageCapabili
518
661
  interface StagePluginOptions extends StageConfig {
519
662
  id?: string;
520
663
  token?: CapabilityToken<StageCapability>;
521
- /**
522
- * Opt this lens into the interaction hub: register a tool-gated `scroll`
523
- * handler (so dragging pans only in `pan` mode). Pair with `<Stage interaction>`
524
- * on the React side, which forwards pointer events to the hub. Default false —
525
- * secondary lenses (thumbnails) stay click-to-navigate.
526
- */
527
- interaction?: boolean;
528
- /**
529
- * When {@link interaction} is on, let drags over page GAPS pan regardless of the
530
- * active tool (and show a grab cursor there) — the gutter always pans, matching
531
- * v2 and the intuition that there's nothing to draw/select outside a page.
532
- * On-page behaviour is untouched. Default true; ignored without `interaction`.
533
- */
534
- panFallback?: boolean;
535
664
  }
536
665
  /**
537
666
  * Wires the parts into a kernel plugin. This file is the "manifest": it says what
@@ -554,37 +683,28 @@ interface DestinationReveal {
554
683
  */
555
684
  declare function destinationToReveal(dest: PdfDestination, layout: PageLayout, bbox?: Rect): DestinationReveal;
556
685
  //#endregion
557
- //#region src/wheel.d.ts
686
+ //#region src/scroll-handler.d.ts
687
+ interface ScrollHandlerOptions {
688
+ /**
689
+ * Let a drag over a page GAP pan regardless of the active tool — and show a grab
690
+ * cursor there — so the gutter always pans (v2 parity, and the natural feel:
691
+ * outside a page there's nothing to draw/select on). On-page behaviour is
692
+ * untouched; the tool's own gesture still owns page space. Default true.
693
+ */
694
+ panFallback?: boolean;
695
+ }
558
696
  /**
559
- * Wheel-input classification for ambient zoom — pure, so every framework
560
- * adapter shares one feel and the mapping is unit-testable.
561
- *
562
- * A ctrl/cmd wheel event is one of three physically different inputs that
563
- * happen to share an event type, each with its own unit system:
697
+ * Pan-the-camera as an interaction handler. Live under the built-in `pan` tool
698
+ * (the `scroll` tag) and — with `panFallback` — under every tool, where it then
699
+ * captures ONLY page-gap drags (on-page downs belong to the active tool, which
700
+ * claims them first at higher priority). It uses the sample's viewport delta, so
701
+ * it pans over the whole viewport (pages and gaps).
564
702
  *
565
- * • trackpad PINCH — browsers (Chrome/Edge/Firefox) synthesize ctrl+wheel
566
- * px-deltas scaled to the de-facto convention that `exp(-Δ/100)` tracks
567
- * the physical finger scale 1:1. Anything weaker feels dead (the content
568
- * must track the fingers — the Figma/maps feel).
569
- * • mouse NOTCHES — coarse steps: ±100/±120 px in Chrome, lines/pages mode
570
- * in Firefox. The pinch mapping would triple per click; a notch instead
571
- * steps by 1.2, the same ratio as the zoom buttons.
572
- * • cmd + continuous SCROLL — real scroll px, big and streaming (with
573
- * momentum): a gentle scrub coefficient. A cmd+mouse notch (±120 px)
574
- * lands within 0.3% of the 1.2 button step, so it needs no special case.
575
- *
576
- * (Safari never synthesizes ctrl+wheel for pinch — it fires proprietary
577
- * gesture events with an absolute scale; that wiring lives in the adapters.)
703
+ * Cursor feel: a closed hand (`grabbing`) while dragging; an open hand (`grab`)
704
+ * hovering a gap under a non-pan tool. The pan tool's own resting `grab` comes
705
+ * from its `Tool.cursor`, so hovering it needs no claim here.
578
706
  */
579
- interface WheelSample {
580
- deltaY: number;
581
- /** WheelEvent.deltaMode: 0 = pixels, 1 = lines, 2 = pages. */
582
- deltaMode: number;
583
- ctrlKey: boolean;
584
- metaKey: boolean;
585
- }
586
- /** Zoom factor for a ctrl/cmd wheel event (the caller decides zoom vs pan). */
587
- declare function wheelZoomFactor(e: WheelSample): number;
707
+ declare function createScrollHandler(stage: StageCapability, interaction: InteractionCapability, options?: ScrollHandlerOptions): InteractionHandler;
588
708
  //#endregion
589
709
  //#region src/settings.d.ts
590
710
  /**
@@ -595,9 +715,41 @@ declare function wheelZoomFactor(e: WheelSample): number;
595
715
  * `update()`, so that taxonomy stays a customer concern.
596
716
  */
597
717
  declare const DEFAULT_SETTINGS: StageSettings;
718
+ /**
719
+ * Out-of-the-box responsive rules — the platform feel with zero configuration:
720
+ * a compact container gets the thin gutter phones use (space, not device — an
721
+ * embedded 500px pane on a desktop is compact too). Override the whole list
722
+ * with `stagePlugin({ responsive: [...] })`; `responsive: []` opts out. The
723
+ * 'compact' name is queryable app-side via `stage.matches('compact')`.
724
+ */
725
+ declare const DEFAULT_RESPONSIVE: readonly ResponsiveRule[];
598
726
  /** Field-by-field settings equality, derived from the registry — a new setting is
599
727
  * covered automatically. (The React `useStageSettings` selector equality.) */
600
728
  declare const settingsEqual: (a: StageSettings, b: StageSettings) => boolean;
601
729
  //#endregion
602
- export { type Align, type Alignment, DEFAULT_SETTINGS, type DestinationReveal, type Direction, type FlowMode, type Gap, type GoToOptions, type GridColumns, type LayoutKind, type PageFrame, type RevealAnchor, type RevealAnchorValue, type RevealOptions, type RevealZoom, type Scheduler, type ScrollBehaviorKind, type ScrollMetrics, type SizingMode, type SpreadMode, type StageAction, type StageCapability, type StageConfig, type StagePluginOptions, type StageScrollToOptions, type StageSettings, type StageState, StageToken, type StageViewState, type Viewpoint, type VisiblePage, type WheelSample, ZoomMode, type ZoomModeValue, type ZoomSpec, destinationToReveal, settingsEqual, stagePlugin, wheelZoomFactor };
730
+ //#region src/responsive.d.ts
731
+ /**
732
+ * Container queries for the settings bag — the pure half. The capability owns
733
+ * the driver (when to re-resolve, how to react); the LAWS live here: what a
734
+ * box is, when a query matches, and what the effective settings are. No state,
735
+ * no dispatch — property-testable in isolation (the `wheel.ts` convention).
736
+ *
737
+ * The query vocabulary is deliberately just the box: a headless, DOM-free
738
+ * stage knows exactly one environmental fact — the viewport it was told.
739
+ * Anything else (pointer coarseness, platform, app state) is either per-event
740
+ * (`PointerSample.pointerType`) or the app's own business via `update()`.
741
+ */
742
+ /** The reported viewport as a queryable box. A square box is 'portrait' (CSS). */
743
+ declare const boxOf: (vp: Size) => StageBox;
744
+ /** All bounds inclusive, all fields optional, conditions AND-ed (CSS ranges). */
745
+ declare const matchesQuery: (q: BoxQuery, box: StageBox) => boolean;
746
+ interface ResolvedResponsive {
747
+ /** base ⊕ every matching rule's patch, in source order (later wins per key). */
748
+ effective: StageSettings;
749
+ /** Names of the matching rules, in source order. */
750
+ active: string[];
751
+ }
752
+ declare const resolveResponsive: (base: StageSettings, rules: readonly ResponsiveRule[], box: StageBox) => ResolvedResponsive;
753
+ //#endregion
754
+ export { type Align, type Alignment, type BoxQuery, DEFAULT_RESPONSIVE, DEFAULT_SETTINGS, type DestinationReveal, type Direction, type FlowMode, type Gap, type GoToOptions, type GridColumns, type LayoutKind, type PageFrame, type ResponsiveRule, type RevealAnchor, type RevealAnchorValue, type RevealOptions, type RevealZoom, type Scheduler, type ScrollBehaviorKind, type ScrollHandlerOptions, type ScrollMetrics, type SizingMode, type SpreadMode, type StageAction, type StageBox, type StageCapability, type StageConfig, type StagePluginOptions, type StageScrollToOptions, type StageSettings, type StageState, StageToken, type StageViewState, type Viewpoint, type VisiblePage, ZoomMode, type ZoomModeValue, type ZoomSpec, boxOf, createScrollHandler, destinationToReveal, matchesQuery, resolveResponsive, settingsEqual, stagePlugin };
603
755
  //# sourceMappingURL=index.d.cts.map