index.d.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. declare type FontItemType = {
  2. text: string;
  3. top?: string | number;
  4. left?: string | number;
  5. fontColor?: string;
  6. fontSize?: string;
  7. fontStyle?: string;
  8. fontWeight?: string;
  9. lineHeight?: string;
  10. };
  11. declare type FontExtendType = {
  12. wordWrap?: boolean;
  13. lengthLimit?: string | number;
  14. lineClamp?: number;
  15. };
  16. declare type ImgType = HTMLImageElement | HTMLCanvasElement;
  17. declare type ImgItemType = {
  18. src: string;
  19. top?: string | number;
  20. left?: string | number;
  21. width?: string;
  22. height?: string;
  23. formatter?: (img: ImgType) => ImgType;
  24. $resolve?: Function;
  25. $reject?: Function;
  26. };
  27. declare type BorderRadiusType = string | number;
  28. declare type BackgroundType = string;
  29. declare type ShadowType = string;
  30. declare type ConfigType = {
  31. nodeType?: number;
  32. flag: 'WEB' | 'MP-WX' | 'UNI-H5' | 'UNI-MP' | 'TARO-H5' | 'TARO-MP';
  33. el?: string;
  34. divElement?: HTMLDivElement;
  35. canvasElement?: HTMLCanvasElement;
  36. ctx: CanvasRenderingContext2D;
  37. dpr: number;
  38. handleCssUnit?: (num: number, unit: string) => number;
  39. rAF?: Function;
  40. setTimeout: Function;
  41. setInterval: Function;
  42. clearTimeout: Function;
  43. clearInterval: Function;
  44. beforeCreate?: Function;
  45. beforeResize?: Function;
  46. afterResize?: Function;
  47. beforeInit?: Function;
  48. afterInit?: Function;
  49. beforeDraw?: Function;
  50. afterDraw?: Function;
  51. afterStart?: Function;
  52. };
  53. declare type RequireKey = 'width' | 'height';
  54. declare type UserConfigType = Partial<Omit<ConfigType, RequireKey>> & Required<Pick<ConfigType, RequireKey>>;
  55. declare type Tuple<T, Len extends number, Res extends T[] = []> = Res['length'] extends Len ? Res : Tuple<T, Len, [...Res, T]>;
  56. interface WatchOptType {
  57. handler?: () => Function;
  58. immediate?: boolean;
  59. deep?: boolean;
  60. }
  61. declare class Lucky {
  62. static version: string;
  63. protected readonly version: string;
  64. protected readonly config: ConfigType;
  65. protected readonly ctx: CanvasRenderingContext2D;
  66. protected htmlFontSize: number;
  67. protected rAF: Function;
  68. protected boxWidth: number;
  69. protected boxHeight: number;
  70. protected data: {
  71. width: string | number;
  72. height: string | number;
  73. };
  74. /**
  75. * 公共构造器
  76. * @param config
  77. */
  78. constructor(config: string | HTMLDivElement | UserConfigType, data: {
  79. width: string | number;
  80. height: string | number;
  81. });
  82. /**
  83. * 初始化组件大小/单位
  84. */
  85. protected resize(): void;
  86. /**
  87. * 初始化方法
  88. */
  89. protected initLucky(): void;
  90. /**
  91. * 鼠标点击事件
  92. * @param e 事件参数
  93. */
  94. protected handleClick(e: MouseEvent): void;
  95. /**
  96. * 根标签的字体大小
  97. */
  98. protected setHTMLFontSize(): void;
  99. clearCanvas(): void;
  100. /**
  101. * 设备像素比
  102. * window 环境下自动获取, 其余环境手动传入
  103. */
  104. protected setDpr(): void;
  105. /**
  106. * 重置盒子和canvas的宽高
  107. */
  108. private resetWidthAndHeight;
  109. /**
  110. * 根据 dpr 缩放 canvas 并处理位移
  111. */
  112. protected zoomCanvas(): void;
  113. /**
  114. * 从 window 对象上获取一些方法
  115. */
  116. private initWindowFunction;
  117. isWeb(): boolean;
  118. /**
  119. * 异步加载图片并返回图片的几何信息
  120. * @param src 图片路径
  121. * @param info 图片信息
  122. */
  123. protected loadImg(src: string, info: ImgItemType, resolveName?: string): Promise<ImgType>;
  124. /**
  125. * 公共绘制图片的方法
  126. * @param imgObj 图片对象
  127. * @param rectInfo: [x轴位置, y轴位置, 渲染宽度, 渲染高度]
  128. */
  129. protected drawImage(ctx: CanvasRenderingContext2D, imgObj: ImgType, ...rectInfo: [...Tuple<number, 4>, ...Partial<Tuple<number, 4>>]): void;
  130. /**
  131. * 计算图片的渲染宽高
  132. * @param imgObj 图片标签元素
  133. * @param imgInfo 图片信息
  134. * @param maxWidth 最大宽度
  135. * @param maxHeight 最大高度
  136. * @return [渲染宽度, 渲染高度]
  137. */
  138. protected computedWidthAndHeight(imgObj: ImgType, imgInfo: ImgItemType, maxWidth: number, maxHeight: number): [number, number];
  139. /**
  140. * 转换单位
  141. * @param { string } value 将要转换的值
  142. * @param { number } denominator 分子
  143. * @return { number } 返回新的字符串
  144. */
  145. protected changeUnits(value: string, denominator?: number): number;
  146. /**
  147. * 获取长度
  148. * @param length 将要转换的长度
  149. * @param maxLength 最大长度
  150. * @return 返回长度
  151. */
  152. protected getLength(length: string | number | undefined, maxLength?: number): number;
  153. /**
  154. * 获取相对(居中)X坐标
  155. * @param width
  156. * @param col
  157. */
  158. protected getOffsetX(width: number, maxWidth?: number): number;
  159. protected getOffscreenCanvas(width: number, height: number): {
  160. _offscreenCanvas: HTMLCanvasElement;
  161. _ctx: CanvasRenderingContext2D;
  162. } | void;
  163. /**
  164. * 添加一个新的响应式数据 (临时)
  165. * @param data 数据
  166. * @param key 属性
  167. * @param value 新值
  168. */
  169. $set(data: object, key: string | number, value: any): void;
  170. /**
  171. * 添加一个属性计算 (临时)
  172. * @param data 源数据
  173. * @param key 属性名
  174. * @param callback 回调函数
  175. */
  176. protected $computed(data: object, key: string, callback: Function): void;
  177. /**
  178. * 添加一个观察者 create user watcher
  179. * @param expr 表达式
  180. * @param handler 回调函数
  181. * @param watchOpt 配置参数
  182. * @return 卸载当前观察者的函数 (暂未返回)
  183. */
  184. protected $watch(expr: string | Function, handler: Function | WatchOptType, watchOpt?: WatchOptType): Function;
  185. }
  186. declare type PrizeFontType$2 = FontItemType & FontExtendType;
  187. declare type ButtonFontType$1 = FontItemType & {};
  188. declare type BlockImgType$2 = ImgItemType & {
  189. rotate?: boolean;
  190. };
  191. declare type PrizeImgType$2 = ImgItemType & {};
  192. declare type ButtonImgType$1 = ImgItemType & {};
  193. declare type BlockType$2 = {
  194. padding?: string;
  195. background?: BackgroundType;
  196. imgs?: Array<BlockImgType$2>;
  197. };
  198. declare type PrizeType$2 = {
  199. range?: number;
  200. background?: BackgroundType;
  201. fonts?: Array<PrizeFontType$2>;
  202. imgs?: Array<PrizeImgType$2>;
  203. };
  204. declare type ButtonType$1 = {
  205. radius?: string;
  206. pointer?: boolean;
  207. background?: BackgroundType;
  208. fonts?: Array<ButtonFontType$1>;
  209. imgs?: Array<ButtonImgType$1>;
  210. };
  211. declare type DefaultConfigType$2 = {
  212. gutter?: string | number;
  213. offsetDegree?: number;
  214. speed?: number;
  215. speedFunction?: string;
  216. accelerationTime?: number;
  217. decelerationTime?: number;
  218. stopRange?: number;
  219. };
  220. declare type DefaultStyleType$2 = {
  221. background?: BackgroundType;
  222. fontColor?: PrizeFontType$2['fontColor'];
  223. fontSize?: PrizeFontType$2['fontSize'];
  224. fontStyle?: PrizeFontType$2['fontStyle'];
  225. fontWeight?: PrizeFontType$2['fontWeight'];
  226. lineHeight?: PrizeFontType$2['lineHeight'];
  227. wordWrap?: PrizeFontType$2['wordWrap'];
  228. lengthLimit?: PrizeFontType$2['lengthLimit'];
  229. lineClamp?: PrizeFontType$2['lineClamp'];
  230. };
  231. declare type StartCallbackType$1 = (e: MouseEvent) => void;
  232. declare type EndCallbackType$2 = (prize: object) => void;
  233. interface LuckyWheelConfig {
  234. width: string | number;
  235. height: string | number;
  236. blocks?: Array<BlockType$2>;
  237. prizes?: Array<PrizeType$2>;
  238. buttons?: Array<ButtonType$1>;
  239. defaultConfig?: DefaultConfigType$2;
  240. defaultStyle?: DefaultStyleType$2;
  241. start?: StartCallbackType$1;
  242. end?: EndCallbackType$2;
  243. }
  244. declare class LuckyWheel extends Lucky {
  245. private blocks;
  246. private prizes;
  247. private buttons;
  248. private defaultConfig;
  249. private defaultStyle;
  250. private _defaultConfig;
  251. private _defaultStyle;
  252. private startCallback?;
  253. private endCallback?;
  254. private Radius;
  255. private prizeRadius;
  256. private prizeDeg;
  257. private prizeAng;
  258. private rotateDeg;
  259. private maxBtnRadius;
  260. private startTime;
  261. private endTime;
  262. private stopDeg;
  263. private endDeg;
  264. private FPS;
  265. /**
  266. * 游戏当前的阶段
  267. * step = 0 时, 游戏尚未开始
  268. * step = 1 时, 此时处于加速阶段
  269. * step = 2 时, 此时处于匀速阶段
  270. * step = 3 时, 此时处于减速阶段
  271. */
  272. private step;
  273. /**
  274. * 中奖索引
  275. * prizeFlag = undefined 时, 处于开始抽奖阶段, 正常旋转
  276. * prizeFlag >= 0 时, 说明stop方法被调用, 并且传入了中奖索引
  277. * prizeFlag === -1 时, 说明stop方法被调用, 并且传入了负值, 本次抽奖无效
  278. */
  279. private prizeFlag;
  280. private ImageCache;
  281. /**
  282. * 大转盘构造器
  283. * @param config 配置项
  284. * @param data 抽奖数据
  285. */
  286. constructor(config: UserConfigType, data: LuckyWheelConfig);
  287. protected resize(): void;
  288. protected initLucky(): void;
  289. /**
  290. * 初始化数据
  291. * @param data
  292. */
  293. private initData;
  294. /**
  295. * 初始化属性计算
  296. */
  297. private initComputed;
  298. /**
  299. * 初始化观察者
  300. */
  301. private initWatch;
  302. /**
  303. * 初始化 canvas 抽奖
  304. */
  305. init(): Promise<void>;
  306. private initImageCache;
  307. /**
  308. * canvas点击事件
  309. * @param e 事件参数
  310. */
  311. protected handleClick(e: MouseEvent): void;
  312. /**
  313. * 根据索引单独加载指定图片并缓存
  314. * @param cellName 模块名称
  315. * @param cellIndex 模块索引
  316. * @param imgName 模块对应的图片缓存
  317. * @param imgIndex 图片索引
  318. */
  319. private loadAndCacheImg;
  320. private drawBlock;
  321. /**
  322. * 开始绘制
  323. */
  324. protected draw(): void;
  325. /**
  326. * 刻舟求剑
  327. */
  328. private carveOnGunwaleOfAMovingBoat;
  329. /**
  330. * 对外暴露: 开始抽奖方法
  331. */
  332. play(): void;
  333. /**
  334. * 对外暴露: 缓慢停止方法
  335. * @param index 中奖索引
  336. */
  337. stop(index?: number): void;
  338. /**
  339. * 实际开始执行方法
  340. * @param num 记录帧动画执行多少次
  341. */
  342. private run;
  343. /**
  344. * 换算渲染坐标
  345. * @param x
  346. * @param y
  347. */
  348. protected conversionAxis(x: number, y: number): [number, number];
  349. }
  350. declare type PrizeFontType$1 = FontItemType & FontExtendType;
  351. declare type ButtonFontType = FontItemType & FontExtendType;
  352. declare type BlockImgType$1 = ImgItemType & {};
  353. declare type PrizeImgType$1 = ImgItemType & {
  354. activeSrc?: string;
  355. };
  356. declare type ButtonImgType = ImgItemType & {};
  357. declare type BlockType$1 = {
  358. borderRadius?: BorderRadiusType;
  359. background?: BackgroundType;
  360. padding?: string;
  361. paddingTop?: string | number;
  362. paddingRight?: string | number;
  363. paddingBottom?: string | number;
  364. paddingLeft?: string | number;
  365. imgs?: Array<BlockImgType$1>;
  366. };
  367. declare type CellType<T, U> = {
  368. x: number;
  369. y: number;
  370. col?: number;
  371. row?: number;
  372. borderRadius?: BorderRadiusType;
  373. background?: BackgroundType;
  374. shadow?: ShadowType;
  375. fonts?: Array<T>;
  376. imgs?: Array<U>;
  377. };
  378. declare type PrizeType$1 = CellType<PrizeFontType$1, PrizeImgType$1> & {
  379. range?: number;
  380. disabled?: boolean;
  381. };
  382. declare type ButtonType = CellType<ButtonFontType, ButtonImgType> & {
  383. callback?: Function;
  384. };
  385. declare type DefaultConfigType$1 = {
  386. gutter?: number;
  387. speed?: number;
  388. accelerationTime?: number;
  389. decelerationTime?: number;
  390. };
  391. declare type DefaultStyleType$1 = {
  392. borderRadius?: BorderRadiusType;
  393. background?: BackgroundType;
  394. shadow?: ShadowType;
  395. fontColor?: PrizeFontType$1['fontColor'];
  396. fontSize?: PrizeFontType$1['fontSize'];
  397. fontStyle?: PrizeFontType$1['fontStyle'];
  398. fontWeight?: PrizeFontType$1['fontWeight'];
  399. lineHeight?: PrizeFontType$1['lineHeight'];
  400. wordWrap?: PrizeFontType$1['wordWrap'];
  401. lengthLimit?: PrizeFontType$1['lengthLimit'];
  402. lineClamp?: PrizeFontType$1['lineClamp'];
  403. };
  404. declare type ActiveStyleType = {
  405. background?: BackgroundType;
  406. shadow?: ShadowType;
  407. fontColor?: PrizeFontType$1['fontColor'];
  408. fontSize?: PrizeFontType$1['fontSize'];
  409. fontStyle?: PrizeFontType$1['fontStyle'];
  410. fontWeight?: PrizeFontType$1['fontWeight'];
  411. lineHeight?: PrizeFontType$1['lineHeight'];
  412. };
  413. declare type RowsType = number;
  414. declare type ColsType = number;
  415. declare type StartCallbackType = (e: MouseEvent, button?: ButtonType) => void;
  416. declare type EndCallbackType$1 = (prize: object) => void;
  417. interface LuckyGridConfig {
  418. width: string | number;
  419. height: string | number;
  420. rows?: RowsType;
  421. cols?: ColsType;
  422. blocks?: Array<BlockType$1>;
  423. prizes?: Array<PrizeType$1>;
  424. buttons?: Array<ButtonType>;
  425. button?: ButtonType;
  426. defaultConfig?: DefaultConfigType$1;
  427. defaultStyle?: DefaultStyleType$1;
  428. activeStyle?: ActiveStyleType;
  429. start?: StartCallbackType;
  430. end?: EndCallbackType$1;
  431. }
  432. declare class LuckyGrid extends Lucky {
  433. private rows;
  434. private cols;
  435. private blocks;
  436. private prizes;
  437. private buttons;
  438. private button?;
  439. private defaultConfig;
  440. private defaultStyle;
  441. private activeStyle;
  442. private _defaultConfig;
  443. private _defaultStyle;
  444. private _activeStyle;
  445. private startCallback?;
  446. private endCallback?;
  447. private cellWidth;
  448. private cellHeight;
  449. private startTime;
  450. private endTime;
  451. private currIndex;
  452. private stopIndex;
  453. private endIndex;
  454. private demo;
  455. private timer;
  456. private FPS;
  457. /**
  458. * 游戏当前的阶段
  459. * step = 0 时, 游戏尚未开始
  460. * step = 1 时, 此时处于加速阶段
  461. * step = 2 时, 此时处于匀速阶段
  462. * step = 3 时, 此时处于减速阶段
  463. */
  464. private step;
  465. /**
  466. * 中奖索引
  467. * prizeFlag = undefined 时, 处于开始抽奖阶段, 正常旋转
  468. * prizeFlag >= 0 时, 说明stop方法被调用, 并且传入了中奖索引
  469. * prizeFlag === -1 时, 说明stop方法被调用, 并且传入了负值, 本次抽奖无效
  470. */
  471. private prizeFlag;
  472. private cells;
  473. private prizeArea;
  474. private ImageCache;
  475. /**
  476. * 九宫格构造器
  477. * @param config 配置项
  478. * @param data 抽奖数据
  479. */
  480. constructor(config: UserConfigType, data: LuckyGridConfig);
  481. protected resize(): void;
  482. protected initLucky(): void;
  483. /**
  484. * 初始化数据
  485. * @param data
  486. */
  487. private initData;
  488. /**
  489. * 初始化属性计算
  490. */
  491. private initComputed;
  492. /**
  493. * 初始化观察者
  494. */
  495. private initWatch;
  496. /**
  497. * 初始化 canvas 抽奖
  498. */
  499. init(): Promise<void>;
  500. private initImageCache;
  501. /**
  502. * canvas点击事件
  503. * @param e 事件参数
  504. */
  505. protected handleClick(e: MouseEvent): void;
  506. /**
  507. * 根据索引单独加载指定图片并缓存
  508. * @param cellName 模块名称
  509. * @param cellIndex 模块索引
  510. * @param imgName 模块对应的图片缓存
  511. * @param imgIndex 图片索引
  512. */
  513. private loadAndCacheImg;
  514. /**
  515. * 绘制九宫格抽奖
  516. */
  517. protected draw(): void;
  518. /**
  519. * 处理背景色
  520. * @param x
  521. * @param y
  522. * @param width
  523. * @param height
  524. * @param background
  525. * @param isActive
  526. */
  527. private handleBackground;
  528. /**
  529. * 刻舟求剑
  530. */
  531. private carveOnGunwaleOfAMovingBoat;
  532. /**
  533. * 对外暴露: 开始抽奖方法
  534. */
  535. play(): void;
  536. /**
  537. * 对外暴露: 缓慢停止方法
  538. * @param index 中奖索引
  539. */
  540. stop(index?: number): void;
  541. /**
  542. * 实际开始执行方法
  543. * @param num 记录帧动画执行多少次
  544. */
  545. private run;
  546. /**
  547. * 计算奖品格子的几何属性
  548. * @param { array } [...矩阵坐标, col, row]
  549. * @return { array } [...真实坐标, width, height]
  550. */
  551. private getGeometricProperty;
  552. /**
  553. * 换算渲染坐标
  554. * @param x
  555. * @param y
  556. */
  557. protected conversionAxis(x: number, y: number): [number, number];
  558. }
  559. declare type PrizeFontType = FontItemType & FontExtendType;
  560. declare type BlockImgType = ImgItemType & {};
  561. declare type PrizeImgType = ImgItemType;
  562. declare type BlockType = {
  563. borderRadius?: BorderRadiusType;
  564. background?: BackgroundType;
  565. padding?: string;
  566. paddingTop?: string | number;
  567. paddingRight?: string | number;
  568. paddingBottom?: string | number;
  569. paddingLeft?: string | number;
  570. imgs?: Array<BlockImgType>;
  571. };
  572. declare type PrizeType = {
  573. borderRadius?: BorderRadiusType;
  574. background?: BackgroundType;
  575. fonts?: Array<PrizeFontType>;
  576. imgs?: Array<PrizeImgType>;
  577. };
  578. declare type SlotType = {
  579. order?: number[];
  580. speed?: number;
  581. direction?: 1 | -1;
  582. };
  583. declare type DefaultConfigType = {
  584. /**
  585. * vertical 为纵向旋转
  586. * horizontal 为横向旋转
  587. */
  588. mode?: 'vertical' | 'horizontal';
  589. /**
  590. * 当排列方向 = `vertical`时
  591. * 1 bottom to top
  592. * -1 top to bottom
  593. * 当排列方向 = `horizontal`时
  594. * 1 right to left
  595. * -1 left to right
  596. */
  597. direction?: 1 | -1;
  598. rowSpacing?: number;
  599. colSpacing?: number;
  600. speed?: number;
  601. accelerationTime?: number;
  602. decelerationTime?: number;
  603. };
  604. declare type DefaultStyleType = {
  605. borderRadius?: BorderRadiusType;
  606. background?: BackgroundType;
  607. fontColor?: PrizeFontType['fontColor'];
  608. fontSize?: PrizeFontType['fontSize'];
  609. fontStyle?: PrizeFontType['fontStyle'];
  610. fontWeight?: PrizeFontType['fontWeight'];
  611. lineHeight?: PrizeFontType['lineHeight'];
  612. wordWrap?: PrizeFontType['wordWrap'];
  613. lengthLimit?: PrizeFontType['lengthLimit'];
  614. lineClamp?: PrizeFontType['lineClamp'];
  615. };
  616. declare type EndCallbackType = (prize: PrizeType | undefined) => void;
  617. interface SlotMachineConfig {
  618. width: string | number;
  619. height: string | number;
  620. blocks?: Array<BlockType>;
  621. prizes?: Array<PrizeType>;
  622. slots?: Array<SlotType>;
  623. defaultConfig?: DefaultConfigType;
  624. defaultStyle?: DefaultStyleType;
  625. end?: EndCallbackType;
  626. }
  627. declare class SlotMachine extends Lucky {
  628. private blocks;
  629. private prizes;
  630. private slots;
  631. private defaultConfig;
  632. private _defaultConfig;
  633. private defaultStyle;
  634. private _defaultStyle;
  635. private endCallback;
  636. private _offscreenCanvas?;
  637. private cellWidth;
  638. private cellHeight;
  639. private cellAndSpacing;
  640. private widthAndSpacing;
  641. private heightAndSpacing;
  642. private FPS;
  643. private scroll;
  644. private stopScroll;
  645. private endScroll;
  646. private startTime;
  647. private endTime;
  648. /**
  649. * 游戏当前的阶段
  650. * step = 0 时, 游戏尚未开始
  651. * step = 1 时, 此时处于加速阶段
  652. * step = 2 时, 此时处于匀速阶段
  653. * step = 3 时, 此时处于减速阶段
  654. */
  655. private step;
  656. /**
  657. * 中奖索引
  658. * prizeFlag = undefined 时, 处于开始抽奖阶段, 正常旋转
  659. * prizeFlag >= 0 时, 说明stop方法被调用, 并且传入了中奖索引
  660. * prizeFlag === -1 时, 说明stop方法被调用, 并且传入了负值, 本次抽奖无效
  661. */
  662. private prizeFlag;
  663. private prizeArea?;
  664. private ImageCache;
  665. /**
  666. * 老虎机构造器
  667. * @param config 配置项
  668. * @param data 抽奖数据
  669. */
  670. constructor(config: UserConfigType, data: SlotMachineConfig);
  671. protected resize(): void;
  672. protected initLucky(): void;
  673. /**
  674. * 初始化数据
  675. * @param data
  676. */
  677. private initData;
  678. /**
  679. * 初始化属性计算
  680. */
  681. private initComputed;
  682. /**
  683. * 初始化观察者
  684. */
  685. private initWatch;
  686. /**
  687. * 初始化 canvas 抽奖
  688. */
  689. init(): Promise<void>;
  690. private initImageCache;
  691. /**
  692. * 根据索引单独加载指定图片并缓存
  693. * @param cellName 模块名称
  694. * @param cellIndex 模块索引
  695. * @param imgName 模块对应的图片缓存
  696. * @param imgIndex 图片索引
  697. */
  698. private loadAndCacheImg;
  699. /**
  700. * 绘制离屏canvas
  701. */
  702. protected drawOffscreenCanvas(): void;
  703. /**
  704. * 绘制背景区域
  705. */
  706. protected drawBlocks(): SlotMachine['prizeArea'];
  707. /**
  708. * 绘制老虎机抽奖
  709. */
  710. protected draw(): void;
  711. /**
  712. * 刻舟求剑
  713. */
  714. private carveOnGunwaleOfAMovingBoat;
  715. /**
  716. * 对外暴露: 开始抽奖方法
  717. */
  718. play(): void;
  719. stop(index: number | number[]): void;
  720. /**
  721. * 让游戏动起来
  722. * @param num 记录帧动画执行多少次
  723. */
  724. private run;
  725. private displacement;
  726. private displacementWidthOrHeight;
  727. }
  728. /**
  729. * 切割圆角
  730. * @param img 将要裁剪的图片对象
  731. * @param radius 裁剪的圆角半径
  732. * @returns 返回一个离屏 canvas 用于渲染
  733. */
  734. declare const cutRound: (img: ImgType, radius: number) => ImgType;
  735. /**
  736. * 透明度
  737. * @param img 将要处理的图片对象
  738. * @param opacity 透明度
  739. * @returns 返回一个离屏 canvas 用于渲染
  740. */
  741. declare const opacity: (img: ImgType, opacity: number) => ImgType;
  742. export { LuckyGrid, LuckyWheel, SlotMachine, cutRound, opacity };