funda-ui 4.7.599 → 4.7.604

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.
@@ -19,40 +19,356 @@ return /******/ (() => { // webpackBootstrap
19
19
  /* harmony export */ "isJSON": () => (/* binding */ isJSON),
20
20
  /* harmony export */ "isValidNumeric": () => (/* binding */ isValidNumeric)
21
21
  /* harmony export */ });
22
- /* unused harmony exports isEmpty, isNumber, isInt, isEmail, isTel, isMobile */
22
+ /* unused harmony exports fixAndParseJSON, isEmpty, isNumber, isInt, isEmail, isTel, isMobile */
23
23
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
24
24
  /**
25
- * Check if a string is a valid number
26
- * @param str - The string to check
27
- * @returns boolean indicating if the string is a valid number
25
+ * Fix And Parse JSON (Support for handling complex escape JSON strings)
26
+ * @private
28
27
  */
29
- function isValidNumeric(str) {
30
- if (typeof str !== "string") return false; // we only process strings!
31
- if (!isNaN(Number(str)) &&
32
- // use type coercion to parse the _entirety_ of the string
33
- !isNaN(parseFloat(str)) // ensure strings of whitespace fail
34
- ) {
35
- return true;
28
+ /*
29
+ - Always try JSON.parse first;
30
+ - If parsing fails, unescape \" → ";
31
+ - Then process the outermost object or array key-by-key, value-by-value;
32
+ - If a top-level value is an unquoted object or array (e.g. messages: [ {...} ]),
33
+ recursively treat that value as a new root to repair;
34
+ - For values wrapped in quotes ('...' or "..."), extract the inner text and
35
+ re-encode it using JSON.stringify (ensures internal single/double quotes
36
+ are not corrupted);
37
+ - Set MAX_DEPTH to prevent infinite recursion.
38
+ */
39
+ // fixAndParseJSON - recursively repairs top-level key/value
40
+ // (when encountering outermost values that are objects/arrays, it recurses)
41
+
42
+ /*
43
+ DEMO:
44
+
45
+ // ✅ Valid JSON (contains svg and single-quote content)
46
+ const okJson = `{
47
+ "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> New Session",
48
+ "value":"new",
49
+ "onClick":"method.setVal(''); method.clearData();"
50
+ }`;
51
+
52
+ // ❌ Single-quote JSON
53
+ const badJson = "{'model':'{model}','messages':[{'role':'user','content':'{message}'}],'stream': true}";
54
+
55
+ // ❌ Escaped JSON
56
+ 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();\\\"}";
57
+
58
+ 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();\"}";
59
+
60
+ 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}]";
61
+
62
+
63
+ console.log('okJson =>', fixAndParseJSON(okJson)); // parses correctly
64
+ console.log('badJson =>', fixAndParseJSON(badJson)); // repaired and parsed
65
+ console.log('badJson2 =>', fixAndParseJSON(badJson2)); // repaired and parsed
66
+ console.log('badJson3 =>', fixAndParseJSON(badJson3)); // repaired and parsed
67
+ console.log('badJson4 =>', fixAndParseJSON(badJson4)); // repaired and parsed
68
+ */
69
+ function fixAndParseJSON(input) {
70
+ var MAX_DEPTH = 6;
71
+
72
+ // 1. Fast attempt
73
+ try {
74
+ return {
75
+ success: true,
76
+ data: JSON.parse(input)
77
+ };
78
+ } catch (e) {
79
+ // continue to repair
36
80
  }
37
- return false;
81
+
82
+ // 2. Simple unescape of \" (common when copied from JS literals)
83
+ var s = input;
84
+ if (s.includes('\\"')) s = s.replace(/\\"/g, '"');
85
+ s = s.trim();
86
+ try {
87
+ if (s.startsWith('{')) {
88
+ s = processTopObject(s, 0, MAX_DEPTH);
89
+ } else if (s.startsWith('[')) {
90
+ s = processTopArray(s, 0, MAX_DEPTH);
91
+ } else {
92
+ throw new Error('Input is not an object or array');
93
+ }
94
+ return {
95
+ success: true,
96
+ data: JSON.parse(s)
97
+ };
98
+ } catch (err) {
99
+ return {
100
+ success: false,
101
+ error: 'Invalid JSON format',
102
+ details: err instanceof Error ? err.message : String(err)
103
+ };
104
+ }
105
+ }
106
+
107
+ /* ---------- Helper (recursive) functions ---------- */
108
+
109
+ function processTopObject(str, depth, MAX_DEPTH) {
110
+ if (depth > MAX_DEPTH) return str;
111
+ str = str.trim();
112
+ // Ensure it is wrapped in { ... }
113
+ if (!(str.startsWith('{') && str.endsWith('}'))) {
114
+ var f = str.indexOf('{');
115
+ var l = str.lastIndexOf('}');
116
+ if (f === -1 || l === -1 || l <= f) return str;
117
+ str = str.slice(f, l + 1);
118
+ }
119
+ var inner = str.slice(1, -1);
120
+ var pairs = splitTopLevel(inner);
121
+ var repairedPairs = pairs.map(function (pair) {
122
+ if (!pair || pair.trim() === '') return '';
123
+ var idx = findTopLevelColon(pair);
124
+ if (idx === -1) {
125
+ return pair; // Non key:value fragment, keep as is (rare case)
126
+ }
127
+
128
+ var rawKey = pair.slice(0, idx).trim();
129
+ var rawVal = pair.slice(idx + 1);
130
+ var keyContent = extractKeyContent(rawKey);
131
+ var keyJson = JSON.stringify(keyContent);
132
+ var repairedValue = repairPossiblyQuotedValue(rawVal, depth + 1, MAX_DEPTH);
133
+ return keyJson + ':' + repairedValue;
134
+ });
135
+ return '{' + repairedPairs.join(',') + '}';
136
+ }
137
+ function processTopArray(str, depth, MAX_DEPTH) {
138
+ if (depth > MAX_DEPTH) return str;
139
+ str = str.trim();
140
+ if (!(str.startsWith('[') && str.endsWith(']'))) {
141
+ var f = str.indexOf('[');
142
+ var l = str.lastIndexOf(']');
143
+ if (f === -1 || l === -1 || l <= f) return str;
144
+ str = str.slice(f, l + 1);
145
+ }
146
+ var inner = str.slice(1, -1);
147
+ var elements = splitTopLevel(inner);
148
+ var processed = elements.map(function (el) {
149
+ var t = el.trim();
150
+ if (t === '') return '';
151
+ if (t.startsWith('{')) return processTopObject(t, depth + 1, MAX_DEPTH);
152
+ if (t.startsWith('[')) return processTopArray(t, depth + 1, MAX_DEPTH);
153
+ return repairPossiblyQuotedValue(t, depth + 1, MAX_DEPTH);
154
+ });
155
+ return '[' + processed.join(',') + ']';
156
+ }
157
+
158
+ // If value is quoted, extract inside and JSON.stringify again (safe escaping)
159
+ // If value is unquoted object/array literal, recurse treating it as new root
160
+ // Otherwise return as is (numbers, booleans, null, or raw expressions)
161
+ function repairPossiblyQuotedValue(rawVal, depth, MAX_DEPTH) {
162
+ var v = rawVal.trim();
163
+ if (v === '') return v;
164
+ if (v[0] === '"' || v[0] === "'") {
165
+ var quote = v[0];
166
+ // Find the last unescaped matching quote
167
+ var lastPos = -1;
168
+ for (var i = v.length - 1; i >= 0; i--) {
169
+ if (v[i] === quote) {
170
+ // check if escaped
171
+ var bs = 0;
172
+ var k = i - 1;
173
+ while (k >= 0 && v[k] === '\\') {
174
+ bs++;
175
+ k--;
176
+ }
177
+ if (bs % 2 === 0) {
178
+ lastPos = i;
179
+ break;
180
+ }
181
+ }
182
+ }
183
+ var inner = lastPos > 0 ? v.slice(1, lastPos) : v.slice(1);
184
+ return JSON.stringify(inner); // Generate valid JSON string (auto escape)
185
+ }
186
+
187
+ // If unquoted object/array literal -> recurse
188
+ if (v.startsWith('{')) {
189
+ return processTopObject(v, depth, MAX_DEPTH);
190
+ }
191
+ if (v.startsWith('[')) {
192
+ return processTopArray(v, depth, MAX_DEPTH);
193
+ }
194
+
195
+ // Other (number, boolean, null, raw expression): return as is
196
+ return v;
197
+ }
198
+
199
+ /* --------- Utils: split by top-level commas, find colon, extract key --------- */
200
+
201
+ // Split string by top-level commas (ignores commas inside strings/objects/arrays/parentheses)
202
+ function splitTopLevel(str) {
203
+ var parts = [];
204
+ var buf = '';
205
+ var depthCurly = 0;
206
+ var depthSquare = 0;
207
+ var depthParen = 0;
208
+ var inSingle = false;
209
+ var inDouble = false;
210
+ var esc = false;
211
+ for (var i = 0; i < str.length; i++) {
212
+ var ch = str[i];
213
+ if (esc) {
214
+ buf += ch;
215
+ esc = false;
216
+ continue;
217
+ }
218
+ if (ch === '\\') {
219
+ buf += ch;
220
+ esc = true;
221
+ continue;
222
+ }
223
+ if (ch === "'" && !inDouble) {
224
+ inSingle = !inSingle;
225
+ buf += ch;
226
+ continue;
227
+ }
228
+ if (ch === '"' && !inSingle) {
229
+ inDouble = !inDouble;
230
+ buf += ch;
231
+ continue;
232
+ }
233
+ if (!inSingle && !inDouble) {
234
+ if (ch === '{') {
235
+ depthCurly++;
236
+ buf += ch;
237
+ continue;
238
+ }
239
+ if (ch === '}') {
240
+ depthCurly--;
241
+ buf += ch;
242
+ continue;
243
+ }
244
+ if (ch === '[') {
245
+ depthSquare++;
246
+ buf += ch;
247
+ continue;
248
+ }
249
+ if (ch === ']') {
250
+ depthSquare--;
251
+ buf += ch;
252
+ continue;
253
+ }
254
+ if (ch === '(') {
255
+ depthParen++;
256
+ buf += ch;
257
+ continue;
258
+ }
259
+ if (ch === ')') {
260
+ depthParen--;
261
+ buf += ch;
262
+ continue;
263
+ }
264
+ if (ch === ',' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
265
+ parts.push(buf);
266
+ buf = '';
267
+ continue;
268
+ }
269
+ }
270
+ buf += ch;
271
+ }
272
+ if (buf.trim() !== '') parts.push(buf);
273
+ return parts;
274
+ }
275
+
276
+ // Find the first top-level colon (ignores strings and nested structures)
277
+ function findTopLevelColon(str) {
278
+ var inSingle = false;
279
+ var inDouble = false;
280
+ var esc = false;
281
+ var depthCurly = 0;
282
+ var depthSquare = 0;
283
+ var depthParen = 0;
284
+ for (var i = 0; i < str.length; i++) {
285
+ var ch = str[i];
286
+ if (esc) {
287
+ esc = false;
288
+ continue;
289
+ }
290
+ if (ch === '\\') {
291
+ esc = true;
292
+ continue;
293
+ }
294
+ if (ch === "'" && !inDouble) {
295
+ inSingle = !inSingle;
296
+ continue;
297
+ }
298
+ if (ch === '"' && !inSingle) {
299
+ inDouble = !inDouble;
300
+ continue;
301
+ }
302
+ if (!inSingle && !inDouble) {
303
+ if (ch === '{') {
304
+ depthCurly++;
305
+ continue;
306
+ }
307
+ if (ch === '}') {
308
+ depthCurly--;
309
+ continue;
310
+ }
311
+ if (ch === '[') {
312
+ depthSquare++;
313
+ continue;
314
+ }
315
+ if (ch === ']') {
316
+ depthSquare--;
317
+ continue;
318
+ }
319
+ if (ch === '(') {
320
+ depthParen++;
321
+ continue;
322
+ }
323
+ if (ch === ')') {
324
+ depthParen--;
325
+ continue;
326
+ }
327
+ if (ch === ':' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
328
+ return i;
329
+ }
330
+ }
331
+ }
332
+ return -1;
333
+ }
334
+
335
+ // Extract key content (supports "key", 'key', key) → returns pure string key
336
+ function extractKeyContent(rawKey) {
337
+ var r = rawKey.trim();
338
+ if (r.startsWith('"') && r.endsWith('"') || r.startsWith("'") && r.endsWith("'")) {
339
+ var inner = r.slice(1, -1).replace(/\\"/g, '"').replace(/\\'/g, "'");
340
+ return inner;
341
+ }
342
+ return r;
38
343
  }
39
344
 
40
345
  /**
41
346
  * Determine whether it is in JSON format
42
- * @param str - The value to check
43
- * @returns boolean indicating if the value is valid JSON
347
+ * @private
44
348
  */
45
- function isJSON(str) {
46
- if (typeof str === 'string' && str.length > 0) {
47
- if (str.replace(/\"\"/g, '').replace(/\,/g, '') === '[{}]') {
48
- return false;
49
- }
50
- if (/^[\],:{}\s]*$/.test(str.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
349
+ function isJSON(input) {
350
+ if (typeof input === 'string' && input.length > 0) {
351
+ return fixAndParseJSON(input).success;
352
+ } else {
353
+ if (_typeof(input) === 'object' && Object.prototype.toString.call(input) === '[object Object]' && !input.length) {
51
354
  return true;
355
+ } else {
356
+ return false;
52
357
  }
53
- return false;
54
358
  }
55
- if (_typeof(str) === 'object' && Object.prototype.toString.call(str) === '[object Object]' && !str.length) {
359
+ }
360
+
361
+ /**
362
+ * Check if a string is a valid number
363
+ * @param str - The string to check
364
+ * @returns boolean indicating if the string is a valid number
365
+ */
366
+ function isValidNumeric(str) {
367
+ if (typeof str !== "string") return false; // we only process strings!
368
+ if (!isNaN(Number(str)) &&
369
+ // use type coercion to parse the _entirety_ of the string
370
+ !isNaN(parseFloat(str)) // ensure strings of whitespace fail
371
+ ) {
56
372
  return true;
57
373
  }
58
374
  return false;
@@ -1,15 +1,25 @@
1
+ /**
2
+ * Fix And Parse JSON (Support for handling complex escape JSON strings)
3
+ * @private
4
+ */
5
+ interface ParseResult {
6
+ success: boolean;
7
+ data?: any;
8
+ error?: string;
9
+ details?: string;
10
+ }
11
+ export declare function fixAndParseJSON(input: string): ParseResult;
12
+ /**
13
+ * Determine whether it is in JSON format
14
+ * @private
15
+ */
16
+ declare function isJSON(input: any): boolean;
1
17
  /**
2
18
  * Check if a string is a valid number
3
19
  * @param str - The string to check
4
20
  * @returns boolean indicating if the string is a valid number
5
21
  */
6
22
  declare function isValidNumeric(str: unknown): boolean;
7
- /**
8
- * Determine whether it is in JSON format
9
- * @param str - The value to check
10
- * @returns boolean indicating if the value is valid JSON
11
- */
12
- declare function isJSON(str: unknown): boolean;
13
23
  /**
14
24
  * Check if input is empty
15
25
  * @param input - The input to check (string or array of strings)