1
0

awesome-qr.d.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /// <reference types="miniprogram-api-typings" />
  2. import { canvasContainer } from "../type";
  3. export declare type ComponentOptions = {
  4. /**
  5. * Component options for data/ECC.
  6. */
  7. data?: {
  8. /**
  9. * Scale factor for data/ECC dots.
  10. * @default 1
  11. */
  12. scale?: number;
  13. };
  14. /**
  15. * Component options for timing patterns.
  16. */
  17. timing?: {
  18. /**
  19. * Scale factor for timing patterns.
  20. * @default 1
  21. */
  22. scale?: number;
  23. /**
  24. * Protector for timing patterns.
  25. * @default false
  26. */
  27. protectors?: boolean;
  28. };
  29. /**
  30. * Component options for alignment patterns.
  31. */
  32. alignment?: {
  33. /**
  34. * Scale factor for alignment patterns.
  35. * @default 1
  36. */
  37. scale?: number;
  38. /**
  39. * Protector for alignment patterns.
  40. * @default false
  41. */
  42. protectors?: boolean;
  43. };
  44. /**
  45. * Component options for alignment pattern on the bottom-right corner.
  46. */
  47. cornerAlignment?: {
  48. /**
  49. * Scale factor for alignment pattern on the bottom-right corner.
  50. * @default 1
  51. */
  52. scale?: number;
  53. /**
  54. * Protector for alignment pattern on the bottom-right corner.
  55. * @default true
  56. */
  57. protectors?: boolean;
  58. };
  59. };
  60. export declare type Options = {
  61. /**
  62. * Text to be encoded in the QR code.
  63. */
  64. text: string;
  65. /**
  66. * Size of the QR code in pixel.
  67. *
  68. * @defaultValue 400
  69. */
  70. size?: number;
  71. /**
  72. * Size of margins around the QR code body in pixel.
  73. *
  74. * @defaultValue 20
  75. */
  76. margin?: number;
  77. /**
  78. * Error correction level of the QR code.
  79. *
  80. * Accepts a value provided by _QRErrorCorrectLevel_.
  81. *
  82. * For more information, please refer to [https://www.qrcode.com/en/about/error_correction.html](https://www.qrcode.com/en/about/error_correction.html).
  83. *
  84. * @defaultValue 0
  85. */
  86. correctLevel?: number;
  87. /**
  88. * **This is an advanced option.**
  89. *
  90. * Specify the mask pattern to be used in QR code encoding.
  91. *
  92. * Accepts a value provided by _QRMaskPattern_.
  93. *
  94. * To find out all eight mask patterns, please refer to [https://en.wikipedia.org/wiki/File:QR_Code_Mask_Patterns.svg](https://en.wikipedia.org/wiki/File:QR_Code_Mask_Patterns.svg)
  95. *
  96. * For more information, please refer to [https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Masking](https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Masking).
  97. */
  98. maskPattern?: number;
  99. /**
  100. * **This is an advanced option.**
  101. *
  102. * Specify the version to be used in QR code encoding.
  103. *
  104. * Accepts an integer in range [1, 40].
  105. *
  106. * For more information, please refer to [https://www.qrcode.com/en/about/version.html](https://www.qrcode.com/en/about/version.html).
  107. */
  108. version?: number;
  109. /**
  110. * Options to control components in the QR code.
  111. *
  112. * @deafultValue undefined
  113. */
  114. components?: ComponentOptions;
  115. /**
  116. * Color of the blocks on the QR code.
  117. *
  118. * Accepts a CSS &lt;color&gt;.
  119. *
  120. * For more information about CSS &lt;color&gt;, please refer to [https://developer.mozilla.org/en-US/docs/Web/CSS/color_value](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
  121. *
  122. * @defaultValue "#000000"
  123. */
  124. colorDark?: string;
  125. /**
  126. * Color of the empty areas on the QR code.
  127. *
  128. * Accepts a CSS &lt;color&gt;.
  129. *
  130. * For more information about CSS &lt;color&gt;, please refer to [https://developer.mozilla.org/en-US/docs/Web/CSS/color_value](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
  131. *
  132. * @defaultValue "#ffffff"
  133. */
  134. colorLight?: string;
  135. /**
  136. * Automatically calculate the _colorLight_ value from the QR code's background.
  137. *
  138. * @defaultValue true
  139. */
  140. autoColor?: boolean;
  141. /**
  142. * Background image to be used in the QR code.
  143. *
  144. * Accepts a `data:` string in web browsers or a Buffer in Node.js.
  145. *
  146. * @defaultValue undefined
  147. */
  148. backgroundImage?: string;
  149. /**
  150. * Color of the dimming mask above the background image.
  151. *
  152. * Accepts a CSS &lt;color&gt;.
  153. *
  154. * For more information about CSS &lt;color&gt;, please refer to [https://developer.mozilla.org/en-US/docs/Web/CSS/color_value](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
  155. *
  156. * @defaultValue "rgba(0, 0, 0, 0)"
  157. */
  158. backgroundDimming?: string;
  159. /**
  160. * Use a white margin instead of a transparent one which reveals the background of the QR code on margins.
  161. *
  162. * @defaultValue true
  163. */
  164. whiteMargin?: boolean;
  165. /**
  166. * Logo image to be displayed at the center of the QR code.
  167. *
  168. * Accepts a `data:` string in web browsers or a Buffer in Node.js.
  169. *
  170. * When set to `undefined` or `null`, the logo is disabled.
  171. *
  172. * @defaultValue undefined
  173. */
  174. logoImage?: string;
  175. /**
  176. * Ratio of the logo size to the QR code size.
  177. *
  178. * @defaultValue 0.2
  179. */
  180. logoScale?: number;
  181. /**
  182. * Size of margins around the logo image in pixels.
  183. *
  184. * @defaultValue 6
  185. */
  186. logoMargin?: number;
  187. /**
  188. * Corner radius of the logo image in pixels.
  189. *
  190. * @defaultValue 8
  191. */
  192. logoCornerRadius?: number;
  193. /**
  194. * @deprecated
  195. *
  196. * Ratio of the real size to the full size of the blocks.
  197. *
  198. * This can be helpful when you want to make more parts of the background visible.
  199. *
  200. * @deafultValue 0.4
  201. */
  202. dotScale?: number;
  203. /**
  204. *
  205. * 由于微信不能直接通过createElement生成canvas,目前通过传参形式进行
  206. *
  207. */
  208. canvasContainer?: Record<canvasContainer, WechatMiniprogram.Canvas>;
  209. };
  210. export declare class AwesomeQR {
  211. private canvas;
  212. private canvasContext;
  213. private qrCode?;
  214. private options;
  215. static CorrectLevel: {
  216. L: number;
  217. M: number;
  218. Q: number;
  219. H: number;
  220. };
  221. private static defaultComponentOptions;
  222. static defaultOptions: Options;
  223. constructor(options: Partial<Options>);
  224. draw(): Promise<string | undefined>;
  225. setOptions(options: Partial<Options>): Options;
  226. private _clear;
  227. private static _prepareRoundedCornerClip;
  228. private static _prepareRoundedCornerClipReverse;
  229. private static _getAverageRGB;
  230. private static _drawDot;
  231. private static _drawAlignProtector;
  232. private static _drawAlign;
  233. private _draw;
  234. getDataUrl(type?: string, encoderOptions?: number): string;
  235. }