{"version":3,"sources":["../src/chromeState.ts"],"sourcesContent":["import { createPushChannel } from './pushChannel';\nimport { CHROME_STATE, REQUEST_CHROME_STATE } from './generated/protocol';\n\n/**\n * What the immediately.run host's own chrome is currently doing over your app\n * (PRESENT_MODE_CHROME_SPEC §6). In run (\"present\") mode the platform shows a\n * single pull-down tab in one corner; activating it opens the platform menu —\n * an anchored panel on desktop, a bottom sheet on mobile — and the host dims\n * and slightly insets your app behind it.\n *\n * Reading this is **entirely optional**. No platform behavior depends on your\n * app consuming it, and an app that never reads it behaves identically\n * (R-PMC-18) — the platform never requires immediately.run knowledge of an app\n * (product value 3). It exists for the two things a cooperative app can do\n * better with it than without:\n *\n * - **Pause while dimmed.** `overlay === 'menu'` means the user is looking at\n *   platform chrome, not at you: a good moment to pause a video, an animation,\n *   or a polling loop.\n * - **Keep the corner clear.** `tab.edge` says where the platform's tab sits, so\n *   a floating control of your own can avoid overlapping it.\n *\n * Baseline capability `chrome:read` — every app may read it. It is a read of the\n * host's own UI state and discloses nothing app-foreign; there is deliberately no\n * counterpart that lets an app *operate* platform chrome.\n *\n * ```ts\n * import { onChromeStateChange } from '@immediately-run/sdk';\n *\n * onChromeStateChange(({ overlay }) => {\n *   if (overlay === 'menu') video.pause();\n * });\n * ```\n */\nexport interface ChromeState {\n  /**\n   * `'menu'` while the platform menu / bottom sheet (and its scrim) is open over\n   * your app; `'none'` at rest. Edit mode reports `'none'` — the workbench chrome\n   * is beside your app, not over it.\n   */\n  overlay: 'none' | 'menu';\n  /** Where the platform's pull-down tab sits. Only one edge exists today. */\n  tab: { edge: 'top-right' };\n}\n\n/**\n * Assumed before the host reports — and the value that stands forever on a host\n * that never pushes this channel (an older host, or one that does not paint\n * present-mode chrome at all). \"Nothing is over you\" is the safe default: an app\n * that gates a pause on it simply never pauses.\n */\nconst DEFAULT_CHROME_STATE: ChromeState = { overlay: 'none', tab: { edge: 'top-right' } };\n\nconst isChromeState = (v: unknown): v is ChromeState => {\n  const c = v as Partial<ChromeState> | null;\n  return (\n    !!c &&\n    (c.overlay === 'none' || c.overlay === 'menu') &&\n    !!c.tab &&\n    typeof c.tab === 'object' &&\n    (c.tab as ChromeState['tab']).edge === 'top-right'\n  );\n};\n\n// Read over the transport (SDK_PACKAGING_SPEC §4): the host pushes `chrome-state`\n// and answers `request-chrome-state` (wire format: site-main channelBridge.ts).\nconst channel = createPushChannel<ChromeState>({\n  pushType: CHROME_STATE,\n  requestType: REQUEST_CHROME_STATE,\n  initial: DEFAULT_CHROME_STATE,\n  parse: (msg) => (isChromeState(msg.chromeState) ? (msg.chromeState as ChromeState) : undefined),\n});\n\n/** Returns the current chrome state. Poll for a one-off read. */\nexport const getChromeState = (): ChromeState => channel.get();\n\n/**\n * Subscribe to chrome-state changes. The listener is invoked immediately with the\n * current value, then again on every change. Returns an unsubscribe fn.\n */\nexport const onChromeStateChange = (listener: (chromeState: ChromeState) => void): (() => void) =>\n  channel.onChange(listener);\n\n/** React hook returning the current chrome state, re-rendering on change. */\nexport const useChromeState = (): ChromeState => channel.use();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAkC;AAClC,sBAAmD;AAkDnD,MAAM,uBAAoC,EAAE,SAAS,QAAQ,KAAK,EAAE,MAAM,YAAY,EAAE;AAExF,MAAM,gBAAgB,CAAC,MAAiC;AACtD,QAAM,IAAI;AACV,SACE,CAAC,CAAC,MACD,EAAE,YAAY,UAAU,EAAE,YAAY,WACvC,CAAC,CAAC,EAAE,OACJ,OAAO,EAAE,QAAQ,YAChB,EAAE,IAA2B,SAAS;AAE3C;AAIA,MAAM,cAAU,sCAA+B;AAAA,EAC7C,UAAU;AAAA,EACV,aAAa;AAAA,EACb,SAAS;AAAA,EACT,OAAO,CAAC,QAAS,cAAc,IAAI,WAAW,IAAK,IAAI,cAA8B;AACvF,CAAC;AAGM,MAAM,iBAAiB,MAAmB,QAAQ,IAAI;AAMtD,MAAM,sBAAsB,CAAC,aAClC,QAAQ,SAAS,QAAQ;AAGpB,MAAM,iBAAiB,MAAmB,QAAQ,IAAI;","names":[]}