sales-frontend-utils 0.0.53 → 0.0.55

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
@@ -617,6 +617,11 @@ __publicField(_MessageEventManager, "instance");
617
617
  var MessageEventManager = _MessageEventManager;
618
618
 
619
619
  // src/utils/canvas-utils.ts
620
+ var getTextWidth = (text, font, context) => {
621
+ context.font = font;
622
+ const metrics = context.measureText(text);
623
+ return metrics.width;
624
+ };
620
625
  var convertTextToImg = ({
621
626
  targetStr,
622
627
  canvasWidth,
@@ -632,8 +637,9 @@ var convertTextToImg = ({
632
637
  if (!ctx) {
633
638
  throw new Error("Canvas context\uB97C \uAC00\uC838\uC62C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
634
639
  }
640
+ const font = `${fontWeight ?? "normal"} ${fontSize ?? 75}px ${fontFamily}`;
635
641
  const defaultHeight = 150;
636
- const calculatedWidth = targetStr.length * 70;
642
+ const calculatedWidth = getTextWidth(targetStr, font, ctx);
637
643
  canvas.width = canvasWidth ?? calculatedWidth;
638
644
  canvas.height = canvasHeight ?? defaultHeight;
639
645
  if (backgroundColor) {
@@ -642,8 +648,7 @@ var convertTextToImg = ({
642
648
  }
643
649
  ctx.fillStyle = fontColor ?? "black";
644
650
  ctx.textAlign = "center";
645
- ctx.font = `${fontWeight ?? "normal"} ${fontSize ?? 75}px ${fontFamily}`;
646
- console.log("font", `${fontWeight ?? "normal"} ${fontSize ?? 75}px ${fontFamily}`);
651
+ ctx.font = font;
647
652
  ctx.textBaseline = "middle";
648
653
  ctx.fillText(targetStr, canvas.width / 2, canvas.height / 2);
649
654
  return canvas.toDataURL();
@@ -1072,6 +1077,86 @@ var getPeriodDate = (periodType) => {
1072
1077
  }
1073
1078
  };
1074
1079
 
1080
+ // src/utils/key-trigger-utils.ts
1081
+ var charFilterEng = (value) => value.replace(/[^a-zA-Z]/g, "");
1082
+ var charFilterKor = (value) => value.replace(/[^\uAC00-\uD7AF]/g, "");
1083
+ function isOverCharCount(value, count) {
1084
+ const hangulLength = charFilterKor(value).length;
1085
+ const englishLength = charFilterEng(value).length;
1086
+ if (hangulLength + englishLength >= count) {
1087
+ return true;
1088
+ }
1089
+ return false;
1090
+ }
1091
+ function checkKeys(event, keys) {
1092
+ if (keys.includes(event.key)) {
1093
+ return true;
1094
+ }
1095
+ return false;
1096
+ }
1097
+ function isEnter(event) {
1098
+ if (checkKeys(event, ["Enter"]) || event.code === "NumpadEnter") {
1099
+ return true;
1100
+ }
1101
+ return false;
1102
+ }
1103
+ function isBackspace(event) {
1104
+ if (checkKeys(event, ["Backspace"])) {
1105
+ return true;
1106
+ }
1107
+ return false;
1108
+ }
1109
+ function isArrowUp(event) {
1110
+ if (checkKeys(event, ["ArrowUp"])) {
1111
+ return true;
1112
+ }
1113
+ return false;
1114
+ }
1115
+ function isArrowDown(event) {
1116
+ if (checkKeys(event, ["ArrowDown"])) {
1117
+ return true;
1118
+ }
1119
+ return false;
1120
+ }
1121
+ function isArrowLeft(event) {
1122
+ if (checkKeys(event, ["ArrowLeft"])) {
1123
+ return true;
1124
+ }
1125
+ return false;
1126
+ }
1127
+ function isArrowRight(event) {
1128
+ if (checkKeys(event, ["ArrowRight"])) {
1129
+ return true;
1130
+ }
1131
+ return false;
1132
+ }
1133
+ function isTab(event) {
1134
+ if (checkKeys(event, ["Tab"])) {
1135
+ return true;
1136
+ }
1137
+ return false;
1138
+ }
1139
+ function isEscape(event) {
1140
+ if (checkKeys(event, ["Escape"])) {
1141
+ return true;
1142
+ }
1143
+ return false;
1144
+ }
1145
+ function isOverKorCharCount(value, count) {
1146
+ const hangulLength = charFilterKor(value).length;
1147
+ if (hangulLength > count) {
1148
+ return true;
1149
+ }
1150
+ return false;
1151
+ }
1152
+ function isOverEngCharCount(value, count) {
1153
+ const englishLength = charFilterEng(value).length;
1154
+ if (englishLength > count) {
1155
+ return true;
1156
+ }
1157
+ return false;
1158
+ }
1159
+
1075
1160
  // src/utils/ga/ga.js
1076
1161
  var ga_default = "(function (w, d, s, l, i) {\n w[l] = w[l] || [];\n w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });\n let f = d.getElementsByTagName(s)[0],\n j = d.createElement(s),\n dl = l !== 'dataLayer' ? `&l=${l}` : '';\n j.async = true;\n j.src = `https://www.googletagmanager.com/gtm.js?id=${i}${dl}`;\n f.parentNode.insertBefore(j, f);\n})(window, document, 'script', 'dataLayer', 'GTM-PPT3LJ56');\n";
1077
1162
 
@@ -1095,6 +1180,9 @@ exports.addE2EObject = addE2EObject;
1095
1180
  exports.base64ToBlob = base64ToBlob;
1096
1181
  exports.base64ToFile = base64ToFile;
1097
1182
  exports.blobToFile = blobToFile;
1183
+ exports.charFilterEng = charFilterEng;
1184
+ exports.charFilterKor = charFilterKor;
1185
+ exports.checkKeys = checkKeys;
1098
1186
  exports.checkUserAgentDspApp = checkUserAgentDspApp;
1099
1187
  exports.convertDateFormat = convertDateFormat;
1100
1188
  exports.convertDateString = convertDateString;
@@ -1132,6 +1220,7 @@ exports.getOrCreateDeviceId = getOrCreateDeviceId;
1132
1220
  exports.getPeriodDate = getPeriodDate;
1133
1221
  exports.getServicePath = getServicePath;
1134
1222
  exports.getSubdomain = getSubdomain;
1223
+ exports.getTextWidth = getTextWidth;
1135
1224
  exports.hasAstx2 = hasAstx2;
1136
1225
  exports.imageUrlToFile = imageUrlToFile;
1137
1226
  exports.imageUrlToFileFetch = imageUrlToFileFetch;
@@ -1140,19 +1229,30 @@ exports.imageUrlToFileWithXMLHttpRequest = imageUrlToFileWithXMLHttpRequest;
1140
1229
  exports.initASTX2 = initASTX2;
1141
1230
  exports.isAndroidDevice = isAndroidDevice;
1142
1231
  exports.isAndroidWebView = isAndroidWebView;
1232
+ exports.isArrowDown = isArrowDown;
1233
+ exports.isArrowLeft = isArrowLeft;
1234
+ exports.isArrowRight = isArrowRight;
1235
+ exports.isArrowUp = isArrowUp;
1236
+ exports.isBackspace = isBackspace;
1143
1237
  exports.isClient = isClient;
1144
1238
  exports.isDate = isDate;
1145
1239
  exports.isDateAfter = isDateAfter;
1146
1240
  exports.isDspApp = isDspApp;
1241
+ exports.isEnter = isEnter;
1242
+ exports.isEscape = isEscape;
1147
1243
  exports.isFpPlannerApp = isFpPlannerApp;
1148
1244
  exports.isFutureDate = isFutureDate;
1149
1245
  exports.isIosDevice = isIosDevice;
1150
1246
  exports.isIosWebView = isIosWebView;
1247
+ exports.isOverCharCount = isOverCharCount;
1248
+ exports.isOverEngCharCount = isOverEngCharCount;
1249
+ exports.isOverKorCharCount = isOverKorCharCount;
1151
1250
  exports.isPc = isPc;
1152
1251
  exports.isPhone = isPhone;
1153
1252
  exports.isProductionApp = isProductionApp;
1154
1253
  exports.isSalesPortal = isSalesPortal;
1155
1254
  exports.isStorybookEnv = isStorybookEnv;
1255
+ exports.isTab = isTab;
1156
1256
  exports.isTablet = isTablet;
1157
1257
  exports.isValidDate = isValidDate;
1158
1258
  exports.loadGaScript = loadGaScript;