7 lines
21 KiB
JavaScript
7 lines
21 KiB
JavaScript
import{d as e,c as t,a9 as n,o as r,x as i,g as o,e as a,f as s,w as u,p as l,bU as h,z as c}from"./index-RXP3BP3O.js";import{_ as f}from"./_plugin-vue_export-helper.BCo6x5W8.js";const d={value:String,icon:String,size:{type:[Number,String],default:160},iconSize:{type:[Number,String],default:40},marginSize:Number,color:{type:String,default:"#000"},bgColor:{type:String,default:"transparent"},bordered:{type:Boolean,default:!0},errorLevel:{type:String,default:"M"},useCanvasToTempFilePath:Boolean,use2d:{type:Boolean,default:!0}};async function v(e,t){let{context:n}=t;return function(e,t,n=!1){return null==t?Promise.reject("context is null"):(t.context&&(t=t.context),new Promise((r,i)=>{const o=uni.createSelectorQuery().in(t).select(e),a=e=>{e?r(e):i("no rect")};n?o.fields({node:!0,size:!0,rect:!0},a).exec():o.boundingClientRect(a).exec()}))}("#"+e,n,false).then(t=>{if(t.node)return t.node;{const r=uni.createCanvasContext(e,n);return{getContext(e){if("2d"==e)return r},width:t.width,height:t.height}}})}function g(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function m(e,t){for(var n=0;t.length>n;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function y(e,t,n){return t&&m(e.prototype,t),n&&m(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);t>n;n++)r[n]=e[n];return r}function w(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return p(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?p(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return e.length>r?{done:!1,value:e[r++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}
|
|
/**
|
|
* @license QR Code generator library (TypeScript)
|
|
* Copyright (c) Project Nayuki.
|
|
* SPDX-License-Identifier: MIT
|
|
*/var E,C,M,R;!function(e){var t=function(){function t(e,n,r,o){if(g(this,t),this.version=void 0,this.errorCorrectionLevel=void 0,this.size=void 0,this.mask=void 0,this.modules=[],this.isFunction=[],this.version=e,this.errorCorrectionLevel=n,t.MIN_VERSION>e||e>t.MAX_VERSION)throw new RangeError("Version value out of range");if(-1>o||o>7)throw new RangeError("Mask value out of range");this.size=4*e+17;for(var a=[],s=0;this.size>s;s++)a.push(!1);for(var u=0;this.size>u;u++)this.modules.push(a.slice()),this.isFunction.push(a.slice());this.drawFunctionPatterns();var l=this.addEccAndInterleave(r);if(this.drawCodewords(l),-1==o)for(var h=1e9,c=0;8>c;c++){this.applyMask(c),this.drawFormatBits(c);var f=this.getPenaltyScore();h>f&&(o=c,h=f),this.applyMask(c)}i(o>=0&&7>=o),this.mask=o,this.applyMask(o),this.drawFormatBits(o),this.isFunction=[]}return y(t,[{key:"getModule",value:function(e,t){return e>=0&&this.size>e&&t>=0&&this.size>t&&this.modules[t][e]}},{key:"getModules",value:function(){return this.modules}},{key:"drawFunctionPatterns",value:function(){for(var e=0;this.size>e;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);for(var t=this.getAlignmentPatternPositions(),n=t.length,r=0;n>r;r++)for(var i=0;n>i;i++)0==r&&0==i||0==r&&i==n-1||r==n-1&&0==i||this.drawAlignmentPattern(t[r],t[i]);this.drawFormatBits(0),this.drawVersion()}},{key:"drawFormatBits",value:function(e){for(var t=this.errorCorrectionLevel.formatBits<<3|e,n=t,o=0;10>o;o++)n=n<<1^1335*(n>>>9);var a=21522^(t<<10|n);i(a>>>15==0);for(var s=0;5>=s;s++)this.setFunctionModule(8,s,r(a,s));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(var u=9;15>u;u++)this.setFunctionModule(14-u,8,r(a,u));for(var l=0;8>l;l++)this.setFunctionModule(this.size-1-l,8,r(a,l));for(var h=8;15>h;h++)this.setFunctionModule(8,this.size-15+h,r(a,h));this.setFunctionModule(8,this.size-8,!0)}},{key:"drawVersion",value:function(){if(this.version>=7){for(var e=this.version,t=0;12>t;t++)e=e<<1^7973*(e>>>11);var n=this.version<<12|e;i(n>>>18==0);for(var o=0;18>o;o++){var a=r(n,o),s=this.size-11+o%3,u=Math.floor(o/3);this.setFunctionModule(s,u,a),this.setFunctionModule(u,s,a)}}}},{key:"drawFinderPattern",value:function(e,t){for(var n=-4;4>=n;n++)for(var r=-4;4>=r;r++){var i=Math.max(Math.abs(r),Math.abs(n)),o=e+r,a=t+n;o>=0&&this.size>o&&a>=0&&this.size>a&&this.setFunctionModule(o,a,2!=i&&4!=i)}}},{key:"drawAlignmentPattern",value:function(e,t){for(var n=-2;2>=n;n++)for(var r=-2;2>=r;r++)this.setFunctionModule(e+r,t+n,1!=Math.max(Math.abs(r),Math.abs(n)))}},{key:"setFunctionModule",value:function(e,t,n){this.modules[t][e]=n,this.isFunction[t][e]=!0}},{key:"addEccAndInterleave",value:function(e){var n=this.version,r=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(n,r))throw new RangeError("Invalid argument");for(var o=t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][n],a=t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][n],s=Math.floor(t.getNumRawDataModules(n)/8),u=o-s%o,l=Math.floor(s/o),h=[],c=t.reedSolomonComputeDivisor(a),f=0,d=0;o>f;f++){var v=e.slice(d,d+l-a+(u>f?0:1));d+=v.length;var g=t.reedSolomonComputeRemainder(v,c);u>f&&v.push(0),h.push(v.concat(g))}for(var m=[],y=function(e){h.forEach(function(t,n){e==l-a&&u>n||m.push(t[e])})},p=0;h[0].length>p;p++)y(p);return i(m.length==s),m}},{key:"drawCodewords",value:function(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");for(var n=0,o=this.size-1;o>=1;o-=2){6==o&&(o=5);for(var a=0;this.size>a;a++)for(var s=0;2>s;s++){var u=o-s,l=o+1&2?a:this.size-1-a;!this.isFunction[l][u]&&8*e.length>n&&(this.modules[l][u]=r(e[n>>>3],7-(7&n)),n++)}}i(n==8*e.length)}},{key:"applyMask",value:function(e){if(0>e||e>7)throw new RangeError("Mask value out of range");for(var t=0;this.size>t;t++)for(var n=0;this.size>n;n++){var r=void 0;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])}}},{key:"getPenaltyScore",value:function(){for(var e=0,n=0;this.size>n;n++){for(var r=!1,o=0,a=[0,0,0,0,0,0,0],s=0;this.size>s;s++)this.modules[n][s]==r?5==++o?e+=t.PENALTY_N1:o>5&&e++:(this.finderPenaltyAddHistory(o,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][s],o=1);e+=this.finderPenaltyTerminateAndCount(r,o,a)*t.PENALTY_N3}for(var u=0;this.size>u;u++){for(var l=!1,h=0,c=[0,0,0,0,0,0,0],f=0;this.size>f;f++)this.modules[f][u]==l?5==++h?e+=t.PENALTY_N1:h>5&&e++:(this.finderPenaltyAddHistory(h,c),l||(e+=this.finderPenaltyCountPatterns(c)*t.PENALTY_N3),l=this.modules[f][u],h=1);e+=this.finderPenaltyTerminateAndCount(l,h,c)*t.PENALTY_N3}for(var d=0;this.size-1>d;d++)for(var v=0;this.size-1>v;v++){var g=this.modules[d][v];g==this.modules[d][v+1]&&g==this.modules[d+1][v]&&g==this.modules[d+1][v+1]&&(e+=t.PENALTY_N2)}var m,y=0,p=w(this.modules);try{for(p.s();!(m=p.n()).done;)y=m.value.reduce(function(e,t){return e+(t?1:0)},y)}catch(M){p.e(M)}finally{p.f()}var E=this.size*this.size,C=Math.ceil(Math.abs(20*y-10*E)/E)-1;return i(C>=0&&9>=C),i((e+=C*t.PENALTY_N4)>=0&&2568888>=e),e}},{key:"getAlignmentPatternPositions",value:function(){if(1==this.version)return[];for(var e=Math.floor(this.version/7)+2,t=32==this.version?26:2*Math.ceil((4*this.version+4)/(2*e-2)),n=[6],r=this.size-7;e>n.length;r-=t)n.splice(1,0,r);return n}},{key:"finderPenaltyCountPatterns",value:function(e){var t=e[1];i(3*this.size>=t);var n=t>0&&e[2]==t&&e[3]==3*t&&e[4]==t&&e[5]==t;return(!n||4*t>e[0]||t>e[6]?0:1)+(!n||4*t>e[6]||t>e[0]?0:1)}},{key:"finderPenaltyTerminateAndCount",value:function(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),this.finderPenaltyAddHistory(t+=this.size,n),this.finderPenaltyCountPatterns(n)}},{key:"finderPenaltyAddHistory",value:function(e,t){0==t[0]&&(e+=this.size),t.pop(),t.unshift(e)}}],[{key:"encodeText",value:function(n,r){var i=e.QrSegment.makeSegments(n);return t.encodeSegments(i,r)}},{key:"encodeBinary",value:function(n,r){var i=e.QrSegment.makeBytes(n);return t.encodeSegments([i],r)}},{key:"encodeSegments",value:function(e,r){var a,s,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:40,h=arguments.length>4&&void 0!==arguments[4]?arguments[4]:-1,c=5>=arguments.length||void 0===arguments[5]||arguments[5];if(t.MIN_VERSION>u||u>l||l>t.MAX_VERSION||-1>h||h>7)throw new RangeError("Invalid value");for(a=u;;a++){var f=8*t.getNumDataCodewords(a,r),d=o.getTotalBits(e,a);if(f>=d){s=d;break}if(a>=l)throw new RangeError("Data too long")}for(var v=0,g=[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH];g.length>v;v++){var m=g[v];c&&s<=8*t.getNumDataCodewords(a,m)&&(r=m)}var y,p=[],E=w(e);try{for(E.s();!(y=E.n()).done;){var C=y.value;n(C.mode.modeBits,4,p),n(C.numChars,C.mode.numCharCountBits(a),p);var M,R=w(C.getData());try{for(R.s();!(M=R.n()).done;){var P=M.value;p.push(P)}}catch(I){R.e(I)}finally{R.f()}}}catch(I){E.e(I)}finally{E.f()}i(p.length==s);var A=8*t.getNumDataCodewords(a,r);i(A>=p.length),n(0,Math.min(4,A-p.length),p),n(0,(8-p.length%8)%8,p),i(p.length%8==0);for(var S=236;A>p.length;S^=253)n(S,8,p);for(var N=[];p.length>8*N.length;)N.push(0);return p.forEach(function(e,t){return N[t>>>3]|=e<<7-(7&t)}),new t(a,r,N,h)}},{key:"getNumRawDataModules",value:function(e){if(t.MIN_VERSION>e||e>t.MAX_VERSION)throw new RangeError("Version number out of range");var n=(16*e+128)*e+64;if(e>=2){var r=Math.floor(e/7)+2;n-=(25*r-10)*r-55,7>e||(n-=36)}return i(n>=208&&29648>=n),n}},{key:"getNumDataCodewords",value:function(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]}},{key:"reedSolomonComputeDivisor",value:function(e){if(1>e||e>255)throw new RangeError("Degree out of range");for(var n=[],r=0;e-1>r;r++)n.push(0);n.push(1);for(var i=1,o=0;e>o;o++){for(var a=0;n.length>a;a++)n[a]=t.reedSolomonMultiply(n[a],i),n.length>a+1&&(n[a]^=n[a+1]);i=t.reedSolomonMultiply(i,2)}return n}},{key:"reedSolomonComputeRemainder",value:function(e,n){var r,i=n.map(function(e){return 0}),o=w(e);try{var a=function(){var e=r.value^i.shift();i.push(0),n.forEach(function(n,r){return i[r]^=t.reedSolomonMultiply(n,e)})};for(o.s();!(r=o.n()).done;)a()}catch(s){o.e(s)}finally{o.f()}return i}},{key:"reedSolomonMultiply",value:function(e,t){if(e>>>8!=0||t>>>8!=0)throw new RangeError("Byte out of range");for(var n=0,r=7;r>=0;r--)n=n<<1^285*(n>>>7),n^=(t>>>r&1)*e;return i(n>>>8==0),n}}]),t}();function n(e,t,n){if(0>t||t>31||e>>>t!=0)throw new RangeError("Value out of range");for(var r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return!!(e>>>t&1)}function i(e){if(!e)throw Error("Assertion error")}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;var o=function(){function e(t,n,r){if(g(this,e),this.mode=void 0,this.numChars=void 0,this.bitData=void 0,this.mode=t,this.numChars=n,this.bitData=r,0>n)throw new RangeError("Invalid argument");this.bitData=r.slice()}return y(e,[{key:"getData",value:function(){return this.bitData.slice()}}],[{key:"makeBytes",value:function(t){var r,i=[],o=w(t);try{for(o.s();!(r=o.n()).done;)n(r.value,8,i)}catch(a){o.e(a)}finally{o.f()}return new e(e.Mode.BYTE,t.length,i)}},{key:"makeNumeric",value:function(t){if(!e.isNumeric(t))throw new RangeError("String contains non-numeric characters");for(var r=[],i=0;t.length>i;){var o=Math.min(t.length-i,3);n(parseInt(t.substring(i,i+o),10),3*o+1,r),i+=o}return new e(e.Mode.NUMERIC,t.length,r)}},{key:"makeAlphanumeric",value:function(t){if(!e.isAlphanumeric(t))throw new RangeError("String contains unencodable characters in alphanumeric mode");var r,i=[];for(r=0;t.length>=r+2;r+=2){var o=45*e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(r));n(o+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(r+1)),11,i)}return t.length>r&&n(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(r)),6,i),new e(e.Mode.ALPHANUMERIC,t.length,i)}},{key:"makeSegments",value:function(t){return""==t?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]}},{key:"makeEci",value:function(t){var r=[];if(0>t)throw new RangeError("ECI assignment value out of range");if(128>t)n(t,8,r);else if(16384>t)n(2,2,r),n(t,14,r);else{if(t>=1e6)throw new RangeError("ECI assignment value out of range");n(6,3,r),n(t,21,r)}return new e(e.Mode.ECI,0,r)}},{key:"isNumeric",value:function(t){return e.NUMERIC_REGEX.test(t)}},{key:"isAlphanumeric",value:function(t){return e.ALPHANUMERIC_REGEX.test(t)}},{key:"getTotalBits",value:function(e,t){var n,r=0,i=w(e);try{for(i.s();!(n=i.n()).done;){var o=n.value,a=o.mode.numCharCountBits(t);if(o.numChars>=1<<a)return 1/0;r+=4+a+o.bitData.length}}catch(s){i.e(s)}finally{i.f()}return r}},{key:"toUtf8ByteArray",value:function(e){e=encodeURI(e);for(var t=[],n=0;e.length>n;n++)"%"!=e.charAt(n)?t.push(e.charCodeAt(n)):(t.push(parseInt(e.substring(n+1,n+3),16)),n+=2);return t}}]),e}();o.NUMERIC_REGEX=/^[0-9]*$/,o.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,o.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",e.QrSegment=o}(E||(E={})),C=E||(E={}),M=C.QrCode||(C.QrCode={}),(R=y(function e(t,n){g(this,e),this.ordinal=void 0,this.formatBits=void 0,this.ordinal=t,this.formatBits=n})).LOW=new R(0,1),R.MEDIUM=new R(1,0),R.QUARTILE=new R(2,3),R.HIGH=new R(3,2),M.Ecc=R,function(e){!function(e){var t=function(){function e(t,n){g(this,e),this.modeBits=void 0,this.numBitsCharCount=void 0,this.modeBits=t,this.numBitsCharCount=n}return y(e,[{key:"numCharCountBits",value:function(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}}]),e}();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||(e.QrSegment={}))}(E||(E={}));var P=E,A=["value","size","level","bgColor","fgColor","includeMargin","marginSize","imageSettings"],S={L:P.QrCode.Ecc.LOW,M:P.QrCode.Ecc.MEDIUM,Q:P.QrCode.Ecc.QUARTILE,H:P.QrCode.Ecc.HIGH};var N=function(){function e(t,n){var r=this;for(var i in g(this,e),this.canvas=void 0,this.pixelRatio="undefined"!=typeof window?window.devicePixelRatio:1,this.path2D=!0,this.SUPPORTS_PATH2D=void 0,this.createImage=function(){return new Image},this.createPath2D=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,t="createPath2D";return r.canvas&&t in r.canvas?r.canvas[t](e):new Path2D(e)},this.canvas=t,n)i in this&&(this[i]=n[i]);this.SUPPORTS_PATH2D=function(){try{r.createPath2D()}catch(e){return!1}return!0}()}return y(e,[{key:"render",value:function(e,t){var n,r,i=this,o=e.value,a=e.size,s=void 0===a?128:a,u=e.level,l=void 0===u?"L":u,h=e.bgColor,c=void 0===h?"#FFFFFF":h,f=e.fgColor,d=void 0===f?"#000000":f,v=e.includeMargin,g=void 0!==v&&v,m=e.marginSize,y=e.imageSettings,p=(function(e,t){if(null==e)return{};var n,r,i=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;o.length>r;r++)0>t.indexOf(n=o[r])&&(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;o.length>r;r++)0>t.indexOf(n=o[r])&&Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}}(e,A),null==y?void 0:y.src),w=this.canvas,E=w.getContext("2d");if(E&&o){var C=P.QrCode.encodeText(o,S[l]).getModules(),M=(n=g,null!=(r=m)?Math.floor(r):n?4:0),R=C.length+2*M,N=function(e,t,n,r){if(null==r)return null;var i=e.length+2*n,o=Math.floor(.1*t),a=i/t,s=(r.width||o)*a,u=(r.height||o)*a,l=null==r.x?e.length/2-s/2:r.x*a,h=null==r.y?e.length/2-u/2:r.y*a,c=null;if(r.excavate){var f=Math.floor(l),d=Math.floor(h);c={x:f,y:d,w:Math.ceil(s+l-f),h:Math.ceil(u+h-d)}}return{x:l,y:h,h:u,w:s,excavation:c}}(C,s,M,y),I=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=null!=N&&null!==e&&e.complete&&0!==e.naturalHeight&&0!==e.naturalWidth;n&&null!=N.excavation&&(C=function(e,t){return e.slice().map(function(e,n){return t.y>n||n>=t.y+t.h?e:e.map(function(e,n){return(t.x>n||n>=t.x+t.w)&&e})})}(C,N.excavation)),t&&t(C);var r=i.pixelRatio;E.clearRect(0,0,w.width,w.height),E.setTransform(1,0,0,1,0,0),w.height=w.width=s*r;var o=s/R*r;if(E.scale(o,o),E.fillStyle=c,E.fillRect(0,0,R,R),E.fillStyle=d,i.SUPPORTS_PATH2D&&i.path2D){var a=i.createPath2D(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=[];return e.forEach(function(e,r){var i=null;e.forEach(function(o,a){if(!o&&null!==i)return n.push("M".concat(i+t," ").concat(r+t,"h").concat(a-i,"v1H").concat(i+t,"z")),void(i=null);if(a!==e.length-1)o&&null===i&&(i=a);else{if(!o)return;n.push(null===i?"M".concat(a+t,",").concat(r+t," h1v1H").concat(a+t,"z"):"M".concat(i+t,",").concat(r+t," h").concat(a+1-i,"v1H").concat(i+t,"z"))}})}),n.join("")}(C,M));E.fill(a)}else C.forEach(function(e,t){e.forEach(function(e,n){e&&E.fillRect(n+M,t+M,1,1)})});var u=(null==e?void 0:e.path)||e;n&&E.drawImage(u,N.x+M,N.y+M,N.w,N.h),"draw"in E&&E.draw()};if(p){var k=this.createImage(w);k.onload=function(){I(k)},k.onerror=function(e){I(),console.warn(e)},k.src=p}else I()}}}]),e}();function I(e){return/^(-)?\d+(\.\d+)?$/.test(e)}function k(e){return function(e){return null!=e}(e)?I(e=String(e))?`${e}px`:e:null}const b="undefined"!=typeof window;let _=class{constructor(){this.currentSrc=null,this.naturalHeight=0,this.naturalWidth=0,this.width=0,this.height=0,this.tagName="IMG",this.path="",this.crossOrigin="",this.referrerPolicy="",this.onload=()=>{},this.onerror=()=>{},this.complete=!1}set src(e){if(console.log("src",e),!e)return this.onerror();e=e.replace(/^@\//,"/"),this.currentSrc=e,uni.getImageInfo({src:e,success:e=>{this.complete=!0,this.path=e.path,this.naturalWidth=this.width=e.width,this.naturalHeight=this.height=e.height,this.onload()},fail:()=>{this.onerror()}})}get src(){return this.currentSrc}};function T(e){return e&&e.createImage?e.createImage():this&&"canvas"==this.tagName&&!("toBlob"in this)||e&&!("toBlob"in e)?new _:b?new window.Image:new _}function O(e,t=0){if(I(e))return Number(e);if("string"==typeof e){const n=/^-?([0-9]+)?([.]{1}[0-9]+){0,1}(em|rpx|px|%)$/g.exec(e);if(!e||!n)return 0;const r=n[3],i=parseFloat(e);if("rpx"===r)return uni.upx2px(i);if("px"===r)return 1*i;if("%"==r)return i/100*t}return 0}const z=f(e({name:"l-qrcode",props:d,emits:["success"],setup(e,{emit:a}){const s=o(),u=`l-qrcode${s.uid}`,l=t(()=>`width: ${k(e.size)}; height: ${k(e.size)};`);let h=null,c=null;const f=t(()=>{const{value:t,icon:n,size:r,color:i,bgColor:o,bordered:a,iconSize:s,errorLevel:u,marginSize:l}=e,h={src:n,x:void 0,y:void 0,height:O(s),width:O(s),excavate:!0};return{value:t,size:O(r),level:u,bgColor:o,fgColor:i,imageSettings:n?h:void 0,includeMargin:a,marginSize:l??0}}),d=function(e,t=300){let n=null;return function(...r){n&&clearTimeout(n),n=setTimeout(()=>{e.apply(this,r)},t)}}(e=>{if(!c)return;const t=Object.assign({canvasId:u,canvas:null},e);"toTempFilePath"in c?c.toTempFilePath(t):uni.canvasToTempFilePath(t,s)}),g=()=>{e.useCanvasToTempFilePath&&d({success(e){a("success",e.tempFilePath)}})},m=n(e,()=>{h&&(h.render(f.value),g())});return r(()=>{v(u,{context:s}).then(e=>{c=e,h=new N(e,{path2D:!1,pixelRatio:1,createImage:T}),h.render(f.value),g()})}),i(()=>{m&&m()}),{canvasId:u,styles:l,props:e,canvasToTempFilePath:d}}}),[["render",function(e,t,n,r,i,o){const f=h,d=c;return a(),s(d,{class:"l-qrcode",style:l([e.styles])},{default:u(()=>[e.use2d?(a(),s(f,{key:0,style:l(e.styles),type:"2d","canvas-id":e.canvasId,id:e.canvasId},null,8,["style","canvas-id","id"])):(a(),s(f,{key:1,style:l(e.styles),"canvas-id":e.canvasId,id:e.canvasId},null,8,["style","canvas-id","id"]))]),_:1},8,["style"])}],["__scopeId","data-v-07ac15a1"]]);export{z as _};
|