You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
36 KiB

2 years ago
{"ast":null,"code":"var BitByte = require('./8BitByte');\n\nvar RSBlock = require('./RSBlock');\n\nvar BitBuffer = require('./BitBuffer');\n\nvar util = require('./util');\n\nvar Polynomial = require('./Polynomial');\n\nfunction QRCode(typeNumber, errorCorrectLevel) {\n this.typeNumber = typeNumber;\n this.errorCorrectLevel = errorCorrectLevel;\n this.modules = null;\n this.moduleCount = 0;\n this.dataCache = null;\n this.dataList = [];\n} // for client side minification\n\n\nvar proto = QRCode.prototype;\n\nproto.addData = function (data) {\n var newData = new BitByte(data);\n this.dataList.push(newData);\n this.dataCache = null;\n};\n\nproto.isDark = function (row, col) {\n if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) {\n throw new Error(row + \",\" + col);\n }\n\n return this.modules[row][col];\n};\n\nproto.getModuleCount = function () {\n return this.moduleCount;\n};\n\nproto.make = function () {\n // Calculate automatically typeNumber if provided is < 1\n if (this.typeNumber < 1) {\n var typeNumber = 1;\n\n for (typeNumber = 1; typeNumber < 40; typeNumber++) {\n var rsBlocks = RSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);\n var buffer = new BitBuffer();\n var totalDataCount = 0;\n\n for (var i = 0; i < rsBlocks.length; i++) {\n totalDataCount += rsBlocks[i].dataCount;\n }\n\n for (var i = 0; i < this.dataList.length; i++) {\n var data = this.dataList[i];\n buffer.put(data.mode, 4);\n buffer.put(data.getLength(), util.getLengthInBits(data.mode, typeNumber));\n data.write(buffer);\n }\n\n if (buffer.getLengthInBits() <= totalDataCount * 8) break;\n }\n\n this.typeNumber = typeNumber;\n }\n\n this.makeImpl(false, this.getBestMaskPattern());\n};\n\nproto.makeImpl = function (test, maskPattern) {\n this.moduleCount = this.typeNumber * 4 + 17;\n this.modules = new Array(this.moduleCount);\n\n for (var row = 0; row < this.moduleCount; row++) {\n this.modules[row] = new Array(this.moduleCount);\n\n for (var col = 0; col < this.moduleCount; col++) {\n this.modules[row][col] = null; //(col + row) % 3;\n }\n }\n\n this.setupPositionProbePattern(0, 0);\n this.setupPositionProbePattern(this.moduleCount - 7, 0);\n this.setupPositionProbePattern(0, this.moduleCount - 7);\n this.setupPositionAdjustPattern();\n this.setupTimingPattern();\n this.setupTypeInfo(test, maskPattern);\n\n if (this.typeNumber >= 7) {\n this.setupTypeNumber(test);\n }\n\n if (this.dataCache == null) {\n this.dataCache = QRCode.createData(this.typeNumber, this.errorCorrectLevel, this.dataList);\n }\n\n this.mapData(this.dataCache, maskPattern);\n};\n\nproto.setupPositionProbePattern = function (row, col) {\n for (var r = -1; r <= 7; r++) {\n if (row + r <= -1 || this.moduleCount <= row + r) continue;\n\n for (var c = -1; c <= 7; c++) {\n if (col + c <= -1 || this.moduleCount <= col + c) continue;\n\n if (0 <= r && r <= 6 && (c == 0 || c == 6) || 0 <= c && c <= 6 && (r == 0 || r == 6) || 2 <= r && r <= 4 && 2 <= c && c <= 4) {\n this.modules[row + r][col + c] = true;\n } else {\n this.modules[row + r][col + c] = false;\n }\n }\n }\n};\n\nproto.getBestMaskPattern = function () {\n var minLostPoint = 0;\n var pattern = 0;\n\n for (var i = 0; i < 8; i++) {\n this.makeImpl(true, i);\n var lostPoint = util.getLostPoint(this);\n\n if (i == 0 || minLostPoint > lostPoint) {\n minLostPoint = lostPoint;\n pattern = i;\n }\n }\n\n return pattern;\n};\n\nproto.createMovieClip = function (target_mc, instance_name, depth) {\n var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth);\n var cs = 1;\n this.make();\n\n for (var row = 0; row < this.modules.length; row++) {\n var y = row * cs;\n\n for (var col = 0; col < this.modules[row].length; col++) {\n var x = col * cs;\n var dark = this.modules[row][col];\n\n if (dark) {\n qr_mc.beginFill(0, 100);\n qr_mc.moveTo(x, y);\n