@svelte-vitals/core 0.33.0 → 0.34.0

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/dist/index.d.ts CHANGED
@@ -1471,7 +1471,7 @@ interface ScoreOptions {
1471
1471
  /** Compute the headline score and its breakdown (design §12). */
1472
1472
  declare function computeScore(results: Result[], config: Config, options?: ScoreOptions): ScoreResult;
1473
1473
  /** Compute an independent score per category present in `results` (issue #10). */
1474
- declare function scoresByCategory(results: Result[], config: Config): Partial<Record<Category, ScoreResult>>;
1474
+ declare function scoresByCategory(results: Result[], config: Config, options?: ScoreOptions): Partial<Record<Category, ScoreResult>>;
1475
1475
  interface HealthResult {
1476
1476
  /** Weighted overall score across present categories (0–100). */
1477
1477
  health: number;
@@ -1518,6 +1518,7 @@ interface JsonReport {
1518
1518
  routes: Array<{
1519
1519
  route: string;
1520
1520
  score: number;
1521
+ categories: Record<string, number>;
1521
1522
  issues: JsonIssue[];
1522
1523
  }>;
1523
1524
  siteIssues: JsonIssue[];
package/dist/index.js CHANGED
@@ -5877,7 +5877,7 @@ function computeScore(results, config, options = {}) {
5877
5877
  const rawScore = clamp(capBinds ? CRITICAL_CAP : rawUncapped);
5878
5878
  return { score: Math.floor(rawScore), rawScore, scoreModel: { routeAverage, sitePenalty, criticalCap } };
5879
5879
  }
5880
- function scoresByCategory(results, config) {
5880
+ function scoresByCategory(results, config, options = {}) {
5881
5881
  const byCat = /* @__PURE__ */ new Map();
5882
5882
  for (const r of results) {
5883
5883
  const cat = r.category ?? "seo";
@@ -5886,7 +5886,7 @@ function scoresByCategory(results, config) {
5886
5886
  bucket.push(r);
5887
5887
  }
5888
5888
  const out = {};
5889
- for (const [cat, rs] of byCat) out[cat] = computeScore(rs, config);
5889
+ for (const [cat, rs] of byCat) out[cat] = computeScore(rs, config, options);
5890
5890
  return out;
5891
5891
  }
5892
5892
  function computeHealth(results, config) {
@@ -6104,6 +6104,11 @@ function buildJsonReport(results, config, meta, ruleIds) {
6104
6104
  const routes = [...routeMap.values()].sort((a, b) => a.route.localeCompare(b.route)).map(({ route, results: rs }) => ({
6105
6105
  route,
6106
6106
  score: computeScore(rs, config, { applyCriticalCap: false }).score,
6107
+ // Per category, scored against that category's own inventory, so this is not guaranteed to average to
6108
+ // `score` — which is one ratio over the union of the pairs the route touched.
6109
+ categories: Object.fromEntries(
6110
+ Object.entries(scoresByCategory(rs, config, { applyCriticalCap: false })).map(([cat, sr]) => [cat, sr.score])
6111
+ ),
6107
6112
  issues: rs.filter((r) => isPenalized(r.detection, config.treatDynamicAs)).map((r) => ({ ...issueOf(r), severity: effectiveSeverity(r, config) }))
6108
6113
  }));
6109
6114
  const siteIssues = results.filter((r) => r.route === void 0 && isPenalized(r.detection, config.treatDynamicAs)).map((r) => ({ ...issueOf(r), severity: effectiveSeverity(r, config) }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svelte-vitals/core",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "description": "Shared, runtime-agnostic core for svelte-vitals (types, rule engine, scorer, reporter).",
5
5
  "type": "module",
6
6
  "license": "MIT",