interface.d.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import type React from 'react';
  2. import type { Ecc, QrCode } from './libs/qrcodegen';
  3. export type Modules = ReturnType<QrCode['getModules']>;
  4. export type Excavation = {
  5. x: number;
  6. y: number;
  7. w: number;
  8. h: number;
  9. };
  10. export type ErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H';
  11. export type CrossOrigin = 'anonymous' | 'use-credentials' | '' | undefined;
  12. export type ERROR_LEVEL_MAPPED_TYPE = {
  13. [index in ErrorCorrectionLevel]: Ecc;
  14. };
  15. export type ImageSettings = {
  16. /**
  17. * The URI of the embedded image.
  18. */
  19. src: string;
  20. /**
  21. * The height, in pixels, of the image.
  22. */
  23. height: number;
  24. /**
  25. * The width, in pixels, of the image.
  26. */
  27. width: number;
  28. /**
  29. * Whether or not to "excavate" the modules around the embedded image. This
  30. * means that any modules the embedded image overlaps will use the background
  31. * color.
  32. */
  33. excavate: boolean;
  34. /**
  35. * The horiztonal offset of the embedded image, starting from the top left corner.
  36. * Will center if not specified.
  37. */
  38. x?: number;
  39. /**
  40. * The vertical offset of the embedded image, starting from the top left corner.
  41. * Will center if not specified.
  42. */
  43. y?: number;
  44. /**
  45. * The opacity of the embedded image in the range of 0-1.
  46. * @defaultValue 1
  47. */
  48. opacity?: number;
  49. /**
  50. * The cross-origin value to use when loading the image. This is used to
  51. * ensure compatibility with CORS, particularly when extracting image data
  52. * from QRCodeCanvas.
  53. * Note: `undefined` is treated differently than the seemingly equivalent
  54. * empty string. This is intended to align with HTML behavior where omitting
  55. * the attribute behaves differently than the empty string.
  56. */
  57. crossOrigin?: CrossOrigin;
  58. };
  59. export type QRProps = {
  60. /**
  61. * The value to encode into the QR Code. An array of strings can be passed in
  62. * to represent multiple segments to further optimize the QR Code.
  63. */
  64. value: string;
  65. /**
  66. * The size, in pixels, to render the QR Code.
  67. * @defaultValue 128
  68. */
  69. size?: number;
  70. /**
  71. * The Error Correction Level to use.
  72. * @see https://www.qrcode.com/en/about/error_correction.html
  73. * @defaultValue L
  74. */
  75. level?: ErrorCorrectionLevel;
  76. /**
  77. * The background color used to render the QR Code.
  78. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
  79. * @defaultValue #FFFFFF
  80. */
  81. bgColor?: string;
  82. /**
  83. * The foregtound color used to render the QR Code.
  84. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
  85. * @defaultValue #000000
  86. */
  87. fgColor?: string;
  88. /**
  89. * The style to apply to the QR Code.
  90. */
  91. style?: React.CSSProperties;
  92. /**
  93. * Whether or not a margin of 4 modules should be rendered as a part of the
  94. * QR Code.
  95. * @deprecated Use `marginSize` instead.
  96. * @defaultValue false
  97. */
  98. includeMargin?: boolean;
  99. /**
  100. * The number of _modules_ to use for margin. The QR Code specification
  101. * requires `4`, however you can specify any number. Values will be turned to
  102. * integers with `Math.floor`. Overrides `includeMargin` when both are specified.
  103. * @defaultValue 0
  104. */
  105. marginSize?: number;
  106. /**
  107. * The settings for the embedded image.
  108. */
  109. imageSettings?: ImageSettings;
  110. /**
  111. * The title to assign to the QR Code. Used for accessibility reasons.
  112. */
  113. title?: string;
  114. /**
  115. * The minimum version used when encoding the QR Code. Valid values are 1-40
  116. * with higher values resulting in more complex QR Codes. The optimal
  117. * (lowest) version is determined for the `value` provided, using `minVersion`
  118. * as the lower bound.
  119. * @defaultValue 1
  120. */
  121. minVersion?: number;
  122. };
  123. export type QRPropsCanvas = QRProps & React.CanvasHTMLAttributes<HTMLCanvasElement>;
  124. export type QRPropsSVG = QRProps & React.SVGAttributes<SVGSVGElement>;