@quicktvui/web-cli 2.1.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/DevServer.js
CHANGED
|
@@ -65,18 +65,34 @@ class DevServer {
|
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* 查找 web-runtime 的 dist 目录
|
|
68
|
+
*
|
|
69
|
+
* 查找优先级:
|
|
70
|
+
* 1. web-cli 内嵌的 runtime/ 目录(全局安装时也能工作)
|
|
71
|
+
* 2. 同级 packages 目录(monorepo 开发时)
|
|
72
|
+
* 3. 项目 node_modules 中的包
|
|
68
73
|
*/
|
|
69
74
|
_findWebRuntimeDist() {
|
|
70
75
|
const candidates = [
|
|
71
|
-
//
|
|
76
|
+
// web-cli 内嵌的 runtime 目录(优先级最高,全局安装时也能找到)
|
|
77
|
+
path.resolve(__dirname, '../runtime'),
|
|
78
|
+
// 同级 packages 目录(monorepo 开发时)
|
|
72
79
|
path.resolve(__dirname, '../../web-runtime/dist'),
|
|
73
|
-
// node_modules 中的包
|
|
80
|
+
// 项目 node_modules 中的包
|
|
74
81
|
path.join(this.projectRoot, 'node_modules/@quicktvui/web-runtime/dist'),
|
|
75
82
|
]
|
|
76
83
|
for (const dir of candidates) {
|
|
77
84
|
if (fs.existsSync(dir)) {
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
// 验证目录中是否有 JS 文件
|
|
86
|
+
try {
|
|
87
|
+
const files = fs.readdirSync(dir)
|
|
88
|
+
const hasJs = files.some((f) => f.endsWith('.js'))
|
|
89
|
+
if (hasJs) {
|
|
90
|
+
signale.info(`找到 web-runtime: ${dir}`)
|
|
91
|
+
return dir
|
|
92
|
+
}
|
|
93
|
+
} catch (e) {
|
|
94
|
+
// 忽略读取错误,继续查找下一个
|
|
95
|
+
}
|
|
80
96
|
}
|
|
81
97
|
}
|
|
82
98
|
signale.warn('未找到 web-runtime dist 目录,bundle 加载功能将不可用')
|
|
@@ -478,42 +494,86 @@ class DevServer {
|
|
|
478
494
|
|
|
479
495
|
/**
|
|
480
496
|
* 处理代理请求
|
|
497
|
+
*
|
|
498
|
+
* URL 格式: /proxy/{http|https}/{host}[:port]/{path}[?query]
|
|
499
|
+
* 示例:
|
|
500
|
+
* /proxy/https/api.example.com/v1/data → https://api.example.com/v1/data
|
|
501
|
+
* /proxy/https/api.example.com:8443/v1/data → https://api.example.com:8443/v1/data
|
|
481
502
|
*/
|
|
482
503
|
_handleProxy(req, res, pathname) {
|
|
483
|
-
//
|
|
504
|
+
// 从完整 URL 中提取查询参数(pathname 只有路径部分)
|
|
505
|
+
const fullUrl = url.parse(req.url, true)
|
|
506
|
+
const queryString = fullUrl.search || ''
|
|
507
|
+
|
|
484
508
|
const match = pathname.match(/^\/proxy\/(https?)\/([^/]+)(\/.*)?$/)
|
|
485
509
|
if (!match) {
|
|
486
510
|
res.writeHead(400, { 'Content-Type': 'text/plain' })
|
|
487
|
-
res.end('Invalid proxy URL format. Use: /proxy/{http|https}/{host}/{path}')
|
|
511
|
+
res.end('Invalid proxy URL format. Use: /proxy/{http|https}/{host}[:port]/{path}')
|
|
488
512
|
return
|
|
489
513
|
}
|
|
490
514
|
|
|
491
515
|
const protocol = match[1]
|
|
492
|
-
const
|
|
493
|
-
const proxyPath = match[3] || '/'
|
|
516
|
+
const hostPort = match[2]
|
|
517
|
+
const proxyPath = (match[3] || '/') + queryString
|
|
518
|
+
|
|
519
|
+
// 分离 host 和 port
|
|
520
|
+
let hostname = hostPort
|
|
521
|
+
let port = protocol === 'https' ? 443 : 80
|
|
522
|
+
if (hostPort.includes(':')) {
|
|
523
|
+
const parts = hostPort.split(':')
|
|
524
|
+
hostname = parts[0]
|
|
525
|
+
port = parseInt(parts[1], 10) || port
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// 过滤掉 hop-by-hop 头,避免转发问题
|
|
529
|
+
const headers = { ...req.headers }
|
|
530
|
+
delete headers['host']
|
|
531
|
+
delete headers['connection']
|
|
532
|
+
delete headers['keep-alive']
|
|
533
|
+
delete headers['transfer-encoding']
|
|
534
|
+
delete headers['te']
|
|
535
|
+
delete headers['trailer']
|
|
536
|
+
delete headers['upgrade']
|
|
537
|
+
delete headers['proxy-connection']
|
|
538
|
+
headers['host'] = hostPort
|
|
539
|
+
// 标记请求来自代理(方便调试)
|
|
540
|
+
headers['x-forwarded-for'] = req.socket.remoteAddress
|
|
541
|
+
headers['x-forwarded-proto'] = protocol
|
|
494
542
|
|
|
495
543
|
const options = {
|
|
496
|
-
hostname
|
|
497
|
-
port
|
|
544
|
+
hostname,
|
|
545
|
+
port,
|
|
498
546
|
path: proxyPath,
|
|
499
547
|
method: req.method,
|
|
500
|
-
headers
|
|
501
|
-
|
|
502
|
-
host: host,
|
|
503
|
-
},
|
|
548
|
+
headers,
|
|
549
|
+
rejectUnauthorized: false, // 允许自签名证书
|
|
504
550
|
}
|
|
505
551
|
|
|
506
552
|
const httpModule = protocol === 'https' ? require('https') : require('http')
|
|
507
553
|
const proxyReq = httpModule.request(options, (proxyRes) => {
|
|
508
|
-
|
|
554
|
+
// 代理响应添加 CORS 头
|
|
555
|
+
const responseHeaders = { ...proxyRes.headers }
|
|
556
|
+
responseHeaders['access-control-allow-origin'] = this.corsOrigin
|
|
557
|
+
responseHeaders['access-control-allow-methods'] = 'GET, POST, PUT, DELETE, OPTIONS, PATCH'
|
|
558
|
+
responseHeaders['access-control-allow-headers'] = '*'
|
|
559
|
+
responseHeaders['access-control-allow-credentials'] = 'true'
|
|
560
|
+
// 移除可能导致问题的安全头
|
|
561
|
+
delete responseHeaders['x-frame-options']
|
|
562
|
+
delete responseHeaders['content-security-policy']
|
|
563
|
+
|
|
564
|
+
res.writeHead(proxyRes.statusCode, responseHeaders)
|
|
509
565
|
proxyRes.pipe(res)
|
|
510
566
|
})
|
|
511
567
|
|
|
512
568
|
proxyReq.on('error', (err) => {
|
|
513
|
-
|
|
514
|
-
res.
|
|
569
|
+
console.error(`[Proxy] Error: ${err.message} -> ${protocol}://${hostname}:${port}${proxyPath}`)
|
|
570
|
+
if (!res.headersSent) {
|
|
571
|
+
res.writeHead(502, { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': this.corsOrigin })
|
|
572
|
+
}
|
|
573
|
+
res.end(JSON.stringify({ error: 'Proxy error', message: err.message, target: `${protocol}://${hostname}:${port}${proxyPath}` }))
|
|
515
574
|
})
|
|
516
575
|
|
|
576
|
+
// 转发请求体(POST/PUT 等)
|
|
517
577
|
req.pipe(proxyReq)
|
|
518
578
|
}
|
|
519
579
|
|
|
@@ -522,8 +582,9 @@ class DevServer {
|
|
|
522
582
|
*/
|
|
523
583
|
_setCORSHeaders(res) {
|
|
524
584
|
res.setHeader('Access-Control-Allow-Origin', this.corsOrigin)
|
|
525
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS')
|
|
526
|
-
res.setHeader('Access-Control-Allow-Headers', '
|
|
585
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS, PATCH')
|
|
586
|
+
res.setHeader('Access-Control-Allow-Headers', '*')
|
|
587
|
+
res.setHeader('Access-Control-Allow-Credentials', 'true')
|
|
527
588
|
}
|
|
528
589
|
|
|
529
590
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quicktvui/web-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "CLI tool for QuickTVUI web development v2 - delegate build & bundle loading",
|
|
5
5
|
"author": "QuickTVUI Team",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -8,9 +8,14 @@
|
|
|
8
8
|
"qt-web-cli": "./bin/qt-web-cli.js"
|
|
9
9
|
},
|
|
10
10
|
"main": "lib/index.js",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"sync-runtime": "rm -rf runtime/*.js && cp ../web-runtime/dist/web-runtime.*.js runtime/",
|
|
13
|
+
"prepublishOnly": "npm run sync-runtime"
|
|
14
|
+
},
|
|
11
15
|
"files": [
|
|
12
16
|
"bin",
|
|
13
17
|
"lib",
|
|
18
|
+
"runtime",
|
|
14
19
|
"templates"
|
|
15
20
|
],
|
|
16
21
|
"keywords": [
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
((0,eval)("this").webpackChunk_quicktvui_web_runtime=(0,eval)("this").webpackChunk_quicktvui_web_runtime||[]).push([[659],{51(t){"use strict";var e={single_source_shortest_paths:function(t,r,n){var o={},i={};i[r]=0;var a,u,s,f,h,c,g,d=e.PriorityQueue.make();for(d.push(r,0);!d.empty();)for(s in u=(a=d.pop()).value,f=a.cost,h=t[u]||{})h.hasOwnProperty(s)&&(c=f+h[s],g=i[s],(void 0===i[s]||g>c)&&(i[s]=c,d.push(s,c),o[s]=u));if(void 0!==n&&void 0===i[n]){var l=["Could not find a path from ",r," to ",n,"."].join("");throw new Error(l)}return o},extract_shortest_path_from_predecessor_list:function(t,e){for(var r=[],n=e;n;)r.push(n),t[n],n=t[n];return r.reverse(),r},find_path:function(t,r,n){var o=e.single_source_shortest_paths(t,r,n);return e.extract_shortest_path_from_predecessor_list(o,n)},PriorityQueue:{make:function(t){var r,n=e.PriorityQueue,o={};for(r in t=t||{},n)n.hasOwnProperty(r)&&(o[r]=n[r]);return o.queue=[],o.sorter=t.sorter||n.default_sorter,o},default_sorter:function(t,e){return t.cost-e.cost},push:function(t,e){var r={value:t,cost:e};this.queue.push(r),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return 0===this.queue.length}}};t.exports=e},659(t,e,r){var n=r(713),o=r(433),i=r(879),a=r(648);function u(t,e,r,i,a){var u=[].slice.call(arguments,1),s=u.length,f="function"==typeof u[s-1];if(!f&&!n())throw new Error("Callback required as last argument");if(!f){if(s<1)throw new Error("Too few arguments provided");return 1===s?(r=e,e=i=void 0):2!==s||e.getContext||(i=r,r=e,e=void 0),new Promise(function(n,a){try{var u=o.create(r,i);n(t(u,e,i))}catch(t){a(t)}})}if(s<2)throw new Error("Too few arguments provided");2===s?(a=r,r=e,e=i=void 0):3===s&&(e.getContext&&void 0===a?(a=i,i=void 0):(a=i,i=r,r=e,e=void 0));try{var h=o.create(r,i);a(null,t(h,e,i))}catch(t){a(t)}}e.create=o.create,e.toCanvas=u.bind(null,i.render),e.toDataURL=u.bind(null,i.renderToDataURL),e.toString=u.bind(null,function(t,e,r){return a.render(t,r)})},713(t){t.exports=function(){return"function"==typeof Promise&&Promise.prototype&&Promise.prototype.then}},694(t,e,r){var n=r(154).getSymbolSize;e.getRowColCoords=function(t){if(1===t)return[];for(var e=Math.floor(t/7)+2,r=n(t),o=145===r?26:2*Math.ceil((r-13)/(2*e-2)),i=[r-7],a=1;a<e-1;a++)i[a]=i[a-1]-o;return i.push(6),i.reverse()},e.getPositions=function(t){for(var r=[],n=e.getRowColCoords(t),o=n.length,i=0;i<o;i++)for(var a=0;a<o;a++)0===i&&0===a||0===i&&a===o-1||i===o-1&&0===a||r.push([n[i],n[a]]);return r}},453(t,e,r){var n=r(804),o=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function i(t){this.mode=n.ALPHANUMERIC,this.data=t}i.getBitsLength=function(t){return 11*Math.floor(t/2)+t%2*6},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(t){var e;for(e=0;e+2<=this.data.length;e+=2){var r=45*o.indexOf(this.data[e]);r+=o.indexOf(this.data[e+1]),t.put(r,11)}this.data.length%2&&t.put(o.indexOf(this.data[e]),6)},t.exports=i},671(t){function e(){this.buffer=[],this.length=0}e.prototype={get:function(t){var e=Math.floor(t/8);return 1==(this.buffer[e]>>>7-t%8&1)},put:function(t,e){for(var r=0;r<e;r++)this.putBit(1==(t>>>e-r-1&1))},getLengthInBits:function(){return this.length},putBit:function(t){var e=Math.floor(this.length/8);this.buffer.length<=e&&this.buffer.push(0),t&&(this.buffer[e]|=128>>>this.length%8),this.length++}},t.exports=e},16(t){function e(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new Uint8Array(t*t),this.reservedBit=new Uint8Array(t*t)}e.prototype.set=function(t,e,r,n){var o=t*this.size+e;this.data[o]=r,n&&(this.reservedBit[o]=!0)},e.prototype.get=function(t,e){return this.data[t*this.size+e]},e.prototype.xor=function(t,e,r){this.data[t*this.size+e]^=r},e.prototype.isReserved=function(t,e){return this.reservedBit[t*this.size+e]},t.exports=e},842(t,e,r){var n=r(804);function o(t){this.mode=n.BYTE,this.data="string"==typeof t?(new TextEncoder).encode(t):new Uint8Array(t)}o.getBitsLength=function(t){return 8*t},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(t){for(var e=0,r=this.data.length;e<r;e++)t.put(this.data[e],8)},t.exports=o},42(t,e,r){var n=r(125),o=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],i=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];e.getBlocksCount=function(t,e){switch(e){case n.L:return o[4*(t-1)+0];case n.M:return o[4*(t-1)+1];case n.Q:return o[4*(t-1)+2];case n.H:return o[4*(t-1)+3];default:return}},e.getTotalCodewordsCount=function(t,e){switch(e){case n.L:return i[4*(t-1)+0];case n.M:return i[4*(t-1)+1];case n.Q:return i[4*(t-1)+2];case n.H:return i[4*(t-1)+3];default:return}}},125(t,e){e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2},e.isValid=function(t){return t&&void 0!==t.bit&&t.bit>=0&&t.bit<4},e.from=function(t,r){if(e.isValid(t))return t;try{return function(t){if("string"!=typeof t)throw new Error("Param is not a string");switch(t.toLowerCase()){case"l":case"low":return e.L;case"m":case"medium":return e.M;case"q":case"quartile":return e.Q;case"h":case"high":return e.H;default:throw new Error("Unknown EC Level: "+t)}}(t)}catch(t){return r}}},328(t,e,r){var n=r(154).getSymbolSize;e.getPositions=function(t){var e=n(t);return[[0,0],[e-7,0],[0,e-7]]}},89(t,e,r){var n=r(154),o=n.getBCHDigit(1335);e.getEncodedBits=function(t,e){for(var r=t.bit<<3|e,i=r<<10;n.getBCHDigit(i)-o>=0;)i^=1335<<n.getBCHDigit(i)-o;return 21522^(r<<10|i)}},103(t,e){var r=new Uint8Array(512),n=new Uint8Array(256);!function(){for(var t=1,e=0;e<255;e++)r[e]=t,n[t]=e,256&(t<<=1)&&(t^=285);for(var o=255;o<512;o++)r[o]=r[o-255]}(),e.log=function(t){if(t<1)throw new Error("log("+t+")");return n[t]},e.exp=function(t){return r[t]},e.mul=function(t,e){return 0===t||0===e?0:r[n[t]+n[e]]}},857(t,e,r){var n=r(804),o=r(154);function i(t){this.mode=n.KANJI,this.data=t}i.getBitsLength=function(t){return 13*t},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(t){var e;for(e=0;e<this.data.length;e++){var r=o.toSJIS(this.data[e]);if(r>=33088&&r<=40956)r-=33088;else{if(!(r>=57408&&r<=60351))throw new Error("Invalid SJIS character: "+this.data[e]+"\nMake sure your charset is UTF-8");r-=49472}r=192*(r>>>8&255)+(255&r),t.put(r,13)}},t.exports=i},776(t,e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var r=3,n=3,o=40,i=10;function a(t,r,n){switch(t){case e.Patterns.PATTERN000:return(r+n)%2==0;case e.Patterns.PATTERN001:return r%2==0;case e.Patterns.PATTERN010:return n%3==0;case e.Patterns.PATTERN011:return(r+n)%3==0;case e.Patterns.PATTERN100:return(Math.floor(r/2)+Math.floor(n/3))%2==0;case e.Patterns.PATTERN101:return r*n%2+r*n%3==0;case e.Patterns.PATTERN110:return(r*n%2+r*n%3)%2==0;case e.Patterns.PATTERN111:return(r*n%3+(r+n)%2)%2==0;default:throw new Error("bad maskPattern:"+t)}}e.isValid=function(t){return null!=t&&""!==t&&!isNaN(t)&&t>=0&&t<=7},e.from=function(t){return e.isValid(t)?parseInt(t,10):void 0},e.getPenaltyN1=function(t){for(var e=t.size,n=0,o=0,i=0,a=null,u=null,s=0;s<e;s++){o=i=0,a=u=null;for(var f=0;f<e;f++){var h=t.get(s,f);h===a?o++:(o>=5&&(n+=r+(o-5)),a=h,o=1),(h=t.get(f,s))===u?i++:(i>=5&&(n+=r+(i-5)),u=h,i=1)}o>=5&&(n+=r+(o-5)),i>=5&&(n+=r+(i-5))}return n},e.getPenaltyN2=function(t){for(var e=t.size,r=0,o=0;o<e-1;o++)for(var i=0;i<e-1;i++){var a=t.get(o,i)+t.get(o,i+1)+t.get(o+1,i)+t.get(o+1,i+1);4!==a&&0!==a||r++}return r*n},e.getPenaltyN3=function(t){for(var e=t.size,r=0,n=0,i=0,a=0;a<e;a++){n=i=0;for(var u=0;u<e;u++)n=n<<1&2047|t.get(a,u),u>=10&&(1488===n||93===n)&&r++,i=i<<1&2047|t.get(u,a),u>=10&&(1488===i||93===i)&&r++}return r*o},e.getPenaltyN4=function(t){for(var e=0,r=t.data.length,n=0;n<r;n++)e+=t.data[n];return Math.abs(Math.ceil(100*e/r/5)-10)*i},e.applyMask=function(t,e){for(var r=e.size,n=0;n<r;n++)for(var o=0;o<r;o++)e.isReserved(o,n)||e.xor(o,n,a(t,o,n))},e.getBestMask=function(t,r){for(var n=Object.keys(e.Patterns).length,o=0,i=1/0,a=0;a<n;a++){r(a),e.applyMask(a,t);var u=e.getPenaltyN1(t)+e.getPenaltyN2(t)+e.getPenaltyN3(t)+e.getPenaltyN4(t);e.applyMask(a,t),u<i&&(i=u,o=a)}return o}},804(t,e,r){var n=r(410),o=r(960);e.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},e.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},e.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(t,e){if(!t.ccBits)throw new Error("Invalid mode: "+t);if(!n.isValid(e))throw new Error("Invalid version: "+e);return e>=1&&e<10?t.ccBits[0]:e<27?t.ccBits[1]:t.ccBits[2]},e.getBestModeForData=function(t){return o.testNumeric(t)?e.NUMERIC:o.testAlphanumeric(t)?e.ALPHANUMERIC:o.testKanji(t)?e.KANJI:e.BYTE},e.toString=function(t){if(t&&t.id)return t.id;throw new Error("Invalid mode")},e.isValid=function(t){return t&&t.bit&&t.ccBits},e.from=function(t,r){if(e.isValid(t))return t;try{return function(t){if("string"!=typeof t)throw new Error("Param is not a string");switch(t.toLowerCase()){case"numeric":return e.NUMERIC;case"alphanumeric":return e.ALPHANUMERIC;case"kanji":return e.KANJI;case"byte":return e.BYTE;default:throw new Error("Unknown mode: "+t)}}(t)}catch(t){return r}}},889(t,e,r){var n=r(804);function o(t){this.mode=n.NUMERIC,this.data=t.toString()}o.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(t){var e,r,n;for(e=0;e+3<=this.data.length;e+=3)r=this.data.substr(e,3),n=parseInt(r,10),t.put(n,10);var o=this.data.length-e;o>0&&(r=this.data.substr(e),n=parseInt(r,10),t.put(n,3*o+1))},t.exports=o},797(t,e,r){var n=r(103);e.mul=function(t,e){for(var r=new Uint8Array(t.length+e.length-1),o=0;o<t.length;o++)for(var i=0;i<e.length;i++)r[o+i]^=n.mul(t[o],e[i]);return r},e.mod=function(t,e){for(var r=new Uint8Array(t);r.length-e.length>=0;){for(var o=r[0],i=0;i<e.length;i++)r[i]^=n.mul(e[i],o);for(var a=0;a<r.length&&0===r[a];)a++;r=r.slice(a)}return r},e.generateECPolynomial=function(t){for(var r=new Uint8Array([1]),o=0;o<t;o++)r=e.mul(r,new Uint8Array([1,n.exp(o)]));return r}},433(t,e,r){var n=r(154),o=r(125),i=r(671),a=r(16),u=r(694),s=r(328),f=r(776),h=r(42),c=r(112),g=r(359),d=r(89),l=r(804),v=r(981);function p(t,e,r){var n,o,i=t.size,a=d.getEncodedBits(e,r);for(n=0;n<15;n++)o=1==(a>>n&1),n<6?t.set(n,8,o,!0):n<8?t.set(n+1,8,o,!0):t.set(i-15+n,8,o,!0),n<8?t.set(8,i-n-1,o,!0):n<9?t.set(8,15-n-1+1,o,!0):t.set(8,15-n-1,o,!0);t.set(i-8,8,1,!0)}function w(t,e,r){var o=new i;r.forEach(function(e){o.put(e.mode.bit,4),o.put(e.getLength(),l.getCharCountIndicator(e.mode,t)),e.write(o)});var a=8*(n.getSymbolTotalCodewords(t)-h.getTotalCodewordsCount(t,e));for(o.getLengthInBits()+4<=a&&o.put(0,4);o.getLengthInBits()%8!=0;)o.putBit(0);for(var u=(a-o.getLengthInBits())/8,s=0;s<u;s++)o.put(s%2?17:236,8);return function(t,e,r){for(var o=n.getSymbolTotalCodewords(e),i=h.getTotalCodewordsCount(e,r),a=o-i,u=h.getBlocksCount(e,r),s=u-o%u,f=Math.floor(o/u),g=Math.floor(a/u),d=g+1,l=f-g,v=new c(l),p=0,w=new Array(u),m=new Array(u),E=0,y=new Uint8Array(t.buffer),A=0;A<u;A++){var C=A<s?g:d;w[A]=y.slice(p,p+C),m[A]=v.encode(w[A]),p+=C,E=Math.max(E,C)}var B,I,M=new Uint8Array(o),T=0;for(B=0;B<E;B++)for(I=0;I<u;I++)B<w[I].length&&(M[T++]=w[I][B]);for(B=0;B<l;B++)for(I=0;I<u;I++)M[T++]=m[I][B];return M}(o,t,e)}function m(t,e,r,o){var i;if(Array.isArray(t))i=v.fromArray(t);else{if("string"!=typeof t)throw new Error("Invalid data");var h=e;if(!h){var c=v.rawSplit(t);h=g.getBestVersionForData(c,r)}i=v.fromString(t,h||40)}var d=g.getBestVersionForData(i,r);if(!d)throw new Error("The amount of data is too big to be stored in a QR Code");if(e){if(e<d)throw new Error("\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: "+d+".\n")}else e=d;var l=w(e,r,i),m=n.getSymbolSize(e),E=new a(m);return function(t,e){for(var r=t.size,n=s.getPositions(e),o=0;o<n.length;o++)for(var i=n[o][0],a=n[o][1],u=-1;u<=7;u++)if(!(i+u<=-1||r<=i+u))for(var f=-1;f<=7;f++)a+f<=-1||r<=a+f||(u>=0&&u<=6&&(0===f||6===f)||f>=0&&f<=6&&(0===u||6===u)||u>=2&&u<=4&&f>=2&&f<=4?t.set(i+u,a+f,!0,!0):t.set(i+u,a+f,!1,!0))}(E,e),function(t){for(var e=t.size,r=8;r<e-8;r++){var n=r%2==0;t.set(r,6,n,!0),t.set(6,r,n,!0)}}(E),function(t,e){for(var r=u.getPositions(e),n=0;n<r.length;n++)for(var o=r[n][0],i=r[n][1],a=-2;a<=2;a++)for(var s=-2;s<=2;s++)-2===a||2===a||-2===s||2===s||0===a&&0===s?t.set(o+a,i+s,!0,!0):t.set(o+a,i+s,!1,!0)}(E,e),p(E,r,0),e>=7&&function(t,e){for(var r,n,o,i=t.size,a=g.getEncodedBits(e),u=0;u<18;u++)r=Math.floor(u/3),n=u%3+i-8-3,o=1==(a>>u&1),t.set(r,n,o,!0),t.set(n,r,o,!0)}(E,e),function(t,e){for(var r=t.size,n=-1,o=r-1,i=7,a=0,u=r-1;u>0;u-=2)for(6===u&&u--;;){for(var s=0;s<2;s++)if(!t.isReserved(o,u-s)){var f=!1;a<e.length&&(f=1==(e[a]>>>i&1)),t.set(o,u-s,f),-1===--i&&(a++,i=7)}if((o+=n)<0||r<=o){o-=n,n=-n;break}}}(E,l),isNaN(o)&&(o=f.getBestMask(E,p.bind(null,E,r))),f.applyMask(o,E),p(E,r,o),{modules:E,version:e,errorCorrectionLevel:r,maskPattern:o,segments:i}}e.create=function(t,e){if(void 0===t||""===t)throw new Error("No input text");var r,i,a=o.M;return void 0!==e&&(a=o.from(e.errorCorrectionLevel,o.M),r=g.from(e.version),i=f.from(e.maskPattern),e.toSJISFunc&&n.setToSJISFunction(e.toSJISFunc)),m(t,r,a,i)}},112(t,e,r){var n=r(797);function o(t){this.genPoly=void 0,this.degree=t,this.degree&&this.initialize(this.degree)}o.prototype.initialize=function(t){this.degree=t,this.genPoly=n.generateECPolynomial(this.degree)},o.prototype.encode=function(t){if(!this.genPoly)throw new Error("Encoder not initialized");var e=new Uint8Array(t.length+this.degree);e.set(t);var r=n.mod(e,this.genPoly),o=this.degree-r.length;if(o>0){var i=new Uint8Array(this.degree);return i.set(r,o),i}return r},t.exports=o},960(t,e){var r="[0-9]+",n="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+",o="(?:(?![A-Z0-9 $%*+\\-./:]|"+(n=n.replace(/u/g,"\\u"))+")(?:.|[\r\n]))+";e.KANJI=new RegExp(n,"g"),e.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),e.BYTE=new RegExp(o,"g"),e.NUMERIC=new RegExp(r,"g"),e.ALPHANUMERIC=new RegExp("[A-Z $%*+\\-./:]+","g");var i=new RegExp("^"+n+"$"),a=new RegExp("^"+r+"$"),u=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");e.testKanji=function(t){return i.test(t)},e.testNumeric=function(t){return a.test(t)},e.testAlphanumeric=function(t){return u.test(t)}},981(t,e,r){var n=r(804),o=r(889),i=r(453),a=r(842),u=r(857),s=r(960),f=r(154),h=r(51);function c(t){return unescape(encodeURIComponent(t)).length}function g(t,e,r){for(var n,o=[];null!==(n=t.exec(r));)o.push({data:n[0],index:n.index,mode:e,length:n[0].length});return o}function d(t){var e,r,o=g(s.NUMERIC,n.NUMERIC,t),i=g(s.ALPHANUMERIC,n.ALPHANUMERIC,t);return f.isKanjiModeEnabled()?(e=g(s.BYTE,n.BYTE,t),r=g(s.KANJI,n.KANJI,t)):(e=g(s.BYTE_KANJI,n.BYTE,t),r=[]),o.concat(i,e,r).sort(function(t,e){return t.index-e.index}).map(function(t){return{data:t.data,mode:t.mode,length:t.length}})}function l(t,e){switch(e){case n.NUMERIC:return o.getBitsLength(t);case n.ALPHANUMERIC:return i.getBitsLength(t);case n.KANJI:return u.getBitsLength(t);case n.BYTE:return a.getBitsLength(t)}}function v(t,e){var r,s=n.getBestModeForData(t);if((r=n.from(e,s))!==n.BYTE&&r.bit<s.bit)throw new Error('"'+t+'" cannot be encoded with mode '+n.toString(r)+".\n Suggested mode is: "+n.toString(s));switch(r!==n.KANJI||f.isKanjiModeEnabled()||(r=n.BYTE),r){case n.NUMERIC:return new o(t);case n.ALPHANUMERIC:return new i(t);case n.KANJI:return new u(t);case n.BYTE:return new a(t)}}e.fromArray=function(t){return t.reduce(function(t,e){return"string"==typeof e?t.push(v(e,null)):e.data&&t.push(v(e.data,e.mode)),t},[])},e.fromString=function(t,r){for(var o=function(t){for(var e=[],r=0;r<t.length;r++){var o=t[r];switch(o.mode){case n.NUMERIC:e.push([o,{data:o.data,mode:n.ALPHANUMERIC,length:o.length},{data:o.data,mode:n.BYTE,length:o.length}]);break;case n.ALPHANUMERIC:e.push([o,{data:o.data,mode:n.BYTE,length:o.length}]);break;case n.KANJI:e.push([o,{data:o.data,mode:n.BYTE,length:c(o.data)}]);break;case n.BYTE:e.push([{data:o.data,mode:n.BYTE,length:c(o.data)}])}}return e}(d(t,f.isKanjiModeEnabled())),i=function(t,e){for(var r={},o={start:{}},i=["start"],a=0;a<t.length;a++){for(var u=t[a],s=[],f=0;f<u.length;f++){var h=u[f],c=""+a+f;s.push(c),r[c]={node:h,lastCount:0},o[c]={};for(var g=0;g<i.length;g++){var d=i[g];r[d]&&r[d].node.mode===h.mode?(o[d][c]=l(r[d].lastCount+h.length,h.mode)-l(r[d].lastCount,h.mode),r[d].lastCount+=h.length):(r[d]&&(r[d].lastCount=h.length),o[d][c]=l(h.length,h.mode)+4+n.getCharCountIndicator(h.mode,e))}}i=s}for(var v=0;v<i.length;v++)o[i[v]].end=0;return{map:o,table:r}}(o,r),a=h.find_path(i.map,"start","end"),u=[],s=1;s<a.length-1;s++)u.push(i.table[a[s]].node);return e.fromArray(function(t){return t.reduce(function(t,e){var r=t.length-1>=0?t[t.length-1]:null;return r&&r.mode===e.mode?(t[t.length-1].data+=e.data,t):(t.push(e),t)},[])}(u))},e.rawSplit=function(t){return e.fromArray(d(t,f.isKanjiModeEnabled()))}},154(t,e){var r,n=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];e.getSymbolSize=function(t){if(!t)throw new Error('"version" cannot be null or undefined');if(t<1||t>40)throw new Error('"version" should be in range from 1 to 40');return 4*t+17},e.getSymbolTotalCodewords=function(t){return n[t]},e.getBCHDigit=function(t){for(var e=0;0!==t;)e++,t>>>=1;return e},e.setToSJISFunction=function(t){if("function"!=typeof t)throw new Error('"toSJISFunc" is not a valid function.');r=t},e.isKanjiModeEnabled=function(){return void 0!==r},e.toSJIS=function(t){return r(t)}},410(t,e){e.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40}},359(t,e,r){var n=r(154),o=r(42),i=r(125),a=r(804),u=r(410),s=n.getBCHDigit(7973);function f(t,e){return a.getCharCountIndicator(t,e)+4}function h(t,e){var r=0;return t.forEach(function(t){var n=f(t.mode,e);r+=n+t.getBitsLength()}),r}e.from=function(t,e){return u.isValid(t)?parseInt(t,10):e},e.getCapacity=function(t,e,r){if(!u.isValid(t))throw new Error("Invalid QR Code version");void 0===r&&(r=a.BYTE);var i=8*(n.getSymbolTotalCodewords(t)-o.getTotalCodewordsCount(t,e));if(r===a.MIXED)return i;var s=i-f(r,t);switch(r){case a.NUMERIC:return Math.floor(s/10*3);case a.ALPHANUMERIC:return Math.floor(s/11*2);case a.KANJI:return Math.floor(s/13);case a.BYTE:default:return Math.floor(s/8)}},e.getBestVersionForData=function(t,r){var n,o=i.from(r,i.M);if(Array.isArray(t)){if(t.length>1)return function(t,r){for(var n=1;n<=40;n++)if(h(t,n)<=e.getCapacity(n,r,a.MIXED))return n}(t,o);if(0===t.length)return 1;n=t[0]}else n=t;return function(t,r,n){for(var o=1;o<=40;o++)if(r<=e.getCapacity(o,n,t))return o}(n.mode,n.getLength(),o)},e.getEncodedBits=function(t){if(!u.isValid(t)||t<7)throw new Error("Invalid QR Code version");for(var e=t<<12;n.getBCHDigit(e)-s>=0;)e^=7973<<n.getBCHDigit(e)-s;return t<<12|e}},879(t,e,r){var n=r(146);e.render=function(t,e,r){var o=r,i=e;void 0!==o||e&&e.getContext||(o=e,e=void 0),e||(i=function(){try{return document.createElement("canvas")}catch(t){throw new Error("You need to specify a canvas element")}}()),o=n.getOptions(o);var a=n.getImageWidth(t.modules.size,o),u=i.getContext("2d"),s=u.createImageData(a,a);return n.qrToImageData(s.data,t,o),function(t,e,r){t.clearRect(0,0,e.width,e.height),e.style||(e.style={}),e.height=r,e.width=r,e.style.height=r+"px",e.style.width=r+"px"}(u,i,a),u.putImageData(s,0,0),i},e.renderToDataURL=function(t,r,n){var o=n;void 0!==o||r&&r.getContext||(o=r,r=void 0),o||(o={});var i=e.render(t,r,o),a=o.type||"image/png",u=o.rendererOpts||{};return i.toDataURL(a,u.quality)}},648(t,e,r){var n=r(146);function o(t,e){var r=t.a/255,n=e+'="'+t.hex+'"';return r<1?n+" "+e+'-opacity="'+r.toFixed(2).slice(1)+'"':n}function i(t,e,r){var n=t+e;return void 0!==r&&(n+=" "+r),n}e.render=function(t,e,r){var a=n.getOptions(e),u=t.modules.size,s=t.modules.data,f=u+2*a.margin,h=a.color.light.a?"<path "+o(a.color.light,"fill")+' d="M0 0h'+f+"v"+f+'H0z"/>':"",c="<path "+o(a.color.dark,"stroke")+' d="'+function(t,e,r){for(var n="",o=0,a=!1,u=0,s=0;s<t.length;s++){var f=Math.floor(s%e),h=Math.floor(s/e);f||a||(a=!0),t[s]?(u++,s>0&&f>0&&t[s-1]||(n+=a?i("M",f+r,.5+h+r):i("m",o,0),o=0,a=!1),f+1<e&&t[s+1]||(n+=i("h",u),u=0)):o++}return n}(s,u,a.margin)+'"/>',g='viewBox="0 0 '+f+" "+f+'"',d='<svg xmlns="http://www.w3.org/2000/svg" '+(a.width?'width="'+a.width+'" height="'+a.width+'" ':"")+g+' shape-rendering="crispEdges">'+h+c+"</svg>\n";return"function"==typeof r&&r(null,d),d}},146(t,e){function r(t){if("number"==typeof t&&(t=t.toString()),"string"!=typeof t)throw new Error("Color should be defined as hex string");var e=t.slice().replace("#","").split("");if(e.length<3||5===e.length||e.length>8)throw new Error("Invalid hex color: "+t);3!==e.length&&4!==e.length||(e=Array.prototype.concat.apply([],e.map(function(t){return[t,t]}))),6===e.length&&e.push("F","F");var r=parseInt(e.join(""),16);return{r:r>>24&255,g:r>>16&255,b:r>>8&255,a:255&r,hex:"#"+e.slice(0,6).join("")}}e.getOptions=function(t){t||(t={}),t.color||(t.color={});var e=void 0===t.margin||null===t.margin||t.margin<0?4:t.margin,n=t.width&&t.width>=21?t.width:void 0,o=t.scale||4;return{width:n,scale:n?4:o,margin:e,color:{dark:r(t.color.dark||"#000000ff"),light:r(t.color.light||"#ffffffff")},type:t.type,rendererOpts:t.rendererOpts||{}}},e.getScale=function(t,e){return e.width&&e.width>=t+2*e.margin?e.width/(t+2*e.margin):e.scale},e.getImageWidth=function(t,r){var n=e.getScale(t,r);return Math.floor((t+2*r.margin)*n)},e.qrToImageData=function(t,r,n){for(var o=r.modules.size,i=r.modules.data,a=e.getScale(o,n),u=Math.floor((o+2*n.margin)*a),s=n.margin*a,f=[n.color.light,n.color.dark],h=0;h<u;h++)for(var c=0;c<u;c++){var g=4*(h*u+c),d=n.color.light;if(h>=s&&c>=s&&h<u-s&&c<u-s)d=f[i[Math.floor((h-s)/a)*o+Math.floor((c-s)/a)]?1:0];t[g++]=d.r,t[g++]=d.g,t[g++]=d.b,t[g]=d.a}}}}]);
|