提交 9e56d04c 编写于 作者: W weixin_47563380

Fri Aug 2 16:33:00 CST 2024 inscode

上级 78cea669
{"containers":[],"config":{}}
\ No newline at end of file
/*
* Eslint config file
* Documentation: https://eslint.org/docs/user-guide/configuring/
* Install the Eslint extension before using this feature.
*/
module.exports = {
env: {
es6: true,
browser: true,
node: true,
},
ecmaFeatures: {
modules: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
globals: {
wx: true,
App: true,
Page: true,
getCurrentPages: true,
getApp: true,
Component: true,
requirePlugin: true,
requireMiniProgram: true,
},
// extends: 'eslint:recommended',
rules: {},
}
{
"pages": [
"pages/home/home",
"pages/passlist/passlist",
"pages/InvMgmtIN/InvMgmtIN",
"pages/MDmaterial/MDmaterial",
"pages/item/item",
"pages/InvMgmt/InvMgmt",
"pages/message/message",
"pages/contact/contact",
"pages/camera/camera",
"pages/appbar/appbar",
"pages/logo/logo",
"pages/index/index",
"pages/fingerPrint/fingerPrint",
"pages/logs/logs",
"pages/about/about",
"pages/generateCode/createCode",
"pages/generateCode/generateCode",
"pages/scanCode/scanCode",
"pages/hello/hello"
],
"window": {
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#008c8c",
"navigationBarTitleText": "小型仓储系统-单机版",
"navigationBarTextStyle":"white"
},
"tabBar": {
"list": [{
"pagePath": "pages/home/home",
"text": "首页",
"iconPath": "/images/card1.jpg",
"selectedIconPath": "/images/card1.jpg"
},{
"pagePath": "pages/message/message",
"text": "消息",
"iconPath": "/images/card1.jpg",
"selectedIconPath": "/images/card1.jpg"
},{
"pagePath": "pages/contact/contact",
"text": "联系我们",
"iconPath": "/images/card1.jpg",
"selectedIconPath": "/images/card1.jpg"
}]
},
"style": "v2",
"rendererOptions": {
"skyline": {
"defaultDisplayBlock": true,
"disableABTest": true,
"sdkVersionBegin": "3.0.0",
"sdkVersionEnd": "15.255.255"
}
},
"componentFramework": "glass-easel",
"sitemapLocation": "sitemap.json",
"lazyCodeLoading": "requiredComponents"
}
\ No newline at end of file
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
// app.ts
App<IAppOption>({
globalData: {},
onLaunch(option) {
console.log(option.scene)
// 展示本地存储能力
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// 登录
wx.login({
success: res => {
console.log(res.code)
// 发送 res.code 到后台换取 openId, sessionKey, unionId
},
})
},
})
\ No newline at end of file
{
"component": true,
"styleIsolation": "apply-shared",
"usingComponents": {}
}
\ No newline at end of file
.weui-navigation-bar {
--weui-FG-0:rgba(0,0,0,.9);
--height: 44px;
--left: 16px;
}
.weui-navigation-bar .android {
--height: 48px;
}
.weui-navigation-bar {
overflow: hidden;
color: var(--weui-FG-0);
flex: none;
}
.weui-navigation-bar__inner {
position: relative;
top: 0;
left: 0;
height: calc(var(--height) + env(safe-area-inset-top));
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
padding-top: env(safe-area-inset-top);
width: 100%;
box-sizing: border-box;
}
.weui-navigation-bar__left {
position: relative;
padding-left: var(--left);
display: flex;
flex-direction: row;
align-items: flex-start;
height: 100%;
box-sizing: border-box;
}
.weui-navigation-bar__btn_goback_wrapper {
padding: 11px 18px 11px 16px;
margin: -11px -18px -11px -16px;
}
.weui-navigation-bar__btn_goback_wrapper.weui-active {
opacity: 0.5;
}
.weui-navigation-bar__btn_goback {
font-size: 12px;
width: 12px;
height: 24px;
-webkit-mask: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E") no-repeat 50% 50%;
mask: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E") no-repeat 50% 50%;
-webkit-mask-size: cover;
mask-size: cover;
background-color: var(--weui-FG-0);
}
.weui-navigation-bar__center {
font-size: 17px;
text-align: center;
position: relative;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
font-weight: bold;
flex: 1;
height: 100%;
}
.weui-navigation-bar__loading {
margin-right: 4px;
align-items: center;
}
.weui-loading {
font-size: 16px;
width: 16px;
height: 16px;
display: block;
background: transparent url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg width='80px' height='80px' viewBox='0 0 80 80' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Ctitle%3Eloading%3C/title%3E%3Cdefs%3E%3ClinearGradient x1='94.0869141%25' y1='0%25' x2='94.0869141%25' y2='90.559082%25' id='linearGradient-1'%3E%3Cstop stop-color='%23606060' stop-opacity='0' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3ClinearGradient x1='100%25' y1='8.67370605%25' x2='100%25' y2='90.6286621%25' id='linearGradient-2'%3E%3Cstop stop-color='%23606060' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3C/defs%3E%3Cg stroke='none' stroke-width='1' fill='none' fill-rule='evenodd' opacity='0.9'%3E%3Cg%3E%3Cpath d='M40,0 C62.09139,0 80,17.90861 80,40 C80,62.09139 62.09139,80 40,80 L40,73 C58.2253967,73 73,58.2253967 73,40 C73,21.7746033 58.2253967,7 40,7 L40,0 Z' fill='url(%23linearGradient-1)'%3E%3C/path%3E%3Cpath d='M40,0 L40,7 C21.7746033,7 7,21.7746033 7,40 C7,58.2253967 21.7746033,73 40,73 L40,80 C17.90861,80 0,62.09139 0,40 C0,17.90861 17.90861,0 40,0 Z' fill='url(%23linearGradient-2)'%3E%3C/path%3E%3Ccircle id='Oval' fill='%23606060' cx='40.5' cy='3.5' r='3.5'%3E%3C/circle%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A") no-repeat;
background-size: 100%;
margin-left: 0;
animation: loading linear infinite 1s;
}
@keyframes loading {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
Component({
options: {
multipleSlots: true // 在组件定义时的选项中启用多slot支持
},
/**
* 组件的属性列表
*/
properties: {
extClass: {
type: String,
value: ''
},
title: {
type: String,
value: ''
},
background: {
type: String,
value: ''
},
color: {
type: String,
value: ''
},
back: {
type: Boolean,
value: true
},
loading: {
type: Boolean,
value: false
},
homeButton: {
type: Boolean,
value: false,
},
animated: {
// 显示隐藏的时候opacity动画效果
type: Boolean,
value: true
},
show: {
// 显示隐藏导航,隐藏的时候navigation-bar的高度占位还在
type: Boolean,
value: true,
observer: '_showChange'
},
// back为true的时候,返回的页面深度
delta: {
type: Number,
value: 1
},
},
/**
* 组件的初始数据
*/
data: {
displayStyle: ''
},
lifetimes: {
attached() {
const rect = wx.getMenuButtonBoundingClientRect()
wx.getSystemInfo({
success: (res) => {
const isAndroid = res.platform === 'android'
const isDevtools = res.platform === 'devtools'
this.setData({
ios: !isAndroid,
innerPaddingRight: `padding-right: ${res.windowWidth - rect.left}px`,
leftWidth: `width: ${res.windowWidth - rect.left }px`,
safeAreaTop: isDevtools || isAndroid ? `height: calc(var(--height) + ${res.safeArea.top}px); padding-top: ${res.safeArea.top}px` : ``
})
}
})
},
},
/**
* 组件的方法列表
*/
methods: {
_showChange(show: boolean) {
const animated = this.data.animated
let displayStyle = ''
if (animated) {
displayStyle = `opacity: ${
show ? '1' : '0'
};transition:opacity 0.5s;`
} else {
displayStyle = `display: ${show ? '' : 'none'}`
}
this.setData({
displayStyle
})
},
back() {
const data = this.data
if (data.delta) {
wx.navigateBack({
delta: data.delta
})
}
this.triggerEvent('back', { delta: data.delta }, {})
}
},
})
<view class="weui-navigation-bar {{extClass}}">
<view class="weui-navigation-bar__inner {{ios ? 'ios' : 'android'}}" style="color: {{color}}; background: {{background}}; {{displayStyle}}; {{innerPaddingRight}}; {{safeAreaTop}};">
<!-- 左侧按钮 -->
<view class='weui-navigation-bar__left' style="{{leftWidth}};">
<block wx:if="{{back || homeButton}}">
<!-- 返回上一页 -->
<block wx:if="{{back}}">
<view class="weui-navigation-bar__buttons weui-navigation-bar__buttons_goback">
<view
bindtap="back"
class="weui-navigation-bar__btn_goback_wrapper"
hover-class="weui-active"
hover-stay-time="100"
aria-role="button"
aria-label="返回"
>
<view class="weui-navigation-bar__button weui-navigation-bar__btn_goback"></view>
</view>
</view>
</block>
<!-- 返回首页 -->
<block wx:if="{{homeButton}}">
<view class="weui-navigation-bar__buttons weui-navigation-bar__buttons_home">
<view
bindtap="home"
class="weui-navigation-bar__btn_home_wrapper"
hover-class="weui-active"
aria-role="button"
aria-label="首页"
>
<view class="weui-navigation-bar__button weui-navigation-bar__btn_home"></view>
</view>
</view>
</block>
</block>
<block wx:else>
<slot name="left"></slot>
</block>
</view>
<!-- 标题 -->
<view class='weui-navigation-bar__center'>
<view wx:if="{{loading}}" class="weui-navigation-bar__loading" aria-role="alert">
<view
class="weui-loading"
aria-role="img"
aria-label="加载中"
></view>
</view>
<block wx:if="{{title}}">
<text>{{title}}</text>
</block>
<block wx:else>
<slot name="center"></slot>
</block>
</view>
<!-- 右侧留空 -->
<view class='weui-navigation-bar__right'>
<slot name="right"></slot>
</view>
</view>
</view>
{
"usingComponents": {}
}
\ No newline at end of file
.swiper{
height: 250rpx; /*rpx能实现高度的自动缩放*/
indicator-dots:"true";
autoplay:true;
interval:"5000";
duration:"500";
}
.swiper image{
width: 100%;
height: 100%;
}
.grid-list{
display: flex;
flex-wrap: wrap; /* 让弹性盒元素在必要的时候拆行 */
border-left: 1px solid #efefef;
border-top: 1px solid #efefef;
}
.grid-item{
width: 33.33%;
height: 200rpx;
display: flex;
flex-direction: column;/* 项目将垂直显示,正如一个列一样。 */
align-items: center; /* 定义flex子项在flex容器的中心 */
justify-content: center;/*用于设置或检索弹性盒子元素在主轴(横轴)方向上的对齐方式为居中*/
border-right: 1px solid #efefef;
border-bottom: 1px solid #efefef;
box-sizing: border-box;
}
.grid-item image {
width: 60rpx;
height: 60rpx;
}
.grid-item text{
font-size: 24rpx;
margin-top: 10rpx;
}
/* 图片 */
.img-box{
display: flex;
padding: 20rpx 10rpx;
justify-content: space-around;
}
.img-box image{
width: 45%;
height: 250rpx;
}
\ No newline at end of file
// pages/InvMgmt/InvMgmt.ts
Page({
/**
* 页面的初始数据
*/
data: {
},
goToInvMgmtIN: function() {
wx.navigateTo({
url: '/pages/InvMgmtIN/InvMgmtIN' // 扫码入库
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
wx.setNavigationBarTitle({
title: '库存管理',
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<!-- 库存管理 -->
<!-- 轮播图区域 -->
<swiper
indicator-dots="true"
autoplay="true"
interval="5000"
duration="500" >
<swiper-item>
<image src="/images/banner1.jpg" mode="aspectFill"></image>
</swiper-item>
<swiper-item>
<image src="/images/card1.jpg" mode="aspectFill"></image>
</swiper-item>
<swiper-item>
<image src="/images/menu1.jpg" mode="aspectFill"></image>
</swiper-item>
</swiper>
<!-- 九宫格区域 -->
<view class="grid-list">
<view class="grid-item">
<image src="/images/banner1.jpg" bindtap="goToInvMgmtIN"></image>
<text>扫码入库</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg"></image>
<text>赚钱建家</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg" bindtap="goToPasslist"></image>
<text>赚钱建家</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg"></image>
<text>赚钱建家</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg"></image>
<text>赚钱建家</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg"></image>
<text>赚钱建家</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg"></image>
<text>赚钱建家</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg"></image>
<text>赚钱建家</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg"></image>
<text>赚钱建家</text>
</view>
</view>
<!-- 图片区域 -->
<view class="img-box">
<image src="/images/banner1.jpg"></image>
<image src="/images/banner1.jpg"></image>
</view>
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
/* pages/InvMgmtIN/InvMgmtIN.wxss */
.input {
display: flex;
width: 100%;
padding: 16px;
box-sizing: border-box;
border-top: .5px solid rgba(0, 0, 0, 0.1);
border-bottom: .5px solid rgba(0, 0, 0, 0.1);
color: black;
}
.label {
width: 105px;
}
// pages/InvMgmtIN/InvMgmtIN.ts
Page({
/**
* 页面的初始数据
*/
data: {
noError: true,
isShow: true,
currentTime: '',//年月日时分秒
MText: '',//物料描述
MCode: '',//批次编码
MLocation: '',//存放地点
src: '',// 存储拍摄的照片路径
formData: {
MText: '',//物料描述
MCode: '',//批次编码
MLocation: '',//存放地点
src: '',// 存储拍摄的照片路径
},
// 初始时,stkmat数组为空
stkmats: []
},
selectImage: function () {
wx.chooseImage({
count: 1,
success: function (res) {
const tempFilePath = res.tempFilePaths[0]; // 用户选择的图片临时文件路径
// 将图片路径保存到本地缓存
wx.setStorageSync('imagePath', tempFilePath);
// 同时更新页面的数据,以便立即显示图片
this.setData({
src: tempFilePath
});
this.setData({
'formData.src': tempFilePath
});
}.bind(this) // 注意这里需要绑定this
});
},
// 错误处理函数
error: function (e: any) {
console.error('摄像头组件发生错误:', e.detail);
this.setData({
isShow: false // 现在显示
});
// 这里可以添加你的错误处理逻辑
},
addOrUpdateItem: function (e: any) {
const { MText, MCode, MLocation, src } = this.data.formData;
if (!MText || !MCode || !MLocation || !src) {
this.setData({
noError: false
})
return wx.showToast({ title: '请填写完整信息', icon: 'none' });
}else{
this.setData({
noError: true
})
}
let stkmat = {
MText: MText,//物料描述
MCode: MCode,//批次编码
MLocation: MLocation,//存放地点
src: this.data.src,// 存储拍摄的照片路径
};
// 尝试从本地存储中获取'stkmats'
let storedItems = wx.getStorageSync('stkmats');
// 检查storedItems是否为null(或undefined,但wx.getStorageSync不会返回undefined)
const itemslist = storedItems ? JSON.parse(storedItems) : [];
// 使用Object.keys()来获取所有键,并计算它们的数量
let recordCount = Object.keys(itemslist).length;
// 将新记录添加到itemsList对象中,使用新记录的ID作为键
itemslist[recordCount.toString()] = stkmat;
this.saveItems(itemslist);
},
saveItems: function (itemslist: any) {
wx.setStorageSync('stkmats', JSON.stringify(itemslist));
/* let storedItems = wx.getStorageSync('stkmats');
// 检查storedItems是否为null(或undefined,但wx.getStorageSync不会返回undefined)
const itemslist1 = storedItems ? JSON.parse(storedItems) : [];
this.setData({
items: itemslist
}); */
},
onInputMText(e: any) {
this.setData({
'formData.MText': e.detail.value
});
},
onInputMCode(e: any) {
this.setData({
'formData.MCode': e.detail.value
});
},
onInputMLocation(e: any) {
this.setData({
'formData.MLocation': e.detail.value
});
},
takePhoto() {
const ctx = wx.createCameraContext()
ctx.takePhoto({
quality: 'high',
success: (res) => {
this.setData({
src: res.tempImagePath
})
this.setData({
'formData.src': res.tempImagePath
});
}
})
},
savePhoto() {
this.addOrUpdateItem();
if (this.data.noError) {
wx.showToast({
title: '保存成功',
icon: 'success',
duration: 2000
})
} else {
wx.showToast({
title: '保存失败',
icon: 'none',
duration: 2000
})
}
/* wx.saveImageToPhotosAlbum({
filePath: this.data.src,
success: function (res) {
wx.showToast({
title: '保存成功',
icon: 'success',
duration: 2000
})
},
fail: function (err) {
wx.showToast({
title: '保存失败',
icon: 'none',
duration: 2000
})
}
}) */
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
// 获取当前时间
let now = new Date();
// 格式化日期时间字符串
let formattedTime = `${now.getFullYear()}${(now.getMonth() + 1).toString().padStart(2, '0')}${now.getDate().toString().padStart(2, '0')}${now.getHours().toString().padStart(2, '0')}${now.getMinutes().toString().padStart(2, '0')}${now.getSeconds().toString().padStart(2, '0')}`;
// 更新页面数据
this.setData({
'formData.MCode': formattedTime
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
wx.setNavigationBarTitle({
title: '扫码入库',
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<!-- pages/camera/camera.wxml -->
<camera device-position="back" flash="off" binderror="error" bindtap="selectImage" style="width: 100%; height: 300px;"></camera>
<image src="{{src}}" wx:if="{{src}}">显示图片</image>
<button bindtap="takePhoto" wx:if="{{isShow}}">拍照</button>
<button bindtap="savePhoto" wx:if="{{src}}">保存</button>
<view class="input">
<text class="label">物料描述</text>
<input placeholder="请输入物料描述" bind:change="onInputMText" value="{{formData.MText}}"/>
</view>
<view class="input">
<text class="label">批次编码</text>
<input placeholder="现在手输,未来实现扫描二维码" bind:change="onInputMCode" value="{{formData.MCode}}"/>
</view>
<view class="input">
<text class="label">存放地点</text>
<input placeholder="请输入存放地点" bind:change="onInputMLocation" value="{{formData.MLocation}}"/>
</view>
<!-- <view class="input">
<text class="label">图片地址</text>
<text>{{src}}</text>
</view> -->
<!-- <view class="input">
<text class="label">显示传值</text>
<input placeholder="显示传值" value="{{formData.MText}}"/>
</view> -->
\ No newline at end of file
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
\ No newline at end of file
/* pages/MDmaterial/MDmaterial.wxss */
.menu {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10rpx 10rpx;
background-color: #feffff;
}
.menu-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.menu-item image {
width: 80rpx;
height: 80rpx;
}
.menu-item text {
margin-top: 10rpx;
font-size: 28rpx;
color: #000000;
}
.shop-item{
display: flex;
padding: 15rpx;
border: 1px solid #efefef;
margin: 15rpx;
border-radius: 8rpx;
box-shadow: 1rpx 1rpx 15rpx #ddd;
}
.thumb image{
width: 250rpx;
height: 250rpx;
display: block;
margin-right: 15rpx;
}
.info{
display: flex;
flex-direction: column;
justify-content: space-around;
font-size: 24rpx;
}
.shop-title{
font-weight: bold;
}
\ No newline at end of file
// pages/MDmaterial/MDmaterial.ts
Page({
/**
* 页面的初始数据
*/
data: {
isShow:true,
searchInput: '', // 用户输入的查询条件
searchResults: [], // 查询结果
imagePath: '', // 用于存储图片的路径
MText: '',//物料描述
MCode: '',//批次编码
MLocation: '',//存放地点
src: '',// 存储拍摄的照片路径
item: {
MText: '',//物料描述
MCode: '',//批次编码
MLocation: '',//存放地点
src: '',// 存储拍摄的照片路径
},
// 初始时,stkmat数组为空
itmes: []
},
// 处理输入事件
handleInput: function (e) {
this.setData({
searchInput: e.detail.value
});
},
// 执行查询
searchData: function () {
let searchInput = this.data.searchInput.trim();
let searchResults = [];
// 这里我们进行简单的模糊查询,即检查name或info字段是否包含搜索条件
this.data.items.forEach(item => {
if (item.MText.includes(searchInput) || item.MCode.includes(searchInput) || item.MLocation.includes(searchInput)) {
searchResults.push(item);
this.setData({
isShow: false
});
}
});
// 更新查询结果到页面上
this.setData({
searchResults: searchResults
});
},
selectImage: function () {
wx.chooseImage({
count: 1,
success: function (res) {
const tempFilePath = res.tempFilePaths[0]; // 用户选择的图片临时文件路径
// 将图片路径保存到本地缓存
wx.setStorageSync('imagePath', tempFilePath);
// 同时更新页面的数据,以便立即显示图片
this.setData({
imagePath: tempFilePath
});
}.bind(this) // 注意这里需要绑定this
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
// 页面加载时,尝试从缓存中读取图片路径
const cachedImagePath = wx.getStorageSync('imagePath') || '';
if (cachedImagePath) {
this.setData({
imagePath: cachedImagePath
});
} else {
this.setData({
imagePath: "/images/banner1.jpg" //初始图片
});
}
// 尝试从本地存储中获取'items'
const storedItems = wx.getStorageSync('stkmats');
//console.log('storedItems:'+storedItems);
// 检查storedItems是否为null(或undefined,但wx.getStorageSync不会返回undefined)
// 如果是null,则默认为空数组;否则,尝试解析JSON字符串为数组
const itemslist = storedItems ? JSON.parse(storedItems) : [];
//if(itemslist)
//console.log('itemslist:'+itemslist);
// 更新页面的items数据
this.setData({
items: itemslist
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
wx.setNavigationBarTitle({
title: '物料管理',
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<view>
<input type="text" bindinput="handleInput" placeholder="请输入查询条件" />
<button bindtap="searchData">查询</button>
<view wx:for="{{searchResults}}" wx:key="id">
{{item.MText}} - {{item.MCode}} - {{item.MLocation}}
</view>
</view>
<view class="shop-item" wx:for="{{searchResults}}" wx:key="id">
<!-- 图片资源 -->
<view class="thumb">
<image src="{{item.src}}" mode="aspectFit" bindtap="selectImage"></image>
</view>
<!-- 文字信息 -->
<view class="info">
<text class="shop-title">物料描述: {{item.MText}}</text>
<text>批次编码:{{item.MCode}}</text>
<text>存放地点: {{item.MLocation}}</text>
</view>
</view>
<view class="shop-item" wx:if="{{isShow}}" wx:for="{{items}}" wx:key="index">
<!-- 图片资源 -->
<view class="thumb">
<image src="{{item.src}}" mode="aspectFit" bindtap="selectImage"></image>
</view>
<!-- 文字信息 -->
<view class="info">
<text class="shop-title">物料描述: {{item.MText}}</text>
<text>批次编码:{{item.MCode}}</text>
<text>存放地点: {{item.MLocation}}</text>
</view>
</view>
{
"navigationBarTitleText": "Hello Page"
}
\ No newline at end of file
// pages/about/about.ts
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<view class="container">
<text>HELLO</text>
</view>
\ No newline at end of file
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
text {
font-size: 30rpx;
color: #333;
}
\ No newline at end of file
// components/app-bar/index.js
Component({
properties: {
},
data: {
showAppbar: false
}
})
\ No newline at end of file
{
"component": true,
"usingComponents": {
}
}
\ No newline at end of file
/* pages/appbar/appbar.wxss */
\ No newline at end of file
// pages/appbar/appbar.ts
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<view wx:if="{{showAppbar}}">
<app-bar-course></app-bar-course>
</view>
\ No newline at end of file
.expand-container {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
padding: 0 24px;
padding-bottom: env(safe-area-inset-bottom);
pointer-events: auto;
overflow: hidden;
background-color: #e9f8f7;
color: #7e8081;
}
.hide {
display: none;
}
.nav-bar {
overflow: hidden;
box-sizing: border-box;
}
.icon--back {
width: 30px;
height: 30px;
}
.title {
margin-left: 10px;
min-width: 160px;
flex: 1;
}
.title .name {
margin-top: 4px;
font-size: 12px;
}
.title-wrap {
flex: 1;
min-width: 240px;
}
.footer {
padding: 0 24px;
}
.footer .icon {
width: 40px;
height: 40px;
}
.expand-cover {
width: 100%;
height: 100%;
}
.music-title {
margin-top: 48px;
font-size: 20px;
font-weight: bold;
color: #07c160;
}
.music-title .name {
margin-top: 12px;
font-size: 14px;
font-weight: 200;
color: #b1b2b3;
}
.cover-area {
margin: 8px 0;
width: 100%;
aspect-ratio: 1 / 1;
overflow: hidden;
}
.cover {
/* aspect-ratio: 1 / 1; */
flex-shrink: 0;
}
.icon {
width: 18px;
height: 18px;
}
.row {
display: flex;
flex-direction: row;
align-items: center;
}
.row-between {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.column {
display: flex;
flex-direction: column;
}
.column-main-center {
display: flex;
flex-direction: column;
justify-content: center;
}
.column-cross-center {
display: flex;
flex-direction: column;
align-items: center;
}
.center {
display: flex;
align-items: center;
justify-content: center;
}
.circle {
width: 100%;
height: 100%;
overflow: hidden;
border-radius: 50%;
}
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
/* pages/camera/camera.wxss */
\ No newline at end of file
// pages/camera/camera.ts
Page({
/**
* 页面的初始数据
*/
data: {
src: '' // 存储拍摄的照片路径
},
takePhoto() {
const ctx = wx.createCameraContext()
console.log('takePhoto拍照')
ctx.takePhoto({
quality: 'high',
success: (res) => {
this.setData({
src: res.tempImagePath
})
}
})
},
savePhoto() {
wx.saveImageToPhotosAlbum({
filePath: this.data.src,
success: function (res) {
wx.showToast({
title: '保存成功',
icon: 'success',
duration: 2000
})
},
fail: function (err) {
wx.showToast({
title: '保存失败',
icon: 'none',
duration: 2000
})
}
})
} ,
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// options.scene 是场景值
console.log('onLoad启动时的场景值:', options.scene);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<!-- pages/camera/camera.wxml -->
<camera device-position="back" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera>
<button bindtap="takePhoto">拍照</button>
<button bindtap="savePhoto" wx:if="{{src}}">保存到相册</button>
<text>{{src}}</text>
<image src="{{src}}">显示图片</image>
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
/* pages/contact/contact.wxss */
\ No newline at end of file
// pages/contact/contact.ts
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
wx.setNavigationBarTitle({
title: '联系我们',
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<!--pages/contact/contact.wxml 使用微信的「联系我」插件-->
<text>pages/contact/contact.wxml 使用微信的「联系我」插件</text>
\ No newline at end of file
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
\ No newline at end of file
/* pages/fingerPrint/fingerPrint.wxss */
\ No newline at end of file
// pages/fingerPrint/fingerPrint.ts
Page({
/**
* 页面的初始数据
*/
data: {
hasLogin: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function () {
const _this = this
console.log('节点信息:onLoad')
wx.checkIsSupportSoterAuthentication({
success(res) {
console.log(res.supportMode.indexOf('fingerPrint'))
if (res.supportMode.indexOf('fingerPrint') === -1) {
wx.showToast({
title: '您的手机暂不支持指纹识别',
icon: 'none',
duration: 2000
})
return
}
_this.setData({
hasLogin: true
})
},
fail() {
wx.showToast({
title: '系统错误',
icon: 'none',
duration: 2000
})
}
})
},
startSoterAuthentication: function () {
const _this = this
console.log('节点信息:wx.checkIsSoterEnrolledInDevice')
wx.checkIsSoterEnrolledInDevice({
checkAuthMode: 'fingerPrint',
success(res) {
if (res.isEnrolled) {
wx.showToast({
title: '您尚未录入指纹,请到系统设置中录入',
icon: 'none',
duration: 2000
})
return
}
wx.startSoterAuthentication({
requestAuthModes: ['fingerPrint'],
challenge: '123456',
authContent: '请用指纹进行身份验证',
success(res) {
wx.showToast({
title: '登录成功',
icon: 'success',
duration: 2000
})
_this.setData({
hasLogin: true
})
},
fail(res) {
wx.showToast({
title: '登录失败,请重试',
icon: 'none',
duration: 2000
})
}
})
},
fail() {
wx.showToast({
title: '系统错误',
icon: 'none',
duration: 2000
})
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<!--指纹识别登录-->
<view class="container">
<view wx:if="{{!hasLogin}}">
<button bindtap="startSoterAuthentication">点击登录</button>
</view>
</view>
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
/* pages/generateCode/createCode.wxss */
\ No newline at end of file
// pages/generateCode/createCode.ts
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<!--pages/generateCode/createCode.wxml-->
<text>pages/generateCode/createCode.wxml</text>
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
/* pages/generateCode/generateCode.wxss */
\ No newline at end of file
// pages/generateCode/generateCode.ts
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
console.log('onReady')
this.generateCode()
},
generateCode: function () {
console.log('generateCode-begin')
const ctx = wx.createCanvasContext('codeCanvas')
const codeData = 'https://example.com' // 二维码包含的信息,可以是文本或URL等
const codeSize = 200 // 二维码的尺寸
const imageMargin = 10 // 二维码与画布边缘的距离
wx.createSelectorQuery().select('#codeCanvas').boundingClientRect((rect) => {
//const canvasWidth = rect.width
const canvasWidth = 100
//const canvasHeight = rect.height
const canvasHeight = 100
const codeWidth = canvasWidth - 2 * imageMargin
const codeHeight = canvasHeight - 2 * imageMargin
// 绘制白色背景
ctx.setFillStyle('#ffffff')
ctx.fillRect(0, 0, canvasWidth, canvasHeight)
// 绘制二维码
console.log('绘制二维码')
ctx.drawImage('/images/qrcode.png', imageMargin, imageMargin, codeWidth, codeHeight)
ctx.draw()
}).exec()
console.log('generateCode-end')
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<!--pages/generateCode/generateCode.wxml-->
<view class="container">
<view>
<canvas canvas-id="codeCanvas" style="width: 200px; height: 200px;"></canvas>
</view>
</view>
\ No newline at end of file
{
"navigationBarTitleText": "Hello Page"
}
\ No newline at end of file
<view class="container">
<text>HELLO</text>
</view>
\ No newline at end of file
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
text {
font-size: 30rpx;
color: #333;
}
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
.swiper-image{
width: 100%;
height: 100%;
}
.grid-list{
display: flex;
flex-wrap: wrap; /* 让弹性盒元素在必要的时候拆行 */
border-left: 1px solid #efefef;
border-top: 1px solid #efefef;
}
.grid-item{
width: 33.33%;
height: 200rpx;
display: flex;
flex-direction: column;/* 项目将垂直显示,正如一个列一样。 */
align-items: center; /* 定义flex子项在flex容器的中心 */
justify-content: center;/*用于设置或检索弹性盒子元素在主轴(横轴)方向上的对齐方式为居中*/
border-right: 1px solid #efefef;
border-bottom: 1px solid #efefef;
box-sizing: border-box;
}
.grid-item image {
width: 60rpx;
height: 60rpx;
}
.grid-item text{
font-size: 24rpx;
margin-top: 10rpx;
}
/* 图片 */
.img-box{
display: flex;
padding: 20rpx 10rpx;
justify-content: space-around;
}
.img-box image{
width: 45%;
height: 250rpx;
}
\ No newline at end of file
// pages/home/home.ts
Page({
/**
* 页面的初始数据
*/
data: {
SwiperList: []
},
// 获取轮播图的方法
getSwiperList() {
console.log('执行getSwiperList')
// wx.request({
// //url: 'https://www.escook.cn/slides',
// url: 'https://www.csdn.net/',
// method: 'GET',
// success: (res) => {
// // 类似于React中的setState,将状态数据更新
// this.setData({
// SwiperList: res.data
// })
// }
// })
},
goToInvMgmt: function() {
wx.navigateTo({
url: '/pages/InvMgmt/InvMgmt' // 库存管理
});
},
goToMDmaterial: function() {
wx.navigateTo({
url: '/pages/MDmaterial/MDmaterial' // 物料管理
});
},
goToPasslist: function() {
wx.navigateTo({
url: '/pages/passlist/passlist' // 用户管理
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
this.getSwiperList()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<!-- 轮播图区域 -->
<swiper
indicator-dots="true"
autoplay="true"
interval="5000"
duration="500" >
<!-- <swiper-item wx:for="{{SwiperList}}" wx:key="id">
<image src="{{item.image}}"></image>
</swiper-item> -->
<swiper-item>
<image class="swiper-image" src="/images/swiper1.jpg" mode="aspectFill"></image>
</swiper-item>
<swiper-item>
<image class="swiper-image" src="/images/swiper2.jpg" mode="aspectFill"></image>
</swiper-item>
<swiper-item>
<image class="swiper-image" src="/images/swiper3.jpg" mode="aspectFill"></image>
</swiper-item>
</swiper>
<!-- 九宫格区域 -->
<view class="grid-list">
<view class="grid-item">
<image src="/images/banner1.jpg" bindtap="goToMDmaterial"></image>
<text>物料管理</text>
</view>
<view class="grid-item">
<image src="/images/banner1.jpg" bindtap="goToInvMgmt"></image>
<text>库存管理</text>
</view>
<view class="grid-item">
<image src="/images/banner1.jpg" bindtap="goToPasslist"></image>
<text>用户管理</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg"></image>
<text>赚钱建家</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg"></image>
<text>赚钱建家</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg"></image>
<text>赚钱建家</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg"></image>
<text>赚钱建家</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg"></image>
<text>赚钱建家</text>
</view>
<view class="grid-item">
<image src="/images/building.jpg"></image>
<text>赚钱建家</text>
</view>
</view>
<!-- 图片区域 -->
<view class="img-box">
<image src="/images/banner1.jpg"></image>
<image src="/images/banner1.jpg"></image>
</view>
\ No newline at end of file
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
\ No newline at end of file
/**index.less**/
page {
height: 100vh;
display: flex;
flex-direction: column;
}
.scrollarea {
flex: 1;
overflow-y: hidden;
}
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
color: #aaa;
width: 80%;
}
.userinfo-avatar {
overflow: hidden;
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}
.usermotto {
margin-top: 200px;
}
.avatar-wrapper {
padding: 0;
width: 56px !important;
border-radius: 8px;
margin-top: 40px;
margin-bottom: 40px;
}
.avatar {
display: block;
width: 56px;
height: 56px;
}
.nickname-wrapper {
display: flex;
width: 100%;
padding: 16px;
box-sizing: border-box;
border-top: .5px solid rgba(0, 0, 0, 0.1);
border-bottom: .5px solid rgba(0, 0, 0, 0.1);
color: black;
}
.nickname-label {
width: 105px;
}
.nickname-input {
flex: 1;
}
// index.ts
// 获取应用实例
const app = getApp<IAppOption>()
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
Component({
data: {
motto: 'Hello World',
QRStr:'',
plant:'',
materialnum:'',
materialtxt:'',
materialbatch:'',
materialamount:'',
materialBUoM:'',
userInfo: {
avatarUrl: defaultAvatarUrl,
nickName: '',
},
hasUserInfo: false,
canIUseGetUserProfile: wx.canIUse('getUserProfile'),
canIUseNicknameComp: wx.canIUse('input.type.nickname'),
},
methods: {
// 事件处理函数
bindViewTap() {
wx.navigateTo({
url: '../logs/logs',
})
},
onInputPlant(e:any){
this.setData({
plant: e.detail.value
});
console.log(this.data.plant)
},
onInputMaterialnum(e:any){
this.setData({
materialnum: e.detail.value
});
console.log(this.data.materialnum)
},
onInputMaterialtxt(e:any){
this.setData({
materialtxt: e.detail.value
});
console.log(this.data.materialtxt)
},
onInputmaterialbatch(e:any){
this.setData({
materialbatch: e.detail.value
});
console.log(this.data.materialbatch)
},
onInputmaterialamount(e:any){
this.setData({
materialamount: e.detail.value
});
console.log(this.data.materialamount)
},
onInputmaterialBUoM(e:any){
this.setData({
materialBUoM: e.detail.value
});
console.log(this.data.materialBUoM)
},
onCreateQR(e:any){
let QRStr="plant:"+this.data.plant+" materialnum:"+this.data.materialnum+" materialtxt:"+this.data.materialtxt+" materialbatch:"+this.data.materialbatch;
console.log(QRStr)
},
onChooseAvatar(e: any) {
const { avatarUrl } = e.detail
const { nickName } = this.data.userInfo
this.setData({
"userInfo.avatarUrl": avatarUrl,
hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
})
},
onInputChange(e: any) {
const nickName = e.detail.value
const { avatarUrl } = this.data.userInfo
this.setData({
"userInfo.nickName": nickName,
hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
})
},
getUserProfile() {
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx.getUserProfile({
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log(res)
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
},
},
})
<!--index.wxml-->
<navigation-bar title="scanMM" back="{{false}}" color="black" background="#FFF"></navigation-bar>
<scroll-view class="scrollarea" scroll-y type="list">
<view class="container">
<view class="userinfo">
<block wx:if="{{canIUseNicknameComp && !hasUserInfo}}">
<button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
<image class="avatar" src="{{userInfo.avatarUrl}}"></image>
</button>
<view class="nickname-wrapper">
<text class="nickname-label">工厂</text>
<input type="plant" class="nickname-input" placeholder="请输入工厂" bind:change="onInputPlant" />
</view>
<view class="nickname-wrapper">
<text class="nickname-label">物料号</text>
<input type="materialnum" class="nickname-input" placeholder="请输入物料号" bind:change="onInputMaterialnum" />
</view>
<view class="nickname-wrapper">
<text class="nickname-label">物料描述</text>
<input type="materialtxt" class="nickname-input" placeholder="请输入物料描述" bind:change="onInputMaterialtxt" />
</view>
<view class="nickname-wrapper">
<text class="nickname-label">批次号</text>
<input type="materialbatch" class="nickname-input" placeholder="请输入批次号" bind:change="onInputmaterialbatch" />
</view>
<view class="nickname-wrapper">
<text class="nickname-label">数量</text>
<input type="materialamount" class="nickname-input" placeholder="请输入数量" bind:change="onInputmaterialamount" />
</view>
<view class="nickname-wrapper">
<text class="nickname-label">基本计量单位</text>
<input type="materialBUoM" class="nickname-input" placeholder="请输入基本计量单位" bind:change="onInputmaterialBUoM" />
</view>
<button class="button" bindtap="onCreateQR">生成二维码</button>
</block>
<block wx:elif="{{!hasUserInfo}}">
<button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button>
<view wx:else> 请使用2.10.4及以上版本基础库 </view>
</block>
<block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block>
</view>
<view class="usermotto">
<text class="user-motto">{{motto}}</text>
</view>
</view>
</scroll-view>
{
"usingComponents": {}
}
\ No newline at end of file
/* pages/item/item.wxss */
.avatar {
display: block;
width: 16px;
height: 16px;
}
.header {
display: flex;
align-items: center;
justify-content: center;
height: 88rpx;
background-color: #ffffff;
box-shadow: 0 1rpx 1rpx rgba(0, 0, 0, 0.1);
}
.logo {
width: 60rpx;
height: 60rpx;
margin-right: 20rpx;
}
.title {
font-size: 32rpx;
font-weight: bold;
color: #333333;
}
.banner {
width: 10px; /* 使 banner 宽度充满容器 */
height: 10px; /* 设定 banner 的高度 */
background-color: rgb(41, 28, 110); /* 设定背景色,实际使用中通常会用图片 */
display: flex; /* 使用 Flex 布局来居中对齐 banner 中的内容 */
justify-content: center; /* 水平居中 */
align-items: center; /* 垂直居中 */
overflow: hidden; /* 如果图片尺寸过大,防止内容溢出 */
}
.menu {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10rpx 10rpx;
background-color: #feffff;
}
.menu-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.menu-item image {
width: 80rpx;
height: 80rpx;
}
.menu-item text {
margin-top: 10rpx;
font-size: 28rpx;
color: #000000;
}
.content {
flex: 1;
padding: 30rpx 60rpx;
background-color: #cc6363;
}
.section {
margin-bottom: 60rpx;
padding: 30rpx 60rpx;
}
.section-title {
font-size: 32rpx;
font-weight: bold;
color: #333333;
margin-bottom: 30rpx;
margin-left: 30rpx;
}
.card-group {
display: flex;
justify-content: space-between;
padding: 5%;
}
.card {
display: flex;
flex-direction: column;
align-items: center;
background-color: #ffffff;
box-shadow: 0 1rpx 1rpx rgba(0, 0, 0, 0.1);
width: 200rpx;
padding: 20rpx;
border-radius: 10rpx;
box-sizing: border-box;
}
.card image {
width: 190rpx;
height: 190rpx;
margin-bottom: 20rpx;
}
.card-title {
font-size: 28rpx;
font-weight: bold;
color: #333333;
margin-bottom: 10rpx;
}
.card-desc {
font-size: 24rpx;
color: #999999;
margin-bottom: 10rpx;
}
.card-price {
font-size: 28rpx;
color: #ff4d4f;
}
.topic-group {
display: flex;
justify-content: space-between;
color: #6e7e94;
padding: 20rpx;
width: 100px;
height: 100px;
}
.topic {
display: flex;
flex-direction: column;
align-items: center;
background-color: #ffffff;
box-shadow: 0 1rpx 1rpx rgba(0, 0, 0, 0.1);
width: 80%;
padding: 20rpx;
border-radius: 10rpx;
}
.topic image {
width: 300rpx;
height: 240rpx;
margin-bottom: 20rpx;
}
.topic-title {
font-size: 28rpx;
font-weight: bold;
color: #333333;
margin-bottom: 10rpx;
}
.footer {
display: flex;
align-items: center;
justify-content: center;
height: 60rpx;
background-color: #ffffff;
box-shadow: 0 -1rpx 1rpx rgba(0, 0, 0, 0.1);
}
.info {
font-size: 24rpx;
color: #999999;
}
// pages/item/item.ts
Page({
/**
* 页面的初始数据
*/
data: {
},
goToPasslist: function() {
wx.navigateTo({
url: '/pages/passlist/passlist' // 用户管理
});
},
goToMDmaterial: function() {
wx.navigateTo({
url: '/pages/MDmaterial/MDmaterial' // 物料主数据
});
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
// 在这里调用API显示提示框
wx.showToast({
title: '已经到底部了', // 提示的内容
icon: 'none', // 图标,'success'、'loading'等,默认无图标
duration: 2000 // 提示的延迟时间,单位毫秒,默认1500
});
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<view class="container">
<view class="banner">
<swiper indicator-dots="true" autoplay="true">
<swiper-item>
<image class="avatar" src="/images/banner1.jpg"></image>
</swiper-item>
<swiper-item>
<image src="/images/banner1.jpg"></image>
</swiper-item>
<swiper-item>
<image src="/images/banner1.jpg"></image>
</swiper-item>
</swiper>
</view>
<view class="menu">
<view class="menu-item">
<image src="/images/menu1.jpg"></image>
<text>主数据管理</text>
</view>
<view class="menu-item">
<image src="/images/menu1.jpg"></image>
<text>采购管理</text>
</view>
<view class="menu-item">
<image src="/images/menu1.jpg"></image>
<text>销售管理</text>
</view>
<view class="menu-item">
<image src="/images/menu1.jpg"></image>
<text>库存管理</text>
</view>
</view>
<view class="content">
<view class="section">
<view class="section-title">主数据管理</view>
<view class="card-group">
<view class="card">
<image src="/images/card1.jpg" bindtap="goToMDmaterial"></image>
<text class="card-title">物料主数据</text>
</view>
<view class="card">
<image src="/images/card1.jpg"></image>
<text class="card-title">客户主数据</text>
</view>
<view class="card">
<image src="/images/card1.jpg"></image>
<text class="card-title">供应商主数据</text>
</view>
</view>
<view class="card-group">
<view class="card">
<image src="/images/card1.jpg"></image>
<text class="card-title">银行主数据</text>
</view>
<view class="card">
<image src="/images/card1.jpg"></image>
<text class="card-title">设备主数据</text>
</view>
<view class="card">
<image src="/images/card1.jpg"></image>
<text class="card-title">其它主数据</text>
</view>
</view>
</view>
<view class="section">
<view class="section-title">供应链管理-对内</view>
<view class="card-group">
<view class="card">
<image src="/images/card1.jpg"></image>
<text class="card-title">采购计划</text>
</view>
<view class="card">
<image src="/images/card1.jpg"></image>
<text class="card-title">采购订单</text>
</view>
<view class="card">
<image src="/images/card1.jpg"></image>
<text class="card-title">库存管理</text>
</view>
</view>
</view>
<view class="section">
<view class="section-title">供应链管理-对外</view>
<view class="card-group">
<view class="card">
<image src="/images/card1.jpg"></image>
<text class="card-title">销售订单</text>
</view>
<view class="card">
<image src="/images/card1.jpg"></image>
<text class="card-title">外向交货</text>
</view>
<view class="card">
<image src="/images/card1.jpg"></image>
<text class="card-title">生产出库</text>
</view>
</view>
</view>
<view class="section">
<view class="section-title">系统管理</view>
<view class="card-group">
<view class="card">
<image src="/images/card1.jpg"></image>
<text class="card-title">其它管理</text>
</view>
<view class="card">
<image src="/images/card1.jpg" bindtap="goToPasslist"></image>
<text class="card-title">用户管理</text>
</view>
<view class="card">
<image src="/images/card1.jpg"></image>
<text class="card-title">其它</text>
</view>
</view>
</view>
<view class="section">
<view class="section-title">管理主题</view>
<view class="topic-group">
<view class="topic">
<image src="/images/topic1.jpg"></image>
<text class="topic-title">成品控制</text>
</view>
<view class="topic">
<image src="/images/topic1.jpg"></image>
<text class="topic-title">获客</text>
</view>
</view>
</view>
</view>
<view class="footer">
<text class="info">版权所有 © 林涛</text>
</view>
</view>
\ No newline at end of file
// pages/logo/logo.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
setTimeout(() => {
wx.navigateTo({
//url: '/pages/index/index'
url: '/pages/item/item'
});
}, 1000);
},
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<!--pages/logo/logo.wxml-->
<view class="container">
<image src="/pages/images/contoursw.jpg" class="image-style"></image>
</view>
\ No newline at end of file
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
\ No newline at end of file
page {
height: 100vh;
display: flex;
flex-direction: column;
}
.scrollarea {
flex: 1;
overflow-y: hidden;
}
.log-item {
margin-top: 20rpx;
text-align: center;
}
.log-item:last-child {
padding-bottom: env(safe-area-inset-bottom);
}
// logs.ts
// const util = require('../../utils/util.js')
import { formatTime } from '../../utils/util'
Component({
data: {
logs: [],
},
lifetimes: {
attached() {
this.setData({
logs: (wx.getStorageSync('logs') || []).map((log: string) => {
return {
date: formatTime(new Date(log)),
timeStamp: log
}
}),
})
}
},
})
<!--logs.wxml-->
<navigation-bar title="查看启动日志" back="{{true}}" color="black" background="#FFF"></navigation-bar>
<scroll-view class="scrollarea" scroll-y type="list">
<block wx:for="{{logs}}" wx:key="timeStamp" wx:for-item="log">
<view class="log-item">{{index + 1}}. {{log.date}}</view>
</block>
</scroll-view>
{
"usingComponents": {}
}
\ No newline at end of file
/* pages/message/message.wxss */
\ No newline at end of file
// pages/message/message.ts
Page({
/**
* 页面的初始数据
*/
data: {
query: {}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log('执行onLoad')
this.setData({
query: options
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
console.log('执行message onReady')
wx.setNavigationBarTitle({
title: '消息',
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<!--pages/message/message.wxml-->
<text>pages/message/message.wxml</text>
\ No newline at end of file
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
\ No newline at end of file
.container {
padding: 20px;
}
.input{
margin: 10px 0;
}
.textlist {
display: flex;
justify-content: space-between;
align-items: left;
padding: 10px;
height: 100px;
width: 100%;
}
.form-container{
display: grid;
width:100%;
padding: 10px;
}
.list-container{
display: grid;
width:100%;
}
.list-container .item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
border-bottom: 1px solid #ccc;
}
.button{
display: flex;
margin-left: 10px;
width: 50%;
}
// pages/passlist/passlist.ts
Page({
/**
* 页面的初始数据
*/
data: {
name:'',
age:'',
formData: {
name: '',
age: ''
},
// 初始时,items数组为空
items: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
this.loadItems();
},
bindNameInput: function(e:any) {
console.log(e.detail.value);
this.setData({
'formData.name': e.detail.value
});
},
bindAgeInput: function(e:any) {
this.setData({
'formData.age': e.detail.value
});
},
addOrUpdateItem: function(e:any) {
const { name, age } = this.data.formData;
if (!name || !age) return wx.showToast({ title: '请填写完整信息', icon: 'none' });
let item = {
name: name,
age: age
};
// 尝试从本地存储中获取'items'
let storedItems = wx.getStorageSync('items');
// 检查storedItems是否为null(或undefined,但wx.getStorageSync不会返回undefined)
const itemslist = storedItems ? JSON.parse(storedItems) : [];
// 使用Object.keys()来获取所有键,并计算它们的数量
let recordCount = Object.keys(itemslist).length;
// 将新记录添加到itemsList对象中,使用新记录的ID作为键
itemslist[recordCount.toString()] = item;
this.saveItems(itemslist);
},
editItem: function(e:any) {
const index = e.currentTarget.dataset.index;
const item = this.data.items[index];
console.log(typeof item);
this.setData({
//这里会报错:类型“never”上不存在属性“name”。这不影响传值。不用理会报错。
formData: { name: item.name, age: item.age }
});
},
deleteItem: function(e:any) {
const index = e.currentTarget.dataset.index;
const items = [...this.data.items];
items.splice(index, 1);
this.setData({
items:items
});
this.saveItems(items);
},
saveItems: function(itemslist:any) {
console.log('保存');
wx.setStorageSync('items', JSON.stringify(itemslist));
let storedItems = wx.getStorageSync('items');
// 检查storedItems是否为null(或undefined,但wx.getStorageSync不会返回undefined)
const itemslist1 = storedItems ? JSON.parse(storedItems) : [];
//var itemslist = wx.getStorageSync('items');
this.setData({
items:itemslist
});
},
loadItems: function() {
// 尝试从本地存储中获取'items'
const storedItems = wx.getStorageSync('items');
//console.log('storedItems:'+storedItems);
// 检查storedItems是否为null(或undefined,但wx.getStorageSync不会返回undefined)
// 如果是null,则默认为空数组;否则,尝试解析JSON字符串为数组
const itemslist = storedItems ? JSON.parse(storedItems) : [];
//if(itemslist)
//console.log('itemslist:'+itemslist);
// 更新页面的items数据
this.setData({
items:itemslist
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
wx.setNavigationBarTitle({
title: '用户管理',
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
// 在这里调用API显示提示框
wx.showToast({
title: '人家是有底线的。', // 提示的内容
icon: 'none', // 图标,'success'、'loading'等,默认无图标
duration: 2000 // 提示的延迟时间,单位毫秒,默认1500
});
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<!--要使用微信开发者工具创建一个包含新增、修改、删除功能的表单,并可以保存到本地以及从本地读取之前保存的记录-->
<navigation-bar title="用户管理" back="{{false}}" color="black" background="#FFF"></navigation-bar>
<view class="container">
<view class="form-container">
<input type="text" class="input" placeholder="请输入用户名" bindinput="bindNameInput" value="{{formData.name}}"/>
<input type="text" class="input" placeholder="请输入密码" bindinput="bindAgeInput" value="{{formData.age}}"/>
<button bindtap="addOrUpdateItem">保存</button>
</view>
<view class="list-container">
<block wx:for="{{items}}" wx:key="index">
<view class="item">
<text type='text' class='textlist'>{{item.name}} - {{item.age}}</text>
</view>
<view class="button">
<button bindtap="editItem" data-index="{{index}}">编辑</button>
<button bindtap="deleteItem" data-index="{{index}}">删除</button>
</view>
</block>
</view>
</view>
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
/* pages/scanCode/scanCode.wxss */
\ No newline at end of file
// pages/scanCode/scanCode.ts
Page({
/**
* 页面的初始数据
*/
data: {
result: ''
},
scanCode: function() {
wx.scanCode({
success: (res) => {
this.setData({
result: res.result
})
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
<!--pages/scanCode/scanCode.wxml-->
<view class="container">
<text>pages/scanCode/scanCode.wxml</text>
<view>
<button bindtap="scanCode" type="primary">扫描二维码</button>
<view wx:if="{{result}}">
<text>扫描结果:{{result}}</text>
</view>
</view>
</view>
\ No newline at end of file
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}
\ No newline at end of file
export const formatTime = (date: Date) => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return (
[year, month, day].map(formatNumber).join('/') +
' ' +
[hour, minute, second].map(formatNumber).join(':')
)
}
const formatNumber = (n: number) => {
const s = n.toString()
return s[1] ? s : '0' + s
}
{
"name": "miniprogram-ts-less-quickstart",
"version": "1.0.0",
"description": "",
"scripts": {
},
"keywords": [],
"author": "",
"license": "",
"dependencies": {
},
"devDependencies": {
"miniprogram-api-typings": "^2.8.3-1"
}
}
{
"description": "项目配置文件",
"miniprogramRoot": "miniprogram/",
"compileType": "miniprogram",
"setting": {
"useCompilerPlugins": [
"typescript",
"less"
],
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"coverView": false,
"postcss": false,
"minified": false,
"enhance": false,
"showShadowRootInWxmlPanel": false,
"packNpmRelationList": [],
"ignoreUploadUnusedFiles": true,
"compileHotReLoad": false,
"skylineRenderEnable": true
},
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {},
"srcMiniprogramRoot": "miniprogram/",
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
},
"libVersion": "2.32.3",
"packOptions": {
"ignore": [],
"include": []
},
"appid": "wxf74b9d8d1f5a59dc"
}
\ No newline at end of file
{
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "miniprogram-1",
"setting": {
"compileHotReLoad": true
}
}
\ No newline at end of file
{
"compilerOptions": {
"strictNullChecks": true,
"noImplicitAny": true,
"module": "CommonJS",
"target": "ES2020",
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"strictPropertyInitialization": true,
"lib": ["ES2020"],
"typeRoots": [
"./typings"
]
},
"include": [
"./**/*.ts"
],
"exclude": [
"node_modules"
]
}
/// <reference path="./types/index.d.ts" />
interface IAppOption {
globalData: {
userInfo?: WechatMiniprogram.UserInfo,
}
userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback,
}
\ No newline at end of file
/// <reference path="./wx/index.d.ts" />
/*! *****************************************************************************
Copyright (c) 2023 Tencent, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***************************************************************************** */
/// <reference path="./lib.wx.app.d.ts" />
/// <reference path="./lib.wx.page.d.ts" />
/// <reference path="./lib.wx.api.d.ts" />
/// <reference path="./lib.wx.cloud.d.ts" />
/// <reference path="./lib.wx.canvas.d.ts" />
/// <reference path="./lib.wx.component.d.ts" />
/// <reference path="./lib.wx.behavior.d.ts" />
/// <reference path="./lib.wx.event.d.ts" />
/// <reference path="./lib.wx.wasm.d.ts" />
declare namespace WechatMiniprogram {
type IAnyObject = Record<string, any>
type Optional<F> = F extends (arg: infer P) => infer R ? (arg?: P) => R : F
type OptionalInterface<T> = { [K in keyof T]: Optional<T[K]> }
interface AsyncMethodOptionLike {
success?: (...args: any[]) => void
}
type PromisifySuccessResult<
P,
T extends AsyncMethodOptionLike
> = P extends {
success: any
}
? void
: P extends { fail: any }
? void
: P extends { complete: any }
? void
: Promise<Parameters<Exclude<T['success'], undefined>>[0]>
// TODO: Extract real definition from `lib.dom.d.ts` to replace this
type IIRFilterNode = any
type WaveShaperNode = any
type ConstantSourceNode = any
type OscillatorNode = any
type GainNode = any
type BiquadFilterNode = any
type PeriodicWaveNode = any
type AudioNode = any
type ChannelSplitterNode = any
type ChannelMergerNode = any
type DelayNode = any
type DynamicsCompressorNode = any
type ScriptProcessorNode = any
type PannerNode = any
type AnalyserNode = any
type AudioListener = any
type WebGLTexture = any
type WebGLRenderingContext = any
// TODO: fill worklet type
type WorkletFunction = (...args: any) => any
type AnimationObject = any
type SharedValue<T = any> = T
type DerivedValue<T = any> = T
}
declare let console: WechatMiniprogram.Console
declare let wx: WechatMiniprogram.Wx
/** 引入模块。返回模块通过 `module.exports` 或 `exports` 暴露的接口。 */
interface Require {
(
/** 需要引入模块文件相对于当前文件的相对路径,或 npm 模块名,或 npm 模块路径。不支持绝对路径 */
module: string,
/** 用于异步获取其他分包中的模块的引用结果,详见 [分包异步化]((subpackages/async)) */
callback?: (moduleExport: any) => void,
/** 异步获取分包失败时的回调,详见 [分包异步化]((subpackages/async)) */
errorCallback?: (err: any) => void
): any
/** 以 Promise 形式异步引入模块。返回模块通过 `module.exports` 或 `exports` 暴露的接口。 */
async(
/** 需要引入模块文件相对于当前文件的相对路径,或 npm 模块名,或 npm 模块路径。不支持绝对路径 */
module: string
): Promise<any>
}
declare const require: Require
/** 引入插件。返回插件通过 `main` 暴露的接口。 */
interface RequirePlugin {
(
/** 需要引入的插件的 alias */
module: string,
/** 用于异步获取其他分包中的插件的引用结果,详见 [分包异步化]((subpackages/async)) */
callback?: (pluginExport: any) => void
): any
/** 以 Promise 形式异步引入插件。返回插件通过 `main` 暴露的接口。 */
async(
/** 需要引入的插件的 alias */
module: string
): Promise<any>
}
declare const requirePlugin: RequirePlugin
/** 插件引入当前使用者小程序。返回使用者小程序通过 [插件配置中 `export` 暴露的接口](https://developers.weixin.qq.com/miniprogram/dev/framework/plugin/using.html#%E5%AF%BC%E5%87%BA%E5%88%B0%E6%8F%92%E4%BB%B6)。
*
* 该接口只在插件中存在
*
* 最低基础库: `2.11.1` */
declare function requireMiniProgram(): any
/** 当前模块对象 */
declare let module: {
/** 模块向外暴露的对象,使用 `require` 引用该模块时可以获取 */
exports: any
}
/** `module.exports` 的引用 */
declare let exports: any
/** [clearInterval(number intervalID)](https://developers.weixin.qq.com/miniprogram/dev/api/base/timer/clearInterval.html)
*
* 取消由 setInterval 设置的定时器。 */
declare function clearInterval(
/** 要取消的定时器的 ID */
intervalID: number
): void
/** [clearTimeout(number timeoutID)](https://developers.weixin.qq.com/miniprogram/dev/api/base/timer/clearTimeout.html)
*
* 取消由 setTimeout 设置的定时器。 */
declare function clearTimeout(
/** 要取消的定时器的 ID */
timeoutID: number
): void
/** [number setInterval(function callback, number delay, any rest)](https://developers.weixin.qq.com/miniprogram/dev/api/base/timer/setInterval.html)
*
* 设定一个定时器。按照指定的周期(以毫秒计)来执行注册的回调函数 */
declare function setInterval(
/** 回调函数 */
callback: (...args: any[]) => any,
/** 执行回调函数之间的时间间隔,单位 ms。 */
delay?: number,
/** param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 */
rest?: any
): number
/** [number setTimeout(function callback, number delay, any rest)](https://developers.weixin.qq.com/miniprogram/dev/api/base/timer/setTimeout.html)
*
* 设定一个定时器。在定时到期以后执行注册的回调函数 */
declare function setTimeout(
/** 回调函数 */
callback: (...args: any[]) => any,
/** 延迟的时间,函数的调用会在该延迟之后发生,单位 ms。 */
delay?: number,
/** param1, param2, ..., paramN 等附加参数,它们会作为参数传递给回调函数。 */
rest?: any
): number
因为 它太大了无法显示 source diff 。你可以改为 查看blob
/*! *****************************************************************************
Copyright (c) 2023 Tencent, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***************************************************************************** */
declare namespace WechatMiniprogram.App {
type SceneValues =
| 1000
| 1001
| 1005
| 1006
| 1007
| 1008
| 1010
| 1011
| 1012
| 1013
| 1014
| 1017
| 1019
| 1020
| 1022
| 1023
| 1024
| 1025
| 1026
| 1027
| 1028
| 1029
| 1030
| 1031
| 1032
| 1034
| 1035
| 1036
| 1037
| 1038
| 1039
| 1042
| 1043
| 1044
| 1045
| 1046
| 1047
| 1048
| 1049
| 1052
| 1053
| 1054
| 1056
| 1057
| 1058
| 1059
| 1060
| 1064
| 1065
| 1067
| 1068
| 1069
| 1071
| 1072
| 1073
| 1074
| 1077
| 1078
| 1079
| 1081
| 1082
| 1084
| 1088
| 1089
| 1090
| 1091
| 1092
| 1095
| 1096
| 1097
| 1099
| 1100
| 1101
| 1102
| 1103
| 1104
| 1106
| 1107
| 1113
| 1114
| 1119
| 1120
| 1121
| 1124
| 1125
| 1126
| 1129
| 1131
| 1133
| 1135
| 1144
| 1145
| 1146
| 1148
| 1150
| 1151
| 1152
| 1153
| 1154
| 1155
| 1157
| 1158
| 1160
| 1167
| 1168
| 1169
| 1171
| 1173
| 1175
| 1176
| 1177
| 1178
| 1179
| 1181
| 1183
| 1184
| 1185
| 1186
| 1187
| 1189
| 1191
| 1192
| 1193
| 1194
| 1195
| 1196
| 1197
| 1198
| 1200
| 1201
| 1202
| 1203
| 1206
| 1207
| 1208
| 1212
| 1215
| 1216
| 1223
| 1228
| 1231
interface LaunchShowOption {
/** 打开小程序的路径 */
path: string
/** 打开小程序的query */
query: IAnyObject
/** 打开小程序的场景值
* - 1000:其他
* - 1001:发现栏小程序主入口,「最近使用」列表(基础库 2.2.4 版本起包含「我的小程序」列表)
* - 1005:微信首页顶部搜索框的搜索结果页
* - 1006:发现栏小程序主入口搜索框的搜索结果页
* - 1007:单人聊天会话中的小程序消息卡片
* - 1008:群聊会话中的小程序消息卡片
* - 1010:收藏夹
* - 1011:扫描二维码
* - 1012:长按图片识别二维码
* - 1013:扫描手机相册中选取的二维码
* - 1014:小程序订阅消息(与 1107 相同)
* - 1017:前往小程序体验版的入口页
* - 1019:微信钱包(微信客户端 7.0.0 版本改为支付入口)
* - 1020:公众号 profile 页相关小程序列表(已废弃)
* - 1022:聊天顶部置顶小程序入口(微信客户端 6.6.1 版本起废弃)
* - 1023:安卓系统桌面图标
* - 1024:小程序 profile 页
* - 1025:扫描一维码
* - 1026:发现栏小程序主入口,「附近的小程序」列表
* - 1027:微信首页顶部搜索框搜索结果页「使用过的小程序」列表
* - 1028:我的卡包
* - 1029:小程序中的卡券详情页
* - 1030:自动化测试下打开小程序
* - 1031:长按图片识别一维码
* - 1032:扫描手机相册中选取的一维码
* - 1034:微信支付完成页
* - 1035:公众号自定义菜单
* - 1036:App 分享消息卡片
* - 1037:小程序打开小程序
* - 1038:从另一个小程序返回
* - 1039:摇电视
* - 1042:添加好友搜索框的搜索结果页
* - 1043:公众号模板消息
* - 1044:带 shareTicket 的小程序消息卡片 [详情](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html)
* - 1045:朋友圈广告
* - 1046:朋友圈广告详情页
* - 1047:扫描小程序码
* - 1048:长按图片识别小程序码
* - 1049:扫描手机相册中选取的小程序码
* - 1052:卡券的适用门店列表
* - 1053:搜一搜的结果页
* - 1054:顶部搜索框小程序快捷入口(微信客户端版本 6.7.4 起废弃)
* - 1056:聊天顶部音乐播放器右上角菜单
* - 1057:钱包中的银行卡详情页
* - 1058:公众号文章
* - 1059:体验版小程序绑定邀请页
* - 1060:微信支付完成页(与 1034 相同)
* - 1064:微信首页连 Wi-Fi 状态栏
* - 1065:URL scheme [详情](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/url-scheme.html)
* - 1067:公众号文章广告
* - 1068:附近小程序列表广告(已废弃)
* - 1069:移动应用通过 openSDK 进入微信,打开小程序
* - 1071:钱包中的银行卡列表页
* - 1072:二维码收款页面
* - 1073:客服消息列表下发的小程序消息卡片
* - 1074:公众号会话下发的小程序消息卡片
* - 1077:摇周边
* - 1078:微信连 Wi-Fi 成功提示页
* - 1079:微信游戏中心
* - 1081:客服消息下发的文字链
* - 1082:公众号会话下发的文字链
* - 1084:朋友圈广告原生页
* - 1088:会话中查看系统消息,打开小程序
* - 1089:微信聊天主界面下拉,「最近使用」栏(基础库 2.2.4 版本起包含「我的小程序」栏)
* - 1090:长按小程序右上角菜单唤出最近使用历史
* - 1091:公众号文章商品卡片
* - 1092:城市服务入口
* - 1095:小程序广告组件
* - 1096:聊天记录,打开小程序
* - 1097:微信支付签约原生页,打开小程序
* - 1099:页面内嵌插件
* - 1100:红包封面详情页打开小程序
* - 1101:远程调试热更新(开发者工具中,预览 -> 自动预览 -> 编译并预览)
* - 1102:公众号 profile 页服务预览
* - 1103:发现栏小程序主入口,「我的小程序」列表(基础库 2.2.4 版本起废弃)
* - 1104:微信聊天主界面下拉,「我的小程序」栏(基础库 2.2.4 版本起废弃)
* - 1106:聊天主界面下拉,从顶部搜索结果页,打开小程序
* - 1107:订阅消息,打开小程序
* - 1113:安卓手机负一屏,打开小程序(三星)
* - 1114:安卓手机侧边栏,打开小程序(三星)
* - 1119:【企业微信】工作台内打开小程序
* - 1120:【企业微信】个人资料页内打开小程序
* - 1121:【企业微信】聊天加号附件框内打开小程序
* - 1124:扫“一物一码”打开小程序
* - 1125:长按图片识别“一物一码”
* - 1126:扫描手机相册中选取的“一物一码”
* - 1129:微信爬虫访问 [详情](https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/sitemap.html)
* - 1131:浮窗(8.0 版本起仅包含被动浮窗)
* - 1133:硬件设备打开小程序 [详情](https://developers.weixin.qq.com/doc/oplatform/Miniprogram_Frame/)
* - 1135:小程序 profile 页相关小程序列表,打开小程序
* - 1144:公众号文章 - 视频贴片
* - 1145:发现栏 - 发现小程序
* - 1146:地理位置信息打开出行类小程序
* - 1148:卡包-交通卡,打开小程序
* - 1150:扫一扫商品条码结果页打开小程序
* - 1151:发现栏 - 我的订单
* - 1152:订阅号视频打开小程序
* - 1153:“识物”结果页打开小程序
* - 1154:朋友圈内打开“单页模式”
* - 1155:“单页模式”打开小程序
* - 1157:服务号会话页打开小程序
* - 1158:群工具打开小程序
* - 1160:群待办
* - 1167:H5 通过开放标签打开小程序 [详情](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html)
* - 1168:移动应用直接运行小程序
* - 1169:发现栏小程序主入口,各个生活服务入口(例如快递服务、出行服务等)
* - 1171:微信运动记录(仅安卓)
* - 1173:聊天素材用小程序打开 [详情](https://developers.weixin.qq.com/miniprogram/dev/framework/material/support_material.html)
* - 1175:视频号主页商店入口
* - 1176:视频号直播间主播打开小程序
* - 1177:视频号直播商品
* - 1178:在电脑打开手机上打开的小程序
* - 1179:#话题页打开小程序
* - 1181:网站应用打开 PC 小程序
* - 1183:PC 微信 - 小程序面板 - 发现小程序 - 搜索
* - 1184:视频号链接打开小程序
* - 1185:群公告
* - 1186:收藏 - 笔记
* - 1187:浮窗(8.0 版本起)
* - 1189:表情雨广告
* - 1191:视频号活动
* - 1192:企业微信联系人 profile 页
* - 1193:视频号主页服务菜单打开小程序
* - 1194:URL Link [详情](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/url-link.html)
* - 1195:视频号主页商品 tab
* - 1196:个人状态打开小程序
* - 1197:视频号主播从直播间返回小游戏
* - 1198:视频号开播界面打开小游戏
* - 1200:视频号广告打开小程序
* - 1201:视频号广告详情页打开小程序
* - 1202:企微客服号会话打开小程序卡片
* - 1203:微信小程序压测工具的请求
* - 1206:视频号小游戏直播间打开小游戏
* - 1207:企微客服号会话打开小程序文字链
* - 1208:聊天打开商品卡片
* - 1212:青少年模式申请页打开小程序
* - 1215:广告预约打开小程序
* - 1216:视频号订单中心打开小程序
* - 1223:安卓桌面 Widget 打开小程序
* - 1228:视频号原生广告组件打开小程序
* - 1231:动态消息提醒入口打开小程序
*/
scene: SceneValues
/** shareTicket,详见 [获取更多转发信息]((转发#获取更多转发信息)) */
shareTicket: string
/** 当场景为由从另一个小程序或公众号或App打开时,返回此字段 */
referrerInfo?: ReferrerInfo
}
interface PageNotFoundOption {
/** 不存在页面的路径 */
path: string
/** 打开不存在页面的 query */
query: IAnyObject
/** 是否本次启动的首个页面(例如从分享等入口进来,首个页面是开发者配置的分享页面) */
isEntryPage: boolean
}
interface Option {
/** 生命周期回调—监听小程序初始化
*
* 小程序初始化完成时触发,全局只触发一次。
*/
onLaunch(options: LaunchShowOption): void
/** 生命周期回调—监听小程序显示
*
* 小程序启动,或从后台进入前台显示时
*/
onShow(options: LaunchShowOption): void
/** 生命周期回调—监听小程序隐藏
*
* 小程序从前台进入后台时
*/
onHide(): void
/** 错误监听函数
*
* 小程序发生脚本错误,或者 api
*/
onError(/** 错误信息,包含堆栈 */ error: string): void
/** 页面不存在监听函数
*
* 小程序要打开的页面不存在时触发,会带上页面信息回调该函数
*
* **注意:**
* 1. 如果开发者没有添加 `onPageNotFound` 监听,当跳转页面不存在时,将推入微信客户端原生的页面不存在提示页面。
* 2. 如果 `onPageNotFound` 回调中又重定向到另一个不存在的页面,将推入微信客户端原生的页面不存在提示页面,并且不再回调 `onPageNotFound`。
*
* 最低基础库: 1.9.90
*/
onPageNotFound(options: PageNotFoundOption): void
/**
* 小程序有未处理的 Promise 拒绝时触发。也可以使用 [wx.onUnhandledRejection](https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onUnhandledRejection.html) 绑定监听。注意事项请参考 [wx.onUnhandledRejection](https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onUnhandledRejection.html)。
* **参数**:与 [wx.onUnhandledRejection](https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onUnhandledRejection.html) 一致
*/
onUnhandledRejection: OnUnhandledRejectionCallback
/**
* 系统切换主题时触发。也可以使用 wx.onThemeChange 绑定监听。
*
* 最低基础库: 2.11.0
*/
onThemeChange: OnThemeChangeCallback
}
type Instance<T extends IAnyObject> = Option & T
type Options<T extends IAnyObject> = Partial<Option> &
T &
ThisType<Instance<T>>
type TrivialInstance = Instance<IAnyObject>
interface Constructor {
<T extends IAnyObject>(options: Options<T>): void
}
interface GetAppOption {
/** 在 `App` 未定义时返回默认实现。当App被调用时,默认实现中定义的属性会被覆盖合并到App中。一般用于独立分包
*
* 最低基础库: 2.2.4
*/
allowDefault?: boolean
}
interface GetApp {
<T extends IAnyObject = IAnyObject>(opts?: GetAppOption): Instance<T>
}
}
declare let App: WechatMiniprogram.App.Constructor
declare let getApp: WechatMiniprogram.App.GetApp
/*! *****************************************************************************
Copyright (c) 2023 Tencent, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***************************************************************************** */
declare namespace WechatMiniprogram.Behavior {
type BehaviorIdentifier = string
type Instance<
TData extends DataOption,
TProperty extends PropertyOption,
TMethod extends MethodOption,
TCustomInstanceProperty extends IAnyObject = Record<string, never>
> = Component.Instance<TData, TProperty, TMethod, TCustomInstanceProperty>
type TrivialInstance = Instance<IAnyObject, IAnyObject, IAnyObject>
type TrivialOption = Options<IAnyObject, IAnyObject, IAnyObject>
type Options<
TData extends DataOption,
TProperty extends PropertyOption,
TMethod extends MethodOption,
TCustomInstanceProperty extends IAnyObject = Record<string, never>
> = Partial<Data<TData>> &
Partial<Property<TProperty>> &
Partial<Method<TMethod>> &
Partial<OtherOption> &
Partial<Lifetimes> &
ThisType<Instance<TData, TProperty, TMethod, TCustomInstanceProperty>>
interface Constructor {
<
TData extends DataOption,
TProperty extends PropertyOption,
TMethod extends MethodOption,
TCustomInstanceProperty extends IAnyObject = Record<string, never>
>(
options: Options<TData, TProperty, TMethod, TCustomInstanceProperty>
): BehaviorIdentifier
}
type DataOption = Component.DataOption
type PropertyOption = Component.PropertyOption
type MethodOption = Component.MethodOption
type Data<D extends DataOption> = Component.Data<D>
type Property<P extends PropertyOption> = Component.Property<P>
type Method<M extends MethodOption> = Component.Method<M>
type DefinitionFilter = Component.DefinitionFilter
type Lifetimes = Component.Lifetimes
type OtherOption = Omit<Component.OtherOption, 'options'>
}
/** 注册一个 `behavior`,接受一个 `Object` 类型的参数。*/
declare let Behavior: WechatMiniprogram.Behavior.Constructor
/*! *****************************************************************************
Copyright (c) 2023 Tencent, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***************************************************************************** */
/* eslint-disable @typescript-eslint/naming-convention */
declare namespace WechatMiniprogram.CanvasRenderingContext {
type CanvasDirection = 'inherit' | 'ltr' | 'rtl'
type CanvasFillRule = 'evenodd' | 'nonzero'
type CanvasFontKerning = 'auto' | 'none' | 'normal'
type CanvasFontStretch =
| 'condensed'
| 'expanded'
| 'extra-condensed'
| 'extra-expanded'
| 'normal'
| 'semi-condensed'
| 'semi-expanded'
| 'ultra-condensed'
| 'ultra-expanded'
type CanvasFontVariantCaps =
| 'all-petite-caps'
| 'all-small-caps'
| 'normal'
| 'petite-caps'
| 'small-caps'
| 'titling-caps'
| 'unicase'
type CanvasLineCap = 'butt' | 'round' | 'square'
type CanvasLineJoin = 'bevel' | 'miter' | 'round'
type CanvasTextAlign = 'center' | 'end' | 'left' | 'right' | 'start'
type CanvasTextBaseline =
| 'alphabetic'
| 'bottom'
| 'hanging'
| 'ideographic'
| 'middle'
| 'top'
type CanvasTextRendering =
| 'auto'
| 'geometricPrecision'
| 'optimizeLegibility'
| 'optimizeSpeed'
type GlobalCompositeOperation =
| 'color'
| 'color-burn'
| 'color-dodge'
| 'copy'
| 'darken'
| 'destination-atop'
| 'destination-in'
| 'destination-out'
| 'destination-over'
| 'difference'
| 'exclusion'
| 'hard-light'
| 'hue'
| 'lighten'
| 'lighter'
| 'luminosity'
| 'multiply'
| 'overlay'
| 'saturation'
| 'screen'
| 'soft-light'
| 'source-atop'
| 'source-in'
| 'source-out'
| 'source-over'
| 'xor'
interface CanvasCompositing {
globalAlpha: number
globalCompositeOperation: GlobalCompositeOperation
}
type CanvasImageSource = VideoContext | Canvas | Image | OffscreenCanvas
interface CanvasDrawImage {
drawImage(image: CanvasImageSource, dx: number, dy: number): void
drawImage(
image: CanvasImageSource,
dx: number,
dy: number,
dw: number,
dh: number
): void
drawImage(
image: CanvasImageSource,
sx: number,
sy: number,
sw: number,
sh: number,
dx: number,
dy: number,
dw: number,
dh: number
): void
}
interface CanvasDrawPath {
beginPath(): void
clip(fillRule?: CanvasFillRule): void
clip(path: Path2D, fillRule?: CanvasFillRule): void
fill(fillRule?: CanvasFillRule): void
fill(path: Path2D, fillRule?: CanvasFillRule): void
isPointInPath(x: number, y: number, fillRule?: CanvasFillRule): boolean
isPointInPath(
path: Path2D,
x: number,
y: number,
fillRule?: CanvasFillRule
): boolean
isPointInStroke(x: number, y: number): boolean
isPointInStroke(path: Path2D, x: number, y: number): boolean
stroke(): void
stroke(path: Path2D): void
}
interface CanvasFillStrokeStyles {
fillStyle: string | CanvasGradient | CanvasPattern
strokeStyle: string | CanvasGradient | CanvasPattern
createConicGradient(
startAngle: number,
x: number,
y: number
): CanvasGradient
createLinearGradient(
x0: number,
y0: number,
x1: number,
y1: number
): CanvasGradient
createPattern(
image: CanvasImageSource,
repetition: string | null
): CanvasPattern | null
createRadialGradient(
x0: number,
y0: number,
r0: number,
x1: number,
y1: number,
r1: number
): CanvasGradient
}
interface CanvasFilters {
filter: string
}
/** An opaque object describing a gradient. It is returned by the methods CanvasRenderingContext2D.createLinearGradient() or CanvasRenderingContext2D.createRadialGradient(). */
interface CanvasGradient {
/**
* Adds a color stop with the given color to the gradient at the given offset. 0.0 is the offset at one end of the gradient, 1.0 is the offset at the other end.
*
* Throws an "IndexSizeError" DOMException if the offset is out of range. Throws a "SyntaxError" DOMException if the color cannot be parsed.
*/
addColorStop(offset: number, color: string): void
}
type PredefinedColorSpace = 'display-p3' | 'srgb'
interface ImageDataSettings {
colorSpace?: PredefinedColorSpace
}
interface CanvasImageData {
createImageData(
sw: number,
sh: number,
settings?: ImageDataSettings
): ImageData
createImageData(imagedata: ImageData): ImageData
getImageData(
sx: number,
sy: number,
sw: number,
sh: number,
settings?: ImageDataSettings
): ImageData
putImageData(imagedata: ImageData, dx: number, dy: number): void
putImageData(
imagedata: ImageData,
dx: number,
dy: number,
dirtyX: number,
dirtyY: number,
dirtyWidth: number,
dirtyHeight: number
): void
}
type ImageSmoothingQuality = 'high' | 'low' | 'medium'
interface CanvasImageSmoothing {
imageSmoothingEnabled: boolean
imageSmoothingQuality: ImageSmoothingQuality
}
interface CanvasPath {
arc(
x: number,
y: number,
radius: number,
startAngle: number,
endAngle: number,
counterclockwise?: boolean
): void
arcTo(
x1: number,
y1: number,
x2: number,
y2: number,
radius: number
): void
bezierCurveTo(
cp1x: number,
cp1y: number,
cp2x: number,
cp2y: number,
x: number,
y: number
): void
closePath(): void
ellipse(
x: number,
y: number,
radiusX: number,
radiusY: number,
rotation: number,
startAngle: number,
endAngle: number,
counterclockwise?: boolean
): void
lineTo(x: number, y: number): void
moveTo(x: number, y: number): void
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
rect(x: number, y: number, w: number, h: number): void
roundRect(
x: number,
y: number,
w: number,
h: number,
radii?: number | number[]
): void
}
interface CanvasPathDrawingStyles {
lineCap: CanvasLineCap
lineDashOffset: number
lineJoin: CanvasLineJoin
lineWidth: number
miterLimit: number
getLineDash(): number[]
setLineDash(segments: number[]): void
}
interface DOMMatrix2DInit {
a?: number
b?: number
c?: number
d?: number
e?: number
f?: number
m11?: number
m12?: number
m21?: number
m22?: number
m41?: number
m42?: number
}
/** An opaque object describing a pattern, based on an image, a canvas, or a video, created by the CanvasRenderingContext2D.createPattern() method. */
interface CanvasPattern {
/** Sets the transformation matrix that will be used when rendering the pattern during a fill or stroke painting operation. */
setTransform(transform?: DOMMatrix2DInit): void
}
interface CanvasRect {
clearRect(x: number, y: number, w: number, h: number): void
fillRect(x: number, y: number, w: number, h: number): void
strokeRect(x: number, y: number, w: number, h: number): void
}
interface CanvasShadowStyles {
shadowBlur: number
shadowColor: string
shadowOffsetX: number
shadowOffsetY: number
}
interface CanvasState {
restore(): void
save(): void
}
/** The dimensions of a piece of text in the canvas, as created by the CanvasRenderingContext2D.measureText() method. */
interface TextMetrics {
/** Returns the measurement described below. */
readonly actualBoundingBoxAscent: number
/** Returns the measurement described below. */
readonly actualBoundingBoxDescent: number
/** Returns the measurement described below. */
readonly actualBoundingBoxLeft: number
/** Returns the measurement described below. */
readonly actualBoundingBoxRight: number
/** Returns the measurement described below. */
readonly fontBoundingBoxAscent: number
/** Returns the measurement described below. */
readonly fontBoundingBoxDescent: number
/** Returns the measurement described below. */
readonly width: number
}
interface CanvasText {
fillText(text: string, x: number, y: number, maxWidth?: number): void
measureText(text: string): TextMetrics
strokeText(text: string, x: number, y: number, maxWidth?: number): void
}
interface CanvasTextDrawingStyles {
direction: CanvasDirection
font: string
fontKerning: CanvasFontKerning
textAlign: CanvasTextAlign
textBaseline: CanvasTextBaseline
}
interface DOMMatrixReadOnly {
readonly a: number
readonly b: number
readonly c: number
readonly d: number
readonly e: number
readonly f: number
readonly is2D: boolean
readonly isIdentity: boolean
readonly m11: number
readonly m12: number
readonly m13: number
readonly m14: number
readonly m21: number
readonly m22: number
readonly m23: number
readonly m24: number
readonly m31: number
readonly m32: number
readonly m33: number
readonly m34: number
readonly m41: number
readonly m42: number
readonly m43: number
readonly m44: number
}
interface CanvasTransform {
getTransform(): DOMMatrixReadOnly
resetTransform(): void
rotate(angle: number): void
scale(x: number, y: number): void
setTransform(
a: number,
b: number,
c: number,
d: number,
e: number,
f: number
): void
setTransform(transform?: DOMMatrix2DInit): void
transform(
a: number,
b: number,
c: number,
d: number,
e: number,
f: number
): void
translate(x: number, y: number): void
}
interface CanvasUserInterface {
// drawFocusIfNeeded(element: Element): void;
// drawFocusIfNeeded(path: Path2D, element: Element): void;
}
interface CanvasRenderingContext2DSettings {
alpha?: boolean
colorSpace?: PredefinedColorSpace
desynchronized?: boolean
willReadFrequently?: boolean
}
/** The CanvasRenderingContext2D interface, part of the Canvas API, provides the 2D rendering context for the drawing surface of a <canvas> element. It is used for drawing shapes, text, images, and other objects. */
interface CanvasRenderingContext2D
extends CanvasCompositing,
CanvasDrawImage,
CanvasDrawPath,
CanvasFillStrokeStyles,
CanvasFilters,
CanvasImageData,
CanvasImageSmoothing,
CanvasPath,
CanvasPathDrawingStyles,
CanvasRect,
CanvasShadowStyles,
CanvasState,
CanvasText,
CanvasTextDrawingStyles,
CanvasTransform,
CanvasUserInterface {
readonly canvas: Canvas
getContextAttributes(): CanvasRenderingContext2DSettings
}
type GLbitfield = number
type GLboolean = boolean
type GLclampf = number
type GLenum = number
type GLfloat = number
type GLint = number
type GLint64 = number
type GLintptr = number
type GLsizei = number
type GLsizeiptr = number
type GLuint = number
type GLuint64 = number
interface WEBGL_color_buffer_float {
readonly FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT: GLenum
readonly RGBA32F_EXT: GLenum
readonly UNSIGNED_NORMALIZED_EXT: GLenum
}
interface WEBGL_compressed_texture_astc {
getSupportedProfiles(): string[]
readonly COMPRESSED_RGBA_ASTC_10x10_KHR: GLenum
readonly COMPRESSED_RGBA_ASTC_10x5_KHR: GLenum
readonly COMPRESSED_RGBA_ASTC_10x6_KHR: GLenum
readonly COMPRESSED_RGBA_ASTC_10x8_KHR: GLenum
readonly COMPRESSED_RGBA_ASTC_12x10_KHR: GLenum
readonly COMPRESSED_RGBA_ASTC_12x12_KHR: GLenum
readonly COMPRESSED_RGBA_ASTC_4x4_KHR: GLenum
readonly COMPRESSED_RGBA_ASTC_5x4_KHR: GLenum
readonly COMPRESSED_RGBA_ASTC_5x5_KHR: GLenum
readonly COMPRESSED_RGBA_ASTC_6x5_KHR: GLenum
readonly COMPRESSED_RGBA_ASTC_6x6_KHR: GLenum
readonly COMPRESSED_RGBA_ASTC_8x5_KHR: GLenum
readonly COMPRESSED_RGBA_ASTC_8x6_KHR: GLenum
readonly COMPRESSED_RGBA_ASTC_8x8_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: GLenum
}
interface WEBGL_compressed_texture_etc {
readonly COMPRESSED_R11_EAC: GLenum
readonly COMPRESSED_RG11_EAC: GLenum
readonly COMPRESSED_RGB8_ETC2: GLenum
readonly COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: GLenum
readonly COMPRESSED_RGBA8_ETC2_EAC: GLenum
readonly COMPRESSED_SIGNED_R11_EAC: GLenum
readonly COMPRESSED_SIGNED_RG11_EAC: GLenum
readonly COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: GLenum
readonly COMPRESSED_SRGB8_ETC2: GLenum
readonly COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: GLenum
}
interface WEBGL_compressed_texture_etc1 {
readonly COMPRESSED_RGB_ETC1_WEBGL: GLenum
}
/** The WEBGL_compressed_texture_s3tc extension is part of the WebGL API and exposes four S3TC compressed texture formats. */
interface WEBGL_compressed_texture_s3tc {
readonly COMPRESSED_RGBA_S3TC_DXT1_EXT: GLenum
readonly COMPRESSED_RGBA_S3TC_DXT3_EXT: GLenum
readonly COMPRESSED_RGBA_S3TC_DXT5_EXT: GLenum
readonly COMPRESSED_RGB_S3TC_DXT1_EXT: GLenum
}
interface WEBGL_compressed_texture_s3tc_srgb {
readonly COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: GLenum
readonly COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: GLenum
readonly COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: GLenum
readonly COMPRESSED_SRGB_S3TC_DXT1_EXT: GLenum
}
/** The WEBGL_debug_renderer_info extension is part of the WebGL API and exposes two constants with information about the graphics driver for debugging purposes. */
interface WEBGL_debug_renderer_info {
readonly UNMASKED_RENDERER_WEBGL: GLenum
readonly UNMASKED_VENDOR_WEBGL: GLenum
}
interface WEBGL_debug_shaders {
getTranslatedShaderSource(shader: WebGLShader): string
}
/** The WEBGL_depth_texture extension is part of the WebGL API and defines 2D depth and depth-stencil textures. */
interface WEBGL_depth_texture {
readonly UNSIGNED_INT_24_8_WEBGL: GLenum
}
interface WEBGL_draw_buffers {
drawBuffersWEBGL(buffers: GLenum[]): void
readonly COLOR_ATTACHMENT0_WEBGL: GLenum
readonly COLOR_ATTACHMENT10_WEBGL: GLenum
readonly COLOR_ATTACHMENT11_WEBGL: GLenum
readonly COLOR_ATTACHMENT12_WEBGL: GLenum
readonly COLOR_ATTACHMENT13_WEBGL: GLenum
readonly COLOR_ATTACHMENT14_WEBGL: GLenum
readonly COLOR_ATTACHMENT15_WEBGL: GLenum
readonly COLOR_ATTACHMENT1_WEBGL: GLenum
readonly COLOR_ATTACHMENT2_WEBGL: GLenum
readonly COLOR_ATTACHMENT3_WEBGL: GLenum
readonly COLOR_ATTACHMENT4_WEBGL: GLenum
readonly COLOR_ATTACHMENT5_WEBGL: GLenum
readonly COLOR_ATTACHMENT6_WEBGL: GLenum
readonly COLOR_ATTACHMENT7_WEBGL: GLenum
readonly COLOR_ATTACHMENT8_WEBGL: GLenum
readonly COLOR_ATTACHMENT9_WEBGL: GLenum
readonly DRAW_BUFFER0_WEBGL: GLenum
readonly DRAW_BUFFER10_WEBGL: GLenum
readonly DRAW_BUFFER11_WEBGL: GLenum
readonly DRAW_BUFFER12_WEBGL: GLenum
readonly DRAW_BUFFER13_WEBGL: GLenum
readonly DRAW_BUFFER14_WEBGL: GLenum
readonly DRAW_BUFFER15_WEBGL: GLenum
readonly DRAW_BUFFER1_WEBGL: GLenum
readonly DRAW_BUFFER2_WEBGL: GLenum
readonly DRAW_BUFFER3_WEBGL: GLenum
readonly DRAW_BUFFER4_WEBGL: GLenum
readonly DRAW_BUFFER5_WEBGL: GLenum
readonly DRAW_BUFFER6_WEBGL: GLenum
readonly DRAW_BUFFER7_WEBGL: GLenum
readonly DRAW_BUFFER8_WEBGL: GLenum
readonly DRAW_BUFFER9_WEBGL: GLenum
readonly MAX_COLOR_ATTACHMENTS_WEBGL: GLenum
readonly MAX_DRAW_BUFFERS_WEBGL: GLenum
}
interface WEBGL_lose_context {
loseContext(): void
restoreContext(): void
}
interface WEBGL_multi_draw {
multiDrawArraysInstancedWEBGL(
mode: GLenum,
firstsList: Int32Array | GLint[],
firstsOffset: GLuint,
countsList: Int32Array | GLsizei[],
countsOffset: GLuint,
instanceCountsList: Int32Array | GLsizei[],
instanceCountsOffset: GLuint,
drawcount: GLsizei
): void
multiDrawArraysWEBGL(
mode: GLenum,
firstsList: Int32Array | GLint[],
firstsOffset: GLuint,
countsList: Int32Array | GLsizei[],
countsOffset: GLuint,
drawcount: GLsizei
): void
multiDrawElementsInstancedWEBGL(
mode: GLenum,
countsList: Int32Array | GLsizei[],
countsOffset: GLuint,
type: GLenum,
offsetsList: Int32Array | GLsizei[],
offsetsOffset: GLuint,
instanceCountsList: Int32Array | GLsizei[],
instanceCountsOffset: GLuint,
drawcount: GLsizei
): void
multiDrawElementsWEBGL(
mode: GLenum,
countsList: Int32Array | GLsizei[],
countsOffset: GLuint,
type: GLenum,
offsetsList: Int32Array | GLsizei[],
offsetsOffset: GLuint,
drawcount: GLsizei
): void
}
type OverSampleType = '2x' | '4x' | 'none'
interface WebGL2RenderingContext
extends WebGL2RenderingContextBase,
WebGL2RenderingContextOverloads,
WebGLRenderingContextBase {}
type Int32List = Int32Array | GLint[]
type Uint32List = Uint32Array | GLuint[]
interface WebGL2RenderingContextBase {
beginQuery(target: GLenum, query: WebGLQuery): void
beginTransformFeedback(primitiveMode: GLenum): void
bindBufferBase(
target: GLenum,
index: GLuint,
buffer: WebGLBuffer | null
): void
bindBufferRange(
target: GLenum,
index: GLuint,
buffer: WebGLBuffer | null,
offset: GLintptr,
size: GLsizeiptr
): void
bindSampler(unit: GLuint, sampler: WebGLSampler | null): void
bindTransformFeedback(
target: GLenum,
tf: WebGLTransformFeedback | null
): void
bindVertexArray(array: WebGLVertexArrayObject | null): void
blitFramebuffer(
srcX0: GLint,
srcY0: GLint,
srcX1: GLint,
srcY1: GLint,
dstX0: GLint,
dstY0: GLint,
dstX1: GLint,
dstY1: GLint,
mask: GLbitfield,
filter: GLenum
): void
clearBufferfi(
buffer: GLenum,
drawbuffer: GLint,
depth: GLfloat,
stencil: GLint
): void
clearBufferfv(
buffer: GLenum,
drawbuffer: GLint,
values: Float32List,
srcOffset?: GLuint
): void
clearBufferiv(
buffer: GLenum,
drawbuffer: GLint,
values: Int32List,
srcOffset?: GLuint
): void
clearBufferuiv(
buffer: GLenum,
drawbuffer: GLint,
values: Uint32List,
srcOffset?: GLuint
): void
clientWaitSync(
sync: WebGLSync,
flags: GLbitfield,
timeout: GLuint64
): GLenum
compressedTexImage3D(
target: GLenum,
level: GLint,
internalformat: GLenum,
width: GLsizei,
height: GLsizei,
depth: GLsizei,
border: GLint,
imageSize: GLsizei,
offset: GLintptr
): void
compressedTexImage3D(
target: GLenum,
level: GLint,
internalformat: GLenum,
width: GLsizei,
height: GLsizei,
depth: GLsizei,
border: GLint,
srcData: ArrayBufferView,
srcOffset?: GLuint,
srcLengthOverride?: GLuint
): void
compressedTexSubImage3D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
zoffset: GLint,
width: GLsizei,
height: GLsizei,
depth: GLsizei,
format: GLenum,
imageSize: GLsizei,
offset: GLintptr
): void
compressedTexSubImage3D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
zoffset: GLint,
width: GLsizei,
height: GLsizei,
depth: GLsizei,
format: GLenum,
srcData: ArrayBufferView,
srcOffset?: GLuint,
srcLengthOverride?: GLuint
): void
copyBufferSubData(
readTarget: GLenum,
writeTarget: GLenum,
readOffset: GLintptr,
writeOffset: GLintptr,
size: GLsizeiptr
): void
copyTexSubImage3D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
zoffset: GLint,
x: GLint,
y: GLint,
width: GLsizei,
height: GLsizei
): void
createQuery(): WebGLQuery | null
createSampler(): WebGLSampler | null
createTransformFeedback(): WebGLTransformFeedback | null
createVertexArray(): WebGLVertexArrayObject | null
deleteQuery(query: WebGLQuery | null): void
deleteSampler(sampler: WebGLSampler | null): void
deleteSync(sync: WebGLSync | null): void
deleteTransformFeedback(tf: WebGLTransformFeedback | null): void
deleteVertexArray(vertexArray: WebGLVertexArrayObject | null): void
drawArraysInstanced(
mode: GLenum,
first: GLint,
count: GLsizei,
instanceCount: GLsizei
): void
drawBuffers(buffers: GLenum[]): void
drawElementsInstanced(
mode: GLenum,
count: GLsizei,
type: GLenum,
offset: GLintptr,
instanceCount: GLsizei
): void
drawRangeElements(
mode: GLenum,
start: GLuint,
end: GLuint,
count: GLsizei,
type: GLenum,
offset: GLintptr
): void
endQuery(target: GLenum): void
endTransformFeedback(): void
fenceSync(condition: GLenum, flags: GLbitfield): WebGLSync | null
framebufferTextureLayer(
target: GLenum,
attachment: GLenum,
texture: WebGLTexture | null,
level: GLint,
layer: GLint
): void
getActiveUniformBlockName(
program: WebGLProgram,
uniformBlockIndex: GLuint
): string | null
getActiveUniformBlockParameter(
program: WebGLProgram,
uniformBlockIndex: GLuint,
pname: GLenum
): any
getActiveUniforms(
program: WebGLProgram,
uniformIndices: GLuint[],
pname: GLenum
): any
getBufferSubData(
target: GLenum,
srcByteOffset: GLintptr,
dstBuffer: ArrayBufferView,
dstOffset?: GLuint,
length?: GLuint
): void
getFragDataLocation(program: WebGLProgram, name: string): GLint
getIndexedParameter(target: GLenum, index: GLuint): any
getInternalformatParameter(
target: GLenum,
internalformat: GLenum,
pname: GLenum
): any
getQuery(target: GLenum, pname: GLenum): WebGLQuery | null
getQueryParameter(query: WebGLQuery, pname: GLenum): any
getSamplerParameter(sampler: WebGLSampler, pname: GLenum): any
getSyncParameter(sync: WebGLSync, pname: GLenum): any
getTransformFeedbackVarying(
program: WebGLProgram,
index: GLuint
): WebGLActiveInfo | null
getUniformBlockIndex(
program: WebGLProgram,
uniformBlockName: string
): GLuint
getUniformIndices(
program: WebGLProgram,
uniformNames: string[]
): GLuint[] | null
invalidateFramebuffer(target: GLenum, attachments: GLenum[]): void
invalidateSubFramebuffer(
target: GLenum,
attachments: GLenum[],
x: GLint,
y: GLint,
width: GLsizei,
height: GLsizei
): void
isQuery(query: WebGLQuery | null): GLboolean
isSampler(sampler: WebGLSampler | null): GLboolean
isSync(sync: WebGLSync | null): GLboolean
isTransformFeedback(tf: WebGLTransformFeedback | null): GLboolean
isVertexArray(vertexArray: WebGLVertexArrayObject | null): GLboolean
pauseTransformFeedback(): void
readBuffer(src: GLenum): void
renderbufferStorageMultisample(
target: GLenum,
samples: GLsizei,
internalformat: GLenum,
width: GLsizei,
height: GLsizei
): void
resumeTransformFeedback(): void
samplerParameterf(
sampler: WebGLSampler,
pname: GLenum,
param: GLfloat
): void
samplerParameteri(
sampler: WebGLSampler,
pname: GLenum,
param: GLint
): void
texImage3D(
target: GLenum,
level: GLint,
internalformat: GLint,
width: GLsizei,
height: GLsizei,
depth: GLsizei,
border: GLint,
format: GLenum,
type: GLenum,
pboOffset: GLintptr
): void
texImage3D(
target: GLenum,
level: GLint,
internalformat: GLint,
width: GLsizei,
height: GLsizei,
depth: GLsizei,
border: GLint,
format: GLenum,
type: GLenum,
source: TexImageSource
): void
texImage3D(
target: GLenum,
level: GLint,
internalformat: GLint,
width: GLsizei,
height: GLsizei,
depth: GLsizei,
border: GLint,
format: GLenum,
type: GLenum,
srcData: ArrayBufferView | null
): void
texImage3D(
target: GLenum,
level: GLint,
internalformat: GLint,
width: GLsizei,
height: GLsizei,
depth: GLsizei,
border: GLint,
format: GLenum,
type: GLenum,
srcData: ArrayBufferView,
srcOffset: GLuint
): void
texStorage2D(
target: GLenum,
levels: GLsizei,
internalformat: GLenum,
width: GLsizei,
height: GLsizei
): void
texStorage3D(
target: GLenum,
levels: GLsizei,
internalformat: GLenum,
width: GLsizei,
height: GLsizei,
depth: GLsizei
): void
texSubImage3D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
zoffset: GLint,
width: GLsizei,
height: GLsizei,
depth: GLsizei,
format: GLenum,
type: GLenum,
pboOffset: GLintptr
): void
texSubImage3D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
zoffset: GLint,
width: GLsizei,
height: GLsizei,
depth: GLsizei,
format: GLenum,
type: GLenum,
source: TexImageSource
): void
texSubImage3D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
zoffset: GLint,
width: GLsizei,
height: GLsizei,
depth: GLsizei,
format: GLenum,
type: GLenum,
srcData: ArrayBufferView | null,
srcOffset?: GLuint
): void
transformFeedbackVaryings(
program: WebGLProgram,
varyings: string[],
bufferMode: GLenum
): void
uniform1ui(location: WebGLUniformLocation | null, v0: GLuint): void
uniform1uiv(
location: WebGLUniformLocation | null,
data: Uint32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniform2ui(
location: WebGLUniformLocation | null,
v0: GLuint,
v1: GLuint
): void
uniform2uiv(
location: WebGLUniformLocation | null,
data: Uint32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniform3ui(
location: WebGLUniformLocation | null,
v0: GLuint,
v1: GLuint,
v2: GLuint
): void
uniform3uiv(
location: WebGLUniformLocation | null,
data: Uint32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniform4ui(
location: WebGLUniformLocation | null,
v0: GLuint,
v1: GLuint,
v2: GLuint,
v3: GLuint
): void
uniform4uiv(
location: WebGLUniformLocation | null,
data: Uint32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniformBlockBinding(
program: WebGLProgram,
uniformBlockIndex: GLuint,
uniformBlockBinding: GLuint
): void
uniformMatrix2x3fv(
location: WebGLUniformLocation | null,
transpose: GLboolean,
data: Float32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniformMatrix2x4fv(
location: WebGLUniformLocation | null,
transpose: GLboolean,
data: Float32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniformMatrix3x2fv(
location: WebGLUniformLocation | null,
transpose: GLboolean,
data: Float32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniformMatrix3x4fv(
location: WebGLUniformLocation | null,
transpose: GLboolean,
data: Float32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniformMatrix4x2fv(
location: WebGLUniformLocation | null,
transpose: GLboolean,
data: Float32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniformMatrix4x3fv(
location: WebGLUniformLocation | null,
transpose: GLboolean,
data: Float32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
vertexAttribDivisor(index: GLuint, divisor: GLuint): void
vertexAttribI4i(
index: GLuint,
x: GLint,
y: GLint,
z: GLint,
w: GLint
): void
vertexAttribI4iv(index: GLuint, values: Int32List): void
vertexAttribI4ui(
index: GLuint,
x: GLuint,
y: GLuint,
z: GLuint,
w: GLuint
): void
vertexAttribI4uiv(index: GLuint, values: Uint32List): void
vertexAttribIPointer(
index: GLuint,
size: GLint,
type: GLenum,
stride: GLsizei,
offset: GLintptr
): void
waitSync(sync: WebGLSync, flags: GLbitfield, timeout: GLint64): void
readonly ACTIVE_UNIFORM_BLOCKS: GLenum
readonly ALREADY_SIGNALED: GLenum
readonly ANY_SAMPLES_PASSED: GLenum
readonly ANY_SAMPLES_PASSED_CONSERVATIVE: GLenum
readonly COLOR: GLenum
readonly COLOR_ATTACHMENT1: GLenum
readonly COLOR_ATTACHMENT10: GLenum
readonly COLOR_ATTACHMENT11: GLenum
readonly COLOR_ATTACHMENT12: GLenum
readonly COLOR_ATTACHMENT13: GLenum
readonly COLOR_ATTACHMENT14: GLenum
readonly COLOR_ATTACHMENT15: GLenum
readonly COLOR_ATTACHMENT2: GLenum
readonly COLOR_ATTACHMENT3: GLenum
readonly COLOR_ATTACHMENT4: GLenum
readonly COLOR_ATTACHMENT5: GLenum
readonly COLOR_ATTACHMENT6: GLenum
readonly COLOR_ATTACHMENT7: GLenum
readonly COLOR_ATTACHMENT8: GLenum
readonly COLOR_ATTACHMENT9: GLenum
readonly COMPARE_REF_TO_TEXTURE: GLenum
readonly CONDITION_SATISFIED: GLenum
readonly COPY_READ_BUFFER: GLenum
readonly COPY_READ_BUFFER_BINDING: GLenum
readonly COPY_WRITE_BUFFER: GLenum
readonly COPY_WRITE_BUFFER_BINDING: GLenum
readonly CURRENT_QUERY: GLenum
readonly DEPTH: GLenum
readonly DEPTH24_STENCIL8: GLenum
readonly DEPTH32F_STENCIL8: GLenum
readonly DEPTH_COMPONENT24: GLenum
readonly DEPTH_COMPONENT32F: GLenum
readonly DRAW_BUFFER0: GLenum
readonly DRAW_BUFFER1: GLenum
readonly DRAW_BUFFER10: GLenum
readonly DRAW_BUFFER11: GLenum
readonly DRAW_BUFFER12: GLenum
readonly DRAW_BUFFER13: GLenum
readonly DRAW_BUFFER14: GLenum
readonly DRAW_BUFFER15: GLenum
readonly DRAW_BUFFER2: GLenum
readonly DRAW_BUFFER3: GLenum
readonly DRAW_BUFFER4: GLenum
readonly DRAW_BUFFER5: GLenum
readonly DRAW_BUFFER6: GLenum
readonly DRAW_BUFFER7: GLenum
readonly DRAW_BUFFER8: GLenum
readonly DRAW_BUFFER9: GLenum
readonly DRAW_FRAMEBUFFER: GLenum
readonly DRAW_FRAMEBUFFER_BINDING: GLenum
readonly DYNAMIC_COPY: GLenum
readonly DYNAMIC_READ: GLenum
readonly FLOAT_32_UNSIGNED_INT_24_8_REV: GLenum
readonly FLOAT_MAT2x3: GLenum
readonly FLOAT_MAT2x4: GLenum
readonly FLOAT_MAT3x2: GLenum
readonly FLOAT_MAT3x4: GLenum
readonly FLOAT_MAT4x2: GLenum
readonly FLOAT_MAT4x3: GLenum
readonly FRAGMENT_SHADER_DERIVATIVE_HINT: GLenum
readonly FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: GLenum
readonly FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: GLenum
readonly FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: GLenum
readonly FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: GLenum
readonly FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: GLenum
readonly FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: GLenum
readonly FRAMEBUFFER_ATTACHMENT_RED_SIZE: GLenum
readonly FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: GLenum
readonly FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: GLenum
readonly FRAMEBUFFER_DEFAULT: GLenum
readonly FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: GLenum
readonly HALF_FLOAT: GLenum
readonly INTERLEAVED_ATTRIBS: GLenum
readonly INT_2_10_10_10_REV: GLenum
readonly INT_SAMPLER_2D: GLenum
readonly INT_SAMPLER_2D_ARRAY: GLenum
readonly INT_SAMPLER_3D: GLenum
readonly INT_SAMPLER_CUBE: GLenum
readonly INVALID_INDEX: GLenum
readonly MAX: GLenum
readonly MAX_3D_TEXTURE_SIZE: GLenum
readonly MAX_ARRAY_TEXTURE_LAYERS: GLenum
readonly MAX_CLIENT_WAIT_TIMEOUT_WEBGL: GLenum
readonly MAX_COLOR_ATTACHMENTS: GLenum
readonly MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS: GLenum
readonly MAX_COMBINED_UNIFORM_BLOCKS: GLenum
readonly MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS: GLenum
readonly MAX_DRAW_BUFFERS: GLenum
readonly MAX_ELEMENTS_INDICES: GLenum
readonly MAX_ELEMENTS_VERTICES: GLenum
readonly MAX_ELEMENT_INDEX: GLenum
readonly MAX_FRAGMENT_INPUT_COMPONENTS: GLenum
readonly MAX_FRAGMENT_UNIFORM_BLOCKS: GLenum
readonly MAX_FRAGMENT_UNIFORM_COMPONENTS: GLenum
readonly MAX_PROGRAM_TEXEL_OFFSET: GLenum
readonly MAX_SAMPLES: GLenum
readonly MAX_SERVER_WAIT_TIMEOUT: GLenum
readonly MAX_TEXTURE_LOD_BIAS: GLenum
readonly MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS: GLenum
readonly MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS: GLenum
readonly MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS: GLenum
readonly MAX_UNIFORM_BLOCK_SIZE: GLenum
readonly MAX_UNIFORM_BUFFER_BINDINGS: GLenum
readonly MAX_VARYING_COMPONENTS: GLenum
readonly MAX_VERTEX_OUTPUT_COMPONENTS: GLenum
readonly MAX_VERTEX_UNIFORM_BLOCKS: GLenum
readonly MAX_VERTEX_UNIFORM_COMPONENTS: GLenum
readonly MIN: GLenum
readonly MIN_PROGRAM_TEXEL_OFFSET: GLenum
readonly OBJECT_TYPE: GLenum
readonly PACK_ROW_LENGTH: GLenum
readonly PACK_SKIP_PIXELS: GLenum
readonly PACK_SKIP_ROWS: GLenum
readonly PIXEL_PACK_BUFFER: GLenum
readonly PIXEL_PACK_BUFFER_BINDING: GLenum
readonly PIXEL_UNPACK_BUFFER: GLenum
readonly PIXEL_UNPACK_BUFFER_BINDING: GLenum
readonly QUERY_RESULT: GLenum
readonly QUERY_RESULT_AVAILABLE: GLenum
readonly R11F_G11F_B10F: GLenum
readonly R16F: GLenum
readonly R16I: GLenum
readonly R16UI: GLenum
readonly R32F: GLenum
readonly R32I: GLenum
readonly R32UI: GLenum
readonly R8: GLenum
readonly R8I: GLenum
readonly R8UI: GLenum
readonly R8_SNORM: GLenum
readonly RASTERIZER_DISCARD: GLenum
readonly READ_BUFFER: GLenum
readonly READ_FRAMEBUFFER: GLenum
readonly READ_FRAMEBUFFER_BINDING: GLenum
readonly RED: GLenum
readonly RED_INTEGER: GLenum
readonly RENDERBUFFER_SAMPLES: GLenum
readonly RG: GLenum
readonly RG16F: GLenum
readonly RG16I: GLenum
readonly RG16UI: GLenum
readonly RG32F: GLenum
readonly RG32I: GLenum
readonly RG32UI: GLenum
readonly RG8: GLenum
readonly RG8I: GLenum
readonly RG8UI: GLenum
readonly RG8_SNORM: GLenum
readonly RGB10_A2: GLenum
readonly RGB10_A2UI: GLenum
readonly RGB16F: GLenum
readonly RGB16I: GLenum
readonly RGB16UI: GLenum
readonly RGB32F: GLenum
readonly RGB32I: GLenum
readonly RGB32UI: GLenum
readonly RGB8: GLenum
readonly RGB8I: GLenum
readonly RGB8UI: GLenum
readonly RGB8_SNORM: GLenum
readonly RGB9_E5: GLenum
readonly RGBA16F: GLenum
readonly RGBA16I: GLenum
readonly RGBA16UI: GLenum
readonly RGBA32F: GLenum
readonly RGBA32I: GLenum
readonly RGBA32UI: GLenum
readonly RGBA8: GLenum
readonly RGBA8I: GLenum
readonly RGBA8UI: GLenum
readonly RGBA8_SNORM: GLenum
readonly RGBA_INTEGER: GLenum
readonly RGB_INTEGER: GLenum
readonly RG_INTEGER: GLenum
readonly SAMPLER_2D_ARRAY: GLenum
readonly SAMPLER_2D_ARRAY_SHADOW: GLenum
readonly SAMPLER_2D_SHADOW: GLenum
readonly SAMPLER_3D: GLenum
readonly SAMPLER_BINDING: GLenum
readonly SAMPLER_CUBE_SHADOW: GLenum
readonly SEPARATE_ATTRIBS: GLenum
readonly SIGNALED: GLenum
readonly SIGNED_NORMALIZED: GLenum
readonly SRGB: GLenum
readonly SRGB8: GLenum
readonly SRGB8_ALPHA8: GLenum
readonly STATIC_COPY: GLenum
readonly STATIC_READ: GLenum
readonly STENCIL: GLenum
readonly STREAM_COPY: GLenum
readonly STREAM_READ: GLenum
readonly SYNC_CONDITION: GLenum
readonly SYNC_FENCE: GLenum
readonly SYNC_FLAGS: GLenum
readonly SYNC_FLUSH_COMMANDS_BIT: GLenum
readonly SYNC_GPU_COMMANDS_COMPLETE: GLenum
readonly SYNC_STATUS: GLenum
readonly TEXTURE_2D_ARRAY: GLenum
readonly TEXTURE_3D: GLenum
readonly TEXTURE_BASE_LEVEL: GLenum
readonly TEXTURE_BINDING_2D_ARRAY: GLenum
readonly TEXTURE_BINDING_3D: GLenum
readonly TEXTURE_COMPARE_FUNC: GLenum
readonly TEXTURE_COMPARE_MODE: GLenum
readonly TEXTURE_IMMUTABLE_FORMAT: GLenum
readonly TEXTURE_IMMUTABLE_LEVELS: GLenum
readonly TEXTURE_MAX_LEVEL: GLenum
readonly TEXTURE_MAX_LOD: GLenum
readonly TEXTURE_MIN_LOD: GLenum
readonly TEXTURE_WRAP_R: GLenum
readonly TIMEOUT_EXPIRED: GLenum
readonly TIMEOUT_IGNORED: GLint64
readonly TRANSFORM_FEEDBACK: GLenum
readonly TRANSFORM_FEEDBACK_ACTIVE: GLenum
readonly TRANSFORM_FEEDBACK_BINDING: GLenum
readonly TRANSFORM_FEEDBACK_BUFFER: GLenum
readonly TRANSFORM_FEEDBACK_BUFFER_BINDING: GLenum
readonly TRANSFORM_FEEDBACK_BUFFER_MODE: GLenum
readonly TRANSFORM_FEEDBACK_BUFFER_SIZE: GLenum
readonly TRANSFORM_FEEDBACK_BUFFER_START: GLenum
readonly TRANSFORM_FEEDBACK_PAUSED: GLenum
readonly TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: GLenum
readonly TRANSFORM_FEEDBACK_VARYINGS: GLenum
readonly UNIFORM_ARRAY_STRIDE: GLenum
readonly UNIFORM_BLOCK_ACTIVE_UNIFORMS: GLenum
readonly UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: GLenum
readonly UNIFORM_BLOCK_BINDING: GLenum
readonly UNIFORM_BLOCK_DATA_SIZE: GLenum
readonly UNIFORM_BLOCK_INDEX: GLenum
readonly UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: GLenum
readonly UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: GLenum
readonly UNIFORM_BUFFER: GLenum
readonly UNIFORM_BUFFER_BINDING: GLenum
readonly UNIFORM_BUFFER_OFFSET_ALIGNMENT: GLenum
readonly UNIFORM_BUFFER_SIZE: GLenum
readonly UNIFORM_BUFFER_START: GLenum
readonly UNIFORM_IS_ROW_MAJOR: GLenum
readonly UNIFORM_MATRIX_STRIDE: GLenum
readonly UNIFORM_OFFSET: GLenum
readonly UNIFORM_SIZE: GLenum
readonly UNIFORM_TYPE: GLenum
readonly UNPACK_IMAGE_HEIGHT: GLenum
readonly UNPACK_ROW_LENGTH: GLenum
readonly UNPACK_SKIP_IMAGES: GLenum
readonly UNPACK_SKIP_PIXELS: GLenum
readonly UNPACK_SKIP_ROWS: GLenum
readonly UNSIGNALED: GLenum
readonly UNSIGNED_INT_10F_11F_11F_REV: GLenum
readonly UNSIGNED_INT_24_8: GLenum
readonly UNSIGNED_INT_2_10_10_10_REV: GLenum
readonly UNSIGNED_INT_5_9_9_9_REV: GLenum
readonly UNSIGNED_INT_SAMPLER_2D: GLenum
readonly UNSIGNED_INT_SAMPLER_2D_ARRAY: GLenum
readonly UNSIGNED_INT_SAMPLER_3D: GLenum
readonly UNSIGNED_INT_SAMPLER_CUBE: GLenum
readonly UNSIGNED_INT_VEC2: GLenum
readonly UNSIGNED_INT_VEC3: GLenum
readonly UNSIGNED_INT_VEC4: GLenum
readonly UNSIGNED_NORMALIZED: GLenum
readonly VERTEX_ARRAY_BINDING: GLenum
readonly VERTEX_ATTRIB_ARRAY_DIVISOR: GLenum
readonly VERTEX_ATTRIB_ARRAY_INTEGER: GLenum
readonly WAIT_FAILED: GLenum
}
interface WebGL2RenderingContextOverloads {
bufferData(target: GLenum, size: GLsizeiptr, usage: GLenum): void
bufferData(
target: GLenum,
srcData: BufferSource | null,
usage: GLenum
): void
bufferData(
target: GLenum,
srcData: ArrayBufferView,
usage: GLenum,
srcOffset: GLuint,
length?: GLuint
): void
bufferSubData(
target: GLenum,
dstByteOffset: GLintptr,
srcData: BufferSource
): void
bufferSubData(
target: GLenum,
dstByteOffset: GLintptr,
srcData: ArrayBufferView,
srcOffset: GLuint,
length?: GLuint
): void
compressedTexImage2D(
target: GLenum,
level: GLint,
internalformat: GLenum,
width: GLsizei,
height: GLsizei,
border: GLint,
imageSize: GLsizei,
offset: GLintptr
): void
compressedTexImage2D(
target: GLenum,
level: GLint,
internalformat: GLenum,
width: GLsizei,
height: GLsizei,
border: GLint,
srcData: ArrayBufferView,
srcOffset?: GLuint,
srcLengthOverride?: GLuint
): void
compressedTexSubImage2D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
width: GLsizei,
height: GLsizei,
format: GLenum,
imageSize: GLsizei,
offset: GLintptr
): void
compressedTexSubImage2D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
width: GLsizei,
height: GLsizei,
format: GLenum,
srcData: ArrayBufferView,
srcOffset?: GLuint,
srcLengthOverride?: GLuint
): void
readPixels(
x: GLint,
y: GLint,
width: GLsizei,
height: GLsizei,
format: GLenum,
type: GLenum,
dstData: ArrayBufferView | null
): void
readPixels(
x: GLint,
y: GLint,
width: GLsizei,
height: GLsizei,
format: GLenum,
type: GLenum,
offset: GLintptr
): void
readPixels(
x: GLint,
y: GLint,
width: GLsizei,
height: GLsizei,
format: GLenum,
type: GLenum,
dstData: ArrayBufferView,
dstOffset: GLuint
): void
texImage2D(
target: GLenum,
level: GLint,
internalformat: GLint,
width: GLsizei,
height: GLsizei,
border: GLint,
format: GLenum,
type: GLenum,
pixels: ArrayBufferView | null
): void
texImage2D(
target: GLenum,
level: GLint,
internalformat: GLint,
format: GLenum,
type: GLenum,
source: TexImageSource
): void
texImage2D(
target: GLenum,
level: GLint,
internalformat: GLint,
width: GLsizei,
height: GLsizei,
border: GLint,
format: GLenum,
type: GLenum,
pboOffset: GLintptr
): void
texImage2D(
target: GLenum,
level: GLint,
internalformat: GLint,
width: GLsizei,
height: GLsizei,
border: GLint,
format: GLenum,
type: GLenum,
source: TexImageSource
): void
texImage2D(
target: GLenum,
level: GLint,
internalformat: GLint,
width: GLsizei,
height: GLsizei,
border: GLint,
format: GLenum,
type: GLenum,
srcData: ArrayBufferView,
srcOffset: GLuint
): void
texSubImage2D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
width: GLsizei,
height: GLsizei,
format: GLenum,
type: GLenum,
pixels: ArrayBufferView | null
): void
texSubImage2D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
format: GLenum,
type: GLenum,
source: TexImageSource
): void
texSubImage2D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
width: GLsizei,
height: GLsizei,
format: GLenum,
type: GLenum,
pboOffset: GLintptr
): void
texSubImage2D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
width: GLsizei,
height: GLsizei,
format: GLenum,
type: GLenum,
source: TexImageSource
): void
texSubImage2D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
width: GLsizei,
height: GLsizei,
format: GLenum,
type: GLenum,
srcData: ArrayBufferView,
srcOffset: GLuint
): void
uniform1fv(
location: WebGLUniformLocation | null,
data: Float32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniform1iv(
location: WebGLUniformLocation | null,
data: Int32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniform2fv(
location: WebGLUniformLocation | null,
data: Float32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniform2iv(
location: WebGLUniformLocation | null,
data: Int32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniform3fv(
location: WebGLUniformLocation | null,
data: Float32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniform3iv(
location: WebGLUniformLocation | null,
data: Int32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniform4fv(
location: WebGLUniformLocation | null,
data: Float32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniform4iv(
location: WebGLUniformLocation | null,
data: Int32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniformMatrix2fv(
location: WebGLUniformLocation | null,
transpose: GLboolean,
data: Float32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniformMatrix3fv(
location: WebGLUniformLocation | null,
transpose: GLboolean,
data: Float32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
uniformMatrix4fv(
location: WebGLUniformLocation | null,
transpose: GLboolean,
data: Float32List,
srcOffset?: GLuint,
srcLength?: GLuint
): void
}
/** Part of the WebGL API and represents the information returned by calling the WebGLRenderingContext.getActiveAttrib() and WebGLRenderingContext.getActiveUniform() methods. */
interface WebGLActiveInfo {
readonly name: string
readonly size: GLint
readonly type: GLenum
}
/** Part of the WebGL API and represents an opaque buffer object storing data such as vertices or colors. */
interface WebGLBuffer {}
/** Part of the WebGL API and represents a collection of buffers that serve as a rendering destination. */
interface WebGLFramebuffer {}
/** The WebGLProgram is part of the WebGL API and is a combination of two compiled WebGLShaders consisting of a vertex shader and a fragment shader (both written in GLSL). */
interface WebGLProgram {}
interface WebGLQuery {}
/** Part of the WebGL API and represents a buffer that can contain an image, or can be source or target of an rendering operation. */
interface WebGLRenderbuffer {}
/** Provides an interface to the OpenGL ES 2.0 graphics rendering context for the drawing surface of an HTML <canvas> element. */
interface WebGLRenderingContext
extends WebGLRenderingContextBase,
WebGLRenderingContextOverloads {}
/** The ANGLE_instanced_arrays extension is part of the WebGL API and allows to draw the same object, or groups of similar objects multiple times, if they share the same vertex data, primitive count and type. */
interface ANGLE_instanced_arrays {
drawArraysInstancedANGLE(
mode: GLenum,
first: GLint,
count: GLsizei,
primcount: GLsizei
): void
drawElementsInstancedANGLE(
mode: GLenum,
count: GLsizei,
type: GLenum,
offset: GLintptr,
primcount: GLsizei
): void
vertexAttribDivisorANGLE(index: GLuint, divisor: GLuint): void
readonly VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: GLenum
}
interface EXT_blend_minmax {
readonly MAX_EXT: GLenum
readonly MIN_EXT: GLenum
}
interface EXT_color_buffer_float {}
interface EXT_color_buffer_half_float {
readonly FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT: GLenum
readonly RGB16F_EXT: GLenum
readonly RGBA16F_EXT: GLenum
readonly UNSIGNED_NORMALIZED_EXT: GLenum
}
interface EXT_float_blend {}
/** The EXT_frag_depth extension is part of the WebGL API and enables to set a depth value of a fragment from within the fragment shader. */
interface EXT_frag_depth {}
interface EXT_sRGB {
readonly FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT: GLenum
readonly SRGB8_ALPHA8_EXT: GLenum
readonly SRGB_ALPHA_EXT: GLenum
readonly SRGB_EXT: GLenum
}
interface EXT_shader_texture_lod {}
interface EXT_texture_compression_bptc {
readonly COMPRESSED_RGBA_BPTC_UNORM_EXT: GLenum
readonly COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: GLenum
readonly COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: GLenum
readonly COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: GLenum
}
interface EXT_texture_compression_rgtc {
readonly COMPRESSED_RED_GREEN_RGTC2_EXT: GLenum
readonly COMPRESSED_RED_RGTC1_EXT: GLenum
readonly COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: GLenum
readonly COMPRESSED_SIGNED_RED_RGTC1_EXT: GLenum
}
/** The EXT_texture_filter_anisotropic extension is part of the WebGL API and exposes two constants for anisotropic filtering (AF). */
interface EXT_texture_filter_anisotropic {
readonly MAX_TEXTURE_MAX_ANISOTROPY_EXT: GLenum
readonly TEXTURE_MAX_ANISOTROPY_EXT: GLenum
}
interface EXT_texture_norm16 {
readonly R16_EXT: GLenum
readonly R16_SNORM_EXT: GLenum
readonly RG16_EXT: GLenum
readonly RG16_SNORM_EXT: GLenum
readonly RGB16_EXT: GLenum
readonly RGB16_SNORM_EXT: GLenum
readonly RGBA16_EXT: GLenum
readonly RGBA16_SNORM_EXT: GLenum
}
interface KHR_parallel_shader_compile {
readonly COMPLETION_STATUS_KHR: GLenum
}
interface OES_draw_buffers_indexed {
blendEquationSeparateiOES(
buf: GLuint,
modeRGB: GLenum,
modeAlpha: GLenum
): void
blendEquationiOES(buf: GLuint, mode: GLenum): void
blendFuncSeparateiOES(
buf: GLuint,
srcRGB: GLenum,
dstRGB: GLenum,
srcAlpha: GLenum,
dstAlpha: GLenum
): void
blendFunciOES(buf: GLuint, src: GLenum, dst: GLenum): void
colorMaskiOES(
buf: GLuint,
r: GLboolean,
g: GLboolean,
b: GLboolean,
a: GLboolean
): void
disableiOES(target: GLenum, index: GLuint): void
enableiOES(target: GLenum, index: GLuint): void
}
/** The OES_element_index_uint extension is part of the WebGL API and adds support for gl.UNSIGNED_INT types to WebGLRenderingContext.drawElements(). */
interface OES_element_index_uint {}
interface OES_fbo_render_mipmap {}
/** The OES_standard_derivatives extension is part of the WebGL API and adds the GLSL derivative functions dFdx, dFdy, and fwidth. */
interface OES_standard_derivatives {
readonly FRAGMENT_SHADER_DERIVATIVE_HINT_OES: GLenum
}
/** The OES_texture_float extension is part of the WebGL API and exposes floating-point pixel types for textures. */
interface OES_texture_float {}
/** The OES_texture_float_linear extension is part of the WebGL API and allows linear filtering with floating-point pixel types for textures. */
interface OES_texture_float_linear {}
/** The OES_texture_half_float extension is part of the WebGL API and adds texture formats with 16- (aka half float) and 32-bit floating-point components. */
interface OES_texture_half_float {
readonly HALF_FLOAT_OES: GLenum
}
/** The OES_texture_half_float_linear extension is part of the WebGL API and allows linear filtering with half floating-point pixel types for textures. */
interface OES_texture_half_float_linear {}
interface OES_vertex_array_object {
bindVertexArrayOES(arrayObject: WebGLVertexArrayObjectOES | null): void
createVertexArrayOES(): WebGLVertexArrayObjectOES | null
deleteVertexArrayOES(
arrayObject: WebGLVertexArrayObjectOES | null
): void
isVertexArrayOES(
arrayObject: WebGLVertexArrayObjectOES | null
): GLboolean
readonly VERTEX_ARRAY_BINDING_OES: GLenum
}
interface OVR_multiview2 {
framebufferTextureMultiviewOVR(
target: GLenum,
attachment: GLenum,
texture: WebGLTexture | null,
level: GLint,
baseViewIndex: GLint,
numViews: GLsizei
): void
readonly FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR: GLenum
readonly FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR: GLenum
readonly FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR: GLenum
readonly MAX_VIEWS_OVR: GLenum
}
type WebGLPowerPreference = 'default' | 'high-performance' | 'low-power'
interface WebGLContextAttributes {
alpha?: boolean
antialias?: boolean
depth?: boolean
desynchronized?: boolean
failIfMajorPerformanceCaveat?: boolean
powerPreference?: WebGLPowerPreference
premultipliedAlpha?: boolean
preserveDrawingBuffer?: boolean
stencil?: boolean
}
interface WebGLRenderingContextBase {
readonly canvas: Canvas
readonly drawingBufferHeight: GLsizei
readonly drawingBufferWidth: GLsizei
activeTexture(texture: GLenum): void
attachShader(program: WebGLProgram, shader: WebGLShader): void
bindAttribLocation(
program: WebGLProgram,
index: GLuint,
name: string
): void
bindBuffer(target: GLenum, buffer: WebGLBuffer | null): void
bindFramebuffer(
target: GLenum,
framebuffer: WebGLFramebuffer | null
): void
bindRenderbuffer(
target: GLenum,
renderbuffer: WebGLRenderbuffer | null
): void
bindTexture(target: GLenum, texture: WebGLTexture | null): void
blendColor(
red: GLclampf,
green: GLclampf,
blue: GLclampf,
alpha: GLclampf
): void
blendEquation(mode: GLenum): void
blendEquationSeparate(modeRGB: GLenum, modeAlpha: GLenum): void
blendFunc(sfactor: GLenum, dfactor: GLenum): void
blendFuncSeparate(
srcRGB: GLenum,
dstRGB: GLenum,
srcAlpha: GLenum,
dstAlpha: GLenum
): void
checkFramebufferStatus(target: GLenum): GLenum
clear(mask: GLbitfield): void
clearColor(
red: GLclampf,
green: GLclampf,
blue: GLclampf,
alpha: GLclampf
): void
clearDepth(depth: GLclampf): void
clearStencil(s: GLint): void
colorMask(
red: GLboolean,
green: GLboolean,
blue: GLboolean,
alpha: GLboolean
): void
compileShader(shader: WebGLShader): void
copyTexImage2D(
target: GLenum,
level: GLint,
internalformat: GLenum,
x: GLint,
y: GLint,
width: GLsizei,
height: GLsizei,
border: GLint
): void
copyTexSubImage2D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
x: GLint,
y: GLint,
width: GLsizei,
height: GLsizei
): void
createBuffer(): WebGLBuffer | null
createFramebuffer(): WebGLFramebuffer | null
createProgram(): WebGLProgram | null
createRenderbuffer(): WebGLRenderbuffer | null
createShader(type: GLenum): WebGLShader | null
createTexture(): WebGLTexture | null
cullFace(mode: GLenum): void
deleteBuffer(buffer: WebGLBuffer | null): void
deleteFramebuffer(framebuffer: WebGLFramebuffer | null): void
deleteProgram(program: WebGLProgram | null): void
deleteRenderbuffer(renderbuffer: WebGLRenderbuffer | null): void
deleteShader(shader: WebGLShader | null): void
deleteTexture(texture: WebGLTexture | null): void
depthFunc(func: GLenum): void
depthMask(flag: GLboolean): void
depthRange(zNear: GLclampf, zFar: GLclampf): void
detachShader(program: WebGLProgram, shader: WebGLShader): void
disable(cap: GLenum): void
disableVertexAttribArray(index: GLuint): void
drawArrays(mode: GLenum, first: GLint, count: GLsizei): void
drawElements(
mode: GLenum,
count: GLsizei,
type: GLenum,
offset: GLintptr
): void
enable(cap: GLenum): void
enableVertexAttribArray(index: GLuint): void
finish(): void
flush(): void
framebufferRenderbuffer(
target: GLenum,
attachment: GLenum,
renderbuffertarget: GLenum,
renderbuffer: WebGLRenderbuffer | null
): void
framebufferTexture2D(
target: GLenum,
attachment: GLenum,
textarget: GLenum,
texture: WebGLTexture | null,
level: GLint
): void
frontFace(mode: GLenum): void
generateMipmap(target: GLenum): void
getActiveAttrib(
program: WebGLProgram,
index: GLuint
): WebGLActiveInfo | null
getActiveUniform(
program: WebGLProgram,
index: GLuint
): WebGLActiveInfo | null
getAttachedShaders(program: WebGLProgram): WebGLShader[] | null
getAttribLocation(program: WebGLProgram, name: string): GLint
getBufferParameter(target: GLenum, pname: GLenum): any
getContextAttributes(): WebGLContextAttributes | null
getError(): GLenum
getExtension(
extensionName: 'ANGLE_instanced_arrays'
): ANGLE_instanced_arrays | null
getExtension(extensionName: 'EXT_blend_minmax'): EXT_blend_minmax | null
getExtension(
extensionName: 'EXT_color_buffer_float'
): EXT_color_buffer_float | null
getExtension(
extensionName: 'EXT_color_buffer_half_float'
): EXT_color_buffer_half_float | null
getExtension(extensionName: 'EXT_float_blend'): EXT_float_blend | null
getExtension(extensionName: 'EXT_frag_depth'): EXT_frag_depth | null
getExtension(extensionName: 'EXT_sRGB'): EXT_sRGB | null
getExtension(
extensionName: 'EXT_shader_texture_lod'
): EXT_shader_texture_lod | null
getExtension(
extensionName: 'EXT_texture_compression_bptc'
): EXT_texture_compression_bptc | null
getExtension(
extensionName: 'EXT_texture_compression_rgtc'
): EXT_texture_compression_rgtc | null
getExtension(
extensionName: 'EXT_texture_filter_anisotropic'
): EXT_texture_filter_anisotropic | null
getExtension(
extensionName: 'KHR_parallel_shader_compile'
): KHR_parallel_shader_compile | null
getExtension(
extensionName: 'OES_element_index_uint'
): OES_element_index_uint | null
getExtension(
extensionName: 'OES_fbo_render_mipmap'
): OES_fbo_render_mipmap | null
getExtension(
extensionName: 'OES_standard_derivatives'
): OES_standard_derivatives | null
getExtension(
extensionName: 'OES_texture_float'
): OES_texture_float | null
getExtension(
extensionName: 'OES_texture_float_linear'
): OES_texture_float_linear | null
getExtension(
extensionName: 'OES_texture_half_float'
): OES_texture_half_float | null
getExtension(
extensionName: 'OES_texture_half_float_linear'
): OES_texture_half_float_linear | null
getExtension(
extensionName: 'OES_vertex_array_object'
): OES_vertex_array_object | null
getExtension(extensionName: 'OVR_multiview2'): OVR_multiview2 | null
getExtension(
extensionName: 'WEBGL_color_buffer_float'
): WEBGL_color_buffer_float | null
getExtension(
extensionName: 'WEBGL_compressed_texture_astc'
): WEBGL_compressed_texture_astc | null
getExtension(
extensionName: 'WEBGL_compressed_texture_etc'
): WEBGL_compressed_texture_etc | null
getExtension(
extensionName: 'WEBGL_compressed_texture_etc1'
): WEBGL_compressed_texture_etc1 | null
getExtension(
extensionName: 'WEBGL_compressed_texture_s3tc'
): WEBGL_compressed_texture_s3tc | null
getExtension(
extensionName: 'WEBGL_compressed_texture_s3tc_srgb'
): WEBGL_compressed_texture_s3tc_srgb | null
getExtension(
extensionName: 'WEBGL_debug_renderer_info'
): WEBGL_debug_renderer_info | null
getExtension(
extensionName: 'WEBGL_debug_shaders'
): WEBGL_debug_shaders | null
getExtension(
extensionName: 'WEBGL_depth_texture'
): WEBGL_depth_texture | null
getExtension(
extensionName: 'WEBGL_draw_buffers'
): WEBGL_draw_buffers | null
getExtension(
extensionName: 'WEBGL_lose_context'
): WEBGL_lose_context | null
getExtension(extensionName: 'WEBGL_multi_draw'): WEBGL_multi_draw | null
getExtension(name: string): any
getFramebufferAttachmentParameter(
target: GLenum,
attachment: GLenum,
pname: GLenum
): any
getParameter(pname: GLenum): any
getProgramInfoLog(program: WebGLProgram): string | null
getProgramParameter(program: WebGLProgram, pname: GLenum): any
getRenderbufferParameter(target: GLenum, pname: GLenum): any
getShaderInfoLog(shader: WebGLShader): string | null
getShaderParameter(shader: WebGLShader, pname: GLenum): any
getShaderPrecisionFormat(
shadertype: GLenum,
precisiontype: GLenum
): WebGLShaderPrecisionFormat | null
getShaderSource(shader: WebGLShader): string | null
getSupportedExtensions(): string[] | null
getTexParameter(target: GLenum, pname: GLenum): any
getUniform(program: WebGLProgram, location: WebGLUniformLocation): any
getUniformLocation(
program: WebGLProgram,
name: string
): WebGLUniformLocation | null
getVertexAttrib(index: GLuint, pname: GLenum): any
getVertexAttribOffset(index: GLuint, pname: GLenum): GLintptr
hint(target: GLenum, mode: GLenum): void
isBuffer(buffer: WebGLBuffer | null): GLboolean
isContextLost(): boolean
isEnabled(cap: GLenum): GLboolean
isFramebuffer(framebuffer: WebGLFramebuffer | null): GLboolean
isProgram(program: WebGLProgram | null): GLboolean
isRenderbuffer(renderbuffer: WebGLRenderbuffer | null): GLboolean
isShader(shader: WebGLShader | null): GLboolean
isTexture(texture: WebGLTexture | null): GLboolean
lineWidth(width: GLfloat): void
linkProgram(program: WebGLProgram): void
pixelStorei(pname: GLenum, param: GLint | GLboolean): void
polygonOffset(factor: GLfloat, units: GLfloat): void
renderbufferStorage(
target: GLenum,
internalformat: GLenum,
width: GLsizei,
height: GLsizei
): void
sampleCoverage(value: GLclampf, invert: GLboolean): void
scissor(x: GLint, y: GLint, width: GLsizei, height: GLsizei): void
shaderSource(shader: WebGLShader, source: string): void
stencilFunc(func: GLenum, ref: GLint, mask: GLuint): void
stencilFuncSeparate(
face: GLenum,
func: GLenum,
ref: GLint,
mask: GLuint
): void
stencilMask(mask: GLuint): void
stencilMaskSeparate(face: GLenum, mask: GLuint): void
stencilOp(fail: GLenum, zfail: GLenum, zpass: GLenum): void
stencilOpSeparate(
face: GLenum,
fail: GLenum,
zfail: GLenum,
zpass: GLenum
): void
texParameterf(target: GLenum, pname: GLenum, param: GLfloat): void
texParameteri(target: GLenum, pname: GLenum, param: GLint): void
uniform1f(location: WebGLUniformLocation | null, x: GLfloat): void
uniform1i(location: WebGLUniformLocation | null, x: GLint): void
uniform2f(
location: WebGLUniformLocation | null,
x: GLfloat,
y: GLfloat
): void
uniform2i(
location: WebGLUniformLocation | null,
x: GLint,
y: GLint
): void
uniform3f(
location: WebGLUniformLocation | null,
x: GLfloat,
y: GLfloat,
z: GLfloat
): void
uniform3i(
location: WebGLUniformLocation | null,
x: GLint,
y: GLint,
z: GLint
): void
uniform4f(
location: WebGLUniformLocation | null,
x: GLfloat,
y: GLfloat,
z: GLfloat,
w: GLfloat
): void
uniform4i(
location: WebGLUniformLocation | null,
x: GLint,
y: GLint,
z: GLint,
w: GLint
): void
useProgram(program: WebGLProgram | null): void
validateProgram(program: WebGLProgram): void
vertexAttrib1f(index: GLuint, x: GLfloat): void
vertexAttrib1fv(index: GLuint, values: Float32List): void
vertexAttrib2f(index: GLuint, x: GLfloat, y: GLfloat): void
vertexAttrib2fv(index: GLuint, values: Float32List): void
vertexAttrib3f(index: GLuint, x: GLfloat, y: GLfloat, z: GLfloat): void
vertexAttrib3fv(index: GLuint, values: Float32List): void
vertexAttrib4f(
index: GLuint,
x: GLfloat,
y: GLfloat,
z: GLfloat,
w: GLfloat
): void
vertexAttrib4fv(index: GLuint, values: Float32List): void
vertexAttribPointer(
index: GLuint,
size: GLint,
type: GLenum,
normalized: GLboolean,
stride: GLsizei,
offset: GLintptr
): void
viewport(x: GLint, y: GLint, width: GLsizei, height: GLsizei): void
readonly ACTIVE_ATTRIBUTES: GLenum
readonly ACTIVE_TEXTURE: GLenum
readonly ACTIVE_UNIFORMS: GLenum
readonly ALIASED_LINE_WIDTH_RANGE: GLenum
readonly ALIASED_POINT_SIZE_RANGE: GLenum
readonly ALPHA: GLenum
readonly ALPHA_BITS: GLenum
readonly ALWAYS: GLenum
readonly ARRAY_BUFFER: GLenum
readonly ARRAY_BUFFER_BINDING: GLenum
readonly ATTACHED_SHADERS: GLenum
readonly BACK: GLenum
readonly BLEND: GLenum
readonly BLEND_COLOR: GLenum
readonly BLEND_DST_ALPHA: GLenum
readonly BLEND_DST_RGB: GLenum
readonly BLEND_EQUATION: GLenum
readonly BLEND_EQUATION_ALPHA: GLenum
readonly BLEND_EQUATION_RGB: GLenum
readonly BLEND_SRC_ALPHA: GLenum
readonly BLEND_SRC_RGB: GLenum
readonly BLUE_BITS: GLenum
readonly BOOL: GLenum
readonly BOOL_VEC2: GLenum
readonly BOOL_VEC3: GLenum
readonly BOOL_VEC4: GLenum
readonly BROWSER_DEFAULT_WEBGL: GLenum
readonly BUFFER_SIZE: GLenum
readonly BUFFER_USAGE: GLenum
readonly BYTE: GLenum
readonly CCW: GLenum
readonly CLAMP_TO_EDGE: GLenum
readonly COLOR_ATTACHMENT0: GLenum
readonly COLOR_BUFFER_BIT: GLenum
readonly COLOR_CLEAR_VALUE: GLenum
readonly COLOR_WRITEMASK: GLenum
readonly COMPILE_STATUS: GLenum
readonly COMPRESSED_TEXTURE_FORMATS: GLenum
readonly CONSTANT_ALPHA: GLenum
readonly CONSTANT_COLOR: GLenum
readonly CONTEXT_LOST_WEBGL: GLenum
readonly CULL_FACE: GLenum
readonly CULL_FACE_MODE: GLenum
readonly CURRENT_PROGRAM: GLenum
readonly CURRENT_VERTEX_ATTRIB: GLenum
readonly CW: GLenum
readonly DECR: GLenum
readonly DECR_WRAP: GLenum
readonly DELETE_STATUS: GLenum
readonly DEPTH_ATTACHMENT: GLenum
readonly DEPTH_BITS: GLenum
readonly DEPTH_BUFFER_BIT: GLenum
readonly DEPTH_CLEAR_VALUE: GLenum
readonly DEPTH_COMPONENT: GLenum
readonly DEPTH_COMPONENT16: GLenum
readonly DEPTH_FUNC: GLenum
readonly DEPTH_RANGE: GLenum
readonly DEPTH_STENCIL: GLenum
readonly DEPTH_STENCIL_ATTACHMENT: GLenum
readonly DEPTH_TEST: GLenum
readonly DEPTH_WRITEMASK: GLenum
readonly DITHER: GLenum
readonly DONT_CARE: GLenum
readonly DST_ALPHA: GLenum
readonly DST_COLOR: GLenum
readonly DYNAMIC_DRAW: GLenum
readonly ELEMENT_ARRAY_BUFFER: GLenum
readonly ELEMENT_ARRAY_BUFFER_BINDING: GLenum
readonly EQUAL: GLenum
readonly FASTEST: GLenum
readonly FLOAT: GLenum
readonly FLOAT_MAT2: GLenum
readonly FLOAT_MAT3: GLenum
readonly FLOAT_MAT4: GLenum
readonly FLOAT_VEC2: GLenum
readonly FLOAT_VEC3: GLenum
readonly FLOAT_VEC4: GLenum
readonly FRAGMENT_SHADER: GLenum
readonly FRAMEBUFFER: GLenum
readonly FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: GLenum
readonly FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: GLenum
readonly FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: GLenum
readonly FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: GLenum
readonly FRAMEBUFFER_BINDING: GLenum
readonly FRAMEBUFFER_COMPLETE: GLenum
readonly FRAMEBUFFER_INCOMPLETE_ATTACHMENT: GLenum
readonly FRAMEBUFFER_INCOMPLETE_DIMENSIONS: GLenum
readonly FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: GLenum
readonly FRAMEBUFFER_UNSUPPORTED: GLenum
readonly FRONT: GLenum
readonly FRONT_AND_BACK: GLenum
readonly FRONT_FACE: GLenum
readonly FUNC_ADD: GLenum
readonly FUNC_REVERSE_SUBTRACT: GLenum
readonly FUNC_SUBTRACT: GLenum
readonly GENERATE_MIPMAP_HINT: GLenum
readonly GEQUAL: GLenum
readonly GREATER: GLenum
readonly GREEN_BITS: GLenum
readonly HIGH_FLOAT: GLenum
readonly HIGH_INT: GLenum
readonly IMPLEMENTATION_COLOR_READ_FORMAT: GLenum
readonly IMPLEMENTATION_COLOR_READ_TYPE: GLenum
readonly INCR: GLenum
readonly INCR_WRAP: GLenum
readonly INT: GLenum
readonly INT_VEC2: GLenum
readonly INT_VEC3: GLenum
readonly INT_VEC4: GLenum
readonly INVALID_ENUM: GLenum
readonly INVALID_FRAMEBUFFER_OPERATION: GLenum
readonly INVALID_OPERATION: GLenum
readonly INVALID_VALUE: GLenum
readonly INVERT: GLenum
readonly KEEP: GLenum
readonly LEQUAL: GLenum
readonly LESS: GLenum
readonly LINEAR: GLenum
readonly LINEAR_MIPMAP_LINEAR: GLenum
readonly LINEAR_MIPMAP_NEAREST: GLenum
readonly LINES: GLenum
readonly LINE_LOOP: GLenum
readonly LINE_STRIP: GLenum
readonly LINE_WIDTH: GLenum
readonly LINK_STATUS: GLenum
readonly LOW_FLOAT: GLenum
readonly LOW_INT: GLenum
readonly LUMINANCE: GLenum
readonly LUMINANCE_ALPHA: GLenum
readonly MAX_COMBINED_TEXTURE_IMAGE_UNITS: GLenum
readonly MAX_CUBE_MAP_TEXTURE_SIZE: GLenum
readonly MAX_FRAGMENT_UNIFORM_VECTORS: GLenum
readonly MAX_RENDERBUFFER_SIZE: GLenum
readonly MAX_TEXTURE_IMAGE_UNITS: GLenum
readonly MAX_TEXTURE_SIZE: GLenum
readonly MAX_VARYING_VECTORS: GLenum
readonly MAX_VERTEX_ATTRIBS: GLenum
readonly MAX_VERTEX_TEXTURE_IMAGE_UNITS: GLenum
readonly MAX_VERTEX_UNIFORM_VECTORS: GLenum
readonly MAX_VIEWPORT_DIMS: GLenum
readonly MEDIUM_FLOAT: GLenum
readonly MEDIUM_INT: GLenum
readonly MIRRORED_REPEAT: GLenum
readonly NEAREST: GLenum
readonly NEAREST_MIPMAP_LINEAR: GLenum
readonly NEAREST_MIPMAP_NEAREST: GLenum
readonly NEVER: GLenum
readonly NICEST: GLenum
readonly NONE: GLenum
readonly NOTEQUAL: GLenum
readonly NO_ERROR: GLenum
readonly ONE: GLenum
readonly ONE_MINUS_CONSTANT_ALPHA: GLenum
readonly ONE_MINUS_CONSTANT_COLOR: GLenum
readonly ONE_MINUS_DST_ALPHA: GLenum
readonly ONE_MINUS_DST_COLOR: GLenum
readonly ONE_MINUS_SRC_ALPHA: GLenum
readonly ONE_MINUS_SRC_COLOR: GLenum
readonly OUT_OF_MEMORY: GLenum
readonly PACK_ALIGNMENT: GLenum
readonly POINTS: GLenum
readonly POLYGON_OFFSET_FACTOR: GLenum
readonly POLYGON_OFFSET_FILL: GLenum
readonly POLYGON_OFFSET_UNITS: GLenum
readonly RED_BITS: GLenum
readonly RENDERBUFFER: GLenum
readonly RENDERBUFFER_ALPHA_SIZE: GLenum
readonly RENDERBUFFER_BINDING: GLenum
readonly RENDERBUFFER_BLUE_SIZE: GLenum
readonly RENDERBUFFER_DEPTH_SIZE: GLenum
readonly RENDERBUFFER_GREEN_SIZE: GLenum
readonly RENDERBUFFER_HEIGHT: GLenum
readonly RENDERBUFFER_INTERNAL_FORMAT: GLenum
readonly RENDERBUFFER_RED_SIZE: GLenum
readonly RENDERBUFFER_STENCIL_SIZE: GLenum
readonly RENDERBUFFER_WIDTH: GLenum
readonly RENDERER: GLenum
readonly REPEAT: GLenum
readonly REPLACE: GLenum
readonly RGB: GLenum
readonly RGB565: GLenum
readonly RGB5_A1: GLenum
readonly RGBA: GLenum
readonly RGBA4: GLenum
readonly SAMPLER_2D: GLenum
readonly SAMPLER_CUBE: GLenum
readonly SAMPLES: GLenum
readonly SAMPLE_ALPHA_TO_COVERAGE: GLenum
readonly SAMPLE_BUFFERS: GLenum
readonly SAMPLE_COVERAGE: GLenum
readonly SAMPLE_COVERAGE_INVERT: GLenum
readonly SAMPLE_COVERAGE_VALUE: GLenum
readonly SCISSOR_BOX: GLenum
readonly SCISSOR_TEST: GLenum
readonly SHADER_TYPE: GLenum
readonly SHADING_LANGUAGE_VERSION: GLenum
readonly SHORT: GLenum
readonly SRC_ALPHA: GLenum
readonly SRC_ALPHA_SATURATE: GLenum
readonly SRC_COLOR: GLenum
readonly STATIC_DRAW: GLenum
readonly STENCIL_ATTACHMENT: GLenum
readonly STENCIL_BACK_FAIL: GLenum
readonly STENCIL_BACK_FUNC: GLenum
readonly STENCIL_BACK_PASS_DEPTH_FAIL: GLenum
readonly STENCIL_BACK_PASS_DEPTH_PASS: GLenum
readonly STENCIL_BACK_REF: GLenum
readonly STENCIL_BACK_VALUE_MASK: GLenum
readonly STENCIL_BACK_WRITEMASK: GLenum
readonly STENCIL_BITS: GLenum
readonly STENCIL_BUFFER_BIT: GLenum
readonly STENCIL_CLEAR_VALUE: GLenum
readonly STENCIL_FAIL: GLenum
readonly STENCIL_FUNC: GLenum
readonly STENCIL_INDEX8: GLenum
readonly STENCIL_PASS_DEPTH_FAIL: GLenum
readonly STENCIL_PASS_DEPTH_PASS: GLenum
readonly STENCIL_REF: GLenum
readonly STENCIL_TEST: GLenum
readonly STENCIL_VALUE_MASK: GLenum
readonly STENCIL_WRITEMASK: GLenum
readonly STREAM_DRAW: GLenum
readonly SUBPIXEL_BITS: GLenum
readonly TEXTURE: GLenum
readonly TEXTURE0: GLenum
readonly TEXTURE1: GLenum
readonly TEXTURE10: GLenum
readonly TEXTURE11: GLenum
readonly TEXTURE12: GLenum
readonly TEXTURE13: GLenum
readonly TEXTURE14: GLenum
readonly TEXTURE15: GLenum
readonly TEXTURE16: GLenum
readonly TEXTURE17: GLenum
readonly TEXTURE18: GLenum
readonly TEXTURE19: GLenum
readonly TEXTURE2: GLenum
readonly TEXTURE20: GLenum
readonly TEXTURE21: GLenum
readonly TEXTURE22: GLenum
readonly TEXTURE23: GLenum
readonly TEXTURE24: GLenum
readonly TEXTURE25: GLenum
readonly TEXTURE26: GLenum
readonly TEXTURE27: GLenum
readonly TEXTURE28: GLenum
readonly TEXTURE29: GLenum
readonly TEXTURE3: GLenum
readonly TEXTURE30: GLenum
readonly TEXTURE31: GLenum
readonly TEXTURE4: GLenum
readonly TEXTURE5: GLenum
readonly TEXTURE6: GLenum
readonly TEXTURE7: GLenum
readonly TEXTURE8: GLenum
readonly TEXTURE9: GLenum
readonly TEXTURE_2D: GLenum
readonly TEXTURE_BINDING_2D: GLenum
readonly TEXTURE_BINDING_CUBE_MAP: GLenum
readonly TEXTURE_CUBE_MAP: GLenum
readonly TEXTURE_CUBE_MAP_NEGATIVE_X: GLenum
readonly TEXTURE_CUBE_MAP_NEGATIVE_Y: GLenum
readonly TEXTURE_CUBE_MAP_NEGATIVE_Z: GLenum
readonly TEXTURE_CUBE_MAP_POSITIVE_X: GLenum
readonly TEXTURE_CUBE_MAP_POSITIVE_Y: GLenum
readonly TEXTURE_CUBE_MAP_POSITIVE_Z: GLenum
readonly TEXTURE_MAG_FILTER: GLenum
readonly TEXTURE_MIN_FILTER: GLenum
readonly TEXTURE_WRAP_S: GLenum
readonly TEXTURE_WRAP_T: GLenum
readonly TRIANGLES: GLenum
readonly TRIANGLE_FAN: GLenum
readonly TRIANGLE_STRIP: GLenum
readonly UNPACK_ALIGNMENT: GLenum
readonly UNPACK_COLORSPACE_CONVERSION_WEBGL: GLenum
readonly UNPACK_FLIP_Y_WEBGL: GLenum
readonly UNPACK_PREMULTIPLY_ALPHA_WEBGL: GLenum
readonly UNSIGNED_BYTE: GLenum
readonly UNSIGNED_INT: GLenum
readonly UNSIGNED_SHORT: GLenum
readonly UNSIGNED_SHORT_4_4_4_4: GLenum
readonly UNSIGNED_SHORT_5_5_5_1: GLenum
readonly UNSIGNED_SHORT_5_6_5: GLenum
readonly VALIDATE_STATUS: GLenum
readonly VENDOR: GLenum
readonly VERSION: GLenum
readonly VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: GLenum
readonly VERTEX_ATTRIB_ARRAY_ENABLED: GLenum
readonly VERTEX_ATTRIB_ARRAY_NORMALIZED: GLenum
readonly VERTEX_ATTRIB_ARRAY_POINTER: GLenum
readonly VERTEX_ATTRIB_ARRAY_SIZE: GLenum
readonly VERTEX_ATTRIB_ARRAY_STRIDE: GLenum
readonly VERTEX_ATTRIB_ARRAY_TYPE: GLenum
readonly VERTEX_SHADER: GLenum
readonly VIEWPORT: GLenum
readonly ZERO: GLenum
}
type BufferSource = ArrayBufferView | ArrayBuffer
type Float32List = Float32Array | GLfloat[]
type TexImageSource =
| Image
| ImageData
| Canvas
| OffscreenCanvas
| VideoContext
interface WebGLRenderingContextOverloads {
bufferData(target: GLenum, size: GLsizeiptr, usage: GLenum): void
bufferData(
target: GLenum,
data: BufferSource | null,
usage: GLenum
): void
bufferSubData(
target: GLenum,
offset: GLintptr,
data: BufferSource
): void
compressedTexImage2D(
target: GLenum,
level: GLint,
internalformat: GLenum,
width: GLsizei,
height: GLsizei,
border: GLint,
data: ArrayBufferView
): void
compressedTexSubImage2D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
width: GLsizei,
height: GLsizei,
format: GLenum,
data: ArrayBufferView
): void
readPixels(
x: GLint,
y: GLint,
width: GLsizei,
height: GLsizei,
format: GLenum,
type: GLenum,
pixels: ArrayBufferView | null
): void
texImage2D(
target: GLenum,
level: GLint,
internalformat: GLint,
width: GLsizei,
height: GLsizei,
border: GLint,
format: GLenum,
type: GLenum,
pixels: ArrayBufferView | null
): void
texImage2D(
target: GLenum,
level: GLint,
internalformat: GLint,
format: GLenum,
type: GLenum,
source: TexImageSource
): void
texSubImage2D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
width: GLsizei,
height: GLsizei,
format: GLenum,
type: GLenum,
pixels: ArrayBufferView | null
): void
texSubImage2D(
target: GLenum,
level: GLint,
xoffset: GLint,
yoffset: GLint,
format: GLenum,
type: GLenum,
source: TexImageSource
): void
uniform1fv(location: WebGLUniformLocation | null, v: Float32List): void
uniform1iv(location: WebGLUniformLocation | null, v: Int32List): void
uniform2fv(location: WebGLUniformLocation | null, v: Float32List): void
uniform2iv(location: WebGLUniformLocation | null, v: Int32List): void
uniform3fv(location: WebGLUniformLocation | null, v: Float32List): void
uniform3iv(location: WebGLUniformLocation | null, v: Int32List): void
uniform4fv(location: WebGLUniformLocation | null, v: Float32List): void
uniform4iv(location: WebGLUniformLocation | null, v: Int32List): void
uniformMatrix2fv(
location: WebGLUniformLocation | null,
transpose: GLboolean,
value: Float32List
): void
uniformMatrix3fv(
location: WebGLUniformLocation | null,
transpose: GLboolean,
value: Float32List
): void
uniformMatrix4fv(
location: WebGLUniformLocation | null,
transpose: GLboolean,
value: Float32List
): void
}
interface WebGLSampler {}
/** The WebGLShader is part of the WebGL API and can either be a vertex or a fragment shader. A WebGLProgram requires both types of shaders. */
interface WebGLShader {}
/** Part of the WebGL API and represents the information returned by calling the WebGLRenderingContext.getShaderPrecisionFormat() method. */
interface WebGLShaderPrecisionFormat {
readonly precision: GLint
readonly rangeMax: GLint
readonly rangeMin: GLint
}
interface WebGLSync {}
/** Part of the WebGL API and represents an opaque texture object providing storage and state for texturing operations. */
interface WebGLTexture {}
interface WebGLTransformFeedback {}
/** Part of the WebGL API and represents the location of a uniform variable in a shader program. */
interface WebGLUniformLocation {}
interface WebGLVertexArrayObject {}
interface WebGLVertexArrayObjectOES {}
}
/*! *****************************************************************************
Copyright (c) 2023 Tencent, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***************************************************************************** */
/**
* Common interfaces and types
*/
interface IAPIError {
errMsg: string
}
interface IAPIParam<T = any> {
config?: ICloudConfig
success?: (res: T) => void
fail?: (err: IAPIError) => void
complete?: (val: T | IAPIError) => void
}
interface IAPISuccessParam {
errMsg: string
}
type IAPICompleteParam = IAPISuccessParam | IAPIError
type IAPIFunction<T, P extends IAPIParam<T>> = (param?: P) => Promise<T>
interface IInitCloudConfig {
env?:
| string
| {
database?: string
functions?: string
storage?: string
}
traceUser?: boolean
}
interface ICloudConfig {
env?: string
traceUser?: boolean
}
interface IICloudAPI {
init: (config?: IInitCloudConfig) => void
[api: string]: AnyFunction | IAPIFunction<any, any>
}
interface ICloudService {
name: string
getAPIs: () => { [name: string]: IAPIFunction<any, any> }
}
interface ICloudServices {
[serviceName: string]: ICloudService
}
interface ICloudMetaData {
session_id: string
}
declare class InternalSymbol {}
interface AnyObject {
[x: string]: any
}
type AnyArray = any[]
type AnyFunction = (...args: any[]) => any
/**
* extend wx with cloud
*/
interface WxCloud {
init: (config?: ICloudConfig) => void
callFunction(param: OQ<ICloud.CallFunctionParam>): void
callFunction(
param: RQ<ICloud.CallFunctionParam>
): Promise<ICloud.CallFunctionResult>
uploadFile(param: OQ<ICloud.UploadFileParam>): WechatMiniprogram.UploadTask
uploadFile(
param: RQ<ICloud.UploadFileParam>
): Promise<ICloud.UploadFileResult>
downloadFile(
param: OQ<ICloud.DownloadFileParam>
): WechatMiniprogram.DownloadTask
downloadFile(
param: RQ<ICloud.DownloadFileParam>
): Promise<ICloud.DownloadFileResult>
getTempFileURL(param: OQ<ICloud.GetTempFileURLParam>): void
getTempFileURL(
param: RQ<ICloud.GetTempFileURLParam>
): Promise<ICloud.GetTempFileURLResult>
deleteFile(param: OQ<ICloud.DeleteFileParam>): void
deleteFile(
param: RQ<ICloud.DeleteFileParam>
): Promise<ICloud.DeleteFileResult>
database: (config?: ICloudConfig) => DB.Database
CloudID: ICloud.ICloudIDConstructor
CDN: ICloud.ICDNConstructor
callContainer(param: OQ<ICloud.CallContainerParam>): void
callContainer(
param: RQ<ICloud.CallContainerParam>
): Promise<ICloud.CallContainerResult>
connectContainer(param: OQ<ICloud.ConnectContainerParam>): void
connectContainer(
param: RQ<ICloud.ConnectContainerParam>
): Promise<ICloud.ConnectContainerResult>
services: ICloud.CloudServices
}
declare namespace ICloud {
interface ICloudAPIParam<T = any> extends IAPIParam<T> {
config?: ICloudConfig
}
// === API: callFunction ===
type CallFunctionData = AnyObject
interface CallFunctionResult extends IAPISuccessParam {
result: AnyObject | string | undefined
}
interface CallFunctionParam extends ICloudAPIParam<CallFunctionResult> {
name: string
data?: CallFunctionData
slow?: boolean
}
// === end ===
// === API: container ===
type CallContainerData = AnyObject
interface CallContainerResult extends IAPISuccessParam {
data: any
statusCode: number
header: Record<string, any>
callID: string
}
interface CallContainerParam extends ICloudAPIParam<CallContainerResult> {
path: string
service?: string
method?: string
header?: Record<string, any>
data?: any // string, object, ArrayBuffer
dataType?: string
responseType?: string
timeout?: number
verbose?: boolean
followRedirect?: boolean
}
interface ConnectContainerResult extends IAPISuccessParam {
socketTask: WechatMiniprogram.SocketTask
}
interface ConnectSocketOptions extends IAPIParam<void> {
header?: Record<string, string>
protocols?: string[]
tcpNoDelay?: boolean
perMessageDeflate?: boolean
timeout?: number
}
type ConnectContainerParam = Omit<
ConnectSocketOptions,
'success' | 'fail' | 'complete'
> &
ICloudAPIParam<ConnectContainerResult> & {
service: string
path?: string
}
// === end ===
// === API: services ===
type AsyncSession<T> = T | PromiseLike<T>
interface GatewayCallOptions {
path: string
data: any
shouldSerialize?: boolean
apiVersion?: number
}
interface GatewayInstance {
call: (
param: CallContainerParam & GatewayCallOptions
) => Promise<CallContainerResult>
refresh: (session: AsyncSession<string>) => Promise<void>
}
interface GatewayConstructOptions {
id: string
appid?: string
domain?: string
keepalive?: boolean
prefetch?: boolean
prefetchOptions?: {
concurrent?: number
enableQuic?: boolean
enableHttp2?: boolean
}
}
interface CloudServices {
Gateway: (opts: GatewayConstructOptions) => GatewayInstance
}
// === end ===
// === API: uploadFile ===
interface UploadFileResult extends IAPISuccessParam {
fileID: string
statusCode: number
}
interface UploadFileParam extends ICloudAPIParam<UploadFileResult> {
cloudPath: string
filePath: string
header?: AnyObject
}
// === end ===
// === API: downloadFile ===
interface DownloadFileResult extends IAPISuccessParam {
tempFilePath: string
statusCode: number
}
interface DownloadFileParam extends ICloudAPIParam<DownloadFileResult> {
fileID: string
cloudPath?: string
}
// === end ===
// === API: getTempFileURL ===
interface GetTempFileURLResult extends IAPISuccessParam {
fileList: GetTempFileURLResultItem[]
}
interface GetTempFileURLResultItem {
fileID: string
tempFileURL: string
maxAge: number
status: number
errMsg: string
}
interface GetTempFileURLParam extends ICloudAPIParam<GetTempFileURLResult> {
fileList: string[]
}
// === end ===
// === API: deleteFile ===
interface DeleteFileResult extends IAPISuccessParam {
fileList: DeleteFileResultItem[]
}
interface DeleteFileResultItem {
fileID: string
status: number
errMsg: string
}
interface DeleteFileParam extends ICloudAPIParam<DeleteFileResult> {
fileList: string[]
}
// === end ===
// === API: CloudID ===
abstract class CloudID {
constructor(cloudID: string)
}
interface ICloudIDConstructor {
new (cloudId: string): CloudID
(cloudId: string): CloudID
}
// === end ===
// === API: CDN ===
abstract class CDN {
target: string | ArrayBuffer | ICDNFilePathSpec
constructor(target: string | ArrayBuffer | ICDNFilePathSpec)
}
interface ICDNFilePathSpec {
type: 'filePath'
filePath: string
}
interface ICDNConstructor {
new (options: string | ArrayBuffer | ICDNFilePathSpec): CDN
(options: string | ArrayBuffer | ICDNFilePathSpec): CDN
}
// === end ===
}
// === Database ===
declare namespace DB {
/**
* The class of all exposed cloud database instances
*/
class Database {
readonly config: ICloudConfig
readonly command: DatabaseCommand
readonly Geo: IGeo
readonly serverDate: () => ServerDate
readonly RegExp: IRegExpConstructor
private constructor()
collection(collectionName: string): CollectionReference
}
class CollectionReference extends Query {
readonly collectionName: string
private constructor(name: string, database: Database)
doc(docId: string | number): DocumentReference
add(options: OQ<IAddDocumentOptions>): void
add(options: RQ<IAddDocumentOptions>): Promise<IAddResult>
}
class DocumentReference {
private constructor(docId: string | number, database: Database)
field(object: Record<string, any>): this
get(options: OQ<IGetDocumentOptions>): void
get(options?: RQ<IGetDocumentOptions>): Promise<IQuerySingleResult>
set(options: OQ<ISetSingleDocumentOptions>): void
set(options?: RQ<ISetSingleDocumentOptions>): Promise<ISetResult>
update(options: OQ<IUpdateSingleDocumentOptions>): void
update(
options?: RQ<IUpdateSingleDocumentOptions>
): Promise<IUpdateResult>
remove(options: OQ<IRemoveSingleDocumentOptions>): void
remove(
options?: RQ<IRemoveSingleDocumentOptions>
): Promise<IRemoveResult>
watch(options: IWatchOptions): RealtimeListener
}
class RealtimeListener {
// "And Now His Watch Is Ended"
close: () => Promise<void>
}
class Query {
where(condition: IQueryCondition): Query
orderBy(fieldPath: string, order: string): Query
limit(max: number): Query
skip(offset: number): Query
field(object: Record<string, any>): Query
get(options: OQ<IGetDocumentOptions>): void
get(options?: RQ<IGetDocumentOptions>): Promise<IQueryResult>
count(options: OQ<ICountDocumentOptions>): void
count(options?: RQ<ICountDocumentOptions>): Promise<ICountResult>
watch(options: IWatchOptions): RealtimeListener
}
interface DatabaseCommand {
eq(val: any): DatabaseQueryCommand
neq(val: any): DatabaseQueryCommand
gt(val: any): DatabaseQueryCommand
gte(val: any): DatabaseQueryCommand
lt(val: any): DatabaseQueryCommand
lte(val: any): DatabaseQueryCommand
in(val: any[]): DatabaseQueryCommand
nin(val: any[]): DatabaseQueryCommand
geoNear(options: IGeoNearCommandOptions): DatabaseQueryCommand
geoWithin(options: IGeoWithinCommandOptions): DatabaseQueryCommand
geoIntersects(
options: IGeoIntersectsCommandOptions
): DatabaseQueryCommand
and(
...expressions: Array<DatabaseLogicCommand | IQueryCondition>
): DatabaseLogicCommand
or(
...expressions: Array<DatabaseLogicCommand | IQueryCondition>
): DatabaseLogicCommand
nor(
...expressions: Array<DatabaseLogicCommand | IQueryCondition>
): DatabaseLogicCommand
not(expression: DatabaseLogicCommand): DatabaseLogicCommand
exists(val: boolean): DatabaseQueryCommand
mod(divisor: number, remainder: number): DatabaseQueryCommand
all(val: any[]): DatabaseQueryCommand
elemMatch(val: any): DatabaseQueryCommand
size(val: number): DatabaseQueryCommand
set(val: any): DatabaseUpdateCommand
remove(): DatabaseUpdateCommand
inc(val: number): DatabaseUpdateCommand
mul(val: number): DatabaseUpdateCommand
min(val: number): DatabaseUpdateCommand
max(val: number): DatabaseUpdateCommand
rename(val: string): DatabaseUpdateCommand
bit(val: number): DatabaseUpdateCommand
push(...values: any[]): DatabaseUpdateCommand
pop(): DatabaseUpdateCommand
shift(): DatabaseUpdateCommand
unshift(...values: any[]): DatabaseUpdateCommand
addToSet(val: any): DatabaseUpdateCommand
pull(val: any): DatabaseUpdateCommand
pullAll(val: any): DatabaseUpdateCommand
project: {
slice(val: number | [number, number]): DatabaseProjectionCommand
}
aggregate: {
__safe_props__?: Set<string>
abs(val: any): DatabaseAggregateCommand
add(val: any): DatabaseAggregateCommand
addToSet(val: any): DatabaseAggregateCommand
allElementsTrue(val: any): DatabaseAggregateCommand
and(val: any): DatabaseAggregateCommand
anyElementTrue(val: any): DatabaseAggregateCommand
arrayElemAt(val: any): DatabaseAggregateCommand
arrayToObject(val: any): DatabaseAggregateCommand
avg(val: any): DatabaseAggregateCommand
ceil(val: any): DatabaseAggregateCommand
cmp(val: any): DatabaseAggregateCommand
concat(val: any): DatabaseAggregateCommand
concatArrays(val: any): DatabaseAggregateCommand
cond(val: any): DatabaseAggregateCommand
convert(val: any): DatabaseAggregateCommand
dateFromParts(val: any): DatabaseAggregateCommand
dateToParts(val: any): DatabaseAggregateCommand
dateFromString(val: any): DatabaseAggregateCommand
dateToString(val: any): DatabaseAggregateCommand
dayOfMonth(val: any): DatabaseAggregateCommand
dayOfWeek(val: any): DatabaseAggregateCommand
dayOfYear(val: any): DatabaseAggregateCommand
divide(val: any): DatabaseAggregateCommand
eq(val: any): DatabaseAggregateCommand
exp(val: any): DatabaseAggregateCommand
filter(val: any): DatabaseAggregateCommand
first(val: any): DatabaseAggregateCommand
floor(val: any): DatabaseAggregateCommand
gt(val: any): DatabaseAggregateCommand
gte(val: any): DatabaseAggregateCommand
hour(val: any): DatabaseAggregateCommand
ifNull(val: any): DatabaseAggregateCommand
in(val: any): DatabaseAggregateCommand
indexOfArray(val: any): DatabaseAggregateCommand
indexOfBytes(val: any): DatabaseAggregateCommand
indexOfCP(val: any): DatabaseAggregateCommand
isArray(val: any): DatabaseAggregateCommand
isoDayOfWeek(val: any): DatabaseAggregateCommand
isoWeek(val: any): DatabaseAggregateCommand
isoWeekYear(val: any): DatabaseAggregateCommand
last(val: any): DatabaseAggregateCommand
let(val: any): DatabaseAggregateCommand
literal(val: any): DatabaseAggregateCommand
ln(val: any): DatabaseAggregateCommand
log(val: any): DatabaseAggregateCommand
log10(val: any): DatabaseAggregateCommand
lt(val: any): DatabaseAggregateCommand
lte(val: any): DatabaseAggregateCommand
ltrim(val: any): DatabaseAggregateCommand
map(val: any): DatabaseAggregateCommand
max(val: any): DatabaseAggregateCommand
mergeObjects(val: any): DatabaseAggregateCommand
meta(val: any): DatabaseAggregateCommand
min(val: any): DatabaseAggregateCommand
millisecond(val: any): DatabaseAggregateCommand
minute(val: any): DatabaseAggregateCommand
mod(val: any): DatabaseAggregateCommand
month(val: any): DatabaseAggregateCommand
multiply(val: any): DatabaseAggregateCommand
neq(val: any): DatabaseAggregateCommand
not(val: any): DatabaseAggregateCommand
objectToArray(val: any): DatabaseAggregateCommand
or(val: any): DatabaseAggregateCommand
pow(val: any): DatabaseAggregateCommand
push(val: any): DatabaseAggregateCommand
range(val: any): DatabaseAggregateCommand
reduce(val: any): DatabaseAggregateCommand
reverseArray(val: any): DatabaseAggregateCommand
rtrim(val: any): DatabaseAggregateCommand
second(val: any): DatabaseAggregateCommand
setDifference(val: any): DatabaseAggregateCommand
setEquals(val: any): DatabaseAggregateCommand
setIntersection(val: any): DatabaseAggregateCommand
setIsSubset(val: any): DatabaseAggregateCommand
setUnion(val: any): DatabaseAggregateCommand
size(val: any): DatabaseAggregateCommand
slice(val: any): DatabaseAggregateCommand
split(val: any): DatabaseAggregateCommand
sqrt(val: any): DatabaseAggregateCommand
stdDevPop(val: any): DatabaseAggregateCommand
stdDevSamp(val: any): DatabaseAggregateCommand
strcasecmp(val: any): DatabaseAggregateCommand
strLenBytes(val: any): DatabaseAggregateCommand
strLenCP(val: any): DatabaseAggregateCommand
substr(val: any): DatabaseAggregateCommand
substrBytes(val: any): DatabaseAggregateCommand
substrCP(val: any): DatabaseAggregateCommand
subtract(val: any): DatabaseAggregateCommand
sum(val: any): DatabaseAggregateCommand
switch(val: any): DatabaseAggregateCommand
toBool(val: any): DatabaseAggregateCommand
toDate(val: any): DatabaseAggregateCommand
toDecimal(val: any): DatabaseAggregateCommand
toDouble(val: any): DatabaseAggregateCommand
toInt(val: any): DatabaseAggregateCommand
toLong(val: any): DatabaseAggregateCommand
toObjectId(val: any): DatabaseAggregateCommand
toString(val: any): DatabaseAggregateCommand
toLower(val: any): DatabaseAggregateCommand
toUpper(val: any): DatabaseAggregateCommand
trim(val: any): DatabaseAggregateCommand
trunc(val: any): DatabaseAggregateCommand
type(val: any): DatabaseAggregateCommand
week(val: any): DatabaseAggregateCommand
year(val: any): DatabaseAggregateCommand
zip(val: any): DatabaseAggregateCommand
}
}
class DatabaseAggregateCommand {}
enum LOGIC_COMMANDS_LITERAL {
AND = 'and',
OR = 'or',
NOT = 'not',
NOR = 'nor'
}
class DatabaseLogicCommand {
and(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
or(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
nor(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
not(expression: DatabaseLogicCommand): DatabaseLogicCommand
}
enum QUERY_COMMANDS_LITERAL {
// comparison
EQ = 'eq',
NEQ = 'neq',
GT = 'gt',
GTE = 'gte',
LT = 'lt',
LTE = 'lte',
IN = 'in',
NIN = 'nin',
// geo
GEO_NEAR = 'geoNear',
GEO_WITHIN = 'geoWithin',
GEO_INTERSECTS = 'geoIntersects',
// element
EXISTS = 'exists',
// evaluation
MOD = 'mod',
// array
ALL = 'all',
ELEM_MATCH = 'elemMatch',
SIZE = 'size'
}
class DatabaseQueryCommand extends DatabaseLogicCommand {
eq(val: any): DatabaseLogicCommand
neq(val: any): DatabaseLogicCommand
gt(val: any): DatabaseLogicCommand
gte(val: any): DatabaseLogicCommand
lt(val: any): DatabaseLogicCommand
lte(val: any): DatabaseLogicCommand
in(val: any[]): DatabaseLogicCommand
nin(val: any[]): DatabaseLogicCommand
exists(val: boolean): DatabaseLogicCommand
mod(divisor: number, remainder: number): DatabaseLogicCommand
all(val: any[]): DatabaseLogicCommand
elemMatch(val: any): DatabaseLogicCommand
size(val: number): DatabaseLogicCommand
geoNear(options: IGeoNearCommandOptions): DatabaseLogicCommand
geoWithin(options: IGeoWithinCommandOptions): DatabaseLogicCommand
geoIntersects(
options: IGeoIntersectsCommandOptions
): DatabaseLogicCommand
}
enum PROJECTION_COMMANDS_LITERAL {
SLICE = 'slice'
}
class DatabaseProjectionCommand {}
enum UPDATE_COMMANDS_LITERAL {
// field
SET = 'set',
REMOVE = 'remove',
INC = 'inc',
MUL = 'mul',
MIN = 'min',
MAX = 'max',
RENAME = 'rename',
// bitwise
BIT = 'bit',
// array
PUSH = 'push',
POP = 'pop',
SHIFT = 'shift',
UNSHIFT = 'unshift',
ADD_TO_SET = 'addToSet',
PULL = 'pull',
PULL_ALL = 'pullAll'
}
class DatabaseUpdateCommand {}
class Batch {}
/**
* A contract that all API provider must adhere to
*/
class APIBaseContract<
PromiseReturn,
CallbackReturn,
Param extends IAPIParam,
Context = any
> {
getContext(param: Param): Context
/**
* In case of callback-style invocation, this function will be called
*/
getCallbackReturn(param: Param, context: Context): CallbackReturn
getFinalParam<T extends Param>(param: Param, context: Context): T
run<T extends Param>(param: T): Promise<PromiseReturn>
}
interface IGeoPointConstructor {
new (longitude: number, latitide: number): GeoPoint
new (geojson: IGeoJSONPoint): GeoPoint
(longitude: number, latitide: number): GeoPoint
(geojson: IGeoJSONPoint): GeoPoint
}
interface IGeoMultiPointConstructor {
new (points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint
(points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint
}
interface IGeoLineStringConstructor {
new (points: GeoPoint[] | IGeoJSONLineString): GeoLineString
(points: GeoPoint[] | IGeoJSONLineString): GeoLineString
}
interface IGeoMultiLineStringConstructor {
new (
lineStrings: GeoLineString[] | IGeoJSONMultiLineString
): GeoMultiLineString
(
lineStrings: GeoLineString[] | IGeoJSONMultiLineString
): GeoMultiLineString
}
interface IGeoPolygonConstructor {
new (lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon
(lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon
}
interface IGeoMultiPolygonConstructor {
new (polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon
(polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon
}
interface IGeo {
Point: IGeoPointConstructor
MultiPoint: IGeoMultiPointConstructor
LineString: IGeoLineStringConstructor
MultiLineString: IGeoMultiLineStringConstructor
Polygon: IGeoPolygonConstructor
MultiPolygon: IGeoMultiPolygonConstructor
}
interface IGeoJSONPoint {
type: 'Point'
coordinates: [number, number]
}
interface IGeoJSONMultiPoint {
type: 'MultiPoint'
coordinates: Array<[number, number]>
}
interface IGeoJSONLineString {
type: 'LineString'
coordinates: Array<[number, number]>
}
interface IGeoJSONMultiLineString {
type: 'MultiLineString'
coordinates: Array<Array<[number, number]>>
}
interface IGeoJSONPolygon {
type: 'Polygon'
coordinates: Array<Array<[number, number]>>
}
interface IGeoJSONMultiPolygon {
type: 'MultiPolygon'
coordinates: Array<Array<Array<[number, number]>>>
}
type IGeoJSONObject =
| IGeoJSONPoint
| IGeoJSONMultiPoint
| IGeoJSONLineString
| IGeoJSONMultiLineString
| IGeoJSONPolygon
| IGeoJSONMultiPolygon
abstract class GeoPoint {
longitude: number
latitude: number
constructor(longitude: number, latitude: number)
toJSON(): Record<string, any>
toString(): string
}
abstract class GeoMultiPoint {
points: GeoPoint[]
constructor(points: GeoPoint[])
toJSON(): IGeoJSONMultiPoint
toString(): string
}
abstract class GeoLineString {
points: GeoPoint[]
constructor(points: GeoPoint[])
toJSON(): IGeoJSONLineString
toString(): string
}
abstract class GeoMultiLineString {
lines: GeoLineString[]
constructor(lines: GeoLineString[])
toJSON(): IGeoJSONMultiLineString
toString(): string
}
abstract class GeoPolygon {
lines: GeoLineString[]
constructor(lines: GeoLineString[])
toJSON(): IGeoJSONPolygon
toString(): string
}
abstract class GeoMultiPolygon {
polygons: GeoPolygon[]
constructor(polygons: GeoPolygon[])
toJSON(): IGeoJSONMultiPolygon
toString(): string
}
type GeoInstance =
| GeoPoint
| GeoMultiPoint
| GeoLineString
| GeoMultiLineString
| GeoPolygon
| GeoMultiPolygon
interface IGeoNearCommandOptions {
geometry: GeoPoint
maxDistance?: number
minDistance?: number
}
interface IGeoWithinCommandOptions {
geometry: GeoPolygon | GeoMultiPolygon
}
interface IGeoIntersectsCommandOptions {
geometry:
| GeoPoint
| GeoMultiPoint
| GeoLineString
| GeoMultiLineString
| GeoPolygon
| GeoMultiPolygon
}
interface IServerDateOptions {
offset: number
}
abstract class ServerDate {
readonly options: IServerDateOptions
constructor(options?: IServerDateOptions)
}
interface IRegExpOptions {
regexp: string
options?: string
}
interface IRegExpConstructor {
new (options: IRegExpOptions): RegExp
(options: IRegExpOptions): RegExp
}
abstract class RegExp {
readonly regexp: string
readonly options: string
constructor(options: IRegExpOptions)
}
type DocumentId = string | number
interface IDocumentData {
_id?: DocumentId
[key: string]: any
}
type IDBAPIParam = IAPIParam
interface IAddDocumentOptions extends IDBAPIParam {
data: IDocumentData
}
type IGetDocumentOptions = IDBAPIParam
type ICountDocumentOptions = IDBAPIParam
interface IUpdateDocumentOptions extends IDBAPIParam {
data: IUpdateCondition
}
interface IUpdateSingleDocumentOptions extends IDBAPIParam {
data: IUpdateCondition
}
interface ISetDocumentOptions extends IDBAPIParam {
data: IUpdateCondition
}
interface ISetSingleDocumentOptions extends IDBAPIParam {
data: IUpdateCondition
}
interface IRemoveDocumentOptions extends IDBAPIParam {
query: IQueryCondition
}
type IRemoveSingleDocumentOptions = IDBAPIParam
interface IWatchOptions {
// server realtime data init & change event
onChange: (snapshot: ISnapshot) => void
// error while connecting / listening
onError: (error: any) => void
}
interface ISnapshot {
id: number
docChanges: ISingleDBEvent[]
docs: Record<string, any>
type?: SnapshotType
}
type SnapshotType = 'init'
interface ISingleDBEvent {
id: number
dataType: DataType
queueType: QueueType
docId: string
doc: Record<string, any>
updatedFields?: Record<string, any>
removedFields?: string[]
}
type DataType = 'init' | 'update' | 'replace' | 'add' | 'remove' | 'limit'
type QueueType = 'init' | 'enqueue' | 'dequeue' | 'update'
interface IQueryCondition {
[key: string]: any
}
type IStringQueryCondition = string
interface IQueryResult extends IAPISuccessParam {
data: IDocumentData[]
}
interface IQuerySingleResult extends IAPISuccessParam {
data: IDocumentData
}
interface IUpdateCondition {
[key: string]: any
}
type IStringUpdateCondition = string
interface IAddResult extends IAPISuccessParam {
_id: DocumentId
}
interface IUpdateResult extends IAPISuccessParam {
stats: {
updated: number
// created: number,
}
}
interface ISetResult extends IAPISuccessParam {
_id: DocumentId
stats: {
updated: number
created: number
}
}
interface IRemoveResult extends IAPISuccessParam {
stats: {
removed: number
}
}
interface ICountResult extends IAPISuccessParam {
total: number
}
}
type Optional<T> = { [K in keyof T]+?: T[K] }
type OQ<
T extends Optional<
Record<'complete' | 'success' | 'fail', (...args: any[]) => any>
>
> =
| (RQ<T> & Required<Pick<T, 'success'>>)
| (RQ<T> & Required<Pick<T, 'fail'>>)
| (RQ<T> & Required<Pick<T, 'complete'>>)
| (RQ<T> & Required<Pick<T, 'success' | 'fail'>>)
| (RQ<T> & Required<Pick<T, 'success' | 'complete'>>)
| (RQ<T> & Required<Pick<T, 'fail' | 'complete'>>)
| (RQ<T> & Required<Pick<T, 'fail' | 'complete' | 'success'>>)
type RQ<
T extends Optional<
Record<'complete' | 'success' | 'fail', (...args: any[]) => any>
>
> = Pick<T, Exclude<keyof T, 'complete' | 'success' | 'fail'>>
/*! *****************************************************************************
Copyright (c) 2023 Tencent, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***************************************************************************** */
declare namespace WechatMiniprogram.Component {
type Instance<
TData extends DataOption,
TProperty extends PropertyOption,
TMethod extends Partial<MethodOption>,
TCustomInstanceProperty extends IAnyObject = {},
TIsPage extends boolean = false
> = InstanceProperties &
InstanceMethods<TData> &
TMethod &
(TIsPage extends true ? Page.ILifetime : {}) &
TCustomInstanceProperty & {
/** 组件数据,**包括内部数据和属性值** */
data: TData & PropertyOptionToData<TProperty>
/** 组件数据,**包括内部数据和属性值**(与 `data` 一致) */
properties: TData & PropertyOptionToData<TProperty>
}
type TrivialInstance = Instance<
IAnyObject,
IAnyObject,
IAnyObject,
IAnyObject
>
type TrivialOption = Options<IAnyObject, IAnyObject, IAnyObject, IAnyObject>
type Options<
TData extends DataOption,
TProperty extends PropertyOption,
TMethod extends MethodOption,
TCustomInstanceProperty extends IAnyObject = {},
TIsPage extends boolean = false
> = Partial<Data<TData>> &
Partial<Property<TProperty>> &
Partial<Method<TMethod, TIsPage>> &
Partial<OtherOption> &
Partial<Lifetimes> &
ThisType<
Instance<
TData,
TProperty,
TMethod,
TCustomInstanceProperty,
TIsPage
>
>
interface Constructor {
<
TData extends DataOption,
TProperty extends PropertyOption,
TMethod extends MethodOption,
TCustomInstanceProperty extends IAnyObject = {},
TIsPage extends boolean = false
>(
options: Options<
TData,
TProperty,
TMethod,
TCustomInstanceProperty,
TIsPage
>
): string
}
type DataOption = Record<string, any>
type PropertyOption = Record<string, AllProperty>
type MethodOption = Record<string, Function>
interface Data<D extends DataOption> {
/** 组件的内部数据,和 `properties` 一同用于组件的模板渲染 */
data?: D
}
interface Property<P extends PropertyOption> {
/** 组件的对外属性,是属性名到属性设置的映射表 */
properties: P
}
interface Method<M extends MethodOption, TIsPage extends boolean = false> {
/** 组件的方法,包括事件响应函数和任意的自定义方法,关于事件响应函数的使用,参见 [组件间通信与事件](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/events.html) */
methods: M & (TIsPage extends true ? Partial<Page.ILifetime> : {})
}
type PropertyType =
| StringConstructor
| NumberConstructor
| BooleanConstructor
| ArrayConstructor
| ObjectConstructor
| null
type ValueType<T extends PropertyType> = T extends null
? any
: T extends StringConstructor
? string
: T extends NumberConstructor
? number
: T extends BooleanConstructor
? boolean
: T extends ArrayConstructor
? any[]
: T extends ObjectConstructor
? IAnyObject
: never
type FullProperty<T extends PropertyType> = {
/** 属性类型 */
type: T
/** 属性初始值 */
value?: ValueType<T>
/** 属性值被更改时的响应函数 */
observer?:
| string
| ((
newVal: ValueType<T>,
oldVal: ValueType<T>,
changedPath: Array<string | number>
) => void)
/** 属性的类型(可以指定多个) */
optionalTypes?: ShortProperty[]
}
type AllFullProperty =
| FullProperty<StringConstructor>
| FullProperty<NumberConstructor>
| FullProperty<BooleanConstructor>
| FullProperty<ArrayConstructor>
| FullProperty<ObjectConstructor>
| FullProperty<null>
type ShortProperty =
| StringConstructor
| NumberConstructor
| BooleanConstructor
| ArrayConstructor
| ObjectConstructor
| null
type AllProperty = AllFullProperty | ShortProperty
type PropertyToData<T extends AllProperty> = T extends ShortProperty
? ValueType<T>
: FullPropertyToData<Exclude<T, ShortProperty>>
type FullPropertyToData<T extends AllFullProperty> = ValueType<T['type']>
// type FullPropertyToData<T extends AllFullProperty> = unknown extends T['value'] ? ValueType<T['type']> : T['value']
type PropertyOptionToData<P extends PropertyOption> = {
[name in keyof P]: PropertyToData<P[name]>
}
interface InstanceProperties {
/** 组件的文件路径 */
is: string
/** 节点id */
id: string
/** 节点dataset */
dataset: Record<string, string>
}
interface InstanceMethods<D extends DataOption> {
/** `setData` 函数用于将数据从逻辑层发送到视图层
*(异步),同时改变对应的 `this.data` 的值(同步)。
*
* **注意:**
*
* 1. **直接修改 this.data 而不调用 this.setData 是无法改变页面的状态的,还会造成数据不一致**。
* 1. 仅支持设置可 JSON 化的数据。
* 1. 单次设置的数据不能超过1024kB,请尽量避免一次设置过多的数据。
* 1. 请不要把 data 中任何一项的 value 设为 `undefined` ,否则这一项将不被设置并可能遗留一些潜在问题。
*/
setData(
/** 这次要改变的数据
*
* 以 `key: value` 的形式表示,将 `this.data` 中的 `key` 对应的值改变成 `value`。
*
* 其中 `key` 可以以数据路径的形式给出,支持改变数组中的某一项或对象的某个属性,如 `array[2].message`,`a.b.c.d`,并且不需要在 this.data 中预先定义。
*/
data: Partial<D> & IAnyObject,
/** setData引起的界面更新渲染完毕后的回调函数,最低基础库: `1.5.0` */
callback?: () => void
): void
/** 检查组件是否具有 `behavior` (检查时会递归检查被直接或间接引入的所有behavior) */
hasBehavior(behavior: Behavior.BehaviorIdentifier): void
/** 触发事件,参见组件事件 */
triggerEvent<DetailType = any>(
name: string,
detail?: DetailType,
options?: TriggerEventOption
): void
/** 创建一个 SelectorQuery 对象,选择器选取范围为这个组件实例内 */
createSelectorQuery(): SelectorQuery
/** 创建一个 IntersectionObserver 对象,选择器选取范围为这个组件实例内 */
createIntersectionObserver(
options: CreateIntersectionObserverOption
): IntersectionObserver
/** 使用选择器选择组件实例节点,返回匹配到的第一个组件实例对象(会被 `wx://component-export` 影响) */
selectComponent(selector: string): TrivialInstance
/** 使用选择器选择组件实例节点,返回匹配到的全部组件实例对象组成的数组 */
selectAllComponents(selector: string): TrivialInstance[]
/**
* 选取当前组件节点所在的组件实例(即组件的引用者),返回它的组件实例对象(会被 `wx://component-export` 影响)
*
* 最低基础库版本:[`2.8.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
**/
selectOwnerComponent(): TrivialInstance
/** 获取这个关系所对应的所有关联节点,参见 组件间关系 */
getRelationNodes(relationKey: string): TrivialInstance[]
/**
* 立刻执行 callback ,其中的多个 setData 之间不会触发界面绘制(只有某些特殊场景中需要,如用于在不同组件同时 setData 时进行界面绘制同步)
*
* 最低基础库版本:[`2.4.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
**/
groupSetData(callback?: () => void): void
/**
* 返回当前页面的 custom-tab-bar 的组件实例
*
* 最低基础库版本:[`2.6.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
**/
getTabBar(): TrivialInstance
/**
* 返回页面标识符(一个字符串),可以用来判断几个自定义组件实例是不是在同一个页面内
*
* 最低基础库版本:[`2.7.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
**/
getPageId(): string
/**
* 执行关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
*
* 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
**/
animate(
selector: string,
keyFrames: KeyFrame[],
duration: number,
callback?: () => void
): void
/**
* 执行关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
*
* 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
**/
animate(
selector: string,
keyFrames: ScrollTimelineKeyframe[],
duration: number,
scrollTimeline: ScrollTimelineOption
): void
/**
* 清除关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
*
* 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
**/
clearAnimation(selector: string, callback: () => void): void
/**
* 清除关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
*
* 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
**/
clearAnimation(
selector: string,
options?: ClearAnimationOptions,
callback?: () => void
): void
/**
* 当从另一页面跳转到该页面时,获得与来源页面实例通信当事件通道,详见 [wx.navigateTo]((wx.navigateTo))
*
* 最低基础库版本:[`2.7.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
getOpenerEventChannel(): EventChannel
/**
* 获取更新性能统计信息,详见 [获取更新性能统计信息]((custom-component/update-perf-stat))
*
*
* 最低基础库版本:[`2.12.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
setUpdatePerformanceListener<WithDataPath extends boolean = false>(
options: SetUpdatePerformanceListenerOption<WithDataPath>,
callback?: UpdatePerformanceListener<WithDataPath>
): void
/**
* 在运行时获取页面或组件所在页面 `touch` 相关事件的 passive 配置,详见 [enablePassiveEvent]((configuration/app#enablePassiveEvent))
*
* 最低基础库版本:[`2.25.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
getPassiveEvent(callback: (config: PassiveConfig) => void): void
/**
* 在运行时切换页面或组件所在页面 `touch` 相关事件的 passive 配置,详见 [enablePassiveEvent]((configuration/app#enablePassiveEvent))
*
* 最低基础库版本:[`2.25.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
setPassiveEvent(config: PassiveConfig): void
}
interface ComponentOptions {
/**
* [启用多slot支持](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件wxml的slot)
*/
multipleSlots?: boolean
/**
* [组件样式隔离](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件样式隔离)
*/
addGlobalClass?: boolean
/**
* [组件样式隔离](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件样式隔离)
*/
styleIsolation?:
| 'isolated'
| 'apply-shared'
| 'shared'
| 'page-isolated'
| 'page-apply-shared'
| 'page-shared'
/**
* [纯数据字段](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/pure-data.html) 是一些不用于界面渲染的 data 字段,可以用于提升页面更新性能。从小程序基础库版本 2.8.2 开始支持。
*/
pureDataPattern?: RegExp
/**
* [虚拟化组件节点](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#%E8%99%9A%E6%8B%9F%E5%8C%96%E7%BB%84%E4%BB%B6%E8%8A%82%E7%82%B9) 使自定义组件内部的第一层节点由自定义组件本身完全决定。从小程序基础库版本 [`2.11.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) 开始支持 */
virtualHost?: boolean
}
interface TriggerEventOption {
/** 事件是否冒泡
*
* 默认值: `false`
*/
bubbles?: boolean
/** 事件是否可以穿越组件边界,为false时,事件将只能在引用组件的节点树上触发,不进入其他任何组件内部
*
* 默认值: `false`
*/
composed?: boolean
/** 事件是否拥有捕获阶段
*
* 默认值: `false`
*/
capturePhase?: boolean
}
interface RelationOption {
/** 目标组件的相对关系 */
type: 'parent' | 'child' | 'ancestor' | 'descendant'
/** 关系生命周期函数,当关系被建立在页面节点树中时触发,触发时机在组件attached生命周期之后 */
linked?(target: TrivialInstance): void
/** 关系生命周期函数,当关系在页面节点树中发生改变时触发,触发时机在组件moved生命周期之后 */
linkChanged?(target: TrivialInstance): void
/** 关系生命周期函数,当关系脱离页面节点树时触发,触发时机在组件detached生命周期之后 */
unlinked?(target: TrivialInstance): void
/** 如果这一项被设置,则它表示关联的目标节点所应具有的behavior,所有拥有这一behavior的组件节点都会被关联 */
target?: string
}
interface PageLifetimes {
/** 页面生命周期回调—监听页面显示
*
* 页面显示/切入前台时触发。
*/
show(): void
/** 页面生命周期回调—监听页面隐藏
*
* 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。
*/
hide(): void
/** 页面生命周期回调—监听页面尺寸变化
*
* 所在页面尺寸变化时执行
*/
resize(size: Page.IResizeOption): void
}
type DefinitionFilter = <T extends TrivialOption>(
/** 使用该 behavior 的 component/behavior 的定义对象 */
defFields: T,
/** 该 behavior 所使用的 behavior 的 definitionFilter 函数列表 */
definitionFilterArr?: DefinitionFilter[]
) => void
interface Lifetimes {
/** 组件生命周期声明对象,组件的生命周期:`created`、`attached`、`ready`、`moved`、`detached` 将收归到 `lifetimes` 字段内进行声明,原有声明方式仍旧有效,如同时存在两种声明方式,则 `lifetimes` 字段内声明方式优先级最高
*
* 最低基础库: `2.2.3` */
lifetimes: Partial<{
/**
* 在组件实例刚刚被创建时执行,注意此时不能调用 `setData`
*
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
created(): void
/**
* 在组件实例进入页面节点树时执行
*
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
attached(): void
/**
* 在组件在视图层布局完成后执行
*
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
ready(): void
/**
* 在组件实例被移动到节点树另一个位置时执行
*
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
moved(): void
/**
* 在组件实例被从页面节点树移除时执行
*
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
detached(): void
/**
* 每当组件方法抛出错误时执行
*
* 最低基础库版本:[`2.4.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
error(err: Error): void
}>
/**
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
*
* 在组件实例刚刚被创建时执行
*
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
created(): void
/**
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
*
* 在组件实例进入页面节点树时执行
*
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
attached(): void
/**
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
*
* 在组件在视图层布局完成后执行
*
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
ready(): void
/**
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
*
* 在组件实例被移动到节点树另一个位置时执行
*
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
moved(): void
/**
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
*
* 在组件实例被从页面节点树移除时执行
*
* 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
detached(): void
/**
* @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
*
* 每当组件方法抛出错误时执行
*
* 最低基础库版本:[`2.4.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
error(err: Error): void
}
interface OtherOption {
/** 类似于mixins和traits的组件间代码复用机制,参见 [behaviors](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/behaviors.html) */
behaviors: Behavior.BehaviorIdentifier[]
/**
* 组件数据字段监听器,用于监听 properties 和 data 的变化,参见 [数据监听器](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/observer.html)
*
* 最低基础库版本:[`2.6.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
*/
observers: Record<string, (...args: any[]) => any>
/** 组件间关系定义,参见 [组件间关系](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/lifetimes.html) */
relations: {
[componentName: string]: RelationOption
}
/** 组件接受的外部样式类,参见 [外部样式类](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html) */
externalClasses?: string[]
/** 组件所在页面的生命周期声明对象,参见 [组件生命周期](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/lifetimes.html)
*
* 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
pageLifetimes?: Partial<PageLifetimes>
/** 一些选项(文档中介绍相关特性时会涉及具体的选项设置,这里暂不列举) */
options: ComponentOptions
/** 定义段过滤器,用于自定义组件扩展,参见 [自定义组件扩展](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/extend.html)
*
* 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
definitionFilter?: DefinitionFilter
/**
* 组件自定义导出,当使用 `behavior: wx://component-export` 时,这个定义段可以用于指定组件被 selectComponent 调用时的返回值,参见 [组件间通信与事件](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/events.html)
* 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
export: () => IAnyObject
}
interface KeyFrame {
/** 关键帧的偏移,范围[0-1] */
offset?: number
/** 动画缓动函数 */
ease?: string
/** 基点位置,即 CSS transform-origin */
transformOrigin?: string
/** 背景颜色,即 CSS background-color */
backgroundColor?: string
/** 底边位置,即 CSS bottom */
bottom?: number | string
/** 高度,即 CSS height */
height?: number | string
/** 左边位置,即 CSS left */
left?: number | string
/** 宽度,即 CSS width */
width?: number | string
/** 不透明度,即 CSS opacity */
opacity?: number | string
/** 右边位置,即 CSS right */
right?: number | string
/** 顶边位置,即 CSS top */
top?: number | string
/** 变换矩阵,即 CSS transform matrix */
matrix?: number[]
/** 三维变换矩阵,即 CSS transform matrix3d */
matrix3d?: number[]
/** 旋转,即 CSS transform rotate */
rotate?: number
/** 三维旋转,即 CSS transform rotate3d */
rotate3d?: number[]
/** X 方向旋转,即 CSS transform rotateX */
rotateX?: number
/** Y 方向旋转,即 CSS transform rotateY */
rotateY?: number
/** Z 方向旋转,即 CSS transform rotateZ */
rotateZ?: number
/** 缩放,即 CSS transform scale */
scale?: number[]
/** 三维缩放,即 CSS transform scale3d */
scale3d?: number[]
/** X 方向缩放,即 CSS transform scaleX */
scaleX?: number
/** Y 方向缩放,即 CSS transform scaleY */
scaleY?: number
/** Z 方向缩放,即 CSS transform scaleZ */
scaleZ?: number
/** 倾斜,即 CSS transform skew */
skew?: number[]
/** X 方向倾斜,即 CSS transform skewX */
skewX?: number
/** Y 方向倾斜,即 CSS transform skewY */
skewY?: number
/** 位移,即 CSS transform translate */
translate?: Array<number | string>
/** 三维位移,即 CSS transform translate3d */
translate3d?: Array<number | string>
/** X 方向位移,即 CSS transform translateX */
translateX?: number | string
/** Y 方向位移,即 CSS transform translateY */
translateY?: number | string
/** Z 方向位移,即 CSS transform translateZ */
translateZ?: number | string
}
interface ClearAnimationOptions {
/** 基点位置,即 CSS transform-origin */
transformOrigin?: boolean
/** 背景颜色,即 CSS background-color */
backgroundColor?: boolean
/** 底边位置,即 CSS bottom */
bottom?: boolean
/** 高度,即 CSS height */
height?: boolean
/** 左边位置,即 CSS left */
left?: boolean
/** 宽度,即 CSS width */
width?: boolean
/** 不透明度,即 CSS opacity */
opacity?: boolean
/** 右边位置,即 CSS right */
right?: boolean
/** 顶边位置,即 CSS top */
top?: boolean
/** 变换矩阵,即 CSS transform matrix */
matrix?: boolean
/** 三维变换矩阵,即 CSS transform matrix3d */
matrix3d?: boolean
/** 旋转,即 CSS transform rotate */
rotate?: boolean
/** 三维旋转,即 CSS transform rotate3d */
rotate3d?: boolean
/** X 方向旋转,即 CSS transform rotateX */
rotateX?: boolean
/** Y 方向旋转,即 CSS transform rotateY */
rotateY?: boolean
/** Z 方向旋转,即 CSS transform rotateZ */
rotateZ?: boolean
/** 缩放,即 CSS transform scale */
scale?: boolean
/** 三维缩放,即 CSS transform scale3d */
scale3d?: boolean
/** X 方向缩放,即 CSS transform scaleX */
scaleX?: boolean
/** Y 方向缩放,即 CSS transform scaleY */
scaleY?: boolean
/** Z 方向缩放,即 CSS transform scaleZ */
scaleZ?: boolean
/** 倾斜,即 CSS transform skew */
skew?: boolean
/** X 方向倾斜,即 CSS transform skewX */
skewX?: boolean
/** Y 方向倾斜,即 CSS transform skewY */
skewY?: boolean
/** 位移,即 CSS transform translate */
translate?: boolean
/** 三维位移,即 CSS transform translate3d */
translate3d?: boolean
/** X 方向位移,即 CSS transform translateX */
translateX?: boolean
/** Y 方向位移,即 CSS transform translateY */
translateY?: boolean
/** Z 方向位移,即 CSS transform translateZ */
translateZ?: boolean
}
interface ScrollTimelineKeyframe {
composite?: 'replace' | 'add' | 'accumulate' | 'auto'
easing?: string
offset?: number | null
[property: string]: string | number | null | undefined
}
interface ScrollTimelineOption {
/** 指定滚动元素的选择器(只支持 scroll-view),该元素滚动时会驱动动画的进度 */
scrollSource: string
/** 指定滚动的方向。有效值为 horizontal 或 vertical */
orientation?: string
/** 指定开始驱动动画进度的滚动偏移量,单位 px */
startScrollOffset: number
/** 指定停止驱动动画进度的滚动偏移量,单位 px */
endScrollOffset: number
/** 起始和结束的滚动范围映射的时间长度,该时间可用于与关键帧动画里的时间 (duration) 相匹配,单位 ms */
timeRange: number
}
interface SetUpdatePerformanceListenerOption<WithDataPath> {
/** 是否返回变更的 data 字段信息 */
withDataPaths?: WithDataPath
}
interface UpdatePerformanceListener<WithDataPath> {
(res: UpdatePerformance<WithDataPath>): void
}
interface UpdatePerformance<WithDataPath> {
/** 此次更新过程的 ID */
updateProcessId: number
/** 对于子更新,返回它所属的更新过程 ID */
parentUpdateProcessId?: number
/** 是否是被合并更新,如果是,则 updateProcessId 表示被合并到的更新过程 ID */
isMergedUpdate: boolean
/** 此次更新的 data 字段信息,只有 withDataPaths 设为 true 时才会返回 */
dataPaths: WithDataPath extends true ? string[] : undefined
/** 此次更新进入等待队列时的时间戳 */
pendingStartTimestamp: number
/** 更新运算开始时的时间戳 */
updateStartTimestamp: number
/** 更新运算结束时的时间戳 */
updateEndTimestamp: number
}
type PassiveConfig =
| {
/** 是否设置 touchmove 事件为 passive,默认为 `false` */
touchmove?: boolean
/** 是否设置 touchstart 事件为 passive,默认为 `false` */
touchstart?: boolean
/** 是否设置 wheel 事件为 passive,默认为 `false` */
wheel?: boolean
}
| boolean
}
/** Component构造器可用于定义组件,调用Component构造器时可以指定组件的属性、数据、方法等。
*
* * 使用 `this.data` 可以获取内部数据和属性值,但不要直接修改它们,应使用 `setData` 修改。
* * 生命周期函数无法在组件方法中通过 `this` 访问到。
* * 属性名应避免以 data 开头,即不要命名成 `dataXyz` 这样的形式,因为在 WXML 中, `data-xyz=""` 会被作为节点 dataset 来处理,而不是组件属性。
* * 在一个组件的定义和使用时,组件的属性名和 data 字段相互间都不能冲突(尽管它们位于不同的定义段中)。
* * 从基础库 `2.0.9` 开始,对象类型的属性和 data 字段中可以包含函数类型的子字段,即可以通过对象类型的属性字段来传递函数。低于这一版本的基础库不支持这一特性。
* * `bug` : 对于 type 为 Object 或 Array 的属性,如果通过该组件自身的 `this.setData` 来改变属性值的一个子字段,则依旧会触发属性 observer ,且 observer 接收到的 `newVal` 是变化的那个子字段的值, `oldVal` 为空, `changedPath` 包含子字段的字段名相关信息。
*/
declare let Component: WechatMiniprogram.Component.Constructor
/*! *****************************************************************************
Copyright (c) 2023 Tencent, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***************************************************************************** */
declare namespace WechatMiniprogram {
interface Target<DataSet extends IAnyObject = IAnyObject> {
/** 事件组件的 id */
id: string
/** 当前组件的类型 */
tagName?: string
/** 事件组件上由 `data-` 开头的自定义属性组成的集合 */
dataset: DataSet
/** 距离页面顶部的偏移量 */
offsetTop: number
/** 距离页面左边的偏移量 */
offsetLeft: number
}
/** 基础事件参数 */
interface BaseEvent<
Mark extends IAnyObject = IAnyObject,
CurrentTargetDataset extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = CurrentTargetDataset
> {
/** 事件类型 */
type: string
/** 页面打开到触发事件所经过的毫秒数 */
timeStamp: number
/** 事件冒泡路径上所有由 `mark:` 开头的自定义属性组成的集合 */
mark?: Mark
/** 触发事件的源组件 */
target: Target<TargetDataset>
/** 事件绑定的当前组件 */
currentTarget: Target<CurrentTargetDataset>
}
/** 自定义事件 */
interface CustomEvent<
Detail extends IAnyObject = IAnyObject,
Mark extends IAnyObject = IAnyObject,
CurrentTargetDataset extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = CurrentTargetDataset
> extends BaseEvent<Mark, CurrentTargetDataset, TargetDataset> {
/** 额外的信息 */
detail: Detail
}
/** Touch 对象 */
interface TouchDetail {
/** 距离页面可显示区域 (屏幕除去导航条) 左上角距离,横向为 X 轴 */
clientX: number
/** 距离页面可显示区域 (屏幕除去导航条) 左上角距离,纵向为 Y 轴 */
clientY: number
/** 触摸点的标识符 */
identifier: number
/** 距离文档左上角的距离,文档的左上角为原点,横向为 X 轴 */
pageX: number
/** 距离文档左上角的距离,文档的左上角为原点,纵向为 Y 轴 */
pageY: number
}
/** canvas Touch 对象 */
interface TouchCanvasDetail {
/** 触摸点的标识符 */
identifier: number
/** 距离 Canvas 左上角的距离,Canvas 的左上角为原点 ,横向为X轴 */
x: number
/** 距离 Canvas 左上角的距离,Canvas 的左上角为原点 纵向为Y轴 */
y: number
}
/** 触摸事件 */
interface Touch<
Detail extends IAnyObject = IAnyObject,
T extends TouchDetail | TouchCanvasDetail = TouchDetail,
Mark extends IAnyObject = IAnyObject,
CurrentTargetDataset extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = CurrentTargetDataset
> extends CustomEvent<Detail, Mark, CurrentTargetDataset, TargetDataset> {
/** 触摸事件,当前停留在屏幕中的触摸点信息的数组 */
touches: T[]
/** 触摸事件,当前变化的触摸点信息的数组 */
changedTouches: T[]
}
/** 触摸事件响应 */
type TouchEvent<
Detail extends IAnyObject = IAnyObject,
Mark extends IAnyObject = IAnyObject,
CurrentTargetDataset extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = CurrentTargetDataset
> = Touch<Detail, TouchDetail, Mark, CurrentTargetDataset, TargetDataset>
/** canvas 触摸事件响应 */
interface TouchCanvas<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> extends Touch<never, TouchCanvasDetail, Mark, never, TargetDataset> {
// canvas 中的触摸事件不可冒泡,所以没有 currentTarget。
currentTarget: never
}
/**
* 图片加载成功时触发
*
* 最低基础库: 2.1.0
*/
type CoverImageLoad<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
/** 图片宽度 */
width: number
/** 图片高度 */
height: number
},
Mark,
TargetDataset
>
/**
* 图片加载失败时触发
*
* 最低基础库: 2.1.0
*/
type CoverImageError = CustomEvent<GeneralCallbackResult>
/**
* 拖动过程中触发的事件,event.detail = {x, y, source}
*
* 最低基础库: 1.9.90
*/
type MovableViewChange<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
x: number
y: number
/**
* 产生移动的原因
*
* - `touch` 拖动
* - `touch-out-of-bounds` 超出移动范围
* - `out-of-bounds` 超出移动范围后的回弹
* - `friction` 惯性
* - `空字符串` setData
*/
source:
| 'touch'
| 'touch-out-of-bounds'
| 'out-of-bounds'
| 'friction'
| ''
},
Mark,
TargetDataset
>
/**
* 缩放过程中触发的事件
*
* event.detail = {x, y, scale}
*
* x 和 y 字段在 2.1.0 之后支持
*
* 最低基础库: 1.9.90
*/
type MovableViewScale<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
/** 最低基础库: 2.1.0 */
x: number
/** 最低基础库: 2.1.0 */
y: number
scale: number
},
Mark,
TargetDataset
>
/**
* 滑动开始事件 (同时开启 enhanced 属性后生效)
*
* detail { scrollTop, scrollLeft }
*
* 最低基础库: 2.12.0
*/
type ScrollViewDragStart<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
scrollTop: number
scrollLeft: number
},
Mark,
TargetDataset
>
/**
* 滑动事件 (同时开启 enhanced 属性后生效)
*
* detail { scrollTop, scrollLeft }
*
* 最低基础库: 2.12.0
*/
type ScrollViewDragging<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
scrollTop: number
scrollLeft: number
},
Mark,
TargetDataset
>
/**
* 滑动结束事件 (同时开启 enhanced 属性后生效)
*
* detail { scrollTop, scrollLeft }
*
* 最低基础库: 2.12.0
*/
type ScrollViewDragEnd<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
scrollTop: number
scrollLeft: number
},
Mark,
TargetDataset
>
/** 滚动到顶部/左边时触发 */
type ScrollViewScrollToUpper<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
direction: 'top' | 'left'
},
Mark,
TargetDataset
>
/** 滚动到底部/右边时触发 */
type ScrollViewScrollToLower<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
direction: 'bottom' | 'right'
},
Mark,
TargetDataset
>
/**
* 滚动时触发
*
* event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}
*/
type ScrollViewScroll<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
scrollLeft: number
scrollTop: number
scrollHeight: number
scrollWidth: number
deltaX: number
deltaY: number
},
Mark,
TargetDataset
>
type ScrollViewRefresherPulling<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<never, Mark, TargetDataset>
type ScrollViewRefresherRefresh<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<never, Mark, TargetDataset>
type ScrollViewRefresherRestore<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<never, Mark, TargetDataset>
type ScrollViewRefresherAbort<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<never, Mark, TargetDataset>
/**
* current 改变时会触发 change 事件
*
* event.detail = {current, source}
*
* **Tip**: 如果在 bindchange 的事件回调函数中使用 setData 改变 current 值,则有可能导致 setData 被不停地调用,因而通常情况下请在改变 current 值前检测 source 字段来判断是否是由于用户触摸引起。
*/
type SwiperChange<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
current: number
/**
* 表示导致变更的原因
*
* - `autoplay` 自动播放导致 swiper 变化;
* - `touch` 用户划动引起 swiper 变化;
* - 其它原因将用空字符串表示。
*
* 最低基础库: 1.4.0
*/
source: '' | 'autoplay' | 'touch'
/** 该 swiper-item 的标识符 */
currentItemId: string
},
Mark,
TargetDataset
>
/**
* swiper-item 的位置发生改变时会触发 transition 事件
*
* event.detail = {dx: dx, dy: dy}
*
* 最低基础库: 2.4.3
*/
type SwiperTransition<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
dx: number
dy: number
},
Mark,
TargetDataset
>
/**
* 动画结束时会触发 animationfinish 事件
*
* 最低基础库: 1.9.0
*/
type SwiperAnimationFinish<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = SwiperChange<Mark, TargetDataset>
/**
* progress 动画完成事件
*
* 最低基础库 2.4.1
*/
type ProgressActiveEnd<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
curPercent: number
},
Mark,
TargetDataset
>
/**
* 用户点击该按钮时,会返回获取到的用户信息,回调的 detail 数据与 `wx. getUserInfo` 返回的一致,`open-type="getUserInfo"` 时有效
*
* 最低基础库: 1.3.0
*/
type ButtonGetUserInfo = CustomEvent<
GeneralCallbackResult & GetUserInfoSuccessCallbackResult
>
/**
* 客服消息回调,`open-type="contact"` 时有效
*
* 最低基础库: 1.5.0
*/
type ButtonContact = CustomEvent<GeneralCallbackResult>
/**
* 获取用户手机号回调,`open-type=getPhoneNumber` 时有效
*
* 最低基础库: 1.2.0
*/
type ButtonGetPhoneNumber = CustomEvent<
GeneralCallbackResult &
Partial<GetWeRunDataSuccessCallbackResult> & {
code: string
}
>
/**
* 当使用开放能力时,发生错误的回调,`open-type=launchApp` 时有效
*
* 最低基础库: 1.9.5
*/
type ButtonError = CustomEvent<GeneralCallbackResult>
/**
* 在打开授权设置页后回调,`open-type=openSetting` 时有效
*
* 最低基础库: 2.0.7
*/
type ButtonOpenSetting = CustomEvent<
GeneralCallbackResult & OpenSettingSuccessCallbackResult
>
/**
* 打开 APP 成功的回调,`open-type=launchApp` 时有效
*
* 最低基础库: 2.4.4
*/
type ButtonLaunchApp = CustomEvent<GeneralCallbackResult>
/**
* checkbox-group 中选中项发生改变时触发 change 事件
*
* detail = { value: ['选中的checkbox 的 value 的数组'] }
*/
type CheckboxGroupChange<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
/** 选中的 checkbox 的 value 的数组 */
value: string[]
},
Mark,
TargetDataset
>
/**
* 编辑器初始化完成时触发
*
* 最低基础库: 2.7.0
*/
type EditorReady<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<never, Mark, TargetDataset>
/**
* 编辑器聚焦时触发
*
* event.detail = {html, text, delta}
*
* 最低基础库: 2.7.0
*/
type EditorFocus<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
html: string
text: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delta: any[]
},
Mark,
TargetDataset
>
/**
* 编辑器失去焦点时触发
*
* detail = {html, text, delta}
*
* 最低基础库: 2.7.0
*/
type EditorBlur<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = EditorFocus<Mark, TargetDataset>
/**
* 编辑器内容改变时触发
*
* detail = {html, text, delta}
*
* 最低基础库: 2.7.0
*/
type EditorInput<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = EditorFocus<Mark, TargetDataset>
/**
* 通过 Context 方法改变编辑器内样式时触发,返回选区已设置的样式
*
* 最低基础库: 2.7.0
*/
type EditorStatusChange<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
Partial<{
align: 'left' | 'center' | 'right' | 'justify'
bold: 'strong'
italic: 'em'
underline: true
strike: 'del'
lineHeight: string
letterSpacing: string
marginTop: string
marginBottom: string
fontFamily: string
fontSize: string
color: string
backgroundColor: string
list: 'checked' | 'unchecked' | 'ordered' | 'bullet'
indent: number
header: number
script: 'sub' | 'super'
direction: 'rtl'
}>,
Mark,
TargetDataset
>
/**
* 携带 form 中的数据触发 submit 事件
*
* event.detail = {value : {'name': 'value'} , formId: ''}
*/
type FormSubmit<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
formId?: unknown
target: Target
/** 表单中的数据,需要在表单组件中加上 name 来作为 key。 */
value: IAnyObject
},
Mark,
TargetDataset
>
/** 表单重置时会触发 reset 事件 */
type FormReset<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
target: Target
},
Mark,
TargetDataset
>
/** 键盘输入时触发
*
* event.detail = {value, cursor, keyCode}
*
* 处理函数可以直接 return 一个字符串,将替换输入框的内容。
*/
type Input<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
/** 输入框内容 */
value: string
/** 光标位置 */
cursor: number
/** keyCode 为键值 (目前工具还不支持返回keyCode参数) `2.1.0` 起支持 */
keyCode?: number
},
Mark,
TargetDataset
>
/**
* 输入框聚焦时触发
*
* event.detail = { value, height }
*/
type InputFocus<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
/** 输入框内容 */
value: string
/** 键盘高度, 在基础库 `1.9.90` 起支持 */
height: number
},
Mark,
TargetDataset
>
/**
* 输入框失去焦点时触发
*
* event.detail = {value: value}
*/
type InputBlur<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
/** 输入框内容 */
value: string
},
Mark,
TargetDataset
>
/**
* 点击完成按钮时触发
*
* event.detail = {value: value}
*/
type InputConfirm<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
/** 输入框内容 */
value: string
},
Mark,
TargetDataset
>
/**
* 键盘高度发生变化的时候触发此事件
*
* event.detail = {height: height, duration: duration}
*
* **tip**: 键盘高度发生变化,keyboardheightchange 事件可能会多次触发,开发者对于相同的 height 值应该忽略掉
*
* 最低基础库: `2.7.0`
*/
type InputKeyboardHeightChange<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
/** 键盘高度 */
height: number
duration: number
},
Mark,
TargetDataset
>
/**
* 取消选择时触发
*
* 最低基础库: 1.9.90
*/
type PickerCancel<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<never, Mark, TargetDataset>
/**
* value 改变时触发 change 事件
*
* event.detail = {value}
*
* 当 mode = region 时 (最低基础库: 1.4.0)
*
* value 改变时触发 change 事件,event.detail = {value, code, postcode},其中字段 code 是统计用区划代码,postcode 是邮政编码
*/
type PickerChange<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
/**
* 当 mode = selector 时, 返回当前选择的 value
*
* 当 mode = multiSelector 时, 返回一个索引数组
*
* 当 mode = time | date 时, 返回 `"12:01"` | `"2016-09-01"`
*
* 当 mode = region 时, 返回 `["广东省", "广州市", "海珠区"]`
*/
value: string | number[] | [string, string, string]
/** 统计用区划代码 当 mode = region 时有效 (最低基础库: 1.4.0) */
code: [string, string, string]
/** 邮政编码 当 mode = region 时有效 (最低基础库: 1.4.0) */
postcode: string
},
Mark,
TargetDataset
>
/** 列改变时触发 当 `mode = multiSelector` 时有效 */
type PickerColumnChange<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
/** 修改的列 */
column: number
value: number
},
Mark,
TargetDataset
>
/**
* 滚动选择时触发 change 事件
*
* event.detail = {value}
*/
type PickerViewChange<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
/** value 为数组,表示 picker-view 内的 picker-view-column 当前选择的是第几项 (下标从 0 开始) */
value: number[]
},
Mark,
TargetDataset
>
/**
* 当滚动选择开始时候触发事件
*
* 最低基础库: 2.3.1
*/
type PickerViewPickStart<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<never, Mark, TargetDataset>
/**
* 当滚动选择结束时候触发事件
*
* 最低基础库: 2.3.1
*/
type PickerViewPickEnd<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<never, Mark, TargetDataset>
/** radio-group 切换事件 */
type RadioGroupChange<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
/** radio-group 中选中项的 value */
{
value: string
},
Mark,
TargetDataset
>
/**
* 完成一次拖动后触发的事件
*
* event.detail = {value}
*/
type SliderChange<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
/** slider 的数值 0 - 100 */
value: number
},
Mark,
TargetDataset
>
/**
* 拖动过程中触发的事件
*
* event.detail = {value}
*
* 最低基础库: 1.7.0
*/
type SliderChanging<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = SliderChange<Mark, TargetDataset>
/**
* checked 改变时触发 change 事件
*
* event.detail={ value}
*/
type SwitchChange<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
value: boolean
},
Mark,
TargetDataset
>
/**
* 输入框聚焦时触发
*
* event.detail = { value, height },height 为键盘高度
*
* 在基础库 1.9.90 起支持
*/
type TextareaFocus<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = InputFocus<Mark, TargetDataset>
/**
* 输入框失去焦点时触发
*
* event.detail = {value, cursor}
*
* **tip**: textarea 的 blur 事件会晚于页面上的 tap 事件,如果需要在 button 的点击事件获取 textarea,可以使用 form 的 bindsubmit。
*/
type TextareaBlur<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = InputBlur<Mark, TargetDataset>
/**
* 输入框行数变化时调用
*
* event.detail = {height: 0, heightRpx: 0, lineCount: 0}
*/
type TextareaLineChange<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = CustomEvent<
{
/** 输入框高度(px) */
height: number
/** 输入框高度(rpx) */
heightRpx: number
/** 行数 */
lineCount: number
/** 行高 */
lineHeight: number
},
Mark,
TargetDataset
>
/**
* 当键盘输入时,触发 input 事件
*
* event.detail = {value, cursor, keyCode}
*
* keyCode 为键值,目前工具还不支持返回 keyCode 参数。
*
* **tip**: 不建议在多行文本上对用户的输入进行修改,所以 **bindinput 处理函数的返回值并不会反映到 textarea 上**
*/
type TextareaInput<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = Input<Mark, TargetDataset>
/**
* 点击完成时, 触发 confirm 事件
*
* event.detail = {value: value}
*/
type TextareaConfirm<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = InputConfirm<Mark, TargetDataset>
/**
* 键盘高度发生变化的时候触发此事件
*
* event.detail = {height: height, duration: duration}
*
* **tip**: 键盘高度发生变化,keyboardheightchange事件可能会多次触发,开发者对于相同的height值应该忽略掉
*
* 最低基础库: 2.7.0
*/
type TextareaKeyboardHeightChange<
Mark extends IAnyObject = IAnyObject,
TargetDataset extends IAnyObject = IAnyObject
> = InputKeyboardHeightChange<Mark, TargetDataset>
/**
* 功能页返回,且操作成功时触发, detail 格式与具体功能页相关
*
* 最低基础库: 2.1.0
*/
type FunctionalNavigatorSuccess<Detail extends IAnyObject = IAnyObject> =
CustomEvent<Detail, never, never>
/**
* 功能页返回,且操作失败时触发, detail 格式与具体功能页相关
*
* 最低基础库: 2.1.0
*/
type FunctionalNavigatorFail<Detail extends IAnyObject = IAnyObject> =
CustomEvent<Detail, never, never>
/**
* 当 `target="miniProgram"` 时有效,跳转小程序成功
*
* 最低基础库: 2.0.7
*/
type NavigatorSuccess = CustomEvent
/**
* 当 `target="miniProgram"` 时有效,跳转小程序失败
*
* `tips`: 需要用户确认跳转 从 2.3.0 版本开始,在跳转至其他小程序前,将统一增加弹窗,询问是否跳转,用户确认后才可以跳转其他小程序。如果用户点击取消,则回调 fail cancel。
*
* 最低基础库: 2.0.7
*/
type NavigatorFail = CustomEvent
/**
* 当 `target="miniProgram"` 时有效,跳转小程序完成
*
* 最低基础库: 2.0.7
*/
type NavigatorComplete = CustomEvent
/**
* 当发生错误时触发 error 事件
*
* detail = {errMsg:MediaError.code}
*/
type AudioError = CustomEvent<{
/**
* MediaError.code
*
* - 1 获取资源被用户禁止
* - 2 网络错误
* - 3 解码错误
* - 4 不合适资源
*/
errMsg: 1 | 2 | 3 | 4
}>
/** 当开始/继续播放时触发play事件 */
type AudioPlay = CustomEvent
/** 当暂停播放时触发 pause 事件 */
type AudioPause = CustomEvent
/**
* 当播放进度改变时触发 timeupdate 事件
*
* detail = {currentTime, duration}
*/
type AudioTimeUpdate = CustomEvent<{
currentTime: number
duration: number
}>
/** 当播放到末尾时触发 ended 事件 */
type AudioEnded = CustomEvent
/** 摄像头在非正常终止时触发,如退出后台等情况 */
type CameraStop = CustomEvent
/** 用户不允许使用摄像头时触发 */
type CameraError = CustomEvent
/**
* 相机初始化完成时触发
*
* 最低基础库: 2.7.0
*/
type CameraInitDone = CustomEvent
/**
* 在扫码识别成功时触发,仅在 mode="scanCode" 时生效
*
* 最低基础库: 2.1.0
*/
type CameraScanCode = CustomEvent
/** 当错误发生时触发,event.detail = {errMsg} */
type ImageError = CoverImageError
/** 当图片载入完毕时触发,event.detail = {height, width} */
type ImageLoad = CoverImageLoad
/**
* 播放状态变化事件,detail = {code}
*
* 最低基础库 1.7.0
*/
type LivePlayerStateChange = CustomEvent<{
/**
* 状态码
*
* - `2001` 已经连接服务器
* - `2002` 已经连接服务器,开始拉流
* - `2003` 网络接收到首个视频数据包(IDR)
* - `2004` 视频播放开始
* - `2005` 视频播放进度
* - `2006` 视频播放结束
* - `2007` 视频播放Loading
* - `2008` 解码器启动
* - `2009` 视频分辨率改变
* - `-2301` 网络断连,且经多次重连抢救无效,更多重试请自行重启播放
* - `-2302` 获取加速拉流地址失败
* - `2101` 当前视频帧解码失败
* - `2102` 当前音频帧解码失败
* - `2103` 网络断连, 已启动自动重连
* - `2104` 网络来包不稳: 可能是下行带宽不足,或由于主播端出流不均匀
* - `2105` 当前视频播放出现卡顿
* - `2106` 硬解启动失败,采用软解
* - `2107` 当前视频帧不连续,可能丢帧
* - `2108` 当前流硬解第一个I帧失败,SDK自动切软解
* - `3001` RTMP -DNS解析失败
* - `3002` RTMP服务器连接失败
* - `3003` RTMP服务器握手失败
* - `3005` RTMP 读/写失败
*/
code: number
}>
/**
* 全屏变化事件,detail = {direction, fullScreen}
*
* 最低基础库 1.7.0
*/
type LivePlayerFullScreenChange = CustomEvent<{
direction: 'vertical' | 'horizontal'
fullScreen: boolean
}>
/**
* 网络状态通知,detail = {info}
*
* 最低基础库 1.9.0
*/
type LivePlayerNetStatus = CustomEvent<{
/**
* 网络状态数据
*
*
* - `videoBitrate` 当前视频编/码器输出的比特率,单位 kbps
* - `audioBitrate` 当前音频编/码器输出的比特率,单位 kbps
* - `videoFPS` 当前视频帧率
* - `videoGOP` 当前视频 GOP,也就是每两个关键帧(I帧)间隔时长,单位 s
* - `netSpeed` 当前的发送/接收速度
* - `netJitter` 网络抖动情况,抖动越大,网络越不稳定
* - `videoWidth` 视频画面的宽度
* - `videoHeight` 视频画面的高度
*/
info:
| 'videoBitrate'
| 'audioBitrate'
| 'videoFPS'
| 'videoGOP'
| 'netSpeed'
| 'netJitter'
| 'videoWidth'
| 'videoHeight'
}>
/**
* 状态变化事件,detail = {code}
*
* 最低基础库: 1.7.0
*/
type LivePusherStateChange = CustomEvent<{
/**
* 状态码
*
* - `1001` 已经连接推流服务器
* - `1002` 已经与服务器握手完毕,开始推流
* - `1003` 打开摄像头成功
* - `1004` 录屏启动成功
* - `1005` 推流动态调整分辨率
* - `1006` 推流动态调整码率
* - `1007` 首帧画面采集完成
* - `1008` 编码器启动
* - `-1301` 打开摄像头失败
* - `-1302` 打开麦克风失败
* - `-1303` 视频编码失败
* - `-1304` 音频编码失败
* - `-1305` 不支持的视频分辨率
* - `-1306` 不支持的音频采样率
* - `-1307` 网络断连,且经多次重连抢救无效,更多重试请自行重启推流
* - `-1308` 开始录屏失败,可能是被用户拒绝
* - `-1309` 录屏失败,不支持的Android系统版本,需要5.0以上的系统
* - `-1310` 录屏被其他应用打断了
* - `-1311` Android Mic打开成功,但是录不到音频数据
* - `-1312` 录屏动态切横竖屏失败
* - `1101` 网络状况不佳: 上行带宽太小,上传数据受阻
* - `1102` 网络断连, 已启动自动重连
* - `1103` 硬编码启动失败,采用软编码
* - `1104` 视频编码失败
* - `1105` 新美颜软编码启动失败,采用老的软编码
* - `1106` 新美颜软编码启动失败,采用老的软编码
* - `3001` RTMP -DNS解析失败
* - `3002` RTMP服务器连接失败
* - `3003` RTMP服务器握手失败
* - `3004` RTMP服务器主动断开,请检查推流地址的合法性或防盗链有效期
* - `3005` RTMP 读/写失败
*/
code: number
}>
/**
* 网络状态通知,detail = {info}
*
* 最低基础库: 1.9.0
*/
type LivePusherNetStatus = CustomEvent<{
/**
* 网络状态数据
*
* -`videoBitrate` 当前视频编/码器输出的比特率,单位 kbps
* -`audioBitrate` 当前音频编/码器输出的比特率,单位 kbps
* -`videoFPS` 当前视频帧率
* -`videoGOP` 当前视频 GOP,也就是每两个关键帧(I帧)间隔时长,单位 s
* -`netSpeed` 当前的发送/接收速度
* -`netJitter` 网络抖动情况,抖动越大,网络越不稳定
* -`videoWidth` 视频画面的宽度
* -`videoHeight` 视频画面的高度
*/
info:
| 'videoBitrate'
| 'audioBitrate'
| 'videoFPS'
| 'videoGOP'
| 'netSpeed'
| 'netJitter'
| 'videoWidth'
| 'videoHeight'
}>
/**
* 渲染错误事件,detail = {errMsg, errCode}
*
* `tip`: 开发者工具上暂不支持 live-pusher
*
* 最低基础库: 1.7.4
*/
type LivePusherError = CustomEvent<{
errMsg: string
/**
* 错误码
*
* - `10001` 用户禁止使用摄像头
* - `10002` 用户禁止使用录音
* - `10003` 背景音资源 (BGM) 加载失败
* - `10004` 等待画面资源 (waiting-image) 加载失败
*/
errCode: number
}>
/**
* 背景音开始播放时触发
*
* 最低基础库: 2.4.0
*/
type LivePusherBgmStart = CustomEvent
/**
* 背景音进度变化时触发,detail = {progress, duration}
*
* 最低基础库: 2.4.0
*/
type LivePusherBgmProgress = CustomEvent<{
progress: number
duration: number
}>
/**
* 背景音播放完成时触发
*
* 最低基础库: 2.4.0
*/
type LivePusherBgmComplete = CustomEvent
/** 当开始/继续播放时触发play事件 */
type VideoPlay = CustomEvent
/** 当暂停播放时触发 pause 事件 */
type VideoPause = CustomEvent
/** 当播放到末尾时触发 ended 事件 */
type VideoEnded = CustomEvent
/** 播放进度变化时触发,event.detail = {currentTime, duration} 。触发频率 250ms 一次 */
type VideoTimeUpdate = CustomEvent<{
currentTime: number
duration: number
}>
/**
* 视频进入和退出全屏时触发,event.detail = {fullScreen, direction}
*
* 最低基础库: 1.4.0
*/
type VideoFullScreenChange = CustomEvent<{
fullScreen: boolean
direction: 'vertical' | 'horizontal'
}>
/**
* 视频出现缓冲时触发
*
* 最低基础库: 1.7.0
*/
type VideoWaiting = CustomEvent
/**
* 视频播放出错时触发
*
* 最低基础库: 1.7.0
*/
type VideoError = CustomEvent
/**
* 加载进度变化时触发,只支持一段加载。
*
* 最低基础库: 2.4.0
*/
type VideoPregress = CustomEvent<{
/** 百分比 */
buffered: number
}>
/**
* 加载进度变化时触发,只支持一段加载。
*
* 最低基础库: 2.4.0
*/
type VoipRoomError = CustomEvent
/**
* 点击地图时触发
*
* 2.9.0 起返回经纬度信息
*/
type MapTap = CustomEvent<{
/** 经度,最低基础库 2.9.0 */
longitude: number
/** 纬度,最低基础库 2.9.0 */
latitude: number
}>
/**
* 点击标记点时触发
*
* e.detail = {markerId}
*/
type MarkerTap = CustomEvent<{
/** 标记点 ID */
markerId: number
}>
/**
* 点击 label 时触发
*
* e.detail = {markerId}
*
* 最低基础库: 2.9.0
*/
type LabelTap = MarkerTap
/**
* 点击控件时触发
*
* e.detail = {controlId}
*/
type ControlTap = CustomEvent<{
/** 控件 ID */
controlId: number
}>
/**
* 点击 label 时触发
*
* e.detail = {markerId}
*
* 最低基础库: 1.2.0
*/
type CalloutTap = MarkerTap
/**
* 在地图渲染更新完成时触发
*
* 最低基础库: 1.6.0
*/
type MapUpdated = CustomEvent
/**
* 在地图渲染更新完成时触发
*
* 最低基础库: 1.6.0
*/
type RegionChange = CustomEvent<{
/** 旋转程度,最低基础库 2.3.0 */
rotate: number
/** 缩放程度,最低基础库 2.3.0 */
skew: number
}> &
(
| {
/**
* 视野变化开始、结束时触发
*
* 视野变化开始为 `begin`
*/
type: 'begin'
/**
* 导致视野变化的原因
*
* - gesture: 用户手势
* - update: 调用接口导致
*/
causedBy: 'gesture' | 'update'
}
| {
/**
* 视野变化结束时触发
*
* 视野变化结束为 `end`
*/
type: 'end'
/**
* 导致视野变化的原因
*
* - drag: 拖动地图导致
* - scale: 缩放导致
* - update: 调用接口导致
*/
causedBy: 'drag' | 'scale' | 'update'
}
)
/**
* 广告加载成功的回调
*
* 最低基础库: 2.2.1
*/
type AdLoad = CustomEvent
/**
* 广告加载失败的回调,event.detail = {errCode: 1002}
*
* `tip`: 监听到error回调后,开发者可以针对性的处理,比如隐藏广告组件的父容器,以保证用户体验,但不要移除广告组件,否则将无法收到bindload的回调。
*
* 最低基础库: 2.2.1
*/
type AdError = CustomEvent<{
/**
* 错误码
*
* - `1000` 后端错误调用失败 该项错误不是开发者的异常情况 一般情况下忽略一段时间即可恢复。
* - `1001` 参数错误 使用方法错误 可以前往developers.weixin.qq.com 确认具体教程 (小程序和小游戏分别有各自的教程,可以在顶部选项中,“设计”一栏的右侧进行切换)。
* - `1002` 广告单元无效 可能是拼写错误、或者误用了其他APP的广告ID 请重新前往mp.weixin.qq.com确认广告位ID。
* - `1003` 内部错误 该项错误不是开发者的异常情况 一般情况下忽略一段时间即可恢复。
* - `1004` 无适合的广告 广告不是每一次都会出现,这次没有出现可能是由于该用户不适合浏览广告 属于正常情况,且开发者需要针对这种情况做形态上的兼容。
* - `1005` 广告组件审核中 你的广告正在被审核,无法展现广告 请前往mp.weixin.qq.com确认审核状态,且开发者需要针对这种情况做形态上的兼容。
* - `1006` 广告组件被驳回 你的广告审核失败,无法展现广告 请前往mp.weixin.qq.com确认审核状态,且开发者需要针对这种情况做形态上的兼容。
* - `1007` 广告组件被驳回 你的广告能力已经被封禁,封禁期间无法展现广告 请前往mp.weixin.qq.com确认小程序广告封禁状态。
* - `1008` 广告单元已关闭 该广告位的广告能力已经被关闭 请前往mp.weixin.qq.com重新打开对应广告位的展现。
*/
errCode: number
}>
/**
* 广告关闭的回调
*
* 最低基础库: 2.6.5
*/
type AdClose = CustomEvent
/**
* 网页向小程序 postMessage 时,会在特定时机 (小程序后退、组件销毁、分享) 触发并收到消息。e.detail = { data }
*
* 最低基础库: 1.6.4
*/
type WebviewMessage = CustomEvent<{
/** 多次 postMessage 的参数组成的数组 */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: any[]
}>
/**
* 网页加载成功时候触发此事件。e.detail = { src }
*
* 最低基础库: 1.6.4
*/
type WebviewLoad = CustomEvent<{
src: string
}>
/**
* 网页加载失败的时候触发此事件。e.detail = { src }
*
* 最低基础库: 1.6.4
*/
type WebviewError = CustomEvent<{
src: string
}>
}
/*! *****************************************************************************
Copyright (c) 2023 Tencent, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***************************************************************************** */
declare namespace WechatMiniprogram.Page {
type Instance<
TData extends DataOption,
TCustom extends CustomOption
> = OptionalInterface<ILifetime> &
InstanceProperties &
InstanceMethods<TData> &
Data<TData> &
TCustom
type Options<
TData extends DataOption,
TCustom extends CustomOption
> = (TCustom &
Partial<Data<TData>> &
Partial<ILifetime> & {
options?: Component.ComponentOptions
}) &
ThisType<Instance<TData, TCustom>>
type TrivialInstance = Instance<IAnyObject, IAnyObject>
interface Constructor {
<TData extends DataOption, TCustom extends CustomOption>(
options: Options<TData, TCustom>
): void
}
interface ILifetime {
/** 生命周期回调—监听页面加载
*
* 页面加载时触发。一个页面只会调用一次,可以在 onLoad 的参数中获取打开当前页面路径中的参数。
*/
onLoad(
/** 打开当前页面路径中的参数 */
query: Record<string, string | undefined>
): void | Promise<void>
/** 生命周期回调—监听页面显示
*
* 页面显示/切入前台时触发。
*/
onShow(): void | Promise<void>
/** 生命周期回调—监听页面初次渲染完成
*
* 页面初次渲染完成时触发。一个页面只会调用一次,代表页面已经准备妥当,可以和视图层进行交互。
*
* 注意:对界面内容进行设置的 API 如`wx.setNavigationBarTitle`,请在`onReady`之后进行。
*/
onReady(): void | Promise<void>
/** 生命周期回调—监听页面隐藏
*
* 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。
*/
onHide(): void | Promise<void>
/** 生命周期回调—监听页面卸载
*
* 页面卸载时触发。如`redirectTo`或`navigateBack`到其他页面时。
*/
onUnload(): void | Promise<void>
/** 监听用户下拉动作
*
* 监听用户下拉刷新事件。
* - 需要在`app.json`的`window`选项中或页面配置中开启`enablePullDownRefresh`。
* - 可以通过`wx.startPullDownRefresh`触发下拉刷新,调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
* - 当处理完数据刷新后,`wx.stopPullDownRefresh`可以停止当前页面的下拉刷新。
*/
onPullDownRefresh(): void | Promise<void>
/** 页面上拉触底事件的处理函数
*
* 监听用户上拉触底事件。
* - 可以在`app.json`的`window`选项中或页面配置中设置触发距离`onReachBottomDistance`。
* - 在触发距离内滑动期间,本事件只会被触发一次。
*/
onReachBottom(): void | Promise<void>
/** 用户点击右上角转发
*
* 监听用户点击页面内转发按钮(`<button>` 组件 `open-type="share"`)或右上角菜单“转发”按钮的行为,并自定义转发内容。
*
* **注意:只有定义了此事件处理函数,右上角菜单才会显示“转发”按钮**
*
* 此事件需要 return 一个 Object,用于自定义转发内容
*/
onShareAppMessage(
/** 分享发起来源参数 */
options: IShareAppMessageOption
):
| ICustomShareContent
| IAsyncCustomShareContent
| Promise<ICustomShareContent>
| void
| Promise<void>
/**
* 监听右上角菜单“分享到朋友圈”按钮的行为,并自定义分享内容
*
* 本接口为 Beta 版本,暂只在 Android 平台支持,详见 [分享到朋友圈 (Beta)](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html)
*
* 基础库 2.11.3 开始支持,低版本需做兼容处理。
*/
onShareTimeline(): ICustomTimelineContent | void
/** 页面滚动触发事件的处理函数
*
* 监听用户滑动页面事件。
*/
onPageScroll(
/** 页面滚动参数 */
options: IPageScrollOption
): void | Promise<void>
/** 当前是 tab 页时,点击 tab 时触发,最低基础库: `1.9.0` */
onTabItemTap(
/** tab 点击参数 */
options: ITabItemTapOption
): void | Promise<void>
/** 窗口尺寸改变时触发,最低基础库:`2.4.0` */
onResize(
/** 窗口尺寸参数 */
options: IResizeOption
): void | Promise<void>
/**
* 监听用户点击右上角菜单“收藏”按钮的行为,并自定义收藏内容。
* 基础库 2.10.3,安卓 7.0.15 版本起支持,iOS 暂不支持
*/
onAddToFavorites(options: IAddToFavoritesOption): IAddToFavoritesContent
}
interface InstanceProperties {
/** 页面的文件路径 */
is: string
/** 到当前页面的路径 */
route: string
/** 打开当前页面路径中的参数 */
options: Record<string, string | undefined>
}
type DataOption = Record<string, any>
type CustomOption = Record<string, any>
type InstanceMethods<D extends DataOption> = Component.InstanceMethods<D>
interface Data<D extends DataOption> {
/** 页面的初始数据
*
* `data` 是页面第一次渲染使用的**初始数据**。
*
* 页面加载时,`data` 将会以`JSON`字符串的形式由逻辑层传至渲染层,因此`data`中的数据必须是可以转成`JSON`的类型:字符串,数字,布尔值,对象,数组。
*
* 渲染层可以通过 `WXML` 对数据进行绑定。
*/
data: D
}
interface ICustomShareContent {
/** 转发标题。默认值:当前小程序名称 */
title?: string
/** 转发路径,必须是以 / 开头的完整路径。默认值:当前页面 path */
path?: string
/** 自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径。支持PNG及JPG。显示图片长宽比是 5:4,最低基础库: `1.5.0`。默认值:使用默认截图 */
imageUrl?: string
}
interface IAsyncCustomShareContent extends ICustomShareContent {
promise: Promise<ICustomShareContent>
}
interface ICustomTimelineContent {
/** 自定义标题,即朋友圈列表页上显示的标题。默认值:当前小程序名称 */
title?: string
/** 自定义页面路径中携带的参数,如 `path?a=1&b=2` 的 “?” 后面部分 默认值:当前页面路径携带的参数 */
query?: string
/** 自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径。支持 PNG 及 JPG。显示图片长宽比是 1:1。默认值:默认使用小程序 Logo*/
imageUrl?: string
}
interface IPageScrollOption {
/** 页面在垂直方向已滚动的距离(单位px) */
scrollTop: number
}
interface IShareAppMessageOption {
/** 转发事件来源。
*
* 可选值:
* - `button`:页面内转发按钮;
* - `menu`:右上角转发菜单。
*
* 最低基础库: `1.2.4`
*/
from: 'button' | 'menu'
/** 如果 `from` 值是 `button`,则 `target` 是触发这次转发事件的 `button`,否则为 `undefined`
*
* 最低基础库: `1.2.4` */
target: any
/** 页面中包含`<web-view>`组件时,返回当前`<web-view>`的url
*
* 最低基础库: `1.6.4`
*/
webViewUrl?: string
}
interface ITabItemTapOption {
/** 被点击tabItem的序号,从0开始,最低基础库: `1.9.0` */
index: string
/** 被点击tabItem的页面路径,最低基础库: `1.9.0` */
pagePath: string
/** 被点击tabItem的按钮文字,最低基础库: `1.9.0` */
text: string
}
interface IResizeOption {
size: {
/** 变化后的窗口宽度,单位 px */
windowWidth: number
/** 变化后的窗口高度,单位 px */
windowHeight: number
}
}
interface IAddToFavoritesOption {
/** 页面中包含web-view组件时,返回当前web-view的url */
webviewUrl?: string
}
interface IAddToFavoritesContent {
/** 自定义标题,默认值:页面标题或账号名称 */
title?: string
/** 自定义图片,显示图片长宽比为 1:1,默认值:页面截图 */
imageUrl?: string
/** 自定义query字段,默认值:当前页面的query */
query?: string
}
interface GetCurrentPages {
(): Array<Instance<IAnyObject, IAnyObject>>
}
}
/**
* 注册小程序中的一个页面。接受一个 `Object` 类型参数,其指定页面的初始数据、生命周期回调、事件处理函数等。
*/
declare let Page: WechatMiniprogram.Page.Constructor
/**
* 获取当前页面栈。数组中第一个元素为首页,最后一个元素为当前页面。
* __注意:__
* - __不要尝试修改页面栈,会导致路由以及页面状态错误。__
* - 不要在 `App.onLaunch` 的时候调用 `getCurrentPages()`,此时 `page` 还没有生成。
*/
declare let getCurrentPages: WechatMiniprogram.Page.GetCurrentPages
/*! *****************************************************************************
Copyright (c) 2023 Tencent, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***************************************************************************** */
declare namespace phys3D {
// pvd调试配置
export interface PhysicsDebugConfig {
isNetwork: boolean // 采用网络的方式
ip?: string // 如果isNetwork为true,调试信息会通过tcp转发的方式转发到打开了pvd调试软件的电脑,需要注意的是,防火墙要对pvd打开
port?: 5425 // pvd默认接口
timeout?: 1000 // 默认耗时
path?: string // 如果isNetwork为false,调试信息会通过写本地文件的方式落地,文件名建议为xxx.pxd2,导入pvd调试即可
}
export enum QueryTriggerInteraction {
UseGlobal = 0,
Ignore = 1,
Collide = 2
}
export class PhysSystem {
constructor(config?: PhysicsDebugConfig)
gravity: RawVec3f
bounceThreshold: number
defaultMaxAngularSpeed: number
defaultSolverIterations: number
defaultSolverVelocityIterations: number
sleepThreshold: number
defaultContactOffset: number
destroyScene: () => void
createScene: () => number
Simulate: (step: number) => void
SyncFromTransforms: (() => void) | undefined // added in 2021.06
SetCollisionMask: (mask: ArrayBuffer) => void
Raycast: (
origin: RawVec3f,
unitDir: RawVec3f,
distance: number,
hit: RaycastHit,
layerMask?: number,
queryTriggerInteraction?: QueryTriggerInteraction
) => boolean
RaycastAll: (
origin: RawVec3f,
unitDir: RawVec3f,
distance: number,
layerMask?: number,
queryTriggerInteraction?: QueryTriggerInteraction
) => RaycastHit[]
CapsuleCast(
p1: RawVec3f,
p2: RawVec3f,
radius: number,
direction: RawVec3f,
hit: RaycastHit,
maxDistance: number,
layerMask?: number,
queryTriggerInteraction?: QueryTriggerInteraction
): void
CapsuleCastAll: (
p1: RawVec3f,
p2: RawVec3f,
radius: number,
direction: RawVec3f,
maxDistance: number,
layerMask?: number,
queryTriggerInteraction?: QueryTriggerInteraction
) => RaycastHit[]
BoxCast(
center: RawVec3f,
halfExt: RawVec3f,
direction: RawVec3f,
hit: RaycastHit,
orientation: RawQuaternion,
maxDistance: number,
layerMask?: number,
queryTriggerInteraction?: QueryTriggerInteraction
): void
BoxCastAll: (
center: RawVec3f,
halfExt: RawVec3f,
direction: RawVec3f,
orientation: RawQuaternion,
maxDistance: number,
layerMask?: number,
queryTriggerInteraction?: QueryTriggerInteraction
) => RaycastHit[]
OverlapBox: (
center: RawVec3f,
halfExt: RawVec3f,
orientation: RawQuaternion,
layermask?: number,
queryTriggerInteraction?: QueryTriggerInteraction
) => Collider[]
OverlapCapsule: (
p1: RawVec3f,
p2: RawVec3f,
radius: number,
layermask?: number,
queryTriggerInteraction?: QueryTriggerInteraction
) => Collider[]
}
export class Rigidbody {
constructor(system: PhysSystem)
enabled?: boolean // since 2021.06
position: RawVec3f
rotation: RawQuaternion
AttachToEntity: (pollObj: any, id: number) => void
Remove(): void
Detach(): void
IsAttached(): boolean
}
export enum CollisionDetectionMode {
Discrete = 0,
Continuous = 1,
ContinuousDynamic = 2,
ContinuousSpeculative = 3
}
export enum RigidbodyConstraints {
None = 0,
FreezePositionX = 1 << 0,
FreezePositionY = 1 << 1,
FreezePositionZ = 1 << 2,
FreezeRotationX = 1 << 3,
FreezeRotationY = 1 << 4,
FreezeRotationZ = 1 << 5,
FreezePosition = FreezePositionX | FreezePositionY | FreezePositionZ,
FreezeRotation = FreezeRotationX | FreezeRotationY | FreezeRotationZ,
FreezeAll = FreezePosition | FreezeRotation
}
export enum ForceMode {
kForceModeForce = 0,
kForceModeImpulse = 1 << 0,
kForceModeVelocityChange = 1 << 1,
kForceModeAcceleration = 1 << 2
}
export enum CombineMode {
eAverage = 0,
eMin,
eMultiply,
eMax
}
export enum CookingFlag {
None = 0,
CookForFasterSimulation = 1 << 0,
EnableMeshCleaning = 1 << 1,
WeldColocatedVertices = 1 << 2
}
export enum CollisionFlags {
None = 0,
Sides = 1 << 0,
Above = 1 << 1,
Below = 1 << 2
}
export class RawVec3f {
constructor()
constructor(x: number, y: number, z: number)
x: number
y: number
z: number
}
export class RawQuaternion {
constructor()
constructor(x: number, y: number, z: number, w: number)
x: number
y: number
z: number
w: number
}
export class Collider {
attachedRigidbody: Rigidbody
bounds: Bounds
name: string
contactOffset: number
enabled: boolean
isTrigger: boolean
scale: RawVec3f
material?: Material
sharedMateiral?: Material
ClosestPoint: (raw: RawVec3f) => RawVec3f
ClosestPointOnBounds: (raw: RawVec3f) => RawVec3f
onCollisionEnter?: (collision: Collision) => void
onCollisionExit?: (collision: Collision) => void
onCollisionStay?: (collision: Collision) => void
onTriggerEnter?: (collision: Collision) => void
onTriggerExit?: (collision: Collision) => void
onTriggerStay?: (collision: Collision) => void
dettachRigidbody?: () => void
userData?: unknown
layer: number
}
export class BoxCollider extends Collider {
constructor(system: PhysSystem, center: RawVec3f, size: RawVec3f)
center: RawVec3f
size: RawVec3f
}
export class SphereCollider extends Collider {
constructor(system: PhysSystem, center: RawVec3f, radius: number)
center: RawVec3f
radius: number
}
export class CapsuleCollider extends Collider {
constructor(
system: PhysSystem,
center: RawVec3f,
height: number,
radius: number
)
center: RawVec3f
height: number
radius: number
}
export class MeshCollider extends Collider {
constructor(
system: PhysSystem,
convex: boolean,
cookingOptions: number,
sharedMesh: PhysMesh
)
cookingOptions: number
sharedMesh: PhysMesh | null
convex: boolean
}
export class CharacterController extends Collider {
constructor(system: PhysSystem)
position: RawVec3f
center: RawVec3f
collisionFlags: CollisionFlags
detectCollisions: boolean
enableOverlapRecovery: boolean
height: number
isGrounded: boolean
minMoveDistance: number
radius: number
skinWidth: number
slopeLimit: number
stepOffset: number
velocity: RawVec3f
Move: (movement: RawVec3f) => CollisionFlags
SimpleMove: (speed: RawVec3f) => boolean
AttachToEntity: (pollObj: any, id: number) => void
OnControllerColliderHit?: (hit: ControllerColliderHit) => void
}
export interface ContactPoint {
normal: RawVec3f
this_collider: Collider
other_collider: Collider
point: RawVec3f
separation: number
}
export interface Collision {
collider: Collider
contacts: ContactPoint[]
impulse: RawVec3f
relative_velocity: RawVec3f
}
export interface ControllerColliderHit {
collider: Collider
controller: CharacterController
moveDirection: RawVec3f
normal: RawVec3f
moveLength: number
point: RawVec3f
}
export class Bounds {
constructor(center: RawVec3f, size: RawVec3f)
center: RawVec3f
extents: RawVec3f
max: RawVec3f
min: RawVec3f
size: RawVec3f
ClosestPoint: (point: RawVec3f) => RawVec3f
Contains: (point: RawVec3f) => boolean
Expand: (amount: number) => void
Intersects: (bounds: Bounds) => boolean
SetMinMax: (min: RawVec3f, max: RawVec3f) => void
SqrDistance: (point: RawVec3f) => number
}
export class Material {
constructor(system: PhysSystem)
dynamicFriction: number
staticFriction: number
bounciness: number
frictionCombine: CombineMode
bounceCombine: CombineMode
id: number
}
export class DynamicRigidbody extends Rigidbody {
mass: number
angularDamping: number
angularVelocity: RawVec3f
centerOfMass: RawVec3f
collisionDetectionMode: CollisionDetectionMode
constraints: number
detectCollisions: boolean
linearDamping: number
freezeRotation: boolean
inertiaTensor: number
// inertiaTensorRotation
// interpolation
isKinematic: boolean
maxAngularVelocity: number
maxDepenetrationVelocity: number
sleepThreshold: number
solverIterations: number
solverVelocityIterations: number
useGravity: boolean
velocity: RawVec3f
userData?: unknown
GetWorldCenterOfMass: () => RawVec3f
AddForce: (force: RawVec3f, mode: ForceMode) => void
AddTorque: (torque: RawVec3f, mode: ForceMode) => void
IsSleeping: () => boolean
Sleep: () => void
WakeUp: () => void
AddExplosionForce: (
explosionForce: number,
explosionPosition: RawVec3f,
explosionRadius: number,
upwardsModifier: number,
mode: ForceMode
) => void
AddForceAtPosition: (
force: RawVec3f,
position: RawVec3f,
mode: ForceMode
) => void
AddRelativeForce: (force: RawVec3f, mode: ForceMode) => void
AddRelativeTorque: (torque: RawVec3f, mode: ForceMode) => void
ClosestPointOnBounds: (position: RawVec3f) => RawVec3f
GetPointVelocity: (worldPoint: RawVec3f) => RawVec3f
GetRelativePointVelocity: (relativePoint: RawVec3f) => RawVec3f
MovePosition: (position: RawVec3f) => void
MoveRotation: (rotation: RawQuaternion) => void
ResetCenterOfMass: () => void
ResetInertiaTensor: () => void
SetDensity: (density: number) => void
// SweepTest: () => void;
// SweepTestAll: () => void;
}
export class PhysMesh {
constructor(system: PhysSystem)
// set vertices
SetVertices: (buffer: Float32Array, count: number) => void
// set indices
SetTriangles: (
buffer: Uint16Array | Uint32Array,
count: number,
useUint16: boolean
) => void
}
export class RaycastHit {
constructor()
collider: Collider
distance: number
normal: RawVec3f
point: RawVec3f
rigidbody: Rigidbody
}
}
/*! *****************************************************************************
Copyright (c) 2023 Tencent, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***************************************************************************** */
/** [WXWebAssembly](https://developers.weixin.qq.com/miniprogram/dev/framework/performance/wasm.html)
*
* WXWebAssembly */
declare namespace WXWebAssembly {
type BufferSource = ArrayBufferView | ArrayBuffer
type CompileError = Error
const CompileError: {
prototype: CompileError
new (message?: string): CompileError
(message?: string): CompileError
}
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) */
interface Instance {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports) */
readonly exports: Exports
}
const Instance: {
prototype: Instance
new (module: Module, importObject?: Imports): Instance
}
type LinkError = Error
const LinkError: {
prototype: LinkError
new (message?: string): LinkError
(message?: string): LinkError
}
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) */
interface Memory {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer) */
readonly buffer: ArrayBuffer
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow) */
grow(delta: number): number
}
const Memory: {
prototype: Memory
new (descriptor: MemoryDescriptor): Memory
}
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) */
interface Module {}
const Module: {
prototype: Module
new (bytes: BufferSource): Module
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections) */
customSections(moduleObject: Module, sectionName: string): ArrayBuffer[]
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports) */
exports(moduleObject: Module): ModuleExportDescriptor[]
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports) */
imports(moduleObject: Module): ModuleImportDescriptor[]
}
interface RuntimeError extends Error {}
const RuntimeError: {
prototype: RuntimeError
new (message?: string): RuntimeError
(message?: string): RuntimeError
}
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table) */
interface Table {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length) */
readonly length: number
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get) */
get(index: number): any
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow) */
grow(delta: number, value?: any): number
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set) */
set(index: number, value?: any): void
}
const Table: {
prototype: Table
new (descriptor: TableDescriptor, value?: any): Table
}
interface MemoryDescriptor {
initial: number
maximum?: number
shared?: boolean
}
interface ModuleExportDescriptor {
kind: ImportExportKind
name: string
}
interface ModuleImportDescriptor {
kind: ImportExportKind
module: string
name: string
}
interface TableDescriptor {
element: TableKind
initial: number
maximum?: number
}
type ImportExportKind = 'function' | 'global' | 'memory' | 'table'
type TableKind = 'anyfunc' | 'externref'
type ValueType =
| 'anyfunc'
| 'externref'
| 'f32'
| 'f64'
| 'i32'
| 'i64'
| 'v128'
// eslint-disable-next-line @typescript-eslint/ban-types
type ExportValue = Function | Memory | Table
type Exports = Record<string, ExportValue>
type ImportValue = ExportValue | number
type Imports = Record<string, ModuleImports>
type ModuleImports = Record<string, ImportValue>
/** [WXWebAssembly](https://developers.weixin.qq.com/miniprogram/dev/framework/performance/wasm.html) */
function instantiate(
path: string,
importObject?: Imports
): Promise<Instance>
}
因为 它太大了无法显示 source diff 。你可以改为 查看blob
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册