qs-canvas.js 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107
  1. import {
  2. __commonJS,
  3. __privateAdd,
  4. __privateGet,
  5. __privateSet
  6. } from "./chunk-VX4GZB4L.js";
  7. // D:/CHB/出入金1/商城前端/前端/h5mall_uniapp/node_modules/qs-canvas/index.js
  8. var require_qs_canvas = __commonJS({
  9. "D:/CHB/\u51FA\u5165\u91D11/\u5546\u57CE\u524D\u7AEF/\u524D\u7AEF/h5mall_uniapp/node_modules/qs-canvas/index.js"(exports, module) {
  10. var QSCanvas = function() {
  11. var _nc;
  12. const platform = getPlatform(), isUni = platform == "uni", isNode = platform == "node", isWeb = platform == "web", imgCache = {}, vmCache = {}, asyncDrawWhiteList = Object.freeze([
  13. "init",
  14. "initAsyncDrawMode",
  15. "initArgs",
  16. "initCanvas",
  17. "handleCtx",
  18. "initData",
  19. "draw",
  20. "toImage",
  21. "updateCanvasWH",
  22. "clear",
  23. "restoreAsyncDrawMode"
  24. ]), calcMethods = Object.freeze([
  25. "setPaintbrush",
  26. "setPaintbrushProp",
  27. "resetPaintbrush",
  28. "savePaintbrush",
  29. "restorePaintbrush",
  30. "calcText",
  31. "calcImg",
  32. "measureText",
  33. "loadImage"
  34. ]), asyncDrawMethods = Object.freeze([
  35. "setPaintbrush",
  36. "setPaintbrushProp",
  37. "resetPaintbrush",
  38. "savePaintbrush",
  39. "restorePaintbrush",
  40. "drawText",
  41. "drawStraightLine",
  42. "drawDoubleStraightLine",
  43. "drawDotted",
  44. "drawDottedStraightLine",
  45. "drawLine",
  46. "drawTextDecoration",
  47. "drawImg",
  48. "drawQrCode",
  49. "setCircle",
  50. "setRect"
  51. ]), allSelfMethods = Object.freeze([
  52. "setPaintbrush",
  53. "setPaintbrushProp",
  54. "resetPaintbrush",
  55. "savePaintbrush",
  56. "restorePaintbrush",
  57. "drawText",
  58. "drawStraightLine",
  59. "drawDoubleStraightLine",
  60. "drawDotted",
  61. "drawDottedStraightLine",
  62. "drawLine",
  63. "drawTextDecoration",
  64. "drawImg",
  65. "drawQrCode",
  66. "setCircle",
  67. "setRect",
  68. "calcText",
  69. "calcImg",
  70. "measureText",
  71. "loadImage",
  72. "drawArray",
  73. "drawItem"
  74. ]), needReturnMethods = Object.freeze(["drawText", "drawImg"]), commonMethods = Object.freeze([
  75. "drawImage",
  76. "putImageData",
  77. "getImageData",
  78. "createImageData",
  79. "addPage",
  80. "save",
  81. "restore",
  82. "rotate",
  83. "translate",
  84. "transform",
  85. "getTransform",
  86. "resetTransform",
  87. "setTransform",
  88. "isPointInPath",
  89. "scale",
  90. "clip",
  91. "fill",
  92. "stroke",
  93. "fillText",
  94. "strokeText",
  95. "fillRect",
  96. "strokeRect",
  97. "clearRect",
  98. "rect",
  99. "measureText",
  100. "moveTo",
  101. "lineTo",
  102. "bezierCurveTo",
  103. "quadraticCurveTo",
  104. "beginPath",
  105. "closePath",
  106. "arc",
  107. "arcTo",
  108. "ellipse",
  109. "setLineDash",
  110. "getLineDash",
  111. "createPattern",
  112. "createLinearGradient",
  113. "createRadialGradient"
  114. ]);
  115. let nodeCanvas, id = 1;
  116. function notUnd(t) {
  117. return String(t) != "undefined";
  118. }
  119. function isNull(a) {
  120. return !((a || a == 0) && !["undefined", "null"].includes(String(a)));
  121. }
  122. function getPlatform() {
  123. if (notUnd(typeof uni))
  124. return "uni";
  125. if (notUnd(typeof window) && notUnd(typeof document))
  126. return "web";
  127. return "node";
  128. }
  129. function getCtx(vm, args) {
  130. if (isUni) {
  131. if (!args.canvasId) {
  132. throw new Error("canvasId \u4E0D\u80FD\u4E3A\u7A7A");
  133. }
  134. }
  135. let canvas, obj = {};
  136. switch (platform) {
  137. case "uni":
  138. canvas = uni.createCanvasContext(args.canvasId, vm);
  139. obj.canvas = canvas;
  140. obj.ctx = canvas;
  141. break;
  142. case "web":
  143. canvas = (args == null ? void 0 : args.canvasId) ? document.getElementById(args == null ? void 0 : args.canvasId) : document.createElement("canvas");
  144. canvas.width = (args == null ? void 0 : args.width) || 10;
  145. canvas.height = (args == null ? void 0 : args.height) || 10;
  146. obj.canvas = canvas;
  147. obj.ctx = canvas.getContext("2d");
  148. break;
  149. case "node":
  150. canvas = nodeCanvas.createCanvas((args == null ? void 0 : args.width) || 10, (args == null ? void 0 : args.height) || 10);
  151. obj.canvas = canvas;
  152. obj.ctx = canvas.getContext("2d");
  153. break;
  154. }
  155. return obj;
  156. }
  157. const _QSCanvas = class {
  158. constructor(obj, vm) {
  159. __privateAdd(this, _nc, void 0);
  160. this._id = id++;
  161. vmCache[this._id] = vm;
  162. if (obj) {
  163. this.init(obj);
  164. }
  165. }
  166. init(obj = {}) {
  167. this.initArgs(obj).initData().initCanvas().handleCtx().resetPaintbrush();
  168. if (this._data.asyncDrawMode === true) {
  169. __privateSet(this, _nc, new _QSCanvas({ asyncDrawMode: false }));
  170. this.initAsyncDrawMode();
  171. }
  172. }
  173. initAsyncDrawMode() {
  174. if (isUni)
  175. return;
  176. const ctxMethods = this._data.ctxMethods;
  177. const arr = [.../* @__PURE__ */ new Set([...allSelfMethods, ...ctxMethods])];
  178. for (let i = 0; i < arr.length; i++) {
  179. const item = arr[i];
  180. this.handleAsyncDrawModeItem(item);
  181. }
  182. }
  183. handleAsyncDrawModeItem(i) {
  184. if (isUni)
  185. return;
  186. if (asyncDrawWhiteList.includes(i)) {
  187. console.log("\u767D\u540D\u5355\u8DF3\u8FC7");
  188. return;
  189. }
  190. if (typeof this[i] == "function") {
  191. if (!this._data.nMethods[i])
  192. this._data.nMethods[i] = this[i];
  193. let _this = this;
  194. this[i] = function() {
  195. let r;
  196. if (calcMethods.includes(i)) {
  197. r = __privateGet(_this, _nc)[i](...arguments);
  198. }
  199. if (r && r !== _this && r !== __privateGet(_this, _nc))
  200. return r;
  201. if (asyncDrawMethods.includes(i) || _this._data.ctxMethods.includes(i)) {
  202. _this._data.asyncDrawQueue.push({ method: i, args: arguments });
  203. }
  204. if (needReturnMethods.includes(i)) {
  205. return __privateGet(_this, _nc)[i](...arguments);
  206. }
  207. };
  208. }
  209. }
  210. restoreAsyncDrawMode() {
  211. if (isUni)
  212. return;
  213. const nMethods = this._data.nMethods;
  214. for (const i in nMethods) {
  215. this[i] = nMethods[i];
  216. }
  217. }
  218. initArgs(obj = {}) {
  219. this._args = obj;
  220. return this;
  221. }
  222. initCanvas() {
  223. const canvasObj = getCtx(vmCache[this._id], this._args);
  224. this.canvas = canvasObj.canvas;
  225. this.ctx = canvasObj.ctx;
  226. return this;
  227. }
  228. handleCtx() {
  229. const ctx = this.ctx;
  230. const active = (i) => {
  231. this._data.ctxMethods.push(i);
  232. this[i] = ctx[i].bind(ctx);
  233. return;
  234. function a() {
  235. return ctx[i](...arguments);
  236. }
  237. };
  238. for (const i in ctx) {
  239. if (typeof ctx[i] == "function") {
  240. if (!this[i]) {
  241. active(i);
  242. }
  243. }
  244. }
  245. for (let k = 0; k < commonMethods.length; k++) {
  246. const i = commonMethods[k];
  247. if (typeof ctx[i] == "function") {
  248. if (!this[i]) {
  249. active(i);
  250. }
  251. }
  252. }
  253. return this;
  254. }
  255. initData() {
  256. this._data = {
  257. oldPaintbrushProps: {},
  258. savedPaintbrushProps: [],
  259. font: { fontStyle: "normal", fontVariant: "normal", fontWeight: "normal", fontSize: 10, fontFamily: "sans-serif" },
  260. height: this._args.height || 10,
  261. width: this._args.width || 10,
  262. whChange: false,
  263. asyncDrawQueue: [],
  264. nMethods: {},
  265. asyncDrawMode: isNode || isWeb ? this._args.asyncDrawMode !== false : false,
  266. ctxMethods: []
  267. };
  268. return this;
  269. }
  270. setPaintbrush(obj = {}) {
  271. filterPaintbrushProps(obj);
  272. for (const k in obj) {
  273. this.setPaintbrushProp(k, obj[k]);
  274. }
  275. return this;
  276. }
  277. setPaintbrushProp(prop, data) {
  278. if (isNull(prop) || isNull(data))
  279. return;
  280. prop = hyphen2Hump(prop);
  281. const ctx = this.ctx;
  282. if (prop == "font") {
  283. if (data) {
  284. if (typeof data != "object") {
  285. console.warn("font\u5C5E\u6027\u9700Object\u683C\u5F0F");
  286. return;
  287. }
  288. for (const k in data)
  289. if (isNull(data[k]))
  290. delete data[k];
  291. const font = { ...this._data.font, ...data };
  292. if (isUni)
  293. font.fontSize = Math.round(font.fontSize);
  294. this._data.font = font;
  295. const f = this._data.font;
  296. this._data.oldPaintbrushProps[prop] = f;
  297. const setFont = () => {
  298. var _a;
  299. ctx.font = `${f.fontStyle || "normal"} ${f.fontVariant || "normal"} ${f.fontWeight || "normal"} ${(_a = f.fontSize) != null ? _a : 10}px ${f.fontFamily || "sans-serif"}`;
  300. };
  301. if (isUni) {
  302. setFont();
  303. } else
  304. setFont();
  305. }
  306. } else {
  307. this._data.oldPaintbrushProps[prop] = data;
  308. const fnn = "set" + prop[0].toUpperCase() + prop.slice(1);
  309. if (typeof (ctx == null ? void 0 : ctx[fnn]) == "function") {
  310. ctx[fnn](data);
  311. } else {
  312. ctx[prop] = data;
  313. }
  314. }
  315. return this;
  316. }
  317. resetPaintbrush(obj = {}) {
  318. this.setPaintbrush({
  319. fillStyle: "#000000",
  320. strokeStyle: "#000000",
  321. shadowColor: "#000000",
  322. shadowBlur: 0,
  323. shadowOffsetX: 0,
  324. shadowOffsetY: 0,
  325. lineCap: "butt",
  326. lineJoin: "miter",
  327. lineWidth: 1,
  328. miterLimit: 10,
  329. font: this._data.font,
  330. textAlign: "start",
  331. textBaseline: "top",
  332. globalAlpha: 1,
  333. globalCompositeOperation: "source-over",
  334. ...obj
  335. });
  336. return this;
  337. }
  338. saveAndSetPaintbrush(paintbrushProps = {}) {
  339. this.savePaintbrush();
  340. this.setPaintbrush(paintbrushProps);
  341. return this;
  342. }
  343. savePaintbrush() {
  344. this._data.savedPaintbrushProps.unshift({ ...this._data.oldPaintbrushProps });
  345. return this;
  346. }
  347. restorePaintbrush() {
  348. const savedProps = this._data.savedPaintbrushProps.shift();
  349. if (savedProps)
  350. this._data.oldPaintbrushProps = { ...this._data.oldPaintbrushProps, ...savedProps };
  351. this.resetPaintbrush({ ...this._data.oldPaintbrushProps });
  352. return this;
  353. }
  354. updateCanvasWH(obj = {}) {
  355. var _a, _b, _c;
  356. let { width, height, delay } = obj, setCanvasWH = (_a = this._args) == null ? void 0 : _a.setCanvasWH;
  357. width = width || ((_b = this._data) == null ? void 0 : _b.width) || 10;
  358. height = height || ((_c = this._data) == null ? void 0 : _c.height) || 10;
  359. return new Promise((rs, rj) => {
  360. if (isUni) {
  361. if (!setCanvasWH || typeof setCanvasWH != "function") {
  362. rj("setCanvasWH\u5F02\u5E38, uni-app \u8BF7\u5728\u521D\u59CB\u5316\u65F6\u4F20\u5165setCanvasWH\u51FD\u6570");
  363. return;
  364. }
  365. setCanvasWH({ height, width });
  366. setTimeout(() => {
  367. rs();
  368. }, delay != null ? delay : 50);
  369. } else {
  370. this.canvas.height = height;
  371. this.canvas.width = width;
  372. rs();
  373. }
  374. }).then((r) => {
  375. if (this._data.width != width || this._data.height != height) {
  376. this._data.whChange = true;
  377. }
  378. this._data.width = width;
  379. this._data.height = height;
  380. if (!this._data.asyncDrawMode)
  381. this.resetPaintbrush(this._data.oldPaintbrushProps);
  382. });
  383. }
  384. clear() {
  385. this.ctx.clearRect(0, 0, this._data.width || 999999, this._data.height || 999999);
  386. return this;
  387. }
  388. draw(obj = {}) {
  389. const { reserve } = obj;
  390. return new Promise((rs, rj) => {
  391. if (isUni) {
  392. let done = false;
  393. const settimeoutkey = setTimeout(() => {
  394. if (!done) {
  395. rs();
  396. } else {
  397. clearTimeout(settimeoutkey);
  398. }
  399. }, 3e3);
  400. this.ctx.draw(reserve != null ? reserve : false, () => {
  401. done = true;
  402. clearTimeout(settimeoutkey);
  403. rs();
  404. });
  405. } else {
  406. if (this._data.asyncDrawMode) {
  407. if (reserve !== true)
  408. this.clear();
  409. this.restoreAsyncDrawMode();
  410. this.resetPaintbrush();
  411. const arr = this._data.asyncDrawQueue;
  412. new Promise(async (resolve, reject) => {
  413. for (let i = 0; i < arr.length; i++) {
  414. const item = arr[i];
  415. try {
  416. const r = this[item.method].call(this, ...item.args);
  417. if (typeof (r == null ? void 0 : r.then) == "function")
  418. await r;
  419. } catch (error) {
  420. reject(error);
  421. return;
  422. }
  423. }
  424. resolve();
  425. }).then(() => {
  426. this._data.asyncDrawQueue = [];
  427. this.initAsyncDrawMode();
  428. rs();
  429. }).catch((err) => {
  430. this.initAsyncDrawMode();
  431. rj(err);
  432. });
  433. } else {
  434. rs();
  435. }
  436. }
  437. });
  438. }
  439. toImage(obj = {}) {
  440. return new Promise((rs, rj) => {
  441. var _a;
  442. if (isUni) {
  443. const canvasId = this._args.canvasId;
  444. if (!canvasId) {
  445. rj("canvasId\u4E0D\u5B58\u5728");
  446. return;
  447. }
  448. uni.canvasToTempFilePath({
  449. ...obj,
  450. canvasId,
  451. success: (r) => {
  452. var _a2;
  453. (_a2 = obj.success) == null ? void 0 : _a2.call(obj, r);
  454. rs(r.tempFilePath);
  455. },
  456. fail: (err) => {
  457. var _a2;
  458. (_a2 = obj.fail) == null ? void 0 : _a2.call(obj, err);
  459. rj(err);
  460. }
  461. }, vmCache[this._id]);
  462. } else {
  463. rs(this.canvas.toDataURL(`image/${["jpg", "jpeg"].includes(obj.fileType) ? "jpeg" : "png"}`, (_a = obj.quality) != null ? _a : 1));
  464. }
  465. });
  466. }
  467. calcText(obj = {}) {
  468. const line = obj.line || -1;
  469. return new Promise((rs, rj) => {
  470. try {
  471. let run2 = function(text, endLine) {
  472. let endLineWidth = 0;
  473. const textWidth = mt(text).width;
  474. if (endLine) {
  475. if (textWidth < obj.maxWidth || text.length < 2) {
  476. return { index: text.length, ellipsis: false, width: textWidth };
  477. } else {
  478. endLineWidth = mt("...").width;
  479. }
  480. }
  481. const textWidthEndLineWidth = textWidth + endLineWidth;
  482. if (textWidthEndLineWidth < obj.maxWidth || text.length < 2) {
  483. return { index: text.length, ellipsis: false, width: textWidthEndLineWidth };
  484. }
  485. let loop = true, mid = Math.floor((text.length + 1) / 2), oldMid = 1, mode = "", tw;
  486. while (loop) {
  487. if (mid <= 1) {
  488. loop = false;
  489. break;
  490. }
  491. if (mid > text.length) {
  492. mid = text.length;
  493. loop = false;
  494. break;
  495. }
  496. const t = text.substr(0, mid);
  497. tw = mt(t).width + endLineWidth;
  498. if (tw > obj.maxWidth) {
  499. text = t;
  500. if (mode == "xy" && Math.abs(oldMid - mid) < 1) {
  501. loop = false;
  502. } else {
  503. mode = "dy";
  504. oldMid = mid;
  505. mid = Math.floor((t.length + 1) / 2);
  506. }
  507. } else if (tw == obj.maxWidth) {
  508. loop = false;
  509. } else {
  510. if (mid <= 1 || Math.abs(oldMid - mid) < 1) {
  511. loop = false;
  512. } else {
  513. mode = "xy";
  514. oldMid = mid;
  515. mid += Math.floor((text.length - mid) / 2);
  516. }
  517. }
  518. }
  519. return { index: mid, ellipsis: endLine, width: tw };
  520. };
  521. var run = run2;
  522. this.saveAndSetPaintbrush({
  523. ...obj.paintbrushProps || {}
  524. });
  525. const mt = this.measureText;
  526. let splitTexts = [], str = obj.val, width = 0;
  527. const font = { ...this._data.font };
  528. if (obj.maxWidth) {
  529. let i = 0;
  530. while (str.length) {
  531. const endLine = line > 0 && splitTexts.length + 1 >= line, { index: len, ellipsis, width: width2 } = run2(str, endLine);
  532. const txt = str.substr(0, len);
  533. splitTexts.push({ ...obj, val: txt, y: i ? obj.y + (font.fontSize + (obj.lineHeight || 0)) * i : obj.y, width: width2 });
  534. if (endLine) {
  535. if (ellipsis)
  536. splitTexts[splitTexts.length - 1].val += "...";
  537. str = "";
  538. } else
  539. str = str.slice(len);
  540. i++;
  541. }
  542. width = splitTexts.length == 1 ? splitTexts[0].width : splitTexts.length > 1 ? obj.maxWidth : 0;
  543. } else {
  544. splitTexts = [obj];
  545. width = mt(obj.val).width;
  546. }
  547. this.restorePaintbrush();
  548. rs({
  549. ...obj,
  550. calcTexts: splitTexts,
  551. _calc: true,
  552. left: obj.x,
  553. top: obj.y,
  554. right: obj.x + width,
  555. bottom: splitTexts[splitTexts.length - 1].y + font.fontSize,
  556. width,
  557. height: splitTexts[splitTexts.length - 1].y + font.fontSize - obj.y,
  558. fontSize: font.fontSize
  559. });
  560. } catch (error) {
  561. rj(error);
  562. }
  563. });
  564. }
  565. drawText(obj = {}) {
  566. return new Promise(async (rs, rj) => {
  567. try {
  568. if (!obj.val) {
  569. console.warn(`\u9700\u7ED8\u5236\u7684\u6587\u672C\u4E3A\u7A7A`);
  570. rs();
  571. return;
  572. }
  573. this.saveAndSetPaintbrush({
  574. ...obj.paintbrushProps || {}
  575. });
  576. const ft = (obj2) => {
  577. this.fillText(obj2.val, obj2.x, obj2.y);
  578. }, ftItem = (item) => {
  579. ft(item);
  580. if (item.textDecoration)
  581. this.drawTextDecoration(item);
  582. };
  583. const calcR = obj._calc ? obj : await this.calcText(obj);
  584. for (let i = 0; i < calcR.calcTexts.length; i++) {
  585. ftItem(calcR.calcTexts[i]);
  586. }
  587. this.restorePaintbrush();
  588. rs(calcR);
  589. } catch (error) {
  590. rj(error);
  591. }
  592. });
  593. }
  594. drawStraightLine(obj = {}) {
  595. const { x1, y1, x2, y2, paintbrushProps } = obj, ctx = this.ctx;
  596. ctx.beginPath();
  597. ctx.moveTo(x1, y1);
  598. ctx.lineTo(x2, y2);
  599. this.saveAndSetPaintbrush(paintbrushProps || {});
  600. ctx.stroke();
  601. this.restorePaintbrush();
  602. }
  603. drawDoubleStraightLine(obj = {}) {
  604. let { gap } = obj;
  605. gap = gap != null ? gap : 1;
  606. this.drawStraightLine(obj);
  607. this.drawStraightLine({ ...obj, y1: obj.y1 + gap, y2: obj.y2 + gap });
  608. }
  609. drawDotted(obj = {}) {
  610. this.setCircle(obj);
  611. if (obj.clip)
  612. obj.clip = false;
  613. this.saveAndSetPaintbrush(obj.paintbrushProps || {});
  614. this.ctx.fill();
  615. this.restorePaintbrush();
  616. }
  617. drawDottedStraightLine(obj = {}) {
  618. let { x1, x2, y1, y2, gap, width, paintbrushProps } = obj;
  619. x2 = x2 - width;
  620. gap = gap || 1;
  621. const len = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
  622. const points = getPoints(x1, y1, x2, y2, Math.floor((len - gap) / (width + gap)), 9999999999);
  623. this.saveAndSetPaintbrush(paintbrushProps);
  624. this.drawDotted({ x: x1, y: y1, d: width });
  625. for (let i = 0; i < points.length; i++)
  626. this.drawDotted({ x: points[i][0], y: points[i][1], d: width });
  627. this.drawDotted({ x: x2, y: y2, d: width });
  628. this.restorePaintbrush();
  629. }
  630. drawLine(obj = {}) {
  631. const { style } = obj;
  632. switch (style) {
  633. case "double":
  634. obj.gap = (obj.width || 1) * 1.5;
  635. this.drawDoubleStraightLine(obj);
  636. break;
  637. case "solide":
  638. this.drawStraightLine(obj);
  639. break;
  640. case "dotted":
  641. obj.gap = (obj.gap || 1) * 1.5;
  642. obj.paintbrushProps = { fillStyle: obj.color };
  643. this.drawDottedStraightLine(obj);
  644. break;
  645. }
  646. }
  647. drawTextDecoration(obj = {}) {
  648. var _a;
  649. this.savePaintbrush();
  650. const oldProps = this._data.oldPaintbrushProps, tw = this.measureText(obj.val).width, tD = obj.textDecoration, line = tD.line || "line-through", color = tD.color || obj.color || oldProps.fillStyle || "#000000", width = tD.thickness || tD.width || (obj.fontSize ? obj.fontSize * 0.1 : false) || 1, style = tD.style || "solide", offset = tD.offset || 0, gap = (_a = tD.gap) != null ? _a : 1, fontSize = obj.fontSize || this._data.font.fontSize;
  651. this.setPaintbrush({ lineWidth: width, strokeStyle: color });
  652. let y = 0;
  653. switch (line) {
  654. case "line-through":
  655. y = obj.y + fontSize / 2 - width / 2;
  656. break;
  657. case "underline":
  658. y = obj.y + fontSize;
  659. break;
  660. case "overline":
  661. y = obj.y;
  662. break;
  663. }
  664. switch (oldProps.textBaseline) {
  665. case "top":
  666. y += width / 2;
  667. break;
  668. case "bottom":
  669. y -= fontSize;
  670. break;
  671. case "center":
  672. y -= fontSize / 2;
  673. break;
  674. }
  675. y += offset;
  676. switch (line) {
  677. case "line-through":
  678. case "underline":
  679. case "overline":
  680. this.drawLine({ x1: obj.x, y1: y, x2: obj.x + tw, y2: y, style, gap, width, color });
  681. break;
  682. }
  683. this.restorePaintbrush();
  684. }
  685. drawImg(obj = {}) {
  686. return new Promise(async (rs, rj) => {
  687. try {
  688. if (!obj.val) {
  689. console.warn(`\u9700\u7ED8\u5236\u7684\u56FE\u7247\u4E3A\u7A7A`);
  690. rs();
  691. return;
  692. }
  693. const calcR = obj._calc ? obj : await this.calcImg(obj);
  694. if ((calcR == null ? void 0 : calcR.drawImageArgs) && Array.isArray(calcR.drawImageArgs))
  695. this.ctx.drawImage(...(calcR == null ? void 0 : calcR.drawImageArgs) || []);
  696. rs(calcR);
  697. } catch (error) {
  698. rj(error);
  699. }
  700. });
  701. }
  702. calcImg(obj = {}) {
  703. return new Promise(async (rs, rj) => {
  704. try {
  705. if (!obj.val) {
  706. console.warn(`\u9700\u7ED8\u5236\u7684\u56FE\u7247\u4E3A\u7A7A`);
  707. rs();
  708. return;
  709. }
  710. const img = await this.loadImage(obj.val), mode = obj.mode || "scaleToFill";
  711. let arr, x = obj.x || 0, y = obj.y || 0, w = obj.width || 0, h = obj.height || 0, sw = img.width, sh = img.height, sx = 0, sy = 0;
  712. const get_6 = () => {
  713. if (isUni) {
  714. }
  715. return [sx, sy, sw, sh, x, y, w, h];
  716. };
  717. switch (mode) {
  718. case "aspectFit":
  719. h = img.height / img.width * w;
  720. if (h < obj.height) {
  721. y = Number(obj.y) + obj.height / 2 - h / 2;
  722. } else {
  723. h = obj.height;
  724. w = img.width / img.height * h;
  725. x = Number(obj.x) + obj.width / 2 - w / 2;
  726. }
  727. arr = get_6();
  728. break;
  729. case "aspectFill":
  730. h = img.height / img.width * w;
  731. if (h < obj.height) {
  732. h = obj.height;
  733. sx = img.width / img.height * obj.height;
  734. sx = (sx - obj.width) / sx * img.width / 2;
  735. sw = img.width - sx * 2;
  736. } else {
  737. sy = (h - obj.height) / h * img.height / 2;
  738. sh = img.height - sy * 2;
  739. }
  740. w = obj.width;
  741. h = obj.height;
  742. arr = get_6();
  743. break;
  744. case "widthFix":
  745. h = obj.height = img.height / img.width * obj.width;
  746. arr = [x, y, w, h];
  747. break;
  748. case "heightFix":
  749. w = obj.width = img.width / img.height * obj.height;
  750. arr = [x, y, w, h];
  751. break;
  752. default:
  753. arr = [x, y, w, h];
  754. }
  755. arr.unshift(isUni ? img.toString() : img);
  756. rs({ ...obj, drawImageArgs: [...arr], img, left: obj.x, top: obj.y, right: obj.x + obj.width, bottom: obj.y + obj.height, _calc: true });
  757. } catch (error) {
  758. rj(error);
  759. }
  760. });
  761. }
  762. drawQrCode(obj = {}) {
  763. return new Promise((rs, rj) => {
  764. if (!(obj == null ? void 0 : obj.val)) {
  765. console.warn("\u7ED8\u5236\u4E8C\u7EF4\u7801val\u4E3A\u7A7A");
  766. rs();
  767. return;
  768. }
  769. this.savePaintbrush();
  770. let qrcodeAlgObjCache = [];
  771. let options = {
  772. text: String(obj.val || "") || "",
  773. size: Number(obj.size || 0) || 200,
  774. background: String(obj.background || "") || "#ffffff",
  775. foreground: String(obj.foreground || "") || "#000000",
  776. pdground: String(obj.pdground || "") || "#000000",
  777. correctLevel: Number(obj.correctLevel || 0) || 3,
  778. dx: Number(obj.x || 0) || 0,
  779. dy: Number(obj.y || 0) || 0
  780. };
  781. let qrCodeAlg = null;
  782. let d = 0;
  783. for (var i = 0, l = qrcodeAlgObjCache.length; i < l; i++) {
  784. d = i;
  785. if (qrcodeAlgObjCache[i].text == options.text && qrcodeAlgObjCache[i].text.correctLevel == options.correctLevel) {
  786. qrCodeAlg = qrcodeAlgObjCache[i].obj;
  787. break;
  788. }
  789. }
  790. if (d == l) {
  791. qrCodeAlg = new QRCodeAlg(options.text, options.correctLevel);
  792. qrcodeAlgObjCache.push({
  793. text: options.text,
  794. correctLevel: options.correctLevel,
  795. obj: qrCodeAlg
  796. });
  797. }
  798. let getForeGround = function(config) {
  799. let options2 = config.options;
  800. if (options2.pdground && (config.row > 1 && config.row < 5 && config.col > 1 && config.col < 5 || config.row > config.count - 6 && config.row < config.count - 2 && config.col > 1 && config.col < 5 || config.row > 1 && config.row < 5 && config.col > config.count - 6 && config.col < config.count - 2)) {
  801. return options2.pdground;
  802. }
  803. return options2.foreground;
  804. };
  805. let count = qrCodeAlg.getModuleCount();
  806. let ratioSize = options.size;
  807. let tileW = ratioSize / count;
  808. let tileH = ratioSize / count;
  809. for (let row = 0; row < count; row++) {
  810. for (let col = 0; col < count; col++) {
  811. let w = (col + 1) * tileW - col * tileW;
  812. let h = (row + 1) * tileW - row * tileW;
  813. let foreground = getForeGround({
  814. row,
  815. col,
  816. count,
  817. options
  818. });
  819. this.setPaintbrush({ fillStyle: qrCodeAlg.modules[row][col] ? foreground : options.background });
  820. this.ctx.fillRect(options.dx + col * tileW, options.dy + row * tileH, w, h);
  821. }
  822. }
  823. this.restorePaintbrush();
  824. rs({ ...obj, height: obj.size, width: obj.size, left: obj.x, top: obj.y, right: obj.x + obj.width, bottom: obj.y + obj.size });
  825. });
  826. }
  827. setCircle(obj = {}) {
  828. const ctx = this.ctx;
  829. let { x, y, d, mode } = obj;
  830. mode = mode || "leftTop";
  831. const r = d / 2;
  832. if (obj.clip)
  833. ctx.save();
  834. ctx.beginPath();
  835. switch (mode) {
  836. case "leftTop":
  837. ctx.arc(x + r, y + r, r, 0, 2 * Math.PI);
  838. break;
  839. case "center":
  840. ctx.arc(x, y, r, 0, 2 * Math.PI);
  841. break;
  842. }
  843. ctx.closePath();
  844. if (obj.clip)
  845. ctx.clip();
  846. return this;
  847. }
  848. setRect(obj = {}) {
  849. const ctx = this.ctx;
  850. const { x, y, r, height, width } = obj;
  851. if (obj.clip)
  852. ctx.save();
  853. ctx.beginPath();
  854. if (r && r > 0) {
  855. ctx.arc(x + r, y + r, r, 1 * Math.PI, 1.5 * Math.PI);
  856. ctx.lineTo(x + width - r, y);
  857. ctx.arc(x + width - r, y + r, r, 1.5 * Math.PI, 0);
  858. ctx.lineTo(x + width, y + height - r);
  859. ctx.arc(x + width - r, y + height - r, r, 0, 0.5 * Math.PI);
  860. ctx.lineTo(x + r, y + height);
  861. ctx.arc(x + r, y + height - r, r, 0.5 * Math.PI, 1 * Math.PI);
  862. ctx.lineTo(x, y + r);
  863. } else {
  864. ctx.moveTo(x, y);
  865. ctx.lineTo(x + width, y);
  866. ctx.lineTo(x + width, y + height);
  867. ctx.lineTo(x, y + height);
  868. ctx.lineTo(x, y);
  869. }
  870. ctx.closePath();
  871. if (obj.clip)
  872. ctx.clip();
  873. return this;
  874. }
  875. loadImage(url) {
  876. return new Promise(async (resolve, reject) => {
  877. if (!url) {
  878. console.warn("\u52A0\u8F7D\u56FE\u7247url\u4E3A\u7A7A");
  879. resolve();
  880. return;
  881. }
  882. if (imgCache[url]) {
  883. resolve(imgCache[url]);
  884. return;
  885. }
  886. let img;
  887. try {
  888. switch (platform) {
  889. case "uni":
  890. img = await new Promise((rs, rj) => {
  891. if (url._loaded) {
  892. rs(url);
  893. return;
  894. }
  895. if (~url.indexOf("data:image")) {
  896. let tempFilePath = url, imageInfoR = {};
  897. imgTools.base64ToPath(url).then((t) => {
  898. tempFilePath = t;
  899. uni.getImageInfo({
  900. src: tempFilePath,
  901. success: (imgInfo) => {
  902. imageInfoR = imgInfo;
  903. const uniImg = new String(tempFilePath);
  904. for (const i in imageInfoR)
  905. uniImg[i] = imageInfoR[i];
  906. uniImg._loaded = true;
  907. rs(uniImg);
  908. },
  909. fail: (err) => rj(err)
  910. });
  911. }).catch((err) => {
  912. rj(err);
  913. });
  914. } else if (url.substr(0, 4) == "http") {
  915. uni.downloadFile({
  916. url,
  917. success: ({ tempFilePath }) => {
  918. uni.getImageInfo({
  919. src: tempFilePath,
  920. success: (imageInfoR) => {
  921. const uniImg = new String(tempFilePath);
  922. for (const i in imageInfoR)
  923. uniImg[i] = imageInfoR[i];
  924. uniImg._loaded = true;
  925. rs(uniImg);
  926. },
  927. fail: (err) => rj(err)
  928. });
  929. },
  930. fail: (error) => rj(error)
  931. });
  932. } else {
  933. uni.getImageInfo({
  934. src: url,
  935. success: (imageInfoR) => {
  936. const uniImg = new String(url);
  937. for (const i in imageInfoR)
  938. uniImg[i] = imageInfoR[i];
  939. uniImg._loaded = true;
  940. rs(uniImg);
  941. },
  942. fail: (err) => rj(err)
  943. });
  944. }
  945. });
  946. break;
  947. case "web":
  948. img = await new Promise((rs, rj) => {
  949. if (typeof url != "string") {
  950. rs(url);
  951. return;
  952. }
  953. const imgObj = new Image();
  954. imgObj.onload = () => {
  955. rs(imgObj);
  956. };
  957. imgObj.onerror = (err) => {
  958. rj(err);
  959. };
  960. imgObj.src = url;
  961. });
  962. break;
  963. case "node":
  964. img = await new Promise((rs, rj) => {
  965. if (typeof url != "string") {
  966. rs(url);
  967. return;
  968. }
  969. nodeCanvas.loadImage(url).then((res) => {
  970. rs(res);
  971. }).catch((err) => {
  972. rj(err);
  973. });
  974. });
  975. break;
  976. }
  977. } catch (error) {
  978. reject(error);
  979. }
  980. imgCache[url] = img;
  981. resolve(img);
  982. });
  983. }
  984. drawArray(data) {
  985. return new Promise(async (rs, rj) => {
  986. try {
  987. if (!data) {
  988. rj("drawArray\u9700\u7ED8\u5236\u53C2\u6570\u4E0D\u5B58\u5728");
  989. return;
  990. }
  991. if (!Array.isArray(data)) {
  992. rj("drawArray\u53C2\u6570\u9700\u8981\u662FArray");
  993. return;
  994. }
  995. data = [...data].sort((a, b) => {
  996. var _a, _b;
  997. return ((_a = a == null ? void 0 : a.zIndex) != null ? _a : 0) - ((_b = b == null ? void 0 : b.zIndex) != null ? _b : 0);
  998. });
  999. const arr = [];
  1000. for (let i = 0; i < data.length; i++) {
  1001. const item = data[i];
  1002. let r;
  1003. switch (typeof item) {
  1004. case "function":
  1005. r = item();
  1006. if (typeof (r == null ? void 0 : r.then) == "function")
  1007. r = await r;
  1008. break;
  1009. case "object":
  1010. if (Array.isArray(item))
  1011. r = await this.drawArray(item);
  1012. else
  1013. r = await this.drawItem(item);
  1014. break;
  1015. }
  1016. arr.push({ item, result: r });
  1017. }
  1018. rs(arr);
  1019. } catch (error) {
  1020. rj(error);
  1021. }
  1022. });
  1023. }
  1024. drawItem(obj = {}) {
  1025. return new Promise(async (rs, rj) => {
  1026. var _a, _b;
  1027. try {
  1028. let r;
  1029. switch (obj.type) {
  1030. case "text":
  1031. r = await this.drawText(obj);
  1032. break;
  1033. case "image":
  1034. r = await this.drawImg(obj);
  1035. break;
  1036. case "qrcode":
  1037. r = await this.drawQrCode(obj);
  1038. break;
  1039. case "method":
  1040. r = (_a = this[obj.name]) == null ? void 0 : _a.call(this, ...obj.data ? Array.isArray(obj.data) ? obj.data : [obj.data] : []);
  1041. if (typeof (r == null ? void 0 : r.then) == "function")
  1042. r = await r;
  1043. break;
  1044. case "function":
  1045. r = (_b = obj.val) == null ? void 0 : _b.call(obj);
  1046. if (typeof (r == null ? void 0 : r.then) == "function")
  1047. r = await r;
  1048. break;
  1049. }
  1050. rs(r);
  1051. } catch (error) {
  1052. rj(error);
  1053. }
  1054. });
  1055. }
  1056. drawRichText(html) {
  1057. return new Promise(async (rs, rj) => {
  1058. if (!html) {
  1059. rj("drawRichText\u9700\u7ED8\u5236\u53C2\u6570\u4E0D\u5B58\u5728");
  1060. return;
  1061. }
  1062. if (typeof html == "string")
  1063. html = htmlParse(html);
  1064. const result = [];
  1065. function run(arr, parent) {
  1066. return new Promise(async (res, rej) => {
  1067. var _a;
  1068. for (let i = 0; i < arr.length; i++) {
  1069. const item = arr[i];
  1070. if (item.type == "text") {
  1071. } else {
  1072. switch (item.name) {
  1073. case "img":
  1074. break;
  1075. }
  1076. }
  1077. result.push(item);
  1078. if ((_a = item.children) == null ? void 0 : _a.length) {
  1079. item.__handle = function(obj) {
  1080. };
  1081. try {
  1082. await run(item.children, item);
  1083. } catch (error) {
  1084. rej(error);
  1085. return;
  1086. }
  1087. }
  1088. }
  1089. res(result);
  1090. });
  1091. }
  1092. try {
  1093. rs({ html, htmlParses: await run(html) });
  1094. } catch (error) {
  1095. rj(error);
  1096. }
  1097. });
  1098. }
  1099. };
  1100. let QSCanvas2 = _QSCanvas;
  1101. _nc = new WeakMap();
  1102. function filterPaintbrushProps(obj) {
  1103. switch (obj == null ? void 0 : obj.textBaseline) {
  1104. case "normal":
  1105. if (isUni)
  1106. obj.textBaseline = "alphabetic";
  1107. break;
  1108. case "hanging":
  1109. if (isUni)
  1110. obj.textBaseline = "top";
  1111. break;
  1112. case "ideographic":
  1113. if (isUni)
  1114. obj.textBaseline = "bottom";
  1115. break;
  1116. }
  1117. switch (obj == null ? void 0 : obj.textAlign) {
  1118. case "start":
  1119. obj.textAlign = "left";
  1120. break;
  1121. case "end":
  1122. obj.textAlign = "right";
  1123. break;
  1124. }
  1125. }
  1126. function hump2Hyphen(s) {
  1127. return s.replace(/([A-Z])/g, "-$1").toLowerCase();
  1128. }
  1129. function hyphen2Hump(s) {
  1130. if (!s)
  1131. return "";
  1132. const arr = s.split("-");
  1133. for (var i = 1; i < arr.length; i++) {
  1134. arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].substring(1);
  1135. }
  1136. return arr.join("");
  1137. }
  1138. function getPoints(x1, y1, x2, y2, pointCount, level) {
  1139. let a, b, rSquare, k, kv, points = [];
  1140. if (x1 === x2) {
  1141. a = x1 + (y2 - y1) * level;
  1142. b = y1 + (y2 - y1) / 2;
  1143. rSquare = (x1 - a) ** 2 + (y1 - b) ** 2;
  1144. } else if (y1 === y2) {
  1145. a = x1 + (x2 - x1) / 2;
  1146. b = y1 - (x2 - x1) * level;
  1147. rSquare = (x1 - a) ** 2 + (y1 - b) ** 2;
  1148. } else {
  1149. let xc = (x1 + x2) / 2, yc = (y1 + y2) / 2, lenSquare = ((x2 - x1) ** 2 + (y2 - y1) ** 2) * level ** 2;
  1150. k = (x2 - x1) / (y1 - y2);
  1151. let l = yc - k * xc;
  1152. let a1 = 1 + k ** 2, b1 = 2 * k * (l - yc) - 2 * xc, c1 = xc ** 2 + (l - yc) ** 2 - lenSquare;
  1153. kv = -1 / k;
  1154. a = (-b1 + Math.sqrt(b1 ** 2 - 4 * a1 * c1) * (kv > 0 && x2 > x1 || kv < 0 && x2 < x1 ? 1 : -1)) / (2 * a1);
  1155. b = k * a + l;
  1156. rSquare = (x1 - a) ** 2 + (y1 - b) ** 2;
  1157. }
  1158. if (x1 === x2 || Math.abs(kv) > 1) {
  1159. let yDistance = y2 - y1;
  1160. let yDis = yDistance / (pointCount + 1);
  1161. for (let i = 0; i < pointCount; i++) {
  1162. let y = y1 + yDis * (i + 1);
  1163. let x = Math.sqrt(rSquare - (y - b) ** 2) * (y2 > y1 ? -1 : 1) + a;
  1164. points.push([x, y]);
  1165. }
  1166. } else {
  1167. let xDistance = x2 - x1;
  1168. let xDis = xDistance / (pointCount + 1);
  1169. for (let i = 0; i < pointCount; i++) {
  1170. let x = x1 + xDis * (i + 1);
  1171. let y = Math.sqrt(rSquare - (x - a) ** 2) * (x2 > x1 ? 1 : -1) + b;
  1172. points.push([x, y]);
  1173. }
  1174. }
  1175. return points;
  1176. }
  1177. var QRCodeAlg = function() {
  1178. function unicodeFormat8(code) {
  1179. var c0, c1, c2;
  1180. if (code < 128) {
  1181. return [code];
  1182. } else if (code < 2048) {
  1183. c0 = 192 + (code >> 6);
  1184. c1 = 128 + (code & 63);
  1185. return [c0, c1];
  1186. } else {
  1187. c0 = 224 + (code >> 12);
  1188. c1 = 128 + (code >> 6 & 63);
  1189. c2 = 128 + (code & 63);
  1190. return [c0, c1, c2];
  1191. }
  1192. }
  1193. function getUTF8Bytes(string) {
  1194. var utf8codes = [];
  1195. for (var i2 = 0; i2 < string.length; i2++) {
  1196. var code = string.charCodeAt(i2);
  1197. var utf8 = unicodeFormat8(code);
  1198. for (var j = 0; j < utf8.length; j++) {
  1199. utf8codes.push(utf8[j]);
  1200. }
  1201. }
  1202. return utf8codes;
  1203. }
  1204. function QRCodeAlg2(data, errorCorrectLevel) {
  1205. this.typeNumber = -1;
  1206. this.errorCorrectLevel = errorCorrectLevel;
  1207. this.modules = null;
  1208. this.moduleCount = 0;
  1209. this.dataCache = null;
  1210. this.rsBlocks = null;
  1211. this.totalDataCount = -1;
  1212. this.data = data;
  1213. this.utf8bytes = getUTF8Bytes(data);
  1214. this.make();
  1215. }
  1216. QRCodeAlg2.prototype = { constructor: QRCodeAlg2, getModuleCount: function() {
  1217. return this.moduleCount;
  1218. }, make: function() {
  1219. this.getRightType();
  1220. this.dataCache = this.createData();
  1221. this.createQrcode();
  1222. }, makeImpl: function(maskPattern) {
  1223. this.moduleCount = this.typeNumber * 4 + 17;
  1224. this.modules = new Array(this.moduleCount);
  1225. for (var row = 0; row < this.moduleCount; row++) {
  1226. this.modules[row] = new Array(this.moduleCount);
  1227. }
  1228. this.setupPositionProbePattern(0, 0);
  1229. this.setupPositionProbePattern(this.moduleCount - 7, 0);
  1230. this.setupPositionProbePattern(0, this.moduleCount - 7);
  1231. this.setupPositionAdjustPattern();
  1232. this.setupTimingPattern();
  1233. this.setupTypeInfo(true, maskPattern);
  1234. if (this.typeNumber >= 7) {
  1235. this.setupTypeNumber(true);
  1236. }
  1237. this.mapData(this.dataCache, maskPattern);
  1238. }, setupPositionProbePattern: function(row, col) {
  1239. for (var r = -1; r <= 7; r++) {
  1240. if (row + r <= -1 || this.moduleCount <= row + r)
  1241. continue;
  1242. for (var c = -1; c <= 7; c++) {
  1243. if (col + c <= -1 || this.moduleCount <= col + c)
  1244. continue;
  1245. 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) {
  1246. this.modules[row + r][col + c] = true;
  1247. } else {
  1248. this.modules[row + r][col + c] = false;
  1249. }
  1250. }
  1251. }
  1252. }, createQrcode: function() {
  1253. var minLostPoint = 0;
  1254. var pattern = 0;
  1255. var bestModules = null;
  1256. for (var i2 = 0; i2 < 8; i2++) {
  1257. this.makeImpl(i2);
  1258. var lostPoint = QRUtil.getLostPoint(this);
  1259. if (i2 == 0 || minLostPoint > lostPoint) {
  1260. minLostPoint = lostPoint;
  1261. pattern = i2;
  1262. bestModules = this.modules;
  1263. }
  1264. }
  1265. this.modules = bestModules;
  1266. this.setupTypeInfo(false, pattern);
  1267. if (this.typeNumber >= 7) {
  1268. this.setupTypeNumber(false);
  1269. }
  1270. }, setupTimingPattern: function() {
  1271. for (var r = 8; r < this.moduleCount - 8; r++) {
  1272. if (this.modules[r][6] != null) {
  1273. continue;
  1274. }
  1275. this.modules[r][6] = r % 2 == 0;
  1276. if (this.modules[6][r] != null) {
  1277. continue;
  1278. }
  1279. this.modules[6][r] = r % 2 == 0;
  1280. }
  1281. }, setupPositionAdjustPattern: function() {
  1282. var pos = QRUtil.getPatternPosition(this.typeNumber);
  1283. for (var i2 = 0; i2 < pos.length; i2++) {
  1284. for (var j = 0; j < pos.length; j++) {
  1285. var row = pos[i2];
  1286. var col = pos[j];
  1287. if (this.modules[row][col] != null) {
  1288. continue;
  1289. }
  1290. for (var r = -2; r <= 2; r++) {
  1291. for (var c = -2; c <= 2; c++) {
  1292. if (r == -2 || r == 2 || c == -2 || c == 2 || r == 0 && c == 0) {
  1293. this.modules[row + r][col + c] = true;
  1294. } else {
  1295. this.modules[row + r][col + c] = false;
  1296. }
  1297. }
  1298. }
  1299. }
  1300. }
  1301. }, setupTypeNumber: function(test) {
  1302. var bits = QRUtil.getBCHTypeNumber(this.typeNumber);
  1303. for (var i2 = 0; i2 < 18; i2++) {
  1304. var mod = !test && (bits >> i2 & 1) == 1;
  1305. this.modules[Math.floor(i2 / 3)][i2 % 3 + this.moduleCount - 8 - 3] = mod;
  1306. this.modules[i2 % 3 + this.moduleCount - 8 - 3][Math.floor(i2 / 3)] = mod;
  1307. }
  1308. }, setupTypeInfo: function(test, maskPattern) {
  1309. var data = QRErrorCorrectLevel[this.errorCorrectLevel] << 3 | maskPattern;
  1310. var bits = QRUtil.getBCHTypeInfo(data);
  1311. for (var i2 = 0; i2 < 15; i2++) {
  1312. var mod = !test && (bits >> i2 & 1) == 1;
  1313. if (i2 < 6) {
  1314. this.modules[i2][8] = mod;
  1315. } else if (i2 < 8) {
  1316. this.modules[i2 + 1][8] = mod;
  1317. } else {
  1318. this.modules[this.moduleCount - 15 + i2][8] = mod;
  1319. }
  1320. var mod = !test && (bits >> i2 & 1) == 1;
  1321. if (i2 < 8) {
  1322. this.modules[8][this.moduleCount - i2 - 1] = mod;
  1323. } else if (i2 < 9) {
  1324. this.modules[8][15 - i2 - 1 + 1] = mod;
  1325. } else {
  1326. this.modules[8][15 - i2 - 1] = mod;
  1327. }
  1328. }
  1329. this.modules[this.moduleCount - 8][8] = !test;
  1330. }, createData: function() {
  1331. var buffer = new QRBitBuffer();
  1332. var lengthBits = this.typeNumber > 9 ? 16 : 8;
  1333. buffer.put(4, 4);
  1334. buffer.put(this.utf8bytes.length, lengthBits);
  1335. for (var i2 = 0, l = this.utf8bytes.length; i2 < l; i2++) {
  1336. buffer.put(this.utf8bytes[i2], 8);
  1337. }
  1338. if (buffer.length + 4 <= this.totalDataCount * 8) {
  1339. buffer.put(0, 4);
  1340. }
  1341. while (buffer.length % 8 != 0) {
  1342. buffer.putBit(false);
  1343. }
  1344. while (true) {
  1345. if (buffer.length >= this.totalDataCount * 8) {
  1346. break;
  1347. }
  1348. buffer.put(QRCodeAlg2.PAD0, 8);
  1349. if (buffer.length >= this.totalDataCount * 8) {
  1350. break;
  1351. }
  1352. buffer.put(QRCodeAlg2.PAD1, 8);
  1353. }
  1354. return this.createBytes(buffer);
  1355. }, createBytes: function(buffer) {
  1356. var offset = 0;
  1357. var maxDcCount = 0;
  1358. var maxEcCount = 0;
  1359. var length = this.rsBlock.length / 3;
  1360. var rsBlocks = new Array();
  1361. for (var i2 = 0; i2 < length; i2++) {
  1362. var count = this.rsBlock[i2 * 3 + 0];
  1363. var totalCount = this.rsBlock[i2 * 3 + 1];
  1364. var dataCount = this.rsBlock[i2 * 3 + 2];
  1365. for (var j = 0; j < count; j++) {
  1366. rsBlocks.push([dataCount, totalCount]);
  1367. }
  1368. }
  1369. var dcdata = new Array(rsBlocks.length);
  1370. var ecdata = new Array(rsBlocks.length);
  1371. for (var r = 0; r < rsBlocks.length; r++) {
  1372. var dcCount = rsBlocks[r][0];
  1373. var ecCount = rsBlocks[r][1] - dcCount;
  1374. maxDcCount = Math.max(maxDcCount, dcCount);
  1375. maxEcCount = Math.max(maxEcCount, ecCount);
  1376. dcdata[r] = new Array(dcCount);
  1377. for (var i2 = 0; i2 < dcdata[r].length; i2++) {
  1378. dcdata[r][i2] = 255 & buffer.buffer[i2 + offset];
  1379. }
  1380. offset += dcCount;
  1381. var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
  1382. var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
  1383. var modPoly = rawPoly.mod(rsPoly);
  1384. ecdata[r] = new Array(rsPoly.getLength() - 1);
  1385. for (var i2 = 0; i2 < ecdata[r].length; i2++) {
  1386. var modIndex = i2 + modPoly.getLength() - ecdata[r].length;
  1387. ecdata[r][i2] = modIndex >= 0 ? modPoly.get(modIndex) : 0;
  1388. }
  1389. }
  1390. var data = new Array(this.totalDataCount);
  1391. var index = 0;
  1392. for (var i2 = 0; i2 < maxDcCount; i2++) {
  1393. for (var r = 0; r < rsBlocks.length; r++) {
  1394. if (i2 < dcdata[r].length) {
  1395. data[index++] = dcdata[r][i2];
  1396. }
  1397. }
  1398. }
  1399. for (var i2 = 0; i2 < maxEcCount; i2++) {
  1400. for (var r = 0; r < rsBlocks.length; r++) {
  1401. if (i2 < ecdata[r].length) {
  1402. data[index++] = ecdata[r][i2];
  1403. }
  1404. }
  1405. }
  1406. return data;
  1407. }, mapData: function(data, maskPattern) {
  1408. var inc = -1;
  1409. var row = this.moduleCount - 1;
  1410. var bitIndex = 7;
  1411. var byteIndex = 0;
  1412. for (var col = this.moduleCount - 1; col > 0; col -= 2) {
  1413. if (col == 6)
  1414. col--;
  1415. while (true) {
  1416. for (var c = 0; c < 2; c++) {
  1417. if (this.modules[row][col - c] == null) {
  1418. var dark = false;
  1419. if (byteIndex < data.length) {
  1420. dark = (data[byteIndex] >>> bitIndex & 1) == 1;
  1421. }
  1422. var mask = QRUtil.getMask(maskPattern, row, col - c);
  1423. if (mask) {
  1424. dark = !dark;
  1425. }
  1426. this.modules[row][col - c] = dark;
  1427. bitIndex--;
  1428. if (bitIndex == -1) {
  1429. byteIndex++;
  1430. bitIndex = 7;
  1431. }
  1432. }
  1433. }
  1434. row += inc;
  1435. if (row < 0 || this.moduleCount <= row) {
  1436. row -= inc;
  1437. inc = -inc;
  1438. break;
  1439. }
  1440. }
  1441. }
  1442. } };
  1443. QRCodeAlg2.PAD0 = 236;
  1444. QRCodeAlg2.PAD1 = 17;
  1445. var QRErrorCorrectLevel = [1, 0, 3, 2];
  1446. var QRMaskPattern = { PATTERN000: 0, PATTERN001: 1, PATTERN010: 2, PATTERN011: 3, PATTERN100: 4, PATTERN101: 5, PATTERN110: 6, PATTERN111: 7 };
  1447. var QRUtil = { PATTERN_POSITION_TABLE: [[], [6, 18], [6, 22], [6, 26], [6, 30], [6, 34], [6, 22, 38], [6, 24, 42], [6, 26, 46], [6, 28, 50], [6, 30, 54], [6, 32, 58], [6, 34, 62], [6, 26, 46, 66], [6, 26, 48, 70], [6, 26, 50, 74], [6, 30, 54, 78], [6, 30, 56, 82], [6, 30, 58, 86], [6, 34, 62, 90], [6, 28, 50, 72, 94], [6, 26, 50, 74, 98], [6, 30, 54, 78, 102], [6, 28, 54, 80, 106], [6, 32, 58, 84, 110], [6, 30, 58, 86, 114], [6, 34, 62, 90, 118], [6, 26, 50, 74, 98, 122], [6, 30, 54, 78, 102, 126], [6, 26, 52, 78, 104, 130], [6, 30, 56, 82, 108, 134], [6, 34, 60, 86, 112, 138], [6, 30, 58, 86, 114, 142], [6, 34, 62, 90, 118, 146], [6, 30, 54, 78, 102, 126, 150], [6, 24, 50, 76, 102, 128, 154], [6, 28, 54, 80, 106, 132, 158], [6, 32, 58, 84, 110, 136, 162], [6, 26, 54, 82, 110, 138, 166], [6, 30, 58, 86, 114, 142, 170]], G15: 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0, G18: 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0, G15_MASK: 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1, getBCHTypeInfo: function(data) {
  1448. var d = data << 10;
  1449. while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
  1450. d ^= QRUtil.G15 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15);
  1451. }
  1452. return (data << 10 | d) ^ QRUtil.G15_MASK;
  1453. }, getBCHTypeNumber: function(data) {
  1454. var d = data << 12;
  1455. while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
  1456. d ^= QRUtil.G18 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18);
  1457. }
  1458. return data << 12 | d;
  1459. }, getBCHDigit: function(data) {
  1460. var digit = 0;
  1461. while (data != 0) {
  1462. digit++;
  1463. data >>>= 1;
  1464. }
  1465. return digit;
  1466. }, getPatternPosition: function(typeNumber) {
  1467. return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];
  1468. }, getMask: function(maskPattern, i2, j) {
  1469. switch (maskPattern) {
  1470. case QRMaskPattern.PATTERN000:
  1471. return (i2 + j) % 2 == 0;
  1472. case QRMaskPattern.PATTERN001:
  1473. return i2 % 2 == 0;
  1474. case QRMaskPattern.PATTERN010:
  1475. return j % 3 == 0;
  1476. case QRMaskPattern.PATTERN011:
  1477. return (i2 + j) % 3 == 0;
  1478. case QRMaskPattern.PATTERN100:
  1479. return (Math.floor(i2 / 2) + Math.floor(j / 3)) % 2 == 0;
  1480. case QRMaskPattern.PATTERN101:
  1481. return i2 * j % 2 + i2 * j % 3 == 0;
  1482. case QRMaskPattern.PATTERN110:
  1483. return (i2 * j % 2 + i2 * j % 3) % 2 == 0;
  1484. case QRMaskPattern.PATTERN111:
  1485. return (i2 * j % 3 + (i2 + j) % 2) % 2 == 0;
  1486. default:
  1487. throw new Error("bad maskPattern:" + maskPattern);
  1488. }
  1489. }, getErrorCorrectPolynomial: function(errorCorrectLength) {
  1490. var a = new QRPolynomial([1], 0);
  1491. for (var i2 = 0; i2 < errorCorrectLength; i2++) {
  1492. a = a.multiply(new QRPolynomial([1, QRMath.gexp(i2)], 0));
  1493. }
  1494. return a;
  1495. }, getLostPoint: function(qrCode) {
  1496. var moduleCount = qrCode.getModuleCount(), lostPoint = 0, darkCount = 0;
  1497. for (var row = 0; row < moduleCount; row++) {
  1498. var sameCount = 0;
  1499. var head = qrCode.modules[row][0];
  1500. for (var col = 0; col < moduleCount; col++) {
  1501. var current = qrCode.modules[row][col];
  1502. if (col < moduleCount - 6) {
  1503. if (current && !qrCode.modules[row][col + 1] && qrCode.modules[row][col + 2] && qrCode.modules[row][col + 3] && qrCode.modules[row][col + 4] && !qrCode.modules[row][col + 5] && qrCode.modules[row][col + 6]) {
  1504. if (col < moduleCount - 10) {
  1505. if (qrCode.modules[row][col + 7] && qrCode.modules[row][col + 8] && qrCode.modules[row][col + 9] && qrCode.modules[row][col + 10]) {
  1506. lostPoint += 40;
  1507. }
  1508. } else if (col > 3) {
  1509. if (qrCode.modules[row][col - 1] && qrCode.modules[row][col - 2] && qrCode.modules[row][col - 3] && qrCode.modules[row][col - 4]) {
  1510. lostPoint += 40;
  1511. }
  1512. }
  1513. }
  1514. }
  1515. if (row < moduleCount - 1 && col < moduleCount - 1) {
  1516. var count = 0;
  1517. if (current)
  1518. count++;
  1519. if (qrCode.modules[row + 1][col])
  1520. count++;
  1521. if (qrCode.modules[row][col + 1])
  1522. count++;
  1523. if (qrCode.modules[row + 1][col + 1])
  1524. count++;
  1525. if (count == 0 || count == 4) {
  1526. lostPoint += 3;
  1527. }
  1528. }
  1529. if (head ^ current) {
  1530. sameCount++;
  1531. } else {
  1532. head = current;
  1533. if (sameCount >= 5) {
  1534. lostPoint += 3 + sameCount - 5;
  1535. }
  1536. sameCount = 1;
  1537. }
  1538. if (current) {
  1539. darkCount++;
  1540. }
  1541. }
  1542. }
  1543. for (var col = 0; col < moduleCount; col++) {
  1544. var sameCount = 0;
  1545. var head = qrCode.modules[0][col];
  1546. for (var row = 0; row < moduleCount; row++) {
  1547. var current = qrCode.modules[row][col];
  1548. if (row < moduleCount - 6) {
  1549. if (current && !qrCode.modules[row + 1][col] && qrCode.modules[row + 2][col] && qrCode.modules[row + 3][col] && qrCode.modules[row + 4][col] && !qrCode.modules[row + 5][col] && qrCode.modules[row + 6][col]) {
  1550. if (row < moduleCount - 10) {
  1551. if (qrCode.modules[row + 7][col] && qrCode.modules[row + 8][col] && qrCode.modules[row + 9][col] && qrCode.modules[row + 10][col]) {
  1552. lostPoint += 40;
  1553. }
  1554. } else if (row > 3) {
  1555. if (qrCode.modules[row - 1][col] && qrCode.modules[row - 2][col] && qrCode.modules[row - 3][col] && qrCode.modules[row - 4][col]) {
  1556. lostPoint += 40;
  1557. }
  1558. }
  1559. }
  1560. }
  1561. if (head ^ current) {
  1562. sameCount++;
  1563. } else {
  1564. head = current;
  1565. if (sameCount >= 5) {
  1566. lostPoint += 3 + sameCount - 5;
  1567. }
  1568. sameCount = 1;
  1569. }
  1570. }
  1571. }
  1572. var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
  1573. lostPoint += ratio * 10;
  1574. return lostPoint;
  1575. } };
  1576. var QRMath = { glog: function(n) {
  1577. if (n < 1) {
  1578. throw new Error("glog(" + n + ")");
  1579. }
  1580. return QRMath.LOG_TABLE[n];
  1581. }, gexp: function(n) {
  1582. while (n < 0) {
  1583. n += 255;
  1584. }
  1585. while (n >= 256) {
  1586. n -= 255;
  1587. }
  1588. return QRMath.EXP_TABLE[n];
  1589. }, EXP_TABLE: new Array(256), LOG_TABLE: new Array(256) };
  1590. for (var i = 0; i < 8; i++) {
  1591. QRMath.EXP_TABLE[i] = 1 << i;
  1592. }
  1593. for (var i = 8; i < 256; i++) {
  1594. QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] ^ QRMath.EXP_TABLE[i - 5] ^ QRMath.EXP_TABLE[i - 6] ^ QRMath.EXP_TABLE[i - 8];
  1595. }
  1596. for (var i = 0; i < 255; i++) {
  1597. QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i;
  1598. }
  1599. function QRPolynomial(num, shift) {
  1600. if (num.length == void 0) {
  1601. throw new Error(num.length + "/" + shift);
  1602. }
  1603. var offset = 0;
  1604. while (offset < num.length && num[offset] == 0) {
  1605. offset++;
  1606. }
  1607. this.num = new Array(num.length - offset + shift);
  1608. for (var i2 = 0; i2 < num.length - offset; i2++) {
  1609. this.num[i2] = num[i2 + offset];
  1610. }
  1611. }
  1612. QRPolynomial.prototype = { get: function(index) {
  1613. return this.num[index];
  1614. }, getLength: function() {
  1615. return this.num.length;
  1616. }, multiply: function(e) {
  1617. var num = new Array(this.getLength() + e.getLength() - 1);
  1618. for (var i2 = 0; i2 < this.getLength(); i2++) {
  1619. for (var j = 0; j < e.getLength(); j++) {
  1620. num[i2 + j] ^= QRMath.gexp(QRMath.glog(this.get(i2)) + QRMath.glog(e.get(j)));
  1621. }
  1622. }
  1623. return new QRPolynomial(num, 0);
  1624. }, mod: function(e) {
  1625. var tl = this.getLength(), el = e.getLength();
  1626. if (tl - el < 0) {
  1627. return this;
  1628. }
  1629. var num = new Array(tl);
  1630. for (var i2 = 0; i2 < tl; i2++) {
  1631. num[i2] = this.get(i2);
  1632. }
  1633. while (num.length >= el) {
  1634. var ratio = QRMath.glog(num[0]) - QRMath.glog(e.get(0));
  1635. for (var i2 = 0; i2 < e.getLength(); i2++) {
  1636. num[i2] ^= QRMath.gexp(QRMath.glog(e.get(i2)) + ratio);
  1637. }
  1638. while (num[0] == 0) {
  1639. num.shift();
  1640. }
  1641. }
  1642. return new QRPolynomial(num, 0);
  1643. } };
  1644. var RS_BLOCK_TABLE = [[1, 26, 19], [1, 26, 16], [1, 26, 13], [1, 26, 9], [1, 44, 34], [1, 44, 28], [1, 44, 22], [1, 44, 16], [1, 70, 55], [1, 70, 44], [2, 35, 17], [2, 35, 13], [1, 100, 80], [2, 50, 32], [2, 50, 24], [4, 25, 9], [1, 134, 108], [2, 67, 43], [2, 33, 15, 2, 34, 16], [2, 33, 11, 2, 34, 12], [2, 86, 68], [4, 43, 27], [4, 43, 19], [4, 43, 15], [2, 98, 78], [4, 49, 31], [2, 32, 14, 4, 33, 15], [4, 39, 13, 1, 40, 14], [2, 121, 97], [2, 60, 38, 2, 61, 39], [4, 40, 18, 2, 41, 19], [4, 40, 14, 2, 41, 15], [2, 146, 116], [3, 58, 36, 2, 59, 37], [4, 36, 16, 4, 37, 17], [4, 36, 12, 4, 37, 13], [2, 86, 68, 2, 87, 69], [4, 69, 43, 1, 70, 44], [6, 43, 19, 2, 44, 20], [6, 43, 15, 2, 44, 16], [4, 101, 81], [1, 80, 50, 4, 81, 51], [4, 50, 22, 4, 51, 23], [3, 36, 12, 8, 37, 13], [2, 116, 92, 2, 117, 93], [6, 58, 36, 2, 59, 37], [4, 46, 20, 6, 47, 21], [7, 42, 14, 4, 43, 15], [4, 133, 107], [8, 59, 37, 1, 60, 38], [8, 44, 20, 4, 45, 21], [12, 33, 11, 4, 34, 12], [3, 145, 115, 1, 146, 116], [4, 64, 40, 5, 65, 41], [11, 36, 16, 5, 37, 17], [11, 36, 12, 5, 37, 13], [5, 109, 87, 1, 110, 88], [5, 65, 41, 5, 66, 42], [5, 54, 24, 7, 55, 25], [11, 36, 12], [5, 122, 98, 1, 123, 99], [7, 73, 45, 3, 74, 46], [15, 43, 19, 2, 44, 20], [3, 45, 15, 13, 46, 16], [1, 135, 107, 5, 136, 108], [10, 74, 46, 1, 75, 47], [1, 50, 22, 15, 51, 23], [2, 42, 14, 17, 43, 15], [5, 150, 120, 1, 151, 121], [9, 69, 43, 4, 70, 44], [17, 50, 22, 1, 51, 23], [2, 42, 14, 19, 43, 15], [3, 141, 113, 4, 142, 114], [3, 70, 44, 11, 71, 45], [17, 47, 21, 4, 48, 22], [9, 39, 13, 16, 40, 14], [3, 135, 107, 5, 136, 108], [3, 67, 41, 13, 68, 42], [15, 54, 24, 5, 55, 25], [15, 43, 15, 10, 44, 16], [4, 144, 116, 4, 145, 117], [17, 68, 42], [17, 50, 22, 6, 51, 23], [19, 46, 16, 6, 47, 17], [2, 139, 111, 7, 140, 112], [17, 74, 46], [7, 54, 24, 16, 55, 25], [34, 37, 13], [4, 151, 121, 5, 152, 122], [4, 75, 47, 14, 76, 48], [11, 54, 24, 14, 55, 25], [16, 45, 15, 14, 46, 16], [6, 147, 117, 4, 148, 118], [6, 73, 45, 14, 74, 46], [11, 54, 24, 16, 55, 25], [30, 46, 16, 2, 47, 17], [8, 132, 106, 4, 133, 107], [8, 75, 47, 13, 76, 48], [7, 54, 24, 22, 55, 25], [22, 45, 15, 13, 46, 16], [10, 142, 114, 2, 143, 115], [19, 74, 46, 4, 75, 47], [28, 50, 22, 6, 51, 23], [33, 46, 16, 4, 47, 17], [8, 152, 122, 4, 153, 123], [22, 73, 45, 3, 74, 46], [8, 53, 23, 26, 54, 24], [12, 45, 15, 28, 46, 16], [3, 147, 117, 10, 148, 118], [3, 73, 45, 23, 74, 46], [4, 54, 24, 31, 55, 25], [11, 45, 15, 31, 46, 16], [7, 146, 116, 7, 147, 117], [21, 73, 45, 7, 74, 46], [1, 53, 23, 37, 54, 24], [19, 45, 15, 26, 46, 16], [5, 145, 115, 10, 146, 116], [19, 75, 47, 10, 76, 48], [15, 54, 24, 25, 55, 25], [23, 45, 15, 25, 46, 16], [13, 145, 115, 3, 146, 116], [2, 74, 46, 29, 75, 47], [42, 54, 24, 1, 55, 25], [23, 45, 15, 28, 46, 16], [17, 145, 115], [10, 74, 46, 23, 75, 47], [10, 54, 24, 35, 55, 25], [19, 45, 15, 35, 46, 16], [17, 145, 115, 1, 146, 116], [14, 74, 46, 21, 75, 47], [29, 54, 24, 19, 55, 25], [11, 45, 15, 46, 46, 16], [13, 145, 115, 6, 146, 116], [14, 74, 46, 23, 75, 47], [44, 54, 24, 7, 55, 25], [59, 46, 16, 1, 47, 17], [12, 151, 121, 7, 152, 122], [12, 75, 47, 26, 76, 48], [39, 54, 24, 14, 55, 25], [22, 45, 15, 41, 46, 16], [6, 151, 121, 14, 152, 122], [6, 75, 47, 34, 76, 48], [46, 54, 24, 10, 55, 25], [2, 45, 15, 64, 46, 16], [17, 152, 122, 4, 153, 123], [29, 74, 46, 14, 75, 47], [49, 54, 24, 10, 55, 25], [24, 45, 15, 46, 46, 16], [4, 152, 122, 18, 153, 123], [13, 74, 46, 32, 75, 47], [48, 54, 24, 14, 55, 25], [42, 45, 15, 32, 46, 16], [20, 147, 117, 4, 148, 118], [40, 75, 47, 7, 76, 48], [43, 54, 24, 22, 55, 25], [10, 45, 15, 67, 46, 16], [19, 148, 118, 6, 149, 119], [18, 75, 47, 31, 76, 48], [34, 54, 24, 34, 55, 25], [20, 45, 15, 61, 46, 16]];
  1645. QRCodeAlg2.prototype.getRightType = function() {
  1646. for (var typeNumber = 1; typeNumber < 41; typeNumber++) {
  1647. var rsBlock = RS_BLOCK_TABLE[(typeNumber - 1) * 4 + this.errorCorrectLevel];
  1648. if (rsBlock == void 0) {
  1649. throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + this.errorCorrectLevel);
  1650. }
  1651. var length = rsBlock.length / 3;
  1652. var totalDataCount = 0;
  1653. for (var i2 = 0; i2 < length; i2++) {
  1654. var count = rsBlock[i2 * 3 + 0];
  1655. var dataCount = rsBlock[i2 * 3 + 2];
  1656. totalDataCount += dataCount * count;
  1657. }
  1658. var lengthBytes = typeNumber > 9 ? 2 : 1;
  1659. if (this.utf8bytes.length + lengthBytes < totalDataCount || typeNumber == 40) {
  1660. this.typeNumber = typeNumber;
  1661. this.rsBlock = rsBlock;
  1662. this.totalDataCount = totalDataCount;
  1663. break;
  1664. }
  1665. }
  1666. };
  1667. function QRBitBuffer() {
  1668. this.buffer = new Array();
  1669. this.length = 0;
  1670. }
  1671. QRBitBuffer.prototype = { get: function(index) {
  1672. var bufIndex = Math.floor(index / 8);
  1673. return this.buffer[bufIndex] >>> 7 - index % 8 & 1;
  1674. }, put: function(num, length) {
  1675. for (var i2 = 0; i2 < length; i2++) {
  1676. this.putBit(num >>> length - i2 - 1 & 1);
  1677. }
  1678. }, putBit: function(bit) {
  1679. var bufIndex = Math.floor(this.length / 8);
  1680. if (this.buffer.length <= bufIndex) {
  1681. this.buffer.push(0);
  1682. }
  1683. if (bit) {
  1684. this.buffer[bufIndex] |= 128 >>> this.length % 8;
  1685. }
  1686. this.length++;
  1687. } };
  1688. return QRCodeAlg2;
  1689. }();
  1690. var htmlParse = function() {
  1691. var startTag = /^<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/;
  1692. var endTag = /^<\/([-A-Za-z0-9_]+)[^>]*>/;
  1693. var attr = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;
  1694. var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr");
  1695. var block = makeMap("a,address,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video");
  1696. var inline = makeMap("abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var");
  1697. var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");
  1698. var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");
  1699. var special = makeMap("script,style");
  1700. function HTMLParser(html, handler) {
  1701. var index;
  1702. var chars;
  1703. var match;
  1704. var stack = [];
  1705. var last = html;
  1706. stack.last = function() {
  1707. return this[this.length - 1];
  1708. };
  1709. while (html) {
  1710. chars = true;
  1711. if (!stack.last() || !special[stack.last()]) {
  1712. if (html.indexOf("<!--") == 0) {
  1713. index = html.indexOf("-->");
  1714. if (index >= 0) {
  1715. if (handler.comment) {
  1716. handler.comment(html.substring(4, index));
  1717. }
  1718. html = html.substring(index + 3);
  1719. chars = false;
  1720. }
  1721. } else if (html.indexOf("</") == 0) {
  1722. match = html.match(endTag);
  1723. if (match) {
  1724. html = html.substring(match[0].length);
  1725. match[0].replace(endTag, parseEndTag);
  1726. chars = false;
  1727. }
  1728. } else if (html.indexOf("<") == 0) {
  1729. match = html.match(startTag);
  1730. if (match) {
  1731. html = html.substring(match[0].length);
  1732. match[0].replace(startTag, parseStartTag);
  1733. chars = false;
  1734. }
  1735. }
  1736. if (chars) {
  1737. index = html.indexOf("<");
  1738. var text = index < 0 ? html : html.substring(0, index);
  1739. html = index < 0 ? "" : html.substring(index);
  1740. if (handler.chars) {
  1741. handler.chars(text);
  1742. }
  1743. }
  1744. } else {
  1745. html = html.replace(new RegExp("([\\s\\S]*?)</" + stack.last() + "[^>]*>"), function(all, text2) {
  1746. text2 = text2.replace(/<!--([\s\S]*?)-->|<!\[CDATA\[([\s\S]*?)]]>/g, "$1$2");
  1747. if (handler.chars) {
  1748. handler.chars(text2);
  1749. }
  1750. return "";
  1751. });
  1752. parseEndTag("", stack.last());
  1753. }
  1754. if (html == last) {
  1755. throw "Parse Error: " + html;
  1756. }
  1757. last = html;
  1758. }
  1759. parseEndTag();
  1760. function parseStartTag(tag, tagName, rest, unary) {
  1761. tagName = tagName.toLowerCase();
  1762. if (block[tagName]) {
  1763. while (stack.last() && inline[stack.last()]) {
  1764. parseEndTag("", stack.last());
  1765. }
  1766. }
  1767. if (closeSelf[tagName] && stack.last() == tagName) {
  1768. parseEndTag("", tagName);
  1769. }
  1770. unary = empty[tagName] || !!unary;
  1771. if (!unary) {
  1772. stack.push(tagName);
  1773. }
  1774. if (handler.start) {
  1775. var attrs = [];
  1776. rest.replace(attr, function(match2, name) {
  1777. var value = arguments[2] ? arguments[2] : arguments[3] ? arguments[3] : arguments[4] ? arguments[4] : fillAttrs[name] ? name : "";
  1778. attrs.push({ name, value, escaped: value.replace(/(^|[^\\])"/g, '$1\\"') });
  1779. });
  1780. if (handler.start) {
  1781. handler.start(tagName, attrs, unary);
  1782. }
  1783. }
  1784. }
  1785. function parseEndTag(tag, tagName) {
  1786. if (!tagName) {
  1787. var pos = 0;
  1788. } else {
  1789. for (var pos = stack.length - 1; pos >= 0; pos--) {
  1790. if (stack[pos] == tagName) {
  1791. break;
  1792. }
  1793. }
  1794. }
  1795. if (pos >= 0) {
  1796. for (var i = stack.length - 1; i >= pos; i--) {
  1797. if (handler.end) {
  1798. handler.end(stack[i]);
  1799. }
  1800. }
  1801. stack.length = pos;
  1802. }
  1803. }
  1804. }
  1805. function makeMap(str) {
  1806. var obj = {};
  1807. var items = str.split(",");
  1808. for (var i = 0; i < items.length; i++) {
  1809. obj[items[i]] = true;
  1810. }
  1811. return obj;
  1812. }
  1813. function removeDOCTYPE(html) {
  1814. return html.replace(/<\?xml.*\?>\n/, "").replace(/<!doctype.*>\n/, "").replace(/<!DOCTYPE.*>\n/, "");
  1815. }
  1816. function parseAttrs(attrs) {
  1817. return attrs.reduce(function(pre, attr2) {
  1818. var value = attr2.value;
  1819. var name = attr2.name;
  1820. if (pre[name]) {
  1821. pre[name] = pre[name] + " " + value;
  1822. } else {
  1823. pre[name] = value;
  1824. }
  1825. return pre;
  1826. }, {});
  1827. }
  1828. function parseHtml(html) {
  1829. html = removeDOCTYPE(html);
  1830. var stacks = [];
  1831. var results = { node: "root", children: [] };
  1832. HTMLParser(html, { start: function start(tag, attrs, unary) {
  1833. var node = { name: tag };
  1834. if (attrs.length !== 0) {
  1835. node.attrs = parseAttrs(attrs);
  1836. }
  1837. if (unary) {
  1838. var parent = stacks[0] || results;
  1839. if (!parent.children) {
  1840. parent.children = [];
  1841. }
  1842. parent.children.push(node);
  1843. } else {
  1844. stacks.unshift(node);
  1845. }
  1846. }, end: function end(tag) {
  1847. var node = stacks.shift();
  1848. if (node.name !== tag)
  1849. console.error("invalid state: mismatch end tag");
  1850. if (stacks.length === 0) {
  1851. results.children.push(node);
  1852. } else {
  1853. var parent = stacks[0];
  1854. if (!parent.children) {
  1855. parent.children = [];
  1856. }
  1857. parent.children.push(node);
  1858. }
  1859. }, chars: function chars(text) {
  1860. var node = { type: "text", text };
  1861. if (stacks.length === 0) {
  1862. results.children.push(node);
  1863. } else {
  1864. var parent = stacks[0];
  1865. if (!parent.children) {
  1866. parent.children = [];
  1867. }
  1868. parent.children.push(node);
  1869. }
  1870. }, comment: function comment(text) {
  1871. var node = { node: "comment", text };
  1872. var parent = stacks[0];
  1873. if (!parent.children) {
  1874. parent.children = [];
  1875. }
  1876. parent.children.push(node);
  1877. } });
  1878. return results.children;
  1879. }
  1880. return parseHtml;
  1881. }();
  1882. var imgTools = function() {
  1883. function getLocalFilePath(path) {
  1884. if (path.indexOf("_www") === 0 || path.indexOf("_doc") === 0 || path.indexOf("_documents") === 0 || path.indexOf("_downloads") === 0) {
  1885. return path;
  1886. }
  1887. if (path.indexOf("file://") === 0) {
  1888. return path;
  1889. }
  1890. if (path.indexOf("/storage/emulated/0/") === 0) {
  1891. return path;
  1892. }
  1893. if (path.indexOf("/") === 0) {
  1894. var localFilePath = plus.io.convertAbsoluteFileSystem(path);
  1895. if (localFilePath !== path) {
  1896. return localFilePath;
  1897. } else {
  1898. path = path.substr(1);
  1899. }
  1900. }
  1901. return "_www/" + path;
  1902. }
  1903. function dataUrlToBase64(str) {
  1904. var array = str.split(",");
  1905. return array[array.length - 1];
  1906. }
  1907. var index = 0;
  1908. function getNewFileId() {
  1909. return Date.now() + String(index++);
  1910. }
  1911. function biggerThan(v1, v2) {
  1912. var v1Array = v1.split(".");
  1913. var v2Array = v2.split(".");
  1914. var update = false;
  1915. for (var index2 = 0; index2 < v2Array.length; index2++) {
  1916. var diff = v1Array[index2] - v2Array[index2];
  1917. if (diff !== 0) {
  1918. update = diff > 0;
  1919. break;
  1920. }
  1921. }
  1922. return update;
  1923. }
  1924. function pathToBase64(path) {
  1925. return new Promise(function(resolve, reject) {
  1926. if (typeof window === "object" && "document" in window) {
  1927. if (typeof FileReader === "function") {
  1928. var xhr = new XMLHttpRequest();
  1929. xhr.open("GET", path, true);
  1930. xhr.responseType = "blob";
  1931. xhr.onload = function() {
  1932. if (this.status === 200) {
  1933. let fileReader = new FileReader();
  1934. fileReader.onload = function(e) {
  1935. resolve(e.target.result);
  1936. };
  1937. fileReader.onerror = reject;
  1938. fileReader.readAsDataURL(this.response);
  1939. }
  1940. };
  1941. xhr.onerror = reject;
  1942. xhr.send();
  1943. return;
  1944. }
  1945. var canvas = document.createElement("canvas");
  1946. var c2x = canvas.getContext("2d");
  1947. var img = new Image();
  1948. img.onload = function() {
  1949. canvas.width = img.width;
  1950. canvas.height = img.height;
  1951. c2x.drawImage(img, 0, 0);
  1952. resolve(canvas.toDataURL());
  1953. canvas.height = canvas.width = 0;
  1954. };
  1955. img.onerror = reject;
  1956. img.src = path;
  1957. return;
  1958. }
  1959. if (typeof plus === "object") {
  1960. plus.io.resolveLocalFileSystemURL(getLocalFilePath(path), function(entry) {
  1961. entry.file(function(file) {
  1962. var fileReader = new plus.io.FileReader();
  1963. fileReader.onload = function(data) {
  1964. resolve(data.target.result);
  1965. };
  1966. fileReader.onerror = function(error) {
  1967. reject(error);
  1968. };
  1969. fileReader.readAsDataURL(file);
  1970. }, function(error) {
  1971. reject(error);
  1972. });
  1973. }, function(error) {
  1974. reject(error);
  1975. });
  1976. return;
  1977. }
  1978. if (typeof wx === "object" && wx.canIUse("getFileSystemManager")) {
  1979. wx.getFileSystemManager().readFile({
  1980. filePath: path,
  1981. encoding: "base64",
  1982. success: function(res) {
  1983. resolve("data:image/png;base64," + res.data);
  1984. },
  1985. fail: function(error) {
  1986. reject(error);
  1987. }
  1988. });
  1989. return;
  1990. }
  1991. reject(new Error("not support"));
  1992. });
  1993. }
  1994. function base64ToPath(base64) {
  1995. return new Promise(function(resolve, reject) {
  1996. if (typeof window === "object" && "document" in window) {
  1997. base64 = base64.split(",");
  1998. var type = base64[0].match(/:(.*?);/)[1];
  1999. var str = atob(base64[1]);
  2000. var n = str.length;
  2001. var array = new Uint8Array(n);
  2002. while (n--) {
  2003. array[n] = str.charCodeAt(n);
  2004. }
  2005. return resolve((window.URL || window.webkitURL).createObjectURL(new Blob([array], { type })));
  2006. }
  2007. var extName = base64.split(",")[0].match(/data\:\S+\/(\S+);/);
  2008. if (extName) {
  2009. extName = extName[1];
  2010. } else {
  2011. reject(new Error("base64 error"));
  2012. }
  2013. var fileName = getNewFileId() + "." + extName;
  2014. if (typeof plus === "object") {
  2015. var basePath = "_doc";
  2016. var dirPath = "uniapp_temp";
  2017. var filePath = basePath + "/" + dirPath + "/" + fileName;
  2018. if (!biggerThan(plus.os.name === "Android" ? "1.9.9.80627" : "1.9.9.80472", plus.runtime.innerVersion)) {
  2019. plus.io.resolveLocalFileSystemURL(basePath, function(entry) {
  2020. entry.getDirectory(dirPath, {
  2021. create: true,
  2022. exclusive: false
  2023. }, function(entry2) {
  2024. entry2.getFile(fileName, {
  2025. create: true,
  2026. exclusive: false
  2027. }, function(entry3) {
  2028. entry3.createWriter(function(writer) {
  2029. writer.onwrite = function() {
  2030. resolve(filePath);
  2031. };
  2032. writer.onerror = reject;
  2033. writer.seek(0);
  2034. writer.writeAsBinary(dataUrlToBase64(base64));
  2035. }, reject);
  2036. }, reject);
  2037. }, reject);
  2038. }, reject);
  2039. return;
  2040. }
  2041. var bitmap = new plus.nativeObj.Bitmap(fileName);
  2042. bitmap.loadBase64Data(base64, function() {
  2043. bitmap.save(filePath, {}, function() {
  2044. bitmap.clear();
  2045. resolve(filePath);
  2046. }, function(error) {
  2047. bitmap.clear();
  2048. reject(error);
  2049. });
  2050. }, function(error) {
  2051. bitmap.clear();
  2052. reject(error);
  2053. });
  2054. return;
  2055. }
  2056. function getEnvPath() {
  2057. var _a, _b, _c, _d, _e, _f;
  2058. if (typeof my === "object" && ((_a = my == null ? void 0 : my.env) == null ? void 0 : _a.USER_DATA_PATH)) {
  2059. return my.env.USER_DATA_PATH;
  2060. }
  2061. if (typeof swan === "object" && ((_b = swan == null ? void 0 : swan.env) == null ? void 0 : _b.USER_DATA_PATH)) {
  2062. return swan.env.USER_DATA_PATH;
  2063. }
  2064. if (typeof tt === "object" && ((_c = tt == null ? void 0 : tt.env) == null ? void 0 : _c.USER_DATA_PATH)) {
  2065. return tt.env.USER_DATA_PATH;
  2066. }
  2067. if (typeof qq === "object" && ((_d = qq == null ? void 0 : qq.env) == null ? void 0 : _d.USER_DATA_PATH)) {
  2068. return qq.env.USER_DATA_PATH;
  2069. }
  2070. if (typeof qh === "object" && ((_e = qh == null ? void 0 : qh.env) == null ? void 0 : _e.USER_DATA_PATH)) {
  2071. return qh.env.USER_DATA_PATH;
  2072. }
  2073. if (typeof wx === "object" && ((_f = wx == null ? void 0 : wx.env) == null ? void 0 : _f.USER_DATA_PATH)) {
  2074. return wx.env.USER_DATA_PATH;
  2075. }
  2076. return "https://user";
  2077. }
  2078. try {
  2079. var filePath = getEnvPath() + "/" + fileName;
  2080. uni.getFileSystemManager().writeFile({
  2081. filePath,
  2082. data: dataUrlToBase64(base64),
  2083. encoding: "base64",
  2084. success: function() {
  2085. resolve(filePath);
  2086. },
  2087. fail: function(error) {
  2088. reject(error);
  2089. }
  2090. });
  2091. } catch (e) {
  2092. reject(new Error("not support"));
  2093. }
  2094. });
  2095. }
  2096. return { pathToBase64, base64ToPath };
  2097. }();
  2098. if (notUnd(typeof module)) {
  2099. module.exports = QSCanvas2;
  2100. }
  2101. return QSCanvas2;
  2102. }();
  2103. }
  2104. });
  2105. export default require_qs_canvas();
  2106. //# sourceMappingURL=qs-canvas.js.map