diff --git a/.gitignore b/.gitignore index d3ec3be..4b81f11 100644 --- a/.gitignore +++ b/.gitignore @@ -41,7 +41,6 @@ build/Release # Dependency directories node_modules/ jspm_packages/ -dist/ # TypeScript v1 declaration files typings/ @@ -82,7 +81,6 @@ typings/ # Nuxt.js build / generate output .nuxt -dist # Gatsby files .cache/ diff --git a/dist/components/QR25D.d.ts b/dist/components/QR25D.d.ts new file mode 100644 index 0000000..318c279 --- /dev/null +++ b/dist/components/QR25D.d.ts @@ -0,0 +1,10 @@ +import { RendererProps, SFC } from './RendererWrapper'; +interface QR25DProps extends RendererProps { + height?: number; + posHeight?: number; + topColor?: string; + leftColor?: string; + rightColor?: string; +} +declare const _default: SFC; +export default _default; diff --git a/dist/components/QRBubble.d.ts b/dist/components/QRBubble.d.ts new file mode 100644 index 0000000..37fc5cc --- /dev/null +++ b/dist/components/QRBubble.d.ts @@ -0,0 +1,7 @@ +import { RendererProps, SFC } from './RendererWrapper'; +interface QRBubbleProps extends RendererProps { + circleColor?: string; + posColor?: string; +} +declare const _default: SFC; +export default _default; diff --git a/dist/components/QRDsj.d.ts b/dist/components/QRDsj.d.ts new file mode 100644 index 0000000..cec6614 --- /dev/null +++ b/dist/components/QRDsj.d.ts @@ -0,0 +1,13 @@ +import { RendererProps, SFC } from './RendererWrapper'; +declare enum Type { + Rect = "rect", + Dsj = "dsj" +} +interface QRDsjProps extends RendererProps { + scale?: number; + crossWidth?: number; + posWidth?: number; + posType?: Type | string; +} +declare const _default: SFC; +export default _default; diff --git a/dist/components/QRFunc.d.ts b/dist/components/QRFunc.d.ts new file mode 100644 index 0000000..ca5ac1e --- /dev/null +++ b/dist/components/QRFunc.d.ts @@ -0,0 +1,21 @@ +import { RendererProps, SFC } from './RendererWrapper'; +declare enum Type { + Rect = "rect", + Round = "round" +} +declare enum PosType { + Rect = "rect", + Round = "round", + Planet = "planet", + RoundRect = "roundRect" +} +interface QRFuncProps extends RendererProps { + funcType?: string; + type?: Type | string; + posType?: PosType | string; + otherColor1?: string; + otherColor2?: string; + posColor?: string; +} +declare const _default: SFC; +export default _default; diff --git a/dist/components/QRImage.d.ts b/dist/components/QRImage.d.ts new file mode 100644 index 0000000..32876c5 --- /dev/null +++ b/dist/components/QRImage.d.ts @@ -0,0 +1,22 @@ +import { RendererProps, SFC } from './RendererWrapper'; +declare enum Type { + Rect = "rect", + Round = "round" +} +declare enum PosType { + Rect = "rect", + Round = "round", + Planet = "planet" +} +interface QRImageProps extends RendererProps { + image?: string; + type?: Type | string; + size?: number; + opacity?: number; + darkColor?: string; + lightColor?: string; + posType?: PosType | string; + posColor?: string; +} +declare const _default: SFC; +export default _default; diff --git a/dist/components/QRLine.d.ts b/dist/components/QRLine.d.ts new file mode 100644 index 0000000..e17d5c5 --- /dev/null +++ b/dist/components/QRLine.d.ts @@ -0,0 +1,26 @@ +import { RendererProps, SFC } from './RendererWrapper'; +declare enum PosType { + Rect = "rect", + Round = "round", + Planet = "planet", + RoundRect = "roundRect" +} +declare enum LineDirection { + LeftToRight = "left-right", + UpToDown = "up-down", + HAndV = "h-v", + Loop = "loop", + TopLeftToBottomRight = "topLeft-bottomRight", + TopRightToBottomLeft = "topRight-bottomLeft", + Cross = "cross" +} +interface QRLineProps extends RendererProps { + direction?: LineDirection | string; + lineWidth?: number; + lineOpacity?: number; + lineColor?: string; + posType?: PosType | string; + posColor?: string; +} +declare const _default: SFC; +export default _default; diff --git a/dist/components/QRNormal.d.ts b/dist/components/QRNormal.d.ts new file mode 100644 index 0000000..2f924b7 --- /dev/null +++ b/dist/components/QRNormal.d.ts @@ -0,0 +1,22 @@ +import { RendererProps, SFC } from './RendererWrapper'; +declare enum Type { + Rect = "rect", + Round = "round", + Rand = "rand" +} +declare enum PosType { + Rect = "rect", + Round = "round", + Planet = "planet", + RoundRect = "roundRect" +} +interface QRNormalProps extends RendererProps { + type?: Type | string; + posType?: PosType | string; + size?: number; + opacity?: number; + otherColor?: string; + posColor?: string; +} +declare const _default: SFC; +export default _default; diff --git a/dist/components/QRRandRect.d.ts b/dist/components/QRRandRect.d.ts new file mode 100644 index 0000000..69761c3 --- /dev/null +++ b/dist/components/QRRandRect.d.ts @@ -0,0 +1,5 @@ +import { RendererProps, SFC } from './RendererWrapper'; +interface QRRandRectProps extends RendererProps { +} +declare const _default: SFC; +export default _default; diff --git a/dist/components/QRResImage.d.ts b/dist/components/QRResImage.d.ts new file mode 100644 index 0000000..e1ab2f1 --- /dev/null +++ b/dist/components/QRResImage.d.ts @@ -0,0 +1,17 @@ +import { RendererProps, SFC } from './RendererWrapper'; +declare enum Type { + None = "none", + White = "white", + Bw = "bw" +} +interface QRResImageProps extends RendererProps { + image?: string; + contrast?: number; + exposure?: number; + alignType?: Type | string; + timingType?: Type | string; + otherColor?: string; + posColor?: string; +} +declare const _default: SFC; +export default _default; diff --git a/dist/components/RendererWrapper.d.ts b/dist/components/RendererWrapper.d.ts new file mode 100644 index 0000000..a372f02 --- /dev/null +++ b/dist/components/RendererWrapper.d.ts @@ -0,0 +1,21 @@ +import React from 'react'; +import QRCode from "../utils/qrcode"; +export interface RendererProps { + qrcode?: QRCode; + className?: string; + value?: string; + level?: string; + styles?: any; + title?: string; + titleSize?: number; + titleColor?: string; + titleAlign?: string; + icon?: string; + iconScale?: number; +} +export declare type SFC

