funda-ui 4.7.604 → 4.7.608

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.
@@ -992,10 +992,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
992
992
  __nested_webpack_require_993__.r(__webpack_exports__);
993
993
  /* harmony export */
994
994
  __nested_webpack_require_993__.d(__webpack_exports__, {
995
- /* harmony export */"fixAndParseJSON": function fixAndParseJSON() {
996
- return (/* binding */_fixAndParseJSON
997
- );
998
- },
999
995
  /* harmony export */"isEmail": function isEmail() {
1000
996
  return (/* binding */_isEmail
1001
997
  );
@@ -1041,63 +1037,82 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1041
1037
  }
1042
1038
  /**
1043
1039
  * Fix And Parse JSON (Support for handling complex escape JSON strings)
1040
+ * @desc recursively fix top-level key/value (recursively handles when encountering top-level values that are objects/arrays)
1044
1041
  * @private
1045
1042
  */
1046
1043
  /*
1047
- - Always try JSON.parse first;
1048
- - If parsing fails, unescape \" → ";
1049
- - Then process the outermost object or array key-by-key, value-by-value;
1050
- - If a top-level value is an unquoted object or array (e.g. messages: [ {...} ]),
1051
- recursively treat that value as a new root to repair;
1052
- - For values wrapped in quotes ('...' or "..."), extract the inner text and
1053
- re-encode it using JSON.stringify (ensures internal single/double quotes
1054
- are not corrupted);
1044
+ - Still prioritize JSON.parse first;
1045
+ - After parse fails, do unescaping (\\" → ");
1046
+ - Then process the outermost layer (object or array) key by key, value by value;
1047
+ - If a top-level value is an unquoted object or array (e.g., messages: [ {...} ]), recursively treat that value as a new outermost layer for fixing;
1048
+ - For strings wrapped in quotes ('...' or "..."), only extract the outer layer and re-encode with JSON.stringify (ensuring internal single/double quotes won't be mistakenly changed);
1055
1049
  - Set MAX_DEPTH to prevent infinite recursion.
1056
1050
  */
1057
- // fixAndParseJSON - recursively repairs top-level key/value
1058
- // (when encountering outermost values that are objects/arrays, it recurses)
1059
-
1060
1051
  /*
1061
- DEMO:
1052
+ @Examples:
1062
1053
 
1063
- // ✅ Valid JSON (contains svg and single-quote content)
1054
+ // ✅ Valid JSON (contains svg and single quote content)
1064
1055
  const okJson = `{
1065
- "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> New Session",
1056
+ "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> 新建会话",
1066
1057
  "value":"new",
1067
1058
  "onClick":"method.setVal(''); method.clearData();"
1068
1059
  }`;
1069
1060
 
1070
- // Single-quote JSON
1061
+ const okJson2 = `{
1062
+ label:"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> 新建会话",
1063
+ value:"new",
1064
+ onClick:"method.setVal(''); method.clearData();"
1065
+ }`;
1066
+
1067
+ // ⚠️ Single quote JSON
1071
1068
  const badJson = "{'model':'{model}','messages':[{'role':'user','content':'{message}'}],'stream': true}";
1072
1069
 
1073
- // Escaped JSON
1074
- const badJson2 = "{\\\"label\\\":\\\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> New Session\\\",\\\"value\\\":\\\"new\\\",\\\"onClick\\\":\\\"method.setVal(''); method.clearData();\\\"}";
1070
+ // ⚠️ Escaped JSON
1071
+ const badJson2 = "{\\\"label\\\":\\\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> 新建会话\\\",\\\"value\\\":\\\"new\\\",\\\"onClick\\\":\\\"method.setVal(''); method.clearData();\\\"}";
1072
+
1073
+ const badJson3 = "{\"label\":\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> 新建会话\",\"value\":\"new\",\"onClick\":\"method.setVal(''); method.clearData();\"}";
1074
+
1075
+ const badJson4 = "[{\"label\":\"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M20.5 9a3.49 3.49 0 0 0-3.45 3h-1.1a2.49 2.49 0 0 0-4.396-1.052L8.878 9.731l3.143-4.225a2.458 2.458 0 0 0 2.98-.019L17.339 8H16v1h3V6h-1v1.243l-2.336-2.512A2.473 2.473 0 0 0 16 3.5a2.5 2.5 0 0 0-5 0 2.474 2.474 0 0 0 .343 1.243L7.947 9.308 4.955 7.947a2.404 2.404 0 0 0-.161-1.438l3.704-1.385-.44 1.371.942.333L10 4 7.172 3l-.334.943 1.01.357-3.659 1.368a2.498 2.498 0 1 0-.682 4.117l2.085 2.688-2.053 2.76a2.5 2.5 0 1 0 .87 3.864l3.484 1.587-1.055.373.334.943L10 21l-1-2.828-.943.333.435 1.354-3.608-1.645A2.471 2.471 0 0 0 5 17.5a2.5 2.5 0 0 0-.058-.527l3.053-1.405 3.476 4.48a2.498 2.498 0 1 0 4.113.075L18 17.707V19h1v-3h-3v1h1.293l-2.416 2.416a2.466 2.466 0 0 0-2.667-.047l-3.283-4.23 2.554-1.176A2.494 2.494 0 0 0 15.95 13h1.1a3.493 3.493 0 1 0 3.45-4zm-7-7A1.5 1.5 0 1 1 12 3.5 1.502 1.502 0 0 1 13.5 2zm0 18a1.5 1.5 0 1 1-1.5 1.5 1.502 1.502 0 0 1 1.5-1.5zM1 7.5a1.5 1.5 0 1 1 2.457 1.145l-.144.112A1.496 1.496 0 0 1 1 7.5zm3.32 1.703a2.507 2.507 0 0 0 .264-.326l2.752 1.251-1.124 1.512zM2.5 19A1.5 1.5 0 1 1 4 17.5 1.502 1.502 0 0 1 2.5 19zm2.037-2.941a2.518 2.518 0 0 0-.193-.234l1.885-2.532 1.136 1.464zm3.76-1.731L6.849 12.46l1.42-1.908L11.1 11.84a2.29 2.29 0 0 0-.033 1.213zM13.5 14a1.5 1.5 0 1 1 1.5-1.5 1.502 1.502 0 0 1-1.5 1.5zm7 1a2.5 2.5 0 1 1 2.5-2.5 2.502 2.502 0 0 1-2.5 2.5zm1.5-2.5a1.5 1.5 0 1 1-1.5-1.5 1.502 1.502 0 0 1 1.5 1.5z'/><path fill='none' d='M0 0h24v24H0z'/></svg> 深度思考\",\"value\":\"brief\",\"onClick\":\"if(isActive){method.executeCustomMethod('changeModel', true)}else{method.executeCustomMethod('changeModel', false)}\"},{\"label\":\"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M19 2H5c-1.103 0-2 .897-2 2v12c0 1.103.897 2 2 2h3.586L12 21.414 15.414 18H19c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zm0 14h-4.414L12 18.586 9.414 16H5V4h14v12z'/></svg> 精简回答\",\"value\":\"brief\",\"onClick\":\"if(isActive){method.setContextData({systemPrompt:'请精简回答,字数控制在150个字左右, 思考过程请简洁简短',mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}else{method.setContextData({mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}\"},{\"label\":\"<svg fill='none' width='12' height='12' viewBox='0 0 16 16'><path d='M7 0.0618896V9H15.9381C15.446 12.9463 12.0796 16 8 16C3.58172 16 0 12.4183 0 8C0 3.92038 3.05369 0.553988 7 0.0618896Z' fill='currentColor'/><path d='M9 0.0618897V7H15.9381C15.4869 3.38128 12.6187 0.513137 9 0.0618897Z' fill='currentColor'/></svg> 指标分析\",\"value\":\"lab\",\"onClick\":\"return method.executeCustomMethod('getLibList')\",\"isSelect\":true,\"dynamicOptions\":true}]";
1076
+
1075
1077
 
1076
- const badJson3 = "{\"label\":\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> New Session\",\"value\":\"new\",\"onClick\":\"method.setVal(''); method.clearData();\"}";
1078
+ // Invalid JSON with missing } or ]
1079
+ const errorJson001 = "{'model':'qwen-plus','base_url':'https://dashscope.aliyuncs.com/compatible-mode/v1/','api_key':'sk-0989fb9baab8450682af4d000f5b7cba','message':'{message}','stream':'true','chatId': '{chatId}', 'token': '{token}'";
1077
1080
 
1078
- const badJson4 = "[{\"label\":\"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M20.5 9a3.49 3.49 0 0 0-3.45 3h-1.1a2.49 2.49 0 0 0-4.396-1.052L8.878 9.731l3.143-4.225a2.458 2.458 0 0 0 2.98-.019L17.339 8H16v1h3V6h-1v1.243l-2.336-2.512A2.473 2.473 0 0 0 16 3.5a2.5 2.5 0 0 0-5 0 2.474 2.474 0 0 0 .343 1.243L7.947 9.308 4.955 7.947a2.404 2.404 0 0 0-.161-1.438l3.704-1.385-.44 1.371.942.333L10 4 7.172 3l-.334.943 1.01.357-3.659 1.368a2.498 2.498 0 1 0-.682 4.117l2.085 2.688-2.053 2.76a2.5 2.5 0 1 0 .87 3.864l3.484 1.587-1.055.373.334.943L10 21l-1-2.828-.943.333.435 1.354-3.608-1.645A2.471 2.471 0 0 0 5 17.5a2.5 2.5 0 0 0-.058-.527l3.053-1.405 3.476 4.48a2.498 2.498 0 1 0 4.113.075L18 17.707V19h1v-3h-3v1h1.293l-2.416 2.416a2.466 2.466 0 0 0-2.667-.047l-3.283-4.23 2.554-1.176A2.494 2.494 0 0 0 15.95 13h1.1a3.493 3.493 0 1 0 3.45-4zm-7-7A1.5 1.5 0 1 1 12 3.5 1.502 1.502 0 0 1 13.5 2zm0 18a1.5 1.5 0 1 1-1.5 1.5 1.502 1.502 0 0 1 1.5-1.5zM1 7.5a1.5 1.5 0 1 1 2.457 1.145l-.144.112A1.496 1.496 0 0 1 1 7.5zm3.32 1.703a2.507 2.507 0 0 0 .264-.326l2.752 1.251-1.124 1.512zM2.5 19A1.5 1.5 0 1 1 4 17.5 1.502 1.502 0 0 1 2.5 19zm2.037-2.941a2.518 2.518 0 0 0-.193-.234l1.885-2.532 1.136 1.464zm3.76-1.731L6.849 12.46l1.42-1.908L11.1 11.84a2.29 2.29 0 0 0-.033 1.213zM13.5 14a1.5 1.5 0 1 1 1.5-1.5 1.502 1.502 0 0 1-1.5 1.5zm7 1a2.5 2.5 0 1 1 2.5-2.5 2.502 2.502 0 0 1-2.5 2.5zm1.5-2.5a1.5 1.5 0 1 1-1.5-1.5 1.502 1.502 0 0 1 1.5 1.5z'/><path fill='none' d='M0 0h24v24H0z'/></svg> Deep Thought","value":"brief","onClick":"if(isActive){method.executeCustomMethod('changeModel', true)}else{method.executeCustomMethod('changeModel', false)}"},{"label":"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M19 2H5c-1.103 0-2 .897-2 2v12c0 1.103.897 2 2 2h3.586L12 21.414 15.414 18H19c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zm0 14h-4.414L12 18.586 9.414 16H5V4h14v12z'/></svg> Concise Answer","value":"brief","onClick":"if(isActive){method.setContextData({systemPrompt:'Please answer concisely, around 150 words, keep reasoning brief',mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}else{method.setContextData({mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}"},{"label":"<svg fill='none' width='12' height='12' viewBox='0 0 16 16'><path d='M7 0.0618896V9H15.9381C15.446 12.9463 12.0796 16 8 16C3.58172 16 0 12.4183 0 8C0 3.92038 3.05369 0.553988 7 0.0618896Z' fill='currentColor'/><path d='M9 0.0618897V7H15.9381C15.4869 3.38128 12.6187 0.513137 9 0.0618897Z' fill='currentColor'/></svg> Metrics Analysis","value":"lab","onClick":"return method.executeCustomMethod('getLibList')","isSelect":true,"dynamicOptions":true}]";
1081
+ const errorJson002 = "[{'model':'qwen-plus','base_url':'https://dashscope.aliyuncs.com/compatible-mode/v1/','api_key':'sk-0989fb9baab8450682af4d000f5b7cba','message':'{message}','stream':'true','chatId': '{chatId}', 'token': '{token}'}";
1079
1082
 
1083
+ // ❌ Invalid JSON with missing quotes
1084
+ const errorJson003 = "{'model':'qwen-plus','base_url':'https://dashscope.aliyuncs.com/compatible-mode/v1/','api_key':'sk-0989fb9baab8450682af4d000f5b7cba','message':'{message}','stream':'true','chatId': {chatId}', 'token': '{token}'}";
1085
+
1086
+
1087
+
1088
+ console.log('okJson =>', fixAndParseJSON(okJson)); // Can parse normally success = true
1089
+ console.log('okJson =>', fixAndParseJSON(okJson2)); // Can parse normally success = true
1090
+ console.log('badJson =>', fixAndParseJSON(badJson)); // Can parse after fixing success = true
1091
+ console.log('badJson =>', fixAndParseJSON(badJson2)); // Can parse after fixing success = true
1092
+ console.log('badJson =>', fixAndParseJSON(badJson3)); // Can parse after fixing success = true
1093
+ console.log('badJson =>', fixAndParseJSON(badJson4)); // Can parse after fixing success = true
1094
+ console.log('errorJson =>', fixAndParseJSON(errorJson001)); // {success: false, error: 'Invalid JSON format', details: 'Invalid object: mismatched braces'}
1095
+ console.log('errorJson =>', fixAndParseJSON(errorJson002)); // {success: false, error: 'Invalid JSON format', details: "Expected property name or '}' in JSON at position 2 (line 1 column 3)"}
1096
+ console.log('errorJson =>', fixAndParseJSON(errorJson003)); // {success: false, error: 'Invalid JSON format', details: 'Invalid object: mismatched braces'}
1080
1097
 
1081
- console.log('okJson =>', fixAndParseJSON(okJson)); // parses correctly
1082
- console.log('badJson =>', fixAndParseJSON(badJson)); // repaired and parsed
1083
- console.log('badJson2 =>', fixAndParseJSON(badJson2)); // repaired and parsed
1084
- console.log('badJson3 =>', fixAndParseJSON(badJson3)); // repaired and parsed
1085
- console.log('badJson4 =>', fixAndParseJSON(badJson4)); // repaired and parsed
1086
1098
  */
1087
- function _fixAndParseJSON(input) {
1099
+
1100
+ // Type definitions
1101
+
1102
+ function fixAndParseJSON(input) {
1088
1103
  var MAX_DEPTH = 6;
1089
1104
 
1090
- // 1. Fast attempt
1105
+ // 1. Quick attempt
1091
1106
  try {
1092
1107
  return {
1093
1108
  success: true,
1094
1109
  data: JSON.parse(input)
1095
1110
  };
1096
1111
  } catch (e) {
1097
- // continue to repair
1112
+ // Continue with fixing
1098
1113
  }
1099
1114
 
1100
- // 2. Simple unescape of \" (common when copied from JS literals)
1115
+ // 2. Simple unescaping of escaped \" (common case from pasted JS literals)
1101
1116
  var s = input;
1102
1117
  if (s.includes('\\"')) s = s.replace(/\\"/g, '"');
1103
1118
  s = s.trim();
@@ -1114,24 +1129,54 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1114
1129
  data: JSON.parse(s)
1115
1130
  };
1116
1131
  } catch (err) {
1132
+ var error = err instanceof Error ? err : new Error('Unknown error');
1117
1133
  return {
1118
1134
  success: false,
1119
1135
  error: 'Invalid JSON format',
1120
- details: err instanceof Error ? err.message : String(err)
1136
+ details: error.message
1121
1137
  };
1122
1138
  }
1123
1139
  }
1124
1140
 
1125
- /* ---------- Helper (recursive) functions ---------- */
1141
+ /* ---------- Helper (Recursive) Functions ---------- */
1126
1142
 
1127
1143
  function processTopObject(str, depth, MAX_DEPTH) {
1128
1144
  if (depth > MAX_DEPTH) return str;
1129
1145
  str = str.trim();
1130
- // Ensure it is wrapped in { ... }
1146
+
1147
+ // First check if braces match
1148
+ var braceCount = 0;
1149
+ var inString = false;
1150
+ var escapeNext = false;
1151
+ for (var i = 0; i < str.length; i++) {
1152
+ var ch = str[i];
1153
+ if (escapeNext) {
1154
+ escapeNext = false;
1155
+ continue;
1156
+ }
1157
+ if (ch === '\\') {
1158
+ escapeNext = true;
1159
+ continue;
1160
+ }
1161
+ if ((ch === '"' || ch === "'") && !escapeNext) {
1162
+ inString = !inString;
1163
+ continue;
1164
+ }
1165
+ if (!inString) {
1166
+ if (ch === '{') braceCount++;else if (ch === '}') braceCount--;
1167
+ }
1168
+ }
1169
+ if (braceCount !== 0) {
1170
+ throw new Error('Invalid object: mismatched braces');
1171
+ }
1172
+
1173
+ // Ensure both ends are { ... }
1131
1174
  if (!(str.startsWith('{') && str.endsWith('}'))) {
1132
- var f = str.indexOf('{');
1133
- var l = str.lastIndexOf('}');
1134
- if (f === -1 || l === -1 || l <= f) return str;
1175
+ var f = str.indexOf('{'),
1176
+ l = str.lastIndexOf('}');
1177
+ if (f === -1 || l === -1 || l <= f) {
1178
+ throw new Error('Invalid object format: missing or mismatched braces');
1179
+ }
1135
1180
  str = str.slice(f, l + 1);
1136
1181
  }
1137
1182
  var inner = str.slice(1, -1);
@@ -1156,8 +1201,8 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1156
1201
  if (depth > MAX_DEPTH) return str;
1157
1202
  str = str.trim();
1158
1203
  if (!(str.startsWith('[') && str.endsWith(']'))) {
1159
- var f = str.indexOf('[');
1160
- var l = str.lastIndexOf(']');
1204
+ var f = str.indexOf('['),
1205
+ l = str.lastIndexOf(']');
1161
1206
  if (f === -1 || l === -1 || l <= f) return str;
1162
1207
  str = str.slice(f, l + 1);
1163
1208
  }
@@ -1173,21 +1218,21 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1173
1218
  return '[' + processed.join(',') + ']';
1174
1219
  }
1175
1220
 
1176
- // If value is quoted, extract inside and JSON.stringify again (safe escaping)
1177
- // If value is unquoted object/array literal, recurse treating it as new root
1178
- // Otherwise return as is (numbers, booleans, null, or raw expressions)
1221
+ // If it's a string wrapped in quotes, extract the inner content and JSON.stringify (safe escaping)
1222
+ // If it's an object/array literal (not wrapped in quotes), recursively process (treat as new outermost layer)
1223
+ // Otherwise return the original fragment directly (numbers/true/false/null or JS expressions)
1179
1224
  function repairPossiblyQuotedValue(rawVal, depth, MAX_DEPTH) {
1180
1225
  var v = rawVal.trim();
1181
1226
  if (v === '') return v;
1182
1227
  if (v[0] === '"' || v[0] === "'") {
1183
1228
  var quote = v[0];
1184
- // Find the last unescaped matching quote
1229
+ // Find the last unescaped same quote
1185
1230
  var lastPos = -1;
1186
1231
  for (var i = v.length - 1; i >= 0; i--) {
1187
1232
  if (v[i] === quote) {
1188
- // check if escaped
1189
- var bs = 0;
1190
- var k = i - 1;
1233
+ // check escaped
1234
+ var bs = 0,
1235
+ k = i - 1;
1191
1236
  while (k >= 0 && v[k] === '\\') {
1192
1237
  bs++;
1193
1238
  k--;
@@ -1199,10 +1244,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1199
1244
  }
1200
1245
  }
1201
1246
  var inner = lastPos > 0 ? v.slice(1, lastPos) : v.slice(1);
1202
- return JSON.stringify(inner); // Generate valid JSON string (auto escape)
1247
+ return JSON.stringify(inner); // Use JSON.stringify to generate valid JSON string (automatically escape internal quotes, etc.)
1203
1248
  }
1204
1249
 
1205
- // If unquoted object/array literal -> recurse
1250
+ // If it's an object or array literal (not wrapped in quotes) -> recursively treat as new outermost layer
1206
1251
  if (v.startsWith('{')) {
1207
1252
  return processTopObject(v, depth, MAX_DEPTH);
1208
1253
  }
@@ -1210,22 +1255,22 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1210
1255
  return processTopArray(v, depth, MAX_DEPTH);
1211
1256
  }
1212
1257
 
1213
- // Other (number, boolean, null, raw expression): return as is
1258
+ // Others (numbers, boolean, null, or JS expressions): return as-is
1214
1259
  return v;
1215
1260
  }
1216
1261
 
1217
- /* --------- Utils: split by top-level commas, find colon, extract key --------- */
1262
+ /* --------- Utilities: Split by top-level commas, find top-level colon, extract key --------- */
1218
1263
 
1219
- // Split string by top-level commas (ignores commas inside strings/objects/arrays/parentheses)
1264
+ // Split by top-level commas (ignore strings, sub-objects, sub-arrays, commas inside parentheses)
1220
1265
  function splitTopLevel(str) {
1221
1266
  var parts = [];
1222
1267
  var buf = '';
1223
- var depthCurly = 0;
1224
- var depthSquare = 0;
1225
- var depthParen = 0;
1226
- var inSingle = false;
1227
- var inDouble = false;
1228
- var esc = false;
1268
+ var depthCurly = 0,
1269
+ depthSquare = 0,
1270
+ depthParen = 0;
1271
+ var inSingle = false,
1272
+ inDouble = false,
1273
+ esc = false;
1229
1274
  for (var i = 0; i < str.length; i++) {
1230
1275
  var ch = str[i];
1231
1276
  if (esc) {
@@ -1287,18 +1332,23 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1287
1332
  }
1288
1333
  buf += ch;
1289
1334
  }
1335
+
1336
+ // Check for unclosed brackets or quotes
1337
+ if (depthCurly !== 0 || depthSquare !== 0 || depthParen !== 0 || inSingle || inDouble) {
1338
+ throw new Error('Invalid JSON: unclosed brackets or quotes');
1339
+ }
1290
1340
  if (buf.trim() !== '') parts.push(buf);
1291
1341
  return parts;
1292
1342
  }
1293
1343
 
1294
- // Find the first top-level colon (ignores strings and nested structures)
1344
+ // Find the first "top-level" colon index (ignore inside strings & sub-levels)
1295
1345
  function findTopLevelColon(str) {
1296
- var inSingle = false;
1297
- var inDouble = false;
1298
- var esc = false;
1299
- var depthCurly = 0;
1300
- var depthSquare = 0;
1301
- var depthParen = 0;
1346
+ var inSingle = false,
1347
+ inDouble = false,
1348
+ esc = false;
1349
+ var depthCurly = 0,
1350
+ depthSquare = 0,
1351
+ depthParen = 0;
1302
1352
  for (var i = 0; i < str.length; i++) {
1303
1353
  var ch = str[i];
1304
1354
  if (esc) {
@@ -1350,7 +1400,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1350
1400
  return -1;
1351
1401
  }
1352
1402
 
1353
- // Extract key content (supports "key", 'key', key) returns pure string key
1403
+ // Extract key content (supports "key", 'key', key), returns pure key string
1354
1404
  function extractKeyContent(rawKey) {
1355
1405
  var r = rawKey.trim();
1356
1406
  if (r.startsWith('"') && r.endsWith('"') || r.startsWith("'") && r.endsWith("'")) {
@@ -1366,7 +1416,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1366
1416
  */
1367
1417
  function _isJSON(input) {
1368
1418
  if (typeof input === 'string' && input.length > 0) {
1369
- return _fixAndParseJSON(input).success;
1419
+ return fixAndParseJSON(input).success;
1370
1420
  } else {
1371
1421
  if (_typeof(input) === 'object' && Object.prototype.toString.call(input) === '[object Object]' && !input.length) {
1372
1422
  return true;