repometry 0.0.0-dev.0 → 0.1.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.
Files changed (281) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +24 -1
  3. package/package.json +48 -7
  4. package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
  5. package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
  6. package/target/main/resources/report/json/config-v1.schema.json +34 -0
  7. package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
  8. package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
  9. package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
  10. package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
  11. package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
  12. package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
  13. package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
  14. package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
  15. package/target/main/resources/report/json/report-v1.schema.json +65 -0
  16. package/target/main/resources/report/json/report-v2.schema.json +238 -0
  17. package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
  18. package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
  19. package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
  20. package/target/main/resources/viewer/files.css +578 -0
  21. package/target/main/resources/viewer/index.html +130 -0
  22. package/target/main/resources/viewer/projects.html +52 -0
  23. package/target/main/resources/viewer/styles.css +586 -0
  24. package/target/main/resources/viewer/viewer-pulls.css +64 -0
  25. package/target/main/ts/api/gh/github-pr-comment.d.ts +4 -0
  26. package/target/main/ts/api/gh/github-pr-comment.js +107 -0
  27. package/target/main/ts/api/gh/github.d.ts +6 -0
  28. package/target/main/ts/api/gh/github.js +91 -0
  29. package/target/main/ts/api/git/blob-batch.d.ts +10 -0
  30. package/target/main/ts/api/git/blob-batch.js +105 -0
  31. package/target/main/ts/api/git/changes.d.ts +22 -0
  32. package/target/main/ts/api/git/changes.js +107 -0
  33. package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
  34. package/target/main/ts/api/git/commit-metadata.js +54 -0
  35. package/target/main/ts/api/git/git-churn.d.ts +9 -0
  36. package/target/main/ts/api/git/git-churn.js +70 -0
  37. package/target/main/ts/api/git/git-reader.d.ts +16 -0
  38. package/target/main/ts/api/git/git-reader.js +73 -0
  39. package/target/main/ts/api/git/git.d.ts +21 -0
  40. package/target/main/ts/api/git/git.js +152 -0
  41. package/target/main/ts/api/git/inspection-source.d.ts +15 -0
  42. package/target/main/ts/api/git/inspection-source.js +30 -0
  43. package/target/main/ts/api/git/local-sources.d.ts +5 -0
  44. package/target/main/ts/api/git/local-sources.js +46 -0
  45. package/target/main/ts/api/git/local.d.ts +3 -0
  46. package/target/main/ts/api/git/local.js +35 -0
  47. package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
  48. package/target/main/ts/api/git/metabranch-worktree.js +34 -0
  49. package/target/main/ts/api/git/source-cache.d.ts +3 -0
  50. package/target/main/ts/api/git/source-cache.js +56 -0
  51. package/target/main/ts/api/import/finding-import.d.ts +9 -0
  52. package/target/main/ts/api/import/finding-import.js +226 -0
  53. package/target/main/ts/api/import/lcov-files.d.ts +5 -0
  54. package/target/main/ts/api/import/lcov-files.js +13 -0
  55. package/target/main/ts/api/import/profile-file.d.ts +4 -0
  56. package/target/main/ts/api/import/profile-file.js +16 -0
  57. package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
  58. package/target/main/ts/api/worker/remote-executor.js +45 -0
  59. package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
  60. package/target/main/ts/api/worker/worker-protocol.js +101 -0
  61. package/target/main/ts/api/worker/worker.d.ts +5 -0
  62. package/target/main/ts/api/worker/worker.js +85 -0
  63. package/target/main/ts/cli/arguments.d.ts +28 -0
  64. package/target/main/ts/cli/arguments.js +110 -0
  65. package/target/main/ts/cli/config.d.ts +14 -0
  66. package/target/main/ts/cli/config.js +60 -0
  67. package/target/main/ts/cli/github-pr-comment.d.ts +1 -0
  68. package/target/main/ts/cli/github-pr-comment.js +12 -0
  69. package/target/main/ts/cli/imports.d.ts +7 -0
  70. package/target/main/ts/cli/imports.js +29 -0
  71. package/target/main/ts/cli/main.d.ts +2 -0
  72. package/target/main/ts/cli/main.js +343 -284
  73. package/target/main/ts/cli/reporting.d.ts +18 -0
  74. package/target/main/ts/cli/reporting.js +108 -0
  75. package/target/main/ts/cli/revisions.d.ts +6 -0
  76. package/target/main/ts/cli/revisions.js +15 -0
  77. package/target/main/ts/cli/store.d.ts +13 -0
  78. package/target/main/ts/cli/store.js +38 -0
  79. package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
  80. package/target/main/ts/compose/analyze-snapshot.js +163 -0
  81. package/target/main/ts/compose/attach-churn.d.ts +2 -0
  82. package/target/main/ts/compose/attach-churn.js +37 -0
  83. package/target/main/ts/compose/diff-coverage.d.ts +20 -0
  84. package/target/main/ts/compose/diff-coverage.js +56 -0
  85. package/target/main/ts/compose/inspect.d.ts +23 -0
  86. package/target/main/ts/compose/inspect.js +44 -0
  87. package/target/main/ts/compose/plugin-list.d.ts +6 -0
  88. package/target/main/ts/compose/plugin-list.js +9 -0
  89. package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
  90. package/target/main/ts/compose/prepare-metabranch.js +16 -0
  91. package/target/main/ts/compose/review.d.ts +16 -0
  92. package/target/main/ts/compose/review.js +38 -0
  93. package/target/main/ts/compose/sources.d.ts +3 -0
  94. package/target/main/ts/compose/sources.js +29 -0
  95. package/target/main/ts/core/engine/execute.d.ts +10 -0
  96. package/target/main/ts/core/engine/execute.js +49 -0
  97. package/target/main/ts/core/engine/manifest.d.ts +4 -0
  98. package/target/main/ts/core/engine/manifest.js +104 -0
  99. package/target/main/ts/core/engine/plan.d.ts +22 -0
  100. package/target/main/ts/core/engine/plan.js +106 -0
  101. package/target/main/ts/core/engine/plugin.d.ts +59 -0
  102. package/target/main/ts/core/engine/plugin.js +4 -0
  103. package/target/main/ts/core/engine/report-products.d.ts +16 -0
  104. package/target/main/ts/core/engine/report-products.js +85 -0
  105. package/target/main/ts/core/model/changes.d.ts +8 -0
  106. package/target/main/ts/core/model/changes.js +1 -0
  107. package/target/main/ts/core/model/churn.d.ts +11 -0
  108. package/target/main/ts/core/model/churn.js +5 -0
  109. package/target/main/ts/core/model/clone-source.d.ts +16 -0
  110. package/target/main/ts/core/model/clone-source.js +14 -0
  111. package/target/main/ts/core/model/code-structure.d.ts +30 -0
  112. package/target/main/ts/core/model/code-structure.js +31 -0
  113. package/target/main/ts/core/model/comparison.d.ts +24 -0
  114. package/target/main/ts/core/model/comparison.js +1 -0
  115. package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
  116. package/target/main/ts/core/model/diff-coverage.js +1 -0
  117. package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
  118. package/target/main/ts/core/model/finding-ignore.js +35 -0
  119. package/target/main/ts/core/model/finding.d.ts +28 -0
  120. package/target/main/ts/core/model/finding.js +29 -0
  121. package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
  122. package/target/main/ts/core/model/ignore-rule.js +1 -0
  123. package/target/main/ts/core/model/measurement.d.ts +27 -0
  124. package/target/main/ts/core/model/measurement.js +24 -0
  125. package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
  126. package/target/main/ts/core/model/metric-descriptor.js +1 -0
  127. package/target/main/ts/core/model/plugin-data.d.ts +25 -0
  128. package/target/main/ts/core/model/plugin-data.js +1 -0
  129. package/target/main/ts/core/model/pull-review.d.ts +48 -0
  130. package/target/main/ts/core/model/pull-review.js +1 -0
  131. package/target/main/ts/core/model/quality-summary.d.ts +42 -0
  132. package/target/main/ts/core/model/quality-summary.js +64 -0
  133. package/target/main/ts/core/model/report.d.ts +32 -0
  134. package/target/main/ts/core/model/report.js +5 -0
  135. package/target/main/ts/core/model/scanner-import.d.ts +39 -0
  136. package/target/main/ts/core/model/scanner-import.js +28 -0
  137. package/target/main/ts/core/model/snapshot.d.ts +15 -0
  138. package/target/main/ts/core/model/snapshot.js +50 -0
  139. package/target/main/ts/core/model/source-locator.d.ts +7 -0
  140. package/target/main/ts/core/model/source-locator.js +1 -0
  141. package/target/main/ts/core/model/source.d.ts +23 -0
  142. package/target/main/ts/core/model/source.js +1 -0
  143. package/target/main/ts/core/ports/report.d.ts +9 -0
  144. package/target/main/ts/core/ports/report.js +1 -0
  145. package/target/main/ts/core/ports/source-provider.d.ts +14 -0
  146. package/target/main/ts/core/ports/source-provider.js +4 -0
  147. package/target/main/ts/core/profile/exclusions.d.ts +11 -0
  148. package/target/main/ts/core/profile/exclusions.js +57 -0
  149. package/target/main/ts/core/profile/maintainability.d.ts +31 -0
  150. package/target/main/ts/core/profile/maintainability.js +9 -0
  151. package/target/main/ts/core/profile/profile.d.ts +4 -0
  152. package/target/main/ts/core/profile/profile.js +10 -0
  153. package/target/main/ts/core/usecases/compare.d.ts +6 -0
  154. package/target/main/ts/core/usecases/compare.js +145 -0
  155. package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
  156. package/target/main/ts/core/usecases/diff-coverage-policy.js +10 -0
  157. package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
  158. package/target/main/ts/core/usecases/diff-coverage.js +15 -0
  159. package/target/main/ts/core/usecases/inspect.d.ts +38 -0
  160. package/target/main/ts/core/usecases/inspect.js +41 -0
  161. package/target/main/ts/core/usecases/review.d.ts +31 -0
  162. package/target/main/ts/core/usecases/review.js +128 -0
  163. package/target/main/ts/index.d.ts +35 -0
  164. package/target/main/ts/index.js +17 -13
  165. package/target/main/ts/plugin.d.ts +14 -0
  166. package/target/main/ts/plugin.js +5 -0
  167. package/target/main/ts/plugins/coverage/coverage.d.ts +23 -0
  168. package/target/main/ts/plugins/coverage/coverage.js +120 -0
  169. package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
  170. package/target/main/ts/plugins/coverage/diff-coverage.js +89 -0
  171. package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
  172. package/target/main/ts/plugins/duplication/duplication.js +93 -0
  173. package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
  174. package/target/main/ts/plugins/language-js/babel-provider.js +46 -0
  175. package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
  176. package/target/main/ts/plugins/language-js/clone-candidates.js +64 -0
  177. package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
  178. package/target/main/ts/plugins/language-js/code-lines.js +35 -0
  179. package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
  180. package/target/main/ts/plugins/language-js/function-facts.js +60 -0
  181. package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
  182. package/target/main/ts/plugins/language-js/structural-observations.js +79 -0
  183. package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
  184. package/target/main/ts/plugins/maintainability/maintainability.js +42 -0
  185. package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
  186. package/target/main/ts/plugins/maintainability/structural-smells.js +15 -0
  187. package/target/main/ts/plugins/source/forges.d.ts +4 -0
  188. package/target/main/ts/plugins/source/forges.js +79 -0
  189. package/target/main/ts/plugins/structure/structure.d.ts +2 -0
  190. package/target/main/ts/plugins/structure/structure.js +37 -0
  191. package/target/main/ts/report/html/app/viewer-access.d.ts +19 -0
  192. package/target/main/ts/report/html/app/viewer-access.js +25 -0
  193. package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
  194. package/target/main/ts/report/html/app/viewer-chart.js +711 -0
  195. package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
  196. package/target/main/ts/report/html/app/viewer-commits.js +280 -0
  197. package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
  198. package/target/main/ts/report/html/app/viewer-data.js +105 -0
  199. package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
  200. package/target/main/ts/report/html/app/viewer-files.js +2087 -0
  201. package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
  202. package/target/main/ts/report/html/app/viewer-filter.js +492 -0
  203. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +68 -0
  204. package/target/main/ts/report/html/app/viewer-metric-registry.js +206 -0
  205. package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
  206. package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
  207. package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
  208. package/target/main/ts/report/html/app/viewer-profile.js +401 -0
  209. package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
  210. package/target/main/ts/report/html/app/viewer-projects.js +90 -0
  211. package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
  212. package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
  213. package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
  214. package/target/main/ts/report/html/app/viewer-source.js +313 -0
  215. package/target/main/ts/report/html/app/viewer-trends.d.ts +74 -0
  216. package/target/main/ts/report/html/app/viewer-trends.js +413 -0
  217. package/target/main/ts/report/html/app/viewer.d.ts +1 -0
  218. package/target/main/ts/report/html/app/viewer.js +794 -0
  219. package/target/main/ts/report/html/site/badges.d.ts +14 -0
  220. package/target/main/ts/report/html/site/badges.js +39 -0
  221. package/target/main/ts/report/html/site/export-site.d.ts +21 -0
  222. package/target/main/ts/report/html/site/export-site.js +157 -0
  223. package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
  224. package/target/main/ts/report/html/site/exported-server.js +70 -0
  225. package/target/main/ts/report/html/site/local-server.d.ts +7 -0
  226. package/target/main/ts/report/html/site/local-server.js +64 -0
  227. package/target/main/ts/report/html/site/projects.d.ts +3 -0
  228. package/target/main/ts/report/html/site/projects.js +79 -0
  229. package/target/main/ts/report/html/site/server.d.ts +4 -0
  230. package/target/main/ts/report/html/site/server.js +64 -0
  231. package/target/main/ts/report/html/site/source-route.d.ts +6 -0
  232. package/target/main/ts/report/html/site/source-route.js +22 -0
  233. package/target/main/ts/report/json/projections/commit-summary.d.ts +11 -0
  234. package/target/main/ts/report/json/projections/commit-summary.js +118 -0
  235. package/target/main/ts/report/json/projections/components.d.ts +4 -0
  236. package/target/main/ts/report/json/projections/components.js +29 -0
  237. package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
  238. package/target/main/ts/report/json/projections/file-metrics.js +243 -0
  239. package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
  240. package/target/main/ts/report/json/projections/inspection-context.js +92 -0
  241. package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
  242. package/target/main/ts/report/json/projections/inspection-details.js +69 -0
  243. package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
  244. package/target/main/ts/report/json/projections/metric-values.js +57 -0
  245. package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
  246. package/target/main/ts/report/json/projections/public-history.js +16 -0
  247. package/target/main/ts/report/json/store/components.d.ts +2 -0
  248. package/target/main/ts/report/json/store/components.js +31 -0
  249. package/target/main/ts/report/json/store/local-store.d.ts +13 -0
  250. package/target/main/ts/report/json/store/local-store.js +179 -0
  251. package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
  252. package/target/main/ts/report/json/store/pull-review-store.js +51 -0
  253. package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
  254. package/target/main/ts/report/json/validation/metabranch.js +7 -0
  255. package/target/main/ts/report/json/validation/report.d.ts +15 -0
  256. package/target/main/ts/report/json/validation/report.js +64 -0
  257. package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
  258. package/target/main/ts/report/json/validation/summary-validation.js +27 -0
  259. package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
  260. package/target/main/ts/report/json/wire/compact-json.js +76 -0
  261. package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
  262. package/target/main/ts/report/json/wire/component-model.js +1 -0
  263. package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
  264. package/target/main/ts/report/json/wire/domain-types.js +1 -0
  265. package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
  266. package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
  267. package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
  268. package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
  269. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
  270. package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
  271. package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
  272. package/target/main/ts/report/json/wire/project-model.js +1 -0
  273. package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
  274. package/target/main/ts/report/json/wire/public-history-model.js +6 -0
  275. package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
  276. package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
  277. package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
  278. package/target/main/ts/report/json/wire/summary-model.js +1 -0
  279. package/target/main/ts/report.d.ts +11 -0
  280. package/target/main/ts/report.js +5 -0
  281. package/index.js +0 -1