= StyledFunctionComponent

; +export interface StyledFunctionComponent

extends React.FunctionComponent

{ + defaultCSS?: any; +} +export declare const RendererWrapper: (renderer: SFC) => SFC; +export declare function drawIcon({ qrcode, title, titleSize, titleColor, titleAlign, icon, iconScale, styles }: RendererProps): JSX.Element[] | null; diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..f77e025 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,13 @@ +export { default as QRNormal } from "./components/QRNormal"; +export { default as QR25D } from "./components/QR25D"; +export { default as QRDsj } from "./components/QRDsj"; +export { default as QRRandRect } from "./components/QRRandRect"; +export { default as QRImage } from "./components/QRImage"; +export { default as QRResImage } from "./components/QRResImage"; +export { default as QRBubble } from "./components/QRBubble"; +export { default as QRFunc } from "./components/QRFunc"; +export { default as QRLine } from "./components/QRLine"; +export { default as QRCode } from "./utils/qrcode"; +export * from "./utils/helper"; +export * from "./utils/qrcodeHandler"; +export * from "./components/RendererWrapper"; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..dd13810 --- /dev/null +++ b/dist/index.js @@ -0,0 +1 @@ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define("react-qrbtf",["react"],t):"object"==typeof exports?exports["react-qrbtf"]=t(require("react")):e["react-qrbtf"]=t(e.react)}(window,function(r){return i={},o.m=n=[function(e,t){e.exports=r},function(e,t){var r=Array.isArray;e.exports=r},function(e,l,t){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(l,"__esModule",{value:!0}),l.getTypeTable=l.encodeData=l.getLevelNumber=l.QRPointType=void 0;var n=r(t(43));function o(e){return"L"===e?1:"M"===e?0:"Q"===e?3:"H"===e?2:0}l.QRPointType={DATA:0,POS_CENTER:1,POS_OTHER:2,ALIGN_CENTER:3,ALIGN_OTHER:4,TIMING:5,FORMAT:6,VERSION:7},l.getLevelNumber=o,l.encodeData=function(e){if(e.text&&!(e.text.length<=0)){e.typeNumber||(e.typeNumber=-1),e.correctLevel||(e.correctLevel="M");var t=new n.default(e.typeNumber,o(e.correctLevel));return t.addData(e.text),t.make(),t}},l.getTypeTable=function(e){for(var t=e.getModuleCount(),r=e.getPositionTable(),n=[[3,3],[3,t-4],[t-4,3]],o=new Array(t),i=0;i>>18,o[1]=128|(258048&i)>>>12,o[2]=128|(4032&i)>>>6,o[3]=128|63&i):2048>>12,o[1]=128|(4032&i)>>>6,o[2]=128|63&i):128>>6,o[1]=128|63&i):o[0]=i,(t=this.parsedData).push.apply(t,o)}this.parsedData=Array.prototype.concat.apply([],this.parsedData),this.parsedData.length!=this.data.length&&(this.parsedData.unshift(191),this.parsedData.unshift(187),this.parsedData.unshift(239))}var i=(c.prototype.addData=function(e){var t=new n(e);this.dataList.push(t),this.dataCache=null},c.prototype.isDark=function(e,t){if(e<0||this.moduleCount<=e||t<0||this.moduleCount<=t)throw new Error(e+","+t);return this.modules[e][t]},c.prototype.getModuleCount=function(){return this.moduleCount},c.prototype.getPositionTable=function(){return this.position},c.prototype.make=function(){if(this.typeNumber<1){for(var e=1,e=1;e<40;e++){for(var t=O.getRSBlocks(e,this.errorCorrectLevel),r=new R,n=0,o=0;o>r&1);this.modules[Math.floor(r/3)][r%3+this.moduleCount-8-3]=n}for(r=0;r<18;r++)n=!e&&1==(t>>r&1),this.modules[r%3+this.moduleCount-8-3][Math.floor(r/3)]=n},c.prototype.setupTypeInfo=function(e,t){for(var r=this.errorCorrectLevel<<3|t,n=b.getBCHTypeInfo(r),o=0;o<15;o++){var i=!e&&1==(n>>o&1);o<6?this.modules[o][8]=i:o<8?this.modules[o+1][8]=i:this.modules[this.moduleCount-15+o][8]=i}for(o=0;o<15;o++)i=!e&&1==(n>>o&1),o<8?this.modules[8][this.moduleCount-o-1]=i:o<9?this.modules[8][15-o-1+1]=i:this.modules[8][15-o-1]=i;this.modules[this.moduleCount-8][8]=!e},c.prototype.mapData=function(e,t){for(var r=-1,n=this.moduleCount-1,o=7,i=0,a=this.moduleCount-1;0>>o&1)),b.getMask(t,n,a-c)&&(u=!u),this.modules[n][a-c]=u,-1==--o&&(i++,o=7));if((n+=r)<0||this.moduleCount<=n){n-=r,r=-r;break}}},c.createData=function(e,t,r){for(var n=O.getRSBlocks(e,t),o=new R,i=0;i8*u)throw new Error("code length overflow. ("+o.getLengthInBits()+">"+8*u+")");for(o.getLengthInBits()+4<=8*u&&o.put(0,4);o.getLengthInBits()%8!=0;)o.putBit(!1);for(;!(o.getLengthInBits()>=8*u||(o.put(c.PAD0,8),o.getLengthInBits()>=8*u));)o.put(c.PAD1,8);return c.createBytes(o,n)},c.createBytes=function(e,t){for(var r=0,n=0,o=0,i=new Array(t.length),a=new Array(t.length),u=0;u>>=1;return t},getPatternPosition:function(e){return b.PATTERN_POSITION_TABLE[e-1]},getMask:function(e,t,r){switch(e){case p:return(t+r)%2==0;case h:return t%2==0;case d:return r%3==0;case y:return(t+r)%3==0;case v:return(Math.floor(t/2)+Math.floor(r/3))%2==0;case g:return t*r%2+t*r%3==0;case m:return(t*r%2+t*r%3)%2==0;case x:return(t*r%3+(t+r)%2)%2==0;default:throw new Error("bad maskPattern:"+e)}},getErrorCorrectPolynomial:function(e){for(var t=new _([1],0),r=0;r>>7-e%8&1)},P.prototype.put=function(e,t){for(var r=0;r>>t-r-1&1))},P.prototype.getLengthInBits=function(){return this.length},P.prototype.putBit=function(e){var t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++},P);function P(){this.buffer=[],this.length=0}t.default=i},function(r,e,t){(function(e){var t="object"==typeof e&&e&&e.Object===Object&&e;r.exports=t}).call(this,t(77))},function(e,t,r){var n=r(46),o=r(12);e.exports=function(e,t){return e&&n(e,t,o)}},function(e,t,r){var n=r(80)();e.exports=n},function(e,t,r){var f=r(81),s=r(26),p=r(1),h=r(15),d=r(28),y=r(29),v=Object.prototype.hasOwnProperty;e.exports=function(e,t){var r=p(e),n=!r&&s(e),o=!r&&!n&&h(e),i=!r&&!n&&!o&&y(e),a=r||n||o||i,u=a?f(e.length,String):[],c=u.length;for(var l in e)!t&&!v.call(e,l)||a&&("length"==l||o&&("offset"==l||"parent"==l)||i&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||d(l,c))||u.push(l);return u}},function(e,t){e.exports=function(t,r){return function(e){return t(r(e))}}},function(e,t,r){var n=r(8),o=r(35),i=r(5),a=Function.prototype,u=Object.prototype,c=a.toString,l=u.hasOwnProperty,f=c.call(Object);e.exports=function(e){if(!i(e)||"[object Object]"!=n(e))return!1;var t=o(e);if(null===t)return!0;var r=l.call(t,"constructor")&&t.constructor;return"function"==typeof r&&r instanceof r&&c.call(r)==f}},function(e,t){e.exports=function(e,t){for(var r=-1,n=null==e?0:e.length,o=Array(n);++r(n/255+c-.5)*(u+1)+.5&&(e%3!=1||t%3!=1)&&p.push(d.default.createElement("use",{key:"g_"+e+"_"+t,x:e,y:t,xlinkHref:a}))}o(p)}}})})(e,t.getModuleCount(),"#S-black").then(function(e){return u(e)})},[u,e,t]),d.default.createElement("svg",{className:r,style:n.svg,width:"100%",height:"100%",viewBox:function(e){if(!e)return"0 0 0 0";var t=3*e.getModuleCount();return String(-t/5)+" "+String(-t/5)+" "+String(t+t/5*2)+" "+String(t+t/5*2)}(t),fill:"white",xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink"},d.default.createElement("defs",null,d.default.createElement("rect",{id:"B-black",fill:o,width:3.08,height:3.08}),d.default.createElement("rect",{id:"B-white",fill:"white",width:3.08,height:3.08}),d.default.createElement("rect",{id:"S-black",fill:o,width:1.02,height:1.02}),d.default.createElement("rect",{id:"S-white",fill:"white",width:1.02,height:1.02}),d.default.createElement("rect",{id:"B",width:3.08,height:3.08}),d.default.createElement("rect",{id:"S",width:1.02,height:1.02})),a.concat(function(e){var t=e.qrcode,r=e.alignType,n=e.timingType,o=e.posColor;if(!t)return[];var i=t.getModuleCount(),a=y.getTypeTable(t),u=new Array(i);for(var c=0,l=0;l>; + moduleCount: number; + position: number[][]; + dataCache: number[] | null; + dataList: QR8BitByte[]; + static PAD0: number; + static PAD1: number; + constructor(typeNumber: number, errorCorrectLevel: number); + addData(data: string): void; + isDark(row: number, col: number): boolean | null; + getModuleCount(): number; + getPositionTable(): number[][]; + make(): void; + makeImpl(test: boolean, maskPattern: number): void; + setupPositionProbePattern(row: number, col: number): void; + getBestMaskPattern(): number; + setupTimingPattern(): void; + setupPositionAdjustPattern(): void; + setupTypeNumber(test: boolean): void; + setupTypeInfo(test: boolean, maskPattern: number): void; + mapData(data: number[], maskPattern: number): void; + static createData(typeNumber: number, errorCorrectLevel: number, dataList: QR8BitByte[]): any[]; + static createBytes(buffer: QRBitBuffer, rsBlocks: QRRSBlock[]): any[]; +} +declare class QRRSBlock { + totalCount: number; + dataCount: number; + constructor(totalCount: number, dataCount: number); + static RS_BLOCK_TABLE: number[][]; + static getRSBlocks(typeNumber: number, errorCorrectLevel: number): QRRSBlock[]; + static getRsBlockTable(typeNumber: number, errorCorrectLevel: number): Array; +} +declare class QRBitBuffer { + buffer: number[]; + length: number; + constructor(); + get(index: number): boolean; + put(num: number, length: number): void; + getLengthInBits(): number; + putBit(bit: boolean): void; +} +export default QRCode; diff --git a/dist/utils/qrcodeHandler.d.ts b/dist/utils/qrcodeHandler.d.ts new file mode 100644 index 0000000..53e6390 --- /dev/null +++ b/dist/utils/qrcodeHandler.d.ts @@ -0,0 +1,19 @@ +import QRCode from "./qrcode"; +export declare const QRPointType: { + DATA: number; + POS_CENTER: number; + POS_OTHER: number; + ALIGN_CENTER: number; + ALIGN_OTHER: number; + TIMING: number; + FORMAT: number; + VERSION: number; +}; +export interface IOptions { + text: string; + typeNumber?: number; + correctLevel?: string; +} +export declare function getLevelNumber(level: string): 2 | 1 | 0 | 3; +export declare function encodeData(options: IOptions): QRCode | undefined; +export declare function getTypeTable(qrcode: QRCode): number[][];