@dimina-kit/electron-deck 0.1.0-dev.20260616102751 → 0.1.0-dev.20260618090552

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.
Files changed (36) hide show
  1. package/README.md +26 -24
  2. package/dist/client/index.js +1 -1
  3. package/dist/client/index.js.map +1 -1
  4. package/dist/client/layout-client.d.ts +1 -1
  5. package/dist/dock-react/dock-view.d.ts +14 -9
  6. package/dist/dock-react/dock-view.d.ts.map +1 -1
  7. package/dist/dock-react/drag-redock.d.ts +15 -0
  8. package/dist/dock-react/drag-redock.d.ts.map +1 -1
  9. package/dist/dock-react/index.d.ts +2 -2
  10. package/dist/dock-react/index.d.ts.map +1 -1
  11. package/dist/dock-react/index.js +197 -39
  12. package/dist/dock-react/index.js.map +1 -1
  13. package/dist/{electron-deck-DfFKeFEC.js → electron-deck-CW6gkGS-.js} +4 -4
  14. package/dist/electron-deck-CW6gkGS-.js.map +1 -0
  15. package/dist/host/index.js +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/internal/deck-app.d.ts +3 -3
  18. package/dist/layout/index.d.ts +2 -1
  19. package/dist/layout/index.d.ts.map +1 -1
  20. package/dist/layout/index.js +2 -2
  21. package/dist/layout/mutations.d.ts.map +1 -1
  22. package/dist/layout/sanitize.d.ts +27 -0
  23. package/dist/layout/sanitize.d.ts.map +1 -0
  24. package/dist/layout/serialize.d.ts.map +1 -1
  25. package/dist/layout/types.d.ts +49 -7
  26. package/dist/layout/types.d.ts.map +1 -1
  27. package/dist/{layout-CZtF0auJ.js → layout-WI8y1hxP.js} +55 -6
  28. package/dist/layout-WI8y1hxP.js.map +1 -0
  29. package/dist/main/compositor.d.ts +1 -1
  30. package/dist/main/index.d.ts +2 -2
  31. package/dist/main/view-handle.d.ts +8 -8
  32. package/dist/types.d.ts +2 -2
  33. package/dist/view-handle-CR-yWNfr.js.map +1 -1
  34. package/package.json +5 -5
  35. package/dist/electron-deck-DfFKeFEC.js.map +0 -1
  36. package/dist/layout-CZtF0auJ.js.map +0 -1
package/README.md CHANGED
@@ -1,41 +1,43 @@
1
1
  # @dimina-kit/electron-deck
2
2
 
3
- Dimina devtools host 集成地基。提供:连接层(per-webContents `Connection` + 资源归属)、host-shell 的跨进程 transport、`DeckConfig` 配置类型与 `defineEvent`,以及 webview 侧的 preload / client。
3
+ 领域中立的 Electron host-shell 框架。它把跨窗口编排、原生 `WebContentsView` 的 z 叠放与几何跟随、嵌套寿命管理抽成一组正交原语,让任意 Electron 多窗口应用用极少的 host 代码拼出「窗口 + 原生 view + 浮层 + popout」。同时提供 host-shell 的跨进程 transport(声明式 + typed 双向 IPC)、信任边界、确定性资源生命周期,以及 webview 侧的 preload / client。
4
4
 
5
- 下游 host(如 qdmp)写一份 `DeckConfig` 交给 `launch(config)`,framework 接管 Electron 装配、IPC、生命周期。
5
+ ## 入口
6
6
 
7
- ## 入口包归属
8
-
9
- `launch()` 入口函数住在 `@dimina-kit/devtools`(它要驱动 devtools 真运行时,而 devtools 已依赖本包——入口放本包会形成循环依赖)。本包提供配置类型、`defineEvent` 和 webview 侧工具:
10
-
11
- | 你要的 | 从哪导入 |
12
- |---|---|
13
- | `launch(config)` 入口函数 | `@dimina-kit/devtools` |
14
- | `defineEvent` / `DeckConfig` 等类型 | `@dimina-kit/electron-deck` |
15
- | preload bridge `exposeDeckBridge()` | `@dimina-kit/electron-deck/preload` |
16
- | renderer client `createDeckClient<HS, EV>()` | `@dimina-kit/electron-deck/client` |
17
- | layout-as-data 引擎(`SplitNode`/`TabGroupNode` 树、`movePanel`/`splitPanel`/`closePanel`/`setActive`/`setSizes` 等 mutation、`serializeLayout`/`parseLayout`/`validateTree`、`createLayoutModel` 单写者可观察模型、panel registry) | `@dimina-kit/electron-deck/layout` |
18
- | `<DockView>` React 渲染器(把 layout 树渲染成可拖拽 re-dock / tab / 分屏的 docking UI) | `@dimina-kit/electron-deck/dock-react` |
19
-
20
- ## 最小例子
7
+ 框架入口 `electronDeck(config, options?)` 与 `startElectronDeck(...)` 都从本包根导出。host 写一份 `DeckConfig`,framework 接管 Electron 装配、IPC、生命周期:
21
8
 
22
9
  ```ts
23
10
  // main.ts
24
- import { launch } from '@dimina-kit/devtools'
25
- import { defineEvent } from '@dimina-kit/electron-deck'
11
+ import { startElectronDeck, defineEvent } from '@dimina-kit/electron-deck'
26
12
 
27
13
  const authChanged = defineEvent<{ user: { id: string } | null }>('authChanged')
28
14
 
29
- // 不要顶层 `await launch(...)`:electron 在 main 模块求值完成前不触发
30
- // app.whenReady(),而 launch() 内部要 await whenReady,顶层 await 会死锁。
31
- launch({
15
+ startElectronDeck({
32
16
  app: { name: 'My DevTools' },
33
17
  hostServices: { getUser: async () => ({ user: null }) },
34
18
  events: [authChanged],
35
- }).catch((err) => { console.error('launch() failed:', err) })
19
+ })
36
20
  ```
37
21
 
22
+ `startElectronDeck()` 内部已对 `app.whenReady()` 做 gating,可在 main 模块顶层直接调用。`electronDeck()` 是其 await 版本——若直接用它,不要在 main 模块顶层 `await`(electron 在 main 模块求值完成前不触发 `whenReady`,顶层 await 会死锁),改用 `startElectronDeck()` 或 `electronDeck(...).catch(...)`。
23
+
24
+ `@dimina-kit/devtools` 的 `launch(config)` 是预注入 devtools backend 的薄封装——集成 devtools 时用它,见 [`../devtools/docs/workbench-model.md`](../devtools/docs/workbench-model.md)。
25
+
26
+ ## 导出
27
+
28
+ | 你要的 | 从哪导入 |
29
+ |---|---|
30
+ | `electronDeck` / `startElectronDeck` 入口、`defineEvent`、`DeckConfig` / `RuntimeBackend` 等类型 | `@dimina-kit/electron-deck` |
31
+ | 主进程装配工具 | `@dimina-kit/electron-deck/main` |
32
+ | host 侧 control-bus / capability / trust 原语 | `@dimina-kit/electron-deck/host` |
33
+ | preload bridge `exposeDeckBridge()` | `@dimina-kit/electron-deck/preload` |
34
+ | renderer client `createDeckClient<HS, EV>()` | `@dimina-kit/electron-deck/client`(浏览器构建:`/client/browser`) |
35
+ | layout-as-data 引擎(`SplitNode`/`TabGroupNode` 树、`movePanel`/`splitPanel`/`closePanel`/`insertPanel`/`setActive`/`setSizes`/`setConstraint` mutation、`serializeLayout`/`parseLayout`/`validateTree`、`createLayoutModel` 单写者可观察模型、panel registry,descriptor 可带 `PanelCapabilities`:`draggable`/`dropPolicy`/`hideTab`;split 子可带 `SizeConstraint`:`fixedPx` 锁死 / `minPx` 柔性下限) | `@dimina-kit/electron-deck/layout` |
36
+ | `<DockView>` React 渲染器(把 layout 树渲染成可拖拽 re-dock / tab / 分屏的 docking UI;按 descriptor 的 `PanelCapabilities` 约束拖拽——`draggable:false` 锁定为不可拖且不可作落点锚,`dropPolicy:'reorder-only'` 只允许组内重排)+ `computeReorderIndex` 纯几何 | `@dimina-kit/electron-deck/dock-react` |
37
+
38
38
  ## 文档
39
39
 
