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.d.cts CHANGED
@@ -233,6 +233,10 @@ interface ConvertTextToImgParams {
233
233
  * @returns Base64로 인코딩된 이미지 데이터 URL
234
234
  */
235
235
  declare const convertTextToImg: ({ targetStr, canvasWidth, canvasHeight, backgroundColor, fontColor, fontSize, fontWeight }: ConvertTextToImgParams) => string;
236
+ declare function drawImageResizeCentered(base64: string, size: {
237
+ canvasWidth: number;
238
+ canvasHeight: number;
239
+ }): Promise<unknown>;
236
240
 
237
241
  declare const getCookie: (name: string) => string;
238
242
  declare const setCookie: (name: string, value: string, options?: {
@@ -256,11 +260,6 @@ declare function fileToBase64(file: File | Blob): Promise<string>;
256
260
  */
257
261
  declare function getExt(data: string | File | Blob): string | undefined;
258
262
 
259
- declare global {
260
- interface Window {
261
- $ASTX2: any;
262
- }
263
- }
264
263
  /**
265
264
  * element를 동적으로 추가하는 경우 사용.
266
265
  * @param el HTMLElement
@@ -288,4 +287,4 @@ declare const initASTX2: ({ initSuccess, initFailure, checkServerSuccess, checkS
288
287
  */
289
288
  declare function getE2EDataIDs(ids: string[], onSuccess: (astx_data: any) => void, onFailure?: () => void): void;
290
289
 
291
- export { type BrowserName, type ExecutionEnvironment, MessageEventManager, type OSName, addE2EObject, base64ToBlob, base64ToFile, blobToFile, checkUserAgentDspApp, convertTextToImg, debounce, deleteCookie, fileToBase64, getApiHostNameFromEnvironment, getBrowserName, getBrowserVersion, getCdnHostNameFromEnvironment, getCookie, getCurrentBrowserName, getCurrentBrowserVersion, getCurrentOSName, getCurrentOSVersion, getDeviceModel, getDspExecutionEnvironment, getE2EDataIDs, getEnvironmentFromHostname, getExt, getFormFactorFromUserAgent, getOSName, getOSVersion, getOrCreateDeviceId, getSubdomain, hasAstx2, initASTX2, isClient, isDspApp, isFpPlannerApp, isPc, isPhone, isSalesPortal, isStorybookEnv, isTablet, isWebView, loadScript, setCookie, throttle };
290
+ export { type BrowserName, type ExecutionEnvironment, MessageEventManager, type OSName, addE2EObject, base64ToBlob, base64ToFile, blobToFile, checkUserAgentDspApp, convertTextToImg, debounce, deleteCookie, drawImageResizeCentered, fileToBase64, getApiHostNameFromEnvironment, getBrowserName, getBrowserVersion, getCdnHostNameFromEnvironment, getCookie, getCurrentBrowserName, getCurrentBrowserVersion, getCurrentOSName, getCurrentOSVersion, getDeviceModel, getDspExecutionEnvironment, getE2EDataIDs, getEnvironmentFromHostname, getExt, getFormFactorFromUserAgent, getOSName, getOSVersion, getOrCreateDeviceId, getSubdomain, hasAstx2, initASTX2, isClient, isDspApp, isFpPlannerApp, isPc, isPhone, isSalesPortal, isStorybookEnv, isTablet, isWebView, loadScript, setCookie, throttle };
package/dist/index.d.ts CHANGED
@@ -233,6 +233,10 @@ interface ConvertTextToImgParams {
233
233
  * @returns Base64로 인코딩된 이미지 데이터 URL
234
234
  */
235
235
  declare const convertTextToImg: ({ targetStr, canvasWidth, canvasHeight, backgroundColor, fontColor, fontSize, fontWeight }: ConvertTextToImgParams) => string;
236
+ declare function drawImageResizeCentered(base64: string, size: {
237
+ canvasWidth: number;
238
+ canvasHeight: number;
239
+ }): Promise<unknown>;
236
240
 
237
241
  declare const getCookie: (name: string) => string;
238
242
  declare const setCookie: (name: string, value: string, options?: {
@@ -256,11 +260,6 @@ declare function fileToBase64(file: File | Blob): Promise<string>;
256
260
  */
257
261
  declare function getExt(data: string | File | Blob): string | undefined;
258
262
 
259
- declare global {
260
- interface Window {
261
- $ASTX2: any;
262
- }
263
- }
264
263
  /**
265
264
  * element를 동적으로 추가하는 경우 사용.
266
265
  * @param el HTMLElement
@@ -288,4 +287,4 @@ declare const initASTX2: ({ initSuccess, initFailure, checkServerSuccess, checkS
288
287
  */
289
288
  declare function getE2EDataIDs(ids: string[], onSuccess: (astx_data: any) => void, onFailure?: () => void): void;
290
289
 
291
- export { type BrowserName, type ExecutionEnvironment, MessageEventManager, type OSName, addE2EObject, base64ToBlob, base64ToFile, blobToFile, checkUserAgentDspApp, convertTextToImg, debounce, deleteCookie, fileToBase64, getApiHostNameFromEnvironment, getBrowserName, getBrowserVersion, getCdnHostNameFromEnvironment, getCookie, getCurrentBrowserName, getCurrentBrowserVersion, getCurrentOSName, getCurrentOSVersion, getDeviceModel, getDspExecutionEnvironment, getE2EDataIDs, getEnvironmentFromHostname, getExt, getFormFactorFromUserAgent, getOSName, getOSVersion, getOrCreateDeviceId, getSubdomain, hasAstx2, initASTX2, isClient, isDspApp, isFpPlannerApp, isPc, isPhone, isSalesPortal, isStorybookEnv, isTablet, isWebView, loadScript, setCookie, throttle };
290
+ export { type BrowserName, type ExecutionEnvironment, MessageEventManager, type OSName, addE2EObject, base64ToBlob, base64ToFile, blobToFile, checkUserAgentDspApp, convertTextToImg, debounce, deleteCookie, drawImageResizeCentered, fileToBase64, getApiHostNameFromEnvironment, getBrowserName, getBrowserVersion, getCdnHostNameFromEnvironment, getCookie, getCurrentBrowserName, getCurrentBrowserVersion, getCurrentOSName, getCurrentOSVersion, getDeviceModel, getDspExecutionEnvironment, getE2EDataIDs, getEnvironmentFromHostname, getExt, getFormFactorFromUserAgent, getOSName, getOSVersion, getOrCreateDeviceId, getSubdomain, hasAstx2, initASTX2, isClient, isDspApp, isFpPlannerApp, isPc, isPhone, isSalesPortal, isStorybookEnv, isTablet, isWebView, loadScript, setCookie, throttle };
package/dist/index.js CHANGED
@@ -471,6 +471,37 @@ var convertTextToImg = ({
471
471
  ctx.fillText(targetStr, canvas.width / 2, canvas.height / 2);
472
472
  return canvas.toDataURL();
473
473
  };
474
+ function drawImageResizeCentered(base64, size) {
475
+ return new Promise((resolve) => {
476
+ const { canvasHeight, canvasWidth } = size;
477
+ const canvas = document.createElement("canvas");
478
+ canvas.width = canvasWidth;
479
+ canvas.height = canvasHeight;
480
+ const ctx = canvas.getContext("2d");
481
+ const img = new Image();
482
+ img.src = base64;
483
+ img.onload = () => {
484
+ const imageWidth = img.width;
485
+ const imageHeight = img.height;
486
+ const canvasRatio = canvasWidth / canvasHeight;
487
+ const imageRatio = imageWidth / imageHeight;
488
+ let newWidth;
489
+ let newHeight;
490
+ if (imageRatio > canvasRatio) {
491
+ newWidth = canvasWidth;
492
+ newHeight = newWidth / imageRatio;
493
+ } else {
494
+ newHeight = canvasHeight;
495
+ newWidth = newHeight * imageRatio;
496
+ }
497
+ const x = (canvasWidth - newWidth) / 2;
498
+ const y = (canvasHeight - newHeight) / 2;
499
+ ctx?.clearRect(0, 0, canvasWidth, canvasHeight);
500
+ ctx?.drawImage(img, x, y, newWidth, newHeight);
501
+ resolve(canvas.toDataURL());
502
+ };
503
+ });
504
+ }
474
505
 
475
506
  // src/utils/cookie-utils.ts
476
507
  var getCookie = (name) => {
@@ -573,19 +604,16 @@ var astx2_custom_default = "/* ASTx 1.3 | (C) Copyright AhnLab, Inc. | $Revision
573
604
 
574
605
  // src/utils/astx2-utils.ts
575
606
  function addE2EObject(el, e2e_type) {
576
- const globalThis = window;
577
- if (globalThis.$ASTX2) {
578
- globalThis.$ASTX2.addE2EObject(el, e2e_type);
579
- globalThis.$ASTX2.resetE2E();
607
+ if (window.$ASTX2) {
608
+ window.$ASTX2.addE2EObject(el, e2e_type);
609
+ window.$ASTX2.resetE2E();
580
610
  }
581
611
  }
582
612
  function hasAstx2() {
583
- const globalThis = window;
584
- return !!globalThis.$ASTX2;
613
+ return !!window.$ASTX2;
585
614
  }
586
615
  var loadScript = (callback) => {
587
- const globalThis = window;
588
- if (!globalThis.$ASTX2) {
616
+ if (!window.$ASTX2) {
589
617
  console.log("dynamic load");
590
618
  const script = document.createElement("script");
591
619
  script.innerHTML = `
@@ -608,27 +636,26 @@ var init = ({
608
636
  checkServerFailure = () => {
609
637
  }
610
638
  } = {}) => {
611
- const globalThis = window;
612
- globalThis.$ASTX2.init(
639
+ window.$ASTX2.init(
613
640
  () => {
614
- globalThis.$ASTX2.initE2E();
615
- globalThis.$ASTX2.checkServer(
641
+ window.$ASTX2.initE2E();
642
+ window.$ASTX2.checkServer(
616
643
  () => {
617
644
  checkServerSuccess();
618
645
  },
619
646
  () => {
620
647
  checkServerFailure();
621
- console.error(`ASTX.checkServer() onFailure: errno=${globalThis.$ASTX2.getLastError()}`);
648
+ console.error(`ASTX.checkServer() onFailure: errno=${window.$ASTX2.getLastError()}`);
622
649
  }
623
650
  );
624
651
  initSuccess();
625
652
  },
626
653
  () => {
627
654
  initFailure();
628
- if (globalThis.$ASTX2.getLastError() === 103) {
655
+ if (window.$ASTX2.getLastError() === 103) {
629
656
  console.error("AhnLab Safe Transaction \uD074\uB77C\uC774\uC5B8\uD2B8\uAC00 \uC124\uCE58\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4.");
630
657
  } else {
631
- console.error(`$ASTX2.init() onFailure: errno=${globalThis.$ASTX2.getLastError()}`);
658
+ console.error(`$ASTX2.init() onFailure: errno=${window.$ASTX2.getLastError()}`);
632
659
  }
633
660
  }
634
661
  );
@@ -643,8 +670,7 @@ var initASTX2 = ({
643
670
  checkServerFailure = () => {
644
671
  }
645
672
  } = {}) => {
646
- const globalThis = window;
647
- if (globalThis.$ASTX2) {
673
+ if (window.$ASTX2) {
648
674
  init({
649
675
  initSuccess,
650
676
  initFailure,
@@ -655,21 +681,20 @@ var initASTX2 = ({
655
681
  };
656
682
  function getE2EDataIDs(ids, onSuccess, onFailure = () => {
657
683
  }) {
658
- const globalThis = window;
659
- if (globalThis.$ASTX2) {
660
- globalThis.$ASTX2.getE2EDataIDs(
684
+ if (window.$ASTX2) {
685
+ window.$ASTX2.getE2EDataIDs(
661
686
  ids,
662
687
  async (astx_data) => {
663
688
  onSuccess(astx_data);
664
689
  },
665
690
  () => {
666
691
  onFailure();
667
- console.log(`ASTX.getE2EData() onFailure: errno=${globalThis.$ASTX2.getLastError()}`);
692
+ console.log(`ASTX.getE2EData() onFailure: errno=${window.$ASTX2.getLastError()}`);
668
693
  }
669
694
  );
670
695
  }
671
696
  }
672
697
 
673
- export { MessageEventManager, addE2EObject, base64ToBlob, base64ToFile, blobToFile, checkUserAgentDspApp, convertTextToImg, debounce, deleteCookie, fileToBase64, getApiHostNameFromEnvironment, getBrowserName, getBrowserVersion, getCdnHostNameFromEnvironment, getCookie, getCurrentBrowserName, getCurrentBrowserVersion, getCurrentOSName, getCurrentOSVersion, getDeviceModel, getDspExecutionEnvironment, getE2EDataIDs, getEnvironmentFromHostname, getExt, getFormFactorFromUserAgent, getOSName, getOSVersion, getOrCreateDeviceId, getSubdomain, hasAstx2, initASTX2, isClient, isDspApp, isFpPlannerApp, isPc, isPhone, isSalesPortal, isStorybookEnv, isTablet, isWebView, loadScript, setCookie, throttle };
698
+ export { MessageEventManager, addE2EObject, base64ToBlob, base64ToFile, blobToFile, checkUserAgentDspApp, convertTextToImg, debounce, deleteCookie, drawImageResizeCentered, fileToBase64, getApiHostNameFromEnvironment, getBrowserName, getBrowserVersion, getCdnHostNameFromEnvironment, getCookie, getCurrentBrowserName, getCurrentBrowserVersion, getCurrentOSName, getCurrentOSVersion, getDeviceModel, getDspExecutionEnvironment, getE2EDataIDs, getEnvironmentFromHostname, getExt, getFormFactorFromUserAgent, getOSName, getOSVersion, getOrCreateDeviceId, getSubdomain, hasAstx2, initASTX2, isClient, isDspApp, isFpPlannerApp, isPc, isPhone, isSalesPortal, isStorybookEnv, isTablet, isWebView, loadScript, setCookie, throttle };
674
699
  //# sourceMappingURL=index.js.map
675
700
  //# sourceMappingURL=index.js.map