import { Machine, EventObject, Service } from '@zag-js/core'; import { DataUrlType } from '@zag-js/dom-query'; import { PropTypes, RequiredBy, DirectionProperty, CommonProperties } from '@zag-js/types'; import { QrCodeGenerateOptions, QrCodeGenerateResult } from 'uqr'; export { QrCodeGenerateOptions, QrCodeGenerateResult } from 'uqr'; interface ValueChangeDetails { value: string; } type ElementIds = Partial<{ root: string; frame: string; }>; interface QrCodeProps extends DirectionProperty, CommonProperties { /** * The controlled value to encode. */ value?: string | undefined; /** * The initial value to encode when rendered. * Use when you don't need to control the value of the qr code. */ defaultValue?: string | undefined; /** * The element ids. */ ids?: ElementIds | undefined; /** * The qr code encoding options. */ encoding?: QrCodeGenerateOptions | undefined; /** * Callback fired when the value changes. */ onValueChange?: ((details: ValueChangeDetails) => void) | undefined; /** * The pixel size of the qr code. */ pixelSize?: number | undefined; } type PropsWithDefault = "pixelSize" | "defaultValue"; type Computed = Readonly<{ encoded: QrCodeGenerateResult; }>; interface QrCodeSchema { props: RequiredBy; context: { value: string; }; computed: Computed; state: "idle"; event: EventObject; action: string; effect: string; guard: string; } type QrCodeService = Service; type QrCodeMachine = Machine; interface DownloadTriggerProps { /** * The mime type of the image. */ mimeType: DataUrlType; /** * The quality of the image. */ quality?: number | undefined; /** * The name of the file. */ fileName: string; } interface QrCodeApi { /** * The value to encode. */ value: string; /** * Set the value to encode. */ setValue: (value: string) => void; /** * Returns the data URL of the qr code. */ getDataUrl: (type: DataUrlType, quality?: number) => Promise; getRootProps: () => T["element"]; getFrameProps: () => T["svg"]; getPatternProps: () => T["path"]; getOverlayProps: () => T["element"]; getDownloadTriggerProps: (props: DownloadTriggerProps) => T["button"]; } export type { DownloadTriggerProps, ElementIds, QrCodeApi, QrCodeMachine, QrCodeProps, QrCodeSchema, QrCodeService, ValueChangeDetails };