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.
package/Utils/anim.js CHANGED
@@ -217,40 +217,356 @@ function setDefaultOptions(props, options) {
217
217
  /* harmony export */ "isJSON": () => (/* binding */ isJSON),
218
218
  /* harmony export */ "isValidNumeric": () => (/* binding */ isValidNumeric)
219
219
  /* harmony export */ });
220
- /* unused harmony exports isEmpty, isNumber, isInt, isEmail, isTel, isMobile */
220
+ /* unused harmony exports fixAndParseJSON, isEmpty, isNumber, isInt, isEmail, isTel, isMobile */
221
221
  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); }
222
222
  /**
223
- * Check if a string is a valid number
224
- * @param str - The string to check
225
- * @returns boolean indicating if the string is a valid number
223
+ * Fix And Parse JSON (Support for handling complex escape JSON strings)
224
+ * @private
226
225
  */
227
- function isValidNumeric(str) {
228
- if (typeof str !== "string") return false; // we only process strings!
229
- if (!isNaN(Number(str)) &&
230
- // use type coercion to parse the _entirety_ of the string
231
- !isNaN(parseFloat(str)) // ensure strings of whitespace fail
232
- ) {
233
- return true;
226
+ /*
227
+ - Always try JSON.parse first;
228
+ - If parsing fails, unescape \" → ";
229
+ - Then process the outermost object or array key-by-key, value-by-value;
230
+ - If a top-level value is an unquoted object or array (e.g. messages: [ {...} ]),
231
+ recursively treat that value as a new root to repair;
232
+ - For values wrapped in quotes ('...' or "..."), extract the inner text and
233
+ re-encode it using JSON.stringify (ensures internal single/double quotes
234
+ are not corrupted);
235
+ - Set MAX_DEPTH to prevent infinite recursion.
236
+ */
237
+ // fixAndParseJSON - recursively repairs top-level key/value
238
+ // (when encountering outermost values that are objects/arrays, it recurses)
239
+
240
+ /*
241
+ DEMO:
242
+
243
+ // ✅ Valid JSON (contains svg and single-quote content)
244
+ const okJson = `{
245
+ "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> New Session",
246
+ "value":"new",
247
+ "onClick":"method.setVal(''); method.clearData();"
248
+ }`;
249
+
250
+ // ❌ Single-quote JSON
251
+ const badJson = "{'model':'{model}','messages':[{'role':'user','content':'{message}'}],'stream': true}";
252
+
253
+ // ❌ Escaped JSON
254
+ 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();\\\"}";
255
+
256
+ 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();\"}";
257
+
258
+ 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}]";
259
+
260
+
261
+ console.log('okJson =>', fixAndParseJSON(okJson)); // parses correctly
262
+ console.log('badJson =>', fixAndParseJSON(badJson)); // repaired and parsed
263
+ console.log('badJson2 =>', fixAndParseJSON(badJson2)); // repaired and parsed
264
+ console.log('badJson3 =>', fixAndParseJSON(badJson3)); // repaired and parsed
265
+ console.log('badJson4 =>', fixAndParseJSON(badJson4)); // repaired and parsed
266
+ */
267
+ function fixAndParseJSON(input) {
268
+ var MAX_DEPTH = 6;
269
+
270
+ // 1. Fast attempt
271
+ try {
272
+ return {
273
+ success: true,
274
+ data: JSON.parse(input)
275
+ };
276
+ } catch (e) {
277
+ // continue to repair
234
278
  }
235
- return false;
279
+
280
+ // 2. Simple unescape of \" (common when copied from JS literals)
281
+ var s = input;
282
+ if (s.includes('\\"')) s = s.replace(/\\"/g, '"');
283
+ s = s.trim();
284
+ try {
285
+ if (s.startsWith('{')) {
286
+ s = processTopObject(s, 0, MAX_DEPTH);
287
+ } else if (s.startsWith('[')) {
288
+ s = processTopArray(s, 0, MAX_DEPTH);
289
+ } else {
290
+ throw new Error('Input is not an object or array');
291
+ }
292
+ return {
293
+ success: true,
294
+ data: JSON.parse(s)
295
+ };
296
+ } catch (err) {
297
+ return {
298
+ success: false,
299
+ error: 'Invalid JSON format',
300
+ details: err instanceof Error ? err.message : String(err)
301
+ };
302
+ }
303
+ }
304
+
305
+ /* ---------- Helper (recursive) functions ---------- */
306
+
307
+ function processTopObject(str, depth, MAX_DEPTH) {
308
+ if (depth > MAX_DEPTH) return str;
309
+ str = str.trim();
310
+ // Ensure it is wrapped in { ... }
311
+ if (!(str.startsWith('{') && str.endsWith('}'))) {
312
+ var f = str.indexOf('{');
313
+ var l = str.lastIndexOf('}');
314
+ if (f === -1 || l === -1 || l <= f) return str;
315
+ str = str.slice(f, l + 1);
316
+ }
317
+ var inner = str.slice(1, -1);
318
+ var pairs = splitTopLevel(inner);
319
+ var repairedPairs = pairs.map(function (pair) {
320
+ if (!pair || pair.trim() === '') return '';
321
+ var idx = findTopLevelColon(pair);
322
+ if (idx === -1) {
323
+ return pair; // Non key:value fragment, keep as is (rare case)
324
+ }
325
+
326
+ var rawKey = pair.slice(0, idx).trim();
327
+ var rawVal = pair.slice(idx + 1);
328
+ var keyContent = extractKeyContent(rawKey);
329
+ var keyJson = JSON.stringify(keyContent);
330
+ var repairedValue = repairPossiblyQuotedValue(rawVal, depth + 1, MAX_DEPTH);
331
+ return keyJson + ':' + repairedValue;
332
+ });
333
+ return '{' + repairedPairs.join(',') + '}';
334
+ }
335
+ function processTopArray(str, depth, MAX_DEPTH) {
336
+ if (depth > MAX_DEPTH) return str;
337
+ str = str.trim();
338
+ if (!(str.startsWith('[') && str.endsWith(']'))) {
339
+ var f = str.indexOf('[');
340
+ var l = str.lastIndexOf(']');
341
+ if (f === -1 || l === -1 || l <= f) return str;
342
+ str = str.slice(f, l + 1);
343
+ }
344
+ var inner = str.slice(1, -1);
345
+ var elements = splitTopLevel(inner);
346
+ var processed = elements.map(function (el) {
347
+ var t = el.trim();
348
+ if (t === '') return '';
349
+ if (t.startsWith('{')) return processTopObject(t, depth + 1, MAX_DEPTH);
350
+ if (t.startsWith('[')) return processTopArray(t, depth + 1, MAX_DEPTH);
351
+ return repairPossiblyQuotedValue(t, depth + 1, MAX_DEPTH);
352
+ });
353
+ return '[' + processed.join(',') + ']';
354
+ }
355
+
356
+ // If value is quoted, extract inside and JSON.stringify again (safe escaping)
357
+ // If value is unquoted object/array literal, recurse treating it as new root
358
+ // Otherwise return as is (numbers, booleans, null, or raw expressions)
359
+ function repairPossiblyQuotedValue(rawVal, depth, MAX_DEPTH) {
360
+ var v = rawVal.trim();
361
+ if (v === '') return v;
362
+ if (v[0] === '"' || v[0] === "'") {
363
+ var quote = v[0];
364
+ // Find the last unescaped matching quote
365
+ var lastPos = -1;
366
+ for (var i = v.length - 1; i >= 0; i--) {
367
+ if (v[i] === quote) {
368
+ // check if escaped
369
+ var bs = 0;
370
+ var k = i - 1;
371
+ while (k >= 0 && v[k] === '\\') {
372
+ bs++;
373
+ k--;
374
+ }
375
+ if (bs % 2 === 0) {
376
+ lastPos = i;
377
+ break;
378
+ }
379
+ }
380
+ }
381
+ var inner = lastPos > 0 ? v.slice(1, lastPos) : v.slice(1);
382
+ return JSON.stringify(inner); // Generate valid JSON string (auto escape)
383
+ }
384
+
385
+ // If unquoted object/array literal -> recurse
386
+ if (v.startsWith('{')) {
387
+ return processTopObject(v, depth, MAX_DEPTH);
388
+ }
389
+ if (v.startsWith('[')) {
390
+ return processTopArray(v, depth, MAX_DEPTH);
391
+ }
392
+
393
+ // Other (number, boolean, null, raw expression): return as is
394
+ return v;
395
+ }
396
+
397
+ /* --------- Utils: split by top-level commas, find colon, extract key --------- */
398
+
399
+ // Split string by top-level commas (ignores commas inside strings/objects/arrays/parentheses)
400
+ function splitTopLevel(str) {
401
+ var parts = [];
402
+ var buf = '';
403
+ var depthCurly = 0;
404
+ var depthSquare = 0;
405
+ var depthParen = 0;
406
+ var inSingle = false;
407
+ var inDouble = false;
408
+ var esc = false;
409
+ for (var i = 0; i < str.length; i++) {
410
+ var ch = str[i];
411
+ if (esc) {
412
+ buf += ch;
413
+ esc = false;
414
+ continue;
415
+ }
416
+ if (ch === '\\') {
417
+ buf += ch;
418
+ esc = true;
419
+ continue;
420
+ }
421
+ if (ch === "'" && !inDouble) {
422
+ inSingle = !inSingle;
423
+ buf += ch;
424
+ continue;
425
+ }
426
+ if (ch === '"' && !inSingle) {
427
+ inDouble = !inDouble;
428
+ buf += ch;
429
+ continue;
430
+ }
431
+ if (!inSingle && !inDouble) {
432
+ if (ch === '{') {
433
+ depthCurly++;
434
+ buf += ch;
435
+ continue;
436
+ }
437
+ if (ch === '}') {
438
+ depthCurly--;
439
+ buf += ch;
440
+ continue;
441
+ }
442
+ if (ch === '[') {
443
+ depthSquare++;
444
+ buf += ch;
445
+ continue;
446
+ }
447
+ if (ch === ']') {
448
+ depthSquare--;
449
+ buf += ch;
450
+ continue;
451
+ }
452
+ if (ch === '(') {
453
+ depthParen++;
454
+ buf += ch;
455
+ continue;
456
+ }
457
+ if (ch === ')') {
458
+ depthParen--;
459
+ buf += ch;
460
+ continue;
461
+ }
462
+ if (ch === ',' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
463
+ parts.push(buf);
464
+ buf = '';
465
+ continue;
466
+ }
467
+ }
468
+ buf += ch;
469
+ }
470
+ if (buf.trim() !== '') parts.push(buf);
471
+ return parts;
472
+ }
473
+
474
+ // Find the first top-level colon (ignores strings and nested structures)
475
+ function findTopLevelColon(str) {
476
+ var inSingle = false;
477
+ var inDouble = false;
478
+ var esc = false;
479
+ var depthCurly = 0;
480
+ var depthSquare = 0;
481
+ var depthParen = 0;
482
+ for (var i = 0; i < str.length; i++) {
483
+ var ch = str[i];
484
+ if (esc) {
485
+ esc = false;
486
+ continue;
487
+ }
488
+ if (ch === '\\') {
489
+ esc = true;
490
+ continue;
491
+ }
492
+ if (ch === "'" && !inDouble) {
493
+ inSingle = !inSingle;
494
+ continue;
495
+ }
496
+ if (ch === '"' && !inSingle) {
497
+ inDouble = !inDouble;
498
+ continue;
499
+ }
500
+ if (!inSingle && !inDouble) {
501
+ if (ch === '{') {
502
+ depthCurly++;
503
+ continue;
504
+ }
505
+ if (ch === '}') {
506
+ depthCurly--;
507
+ continue;
508
+ }
509
+ if (ch === '[') {
510
+ depthSquare++;
511
+ continue;
512
+ }
513
+ if (ch === ']') {
514
+ depthSquare--;
515
+ continue;
516
+ }
517
+ if (ch === '(') {
518
+ depthParen++;
519
+ continue;
520
+ }
521
+ if (ch === ')') {
522
+ depthParen--;
523
+ continue;
524
+ }
525
+ if (ch === ':' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
526
+ return i;
527
+ }
528
+ }
529
+ }
530
+ return -1;
531
+ }
532
+
533
+ // Extract key content (supports "key", 'key', key) → returns pure string key
534
+ function extractKeyContent(rawKey) {
535
+ var r = rawKey.trim();
536
+ if (r.startsWith('"') && r.endsWith('"') || r.startsWith("'") && r.endsWith("'")) {
537
+ var inner = r.slice(1, -1).replace(/\\"/g, '"').replace(/\\'/g, "'");
538
+ return inner;
539
+ }
540
+ return r;
236
541
  }
237
542
 
238
543
  /**
239
544
  * Determine whether it is in JSON format
240
- * @param str - The value to check
241
- * @returns boolean indicating if the value is valid JSON
545
+ * @private
242
546
  */
243
- function isJSON(str) {
244
- if (typeof str === 'string' && str.length > 0) {
245
- if (str.replace(/\"\"/g, '').replace(/\,/g, '') === '[{}]') {
246
- return false;
247
- }
248
- if (/^[\],:{}\s]*$/.test(str.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
547
+ function isJSON(input) {
548
+ if (typeof input === 'string' && input.length > 0) {
549
+ return fixAndParseJSON(input).success;
550
+ } else {
551
+ if (_typeof(input) === 'object' && Object.prototype.toString.call(input) === '[object Object]' && !input.length) {
249
552
  return true;
553
+ } else {
554
+ return false;
250
555
  }
251
- return false;
252
556
  }
253
- if (_typeof(str) === 'object' && Object.prototype.toString.call(str) === '[object Object]' && !str.length) {
557
+ }
558
+
559
+ /**
560
+ * Check if a string is a valid number
561
+ * @param str - The string to check
562
+ * @returns boolean indicating if the string is a valid number
563
+ */
564
+ function isValidNumeric(str) {
565
+ if (typeof str !== "string") return false; // we only process strings!
566
+ if (!isNaN(Number(str)) &&
567
+ // use type coercion to parse the _entirety_ of the string
568
+ !isNaN(parseFloat(str)) // ensure strings of whitespace fail
569
+ ) {
254
570
  return true;
255
571
  }
256
572
  return false;