{"version":3,"file":"index.mjs","names":[],"sources":["../../src/display/display.ts"],"sourcesContent":["/* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD */\n/* SPDX-License-Identifier: Apache-2.0 */\n\n/**\n * Display service module for JS apps — wraps `brookesia_service_display` RPC.\n *\n * @example\n * import display from '@brookesia/service/display';\n * if (display.available()) {\n *   const outputs = display.getOutputs();\n *   const sourceId = display.registerSource({ name: 'LVGL', role: 'gui' });\n *   display.setBacklightBrightness(outputs[0].id ?? 0, 80);\n *   display.close();\n * }\n */\n\nimport {\n  closeDisplay,\n  getActiveRole,\n  getActiveSource,\n  getBacklightBrightness,\n  getBacklightOnOff,\n  getOutputs,\n  getSourceRoles,\n  getSources,\n  getTouchGestureConfig,\n  isDisplayAvailable,\n  loadDisplayData,\n  openDisplay,\n  registerSource,\n  releaseOutput,\n  requestOutput,\n  resetDisplayData,\n  setActiveSource,\n  setActiveSourceRole,\n  setBacklightBrightness,\n  setBacklightOnOff,\n  setTouchGestureConfig,\n  unregisterSource,\n  type DisplayClientOptions,\n  type DisplayHandle,\n} from './display-client.ts';\nimport type {\n  DisplayOutputInfo,\n  DisplayOutputSlot,\n  DisplayPixelFormat,\n  DisplaySourceInfo,\n  DisplaySourceState,\n  DisplayTouchGestureConfig,\n  DisplayTouchOperationMode,\n} from './display-types.ts';\n\nexport type {\n  DisplayOutputInfo,\n  DisplayOutputSlot,\n  DisplayPixelFormat,\n  DisplaySourceInfo,\n  DisplaySourceState,\n  DisplayTouchGestureConfig,\n  DisplayTouchOperationMode,\n};\n\nexport type DisplayModuleOptions = DisplayClientOptions;\n\ntype State = {\n  handle: DisplayHandle | null;\n  options: DisplayModuleOptions;\n};\n\nconst state: State = { handle: null, options: {} };\n\nfunction handle(): DisplayHandle {\n  if (state.handle !== null) {\n    return state.handle;\n  }\n  if (!isDisplayAvailable(state.options)) {\n    throw new Error('Display service is not available');\n  }\n  state.handle = openDisplay(state.options);\n  return state.handle;\n}\n\n/**\n * Inject a mock RPC host and reset the cached service handle (vitest / Node only).\n *\n * @param options - Client options, typically `{ host }` from `@brookesia/service/hosts/display`\n */\nexport function configure(options: DisplayModuleOptions): void {\n  if (state.handle !== null) {\n    closeDisplay(state.handle, state.options);\n  }\n  state.handle = null;\n  state.options = options;\n}\n\nconst display = {\n  /** @returns `true` when the Display service is registered */\n  available(): boolean {\n    return isDisplayAvailable(state.options);\n  },\n\n  /** Release the Display service binding. */\n  close(): void {\n    if (state.handle === null) {\n      return;\n    }\n    closeDisplay(state.handle, state.options);\n    state.handle = null;\n  },\n\n  /** @returns Physical display outputs (panel slots) */\n  getOutputs(): DisplayOutputInfo[] {\n    return getOutputs(handle(), state.options);\n  },\n\n  /** @returns Registered display sources (LVGL, camera, NES, …) */\n  getSources(): DisplaySourceInfo[] {\n    return getSources(handle(), state.options);\n  },\n\n  /**\n   * Register a new display source.\n   *\n   * @param source - `{ name, role, preferred_outputs?, ... }`\n   * @returns Source ID assigned by the service\n   */\n  registerSource(source: DisplaySourceInfo): number {\n    return registerSource(handle(), source, state.options);\n  },\n\n  /**\n   * Unregister a display source by name.\n   *\n   * @param sourceName - Source name; do not unregister system `'LVGL'` unless intended\n   */\n  unregisterSource(sourceName: string): void {\n    unregisterSource(handle(), sourceName, state.options);\n  },\n\n  /**\n   * Request an output for a source.\n   *\n   * @param sourceName - Registered source name\n   * @param outputName - Target output name from {@link getOutputs}\n   */\n  requestOutput(sourceName: string, outputName: string): void {\n    requestOutput(handle(), sourceName, outputName, state.options);\n  },\n\n  /**\n   * Release an output previously requested by a source.\n   *\n   * @param sourceName - Source name\n   * @param outputName - Output name\n   */\n  releaseOutput(sourceName: string, outputName: string): void {\n    releaseOutput(handle(), sourceName, outputName, state.options);\n  },\n\n  /**\n   * Set the active source shown on an output.\n   *\n   * @param outputName - Output name\n   * @param sourceName - Source to display\n   */\n  setActiveSource(outputName: string, sourceName: string): void {\n    setActiveSource(handle(), outputName, sourceName, state.options);\n  },\n\n  /**\n   * @param outputName - Output name\n   * @returns Name of the currently active source\n   */\n  getActiveSource(outputName: string): string {\n    return getActiveSource(handle(), outputName, state.options);\n  },\n\n  /**\n   * Grant an output to the first registered source with the given role.\n   *\n   * @param outputName - Output name; empty string uses the first output\n   * @param role - Source role to look for (e.g. `'gui'`, `'video'`)\n   */\n  setActiveSourceRole(outputName: string, role: string): void {\n    setActiveSourceRole(handle(), outputName, role, state.options);\n  },\n\n  /**\n   * @param outputName - Output name\n   * @returns The role of the source currently active on the output\n   */\n  getActiveRole(outputName: string): string {\n    return getActiveRole(handle(), outputName, state.options);\n  },\n\n  /**\n   * @returns All registered display source roles, de-duplicated in registration order\n   */\n  getSourceRoles(): string[] {\n    return getSourceRoles(handle(), state.options);\n  },\n\n  /**\n   * Configure touch gesture thresholds for an output.\n   *\n   * @param outputId - Output ID from {@link getOutputs}\n   * @param config - Swipe / long-press thresholds\n   */\n  setTouchGestureConfig(outputId: number, config: DisplayTouchGestureConfig): void {\n    setTouchGestureConfig(handle(), outputId, config, state.options);\n  },\n\n  /**\n   * @param outputId - Output ID\n   * @returns Current touch gesture configuration\n   */\n  getTouchGestureConfig(outputId: number): DisplayTouchGestureConfig {\n    return getTouchGestureConfig(handle(), outputId, state.options);\n  },\n\n  /**\n   * Set backlight brightness.\n   *\n   * @param outputId - Output ID\n   * @param brightness - 0–100 percent\n   */\n  setBacklightBrightness(outputId: number, brightness: number): void {\n    setBacklightBrightness(handle(), outputId, brightness, state.options);\n  },\n\n  /**\n   * @param outputId - Output ID\n   * @returns Brightness 0–100\n   */\n  getBacklightBrightness(outputId: number): number {\n    return getBacklightBrightness(handle(), outputId, state.options);\n  },\n\n  /**\n   * Turn backlight on or off.\n   *\n   * @param outputId - Output ID\n   * @param on - `true` for on\n   */\n  setBacklightOnOff(outputId: number, on: boolean): void {\n    setBacklightOnOff(handle(), outputId, on, state.options);\n  },\n\n  /**\n   * @param outputId - Output ID\n   * @returns `true` when backlight is on\n   */\n  getBacklightOnOff(outputId: number): boolean {\n    return getBacklightOnOff(handle(), outputId, state.options);\n  },\n\n  /**\n   * Load persisted backlight / gesture settings for an output.\n   *\n   * @param outputId - Output ID\n   */\n  loadData(outputId: number): void {\n    loadDisplayData(handle(), outputId, state.options);\n  },\n\n  /**\n   * Reset persisted settings for an output to defaults.\n   *\n   * @param outputId - Output ID\n   */\n  resetData(outputId: number): void {\n    resetDisplayData(handle(), outputId, state.options);\n  },\n};\n\nexport default display;\n"],"mappings":";;;;;;;;;;;;;;AAqEA,MAAM,QAAe;CAAE,QAAQ;CAAM,SAAS,CAAC;AAAE;AAEjD,SAAS,SAAwB;CAC/B,IAAI,MAAM,WAAW,MACnB,OAAO,MAAM;CAEf,IAAI,CAAC,mBAAmB,MAAM,OAAO,GACnC,MAAM,IAAI,MAAM,kCAAkC;CAEpD,MAAM,SAAS,YAAY,MAAM,OAAO;CACxC,OAAO,MAAM;AACf;;;;;;AAOA,SAAgB,UAAU,SAAqC;CAC7D,IAAI,MAAM,WAAW,MACnB,aAAa,MAAM,QAAQ,MAAM,OAAO;CAE1C,MAAM,SAAS;CACf,MAAM,UAAU;AAClB;AAEA,MAAM,UAAU;;CAEd,YAAqB;EACnB,OAAO,mBAAmB,MAAM,OAAO;CACzC;;CAGA,QAAc;EACZ,IAAI,MAAM,WAAW,MACnB;EAEF,aAAa,MAAM,QAAQ,MAAM,OAAO;EACxC,MAAM,SAAS;CACjB;;CAGA,aAAkC;EAChC,OAAO,WAAW,OAAO,GAAG,MAAM,OAAO;CAC3C;;CAGA,aAAkC;EAChC,OAAO,WAAW,OAAO,GAAG,MAAM,OAAO;CAC3C;;;;;;;CAQA,eAAe,QAAmC;EAChD,OAAO,eAAe,OAAO,GAAG,QAAQ,MAAM,OAAO;CACvD;;;;;;CAOA,iBAAiB,YAA0B;EACzC,iBAAiB,OAAO,GAAG,YAAY,MAAM,OAAO;CACtD;;;;;;;CAQA,cAAc,YAAoB,YAA0B;EAC1D,cAAc,OAAO,GAAG,YAAY,YAAY,MAAM,OAAO;CAC/D;;;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