onelink-smart-script-latest.js 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376
  1. /**
  2. * AF Smart Script (Build 2.10.0)
  3. */
  4. function _arrayLikeToArray(r, a) {
  5. (null == a || a > r.length) && (a = r.length);
  6. for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  7. return n;
  8. }
  9. function _arrayWithHoles(r) {
  10. if (Array.isArray(r)) return r;
  11. }
  12. function _arrayWithoutHoles(r) {
  13. if (Array.isArray(r)) return _arrayLikeToArray(r);
  14. }
  15. function _defineProperty(e, r, t) {
  16. return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
  17. value: t,
  18. enumerable: !0,
  19. configurable: !0,
  20. writable: !0
  21. }) : e[r] = t, e;
  22. }
  23. function _iterableToArray(r) {
  24. if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
  25. }
  26. function _iterableToArrayLimit(r, l) {
  27. var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  28. if (null != t) {
  29. var e,
  30. n,
  31. i,
  32. u,
  33. a = [],
  34. f = !0,
  35. o = !1;
  36. try {
  37. if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
  38. } catch (r) {
  39. o = !0, n = r;
  40. } finally {
  41. try {
  42. if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
  43. } finally {
  44. if (o) throw n;
  45. }
  46. }
  47. return a;
  48. }
  49. }
  50. function _nonIterableRest() {
  51. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  52. }
  53. function _nonIterableSpread() {
  54. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  55. }
  56. function ownKeys(e, r) {
  57. var t = Object.keys(e);
  58. if (Object.getOwnPropertySymbols) {
  59. var o = Object.getOwnPropertySymbols(e);
  60. r && (o = o.filter(function (r) {
  61. return Object.getOwnPropertyDescriptor(e, r).enumerable;
  62. })), t.push.apply(t, o);
  63. }
  64. return t;
  65. }
  66. function _objectSpread2(e) {
  67. for (var r = 1; r < arguments.length; r++) {
  68. var t = null != arguments[r] ? arguments[r] : {};
  69. r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
  70. _defineProperty(e, r, t[r]);
  71. }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
  72. Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
  73. });
  74. }
  75. return e;
  76. }
  77. function _slicedToArray(r, e) {
  78. return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
  79. }
  80. function _toConsumableArray(r) {
  81. return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
  82. }
  83. function _toPrimitive(t, r) {
  84. if ("object" != typeof t || !t) return t;
  85. var e = t[Symbol.toPrimitive];
  86. if (void 0 !== e) {
  87. var i = e.call(t, r || "default");
  88. if ("object" != typeof i) return i;
  89. throw new TypeError("@@toPrimitive must return a primitive value.");
  90. }
  91. return ("string" === r ? String : Number)(t);
  92. }
  93. function _toPropertyKey(t) {
  94. var i = _toPrimitive(t, "string");
  95. return "symbol" == typeof i ? i : i + "";
  96. }
  97. function _typeof(o) {
  98. "@babel/helpers - typeof";
  99. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  100. return typeof o;
  101. } : function (o) {
  102. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  103. }, _typeof(o);
  104. }
  105. function _unsupportedIterableToArray(r, a) {
  106. if (r) {
  107. if ("string" == typeof r) return _arrayLikeToArray(r, a);
  108. var t = {}.toString.call(r).slice(8, -1);
  109. return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  110. }
  111. }
  112. var AF_URL_SCHEME = '(https:\\/\\/)(([^\\.]+).)(.*\\/)(.*)';
  113. var VALID_AF_URL_PARTS_LENGTH = 5;
  114. var GOOGLE_CLICK_ID = 'gclid';
  115. var FACEBOOK_CLICK_ID = 'fbclid';
  116. var TWITTER_CLICK_ID = 'twclid';
  117. var SNAPCHAT_CLICK_ID = 'sccid';
  118. var TIKTOK_CLICK_ID = 'ttclid';
  119. var GBRAID = 'gbraid';
  120. var WBRAID = 'wbraid';
  121. var ASSOCIATED_AD_KEYWORD = 'keyword';
  122. var AF_KEYWORDS = 'af_keywords';
  123. var AF_CUSTOM_EXCLUDE_PARAMS_KEYS = ['pid', 'c', 'af_channel', 'af_ad', 'af_adset', 'deep_link_value', 'af_sub1', 'af_sub2', 'af_sub3', 'af_sub4', 'af_sub5'];
  124. var GCLID_EXCLUDE_PARAMS_KEYS = ['pid', 'c', 'af_channel', 'af_ad', 'af_adset', 'deep_link_value'];
  125. var LOCAL_STORAGE_VALUES = {
  126. SS_WEB_REFERRER: 'ss_webReferrer'
  127. };
  128. var isSkippedURL = function isSkippedURL(_ref) {
  129. var url = _ref.url,
  130. skipKeys = _ref.skipKeys,
  131. errorMsg = _ref.errorMsg;
  132. // search if this page referred and contains one of the given keys
  133. if (url) {
  134. var lowerURL = url.toLowerCase();
  135. if (lowerURL) {
  136. var skipKey = skipKeys.find(function (key) {
  137. return lowerURL.includes(key.toLowerCase());
  138. });
  139. !!skipKey && console.debug(errorMsg, skipKey);
  140. return !!skipKey;
  141. }
  142. }
  143. return false;
  144. };
  145. var getGoogleClickIdParameters = function getGoogleClickIdParameters(gciKey, currentURLParams) {
  146. var gciParam = currentURLParams[GOOGLE_CLICK_ID];
  147. var result = {};
  148. if (gciParam) {
  149. console.debug('This user comes from Google AdWords');
  150. result[gciKey] = gciParam;
  151. var keywordParam = currentURLParams[ASSOCIATED_AD_KEYWORD];
  152. if (keywordParam) {
  153. console.debug('There is a keyword associated with the ad');
  154. result[AF_KEYWORDS] = keywordParam;
  155. }
  156. } else {
  157. console.debug('This user comes from SRN or custom network');
  158. }
  159. return result;
  160. };
  161. var stringifyParameters = function stringifyParameters() {
  162. var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  163. var paramStr = Object.keys(parameters).reduce(function (curr, key) {
  164. if (parameters[key]) {
  165. curr += "&".concat(key, "=").concat(parameters[key]);
  166. }
  167. return curr;
  168. }, '');
  169. console.debug('Generated OneLink parameters', paramStr);
  170. return paramStr;
  171. };
  172. var getParameterValue = function getParameterValue(currentURLParams) {
  173. var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  174. keys: [],
  175. overrideValues: {},
  176. defaultValue: ''
  177. };
  178. //exit when config object structure is not valid
  179. if (!(config !== null && config !== void 0 && config.keys && Array.isArray(config.keys) || config !== null && config !== void 0 && config.defaultValue)) {
  180. console.error('Parameter config structure is wrong', config);
  181. return null;
  182. }
  183. var _config$keys = config.keys,
  184. keys = _config$keys === void 0 ? [] : _config$keys,
  185. _config$overrideValue = config.overrideValues,
  186. overrideValues = _config$overrideValue === void 0 ? {} : _config$overrideValue,
  187. _config$defaultValue = config.defaultValue,
  188. defaultValue = _config$defaultValue === void 0 ? '' : _config$defaultValue;
  189. var firstMatchedKey = keys.find(function (key) {
  190. //set the first match of key which contains also a value
  191. return !!currentURLParams[key];
  192. });
  193. if (firstMatchedKey) {
  194. var value = currentURLParams[firstMatchedKey];
  195. //in case the value exists:
  196. //check if it exists in the overrideValues object, when exists - replace it
  197. //otherwise return default value
  198. return overrideValues[value] || value || defaultValue;
  199. }
  200. return defaultValue;
  201. };
  202. var isIOS = function isIOS(useragent) {
  203. return /iphone|ipad|ipod/i.test(useragent && useragent.toLowerCase());
  204. };
  205. var isUACHSupported = function isUACHSupported() {
  206. return (typeof navigator === "undefined" ? "undefined" : _typeof(navigator)) === 'object' && 'userAgentData' in navigator && 'getHighEntropyValues' in navigator.userAgentData && !isIOS(navigator && navigator.userAgent);
  207. };
  208. var getQueryParamsAndSaveToLocalStorage = function getQueryParamsAndSaveToLocalStorage(websiteUrl) {
  209. if (!websiteUrl) {
  210. console.debug("website doesnt exist + ".concat(websiteUrl));
  211. }
  212. try {
  213. var url = new URL(websiteUrl);
  214. var urlParams = new URLSearchParams(url.search);
  215. var queryParams = Array.from(urlParams).reduce(function (acc, _ref2) {
  216. var _ref3 = _slicedToArray(_ref2, 2),
  217. key = _ref3[0],
  218. value = _ref3[1];
  219. return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, key, encodeURIComponent(value)));
  220. }, {});
  221. var savedQueryParams = JSON.parse(localStorage.getItem('ss_incoming_params') || '[]');
  222. var now = new Date().getTime();
  223. var twoHoursLater = now + 2 * 60 * 60 * 1000; // Add 2 hours in milliseconds(product request)
  224. var dataToSave = _objectSpread2(_objectSpread2({}, queryParams), {}, {
  225. af_ss_exp_at: twoHoursLater
  226. });
  227. savedQueryParams.unshift(dataToSave); // we used unshift becuse the order matter
  228. localStorage.setItem('ss_incoming_params', JSON.stringify(savedQueryParams));
  229. } catch (error) {
  230. console.debug("url isnt valid + ".concat(error));
  231. }
  232. };
  233. var isValidUrl = function isValidUrl(urlString) {
  234. try {
  235. return Boolean(new URL(urlString));
  236. } catch (e) {
  237. return false;
  238. }
  239. };
  240. var getCurrentUrl = function getCurrentUrl() {
  241. return new URL(window.location.href);
  242. };
  243. var getReferrerUrl = function getReferrerUrl() {
  244. var referrer = document.referrer;
  245. return referrer ? new URL(referrer) : null;
  246. };
  247. var isSameOrigin = function isSameOrigin(currentUrl, refUrl) {
  248. return currentUrl.origin === refUrl.origin;
  249. };
  250. var saveWebReferrer = function saveWebReferrer() {
  251. var currentUrl = getCurrentUrl();
  252. var refUrl = getReferrerUrl();
  253. if (refUrl && isSameOrigin(currentUrl, refUrl)) {
  254. console.warn('You navigate from the same website');
  255. return;
  256. }
  257. localStorage.setItem(LOCAL_STORAGE_VALUES.SS_WEB_REFERRER, JSON.stringify(document.referrer));
  258. };
  259. var removeExpiredLocalStorageItems = function removeExpiredLocalStorageItems() {
  260. var currentTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Date.now();
  261. var incomingParams = JSON.parse(localStorage.getItem('ss_incoming_params') || '[]');
  262. localStorage.setItem('ss_incoming_params', JSON.stringify(incomingParams.filter(function (_ref4) {
  263. var af_ss_exp_at = _ref4.af_ss_exp_at;
  264. return af_ss_exp_at > currentTime;
  265. })));
  266. };
  267. function aggregateValuesFromParameters() {
  268. var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  269. var aggregateValues = [];
  270. Object.values(parameters).forEach(function (value) {
  271. if (value && value.keys && Array.isArray(value.keys)) {
  272. value.keys.forEach(function (key) {
  273. return aggregateValues.push(key);
  274. });
  275. }
  276. if (Array.isArray(value)) {
  277. value.forEach(function (item) {
  278. if (Array.isArray(item === null || item === void 0 ? void 0 : item.keys)) {
  279. aggregateValues.push.apply(aggregateValues, _toConsumableArray(item.keys));
  280. }
  281. });
  282. }
  283. });
  284. if (
  285. // eslint-disable-next-line no-prototype-builtins
  286. parameters.hasOwnProperty('googleClickIdKey') && typeof parameters.googleClickIdKey === 'string') {
  287. aggregateValues.push(GOOGLE_CLICK_ID);
  288. }
  289. return aggregateValues;
  290. }
  291. function getCurrentURLParams(aggregateValues) {
  292. var currentURLParams = {};
  293. if (Object.keys(localStorage).includes('ss_incoming_params')) {
  294. var incomingParamsFromSS = JSON.parse(localStorage['ss_incoming_params']);
  295. currentURLParams = incomingParamsFromSS.find(function (obj) {
  296. return aggregateValues.some(function (key) {
  297. return key in obj;
  298. });
  299. }) || {};
  300. } else {
  301. console.log("Key 'ss_incoming_params' not found in localStorage.");
  302. }
  303. return currentURLParams;
  304. }
  305. var isOneLinkURLValid = function isOneLinkURLValid(oneLinkURL) {
  306. var _ref5;
  307. var oneLinkURLParts = (_ref5 = oneLinkURL || '') === null || _ref5 === void 0 ? void 0 : _ref5.toString().match(AF_URL_SCHEME);
  308. if (!oneLinkURLParts || (oneLinkURLParts === null || oneLinkURLParts === void 0 ? void 0 : oneLinkURLParts.length) < VALID_AF_URL_PARTS_LENGTH) {
  309. console.error("oneLinkURL is missing or not in the correct format, can't generate URL", oneLinkURL);
  310. return false;
  311. }
  312. return true;
  313. };
  314. var isMSValid = function isMSValid() {
  315. var mediaSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  316. if (!(mediaSource !== null && mediaSource !== void 0 && mediaSource.defaultValue)) {
  317. console.error("mediaSource is missing (default value was not supplied), can't generate URL", mediaSource);
  318. return false;
  319. }
  320. return true;
  321. };
  322. var isSkipListsValid = function isSkipListsValid(_ref6) {
  323. var _ref6$referrerSkipLis = _ref6.referrerSkipList,
  324. referrerSkipList = _ref6$referrerSkipLis === void 0 ? [] : _ref6$referrerSkipLis,
  325. _ref6$urlSkipList = _ref6.urlSkipList,
  326. urlSkipList = _ref6$urlSkipList === void 0 ? [] : _ref6$urlSkipList;
  327. if (isSkippedURL({
  328. url: document.referrer,
  329. skipKeys: referrerSkipList,
  330. errorMsg: 'Generate url is skipped. HTTP referrer contains key:'
  331. })) {
  332. return false;
  333. }
  334. if (isSkippedURL({
  335. url: document.URL,
  336. skipKeys: urlSkipList,
  337. errorMsg: 'Generate url is skipped. URL contains string:'
  338. })) {
  339. return false;
  340. }
  341. return true;
  342. };
  343. var extractCustomParams = function extractCustomParams(_ref7) {
  344. var _ref7$afCustom = _ref7.afCustom,
  345. afCustom = _ref7$afCustom === void 0 ? [] : _ref7$afCustom,
  346. _ref7$currentURLParam = _ref7.currentURLParams,
  347. currentURLParams = _ref7$currentURLParam === void 0 ? {} : _ref7$currentURLParam,
  348. googleClickIdKey = _ref7.googleClickIdKey;
  349. var afParams = {};
  350. if (Array.isArray(afCustom)) {
  351. afCustom.forEach(function (customParam) {
  352. if (customParam !== null && customParam !== void 0 && customParam.paramKey) {
  353. var isOverrideExistingKey = AF_CUSTOM_EXCLUDE_PARAMS_KEYS.find(function (k) {
  354. return k === (customParam === null || customParam === void 0 ? void 0 : customParam.paramKey);
  355. });
  356. if ((customParam === null || customParam === void 0 ? void 0 : customParam.paramKey) === googleClickIdKey || isOverrideExistingKey) {
  357. console.debug("Custom parameter ParamKey can't override Google-Click-Id or AF Parameters keys", customParam);
  358. } else {
  359. afParams[customParam.paramKey] = getParameterValue(currentURLParams, customParam);
  360. }
  361. }
  362. });
  363. }
  364. return afParams;
  365. };
  366. var validateAndMappedParams = function validateAndMappedParams() {
  367. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  368. var currentURLParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  369. var isDirectClick = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  370. var mediaSource = params.mediaSource,
  371. campaign = params.campaign,
  372. channel = params.channel,
  373. ad = params.ad,
  374. adSet = params.adSet,
  375. deepLinkValue = params.deepLinkValue,
  376. afSub1 = params.afSub1,
  377. afSub2 = params.afSub2,
  378. afSub3 = params.afSub3,
  379. afSub4 = params.afSub4,
  380. afSub5 = params.afSub5,
  381. afCustom = params.afCustom,
  382. googleClickIdKey = params.googleClickIdKey;
  383. var afParams = {};
  384. // Validates the URL and returns `true` if it should be skipped, `false` otherwise.
  385. if (mediaSource) {
  386. var pidValue = getParameterValue(currentURLParams, mediaSource);
  387. if (!pidValue) {
  388. console.error("mediaSource was not found in the URL and default value was not supplied, can't generate URL", mediaSource);
  389. return null;
  390. }
  391. var pidParamKey = isDirectClick ? 'af_media_source' : 'pid';
  392. afParams[pidParamKey] = pidValue;
  393. }
  394. if (campaign) {
  395. var campaignValue = getParameterValue(currentURLParams, campaign);
  396. if (!campaignValue && isDirectClick) {
  397. console.error("campaign was not found in the URL and default value was not supplied, can't generate URL", campaign);
  398. return null;
  399. }
  400. if (isDirectClick) {
  401. afParams['af_campaign'] = campaignValue;
  402. afParams['af_campaign_id'] = campaignValue;
  403. } else {
  404. afParams['c'] = campaignValue;
  405. }
  406. }
  407. if (channel) {
  408. afParams['af_channel'] = getParameterValue(currentURLParams, channel);
  409. }
  410. if (ad) {
  411. afParams['af_ad'] = getParameterValue(currentURLParams, ad);
  412. }
  413. if (adSet) {
  414. afParams['af_adset'] = getParameterValue(currentURLParams, adSet);
  415. }
  416. if (deepLinkValue) {
  417. afParams['deep_link_value'] = getParameterValue(currentURLParams, deepLinkValue);
  418. }
  419. var afSubs = [afSub1, afSub2, afSub3, afSub4, afSub5];
  420. afSubs.forEach(function (afSub, index) {
  421. if (afSub) {
  422. afParams["af_sub".concat(index + 1)] = getParameterValue(currentURLParams, afSub);
  423. }
  424. });
  425. if (googleClickIdKey) {
  426. if (GCLID_EXCLUDE_PARAMS_KEYS.find(function (k) {
  427. return k === googleClickIdKey;
  428. })) {
  429. console.debug("Google Click Id ParamKey can't override AF Parameters keys", googleClickIdKey);
  430. } else {
  431. var googleParameters = getGoogleClickIdParameters(googleClickIdKey, currentURLParams);
  432. Object.keys(googleParameters).forEach(function (gpk) {
  433. afParams[gpk] = googleParameters[gpk];
  434. });
  435. }
  436. }
  437. var customParams = extractCustomParams({
  438. afCustom: afCustom,
  439. currentURLParams: currentURLParams,
  440. googleClickIdKey: googleClickIdKey
  441. });
  442. return _objectSpread2(_objectSpread2({}, afParams), customParams);
  443. };
  444. var isPlatformValid = function isPlatformValid(platform) {
  445. if (!platform) {
  446. console.error("platform is missing , can't generate URL", platform);
  447. return false;
  448. }
  449. var platforms = ['smartcast', 'tizen', 'roku', 'webos', 'vidaa', 'playstation', 'android', 'ios', 'steam', 'quest', 'battlenet', 'epic', 'switch', 'xbox', 'nativepc'];
  450. if (!platforms.includes(platform.toLowerCase())) {
  451. console.error('platform need to be part of the known platforms supoorted');
  452. return false;
  453. }
  454. return true;
  455. };
  456. function getUserAgentData() {
  457. return new Promise(function (resolve) {
  458. if (isUACHSupported()) {
  459. navigator.userAgentData.getHighEntropyValues(['model', 'platformVersion']).then(function (clientHints) {
  460. resolve({
  461. model: clientHints.model,
  462. platformVersion: clientHints.platformVersion
  463. });
  464. })["catch"](function () {
  465. resolve();
  466. });
  467. } else {
  468. resolve();
  469. }
  470. });
  471. }
  472. var createImpressionsLink = function createImpressionsLink(finalURL) {
  473. if (!finalURL) {
  474. console.debug('ClickURL is not valid');
  475. return null;
  476. }
  477. return new Promise(function (resolve) {
  478. getUserAgentData().then(function (userAgentData) {
  479. var url = new URL(finalURL);
  480. url.hostname = 'impressions.onelink.me';
  481. if (userAgentData) {
  482. url.searchParams.append('af_ch_model', encodeURIComponent(userAgentData.model));
  483. url.searchParams.append('af_ch_os_version', encodeURIComponent(userAgentData.platformVersion));
  484. }
  485. resolve(url.href);
  486. })["catch"](function () {
  487. resolve();
  488. });
  489. });
  490. };
  491. function getHexColorAfterValidation(color) {
  492. var colorRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
  493. return colorRegex.test(color) ? color : '#000';
  494. }
  495. function getParameterValueFromURL(url, parameter) {
  496. var params = new URLSearchParams(url);
  497. return params.get(parameter);
  498. }
  499. function updateFinalUrlWithForwardParameters(url, forwardParametersList, URLSearchParams) {
  500. return forwardParametersList.reduce(function (updatedUrl, parameterName) {
  501. var parameterValue = getParameterValueFromURL(URLSearchParams, parameterName);
  502. if (parameterValue) {
  503. console.debug("The URL contains forwarding parameter ".concat(parameterName, "."));
  504. return "".concat(updatedUrl, "&").concat(parameterName, "=").concat(encodeURIComponent(parameterValue));
  505. }
  506. return updatedUrl;
  507. }, url);
  508. }
  509. var processTrackingParameters = function processTrackingParameters(destinationURL) {
  510. var forwardParametersList = [GOOGLE_CLICK_ID, FACEBOOK_CLICK_ID, TWITTER_CLICK_ID, SNAPCHAT_CLICK_ID, TIKTOK_CLICK_ID, GBRAID, WBRAID];
  511. //DELINIT-1888 - for supporting postbacks for GCLID and FBCLID we need to fdorward them to the final URL
  512. destinationURL = updateFinalUrlWithForwardParameters(destinationURL, forwardParametersList, window.location.search);
  513. // DELINIT-1888 - specific handling for GCLID - passing the keyword to the final URL and make sure it does not already on the link
  514. var hasGclidOnURL = getParameterValueFromURL(window.location.search, GOOGLE_CLICK_ID);
  515. var gbraid = getParameterValueFromURL(window.location.search, GBRAID);
  516. var wbraid = getParameterValueFromURL(window.location.search, WBRAID);
  517. if (hasGclidOnURL || gbraid || wbraid) {
  518. var keywordParam = getParameterValueFromURL(window.location.search, ASSOCIATED_AD_KEYWORD);
  519. var hasAfKeywordOnFinalURL = getParameterValueFromURL(destinationURL, AF_KEYWORDS);
  520. if (keywordParam && !hasAfKeywordOnFinalURL) {
  521. destinationURL = "".concat(destinationURL, "&").concat(AF_KEYWORDS, "=").concat(keywordParam);
  522. }
  523. }
  524. return destinationURL;
  525. };
  526. /**
  527. * EasyQRCodeJS
  528. *
  529. * Cross-browser QRCode generator for pure javascript. Support Canvas, SVG and Table drawing methods. Support Dot style, Logo, Background image, Colorful, Title etc. settings. Support Angular, Vue.js, React, Next.js, Svelte framework. Support binary(hex) data mode.(Running with DOM on client side)
  530. *
  531. * Version 4.4.10
  532. *
  533. * @author [ inthinkcolor@gmail.com ]
  534. *
  535. * @see https://github.com/ushelp/EasyQRCodeJS
  536. * @see http://www.easyproject.cn/easyqrcodejs/tryit.html
  537. * @see https://github.com/ushelp/EasyQRCodeJS-NodeJS
  538. *
  539. * Copyright 2017 Ray, EasyProject
  540. * Released under the MIT license
  541. *
  542. * [Support AMD, CMD, CommonJS/Node.js]
  543. *
  544. */
  545. function QRCode() {
  546. // 自定义局部 undefined 变量
  547. var undefined$1;
  548. /** Node.js global 检测. */
  549. var freeGlobal = (typeof global === "undefined" ? "undefined" : _typeof(global)) == 'object' && global && global.Object === Object && global;
  550. /** `self` 变量检测. */
  551. var freeSelf = (typeof self === "undefined" ? "undefined" : _typeof(self)) == 'object' && self && self.Object === Object && self;
  552. /** 全局对象检测. */
  553. var root = freeGlobal || freeSelf || Function('return this')();
  554. /** `exports` 变量检测. */
  555. var freeExports = (typeof exports === "undefined" ? "undefined" : _typeof(exports)) == 'object' && exports && !exports.nodeType && exports;
  556. /** `module` 变量检测. */
  557. var freeModule = freeExports && (typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module && !module.nodeType && module;
  558. var _QRCode = root.QRCode;
  559. var QRCode;
  560. function QR8bitByte(data, binary, utf8WithoutBOM) {
  561. this.mode = QRMode.MODE_8BIT_BYTE;
  562. this.data = data;
  563. this.parsedData = [];
  564. // Added to support UTF-8 Characters
  565. for (var i = 0, l = this.data.length; i < l; i++) {
  566. var byteArray = [];
  567. var code = this.data.charCodeAt(i);
  568. if (binary) {
  569. byteArray[0] = code;
  570. } else {
  571. if (code > 0x10000) {
  572. byteArray[0] = 0xf0 | (code & 0x1c0000) >>> 18;
  573. byteArray[1] = 0x80 | (code & 0x3f000) >>> 12;
  574. byteArray[2] = 0x80 | (code & 0xfc0) >>> 6;
  575. byteArray[3] = 0x80 | code & 0x3f;
  576. } else if (code > 0x800) {
  577. byteArray[0] = 0xe0 | (code & 0xf000) >>> 12;
  578. byteArray[1] = 0x80 | (code & 0xfc0) >>> 6;
  579. byteArray[2] = 0x80 | code & 0x3f;
  580. } else if (code > 0x80) {
  581. byteArray[0] = 0xc0 | (code & 0x7c0) >>> 6;
  582. byteArray[1] = 0x80 | code & 0x3f;
  583. } else {
  584. byteArray[0] = code;
  585. }
  586. }
  587. this.parsedData.push(byteArray);
  588. }
  589. this.parsedData = Array.prototype.concat.apply([], this.parsedData);
  590. if (!utf8WithoutBOM && this.parsedData.length != this.data.length) {
  591. this.parsedData.unshift(191);
  592. this.parsedData.unshift(187);
  593. this.parsedData.unshift(239);
  594. }
  595. }
  596. QR8bitByte.prototype = {
  597. getLength: function getLength(buffer) {
  598. return this.parsedData.length;
  599. },
  600. write: function write(buffer) {
  601. for (var i = 0, l = this.parsedData.length; i < l; i++) {
  602. buffer.put(this.parsedData[i], 8);
  603. }
  604. }
  605. };
  606. function QRCodeModel(typeNumber, errorCorrectLevel) {
  607. this.typeNumber = typeNumber;
  608. this.errorCorrectLevel = errorCorrectLevel;
  609. this.modules = null;
  610. this.moduleCount = 0;
  611. this.dataCache = null;
  612. this.dataList = [];
  613. }
  614. QRCodeModel.prototype = {
  615. addData: function addData(data, binary, utf8WithoutBOM) {
  616. var newData = new QR8bitByte(data, binary, utf8WithoutBOM);
  617. this.dataList.push(newData);
  618. this.dataCache = null;
  619. },
  620. isDark: function isDark(row, col) {
  621. if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) {
  622. throw new Error(row + ',' + col);
  623. }
  624. return this.modules[row][col][0];
  625. },
  626. getEye: function getEye(row, col) {
  627. if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) {
  628. throw new Error(row + ',' + col);
  629. }
  630. var block = this.modules[row][col]; // [isDark(ture/false), EyeOuterOrInner(O/I), Position(TL/TR/BL/A) ]
  631. if (block[1]) {
  632. var type = 'P' + block[1] + '_' + block[2]; //PO_TL, PI_TL, PO_TR, PI_TR, PO_BL, PI_BL
  633. if (block[2] == 'A') {
  634. type = 'A' + block[1]; // AI, AO
  635. }
  636. return {
  637. isDark: block[0],
  638. type: type
  639. };
  640. } else {
  641. return null;
  642. }
  643. },
  644. getModuleCount: function getModuleCount() {
  645. return this.moduleCount;
  646. },
  647. make: function make() {
  648. this.makeImpl(false, this.getBestMaskPattern());
  649. },
  650. makeImpl: function makeImpl(test, maskPattern) {
  651. this.moduleCount = this.typeNumber * 4 + 17;
  652. this.modules = new Array(this.moduleCount);
  653. for (var row = 0; row < this.moduleCount; row++) {
  654. this.modules[row] = new Array(this.moduleCount);
  655. for (var col = 0; col < this.moduleCount; col++) {
  656. this.modules[row][col] = []; // [isDark(ture/false), EyeOuterOrInner(O/I), Position(TL/TR/BL) ]
  657. }
  658. }
  659. this.setupPositionProbePattern(0, 0, 'TL'); // TopLeft, TL
  660. this.setupPositionProbePattern(this.moduleCount - 7, 0, 'BL'); // BotoomLeft, BL
  661. this.setupPositionProbePattern(0, this.moduleCount - 7, 'TR'); // TopRight, TR
  662. this.setupPositionAdjustPattern('A'); // Alignment, A
  663. this.setupTimingPattern();
  664. this.setupTypeInfo(test, maskPattern);
  665. if (this.typeNumber >= 7) {
  666. this.setupTypeNumber(test);
  667. }
  668. if (this.dataCache == null) {
  669. this.dataCache = QRCodeModel.createData(this.typeNumber, this.errorCorrectLevel, this.dataList);
  670. }
  671. this.mapData(this.dataCache, maskPattern);
  672. },
  673. setupPositionProbePattern: function setupPositionProbePattern(row, col, posName) {
  674. for (var r = -1; r <= 7; r++) {
  675. if (row + r <= -1 || this.moduleCount <= row + r) continue;
  676. for (var c = -1; c <= 7; c++) {
  677. if (col + c <= -1 || this.moduleCount <= col + c) continue;
  678. 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) {
  679. this.modules[row + r][col + c][0] = true;
  680. this.modules[row + r][col + c][2] = posName; // Position
  681. if (r == -0 || c == -0 || r == 6 || c == 6) {
  682. this.modules[row + r][col + c][1] = 'O'; // Position Outer
  683. } else {
  684. this.modules[row + r][col + c][1] = 'I'; // Position Inner
  685. }
  686. } else {
  687. this.modules[row + r][col + c][0] = false;
  688. }
  689. }
  690. }
  691. },
  692. getBestMaskPattern: function getBestMaskPattern() {
  693. var minLostPoint = 0;
  694. var pattern = 0;
  695. for (var i = 0; i < 8; i++) {
  696. this.makeImpl(true, i);
  697. var lostPoint = QRUtil.getLostPoint(this);
  698. if (i == 0 || minLostPoint > lostPoint) {
  699. minLostPoint = lostPoint;
  700. pattern = i;
  701. }
  702. }
  703. return pattern;
  704. },
  705. createMovieClip: function createMovieClip(target_mc, instance_name, depth) {
  706. var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth);
  707. var cs = 1;
  708. this.make();
  709. for (var row = 0; row < this.modules.length; row++) {
  710. var y = row * cs;
  711. for (var col = 0; col < this.modules[row].length; col++) {
  712. var x = col * cs;
  713. var dark = this.modules[row][col][0];
  714. if (dark) {
  715. qr_mc.beginFill(0, 100);
  716. qr_mc.moveTo(x, y);
  717. qr_mc.lineTo(x + cs, y);
  718. qr_mc.lineTo(x + cs, y + cs);
  719. qr_mc.lineTo(x, y + cs);
  720. qr_mc.endFill();
  721. }
  722. }
  723. }
  724. return qr_mc;
  725. },
  726. setupTimingPattern: function setupTimingPattern() {
  727. for (var r = 8; r < this.moduleCount - 8; r++) {
  728. if (this.modules[r][6][0] != null) {
  729. continue;
  730. }
  731. this.modules[r][6][0] = r % 2 == 0;
  732. }
  733. for (var c = 8; c < this.moduleCount - 8; c++) {
  734. if (this.modules[6][c][0] != null) {
  735. continue;
  736. }
  737. this.modules[6][c][0] = c % 2 == 0;
  738. }
  739. },
  740. setupPositionAdjustPattern: function setupPositionAdjustPattern(posName) {
  741. var pos = QRUtil.getPatternPosition(this.typeNumber);
  742. for (var i = 0; i < pos.length; i++) {
  743. for (var j = 0; j < pos.length; j++) {
  744. var row = pos[i];
  745. var col = pos[j];
  746. if (this.modules[row][col][0] != null) {
  747. continue;
  748. }
  749. for (var r = -2; r <= 2; r++) {
  750. for (var c = -2; c <= 2; c++) {
  751. if (r == -2 || r == 2 || c == -2 || c == 2 || r == 0 && c == 0) {
  752. this.modules[row + r][col + c][0] = true;
  753. this.modules[row + r][col + c][2] = posName; // Position
  754. if (r == -2 || c == -2 || r == 2 || c == 2) {
  755. this.modules[row + r][col + c][1] = 'O'; // Position Outer
  756. } else {
  757. this.modules[row + r][col + c][1] = 'I'; // Position Inner
  758. }
  759. } else {
  760. this.modules[row + r][col + c][0] = false;
  761. }
  762. }
  763. }
  764. }
  765. }
  766. },
  767. setupTypeNumber: function setupTypeNumber(test) {
  768. var bits = QRUtil.getBCHTypeNumber(this.typeNumber);
  769. for (var i = 0; i < 18; i++) {
  770. var mod = !test && (bits >> i & 1) == 1;
  771. this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3][0] = mod;
  772. }
  773. for (var i = 0; i < 18; i++) {
  774. var mod = !test && (bits >> i & 1) == 1;
  775. this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)][0] = mod;
  776. }
  777. },
  778. setupTypeInfo: function setupTypeInfo(test, maskPattern) {
  779. var data = this.errorCorrectLevel << 3 | maskPattern;
  780. var bits = QRUtil.getBCHTypeInfo(data);
  781. for (var i = 0; i < 15; i++) {
  782. var mod = !test && (bits >> i & 1) == 1;
  783. if (i < 6) {
  784. this.modules[i][8][0] = mod;
  785. } else if (i < 8) {
  786. this.modules[i + 1][8][0] = mod;
  787. } else {
  788. this.modules[this.moduleCount - 15 + i][8][0] = mod;
  789. }
  790. }
  791. for (var i = 0; i < 15; i++) {
  792. var mod = !test && (bits >> i & 1) == 1;
  793. if (i < 8) {
  794. this.modules[8][this.moduleCount - i - 1][0] = mod;
  795. } else if (i < 9) {
  796. this.modules[8][15 - i - 1 + 1][0] = mod;
  797. } else {
  798. this.modules[8][15 - i - 1][0] = mod;
  799. }
  800. }
  801. this.modules[this.moduleCount - 8][8][0] = !test;
  802. },
  803. mapData: function mapData(data, maskPattern) {
  804. var inc = -1;
  805. var row = this.moduleCount - 1;
  806. var bitIndex = 7;
  807. var byteIndex = 0;
  808. for (var col = this.moduleCount - 1; col > 0; col -= 2) {
  809. if (col == 6) col--;
  810. while (true) {
  811. for (var c = 0; c < 2; c++) {
  812. if (this.modules[row][col - c][0] == null) {
  813. var dark = false;
  814. if (byteIndex < data.length) {
  815. dark = (data[byteIndex] >>> bitIndex & 1) == 1;
  816. }
  817. var mask = QRUtil.getMask(maskPattern, row, col - c);
  818. if (mask) {
  819. dark = !dark;
  820. }
  821. this.modules[row][col - c][0] = dark;
  822. bitIndex--;
  823. if (bitIndex == -1) {
  824. byteIndex++;
  825. bitIndex = 7;
  826. }
  827. }
  828. }
  829. row += inc;
  830. if (row < 0 || this.moduleCount <= row) {
  831. row -= inc;
  832. inc = -inc;
  833. break;
  834. }
  835. }
  836. }
  837. }
  838. };
  839. QRCodeModel.PAD0 = 0xec;
  840. QRCodeModel.PAD1 = 0x11;
  841. QRCodeModel.createData = function (typeNumber, errorCorrectLevel, dataList) {
  842. var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel);
  843. var buffer = new QRBitBuffer();
  844. for (var i = 0; i < dataList.length; i++) {
  845. var data = dataList[i];
  846. buffer.put(data.mode, 4);
  847. buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber));
  848. data.write(buffer);
  849. }
  850. var totalDataCount = 0;
  851. for (var i = 0; i < rsBlocks.length; i++) {
  852. totalDataCount += rsBlocks[i].dataCount;
  853. }
  854. if (buffer.getLengthInBits() > totalDataCount * 8) {
  855. throw new Error('code length overflow. (' + buffer.getLengthInBits() + '>' + totalDataCount * 8 + ')');
  856. }
  857. if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
  858. buffer.put(0, 4);
  859. }
  860. while (buffer.getLengthInBits() % 8 != 0) {
  861. buffer.putBit(false);
  862. }
  863. while (true) {
  864. if (buffer.getLengthInBits() >= totalDataCount * 8) {
  865. break;
  866. }
  867. buffer.put(QRCodeModel.PAD0, 8);
  868. if (buffer.getLengthInBits() >= totalDataCount * 8) {
  869. break;
  870. }
  871. buffer.put(QRCodeModel.PAD1, 8);
  872. }
  873. return QRCodeModel.createBytes(buffer, rsBlocks);
  874. };
  875. QRCodeModel.createBytes = function (buffer, rsBlocks) {
  876. var offset = 0;
  877. var maxDcCount = 0;
  878. var maxEcCount = 0;
  879. var dcdata = new Array(rsBlocks.length);
  880. var ecdata = new Array(rsBlocks.length);
  881. for (var r = 0; r < rsBlocks.length; r++) {
  882. var dcCount = rsBlocks[r].dataCount;
  883. var ecCount = rsBlocks[r].totalCount - dcCount;
  884. maxDcCount = Math.max(maxDcCount, dcCount);
  885. maxEcCount = Math.max(maxEcCount, ecCount);
  886. dcdata[r] = new Array(dcCount);
  887. for (var i = 0; i < dcdata[r].length; i++) {
  888. dcdata[r][i] = 0xff & buffer.buffer[i + offset];
  889. }
  890. offset += dcCount;
  891. var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
  892. var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
  893. var modPoly = rawPoly.mod(rsPoly);
  894. ecdata[r] = new Array(rsPoly.getLength() - 1);
  895. for (var i = 0; i < ecdata[r].length; i++) {
  896. var modIndex = i + modPoly.getLength() - ecdata[r].length;
  897. ecdata[r][i] = modIndex >= 0 ? modPoly.get(modIndex) : 0;
  898. }
  899. }
  900. var totalCodeCount = 0;
  901. for (var i = 0; i < rsBlocks.length; i++) {
  902. totalCodeCount += rsBlocks[i].totalCount;
  903. }
  904. var data = new Array(totalCodeCount);
  905. var index = 0;
  906. for (var i = 0; i < maxDcCount; i++) {
  907. for (var r = 0; r < rsBlocks.length; r++) {
  908. if (i < dcdata[r].length) {
  909. data[index++] = dcdata[r][i];
  910. }
  911. }
  912. }
  913. for (var i = 0; i < maxEcCount; i++) {
  914. for (var r = 0; r < rsBlocks.length; r++) {
  915. if (i < ecdata[r].length) {
  916. data[index++] = ecdata[r][i];
  917. }
  918. }
  919. }
  920. return data;
  921. };
  922. var QRMode = {
  923. MODE_NUMBER: 1 << 0,
  924. MODE_ALPHA_NUM: 1 << 1,
  925. MODE_8BIT_BYTE: 1 << 2,
  926. MODE_KANJI: 1 << 3
  927. };
  928. var QRErrorCorrectLevel = {
  929. L: 1,
  930. M: 0,
  931. Q: 3,
  932. H: 2
  933. };
  934. var QRMaskPattern = {
  935. PATTERN000: 0,
  936. PATTERN001: 1,
  937. PATTERN010: 2,
  938. PATTERN011: 3,
  939. PATTERN100: 4,
  940. PATTERN101: 5,
  941. PATTERN110: 6,
  942. PATTERN111: 7
  943. };
  944. var QRUtil = {
  945. 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]],
  946. G15: 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0,
  947. G18: 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0,
  948. G15_MASK: 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1,
  949. getBCHTypeInfo: function getBCHTypeInfo(data) {
  950. var d = data << 10;
  951. while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
  952. d ^= QRUtil.G15 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15);
  953. }
  954. return (data << 10 | d) ^ QRUtil.G15_MASK;
  955. },
  956. getBCHTypeNumber: function getBCHTypeNumber(data) {
  957. var d = data << 12;
  958. while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
  959. d ^= QRUtil.G18 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18);
  960. }
  961. return data << 12 | d;
  962. },
  963. getBCHDigit: function getBCHDigit(data) {
  964. var digit = 0;
  965. while (data != 0) {
  966. digit++;
  967. data >>>= 1;
  968. }
  969. return digit;
  970. },
  971. getPatternPosition: function getPatternPosition(typeNumber) {
  972. return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];
  973. },
  974. getMask: function getMask(maskPattern, i, j) {
  975. switch (maskPattern) {
  976. case QRMaskPattern.PATTERN000:
  977. return (i + j) % 2 == 0;
  978. case QRMaskPattern.PATTERN001:
  979. return i % 2 == 0;
  980. case QRMaskPattern.PATTERN010:
  981. return j % 3 == 0;
  982. case QRMaskPattern.PATTERN011:
  983. return (i + j) % 3 == 0;
  984. case QRMaskPattern.PATTERN100:
  985. return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0;
  986. case QRMaskPattern.PATTERN101:
  987. return i * j % 2 + i * j % 3 == 0;
  988. case QRMaskPattern.PATTERN110:
  989. return (i * j % 2 + i * j % 3) % 2 == 0;
  990. case QRMaskPattern.PATTERN111:
  991. return (i * j % 3 + (i + j) % 2) % 2 == 0;
  992. default:
  993. throw new Error('bad maskPattern:' + maskPattern);
  994. }
  995. },
  996. getErrorCorrectPolynomial: function getErrorCorrectPolynomial(errorCorrectLength) {
  997. var a = new QRPolynomial([1], 0);
  998. for (var i = 0; i < errorCorrectLength; i++) {
  999. a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0));
  1000. }
  1001. return a;
  1002. },
  1003. getLengthInBits: function getLengthInBits(mode, type) {
  1004. if (1 <= type && type < 10) {
  1005. switch (mode) {
  1006. case QRMode.MODE_NUMBER:
  1007. return 10;
  1008. case QRMode.MODE_ALPHA_NUM:
  1009. return 9;
  1010. case QRMode.MODE_8BIT_BYTE:
  1011. return 8;
  1012. case QRMode.MODE_KANJI:
  1013. return 8;
  1014. default:
  1015. throw new Error('mode:' + mode);
  1016. }
  1017. } else if (type < 27) {
  1018. switch (mode) {
  1019. case QRMode.MODE_NUMBER:
  1020. return 12;
  1021. case QRMode.MODE_ALPHA_NUM:
  1022. return 11;
  1023. case QRMode.MODE_8BIT_BYTE:
  1024. return 16;
  1025. case QRMode.MODE_KANJI:
  1026. return 10;
  1027. default:
  1028. throw new Error('mode:' + mode);
  1029. }
  1030. } else if (type < 41) {
  1031. switch (mode) {
  1032. case QRMode.MODE_NUMBER:
  1033. return 14;
  1034. case QRMode.MODE_ALPHA_NUM:
  1035. return 13;
  1036. case QRMode.MODE_8BIT_BYTE:
  1037. return 16;
  1038. case QRMode.MODE_KANJI:
  1039. return 12;
  1040. default:
  1041. throw new Error('mode:' + mode);
  1042. }
  1043. } else {
  1044. throw new Error('type:' + type);
  1045. }
  1046. },
  1047. getLostPoint: function getLostPoint(qrCode) {
  1048. var moduleCount = qrCode.getModuleCount();
  1049. var lostPoint = 0;
  1050. for (var row = 0; row < moduleCount; row++) {
  1051. for (var col = 0; col < moduleCount; col++) {
  1052. var sameCount = 0;
  1053. var dark = qrCode.isDark(row, col);
  1054. for (var r = -1; r <= 1; r++) {
  1055. if (row + r < 0 || moduleCount <= row + r) {
  1056. continue;
  1057. }
  1058. for (var c = -1; c <= 1; c++) {
  1059. if (col + c < 0 || moduleCount <= col + c) {
  1060. continue;
  1061. }
  1062. if (r == 0 && c == 0) {
  1063. continue;
  1064. }
  1065. if (dark == qrCode.isDark(row + r, col + c)) {
  1066. sameCount++;
  1067. }
  1068. }
  1069. }
  1070. if (sameCount > 5) {
  1071. lostPoint += 3 + sameCount - 5;
  1072. }
  1073. }
  1074. }
  1075. for (var row = 0; row < moduleCount - 1; row++) {
  1076. for (var col = 0; col < moduleCount - 1; col++) {
  1077. var count = 0;
  1078. if (qrCode.isDark(row, col)) count++;
  1079. if (qrCode.isDark(row + 1, col)) count++;
  1080. if (qrCode.isDark(row, col + 1)) count++;
  1081. if (qrCode.isDark(row + 1, col + 1)) count++;
  1082. if (count == 0 || count == 4) {
  1083. lostPoint += 3;
  1084. }
  1085. }
  1086. }
  1087. for (var row = 0; row < moduleCount; row++) {
  1088. for (var col = 0; col < moduleCount - 6; col++) {
  1089. if (qrCode.isDark(row, col) && !qrCode.isDark(row, col + 1) && qrCode.isDark(row, col + 2) && qrCode.isDark(row, col + 3) && qrCode.isDark(row, col + 4) && !qrCode.isDark(row, col + 5) && qrCode.isDark(row, col + 6)) {
  1090. lostPoint += 40;
  1091. }
  1092. }
  1093. }
  1094. for (var col = 0; col < moduleCount; col++) {
  1095. for (var row = 0; row < moduleCount - 6; row++) {
  1096. if (qrCode.isDark(row, col) && !qrCode.isDark(row + 1, col) && qrCode.isDark(row + 2, col) && qrCode.isDark(row + 3, col) && qrCode.isDark(row + 4, col) && !qrCode.isDark(row + 5, col) && qrCode.isDark(row + 6, col)) {
  1097. lostPoint += 40;
  1098. }
  1099. }
  1100. }
  1101. var darkCount = 0;
  1102. for (var col = 0; col < moduleCount; col++) {
  1103. for (var row = 0; row < moduleCount; row++) {
  1104. if (qrCode.isDark(row, col)) {
  1105. darkCount++;
  1106. }
  1107. }
  1108. }
  1109. var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
  1110. lostPoint += ratio * 10;
  1111. return lostPoint;
  1112. }
  1113. };
  1114. var QRMath = {
  1115. glog: function glog(n) {
  1116. if (n < 1) {
  1117. throw new Error('glog(' + n + ')');
  1118. }
  1119. return QRMath.LOG_TABLE[n];
  1120. },
  1121. gexp: function gexp(n) {
  1122. while (n < 0) {
  1123. n += 255;
  1124. }
  1125. while (n >= 256) {
  1126. n -= 255;
  1127. }
  1128. return QRMath.EXP_TABLE[n];
  1129. },
  1130. EXP_TABLE: new Array(256),
  1131. LOG_TABLE: new Array(256)
  1132. };
  1133. for (var i = 0; i < 8; i++) {
  1134. QRMath.EXP_TABLE[i] = 1 << i;
  1135. }
  1136. for (var i = 8; i < 256; i++) {
  1137. QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] ^ QRMath.EXP_TABLE[i - 5] ^ QRMath.EXP_TABLE[i - 6] ^ QRMath.EXP_TABLE[i - 8];
  1138. }
  1139. for (var i = 0; i < 255; i++) {
  1140. QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i;
  1141. }
  1142. function QRPolynomial(num, shift) {
  1143. if (num.length == undefined$1) {
  1144. throw new Error(num.length + '/' + shift);
  1145. }
  1146. var offset = 0;
  1147. while (offset < num.length && num[offset] == 0) {
  1148. offset++;
  1149. }
  1150. this.num = new Array(num.length - offset + shift);
  1151. for (var i = 0; i < num.length - offset; i++) {
  1152. this.num[i] = num[i + offset];
  1153. }
  1154. }
  1155. QRPolynomial.prototype = {
  1156. get: function get(index) {
  1157. return this.num[index];
  1158. },
  1159. getLength: function getLength() {
  1160. return this.num.length;
  1161. },
  1162. multiply: function multiply(e) {
  1163. var num = new Array(this.getLength() + e.getLength() - 1);
  1164. for (var i = 0; i < this.getLength(); i++) {
  1165. for (var j = 0; j < e.getLength(); j++) {
  1166. num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i)) + QRMath.glog(e.get(j)));
  1167. }
  1168. }
  1169. return new QRPolynomial(num, 0);
  1170. },
  1171. mod: function mod(e) {
  1172. if (this.getLength() - e.getLength() < 0) {
  1173. return this;
  1174. }
  1175. var ratio = QRMath.glog(this.get(0)) - QRMath.glog(e.get(0));
  1176. var num = new Array(this.getLength());
  1177. for (var i = 0; i < this.getLength(); i++) {
  1178. num[i] = this.get(i);
  1179. }
  1180. for (var i = 0; i < e.getLength(); i++) {
  1181. num[i] ^= QRMath.gexp(QRMath.glog(e.get(i)) + ratio);
  1182. }
  1183. return new QRPolynomial(num, 0).mod(e);
  1184. }
  1185. };
  1186. function QRRSBlock(totalCount, dataCount) {
  1187. this.totalCount = totalCount;
  1188. this.dataCount = dataCount;
  1189. }
  1190. QRRSBlock.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, 7, 37, 13], [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]];
  1191. QRRSBlock.getRSBlocks = function (typeNumber, errorCorrectLevel) {
  1192. var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel);
  1193. if (rsBlock == undefined$1) {
  1194. throw new Error('bad rs block @ typeNumber:' + typeNumber + '/errorCorrectLevel:' + errorCorrectLevel);
  1195. }
  1196. var length = rsBlock.length / 3;
  1197. var list = [];
  1198. for (var i = 0; i < length; i++) {
  1199. var count = rsBlock[i * 3 + 0];
  1200. var totalCount = rsBlock[i * 3 + 1];
  1201. var dataCount = rsBlock[i * 3 + 2];
  1202. for (var j = 0; j < count; j++) {
  1203. list.push(new QRRSBlock(totalCount, dataCount));
  1204. }
  1205. }
  1206. return list;
  1207. };
  1208. QRRSBlock.getRsBlockTable = function (typeNumber, errorCorrectLevel) {
  1209. switch (errorCorrectLevel) {
  1210. case QRErrorCorrectLevel.L:
  1211. return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
  1212. case QRErrorCorrectLevel.M:
  1213. return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
  1214. case QRErrorCorrectLevel.Q:
  1215. return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
  1216. case QRErrorCorrectLevel.H:
  1217. return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
  1218. default:
  1219. return undefined$1;
  1220. }
  1221. };
  1222. function QRBitBuffer() {
  1223. this.buffer = [];
  1224. this.length = 0;
  1225. }
  1226. QRBitBuffer.prototype = {
  1227. get: function get(index) {
  1228. var bufIndex = Math.floor(index / 8);
  1229. return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) == 1;
  1230. },
  1231. put: function put(num, length) {
  1232. for (var i = 0; i < length; i++) {
  1233. this.putBit((num >>> length - i - 1 & 1) == 1);
  1234. }
  1235. },
  1236. getLengthInBits: function getLengthInBits() {
  1237. return this.length;
  1238. },
  1239. putBit: function putBit(bit) {
  1240. var bufIndex = Math.floor(this.length / 8);
  1241. if (this.buffer.length <= bufIndex) {
  1242. this.buffer.push(0);
  1243. }
  1244. if (bit) {
  1245. this.buffer[bufIndex] |= 0x80 >>> this.length % 8;
  1246. }
  1247. this.length++;
  1248. }
  1249. };
  1250. var QRCodeLimitLength = [[17, 14, 11, 7], [32, 26, 20, 14], [53, 42, 32, 24], [78, 62, 46, 34], [106, 84, 60, 44], [134, 106, 74, 58], [154, 122, 86, 64], [192, 152, 108, 84], [230, 180, 130, 98], [271, 213, 151, 119], [321, 251, 177, 137], [367, 287, 203, 155], [425, 331, 241, 177], [458, 362, 258, 194], [520, 412, 292, 220], [586, 450, 322, 250], [644, 504, 364, 280], [718, 560, 394, 310], [792, 624, 442, 338], [858, 666, 482, 382], [929, 711, 509, 403], [1003, 779, 565, 439], [1091, 857, 611, 461], [1171, 911, 661, 511], [1273, 997, 715, 535], [1367, 1059, 751, 593], [1465, 1125, 805, 625], [1528, 1190, 868, 658], [1628, 1264, 908, 698], [1732, 1370, 982, 742], [1840, 1452, 1030, 790], [1952, 1538, 1112, 842], [2068, 1628, 1168, 898], [2188, 1722, 1228, 958], [2303, 1809, 1283, 983], [2431, 1911, 1351, 1051], [2563, 1989, 1423, 1093], [2699, 2099, 1499, 1139], [2809, 2213, 1579, 1219], [2953, 2331, 1663, 1273]];
  1251. function _isSupportCanvas() {
  1252. return typeof CanvasRenderingContext2D != 'undefined';
  1253. }
  1254. // android 2.x doesn't support Data-URI spec
  1255. function _getAndroid() {
  1256. var android = false;
  1257. var sAgent = navigator.userAgent;
  1258. if (/android/i.test(sAgent)) {
  1259. // android
  1260. android = true;
  1261. var aMat = sAgent.toString().match(/android ([0-9]\.[0-9])/i);
  1262. if (aMat && aMat[1]) {
  1263. android = parseFloat(aMat[1]);
  1264. }
  1265. }
  1266. return android;
  1267. }
  1268. // Drawing in DOM by using Table tag
  1269. var Drawing = !_isSupportCanvas() ? function () {
  1270. var Drawing = function Drawing(el, htOption) {
  1271. this._el = el;
  1272. this._htOption = htOption;
  1273. };
  1274. /**
  1275. * Draw the QRCode
  1276. *
  1277. * @param {QRCode} oQRCode
  1278. */
  1279. Drawing.prototype.draw = function (oQRCode) {
  1280. var _htOption = this._htOption;
  1281. var _el = this._el;
  1282. var nCount = oQRCode.getModuleCount();
  1283. var nWidth = Math.round(_htOption.width / nCount);
  1284. var nHeight = Math.round((_htOption.height - _htOption.titleHeight) / nCount);
  1285. if (nWidth <= 1) {
  1286. nWidth = 1;
  1287. }
  1288. if (nHeight <= 1) {
  1289. nHeight = 1;
  1290. }
  1291. this._htOption.width = nWidth * nCount;
  1292. this._htOption.height = nHeight * nCount + _htOption.titleHeight;
  1293. this._htOption.quietZone = Math.round(this._htOption.quietZone);
  1294. var aHTML = [];
  1295. var divStyle = '';
  1296. var drawWidth = Math.round(nWidth * _htOption.dotScale);
  1297. var drawHeight = Math.round(nHeight * _htOption.dotScale);
  1298. if (drawWidth < 4) {
  1299. drawWidth = 4;
  1300. drawHeight = 4;
  1301. }
  1302. var nonRequiredColorDark = _htOption.colorDark;
  1303. var nonRequiredcolorLight = _htOption.colorLight;
  1304. if (_htOption.backgroundImage) {
  1305. if (_htOption.autoColor) {
  1306. _htOption.colorDark = "rgba(0, 0, 0, .6);filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#99000000', EndColorStr='#99000000');";
  1307. _htOption.colorLight = "rgba(255, 255, 255, .7);filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#B2FFFFFF', EndColorStr='#B2FFFFFF');";
  1308. // _htOption.colorDark="rgba(0, 0, 0, .6)";
  1309. // _htOption.colorLight='rgba(255, 255, 255, .7)';
  1310. } else {
  1311. _htOption.colorLight = 'rgba(0,0,0,0)';
  1312. }
  1313. var backgroundImageEle = '<div style="display:inline-block; z-index:-10;position:absolute;"><img src="' + _htOption.backgroundImage + '" width="' + (_htOption.width + _htOption.quietZone * 2) + '" height="' + (_htOption.height + _htOption.quietZone * 2) + '" style="opacity:' + _htOption.backgroundImageAlpha + ';filter:alpha(opacity=' + _htOption.backgroundImageAlpha * 100 + '); "/></div>';
  1314. aHTML.push(backgroundImageEle);
  1315. }
  1316. if (_htOption.quietZone) {
  1317. divStyle = 'display:inline-block; width:' + (_htOption.width + _htOption.quietZone * 2) + 'px; height:' + (_htOption.width + _htOption.quietZone * 2) + 'px;background:' + _htOption.quietZoneColor + '; text-align:center;';
  1318. }
  1319. aHTML.push('<div style="font-size:0;' + divStyle + '">');
  1320. aHTML.push('<table style="font-size:0;border:0;border-collapse:collapse; margin-top:' + _htOption.quietZone + 'px;" border="0" cellspacing="0" cellspadding="0" align="center" valign="middle">');
  1321. aHTML.push('<tr height="' + _htOption.titleHeight + '" align="center"><td style="border:0;border-collapse:collapse;margin:0;padding:0" colspan="' + nCount + '">');
  1322. if (_htOption.title) {
  1323. var c = _htOption.titleColor;
  1324. var f = _htOption.titleFont;
  1325. aHTML.push('<div style="width:100%;margin-top:' + _htOption.titleTop + 'px;color:' + c + ';font:' + f + ';background:' + _htOption.titleBackgroundColor + '">' + _htOption.title + '</div>');
  1326. }
  1327. if (_htOption.subTitle) {
  1328. aHTML.push('<div style="width:100%;margin-top:' + (_htOption.subTitleTop - _htOption.titleTop) + 'px;color:' + _htOption.subTitleColor + '; font:' + _htOption.subTitleFont + '">' + _htOption.subTitle + '</div>');
  1329. }
  1330. aHTML.push('</td></tr>');
  1331. for (var row = 0; row < nCount; row++) {
  1332. aHTML.push('<tr style="border:0; padding:0; margin:0;" height="7">');
  1333. for (var col = 0; col < nCount; col++) {
  1334. var bIsDark = oQRCode.isDark(row, col);
  1335. var eye = oQRCode.getEye(row, col); // { isDark: true/false, type: PO_TL, PI_TL, PO_TR, PI_TR, PO_BL, PI_BL };
  1336. if (eye) {
  1337. // Is eye
  1338. bIsDark = eye.isDark;
  1339. var type = eye.type;
  1340. // PX_XX, PX, colorDark, colorLight
  1341. var eyeColorDark = _htOption[type] || _htOption[type.substring(0, 2)] || nonRequiredColorDark;
  1342. aHTML.push('<td style="border:0;border-collapse:collapse;padding:0;margin:0;width:' + nWidth + 'px;height:' + nHeight + 'px;">' + '<span style="width:' + nWidth + 'px;height:' + nHeight + 'px;background-color:' + (bIsDark ? eyeColorDark : nonRequiredcolorLight) + ';display:inline-block"></span></td>');
  1343. } else {
  1344. // Timing Pattern
  1345. var nowDarkColor = _htOption.colorDark;
  1346. if (row == 6) {
  1347. nowDarkColor = _htOption.timing_H || _htOption.timing || nonRequiredColorDark;
  1348. aHTML.push('<td style="border:0;border-collapse:collapse;padding:0;margin:0;width:' + nWidth + 'px;height:' + nHeight + 'px;background-color:' + (bIsDark ? nowDarkColor : nonRequiredcolorLight) + ';"></td>');
  1349. } else if (col == 6) {
  1350. nowDarkColor = _htOption.timing_V || _htOption.timing || nonRequiredColorDark;
  1351. aHTML.push('<td style="border:0;border-collapse:collapse;padding:0;margin:0;width:' + nWidth + 'px;height:' + nHeight + 'px;background-color:' + (bIsDark ? nowDarkColor : nonRequiredcolorLight) + ';"></td>');
  1352. } else {
  1353. aHTML.push('<td style="border:0;border-collapse:collapse;padding:0;margin:0;width:' + nWidth + 'px;height:' + nHeight + 'px;">' + '<div style="display:inline-block;width:' + drawWidth + 'px;height:' + drawHeight + 'px;background-color:' + (bIsDark ? nowDarkColor : _htOption.colorLight) + ';"></div></td>');
  1354. }
  1355. }
  1356. }
  1357. aHTML.push('</tr>');
  1358. }
  1359. aHTML.push('</table>');
  1360. aHTML.push('</div>');
  1361. if (_htOption.logo) {
  1362. // Logo Image
  1363. var img = new Image();
  1364. if (_htOption.crossOrigin != null) {
  1365. img.crossOrigin = _htOption.crossOrigin;
  1366. }
  1367. // img.crossOrigin="Anonymous";
  1368. img.src = _htOption.logo;
  1369. var imgW = _htOption.width / 3.5;
  1370. var imgH = _htOption.height / 3.5;
  1371. if (imgW != imgH) {
  1372. imgW = imgH;
  1373. }
  1374. if (_htOption.logoWidth) {
  1375. imgW = _htOption.logoWidth;
  1376. }
  1377. if (_htOption.logoHeight) {
  1378. imgH = _htOption.logoHeight;
  1379. }
  1380. var imgDivStyle = 'position:relative; z-index:1;display:table-cell;top:-' + ((_htOption.height - _htOption.titleHeight) / 2 + imgH / 2 + _htOption.quietZone) + 'px;text-align:center; width:' + imgW + 'px; height:' + imgH + 'px;line-height:' + imgW + 'px; vertical-align: middle;';
  1381. if (!_htOption.logoBackgroundTransparent) {
  1382. imgDivStyle += 'background:' + _htOption.logoBackgroundColor;
  1383. }
  1384. aHTML.push('<div style="' + imgDivStyle + '"><img src="' + _htOption.logo + '" style="max-width: ' + imgW + 'px; max-height: ' + imgH + 'px;" /> <div style=" display: none; width:1px;margin-left: -1px;"></div></div>');
  1385. }
  1386. if (_htOption.onRenderingStart) {
  1387. _htOption.onRenderingStart(_htOption);
  1388. }
  1389. _el.innerHTML = aHTML.join('');
  1390. // Fix the margin values as real size.
  1391. var elTable = _el.childNodes[0];
  1392. var nLeftMarginTable = (_htOption.width - elTable.offsetWidth) / 2;
  1393. var nTopMarginTable = (_htOption.height - elTable.offsetHeight) / 2;
  1394. if (nLeftMarginTable > 0 && nTopMarginTable > 0) {
  1395. elTable.style.margin = nTopMarginTable + 'px ' + nLeftMarginTable + 'px';
  1396. }
  1397. if (this._htOption.onRenderingEnd) {
  1398. this._htOption.onRenderingEnd(this._htOption, null);
  1399. }
  1400. };
  1401. /**
  1402. * Clear the QRCode
  1403. */
  1404. Drawing.prototype.clear = function () {
  1405. this._el.innerHTML = '';
  1406. };
  1407. return Drawing;
  1408. }() : function () {
  1409. // Drawing in Canvas
  1410. function _onMakeImage() {
  1411. if (this._htOption.drawer == 'svg') {
  1412. var svgData = this._oContext.getSerializedSvg(true);
  1413. this.dataURL = svgData;
  1414. this._el.innerHTML = svgData;
  1415. } else {
  1416. // canvas
  1417. // this._elImage.crossOrigin='Anonymous';
  1418. try {
  1419. // if (this._htOption.crossOrigin != null) {
  1420. // this._elImage.crossOrigin = this._htOption.crossOrigin;
  1421. // }
  1422. var dataURL = this._elCanvas.toDataURL('image/png');
  1423. // this._elImage.src = dataURL;
  1424. this.dataURL = dataURL;
  1425. // this._elImage.style.display = "inline";
  1426. // this._elCanvas.style.display = "none";
  1427. } catch (e) {
  1428. console.error(e);
  1429. }
  1430. }
  1431. if (this._htOption.onRenderingEnd) {
  1432. if (!this.dataURL) {
  1433. console.error("Can not get base64 data, please check: 1. Published the page and image to the server 2. The image request support CORS 3. Configured `crossOrigin:'anonymous'` option");
  1434. }
  1435. this._htOption.onRenderingEnd(this._htOption, this.dataURL);
  1436. }
  1437. }
  1438. // Android 2.1 bug workaround
  1439. // http://code.google.com/p/android/issues/detail?id=5141
  1440. if (root._android && root._android <= 2.1) {
  1441. var factor = 1 / window.devicePixelRatio;
  1442. var drawImage = CanvasRenderingContext2D.prototype.drawImage;
  1443. CanvasRenderingContext2D.prototype.drawImage = function (image, sx, sy, sw, sh, dx, dy, dw, dh) {
  1444. if ('nodeName' in image && /img/i.test(image.nodeName)) {
  1445. for (var i = arguments.length - 1; i >= 1; i--) {
  1446. arguments[i] = arguments[i] * factor;
  1447. }
  1448. } else if (typeof dw == 'undefined') {
  1449. arguments[1] *= factor;
  1450. arguments[2] *= factor;
  1451. arguments[3] *= factor;
  1452. arguments[4] *= factor;
  1453. }
  1454. drawImage.apply(this, arguments);
  1455. };
  1456. }
  1457. /**
  1458. * Check whether the user's browser supports Data URI or not
  1459. *
  1460. * @private
  1461. * @param {Function} fSuccess Occurs if it supports Data URI
  1462. * @param {Function} fFail Occurs if it doesn't support Data URI
  1463. */
  1464. function _safeSetDataURI(fSuccess, fFail) {
  1465. var self = this;
  1466. self._fFail = fFail;
  1467. self._fSuccess = fSuccess;
  1468. // Check it just once
  1469. if (self._bSupportDataURI === null) {
  1470. var el = document.createElement('img');
  1471. var fOnError = function fOnError() {
  1472. self._bSupportDataURI = false;
  1473. if (self._fFail) {
  1474. self._fFail.call(self);
  1475. }
  1476. };
  1477. var fOnSuccess = function fOnSuccess() {
  1478. self._bSupportDataURI = true;
  1479. if (self._fSuccess) {
  1480. self._fSuccess.call(self);
  1481. }
  1482. };
  1483. el.onabort = fOnError;
  1484. el.onerror = fOnError;
  1485. el.onload = fOnSuccess;
  1486. el.src = 'data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; // the Image contains 1px data.
  1487. return;
  1488. } else if (self._bSupportDataURI === true && self._fSuccess) {
  1489. self._fSuccess.call(self);
  1490. } else if (self._bSupportDataURI === false && self._fFail) {
  1491. self._fFail.call(self);
  1492. }
  1493. }
  1494. /**
  1495. * Drawing QRCode by using canvas
  1496. *
  1497. * @constructor
  1498. * @param {HTMLElement} el
  1499. * @param {Object} htOption QRCode Options
  1500. */
  1501. var Drawing = function Drawing(el, htOption) {
  1502. this._bIsPainted = false;
  1503. this._android = _getAndroid();
  1504. this._el = el;
  1505. this._htOption = htOption;
  1506. if (this._htOption.drawer == 'svg') {
  1507. this._oContext = {};
  1508. this._elCanvas = {};
  1509. } else {
  1510. // canvas
  1511. this._elCanvas = document.createElement('canvas');
  1512. this._el.appendChild(this._elCanvas);
  1513. this._oContext = this._elCanvas.getContext('2d');
  1514. // this._elImage = document.createElement("img");
  1515. // this._elImage.alt = "Scan me!";
  1516. // this._elImage.style.display = "none";
  1517. // this._el.appendChild(this._elImage);
  1518. }
  1519. this._bSupportDataURI = null;
  1520. this.dataURL = null;
  1521. };
  1522. /**
  1523. * Draw the QRCode
  1524. *
  1525. * @param {QRCode} oQRCode
  1526. */
  1527. Drawing.prototype.draw = function (oQRCode) {
  1528. // var _elImage = this._elImage;
  1529. var _htOption = this._htOption;
  1530. if (!_htOption.title && !_htOption.subTitle) {
  1531. _htOption.height -= _htOption.titleHeight;
  1532. _htOption.titleHeight = 0;
  1533. }
  1534. var nCount = oQRCode.getModuleCount();
  1535. var nWidth = Math.round(_htOption.width / nCount);
  1536. var nHeight = Math.round((_htOption.height - _htOption.titleHeight) / nCount);
  1537. if (nWidth <= 1) {
  1538. nWidth = 1;
  1539. }
  1540. if (nHeight <= 1) {
  1541. nHeight = 1;
  1542. }
  1543. _htOption.width = nWidth * nCount;
  1544. _htOption.height = nHeight * nCount + _htOption.titleHeight;
  1545. _htOption.quietZone = Math.round(_htOption.quietZone);
  1546. this._elCanvas.width = _htOption.width + _htOption.quietZone * 2;
  1547. this._elCanvas.height = _htOption.height + _htOption.quietZone * 2;
  1548. if (this._htOption.drawer != 'canvas') {
  1549. // _elImage.style.display = "none";
  1550. // } else {
  1551. this._oContext = new C2S(this._elCanvas.width, this._elCanvas.height);
  1552. }
  1553. this.clear();
  1554. var _oContext = this._oContext;
  1555. _oContext.lineWidth = 0;
  1556. _oContext.fillStyle = _htOption.colorLight;
  1557. _oContext.fillRect(0, 0, this._elCanvas.width, this._elCanvas.height);
  1558. var t = this;
  1559. function drawQuietZoneColor() {
  1560. if (_htOption.quietZone > 0 && _htOption.quietZoneColor) {
  1561. // top
  1562. _oContext.lineWidth = 0;
  1563. _oContext.fillStyle = _htOption.quietZoneColor;
  1564. _oContext.fillRect(0, 0, t._elCanvas.width, _htOption.quietZone);
  1565. // left
  1566. _oContext.fillRect(0, _htOption.quietZone, _htOption.quietZone, t._elCanvas.height - _htOption.quietZone * 2);
  1567. // right
  1568. _oContext.fillRect(t._elCanvas.width - _htOption.quietZone, _htOption.quietZone, _htOption.quietZone, t._elCanvas.height - _htOption.quietZone * 2);
  1569. // bottom
  1570. _oContext.fillRect(0, t._elCanvas.height - _htOption.quietZone, t._elCanvas.width, _htOption.quietZone);
  1571. }
  1572. }
  1573. if (_htOption.backgroundImage) {
  1574. // Background Image
  1575. var bgImg = new Image();
  1576. bgImg.onload = function () {
  1577. _oContext.globalAlpha = 1;
  1578. _oContext.globalAlpha = _htOption.backgroundImageAlpha;
  1579. var imageSmoothingQuality = _oContext.imageSmoothingQuality;
  1580. var imageSmoothingEnabled = _oContext.imageSmoothingEnabled;
  1581. _oContext.imageSmoothingEnabled = true;
  1582. _oContext.imageSmoothingQuality = 'high';
  1583. _oContext.drawImage(bgImg, 0, _htOption.titleHeight, _htOption.width + _htOption.quietZone * 2, _htOption.height + _htOption.quietZone * 2 - _htOption.titleHeight);
  1584. _oContext.imageSmoothingEnabled = imageSmoothingEnabled;
  1585. _oContext.imageSmoothingQuality = imageSmoothingQuality;
  1586. _oContext.globalAlpha = 1;
  1587. drawQrcode.call(t, oQRCode);
  1588. };
  1589. // bgImg.crossOrigin='Anonymous';
  1590. if (_htOption.crossOrigin != null) {
  1591. bgImg.crossOrigin = _htOption.crossOrigin;
  1592. }
  1593. bgImg.originalSrc = _htOption.backgroundImage;
  1594. bgImg.src = _htOption.backgroundImage;
  1595. // DoSomething
  1596. } else {
  1597. drawQrcode.call(t, oQRCode);
  1598. }
  1599. function drawQrcode(oQRCode) {
  1600. if (_htOption.onRenderingStart) {
  1601. _htOption.onRenderingStart(_htOption);
  1602. }
  1603. for (var row = 0; row < nCount; row++) {
  1604. for (var col = 0; col < nCount; col++) {
  1605. var nLeft = col * nWidth + _htOption.quietZone;
  1606. var nTop = row * nHeight + _htOption.quietZone;
  1607. var bIsDark = oQRCode.isDark(row, col);
  1608. var eye = oQRCode.getEye(row, col); // { isDark: true/false, type: PO_TL, PI_TL, PO_TR, PI_TR, PO_BL, PI_BL };
  1609. var nowDotScale = _htOption.dotScale;
  1610. _oContext.lineWidth = 0;
  1611. // Color handler
  1612. var dColor;
  1613. var lColor;
  1614. if (eye) {
  1615. dColor = _htOption[eye.type] || _htOption[eye.type.substring(0, 2)] || _htOption.colorDark;
  1616. lColor = _htOption.colorLight;
  1617. } else {
  1618. if (_htOption.backgroundImage) {
  1619. lColor = 'rgba(0,0,0,0)';
  1620. if (row == 6) {
  1621. // dColor = _htOption.timing_H || _htOption.timing || _htOption.colorDark;
  1622. if (_htOption.autoColor) {
  1623. dColor = _htOption.timing_H || _htOption.timing || _htOption.autoColorDark;
  1624. lColor = _htOption.autoColorLight;
  1625. } else {
  1626. dColor = _htOption.timing_H || _htOption.timing || _htOption.colorDark;
  1627. }
  1628. } else if (col == 6) {
  1629. // dColor = _htOption.timing_V || _htOption.timing || _htOption.colorDark;
  1630. if (_htOption.autoColor) {
  1631. dColor = _htOption.timing_V || _htOption.timing || _htOption.autoColorDark;
  1632. lColor = _htOption.autoColorLight;
  1633. } else {
  1634. dColor = _htOption.timing_V || _htOption.timing || _htOption.colorDark;
  1635. }
  1636. } else {
  1637. if (_htOption.autoColor) {
  1638. dColor = _htOption.autoColorDark;
  1639. lColor = _htOption.autoColorLight;
  1640. } else {
  1641. dColor = _htOption.colorDark;
  1642. }
  1643. }
  1644. } else {
  1645. if (row == 6) {
  1646. dColor = _htOption.timing_H || _htOption.timing || _htOption.colorDark;
  1647. } else if (col == 6) {
  1648. dColor = _htOption.timing_V || _htOption.timing || _htOption.colorDark;
  1649. } else {
  1650. dColor = _htOption.colorDark;
  1651. }
  1652. lColor = _htOption.colorLight;
  1653. }
  1654. }
  1655. _oContext.strokeStyle = bIsDark ? dColor : lColor;
  1656. _oContext.fillStyle = bIsDark ? dColor : lColor;
  1657. if (eye) {
  1658. if (eye.type == 'AO') {
  1659. nowDotScale = _htOption.dotScaleAO;
  1660. } else if (eye.type == 'AI') {
  1661. nowDotScale = _htOption.dotScaleAI;
  1662. } else {
  1663. nowDotScale = 1;
  1664. }
  1665. if (_htOption.backgroundImage && _htOption.autoColor) {
  1666. dColor = (eye.type == 'AO' ? _htOption.AI : _htOption.AO) || _htOption.autoColorDark;
  1667. lColor = _htOption.autoColorLight;
  1668. } else {
  1669. dColor = (eye.type == 'AO' ? _htOption.AI : _htOption.AO) || dColor;
  1670. }
  1671. // Is eye
  1672. bIsDark = eye.isDark;
  1673. _oContext.fillRect(nLeft + nWidth * (1 - nowDotScale) / 2, _htOption.titleHeight + nTop + nHeight * (1 - nowDotScale) / 2, nWidth * nowDotScale, nHeight * nowDotScale);
  1674. } else {
  1675. if (row == 6) {
  1676. // Timing Pattern
  1677. nowDotScale = _htOption.dotScaleTiming_H;
  1678. _oContext.fillRect(nLeft + nWidth * (1 - nowDotScale) / 2, _htOption.titleHeight + nTop + nHeight * (1 - nowDotScale) / 2, nWidth * nowDotScale, nHeight * nowDotScale);
  1679. } else if (col == 6) {
  1680. // Timing Pattern
  1681. nowDotScale = _htOption.dotScaleTiming_V;
  1682. _oContext.fillRect(nLeft + nWidth * (1 - nowDotScale) / 2, _htOption.titleHeight + nTop + nHeight * (1 - nowDotScale) / 2, nWidth * nowDotScale, nHeight * nowDotScale);
  1683. } else {
  1684. if (_htOption.backgroundImage) {
  1685. _oContext.fillRect(nLeft + nWidth * (1 - nowDotScale) / 2, _htOption.titleHeight + nTop + nHeight * (1 - nowDotScale) / 2, nWidth * nowDotScale, nHeight * nowDotScale);
  1686. } else {
  1687. _oContext.fillRect(nLeft + nWidth * (1 - nowDotScale) / 2, _htOption.titleHeight + nTop + nHeight * (1 - nowDotScale) / 2, nWidth * nowDotScale, nHeight * nowDotScale);
  1688. }
  1689. }
  1690. }
  1691. if (_htOption.dotScale != 1 && !eye) {
  1692. _oContext.strokeStyle = _htOption.colorLight;
  1693. }
  1694. }
  1695. }
  1696. if (_htOption.title) {
  1697. _oContext.fillStyle = _htOption.titleBackgroundColor;
  1698. _oContext.fillRect(0, 0, this._elCanvas.width, _htOption.titleHeight + _htOption.quietZone);
  1699. _oContext.font = _htOption.titleFont;
  1700. _oContext.fillStyle = _htOption.titleColor;
  1701. _oContext.textAlign = 'center';
  1702. _oContext.fillText(_htOption.title, this._elCanvas.width / 2, +_htOption.quietZone + _htOption.titleTop);
  1703. }
  1704. if (_htOption.subTitle) {
  1705. _oContext.font = _htOption.subTitleFont;
  1706. _oContext.fillStyle = _htOption.subTitleColor;
  1707. _oContext.fillText(_htOption.subTitle, this._elCanvas.width / 2, +_htOption.quietZone + _htOption.subTitleTop);
  1708. }
  1709. function generateLogoImg(img) {
  1710. var imgContainerW = Math.round(_htOption.width / 3.5);
  1711. var imgContainerH = Math.round(_htOption.height / 3.5);
  1712. if (imgContainerW !== imgContainerH) {
  1713. imgContainerW = imgContainerH;
  1714. }
  1715. if (_htOption.logoMaxWidth) {
  1716. imgContainerW = Math.round(_htOption.logoMaxWidth);
  1717. } else if (_htOption.logoWidth) {
  1718. imgContainerW = Math.round(_htOption.logoWidth);
  1719. }
  1720. if (_htOption.logoMaxHeight) {
  1721. imgContainerH = Math.round(_htOption.logoMaxHeight);
  1722. } else if (_htOption.logoHeight) {
  1723. imgContainerH = Math.round(_htOption.logoHeight);
  1724. }
  1725. var nw;
  1726. var nh;
  1727. if (typeof img.naturalWidth == 'undefined') {
  1728. // IE 6/7/8
  1729. nw = img.width;
  1730. nh = img.height;
  1731. } else {
  1732. // HTML5 browsers
  1733. nw = img.naturalWidth;
  1734. nh = img.naturalHeight;
  1735. }
  1736. if (_htOption.logoMaxWidth || _htOption.logoMaxHeight) {
  1737. if (_htOption.logoMaxWidth && nw <= imgContainerW) {
  1738. imgContainerW = nw;
  1739. }
  1740. if (_htOption.logoMaxHeight && nh <= imgContainerH) {
  1741. imgContainerH = nh;
  1742. }
  1743. if (nw <= imgContainerW && nh <= imgContainerH) {
  1744. imgContainerW = nw;
  1745. imgContainerH = nh;
  1746. }
  1747. }
  1748. var imgContainerX = (_htOption.width + _htOption.quietZone * 2 - imgContainerW) / 2;
  1749. var imgContainerY = (_htOption.height + _htOption.titleHeight + _htOption.quietZone * 2 - imgContainerH) / 2;
  1750. var imgScale = Math.min(imgContainerW / nw, imgContainerH / nh);
  1751. var imgW = nw * imgScale;
  1752. var imgH = nh * imgScale;
  1753. if (_htOption.logoMaxWidth || _htOption.logoMaxHeight) {
  1754. imgContainerW = imgW;
  1755. imgContainerH = imgH;
  1756. imgContainerX = (_htOption.width + _htOption.quietZone * 2 - imgContainerW) / 2;
  1757. imgContainerY = (_htOption.height + _htOption.titleHeight + _htOption.quietZone * 2 - imgContainerH) / 2;
  1758. }
  1759. // Did Not Use Transparent Logo Image
  1760. if (!_htOption.logoBackgroundTransparent) {
  1761. //if (!_htOption.logoBackgroundColor) {
  1762. //_htOption.logoBackgroundColor = '#ffffff';
  1763. //}
  1764. _oContext.fillStyle = _htOption.logoBackgroundColor;
  1765. _oContext.fillRect(imgContainerX, imgContainerY, imgContainerW, imgContainerH);
  1766. }
  1767. var imageSmoothingQuality = _oContext.imageSmoothingQuality;
  1768. var imageSmoothingEnabled = _oContext.imageSmoothingEnabled;
  1769. _oContext.imageSmoothingEnabled = true;
  1770. _oContext.imageSmoothingQuality = 'high';
  1771. _oContext.drawImage(img, imgContainerX + (imgContainerW - imgW) / 2, imgContainerY + (imgContainerH - imgH) / 2, imgW, imgH);
  1772. _oContext.imageSmoothingEnabled = imageSmoothingEnabled;
  1773. _oContext.imageSmoothingQuality = imageSmoothingQuality;
  1774. drawQuietZoneColor();
  1775. _this._bIsPainted = true;
  1776. _this.makeImage();
  1777. }
  1778. if (_htOption.logo) {
  1779. // Logo Image
  1780. var img = new Image();
  1781. var _this = this;
  1782. img.onload = function () {
  1783. generateLogoImg(img);
  1784. };
  1785. img.onerror = function (e) {
  1786. console.error(e);
  1787. };
  1788. // img.crossOrigin="Anonymous";
  1789. if (_htOption.crossOrigin != null) {
  1790. img.crossOrigin = _htOption.crossOrigin;
  1791. }
  1792. img.originalSrc = _htOption.logo;
  1793. img.src = _htOption.logo;
  1794. } else {
  1795. drawQuietZoneColor();
  1796. this._bIsPainted = true;
  1797. this.makeImage();
  1798. }
  1799. }
  1800. };
  1801. /**
  1802. * Make the image from Canvas if the browser supports Data URI.
  1803. */
  1804. Drawing.prototype.makeImage = function () {
  1805. if (this._bIsPainted) {
  1806. _safeSetDataURI.call(this, _onMakeImage);
  1807. }
  1808. };
  1809. /**
  1810. * Return whether the QRCode is painted or not
  1811. *
  1812. * @return {Boolean}
  1813. */
  1814. Drawing.prototype.isPainted = function () {
  1815. return this._bIsPainted;
  1816. };
  1817. /**
  1818. * Clear the QRCode
  1819. */
  1820. Drawing.prototype.clear = function () {
  1821. this._oContext.clearRect(0, 0, this._elCanvas.width, this._elCanvas.height);
  1822. this._bIsPainted = false;
  1823. };
  1824. Drawing.prototype.remove = function () {
  1825. this._oContext.clearRect(0, 0, this._elCanvas.width, this._elCanvas.height);
  1826. this._bIsPainted = false;
  1827. this._el.innerHTML = '';
  1828. };
  1829. /**
  1830. * @private
  1831. * @param {Number} nNumber
  1832. */
  1833. Drawing.prototype.round = function (nNumber) {
  1834. if (!nNumber) {
  1835. return nNumber;
  1836. }
  1837. return Math.floor(nNumber * 1000) / 1000;
  1838. };
  1839. return Drawing;
  1840. }();
  1841. /**
  1842. * Get the type by string length
  1843. *
  1844. * @private
  1845. * @param {String} sText
  1846. * @param {Number} nCorrectLevel
  1847. * @return {Number} type
  1848. */
  1849. function _getTypeNumber(sText, _htOption) {
  1850. var nCorrectLevel = _htOption.correctLevel;
  1851. var nType = 1;
  1852. var length = _getUTF8Length(sText);
  1853. for (var i = 0, len = QRCodeLimitLength.length; i < len; i++) {
  1854. var nLimit = 0;
  1855. switch (nCorrectLevel) {
  1856. case QRErrorCorrectLevel.L:
  1857. nLimit = QRCodeLimitLength[i][0];
  1858. break;
  1859. case QRErrorCorrectLevel.M:
  1860. nLimit = QRCodeLimitLength[i][1];
  1861. break;
  1862. case QRErrorCorrectLevel.Q:
  1863. nLimit = QRCodeLimitLength[i][2];
  1864. break;
  1865. case QRErrorCorrectLevel.H:
  1866. nLimit = QRCodeLimitLength[i][3];
  1867. break;
  1868. }
  1869. if (length <= nLimit) {
  1870. break;
  1871. } else {
  1872. nType++;
  1873. }
  1874. }
  1875. if (nType > QRCodeLimitLength.length) {
  1876. throw new Error('Too long data. the CorrectLevel.' + ['M', 'L', 'H', 'Q'][nCorrectLevel] + ' limit length is ' + nLimit);
  1877. }
  1878. if (_htOption.version != 0) {
  1879. if (nType <= _htOption.version) {
  1880. nType = _htOption.version;
  1881. _htOption.runVersion = nType;
  1882. } else {
  1883. console.warn('QR Code version ' + _htOption.version + ' too small, run version use ' + nType);
  1884. _htOption.runVersion = nType;
  1885. }
  1886. }
  1887. return nType;
  1888. }
  1889. function _getUTF8Length(sText) {
  1890. var replacedText = encodeURI(sText).toString().replace(/\%[0-9a-fA-F]{2}/g, 'a');
  1891. return replacedText.length + (replacedText.length != sText.length ? 3 : 0);
  1892. }
  1893. QRCode = function QRCode(el, vOption) {
  1894. this._htOption = {
  1895. width: 256,
  1896. height: 256,
  1897. typeNumber: 4,
  1898. colorDark: '#000000',
  1899. colorLight: '#ffffff',
  1900. correctLevel: QRErrorCorrectLevel.H,
  1901. dotScale: 1,
  1902. // For body block, must be greater than 0, less than or equal to 1. default is 1
  1903. dotScaleTiming: 1,
  1904. // Dafault for timing block , must be greater than 0, less than or equal to 1. default is 1
  1905. dotScaleTiming_H: undefined$1,
  1906. // For horizontal timing block, must be greater than 0, less than or equal to 1. default is 1
  1907. dotScaleTiming_V: undefined$1,
  1908. // For vertical timing block, must be greater than 0, less than or equal to 1. default is 1
  1909. dotScaleA: 1,
  1910. // Dafault for alignment block, must be greater than 0, less than or equal to 1. default is 1
  1911. dotScaleAO: undefined$1,
  1912. // For alignment outer block, must be greater than 0, less than or equal to 1. default is 1
  1913. dotScaleAI: undefined$1,
  1914. // For alignment inner block, must be greater than 0, less than or equal to 1. default is 1
  1915. quietZone: 0,
  1916. quietZoneColor: 'rgba(0,0,0,0)',
  1917. title: '',
  1918. titleFont: 'normal normal bold 16px Arial',
  1919. titleColor: '#000000',
  1920. titleBackgroundColor: '#ffffff',
  1921. titleHeight: 0,
  1922. // Title Height, Include subTitle
  1923. titleTop: 30,
  1924. // draws y coordinates. default is 30
  1925. subTitle: '',
  1926. subTitleFont: 'normal normal normal 14px Arial',
  1927. subTitleColor: '#4F4F4F',
  1928. subTitleTop: 60,
  1929. // draws y coordinates. default is 0
  1930. logo: undefined$1,
  1931. logoWidth: undefined$1,
  1932. logoHeight: undefined$1,
  1933. logoMaxWidth: undefined$1,
  1934. logoMaxHeight: undefined$1,
  1935. logoBackgroundColor: '#ffffff',
  1936. logoBackgroundTransparent: false,
  1937. // === Posotion Pattern(Eye) Color
  1938. PO: undefined$1,
  1939. // Global Posotion Outer color. if not set, the defaut is `colorDark`
  1940. PI: undefined$1,
  1941. // Global Posotion Inner color. if not set, the defaut is `colorDark`
  1942. PO_TL: undefined$1,
  1943. // Posotion Outer - Top Left
  1944. PI_TL: undefined$1,
  1945. // Posotion Inner - Top Left
  1946. PO_TR: undefined$1,
  1947. // Posotion Outer - Top Right
  1948. PI_TR: undefined$1,
  1949. // Posotion Inner - Top Right
  1950. PO_BL: undefined$1,
  1951. // Posotion Outer - Bottom Left
  1952. PI_BL: undefined$1,
  1953. // Posotion Inner - Bottom Left
  1954. // === Alignment Color
  1955. AO: undefined$1,
  1956. // Alignment Outer. if not set, the defaut is `colorDark`
  1957. AI: undefined$1,
  1958. // Alignment Inner. if not set, the defaut is `colorDark`
  1959. // === Timing Pattern Color
  1960. timing: undefined$1,
  1961. // Global Timing color. if not set, the defaut is `colorDark`
  1962. timing_H: undefined$1,
  1963. // Horizontal timing color
  1964. timing_V: undefined$1,
  1965. // Vertical timing color
  1966. // ==== Backgroud Image
  1967. backgroundImage: undefined$1,
  1968. // Background Image
  1969. backgroundImageAlpha: 1,
  1970. // Background image transparency, value between 0 and 1. default is 1.
  1971. autoColor: false,
  1972. // Automatic color adjustment(for data block)
  1973. autoColorDark: 'rgba(0, 0, 0, .6)',
  1974. // Automatic color: dark CSS color
  1975. autoColorLight: 'rgba(255, 255, 255, .7)',
  1976. // Automatic color: light CSS color
  1977. // ==== Event Handler
  1978. onRenderingStart: undefined$1,
  1979. onRenderingEnd: undefined$1,
  1980. // ==== Versions
  1981. version: 0,
  1982. // The symbol versions of QR Code range from Version 1 to Version 40. default 0 means automatically choose the closest version based on the text length.
  1983. // ==== Tooltip
  1984. tooltip: false,
  1985. // Whether set the QRCode Text as the title attribute value of the image
  1986. // ==== Binary(hex) data mode
  1987. binary: false,
  1988. // Whether it is binary mode, default is text mode.
  1989. // ==== Drawing method
  1990. drawer: 'canvas',
  1991. // Drawing method: canvas, svg(Chrome, FF, IE9+)
  1992. // ==== CORS
  1993. crossOrigin: null,
  1994. // String which specifies the CORS setting to use when retrieving the image. null means that the crossOrigin attribute is not set.
  1995. // UTF-8 without BOM
  1996. utf8WithoutBOM: true
  1997. };
  1998. if (typeof vOption === 'string') {
  1999. vOption = {
  2000. text: vOption
  2001. };
  2002. }
  2003. // Overwrites options
  2004. if (vOption) {
  2005. for (var i in vOption) {
  2006. this._htOption[i] = vOption[i];
  2007. }
  2008. }
  2009. if (this._htOption.version < 0 || this._htOption.version > 40) {
  2010. console.warn("QR Code version '" + this._htOption.version + "' is invalidate, reset to 0");
  2011. this._htOption.version = 0;
  2012. }
  2013. if (this._htOption.dotScale < 0 || this._htOption.dotScale > 1) {
  2014. console.warn(this._htOption.dotScale + ' , is invalidate, dotScale must greater than 0, less than or equal to 1, now reset to 1. ');
  2015. this._htOption.dotScale = 1;
  2016. }
  2017. if (this._htOption.dotScaleTiming < 0 || this._htOption.dotScaleTiming > 1) {
  2018. console.warn(this._htOption.dotScaleTiming + ' , is invalidate, dotScaleTiming must greater than 0, less than or equal to 1, now reset to 1. ');
  2019. this._htOption.dotScaleTiming = 1;
  2020. }
  2021. if (this._htOption.dotScaleTiming_H) {
  2022. if (this._htOption.dotScaleTiming_H < 0 || this._htOption.dotScaleTiming_H > 1) {
  2023. console.warn(this._htOption.dotScaleTiming_H + ' , is invalidate, dotScaleTiming_H must greater than 0, less than or equal to 1, now reset to 1. ');
  2024. this._htOption.dotScaleTiming_H = 1;
  2025. }
  2026. } else {
  2027. this._htOption.dotScaleTiming_H = this._htOption.dotScaleTiming;
  2028. }
  2029. if (this._htOption.dotScaleTiming_V) {
  2030. if (this._htOption.dotScaleTiming_V < 0 || this._htOption.dotScaleTiming_V > 1) {
  2031. console.warn(this._htOption.dotScaleTiming_V + ' , is invalidate, dotScaleTiming_V must greater than 0, less than or equal to 1, now reset to 1. ');
  2032. this._htOption.dotScaleTiming_V = 1;
  2033. }
  2034. } else {
  2035. this._htOption.dotScaleTiming_V = this._htOption.dotScaleTiming;
  2036. }
  2037. if (this._htOption.dotScaleA < 0 || this._htOption.dotScaleA > 1) {
  2038. console.warn(this._htOption.dotScaleA + ' , is invalidate, dotScaleA must greater than 0, less than or equal to 1, now reset to 1. ');
  2039. this._htOption.dotScaleA = 1;
  2040. }
  2041. if (this._htOption.dotScaleAO) {
  2042. if (this._htOption.dotScaleAO < 0 || this._htOption.dotScaleAO > 1) {
  2043. console.warn(this._htOption.dotScaleAO + ' , is invalidate, dotScaleAO must greater than 0, less than or equal to 1, now reset to 1. ');
  2044. this._htOption.dotScaleAO = 1;
  2045. }
  2046. } else {
  2047. this._htOption.dotScaleAO = this._htOption.dotScaleA;
  2048. }
  2049. if (this._htOption.dotScaleAI) {
  2050. if (this._htOption.dotScaleAI < 0 || this._htOption.dotScaleAI > 1) {
  2051. console.warn(this._htOption.dotScaleAI + ' , is invalidate, dotScaleAI must greater than 0, less than or equal to 1, now reset to 1. ');
  2052. this._htOption.dotScaleAI = 1;
  2053. }
  2054. } else {
  2055. this._htOption.dotScaleAI = this._htOption.dotScaleA;
  2056. }
  2057. if (this._htOption.backgroundImageAlpha < 0 || this._htOption.backgroundImageAlpha > 1) {
  2058. console.warn(this._htOption.backgroundImageAlpha + ' , is invalidate, backgroundImageAlpha must between 0 and 1, now reset to 1. ');
  2059. this._htOption.backgroundImageAlpha = 1;
  2060. }
  2061. this._htOption.height = this._htOption.height + this._htOption.titleHeight;
  2062. if (typeof el == 'string') {
  2063. el = document.getElementById(el);
  2064. }
  2065. if (!this._htOption.drawer || this._htOption.drawer != 'svg' && this._htOption.drawer != 'canvas') {
  2066. this._htOption.drawer = 'canvas';
  2067. }
  2068. this._android = _getAndroid();
  2069. this._el = el;
  2070. this._oQRCode = null;
  2071. var _htOptionClone = {};
  2072. for (var i in this._htOption) {
  2073. _htOptionClone[i] = this._htOption[i];
  2074. }
  2075. this._oDrawing = new Drawing(this._el, _htOptionClone);
  2076. if (this._htOption.text) {
  2077. this.makeCode(this._htOption.text);
  2078. }
  2079. };
  2080. /**
  2081. * Make the QRCode
  2082. *
  2083. * @param {String} sText link data
  2084. */
  2085. QRCode.prototype.makeCode = function (sText) {
  2086. this._oQRCode = new QRCodeModel(_getTypeNumber(sText, this._htOption), this._htOption.correctLevel);
  2087. this._oQRCode.addData(sText, this._htOption.binary, this._htOption.utf8WithoutBOM);
  2088. this._oQRCode.make();
  2089. if (this._htOption.tooltip) {
  2090. this._el.title = sText;
  2091. }
  2092. this._oDrawing.draw(this._oQRCode);
  2093. // this.makeImage();
  2094. };
  2095. /**
  2096. * Make the Image from Canvas element
  2097. * - It occurs automatically
  2098. * - Android below 3 doesn't support Data-URI spec.
  2099. *
  2100. * @private
  2101. */
  2102. QRCode.prototype.makeImage = function () {
  2103. if (typeof this._oDrawing.makeImage == 'function' && (!this._android || this._android >= 3)) {
  2104. this._oDrawing.makeImage();
  2105. }
  2106. };
  2107. /**
  2108. * Clear the QRCode
  2109. */
  2110. QRCode.prototype.clear = function () {
  2111. this._oDrawing.remove();
  2112. };
  2113. /**
  2114. * Resize the QRCode
  2115. */
  2116. QRCode.prototype.resize = function (width, height) {
  2117. this._oDrawing._htOption.width = width;
  2118. this._oDrawing._htOption.height = height;
  2119. this._oDrawing.draw(this._oQRCode);
  2120. };
  2121. /**
  2122. * No Conflict
  2123. * @return QRCode object
  2124. */
  2125. QRCode.prototype.noConflict = function () {
  2126. if (root.QRCode === this) {
  2127. root.QRCode = _QRCode;
  2128. }
  2129. return QRCode;
  2130. };
  2131. /**
  2132. * @name QRCode.CorrectLevel
  2133. */
  2134. QRCode.CorrectLevel = QRErrorCorrectLevel;
  2135. /*--------------------------------------------------------------------------*/
  2136. // Export QRCode
  2137. // AMD & CMD Compatibility
  2138. if (typeof define == 'function' && (define.amd || define.cmd)) {
  2139. // 1. Define an anonymous module
  2140. define([], function () {
  2141. return QRCode;
  2142. });
  2143. }
  2144. // CommonJS Compatibility(include NodeJS)
  2145. else if (freeModule) {
  2146. // Node.js
  2147. (freeModule.exports = QRCode).QRCode = QRCode;
  2148. // Other CommonJS
  2149. freeExports.QRCode = QRCode;
  2150. } else {
  2151. // Export Global
  2152. root.QRCode = QRCode;
  2153. }
  2154. }
  2155. var version = "2.10.0";
  2156. var formatVersion = version.replace(/\./g, '_'); //replace . with _
  2157. QRCode();
  2158. removeExpiredLocalStorageItems();
  2159. getQueryParamsAndSaveToLocalStorage(window.location.href);
  2160. saveWebReferrer();
  2161. (function () {
  2162. var generateOneLinkURL = function generateOneLinkURL() {
  2163. var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
  2164. afParameters: {}
  2165. };
  2166. var oneLinkURL = parameters.oneLinkURL,
  2167. _parameters$afParamet = parameters.afParameters,
  2168. _parameters$afParamet2 = _parameters$afParamet === void 0 ? {} : _parameters$afParamet,
  2169. mediaSource = _parameters$afParamet2.mediaSource,
  2170. _parameters$referrerS = parameters.referrerSkipList,
  2171. referrerSkipList = _parameters$referrerS === void 0 ? [] : _parameters$referrerS,
  2172. _parameters$urlSkipLi = parameters.urlSkipList,
  2173. urlSkipList = _parameters$urlSkipLi === void 0 ? [] : _parameters$urlSkipLi,
  2174. webReferrer = parameters.webReferrer;
  2175. if (!isOneLinkURLValid(oneLinkURL)) return null;
  2176. if (!isSkipListsValid({
  2177. referrerSkipList: referrerSkipList,
  2178. urlSkipList: urlSkipList
  2179. })) return null;
  2180. if (!isMSValid(mediaSource)) return null;
  2181. var aggregateValues = aggregateValuesFromParameters(parameters.afParameters);
  2182. var currentURLParams = getCurrentURLParams(aggregateValues);
  2183. var validParams = validateAndMappedParams(parameters.afParameters, currentURLParams);
  2184. if (!validParams) return null;
  2185. var afParams = _objectSpread2({
  2186. af_js_web: true,
  2187. af_ss_ver: window.AF_SMART_SCRIPT.version
  2188. }, validParams);
  2189. var finalParams = stringifyParameters(afParams).replace('&', '?');
  2190. var finalURL = oneLinkURL + finalParams;
  2191. var webReferrerValue = JSON.parse(localStorage.getItem(LOCAL_STORAGE_VALUES.SS_WEB_REFERRER));
  2192. if (webReferrer && webReferrerValue && isValidUrl(webReferrerValue)) {
  2193. var webReferrerKeyValue = "&".concat(webReferrer, "=").concat(webReferrerValue);
  2194. finalURL = "".concat(finalURL).concat(webReferrerKeyValue);
  2195. }
  2196. finalURL = processTrackingParameters(finalURL);
  2197. console.debug('Generated OneLink URL', finalURL);
  2198. window.AF_SMART_SCRIPT.displayQrCode = function (htmlId) {
  2199. var qrOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2200. var _qrOptions$logo = qrOptions.logo,
  2201. logo = _qrOptions$logo === void 0 ? '' : _qrOptions$logo,
  2202. _qrOptions$codeColor = qrOptions.codeColor,
  2203. codeColor = _qrOptions$codeColor === void 0 ? '#000' : _qrOptions$codeColor;
  2204. if (!finalURL) {
  2205. console.debug('ClickURL is not valid');
  2206. return null;
  2207. }
  2208. return new QRCode(document.getElementById(htmlId), {
  2209. text: "".concat(finalURL, "&af_ss_qr=").concat(qrOptions.logo || qrOptions.codeColor ? 'c' : 'true', " "),
  2210. logo: logo,
  2211. colorDark: getHexColorAfterValidation(codeColor),
  2212. logoBackgroundTransparent: true,
  2213. crossOrigin: 'anonymous',
  2214. correctLevel: logo ? QRCode.CorrectLevel.Q : QRCode.CorrectLevel.L
  2215. });
  2216. };
  2217. createImpressionsLink(finalURL).then(function (impressionsLinkURL) {
  2218. if (impressionsLinkURL) {
  2219. window.AF_SMART_SCRIPT.fireImpressionsLink = function () {
  2220. var img = new Image(1, 1);
  2221. img.style.display = 'none';
  2222. img.style.position = 'absolute';
  2223. img.style.left = '-1px';
  2224. img.style.top = '-1px';
  2225. img.src = impressionsLinkURL;
  2226. };
  2227. }
  2228. });
  2229. return {
  2230. clickURL: finalURL
  2231. };
  2232. };
  2233. var generateDirectClickURL = function generateDirectClickURL() {
  2234. var _campaign$keys;
  2235. var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
  2236. afParameters: {},
  2237. referrerSkipList: [],
  2238. urlSkipList: []
  2239. };
  2240. var _parameters$afParamet3 = parameters.afParameters,
  2241. afParameters = _parameters$afParamet3 === void 0 ? {} : _parameters$afParamet3,
  2242. _parameters$referrerS2 = parameters.referrerSkipList,
  2243. referrerSkipList = _parameters$referrerS2 === void 0 ? [] : _parameters$referrerS2,
  2244. _parameters$urlSkipLi2 = parameters.urlSkipList,
  2245. urlSkipList = _parameters$urlSkipLi2 === void 0 ? [] : _parameters$urlSkipLi2,
  2246. platform = parameters.platform,
  2247. app_id = parameters.app_id,
  2248. redirectURL = parameters.redirectURL;
  2249. var mediaSource = afParameters.mediaSource,
  2250. campaign = afParameters.campaign;
  2251. if (!mediaSource) {
  2252. console.error("mediaSource is missing , can't generate URL", mediaSource);
  2253. return null;
  2254. }
  2255. if (!campaign) {
  2256. console.error("campaign is missing , can't generate URL", campaign);
  2257. return null;
  2258. }
  2259. if (!app_id) {
  2260. console.error("app_id is missing , can't generate URL", app_id);
  2261. return null;
  2262. }
  2263. if (!redirectURL) {
  2264. console.error("redirectURL is missing , can't generate URL", redirectURL);
  2265. return null;
  2266. }
  2267. var lowerCasePlatform = platform === null || platform === void 0 ? void 0 : platform.toLowerCase();
  2268. if (!isPlatformValid(lowerCasePlatform)) return null;
  2269. if (typeof app_id !== 'string') {
  2270. console.error('app_id must be a string');
  2271. return null;
  2272. }
  2273. if ((campaign === null || campaign === void 0 || (_campaign$keys = campaign.keys) === null || _campaign$keys === void 0 ? void 0 : _campaign$keys.length) === 0 && !(campaign !== null && campaign !== void 0 && campaign.defaultValue)) {
  2274. console.error("campaign is missing (default value was not supplied), can't generate URL", mediaSource);
  2275. return null;
  2276. }
  2277. if (!isSkipListsValid({
  2278. referrerSkipList: referrerSkipList,
  2279. urlSkipList: urlSkipList
  2280. })) return null;
  2281. if (!isMSValid(mediaSource)) return null;
  2282. var aggregateValues = aggregateValuesFromParameters(parameters.afParameters);
  2283. var currentURLParams = getCurrentURLParams(aggregateValues);
  2284. var validParams = validateAndMappedParams(parameters.afParameters, currentURLParams, true);
  2285. if (!validParams) return null;
  2286. var afParams = _objectSpread2({
  2287. af_js_web: true,
  2288. af_ss_ver: window.AF_SMART_SCRIPT.version
  2289. }, validParams);
  2290. var finalParams = stringifyParameters(afParams).replace('&', '?');
  2291. var clickBaseUrl = "https://engagements.appsflyer.com/v1.0/c2s/click/app/".concat(lowerCasePlatform);
  2292. if (['ios', 'android'].includes(lowerCasePlatform)) {
  2293. clickBaseUrl = 'https://app.appsflyer.com';
  2294. }
  2295. var finalURL = "".concat(clickBaseUrl, "/").concat(app_id).concat(finalParams, "&af_r=").concat(encodeURIComponent(redirectURL));
  2296. if (['ios', 'android'].includes(lowerCasePlatform)) {
  2297. finalURL = finalURL.replace('af_media_source', 'pid').replace('af_campaign', 'c').replace('af_campaign_id', 'af_c_id');
  2298. }
  2299. finalURL = processTrackingParameters(finalURL);
  2300. console.debug('generate Direct Click URL', finalURL);
  2301. delete window.AF_SMART_SCRIPT.displayQrCode;
  2302. delete window.AF_SMART_SCRIPT.fireImpressionsLink;
  2303. return {
  2304. clickURL: finalURL
  2305. };
  2306. };
  2307. window.AF_SMART_SCRIPT = {
  2308. generateOneLinkURL: generateOneLinkURL,
  2309. generateDirectClickURL: generateDirectClickURL,
  2310. version: formatVersion
  2311. };
  2312. })();