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.
@@ -1038,10 +1038,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1038
1038
  __nested_webpack_require_993__.r(__webpack_exports__);
1039
1039
  /* harmony export */
1040
1040
  __nested_webpack_require_993__.d(__webpack_exports__, {
1041
- /* harmony export */"fixAndParseJSON": function fixAndParseJSON() {
1042
- return (/* binding */_fixAndParseJSON
1043
- );
1044
- },
1045
1041
  /* harmony export */"isEmail": function isEmail() {
1046
1042
  return (/* binding */_isEmail
1047
1043
  );
@@ -1087,63 +1083,82 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1087
1083
  }
1088
1084
  /**
1089
1085
  * Fix And Parse JSON (Support for handling complex escape JSON strings)
1086
+ * @desc recursively fix top-level key/value (recursively handles when encountering top-level values that are objects/arrays)
1090
1087
  * @private
1091
1088
  */
1092
1089
  /*
1093
- - Always try JSON.parse first;
1094
- - If parsing fails, unescape \" → ";
1095
- - Then process the outermost object or array key-by-key, value-by-value;
1096
- - If a top-level value is an unquoted object or array (e.g. messages: [ {...} ]),
1097
- recursively treat that value as a new root to repair;
1098
- - For values wrapped in quotes ('...' or "..."), extract the inner text and
1099
- re-encode it using JSON.stringify (ensures internal single/double quotes
1100
- are not corrupted);
1090
+ - Still prioritize JSON.parse first;
1091
+ - After parse fails, do unescaping (\\" → ");
1092
+ - Then process the outermost layer (object or array) key by key, value by value;
1093
+ - 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;
1094
+ - 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);
1101
1095
  - Set MAX_DEPTH to prevent infinite recursion.
1102
1096
  */
1103
- // fixAndParseJSON - recursively repairs top-level key/value
1104
- // (when encountering outermost values that are objects/arrays, it recurses)
1105
-
1106
1097
  /*
1107
- DEMO:
1098
+ @Examples:
1108
1099
 
1109
- // ✅ Valid JSON (contains svg and single-quote content)
1100
+ // ✅ Valid JSON (contains svg and single quote content)
1110
1101
  const okJson = `{
1111
- "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> New Session",
1102
+ "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> 新建会话",
1112
1103
  "value":"new",
1113
1104
  "onClick":"method.setVal(''); method.clearData();"
1114
1105
  }`;
1115
1106
 
1116
- // Single-quote JSON
1107
+ const okJson2 = `{
1108
+ label:"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> 新建会话",
1109
+ value:"new",
1110
+ onClick:"method.setVal(''); method.clearData();"
1111
+ }`;
1112
+
1113
+ // ⚠️ Single quote JSON
1117
1114
  const badJson = "{'model':'{model}','messages':[{'role':'user','content':'{message}'}],'stream': true}";
1118
1115
 
1119
- // Escaped JSON
1120
- 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();\\\"}";
1116
+ // ⚠️ Escaped JSON
1117
+ 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();\\\"}";
1118
+
1119
+ 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();\"}";
1120
+
1121
+ 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}]";
1122
+
1121
1123
 
1122
- 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();\"}";
1124
+ // Invalid JSON with missing } or ]
1125
+ 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}'";
1123
1126
 
1124
- 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}]";
1127
+ 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}'}";
1125
1128
 
1129
+ // ❌ Invalid JSON with missing quotes
1130
+ 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}'}";
1131
+
1132
+
1133
+
1134
+ console.log('okJson =>', fixAndParseJSON(okJson)); // Can parse normally success = true
1135
+ console.log('okJson =>', fixAndParseJSON(okJson2)); // Can parse normally success = true
1136
+ console.log('badJson =>', fixAndParseJSON(badJson)); // Can parse after fixing success = true
1137
+ console.log('badJson =>', fixAndParseJSON(badJson2)); // Can parse after fixing success = true
1138
+ console.log('badJson =>', fixAndParseJSON(badJson3)); // Can parse after fixing success = true
1139
+ console.log('badJson =>', fixAndParseJSON(badJson4)); // Can parse after fixing success = true
1140
+ console.log('errorJson =>', fixAndParseJSON(errorJson001)); // {success: false, error: 'Invalid JSON format', details: 'Invalid object: mismatched braces'}
1141
+ 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)"}
1142
+ console.log('errorJson =>', fixAndParseJSON(errorJson003)); // {success: false, error: 'Invalid JSON format', details: 'Invalid object: mismatched braces'}
1126
1143
 
1127
- console.log('okJson =>', fixAndParseJSON(okJson)); // parses correctly
1128
- console.log('badJson =>', fixAndParseJSON(badJson)); // repaired and parsed
1129
- console.log('badJson2 =>', fixAndParseJSON(badJson2)); // repaired and parsed
1130
- console.log('badJson3 =>', fixAndParseJSON(badJson3)); // repaired and parsed
1131
- console.log('badJson4 =>', fixAndParseJSON(badJson4)); // repaired and parsed
1132
1144
  */
1133
- function _fixAndParseJSON(input) {
1145
+
1146
+ // Type definitions
1147
+
1148
+ function fixAndParseJSON(input) {
1134
1149
  var MAX_DEPTH = 6;
1135
1150
 
1136
- // 1. Fast attempt
1151
+ // 1. Quick attempt
1137
1152
  try {
1138
1153
  return {
1139
1154
  success: true,
1140
1155
  data: JSON.parse(input)
1141
1156
  };
1142
1157
  } catch (e) {
1143
- // continue to repair
1158
+ // Continue with fixing
1144
1159
  }
1145
1160
 
1146
- // 2. Simple unescape of \" (common when copied from JS literals)
1161
+ // 2. Simple unescaping of escaped \" (common case from pasted JS literals)
1147
1162
  var s = input;
1148
1163
  if (s.includes('\\"')) s = s.replace(/\\"/g, '"');
1149
1164
  s = s.trim();
@@ -1160,24 +1175,54 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1160
1175
  data: JSON.parse(s)
1161
1176
  };
1162
1177
  } catch (err) {
1178
+ var error = err instanceof Error ? err : new Error('Unknown error');
1163
1179
  return {
1164
1180
  success: false,
1165
1181
  error: 'Invalid JSON format',
1166
- details: err instanceof Error ? err.message : String(err)
1182
+ details: error.message
1167
1183
  };
1168
1184
  }
1169
1185
  }
1170
1186
 
1171
- /* ---------- Helper (recursive) functions ---------- */
1187
+ /* ---------- Helper (Recursive) Functions ---------- */
1172
1188
 
1173
1189
  function processTopObject(str, depth, MAX_DEPTH) {
1174
1190
  if (depth > MAX_DEPTH) return str;
1175
1191
  str = str.trim();
1176
- // Ensure it is wrapped in { ... }
1192
+
1193
+ // First check if braces match
1194
+ var braceCount = 0;
1195
+ var inString = false;
1196
+ var escapeNext = false;
1197
+ for (var i = 0; i < str.length; i++) {
1198
+ var ch = str[i];
1199
+ if (escapeNext) {
1200
+ escapeNext = false;
1201
+ continue;
1202
+ }
1203
+ if (ch === '\\') {
1204
+ escapeNext = true;
1205
+ continue;
1206
+ }
1207
+ if ((ch === '"' || ch === "'") && !escapeNext) {
1208
+ inString = !inString;
1209
+ continue;
1210
+ }
1211
+ if (!inString) {
1212
+ if (ch === '{') braceCount++;else if (ch === '}') braceCount--;
1213
+ }
1214
+ }
1215
+ if (braceCount !== 0) {
1216
+ throw new Error('Invalid object: mismatched braces');
1217
+ }
1218
+
1219
+ // Ensure both ends are { ... }
1177
1220
  if (!(str.startsWith('{') && str.endsWith('}'))) {
1178
- var f = str.indexOf('{');
1179
- var l = str.lastIndexOf('}');
1180
- if (f === -1 || l === -1 || l <= f) return str;
1221
+ var f = str.indexOf('{'),
1222
+ l = str.lastIndexOf('}');
1223
+ if (f === -1 || l === -1 || l <= f) {
1224
+ throw new Error('Invalid object format: missing or mismatched braces');
1225
+ }
1181
1226
  str = str.slice(f, l + 1);
1182
1227
  }
1183
1228
  var inner = str.slice(1, -1);
@@ -1202,8 +1247,8 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1202
1247
  if (depth > MAX_DEPTH) return str;
1203
1248
  str = str.trim();
1204
1249
  if (!(str.startsWith('[') && str.endsWith(']'))) {
1205
- var f = str.indexOf('[');
1206
- var l = str.lastIndexOf(']');
1250
+ var f = str.indexOf('['),
1251
+ l = str.lastIndexOf(']');
1207
1252
  if (f === -1 || l === -1 || l <= f) return str;
1208
1253
  str = str.slice(f, l + 1);
1209
1254
  }
@@ -1219,21 +1264,21 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1219
1264
  return '[' + processed.join(',') + ']';
1220
1265
  }
1221
1266
 
1222
- // If value is quoted, extract inside and JSON.stringify again (safe escaping)
1223
- // If value is unquoted object/array literal, recurse treating it as new root
1224
- // Otherwise return as is (numbers, booleans, null, or raw expressions)
1267
+ // If it's a string wrapped in quotes, extract the inner content and JSON.stringify (safe escaping)
1268
+ // If it's an object/array literal (not wrapped in quotes), recursively process (treat as new outermost layer)
1269
+ // Otherwise return the original fragment directly (numbers/true/false/null or JS expressions)
1225
1270
  function repairPossiblyQuotedValue(rawVal, depth, MAX_DEPTH) {
1226
1271
  var v = rawVal.trim();
1227
1272
  if (v === '') return v;
1228
1273
  if (v[0] === '"' || v[0] === "'") {
1229
1274
  var quote = v[0];
1230
- // Find the last unescaped matching quote
1275
+ // Find the last unescaped same quote
1231
1276
  var lastPos = -1;
1232
1277
  for (var i = v.length - 1; i >= 0; i--) {
1233
1278
  if (v[i] === quote) {
1234
- // check if escaped
1235
- var bs = 0;
1236
- var k = i - 1;
1279
+ // check escaped
1280
+ var bs = 0,
1281
+ k = i - 1;
1237
1282
  while (k >= 0 && v[k] === '\\') {
1238
1283
  bs++;
1239
1284
  k--;
@@ -1245,10 +1290,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1245
1290
  }
1246
1291
  }
1247
1292
  var inner = lastPos > 0 ? v.slice(1, lastPos) : v.slice(1);
1248
- return JSON.stringify(inner); // Generate valid JSON string (auto escape)
1293
+ return JSON.stringify(inner); // Use JSON.stringify to generate valid JSON string (automatically escape internal quotes, etc.)
1249
1294
  }
1250
1295
 
1251
- // If unquoted object/array literal -> recurse
1296
+ // If it's an object or array literal (not wrapped in quotes) -> recursively treat as new outermost layer
1252
1297
  if (v.startsWith('{')) {
1253
1298
  return processTopObject(v, depth, MAX_DEPTH);
1254
1299
  }
@@ -1256,22 +1301,22 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1256
1301
  return processTopArray(v, depth, MAX_DEPTH);
1257
1302
  }
1258
1303
 
1259
- // Other (number, boolean, null, raw expression): return as is
1304
+ // Others (numbers, boolean, null, or JS expressions): return as-is
1260
1305
  return v;
1261
1306
  }
1262
1307
 
1263
- /* --------- Utils: split by top-level commas, find colon, extract key --------- */
1308
+ /* --------- Utilities: Split by top-level commas, find top-level colon, extract key --------- */
1264
1309
 
1265
- // Split string by top-level commas (ignores commas inside strings/objects/arrays/parentheses)
1310
+ // Split by top-level commas (ignore strings, sub-objects, sub-arrays, commas inside parentheses)
1266
1311
  function splitTopLevel(str) {
1267
1312
  var parts = [];
1268
1313
  var buf = '';
1269
- var depthCurly = 0;
1270
- var depthSquare = 0;
1271
- var depthParen = 0;
1272
- var inSingle = false;
1273
- var inDouble = false;
1274
- var esc = false;
1314
+ var depthCurly = 0,
1315
+ depthSquare = 0,
1316
+ depthParen = 0;
1317
+ var inSingle = false,
1318
+ inDouble = false,
1319
+ esc = false;
1275
1320
  for (var i = 0; i < str.length; i++) {
1276
1321
  var ch = str[i];
1277
1322
  if (esc) {
@@ -1333,18 +1378,23 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1333
1378
  }
1334
1379
  buf += ch;
1335
1380
  }
1381
+
1382
+ // Check for unclosed brackets or quotes
1383
+ if (depthCurly !== 0 || depthSquare !== 0 || depthParen !== 0 || inSingle || inDouble) {
1384
+ throw new Error('Invalid JSON: unclosed brackets or quotes');
1385
+ }
1336
1386
  if (buf.trim() !== '') parts.push(buf);
1337
1387
  return parts;
1338
1388
  }
1339
1389
 
1340
- // Find the first top-level colon (ignores strings and nested structures)
1390
+ // Find the first "top-level" colon index (ignore inside strings & sub-levels)
1341
1391
  function findTopLevelColon(str) {
1342
- var inSingle = false;
1343
- var inDouble = false;
1344
- var esc = false;
1345
- var depthCurly = 0;
1346
- var depthSquare = 0;
1347
- var depthParen = 0;
1392
+ var inSingle = false,
1393
+ inDouble = false,
1394
+ esc = false;
1395
+ var depthCurly = 0,
1396
+ depthSquare = 0,
1397
+ depthParen = 0;
1348
1398
  for (var i = 0; i < str.length; i++) {
1349
1399
  var ch = str[i];
1350
1400
  if (esc) {
@@ -1396,7 +1446,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1396
1446
  return -1;
1397
1447
  }
1398
1448
 
1399
- // Extract key content (supports "key", 'key', key) returns pure string key
1449
+ // Extract key content (supports "key", 'key', key), returns pure key string
1400
1450
  function extractKeyContent(rawKey) {
1401
1451
  var r = rawKey.trim();
1402
1452
  if (r.startsWith('"') && r.endsWith('"') || r.startsWith("'") && r.endsWith("'")) {
@@ -1412,7 +1462,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1412
1462
  */
1413
1463
  function _isJSON(input) {
1414
1464
  if (typeof input === 'string' && input.length > 0) {
1415
- return _fixAndParseJSON(input).success;
1465
+ return fixAndParseJSON(input).success;
1416
1466
  } else {
1417
1467
  if (_typeof(input) === 'object' && Object.prototype.toString.call(input) === '[object Object]' && !input.length) {
1418
1468
  return true;