@sunspots/shapes 0.0.1
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 +169 -0
- package/dist/index.mjs +1 -0
- package/package.json +32 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { ShapeConfig, Shape, Box as Box$1 } from '@sunspots/core';
|
|
2
|
+
|
|
3
|
+
interface RectConfig extends ShapeConfig {
|
|
4
|
+
height: number;
|
|
5
|
+
width: number;
|
|
6
|
+
}
|
|
7
|
+
declare class Rect extends Shape<RectConfig> implements RectConfig {
|
|
8
|
+
type: string;
|
|
9
|
+
render(context: CanvasRenderingContext2D): void;
|
|
10
|
+
innerBox(): Box$1;
|
|
11
|
+
boundingBox(): Box$1;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare class Bar extends Rect {
|
|
15
|
+
type: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface TsplBarcodeConfig extends ShapeConfig {
|
|
19
|
+
content: string;
|
|
20
|
+
codeType: string;
|
|
21
|
+
}
|
|
22
|
+
declare class TsplBarcode extends Shape<TsplBarcodeConfig> implements TsplBarcodeConfig {
|
|
23
|
+
type: string;
|
|
24
|
+
fill: string;
|
|
25
|
+
codeType: string;
|
|
26
|
+
content: string;
|
|
27
|
+
private data;
|
|
28
|
+
render(context: CanvasRenderingContext2D): void;
|
|
29
|
+
renderShadow(context: CanvasRenderingContext2D): void;
|
|
30
|
+
innerBox(): Box$1;
|
|
31
|
+
boundingBox(): Box$1;
|
|
32
|
+
toObject(): {
|
|
33
|
+
type: string;
|
|
34
|
+
index: number;
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
fill: string | undefined;
|
|
40
|
+
stroke: string | undefined;
|
|
41
|
+
strokeWidth: number;
|
|
42
|
+
} & Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
declare const TSPL_BARCODE_TYPES: string[];
|
|
45
|
+
|
|
46
|
+
declare class Box extends Rect {
|
|
47
|
+
type: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface CircleConfig extends ShapeConfig {
|
|
51
|
+
radius: number;
|
|
52
|
+
}
|
|
53
|
+
declare class Circle extends Shape<CircleConfig> implements CircleConfig {
|
|
54
|
+
type: string;
|
|
55
|
+
radius: number;
|
|
56
|
+
render(context: CanvasRenderingContext2D): void;
|
|
57
|
+
innerBox(): Box$1;
|
|
58
|
+
boundingBox(): Box$1;
|
|
59
|
+
setWidth(width: number): void;
|
|
60
|
+
setHeight(height: number): void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
type Level = 'L' | 'M' | 'Q' | 'H';
|
|
64
|
+
interface QrcodeConfig extends ShapeConfig {
|
|
65
|
+
content: string;
|
|
66
|
+
level?: Level;
|
|
67
|
+
/** 单元格的宽度,1-10 */
|
|
68
|
+
moduleSize?: number;
|
|
69
|
+
}
|
|
70
|
+
declare class Qrcode extends Shape<QrcodeConfig> implements QrcodeConfig {
|
|
71
|
+
protected config: QrcodeConfig;
|
|
72
|
+
type: string;
|
|
73
|
+
fill: string;
|
|
74
|
+
resizable: boolean;
|
|
75
|
+
get content(): string;
|
|
76
|
+
set content(value: string);
|
|
77
|
+
get level(): Level;
|
|
78
|
+
set level(value: Level);
|
|
79
|
+
moduleSize: number;
|
|
80
|
+
private padding;
|
|
81
|
+
private qr;
|
|
82
|
+
constructor(config: QrcodeConfig);
|
|
83
|
+
render(context: CanvasRenderingContext2D): void;
|
|
84
|
+
renderShadow(context: CanvasRenderingContext2D): void;
|
|
85
|
+
innerBox(): Box$1;
|
|
86
|
+
boundingBox(): Box$1;
|
|
87
|
+
toObject(): {
|
|
88
|
+
type: string;
|
|
89
|
+
index: number;
|
|
90
|
+
x: number;
|
|
91
|
+
y: number;
|
|
92
|
+
width: number;
|
|
93
|
+
height: number;
|
|
94
|
+
fill: string | undefined;
|
|
95
|
+
stroke: string | undefined;
|
|
96
|
+
strokeWidth: number;
|
|
97
|
+
} & Record<string, unknown>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface TextConfig extends ShapeConfig {
|
|
101
|
+
content: string;
|
|
102
|
+
fontSize: number;
|
|
103
|
+
fontStyle?: string;
|
|
104
|
+
fontWeight?: string;
|
|
105
|
+
fontFamily?: string;
|
|
106
|
+
maxWidth?: number;
|
|
107
|
+
algin?: CanvasTextAlign;
|
|
108
|
+
}
|
|
109
|
+
declare class Text extends Shape<TextConfig> implements TextConfig {
|
|
110
|
+
type: string;
|
|
111
|
+
fontSize: number;
|
|
112
|
+
fontStyle?: string | undefined;
|
|
113
|
+
fontWeight?: string | undefined;
|
|
114
|
+
fontFamily?: string | undefined;
|
|
115
|
+
content: string;
|
|
116
|
+
maxWidth?: number | undefined;
|
|
117
|
+
algin?: CanvasTextAlign | undefined;
|
|
118
|
+
resizable: boolean;
|
|
119
|
+
get width(): number;
|
|
120
|
+
set width(value: number);
|
|
121
|
+
get height(): number;
|
|
122
|
+
set height(value: number);
|
|
123
|
+
constructor(config: TextConfig);
|
|
124
|
+
render(context: CanvasRenderingContext2D): void;
|
|
125
|
+
innerBox(): Box$1;
|
|
126
|
+
boundingBox(): Box$1;
|
|
127
|
+
private textWidth;
|
|
128
|
+
renderShadow(context: CanvasRenderingContext2D): void;
|
|
129
|
+
setWidth(_width: number): void;
|
|
130
|
+
setHeight(height: number): void;
|
|
131
|
+
toObject(merge?: Record<string, unknown>): {
|
|
132
|
+
type: string;
|
|
133
|
+
index: number;
|
|
134
|
+
x: number;
|
|
135
|
+
y: number;
|
|
136
|
+
width: number;
|
|
137
|
+
height: number;
|
|
138
|
+
fill: string | undefined;
|
|
139
|
+
stroke: string | undefined;
|
|
140
|
+
strokeWidth: number;
|
|
141
|
+
} & Record<string, unknown>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface TsplTextConfig extends TextConfig {
|
|
145
|
+
font?: string;
|
|
146
|
+
scale?: number;
|
|
147
|
+
}
|
|
148
|
+
declare class TsplText extends Text implements TsplTextConfig {
|
|
149
|
+
font?: string;
|
|
150
|
+
scale: number;
|
|
151
|
+
constructor(config: TsplTextConfig);
|
|
152
|
+
toObject(): {
|
|
153
|
+
type: string;
|
|
154
|
+
index: number;
|
|
155
|
+
x: number;
|
|
156
|
+
y: number;
|
|
157
|
+
width: number;
|
|
158
|
+
height: number;
|
|
159
|
+
fill: string | undefined;
|
|
160
|
+
stroke: string | undefined;
|
|
161
|
+
strokeWidth: number;
|
|
162
|
+
} & Record<string, unknown>;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* font => fontSize (px)
|
|
166
|
+
*/
|
|
167
|
+
declare const TSPL_FONT_MAP: Map<string, number>;
|
|
168
|
+
|
|
169
|
+
export { Bar, Box, Circle, Qrcode, type QrcodeConfig, Rect, type RectConfig, TSPL_BARCODE_TYPES, TSPL_FONT_MAP, Text, type TextConfig, TsplBarcode, type TsplBarcodeConfig, TsplText };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var X=Object.defineProperty;var g=(E,f)=>X(E,"name",{value:f,configurable:!0});import{Shape as G}from"@sunspots/core";var N=class N extends G{constructor(){super(...arguments);this.type="rect"}render(n){let{x:h,y:a,width:u,height:s,stroke:l}=this;n.fillRect(h,a,u,s),l&&n.strokeRect(h,a,u,s)}innerBox(){return{x:this.x,y:this.y,width:this.width,height:this.height}}boundingBox(){var u;let n=this.innerBox(),h=(u=this.strokeWidth)!=null?u:0,a=h/2;return n.x-=a,n.y-=a,n.width+=h,n.height+=h,n}};g(N,"Rect");var R=N;var B=class B extends R{constructor(){super(...arguments);this.type="bar"}};g(B,"Bar");var k=B;import{Shape as K}from"@sunspots/core";var P=class P extends K{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:h,y:a,height:u}=this,s=0;for(let l=0;l<this.data.length;l++)l%2===0&&n.fillRect(h+s,a,this.data[l],u),s+=this.data[l]}renderShadow(n){let{x:h,y:a,height:u}=this;n.fillRect(h,a,this.data.reduce((s,l)=>s+l),u)}innerBox(){return{x:this.x,y:this.y,width:this.data.reduce((n,h)=>n+h),height:this.height}}boundingBox(){var u;let n=this.innerBox(),h=(u=this.strokeWidth)!=null?u:0,a=h/2;return n.x-=a,n.y-=a,n.width+=h,n.height+=h,n}toObject(){return super.toObject({content:this.content,codeType:this.codeType})}};g(P,"TsplBarcode");var F=P,ct=["128","128M","EAN128","EAN128M","25","25C","25S","25I","39","39C","93","EAN13","EAN13+2","EAN13+5","EAN8","EAN8+2","EAN8+5","CODA","POST","UPCA","UPCA+2","UPA+5","UPCE","UPCE+2","UPE+5","MSI","MSIC","PLESSEY","CPOST","ITF14","EAN14","11","TELEPEN","TELEPENN","PLANET","CODE49","DPI","DPL","LOGMARS"];var T=class T extends R{constructor(){super(...arguments);this.type="box"}};g(T,"Box");var U=T;import{Shape as V}from"@sunspots/core";var z=class z extends V{constructor(){super(...arguments);this.type="circle"}render(n){let{x:h,y:a,radius:u,stroke:s,strokeWidth:l}=this;n.beginPath(),n.arc(h,a,u,0,Math.PI*2,!1),n.fill(),s&&(n.lineWidth=l!=null?l: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 u;let n=this.innerBox(),h=(u=this.strokeWidth)!=null?u:0,a=h/2;return n.x-=a,n.y-=a,n.width+=h,n.height+=h,n}setWidth(n){this.width=n,this.radius=n/2}setHeight(n){this.height=n,this.radius=n/2}};g(z,"Circle");var W=z;import{Color as $,Shape as J}from"@sunspots/core";var x;(u=>{let s=class s{constructor(t,i,e,o){this.version=t;this.errorCorrectionLevel=i;this.modules=[];this.isFunction=[];if(t<s.MIN_VERSION||t>s.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 r=[];for(let d=0;d<this.size;d++)r.push(!1);for(let d=0;d<this.size;d++)this.modules.push(r.slice()),this.isFunction.push(r.slice());this.drawFunctionPatterns();let c=this.addEccAndInterleave(e);if(this.drawCodewords(c),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)}}h(o>=0&&o<=7),this.mask=o,this.applyMask(o),this.drawFormatBits(o),this.isFunction=[]}static encodeText(t,i){let e=u.QrSegment.makeSegments(t);return s.encodeSegments(e,i)}static encodeBinary(t,i){let e=u.QrSegment.makeBytes(t);return s.encodeSegments([e],i)}static encodeSegments(t,i,e=1,o=40,r=-1,c=!0){if(!(s.MIN_VERSION<=e&&e<=o&&o<=s.MAX_VERSION)||r<-1||r>7)throw new RangeError("Invalid value");let d,m;for(d=e;;d++){let b=s.getNumDataCodewords(d,i)*8,C=a.getTotalBits(t,d);if(C<=b){m=C;break}if(d>=o)throw new RangeError("Data too long")}for(let b of[s.Ecc.MEDIUM,s.Ecc.QUARTILE,s.Ecc.HIGH])c&&m<=s.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 C of b.getData())p.push(C)}h(p.length==m);let M=s.getNumDataCodewords(d,i)*8;h(p.length<=M),f(0,Math.min(4,M-p.length),p),f(0,(8-p.length%8)%8,p),h(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,C)=>v[C>>>3]|=b<<7-(C&7)),new s(d,i,v,r)}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 r=0;r<10;r++)e=e<<1^(e>>>9)*1335;let o=(i<<10|e)^21522;h(o>>>15==0);for(let r=0;r<=5;r++)this.setFunctionModule(8,r,n(o,r));this.setFunctionModule(8,7,n(o,6)),this.setFunctionModule(8,8,n(o,7)),this.setFunctionModule(7,8,n(o,8));for(let r=9;r<15;r++)this.setFunctionModule(14-r,8,n(o,r));for(let r=0;r<8;r++)this.setFunctionModule(this.size-1-r,8,n(o,r));for(let r=8;r<15;r++)this.setFunctionModule(8,this.size-15+r,n(o,r));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;h(i>>>18==0);for(let e=0;e<18;e++){let o=n(i,e),r=this.size-11+e%3,c=Math.floor(e/3);this.setFunctionModule(r,c,o),this.setFunctionModule(c,r,o)}}drawFinderPattern(t,i){for(let e=-4;e<=4;e++)for(let o=-4;o<=4;o++){let r=Math.max(Math.abs(o),Math.abs(e)),c=t+o,d=i+e;c>=0&&c<this.size&&d>=0&&d<this.size&&this.setFunctionModule(c,d,r!=2&&r!=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!=s.getNumDataCodewords(i,e))throw new RangeError("Invalid argument");let o=s.NUM_ERROR_CORRECTION_BLOCKS[e.ordinal][i],r=s.ECC_CODEWORDS_PER_BLOCK[e.ordinal][i],c=Math.floor(s.getNumRawDataModules(i)/8),d=o-c%o,m=Math.floor(c/o),p=[],M=s.reedSolomonComputeDivisor(r);for(let b=0,C=0;b<o;b++){let w=t.slice(C,C+m-r+(b<d?0:1));C+=w.length;let j=s.reedSolomonComputeRemainder(w,M);b<d&&w.push(0),p.push(w.concat(j))}let v=[];for(let b=0;b<p[0].length;b++)p.forEach((C,w)=>{(b!=m-r||w>=d)&&v.push(C[b])});return h(v.length==c),v}drawCodewords(t){if(t.length!=Math.floor(s.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 r=0;r<2;r++){let c=e-r,m=(e+1&2)==0?this.size-1-o:o;!this.isFunction[m][c]&&i<t.length*8&&(this.modules[m][c]=n(t[i>>>3],7-(i&7)),i++)}}h(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 r=0;r<this.size;r++){let c=!1,d=0,m=[0,0,0,0,0,0,0];for(let p=0;p<this.size;p++)this.modules[r][p]==c?(d++,d==5?t+=s.PENALTY_N1:d>5&&t++):(this.finderPenaltyAddHistory(d,m),c||(t+=this.finderPenaltyCountPatterns(m)*s.PENALTY_N3),c=this.modules[r][p],d=1);t+=this.finderPenaltyTerminateAndCount(c,d,m)*s.PENALTY_N3}for(let r=0;r<this.size;r++){let c=!1,d=0,m=[0,0,0,0,0,0,0];for(let p=0;p<this.size;p++)this.modules[p][r]==c?(d++,d==5?t+=s.PENALTY_N1:d>5&&t++):(this.finderPenaltyAddHistory(d,m),c||(t+=this.finderPenaltyCountPatterns(m)*s.PENALTY_N3),c=this.modules[p][r],d=1);t+=this.finderPenaltyTerminateAndCount(c,d,m)*s.PENALTY_N3}for(let r=0;r<this.size-1;r++)for(let c=0;c<this.size-1;c++){let d=this.modules[r][c];d==this.modules[r][c+1]&&d==this.modules[r+1][c]&&d==this.modules[r+1][c+1]&&(t+=s.PENALTY_N2)}let i=0;for(let r of this.modules)i=r.reduce((c,d)=>c+(d?1:0),i);let e=this.size*this.size,o=Math.ceil(Math.abs(i*20-e*10)/e)-1;return h(o>=0&&o<=9),t+=o*s.PENALTY_N4,h(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<s.MIN_VERSION||t>s.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 h(i>=208&&i<=29648),i}static getNumDataCodewords(t,i){return Math.floor(s.getNumRawDataModules(t)/8)-s.ECC_CODEWORDS_PER_BLOCK[i.ordinal][t]*s.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 r=0;r<i.length;r++)i[r]=s.reedSolomonMultiply(i[r],e),r+1<i.length&&(i[r]^=i[r+1]);e=s.reedSolomonMultiply(e,2)}return i}static reedSolomonComputeRemainder(t,i){let e=i.map(o=>0);for(let o of t){let r=o^e.shift();e.push(0),i.forEach((c,d)=>e[d]^=s.reedSolomonMultiply(c,r))}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 h(e>>>8==0),e}finderPenaltyCountPatterns(t){let i=t[1];h(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(s,"QrCode"),s.MIN_VERSION=1,s.MAX_VERSION=40,s.PENALTY_N1=3,s.PENALTY_N2=3,s.PENALTY_N3=40,s.PENALTY_N4=10,s.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]],s.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 E=s;u.QrCode=s;function f(y,t,i){if(t<0||t>31||y>>>t)throw new RangeError("Value out of range");for(let e=t-1;e>=0;e--)i.push(y>>>e&1)}g(f,"appendBits");function n(y,t){return(y>>>t&1)!=0}g(n,"getBit");function h(y){if(!y)throw new Error("Assertion error")}g(h,"assert");let l=class l{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 l(l.Mode.BYTE,t.length,i)}static makeNumeric(t){if(!l.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 l(l.Mode.NUMERIC,t.length,i)}static makeAlphanumeric(t){if(!l.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=l.ALPHANUMERIC_CHARSET.indexOf(t.charAt(e))*45;o+=l.ALPHANUMERIC_CHARSET.indexOf(t.charAt(e+1)),f(o,11,i)}return e<t.length&&f(l.ALPHANUMERIC_CHARSET.indexOf(t.charAt(e)),6,i),new l(l.Mode.ALPHANUMERIC,t.length,i)}static makeSegments(t){return t==""?[]:l.isNumeric(t)?[l.makeNumeric(t)]:l.isAlphanumeric(t)?[l.makeAlphanumeric(t)]:[l.makeBytes(l.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 l(l.Mode.ECI,0,i)}static isNumeric(t){return l.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return l.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(t,i){let e=0;for(let o of t){let r=o.mode.numCharCountBits(i);if(o.numChars>=1<<r)return 1/0;e+=4+r+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(l,"QrSegment"),l.NUMERIC_REGEX=/^[0-9]*$/,l.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,l.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let a=l;u.QrSegment=l})(x||(x={}));(f=>{let E;(h=>{let a=class a{constructor(s,l){this.ordinal=s;this.formatBits=l}};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;h.Ecc=a})(E=f.QrCode||(f.QrCode={}))})(x||(x={}));(f=>{let E;(h=>{let a=class a{constructor(s,l){this.modeBits=s;this.numBitsCharCount=l}numCharCountBits(s){return this.numBitsCharCount[Math.floor((s+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;h.Mode=a})(E=f.QrSegment||(f.QrSegment={}))})(x||(x={}));var S=x;var Z={L:S.QrCode.Ecc.LOW,M:S.QrCode.Ecc.MEDIUM,Q:S.QrCode.Ecc.QUARTILE,H:S.QrCode.Ecc.HIGH};function I(E,f){return S.QrCode.encodeText(E,Z[f])}g(I,"createQr");var O=class O extends J{constructor(n){super(n);this.config=n;this.type="qrcode";this.fill="#000000";this.resizable=!1;this.moduleSize=6;this.padding=1;this.qr=I(this.content,this.level);Object.assign(this,n)}get content(){return this.config.content}set content(n){this.config.content=n,this.qr=I(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=I(this.content,this.level)}render(n){let{x:h,y:a,qr:u,padding:s,moduleSize:l}=this;for(let y=0;y<u.size;y++)for(let t=0;t<u.size;t++)n.fillStyle=u.getModule(t,y)?"#000000":$.Transparent,n.fillRect(h+(t+s)*l,a+(y+s)*l,l,l)}renderShadow(n){let{x:h,y:a,qr:u,padding:s,moduleSize:l}=this,y=(u.size+s*2)*l;n.fillRect(h,a,y,y)}innerBox(){let{x:n,y:h,qr:a,padding:u,moduleSize:s}=this,l=(a.size+u*2)*s;return{x:n,y:h,width:l,height:l}}boundingBox(){var u;let n=this.innerBox(),h=(u=this.strokeWidth)!=null?u:0,a=h/2;return n.x-=a,n.y-=a,n.width+=h,n.height+=h,n}toObject(){return super.toObject({content:this.content,moduleSize:this.moduleSize,level:this.level})}};g(O,"Qrcode");var Q=O;import{Shape as q,withPixel as H}from"@sunspots/core";var L=class L extends q{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){}render(n){let{x:h,y:a,content:u,fontSize:s,fontStyle:l,fontWeight:y,fontFamily:t,maxWidth:i,algin:e}=this;n.textAlign=e!=null?e:"left",n.textBaseline="top",n.font=[l,y,H(s),t!=null?t:"sans-serif"].filter(Boolean).join(" "),n.fillText(u,h,a,i)}innerBox(){var n;return{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:h,fontSize:a,fontStyle:u,fontWeight:s,fontFamily:l}=this;n.font=[u,s,H(a),l!=null?l:"sans-serif"].filter(Boolean).join(" ");let{width:y}=n.measureText(h);return y}renderShadow(n){let{x:h,y:a,fontSize:u}=this,s=this.textWidth();n.fillRect(h,a,s,u),this.width=s}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(L,"Text");var A=L;var D=class D extends A{constructor(n){super(n);this.scale=1;Object.assign(this,n)}toObject(){return super.toObject({scale:this.scale,font:this.font})}};g(D,"TsplText");var Y=D,kt=new Map([["TSS16.BF2",16],["TSS24.BF2",24],["TSS32.BF2",32]]);export{k as Bar,U as Box,W as Circle,Q as Qrcode,R as Rect,ct as TSPL_BARCODE_TYPES,kt as TSPL_FONT_MAP,A as Text,F as TsplBarcode,Y as TsplText};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sunspots/shapes",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.mts",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.mts",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
|
+
"require": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"dev": "tsup --watch",
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"publish:dev": "yalc publish ."
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@sunspots/core": "0.0.1"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "559cddb71cb7b7d7065ea79e4da732d6a2140fa4"
|
|
32
|
+
}
|