generated from VLADIMIR/template_frontend
5 lines
15 KiB
JavaScript
5 lines
15 KiB
JavaScript
import{E as e,R as t,X as n,k as r,rt as i,v as a,z as o}from"./vue-router-CyfP71JJ.js";import{G as s,K as c,M as l,N as u,r as d,t as f}from"./light-CPiNeYrP.js";function p(e){return{borderRadius:e.borderRadius}}var m={name:`QrCode`,common:f,self:p},h;(function(e){class t{static encodeText(n,r){let i=e.QrSegment.makeSegments(n);return t.encodeSegments(i,r)}static encodeBinary(n,r){let i=e.QrSegment.makeBytes(n);return t.encodeSegments([i],r)}static encodeSegments(e,r,a=1,o=40,s=-1,c=!0){if(!(t.MIN_VERSION<=a&&a<=o&&o<=t.MAX_VERSION)||s<-1||s>7)throw RangeError(`Invalid value`);let l,u;for(l=a;;l++){let n=t.getNumDataCodewords(l,r)*8,a=i.getTotalBits(e,l);if(a<=n){u=a;break}if(l>=o)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])c&&u<=t.getNumDataCodewords(l,e)*8&&(r=e);let d=[];for(let t of e){n(t.mode.modeBits,4,d),n(t.numChars,t.mode.numCharCountBits(l),d);for(let e of t.getData())d.push(e)}let f=t.getNumDataCodewords(l,r)*8;n(0,Math.min(4,f-d.length),d),n(0,(8-d.length%8)%8,d);for(let e=236;d.length<f;e^=253)n(e,8,d);let p=[];for(;p.length*8<d.length;)p.push(0);return d.forEach((e,t)=>p[t>>>3]|=e<<7-(t&7)),new t(l,r,p,s)}constructor(e,n,r,i){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version value out of range`);if(i<-1||i>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let a=[];for(let e=0;e<this.size;e++)a.push(!1);for(let e=0;e<this.size;e++)this.modules.push(a.slice()),this.isFunction.push(a.slice());this.drawFunctionPatterns();let o=this.addEccAndInterleave(r);if(this.drawCodewords(o),i===-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(i=t,e=n),this.applyMask(t)}}this.mask=i,this.applyMask(i),this.drawFormatBits(i),this.isFunction=[]}getModule(e,t){return e>=0&&e<this.size&&t>=0&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0),this.setFunctionModule(e,6,e%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n===0&&r===0||n===0&&r===t-1||n===t-1&&r===0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.errorCorrectionLevel.formatBits<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let i=(t<<10|n)^21522;for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(i,e));this.setFunctionModule(8,7,r(i,6)),this.setFunctionModule(8,8,r(i,7)),this.setFunctionModule(7,8,r(i,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(i,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(i,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(i,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;a>=0&&a<this.size&&o>=0&&o<this.size&&this.setFunctionModule(a,o,i!==2&&i!==4)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!==1)}setFunctionModule(e,t,n){this.modules[t][e]=n,this.isFunction[t][e]=!0}addEccAndInterleave(e){let n=this.version,r=this.errorCorrectionLevel;if(e.length!==t.getNumDataCodewords(n,r))throw RangeError(`Invalid argument`);let i=t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][n],a=t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][n],o=Math.floor(t.getNumRawDataModules(n)/8),s=i-o%i,c=Math.floor(o/i),l=[],u=t.reedSolomonComputeDivisor(a);for(let n=0,r=0;n<i;n++){let i=e.slice(r,r+c-a+(n<s?0:1));r+=i.length;let o=t.reedSolomonComputeRemainder(i,u);n<s&&i.push(0),l.push(i.concat(o))}let d=[];for(let e=0;e<l[0].length;e++)l.forEach((t,n)=>{(e!==c-a||n>=s)&&d.push(t[e])});return d}drawCodewords(e){if(e.length!==Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t===6&&(t=5);for(let i=0;i<this.size;i++)for(let a=0;a<2;a++){let o=t-a,s=t+1&2?i:this.size-1-i;!this.isFunction[s][o]&&n<e.length*8&&(this.modules[s][o]=r(e[n>>>3],7-(n&7)),n++)}}}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.isFunction[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[n][o]===r?(i++,i===5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[o][n]===r?(i++,i===5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size-1;n++)for(let r=0;r<this.size-1;r++){let i=this.modules[n][r];i===this.modules[n][r+1]&&i===this.modules[n+1][r]&&i===this.modules[n+1][r+1]&&(e+=t.PENALTY_N2)}let n=0;for(let e of this.modules)n=e.reduce((e,t)=>e+ +!!t,n);let r=this.size*this.size,i=Math.ceil(Math.abs(n*20-r*10)/r)-1;return e+=i*t.PENALTY_N4,e}getAlignmentPatternPositions(){if(this.version===1)return[];{let e=Math.floor(this.version/7)+2,t=this.version===32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t<e-1;t++)n.push(0);n.push(1);let r=1;for(let i=0;i<e;i++){for(let e=0;e<n.length;e++)n[e]=t.reedSolomonMultiply(n[e],r),e+1<n.length&&(n[e]^=n[e+1]);r=t.reedSolomonMultiply(r,2)}return n}static reedSolomonComputeRemainder(e,n){let r=n.map(e=>0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return n}finderPenaltyCountPatterns(e){let t=e[1],n=t>0&&e[2]===t&&e[3]===t*3&&e[4]===t&&e[5]===t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]===0&&(e+=this.size),t.pop(),t.unshift(e)}}t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}class i{static makeBytes(e){let t=[];for(let r of e)n(r,8,t);return new i(i.Mode.BYTE,e.length,t)}static makeNumeric(e){if(!i.isNumeric(e))throw RangeError(`String contains non-numeric characters`);let t=[];for(let r=0;r<e.length;){let i=Math.min(e.length-r,3);n(Number.parseInt(e.substr(r,i),10),i*3+1,t),r+=i}return new i(i.Mode.NUMERIC,e.length,t)}static makeAlphanumeric(e){if(!i.isAlphanumeric(e))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let t=[],r;for(r=0;r+2<=e.length;r+=2){let a=i.ALPHANUMERIC_CHARSET.indexOf(e.charAt(r))*45;a+=i.ALPHANUMERIC_CHARSET.indexOf(e.charAt(r+1)),n(a,11,t)}return r<e.length&&n(i.ALPHANUMERIC_CHARSET.indexOf(e.charAt(r)),6,t),new i(i.Mode.ALPHANUMERIC,e.length,t)}static makeSegments(e){return e===``?[]:i.isNumeric(e)?[i.makeNumeric(e)]:i.isAlphanumeric(e)?[i.makeAlphanumeric(e)]:[i.makeBytes(i.toUtf8ByteArray(e))]}static makeEci(e){let t=[];if(e<0)throw RangeError(`ECI assignment value out of range`);if(e<128)n(e,8,t);else if(e<16384)n(2,2,t),n(e,14,t);else if(e<1e6)n(6,3,t),n(e,21,t);else throw RangeError(`ECI assignment value out of range`);return new i(i.Mode.ECI,0,t)}static isNumeric(e){return i.NUMERIC_REGEX.test(e)}static isAlphanumeric(e){return i.ALPHANUMERIC_REGEX.test(e)}constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}getData(){return this.bitData.slice()}static getTotalBits(e,t){let n=0;for(let r of e){let e=r.mode.numCharCountBits(t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)===`%`?(t.push(Number.parseInt(e.substr(n+1,2),16)),n+=2):t.push(e.charCodeAt(n));return t}}i.NUMERIC_REGEX=/^[0-9]*$/,i.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+./:-]*$/,i.ALPHANUMERIC_CHARSET=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`,e.QrSegment=i})(h||={}),(function(e){(function(e){class t{constructor(e,t){this.ordinal=e,this.formatBits=t}}t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(h||={}),(function(e){(function(e){class t{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}}t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(h||={});var g=h,_=s([c(`qr-code`,`
|
|
background: #fff;
|
|
border-radius: var(--n-border-radius);
|
|
display: inline-flex;
|
|
`)]),v={L:g.QrCode.Ecc.LOW,M:g.QrCode.Ecc.MEDIUM,Q:g.QrCode.Ecc.QUARTILE,H:g.QrCode.Ecc.HIGH},y=Object.assign(Object.assign({},d.props),{value:String,color:{type:String,default:`#000`},backgroundColor:{type:String,default:`#FFF`},iconSrc:String,iconSize:{type:Number,default:40},iconBackgroundColor:{type:String,default:`#FFF`},iconBorderRadius:{type:Number,default:4},size:{type:Number,default:100},padding:{type:[Number,String],default:12},errorCorrectionLevel:{type:String,default:`M`},type:{type:String,default:`canvas`}}),b=2,x=e({name:`QrCode`,props:y,setup(e){let{mergedClsPrefixRef:r,inlineThemeDisabled:o}=u(e),s=d(`QrCode`,`-qr-code`,_,m,e,r),c=a(()=>({"--n-border-radius":s.value.self.borderRadius})),f=o?l(`qr-code`,void 0,c,e):void 0,p=i(),h=a(()=>{let t=v[e.errorCorrectionLevel];return g.QrCode.encodeText(e.value??`-`,t)});t(()=>{let t=i(0),r=null;n(()=>{e.type!==`svg`&&(t.value,y(h.value,e.size,e.color,e.backgroundColor,r?{icon:r,iconBorderRadius:e.iconBorderRadius,iconSize:e.iconSize,iconBackgroundColor:e.iconBackgroundColor}:null))}),n(()=>{if(e.type===`svg`)return;let{iconSrc:n}=e;if(n){let e=!1,i=new Image;return i.src=n,i.onload=()=>{e||(r=i,t.value++)},()=>{e=!0}}})});function y(e,t,n,r,i){let a=p.value;if(!a)return;let o=t*b,s=o/e.size;a.width=o,a.height=o;let c=a.getContext(`2d`);if(c){c.clearRect(0,0,a.width,a.height);for(let t=0;t<e.size;t++)for(let i=0;i<e.size;i++){c.fillStyle=e.getModule(i,t)?n:r;let a=Math.floor(i*s),o=Math.ceil((i+1)*s),l=Math.floor(t*s),u=Math.ceil((t+1)*s);c.fillRect(a,l,o-a,u-l)}if(i){let{icon:e,iconBackgroundColor:t,iconBorderRadius:n,iconSize:r}=i,o=r*b,s=(a.width-o)/2,l=(a.height-o)/2;c.fillStyle=t,c.beginPath(),c.roundRect(s,l,o,o,n*b),c.fill();let u=e.width/e.height,d=u>=1?o:o*u,f=u<=1?o:o/u,p=s+(o-d)/2,m=l+(o-f)/2;c.drawImage(e,p,m,d,f)}}}function x(e,t=0){let n=[];return e.forEach((e,r)=>{let i=null;e.forEach((a,o)=>{if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function S(t,n,r){let i=t.getModules(),a=i.length,o=i,s=``,c=`<path fill="transparent" d="M0,0 h${a}v${a}H0z" shape-rendering="crispEdges"></path>`,l=`<path fill="${e.color}" d="${x(o,0)}" shape-rendering="crispEdges"></path>`,u=``;if(r){let{iconSrc:e,iconSize:t}=r,o=Math.floor(n*.1),s=a/n,c=(t||o)*s,l=(t||o)*s,d=i.length/2-l/2,f=i.length/2-c/2;u+=`<image href="${e}" width="${l}" height="${c}" x="${d}" y="${f}" preserveAspectRatio="none"></image>`}return s+=c,s+=l,s+=u,{innerHtml:s,numCells:a}}let C=a(()=>S(h.value,e.size,e.iconSrc?{iconSrc:e.iconSrc,iconBorderRadius:e.iconBorderRadius,iconSize:e.iconSize,iconBackgroundColor:e.iconBackgroundColor}:null));return{canvasRef:p,mergedClsPrefix:r,cssVars:o?void 0:c,themeClass:f?.themeClass,svgInfo:C}},render(){let{mergedClsPrefix:e,backgroundColor:t,padding:n,cssVars:i,themeClass:a,size:o,type:s}=this;return r(`div`,{class:[`${e}-qr-code`,a],style:Object.assign({padding:typeof n==`number`?`${n}px`:n,backgroundColor:t,width:`${o}px`,height:`${o}px`},i)},s===`canvas`?r(`canvas`,{ref:`canvasRef`,style:{width:`${o}px`,height:`${o}px`}}):r(`svg`,{height:o,width:o,viewBox:`0 0 ${this.svgInfo.numCells} ${this.svgInfo.numCells}`,role:`img`,innerHTML:this.svgInfo.innerHtml}))}});function S(e,n=5e3){let r=i(!0),a=null,s=()=>{r.value=!0,e(),a=window.setInterval(e,n)},c=()=>{r.value=!1,a&&=(clearInterval(a),null)};return t(s),o(c),{isActive:r,start:s,stop:c}}export{x as n,S as t}; |