40
- - 连接层(Connection / 资源归属 / debugTap)参考:[`docs/foundation.md`](./docs/foundation.md)
41
- - host 集成(config 字段 / Runtime / preload / client / 必知约束)参考:[`../devtools/docs/workbench-model.md`](../devtools/docs/workbench-model.md)
40
+ - 架构总览(四个布局/多窗口原语、注入式 `RuntimeBackend`、信任边界、生命周期):[`docs/architecture.md`](./docs/architecture.md)
41
+ - 连接层(`Connection` / 资源归属 / debugTap):[`docs/foundation.md`](./docs/foundation.md)
42
+ - 横切契约:[`docs/contracts/`](./docs/contracts/)
43
+ - host 集成(以 devtools 为例):[`../devtools/docs/workbench-model.md`](../devtools/docs/workbench-model.md)
@@ -203,7 +203,7 @@ function createPlacementAnchor(target, opts) {
203
203
  //#endregion
204
204
  //#region src/client/layout-client.ts
205
205
  /**
206
- * Renderer half of the A5-2 slot-token handshake (§A5-2.1). Subscribes to main's
206
+ * Renderer half of the slot-token handshake (capability-and-lifecycle.md「原子下发握手协议」). Subscribes to main's
207
207
  * `slot-grant` pushes FIRST (so a grant replayed synchronously by `subscribe()`
208
208
  * cannot be missed), then on each grant anchors the granted DOM slot with this
209
209
  * session's hardening opts (followScroll / followGeometry / guardDisplayNone)
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../view-anchor/src/view-anchor.ts","../../src/client/layout-client.ts","../../src/client/index.ts"],"sourcesContent":["import type {\n Bounds,\n Placement,\n ViewAnchorOptions,\n ViewAnchorHandle,\n} from './types.js'\n\nconst ZERO: Bounds = { x: 0, y: 0, width: 0, height: 0 }\n\n// Round to integers (setBounds rejects fractionals). Width/height are clamped\n// to ≥0 (negative area is meaningless and `0` is the canonical \"hidden\"\n// signal). x/y are NOT clamped: a position is a position — an anchored overlay\n// scrolled past the top/left edge has a legitimately NEGATIVE origin, and\n// flooring it to 0 would pin the native view at the edge instead of letting it\n// track its element off-screen. (Each consumer's IPC schema enforces its own\n// origin policy — the simulator's allows negative; the DevTools placeholder\n// never goes negative, so its NonNegInt schema is unaffected.)\nconst clampRect = (r: {\n x: number\n y: number\n width: number\n height: number\n}): Bounds => ({\n x: Math.round(r.x),\n y: Math.round(r.y),\n width: Math.max(0, Math.round(r.width)),\n height: Math.max(0, Math.round(r.height)),\n})\n\n/**\n * Create an anchor binding ONE native view's bounds to `target`'s geometry.\n *\n * Imperative core — no React, no Electron. Behaviour:\n * - `present === true`: publish `target.getBoundingClientRect()` (x/y rounded,\n * width/height `Math.max(0, Math.round(...))`) immediately, then re-publish\n * SYNCHRONOUSLY on every `ResizeObserver` tick and window `resize`.\n * - `present === false`: publish `{0,0,0,0}` immediately; do not observe.\n * - `update(opts)`: re-apply synchronously.\n * - `dispose()`: stop observing, never publish again.\n *\n * Synchronous, NOT RAF-deferred: the native overlay is a cross-process\n * `WebContentsView` whose `setBounds` already lands ~1 compositor frame behind\n * the renderer's DOM paint (the two processes composite on different frames).\n * Deferring the measure+publish to a RAF stacked a SECOND frame on top — during\n * a height/splitter drag that read as the overlay visibly trailing the region\n * edge (worst when GROWING, where the not-yet-followed edge exposes background).\n * Publishing in the observer tick itself removes that self-inflicted frame and\n * leaves only the unavoidable cross-process frame (masked by matching the\n * placeholder/desk background colour). The anti-flood role the RAF used to play\n * — collapsing a burst of RO+resize ticks in one frame into one publish — is now\n * served by `lastPublished` dedup: a tick whose measured rect is byte-identical\n * to the last published one is dropped, so a continuous drag still emits at most\n * one publish per distinct rect.\n *\n * Teardown safety: there is no queued frame to outrun a state change — every\n * emit reads `disposed`/`present` synchronously, so a tick after\n * `update`/`dispose` can never write a stale rect over the live one.\n */\nexport function createViewAnchor(\n target: HTMLElement,\n opts: ViewAnchorOptions,\n): ViewAnchorHandle {\n let present = opts.present\n let publish = opts.publish\n let observer: ResizeObserver | null = null\n // The last rect handed to `publish`, for dedup-coalescing (see header). Reset\n // to `null` on every `apply()` so a state change (e.g. zoom, which rides in\n // the `publish` closure, not in `Bounds`) always forces one fresh publish\n // even when the geometry is unchanged.\n let lastPublished: Bounds | null = null\n let disposed = false\n\n const measure = (): Bounds => {\n const r = target.getBoundingClientRect()\n return clampRect({ x: r.left, y: r.top, width: r.width, height: r.height })\n }\n\n const sameRect = (a: Bounds, b: Bounds): boolean =>\n a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height\n\n // Measure + publish SYNCHRONOUSLY on the triggering tick — no RAF defer (see\n // header for why). Bail if torn down or detached, and dedup a rect\n // byte-identical to the last published one (collapses a same-frame RO+resize\n // burst, and a steady drag that re-fires the same final rect, into one).\n const emit = (): void => {\n if (disposed || !present) return\n const m = measure()\n if (lastPublished && sameRect(lastPublished, m)) return\n lastPublished = m\n publish(m)\n }\n\n const startObserving = (): void => {\n if (observer) return\n observer = new ResizeObserver(emit)\n observer.observe(target)\n window.addEventListener('resize', emit)\n }\n\n const stopObserving = (): void => {\n if (observer) {\n observer.disconnect()\n observer = null\n }\n window.removeEventListener('resize', emit)\n }\n\n // Apply the current (present, publish) synchronously. Reset `lastPublished`\n // first so the publish below is never dedup-skipped — a state change (zoom,\n // present flip, new publish target) must always re-emit even if the geometry\n // is byte-identical to the previous emit.\n const apply = (): void => {\n lastPublished = null\n if (present) {\n startObserving()\n lastPublished = measure()\n publish(lastPublished)\n } else {\n stopObserving()\n publish(ZERO)\n }\n }\n\n apply()\n\n return {\n update(next: ViewAnchorOptions): void {\n if (disposed) return\n publish = next.publish\n present = next.present\n apply()\n },\n dispose(): void {\n if (disposed) return\n disposed = true\n stopObserving()\n },\n }\n}\n\n// ── Explicit Placement API ────────────────────────────────────────────\n//\n// The modern surface that replaces the magic-`{0,0,0,0}` \"hidden\" value.\n// Visibility is an explicit discriminant, NEVER inferred from geometry — a\n// real 0×0-but-on-screen view is `{ visible:true, bounds:{...,width:0} }`\n// and a hidden one is `{ visible:false }` (no `bounds`). See `Placement`.\n\nexport interface PlacementAnchorOptions {\n /**\n * Caller's INTENT: should the native view be on-screen? `true` →\n * publish the measured rect as `{ visible:true, bounds }`; `false` →\n * publish `{ visible:false }`. Crucially, hiddenness comes from this\n * flag, not from a measured zero size — so a legitimately 0-sized but\n * visible target still publishes `visible:true`.\n */\n visible: boolean\n /** Receives each explicit Placement. Owns IPC → host. */\n publish: (placement: Placement) => void\n /**\n * Opt-in geometry detach. When true, a measured zero-area target (no\n * geometry box — display:none / unmounted / unstable first layout) publishes\n * `{ visible:false }` (detach-but-keep) instead of `{ visible:true,\n * bounds:0×0 }`, and an IntersectionObserver is attached so a display:none\n * transition (which ResizeObserver does not report) re-publishes. Default\n * false keeps the legitimate 0×0-visible semantics.\n */\n guardDisplayNone?: boolean\n /**\n * Opt-in capture-phase ancestor-scroll follow (§2.C). When true, the anchor\n * listens for `scroll` on `window` in the CAPTURE phase (scroll events don't\n * bubble, but reach `window` while capturing), so an ancestor scroll\n * container scrolling the target re-measures and re-publishes. With\n * `followGeometry` off, the scroll callback does a single synchronous\n * `emit()`; with it on, the scroll OPENS the RAF sentinel window so the\n * follow tracks every frame of a scroll burst. Default false.\n */\n followScroll?: boolean\n /**\n * Opt-in windowed RAF geometry sentinel (§2.D/§6). Catches ancestor\n * transform / reflow moves that no DOM event reports. The sentinel is\n * NON-resident: it is OPENED on demand (a scroll burst, a `[role=\"separator\"]`\n * splitter pointerdown, or an explicit `pulse()`), polls geometry once per\n * animation frame publishing IN-FRAME, and AUTO-CLOSES once the rect goes\n * steady (a few unchanged frames). While closed it schedules no frame, so the\n * static cost when idle is exactly zero. Default false.\n */\n followGeometry?: boolean\n}\n\nexport interface PlacementAnchorHandle {\n /** Apply new options; re-publishes immediately (mirrors `createViewAnchor`). */\n update(opts: PlacementAnchorOptions): void\n /** Stop observing; never publish again. */\n dispose(): void\n /**\n * Open the RAF sentinel window (animation follow); auto-closes after going\n * steady or after `durationMs`. No-op when `followGeometry` is false.\n */\n pulse(durationMs?: number): void\n}\n\n/**\n * Pure measure: read `target`'s rect and wrap it as an explicit visible\n * Placement. Always `{ visible:true }` — hiddenness is a caller decision\n * (see `createPlacementAnchor`), so this never returns `{ visible:false }`\n * and never infers visibility from a 0 size. A collapsed (0×0) but present\n * element therefore yields `{ visible:true, bounds:{...,width:0,height:0} }`,\n * distinct from any hidden Placement.\n */\nexport function measurePlacement(target: HTMLElement): Placement {\n const r = target.getBoundingClientRect()\n return {\n visible: true,\n bounds: clampRect({ x: r.left, y: r.top, width: r.width, height: r.height }),\n }\n}\n\nconst samePlacement = (a: Placement, b: Placement): boolean => {\n // Discriminant-aware dedup: a visibility flip is always a change, even when\n // the geometry would otherwise look identical.\n if (a.visible !== b.visible) return false\n if (a.visible && b.visible) {\n return (\n a.bounds.x === b.bounds.x &&\n a.bounds.y === b.bounds.y &&\n a.bounds.width === b.bounds.width &&\n a.bounds.height === b.bounds.height\n )\n }\n return true\n}\n\n/**\n * The explicit-Placement mirror of `createViewAnchor`. Same observer/dedup/\n * teardown machinery, but the sink receives a `Placement`:\n * - `visible === true` → publish `measurePlacement(target)` and re-publish\n * SYNCHRONOUSLY on every `ResizeObserver`/`resize` tick.\n * - `visible === false` → publish `{ visible:false }` (NOT a ZERO bounds);\n * do not observe.\n *\n * Dedup carries the discriminant (`samePlacement`), so a visibility flip is\n * never coalesced away.\n *\n * Opt-in `guardDisplayNone` (default false): when on, a measured zero-area\n * target (display:none / unmounted / unstable first layout) publishes\n * `{ visible:false }` instead of `{ visible:true, bounds:0×0 }`, and an\n * IntersectionObserver is attached so a display:none transition (which\n * ResizeObserver does not report) re-publishes.\n */\nexport function createPlacementAnchor(\n target: HTMLElement,\n opts: PlacementAnchorOptions,\n): PlacementAnchorHandle {\n let visible = opts.visible\n let publish = opts.publish\n const guardDisplayNone = opts.guardDisplayNone ?? false\n // Captured at creation; the follow options are never re-set via update().\n const followScroll = opts.followScroll ?? false\n const followGeometry = opts.followGeometry ?? false\n let observer: ResizeObserver | null = null\n let io: IntersectionObserver | null = null\n let lastPublished: Placement | null = null\n let disposed = false\n\n // ── Windowed RAF geometry sentinel state (§2.D/§6) ──────────────────\n // The sentinel is a windowed poll, opened on demand and auto-closing once\n // the geometry goes steady. It publishes IN-FRAME (no nested defer): each\n // frame measures, and either publishes a changed rect synchronously or\n // counts toward the steady-close threshold. While closed `rafId` is null\n // and no frame is scheduled — zero static cost when idle.\n let rafId: number | null = null\n let steadyFrames = 0\n const STEADY_CLOSE_FRAMES = 2\n // True while a [role=\"separator\"] splitter drag is in progress: set on the\n // capture-phase pointerdown that opened the window, cleared on pointerup\n // (§2.D). A held pointer means the drag may still resume after a static\n // pause, so a steady run while held must NOT close the sentinel — it only\n // closes once the pointer is released (松手后 2~3 帧内判静止→关窗). Without\n // this gate a press that pauses a couple of frames before the drag actually\n // moves would close mid-press and drop the entire subsequent drag.\n let pointerHeld = false\n // Absolute time (performance.now()) past which a `pulse(durationMs)` window\n // force-closes even if the geometry is still changing — the upper bound that\n // prevents a perpetually-animating target from keeping the sentinel resident.\n // null = no time bound (scroll/splitter opens rely on steady-close instead).\n let sentinelDeadline: number | null = null\n\n // Measure the target, applying the opt-in first-frame / display:none guard:\n // a zero-area box (no geometry to anchor) becomes a detach instead of a\n // 0×0-visible Placement. Default off → byte-for-byte the plain measure.\n const computePlacement = (): Placement => {\n const p = measurePlacement(target)\n if (\n guardDisplayNone &&\n p.visible &&\n (p.bounds.width === 0 || p.bounds.height === 0)\n ) {\n return { visible: false }\n }\n return p\n }\n\n const emit = (): void => {\n if (disposed || !visible) return\n const p = computePlacement()\n if (lastPublished && samePlacement(lastPublished, p)) return\n lastPublished = p\n publish(p)\n }\n\n // One sentinel frame: measure, publish-in-frame if changed, else count toward\n // the steady-close threshold. A changed frame re-arms; a steady frame re-arms\n // until STEADY_CLOSE_FRAMES consecutive unchanged frames, then closes (no\n // re-arm). Reads `disposed`/`visible` live so a frame outliving teardown is\n // inert.\n const sentinelFrame = (): void => {\n rafId = null\n if (disposed || !visible) {\n sentinelDeadline = null\n return\n }\n // §2.F upper bound: a pulse window past its deadline closes regardless of\n // motion, so a target that changes every frame can't keep the sentinel alive.\n if (sentinelDeadline !== null && performance.now() >= sentinelDeadline) {\n sentinelDeadline = null\n return // duration elapsed → close (no re-arm)\n }\n const p = computePlacement()\n if (lastPublished && samePlacement(lastPublished, p)) {\n steadyFrames++\n // Steady-close only fires once the pointer is RELEASED (§2.D): while a\n // splitter drag is held, a static pause is a hesitation, not the end of\n // the drag, so we keep polling (re-arm below) and let `steadyFrames`\n // accrue — it converges to a close within N frames after pointerup.\n if (steadyFrames >= STEADY_CLOSE_FRAMES && !pointerHeld) {\n sentinelDeadline = null\n return // steady (and released) → close\n }\n } else {\n lastPublished = p\n publish(p) // publish synchronously in THIS frame\n steadyFrames = 0\n }\n // `publish` may have synchronously disposed (or hidden) the anchor; re-read\n // live state so a re-entrant teardown leaves ZERO scheduled frames (B2).\n if (!disposed && visible) {\n rafId = requestAnimationFrame(sentinelFrame) // keep polling\n } else {\n sentinelDeadline = null\n }\n }\n\n const openSentinel = (): void => {\n if (!followGeometry || disposed) return\n steadyFrames = 0\n if (rafId === null) rafId = requestAnimationFrame(sentinelFrame)\n }\n\n const closeSentinel = (): void => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId)\n rafId = null\n }\n steadyFrames = 0\n sentinelDeadline = null\n pointerHeld = false\n }\n\n // §2.C — an ancestor scroll moved the target's screen rect. With the sentinel\n // on, open the window so the whole scroll burst is followed frame-by-frame;\n // without it, a single synchronous emit() follows the new rect (A1).\n const onScroll = (): void => {\n if (followGeometry) openSentinel()\n else emit()\n }\n\n // §2.D — a capture-phase pointerdown on a [role=\"separator\"] splitter handle\n // marks the start of a drag that moves the target via ancestor reflow (no RO\n // tick) → open the sentinel.\n const onPointerDown = (e: Event): void => {\n const t = e.target as Element | null\n if (t && t.closest && t.closest('[role=\"separator\"]')) {\n pointerHeld = true\n openSentinel()\n }\n }\n\n // §2.D — pointer released: the drag is over, so a steady run may now close the\n // sentinel. Re-open it (a no-op if already polling) so the steady-close\n // threshold is reached even if the geometry was already static at release.\n const onPointerUp = (): void => {\n if (!pointerHeld) return\n pointerHeld = false\n openSentinel()\n }\n\n const startObserving = (): void => {\n if (observer) return\n observer = new ResizeObserver(emit)\n observer.observe(target)\n window.addEventListener('resize', emit)\n // A display:none transition is invisible to ResizeObserver; an\n // IntersectionObserver re-fires `emit`, which re-measures via\n // `computePlacement` (now-zero box → detach, restored box → visible).\n if (guardDisplayNone && typeof IntersectionObserver !== 'undefined') {\n io = new IntersectionObserver(emit)\n io.observe(target)\n }\n if (followScroll) {\n window.addEventListener('scroll', onScroll, {\n capture: true,\n passive: true,\n })\n }\n if (followGeometry) {\n window.addEventListener('pointerdown', onPointerDown, { capture: true })\n window.addEventListener('pointerup', onPointerUp, { capture: true })\n }\n }\n\n const stopObserving = (): void => {\n if (observer) {\n observer.disconnect()\n observer = null\n }\n if (io) {\n io.disconnect()\n io = null\n }\n window.removeEventListener('resize', emit)\n window.removeEventListener('scroll', onScroll, {\n capture: true,\n } as EventListenerOptions)\n window.removeEventListener('pointerdown', onPointerDown, {\n capture: true,\n } as EventListenerOptions)\n window.removeEventListener('pointerup', onPointerUp, {\n capture: true,\n } as EventListenerOptions)\n closeSentinel()\n }\n\n const apply = (): void => {\n lastPublished = null\n if (visible) {\n startObserving()\n lastPublished = computePlacement()\n publish(lastPublished)\n } else {\n stopObserving()\n const hidden: Placement = { visible: false }\n lastPublished = hidden\n publish(hidden)\n }\n }\n\n apply()\n\n return {\n update(next: PlacementAnchorOptions): void {\n if (disposed) return\n publish = next.publish\n visible = next.visible\n apply()\n },\n dispose(): void {\n if (disposed) return\n disposed = true\n stopObserving()\n },\n pulse(durationMs?: number): void {\n // Imperative window open (§2.F): start the animation-follow window. It\n // closes on steady (N=2 unchanged frames) OR, when `durationMs` is given,\n // at that deadline — whichever comes first. The deadline is the upper bound\n // that guarantees a still-animating target cannot keep the sentinel\n // resident; without it, only steady-close applies.\n if (disposed || !followGeometry) return\n if (durationMs !== undefined && durationMs > 0) {\n const next = performance.now() + durationMs\n // Extend (never shorten) an existing window's deadline.\n sentinelDeadline = sentinelDeadline === null ? next : Math.max(sentinelDeadline, next)\n }\n openSentinel()\n },\n }\n}\n","import { createPlacementAnchor } from '@dimina-kit/view-anchor'\nimport type { Placement } from '@dimina-kit/view-anchor'\n\n/** One main→renderer slot grant: a native view (`viewId`) wants to follow the\n * DOM slot `slotId`; `slotToken` is the capability the renderer threads back on\n * every `place` so main can match a placement to the granted slot. */\nexport interface SlotGrant {\n\tviewId: string\n\tslotId: string\n\tslotToken: string\n}\n\n/** The renderer-side transport for the slot-token handshake. `onSlotGrant`\n * registers the grant listener (returns an unsubscribe); `subscribe` asks main\n * to (re)play buffered grants AFTER the listener is attached; `sendPlace`\n * forwards a measured placement carrying its slot's token. */\nexport interface LayoutBridge {\n\tonSlotGrant(cb: (grant: SlotGrant) => void): () => void\n\tsendPlace(msg: { slotToken: string; placement: Placement }): void\n\tsubscribe(): void\n}\n\nexport interface LayoutClientDeps {\n\tbridge: LayoutBridge\n\t/** Resolve a grant's `slotId` to its DOM element. Default:\n\t * `document.querySelector(slotId)`. Returns `null` when the slot is not\n\t * mounted (graceful no-op). */\n\tresolveSlot?(slotId: string): HTMLElement | null\n\t/** Anchor factory. Default: view-anchor's `createPlacementAnchor`. Injected\n\t * in tests to capture `(target, opts)` without real RO/IO/RAF. */\n\tcreateAnchor?: (\n\t\ttarget: HTMLElement,\n\t\topts: {\n\t\t\tvisible: boolean\n\t\t\tpublish: (p: Placement) => void\n\t\t\tfollowScroll?: boolean\n\t\t\tfollowGeometry?: boolean\n\t\t\tguardDisplayNone?: boolean\n\t\t},\n\t) => { dispose(): void }\n}\n\n/**\n * Renderer half of the A5-2 slot-token handshake (§A5-2.1). Subscribes to main's\n * `slot-grant` pushes FIRST (so a grant replayed synchronously by `subscribe()`\n * cannot be missed), then on each grant anchors the granted DOM slot with this\n * session's hardening opts (followScroll / followGeometry / guardDisplayNone)\n * and threads each measured `Placement` back to main as a `place` carrying that\n * grant's `slotToken`.\n */\nexport function createDeckLayoutClient(deps: LayoutClientDeps): {\n\tdispose(): void\n} {\n\tconst resolveSlot =\n\t\tdeps.resolveSlot ??\n\t\t((id: string): HTMLElement | null => document.querySelector(id))\n\tconst createAnchor = deps.createAnchor ?? createPlacementAnchor\n\n // One live anchor per `viewId`. Main intentionally re-delivers a grant on\n // per-wc replay, so we dedup: a same-token replay is a no-op (keep the live\n // anchor); a new token for an existing `viewId` replaces it (dispose old,\n // create new). The map holds only CURRENTLY-LIVE anchors — a replaced anchor\n // is disposed at replacement time and removed, so `dispose()` never\n // double-disposes it.\n const byViewId = new Map<string, { token: string; anchor: { dispose(): void } }>()\n let disposed = false\n\n // Register the grant listener BEFORE requesting replay (handshake §A5-2.1):\n // a grant the main side replays synchronously inside `subscribe()` must find\n // the listener already attached.\n const unsub = deps.bridge.onSlotGrant((grant) => {\n if (disposed) return\n const existing = byViewId.get(grant.viewId)\n // Same viewId+token re-delivered (per-wc replay) → pure no-op: keep the\n // live anchor, do not create a second, do not dispose the first.\n if (existing && existing.token === grant.slotToken) return\n // A new token for this viewId → REVOKE the stale anchor FIRST (codex P4\n // round-3): dispose + drop it BEFORE resolving the new slot, so a stale\n // anchor can never keep publishing a revoked token even when the new slot\n // isn't mounted yet. Deleting before `createAnchor` also means a throw in\n // `createAnchor` can't leave an already-disposed anchor in the map (which a\n // later `dispose()` would double-dispose).\n if (existing) {\n // try/finally (codex P4 round-4): the `delete` MUST run even if the old\n // anchor's dispose throws — otherwise the disposed-but-still-mapped anchor\n // keeps publishing the revoked token AND a later client.dispose() would\n // dispose it a second time.\n try {\n existing.anchor.dispose()\n }\n finally {\n byViewId.delete(grant.viewId)\n }\n }\n const el = resolveSlot(grant.slotId)\n if (!el) return // new slot not mounted → graceful no-op; old anchor already revoked\n const anchor = createAnchor(el, {\n visible: true,\n followScroll: true,\n followGeometry: true,\n guardDisplayNone: true,\n // Capture THIS grant's slotToken in the closure so each anchor publishes\n // to its own token (no cross-talk between slots).\n publish: (placement) => {\n deps.bridge.sendPlace({ slotToken: grant.slotToken, placement })\n },\n })\n byViewId.set(grant.viewId, { token: grant.slotToken, anchor })\n })\n\n // Request replay AFTER the listener is attached.\n deps.bridge.subscribe()\n\n return {\n dispose(): void {\n if (disposed) return\n disposed = true\n unsub()\n for (const { anchor } of byViewId.values()) anchor.dispose()\n byViewId.clear()\n },\n }\n}\n","import {\n\tDeckClientNotReadyError,\n\tDeckRemoteError,\n} from '../errors.js'\nimport {\n\tBRIDGE_PROTOCOL_VERSION,\n\tDEFAULT_BRIDGE_GLOBAL,\n} from '../shared/protocol.js'\nimport type { EventEnvelope, DeckBridge } from '../shared/protocol.js'\nimport type { Disposable, HostEvent, JsonValue } from '../types.js'\n\nexport { DeckClientNotReadyError, DeckRemoteError }\n\nexport { createDeckLayoutClient } from './layout-client.js'\nexport type {\n\tSlotGrant,\n\tLayoutBridge,\n\tLayoutClientDeps,\n} from './layout-client.js'\n\nexport interface CreateDeckClientOptions {\n\t/** 默认 `__electronDeckBridge`;必须与 host preload 对齐 */\n\treadonly globalName?: string\n}\n\n// HS / EV 使用 `any` 而非 `JsonValue[]` 约束:\n// (1) host 侧 HostServiceHandler 同样是 `(...args: any[]) => unknown`,两侧对称;\n// (2) JsonValue 索引签名挡掉常见 host 写法(`(p: { code: string }) => ...`),\n// 强迫 rest-only 签名时 `Parameters<HS[K]>` 推不出真实参数类型;\n// (3) Electron IPC 实际走 structured clone(非 JSON),原约束的\"前提\"本就错;\n// (4) 真要 runtime 校验,在 transport 边界用 `runtime.ipc.handle({ validator })`\n// 与 protocol envelope(`InvokeRequest.args: readonly JsonValue[]`)已经够。\nexport interface DeckClient<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tHS extends Record<keyof HS, (...args: any[]) => unknown>,\n\tEV extends readonly HostEvent<JsonValue>[],\n> {\n\tready(): Promise<void>\n\tinvoke<K extends keyof HS & string>(\n\t\tname: K,\n\t\t...args: Parameters<HS[K]>\n\t): Promise<Awaited<ReturnType<HS[K]>>>\n\ton<E extends EV[number]>(\n\t\tevent: E,\n\t\tlistener: (payload: E extends HostEvent<infer P> ? P : never) => void,\n\t): Disposable\n}\n\nexport function createDeckClient<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tHS extends Record<keyof HS, (...args: any[]) => unknown>,\n\tEV extends readonly HostEvent<JsonValue>[],\n>(options?: CreateDeckClientOptions): DeckClient<HS, EV> {\n\tconst globalName = options?.globalName ?? DEFAULT_BRIDGE_GLOBAL\n\n\tfunction getBridge(): DeckBridge {\n\t\tconst bridge = readBridgeFromGlobal(globalName)\n\t\tif (bridge === undefined) {\n\t\t\tthrow new DeckClientNotReadyError(\n\t\t\t\t`Deck framework bridge is missing on window[\"${globalName}\"] — did the host preload call exposeDeckBridge()?`,\n\t\t\t)\n\t\t}\n\t\treturn bridge\n\t}\n\n\treturn {\n\t\tasync ready(): Promise<void> {\n\t\t\tconst bridge = getBridge()\n\t\t\tconst remoteMajor = parseMajor(bridge.version)\n\t\t\tconst localMajor = parseMajor(BRIDGE_PROTOCOL_VERSION)\n\t\t\tif (remoteMajor !== localMajor) {\n\t\t\t\tthrow new DeckClientNotReadyError(\n\t\t\t\t\t`Deck bridge protocol version mismatch: bridge=${String(bridge.version)}, client expected major ${localMajor}.x.x (${BRIDGE_PROTOCOL_VERSION})`,\n\t\t\t\t)\n\t\t\t}\n\t\t},\n\n\t\tasync invoke<K extends keyof HS & string>(\n\t\t\tname: K,\n\t\t\t...args: Parameters<HS[K]>\n\t\t): Promise<Awaited<ReturnType<HS[K]>>> {\n\t\t\tconst bridge = getBridge()\n\t\t\tconst response = await bridge.invoke({\n\t\t\t\tkind: 'host',\n\t\t\t\tname,\n\t\t\t\targs: args as readonly JsonValue[],\n\t\t\t})\n\t\t\tif (response.ok) {\n\t\t\t\treturn response.result as Awaited<ReturnType<HS[K]>>\n\t\t\t}\n\t\t\tconst { remoteName, message, code } = response.error\n\t\t\tthrow new DeckRemoteError(remoteName, message, code)\n\t\t},\n\n\t\ton<E extends EV[number]>(\n\t\t\tevent: E,\n\t\t\tlistener: (payload: E extends HostEvent<infer P> ? P : never) => void,\n\t\t): Disposable {\n\t\t\tconst bridge = getBridge()\n\t\t\tconst wrapped = (env: EventEnvelope): void => {\n\t\t\t\tif (env.name === event.name) {\n\t\t\t\t\tlistener(env.payload as E extends HostEvent<infer P> ? P : never)\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst unsubscribe = bridge.onEvent(wrapped)\n\t\t\tlet disposed = false\n\t\t\treturn {\n\t\t\t\tdispose: () => {\n\t\t\t\t\tif (disposed) return\n\t\t\t\t\tdisposed = true\n\t\t\t\t\tunsubscribe()\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t}\n}\n\nexport function readBridgeFromGlobal(\n\tglobalName: string = DEFAULT_BRIDGE_GLOBAL,\n): DeckBridge | undefined {\n\tconst g = globalThis as unknown as Record<string, unknown>\n\tconst bridge = g[globalName]\n\tif (bridge === undefined || bridge === null) return undefined\n\treturn bridge as DeckBridge\n}\n\nfunction parseMajor(version: unknown): number {\n\tif (typeof version !== 'string') return Number.NaN\n\tconst head = version.split('.')[0] ?? ''\n\tconst n = Number.parseInt(head, 10)\n\treturn Number.isNaN(n) ? Number.NaN : n\n}\n\nexport { BRIDGE_PROTOCOL_VERSION, DEFAULT_BRIDGE_GLOBAL }\n"],"mappings":";;;A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EACN,MAAM,QAAuB;GAC5B,MAAM,SAAS,UAAU;GACzB,MAAM,cAAc,WAAW,OAAO,OAAO;GAC7C,MAAM,aAAa,WAAW,uBAAuB;GACrD,IAAI,gBAAgB,YACnB,MAAM,IAAI,wBACT,iDAAiD,OAAO,OAAO,OAAO,EAAE,0BAA0B,WAAW,QAAQ,wBAAwB,EAC9I;EAEF;EAEA,MAAM,OACL,MACA,GAAG,MACmC;GAEtC,MAAM,WAAW,MADF,UACQ,EAAO,OAAO;IACpC,MAAM;IACN;IACM;GACP,CAAC;GACD,IAAI,SAAS,IACZ,OAAO,SAAS;GAEjB,MAAM,EAAE,YAAY,SAAS,SAAS,SAAS;GAC/C,MAAM,IAAI,gBAAgB,YAAY,SAAS,IAAI;EACpD;EAEA,GACC,OACA,UACa;GACb,MAAM,SAAS,UAAU;GACzB,MAAM,WAAW,QAA6B;IAC7C,IAAI,IAAI,SAAS,MAAM,MACtB,SAAS,IAAI,OAAmD;GAElE;GACA,MAAM,cAAc,OAAO,QAAQ,OAAO;GAC1C,IAAI,WAAW;GACf,OAAO,EACN,eAAe;IACd,IAAI,UAAU;IACd,WAAW;IACX,YAAY;GACb,EACD;EACD;CACD;AACD;AAEA,SAAgB,qBACf,aAAqB,uBACI;CAEzB,MAAM,SAAS,WAAE;CACjB,IAAI,WAAW,KAAA,KAAa,WAAW,MAAM,OAAO,KAAA;CACpD,OAAO;AACR;AAEA,SAAS,WAAW,SAA0B;CAC7C,IAAI,OAAO,YAAY,UAAU,OAAO;CACxC,MAAM,OAAO,QAAQ,MAAM,GAAG,EAAE,MAAM;CACtC,MAAM,IAAI,OAAO,SAAS,MAAM,EAAE;CAClC,OAAO,OAAO,MAAM,CAAC,IAAI,MAAa;AACvC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../view-anchor/src/view-anchor.ts","../../src/client/layout-client.ts","../../src/client/index.ts"],"sourcesContent":["import type {\n Bounds,\n Placement,\n ViewAnchorOptions,\n ViewAnchorHandle,\n} from './types.js'\n\nconst ZERO: Bounds = { x: 0, y: 0, width: 0, height: 0 }\n\n// Round to integers (setBounds rejects fractionals). Width/height are clamped\n// to ≥0 (negative area is meaningless and `0` is the canonical \"hidden\"\n// signal). x/y are NOT clamped: a position is a position — an anchored overlay\n// scrolled past the top/left edge has a legitimately NEGATIVE origin, and\n// flooring it to 0 would pin the native view at the edge instead of letting it\n// track its element off-screen. (Each consumer's IPC schema enforces its own\n// origin policy — the simulator's allows negative; the DevTools placeholder\n// never goes negative, so its NonNegInt schema is unaffected.)\nconst clampRect = (r: {\n x: number\n y: number\n width: number\n height: number\n}): Bounds => ({\n x: Math.round(r.x),\n y: Math.round(r.y),\n width: Math.max(0, Math.round(r.width)),\n height: Math.max(0, Math.round(r.height)),\n})\n\n/**\n * Create an anchor binding ONE native view's bounds to `target`'s geometry.\n *\n * Imperative core — no React, no Electron. Behaviour:\n * - `present === true`: publish `target.getBoundingClientRect()` (x/y rounded,\n * width/height `Math.max(0, Math.round(...))`) immediately, then re-publish\n * SYNCHRONOUSLY on every `ResizeObserver` tick and window `resize`.\n * - `present === false`: publish `{0,0,0,0}` immediately; do not observe.\n * - `update(opts)`: re-apply synchronously.\n * - `dispose()`: stop observing, never publish again.\n *\n * Synchronous, NOT RAF-deferred: the native overlay is a cross-process\n * `WebContentsView` whose `setBounds` already lands ~1 compositor frame behind\n * the renderer's DOM paint (the two processes composite on different frames).\n * Deferring the measure+publish to a RAF stacked a SECOND frame on top — during\n * a height/splitter drag that read as the overlay visibly trailing the region\n * edge (worst when GROWING, where the not-yet-followed edge exposes background).\n * Publishing in the observer tick itself removes that self-inflicted frame and\n * leaves only the unavoidable cross-process frame (masked by matching the\n * placeholder/desk background colour). The anti-flood role the RAF used to play\n * — collapsing a burst of RO+resize ticks in one frame into one publish — is now\n * served by `lastPublished` dedup: a tick whose measured rect is byte-identical\n * to the last published one is dropped, so a continuous drag still emits at most\n * one publish per distinct rect.\n *\n * Teardown safety: there is no queued frame to outrun a state change — every\n * emit reads `disposed`/`present` synchronously, so a tick after\n * `update`/`dispose` can never write a stale rect over the live one.\n */\nexport function createViewAnchor(\n target: HTMLElement,\n opts: ViewAnchorOptions,\n): ViewAnchorHandle {\n let present = opts.present\n let publish = opts.publish\n let observer: ResizeObserver | null = null\n // The last rect handed to `publish`, for dedup-coalescing (see header). Reset\n // to `null` on every `apply()` so a state change (e.g. zoom, which rides in\n // the `publish` closure, not in `Bounds`) always forces one fresh publish\n // even when the geometry is unchanged.\n let lastPublished: Bounds | null = null\n let disposed = false\n\n const measure = (): Bounds => {\n const r = target.getBoundingClientRect()\n return clampRect({ x: r.left, y: r.top, width: r.width, height: r.height })\n }\n\n const sameRect = (a: Bounds, b: Bounds): boolean =>\n a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height\n\n // Measure + publish SYNCHRONOUSLY on the triggering tick — no RAF defer (see\n // header for why). Bail if torn down or detached, and dedup a rect\n // byte-identical to the last published one (collapses a same-frame RO+resize\n // burst, and a steady drag that re-fires the same final rect, into one).\n const emit = (): void => {\n if (disposed || !present) return\n const m = measure()\n if (lastPublished && sameRect(lastPublished, m)) return\n lastPublished = m\n publish(m)\n }\n\n const startObserving = (): void => {\n if (observer) return\n observer = new ResizeObserver(emit)\n observer.observe(target)\n window.addEventListener('resize', emit)\n }\n\n const stopObserving = (): void => {\n if (observer) {\n observer.disconnect()\n observer = null\n }\n window.removeEventListener('resize', emit)\n }\n\n // Apply the current (present, publish) synchronously. Reset `lastPublished`\n // first so the publish below is never dedup-skipped — a state change (zoom,\n // present flip, new publish target) must always re-emit even if the geometry\n // is byte-identical to the previous emit.\n const apply = (): void => {\n lastPublished = null\n if (present) {\n startObserving()\n lastPublished = measure()\n publish(lastPublished)\n } else {\n stopObserving()\n publish(ZERO)\n }\n }\n\n apply()\n\n return {\n update(next: ViewAnchorOptions): void {\n if (disposed) return\n publish = next.publish\n present = next.present\n apply()\n },\n dispose(): void {\n if (disposed) return\n disposed = true\n stopObserving()\n },\n }\n}\n\n// ── Explicit Placement API ────────────────────────────────────────────\n//\n// The modern surface that replaces the magic-`{0,0,0,0}` \"hidden\" value.\n// Visibility is an explicit discriminant, NEVER inferred from geometry — a\n// real 0×0-but-on-screen view is `{ visible:true, bounds:{...,width:0} }`\n// and a hidden one is `{ visible:false }` (no `bounds`). See `Placement`.\n\nexport interface PlacementAnchorOptions {\n /**\n * Caller's INTENT: should the native view be on-screen? `true` →\n * publish the measured rect as `{ visible:true, bounds }`; `false` →\n * publish `{ visible:false }`. Crucially, hiddenness comes from this\n * flag, not from a measured zero size — so a legitimately 0-sized but\n * visible target still publishes `visible:true`.\n */\n visible: boolean\n /** Receives each explicit Placement. Owns IPC → host. */\n publish: (placement: Placement) => void\n /**\n * Opt-in geometry detach. When true, a measured zero-area target (no\n * geometry box — display:none / unmounted / unstable first layout) publishes\n * `{ visible:false }` (detach-but-keep) instead of `{ visible:true,\n * bounds:0×0 }`, and an IntersectionObserver is attached so a display:none\n * transition (which ResizeObserver does not report) re-publishes. Default\n * false keeps the legitimate 0×0-visible semantics.\n */\n guardDisplayNone?: boolean\n /**\n * Opt-in capture-phase ancestor-scroll follow (§2.C). When true, the anchor\n * listens for `scroll` on `window` in the CAPTURE phase (scroll events don't\n * bubble, but reach `window` while capturing), so an ancestor scroll\n * container scrolling the target re-measures and re-publishes. With\n * `followGeometry` off, the scroll callback does a single synchronous\n * `emit()`; with it on, the scroll OPENS the RAF sentinel window so the\n * follow tracks every frame of a scroll burst. Default false.\n */\n followScroll?: boolean\n /**\n * Opt-in windowed RAF geometry sentinel (§2.D/§6). Catches ancestor\n * transform / reflow moves that no DOM event reports. The sentinel is\n * NON-resident: it is OPENED on demand (a scroll burst, a `[role=\"separator\"]`\n * splitter pointerdown, or an explicit `pulse()`), polls geometry once per\n * animation frame publishing IN-FRAME, and AUTO-CLOSES once the rect goes\n * steady (a few unchanged frames). While closed it schedules no frame, so the\n * static cost when idle is exactly zero. Default false.\n */\n followGeometry?: boolean\n}\n\nexport interface PlacementAnchorHandle {\n /** Apply new options; re-publishes immediately (mirrors `createViewAnchor`). */\n update(opts: PlacementAnchorOptions): void\n /** Stop observing; never publish again. */\n dispose(): void\n /**\n * Open the RAF sentinel window (animation follow); auto-closes after going\n * steady or after `durationMs`. No-op when `followGeometry` is false.\n */\n pulse(durationMs?: number): void\n}\n\n/**\n * Pure measure: read `target`'s rect and wrap it as an explicit visible\n * Placement. Always `{ visible:true }` — hiddenness is a caller decision\n * (see `createPlacementAnchor`), so this never returns `{ visible:false }`\n * and never infers visibility from a 0 size. A collapsed (0×0) but present\n * element therefore yields `{ visible:true, bounds:{...,width:0,height:0} }`,\n * distinct from any hidden Placement.\n */\nexport function measurePlacement(target: HTMLElement): Placement {\n const r = target.getBoundingClientRect()\n return {\n visible: true,\n bounds: clampRect({ x: r.left, y: r.top, width: r.width, height: r.height }),\n }\n}\n\nconst samePlacement = (a: Placement, b: Placement): boolean => {\n // Discriminant-aware dedup: a visibility flip is always a change, even when\n // the geometry would otherwise look identical.\n if (a.visible !== b.visible) return false\n if (a.visible && b.visible) {\n return (\n a.bounds.x === b.bounds.x &&\n a.bounds.y === b.bounds.y &&\n a.bounds.width === b.bounds.width &&\n a.bounds.height === b.bounds.height\n )\n }\n return true\n}\n\n/**\n * The explicit-Placement mirror of `createViewAnchor`. Same observer/dedup/\n * teardown machinery, but the sink receives a `Placement`:\n * - `visible === true` → publish `measurePlacement(target)` and re-publish\n * SYNCHRONOUSLY on every `ResizeObserver`/`resize` tick.\n * - `visible === false` → publish `{ visible:false }` (NOT a ZERO bounds);\n * do not observe.\n *\n * Dedup carries the discriminant (`samePlacement`), so a visibility flip is\n * never coalesced away.\n *\n * Opt-in `guardDisplayNone` (default false): when on, a measured zero-area\n * target (display:none / unmounted / unstable first layout) publishes\n * `{ visible:false }` instead of `{ visible:true, bounds:0×0 }`, and an\n * IntersectionObserver is attached so a display:none transition (which\n * ResizeObserver does not report) re-publishes.\n */\nexport function createPlacementAnchor(\n target: HTMLElement,\n opts: PlacementAnchorOptions,\n): PlacementAnchorHandle {\n let visible = opts.visible\n let publish = opts.publish\n const guardDisplayNone = opts.guardDisplayNone ?? false\n // Captured at creation; the follow options are never re-set via update().\n const followScroll = opts.followScroll ?? false\n const followGeometry = opts.followGeometry ?? false\n let observer: ResizeObserver | null = null\n let io: IntersectionObserver | null = null\n let lastPublished: Placement | null = null\n let disposed = false\n\n // ── Windowed RAF geometry sentinel state (§2.D/§6) ──────────────────\n // The sentinel is a windowed poll, opened on demand and auto-closing once\n // the geometry goes steady. It publishes IN-FRAME (no nested defer): each\n // frame measures, and either publishes a changed rect synchronously or\n // counts toward the steady-close threshold. While closed `rafId` is null\n // and no frame is scheduled — zero static cost when idle.\n let rafId: number | null = null\n let steadyFrames = 0\n const STEADY_CLOSE_FRAMES = 2\n // True while a [role=\"separator\"] splitter drag is in progress: set on the\n // capture-phase pointerdown that opened the window, cleared on pointerup\n // (§2.D). A held pointer means the drag may still resume after a static\n // pause, so a steady run while held must NOT close the sentinel — it only\n // closes once the pointer is released (松手后 2~3 帧内判静止→关窗). Without\n // this gate a press that pauses a couple of frames before the drag actually\n // moves would close mid-press and drop the entire subsequent drag.\n let pointerHeld = false\n // Absolute time (performance.now()) past which a `pulse(durationMs)` window\n // force-closes even if the geometry is still changing — the upper bound that\n // prevents a perpetually-animating target from keeping the sentinel resident.\n // null = no time bound (scroll/splitter opens rely on steady-close instead).\n let sentinelDeadline: number | null = null\n\n // Measure the target, applying the opt-in first-frame / display:none guard:\n // a zero-area box (no geometry to anchor) becomes a detach instead of a\n // 0×0-visible Placement. Default off → byte-for-byte the plain measure.\n const computePlacement = (): Placement => {\n const p = measurePlacement(target)\n if (\n guardDisplayNone &&\n p.visible &&\n (p.bounds.width === 0 || p.bounds.height === 0)\n ) {\n return { visible: false }\n }\n return p\n }\n\n const emit = (): void => {\n if (disposed || !visible) return\n const p = computePlacement()\n if (lastPublished && samePlacement(lastPublished, p)) return\n lastPublished = p\n publish(p)\n }\n\n // One sentinel frame: measure, publish-in-frame if changed, else count toward\n // the steady-close threshold. A changed frame re-arms; a steady frame re-arms\n // until STEADY_CLOSE_FRAMES consecutive unchanged frames, then closes (no\n // re-arm). Reads `disposed`/`visible` live so a frame outliving teardown is\n // inert.\n const sentinelFrame = (): void => {\n rafId = null\n if (disposed || !visible) {\n sentinelDeadline = null\n return\n }\n // §2.F upper bound: a pulse window past its deadline closes regardless of\n // motion, so a target that changes every frame can't keep the sentinel alive.\n if (sentinelDeadline !== null && performance.now() >= sentinelDeadline) {\n sentinelDeadline = null\n return // duration elapsed → close (no re-arm)\n }\n const p = computePlacement()\n if (lastPublished && samePlacement(lastPublished, p)) {\n steadyFrames++\n // Steady-close only fires once the pointer is RELEASED (§2.D): while a\n // splitter drag is held, a static pause is a hesitation, not the end of\n // the drag, so we keep polling (re-arm below) and let `steadyFrames`\n // accrue — it converges to a close within N frames after pointerup.\n if (steadyFrames >= STEADY_CLOSE_FRAMES && !pointerHeld) {\n sentinelDeadline = null\n return // steady (and released) → close\n }\n } else {\n lastPublished = p\n publish(p) // publish synchronously in THIS frame\n steadyFrames = 0\n }\n // `publish` may have synchronously disposed (or hidden) the anchor; re-read\n // live state so a re-entrant teardown leaves ZERO scheduled frames (B2).\n if (!disposed && visible) {\n rafId = requestAnimationFrame(sentinelFrame) // keep polling\n } else {\n sentinelDeadline = null\n }\n }\n\n const openSentinel = (): void => {\n if (!followGeometry || disposed) return\n steadyFrames = 0\n if (rafId === null) rafId = requestAnimationFrame(sentinelFrame)\n }\n\n const closeSentinel = (): void => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId)\n rafId = null\n }\n steadyFrames = 0\n sentinelDeadline = null\n pointerHeld = false\n }\n\n // §2.C — an ancestor scroll moved the target's screen rect. With the sentinel\n // on, open the window so the whole scroll burst is followed frame-by-frame;\n // without it, a single synchronous emit() follows the new rect (A1).\n const onScroll = (): void => {\n if (followGeometry) openSentinel()\n else emit()\n }\n\n // §2.D — a capture-phase pointerdown on a [role=\"separator\"] splitter handle\n // marks the start of a drag that moves the target via ancestor reflow (no RO\n // tick) → open the sentinel.\n const onPointerDown = (e: Event): void => {\n const t = e.target as Element | null\n if (t && t.closest && t.closest('[role=\"separator\"]')) {\n pointerHeld = true\n openSentinel()\n }\n }\n\n // §2.D — pointer released: the drag is over, so a steady run may now close the\n // sentinel. Re-open it (a no-op if already polling) so the steady-close\n // threshold is reached even if the geometry was already static at release.\n const onPointerUp = (): void => {\n if (!pointerHeld) return\n pointerHeld = false\n openSentinel()\n }\n\n const startObserving = (): void => {\n if (observer) return\n observer = new ResizeObserver(emit)\n observer.observe(target)\n window.addEventListener('resize', emit)\n // A display:none transition is invisible to ResizeObserver; an\n // IntersectionObserver re-fires `emit`, which re-measures via\n // `computePlacement` (now-zero box → detach, restored box → visible).\n if (guardDisplayNone && typeof IntersectionObserver !== 'undefined') {\n io = new IntersectionObserver(emit)\n io.observe(target)\n }\n if (followScroll) {\n window.addEventListener('scroll', onScroll, {\n capture: true,\n passive: true,\n })\n }\n if (followGeometry) {\n window.addEventListener('pointerdown', onPointerDown, { capture: true })\n window.addEventListener('pointerup', onPointerUp, { capture: true })\n }\n }\n\n const stopObserving = (): void => {\n if (observer) {\n observer.disconnect()\n observer = null\n }\n if (io) {\n io.disconnect()\n io = null\n }\n window.removeEventListener('resize', emit)\n window.removeEventListener('scroll', onScroll, {\n capture: true,\n } as EventListenerOptions)\n window.removeEventListener('pointerdown', onPointerDown, {\n capture: true,\n } as EventListenerOptions)\n window.removeEventListener('pointerup', onPointerUp, {\n capture: true,\n } as EventListenerOptions)\n closeSentinel()\n }\n\n const apply = (): void => {\n lastPublished = null\n if (visible) {\n startObserving()\n lastPublished = computePlacement()\n publish(lastPublished)\n } else {\n stopObserving()\n const hidden: Placement = { visible: false }\n lastPublished = hidden\n publish(hidden)\n }\n }\n\n apply()\n\n return {\n update(next: PlacementAnchorOptions): void {\n if (disposed) return\n publish = next.publish\n visible = next.visible\n apply()\n },\n dispose(): void {\n if (disposed) return\n disposed = true\n stopObserving()\n },\n pulse(durationMs?: number): void {\n // Imperative window open (§2.F): start the animation-follow window. It\n // closes on steady (N=2 unchanged frames) OR, when `durationMs` is given,\n // at that deadline — whichever comes first. The deadline is the upper bound\n // that guarantees a still-animating target cannot keep the sentinel\n // resident; without it, only steady-close applies.\n if (disposed || !followGeometry) return\n if (durationMs !== undefined && durationMs > 0) {\n const next = performance.now() + durationMs\n // Extend (never shorten) an existing window's deadline.\n sentinelDeadline = sentinelDeadline === null ? next : Math.max(sentinelDeadline, next)\n }\n openSentinel()\n },\n }\n}\n","import { createPlacementAnchor } from '@dimina-kit/view-anchor'\nimport type { Placement } from '@dimina-kit/view-anchor'\n\n/** One main→renderer slot grant: a native view (`viewId`) wants to follow the\n * DOM slot `slotId`; `slotToken` is the capability the renderer threads back on\n * every `place` so main can match a placement to the granted slot. */\nexport interface SlotGrant {\n\tviewId: string\n\tslotId: string\n\tslotToken: string\n}\n\n/** The renderer-side transport for the slot-token handshake. `onSlotGrant`\n * registers the grant listener (returns an unsubscribe); `subscribe` asks main\n * to (re)play buffered grants AFTER the listener is attached; `sendPlace`\n * forwards a measured placement carrying its slot's token. */\nexport interface LayoutBridge {\n\tonSlotGrant(cb: (grant: SlotGrant) => void): () => void\n\tsendPlace(msg: { slotToken: string; placement: Placement }): void\n\tsubscribe(): void\n}\n\nexport interface LayoutClientDeps {\n\tbridge: LayoutBridge\n\t/** Resolve a grant's `slotId` to its DOM element. Default:\n\t * `document.querySelector(slotId)`. Returns `null` when the slot is not\n\t * mounted (graceful no-op). */\n\tresolveSlot?(slotId: string): HTMLElement | null\n\t/** Anchor factory. Default: view-anchor's `createPlacementAnchor`. Injected\n\t * in tests to capture `(target, opts)` without real RO/IO/RAF. */\n\tcreateAnchor?: (\n\t\ttarget: HTMLElement,\n\t\topts: {\n\t\t\tvisible: boolean\n\t\t\tpublish: (p: Placement) => void\n\t\t\tfollowScroll?: boolean\n\t\t\tfollowGeometry?: boolean\n\t\t\tguardDisplayNone?: boolean\n\t\t},\n\t) => { dispose(): void }\n}\n\n/**\n * Renderer half of the slot-token handshake (capability-and-lifecycle.md「原子下发握手协议」). Subscribes to main's\n * `slot-grant` pushes FIRST (so a grant replayed synchronously by `subscribe()`\n * cannot be missed), then on each grant anchors the granted DOM slot with this\n * session's hardening opts (followScroll / followGeometry / guardDisplayNone)\n * and threads each measured `Placement` back to main as a `place` carrying that\n * grant's `slotToken`.\n */\nexport function createDeckLayoutClient(deps: LayoutClientDeps): {\n\tdispose(): void\n} {\n\tconst resolveSlot =\n\t\tdeps.resolveSlot ??\n\t\t((id: string): HTMLElement | null => document.querySelector(id))\n\tconst createAnchor = deps.createAnchor ?? createPlacementAnchor\n\n // One live anchor per `viewId`. Main intentionally re-delivers a grant on\n // per-wc replay, so we dedup: a same-token replay is a no-op (keep the live\n // anchor); a new token for an existing `viewId` replaces it (dispose old,\n // create new). The map holds only CURRENTLY-LIVE anchors — a replaced anchor\n // is disposed at replacement time and removed, so `dispose()` never\n // double-disposes it.\n const byViewId = new Map<string, { token: string; anchor: { dispose(): void } }>()\n let disposed = false\n\n // Register the grant listener BEFORE requesting replay (handshake):\n // a grant the main side replays synchronously inside `subscribe()` must find\n // the listener already attached.\n const unsub = deps.bridge.onSlotGrant((grant) => {\n if (disposed) return\n const existing = byViewId.get(grant.viewId)\n // Same viewId+token re-delivered (per-wc replay) → pure no-op: keep the\n // live anchor, do not create a second, do not dispose the first.\n if (existing && existing.token === grant.slotToken) return\n // A new token for this viewId → REVOKE the stale anchor FIRST (codex P4\n // round-3): dispose + drop it BEFORE resolving the new slot, so a stale\n // anchor can never keep publishing a revoked token even when the new slot\n // isn't mounted yet. Deleting before `createAnchor` also means a throw in\n // `createAnchor` can't leave an already-disposed anchor in the map (which a\n // later `dispose()` would double-dispose).\n if (existing) {\n // try/finally (codex P4 round-4): the `delete` MUST run even if the old\n // anchor's dispose throws — otherwise the disposed-but-still-mapped anchor\n // keeps publishing the revoked token AND a later client.dispose() would\n // dispose it a second time.\n try {\n existing.anchor.dispose()\n }\n finally {\n byViewId.delete(grant.viewId)\n }\n }\n const el = resolveSlot(grant.slotId)\n if (!el) return // new slot not mounted → graceful no-op; old anchor already revoked\n const anchor = createAnchor(el, {\n visible: true,\n followScroll: true,\n followGeometry: true,\n guardDisplayNone: true,\n // Capture THIS grant's slotToken in the closure so each anchor publishes\n // to its own token (no cross-talk between slots).\n publish: (placement) => {\n deps.bridge.sendPlace({ slotToken: grant.slotToken, placement })\n },\n })\n byViewId.set(grant.viewId, { token: grant.slotToken, anchor })\n })\n\n // Request replay AFTER the listener is attached.\n deps.bridge.subscribe()\n\n return {\n dispose(): void {\n if (disposed) return\n disposed = true\n unsub()\n for (const { anchor } of byViewId.values()) anchor.dispose()\n byViewId.clear()\n },\n }\n}\n","import {\n\tDeckClientNotReadyError,\n\tDeckRemoteError,\n} from '../errors.js'\nimport {\n\tBRIDGE_PROTOCOL_VERSION,\n\tDEFAULT_BRIDGE_GLOBAL,\n} from '../shared/protocol.js'\nimport type { EventEnvelope, DeckBridge } from '../shared/protocol.js'\nimport type { Disposable, HostEvent, JsonValue } from '../types.js'\n\nexport { DeckClientNotReadyError, DeckRemoteError }\n\nexport { createDeckLayoutClient } from './layout-client.js'\nexport type {\n\tSlotGrant,\n\tLayoutBridge,\n\tLayoutClientDeps,\n} from './layout-client.js'\n\nexport interface CreateDeckClientOptions {\n\t/** 默认 `__electronDeckBridge`;必须与 host preload 对齐 */\n\treadonly globalName?: string\n}\n\n// HS / EV 使用 `any` 而非 `JsonValue[]` 约束:\n// (1) host 侧 HostServiceHandler 同样是 `(...args: any[]) => unknown`,两侧对称;\n// (2) JsonValue 索引签名挡掉常见 host 写法(`(p: { code: string }) => ...`),\n// 强迫 rest-only 签名时 `Parameters<HS[K]>` 推不出真实参数类型;\n// (3) Electron IPC 实际走 structured clone(非 JSON),原约束的\"前提\"本就错;\n// (4) 真要 runtime 校验,在 transport 边界用 `runtime.ipc.handle({ validator })`\n// 与 protocol envelope(`InvokeRequest.args: readonly JsonValue[]`)已经够。\nexport interface DeckClient<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tHS extends Record<keyof HS, (...args: any[]) => unknown>,\n\tEV extends readonly HostEvent<JsonValue>[],\n> {\n\tready(): Promise<void>\n\tinvoke<K extends keyof HS & string>(\n\t\tname: K,\n\t\t...args: Parameters<HS[K]>\n\t): Promise<Awaited<ReturnType<HS[K]>>>\n\ton<E extends EV[number]>(\n\t\tevent: E,\n\t\tlistener: (payload: E extends HostEvent<infer P> ? P : never) => void,\n\t): Disposable\n}\n\nexport function createDeckClient<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tHS extends Record<keyof HS, (...args: any[]) => unknown>,\n\tEV extends readonly HostEvent<JsonValue>[],\n>(options?: CreateDeckClientOptions): DeckClient<HS, EV> {\n\tconst globalName = options?.globalName ?? DEFAULT_BRIDGE_GLOBAL\n\n\tfunction getBridge(): DeckBridge {\n\t\tconst bridge = readBridgeFromGlobal(globalName)\n\t\tif (bridge === undefined) {\n\t\t\tthrow new DeckClientNotReadyError(\n\t\t\t\t`Deck framework bridge is missing on window[\"${globalName}\"] — did the host preload call exposeDeckBridge()?`,\n\t\t\t)\n\t\t}\n\t\treturn bridge\n\t}\n\n\treturn {\n\t\tasync ready(): Promise<void> {\n\t\t\tconst bridge = getBridge()\n\t\t\tconst remoteMajor = parseMajor(bridge.version)\n\t\t\tconst localMajor = parseMajor(BRIDGE_PROTOCOL_VERSION)\n\t\t\tif (remoteMajor !== localMajor) {\n\t\t\t\tthrow new DeckClientNotReadyError(\n\t\t\t\t\t`Deck bridge protocol version mismatch: bridge=${String(bridge.version)}, client expected major ${localMajor}.x.x (${BRIDGE_PROTOCOL_VERSION})`,\n\t\t\t\t)\n\t\t\t}\n\t\t},\n\n\t\tasync invoke<K extends keyof HS & string>(\n\t\t\tname: K,\n\t\t\t...args: Parameters<HS[K]>\n\t\t): Promise<Awaited<ReturnType<HS[K]>>> {\n\t\t\tconst bridge = getBridge()\n\t\t\tconst response = await bridge.invoke({\n\t\t\t\tkind: 'host',\n\t\t\t\tname,\n\t\t\t\targs: args as readonly JsonValue[],\n\t\t\t})\n\t\t\tif (response.ok) {\n\t\t\t\treturn response.result as Awaited<ReturnType<HS[K]>>\n\t\t\t}\n\t\t\tconst { remoteName, message, code } = response.error\n\t\t\tthrow new DeckRemoteError(remoteName, message, code)\n\t\t},\n\n\t\ton<E extends EV[number]>(\n\t\t\tevent: E,\n\t\t\tlistener: (payload: E extends HostEvent<infer P> ? P : never) => void,\n\t\t): Disposable {\n\t\t\tconst bridge = getBridge()\n\t\t\tconst wrapped = (env: EventEnvelope): void => {\n\t\t\t\tif (env.name === event.name) {\n\t\t\t\t\tlistener(env.payload as E extends HostEvent<infer P> ? P : never)\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst unsubscribe = bridge.onEvent(wrapped)\n\t\t\tlet disposed = false\n\t\t\treturn {\n\t\t\t\tdispose: () => {\n\t\t\t\t\tif (disposed) return\n\t\t\t\t\tdisposed = true\n\t\t\t\t\tunsubscribe()\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t}\n}\n\nexport function readBridgeFromGlobal(\n\tglobalName: string = DEFAULT_BRIDGE_GLOBAL,\n): DeckBridge | undefined {\n\tconst g = globalThis as unknown as Record<string, unknown>\n\tconst bridge = g[globalName]\n\tif (bridge === undefined || bridge === null) return undefined\n\treturn bridge as DeckBridge\n}\n\nfunction parseMajor(version: unknown): number {\n\tif (typeof version !== 'string') return Number.NaN\n\tconst head = version.split('.')[0] ?? ''\n\tconst n = Number.parseInt(head, 10)\n\treturn Number.isNaN(n) ? Number.NaN : n\n}\n\nexport { BRIDGE_PROTOCOL_VERSION, DEFAULT_BRIDGE_GLOBAL }\n"],"mappings":";;;AAiBA,IAAM,aAAa,OAKJ;CACb,GAAG,KAAK,MAAM,EAAE,CAAC;CACjB,GAAG,KAAK,MAAM,EAAE,CAAC;CACjB,OAAO,KAAK,IAAI,GAAG,KAAK,MAAM,EAAE,KAAK,CA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BACT,iDAAiD,OAAO,OAAO,OAAO,EAAE,0BAA0B,WAAW,QAAQ,wBAAwB,EAC9I;EAEF;EAEA,MAAM,OACL,MACA,GAAG,MACmC;GAEtC,MAAM,WAAW,MADF,UACQ,EAAO,OAAO;IACpC,MAAM;IACN;IACM;GACP,CAAC;GACD,IAAI,SAAS,IACZ,OAAO,SAAS;GAEjB,MAAM,EAAE,YAAY,SAAS,SAAS,SAAS;GAC/C,MAAM,IAAI,gBAAgB,YAAY,SAAS,IAAI;EACpD;EAEA,GACC,OACA,UACa;GACb,MAAM,SAAS,UAAU;GACzB,MAAM,WAAW,QAA6B;IAC7C,IAAI,IAAI,SAAS,MAAM,MACtB,SAAS,IAAI,OAAmD;GAElE;GACA,MAAM,cAAc,OAAO,QAAQ,OAAO;GAC1C,IAAI,WAAW;GACf,OAAO,EACN,eAAe;IACd,IAAI,UAAU;IACd,WAAW;IACX,YAAY;GACb,EACD;EACD;CACD;AACD;AAEA,SAAgB,qBACf,aAAqB,uBACI;CAEzB,MAAM,SAAS,WAAE;CACjB,IAAI,WAAW,KAAA,KAAa,WAAW,MAAM,OAAO,KAAA;CACpD,OAAO;AACR;AAEA,SAAS,WAAW,SAA0B;CAC7C,IAAI,OAAO,YAAY,UAAU,OAAO;CACxC,MAAM,OAAO,QAAQ,MAAM,GAAG,EAAE,MAAM;CACtC,MAAM,IAAI,OAAO,SAAS,MAAM,EAAE;CAClC,OAAO,OAAO,MAAM,CAAC,IAAI,MAAa;AACvC"}
@@ -38,7 +38,7 @@ export interface LayoutClientDeps {
38
38
  };
39
39
  }
40
40
  /**
41
- * Renderer half of the A5-2 slot-token handshake (§A5-2.1). Subscribes to main's
41
+ * Renderer half of the slot-token handshake (capability-and-lifecycle.md「原子下发握手协议」). Subscribes to main's
42
42
  * `slot-grant` pushes FIRST (so a grant replayed synchronously by `subscribe()`
43
43
  * cannot be missed), then on each grant anchors the granted DOM slot with this
44
44
  * session's hardening opts (followScroll / followGeometry / guardDisplayNone)
@@ -11,7 +11,7 @@
11
11
  * react here does not violate the pure-TS layout boundary.
12
12
  */
13
13
  import { type ReactNode } from 'react';
14
- import type { LayoutModel, PanelRegistry } from '../layout/index.js';
14
+ import type { LayoutModel, PanelRegistry, SizeConstraint } from '../layout/index.js';
15
15
  export interface DockViewProps {
16
16
  model: LayoutModel;
17
17
  registry: PanelRegistry;
@@ -29,15 +29,20 @@ export interface DockViewProps {
29
29
  bindNativeSlot: (panelId: string, el: HTMLElement | null) => void;
30
30
  }
31
31
  /**
32
- * Compute the `defaultSize` percentage for each FLEXIBLE (unconstrained) child,
33
- * keyed by its ORIGINAL child index. Fixed (px-pinned) children are excluded
34
- * from the pool entirely so their weight never pollutes the flexible siblings'
35
- * normalization (FIX E1). `constraints[i]` non-null child i is fixed and is
36
- * absent from the returned map.
32
+ * Read the current dock layout epoch (the model revision). Re-renders the caller
33
+ * whenever a layout mutation commits. Keyed into a panel's effect deps, it lets
34
+ * a native-overlay host re-measure on a reorder that fires no geometry event.
35
+ * Returns 0 when used outside a `<DockView>`.
37
36
  */
38
- export declare function computeFlexiblePercentages(sizes: readonly number[], constraints: readonly ({
39
- fixedPx: number;
40
- } | null)[] | undefined): Map<number, number>;
37
+ export declare function useDockLayoutEpoch(): number;
38
+ /**
39
+ * Compute the `defaultSize` percentage for each FLEXIBLE child, keyed by its
40
+ * ORIGINAL child index. Px-sized children (a non-null `constraint` — `fixedPx`
41
+ * locked OR `minPx` floored) are EXCLUDED from the pool: their size is px, not a
42
+ * weight, so it must never pollute the flexible siblings' normalization (FIX E1).
43
+ * `constraints[i]` non-null ⇒ child i is px-sized and absent from the returned map.
44
+ */
45
+ export declare function computeFlexiblePercentages(sizes: readonly number[], constraints: readonly (SizeConstraint | null)[] | undefined): Map<number, number>;
41
46
  export declare function DockView(props: DockViewProps): ReactNode;
42
47
  /** Are two panelId→percentage maps equivalent within `epsilon` percentage
43
48
  * points? Both maps must cover EXACTLY the `ids` key set — a missing key OR an
@@ -1 +1 @@
1
- {"version":3,"file":"dock-view.d.ts","sourceRoot":"","sources":["../../src/dock-react/dock-view.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAON,KAAK,SAAS,EACd,MAAM,OAAO,CAAA;AAId,OAAO,KAAK,EACX,WAAW,EAGX,aAAa,EAIb,MAAM,oBAAoB,CAAA;AAgB3B,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,WAAW,CAAA;IAClB,QAAQ,EAAE,aAAa,CAAA;IACvB;;;;;;;OAOG;IACH,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,KAAK,SAAS,CAAA;IACzE,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAA;CACjE;AAaD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACzC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,WAAW,EAAE,SAAS,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,GAC9D,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAUrB;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,CA6GxD;AA4GD;;;;;;;qEAOqE;AACrE,wBAAgB,iBAAiB,CAChC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzB,GAAG,EAAE,SAAS,MAAM,EAAE,EACtB,OAAO,GAAE,MAAuB,GAC9B,OAAO,CAaT"}
1
+ {"version":3,"file":"dock-view.d.ts","sourceRoot":"","sources":["../../src/dock-react/dock-view.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EASN,KAAK,SAAS,EACd,MAAM,OAAO,CAAA;AAId,OAAO,KAAK,EACX,WAAW,EAGX,aAAa,EACb,cAAc,EAGd,MAAM,oBAAoB,CAAA;AAiB3B,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,WAAW,CAAA;IAClB,QAAQ,EAAE,aAAa,CAAA;IACvB;;;;;;;OAOG;IACH,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,KAAK,SAAS,CAAA;IACzE,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAA;CACjE;AAqBD;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAaD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACzC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,WAAW,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,GACzD,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAUrB;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,CAgJxD;AA0KD;;;;;;;qEAOqE;AACrE,wBAAgB,iBAAiB,CAChC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzB,GAAG,EAAE,SAAS,MAAM,EAAE,EACtB,OAAO,GAAE,MAAuB,GAC9B,OAAO,CAaT"}
@@ -92,4 +92,19 @@ export declare function isNoopRedock(dragged: string, draggedGroupId: string | u
92
92
  groupId: string;
93
93
  panelId: string;
94
94
  }, zone: DropZone): boolean;
95
+ /**
96
+ * Map a pointer x-position over a horizontal tab strip to an insertion index for
97
+ * a within-strip REORDER (the `dropPolicy:'reorder-only'` gesture). The strip is
98
+ * the dragged tab's own group; `tabRects` are the tab buttons' rects in visual
99
+ * order (each `left` is the rect's left edge, `width` its width). The index is
100
+ * the count of tabs whose MIDPOINT the pointer has passed: the LEFT half of a tab
101
+ * inserts BEFORE it, the RIGHT half (and the exact midpoint) inserts AFTER it. A
102
+ * pointer left of the first tab → 0; past the last tab → `tabRects.length`. Pure
103
+ * (no DOM): the caller measures the rects and passes the pointer x. An empty
104
+ * strip or a non-finite pointer → 0.
105
+ */
106
+ export declare function computeReorderIndex(tabRects: readonly {
107
+ left: number;
108
+ width: number;
109
+ }[], pointerX: number): number;
95
110
  //# sourceMappingURL=drag-redock.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"drag-redock.d.ts","sourceRoot":"","sources":["../../src/dock-react/drag-redock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,uEAAuE;AACvE,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAErE;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GACtD;IACD,IAAI,EAAE,OAAO,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,GAAG,EAAE,KAAK,GAAG,QAAQ,CAAA;IACrB,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;CAClB,CAAA;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACvC,KAAK,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAC/B,YAAY,SAAO,GACjB,QAAQ,CAmEV;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CACjC,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,MA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,OAAO,EAAE,MAAM,EACf,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC1C,cAAc,CAOhB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAC3B,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAC5C,IAAI,EAAE,QAAQ,GACZ,OAAO,CAMT;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAClC,QAAQ,EAAE,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,EACpD,QAAQ,EAAE,MAAM,GACd,MAAM,CASR"}
@@ -5,8 +5,8 @@
5
5
  * `PanelRegistry` (panelId -> descriptor). See `dock-view.test.tsx` for the
6
6
  * `data-*` contract.
7
7
  */
8
- export { DockView, computeFlexiblePercentages, layoutsEquivalent } from './dock-view.js';
8
+ export { DockView, computeFlexiblePercentages, layoutsEquivalent, useDockLayoutEpoch } from './dock-view.js';
9
9
  export type { DockViewProps } from './dock-view.js';
10
- export { computeDropZone, dropZoneToMutation, isNoopRedock } from './drag-redock.js';
10
+ export { computeDropZone, computeReorderIndex, dropZoneToMutation, isNoopRedock } from './drag-redock.js';
11
11
  export type { DropZone, RedockMutation } from './drag-redock.js';
12
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dock-react/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,QAAQ,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACxF,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAInD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpF,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dock-react/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,QAAQ,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAC5G,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAInD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACzG,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA"}