@sunspots/shapes 0.0.7 → 0.0.8
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/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -18,14 +18,14 @@ declare class Bar extends Rect {
|
|
|
18
18
|
interface BarcodeConfig extends ShapeConfig {
|
|
19
19
|
content: string;
|
|
20
20
|
codeType: string;
|
|
21
|
-
readable
|
|
21
|
+
readable?: boolean;
|
|
22
22
|
}
|
|
23
23
|
declare class Barcode extends Shape<BarcodeConfig> implements BarcodeConfig {
|
|
24
24
|
type: string;
|
|
25
25
|
fill: string;
|
|
26
26
|
codeType: string;
|
|
27
27
|
content: string;
|
|
28
|
-
readable
|
|
28
|
+
readable?: boolean;
|
|
29
29
|
private data;
|
|
30
30
|
render(context: CanvasRenderingContext2D): void;
|
|
31
31
|
renderShadow(context: CanvasRenderingContext2D): void;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var K=Object.defineProperty;var g=(x,f)=>K(x,"name",{value:f,configurable:!0});import{Shape as V}from"@sunspots/core";var B=class B extends V{constructor(){super(...arguments);this.type="rect"}render(n){let{x:l,y:a,width:c,height:r,stroke:h}=this;n.fillRect(l,a,c,r),h&&n.strokeRect(l,a,c,r)}innerBox(){return{x:this.x,y:this.y,width:this.width,height:this.height}}boundingBox(){var c;let n=this.innerBox(),l=(c=this.strokeWidth)!=null?c:0,a=l/2;return n.x-=a,n.y-=a,n.width+=l,n.height+=l,n}};g(B,"Rect");var R=B;var N=class N extends R{constructor(){super(...arguments);this.type="bar"}};g(N,"Bar");var F=N;import{Shape as $}from"@sunspots/core";var P=class P extends ${constructor(){super(...arguments);this.type="barcode";this.fill="#000000";this.data=new Array(120).fill(null).map(()=>Math.floor(Math.random()*4)*1.5)}render(n){let{x:l,y:a,height:c}=this,r=0;for(let h=0;h<this.data.length;h++)h%2===0&&n.fillRect(l+r,a,this.data[h],c),r+=this.data[h]}renderShadow(n){let{x:l,y:a,height:c}=this;n.fillRect(l,a,this.data.reduce((r,h)=>r+h),c)}innerBox(){return{x:this.x,y:this.y,width:this.data.reduce((n,l)=>n+l),height:this.height}}boundingBox(){var c;let n=this.innerBox(),l=(c=this.strokeWidth)!=null?c:0,a=l/2;return n.x-=a,n.y-=a,n.width+=l,n.height+=l,n}toObject(){return super.toObject({content:this.content,codeType:this.codeType})}};g(P,"Barcode");var W=P,pt=["CODA","CODE49","CPOST","DPI","DPL","EAN128","EAN128M","EAN13","EAN13+2","EAN13+5","EAN14","EAN8","EAN8+2","EAN8+5","ITF14","LOGMARS","MSI","MSIC","PLANET","PLESSEY","POST","TELEPEN","TELEPENN","UPA+5","UPCA","UPCA+2","UPCE","UPCE+2","UPE+5","11","128","128M","25","25C","25I","25S","39","39C","93"];var I=class I extends R{constructor(){super(...arguments);this.type="box"}};g(I,"Box");var U=I;import{Shape as J}from"@sunspots/core";var T=class T extends J{constructor(){super(...arguments);this.type="circle"}render(n){let{x:l,y:a,radius:c,stroke:r,strokeWidth:h}=this;n.beginPath(),n.arc(l,a,c,0,Math.PI*2,!1),n.fill(),r&&(n.lineWidth=h!=null?h:1,n.stroke()),n.closePath()}innerBox(){return{x:this.x-this.radius,y:this.y-this.radius,width:this.radius*2,height:this.radius*2}}boundingBox(){var c;let n=this.innerBox(),l=(c=this.strokeWidth)!=null?c:0,a=l/2;return n.x-=a,n.y-=a,n.width+=l,n.height+=l,n}setWidth(n){this.width=n,this.radius=n/2}setHeight(n){this.height=n,this.radius=n/2}};g(T,"Circle");var Q=T;import{Shape as Z}from"@sunspots/core";var z=class z extends Z{constructor(){super(...arguments);this.type="image";this.fill="#000000"}render(n){let{x:l,y:a,width:c,height:r,image:h}=this;n.drawImage(h,l,a,c,r)}renderShadow(n){let{x:l,y:a,width:c,height:r}=this;n.fillRect(l,a,c,r)}innerBox(){return{x:this.x,y:this.y,width:this.width,height:this.height}}boundingBox(){var c;let n=this.innerBox(),l=(c=this.strokeWidth)!=null?c:0,a=l/2;return n.x-=a,n.y-=a,n.width+=l,n.height+=l,n}};g(z,"Image");var H=z;import{Color as q,Shape as _}from"@sunspots/core";var E;(c=>{let r=class r{constructor(t,i,e,o){this.version=t;this.errorCorrectionLevel=i;this.modules=[];this.isFunction=[];if(t<r.MIN_VERSION||t>r.MAX_VERSION)throw new RangeError("Version value out of range");if(o<-1||o>7)throw new RangeError("Mask value out of range");this.size=t*4+17;let s=[];for(let d=0;d<this.size;d++)s.push(!1);for(let d=0;d<this.size;d++)this.modules.push(s.slice()),this.isFunction.push(s.slice());this.drawFunctionPatterns();let u=this.addEccAndInterleave(e);if(this.drawCodewords(u),o==-1){let d=1e9;for(let m=0;m<8;m++){this.applyMask(m),this.drawFormatBits(m);let p=this.getPenaltyScore();p<d&&(o=m,d=p),this.applyMask(m)}}l(o>=0&&o<=7),this.mask=o,this.applyMask(o),this.drawFormatBits(o),this.isFunction=[]}static encodeText(t,i){let e=c.QrSegment.makeSegments(t);return r.encodeSegments(e,i)}static encodeBinary(t,i){let e=c.QrSegment.makeBytes(t);return r.encodeSegments([e],i)}static encodeSegments(t,i,e=1,o=40,s=-1,u=!0){if(!(r.MIN_VERSION<=e&&e<=o&&o<=r.MAX_VERSION)||s<-1||s>7)throw new RangeError("Invalid value");let d,m;for(d=e;;d++){let b=r.getNumDataCodewords(d,i)*8,y=a.getTotalBits(t,d);if(y<=b){m=y;break}if(d>=o)throw new RangeError("Data too long")}for(let b of[r.Ecc.MEDIUM,r.Ecc.QUARTILE,r.Ecc.HIGH])u&&m<=r.getNumDataCodewords(d,b)*8&&(i=b);let p=[];for(let b of t){f(b.mode.modeBits,4,p),f(b.numChars,b.mode.numCharCountBits(d),p);for(let y of b.getData())p.push(y)}l(p.length==m);let M=r.getNumDataCodewords(d,i)*8;l(p.length<=M),f(0,Math.min(4,M-p.length),p),f(0,(8-p.length%8)%8,p),l(p.length%8==0);for(let b=236;p.length<M;b^=253)f(b,8,p);let v=[];for(;v.length*8<p.length;)v.push(0);return p.forEach((b,y)=>v[y>>>3]|=b<<7-(y&7)),new r(d,i,v,s)}getModule(t,i){return t>=0&&t<this.size&&i>=0&&i<this.size&&this.modules[i][t]}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 t=this.getAlignmentPatternPositions(),i=t.length;for(let e=0;e<i;e++)for(let o=0;o<i;o++)e==0&&o==0||e==0&&o==i-1||e==i-1&&o==0||this.drawAlignmentPattern(t[e],t[o]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(t){let i=this.errorCorrectionLevel.formatBits<<3|t,e=i;for(let s=0;s<10;s++)e=e<<1^(e>>>9)*1335;let o=(i<<10|e)^21522;l(o>>>15==0);for(let s=0;s<=5;s++)this.setFunctionModule(8,s,n(o,s));this.setFunctionModule(8,7,n(o,6)),this.setFunctionModule(8,8,n(o,7)),this.setFunctionModule(7,8,n(o,8));for(let s=9;s<15;s++)this.setFunctionModule(14-s,8,n(o,s));for(let s=0;s<8;s++)this.setFunctionModule(this.size-1-s,8,n(o,s));for(let s=8;s<15;s++)this.setFunctionModule(8,this.size-15+s,n(o,s));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let t=this.version;for(let e=0;e<12;e++)t=t<<1^(t>>>11)*7973;let i=this.version<<12|t;l(i>>>18==0);for(let e=0;e<18;e++){let o=n(i,e),s=this.size-11+e%3,u=Math.floor(e/3);this.setFunctionModule(s,u,o),this.setFunctionModule(u,s,o)}}drawFinderPattern(t,i){for(let e=-4;e<=4;e++)for(let o=-4;o<=4;o++){let s=Math.max(Math.abs(o),Math.abs(e)),u=t+o,d=i+e;u>=0&&u<this.size&&d>=0&&d<this.size&&this.setFunctionModule(u,d,s!=2&&s!=4)}}drawAlignmentPattern(t,i){for(let e=-2;e<=2;e++)for(let o=-2;o<=2;o++)this.setFunctionModule(t+o,i+e,Math.max(Math.abs(o),Math.abs(e))!=1)}setFunctionModule(t,i,e){this.modules[i][t]=e,this.isFunction[i][t]=!0}addEccAndInterleave(t){let i=this.version,e=this.errorCorrectionLevel;if(t.length!=r.getNumDataCodewords(i,e))throw new RangeError("Invalid argument");let o=r.NUM_ERROR_CORRECTION_BLOCKS[e.ordinal][i],s=r.ECC_CODEWORDS_PER_BLOCK[e.ordinal][i],u=Math.floor(r.getNumRawDataModules(i)/8),d=o-u%o,m=Math.floor(u/o),p=[],M=r.reedSolomonComputeDivisor(s);for(let b=0,y=0;b<o;b++){let w=t.slice(y,y+m-s+(b<d?0:1));y+=w.length;let G=r.reedSolomonComputeRemainder(w,M);b<d&&w.push(0),p.push(w.concat(G))}let v=[];for(let b=0;b<p[0].length;b++)p.forEach((y,w)=>{(b!=m-s||w>=d)&&v.push(y[b])});return l(v.length==u),v}drawCodewords(t){if(t.length!=Math.floor(r.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let i=0;for(let e=this.size-1;e>=1;e-=2){e==6&&(e=5);for(let o=0;o<this.size;o++)for(let s=0;s<2;s++){let u=e-s,m=(e+1&2)==0?this.size-1-o:o;!this.isFunction[m][u]&&i<t.length*8&&(this.modules[m][u]=n(t[i>>>3],7-(i&7)),i++)}}l(i==t.length*8)}applyMask(t){if(t<0||t>7)throw new RangeError("Mask value out of range");for(let i=0;i<this.size;i++)for(let e=0;e<this.size;e++){let o;switch(t){case 0:o=(e+i)%2==0;break;case 1:o=i%2==0;break;case 2:o=e%3==0;break;case 3:o=(e+i)%3==0;break;case 4:o=(Math.floor(e/3)+Math.floor(i/2))%2==0;break;case 5:o=e*i%2+e*i%3==0;break;case 6:o=(e*i%2+e*i%3)%2==0;break;case 7:o=((e+i)%2+e*i%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[i][e]&&o&&(this.modules[i][e]=!this.modules[i][e])}}getPenaltyScore(){let t=0;for(let s=0;s<this.size;s++){let u=!1,d=0,m=[0,0,0,0,0,0,0];for(let p=0;p<this.size;p++)this.modules[s][p]==u?(d++,d==5?t+=r.PENALTY_N1:d>5&&t++):(this.finderPenaltyAddHistory(d,m),u||(t+=this.finderPenaltyCountPatterns(m)*r.PENALTY_N3),u=this.modules[s][p],d=1);t+=this.finderPenaltyTerminateAndCount(u,d,m)*r.PENALTY_N3}for(let s=0;s<this.size;s++){let u=!1,d=0,m=[0,0,0,0,0,0,0];for(let p=0;p<this.size;p++)this.modules[p][s]==u?(d++,d==5?t+=r.PENALTY_N1:d>5&&t++):(this.finderPenaltyAddHistory(d,m),u||(t+=this.finderPenaltyCountPatterns(m)*r.PENALTY_N3),u=this.modules[p][s],d=1);t+=this.finderPenaltyTerminateAndCount(u,d,m)*r.PENALTY_N3}for(let s=0;s<this.size-1;s++)for(let u=0;u<this.size-1;u++){let d=this.modules[s][u];d==this.modules[s][u+1]&&d==this.modules[s+1][u]&&d==this.modules[s+1][u+1]&&(t+=r.PENALTY_N2)}let i=0;for(let s of this.modules)i=s.reduce((u,d)=>u+(d?1:0),i);let e=this.size*this.size,o=Math.ceil(Math.abs(i*20-e*10)/e)-1;return l(o>=0&&o<=9),t+=o*r.PENALTY_N4,l(t>=0&&t<=2568888),t}getAlignmentPatternPositions(){if(this.version==1)return[];{let t=Math.floor(this.version/7)+2,i=this.version==32?26:Math.ceil((this.version*4+4)/(t*2-2))*2,e=[6];for(let o=this.size-7;e.length<t;o-=i)e.splice(1,0,o);return e}}static getNumRawDataModules(t){if(t<r.MIN_VERSION||t>r.MAX_VERSION)throw new RangeError("Version number out of range");let i=(16*t+128)*t+64;if(t>=2){let e=Math.floor(t/7)+2;i-=(25*e-10)*e-55,t>=7&&(i-=36)}return l(i>=208&&i<=29648),i}static getNumDataCodewords(t,i){return Math.floor(r.getNumRawDataModules(t)/8)-r.ECC_CODEWORDS_PER_BLOCK[i.ordinal][t]*r.NUM_ERROR_CORRECTION_BLOCKS[i.ordinal][t]}static reedSolomonComputeDivisor(t){if(t<1||t>255)throw new RangeError("Degree out of range");let i=[];for(let o=0;o<t-1;o++)i.push(0);i.push(1);let e=1;for(let o=0;o<t;o++){for(let s=0;s<i.length;s++)i[s]=r.reedSolomonMultiply(i[s],e),s+1<i.length&&(i[s]^=i[s+1]);e=r.reedSolomonMultiply(e,2)}return i}static reedSolomonComputeRemainder(t,i){let e=i.map(o=>0);for(let o of t){let s=o^e.shift();e.push(0),i.forEach((u,d)=>e[d]^=r.reedSolomonMultiply(u,s))}return e}static reedSolomonMultiply(t,i){if(t>>>8||i>>>8)throw new RangeError("Byte out of range");let e=0;for(let o=7;o>=0;o--)e=e<<1^(e>>>7)*285,e^=(i>>>o&1)*t;return l(e>>>8==0),e}finderPenaltyCountPatterns(t){let i=t[1];l(i<=this.size*3);let e=i>0&&t[2]==i&&t[3]==i*3&&t[4]==i&&t[5]==i;return(e&&t[0]>=i*4&&t[6]>=i?1:0)+(e&&t[6]>=i*4&&t[0]>=i?1:0)}finderPenaltyTerminateAndCount(t,i,e){return t&&(this.finderPenaltyAddHistory(i,e),i=0),i+=this.size,this.finderPenaltyAddHistory(i,e),this.finderPenaltyCountPatterns(e)}finderPenaltyAddHistory(t,i){i[0]==0&&(t+=this.size),i.pop(),i.unshift(t)}};g(r,"QrCode"),r.MIN_VERSION=1,r.MAX_VERSION=40,r.PENALTY_N1=3,r.PENALTY_N2=3,r.PENALTY_N3=40,r.PENALTY_N4=10,r.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]],r.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]];let x=r;c.QrCode=r;function f(C,t,i){if(t<0||t>31||C>>>t)throw new RangeError("Value out of range");for(let e=t-1;e>=0;e--)i.push(C>>>e&1)}g(f,"appendBits");function n(C,t){return(C>>>t&1)!=0}g(n,"getBit");function l(C){if(!C)throw new Error("Assertion error")}g(l,"assert");let h=class h{constructor(t,i,e){this.mode=t;this.numChars=i;this.bitData=e;if(i<0)throw new RangeError("Invalid argument");this.bitData=e.slice()}static makeBytes(t){let i=[];for(let e of t)f(e,8,i);return new h(h.Mode.BYTE,t.length,i)}static makeNumeric(t){if(!h.isNumeric(t))throw new RangeError("String contains non-numeric characters");let i=[];for(let e=0;e<t.length;){let o=Math.min(t.length-e,3);f(parseInt(t.substring(e,e+o),10),o*3+1,i),e+=o}return new h(h.Mode.NUMERIC,t.length,i)}static makeAlphanumeric(t){if(!h.isAlphanumeric(t))throw new RangeError("String contains unencodable characters in alphanumeric mode");let i=[],e;for(e=0;e+2<=t.length;e+=2){let o=h.ALPHANUMERIC_CHARSET.indexOf(t.charAt(e))*45;o+=h.ALPHANUMERIC_CHARSET.indexOf(t.charAt(e+1)),f(o,11,i)}return e<t.length&&f(h.ALPHANUMERIC_CHARSET.indexOf(t.charAt(e)),6,i),new h(h.Mode.ALPHANUMERIC,t.length,i)}static makeSegments(t){return t==""?[]:h.isNumeric(t)?[h.makeNumeric(t)]:h.isAlphanumeric(t)?[h.makeAlphanumeric(t)]:[h.makeBytes(h.toUtf8ByteArray(t))]}static makeEci(t){let i=[];if(t<0)throw new RangeError("ECI assignment value out of range");if(t<128)f(t,8,i);else if(t<16384)f(2,2,i),f(t,14,i);else if(t<1e6)f(6,3,i),f(t,21,i);else throw new RangeError("ECI assignment value out of range");return new h(h.Mode.ECI,0,i)}static isNumeric(t){return h.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return h.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(t,i){let e=0;for(let o of t){let s=o.mode.numCharCountBits(i);if(o.numChars>=1<<s)return 1/0;e+=4+s+o.bitData.length}return e}static toUtf8ByteArray(t){t=encodeURI(t);let i=[];for(let e=0;e<t.length;e++)t.charAt(e)!="%"?i.push(t.charCodeAt(e)):(i.push(parseInt(t.substring(e+1,e+3),16)),e+=2);return i}};g(h,"QrSegment"),h.NUMERIC_REGEX=/^[0-9]*$/,h.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,h.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let a=h;c.QrSegment=h})(E||(E={}));(f=>{let x;(l=>{let a=class a{constructor(r,h){this.ordinal=r;this.formatBits=h}};g(a,"Ecc"),a.LOW=new a(0,1),a.MEDIUM=new a(1,0),a.QUARTILE=new a(2,3),a.HIGH=new a(3,2);let n=a;l.Ecc=a})(x=f.QrCode||(f.QrCode={}))})(E||(E={}));(f=>{let x;(l=>{let a=class a{constructor(r,h){this.modeBits=r;this.numBitsCharCount=h}numCharCountBits(r){return this.numBitsCharCount[Math.floor((r+7)/17)]}};g(a,"Mode"),a.NUMERIC=new a(1,[10,12,14]),a.ALPHANUMERIC=new a(2,[9,11,13]),a.BYTE=new a(4,[8,16,16]),a.KANJI=new a(8,[8,10,12]),a.ECI=new a(7,[0,0,0]);let n=a;l.Mode=a})(x=f.QrSegment||(f.QrSegment={}))})(E||(E={}));var S=E;var tt={L:S.QrCode.Ecc.LOW,M:S.QrCode.Ecc.MEDIUM,Q:S.QrCode.Ecc.QUARTILE,H:S.QrCode.Ecc.HIGH};function O(x,f){return S.QrCode.encodeText(x,tt[f])}g(O,"createQr");var L=class L extends _{constructor(n){super(n);this.config=n;this.type="qrcode";this.fill="#000000";this.resizable=!1;this.moduleSize=6;this.padding=1;this.qr=O(this.content,this.level);Object.assign(this,n)}get content(){return this.config.content}set content(n){this.config.content=n,this.qr=O(this.content,this.level)}get level(){var n;return(n=this.config.level)!=null?n:"M"}set level(n){this.config.level=n,this.qr=O(this.content,this.level)}render(n){let{x:l,y:a,qr:c,padding:r,moduleSize:h}=this;for(let C=0;C<c.size;C++)for(let t=0;t<c.size;t++)n.fillStyle=c.getModule(t,C)?this.fill:q.Transparent,n.fillRect(l+(t+r)*h,a+(C+r)*h,h,h)}renderShadow(n){let{x:l,y:a,qr:c,padding:r,moduleSize:h}=this,C=(c.size+r*2)*h;n.fillRect(l,a,C,C)}innerBox(){let{x:n,y:l,qr:a,padding:c,moduleSize:r}=this,h=(a.size+c*2)*r;return{x:n,y:l,width:h,height:h}}boundingBox(){var c;let n=this.innerBox(),l=(c=this.strokeWidth)!=null?c:0,a=l/2;return n.x-=a,n.y-=a,n.width+=l,n.height+=l,n}toObject(){return super.toObject({content:this.content,moduleSize:this.moduleSize,level:this.level})}};g(L,"Qrcode");var Y=L;import{Shape as et,withPixel as j}from"@sunspots/core";var D=class D extends et{constructor(n){super(n);this.type="text";this.resizable=!1;Object.assign(this,n)}get width(){var n;return(n=this.config.width)!=null?n:0}set width(n){this.config.width=n}get height(){var n;return(n=this.fontSize)!=null?n:0}set height(n){this.fontSize=n}render(n){let{x:l,y:a,content:c,fontSize:r,fontStyle:h,fontWeight:C,fontFamily:t,maxWidth:i,algin:e}=this;n.textAlign=e!=null?e:"left",n.textBaseline="top",n.font=[h,C,j(r),t!=null?t:"sans-serif"].filter(Boolean).join(" "),n.fillText(c,l,a,i)}innerBox(){var n;return this.width=this.textWidth(),{x:this.x,y:this.y,width:(n=this.width)!=null?n:0,height:this.fontSize}}boundingBox(){return this.innerBox()}textWidth(){let n=this.stage.draftContext,{content:l,fontSize:a,fontStyle:c,fontWeight:r,fontFamily:h}=this;n.font=[c,r,j(a),h!=null?h:"sans-serif"].filter(Boolean).join(" ");let{width:C}=n.measureText(l);return C}renderShadow(n){let{x:l,y:a,fontSize:c}=this,r=this.textWidth();n.fillRect(l,a,r,c),this.width=r}setWidth(n){this.width=this.textWidth()}setHeight(n){this.height=n,this.fontSize=n}toObject(n={}){return Object.assign(super.toObject({content:this.content,fontSize:this.fontSize}),n)}};g(D,"Text");var A=D;var k=class k extends A{constructor(n){super(n);this.scale=1;Object.assign(this,n)}toObject(){return super.toObject({scale:this.scale,font:this.font})}};g(k,"TsplText");var X=k,Xt=new Map([["TSS16.BF2",16],["TSS24.BF2",24],["TSS32.BF2",32]]);export{pt as BARCODE_TYPES,F as Bar,W as Barcode,U as Box,Q as Circle,H as Image,Y as Qrcode,R as Rect,Xt as TSPL_FONT_MAP,A as Text,X as TsplText};
|
|
1
|
+
var K=Object.defineProperty;var g=(x,f)=>K(x,"name",{value:f,configurable:!0});import{Shape as V}from"@sunspots/core";var B=class B extends V{constructor(){super(...arguments);this.type="rect"}render(n){let{x:l,y:a,width:c,height:r,stroke:h}=this;n.fillRect(l,a,c,r),h&&n.strokeRect(l,a,c,r)}innerBox(){return{x:this.x,y:this.y,width:this.width,height:this.height}}boundingBox(){var c;let n=this.innerBox(),l=(c=this.strokeWidth)!=null?c:0,a=l/2;return n.x-=a,n.y-=a,n.width+=l,n.height+=l,n}};g(B,"Rect");var R=B;var N=class N extends R{constructor(){super(...arguments);this.type="bar"}};g(N,"Bar");var F=N;import{Shape as $}from"@sunspots/core";var P=class P extends ${constructor(){super(...arguments);this.type="barcode";this.fill="#000000";this.data=new Array(120).fill(null).map(()=>Math.floor(Math.random()*4)*1.5)}render(n){let{x:l,y:a,height:c}=this,r=0;for(let h=0;h<this.data.length;h++)h%2===0&&n.fillRect(l+r,a,this.data[h],c),r+=this.data[h]}renderShadow(n){let{x:l,y:a,height:c}=this;n.fillRect(l,a,this.data.reduce((r,h)=>r+h),c)}innerBox(){return{x:this.x,y:this.y,width:this.data.reduce((n,l)=>n+l),height:this.height}}boundingBox(){var c;let n=this.innerBox(),l=(c=this.strokeWidth)!=null?c:0,a=l/2;return n.x-=a,n.y-=a,n.width+=l,n.height+=l,n}toObject(){return super.toObject({content:this.content,codeType:this.codeType,readable:this.readable})}};g(P,"Barcode");var W=P,pt=["CODA","CODE49","CPOST","DPI","DPL","EAN128","EAN128M","EAN13","EAN13+2","EAN13+5","EAN14","EAN8","EAN8+2","EAN8+5","ITF14","LOGMARS","MSI","MSIC","PLANET","PLESSEY","POST","TELEPEN","TELEPENN","UPA+5","UPCA","UPCA+2","UPCE","UPCE+2","UPE+5","11","128","128M","25","25C","25I","25S","39","39C","93"];var I=class I extends R{constructor(){super(...arguments);this.type="box"}};g(I,"Box");var U=I;import{Shape as J}from"@sunspots/core";var T=class T extends J{constructor(){super(...arguments);this.type="circle"}render(n){let{x:l,y:a,radius:c,stroke:r,strokeWidth:h}=this;n.beginPath(),n.arc(l,a,c,0,Math.PI*2,!1),n.fill(),r&&(n.lineWidth=h!=null?h:1,n.stroke()),n.closePath()}innerBox(){return{x:this.x-this.radius,y:this.y-this.radius,width:this.radius*2,height:this.radius*2}}boundingBox(){var c;let n=this.innerBox(),l=(c=this.strokeWidth)!=null?c:0,a=l/2;return n.x-=a,n.y-=a,n.width+=l,n.height+=l,n}setWidth(n){this.width=n,this.radius=n/2}setHeight(n){this.height=n,this.radius=n/2}};g(T,"Circle");var Q=T;import{Shape as Z}from"@sunspots/core";var z=class z extends Z{constructor(){super(...arguments);this.type="image";this.fill="#000000"}render(n){let{x:l,y:a,width:c,height:r,image:h}=this;n.drawImage(h,l,a,c,r)}renderShadow(n){let{x:l,y:a,width:c,height:r}=this;n.fillRect(l,a,c,r)}innerBox(){return{x:this.x,y:this.y,width:this.width,height:this.height}}boundingBox(){var c;let n=this.innerBox(),l=(c=this.strokeWidth)!=null?c:0,a=l/2;return n.x-=a,n.y-=a,n.width+=l,n.height+=l,n}};g(z,"Image");var H=z;import{Color as q,Shape as _}from"@sunspots/core";var E;(c=>{let r=class r{constructor(t,i,e,o){this.version=t;this.errorCorrectionLevel=i;this.modules=[];this.isFunction=[];if(t<r.MIN_VERSION||t>r.MAX_VERSION)throw new RangeError("Version value out of range");if(o<-1||o>7)throw new RangeError("Mask value out of range");this.size=t*4+17;let s=[];for(let d=0;d<this.size;d++)s.push(!1);for(let d=0;d<this.size;d++)this.modules.push(s.slice()),this.isFunction.push(s.slice());this.drawFunctionPatterns();let u=this.addEccAndInterleave(e);if(this.drawCodewords(u),o==-1){let d=1e9;for(let m=0;m<8;m++){this.applyMask(m),this.drawFormatBits(m);let p=this.getPenaltyScore();p<d&&(o=m,d=p),this.applyMask(m)}}l(o>=0&&o<=7),this.mask=o,this.applyMask(o),this.drawFormatBits(o),this.isFunction=[]}static encodeText(t,i){let e=c.QrSegment.makeSegments(t);return r.encodeSegments(e,i)}static encodeBinary(t,i){let e=c.QrSegment.makeBytes(t);return r.encodeSegments([e],i)}static encodeSegments(t,i,e=1,o=40,s=-1,u=!0){if(!(r.MIN_VERSION<=e&&e<=o&&o<=r.MAX_VERSION)||s<-1||s>7)throw new RangeError("Invalid value");let d,m;for(d=e;;d++){let b=r.getNumDataCodewords(d,i)*8,y=a.getTotalBits(t,d);if(y<=b){m=y;break}if(d>=o)throw new RangeError("Data too long")}for(let b of[r.Ecc.MEDIUM,r.Ecc.QUARTILE,r.Ecc.HIGH])u&&m<=r.getNumDataCodewords(d,b)*8&&(i=b);let p=[];for(let b of t){f(b.mode.modeBits,4,p),f(b.numChars,b.mode.numCharCountBits(d),p);for(let y of b.getData())p.push(y)}l(p.length==m);let M=r.getNumDataCodewords(d,i)*8;l(p.length<=M),f(0,Math.min(4,M-p.length),p),f(0,(8-p.length%8)%8,p),l(p.length%8==0);for(let b=236;p.length<M;b^=253)f(b,8,p);let v=[];for(;v.length*8<p.length;)v.push(0);return p.forEach((b,y)=>v[y>>>3]|=b<<7-(y&7)),new r(d,i,v,s)}getModule(t,i){return t>=0&&t<this.size&&i>=0&&i<this.size&&this.modules[i][t]}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 t=this.getAlignmentPatternPositions(),i=t.length;for(let e=0;e<i;e++)for(let o=0;o<i;o++)e==0&&o==0||e==0&&o==i-1||e==i-1&&o==0||this.drawAlignmentPattern(t[e],t[o]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(t){let i=this.errorCorrectionLevel.formatBits<<3|t,e=i;for(let s=0;s<10;s++)e=e<<1^(e>>>9)*1335;let o=(i<<10|e)^21522;l(o>>>15==0);for(let s=0;s<=5;s++)this.setFunctionModule(8,s,n(o,s));this.setFunctionModule(8,7,n(o,6)),this.setFunctionModule(8,8,n(o,7)),this.setFunctionModule(7,8,n(o,8));for(let s=9;s<15;s++)this.setFunctionModule(14-s,8,n(o,s));for(let s=0;s<8;s++)this.setFunctionModule(this.size-1-s,8,n(o,s));for(let s=8;s<15;s++)this.setFunctionModule(8,this.size-15+s,n(o,s));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let t=this.version;for(let e=0;e<12;e++)t=t<<1^(t>>>11)*7973;let i=this.version<<12|t;l(i>>>18==0);for(let e=0;e<18;e++){let o=n(i,e),s=this.size-11+e%3,u=Math.floor(e/3);this.setFunctionModule(s,u,o),this.setFunctionModule(u,s,o)}}drawFinderPattern(t,i){for(let e=-4;e<=4;e++)for(let o=-4;o<=4;o++){let s=Math.max(Math.abs(o),Math.abs(e)),u=t+o,d=i+e;u>=0&&u<this.size&&d>=0&&d<this.size&&this.setFunctionModule(u,d,s!=2&&s!=4)}}drawAlignmentPattern(t,i){for(let e=-2;e<=2;e++)for(let o=-2;o<=2;o++)this.setFunctionModule(t+o,i+e,Math.max(Math.abs(o),Math.abs(e))!=1)}setFunctionModule(t,i,e){this.modules[i][t]=e,this.isFunction[i][t]=!0}addEccAndInterleave(t){let i=this.version,e=this.errorCorrectionLevel;if(t.length!=r.getNumDataCodewords(i,e))throw new RangeError("Invalid argument");let o=r.NUM_ERROR_CORRECTION_BLOCKS[e.ordinal][i],s=r.ECC_CODEWORDS_PER_BLOCK[e.ordinal][i],u=Math.floor(r.getNumRawDataModules(i)/8),d=o-u%o,m=Math.floor(u/o),p=[],M=r.reedSolomonComputeDivisor(s);for(let b=0,y=0;b<o;b++){let w=t.slice(y,y+m-s+(b<d?0:1));y+=w.length;let G=r.reedSolomonComputeRemainder(w,M);b<d&&w.push(0),p.push(w.concat(G))}let v=[];for(let b=0;b<p[0].length;b++)p.forEach((y,w)=>{(b!=m-s||w>=d)&&v.push(y[b])});return l(v.length==u),v}drawCodewords(t){if(t.length!=Math.floor(r.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let i=0;for(let e=this.size-1;e>=1;e-=2){e==6&&(e=5);for(let o=0;o<this.size;o++)for(let s=0;s<2;s++){let u=e-s,m=(e+1&2)==0?this.size-1-o:o;!this.isFunction[m][u]&&i<t.length*8&&(this.modules[m][u]=n(t[i>>>3],7-(i&7)),i++)}}l(i==t.length*8)}applyMask(t){if(t<0||t>7)throw new RangeError("Mask value out of range");for(let i=0;i<this.size;i++)for(let e=0;e<this.size;e++){let o;switch(t){case 0:o=(e+i)%2==0;break;case 1:o=i%2==0;break;case 2:o=e%3==0;break;case 3:o=(e+i)%3==0;break;case 4:o=(Math.floor(e/3)+Math.floor(i/2))%2==0;break;case 5:o=e*i%2+e*i%3==0;break;case 6:o=(e*i%2+e*i%3)%2==0;break;case 7:o=((e+i)%2+e*i%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[i][e]&&o&&(this.modules[i][e]=!this.modules[i][e])}}getPenaltyScore(){let t=0;for(let s=0;s<this.size;s++){let u=!1,d=0,m=[0,0,0,0,0,0,0];for(let p=0;p<this.size;p++)this.modules[s][p]==u?(d++,d==5?t+=r.PENALTY_N1:d>5&&t++):(this.finderPenaltyAddHistory(d,m),u||(t+=this.finderPenaltyCountPatterns(m)*r.PENALTY_N3),u=this.modules[s][p],d=1);t+=this.finderPenaltyTerminateAndCount(u,d,m)*r.PENALTY_N3}for(let s=0;s<this.size;s++){let u=!1,d=0,m=[0,0,0,0,0,0,0];for(let p=0;p<this.size;p++)this.modules[p][s]==u?(d++,d==5?t+=r.PENALTY_N1:d>5&&t++):(this.finderPenaltyAddHistory(d,m),u||(t+=this.finderPenaltyCountPatterns(m)*r.PENALTY_N3),u=this.modules[p][s],d=1);t+=this.finderPenaltyTerminateAndCount(u,d,m)*r.PENALTY_N3}for(let s=0;s<this.size-1;s++)for(let u=0;u<this.size-1;u++){let d=this.modules[s][u];d==this.modules[s][u+1]&&d==this.modules[s+1][u]&&d==this.modules[s+1][u+1]&&(t+=r.PENALTY_N2)}let i=0;for(let s of this.modules)i=s.reduce((u,d)=>u+(d?1:0),i);let e=this.size*this.size,o=Math.ceil(Math.abs(i*20-e*10)/e)-1;return l(o>=0&&o<=9),t+=o*r.PENALTY_N4,l(t>=0&&t<=2568888),t}getAlignmentPatternPositions(){if(this.version==1)return[];{let t=Math.floor(this.version/7)+2,i=this.version==32?26:Math.ceil((this.version*4+4)/(t*2-2))*2,e=[6];for(let o=this.size-7;e.length<t;o-=i)e.splice(1,0,o);return e}}static getNumRawDataModules(t){if(t<r.MIN_VERSION||t>r.MAX_VERSION)throw new RangeError("Version number out of range");let i=(16*t+128)*t+64;if(t>=2){let e=Math.floor(t/7)+2;i-=(25*e-10)*e-55,t>=7&&(i-=36)}return l(i>=208&&i<=29648),i}static getNumDataCodewords(t,i){return Math.floor(r.getNumRawDataModules(t)/8)-r.ECC_CODEWORDS_PER_BLOCK[i.ordinal][t]*r.NUM_ERROR_CORRECTION_BLOCKS[i.ordinal][t]}static reedSolomonComputeDivisor(t){if(t<1||t>255)throw new RangeError("Degree out of range");let i=[];for(let o=0;o<t-1;o++)i.push(0);i.push(1);let e=1;for(let o=0;o<t;o++){for(let s=0;s<i.length;s++)i[s]=r.reedSolomonMultiply(i[s],e),s+1<i.length&&(i[s]^=i[s+1]);e=r.reedSolomonMultiply(e,2)}return i}static reedSolomonComputeRemainder(t,i){let e=i.map(o=>0);for(let o of t){let s=o^e.shift();e.push(0),i.forEach((u,d)=>e[d]^=r.reedSolomonMultiply(u,s))}return e}static reedSolomonMultiply(t,i){if(t>>>8||i>>>8)throw new RangeError("Byte out of range");let e=0;for(let o=7;o>=0;o--)e=e<<1^(e>>>7)*285,e^=(i>>>o&1)*t;return l(e>>>8==0),e}finderPenaltyCountPatterns(t){let i=t[1];l(i<=this.size*3);let e=i>0&&t[2]==i&&t[3]==i*3&&t[4]==i&&t[5]==i;return(e&&t[0]>=i*4&&t[6]>=i?1:0)+(e&&t[6]>=i*4&&t[0]>=i?1:0)}finderPenaltyTerminateAndCount(t,i,e){return t&&(this.finderPenaltyAddHistory(i,e),i=0),i+=this.size,this.finderPenaltyAddHistory(i,e),this.finderPenaltyCountPatterns(e)}finderPenaltyAddHistory(t,i){i[0]==0&&(t+=this.size),i.pop(),i.unshift(t)}};g(r,"QrCode"),r.MIN_VERSION=1,r.MAX_VERSION=40,r.PENALTY_N1=3,r.PENALTY_N2=3,r.PENALTY_N3=40,r.PENALTY_N4=10,r.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]],r.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]];let x=r;c.QrCode=r;function f(C,t,i){if(t<0||t>31||C>>>t)throw new RangeError("Value out of range");for(let e=t-1;e>=0;e--)i.push(C>>>e&1)}g(f,"appendBits");function n(C,t){return(C>>>t&1)!=0}g(n,"getBit");function l(C){if(!C)throw new Error("Assertion error")}g(l,"assert");let h=class h{constructor(t,i,e){this.mode=t;this.numChars=i;this.bitData=e;if(i<0)throw new RangeError("Invalid argument");this.bitData=e.slice()}static makeBytes(t){let i=[];for(let e of t)f(e,8,i);return new h(h.Mode.BYTE,t.length,i)}static makeNumeric(t){if(!h.isNumeric(t))throw new RangeError("String contains non-numeric characters");let i=[];for(let e=0;e<t.length;){let o=Math.min(t.length-e,3);f(parseInt(t.substring(e,e+o),10),o*3+1,i),e+=o}return new h(h.Mode.NUMERIC,t.length,i)}static makeAlphanumeric(t){if(!h.isAlphanumeric(t))throw new RangeError("String contains unencodable characters in alphanumeric mode");let i=[],e;for(e=0;e+2<=t.length;e+=2){let o=h.ALPHANUMERIC_CHARSET.indexOf(t.charAt(e))*45;o+=h.ALPHANUMERIC_CHARSET.indexOf(t.charAt(e+1)),f(o,11,i)}return e<t.length&&f(h.ALPHANUMERIC_CHARSET.indexOf(t.charAt(e)),6,i),new h(h.Mode.ALPHANUMERIC,t.length,i)}static makeSegments(t){return t==""?[]:h.isNumeric(t)?[h.makeNumeric(t)]:h.isAlphanumeric(t)?[h.makeAlphanumeric(t)]:[h.makeBytes(h.toUtf8ByteArray(t))]}static makeEci(t){let i=[];if(t<0)throw new RangeError("ECI assignment value out of range");if(t<128)f(t,8,i);else if(t<16384)f(2,2,i),f(t,14,i);else if(t<1e6)f(6,3,i),f(t,21,i);else throw new RangeError("ECI assignment value out of range");return new h(h.Mode.ECI,0,i)}static isNumeric(t){return h.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return h.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(t,i){let e=0;for(let o of t){let s=o.mode.numCharCountBits(i);if(o.numChars>=1<<s)return 1/0;e+=4+s+o.bitData.length}return e}static toUtf8ByteArray(t){t=encodeURI(t);let i=[];for(let e=0;e<t.length;e++)t.charAt(e)!="%"?i.push(t.charCodeAt(e)):(i.push(parseInt(t.substring(e+1,e+3),16)),e+=2);return i}};g(h,"QrSegment"),h.NUMERIC_REGEX=/^[0-9]*$/,h.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,h.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let a=h;c.QrSegment=h})(E||(E={}));(f=>{let x;(l=>{let a=class a{constructor(r,h){this.ordinal=r;this.formatBits=h}};g(a,"Ecc"),a.LOW=new a(0,1),a.MEDIUM=new a(1,0),a.QUARTILE=new a(2,3),a.HIGH=new a(3,2);let n=a;l.Ecc=a})(x=f.QrCode||(f.QrCode={}))})(E||(E={}));(f=>{let x;(l=>{let a=class a{constructor(r,h){this.modeBits=r;this.numBitsCharCount=h}numCharCountBits(r){return this.numBitsCharCount[Math.floor((r+7)/17)]}};g(a,"Mode"),a.NUMERIC=new a(1,[10,12,14]),a.ALPHANUMERIC=new a(2,[9,11,13]),a.BYTE=new a(4,[8,16,16]),a.KANJI=new a(8,[8,10,12]),a.ECI=new a(7,[0,0,0]);let n=a;l.Mode=a})(x=f.QrSegment||(f.QrSegment={}))})(E||(E={}));var S=E;var tt={L:S.QrCode.Ecc.LOW,M:S.QrCode.Ecc.MEDIUM,Q:S.QrCode.Ecc.QUARTILE,H:S.QrCode.Ecc.HIGH};function O(x,f){return S.QrCode.encodeText(x,tt[f])}g(O,"createQr");var L=class L extends _{constructor(n){super(n);this.config=n;this.type="qrcode";this.fill="#000000";this.resizable=!1;this.moduleSize=6;this.padding=1;this.qr=O(this.content,this.level);Object.assign(this,n)}get content(){return this.config.content}set content(n){this.config.content=n,this.qr=O(this.content,this.level)}get level(){var n;return(n=this.config.level)!=null?n:"M"}set level(n){this.config.level=n,this.qr=O(this.content,this.level)}render(n){let{x:l,y:a,qr:c,padding:r,moduleSize:h}=this;for(let C=0;C<c.size;C++)for(let t=0;t<c.size;t++)n.fillStyle=c.getModule(t,C)?this.fill:q.Transparent,n.fillRect(l+(t+r)*h,a+(C+r)*h,h,h)}renderShadow(n){let{x:l,y:a,qr:c,padding:r,moduleSize:h}=this,C=(c.size+r*2)*h;n.fillRect(l,a,C,C)}innerBox(){let{x:n,y:l,qr:a,padding:c,moduleSize:r}=this,h=(a.size+c*2)*r;return{x:n,y:l,width:h,height:h}}boundingBox(){var c;let n=this.innerBox(),l=(c=this.strokeWidth)!=null?c:0,a=l/2;return n.x-=a,n.y-=a,n.width+=l,n.height+=l,n}toObject(){return super.toObject({content:this.content,moduleSize:this.moduleSize,level:this.level})}};g(L,"Qrcode");var Y=L;import{Shape as et,withPixel as j}from"@sunspots/core";var D=class D extends et{constructor(n){super(n);this.type="text";this.resizable=!1;Object.assign(this,n)}get width(){var n;return(n=this.config.width)!=null?n:0}set width(n){this.config.width=n}get height(){var n;return(n=this.fontSize)!=null?n:0}set height(n){this.fontSize=n}render(n){let{x:l,y:a,content:c,fontSize:r,fontStyle:h,fontWeight:C,fontFamily:t,maxWidth:i,algin:e}=this;n.textAlign=e!=null?e:"left",n.textBaseline="top",n.font=[h,C,j(r),t!=null?t:"sans-serif"].filter(Boolean).join(" "),n.fillText(c,l,a,i)}innerBox(){var n;return this.width=this.textWidth(),{x:this.x,y:this.y,width:(n=this.width)!=null?n:0,height:this.fontSize}}boundingBox(){return this.innerBox()}textWidth(){let n=this.stage.draftContext,{content:l,fontSize:a,fontStyle:c,fontWeight:r,fontFamily:h}=this;n.font=[c,r,j(a),h!=null?h:"sans-serif"].filter(Boolean).join(" ");let{width:C}=n.measureText(l);return C}renderShadow(n){let{x:l,y:a,fontSize:c}=this,r=this.textWidth();n.fillRect(l,a,r,c),this.width=r}setWidth(n){this.width=this.textWidth()}setHeight(n){this.height=n,this.fontSize=n}toObject(n={}){return Object.assign(super.toObject({content:this.content,fontSize:this.fontSize}),n)}};g(D,"Text");var A=D;var k=class k extends A{constructor(n){super(n);this.scale=1;Object.assign(this,n)}toObject(){return super.toObject({scale:this.scale,font:this.font})}};g(k,"TsplText");var X=k,Xt=new Map([["TSS16.BF2",16],["TSS24.BF2",24],["TSS32.BF2",32]]);export{pt as BARCODE_TYPES,F as Bar,W as Barcode,U as Box,Q as Circle,H as Image,Y as Qrcode,R as Rect,Xt as TSPL_FONT_MAP,A as Text,X as TsplText};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sunspots/shapes",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.mts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@sunspots/core": "0.0.
|
|
29
|
+
"@sunspots/core": "0.0.8"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "dfa0060059aab5558a0efa98ec46d6362fc144bb"
|
|
32
32
|
}
|