UNPKG

@imgly/plugin-qr-code-web

Version:

QR code generation plugin for the CE.SDK editor

40 lines (38 loc) 29 kB
var Pe=class{constructor(e,i){this.engine=e,this.key=i}hasData(e){return this.engine.block.isValid(e)&&this.engine.block.hasMetadata(e,this.key)}get(e){if(this.hasData(e))return JSON.parse(this.engine.block.getMetadata(e,this.key))}set(e,i){this.engine.block.setMetadata(e,this.key,JSON.stringify(i))}clear(e){this.engine.block.hasMetadata(e,this.key)&&this.engine.block.removeMetadata(e,this.key)}},de=Pe,Me=typeof global=="object"&&global&&global.Object===Object&&global,ge=Me,ke=typeof self=="object"&&self&&self.Object===Object&&self,_e=ge||ke||Function("return this")(),A=_e,Fe=A.Symbol,I=Fe,be=Object.prototype,Ne=be.hasOwnProperty,Oe=be.toString,O=I?I.toStringTag:void 0;function je(e){var i=Ne.call(e,O),o=e[O];try{e[O]=void 0;var s=!0}catch{}var c=Oe.call(e);return s&&(i?e[O]=o:delete e[O]),c}var De=je,Be=Object.prototype,xe=Be.toString;function Te(e){return xe.call(e)}var ze=Te,Ue="[object Null]",Le="[object Undefined]",ee=I?I.toStringTag:void 0;function $e(e){return e==null?e===void 0?Le:Ue:ee&&ee in Object(e)?De(e):ze(e)}var x=$e;function Ve(e){return e!=null&&typeof e=="object"}var X=Ve,Nn=Array.isArray;function He(e){var i=typeof e;return e!=null&&(i=="object"||i=="function")}var ye=He,qe="[object AsyncFunction]",Ge="[object Function]",Ye="[object GeneratorFunction]",Ke="[object Proxy]";function Xe(e){if(!ye(e))return!1;var i=x(e);return i==Ge||i==Ye||i==qe||i==Ke}var Ze=Xe,We=A["__core-js_shared__"],$=We,te=function(){var e=/[^.]+$/.exec($&&$.keys&&$.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Je(e){return!!te&&te in e}var Qe=Je,et=Function.prototype,tt=et.toString;function rt(e){if(e!=null){try{return tt.call(e)}catch{}try{return e+""}catch{}}return""}var R=rt,nt=/[\\^$.*+?()[\]{}|]/g,it=/^\[object .+?Constructor\]$/,at=Function.prototype,ot=Object.prototype,lt=at.toString,st=ot.hasOwnProperty,ct=RegExp("^"+lt.call(st).replace(nt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ut(e){if(!ye(e)||Qe(e))return!1;var i=Ze(e)?ct:it;return i.test(R(e))}var ft=ut;function pt(e,i){return e?.[i]}var ht=pt;function dt(e,i){var o=ht(e,i);return ft(o)?o:void 0}var P=dt,gt=P(A,"WeakMap"),H=gt;function bt(e,i){return e===i||e!==e&&i!==i}var yt=bt,vt=9007199254740991;function mt(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=vt}var Et=mt;var On=Object.prototype;var At="[object Arguments]";function wt(e){return X(e)&&x(e)==At}var re=wt,ve=Object.prototype,Rt=ve.hasOwnProperty,St=ve.propertyIsEnumerable,jn=re(function(){return arguments}())?re:function(e){return X(e)&&Rt.call(e,"callee")&&!St.call(e,"callee")};var me=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ne=me&&typeof module=="object"&&module&&!module.nodeType&&module,Ct=ne&&ne.exports===me,ie=Ct?A.Buffer:void 0,Dn=ie?ie.isBuffer:void 0;var It="[object Arguments]",Pt="[object Array]",Mt="[object Boolean]",kt="[object Date]",_t="[object Error]",Ft="[object Function]",Nt="[object Map]",Ot="[object Number]",jt="[object Object]",Dt="[object RegExp]",Bt="[object Set]",xt="[object String]",Tt="[object WeakMap]",zt="[object ArrayBuffer]",Ut="[object DataView]",Lt="[object Float32Array]",$t="[object Float64Array]",Vt="[object Int8Array]",Ht="[object Int16Array]",qt="[object Int32Array]",Gt="[object Uint8Array]",Yt="[object Uint8ClampedArray]",Kt="[object Uint16Array]",Xt="[object Uint32Array]",g={};g[Lt]=g[$t]=g[Vt]=g[Ht]=g[qt]=g[Gt]=g[Yt]=g[Kt]=g[Xt]=!0;g[It]=g[Pt]=g[zt]=g[Mt]=g[Ut]=g[kt]=g[_t]=g[Ft]=g[Nt]=g[Ot]=g[jt]=g[Dt]=g[Bt]=g[xt]=g[Tt]=!1;function Zt(e){return X(e)&&Et(e.length)&&!!g[x(e)]}var Wt=Zt;function Jt(e){return function(i){return e(i)}}var Qt=Jt,Ee=typeof exports=="object"&&exports&&!exports.nodeType&&exports,j=Ee&&typeof module=="object"&&module&&!module.nodeType&&module,er=j&&j.exports===Ee,V=er&&ge.process,tr=function(){try{var e=j&&j.require&&j.require("util").types;return e||V&&V.binding&&V.binding("util")}catch{}}(),ae=tr,oe=ae&&ae.isTypedArray,Bn=oe?Qt(oe):Wt;var rr=Object.prototype,xn=rr.hasOwnProperty;function nr(e,i){return function(o){return e(i(o))}}var ir=nr,Tn=ir(Object.keys,Object);var ar=Object.prototype,zn=ar.hasOwnProperty;var or=P(Object,"create"),D=or;function lr(){this.__data__=D?D(null):{},this.size=0}var sr=lr;function cr(e){var i=this.has(e)&&delete this.__data__[e];return this.size-=i?1:0,i}var ur=cr,fr="__lodash_hash_undefined__",pr=Object.prototype,hr=pr.hasOwnProperty;function dr(e){var i=this.__data__;if(D){var o=i[e];return o===fr?void 0:o}return hr.call(i,e)?i[e]:void 0}var gr=dr,br=Object.prototype,yr=br.hasOwnProperty;function vr(e){var i=this.__data__;return D?i[e]!==void 0:yr.call(i,e)}var mr=vr,Er="__lodash_hash_undefined__";function Ar(e,i){var o=this.__data__;return this.size+=this.has(e)?0:1,o[e]=D&&i===void 0?Er:i,this}var wr=Ar;function M(e){var i=-1,o=e==null?0:e.length;for(this.clear();++i<o;){var s=e[i];this.set(s[0],s[1])}}M.prototype.clear=sr;M.prototype.delete=ur;M.prototype.get=gr;M.prototype.has=mr;M.prototype.set=wr;var le=M;function Rr(){this.__data__=[],this.size=0}var Sr=Rr;function Cr(e,i){for(var o=e.length;o--;)if(yt(e[o][0],i))return o;return-1}var z=Cr,Ir=Array.prototype,Pr=Ir.splice;function Mr(e){var i=this.__data__,o=z(i,e);if(o<0)return!1;var s=i.length-1;return o==s?i.pop():Pr.call(i,o,1),--this.size,!0}var kr=Mr;function _r(e){var i=this.__data__,o=z(i,e);return o<0?void 0:i[o][1]}var Fr=_r;function Nr(e){return z(this.__data__,e)>-1}var Or=Nr;function jr(e,i){var o=this.__data__,s=z(o,e);return s<0?(++this.size,o.push([e,i])):o[s][1]=i,this}var Dr=jr;function k(e){var i=-1,o=e==null?0:e.length;for(this.clear();++i<o;){var s=e[i];this.set(s[0],s[1])}}k.prototype.clear=Sr;k.prototype.delete=kr;k.prototype.get=Fr;k.prototype.has=Or;k.prototype.set=Dr;var U=k,Br=P(A,"Map"),B=Br;function xr(){this.size=0,this.__data__={hash:new le,map:new(B||U),string:new le}}var Tr=xr;function zr(e){var i=typeof e;return i=="string"||i=="number"||i=="symbol"||i=="boolean"?e!=="__proto__":e===null}var Ur=zr;function Lr(e,i){var o=e.__data__;return Ur(i)?o[typeof i=="string"?"string":"hash"]:o.map}var L=Lr;function $r(e){var i=L(this,e).delete(e);return this.size-=i?1:0,i}var Vr=$r;function Hr(e){return L(this,e).get(e)}var qr=Hr;function Gr(e){return L(this,e).has(e)}var Yr=Gr;function Kr(e,i){var o=L(this,e),s=o.size;return o.set(e,i),this.size+=o.size==s?0:1,this}var Xr=Kr;function _(e){var i=-1,o=e==null?0:e.length;for(this.clear();++i<o;){var s=e[i];this.set(s[0],s[1])}}_.prototype.clear=Tr;_.prototype.delete=Vr;_.prototype.get=qr;_.prototype.has=Yr;_.prototype.set=Xr;var Ae=_;function Zr(){this.__data__=new U,this.size=0}var Wr=Zr;function Jr(e){var i=this.__data__,o=i.delete(e);return this.size=i.size,o}var Qr=Jr;function en(e){return this.__data__.get(e)}var tn=en;function rn(e){return this.__data__.has(e)}var nn=rn,an=200;function on(e,i){var o=this.__data__;if(o instanceof U){var s=o.__data__;if(!B||s.length<an-1)return s.push([e,i]),this.size=++o.size,this;o=this.__data__=new Ae(s)}return o.set(e,i),this.size=o.size,this}var ln=on;function T(e){var i=this.__data__=new U(e);this.size=i.size}T.prototype.clear=Wr;T.prototype.delete=Qr;T.prototype.get=tn;T.prototype.has=nn;T.prototype.set=ln;var sn=Object.prototype,Un=sn.propertyIsEnumerable;var cn=P(A,"DataView"),q=cn,un=P(A,"Promise"),G=un,fn=P(A,"Set"),Y=fn,se="[object Map]",pn="[object Object]",ce="[object Promise]",ue="[object Set]",fe="[object WeakMap]",pe="[object DataView]",hn=R(q),dn=R(B),gn=R(G),bn=R(Y),yn=R(H),C=x;(q&&C(new q(new ArrayBuffer(1)))!=pe||B&&C(new B)!=se||G&&C(G.resolve())!=ce||Y&&C(new Y)!=ue||H&&C(new H)!=fe)&&(C=function(e){var i=x(e),o=i==pn?e.constructor:void 0,s=o?R(o):"";if(s)switch(s){case hn:return pe;case dn:return se;case gn:return ce;case bn:return ue;case yn:return fe}return i});var Ln=A.Uint8Array;var vn="__lodash_hash_undefined__";function mn(e){return this.__data__.set(e,vn),this}var En=mn;function An(e){return this.__data__.has(e)}var wn=An;function K(e){var i=-1,o=e==null?0:e.length;for(this.__data__=new Ae;++i<o;)this.add(e[i])}K.prototype.add=K.prototype.push=En;K.prototype.has=wn;var he=I?I.prototype:void 0,$n=he?he.valueOf:void 0;var Rn=Object.prototype,Vn=Rn.hasOwnProperty;var Sn=Object.prototype,Hn=Sn.hasOwnProperty;var qn=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),Cn=new RegExp(/[A-Fa-f0-9]{1}/,"g"),In=new RegExp(/[A-Fa-f0-9]{2}/,"g"),Z=(e,i=!1)=>{let{r:o,g:s,b:c,a:f}=e,h=Math.round(255*o),t=Math.round(255*s),n=Math.round(255*c),r=Math.round(255*f),a=l=>l.toString(16).padStart(2,"0");return`#${a(h)}${a(t)}${a(n)}${i?a(r):""}`},we=e=>{let i=(o,s,c,f,h)=>({r:parseInt(o,16)/h,g:parseInt(s,16)/h,b:parseInt(c,16)/h,a:f===void 0?1:parseInt(f,16)/h});if(e.startsWith("#")){if(e.length===4||e.length===5){let o=e.match(Cn);if(o){let[s,c,f,h]=o;return i(s,c,f,h,15)}}if(e.length===7||e.length===8){let o=e.match(In);if(o){let[s,c,f,h]=o;return i(s,c,f,h,255)}}}throw new Error('Invalid hex string! Allowed RGB formats are "#FFF" and "#FFFFFF". Allowed RGBA formats are "#FFFF" and "#FFFFFFFF')};var F;(f=>{class e{constructor(t,n,r,a){this.version=t;this.errorCorrectionLevel=n;this.modules=[];this.isFunction=[];if(t<e.MIN_VERSION||t>e.MAX_VERSION)throw new RangeError("Version value out of range");if(a<-1||a>7)throw new RangeError("Mask value out of range");this.size=t*4+17;let l=[];for(let u=0;u<this.size;u++)l.push(!1);for(let u=0;u<this.size;u++)this.modules.push(l.slice()),this.isFunction.push(l.slice());this.drawFunctionPatterns();let p=this.addEccAndInterleave(r);if(this.drawCodewords(p),a==-1){let u=1e9;for(let b=0;b<8;b++){this.applyMask(b),this.drawFormatBits(b);let d=this.getPenaltyScore();d<u&&(a=b,u=d),this.applyMask(b)}}s(0<=a&&a<=7),this.mask=a,this.applyMask(a),this.drawFormatBits(a),this.isFunction=[]}static encodeText(t,n){let r=f.QrSegment.makeSegments(t);return e.encodeSegments(r,n)}static encodeBinary(t,n){let r=f.QrSegment.makeBytes(t);return e.encodeSegments([r],n)}static encodeSegments(t,n,r=1,a=40,l=-1,p=!0){if(!(e.MIN_VERSION<=r&&r<=a&&a<=e.MAX_VERSION)||l<-1||l>7)throw new RangeError("Invalid value");let u,b;for(u=r;;u++){let y=e.getNumDataCodewords(u,n)*8,E=c.getTotalBits(t,u);if(E<=y){b=E;break}if(u>=a)throw new RangeError("Data too long")}for(let y of[e.Ecc.MEDIUM,e.Ecc.QUARTILE,e.Ecc.HIGH])p&&b<=e.getNumDataCodewords(u,y)*8&&(n=y);let d=[];for(let y of t){i(y.mode.modeBits,4,d),i(y.numChars,y.mode.numCharCountBits(u),d);for(let E of y.getData())d.push(E)}s(d.length==b);let N=e.getNumDataCodewords(u,n)*8;s(d.length<=N),i(0,Math.min(4,N-d.length),d),i(0,(8-d.length%8)%8,d),s(d.length%8==0);for(let y=236;d.length<N;y^=253)i(y,8,d);let w=[];for(;w.length*8<d.length;)w.push(0);return d.forEach((y,E)=>w[E>>>3]|=y<<7-(E&7)),new e(u,n,w,l)}getModule(t,n){return 0<=t&&t<this.size&&0<=n&&n<this.size&&this.modules[n][t]}getModules(){return this.modules}drawFunctionPatterns(){for(let r=0;r<this.size;r++)this.setFunctionModule(6,r,r%2==0),this.setFunctionModule(r,6,r%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let t=this.getAlignmentPatternPositions(),n=t.length;for(let r=0;r<n;r++)for(let a=0;a<n;a++)r==0&&a==0||r==0&&a==n-1||r==n-1&&a==0||this.drawAlignmentPattern(t[r],t[a]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(t){let n=this.errorCorrectionLevel.formatBits<<3|t,r=n;for(let l=0;l<10;l++)r=r<<1^(r>>>9)*1335;let a=(n<<10|r)^21522;s(a>>>15==0);for(let l=0;l<=5;l++)this.setFunctionModule(8,l,o(a,l));this.setFunctionModule(8,7,o(a,6)),this.setFunctionModule(8,8,o(a,7)),this.setFunctionModule(7,8,o(a,8));for(let l=9;l<15;l++)this.setFunctionModule(14-l,8,o(a,l));for(let l=0;l<8;l++)this.setFunctionModule(this.size-1-l,8,o(a,l));for(let l=8;l<15;l++)this.setFunctionModule(8,this.size-15+l,o(a,l));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let t=this.version;for(let r=0;r<12;r++)t=t<<1^(t>>>11)*7973;let n=this.version<<12|t;s(n>>>18==0);for(let r=0;r<18;r++){let a=o(n,r),l=this.size-11+r%3,p=Math.floor(r/3);this.setFunctionModule(l,p,a),this.setFunctionModule(p,l,a)}}drawFinderPattern(t,n){for(let r=-4;r<=4;r++)for(let a=-4;a<=4;a++){let l=Math.max(Math.abs(a),Math.abs(r)),p=t+a,u=n+r;0<=p&&p<this.size&&0<=u&&u<this.size&&this.setFunctionModule(p,u,l!=2&&l!=4)}}drawAlignmentPattern(t,n){for(let r=-2;r<=2;r++)for(let a=-2;a<=2;a++)this.setFunctionModule(t+a,n+r,Math.max(Math.abs(a),Math.abs(r))!=1)}setFunctionModule(t,n,r){this.modules[n][t]=r,this.isFunction[n][t]=!0}addEccAndInterleave(t){let n=this.version,r=this.errorCorrectionLevel;if(t.length!=e.getNumDataCodewords(n,r))throw new RangeError("Invalid argument");let a=e.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][n],l=e.ECC_CODEWORDS_PER_BLOCK[r.ordinal][n],p=Math.floor(e.getNumRawDataModules(n)/8),u=a-p%a,b=Math.floor(p/a),d=[],N=e.reedSolomonComputeDivisor(l);for(let y=0,E=0;y<a;y++){let S=t.slice(E,E+b-l+(y<u?0:1));E+=S.length;let Ie=e.reedSolomonComputeRemainder(S,N);y<u&&S.push(0),d.push(S.concat(Ie))}let w=[];for(let y=0;y<d[0].length;y++)d.forEach((E,S)=>{(y!=b-l||S>=u)&&w.push(E[y])});return s(w.length==p),w}drawCodewords(t){if(t.length!=Math.floor(e.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let n=0;for(let r=this.size-1;r>=1;r-=2){r==6&&(r=5);for(let a=0;a<this.size;a++)for(let l=0;l<2;l++){let p=r-l,b=(r+1&2)==0?this.size-1-a:a;!this.isFunction[b][p]&&n<t.length*8&&(this.modules[b][p]=o(t[n>>>3],7-(n&7)),n++)}}s(n==t.length*8)}applyMask(t){if(t<0||t>7)throw new RangeError("Mask value out of range");for(let n=0;n<this.size;n++)for(let r=0;r<this.size;r++){let a;switch(t){case 0:a=(r+n)%2==0;break;case 1:a=n%2==0;break;case 2:a=r%3==0;break;case 3:a=(r+n)%3==0;break;case 4:a=(Math.floor(r/3)+Math.floor(n/2))%2==0;break;case 5:a=r*n%2+r*n%3==0;break;case 6:a=(r*n%2+r*n%3)%2==0;break;case 7:a=((r+n)%2+r*n%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[n][r]&&a&&(this.modules[n][r]=!this.modules[n][r])}}getPenaltyScore(){let t=0;for(let l=0;l<this.size;l++){let p=!1,u=0,b=[0,0,0,0,0,0,0];for(let d=0;d<this.size;d++)this.modules[l][d]==p?(u++,u==5?t+=e.PENALTY_N1:u>5&&t++):(this.finderPenaltyAddHistory(u,b),p||(t+=this.finderPenaltyCountPatterns(b)*e.PENALTY_N3),p=this.modules[l][d],u=1);t+=this.finderPenaltyTerminateAndCount(p,u,b)*e.PENALTY_N3}for(let l=0;l<this.size;l++){let p=!1,u=0,b=[0,0,0,0,0,0,0];for(let d=0;d<this.size;d++)this.modules[d][l]==p?(u++,u==5?t+=e.PENALTY_N1:u>5&&t++):(this.finderPenaltyAddHistory(u,b),p||(t+=this.finderPenaltyCountPatterns(b)*e.PENALTY_N3),p=this.modules[d][l],u=1);t+=this.finderPenaltyTerminateAndCount(p,u,b)*e.PENALTY_N3}for(let l=0;l<this.size-1;l++)for(let p=0;p<this.size-1;p++){let u=this.modules[l][p];u==this.modules[l][p+1]&&u==this.modules[l+1][p]&&u==this.modules[l+1][p+1]&&(t+=e.PENALTY_N2)}let n=0;for(let l of this.modules)n=l.reduce((p,u)=>p+(u?1:0),n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return s(0<=a&&a<=9),t+=a*e.PENALTY_N4,s(0<=t&&t<=2568888),t}getAlignmentPatternPositions(){if(this.version==1)return[];{let t=Math.floor(this.version/7)+2,n=this.version==32?26:Math.ceil((this.version*4+4)/(t*2-2))*2,r=[6];for(let a=this.size-7;r.length<t;a-=n)r.splice(1,0,a);return r}}static getNumRawDataModules(t){if(t<e.MIN_VERSION||t>e.MAX_VERSION)throw new RangeError("Version number out of range");let n=(16*t+128)*t+64;if(t>=2){let r=Math.floor(t/7)+2;n-=(25*r-10)*r-55,t>=7&&(n-=36)}return s(208<=n&&n<=29648),n}static getNumDataCodewords(t,n){return Math.floor(e.getNumRawDataModules(t)/8)-e.ECC_CODEWORDS_PER_BLOCK[n.ordinal][t]*e.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][t]}static reedSolomonComputeDivisor(t){if(t<1||t>255)throw new RangeError("Degree out of range");let n=[];for(let a=0;a<t-1;a++)n.push(0);n.push(1);let r=1;for(let a=0;a<t;a++){for(let l=0;l<n.length;l++)n[l]=e.reedSolomonMultiply(n[l],r),l+1<n.length&&(n[l]^=n[l+1]);r=e.reedSolomonMultiply(r,2)}return n}static reedSolomonComputeRemainder(t,n){let r=n.map(a=>0);for(let a of t){let l=a^r.shift();r.push(0),n.forEach((p,u)=>r[u]^=e.reedSolomonMultiply(p,l))}return r}static reedSolomonMultiply(t,n){if(t>>>8||n>>>8)throw new RangeError("Byte out of range");let r=0;for(let a=7;a>=0;a--)r=r<<1^(r>>>7)*285,r^=(n>>>a&1)*t;return s(r>>>8==0),r}finderPenaltyCountPatterns(t){let n=t[1];s(n<=this.size*3);let r=n>0&&t[2]==n&&t[3]==n*3&&t[4]==n&&t[5]==n;return(r&&t[0]>=n*4&&t[6]>=n?1:0)+(r&&t[6]>=n*4&&t[0]>=n?1:0)}finderPenaltyTerminateAndCount(t,n,r){return t&&(this.finderPenaltyAddHistory(n,r),n=0),n+=this.size,this.finderPenaltyAddHistory(n,r),this.finderPenaltyCountPatterns(r)}finderPenaltyAddHistory(t,n){n[0]==0&&(t+=this.size),n.pop(),n.unshift(t)}static{this.MIN_VERSION=1}static{this.MAX_VERSION=40}static{this.PENALTY_N1=3}static{this.PENALTY_N2=3}static{this.PENALTY_N3=40}static{this.PENALTY_N4=10}static{this.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]]}static{this.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]]}}f.QrCode=e;function i(h,t,n){if(t<0||t>31||h>>>t)throw new RangeError("Value out of range");for(let r=t-1;r>=0;r--)n.push(h>>>r&1)}function o(h,t){return(h>>>t&1)!=0}function s(h){if(!h)throw new Error("Assertion error")}class c{constructor(t,n,r){this.mode=t;this.numChars=n;this.bitData=r;if(n<0)throw new RangeError("Invalid argument");this.bitData=r.slice()}static makeBytes(t){let n=[];for(let r of t)i(r,8,n);return new c(c.Mode.BYTE,t.length,n)}static makeNumeric(t){if(!c.isNumeric(t))throw new RangeError("String contains non-numeric characters");let n=[];for(let r=0;r<t.length;){let a=Math.min(t.length-r,3);i(parseInt(t.substring(r,r+a),10),a*3+1,n),r+=a}return new c(c.Mode.NUMERIC,t.length,n)}static makeAlphanumeric(t){if(!c.isAlphanumeric(t))throw new RangeError("String contains unencodable characters in alphanumeric mode");let n=[],r;for(r=0;r+2<=t.length;r+=2){let a=c.ALPHANUMERIC_CHARSET.indexOf(t.charAt(r))*45;a+=c.ALPHANUMERIC_CHARSET.indexOf(t.charAt(r+1)),i(a,11,n)}return r<t.length&&i(c.ALPHANUMERIC_CHARSET.indexOf(t.charAt(r)),6,n),new c(c.Mode.ALPHANUMERIC,t.length,n)}static makeSegments(t){return t==""?[]:c.isNumeric(t)?[c.makeNumeric(t)]:c.isAlphanumeric(t)?[c.makeAlphanumeric(t)]:[c.makeBytes(c.toUtf8ByteArray(t))]}static makeEci(t){let n=[];if(t<0)throw new RangeError("ECI assignment value out of range");if(t<128)i(t,8,n);else if(t<16384)i(2,2,n),i(t,14,n);else if(t<1e6)i(6,3,n),i(t,21,n);else throw new RangeError("ECI assignment value out of range");return new c(c.Mode.ECI,0,n)}static isNumeric(t){return c.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return c.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(t,n){let r=0;for(let a of t){let l=a.mode.numCharCountBits(n);if(a.numChars>=1<<l)return 1/0;r+=4+l+a.bitData.length}return r}static toUtf8ByteArray(t){t=encodeURI(t);let n=[];for(let r=0;r<t.length;r++)t.charAt(r)!="%"?n.push(t.charCodeAt(r)):(n.push(parseInt(t.substring(r+1,r+3),16)),r+=2);return n}static{this.NUMERIC_REGEX=/^[0-9]*$/}static{this.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/}static{this.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"}}f.QrSegment=c})(F||={});(i=>{let e;(s=>{class o{constructor(f,h){this.ordinal=f;this.formatBits=h}static{this.LOW=new o(0,1)}static{this.MEDIUM=new o(1,0)}static{this.QUARTILE=new o(2,3)}static{this.HIGH=new o(3,2)}}s.Ecc=o})(e=i.QrCode||={})})(F||={});(i=>{let e;(s=>{class o{constructor(f,h){this.modeBits=f;this.numBitsCharCount=h}static{this.NUMERIC=new o(1,[10,12,14])}static{this.ALPHANUMERIC=new o(2,[9,11,13])}static{this.BYTE=new o(4,[8,16,16])}static{this.KANJI=new o(8,[8,10,12])}static{this.ECI=new o(7,[0,0,0])}numCharCountBits(f){return this.numBitsCharCount[Math.floor((f+7)/17)]}}s.Mode=o})(e=i.QrSegment||={})})(F||={});var W=F;function J(e,i){let o=W.QrCode.encodeText(e,W.QrCode.Ecc.HIGH),s=Pn(o);return{svg:Mn(s,i,o.size),path:s,size:o.size}}function Pn(e){let i=[];for(let o=0;o<e.size;o++)for(let s=0;s<e.size;s++)e.getModule(s,o)&&i.push(`M${s},${o}h1v1h-1z`);return i.join(" ")}function Mn(e,i,o){return`<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 ${o} ${o}" stroke="none"> <path d="${e}" fill="${i}"/> </svg> `}var Q="@imgly/plugin-qr-code-web",m="//ly.img.panel/generate-qr",v="//ly.img.panel/update-qr",Se=(e={})=>{let{createdBlockType:i="shape",addCheckboxForCreatedBlockType:o=!1}=e||{};return{initialize({cesdk:s}){if(s==null)return;let c=new de(s.engine,Q);s.ui.addIconSet("@imgly/plugin/qr",` <svg> <symbol fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="@imgly/plugin/qr" > <path fill-rule="evenodd" clip-rule="evenodd" d="M3 3H11V11H3V3ZM5 5H9V9H5V5Z" fill="currentColor"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M3 13H11V21H3V13ZM5 15H9V19H5V15Z" fill="currentColor"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M13 3V11H21V3H13ZM19 5H15V9H19V5Z" fill="currentColor"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M15 13H13V15H15V17H13V21H17V19H19V21H21V19H19V17H21V13H17V15H15V13ZM17 17H15V19H17V17ZM17 17V15H19V17H17Z" fill="currentColor"/> </symbol> </svg> `),s.setTranslations({en:{"ly.img.generate-qr.dock.label":"QR Code",[`panel.${m}`]:"Generate QR Code",[`panel.${m}.description`]:"Enter a URL to automatically generate a QR code for you to embed it in your design.",[`panel.${m}.submit`]:"Generate QR Code",[`panel.${m}.url`]:"URL",[`panel.${m}.foregroundColor`]:"Foreground Color",[`panel.${m}.error`]:"Failed to create QR code block.",[`panel.${v}`]:"Update QR Code",[`panel.${v}.description`]:"Update the URL to automatically refresh the QR code within your design.",[`panel.${v}.asShape`]:"As Shape?",[`panel.${v}.onlyOneBlock`]:"Please select only one block to update the QR code.",[`panel.${v}.noMetadata`]:"Invalid QR code block selected. Missing metadata.",[`panel.${v}.invalidStateShape`]:"Invalid state with no shape found.",[`panel.${v}.invalidStateFill`]:"Invalid state with no fill found.",[`panel.${v}.url`]:"URL",[`panel.${v}.foregroundColor`]:"Foreground Color","ly.img.generate-qr.canvasMenu.edit":"Edit"}}),["ly.img.replace","ly.img.crop","ly.img.fill","ly.img.adjustment","ly.img.shape.options"].forEach(f=>{s.feature.enable(f,({isPreviousEnable:h,engine:t})=>t.block.findAllSelected().every(r=>c.hasData(r)?c.get(r)?.type==="fill":!1)?!1:h())}),s.ui.registerComponent("ly.img.generate-qr.dock",({builder:f})=>{let h=s.ui.isPanelOpen(m);f.Button("ly.img.generate-qr.dock",{label:"ly.img.generate-qr.dock.label",icon:"@imgly/plugin/qr",isSelected:h,onClick:()=>{h?s.ui.closePanel(m):s.ui.openPanel(m)}})}),s.ui.registerComponent("ly.img.update-qr.canvasMenu",({builder:f,engine:h})=>{let t=h.block.findAllSelected();if(t.length!==1)return;let n=t[0];h.block.isAllowedByScope(n,"fill/change")&&c.hasData(n)&&f.Button("ly.img.update-qr.dock",{label:"ly.img.generate-qr.canvasMenu.edit",icon:"@imgly/plugin/qr",onClick:()=>{s.ui.openPanel(v)}})}),s.ui.setCanvasMenuOrder(["ly.img.update-qr.canvasMenu",...s.ui.getCanvasMenuOrder()]),s.ui.registerPanel(m,({builder:f,engine:h,state:t})=>{let n=t("url",""),r=t("color",{r:0,g:0,b:0,a:1}),a=t("asShape",i==="shape");f.Section("ly.img.generate-qr.text.section",{children:()=>{f.Text("ly.img.generate-qr.text",{content:`panel.${m}.description`})}}),f.Section("ly.img.generate-qr.inputs.section",{children:()=>{f.TextInput("ly.img.generate-qr.url",{inputLabel:`panel.${m}.url`,...n}),f.ColorInput("ly.img.generate-qr.foregroundColor",{label:`panel.${m}.foregroundColor`,inputLabel:`panel.${m}.foregroundColor`,...r})}}),f.Section("ly.img.generate-qr.button.section",{children:()=>{f.Button("ly.img.generate-qr.generate",{label:`panel.${m}.submit`,isDisabled:n.value==="",color:"accent",onClick:async()=>{await _n(s,h,n.value,r.value,c,a.value)!=null&&s.ui.closePanel(m)}}),o&&f.Checkbox("ly.img.generate-qr.asShape",{inputLabel:`panel.${v}.asShape`,...a})}})}),s.engine.block.onSelectionChanged(()=>{let f=s.engine.block.findAllSelected();if(f.length!==1){s.ui.isPanelOpen(v)&&s.ui.closePanel(v);return}let h=f[0];c.hasData(h)||s.ui.isPanelOpen(v)&&s.ui.closePanel(v)}),s.ui.registerPanel(v,({builder:f,engine:h})=>{let t=h.block.findAllSelected();if(t.length!==1){f.Section("ly.img.update-qr.only-one-block.section",{children:()=>{f.Text("ly.img.update-qr.only-one-block",{content:`panel.${v}.onlyOneBlock`})}});return}let n=t[0];if(!c.hasData(n)){f.Section("ly.img.update-qr.no-metadata.section",{children:()=>{f.Text("ly.img.update-qr.no-metadata",{content:`panel.${v}.noMetadata`})}});return}let{url:r,color:a,type:l}=c.get(n);f.Section("ly.img.update-qr.section",{children:()=>{f.Text("ly.img.update-qr.text",{content:`panel.${v}.description`}),f.TextInput("ly.img.update-qr.url",{inputLabel:`panel.${v}.url`,value:r,setValue:p=>{c.set(n,{url:p,color:a,type:l}),Re(s,h,n,p,a,l)}}),l==="fill"&&f.ColorInput("ly.img.update-qr.foregroundColor",{inputLabel:`panel.${v}.foregroundColor`,inputLabelPosition:"top",value:we(a),setValue:p=>{let u=kn(h,p);c.set(n,{url:r,color:u,type:l}),Re(s,h,n,r,u,l)}})}})})}}};function kn(e,i){let o=typeof i=="string",s;if(o)s=i;else{let c=e.editor.convertColorToColorSpace(i,"sRGB");s=Z(c)}return s}async function _n(e,i,o,s,c,f){let h=i.editor.convertColorToColorSpace(s,"sRGB"),t=Z(h),{path:n,svg:r,size:a}=J(o,t),l;if(f){if(l=await i.asset.defaultApplyAsset({id:"qr-code",meta:{kind:"shape",vectorPath:n,height:a,width:a,shapeType:"//ly.img.ubq/shape/vector_path"},payload:{}}),l!=null){if(i.block.supportsFill(l)){let p=i.block.getFill(l);i.block.getType(p)==="//ly.img.ubq/fill/color"&&i.block.setColor(p,"fill/color/value",h)}Ce(i,l)}}else{let p=`data:text/plain;base64,${btoa(r)}`;l=await i.asset.defaultApplyAsset({id:"qr-code",meta:{fillType:"//ly.img.ubq/fill/image",width:a,height:a},payload:{sourceSet:[{uri:p,width:a,height:a}]}})}return l==null?e.ui.showNotification({type:"error",message:`panel.${m}.error`}):c.set(l,{url:o,color:t,type:f?"shape":"fill"}),l}function Re(e,i,o,s,c,f){let{path:h,svg:t,size:n}=J(s,c);if(f==="shape"){if(!i.block.supportsShape(o)){e.ui.showNotification({type:"error",message:`panel.${v}.invalidStateShape`});return}let r=i.block.getShape(o);i.block.setString(r,"shape/vector_path/path",h),i.block.setFloat(r,"shape/vector_path/height",n),i.block.setFloat(r,"shape/vector_path/width",n),Ce(i,o)}else if(f==="fill"){if(!i.block.supportsFill(o)){e.ui.showNotification({type:"error",message:`panel.${v}.invalidStateFill`});return}let r=i.block.getFill(o),a=`data:text/plain;base64,${btoa(t)}`;i.block.setSourceSet(r,"fill/image/sourceSet",[{uri:a,width:n,height:n}])}}function Ce(e,i){let o=e.block.duplicate(i),s=e.block.getParent(i);if(s!=null){let c=e.block.create("graphic");e.block.setShape(c,e.block.createShape("//ly.img.ubq/shape/rect")),e.block.appendChild(s,c),e.block.setPositionX(c,e.block.getPositionX(i)),e.block.setPositionY(c,e.block.getPositionY(i)),e.block.setWidth(c,e.block.getWidth(i)),e.block.setHeight(c,e.block.getHeight(i));let f=e.block.combine([o,c],"Intersection");e.block.setShape(i,e.block.getShape(f)),e.block.destroy(f)}return i}var Fn=e=>({name:Q,version:"0.1.2",...Se(e)}),ti=Fn;export{ti as default}; /*! Bundled license information: lodash-es/lodash.js: (** * @license * Lodash (Custom Build) <https://lodash.com/> * Build: `lodash modularize exports="es" -o ./` * Copyright OpenJS Foundation and other contributors <https://openjsf.org/> * Released under MIT license <https://lodash.com/license> * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors *) */ /** * @license QR Code generator library (TypeScript) * Copyright (c) Project Nayuki. * SPDX-License-Identifier: MIT */ //# sourceMappingURL=index.mjs.map