@sunspots/shapes 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +25 -3
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -172,6 +172,7 @@ interface TsplTextConfig extends TextConfig {
|
|
|
172
172
|
declare class TsplText extends Text implements TsplTextConfig {
|
|
173
173
|
font?: string;
|
|
174
174
|
scale: number;
|
|
175
|
+
wrap?: boolean;
|
|
175
176
|
constructor(config: TsplTextConfig);
|
|
176
177
|
toObject(): {
|
|
177
178
|
type: string;
|
|
@@ -189,7 +190,28 @@ declare class TsplText extends Text implements TsplTextConfig {
|
|
|
189
190
|
/**
|
|
190
191
|
* font => fontSize (px)
|
|
191
192
|
*/
|
|
192
|
-
declare const
|
|
193
|
-
|
|
193
|
+
declare const TSPL_FONT_SIZE_MAP: Map<string, number>;
|
|
194
|
+
/**
|
|
195
|
+
*
|
|
196
|
+
* @param font
|
|
197
|
+
* @param scale
|
|
198
|
+
* @returns pixel
|
|
199
|
+
*/
|
|
200
|
+
declare function getTsplFontSize(font: string, scale?: number): number;
|
|
201
|
+
/**
|
|
202
|
+
* @deprecated Use {@link getTsplFontSize} instead
|
|
203
|
+
*/
|
|
204
|
+
declare const calcFontSize: typeof getTsplFontSize;
|
|
205
|
+
/**
|
|
206
|
+
*
|
|
207
|
+
* @param text
|
|
208
|
+
* @param font
|
|
209
|
+
* @param scale
|
|
210
|
+
* @returns pixel
|
|
211
|
+
*/
|
|
212
|
+
declare function measureTsplText(text: string, font: string, scale?: number): {
|
|
213
|
+
height: number;
|
|
214
|
+
width: number;
|
|
215
|
+
};
|
|
194
216
|
|
|
195
|
-
export { BARCODE_TYPES, Bar, Barcode, type BarcodeConfig, Box, Circle, Image, type ImageConfig, type QrCodeLevel, Qrcode, type QrcodeConfig, Rect, type RectConfig,
|
|
217
|
+
export { BARCODE_TYPES, Bar, Barcode, type BarcodeConfig, Box, Circle, Image, type ImageConfig, type QrCodeLevel, Qrcode, type QrcodeConfig, Rect, type RectConfig, TSPL_FONT_SIZE_MAP, Text, type TextConfig, TsplText, calcFontSize, getTsplFontSize, measureTsplText };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Z=Object.defineProperty;var c=(C,i)=>Z(C,"name",{value:i,configurable:!0});import{Shape as _,angleToRadian as tt}from"@sunspots/core";var N=class N extends _{constructor(){super(...arguments);this.type="rect"}render(t){let{x:e,y:r,width:n,height:s,stroke:o,rotation:a}=this;t.save(),a&&(t.translate(e,r),t.rotate(tt(a))),t.fillRect(a?0:e,a?0:r,n,s),o&&t.strokeRect(a?0:e,a?0:r,n,s),t.restore()}innerBox(){return{x:this.x,y:this.y,width:this.width,height:this.height}}boundingBox(){var n;let t=this.innerBox(),e=(n=this.strokeWidth)!=null?n:0,r=e/2;return t.x-=r,t.y-=r,t.width+=e,t.height+=e,t}};c(N,"Rect");var w=N;var P=class P extends w{constructor(){super(...arguments);this.type="bar"}};c(P,"Bar");var W=P;import{angleToRadian as U,ResizeDirection as H,Shape as et}from"@sunspots/core";var T=class T extends et{constructor(){super(...arguments);this.type="barcode";this.fill="#000000";this.resizable={directions:[H.Top,H.Bottom]};this.data=new Array(120).fill(null).map(()=>Math.floor(Math.random()*4)*1.5)}render(t){let{x:e,y:r,rotation:n,height:s}=this,o=0;t.save(),n&&(t.translate(e,r),t.rotate(U(n)));for(let a=0;a<this.data.length;a++){if(a%2===0){let l=o;t.fillRect(n?l:e+l,n?0:r,this.data[a],s)}o+=this.data[a]}t.restore()}renderShadow(t){let{x:e,y:r,rotation:n,height:s}=this;t.save(),n&&(t.translate(e,r),t.rotate(U(n))),t.fillRect(n?0:e,n?0:r,this.data.reduce((o,a)=>o+a),s),t.restore()}innerBox(){return{x:this.x,y:this.y,width:this.data.reduce((t,e)=>t+e),height:this.height}}boundingBox(){var n;let t=this.innerBox(),e=(n=this.strokeWidth)!=null?n:0,r=e/2;return t.x-=r,t.y-=r,t.width+=e,t.height+=e,t}toObject(){return super.toObject({content:this.content,codeType:this.codeType,readable:this.readable})}};c(T,"Barcode");var Y=T,Et=["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 z=class z extends w{constructor(){super(...arguments);this.type="box"}};c(z,"Box");var j=z;import{Shape as it}from"@sunspots/core";var I=class I extends it{constructor(){super(...arguments);this.type="circle"}render(t){let{x:e,y:r,radius:n,stroke:s,strokeWidth:o}=this;t.beginPath(),t.arc(e,r,n,0,Math.PI*2,!1),t.fill(),s&&(t.lineWidth=o!=null?o:1,t.stroke()),t.closePath()}innerBox(){return{x:this.x-this.radius,y:this.y-this.radius,width:this.radius*2,height:this.radius*2}}boundingBox(){var n;let t=this.innerBox(),e=(n=this.strokeWidth)!=null?n:0,r=e/2;return t.x-=r,t.y-=r,t.width+=e,t.height+=e,t}setWidth(t){this.width=t,this.radius=t/2}setHeight(t){this.height=t,this.radius=t/2}};c(I,"Circle");var X=I;import{Shape as rt}from"@sunspots/core";var O=class O extends rt{constructor(){super(...arguments);this.type="image";this.fill="#000000"}render(t){let{x:e,y:r,width:n,height:s,image:o}=this;t.drawImage(o,e,r,n,s)}renderShadow(t){let{x:e,y:r,width:n,height:s}=this;t.fillRect(e,r,n,s)}innerBox(){return{x:this.x,y:this.y,width:this.width,height:this.height}}boundingBox(){var n;let t=this.innerBox(),e=(n=this.strokeWidth)!=null?n:0,r=e/2;return t.x-=r,t.y-=r,t.width+=e,t.height+=e,t}};c(O,"Image");var G=O;import{angleToRadian as K,Color as nt,Shape as ot}from"@sunspots/core";var h=class h{constructor(i,t,e,r){this.version=i;this.errorCorrectionLevel=t;this.modules=[];this.isFunction=[];if(i<h.MIN_VERSION||i>h.MAX_VERSION)throw new RangeError("Version value out of range");if(r<-1||r>7)throw new RangeError("Mask value out of range");this.size=i*4+17;let n=[];for(let o=0;o<this.size;o++)n.push(!1);for(let o=0;o<this.size;o++)this.modules.push(n.slice()),this.isFunction.push(n.slice());this.drawFunctionPatterns();let s=this.addEccAndInterleave(e);if(this.drawCodewords(s),r==-1){let o=1e9;for(let a=0;a<8;a++){this.applyMask(a),this.drawFormatBits(a);let l=this.getPenaltyScore();l<o&&(r=a,o=l),this.applyMask(a)}}m(0<=r&&r<=7),this.mask=r,this.applyMask(r),this.drawFormatBits(r),this.isFunction=[]}static encodeText(i,t){let e=S.makeSegments(i);return h.encodeSegments(e,t)}static encodeBinary(i,t){let e=S.makeBytes(i);return h.encodeSegments([e],t)}static encodeSegments(i,t,e=1,r=40,n=-1,s=!0){if(!(h.MIN_VERSION<=e&&e<=r&&r<=h.MAX_VERSION)||n<-1||n>7)throw new RangeError("Invalid value");let o,a;for(o=e;;o++){let d=h.getNumDataCodewords(o,t)*8,y=S.getTotalBits(i,o);if(y<=d){a=y;break}if(o>=r)throw new RangeError("Data too long")}for(let d of[v.MEDIUM,v.QUARTILE,v.HIGH])s&&a<=h.getNumDataCodewords(o,d)*8&&(t=d);let l=[];for(let d of i){g(d.mode.modeBits,4,l),g(d.numChars,d.mode.numCharCountBits(o),l);for(let y of d.getData())l.push(y)}m(l.length==a);let f=h.getNumDataCodewords(o,t)*8;m(l.length<=f),g(0,Math.min(4,f-l.length),l),g(0,(8-l.length%8)%8,l),m(l.length%8==0);for(let d=236;l.length<f;d^=253)g(d,8,l);let p=[];for(;p.length*8<l.length;)p.push(0);return l.forEach((d,y)=>p[y>>>3]|=d<<7-(y&7)),new h(o,t,p,n)}getModule(i,t){return 0<=i&&i<this.size&&0<=t&&t<this.size&&this.modules[t][i]}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 i=this.getAlignmentPatternPositions(),t=i.length;for(let e=0;e<t;e++)for(let r=0;r<t;r++)e==0&&r==0||e==0&&r==t-1||e==t-1&&r==0||this.drawAlignmentPattern(i[e],i[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(i){let t=this.errorCorrectionLevel.formatBits<<3|i,e=t;for(let n=0;n<10;n++)e=e<<1^(e>>>9)*1335;let r=(t<<10|e)^21522;m(r>>>15==0);for(let n=0;n<=5;n++)this.setFunctionModule(8,n,E(r,n));this.setFunctionModule(8,7,E(r,6)),this.setFunctionModule(8,8,E(r,7)),this.setFunctionModule(7,8,E(r,8));for(let n=9;n<15;n++)this.setFunctionModule(14-n,8,E(r,n));for(let n=0;n<8;n++)this.setFunctionModule(this.size-1-n,8,E(r,n));for(let n=8;n<15;n++)this.setFunctionModule(8,this.size-15+n,E(r,n));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let i=this.version;for(let e=0;e<12;e++)i=i<<1^(i>>>11)*7973;let t=this.version<<12|i;m(t>>>18==0);for(let e=0;e<18;e++){let r=E(t,e),n=this.size-11+e%3,s=Math.floor(e/3);this.setFunctionModule(n,s,r),this.setFunctionModule(s,n,r)}}drawFinderPattern(i,t){for(let e=-4;e<=4;e++)for(let r=-4;r<=4;r++){let n=Math.max(Math.abs(r),Math.abs(e)),s=i+r,o=t+e;0<=s&&s<this.size&&0<=o&&o<this.size&&this.setFunctionModule(s,o,n!=2&&n!=4)}}drawAlignmentPattern(i,t){for(let e=-2;e<=2;e++)for(let r=-2;r<=2;r++)this.setFunctionModule(i+r,t+e,Math.max(Math.abs(r),Math.abs(e))!=1)}setFunctionModule(i,t,e){this.modules[t][i]=e,this.isFunction[t][i]=!0}addEccAndInterleave(i){let t=this.version,e=this.errorCorrectionLevel;if(i.length!=h.getNumDataCodewords(t,e))throw new RangeError("Invalid argument");let r=h.NUM_ERROR_CORRECTION_BLOCKS[e.ordinal][t],n=h.ECC_CODEWORDS_PER_BLOCK[e.ordinal][t],s=Math.floor(h.getNumRawDataModules(t)/8),o=r-s%r,a=Math.floor(s/r),l=[],f=h.reedSolomonComputeDivisor(n);for(let d=0,y=0;d<r;d++){let x=i.slice(y,y+a-n+(d<o?0:1));y+=x.length;let J=h.reedSolomonComputeRemainder(x,f);d<o&&x.push(0),l.push(x.concat(J))}let p=[];for(let d=0;d<l[0].length;d++)l.forEach((y,x)=>{(d!=a-n||x>=o)&&p.push(y[d])});return m(p.length==s),p}drawCodewords(i){if(i.length!=Math.floor(h.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let t=0;for(let e=this.size-1;e>=1;e-=2){e==6&&(e=5);for(let r=0;r<this.size;r++)for(let n=0;n<2;n++){let s=e-n,a=(e+1&2)==0?this.size-1-r:r;!this.isFunction[a][s]&&t<i.length*8&&(this.modules[a][s]=E(i[t>>>3],7-(t&7)),t++)}}m(t==i.length*8)}applyMask(i){if(i<0||i>7)throw new RangeError("Mask value out of range");for(let t=0;t<this.size;t++)for(let e=0;e<this.size;e++){let r;switch(i){case 0:r=(e+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=e%3==0;break;case 3:r=(e+t)%3==0;break;case 4:r=(Math.floor(e/3)+Math.floor(t/2))%2==0;break;case 5:r=e*t%2+e*t%3==0;break;case 6:r=(e*t%2+e*t%3)%2==0;break;case 7:r=((e+t)%2+e*t%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[t][e]&&r&&(this.modules[t][e]=!this.modules[t][e])}}getPenaltyScore(){let i=0;for(let n=0;n<this.size;n++){let s=!1,o=0,a=[0,0,0,0,0,0,0];for(let l=0;l<this.size;l++)this.modules[n][l]==s?(o++,o==5?i+=h.PENALTY_N1:o>5&&i++):(this.finderPenaltyAddHistory(o,a),s||(i+=this.finderPenaltyCountPatterns(a)*h.PENALTY_N3),s=this.modules[n][l],o=1);i+=this.finderPenaltyTerminateAndCount(s,o,a)*h.PENALTY_N3}for(let n=0;n<this.size;n++){let s=!1,o=0,a=[0,0,0,0,0,0,0];for(let l=0;l<this.size;l++)this.modules[l][n]==s?(o++,o==5?i+=h.PENALTY_N1:o>5&&i++):(this.finderPenaltyAddHistory(o,a),s||(i+=this.finderPenaltyCountPatterns(a)*h.PENALTY_N3),s=this.modules[l][n],o=1);i+=this.finderPenaltyTerminateAndCount(s,o,a)*h.PENALTY_N3}for(let n=0;n<this.size-1;n++)for(let s=0;s<this.size-1;s++){let o=this.modules[n][s];o==this.modules[n][s+1]&&o==this.modules[n+1][s]&&o==this.modules[n+1][s+1]&&(i+=h.PENALTY_N2)}let t=0;for(let n of this.modules)t=n.reduce((s,o)=>s+(o?1:0),t);let e=this.size*this.size,r=Math.ceil(Math.abs(t*20-e*10)/e)-1;return m(0<=r&&r<=9),i+=r*h.PENALTY_N4,m(0<=i&&i<=2568888),i}getAlignmentPatternPositions(){if(this.version==1)return[];{let i=Math.floor(this.version/7)+2,t=Math.floor((this.version*8+i*3+5)/(i*4-4))*2,e=[6];for(let r=this.size-7;e.length<i;r-=t)e.splice(1,0,r);return e}}static getNumRawDataModules(i){if(i<h.MIN_VERSION||i>h.MAX_VERSION)throw new RangeError("Version number out of range");let t=(16*i+128)*i+64;if(i>=2){let e=Math.floor(i/7)+2;t-=(25*e-10)*e-55,i>=7&&(t-=36)}return m(208<=t&&t<=29648),t}static getNumDataCodewords(i,t){return Math.floor(h.getNumRawDataModules(i)/8)-h.ECC_CODEWORDS_PER_BLOCK[t.ordinal][i]*h.NUM_ERROR_CORRECTION_BLOCKS[t.ordinal][i]}static reedSolomonComputeDivisor(i){if(i<1||i>255)throw new RangeError("Degree out of range");let t=[];for(let r=0;r<i-1;r++)t.push(0);t.push(1);let e=1;for(let r=0;r<i;r++){for(let n=0;n<t.length;n++)t[n]=h.reedSolomonMultiply(t[n],e),n+1<t.length&&(t[n]^=t[n+1]);e=h.reedSolomonMultiply(e,2)}return t}static reedSolomonComputeRemainder(i,t){let e=t.map(r=>0);for(let r of i){let n=r^e.shift();e.push(0),t.forEach((s,o)=>e[o]^=h.reedSolomonMultiply(s,n))}return e}static reedSolomonMultiply(i,t){if(i>>>8||t>>>8)throw new RangeError("Byte out of range");let e=0;for(let r=7;r>=0;r--)e=e<<1^(e>>>7)*285,e^=(t>>>r&1)*i;return m(e>>>8==0),e}finderPenaltyCountPatterns(i){let t=i[1];m(t<=this.size*3);let e=t>0&&i[2]==t&&i[3]==t*3&&i[4]==t&&i[5]==t;return(e&&i[0]>=t*4&&i[6]>=t?1:0)+(e&&i[6]>=t*4&&i[0]>=t?1:0)}finderPenaltyTerminateAndCount(i,t,e){return i&&(this.finderPenaltyAddHistory(t,e),t=0),t+=this.size,this.finderPenaltyAddHistory(t,e),this.finderPenaltyCountPatterns(e)}finderPenaltyAddHistory(i,t){t[0]==0&&(i+=this.size),t.pop(),t.unshift(i)}};c(h,"QrCode"),h.MIN_VERSION=1,h.MAX_VERSION=40,h.PENALTY_N1=3,h.PENALTY_N2=3,h.PENALTY_N3=40,h.PENALTY_N4=10,h.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]],h.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]];var B=h;function g(C,i,t){if(i<0||i>31||C>>>i)throw new RangeError("Value out of range");for(let e=i-1;e>=0;e--)t.push(C>>>e&1)}c(g,"appendBits");function E(C,i){return(C>>>i&1)!=0}c(E,"getBit");function m(C){if(!C)throw new Error("Assertion error")}c(m,"assert");var u=class u{constructor(i,t,e){this.mode=i;this.numChars=t;this.bitData=e;if(t<0)throw new RangeError("Invalid argument");this.bitData=e.slice()}static makeBytes(i){let t=[];for(let e of i)g(e,8,t);return new u(R.BYTE,i.length,t)}static makeNumeric(i){if(!u.isNumeric(i))throw new RangeError("String contains non-numeric characters");let t=[];for(let e=0;e<i.length;){let r=Math.min(i.length-e,3);g(parseInt(i.substring(e,e+r),10),r*3+1,t),e+=r}return new u(R.NUMERIC,i.length,t)}static makeAlphanumeric(i){if(!u.isAlphanumeric(i))throw new RangeError("String contains unencodable characters in alphanumeric mode");let t=[],e;for(e=0;e+2<=i.length;e+=2){let r=u.ALPHANUMERIC_CHARSET.indexOf(i.charAt(e))*45;r+=u.ALPHANUMERIC_CHARSET.indexOf(i.charAt(e+1)),g(r,11,t)}return e<i.length&&g(u.ALPHANUMERIC_CHARSET.indexOf(i.charAt(e)),6,t),new u(R.ALPHANUMERIC,i.length,t)}static makeSegments(i){return i==""?[]:u.isNumeric(i)?[u.makeNumeric(i)]:u.isAlphanumeric(i)?[u.makeAlphanumeric(i)]:[u.makeBytes(u.toUtf8ByteArray(i))]}static makeEci(i){let t=[];if(i<0)throw new RangeError("ECI assignment value out of range");if(i<128)g(i,8,t);else if(i<16384)g(2,2,t),g(i,14,t);else if(i<1e6)g(6,3,t),g(i,21,t);else throw new RangeError("ECI assignment value out of range");return new u(R.ECI,0,t)}static isNumeric(i){return u.NUMERIC_REGEX.test(i)}static isAlphanumeric(i){return u.ALPHANUMERIC_REGEX.test(i)}getData(){return this.bitData.slice()}static getTotalBits(i,t){let e=0;for(let r of i){let n=r.mode.numCharCountBits(t);if(r.numChars>=1<<n)return 1/0;e+=4+n+r.bitData.length}return e}static toUtf8ByteArray(i){i=encodeURI(i);let t=[];for(let e=0;e<i.length;e++)i.charAt(e)!="%"?t.push(i.charCodeAt(e)):(t.push(parseInt(i.substring(e+1,e+3),16)),e+=2);return t}};c(u,"QrSegment"),u.NUMERIC_REGEX=/^[0-9]*$/,u.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+./:-]*$/,u.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";var S=u,A=class A{constructor(i,t){this.ordinal=i;this.formatBits=t}};c(A,"QrCodeEcc"),A.LOW=new A(0,1),A.MEDIUM=new A(1,0),A.QUARTILE=new A(2,3),A.HIGH=new A(3,2);var v=A,b=class b{constructor(i,t){this.modeBits=i;this.numBitsCharCount=t}numCharCountBits(i){return this.numBitsCharCount[Math.floor((i+7)/17)]}};c(b,"QrSegmentMode"),b.NUMERIC=new b(1,[10,12,14]),b.ALPHANUMERIC=new b(2,[9,11,13]),b.BYTE=new b(4,[8,16,16]),b.KANJI=new b(8,[8,10,12]),b.ECI=new b(7,[0,0,0]);var R=b;var st={L:v.LOW,M:v.MEDIUM,Q:v.QUARTILE,H:v.HIGH};function L(C,i){return B.encodeText(C,st[i])}c(L,"createQrcode");var D=class D extends ot{constructor(t){super(t);this.config=t;this.type="qrcode";this.fill="#000000";this.resizable=!1;this.moduleSize=6;this.padding=1;this.qr=L(this.content,this.level);Object.assign(this,t)}get content(){return this.config.content}set content(t){this.config.content=t,this.qr=L(this.content,this.level)}get level(){var t;return(t=this.config.level)!=null?t:"M"}set level(t){this.config.level=t,this.qr=L(this.content,this.level)}render(t){let{x:e,y:r,rotation:n,qr:s,padding:o,moduleSize:a}=this;t.save(),n&&(t.translate(e,r),t.rotate(K(n)));for(let l=0;l<s.size;l++)for(let f=0;f<s.size;f++){let p=(f+o)*a,d=(l+o)*a;t.fillStyle=s.getModule(f,l)?this.fill:nt.Transparent,t.fillRect(n?p:e+p,n?d:r+d,a,a)}t.restore()}renderShadow(t){let{x:e,y:r,rotation:n,qr:s,padding:o,moduleSize:a}=this,l=(s.size+o*2)*a;t.save(),n&&(t.translate(e,r),t.rotate(K(n))),t.fillRect(n?0:e,n?0:r,l,l),t.restore()}innerBox(){let{x:t,y:e,qr:r,padding:n,moduleSize:s}=this,o=(r.size+n*2)*s;return{x:t,y:e,width:o,height:o}}boundingBox(){var n;let t=this.innerBox(),e=(n=this.strokeWidth)!=null?n:0,r=e/2;return t.x-=r,t.y-=r,t.width+=e,t.height+=e,t}toObject(){return super.toObject({content:this.content,moduleSize:this.moduleSize,level:this.level})}};c(D,"Qrcode");var q=D;import{angleToRadian as Q,Shape as at,withPixel as V}from"@sunspots/core";var k=class k extends at{constructor(t){super(t);this.type="text";this.resizable=!1;Object.assign(this,t)}get width(){var t;return(t=this.config.width)!=null?t:0}set width(t){this.config.width=t}get height(){var t;return(t=this.fontSize)!=null?t:0}set height(t){this.fontSize=t}render(t){let{x:e,y:r,rotation:n,content:s,fontSize:o,fontStyle:a,fontWeight:l,fontFamily:f,maxWidth:p,algin:d}=this;t.save(),n&&(t.translate(e,r),t.rotate(Q(n))),t.textAlign=d!=null?d:"left",t.textBaseline="top",t.font=[a,l,V(o),f!=null?f:"sans-serif"].filter(Boolean).join(" "),t.fillText(s,n?0:e,n?0:r,p),t.restore()}innerBox(){var t;return this.width=this.textWidth(),{x:this.x,y:this.y,width:(t=this.width)!=null?t:0,height:this.fontSize}}boundingBox(){return this.innerBox()}textWidth(){let t=this.stage.draftContext,{content:e,fontSize:r,fontStyle:n,fontWeight:s,fontFamily:o}=this;t.font=[n,s,V(r),o!=null?o:"sans-serif"].filter(Boolean).join(" ");let{width:a}=t.measureText(e);return a}renderShadow(t){let{x:e,y:r,fontSize:n,rotation:s}=this,o=this.textWidth();t.save(),s&&(t.translate(e,r),t.rotate(Q(s))),t.fillRect(s?0:e,s?0:r,o,n),t.restore(),this.width=o}setWidth(t){this.width=this.textWidth()}setHeight(t){this.height=t,this.fontSize=t}toObject(t={}){return Object.assign(super.toObject({content:this.content,fontSize:this.fontSize}),t)}};c(k,"Text");var M=k;import{dotToPixel as lt}from"@sunspots/core";var F=class F extends M{constructor(t){super(t);this.scale=1;Object.assign(this,t)}toObject(){return super.toObject({scale:this.scale,font:this.font})}};c(F,"TsplText");var $=F,ht=new Map([["TSS16.BF2",16],["TSS20.BF2",20],["TSS24.BF2",24],["TSS32.BF2",32]]);function te(C,i=1){return lt(ht.get(C)*i)}c(te,"calcFontSize");export{Et as BARCODE_TYPES,W as Bar,Y as Barcode,j as Box,X as Circle,G as Image,q as Qrcode,w as Rect,ht as TSPL_FONT_MAP,M as Text,$ as TsplText,te as calcFontSize};
|
|
1
|
+
var _=Object.defineProperty;var c=(f,i)=>_(f,"name",{value:i,configurable:!0});import{Shape as tt,angleToRadian as et}from"@sunspots/core";var N=class N extends tt{constructor(){super(...arguments);this.type="rect"}render(t){let{x:e,y:r,width:n,height:s,stroke:o,rotation:a}=this;t.save(),a&&(t.translate(e,r),t.rotate(et(a))),t.fillRect(a?0:e,a?0:r,n,s),o&&t.strokeRect(a?0:e,a?0:r,n,s),t.restore()}innerBox(){return{x:this.x,y:this.y,width:this.width,height:this.height}}boundingBox(){var n;let t=this.innerBox(),e=(n=this.strokeWidth)!=null?n:0,r=e/2;return t.x-=r,t.y-=r,t.width+=e,t.height+=e,t}};c(N,"Rect");var w=N;var P=class P extends w{constructor(){super(...arguments);this.type="bar"}};c(P,"Bar");var W=P;import{angleToRadian as U,ResizeDirection as H,Shape as it}from"@sunspots/core";var T=class T extends it{constructor(){super(...arguments);this.type="barcode";this.fill="#000000";this.resizable={directions:[H.Top,H.Bottom]};this.data=new Array(120).fill(null).map(()=>Math.floor(Math.random()*4)*1.5)}render(t){let{x:e,y:r,rotation:n,height:s}=this,o=0;t.save(),n&&(t.translate(e,r),t.rotate(U(n)));for(let a=0;a<this.data.length;a++){if(a%2===0){let l=o;t.fillRect(n?l:e+l,n?0:r,this.data[a],s)}o+=this.data[a]}t.restore()}renderShadow(t){let{x:e,y:r,rotation:n,height:s}=this;t.save(),n&&(t.translate(e,r),t.rotate(U(n))),t.fillRect(n?0:e,n?0:r,this.data.reduce((o,a)=>o+a),s),t.restore()}innerBox(){return{x:this.x,y:this.y,width:this.data.reduce((t,e)=>t+e),height:this.height}}boundingBox(){var n;let t=this.innerBox(),e=(n=this.strokeWidth)!=null?n:0,r=e/2;return t.x-=r,t.y-=r,t.width+=e,t.height+=e,t}toObject(){return super.toObject({content:this.content,codeType:this.codeType,readable:this.readable})}};c(T,"Barcode");var Y=T,Rt=["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 z=class z extends w{constructor(){super(...arguments);this.type="box"}};c(z,"Box");var j=z;import{Shape as rt}from"@sunspots/core";var I=class I extends rt{constructor(){super(...arguments);this.type="circle"}render(t){let{x:e,y:r,radius:n,stroke:s,strokeWidth:o}=this;t.beginPath(),t.arc(e,r,n,0,Math.PI*2,!1),t.fill(),s&&(t.lineWidth=o!=null?o:1,t.stroke()),t.closePath()}innerBox(){return{x:this.x-this.radius,y:this.y-this.radius,width:this.radius*2,height:this.radius*2}}boundingBox(){var n;let t=this.innerBox(),e=(n=this.strokeWidth)!=null?n:0,r=e/2;return t.x-=r,t.y-=r,t.width+=e,t.height+=e,t}setWidth(t){this.width=t,this.radius=t/2}setHeight(t){this.height=t,this.radius=t/2}};c(I,"Circle");var X=I;import{Shape as nt}from"@sunspots/core";var O=class O extends nt{constructor(){super(...arguments);this.type="image";this.fill="#000000"}render(t){let{x:e,y:r,width:n,height:s,image:o}=this;t.drawImage(o,e,r,n,s)}renderShadow(t){let{x:e,y:r,width:n,height:s}=this;t.fillRect(e,r,n,s)}innerBox(){return{x:this.x,y:this.y,width:this.width,height:this.height}}boundingBox(){var n;let t=this.innerBox(),e=(n=this.strokeWidth)!=null?n:0,r=e/2;return t.x-=r,t.y-=r,t.width+=e,t.height+=e,t}};c(O,"Image");var G=O;import{angleToRadian as K,Color as ot,Shape as st}from"@sunspots/core";var h=class h{constructor(i,t,e,r){this.version=i;this.errorCorrectionLevel=t;this.modules=[];this.isFunction=[];if(i<h.MIN_VERSION||i>h.MAX_VERSION)throw new RangeError("Version value out of range");if(r<-1||r>7)throw new RangeError("Mask value out of range");this.size=i*4+17;let n=[];for(let o=0;o<this.size;o++)n.push(!1);for(let o=0;o<this.size;o++)this.modules.push(n.slice()),this.isFunction.push(n.slice());this.drawFunctionPatterns();let s=this.addEccAndInterleave(e);if(this.drawCodewords(s),r==-1){let o=1e9;for(let a=0;a<8;a++){this.applyMask(a),this.drawFormatBits(a);let l=this.getPenaltyScore();l<o&&(r=a,o=l),this.applyMask(a)}}b(0<=r&&r<=7),this.mask=r,this.applyMask(r),this.drawFormatBits(r),this.isFunction=[]}static encodeText(i,t){let e=S.makeSegments(i);return h.encodeSegments(e,t)}static encodeBinary(i,t){let e=S.makeBytes(i);return h.encodeSegments([e],t)}static encodeSegments(i,t,e=1,r=40,n=-1,s=!0){if(!(h.MIN_VERSION<=e&&e<=r&&r<=h.MAX_VERSION)||n<-1||n>7)throw new RangeError("Invalid value");let o,a;for(o=e;;o++){let d=h.getNumDataCodewords(o,t)*8,m=S.getTotalBits(i,o);if(m<=d){a=m;break}if(o>=r)throw new RangeError("Data too long")}for(let d of[E.MEDIUM,E.QUARTILE,E.HIGH])s&&a<=h.getNumDataCodewords(o,d)*8&&(t=d);let l=[];for(let d of i){g(d.mode.modeBits,4,l),g(d.numChars,d.mode.numCharCountBits(o),l);for(let m of d.getData())l.push(m)}b(l.length==a);let p=h.getNumDataCodewords(o,t)*8;b(l.length<=p),g(0,Math.min(4,p-l.length),l),g(0,(8-l.length%8)%8,l),b(l.length%8==0);for(let d=236;l.length<p;d^=253)g(d,8,l);let y=[];for(;y.length*8<l.length;)y.push(0);return l.forEach((d,m)=>y[m>>>3]|=d<<7-(m&7)),new h(o,t,y,n)}getModule(i,t){return 0<=i&&i<this.size&&0<=t&&t<this.size&&this.modules[t][i]}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 i=this.getAlignmentPatternPositions(),t=i.length;for(let e=0;e<t;e++)for(let r=0;r<t;r++)e==0&&r==0||e==0&&r==t-1||e==t-1&&r==0||this.drawAlignmentPattern(i[e],i[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(i){let t=this.errorCorrectionLevel.formatBits<<3|i,e=t;for(let n=0;n<10;n++)e=e<<1^(e>>>9)*1335;let r=(t<<10|e)^21522;b(r>>>15==0);for(let n=0;n<=5;n++)this.setFunctionModule(8,n,v(r,n));this.setFunctionModule(8,7,v(r,6)),this.setFunctionModule(8,8,v(r,7)),this.setFunctionModule(7,8,v(r,8));for(let n=9;n<15;n++)this.setFunctionModule(14-n,8,v(r,n));for(let n=0;n<8;n++)this.setFunctionModule(this.size-1-n,8,v(r,n));for(let n=8;n<15;n++)this.setFunctionModule(8,this.size-15+n,v(r,n));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let i=this.version;for(let e=0;e<12;e++)i=i<<1^(i>>>11)*7973;let t=this.version<<12|i;b(t>>>18==0);for(let e=0;e<18;e++){let r=v(t,e),n=this.size-11+e%3,s=Math.floor(e/3);this.setFunctionModule(n,s,r),this.setFunctionModule(s,n,r)}}drawFinderPattern(i,t){for(let e=-4;e<=4;e++)for(let r=-4;r<=4;r++){let n=Math.max(Math.abs(r),Math.abs(e)),s=i+r,o=t+e;0<=s&&s<this.size&&0<=o&&o<this.size&&this.setFunctionModule(s,o,n!=2&&n!=4)}}drawAlignmentPattern(i,t){for(let e=-2;e<=2;e++)for(let r=-2;r<=2;r++)this.setFunctionModule(i+r,t+e,Math.max(Math.abs(r),Math.abs(e))!=1)}setFunctionModule(i,t,e){this.modules[t][i]=e,this.isFunction[t][i]=!0}addEccAndInterleave(i){let t=this.version,e=this.errorCorrectionLevel;if(i.length!=h.getNumDataCodewords(t,e))throw new RangeError("Invalid argument");let r=h.NUM_ERROR_CORRECTION_BLOCKS[e.ordinal][t],n=h.ECC_CODEWORDS_PER_BLOCK[e.ordinal][t],s=Math.floor(h.getNumRawDataModules(t)/8),o=r-s%r,a=Math.floor(s/r),l=[],p=h.reedSolomonComputeDivisor(n);for(let d=0,m=0;d<r;d++){let x=i.slice(m,m+a-n+(d<o?0:1));m+=x.length;let J=h.reedSolomonComputeRemainder(x,p);d<o&&x.push(0),l.push(x.concat(J))}let y=[];for(let d=0;d<l[0].length;d++)l.forEach((m,x)=>{(d!=a-n||x>=o)&&y.push(m[d])});return b(y.length==s),y}drawCodewords(i){if(i.length!=Math.floor(h.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let t=0;for(let e=this.size-1;e>=1;e-=2){e==6&&(e=5);for(let r=0;r<this.size;r++)for(let n=0;n<2;n++){let s=e-n,a=(e+1&2)==0?this.size-1-r:r;!this.isFunction[a][s]&&t<i.length*8&&(this.modules[a][s]=v(i[t>>>3],7-(t&7)),t++)}}b(t==i.length*8)}applyMask(i){if(i<0||i>7)throw new RangeError("Mask value out of range");for(let t=0;t<this.size;t++)for(let e=0;e<this.size;e++){let r;switch(i){case 0:r=(e+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=e%3==0;break;case 3:r=(e+t)%3==0;break;case 4:r=(Math.floor(e/3)+Math.floor(t/2))%2==0;break;case 5:r=e*t%2+e*t%3==0;break;case 6:r=(e*t%2+e*t%3)%2==0;break;case 7:r=((e+t)%2+e*t%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[t][e]&&r&&(this.modules[t][e]=!this.modules[t][e])}}getPenaltyScore(){let i=0;for(let n=0;n<this.size;n++){let s=!1,o=0,a=[0,0,0,0,0,0,0];for(let l=0;l<this.size;l++)this.modules[n][l]==s?(o++,o==5?i+=h.PENALTY_N1:o>5&&i++):(this.finderPenaltyAddHistory(o,a),s||(i+=this.finderPenaltyCountPatterns(a)*h.PENALTY_N3),s=this.modules[n][l],o=1);i+=this.finderPenaltyTerminateAndCount(s,o,a)*h.PENALTY_N3}for(let n=0;n<this.size;n++){let s=!1,o=0,a=[0,0,0,0,0,0,0];for(let l=0;l<this.size;l++)this.modules[l][n]==s?(o++,o==5?i+=h.PENALTY_N1:o>5&&i++):(this.finderPenaltyAddHistory(o,a),s||(i+=this.finderPenaltyCountPatterns(a)*h.PENALTY_N3),s=this.modules[l][n],o=1);i+=this.finderPenaltyTerminateAndCount(s,o,a)*h.PENALTY_N3}for(let n=0;n<this.size-1;n++)for(let s=0;s<this.size-1;s++){let o=this.modules[n][s];o==this.modules[n][s+1]&&o==this.modules[n+1][s]&&o==this.modules[n+1][s+1]&&(i+=h.PENALTY_N2)}let t=0;for(let n of this.modules)t=n.reduce((s,o)=>s+(o?1:0),t);let e=this.size*this.size,r=Math.ceil(Math.abs(t*20-e*10)/e)-1;return b(0<=r&&r<=9),i+=r*h.PENALTY_N4,b(0<=i&&i<=2568888),i}getAlignmentPatternPositions(){if(this.version==1)return[];{let i=Math.floor(this.version/7)+2,t=Math.floor((this.version*8+i*3+5)/(i*4-4))*2,e=[6];for(let r=this.size-7;e.length<i;r-=t)e.splice(1,0,r);return e}}static getNumRawDataModules(i){if(i<h.MIN_VERSION||i>h.MAX_VERSION)throw new RangeError("Version number out of range");let t=(16*i+128)*i+64;if(i>=2){let e=Math.floor(i/7)+2;t-=(25*e-10)*e-55,i>=7&&(t-=36)}return b(208<=t&&t<=29648),t}static getNumDataCodewords(i,t){return Math.floor(h.getNumRawDataModules(i)/8)-h.ECC_CODEWORDS_PER_BLOCK[t.ordinal][i]*h.NUM_ERROR_CORRECTION_BLOCKS[t.ordinal][i]}static reedSolomonComputeDivisor(i){if(i<1||i>255)throw new RangeError("Degree out of range");let t=[];for(let r=0;r<i-1;r++)t.push(0);t.push(1);let e=1;for(let r=0;r<i;r++){for(let n=0;n<t.length;n++)t[n]=h.reedSolomonMultiply(t[n],e),n+1<t.length&&(t[n]^=t[n+1]);e=h.reedSolomonMultiply(e,2)}return t}static reedSolomonComputeRemainder(i,t){let e=t.map(r=>0);for(let r of i){let n=r^e.shift();e.push(0),t.forEach((s,o)=>e[o]^=h.reedSolomonMultiply(s,n))}return e}static reedSolomonMultiply(i,t){if(i>>>8||t>>>8)throw new RangeError("Byte out of range");let e=0;for(let r=7;r>=0;r--)e=e<<1^(e>>>7)*285,e^=(t>>>r&1)*i;return b(e>>>8==0),e}finderPenaltyCountPatterns(i){let t=i[1];b(t<=this.size*3);let e=t>0&&i[2]==t&&i[3]==t*3&&i[4]==t&&i[5]==t;return(e&&i[0]>=t*4&&i[6]>=t?1:0)+(e&&i[6]>=t*4&&i[0]>=t?1:0)}finderPenaltyTerminateAndCount(i,t,e){return i&&(this.finderPenaltyAddHistory(t,e),t=0),t+=this.size,this.finderPenaltyAddHistory(t,e),this.finderPenaltyCountPatterns(e)}finderPenaltyAddHistory(i,t){t[0]==0&&(i+=this.size),t.pop(),t.unshift(i)}};c(h,"QrCode"),h.MIN_VERSION=1,h.MAX_VERSION=40,h.PENALTY_N1=3,h.PENALTY_N2=3,h.PENALTY_N3=40,h.PENALTY_N4=10,h.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]],h.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]];var B=h;function g(f,i,t){if(i<0||i>31||f>>>i)throw new RangeError("Value out of range");for(let e=i-1;e>=0;e--)t.push(f>>>e&1)}c(g,"appendBits");function v(f,i){return(f>>>i&1)!=0}c(v,"getBit");function b(f){if(!f)throw new Error("Assertion error")}c(b,"assert");var u=class u{constructor(i,t,e){this.mode=i;this.numChars=t;this.bitData=e;if(t<0)throw new RangeError("Invalid argument");this.bitData=e.slice()}static makeBytes(i){let t=[];for(let e of i)g(e,8,t);return new u(R.BYTE,i.length,t)}static makeNumeric(i){if(!u.isNumeric(i))throw new RangeError("String contains non-numeric characters");let t=[];for(let e=0;e<i.length;){let r=Math.min(i.length-e,3);g(parseInt(i.substring(e,e+r),10),r*3+1,t),e+=r}return new u(R.NUMERIC,i.length,t)}static makeAlphanumeric(i){if(!u.isAlphanumeric(i))throw new RangeError("String contains unencodable characters in alphanumeric mode");let t=[],e;for(e=0;e+2<=i.length;e+=2){let r=u.ALPHANUMERIC_CHARSET.indexOf(i.charAt(e))*45;r+=u.ALPHANUMERIC_CHARSET.indexOf(i.charAt(e+1)),g(r,11,t)}return e<i.length&&g(u.ALPHANUMERIC_CHARSET.indexOf(i.charAt(e)),6,t),new u(R.ALPHANUMERIC,i.length,t)}static makeSegments(i){return i==""?[]:u.isNumeric(i)?[u.makeNumeric(i)]:u.isAlphanumeric(i)?[u.makeAlphanumeric(i)]:[u.makeBytes(u.toUtf8ByteArray(i))]}static makeEci(i){let t=[];if(i<0)throw new RangeError("ECI assignment value out of range");if(i<128)g(i,8,t);else if(i<16384)g(2,2,t),g(i,14,t);else if(i<1e6)g(6,3,t),g(i,21,t);else throw new RangeError("ECI assignment value out of range");return new u(R.ECI,0,t)}static isNumeric(i){return u.NUMERIC_REGEX.test(i)}static isAlphanumeric(i){return u.ALPHANUMERIC_REGEX.test(i)}getData(){return this.bitData.slice()}static getTotalBits(i,t){let e=0;for(let r of i){let n=r.mode.numCharCountBits(t);if(r.numChars>=1<<n)return 1/0;e+=4+n+r.bitData.length}return e}static toUtf8ByteArray(i){i=encodeURI(i);let t=[];for(let e=0;e<i.length;e++)i.charAt(e)!="%"?t.push(i.charCodeAt(e)):(t.push(parseInt(i.substring(e+1,e+3),16)),e+=2);return t}};c(u,"QrSegment"),u.NUMERIC_REGEX=/^[0-9]*$/,u.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+./:-]*$/,u.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";var S=u,A=class A{constructor(i,t){this.ordinal=i;this.formatBits=t}};c(A,"QrCodeEcc"),A.LOW=new A(0,1),A.MEDIUM=new A(1,0),A.QUARTILE=new A(2,3),A.HIGH=new A(3,2);var E=A,C=class C{constructor(i,t){this.modeBits=i;this.numBitsCharCount=t}numCharCountBits(i){return this.numBitsCharCount[Math.floor((i+7)/17)]}};c(C,"QrSegmentMode"),C.NUMERIC=new C(1,[10,12,14]),C.ALPHANUMERIC=new C(2,[9,11,13]),C.BYTE=new C(4,[8,16,16]),C.KANJI=new C(8,[8,10,12]),C.ECI=new C(7,[0,0,0]);var R=C;var at={L:E.LOW,M:E.MEDIUM,Q:E.QUARTILE,H:E.HIGH};function F(f,i){return B.encodeText(f,at[i])}c(F,"createQrcode");var L=class L extends st{constructor(t){super(t);this.config=t;this.type="qrcode";this.fill="#000000";this.resizable=!1;this.moduleSize=6;this.padding=1;this.qr=F(this.content,this.level);Object.assign(this,t)}get content(){return this.config.content}set content(t){this.config.content=t,this.qr=F(this.content,this.level)}get level(){var t;return(t=this.config.level)!=null?t:"M"}set level(t){this.config.level=t,this.qr=F(this.content,this.level)}render(t){let{x:e,y:r,rotation:n,qr:s,padding:o,moduleSize:a}=this;t.save(),n&&(t.translate(e,r),t.rotate(K(n)));for(let l=0;l<s.size;l++)for(let p=0;p<s.size;p++){let y=(p+o)*a,d=(l+o)*a;t.fillStyle=s.getModule(p,l)?this.fill:ot.Transparent,t.fillRect(n?y:e+y,n?d:r+d,a,a)}t.restore()}renderShadow(t){let{x:e,y:r,rotation:n,qr:s,padding:o,moduleSize:a}=this,l=(s.size+o*2)*a;t.save(),n&&(t.translate(e,r),t.rotate(K(n))),t.fillRect(n?0:e,n?0:r,l,l),t.restore()}innerBox(){let{x:t,y:e,qr:r,padding:n,moduleSize:s}=this,o=(r.size+n*2)*s;return{x:t,y:e,width:o,height:o}}boundingBox(){var n;let t=this.innerBox(),e=(n=this.strokeWidth)!=null?n:0,r=e/2;return t.x-=r,t.y-=r,t.width+=e,t.height+=e,t}toObject(){return super.toObject({content:this.content,moduleSize:this.moduleSize,level:this.level})}};c(L,"Qrcode");var q=L;import{angleToRadian as Q,Shape as lt,withPixel as V}from"@sunspots/core";var D=class D extends lt{constructor(t){super(t);this.type="text";this.resizable=!1;Object.assign(this,t)}get width(){var t;return(t=this.config.width)!=null?t:0}set width(t){this.config.width=t}get height(){var t;return(t=this.fontSize)!=null?t:0}set height(t){this.fontSize=t}render(t){let{x:e,y:r,rotation:n,content:s,fontSize:o,fontStyle:a,fontWeight:l,fontFamily:p,maxWidth:y,algin:d}=this;t.save(),n&&(t.translate(e,r),t.rotate(Q(n))),t.textAlign=d!=null?d:"left",t.textBaseline="top",t.font=[a,l,V(o),p!=null?p:"sans-serif"].filter(Boolean).join(" "),t.fillText(s,n?0:e,n?0:r,y),t.restore()}innerBox(){var t;return this.width=this.textWidth(),{x:this.x,y:this.y,width:(t=this.width)!=null?t:0,height:this.fontSize}}boundingBox(){return this.innerBox()}textWidth(){let t=this.stage.draftContext,{content:e,fontSize:r,fontStyle:n,fontWeight:s,fontFamily:o}=this;t.font=[n,s,V(r),o!=null?o:"sans-serif"].filter(Boolean).join(" ");let{width:a}=t.measureText(e);return a}renderShadow(t){let{x:e,y:r,fontSize:n,rotation:s}=this,o=this.textWidth();t.save(),s&&(t.translate(e,r),t.rotate(Q(s))),t.fillRect(s?0:e,s?0:r,o,n),t.restore(),this.width=o}setWidth(t){this.width=this.textWidth()}setHeight(t){this.height=t,this.fontSize=t}toObject(t={}){return Object.assign(super.toObject({content:this.content,fontSize:this.fontSize}),t)}};c(D,"Text");var M=D;import{dotToPixel as ht}from"@sunspots/core";var k=class k extends M{constructor(t){super(t);this.scale=1;Object.assign(this,t)}toObject(){return super.toObject({scale:this.scale,font:this.font,wrap:this.wrap})}};c(k,"TsplText");var $=k,dt=new Map([["TSS16.BF2",16],["TSS20.BF2",20],["TSS24.BF2",24],["TSS32.BF2",32]]);function Z(f,i=1){return ht(dt.get(f)*i)}c(Z,"getTsplFontSize");var re=Z,ct=/[\u4E00-\u9FFF\u3000-\u303F\uFF00-\uFFEF]/;function ut(f){return ct.test(f)}c(ut,"isChineseOrPunctuation");function ne(f,i,t=1){let e=Z(i,t),r=f.split("").reduce((n,s)=>ut(s)?n+e:n+e/2,0);return{height:e,width:r}}c(ne,"measureTsplText");export{Rt as BARCODE_TYPES,W as Bar,Y as Barcode,j as Box,X as Circle,G as Image,q as Qrcode,w as Rect,dt as TSPL_FONT_SIZE_MAP,M as Text,$ as TsplText,re as calcFontSize,Z as getTsplFontSize,ne as measureTsplText};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sunspots/shapes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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.
|
|
29
|
+
"@sunspots/core": "0.2.0"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "6a5e1c9046609fdfb49792e0e5ef7cf8188cc2b0"
|
|
32
32
|
}
|