@dimina-kit/electron-deck 0.1.0-dev.20260618090552 → 0.1.0-dev.20260624084417
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/README.md +2 -2
- package/dist/client/index.js.map +1 -1
- package/dist/dock-react/dock-view.d.ts.map +1 -1
- package/dist/dock-react/index.js +5 -4
- package/dist/dock-react/index.js.map +1 -1
- package/dist/{electron-deck-CW6gkGS-.js → electron-deck-C9_Yu3fd.js} +53 -59
- package/dist/electron-deck-C9_Yu3fd.js.map +1 -0
- package/dist/electron-deck.d.ts +2 -2
- package/dist/host/capability.d.ts +1 -1
- package/dist/host/control-bus.d.ts +3 -3
- package/dist/host/index.d.ts +1 -1
- package/dist/host/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/deck-app.d.ts +54 -60
- package/dist/internal/deck-app.d.ts.map +1 -1
- package/dist/internal/electron-types.d.ts +3 -3
- package/dist/internal/trust-set.d.ts +3 -3
- package/dist/internal/wire-transport.d.ts +5 -5
- package/dist/internal/wire-transport.d.ts.map +1 -1
- package/dist/layout/index.d.ts +1 -0
- package/dist/layout/index.d.ts.map +1 -1
- package/dist/layout/index.js +2 -2
- package/dist/layout/types.d.ts +8 -2
- package/dist/layout/types.d.ts.map +1 -1
- package/dist/layout/user-actions.d.ts +9 -0
- package/dist/layout/user-actions.d.ts.map +1 -0
- package/dist/{layout-WI8y1hxP.js → layout-oJQ9hind.js} +20 -2
- package/dist/layout-oJQ9hind.js.map +1 -0
- package/dist/view-handle-CR-yWNfr.js.map +1 -1
- package/package.json +4 -2
- package/dist/electron-deck-CW6gkGS-.js.map +0 -1
- package/dist/layout-WI8y1hxP.js.map +0 -1
package/README.md
CHANGED
|
@@ -32,8 +32,8 @@ startElectronDeck({
|
|
|
32
32
|
| host 侧 control-bus / capability / trust 原语 | `@dimina-kit/electron-deck/host` |
|
|
33
33
|
| preload bridge `exposeDeckBridge()` | `@dimina-kit/electron-deck/preload` |
|
|
34
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`
|
|
35
|
+
| layout-as-data 引擎(`SplitNode`/`TabGroupNode` 树、`movePanel`/`splitPanel`/`closePanel`/`insertPanel`/`setActive`/`setSizes`/`setConstraint` mutation、`serializeLayout`/`parseLayout`/`validateTree`、`createLayoutModel` 单写者可观察模型、panel registry,descriptor 可带 `PanelCapabilities`:`draggable`/`dropPolicy`/`closable`/`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'` 只允许组内重排,`closable:false` 隐藏关闭控件)+ `computeReorderIndex` 纯几何 | `@dimina-kit/electron-deck/dock-react` |
|
|
37
37
|
|
|
38
38
|
## 文档
|
|
39
39
|
|
package/dist/client/index.js.map
CHANGED
|
@@ -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 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,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BAAgB,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. 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. 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 ──────────────────\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 // A held pointer means the drag may still resume after a static pause, so a\n // steady run while held must NOT close the sentinel — it only closes once the\n // pointer is released. Without this gate a press that pauses a couple of\n // frames before the drag actually moves would close mid-press and drop the\n // 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 // 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: 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.\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 // An ancestor scroll moved the target's screen rect. With the sentinel on,\n // open the window so the whole scroll burst is followed frame-by-frame;\n // without it, a single synchronous emit() follows the new rect.\n const onScroll = (): void => {\n if (followGeometry) openSentinel()\n else emit()\n }\n\n // A capture-phase pointerdown on a [role=\"separator\"] splitter handle marks\n // the start of a drag that moves the target via ancestor reflow (no RO tick)\n // → 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 // 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: 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:\n // 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: 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,CAAC;CACtC,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,EAAE,MAAM,CAAC;AAC1C;;;;;;;;;AAsLA,SAAgB,iBAAiB,QAAgC;CAC/D,MAAM,IAAI,OAAO,sBAAsB;CACvC,OAAO;EACL,SAAS;EACT,QAAQ,UAAU;GAAE,GAAG,EAAE;GAAM,GAAG,EAAE;GAAK,OAAO,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M,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 +1 @@
|
|
|
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;
|
|
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;AAWd,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,CAsJxD;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"}
|
package/dist/dock-react/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as extractPanel, l as setSizes, o as movePanel, s as setActive, t as closePanelForUser, u as splitPanel } from "../layout-oJQ9hind.js";
|
|
2
2
|
import { Fragment, createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
3
3
|
import { Group, Panel, Separator } from "react-resizable-panels";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -195,8 +195,8 @@ function DockView(props) {
|
|
|
195
195
|
model.apply((t) => setActive(t, groupId, panelId));
|
|
196
196
|
}, [model]);
|
|
197
197
|
const handleClose = useCallback((panelId) => {
|
|
198
|
-
model.apply((t) =>
|
|
199
|
-
}, [model]);
|
|
198
|
+
model.apply((t) => closePanelForUser(t, panelId, registry));
|
|
199
|
+
}, [model, registry]);
|
|
200
200
|
const canClose = countPanels(tree.root) > 1;
|
|
201
201
|
const isPanelInTree = useCallback((panelId) => findPanelGroupId(tree.root, panelId) !== void 0, [tree]);
|
|
202
202
|
const handleApplyLayout = useCallback((splitId, weights) => {
|
|
@@ -208,6 +208,7 @@ function DockView(props) {
|
|
|
208
208
|
panelId: activePanelId
|
|
209
209
|
};
|
|
210
210
|
const draggedGroupId = findPanelGroupId(model.get().root, draggedPanelId);
|
|
211
|
+
if (registry.get(draggedPanelId)?.draggable === false) return;
|
|
211
212
|
if (registry.get(activePanelId)?.draggable === false) return;
|
|
212
213
|
if (registry.get(draggedPanelId)?.dropPolicy === "reorder-only") {
|
|
213
214
|
if (draggedGroupId === void 0 || draggedGroupId !== groupId) return;
|
|
@@ -678,7 +679,7 @@ function GroupView(props) {
|
|
|
678
679
|
onClick: () => {
|
|
679
680
|
if (!active) ctx.onActivate(node.id, panelId);
|
|
680
681
|
},
|
|
681
|
-
children: [title, ctx.canClose ? /* @__PURE__ */ jsx("span", {
|
|
682
|
+
children: [title, ctx.canClose && descriptor?.closable !== false ? /* @__PURE__ */ jsx("span", {
|
|
682
683
|
role: "button",
|
|
683
684
|
tabIndex: 0,
|
|
684
685
|
"data-deck-tab-close": panelId,
|