Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
chore: wip
  • Loading branch information
chrisbbreuer committed Jan 7, 2025
1 parent efa03d4 commit 5c202d3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
18 changes: 9 additions & 9 deletions packages/qrx/src/bar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import optionsFromStrings from './utils/optionsFromStrings'
const API = function () { }

export const barcode = function (element: any, text: any, options: any): any {
// @ts-expect-error - unsure right now of how we could handle this better
const api = new API()

if (typeof element === 'undefined') {
Expand Down Expand Up @@ -48,25 +49,24 @@ function registerBarcode(barcodes: any, name: any): void {
API.prototype[name]
= API.prototype[name.toUpperCase()]
= API.prototype[name.toLowerCase()]
= function (text, options) {
const api = this
return api._errorHandler.wrapBarcodeCall(() => {
= function (text: any, options: any): any {
return this._errorHandler.wrapBarcodeCall(() => {
// Ensure text is options.text
options.text = typeof options.text === 'undefined' ? undefined : `${options.text}`

let newOptions = merge(api._options, options)
let newOptions = merge(this._options, options)
newOptions = optionsFromStrings(newOptions)
const Encoder = barcodes[name]
const encoded = encode(text, Encoder, newOptions)
api._encodings.push(encoded)
this._encodings.push(encoded)

return api
return this
})
}
}

// encode() handles the Encoder call and builds the binary string to be rendered
function encode(text, Encoder, options) {
function encode(text: any, Encoder: any, options: any): any {
// Ensure that text is a string
text = `${text}`

Expand Down Expand Up @@ -105,13 +105,13 @@ function autoSelectBarcode() {

// Sets global encoder options
// Added to the api by the barcode function
API.prototype.options = function (options) {
API.prototype.options = function (options: any) {
this._options = merge(this._options, options)
return this
}

// Will create a blank space (usually in between barcodes)
API.prototype.blank = function (size) {
API.prototype.blank = function (size: any) {
// eslint-disable-next-line unicorn/no-new-array
const zeroes = new Array(size + 1).join('0')
this._encodings.push({ data: zeroes })
Expand Down
6 changes: 5 additions & 1 deletion packages/qrx/src/bar/renderers/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import merge from '../utils/merge'
import { calculateEncodingAttributes, getMaximumHeightOfEncodings, getTotalWidthOfEncodings } from './shared'

class CanvasRenderer {
export class CanvasRenderer {
canvas: any
encodings: any
options: any

constructor(canvas: any, encodings: any, options: any) {
this.canvas = canvas
this.encodings = encodings
Expand Down
6 changes: 5 additions & 1 deletion packages/qrx/src/bar/renderers/object.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class ObjectRenderer {
export class ObjectRenderer {
object: any
encodings: any
options: any

constructor(object: any, encodings: any, options: any) {
this.object = object
this.encodings = encodings
Expand Down
5 changes: 5 additions & 0 deletions packages/qrx/src/bar/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare global {
interface Window {
barcode: any
}
}

0 comments on commit 5c202d3

Please sign in to comment.