From 66c84627687bbbcabf726647e304327b075ff819 Mon Sep 17 00:00:00 2001 From: linju Date: Tue, 10 Jan 2023 17:11:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8Euni-admin=E5=90=8C=E6=AD=A5=E7=9B=B8?= =?UTF-8?q?=E5=85=B3uniCloud=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 3 - common/appInit.js | 5 +- pages.json | 9 +- pages/list/list.nvue | 2 +- ...6\345\272\223\347\256\241\347\220\206.jql" | 12 - .../database/JQL\346\237\245\350\257\242.jql" | 9 - uniCloud-aliyun/database/default.jql | 12 - .../database/opendb-department.schema.json | 47 - .../database/opendb-mall-goods.schema.json | 123 - uni_modules/Sansnn-uQRCode/changelog.md | 19 +- uni_modules/Sansnn-uQRCode/common/cache.js | 1 + uni_modules/Sansnn-uQRCode/common/queue.js | 41 + .../Sansnn-uQRCode/common/types/cache.d.ts | 3 + .../Sansnn-uQRCode/common/types/queue.d.ts | 4 + .../components/u-qrcode/u-qrcode.vue | 1900 +++++++------ .../components/uqrcode/uqrcode.vue | 1900 +++++++------ .../js_sdk/gcanvas/bridge/bridge-weex.js | 480 ++-- .../context-2d/FillStyleLinearGradient.js | 34 +- .../gcanvas/context-2d/FillStylePattern.js | 14 +- .../context-2d/FillStyleRadialGradient.js | 32 +- .../gcanvas/context-2d/RenderingContext.js | 1332 ++++----- .../gcanvas/context-webgl/ActiveInfo.js | 20 +- .../js_sdk/gcanvas/context-webgl/Buffer.js | 40 +- .../gcanvas/context-webgl/Framebuffer.js | 40 +- .../js_sdk/gcanvas/context-webgl/GLenum.js | 594 ++-- .../js_sdk/gcanvas/context-webgl/GLmethod.js | 282 +- .../js_sdk/gcanvas/context-webgl/GLtype.js | 46 +- .../js_sdk/gcanvas/context-webgl/Program.js | 40 +- .../gcanvas/context-webgl/Renderbuffer.js | 40 +- .../gcanvas/context-webgl/RenderingContext.js | 2380 ++++++++--------- .../js_sdk/gcanvas/context-webgl/Shader.js | 42 +- .../context-webgl/ShaderPrecisionFormat.js | 20 +- .../js_sdk/gcanvas/context-webgl/Texture.js | 42 +- .../gcanvas/context-webgl/UniformLocation.js | 42 +- .../gcanvas/context-webgl/classUtils.js | 4 +- .../js_sdk/gcanvas/env/canvas.js | 146 +- .../js_sdk/gcanvas/env/image.js | 190 +- .../Sansnn-uQRCode/js_sdk/gcanvas/env/tool.js | 46 +- .../Sansnn-uQRCode/js_sdk/gcanvas/index.js | 76 +- .../Sansnn-uQRCode/js_sdk/uqrcode/uqrcode.js | 39 +- uni_modules/Sansnn-uQRCode/license.md | 402 +-- uni_modules/Sansnn-uQRCode/package.json | 7 +- uni_modules/Sansnn-uQRCode/readme.md | 688 +++-- .../components/uni-badge/uni-badge.vue | 6 +- uni_modules/uni-captcha/changelog.md | 3 + uni_modules/uni-captcha/package.json | 11 +- .../common/uni-captcha/index.js | 2 +- uni_modules/uni-data-picker/changelog.md | 134 +- .../components/uni-data-picker/keypress.js | 90 +- .../uni-data-pickerview/uni-data-picker.js | 1126 ++++---- .../uni-data-pickerview.vue | 2 +- uni_modules/uni-data-picker/package.json | 178 +- uni_modules/uni-data-picker/readme.md | 42 +- uni_modules/uni-data-select/changelog.md | 2 + .../uni-data-select/uni-data-select.vue | 41 +- uni_modules/uni-data-select/package.json | 2 +- uni_modules/uni-datetime-picker/changelog.md | 2 + .../uni-datetime-picker/time-picker.vue | 30 +- .../uni-datetime-picker.vue | 19 +- uni_modules/uni-datetime-picker/package.json | 2 +- uni_modules/uni-easyinput/changelog.md | 2 + .../uni-easyinput/uni-easyinput.vue | 5 +- uni_modules/uni-easyinput/package.json | 2 +- uni_modules/uni-file-picker/changelog.md | 2 + .../uni-file-picker/choose-and-upload-file.js | 6 +- .../uni-file-picker/uni-file-picker.vue | 17 +- uni_modules/uni-file-picker/package.json | 11 +- uni_modules/uni-id-pages/changelog.md | 28 +- .../uni-id-pages/common/login-page.mixin.js | 2 +- .../uni-id-pages/common/login-page.scss | 3 +- uni_modules/uni-id-pages/common/store.js | 290 +- .../uni-id-pages-avatar.vue | 14 +- .../uni-id-pages-bind-mobile.vue | 14 +- .../uni-id-pages-email-form.vue | 21 +- .../uni-id-pages-fab-login.vue | 49 +- .../uni-id-pages-sms-form.vue | 30 +- .../uni-id-pages-user-profile.vue | 2 +- uni_modules/uni-id-pages/config.js | 13 +- uni_modules/uni-id-pages/init.js | 15 +- uni_modules/uni-id-pages/package.json | 2 +- .../pages/common/webview/webview.vue | 2 +- .../pages/login/login-smscode.vue | 9 +- .../pages/login/login-withoutpwd.vue | 22 +- .../pages/login/login-withpwd.vue | 11 +- .../pages/register/register-admin.vue | 12 +- .../pages/register/register-by-email.vue | 8 +- .../uni-id-pages/pages/register/register.vue | 7 +- .../pages/retrieve/retrieve-by-email.vue | 22 +- .../uni-id-pages/pages/retrieve/retrieve.vue | 10 +- .../userinfo/bind-mobile/bind-mobile.vue | 25 +- .../pages/userinfo/change_pwd/change_pwd.vue | 22 +- .../pages/userinfo/cropImage/cropImage.vue | 2 +- .../cropImage/limeClipper/limeClipper.vue | 12 +- .../pages/userinfo/deactivate/deactivate.vue | 5 +- .../pages/userinfo/set-pwd/set-pwd.vue | 170 ++ .../uni-id-pages/pages/userinfo/userinfo.vue | 30 +- .../uni-id-co/common/constants.js | 6 +- .../cloudfunctions/uni-id-co/common/error.js | 4 +- .../cloudfunctions/uni-id-co/common/utils.js | 21 +- .../uni-id-co/common/validator.js | 17 +- .../uni-id-co/config/permission.js | 3 + .../cloudfunctions/uni-id-co/index.obj.js | 29 +- .../cloudfunctions/uni-id-co/lang/en.js | 4 +- .../cloudfunctions/uni-id-co/lang/zh-hans.js | 4 +- .../uni-id-co/lib/utils/account.js | 55 +- .../uni-id-co/lib/utils/config.js | 2 +- .../uni-id-co/lib/utils/login.js | 14 +- .../uni-id-co/lib/utils/logout.js | 10 +- .../uni-id-co/lib/utils/register.js | 11 +- .../uni-id-co/lib/utils/relate.js | 4 +- .../uni-id-co/lib/utils/unified-login.js | 10 +- .../uni-id-co/middleware/index.js | 1 + .../middleware/verify-request-sign.js | 39 + .../uni-id-co/module/account/index.js | 1 + .../module/account/reset-pwd-by-email.js | 10 +- .../module/account/reset-pwd-by-sms.js | 10 +- .../uni-id-co/module/account/set-pwd.js | 83 + .../uni-id-co/module/admin/add-user.js | 4 +- .../uni-id-co/module/admin/update-user.js | 20 +- .../uni-id-co/module/external/index.js | 4 + .../uni-id-co/module/external/login.js | 29 + .../uni-id-co/module/external/register.js | 52 + .../uni-id-co/module/login/login-by-weixin.js | 44 +- .../uni-id-co/module/multi-end/utils.js | 4 +- .../module/verify/send-email-code.js | 14 +- .../uni-id-co/module/verify/send-sms-code.js | 2 +- .../cloudfunctions/uni-id-co/package.json | 2 +- uni_modules/uni-id/changelog.md | 2 + uni_modules/uni-id/package.json | 22 +- uni_modules/uni-id/uni-id.zip | Bin 0 -> 42348 bytes .../cloudfunctions/common/uni-id/index.js | 2 +- .../cloudfunctions/common/uni-id/package.json | 5 +- uni_modules/uni-list/changelog.md | 16 + .../uni-list-chat/uni-list-chat.vue | 52 +- .../uni-list-item/uni-list-item.vue | 49 +- uni_modules/uni-list/package.json | 2 +- uni_modules/uni-nav-bar/changelog.md | 6 + .../components/uni-nav-bar/uni-nav-bar.vue | 17 +- uni_modules/uni-nav-bar/package.json | 11 +- uni_modules/uni-popup/changelog.md | 4 + .../uni-popup-dialog/uni-popup-dialog.vue | 29 +- .../components/uni-popup/uni-popup.vue | 946 +++---- uni_modules/uni-popup/package.json | 13 +- uni_modules/uni-table/changelog.md | 2 + .../components/uni-table/uni-table.vue | 2 +- .../components/uni-th/filter-dropdown.vue | 24 +- .../uni-table/components/uni-th/uni-th.vue | 117 +- .../components/uni-tr/table-checkbox.vue | 14 +- uni_modules/uni-table/package.json | 11 +- uni_modules/uni-ui/changelog.md | 941 +++---- uni_modules/uni-ui/package.json | 2 +- .../uni-upgrade-center-app/changelog.md | 2 + .../uni-upgrade-center-app/package.json | 4 +- .../uni-upgrade-center-app/pages_init.json | 18 - .../static/app_update_close.png | Bin 7644 -> 0 bytes .../uni-upgrade-center-app/static/bg_top.png | Bin 30486 -> 0 bytes .../static/button_bg.png | Bin 4156 -> 0 bytes .../check-version/check-version.param.json | 9 - .../cloudfunctions/check-version/index.js | 167 -- .../uniCloud/cloudfunctions/temp.png | Bin 7644 -> 0 bytes .../cloudfunctions/upgrade-center/index.js | 19 - .../database/opendb-app-list.schema.json | 391 ++- 162 files changed, 9312 insertions(+), 7897 deletions(-) delete mode 100644 "uniCloud-aliyun/database/JQL\346\225\260\346\215\256\345\272\223\347\256\241\347\220\206.jql" delete mode 100644 "uniCloud-aliyun/database/JQL\346\237\245\350\257\242.jql" delete mode 100644 uniCloud-aliyun/database/default.jql delete mode 100644 uniCloud-aliyun/database/opendb-department.schema.json delete mode 100644 uniCloud-aliyun/database/opendb-mall-goods.schema.json create mode 100644 uni_modules/Sansnn-uQRCode/common/cache.js create mode 100644 uni_modules/Sansnn-uQRCode/common/queue.js create mode 100644 uni_modules/Sansnn-uQRCode/common/types/cache.d.ts create mode 100644 uni_modules/Sansnn-uQRCode/common/types/queue.d.ts create mode 100644 uni_modules/uni-id-pages/pages/userinfo/set-pwd/set-pwd.vue create mode 100644 uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/middleware/verify-request-sign.js create mode 100644 uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/account/set-pwd.js create mode 100644 uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/index.js create mode 100644 uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/login.js create mode 100644 uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/register.js create mode 100644 uni_modules/uni-id/uni-id.zip delete mode 100644 uni_modules/uni-upgrade-center-app/pages_init.json delete mode 100644 uni_modules/uni-upgrade-center-app/static/app_update_close.png delete mode 100644 uni_modules/uni-upgrade-center-app/static/bg_top.png delete mode 100644 uni_modules/uni-upgrade-center-app/static/button_bg.png delete mode 100644 uni_modules/uni-upgrade-center-app/uniCloud/cloudfunctions/check-version/check-version.param.json delete mode 100644 uni_modules/uni-upgrade-center-app/uniCloud/cloudfunctions/check-version/index.js delete mode 100644 uni_modules/uni-upgrade-center-app/uniCloud/cloudfunctions/temp.png delete mode 100644 uni_modules/uni-upgrade-center/uniCloud/cloudfunctions/upgrade-center/index.js diff --git a/App.vue b/App.vue index e3f3a82..65eaabd 100644 --- a/App.vue +++ b/App.vue @@ -18,9 +18,6 @@ console.log('App Launch') this.globalData.$i18n = this.$i18n this.globalData.$t = str => this.$t(str) - - console.log('uni.getPushClientId',uni.getPushClientId); - initApp(); uniIdPageInit() diff --git a/common/appInit.js b/common/appInit.js index 0e9bf7f..a2bc5d7 100644 --- a/common/appInit.js +++ b/common/appInit.js @@ -1,7 +1,7 @@ import uniStarterConfig from '@/uni-starter.config.js'; //应用初始化页 // #ifdef APP-PLUS -import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'; +import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'; import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version'; // 实现,路由拦截。当应用无访问摄像头/相册权限,引导跳到设置界面 https://ext.dcloud.net.cn/plugin?id=5095 @@ -154,7 +154,8 @@ function initAppVersion() { // 有新版本 getApp({ allowDefault: true - }).appVersion.hasNew = true; + }).appVersion.hasNew = true; + console.log(checkUpdate()); } }) }); diff --git a/pages.json b/pages.json index 365d430..2647e49 100644 --- a/pages.json +++ b/pages.json @@ -192,7 +192,14 @@ "navigationBarTitleText": "注册管理员账号" } } - ], + ,{ + "path": "uni_modules/uni-id-pages/pages/userinfo/set-pwd/set-pwd", + "style": { + "enablePullDownRefresh": false, + "navigationBarTitleText": "设置密码" + } +} +], "globalStyle": { // #ifdef H5 "h5": { diff --git a/pages/list/list.nvue b/pages/list/list.nvue index 2753fcf..46d685f 100644 --- a/pages/list/list.nvue +++ b/pages/list/list.nvue @@ -254,4 +254,4 @@ z-index: 999; /* #endif */ } - + diff --git "a/uniCloud-aliyun/database/JQL\346\225\260\346\215\256\345\272\223\347\256\241\347\220\206.jql" "b/uniCloud-aliyun/database/JQL\346\225\260\346\215\256\345\272\223\347\256\241\347\220\206.jql" deleted file mode 100644 index 5292b02..0000000 --- "a/uniCloud-aliyun/database/JQL\346\225\260\346\215\256\345\272\223\347\256\241\347\220\206.jql" +++ /dev/null @@ -1,12 +0,0 @@ -// 本文件用于,使用JQL语法操作项目关联的uniCloud空间的数据库,方便开发调试和远程数据库管理 -// 编写clientDB的js API(也支持常规js语法,比如var),可以对云数据库进行增删改查操作。不支持uniCloud-db组件写法 -// 可以全部运行,也可以选中部分代码运行。点击工具栏上的运行按钮或者按下【F5】键运行代码 -// 如果文档中存在多条JQL语句,只有最后一条语句生效 -// 如果混写了普通js,最后一条语句需是数据库操作语句 -// 此处代码运行不受DB Schema的权限控制,移植代码到实际业务中注意在schema中配好permission -// 不支持clientDB的action -// 数据库查询有最大返回条数限制,详见:https://uniapp.dcloud.net.cn/uniCloud/cf-database?id=limit -// 详细JQL语法,请参考 https://uniapp.dcloud.net.cn/uniCloud/clientdb?id=jsquery - -// 下面示例查询uni-id-users表的所有数据 -db.collection('uni-id-users').where('user_id._id=="610a6daa506cc7000100c07f"').get(); diff --git "a/uniCloud-aliyun/database/JQL\346\237\245\350\257\242.jql" "b/uniCloud-aliyun/database/JQL\346\237\245\350\257\242.jql" deleted file mode 100644 index 680e898..0000000 --- "a/uniCloud-aliyun/database/JQL\346\237\245\350\257\242.jql" +++ /dev/null @@ -1,9 +0,0 @@ -// 本查询文件用于,使用JQL语法查询项目关联的uniCloud空间的数据库,方便开发调试 -// 选中查询代码,点击工具栏上的运行按钮或者【F5】运行查询语句 -// 如果没有选中代码,直接运行,则会执行整个文档的JQL语句。但如果文档中存在多条JQL语句,只有最后一条语句生效 -// 本文档支持简单js,但不支持clientDB的action -// 数据库查询有最大返回条数限制,详见:https://uniapp.dcloud.net.cn/uniCloud/cf-database?id=limit -// 详细JQL语法,请参考 https://uniapp.dcloud.net.cn/uniCloud/clientdb?id=jsquery - -// 下面示例查询uni-id-users表的所有数据 -db.collection('uni-id-users').get(); diff --git a/uniCloud-aliyun/database/default.jql b/uniCloud-aliyun/database/default.jql deleted file mode 100644 index 35d21de..0000000 --- a/uniCloud-aliyun/database/default.jql +++ /dev/null @@ -1,12 +0,0 @@ -// 本文件用于,使用JQL语法操作项目关联的uniCloud空间的数据库,方便开发调试和远程数据库管理 -// 编写clientDB的js API(也支持常规js语法,比如var),可以对云数据库进行增删改查操作。不支持uniCloud-db组件写法 -// 可以全部运行,也可以选中部分代码运行。点击工具栏上的运行按钮或者按下【F5】键运行代码 -// 如果文档中存在多条JQL语句,只有最后一条语句生效 -// 如果混写了普通js,最后一条语句需是数据库操作语句 -// 此处代码运行不受DB Schema的权限控制,移植代码到实际业务中注意在schema中配好permission -// 不支持clientDB的action -// 数据库查询有最大返回条数限制,详见:https://uniapp.dcloud.net.cn/uniCloud/cf-database.html#limit -// 详细JQL语法,请参考:https://uniapp.dcloud.net.cn/uniCloud/jql.html - -// 下面示例查询uni-id-users表的所有数据 -db.collection('uni-id-users').get(); diff --git a/uniCloud-aliyun/database/opendb-department.schema.json b/uniCloud-aliyun/database/opendb-department.schema.json deleted file mode 100644 index 3996e9a..0000000 --- a/uniCloud-aliyun/database/opendb-department.schema.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "bsonType": "object", - "required": ["name"], - "permission": { - "read": true, - "create": false, - "update": false, - "delete": false - }, - "properties": { - "_id": { - "description": "ID,系统自动生成" - }, - "parent_id": { - "bsonType": "string", - "description": "父级部门ID", - "parentKey": "_id" - }, - "name": { - "bsonType": "string", - "description": "部门名称", - "title": "部门名称", - "trim": "both" - }, - "level": { - "bsonType": "int", - "description": "部门层级,为提升检索效率而作的冗余设计" - }, - "sort": { - "bsonType": "int", - "description": "部门在当前层级下的顺序,由小到大", - "title": "显示顺序" - }, - "manager_uid": { - "bsonType": "string", - "description": "部门主管的userid, 参考`uni-id-users` 表", - "foreignKey": "uni-id-users._id" - }, - "create_date": { - "bsonType": "timestamp", - "description": "部门创建时间", - "forceDefaultValue": { - "$env": "now" - } - } - } -} diff --git a/uniCloud-aliyun/database/opendb-mall-goods.schema.json b/uniCloud-aliyun/database/opendb-mall-goods.schema.json deleted file mode 100644 index 3b6e309..0000000 --- a/uniCloud-aliyun/database/opendb-mall-goods.schema.json +++ /dev/null @@ -1,123 +0,0 @@ -{ - "bsonType": "object", - "permission": { - "create": false, - "delete": false, - "read": "doc.is_on_sale == true", - "update": false - }, - "properties": { - "_id": { - "description": "存储文档 ID(商品 ID),系统自动生成" - }, - "add_date": { - "bsonType": "timestamp", - "defaultValue": { - "$env": "now" - }, - "description": "上架时间" - }, - "category_id": { - "bsonType": "string", - "description": "分类 id,参考`opendb-mall-categories`表", - "foreignKey": "opendb-mall-categories._id" - }, - "comment_count": { - "bsonType": "int", - "description": "累计评论数" - }, - "goods_banner_imgs": { - "bsonType": "array", - "description": "商品详情页的banner图地址" - }, - "goods_desc": { - "bsonType": "string", - "description": "商品详细描述", - "title": "详细描述", - "trim": "both" - }, - "goods_sn": { - "bsonType": "string", - "description": "商品的唯一货号", - "title": "货号", - "trim": "both" - }, - "goods_thumb": { - "bsonType": "string", - "description": "商品缩略图,用于在列表或搜索结果中预览显示", - "pattern": "^(http:\/\/|https:\/\/|\/|.\/|@\/)\\S", - "title": "缩略图地址", - "trim": "both" - }, - "is_alone_sale": { - "bsonType": "bool", - "description": "是否能单独销售;如果不能单独销售,则只能作为某商品的配件或者赠品销售" - }, - "is_best": { - "bsonType": "bool", - "description": "是否精品" - }, - "is_hot": { - "bsonType": "bool", - "description": "是否热销" - }, - "is_new": { - "bsonType": "bool", - "description": "是否新品", - "title": "是否新品" - }, - "is_on_sale": { - "bsonType": "bool", - "description": "是否上架销售", - "title": "是否上架" - }, - "is_real": { - "bsonType": "bool", - "description": "是否实物", - "title": "是否为实物" - }, - "keywords": { - "bsonType": "string", - "description": "商品关键字,为搜索引擎收录使用", - "title": "关键字", - "trim": "both" - }, - "last_modify_date": { - "bsonType": "timestamp", - "defaultValue": { - "$env": "now" - }, - "description": "最后修改时间" - }, - "month_sell_count": { - "bsonType": "int", - "description": "月销量" - }, - "name": { - "bsonType": "string", - "description": "商品名称", - "title": "名称", - "trim": "both" - }, - "remain_count": { - "bsonType": "int", - "description": "库存数量", - "title": "库存数量" - }, - "seller_note": { - "bsonType": "string", - "description": "商家备注,仅商家可见", - "permission": { - "read": false - }, - "trim": "both" - }, - "total_sell_count": { - "bsonType": "int", - "description": "总销量" - } - }, - "required": ["goods_sn", "name", "remain_count", "month_sell_count", "total_sell_count", "comment_count", "is_real", - "is_on_sale", "is_alone_sale", "is_best", "is_new", "is_hot" - ] -} diff --git a/uni_modules/Sansnn-uQRCode/changelog.md b/uni_modules/Sansnn-uQRCode/changelog.md index 2fc9664..faf7abd 100644 --- a/uni_modules/Sansnn-uQRCode/changelog.md +++ b/uni_modules/Sansnn-uQRCode/changelog.md @@ -1,7 +1,12 @@ -## 3.5.1(2022-08-11) -v3.5.1 - -修复vue3引入报错; -修复vue导出临时文件失败; -修复在其他dom元素更新时,可能导致二维码重新渲染; -修复size重新赋值导致组件偏移、闪烁。 +## 4.0.6(2022-12-12) +修复`getDrawModules`,第一次获取结果正常,后续获取`tile`模块不存在的问题; +修复安卓type:normal因Canvas API使用了小数或为0的参数导致生成异常的问题(注:安卓非2d Canvas部分API参数不支持携带小数,部分API参数必须大于0)。 +## 4.0.1(2022-11-28) +优化组件loading属性的表现; +新增组件type选项normal,以便于在某些条件编译初始为type=2d时还可以选择使用非2d组件类型; +修复组件条件编译在其他编辑器语法提示报错; +修复原生对es5的支持。 +## 4.0.0(2022-11-21) +v4版本源代码全面开放,开源地址:[https://github.com/Sansnn/uQRCode](https://github.com/Sansnn/uQRCode); + +升级说明:v4为大版本更新,虽然已尽可能兼容上一代版本,但不可避免的还是存在一些细节差异,若更新后出现问题,请参考对照[v3 文档](https://uqrcode.cn/doc/v3),[v4 文档](https://uqrcode.cn/doc)进行修改。 diff --git a/uni_modules/Sansnn-uQRCode/common/cache.js b/uni_modules/Sansnn-uQRCode/common/cache.js new file mode 100644 index 0000000..d897d26 --- /dev/null +++ b/uni_modules/Sansnn-uQRCode/common/cache.js @@ -0,0 +1 @@ +export const cacheImageList = []; \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/common/queue.js b/uni_modules/Sansnn-uQRCode/common/queue.js new file mode 100644 index 0000000..c89d76b --- /dev/null +++ b/uni_modules/Sansnn-uQRCode/common/queue.js @@ -0,0 +1,41 @@ +function Queue() { + let waitingQueue = this.waitingQueue = []; + let isRunning = this.isRunning = false; // 记录是否有未完成的任务 + + function execute(task, resolve, reject) { + task() + .then((data) => { + resolve(data); + }) + .catch((e) => { + reject(e); + }) + .finally(() => { + // 等待任务队列中如果有任务,则触发它;否则设置isRunning = false,表示无任务状态 + if (waitingQueue.length) { + const next = waitingQueue.shift(); + execute(next.task, next.resolve, next.reject); + } else { + isRunning = false; + } + }); + } + this.exec = function(task) { + return new Promise((resolve, reject) => { + if (isRunning) { + waitingQueue.push({ + task, + resolve, + reject + }); + } else { + isRunning = true; + execute(task, resolve, reject); + } + }); + } +} + +/* 队列实例,某些平台一起使用多个组件时需要通过队列逐一绘制,否则部分绘制方法异常,nvue端的iOS gcanvas尤其明显,在不通过队列绘制时会出现图片丢失的情况 */ +export const queueDraw = new Queue(); +export const queueLoadImage = new Queue(); \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/common/types/cache.d.ts b/uni_modules/Sansnn-uQRCode/common/types/cache.d.ts new file mode 100644 index 0000000..657e9fa --- /dev/null +++ b/uni_modules/Sansnn-uQRCode/common/types/cache.d.ts @@ -0,0 +1,3 @@ +declare module '*/common/cache' { + export const cacheImageList: Array; +} \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/common/types/queue.d.ts b/uni_modules/Sansnn-uQRCode/common/types/queue.d.ts new file mode 100644 index 0000000..9c5aafc --- /dev/null +++ b/uni_modules/Sansnn-uQRCode/common/types/queue.d.ts @@ -0,0 +1,4 @@ +declare module '*/common/queue' { + export const queueDraw: any; + export const queueLoadImage: any; +} \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/components/u-qrcode/u-qrcode.vue b/uni_modules/Sansnn-uQRCode/components/u-qrcode/u-qrcode.vue index 8ae7f42..8ae9598 100644 --- a/uni_modules/Sansnn-uQRCode/components/u-qrcode/u-qrcode.vue +++ b/uni_modules/Sansnn-uQRCode/components/u-qrcode/u-qrcode.vue @@ -1,771 +1,1131 @@ - - - + + - - + // #ifdef VUE3 + import { + toRaw + } from 'vue'; + // #endif + + /* 引入uQRCode核心js */ + import UQRCode from '../../js_sdk/uqrcode/uqrcode'; + + /* 引入nvue所需模块 */ + // #ifdef APP-NVUE + import { + enable, + WeexBridge + } from '../../js_sdk/gcanvas'; + const modal = weex.requireModule('modal'); + // #endif + + /* 引入队列 */ + import { + queueDraw, + queueLoadImage + } from '../../common/queue'; + /* 引入缓存图片 */ + import { + cacheImageList + } from '../../common/cache'; + + let instance = null; + + export default { + name: 'uqrcode', + props: { + /** + * canvas组件id + */ + canvasId: { + type: String, + required: true // canvasId在微信小程序初始值不能为空,created中赋值也不行,必须给一个值,否则挂载组件后无法绘制。不考虑用随机id,uuid + }, + /** + * 二维码内容 + */ + value: { + type: [String, Number] + }, + /** + * 选项 + */ + options: { + type: Object, + default: () => { + return {}; + } + }, + /** + * 二维码大小 + */ + size: { + type: [String, Number], + default: 200 + }, + /** + * 二维码尺寸单位 + */ + sizeUnit: { + type: String, + default: 'px' + }, + /** + * 导出的文件类型 + */ + fileType: { + type: String, + default: 'png' + }, + /** + * 是否初始化组件后就开始生成 + */ + start: { + type: Boolean, + default: true + }, + /** + * 是否数据发生改变自动重绘 + */ + auto: { + type: Boolean, + default: true + }, + /** + * 隐藏组件 + */ + hide: { + type: Boolean, + default: false + }, + /** + * canvas 类型,微信小程序默认使用2d,非2d微信官方已放弃维护,问题比较多 + * 注意:微信小程序type2d手机上正常,PC上微信内打开小程序toDataURL报错,看后期微信官方团队会不会做兼容,不兼容的话只能在自行判断在PC使用非2d,或者直接提示用户请在手机上操作,微信团队的海报中心小程序就是这么做的 + */ + type: { + type: String, + default: () => { + // #ifdef MP-WEIXIN + return '2d'; + // #endif + // #ifndef MP-WEIXIN + return 'normal'; + // #endif + } + }, + /** + * 队列绘制,主要针对NVue端 + */ + queue: { + type: Boolean, + default: false + }, + /** + * 是否队列加载图片,可减少canvas发起的网络资源请求,节省服务器资源 + */ + isQueueLoadImage: { + type: Boolean, + default: false + }, + /** + * loading态 + */ + loading: { + type: Boolean, + default: undefined + }, + /** + * H5保存即自动下载(在支持的环境下),默认false为仅弹层提示用户需要长按图片保存,不会自动下载 + */ + h5SaveIsDownload: { + type: Boolean, + default: false + }, + /** + * H5下载名称 + */ + h5DownloadName: { + type: String, + default: 'uQRCode' + } + }, + data() { + return { + canvas: undefined, + canvasType: undefined, + canvasContext: undefined, + makeDelegate: undefined, + drawDelegate: undefined, + toTempFilePathDelegate: undefined, + makeExecuted: false, + makeing: false, + drawing: false, + isError: false, + error: undefined, + isH5Save: false, + tempFilePath: '', + templateOptions: { + size: 0, + width: 0, // 组件宽度 + height: 0, + canvasWidth: 0, // canvas宽度 + canvasHeight: 0, + canvasTransform: '', + canvasDisplay: false + }, + uqrcodeOptions: { + data: '' + }, + plugins: [], + makeingPattern: [ + [ + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true] + ], + [ + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, false, false, false], + [true, true, true, true, true, true, false, true, true, true], + [true, true, true, true, true, true, false, true, true, true], + [true, true, true, true, true, true, false, true, true, true] + ], + [ + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, true, true, true, true, false, false, false], + [true, true, true, true, true, true, true, false, false, false], + [true, true, true, true, true, true, true, false, false, false], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true] + ], + [ + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, false, false, false, false, false, false, false], + [true, true, true, false, false, false, false, false, false, false], + [true, true, true, false, false, false, false, false, false, false], + [true, true, true, false, false, false, false, false, false, false], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true] + ] + ] + }; + }, + watch: { + type: { + handler(val) { + const types = ['2d']; + if (types.includes(val)) { + this.canvasType = val; + } else { + this.canvasType = undefined; + } + }, + immediate: true + }, + value: { + handler() { + if (this.auto) { + this.remake(); + } + } + }, + size: { + handler() { + if (this.auto) { + this.remake(); + } + } + }, + options: { + handler() { + if (this.auto) { + this.remake(); + } + }, + deep: true + }, + makeing: { + handler(val) { + if (!val) { + if (typeof this.toTempFilePathDelegate === 'function') { + this.toTempFilePathDelegate(); + } + } + } + } + }, + mounted() { + this.templateOptions.size = this.sizeUnit == 'rpx' ? uni.upx2px(this.size) : this.size; + this.templateOptions.width = this.templateOptions.size; + this.templateOptions.height = this.templateOptions.size; + this.templateOptions.canvasWidth = this.templateOptions.size; + this.templateOptions.canvasHeight = this.templateOptions.size; + if (this.canvasType == '2d') { + // #ifndef MP-WEIXIN + this.templateOptions.canvasTransform = `scale(${this.templateOptions.size / this.templateOptions.canvasWidth}, ${this.templateOptions.size / + this.templateOptions.canvasHeight})`; + // #endif + } else { + this.templateOptions.canvasTransform = `scale(${this.templateOptions.size / this.templateOptions.canvasWidth}, ${this.templateOptions.size / + this.templateOptions.canvasHeight})`; + } + if (this.start) { + this.make(); + } + }, + methods: { + /** + * 获取模板选项 + */ + getTemplateOptions() { + var size = this.sizeUnit == 'rpx' ? uni.upx2px(this.size) : this.size; + return deepReplace(this.templateOptions, { + size, + width: size, + height: size + }); + }, + /** + * 获取插件选项 + */ + getUqrcodeOptions() { + return deepReplace(this.options, { + data: String(this.value), + size: Number(this.templateOptions.size) + }); + }, + /** + * 重置画布 + */ + resetCanvas(callback) { + this.templateOptions.canvasDisplay = false; + this.$nextTick(() => { + this.templateOptions.canvasDisplay = true; + this.$nextTick(() => { + callback && callback(); + }); + }); + }, + /** + * 绘制二维码 + */ + async draw(callback = {}, isDrawDelegate = false) { + if (typeof callback.success != 'function') { + callback.success = () => {}; + } + if (typeof callback.fail != 'function') { + callback.fail = () => {}; + } + if (typeof callback.complete != 'function') { + callback.complete = () => {}; + } + + if (this.drawing) { + if (!isDrawDelegate) { + this.drawDelegate = () => { + this.draw(callback, true); + }; + return; + } + } else { + this.drawing = true; + } + + if (!this.canvasId) { + console.error('[uQRCode]: canvasId must be set!'); + this.isError = true; + this.drawing = false; + callback.fail({ + errMsg: '[uQRCode]: canvasId must be set!' + }); + callback.complete({ + errMsg: '[uQRCode]: canvasId must be set!' + }); + return; + } + if (!this.value) { + console.error('[uQRCode]: value must be set!'); + this.isError = true; + this.drawing = false; + callback.fail({ + errMsg: '[uQRCode]: value must be set!' + }); + callback.complete({ + errMsg: '[uQRCode]: value must be set!' + }); + return; + } + + /* 组件数据 */ + this.templateOptions = this.getTemplateOptions(); + /* uQRCode选项 */ + this.uqrcodeOptions = this.getUqrcodeOptions(); + /* 纠错等级兼容字母写法 */ + if (typeof this.uqrcodeOptions.errorCorrectLevel === 'string') { + this.uqrcodeOptions.errorCorrectLevel = UQRCode.errorCorrectLevel[this.uqrcodeOptions.errorCorrectLevel]; + } + /* nvue不支持动态修改gcanvas尺寸,除nvue外,默认使用useDynamicSize */ + // #ifndef APP-NVUE + if (typeof this.options.useDynamicSize === 'undefined') { + this.uqrcodeOptions.useDynamicSize = true; + } + // #endif + // #ifdef APP-NVUE + if (typeof this.options.useDynamicSize === 'undefined') { + this.uqrcodeOptions.useDynamicSize = false; + } + // if (typeof this.options.drawReserve === 'undefined') { + // this.uqrcodeOptions.drawReserve = true; + // } + // #endif + + /* 获取uQRCode实例 */ + const qr = instance = new UQRCode(); + /* 注册扩展 */ + this.plugins.forEach(p => qr.register(p.plugin)); + /* 设置uQRCode选项 */ + qr.setOptions(this.uqrcodeOptions); + /* 调用制作二维码方法 */ + qr.make(); + + /* 获取canvas上下文 */ + let canvasContext = null; + // #ifndef APP-NVUE + if (this.canvasType === '2d') { + // #ifdef MP-WEIXIN + /* 微信小程序获取canvas2d上下文方式 */ + const canvas = (this.canvas = await new Promise(resolve => { + uni + .createSelectorQuery() + .in(this) // 在组件内使用需要 + .select(`#${this.canvasId}`) + .fields({ + node: true, + size: true + }) + .exec(res => { + resolve(res[0].node); + }); + })); + canvasContext = this.canvasContext = canvas.getContext('2d'); + /* 2d的组件设置宽高与实际canvas绘制宽高不是一个,打个比方,组件size=200,canvas.width设置为100,那么绘制出来就是100=200,组件size=400,canvas.width设置为800,绘制大小还是800=400,所以无需理会下方返回的dynamicSize是多少,按dpr重新赋值给canvas即可 */ + this.templateOptions.canvasWidth = qr.size; + this.templateOptions.canvasHeight = qr.size; + this.templateOptions.canvasTransform = ''; + /* 使用dynamicSize+scale,可以解决小块间出现白线问题,dpr可以解决模糊问题 */ + const dpr = uni.getSystemInfoSync().pixelRatio; + canvas.width = qr.dynamicSize * dpr; + canvas.height = qr.dynamicSize * dpr; + canvasContext.scale(dpr, dpr); + /* 微信小程序获取图像方式 */ + qr.loadImage = this.getLoadImage(function(src) { + /* 小程序下获取网络图片信息需先配置download域名白名单才能生效 */ + return new Promise((resolve, reject) => { + const img = canvas.createImage(); + img.src = src; + img.onload = () => { + resolve(img); + }; + img.onerror = err => { + reject(err); + }; + }); + }); + // #endif + // #ifndef MP-WEIXIN + /* 非微信小程序不支持2d,切换回uniapp获取canvas上下文方式 */ + canvasContext = this.canvasContext = uni.createCanvasContext(this.canvasId, this); + /* 使用dynamicSize,可以解决小块间出现白线问题,再通过scale缩放至size,使其达到所设尺寸 */ + this.templateOptions.canvasWidth = qr.dynamicSize; + this.templateOptions.canvasHeight = qr.dynamicSize; + this.templateOptions.canvasTransform = `scale(${this.templateOptions.size / this.templateOptions.canvasWidth}, ${this.templateOptions.size / + this.templateOptions.canvasHeight})`; + /* uniapp获取图像方式 */ + qr.loadImage = this.getLoadImage(function(src) { + return new Promise((resolve, reject) => { + if (src.startsWith('http')) { + uni.getImageInfo({ + src, + success: res => { + resolve(res.path); + }, + fail: err => { + reject(err); + } + }); + } else { + if (src.startsWith('.')) { + console.error('[uQRCode]: 本地图片路径仅支持绝对路径!'); + throw new Error('[uQRCode]: local image path only supports absolute path!'); + } else { + resolve(src); + } + } + }); + }); + // #endif + } else { + /* uniapp获取canvas上下文方式 */ + canvasContext = this.canvasContext = uni.createCanvasContext(this.canvasId, this); + /* 使用dynamicSize,可以解决小块间出现白线问题,再通过scale缩放至size,使其达到所设尺寸 */ + this.templateOptions.canvasWidth = qr.dynamicSize; + this.templateOptions.canvasHeight = qr.dynamicSize; + this.templateOptions.canvasTransform = `scale(${this.templateOptions.size / this.templateOptions.canvasWidth}, ${this.templateOptions.size / + this.templateOptions.canvasHeight})`; + /* uniapp获取图像方式 */ + qr.loadImage = this.getLoadImage(function(src) { + return new Promise((resolve, reject) => { + /* getImageInfo在微信小程序的bug:本地路径返回路径会把开头的/或../移除,导致路径错误,解决方法:限制只能使用绝对路径 */ + if (src.startsWith('http')) { + uni.getImageInfo({ + src, + success: res => { + resolve(res.path); + }, + fail: err => { + reject(err); + } + }); + } else { + if (src.startsWith('.')) { + console.error('[uQRCode]: 本地图片路径仅支持绝对路径!'); + throw new Error('[uQRCode]: local image path only supports absolute path!'); + } else { + resolve(src); + } + } + }); + }); + } + // #endif + // #ifdef APP-NVUE + /* NVue获取canvas上下文方式 */ + const gcanvas = this.$refs['gcanvas']; + const canvas = enable(gcanvas, { + bridge: WeexBridge + }); + canvasContext = this.canvasContext = canvas.getContext('2d'); + /* NVue获取图像方式 */ + qr.loadImage = this.getLoadImage(function(src) { + return new Promise((resolve, reject) => { + /* getImageInfo在nvue的bug:获取同一个路径的图片信息,同一时间第一次获取成功,后续失败,猜测是写入本地时产生文件写入冲突,所以没有返回,特别是对于网络资源 --- 已实现队列绘制,已解决此问题 */ + if (src.startsWith('.')) { + console.error('[uQRCode]: 本地图片路径仅支持绝对路径!'); + throw new Error('[uQRCode]: local image path only supports absolute path!'); + } else { + uni.getImageInfo({ + src, + success: res => { + resolve(res.path); + }, + fail: err => { + reject(err); + } + }); + } + }); + }); + // #endif + + /* 设置uQRCode实例的canvas上下文 */ + qr.canvasContext = canvasContext; + /* 延时等待页面重新绘制完毕 */ + setTimeout(() => { + /* 从插件获取具体要调用哪一个扩展函数 */ + var plugin = this.plugins.find(p => p.name == qr.style); + var drawCanvasName = plugin ? plugin.drawCanvas : 'drawCanvas'; + /* 虽然qr[drawCanvasName]是直接返回Promise的,但由于js内部this指向问题,故不能直接exec(qr[drawCanvasName])此方式执行,需要改成exec(() => qr[drawCanvasName]())才能正确获取this */ + var drawCanvas; + if (this.queue) { + drawCanvas = () => queueDraw.exec(() => qr[drawCanvasName]()); + // drawCanvas = () => queueDraw.exec(() => new Promise((resolve, reject) => { + // setTimeout(() => { + // qr[drawCanvasName]().then(resolve).catch(reject); + // }, 1000); + // })); + } else { + drawCanvas = () => qr[drawCanvasName](); + } + /* 调用绘制方法将二维码图案绘制到canvas上 */ + drawCanvas() + .then(() => { + if (this.drawDelegate) { + /* 高频重绘纠正 */ + let delegate = this.drawDelegate; + this.drawDelegate = undefined; + delegate(); + } else { + this.drawing = false; + callback.success(); + } + }) + .catch(err => { + console.log(err); + if (this.drawDelegate) { + /* 高频重绘纠正 */ + let delegate = this.drawDelegate; + this.drawDelegate = undefined; + delegate(); + } else { + this.drawing = false; + this.isError = true; + callback.fail(err); + } + }) + .finally(() => { + callback.complete(); + }); + }, 300); + }, + /** + * 生成二维码 + */ + make(callback = {}) { + this.makeExecuted = true; + this.makeing = true; + this.isError = false; + + if (typeof callback.success != 'function') { + callback.success = () => {}; + } + if (typeof callback.fail != 'function') { + callback.fail = () => {}; + } + if (typeof callback.complete != 'function') { + callback.complete = () => {}; + } + + this.resetCanvas(() => { + clearTimeout(this.makeDelegate); + this.makeDelegate = setTimeout(() => { + this.draw({ + success: () => { + setTimeout(() => { + callback.success(); + this.complete(true); + }, 300); + }, + fail: err => { + callback.fail(err); + this.error = err; + this.complete(false, err.errMsg); + }, + complete: () => { + callback.complete(); + this.makeing = false; + } + }); + }, 300); + }); + }, + /** + * 重新生成 + */ + remake(callback) { + this.$emit('change'); + this.make(callback); + }, + /** + * 生成完成 + */ + complete(success = true, errMsg = '') { + if (success) { + this.$emit('complete', { + success + }); + } else { + this.$emit('complete', { + success, + errMsg + }); + } + }, + /** + * 导出临时路径 + */ + toTempFilePath(callback = {}) { + if (typeof callback.success != 'function') { + callback.success = () => {}; + } + if (typeof callback.fail != 'function') { + callback.fail = () => {}; + } + if (typeof callback.complete != 'function') { + callback.complete = () => {}; + } + + if (!this.makeExecuted) { + console.error('[uQRCode]: make() 方法从未调用!请先成功调用 make() 后再进行操作。'); + var err = { + errMsg: '[uQRCode]: make() method has never been executed! please execute make() successfully before operating.' + }; + callback.fail(err); + callback.complete(err); + return; + } + + if (this.isError) { + callback.fail(this.error); + callback.complete(this.error); + return; + } + + if (this.makeing) { + /* 如果还在生成状态,那当前操作将托管到委托,监听生成完成后再通过委托复调当前方法 */ + this.toTempFilePathDelegate = () => { + this.toTempFilePath(callback); + }; + return; + } else { + this.toTempFilePathDelegate = null; + } + + // #ifndef APP-NVUE + if (this.canvasType === '2d') { + // #ifdef MP-WEIXIN + try { + let dataURL = null; + // #ifdef VUE3 + dataURL = toRaw(this.canvas) + .toDataURL(); + // #endif + // #ifndef VUE3 + dataURL = this.canvas.toDataURL(); + // #endif + callback.success({ + tempFilePath: dataURL + }); + callback.complete({ + tempFilePath: dataURL + }); + } catch (e) { + callback.fail(e); + callback.complete(e); + } + // #endif + } else { + uni.canvasToTempFilePath({ + canvasId: this.canvasId, + fileType: this.fileType, + width: Number(this.templateOptions.canvasWidth), + height: Number(this.templateOptions.canvasHeight), + destWidth: Number(this.templateOptions.size), + destHeight: Number(this.templateOptions.size), + success: res => { + callback.success(res); + }, + fail: err => { + callback.fail(err); + }, + complete: () => { + callback.complete(); + } + }, + this + ); + } + // #endif + // #ifdef APP-NVUE + const dpr = uni.getSystemInfoSync().pixelRatio; + this.canvasContext.toTempFilePath( + 0, + 0, + this.templateOptions.canvasWidth * dpr, + this.templateOptions.canvasHeight * dpr, + this.templateOptions.size * dpr, + this.templateOptions.size * dpr, + '', + 1, + res => { + callback.success(res); + callback.complete(res); + } + ); + // #endif + }, + /** + * 保存 + */ + save(callback = {}) { + if (typeof callback.success != 'function') { + callback.success = () => {}; + } + if (typeof callback.fail != 'function') { + callback.fail = () => {}; + } + if (typeof callback.complete != 'function') { + callback.complete = () => {}; + } + + this.toTempFilePath({ + success: res => { + // #ifndef H5 + if (this.canvasType === '2d') { + // #ifdef MP-WEIXIN + /* 需要将 data:image/png;base64, 这段去除 writeFile 才能正常打开文件,否则是损坏文件,无法打开 */ + const reg = new RegExp('^data:image/png;base64,', 'g'); + const dataURL = res.tempFilePath.replace(reg, ''); + const fs = wx.getFileSystemManager(); + const tempFilePath = `${wx.env.USER_DATA_PATH}/${new Date().getTime()}${ + Math.random() + .toString() + .split('.')[1] + }.png`; + fs.writeFile({ + filePath: tempFilePath, // 要写入的文件路径 (本地路径) + data: dataURL, // base64图片 + encoding: 'base64', + success: res1 => { + uni.saveImageToPhotosAlbum({ + filePath: tempFilePath, + success: res2 => { + callback.success(res2); + }, + fail: err2 => { + callback.fail(err2); + }, + complete: () => { + callback.complete(); + } + }); + }, + fail: err => { + callback.fail(err); + }, + complete: () => { + callback.complete(); + } + }); + // #endif + } else { + uni.saveImageToPhotosAlbum({ + filePath: res.tempFilePath, + success: res1 => { + callback.success(res1); + }, + fail: err1 => { + callback.fail(err1); + }, + complete: () => { + callback.complete(); + } + }); + } + // #endif + + // #ifdef H5 + /* 可以在电脑浏览器下载,移动端iOS不行,安卓微信浏览器不行,安卓外部浏览器可以 */ + this.isH5Save = true; + this.tempFilePath = res.tempFilePath; + if (this.h5SaveIsDownload) { + const aEle = document.createElement('a'); + aEle.download = this.h5DownloadName; // 设置下载的文件名,默认是'下载' + aEle.href = res.tempFilePath; + document.body.appendChild(aEle); + aEle.click(); + aEle.remove(); // 下载之后把创建的元素删除 + } + callback.success({ + errMsg: 'ok' + }); + callback.complete({ + errMsg: 'ok' + }); + // #endif + }, + fail: err => { + callback.fail(err); + callback.complete(err); + } + }); + }, + /** + * 注册click事件 + */ + onClick(e) { + this.$emit('click', e); + }, + /** + * 获取实例 + */ + getInstance() { + return instance; + }, + /** + * 注册扩展,组件仅支持注册type为style的drawCanvas扩展 + * @param {Object} plugin + */ + registerStyle(plugin) { + if (plugin.Type != 'style') { + console.warn('[uQRCode]: registerStyle 仅支持注册 style 类型的扩展!'); + return { + errMsg: 'registerStyle 仅支持注册 style 类型的扩展!' + }; + } + if (typeof plugin === 'function') { + this.plugins.push({ + plugin, + name: plugin.Name, + drawCanvas: plugin.DrawCanvas + }); + } + }, + getLoadImage(loadImage) { + var that = this; + if (typeof loadImage == 'function') { + return function(src) { + /* 判断是否是队列加载图片的 */ + if (that.isQueueLoadImage) { + /* 解决iOS APP||NVUE同时绘制多个二维码导致图片丢失需使用队列 */ + return queueLoadImage.exec(() => { + return new Promise((resolve, reject) => { + setTimeout(() => { + const cache = cacheImageList.find(x => x.src == src); + if (cache) { + resolve(cache.img); + } else { + loadImage(src) + .then(img => { + cacheImageList.push({ + src, + img + }); + resolve(img); + }) + .catch(err => { + reject(err); + }); + } + }, 10); + }); + }); + } else { + return loadImage(src); + } + }; + } else { + return function(src) { + return Promise.resolve(src); + }; + } + } + } + }; + + /** + * 对象属性深度替换 + * @param {Object} o 原始对象/默认对象/被替换的对象 + * @param {Object} r 从这个对象里取值替换到o对象里 + * @return {Object} 替换后的新对象 + */ + function deepReplace(o = {}, r = {}, c = false) { + let obj; + if (c) { + // 从源替换 + obj = o; + } else { + // 不替换源,copy一份备份来替换 + obj = { + ...o + }; + } + for (let k in r) { + var vr = r[k]; + if (vr != undefined) { + if (vr.constructor == Object) { + obj[k] = this.deepReplace(obj[k], vr); + } else if (vr.constructor == String && !vr) { + obj[k] = obj[k]; + } else { + obj[k] = vr; + } + } + } + return obj; + } + + + diff --git a/uni_modules/Sansnn-uQRCode/components/uqrcode/uqrcode.vue b/uni_modules/Sansnn-uQRCode/components/uqrcode/uqrcode.vue index 8ae7f42..8ae9598 100644 --- a/uni_modules/Sansnn-uQRCode/components/uqrcode/uqrcode.vue +++ b/uni_modules/Sansnn-uQRCode/components/uqrcode/uqrcode.vue @@ -1,771 +1,1131 @@ - - - + + - - + // #ifdef VUE3 + import { + toRaw + } from 'vue'; + // #endif + + /* 引入uQRCode核心js */ + import UQRCode from '../../js_sdk/uqrcode/uqrcode'; + + /* 引入nvue所需模块 */ + // #ifdef APP-NVUE + import { + enable, + WeexBridge + } from '../../js_sdk/gcanvas'; + const modal = weex.requireModule('modal'); + // #endif + + /* 引入队列 */ + import { + queueDraw, + queueLoadImage + } from '../../common/queue'; + /* 引入缓存图片 */ + import { + cacheImageList + } from '../../common/cache'; + + let instance = null; + + export default { + name: 'uqrcode', + props: { + /** + * canvas组件id + */ + canvasId: { + type: String, + required: true // canvasId在微信小程序初始值不能为空,created中赋值也不行,必须给一个值,否则挂载组件后无法绘制。不考虑用随机id,uuid + }, + /** + * 二维码内容 + */ + value: { + type: [String, Number] + }, + /** + * 选项 + */ + options: { + type: Object, + default: () => { + return {}; + } + }, + /** + * 二维码大小 + */ + size: { + type: [String, Number], + default: 200 + }, + /** + * 二维码尺寸单位 + */ + sizeUnit: { + type: String, + default: 'px' + }, + /** + * 导出的文件类型 + */ + fileType: { + type: String, + default: 'png' + }, + /** + * 是否初始化组件后就开始生成 + */ + start: { + type: Boolean, + default: true + }, + /** + * 是否数据发生改变自动重绘 + */ + auto: { + type: Boolean, + default: true + }, + /** + * 隐藏组件 + */ + hide: { + type: Boolean, + default: false + }, + /** + * canvas 类型,微信小程序默认使用2d,非2d微信官方已放弃维护,问题比较多 + * 注意:微信小程序type2d手机上正常,PC上微信内打开小程序toDataURL报错,看后期微信官方团队会不会做兼容,不兼容的话只能在自行判断在PC使用非2d,或者直接提示用户请在手机上操作,微信团队的海报中心小程序就是这么做的 + */ + type: { + type: String, + default: () => { + // #ifdef MP-WEIXIN + return '2d'; + // #endif + // #ifndef MP-WEIXIN + return 'normal'; + // #endif + } + }, + /** + * 队列绘制,主要针对NVue端 + */ + queue: { + type: Boolean, + default: false + }, + /** + * 是否队列加载图片,可减少canvas发起的网络资源请求,节省服务器资源 + */ + isQueueLoadImage: { + type: Boolean, + default: false + }, + /** + * loading态 + */ + loading: { + type: Boolean, + default: undefined + }, + /** + * H5保存即自动下载(在支持的环境下),默认false为仅弹层提示用户需要长按图片保存,不会自动下载 + */ + h5SaveIsDownload: { + type: Boolean, + default: false + }, + /** + * H5下载名称 + */ + h5DownloadName: { + type: String, + default: 'uQRCode' + } + }, + data() { + return { + canvas: undefined, + canvasType: undefined, + canvasContext: undefined, + makeDelegate: undefined, + drawDelegate: undefined, + toTempFilePathDelegate: undefined, + makeExecuted: false, + makeing: false, + drawing: false, + isError: false, + error: undefined, + isH5Save: false, + tempFilePath: '', + templateOptions: { + size: 0, + width: 0, // 组件宽度 + height: 0, + canvasWidth: 0, // canvas宽度 + canvasHeight: 0, + canvasTransform: '', + canvasDisplay: false + }, + uqrcodeOptions: { + data: '' + }, + plugins: [], + makeingPattern: [ + [ + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true] + ], + [ + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, false, false, false], + [true, true, true, true, true, true, false, true, true, true], + [true, true, true, true, true, true, false, true, true, true], + [true, true, true, true, true, true, false, true, true, true] + ], + [ + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, true, true, true, true, false, false, false], + [true, true, true, true, true, true, true, false, false, false], + [true, true, true, true, true, true, true, false, false, false], + [true, true, true, false, false, false, false, true, true, true], + [true, true, true, false, false, false, false, true, true, true] + ], + [ + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, false, false, false, false, false, false, false], + [true, true, true, false, false, false, false, false, false, false], + [true, true, true, false, false, false, false, false, false, false], + [true, true, true, false, false, false, false, false, false, false], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true] + ] + ] + }; + }, + watch: { + type: { + handler(val) { + const types = ['2d']; + if (types.includes(val)) { + this.canvasType = val; + } else { + this.canvasType = undefined; + } + }, + immediate: true + }, + value: { + handler() { + if (this.auto) { + this.remake(); + } + } + }, + size: { + handler() { + if (this.auto) { + this.remake(); + } + } + }, + options: { + handler() { + if (this.auto) { + this.remake(); + } + }, + deep: true + }, + makeing: { + handler(val) { + if (!val) { + if (typeof this.toTempFilePathDelegate === 'function') { + this.toTempFilePathDelegate(); + } + } + } + } + }, + mounted() { + this.templateOptions.size = this.sizeUnit == 'rpx' ? uni.upx2px(this.size) : this.size; + this.templateOptions.width = this.templateOptions.size; + this.templateOptions.height = this.templateOptions.size; + this.templateOptions.canvasWidth = this.templateOptions.size; + this.templateOptions.canvasHeight = this.templateOptions.size; + if (this.canvasType == '2d') { + // #ifndef MP-WEIXIN + this.templateOptions.canvasTransform = `scale(${this.templateOptions.size / this.templateOptions.canvasWidth}, ${this.templateOptions.size / + this.templateOptions.canvasHeight})`; + // #endif + } else { + this.templateOptions.canvasTransform = `scale(${this.templateOptions.size / this.templateOptions.canvasWidth}, ${this.templateOptions.size / + this.templateOptions.canvasHeight})`; + } + if (this.start) { + this.make(); + } + }, + methods: { + /** + * 获取模板选项 + */ + getTemplateOptions() { + var size = this.sizeUnit == 'rpx' ? uni.upx2px(this.size) : this.size; + return deepReplace(this.templateOptions, { + size, + width: size, + height: size + }); + }, + /** + * 获取插件选项 + */ + getUqrcodeOptions() { + return deepReplace(this.options, { + data: String(this.value), + size: Number(this.templateOptions.size) + }); + }, + /** + * 重置画布 + */ + resetCanvas(callback) { + this.templateOptions.canvasDisplay = false; + this.$nextTick(() => { + this.templateOptions.canvasDisplay = true; + this.$nextTick(() => { + callback && callback(); + }); + }); + }, + /** + * 绘制二维码 + */ + async draw(callback = {}, isDrawDelegate = false) { + if (typeof callback.success != 'function') { + callback.success = () => {}; + } + if (typeof callback.fail != 'function') { + callback.fail = () => {}; + } + if (typeof callback.complete != 'function') { + callback.complete = () => {}; + } + + if (this.drawing) { + if (!isDrawDelegate) { + this.drawDelegate = () => { + this.draw(callback, true); + }; + return; + } + } else { + this.drawing = true; + } + + if (!this.canvasId) { + console.error('[uQRCode]: canvasId must be set!'); + this.isError = true; + this.drawing = false; + callback.fail({ + errMsg: '[uQRCode]: canvasId must be set!' + }); + callback.complete({ + errMsg: '[uQRCode]: canvasId must be set!' + }); + return; + } + if (!this.value) { + console.error('[uQRCode]: value must be set!'); + this.isError = true; + this.drawing = false; + callback.fail({ + errMsg: '[uQRCode]: value must be set!' + }); + callback.complete({ + errMsg: '[uQRCode]: value must be set!' + }); + return; + } + + /* 组件数据 */ + this.templateOptions = this.getTemplateOptions(); + /* uQRCode选项 */ + this.uqrcodeOptions = this.getUqrcodeOptions(); + /* 纠错等级兼容字母写法 */ + if (typeof this.uqrcodeOptions.errorCorrectLevel === 'string') { + this.uqrcodeOptions.errorCorrectLevel = UQRCode.errorCorrectLevel[this.uqrcodeOptions.errorCorrectLevel]; + } + /* nvue不支持动态修改gcanvas尺寸,除nvue外,默认使用useDynamicSize */ + // #ifndef APP-NVUE + if (typeof this.options.useDynamicSize === 'undefined') { + this.uqrcodeOptions.useDynamicSize = true; + } + // #endif + // #ifdef APP-NVUE + if (typeof this.options.useDynamicSize === 'undefined') { + this.uqrcodeOptions.useDynamicSize = false; + } + // if (typeof this.options.drawReserve === 'undefined') { + // this.uqrcodeOptions.drawReserve = true; + // } + // #endif + + /* 获取uQRCode实例 */ + const qr = instance = new UQRCode(); + /* 注册扩展 */ + this.plugins.forEach(p => qr.register(p.plugin)); + /* 设置uQRCode选项 */ + qr.setOptions(this.uqrcodeOptions); + /* 调用制作二维码方法 */ + qr.make(); + + /* 获取canvas上下文 */ + let canvasContext = null; + // #ifndef APP-NVUE + if (this.canvasType === '2d') { + // #ifdef MP-WEIXIN + /* 微信小程序获取canvas2d上下文方式 */ + const canvas = (this.canvas = await new Promise(resolve => { + uni + .createSelectorQuery() + .in(this) // 在组件内使用需要 + .select(`#${this.canvasId}`) + .fields({ + node: true, + size: true + }) + .exec(res => { + resolve(res[0].node); + }); + })); + canvasContext = this.canvasContext = canvas.getContext('2d'); + /* 2d的组件设置宽高与实际canvas绘制宽高不是一个,打个比方,组件size=200,canvas.width设置为100,那么绘制出来就是100=200,组件size=400,canvas.width设置为800,绘制大小还是800=400,所以无需理会下方返回的dynamicSize是多少,按dpr重新赋值给canvas即可 */ + this.templateOptions.canvasWidth = qr.size; + this.templateOptions.canvasHeight = qr.size; + this.templateOptions.canvasTransform = ''; + /* 使用dynamicSize+scale,可以解决小块间出现白线问题,dpr可以解决模糊问题 */ + const dpr = uni.getSystemInfoSync().pixelRatio; + canvas.width = qr.dynamicSize * dpr; + canvas.height = qr.dynamicSize * dpr; + canvasContext.scale(dpr, dpr); + /* 微信小程序获取图像方式 */ + qr.loadImage = this.getLoadImage(function(src) { + /* 小程序下获取网络图片信息需先配置download域名白名单才能生效 */ + return new Promise((resolve, reject) => { + const img = canvas.createImage(); + img.src = src; + img.onload = () => { + resolve(img); + }; + img.onerror = err => { + reject(err); + }; + }); + }); + // #endif + // #ifndef MP-WEIXIN + /* 非微信小程序不支持2d,切换回uniapp获取canvas上下文方式 */ + canvasContext = this.canvasContext = uni.createCanvasContext(this.canvasId, this); + /* 使用dynamicSize,可以解决小块间出现白线问题,再通过scale缩放至size,使其达到所设尺寸 */ + this.templateOptions.canvasWidth = qr.dynamicSize; + this.templateOptions.canvasHeight = qr.dynamicSize; + this.templateOptions.canvasTransform = `scale(${this.templateOptions.size / this.templateOptions.canvasWidth}, ${this.templateOptions.size / + this.templateOptions.canvasHeight})`; + /* uniapp获取图像方式 */ + qr.loadImage = this.getLoadImage(function(src) { + return new Promise((resolve, reject) => { + if (src.startsWith('http')) { + uni.getImageInfo({ + src, + success: res => { + resolve(res.path); + }, + fail: err => { + reject(err); + } + }); + } else { + if (src.startsWith('.')) { + console.error('[uQRCode]: 本地图片路径仅支持绝对路径!'); + throw new Error('[uQRCode]: local image path only supports absolute path!'); + } else { + resolve(src); + } + } + }); + }); + // #endif + } else { + /* uniapp获取canvas上下文方式 */ + canvasContext = this.canvasContext = uni.createCanvasContext(this.canvasId, this); + /* 使用dynamicSize,可以解决小块间出现白线问题,再通过scale缩放至size,使其达到所设尺寸 */ + this.templateOptions.canvasWidth = qr.dynamicSize; + this.templateOptions.canvasHeight = qr.dynamicSize; + this.templateOptions.canvasTransform = `scale(${this.templateOptions.size / this.templateOptions.canvasWidth}, ${this.templateOptions.size / + this.templateOptions.canvasHeight})`; + /* uniapp获取图像方式 */ + qr.loadImage = this.getLoadImage(function(src) { + return new Promise((resolve, reject) => { + /* getImageInfo在微信小程序的bug:本地路径返回路径会把开头的/或../移除,导致路径错误,解决方法:限制只能使用绝对路径 */ + if (src.startsWith('http')) { + uni.getImageInfo({ + src, + success: res => { + resolve(res.path); + }, + fail: err => { + reject(err); + } + }); + } else { + if (src.startsWith('.')) { + console.error('[uQRCode]: 本地图片路径仅支持绝对路径!'); + throw new Error('[uQRCode]: local image path only supports absolute path!'); + } else { + resolve(src); + } + } + }); + }); + } + // #endif + // #ifdef APP-NVUE + /* NVue获取canvas上下文方式 */ + const gcanvas = this.$refs['gcanvas']; + const canvas = enable(gcanvas, { + bridge: WeexBridge + }); + canvasContext = this.canvasContext = canvas.getContext('2d'); + /* NVue获取图像方式 */ + qr.loadImage = this.getLoadImage(function(src) { + return new Promise((resolve, reject) => { + /* getImageInfo在nvue的bug:获取同一个路径的图片信息,同一时间第一次获取成功,后续失败,猜测是写入本地时产生文件写入冲突,所以没有返回,特别是对于网络资源 --- 已实现队列绘制,已解决此问题 */ + if (src.startsWith('.')) { + console.error('[uQRCode]: 本地图片路径仅支持绝对路径!'); + throw new Error('[uQRCode]: local image path only supports absolute path!'); + } else { + uni.getImageInfo({ + src, + success: res => { + resolve(res.path); + }, + fail: err => { + reject(err); + } + }); + } + }); + }); + // #endif + + /* 设置uQRCode实例的canvas上下文 */ + qr.canvasContext = canvasContext; + /* 延时等待页面重新绘制完毕 */ + setTimeout(() => { + /* 从插件获取具体要调用哪一个扩展函数 */ + var plugin = this.plugins.find(p => p.name == qr.style); + var drawCanvasName = plugin ? plugin.drawCanvas : 'drawCanvas'; + /* 虽然qr[drawCanvasName]是直接返回Promise的,但由于js内部this指向问题,故不能直接exec(qr[drawCanvasName])此方式执行,需要改成exec(() => qr[drawCanvasName]())才能正确获取this */ + var drawCanvas; + if (this.queue) { + drawCanvas = () => queueDraw.exec(() => qr[drawCanvasName]()); + // drawCanvas = () => queueDraw.exec(() => new Promise((resolve, reject) => { + // setTimeout(() => { + // qr[drawCanvasName]().then(resolve).catch(reject); + // }, 1000); + // })); + } else { + drawCanvas = () => qr[drawCanvasName](); + } + /* 调用绘制方法将二维码图案绘制到canvas上 */ + drawCanvas() + .then(() => { + if (this.drawDelegate) { + /* 高频重绘纠正 */ + let delegate = this.drawDelegate; + this.drawDelegate = undefined; + delegate(); + } else { + this.drawing = false; + callback.success(); + } + }) + .catch(err => { + console.log(err); + if (this.drawDelegate) { + /* 高频重绘纠正 */ + let delegate = this.drawDelegate; + this.drawDelegate = undefined; + delegate(); + } else { + this.drawing = false; + this.isError = true; + callback.fail(err); + } + }) + .finally(() => { + callback.complete(); + }); + }, 300); + }, + /** + * 生成二维码 + */ + make(callback = {}) { + this.makeExecuted = true; + this.makeing = true; + this.isError = false; + + if (typeof callback.success != 'function') { + callback.success = () => {}; + } + if (typeof callback.fail != 'function') { + callback.fail = () => {}; + } + if (typeof callback.complete != 'function') { + callback.complete = () => {}; + } + + this.resetCanvas(() => { + clearTimeout(this.makeDelegate); + this.makeDelegate = setTimeout(() => { + this.draw({ + success: () => { + setTimeout(() => { + callback.success(); + this.complete(true); + }, 300); + }, + fail: err => { + callback.fail(err); + this.error = err; + this.complete(false, err.errMsg); + }, + complete: () => { + callback.complete(); + this.makeing = false; + } + }); + }, 300); + }); + }, + /** + * 重新生成 + */ + remake(callback) { + this.$emit('change'); + this.make(callback); + }, + /** + * 生成完成 + */ + complete(success = true, errMsg = '') { + if (success) { + this.$emit('complete', { + success + }); + } else { + this.$emit('complete', { + success, + errMsg + }); + } + }, + /** + * 导出临时路径 + */ + toTempFilePath(callback = {}) { + if (typeof callback.success != 'function') { + callback.success = () => {}; + } + if (typeof callback.fail != 'function') { + callback.fail = () => {}; + } + if (typeof callback.complete != 'function') { + callback.complete = () => {}; + } + + if (!this.makeExecuted) { + console.error('[uQRCode]: make() 方法从未调用!请先成功调用 make() 后再进行操作。'); + var err = { + errMsg: '[uQRCode]: make() method has never been executed! please execute make() successfully before operating.' + }; + callback.fail(err); + callback.complete(err); + return; + } + + if (this.isError) { + callback.fail(this.error); + callback.complete(this.error); + return; + } + + if (this.makeing) { + /* 如果还在生成状态,那当前操作将托管到委托,监听生成完成后再通过委托复调当前方法 */ + this.toTempFilePathDelegate = () => { + this.toTempFilePath(callback); + }; + return; + } else { + this.toTempFilePathDelegate = null; + } + + // #ifndef APP-NVUE + if (this.canvasType === '2d') { + // #ifdef MP-WEIXIN + try { + let dataURL = null; + // #ifdef VUE3 + dataURL = toRaw(this.canvas) + .toDataURL(); + // #endif + // #ifndef VUE3 + dataURL = this.canvas.toDataURL(); + // #endif + callback.success({ + tempFilePath: dataURL + }); + callback.complete({ + tempFilePath: dataURL + }); + } catch (e) { + callback.fail(e); + callback.complete(e); + } + // #endif + } else { + uni.canvasToTempFilePath({ + canvasId: this.canvasId, + fileType: this.fileType, + width: Number(this.templateOptions.canvasWidth), + height: Number(this.templateOptions.canvasHeight), + destWidth: Number(this.templateOptions.size), + destHeight: Number(this.templateOptions.size), + success: res => { + callback.success(res); + }, + fail: err => { + callback.fail(err); + }, + complete: () => { + callback.complete(); + } + }, + this + ); + } + // #endif + // #ifdef APP-NVUE + const dpr = uni.getSystemInfoSync().pixelRatio; + this.canvasContext.toTempFilePath( + 0, + 0, + this.templateOptions.canvasWidth * dpr, + this.templateOptions.canvasHeight * dpr, + this.templateOptions.size * dpr, + this.templateOptions.size * dpr, + '', + 1, + res => { + callback.success(res); + callback.complete(res); + } + ); + // #endif + }, + /** + * 保存 + */ + save(callback = {}) { + if (typeof callback.success != 'function') { + callback.success = () => {}; + } + if (typeof callback.fail != 'function') { + callback.fail = () => {}; + } + if (typeof callback.complete != 'function') { + callback.complete = () => {}; + } + + this.toTempFilePath({ + success: res => { + // #ifndef H5 + if (this.canvasType === '2d') { + // #ifdef MP-WEIXIN + /* 需要将 data:image/png;base64, 这段去除 writeFile 才能正常打开文件,否则是损坏文件,无法打开 */ + const reg = new RegExp('^data:image/png;base64,', 'g'); + const dataURL = res.tempFilePath.replace(reg, ''); + const fs = wx.getFileSystemManager(); + const tempFilePath = `${wx.env.USER_DATA_PATH}/${new Date().getTime()}${ + Math.random() + .toString() + .split('.')[1] + }.png`; + fs.writeFile({ + filePath: tempFilePath, // 要写入的文件路径 (本地路径) + data: dataURL, // base64图片 + encoding: 'base64', + success: res1 => { + uni.saveImageToPhotosAlbum({ + filePath: tempFilePath, + success: res2 => { + callback.success(res2); + }, + fail: err2 => { + callback.fail(err2); + }, + complete: () => { + callback.complete(); + } + }); + }, + fail: err => { + callback.fail(err); + }, + complete: () => { + callback.complete(); + } + }); + // #endif + } else { + uni.saveImageToPhotosAlbum({ + filePath: res.tempFilePath, + success: res1 => { + callback.success(res1); + }, + fail: err1 => { + callback.fail(err1); + }, + complete: () => { + callback.complete(); + } + }); + } + // #endif + + // #ifdef H5 + /* 可以在电脑浏览器下载,移动端iOS不行,安卓微信浏览器不行,安卓外部浏览器可以 */ + this.isH5Save = true; + this.tempFilePath = res.tempFilePath; + if (this.h5SaveIsDownload) { + const aEle = document.createElement('a'); + aEle.download = this.h5DownloadName; // 设置下载的文件名,默认是'下载' + aEle.href = res.tempFilePath; + document.body.appendChild(aEle); + aEle.click(); + aEle.remove(); // 下载之后把创建的元素删除 + } + callback.success({ + errMsg: 'ok' + }); + callback.complete({ + errMsg: 'ok' + }); + // #endif + }, + fail: err => { + callback.fail(err); + callback.complete(err); + } + }); + }, + /** + * 注册click事件 + */ + onClick(e) { + this.$emit('click', e); + }, + /** + * 获取实例 + */ + getInstance() { + return instance; + }, + /** + * 注册扩展,组件仅支持注册type为style的drawCanvas扩展 + * @param {Object} plugin + */ + registerStyle(plugin) { + if (plugin.Type != 'style') { + console.warn('[uQRCode]: registerStyle 仅支持注册 style 类型的扩展!'); + return { + errMsg: 'registerStyle 仅支持注册 style 类型的扩展!' + }; + } + if (typeof plugin === 'function') { + this.plugins.push({ + plugin, + name: plugin.Name, + drawCanvas: plugin.DrawCanvas + }); + } + }, + getLoadImage(loadImage) { + var that = this; + if (typeof loadImage == 'function') { + return function(src) { + /* 判断是否是队列加载图片的 */ + if (that.isQueueLoadImage) { + /* 解决iOS APP||NVUE同时绘制多个二维码导致图片丢失需使用队列 */ + return queueLoadImage.exec(() => { + return new Promise((resolve, reject) => { + setTimeout(() => { + const cache = cacheImageList.find(x => x.src == src); + if (cache) { + resolve(cache.img); + } else { + loadImage(src) + .then(img => { + cacheImageList.push({ + src, + img + }); + resolve(img); + }) + .catch(err => { + reject(err); + }); + } + }, 10); + }); + }); + } else { + return loadImage(src); + } + }; + } else { + return function(src) { + return Promise.resolve(src); + }; + } + } + } + }; + + /** + * 对象属性深度替换 + * @param {Object} o 原始对象/默认对象/被替换的对象 + * @param {Object} r 从这个对象里取值替换到o对象里 + * @return {Object} 替换后的新对象 + */ + function deepReplace(o = {}, r = {}, c = false) { + let obj; + if (c) { + // 从源替换 + obj = o; + } else { + // 不替换源,copy一份备份来替换 + obj = { + ...o + }; + } + for (let k in r) { + var vr = r[k]; + if (vr != undefined) { + if (vr.constructor == Object) { + obj[k] = this.deepReplace(obj[k], vr); + } else if (vr.constructor == String && !vr) { + obj[k] = obj[k]; + } else { + obj[k] = vr; + } + } + } + return obj; + } + + + diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/bridge/bridge-weex.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/bridge/bridge-weex.js index 27086ec..cec30ab 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/bridge/bridge-weex.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/bridge/bridge-weex.js @@ -1,241 +1,241 @@ -const isWeex = typeof WXEnvironment !== 'undefined'; -const isWeexIOS = isWeex && /ios/i.test(WXEnvironment.platform); -const isWeexAndroid = isWeex && !isWeexIOS; - -import GLmethod from '../context-webgl/GLmethod'; - -const GCanvasModule = - (typeof weex !== 'undefined' && weex.requireModule) ? (weex.requireModule('gcanvas')) : - (typeof __weex_require__ !== 'undefined') ? (__weex_require__('@weex-module/gcanvas')) : {}; - -let isDebugging = false; - -let isComboDisabled = false; - -const logCommand = (function () { - const methodQuery = []; - Object.keys(GLmethod).forEach(key => { - methodQuery[GLmethod[key]] = key; - }) - const queryMethod = (id) => { - return methodQuery[parseInt(id)] || 'NotFoundMethod'; - } - const logCommand = (id, cmds) => { - const mId = cmds.split(',')[0]; - const mName = queryMethod(mId); - console.log(`=== callNative - componentId:${id}; method: ${mName}; cmds: ${cmds}`); - } - return logCommand; -})(); - -function joinArray(arr, sep) { - let res = ''; - for (let i = 0; i < arr.length; i++) { - if (i !== 0) { - res += sep; - } - res += arr[i]; - } - return res; -} - -const commandsCache = {} - -const GBridge = { - - callEnable: (ref, configArray) => { - - commandsCache[ref] = []; - - return GCanvasModule.enable({ - componentId: ref, - config: configArray - }); - }, - - callEnableDebug: () => { - isDebugging = true; - }, - - callEnableDisableCombo: () => { - isComboDisabled = true; - }, - - callSetContextType: function (componentId, context_type) { - GCanvasModule.setContextType(context_type, componentId); - }, - - callReset: function(id){ - GCanvasModule.resetComponent && canvasModule.resetComponent(componentId); - }, - - render: isWeexIOS ? function (componentId) { - return GCanvasModule.extendCallNative({ - contextId: componentId, - type: 0x60000001 - }); - } : function (componentId) { - return callGCanvasLinkNative(componentId, 0x60000001, 'render'); - }, - - render2d: isWeexIOS ? function (componentId, commands, callback) { - - if (isDebugging) { - console.log('>>> >>> render2d ==='); - console.log('>>> commands: ' + commands); - } - - GCanvasModule.render([commands, callback?true:false], componentId, callback); - - } : function (componentId, commands,callback) { - - if (isDebugging) { - console.log('>>> >>> render2d ==='); - console.log('>>> commands: ' + commands); - } - - callGCanvasLinkNative(componentId, 0x20000001, commands); - if(callback){ - callback(); - } - }, - - callExtendCallNative: isWeexIOS ? function (componentId, cmdArgs) { - - throw 'should not be here anymore ' + cmdArgs; - - } : function (componentId, cmdArgs) { - - throw 'should not be here anymore ' + cmdArgs; - - }, - - - flushNative: isWeexIOS ? function (componentId) { - - const cmdArgs = joinArray(commandsCache[componentId], ';'); - commandsCache[componentId] = []; - - if (isDebugging) { - console.log('>>> >>> flush native ==='); - console.log('>>> commands: ' + cmdArgs); - } - - const result = GCanvasModule.extendCallNative({ - "contextId": componentId, - "type": 0x60000000, - "args": cmdArgs - }); - - const res = result && result.result; - - if (isDebugging) { - console.log('>>> result: ' + res); - } - - return res; - - } : function (componentId) { - - const cmdArgs = joinArray(commandsCache[componentId], ';'); - commandsCache[componentId] = []; - - if (isDebugging) { - console.log('>>> >>> flush native ==='); - console.log('>>> commands: ' + cmdArgs); - } - - const result = callGCanvasLinkNative(componentId, 0x60000000, cmdArgs); - - if (isDebugging) { - console.log('>>> result: ' + result); - } - - return result; - }, - - callNative: function (componentId, cmdArgs, cache) { - - if (isDebugging) { - logCommand(componentId, cmdArgs); - } - - commandsCache[componentId].push(cmdArgs); - - if (!cache || isComboDisabled) { - return GBridge.flushNative(componentId); - } else { - return undefined; - } - }, - - texImage2D(componentId, ...args) { - if (isWeexIOS) { - if (args.length === 6) { - const [target, level, internalformat, format, type, image] = args; - GBridge.callNative( - componentId, - GLmethod.texImage2D + ',' + 6 + ',' + target + ',' + level + ',' + internalformat + ',' + format + ',' + type + ',' + image.src - ) - } else if (args.length === 9) { - const [target, level, internalformat, width, height, border, format, type, image] = args; - GBridge.callNative( - componentId, - GLmethod.texImage2D + ',' + 9 + ',' + target + ',' + level + ',' + internalformat + ',' + width + ',' + height + ',' + border + ',' + - + format + ',' + type + ',' + (image ? image.src : 0) - ) - } - } else if (isWeexAndroid) { - if (args.length === 6) { - const [target, level, internalformat, format, type, image] = args; - GCanvasModule.texImage2D(componentId, target, level, internalformat, format, type, image.src); - } else if (args.length === 9) { - const [target, level, internalformat, width, height, border, format, type, image] = args; - GCanvasModule.texImage2D(componentId, target, level, internalformat, width, height, border, format, type, (image ? image.src : 0)); - } - } - }, - - texSubImage2D(componentId, target, level, xoffset, yoffset, format, type, image) { - if (isWeexIOS) { - if (arguments.length === 8) { - GBridge.callNative( - componentId, - GLmethod.texSubImage2D + ',' + 6 + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset, + ',' + format + ',' + type + ',' + image.src - ) - } - } else if (isWeexAndroid) { - GCanvasModule.texSubImage2D(componentId, target, level, xoffset, yoffset, format, type, image.src); - } - }, - - bindImageTexture(componentId, src, imageId) { - GCanvasModule.bindImageTexture([src, imageId], componentId); - }, - - perloadImage([url, id], callback) { - GCanvasModule.preLoadImage([url, id], function (image) { - image.url = url; - image.id = id; - callback(image); - }); - }, - - measureText(text, fontStyle, componentId) { - return GCanvasModule.measureText([text, fontStyle], componentId); - }, - - getImageData (componentId, x, y, w, h, callback) { - GCanvasModule.getImageData([x, y,w,h],componentId,callback); - }, - - putImageData (componentId, data, x, y, w, h, callback) { - GCanvasModule.putImageData([x, y,w,h,data],componentId,callback); - }, - - toTempFilePath(componentId, x, y, width, height, destWidth, destHeight, fileType, quality, callback){ - GCanvasModule.toTempFilePath([x, y, width,height, destWidth, destHeight, fileType, quality], componentId, callback); - } -} - +const isWeex = typeof WXEnvironment !== 'undefined'; +const isWeexIOS = isWeex && /ios/i.test(WXEnvironment.platform); +const isWeexAndroid = isWeex && !isWeexIOS; + +import GLmethod from '../context-webgl/GLmethod'; + +const GCanvasModule = + (typeof weex !== 'undefined' && weex.requireModule) ? (weex.requireModule('gcanvas')) : + (typeof __weex_require__ !== 'undefined') ? (__weex_require__('@weex-module/gcanvas')) : {}; + +let isDebugging = false; + +let isComboDisabled = false; + +const logCommand = (function () { + const methodQuery = []; + Object.keys(GLmethod).forEach(key => { + methodQuery[GLmethod[key]] = key; + }) + const queryMethod = (id) => { + return methodQuery[parseInt(id)] || 'NotFoundMethod'; + } + const logCommand = (id, cmds) => { + const mId = cmds.split(',')[0]; + const mName = queryMethod(mId); + console.log(`=== callNative - componentId:${id}; method: ${mName}; cmds: ${cmds}`); + } + return logCommand; +})(); + +function joinArray(arr, sep) { + let res = ''; + for (let i = 0; i < arr.length; i++) { + if (i !== 0) { + res += sep; + } + res += arr[i]; + } + return res; +} + +const commandsCache = {} + +const GBridge = { + + callEnable: (ref, configArray) => { + + commandsCache[ref] = []; + + return GCanvasModule.enable({ + componentId: ref, + config: configArray + }); + }, + + callEnableDebug: () => { + isDebugging = true; + }, + + callEnableDisableCombo: () => { + isComboDisabled = true; + }, + + callSetContextType: function (componentId, context_type) { + GCanvasModule.setContextType(context_type, componentId); + }, + + callReset: function(id){ + GCanvasModule.resetComponent && canvasModule.resetComponent(componentId); + }, + + render: isWeexIOS ? function (componentId) { + return GCanvasModule.extendCallNative({ + contextId: componentId, + type: 0x60000001 + }); + } : function (componentId) { + return callGCanvasLinkNative(componentId, 0x60000001, 'render'); + }, + + render2d: isWeexIOS ? function (componentId, commands, callback) { + + if (isDebugging) { + console.log('>>> >>> render2d ==='); + console.log('>>> commands: ' + commands); + } + + GCanvasModule.render([commands, callback?true:false], componentId, callback); + + } : function (componentId, commands,callback) { + + if (isDebugging) { + console.log('>>> >>> render2d ==='); + console.log('>>> commands: ' + commands); + } + + callGCanvasLinkNative(componentId, 0x20000001, commands); + if(callback){ + callback(); + } + }, + + callExtendCallNative: isWeexIOS ? function (componentId, cmdArgs) { + + throw 'should not be here anymore ' + cmdArgs; + + } : function (componentId, cmdArgs) { + + throw 'should not be here anymore ' + cmdArgs; + + }, + + + flushNative: isWeexIOS ? function (componentId) { + + const cmdArgs = joinArray(commandsCache[componentId], ';'); + commandsCache[componentId] = []; + + if (isDebugging) { + console.log('>>> >>> flush native ==='); + console.log('>>> commands: ' + cmdArgs); + } + + const result = GCanvasModule.extendCallNative({ + "contextId": componentId, + "type": 0x60000000, + "args": cmdArgs + }); + + const res = result && result.result; + + if (isDebugging) { + console.log('>>> result: ' + res); + } + + return res; + + } : function (componentId) { + + const cmdArgs = joinArray(commandsCache[componentId], ';'); + commandsCache[componentId] = []; + + if (isDebugging) { + console.log('>>> >>> flush native ==='); + console.log('>>> commands: ' + cmdArgs); + } + + const result = callGCanvasLinkNative(componentId, 0x60000000, cmdArgs); + + if (isDebugging) { + console.log('>>> result: ' + result); + } + + return result; + }, + + callNative: function (componentId, cmdArgs, cache) { + + if (isDebugging) { + logCommand(componentId, cmdArgs); + } + + commandsCache[componentId].push(cmdArgs); + + if (!cache || isComboDisabled) { + return GBridge.flushNative(componentId); + } else { + return undefined; + } + }, + + texImage2D(componentId, ...args) { + if (isWeexIOS) { + if (args.length === 6) { + const [target, level, internalformat, format, type, image] = args; + GBridge.callNative( + componentId, + GLmethod.texImage2D + ',' + 6 + ',' + target + ',' + level + ',' + internalformat + ',' + format + ',' + type + ',' + image.src + ) + } else if (args.length === 9) { + const [target, level, internalformat, width, height, border, format, type, image] = args; + GBridge.callNative( + componentId, + GLmethod.texImage2D + ',' + 9 + ',' + target + ',' + level + ',' + internalformat + ',' + width + ',' + height + ',' + border + ',' + + + format + ',' + type + ',' + (image ? image.src : 0) + ) + } + } else if (isWeexAndroid) { + if (args.length === 6) { + const [target, level, internalformat, format, type, image] = args; + GCanvasModule.texImage2D(componentId, target, level, internalformat, format, type, image.src); + } else if (args.length === 9) { + const [target, level, internalformat, width, height, border, format, type, image] = args; + GCanvasModule.texImage2D(componentId, target, level, internalformat, width, height, border, format, type, (image ? image.src : 0)); + } + } + }, + + texSubImage2D(componentId, target, level, xoffset, yoffset, format, type, image) { + if (isWeexIOS) { + if (arguments.length === 8) { + GBridge.callNative( + componentId, + GLmethod.texSubImage2D + ',' + 6 + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset, + ',' + format + ',' + type + ',' + image.src + ) + } + } else if (isWeexAndroid) { + GCanvasModule.texSubImage2D(componentId, target, level, xoffset, yoffset, format, type, image.src); + } + }, + + bindImageTexture(componentId, src, imageId) { + GCanvasModule.bindImageTexture([src, imageId], componentId); + }, + + perloadImage([url, id], callback) { + GCanvasModule.preLoadImage([url, id], function (image) { + image.url = url; + image.id = id; + callback(image); + }); + }, + + measureText(text, fontStyle, componentId) { + return GCanvasModule.measureText([text, fontStyle], componentId); + }, + + getImageData (componentId, x, y, w, h, callback) { + GCanvasModule.getImageData([x, y,w,h],componentId,callback); + }, + + putImageData (componentId, data, x, y, w, h, callback) { + GCanvasModule.putImageData([x, y,w,h,data],componentId,callback); + }, + + toTempFilePath(componentId, x, y, width, height, destWidth, destHeight, fileType, quality, callback){ + GCanvasModule.toTempFilePath([x, y, width,height, destWidth, destHeight, fileType, quality], componentId, callback); + } +} + export default GBridge; \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/FillStyleLinearGradient.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/FillStyleLinearGradient.js index 3e7f03a..97e9f0f 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/FillStyleLinearGradient.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/FillStyleLinearGradient.js @@ -1,18 +1,18 @@ -class FillStyleLinearGradient { - - constructor(x0, y0, x1, y1) { - this._start_pos = { _x: x0, _y: y0 }; - this._end_pos = { _x: x1, _y: y1 }; - this._stop_count = 0; - this._stops = [0, 0, 0, 0, 0]; - } - - addColorStop = function (pos, color) { - if (this._stop_count < 5 && 0.0 <= pos && pos <= 1.0) { - this._stops[this._stop_count] = { _pos: pos, _color: color }; - this._stop_count++; - } - } -} - +class FillStyleLinearGradient { + + constructor(x0, y0, x1, y1) { + this._start_pos = { _x: x0, _y: y0 }; + this._end_pos = { _x: x1, _y: y1 }; + this._stop_count = 0; + this._stops = [0, 0, 0, 0, 0]; + } + + addColorStop = function (pos, color) { + if (this._stop_count < 5 && 0.0 <= pos && pos <= 1.0) { + this._stops[this._stop_count] = { _pos: pos, _color: color }; + this._stop_count++; + } + } +} + export default FillStyleLinearGradient; \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/FillStylePattern.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/FillStylePattern.js index 6e4f646..6c9c921 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/FillStylePattern.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/FillStylePattern.js @@ -1,8 +1,8 @@ -class FillStylePattern { - constructor(img, pattern) { - this._style = pattern; - this._img = img; - } -} - +class FillStylePattern { + constructor(img, pattern) { + this._style = pattern; + this._img = img; + } +} + export default FillStylePattern; \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/FillStyleRadialGradient.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/FillStyleRadialGradient.js index 7790596..e6ab4f3 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/FillStyleRadialGradient.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/FillStyleRadialGradient.js @@ -1,17 +1,17 @@ -class FillStyleRadialGradient { - constructor(x0, y0, r0, x1, y1, r1) { - this._start_pos = { _x: x0, _y: y0, _r: r0 }; - this._end_pos = { _x: x1, _y: y1, _r: r1 }; - this._stop_count = 0; - this._stops = [0, 0, 0, 0, 0]; - } - - addColorStop(pos, color) { - if (this._stop_count < 5 && 0.0 <= pos && pos <= 1.0) { - this._stops[this._stop_count] = { _pos: pos, _color: color }; - this._stop_count++; - } - } -} - +class FillStyleRadialGradient { + constructor(x0, y0, r0, x1, y1, r1) { + this._start_pos = { _x: x0, _y: y0, _r: r0 }; + this._end_pos = { _x: x1, _y: y1, _r: r1 }; + this._stop_count = 0; + this._stops = [0, 0, 0, 0, 0]; + } + + addColorStop(pos, color) { + if (this._stop_count < 5 && 0.0 <= pos && pos <= 1.0) { + this._stops[this._stop_count] = { _pos: pos, _color: color }; + this._stop_count++; + } + } +} + export default FillStyleRadialGradient; \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/RenderingContext.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/RenderingContext.js index e6b8f48..3e663ee 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/RenderingContext.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-2d/RenderingContext.js @@ -1,666 +1,666 @@ -import FillStylePattern from './FillStylePattern'; -import FillStyleLinearGradient from './FillStyleLinearGradient'; -import FillStyleRadialGradient from './FillStyleRadialGradient'; -import GImage from '../env/image.js'; -import { - ArrayBufferToBase64, - Base64ToUint8ClampedArray -} from '../env/tool.js'; - -export default class CanvasRenderingContext2D { - - _drawCommands = ''; - - _globalAlpha = 1.0; - - _fillStyle = 'rgb(0,0,0)'; - _strokeStyle = 'rgb(0,0,0)'; - - _lineWidth = 1; - _lineCap = 'butt'; - _lineJoin = 'miter'; - - _miterLimit = 10; - - _globalCompositeOperation = 'source-over'; - - _textAlign = 'start'; - _textBaseline = 'alphabetic'; - - _font = '10px sans-serif'; - - _savedGlobalAlpha = []; - - timer = null; - componentId = null; - - _notCommitDrawImageCache = []; - _needRedrawImageCache = []; - _redrawCommands = ''; - _autoSaveContext = true; - // _imageMap = new GHashMap(); - // _textureMap = new GHashMap(); - - constructor() { - this.className = 'CanvasRenderingContext2D'; - //this.save() - } - - setFillStyle(value) { - this.fillStyle = value; - } - - set fillStyle(value) { - this._fillStyle = value; - - if (typeof(value) == 'string') { - this._drawCommands = this._drawCommands.concat("F" + value + ";"); - } else if (value instanceof FillStylePattern) { - const image = value._img; - if (!image.complete) { - image.onload = () => { - var index = this._needRedrawImageCache.indexOf(image); - if (index > -1) { - this._needRedrawImageCache.splice(index, 1); - CanvasRenderingContext2D.GBridge.bindImageTexture(this.componentId, image.src, image._id); - this._redrawflush(true); - } - } - this._notCommitDrawImageCache.push(image); - } else { - CanvasRenderingContext2D.GBridge.bindImageTexture(this.componentId, image.src, image._id); - } - - //CanvasRenderingContext2D.GBridge.bindImageTexture(this.componentId, image.src, image._id); - this._drawCommands = this._drawCommands.concat("G" + image._id + "," + value._style + ";"); - } else if (value instanceof FillStyleLinearGradient) { - var command = "D" + value._start_pos._x.toFixed(2) + "," + value._start_pos._y.toFixed(2) + "," + - value._end_pos._x.toFixed(2) + "," + value._end_pos._y.toFixed(2) + "," + - value._stop_count; - for (var i = 0; i < value._stop_count; ++i) { - command += ("," + value._stops[i]._pos + "," + value._stops[i]._color); - } - this._drawCommands = this._drawCommands.concat(command + ";"); - } else if (value instanceof FillStyleRadialGradient) { - var command = "H" + value._start_pos._x.toFixed(2) + "," + value._start_pos._y.toFixed(2) + "," + value._start_pos._r - .toFixed(2) + "," + - value._end_pos._x.toFixed(2) + "," + value._end_pos._y.toFixed(2) + "," + value._end_pos._r.toFixed(2) + "," + - value._stop_count; - for (var i = 0; i < value._stop_count; ++i) { - command += ("," + value._stops[i]._pos + "," + value._stops[i]._color); - } - this._drawCommands = this._drawCommands.concat(command + ";"); - } - } - - get fillStyle() { - return this._fillStyle; - } - - get globalAlpha() { - return this._globalAlpha; - } - - setGlobalAlpha(value) { - this.globalAlpha = value; - } - - set globalAlpha(value) { - this._globalAlpha = value; - this._drawCommands = this._drawCommands.concat("a" + value.toFixed(2) + ";"); - } - - - get strokeStyle() { - return this._strokeStyle; - } - - setStrokeStyle(value) { - this.strokeStyle = value; - } - - set strokeStyle(value) { - - this._strokeStyle = value; - - if (typeof(value) == 'string') { - this._drawCommands = this._drawCommands.concat("S" + value + ";"); - } else if (value instanceof FillStylePattern) { - CanvasRenderingContext2D.GBridge.bindImageTexture(this.componentId, image.src, image._id); - this._drawCommands = this._drawCommands.concat("G" + image._id + "," + value._style + ";"); - } else if (value instanceof FillStyleLinearGradient) { - var command = "D" + value._start_pos._x.toFixed(2) + "," + value._start_pos._y.toFixed(2) + "," + - value._end_pos._x.toFixed(2) + "," + value._end_pos._y.toFixed(2) + "," + - value._stop_count; - - for (var i = 0; i < value._stop_count; ++i) { - command += ("," + value._stops[i]._pos + "," + value._stops[i]._color); - } - this._drawCommands = this._drawCommands.concat(command + ";"); - } else if (value instanceof FillStyleRadialGradient) { - var command = "H" + value._start_pos._x.toFixed(2) + "," + value._start_pos._y.toFixed(2) + "," + value._start_pos._r - .toFixed(2) + "," + - value._end_pos._x.toFixed(2) + "," + value._end_pos._y + ",".toFixed(2) + value._end_pos._r.toFixed(2) + "," + - value._stop_count; - - for (var i = 0; i < value._stop_count; ++i) { - command += ("," + value._stops[i]._pos + "," + value._stops[i]._color); - } - this._drawCommands = this._drawCommands.concat(command + ";"); - } - } - - get lineWidth() { - return this._lineWidth; - } - - setLineWidth(value) { - this.lineWidth = value; - } - - set lineWidth(value) { - this._lineWidth = value; - this._drawCommands = this._drawCommands.concat("W" + value + ";"); - } - - get lineCap() { - return this._lineCap; - } - - setLineCap(value) { - this.lineCap = value; - } - - set lineCap(value) { - this._lineCap = value; - this._drawCommands = this._drawCommands.concat("C" + value + ";"); - } - - get lineJoin() { - return this._lineJoin; - } - - setLineJoin(value) { - this.lineJoin = value - } - - set lineJoin(value) { - this._lineJoin = value; - this._drawCommands = this._drawCommands.concat("J" + value + ";"); - } - - get miterLimit() { - return this._miterLimit; - } - - setMiterLimit(value) { - this.miterLimit = value - } - - set miterLimit(value) { - this._miterLimit = value; - this._drawCommands = this._drawCommands.concat("M" + value + ";"); - } - - get globalCompositeOperation() { - return this._globalCompositeOperation; - } - - set globalCompositeOperation(value) { - - this._globalCompositeOperation = value; - let mode = 0; - switch (value) { - case "source-over": - mode = 0; - break; - case "source-atop": - mode = 5; - break; - case "source-in": - mode = 0; - break; - case "source-out": - mode = 2; - break; - case "destination-over": - mode = 4; - break; - case "destination-atop": - mode = 4; - break; - case "destination-in": - mode = 4; - break; - case "destination-out": - mode = 3; - break; - case "lighter": - mode = 1; - break; - case "copy": - mode = 2; - break; - case "xor": - mode = 6; - break; - default: - mode = 0; - } - - this._drawCommands = this._drawCommands.concat("B" + mode + ";"); - } - - get textAlign() { - return this._textAlign; - } - - setTextAlign(value) { - this.textAlign = value - } - - set textAlign(value) { - - this._textAlign = value; - let Align = 0; - switch (value) { - case "start": - Align = 0; - break; - case "end": - Align = 1; - break; - case "left": - Align = 2; - break; - case "center": - Align = 3; - break; - case "right": - Align = 4; - break; - default: - Align = 0; - } - - this._drawCommands = this._drawCommands.concat("A" + Align + ";"); - } - - get textBaseline() { - return this._textBaseline; - } - - setTextBaseline(value) { - this.textBaseline = value - } - - set textBaseline(value) { - this._textBaseline = value; - let baseline = 0; - switch (value) { - case "alphabetic": - baseline = 0; - break; - case "middle": - baseline = 1; - break; - case "top": - baseline = 2; - break; - case "hanging": - baseline = 3; - break; - case "bottom": - baseline = 4; - break; - case "ideographic": - baseline = 5; - break; - default: - baseline = 0; - break; - } - - this._drawCommands = this._drawCommands.concat("E" + baseline + ";"); - } - - get font() { - return this._font; - } - - setFontSize(size) { - var str = this._font; - var strs = str.trim().split(/\s+/); - for (var i = 0; i < strs.length; i++) { - var values = ["normal", "italic", "oblique", "normal", "small-caps", "normal", "bold", - "bolder", "lighter", "100", "200", "300", "400", "500", "600", "700", "800", "900", - "normal", "ultra-condensed", "extra-condensed", "condensed", "semi-condensed", - "semi-expanded", "expanded", "extra-expanded", "ultra-expanded" - ]; - - if (-1 == values.indexOf(strs[i].trim())) { - if (typeof size === 'string') { - strs[i] = size; - } else if (typeof size === 'number') { - strs[i] = String(size) + 'px'; - } - break; - } - } - this.font = strs.join(" "); - } - - set font(value) { - this._font = value; - this._drawCommands = this._drawCommands.concat("j" + value + ";"); - } - - setTransform(a, b, c, d, tx, ty) { - this._drawCommands = this._drawCommands.concat("t" + - (a === 1 ? "1" : a.toFixed(2)) + "," + - (b === 0 ? "0" : b.toFixed(2)) + "," + - (c === 0 ? "0" : c.toFixed(2)) + "," + - (d === 1 ? "1" : d.toFixed(2)) + "," + tx.toFixed(2) + "," + ty.toFixed(2) + ";"); - } - - transform(a, b, c, d, tx, ty) { - this._drawCommands = this._drawCommands.concat("f" + - (a === 1 ? "1" : a.toFixed(2)) + "," + - (b === 0 ? "0" : b.toFixed(2)) + "," + - (c === 0 ? "0" : c.toFixed(2)) + "," + - (d === 1 ? "1" : d.toFixed(2)) + "," + tx + "," + ty + ";"); - } - - resetTransform() { - this._drawCommands = this._drawCommands.concat("m;"); - } - - scale(a, d) { - this._drawCommands = this._drawCommands.concat("k" + a.toFixed(2) + "," + - d.toFixed(2) + ";"); - } - - rotate(angle) { - this._drawCommands = this._drawCommands - .concat("r" + angle.toFixed(6) + ";"); - } - - translate(tx, ty) { - this._drawCommands = this._drawCommands.concat("l" + tx.toFixed(2) + "," + ty.toFixed(2) + ";"); - } - - save() { - this._savedGlobalAlpha.push(this._globalAlpha); - this._drawCommands = this._drawCommands.concat("v;"); - } - - restore() { - this._drawCommands = this._drawCommands.concat("e;"); - this._globalAlpha = this._savedGlobalAlpha.pop(); - } - - createPattern(img, pattern) { - if (typeof img === 'string') { - var imgObj = new GImage(); - imgObj.src = img; - img = imgObj; - } - return new FillStylePattern(img, pattern); - } - - createLinearGradient(x0, y0, x1, y1) { - return new FillStyleLinearGradient(x0, y0, x1, y1); - } - - createRadialGradient = function(x0, y0, r0, x1, y1, r1) { - return new FillStyleRadialGradient(x0, y0, r0, x1, y1, r1); - }; - - createCircularGradient = function(x0, y0, r0) { - return new FillStyleRadialGradient(x0, y0, 0, x0, y0, r0); - }; - - strokeRect(x, y, w, h) { - this._drawCommands = this._drawCommands.concat("s" + x + "," + y + "," + w + "," + h + ";"); - } - - - clearRect(x, y, w, h) { - this._drawCommands = this._drawCommands.concat("c" + x + "," + y + "," + w + - "," + h + ";"); - } - - clip() { - this._drawCommands = this._drawCommands.concat("p;"); - } - - resetClip() { - this._drawCommands = this._drawCommands.concat("q;"); - } - - closePath() { - this._drawCommands = this._drawCommands.concat("o;"); - } - - moveTo(x, y) { - this._drawCommands = this._drawCommands.concat("g" + x.toFixed(2) + "," + y.toFixed(2) + ";"); - } - - lineTo(x, y) { - this._drawCommands = this._drawCommands.concat("i" + x.toFixed(2) + "," + y.toFixed(2) + ";"); - } - - quadraticCurveTo = function(cpx, cpy, x, y) { - this._drawCommands = this._drawCommands.concat("u" + cpx + "," + cpy + "," + x + "," + y + ";"); - } - - bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y, ) { - this._drawCommands = this._drawCommands.concat( - "z" + cp1x.toFixed(2) + "," + cp1y.toFixed(2) + "," + cp2x.toFixed(2) + "," + cp2y.toFixed(2) + "," + - x.toFixed(2) + "," + y.toFixed(2) + ";"); - } - - arcTo(x1, y1, x2, y2, radius) { - this._drawCommands = this._drawCommands.concat("h" + x1 + "," + y1 + "," + x2 + "," + y2 + "," + radius + ";"); - } - - beginPath() { - this._drawCommands = this._drawCommands.concat("b;"); - } - - - fillRect(x, y, w, h) { - this._drawCommands = this._drawCommands.concat("n" + x + "," + y + "," + w + - "," + h + ";"); - } - - rect(x, y, w, h) { - this._drawCommands = this._drawCommands.concat("w" + x + "," + y + "," + w + "," + h + ";"); - } - - fill() { - this._drawCommands = this._drawCommands.concat("L;"); - } - - stroke(path) { - this._drawCommands = this._drawCommands.concat("x;"); - } - - arc(x, y, radius, startAngle, endAngle, anticlockwise) { - - let ianticlockwise = 0; - if (anticlockwise) { - ianticlockwise = 1; - } - - this._drawCommands = this._drawCommands.concat( - "y" + x.toFixed(2) + "," + y.toFixed(2) + "," + - radius.toFixed(2) + "," + startAngle + "," + endAngle + "," + ianticlockwise + - ";" - ); - } - - fillText(text, x, y) { - let tmptext = text.replace(/!/g, "!!"); - tmptext = tmptext.replace(/,/g, "!,"); - tmptext = tmptext.replace(/;/g, "!;"); - this._drawCommands = this._drawCommands.concat("T" + tmptext + "," + x + "," + y + ",0.0;"); - } - - strokeText = function(text, x, y) { - let tmptext = text.replace(/!/g, "!!"); - tmptext = tmptext.replace(/,/g, "!,"); - tmptext = tmptext.replace(/;/g, "!;"); - this._drawCommands = this._drawCommands.concat("U" + tmptext + "," + x + "," + y + ",0.0;"); - } - - measureText(text) { - return CanvasRenderingContext2D.GBridge.measureText(text, this.font, this.componentId); - } - - isPointInPath = function(x, y) { - throw new Error('GCanvas not supported yet'); - } - - drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh) { - if (typeof image === 'string') { - var imgObj = new GImage(); - imgObj.src = image; - image = imgObj; - } - if (image instanceof GImage) { - if (!image.complete) { - imgObj.onload = () => { - var index = this._needRedrawImageCache.indexOf(image); - if (index > -1) { - this._needRedrawImageCache.splice(index, 1); - CanvasRenderingContext2D.GBridge.bindImageTexture(this.componentId, image.src, image._id); - this._redrawflush(true); - } - } - this._notCommitDrawImageCache.push(image); - } else { - CanvasRenderingContext2D.GBridge.bindImageTexture(this.componentId, image.src, image._id); - } - var srcArgs = [image, sx, sy, sw, sh, dx, dy, dw, dh]; - var args = []; - for (var arg in srcArgs) { - if (typeof(srcArgs[arg]) != 'undefined') { - args.push(srcArgs[arg]); - } - } - this.__drawImage.apply(this, args); - //this.__drawImage(image,sx, sy, sw, sh, dx, dy, dw, dh); - } - } - - __drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh) { - const numArgs = arguments.length; - - function drawImageCommands() { - - if (numArgs === 3) { - const x = parseFloat(sx) || 0.0; - const y = parseFloat(sy) || 0.0; - - return ("d" + image._id + ",0,0," + - image.width + "," + image.height + "," + - x + "," + y + "," + image.width + "," + image.height + ";"); - } else if (numArgs === 5) { - const x = parseFloat(sx) || 0.0; - const y = parseFloat(sy) || 0.0; - const width = parseInt(sw) || image.width; - const height = parseInt(sh) || image.height; - - return ("d" + image._id + ",0,0," + - image.width + "," + image.height + "," + - x + "," + y + "," + width + "," + height + ";"); - } else if (numArgs === 9) { - sx = parseFloat(sx) || 0.0; - sy = parseFloat(sy) || 0.0; - sw = parseInt(sw) || image.width; - sh = parseInt(sh) || image.height; - dx = parseFloat(dx) || 0.0; - dy = parseFloat(dy) || 0.0; - dw = parseInt(dw) || image.width; - dh = parseInt(dh) || image.height; - - return ("d" + image._id + "," + - sx + "," + sy + "," + sw + "," + sh + "," + - dx + "," + dy + "," + dw + "," + dh + ";"); - } - } - this._drawCommands += drawImageCommands(); - } - - _flush(reserve, callback) { - const commands = this._drawCommands; - this._drawCommands = ''; - CanvasRenderingContext2D.GBridge.render2d(this.componentId, commands, callback); - this._needRender = false; - } - - _redrawflush(reserve, callback) { - const commands = this._redrawCommands; - CanvasRenderingContext2D.GBridge.render2d(this.componentId, commands, callback); - if (this._needRedrawImageCache.length == 0) { - this._redrawCommands = ''; - } - } - - draw(reserve, callback) { - if (!reserve) { - this._globalAlpha = this._savedGlobalAlpha.pop(); - this._savedGlobalAlpha.push(this._globalAlpha); - this._redrawCommands = this._drawCommands; - this._needRedrawImageCache = this._notCommitDrawImageCache; - if (this._autoSaveContext) { - this._drawCommands = ("v;" + this._drawCommands); - this._autoSaveContext = false; - } else { - this._drawCommands = ("e;X;v;" + this._drawCommands); - } - } else { - this._needRedrawImageCache = this._needRedrawImageCache.concat(this._notCommitDrawImageCache); - this._redrawCommands += this._drawCommands; - if (this._autoSaveContext) { - this._drawCommands = ("v;" + this._drawCommands); - this._autoSaveContext = false; - } - } - this._notCommitDrawImageCache = []; - if (this._flush) { - this._flush(reserve, callback); - } - } - - getImageData(x, y, w, h, callback) { - CanvasRenderingContext2D.GBridge.getImageData(this.componentId, x, y, w, h, function(res) { - res.data = Base64ToUint8ClampedArray(res.data); - if (typeof(callback) == 'function') { - callback(res); - } - }); - } - - putImageData(data, x, y, w, h, callback) { - if (data instanceof Uint8ClampedArray) { - data = ArrayBufferToBase64(data); - CanvasRenderingContext2D.GBridge.putImageData(this.componentId, data, x, y, w, h, function(res) { - if (typeof(callback) == 'function') { - callback(res); - } - }); - } - } - - toTempFilePath(x, y, width, height, destWidth, destHeight, fileType, quality, callback) { - CanvasRenderingContext2D.GBridge.toTempFilePath(this.componentId, x, y, width, height, destWidth, destHeight, - fileType, quality, - function(res) { - if (typeof(callback) == 'function') { - callback(res); - } - }); - } -} +import FillStylePattern from './FillStylePattern'; +import FillStyleLinearGradient from './FillStyleLinearGradient'; +import FillStyleRadialGradient from './FillStyleRadialGradient'; +import GImage from '../env/image.js'; +import { + ArrayBufferToBase64, + Base64ToUint8ClampedArray +} from '../env/tool.js'; + +export default class CanvasRenderingContext2D { + + _drawCommands = ''; + + _globalAlpha = 1.0; + + _fillStyle = 'rgb(0,0,0)'; + _strokeStyle = 'rgb(0,0,0)'; + + _lineWidth = 1; + _lineCap = 'butt'; + _lineJoin = 'miter'; + + _miterLimit = 10; + + _globalCompositeOperation = 'source-over'; + + _textAlign = 'start'; + _textBaseline = 'alphabetic'; + + _font = '10px sans-serif'; + + _savedGlobalAlpha = []; + + timer = null; + componentId = null; + + _notCommitDrawImageCache = []; + _needRedrawImageCache = []; + _redrawCommands = ''; + _autoSaveContext = true; + // _imageMap = new GHashMap(); + // _textureMap = new GHashMap(); + + constructor() { + this.className = 'CanvasRenderingContext2D'; + //this.save() + } + + setFillStyle(value) { + this.fillStyle = value; + } + + set fillStyle(value) { + this._fillStyle = value; + + if (typeof(value) == 'string') { + this._drawCommands = this._drawCommands.concat("F" + value + ";"); + } else if (value instanceof FillStylePattern) { + const image = value._img; + if (!image.complete) { + image.onload = () => { + var index = this._needRedrawImageCache.indexOf(image); + if (index > -1) { + this._needRedrawImageCache.splice(index, 1); + CanvasRenderingContext2D.GBridge.bindImageTexture(this.componentId, image.src, image._id); + this._redrawflush(true); + } + } + this._notCommitDrawImageCache.push(image); + } else { + CanvasRenderingContext2D.GBridge.bindImageTexture(this.componentId, image.src, image._id); + } + + //CanvasRenderingContext2D.GBridge.bindImageTexture(this.componentId, image.src, image._id); + this._drawCommands = this._drawCommands.concat("G" + image._id + "," + value._style + ";"); + } else if (value instanceof FillStyleLinearGradient) { + var command = "D" + value._start_pos._x.toFixed(2) + "," + value._start_pos._y.toFixed(2) + "," + + value._end_pos._x.toFixed(2) + "," + value._end_pos._y.toFixed(2) + "," + + value._stop_count; + for (var i = 0; i < value._stop_count; ++i) { + command += ("," + value._stops[i]._pos + "," + value._stops[i]._color); + } + this._drawCommands = this._drawCommands.concat(command + ";"); + } else if (value instanceof FillStyleRadialGradient) { + var command = "H" + value._start_pos._x.toFixed(2) + "," + value._start_pos._y.toFixed(2) + "," + value._start_pos._r + .toFixed(2) + "," + + value._end_pos._x.toFixed(2) + "," + value._end_pos._y.toFixed(2) + "," + value._end_pos._r.toFixed(2) + "," + + value._stop_count; + for (var i = 0; i < value._stop_count; ++i) { + command += ("," + value._stops[i]._pos + "," + value._stops[i]._color); + } + this._drawCommands = this._drawCommands.concat(command + ";"); + } + } + + get fillStyle() { + return this._fillStyle; + } + + get globalAlpha() { + return this._globalAlpha; + } + + setGlobalAlpha(value) { + this.globalAlpha = value; + } + + set globalAlpha(value) { + this._globalAlpha = value; + this._drawCommands = this._drawCommands.concat("a" + value.toFixed(2) + ";"); + } + + + get strokeStyle() { + return this._strokeStyle; + } + + setStrokeStyle(value) { + this.strokeStyle = value; + } + + set strokeStyle(value) { + + this._strokeStyle = value; + + if (typeof(value) == 'string') { + this._drawCommands = this._drawCommands.concat("S" + value + ";"); + } else if (value instanceof FillStylePattern) { + CanvasRenderingContext2D.GBridge.bindImageTexture(this.componentId, image.src, image._id); + this._drawCommands = this._drawCommands.concat("G" + image._id + "," + value._style + ";"); + } else if (value instanceof FillStyleLinearGradient) { + var command = "D" + value._start_pos._x.toFixed(2) + "," + value._start_pos._y.toFixed(2) + "," + + value._end_pos._x.toFixed(2) + "," + value._end_pos._y.toFixed(2) + "," + + value._stop_count; + + for (var i = 0; i < value._stop_count; ++i) { + command += ("," + value._stops[i]._pos + "," + value._stops[i]._color); + } + this._drawCommands = this._drawCommands.concat(command + ";"); + } else if (value instanceof FillStyleRadialGradient) { + var command = "H" + value._start_pos._x.toFixed(2) + "," + value._start_pos._y.toFixed(2) + "," + value._start_pos._r + .toFixed(2) + "," + + value._end_pos._x.toFixed(2) + "," + value._end_pos._y + ",".toFixed(2) + value._end_pos._r.toFixed(2) + "," + + value._stop_count; + + for (var i = 0; i < value._stop_count; ++i) { + command += ("," + value._stops[i]._pos + "," + value._stops[i]._color); + } + this._drawCommands = this._drawCommands.concat(command + ";"); + } + } + + get lineWidth() { + return this._lineWidth; + } + + setLineWidth(value) { + this.lineWidth = value; + } + + set lineWidth(value) { + this._lineWidth = value; + this._drawCommands = this._drawCommands.concat("W" + value + ";"); + } + + get lineCap() { + return this._lineCap; + } + + setLineCap(value) { + this.lineCap = value; + } + + set lineCap(value) { + this._lineCap = value; + this._drawCommands = this._drawCommands.concat("C" + value + ";"); + } + + get lineJoin() { + return this._lineJoin; + } + + setLineJoin(value) { + this.lineJoin = value + } + + set lineJoin(value) { + this._lineJoin = value; + this._drawCommands = this._drawCommands.concat("J" + value + ";"); + } + + get miterLimit() { + return this._miterLimit; + } + + setMiterLimit(value) { + this.miterLimit = value + } + + set miterLimit(value) { + this._miterLimit = value; + this._drawCommands = this._drawCommands.concat("M" + value + ";"); + } + + get globalCompositeOperation() { + return this._globalCompositeOperation; + } + + set globalCompositeOperation(value) { + + this._globalCompositeOperation = value; + let mode = 0; + switch (value) { + case "source-over": + mode = 0; + break; + case "source-atop": + mode = 5; + break; + case "source-in": + mode = 0; + break; + case "source-out": + mode = 2; + break; + case "destination-over": + mode = 4; + break; + case "destination-atop": + mode = 4; + break; + case "destination-in": + mode = 4; + break; + case "destination-out": + mode = 3; + break; + case "lighter": + mode = 1; + break; + case "copy": + mode = 2; + break; + case "xor": + mode = 6; + break; + default: + mode = 0; + } + + this._drawCommands = this._drawCommands.concat("B" + mode + ";"); + } + + get textAlign() { + return this._textAlign; + } + + setTextAlign(value) { + this.textAlign = value + } + + set textAlign(value) { + + this._textAlign = value; + let Align = 0; + switch (value) { + case "start": + Align = 0; + break; + case "end": + Align = 1; + break; + case "left": + Align = 2; + break; + case "center": + Align = 3; + break; + case "right": + Align = 4; + break; + default: + Align = 0; + } + + this._drawCommands = this._drawCommands.concat("A" + Align + ";"); + } + + get textBaseline() { + return this._textBaseline; + } + + setTextBaseline(value) { + this.textBaseline = value + } + + set textBaseline(value) { + this._textBaseline = value; + let baseline = 0; + switch (value) { + case "alphabetic": + baseline = 0; + break; + case "middle": + baseline = 1; + break; + case "top": + baseline = 2; + break; + case "hanging": + baseline = 3; + break; + case "bottom": + baseline = 4; + break; + case "ideographic": + baseline = 5; + break; + default: + baseline = 0; + break; + } + + this._drawCommands = this._drawCommands.concat("E" + baseline + ";"); + } + + get font() { + return this._font; + } + + setFontSize(size) { + var str = this._font; + var strs = str.trim().split(/\s+/); + for (var i = 0; i < strs.length; i++) { + var values = ["normal", "italic", "oblique", "normal", "small-caps", "normal", "bold", + "bolder", "lighter", "100", "200", "300", "400", "500", "600", "700", "800", "900", + "normal", "ultra-condensed", "extra-condensed", "condensed", "semi-condensed", + "semi-expanded", "expanded", "extra-expanded", "ultra-expanded" + ]; + + if (-1 == values.indexOf(strs[i].trim())) { + if (typeof size === 'string') { + strs[i] = size; + } else if (typeof size === 'number') { + strs[i] = String(size) + 'px'; + } + break; + } + } + this.font = strs.join(" "); + } + + set font(value) { + this._font = value; + this._drawCommands = this._drawCommands.concat("j" + value + ";"); + } + + setTransform(a, b, c, d, tx, ty) { + this._drawCommands = this._drawCommands.concat("t" + + (a === 1 ? "1" : a.toFixed(2)) + "," + + (b === 0 ? "0" : b.toFixed(2)) + "," + + (c === 0 ? "0" : c.toFixed(2)) + "," + + (d === 1 ? "1" : d.toFixed(2)) + "," + tx.toFixed(2) + "," + ty.toFixed(2) + ";"); + } + + transform(a, b, c, d, tx, ty) { + this._drawCommands = this._drawCommands.concat("f" + + (a === 1 ? "1" : a.toFixed(2)) + "," + + (b === 0 ? "0" : b.toFixed(2)) + "," + + (c === 0 ? "0" : c.toFixed(2)) + "," + + (d === 1 ? "1" : d.toFixed(2)) + "," + tx + "," + ty + ";"); + } + + resetTransform() { + this._drawCommands = this._drawCommands.concat("m;"); + } + + scale(a, d) { + this._drawCommands = this._drawCommands.concat("k" + a.toFixed(2) + "," + + d.toFixed(2) + ";"); + } + + rotate(angle) { + this._drawCommands = this._drawCommands + .concat("r" + angle.toFixed(6) + ";"); + } + + translate(tx, ty) { + this._drawCommands = this._drawCommands.concat("l" + tx.toFixed(2) + "," + ty.toFixed(2) + ";"); + } + + save() { + this._savedGlobalAlpha.push(this._globalAlpha); + this._drawCommands = this._drawCommands.concat("v;"); + } + + restore() { + this._drawCommands = this._drawCommands.concat("e;"); + this._globalAlpha = this._savedGlobalAlpha.pop(); + } + + createPattern(img, pattern) { + if (typeof img === 'string') { + var imgObj = new GImage(); + imgObj.src = img; + img = imgObj; + } + return new FillStylePattern(img, pattern); + } + + createLinearGradient(x0, y0, x1, y1) { + return new FillStyleLinearGradient(x0, y0, x1, y1); + } + + createRadialGradient = function(x0, y0, r0, x1, y1, r1) { + return new FillStyleRadialGradient(x0, y0, r0, x1, y1, r1); + }; + + createCircularGradient = function(x0, y0, r0) { + return new FillStyleRadialGradient(x0, y0, 0, x0, y0, r0); + }; + + strokeRect(x, y, w, h) { + this._drawCommands = this._drawCommands.concat("s" + x + "," + y + "," + w + "," + h + ";"); + } + + + clearRect(x, y, w, h) { + this._drawCommands = this._drawCommands.concat("c" + x + "," + y + "," + w + + "," + h + ";"); + } + + clip() { + this._drawCommands = this._drawCommands.concat("p;"); + } + + resetClip() { + this._drawCommands = this._drawCommands.concat("q;"); + } + + closePath() { + this._drawCommands = this._drawCommands.concat("o;"); + } + + moveTo(x, y) { + this._drawCommands = this._drawCommands.concat("g" + x.toFixed(2) + "," + y.toFixed(2) + ";"); + } + + lineTo(x, y) { + this._drawCommands = this._drawCommands.concat("i" + x.toFixed(2) + "," + y.toFixed(2) + ";"); + } + + quadraticCurveTo = function(cpx, cpy, x, y) { + this._drawCommands = this._drawCommands.concat("u" + cpx + "," + cpy + "," + x + "," + y + ";"); + } + + bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y, ) { + this._drawCommands = this._drawCommands.concat( + "z" + cp1x.toFixed(2) + "," + cp1y.toFixed(2) + "," + cp2x.toFixed(2) + "," + cp2y.toFixed(2) + "," + + x.toFixed(2) + "," + y.toFixed(2) + ";"); + } + + arcTo(x1, y1, x2, y2, radius) { + this._drawCommands = this._drawCommands.concat("h" + x1 + "," + y1 + "," + x2 + "," + y2 + "," + radius + ";"); + } + + beginPath() { + this._drawCommands = this._drawCommands.concat("b;"); + } + + + fillRect(x, y, w, h) { + this._drawCommands = this._drawCommands.concat("n" + x + "," + y + "," + w + + "," + h + ";"); + } + + rect(x, y, w, h) { + this._drawCommands = this._drawCommands.concat("w" + x + "," + y + "," + w + "," + h + ";"); + } + + fill() { + this._drawCommands = this._drawCommands.concat("L;"); + } + + stroke(path) { + this._drawCommands = this._drawCommands.concat("x;"); + } + + arc(x, y, radius, startAngle, endAngle, anticlockwise) { + + let ianticlockwise = 0; + if (anticlockwise) { + ianticlockwise = 1; + } + + this._drawCommands = this._drawCommands.concat( + "y" + x.toFixed(2) + "," + y.toFixed(2) + "," + + radius.toFixed(2) + "," + startAngle + "," + endAngle + "," + ianticlockwise + + ";" + ); + } + + fillText(text, x, y) { + let tmptext = text.replace(/!/g, "!!"); + tmptext = tmptext.replace(/,/g, "!,"); + tmptext = tmptext.replace(/;/g, "!;"); + this._drawCommands = this._drawCommands.concat("T" + tmptext + "," + x + "," + y + ",0.0;"); + } + + strokeText = function(text, x, y) { + let tmptext = text.replace(/!/g, "!!"); + tmptext = tmptext.replace(/,/g, "!,"); + tmptext = tmptext.replace(/;/g, "!;"); + this._drawCommands = this._drawCommands.concat("U" + tmptext + "," + x + "," + y + ",0.0;"); + } + + measureText(text) { + return CanvasRenderingContext2D.GBridge.measureText(text, this.font, this.componentId); + } + + isPointInPath = function(x, y) { + throw new Error('GCanvas not supported yet'); + } + + drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh) { + if (typeof image === 'string') { + var imgObj = new GImage(); + imgObj.src = image; + image = imgObj; + } + if (image instanceof GImage) { + if (!image.complete) { + imgObj.onload = () => { + var index = this._needRedrawImageCache.indexOf(image); + if (index > -1) { + this._needRedrawImageCache.splice(index, 1); + CanvasRenderingContext2D.GBridge.bindImageTexture(this.componentId, image.src, image._id); + this._redrawflush(true); + } + } + this._notCommitDrawImageCache.push(image); + } else { + CanvasRenderingContext2D.GBridge.bindImageTexture(this.componentId, image.src, image._id); + } + var srcArgs = [image, sx, sy, sw, sh, dx, dy, dw, dh]; + var args = []; + for (var arg in srcArgs) { + if (typeof(srcArgs[arg]) != 'undefined') { + args.push(srcArgs[arg]); + } + } + this.__drawImage.apply(this, args); + //this.__drawImage(image,sx, sy, sw, sh, dx, dy, dw, dh); + } + } + + __drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh) { + const numArgs = arguments.length; + + function drawImageCommands() { + + if (numArgs === 3) { + const x = parseFloat(sx) || 0.0; + const y = parseFloat(sy) || 0.0; + + return ("d" + image._id + ",0,0," + + image.width + "," + image.height + "," + + x + "," + y + "," + image.width + "," + image.height + ";"); + } else if (numArgs === 5) { + const x = parseFloat(sx) || 0.0; + const y = parseFloat(sy) || 0.0; + const width = parseInt(sw) || image.width; + const height = parseInt(sh) || image.height; + + return ("d" + image._id + ",0,0," + + image.width + "," + image.height + "," + + x + "," + y + "," + width + "," + height + ";"); + } else if (numArgs === 9) { + sx = parseFloat(sx) || 0.0; + sy = parseFloat(sy) || 0.0; + sw = parseInt(sw) || image.width; + sh = parseInt(sh) || image.height; + dx = parseFloat(dx) || 0.0; + dy = parseFloat(dy) || 0.0; + dw = parseInt(dw) || image.width; + dh = parseInt(dh) || image.height; + + return ("d" + image._id + "," + + sx + "," + sy + "," + sw + "," + sh + "," + + dx + "," + dy + "," + dw + "," + dh + ";"); + } + } + this._drawCommands += drawImageCommands(); + } + + _flush(reserve, callback) { + const commands = this._drawCommands; + this._drawCommands = ''; + CanvasRenderingContext2D.GBridge.render2d(this.componentId, commands, callback); + this._needRender = false; + } + + _redrawflush(reserve, callback) { + const commands = this._redrawCommands; + CanvasRenderingContext2D.GBridge.render2d(this.componentId, commands, callback); + if (this._needRedrawImageCache.length == 0) { + this._redrawCommands = ''; + } + } + + draw(reserve, callback) { + if (!reserve) { + this._globalAlpha = this._savedGlobalAlpha.pop(); + this._savedGlobalAlpha.push(this._globalAlpha); + this._redrawCommands = this._drawCommands; + this._needRedrawImageCache = this._notCommitDrawImageCache; + if (this._autoSaveContext) { + this._drawCommands = ("v;" + this._drawCommands); + this._autoSaveContext = false; + } else { + this._drawCommands = ("e;X;v;" + this._drawCommands); + } + } else { + this._needRedrawImageCache = this._needRedrawImageCache.concat(this._notCommitDrawImageCache); + this._redrawCommands += this._drawCommands; + if (this._autoSaveContext) { + this._drawCommands = ("v;" + this._drawCommands); + this._autoSaveContext = false; + } + } + this._notCommitDrawImageCache = []; + if (this._flush) { + this._flush(reserve, callback); + } + } + + getImageData(x, y, w, h, callback) { + CanvasRenderingContext2D.GBridge.getImageData(this.componentId, x, y, w, h, function(res) { + res.data = Base64ToUint8ClampedArray(res.data); + if (typeof(callback) == 'function') { + callback(res); + } + }); + } + + putImageData(data, x, y, w, h, callback) { + if (data instanceof Uint8ClampedArray) { + data = ArrayBufferToBase64(data); + CanvasRenderingContext2D.GBridge.putImageData(this.componentId, data, x, y, w, h, function(res) { + if (typeof(callback) == 'function') { + callback(res); + } + }); + } + } + + toTempFilePath(x, y, width, height, destWidth, destHeight, fileType, quality, callback) { + CanvasRenderingContext2D.GBridge.toTempFilePath(this.componentId, x, y, width, height, destWidth, destHeight, + fileType, quality, + function(res) { + if (typeof(callback) == 'function') { + callback(res); + } + }); + } +} diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/ActiveInfo.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/ActiveInfo.js index b495129..41738b1 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/ActiveInfo.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/ActiveInfo.js @@ -1,11 +1,11 @@ -export default class WebGLActiveInfo { - className = 'WebGLActiveInfo'; - - constructor({ - type, name, size - }) { - this.type = type; - this.name = name; - this.size = size; - } +export default class WebGLActiveInfo { + className = 'WebGLActiveInfo'; + + constructor({ + type, name, size + }) { + this.type = type; + this.name = name; + this.size = size; + } } \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Buffer.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Buffer.js index 4800f67..a451291 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Buffer.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Buffer.js @@ -1,21 +1,21 @@ -import {getTransferedObjectUUID} from './classUtils'; - -const name = 'WebGLBuffer'; - -function uuid(id) { - return getTransferedObjectUUID(name, id); -} - -export default class WebGLBuffer { - className = name; - - constructor(id) { - this.id = id; - } - - static uuid = uuid; - - uuid() { - return uuid(this.id); - } +import {getTransferedObjectUUID} from './classUtils'; + +const name = 'WebGLBuffer'; + +function uuid(id) { + return getTransferedObjectUUID(name, id); +} + +export default class WebGLBuffer { + className = name; + + constructor(id) { + this.id = id; + } + + static uuid = uuid; + + uuid() { + return uuid(this.id); + } } \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Framebuffer.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Framebuffer.js index 28b46d3..e8d806e 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Framebuffer.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Framebuffer.js @@ -1,21 +1,21 @@ -import {getTransferedObjectUUID} from './classUtils'; - -const name = 'WebGLFrameBuffer'; - -function uuid(id) { - return getTransferedObjectUUID(name, id); -} - -export default class WebGLFramebuffer { - className = name; - - constructor(id) { - this.id = id; - } - - static uuid = uuid; - - uuid() { - return uuid(this.id); - } +import {getTransferedObjectUUID} from './classUtils'; + +const name = 'WebGLFrameBuffer'; + +function uuid(id) { + return getTransferedObjectUUID(name, id); +} + +export default class WebGLFramebuffer { + className = name; + + constructor(id) { + this.id = id; + } + + static uuid = uuid; + + uuid() { + return uuid(this.id); + } } \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/GLenum.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/GLenum.js index ac5544d..5fdc49f 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/GLenum.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/GLenum.js @@ -1,298 +1,298 @@ -export default { - "DEPTH_BUFFER_BIT": 256, - "STENCIL_BUFFER_BIT": 1024, - "COLOR_BUFFER_BIT": 16384, - "POINTS": 0, - "LINES": 1, - "LINE_LOOP": 2, - "LINE_STRIP": 3, - "TRIANGLES": 4, - "TRIANGLE_STRIP": 5, - "TRIANGLE_FAN": 6, - "ZERO": 0, - "ONE": 1, - "SRC_COLOR": 768, - "ONE_MINUS_SRC_COLOR": 769, - "SRC_ALPHA": 770, - "ONE_MINUS_SRC_ALPHA": 771, - "DST_ALPHA": 772, - "ONE_MINUS_DST_ALPHA": 773, - "DST_COLOR": 774, - "ONE_MINUS_DST_COLOR": 775, - "SRC_ALPHA_SATURATE": 776, - "FUNC_ADD": 32774, - "BLEND_EQUATION": 32777, - "BLEND_EQUATION_RGB": 32777, - "BLEND_EQUATION_ALPHA": 34877, - "FUNC_SUBTRACT": 32778, - "FUNC_REVERSE_SUBTRACT": 32779, - "BLEND_DST_RGB": 32968, - "BLEND_SRC_RGB": 32969, - "BLEND_DST_ALPHA": 32970, - "BLEND_SRC_ALPHA": 32971, - "CONSTANT_COLOR": 32769, - "ONE_MINUS_CONSTANT_COLOR": 32770, - "CONSTANT_ALPHA": 32771, - "ONE_MINUS_CONSTANT_ALPHA": 32772, - "BLEND_COLOR": 32773, - "ARRAY_BUFFER": 34962, - "ELEMENT_ARRAY_BUFFER": 34963, - "ARRAY_BUFFER_BINDING": 34964, - "ELEMENT_ARRAY_BUFFER_BINDING": 34965, - "STREAM_DRAW": 35040, - "STATIC_DRAW": 35044, - "DYNAMIC_DRAW": 35048, - "BUFFER_SIZE": 34660, - "BUFFER_USAGE": 34661, - "CURRENT_VERTEX_ATTRIB": 34342, - "FRONT": 1028, - "BACK": 1029, - "FRONT_AND_BACK": 1032, - "TEXTURE_2D": 3553, - "CULL_FACE": 2884, - "BLEND": 3042, - "DITHER": 3024, - "STENCIL_TEST": 2960, - "DEPTH_TEST": 2929, - "SCISSOR_TEST": 3089, - "POLYGON_OFFSET_FILL": 32823, - "SAMPLE_ALPHA_TO_COVERAGE": 32926, - "SAMPLE_COVERAGE": 32928, - "NO_ERROR": 0, - "INVALID_ENUM": 1280, - "INVALID_VALUE": 1281, - "INVALID_OPERATION": 1282, - "OUT_OF_MEMORY": 1285, - "CW": 2304, - "CCW": 2305, - "LINE_WIDTH": 2849, - "ALIASED_POINT_SIZE_RANGE": 33901, - "ALIASED_LINE_WIDTH_RANGE": 33902, - "CULL_FACE_MODE": 2885, - "FRONT_FACE": 2886, - "DEPTH_RANGE": 2928, - "DEPTH_WRITEMASK": 2930, - "DEPTH_CLEAR_VALUE": 2931, - "DEPTH_FUNC": 2932, - "STENCIL_CLEAR_VALUE": 2961, - "STENCIL_FUNC": 2962, - "STENCIL_FAIL": 2964, - "STENCIL_PASS_DEPTH_FAIL": 2965, - "STENCIL_PASS_DEPTH_PASS": 2966, - "STENCIL_REF": 2967, - "STENCIL_VALUE_MASK": 2963, - "STENCIL_WRITEMASK": 2968, - "STENCIL_BACK_FUNC": 34816, - "STENCIL_BACK_FAIL": 34817, - "STENCIL_BACK_PASS_DEPTH_FAIL": 34818, - "STENCIL_BACK_PASS_DEPTH_PASS": 34819, - "STENCIL_BACK_REF": 36003, - "STENCIL_BACK_VALUE_MASK": 36004, - "STENCIL_BACK_WRITEMASK": 36005, - "VIEWPORT": 2978, - "SCISSOR_BOX": 3088, - "COLOR_CLEAR_VALUE": 3106, - "COLOR_WRITEMASK": 3107, - "UNPACK_ALIGNMENT": 3317, - "PACK_ALIGNMENT": 3333, - "MAX_TEXTURE_SIZE": 3379, - "MAX_VIEWPORT_DIMS": 3386, - "SUBPIXEL_BITS": 3408, - "RED_BITS": 3410, - "GREEN_BITS": 3411, - "BLUE_BITS": 3412, - "ALPHA_BITS": 3413, - "DEPTH_BITS": 3414, - "STENCIL_BITS": 3415, - "POLYGON_OFFSET_UNITS": 10752, - "POLYGON_OFFSET_FACTOR": 32824, - "TEXTURE_BINDING_2D": 32873, - "SAMPLE_BUFFERS": 32936, - "SAMPLES": 32937, - "SAMPLE_COVERAGE_VALUE": 32938, - "SAMPLE_COVERAGE_INVERT": 32939, - "COMPRESSED_TEXTURE_FORMATS": 34467, - "DONT_CARE": 4352, - "FASTEST": 4353, - "NICEST": 4354, - "GENERATE_MIPMAP_HINT": 33170, - "BYTE": 5120, - "UNSIGNED_BYTE": 5121, - "SHORT": 5122, - "UNSIGNED_SHORT": 5123, - "INT": 5124, - "UNSIGNED_INT": 5125, - "FLOAT": 5126, - "DEPTH_COMPONENT": 6402, - "ALPHA": 6406, - "RGB": 6407, - "RGBA": 6408, - "LUMINANCE": 6409, - "LUMINANCE_ALPHA": 6410, - "UNSIGNED_SHORT_4_4_4_4": 32819, - "UNSIGNED_SHORT_5_5_5_1": 32820, - "UNSIGNED_SHORT_5_6_5": 33635, - "FRAGMENT_SHADER": 35632, - "VERTEX_SHADER": 35633, - "MAX_VERTEX_ATTRIBS": 34921, - "MAX_VERTEX_UNIFORM_VECTORS": 36347, - "MAX_VARYING_VECTORS": 36348, - "MAX_COMBINED_TEXTURE_IMAGE_UNITS": 35661, - "MAX_VERTEX_TEXTURE_IMAGE_UNITS": 35660, - "MAX_TEXTURE_IMAGE_UNITS": 34930, - "MAX_FRAGMENT_UNIFORM_VECTORS": 36349, - "SHADER_TYPE": 35663, - "DELETE_STATUS": 35712, - "LINK_STATUS": 35714, - "VALIDATE_STATUS": 35715, - "ATTACHED_SHADERS": 35717, - "ACTIVE_UNIFORMS": 35718, - "ACTIVE_ATTRIBUTES": 35721, - "SHADING_LANGUAGE_VERSION": 35724, - "CURRENT_PROGRAM": 35725, - "NEVER": 512, - "LESS": 513, - "EQUAL": 514, - "LEQUAL": 515, - "GREATER": 516, - "NOTEQUAL": 517, - "GEQUAL": 518, - "ALWAYS": 519, - "KEEP": 7680, - "REPLACE": 7681, - "INCR": 7682, - "DECR": 7683, - "INVERT": 5386, - "INCR_WRAP": 34055, - "DECR_WRAP": 34056, - "VENDOR": 7936, - "RENDERER": 7937, - "VERSION": 7938, - "NEAREST": 9728, - "LINEAR": 9729, - "NEAREST_MIPMAP_NEAREST": 9984, - "LINEAR_MIPMAP_NEAREST": 9985, - "NEAREST_MIPMAP_LINEAR": 9986, - "LINEAR_MIPMAP_LINEAR": 9987, - "TEXTURE_MAG_FILTER": 10240, - "TEXTURE_MIN_FILTER": 10241, - "TEXTURE_WRAP_S": 10242, - "TEXTURE_WRAP_T": 10243, - "TEXTURE": 5890, - "TEXTURE_CUBE_MAP": 34067, - "TEXTURE_BINDING_CUBE_MAP": 34068, - "TEXTURE_CUBE_MAP_POSITIVE_X": 34069, - "TEXTURE_CUBE_MAP_NEGATIVE_X": 34070, - "TEXTURE_CUBE_MAP_POSITIVE_Y": 34071, - "TEXTURE_CUBE_MAP_NEGATIVE_Y": 34072, - "TEXTURE_CUBE_MAP_POSITIVE_Z": 34073, - "TEXTURE_CUBE_MAP_NEGATIVE_Z": 34074, - "MAX_CUBE_MAP_TEXTURE_SIZE": 34076, - "TEXTURE0": 33984, - "TEXTURE1": 33985, - "TEXTURE2": 33986, - "TEXTURE3": 33987, - "TEXTURE4": 33988, - "TEXTURE5": 33989, - "TEXTURE6": 33990, - "TEXTURE7": 33991, - "TEXTURE8": 33992, - "TEXTURE9": 33993, - "TEXTURE10": 33994, - "TEXTURE11": 33995, - "TEXTURE12": 33996, - "TEXTURE13": 33997, - "TEXTURE14": 33998, - "TEXTURE15": 33999, - "TEXTURE16": 34000, - "TEXTURE17": 34001, - "TEXTURE18": 34002, - "TEXTURE19": 34003, - "TEXTURE20": 34004, - "TEXTURE21": 34005, - "TEXTURE22": 34006, - "TEXTURE23": 34007, - "TEXTURE24": 34008, - "TEXTURE25": 34009, - "TEXTURE26": 34010, - "TEXTURE27": 34011, - "TEXTURE28": 34012, - "TEXTURE29": 34013, - "TEXTURE30": 34014, - "TEXTURE31": 34015, - "ACTIVE_TEXTURE": 34016, - "REPEAT": 10497, - "CLAMP_TO_EDGE": 33071, - "MIRRORED_REPEAT": 33648, - "FLOAT_VEC2": 35664, - "FLOAT_VEC3": 35665, - "FLOAT_VEC4": 35666, - "INT_VEC2": 35667, - "INT_VEC3": 35668, - "INT_VEC4": 35669, - "BOOL": 35670, - "BOOL_VEC2": 35671, - "BOOL_VEC3": 35672, - "BOOL_VEC4": 35673, - "FLOAT_MAT2": 35674, - "FLOAT_MAT3": 35675, - "FLOAT_MAT4": 35676, - "SAMPLER_2D": 35678, - "SAMPLER_CUBE": 35680, - "VERTEX_ATTRIB_ARRAY_ENABLED": 34338, - "VERTEX_ATTRIB_ARRAY_SIZE": 34339, - "VERTEX_ATTRIB_ARRAY_STRIDE": 34340, - "VERTEX_ATTRIB_ARRAY_TYPE": 34341, - "VERTEX_ATTRIB_ARRAY_NORMALIZED": 34922, - "VERTEX_ATTRIB_ARRAY_POINTER": 34373, - "VERTEX_ATTRIB_ARRAY_BUFFER_BINDING": 34975, - "IMPLEMENTATION_COLOR_READ_TYPE": 35738, - "IMPLEMENTATION_COLOR_READ_FORMAT": 35739, - "COMPILE_STATUS": 35713, - "LOW_FLOAT": 36336, - "MEDIUM_FLOAT": 36337, - "HIGH_FLOAT": 36338, - "LOW_INT": 36339, - "MEDIUM_INT": 36340, - "HIGH_INT": 36341, - "FRAMEBUFFER": 36160, - "RENDERBUFFER": 36161, - "RGBA4": 32854, - "RGB5_A1": 32855, - "RGB565": 36194, - "DEPTH_COMPONENT16": 33189, - "STENCIL_INDEX8": 36168, - "DEPTH_STENCIL": 34041, - "RENDERBUFFER_WIDTH": 36162, - "RENDERBUFFER_HEIGHT": 36163, - "RENDERBUFFER_INTERNAL_FORMAT": 36164, - "RENDERBUFFER_RED_SIZE": 36176, - "RENDERBUFFER_GREEN_SIZE": 36177, - "RENDERBUFFER_BLUE_SIZE": 36178, - "RENDERBUFFER_ALPHA_SIZE": 36179, - "RENDERBUFFER_DEPTH_SIZE": 36180, - "RENDERBUFFER_STENCIL_SIZE": 36181, - "FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE": 36048, - "FRAMEBUFFER_ATTACHMENT_OBJECT_NAME": 36049, - "FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL": 36050, - "FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE": 36051, - "COLOR_ATTACHMENT0": 36064, - "DEPTH_ATTACHMENT": 36096, - "STENCIL_ATTACHMENT": 36128, - "DEPTH_STENCIL_ATTACHMENT": 33306, - "NONE": 0, - "FRAMEBUFFER_COMPLETE": 36053, - "FRAMEBUFFER_INCOMPLETE_ATTACHMENT": 36054, - "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT": 36055, - "FRAMEBUFFER_INCOMPLETE_DIMENSIONS": 36057, - "FRAMEBUFFER_UNSUPPORTED": 36061, - "FRAMEBUFFER_BINDING": 36006, - "RENDERBUFFER_BINDING": 36007, - "MAX_RENDERBUFFER_SIZE": 34024, - "INVALID_FRAMEBUFFER_OPERATION": 1286, - "UNPACK_FLIP_Y_WEBGL": 37440, - "UNPACK_PREMULTIPLY_ALPHA_WEBGL": 37441, - "CONTEXT_LOST_WEBGL": 37442, - "UNPACK_COLORSPACE_CONVERSION_WEBGL": 37443, - "BROWSER_DEFAULT_WEBGL": 37444 +export default { + "DEPTH_BUFFER_BIT": 256, + "STENCIL_BUFFER_BIT": 1024, + "COLOR_BUFFER_BIT": 16384, + "POINTS": 0, + "LINES": 1, + "LINE_LOOP": 2, + "LINE_STRIP": 3, + "TRIANGLES": 4, + "TRIANGLE_STRIP": 5, + "TRIANGLE_FAN": 6, + "ZERO": 0, + "ONE": 1, + "SRC_COLOR": 768, + "ONE_MINUS_SRC_COLOR": 769, + "SRC_ALPHA": 770, + "ONE_MINUS_SRC_ALPHA": 771, + "DST_ALPHA": 772, + "ONE_MINUS_DST_ALPHA": 773, + "DST_COLOR": 774, + "ONE_MINUS_DST_COLOR": 775, + "SRC_ALPHA_SATURATE": 776, + "FUNC_ADD": 32774, + "BLEND_EQUATION": 32777, + "BLEND_EQUATION_RGB": 32777, + "BLEND_EQUATION_ALPHA": 34877, + "FUNC_SUBTRACT": 32778, + "FUNC_REVERSE_SUBTRACT": 32779, + "BLEND_DST_RGB": 32968, + "BLEND_SRC_RGB": 32969, + "BLEND_DST_ALPHA": 32970, + "BLEND_SRC_ALPHA": 32971, + "CONSTANT_COLOR": 32769, + "ONE_MINUS_CONSTANT_COLOR": 32770, + "CONSTANT_ALPHA": 32771, + "ONE_MINUS_CONSTANT_ALPHA": 32772, + "BLEND_COLOR": 32773, + "ARRAY_BUFFER": 34962, + "ELEMENT_ARRAY_BUFFER": 34963, + "ARRAY_BUFFER_BINDING": 34964, + "ELEMENT_ARRAY_BUFFER_BINDING": 34965, + "STREAM_DRAW": 35040, + "STATIC_DRAW": 35044, + "DYNAMIC_DRAW": 35048, + "BUFFER_SIZE": 34660, + "BUFFER_USAGE": 34661, + "CURRENT_VERTEX_ATTRIB": 34342, + "FRONT": 1028, + "BACK": 1029, + "FRONT_AND_BACK": 1032, + "TEXTURE_2D": 3553, + "CULL_FACE": 2884, + "BLEND": 3042, + "DITHER": 3024, + "STENCIL_TEST": 2960, + "DEPTH_TEST": 2929, + "SCISSOR_TEST": 3089, + "POLYGON_OFFSET_FILL": 32823, + "SAMPLE_ALPHA_TO_COVERAGE": 32926, + "SAMPLE_COVERAGE": 32928, + "NO_ERROR": 0, + "INVALID_ENUM": 1280, + "INVALID_VALUE": 1281, + "INVALID_OPERATION": 1282, + "OUT_OF_MEMORY": 1285, + "CW": 2304, + "CCW": 2305, + "LINE_WIDTH": 2849, + "ALIASED_POINT_SIZE_RANGE": 33901, + "ALIASED_LINE_WIDTH_RANGE": 33902, + "CULL_FACE_MODE": 2885, + "FRONT_FACE": 2886, + "DEPTH_RANGE": 2928, + "DEPTH_WRITEMASK": 2930, + "DEPTH_CLEAR_VALUE": 2931, + "DEPTH_FUNC": 2932, + "STENCIL_CLEAR_VALUE": 2961, + "STENCIL_FUNC": 2962, + "STENCIL_FAIL": 2964, + "STENCIL_PASS_DEPTH_FAIL": 2965, + "STENCIL_PASS_DEPTH_PASS": 2966, + "STENCIL_REF": 2967, + "STENCIL_VALUE_MASK": 2963, + "STENCIL_WRITEMASK": 2968, + "STENCIL_BACK_FUNC": 34816, + "STENCIL_BACK_FAIL": 34817, + "STENCIL_BACK_PASS_DEPTH_FAIL": 34818, + "STENCIL_BACK_PASS_DEPTH_PASS": 34819, + "STENCIL_BACK_REF": 36003, + "STENCIL_BACK_VALUE_MASK": 36004, + "STENCIL_BACK_WRITEMASK": 36005, + "VIEWPORT": 2978, + "SCISSOR_BOX": 3088, + "COLOR_CLEAR_VALUE": 3106, + "COLOR_WRITEMASK": 3107, + "UNPACK_ALIGNMENT": 3317, + "PACK_ALIGNMENT": 3333, + "MAX_TEXTURE_SIZE": 3379, + "MAX_VIEWPORT_DIMS": 3386, + "SUBPIXEL_BITS": 3408, + "RED_BITS": 3410, + "GREEN_BITS": 3411, + "BLUE_BITS": 3412, + "ALPHA_BITS": 3413, + "DEPTH_BITS": 3414, + "STENCIL_BITS": 3415, + "POLYGON_OFFSET_UNITS": 10752, + "POLYGON_OFFSET_FACTOR": 32824, + "TEXTURE_BINDING_2D": 32873, + "SAMPLE_BUFFERS": 32936, + "SAMPLES": 32937, + "SAMPLE_COVERAGE_VALUE": 32938, + "SAMPLE_COVERAGE_INVERT": 32939, + "COMPRESSED_TEXTURE_FORMATS": 34467, + "DONT_CARE": 4352, + "FASTEST": 4353, + "NICEST": 4354, + "GENERATE_MIPMAP_HINT": 33170, + "BYTE": 5120, + "UNSIGNED_BYTE": 5121, + "SHORT": 5122, + "UNSIGNED_SHORT": 5123, + "INT": 5124, + "UNSIGNED_INT": 5125, + "FLOAT": 5126, + "DEPTH_COMPONENT": 6402, + "ALPHA": 6406, + "RGB": 6407, + "RGBA": 6408, + "LUMINANCE": 6409, + "LUMINANCE_ALPHA": 6410, + "UNSIGNED_SHORT_4_4_4_4": 32819, + "UNSIGNED_SHORT_5_5_5_1": 32820, + "UNSIGNED_SHORT_5_6_5": 33635, + "FRAGMENT_SHADER": 35632, + "VERTEX_SHADER": 35633, + "MAX_VERTEX_ATTRIBS": 34921, + "MAX_VERTEX_UNIFORM_VECTORS": 36347, + "MAX_VARYING_VECTORS": 36348, + "MAX_COMBINED_TEXTURE_IMAGE_UNITS": 35661, + "MAX_VERTEX_TEXTURE_IMAGE_UNITS": 35660, + "MAX_TEXTURE_IMAGE_UNITS": 34930, + "MAX_FRAGMENT_UNIFORM_VECTORS": 36349, + "SHADER_TYPE": 35663, + "DELETE_STATUS": 35712, + "LINK_STATUS": 35714, + "VALIDATE_STATUS": 35715, + "ATTACHED_SHADERS": 35717, + "ACTIVE_UNIFORMS": 35718, + "ACTIVE_ATTRIBUTES": 35721, + "SHADING_LANGUAGE_VERSION": 35724, + "CURRENT_PROGRAM": 35725, + "NEVER": 512, + "LESS": 513, + "EQUAL": 514, + "LEQUAL": 515, + "GREATER": 516, + "NOTEQUAL": 517, + "GEQUAL": 518, + "ALWAYS": 519, + "KEEP": 7680, + "REPLACE": 7681, + "INCR": 7682, + "DECR": 7683, + "INVERT": 5386, + "INCR_WRAP": 34055, + "DECR_WRAP": 34056, + "VENDOR": 7936, + "RENDERER": 7937, + "VERSION": 7938, + "NEAREST": 9728, + "LINEAR": 9729, + "NEAREST_MIPMAP_NEAREST": 9984, + "LINEAR_MIPMAP_NEAREST": 9985, + "NEAREST_MIPMAP_LINEAR": 9986, + "LINEAR_MIPMAP_LINEAR": 9987, + "TEXTURE_MAG_FILTER": 10240, + "TEXTURE_MIN_FILTER": 10241, + "TEXTURE_WRAP_S": 10242, + "TEXTURE_WRAP_T": 10243, + "TEXTURE": 5890, + "TEXTURE_CUBE_MAP": 34067, + "TEXTURE_BINDING_CUBE_MAP": 34068, + "TEXTURE_CUBE_MAP_POSITIVE_X": 34069, + "TEXTURE_CUBE_MAP_NEGATIVE_X": 34070, + "TEXTURE_CUBE_MAP_POSITIVE_Y": 34071, + "TEXTURE_CUBE_MAP_NEGATIVE_Y": 34072, + "TEXTURE_CUBE_MAP_POSITIVE_Z": 34073, + "TEXTURE_CUBE_MAP_NEGATIVE_Z": 34074, + "MAX_CUBE_MAP_TEXTURE_SIZE": 34076, + "TEXTURE0": 33984, + "TEXTURE1": 33985, + "TEXTURE2": 33986, + "TEXTURE3": 33987, + "TEXTURE4": 33988, + "TEXTURE5": 33989, + "TEXTURE6": 33990, + "TEXTURE7": 33991, + "TEXTURE8": 33992, + "TEXTURE9": 33993, + "TEXTURE10": 33994, + "TEXTURE11": 33995, + "TEXTURE12": 33996, + "TEXTURE13": 33997, + "TEXTURE14": 33998, + "TEXTURE15": 33999, + "TEXTURE16": 34000, + "TEXTURE17": 34001, + "TEXTURE18": 34002, + "TEXTURE19": 34003, + "TEXTURE20": 34004, + "TEXTURE21": 34005, + "TEXTURE22": 34006, + "TEXTURE23": 34007, + "TEXTURE24": 34008, + "TEXTURE25": 34009, + "TEXTURE26": 34010, + "TEXTURE27": 34011, + "TEXTURE28": 34012, + "TEXTURE29": 34013, + "TEXTURE30": 34014, + "TEXTURE31": 34015, + "ACTIVE_TEXTURE": 34016, + "REPEAT": 10497, + "CLAMP_TO_EDGE": 33071, + "MIRRORED_REPEAT": 33648, + "FLOAT_VEC2": 35664, + "FLOAT_VEC3": 35665, + "FLOAT_VEC4": 35666, + "INT_VEC2": 35667, + "INT_VEC3": 35668, + "INT_VEC4": 35669, + "BOOL": 35670, + "BOOL_VEC2": 35671, + "BOOL_VEC3": 35672, + "BOOL_VEC4": 35673, + "FLOAT_MAT2": 35674, + "FLOAT_MAT3": 35675, + "FLOAT_MAT4": 35676, + "SAMPLER_2D": 35678, + "SAMPLER_CUBE": 35680, + "VERTEX_ATTRIB_ARRAY_ENABLED": 34338, + "VERTEX_ATTRIB_ARRAY_SIZE": 34339, + "VERTEX_ATTRIB_ARRAY_STRIDE": 34340, + "VERTEX_ATTRIB_ARRAY_TYPE": 34341, + "VERTEX_ATTRIB_ARRAY_NORMALIZED": 34922, + "VERTEX_ATTRIB_ARRAY_POINTER": 34373, + "VERTEX_ATTRIB_ARRAY_BUFFER_BINDING": 34975, + "IMPLEMENTATION_COLOR_READ_TYPE": 35738, + "IMPLEMENTATION_COLOR_READ_FORMAT": 35739, + "COMPILE_STATUS": 35713, + "LOW_FLOAT": 36336, + "MEDIUM_FLOAT": 36337, + "HIGH_FLOAT": 36338, + "LOW_INT": 36339, + "MEDIUM_INT": 36340, + "HIGH_INT": 36341, + "FRAMEBUFFER": 36160, + "RENDERBUFFER": 36161, + "RGBA4": 32854, + "RGB5_A1": 32855, + "RGB565": 36194, + "DEPTH_COMPONENT16": 33189, + "STENCIL_INDEX8": 36168, + "DEPTH_STENCIL": 34041, + "RENDERBUFFER_WIDTH": 36162, + "RENDERBUFFER_HEIGHT": 36163, + "RENDERBUFFER_INTERNAL_FORMAT": 36164, + "RENDERBUFFER_RED_SIZE": 36176, + "RENDERBUFFER_GREEN_SIZE": 36177, + "RENDERBUFFER_BLUE_SIZE": 36178, + "RENDERBUFFER_ALPHA_SIZE": 36179, + "RENDERBUFFER_DEPTH_SIZE": 36180, + "RENDERBUFFER_STENCIL_SIZE": 36181, + "FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE": 36048, + "FRAMEBUFFER_ATTACHMENT_OBJECT_NAME": 36049, + "FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL": 36050, + "FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE": 36051, + "COLOR_ATTACHMENT0": 36064, + "DEPTH_ATTACHMENT": 36096, + "STENCIL_ATTACHMENT": 36128, + "DEPTH_STENCIL_ATTACHMENT": 33306, + "NONE": 0, + "FRAMEBUFFER_COMPLETE": 36053, + "FRAMEBUFFER_INCOMPLETE_ATTACHMENT": 36054, + "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT": 36055, + "FRAMEBUFFER_INCOMPLETE_DIMENSIONS": 36057, + "FRAMEBUFFER_UNSUPPORTED": 36061, + "FRAMEBUFFER_BINDING": 36006, + "RENDERBUFFER_BINDING": 36007, + "MAX_RENDERBUFFER_SIZE": 34024, + "INVALID_FRAMEBUFFER_OPERATION": 1286, + "UNPACK_FLIP_Y_WEBGL": 37440, + "UNPACK_PREMULTIPLY_ALPHA_WEBGL": 37441, + "CONTEXT_LOST_WEBGL": 37442, + "UNPACK_COLORSPACE_CONVERSION_WEBGL": 37443, + "BROWSER_DEFAULT_WEBGL": 37444 }; \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/GLmethod.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/GLmethod.js index f2659be..8ca2212 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/GLmethod.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/GLmethod.js @@ -1,142 +1,142 @@ -let i = 1; - -const GLmethod = {}; - -GLmethod.activeTexture = i++; //1 -GLmethod.attachShader = i++; -GLmethod.bindAttribLocation = i++; -GLmethod.bindBuffer = i++; -GLmethod.bindFramebuffer = i++; -GLmethod.bindRenderbuffer = i++; -GLmethod.bindTexture = i++; -GLmethod.blendColor = i++; -GLmethod.blendEquation = i++; -GLmethod.blendEquationSeparate = i++; //10 -GLmethod.blendFunc = i++; -GLmethod.blendFuncSeparate = i++; -GLmethod.bufferData = i++; -GLmethod.bufferSubData = i++; -GLmethod.checkFramebufferStatus = i++; -GLmethod.clear = i++; -GLmethod.clearColor = i++; -GLmethod.clearDepth = i++; -GLmethod.clearStencil = i++; -GLmethod.colorMask = i++; //20 -GLmethod.compileShader = i++; -GLmethod.compressedTexImage2D = i++; -GLmethod.compressedTexSubImage2D = i++; -GLmethod.copyTexImage2D = i++; -GLmethod.copyTexSubImage2D = i++; -GLmethod.createBuffer = i++; -GLmethod.createFramebuffer = i++; -GLmethod.createProgram = i++; -GLmethod.createRenderbuffer = i++; -GLmethod.createShader = i++; //30 -GLmethod.createTexture = i++; -GLmethod.cullFace = i++; -GLmethod.deleteBuffer = i++; -GLmethod.deleteFramebuffer = i++; -GLmethod.deleteProgram = i++; -GLmethod.deleteRenderbuffer = i++; -GLmethod.deleteShader = i++; -GLmethod.deleteTexture = i++; -GLmethod.depthFunc = i++; -GLmethod.depthMask = i++; //40 -GLmethod.depthRange = i++; -GLmethod.detachShader = i++; -GLmethod.disable = i++; -GLmethod.disableVertexAttribArray = i++; -GLmethod.drawArrays = i++; -GLmethod.drawArraysInstancedANGLE = i++; -GLmethod.drawElements = i++; -GLmethod.drawElementsInstancedANGLE = i++; -GLmethod.enable = i++; -GLmethod.enableVertexAttribArray = i++; //50 -GLmethod.flush = i++; -GLmethod.framebufferRenderbuffer = i++; -GLmethod.framebufferTexture2D = i++; -GLmethod.frontFace = i++; -GLmethod.generateMipmap = i++; -GLmethod.getActiveAttrib = i++; -GLmethod.getActiveUniform = i++; -GLmethod.getAttachedShaders = i++; -GLmethod.getAttribLocation = i++; -GLmethod.getBufferParameter = i++; //60 -GLmethod.getContextAttributes = i++; -GLmethod.getError = i++; -GLmethod.getExtension = i++; -GLmethod.getFramebufferAttachmentParameter = i++; -GLmethod.getParameter = i++; -GLmethod.getProgramInfoLog = i++; -GLmethod.getProgramParameter = i++; -GLmethod.getRenderbufferParameter = i++; -GLmethod.getShaderInfoLog = i++; -GLmethod.getShaderParameter = i++; //70 -GLmethod.getShaderPrecisionFormat = i++; -GLmethod.getShaderSource = i++; -GLmethod.getSupportedExtensions = i++; -GLmethod.getTexParameter = i++; -GLmethod.getUniform = i++; -GLmethod.getUniformLocation = i++; -GLmethod.getVertexAttrib = i++; -GLmethod.getVertexAttribOffset = i++; -GLmethod.isBuffer = i++; -GLmethod.isContextLost = i++; //80 -GLmethod.isEnabled = i++; -GLmethod.isFramebuffer = i++; -GLmethod.isProgram = i++; -GLmethod.isRenderbuffer = i++; -GLmethod.isShader = i++; -GLmethod.isTexture = i++; -GLmethod.lineWidth = i++; -GLmethod.linkProgram = i++; -GLmethod.pixelStorei = i++; -GLmethod.polygonOffset = i++; //90 -GLmethod.readPixels = i++; -GLmethod.renderbufferStorage = i++; -GLmethod.sampleCoverage = i++; -GLmethod.scissor = i++; -GLmethod.shaderSource = i++; -GLmethod.stencilFunc = i++; -GLmethod.stencilFuncSeparate = i++; -GLmethod.stencilMask = i++; -GLmethod.stencilMaskSeparate = i++; -GLmethod.stencilOp = i++; //100 -GLmethod.stencilOpSeparate = i++; -GLmethod.texImage2D = i++; -GLmethod.texParameterf = i++; -GLmethod.texParameteri = i++; -GLmethod.texSubImage2D = i++; -GLmethod.uniform1f = i++; -GLmethod.uniform1fv = i++; -GLmethod.uniform1i = i++; -GLmethod.uniform1iv = i++; -GLmethod.uniform2f = i++; //110 -GLmethod.uniform2fv = i++; -GLmethod.uniform2i = i++; -GLmethod.uniform2iv = i++; -GLmethod.uniform3f = i++; -GLmethod.uniform3fv = i++; -GLmethod.uniform3i = i++; -GLmethod.uniform3iv = i++; -GLmethod.uniform4f = i++; -GLmethod.uniform4fv = i++; -GLmethod.uniform4i = i++; //120 -GLmethod.uniform4iv = i++; -GLmethod.uniformMatrix2fv = i++; -GLmethod.uniformMatrix3fv = i++; -GLmethod.uniformMatrix4fv = i++; -GLmethod.useProgram = i++; -GLmethod.validateProgram = i++; -GLmethod.vertexAttrib1f = i++; //new -GLmethod.vertexAttrib2f = i++; //new -GLmethod.vertexAttrib3f = i++; //new -GLmethod.vertexAttrib4f = i++; //new //130 -GLmethod.vertexAttrib1fv = i++; //new -GLmethod.vertexAttrib2fv = i++; //new -GLmethod.vertexAttrib3fv = i++; //new -GLmethod.vertexAttrib4fv = i++; //new -GLmethod.vertexAttribPointer = i++; -GLmethod.viewport = i++; - +let i = 1; + +const GLmethod = {}; + +GLmethod.activeTexture = i++; //1 +GLmethod.attachShader = i++; +GLmethod.bindAttribLocation = i++; +GLmethod.bindBuffer = i++; +GLmethod.bindFramebuffer = i++; +GLmethod.bindRenderbuffer = i++; +GLmethod.bindTexture = i++; +GLmethod.blendColor = i++; +GLmethod.blendEquation = i++; +GLmethod.blendEquationSeparate = i++; //10 +GLmethod.blendFunc = i++; +GLmethod.blendFuncSeparate = i++; +GLmethod.bufferData = i++; +GLmethod.bufferSubData = i++; +GLmethod.checkFramebufferStatus = i++; +GLmethod.clear = i++; +GLmethod.clearColor = i++; +GLmethod.clearDepth = i++; +GLmethod.clearStencil = i++; +GLmethod.colorMask = i++; //20 +GLmethod.compileShader = i++; +GLmethod.compressedTexImage2D = i++; +GLmethod.compressedTexSubImage2D = i++; +GLmethod.copyTexImage2D = i++; +GLmethod.copyTexSubImage2D = i++; +GLmethod.createBuffer = i++; +GLmethod.createFramebuffer = i++; +GLmethod.createProgram = i++; +GLmethod.createRenderbuffer = i++; +GLmethod.createShader = i++; //30 +GLmethod.createTexture = i++; +GLmethod.cullFace = i++; +GLmethod.deleteBuffer = i++; +GLmethod.deleteFramebuffer = i++; +GLmethod.deleteProgram = i++; +GLmethod.deleteRenderbuffer = i++; +GLmethod.deleteShader = i++; +GLmethod.deleteTexture = i++; +GLmethod.depthFunc = i++; +GLmethod.depthMask = i++; //40 +GLmethod.depthRange = i++; +GLmethod.detachShader = i++; +GLmethod.disable = i++; +GLmethod.disableVertexAttribArray = i++; +GLmethod.drawArrays = i++; +GLmethod.drawArraysInstancedANGLE = i++; +GLmethod.drawElements = i++; +GLmethod.drawElementsInstancedANGLE = i++; +GLmethod.enable = i++; +GLmethod.enableVertexAttribArray = i++; //50 +GLmethod.flush = i++; +GLmethod.framebufferRenderbuffer = i++; +GLmethod.framebufferTexture2D = i++; +GLmethod.frontFace = i++; +GLmethod.generateMipmap = i++; +GLmethod.getActiveAttrib = i++; +GLmethod.getActiveUniform = i++; +GLmethod.getAttachedShaders = i++; +GLmethod.getAttribLocation = i++; +GLmethod.getBufferParameter = i++; //60 +GLmethod.getContextAttributes = i++; +GLmethod.getError = i++; +GLmethod.getExtension = i++; +GLmethod.getFramebufferAttachmentParameter = i++; +GLmethod.getParameter = i++; +GLmethod.getProgramInfoLog = i++; +GLmethod.getProgramParameter = i++; +GLmethod.getRenderbufferParameter = i++; +GLmethod.getShaderInfoLog = i++; +GLmethod.getShaderParameter = i++; //70 +GLmethod.getShaderPrecisionFormat = i++; +GLmethod.getShaderSource = i++; +GLmethod.getSupportedExtensions = i++; +GLmethod.getTexParameter = i++; +GLmethod.getUniform = i++; +GLmethod.getUniformLocation = i++; +GLmethod.getVertexAttrib = i++; +GLmethod.getVertexAttribOffset = i++; +GLmethod.isBuffer = i++; +GLmethod.isContextLost = i++; //80 +GLmethod.isEnabled = i++; +GLmethod.isFramebuffer = i++; +GLmethod.isProgram = i++; +GLmethod.isRenderbuffer = i++; +GLmethod.isShader = i++; +GLmethod.isTexture = i++; +GLmethod.lineWidth = i++; +GLmethod.linkProgram = i++; +GLmethod.pixelStorei = i++; +GLmethod.polygonOffset = i++; //90 +GLmethod.readPixels = i++; +GLmethod.renderbufferStorage = i++; +GLmethod.sampleCoverage = i++; +GLmethod.scissor = i++; +GLmethod.shaderSource = i++; +GLmethod.stencilFunc = i++; +GLmethod.stencilFuncSeparate = i++; +GLmethod.stencilMask = i++; +GLmethod.stencilMaskSeparate = i++; +GLmethod.stencilOp = i++; //100 +GLmethod.stencilOpSeparate = i++; +GLmethod.texImage2D = i++; +GLmethod.texParameterf = i++; +GLmethod.texParameteri = i++; +GLmethod.texSubImage2D = i++; +GLmethod.uniform1f = i++; +GLmethod.uniform1fv = i++; +GLmethod.uniform1i = i++; +GLmethod.uniform1iv = i++; +GLmethod.uniform2f = i++; //110 +GLmethod.uniform2fv = i++; +GLmethod.uniform2i = i++; +GLmethod.uniform2iv = i++; +GLmethod.uniform3f = i++; +GLmethod.uniform3fv = i++; +GLmethod.uniform3i = i++; +GLmethod.uniform3iv = i++; +GLmethod.uniform4f = i++; +GLmethod.uniform4fv = i++; +GLmethod.uniform4i = i++; //120 +GLmethod.uniform4iv = i++; +GLmethod.uniformMatrix2fv = i++; +GLmethod.uniformMatrix3fv = i++; +GLmethod.uniformMatrix4fv = i++; +GLmethod.useProgram = i++; +GLmethod.validateProgram = i++; +GLmethod.vertexAttrib1f = i++; //new +GLmethod.vertexAttrib2f = i++; //new +GLmethod.vertexAttrib3f = i++; //new +GLmethod.vertexAttrib4f = i++; //new //130 +GLmethod.vertexAttrib1fv = i++; //new +GLmethod.vertexAttrib2fv = i++; //new +GLmethod.vertexAttrib3fv = i++; //new +GLmethod.vertexAttrib4fv = i++; //new +GLmethod.vertexAttribPointer = i++; +GLmethod.viewport = i++; + export default GLmethod; \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/GLtype.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/GLtype.js index 695abcb..d7d81bb 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/GLtype.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/GLtype.js @@ -1,23 +1,23 @@ -const GLtype = {}; - -[ - "GLbitfield", - "GLboolean", - "GLbyte", - "GLclampf", - "GLenum", - "GLfloat", - "GLint", - "GLintptr", - "GLsizei", - "GLsizeiptr", - "GLshort", - "GLubyte", - "GLuint", - "GLushort" -].sort().map((typeName, i) => GLtype[typeName] = 1 >> (i + 1)); - -export default GLtype; - - - +const GLtype = {}; + +[ + "GLbitfield", + "GLboolean", + "GLbyte", + "GLclampf", + "GLenum", + "GLfloat", + "GLint", + "GLintptr", + "GLsizei", + "GLsizeiptr", + "GLshort", + "GLubyte", + "GLuint", + "GLushort" +].sort().map((typeName, i) => GLtype[typeName] = 1 >> (i + 1)); + +export default GLtype; + + + diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Program.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Program.js index 6f5691c..bd69737 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Program.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Program.js @@ -1,21 +1,21 @@ -import {getTransferedObjectUUID} from './classUtils'; - -const name = 'WebGLProgram'; - -function uuid(id) { - return getTransferedObjectUUID(name, id); -} - -export default class WebGLProgram { - className = name; - - constructor(id) { - this.id = id; - } - - static uuid = uuid; - - uuid() { - return uuid(this.id); - } +import {getTransferedObjectUUID} from './classUtils'; + +const name = 'WebGLProgram'; + +function uuid(id) { + return getTransferedObjectUUID(name, id); +} + +export default class WebGLProgram { + className = name; + + constructor(id) { + this.id = id; + } + + static uuid = uuid; + + uuid() { + return uuid(this.id); + } } \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Renderbuffer.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Renderbuffer.js index d3182ae..3f500f0 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Renderbuffer.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Renderbuffer.js @@ -1,21 +1,21 @@ -import {getTransferedObjectUUID} from './classUtils'; - -const name = 'WebGLRenderBuffer'; - -function uuid(id) { - return getTransferedObjectUUID(name, id); -} - -export default class WebGLRenderbuffer { - className = name; - - constructor(id) { - this.id = id; - } - - static uuid = uuid; - - uuid() { - return uuid(this.id); - } +import {getTransferedObjectUUID} from './classUtils'; + +const name = 'WebGLRenderBuffer'; + +function uuid(id) { + return getTransferedObjectUUID(name, id); +} + +export default class WebGLRenderbuffer { + className = name; + + constructor(id) { + this.id = id; + } + + static uuid = uuid; + + uuid() { + return uuid(this.id); + } } \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/RenderingContext.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/RenderingContext.js index 5f9608f..c004883 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/RenderingContext.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/RenderingContext.js @@ -1,1191 +1,1191 @@ -import GLenum from './GLenum'; -import ActiveInfo from './ActiveInfo'; -import Buffer from './Buffer'; -import Framebuffer from './Framebuffer'; -import Renderbuffer from './Renderbuffer'; -import Texture from './Texture'; -import Program from './Program'; -import Shader from './Shader'; -import ShaderPrecisionFormat from './ShaderPrecisionFormat'; -import UniformLocation from './UniformLocation'; -import GLmethod from './GLmethod'; - -const processArray = (array, checkArrayType = false) => { - - function joinArray(arr, sep) { - let res = ''; - for (let i = 0; i < arr.length; i++) { - if (i !== 0) { - res += sep; - } - res += arr[i]; - } - return res; - } - - let type = 'Float32Array'; - if (checkArrayType) { - if (array instanceof Uint8Array) { - type = 'Uint8Array' - } else if (array instanceof Uint16Array) { - type = 'Uint16Array'; - } else if (array instanceof Uint32Array) { - type = 'Uint32Array'; - } else if (array instanceof Float32Array) { - type = 'Float32Array'; - } else { - throw new Error('Check array type failed. Array type is ' + typeof array); - } - } - - const ArrayTypes = { - Uint8Array: 1, - Uint16Array: 2, - Uint32Array: 4, - Float32Array: 14 - }; - return ArrayTypes[type] + ',' + btoa(joinArray(array, ',')) -} - -export default class WebGLRenderingContext { - - // static GBridge = null; - - className = 'WebGLRenderingContext'; - - constructor(canvas, type, attrs) { - this._canvas = canvas; - this._type = type; - this._version = 'WebGL 1.0'; - this._attrs = attrs; - this._map = new Map(); - - Object.keys(GLenum) - .forEach(name => Object.defineProperty(this, name, { - value: GLenum[name] - })); - } - - get canvas() { - return this._canvas; - } - - activeTexture = function (textureUnit) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.activeTexture + ',' + textureUnit, - true - ); - } - - attachShader = function (progarm, shader) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.attachShader + ',' + progarm.id + ',' + shader.id, - true - ); - } - - bindAttribLocation = function (program, index, name) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.bindAttribLocation + ',' + program.id + ',' + index + ',' + name, - true - ) - } - - bindBuffer = function (target, buffer) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.bindBuffer + ',' + target + ',' + (buffer ? buffer.id : 0), - true - ); - } - - bindFramebuffer = function (target, framebuffer) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.bindFramebuffer + ',' + target + ',' + (framebuffer ? framebuffer.id : 0), - true - ) - } - - bindRenderbuffer = function (target, renderBuffer) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.bindRenderbuffer + ',' + target + ',' + (renderBuffer ? renderBuffer.id : 0), - true - ) - } - - bindTexture = function (target, texture) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.bindTexture + ',' + target + ',' + (texture ? texture.id : 0), - true - ) - } - - blendColor = function (r, g, b, a) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.blendColor + ',' + target + ',' + r + ',' + g + ',' + b + ',' + a, - true - ) - } - - blendEquation = function (mode) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.blendEquation + ',' + mode, - true - ) - } - - blendEquationSeparate = function (modeRGB, modeAlpha) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.blendEquationSeparate + ',' + modeRGB + ',' + modeAlpha, - true - ) - } - - - blendFunc = function (sfactor, dfactor) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.blendFunc + ',' + sfactor + ',' + dfactor, - true - ); - } - - blendFuncSeparate = function (srcRGB, dstRGB, srcAlpha, dstAlpha) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.blendFuncSeparate + ',' + srcRGB + ',' + dstRGB + ',' + srcAlpha + ',' + dstAlpha, - true - ); - } - - bufferData = function (target, data, usage) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.bufferData + ',' + target + ',' + processArray(data, true) + ',' + usage, - true - ) - } - - bufferSubData = function (target, offset, data) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.bufferSubData + ',' + target + ',' + offset + ',' + processArray(data, true), - true - ) - } - - checkFramebufferStatus = function (target) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.checkFramebufferStatus + ',' + target - ); - return Number(result); - } - - clear = function (mask) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.clear + ',' + mask - ); - this._canvas._needRender = true; - } - - clearColor = function (r, g, b, a) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.clearColor + ',' + r + ',' + g + ',' + b, - true - ) - } - - clearDepth = function (depth) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.clearDepth + ',' + depth, - true - ) - } - - clearStencil = function (s) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.clearStencil + ',' + s - ); - } - - colorMask = function (r, g, b, a) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.colorMask + ',' + r + ',' + g + ',' + b + ',' + a - ) - } - - compileShader = function (shader) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.compileShader + ',' + shader.id, - true - ) - } - - compressedTexImage2D = function (target, level, internalformat, width, height, border, pixels) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.compressedTexImage2D + ',' + target + ',' + level + ',' + internalformat + ',' + - width + ',' + height + ',' + border + ',' + processArray(pixels), - true - ) - } - - compressedTexSubImage2D = function (target, level, xoffset, yoffset, width, height, format, pixels) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.compressedTexSubImage2D + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' + - width + ',' + height + ',' + format + ',' + processArray(pixels), - true - ) - } - - - copyTexImage2D = function (target, level, internalformat, x, y, width, height, border) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.copyTexImage2D + ',' + target + ',' + level + ',' + internalformat + ',' + x + ',' + y + ',' + - width + ',' + height + ',' + border, - true - ); - } - - copyTexSubImage2D = function (target, level, xoffset, yoffset, x, y, width, height) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.copyTexSubImage2D + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' + x + ',' + y + ',' + - width + ',' + height - ); - } - - createBuffer = function () { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.createBuffer + '' - ); - const buffer = new Buffer(result); - this._map.set(buffer.uuid(), buffer); - return buffer; - } - - createFramebuffer = function () { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.createFramebuffer + '' - ); - const framebuffer = new Framebuffer(result); - this._map.set(framebuffer.uuid(), framebuffer); - return framebuffer; - } - - - createProgram = function () { - const id = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.createProgram + '' - ); - const program = new Program(id); - this._map.set(program.uuid(), program); - return program; - } - - createRenderbuffer = function () { - const id = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.createRenderbuffer + '' - ) - const renderBuffer = new Renderbuffer(id); - this._map.set(renderBuffer.uuid(), renderBuffer); - return renderBuffer; - } - - createShader = function (type) { - const id = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.createShader + ',' + type - ) - const shader = new Shader(id, type); - this._map.set(shader.uuid(), shader); - return shader; - } - - createTexture = function () { - const id = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.createTexture + '' - ); - const texture = new Texture(id); - this._map.set(texture.uuid(), texture); - return texture; - } - - cullFace = function (mode) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.cullFace + ',' + mode, - true - ) - } - - - deleteBuffer = function (buffer) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.deleteBuffer + ',' + buffer.id, - true - ) - } - - deleteFramebuffer = function (framebuffer) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.deleteFramebuffer + ',' + framebuffer.id, - true - ) - } - - deleteProgram = function (program) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.deleteProgram + ',' + program.id, - true - ) - } - - deleteRenderbuffer = function (renderbuffer) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.deleteRenderbuffer + ',' + renderbuffer.id, - true - ) - } - - deleteShader = function (shader) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.deleteShader + ',' + shader.id, - true - ) - } - - deleteTexture = function (texture) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.deleteTexture + ',' + texture.id, - true - ) - } - - depthFunc = function (func) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.depthFunc + ',' + func - ) - } - - depthMask = function (flag) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.depthMask + ',' + Number(flag), - true - ) - } - - depthRange = function (zNear, zFar) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.depthRange + ',' + zNear + ',' + zFar, - true - ) - } - - detachShader = function (program, shader) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.detachShader + ',' + program.id + ',' + shader.id, - true - ) - } - - disable = function (cap) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.disable + ',' + cap, - true - ) - } - - disableVertexAttribArray = function (index) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.disableVertexAttribArray + ',' + index, - true - ); - } - - drawArrays = function (mode, first, count) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.drawArrays + ',' + mode + ',' + first + ',' + count - ) - this._canvas._needRender = true; - } - - drawElements = function (mode, count, type, offset) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.drawElements + ',' + mode + ',' + count + ',' + type + ',' + offset + ';' - ); - this._canvas._needRender = true; - } - - enable = function (cap) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.enable + ',' + cap, - true - ); - } - - enableVertexAttribArray = function (index) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.enableVertexAttribArray + ',' + index, - true - ) - } - - - flush = function () { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.flush + '' - ) - } - - framebufferRenderbuffer = function (target, attachment, textarget, texture, level) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.framebufferRenderbuffer + ',' + target + ',' + attachment + ',' + textarget + ',' + (texture ? texture.id : 0) + ',' + level, - true - ) - } - - framebufferTexture2D = function (target, attachment, textarget, texture, level) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.framebufferTexture2D + ',' + target + ',' + attachment + ',' + textarget + ',' + (texture ? texture.id : 0) + ',' + level, - true - ) - } - - frontFace = function (mode) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.frontFace + ',' + mode, - true - ) - } - - generateMipmap = function (target) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.generateMipmap + ',' + target, - true - ) - } - - getActiveAttrib = function (progarm, index) { - const resultString = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getActiveAttrib + ',' + progarm.id + ',' + index - ) - const [type, size, name] = resultString.split(','); - return new ActiveInfo({ - type: Number(type), - size: Number(size), - name - }); - } - - getActiveUniform = function (progarm, index) { - const resultString = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getActiveUniform + ',' + progarm.id + ',' + index - ); - const [type, size, name] = resultString.split(','); - return new ActiveInfo({ - type: Number(type), - size: Number(size), - name - }) - } - - getAttachedShaders = function (progarm) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getAttachedShaders + ',' + progarm.id - ); - const [type, ...ids] = result; - return ids.map(id => this._map.get(Shader.uuid(id))); - } - - getAttribLocation = function (progarm, name) { - return WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getAttribLocation + ',' + progarm.id + ',' + name - ) - } - - getBufferParameter = function (target, pname) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getBufferParameter + ',' + target + ',' + pname - ); - const [type, res] = getBufferParameter; - return res; - } - - getError = function () { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getError + '' - ) - return result; - } - - getExtension = function (name) { - return null; - } - - getFramebufferAttachmentParameter = function (target, attachment, pname) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getFramebufferAttachmentParameter + ',' + target + ',' + attachment + ',' + pname - ) - switch (pname) { - case GLenum.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: - return this._map.get(Renderbuffer.uuid(result)) || this._map.get(Texture.uuid(result)) || null; - default: - return result; - } - } - - getParameter = function (pname) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getParameter + ',' + pname - ) - switch (pname) { - case GLenum.VERSION: - return this._version; - case GLenum.ARRAY_BUFFER_BINDING: // buffer - case GLenum.ELEMENT_ARRAY_BUFFER_BINDING: // buffer - return this._map.get(Buffer.uuid(result)) || null; - case GLenum.CURRENT_PROGRAM: // program - return this._map.get(Program.uuid(result)) || null; - case GLenum.FRAMEBUFFER_BINDING: // framebuffer - return this._map.get(Framebuffer.uuid(result)) || null; - case GLenum.RENDERBUFFER_BINDING: // renderbuffer - return this._map.get(Renderbuffer.uuid(result)) || null; - case GLenum.TEXTURE_BINDING_2D: // texture - case GLenum.TEXTURE_BINDING_CUBE_MAP: // texture - return this._map.get(Texture.uuid(result)) || null; - case GLenum.ALIASED_LINE_WIDTH_RANGE: // Float32Array - case GLenum.ALIASED_POINT_SIZE_RANGE: // Float32Array - case GLenum.BLEND_COLOR: // Float32Array - case GLenum.COLOR_CLEAR_VALUE: // Float32Array - case GLenum.DEPTH_RANGE: // Float32Array - case GLenum.MAX_VIEWPORT_DIMS: // Int32Array - case GLenum.SCISSOR_BOX: // Int32Array - case GLenum.VIEWPORT: // Int32Array - case GLenum.COMPRESSED_TEXTURE_FORMATS: // Uint32Array - default: - const [type, ...res] = result.split(','); - if (res.length === 1) { - return Number(res[0]); - } else { - return res.map(Number); - } - } - } - - getProgramInfoLog = function (progarm) { - return WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getProgramInfoLog + ',' + progarm.id - ) - } - - getProgramParameter = function (program, pname) { - const res = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getProgramParameter + ',' + program.id + ',' + pname - ); - - const [type, result] = res.split(',').map(i => parseInt(i)); - - if (type === 1) { - return Boolean(result); - } else if (type === 2) { - return result; - } else { - throw new Error('Unrecongized program paramater ' + res + ', type: ' + typeof res); - } - } - - - getRenderbufferParameter = function (target, pname) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getRenderbufferParameter + ',' + target + ',' + pname - ) - return result; - } - - - getShaderInfoLog = function (shader) { - return WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getShaderInfoLog + ',' + shader.id - ); - } - - getShaderParameter = function (shader, pname) { - return WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getShaderParameter + ',' + shader.id + ',' + pname - ) - } - - getShaderPrecisionFormat = function (shaderType, precisionType) { - const [rangeMin, rangeMax, precision] = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getShaderPrecisionFormat + ',' + shaderType + ',' + precisionType - ); - const shaderPrecisionFormat = new ShaderPrecisionFormat({ - rangeMin: Number(rangeMin), - rangeMax: Number(rangeMax), - precision: Number(precision) - }); - return shaderPrecisionFormat; - } - - getShaderSource = function (shader) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getShaderSource + ',' + shader.id - ); - return result; - } - - getSupportedExtensions = function () { - return Object.keys({}); - } - - getTexParameter = function (target, pname) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getTexParameter + ',' + target + ',' + pname - ) - return result; - } - - getUniformLocation = function (program, name) { - const id = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getUniformLocation + ',' + program.id + ',' + name - ); - if (id === -1) { - return null; - } else { - return new UniformLocation(Number(id)); - } - } - - getVertexAttrib = function (index, pname) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getVertexAttrib + ',' + index + ',' + pname - ); - switch (pname) { - case GLenum.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: - return this._map.get(Buffer.uuid(result)) || null; - case GLenum.CURRENT_VERTEX_ATTRIB: // Float32Array - default: - return result; - } - } - - getVertexAttribOffset = function (index, pname) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.getVertexAttribOffset + ',' + index + ',' + pname - ) - return Number(result); - } - - isBuffer = function (buffer) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.isBuffer + ',' + buffer.id - ) - return Boolean(result); - } - - isContextLost = function () { - return false; - } - - isEnabled = function (cap) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.isEnabled + ',' + cap - ) - return Boolean(result); - } - - isFramebuffer = function (framebuffer) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.isFramebuffer + ',' + framebuffer.id - ) - return Boolean(result); - } - - isProgram = function (program) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.isProgram + ',' + program.id - ) - return Boolean(result); - } - - isRenderbuffer = function (renderBuffer) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.isRenderbuffer + ',' + renderbuffer.id - ) - return Boolean(result); - } - - isShader = function (shader) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.isShader + ',' + shader.id - ) - return Boolean(result); - } - - isTexture = function (texture) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.isTexture + ',' + texture.id - ); - return Boolean(result); - } - - lineWidth = function (width) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.lineWidth + ',' + width, - true - ) - } - - linkProgram = function (program) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.linkProgram + ',' + program.id, - true - ); - } - - - pixelStorei = function (pname, param) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.pixelStorei + ',' + pname + ',' + Number(param) - ) - } - - polygonOffset = function (factor, units) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.polygonOffset + ',' + factor + ',' + units - ) - } - - readPixels = function (x, y, width, height, format, type, pixels) { - const result = WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.readPixels + ',' + x + ',' + y + ',' + width + ',' + height + ',' + format + ',' + type - ) - return result; - } - - renderbufferStorage = function (target, internalFormat, width, height) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.renderbufferStorage + ',' + target + ',' + internalFormat + ',' + width + ',' + height, - true - ) - } - - sampleCoverage = function (value, invert) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.sampleCoverage + ',' + value + ',' + Number(invert), - true - ) - } - - scissor = function (x, y, width, height) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.scissor + ',' + x + ',' + y + ',' + width + ',' + height, - true - ) - } - - shaderSource = function (shader, source) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.shaderSource + ',' + shader.id + ',' + source - ) - } - - stencilFunc = function (func, ref, mask) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.stencilFunc + ',' + func + ',' + ref + ',' + mask, - true - ) - } - - stencilFuncSeparate = function (face, func, ref, mask) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.stencilFuncSeparate + ',' + face + ',' + func + ',' + ref + ',' + mask, - true - ) - } - - stencilMask = function (mask) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.stencilMask + ',' + mask, - true - ) - } - - stencilMaskSeparate = function (face, mask) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.stencilMaskSeparate + ',' + face + ',' + mask, - true - ) - } - - stencilOp = function (fail, zfail, zpass) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.stencilOp + ',' + fail + ',' + zfail + ',' + zpass - ) - } - - stencilOpSeparate = function (face, fail, zfail, zpass) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.stencilOp + ',' + face + ',' + fail + ',' + zfail + ',' + zpass, - true - ) - } - - texImage2D = function (...args) { - WebGLRenderingContext.GBridge.texImage2D(this._canvas.id, ...args); - } - - - texParameterf = function (target, pname, param) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.texParameterf + ',' + target + ',' + pname + ',' + param, - true - ) - } - - texParameteri = function (target, pname, param) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.texParameteri + ',' + target + ',' + pname + ',' + param - ) - } - - texSubImage2D = function (...args) { - WebGLRenderingContext.GBridge.texSubImage2D(this._canvas.id, ...args); - } - - uniform1f = function (location, v0) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform1f + ',' + location.id + ',' + v0 - ) - } - - uniform1fv = function (location, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform1fv + ',' + location.id + ',' + processArray(value), - true - ) - } - - uniform1i = function (location, v0) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform1i + ',' + location.id + ',' + v0, - // true - ) - } - - uniform1iv = function (location, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform1iv + ',' + location.id + ',' + processArray(value), - true - ) - } - - uniform2f = function (location, v0, v1) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform2f + ',' + location.id + ',' + v0 + ',' + v1, - true - ) - } - - uniform2fv = function (location, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform2fv + ',' + location.id + ',' + processArray(value), - true - ) - } - - uniform2i = function (location, v0, v1) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform2i + ',' + location.id + ',' + v0 + ',' + v1, - true - ) - } - - uniform2iv = function (location, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform2iv + ',' + location.id + ',' + processArray(value), - true - ) - } - - uniform3f = function (location, v0, v1, v2) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform3f + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2, - true - ) - } - - uniform3fv = function (location, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform3fv + ',' + location.id + ',' + processArray(value), - true - ) - } - - uniform3i = function (location, v0, v1, v2) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform3i + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2, - true - ) - } - - uniform3iv = function (location, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform3iv + ',' + location.id + ',' + processArray(value), - true - ) - } - - uniform4f = function (location, v0, v1, v2, v3) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform4f + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2 + ',' + v3, - true - ) - } - - uniform4fv = function (location, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform4fv + ',' + location.id + ',' + processArray(value), - true - ) - } - - uniform4i = function (location, v0, v1, v2, v3) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform4i + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2 + ',' + v3, - true - ) - } - - uniform4iv = function (location, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniform4iv + ',' + location.id + ',' + processArray(value, true), - true - ) - } - - uniformMatrix2fv = function (location, transpose, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniformMatrix2fv + ',' + location.id + ',' + Number(transpose) + ',' + processArray(value), - true - ) - } - - uniformMatrix3fv = function (location, transpose, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniformMatrix3fv + ',' + location.id + ',' + Number(transpose) + ',' + processArray(value), - true - ) - } - - uniformMatrix4fv = function (location, transpose, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.uniformMatrix4fv + ',' + location.id + ',' + Number(transpose) + ',' + processArray(value), - true - ); - } - - useProgram = function (progarm) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.useProgram + ',' + progarm.id + '', - true - ) - } - - - validateProgram = function (program) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.validateProgram + ',' + program.id, - true - ) - } - - vertexAttrib1f = function (index, v0) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.vertexAttrib1f + ',' + index + ',' + v0, - true - ) - } - - vertexAttrib2f = function (index, v0, v1) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.vertexAttrib2f + ',' + index + ',' + v0 + ',' + v1, - true - ) - } - - vertexAttrib3f = function (index, v0, v1, v2) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.vertexAttrib3f + ',' + index + ',' + v0 + ',' + v1 + ',' + v2, - true - ) - } - - vertexAttrib4f = function (index, v0, v1, v2, v3) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.vertexAttrib4f + ',' + index + ',' + v0 + ',' + v1 + ',' + v2 + ',' + v3, - true - ) - } - - vertexAttrib1fv = function (index, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.vertexAttrib1fv + ',' + index + ',' + processArray(value), - true - ) - } - - vertexAttrib2fv = function (index, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.vertexAttrib2fv + ',' + index + ',' + processArray(value), - true - ) - } - - vertexAttrib3fv = function (index, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.vertexAttrib3fv + ',' + index + ',' + processArray(value), - true - ) - } - - vertexAttrib4fv = function (index, value) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.vertexAttrib4fv + ',' + index + ',' + processArray(value), - true - ) - } - - vertexAttribPointer = function (index, size, type, normalized, stride, offset) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.vertexAttribPointer + ',' + index + ',' + size + ',' + type + ',' + Number(normalized) + ',' + stride + ',' + offset, - true - ) - } - - viewport = function (x, y, width, height) { - WebGLRenderingContext.GBridge.callNative( - this._canvas.id, - GLmethod.viewport + ',' + x + ',' + y + ',' + width + ',' + height, - true - ) - } +import GLenum from './GLenum'; +import ActiveInfo from './ActiveInfo'; +import Buffer from './Buffer'; +import Framebuffer from './Framebuffer'; +import Renderbuffer from './Renderbuffer'; +import Texture from './Texture'; +import Program from './Program'; +import Shader from './Shader'; +import ShaderPrecisionFormat from './ShaderPrecisionFormat'; +import UniformLocation from './UniformLocation'; +import GLmethod from './GLmethod'; + +const processArray = (array, checkArrayType = false) => { + + function joinArray(arr, sep) { + let res = ''; + for (let i = 0; i < arr.length; i++) { + if (i !== 0) { + res += sep; + } + res += arr[i]; + } + return res; + } + + let type = 'Float32Array'; + if (checkArrayType) { + if (array instanceof Uint8Array) { + type = 'Uint8Array' + } else if (array instanceof Uint16Array) { + type = 'Uint16Array'; + } else if (array instanceof Uint32Array) { + type = 'Uint32Array'; + } else if (array instanceof Float32Array) { + type = 'Float32Array'; + } else { + throw new Error('Check array type failed. Array type is ' + typeof array); + } + } + + const ArrayTypes = { + Uint8Array: 1, + Uint16Array: 2, + Uint32Array: 4, + Float32Array: 14 + }; + return ArrayTypes[type] + ',' + btoa(joinArray(array, ',')) +} + +export default class WebGLRenderingContext { + + // static GBridge = null; + + className = 'WebGLRenderingContext'; + + constructor(canvas, type, attrs) { + this._canvas = canvas; + this._type = type; + this._version = 'WebGL 1.0'; + this._attrs = attrs; + this._map = new Map(); + + Object.keys(GLenum) + .forEach(name => Object.defineProperty(this, name, { + value: GLenum[name] + })); + } + + get canvas() { + return this._canvas; + } + + activeTexture = function (textureUnit) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.activeTexture + ',' + textureUnit, + true + ); + } + + attachShader = function (progarm, shader) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.attachShader + ',' + progarm.id + ',' + shader.id, + true + ); + } + + bindAttribLocation = function (program, index, name) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.bindAttribLocation + ',' + program.id + ',' + index + ',' + name, + true + ) + } + + bindBuffer = function (target, buffer) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.bindBuffer + ',' + target + ',' + (buffer ? buffer.id : 0), + true + ); + } + + bindFramebuffer = function (target, framebuffer) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.bindFramebuffer + ',' + target + ',' + (framebuffer ? framebuffer.id : 0), + true + ) + } + + bindRenderbuffer = function (target, renderBuffer) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.bindRenderbuffer + ',' + target + ',' + (renderBuffer ? renderBuffer.id : 0), + true + ) + } + + bindTexture = function (target, texture) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.bindTexture + ',' + target + ',' + (texture ? texture.id : 0), + true + ) + } + + blendColor = function (r, g, b, a) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.blendColor + ',' + target + ',' + r + ',' + g + ',' + b + ',' + a, + true + ) + } + + blendEquation = function (mode) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.blendEquation + ',' + mode, + true + ) + } + + blendEquationSeparate = function (modeRGB, modeAlpha) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.blendEquationSeparate + ',' + modeRGB + ',' + modeAlpha, + true + ) + } + + + blendFunc = function (sfactor, dfactor) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.blendFunc + ',' + sfactor + ',' + dfactor, + true + ); + } + + blendFuncSeparate = function (srcRGB, dstRGB, srcAlpha, dstAlpha) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.blendFuncSeparate + ',' + srcRGB + ',' + dstRGB + ',' + srcAlpha + ',' + dstAlpha, + true + ); + } + + bufferData = function (target, data, usage) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.bufferData + ',' + target + ',' + processArray(data, true) + ',' + usage, + true + ) + } + + bufferSubData = function (target, offset, data) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.bufferSubData + ',' + target + ',' + offset + ',' + processArray(data, true), + true + ) + } + + checkFramebufferStatus = function (target) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.checkFramebufferStatus + ',' + target + ); + return Number(result); + } + + clear = function (mask) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.clear + ',' + mask + ); + this._canvas._needRender = true; + } + + clearColor = function (r, g, b, a) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.clearColor + ',' + r + ',' + g + ',' + b, + true + ) + } + + clearDepth = function (depth) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.clearDepth + ',' + depth, + true + ) + } + + clearStencil = function (s) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.clearStencil + ',' + s + ); + } + + colorMask = function (r, g, b, a) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.colorMask + ',' + r + ',' + g + ',' + b + ',' + a + ) + } + + compileShader = function (shader) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.compileShader + ',' + shader.id, + true + ) + } + + compressedTexImage2D = function (target, level, internalformat, width, height, border, pixels) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.compressedTexImage2D + ',' + target + ',' + level + ',' + internalformat + ',' + + width + ',' + height + ',' + border + ',' + processArray(pixels), + true + ) + } + + compressedTexSubImage2D = function (target, level, xoffset, yoffset, width, height, format, pixels) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.compressedTexSubImage2D + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' + + width + ',' + height + ',' + format + ',' + processArray(pixels), + true + ) + } + + + copyTexImage2D = function (target, level, internalformat, x, y, width, height, border) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.copyTexImage2D + ',' + target + ',' + level + ',' + internalformat + ',' + x + ',' + y + ',' + + width + ',' + height + ',' + border, + true + ); + } + + copyTexSubImage2D = function (target, level, xoffset, yoffset, x, y, width, height) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.copyTexSubImage2D + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' + x + ',' + y + ',' + + width + ',' + height + ); + } + + createBuffer = function () { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.createBuffer + '' + ); + const buffer = new Buffer(result); + this._map.set(buffer.uuid(), buffer); + return buffer; + } + + createFramebuffer = function () { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.createFramebuffer + '' + ); + const framebuffer = new Framebuffer(result); + this._map.set(framebuffer.uuid(), framebuffer); + return framebuffer; + } + + + createProgram = function () { + const id = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.createProgram + '' + ); + const program = new Program(id); + this._map.set(program.uuid(), program); + return program; + } + + createRenderbuffer = function () { + const id = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.createRenderbuffer + '' + ) + const renderBuffer = new Renderbuffer(id); + this._map.set(renderBuffer.uuid(), renderBuffer); + return renderBuffer; + } + + createShader = function (type) { + const id = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.createShader + ',' + type + ) + const shader = new Shader(id, type); + this._map.set(shader.uuid(), shader); + return shader; + } + + createTexture = function () { + const id = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.createTexture + '' + ); + const texture = new Texture(id); + this._map.set(texture.uuid(), texture); + return texture; + } + + cullFace = function (mode) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.cullFace + ',' + mode, + true + ) + } + + + deleteBuffer = function (buffer) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.deleteBuffer + ',' + buffer.id, + true + ) + } + + deleteFramebuffer = function (framebuffer) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.deleteFramebuffer + ',' + framebuffer.id, + true + ) + } + + deleteProgram = function (program) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.deleteProgram + ',' + program.id, + true + ) + } + + deleteRenderbuffer = function (renderbuffer) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.deleteRenderbuffer + ',' + renderbuffer.id, + true + ) + } + + deleteShader = function (shader) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.deleteShader + ',' + shader.id, + true + ) + } + + deleteTexture = function (texture) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.deleteTexture + ',' + texture.id, + true + ) + } + + depthFunc = function (func) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.depthFunc + ',' + func + ) + } + + depthMask = function (flag) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.depthMask + ',' + Number(flag), + true + ) + } + + depthRange = function (zNear, zFar) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.depthRange + ',' + zNear + ',' + zFar, + true + ) + } + + detachShader = function (program, shader) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.detachShader + ',' + program.id + ',' + shader.id, + true + ) + } + + disable = function (cap) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.disable + ',' + cap, + true + ) + } + + disableVertexAttribArray = function (index) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.disableVertexAttribArray + ',' + index, + true + ); + } + + drawArrays = function (mode, first, count) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.drawArrays + ',' + mode + ',' + first + ',' + count + ) + this._canvas._needRender = true; + } + + drawElements = function (mode, count, type, offset) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.drawElements + ',' + mode + ',' + count + ',' + type + ',' + offset + ';' + ); + this._canvas._needRender = true; + } + + enable = function (cap) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.enable + ',' + cap, + true + ); + } + + enableVertexAttribArray = function (index) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.enableVertexAttribArray + ',' + index, + true + ) + } + + + flush = function () { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.flush + '' + ) + } + + framebufferRenderbuffer = function (target, attachment, textarget, texture, level) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.framebufferRenderbuffer + ',' + target + ',' + attachment + ',' + textarget + ',' + (texture ? texture.id : 0) + ',' + level, + true + ) + } + + framebufferTexture2D = function (target, attachment, textarget, texture, level) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.framebufferTexture2D + ',' + target + ',' + attachment + ',' + textarget + ',' + (texture ? texture.id : 0) + ',' + level, + true + ) + } + + frontFace = function (mode) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.frontFace + ',' + mode, + true + ) + } + + generateMipmap = function (target) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.generateMipmap + ',' + target, + true + ) + } + + getActiveAttrib = function (progarm, index) { + const resultString = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getActiveAttrib + ',' + progarm.id + ',' + index + ) + const [type, size, name] = resultString.split(','); + return new ActiveInfo({ + type: Number(type), + size: Number(size), + name + }); + } + + getActiveUniform = function (progarm, index) { + const resultString = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getActiveUniform + ',' + progarm.id + ',' + index + ); + const [type, size, name] = resultString.split(','); + return new ActiveInfo({ + type: Number(type), + size: Number(size), + name + }) + } + + getAttachedShaders = function (progarm) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getAttachedShaders + ',' + progarm.id + ); + const [type, ...ids] = result; + return ids.map(id => this._map.get(Shader.uuid(id))); + } + + getAttribLocation = function (progarm, name) { + return WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getAttribLocation + ',' + progarm.id + ',' + name + ) + } + + getBufferParameter = function (target, pname) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getBufferParameter + ',' + target + ',' + pname + ); + const [type, res] = getBufferParameter; + return res; + } + + getError = function () { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getError + '' + ) + return result; + } + + getExtension = function (name) { + return null; + } + + getFramebufferAttachmentParameter = function (target, attachment, pname) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getFramebufferAttachmentParameter + ',' + target + ',' + attachment + ',' + pname + ) + switch (pname) { + case GLenum.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: + return this._map.get(Renderbuffer.uuid(result)) || this._map.get(Texture.uuid(result)) || null; + default: + return result; + } + } + + getParameter = function (pname) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getParameter + ',' + pname + ) + switch (pname) { + case GLenum.VERSION: + return this._version; + case GLenum.ARRAY_BUFFER_BINDING: // buffer + case GLenum.ELEMENT_ARRAY_BUFFER_BINDING: // buffer + return this._map.get(Buffer.uuid(result)) || null; + case GLenum.CURRENT_PROGRAM: // program + return this._map.get(Program.uuid(result)) || null; + case GLenum.FRAMEBUFFER_BINDING: // framebuffer + return this._map.get(Framebuffer.uuid(result)) || null; + case GLenum.RENDERBUFFER_BINDING: // renderbuffer + return this._map.get(Renderbuffer.uuid(result)) || null; + case GLenum.TEXTURE_BINDING_2D: // texture + case GLenum.TEXTURE_BINDING_CUBE_MAP: // texture + return this._map.get(Texture.uuid(result)) || null; + case GLenum.ALIASED_LINE_WIDTH_RANGE: // Float32Array + case GLenum.ALIASED_POINT_SIZE_RANGE: // Float32Array + case GLenum.BLEND_COLOR: // Float32Array + case GLenum.COLOR_CLEAR_VALUE: // Float32Array + case GLenum.DEPTH_RANGE: // Float32Array + case GLenum.MAX_VIEWPORT_DIMS: // Int32Array + case GLenum.SCISSOR_BOX: // Int32Array + case GLenum.VIEWPORT: // Int32Array + case GLenum.COMPRESSED_TEXTURE_FORMATS: // Uint32Array + default: + const [type, ...res] = result.split(','); + if (res.length === 1) { + return Number(res[0]); + } else { + return res.map(Number); + } + } + } + + getProgramInfoLog = function (progarm) { + return WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getProgramInfoLog + ',' + progarm.id + ) + } + + getProgramParameter = function (program, pname) { + const res = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getProgramParameter + ',' + program.id + ',' + pname + ); + + const [type, result] = res.split(',').map(i => parseInt(i)); + + if (type === 1) { + return Boolean(result); + } else if (type === 2) { + return result; + } else { + throw new Error('Unrecongized program paramater ' + res + ', type: ' + typeof res); + } + } + + + getRenderbufferParameter = function (target, pname) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getRenderbufferParameter + ',' + target + ',' + pname + ) + return result; + } + + + getShaderInfoLog = function (shader) { + return WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getShaderInfoLog + ',' + shader.id + ); + } + + getShaderParameter = function (shader, pname) { + return WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getShaderParameter + ',' + shader.id + ',' + pname + ) + } + + getShaderPrecisionFormat = function (shaderType, precisionType) { + const [rangeMin, rangeMax, precision] = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getShaderPrecisionFormat + ',' + shaderType + ',' + precisionType + ); + const shaderPrecisionFormat = new ShaderPrecisionFormat({ + rangeMin: Number(rangeMin), + rangeMax: Number(rangeMax), + precision: Number(precision) + }); + return shaderPrecisionFormat; + } + + getShaderSource = function (shader) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getShaderSource + ',' + shader.id + ); + return result; + } + + getSupportedExtensions = function () { + return Object.keys({}); + } + + getTexParameter = function (target, pname) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getTexParameter + ',' + target + ',' + pname + ) + return result; + } + + getUniformLocation = function (program, name) { + const id = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getUniformLocation + ',' + program.id + ',' + name + ); + if (id === -1) { + return null; + } else { + return new UniformLocation(Number(id)); + } + } + + getVertexAttrib = function (index, pname) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getVertexAttrib + ',' + index + ',' + pname + ); + switch (pname) { + case GLenum.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: + return this._map.get(Buffer.uuid(result)) || null; + case GLenum.CURRENT_VERTEX_ATTRIB: // Float32Array + default: + return result; + } + } + + getVertexAttribOffset = function (index, pname) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.getVertexAttribOffset + ',' + index + ',' + pname + ) + return Number(result); + } + + isBuffer = function (buffer) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.isBuffer + ',' + buffer.id + ) + return Boolean(result); + } + + isContextLost = function () { + return false; + } + + isEnabled = function (cap) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.isEnabled + ',' + cap + ) + return Boolean(result); + } + + isFramebuffer = function (framebuffer) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.isFramebuffer + ',' + framebuffer.id + ) + return Boolean(result); + } + + isProgram = function (program) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.isProgram + ',' + program.id + ) + return Boolean(result); + } + + isRenderbuffer = function (renderBuffer) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.isRenderbuffer + ',' + renderbuffer.id + ) + return Boolean(result); + } + + isShader = function (shader) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.isShader + ',' + shader.id + ) + return Boolean(result); + } + + isTexture = function (texture) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.isTexture + ',' + texture.id + ); + return Boolean(result); + } + + lineWidth = function (width) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.lineWidth + ',' + width, + true + ) + } + + linkProgram = function (program) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.linkProgram + ',' + program.id, + true + ); + } + + + pixelStorei = function (pname, param) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.pixelStorei + ',' + pname + ',' + Number(param) + ) + } + + polygonOffset = function (factor, units) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.polygonOffset + ',' + factor + ',' + units + ) + } + + readPixels = function (x, y, width, height, format, type, pixels) { + const result = WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.readPixels + ',' + x + ',' + y + ',' + width + ',' + height + ',' + format + ',' + type + ) + return result; + } + + renderbufferStorage = function (target, internalFormat, width, height) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.renderbufferStorage + ',' + target + ',' + internalFormat + ',' + width + ',' + height, + true + ) + } + + sampleCoverage = function (value, invert) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.sampleCoverage + ',' + value + ',' + Number(invert), + true + ) + } + + scissor = function (x, y, width, height) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.scissor + ',' + x + ',' + y + ',' + width + ',' + height, + true + ) + } + + shaderSource = function (shader, source) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.shaderSource + ',' + shader.id + ',' + source + ) + } + + stencilFunc = function (func, ref, mask) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.stencilFunc + ',' + func + ',' + ref + ',' + mask, + true + ) + } + + stencilFuncSeparate = function (face, func, ref, mask) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.stencilFuncSeparate + ',' + face + ',' + func + ',' + ref + ',' + mask, + true + ) + } + + stencilMask = function (mask) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.stencilMask + ',' + mask, + true + ) + } + + stencilMaskSeparate = function (face, mask) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.stencilMaskSeparate + ',' + face + ',' + mask, + true + ) + } + + stencilOp = function (fail, zfail, zpass) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.stencilOp + ',' + fail + ',' + zfail + ',' + zpass + ) + } + + stencilOpSeparate = function (face, fail, zfail, zpass) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.stencilOp + ',' + face + ',' + fail + ',' + zfail + ',' + zpass, + true + ) + } + + texImage2D = function (...args) { + WebGLRenderingContext.GBridge.texImage2D(this._canvas.id, ...args); + } + + + texParameterf = function (target, pname, param) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.texParameterf + ',' + target + ',' + pname + ',' + param, + true + ) + } + + texParameteri = function (target, pname, param) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.texParameteri + ',' + target + ',' + pname + ',' + param + ) + } + + texSubImage2D = function (...args) { + WebGLRenderingContext.GBridge.texSubImage2D(this._canvas.id, ...args); + } + + uniform1f = function (location, v0) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform1f + ',' + location.id + ',' + v0 + ) + } + + uniform1fv = function (location, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform1fv + ',' + location.id + ',' + processArray(value), + true + ) + } + + uniform1i = function (location, v0) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform1i + ',' + location.id + ',' + v0, + // true + ) + } + + uniform1iv = function (location, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform1iv + ',' + location.id + ',' + processArray(value), + true + ) + } + + uniform2f = function (location, v0, v1) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform2f + ',' + location.id + ',' + v0 + ',' + v1, + true + ) + } + + uniform2fv = function (location, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform2fv + ',' + location.id + ',' + processArray(value), + true + ) + } + + uniform2i = function (location, v0, v1) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform2i + ',' + location.id + ',' + v0 + ',' + v1, + true + ) + } + + uniform2iv = function (location, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform2iv + ',' + location.id + ',' + processArray(value), + true + ) + } + + uniform3f = function (location, v0, v1, v2) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform3f + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2, + true + ) + } + + uniform3fv = function (location, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform3fv + ',' + location.id + ',' + processArray(value), + true + ) + } + + uniform3i = function (location, v0, v1, v2) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform3i + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2, + true + ) + } + + uniform3iv = function (location, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform3iv + ',' + location.id + ',' + processArray(value), + true + ) + } + + uniform4f = function (location, v0, v1, v2, v3) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform4f + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2 + ',' + v3, + true + ) + } + + uniform4fv = function (location, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform4fv + ',' + location.id + ',' + processArray(value), + true + ) + } + + uniform4i = function (location, v0, v1, v2, v3) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform4i + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2 + ',' + v3, + true + ) + } + + uniform4iv = function (location, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniform4iv + ',' + location.id + ',' + processArray(value, true), + true + ) + } + + uniformMatrix2fv = function (location, transpose, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniformMatrix2fv + ',' + location.id + ',' + Number(transpose) + ',' + processArray(value), + true + ) + } + + uniformMatrix3fv = function (location, transpose, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniformMatrix3fv + ',' + location.id + ',' + Number(transpose) + ',' + processArray(value), + true + ) + } + + uniformMatrix4fv = function (location, transpose, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.uniformMatrix4fv + ',' + location.id + ',' + Number(transpose) + ',' + processArray(value), + true + ); + } + + useProgram = function (progarm) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.useProgram + ',' + progarm.id + '', + true + ) + } + + + validateProgram = function (program) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.validateProgram + ',' + program.id, + true + ) + } + + vertexAttrib1f = function (index, v0) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.vertexAttrib1f + ',' + index + ',' + v0, + true + ) + } + + vertexAttrib2f = function (index, v0, v1) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.vertexAttrib2f + ',' + index + ',' + v0 + ',' + v1, + true + ) + } + + vertexAttrib3f = function (index, v0, v1, v2) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.vertexAttrib3f + ',' + index + ',' + v0 + ',' + v1 + ',' + v2, + true + ) + } + + vertexAttrib4f = function (index, v0, v1, v2, v3) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.vertexAttrib4f + ',' + index + ',' + v0 + ',' + v1 + ',' + v2 + ',' + v3, + true + ) + } + + vertexAttrib1fv = function (index, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.vertexAttrib1fv + ',' + index + ',' + processArray(value), + true + ) + } + + vertexAttrib2fv = function (index, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.vertexAttrib2fv + ',' + index + ',' + processArray(value), + true + ) + } + + vertexAttrib3fv = function (index, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.vertexAttrib3fv + ',' + index + ',' + processArray(value), + true + ) + } + + vertexAttrib4fv = function (index, value) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.vertexAttrib4fv + ',' + index + ',' + processArray(value), + true + ) + } + + vertexAttribPointer = function (index, size, type, normalized, stride, offset) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.vertexAttribPointer + ',' + index + ',' + size + ',' + type + ',' + Number(normalized) + ',' + stride + ',' + offset, + true + ) + } + + viewport = function (x, y, width, height) { + WebGLRenderingContext.GBridge.callNative( + this._canvas.id, + GLmethod.viewport + ',' + x + ',' + y + ',' + width + ',' + height, + true + ) + } } \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Shader.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Shader.js index a763886..2917b59 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Shader.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Shader.js @@ -1,22 +1,22 @@ -import {getTransferedObjectUUID} from './classUtils'; - -const name = 'WebGLShader'; - -function uuid(id) { - return getTransferedObjectUUID(name, id); -} - -export default class WebGLShader { - className = name; - - constructor(id, type) { - this.id = id; - this.type = type; - } - - static uuid = uuid; - - uuid() { - return uuid(this.id); - } +import {getTransferedObjectUUID} from './classUtils'; + +const name = 'WebGLShader'; + +function uuid(id) { + return getTransferedObjectUUID(name, id); +} + +export default class WebGLShader { + className = name; + + constructor(id, type) { + this.id = id; + this.type = type; + } + + static uuid = uuid; + + uuid() { + return uuid(this.id); + } } \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/ShaderPrecisionFormat.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/ShaderPrecisionFormat.js index 208d6c1..8b70e9a 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/ShaderPrecisionFormat.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/ShaderPrecisionFormat.js @@ -1,11 +1,11 @@ -export default class WebGLShaderPrecisionFormat { - className = 'WebGLShaderPrecisionFormat'; - - constructor({ - rangeMin, rangeMax, precision - }) { - this.rangeMin = rangeMin; - this.rangeMax = rangeMax; - this.precision = precision; - } +export default class WebGLShaderPrecisionFormat { + className = 'WebGLShaderPrecisionFormat'; + + constructor({ + rangeMin, rangeMax, precision + }) { + this.rangeMin = rangeMin; + this.rangeMax = rangeMax; + this.precision = precision; + } } \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Texture.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Texture.js index de4d806..089181e 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Texture.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/Texture.js @@ -1,22 +1,22 @@ -import {getTransferedObjectUUID} from './classUtils'; - -const name = 'WebGLTexture'; - -function uuid(id) { - return getTransferedObjectUUID(name, id); -} - -export default class WebGLTexture { - className = name; - - constructor(id, type) { - this.id = id; - this.type = type; - } - - static uuid = uuid; - - uuid() { - return uuid(this.id); - } +import {getTransferedObjectUUID} from './classUtils'; + +const name = 'WebGLTexture'; + +function uuid(id) { + return getTransferedObjectUUID(name, id); +} + +export default class WebGLTexture { + className = name; + + constructor(id, type) { + this.id = id; + this.type = type; + } + + static uuid = uuid; + + uuid() { + return uuid(this.id); + } } \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/UniformLocation.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/UniformLocation.js index f5e99dc..f19c94c 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/UniformLocation.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/UniformLocation.js @@ -1,22 +1,22 @@ -import {getTransferedObjectUUID} from './classUtils'; - -const name = 'WebGLUniformLocation'; - -function uuid(id) { - return getTransferedObjectUUID(name, id); -} - -export default class WebGLUniformLocation { - className = name; - - constructor(id, type) { - this.id = id; - this.type = type; - } - - static uuid = uuid; - - uuid() { - return uuid(this.id); - } +import {getTransferedObjectUUID} from './classUtils'; + +const name = 'WebGLUniformLocation'; + +function uuid(id) { + return getTransferedObjectUUID(name, id); +} + +export default class WebGLUniformLocation { + className = name; + + constructor(id, type) { + this.id = id; + this.type = type; + } + + static uuid = uuid; + + uuid() { + return uuid(this.id); + } } \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/classUtils.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/classUtils.js index 88716be..59f02e1 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/classUtils.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/context-webgl/classUtils.js @@ -1,3 +1,3 @@ -export function getTransferedObjectUUID(name, id) { - return `${name.toLowerCase()}-${id}`; +export function getTransferedObjectUUID(name, id) { + return `${name.toLowerCase()}-${id}`; } \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/env/canvas.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/env/canvas.js index a8d9bb9..57df6fe 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/env/canvas.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/env/canvas.js @@ -1,74 +1,74 @@ -import GContext2D from '../context-2d/RenderingContext'; -import GContextWebGL from '../context-webgl/RenderingContext'; - -export default class GCanvas { - - // static GBridge = null; - - id = null; - - _needRender = true; - - constructor(id, { disableAutoSwap }) { - this.id = id; - - this._disableAutoSwap = disableAutoSwap; - if (disableAutoSwap) { - this._swapBuffers = () => { - GCanvas.GBridge.render(this.id); - } - } - } - - getContext(type) { - - let context = null; - - if (type.match(/webgl/i)) { - context = new GContextWebGL(this); - - context.componentId = this.id; - - if (!this._disableAutoSwap) { - const render = () => { - if (this._needRender) { - GCanvas.GBridge.render(this.id); - this._needRender = false; - } - } - setInterval(render, 16); - } - - GCanvas.GBridge.callSetContextType(this.id, 1); // 0 for 2d; 1 for webgl - } else if (type.match(/2d/i)) { - context = new GContext2D(this); - - context.componentId = this.id; - -// const render = ( callback ) => { -// -// const commands = context._drawCommands; -// context._drawCommands = ''; -// -// GCanvas.GBridge.render2d(this.id, commands, callback); -// this._needRender = false; -// } -// //draw方法触发 -// context._flush = render; -// //setInterval(render, 16); - - GCanvas.GBridge.callSetContextType(this.id, 0); - } else { - throw new Error('not supported context ' + type); - } - - return context; - - } - - reset() { - GCanvas.GBridge.callReset(this.id); - } - - +import GContext2D from '../context-2d/RenderingContext'; +import GContextWebGL from '../context-webgl/RenderingContext'; + +export default class GCanvas { + + // static GBridge = null; + + id = null; + + _needRender = true; + + constructor(id, { disableAutoSwap }) { + this.id = id; + + this._disableAutoSwap = disableAutoSwap; + if (disableAutoSwap) { + this._swapBuffers = () => { + GCanvas.GBridge.render(this.id); + } + } + } + + getContext(type) { + + let context = null; + + if (type.match(/webgl/i)) { + context = new GContextWebGL(this); + + context.componentId = this.id; + + if (!this._disableAutoSwap) { + const render = () => { + if (this._needRender) { + GCanvas.GBridge.render(this.id); + this._needRender = false; + } + } + setInterval(render, 16); + } + + GCanvas.GBridge.callSetContextType(this.id, 1); // 0 for 2d; 1 for webgl + } else if (type.match(/2d/i)) { + context = new GContext2D(this); + + context.componentId = this.id; + +// const render = ( callback ) => { +// +// const commands = context._drawCommands; +// context._drawCommands = ''; +// +// GCanvas.GBridge.render2d(this.id, commands, callback); +// this._needRender = false; +// } +// //draw方法触发 +// context._flush = render; +// //setInterval(render, 16); + + GCanvas.GBridge.callSetContextType(this.id, 0); + } else { + throw new Error('not supported context ' + type); + } + + return context; + + } + + reset() { + GCanvas.GBridge.callReset(this.id); + } + + } \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/env/image.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/env/image.js index 9499a51..458d3cd 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/env/image.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/env/image.js @@ -1,96 +1,96 @@ -let incId = 1; - -const noop = function () { }; - -class GImage { - - static GBridge = null; - - constructor() { - this._id = incId++; - this._width = 0; - this._height = 0; - this._src = undefined; - this._onload = noop; - this._onerror = noop; - this.complete = false; - } - - get width() { - return this._width; - } - set width(v) { - this._width = v; - } - - get height() { - return this._height; - } - - set height(v) { - this._height = v; - } - - get src() { - return this._src; - } - - set src(v) { - - if (v.startsWith('//')) { - v = 'http:' + v; - } - - this._src = v; - - GImage.GBridge.perloadImage([this._src, this._id], (data) => { - if (typeof data === 'string') { - data = JSON.parse(data); - } - if (data.error) { - var evt = { type: 'error', target: this }; - this.onerror(evt); - } else { - this.complete = true; - this.width = typeof data.width === 'number' ? data.width : 0; - this.height = typeof data.height === 'number' ? data.height : 0; - var evt = { type: 'load', target: this }; - this.onload(evt); - } - }); - } - - addEventListener(name, listener) { - if (name === 'load') { - this.onload = listener; - } else if (name === 'error') { - this.onerror = listener; - } - } - - removeEventListener(name, listener) { - if (name === 'load') { - this.onload = noop; - } else if (name === 'error') { - this.onerror = noop; - } - } - - get onload() { - return this._onload; - } - - set onload(v) { - this._onload = v; - } - - get onerror() { - return this._onerror; - } - - set onerror(v) { - this._onerror = v; - } -} - +let incId = 1; + +const noop = function () { }; + +class GImage { + + static GBridge = null; + + constructor() { + this._id = incId++; + this._width = 0; + this._height = 0; + this._src = undefined; + this._onload = noop; + this._onerror = noop; + this.complete = false; + } + + get width() { + return this._width; + } + set width(v) { + this._width = v; + } + + get height() { + return this._height; + } + + set height(v) { + this._height = v; + } + + get src() { + return this._src; + } + + set src(v) { + + if (v.startsWith('//')) { + v = 'http:' + v; + } + + this._src = v; + + GImage.GBridge.perloadImage([this._src, this._id], (data) => { + if (typeof data === 'string') { + data = JSON.parse(data); + } + if (data.error) { + var evt = { type: 'error', target: this }; + this.onerror(evt); + } else { + this.complete = true; + this.width = typeof data.width === 'number' ? data.width : 0; + this.height = typeof data.height === 'number' ? data.height : 0; + var evt = { type: 'load', target: this }; + this.onload(evt); + } + }); + } + + addEventListener(name, listener) { + if (name === 'load') { + this.onload = listener; + } else if (name === 'error') { + this.onerror = listener; + } + } + + removeEventListener(name, listener) { + if (name === 'load') { + this.onload = noop; + } else if (name === 'error') { + this.onerror = noop; + } + } + + get onload() { + return this._onload; + } + + set onload(v) { + this._onload = v; + } + + get onerror() { + return this._onerror; + } + + set onerror(v) { + this._onerror = v; + } +} + export default GImage; \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/env/tool.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/env/tool.js index d3fb398..1174c7f 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/env/tool.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/env/tool.js @@ -1,24 +1,24 @@ - -export function ArrayBufferToBase64 (buffer) { - var binary = ''; - var bytes = new Uint8ClampedArray(buffer); - for (var len = bytes.byteLength, i = 0; i < len; i++) { - binary += String.fromCharCode(bytes[i]); - } - return btoa(binary); -} - -export function Base64ToUint8ClampedArray(base64String) { - const padding = '='.repeat((4 - base64String.length % 4) % 4); - const base64 = (base64String + padding) - .replace(/\-/g, '+') - .replace(/_/g, '/'); - - const rawData = atob(base64); - const outputArray = new Uint8ClampedArray(rawData.length); - - for (let i = 0; i < rawData.length; ++i) { - outputArray[i] = rawData.charCodeAt(i); - } - return outputArray; + +export function ArrayBufferToBase64 (buffer) { + var binary = ''; + var bytes = new Uint8ClampedArray(buffer); + for (var len = bytes.byteLength, i = 0; i < len; i++) { + binary += String.fromCharCode(bytes[i]); + } + return btoa(binary); +} + +export function Base64ToUint8ClampedArray(base64String) { + const padding = '='.repeat((4 - base64String.length % 4) % 4); + const base64 = (base64String + padding) + .replace(/\-/g, '+') + .replace(/_/g, '/'); + + const rawData = atob(base64); + const outputArray = new Uint8ClampedArray(rawData.length); + + for (let i = 0; i < rawData.length; ++i) { + outputArray[i] = rawData.charCodeAt(i); + } + return outputArray; } \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/index.js b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/index.js index a34ad58..3dcc62a 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/index.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/gcanvas/index.js @@ -1,39 +1,39 @@ -import GCanvas from './env/canvas'; -import GImage from './env/image'; - -import GWebGLRenderingContext from './context-webgl/RenderingContext'; -import GContext2D from './context-2d/RenderingContext'; - -import GBridgeWeex from './bridge/bridge-weex'; - -export let Image = GImage; - -export let WeexBridge = GBridgeWeex; - -export function enable(el, { bridge, debug, disableAutoSwap, disableComboCommands } = {}) { - - const GBridge = GImage.GBridge = GCanvas.GBridge = GWebGLRenderingContext.GBridge = GContext2D.GBridge = bridge; - - GBridge.callEnable(el.ref, [ - 0, // renderMode: 0--RENDERMODE_WHEN_DIRTY, 1--RENDERMODE_CONTINUOUSLY - -1, // hybridLayerType: 0--LAYER_TYPE_NONE 1--LAYER_TYPE_SOFTWARE 2--LAYER_TYPE_HARDWARE - false, // supportScroll - false, // newCanvasMode - 1, // compatible - 'white',// clearColor - false // sameLevel: newCanvasMode = true && true => GCanvasView and Webview is same level - ]); - - if (debug === true) { - GBridge.callEnableDebug(); - } - if (disableComboCommands) { - GBridge.callEnableDisableCombo(); - } - - var canvas = new GCanvas(el.ref, { disableAutoSwap }); - canvas.width = el.style.width; - canvas.height = el.style.height; - - return canvas; +import GCanvas from './env/canvas'; +import GImage from './env/image'; + +import GWebGLRenderingContext from './context-webgl/RenderingContext'; +import GContext2D from './context-2d/RenderingContext'; + +import GBridgeWeex from './bridge/bridge-weex'; + +export let Image = GImage; + +export let WeexBridge = GBridgeWeex; + +export function enable(el, { bridge, debug, disableAutoSwap, disableComboCommands } = {}) { + + const GBridge = GImage.GBridge = GCanvas.GBridge = GWebGLRenderingContext.GBridge = GContext2D.GBridge = bridge; + + GBridge.callEnable(el.ref, [ + 0, // renderMode: 0--RENDERMODE_WHEN_DIRTY, 1--RENDERMODE_CONTINUOUSLY + -1, // hybridLayerType: 0--LAYER_TYPE_NONE 1--LAYER_TYPE_SOFTWARE 2--LAYER_TYPE_HARDWARE + false, // supportScroll + false, // newCanvasMode + 1, // compatible + 'white',// clearColor + false // sameLevel: newCanvasMode = true && true => GCanvasView and Webview is same level + ]); + + if (debug === true) { + GBridge.callEnableDebug(); + } + if (disableComboCommands) { + GBridge.callEnableDisableCombo(); + } + + var canvas = new GCanvas(el.ref, { disableAutoSwap }); + canvas.width = el.style.width; + canvas.height = el.style.height; + + return canvas; }; \ No newline at end of file diff --git a/uni_modules/Sansnn-uQRCode/js_sdk/uqrcode/uqrcode.js b/uni_modules/Sansnn-uQRCode/js_sdk/uqrcode/uqrcode.js index 8d71692..2290ab3 100644 --- a/uni_modules/Sansnn-uQRCode/js_sdk/uqrcode/uqrcode.js +++ b/uni_modules/Sansnn-uQRCode/js_sdk/uqrcode/uqrcode.js @@ -1,11 +1,12 @@ //--------------------------------------------------------------------- -// uQRCode二维码生成插件 v3.5.1 +// uQRCode二维码生成插件 v4.0.6 // // uQRCode是一款基于Javascript环境开发的二维码生成插件,适用所有Javascript运行环境的前端应用和Node.js。 // // Copyright (c) Sansnn uQRCode All rights reserved. // -// Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) +// Licensed under the Apache License, Version 2.0. +// http://www.apache.org/licenses/LICENSE-2.0 // // github地址: // https://github.com/Sansnn/uQRCode @@ -19,29 +20,15 @@ // 复制使用请保留本段注释,感谢支持开源! // //--------------------------------------------------------------------- + //--------------------------------------------------------------------- -// QRCode for JavaScript -// -// Copyright (c) 2009 Kazuhiko Arase -// -// URL: http://www.d-project.com/ -// -// Licensed under the MIT license: -// http://www.opensource.org/licenses/mit-license.php -// -// The word "QR Code" is registered trademark of -// DENSO WAVE INCORPORATED -// http://www.denso-wave.com/qrcode/faqpatent-e.html -// +// 当前文件格式为 es,将 bundle 保留为 ES 模块文件,适用于其他打包工具以及支持 - -``` - -> `vue3`推荐使用`npm`安装,非`npm`安装直接引入`uqrcode.js`文件如果出现报错:`SyntaxError: The requested module 'uqrcode.js' does not provide an export named 'default'`,在`uqrcode.js`文件中最后一行添加`export default uQRCode`即可。 - -### 简单用法 - -`uQRCode`基于`Canvas API`封装了一套方法,建议开发者使用`canvas`生成,一键调用,非常方便。以下是示例: - -- HTML部分 -``` html - -``` - -- JS部分 -``` javascript -// 获取uQRCode实例 -var qr = new UQRCode(); -// 设置二维码内容 -qr.data = "https://doc.uqrcode.cn"; -// 设置二维码大小,必须与canvas设置的宽高一致 -qr.size = 200; -// 调用制作二维码方法 -qr.make(); -// 获取canvas元素 -var canvas = document.getElementById("qrcode"); -// 获取canvas上下文 -var canvasContext = canvas.getContext("2d"); -// 设置uQRCode实例的canvas上下文 -qr.canvasContext = canvasContext; -// 调用绘制方法将二维码图案绘制到canvas上 -qr.drawCanvas(); -``` - -### 高级用法 - -考虑到部分平台可能不支持`canvas`,所以`uQRCode`并没有强制要求和`canvas`一起使用,您还可以选择其他方式来生成二维码,例如使用`js`操作`dom`进行绘制或是使用`svg`绘制等。以下是示例: - -- js操作dom -``` html - - - - - uQRCode二维码生成 - - -
- - - - -``` - -- svg -``` html - - - - - uQRCode二维码生成 - - - - - - - -``` - -> 更多用法大家自行探索咯,期待分享哟~ - -### 导出临时文件路径 - -原生方式基于`Canvas`的,请自行参阅各平台`Canvas`的导出方式。以下是部分示例: - -- uni-app -```javascript -// 通过uni.createCanvasContext方式创建绘制上下文的,对应导出API为uni.canvasToTempFilePath -// 调用完ctx.draw()方法后不能第一时间导出,否则会异常,需要有一定的延时 -setTimeout(() => { - uni.canvasToTempFilePath( - { - canvasId: this.canvasId, - fileType: this.fileType, - width: this.canvasWidth, - height: this.canvasHeight, - success: res => { - console.log(res); - }, - fail: err => { - console.log(err); - } - }, - // this // 组件内使用必传当前实例 - ); -}, 300); -``` - -- Canvas2D -```javascript -// 得到base64 -console.log(canvas.toDataURL()); -// 得到buffer -console.log(canvas.toBuffer()); -``` - -### 保存二维码到本地相册 - -必须在导出临时文件路径成功后再执行保存。uni-app通用保存方式(H5除外): -```javascript -uni.saveImageToPhotosAlbum({ - filePath: tempFilePath, - success: res => { - console.log(res); - }, - fail: err => { - console.log(err); - } -}); -``` - -H5可以通过设置``标签`href`属性的方式进行保存: -```javascript -const aEle = document.createElement('a'); -aEle.download = 'uQRCode'; // 设置下载的文件名,默认是'下载' -aEle.href = tempFilePath; -document.body.appendChild(aEle); -aEle.click(); -aEle.remove(); // 下载之后把创建的元素删除 -``` -经过测试,PC端浏览器可以下载,部分安卓自带或第三方浏览器可以下载,安卓微信浏览器不适用,移动端iOS所有浏览器均不适用,差异较大,还是推荐各位导出文件给图片组件显示,然后提示用户通过长按图片进行保存这种方式。 - -## uni-app组件方式 - -### 安装 - -通过uni-app插件市场地址安装:[https://ext.dcloud.net.cn/plugin?id=1287](https://ext.dcloud.net.cn/plugin?id=1287)。 - -### 引入 - -uni-app默认为easycom模式,可直接键入``标签。 - -### 简单用法 - -安装`uqrcode`组件后,在`template`中键入``。设置`ref`属性可使用组件内部方法,`canvas-id`属性为组件内部的canvas组件标识,`value`属性为二维码生成对应内容。 - -``` html - -``` - -### 导出临时文件路径 - -为了保证方法调用成功,请在 [complete](/document/uni-app.md#complete) 事件返回`success=true`后调用。 - -```javascript -// uqrcode为组件的ref名称 -this.$refs.uqrcode.toTempFilePath({ - success: res => { - console.log(res); - } -}); -``` - -### 保存二维码到本地相册 - -为了保证方法调用成功,请在 [complete](/document/uni-app.md#complete) 事件返回`success=true`后调用。 - -```javascript -// uqrcode为组件的ref名称 -this.$refs.uqrcode.save({ - success: () => { - uni.showToast({ - icon: 'success', - title: '保存成功' - }); - } -}); -``` - -## 更多配置说明请前往官方文档查看:[https://doc.uqrcode.cn](https://doc.uqrcode.cn)。 \ No newline at end of file +# 介绍 + +`uQRCode`是一款基于`Javascript`环境开发的二维码生成插件,适用所有`Javascript`运行环境的前端应用和`Node.js`应用。 + +`uQRCode`可扩展性高,它支持自定义渲染二维码,可通过`uQRCode API`得到二维码绘制关键信息后,使用`canvas`、`svg`或`js`操作`dom`的方式绘制二维码图案。还可自定义二维码样式,如随机颜色、圆点、方块、块与块之间的间距等。 + +欢迎加入群聊【uQRCode交流群】:[695070434](https://jq.qq.com/?_wv=1027&k=JRjzDqiw)。 + +# 设计器 + +uQRCode发布了配套的可视化设计器,可根据自己喜好在设计器中设计二维码样式,一键生成配置代码复制到项目中,详情请在微信小程序搜索“柚子二维码”,或扫描下方小程序码体验。 + +![uQRCode设计器](https://uqrcode.cn/mp_weixin_code.jpg) + +## 设计器模板示例 + +![uQRCode设计器](https://uqrcode.cn/yz_1.png) +![uQRCode设计器](https://uqrcode.cn/yz_2.png) +![uQRCode设计器](https://uqrcode.cn/yz_3.png) +![uQRCode设计器](https://uqrcode.cn/yz_4.png) +![uQRCode设计器](https://uqrcode.cn/yz_5.png) +![uQRCode设计器](https://uqrcode.cn/yz_6.png) +![uQRCode设计器](https://uqrcode.cn/yz_7.png) +![uQRCode设计器](https://uqrcode.cn/yz_8.png) +![uQRCode设计器](https://uqrcode.cn/yz_9.png) + +# 快速上手 + +> 在`uni-app`中,我们更推荐使用组件方式来生成二维码,组件方式大大提高了页面的可读性以及避开了一些平台容易出问题的地方,当组件无法满足需求的时候,再考虑切换成原生方式。 + +官方文档:[https://uqrcode.cn/doc](https://uqrcode.cn/doc)。 + +github地址:[https://github.com/Sansnn/uQRCode](https://github.com/Sansnn/uQRCode)。 + +npm地址:[https://www.npmjs.com/package/uqrcodejs](https://www.npmjs.com/package/uqrcodejs)。 + +uni-app插件市场地址:[https://ext.dcloud.net.cn/plugin?id=1287](https://ext.dcloud.net.cn/plugin?id=1287)。 + +## 原生方式 + +原生方式仅需要获取`uqrcode.js`文件便可使用。详细配置请移步到:文档 > [原生](https://uqrcode.cn/doc/document/native.html)。 + +### 安装 + +1. 通过`npm`安装,成功后即可使用`import`或`require`进行引用。 +``` bash +# npm安装 +npm install uqrcodejs +# 或者 +npm install @uqrcode/js +``` + +2. 通过项目开源地址获取`uqrcode.js`,下载`uqrcode.js`后,将其复制到您项目指定目录,在页面中引入`uqrcode.js`文件即可开始使用。 + +### 引入 + +- 通过`import`引入。 +``` javascript +// npm安装 +import UQRCode from 'uqrcodejs'; // npm install uqrcodejs +// 或者 +import UQRCode from '@uqrcode/js'; // npm install @uqrcode/js +``` + +- `Node.js`通过`require`引入。 +``` javascript +// npm安装 +const UQRCode = require('uqrcodejs'); // npm install uqrcodejs +// 或者 +const UQRCode = require('@uqrcode/js'); // npm install @uqrcode/js +``` + +- 原生浏览器环境,在js脚本加载时添加到`window`。 +``` html + + +``` + +### 简单用法 + +`uQRCode`基于`Canvas API`封装了一套方法,建议开发者使用`canvas`生成,一键调用,非常方便。以下是示例: + +- HTML示例 + - DOM部分 + ``` html + + ``` + + - JS部分 + ``` javascript + // 获取uQRCode实例 + var qr = new UQRCode(); + // 设置二维码内容 + qr.data = "https://uqrcode.cn/doc"; + // 设置二维码大小,必须与canvas设置的宽高一致 + qr.size = 200; + // 调用制作二维码方法 + qr.make(); + // 获取canvas元素 + var canvas = document.getElementById("qrcode"); + // 获取canvas上下文 + var canvasContext = canvas.getContext("2d"); + // 设置uQRCode实例的canvas上下文 + qr.canvasContext = canvasContext; + // 调用绘制方法将二维码图案绘制到canvas上 + qr.drawCanvas(); + ``` + +- uni-app示例 + - Template部分 + ``` html + + ``` + + - JS部分 + ``` javascript + onReady() { + // 获取uQRCode实例 + var qr = new UQRCode(); + // 设置二维码内容 + qr.data = "https://uqrcode.cn/doc"; + // 设置二维码大小,必须与canvas设置的宽高一致 + qr.size = 200; + // 调用制作二维码方法 + qr.make(); + // 获取canvas上下文 + var canvasContext = uni.createCanvasContext('qrcode', this); // 如果是组件,this必须传入 + // 设置uQRCode实例的canvas上下文 + qr.canvasContext = canvasContext; + // 调用绘制方法将二维码图案绘制到canvas上 + qr.drawCanvas(); + } + ``` + +- 微信小程序,推荐使用Canvas 2D,关于Canvas 2D的使用请参考微信开放文档。 + +### 高级用法 + +考虑到部分平台可能不支持`canvas`,所以`uQRCode`并没有强制要求和`canvas`一起使用,您还可以选择其他方式来生成二维码,例如使用`js`操作`dom`进行绘制或是使用`svg`绘制等。以下是示例: + +- uni-app v-for+view + +```html + + + +``` + +- js操作dom + +``` html + + + + + uQRCode二维码生成 + + +
+ + + + +``` + +- svg +``` html + + + + + uQRCode二维码生成 + + + + + + + +``` + +> 更多用法大家自行探索咯,期待分享哟~ + +### 导出临时文件路径 + +原生方式基于`Canvas`的,请自行参阅各平台`Canvas`的导出方式。以下是部分示例: + +- uni-app +```javascript +// 通过uni.createCanvasContext方式创建绘制上下文的,对应导出API为uni.canvasToTempFilePath +// 调用完ctx.draw()方法后不能第一时间导出,否则会异常,需要有一定的延时 +setTimeout(() => { + uni.canvasToTempFilePath( + { + canvasId: this.canvasId, + fileType: this.fileType, + width: this.canvasWidth, + height: this.canvasHeight, + success: res => { + console.log(res); + }, + fail: err => { + console.log(err); + } + }, + // this // 组件内使用必传当前实例 + ); +}, 300); +``` + +- Canvas2D +```javascript +// 得到base64 +console.log(canvas.toDataURL()); +// 得到buffer +console.log(canvas.toBuffer()); +``` + +### 保存二维码到本地相册 + +必须在导出临时文件路径成功后再执行保存。uni-app通用保存方式(H5除外): +```javascript +uni.saveImageToPhotosAlbum({ + filePath: tempFilePath, + success: res => { + console.log(res); + }, + fail: err => { + console.log(err); + } +}); +``` + +H5可以通过设置`
`标签`href`属性的方式进行保存: +```javascript +const aEle = document.createElement('a'); +aEle.download = 'uQRCode'; // 设置下载的文件名,默认是'下载' +aEle.href = tempFilePath; +document.body.appendChild(aEle); +aEle.click(); +aEle.remove(); // 下载之后把创建的元素删除 +``` +经过测试,PC端浏览器可以下载,部分安卓自带或第三方浏览器可以下载,安卓微信浏览器不适用,移动端iOS所有浏览器均不适用,差异较大,还是推荐各位导出文件给图片组件显示,然后提示用户通过长按图片进行保存这种方式。 + +## uni-app组件方式 + +### 安装 + +通过uni-app插件市场地址安装:[https://ext.dcloud.net.cn/plugin?id=1287](https://ext.dcloud.net.cn/plugin?id=1287)。详细配置请移步到:文档 > [uni-app组件](https://uqrcode.cn/doc/document/uni-app.html)。 + +### 引入 + +uni-app默认为easycom模式,可直接键入``标签。 + +### 简单用法 + +安装`uqrcode`组件后,在`template`中键入``。设置`ref`属性可使用组件内部方法,`canvas-id`属性为组件内部的canvas组件标识,`value`属性为二维码生成对应内容,`options`为配置选项,可配置二维码样式,绘制Logo等,详见:[options](https://uqrcode.cn/doc/document/uni-app.html#options) 。 + +``` html + +``` + +### 导出临时文件路径 + +为了保证方法调用成功,请在 [complete](https://uqrcode.cn/doc/document/uni-app.html#complete) 事件返回`success=true`后调用。 + +```javascript +// uqrcode为组件的ref名称 +this.$refs.uqrcode.toTempFilePath({ + success: res => { + console.log(res); + } +}); +``` + +### 保存二维码到本地相册 + +为了保证方法调用成功,请在 [complete](https://uqrcode.cn/doc/document/uni-app.html#complete) 事件返回`success=true`后调用。 + +```javascript +// uqrcode为组件的ref名称 +this.$refs.uqrcode.save({ + success: () => { + uni.showToast({ + icon: 'success', + title: '保存成功' + }); + } +}); +``` + +## 更多使用说明请前往官方文档查看:[https://uqrcode.cn/doc](https://uqrcode.cn/doc)。 \ No newline at end of file diff --git a/uni_modules/uni-badge/components/uni-badge/uni-badge.vue b/uni_modules/uni-badge/components/uni-badge/uni-badge.vue index 664dc37..7b2ba31 100644 --- a/uni_modules/uni-badge/components/uni-badge/uni-badge.vue +++ b/uni_modules/uni-badge/components/uni-badge/uni-badge.vue @@ -191,12 +191,13 @@ /* #ifndef APP-NVUE */ display: flex; overflow: hidden; - box-sizing: border-box; + box-sizing: border-box; + min-width: 20px; + font-feature-settings: "tnum"; /* #endif */ justify-content: center; flex-direction: row; height: 20px; - min-width: 20px; padding: 0 4px; line-height: 18px; color: #fff; @@ -206,7 +207,6 @@ border: 1px solid #fff; text-align: center; font-family: 'Helvetica Neue', Helvetica, sans-serif; - font-feature-settings: "tnum"; font-size: $bage-size; /* #ifdef H5 */ z-index: 999; diff --git a/uni_modules/uni-captcha/changelog.md b/uni_modules/uni-captcha/changelog.md index 496672f..f63f784 100644 --- a/uni_modules/uni-captcha/changelog.md +++ b/uni_modules/uni-captcha/changelog.md @@ -1,3 +1,6 @@ +## 0.6.2(2023-01-10) +- 修复 抖音小程序无法显示的Bug +- 修复 刷新时兼容 device_uuid ## 0.6.1(2022-06-23) - 修复:部分返回值,不符合响应体规范的问题 ## 0.6.0(2022-05-27) diff --git a/uni_modules/uni-captcha/package.json b/uni_modules/uni-captcha/package.json index 5e20db3..a35fc4a 100644 --- a/uni_modules/uni-captcha/package.json +++ b/uni_modules/uni-captcha/package.json @@ -1,7 +1,7 @@ { "id": "uni-captcha", "displayName": "uni-captcha", - "version": "0.6.1", + "version": "0.6.2", "description": "云端一体图形验证码组件", "keywords": [ "captcha", @@ -14,11 +14,7 @@ "engines": { "HBuilderX": "^3.1.0" }, - "dcloudext": { - "category": [ - "uniCloud", - "云函数模板" - ], +"dcloudext": { "sale": { "regular": { "price": "0.00" @@ -35,7 +31,8 @@ "data": "无", "permissions": "无" }, - "npmurl": "" + "npmurl": "", + "type": "unicloud-template-function" }, "uni_modules": { "dependencies": [], diff --git a/uni_modules/uni-captcha/uniCloud/cloudfunctions/common/uni-captcha/index.js b/uni_modules/uni-captcha/uniCloud/cloudfunctions/common/uni-captcha/index.js index b170e62..837e6d0 100644 --- a/uni_modules/uni-captcha/uniCloud/cloudfunctions/common/uni-captcha/index.js +++ b/uni_modules/uni-captcha/uniCloud/cloudfunctions/common/uni-captcha/index.js @@ -1 +1 @@ -"use strict";var e=require("assert"),t=require("path");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(e),r=n(t);const s={10001:"uni-captcha-create-fail",10002:"uni-captcha-verify-fail",10003:"uni-captcha-refresh-fail",10101:"uni-captcha-deviceId-empty",10102:"uni-captcha-text-required",10103:"uni-captcha-verify-overdue",10104:"uni-captcha-verify-fail",50403:"uni-captcha-interior-fail"};function a(e){const t=.2*Math.random()-.1;switch(e.type){case"M":case"L":e.x+=t,e.y+=t;break;case"Q":case"C":e.x+=t,e.y+=t,e.x1+=t,e.y1+=t}return e}function i(e,t,n,o,r,s,a){let i,l,c,u,p,h;if(e<=0||e>=1)throw RangeError("spliteCurveAt requires position > 0 && position < 1");return u=[],p=0,i={},l={},c={},i.x=t,i.y=n,l.x=o,l.y=r,c.x=s,c.y=a,h=e,u[p++]=i.x,u[p++]=i.y,u[p++]=i.x+=(l.x-i.x)*h,u[p++]=i.y+=(l.y-i.y)*h,l.x+=(c.x-l.x)*h,l.y+=(c.y-l.y)*h,u[p++]=i.x+(l.x-i.x)*h,u[p++]=i.y+(l.y-i.y)*h,u[p++]=l.x,u[p++]=l.y,u[p++]=c.x,u[p++]=c.y,u}function l(e,t){return Math.random()*(t-e)+e}var c=function(e,t){const n=e[0];o.default(n,"expect a string");const r=t.fontSize,s=r/t.font.unitsPerEm,c=t.font.charToGlyph(n),u=c.advanceWidth?c.advanceWidth*s:0,p=t.x-u/2,h=(t.ascender+t.descender)*s,f=t.y+h/2,d=c.getPath(p,f,r);d.commands.forEach(a),d.commands=function(e,t){const n=[];for(let o=0;ot.truncateLineProbability){const e=l(-.1,.1);n.push(r),n.push({type:"L",x:(r.x+s.x)/2+e,y:(r.y+s.y)/2+e})}else n.push(r)}else if("Q"===r.type&&o>=1){const s=e[o-1];if(("L"===s.type||"M"===s.type)&&Math.random()>t.truncateCurveProbability){const e=s.x,o=s.y,a=l(-.1,.1),c=r.x1+a,u=r.y1+a,p=r.x+a,h=r.y+a,f=i(l(t.truncateCurvePositionMin,t.truncateCurvePositionMax),e,o,c,u,p,h),d={type:"Q",x1:f[2],y1:f[3],x:f[4],y:f[5]},g={type:"L",x:f[4],y:f[5]},m={type:"Q",x1:f[6],y1:f[7],x:f[8],y:f[9]},y={type:"L",x:f[8],y:f[9]};n.push(d),n.push(g),n.push(m),n.push(y)}}else n.push(r)}return n}(d.commands,t);return d.toPathData()};function u(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function p(e,t){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new u,this.dtree=new u}var h=new u,f=new u,d=new Uint8Array(30),g=new Uint16Array(30),m=new Uint8Array(30),y=new Uint16Array(30),v=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),b=new u,S=new Uint8Array(320);function x(e,t,n,o){var r,s;for(r=0;r>>=1,t}function O(e,t,n){if(!t)return n;for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<>>16-t;return e.tag>>>=t,e.bitcount-=t,o+n}function w(e,t){for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<>>=1,++r,n+=t.table[r],o-=t.table[r]}while(o>=0);return e.tag=s,e.bitcount-=r,t.trans[n+o]}function k(e,t,n){var o,r,s,a,i,l;for(o=O(e,5,257),r=O(e,5,1),s=O(e,4,4),a=0;a<19;++a)S[a]=0;for(a=0;a8;)e.sourceIndex--,e.bitcount-=8;if((t=256*(t=e.source[e.sourceIndex+1])+e.source[e.sourceIndex])!==(65535&~(256*e.source[e.sourceIndex+3]+e.source[e.sourceIndex+2])))return-3;for(e.sourceIndex+=4,n=t;n;--n)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,0}!function(e,t){var n;for(n=0;n<7;++n)e.table[n]=0;for(e.table[7]=24,e.table[8]=152,e.table[9]=112,n=0;n<24;++n)e.trans[n]=256+n;for(n=0;n<144;++n)e.trans[24+n]=n;for(n=0;n<8;++n)e.trans[168+n]=280+n;for(n=0;n<112;++n)e.trans[176+n]=144+n;for(n=0;n<5;++n)t.table[n]=0;for(t.table[5]=32,n=0;n<32;++n)t.trans[n]=n}(h,f),x(d,g,4,3),x(m,y,2,1),d[28]=0,g[28]=258;var C=function(e,t){var n,o,r=new p(e,t);do{switch(n=E(r),O(r,2,0)){case 0:o=D(r);break;case 1:o=R(r,h,f);break;case 2:k(r,r.ltree,r.dtree),o=R(r,r.ltree,r.dtree);break;default:o=-3}if(0!==o)throw new Error("Data error")}while(!n);return r.destLenthis.x2&&(this.x2=e)),"number"==typeof t&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=t,this.y2=t),tthis.y2&&(this.y2=t))},I.prototype.addX=function(e){this.addPoint(e,null)},I.prototype.addY=function(e){this.addPoint(null,e)},I.prototype.addBezier=function(e,t,n,o,r,s,a,i){const l=[e,t],c=[n,o],u=[r,s],p=[a,i];this.addPoint(e,t),this.addPoint(a,i);for(let e=0;e<=1;e++){const t=6*l[e]-12*c[e]+6*u[e],n=-3*l[e]+9*c[e]-9*u[e]+3*p[e],o=3*c[e]-3*l[e];if(0===n){if(0===t)continue;const n=-o/t;0=0&&n>0&&(e+=" "),e+=t(o)}return e}e=void 0!==e?e:2;let o="";for(let e=0;e=0&&e<=255,"Byte value should be between 0 and 255."),[e]},F.BYTE=H(1),A.CHAR=function(e){return[e.charCodeAt(0)]},F.CHAR=H(1),A.CHARARRAY=function(e){const t=[];for(let n=0;n>8&255,255&e]},F.USHORT=H(2),A.SHORT=function(e){return e>=32768&&(e=-(65536-e)),[e>>8&255,255&e]},F.SHORT=H(2),A.UINT24=function(e){return[e>>16&255,e>>8&255,255&e]},F.UINT24=H(3),A.ULONG=function(e){return[e>>24&255,e>>16&255,e>>8&255,255&e]},F.ULONG=H(4),A.LONG=function(e){return e>=2147483648&&(e=-(4294967296-e)),[e>>24&255,e>>16&255,e>>8&255,255&e]},F.LONG=H(4),A.FIXED=A.ULONG,F.FIXED=F.ULONG,A.FWORD=A.SHORT,F.FWORD=F.SHORT,A.UFWORD=A.USHORT,F.UFWORD=F.USHORT,A.LONGDATETIME=function(e){return[0,0,0,0,e>>24&255,e>>16&255,e>>8&255,255&e]},F.LONGDATETIME=H(8),A.TAG=function(e){return N.argument(4===e.length,"Tag should be exactly 4 ASCII characters."),[e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)]},F.TAG=H(4),A.Card8=A.BYTE,F.Card8=F.BYTE,A.Card16=A.USHORT,F.Card16=F.USHORT,A.OffSize=A.BYTE,F.OffSize=F.BYTE,A.SID=A.USHORT,F.SID=F.USHORT,A.NUMBER=function(e){return e>=-107&&e<=107?[e+139]:e>=108&&e<=1131?[247+((e-=108)>>8),255&e]:e>=-1131&&e<=-108?[251+((e=-e-108)>>8),255&e]:e>=-32768&&e<=32767?A.NUMBER16(e):A.NUMBER32(e)},F.NUMBER=function(e){return A.NUMBER(e).length},A.NUMBER16=function(e){return[28,e>>8&255,255&e]},F.NUMBER16=H(3),A.NUMBER32=function(e){return[29,e>>24&255,e>>16&255,e>>8&255,255&e]},F.NUMBER32=H(5),A.REAL=function(e){let t=e.toString();const n=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(t);if(n){const o=parseFloat("1e"+((n[2]?+n[2]:0)+n[1].length));t=(Math.round(e*o)/o).toString()}let o="";for(let e=0,n=t.length;e>8&255,t[t.length]=255&o}return t},F.UTF16=function(e){return 2*e.length};const z={"x-mac-croatian":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø¿¡¬√ƒ≈Ć«Č… ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ","x-mac-cyrillic":"АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњјЅ¬√ƒ≈∆«»… ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю","x-mac-gaelic":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæøṁṖṗɼƒſṠ«»… ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ","x-mac-greek":"Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩάΝ¬ΟΡ≈Τ«»… ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ­","x-mac-icelandic":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüÝ°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-inuit":"ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗᓘᓚᓛᓪᔨᔩᔪᔫᔭ… ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł","x-mac-ce":"ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅņѬ√ńŇ∆«»… ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ",macintosh:"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-romanian":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-turkish":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ"};P.MACSTRING=function(e,t,n,o){const r=z[o];if(void 0===r)return;let s="";for(let o=0;o=-128&&e<=127}function X(e,t,n){let o=0;const r=e.length;for(;t>8&255,t+256&255)}return s}A.MACSTRING=function(e,t){const n=function(e){if(!_){_={};for(let e in z)_[e]=new String(e)}const t=_[e];if(void 0===t)return;if(W){const e=W.get(t);if(void 0!==e)return e}const n=z[e];if(void 0===n)return;const o={};for(let e=0;e=128&&(r=n[r],void 0===r))return;o[t]=r}return o},F.MACSTRING=function(e,t){const n=A.MACSTRING(e,t);return void 0!==n?n.length:0},A.VARDELTAS=function(e){let t=0;const n=[];for(;t=-128&&o<=127?V(e,t,n):j(e,t,n)}return n},A.INDEX=function(e){let t=1;const n=[t],o=[];for(let r=0;r>8,t[s+1]=255&a,t=t.concat(o[n])}return t},F.TABLE=function(e){let t=0;const n=e.fields.length;for(let o=0;o0)return new ce(this.data,this.offset+t).parseStruct(e)},ce.prototype.parseListOfLists=function(e){const t=this.parseOffset16List(),n=t.length,o=this.relativeOffset,r=new Array(n);for(let o=0;o=0;r-=1){const n=pe.getUShort(e,t+4+8*r),s=pe.getUShort(e,t+4+8*r+2);if(3===n&&(0===s||1===s||10===s)){o=pe.getULong(e,t+4+8*r+4);break}}if(-1===o)throw new Error("No valid cmap sub-tables found.");const r=new pe.Parser(e,t+o);if(n.format=r.parseUShort(),12===n.format)!function(e,t){let n;t.parseUShort(),e.length=t.parseULong(),e.language=t.parseULong(),e.groupCount=n=t.parseULong(),e.glyphIndexMap={};for(let o=0;o>1,t.skip("uShort",3),e.glyphIndexMap={};const a=new pe.Parser(n,o+r+14),i=new pe.Parser(n,o+r+16+2*s),l=new pe.Parser(n,o+r+16+4*s),c=new pe.Parser(n,o+r+16+6*s);let u=o+r+16+8*s;for(let t=0;t0?(s=e.parseByte(),0==(t&r)&&(s=-s),s=n+s):s=(t&r)>0?n:n+e.parseShort(),s}function Ee(e,t,n){const o=new pe.Parser(t,n);let r,s;if(e.numberOfContours=o.parseShort(),e._xMin=o.parseShort(),e._yMin=o.parseShort(),e._xMax=o.parseShort(),e._yMax=o.parseShort(),e.numberOfContours>0){const t=e.endPointIndices=[];for(let n=0;n0){const t=o.parseByte();for(let n=0;n0){const a=[];let i;if(n>0){for(let e=0;e=0,a.push(i);let e=0;for(let t=0;t0?(2&r)>0?(n.dx=o.parseShort(),n.dy=o.parseShort()):n.matchedPoints=[o.parseUShort(),o.parseUShort()]:(2&r)>0?(n.dx=o.parseChar(),n.dy=o.parseChar()):n.matchedPoints=[o.parseByte(),o.parseByte()],(8&r)>0?n.xScale=n.yScale=o.parseF2Dot14():(64&r)>0?(n.xScale=o.parseF2Dot14(),n.yScale=o.parseF2Dot14()):(128&r)>0&&(n.xScale=o.parseF2Dot14(),n.scale01=o.parseF2Dot14(),n.scale10=o.parseF2Dot14(),n.yScale=o.parseF2Dot14()),e.components.push(n),t=!!(32&r)}if(256&r){e.instructionLength=o.parseUShort(),e.instructions=[];for(let t=0;tt.points.length-1||o.matchedPoints[1]>r.points.length-1)throw Error("Matched points out of range in "+t.name);const n=t.points[o.matchedPoints[0]];let s=r.points[o.matchedPoints[1]];const a={xScale:o.xScale,scale01:o.scale01,scale10:o.scale10,yScale:o.yScale,dx:0,dy:0};s=Oe([s],a)[0],a.dx=n.x-s.x,a.dy=n.y-s.y,e=Oe(r.points,a)}t.points=t.points.concat(e)}}return we(t.points)}var Re={getPath:we,parse:function(e,t,n,o){const r=new Ie.GlyphSet(o);for(let s=0;s>4,s=15&o;if(15===r)break;if(t+=n[r],15===s)break;t+=n[s]}return parseFloat(t)}(e);if(t>=32&&t<=246)return t-139;if(t>=247&&t<=250)return n=e.parseByte(),256*(t-247)+n+108;if(t>=251&&t<=254)return n=e.parseByte(),256*-(t-251)-n-108;throw new Error("Invalid b0 "+t)}function Pe(e,t,n){t=void 0!==t?t:0;const o=new pe.Parser(e,t),r=[];let s=[];for(n=void 0!==n?n:e.length;o.relativeOffset>1,l.length=0,d=!0}return function n(p){let x,U,T,E,O,w,k,R,D,C,L,I,M=0;for(;M1&&!d&&(v=l.shift()+h,d=!0),y+=l.pop(),b(m,y);break;case 5:for(;l.length>0;)m+=l.shift(),y+=l.shift(),i.lineTo(m,y);break;case 6:for(;l.length>0&&(m+=l.shift(),i.lineTo(m,y),0!==l.length);)y+=l.shift(),i.lineTo(m,y);break;case 7:for(;l.length>0&&(y+=l.shift(),i.lineTo(m,y),0!==l.length);)m+=l.shift(),i.lineTo(m,y);break;case 8:for(;l.length>0;)o=m+l.shift(),r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),m=s+l.shift(),y=a+l.shift(),i.curveTo(o,r,s,a,m,y);break;case 10:O=l.pop()+u,w=c[O],w&&n(w);break;case 11:return;case 12:switch(B=p[M],M+=1,B){case 35:o=m+l.shift(),r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),k=s+l.shift(),R=a+l.shift(),D=k+l.shift(),C=R+l.shift(),L=D+l.shift(),I=C+l.shift(),m=L+l.shift(),y=I+l.shift(),l.shift(),i.curveTo(o,r,s,a,k,R),i.curveTo(D,C,L,I,m,y);break;case 34:o=m+l.shift(),r=y,s=o+l.shift(),a=r+l.shift(),k=s+l.shift(),R=a,D=k+l.shift(),C=a,L=D+l.shift(),I=y,m=L+l.shift(),i.curveTo(o,r,s,a,k,R),i.curveTo(D,C,L,I,m,y);break;case 36:o=m+l.shift(),r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),k=s+l.shift(),R=a,D=k+l.shift(),C=a,L=D+l.shift(),I=C+l.shift(),m=L+l.shift(),i.curveTo(o,r,s,a,k,R),i.curveTo(D,C,L,I,m,y);break;case 37:o=m+l.shift(),r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),k=s+l.shift(),R=a+l.shift(),D=k+l.shift(),C=R+l.shift(),L=D+l.shift(),I=C+l.shift(),Math.abs(L-m)>Math.abs(I-y)?m=L+l.shift():y=I+l.shift(),i.curveTo(o,r,s,a,k,R),i.curveTo(D,C,L,I,m,y);break;default:console.log("Glyph "+t.index+": unknown operator 1200"+B),l.length=0}break;case 14:l.length>0&&!d&&(v=l.shift()+h,d=!0),g&&(i.closePath(),g=!1);break;case 18:S();break;case 19:case 20:S(),M+=f+7>>3;break;case 21:l.length>2&&!d&&(v=l.shift()+h,d=!0),y+=l.pop(),m+=l.pop(),b(m,y);break;case 22:l.length>1&&!d&&(v=l.shift()+h,d=!0),m+=l.pop(),b(m,y);break;case 23:S();break;case 24:for(;l.length>2;)o=m+l.shift(),r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),m=s+l.shift(),y=a+l.shift(),i.curveTo(o,r,s,a,m,y);m+=l.shift(),y+=l.shift(),i.lineTo(m,y);break;case 25:for(;l.length>6;)m+=l.shift(),y+=l.shift(),i.lineTo(m,y);o=m+l.shift(),r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),m=s+l.shift(),y=a+l.shift(),i.curveTo(o,r,s,a,m,y);break;case 26:for(l.length%2&&(m+=l.shift());l.length>0;)o=m,r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),m=s,y=a+l.shift(),i.curveTo(o,r,s,a,m,y);break;case 27:for(l.length%2&&(y+=l.shift());l.length>0;)o=m+l.shift(),r=y,s=o+l.shift(),a=r+l.shift(),m=s+l.shift(),y=a,i.curveTo(o,r,s,a,m,y);break;case 28:x=p[M],U=p[M+1],l.push((x<<24|U<<16)>>16),M+=2;break;case 29:O=l.pop()+e.gsubrsBias,w=e.gsubrs[O],w&&n(w);break;case 30:for(;l.length>0&&(o=m,r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),m=s+l.shift(),y=a+(1===l.length?l.shift():0),i.curveTo(o,r,s,a,m,y),0!==l.length);)o=m+l.shift(),r=y,s=o+l.shift(),a=r+l.shift(),y=a+l.shift(),m=s+(1===l.length?l.shift():0),i.curveTo(o,r,s,a,m,y);break;case 31:for(;l.length>0&&(o=m+l.shift(),r=y,s=o+l.shift(),a=r+l.shift(),y=a+l.shift(),m=s+(1===l.length?l.shift():0),i.curveTo(o,r,s,a,m,y),0!==l.length);)o=m,r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),m=s+l.shift(),y=a+(1===l.length?l.shift():0),i.curveTo(o,r,s,a,m,y);break;default:B<32?console.log("Glyph "+t.index+": unknown operator "+B):B<247?l.push(B-139):B<251?(x=p[M],M+=1,l.push(256*(B-247)+x+108)):B<255?(x=p[M],M+=1,l.push(256*-(B-251)-x-108)):(x=p[M],U=p[M+1],T=p[M+2],E=p[M+3],M+=4,l.push((x<<24|U<<16|T<<8|E)/65536))}}}(n),t.advanceWidth=v,i}function Ve(e,t){let n,o=de.indexOf(e);return o>=0&&(n=o),o=t.indexOf(e),o>=0?n=o+de.length:(n=de.length+t.length,t.push(e)),n}function je(e,t,n){const o={};for(let r=0;r=o)throw new Error("CFF table CID Font FDSelect has bad FD index value "+s+" (FD count "+o+")");r.push(s)}else{if(3!==i)throw new Error("CFF Table CID Font FDSelect table has unsupported format "+i);{const e=a.parseCard16();let t,i=a.parseCard16();if(0!==i)throw new Error("CFF Table CID Font FDSelect format 3 range has bad initial GID "+i);for(let l=0;l=o)throw new Error("CFF table CID Font FDSelect has bad FD index value "+s+" (FD count "+o+")");if(t>n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+t);for(;i=1&&(n.ulCodePageRange1=o.parseULong(),n.ulCodePageRange2=o.parseULong()),n.version>=2&&(n.sxHeight=o.parseShort(),n.sCapHeight=o.parseShort(),n.usDefaultChar=o.parseUShort(),n.usBreakChar=o.parseUShort(),n.usMaxContent=o.parseUShort()),n},make:function(e){return new oe.Table("OS/2",[{name:"version",type:"USHORT",value:3},{name:"xAvgCharWidth",type:"SHORT",value:0},{name:"usWeightClass",type:"USHORT",value:0},{name:"usWidthClass",type:"USHORT",value:0},{name:"fsType",type:"USHORT",value:0},{name:"ySubscriptXSize",type:"SHORT",value:650},{name:"ySubscriptYSize",type:"SHORT",value:699},{name:"ySubscriptXOffset",type:"SHORT",value:0},{name:"ySubscriptYOffset",type:"SHORT",value:140},{name:"ySuperscriptXSize",type:"SHORT",value:650},{name:"ySuperscriptYSize",type:"SHORT",value:699},{name:"ySuperscriptXOffset",type:"SHORT",value:0},{name:"ySuperscriptYOffset",type:"SHORT",value:479},{name:"yStrikeoutSize",type:"SHORT",value:49},{name:"yStrikeoutPosition",type:"SHORT",value:258},{name:"sFamilyClass",type:"SHORT",value:0},{name:"bFamilyType",type:"BYTE",value:0},{name:"bSerifStyle",type:"BYTE",value:0},{name:"bWeight",type:"BYTE",value:0},{name:"bProportion",type:"BYTE",value:0},{name:"bContrast",type:"BYTE",value:0},{name:"bStrokeVariation",type:"BYTE",value:0},{name:"bArmStyle",type:"BYTE",value:0},{name:"bLetterform",type:"BYTE",value:0},{name:"bMidline",type:"BYTE",value:0},{name:"bXHeight",type:"BYTE",value:0},{name:"ulUnicodeRange1",type:"ULONG",value:0},{name:"ulUnicodeRange2",type:"ULONG",value:0},{name:"ulUnicodeRange3",type:"ULONG",value:0},{name:"ulUnicodeRange4",type:"ULONG",value:0},{name:"achVendID",type:"CHARARRAY",value:"XXXX"},{name:"fsSelection",type:"USHORT",value:0},{name:"usFirstCharIndex",type:"USHORT",value:0},{name:"usLastCharIndex",type:"USHORT",value:0},{name:"sTypoAscender",type:"SHORT",value:0},{name:"sTypoDescender",type:"SHORT",value:0},{name:"sTypoLineGap",type:"SHORT",value:0},{name:"usWinAscent",type:"USHORT",value:0},{name:"usWinDescent",type:"USHORT",value:0},{name:"ulCodePageRange1",type:"ULONG",value:0},{name:"ulCodePageRange2",type:"ULONG",value:0},{name:"sxHeight",type:"SHORT",value:0},{name:"sCapHeight",type:"SHORT",value:0},{name:"usDefaultChar",type:"USHORT",value:0},{name:"usBreakChar",type:"USHORT",value:0},{name:"usMaxContext",type:"USHORT",value:0}],e)},unicodeRanges:gt,getUnicodeRange:function(e){for(let t=0;t=n.begin&&e=ye.length){const e=o.parseChar();n.names.push(o.parseString(e))}break;case 2.5:n.numberOfGlyphs=o.parseUShort(),n.offset=new Array(n.numberOfGlyphs);for(let e=0;et.value.tag?1:-1})),t.fields=t.fields.concat(o),t.fields=t.fields.concat(r),t}function kt(e,t,n){for(let n=0;n0){return e.glyphs.get(o).getMetrics()}}return n}function Rt(e){let t=0;for(let n=0;nm||void 0===l)&&m>0&&(l=m),c 123 are reserved for internal usage");f|=1<0?tt.make(w):void 0,D=yt.make(),C=$e.make(e.glyphs,{version:e.getEnglishName("version"),fullName:T,familyName:x,weightName:U,postScriptName:E,unitsPerEm:e.unitsPerEm,fontBBox:[0,d.yMin,d.ascender,d.advanceWidthMax]}),L=e.metas&&Object.keys(e.metas).length>0?Ut.make(e.metas):void 0,I=[g,m,y,v,k,S,D,C,b];R&&I.push(R),e.tables.gsub&&I.push(xt.make(e.tables.gsub)),L&&I.push(L);const M=wt(I),B=Et(M.encode()),G=M.fields;let N=!1;for(let e=0;e>>1,s=e[r].tag;if(s===t)return r;s>>1,s=e[r];if(s===t)return r;s=0)return o[r].script;if(t){const t={tag:e,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return o.splice(-1-r,0,t),t.script}}},getLangSysTable:function(e,t,n){const o=this.getScriptTable(e,n);if(o){if(!t||"dflt"===t||"DFLT"===t)return o.defaultLangSys;const e=Ct(o.langSysRecords,t);if(e>=0)return o.langSysRecords[e].langSys;if(n){const n={tag:t,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return o.langSysRecords.splice(-1-e,0,n),n.langSys}}},getFeatureTable:function(e,t,n,o){const r=this.getLangSysTable(e,t,o);if(r){let e;const t=r.featureIndexes,s=this.font.tables[this.tableName].features;for(let o=0;o=s[o-1].tag,"Features must be added in alphabetical order."),e={tag:n,feature:{params:0,lookupListIndexes:[]}},s.push(e),t.push(o),e.feature}}},getLookupTables:function(e,t,n,o,r){const s=this.getFeatureTable(e,t,n,r),a=[];if(s){let e;const t=s.lookupListIndexes,n=this.font.tables[this.tableName].lookups;for(let r=0;r=0){const e=s.ligatureSets[c];for(let t=0;t0&&e<0?n:o<0&&e>0?-n:e*o},Zt={x:1,y:0,axis:"x",distance:function(e,t,n,o){return(n?e.xo:e.x)-(o?t.xo:t.x)},interpolate:function(e,t,n,o){let r,s,a,i,l,c,u;if(!o||o===this)return r=e.xo-t.xo,s=e.xo-n.xo,l=t.x-t.xo,c=n.x-n.xo,a=Math.abs(r),i=Math.abs(s),u=a+i,0===u?void(e.x=e.xo+(l+c)/2):void(e.x=e.xo+(l*i+c*a)/u);r=o.distance(e,t,!0,!0),s=o.distance(e,n,!0,!0),l=o.distance(t,t,!1,!0),c=o.distance(n,n,!1,!0),a=Math.abs(r),i=Math.abs(s),u=a+i,0!==u?Zt.setRelative(e,e,(l*i+c*a)/u,o,!0):Zt.setRelative(e,e,(l+c)/2,o,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(e,t,n,o,r){if(!o||o===this)return void(e.x=(r?t.xo:t.x)+n);const s=r?t.xo:t.x,a=r?t.yo:t.y,i=s+n*o.x,l=a+n*o.y;e.x=i+(e.y-l)/o.normalSlope},slope:0,touch:function(e){e.xTouched=!0},touched:function(e){return e.xTouched},untouch:function(e){e.xTouched=!1}},Qt={x:0,y:1,axis:"y",distance:function(e,t,n,o){return(n?e.yo:e.y)-(o?t.yo:t.y)},interpolate:function(e,t,n,o){let r,s,a,i,l,c,u;if(!o||o===this)return r=e.yo-t.yo,s=e.yo-n.yo,l=t.y-t.yo,c=n.y-n.yo,a=Math.abs(r),i=Math.abs(s),u=a+i,0===u?void(e.y=e.yo+(l+c)/2):void(e.y=e.yo+(l*i+c*a)/u);r=o.distance(e,t,!0,!0),s=o.distance(e,n,!0,!0),l=o.distance(t,t,!1,!0),c=o.distance(n,n,!1,!0),a=Math.abs(r),i=Math.abs(s),u=a+i,0!==u?Qt.setRelative(e,e,(l*i+c*a)/u,o,!0):Qt.setRelative(e,e,(l+c)/2,o,!0)},normalSlope:0,setRelative:function(e,t,n,o,r){if(!o||o===this)return void(e.y=(r?t.yo:t.y)+n);const s=r?t.xo:t.x,a=r?t.yo:t.y,i=s+n*o.x,l=a+n*o.y;e.y=l+o.normalSlope*(e.x-i)},slope:Number.POSITIVE_INFINITY,touch:function(e){e.yTouched=!0},touched:function(e){return e.yTouched},untouch:function(e){e.yTouched=!1}};function $t(e,t){this.x=e,this.y=t,this.axis=void 0,this.slope=t/e,this.normalSlope=-e/t,Object.freeze(this)}function Kt(e,t){const n=Math.sqrt(e*e+t*t);return t/=n,1===(e/=n)&&0===t?Zt:0===e&&1===t?Qt:new $t(e,t)}function Jt(e,t,n,o){this.x=this.xo=Math.round(64*e)/64,this.y=this.yo=Math.round(64*t)/64,this.lastPointOfContour=n,this.onCurve=o,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}Object.freeze(Zt),Object.freeze(Qt),$t.prototype.distance=function(e,t,n,o){return this.x*Zt.distance(e,t,n,o)+this.y*Qt.distance(e,t,n,o)},$t.prototype.interpolate=function(e,t,n,o){let r,s,a,i,l,c,u;a=o.distance(e,t,!0,!0),i=o.distance(e,n,!0,!0),r=o.distance(t,t,!1,!0),s=o.distance(n,n,!1,!0),l=Math.abs(a),c=Math.abs(i),u=l+c,0!==u?this.setRelative(e,e,(r*c+s*l)/u,o,!0):this.setRelative(e,e,(r+s)/2,o,!0)},$t.prototype.setRelative=function(e,t,n,o,r){o=o||this;const s=r?t.xo:t.x,a=r?t.yo:t.y,i=s+n*o.x,l=a+n*o.y,c=o.normalSlope,u=this.slope,p=e.x,h=e.y;e.x=(u*p-c*i+l-h)/(u-c),e.y=u*(e.x-p)+h},$t.prototype.touch=function(e){e.xTouched=!0,e.yTouched=!0},Jt.prototype.nextTouched=function(e){let t=this.nextPointOnContour;for(;!e.touched(t)&&t!==this;)t=t.nextPointOnContour;return t},Jt.prototype.prevTouched=function(e){let t=this.prevPointOnContour;for(;!e.touched(t)&&t!==this;)t=t.prevPointOnContour;return t};const en=Object.freeze(new Jt(0,0)),tn={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function nn(e,t){switch(this.env=e,this.stack=[],this.prog=t,e){case"glyf":this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case"prep":this.fv=this.pv=this.dpv=Zt,this.round=_t}}function on(e){const t=e.tZone=new Array(e.gZone.length);for(let e=0;e=176&&o<=183)r+=o-176+1;else if(o>=184&&o<=191)r+=2*(o-184+1);else if(t&&1===s&&27===o)break}while(s>0);e.ip=r}function sn(e,t){exports.DEBUG&&console.log(t.step,"SVTCA["+e.axis+"]"),t.fv=t.pv=t.dpv=e}function an(e,t){exports.DEBUG&&console.log(t.step,"SPVTCA["+e.axis+"]"),t.pv=t.dpv=e}function ln(e,t){exports.DEBUG&&console.log(t.step,"SFVTCA["+e.axis+"]"),t.fv=e}function cn(e,t){const n=t.stack,o=n.pop(),r=n.pop(),s=t.z2[o],a=t.z1[r];let i,l;exports.DEBUG&&console.log("SPVTL["+e+"]",o,r),e?(i=s.y-a.y,l=a.x-s.x):(i=a.x-s.x,l=a.y-s.y),t.pv=t.dpv=Kt(i,l)}function un(e,t){const n=t.stack,o=n.pop(),r=n.pop(),s=t.z2[o],a=t.z1[r];let i,l;exports.DEBUG&&console.log("SFVTL["+e+"]",o,r),e?(i=s.y-a.y,l=a.x-s.x):(i=a.x-s.x,l=a.y-s.y),t.fv=Kt(i,l)}function pn(e){exports.DEBUG&&console.log(e.step,"POP[]"),e.stack.pop()}function hn(e,t){const n=t.stack.pop(),o=t.z0[n],r=t.fv,s=t.pv;exports.DEBUG&&console.log(t.step,"MDAP["+e+"]",n);let a=s.distance(o,en);e&&(a=t.round(a)),r.setRelative(o,en,a,s),r.touch(o),t.rp0=t.rp1=n}function fn(e,t){const n=t.z2,o=n.length-2;let r,s,a;exports.DEBUG&&console.log(t.step,"IUP["+e.axis+"]");for(let t=0;t1?"loop "+(t.loop-i)+": ":"")+"SHP["+(e?"rp1":"rp2")+"]",o)}t.loop=1}function gn(e,t){const n=t.stack,o=e?t.rp1:t.rp2,r=(e?t.z0:t.z1)[o],s=t.fv,a=t.pv,i=n.pop(),l=t.z2[t.contours[i]];let c=l;exports.DEBUG&&console.log(t.step,"SHC["+e+"]",i);const u=a.distance(r,r,!1,!0);do{c!==r&&s.setRelative(c,c,u,a),c=c.nextPointOnContour}while(c!==l)}function mn(e,t){const n=t.stack,o=e?t.rp1:t.rp2,r=(e?t.z0:t.z1)[o],s=t.fv,a=t.pv,i=n.pop();let l,c;switch(exports.DEBUG&&console.log(t.step,"SHZ["+e+"]",i),i){case 0:l=t.tZone;break;case 1:l=t.gZone;break;default:throw new Error("Invalid zone")}const u=a.distance(r,r,!1,!0),p=l.length-2;for(let e=0;e",i),t.stack.push(Math.round(64*i))}function xn(e,t){const n=t.stack,o=n.pop(),r=t.fv,s=t.pv,a=t.ppem,i=t.deltaBase+16*(e-1),l=t.deltaShift,c=t.z0;exports.DEBUG&&console.log(t.step,"DELTAP["+e+"]",o,n);for(let e=0;e>4)!==a)continue;let u=(15&o)-8;u>=0&&u++,exports.DEBUG&&console.log(t.step,"DELTAPFIX",e,"by",u*l);const p=c[e];r.setRelative(p,p,u*l,s)}}function Un(e,t){const n=t.stack,o=n.pop();exports.DEBUG&&console.log(t.step,"ROUND[]"),n.push(64*t.round(o/64))}function Tn(e,t){const n=t.stack,o=n.pop(),r=t.ppem,s=t.deltaBase+16*(e-1),a=t.deltaShift;exports.DEBUG&&console.log(t.step,"DELTAC["+e+"]",o,n);for(let e=0;e>4)!==r)continue;let i=(15&o)-8;i>=0&&i++;const l=i*a;exports.DEBUG&&console.log(t.step,"DELTACFIX",e,"by",l),t.cvt[e]+=l}}function En(e,t){const n=t.stack,o=n.pop(),r=n.pop(),s=t.z2[o],a=t.z1[r];let i,l;exports.DEBUG&&console.log("SDPVTL["+e+"]",o,r),e?(i=s.y-a.y,l=a.x-s.x):(i=a.x-s.x,l=a.y-s.y),t.dpv=Kt(i,l)}function On(e,t){const n=t.stack,o=t.prog;let r=t.ip;exports.DEBUG&&console.log(t.step,"PUSHB["+e+"]");for(let t=0;t=0?1:-1,m=Math.abs(m),e&&(v=s.cvt[i],o&&Math.abs(m-v)":"_")+(o?"R":"_")+(0===r?"Gr":1===r?"Bl":2===r?"Wh":"")+"]",e?i+"("+s.cvt[i]+","+v+")":"",l,"(d =",g,"->",y*m,")"),s.rp1=s.rp0,s.rp2=l,t&&(s.rp0=l)}function Rn(e){(e=e||{}).empty||(Nt(e.familyName,"When creating a new Font object, familyName is required."),Nt(e.styleName,"When creating a new Font object, styleName is required."),Nt(e.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),Nt(e.ascender,"When creating a new Font object, ascender is required."),Nt(e.descender,"When creating a new Font object, descender is required."),Nt(e.descender<0,"Descender should be negative (e.g. -512)."),this.names={fontFamily:{en:e.familyName||" "},fontSubfamily:{en:e.styleName||" "},fullName:{en:e.fullName||e.familyName+" "+e.styleName},postScriptName:{en:e.postScriptName||e.familyName+e.styleName},designer:{en:e.designer||" "},designerURL:{en:e.designerURL||" "},manufacturer:{en:e.manufacturer||" "},manufacturerURL:{en:e.manufacturerURL||" "},license:{en:e.license||" "},licenseURL:{en:e.licenseURL||" "},version:{en:e.version||"Version 0.1"},description:{en:e.description||" "},copyright:{en:e.copyright||" "},trademark:{en:e.trademark||" "}},this.unitsPerEm=e.unitsPerEm||1e3,this.ascender=e.ascender,this.descender=e.descender,this.createdTimestamp=e.createdTimestamp,this.tables={os2:{usWeightClass:e.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:e.widthClass||this.usWidthClasses.MEDIUM,fsSelection:e.fsSelection||this.fsSelectionValues.REGULAR}}),this.supported=!0,this.glyphs=new Ie.GlyphSet(this,e.glyphs||[]),this.encoding=new ve(this),this.substitution=new It(this),this.tables=this.tables||{},Object.defineProperty(this,"hinting",{get:function(){return this._hinting?this._hinting:"truetype"===this.outlinesFormat?this._hinting=new zt(this):void 0}})}function Dn(e,t){const n=JSON.stringify(e);let o=256;for(let e in t){let r=parseInt(e);if(r&&!(r<256)){if(JSON.stringify(t[e])===n)return r;o<=r&&(o=r+1)}}return t[o]=e,o}function Cn(e,t,n){const o=Dn(t.name,n);return[{name:"tag_"+e,type:"TAG",value:t.tag},{name:"minValue_"+e,type:"FIXED",value:t.minValue<<16},{name:"defaultValue_"+e,type:"FIXED",value:t.defaultValue<<16},{name:"maxValue_"+e,type:"FIXED",value:t.maxValue<<16},{name:"flags_"+e,type:"USHORT",value:0},{name:"nameID_"+e,type:"USHORT",value:o}]}function Ln(e,t,n){const o={},r=new pe.Parser(e,t);return o.tag=r.parseTag(),o.minValue=r.parseFixed(),o.defaultValue=r.parseFixed(),o.maxValue=r.parseFixed(),r.skip("uShort",1),o.name=n[r.parseUShort()]||{},o}function In(e,t,n,o){const r=[{name:"nameID_"+e,type:"USHORT",value:Dn(t.name,o)},{name:"flags_"+e,type:"USHORT",value:0}];for(let o=0;o2)return;const n=this.font;let o=this._prepState;if(!o||o.ppem!==t){let e=this._fpgmState;if(!e){nn.prototype=tn,e=this._fpgmState=new nn("fpgm",n.tables.fpgm),e.funcs=[],e.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),e.step=-1);try{At(e)}catch(e){return console.log("Hinting error in FPGM:"+e),void(this._errorState=3)}}nn.prototype=e,o=this._prepState=new nn("prep",n.tables.prep),o.ppem=t;const r=n.tables.cvt;if(r){const e=o.cvt=new Array(r.length),s=t/n.unitsPerEm;for(let t=0;t1))try{return Ft(e,o)}catch(e){return this._errorState<1&&(console.log("Hinting error:"+e),console.log("Note: further hinting errors are silenced")),void(this._errorState=1)}},Ft=function(e,t){const n=t.ppem/t.font.unitsPerEm,o=n;let r,s,a,i=e.components;if(nn.prototype=t,i){const l=t.font;s=[],r=[];for(let e=0;e1?"loop "+(e.loop-n)+": ":"")+"SHPIX[]",a,r),o.setRelative(i,i,r),o.touch(i)}e.loop=1},function(e){const t=e.stack,n=e.rp1,o=e.rp2;let r=e.loop;const s=e.z0[n],a=e.z1[o],i=e.fv,l=e.dpv,c=e.z2;for(;r--;){const u=t.pop(),p=c[u];exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-r)+": ":"")+"IP[]",u,n,"<->",o),i.interpolate(p,s,a,l),i.touch(p)}e.loop=1},yn.bind(void 0,0),yn.bind(void 0,1),function(e){const t=e.stack,n=e.rp0,o=e.z0[n];let r=e.loop;const s=e.fv,a=e.pv,i=e.z1;for(;r--;){const n=t.pop(),l=i[n];exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-r)+": ":"")+"ALIGNRP[]",n),s.setRelative(l,o,0,a),s.touch(l)}e.loop=1},function(e){exports.DEBUG&&console.log(e.step,"RTDG[]"),e.round=qt},vn.bind(void 0,0),vn.bind(void 0,1),function(e){const t=e.prog;let n=e.ip;const o=e.stack,r=t[++n];exports.DEBUG&&console.log(e.step,"NPUSHB[]",r);for(let e=0;en?1:0)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"GTEQ[]",n,o),t.push(o>=n?1:0)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"EQ[]",n,o),t.push(n===o?1:0)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"NEQ[]",n,o),t.push(n!==o?1:0)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"ODD[]",n),t.push(Math.trunc(n)%2?1:0)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"EVEN[]",n),t.push(Math.trunc(n)%2?0:1)},function(e){let t=e.stack.pop();exports.DEBUG&&console.log(e.step,"IF[]",t),t||(rn(e,!0),exports.DEBUG&&console.log(e.step,"EIF[]"))},function(e){exports.DEBUG&&console.log(e.step,"EIF[]")},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"AND[]",n,o),t.push(n&&o?1:0)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"OR[]",n,o),t.push(n||o?1:0)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"NOT[]",n),t.push(n?0:1)},xn.bind(void 0,1),function(e){const t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SDB[]",t),e.deltaBase=t},function(e){const t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SDS[]",t),e.deltaShift=Math.pow(.5,t)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"ADD[]",n,o),t.push(o+n)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"SUB[]",n,o),t.push(o-n)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"DIV[]",n,o),t.push(64*o/n)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"MUL[]",n,o),t.push(o*n/64)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"ABS[]",n),t.push(Math.abs(n))},function(e){const t=e.stack;let n=t.pop();exports.DEBUG&&console.log(e.step,"NEG[]",n),t.push(-n)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"FLOOR[]",n),t.push(64*Math.floor(n/64))},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"CEILING[]",n),t.push(64*Math.ceil(n/64))},Un.bind(void 0,0),Un.bind(void 0,1),Un.bind(void 0,2),Un.bind(void 0,3),void 0,void 0,void 0,void 0,function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"WCVTF[]",n,o),e.cvt[o]=n*e.ppem/e.font.unitsPerEm},xn.bind(void 0,2),xn.bind(void 0,3),Tn.bind(void 0,1),Tn.bind(void 0,2),Tn.bind(void 0,3),function(e){let t,n=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"SROUND[]",n),e.round=Yt,192&n){case 0:t=.5;break;case 64:t=1;break;case 128:t=2;break;default:throw new Error("invalid SROUND value")}switch(e.srPeriod=t,48&n){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*t;break;case 32:e.srPhase=.5*t;break;case 48:e.srPhase=.75*t;break;default:throw new Error("invalid SROUND value")}n&=15,e.srThreshold=0===n?0:(n/8-.5)*t},function(e){let t,n=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"S45ROUND[]",n),e.round=Yt,192&n){case 0:t=Math.sqrt(2)/2;break;case 64:t=Math.sqrt(2);break;case 128:t=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(e.srPeriod=t,48&n){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*t;break;case 32:e.srPhase=.5*t;break;case 48:e.srPhase=.75*t;break;default:throw new Error("invalid S45ROUND value")}n&=15,e.srThreshold=0===n?0:(n/8-.5)*t},void 0,void 0,function(e){exports.DEBUG&&console.log(e.step,"ROFF[]"),e.round=Wt},void 0,function(e){exports.DEBUG&&console.log(e.step,"RUTG[]"),e.round=Vt},function(e){exports.DEBUG&&console.log(e.step,"RDTG[]"),e.round=jt},pn,pn,void 0,void 0,void 0,void 0,void 0,function(e){const t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SCANCTRL[]",t)},En.bind(void 0,0),En.bind(void 0,1),function(e){const t=e.stack,n=t.pop();let o=0;exports.DEBUG&&console.log(e.step,"GETINFO[]",n),1&n&&(o=35),32&n&&(o|=4096),t.push(o)},void 0,function(e){const t=e.stack,n=t.pop(),o=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,"ROLL[]"),t.push(o),t.push(n),t.push(r)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"MAX[]",n,o),t.push(Math.max(o,n))},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"MIN[]",n,o),t.push(Math.min(o,n))},function(e){const t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SCANTYPE[]",t)},function(e){const t=e.stack.pop();let n=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"INSTCTRL[]",t,n),t){case 1:return void(e.inhibitGridFit=!!n);case 2:return void(e.ignoreCvt=!!n);default:throw new Error("invalid INSTCTRL[] selector")}},void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,On.bind(void 0,1),On.bind(void 0,2),On.bind(void 0,3),On.bind(void 0,4),On.bind(void 0,5),On.bind(void 0,6),On.bind(void 0,7),On.bind(void 0,8),wn.bind(void 0,1),wn.bind(void 0,2),wn.bind(void 0,3),wn.bind(void 0,4),wn.bind(void 0,5),wn.bind(void 0,6),wn.bind(void 0,7),wn.bind(void 0,8),kn.bind(void 0,0,0,0,0,0),kn.bind(void 0,0,0,0,0,1),kn.bind(void 0,0,0,0,0,2),kn.bind(void 0,0,0,0,0,3),kn.bind(void 0,0,0,0,1,0),kn.bind(void 0,0,0,0,1,1),kn.bind(void 0,0,0,0,1,2),kn.bind(void 0,0,0,0,1,3),kn.bind(void 0,0,0,1,0,0),kn.bind(void 0,0,0,1,0,1),kn.bind(void 0,0,0,1,0,2),kn.bind(void 0,0,0,1,0,3),kn.bind(void 0,0,0,1,1,0),kn.bind(void 0,0,0,1,1,1),kn.bind(void 0,0,0,1,1,2),kn.bind(void 0,0,0,1,1,3),kn.bind(void 0,0,1,0,0,0),kn.bind(void 0,0,1,0,0,1),kn.bind(void 0,0,1,0,0,2),kn.bind(void 0,0,1,0,0,3),kn.bind(void 0,0,1,0,1,0),kn.bind(void 0,0,1,0,1,1),kn.bind(void 0,0,1,0,1,2),kn.bind(void 0,0,1,0,1,3),kn.bind(void 0,0,1,1,0,0),kn.bind(void 0,0,1,1,0,1),kn.bind(void 0,0,1,1,0,2),kn.bind(void 0,0,1,1,0,3),kn.bind(void 0,0,1,1,1,0),kn.bind(void 0,0,1,1,1,1),kn.bind(void 0,0,1,1,1,2),kn.bind(void 0,0,1,1,1,3),kn.bind(void 0,1,0,0,0,0),kn.bind(void 0,1,0,0,0,1),kn.bind(void 0,1,0,0,0,2),kn.bind(void 0,1,0,0,0,3),kn.bind(void 0,1,0,0,1,0),kn.bind(void 0,1,0,0,1,1),kn.bind(void 0,1,0,0,1,2),kn.bind(void 0,1,0,0,1,3),kn.bind(void 0,1,0,1,0,0),kn.bind(void 0,1,0,1,0,1),kn.bind(void 0,1,0,1,0,2),kn.bind(void 0,1,0,1,0,3),kn.bind(void 0,1,0,1,1,0),kn.bind(void 0,1,0,1,1,1),kn.bind(void 0,1,0,1,1,2),kn.bind(void 0,1,0,1,1,3),kn.bind(void 0,1,1,0,0,0),kn.bind(void 0,1,1,0,0,1),kn.bind(void 0,1,1,0,0,2),kn.bind(void 0,1,1,0,0,3),kn.bind(void 0,1,1,0,1,0),kn.bind(void 0,1,1,0,1,1),kn.bind(void 0,1,1,0,1,2),kn.bind(void 0,1,1,0,1,3),kn.bind(void 0,1,1,1,0,0),kn.bind(void 0,1,1,1,0,1),kn.bind(void 0,1,1,1,0,2),kn.bind(void 0,1,1,1,0,3),kn.bind(void 0,1,1,1,1,0),kn.bind(void 0,1,1,1,1,1),kn.bind(void 0,1,1,1,1,2),kn.bind(void 0,1,1,1,1,3)],Rn.prototype.hasChar=function(e){return null!==this.encoding.charToGlyphIndex(e)},Rn.prototype.charToGlyphIndex=function(e){return this.encoding.charToGlyphIndex(e)},Rn.prototype.charToGlyph=function(e){const t=this.charToGlyphIndex(e);let n=this.glyphs.get(t);return n||(n=this.glyphs.get(0)),n},Rn.prototype.stringToGlyphs=function(e,t){t=t||this.defaultRenderOptions;const n=[];for(let t=0;t>1;e1&&console.warn("Only the first kern subtable is supported."),e.skip("uLong");const n=255&e.parseUShort();if(e.skip("uShort"),0===n){const n=e.parseUShort();e.skip("uShort",3);for(let o=0;o{const t=jn.loadSync(e);Qn.font=t,Qn.ascender=t.ascender,Qn.descender=t.descender}};const Kn=$n.options,Jn=function(e,t){return Math.round(e+Math.random()*(t-e))};const eo=function(e,t){return{text:(e+t).toString(),equation:e+"+"+t}},to=function(e,t){return{text:(e-t).toString(),equation:e+"-"+t}};function no(e,t,n){return 6*(n=(n+1)%1)<1?e+(t-e)*n*6:2*n<1?t:3*n<2?e+(t-e)*(2/3-n)*6:e}var oo={int:Jn,greyColor:function(e,t){const n=Jn(e=e||1,t=t||9).toString(16);return`#${n}${n}${n}`},captchaText:function(e){"number"==typeof e&&(e={size:e});const t=(e=e||{}).size||4,n=e.ignoreChars||"";let o=-1,r="",s=e.charPreset||Kn.charPreset;n&&(s=function(e,t){return e.split("").filter(e=>-1===t.indexOf(e))}(s,n));const a=s.length-1;for(;++o>16,o=t>>8&255,r=255&t,s=Math.max(n,o,r),a=Math.min(n,o,r);return(s+a)/510}(e):1;let r,s;o>=.5?(r=Math.round(100*o)-45,s=Math.round(100*o)-25):(r=Math.round(100*o)+25,s=Math.round(100*o)+45);const a=Jn(r,s)/100,i=a<.5?a*(a+n):a+n-a*n,l=2*a-i,c=Math.floor(255*no(l,i,t+1/3)),u=Math.floor(255*no(l,i,t));return"#"+(Math.floor(255*no(l,i,t-1/3))|u<<8|c<<16|1<<24).toString(16).slice(1)}};const ro=$n.options,so=function(e,t){e=e||oo.captchaText();const n=(t=Object.assign({},ro,t)).width,o=t.height,r=t.background||t.backgroundColor;r&&(t.color=!0);const s=r?``:"",a=[].concat(function(e,t,n){const o=n.color,r=[],s=n.inverse?7:1,a=n.inverse?15:9;let i=-1;for(;++i`)}return r}(n,o,t)).concat(function(e,t,n,o,r){const s=e.length,a=(t-2)/(s+1),i=o.inverse?10:0,l=o.inverse?14:4;let u=-1;const p=[],h=r||o.color?oo.color(o.background):oo.greyColor(i,l);for(;++u`)}return p}(e,n,o,t)).sort(()=>Math.random()-.5).join("");return`${``}${s}${a}`};var ao=so,io=oo.captchaText,lo=function(e){const t=e.text||oo.captchaText(e);return{text:t,data:so(t,e)}},co=function(e){const t=oo.mathExpr(e.mathMin,e.mathMax,e.mathOperator);return{text:t.text,data:so(t.equation,e)}},uo=ro,po=$n.loadFont;ao.randomText=io,ao.create=lo,ao.createMathExpr=co,ao.options=uo,ao.loadFont=po;var ho=ao;const fo=Object.prototype.toString;function go(e){return"[object Object]"===fo.call(e)}function mo(){"development"===process.env.NODE_ENV&&console.log(...arguments)}const yo=async function(){};function vo(e){return yo.constructor===e.constructor?async function(){const t=await e.apply(this,arguments);return go(t)&&(t.msg&&(t.message=t.msg,t.errMsg=t.msg),0===t.code?t.errCode=t.code:t.errCode=s[t.code]||t.code),t}:function(){const t=e.apply(this,arguments);return go(t)&&(t.msg&&(t.message=t.msg,t.errMsg=t.msg),0===t.code?t.errCode=t.code:t.errCode=s[t.code]||t.code),t}}const bo=uniCloud.database().collection("opendb-verify-codes");class So{async setVerifyCode({deviceId:e,code:t,expiresDate:n,scene:o}){if(!e)return{code:10101,msg:"deviceId不可为空"};if(!t)return{code:10102,msg:"验证码不可为空"};n||(n=180);const r=Date.now(),s={deviceId:e,scene:o,code:t.toLocaleLowerCase(),state:0,ip:__ctx__.CLIENTIP,created_date:r,expired_date:r+1e3*n};return mo("addRes",await bo.add(s)),{code:0,deviceId:e}}async verifyCode({deviceId:e,code:t,scene:n}){if(!e)return{code:10101,msg:"deviceId不可为空"};if(!t)return{code:10102,msg:"验证码不可为空"};const o=Date.now(),r={deviceId:e,scene:n,code:t.toLocaleLowerCase(),state:0},s=await bo.where(r).orderBy("created_date","desc").limit(1).get();if(mo("verifyRecord:",s),s&&s.data&&s.data.length>0){const e=s.data[0];if(e.expired_date{e.scene&&delete e.scene,this.pluginConfig.scene[n]=Object.assign({},t,e[n])})}}}{constructor(){super(),this.DEVICEID2opts={}}mergeConfig(e){const t=go(this.pluginConfig.scene)?this.pluginConfig.scene[e.scene]:e.scene;return Object.assign({},go(t)?t:this.pluginConfig,e)}async create(e={}){if(!e.scene)throw new Error("scene验证码场景不可为空");e=this.mergeConfig(e);let{scene:t,expiresDate:n,deviceId:o,...r}=e;if(o=o||__ctx__.DEVICEID,!o)throw new Error("deviceId不可为空");const s=new So;try{const{text:a,base64:i}=function(e={}){const{uniPlatform:t=""}=e;let n;n=e.mathExpr?ho.createMathExpr(e):ho.create(e);let o="data:image/svg+xml;utf8,"+n.data.replace(/#/g,"%23");return(!t||"string"==typeof t&&-1===t.indexOf("mp-"))&&(o=o.replace(/"/g,"'").replace(//g,"%3E")),{text:n.text,base64:o}}(r),l=await s.setVerifyCode({deviceId:o,code:a,expiresDate:n,scene:t});return l.code>0?{...l,code:10001}:(this.DEVICEID2opts[o]=e,{code:0,msg:"验证码获取成功",captchaBase64:i})}catch(e){return{code:10001,msg:"验证码生成失败:"+e.message}}}async verify({deviceId:e,captcha:t,scene:n}){if(!(e=e||__ctx__.DEVICEID))throw new Error("deviceId不可为空");if(!n)throw new Error("scene验证码场景不可为空");const o=new So;try{const r=await o.verifyCode({deviceId:e,code:t,scene:n});return r.code>0?r:{code:0,msg:"验证码通过"}}catch(e){return{code:10002,msg:"验证码校验失败:"+e.message}}}async refresh(e={}){let{scene:t,expiresDate:n,deviceId:o,...r}=e;if(o=o||__ctx__.DEVICEID,!o)throw new Error("deviceId不可为空");if(!t)throw new Error("scene验证码场景不可为空");const s=await bo.where({deviceId:o,scene:t}).orderBy("created_date","desc").limit(1).get();if(s&&s.data&&s.data.length>0){const e=s.data[0];await bo.doc(e._id).update({state:2}),Object.keys(r).length>0&&(this.DEVICEID2opts[o]=Object.assign({},this.DEVICEID2opts[o],r));let a={};try{a=await this.create(Object.assign({},this.DEVICEID2opts[o],{deviceId:o,scene:t,expiresDate:n}))}catch(e){return{code:50403,msg:e.message}}return a.code>0?{...a,code:50403}:{code:0,msg:"验证码刷新成功",captchaBase64:a.captchaBase64}}return{code:10003,msg:`验证码刷新失败:无此设备在 ${t} 场景信息,请重新获取`}}}const To=new So;Object.keys(To).forEach(e=>{Uo.prototype[e]=vo(To[e])});const Eo=new Uo,Oo=new Proxy(Eo,{get(e,t){if(t in e)return"function"==typeof e[t]?vo(e[t]).bind(Oo):e[t]}});module.exports=Oo; +"use strict";var e=require("assert"),t=require("path");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(e),r=n(t);const s={10001:"uni-captcha-create-fail",10002:"uni-captcha-verify-fail",10003:"uni-captcha-refresh-fail",10101:"uni-captcha-deviceId-required",10102:"uni-captcha-text-required",10103:"uni-captcha-verify-overdue",10104:"uni-captcha-verify-fail",50403:"uni-captcha-interior-fail"};function a(e){const t=.2*Math.random()-.1;switch(e.type){case"M":case"L":e.x+=t,e.y+=t;break;case"Q":case"C":e.x+=t,e.y+=t,e.x1+=t,e.y1+=t}return e}function i(e,t,n,o,r,s,a){let i,l,c,u,p,h;if(e<=0||e>=1)throw RangeError("spliteCurveAt requires position > 0 && position < 1");return u=[],p=0,i={},l={},c={},i.x=t,i.y=n,l.x=o,l.y=r,c.x=s,c.y=a,h=e,u[p++]=i.x,u[p++]=i.y,u[p++]=i.x+=(l.x-i.x)*h,u[p++]=i.y+=(l.y-i.y)*h,l.x+=(c.x-l.x)*h,l.y+=(c.y-l.y)*h,u[p++]=i.x+(l.x-i.x)*h,u[p++]=i.y+(l.y-i.y)*h,u[p++]=l.x,u[p++]=l.y,u[p++]=c.x,u[p++]=c.y,u}function l(e,t){return Math.random()*(t-e)+e}var c=function(e,t){const n=e[0];o.default(n,"expect a string");const r=t.fontSize,s=r/t.font.unitsPerEm,c=t.font.charToGlyph(n),u=c.advanceWidth?c.advanceWidth*s:0,p=t.x-u/2,h=(t.ascender+t.descender)*s,f=t.y+h/2,d=c.getPath(p,f,r);d.commands.forEach(a),d.commands=function(e,t){const n=[];for(let o=0;ot.truncateLineProbability){const e=l(-.1,.1);n.push(r),n.push({type:"L",x:(r.x+s.x)/2+e,y:(r.y+s.y)/2+e})}else n.push(r)}else if("Q"===r.type&&o>=1){const s=e[o-1];if(("L"===s.type||"M"===s.type)&&Math.random()>t.truncateCurveProbability){const e=s.x,o=s.y,a=l(-.1,.1),c=r.x1+a,u=r.y1+a,p=r.x+a,h=r.y+a,f=i(l(t.truncateCurvePositionMin,t.truncateCurvePositionMax),e,o,c,u,p,h),d={type:"Q",x1:f[2],y1:f[3],x:f[4],y:f[5]},g={type:"L",x:f[4],y:f[5]},m={type:"Q",x1:f[6],y1:f[7],x:f[8],y:f[9]},y={type:"L",x:f[8],y:f[9]};n.push(d),n.push(g),n.push(m),n.push(y)}}else n.push(r)}return n}(d.commands,t);return d.toPathData()};function u(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function p(e,t){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=t,this.destLen=0,this.ltree=new u,this.dtree=new u}var h=new u,f=new u,d=new Uint8Array(30),g=new Uint16Array(30),m=new Uint8Array(30),y=new Uint16Array(30),v=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),b=new u,S=new Uint8Array(320);function x(e,t,n,o){var r,s;for(r=0;r>>=1,t}function O(e,t,n){if(!t)return n;for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<>>16-t;return e.tag>>>=t,e.bitcount-=t,o+n}function w(e,t){for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<>>=1,++r,n+=t.table[r],o-=t.table[r]}while(o>=0);return e.tag=s,e.bitcount-=r,t.trans[n+o]}function k(e,t,n){var o,r,s,a,i,l;for(o=O(e,5,257),r=O(e,5,1),s=O(e,4,4),a=0;a<19;++a)S[a]=0;for(a=0;a8;)e.sourceIndex--,e.bitcount-=8;if((t=256*(t=e.source[e.sourceIndex+1])+e.source[e.sourceIndex])!==(65535&~(256*e.source[e.sourceIndex+3]+e.source[e.sourceIndex+2])))return-3;for(e.sourceIndex+=4,n=t;n;--n)e.dest[e.destLen++]=e.source[e.sourceIndex++];return e.bitcount=0,0}!function(e,t){var n;for(n=0;n<7;++n)e.table[n]=0;for(e.table[7]=24,e.table[8]=152,e.table[9]=112,n=0;n<24;++n)e.trans[n]=256+n;for(n=0;n<144;++n)e.trans[24+n]=n;for(n=0;n<8;++n)e.trans[168+n]=280+n;for(n=0;n<112;++n)e.trans[176+n]=144+n;for(n=0;n<5;++n)t.table[n]=0;for(t.table[5]=32,n=0;n<32;++n)t.trans[n]=n}(h,f),x(d,g,4,3),x(m,y,2,1),d[28]=0,g[28]=258;var C=function(e,t){var n,o,r=new p(e,t);do{switch(n=E(r),O(r,2,0)){case 0:o=D(r);break;case 1:o=R(r,h,f);break;case 2:k(r,r.ltree,r.dtree),o=R(r,r.ltree,r.dtree);break;default:o=-3}if(0!==o)throw new Error("Data error")}while(!n);return r.destLenthis.x2&&(this.x2=e)),"number"==typeof t&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=t,this.y2=t),tthis.y2&&(this.y2=t))},I.prototype.addX=function(e){this.addPoint(e,null)},I.prototype.addY=function(e){this.addPoint(null,e)},I.prototype.addBezier=function(e,t,n,o,r,s,a,i){const l=[e,t],c=[n,o],u=[r,s],p=[a,i];this.addPoint(e,t),this.addPoint(a,i);for(let e=0;e<=1;e++){const t=6*l[e]-12*c[e]+6*u[e],n=-3*l[e]+9*c[e]-9*u[e]+3*p[e],o=3*c[e]-3*l[e];if(0===n){if(0===t)continue;const n=-o/t;0=0&&n>0&&(e+=" "),e+=t(o)}return e}e=void 0!==e?e:2;let o="";for(let e=0;e=0&&e<=255,"Byte value should be between 0 and 255."),[e]},F.BYTE=H(1),A.CHAR=function(e){return[e.charCodeAt(0)]},F.CHAR=H(1),A.CHARARRAY=function(e){const t=[];for(let n=0;n>8&255,255&e]},F.USHORT=H(2),A.SHORT=function(e){return e>=32768&&(e=-(65536-e)),[e>>8&255,255&e]},F.SHORT=H(2),A.UINT24=function(e){return[e>>16&255,e>>8&255,255&e]},F.UINT24=H(3),A.ULONG=function(e){return[e>>24&255,e>>16&255,e>>8&255,255&e]},F.ULONG=H(4),A.LONG=function(e){return e>=2147483648&&(e=-(4294967296-e)),[e>>24&255,e>>16&255,e>>8&255,255&e]},F.LONG=H(4),A.FIXED=A.ULONG,F.FIXED=F.ULONG,A.FWORD=A.SHORT,F.FWORD=F.SHORT,A.UFWORD=A.USHORT,F.UFWORD=F.USHORT,A.LONGDATETIME=function(e){return[0,0,0,0,e>>24&255,e>>16&255,e>>8&255,255&e]},F.LONGDATETIME=H(8),A.TAG=function(e){return N.argument(4===e.length,"Tag should be exactly 4 ASCII characters."),[e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)]},F.TAG=H(4),A.Card8=A.BYTE,F.Card8=F.BYTE,A.Card16=A.USHORT,F.Card16=F.USHORT,A.OffSize=A.BYTE,F.OffSize=F.BYTE,A.SID=A.USHORT,F.SID=F.USHORT,A.NUMBER=function(e){return e>=-107&&e<=107?[e+139]:e>=108&&e<=1131?[247+((e-=108)>>8),255&e]:e>=-1131&&e<=-108?[251+((e=-e-108)>>8),255&e]:e>=-32768&&e<=32767?A.NUMBER16(e):A.NUMBER32(e)},F.NUMBER=function(e){return A.NUMBER(e).length},A.NUMBER16=function(e){return[28,e>>8&255,255&e]},F.NUMBER16=H(3),A.NUMBER32=function(e){return[29,e>>24&255,e>>16&255,e>>8&255,255&e]},F.NUMBER32=H(5),A.REAL=function(e){let t=e.toString();const n=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(t);if(n){const o=parseFloat("1e"+((n[2]?+n[2]:0)+n[1].length));t=(Math.round(e*o)/o).toString()}let o="";for(let e=0,n=t.length;e>8&255,t[t.length]=255&o}return t},F.UTF16=function(e){return 2*e.length};const z={"x-mac-croatian":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø¿¡¬√ƒ≈Ć«Č… ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ","x-mac-cyrillic":"АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњјЅ¬√ƒ≈∆«»… ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю","x-mac-gaelic":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæøṁṖṗɼƒſṠ«»… ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ","x-mac-greek":"Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩάΝ¬ΟΡ≈Τ«»… ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ­","x-mac-icelandic":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüÝ°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-inuit":"ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗᓘᓚᓛᓪᔨᔩᔪᔫᔭ… ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł","x-mac-ce":"ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅņѬ√ńŇ∆«»… ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ",macintosh:"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-romanian":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-turkish":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ"};P.MACSTRING=function(e,t,n,o){const r=z[o];if(void 0===r)return;let s="";for(let o=0;o=-128&&e<=127}function X(e,t,n){let o=0;const r=e.length;for(;t>8&255,t+256&255)}return s}A.MACSTRING=function(e,t){const n=function(e){if(!W){W={};for(let e in z)W[e]=new String(e)}const t=W[e];if(void 0===t)return;if(_){const e=_.get(t);if(void 0!==e)return e}const n=z[e];if(void 0===n)return;const o={};for(let e=0;e=128&&(r=n[r],void 0===r))return;o[t]=r}return o},F.MACSTRING=function(e,t){const n=A.MACSTRING(e,t);return void 0!==n?n.length:0},A.VARDELTAS=function(e){let t=0;const n=[];for(;t=-128&&o<=127?V(e,t,n):j(e,t,n)}return n},A.INDEX=function(e){let t=1;const n=[t],o=[];for(let r=0;r>8,t[s+1]=255&a,t=t.concat(o[n])}return t},F.TABLE=function(e){let t=0;const n=e.fields.length;for(let o=0;o0)return new ce(this.data,this.offset+t).parseStruct(e)},ce.prototype.parseListOfLists=function(e){const t=this.parseOffset16List(),n=t.length,o=this.relativeOffset,r=new Array(n);for(let o=0;o=0;r-=1){const n=pe.getUShort(e,t+4+8*r),s=pe.getUShort(e,t+4+8*r+2);if(3===n&&(0===s||1===s||10===s)){o=pe.getULong(e,t+4+8*r+4);break}}if(-1===o)throw new Error("No valid cmap sub-tables found.");const r=new pe.Parser(e,t+o);if(n.format=r.parseUShort(),12===n.format)!function(e,t){let n;t.parseUShort(),e.length=t.parseULong(),e.language=t.parseULong(),e.groupCount=n=t.parseULong(),e.glyphIndexMap={};for(let o=0;o>1,t.skip("uShort",3),e.glyphIndexMap={};const a=new pe.Parser(n,o+r+14),i=new pe.Parser(n,o+r+16+2*s),l=new pe.Parser(n,o+r+16+4*s),c=new pe.Parser(n,o+r+16+6*s);let u=o+r+16+8*s;for(let t=0;t0?(s=e.parseByte(),0==(t&r)&&(s=-s),s=n+s):s=(t&r)>0?n:n+e.parseShort(),s}function Ee(e,t,n){const o=new pe.Parser(t,n);let r,s;if(e.numberOfContours=o.parseShort(),e._xMin=o.parseShort(),e._yMin=o.parseShort(),e._xMax=o.parseShort(),e._yMax=o.parseShort(),e.numberOfContours>0){const t=e.endPointIndices=[];for(let n=0;n0){const t=o.parseByte();for(let n=0;n0){const a=[];let i;if(n>0){for(let e=0;e=0,a.push(i);let e=0;for(let t=0;t0?(2&r)>0?(n.dx=o.parseShort(),n.dy=o.parseShort()):n.matchedPoints=[o.parseUShort(),o.parseUShort()]:(2&r)>0?(n.dx=o.parseChar(),n.dy=o.parseChar()):n.matchedPoints=[o.parseByte(),o.parseByte()],(8&r)>0?n.xScale=n.yScale=o.parseF2Dot14():(64&r)>0?(n.xScale=o.parseF2Dot14(),n.yScale=o.parseF2Dot14()):(128&r)>0&&(n.xScale=o.parseF2Dot14(),n.scale01=o.parseF2Dot14(),n.scale10=o.parseF2Dot14(),n.yScale=o.parseF2Dot14()),e.components.push(n),t=!!(32&r)}if(256&r){e.instructionLength=o.parseUShort(),e.instructions=[];for(let t=0;tt.points.length-1||o.matchedPoints[1]>r.points.length-1)throw Error("Matched points out of range in "+t.name);const n=t.points[o.matchedPoints[0]];let s=r.points[o.matchedPoints[1]];const a={xScale:o.xScale,scale01:o.scale01,scale10:o.scale10,yScale:o.yScale,dx:0,dy:0};s=Oe([s],a)[0],a.dx=n.x-s.x,a.dy=n.y-s.y,e=Oe(r.points,a)}t.points=t.points.concat(e)}}return we(t.points)}var Re={getPath:we,parse:function(e,t,n,o){const r=new Ie.GlyphSet(o);for(let s=0;s>4,s=15&o;if(15===r)break;if(t+=n[r],15===s)break;t+=n[s]}return parseFloat(t)}(e);if(t>=32&&t<=246)return t-139;if(t>=247&&t<=250)return n=e.parseByte(),256*(t-247)+n+108;if(t>=251&&t<=254)return n=e.parseByte(),256*-(t-251)-n-108;throw new Error("Invalid b0 "+t)}function Pe(e,t,n){t=void 0!==t?t:0;const o=new pe.Parser(e,t),r=[];let s=[];for(n=void 0!==n?n:e.length;o.relativeOffset>1,l.length=0,d=!0}return function n(p){let x,U,T,E,O,w,k,R,D,C,L,I,M=0;for(;M1&&!d&&(v=l.shift()+h,d=!0),y+=l.pop(),b(m,y);break;case 5:for(;l.length>0;)m+=l.shift(),y+=l.shift(),i.lineTo(m,y);break;case 6:for(;l.length>0&&(m+=l.shift(),i.lineTo(m,y),0!==l.length);)y+=l.shift(),i.lineTo(m,y);break;case 7:for(;l.length>0&&(y+=l.shift(),i.lineTo(m,y),0!==l.length);)m+=l.shift(),i.lineTo(m,y);break;case 8:for(;l.length>0;)o=m+l.shift(),r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),m=s+l.shift(),y=a+l.shift(),i.curveTo(o,r,s,a,m,y);break;case 10:O=l.pop()+u,w=c[O],w&&n(w);break;case 11:return;case 12:switch(B=p[M],M+=1,B){case 35:o=m+l.shift(),r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),k=s+l.shift(),R=a+l.shift(),D=k+l.shift(),C=R+l.shift(),L=D+l.shift(),I=C+l.shift(),m=L+l.shift(),y=I+l.shift(),l.shift(),i.curveTo(o,r,s,a,k,R),i.curveTo(D,C,L,I,m,y);break;case 34:o=m+l.shift(),r=y,s=o+l.shift(),a=r+l.shift(),k=s+l.shift(),R=a,D=k+l.shift(),C=a,L=D+l.shift(),I=y,m=L+l.shift(),i.curveTo(o,r,s,a,k,R),i.curveTo(D,C,L,I,m,y);break;case 36:o=m+l.shift(),r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),k=s+l.shift(),R=a,D=k+l.shift(),C=a,L=D+l.shift(),I=C+l.shift(),m=L+l.shift(),i.curveTo(o,r,s,a,k,R),i.curveTo(D,C,L,I,m,y);break;case 37:o=m+l.shift(),r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),k=s+l.shift(),R=a+l.shift(),D=k+l.shift(),C=R+l.shift(),L=D+l.shift(),I=C+l.shift(),Math.abs(L-m)>Math.abs(I-y)?m=L+l.shift():y=I+l.shift(),i.curveTo(o,r,s,a,k,R),i.curveTo(D,C,L,I,m,y);break;default:console.log("Glyph "+t.index+": unknown operator 1200"+B),l.length=0}break;case 14:l.length>0&&!d&&(v=l.shift()+h,d=!0),g&&(i.closePath(),g=!1);break;case 18:S();break;case 19:case 20:S(),M+=f+7>>3;break;case 21:l.length>2&&!d&&(v=l.shift()+h,d=!0),y+=l.pop(),m+=l.pop(),b(m,y);break;case 22:l.length>1&&!d&&(v=l.shift()+h,d=!0),m+=l.pop(),b(m,y);break;case 23:S();break;case 24:for(;l.length>2;)o=m+l.shift(),r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),m=s+l.shift(),y=a+l.shift(),i.curveTo(o,r,s,a,m,y);m+=l.shift(),y+=l.shift(),i.lineTo(m,y);break;case 25:for(;l.length>6;)m+=l.shift(),y+=l.shift(),i.lineTo(m,y);o=m+l.shift(),r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),m=s+l.shift(),y=a+l.shift(),i.curveTo(o,r,s,a,m,y);break;case 26:for(l.length%2&&(m+=l.shift());l.length>0;)o=m,r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),m=s,y=a+l.shift(),i.curveTo(o,r,s,a,m,y);break;case 27:for(l.length%2&&(y+=l.shift());l.length>0;)o=m+l.shift(),r=y,s=o+l.shift(),a=r+l.shift(),m=s+l.shift(),y=a,i.curveTo(o,r,s,a,m,y);break;case 28:x=p[M],U=p[M+1],l.push((x<<24|U<<16)>>16),M+=2;break;case 29:O=l.pop()+e.gsubrsBias,w=e.gsubrs[O],w&&n(w);break;case 30:for(;l.length>0&&(o=m,r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),m=s+l.shift(),y=a+(1===l.length?l.shift():0),i.curveTo(o,r,s,a,m,y),0!==l.length);)o=m+l.shift(),r=y,s=o+l.shift(),a=r+l.shift(),y=a+l.shift(),m=s+(1===l.length?l.shift():0),i.curveTo(o,r,s,a,m,y);break;case 31:for(;l.length>0&&(o=m+l.shift(),r=y,s=o+l.shift(),a=r+l.shift(),y=a+l.shift(),m=s+(1===l.length?l.shift():0),i.curveTo(o,r,s,a,m,y),0!==l.length);)o=m,r=y+l.shift(),s=o+l.shift(),a=r+l.shift(),m=s+l.shift(),y=a+(1===l.length?l.shift():0),i.curveTo(o,r,s,a,m,y);break;default:B<32?console.log("Glyph "+t.index+": unknown operator "+B):B<247?l.push(B-139):B<251?(x=p[M],M+=1,l.push(256*(B-247)+x+108)):B<255?(x=p[M],M+=1,l.push(256*-(B-251)-x-108)):(x=p[M],U=p[M+1],T=p[M+2],E=p[M+3],M+=4,l.push((x<<24|U<<16|T<<8|E)/65536))}}}(n),t.advanceWidth=v,i}function Ve(e,t){let n,o=de.indexOf(e);return o>=0&&(n=o),o=t.indexOf(e),o>=0?n=o+de.length:(n=de.length+t.length,t.push(e)),n}function je(e,t,n){const o={};for(let r=0;r=o)throw new Error("CFF table CID Font FDSelect has bad FD index value "+s+" (FD count "+o+")");r.push(s)}else{if(3!==i)throw new Error("CFF Table CID Font FDSelect table has unsupported format "+i);{const e=a.parseCard16();let t,i=a.parseCard16();if(0!==i)throw new Error("CFF Table CID Font FDSelect format 3 range has bad initial GID "+i);for(let l=0;l=o)throw new Error("CFF table CID Font FDSelect has bad FD index value "+s+" (FD count "+o+")");if(t>n)throw new Error("CFF Table CID Font FDSelect format 3 range has bad GID "+t);for(;i=1&&(n.ulCodePageRange1=o.parseULong(),n.ulCodePageRange2=o.parseULong()),n.version>=2&&(n.sxHeight=o.parseShort(),n.sCapHeight=o.parseShort(),n.usDefaultChar=o.parseUShort(),n.usBreakChar=o.parseUShort(),n.usMaxContent=o.parseUShort()),n},make:function(e){return new oe.Table("OS/2",[{name:"version",type:"USHORT",value:3},{name:"xAvgCharWidth",type:"SHORT",value:0},{name:"usWeightClass",type:"USHORT",value:0},{name:"usWidthClass",type:"USHORT",value:0},{name:"fsType",type:"USHORT",value:0},{name:"ySubscriptXSize",type:"SHORT",value:650},{name:"ySubscriptYSize",type:"SHORT",value:699},{name:"ySubscriptXOffset",type:"SHORT",value:0},{name:"ySubscriptYOffset",type:"SHORT",value:140},{name:"ySuperscriptXSize",type:"SHORT",value:650},{name:"ySuperscriptYSize",type:"SHORT",value:699},{name:"ySuperscriptXOffset",type:"SHORT",value:0},{name:"ySuperscriptYOffset",type:"SHORT",value:479},{name:"yStrikeoutSize",type:"SHORT",value:49},{name:"yStrikeoutPosition",type:"SHORT",value:258},{name:"sFamilyClass",type:"SHORT",value:0},{name:"bFamilyType",type:"BYTE",value:0},{name:"bSerifStyle",type:"BYTE",value:0},{name:"bWeight",type:"BYTE",value:0},{name:"bProportion",type:"BYTE",value:0},{name:"bContrast",type:"BYTE",value:0},{name:"bStrokeVariation",type:"BYTE",value:0},{name:"bArmStyle",type:"BYTE",value:0},{name:"bLetterform",type:"BYTE",value:0},{name:"bMidline",type:"BYTE",value:0},{name:"bXHeight",type:"BYTE",value:0},{name:"ulUnicodeRange1",type:"ULONG",value:0},{name:"ulUnicodeRange2",type:"ULONG",value:0},{name:"ulUnicodeRange3",type:"ULONG",value:0},{name:"ulUnicodeRange4",type:"ULONG",value:0},{name:"achVendID",type:"CHARARRAY",value:"XXXX"},{name:"fsSelection",type:"USHORT",value:0},{name:"usFirstCharIndex",type:"USHORT",value:0},{name:"usLastCharIndex",type:"USHORT",value:0},{name:"sTypoAscender",type:"SHORT",value:0},{name:"sTypoDescender",type:"SHORT",value:0},{name:"sTypoLineGap",type:"SHORT",value:0},{name:"usWinAscent",type:"USHORT",value:0},{name:"usWinDescent",type:"USHORT",value:0},{name:"ulCodePageRange1",type:"ULONG",value:0},{name:"ulCodePageRange2",type:"ULONG",value:0},{name:"sxHeight",type:"SHORT",value:0},{name:"sCapHeight",type:"SHORT",value:0},{name:"usDefaultChar",type:"USHORT",value:0},{name:"usBreakChar",type:"USHORT",value:0},{name:"usMaxContext",type:"USHORT",value:0}],e)},unicodeRanges:gt,getUnicodeRange:function(e){for(let t=0;t=n.begin&&e=ye.length){const e=o.parseChar();n.names.push(o.parseString(e))}break;case 2.5:n.numberOfGlyphs=o.parseUShort(),n.offset=new Array(n.numberOfGlyphs);for(let e=0;et.value.tag?1:-1})),t.fields=t.fields.concat(o),t.fields=t.fields.concat(r),t}function kt(e,t,n){for(let n=0;n0){return e.glyphs.get(o).getMetrics()}}return n}function Rt(e){let t=0;for(let n=0;nm||void 0===l)&&m>0&&(l=m),c 123 are reserved for internal usage");f|=1<0?tt.make(w):void 0,D=yt.make(),C=$e.make(e.glyphs,{version:e.getEnglishName("version"),fullName:T,familyName:x,weightName:U,postScriptName:E,unitsPerEm:e.unitsPerEm,fontBBox:[0,d.yMin,d.ascender,d.advanceWidthMax]}),L=e.metas&&Object.keys(e.metas).length>0?Ut.make(e.metas):void 0,I=[g,m,y,v,k,S,D,C,b];R&&I.push(R),e.tables.gsub&&I.push(xt.make(e.tables.gsub)),L&&I.push(L);const M=wt(I),B=Et(M.encode()),G=M.fields;let N=!1;for(let e=0;e>>1,s=e[r].tag;if(s===t)return r;s>>1,s=e[r];if(s===t)return r;s=0)return o[r].script;if(t){const t={tag:e,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return o.splice(-1-r,0,t),t.script}}},getLangSysTable:function(e,t,n){const o=this.getScriptTable(e,n);if(o){if(!t||"dflt"===t||"DFLT"===t)return o.defaultLangSys;const e=Ct(o.langSysRecords,t);if(e>=0)return o.langSysRecords[e].langSys;if(n){const n={tag:t,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return o.langSysRecords.splice(-1-e,0,n),n.langSys}}},getFeatureTable:function(e,t,n,o){const r=this.getLangSysTable(e,t,o);if(r){let e;const t=r.featureIndexes,s=this.font.tables[this.tableName].features;for(let o=0;o=s[o-1].tag,"Features must be added in alphabetical order."),e={tag:n,feature:{params:0,lookupListIndexes:[]}},s.push(e),t.push(o),e.feature}}},getLookupTables:function(e,t,n,o,r){const s=this.getFeatureTable(e,t,n,r),a=[];if(s){let e;const t=s.lookupListIndexes,n=this.font.tables[this.tableName].lookups;for(let r=0;r=0){const e=s.ligatureSets[c];for(let t=0;t0&&e<0?n:o<0&&e>0?-n:e*o},Zt={x:1,y:0,axis:"x",distance:function(e,t,n,o){return(n?e.xo:e.x)-(o?t.xo:t.x)},interpolate:function(e,t,n,o){let r,s,a,i,l,c,u;if(!o||o===this)return r=e.xo-t.xo,s=e.xo-n.xo,l=t.x-t.xo,c=n.x-n.xo,a=Math.abs(r),i=Math.abs(s),u=a+i,0===u?void(e.x=e.xo+(l+c)/2):void(e.x=e.xo+(l*i+c*a)/u);r=o.distance(e,t,!0,!0),s=o.distance(e,n,!0,!0),l=o.distance(t,t,!1,!0),c=o.distance(n,n,!1,!0),a=Math.abs(r),i=Math.abs(s),u=a+i,0!==u?Zt.setRelative(e,e,(l*i+c*a)/u,o,!0):Zt.setRelative(e,e,(l+c)/2,o,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(e,t,n,o,r){if(!o||o===this)return void(e.x=(r?t.xo:t.x)+n);const s=r?t.xo:t.x,a=r?t.yo:t.y,i=s+n*o.x,l=a+n*o.y;e.x=i+(e.y-l)/o.normalSlope},slope:0,touch:function(e){e.xTouched=!0},touched:function(e){return e.xTouched},untouch:function(e){e.xTouched=!1}},Qt={x:0,y:1,axis:"y",distance:function(e,t,n,o){return(n?e.yo:e.y)-(o?t.yo:t.y)},interpolate:function(e,t,n,o){let r,s,a,i,l,c,u;if(!o||o===this)return r=e.yo-t.yo,s=e.yo-n.yo,l=t.y-t.yo,c=n.y-n.yo,a=Math.abs(r),i=Math.abs(s),u=a+i,0===u?void(e.y=e.yo+(l+c)/2):void(e.y=e.yo+(l*i+c*a)/u);r=o.distance(e,t,!0,!0),s=o.distance(e,n,!0,!0),l=o.distance(t,t,!1,!0),c=o.distance(n,n,!1,!0),a=Math.abs(r),i=Math.abs(s),u=a+i,0!==u?Qt.setRelative(e,e,(l*i+c*a)/u,o,!0):Qt.setRelative(e,e,(l+c)/2,o,!0)},normalSlope:0,setRelative:function(e,t,n,o,r){if(!o||o===this)return void(e.y=(r?t.yo:t.y)+n);const s=r?t.xo:t.x,a=r?t.yo:t.y,i=s+n*o.x,l=a+n*o.y;e.y=l+o.normalSlope*(e.x-i)},slope:Number.POSITIVE_INFINITY,touch:function(e){e.yTouched=!0},touched:function(e){return e.yTouched},untouch:function(e){e.yTouched=!1}};function $t(e,t){this.x=e,this.y=t,this.axis=void 0,this.slope=t/e,this.normalSlope=-e/t,Object.freeze(this)}function Kt(e,t){const n=Math.sqrt(e*e+t*t);return t/=n,1===(e/=n)&&0===t?Zt:0===e&&1===t?Qt:new $t(e,t)}function Jt(e,t,n,o){this.x=this.xo=Math.round(64*e)/64,this.y=this.yo=Math.round(64*t)/64,this.lastPointOfContour=n,this.onCurve=o,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}Object.freeze(Zt),Object.freeze(Qt),$t.prototype.distance=function(e,t,n,o){return this.x*Zt.distance(e,t,n,o)+this.y*Qt.distance(e,t,n,o)},$t.prototype.interpolate=function(e,t,n,o){let r,s,a,i,l,c,u;a=o.distance(e,t,!0,!0),i=o.distance(e,n,!0,!0),r=o.distance(t,t,!1,!0),s=o.distance(n,n,!1,!0),l=Math.abs(a),c=Math.abs(i),u=l+c,0!==u?this.setRelative(e,e,(r*c+s*l)/u,o,!0):this.setRelative(e,e,(r+s)/2,o,!0)},$t.prototype.setRelative=function(e,t,n,o,r){o=o||this;const s=r?t.xo:t.x,a=r?t.yo:t.y,i=s+n*o.x,l=a+n*o.y,c=o.normalSlope,u=this.slope,p=e.x,h=e.y;e.x=(u*p-c*i+l-h)/(u-c),e.y=u*(e.x-p)+h},$t.prototype.touch=function(e){e.xTouched=!0,e.yTouched=!0},Jt.prototype.nextTouched=function(e){let t=this.nextPointOnContour;for(;!e.touched(t)&&t!==this;)t=t.nextPointOnContour;return t},Jt.prototype.prevTouched=function(e){let t=this.prevPointOnContour;for(;!e.touched(t)&&t!==this;)t=t.prevPointOnContour;return t};const en=Object.freeze(new Jt(0,0)),tn={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function nn(e,t){switch(this.env=e,this.stack=[],this.prog=t,e){case"glyf":this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case"prep":this.fv=this.pv=this.dpv=Zt,this.round=Wt}}function on(e){const t=e.tZone=new Array(e.gZone.length);for(let e=0;e=176&&o<=183)r+=o-176+1;else if(o>=184&&o<=191)r+=2*(o-184+1);else if(t&&1===s&&27===o)break}while(s>0);e.ip=r}function sn(e,t){exports.DEBUG&&console.log(t.step,"SVTCA["+e.axis+"]"),t.fv=t.pv=t.dpv=e}function an(e,t){exports.DEBUG&&console.log(t.step,"SPVTCA["+e.axis+"]"),t.pv=t.dpv=e}function ln(e,t){exports.DEBUG&&console.log(t.step,"SFVTCA["+e.axis+"]"),t.fv=e}function cn(e,t){const n=t.stack,o=n.pop(),r=n.pop(),s=t.z2[o],a=t.z1[r];let i,l;exports.DEBUG&&console.log("SPVTL["+e+"]",o,r),e?(i=s.y-a.y,l=a.x-s.x):(i=a.x-s.x,l=a.y-s.y),t.pv=t.dpv=Kt(i,l)}function un(e,t){const n=t.stack,o=n.pop(),r=n.pop(),s=t.z2[o],a=t.z1[r];let i,l;exports.DEBUG&&console.log("SFVTL["+e+"]",o,r),e?(i=s.y-a.y,l=a.x-s.x):(i=a.x-s.x,l=a.y-s.y),t.fv=Kt(i,l)}function pn(e){exports.DEBUG&&console.log(e.step,"POP[]"),e.stack.pop()}function hn(e,t){const n=t.stack.pop(),o=t.z0[n],r=t.fv,s=t.pv;exports.DEBUG&&console.log(t.step,"MDAP["+e+"]",n);let a=s.distance(o,en);e&&(a=t.round(a)),r.setRelative(o,en,a,s),r.touch(o),t.rp0=t.rp1=n}function fn(e,t){const n=t.z2,o=n.length-2;let r,s,a;exports.DEBUG&&console.log(t.step,"IUP["+e.axis+"]");for(let t=0;t1?"loop "+(t.loop-i)+": ":"")+"SHP["+(e?"rp1":"rp2")+"]",o)}t.loop=1}function gn(e,t){const n=t.stack,o=e?t.rp1:t.rp2,r=(e?t.z0:t.z1)[o],s=t.fv,a=t.pv,i=n.pop(),l=t.z2[t.contours[i]];let c=l;exports.DEBUG&&console.log(t.step,"SHC["+e+"]",i);const u=a.distance(r,r,!1,!0);do{c!==r&&s.setRelative(c,c,u,a),c=c.nextPointOnContour}while(c!==l)}function mn(e,t){const n=t.stack,o=e?t.rp1:t.rp2,r=(e?t.z0:t.z1)[o],s=t.fv,a=t.pv,i=n.pop();let l,c;switch(exports.DEBUG&&console.log(t.step,"SHZ["+e+"]",i),i){case 0:l=t.tZone;break;case 1:l=t.gZone;break;default:throw new Error("Invalid zone")}const u=a.distance(r,r,!1,!0),p=l.length-2;for(let e=0;e",i),t.stack.push(Math.round(64*i))}function xn(e,t){const n=t.stack,o=n.pop(),r=t.fv,s=t.pv,a=t.ppem,i=t.deltaBase+16*(e-1),l=t.deltaShift,c=t.z0;exports.DEBUG&&console.log(t.step,"DELTAP["+e+"]",o,n);for(let e=0;e>4)!==a)continue;let u=(15&o)-8;u>=0&&u++,exports.DEBUG&&console.log(t.step,"DELTAPFIX",e,"by",u*l);const p=c[e];r.setRelative(p,p,u*l,s)}}function Un(e,t){const n=t.stack,o=n.pop();exports.DEBUG&&console.log(t.step,"ROUND[]"),n.push(64*t.round(o/64))}function Tn(e,t){const n=t.stack,o=n.pop(),r=t.ppem,s=t.deltaBase+16*(e-1),a=t.deltaShift;exports.DEBUG&&console.log(t.step,"DELTAC["+e+"]",o,n);for(let e=0;e>4)!==r)continue;let i=(15&o)-8;i>=0&&i++;const l=i*a;exports.DEBUG&&console.log(t.step,"DELTACFIX",e,"by",l),t.cvt[e]+=l}}function En(e,t){const n=t.stack,o=n.pop(),r=n.pop(),s=t.z2[o],a=t.z1[r];let i,l;exports.DEBUG&&console.log("SDPVTL["+e+"]",o,r),e?(i=s.y-a.y,l=a.x-s.x):(i=a.x-s.x,l=a.y-s.y),t.dpv=Kt(i,l)}function On(e,t){const n=t.stack,o=t.prog;let r=t.ip;exports.DEBUG&&console.log(t.step,"PUSHB["+e+"]");for(let t=0;t=0?1:-1,m=Math.abs(m),e&&(v=s.cvt[i],o&&Math.abs(m-v)":"_")+(o?"R":"_")+(0===r?"Gr":1===r?"Bl":2===r?"Wh":"")+"]",e?i+"("+s.cvt[i]+","+v+")":"",l,"(d =",g,"->",y*m,")"),s.rp1=s.rp0,s.rp2=l,t&&(s.rp0=l)}function Rn(e){(e=e||{}).empty||(Nt(e.familyName,"When creating a new Font object, familyName is required."),Nt(e.styleName,"When creating a new Font object, styleName is required."),Nt(e.unitsPerEm,"When creating a new Font object, unitsPerEm is required."),Nt(e.ascender,"When creating a new Font object, ascender is required."),Nt(e.descender,"When creating a new Font object, descender is required."),Nt(e.descender<0,"Descender should be negative (e.g. -512)."),this.names={fontFamily:{en:e.familyName||" "},fontSubfamily:{en:e.styleName||" "},fullName:{en:e.fullName||e.familyName+" "+e.styleName},postScriptName:{en:e.postScriptName||e.familyName+e.styleName},designer:{en:e.designer||" "},designerURL:{en:e.designerURL||" "},manufacturer:{en:e.manufacturer||" "},manufacturerURL:{en:e.manufacturerURL||" "},license:{en:e.license||" "},licenseURL:{en:e.licenseURL||" "},version:{en:e.version||"Version 0.1"},description:{en:e.description||" "},copyright:{en:e.copyright||" "},trademark:{en:e.trademark||" "}},this.unitsPerEm=e.unitsPerEm||1e3,this.ascender=e.ascender,this.descender=e.descender,this.createdTimestamp=e.createdTimestamp,this.tables={os2:{usWeightClass:e.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:e.widthClass||this.usWidthClasses.MEDIUM,fsSelection:e.fsSelection||this.fsSelectionValues.REGULAR}}),this.supported=!0,this.glyphs=new Ie.GlyphSet(this,e.glyphs||[]),this.encoding=new ve(this),this.substitution=new It(this),this.tables=this.tables||{},Object.defineProperty(this,"hinting",{get:function(){return this._hinting?this._hinting:"truetype"===this.outlinesFormat?this._hinting=new zt(this):void 0}})}function Dn(e,t){const n=JSON.stringify(e);let o=256;for(let e in t){let r=parseInt(e);if(r&&!(r<256)){if(JSON.stringify(t[e])===n)return r;o<=r&&(o=r+1)}}return t[o]=e,o}function Cn(e,t,n){const o=Dn(t.name,n);return[{name:"tag_"+e,type:"TAG",value:t.tag},{name:"minValue_"+e,type:"FIXED",value:t.minValue<<16},{name:"defaultValue_"+e,type:"FIXED",value:t.defaultValue<<16},{name:"maxValue_"+e,type:"FIXED",value:t.maxValue<<16},{name:"flags_"+e,type:"USHORT",value:0},{name:"nameID_"+e,type:"USHORT",value:o}]}function Ln(e,t,n){const o={},r=new pe.Parser(e,t);return o.tag=r.parseTag(),o.minValue=r.parseFixed(),o.defaultValue=r.parseFixed(),o.maxValue=r.parseFixed(),r.skip("uShort",1),o.name=n[r.parseUShort()]||{},o}function In(e,t,n,o){const r=[{name:"nameID_"+e,type:"USHORT",value:Dn(t.name,o)},{name:"flags_"+e,type:"USHORT",value:0}];for(let o=0;o2)return;const n=this.font;let o=this._prepState;if(!o||o.ppem!==t){let e=this._fpgmState;if(!e){nn.prototype=tn,e=this._fpgmState=new nn("fpgm",n.tables.fpgm),e.funcs=[],e.font=n,exports.DEBUG&&(console.log("---EXEC FPGM---"),e.step=-1);try{At(e)}catch(e){return console.log("Hinting error in FPGM:"+e),void(this._errorState=3)}}nn.prototype=e,o=this._prepState=new nn("prep",n.tables.prep),o.ppem=t;const r=n.tables.cvt;if(r){const e=o.cvt=new Array(r.length),s=t/n.unitsPerEm;for(let t=0;t1))try{return Ft(e,o)}catch(e){return this._errorState<1&&(console.log("Hinting error:"+e),console.log("Note: further hinting errors are silenced")),void(this._errorState=1)}},Ft=function(e,t){const n=t.ppem/t.font.unitsPerEm,o=n;let r,s,a,i=e.components;if(nn.prototype=t,i){const l=t.font;s=[],r=[];for(let e=0;e1?"loop "+(e.loop-n)+": ":"")+"SHPIX[]",a,r),o.setRelative(i,i,r),o.touch(i)}e.loop=1},function(e){const t=e.stack,n=e.rp1,o=e.rp2;let r=e.loop;const s=e.z0[n],a=e.z1[o],i=e.fv,l=e.dpv,c=e.z2;for(;r--;){const u=t.pop(),p=c[u];exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-r)+": ":"")+"IP[]",u,n,"<->",o),i.interpolate(p,s,a,l),i.touch(p)}e.loop=1},yn.bind(void 0,0),yn.bind(void 0,1),function(e){const t=e.stack,n=e.rp0,o=e.z0[n];let r=e.loop;const s=e.fv,a=e.pv,i=e.z1;for(;r--;){const n=t.pop(),l=i[n];exports.DEBUG&&console.log(e.step,(e.loop>1?"loop "+(e.loop-r)+": ":"")+"ALIGNRP[]",n),s.setRelative(l,o,0,a),s.touch(l)}e.loop=1},function(e){exports.DEBUG&&console.log(e.step,"RTDG[]"),e.round=qt},vn.bind(void 0,0),vn.bind(void 0,1),function(e){const t=e.prog;let n=e.ip;const o=e.stack,r=t[++n];exports.DEBUG&&console.log(e.step,"NPUSHB[]",r);for(let e=0;en?1:0)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"GTEQ[]",n,o),t.push(o>=n?1:0)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"EQ[]",n,o),t.push(n===o?1:0)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"NEQ[]",n,o),t.push(n!==o?1:0)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"ODD[]",n),t.push(Math.trunc(n)%2?1:0)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"EVEN[]",n),t.push(Math.trunc(n)%2?0:1)},function(e){let t=e.stack.pop();exports.DEBUG&&console.log(e.step,"IF[]",t),t||(rn(e,!0),exports.DEBUG&&console.log(e.step,"EIF[]"))},function(e){exports.DEBUG&&console.log(e.step,"EIF[]")},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"AND[]",n,o),t.push(n&&o?1:0)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"OR[]",n,o),t.push(n||o?1:0)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"NOT[]",n),t.push(n?0:1)},xn.bind(void 0,1),function(e){const t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SDB[]",t),e.deltaBase=t},function(e){const t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SDS[]",t),e.deltaShift=Math.pow(.5,t)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"ADD[]",n,o),t.push(o+n)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"SUB[]",n,o),t.push(o-n)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"DIV[]",n,o),t.push(64*o/n)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"MUL[]",n,o),t.push(o*n/64)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"ABS[]",n),t.push(Math.abs(n))},function(e){const t=e.stack;let n=t.pop();exports.DEBUG&&console.log(e.step,"NEG[]",n),t.push(-n)},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"FLOOR[]",n),t.push(64*Math.floor(n/64))},function(e){const t=e.stack,n=t.pop();exports.DEBUG&&console.log(e.step,"CEILING[]",n),t.push(64*Math.ceil(n/64))},Un.bind(void 0,0),Un.bind(void 0,1),Un.bind(void 0,2),Un.bind(void 0,3),void 0,void 0,void 0,void 0,function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"WCVTF[]",n,o),e.cvt[o]=n*e.ppem/e.font.unitsPerEm},xn.bind(void 0,2),xn.bind(void 0,3),Tn.bind(void 0,1),Tn.bind(void 0,2),Tn.bind(void 0,3),function(e){let t,n=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"SROUND[]",n),e.round=Yt,192&n){case 0:t=.5;break;case 64:t=1;break;case 128:t=2;break;default:throw new Error("invalid SROUND value")}switch(e.srPeriod=t,48&n){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*t;break;case 32:e.srPhase=.5*t;break;case 48:e.srPhase=.75*t;break;default:throw new Error("invalid SROUND value")}n&=15,e.srThreshold=0===n?0:(n/8-.5)*t},function(e){let t,n=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"S45ROUND[]",n),e.round=Yt,192&n){case 0:t=Math.sqrt(2)/2;break;case 64:t=Math.sqrt(2);break;case 128:t=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(e.srPeriod=t,48&n){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*t;break;case 32:e.srPhase=.5*t;break;case 48:e.srPhase=.75*t;break;default:throw new Error("invalid S45ROUND value")}n&=15,e.srThreshold=0===n?0:(n/8-.5)*t},void 0,void 0,function(e){exports.DEBUG&&console.log(e.step,"ROFF[]"),e.round=_t},void 0,function(e){exports.DEBUG&&console.log(e.step,"RUTG[]"),e.round=Vt},function(e){exports.DEBUG&&console.log(e.step,"RDTG[]"),e.round=jt},pn,pn,void 0,void 0,void 0,void 0,void 0,function(e){const t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SCANCTRL[]",t)},En.bind(void 0,0),En.bind(void 0,1),function(e){const t=e.stack,n=t.pop();let o=0;exports.DEBUG&&console.log(e.step,"GETINFO[]",n),1&n&&(o=35),32&n&&(o|=4096),t.push(o)},void 0,function(e){const t=e.stack,n=t.pop(),o=t.pop(),r=t.pop();exports.DEBUG&&console.log(e.step,"ROLL[]"),t.push(o),t.push(n),t.push(r)},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"MAX[]",n,o),t.push(Math.max(o,n))},function(e){const t=e.stack,n=t.pop(),o=t.pop();exports.DEBUG&&console.log(e.step,"MIN[]",n,o),t.push(Math.min(o,n))},function(e){const t=e.stack.pop();exports.DEBUG&&console.log(e.step,"SCANTYPE[]",t)},function(e){const t=e.stack.pop();let n=e.stack.pop();switch(exports.DEBUG&&console.log(e.step,"INSTCTRL[]",t,n),t){case 1:return void(e.inhibitGridFit=!!n);case 2:return void(e.ignoreCvt=!!n);default:throw new Error("invalid INSTCTRL[] selector")}},void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,On.bind(void 0,1),On.bind(void 0,2),On.bind(void 0,3),On.bind(void 0,4),On.bind(void 0,5),On.bind(void 0,6),On.bind(void 0,7),On.bind(void 0,8),wn.bind(void 0,1),wn.bind(void 0,2),wn.bind(void 0,3),wn.bind(void 0,4),wn.bind(void 0,5),wn.bind(void 0,6),wn.bind(void 0,7),wn.bind(void 0,8),kn.bind(void 0,0,0,0,0,0),kn.bind(void 0,0,0,0,0,1),kn.bind(void 0,0,0,0,0,2),kn.bind(void 0,0,0,0,0,3),kn.bind(void 0,0,0,0,1,0),kn.bind(void 0,0,0,0,1,1),kn.bind(void 0,0,0,0,1,2),kn.bind(void 0,0,0,0,1,3),kn.bind(void 0,0,0,1,0,0),kn.bind(void 0,0,0,1,0,1),kn.bind(void 0,0,0,1,0,2),kn.bind(void 0,0,0,1,0,3),kn.bind(void 0,0,0,1,1,0),kn.bind(void 0,0,0,1,1,1),kn.bind(void 0,0,0,1,1,2),kn.bind(void 0,0,0,1,1,3),kn.bind(void 0,0,1,0,0,0),kn.bind(void 0,0,1,0,0,1),kn.bind(void 0,0,1,0,0,2),kn.bind(void 0,0,1,0,0,3),kn.bind(void 0,0,1,0,1,0),kn.bind(void 0,0,1,0,1,1),kn.bind(void 0,0,1,0,1,2),kn.bind(void 0,0,1,0,1,3),kn.bind(void 0,0,1,1,0,0),kn.bind(void 0,0,1,1,0,1),kn.bind(void 0,0,1,1,0,2),kn.bind(void 0,0,1,1,0,3),kn.bind(void 0,0,1,1,1,0),kn.bind(void 0,0,1,1,1,1),kn.bind(void 0,0,1,1,1,2),kn.bind(void 0,0,1,1,1,3),kn.bind(void 0,1,0,0,0,0),kn.bind(void 0,1,0,0,0,1),kn.bind(void 0,1,0,0,0,2),kn.bind(void 0,1,0,0,0,3),kn.bind(void 0,1,0,0,1,0),kn.bind(void 0,1,0,0,1,1),kn.bind(void 0,1,0,0,1,2),kn.bind(void 0,1,0,0,1,3),kn.bind(void 0,1,0,1,0,0),kn.bind(void 0,1,0,1,0,1),kn.bind(void 0,1,0,1,0,2),kn.bind(void 0,1,0,1,0,3),kn.bind(void 0,1,0,1,1,0),kn.bind(void 0,1,0,1,1,1),kn.bind(void 0,1,0,1,1,2),kn.bind(void 0,1,0,1,1,3),kn.bind(void 0,1,1,0,0,0),kn.bind(void 0,1,1,0,0,1),kn.bind(void 0,1,1,0,0,2),kn.bind(void 0,1,1,0,0,3),kn.bind(void 0,1,1,0,1,0),kn.bind(void 0,1,1,0,1,1),kn.bind(void 0,1,1,0,1,2),kn.bind(void 0,1,1,0,1,3),kn.bind(void 0,1,1,1,0,0),kn.bind(void 0,1,1,1,0,1),kn.bind(void 0,1,1,1,0,2),kn.bind(void 0,1,1,1,0,3),kn.bind(void 0,1,1,1,1,0),kn.bind(void 0,1,1,1,1,1),kn.bind(void 0,1,1,1,1,2),kn.bind(void 0,1,1,1,1,3)],Rn.prototype.hasChar=function(e){return null!==this.encoding.charToGlyphIndex(e)},Rn.prototype.charToGlyphIndex=function(e){return this.encoding.charToGlyphIndex(e)},Rn.prototype.charToGlyph=function(e){const t=this.charToGlyphIndex(e);let n=this.glyphs.get(t);return n||(n=this.glyphs.get(0)),n},Rn.prototype.stringToGlyphs=function(e,t){t=t||this.defaultRenderOptions;const n=[];for(let t=0;t>1;e1&&console.warn("Only the first kern subtable is supported."),e.skip("uLong");const n=255&e.parseUShort();if(e.skip("uShort"),0===n){const n=e.parseUShort();e.skip("uShort",3);for(let o=0;o{const t=jn.loadSync(e);Qn.font=t,Qn.ascender=t.ascender,Qn.descender=t.descender}};const Kn=$n.options,Jn=function(e,t){return Math.round(e+Math.random()*(t-e))};const eo=function(e,t){return{text:(e+t).toString(),equation:e+"+"+t}},to=function(e,t){return{text:(e-t).toString(),equation:e+"-"+t}};function no(e,t,n){return 6*(n=(n+1)%1)<1?e+(t-e)*n*6:2*n<1?t:3*n<2?e+(t-e)*(2/3-n)*6:e}var oo={int:Jn,greyColor:function(e,t){const n=Jn(e=e||1,t=t||9).toString(16);return`#${n}${n}${n}`},captchaText:function(e){"number"==typeof e&&(e={size:e});const t=(e=e||{}).size||4,n=e.ignoreChars||"";let o=-1,r="",s=e.charPreset||Kn.charPreset;n&&(s=function(e,t){return e.split("").filter(e=>-1===t.indexOf(e))}(s,n));const a=s.length-1;for(;++o>16,o=t>>8&255,r=255&t,s=Math.max(n,o,r),a=Math.min(n,o,r);return(s+a)/510}(e):1;let r,s;o>=.5?(r=Math.round(100*o)-45,s=Math.round(100*o)-25):(r=Math.round(100*o)+25,s=Math.round(100*o)+45);const a=Jn(r,s)/100,i=a<.5?a*(a+n):a+n-a*n,l=2*a-i,c=Math.floor(255*no(l,i,t+1/3)),u=Math.floor(255*no(l,i,t));return"#"+(Math.floor(255*no(l,i,t-1/3))|u<<8|c<<16|1<<24).toString(16).slice(1)}};const ro=$n.options,so=function(e,t){e=e||oo.captchaText();const n=(t=Object.assign({},ro,t)).width,o=t.height,r=t.background||t.backgroundColor;r&&(t.color=!0);const s=r?``:"",a=[].concat(function(e,t,n){const o=n.color,r=[],s=n.inverse?7:1,a=n.inverse?15:9;let i=-1;for(;++i`)}return r}(n,o,t)).concat(function(e,t,n,o,r){const s=e.length,a=(t-2)/(s+1),i=o.inverse?10:0,l=o.inverse?14:4;let u=-1;const p=[],h=r||o.color?oo.color(o.background):oo.greyColor(i,l);for(;++u`)}return p}(e,n,o,t)).sort(()=>Math.random()-.5).join("");return`${``}${s}${a}`};var ao=so,io=oo.captchaText,lo=function(e){const t=e.text||oo.captchaText(e);return{text:t,data:so(t,e)}},co=function(e){const t=oo.mathExpr(e.mathMin,e.mathMax,e.mathOperator);return{text:t.text,data:so(t.equation,e)}},uo=ro,po=$n.loadFont;ao.randomText=io,ao.create=lo,ao.createMathExpr=co,ao.options=uo,ao.loadFont=po;var ho=ao;const fo=Object.prototype.toString;function go(e){return"[object Object]"===fo.call(e)}function mo(){"development"===process.env.NODE_ENV&&console.log(...arguments)}const yo=async function(){};function vo(e){return yo.constructor===e.constructor?async function(){const t=await e.apply(this,arguments);return go(t)&&(t.msg&&(t.message=t.msg,t.errMsg=t.msg),0===t.code?t.errCode=t.code:t.errCode=s[t.code]||t.code),t}:function(){const t=e.apply(this,arguments);return go(t)&&(t.msg&&(t.message=t.msg,t.errMsg=t.msg),0===t.code?t.errCode=t.code:t.errCode=s[t.code]||t.code),t}}const bo=uniCloud.database(),So=bo.collection("opendb-verify-codes");class xo{async setVerifyCode({clientIP:e,deviceId:t,code:n,expiresDate:o,scene:r}){if(!t)return{code:10101,msg:"deviceId不可为空"};if(!n)return{code:10102,msg:"验证码不可为空"};o||(o=180);const s=Date.now(),a={device_uuid:t,scene:r,code:n.toLocaleLowerCase(),state:0,ip:e,created_date:s,expired_date:s+1e3*o};return mo("addRes",await So.add(a)),{code:0,deviceId:t}}async verifyCode({deviceId:e,code:t,scene:n}){if(!e)return{code:10101,msg:"deviceId不可为空"};if(!t)return{code:10102,msg:"验证码不可为空"};const o=Date.now(),r={device_uuid:e,scene:n,code:t.toLocaleLowerCase(),state:0},s=await So.where(r).orderBy("created_date","desc").limit(1).get();if(mo("verifyRecord:",s),s&&s.data&&s.data.length>0){const e=s.data[0];if(e.expired_date{e.scene&&delete e.scene,this.pluginConfig.scene[n]=Object.assign({},t,e[n])})}}}{constructor(){super(),this.DEVICEID2opts={}}mergeConfig(e){const t=go(this.pluginConfig.scene)?this.pluginConfig.scene[e.scene]:e.scene;return Object.assign({},go(t)?t:this.pluginConfig,e)}async create(e={}){if(!e.scene)throw new Error("scene验证码场景不可为空");e=this.mergeConfig(e);let{scene:t,expiresDate:n,deviceId:o,clientIP:r,...s}=e;if(o=o||__ctx__.DEVICEID,r=r||__ctx__.CLIENTIP,!o)throw new Error("deviceId不可为空");const a=new xo;try{const{text:i,base64:l}=function(e={}){const{uniPlatform:t=""}=e;let n;n=e.mathExpr?ho.createMathExpr(e):ho.create(e);let o="data:image/svg+xml;utf8,"+n.data.replace(/#/g,"%23");return(!t||["mp-toutiao","h5","web"].indexOf(t)>-1)&&(o=o.replace(/"/g,"'").replace(//g,"%3E")),{text:n.text,base64:o}}(s),c=await a.setVerifyCode({clientIP:r,deviceId:o,code:i,expiresDate:n,scene:t});return c.code>0?{...c,code:10001}:(this.DEVICEID2opts[o]=e,{code:0,msg:"验证码获取成功",captchaBase64:l})}catch(e){return{code:10001,msg:"验证码生成失败:"+e.message}}}async verify({deviceId:e,captcha:t,scene:n}){if(!(e=e||__ctx__.DEVICEID))throw new Error("deviceId不可为空");if(!n)throw new Error("scene验证码场景不可为空");const o=new xo;try{const r=await o.verifyCode({deviceId:e,code:t,scene:n});return r.code>0?r:{code:0,msg:"验证码通过"}}catch(e){return{code:10002,msg:"验证码校验失败:"+e.message}}}async refresh(e={}){let{scene:t,expiresDate:n,deviceId:o,...r}=e;if(o=o||__ctx__.DEVICEID,!o)throw new Error("deviceId不可为空");if(!t)throw new Error("scene验证码场景不可为空");const s=await So.where(bo.command.or([{device_uuid:o,scene:t},{deviceId:o,scene:t}])).orderBy("created_date","desc").limit(1).get();if(s&&s.data&&s.data.length>0){const e=s.data[0];await So.doc(e._id).update({state:2}),Object.keys(r).length>0&&(this.DEVICEID2opts[o]=Object.assign({},this.DEVICEID2opts[o],r));let a={};try{a=await this.create(Object.assign({},this.DEVICEID2opts[o],{deviceId:o,scene:t,expiresDate:n}))}catch(e){return{code:50403,msg:e.message}}return a.code>0?{...a,code:50403}:{code:0,msg:"验证码刷新成功",captchaBase64:a.captchaBase64}}return{code:10003,msg:`验证码刷新失败:无此设备在 ${t} 场景信息,请重新获取`}}}const Eo=new xo;Object.keys(Eo).forEach(e=>{To.prototype[e]=vo(Eo[e])});const Oo=new To,wo=new Proxy(Oo,{get(e,t){if(t in e)return"function"==typeof e[t]?vo(e[t]).bind(wo):e[t]}});module.exports=wo; diff --git a/uni_modules/uni-data-picker/changelog.md b/uni_modules/uni-data-picker/changelog.md index 8451fb3..1fb27cd 100644 --- a/uni_modules/uni-data-picker/changelog.md +++ b/uni_modules/uni-data-picker/changelog.md @@ -1,66 +1,68 @@ -## 1.0.8(2022-09-16) -- 可以使用 uni-scss 控制主题色 -## 1.0.7(2022-07-06) -- 优化 pc端图标位置不正确的问题 -## 1.0.6(2022-07-05) -- 优化 显示样式 -## 1.0.5(2022-07-04) -- 修复 uni-data-picker 在 uni-forms-item 中宽度不正确的bug -## 1.0.4(2022-04-19) -- 修复 字节小程序 本地数据无法选择下一级的Bug -## 1.0.3(2022-02-25) -- 修复 nvue 不支持的 v-show 的 bug -## 1.0.2(2022-02-25) -- 修复 条件编译 nvue 不支持的 css 样式 -## 1.0.1(2021-11-23) -- 修复 由上个版本引发的map、v-model等属性不生效的bug -## 1.0.0(2021-11-19) -- 优化 组件 UI,并提供设计资源,详见:[https://uniapp.dcloud.io/component/uniui/resource](https://uniapp.dcloud.io/component/uniui/resource) -- 文档迁移,详见:[https://uniapp.dcloud.io/component/uniui/uni-data-picker](https://uniapp.dcloud.io/component/uniui/uni-data-picker) -## 0.4.9(2021-10-28) -- 修复 VUE2 v-model 概率无效的 bug -## 0.4.8(2021-10-27) -- 修复 v-model 概率无效的 bug -## 0.4.7(2021-10-25) -- 新增 属性 spaceInfo 服务空间配置 HBuilderX 3.2.11+ -- 修复 树型 uniCloud 数据类型为 int 时报错的 bug -## 0.4.6(2021-10-19) -- 修复 非 VUE3 v-model 为 0 时无法选中的 bug -## 0.4.5(2021-09-26) -- 新增 清除已选项的功能(通过 clearIcon 属性配置是否显示按钮),同时提供 clear 方法以供调用,二者等效 -- 修复 readonly 为 true 时报错的 bug -## 0.4.4(2021-09-26) -- 修复 上一版本造成的 map 属性失效的 bug -- 新增 ellipsis 属性,支持配置 tab 选项长度过长时是否自动省略 -## 0.4.3(2021-09-24) -- 修复 某些情况下级联未触发的 bug -## 0.4.2(2021-09-23) -- 新增 提供 show 和 hide 方法,开发者可以通过 ref 调用 -- 新增 选项内容过长自动添加省略号 -## 0.4.1(2021-09-15) -- 新增 map 属性 字段映射,将 text/value 映射到数据中的其他字段 -## 0.4.0(2021-07-13) -- 组件兼容 vue3,如何创建 vue3 项目,详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834) -## 0.3.5(2021-06-04) -- 修复 无法加载云端数据的问题 -## 0.3.4(2021-05-28) -- 修复 v-model 无效问题 -- 修复 loaddata 为空数据组时加载时间过长问题 -- 修复 上个版本引出的本地数据无法选择带有 children 的 2 级节点 -## 0.3.3(2021-05-12) -- 新增 组件示例地址 -## 0.3.2(2021-04-22) -- 修复 非树形数据有 where 属性查询报错的问题 -## 0.3.1(2021-04-15) -- 修复 本地数据概率无法回显时问题 -## 0.3.0(2021-04-07) -- 新增 支持云端非树形表结构数据 -- 修复 根节点 parent_field 字段等于 null 时选择界面错乱问题 -## 0.2.0(2021-03-15) -- 修复 nodeclick、popupopened、popupclosed 事件无法触发的问题 -## 0.1.9(2021-03-09) -- 修复 微信小程序某些情况下无法选择的问题 -## 0.1.8(2021-02-05) -- 优化 部分样式在 nvue 上的兼容表现 -## 0.1.7(2021-02-05) -- 调整为 uni_modules 目录规范 +## 1.0.9(2022-11-30) +- 修复 v-for 为使用 key 值控制台 warning +## 1.0.8(2022-09-16) +- 可以使用 uni-scss 控制主题色 +## 1.0.7(2022-07-06) +- 优化 pc端图标位置不正确的问题 +## 1.0.6(2022-07-05) +- 优化 显示样式 +## 1.0.5(2022-07-04) +- 修复 uni-data-picker 在 uni-forms-item 中宽度不正确的bug +## 1.0.4(2022-04-19) +- 修复 字节小程序 本地数据无法选择下一级的Bug +## 1.0.3(2022-02-25) +- 修复 nvue 不支持的 v-show 的 bug +## 1.0.2(2022-02-25) +- 修复 条件编译 nvue 不支持的 css 样式 +## 1.0.1(2021-11-23) +- 修复 由上个版本引发的map、v-model等属性不生效的bug +## 1.0.0(2021-11-19) +- 优化 组件 UI,并提供设计资源,详见:[https://uniapp.dcloud.io/component/uniui/resource](https://uniapp.dcloud.io/component/uniui/resource) +- 文档迁移,详见:[https://uniapp.dcloud.io/component/uniui/uni-data-picker](https://uniapp.dcloud.io/component/uniui/uni-data-picker) +## 0.4.9(2021-10-28) +- 修复 VUE2 v-model 概率无效的 bug +## 0.4.8(2021-10-27) +- 修复 v-model 概率无效的 bug +## 0.4.7(2021-10-25) +- 新增 属性 spaceInfo 服务空间配置 HBuilderX 3.2.11+ +- 修复 树型 uniCloud 数据类型为 int 时报错的 bug +## 0.4.6(2021-10-19) +- 修复 非 VUE3 v-model 为 0 时无法选中的 bug +## 0.4.5(2021-09-26) +- 新增 清除已选项的功能(通过 clearIcon 属性配置是否显示按钮),同时提供 clear 方法以供调用,二者等效 +- 修复 readonly 为 true 时报错的 bug +## 0.4.4(2021-09-26) +- 修复 上一版本造成的 map 属性失效的 bug +- 新增 ellipsis 属性,支持配置 tab 选项长度过长时是否自动省略 +## 0.4.3(2021-09-24) +- 修复 某些情况下级联未触发的 bug +## 0.4.2(2021-09-23) +- 新增 提供 show 和 hide 方法,开发者可以通过 ref 调用 +- 新增 选项内容过长自动添加省略号 +## 0.4.1(2021-09-15) +- 新增 map 属性 字段映射,将 text/value 映射到数据中的其他字段 +## 0.4.0(2021-07-13) +- 组件兼容 vue3,如何创建 vue3 项目,详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834) +## 0.3.5(2021-06-04) +- 修复 无法加载云端数据的问题 +## 0.3.4(2021-05-28) +- 修复 v-model 无效问题 +- 修复 loaddata 为空数据组时加载时间过长问题 +- 修复 上个版本引出的本地数据无法选择带有 children 的 2 级节点 +## 0.3.3(2021-05-12) +- 新增 组件示例地址 +## 0.3.2(2021-04-22) +- 修复 非树形数据有 where 属性查询报错的问题 +## 0.3.1(2021-04-15) +- 修复 本地数据概率无法回显时问题 +## 0.3.0(2021-04-07) +- 新增 支持云端非树形表结构数据 +- 修复 根节点 parent_field 字段等于 null 时选择界面错乱问题 +## 0.2.0(2021-03-15) +- 修复 nodeclick、popupopened、popupclosed 事件无法触发的问题 +## 0.1.9(2021-03-09) +- 修复 微信小程序某些情况下无法选择的问题 +## 0.1.8(2021-02-05) +- 优化 部分样式在 nvue 上的兼容表现 +## 0.1.7(2021-02-05) +- 调整为 uni_modules 目录规范 diff --git a/uni_modules/uni-data-picker/components/uni-data-picker/keypress.js b/uni_modules/uni-data-picker/components/uni-data-picker/keypress.js index 6ef26a2..a747b9f 100644 --- a/uni_modules/uni-data-picker/components/uni-data-picker/keypress.js +++ b/uni_modules/uni-data-picker/components/uni-data-picker/keypress.js @@ -1,45 +1,45 @@ -// #ifdef H5 -export default { - name: 'Keypress', - props: { - disable: { - type: Boolean, - default: false - } - }, - mounted () { - const keyNames = { - esc: ['Esc', 'Escape'], - tab: 'Tab', - enter: 'Enter', - space: [' ', 'Spacebar'], - up: ['Up', 'ArrowUp'], - left: ['Left', 'ArrowLeft'], - right: ['Right', 'ArrowRight'], - down: ['Down', 'ArrowDown'], - delete: ['Backspace', 'Delete', 'Del'] - } - const listener = ($event) => { - if (this.disable) { - return - } - const keyName = Object.keys(keyNames).find(key => { - const keyName = $event.key - const value = keyNames[key] - return value === keyName || (Array.isArray(value) && value.includes(keyName)) - }) - if (keyName) { - // 避免和其他按键事件冲突 - setTimeout(() => { - this.$emit(keyName, {}) - }, 0) - } - } - document.addEventListener('keyup', listener) - this.$once('hook:beforeDestroy', () => { - document.removeEventListener('keyup', listener) - }) - }, - render: () => {} -} -// #endif +// #ifdef H5 +export default { + name: 'Keypress', + props: { + disable: { + type: Boolean, + default: false + } + }, + mounted () { + const keyNames = { + esc: ['Esc', 'Escape'], + tab: 'Tab', + enter: 'Enter', + space: [' ', 'Spacebar'], + up: ['Up', 'ArrowUp'], + left: ['Left', 'ArrowLeft'], + right: ['Right', 'ArrowRight'], + down: ['Down', 'ArrowDown'], + delete: ['Backspace', 'Delete', 'Del'] + } + const listener = ($event) => { + if (this.disable) { + return + } + const keyName = Object.keys(keyNames).find(key => { + const keyName = $event.key + const value = keyNames[key] + return value === keyName || (Array.isArray(value) && value.includes(keyName)) + }) + if (keyName) { + // 避免和其他按键事件冲突 + setTimeout(() => { + this.$emit(keyName, {}) + }, 0) + } + } + document.addEventListener('keyup', listener) + this.$once('hook:beforeDestroy', () => { + document.removeEventListener('keyup', listener) + }) + }, + render: () => {} +} +// #endif diff --git a/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-picker.js b/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-picker.js index c12fd54..555d2c5 100644 --- a/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-picker.js +++ b/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-picker.js @@ -1,563 +1,563 @@ -export default { - props: { - localdata: { - type: [Array, Object], - default () { - return [] - } - }, - spaceInfo: { - type: Object, - default () { - return {} - } - }, - collection: { - type: String, - default: '' - }, - action: { - type: String, - default: '' - }, - field: { - type: String, - default: '' - }, - orderby: { - type: String, - default: '' - }, - where: { - type: [String, Object], - default: '' - }, - pageData: { - type: String, - default: 'add' - }, - pageCurrent: { - type: Number, - default: 1 - }, - pageSize: { - type: Number, - default: 20 - }, - getcount: { - type: [Boolean, String], - default: false - }, - getone: { - type: [Boolean, String], - default: false - }, - gettree: { - type: [Boolean, String], - default: false - }, - manual: { - type: Boolean, - default: false - }, - value: { - type: [Array, String, Number], - default () { - return [] - } - }, - modelValue: { - type: [Array, String, Number], - default () { - return [] - } - }, - preload: { - type: Boolean, - default: false - }, - stepSearh: { - type: Boolean, - default: true - }, - selfField: { - type: String, - default: '' - }, - parentField: { - type: String, - default: '' - }, - multiple: { - type: Boolean, - default: false - }, - map: { - type: Object, - default() { - return { - text: "text", - value: "value" - } - } - } - }, - data() { - return { - loading: false, - errorMessage: '', - loadMore: { - contentdown: '', - contentrefresh: '', - contentnomore: '' - }, - dataList: [], - selected: [], - selectedIndex: 0, - page: { - current: this.pageCurrent, - size: this.pageSize, - count: 0 - } - } - }, - computed: { - isLocaldata() { - return !this.collection.length - }, - postField() { - let fields = [this.field]; - if (this.parentField) { - fields.push(`${this.parentField} as parent_value`); - } - return fields.join(','); - }, - dataValue() { - let isModelValue = Array.isArray(this.modelValue) ? (this.modelValue.length > 0) : (this.modelValue !== null || this.modelValue !== undefined) - return isModelValue ? this.modelValue : this.value - }, - hasValue() { - if (typeof this.dataValue === 'number') { - return true - } - return (this.dataValue != null) && (this.dataValue.length > 0) - } - }, - created() { - this.$watch(() => { - var al = []; - ['pageCurrent', - 'pageSize', - 'spaceInfo', - 'value', - 'modelValue', - 'localdata', - 'collection', - 'action', - 'field', - 'orderby', - 'where', - 'getont', - 'getcount', - 'gettree' - ].forEach(key => { - al.push(this[key]) - }); - return al - }, (newValue, oldValue) => { - let needReset = false - for (let i = 2; i < newValue.length; i++) { - if (newValue[i] != oldValue[i]) { - needReset = true - break - } - } - if (newValue[0] != oldValue[0]) { - this.page.current = this.pageCurrent - } - this.page.size = this.pageSize - - this.onPropsChange() - }) - this._treeData = [] - }, - methods: { - onPropsChange() { - this._treeData = [] - }, - getCommand(options = {}) { - /* eslint-disable no-undef */ - let db = uniCloud.database(this.spaceInfo) - - const action = options.action || this.action - if (action) { - db = db.action(action) - } - - const collection = options.collection || this.collection - db = db.collection(collection) - - const where = options.where || this.where - if (!(!where || !Object.keys(where).length)) { - db = db.where(where) - } - - const field = options.field || this.field - if (field) { - db = db.field(field) - } - - const orderby = options.orderby || this.orderby - if (orderby) { - db = db.orderBy(orderby) - } - - const current = options.pageCurrent !== undefined ? options.pageCurrent : this.page.current - const size = options.pageSize !== undefined ? options.pageSize : this.page.size - const getCount = options.getcount !== undefined ? options.getcount : this.getcount - const getTree = options.gettree !== undefined ? options.gettree : this.gettree - - const getOptions = { - getCount, - getTree - } - if (options.getTreePath) { - getOptions.getTreePath = options.getTreePath - } - - db = db.skip(size * (current - 1)).limit(size).get(getOptions) - - return db - }, - getNodeData(callback) { - if (this.loading) { - return - } - this.loading = true - this.getCommand({ - field: this.postField, - where: this._pathWhere() - }).then((res) => { - this.loading = false - this.selected = res.result.data - callback && callback() - }).catch((err) => { - this.loading = false - this.errorMessage = err - }) - }, - getTreePath(callback) { - if (this.loading) { - return - } - this.loading = true - - this.getCommand({ - field: this.postField, - getTreePath: { - startWith: `${this.selfField}=='${this.dataValue}'` - } - }).then((res) => { - this.loading = false - let treePath = [] - this._extractTreePath(res.result.data, treePath) - this.selected = treePath - callback && callback() - }).catch((err) => { - this.loading = false - this.errorMessage = err - }) - }, - loadData() { - if (this.isLocaldata) { - this._processLocalData() - return - } - - if (this.dataValue != null) { - this._loadNodeData((data) => { - this._treeData = data - this._updateBindData() - this._updateSelected() - }) - return - } - - if (this.stepSearh) { - this._loadNodeData((data) => { - this._treeData = data - this._updateBindData() - }) - } else { - this._loadAllData((data) => { - this._treeData = [] - this._extractTree(data, this._treeData, null) - this._updateBindData() - }) - } - }, - _loadAllData(callback) { - if (this.loading) { - return - } - this.loading = true - - this.getCommand({ - field: this.postField, - gettree: true, - startwith: `${this.selfField}=='${this.dataValue}'` - }).then((res) => { - this.loading = false - callback(res.result.data) - this.onDataChange() - }).catch((err) => { - this.loading = false - this.errorMessage = err - }) - }, - _loadNodeData(callback, pw) { - if (this.loading) { - return - } - this.loading = true - - this.getCommand({ - field: this.postField, - where: pw || this._postWhere(), - pageSize: 500 - }).then((res) => { - this.loading = false - callback(res.result.data) - this.onDataChange() - }).catch((err) => { - this.loading = false - this.errorMessage = err - }) - }, - _pathWhere() { - let result = [] - let where_field = this._getParentNameByField(); - if (where_field) { - result.push(`${where_field} == '${this.dataValue}'`) - } - - if (this.where) { - return `(${this.where}) && (${result.join(' || ')})` - } - - return result.join(' || ') - }, - _postWhere() { - let result = [] - let selected = this.selected - let parentField = this.parentField - if (parentField) { - result.push(`${parentField} == null || ${parentField} == ""`) - } - if (selected.length) { - for (var i = 0; i < selected.length - 1; i++) { - result.push(`${parentField} == '${selected[i].value}'`) - } - } - - let where = [] - if (this.where) { - where.push(`(${this.where})`) - } - if (result.length) { - where.push(`(${result.join(' || ')})`) - } - - return where.join(' && ') - }, - _nodeWhere() { - let result = [] - let selected = this.selected - if (selected.length) { - result.push(`${this.parentField} == '${selected[selected.length - 1].value}'`) - } - - if (this.where) { - return `(${this.where}) && (${result.join(' || ')})` - } - - return result.join(' || ') - }, - _getParentNameByField() { - const fields = this.field.split(','); - let where_field = null; - for (let i = 0; i < fields.length; i++) { - const items = fields[i].split('as'); - if (items.length < 2) { - continue; - } - if (items[1].trim() === 'value') { - where_field = items[0].trim(); - break; - } - } - return where_field - }, - _isTreeView() { - return (this.parentField && this.selfField) - }, - _updateSelected() { - var dl = this.dataList - var sl = this.selected - let textField = this.map.text - let valueField = this.map.value - for (var i = 0; i < sl.length; i++) { - var value = sl[i].value - var dl2 = dl[i] - for (var j = 0; j < dl2.length; j++) { - var item2 = dl2[j] - if (item2[valueField] === value) { - sl[i].text = item2[textField] - break - } - } - } - }, - _updateBindData(node) { - const { - dataList, - hasNodes - } = this._filterData(this._treeData, this.selected) - - let isleaf = this._stepSearh === false && !hasNodes - - if (node) { - node.isleaf = isleaf - } - - this.dataList = dataList - this.selectedIndex = dataList.length - 1 - - if (!isleaf && this.selected.length < dataList.length) { - this.selected.push({ - value: null, - text: "请选择" - }) - } - - return { - isleaf, - hasNodes - } - }, - _filterData(data, paths) { - let dataList = [] - let hasNodes = true - - dataList.push(data.filter((item) => { - return (item.parent_value === null || item.parent_value === undefined || item.parent_value === '') - })) - for (let i = 0; i < paths.length; i++) { - var value = paths[i].value - var nodes = data.filter((item) => { - return item.parent_value === value - }) - - if (nodes.length) { - dataList.push(nodes) - } else { - hasNodes = false - } - } - - return { - dataList, - hasNodes - } - }, - _extractTree(nodes, result, parent_value) { - let list = result || [] - let valueField = this.map.value - for (let i = 0; i < nodes.length; i++) { - let node = nodes[i] - - let child = {} - for (let key in node) { - if (key !== 'children') { - child[key] = node[key] - } - } - if (parent_value !== null && parent_value !== undefined && parent_value !== '') { - child.parent_value = parent_value - } - result.push(child) - - let children = node.children - if (children) { - this._extractTree(children, result, node[valueField]) - } - } - }, - _extractTreePath(nodes, result) { - let list = result || [] - for (let i = 0; i < nodes.length; i++) { - let node = nodes[i] - - let child = {} - for (let key in node) { - if (key !== 'children') { - child[key] = node[key] - } - } - result.push(child) - - let children = node.children - if (children) { - this._extractTreePath(children, result) - } - } - }, - _findNodePath(key, nodes, path = []) { - let textField = this.map.text - let valueField = this.map.value - for (let i = 0; i < nodes.length; i++) { - let node = nodes[i] - let children = node.children - let text = node[textField] - let value = node[valueField] - - path.push({ - value, - text - }) - - if (value === key) { - return path - } - - if (children) { - const p = this._findNodePath(key, children, path) - if (p.length) { - return p - } - } - - path.pop() - } - return [] - }, - _processLocalData() { - this._treeData = [] - this._extractTree(this.localdata, this._treeData) - - var inputValue = this.dataValue - if (inputValue === undefined) { - return - } - - if (Array.isArray(inputValue)) { - inputValue = inputValue[inputValue.length - 1] - if (typeof inputValue === 'object' && inputValue[this.map.value]) { - inputValue = inputValue[this.map.value] - } - } - - this.selected = this._findNodePath(inputValue, this.localdata) - } - } -} +export default { + props: { + localdata: { + type: [Array, Object], + default () { + return [] + } + }, + spaceInfo: { + type: Object, + default () { + return {} + } + }, + collection: { + type: String, + default: '' + }, + action: { + type: String, + default: '' + }, + field: { + type: String, + default: '' + }, + orderby: { + type: String, + default: '' + }, + where: { + type: [String, Object], + default: '' + }, + pageData: { + type: String, + default: 'add' + }, + pageCurrent: { + type: Number, + default: 1 + }, + pageSize: { + type: Number, + default: 20 + }, + getcount: { + type: [Boolean, String], + default: false + }, + getone: { + type: [Boolean, String], + default: false + }, + gettree: { + type: [Boolean, String], + default: false + }, + manual: { + type: Boolean, + default: false + }, + value: { + type: [Array, String, Number], + default () { + return [] + } + }, + modelValue: { + type: [Array, String, Number], + default () { + return [] + } + }, + preload: { + type: Boolean, + default: false + }, + stepSearh: { + type: Boolean, + default: true + }, + selfField: { + type: String, + default: '' + }, + parentField: { + type: String, + default: '' + }, + multiple: { + type: Boolean, + default: false + }, + map: { + type: Object, + default() { + return { + text: "text", + value: "value" + } + } + } + }, + data() { + return { + loading: false, + errorMessage: '', + loadMore: { + contentdown: '', + contentrefresh: '', + contentnomore: '' + }, + dataList: [], + selected: [], + selectedIndex: 0, + page: { + current: this.pageCurrent, + size: this.pageSize, + count: 0 + } + } + }, + computed: { + isLocaldata() { + return !this.collection.length + }, + postField() { + let fields = [this.field]; + if (this.parentField) { + fields.push(`${this.parentField} as parent_value`); + } + return fields.join(','); + }, + dataValue() { + let isModelValue = Array.isArray(this.modelValue) ? (this.modelValue.length > 0) : (this.modelValue !== null || this.modelValue !== undefined) + return isModelValue ? this.modelValue : this.value + }, + hasValue() { + if (typeof this.dataValue === 'number') { + return true + } + return (this.dataValue != null) && (this.dataValue.length > 0) + } + }, + created() { + this.$watch(() => { + var al = []; + ['pageCurrent', + 'pageSize', + 'spaceInfo', + 'value', + 'modelValue', + 'localdata', + 'collection', + 'action', + 'field', + 'orderby', + 'where', + 'getont', + 'getcount', + 'gettree' + ].forEach(key => { + al.push(this[key]) + }); + return al + }, (newValue, oldValue) => { + let needReset = false + for (let i = 2; i < newValue.length; i++) { + if (newValue[i] != oldValue[i]) { + needReset = true + break + } + } + if (newValue[0] != oldValue[0]) { + this.page.current = this.pageCurrent + } + this.page.size = this.pageSize + + this.onPropsChange() + }) + this._treeData = [] + }, + methods: { + onPropsChange() { + this._treeData = [] + }, + getCommand(options = {}) { + /* eslint-disable no-undef */ + let db = uniCloud.database(this.spaceInfo) + + const action = options.action || this.action + if (action) { + db = db.action(action) + } + + const collection = options.collection || this.collection + db = db.collection(collection) + + const where = options.where || this.where + if (!(!where || !Object.keys(where).length)) { + db = db.where(where) + } + + const field = options.field || this.field + if (field) { + db = db.field(field) + } + + const orderby = options.orderby || this.orderby + if (orderby) { + db = db.orderBy(orderby) + } + + const current = options.pageCurrent !== undefined ? options.pageCurrent : this.page.current + const size = options.pageSize !== undefined ? options.pageSize : this.page.size + const getCount = options.getcount !== undefined ? options.getcount : this.getcount + const getTree = options.gettree !== undefined ? options.gettree : this.gettree + + const getOptions = { + getCount, + getTree + } + if (options.getTreePath) { + getOptions.getTreePath = options.getTreePath + } + + db = db.skip(size * (current - 1)).limit(size).get(getOptions) + + return db + }, + getNodeData(callback) { + if (this.loading) { + return + } + this.loading = true + this.getCommand({ + field: this.postField, + where: this._pathWhere() + }).then((res) => { + this.loading = false + this.selected = res.result.data + callback && callback() + }).catch((err) => { + this.loading = false + this.errorMessage = err + }) + }, + getTreePath(callback) { + if (this.loading) { + return + } + this.loading = true + + this.getCommand({ + field: this.postField, + getTreePath: { + startWith: `${this.selfField}=='${this.dataValue}'` + } + }).then((res) => { + this.loading = false + let treePath = [] + this._extractTreePath(res.result.data, treePath) + this.selected = treePath + callback && callback() + }).catch((err) => { + this.loading = false + this.errorMessage = err + }) + }, + loadData() { + if (this.isLocaldata) { + this._processLocalData() + return + } + + if (this.dataValue != null) { + this._loadNodeData((data) => { + this._treeData = data + this._updateBindData() + this._updateSelected() + }) + return + } + + if (this.stepSearh) { + this._loadNodeData((data) => { + this._treeData = data + this._updateBindData() + }) + } else { + this._loadAllData((data) => { + this._treeData = [] + this._extractTree(data, this._treeData, null) + this._updateBindData() + }) + } + }, + _loadAllData(callback) { + if (this.loading) { + return + } + this.loading = true + + this.getCommand({ + field: this.postField, + gettree: true, + startwith: `${this.selfField}=='${this.dataValue}'` + }).then((res) => { + this.loading = false + callback(res.result.data) + this.onDataChange() + }).catch((err) => { + this.loading = false + this.errorMessage = err + }) + }, + _loadNodeData(callback, pw) { + if (this.loading) { + return + } + this.loading = true + + this.getCommand({ + field: this.postField, + where: pw || this._postWhere(), + pageSize: 500 + }).then((res) => { + this.loading = false + callback(res.result.data) + this.onDataChange() + }).catch((err) => { + this.loading = false + this.errorMessage = err + }) + }, + _pathWhere() { + let result = [] + let where_field = this._getParentNameByField(); + if (where_field) { + result.push(`${where_field} == '${this.dataValue}'`) + } + + if (this.where) { + return `(${this.where}) && (${result.join(' || ')})` + } + + return result.join(' || ') + }, + _postWhere() { + let result = [] + let selected = this.selected + let parentField = this.parentField + if (parentField) { + result.push(`${parentField} == null || ${parentField} == ""`) + } + if (selected.length) { + for (var i = 0; i < selected.length - 1; i++) { + result.push(`${parentField} == '${selected[i].value}'`) + } + } + + let where = [] + if (this.where) { + where.push(`(${this.where})`) + } + if (result.length) { + where.push(`(${result.join(' || ')})`) + } + + return where.join(' && ') + }, + _nodeWhere() { + let result = [] + let selected = this.selected + if (selected.length) { + result.push(`${this.parentField} == '${selected[selected.length - 1].value}'`) + } + + if (this.where) { + return `(${this.where}) && (${result.join(' || ')})` + } + + return result.join(' || ') + }, + _getParentNameByField() { + const fields = this.field.split(','); + let where_field = null; + for (let i = 0; i < fields.length; i++) { + const items = fields[i].split('as'); + if (items.length < 2) { + continue; + } + if (items[1].trim() === 'value') { + where_field = items[0].trim(); + break; + } + } + return where_field + }, + _isTreeView() { + return (this.parentField && this.selfField) + }, + _updateSelected() { + var dl = this.dataList + var sl = this.selected + let textField = this.map.text + let valueField = this.map.value + for (var i = 0; i < sl.length; i++) { + var value = sl[i].value + var dl2 = dl[i] + for (var j = 0; j < dl2.length; j++) { + var item2 = dl2[j] + if (item2[valueField] === value) { + sl[i].text = item2[textField] + break + } + } + } + }, + _updateBindData(node) { + const { + dataList, + hasNodes + } = this._filterData(this._treeData, this.selected) + + let isleaf = this._stepSearh === false && !hasNodes + + if (node) { + node.isleaf = isleaf + } + + this.dataList = dataList + this.selectedIndex = dataList.length - 1 + + if (!isleaf && this.selected.length < dataList.length) { + this.selected.push({ + value: null, + text: "请选择" + }) + } + + return { + isleaf, + hasNodes + } + }, + _filterData(data, paths) { + let dataList = [] + let hasNodes = true + + dataList.push(data.filter((item) => { + return (item.parent_value === null || item.parent_value === undefined || item.parent_value === '') + })) + for (let i = 0; i < paths.length; i++) { + var value = paths[i].value + var nodes = data.filter((item) => { + return item.parent_value === value + }) + + if (nodes.length) { + dataList.push(nodes) + } else { + hasNodes = false + } + } + + return { + dataList, + hasNodes + } + }, + _extractTree(nodes, result, parent_value) { + let list = result || [] + let valueField = this.map.value + for (let i = 0; i < nodes.length; i++) { + let node = nodes[i] + + let child = {} + for (let key in node) { + if (key !== 'children') { + child[key] = node[key] + } + } + if (parent_value !== null && parent_value !== undefined && parent_value !== '') { + child.parent_value = parent_value + } + result.push(child) + + let children = node.children + if (children) { + this._extractTree(children, result, node[valueField]) + } + } + }, + _extractTreePath(nodes, result) { + let list = result || [] + for (let i = 0; i < nodes.length; i++) { + let node = nodes[i] + + let child = {} + for (let key in node) { + if (key !== 'children') { + child[key] = node[key] + } + } + result.push(child) + + let children = node.children + if (children) { + this._extractTreePath(children, result) + } + } + }, + _findNodePath(key, nodes, path = []) { + let textField = this.map.text + let valueField = this.map.value + for (let i = 0; i < nodes.length; i++) { + let node = nodes[i] + let children = node.children + let text = node[textField] + let value = node[valueField] + + path.push({ + value, + text + }) + + if (value === key) { + return path + } + + if (children) { + const p = this._findNodePath(key, children, path) + if (p.length) { + return p + } + } + + path.pop() + } + return [] + }, + _processLocalData() { + this._treeData = [] + this._extractTree(this.localdata, this._treeData) + + var inputValue = this.dataValue + if (inputValue === undefined) { + return + } + + if (Array.isArray(inputValue)) { + inputValue = inputValue[inputValue.length - 1] + if (typeof inputValue === 'object' && inputValue[this.map.value]) { + inputValue = inputValue[this.map.value] + } + } + + this.selected = this._findNodePath(inputValue, this.localdata) + } + } +} diff --git a/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-pickerview.vue b/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-pickerview.vue index b2691e5..0990868 100644 --- a/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-pickerview.vue +++ b/uni_modules/uni-data-picker/components/uni-data-pickerview/uni-data-pickerview.vue @@ -14,7 +14,7 @@