diff --git a/.gitignore b/.gitignore index 53e678b4..01db4aa5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /node_modules/ -/lib/ \ No newline at end of file +/lib/ +*.py \ No newline at end of file diff --git a/README.md b/README.md index 0e20bb3e..c9b721f4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

- +

@@ -74,7 +74,6 @@ pnpm add karin-plugin-mystool@latest -w
其他 -- [x] 使用[wkhtmltoimage](https://wkhtmltopdf.org/)截图(由于坤术原因部分图片不支持使用,暂时没有安装教程、windows直接下载exe即可、ubuntu使用apt安装),建议优先使用[karin-puppeteer](https://github.com/KarinJS/karin-puppeteer) - [x] 1034、10035、签到(额外安装[插件](https://github.com/babanbang/MysSign)提供功能)
@@ -86,6 +85,5 @@ pnpm add karin-plugin-mystool@latest -w |:------:|------------| |[Miao-Yunzai](https://gitee.com/yoimiya-kokomi/Miao-Yunzai)|喵喵!| |[miao-plugin](https://gitee.com/yoimiya-kokomi/miao-plugin)|喵喵!| -|[simple-qrbtf](https://github.com/StringKe/simple-qrbtf)|二维码生成| ![Alt](https://repobeats.axiom.co/api/embed/a987d3b44ed2f3c8cac52fe11b3f24b075d5f58b.svg "Repobeats analytics image") \ No newline at end of file diff --git a/config/config.yaml b/config/config.yaml index e85805dd..c76a6b89 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -12,9 +12,6 @@ wkhtmltoimage: false # 渲染精度(0-100) quality: 100 -# 使用自定义样式的二维码 -qrbtf: false - # 数据库(可选sqlite、postgres)一般使用sqlite就足够满足需求 dialect: sqlite diff --git a/config/qrbtf.yaml b/config/qrbtf.yaml deleted file mode 100644 index 05967da2..00000000 --- a/config/qrbtf.yaml +++ /dev/null @@ -1 +0,0 @@ -styles: [] \ No newline at end of file diff --git a/package.json b/package.json index 2c1359ed..a50df8b5 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "sqlite3": "5.1.6", "pg": "^8.12.0", "md5": "^2.3.0", + "qrcode": "^1.5.3", "image-size": "^1.1.1" }, "devDependencies": { @@ -39,6 +40,7 @@ "@types/node-schedule": "^2.1.7", "@types/ws": "^8.5.11", "@types/md5": "^2.3.5", + "@types/qrcode": "^1.5.5", "eslint": "^9.7.0", "neostandard": "^0.11.1", "tsc-alias": "^1.8.10", diff --git a/resources/css/common.css b/resources/css/common.css deleted file mode 100644 index 0b5ae832..00000000 --- a/resources/css/common.css +++ /dev/null @@ -1,739 +0,0 @@ -@font-face { - font-family: "HYWenHei-55W"; - src: url("../fonts/HYWenHei-55W.ttf"); - font-weight: normal; - font-style: normal; -} - -@font-face { - font-family: "zzz-font"; - src: url("../fonts/zzz_fonts.ttf"); -} - -@font-face { - font-family: 'Number'; - src: url("../fonts/tttgbnumber.woff") format('woff'), url("../fonts/tttgbnumber.ttf") format('truetype'); -} - -@font-face { - font-family: 'NZBZ'; - src: url("../fonts/NZBZ.woff") format('woff'), url("../fonts/NZBZ.ttf") format('truetype'); -} - -@font-face { - font-family: 'YS'; - src: url("../fonts/HYWH-65W.woff") format('woff'), url("../fonts/HYWH-65W.ttf") format('truetype'); -} - -.font-YS { - font-family: Number, "汉仪文黑-65W", YS, PingFangSC-Medium, "PingFang SC", sans-serif; -} - -.font-NZBZ { - font-family: Number, "印品南征北战NZBZ体", NZBZ, "汉仪文黑-65W", YS, PingFangSC-Medium, "PingFang SC", sans-serif; -} - -* { - margin: 0; - padding: 0; - -webkit-box-sizing: border-box; - box-sizing: border-box; - -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; -} - -body { - font-size: 18px; - color: #1e1f20; - font-family: Number, "汉仪文黑-65W", YS, PingFangSC-Medium, "PingFang SC", sans-serif; - -webkit-transform-origin: 0 0; - transform-origin: 0 0; - width: 600px; -} - -.container { - padding: 20px 15px 10px 15px; - background-size: contain; - width: 100%; -} - -.head-box { - border-radius: 15px; - padding: 10px 20px; - position: relative; - color: #fff; - margin-top: 30px; -} - -.head-box .title { - font-family: Number, "印品南征北战NZBZ体", NZBZ, "汉仪文黑-65W", YS, PingFangSC-Medium, "PingFang SC", sans-serif; - font-size: 36px; - text-shadow: 0 0 1px #000, 1px 1px 3px rgba(0, 0, 0, 0.9); -} - -.head-box .title .label { - display: inline-block; - margin-left: 10px; -} - -.head-box .genshin_logo { - position: absolute; - top: 1px; - right: 15px; - width: 97px; -} - -.head-box .label { - font-size: 16px; - text-shadow: 0 0 1px #000, 1px 1px 3px rgba(0, 0, 0, 0.9); -} - -.head-box .label span { - color: #d3bc8e; - padding: 0 2px; -} - -.notice { - color: #888; - font-size: 12px; - text-align: right; - padding: 12px 5px 5px; -} - -.notice-center { - color: #fff; - text-align: center; - margin-bottom: 10px; - text-shadow: 1px 1px 1px #333; -} - -.copyright { - width: 100%; - font-size: 14px; - text-align: center; - color: #fff; - position: absolute; - left: 0; - bottom: 10px; - text-shadow: 1px 1px 1px #000; -} - -.copyright .version { - color: #d3bc8e; - display: inline-block; - padding: 0 3px; -} - -/* */ -.cont { - border-radius: 10px; - background: url('../images/cont/card-bg.png') top left repeat-x; - background-size: auto 100%; - margin: 5px 0; - position: relative; - -webkit-box-shadow: 0 0 1px 0 #ccc, 2px 2px 4px 0 rgba(50, 50, 50, 0.8); - box-shadow: 0 0 1px 0 #ccc, 2px 2px 4px 0 rgba(50, 50, 50, 0.8); - overflow: hidden; - color: #fff; - font-size: 16px; -} - -.cons { - display: inline-block; - vertical-align: middle; - padding: 0 5px; - border-radius: 4px; - color: rgb(255, 255, 255); -} - -.cons-0 { - background: rgb(119, 119, 119); -} - -.cons-n0 { - background: rgb(45, 45, 45); -} - -.cons-1 { - background: rgb(94, 151, 163); -} - -.cons-2 { - background: rgb(46, 179, 133); -} - -.cons-3 { - background: rgb(44, 150, 174); -} - -.cons-4 { - background: rgb(44, 70, 174); -} - -.cons-5 { - background: rgb(61, 18, 117); -} - -.cons-6 { - background: rgb(253, 89, 60); -} - -.cons2-0 { - border-radius: 4px; - background: rgb(50, 50, 50); -} - -.cons2-1 { - border-radius: 4px; - background: rgb(94, 151, 163); -} - -.cons2-2 { - border-radius: 4px; - background: rgb(46, 179, 133); -} - -.cons2-3 { - border-radius: 4px; - background: rgb(44, 150, 174); -} - -.cons2-4 { - border-radius: 4px; - background: rgb(44, 70, 174); -} - -.cons2-5 { - border-radius: 4px; - background: rgb(61, 18, 117); -} - -.cons2-6 { - border-radius: 4px; - background: rgb(253, 89, 60); -} - -.cons3-1 { - color: rgb(255, 255, 255); -} - -.cons3-2 { - color: rgb(44, 150, 174); -} - -.cons3-3 { - color: rgb(44, 150, 174); -} - -.cons3-4 { - color: rgb(44, 70, 174); -} - -.cons3-5 { - color: rgb(61, 18, 117); -} - -.cons3-6 { - color: rgb(253, 89, 60); -} - -.avatar-cons { - height: 15.5%; - width: 12%; - font-size: 70%; - font-weight: bold; - aspect-ratio: 1; - display: grid; - place-content: center; - text-align: center; - position: absolute; - top: 1%; - right: 1%; - z-index: 0; - padding-bottom: 4%; - background-image: url('../images/item/cons.png'); - background-size: cover; - background-repeat: no-repeat; -} - -.avatar-cons p { - position: absolute; - top: 8%; - right: 33%; -} - -/******** Fetter ********/ -.fetter { - width: 50px; - height: 50px; - display: inline-block; - background: url('../images/item/fetter.png'); - background-size: auto 100%; -} - -.fetter.fetter1 { - background-position: 0% 0; -} - -.fetter.fetter2 { - background-position: 11.11111111% 0; -} - -.fetter.fetter3 { - background-position: 22.22222222% 0; -} - -.fetter.fetter4 { - background-position: 33.33333333% 0; -} - -.fetter.fetter5 { - background-position: 44.44444444% 0; -} - -.fetter.fetter6 { - background-position: 55.55555556% 0; -} - -.fetter.fetter7 { - background-position: 66.66666667% 0; -} - -.fetter.fetter8 { - background-position: 77.77777778% 0; -} - -.fetter.fetter9 { - background-position: 88.88888889% 0; -} - -.fetter.fetter10 { - background-position: 100% 0; -} - -/* talent */ -.bg-wind, -.bg-anemo { - background-image: url('../images./images/talent/talent-anemo.png'); -} - -.bg-ice, -.bg-cryo { - background-image: url('../images/talent/talent-cryo.png'); -} - -.bg-dendro { - background-image: url('../images/talent/talent-dendro.png'); -} - -.bg-elec, -.bg-electro { - background-image: url('../images/talent/talent-electro.png'); -} - -.bg-imaginary, -.bg-geo { - background-image: url('../images/talent/talent-geo.png'); -} - -.bg-hydro { - background-image: url('../images/talent/talent-hydro.png'); -} - -.bg-fire, -.bg-pyro { - background-image: url('../images/talent/talent-pyro.png'); -} - -.bg-quantum { - background-image: url('../images/talent/talent-quantum.png'); -} - -.bg-phy { - background-image: url('../images/talent/talent-sr.png'); -} - -.noact { - background-image: url('../images/talent/talent-sr.png'); - opacity: 0.4; -} - -/* attr */ -.attr-icon { - background-image: url('../images/item/icon-sr.png'); -} - -.attr-icon-gs { - background-image: url('../images/item/icon.png'); -} - -.i-hp { - background-position: -16px 0; -} - -.i-atk { - background-position: -32px 0; -} - -.i-def { - background-position: -48px 0; -} - -.i-mastery { - background-position: -64px 0; -} - -.i-cpct { - background-position: -80px 0; -} - -.i-cdmg { - background-position: -96px 0; -} - -.i-stance { - background-position: -64px 0; -} - -.i-recharge { - background-position: -112px 0; -} - -.i-dmg { - background-position: -128px 0; -} - -.i-heal { - background-image: url('../images/item/icon-sr.png'); - background-position: -144px 0; -} - -.i-speed { - background-position: -160px 0; -} - -.i-effPct { - background-position: -176px 0; -} - -.i-effDef { - background-position: -192px 0; -} - -/******** ELEM ********/ -.elem-hydro .talent-icon { - background-image: url("../images/talent/talent-hydro.png"); -} - -.elem-hydro .elem-bg, -.hydro-bg { - background-image: url("../images/elem-bg/bg-hydro.png"); -} - -.elem-anemo .talent-icon { - background-image: url("../images/talent/talent-anemo.png"); -} - -.elem-anemo .elem-bg, -.elem-wind .elem-bg, -.anemo-bg { - background-image: url("../images/elem-bg/bg-anemo.png"); -} - -.elem-cryo .talent-icon { - background-image: url("../images/talent/talent-cryo.png"); -} - -.elem-cryo .elem-bg, -.elem-ice .elem-bg, -.cryo-bg { - background-image: url("../images/elem-bg/bg-cryo.png"); -} - -.elem-electro .talent-icon { - background-image: url("../images/talent/talent-electro.png"); -} - -.elem-electro .elem-bg, -.elem-elec .elem-bg, -.electro-bg { - background-image: url("../images/elem-bg/bg-electro.png"); -} - -.elem-geo .talent-icon { - background-image: url("../images/talent/talent-geo.png"); -} - -.elem-geo .elem-bg, -.elem-imaginary .elem-bg, -.geo-bg { - background-image: url("../images/elem-bg/bg-geo.png"); -} - -.elem-pyro .talent-icon { - background-image: url("../images/talent/talent-pyro.png"); -} - -.elem-pyro .elem-bg, -.elem-fire .elem-bg, -.pyro-bg { - background-image: url("../images/elem-bg/bg-pyro.png"); -} - -.elem-dendro .talent-icon { - background-image: url("../images/talent/talent-dendro.png"); -} - -.elem-dendro .elem-bg, -.dendro-bg { - background-image: url("../images/elem-bg/bg-dendro.png"); -} - -.elem-quantum .talent-icon { - background-image: url("../images/talent/talent-quantum.png"); -} - -.elem-quantum .elem-bg, -.quantum-bg { - background-image: url("../images/elem-bg/bg-quantum.png"); -} - -.elem-sr .talent-icon { - background-image: url("../images/talent/talent-sr.png"); -} - -.elem-sr .elem-bg, -.elem-phy .elem-bg, -.sr-bg { - background-image: url("../images/elem-bg/bg-sr.png"); -} - -/* item-icon */ -.item-icon { - width: 100%; - height: 100%; - border-radius: 4px; - position: relative; - overflow: hidden; -} - -.item-icon .img { - width: 100%; - height: 100%; - display: block; - background-size: contain; - background-position: center; - background-repeat: no-repeat; -} - -.item-icon.artis .img { - width: 84%; - height: 84%; - margin: 8%; -} - -.item-icon.star1 { - background-image: url("../images/item/bg1.png"); -} - -.item-icon.opacity-bg.star1 { - background-image: url("../images/item/bg1-o.png"); -} - -.item-icon.star2 { - background-image: url("../images/item/bg2.png"); -} - -.item-icon.opacity-bg.star2 { - background-image: url("../images/item/bg2-o.png"); -} - -.item-icon.star3 { - background-image: url("../images/item/bg3.png"); -} - -.item-icon.opacity-bg.star3 { - background-image: url("../images/item/bg3-o.png"); -} - -.item-icon.star4 { - background-image: url("../images/item/bg4.png"); -} - -.item-icon.opacity-bg.star4 { - background-image: url("../images/item/bg4-o.png"); -} - -.item-icon.star5 { - background-image: url("../images/item/bg5.png"); -} - -.item-icon.opacity-bg.star5 { - background-image: url("../images/item/bg5-o.png"); -} - -.item-icon.star-w { - background: #fff; -} - -.item-list { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; -} - -.item-list .item-card { - width: 70px; - background: #e7e5d9; -} - -.item-list .item-icon { - border-bottom-left-radius: 0; - border-bottom-right-radius: 12px; -} - -.item-list .item-title { - color: #222; - font-size: 13px; - text-align: center; - padding: 2px; - white-space: nowrap; - overflow: hidden; -} - -.item-list .item-icon { - height: initial; -} - -.item-list .item-badge { - position: absolute; - display: block; - left: 0; - top: 0; - background: rgba(0, 0, 0, 0.6); - font-size: 12px; - color: #fff; - padding: 4px 5px 3px; - border-radius: 0 0 6px 0; -} - -.icon { - background-size: contain; - background-position: center; - background-repeat: no-repeat; - display: block; -} - -.bg5 { - background-image: url('../images/item/bg5.png'); -} - -.bg4 { - background-image: url('../images/item/bg4.png'); -} - -.存护 { - background-image: url('../images/talent/存护.png'); -} - -.存护-s { - background-image: url('../images/talent/存护-s.png'); -} - -.存护-bg { - background-image: url('../images/talent/存护.png'), url('../images/talent/bg.png'); -} - -.丰饶 { - background-image: url('../images/talent/丰饶.png'); -} - -.丰饶-s { - background-image: url('../images/talent/丰饶-s.png'); -} - -.丰饶-bg { - background-image: url('../images/talent/丰饶.png'), url('../images/talent/bg.png'); -} - -.毁灭 { - background-image: url('../images/talent/毁灭.png'); -} - -.毁灭-s { - background-image: url('./talent/毁灭-s.png'); -} - -.毁灭-bg { - background-image: url('../images/talent/毁灭.png'), url('../images/talent/bg.png'); -} - -.同谐 { - background-image: url('../images/talent/同谐.png'); -} - -.同谐-s { - background-image: url('../images/talent/同谐-s.png'); -} - -.同谐-bg { - background-image: url('../images/talent/同谐.png'), url('../images/talent/bg.png'); -} - -.虚无 { - background-image: url('../images/talent/虚无.png'); -} - -.虚无-s { - background-image: url('../images/talent/虚无-s.png'); -} - -.虚无-bg { - background-image: url('../images/talent/虚无.png'), url('../images/talent/bg.png'); -} - -.巡猎 { - background-image: url('../images/talent/巡猎.png'); -} - -.巡猎-s { - background-image: url('../images/talent/巡猎-s.png'); -} - -.巡猎-bg { - background-image: url('../images/talent/巡猎.png'), url('../images/talent/bg.png'); -} - -.智识 { - background-image: url('../images/talent/智识.png'); -} - -.智识-s { - background-image: url('../images/talent/智识-s.png'); -} - -.智识-bg { - background-image: url('../images/talent/智识.png'), url('../images/talent/bg.png'); -} - -/** profile**/ -.mark-ACE, -.mark-MAX { - color: #e85656; - font-weight: bold; -} - -.mark-SSS, -.mark-SS { - color: #ffe699; - font-weight: bold; -} - -.mark-S, -.mark-A { - color: #d699ff; - font-weight: bold; -} \ No newline at end of file diff --git a/resources/images/cont/card-bg.png b/resources/images/cont/card-bg.png deleted file mode 100644 index 036d416e..00000000 Binary files a/resources/images/cont/card-bg.png and /dev/null differ diff --git a/resources/images/cont/logo.png b/resources/images/cont/logo.png deleted file mode 100644 index a8cb922f..00000000 Binary files a/resources/images/cont/logo.png and /dev/null differ diff --git a/resources/images/cont/up-num-icon0.png b/resources/images/cont/up-num-icon0.png deleted file mode 100644 index a7865996..00000000 Binary files a/resources/images/cont/up-num-icon0.png and /dev/null differ diff --git a/resources/images/cont/up-num-icon1.png b/resources/images/cont/up-num-icon1.png deleted file mode 100644 index 63475700..00000000 Binary files a/resources/images/cont/up-num-icon1.png and /dev/null differ diff --git a/resources/images/cont/up-num-icon2.png b/resources/images/cont/up-num-icon2.png deleted file mode 100644 index 9d91fcb5..00000000 Binary files a/resources/images/cont/up-num-icon2.png and /dev/null differ diff --git a/resources/images/default_banner/gs.webp b/resources/images/default_banner/gs.webp new file mode 100644 index 00000000..e0d2fc0b Binary files /dev/null and b/resources/images/default_banner/gs.webp differ diff --git a/resources/images/default_banner/sr.webp b/resources/images/default_banner/sr.webp new file mode 100644 index 00000000..2a58b01a Binary files /dev/null and b/resources/images/default_banner/sr.webp differ diff --git a/resources/images/default_banner/zzz.webp b/resources/images/default_banner/zzz.webp new file mode 100644 index 00000000..3c068d9f Binary files /dev/null and b/resources/images/default_banner/zzz.webp differ diff --git a/resources/images/default_face/gs.webp b/resources/images/default_face/gs.webp new file mode 100644 index 00000000..2d06f082 Binary files /dev/null and b/resources/images/default_face/gs.webp differ diff --git a/resources/images/default_face/sr.webp b/resources/images/default_face/sr.webp new file mode 100644 index 00000000..a6d663e4 Binary files /dev/null and b/resources/images/default_face/sr.webp differ diff --git a/resources/images/default_face/zzz.webp b/resources/images/default_face/zzz.webp new file mode 100644 index 00000000..21c65a15 Binary files /dev/null and b/resources/images/default_face/zzz.webp differ diff --git a/resources/images/elem-bg/bg-anemo.png b/resources/images/elem-bg/bg-anemo.png deleted file mode 100644 index 38f0fa0d..00000000 Binary files a/resources/images/elem-bg/bg-anemo.png and /dev/null differ diff --git a/resources/images/elem-bg/bg-cryo.png b/resources/images/elem-bg/bg-cryo.png deleted file mode 100644 index 4e7c14c3..00000000 Binary files a/resources/images/elem-bg/bg-cryo.png and /dev/null differ diff --git a/resources/images/elem-bg/bg-dendro.png b/resources/images/elem-bg/bg-dendro.png deleted file mode 100644 index 6fb75930..00000000 Binary files a/resources/images/elem-bg/bg-dendro.png and /dev/null differ diff --git a/resources/images/elem-bg/bg-electro.png b/resources/images/elem-bg/bg-electro.png deleted file mode 100644 index f9961161..00000000 Binary files a/resources/images/elem-bg/bg-electro.png and /dev/null differ diff --git a/resources/images/elem-bg/bg-geo.png b/resources/images/elem-bg/bg-geo.png deleted file mode 100644 index 0e313a56..00000000 Binary files a/resources/images/elem-bg/bg-geo.png and /dev/null differ diff --git a/resources/images/elem-bg/bg-hydro.png b/resources/images/elem-bg/bg-hydro.png deleted file mode 100644 index ee7afb2c..00000000 Binary files a/resources/images/elem-bg/bg-hydro.png and /dev/null differ diff --git a/resources/images/elem-bg/bg-pyro.png b/resources/images/elem-bg/bg-pyro.png deleted file mode 100644 index 4b153afe..00000000 Binary files a/resources/images/elem-bg/bg-pyro.png and /dev/null differ diff --git a/resources/images/elem-bg/bg-quantum.png b/resources/images/elem-bg/bg-quantum.png deleted file mode 100644 index 83de20b3..00000000 Binary files a/resources/images/elem-bg/bg-quantum.png and /dev/null differ diff --git a/resources/images/elem-bg/bg-sr.png b/resources/images/elem-bg/bg-sr.png deleted file mode 100644 index 3dd07c94..00000000 Binary files a/resources/images/elem-bg/bg-sr.png and /dev/null differ diff --git a/resources/images/elem-bg/talent-quantum.png b/resources/images/elem-bg/talent-quantum.png deleted file mode 100644 index e42af8dc..00000000 Binary files a/resources/images/elem-bg/talent-quantum.png and /dev/null differ diff --git a/resources/images/elem-bg/talent-sr.png b/resources/images/elem-bg/talent-sr.png deleted file mode 100644 index d247c4e2..00000000 Binary files a/resources/images/elem-bg/talent-sr.png and /dev/null differ diff --git a/resources/images/icon/check.png b/resources/images/icon/check.png deleted file mode 100644 index f89e65c3..00000000 Binary files a/resources/images/icon/check.png and /dev/null differ diff --git a/resources/images/icon/check.webp b/resources/images/icon/check.webp new file mode 100644 index 00000000..5f1908dc Binary files /dev/null and b/resources/images/icon/check.webp differ diff --git a/resources/images/item/artifact-icon.png b/resources/images/item/artifact-icon.png deleted file mode 100644 index fc055941..00000000 Binary files a/resources/images/item/artifact-icon.png and /dev/null differ diff --git a/resources/images/item/atk-bow.png b/resources/images/item/atk-bow.png deleted file mode 100644 index 1755c6e9..00000000 Binary files a/resources/images/item/atk-bow.png and /dev/null differ diff --git a/resources/images/item/atk-catalyst.png b/resources/images/item/atk-catalyst.png deleted file mode 100644 index b5062d3e..00000000 Binary files a/resources/images/item/atk-catalyst.png and /dev/null differ diff --git a/resources/images/item/atk-claymore.png b/resources/images/item/atk-claymore.png deleted file mode 100644 index 53654349..00000000 Binary files a/resources/images/item/atk-claymore.png and /dev/null differ diff --git a/resources/images/item/atk-polearm.png b/resources/images/item/atk-polearm.png deleted file mode 100644 index 165cbc2a..00000000 Binary files a/resources/images/item/atk-polearm.png and /dev/null differ diff --git a/resources/images/item/atk-sword.png b/resources/images/item/atk-sword.png deleted file mode 100644 index be5c3f8f..00000000 Binary files a/resources/images/item/atk-sword.png and /dev/null differ diff --git a/resources/images/item/bg1-o.png b/resources/images/item/bg1-o.png deleted file mode 100644 index 937aca46..00000000 Binary files a/resources/images/item/bg1-o.png and /dev/null differ diff --git a/resources/images/item/bg1.png b/resources/images/item/bg1.png deleted file mode 100644 index 58115989..00000000 Binary files a/resources/images/item/bg1.png and /dev/null differ diff --git a/resources/images/item/bg2-o.png b/resources/images/item/bg2-o.png deleted file mode 100644 index 84b9d88c..00000000 Binary files a/resources/images/item/bg2-o.png and /dev/null differ diff --git a/resources/images/item/bg2.png b/resources/images/item/bg2.png deleted file mode 100644 index cf8e63c2..00000000 Binary files a/resources/images/item/bg2.png and /dev/null differ diff --git a/resources/images/item/bg3-o.png b/resources/images/item/bg3-o.png deleted file mode 100644 index cd2191fb..00000000 Binary files a/resources/images/item/bg3-o.png and /dev/null differ diff --git a/resources/images/item/bg3.png b/resources/images/item/bg3.png deleted file mode 100644 index c7d45782..00000000 Binary files a/resources/images/item/bg3.png and /dev/null differ diff --git a/resources/images/item/bg4-o.png b/resources/images/item/bg4-o.png deleted file mode 100644 index eddbe8a3..00000000 Binary files a/resources/images/item/bg4-o.png and /dev/null differ diff --git a/resources/images/item/bg4.png b/resources/images/item/bg4.png deleted file mode 100644 index 80795471..00000000 Binary files a/resources/images/item/bg4.png and /dev/null differ diff --git a/resources/images/item/bg5-o.png b/resources/images/item/bg5-o.png deleted file mode 100644 index 23bf9fef..00000000 Binary files a/resources/images/item/bg5-o.png and /dev/null differ diff --git a/resources/images/item/bg5.png b/resources/images/item/bg5.png deleted file mode 100644 index 2630db5b..00000000 Binary files a/resources/images/item/bg5.png and /dev/null differ diff --git a/resources/images/item/bg5.psd b/resources/images/item/bg5.psd deleted file mode 100644 index 588f141d..00000000 Binary files a/resources/images/item/bg5.psd and /dev/null differ diff --git a/resources/images/item/cons.png b/resources/images/item/cons.png deleted file mode 100644 index b307ccd5..00000000 Binary files a/resources/images/item/cons.png and /dev/null differ diff --git a/resources/images/item/cons0.png b/resources/images/item/cons0.png deleted file mode 100644 index c38d551d..00000000 Binary files a/resources/images/item/cons0.png and /dev/null differ diff --git a/resources/images/item/crown-o.png b/resources/images/item/crown-o.png deleted file mode 100644 index 177c58e4..00000000 Binary files a/resources/images/item/crown-o.png and /dev/null differ diff --git a/resources/images/item/crown-sr-o.png b/resources/images/item/crown-sr-o.png deleted file mode 100644 index d656167a..00000000 Binary files a/resources/images/item/crown-sr-o.png and /dev/null differ diff --git a/resources/images/item/face.png b/resources/images/item/face.png deleted file mode 100644 index 44625f05..00000000 Binary files a/resources/images/item/face.png and /dev/null differ diff --git a/resources/images/item/fetter.png b/resources/images/item/fetter.png deleted file mode 100644 index 1ccdcf0b..00000000 Binary files a/resources/images/item/fetter.png and /dev/null differ diff --git a/resources/images/item/icon-sr.png b/resources/images/item/icon-sr.png deleted file mode 100644 index e9ab31ae..00000000 Binary files a/resources/images/item/icon-sr.png and /dev/null differ diff --git a/resources/images/item/icon.png b/resources/images/item/icon.png deleted file mode 100644 index 06df16ed..00000000 Binary files a/resources/images/item/icon.png and /dev/null differ diff --git a/resources/images/item/star-ltr.png b/resources/images/item/star-ltr.png deleted file mode 100644 index f0895d62..00000000 Binary files a/resources/images/item/star-ltr.png and /dev/null differ diff --git a/resources/images/item/star.png b/resources/images/item/star.png deleted file mode 100644 index 80d18882..00000000 Binary files a/resources/images/item/star.png and /dev/null differ diff --git "a/resources/images/item/\346\236\253\344\270\271.png" "b/resources/images/item/\346\236\253\344\270\271.png" deleted file mode 100644 index 93b0f8d1..00000000 Binary files "a/resources/images/item/\346\236\253\344\270\271.png" and /dev/null differ diff --git "a/resources/images/item/\347\222\203\346\234\210.png" "b/resources/images/item/\347\222\203\346\234\210.png" deleted file mode 100644 index fc2754b8..00000000 Binary files "a/resources/images/item/\347\222\203\346\234\210.png" and /dev/null differ diff --git "a/resources/images/item/\347\250\273\345\246\273.png" "b/resources/images/item/\347\250\273\345\246\273.png" deleted file mode 100644 index 086a720f..00000000 Binary files "a/resources/images/item/\347\250\273\345\246\273.png" and /dev/null differ diff --git "a/resources/images/item/\350\222\231\345\276\267.png" "b/resources/images/item/\350\222\231\345\276\267.png" deleted file mode 100644 index 0272b710..00000000 Binary files "a/resources/images/item/\350\222\231\345\276\267.png" and /dev/null differ diff --git "a/resources/images/item/\351\241\273\345\274\245.png" "b/resources/images/item/\351\241\273\345\274\245.png" deleted file mode 100644 index 9b36aeb2..00000000 Binary files "a/resources/images/item/\351\241\273\345\274\245.png" and /dev/null differ diff --git a/resources/images/other/star.png b/resources/images/other/star.png deleted file mode 100644 index 1952c991..00000000 Binary files a/resources/images/other/star.png and /dev/null differ diff --git a/resources/images/other/up.1b26ff0c.png b/resources/images/other/up.1b26ff0c.png deleted file mode 100644 index afd568c2..00000000 Binary files a/resources/images/other/up.1b26ff0c.png and /dev/null differ diff --git "a/resources/images/other/\346\221\270.png" "b/resources/images/other/\346\221\270.png" deleted file mode 100644 index ed204973..00000000 Binary files "a/resources/images/other/\346\221\270.png" and /dev/null differ diff --git "a/resources/images/other/\346\221\270.webp" "b/resources/images/other/\346\221\270.webp" new file mode 100644 index 00000000..ec1e466d Binary files /dev/null and "b/resources/images/other/\346\221\270.webp" differ diff --git a/resources/images/talent/bg.png b/resources/images/talent/bg.png deleted file mode 100644 index c37b2cd7..00000000 Binary files a/resources/images/talent/bg.png and /dev/null differ diff --git a/resources/images/talent/talent-anemo.png b/resources/images/talent/talent-anemo.png deleted file mode 100644 index 20debcd5..00000000 Binary files a/resources/images/talent/talent-anemo.png and /dev/null differ diff --git a/resources/images/talent/talent-cryo.png b/resources/images/talent/talent-cryo.png deleted file mode 100644 index 4110aa64..00000000 Binary files a/resources/images/talent/talent-cryo.png and /dev/null differ diff --git a/resources/images/talent/talent-dendro.png b/resources/images/talent/talent-dendro.png deleted file mode 100644 index 273480cc..00000000 Binary files a/resources/images/talent/talent-dendro.png and /dev/null differ diff --git a/resources/images/talent/talent-electro.png b/resources/images/talent/talent-electro.png deleted file mode 100644 index 4c8dc167..00000000 Binary files a/resources/images/talent/talent-electro.png and /dev/null differ diff --git a/resources/images/talent/talent-geo.png b/resources/images/talent/talent-geo.png deleted file mode 100644 index fafdf263..00000000 Binary files a/resources/images/talent/talent-geo.png and /dev/null differ diff --git a/resources/images/talent/talent-hydro.png b/resources/images/talent/talent-hydro.png deleted file mode 100644 index d23347b4..00000000 Binary files a/resources/images/talent/talent-hydro.png and /dev/null differ diff --git a/resources/images/talent/talent-pyro.png b/resources/images/talent/talent-pyro.png deleted file mode 100644 index 7901bd63..00000000 Binary files a/resources/images/talent/talent-pyro.png and /dev/null differ diff --git a/resources/images/talent/talent-quantum.png b/resources/images/talent/talent-quantum.png deleted file mode 100644 index e42af8dc..00000000 Binary files a/resources/images/talent/talent-quantum.png and /dev/null differ diff --git a/resources/images/talent/talent-sr.png b/resources/images/talent/talent-sr.png deleted file mode 100644 index d247c4e2..00000000 Binary files a/resources/images/talent/talent-sr.png and /dev/null differ diff --git "a/resources/images/talent/\344\270\260\351\245\266-s.png" "b/resources/images/talent/\344\270\260\351\245\266-s.png" deleted file mode 100644 index 112fa4fb..00000000 Binary files "a/resources/images/talent/\344\270\260\351\245\266-s.png" and /dev/null differ diff --git "a/resources/images/talent/\344\270\260\351\245\266.png" "b/resources/images/talent/\344\270\260\351\245\266.png" deleted file mode 100644 index 2a87189a..00000000 Binary files "a/resources/images/talent/\344\270\260\351\245\266.png" and /dev/null differ diff --git "a/resources/images/talent/\345\220\214\350\260\220-s.png" "b/resources/images/talent/\345\220\214\350\260\220-s.png" deleted file mode 100644 index d009b79e..00000000 Binary files "a/resources/images/talent/\345\220\214\350\260\220-s.png" and /dev/null differ diff --git "a/resources/images/talent/\345\220\214\350\260\220.png" "b/resources/images/talent/\345\220\214\350\260\220.png" deleted file mode 100644 index 8637f03d..00000000 Binary files "a/resources/images/talent/\345\220\214\350\260\220.png" and /dev/null differ diff --git "a/resources/images/talent/\345\255\230\346\212\244-s.png" "b/resources/images/talent/\345\255\230\346\212\244-s.png" deleted file mode 100644 index 424bab66..00000000 Binary files "a/resources/images/talent/\345\255\230\346\212\244-s.png" and /dev/null differ diff --git "a/resources/images/talent/\345\255\230\346\212\244.png" "b/resources/images/talent/\345\255\230\346\212\244.png" deleted file mode 100644 index 160ed77c..00000000 Binary files "a/resources/images/talent/\345\255\230\346\212\244.png" and /dev/null differ diff --git "a/resources/images/talent/\345\267\241\347\214\216-s.png" "b/resources/images/talent/\345\267\241\347\214\216-s.png" deleted file mode 100644 index 326c68b3..00000000 Binary files "a/resources/images/talent/\345\267\241\347\214\216-s.png" and /dev/null differ diff --git "a/resources/images/talent/\345\267\241\347\214\216.png" "b/resources/images/talent/\345\267\241\347\214\216.png" deleted file mode 100644 index 4d81fb08..00000000 Binary files "a/resources/images/talent/\345\267\241\347\214\216.png" and /dev/null differ diff --git "a/resources/images/talent/\346\231\272\350\257\206-s.png" "b/resources/images/talent/\346\231\272\350\257\206-s.png" deleted file mode 100644 index 92a0eef4..00000000 Binary files "a/resources/images/talent/\346\231\272\350\257\206-s.png" and /dev/null differ diff --git "a/resources/images/talent/\346\231\272\350\257\206.png" "b/resources/images/talent/\346\231\272\350\257\206.png" deleted file mode 100644 index 84596fc1..00000000 Binary files "a/resources/images/talent/\346\231\272\350\257\206.png" and /dev/null differ diff --git "a/resources/images/talent/\346\254\242\346\204\211-s.png" "b/resources/images/talent/\346\254\242\346\204\211-s.png" deleted file mode 100644 index 26c67464..00000000 Binary files "a/resources/images/talent/\346\254\242\346\204\211-s.png" and /dev/null differ diff --git "a/resources/images/talent/\346\257\201\347\201\255-s.png" "b/resources/images/talent/\346\257\201\347\201\255-s.png" deleted file mode 100644 index cda73b2b..00000000 Binary files "a/resources/images/talent/\346\257\201\347\201\255-s.png" and /dev/null differ diff --git "a/resources/images/talent/\346\257\201\347\201\255.png" "b/resources/images/talent/\346\257\201\347\201\255.png" deleted file mode 100644 index f1b4c855..00000000 Binary files "a/resources/images/talent/\346\257\201\347\201\255.png" and /dev/null differ diff --git "a/resources/images/talent/\347\271\201\350\202\262-s.png" "b/resources/images/talent/\347\271\201\350\202\262-s.png" deleted file mode 100644 index 50ff7291..00000000 Binary files "a/resources/images/talent/\347\271\201\350\202\262-s.png" and /dev/null differ diff --git "a/resources/images/talent/\350\231\232\346\227\240-s.png" "b/resources/images/talent/\350\231\232\346\227\240-s.png" deleted file mode 100644 index 52ed747b..00000000 Binary files "a/resources/images/talent/\350\231\232\346\227\240-s.png" and /dev/null differ diff --git "a/resources/images/talent/\350\231\232\346\227\240.png" "b/resources/images/talent/\350\231\232\346\227\240.png" deleted file mode 100644 index a5ec6c4d..00000000 Binary files "a/resources/images/talent/\350\231\232\346\227\240.png" and /dev/null differ diff --git "a/resources/images/talent/\350\256\260\345\277\206-s.png" "b/resources/images/talent/\350\256\260\345\277\206-s.png" deleted file mode 100644 index 51c7edf2..00000000 Binary files "a/resources/images/talent/\350\256\260\345\277\206-s.png" and /dev/null differ diff --git a/resources/template/layout/default.html b/resources/template/layout/default.html index 78c58df1..e5308e98 100644 --- a/resources/template/layout/default.html +++ b/resources/template/layout/default.html @@ -4,17 +4,53 @@ - - - - + {{block 'css'}}{{/block}}
{{block 'main'}}{{/block}} - +
diff --git a/resources/template/layout/elem.html b/resources/template/layout/elem.html deleted file mode 100644 index 06e816d5..00000000 --- a/resources/template/layout/elem.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - {{block 'css'}} - {{/block}} - -{{set elemCls = {火:'pyro',冰:'cryo',风:'anemo',雷:'electro',量子:'quantum',虚数:'geo',物理:'sr', }[element||elem] || element || -elem || 'hydro' }} - - -
- {{block 'main'}}{{/block}} - -
- - - \ No newline at end of file diff --git a/resources/template/user/images/uid-list-bg.webp b/resources/template/user/images/uid-list-bg.webp new file mode 100644 index 00000000..60c500f1 Binary files /dev/null and b/resources/template/user/images/uid-list-bg.webp differ diff --git a/resources/template/user/login-qrcode.html b/resources/template/user/login-qrcode.html deleted file mode 100644 index 99faaf5b..00000000 --- a/resources/template/user/login-qrcode.html +++ /dev/null @@ -1,40 +0,0 @@ -{{extend defaultLayout}} -{{block 'css'}} - -{{/block}} -{{block 'main'}} -{{each Qrsvg qr}} -
{{@ qr}}
-{{/each}} -
- 免责声明:请勿随意扫码,谁触发谁扫码,bot仅提供功能。
如果恶意抢码导致账号出问题的请自行承担后果 -
-{{/block}} \ No newline at end of file diff --git a/resources/template/user/uid-list.css b/resources/template/user/uid-list.css index 2231d9a9..c8d4416a 100644 --- a/resources/template/user/uid-list.css +++ b/resources/template/user/uid-list.css @@ -1,14 +1,14 @@ body { - width: 450px; + width: 350px; } .container { - width: 450px; + padding: 20px 10px 40px 0; + background-image: url('./images/uid-list-bg.webp'); } nobr { - font-size: 12px; - background: #000; + background: #323131; color: #d3bc8e; display: inline-block; padding: 1px 2px; @@ -16,6 +16,10 @@ nobr { margin: 0 1px; } +.uid-list { + margin-left: 10px; +} + .uid-list .game-cont { background: rgba(255, 255, 255, 0.65); margin: 0 0 10px; @@ -24,268 +28,178 @@ nobr { } .uid-list .game-cont .game-title { - font-size: 16px; + font-size: 14px; + font-weight: bold; background: rgba(255, 255, 255, 0.8); - padding: 8px 15px 5px; -} - -.uid-list .game-cont .game-title strong { - margin-right: 15px; -} - -.uid-list .game-cont .game-title span { - font-size: 12px; - color: #666; - float: right; -} - -.uid-list .game-cont .game-title nobr { - background: none; - font-size: 12px; - color: #3a2702; - display: inline-block; - padding: 1px 2px; - border-radius: 3px; - margin: 0 1px; -} - -.uid-list .game-cont .cont-body { - background: none; - padding: 0; + padding: 5px 15px 5px; } .uid-list .game-ul { padding: 8px; } -.uid-list .game-ul .no-uid { - font-size: 12px; - text-align: center; -} - -.uid-list .game-idx { - height: 50px; - padding: 20px 0 10px; - margin-right: 5px; +.uid-list .game-ul>* { + margin-top: 3px; + margin-bottom: 3px; } -.uid-list .game-idx span { - display: block; - width: 18px; - height: 22px; - border-radius: 6px; - background: #fff; +.uid-list .game-ul .no-uid { + font-size: 12px; text-align: center; - font-size: 14px; - line-height: 22px; } -.uid-list .game-bar { - height: 64px; - line-height: 30px; - margin: 0; - border-radius: 33px; - background: right top no-repeat #f0ece4; - background-size: auto 100%; - width: 375px; - position: relative; -} - -.uid-list .game-inner { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; +.game-li-gs, +.game-li-sr, +.game-li-zzz { display: flex; - background: -webkit-gradient(linear, left top, right top, from(rgba(240, 236, 228, 0.6)), color-stop(rgba(240, 236, 228, 0.6)), color-stop(rgba(240, 236, 228, 0)), to(rgba(240, 236, 228, 0))); - background: -webkit-linear-gradient(left, rgba(240, 236, 228, 0.6), rgba(240, 236, 228, 0.6), rgba(240, 236, 228, 0), rgba(240, 236, 228, 0)); - background: linear-gradient(to right, rgba(240, 236, 228, 0.6), rgba(240, 236, 228, 0.6), rgba(240, 236, 228, 0), rgba(240, 236, 228, 0)); - padding: 4px; - border-radius: 33px; -} - -.uid-list .game-inner .face { - width: 56px; - height: 56px; - border-radius: 30px; - -webkit-box-shadow: 0 0 1px #000, 0 0 5px rgba(0, 0, 0, 0.5); - box-shadow: 0 0 1px #000, 0 0 5px rgba(0, 0, 0, 0.5); - border: 2px solid #fff; - overflow: hidden; + flex-direction: column; + padding: 5px 5px 8px 5px; + border-radius: 8px; background-size: cover; + position: relative; } -.uid-list .game-inner .face span { - display: block; - width: 64px; - height: 64px; - background-size: auto 100%; - background-repeat: no-repeat; +.game-li-gs { + background-image: url('../../images/default_banner/gs.webp'); } -.uid-list .game-inner .info { - padding: 4px 10px; - line-height: 18px; - color: #414e64; +.game-li-sr { + background-image: url('../../images/default_banner/sr.webp'); } -.uid-list .game-inner .info div.shadow { - position: relative; - -webkit-text-stroke: 2px #fff; +.game-li-zzz { + background-image: url('../../images/default_banner/zzz.webp'); } -.uid-list .game-inner .info div.shadow span { - font-weight: normal; - display: block; +.game-li-gs.active:after, +.game-li-sr.active:after, +.game-li-zzz.active:after { + content: ''; position: absolute; - -webkit-text-stroke: 0px #fff; - left: 0; - top: 0; + top: 5px; + right: 5px; + width: 30px; + height: 30px; + border-radius: 50%; + border: 2px solid #ffffff; + background: url('../../images/icon/check.webp') center center no-repeat #4a5366; + background-size: 70% auto; } -.uid-list .game-inner .info .uid-info { - height: 25px; - font-size: 24px; - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; +.game-li-info { display: flex; - margin-top: 5px; + flex-wrap: nowrap; } -.uid-list .game-inner .info .uid-info .uid { - font-weight: normal; - display: block; - padding-right: 8px; +.game-idx { + width: 20px; + height: 20px; + line-height: 15px; + font-size: 14px; + font-weight: bold; + text-align: center; + border-radius: 40%; + background: #fff; + border: 3px solid #6ec4de; + color: #323131; + text-shadow: 1px 1px 1px #e9d375; + margin-top: 8px; + margin-right: 5px; } -.uid-list .game-inner .info .uid-info .type { - width: 35px; - font-size: 12px; - font-weight: normal; - background: #4a5366; - height: 18px; - display: block; - text-align: center; - border-radius: 4px; - color: #fff; - -webkit-transform: scale(0.9); - transform: scale(0.9); +.game-face { + width: 36px; + height: 36px; + margin-right: 5px; + border-radius: 50%; + border: 2px solid #ffffff; + background-color: #cccbc9; + background-size: contain; } -.uid-list .game-inner .info .uid-info .type.sk { - background: #e75a09; - color: #3a2702; - font-weight: bold; - -webkit-box-shadow: 0 0 3px 0 #000; - box-shadow: 0 0 3px 0 #000; +.game-base { + color: #ffffff; + font-size: 14px; } -.uid-list .game-inner .info .uid-info .type.ck { - background: #d3bc8e; - color: #3a2702; - font-weight: bold; - -webkit-box-shadow: 0 0 3px 0 #000; - box-shadow: 0 0 3px 0 #000; +.game-base span { + display: flex; + flex-wrap: nowrap; } -.uid-list .game-inner .info .uid-info .type.reg { - background: #666; +.game-base span>* { + margin-right: 5px; } -.uid-list .game-inner .info .detail { - font-size: 14px; - text-shadow: 0 0 2px #fff; +.game-base span:last-child { + font-size: 10px; + margin-top: 2px; + color: #ffffffa9; } -.uid-list .game-inner .info .detail .no-info { - color: #555; - font-size: 12px; - text-shadow: 0 0 1px #fff; +.game-base div.shadow { + position: relative; + -webkit-text-stroke: 2px #393838; } -.uid-list .game-inner:after { +.game-base div.shadow span { + font-size: 14px; + font-weight: normal; display: block; - content: ""; - width: 36px; - height: 36px; - border-radius: 50%; - border: 2px solid #ece5d8; - opacity: 0; - -webkit-box-shadow: 0 0 1px #000, 0 0 5px rgba(0, 0, 0, 0.5); - box-shadow: 0 0 1px #000, 0 0 5px rgba(0, 0, 0, 0.5); position: absolute; - right: 13px; - top: 12px; -} - -.uid-list .game-li { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - margin-bottom: 10px; -} - -.uid-list .game-li:last-child { - margin-bottom: 0; + color: #ffffff; + -webkit-text-stroke: 0px #fff; + left: 0px; + top: -2px; } -.uid-list .game-li.active .game-bar { - -webkit-box-shadow: 0 0 1px 1px #fff, 0 0 5px 2px #d3bc8e; - box-shadow: 0 0 1px 1px #fff, 0 0 5px 2px #d3bc8e; +.game-type { + width: 20px; + padding: 1px; + font-size: 8px; + font-weight: bold; + border-radius: 3px; + box-shadow: 0 0 3px 0 #000; + text-align: center; + line-height: 13px; + color: #ffffff; } -.uid-list .game-li.active .game-inner:after { - opacity: 1; - background: url('../../imgs/icon/check.png') center center no-repeat #4a5366; - background-size: 70% auto; +.game-type.reg { + color: #ffffffa9; + background: #666; } -.uid-list .game-li.active .game-idx span { +.game-type.ck { background: #d3bc8e; - color: #3a2702; - -webkit-box-shadow: 0 0 1px 1px #fff, 0 0 5px 2px #d3bc8e; - box-shadow: 0 0 1px 1px #fff, 0 0 5px 2px #d3bc8e; } -.tips { - border-radius: 10px; - font-size: 12px; - padding: 8px 12px 8px 24px; - color: #fff; - margin-bottom: 10px; - background: rgba(0, 0, 0, 0.4); -} - -.tips li { - padding: 2px 0; +.game-type.sk { + background: #e75a09; } -.tips nobr { - font-size: 12px; - background: #000; - color: #d3bc8e; - display: inline-block; - padding: 1px 2px; - border-radius: 3px; - margin: 0 1px; +.game-li-info-card { + height: 45px; + display: flex; + align-items: center; + justify-content: center; } -.ban { - margin-top: 5px; - border-radius: 10px; - font-size: 12px; - padding: 4px 4px 4px 4px; - color: #fff; - background: rgba(0, 0, 0, 0.4); +.game-li-info-card .card-list { + width: 95%; + height: 75%; + display: flex; + flex-wrap: nowrap; + border-radius: 5px; + background-color: #2625256f; + backdrop-filter: blur(3px); + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); } -.ban nobr { - font-size: 11px; - background: #000; - color: #d3bc8e; - display: inline-block; - padding: 1px 2px; - border-radius: 3px; - margin: 2px 1px; +.change-uid { + font-size: 8px; + color: #ffffff; + position: absolute; + bottom: -2px; + right: 4px; } \ No newline at end of file diff --git a/resources/template/user/uid-list.html b/resources/template/user/uid-list.html index 26dfc029..176992be 100644 --- a/resources/template/user/uid-list.html +++ b/resources/template/user/uid-list.html @@ -1,87 +1,57 @@ -{{extend elemLayout}} +{{extend defaultLayout}} {{block 'css'}} {{/block}} {{block 'main'}} -{{ set gameMap = {gs:'#gs',sr:'#sr',zzz:'#zzz'} }}
{{each uids game}} - {{set mark = gameMap[game.key]}}
-
- {{mark}}{{game.name}} - 使用{{mark}}uid1切换uid -
+
#{{game.key}} - [{{game.name}}UID列表]
{{if game.uidList?.length > 0 }} {{each game.uidList uid idx}} -
-
- {{idx+1}} +
+
+
{{idx+1}}
+
+
+ +
{{uid.name}}
+
{{uid.uid}}{{uid.uid}}
+
+ +
{{uid.region}}
+ {{if uid.level>0}} +
{{uid.level}}级
+ {{/if}} +
+ {{(uid.type==='ck'||uid.type==='all')?'CK':'绑定'}}
+ {{if (uid.type==='sk'||uid.type==='all')}} +
SK
+ {{/if}} +
+
-
-
-
-
-
-
{{uid.uid}}{{uid.uid}}
-
- {{(uid.type==='ck'||uid.type==='all')?'CK':'绑定'}}
- {{if (uid.type==='sk'||uid.type==='all')}} -
SK
- {{/if}} -
-
- {{if uid.name && uid.level}} -
{{uid.name}} Lv.{{uid.level}}
- {{else}} -
暂无uid信息,可通过更新面板获取信息
- {{/if}} -
-
+ {{if uid.main&&uid.card}} +
+
+
+ {{/if}} +
使用#{{game.key}}uid{{idx+1}}切换此UID
{{/each}} {{else}} -
暂无uid,请发送CK或通过 - {{mark}}绑定123456789 - 来绑定UID +
+ 请#扫码登录或通过#{{game.key}}绑定123456789来绑定UID
{{/if}} - {{if game.banList?.length > 0}} -
    - {{each game.banList uid}} - ×{{uid}} - {{/each}} -
- {{/if}}
-
{{/each}}
- -
    -
  • 原神及通用命令以#gs开头,星铁命令以#sr开头,绝区零命令以#zzz开头。
  • -
  • 绑定Cookie或Stoke请使用#扫码登录
  • -
  • - {{mark}}删除uid1 - 删除指定序号uid - - {{mark}}绑定123456789 - 绑定对应uid -
  • -
  • - {{mark}}我的ck - 查看ck信息 - - {{mark}}删除ck - 删除当前ck -
  • -
{{/block}} \ No newline at end of file diff --git a/src/apps/UserBing.ts b/src/apps/UserBing.ts index 138c5d34..524a2a25 100644 --- a/src/apps/UserBing.ts +++ b/src/apps/UserBing.ts @@ -1,10 +1,10 @@ import { MysReq, MysUtil, fetchQRcode, getTokenByGameToken, getUserFullInfo, queryQRcode } from "@/mys" import { BasePlayer } from "@/panel" -import { BingUIDType, ConfigName, GameList, MysUserDBCOLUMNS, UidWithType } from "@/types" +import { BingUIDType, GameList, MysUserDBCOLUMNS, UidWithType } from "@/types" import { MysUser, User } from "@/user" -import { BaseModel, Cfg, GamePathType, getSimpleQrOption, SimpleQr, SimpleQrType } from "@/utils" +import { BaseModel, GamePathType } from "@/utils" import { common, ImageElement, karin, KarinMessage, logger, segment } from "node-karin" -import lodash from 'node-karin/lodash' +import QR from 'qrcode' interface uidInfo { key: GameList @@ -13,7 +13,7 @@ interface uidInfo { name?: string level?: number face?: string - banner?: string + region: string })[] banList: UidWithType[] } @@ -28,7 +28,7 @@ const getLtuidInfo = (mysUser: MysUser, option: { ck?: boolean, sk?: boolean } = return '' }).join('\n') - return segment.text(msg + (option.ck ? `\n【CK】:${mysUser.cookie}` : '') + (option.sk ? `\n【SK】:${mysUser.stoken}` : '')) + return msg + (option.ck ? `\n【CK】:${mysUser.cookie}` : '') + (option.sk ? `\n【SK】:${mysUser.stoken}` : '') } const showUid = async (e: KarinMessage) => { @@ -49,7 +49,8 @@ const showUid = async (e: KarinMessage) => { uidList.list.forEach((v) => { const player = BasePlayer.create(v.uid, game) uidInfo.uidList.push({ - ...v, ...player.getData(['name', 'level', 'face', 'banner']) + region: MysUtil.getServerByUid(v.uid, game).name, + ...v, ...player.getData(['name', 'level', 'Face']) }) }) uids.push(uidInfo) @@ -125,16 +126,16 @@ const bingCookie = async (e: KarinMessage, cookie?: string, mysUser?: MysUser, t e.reply(`绑定Cookie失败:${userFullInfo?.message || 'Cookie错误'}`) return false } + } - const user = await User.create(e.user_id, GameList.Gs) - await user.addMysUser(mysUser, type) - await mysUser.save() + const user = await User.create(e.user_id, GameList.Gs) + await user.addMysUser(mysUser, type) + await mysUser.save() - logger.mark(`${e.logFnc} 保存Cookie成功 [ltuid:${mysUser.ltuid}]`) + logger.mark(`${e.logFnc} 保存Cookie成功 [ltuid:${mysUser.ltuid}]`) - e.reply(['绑定Cookie成功', getLtuidInfo(mysUser)].join('\n')) - return true - } + e.reply(['绑定Cookie成功', getLtuidInfo(mysUser)].join('\n')) + return true } /** 绑定米游社Stoken */ @@ -145,7 +146,7 @@ const bingStoken = async (e: KarinMessage, stoken?: string) => { } const stokenMap = MysUtil.getCookieMap(stoken) - if (!stokenMap.stoken || !stokenMap.stuid || !stokenMap.ltoken || !stokenMap.mid) { + if (!stokenMap.stoken || !stokenMap.stuid || !(stokenMap.ltoken || stokenMap.mid)) { e.reply('发送Stoken不完整,请使用#扫码登录') return false } @@ -164,6 +165,8 @@ const bingStoken = async (e: KarinMessage, stoken?: string) => { return false } + await mysUser.save() + const sendMsg = [] const _reply = e.reply e.reply = (msg) => sendMsg.push(msg) as any @@ -227,6 +230,32 @@ export const DelBingUid = karin.command( { name: 'MysTool-解绑UID', priority: 0 } ) +/** 切换UID */ +export const setMainUid = karin.command( + new RegExp(`^(${reg})(我的)?uid[0-9]{0,2}$`, 'i'), + async (e) => { + const game = MysUtil.getGameByMsg(e.msg) + const idx = e.msg.match(/[0-9]{1,2}/g) + + if (idx && idx[0]) { + const user = await User.create(e.user_id, game.key) + const uidList = user.getUidList() + + const _idx = Number(idx[0]) + if (_idx <= uidList.length) { + await user.setMainUid({ uid: uidList[_idx - 1] }) + + await showUid(e) + return true + } + } + + e.reply(`${game.name}uid序号输入错误`) + return true + }, + { name: 'MysTool-切换UID', priority: 0 } +) + /** 查询绑定的UID列表 */ export const ShowBingUidList = karin.command( new RegExp(`^(${reg})(我的)?uid$`, 'i'), @@ -271,7 +300,7 @@ export const DelCookieOrStoken = karin.command( const _idx = Number(idx[0]) const uidList = user.getUidList() if (_idx > uidList.length) { - e.reply('序号输入错误') + e.reply('UID序号输入错误', { at: true }) return true } uid = uidList[_idx - 1] @@ -282,12 +311,12 @@ export const DelCookieOrStoken = karin.command( return true } - const isCK = /c(oo)?k(ie)?/.test(e.msg) + const isCK = /c(oo)?k(ie)?/i.test(e.msg) if (!user[isCK ? 'hasCk' : 'hasSk'](uid)) { e.reply(`UID:${uid}暂未绑定${isCK ? 'Cookie' : 'Stoke'}`, { at: true }) return true } - await user.setUidType({ uid, type: BingUIDType[isCK ? 'ck' : 'sk'] }) + await user.setUidType({ uid, type: BingUIDType[isCK ? 'sk' : 'ck'] }) e.reply(`已删除UID:${uid}绑定的${isCK ? 'Cookie' : 'Stoke'}`, { at: true }) return true @@ -312,7 +341,7 @@ export const ShowMyCookieAndStoken = karin.command( } const sendMsg = mysUsers.map(mysUser => { - return getLtuidInfo(mysUser, { ck: true, sk: true }) + return segment.text(getLtuidInfo(mysUser, { ck: true, sk: true })) }) const content = common.makeForward(sendMsg, e.self_id, e.bot.account.name) @@ -347,25 +376,7 @@ export const MiHoYoLoginQRCode = karin.command( return true } - const base = new BaseModel(GamePathType.Core, e) - base.model = 'user/login-qrcode' - - const config = Cfg.getConfig(ConfigName.config, GamePathType.Core) - let qrbtf; let style: SimpleQrType = SimpleQrType.base - if (config?.qrbtf) { - const qr = Cfg.getConfig(ConfigName.qrbtf, GamePathType.Core) - const option = lodash.sample(qr.styles) - if (option?.style && SimpleQr[option.style]) { - style = option.style - qrbtf = getSimpleQrOption(option.style, QRcode.data.url, option) - } - } - if (!qrbtf) { - qrbtf = getSimpleQrOption(SimpleQrType.base, QRcode.data.url, { style: SimpleQrType.base }) - } - const image = await base.renderImg({ - QRSVGS: [SimpleQr[style](qrbtf)] - }, { nowk: true }) + const image = segment.image((await QR.toDataURL(QRcode.data.url)).replace('data:image/png;base64,', 'base64://')) if (!image) { QRCodes.delete(e.user_id) e.reply('生成二维码失败、请稍后再试', { at: true }) @@ -401,7 +412,7 @@ export const MiHoYoLoginQRCode = karin.command( } if (res.data.stat === 'Confirmed') { - data = JSON.parse(res.data.payload.raw) as { uid: number, token: string } + data = JSON.parse(res.data.payload.raw) as { uid: string, token: string } break } } catch (err) { @@ -414,7 +425,7 @@ export const MiHoYoLoginQRCode = karin.command( return true } - const res = await getTokenByGameToken(mysReq, { account_id: Number(data.uid), game_token: data.token }) + const res = await getTokenByGameToken(mysReq, { account_id: parseInt(data.uid), game_token: data.token }) if (!res) { e.reply('获取Token失败', { at: true }) QRCodes.delete(e.user_id) @@ -436,7 +447,6 @@ export const UpdataCookie = karin.command( const user = await User.create(e.user_id, GameList.Gs) const sendMsg: any[] = [] - const _reply = e.reply e.reply = (msg) => sendMsg.push(msg) as any for (const stuid of user.stuids) { diff --git a/src/apps/exchange.ts b/src/apps/exchange.ts index 9b523f5d..4ef23a6c 100644 --- a/src/apps/exchange.ts +++ b/src/apps/exchange.ts @@ -25,7 +25,6 @@ export class exchange extends Plugin { async getCode() { const game = MysUtil.getGameByMsg(this.e.msg) - if (!game) return false let msg = [] this.redisKey = `${PluginName}:${game.key}:Exchange:` diff --git a/src/apps/gachaLog.ts b/src/apps/gachaLog.ts index 44495746..d0bd5479 100644 --- a/src/apps/gachaLog.ts +++ b/src/apps/gachaLog.ts @@ -98,12 +98,16 @@ export const dealGachaUrl = karin.command( } const check = await checkUrl(e, res) - if (check) return e.reply(check) + if (check) { + e.reply(check) + return true + } const key = `mys.${game}.gachaLog` if (handler.has(key)) { e.reply("链接发送成功,数据获取中……") - return await handler.call(key, { e, params }) + await handler.call(key, { e, params }) + return true } return false }, diff --git a/src/mys/MysApi.ts b/src/mys/MysApi.ts index 4cb30ab1..aaa9f04e 100644 --- a/src/mys/MysApi.ts +++ b/src/mys/MysApi.ts @@ -1,4 +1,4 @@ -import { GameList, GameRegion } from '@/types' +import { GameList, GameRegions } from '@/types' import { defineMysApi, BaseMysResData } from './define' import { ActionHeader, CookieHeader, NoHeader, PassportHeader, StokenHeader } from './headers' import { MysTool } from './MysTool' @@ -15,24 +15,22 @@ export const getDeviceFp = defineMysApi< { urlKey: 'get-device-fp', url: (mysReq, data) => `${MysTool[mysReq.hoyolab ? 'os_public_data_api' : 'public_data_api']}device-fp/api/getFp`, - body: (mysReq, data) => { - return { - seed_id: lodash.sampleSize('0123456789abcdef', 16), - device_id: mysReq.device_id, - seed_time: new Date().getTime() + '', - ...(mysReq.hoyolab ? { - platform: '5', - ext_fields: `{"userAgent":"Mozilla/5.0 (Linux; Android 11; J9110 Build/55.2.A.4.332; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/124.0.6367.179 Mobile Safari/537.36 miHoYoBBSOversea/2.55.0","browserScreenSize":"387904","maxTouchPoints":"5","isTouchSupported":"1","browserLanguage":"zh-CN","browserPlat":"Linux aarch64","browserTimeZone":"Asia/Shanghai","webGlRender":"Adreno (TM) 640","webGlVendor":"Qualcomm","numOfPlugins":"0","listOfPlugins":"unknown","screenRatio":"2.625","deviceMemory":"4","hardwareConcurrency":"8","cpuClass":"unknown","ifNotTrack":"unknown","ifAdBlock":"0","hasLiedLanguage":"0","hasLiedResolution":"1","hasLiedOs":"0","hasLiedBrowser":"0","canvas":"${MysUtil.getSeedId(64)}","webDriver":"0","colorDepth":"24","pixelRatio":"2.625","packageName":"unknown","packageVersion":"2.27.0","webgl":"${MysUtil.getSeedId(64)}"}`, - app_name: mysReq.game_biz, - device_fp: '38d7f2364db95' - } : { - platform: '1', - ext_fields: `{"proxyStatus":"0","accelerometer":"-0.159515x-0.830887x-0.682495","ramCapacity":"3746","IDFV":"${mysReq.device_id}","gyroscope":"-0.191951x-0.112927x0.632637","isJailBreak":"0","model":"iPhone12,5","ramRemain":"115","chargeStatus":"1","networkType":"WIFI","vendor":"--","osVersion":"17.0.2","batteryStatus":"50","screenSize":"414×896","cpuCores":"6","appMemory":"55","romCapacity":"488153","romRemain":"157348","cpuType":"CPU_TYPE_ARM64","magnetometer":"-84.426331x-89.708435x-37.117889"}`, - app_name: 'bbs_cn', - device_fp: '38d7ee834d1e9' - }) - } - }, + body: (mysReq, data) => ({ + seed_id: lodash.sampleSize('0123456789abcdef', 16), + device_id: mysReq.device_id, + seed_time: new Date().getTime() + '', + ...(mysReq.hoyolab ? { + platform: '5', + ext_fields: `{"userAgent":"Mozilla/5.0 (Linux; Android 11; J9110 Build/55.2.A.4.332; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/124.0.6367.179 Mobile Safari/537.36 miHoYoBBSOversea/2.55.0","browserScreenSize":"387904","maxTouchPoints":"5","isTouchSupported":"1","browserLanguage":"zh-CN","browserPlat":"Linux aarch64","browserTimeZone":"Asia/Shanghai","webGlRender":"Adreno (TM) 640","webGlVendor":"Qualcomm","numOfPlugins":"0","listOfPlugins":"unknown","screenRatio":"2.625","deviceMemory":"4","hardwareConcurrency":"8","cpuClass":"unknown","ifNotTrack":"unknown","ifAdBlock":"0","hasLiedLanguage":"0","hasLiedResolution":"1","hasLiedOs":"0","hasLiedBrowser":"0","canvas":"${MysUtil.getSeedId(64)}","webDriver":"0","colorDepth":"24","pixelRatio":"2.625","packageName":"unknown","packageVersion":"2.27.0","webgl":"${MysUtil.getSeedId(64)}"}`, + app_name: mysReq.game_biz, + device_fp: '38d7f2364db95' + } : { + platform: '1', + ext_fields: `{"proxyStatus":"0","accelerometer":"-0.159515x-0.830887x-0.682495","ramCapacity":"3746","IDFV":"${mysReq.device_id}","gyroscope":"-0.191951x-0.112927x0.632637","isJailBreak":"0","model":"iPhone12,5","ramRemain":"115","chargeStatus":"1","networkType":"WIFI","vendor":"--","osVersion":"17.0.2","batteryStatus":"50","screenSize":"414×896","cpuCores":"6","appMemory":"55","romCapacity":"488153","romRemain":"157348","cpuType":"CPU_TYPE_ARM64","magnetometer":"-84.426331x-89.708435x-37.117889"}`, + app_name: 'bbs_cn', + device_fp: '38d7ee834d1e9' + }) + }), header: CookieHeader, noFp: true } @@ -70,12 +68,10 @@ export const getTokenByGameToken = defineMysApi< { urlKey: 'getTokenByGameToken', url: (mysReq, data) => `${MysTool.pass_api}account/ma-cn-session/app/getTokenByGameToken`, - body: (mysReq, data) => { - return { - account_id: data.account_id, - game_token: data.game_token - } - }, + body: (mysReq, data) => ({ + account_id: data.account_id, + game_token: data.game_token + }), header: PassportHeader, noFp: true } @@ -164,13 +160,11 @@ export const changeGameRoleByDefault = defineMysApi< { urlKey: 'changeGameRoleByDefault', url: (mysReq, data) => `${MysTool.new_web_api}binding/api/changeGameRoleByDefault`, - body: (mysReq, data) => { - return { - action_ticket: data.action_ticket, - game_biz: data.game_biz, - game_uid: data.game_uid - } - }, + body: (mysReq, data) => ({ + action_ticket: data.action_ticket, + game_biz: data.game_biz, + game_uid: data.game_uid + }), header: ActionHeader, noFp: true } @@ -204,9 +198,10 @@ export const fetchQRcode = defineMysApi< { urlKey: 'fetchQRcode', url: (mysReq, data) => `${MysTool.hk4e_sdk_api}hk4e_cn/combo/panda/qrcode/fetch`, - body: (mysReq, data) => { - return { app_id: MysTool.app_id, device: data.device } - }, + body: (mysReq, data) => ({ + app_id: MysTool.app_id, + device: data.device + }), header: NoHeader, noFp: true } @@ -226,9 +221,11 @@ export const queryQRcode = defineMysApi< { urlKey: 'queryQRcode', url: (mysReq, data) => `${MysTool.hk4e_sdk_api}hk4e_cn/combo/panda/qrcode/query`, - body: (mysReq, data) => { - return { app_id: MysTool.app_id, device: data.device, ticket: data.ticket } - }, + body: (mysReq, data) => ({ + app_id: MysTool.app_id, + device: data.device, + ticket: data.ticket + }), header: NoHeader, noFp: true } @@ -249,9 +246,7 @@ export const miyolive_index = defineMysApi< { urlKey: 'miyolive_index', url: (mysReq, data) => `${MysTool.web_api}event/miyolive/index`, - header: (mysReq, options) => { - return { 'x-rpc-act_id': options!.reqData!.actid } - }, + header: (mysReq, options) => ({ 'x-rpc-act_id': options!.reqData!.actid }), noFp: true } ) @@ -270,9 +265,7 @@ export const miyolive_code = defineMysApi< { urlKey: 'miyolive_code', url: (mysReq, data) => `${MysTool.web_api}event/miyolive/refreshCode?version=${data.code_ver}&time=${Math.floor(Date.now() / 1000)}`, - header: (mysReq, options) => { - return { 'x-rpc-act_id': options!.reqData!.actid } - }, + header: (mysReq, options) => ({ 'x-rpc-act_id': options!.reqData!.actid }), noFp: true } ) @@ -309,14 +302,12 @@ export const genAuthKey = defineMysApi< { urlKey: 'genAuthKey', url: (mysReq, data) => `${MysTool.web_api}binding/api/genAuthKey`, - body: (mysReq, data) => { - return { - auth_appid: data.auth_appid, - game_biz: mysReq.game_biz, - game_uid: mysReq.uid, - region: mysReq.server, - } - }, + body: (mysReq, data) => ({ + auth_appid: data.auth_appid, + game_biz: mysReq.game_biz, + game_uid: mysReq.uid, + region: mysReq.server, + }), header: (mysReq, options) => { return { ...StokenHeader(mysReq), @@ -331,7 +322,7 @@ export const genAuthKey = defineMysApi< export const getGachaLog = defineMysApi< BaseMysResData & { data: { - region: GameRegion + region: GameRegions[GameList] } }, { authkey: string, gacha_type: number, page: number, end_id: number } @@ -351,4 +342,31 @@ export const getGachaLog = defineMysApi< }, header: NoHeader, noFp: true -}) \ No newline at end of file +}) + +export const getGameRecordCard = defineMysApi< + BaseMysResData & { + data: { + list: { + game_role_id: string + nickname: string + region: GameRegions[GameList] + level: number + data: { + name: string + value: string + }[] + }[] + } + } +>( + { + urlKey: 'getGameRecordCard', + url: (mysReq, data) => `${MysTool[mysReq.hoyolab ? 'os_record_api' : 'record_api']}game_record/card/api/getGameRecordCard?uid=${mysReq.mysUserInfo!.ltuid}`, + query: (mysReq, data) => `uid=${mysReq.mysUserInfo!.ltuid}`, + header: ActionHeader, + noFp: true + }, + false, + true +) \ No newline at end of file diff --git a/src/mys/MysInfo.ts b/src/mys/MysInfo.ts index 9c516fb3..c8bf2fe9 100644 --- a/src/mys/MysInfo.ts +++ b/src/mys/MysInfo.ts @@ -44,16 +44,6 @@ export class MysInfo { } } - setCkInfo(mysUser: MysUser, owner: boolean = false) { - this.ckInfo = { - type: mysUser.type, - cookie: mysUser.cookie, - stoken: mysUser.stoken, - device: mysUser.device, - owner: owner - } - } - /** 获取ck绑定的uid */ async getSelfUid(type: BingUIDType) { const at = (this.e!.at || [])[0] @@ -80,7 +70,7 @@ export class MysInfo { } this.mysUser = user.getMysUserByUid() - this.setCkInfo(this.mysUser, true) + this.ckInfo = { ...this.mysUser.getMysUserInfo(), owner: true } return user.uid } @@ -106,7 +96,7 @@ export class MysInfo { const mysUser = await MysUser.getByQueryUid(uid, this.game) if (mysUser) { this.mysUser = mysUser - this.setCkInfo(this.mysUser) + this.ckInfo = { ...mysUser.getMysUserInfo(), owner: false } } return undefined } diff --git a/src/mys/MysReq.ts b/src/mys/MysReq.ts index a77c1f31..b4e8c5ac 100644 --- a/src/mys/MysReq.ts +++ b/src/mys/MysReq.ts @@ -168,7 +168,7 @@ export class MysReq{ async cache(res: any, cacheKey: string, cd: number) { if (!res || res.retcode !== 0) return - redis.setEx(cacheKey, cd, JSON.stringify(res)) + redis.setEx(cacheKey, cd, JSON.stringify({ ...res, isCache: true })) } checkstatus(err: any, type: string) { diff --git a/src/mys/MysTool.ts b/src/mys/MysTool.ts index a59bcbca..d0701b16 100644 --- a/src/mys/MysTool.ts +++ b/src/mys/MysTool.ts @@ -1,4 +1,4 @@ -import { GameList, GsRegin, SrRegin, ZzzRegin, GameRegion } from "@/types" +import { GameList, GsRegin, SrRegin, ZzzRegin, GameRegions } from "@/types" const app_version = { cn: '2.70.1', os: '1.5.0' } const app_id = 2 //崩三 1 未定 2 原神 4 崩二 7 崩铁 8 绝区零 12 @@ -53,7 +53,7 @@ const game_biz = { zzz: ['nap_cn', 'nap_global'] } -function setRegion(regions: GameRegion[]) { +function setRegion(regions: GameRegions[g][]) { const names = ['美服', '欧服', '亚服', '港澳台服'] return regions.map((region, idx) => { return { region, name: names[idx], os: true } diff --git a/src/mys/MysUtil.ts b/src/mys/MysUtil.ts index 8b6268c1..efecfcf3 100644 --- a/src/mys/MysUtil.ts +++ b/src/mys/MysUtil.ts @@ -1,16 +1,16 @@ -import { GameKeyAndName, GameList, GameNames, GameRegion, MysType } from '@/types/mys' +import { GameKeyAndName, GameList, GameNames, GameRegions, MysType } from '@/types/mys' import lodash from 'node-karin/lodash' import moment from 'node-karin/moment' import { game_biz, game_servers } from './MysTool' export const MysUtil = new (class Mysutil { - #all_game_biz = Object.values(game_biz).flat() - #gamelist: GameKeyAndName[] = [] - #allgames: GameKeyAndName[] = [ - { key: GameList.Gs, name: GameNames.gs }, - { key: GameList.Sr, name: GameNames.sr }, - { key: GameList.Zzz, name: GameNames.zzz } - ] + AllGameBiz = Object.values(game_biz).flat() + #gamelist: Partial> = {} + #allgames: Record = { + [GameList.Gs]: { key: GameList.Gs, name: GameNames.gs }, + [GameList.Sr]: { key: GameList.Sr, name: GameNames.sr }, + [GameList.Zzz]: { key: GameList.Zzz, name: GameNames.zzz } + } #allReg = { [GameList.Sr]: '(\\*|#?(sr|星铁|星轨|穹轨|星穹|崩铁|星穹铁道|崩坏星穹铁道|铁道))', [GameList.Zzz]: '(%|#?(zzz|绝区零))', @@ -30,22 +30,18 @@ export const MysUtil = new (class Mysutil { return [MysType.cn, MysType.os] } get games() { - return [...this.#gamelist] + return Object.values(this.#gamelist) } get AllGames() { - return [...this.#allgames] - } - get AllGameBiz() { - return [...this.#all_game_biz] + return Object.values(this.#allgames) } get EndOfDay() { return Number(moment().endOf('day').format('X')) - Number(moment().format('X')) } initGame(key: GameList) { - if (this.#gamelist.some((g) => g.key === key)) return - this.#gamelist.push({ key, name: GameNames[key] }) - this.#gamelist = lodash.sortBy(this.#gamelist, 'key') + if (this.#gamelist[key]) return + this.#gamelist[key] = { key, name: GameNames[key] } } getGame(game: GameList) { @@ -53,13 +49,13 @@ export const MysUtil = new (class Mysutil { } getGameByMsg(msg: string) { - for (const i of this.AllGames) { - if (new RegExp('^' + this.reg[i.key], 'i').test(msg)) { - return i + for (const game of this.AllGames) { + if (new RegExp('^' + this.reg[game.key], 'i').test(msg)) { + return game } } - return this.#allgames[0] + return this.#allgames[GameList.Gs] } getServ(uid: string, game: GameList) { @@ -74,23 +70,23 @@ export const MysUtil = new (class Mysutil { for (const i in game_biz) { const game = i as GameList if (game_biz[game].includes(biz)) { - return this.#allgames.find((g) => g.key === game)! + return this.#allgames[game] } } - return this.#allgames[2] + return this.#allgames[GameList.Gs] } getGameByRegion(region: string) { for (const i in game_servers) { const game = i as GameList if (game_servers[game].some(r => r.region === region)) { - return this.#allgames.find((g) => g.key === game)! + return this.#allgames[game] } } - return this.#allgames[2] + return undefined } - getServerByRegion(region: GameRegion, game: g) { + getServerByRegion(region: GameRegions[g], game: g) { return game_servers[game].find(r => r.region === region)! } @@ -159,7 +155,7 @@ export const MysUtil = new (class Mysutil { /** 循环game */ async eachGame(fn: (game: GameList, ds: GameKeyAndName) => any, all = false) { - for (const ds of (all ? this.#allgames : this.games)) { + for (const ds of (all ? this.AllGames : this.games)) { await fn(ds.key, ds) } } diff --git a/src/mys/define.ts b/src/mys/define.ts index ce81dac7..3b924ec8 100644 --- a/src/mys/define.ts +++ b/src/mys/define.ts @@ -8,6 +8,7 @@ type MysApi = (mysReq: MysReq, reqData?: ReqData) export interface BaseMysResData { retcode: number message: string + isCache?: boolean } export type defineApi = { diff --git a/src/mys/headers.ts b/src/mys/headers.ts index e649c42b..9bb33ac1 100644 --- a/src/mys/headers.ts +++ b/src/mys/headers.ts @@ -1,4 +1,5 @@ import { app_version } from "./MysTool" +import { MysUtil } from "./MysUtil" import { MysReq } from "./MysReq" import { GameList } from "@/types" @@ -18,9 +19,9 @@ export const BaseOsHeaders = { 'x-rpc-language': 'zh-cn' } -export const NoHeader = (mysReq: MysReq, options: { q?: string, b?: unknown } = {}) => { return {} } +export const NoHeader = (mysReq: MysReq, options: { q?: string, b?: any } = {}) => { return {} } -export const CookieHeader = (mysReq: MysReq, options: { q?: string, b?: unknown } = {}) => { +export const CookieHeader = (mysReq: MysReq, options: { q?: string, b?: any } = {}) => { return { Cookie: mysReq.mysUserInfo!.cookie, ...(mysReq.hoyolab ? BaseOsHeaders : BaseHeaders(mysReq)) @@ -36,18 +37,19 @@ export const StokenHeader = (mysReq: MysReq) => { } } -export const PassportHeader = (mysReq: MysReq, options: { q?: string, b?: unknown } = {}) => { +export const PassportHeader = (mysReq: MysReq, options: { q?: string, b?: any } = {}) => { const { q = '', b = '' } = options return { 'x-rpc-app_version': app_version.cn, 'x-rpc-game_biz': 'bbs_cn', 'x-rpc-client_type': '2', 'User-Agent': 'okhttp/4.8.0', + 'x-rpc-app_id': 'bll8iq97cem8', DS: mysReq.getDS1({ q, b: JSON.stringify(b), saltKey: 'PROD' }) } } -export const ActionHeader = (mysReq: MysReq, options: { q?: string, b?: unknown } = {}) => { +export const ActionHeader = (mysReq: MysReq, options: { q?: string, b?: any } = {}) => { const { q = '', b = '' } = options return { ...StokenHeader(mysReq), diff --git a/src/panel/BasePanel.ts b/src/panel/BasePanel.ts index e25b0d14..b2c3187f 100644 --- a/src/panel/BasePanel.ts +++ b/src/panel/BasePanel.ts @@ -1,5 +1,5 @@ import { GameList } from "@/types"; -import { Data, GamePathType, PluginName } from "@/utils"; +import { Data } from "@/utils"; const reFn: Partial> = {} const metaMap: Partial> = {} @@ -46,19 +46,19 @@ export class BasePanel { } /** 获取缓存 */ - _getCache(uuid = '', time = 10 * 60) { + _getCache(uuid = '', time = 10 * 60) { if (uuid && cacheMap[uuid]) { - return cacheMap[uuid]._expire(time) + return cacheMap[uuid]._expire(time) as T } this._uuid = uuid } /** 设置缓存 */ - _cache(time = 10 * 60) { + _cache(time = 10 * 60) { if (this._uuid) { this._expire(time) cacheMap[this._uuid] = this - return cacheMap[this._uuid] + return cacheMap[this._uuid] as T } return this } diff --git a/src/panel/BasePlayer.ts b/src/panel/BasePlayer.ts index 6e2a5408..1a297cf6 100644 --- a/src/panel/BasePlayer.ts +++ b/src/panel/BasePlayer.ts @@ -10,9 +10,11 @@ export class BasePlayer extends BasePanel { /** 等级 */ level: number = 0 /** 头像 */ - face: string = '' + face?: string = '' /** 背景图 */ - card: string = '' + background?: string = '' + /** 基础信息卡片 */ + recordCard: string = '' _updateAvatar: string[] = [] constructor(uid: string, game: GameList) { @@ -20,10 +22,12 @@ export class BasePlayer extends BasePanel { this.uid = uid } - get banner() { - const imgPath = Data.getFilePath(`resources/images/other/default_banner.png`, GamePathType[this.game], karinPath.node) - if (!imgPath) return Data.getFilePath(`resources/images/other/default_banner.png`, GamePathType.Core, karinPath.node) - return imgPath + get Face() { + return this.face || Data.getFilePath(`resources/images/default_face/${this.game}.webp`, GamePathType.Core, karinPath.node) + } + + get Background() { + return this.background || Data.getFilePath(`resources/images/default_background/${this.game}.webp`, GamePathType.Core, karinPath.node) } get PlayerDataPath() { @@ -32,11 +36,11 @@ export class BasePlayer extends BasePanel { static create(uid: string, game: GameList) { const player = new BasePlayer(uid, game) - const cache = player._getCache(`player:${game}:${uid}`) + const cache = player._getCache(`player:${game}:${uid}`) if (cache) return cache player.reload() - return player._cache(100) + return player._cache(100) } /** 加载面板数据文件 */ @@ -56,13 +60,15 @@ export class BasePlayer extends BasePanel { name?: string level?: number face?: string - card?: string + background?: string + recordCard?: string }, save = false) { this.name = ds.name || this.name this.level = ds.level || this.level this.face = ds.face || this.face - this.card = ds.card || this.card + this.background = ds.background || this.background + this.recordCard = ds.recordCard || this.recordCard - save && this.save(this.getData(['name', 'level', 'face', 'card'])) + save && this.save(this.getData(['name', 'level', '_face', 'card'])) } } \ No newline at end of file diff --git a/src/types/configs.ts b/src/types/configs.ts index 0dca4f5a..c04d2e7a 100644 --- a/src/types/configs.ts +++ b/src/types/configs.ts @@ -1,5 +1,4 @@ -import { GamePathType, SimpleQrType } from "@/utils"; -import { BaseQrOptions, CircleQrOption, DSJQrOptions, FuncQrOptions, ImageFillQrOptions, ImageQrOptions, LineQrOptions, RandRectOptions, SolidQrOptions } from "@/utils/simple-qrbtf/component"; +import { GamePathType } from "@/utils"; import { Dialect } from "sequelize"; export const enum ConfigName { @@ -7,8 +6,6 @@ export const enum ConfigName { config = 'config', /** 面板配置 */ panel = 'panel', - /** 自定义二维码配置 */ - qrbtf = 'qrbtf', /** 游戏基础数据配置 */ lables = 'lables' } @@ -35,9 +32,6 @@ interface CoreConfig { /** 渲染精度(0 - 100) */ quality: number - /** 使用自定义样式的二维码 */ - qrbtf: boolean - /** 数据库(可选sqlite、postgres)一般使用sqlite就足够满足需求*/ dialect: ('sqlite' | 'postgres') & Dialect @@ -56,28 +50,6 @@ interface CoreConfig { } } -interface QrOption { - size?: number - /** 数据点透明度 */ - opacity?: number -} - -export type CoreQrbtfStyles = { - [SimpleQrType.base]: BaseQrOptions & QrOption & { style: SimpleQrType.base } - [SimpleQrType.circle]: CircleQrOption & QrOption & { style: SimpleQrType.circle } - [SimpleQrType.dsj]: DSJQrOptions & QrOption & { style: SimpleQrType.dsj } - [SimpleQrType.randRect]: RandRectOptions & QrOption & { style: SimpleQrType.randRect } - [SimpleQrType.line]: LineQrOptions & QrOption & { style: SimpleQrType.line } - [SimpleQrType.solid]: SolidQrOptions & QrOption & { style: SimpleQrType.solid } - [SimpleQrType.image]: ImageQrOptions & QrOption & { style: SimpleQrType.image } - [SimpleQrType.func]: FuncQrOptions & QrOption & { style: SimpleQrType.func } - [SimpleQrType.imageFill]: ImageFillQrOptions & QrOption & { style: SimpleQrType.imageFill } -}[T] - -interface CoreQrbtf { - styles: CoreQrbtfStyles[] -} - interface Panel { /** 面板查询服务 */ serv: string @@ -167,13 +139,6 @@ type Configs = { [GamePathType.sr]: SrPanel [GamePathType.zzz]: undefined } - [ConfigName.qrbtf]: { - [GamePathType.Core]: CoreQrbtf - [GamePathType.Sign]: undefined - [GamePathType.gs]: undefined - [GamePathType.sr]: undefined - [GamePathType.zzz]: undefined - } [ConfigName.lables]: { [GamePathType.Core]: undefined [GamePathType.Sign]: undefined diff --git a/src/types/mys.ts b/src/types/mys.ts index cf1434db..08956ed9 100644 --- a/src/types/mys.ts +++ b/src/types/mys.ts @@ -15,7 +15,7 @@ export const enum MysType { } export interface gameServer { - region: GameRegion + region: GameRegions[GameList] name: string os: boolean } @@ -24,6 +24,7 @@ export type GameKeyAndName = { key: GameList name: GameNames } + export const enum GsRegin { gf = 'cn_gf01', bili = 'cn_qd01', @@ -50,10 +51,8 @@ export const enum ZzzRegin { cht = 'prod_gf_sg' } -type gameRegions = { +export type GameRegions = { [GameList.Gs]: GsRegin [GameList.Sr]: SrRegin [GameList.Zzz]: ZzzRegin } - -export type GameRegion = gameRegions[game] \ No newline at end of file diff --git a/src/types/user/User.ts b/src/types/user/User.ts index 8a99a862..8053febd 100644 --- a/src/types/user/User.ts +++ b/src/types/user/User.ts @@ -1,4 +1,4 @@ -import { GameList, GameRegion, MysType } from "@/types/mys" +import { GameList, GameRegions, MysType } from "@/types/mys" import { BingUIDType } from "./db" export interface UidWithType { @@ -19,6 +19,6 @@ export interface mysUserInfo { cookie?: string stoken?: string device?: string - region?: GameRegion + region?: GameRegions[g] owner?: boolean } \ No newline at end of file diff --git a/src/types/user/db/MysUserDB.ts b/src/types/user/db/MysUserDB.ts index 3a2a6d12..71cdf224 100644 --- a/src/types/user/db/MysUserDB.ts +++ b/src/types/user/db/MysUserDB.ts @@ -1,3 +1,5 @@ +import { MysType } from "@/types" + export enum MysUserDBCOLUMNS { /** 米游社ID */ ltuid = 'ltuid', @@ -21,4 +23,18 @@ export enum MysUserDBCOLUMNS { sr = 'sr_uids', /** 绝区零UID */ zzz = 'zzz_uids' +} + +export interface MysUserDBSaveData { + [MysUserDBCOLUMNS.ltuid]?: string + [MysUserDBCOLUMNS.type]?: MysType + [MysUserDBCOLUMNS.cookie]?: string + [MysUserDBCOLUMNS.stoken]?: string + [MysUserDBCOLUMNS.ltoken]?: string + [MysUserDBCOLUMNS.mid]?: string + [MysUserDBCOLUMNS.login_ticket]?: string + [MysUserDBCOLUMNS.device]?: string + [MysUserDBCOLUMNS.gs]?: string[] + [MysUserDBCOLUMNS.sr]?: string[] + [MysUserDBCOLUMNS.zzz]?: string[] } \ No newline at end of file diff --git a/src/types/user/db/UserDB.ts b/src/types/user/db/UserDB.ts index 8fabd5ee..20e76cab 100644 --- a/src/types/user/db/UserDB.ts +++ b/src/types/user/db/UserDB.ts @@ -21,4 +21,16 @@ export const enum UserDBCOLUMNS { sr_uids = 'sr_uids', /** 绑定的绝区零UID列表 */ zzz_uids = 'zzz_uids' +} + +export interface UserDBSaveData { + [UserDBCOLUMNS.user_id]?: string + [UserDBCOLUMNS.ltuids]?: string[] + [UserDBCOLUMNS.stuids]?: string[] + [UserDBCOLUMNS.gs_main]?: string + [UserDBCOLUMNS.sr_main]?: string + [UserDBCOLUMNS.zzz_main]?: string + [UserDBCOLUMNS.gs_uids]?: Record + [UserDBCOLUMNS.sr_uids]?: Record + [UserDBCOLUMNS.zzz_uids]?: Record } \ No newline at end of file diff --git a/src/user/Base.ts b/src/user/Base.ts deleted file mode 100644 index 9a09478d..00000000 --- a/src/user/Base.ts +++ /dev/null @@ -1,23 +0,0 @@ -export default class Base { - _get(key: any): any { } - _set(key: any, value: any): void { } - constructor(COLUMNS_KEY: string[]) { - return new Proxy(this, { - get(self, key, receiver) { - if (typeof key === 'string' && COLUMNS_KEY.includes(key)) { - return self._get.call(self, key) - } else { - return Reflect.get(self, key, receiver) - } - }, - set(target, key, newValue) { - if (typeof key === 'string' && COLUMNS_KEY.includes(key)) { - target._set.call(target, key, newValue) - return true - } else { - return Reflect.set(target, key, newValue) - } - } - }) - } -} \ No newline at end of file diff --git a/src/user/MysUser.ts b/src/user/MysUser.ts index e50b73c5..5e4a843b 100644 --- a/src/user/MysUser.ts +++ b/src/user/MysUser.ts @@ -1,59 +1,40 @@ import { MysReq, MysUtil, getCookieBySToken, getUserGameRolesByCookie } from '@/mys' import { BasePlayer } from '@/panel' -import { GameList, MysType, MysUserDBCOLUMNS } from '@/types' +import { GameList, MysType, MysUserDBCOLUMNS, MysUserDBSaveData } from '@/types' import { logger } from 'node-karin' -import Base from './Base' import { DailyCache } from './DailyCache' import { MysUserDB } from './db' -export class MysUser extends Base { +export class MysUser { /** 米游社账号数据 */ db!: MysUserDB /** 米游社ID */ - [MysUserDBCOLUMNS.ltuid]!: string + declare [MysUserDBCOLUMNS.ltuid]: string /** 米游社类型 */ - [MysUserDBCOLUMNS.type]!: MysType + declare [MysUserDBCOLUMNS.type]: MysType /** 米游社cookie */ - [MysUserDBCOLUMNS.cookie]!: string + declare [MysUserDBCOLUMNS.cookie]: string /** 米游社stoken */ - [MysUserDBCOLUMNS.stoken]!: string + declare [MysUserDBCOLUMNS.stoken]: string /** 米游社ltoken */ - [MysUserDBCOLUMNS.ltoken]!: string + declare [MysUserDBCOLUMNS.ltoken]: string /** 米游社mid */ - [MysUserDBCOLUMNS.mid]!: string + declare [MysUserDBCOLUMNS.mid]: string /** 米游社login_ticket */ - [MysUserDBCOLUMNS.login_ticket]!: string + declare [MysUserDBCOLUMNS.login_ticket]: string /** 随机设备device */ - [MysUserDBCOLUMNS.device]!: string + declare [MysUserDBCOLUMNS.device]: string /** 原神UID */ - [MysUserDBCOLUMNS.gs]!: string[] + declare [MysUserDBCOLUMNS.gs]: string[] /** 崩铁UID */ - [MysUserDBCOLUMNS.sr]!: string[] + declare [MysUserDBCOLUMNS.sr]: string[] /** 绝区零UID */ - [MysUserDBCOLUMNS.zzz]!: string[] - - static COLUMNS_KEY = Object.keys(MysUserDB.COLUMNS).filter(k => k !== MysUserDBCOLUMNS['ltuid']) as MysUserDBCOLUMNS[] + declare [MysUserDBCOLUMNS.zzz]: string[] constructor(ltuid: string) { - super(MysUser.COLUMNS_KEY) this.ltuid = ltuid } - _get(key: MysUserDBCOLUMNS) { - if (key === MysUserDBCOLUMNS['stoken'] && this.db[MysUserDBCOLUMNS['stoken']]) { - return MysUtil.splicToken({ - ltuid: this.ltuid, - stoken: this.db.stoken, - mid: this.db.mid, - ltoken: this.db.ltoken - }) - } - return this.db[key] - } - _set(key: MysUserDBCOLUMNS, value: any) { - this.db[key] = value - } - static async create(ltuid: string, db?: MysUserDB) { const mys = new MysUser(ltuid) await mys.initDB(db) @@ -66,12 +47,24 @@ export class MysUser extends Base { if (this.db && !db) return this.db = db || await MysUserDB.find(this.ltuid) + for (const key of MysUserDB.COLUMNS_KEY) { + this[key] = this.db[key] as string & MysType & string[] + } } /** 保存数据 */ async save() { if (!this.db) return false - await this.db.save() + await this.db.saveDB(this) + } + + getStoken() { + return MysUtil.splicToken({ + ltuid: this.ltuid, + stoken: this.stoken, + mid: this.mid, + ltoken: this.ltoken + }) } /** 根据UID查询对应米游社账号 */ @@ -82,6 +75,16 @@ export class MysUser extends Base { return await MysUser.create(mys.ltuid) } + getMysUserInfo() { + return { + type: this.type, + ltuid: this.ltuid, + cookie: this.cookie, + stoken: this.getStoken(), + device: this.device + } + } + /** 分配查询MysUser */ static async getByQueryUid(uid: string, game: GameList) { // 使用CK池内容,分配次数最少的一个ltuid @@ -110,13 +113,14 @@ export class MysUser extends Base { } /** 修改数据 */ - async setData(data: Partial) { - for (const i in data) { - const key = i as MysUserDBCOLUMNS - if (!data[key]) continue + async setData(data: MysUserDBSaveData) { + if (MysUserDBCOLUMNS.ltuid in data) { + delete data[MysUserDBCOLUMNS.ltuid] + } - if (MysUser.COLUMNS_KEY.includes(key)) { - this.db[key] = data[key] as string & MysType & string[] + for (const key of MysUserDB.COLUMNS_KEY) { + if (data[key] !== undefined) { + this[key] = data[key] as string & MysType & string[] } } } @@ -128,7 +132,7 @@ export class MysUser extends Base { for (const serv of servs || MysUtil.servs) { const res = await getCookieBySToken( new MysReq(this.ltuid, GameList.Gs, { - stoken: this.stoken.replace(/;/g, '&').replace(/stuid/, 'uid'), + stoken: this.getStoken().replace(/;/g, '&').replace(/stuid/, 'uid'), type: serv }, { log: false }), { method: serv === MysType.cn ? 'GET' : 'POST' } @@ -163,13 +167,14 @@ export class MysUser extends Base { ) if (res?.retcode === 0) { this.type = serv + break } else if (res?.retcode === -100) { msg = 'cookie失效,请重新登录获取' } else { msg = res?.message || '请求失败' } } - if (!res) return err(msg) + if (!res || res?.retcode !== 0) return err(msg) const playerList = (res?.data?.list || []).filter((v: any) => MysUtil.AllGameBiz.includes(v.game_biz) @@ -183,10 +188,9 @@ export class MysUser extends Base { const uid = String(val.game_uid) const game = MysUtil.getGameByGamebiz(val.game_biz) this.addUid(uid, game.key) - const player = new BasePlayer(uid, game.key) - player.setBasicData({ - }, true) + const player = new BasePlayer(uid, game.key) + player.setBasicData({ name: val.nickname }, true) }) return { status: 0, msg: '' } } @@ -201,7 +205,7 @@ export class MysUser extends Base { const g = MysUserDBCOLUMNS[game] if ((game === GameList.Zzz ? /\d{8,10}/ : /\d{9,10}/).test(uid)) { if (!this[g].includes(uid)) { - this.db[g].push(uid) + this[g].push(uid) } } return true diff --git a/src/user/User.ts b/src/user/User.ts index c1c13f1a..b9bcbac9 100644 --- a/src/user/User.ts +++ b/src/user/User.ts @@ -1,45 +1,37 @@ import { MysUtil } from '@/mys' -import { BingUIDType, GameList, MysUserDBCOLUMNS, UidListWithType, UserDBCOLUMNS } from '@/types' -import Base from './Base' +import { BingUIDType, GameList, MysUserDBCOLUMNS, UidListWithType, UserDBCOLUMNS, mysUserInfo } from '@/types' import { MysUser } from './MysUser' import { UserDB } from './db' -export class User extends Base { +export class User { /** 用户数据 */ db!: UserDB game: GameList /** 用户ID */ - [UserDBCOLUMNS.user_id]: string + declare [UserDBCOLUMNS.user_id]: string /** 绑定的cookie ltuids */ - [UserDBCOLUMNS.ltuids]!: string[] + declare [UserDBCOLUMNS.ltuids]: string[] /** 绑定的stoken stuids */ - [UserDBCOLUMNS.stuids]!: string[] + declare [UserDBCOLUMNS.stuids]: string[] /** 当前使用的原神UID */ - [UserDBCOLUMNS.gs_main]!: string + declare [UserDBCOLUMNS.gs_main]: string /** 当前使用的崩坏;星穹铁道UID */ - [UserDBCOLUMNS.sr_main]!: string + declare [UserDBCOLUMNS.sr_main]: string /** 当前使用绝区零UID */ - [UserDBCOLUMNS.zzz_main]!: string + declare [UserDBCOLUMNS.zzz_main]: string /** 绑定的原神UID列表 */ - [UserDBCOLUMNS.gs_uids]!: Record + declare [UserDBCOLUMNS.gs_uids]: Record /** 绑定的崩坏;星穹铁道UID列表 */ - [UserDBCOLUMNS.sr_uids]!: Record + declare [UserDBCOLUMNS.sr_uids]: Record /** 绑定的绝区零UID列表 */ - [UserDBCOLUMNS.zzz_uids]!: Record + declare [UserDBCOLUMNS.zzz_uids]: Record /** 绑定的米游社账号 */ #mysUsers: Record = {} - static COLUMNS_KEY = Object.keys(UserDB.COLUMNS).filter(k => k !== UserDBCOLUMNS['user_id']) as UserDBCOLUMNS[] - constructor(user_id: string, game: GameList = GameList.Gs) { - super(User.COLUMNS_KEY) this.game = game this.user_id = user_id } - _get(key: UserDBCOLUMNS) { return this.db[key] } - _set(key: UserDBCOLUMNS, value: any) { - this.db[key] = value - } get uid() { return this[this.Key.m] @@ -83,12 +75,15 @@ export class User extends Base { if (this.db && !db) return this.db = db || await UserDB.find(this.user_id) + for (const key of UserDB.COLUMNS_KEY) { + this[key] = this.db[key] as string & string[] & Record + } } /** 保存数据 */ async save() { if (!this.db) return false - await this.db.save() + await this.db.saveDB(this) } /** 初始化MysUser对象 */ @@ -129,9 +124,13 @@ export class User extends Base { await MysUtil.eachGame(async (game) => { const g = self.gameKey(game) const uids = mysUser[g.u].filter(v => self[g.u][v] !== BingUIDType.ban) - await self.addRegUid({ uid: uids, game, type, save: false }) + await self.addRegUid({ + uid: uids, game, type, save: false + }) if (uids[0] && !self[g.m]) { - self.setMainUid({ uid: uids[0], game, save: false }) + self.setMainUid({ + uid: uids[0], game, save: false + }) } }, true) await this.save() @@ -147,8 +146,13 @@ export class User extends Base { return this.#mysUsers[ltuid] } - getCkInfoByUid(params: { game?: GameList, uid?: string } = {}) { + getCkInfoByUid(params: { game?: g, uid?: string } = {}): mysUserInfo { + const { game = this.game, uid = this.mainUid(game) } = params + + const mysUser = this.getMysUserByUid({ game, uid }) + const ckInfo = mysUser.getMysUserInfo() + return { ...ckInfo, user_id: this.user_id } } /** 添加绑定UID */ @@ -162,13 +166,13 @@ export class User extends Base { const { uid, game = this.game, type = BingUIDType.reg, save = true } = options if (Array.isArray(uid)) { for (const u of uid) { - await this.addRegUid({ uid: u, game, save: false }) + await this.addRegUid({ uid: u, game, type, save: false }) } if (save) await this.save() return true } - this.db[this.gameKey(game).u][uid] = type + this[this.gameKey(game).u][uid] = type await this.setMainUid({ uid, game, save: false }) if (save) await this.save() @@ -180,9 +184,11 @@ export class User extends Base { const g = this.gameKey(game || this.game) if (!(uid in this[g.u])) return undefined - delete this.db[g.u][uid] + delete this[g.u][uid] if (this[g.m] === uid || !this[g.m]) { - await this.setMainUid({ uid: Object.keys(this[g.u])[0], game, save: false }) + await this.setMainUid({ + uid: Object.keys(this[g.u])[0], game, save: false + }) } await this.save() @@ -190,10 +196,10 @@ export class User extends Base { /** 切换UID */ async setMainUid(options: { - uid?: string, - game?: GameList, - /** 是否立即保存 */ - save?: boolean, + uid?: string + game?: GameList + /** 是否立即保存,默认true */ + save?: boolean }) { const { uid = '', game = this.game, save = true } = options const uidList = this.getUidList({ game }) @@ -201,7 +207,7 @@ export class User extends Base { return false } - this.db[this.gameKey(game).m] = uid + this[this.gameKey(game).m] = uid if (save) await this.save() } @@ -216,15 +222,15 @@ export class User extends Base { const uid = options.uid || this[g.m] if (options.type === BingUIDType.ban) { - this.db[g.u][uid] = BingUIDType.ban + this[g.u][uid] = BingUIDType.ban const uidList = this.getUidList({ game }) await this.setMainUid({ uid: uidList[0], game }) return true } - if (this.db[g.u][uid] === options.type) { - this.db[g.u][uid] = BingUIDType.reg + if (this[g.u][uid] === options.type) { + this[g.u][uid] = BingUIDType.reg } else if (this[g.u][uid] === BingUIDType.all) { - this.db[g.u][uid] = options.type + this[g.u][uid] = options.type } else { return false } diff --git a/src/user/db/MysUserDB.ts b/src/user/db/MysUserDB.ts index be2457b9..752f281f 100644 --- a/src/user/db/MysUserDB.ts +++ b/src/user/db/MysUserDB.ts @@ -1,5 +1,5 @@ import { MysUtil } from '@/mys' -import { GameList, MysType, MysUserDBCOLUMNS } from '@/types' +import { GameList, MysType, MysUserDBCOLUMNS, MysUserDBSaveData } from '@/types' import { DbBaseModel } from './BaseModel' const { Types, Column, ArrayColumn, Op, DIALECT } = DbBaseModel @@ -15,13 +15,13 @@ const COLUMNS = { [MysUserDBCOLUMNS['mid']]: Column('STRING'), [MysUserDBCOLUMNS['login_ticket']]: Column('STRING'), [MysUserDBCOLUMNS['device']]: Column('STRING'), - [MysUserDBCOLUMNS['gs']]: ArrayColumn('gs_uids', { + [MysUserDBCOLUMNS['gs']]: ArrayColumn(MysUserDBCOLUMNS['gs'], { fn: (data) => data.sort((a, b) => Number(a) - Number(b)) }), - [MysUserDBCOLUMNS['sr']]: ArrayColumn('sr_uids', { + [MysUserDBCOLUMNS['sr']]: ArrayColumn(MysUserDBCOLUMNS['sr'], { fn: (data) => data.sort((a, b) => Number(a) - Number(b)) }), - [MysUserDBCOLUMNS['zzz']]: ArrayColumn('zzz_uids', { + [MysUserDBCOLUMNS['zzz']]: ArrayColumn(MysUserDBCOLUMNS['zzz'], { fn: (data) => data.sort((a, b) => Number(a) - Number(b)) }) } @@ -50,7 +50,7 @@ export class MysUserDB extends DbBaseModel { /** 绝区零UID */ declare [MysUserDBCOLUMNS.zzz]: string[] - static COLUMNS = COLUMNS + static COLUMNS_KEY = Object.keys(COLUMNS).filter(k => k !== MysUserDBCOLUMNS['ltuid']) as MysUserDBCOLUMNS[] /** 根据ltuid查找MysUser */ static async find(ltuid: string) { @@ -73,6 +73,16 @@ export class MysUserDB extends DbBaseModel { }) return users?.[0] } + + async saveDB(param: MysUserDBSaveData) { + for (const key of MysUserDB.COLUMNS_KEY) { + if (param[key] !== undefined) { + this[key] = param[key] as string & MysType & string[] + } + } + + await this.save() + } } DbBaseModel.initDB(MysUserDB, COLUMNS) diff --git a/src/user/db/UserDB.ts b/src/user/db/UserDB.ts index ea890cd8..d3e4e99a 100644 --- a/src/user/db/UserDB.ts +++ b/src/user/db/UserDB.ts @@ -1,4 +1,4 @@ -import { BingUIDType, UserDBCOLUMNS } from '@/types/user' +import { BingUIDType, UserDBCOLUMNS, UserDBSaveData } from '@/types/user' import { DbBaseModel } from './BaseModel' const { Types, ArrayColumn, JsonColumn, Column } = DbBaseModel @@ -37,11 +37,21 @@ export class UserDB extends DbBaseModel { /** 绑定的绝区零UID列表 */ declare [UserDBCOLUMNS.zzz_uids]: Record - static COLUMNS = COLUMNS + static COLUMNS_KEY = Object.keys(COLUMNS).filter(k => k !== UserDBCOLUMNS['user_id']) as UserDBCOLUMNS[] static async find(user_id: string) { return await UserDB.findByPk(user_id) || UserDB.build({ user_id }) } + + async saveDB(param: UserDBSaveData) { + for (const key of UserDB.COLUMNS_KEY) { + if (param[key] !== undefined) { + this[key] = param[key] as string & string[] & Record + } + } + + await this.save() + } } DbBaseModel.initDB(UserDB, COLUMNS) diff --git a/src/utils/BaseModel.ts b/src/utils/BaseModel.ts index 4ad4d05e..9824b9c9 100644 --- a/src/utils/BaseModel.ts +++ b/src/utils/BaseModel.ts @@ -4,12 +4,11 @@ import path from "path"; import { Data, GamePathType, karinPath } from "./Data"; import { Cfg } from "./config"; import { NpmPath, PluginName, isNpm } from "./dir"; -import { wkhtmltoimage } from "./wkhtmltoimage"; +// import { wkhtmltoimage } from "./wkhtmltoimage"; -const res_Path = path.join(NpmPath, 'resources/') -const fontsPath = path.join(NpmPath, 'resources/fonts/') -const elemLayout = path.join(NpmPath, 'resources/template/layout/elem.html') -const defaultLayout = path.join(NpmPath, 'resources/template/layout/default.html') +const res_Path = path.join(NpmPath, 'resources/').replace(/\\/g, '/') +const fontsPath = path.join(NpmPath, 'resources/fonts/').replace(/\\/g, '/') +const defaultLayout = path.join(NpmPath, 'resources/template/layout/default.html').replace(/\\/g, '/') export class BaseModel { /** 查询UID */ @@ -54,10 +53,11 @@ export class BaseModel { file: path.join(this.NpmPath, `resources/template/${this.model}.html`), data: { uid: this.uid, - useBrowser: '-pu', PluginName: this.PluginName, - fontsPath, res_Path, elemLayout, defaultLayout, - pluResPath: path.join(this.NpmPath, 'resources/'), + PluginVersion: Cfg.package(this.game).version, + MysToolVersion: this.game === GamePathType.Core ? false : Cfg.package(GamePathType.Core).version, + pluResPath: path.join(this.NpmPath, 'resources/').replace(/\\/g, '/'), + fontsPath, res_Path, defaultLayout, ...data }, // setViewport: { @@ -71,13 +71,15 @@ export class BaseModel { } // if (options.Scale) ImageData.quality = 40 - let img - if (!options.nowk && this.config.wkhtmltoimage) { - img = await wkhtmltoimage(ImageData) - } - if (!img) { - img = await karin.render(ImageData) - } + // let img + // if (!options.nowk && this.config.wkhtmltoimage) { + // img = await wkhtmltoimage(ImageData) + // } + // if (!img) { + // img = await karin.render(ImageData) + // } + + const img = await karin.render(ImageData) return segment.image(img) } } \ No newline at end of file diff --git a/src/utils/Data.ts b/src/utils/Data.ts index e4d9807a..22860c8a 100644 --- a/src/utils/Data.ts +++ b/src/utils/Data.ts @@ -30,9 +30,9 @@ export const Data = new (class Data { } #GameNpmPath: Record = { [GamePathType.gs]: PATH.join(KarinPath, karinPath.node, 'karin-plugin-mystool-genshin'), - [GamePathType.sr]: PATH.join(KarinPath, karinPath.node, 'karin-plugin-mystool-genshin'), - [GamePathType.zzz]: PATH.join(KarinPath, karinPath.node, 'karin-plugin-mystool-genshin'), - [GamePathType.Sign]: PATH.join(KarinPath, karinPath.node, 'karin-plugin-mystool-genshin'), + [GamePathType.sr]: PATH.join(KarinPath, karinPath.node, 'karin-plugin-mystool-starrail'), + [GamePathType.zzz]: PATH.join(KarinPath, karinPath.node, 'karin-plugin-mystool-zzzero'), + [GamePathType.Sign]: PATH.join(KarinPath, karinPath.node, 'karin-plugin-mystool-myssign'), [GamePathType.Core]: NpmPath } /** @@ -41,14 +41,14 @@ export const Data = new (class Data { getFilePath(file: string, game: GamePathType, k_path: karinPath, ckeck: true): string | false getFilePath(file: string, game: GamePathType, k_path: karinPath, ckeck?: false): string getFilePath(file: string, game: GamePathType, k_path: karinPath, ckeck = false) { - if (k_path == karinPath.node) { - return PATH.join(this.getNpmPath(game), file) + if (k_path === karinPath.node) { + return PATH.join(this.getNpmPath(game), file).replace(/\\/g, '/') } const filePath = PATH.join(KarinPath, `${k_path}/${this.getPluginName(game, true)}`, file) if (ckeck) { - return fs.existsSync(filePath) ? filePath : false + return fs.existsSync(filePath) ? filePath.replace(/\\/g, '/') : false } - return filePath + return filePath.replace(/\\/g, '/') } /** * 根据指定的path依次检查与创建目录 @@ -65,10 +65,13 @@ export const Data = new (class Data { path = path.replace(/^\/+|\/+$/g, '') if (fs.existsSync(PATH.join(createDirPath, path))) { - return PATH.join(createDirPath, path, file) + return PATH.join(createDirPath, path, file).replace(/\\/g, '/') } let nowPath = createDirPath + if (!fs.existsSync(nowPath)) { + fs.mkdirSync(nowPath); + } path.split('/').forEach(name => { nowPath = PATH.join(nowPath, name) if (!fs.existsSync(nowPath)) { @@ -76,7 +79,7 @@ export const Data = new (class Data { } }) - return PATH.join(nowPath, file) + return PATH.join(nowPath, file).replace(/\\/g, '/') } copyFile(copyFile: string, target: string, game: GamePathType, k_path: karinPath) { @@ -103,8 +106,13 @@ export const Data = new (class Data { return path } - setNpmPath(game: GamePathType, path: string) { + setNpmPath(game: GamePathType, path: string, isNpm: boolean) { this.#GameNpmPath[game] = path + if (isNpm) { + this.#GamePluginName[game] = PATH.basename(path).replace(/(^|-)\w/g, (m) => m.toUpperCase()) + } else { + this.#GamePluginName[game] = PATH.basename(path) + } } getNpmPath(game: GamePathType) { diff --git a/src/utils/config.ts b/src/utils/config.ts index 7c41dc4c..a6462e1a 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -2,18 +2,19 @@ import { CfgType, ConfigName, ConfigsType } from '@/types' import { logger } from 'node-karin' import { yaml as Yaml, chokidar, fs, lodash, path as PATH } from 'node-karin/modules.js' import { Data, GamePathType, karinPath } from './Data' -import { NpmPath, PluginName } from './dir' +import { NpmPath, isNpm } from './dir' export const Cfg = new (class Config { - #config: Map | Yaml.Document> = new Map() - #watcher: Map = new Map() + #config: Map = new Map() + #packages: Map = new Map() + #watcher: Map = new Map() constructor() { - this.initCfg(GamePathType.Core, NpmPath) + this.initCfg(GamePathType.Core, NpmPath, isNpm) } /** 初始化配置 */ - async initCfg(game: GamePathType, npmPath: string) { - await Data.setNpmPath(game, npmPath) + async initCfg(game: GamePathType, npmPath: string, isNpm: boolean) { + await Data.setNpmPath(game, npmPath, isNpm) const defSetPath = Data.getFilePath(`config`, game, karinPath.node) if (!fs.existsSync(defSetPath)) return false @@ -35,21 +36,15 @@ export const Cfg = new (class Config { } this.getdefSet(fileName, game) }) - - const ViewPath = PATH.join(defSetPath, 'PluginConfigView.js') - if (fs.existsSync(ViewPath)) { - fs.writeFileSync( - PATH.join(configPath,'PluginConfigView.yaml'), - Yaml.stringify( - (await Data.importModule('config/PluginConfigView.js', game, { defData: [] })).module - ), - 'utf8' - ) - } } package(game: GamePathType) { - return Data.readJSON('package.json', game, karinPath.node) + if (this.#packages.has(game)) return this.#packages.get(game) + + const pkg = Data.readJSON('package.json', game, karinPath.node) + this.#packages.set(game, pkg) + + return pkg } /** 获取用户配置 */ @@ -70,12 +65,12 @@ export const Cfg = new (class Config { /** 修改用户配置 */ setConfig(name: ConfigName, game: GamePathType, data: any) { - const ConfigPath = this.getConfigPath(CfgType.config, game as GamePathType, name) - const defSetPath = this.getConfigPath(CfgType.defSet, game as GamePathType, name) + const ConfigPath = this.getConfigPath(CfgType.config, game, name) + const defSetPath = this.getConfigPath(CfgType.defSet, game, name) let config: string if (fs.existsSync(defSetPath)) { - const defSet = this.getdefSet(name as ConfigName, game as GamePathType, true) + const defSet = this.getdefSet(name, game, true) lodash.forEach(data, (value, key) => { if (defSet.hasIn([key])) { defSet.setIn([key], value) @@ -91,28 +86,29 @@ export const Cfg = new (class Config { fs.writeFileSync(ConfigPath, config, 'utf8') } - /** 获取配置yaml */ #getYaml(type: CfgType, name: ConfigName, game: GamePathType, Document: true): Yaml.Document #getYaml(type: CfgType, name: N, game: G): ConfigsType #getYaml(type: CfgType, name: ConfigName, game: GamePathType, Document = false) { const file = this.getConfigPath(type, game, name) - const key = `${Document ? (type + '_Document') : type}.${game}.${name}` + const key = `${type}.${game}.${name}` - let cfg = this.#config.get(key) - if (cfg) return cfg + if (this.#config.has(key)) { + const cfg = this.#config.get(key) + return Document ? cfg : cfg.toJSON() + } try { - const data = fs.readFileSync(file, 'utf8') - cfg = Document ? Yaml.parseDocument(data) : Yaml.parse(data) + const cfg = Yaml.parseDocument(fs.readFileSync(file, 'utf8')) this.#config.set(key, cfg) + + this.#watch(file, key) + return Document ? cfg : cfg.toJSON() } catch (error) { + const PluginName = Data.getPluginName(game) logger.error(`[${PluginName}][${key}] 格式错误 ${error}`) throw error } - - if (!Document) this.#watch(file, key) - return cfg } /** 获取配置路径 */ @@ -132,6 +128,8 @@ export const Cfg = new (class Config { watcher.on('change', () => { if (key.includes('config')) { this.#config.delete(key) + const [type, game, name] = key.split('.') as [CfgType, GamePathType, ConfigName] + const PluginName = Data.getPluginName(game) logger.mark(`[${PluginName}修改配置文件][${key}]`) } }) diff --git a/src/utils/index.ts b/src/utils/index.ts index 5fca21eb..719ee42b 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,5 +1,4 @@ export * from './config' export * from './Data' export * from './dir' -export * from './simple-qrbtf/index' export * from './BaseModel' \ No newline at end of file diff --git a/src/utils/simple-qrbtf/component/base.qr.ts b/src/utils/simple-qrbtf/component/base.qr.ts deleted file mode 100644 index dbc2258b..00000000 --- a/src/utils/simple-qrbtf/component/base.qr.ts +++ /dev/null @@ -1,157 +0,0 @@ -import { createRenderer, Renderer } from '../renderer'; -import { getTypeTable, QRPointType, rand } from '../utils'; - -enum Type { - Rect = 'rect', - Round = 'round', - Rand = 'rand', -} - -enum PosType { - Rect = 'rect', - Round = 'round', - Planet = 'planet', - RoundRect = 'roundRect', -} - -export interface BaseQrOptions { - type?: Type | string; - posType?: PosType | string; - /** 数据点颜色 */ - otherColor?: string; - /** 定位点颜色 */ - posColor?: string; -} - -const BaseQrRenderer: Renderer = { - defaultProps: { - type: Type.Rect, - posType: PosType.Rect, - otherColor: '#000000', - posColor: '#000000', - }, - listPoints: (props) => { - const { qrcode, type, posType, otherColor, posColor } = props; - let { size, opacity } = props; - if (!qrcode) return []; - - const nCount = qrcode.getModuleCount(); - const typeTable = getTypeTable(qrcode); - const pointList = []; - - size = size / 100; - opacity = opacity / 100; - - const vw = [3, -3]; - const vh = [3, -3]; - const sq25 = - 'M32.048565,-1.29480038e-15 L67.951435,1.29480038e-15 C79.0954192,-7.52316311e-16 83.1364972,1.16032014 87.2105713,3.3391588 C91.2846454,5.51799746 94.4820025,8.71535463 96.6608412,12.7894287 C98.8396799,16.8635028 100,20.9045808 100,32.048565 L100,67.951435 C100,79.0954192 98.8396799,83.1364972 96.6608412,87.2105713 C94.4820025,91.2846454 91.2846454,94.4820025 87.2105713,96.6608412 C83.1364972,98.8396799 79.0954192,100 67.951435,100 L32.048565,100 C20.9045808,100 16.8635028,98.8396799 12.7894287,96.6608412 C8.71535463,94.4820025 5.51799746,91.2846454 3.3391588,87.2105713 C1.16032014,83.1364972 5.01544207e-16,79.0954192 -8.63200256e-16,67.951435 L8.63200256e-16,32.048565 C-5.01544207e-16,20.9045808 1.16032014,16.8635028 3.3391588,12.7894287 C5.51799746,8.71535463 8.71535463,5.51799746 12.7894287,3.3391588 C16.8635028,1.16032014 20.9045808,7.52316311e-16 32.048565,-1.29480038e-15 Z'; - - if (size <= 0) size = 1.0; - - for (let x = 0; x < nCount; x++) { - for (let y = 0; y < nCount; y++) { - if (qrcode.isDark(x, y) === false) { - // do nothing; - } else if ( - typeTable[x][y] === QRPointType.ALIGN_CENTER || - typeTable[x][y] === QRPointType.ALIGN_OTHER || - typeTable[x][y] === QRPointType.TIMING - ) { - if (type === Type.Rect) { - pointList.push( - ``, - ); - } else if (type === Type.Round) { - pointList.push( - ``, - ); - } else if (type === Type.Rand) { - pointList.push( - ``, - ); - } - } else if (typeTable[x][y] === QRPointType.POS_CENTER) { - if (posType === PosType.Rect) { - pointList.push(` - - `); - } else if (posType === PosType.Round) { - pointList.push(` - - `); - pointList.push(` - - `); - } else if (posType === PosType.Planet) { - pointList.push(` - - `); - pointList.push( - ``, - ); - for (let w = 0; w < vw.length; w++) { - pointList.push( - ``, - ); - } - for (let h = 0; h < vh.length; h++) { - pointList.push( - ``, - ); - } - } else if (posType === PosType.RoundRect) { - pointList.push(` - `); - pointList.push(` - - `); - } - } else if (typeTable[x][y] === QRPointType.POS_OTHER) { - if (posType === PosType.Rect) { - pointList.push(` - - `); - } - } else { - if (type === Type.Rect) { - pointList.push( - ` `, - ); - } else if (type === Type.Round) { - pointList.push( - ``, - ); - } else if (type === Type.Rand) { - pointList.push( - ` `, - ); - } - } - } - } - - return pointList; - }, -}; - -export const BaseQr = createRenderer(BaseQrRenderer); - -export default BaseQr; diff --git a/src/utils/simple-qrbtf/component/circle.qr.ts b/src/utils/simple-qrbtf/component/circle.qr.ts deleted file mode 100644 index f2fd7fd0..00000000 --- a/src/utils/simple-qrbtf/component/circle.qr.ts +++ /dev/null @@ -1,149 +0,0 @@ -import { createRenderer, Renderer } from '../renderer'; -import { getTypeTable, QRPointType, rand } from '../utils'; - -export interface CircleQrOption { - /** 数据点颜色 */ - otherColor?: string; - /** 定位点颜色 */ - posColor?: string; -} - -const CircleQrRenderer: Renderer = { - defaultProps: { - otherColor: '#000', - posColor: '#999', - }, - listPoints: (props) => { - const { qrcode } = props; - if (!qrcode) return []; - - const nCount = qrcode.getModuleCount(); - const typeTable = getTypeTable(qrcode); - const pointList = []; - const g1 = []; - const g2 = []; - - const otherColor = props.otherColor; - const posColor = props.posColor; - - const available: Array> = []; - const ava2: Array> = []; - for (let x = 0; x < nCount; x++) { - available[x] = []; - ava2[x] = []; - for (let y = 0; y < nCount; y++) { - available[x][y] = true; - ava2[x][y] = true; - } - } - - for (let y = 0; y < nCount; y++) { - for (let x = 0; x < nCount; x++) { - if (qrcode.isDark(x, y) && typeTable[x][y] === QRPointType.POS_CENTER) { - pointList.push(``); - pointList.push(``); - } else if (qrcode.isDark(x, y) && typeTable[x][y] === QRPointType.POS_OTHER) { - // do nothing; - } else { - if (available[x][y] && ava2[x][y] && x < nCount - 2 && y < nCount - 2) { - let ctn = true; - for (let i = 0; i < 3; i++) { - for (let j = 0; j < 3; j++) { - if (ava2[x + i][y + j] === false) { - ctn = false; - } - } - } - if ( - ctn && - qrcode.isDark(x + 1, y) && - qrcode.isDark(x + 1, y + 2) && - qrcode.isDark(x, y + 1) && - qrcode.isDark(x + 2, y + 1) - ) { - g1.push( - ``, - ); - if (qrcode.isDark(x + 1, y + 1)) { - g1.push( - ``, - ); - } - available[x + 1][y] = false; - available[x][y + 1] = false; - available[x + 2][y + 1] = false; - available[x + 1][y + 2] = false; - for (let i = 0; i < 3; i++) { - for (let j = 0; j < 3; j++) { - ava2[x + i][y + j] = false; - } - } - } - } - if (x < nCount - 1 && y < nCount - 1) { - if ( - qrcode.isDark(x, y) && - qrcode.isDark(x + 1, y) && - qrcode.isDark(x, y + 1) && - qrcode.isDark(x + 1, y + 1) - ) { - g1.push( - ``, - ); - for (let i = 0; i < 2; i++) { - for (let j = 0; j < 2; j++) { - available[x + i][y + j] = false; - ava2[x + i][y + j] = false; - } - } - } - } - if (available[x][y] && y < nCount - 1) { - if (qrcode.isDark(x, y) && qrcode.isDark(x, y + 1)) { - pointList.push( - ``, - ); - available[x][y] = false; - available[x][y + 1] = false; - } - } - if (available[x][y] && x < nCount - 1) { - if (qrcode.isDark(x, y) && qrcode.isDark(x + 1, y)) { - pointList.push( - ``, - ); - available[x][y] = false; - available[x + 1][y] = false; - } - } - if (available[x][y]) { - if (qrcode.isDark(x, y)) { - pointList.push( - ``, - ); - } else if (typeTable[x][y] === QRPointType.DATA) { - if (rand(0, 1) > 0.85) { - g2.push( - ``, - ); - } - } - } - } - } - } - - for (let i = 0; i < g1.length; i++) { - pointList.push(g1[i]); - } - for (let i = 0; i < g2.length; i++) { - pointList.push(g2[i]); - } - - return pointList; - }, -}; - -export const CircleQr = createRenderer(CircleQrRenderer); -export default CircleQr; diff --git a/src/utils/simple-qrbtf/component/dsj.qr.ts b/src/utils/simple-qrbtf/component/dsj.qr.ts deleted file mode 100644 index 358a098f..00000000 --- a/src/utils/simple-qrbtf/component/dsj.qr.ts +++ /dev/null @@ -1,242 +0,0 @@ -import { createRenderer, Renderer } from '../renderer'; -import { getTypeTable, QRPointType } from '../utils'; - -enum Type { - Rect = 'rect', - Dsj = 'dsj', -} - -export interface DSJQrOptions { - scale?: number; - crossWidth?: number; - posWidth?: number; - posType?: Type | string; -} - -const DsjQrRenderer: Renderer = { - defaultProps: { - scale: 100, - crossWidth: 100, - posWidth: 100, - posType: 'rect', - }, - listPoints: (props) => { - const { qrcode } = props; - if (!qrcode) return []; - - const nCount = qrcode.getModuleCount(); - const typeTable = getTypeTable(qrcode); - const pointList = []; - const g1 = []; - const g2 = []; - - let width2 = props.scale! / 100; - let width1 = props.crossWidth! / 100; - const width3 = props.posWidth! / 100; - const posType = props.posType; - - if (width2 <= 0) width2 = 70; - if (width1 <= 0) width1 = 70; - - const available: Array> = []; - const ava2: Array> = []; - for (let x = 0; x < nCount; x++) { - available[x] = []; - ava2[x] = []; - for (let y = 0; y < nCount; y++) { - available[x][y] = true; - ava2[x][y] = true; - } - } - - for (let y = 0; y < nCount; y++) { - for (let x = 0; x < nCount; x++) { - if (qrcode.isDark(x, y) === false) { - // do nothing; - } else if (typeTable[x][y] === QRPointType.POS_CENTER) { - if (posType === Type.Rect) { - pointList.push(``); - } else if (posType === Type.Dsj) { - pointList.push( - ``, - ); - pointList.push( - ``, - ); - pointList.push( - ``, - ); - pointList.push( - ``, - ); - pointList.push( - ``, - ); - } - } else if (typeTable[x][y] === QRPointType.POS_OTHER) { - if (posType === Type.Rect) { - pointList.push(``); - } - } else { - if (available[x][y] && ava2[x][y] && x < nCount - 2 && y < nCount - 2) { - let ctn = true; - for (let i = 0; i < 3; i++) { - for (let j = 0; j < 3; j++) { - if (ava2[x + i][y + j] === false) { - ctn = false; - } - } - } - if ( - ctn && - qrcode.isDark(x + 2, y) && - qrcode.isDark(x + 1, y + 1) && - qrcode.isDark(x, y + 2) && - qrcode.isDark(x + 2, y + 2) - ) { - g1.push( - ``, - ); - g1.push( - ``, - ); - available[x][y] = false; - available[x + 2][y] = false; - available[x][y + 2] = false; - available[x + 2][y + 2] = false; - available[x + 1][y + 1] = false; - for (let i = 0; i < 3; i++) { - for (let j = 0; j < 3; j++) { - ava2[x + i][y + j] = false; - } - } - } - } - if (available[x][y] && ava2[x][y] && x < nCount - 1 && y < nCount - 1) { - let ctn = true; - for (let i = 0; i < 2; i++) { - for (let j = 0; j < 2; j++) { - if (ava2[x + i][y + j] === false) { - ctn = false; - } - } - } - if (ctn && qrcode.isDark(x + 1, y) && qrcode.isDark(x, y + 1) && qrcode.isDark(x + 1, y + 1)) { - g1.push( - ``, - ); - g1.push( - ``, - ); - for (let i = 0; i < 2; i++) { - for (let j = 0; j < 2; j++) { - available[x + i][y + j] = false; - ava2[x + i][y + j] = false; - } - } - } - } - if (available[x][y] && ava2[x][y]) { - if (y === 0 || (y > 0 && (!qrcode.isDark(x, y - 1) || !ava2[x][y - 1]))) { - const start = y; - let end = y; - let ctn = true; - while (ctn && end < nCount) { - if (qrcode.isDark(x, end) && ava2[x][end]) { - end++; - } else { - ctn = false; - } - } - if (end - start > 2) { - for (let i = start; i < end; i++) { - ava2[x][i] = false; - available[x][i] = false; - } - g2.push( - ``, - ); - g2.push( - ``, - ); - } - } - } - if (available[x][y] && ava2[x][y]) { - if (x === 0 || (x > 0 && (!qrcode.isDark(x - 1, y) || !ava2[x - 1][y]))) { - const start = x; - let end = x; - let ctn = true; - while (ctn && end < nCount) { - if (qrcode.isDark(end, y) && ava2[end][y]) { - end++; - } else { - ctn = false; - } - } - if (end - start > 1) { - for (let i = start; i < end; i++) { - ava2[i][y] = false; - available[i][y] = false; - } - g2.push( - ``, - ); - } - } - } - if (available[x][y]) { - pointList.push( - ``, - ); - } - } - } - } - - for (let i = 0; i < g1.length; i++) { - pointList.push(g1[i]); - } - for (let i = 0; i < g2.length; i++) { - pointList.push(g2[i]); - } - return pointList; - }, -}; - -export const DsjQR = createRenderer(DsjQrRenderer); -export default DsjQR; diff --git a/src/utils/simple-qrbtf/component/func.qr.ts b/src/utils/simple-qrbtf/component/func.qr.ts deleted file mode 100644 index 71008494..00000000 --- a/src/utils/simple-qrbtf/component/func.qr.ts +++ /dev/null @@ -1,190 +0,0 @@ -import { createRenderer, Renderer } from '../renderer'; -import { getTypeTable, QRPointType } from '../utils'; - -enum Type { - Rect = 'rect', - Round = 'round', -} - -enum PosType { - Rect = 'rect', - Round = 'round', - Planet = 'planet', - RoundRect = 'roundRect', -} - -enum FuncType { - FuncA = 'A', - FuncB = 'B', -} - -export interface FuncQrOptions { - /** ⭕样式 */ - funcType?: FuncType; - type?: Type; - posType?: PosType; - /** 数据点颜色 */ - otherColor1?: string; - /** ⭕颜色 */ - otherColor2?: string; - /** 定位点颜色 */ - posColor?: string; -} - -const FuncQrRenderer: Renderer = { - defaultProps: { - funcType: FuncType.FuncA, - type: Type.Rect, - posType: PosType.Rect, - otherColor1: '#000', - otherColor2: '#999', - posColor: '#777', - }, - listPoints: (props) => { - const { qrcode } = props; - if (!qrcode) return []; - - const nCount = qrcode.getModuleCount(); - const typeTable = getTypeTable(qrcode); - const pointList = []; - - const { type, funcType, posType, otherColor1, otherColor2, posColor } = props; - let size = props.size; - - const vw = [3, -3]; - const vh = [3, -3]; - - const sq25 = - 'M32.048565,-1.29480038e-15 L67.951435,1.29480038e-15 C79.0954192,-7.52316311e-16 83.1364972,1.16032014 87.2105713,3.3391588 C91.2846454,5.51799746 94.4820025,8.71535463 96.6608412,12.7894287 C98.8396799,16.8635028 100,20.9045808 100,32.048565 L100,67.951435 C100,79.0954192 98.8396799,83.1364972 96.6608412,87.2105713 C94.4820025,91.2846454 91.2846454,94.4820025 87.2105713,96.6608412 C83.1364972,98.8396799 79.0954192,100 67.951435,100 L32.048565,100 C20.9045808,100 16.8635028,98.8396799 12.7894287,96.6608412 C8.71535463,94.4820025 5.51799746,91.2846454 3.3391588,87.2105713 C1.16032014,83.1364972 5.01544207e-16,79.0954192 -8.63200256e-16,67.951435 L8.63200256e-16,32.048565 C-5.01544207e-16,20.9045808 1.16032014,16.8635028 3.3391588,12.7894287 C5.51799746,8.71535463 8.71535463,5.51799746 12.7894287,3.3391588 C16.8635028,1.16032014 20.9045808,7.52316311e-16 32.048565,-1.29480038e-15 Z'; - - if (size <= 0) size = 1.0; - - if (funcType === FuncType.FuncA && type === Type.Rect) { - pointList.push( - ``, - ); - } - - for (let x = 0; x < nCount; x++) { - for (let y = 0; y < nCount; y++) { - if (qrcode.isDark(x, y) && typeTable[x][y] === QRPointType.POS_CENTER) { - if (posType === PosType.Rect) { - pointList.push(``); - } else if (posType === PosType.Round) { - pointList.push(``); - pointList.push( - ``, - ); - } else if (posType === PosType.Planet) { - pointList.push(``); - pointList.push( - ``, - ); - for (let w = 0; w < vw.length; w++) { - pointList.push( - ``, - ); - } - for (let h = 0; h < vh.length; h++) { - pointList.push( - ``, - ); - } - } else if (posType === PosType.RoundRect) { - pointList.push(``); - pointList.push( - ``, - ); - } - } else if (qrcode.isDark(x, y) && typeTable[x][y] === QRPointType.POS_OTHER) { - if (posType === PosType.Rect) { - pointList.push(``); - } - } else { - const dist = - Math.sqrt(Math.pow((nCount - 1) / 2 - x, 2) + Math.pow((nCount - 1) / 2 - y, 2)) / - ((nCount / 2) * Math.sqrt(2)); - if (funcType === FuncType.FuncA) { - let sizeF = (1 - Math.cos(Math.PI * dist)) / 6 + 1 / 5; - const colorF = otherColor1; - const opacityF = Number(qrcode.isDark(x, y)); - if (type === Type.Rect) { - sizeF = sizeF + 0.2; - pointList.push( - ``, - ); - } else if (type === Type.Round) { - pointList.push( - ``, - ); - } - } - if (funcType === FuncType.FuncB) { - let sizeF = 0; - let colorF = otherColor1; - let opacityF = Number(qrcode.isDark(x, y)); - if (dist > 5 / 20 && dist < 8 / 20) { - sizeF = 5 / 10; - colorF = otherColor2; - opacityF = 1; - } else { - sizeF = 1 / 4; - if (type === Type.Rect) { - sizeF = 1 / 4 - 0.1; - } - } - if (type === Type.Rect) { - sizeF = 2 * sizeF + 0.1; - if (qrcode.isDark(x, y)) { - pointList.push( - ``, - ); - } else { - sizeF = sizeF - 0.1; - pointList.push( - ``, - ); - } - } else if (type === Type.Round) { - if (qrcode.isDark(x, y)) { - pointList.push( - ``, - ); - } else { - pointList.push( - ``, - ); - } - } - } - } - } - } - - return pointList; - }, -}; - -export const FuncQr = createRenderer(FuncQrRenderer); -export default FuncQr; diff --git a/src/utils/simple-qrbtf/component/image-fill.qr.ts b/src/utils/simple-qrbtf/component/image-fill.qr.ts deleted file mode 100644 index 20e6610e..00000000 --- a/src/utils/simple-qrbtf/component/image-fill.qr.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { createRenderer, Renderer } from '../renderer'; -import { defaultImage } from '../utils'; - -export interface ImageFillQrOptions { - /** 背景图片base64 */ - image?: string; - color?: string; -} - -const ImageFillRenderer: Renderer = { - defaultProps: { - image: defaultImage, - color: 'rgba(0,0,0,0)', - }, - listPoints: (props) => { - const { qrcode } = props; - if (!qrcode) return []; - - const nCount = qrcode.getModuleCount(); - const pointList = new Array(nCount); - - const color = props.color; - const opacity = props.opacity / 100; - const image = props.image; - - pointList.push( - ``, - ); - pointList.push( - ``, - ); - - for (let x = 0; x < nCount; x++) { - for (let y = 0; y < nCount; y++) { - if (!qrcode.isDark(x, y)) { - pointList.push( - ``, - ); - } - } - } - - return pointList; - }, -}; -export const ImageFillQr = createRenderer(ImageFillRenderer); - -export default ImageFillQr; diff --git a/src/utils/simple-qrbtf/component/image.qr.ts b/src/utils/simple-qrbtf/component/image.qr.ts deleted file mode 100644 index 0acb7f06..00000000 --- a/src/utils/simple-qrbtf/component/image.qr.ts +++ /dev/null @@ -1,159 +0,0 @@ -import { createRenderer, Renderer } from '../renderer'; -import { defaultImage, getTypeTable, QRPointType } from '../utils'; - -enum Type { - Rect = 'rect', - Round = 'round', -} - -enum PosType { - Rect = 'rect', - Round = 'round', - Planet = 'planet', -} - -export interface ImageQrOptions { - /** 背景图片base64 */ - image?: string; - type?: Type; - darkColor?: string; - lightColor?: string; - posType?: PosType; - /** 定位点颜色 */ - posColor?: string; -} - -const ImageQrRenderer: Renderer = { - defaultProps: { - image: defaultImage, - type: Type.Rect, - darkColor: '#000000', - lightColor: '#FFFFFF', - posType: PosType.Rect, - posColor: '#000000', - }, - listPoints: (props) => { - const { qrcode } = props; - if (!qrcode) return []; - - const nCount = qrcode.getModuleCount(); - const typeTable = getTypeTable(qrcode); - const pointList = new Array(nCount); - - let size = props.size / 100 / 3; - const opacity = props.opacity / 100; - - const { type, darkColor, lightColor, posType, posColor, image } = props; - - const vw = [3, -3]; - const vh = [3, -3]; - - if (size <= 0) size = 1.0; - - pointList.push(``); - - for (let x = 0; x < nCount; x++) { - for (let y = 0; y < nCount; y++) { - if ( - typeTable[x][y] === QRPointType.ALIGN_CENTER || - typeTable[x][y] === QRPointType.ALIGN_OTHER || - typeTable[x][y] === QRPointType.TIMING - ) { - if (qrcode.isDark(x, y)) { - if (type === Type.Rect) { - pointList.push( - ``, - ); - } else if (type === Type.Round) - pointList.push( - ``, - ); - } else { - if (type === Type.Rect) { - pointList.push( - ``, - ); - } else if (type === Type.Round) { - pointList.push( - ``, - ); - } - } - } else if (typeTable[x][y] === QRPointType.POS_CENTER) { - if (qrcode.isDark(x, y)) { - if (posType === PosType.Rect) { - pointList.push(``); - } else if (posType === PosType.Round) { - pointList.push(``); - pointList.push(``); - pointList.push( - ``, - ); - } else if (posType === PosType.Planet) { - pointList.push(``); - pointList.push(``); - pointList.push( - ``, - ); - for (let w = 0; w < vw.length; w++) { - pointList.push( - ``, - ); - } - for (let h = 0; h < vh.length; h++) { - pointList.push( - ``, - ); - } - } - } - } else if (typeTable[x][y] === QRPointType.POS_OTHER) { - if (qrcode.isDark(x, y)) { - if (posType === PosType.Rect) { - pointList.push(``); - } - } else { - if (posType === PosType.Rect) { - pointList.push(``); - } - } - } else { - if (qrcode.isDark(x, y)) { - if (type === Type.Rect) - pointList.push( - ``, - ); - else if (type === Type.Round) - pointList.push( - ``, - ); - } else { - if (type === Type.Rect) - pointList.push( - ``, - ); - else if (type === Type.Round) - pointList.push( - ``, - ); - } - } - } - } - - return pointList; - }, -}; - -export const ImageQr = createRenderer(ImageQrRenderer); -export default ImageQr; diff --git a/src/utils/simple-qrbtf/component/index.ts b/src/utils/simple-qrbtf/component/index.ts deleted file mode 100644 index fca5a7be..00000000 --- a/src/utils/simple-qrbtf/component/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -export * from './base.qr'; -export * from './image-fill.qr'; -export * from './image.qr'; -export * from './func.qr'; -export * from './dsj.qr'; -export * from './solid.qr'; -export * from './circle.qr'; -export * from './rand-rect.qr'; -export * from './line.qr'; diff --git a/src/utils/simple-qrbtf/component/line.qr.ts b/src/utils/simple-qrbtf/component/line.qr.ts deleted file mode 100644 index 251c2205..00000000 --- a/src/utils/simple-qrbtf/component/line.qr.ts +++ /dev/null @@ -1,442 +0,0 @@ -import { createRenderer, Renderer } from '../renderer'; -import { getTypeTable, QRPointType, rand } from '../utils'; - -enum PosType { - Rect = 'rect', - Round = 'round', - Planet = 'planet', - RoundRect = 'roundRect', -} - -enum LineDirection { - /** 左-->右 */ - LeftToRight = 'left-right', - /** 上-->左下 */ - UpToDown = 'up-down', - HAndV = 'h-v', - Loop = 'loop', - /** 左上-->右下 */ - TopLeftToBottomRight = 'topLeft-bottomRight', - /** 右上-->左下 */ - TopRightToBottomLeft = 'topRight-bottomLeft', - Cross = 'cross', -} - -export interface LineQrOptions { - /** 数据线条方向 */ - direction?: LineDirection; - /** 数据线条宽度 */ - lineWidth?: number; - /** 数据线条透明度 */ - lineOpacity?: number; - /** 数据线条颜色 */ - lineColor?: string; - posType?: PosType; - /** 定位点颜色 */ - posColor?: string; -} - -const LineQrRenderer: Renderer = { - defaultProps: { - direction: LineDirection.LeftToRight, - posType: PosType.Rect, - lineWidth: 50, - lineOpacity: 100, - lineColor: '#000000', - posColor: '#000000', - }, - listPoints: (props) => { - const { qrcode } = props; - if (!qrcode) return []; - - const nCount = qrcode.getModuleCount(); - const typeTable = getTypeTable(qrcode); - const pointList = []; - - const { direction, posType, posColor, lineColor } = props; - let size = props.size / 100; - const opacity = props.opacity / 100; - - const vw = [3, -3]; - const vh = [3, -3]; - - const sq25 = - 'M32.048565,-1.29480038e-15 L67.951435,1.29480038e-15 C79.0954192,-7.52316311e-16 83.1364972,1.16032014 87.2105713,3.3391588 C91.2846454,5.51799746 94.4820025,8.71535463 96.6608412,12.7894287 C98.8396799,16.8635028 100,20.9045808 100,32.048565 L100,67.951435 C100,79.0954192 98.8396799,83.1364972 96.6608412,87.2105713 C94.4820025,91.2846454 91.2846454,94.4820025 87.2105713,96.6608412 C83.1364972,98.8396799 79.0954192,100 67.951435,100 L32.048565,100 C20.9045808,100 16.8635028,98.8396799 12.7894287,96.6608412 C8.71535463,94.4820025 5.51799746,91.2846454 3.3391588,87.2105713 C1.16032014,83.1364972 5.01544207e-16,79.0954192 -8.63200256e-16,67.951435 L8.63200256e-16,32.048565 C-5.01544207e-16,20.9045808 1.16032014,16.8635028 3.3391588,12.7894287 C5.51799746,8.71535463 8.71535463,5.51799746 12.7894287,3.3391588 C16.8635028,1.16032014 20.9045808,7.52316311e-16 32.048565,-1.29480038e-15 Z'; - - if (size <= 0) size = 1.0; - - const available: Array> = []; - const ava2: Array> = []; - for (let x = 0; x < nCount; x++) { - available[x] = []; - ava2[x] = []; - for (let y = 0; y < nCount; y++) { - available[x][y] = true; - ava2[x][y] = true; - } - } - - for (let x = 0; x < nCount; x++) { - for (let y = 0; y < nCount; y++) { - if (qrcode.isDark(x, y) === false) continue; - - if (typeTable[x][y] === QRPointType.POS_CENTER) { - if (posType === PosType.Rect) { - pointList.push(``); - } else if (posType === PosType.Round) { - pointList.push(``); - pointList.push( - ``, - ); - } else if (posType === PosType.Planet) { - pointList.push(``); - pointList.push( - ``, - ); - for (let w = 0; w < vw.length; w++) { - pointList.push( - ``, - ); - } - for (let h = 0; h < vh.length; h++) { - pointList.push( - ``, - ); - } - } else if (posType === PosType.RoundRect) { - pointList.push(``); - pointList.push( - ``, - ); - } - } else if (typeTable[x][y] === QRPointType.POS_OTHER) { - if (posType === PosType.Rect) { - pointList.push(``); - } - } else { - if (direction === LineDirection.LeftToRight) { - if (x === 0 || (x > 0 && (!qrcode.isDark(x - 1, y) || !ava2[x - 1][y]))) { - const start = 0; - let end = 0; - let ctn = true; - while (ctn && x + end < nCount) { - if (qrcode.isDark(x + end, y) && ava2[x + end][y]) { - end++; - } else { - ctn = false; - } - } - if (end - start > 1) { - for (let i = start; i < end; i++) { - ava2[x + i][y] = false; - available[x + i][y] = false; - } - pointList.push( - ``, - ); - } - } - if (available[x][y]) { - pointList.push( - ``, - ); - } - } - - if (direction === LineDirection.UpToDown) { - if (y === 0 || (y > 0 && (!qrcode.isDark(x, y - 1) || !ava2[x][y - 1]))) { - const start = 0; - let end = 0; - let ctn = true; - while (ctn && y + end < nCount) { - if (qrcode.isDark(x, y + end) && ava2[x][y + end]) { - end++; - } else { - ctn = false; - } - } - if (end - start > 1) { - for (let i = start; i < end; i++) { - ava2[x][y + i] = false; - available[x][y + i] = false; - } - pointList.push( - ``, - ); - } - } - if (available[x][y]) { - pointList.push( - ``, - ); - } - } - if (direction === LineDirection.HAndV) { - if (y === 0 || (y > 0 && (!qrcode.isDark(x, y - 1) || !ava2[x][y - 1]))) { - const start = 0; - let end = 0; - let ctn = true; - while (ctn && y + end < nCount) { - if (qrcode.isDark(x, y + end) && ava2[x][y + end] && end - start <= 3) { - end++; - } else { - ctn = false; - } - } - if (end - start > 1) { - for (let i = start; i < end; i++) { - ava2[x][y + i] = false; - available[x][y + i] = false; - } - pointList.push( - ``, - ); - } - } - if (x === 0 || (x > 0 && (!qrcode.isDark(x - 1, y) || !ava2[x - 1][y]))) { - const start = 0; - let end = 0; - let ctn = true; - while (ctn && x + end < nCount) { - if (qrcode.isDark(x + end, y) && ava2[x + end][y] && end - start <= 3) { - end++; - } else { - ctn = false; - } - } - if (end - start > 1) { - for (let i = start; i < end; i++) { - ava2[x + i][y] = false; - available[x + i][y] = false; - } - pointList.push( - ``, - ); - } - } - if (available[x][y]) { - pointList.push( - ``, - ); - } - } - - if (direction === LineDirection.Loop) { - if (Number(x > y) ^ Number(x + y < nCount)) { - if (y === 0 || (y > 0 && (!qrcode.isDark(x, y - 1) || !ava2[x][y - 1]))) { - const start = 0; - let end = 0; - let ctn = true; - while (ctn && y + end < nCount) { - if (qrcode.isDark(x, y + end) && ava2[x][y + end] && end - start <= 3) { - end++; - } else { - ctn = false; - } - } - if (end - start > 1) { - for (let i = start; i < end; i++) { - ava2[x][y + i] = false; - available[x][y + i] = false; - } - pointList.push( - ``, - ); - } - } - } else { - if (x === 0 || (x > 0 && (!qrcode.isDark(x - 1, y) || !ava2[x - 1][y]))) { - const start = 0; - let end = 0; - let ctn = true; - while (ctn && x + end < nCount) { - if (qrcode.isDark(x + end, y) && ava2[x + end][y] && end - start <= 3) { - end++; - } else { - ctn = false; - } - } - if (end - start > 1) { - for (let i = start; i < end; i++) { - ava2[x + i][y] = false; - available[x + i][y] = false; - } - pointList.push( - ``, - ); - } - } - } - if (available[x][y]) { - pointList.push( - ``, - ); - } - } - if (direction === LineDirection.TopLeftToBottomRight) { - if ( - y === 0 || - x === 0 || - (y > 0 && x > 0 && (!qrcode.isDark(x - 1, y - 1) || !ava2[x - 1][y - 1])) - ) { - const start = 0; - let end = 0; - let ctn = true; - while (ctn && y + end < nCount && x + end < nCount) { - if (qrcode.isDark(x + end, y + end) && ava2[x + end][y + end]) { - end++; - } else { - ctn = false; - } - } - if (end - start > 1) { - for (let i = start; i < end; i++) { - ava2[x + i][y + i] = false; - available[x + i][y + i] = false; - } - pointList.push( - ``, - ); - } - } - if (available[x][y]) { - pointList.push( - ``, - ); - } - } - if (direction === LineDirection.TopRightToBottomLeft) { - if ( - x === 0 || - y === nCount - 1 || - (x > 0 && y < nCount - 1 && (!qrcode.isDark(x - 1, y + 1) || !ava2[x - 1][y + 1])) - ) { - const start = 0; - let end = 0; - let ctn = true; - while (ctn && x + end < nCount && y - end >= 0) { - if (qrcode.isDark(x + end, y - end) && available[x + end][y - end]) { - end++; - } else { - ctn = false; - } - } - if (end - start > 1) { - for (let i = start; i < end; i++) { - ava2[x + i][y - i] = false; - available[x + i][y - i] = false; - } - pointList.push( - ``, - ); - } - } - if (available[x][y]) { - pointList.push( - ``, - ); - } - } - if (direction === LineDirection.Cross) { - if ( - x === 0 || - y === nCount - 1 || - (x > 0 && y < nCount - 1 && (!qrcode.isDark(x - 1, y + 1) || !ava2[x - 1][y + 1])) - ) { - const start = 0; - let end = 0; - let ctn = true; - while (ctn && x + end < nCount && y - end >= 0) { - if (qrcode.isDark(x + end, y - end) && ava2[x + end][y - end]) { - end++; - } else { - ctn = false; - } - } - if (end - start > 1) { - for (let i = start; i < end; i++) { - ava2[x + i][y - i] = false; - } - pointList.push( - ``, - ); - } - } - if ( - y === 0 || - x === 0 || - (y > 0 && x > 0 && (!qrcode.isDark(x - 1, y - 1) || !available[x - 1][y - 1])) - ) { - const start = 0; - let end = 0; - let ctn = true; - while (ctn && y + end < nCount && x + end < nCount) { - if (qrcode.isDark(x + end, y + end) && available[x + end][y + end]) { - end++; - } else { - ctn = false; - } - } - if (end - start > 1) { - for (let i = start; i < end; i++) { - available[x + i][y + i] = false; - } - pointList.push( - ``, - ); - } - } - pointList.push( - ``, - ); - } - } - } - } - - return pointList; - }, -}; - -export const LineQr = createRenderer(LineQrRenderer); -export default LineQr; diff --git a/src/utils/simple-qrbtf/component/rand-rect.qr.ts b/src/utils/simple-qrbtf/component/rand-rect.qr.ts deleted file mode 100644 index fa9fbcae..00000000 --- a/src/utils/simple-qrbtf/component/rand-rect.qr.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { createRenderer, Renderer } from '../renderer'; -import { rand } from '../utils'; - -// eslint-disable-next-line @typescript-eslint/ban-types -export declare type RandRectOptions = {}; - -const RandRectRenderer: Renderer = { - defaultProps: {}, - listPoints: (props) => { - const { qrcode } = props; - if (!qrcode) return []; - - const nCount = qrcode.getModuleCount(); - const pointList = []; - - const randArr = []; - for (let row = 0; row < nCount; row++) { - for (let col = 0; col < nCount; col++) { - randArr.push([row, col]); - } - } - randArr.sort(function () { - return 0.5 - Math.random(); - }); - - for (let i = 0; i < randArr.length; i++) { - const row = randArr[i][0]; - const col = randArr[i][1]; - if (qrcode.isDark(row, col)) { - const tempRand = rand(0.8, 1.3); - const randNum = rand(50, 230); - const tempRGB = [ - 'rgb(' + - Math.floor(20 + randNum) + - ',' + - Math.floor(170 - randNum / 2) + - ',' + - Math.floor(60 + randNum * 2) + - ')', - 'rgb(' + - Math.floor(-20 + randNum) + - ',' + - Math.floor(130 - randNum / 2) + - ',' + - Math.floor(20 + randNum * 2) + - ')', - ]; - const width = 0.15; - - pointList.push( - ``, - ); - pointList.push( - ``, - ); - } - } - return pointList; - }, -}; - -export const RandRectQr = createRenderer(RandRectRenderer); -export default RandRectQr; diff --git a/src/utils/simple-qrbtf/component/solid.qr.ts b/src/utils/simple-qrbtf/component/solid.qr.ts deleted file mode 100644 index e189ce3b..00000000 --- a/src/utils/simple-qrbtf/component/solid.qr.ts +++ /dev/null @@ -1,193 +0,0 @@ -// 25D - -import { createRenderer, getDefaultIcon, Renderer, RendererOptions } from '../renderer'; -import { getExactValue, getIdNum, getTypeTable, QRPointType } from '../utils'; - -const X = [Math.sqrt(3) / 2, 1 / 2]; -const Y = [-Math.sqrt(3) / 2, 1 / 2]; -const Z = [0, 0]; - -const matrixString = - 'matrix(' + - String(X[0]) + - ', ' + - String(X[1]) + - ', ' + - String(Y[0]) + - ', ' + - String(Y[1]) + - ', ' + - String(Z[0]) + - ', ' + - String(Z[1]) + - ')'; - -export interface SolidQrOptions { - upColor?: string; - leftColor?: string; - rightColor?: string; - height?: number; - lpHeight?: number; -} - -const SolidQrRenderer: Renderer = { - defaultProps: { - upColor: '#333', - leftColor: '#666', - rightColor: '#999', - height: 0.5, - lpHeight: 1, - }, - listPoints: (props) => { - const { qrcode } = props; - if (!qrcode) return []; - - const { upColor, leftColor, rightColor } = props; - const nCount = qrcode.getModuleCount(); - const typeTable = getTypeTable(qrcode); - const pointList = []; - - const size = 1.001; - const size2 = 1.001; - let height = props.height!; - let height2 = props.lpHeight!; - - if (height <= 0) height = 1.0; - if (height2 <= 0) height2 = 1.0; - - for (let x = 0; x < nCount; x++) { - for (let y = 0; y < nCount; y++) { - if (qrcode.isDark(x, y) === false) { - // do nothing; - } else if (typeTable[x][y] === QRPointType.POS_OTHER || typeTable[x][y] === QRPointType.POS_CENTER) { - pointList.push( - ``, - ); - pointList.push( - ``, - ); - pointList.push( - ``, - ); - } else { - pointList.push( - ``, - ); - pointList.push( - ``, - ); - pointList.push( - ``, - ); - } - } - } - - return pointList; - }, - getViewBox: ({ qrcode }) => { - if (!qrcode) return '0 0 0 0'; - - const nCount = qrcode.getModuleCount(); - return String(-nCount) + ' ' + String(-nCount / 2) + ' ' + String(nCount * 2) + ' ' + String(nCount * 2); - }, - drawIcon: (props) => { - const iconMode = getExactValue(props.icon.enabled, 0); - if (iconMode === 1) { - return defaultDrawIcon(props); - } else { - return builtinDrawIcon(props); - } - }, -}; - -function builtinDrawIcon(props: RendererOptions) { - const { qrcode, icon } = props; - if (!qrcode) return []; - - let id = 0; - const nCount = qrcode.getModuleCount(); - const pointList = []; - const sq25 = - 'M32.048565,-1.29480038e-15 L67.951435,1.29480038e-15 C79.0954192,-7.52316311e-16 83.1364972,1.16032014 87.2105713,3.3391588 C91.2846454,5.51799746 94.4820025,8.71535463 96.6608412,12.7894287 C98.8396799,16.8635028 100,20.9045808 100,32.048565 L100,67.951435 C100,79.0954192 98.8396799,83.1364972 96.6608412,87.2105713 C94.4820025,91.2846454 91.2846454,94.4820025 87.2105713,96.6608412 C83.1364972,98.8396799 79.0954192,100 67.951435,100 L32.048565,100 C20.9045808,100 16.8635028,98.8396799 12.7894287,96.6608412 C8.71535463,94.4820025 5.51799746,91.2846454 3.3391588,87.2105713 C1.16032014,83.1364972 5.01544207e-16,79.0954192 -8.63200256e-16,67.951435 L8.63200256e-16,32.048565 C-5.01544207e-16,20.9045808 1.16032014,16.8635028 3.3391588,12.7894287 C5.51799746,8.71535463 8.71535463,5.51799746 12.7894287,3.3391588 C16.8635028,1.16032014 20.9045808,7.52316311e-16 32.048565,-1.29480038e-15 Z'; - - // draw icon - if (icon) { - const iconMode = getExactValue(icon.enabled, 0); - const { scale } = icon; - - const iconSize = Number((nCount * (scale > 33 ? 33 : scale)) / 100); - const iconXY = (nCount - iconSize) / 2; - - if (icon && iconMode) { - const randomIdDefs = getIdNum(); - const randomIdClips = getIdNum(); - const builtinIcon = getDefaultIcon(iconMode); - pointList.push(` - - -`); - pointList.push(` - - - - - - - - - - ${builtinIcon} - - -`); - } - } - - return pointList; -} - -function defaultDrawIcon(props: RendererOptions) { - const { qrcode, icon } = props; - if (!qrcode) return []; - - let id = 0; - const nCount = qrcode.getModuleCount(); - const pointList = []; - const sq25 = - 'M32.048565,-1.29480038e-15 L67.951435,1.29480038e-15 C79.0954192,-7.52316311e-16 83.1364972,1.16032014 87.2105713,3.3391588 C91.2846454,5.51799746 94.4820025,8.71535463 96.6608412,12.7894287 C98.8396799,16.8635028 100,20.9045808 100,32.048565 L100,67.951435 C100,79.0954192 98.8396799,83.1364972 96.6608412,87.2105713 C94.4820025,91.2846454 91.2846454,94.4820025 87.2105713,96.6608412 C83.1364972,98.8396799 79.0954192,100 67.951435,100 L32.048565,100 C20.9045808,100 16.8635028,98.8396799 12.7894287,96.6608412 C8.71535463,94.4820025 5.51799746,91.2846454 3.3391588,87.2105713 C1.16032014,83.1364972 5.01544207e-16,79.0954192 -8.63200256e-16,67.951435 L8.63200256e-16,32.048565 C-5.01544207e-16,20.9045808 1.16032014,16.8635028 3.3391588,12.7894287 C5.51799746,8.71535463 8.71535463,5.51799746 12.7894287,3.3391588 C16.8635028,1.16032014 20.9045808,7.52316311e-16 32.048565,-1.29480038e-15 Z'; - - // draw icon - if (icon) { - const iconEnabled = getExactValue(icon.enabled, 0); - const { src, scale } = icon; - - const iconSize = Number((nCount * (scale > 33 ? 33 : scale)) / 100); - const iconXY = (nCount - iconSize) / 2; - - if (icon && iconEnabled) { - const randomIdDefs = getIdNum(); - const randomIdClips = getIdNum(); - - pointList.push(` - - `); - pointList.push(` - - - - - - - - - - `); - } - } - - return pointList; -} - -export const SolidQr = createRenderer(SolidQrRenderer); -export default SolidQr; diff --git a/src/utils/simple-qrbtf/helper.ts b/src/utils/simple-qrbtf/helper.ts deleted file mode 100644 index fa45820c..00000000 --- a/src/utils/simple-qrbtf/helper.ts +++ /dev/null @@ -1,13 +0,0 @@ -export type DeepPartial = { - [P in keyof T]?: DeepPartial; -}; - -export function merge(target: DeepPartial, ...sources: (DeepPartial | undefined)[]): T { - for (const source of sources) { - if (!source) { - continue; - } - Object.assign(target, source); - } - return target as T; -} diff --git a/src/utils/simple-qrbtf/index.ts b/src/utils/simple-qrbtf/index.ts deleted file mode 100644 index ec654350..00000000 --- a/src/utils/simple-qrbtf/index.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { CoreQrbtfStyles } from '@/types'; -import { Data } from '../Data'; -import { BaseQr, BaseQrOptions, CircleQr, CircleQrOption, DsjQR, DSJQrOptions, FuncQr, FuncQrOptions, ImageFillQr, ImageFillQrOptions, ImageQr, ImageQrOptions, LineQr, LineQrOptions, RandRectQr, SolidQr, SolidQrOptions } from './component'; -import { DeepPartial } from './helper'; -import { DefaultRendererOptions, RendererOptions } from './renderer'; - -export enum SimpleQrType { - base = 'base', - circle = 'circle', - dsj = 'dsj', - randRect = 'randRect', - line = 'line', - solid = 'solid', - image = 'image', - func = 'func', - imageFill = 'imageFill', -} - -export const SimpleQr = { - [SimpleQrType.base]: BaseQr, - [SimpleQrType.circle]: CircleQr, - [SimpleQrType.dsj]: DsjQR, - [SimpleQrType.randRect]: RandRectQr, - [SimpleQrType.line]: LineQr, - [SimpleQrType.solid]: SolidQr, - [SimpleQrType.image]: ImageQr, - [SimpleQrType.func]: FuncQr, - [SimpleQrType.imageFill]: ImageFillQr, -}; - -const SimpleQrOptions = { - [SimpleQrType.base]: (content: string, Option: any): DeepPartial> => { - return { - content, ...Data.getData(Option, ['size']) - } - }, - [SimpleQrType.circle]: (content: string, Option: any): DeepPartial> => { - return { - content, ...Data.getData(Option, ['size']) - } - }, - [SimpleQrType.dsj]: (content: string, Option: any): DeepPartial> => { - return { - content, ...Data.getData(Option, ['size']) - } - }, - [SimpleQrType.randRect]: (content: string, Option: any): DeepPartial => { - return { - content, ...Data.getData(Option, ['size']) - } - }, - [SimpleQrType.line]: (content: string, Option: any): DeepPartial> => { - return { - content, ...Data.getData(Option, ['size']) - } - }, - [SimpleQrType.solid]: (content: string, Option: any): DeepPartial> => { - return { - content, ...Data.getData(Option, ['size']) - } - }, - [SimpleQrType.image]: (content: string, Option: any): DeepPartial> => { - return { - content, ...Data.getData(Option, ['size']) - } - }, - [SimpleQrType.func]: (content: string, Option: any): DeepPartial> => { - return { - content, ...Data.getData(Option, ['size']) - } - }, - [SimpleQrType.imageFill]: (content: string, Option: any): DeepPartial> => { - return { - content, ...Data.getData(Option, ['size']) - } - } -}; - -export const getSimpleQrOption = (type: T, content: string, Option: CoreQrbtfStyles) => SimpleQrOptions[type](content, Option); \ No newline at end of file diff --git a/src/utils/simple-qrbtf/renderer.ts b/src/utils/simple-qrbtf/renderer.ts deleted file mode 100644 index 5b54740d..00000000 --- a/src/utils/simple-qrbtf/renderer.ts +++ /dev/null @@ -1,286 +0,0 @@ -import { DeepPartial, merge } from './helper'; -import { arrToStr, encodeData, getExactValue, getIdNum } from './utils'; -import QRCode from './utils/qrcode'; - -export function defaultViewBox({ qrcode }: T) { - if (!qrcode) return '0 0 0 0'; - - const nCount = qrcode.getModuleCount(); - return ( - String(-nCount / 9 - 2) + - ' ' + - String(-nCount / 9 + 2) + - ' ' + - String(nCount + (nCount / 9) + 3) + - ' ' + - String(nCount + (nCount / 9) + 3) - ); -} - -export function defaultDrawIcon({ qrcode, icon }: T) { - if (!qrcode) return []; - - const nCount = qrcode.getModuleCount(); - const pointList = []; - const sq25 = - 'M32.048565,-1.29480038e-15 L67.951435,1.29480038e-15 C79.0954192,-7.52316311e-16 83.1364972,1.16032014 87.2105713,3.3391588 C91.2846454,5.51799746 94.4820025,8.71535463 96.6608412,12.7894287 C98.8396799,16.8635028 100,20.9045808 100,32.048565 L100,67.951435 C100,79.0954192 98.8396799,83.1364972 96.6608412,87.2105713 C94.4820025,91.2846454 91.2846454,94.4820025 87.2105713,96.6608412 C83.1364972,98.8396799 79.0954192,100 67.951435,100 L32.048565,100 C20.9045808,100 16.8635028,98.8396799 12.7894287,96.6608412 C8.71535463,94.4820025 5.51799746,91.2846454 3.3391588,87.2105713 C1.16032014,83.1364972 5.01544207e-16,79.0954192 -8.63200256e-16,67.951435 L8.63200256e-16,32.048565 C-5.01544207e-16,20.9045808 1.16032014,16.8635028 3.3391588,12.7894287 C5.51799746,8.71535463 8.71535463,5.51799746 12.7894287,3.3391588 C16.8635028,1.16032014 20.9045808,7.52316311e-16 32.048565,-1.29480038e-15 Z'; - - if (icon) { - const iconEnabled = getExactValue(icon.enabled, 0); - const { src, scale } = icon; - - const iconSize = Number((nCount * (scale > 33 ? 33 : scale)) / 100); - const iconXY = (nCount - iconSize) / 2; - - if (icon && iconEnabled) { - const randomIdDefs = getIdNum(); - const randomIdClips = getIdNum(); - - const transform = `translate(${String(iconXY)},${String(iconXY)}) scale(${String(iconSize / 100)},${String(iconSize / 100)})`; - pointList.push( - ``, - ); - - const pathTransform = - 'translate(' + - String(iconXY) + - ',' + - String(iconXY) + - ') ' + - 'scale(' + - String(iconSize / 100) + - ',' + - String(iconSize / 100) + - ')'; - - pointList.push(` - - - - - - - - - - -`); - } - } - - return pointList; -} - -export function getDefaultIcon(iconMode: number) { - const WeChatIconSmall = ` - - - - -`; - - const WeChatIcon = ` - - - - - - `; - - const WeChatPayIcon = ` - - - - - `; - - const AlipayIcon = ` - - - - - `; - - if (iconMode === 2) { - return WeChatIconSmall; - } else if (iconMode === 3) { - return WeChatIcon; - } else if (iconMode === 4) { - return WeChatPayIcon; - } else if (iconMode === 5) { - return AlipayIcon; - } - return ''; -} - -export function builtinDrawIcon({ qrcode, icon }: T) { - if (!qrcode) return []; - - const nCount = qrcode.getModuleCount(); - const pointList = []; - const sq25 = - 'M32.048565,-1.29480038e-15 L67.951435,1.29480038e-15 C79.0954192,-7.52316311e-16 83.1364972,1.16032014 87.2105713,3.3391588 C91.2846454,5.51799746 94.4820025,8.71535463 96.6608412,12.7894287 C98.8396799,16.8635028 100,20.9045808 100,32.048565 L100,67.951435 C100,79.0954192 98.8396799,83.1364972 96.6608412,87.2105713 C94.4820025,91.2846454 91.2846454,94.4820025 87.2105713,96.6608412 C83.1364972,98.8396799 79.0954192,100 67.951435,100 L32.048565,100 C20.9045808,100 16.8635028,98.8396799 12.7894287,96.6608412 C8.71535463,94.4820025 5.51799746,91.2846454 3.3391588,87.2105713 C1.16032014,83.1364972 5.01544207e-16,79.0954192 -8.63200256e-16,67.951435 L8.63200256e-16,32.048565 C-5.01544207e-16,20.9045808 1.16032014,16.8635028 3.3391588,12.7894287 C5.51799746,8.71535463 8.71535463,5.51799746 12.7894287,3.3391588 C16.8635028,1.16032014 20.9045808,7.52316311e-16 32.048565,-1.29480038e-15 Z'; - - // draw icon - if (icon) { - const iconMode = getExactValue(icon.enabled, 0); - - const { scale } = icon; - - const iconSize = Number((nCount * (scale > 33 ? 33 : scale)) / 100); - const iconXY = (nCount - iconSize) / 2; - - if (icon && iconMode) { - const randomIdDefs = getIdNum(); - const randomIdClips = getIdNum(); - - const builtinIcon = getDefaultIcon(iconMode); - - const transform = - 'translate(' + - String(iconXY) + - ',' + - String(iconXY) + - ') ' + - 'scale(' + - String(iconSize / 100) + - ',' + - String(iconSize / 100) + - ')'; - - pointList.push( - ``, - ); - - const defsTransform = - 'translate(' + - String(iconXY) + - ',' + - String(iconXY) + - ') ' + - 'scale(' + - String(iconSize / 100) + - ',' + - String(iconSize / 100) + - ')'; - const pathTransform = - 'translate(' + - String(iconXY) + - ',' + - String(iconXY) + - ') ' + - 'scale(' + - String(iconSize / 100) + - ',' + - String(iconSize / 100) + - ')'; - pointList.push(` - - - - - - - - - - ${builtinIcon} - - - - `); - } - } - - return pointList; -} - -function drawIcon(props: T) { - const iconMode = getExactValue(props.icon.enabled, 0); - if (iconMode === 1) { - return defaultDrawIcon(props); - } else { - return builtinDrawIcon(props); - } -} - -export interface DefaultRendererOptions { - qrcode: QRCode; - content: string; - /** 纠错等级H为最高 */ - level: 'L' | 'M' | 'Q' | 'H'; - size: number; - /** 透明度 */ - opacity: number; - icon: { - enabled: number; - scale: number; - src: string; - }; -} - -export declare type RendererOptions = T & DefaultRendererOptions; - -export interface Renderer { - getViewBox?: (props: RendererOptions) => string; - listPoints: (props: RendererOptions) => string[]; - drawIcon?: (props: RendererOptions) => string[]; - beforeListing?: (props: RendererOptions) => string[]; - - defaultProps: T; -} - -export function createRenderer(rendererProps: Renderer) { - const renderer = merge( - { - getViewBox: defaultViewBox, - drawIcon: drawIcon, - listPoints: (_props: T) => { - return []; - }, - beforeListing: (_props: T) => { - return []; - }, - }, - rendererProps, - ) as Required>; - - return (props?: DeepPartial>) => { - const newProps = merge( - { - level: 'H', - icon: { - enabled: 0, - scale: 100, - src: '', - }, - opacity: 100, - size: 100, - }, - rendererProps.defaultProps, - props, - ) as RendererOptions; - - newProps.content = newProps.content || '无二维码内容'; - newProps.level = newProps.icon ? 'H' : newProps.level; - newProps.qrcode = - newProps.qrcode || - encodeData({ - text: newProps.content, - correctLevel: newProps.level, - typeNumber: -1, - }); - - const template = []; - const viewBox = renderer.getViewBox(newProps); - template.push( - ``, - ); - template.push(arrToStr(renderer.beforeListing(newProps))); - template.push(arrToStr(renderer.listPoints(newProps))); - template.push(arrToStr(renderer.drawIcon(newProps))); - template.push(``); - - return arrToStr(template).split('\n').join(' '); - }; -} diff --git a/src/utils/simple-qrbtf/utils/data.ts b/src/utils/simple-qrbtf/utils/data.ts deleted file mode 100644 index 572a070f..00000000 --- a/src/utils/simple-qrbtf/utils/data.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const defaultImage = - 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKgAAACFCAMAAAD4p0NuAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABFUExURUxpcVybvlqZvuzy9/P2+FWWvF+fwl+cwV+cwGaZxWykxYCxzaPG28Xc6dzq8ZO91Ovz97XR4tLk7v37+v////f5+/39/S5meukAAAATdFJOUwAyVv7+RQwUIgRtgaPF3JTrtdJR0xinAAANoklEQVR42tSb6YKjKBCAV8FoQMEDeP9H3bpATEw6SfePDNO7s6YNfhbUzf7337eM63//wLjy+Ac4LzC+HxQ4exjfTwqcQ9c2X0+KAu2s774fFAW6rO0ApF8P2k4zrf33g66z+RdAG+PiPwI6B/vtoKj0jVXBd8P3g3Y+pbH7crW/XsE6jSktXw9KZjTFrzekbEZTdN+u9qhL7Rrj/C+AmjlGZb88LCFQFXWCsKT/YlCOnaLWAe3TN4Oi0o8BQKe31f7vEpgXZmLrBKDpbfuEc1/+hBQn+mkmjp0Q9G21p0zrL3ItztkuP4KC0ietY3pT7XF3D03/BzaNJhp+eDiFJBqUibXp9adSMNOaP8hgQJ59Z9rnpODpe9ClCKhheRu088sfOF72jT+sJ920BJKoeysbYS3U5tdugpbG6OfryevnUoxRb+qdh/I312B/HXTRG/vw3Ohw1By3iAN80+sPxaJFZ1X89dpfeeUDuvDHDkfMPXHGd0z+lVc+KjRqvyGlMg3aHdHl69P1I062pC950atM77SKNP/l+vG4sKw2UpEHpCwWq2HlafGD74afd6nMjtNHpTCOHeABaLBvf/jPDz84EQh02+jp/YmHErHA9iBQ+FfKL3X9wdthUa2B6bVSuEuRlMZFfi783/nDS3/8vL4NOBswOxuAzgZJ+1sfxWJpOk+QrE5hJNInqPwtmLxrrQOBIunYdk0zfDgamAk5I5A6CzMNx8KirF7TWpR6Zt3goY3I/8neR0yzkDyJdPWm7T4crfEuICaSzoth1PL8vMvaUQMnk/JWXW7uPPG4OPk0R1UG5DHrMn40lnUOuO48UlATvvRuz5ETV28KJE9hhbGFFeX/yOLACw4tUlaYODRscB7h3ZE2ebyghnny7bCDgnHxkw77LXmnhm0dKdR4DLqqG04UaiyshRgdc3wRVEDga2o9gnbWhUrqsYgUbvVPQGnpxzkeBeqm+2X1I/Av/unKT7L0Ii0UZ1n6Ky/90Bq7uEhvFHk3435ObrGG6+QPTS+irjXpfKpN7QT73pnnugQv7bK4klpg32Ud2f1BA/fZRYVd8CHyC7E5O0tjrlnt0SuVdR/BPt0YKLhjxbUPs62MV3Nunnj5A74U3dtfqtH32c7ElDknMmQ4+keo4pbAT+wi1TULG3HwNg7yG02kYPIG/Ky+owy4lQ0+eHAScceg/e4wMqrX8kYjYfby7oX1TKjDHWjDQu0H8TYT6RJqE4QQPGu+hT1uAd1daNfZCSBkio5o9tsaDAlInvgy9KgBX2zfAech+Q4aAbQ1pmUPJQ+384aYmp0IDthoxfVcKgAmgKCkbb0KggGuyNM2ZInJBLidUfLMiftrWRe/e4nrc1CQaOudg6+wLpDsgBRSRr0l8bAw6TSD6TFdMxTEQe7lMA82K0oWgwd80ZDmdSybEZej8/T7TpYG/Wogy5tt/w3piURxpcGOKofvx4NkGrXv5NrDpDjraOjR+WMeC2wQw+qfMOIAJrBHcLsGq17d59IGAs1X4Fdx1Ta4y7cnkd8paELRQtKd5knG4sA8zUu+TKIJwcGkuGhTNRx8bRb7k+DlEHR3VfuYt03tV3HTMlKazH3Y/xAUSFXlixI/SEa214AKk0K4fuOfdh+FAV8GPUzBDqq6ilpHQUU7+DIoYOr9q8eRdmedQGGMKr+JuxfNpKBQOyjKOA+82i9iLA9TOvg3QPELabVnY6k95di21a/mO1LIMytQsO88zIhXi8lTpkoQ8HLNexIFrQTVF8vKAy7xwbESWK1LLtyBzm0NOmaPi28LiXVHT+gsmmoRcIJP+1dBZQmW9iTeryWkQO/BI8wOxuzMCShYf3sApRkhPU/0O7n0oeyySHnMq1qvRaInoKzFMesKSLlok91Bd7VRxt+CNpTeUUyALqFhUEENWF/ofzL49R59CprXlUD5qSlWoGuxbLa7By0fBUpDDhI9L5w9MU9K9ujtOJHoPWiwZed2t6BVTLKJtyPQ7QPQbIdWfzeOdvEJ6K5/fH/MygRpU9qzFkqYPpaoznb0Pt9YTbtrPYVTD0D3cZAo5GnxoHEBxNHaT0GzBp5kRv4FiSbQK7/QgHigNvjO7UmTluQeXPEai2f6RKKQHN4PW9nF8ATU8XvFgzJt4c5+IWpKuw/8RKKnylQv5XNQdplH0Lw7N03/8B9M894D1QVUZfPU3GdGR9DhHdDk5pJW613Kyu2O6TVQXZb+JTv6Nigo0+hS2KWq0eqPxqb3lEmDSzws/Q8u9FXQVPv61q9VrQJiWvO+edKzOS79ISA52sVPQdHgj4lDxYgBVDb474BG8L21wZ/M2Vh+B4q5y/hLF5omAhWBYiRzNmL6JejQ0Veo3rwHJRI2PwHdazoJ5qklKslFXS4LdZnrE1CqNHRWn4d56rFEmx1UR0+gOa9wKw0d8+BPXMo28WfQcK9MsCU7FikKFK+bzr4g0WavPWm03yLRCNmwxD/SawFORfkuKROJV2NF4jmoMgfQJW90z8ZKrsagXwAtlXFIAgQ0BjVRcYPj4gw6i4qSb5wxT8foMkfBp6DuAAo5QS4botJX1U79dOm53afrLYqPDWnGqiF7pSMoVT7cOi2jNVJLGZ6CUhZamc3zdDkVTn16voybl7GyosA1TgtDSE3nFrSReDiX0gqovgfFLXpY+nl1PFYsQJQLVzJn9Rh0yaAJHRGY49zksJZX9g7U0IvkAiXewNvxDjShb6tAcRu3ZefDdPmCDkSwSB+BNm3WJa0sZ16YANtxnSN8cArq0kyVqV3kYqtuQLE80VWgxC3uzWrK+eWy9VTTUQ8kyn1lXQkUp6CWTgopRvL1t6BoSzi9nKhA1zRYEkuUUt7Go5MoH1WEwFBQ7EAFUjxZECGvl90DpBw9qUegQ5tXHvNpKrFPc5BYhrX8CAovsoacEFPtsTMzgiZ47BFUj1QfzaBBSWVX8voYSaRchm2wRPgItPSVaVARA4KwGKogFksZBZRL3uCnk+RMyDovEKMlAh27GnSacIv3Agq3rlJYp/bdRHNyXi9VaTPFdArKHekxFjcPptwhpapyJgfLW0vUjBN3X3AlE9cSV3KymHQwaCLQNhfG2e46rtZzdRlL/XKwgKvBXIX2K+Qk93b0IFBceDOlmCuOe3Y316DwBJJnTJzqcADAf4H0AVQ+s1wJx8J55zX2nKTcTF2RiTk1yrQUoqkJMc14bOBQ0BGBphLaY/NDlYoj+nqyxMsB1M9RApUofwQ3UZxQgUopnk4qmb0qjn0mnTmRNE7Ft9BL2NtzTaTy4j4hGmmNyxUSxXmycuB/vG0PSw8mYVwmzHwkrALbSAqNtcIbUG6FYRtMmj7UKVw1GhQRKMkj5vo+7dWmwbbI7dmOheCi9m1nU5YnvOU8jZ6aI13T3fh6btJZvzgtksUf9OkCujEoF7ry4QXardh7DYKpRaS8dArypkY6UcfjCLzwXvP+9BSMBN6t3Jo8OJ6Dwec1QkM2rluWIHb1BgKlzRBsXr+r/C9WFzKFsBIy16YzJ4dqkyFJytG+6+FUAexKPEoC+5nSAdij5PC9tAf7fPziCFqaWmR0SeMDyXMYZOljDfpf1QptsEdM+7NQRi7aQxwGKnS5///b+AwK2vqoFyycYuvMrKBNcc1BkSjtcASVFphoRrdgd0imGOo9entCLDdtzZLKFmXMYqPOGnY5bNIRi2kiJZgE/EVabenb9UdQOSfEoORsFzROZYoiUQia7qvw1VGNI+fSdg8OlcjhI6CiRhE3NC90LmVBLy+NaeGvQKkYfGEF5n520LnXRptQJBrOTtjndjYGIHl3wt9BDr+cdsDZMmG9r2qp8/tCROJwb1Ng3JCYMigEaZ14QLhtwcbhNObu5eVaQGMKp8fn5CENH3irWyCPzuhQAjJNtjzjmvWL2+lgeyCkhfgZBbhLlOfEdxwn7Jfyu+QpMiiqkrbn59bLubVU9F2ZZ+fj8DiqOWBWB6EkIjXoIwaWqEYFwC4c7dAO07G2LbaBp9glSmHnkxMidIZQV62Fx0eeLpehOhxxe9RAaBvuW2eJYl+TDzT00tHnwwJ5ih1U3uihkOikIa99JNlf/m/ninYbBmGg0oRmDJF2WsT/f+owNoS1KaSSq9pS+woPDonPdrm7Dolsh2xA8FwoC5T1kJuxyiI/ZVsncLZbcxu7r1hmnGmeUuJuUse7tJmuWZC7t4PQufBAUqBxfL5ktt+2+g+e84musR63CIxFLlC9+R6t3zYXc0uR7rug6yVIrpdvTyrOH1f3mJRZMXIJnrjUIhjo74JDRJPniYFCkRrmHhkb5kPKeSb9DfLNkJRx7rHrYaujJ+pSy1f8RLk0rMg3e0BI2ds6DHP/icpHGjybmK0GiANqgbnNWa01jNPzyoZj6g/b39nAkjsJxpgEA5yC8OMeCPbgVhIEw5HK1toilMTJR7o6kNSW0xiEC0Nz2o+MSf+6QGPaj6twTXBRMQbpKkbEJ8ZK/8J3D0pbQifhgZ4ikF6VBEowKjtQNbL1L+OVGAGAY4E/afGAkB/oGUqTArMKPfYfaRB9ShT6zhoaLjf3H1JraHBGg5cOBPqxUeIt9tP3x0GLtyvR4knmFx2BmhiofDs68Kv48RoChSsLJ9+JEP1MjPgDzf9m6vD1tCr8Rzn9kN7/+wPJ2MaVAfdbugAAAABJRU5ErkJggg=='; diff --git a/src/utils/simple-qrbtf/utils/helper.ts b/src/utils/simple-qrbtf/utils/helper.ts deleted file mode 100644 index c59cd077..00000000 --- a/src/utils/simple-qrbtf/utils/helper.ts +++ /dev/null @@ -1,29 +0,0 @@ -let seed = 0; - -let idNum = 0; - -export function rand(min: number, max: number) { - seed = (seed * 9301 + 49297) % 233280; - return min + (seed / 233280.0) * (max - min); -} - -export function getIdNum() { - idNum += 1; - return idNum.toString(); -} - -export function getExactValue(value: any, defaultValue: any) { - if (typeof value != 'string') return value; - if (value.length <= 0) value = defaultValue; - if (!isNaN(value)) value = parseInt(value); - return value; -} - -export function arrToStr(arr: string[]): string { - return arr - .reduce((result, curr) => { - if (curr && curr.length > 0) result.push(curr); - return result; - }, []) - .join('\n'); -} diff --git a/src/utils/simple-qrbtf/utils/index.ts b/src/utils/simple-qrbtf/utils/index.ts deleted file mode 100644 index 5bd3c98d..00000000 --- a/src/utils/simple-qrbtf/utils/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -export * from './helper'; -export * from './qrcodeHandler'; -export * from './qrcode'; -export * from './data'; - -export const QRPointType = { - DATA: 0, - POS_CENTER: 1, - POS_OTHER: 2, - ALIGN_CENTER: 3, - ALIGN_OTHER: 4, - TIMING: 5, - FORMAT: 6, - VERSION: 7, -}; diff --git a/src/utils/simple-qrbtf/utils/qrcode.ts b/src/utils/simple-qrbtf/utils/qrcode.ts deleted file mode 100644 index 31b25217..00000000 --- a/src/utils/simple-qrbtf/utils/qrcode.ts +++ /dev/null @@ -1,1210 +0,0 @@ -//--------------------------------------------------------------------- -// 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 -// -//--------------------------------------------------------------------- -/* eslint-disable */ -class QR8BitByte { - mode: number; - data: string; - parsedData: number[]; - constructor(data: string) { - this.mode = QRMode.MODE_8BIT_BYTE; - this.data = data; - this.parsedData = []; - - // Added to support UTF-8 Characters - for (let i = 0, l = this.data.length; i < l; i++) { - let byteArray: number[] = []; - let code = this.data.charCodeAt(i); - - if (code > 0x10000) { - byteArray[0] = 0xf0 | ((code & 0x1c0000) >>> 18); - byteArray[1] = 0x80 | ((code & 0x3f000) >>> 12); - byteArray[2] = 0x80 | ((code & 0xfc0) >>> 6); - byteArray[3] = 0x80 | (code & 0x3f); - } else if (code > 0x800) { - byteArray[0] = 0xe0 | ((code & 0xf000) >>> 12); - byteArray[1] = 0x80 | ((code & 0xfc0) >>> 6); - byteArray[2] = 0x80 | (code & 0x3f); - } else if (code > 0x80) { - byteArray[0] = 0xc0 | ((code & 0x7c0) >>> 6); - byteArray[1] = 0x80 | (code & 0x3f); - } else { - byteArray[0] = code; - } - - this.parsedData.push(...byteArray); - } - - this.parsedData = Array.prototype.concat.apply([], this.parsedData); - - if (this.parsedData.length != this.data.length) { - this.parsedData.unshift(191); - this.parsedData.unshift(187); - this.parsedData.unshift(239); - } - } - - getLength() { - return this.parsedData.length; - } - - write(buffer: QRBitBuffer) { - for (let i = 0, l = this.parsedData.length; i < l; i++) { - buffer.put(this.parsedData[i], 8); - } - } -} - -//--------------------------------------------------------------------- -// QRCode -//--------------------------------------------------------------------- -class QRCode { - typeNumber: number; - errorCorrectLevel: number; - modules: Array>; - moduleCount: number; - position: number[][]; - dataCache: number[] | null; - dataList: QR8BitByte[]; - static PAD0 = 0xec; - static PAD1 = 0x11; - - constructor(typeNumber: number, errorCorrectLevel: number) { - this.typeNumber = typeNumber; - this.errorCorrectLevel = errorCorrectLevel; - this.modules = []; - this.moduleCount = 0; - this.position = []; - this.dataCache = null; - this.dataList = []; - } - - addData(data: string) { - let newData = new QR8BitByte(data); - this.dataList.push(newData); - this.dataCache = null; - } - - isDark(row: number, col: number) { - if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) { - throw new Error(row + ',' + col); - } - return this.modules[row][col]; - } - - getModuleCount() { - return this.moduleCount; - } - - getPositionTable() { - return this.position; - } - - make() { - // Calculate automatically typeNumber if provided is < 1 - if (this.typeNumber < 1) { - let typeNumber = 1; - for (typeNumber = 1; typeNumber < 40; typeNumber++) { - let rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel); - - let buffer = new QRBitBuffer(); - let totalDataCount = 0; - for (let i = 0; i < rsBlocks.length; i++) { - totalDataCount += rsBlocks[i].dataCount; - } - - for (let i = 0; i < this.dataList.length; i++) { - let data = this.dataList[i]; - buffer.put(data.mode, 4); - buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber)); - data.write(buffer); - } - if (buffer.getLengthInBits() <= totalDataCount * 8) break; - } - this.typeNumber = typeNumber; - } - this.makeImpl(false, this.getBestMaskPattern()); - } - - makeImpl(test: boolean, maskPattern: number) { - this.moduleCount = this.typeNumber * 4 + 17; - this.modules = new Array(this.moduleCount); - - for (let row = 0; row < this.moduleCount; row++) { - this.modules[row] = new Array(this.moduleCount); - - for (let col = 0; col < this.moduleCount; col++) { - this.modules[row][col] = null; //(col + row) % 3; - } - } - - this.setupPositionProbePattern(0, 0); - this.setupPositionProbePattern(this.moduleCount - 7, 0); - this.setupPositionProbePattern(0, this.moduleCount - 7); - this.setupPositionAdjustPattern(); - this.setupTimingPattern(); - this.setupTypeInfo(test, maskPattern); - - if (this.typeNumber >= 7) { - this.setupTypeNumber(test); - } - - if (this.dataCache == null) { - this.dataCache = QRCode.createData(this.typeNumber, this.errorCorrectLevel, this.dataList); - } - - this.mapData(this.dataCache, maskPattern); - } - - setupPositionProbePattern(row: number, col: number) { - for (let r = -1; r <= 7; r++) { - if (row + r <= -1 || this.moduleCount <= row + r) continue; - - for (let c = -1; c <= 7; c++) { - if (col + c <= -1 || this.moduleCount <= col + c) continue; - - if ( - (0 <= r && r <= 6 && (c == 0 || c == 6)) || - (0 <= c && c <= 6 && (r == 0 || r == 6)) || - (2 <= r && r <= 4 && 2 <= c && c <= 4) - ) { - this.modules[row + r][col + c] = true; - } else { - this.modules[row + r][col + c] = false; - } - } - } - } - - getBestMaskPattern() { - let minLostPoint = 0; - let pattern = 0; - - for (let i = 0; i < 8; i++) { - this.makeImpl(true, i); - - let lostPoint = QRUtil.getLostPoint(this); - - if (i == 0 || minLostPoint > lostPoint) { - minLostPoint = lostPoint; - pattern = i; - } - } - - return pattern; - } - - setupTimingPattern() { - for (let r = 8; r < this.moduleCount - 8; r++) { - if (this.modules[r][6] != null) { - continue; - } - this.modules[r][6] = r % 2 == 0; - } - - for (let c = 8; c < this.moduleCount - 8; c++) { - if (this.modules[6][c] != null) { - continue; - } - this.modules[6][c] = c % 2 == 0; - } - } - - setupPositionAdjustPattern() { - let pos = QRUtil.getPatternPosition(this.typeNumber); - - this.position = new Array>(); - - for (let i = 0; i < pos.length; i++) { - for (let j = 0; j < pos.length; j++) { - let row = pos[i]; - let col = pos[j]; - - if (this.modules[row][col] != null) { - continue; - } - - this.position.push([row, col]); - - for (let r = -2; r <= 2; r++) { - for (let c = -2; c <= 2; c++) { - if (r == -2 || r == 2 || c == -2 || c == 2 || (r == 0 && c == 0)) { - this.modules[row + r][col + c] = true; - } else { - this.modules[row + r][col + c] = false; - } - } - } - } - } - } - - setupTypeNumber(test: boolean) { - let bits = QRUtil.getBCHTypeNumber(this.typeNumber); - - for (let i = 0; i < 18; i++) { - let mod = !test && ((bits >> i) & 1) == 1; - this.modules[Math.floor(i / 3)][(i % 3) + this.moduleCount - 8 - 3] = mod; - } - - for (let i = 0; i < 18; i++) { - let mod = !test && ((bits >> i) & 1) == 1; - this.modules[(i % 3) + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod; - } - } - - setupTypeInfo(test: boolean, maskPattern: number) { - let data = (this.errorCorrectLevel << 3) | maskPattern; - let bits = QRUtil.getBCHTypeInfo(data); - - // vertical - for (let i = 0; i < 15; i++) { - let mod = !test && ((bits >> i) & 1) == 1; - - if (i < 6) { - this.modules[i][8] = mod; - } else if (i < 8) { - this.modules[i + 1][8] = mod; - } else { - this.modules[this.moduleCount - 15 + i][8] = mod; - } - } - - // horizontal - for (let i = 0; i < 15; i++) { - let mod = !test && ((bits >> i) & 1) == 1; - - if (i < 8) { - this.modules[8][this.moduleCount - i - 1] = mod; - } else if (i < 9) { - this.modules[8][15 - i - 1 + 1] = mod; - } else { - this.modules[8][15 - i - 1] = mod; - } - } - - // fixed module - this.modules[this.moduleCount - 8][8] = !test; - } - - mapData(data: number[], maskPattern: number) { - let inc = -1; - let row = this.moduleCount - 1; - let bitIndex = 7; - let byteIndex = 0; - - for (let col = this.moduleCount - 1; col > 0; col -= 2) { - if (col == 6) col--; - - while (true) { - for (let c = 0; c < 2; c++) { - if (this.modules[row][col - c] == null) { - let dark = false; - - if (byteIndex < data.length) { - dark = ((data[byteIndex] >>> bitIndex) & 1) == 1; - } - - let mask = QRUtil.getMask(maskPattern, row, col - c); - - if (mask) { - dark = !dark; - } - - this.modules[row][col - c] = dark; - bitIndex--; - - if (bitIndex == -1) { - byteIndex++; - bitIndex = 7; - } - } - } - - row += inc; - - if (row < 0 || this.moduleCount <= row) { - row -= inc; - inc = -inc; - break; - } - } - } - } - - static createData(typeNumber: number, errorCorrectLevel: number, dataList: QR8BitByte[]) { - let rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel); - - let buffer = new QRBitBuffer(); - - for (let i = 0; i < dataList.length; i++) { - let data = dataList[i]; - buffer.put(data.mode, 4); - buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber)); - data.write(buffer); - } - - // calc num max data. - let totalDataCount = 0; - for (let i = 0; i < rsBlocks.length; i++) { - totalDataCount += rsBlocks[i].dataCount; - } - - if (buffer.getLengthInBits() > totalDataCount * 8) { - throw new Error('code length overflow. (' + buffer.getLengthInBits() + '>' + totalDataCount * 8 + ')'); - } - - // end code - if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) { - buffer.put(0, 4); - } - - // padding - while (buffer.getLengthInBits() % 8 != 0) { - buffer.putBit(false); - } - - // padding - while (true) { - if (buffer.getLengthInBits() >= totalDataCount * 8) { - break; - } - buffer.put(QRCode.PAD0, 8); - - if (buffer.getLengthInBits() >= totalDataCount * 8) { - break; - } - buffer.put(QRCode.PAD1, 8); - } - - return QRCode.createBytes(buffer, rsBlocks); - } - - static createBytes(buffer: QRBitBuffer, rsBlocks: QRRSBlock[]) { - let offset = 0; - - let maxDcCount = 0; - let maxEcCount = 0; - - let dcdata = new Array(rsBlocks.length); - let ecdata = new Array(rsBlocks.length); - - for (let r = 0; r < rsBlocks.length; r++) { - let dcCount = rsBlocks[r].dataCount; - let ecCount = rsBlocks[r].totalCount - dcCount; - - maxDcCount = Math.max(maxDcCount, dcCount); - maxEcCount = Math.max(maxEcCount, ecCount); - - dcdata[r] = new Array(dcCount); - - for (let i = 0; i < dcdata[r].length; i++) { - dcdata[r][i] = 0xff & buffer.buffer[i + offset]; - } - offset += dcCount; - - let rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount); - let rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1); - - let modPoly = rawPoly.mod(rsPoly); - ecdata[r] = new Array(rsPoly.getLength() - 1); - for (let i = 0; i < ecdata[r].length; i++) { - let modIndex = i + modPoly.getLength() - ecdata[r].length; - ecdata[r][i] = modIndex >= 0 ? modPoly.get(modIndex) : 0; - } - } - - let totalCodeCount = 0; - for (let i = 0; i < rsBlocks.length; i++) { - totalCodeCount += rsBlocks[i].totalCount; - } - - let data = new Array(totalCodeCount); - let index = 0; - - for (let i = 0; i < maxDcCount; i++) { - for (let r = 0; r < rsBlocks.length; r++) { - if (i < dcdata[r].length) { - data[index++] = dcdata[r][i]; - } - } - } - - for (let i = 0; i < maxEcCount; i++) { - for (let r = 0; r < rsBlocks.length; r++) { - if (i < ecdata[r].length) { - data[index++] = ecdata[r][i]; - } - } - } - - return data; - } -} - -//--------------------------------------------------------------------- -// QRMode -//--------------------------------------------------------------------- - -let QRMode = { - MODE_NUMBER: 1 << 0, - MODE_ALPHA_NUM: 1 << 1, - MODE_8BIT_BYTE: 1 << 2, - MODE_KANJI: 1 << 3, -}; - -//--------------------------------------------------------------------- -// QRErrorCorrectLevel -//--------------------------------------------------------------------- - -let QRErrorCorrectLevel = { - L: 1, - M: 0, - Q: 3, - H: 2, -}; - -//--------------------------------------------------------------------- -// QRMaskPattern -//--------------------------------------------------------------------- - -let QRMaskPattern = { - PATTERN000: 0, - PATTERN001: 1, - PATTERN010: 2, - PATTERN011: 3, - PATTERN100: 4, - PATTERN101: 5, - PATTERN110: 6, - PATTERN111: 7, -}; - -//--------------------------------------------------------------------- -// QRUtil -//--------------------------------------------------------------------- - -let QRUtil = { - PATTERN_POSITION_TABLE: [ - [], - [6, 18], - [6, 22], - [6, 26], - [6, 30], - [6, 34], - [6, 22, 38], - [6, 24, 42], - [6, 26, 46], - [6, 28, 50], - [6, 30, 54], - [6, 32, 58], - [6, 34, 62], - [6, 26, 46, 66], - [6, 26, 48, 70], - [6, 26, 50, 74], - [6, 30, 54, 78], - [6, 30, 56, 82], - [6, 30, 58, 86], - [6, 34, 62, 90], - [6, 28, 50, 72, 94], - [6, 26, 50, 74, 98], - [6, 30, 54, 78, 102], - [6, 28, 54, 80, 106], - [6, 32, 58, 84, 110], - [6, 30, 58, 86, 114], - [6, 34, 62, 90, 118], - [6, 26, 50, 74, 98, 122], - [6, 30, 54, 78, 102, 126], - [6, 26, 52, 78, 104, 130], - [6, 30, 56, 82, 108, 134], - [6, 34, 60, 86, 112, 138], - [6, 30, 58, 86, 114, 142], - [6, 34, 62, 90, 118, 146], - [6, 30, 54, 78, 102, 126, 150], - [6, 24, 50, 76, 102, 128, 154], - [6, 28, 54, 80, 106, 132, 158], - [6, 32, 58, 84, 110, 136, 162], - [6, 26, 54, 82, 110, 138, 166], - [6, 30, 58, 86, 114, 142, 170], - ], - - G15: (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0), - G18: (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0), - G15_MASK: (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1), - - getBCHTypeInfo: function (data: number) { - let d = data << 10; - while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) { - d ^= QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15)); - } - return ((data << 10) | d) ^ QRUtil.G15_MASK; - }, - - getBCHTypeNumber: function (data: number) { - let d = data << 12; - while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) { - d ^= QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18)); - } - return (data << 12) | d; - }, - - getBCHDigit: function (data: number) { - let digit = 0; - - while (data != 0) { - digit++; - data >>>= 1; - } - - return digit; - }, - - getPatternPosition: function (typeNumber: number) { - return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1]; - }, - - getMask: function (maskPattern: number, i: number, j: number) { - switch (maskPattern) { - case QRMaskPattern.PATTERN000: - return (i + j) % 2 == 0; - case QRMaskPattern.PATTERN001: - return i % 2 == 0; - case QRMaskPattern.PATTERN010: - return j % 3 == 0; - case QRMaskPattern.PATTERN011: - return (i + j) % 3 == 0; - case QRMaskPattern.PATTERN100: - return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0; - case QRMaskPattern.PATTERN101: - return ((i * j) % 2) + ((i * j) % 3) == 0; - case QRMaskPattern.PATTERN110: - return (((i * j) % 2) + ((i * j) % 3)) % 2 == 0; - case QRMaskPattern.PATTERN111: - return (((i * j) % 3) + ((i + j) % 2)) % 2 == 0; - - default: - throw new Error('bad maskPattern:' + maskPattern); - } - }, - - getErrorCorrectPolynomial: function (errorCorrectLength: number) { - let a = new QRPolynomial([1], 0); - - for (let i = 0; i < errorCorrectLength; i++) { - a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0)); - } - - return a; - }, - - getLengthInBits: function (mode: number, type: number) { - if (1 <= type && type < 10) { - // 1 - 9 - - switch (mode) { - case QRMode.MODE_NUMBER: - return 10; - case QRMode.MODE_ALPHA_NUM: - return 9; - case QRMode.MODE_8BIT_BYTE: - return 8; - case QRMode.MODE_KANJI: - return 8; - default: - throw new Error('mode:' + mode); - } - } else if (type < 27) { - // 10 - 26 - - switch (mode) { - case QRMode.MODE_NUMBER: - return 12; - case QRMode.MODE_ALPHA_NUM: - return 11; - case QRMode.MODE_8BIT_BYTE: - return 16; - case QRMode.MODE_KANJI: - return 10; - default: - throw new Error('mode:' + mode); - } - } else if (type < 41) { - // 27 - 40 - - switch (mode) { - case QRMode.MODE_NUMBER: - return 14; - case QRMode.MODE_ALPHA_NUM: - return 13; - case QRMode.MODE_8BIT_BYTE: - return 16; - case QRMode.MODE_KANJI: - return 12; - default: - throw new Error('mode:' + mode); - } - } else { - throw new Error('type:' + type); - } - }, - - getLostPoint: function (qrCode: QRCode) { - let moduleCount = qrCode.getModuleCount(); - - let lostPoint = 0; - - // LEVEL1 - - for (let row = 0; row < moduleCount; row++) { - for (let col = 0; col < moduleCount; col++) { - let sameCount = 0; - let dark = qrCode.isDark(row, col); - - for (let r = -1; r <= 1; r++) { - if (row + r < 0 || moduleCount <= row + r) { - continue; - } - - for (let c = -1; c <= 1; c++) { - if (col + c < 0 || moduleCount <= col + c) { - continue; - } - - if (r == 0 && c == 0) { - continue; - } - - if (dark == qrCode.isDark(row + r, col + c)) { - sameCount++; - } - } - } - - if (sameCount > 5) { - lostPoint += 3 + sameCount - 5; - } - } - } - - // LEVEL2 - - for (let row = 0; row < moduleCount - 1; row++) { - for (let col = 0; col < moduleCount - 1; col++) { - let count = 0; - if (qrCode.isDark(row, col)) count++; - if (qrCode.isDark(row + 1, col)) count++; - if (qrCode.isDark(row, col + 1)) count++; - if (qrCode.isDark(row + 1, col + 1)) count++; - if (count == 0 || count == 4) { - lostPoint += 3; - } - } - } - - // LEVEL3 - - for (let row = 0; row < moduleCount; row++) { - for (let col = 0; col < moduleCount - 6; col++) { - if ( - qrCode.isDark(row, col) && - !qrCode.isDark(row, col + 1) && - qrCode.isDark(row, col + 2) && - qrCode.isDark(row, col + 3) && - qrCode.isDark(row, col + 4) && - !qrCode.isDark(row, col + 5) && - qrCode.isDark(row, col + 6) - ) { - lostPoint += 40; - } - } - } - - for (let col = 0; col < moduleCount; col++) { - for (let row = 0; row < moduleCount - 6; row++) { - if ( - qrCode.isDark(row, col) && - !qrCode.isDark(row + 1, col) && - qrCode.isDark(row + 2, col) && - qrCode.isDark(row + 3, col) && - qrCode.isDark(row + 4, col) && - !qrCode.isDark(row + 5, col) && - qrCode.isDark(row + 6, col) - ) { - lostPoint += 40; - } - } - } - - // LEVEL4 - - let darkCount = 0; - - for (let col = 0; col < moduleCount; col++) { - for (let row = 0; row < moduleCount; row++) { - if (qrCode.isDark(row, col)) { - darkCount++; - } - } - } - - let ratio = Math.abs((100 * darkCount) / moduleCount / moduleCount - 50) / 5; - lostPoint += ratio * 10; - - return lostPoint; - }, -}; - -//--------------------------------------------------------------------- -// QRMath -//--------------------------------------------------------------------- - -let QRMath = { - glog: function (n: number) { - if (n < 1) { - throw new Error('glog(' + n + ')'); - } - - return QRMath.LOG_TABLE[n]; - }, - - gexp: function (n: number) { - while (n < 0) { - n += 255; - } - - while (n >= 256) { - n -= 255; - } - - return QRMath.EXP_TABLE[n]; - }, - - EXP_TABLE: new Array(256), - - LOG_TABLE: new Array(256), -}; - -for (let i = 0; i < 8; i++) { - QRMath.EXP_TABLE[i] = 1 << i; -} -for (let i = 8; i < 256; i++) { - QRMath.EXP_TABLE[i] = - QRMath.EXP_TABLE[i - 4] ^ QRMath.EXP_TABLE[i - 5] ^ QRMath.EXP_TABLE[i - 6] ^ QRMath.EXP_TABLE[i - 8]; -} -for (let i = 0; i < 255; i++) { - QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i; -} - -//--------------------------------------------------------------------- -// QRPolynomial -//--------------------------------------------------------------------- -class QRPolynomial { - num: number[]; - constructor(num: number[], shift: number) { - if (num.length == undefined) { - throw new Error(num.length + '/' + shift); - } - - let offset = 0; - - while (offset < num.length && num[offset] == 0) { - offset++; - } - - this.num = new Array(num.length - offset + shift); - for (let i = 0; i < num.length - offset; i++) { - this.num[i] = num[i + offset]; - } - } - - get(index: number) { - return this.num[index]; - } - - getLength() { - return this.num.length; - } - - multiply(e: QRPolynomial) { - let num = new Array(this.getLength() + e.getLength() - 1); - - for (let i = 0; i < this.getLength(); i++) { - for (let j = 0; j < e.getLength(); j++) { - num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i)) + QRMath.glog(e.get(j))); - } - } - - return new QRPolynomial(num, 0); - } - - mod(e: QRPolynomial): QRPolynomial { - if (this.getLength() - e.getLength() < 0) { - return this; - } - - let ratio = QRMath.glog(this.get(0)) - QRMath.glog(e.get(0)); - - let num = new Array(this.getLength()); - - for (let i = 0; i < this.getLength(); i++) { - num[i] = this.get(i); - } - - for (let i = 0; i < e.getLength(); i++) { - num[i] ^= QRMath.gexp(QRMath.glog(e.get(i)) + ratio); - } - - // recursive call - return new QRPolynomial(num, 0).mod(e); - } -} - -//--------------------------------------------------------------------- -// QRRSBlock -//--------------------------------------------------------------------- -class QRRSBlock { - totalCount: number; - dataCount: number; - constructor(totalCount: number, dataCount: number) { - this.totalCount = totalCount; - this.dataCount = dataCount; - } - - static RS_BLOCK_TABLE = [ - // L - // M - // Q - // H - - // 1 - [1, 26, 19], - [1, 26, 16], - [1, 26, 13], - [1, 26, 9], - - // 2 - [1, 44, 34], - [1, 44, 28], - [1, 44, 22], - [1, 44, 16], - - // 3 - [1, 70, 55], - [1, 70, 44], - [2, 35, 17], - [2, 35, 13], - - // 4 - [1, 100, 80], - [2, 50, 32], - [2, 50, 24], - [4, 25, 9], - - // 5 - [1, 134, 108], - [2, 67, 43], - [2, 33, 15, 2, 34, 16], - [2, 33, 11, 2, 34, 12], - - // 6 - [2, 86, 68], - [4, 43, 27], - [4, 43, 19], - [4, 43, 15], - - // 7 - [2, 98, 78], - [4, 49, 31], - [2, 32, 14, 4, 33, 15], - [4, 39, 13, 1, 40, 14], - - // 8 - [2, 121, 97], - [2, 60, 38, 2, 61, 39], - [4, 40, 18, 2, 41, 19], - [4, 40, 14, 2, 41, 15], - - // 9 - [2, 146, 116], - [3, 58, 36, 2, 59, 37], - [4, 36, 16, 4, 37, 17], - [4, 36, 12, 4, 37, 13], - - // 10 - [2, 86, 68, 2, 87, 69], - [4, 69, 43, 1, 70, 44], - [6, 43, 19, 2, 44, 20], - [6, 43, 15, 2, 44, 16], - - // 11 - [4, 101, 81], - [1, 80, 50, 4, 81, 51], - [4, 50, 22, 4, 51, 23], - [3, 36, 12, 8, 37, 13], - - // 12 - [2, 116, 92, 2, 117, 93], - [6, 58, 36, 2, 59, 37], - [4, 46, 20, 6, 47, 21], - [7, 42, 14, 4, 43, 15], - - // 13 - [4, 133, 107], - [8, 59, 37, 1, 60, 38], - [8, 44, 20, 4, 45, 21], - [12, 33, 11, 4, 34, 12], - - // 14 - [3, 145, 115, 1, 146, 116], - [4, 64, 40, 5, 65, 41], - [11, 36, 16, 5, 37, 17], - [11, 36, 12, 5, 37, 13], - - // 15 - [5, 109, 87, 1, 110, 88], - [5, 65, 41, 5, 66, 42], - [5, 54, 24, 7, 55, 25], - [11, 36, 12], - - // 16 - [5, 122, 98, 1, 123, 99], - [7, 73, 45, 3, 74, 46], - [15, 43, 19, 2, 44, 20], - [3, 45, 15, 13, 46, 16], - - // 17 - [1, 135, 107, 5, 136, 108], - [10, 74, 46, 1, 75, 47], - [1, 50, 22, 15, 51, 23], - [2, 42, 14, 17, 43, 15], - - // 18 - [5, 150, 120, 1, 151, 121], - [9, 69, 43, 4, 70, 44], - [17, 50, 22, 1, 51, 23], - [2, 42, 14, 19, 43, 15], - - // 19 - [3, 141, 113, 4, 142, 114], - [3, 70, 44, 11, 71, 45], - [17, 47, 21, 4, 48, 22], - [9, 39, 13, 16, 40, 14], - - // 20 - [3, 135, 107, 5, 136, 108], - [3, 67, 41, 13, 68, 42], - [15, 54, 24, 5, 55, 25], - [15, 43, 15, 10, 44, 16], - - // 21 - [4, 144, 116, 4, 145, 117], - [17, 68, 42], - [17, 50, 22, 6, 51, 23], - [19, 46, 16, 6, 47, 17], - - // 22 - [2, 139, 111, 7, 140, 112], - [17, 74, 46], - [7, 54, 24, 16, 55, 25], - [34, 37, 13], - - // 23 - [4, 151, 121, 5, 152, 122], - [4, 75, 47, 14, 76, 48], - [11, 54, 24, 14, 55, 25], - [16, 45, 15, 14, 46, 16], - - // 24 - [6, 147, 117, 4, 148, 118], - [6, 73, 45, 14, 74, 46], - [11, 54, 24, 16, 55, 25], - [30, 46, 16, 2, 47, 17], - - // 25 - [8, 132, 106, 4, 133, 107], - [8, 75, 47, 13, 76, 48], - [7, 54, 24, 22, 55, 25], - [22, 45, 15, 13, 46, 16], - - // 26 - [10, 142, 114, 2, 143, 115], - [19, 74, 46, 4, 75, 47], - [28, 50, 22, 6, 51, 23], - [33, 46, 16, 4, 47, 17], - - // 27 - [8, 152, 122, 4, 153, 123], - [22, 73, 45, 3, 74, 46], - [8, 53, 23, 26, 54, 24], - [12, 45, 15, 28, 46, 16], - - // 28 - [3, 147, 117, 10, 148, 118], - [3, 73, 45, 23, 74, 46], - [4, 54, 24, 31, 55, 25], - [11, 45, 15, 31, 46, 16], - - // 29 - [7, 146, 116, 7, 147, 117], - [21, 73, 45, 7, 74, 46], - [1, 53, 23, 37, 54, 24], - [19, 45, 15, 26, 46, 16], - - // 30 - [5, 145, 115, 10, 146, 116], - [19, 75, 47, 10, 76, 48], - [15, 54, 24, 25, 55, 25], - [23, 45, 15, 25, 46, 16], - - // 31 - [13, 145, 115, 3, 146, 116], - [2, 74, 46, 29, 75, 47], - [42, 54, 24, 1, 55, 25], - [23, 45, 15, 28, 46, 16], - - // 32 - [17, 145, 115], - [10, 74, 46, 23, 75, 47], - [10, 54, 24, 35, 55, 25], - [19, 45, 15, 35, 46, 16], - - // 33 - [17, 145, 115, 1, 146, 116], - [14, 74, 46, 21, 75, 47], - [29, 54, 24, 19, 55, 25], - [11, 45, 15, 46, 46, 16], - - // 34 - [13, 145, 115, 6, 146, 116], - [14, 74, 46, 23, 75, 47], - [44, 54, 24, 7, 55, 25], - [59, 46, 16, 1, 47, 17], - - // 35 - [12, 151, 121, 7, 152, 122], - [12, 75, 47, 26, 76, 48], - [39, 54, 24, 14, 55, 25], - [22, 45, 15, 41, 46, 16], - - // 36 - [6, 151, 121, 14, 152, 122], - [6, 75, 47, 34, 76, 48], - [46, 54, 24, 10, 55, 25], - [2, 45, 15, 64, 46, 16], - - // 37 - [17, 152, 122, 4, 153, 123], - [29, 74, 46, 14, 75, 47], - [49, 54, 24, 10, 55, 25], - [24, 45, 15, 46, 46, 16], - - // 38 - [4, 152, 122, 18, 153, 123], - [13, 74, 46, 32, 75, 47], - [48, 54, 24, 14, 55, 25], - [42, 45, 15, 32, 46, 16], - - // 39 - [20, 147, 117, 4, 148, 118], - [40, 75, 47, 7, 76, 48], - [43, 54, 24, 22, 55, 25], - [10, 45, 15, 67, 46, 16], - - // 40 - [19, 148, 118, 6, 149, 119], - [18, 75, 47, 31, 76, 48], - [34, 54, 24, 34, 55, 25], - [20, 45, 15, 61, 46, 16], - ]; - static getRSBlocks(typeNumber: number, errorCorrectLevel: number): QRRSBlock[] { - let rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel); - - if (rsBlock == undefined) { - throw new Error('bad rs block @ typeNumber:' + typeNumber + '/errorCorrectLevel:' + errorCorrectLevel); - } - - let length = rsBlock.length / 3; - - let list = []; - - for (let i = 0; i < length; i++) { - let count = rsBlock[i * 3 + 0]; - let totalCount = rsBlock[i * 3 + 1]; - let dataCount = rsBlock[i * 3 + 2]; - - for (let j = 0; j < count; j++) { - list.push(new QRRSBlock(totalCount, dataCount)); - } - } - - return list; - } - - static getRsBlockTable(typeNumber: number, errorCorrectLevel: number): Array { - switch (errorCorrectLevel) { - case QRErrorCorrectLevel.L: - return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0]; - case QRErrorCorrectLevel.M: - return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1]; - case QRErrorCorrectLevel.Q: - return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2]; - case QRErrorCorrectLevel.H: - return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3]; - default: - return []; - } - } -} - -//--------------------------------------------------------------------- -// QRBitBuffer -//--------------------------------------------------------------------- -class QRBitBuffer { - buffer: number[]; - length: number; - constructor() { - this.buffer = []; - this.length = 0; - } - - get(index: number) { - let bufIndex = Math.floor(index / 8); - return ((this.buffer[bufIndex] >>> (7 - (index % 8))) & 1) == 1; - } - - put(num: number, length: number) { - for (let i = 0; i < length; i++) { - this.putBit(((num >>> (length - i - 1)) & 1) == 1); - } - } - - getLengthInBits() { - return this.length; - } - - putBit(bit: boolean) { - let bufIndex = Math.floor(this.length / 8); - if (this.buffer.length <= bufIndex) { - this.buffer.push(0); - } - - if (bit) { - this.buffer[bufIndex] |= 0x80 >>> this.length % 8; - } - - this.length++; - } -} - -export default QRCode; diff --git a/src/utils/simple-qrbtf/utils/qrcodeHandler.ts b/src/utils/simple-qrbtf/utils/qrcodeHandler.ts deleted file mode 100644 index 4e8b3ce6..00000000 --- a/src/utils/simple-qrbtf/utils/qrcodeHandler.ts +++ /dev/null @@ -1,93 +0,0 @@ -import QRCode from './qrcode'; - -export const QRPointType = { - DATA: 0, - POS_CENTER: 1, - POS_OTHER: 2, - ALIGN_CENTER: 3, - ALIGN_OTHER: 4, - TIMING: 5, - FORMAT: 6, - VERSION: 7, -}; - -export interface IOptions { - text: string; - typeNumber?: number; - correctLevel?: string; -} - -export function getLevelNumber(level: string) { - if (level === 'L') return 1; - else if (level === 'M') return 0; - else if (level === 'Q') return 3; - else if (level === 'H') return 2; - return 0; -} - -export function encodeData(options: IOptions) { - if (!options.text || options.text.length <= 0) return undefined; - if (!options.typeNumber) options.typeNumber = -1; - if (!options.correctLevel) options.correctLevel = 'M'; - - const qrcode = new QRCode(options.typeNumber, getLevelNumber(options.correctLevel)); - qrcode.addData(options.text); - qrcode.make(); - - return qrcode; -} - -export function getTypeTable(qrcode: QRCode): number[][] { - const nCount = qrcode.getModuleCount(); - const position = qrcode.getPositionTable(); - const PD = [ - [3, 3], - [3, nCount - 4], - [nCount - 4, 3], - ]; - - const typeTable = new Array(nCount); - for (let i = 0; i < nCount; i++) typeTable[i] = new Array(nCount); - - for (let i = 8; i < nCount - 7; i++) { - typeTable[i][6] = typeTable[6][i] = QRPointType.TIMING; - } - - for (let i = 0; i < position.length; i++) { - typeTable[position[i][0]][position[i][1]] = QRPointType.ALIGN_CENTER; - for (let r = -2; r <= 2; r++) { - for (let c = -2; c <= 2; c++) { - if (!(r === 0 && c === 0)) typeTable[position[i][0] + r][position[i][1] + c] = QRPointType.ALIGN_OTHER; - } - } - } - - for (let i = 0; i < PD.length; i++) { - typeTable[PD[i][0]][PD[i][1]] = QRPointType.POS_CENTER; - for (let r = -4; r <= 4; r++) { - for (let c = -4; c <= 4; c++) { - if (PD[i][0] + r >= 0 && PD[i][0] + r < nCount && PD[i][1] + c >= 0 && PD[i][1] + c < nCount) - if (!(r === 0 && c === 0)) typeTable[PD[i][0] + r][PD[i][1] + c] = QRPointType.POS_OTHER; - } - } - } - - for (let i = 0; i <= 8; i++) { - if (i !== 6) typeTable[i][8] = typeTable[8][i] = QRPointType.FORMAT; - if (i < 7) typeTable[nCount - i - 1][8] = QRPointType.FORMAT; - if (i < 8) typeTable[8][nCount - i - 1] = QRPointType.FORMAT; - } - - for (let i = nCount - 11; i <= nCount - 9; i++) { - for (let j = 0; j <= 5; j++) { - typeTable[i][j] = typeTable[j][i] = QRPointType.VERSION; - } - } - - for (let i = 0; i < nCount; i++) { - for (let j = 0; j < nCount; j++) { - if (!typeTable[i][j]) typeTable[i][j] = QRPointType.DATA; - } - } - return typeTable; -}