tw-framework 1.0.3 → 1.0.5

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.
@@ -1036,10 +1036,10 @@ var CacheManager = class {
1036
1036
  get(key) {
1037
1037
  const memValue = this.memoryCache.get(key);
1038
1038
  if (memValue !== void 0) return memValue;
1039
- const sessionValue = this.sessionCache.get(key);
1040
- if (sessionValue !== void 0) {
1041
- this.memoryCache.set(key, sessionValue);
1042
- return sessionValue;
1039
+ const sessionValue2 = this.sessionCache.get(key);
1040
+ if (sessionValue2 !== void 0) {
1041
+ this.memoryCache.set(key, sessionValue2);
1042
+ return sessionValue2;
1043
1043
  }
1044
1044
  const persistentValue = this.persistentCache.get(key);
1045
1045
  if (persistentValue !== void 0) {
@@ -1330,6 +1330,9 @@ function getClipboardManager() {
1330
1330
  async function copyToClipboard(text, options) {
1331
1331
  return getClipboardManager().copyText(text, options);
1332
1332
  }
1333
+ async function copyText(text, options) {
1334
+ return getClipboardManager().copyText(text, options);
1335
+ }
1333
1336
  async function copyHTML(html, plainText, options) {
1334
1337
  return getClipboardManager().copyHTML(html, plainText, options);
1335
1338
  }
@@ -1340,6 +1343,162 @@ async function pasteFromClipboard() {
1340
1343
  return getClipboardManager().readText();
1341
1344
  }
1342
1345
 
1346
+ // ../../packages/runtime/tw/performance/metrics.ts
1347
+ var LCP_THRESHOLDS = { good: 2500, poor: 4e3 };
1348
+ var FID_THRESHOLDS = { good: 100, poor: 300 };
1349
+ var CLS_THRESHOLDS = { good: 0.1, poor: 0.25 };
1350
+ var INP_THRESHOLDS = { good: 200, poor: 500 };
1351
+ var TTFB_THRESHOLDS = { good: 800, poor: 1800 };
1352
+ var FCP_THRESHOLDS = { good: 1800, poor: 3e3 };
1353
+ function getRating(value, thresholds) {
1354
+ if (value <= thresholds.good) return "good";
1355
+ if (value <= thresholds.poor) return "needs-improvement";
1356
+ return "poor";
1357
+ }
1358
+ var clsValue = 0;
1359
+ var sessionValue = 0;
1360
+ var sessionEntries = [];
1361
+ function observeLCP(callback) {
1362
+ if (typeof PerformanceObserver === "undefined") return () => {
1363
+ };
1364
+ const observer = new PerformanceObserver((list) => {
1365
+ const entries = list.getEntries();
1366
+ const lastEntry = entries[entries.length - 1];
1367
+ const value = lastEntry.startTime;
1368
+ callback({
1369
+ name: "LCP",
1370
+ value,
1371
+ rating: getRating(value, LCP_THRESHOLDS),
1372
+ delta: value,
1373
+ entries,
1374
+ id: "v3-" + Date.now()
1375
+ });
1376
+ });
1377
+ observer.observe({ type: "largest-contentful-paint", buffered: true });
1378
+ return () => observer.disconnect();
1379
+ }
1380
+ function observeFID(callback) {
1381
+ if (typeof PerformanceObserver === "undefined") return () => {
1382
+ };
1383
+ const observer = new PerformanceObserver((list) => {
1384
+ const entries = list.getEntries();
1385
+ for (const entry of entries) {
1386
+ const value = entry.processingStart - entry.startTime;
1387
+ callback({
1388
+ name: "FID",
1389
+ value,
1390
+ rating: getRating(value, FID_THRESHOLDS),
1391
+ delta: value,
1392
+ entries: [entry],
1393
+ id: "v3-" + Date.now()
1394
+ });
1395
+ }
1396
+ });
1397
+ observer.observe({ type: "first-input", buffered: true });
1398
+ return () => observer.disconnect();
1399
+ }
1400
+ function observeCLS(callback) {
1401
+ if (typeof PerformanceObserver === "undefined") return () => {
1402
+ };
1403
+ const observer = new PerformanceObserver((list) => {
1404
+ const entries = list.getEntries();
1405
+ for (const entry of entries) {
1406
+ if (!entry.hadRecentInput) {
1407
+ const firstSessionEntry = sessionEntries[0];
1408
+ const lastSessionEntry = sessionEntries[sessionEntries.length - 1];
1409
+ if (firstSessionEntry && lastSessionEntry && entry.startTime - lastSessionEntry.startTime < 1e3 && entry.startTime - firstSessionEntry.startTime < 5e3) {
1410
+ sessionValue += entry.value;
1411
+ } else {
1412
+ sessionValue = entry.value;
1413
+ sessionEntries = [];
1414
+ }
1415
+ sessionEntries.push(entry);
1416
+ clsValue = sessionValue;
1417
+ callback({
1418
+ name: "CLS",
1419
+ value: clsValue * 1e3,
1420
+ rating: getRating(clsValue, CLS_THRESHOLDS),
1421
+ delta: entry.value * 1e3,
1422
+ entries: [entry],
1423
+ id: "v3-" + Date.now()
1424
+ });
1425
+ }
1426
+ }
1427
+ });
1428
+ observer.observe({ type: "layout-shift", buffered: true });
1429
+ return () => observer.disconnect();
1430
+ }
1431
+ function observeINP(callback) {
1432
+ if (typeof PerformanceObserver === "undefined") return () => {
1433
+ };
1434
+ const observer = new PerformanceObserver((list) => {
1435
+ const entries = list.getEntries();
1436
+ let maxDuration = 0;
1437
+ for (const entry of entries) {
1438
+ const duration = entry.duration;
1439
+ if (duration > maxDuration) maxDuration = duration;
1440
+ }
1441
+ callback({
1442
+ name: "INP",
1443
+ value: maxDuration,
1444
+ rating: getRating(maxDuration, INP_THRESHOLDS),
1445
+ delta: maxDuration,
1446
+ entries,
1447
+ id: "v3-" + Date.now()
1448
+ });
1449
+ });
1450
+ observer.observe({ type: "event", buffered: true });
1451
+ return () => observer.disconnect();
1452
+ }
1453
+ function observeTTFB(callback) {
1454
+ if (typeof performance === "undefined") return () => {
1455
+ };
1456
+ const navEntry = performance.getEntriesByType("navigation")[0];
1457
+ if (navEntry) {
1458
+ const value = navEntry.responseStart - navEntry.requestStart;
1459
+ callback({
1460
+ name: "TTFB",
1461
+ value,
1462
+ rating: getRating(value, TTFB_THRESHOLDS),
1463
+ delta: value,
1464
+ entries: [navEntry],
1465
+ id: "v3-" + Date.now()
1466
+ });
1467
+ }
1468
+ return () => {
1469
+ };
1470
+ }
1471
+ function observeFCP(callback) {
1472
+ if (typeof PerformanceObserver === "undefined") return () => {
1473
+ };
1474
+ const observer = new PerformanceObserver((list) => {
1475
+ const entries = list.getEntries();
1476
+ for (const entry of entries) {
1477
+ callback({
1478
+ name: "FCP",
1479
+ value: entry.startTime,
1480
+ rating: getRating(entry.startTime, FCP_THRESHOLDS),
1481
+ delta: entry.startTime,
1482
+ entries: [entry],
1483
+ id: "v3-" + Date.now()
1484
+ });
1485
+ }
1486
+ });
1487
+ observer.observe({ type: "paint", buffered: true });
1488
+ return () => observer.disconnect();
1489
+ }
1490
+ function observeAllVitals(callback) {
1491
+ const cleanups = [
1492
+ observeLCP(callback),
1493
+ observeFID(callback),
1494
+ observeCLS(callback),
1495
+ observeINP(callback),
1496
+ observeTTFB(callback),
1497
+ observeFCP(callback)
1498
+ ];
1499
+ return () => cleanups.forEach((cleanup) => cleanup());
1500
+ }
1501
+
1343
1502
  // ../../packages/runtime/tw/ssr-streaming.ts
1344
1503
  var encoder = new TextEncoder();
1345
1504
  function toUint8(chunk) {
@@ -5912,11 +6071,14 @@ var validators = {
5912
6071
  if (str.length > max) return message || `Must be at most ${max} characters`;
5913
6072
  return true;
5914
6073
  },
5915
- email: (value) => {
6074
+ // Factory like every other validator (docs/form-validators.md shows
6075
+ // `const email = validators.email()`); previously this was a bare
6076
+ // ValidatorFn, so `validators.email()(v)` threw.
6077
+ email: (message = "Invalid email address") => (value) => {
5916
6078
  const str = String(value != null ? value : "");
5917
6079
  if (!str) return true;
5918
6080
  const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
5919
- return re.test(str) ? true : "Invalid email address";
6081
+ return re.test(str) ? true : message;
5920
6082
  },
5921
6083
  url: (message = "Invalid URL") => (value) => {
5922
6084
  const str = String(value != null ? value : "");
@@ -13468,6 +13630,7 @@ export {
13468
13630
  consumeContext,
13469
13631
  copyHTML,
13470
13632
  copyJSON,
13633
+ copyText,
13471
13634
  copyToClipboard,
13472
13635
  createAnalyticsPlugin,
13473
13636
  createBuiltinTransitions,
@@ -13676,6 +13839,13 @@ export {
13676
13839
  nextTick,
13677
13840
  normalizeChild,
13678
13841
  normalizeChildren,
13842
+ observeAllVitals,
13843
+ observeCLS,
13844
+ observeFCP,
13845
+ observeFID,
13846
+ observeINP,
13847
+ observeLCP,
13848
+ observeTTFB,
13679
13849
  observeVisibility,
13680
13850
  off,
13681
13851
  offAll,