import { expectType } from 'tsd' ; const canvas = wx . createCanvas ( ) ; const context = canvas . getContext ( '2d' ) ; context . fillStyle = '#1aad19' ; context . fillRect ( 0 , 0 , 100 , 100 ) ; context . fillRect ( canvas . width / 2 - 50 , 0 , 100 , 100 ) ; function drawRect ( x , y ) { context . clearRect ( x , y - 1 , 100 , 100 ) ; context . fillRect ( x , y , 100 , 100 ) ; } drawRect ( canvas . width / 2 - 50 , 0 ) ; const rectX = canvas . width / 2 - 50 ; let rectY = 0 ; setInterval ( function ( ) { drawRect ( rectX , rectY ++ ) ; } , 16 ) ; const image = wx . createImage ( ) ; const imgX = canvas . width / 2 - 50 ; const imgY = 500 ; image . onload = function ( ) { context . drawImage ( image , imgX , imgY ) ; } ; image . src = 'img/plane.png' ; let touchX = imgX ; let touchY = imgY ; wx . onTouchMove ( function ( res ) { context . clearRect ( touchX , touchY , 100 , 100 ) ; touchX = res . changedTouches [ 0 ] . clientX ; touchY = res . changedTouches [ 0 ] . clientY ; context . drawImage ( image , touchX , touchY ) ; if ( touchX >= rectX - 100 && touchX <= rectX + 100 && touchY >= rectY - 100 && touchY <= rectY + 100 ) { wx . showModal ( { title : '提示' , content : '发生碰撞，游戏结束！' , } ) ; } } ) ; function sayHello ( name ) { console . log ( `Hello ${ name } !` ) ; } function sayGoodbye ( name ) { console . log ( `Goodbye ${ name } !` ) ; } module . exports . sayHello = sayHello ; exports . sayGoodbye = sayGoodbye ; GameGlobal . globalData = 1 ; console . log ( GameGlobal . globalData ) ; const updateManager = wx . getUpdateManager ( ) ; updateManager . onCheckForUpdate ( function ( res ) { console . log ( res . hasUpdate ) ; } ) ; updateManager . onUpdateReady ( function ( ) { wx . showModal ( { title : '更新提示' , content : '新版本已经准备好，是否重启应用？' , success ( res ) { if ( res . confirm ) { updateManager . applyUpdate ( ) ; } } , } ) ; } ) ; updateManager . onUpdateFailed ( function ( ) { } ) ; const fs = wx . getFileSystemManager ( ) ; wx . chooseImage ( { success ( res ) { expectType < string [ ] > ( res . tempFilePaths ) ; } , } ) ; fs . saveFile ( { tempFilePath : '' , success ( res ) { console . log ( res . savedFilePath ) ; } , } ) ; fs . writeFileSync ( `${ wx . env . USER_DATA_PATH }/hello.txt` , 'hello, world' , 'utf8' ) ; const url = 'https://developers.weixin.qq.com' ; const audio = wx . createInnerAudioContext ( ) ; audio . src = url ; audio . play ( ) ; audio . obeyMuteSwitch = false ; const bgm = wx . createInnerAudioContext ( ) ; bgm . autoplay = true ; bgm . loop = true ; bgm . src = url ; wx . onShow ( function ( ) { bgm . play ( ) ; } ) ; wx . onAudioInterruptionEnd ( function ( ) { bgm . play ( ) ; } ) ; wx . onAudioInterruptionBegin ( function ( ) { } ) ; const src = 'http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400' ; const video = wx . createVideo ( { x : 10 , y : 76 , width : 300 , height : 200 , poster : '' , controls : true , src , } ) ; video . play ( ) ; video . pause ( ) ; video . seek ( 10 ) ; video . onTimeUpdate ( res => { expectType < number > ( res . position ) ; expectType < number > ( res . duration ) ; } ) ; video . onEnded ( ( ) => { console . log ( '视频播放完了' ) ; } ) ; { const callback = ( res ) => { expectType < number > ( res . position ) ; expectType < number > ( res . duration ) ; if ( res . position >= 3 ) { } } ; video . onTimeUpdate ( callback ) ; } video . onTimeUpdate ( res => { expectType < number > ( res . position ) ; expectType < number > ( res . duration ) ; } ) ; video . play ( ) ; video . destroy ( ) ; const loadTask = wx . loadSubpackage ( { name : 'stage1' , success ( ) { } , fail ( ) { } , complete ( ) { } , } ) ; loadTask . onProgressUpdate ( res => { expectType < number > ( res . progress ) ; expectType < number > ( res . totalBytesWritten ) ; expectType < number > ( res . totalBytesExpectedToWrite ) ; } ) ; const worker = wx . createWorker ( 'workers/request/index.js' ) ; worker . postMessage ( { msg : 'hello worker' , } ) ; const bannerAd = wx . createBannerAd ( { adUnitId : 'xxxx' , style : { left : 10 , top : 76 , width : 320 , height : 0 , } , adIntervals : 30 , } ) ; bannerAd . show ( ) ; bannerAd . hide ( ) ; bannerAd . onError ( err => { console . log ( err ) ; } ) ; bannerAd . show ( ) . catch ( err => console . log ( err ) ) ; bannerAd . onLoad ( ( ) => { console . log ( 'banner 广告加载成功' ) ; } ) ; bannerAd . show ( ) . then ( ( ) => console . log ( 'banner 广告显示' ) ) ; bannerAd . style . width = 400 ; const { screenWidth } = wx . getSystemInfoSync ( ) ; expectType < number > ( screenWidth ) ; bannerAd . onResize ( res => { console . log ( res . width , res . height ) ; console . log ( bannerAd . style . realWidth , bannerAd . style . realHeight ) ; } ) ; bannerAd . onResize ( res => { bannerAd . style . width = res . width + Math . random ( ) * 10 ; } ) ; bannerAd . destroy ( ) ; const video1 = wx . createRewardedVideoAd ( { adUnitId : 'xxxx' } ) ; const video2 = wx . createRewardedVideoAd ( { adUnitId : 'xxxx' } ) ; console . log ( video1 === video2 ) ; const rewardedVideoAd = wx . createRewardedVideoAd ( { adUnitId : 'xxxx' } ) ; rewardedVideoAd . onLoad ( ( ) => { console . log ( '激励视频 广告加载成功' ) ; } ) ; rewardedVideoAd . show ( ) . then ( ( ) => console . log ( '激励视频 广告显示' ) ) ; rewardedVideoAd . onError ( err => { console . log ( err ) ; } ) ; rewardedVideoAd . show ( ) . catch ( err => console . log ( err ) ) ; rewardedVideoAd . show ( ) . catch ( ( ) => { rewardedVideoAd . load ( ) . then ( ( ) => rewardedVideoAd . show ( ) ) ; } ) ; const interstitialAd = wx . createInterstitialAd ( { adUnitId : 'xxxx' } ) ; interstitialAd . show ( ) . catch ( err => { console . error ( err ) ; } ) ; interstitialAd . onLoad ( ( ) => { console . log ( '插屏 广告加载成功' ) ; } ) ; interstitialAd . onError ( err => { console . log ( err ) ; } ) ; interstitialAd . onClose ( ( ) => { console . log ( '插屏 广告关闭' ) ; } ) ; wx . onShareAppMessage ( function ( ) { return { title : '转发标题' , } ; } ) ; wx . shareAppMessage ( { title : '转发标题' , } ) ; wx . onShareAppMessage ( function ( ) { return { title : '转发标题' , imageUrl : canvas . toTempFilePathSync ( { destWidth : 500 , destHeight : 400 , } ) , } ; } ) ; const id = '' ; wx . shareAppMessage ( { imageUrlId : id , imageUrl : url , } ) ; wx . onShareAppMessage ( function ( ) { return { imageUrlId : id , imageUrl : url , } ; } ) ; wx . updateShareMenu ( { withShareTicket : true , } ) ; wx . updateShareMenu ( { withShareTicket : true , isUpdatableMessage : true , activityId : '' , templateInfo : { parameterList : [ { name : 'member_count' , value : '1' , } , { name : 'room_limit' , value : '3' , } , ] , } , } ) ; const openDataContext = wx . getOpenDataContext ( ) ; openDataContext . postMessage ( { text : 'hello' , year : new Date ( ) . getFullYear ( ) , } ) ;