@@ -0,0 +1,113 @@
1
+ import type { FileMetricsReport } from '../../json/wire/file-metrics-model.js';
2
+ type FileEntry = FileMetricsReport['files'][number];
3
+ /** A built-in measure, or another plugin's metric by its registry key. */
4
+ export type Measure = string;
5
+ export type Operator = '>' | '>=' | '<' | '<=' | '=';
6
+ export type Clause = {
7
+ readonly kind: 'lang';
8
+ readonly value: string;
9
+ } | {
10
+ readonly kind: 'component';
11
+ readonly value: string;
12
+ } | {
13
+ readonly kind: 'path';
14
+ readonly value: string;
15
+ } | {
16
+ readonly kind: 'measure';
17
+ readonly measure: Measure;
18
+ readonly operator: Operator;
19
+ readonly value: number;
20
+ } | {
21
+ readonly kind: 'has';
22
+ readonly value: 'findings' | 'diagnostics';
23
+ }
24
+ /** Whether a plugin read the file: `ignored:yes` lists what is only counted, lockfiles aside. */
25
+ | {
26
+ readonly kind: 'analysed';
27
+ readonly value: 'yes' | 'no';
28
+ }
29
+ /** Generated dependency lockfiles: `lockfile:yes`. */
30
+ | {
31
+ readonly kind: 'lockfile';
32
+ readonly value: 'yes' | 'no';
33
+ };
34
+ /** What a file brings to the query beyond its metrics: the components it belongs to and its open findings. */
35
+ export interface FileFacts {
36
+ readonly components: ReadonlyMap<string, readonly string[]>;
37
+ readonly findings: ReadonlyMap<string, number>;
38
+ }
39
+ export interface MeasureSpec {
40
+ readonly label: string;
41
+ readonly percent?: boolean;
42
+ readonly minutes?: boolean;
43
+ read(entry: FileEntry): number | null;
44
+ }
45
+ export declare function usePluginMeasures(entries: Iterable<readonly [string, MeasureSpec]>): void;
46
+ /**
47
+ * Dependency lockfiles, by exact file name. They are generated, often the largest files in a repository, and no
48
+ * plugin reads them: the language bar and the Metrics list give them a category of their own beside the ignored files.
49
+ */
50
+ export declare const lockfileNames: ReadonlySet<string>;
51
+ /** Whether a path names a lockfile: its file name, at any depth, exactly as the tools write it. */
52
+ export declare function isLockfile(path: string): boolean;
53
+ /** Whether no plugin read a file and it is not a lockfile: what the interface calls ignored. */
54
+ export declare function isIgnored(entry: Pick<FileEntry, 'path' | 'analysed'>): boolean;
55
+ /** The language bar's names for the two categories that are not languages. */
56
+ export declare const lockfilesLabel = "Lockfiles";
57
+ export declare const ignoredLabel = "Ignored";
58
+ /** What the language bar weighs: size in bytes, physical lines, or code lines. */
59
+ export type ShareMeasure = 'bytes' | 'lines' | 'code-lines';
60
+ /** Whether every file carries its size: inspections made before sizes were recorded carry none. */
61
+ export declare function sized(files: readonly Pick<FileEntry, 'bytes'>[]): boolean;
62
+ /**
63
+ * What the language bar weighs, largest language first, then lockfiles, then the ignored files. Size in bytes when
64
+ * every file has it: one measure for code, lockfiles and ignored files alike, untouched by formatting. Without sizes,
65
+ * physical lines where any file is only counted (the one line measure all files have), otherwise code lines.
66
+ */
67
+ export declare function languageShares(files: readonly Pick<FileEntry, 'path' | 'analysed' | 'lines' | 'quality' | 'bytes'>[]): {
68
+ readonly measure: ShareMeasure;
69
+ readonly shares: readonly (readonly [string, number])[];
70
+ };
71
+ export declare function languageOf(path: string): string;
72
+ export declare function languageColor(language: string): string;
73
+ /** Splits the query into clauses; a word that names nothing known becomes a path fragment. */
74
+ export declare function parseQuery(text: string): Clause[];
75
+ export declare function parseWord(word: string): Clause | null;
76
+ export declare function formatQuery(clauses: readonly Clause[]): string;
77
+ export declare function clauseText(clause: Clause): string;
78
+ /** The chip's words: what it selects, in the interface's language rather than the query's. */
79
+ export declare function clauseLabel(clause: Clause): {
80
+ key: string;
81
+ value: string;
82
+ };
83
+ export declare function sameClause(a: Clause, b: Clause): boolean;
84
+ /**
85
+ * Whether a file passes the query. Chips of one kind widen the selection (TypeScript or JavaScript), chips of
86
+ * different kinds narrow it (TypeScript in the core component), and every condition must hold.
87
+ */
88
+ export declare function matches(entry: FileEntry, clauses: readonly Clause[], facts: FileFacts, text?: string): boolean;
89
+ export interface Suggestion {
90
+ readonly group: string;
91
+ readonly label: string;
92
+ readonly detail?: string;
93
+ readonly clause: Clause;
94
+ readonly color?: string;
95
+ }
96
+ /** What the field offers for the typed text: the facets of this codebase first, then conditions, then the path. */
97
+ export declare function suggest(text: string, files: readonly FileEntry[], facts: FileFacts, chosen: readonly Clause[]): Suggestion[];
98
+ export interface QueryField {
99
+ readonly element: HTMLElement;
100
+ /** Text typed but not yet made a chip; it filters paths as you type. */
101
+ readonly text: () => string;
102
+ /** Replaces the chips from outside, as when a language is picked on the bar; reports the change as typing does. */
103
+ readonly set: (clauses: readonly Clause[]) => void;
104
+ }
105
+ /**
106
+ * The field: chips for the chosen clauses, then a text input; the list of suggestions hangs from it in one frame.
107
+ * Backspace in an empty input takes the last chip back into text, so a chip can be edited, not just removed.
108
+ */
109
+ export declare function queryField(clauses: readonly Clause[], options: {
110
+ readonly suggestions: (text: string) => Suggestion[];
111
+ readonly change: (clauses: readonly Clause[], text: string) => void;
112
+ }): QueryField;
113
+ export {};
@@ -0,0 +1,492 @@
1
+ import { labelOf } from './viewer-metrics.js';
2
+ const measures = {
3
+ complexity: { label: labelOf('complexity'), read: entry => entry.complexity?.maximum ?? null },
4
+ cognitive: { label: labelOf('cognitive'), read: entry => entry.quality?.cognitiveComplexity ?? null },
5
+ lines: { label: labelOf('code-lines'), read: entry => entry.quality?.codeLines ?? entry.lines },
6
+ functions: { label: 'Functions', read: entry => entry.functions },
7
+ coverage: { label: labelOf('coverage'), percent: true,
8
+ read: entry => entry.lineCoverage && entry.lineCoverage.total > 0 ? entry.lineCoverage.covered / entry.lineCoverage.total : null },
9
+ duplication: { label: 'Duplication', percent: true, read: entry => {
10
+ const duplication = entry.quality?.duplication;
11
+ return duplication && duplication.codeLines > 0 ? duplication.duplicatedLines / duplication.codeLines : null;
12
+ } },
13
+ remediation: { label: labelOf('effort'), minutes: true, read: entry => entry.quality?.maintainability?.effortMinutes ?? null },
14
+ changes: { label: 'Git changes', read: entry => entry.quality?.churn ?? null },
15
+ };
16
+ /** Other plugins' metrics, by key, for the inspection on screen. */
17
+ let pluginMeasures = new Map();
18
+ export function usePluginMeasures(entries) {
19
+ pluginMeasures = new Map(entries);
20
+ }
21
+ function measureOf(name) {
22
+ return name in measures ? measures[name] : pluginMeasures.get(name);
23
+ }
24
+ /**
25
+ * Dependency lockfiles, by exact file name. They are generated, often the largest files in a repository, and no
26
+ * plugin reads them: the language bar and the Metrics list give them a category of their own beside the ignored files.
27
+ */
28
+ export const lockfileNames = new Set([
29
+ 'package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lock', 'bun.lockb', 'deno.lock',
30
+ 'Cargo.lock', 'Gemfile.lock', 'composer.lock', 'poetry.lock', 'Pipfile.lock', 'uv.lock', 'go.sum', 'flake.lock',
31
+ 'mix.lock', 'pubspec.lock', 'packages.lock.json', 'gradle.lockfile',
32
+ ]);
33
+ /** Whether a path names a lockfile: its file name, at any depth, exactly as the tools write it. */
34
+ export function isLockfile(path) {
35
+ return lockfileNames.has(path.slice(path.lastIndexOf('/') + 1));
36
+ }
37
+ /** Whether no plugin read a file and it is not a lockfile: what the interface calls ignored. */
38
+ export function isIgnored(entry) {
39
+ return entry.analysed === false && !isLockfile(entry.path);
40
+ }
41
+ /** The language bar's names for the two categories that are not languages. */
42
+ export const lockfilesLabel = 'Lockfiles';
43
+ export const ignoredLabel = 'Ignored';
44
+ /** Whether every file carries its size: inspections made before sizes were recorded carry none. */
45
+ export function sized(files) {
46
+ return files.length > 0 && files.every(entry => entry.bytes !== undefined);
47
+ }
48
+ /**
49
+ * What the language bar weighs, largest language first, then lockfiles, then the ignored files. Size in bytes when
50
+ * every file has it: one measure for code, lockfiles and ignored files alike, untouched by formatting. Without sizes,
51
+ * physical lines where any file is only counted (the one line measure all files have), otherwise code lines.
52
+ */
53
+ export function languageShares(files) {
54
+ const measure = sized(files) ? 'bytes'
55
+ : files.some(entry => entry.analysed === false || isLockfile(entry.path)) ? 'lines' : 'code-lines';
56
+ const weightOf = (entry) => (measure === 'bytes' ? entry.bytes
57
+ : measure === 'lines' ? entry.lines : entry.quality?.codeLines ?? entry.lines) ?? 0;
58
+ const weights = new Map();
59
+ let lockfiles = 0;
60
+ let ignored = 0;
61
+ for (const entry of files) {
62
+ if (isLockfile(entry.path))
63
+ lockfiles += weightOf(entry);
64
+ else if (entry.analysed === false)
65
+ ignored += weightOf(entry);
66
+ else {
67
+ const language = languageOf(entry.path);
68
+ weights.set(language, (weights.get(language) ?? 0) + weightOf(entry));
69
+ }
70
+ }
71
+ const shares = [...weights].filter(([, weight]) => weight > 0).sort((a, b) => b[1] - a[1]);
72
+ if (lockfiles > 0)
73
+ shares.push([lockfilesLabel, lockfiles]);
74
+ if (ignored > 0)
75
+ shares.push([ignoredLabel, ignored]);
76
+ return { measure, shares };
77
+ }
78
+ /** Ready-made conditions offered before anything is typed: the questions people ask of a codebase most. */
79
+ const presets = [
80
+ { text: 'complexity>10', label: 'Complex functions' },
81
+ { text: 'coverage<80%', label: 'Under 80% covered' },
82
+ { text: 'duplication>0', label: 'Has duplication' },
83
+ { text: 'remediation>0', label: 'Has technical debt' },
84
+ { text: 'changes>0', label: 'Changed recently' },
85
+ { text: 'has:findings', label: 'Has findings' },
86
+ ];
87
+ const languages = {
88
+ ts: 'TypeScript', tsx: 'TypeScript', mts: 'TypeScript', cts: 'TypeScript',
89
+ js: 'JavaScript', jsx: 'JavaScript', mjs: 'JavaScript', cjs: 'JavaScript',
90
+ py: 'Python', go: 'Go', rs: 'Rust', java: 'Java', kt: 'Kotlin', kts: 'Kotlin', rb: 'Ruby', php: 'PHP', cs: 'C#',
91
+ c: 'C', h: 'C', cc: 'C++', cpp: 'C++', cxx: 'C++', hpp: 'C++', hh: 'C++', swift: 'Swift', scala: 'Scala',
92
+ vue: 'Vue', svelte: 'Svelte', sh: 'Shell', bash: 'Shell', css: 'CSS', scss: 'SCSS', less: 'Less', html: 'HTML',
93
+ };
94
+ /** Language colours follow the conventions people already know from code hosts. */
95
+ const languageColors = {
96
+ TypeScript: '#3178c6', JavaScript: '#f1e05a', Python: '#3572a5', Go: '#00add8', Rust: '#dea584', Java: '#b07219',
97
+ Kotlin: '#a97bff', Ruby: '#701516', PHP: '#4f5d95', 'C#': '#178600', C: '#555555', 'C++': '#f34b7d', Swift: '#f05138',
98
+ Scala: '#c22d40', Vue: '#41b883', Svelte: '#ff3e00', Shell: '#89e051', CSS: '#663399', SCSS: '#c6538c', Less: '#1d365d',
99
+ HTML: '#e34c26',
100
+ };
101
+ export function languageOf(path) {
102
+ const name = path.slice(path.lastIndexOf('/') + 1);
103
+ const dot = name.lastIndexOf('.');
104
+ const extension = dot > 0 ? name.slice(dot + 1).toLowerCase() : '';
105
+ return languages[extension] ?? (extension ? extension.toUpperCase() : 'Other');
106
+ }
107
+ export function languageColor(language) {
108
+ return languageColors[language] ?? 'var(--neutral-2)';
109
+ }
110
+ /** Splits the query into clauses; a word that names nothing known becomes a path fragment. */
111
+ export function parseQuery(text) {
112
+ const clauses = [];
113
+ for (const match of text.matchAll(/(\w+):"([^"]*)"|(\S+)/g)) {
114
+ const clause = match[1] ? keyed(match[1], match[2]) : parseWord(match[3]);
115
+ if (clause)
116
+ clauses.push(clause);
117
+ }
118
+ return clauses;
119
+ }
120
+ export function parseWord(word) {
121
+ const keyedWord = /^(\w+):(.+)$/.exec(word);
122
+ if (keyedWord)
123
+ return keyed(keyedWord[1], keyedWord[2]);
124
+ const condition = /^([\w.-]+)(>=|<=|>|<|=)(\d+(?:\.\d+)?)(%|h|min)?$/i.exec(word);
125
+ if (condition) {
126
+ const measure = condition[1].toLowerCase();
127
+ const spec = measureOf(measure);
128
+ if (!spec)
129
+ return null;
130
+ const number = Number(condition[3]);
131
+ const unit = condition[4]?.toLowerCase();
132
+ const value = spec.percent ? (unit === '%' || number > 1 ? number / 100 : number) : unit === 'h' ? number * 60 : number;
133
+ return { kind: 'measure', measure, operator: condition[2], value };
134
+ }
135
+ return word ? { kind: 'path', value: word } : null;
136
+ }
137
+ function keyed(key, value) {
138
+ switch (key.toLowerCase()) {
139
+ case 'lang':
140
+ case 'language': return { kind: 'lang', value };
141
+ case 'component': return { kind: 'component', value };
142
+ case 'path':
143
+ case 'in': return { kind: 'path', value };
144
+ case 'has': return value === 'findings' || value === 'diagnostics' ? { kind: 'has', value } : null;
145
+ // The interface and the query call the files no plugin read "ignored"; `analysed:` stays as a silent alias.
146
+ case 'analysed':
147
+ case 'analyzed': return value === 'yes' || value === 'no' ? { kind: 'analysed', value } : null;
148
+ case 'ignored': return value === 'yes' || value === 'no' ? { kind: 'analysed', value: value === 'yes' ? 'no' : 'yes' } : null;
149
+ case 'lockfile':
150
+ case 'lockfiles': return value === 'yes' || value === 'no' ? { kind: 'lockfile', value } : null;
151
+ default: return null;
152
+ }
153
+ }
154
+ export function formatQuery(clauses) {
155
+ return clauses.map(clauseText).join(' ');
156
+ }
157
+ export function clauseText(clause) {
158
+ const quoted = (value) => /\s|"/.test(value) ? `"${value.replaceAll('"', '')}"` : value;
159
+ switch (clause.kind) {
160
+ case 'lang': return `lang:${quoted(clause.value)}`;
161
+ case 'component': return `component:${quoted(clause.value)}`;
162
+ case 'path': return /^\w+:|[<>=]/.test(clause.value) || /\s/.test(clause.value) ? `path:${quoted(clause.value)}` : clause.value;
163
+ case 'has': return `has:${clause.value}`;
164
+ case 'analysed': return `ignored:${clause.value === 'no' ? 'yes' : 'no'}`;
165
+ case 'lockfile': return `lockfile:${clause.value}`;
166
+ case 'measure': {
167
+ const percent = measureOf(clause.measure)?.percent;
168
+ const value = percent ? `${Math.round(clause.value * 1000) / 10}%` : String(clause.value);
169
+ return `${clause.measure}${clause.operator}${value}`;
170
+ }
171
+ }
172
+ }
173
+ /** The chip's words: what it selects, in the interface's language rather than the query's. */
174
+ export function clauseLabel(clause) {
175
+ switch (clause.kind) {
176
+ case 'lang': return { key: 'Language', value: clause.value };
177
+ case 'component': return { key: 'Component', value: clause.value };
178
+ case 'path': return { key: 'Path', value: clause.value };
179
+ case 'has': return { key: 'Has', value: clause.value };
180
+ case 'analysed': return { key: 'Ignored', value: clause.value === 'no' ? 'Yes' : 'No' };
181
+ case 'lockfile': return { key: 'Lockfile', value: clause.value === 'yes' ? 'Yes' : 'No' };
182
+ case 'measure': {
183
+ const { label, percent, minutes } = measureOf(clause.measure) ?? { label: clause.measure };
184
+ const value = percent ? `${Math.round(clause.value * 1000) / 10}%` : minutes ? `${clause.value} min` : String(clause.value);
185
+ return { key: label, value: `${clause.operator === '>=' ? '≥' : clause.operator === '<=' ? '≤' : clause.operator} ${value}` };
186
+ }
187
+ }
188
+ }
189
+ export function sameClause(a, b) {
190
+ return clauseText(a) === clauseText(b);
191
+ }
192
+ /**
193
+ * Whether a file passes the query. Chips of one kind widen the selection (TypeScript or JavaScript), chips of
194
+ * different kinds narrow it (TypeScript in the core component), and every condition must hold.
195
+ */
196
+ export function matches(entry, clauses, facts, text = '') {
197
+ const any = (kind, test) => {
198
+ const values = clauses.flatMap(clause => clause.kind === kind ? [clause.value] : []);
199
+ return values.length === 0 || values.some(test);
200
+ };
201
+ const path = entry.path.toLowerCase();
202
+ if (text && !path.includes(text.toLowerCase()))
203
+ return false;
204
+ if (!any('lang', value => languageOf(entry.path).toLowerCase() === value.toLowerCase()))
205
+ return false;
206
+ if (!any('component', value => (facts.components.get(entry.path) ?? []).some(name => name.toLowerCase() === value.toLowerCase())))
207
+ return false;
208
+ if (!any('path', value => path.includes(value.toLowerCase())))
209
+ return false;
210
+ return clauses.every(clause => {
211
+ if (clause.kind === 'has')
212
+ return clause.value === 'findings' ? (facts.findings.get(entry.path) ?? 0) > 0 : entry.diagnosticCount > 0;
213
+ if (clause.kind === 'analysed')
214
+ return isIgnored(entry) === (clause.value === 'no');
215
+ if (clause.kind === 'lockfile')
216
+ return isLockfile(entry.path) === (clause.value === 'yes');
217
+ if (clause.kind !== 'measure')
218
+ return true;
219
+ const value = measureOf(clause.measure)?.read(entry) ?? null;
220
+ if (value === null)
221
+ return false;
222
+ switch (clause.operator) {
223
+ case '>': return value > clause.value;
224
+ case '>=': return value >= clause.value;
225
+ case '<': return value < clause.value;
226
+ case '<=': return value <= clause.value;
227
+ case '=': return value === clause.value;
228
+ }
229
+ });
230
+ }
231
+ /** What the field offers for the typed text: the facets of this codebase first, then conditions, then the path. */
232
+ export function suggest(text, files, facts, chosen) {
233
+ const query = text.trim().toLowerCase();
234
+ const taken = (clause) => chosen.some(other => sameClause(other, clause));
235
+ const result = [];
236
+ const counts = new Map();
237
+ for (const file of files)
238
+ counts.set(languageOf(file.path), (counts.get(languageOf(file.path)) ?? 0) + 1);
239
+ for (const [language, total] of [...counts].sort((a, b) => b[1] - a[1])) {
240
+ const clause = { kind: 'lang', value: language };
241
+ if (!taken(clause) && (!query || language.toLowerCase().includes(query) || 'lang'.startsWith(query))) {
242
+ result.push({ group: 'Languages', label: language, detail: quantity(total), clause, color: languageColor(language) });
243
+ }
244
+ }
245
+ const members = new Map();
246
+ for (const names of facts.components.values())
247
+ for (const name of names)
248
+ members.set(name, (members.get(name) ?? 0) + 1);
249
+ for (const [name, total] of members) {
250
+ const clause = { kind: 'component', value: name };
251
+ if (!taken(clause) && (!query || name.toLowerCase().includes(query) || 'component'.startsWith(query))) {
252
+ result.push({ group: 'Components', label: name, detail: quantity(total), clause });
253
+ }
254
+ }
255
+ // Files only counted, never read by a plugin, are one condition away once the text names them.
256
+ const named = (words) => query.length >= 3
257
+ && words.some(phrase => phrase.startsWith(query) || (phrase.includes(' ') && phrase.includes(query)));
258
+ const unread = files.filter(isIgnored).length;
259
+ const notAnalysed = { kind: 'analysed', value: 'no' };
260
+ if (unread && !taken(notAnalysed) && named(['ignored files', 'ignored:yes', 'not analysed', 'analysed:no'])) {
261
+ result.push({ group: 'Conditions', label: 'Ignored files', detail: quantity(unread), clause: notAnalysed });
262
+ }
263
+ const lockfiles = files.filter(file => isLockfile(file.path)).length;
264
+ const lockfile = { kind: 'lockfile', value: 'yes' };
265
+ if (lockfiles && !taken(lockfile) && named(['lockfiles', 'lockfile:yes'])) {
266
+ result.push({ group: 'Conditions', label: lockfilesLabel, detail: quantity(lockfiles), clause: lockfile });
267
+ }
268
+ const typed = query ? parseWord(text.trim()) : null;
269
+ if (typed && (typed.kind === 'measure' || typed.kind === 'has' || typed.kind === 'analysed' || typed.kind === 'lockfile') && !taken(typed)) {
270
+ const { key, value } = clauseLabel(typed);
271
+ result.push({ group: 'Conditions', label: `${key} ${value}`, clause: typed });
272
+ }
273
+ else {
274
+ // Other plugins' metrics are offered once the typed text names them; the presets stay Repometry's own.
275
+ if (query)
276
+ for (const [key, { label }] of pluginMeasures) {
277
+ const clause = { kind: 'measure', measure: key, operator: '>', value: 0 };
278
+ if (!taken(clause) && (key.startsWith(query) || label.toLowerCase().includes(query))) {
279
+ result.push({ group: 'Conditions', label: `${label} above zero`, detail: `${label} > 0`, clause });
280
+ }
281
+ }
282
+ for (const preset of presets) {
283
+ const clause = parseWord(preset.text);
284
+ const { key, value } = clauseLabel(clause);
285
+ if (!taken(clause) && (!query || preset.label.toLowerCase().includes(query) || preset.text.startsWith(query) || key.toLowerCase().includes(query))) {
286
+ result.push({ group: 'Conditions', label: preset.label, detail: `${key} ${value}`, clause });
287
+ }
288
+ }
289
+ }
290
+ if (query && !(typed && typed.kind !== 'path')) {
291
+ result.push({ group: 'Path', label: `Path contains “${text.trim()}”`, clause: { kind: 'path', value: text.trim() } });
292
+ }
293
+ return result;
294
+ }
295
+ function quantity(total) {
296
+ return `${total.toLocaleString()} ${total === 1 ? 'file' : 'files'}`;
297
+ }
298
+ /**
299
+ * The field: chips for the chosen clauses, then a text input; the list of suggestions hangs from it in one frame.
300
+ * Backspace in an empty input takes the last chip back into text, so a chip can be edited, not just removed.
301
+ */
302
+ export function queryField(clauses, options) {
303
+ let chosen = [...clauses];
304
+ let active = 0;
305
+ let shown = [];
306
+ const root = element('div', 'qf');
307
+ const box = element('div', 'qf-box');
308
+ const chips = element('span', 'qf-chips');
309
+ const input = element('input', 'qf-input');
310
+ input.type = 'text';
311
+ input.autocomplete = 'off';
312
+ input.spellcheck = false;
313
+ input.setAttribute('role', 'combobox');
314
+ input.setAttribute('aria-label', 'Filter files');
315
+ input.setAttribute('aria-autocomplete', 'list');
316
+ input.setAttribute('aria-expanded', 'false');
317
+ const list = element('ul', 'qf-options');
318
+ list.id = `qf-options-${Math.random().toString(36).slice(2, 8)}`;
319
+ list.setAttribute('role', 'listbox');
320
+ input.setAttribute('aria-controls', list.id);
321
+ const popover = element('div', 'qf-popover');
322
+ popover.hidden = true;
323
+ const help = element('p', 'qf-help', 'Combine chips: same kind widens, different kinds narrow. Type complexity>10 or coverage<80% for a condition.');
324
+ popover.append(list, help);
325
+ box.append(chips, input);
326
+ root.append(box, popover);
327
+ function placeholder() {
328
+ input.placeholder = chosen.length ? 'Add a filter' : 'Filter by language, component, condition or path';
329
+ }
330
+ function renderChips() {
331
+ chips.replaceChildren(...chosen.map((clause, index) => {
332
+ const chip = element('span', `qf-chip qf-chip-${clause.kind}`);
333
+ const { key, value } = clauseLabel(clause);
334
+ if (clause.kind === 'lang') {
335
+ const dot = element('span', 'qf-dot');
336
+ dot.style.background = languageColor(clause.value);
337
+ chip.append(dot);
338
+ }
339
+ chip.append(element('span', 'qf-chip-key', key), element('span', 'qf-chip-value', value));
340
+ const remove = element('button', 'qf-remove');
341
+ remove.type = 'button';
342
+ remove.setAttribute('aria-label', `Remove ${key} ${value}`);
343
+ remove.addEventListener('click', () => {
344
+ chosen.splice(index, 1);
345
+ commit();
346
+ input.focus();
347
+ });
348
+ chip.append(remove);
349
+ return chip;
350
+ }));
351
+ placeholder();
352
+ }
353
+ function commit() {
354
+ renderChips();
355
+ options.change(chosen, input.value.trim());
356
+ if (!popover.hidden)
357
+ update();
358
+ }
359
+ function update() {
360
+ shown = options.suggestions(input.value);
361
+ active = Math.min(active, Math.max(0, shown.length - 1));
362
+ let group = '';
363
+ list.replaceChildren(...shown.flatMap((suggestion, index) => {
364
+ const items = [];
365
+ if (suggestion.group !== group) {
366
+ group = suggestion.group;
367
+ const heading = element('li', 'qf-group', group);
368
+ heading.setAttribute('role', 'presentation');
369
+ items.push(heading);
370
+ }
371
+ const item = element('li', 'qf-option');
372
+ item.id = `${list.id}-${index}`;
373
+ item.setAttribute('role', 'option');
374
+ if (suggestion.color) {
375
+ const dot = element('span', 'qf-dot');
376
+ dot.style.background = suggestion.color;
377
+ item.append(dot);
378
+ }
379
+ item.append(element('span', 'qf-option-label', suggestion.label));
380
+ if (suggestion.detail)
381
+ item.append(element('span', 'qf-option-detail', suggestion.detail));
382
+ item.addEventListener('mousedown', event => event.preventDefault());
383
+ item.addEventListener('click', () => choose(suggestion));
384
+ item.addEventListener('mousemove', () => { if (active !== index) {
385
+ active = index;
386
+ highlight();
387
+ } });
388
+ items.push(item);
389
+ return items;
390
+ }));
391
+ highlight();
392
+ }
393
+ function highlight() {
394
+ for (const item of list.querySelectorAll('.qf-option'))
395
+ item.classList.toggle('active', item.id === `${list.id}-${active}`);
396
+ const current = list.querySelector(`#${list.id}-${active}`);
397
+ if (current) {
398
+ input.setAttribute('aria-activedescendant', current.id);
399
+ current.scrollIntoView({ block: 'nearest' });
400
+ }
401
+ else
402
+ input.removeAttribute('aria-activedescendant');
403
+ }
404
+ function open() {
405
+ if (!popover.hidden)
406
+ return;
407
+ popover.hidden = false;
408
+ root.classList.add('open');
409
+ input.setAttribute('aria-expanded', 'true');
410
+ active = 0;
411
+ update();
412
+ document.addEventListener('pointerdown', outside, true);
413
+ }
414
+ function close() {
415
+ if (popover.hidden)
416
+ return;
417
+ popover.hidden = true;
418
+ root.classList.remove('open');
419
+ input.setAttribute('aria-expanded', 'false');
420
+ document.removeEventListener('pointerdown', outside, true);
421
+ }
422
+ function outside(event) {
423
+ if (!root.contains(event.target))
424
+ close();
425
+ }
426
+ function choose(suggestion) {
427
+ if (!chosen.some(clause => sameClause(clause, suggestion.clause)))
428
+ chosen.push(suggestion.clause);
429
+ input.value = '';
430
+ active = 0;
431
+ commit();
432
+ }
433
+ box.addEventListener('pointerdown', event => {
434
+ if (event.target === box || event.target === chips) {
435
+ event.preventDefault();
436
+ input.focus();
437
+ }
438
+ });
439
+ input.addEventListener('focus', open);
440
+ input.addEventListener('input', () => {
441
+ open();
442
+ active = 0;
443
+ update();
444
+ options.change(chosen, input.value.trim());
445
+ });
446
+ input.addEventListener('keydown', event => {
447
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
448
+ event.preventDefault();
449
+ open();
450
+ if (shown.length)
451
+ active = (active + (event.key === 'ArrowDown' ? 1 : -1) + shown.length) % shown.length;
452
+ highlight();
453
+ }
454
+ else if (event.key === 'Enter') {
455
+ event.preventDefault();
456
+ const typed = input.value.trim();
457
+ const suggestion = shown[active];
458
+ if (suggestion && !popover.hidden)
459
+ choose(suggestion);
460
+ else if (typed)
461
+ choose({ group: '', label: typed, clause: parseWord(typed) ?? { kind: 'path', value: typed } });
462
+ }
463
+ else if (event.key === 'Escape') {
464
+ if (!popover.hidden) {
465
+ event.preventDefault();
466
+ close();
467
+ }
468
+ }
469
+ else if (event.key === 'Backspace' && input.value === '' && chosen.length) {
470
+ event.preventDefault();
471
+ input.value = clauseText(chosen.pop());
472
+ commit();
473
+ }
474
+ });
475
+ renderChips();
476
+ return {
477
+ element: root,
478
+ text: () => input.value.trim(),
479
+ set(next) {
480
+ chosen = [...next];
481
+ commit();
482
+ },
483
+ };
484
+ }
485
+ function element(tag, className, text) {
486
+ const node = document.createElement(tag);
487
+ if (className)
488
+ node.className = className;
489
+ if (text !== undefined)
490
+ node.textContent = text;
491
+ return node;
492
+ }
@@ -0,0 +1,68 @@
1
+ import type { MetricDescriptor, MetricValues } from '../../json/wire/summary-model.js';
2
+ export type { MetricDescriptor, MetricValues } from '../../json/wire/summary-model.js';
3
+ export type Direction = 'better' | 'worse' | 'same' | 'neutral';
4
+ export interface MetricSpec {
5
+ readonly descriptor: MetricDescriptor;
6
+ /** The word the query field takes and the Trends view id: `todo-count`. */
7
+ readonly key: string;
8
+ readonly plugin: string;
9
+ readonly label: string;
10
+ /** The column header. */
11
+ readonly short: string;
12
+ readonly group: string;
13
+ /** A Metrics column shown before the reader picks columns. */
14
+ readonly column: boolean;
15
+ /** Offered in the Hotspots metric menu. */
16
+ readonly hotspot: boolean;
17
+ /** Has one value per commit, so a trend chart. */
18
+ readonly trend: boolean;
19
+ }
20
+ /** A row that may carry values: a commit, a file or a folder. */
21
+ export interface Valued {
22
+ readonly values?: MetricValues | undefined;
23
+ readonly analysed?: boolean | undefined;
24
+ }
25
+ /** Curated groups first, in this order; groups named by plugins follow in catalog order. */
26
+ export declare const curatedGroups: readonly ['Maintainability', 'Coverage', 'Security', 'Size'];
27
+ /** Repometry's own metrics, which the viewer draws from their typed fields. */
28
+ export declare function isBuiltin(descriptor: MetricDescriptor): boolean;
29
+ /** One spec per descriptor, in catalog order; descriptors listed twice by id count once. */
30
+ export declare function metricSpecs(catalog: readonly MetricDescriptor[]): MetricSpec[];
31
+ /** Positions of a catalog's metrics by id: summary indexes for commits, the detail's own indexes for files. */
32
+ export declare function catalogIndex(catalog: readonly MetricDescriptor[] | undefined): Map<string, number>;
33
+ /** Specs by key, for the query field and the Trends views. Where versions share a key, the one the index holds wins. */
34
+ export declare function byKey(specs: readonly MetricSpec[], index?: ReadonlyMap<string, number>): Map<string, MetricSpec>;
35
+ /** The Trends groups: the curated ones in their order, then each plugin's, with the specs that have a trend. */
36
+ export declare function trendGroups(specs: readonly MetricSpec[]): [string, MetricSpec[]][];
37
+ /**
38
+ * The repository's value at a commit. A commit lists every metric it measured, null where nothing rolls up; a metric
39
+ * it does not list did not run, and has no value, so a chart breaks its line instead of dropping to zero.
40
+ */
41
+ export declare function commitValue(index: ReadonlyMap<string, number>, commit: Valued, spec: MetricSpec): number | null;
42
+ /**
43
+ * A file's or folder's value against the detail's own catalog. None for a file no plugin analysed, nor for a metric
44
+ * this inspection did not run. Within a measured metric a missing value is zero: zeros are left out of the data.
45
+ */
46
+ export declare function entryValue(index: ReadonlyMap<string, number>, entry: Valued, spec: MetricSpec): number | null;
47
+ /** The values of a group of files the viewer gathers itself (a filtered folder, a component), by each metric's roll-up. */
48
+ export declare function rollUp(catalog: readonly MetricDescriptor[] | undefined, entries: readonly Valued[]): MetricValues | undefined;
49
+ export declare function duration(minutes: number): string;
50
+ export declare function format(spec: MetricSpec, value: number | null): string;
51
+ /** The signed change between two values: percentage points for a ratio, coloured only where the metric has a better. */
52
+ export declare function difference(spec: MetricSpec, value: number, before: number): {
53
+ text: string;
54
+ direction: Direction;
55
+ };
56
+ /** The first click on a column sorts worst first. */
57
+ export declare function firstSortAscending(spec: MetricSpec): boolean;
58
+ /** Missing values sort last in both directions. */
59
+ export declare function compareValues(ascending: boolean): (a: number | null, b: number | null) => number;
60
+ /** The colour scale: heat where the metric has a better, so the worst is always red; neutral greys where it has none. */
61
+ export declare function bandScale(spec: MetricSpec): 'heat' | 'neutral';
62
+ /**
63
+ * One of five bands, 0 best to 4 worst. Fixed by the descriptor's limits where it has them; otherwise relative to the
64
+ * highest value shown. A metric where higher is better turns the scale round.
65
+ */
66
+ export declare function bandOf(spec: MetricSpec, value: number, highest: number): number;
67
+ /** The legend's words, best band first; null where the bands are relative and the legend reads Lower … Higher. */
68
+ export declare function bandLabels(spec: MetricSpec): string[] | null;