{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "core-sheet",
  "type": "registry:lib",
  "title": "core/sheet",
  "description": "Framework-free behaviour shared by the ui-* components (sheet); no DOM, no lit. Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/core/sheet.ts",
      "type": "registry:lib",
      "target": "components/ui/core/sheet.ts",
      "content": "/**\n * The bottom sheet a date picker's calendar opens in on a phone (Lit and React alike): when to use one, and the\n * swipe down that closes it. The sheet itself is a native modal `<dialog>` (top layer, the page behind inert, focus\n * kept inside, Esc); the renderers pass in what they touch, so this module needs no DOM itself.\n */\n\n/** A phone: a touch screen narrower than Carbon's md breakpoint (42rem). */\nexport const SHEET_MEDIA = '(pointer: coarse) and (max-width: 41.98rem)';\n\n/** The window members `opensAsSheet` reads (a DOM `Window` fits). */\nexport interface SheetWindow {\n    matchMedia?(query: string): { readonly matches: boolean };\n}\n\n/** Whether a picker set to `picker` opens its calendar as a bottom sheet: `sheet` always, `auto` on a phone (SHEET_MEDIA). */\nexport function opensAsSheet(picker: string, win: SheetWindow = globalThis as SheetWindow): boolean {\n    return picker === 'sheet' || (picker === 'auto' && !!win.matchMedia?.(SHEET_MEDIA).matches);\n}\n\n/** What `swipeToClose` reads of a pointer event (a DOM `PointerEvent` fits). */\nexport interface SwipeEvent {\n    readonly pointerId: number;\n    readonly clientY: number;\n    readonly timeStamp: number;\n    readonly isPrimary?: boolean;\n    readonly button?: number;\n}\n\n/** An event listener (a DOM `EventListener` takes any `Event`, which is an object). */\ntype Listener = (event: object) => void;\n\n/** The grip a swipe starts on (a DOM `Element` fits). */\nexport interface SwipeHandle {\n    addEventListener(type: string, listener: Listener): void;\n    removeEventListener(type: string, listener: Listener): void;\n    setPointerCapture?(pointerId: number): void;\n}\n\n/** The sheet that follows the finger (a DOM `HTMLElement` fits). */\nexport interface SwipeSheet {\n    readonly style: { setProperty(name: string, value: string): void; removeProperty(name: string): string };\n    readonly dataset: Record<string, string | undefined>;\n}\n\n/** Dragged this far down (px), the sheet closes when let go. */\nexport const SWIPE_CLOSE_DISTANCE = 64;\n/** Or flicked down this fast (px per ms), at least 16px. */\nconst SWIPE_CLOSE_SPEED = 0.5;\n\n/**\n * Swipe down to close: a press on `handle` that drags down moves `sheet` with it (`translate`, `data-dragging` while it\n * does, so its spring-back transition can wait), and letting go 64px down, or after a flick down, calls `onClose`;\n * otherwise the sheet goes back. Dragging up doesn't move it. Returns the function that stops listening.\n */\nexport function swipeToClose(handle: SwipeHandle, sheet: SwipeSheet, onClose: () => void): () => void {\n    let drag: { id: number; y: number; at: number; dy: number; speed: number } | null = null;\n    const reset = () => {\n        drag = null;\n        sheet.style.removeProperty('translate');\n        delete sheet.dataset.dragging;\n    };\n    const down = (event: SwipeEvent) => {\n        if (event.isPrimary === false || (event.button ?? 0) !== 0) return;\n        drag = { id: event.pointerId, y: event.clientY, at: event.timeStamp, dy: 0, speed: 0 };\n    };\n    const move = (event: SwipeEvent) => {\n        if (!drag || event.pointerId !== drag.id) return;\n        const dy = Math.max(0, event.clientY - drag.y);\n        const dt = event.timeStamp - drag.at;\n        if (dt > 0) drag.speed = (dy - drag.dy) / dt;\n        drag.dy = dy;\n        drag.at = event.timeStamp;\n        if (dy < 4 && sheet.dataset.dragging === undefined) return; // still a press (on the × button, say): it stays a click\n        // the finger may leave the grip as the sheet moves: the rest of the drag still comes here\n        if (sheet.dataset.dragging === undefined) {\n            try {\n                handle.setPointerCapture?.(event.pointerId);\n            } catch {\n                // the pointer is already gone (lifted between the events): the drag ends with its pointerup anyway\n            }\n        }\n        sheet.dataset.dragging = '';\n        sheet.style.setProperty('translate', `0 ${dy}px`);\n    };\n    const up = (event: SwipeEvent) => {\n        if (!drag || event.pointerId !== drag.id) return;\n        const { dy, speed } = drag;\n        reset();\n        if (dy >= SWIPE_CLOSE_DISTANCE || (dy >= 16 && speed >= SWIPE_CLOSE_SPEED)) onClose();\n    };\n    const cancel = (event: SwipeEvent) => {\n        if (drag && event.pointerId === drag.id) reset();\n    };\n    const listeners: [string, Listener][] = [\n        ['pointerdown', down as Listener],\n        ['pointermove', move as Listener],\n        ['pointerup', up as Listener],\n        ['pointercancel', cancel as Listener],\n    ];\n    for (const [type, listener] of listeners) handle.addEventListener(type, listener);\n    return () => {\n        for (const [type, listener] of listeners) handle.removeEventListener(type, listener);\n        reset();\n    };\n}\n"
    }
  ]
}
