sales-frontend-utils 0.0.18 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -473,6 +473,37 @@ var convertTextToImg = ({
473
473
  ctx.fillText(targetStr, canvas.width / 2, canvas.height / 2);
474
474
  return canvas.toDataURL();
475
475
  };
476
+ function drawImageResizeCentered(base64, size) {
477
+ return new Promise((resolve) => {
478
+ const { canvasHeight, canvasWidth } = size;
479
+ const canvas = document.createElement("canvas");
480
+ canvas.width = canvasWidth;
481
+ canvas.height = canvasHeight;
482
+ const ctx = canvas.getContext("2d");
483
+ const img = new Image();
484
+ img.src = base64;
485
+ img.onload = () => {
486
+ const imageWidth = img.width;
487
+ const imageHeight = img.height;
488
+ const canvasRatio = canvasWidth / canvasHeight;
489
+ const imageRatio = imageWidth / imageHeight;
490
+ let newWidth;
491
+ let newHeight;
492
+ if (imageRatio > canvasRatio) {
493
+ newWidth = canvasWidth;
494
+ newHeight = newWidth / imageRatio;
495
+ } else {
496
+ newHeight = canvasHeight;
497
+ newWidth = newHeight * imageRatio;
498
+ }
499
+ const x = (canvasWidth - newWidth) / 2;
500
+ const y = (canvasHeight - newHeight) / 2;
501
+ ctx?.clearRect(0, 0, canvasWidth, canvasHeight);
502
+ ctx?.drawImage(img, x, y, newWidth, newHeight);
503
+ resolve(canvas.toDataURL());
504
+ };
505
+ });
506
+ }
476
507
 
477
508
  // src/utils/cookie-utils.ts
478
509
  var getCookie = (name) => {
@@ -575,19 +606,16 @@ var astx2_custom_default = "/* ASTx 1.3 | (C) Copyright AhnLab, Inc. | $Revision
575
606
 
576
607
  // src/utils/astx2-utils.ts
577
608
  function addE2EObject(el, e2e_type) {
578
- const globalThis = window;
579
- if (globalThis.$ASTX2) {
580
- globalThis.$ASTX2.addE2EObject(el, e2e_type);
581
- globalThis.$ASTX2.resetE2E();
609
+ if (window.$ASTX2) {
610
+ window.$ASTX2.addE2EObject(el, e2e_type);
611
+ window.$ASTX2.resetE2E();
582
612
  }
583
613
  }
584
614
  function hasAstx2() {
585
- const globalThis = window;
586
- return !!globalThis.$ASTX2;
615
+ return !!window.$ASTX2;
587
616
  }
588
617
  var loadScript = (callback) => {
589
- const globalThis = window;
590
- if (!globalThis.$ASTX2) {
618
+ if (!window.$ASTX2) {
591
619
  console.log("dynamic load");
592
620
  const script = document.createElement("script");
593
621
  script.innerHTML = `
@@ -610,27 +638,26 @@ var init = ({
610
638
  checkServerFailure = () => {
611
639
  }
612
640
  } = {}) => {
613
- const globalThis = window;
614
- globalThis.$ASTX2.init(
641
+ window.$ASTX2.init(
615
642
  () => {
616
- globalThis.$ASTX2.initE2E();
617
- globalThis.$ASTX2.checkServer(
643
+ window.$ASTX2.initE2E();
644
+ window.$ASTX2.checkServer(
618
645
  () => {
619
646
  checkServerSuccess();
620
647
  },
621
648
  () => {
622
649
  checkServerFailure();
623
- console.error(`ASTX.checkServer() onFailure: errno=${globalThis.$ASTX2.getLastError()}`);
650
+ console.error(`ASTX.checkServer() onFailure: errno=${window.$ASTX2.getLastError()}`);
624
651
  }
625
652
  );
626
653
  initSuccess();
627
654
  },
628
655
  () => {
629
656
  initFailure();
630
- if (globalThis.$ASTX2.getLastError() === 103) {
657
+ if (window.$ASTX2.getLastError() === 103) {
631
658
  console.error("AhnLab Safe Transaction \uD074\uB77C\uC774\uC5B8\uD2B8\uAC00 \uC124\uCE58\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4.");
632
659
  } else {
633
- console.error(`$ASTX2.init() onFailure: errno=${globalThis.$ASTX2.getLastError()}`);
660
+ console.error(`$ASTX2.init() onFailure: errno=${window.$ASTX2.getLastError()}`);
634
661
  }
635
662
  }
636
663
  );
@@ -645,8 +672,7 @@ var initASTX2 = ({
645
672
  checkServerFailure = () => {
646
673
  }
647
674
  } = {}) => {
648
- const globalThis = window;
649
- if (globalThis.$ASTX2) {
675
+ if (window.$ASTX2) {
650
676
  init({
651
677
  initSuccess,
652
678
  initFailure,
@@ -657,16 +683,15 @@ var initASTX2 = ({
657
683
  };
658
684
  function getE2EDataIDs(ids, onSuccess, onFailure = () => {
659
685
  }) {
660
- const globalThis = window;
661
- if (globalThis.$ASTX2) {
662
- globalThis.$ASTX2.getE2EDataIDs(
686
+ if (window.$ASTX2) {
687
+ window.$ASTX2.getE2EDataIDs(
663
688
  ids,
664
689
  async (astx_data) => {
665
690
  onSuccess(astx_data);
666
691
  },
667
692
  () => {
668
693
  onFailure();
669
- console.log(`ASTX.getE2EData() onFailure: errno=${globalThis.$ASTX2.getLastError()}`);
694
+ console.log(`ASTX.getE2EData() onFailure: errno=${window.$ASTX2.getLastError()}`);
670
695
  }
671
696
  );
672
697
  }
@@ -681,6 +706,7 @@ exports.checkUserAgentDspApp = checkUserAgentDspApp;
681
706
  exports.convertTextToImg = convertTextToImg;
682
707
  exports.debounce = debounce;
683
708
  exports.deleteCookie = deleteCookie;
709
+ exports.drawImageResizeCentered = drawImageResizeCentered;
684
710
  exports.fileToBase64 = fileToBase64;
685
711
  exports.getApiHostNameFromEnvironment = getApiHostNameFromEnvironment;
686
712
  exports.getBrowserName = getBrowserName;