@sunspots/shapes 0.0.8 → 0.1.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 +14 -6
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _sunspots_core from '@sunspots/core';
|
|
2
|
+
import { ShapeConfig, Shape, Box as Box$1, ResizeDirection } from '@sunspots/core';
|
|
2
3
|
|
|
3
4
|
interface RectConfig extends ShapeConfig {
|
|
4
5
|
height: number;
|
|
@@ -23,6 +24,9 @@ interface BarcodeConfig extends ShapeConfig {
|
|
|
23
24
|
declare class Barcode extends Shape<BarcodeConfig> implements BarcodeConfig {
|
|
24
25
|
type: string;
|
|
25
26
|
fill: string;
|
|
27
|
+
resizable: {
|
|
28
|
+
directions: ResizeDirection[];
|
|
29
|
+
};
|
|
26
30
|
codeType: string;
|
|
27
31
|
content: string;
|
|
28
32
|
readable?: boolean;
|
|
@@ -41,6 +45,7 @@ declare class Barcode extends Shape<BarcodeConfig> implements BarcodeConfig {
|
|
|
41
45
|
fill: string | undefined;
|
|
42
46
|
stroke: string | undefined;
|
|
43
47
|
strokeWidth: number;
|
|
48
|
+
rotation: _sunspots_core.RightAngleRotation;
|
|
44
49
|
} & Record<string, unknown>;
|
|
45
50
|
}
|
|
46
51
|
declare const BARCODE_TYPES: string[];
|
|
@@ -77,10 +82,10 @@ declare class Image extends Shape<ImageConfig> implements ImageConfig {
|
|
|
77
82
|
boundingBox(): Box$1;
|
|
78
83
|
}
|
|
79
84
|
|
|
80
|
-
type
|
|
85
|
+
type QrCodeLevel = 'L' | 'M' | 'Q' | 'H';
|
|
81
86
|
interface QrcodeConfig extends ShapeConfig {
|
|
82
87
|
content: string;
|
|
83
|
-
level?:
|
|
88
|
+
level?: QrCodeLevel;
|
|
84
89
|
/** 单元格的宽度,1-10 */
|
|
85
90
|
moduleSize?: number;
|
|
86
91
|
}
|
|
@@ -91,8 +96,8 @@ declare class Qrcode extends Shape<QrcodeConfig> implements QrcodeConfig {
|
|
|
91
96
|
resizable: boolean;
|
|
92
97
|
get content(): string;
|
|
93
98
|
set content(value: string);
|
|
94
|
-
get level():
|
|
95
|
-
set level(value:
|
|
99
|
+
get level(): QrCodeLevel;
|
|
100
|
+
set level(value: QrCodeLevel);
|
|
96
101
|
moduleSize: number;
|
|
97
102
|
private padding;
|
|
98
103
|
private qr;
|
|
@@ -111,6 +116,7 @@ declare class Qrcode extends Shape<QrcodeConfig> implements QrcodeConfig {
|
|
|
111
116
|
fill: string | undefined;
|
|
112
117
|
stroke: string | undefined;
|
|
113
118
|
strokeWidth: number;
|
|
119
|
+
rotation: _sunspots_core.RightAngleRotation;
|
|
114
120
|
} & Record<string, unknown>;
|
|
115
121
|
}
|
|
116
122
|
|
|
@@ -155,6 +161,7 @@ declare class Text extends Shape<TextConfig> implements TextConfig {
|
|
|
155
161
|
fill: string | undefined;
|
|
156
162
|
stroke: string | undefined;
|
|
157
163
|
strokeWidth: number;
|
|
164
|
+
rotation: _sunspots_core.RightAngleRotation;
|
|
158
165
|
} & Record<string, unknown>;
|
|
159
166
|
}
|
|
160
167
|
|
|
@@ -176,6 +183,7 @@ declare class TsplText extends Text implements TsplTextConfig {
|
|
|
176
183
|
fill: string | undefined;
|
|
177
184
|
stroke: string | undefined;
|
|
178
185
|
strokeWidth: number;
|
|
186
|
+
rotation: _sunspots_core.RightAngleRotation;
|
|
179
187
|
} & Record<string, unknown>;
|
|
180
188
|
}
|
|
181
189
|
/**
|
|
@@ -183,4 +191,4 @@ declare class TsplText extends Text implements TsplTextConfig {
|
|
|
183
191
|
*/
|
|
184
192
|
declare const TSPL_FONT_MAP: Map<string, number>;
|
|
185
193
|
|
|
186
|
-
export { BARCODE_TYPES, Bar, Barcode, type BarcodeConfig, Box, Circle, Image, type ImageConfig, Qrcode, type QrcodeConfig, Rect, type RectConfig, TSPL_FONT_MAP, Text, type TextConfig, TsplText };
|
|
194
|
+
export { BARCODE_TYPES, Bar, Barcode, type BarcodeConfig, Box, Circle, Image, type ImageConfig, type QrCodeLevel, Qrcode, type QrcodeConfig, Rect, type RectConfig, TSPL_FONT_MAP, Text, type TextConfig, TsplText };
|
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,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};
|
|
1
|
+
var Z=Object.defineProperty;var c=(A,i)=>Z(A,"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 x=N;var P=class P extends x{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,At=["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 x{constructor(){super(...arguments);this.type="box"}};c(I,"Box");var j=I;import{Shape as it}from"@sunspots/core";var z=class z 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(z,"Circle");var X=z;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)}}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,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)}b(l.length==a);let f=h.getNumDataCodewords(o,t)*8;b(l.length<=f),g(0,Math.min(4,f-l.length),l),g(0,(8-l.length%8)%8,l),b(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;b(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;b(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 w=i.slice(y,y+a-n+(d<o?0:1));y+=w.length;let J=h.reedSolomonComputeRemainder(w,f);d<o&&w.push(0),l.push(w.concat(J))}let p=[];for(let d=0;d<l[0].length;d++)l.forEach((y,w)=>{(d!=a-n||w>=o)&&p.push(y[d])});return b(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++)}}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(A,i,t){if(i<0||i>31||A>>>i)throw new RangeError("Value out of range");for(let e=i-1;e>=0;e--)t.push(A>>>e&1)}c(g,"appendBits");function E(A,i){return(A>>>i&1)!=0}c(E,"getBit");function b(A){if(!A)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,C=class C{constructor(i,t){this.ordinal=i;this.formatBits=t}};c(C,"QrCodeEcc"),C.LOW=new C(0,1),C.MEDIUM=new C(1,0),C.QUARTILE=new C(2,3),C.HIGH=new C(3,2);var v=C,m=class m{constructor(i,t){this.modeBits=i;this.numBitsCharCount=t}numCharCountBits(i){return this.numBitsCharCount[Math.floor((i+7)/17)]}};c(m,"QrSegmentMode"),m.NUMERIC=new m(1,[10,12,14]),m.ALPHANUMERIC=new m(2,[9,11,13]),m.BYTE=new m(4,[8,16,16]),m.KANJI=new m(8,[8,10,12]),m.ECI=new m(7,[0,0,0]);var R=m;var st={L:v.LOW,M:v.MEDIUM,Q:v.QUARTILE,H:v.HIGH};function L(A,i){return B.encodeText(A,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;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,Jt=new Map([["TSS16.BF2",16],["TSS20.BF2",20],["TSS24.BF2",24],["TSS32.BF2",32]]);export{At as BARCODE_TYPES,W as Bar,Y as Barcode,j as Box,X as Circle,G as Image,q as Qrcode,x as Rect,Jt as TSPL_FONT_MAP,M as Text,$ as TsplText};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sunspots/shapes",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.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.0
|
|
29
|
+
"@sunspots/core": "0.1.0"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "1abe322b4ed0bfd15e92931d44a5c2350bdb986e"
|
|
32
32
|
}
|