quiver-cli 1.3.0 → 2.0.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 (384) hide show
  1. package/README.md +197 -239
  2. package/dist/cli.js +3163 -2040
  3. package/package.json +10 -11
  4. package/template/.agents/AGENTS.md +0 -26
  5. package/template/.agents/commands/cp.md +0 -108
  6. package/template/.agents/commands/next-setup.md +0 -1064
  7. package/template/.agents/commands/review.md +0 -68
  8. package/template/.agents/commands/terraform-readme.md +0 -38
  9. package/template/.agents/config.json +0 -80
  10. package/template/.agents/plugins/opencode/rtk.ts +0 -34
  11. package/template/.agents/skills/agent-browser/SKILL.md +0 -51
  12. package/template/.agents/skills/apps/skybridge/SKILL.md +0 -50
  13. package/template/.agents/skills/code/cleanup/SKILL.md +0 -26
  14. package/template/.agents/skills/code/improve/SKILL.md +0 -122
  15. package/template/.agents/skills/code/improve/references/audit-playbook.md +0 -130
  16. package/template/.agents/skills/code/improve/references/closing-the-loop.md +0 -96
  17. package/template/.agents/skills/code/improve/references/plan-template.md +0 -197
  18. package/template/.agents/skills/code/vercel-react-best-practices/AGENTS.md +0 -3810
  19. package/template/.agents/skills/code/vercel-react-best-practices/README.md +0 -123
  20. package/template/.agents/skills/code/vercel-react-best-practices/SKILL.md +0 -149
  21. package/template/.agents/skills/code/vercel-react-best-practices/metadata.json +0 -15
  22. package/template/.agents/skills/code/vercel-react-best-practices/rules/_sections.md +0 -46
  23. package/template/.agents/skills/code/vercel-react-best-practices/rules/_template.md +0 -28
  24. package/template/.agents/skills/code/vercel-react-best-practices/rules/advanced-effect-event-deps.md +0 -56
  25. package/template/.agents/skills/code/vercel-react-best-practices/rules/advanced-event-handler-refs.md +0 -55
  26. package/template/.agents/skills/code/vercel-react-best-practices/rules/advanced-init-once.md +0 -42
  27. package/template/.agents/skills/code/vercel-react-best-practices/rules/advanced-use-latest.md +0 -39
  28. package/template/.agents/skills/code/vercel-react-best-practices/rules/async-api-routes.md +0 -38
  29. package/template/.agents/skills/code/vercel-react-best-practices/rules/async-cheap-condition-before-await.md +0 -37
  30. package/template/.agents/skills/code/vercel-react-best-practices/rules/async-defer-await.md +0 -82
  31. package/template/.agents/skills/code/vercel-react-best-practices/rules/async-dependencies.md +0 -51
  32. package/template/.agents/skills/code/vercel-react-best-practices/rules/async-parallel.md +0 -28
  33. package/template/.agents/skills/code/vercel-react-best-practices/rules/async-suspense-boundaries.md +0 -99
  34. package/template/.agents/skills/code/vercel-react-best-practices/rules/bundle-analyzable-paths.md +0 -63
  35. package/template/.agents/skills/code/vercel-react-best-practices/rules/bundle-barrel-imports.md +0 -60
  36. package/template/.agents/skills/code/vercel-react-best-practices/rules/bundle-conditional.md +0 -31
  37. package/template/.agents/skills/code/vercel-react-best-practices/rules/bundle-defer-third-party.md +0 -49
  38. package/template/.agents/skills/code/vercel-react-best-practices/rules/bundle-dynamic-imports.md +0 -35
  39. package/template/.agents/skills/code/vercel-react-best-practices/rules/bundle-preload.md +0 -50
  40. package/template/.agents/skills/code/vercel-react-best-practices/rules/client-event-listeners.md +0 -74
  41. package/template/.agents/skills/code/vercel-react-best-practices/rules/client-localstorage-schema.md +0 -71
  42. package/template/.agents/skills/code/vercel-react-best-practices/rules/client-passive-event-listeners.md +0 -48
  43. package/template/.agents/skills/code/vercel-react-best-practices/rules/client-swr-dedup.md +0 -56
  44. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-batch-dom-css.md +0 -107
  45. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-cache-function-results.md +0 -80
  46. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-cache-property-access.md +0 -28
  47. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-cache-storage.md +0 -70
  48. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-combine-iterations.md +0 -32
  49. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-early-exit.md +0 -50
  50. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-flatmap-filter.md +0 -60
  51. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-hoist-regexp.md +0 -45
  52. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-index-maps.md +0 -37
  53. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-length-check-first.md +0 -49
  54. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-min-max-loop.md +0 -82
  55. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-request-idle-callback.md +0 -105
  56. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-set-map-lookups.md +0 -24
  57. package/template/.agents/skills/code/vercel-react-best-practices/rules/js-tosorted-immutable.md +0 -57
  58. package/template/.agents/skills/code/vercel-react-best-practices/rules/rendering-activity.md +0 -26
  59. package/template/.agents/skills/code/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +0 -47
  60. package/template/.agents/skills/code/vercel-react-best-practices/rules/rendering-conditional-render.md +0 -40
  61. package/template/.agents/skills/code/vercel-react-best-practices/rules/rendering-content-visibility.md +0 -38
  62. package/template/.agents/skills/code/vercel-react-best-practices/rules/rendering-hoist-jsx.md +0 -46
  63. package/template/.agents/skills/code/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +0 -82
  64. package/template/.agents/skills/code/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +0 -30
  65. package/template/.agents/skills/code/vercel-react-best-practices/rules/rendering-resource-hints.md +0 -85
  66. package/template/.agents/skills/code/vercel-react-best-practices/rules/rendering-script-defer-async.md +0 -68
  67. package/template/.agents/skills/code/vercel-react-best-practices/rules/rendering-svg-precision.md +0 -28
  68. package/template/.agents/skills/code/vercel-react-best-practices/rules/rendering-usetransition-loading.md +0 -75
  69. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-defer-reads.md +0 -39
  70. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-dependencies.md +0 -45
  71. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +0 -40
  72. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-derived-state.md +0 -29
  73. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-functional-setstate.md +0 -74
  74. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-lazy-state-init.md +0 -58
  75. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +0 -38
  76. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-memo.md +0 -44
  77. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +0 -45
  78. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-no-inline-components.md +0 -82
  79. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +0 -35
  80. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-split-combined-hooks.md +0 -64
  81. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-transitions.md +0 -40
  82. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-use-deferred-value.md +0 -59
  83. package/template/.agents/skills/code/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +0 -73
  84. package/template/.agents/skills/code/vercel-react-best-practices/rules/server-after-nonblocking.md +0 -73
  85. package/template/.agents/skills/code/vercel-react-best-practices/rules/server-auth-actions.md +0 -96
  86. package/template/.agents/skills/code/vercel-react-best-practices/rules/server-cache-lru.md +0 -41
  87. package/template/.agents/skills/code/vercel-react-best-practices/rules/server-cache-react.md +0 -76
  88. package/template/.agents/skills/code/vercel-react-best-practices/rules/server-dedup-props.md +0 -65
  89. package/template/.agents/skills/code/vercel-react-best-practices/rules/server-hoist-static-io.md +0 -149
  90. package/template/.agents/skills/code/vercel-react-best-practices/rules/server-no-shared-module-state.md +0 -50
  91. package/template/.agents/skills/code/vercel-react-best-practices/rules/server-parallel-fetching.md +0 -83
  92. package/template/.agents/skills/code/vercel-react-best-practices/rules/server-parallel-nested-fetching.md +0 -34
  93. package/template/.agents/skills/code/vercel-react-best-practices/rules/server-serialization.md +0 -38
  94. package/template/.agents/skills/data/prisma-cli/SKILL.md +0 -247
  95. package/template/.agents/skills/data/prisma-cli/references/db-execute.md +0 -78
  96. package/template/.agents/skills/data/prisma-cli/references/db-pull.md +0 -185
  97. package/template/.agents/skills/data/prisma-cli/references/db-push.md +0 -148
  98. package/template/.agents/skills/data/prisma-cli/references/db-seed.md +0 -188
  99. package/template/.agents/skills/data/prisma-cli/references/debug.md +0 -46
  100. package/template/.agents/skills/data/prisma-cli/references/dev.md +0 -157
  101. package/template/.agents/skills/data/prisma-cli/references/format.md +0 -48
  102. package/template/.agents/skills/data/prisma-cli/references/generate.md +0 -173
  103. package/template/.agents/skills/data/prisma-cli/references/init.md +0 -136
  104. package/template/.agents/skills/data/prisma-cli/references/mcp.md +0 -38
  105. package/template/.agents/skills/data/prisma-cli/references/migrate-deploy.md +0 -127
  106. package/template/.agents/skills/data/prisma-cli/references/migrate-dev.md +0 -145
  107. package/template/.agents/skills/data/prisma-cli/references/migrate-diff.md +0 -89
  108. package/template/.agents/skills/data/prisma-cli/references/migrate-reset.md +0 -78
  109. package/template/.agents/skills/data/prisma-cli/references/migrate-resolve.md +0 -57
  110. package/template/.agents/skills/data/prisma-cli/references/migrate-status.md +0 -65
  111. package/template/.agents/skills/data/prisma-cli/references/studio.md +0 -137
  112. package/template/.agents/skills/data/prisma-cli/references/validate.md +0 -53
  113. package/template/.agents/skills/data/prisma-client-api/SKILL.md +0 -216
  114. package/template/.agents/skills/data/prisma-client-api/references/client-methods.md +0 -223
  115. package/template/.agents/skills/data/prisma-client-api/references/constructor.md +0 -208
  116. package/template/.agents/skills/data/prisma-client-api/references/filters.md +0 -256
  117. package/template/.agents/skills/data/prisma-client-api/references/model-queries.md +0 -281
  118. package/template/.agents/skills/data/prisma-client-api/references/query-options.md +0 -276
  119. package/template/.agents/skills/data/prisma-client-api/references/raw-queries.md +0 -194
  120. package/template/.agents/skills/data/prisma-client-api/references/relations.md +0 -308
  121. package/template/.agents/skills/data/prisma-client-api/references/transactions.md +0 -184
  122. package/template/.agents/skills/design/impeccable/SKILL.md +0 -84
  123. package/template/.agents/skills/design/impeccable/reference/adapt.md +0 -312
  124. package/template/.agents/skills/design/impeccable/reference/adapt.native.md +0 -58
  125. package/template/.agents/skills/design/impeccable/reference/android.md +0 -40
  126. package/template/.agents/skills/design/impeccable/reference/animate.md +0 -86
  127. package/template/.agents/skills/design/impeccable/reference/audit.md +0 -136
  128. package/template/.agents/skills/design/impeccable/reference/audit.native.md +0 -139
  129. package/template/.agents/skills/design/impeccable/reference/bolder.md +0 -31
  130. package/template/.agents/skills/design/impeccable/reference/clarify.md +0 -94
  131. package/template/.agents/skills/design/impeccable/reference/colorize.md +0 -86
  132. package/template/.agents/skills/design/impeccable/reference/craft-floor.md +0 -42
  133. package/template/.agents/skills/design/impeccable/reference/craft.md +0 -5
  134. package/template/.agents/skills/design/impeccable/reference/critique.md +0 -788
  135. package/template/.agents/skills/design/impeccable/reference/degraded/asset-producer.md +0 -90
  136. package/template/.agents/skills/design/impeccable/reference/degraded/documenter.md +0 -24
  137. package/template/.agents/skills/design/impeccable/reference/degraded/finish-reviewer.md +0 -37
  138. package/template/.agents/skills/design/impeccable/reference/degraded/manual-edit-applier.md +0 -92
  139. package/template/.agents/skills/design/impeccable/reference/delight.md +0 -70
  140. package/template/.agents/skills/design/impeccable/reference/distill.md +0 -111
  141. package/template/.agents/skills/design/impeccable/reference/doctor.md +0 -53
  142. package/template/.agents/skills/design/impeccable/reference/document.md +0 -416
  143. package/template/.agents/skills/design/impeccable/reference/extract.md +0 -69
  144. package/template/.agents/skills/design/impeccable/reference/harden.md +0 -336
  145. package/template/.agents/skills/design/impeccable/reference/hooks.md +0 -105
  146. package/template/.agents/skills/design/impeccable/reference/init.md +0 -125
  147. package/template/.agents/skills/design/impeccable/reference/ios.md +0 -45
  148. package/template/.agents/skills/design/impeccable/reference/layout.md +0 -84
  149. package/template/.agents/skills/design/impeccable/reference/live-setup.md +0 -102
  150. package/template/.agents/skills/design/impeccable/reference/live.md +0 -323
  151. package/template/.agents/skills/design/impeccable/reference/new-work.md +0 -105
  152. package/template/.agents/skills/design/impeccable/reference/onboard.md +0 -234
  153. package/template/.agents/skills/design/impeccable/reference/operate.md +0 -61
  154. package/template/.agents/skills/design/impeccable/reference/optimize.md +0 -258
  155. package/template/.agents/skills/design/impeccable/reference/overdrive.md +0 -127
  156. package/template/.agents/skills/design/impeccable/reference/polish.md +0 -97
  157. package/template/.agents/skills/design/impeccable/reference/quieter.md +0 -99
  158. package/template/.agents/skills/design/impeccable/reference/routing.md +0 -18
  159. package/template/.agents/skills/design/impeccable/reference/shape.md +0 -59
  160. package/template/.agents/skills/design/impeccable/reference/typeset.md +0 -80
  161. package/template/.agents/skills/design/impeccable/reference/visualize.md +0 -47
  162. package/template/.agents/skills/design/impeccable/scripts/command-metadata.json +0 -94
  163. package/template/.agents/skills/design/impeccable/scripts/concept-seed.mjs +0 -558
  164. package/template/.agents/skills/design/impeccable/scripts/context-signals.mjs +0 -334
  165. package/template/.agents/skills/design/impeccable/scripts/context.mjs +0 -1450
  166. package/template/.agents/skills/design/impeccable/scripts/critique-storage.mjs +0 -213
  167. package/template/.agents/skills/design/impeccable/scripts/detect-csp.mjs +0 -198
  168. package/template/.agents/skills/design/impeccable/scripts/detect.mjs +0 -21
  169. package/template/.agents/skills/design/impeccable/scripts/detector/browser/injected/index.mjs +0 -2023
  170. package/template/.agents/skills/design/impeccable/scripts/detector/cli/main.mjs +0 -438
  171. package/template/.agents/skills/design/impeccable/scripts/detector/design-system.mjs +0 -983
  172. package/template/.agents/skills/design/impeccable/scripts/detector/detect-antipatterns-browser.js +0 -8283
  173. package/template/.agents/skills/design/impeccable/scripts/detector/detect-antipatterns.mjs +0 -50
  174. package/template/.agents/skills/design/impeccable/scripts/detector/engines/browser/detect-url.mjs +0 -372
  175. package/template/.agents/skills/design/impeccable/scripts/detector/engines/regex/detect-text.mjs +0 -768
  176. package/template/.agents/skills/design/impeccable/scripts/detector/engines/static-html/css-cascade.mjs +0 -1186
  177. package/template/.agents/skills/design/impeccable/scripts/detector/engines/static-html/detect-html.mjs +0 -264
  178. package/template/.agents/skills/design/impeccable/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -189
  179. package/template/.agents/skills/design/impeccable/scripts/detector/findings.mjs +0 -18
  180. package/template/.agents/skills/design/impeccable/scripts/detector/node/file-system.mjs +0 -212
  181. package/template/.agents/skills/design/impeccable/scripts/detector/profile/profiler.mjs +0 -166
  182. package/template/.agents/skills/design/impeccable/scripts/detector/registry/antipatterns.mjs +0 -617
  183. package/template/.agents/skills/design/impeccable/scripts/detector/rules/checks.mjs +0 -5580
  184. package/template/.agents/skills/design/impeccable/scripts/detector/shared/color.mjs +0 -124
  185. package/template/.agents/skills/design/impeccable/scripts/detector/shared/constants.mjs +0 -112
  186. package/template/.agents/skills/design/impeccable/scripts/detector/shared/fonts.mjs +0 -30
  187. package/template/.agents/skills/design/impeccable/scripts/detector/shared/inline-ignores.mjs +0 -148
  188. package/template/.agents/skills/design/impeccable/scripts/detector/shared/page.mjs +0 -7
  189. package/template/.agents/skills/design/impeccable/scripts/doctor.mjs +0 -336
  190. package/template/.agents/skills/design/impeccable/scripts/embed-prompt.mjs +0 -133
  191. package/template/.agents/skills/design/impeccable/scripts/generate-image.mjs +0 -240
  192. package/template/.agents/skills/design/impeccable/scripts/hook-admin.mjs +0 -741
  193. package/template/.agents/skills/design/impeccable/scripts/hook-before-edit.mjs +0 -516
  194. package/template/.agents/skills/design/impeccable/scripts/hook-lib.mjs +0 -2100
  195. package/template/.agents/skills/design/impeccable/scripts/hook.mjs +0 -78
  196. package/template/.agents/skills/design/impeccable/scripts/lib/artifact-schema.mjs +0 -93
  197. package/template/.agents/skills/design/impeccable/scripts/lib/composition-catalog.mjs +0 -200
  198. package/template/.agents/skills/design/impeccable/scripts/lib/concept-catalog.mjs +0 -357
  199. package/template/.agents/skills/design/impeccable/scripts/lib/design-parser.mjs +0 -842
  200. package/template/.agents/skills/design/impeccable/scripts/lib/impeccable-config.mjs +0 -658
  201. package/template/.agents/skills/design/impeccable/scripts/lib/impeccable-paths.mjs +0 -137
  202. package/template/.agents/skills/design/impeccable/scripts/lib/is-generated.mjs +0 -69
  203. package/template/.agents/skills/design/impeccable/scripts/lib/provider.mjs +0 -5
  204. package/template/.agents/skills/design/impeccable/scripts/lib/roll-selection.mjs +0 -362
  205. package/template/.agents/skills/design/impeccable/scripts/lib/staleness-deep.mjs +0 -457
  206. package/template/.agents/skills/design/impeccable/scripts/lib/staleness-notice.mjs +0 -169
  207. package/template/.agents/skills/design/impeccable/scripts/lib/staleness.mjs +0 -457
  208. package/template/.agents/skills/design/impeccable/scripts/lib/surface-briefs.mjs +0 -151
  209. package/template/.agents/skills/design/impeccable/scripts/lib/target-args.mjs +0 -42
  210. package/template/.agents/skills/design/impeccable/scripts/lib/target-slug.mjs +0 -33
  211. package/template/.agents/skills/design/impeccable/scripts/lib/template-extensions.mjs +0 -146
  212. package/template/.agents/skills/design/impeccable/scripts/live/accept-css.mjs +0 -617
  213. package/template/.agents/skills/design/impeccable/scripts/live/accept-verify.mjs +0 -60
  214. package/template/.agents/skills/design/impeccable/scripts/live/browser-script-parts.mjs +0 -55
  215. package/template/.agents/skills/design/impeccable/scripts/live/completion.mjs +0 -28
  216. package/template/.agents/skills/design/impeccable/scripts/live/event-validation.mjs +0 -199
  217. package/template/.agents/skills/design/impeccable/scripts/live/frameworks/astro.mjs +0 -47
  218. package/template/.agents/skills/design/impeccable/scripts/live/frameworks/detect-utils.mjs +0 -73
  219. package/template/.agents/skills/design/impeccable/scripts/live/frameworks/index.mjs +0 -143
  220. package/template/.agents/skills/design/impeccable/scripts/live/frameworks/journal.mjs +0 -197
  221. package/template/.agents/skills/design/impeccable/scripts/live/frameworks/nextjs.mjs +0 -49
  222. package/template/.agents/skills/design/impeccable/scripts/live/frameworks/nuxt.mjs +0 -161
  223. package/template/.agents/skills/design/impeccable/scripts/live/frameworks/script-src.mjs +0 -17
  224. package/template/.agents/skills/design/impeccable/scripts/live/frameworks/static-html.mjs +0 -26
  225. package/template/.agents/skills/design/impeccable/scripts/live/frameworks/sveltekit.mjs +0 -71
  226. package/template/.agents/skills/design/impeccable/scripts/live/frameworks/tag-strategy.mjs +0 -247
  227. package/template/.agents/skills/design/impeccable/scripts/live/frameworks/tanstack-start.mjs +0 -70
  228. package/template/.agents/skills/design/impeccable/scripts/live/frameworks/vite-generic.mjs +0 -42
  229. package/template/.agents/skills/design/impeccable/scripts/live/generation-preflight.mjs +0 -149
  230. package/template/.agents/skills/design/impeccable/scripts/live/insert-ui.mjs +0 -458
  231. package/template/.agents/skills/design/impeccable/scripts/live/instructions.mjs +0 -142
  232. package/template/.agents/skills/design/impeccable/scripts/live/manual-apply.mjs +0 -939
  233. package/template/.agents/skills/design/impeccable/scripts/live/manual-edit-routes.mjs +0 -357
  234. package/template/.agents/skills/design/impeccable/scripts/live/manual-edits-buffer.mjs +0 -152
  235. package/template/.agents/skills/design/impeccable/scripts/live/poll-lanes.mjs +0 -14
  236. package/template/.agents/skills/design/impeccable/scripts/live/roots.mjs +0 -508
  237. package/template/.agents/skills/design/impeccable/scripts/live/session-store.mjs +0 -563
  238. package/template/.agents/skills/design/impeccable/scripts/live/source-lock.mjs +0 -105
  239. package/template/.agents/skills/design/impeccable/scripts/live/source-search.mjs +0 -105
  240. package/template/.agents/skills/design/impeccable/scripts/live/svelte-ast.mjs +0 -961
  241. package/template/.agents/skills/design/impeccable/scripts/live/svelte-component.mjs +0 -1342
  242. package/template/.agents/skills/design/impeccable/scripts/live/sveltekit-adapter.mjs +0 -316
  243. package/template/.agents/skills/design/impeccable/scripts/live/tanstack-adapter.mjs +0 -280
  244. package/template/.agents/skills/design/impeccable/scripts/live/ui-core.mjs +0 -180
  245. package/template/.agents/skills/design/impeccable/scripts/live/vocabulary.mjs +0 -171
  246. package/template/.agents/skills/design/impeccable/scripts/live-accept.mjs +0 -954
  247. package/template/.agents/skills/design/impeccable/scripts/live-browser-dom.js +0 -146
  248. package/template/.agents/skills/design/impeccable/scripts/live-browser-session.js +0 -123
  249. package/template/.agents/skills/design/impeccable/scripts/live-browser.js +0 -12512
  250. package/template/.agents/skills/design/impeccable/scripts/live-commit-manual-edits.mjs +0 -1244
  251. package/template/.agents/skills/design/impeccable/scripts/live-complete.mjs +0 -107
  252. package/template/.agents/skills/design/impeccable/scripts/live-copy-edit-agent.mjs +0 -683
  253. package/template/.agents/skills/design/impeccable/scripts/live-discard-manual-edits.mjs +0 -51
  254. package/template/.agents/skills/design/impeccable/scripts/live-inject.mjs +0 -503
  255. package/template/.agents/skills/design/impeccable/scripts/live-insert.mjs +0 -292
  256. package/template/.agents/skills/design/impeccable/scripts/live-manual-edit-evidence.mjs +0 -368
  257. package/template/.agents/skills/design/impeccable/scripts/live-poll.mjs +0 -429
  258. package/template/.agents/skills/design/impeccable/scripts/live-resume.mjs +0 -123
  259. package/template/.agents/skills/design/impeccable/scripts/live-server.mjs +0 -1661
  260. package/template/.agents/skills/design/impeccable/scripts/live-status.mjs +0 -71
  261. package/template/.agents/skills/design/impeccable/scripts/live-target.mjs +0 -30
  262. package/template/.agents/skills/design/impeccable/scripts/live-wrap.mjs +0 -927
  263. package/template/.agents/skills/design/impeccable/scripts/live.mjs +0 -359
  264. package/template/.agents/skills/design/impeccable/scripts/modern-screenshot.umd.js +0 -14
  265. package/template/.agents/skills/design/impeccable/scripts/palette.mjs +0 -628
  266. package/template/.agents/skills/design/impeccable/scripts/pin.mjs +0 -221
  267. package/template/.agents/skills/design/impeccable/scripts/serve-question.mjs +0 -932
  268. package/template/.agents/skills/design/impeccable/scripts/surface-brief.mjs +0 -74
  269. package/template/.agents/skills/design/shadcn/SKILL.md +0 -277
  270. package/template/.agents/skills/design/shadcn/agents/openai.yml +0 -5
  271. package/template/.agents/skills/design/shadcn/assets/shadcn-small.png +0 -0
  272. package/template/.agents/skills/design/shadcn/assets/shadcn.png +0 -0
  273. package/template/.agents/skills/design/shadcn/cli.md +0 -290
  274. package/template/.agents/skills/design/shadcn/customization.md +0 -209
  275. package/template/.agents/skills/design/shadcn/evals/evals.json +0 -77
  276. package/template/.agents/skills/design/shadcn/mcp.md +0 -105
  277. package/template/.agents/skills/design/shadcn/registry.md +0 -277
  278. package/template/.agents/skills/design/shadcn/rules/base-vs-radix.md +0 -306
  279. package/template/.agents/skills/design/shadcn/rules/chat.md +0 -224
  280. package/template/.agents/skills/design/shadcn/rules/composition.md +0 -213
  281. package/template/.agents/skills/design/shadcn/rules/forms.md +0 -192
  282. package/template/.agents/skills/design/shadcn/rules/icons.md +0 -101
  283. package/template/.agents/skills/design/shadcn/rules/styling.md +0 -185
  284. package/template/.agents/skills/find-skills/SKILL.md +0 -141
  285. package/template/.agents/skills/hono/SKILL.md +0 -579
  286. package/template/.agents/skills/integrations/langfuse/SKILL.md +0 -146
  287. package/template/.agents/skills/integrations/langfuse/references/ci-cd.md +0 -41
  288. package/template/.agents/skills/integrations/langfuse/references/cli.md +0 -60
  289. package/template/.agents/skills/integrations/langfuse/references/error-analysis.md +0 -88
  290. package/template/.agents/skills/integrations/langfuse/references/instrumentation.md +0 -121
  291. package/template/.agents/skills/integrations/langfuse/references/judge-calibration.md +0 -291
  292. package/template/.agents/skills/integrations/langfuse/references/prompt-engineering.md +0 -35
  293. package/template/.agents/skills/integrations/langfuse/references/prompt-migration.md +0 -79
  294. package/template/.agents/skills/integrations/langfuse/references/skill-feedback.md +0 -55
  295. package/template/.agents/skills/integrations/langfuse/references/trace-evaluator-upgrade.md +0 -76
  296. package/template/.agents/skills/integrations/langfuse/references/user-feedback.md +0 -92
  297. package/template/.agents/skills/integrations/langfuse/references/v4-project-migration.md +0 -73
  298. package/template/.agents/skills/integrations/posthog/SKILL.md +0 -102
  299. package/template/.agents/skills/integrations/posthog/references/error-tracking-alerts.md +0 -63
  300. package/template/.agents/skills/integrations/posthog/references/error-tracking-assigning-issues.md +0 -77
  301. package/template/.agents/skills/integrations/posthog/references/error-tracking-fingerprints.md +0 -57
  302. package/template/.agents/skills/integrations/posthog/references/error-tracking-monitoring.md +0 -140
  303. package/template/.agents/skills/integrations/posthog/references/error-tracking-nextjs.md +0 -490
  304. package/template/.agents/skills/integrations/posthog/references/error-tracking-source-maps.md +0 -45
  305. package/template/.agents/skills/integrations/posthog/references/feature-flags-best-practices.md +0 -139
  306. package/template/.agents/skills/integrations/posthog/references/feature-flags-react.md +0 -302
  307. package/template/.agents/skills/integrations/posthog/references/identify-users.md +0 -202
  308. package/template/.agents/skills/integrations/posthog/references/integration-example.md +0 -706
  309. package/template/.agents/skills/integrations/posthog/references/integration-nextjs.md +0 -385
  310. package/template/.agents/skills/integrations/posthog/references/integration-step-1-begin.md +0 -43
  311. package/template/.agents/skills/integrations/posthog/references/integration-step-2-edit.md +0 -37
  312. package/template/.agents/skills/integrations/posthog/references/integration-step-3-revise.md +0 -22
  313. package/template/.agents/skills/integrations/posthog/references/integration-step-4-conclude.md +0 -38
  314. package/template/.agents/skills/integrations/posthog/references/llm-analytics-anthropic.md +0 -200
  315. package/template/.agents/skills/integrations/posthog/references/llm-analytics-basics.md +0 -62
  316. package/template/.agents/skills/integrations/posthog/references/llm-analytics-costs.md +0 -197
  317. package/template/.agents/skills/integrations/posthog/references/llm-analytics-manual-capture.md +0 -397
  318. package/template/.agents/skills/integrations/posthog/references/llm-analytics-traces.md +0 -98
  319. package/template/.agents/skills/integrations/posthog/references/llm-analytics-vercel-ai.md +0 -120
  320. package/template/.agents/skills/repo/repo-ci/SKILL.md +0 -265
  321. package/template/.agents/skills/repo/repo-init-next-js/SKILL.md +0 -129
  322. package/template/.agents/skills/repo/repo-init-next-js/references/file-contents.md +0 -800
  323. package/template/.agents/skills/repo/repo-init-next-js/scripts/setup.sh +0 -47
  324. package/template/.agents/skills/repo/repo-init-node/SKILL.md +0 -196
  325. package/template/.agents/skills/skill-creator/LICENSE.txt +0 -202
  326. package/template/.agents/skills/skill-creator/SKILL.md +0 -485
  327. package/template/.agents/skills/skill-creator/agents/analyzer.md +0 -274
  328. package/template/.agents/skills/skill-creator/agents/comparator.md +0 -202
  329. package/template/.agents/skills/skill-creator/agents/grader.md +0 -223
  330. package/template/.agents/skills/skill-creator/assets/eval_review.html +0 -146
  331. package/template/.agents/skills/skill-creator/eval-viewer/generate_review.py +0 -471
  332. package/template/.agents/skills/skill-creator/eval-viewer/viewer.html +0 -1325
  333. package/template/.agents/skills/skill-creator/references/schemas.md +0 -430
  334. package/template/.agents/skills/skill-creator/scripts/__init__.py +0 -0
  335. package/template/.agents/skills/skill-creator/scripts/aggregate_benchmark.py +0 -401
  336. package/template/.agents/skills/skill-creator/scripts/generate_report.py +0 -326
  337. package/template/.agents/skills/skill-creator/scripts/improve_description.py +0 -247
  338. package/template/.agents/skills/skill-creator/scripts/package_skill.py +0 -136
  339. package/template/.agents/skills/skill-creator/scripts/quick_validate.py +0 -103
  340. package/template/.agents/skills/skill-creator/scripts/run_eval.py +0 -310
  341. package/template/.agents/skills/skill-creator/scripts/run_loop.py +0 -328
  342. package/template/.agents/skills/skill-creator/scripts/utils.py +0 -47
  343. package/template/.agents/skills/supabase/CHANGELOG.md +0 -71
  344. package/template/.agents/skills/supabase/SKILL.md +0 -145
  345. package/template/.agents/skills/supabase/assets/feedback-issue-template.md +0 -17
  346. package/template/.agents/skills/supabase/references/skill-feedback.md +0 -17
  347. package/template/.agents/skills/supabase-postgres-best-practices/CHANGELOG.md +0 -73
  348. package/template/.agents/skills/supabase-postgres-best-practices/SKILL.md +0 -64
  349. package/template/.agents/skills/supabase-postgres-best-practices/references/_contributing.md +0 -170
  350. package/template/.agents/skills/supabase-postgres-best-practices/references/_sections.md +0 -39
  351. package/template/.agents/skills/supabase-postgres-best-practices/references/_template.md +0 -34
  352. package/template/.agents/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +0 -55
  353. package/template/.agents/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +0 -49
  354. package/template/.agents/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +0 -46
  355. package/template/.agents/skills/supabase-postgres-best-practices/references/conn-limits.md +0 -44
  356. package/template/.agents/skills/supabase-postgres-best-practices/references/conn-pooling.md +0 -41
  357. package/template/.agents/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +0 -46
  358. package/template/.agents/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +0 -54
  359. package/template/.agents/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +0 -53
  360. package/template/.agents/skills/supabase-postgres-best-practices/references/data-pagination.md +0 -50
  361. package/template/.agents/skills/supabase-postgres-best-practices/references/data-upsert.md +0 -50
  362. package/template/.agents/skills/supabase-postgres-best-practices/references/lock-advisory.md +0 -56
  363. package/template/.agents/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +0 -68
  364. package/template/.agents/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +0 -50
  365. package/template/.agents/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +0 -54
  366. package/template/.agents/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +0 -45
  367. package/template/.agents/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +0 -55
  368. package/template/.agents/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +0 -55
  369. package/template/.agents/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +0 -44
  370. package/template/.agents/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +0 -40
  371. package/template/.agents/skills/supabase-postgres-best-practices/references/query-index-types.md +0 -48
  372. package/template/.agents/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +0 -43
  373. package/template/.agents/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +0 -45
  374. package/template/.agents/skills/supabase-postgres-best-practices/references/schema-constraints.md +0 -80
  375. package/template/.agents/skills/supabase-postgres-best-practices/references/schema-data-types.md +0 -46
  376. package/template/.agents/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +0 -59
  377. package/template/.agents/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +0 -55
  378. package/template/.agents/skills/supabase-postgres-best-practices/references/schema-partitioning.md +0 -55
  379. package/template/.agents/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +0 -61
  380. package/template/.agents/skills/supabase-postgres-best-practices/references/security-privileges.md +0 -54
  381. package/template/.agents/skills/supabase-postgres-best-practices/references/security-rls-basics.md +0 -50
  382. package/template/.agents/skills/supabase-postgres-best-practices/references/security-rls-performance.md +0 -63
  383. package/template/.agents/skills/writing/humanizer/SKILL.md +0 -621
  384. package/template/.agents/upstreams.json +0 -116
@@ -1,2023 +0,0 @@
1
- const IS_BROWSER = typeof window !== 'undefined';
2
-
3
- // ─── Section 7: Browser UI (IS_BROWSER only) ────────────────────────────────
4
-
5
- if (IS_BROWSER) {
6
- // Detect extension mode via the script tag's data attribute or the document element fallback.
7
- // currentScript is reliable for synchronously-executing scripts (which our IIFE is).
8
- const _myScript = document.currentScript;
9
- const EXTENSION_MODE = (_myScript && _myScript.dataset.impeccableExtension === 'true')
10
- || document.documentElement.dataset.impeccableExtension === 'true';
11
-
12
- // Kinpaku gold — pinned to the site's brand token (see
13
- // site/styles/kinpaku-tokens.css --ks-kinpaku). Keep this in sync with
14
- // the picker's C.brand in skill/scripts/live-browser.js and the kit's
15
- // picker section in site/styles/kinpaku-kit.css.
16
- //
17
- // One color across both light and dark host pages. The outline is a
18
- // 2px gesture pointing at an element + a labeled tag — it's a marker,
19
- // not body text, so it doesn't need WCAG AA against the page. The
20
- // label text inside the gold tag is dark (LABEL_INK) which has ~16:1
21
- // against the leaf gold, so reading the rule name is solid in both
22
- // modes. Hover deepens the gold (preserves chroma — never drops it,
23
- // dropping chroma washes the gold into a sand/olive tone).
24
- const BRAND_COLOR = 'oklch(84% 0.19 80.46)';
25
- const BRAND_COLOR_HOVER = 'oklch(74% 0.18 80)';
26
- const LABEL_INK = 'oklch(4% 0.004 95)';
27
- const LABEL_BG = BRAND_COLOR;
28
- const OUTLINE_COLOR = BRAND_COLOR;
29
-
30
- // Inject hover styles via CSS (more reliable than JS event listeners)
31
- const styleEl = document.createElement('style');
32
- styleEl.textContent = `
33
- @keyframes impeccable-reveal {
34
- from { opacity: 0; }
35
- to { opacity: 1; }
36
- }
37
- .impeccable-overlay:not(.impeccable-banner) {
38
- pointer-events: none;
39
- outline: 2px solid ${OUTLINE_COLOR};
40
- border-radius: 4px;
41
- transition: outline-color 0.15s ease;
42
- animation: impeccable-reveal 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
43
- animation-play-state: paused;
44
- border-top-left-radius: 0;
45
- }
46
- .impeccable-overlay.impeccable-visible {
47
- animation-play-state: running;
48
- }
49
- .impeccable-overlay.impeccable-hover {
50
- outline-color: ${BRAND_COLOR_HOVER};
51
- z-index: 100001 !important;
52
- }
53
- .impeccable-overlay.impeccable-hover .impeccable-label {
54
- background: ${BRAND_COLOR_HOVER};
55
- }
56
- .impeccable-overlay.impeccable-spotlight {
57
- z-index: 100002 !important;
58
- }
59
- .impeccable-overlay.impeccable-spotlight-dimmed {
60
- opacity: 0.15 !important;
61
- animation: none !important;
62
- filter: blur(3px);
63
- }
64
- .impeccable-spotlight-backdrop {
65
- position: fixed;
66
- top: 0; left: 0; right: 0; bottom: 0;
67
- backdrop-filter: blur(3px) brightness(0.6);
68
- -webkit-backdrop-filter: blur(3px) brightness(0.6);
69
- pointer-events: none;
70
- z-index: 99998;
71
- opacity: 0;
72
- outline: none !important;
73
- animation: none !important;
74
- }
75
- .impeccable-spotlight-backdrop.impeccable-visible {
76
- opacity: 1;
77
- }
78
- .impeccable-hidden .impeccable-overlay${EXTENSION_MODE ? '' : ':not(.impeccable-banner)'} {
79
- display: none !important;
80
- }
81
- `;
82
- (document.head || document.documentElement).appendChild(styleEl);
83
-
84
- // Spotlight backdrop element (created lazily on first use)
85
- let spotlightBackdrop = null;
86
- let spotlightTarget = null;
87
-
88
- function getSpotlightBackdrop() {
89
- if (!spotlightBackdrop) {
90
- spotlightBackdrop = document.createElement('div');
91
- spotlightBackdrop.className = 'impeccable-spotlight-backdrop';
92
- document.body.appendChild(spotlightBackdrop);
93
- }
94
- return spotlightBackdrop;
95
- }
96
-
97
- function updateSpotlightClipPath() {
98
- if (!spotlightBackdrop || !spotlightTarget) return;
99
- const r = spotlightTarget.getBoundingClientRect();
100
- // Match the overlay's outer edge: element rect + 4px (2px overlay offset + 2px outline width)
101
- const inset = 4;
102
- const radius = 6; // outline border-radius (4) + outline width (2)
103
- const x1 = r.left - inset;
104
- const y1 = r.top - inset;
105
- const x2 = r.right + inset;
106
- const y2 = r.bottom + inset;
107
- const vw = window.innerWidth;
108
- const vh = window.innerHeight;
109
- // Outer rect + rounded inner rect (evenodd creates a hole)
110
- const path = `M0 0H${vw}V${vh}H0Z M${x1 + radius} ${y1}H${x2 - radius}A${radius} ${radius} 0 0 1 ${x2} ${y1 + radius}V${y2 - radius}A${radius} ${radius} 0 0 1 ${x2 - radius} ${y2}H${x1 + radius}A${radius} ${radius} 0 0 1 ${x1} ${y2 - radius}V${y1 + radius}A${radius} ${radius} 0 0 1 ${x1 + radius} ${y1}Z`;
111
- spotlightBackdrop.style.clipPath = `path(evenodd, "${path}")`;
112
- }
113
-
114
- function showSpotlight(target) {
115
- if (!target || !target.getBoundingClientRect) return;
116
- // Respect the spotlightBlur setting: if disabled, don't show the backdrop
117
- if (window.__IMPECCABLE_CONFIG__?.spotlightBlur === false) {
118
- spotlightTarget = target;
119
- return;
120
- }
121
- spotlightTarget = target;
122
- const bd = getSpotlightBackdrop();
123
- updateSpotlightClipPath();
124
- bd.classList.add('impeccable-visible');
125
- }
126
-
127
- function hideSpotlight() {
128
- spotlightTarget = null;
129
- if (spotlightBackdrop) spotlightBackdrop.classList.remove('impeccable-visible');
130
- }
131
-
132
- function isInViewport(el) {
133
- const r = el.getBoundingClientRect();
134
- return r.top >= 0 && r.left >= 0 && r.bottom <= window.innerHeight && r.right <= window.innerWidth;
135
- }
136
-
137
- // Reposition spotlight on scroll/resize
138
- window.addEventListener('scroll', () => {
139
- if (spotlightTarget) updateSpotlightClipPath();
140
- }, { passive: true });
141
- window.addEventListener('resize', () => {
142
- if (spotlightTarget) updateSpotlightClipPath();
143
- });
144
-
145
- const overlays = [];
146
- const TYPE_LABELS = {};
147
- const RULE_CATEGORY = {};
148
- for (const ap of ANTIPATTERNS) {
149
- TYPE_LABELS[ap.id] = ap.name.toLowerCase();
150
- RULE_CATEGORY[ap.id] = ap.category || 'quality';
151
- }
152
-
153
- function isInFixedContext(el) {
154
- let p = el;
155
- while (p && p !== document.body) {
156
- if (getComputedStyle(p).position === 'fixed') return true;
157
- p = p.parentElement;
158
- }
159
- return false;
160
- }
161
-
162
- function positionOverlay(overlay) {
163
- const el = overlay._targetEl;
164
- if (!el) return;
165
- const rect = el.getBoundingClientRect();
166
- if (overlay._isFixed) {
167
- // Viewport-relative coords for fixed targets
168
- overlay.style.top = `${rect.top - 2}px`;
169
- overlay.style.left = `${rect.left - 2}px`;
170
- } else {
171
- // Document-relative coords for normal targets
172
- overlay.style.top = `${rect.top + scrollY - 2}px`;
173
- overlay.style.left = `${rect.left + scrollX - 2}px`;
174
- }
175
- overlay.style.width = `${rect.width + 4}px`;
176
- overlay.style.height = `${rect.height + 4}px`;
177
- }
178
-
179
- function repositionOverlays() {
180
- for (const o of overlays) {
181
- if (!o._targetEl || o.classList.contains('impeccable-banner')) continue;
182
- // Skip overlays whose target is currently hidden (display: none on the overlay)
183
- if (o.style.display === 'none') continue;
184
- positionOverlay(o);
185
- }
186
- }
187
-
188
- let resizeRAF;
189
- const onResize = () => {
190
- cancelAnimationFrame(resizeRAF);
191
- resizeRAF = requestAnimationFrame(repositionOverlays);
192
- };
193
- window.addEventListener('resize', onResize);
194
- // Reposition on scroll too -- catches sticky/parallax shifts
195
- window.addEventListener('scroll', onResize, { passive: true });
196
- // Reposition when body resizes (lazy-loaded images, dynamic content, fonts loading)
197
- if (typeof ResizeObserver !== 'undefined') {
198
- const bodyResizeObserver = new ResizeObserver(onResize);
199
- bodyResizeObserver.observe(document.body);
200
- }
201
-
202
- // Track target element visibility via IntersectionObserver.
203
- // Uses a huge rootMargin so all *rendered* elements count as intersecting,
204
- // while display:none / closed <details> / hidden modals etc. do not.
205
- // This is event-driven -- no polling needed.
206
- let overlayIndex = 0;
207
- const visibilityObserver = new IntersectionObserver((entries) => {
208
- for (const entry of entries) {
209
- const overlay = entry.target._impeccableOverlay;
210
- if (!overlay) continue;
211
- if (entry.isIntersecting) {
212
- overlay.style.display = '';
213
- positionOverlay(overlay);
214
- if (!overlay._revealed) {
215
- overlay._revealed = true;
216
- if (firstScanDone) {
217
- // Subsequent reveals (re-scans, scroll-into-view): instant, no animation
218
- overlay.style.animation = 'none';
219
- } else {
220
- // Initial scan: staggered cascade reveal
221
- overlay.style.animationDelay = `${Math.min((overlay._staggerIndex || 0) * 60, 600)}ms`;
222
- }
223
- requestAnimationFrame(() => {
224
- overlay.classList.add('impeccable-visible');
225
- if (overlay._checkLabel) overlay._checkLabel();
226
- });
227
- }
228
- } else {
229
- overlay.style.display = 'none';
230
- }
231
- }
232
- }, { rootMargin: '99999px' });
233
-
234
- function detachOverlay(overlay) {
235
- if (!overlay) return;
236
- if (typeof overlay._cleanup === 'function') {
237
- try { overlay._cleanup(); } catch { /* best effort overlay teardown */ }
238
- }
239
- if (overlay._targetEl && overlay._targetEl._impeccableOverlay === overlay) {
240
- visibilityObserver.unobserve(overlay._targetEl);
241
- delete overlay._targetEl._impeccableOverlay;
242
- }
243
- const idx = overlays.indexOf(overlay);
244
- if (idx >= 0) overlays.splice(idx, 1);
245
- overlay.remove();
246
- }
247
-
248
- // Reposition overlays after CSS transitions end (e.g. reveal animations).
249
- // Listens at document level so it catches transitions on ancestor elements
250
- // (the transform may be on a parent, not the flagged element itself).
251
- document.addEventListener('transitionend', (e) => {
252
- if (e.propertyName !== 'transform') return;
253
- for (const o of overlays) {
254
- if (!o._targetEl || o.classList.contains('impeccable-banner') || o.style.display === 'none') continue;
255
- if (e.target === o._targetEl || e.target.contains(o._targetEl)) {
256
- positionOverlay(o);
257
- }
258
- }
259
- });
260
-
261
- const highlight = function(el, findings) {
262
- if (el._impeccableOverlay) detachOverlay(el._impeccableOverlay);
263
- const hasSlop = findings.some(f => RULE_CATEGORY[f.type || f.id] === 'slop');
264
-
265
- const fixed = isInFixedContext(el);
266
- const rect = el.getBoundingClientRect();
267
- const outline = document.createElement('div');
268
- outline.className = 'impeccable-overlay';
269
- outline._targetEl = el;
270
- outline._isFixed = fixed;
271
- Object.assign(outline.style, {
272
- position: fixed ? 'fixed' : 'absolute',
273
- top: fixed ? `${rect.top - 2}px` : `${rect.top + scrollY - 2}px`,
274
- left: fixed ? `${rect.left - 2}px` : `${rect.left + scrollX - 2}px`,
275
- width: `${rect.width + 4}px`, height: `${rect.height + 4}px`,
276
- zIndex: '99999', boxSizing: 'border-box',
277
- });
278
-
279
- // Build per-finding label entries: ✦ prefix for slop
280
- const entries = findings.map(f => {
281
- const name = TYPE_LABELS[f.type || f.id] || f.type || f.id;
282
- const prefix = RULE_CATEGORY[f.type || f.id] === 'slop' ? '\u2726 ' : '';
283
- return { name: prefix + name, detail: f.detail || f.snippet };
284
- });
285
- const allText = entries.map(e => e.name).join(', ');
286
-
287
- const label = document.createElement('div');
288
- label.className = 'impeccable-label';
289
- Object.assign(label.style, {
290
- position: 'absolute', bottom: '100%', left: '-2px',
291
- display: 'flex', alignItems: 'center',
292
- whiteSpace: 'nowrap',
293
- fontSize: '11px', fontWeight: '600', letterSpacing: '0.02em',
294
- color: LABEL_INK, lineHeight: '14px',
295
- background: LABEL_BG,
296
- fontFamily: 'system-ui, sans-serif',
297
- borderRadius: '4px 4px 0 0',
298
- });
299
-
300
- const textSpan = document.createElement('span');
301
- textSpan.style.padding = '3px 8px';
302
- textSpan.textContent = allText;
303
- label.appendChild(textSpan);
304
-
305
- // State for cycling mode
306
- let cycleMode = false;
307
- let cycleIndex = 0;
308
- let isHovered = false;
309
- let prevBtn, nextBtn;
310
-
311
- function updateCycleText() {
312
- const e = entries[cycleIndex];
313
- textSpan.textContent = isHovered ? e.detail : e.name;
314
- }
315
-
316
- function enableCycleMode() {
317
- if (cycleMode || entries.length < 2) return;
318
- cycleMode = true;
319
-
320
- const btnStyle = {
321
- background: 'none', border: 'none', color: 'rgba(255,255,255,0.7)',
322
- fontSize: '11px', cursor: 'pointer', padding: '3px 4px',
323
- fontFamily: 'system-ui, sans-serif', lineHeight: '14px',
324
- pointerEvents: 'auto',
325
- };
326
-
327
- const navGroup = document.createElement('span');
328
- Object.assign(navGroup.style, {
329
- display: 'inline-flex', alignItems: 'center', flexShrink: '0',
330
- });
331
-
332
- prevBtn = document.createElement('button');
333
- prevBtn.textContent = '\u2039';
334
- Object.assign(prevBtn.style, btnStyle);
335
- prevBtn.style.paddingLeft = '6px';
336
- prevBtn.addEventListener('click', (e) => {
337
- e.stopPropagation();
338
- cycleIndex = (cycleIndex - 1 + entries.length) % entries.length;
339
- updateCycleText();
340
- });
341
-
342
- nextBtn = document.createElement('button');
343
- nextBtn.textContent = '\u203A';
344
- Object.assign(nextBtn.style, btnStyle);
345
- nextBtn.style.paddingRight = '2px';
346
- nextBtn.addEventListener('click', (e) => {
347
- e.stopPropagation();
348
- cycleIndex = (cycleIndex + 1) % entries.length;
349
- updateCycleText();
350
- });
351
-
352
- navGroup.appendChild(prevBtn);
353
- navGroup.appendChild(nextBtn);
354
- label.insertBefore(navGroup, textSpan);
355
- textSpan.style.padding = '3px 8px 3px 4px';
356
- updateCycleText();
357
- }
358
-
359
- outline.appendChild(label);
360
-
361
- // Start hidden; the IntersectionObserver will show it once the target is rendered
362
- outline.style.display = 'none';
363
- outline._staggerIndex = overlayIndex++;
364
- el._impeccableOverlay = outline;
365
- visibilityObserver.observe(el);
366
-
367
- // After first paint, check label width vs outline
368
- outline._checkLabel = () => {
369
- if (entries.length > 1 && label.offsetWidth > outline.offsetWidth) {
370
- enableCycleMode();
371
- }
372
- };
373
-
374
- // Hover: show detail text, darken
375
- const onMouseEnter = () => {
376
- isHovered = true;
377
- outline.classList.add('impeccable-hover');
378
- outline.style.outlineColor = BRAND_COLOR_HOVER;
379
- label.style.background = BRAND_COLOR_HOVER;
380
- if (cycleMode) {
381
- updateCycleText();
382
- } else {
383
- textSpan.textContent = entries.map(e => e.detail).join(' | ');
384
- }
385
- };
386
- const onMouseLeave = () => {
387
- isHovered = false;
388
- outline.classList.remove('impeccable-hover');
389
- outline.style.outlineColor = '';
390
- label.style.background = LABEL_BG;
391
- if (cycleMode) {
392
- updateCycleText();
393
- } else {
394
- textSpan.textContent = allText;
395
- }
396
- };
397
- el.addEventListener('mouseenter', onMouseEnter);
398
- el.addEventListener('mouseleave', onMouseLeave);
399
- outline._cleanup = () => {
400
- el.removeEventListener('mouseenter', onMouseEnter);
401
- el.removeEventListener('mouseleave', onMouseLeave);
402
- };
403
-
404
- document.body.appendChild(outline);
405
- overlays.push(outline);
406
- };
407
-
408
- const showPageBanner = function(findings) {
409
- if (!findings.length) return;
410
- const banner = document.createElement('div');
411
- banner.className = 'impeccable-overlay impeccable-banner';
412
- Object.assign(banner.style, {
413
- position: 'fixed', top: '0', left: '0', right: '0', zIndex: '100000',
414
- background: LABEL_BG, color: LABEL_INK,
415
- fontFamily: 'system-ui, sans-serif', fontSize: '13px',
416
- display: 'flex', alignItems: 'center', pointerEvents: 'auto',
417
- height: '36px', overflow: 'hidden', maxWidth: '100vw',
418
- transform: 'translateY(-100%)',
419
- transition: 'transform 0.4s cubic-bezier(0.16, 1, 0.3, 1)',
420
- });
421
- requestAnimationFrame(() => requestAnimationFrame(() => {
422
- banner.style.transform = 'translateY(0)';
423
- }));
424
-
425
- // Scrollable findings area
426
- const scrollArea = document.createElement('div');
427
- Object.assign(scrollArea.style, {
428
- flex: '1', minWidth: '0', overflowX: 'auto', overflowY: 'hidden',
429
- display: 'flex', gap: '8px', alignItems: 'center',
430
- padding: '0 12px', scrollSnapType: 'x mandatory',
431
- scrollbarWidth: 'none',
432
- });
433
- for (const f of findings) {
434
- const prefix = RULE_CATEGORY[f.type] === 'slop' ? '\u2726 ' : '';
435
- const tag = document.createElement('span');
436
- tag.textContent = `${prefix}${TYPE_LABELS[f.type] || f.type}: ${f.detail}`;
437
- Object.assign(tag.style, {
438
- background: 'rgba(255,255,255,0.15)', padding: '2px 8px',
439
- borderRadius: '3px', fontSize: '12px', fontFamily: 'ui-monospace, monospace',
440
- whiteSpace: 'nowrap', flexShrink: '0', scrollSnapAlign: 'start',
441
- });
442
- scrollArea.appendChild(tag);
443
- }
444
- banner.appendChild(scrollArea);
445
-
446
- // Controls area (only in standalone mode, not extension)
447
- if (!EXTENSION_MODE) {
448
- const controls = document.createElement('div');
449
- Object.assign(controls.style, {
450
- display: 'flex', alignItems: 'center', gap: '2px',
451
- padding: '0 8px', flexShrink: '0',
452
- });
453
-
454
- // Toggle visibility button
455
- const toggle = document.createElement('button');
456
- toggle.textContent = '\u25C9'; // circle with dot (visible state)
457
- toggle.title = 'Toggle overlay visibility';
458
- Object.assign(toggle.style, {
459
- background: 'none', border: 'none',
460
- color: 'white', fontSize: '16px', cursor: 'pointer', padding: '0 4px',
461
- opacity: '0.85', transition: 'opacity 0.15s',
462
- });
463
- let overlaysVisible = true;
464
- toggle.addEventListener('click', () => {
465
- overlaysVisible = !overlaysVisible;
466
- document.body.classList.toggle('impeccable-hidden', !overlaysVisible);
467
- toggle.textContent = overlaysVisible ? '\u25C9' : '\u25CB'; // filled vs empty circle
468
- toggle.style.opacity = overlaysVisible ? '0.85' : '0.5';
469
- });
470
- controls.appendChild(toggle);
471
-
472
- // Close button
473
- const close = document.createElement('button');
474
- close.textContent = '\u00d7';
475
- close.title = 'Dismiss banner';
476
- Object.assign(close.style, {
477
- background: 'none', border: 'none',
478
- color: 'white', fontSize: '18px', cursor: 'pointer', padding: '0 4px',
479
- });
480
- close.addEventListener('click', () => banner.remove());
481
- controls.appendChild(close);
482
-
483
- banner.appendChild(controls);
484
- }
485
- document.body.appendChild(banner);
486
- overlays.push(banner);
487
- };
488
-
489
- // Heuristic for skipping CSS-in-JS hashed class names like "css-1a2b3c" or "_2x4hG_".
490
- // These change between builds and produce brittle, ugly selectors.
491
- function isLikelyHashedClass(c) {
492
- if (!c) return true;
493
- if (/^(css|sc|emotion|jsx|module)-[\w-]{4,}$/i.test(c)) return true;
494
- if (/^_[\w-]{5,}$/.test(c)) return true;
495
- if (/^[a-z0-9]{6,}$/i.test(c) && /\d/.test(c)) return true;
496
- return false;
497
- }
498
-
499
- function buildSelectorSegment(el) {
500
- const tag = el.tagName.toLowerCase();
501
- let sel = tag;
502
-
503
- if (el.classList && el.classList.length > 0) {
504
- const classes = [...el.classList]
505
- .filter(c => !c.startsWith('impeccable-') && !isLikelyHashedClass(c))
506
- .slice(0, 2);
507
- if (classes.length > 0) {
508
- sel += '.' + classes.map(c => CSS.escape(c)).join('.');
509
- }
510
- }
511
-
512
- // Disambiguate among siblings only if the parent has multiple matches
513
- const parent = el.parentElement;
514
- if (parent) {
515
- try {
516
- const matching = parent.querySelectorAll(':scope > ' + sel);
517
- if (matching.length > 1) {
518
- const sameType = [...parent.children].filter(c => c.tagName === el.tagName);
519
- const idx = sameType.indexOf(el) + 1;
520
- sel += `:nth-of-type(${idx})`;
521
- }
522
- } catch {
523
- const idx = [...parent.children].indexOf(el) + 1;
524
- sel = `${tag}:nth-child(${idx})`;
525
- }
526
- }
527
- return sel;
528
- }
529
-
530
- function generateSelector(el) {
531
- if (el === document.body) return 'body';
532
- if (el === document.documentElement) return 'html';
533
- // Read via getAttribute when `el.id` is not a string — a <form> with a
534
- // named control (e.g. <input name="id">) shadows the builtin getter and
535
- // returns the element, producing a garbage `#[object …]` selector (#407).
536
- const elId = typeof el.id === 'string' ? el.id : (el.getAttribute('id') || '');
537
- if (elId) return '#' + CSS.escape(elId);
538
-
539
- const parts = [];
540
- let current = el;
541
- let depth = 0;
542
- const MAX_DEPTH = 10;
543
-
544
- while (current && current !== document.body && current !== document.documentElement && depth < MAX_DEPTH) {
545
- parts.unshift(buildSelectorSegment(current));
546
-
547
- // Anchor on an ancestor's ID and stop walking up
548
- if (current.id) {
549
- parts[0] = '#' + CSS.escape(current.id);
550
- break;
551
- }
552
-
553
- // Stop as soon as the partial selector uniquely identifies the target
554
- const trySelector = parts.join(' > ');
555
- try {
556
- const matches = document.querySelectorAll(trySelector);
557
- if (matches.length === 1 && matches[0] === el) {
558
- return trySelector;
559
- }
560
- } catch { /* invalid selector — keep walking */ }
561
-
562
- current = current.parentElement;
563
- depth++;
564
- }
565
-
566
- return parts.join(' > ');
567
- }
568
-
569
- function getDirectText(el) {
570
- return [...el.childNodes]
571
- .filter(n => n.nodeType === 3)
572
- .map(n => n.textContent || '')
573
- .join('');
574
- }
575
-
576
- function getDirectTextRect(el) {
577
- const rects = [];
578
- for (const node of el.childNodes) {
579
- if (node.nodeType !== 3 || !(node.textContent || '').trim()) continue;
580
- const range = document.createRange();
581
- range.selectNodeContents(node);
582
- for (const rect of range.getClientRects()) {
583
- if (rect.width >= 1 && rect.height >= 1) rects.push(rect);
584
- }
585
- range.detach?.();
586
- }
587
- if (rects.length === 0) return null;
588
- const left = Math.min(...rects.map(r => r.left));
589
- const top = Math.min(...rects.map(r => r.top));
590
- const right = Math.max(...rects.map(r => r.right));
591
- const bottom = Math.max(...rects.map(r => r.bottom));
592
- return {
593
- left,
594
- top,
595
- right,
596
- bottom,
597
- width: right - left,
598
- height: bottom - top,
599
- x: left,
600
- y: top,
601
- };
602
- }
603
-
604
- function collectVisualContrastReasons(el, style) {
605
- const reasons = new Set();
606
- const bgClip = style.webkitBackgroundClip || style.backgroundClip || '';
607
- const ownBgImage = style.backgroundImage || '';
608
- if (bgClip === 'text' && ownBgImage && ownBgImage !== 'none') {
609
- reasons.add('background-clip text');
610
- }
611
- if (style.textShadow && style.textShadow !== 'none') reasons.add('text shadow');
612
-
613
- let current = el;
614
- while (current && current.nodeType === 1) {
615
- const tag = current.tagName?.toLowerCase();
616
- const currentStyle = getComputedStyle(current);
617
- const bgImage = currentStyle.backgroundImage || '';
618
- const isDocumentSurface = tag === 'body' || tag === 'html';
619
-
620
- if (!isDocumentSurface && bgImage && bgImage !== 'none') {
621
- if (/url\s*\(/i.test(bgImage)) reasons.add('image background');
622
- if (/gradient/i.test(bgImage)) reasons.add('gradient background');
623
- }
624
- if (parseFloat(currentStyle.opacity) < 0.99) reasons.add('opacity stack');
625
- if (currentStyle.mixBlendMode && currentStyle.mixBlendMode !== 'normal') reasons.add('blend mode');
626
- if (currentStyle.filter && currentStyle.filter !== 'none') reasons.add('filter');
627
- if (currentStyle.backdropFilter && currentStyle.backdropFilter !== 'none') reasons.add('backdrop filter');
628
-
629
- const solidBg = parseRgb(currentStyle.backgroundColor);
630
- if (solidBg && solidBg.a >= 0.95 && (!bgImage || bgImage === 'none')) break;
631
- current = current.parentElement;
632
- }
633
-
634
- const sampleRect = getDirectTextRect(el) || el.getBoundingClientRect();
635
- if (sampleRect && document.elementsFromPoint) {
636
- const points = [
637
- [sampleRect.left + sampleRect.width / 2, sampleRect.top + sampleRect.height / 2],
638
- [sampleRect.left + Math.min(sampleRect.width - 1, Math.max(1, sampleRect.width * 0.25)), sampleRect.top + sampleRect.height / 2],
639
- [sampleRect.left + Math.min(sampleRect.width - 1, Math.max(1, sampleRect.width * 0.75)), sampleRect.top + sampleRect.height / 2],
640
- ];
641
- for (const [x, y] of points) {
642
- if (x < 0 || y < 0 || x > window.innerWidth || y > window.innerHeight) continue;
643
- const stack = document.elementsFromPoint(x, y);
644
- const selfIndex = stack.findIndex(node => node === el || el.contains(node) || node.contains?.(el));
645
- if (selfIndex < 0) continue;
646
- for (const node of stack.slice(selfIndex + 1)) {
647
- const nodeTag = node.tagName?.toLowerCase();
648
- if (nodeTag === 'img' || nodeTag === 'picture' || nodeTag === 'video' || nodeTag === 'canvas' || nodeTag === 'svg') {
649
- reasons.add(`${nodeTag} underlay`);
650
- break;
651
- }
652
- }
653
- }
654
- }
655
-
656
- return [...reasons];
657
- }
658
-
659
- function collectVisualContrastCandidates(options = {}) {
660
- const maxCandidates = Number.isFinite(options.maxCandidates) ? options.maxCandidates : 12;
661
- const candidates = [];
662
- for (const el of document.querySelectorAll('*')) {
663
- if (candidates.length >= maxCandidates) break;
664
- if (el.closest('.impeccable-overlay, .impeccable-label, .impeccable-banner, .impeccable-tooltip')) continue;
665
- if (el.closest('[id^="impeccable-live-"]')) continue;
666
- if (el === document.body || el === document.documentElement) continue;
667
- if (!isRenderedForBrowserRule(el)) continue;
668
-
669
- const tag = el.tagName.toLowerCase();
670
- const style = getComputedStyle(el);
671
- if (style.display === 'none' || style.visibility === 'hidden') continue;
672
- const directText = getDirectText(el);
673
- const hasDirectText = directText.trim().length > 0;
674
- if (!hasDirectText || isEmojiOnlyText(directText)) continue;
675
-
676
- const bgColor = readOwnBackgroundColor(el, style);
677
- const isStyledButton = (tag === 'a' || tag === 'button')
678
- && bgColor && bgColor.a > 0.5;
679
- if (SAFE_TAGS.has(tag) && !isStyledButton) continue;
680
-
681
- const rect = getDirectTextRect(el) || el.getBoundingClientRect();
682
- if (!rect || rect.width < 4 || rect.height < 4) continue;
683
-
684
- const reasons = collectVisualContrastReasons(el, style);
685
- if (reasons.length === 0) continue;
686
-
687
- const textColor = parseRgb(style.color);
688
- const fontSize = parseFloat(style.fontSize) || 16;
689
- const fontWeight = parseInt(style.fontWeight) || 400;
690
- const isLargeText = fontSize >= WCAG_LARGE_TEXT_PX || (fontSize >= WCAG_LARGE_BOLD_TEXT_PX && fontWeight >= 700);
691
- const threshold = isLargeText ? 3.0 : 4.5;
692
- const clip = {
693
- x: Math.max(0, Math.floor(rect.left + window.scrollX - 2)),
694
- y: Math.max(0, Math.floor(rect.top + window.scrollY - 2)),
695
- width: Math.max(1, Math.ceil(rect.width + 4)),
696
- height: Math.max(1, Math.ceil(rect.height + 4)),
697
- };
698
-
699
- candidates.push({
700
- selector: generateSelector(el),
701
- tagName: tag,
702
- text: directText.trim().replace(/\s+/g, ' ').slice(0, 80),
703
- threshold,
704
- reasons,
705
- clip,
706
- textColor,
707
- preferRenderedForeground: !textColor || textColor.a < 0.99 || reasons.some(reason =>
708
- reason === 'opacity stack' ||
709
- reason === 'blend mode' ||
710
- reason === 'filter' ||
711
- reason === 'backdrop filter' ||
712
- reason === 'background-clip text'
713
- ),
714
- backgroundClipText: reasons.includes('background-clip text'),
715
- });
716
- }
717
- return candidates;
718
- }
719
-
720
- const visualContrastImageCache = new Map();
721
- const visualContrastRasterCache = new WeakMap();
722
-
723
- function clampByte(value) {
724
- return Math.max(0, Math.min(255, Math.round(value)));
725
- }
726
-
727
- function blendRgba(fg, bg) {
728
- if (!fg) return bg || null;
729
- if (!bg || fg.a == null || fg.a >= 0.999) {
730
- return { r: clampByte(fg.r), g: clampByte(fg.g), b: clampByte(fg.b), a: fg.a == null ? 1 : fg.a };
731
- }
732
- const alpha = Math.max(0, Math.min(1, fg.a));
733
- return {
734
- r: clampByte(fg.r * alpha + bg.r * (1 - alpha)),
735
- g: clampByte(fg.g * alpha + bg.g * (1 - alpha)),
736
- b: clampByte(fg.b * alpha + bg.b * (1 - alpha)),
737
- a: 1,
738
- };
739
- }
740
-
741
- function pickWorstContrastColor(textColor, colors) {
742
- const usable = (colors || []).filter(Boolean);
743
- if (!usable.length) return null;
744
- let worst = usable[0];
745
- let worstRatio = contrastRatio(textColor, worst);
746
- for (const color of usable.slice(1)) {
747
- const ratio = contrastRatio(textColor, color);
748
- if (ratio < worstRatio) {
749
- worst = color;
750
- worstRatio = ratio;
751
- }
752
- }
753
- return worst;
754
- }
755
-
756
- function firstCssUrl(value) {
757
- const match = String(value || '').match(/url\((?:"([^"]+)"|'([^']+)'|([^)]*))\)/i);
758
- if (!match) return '';
759
- return (match[1] || match[2] || match[3] || '').trim();
760
- }
761
-
762
- function getLayerValue(value, index = 0) {
763
- return String(value || '').split(',')[index]?.trim() || '';
764
- }
765
-
766
- function parsePositionToken(token, container, painted) {
767
- if (!token || token === 'center') return (container - painted) / 2;
768
- if (token === 'left' || token === 'top') return 0;
769
- if (token === 'right' || token === 'bottom') return container - painted;
770
- if (/%$/.test(token)) {
771
- const pct = parseFloat(token) / 100;
772
- return (container - painted) * pct;
773
- }
774
- if (/px$/.test(token)) return parseFloat(token) || 0;
775
- return (container - painted) / 2;
776
- }
777
-
778
- function parsePositionPair(positionValue) {
779
- const tokens = String(positionValue || '50% 50%').trim().split(/\s+/).filter(Boolean);
780
- const first = tokens[0] || '50%';
781
- if (tokens.length < 2) {
782
- if (first === 'top' || first === 'bottom') return ['50%', first];
783
- return [first, '50%'];
784
- }
785
- return [first, tokens[1] || '50%'];
786
- }
787
-
788
- function resolvePaintedImageRect(containerRect, image, sizeValue, positionValue) {
789
- const intrinsicWidth = image.naturalWidth || image.videoWidth || image.width || 1;
790
- const intrinsicHeight = image.naturalHeight || image.videoHeight || image.height || 1;
791
- let paintedWidth = intrinsicWidth;
792
- let paintedHeight = intrinsicHeight;
793
- const size = String(sizeValue || 'auto').trim();
794
-
795
- if (size === 'cover' || size === 'contain') {
796
- const scale = size === 'cover'
797
- ? Math.max(containerRect.width / intrinsicWidth, containerRect.height / intrinsicHeight)
798
- : Math.min(containerRect.width / intrinsicWidth, containerRect.height / intrinsicHeight);
799
- paintedWidth = intrinsicWidth * scale;
800
- paintedHeight = intrinsicHeight * scale;
801
- } else if (size && size !== 'auto') {
802
- const parts = size.split(/\s+/);
803
- const widthToken = parts[0];
804
- const heightToken = parts[1] || 'auto';
805
- if (/%$/.test(widthToken)) paintedWidth = containerRect.width * (parseFloat(widthToken) / 100);
806
- else if (/px$/.test(widthToken)) paintedWidth = parseFloat(widthToken) || paintedWidth;
807
- if (heightToken === 'auto') paintedHeight = paintedWidth * (intrinsicHeight / intrinsicWidth);
808
- else if (/%$/.test(heightToken)) paintedHeight = containerRect.height * (parseFloat(heightToken) / 100);
809
- else if (/px$/.test(heightToken)) paintedHeight = parseFloat(heightToken) || paintedHeight;
810
- }
811
-
812
- const [xToken, yToken] = parsePositionPair(positionValue);
813
- const positionX = parsePositionToken(xToken, containerRect.width, paintedWidth);
814
- const positionY = parsePositionToken(yToken, containerRect.height, paintedHeight);
815
- return {
816
- left: containerRect.left + positionX,
817
- top: containerRect.top + positionY,
818
- width: paintedWidth,
819
- height: paintedHeight,
820
- intrinsicWidth,
821
- intrinsicHeight,
822
- };
823
- }
824
-
825
- function parseObjectPosition(positionValue) {
826
- return parsePositionPair(positionValue);
827
- }
828
-
829
- function resolveObjectImageRect(containerRect, image, style) {
830
- const intrinsicWidth = image.naturalWidth || image.videoWidth || image.width || 1;
831
- const intrinsicHeight = image.naturalHeight || image.videoHeight || image.height || 1;
832
- const fit = style.objectFit || 'fill';
833
- let paintedWidth = containerRect.width;
834
- let paintedHeight = containerRect.height;
835
- if (fit === 'contain' || fit === 'cover') {
836
- const scale = fit === 'cover'
837
- ? Math.max(containerRect.width / intrinsicWidth, containerRect.height / intrinsicHeight)
838
- : Math.min(containerRect.width / intrinsicWidth, containerRect.height / intrinsicHeight);
839
- paintedWidth = intrinsicWidth * scale;
840
- paintedHeight = intrinsicHeight * scale;
841
- } else if (fit === 'none') {
842
- paintedWidth = intrinsicWidth;
843
- paintedHeight = intrinsicHeight;
844
- } else if (fit === 'scale-down') {
845
- const containScale = Math.min(containerRect.width / intrinsicWidth, containerRect.height / intrinsicHeight, 1);
846
- paintedWidth = intrinsicWidth * containScale;
847
- paintedHeight = intrinsicHeight * containScale;
848
- }
849
- const [xToken, yToken] = parseObjectPosition(style.objectPosition);
850
- return {
851
- left: containerRect.left + parsePositionToken(xToken, containerRect.width, paintedWidth),
852
- top: containerRect.top + parsePositionToken(yToken, containerRect.height, paintedHeight),
853
- width: paintedWidth,
854
- height: paintedHeight,
855
- intrinsicWidth,
856
- intrinsicHeight,
857
- };
858
- }
859
-
860
- function pointToImageSource(point, paintedRect) {
861
- if (
862
- point.x < paintedRect.left ||
863
- point.y < paintedRect.top ||
864
- point.x > paintedRect.left + paintedRect.width ||
865
- point.y > paintedRect.top + paintedRect.height
866
- ) {
867
- return null;
868
- }
869
- return {
870
- x: Math.max(0, Math.min(paintedRect.intrinsicWidth - 1, ((point.x - paintedRect.left) / paintedRect.width) * paintedRect.intrinsicWidth)),
871
- y: Math.max(0, Math.min(paintedRect.intrinsicHeight - 1, ((point.y - paintedRect.top) / paintedRect.height) * paintedRect.intrinsicHeight)),
872
- };
873
- }
874
-
875
- async function loadVisualContrastImage(src) {
876
- if (!src) return null;
877
- if (visualContrastImageCache.has(src)) return visualContrastImageCache.get(src);
878
- const promise = new Promise(resolve => {
879
- const img = new Image();
880
- let settled = false;
881
- const finish = value => {
882
- if (settled) return;
883
- settled = true;
884
- clearTimeout(timer);
885
- resolve(value);
886
- };
887
- const timer = setTimeout(() => finish(null), 800);
888
- try {
889
- const absolute = new URL(src, location.href);
890
- if (absolute.origin !== location.origin && absolute.protocol !== 'data:' && absolute.protocol !== 'blob:') {
891
- img.crossOrigin = 'anonymous';
892
- }
893
- } catch {
894
- // Let the browser resolve unusual URLs itself.
895
- }
896
- img.onload = () => finish(img);
897
- img.onerror = () => finish(null);
898
- img.src = src;
899
- });
900
- visualContrastImageCache.set(src, promise);
901
- return promise;
902
- }
903
-
904
- function sampleDrawablePixel(drawable, sourcePoint) {
905
- if (visualContrastRasterCache.has(drawable)) {
906
- const cached = visualContrastRasterCache.get(drawable);
907
- if (!cached || !cached.ctx) return { status: 'unresolved', reason: cached?.reason || 'image sample failed' };
908
- try {
909
- const x = Math.max(0, Math.min(cached.width - 1, Math.floor(sourcePoint.x * cached.scaleX)));
910
- const y = Math.max(0, Math.min(cached.height - 1, Math.floor(sourcePoint.y * cached.scaleY)));
911
- const data = cached.ctx.getImageData(x, y, 1, 1).data;
912
- return {
913
- status: 'sampled',
914
- color: { r: data[0], g: data[1], b: data[2], a: data[3] / 255 },
915
- };
916
- } catch (err) {
917
- return {
918
- status: 'unresolved',
919
- reason: /taint|cross-origin|Security/i.test(err?.message || '') ? 'tainted image' : 'image sample failed',
920
- };
921
- }
922
- }
923
-
924
- const canvas = document.createElement('canvas');
925
- const intrinsicWidth = drawable.naturalWidth || drawable.videoWidth || drawable.width || 1;
926
- const intrinsicHeight = drawable.naturalHeight || drawable.videoHeight || drawable.height || 1;
927
- const maxRasterSide = 640;
928
- const scale = Math.min(1, maxRasterSide / Math.max(intrinsicWidth, intrinsicHeight));
929
- canvas.width = Math.max(1, Math.round(intrinsicWidth * scale));
930
- canvas.height = Math.max(1, Math.round(intrinsicHeight * scale));
931
- const ctx = canvas.getContext('2d', { willReadFrequently: true });
932
- if (!ctx) return { status: 'unresolved', reason: 'canvas unavailable' };
933
- try {
934
- ctx.drawImage(drawable, 0, 0, canvas.width, canvas.height);
935
- const cached = {
936
- ctx,
937
- width: canvas.width,
938
- height: canvas.height,
939
- scaleX: canvas.width / intrinsicWidth,
940
- scaleY: canvas.height / intrinsicHeight,
941
- };
942
- visualContrastRasterCache.set(drawable, cached);
943
- const x = Math.max(0, Math.min(cached.width - 1, Math.floor(sourcePoint.x * cached.scaleX)));
944
- const y = Math.max(0, Math.min(cached.height - 1, Math.floor(sourcePoint.y * cached.scaleY)));
945
- const data = ctx.getImageData(x, y, 1, 1).data;
946
- return {
947
- status: 'sampled',
948
- color: { r: data[0], g: data[1], b: data[2], a: data[3] / 255 },
949
- };
950
- } catch (err) {
951
- const reason = /taint|cross-origin|Security/i.test(err?.message || '') ? 'tainted image' : 'image sample failed';
952
- visualContrastRasterCache.set(drawable, { ctx: null, reason });
953
- return {
954
- status: 'unresolved',
955
- reason,
956
- };
957
- }
958
- }
959
-
960
- async function sampleCssBackground(el, style, point, textColor) {
961
- const rect = el.getBoundingClientRect();
962
- const bgImage = style.backgroundImage || '';
963
- if (bgImage && bgImage !== 'none') {
964
- if (/gradient/i.test(bgImage)) {
965
- const color = pickWorstContrastColor(textColor, parseGradientColors(bgImage));
966
- if (color) return { status: 'sampled', color, method: 'analytic-gradient' };
967
- }
968
- if (/url\s*\(/i.test(bgImage)) {
969
- const img = await loadVisualContrastImage(firstCssUrl(bgImage));
970
- if (!img) return { status: 'unresolved', reason: 'image unavailable' };
971
- const paintedRect = resolvePaintedImageRect(
972
- rect,
973
- img,
974
- getLayerValue(style.backgroundSize) || 'auto',
975
- getLayerValue(style.backgroundPosition) || '50% 50%',
976
- );
977
- const sourcePoint = pointToImageSource(point, paintedRect);
978
- if (!sourcePoint) return { status: 'unresolved', reason: 'point outside background image' };
979
- const sample = sampleDrawablePixel(img, sourcePoint);
980
- if (sample.status === 'sampled') return { ...sample, method: 'canvas-background-image' };
981
- return sample;
982
- }
983
- }
984
- const bg = parseRgb(style.backgroundColor);
985
- if (bg && bg.a > 0.05) return { status: 'sampled', color: bg, method: 'solid-background' };
986
- return { status: 'unresolved', reason: 'no readable background' };
987
- }
988
-
989
- async function sampleImageElement(img, point) {
990
- const rect = img.getBoundingClientRect();
991
- const style = getComputedStyle(img);
992
- const paintedRect = resolveObjectImageRect(rect, img, style);
993
- const sourcePoint = pointToImageSource(point, paintedRect);
994
- if (!sourcePoint) return { status: 'unresolved', reason: 'point outside image' };
995
- const sample = sampleDrawablePixel(img, sourcePoint);
996
- if (sample.status === 'sampled') return { ...sample, method: 'canvas-img-underlay' };
997
-
998
- if (img.currentSrc || img.src) {
999
- const loaded = await loadVisualContrastImage(img.currentSrc || img.src);
1000
- if (loaded) {
1001
- const loadedRect = { ...paintedRect, intrinsicWidth: loaded.naturalWidth || loaded.width || paintedRect.intrinsicWidth, intrinsicHeight: loaded.naturalHeight || loaded.height || paintedRect.intrinsicHeight };
1002
- const loadedPoint = pointToImageSource(point, loadedRect);
1003
- if (loadedPoint) {
1004
- const loadedSample = sampleDrawablePixel(loaded, loadedPoint);
1005
- if (loadedSample.status === 'sampled') return { ...loadedSample, method: 'canvas-img-underlay' };
1006
- }
1007
- }
1008
- }
1009
- return sample;
1010
- }
1011
-
1012
- function textSamplePoints(rect) {
1013
- const insetX = Math.min(12, Math.max(1, rect.width * 0.12));
1014
- const insetY = Math.min(8, Math.max(1, rect.height * 0.22));
1015
- const xs = rect.width < 28
1016
- ? [rect.left + rect.width / 2]
1017
- : [rect.left + insetX, rect.left + rect.width / 2, rect.right - insetX];
1018
- const ys = rect.height < 22
1019
- ? [rect.top + rect.height / 2]
1020
- : [rect.top + insetY, rect.top + rect.height / 2, rect.bottom - insetY];
1021
- const points = [];
1022
- for (const y of ys) {
1023
- for (const x of xs) {
1024
- if (x >= 0 && y >= 0 && x <= window.innerWidth && y <= window.innerHeight) points.push({ x, y });
1025
- }
1026
- }
1027
- return points;
1028
- }
1029
-
1030
- async function sampleVisualBackgroundAtPoint(el, point, textColor, depth = 0) {
1031
- if (depth > 8) {
1032
- return { status: 'unresolved', reason: 'background stack too deep' };
1033
- }
1034
- const stack = typeof document.elementsFromPoint === 'function'
1035
- ? document.elementsFromPoint(point.x, point.y)
1036
- : [];
1037
- const selfIndex = stack.findIndex(node => node === el || el.contains(node));
1038
- const nodes = selfIndex >= 0 ? stack.slice(selfIndex) : [el, ...stack];
1039
- const unresolved = [];
1040
-
1041
- for (const node of nodes) {
1042
- if (!node || node.nodeType !== 1) continue;
1043
- if (node.closest?.('.impeccable-overlay, .impeccable-label, .impeccable-banner, .impeccable-tooltip')) continue;
1044
- const tag = node.tagName?.toLowerCase();
1045
- if (tag === 'img') {
1046
- const sample = await sampleImageElement(node, point);
1047
- if (sample.status === 'sampled') return sample;
1048
- unresolved.push(sample.reason);
1049
- continue;
1050
- }
1051
- if (tag === 'canvas' || tag === 'video') {
1052
- const rect = node.getBoundingClientRect();
1053
- const sourcePoint = pointToImageSource(point, {
1054
- left: rect.left,
1055
- top: rect.top,
1056
- width: rect.width,
1057
- height: rect.height,
1058
- intrinsicWidth: node.width || node.videoWidth || rect.width,
1059
- intrinsicHeight: node.height || node.videoHeight || rect.height,
1060
- });
1061
- if (sourcePoint) {
1062
- const sample = sampleDrawablePixel(node, sourcePoint);
1063
- if (sample.status === 'sampled') return { ...sample, method: `canvas-${tag}-underlay` };
1064
- unresolved.push(sample.reason);
1065
- }
1066
- continue;
1067
- }
1068
- const style = getComputedStyle(node);
1069
- const sample = await sampleCssBackground(node, style, point, textColor);
1070
- if (sample.status === 'sampled') {
1071
- if (!sample.color || sample.color.a == null || sample.color.a >= 0.95) return sample;
1072
- const under = await sampleVisualBackgroundAtPoint(node.parentElement || document.body, point, textColor, depth + 1);
1073
- if (under.status === 'sampled') {
1074
- return {
1075
- status: 'sampled',
1076
- color: blendRgba(sample.color, under.color),
1077
- method: `${sample.method}+alpha`,
1078
- };
1079
- }
1080
- return sample;
1081
- }
1082
- unresolved.push(sample.reason);
1083
- }
1084
-
1085
- return {
1086
- status: 'unresolved',
1087
- reason: [...new Set(unresolved.filter(Boolean))].slice(0, 3).join(', ') || 'no readable visual background',
1088
- };
1089
- }
1090
-
1091
- async function analyzeVisualContrastCandidate(candidate) {
1092
- let el;
1093
- try {
1094
- el = document.querySelector(candidate.selector);
1095
- } catch {
1096
- return { ...candidate, status: 'unresolved', confidence: 'none', reason: 'stale selector' };
1097
- }
1098
- if (!el) return { ...candidate, status: 'unresolved', confidence: 'none', reason: 'missing element' };
1099
- if (!isRenderedForBrowserRule(el)) return { ...candidate, status: 'unresolved', confidence: 'none', reason: 'hidden element' };
1100
-
1101
- const blockingReason = (candidate.reasons || []).find(reason =>
1102
- reason === 'background-clip text' ||
1103
- reason === 'blend mode' ||
1104
- reason === 'filter' ||
1105
- reason === 'backdrop filter' ||
1106
- reason === 'opacity stack' ||
1107
- reason === 'text shadow'
1108
- );
1109
- if (blockingReason) {
1110
- return { ...candidate, status: 'unresolved', confidence: 'none', reason: `${blockingReason} needs screenshot pixels` };
1111
- }
1112
-
1113
- const style = getComputedStyle(el);
1114
- const textColor = parseRgb(style.color) || candidate.textColor;
1115
- if (!textColor) return { ...candidate, status: 'unresolved', confidence: 'none', reason: 'unreadable text color' };
1116
-
1117
- const rect = getDirectTextRect(el) || el.getBoundingClientRect();
1118
- if (!rect || rect.width < 4 || rect.height < 4) {
1119
- return { ...candidate, status: 'unresolved', confidence: 'none', reason: 'missing text rect' };
1120
- }
1121
-
1122
- const points = textSamplePoints(rect);
1123
- if (points.length === 0) {
1124
- return { ...candidate, status: 'unresolved', confidence: 'none', reason: 'text outside viewport' };
1125
- }
1126
-
1127
- const ratios = [];
1128
- const methods = new Set();
1129
- const unresolved = [];
1130
- for (const point of points) {
1131
- const sample = await sampleVisualBackgroundAtPoint(el, point, textColor);
1132
- if (sample.status !== 'sampled' || !sample.color) {
1133
- unresolved.push(sample.reason);
1134
- continue;
1135
- }
1136
- const fg = blendRgba(textColor, sample.color);
1137
- ratios.push(contrastRatio(fg, sample.color));
1138
- if (sample.method) methods.add(sample.method);
1139
- }
1140
-
1141
- if (ratios.length < Math.min(3, points.length)) {
1142
- return {
1143
- ...candidate,
1144
- status: 'unresolved',
1145
- confidence: 'none',
1146
- samples: ratios.length,
1147
- reason: [...new Set(unresolved.filter(Boolean))].slice(0, 3).join(', ') || 'not enough readable samples',
1148
- };
1149
- }
1150
-
1151
- ratios.sort((a, b) => a - b);
1152
- const pick = pct => ratios[Math.min(ratios.length - 1, Math.max(0, Math.floor((pct / 100) * ratios.length)))];
1153
- const measuredRatio = pick(10);
1154
- const medianRatio = pick(50);
1155
- const status = measuredRatio < candidate.threshold ? 'fail' : 'pass';
1156
- const method = [...methods].sort().join(', ') || 'browser-visual';
1157
- const textLabel = candidate.text ? ` "${candidate.text}"` : '';
1158
- const detail = `browser contrast ${measuredRatio.toFixed(1)}:1 median ${medianRatio.toFixed(1)}:1 (need ${candidate.threshold}:1) via ${method}${textLabel}`;
1159
- return {
1160
- ...candidate,
1161
- status,
1162
- confidence: method.includes('canvas-') ? 'high' : 'medium',
1163
- method,
1164
- ratio: measuredRatio,
1165
- medianRatio,
1166
- samples: ratios.length,
1167
- finding: status === 'fail' ? { id: 'low-contrast', snippet: detail } : null,
1168
- };
1169
- }
1170
-
1171
- function waitForVisualPaint() {
1172
- return new Promise(resolve => {
1173
- requestAnimationFrame(() => requestAnimationFrame(resolve));
1174
- });
1175
- }
1176
-
1177
- async function analyzeVisualContrast(options = {}) {
1178
- const candidates = collectVisualContrastCandidates(options);
1179
- const results = [];
1180
- const shouldScrollOffscreen = options.scrollOffscreen === true;
1181
- const restoreScroll = { x: window.scrollX, y: window.scrollY };
1182
- for (const candidate of candidates) {
1183
- if (shouldScrollOffscreen && (window.scrollX !== restoreScroll.x || window.scrollY !== restoreScroll.y)) {
1184
- window.scrollTo(restoreScroll.x, restoreScroll.y);
1185
- await waitForVisualPaint();
1186
- }
1187
- let result = await analyzeVisualContrastCandidate(candidate);
1188
- if (shouldScrollOffscreen && result.status === 'unresolved' && result.reason === 'text outside viewport') {
1189
- let el = null;
1190
- try {
1191
- el = document.querySelector(candidate.selector);
1192
- } catch {
1193
- el = null;
1194
- }
1195
- if (el && typeof el.scrollIntoView === 'function') {
1196
- el.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'instant' });
1197
- await waitForVisualPaint();
1198
- result = await analyzeVisualContrastCandidate(candidate);
1199
- }
1200
- }
1201
- results.push(result);
1202
- }
1203
- if (shouldScrollOffscreen && (window.scrollX !== restoreScroll.x || window.scrollY !== restoreScroll.y)) {
1204
- window.scrollTo(restoreScroll.x, restoreScroll.y);
1205
- }
1206
- return results;
1207
- }
1208
-
1209
- function isElementHidden(el) {
1210
- if (!el || el === document.body || el === document.documentElement) return false;
1211
- if (typeof el.checkVisibility === 'function') return !el.checkVisibility({ checkOpacity: false, checkVisibilityCSS: true });
1212
- // Fallback: zero size or no offsetParent (covers display:none and detached subtrees)
1213
- return el.offsetWidth === 0 && el.offsetHeight === 0;
1214
- }
1215
-
1216
- function serializeFindings(allFindings) {
1217
- return allFindings.map(({ el, findings }) => ({
1218
- selector: generateSelector(el),
1219
- tagName: el.tagName?.toLowerCase() || 'unknown',
1220
- rect: (el !== document.body && el !== document.documentElement && el.getBoundingClientRect)
1221
- ? el.getBoundingClientRect().toJSON() : null,
1222
- isPageLevel: el === document.body || el === document.documentElement,
1223
- isHidden: isElementHidden(el),
1224
- findings: findings.map(f => {
1225
- const ap = ANTIPATTERNS.find(a => a.id === (f.type || f.id));
1226
- return {
1227
- type: f.type || f.id,
1228
- category: ap ? ap.category : 'quality',
1229
- severity: f.severity || ap?.severity || 'warning',
1230
- // Advisory findings (em-dash overuse, etc.) are surfaced but never
1231
- // treated as failures; carry the flag so the overlay/extension can
1232
- // render them with the mildest affordance and consumers can filter.
1233
- advisory: (ap && ap.advisory === true) || f.advisory === true,
1234
- detail: f.detail || f.snippet,
1235
- ignoreValue: f.ignoreValue || f.value || '',
1236
- name: ap ? ap.name : (f.type || f.id),
1237
- description: ap ? ap.description : '',
1238
- };
1239
- }),
1240
- }));
1241
- }
1242
-
1243
- const printSummary = function(allFindings) {
1244
- if (allFindings.length === 0) {
1245
- console.log('%c[impeccable] No anti-patterns found.', 'color: #22c55e; font-weight: bold');
1246
- return;
1247
- }
1248
- console.group(
1249
- `%c[impeccable] ${allFindings.length} anti-pattern${allFindings.length === 1 ? '' : 's'} found`,
1250
- 'color: oklch(84% 0.19 80.46); font-weight: bold'
1251
- );
1252
- for (const { el, findings } of allFindings) {
1253
- for (const f of findings) {
1254
- console.log(`%c${f.type || f.id}%c ${f.detail || f.snippet}`,
1255
- 'color: oklch(84% 0.19 80.46); font-weight: bold', 'color: inherit', el);
1256
- }
1257
- }
1258
- console.groupEnd();
1259
- };
1260
-
1261
- function addBrowserFindings(groupMap, el, findings) {
1262
- if (!findings || findings.length === 0) return;
1263
- const existing = groupMap.get(el);
1264
- if (existing) existing.push(...findings);
1265
- else groupMap.set(el, [...findings]);
1266
- }
1267
-
1268
- function browserFindingsFromMap(groupMap) {
1269
- return [...groupMap.entries()].map(([el, findings]) => ({ el, findings }));
1270
- }
1271
-
1272
- const DESIGN_COLOR_TOLERANCE = 6;
1273
- const DESIGN_RADIUS_TOLERANCE_PX = 0.5;
1274
- const DESIGN_SKIP_TAGS = new Set(['head', 'title', 'meta', 'link', 'style', 'script', 'noscript', 'template', 'source']);
1275
-
1276
- function normalizeBrowserFontName(value) {
1277
- return String(value || '')
1278
- .trim()
1279
- .replace(/^["']|["']$/g, '')
1280
- .replace(/\+/g, ' ')
1281
- .replace(/\s+/g, ' ')
1282
- .toLowerCase();
1283
- }
1284
-
1285
- function browserPrimaryFont(stack) {
1286
- if (!stack || /var\(/i.test(stack)) return '';
1287
- return String(stack || '')
1288
- .split(',')
1289
- .map(normalizeBrowserFontName)
1290
- .find(font => font && !GENERIC_FONTS.has(font)) || '';
1291
- }
1292
-
1293
- function browserDesignSystemConfig() {
1294
- const raw = window.__IMPECCABLE_CONFIG__?.designSystem;
1295
- if (!raw?.present) return null;
1296
- const allowedFonts = new Set((raw.allowedFonts || []).map(normalizeBrowserFontName).filter(Boolean));
1297
- const allowedColors = (raw.allowedColors || [])
1298
- .filter(color => color && Number.isFinite(color.r) && Number.isFinite(color.g) && Number.isFinite(color.b))
1299
- .map(color => ({ r: color.r, g: color.g, b: color.b }));
1300
- const allowedRadii = (raw.allowedRadii || [])
1301
- .map(Number)
1302
- .filter(px => Number.isFinite(px));
1303
- return {
1304
- present: true,
1305
- hasFonts: raw.hasFonts === true && allowedFonts.size > 0,
1306
- allowedFonts,
1307
- hasColors: raw.hasColors === true && allowedColors.length > 0,
1308
- allowedColors,
1309
- hasRadii: raw.hasRadii === true && allowedRadii.length > 0,
1310
- allowedRadii,
1311
- hasPillRadius: raw.hasPillRadius === true,
1312
- };
1313
- }
1314
-
1315
- function browserColorsClose(a, b) {
1316
- if (!a || !b) return false;
1317
- return Math.max(
1318
- Math.abs(a.r - b.r),
1319
- Math.abs(a.g - b.g),
1320
- Math.abs(a.b - b.b),
1321
- ) <= DESIGN_COLOR_TOLERANCE;
1322
- }
1323
-
1324
- function isBrowserDesignColorAllowed(raw, designSystem) {
1325
- if (!designSystem?.hasColors) return true;
1326
- const text = String(raw || '').trim().toLowerCase();
1327
- if (!text || text === 'transparent' || text === 'currentcolor' || text === 'inherit' || text === 'initial') return true;
1328
- if (text.includes('var(')) return true;
1329
- const parsed = parseAnyColor(text);
1330
- if (!parsed) return true;
1331
- if ((parsed.a ?? 1) <= 0.05) return true;
1332
- return designSystem.allowedColors.some(color => browserColorsClose(parsed, color));
1333
- }
1334
-
1335
- function isBrowserTransparentCss(value) {
1336
- const text = String(value || '').trim().toLowerCase();
1337
- if (!text || text === 'transparent') return true;
1338
- const parsed = parseAnyColor(text);
1339
- return parsed ? (parsed.a ?? 1) <= 0.05 : false;
1340
- }
1341
-
1342
- function isBrowserDesignRadiusAllowed(raw, designSystem) {
1343
- if (!designSystem?.hasRadii) return true;
1344
- const text = String(raw || '').trim().toLowerCase();
1345
- if (!text || text === '0' || text === 'none' || text === 'initial' || text === 'inherit') return true;
1346
- if (text.includes('var(') || text.includes('%')) return true;
1347
- const px = resolveLengthPx(text, 16);
1348
- if (px == null || !Number.isFinite(px) || px <= DESIGN_RADIUS_TOLERANCE_PX) return true;
1349
- if (designSystem.hasPillRadius && px >= 99) return true;
1350
- return designSystem.allowedRadii.some(allowed => Math.abs(allowed - px) <= DESIGN_RADIUS_TOLERANCE_PX);
1351
- }
1352
-
1353
- function browserRadiusTokens(value) {
1354
- return String(value || '')
1355
- .replace(/\s*\/\s*/g, ' ')
1356
- .split(/\s+/)
1357
- .map(token => token.trim())
1358
- .filter(Boolean);
1359
- }
1360
-
1361
- function browserHasDirectText(el) {
1362
- return [...(el.childNodes || [])].some(node => node.nodeType === 3 && node.textContent.trim().length > 0);
1363
- }
1364
-
1365
- function browserSampleText(el) {
1366
- const text = String(el.textContent || '').replace(/\s+/g, ' ').trim();
1367
- return text ? ` "${text.slice(0, 40)}"` : '';
1368
- }
1369
-
1370
- function shouldSkipDesignElement(el) {
1371
- const tag = el.tagName?.toLowerCase?.() || '';
1372
- return DESIGN_SKIP_TAGS.has(tag) || isElementHidden(el);
1373
- }
1374
-
1375
- function checkElementDesignSystemDOM(el, designSystem, seen) {
1376
- if (!designSystem?.present || shouldSkipDesignElement(el)) return [];
1377
- const findings = [];
1378
- const tag = el.tagName?.toLowerCase?.() || 'unknown';
1379
- const style = getComputedStyle(el);
1380
-
1381
- if (designSystem.hasFonts && browserHasDirectText(el)) {
1382
- const font = browserPrimaryFont(style.fontFamily || '');
1383
- if (font && !designSystem.allowedFonts.has(font) && !seen.fonts.has(font)) {
1384
- seen.fonts.add(font);
1385
- findings.push({
1386
- type: 'design-system-font',
1387
- detail: `${tag}${browserSampleText(el)} uses ${font}; not declared in DESIGN.md typography`,
1388
- ignoreValue: font,
1389
- });
1390
- }
1391
- }
1392
-
1393
- if (designSystem.hasColors) {
1394
- const colorChecks = [];
1395
- if (browserHasDirectText(el)) colorChecks.push(['text color', style.color]);
1396
- if (!isBrowserTransparentCss(style.backgroundColor)) colorChecks.push(['background', style.backgroundColor]);
1397
- for (const side of ['Top', 'Right', 'Bottom', 'Left']) {
1398
- if ((parseFloat(style[`border${side}Width`]) || 0) > 0) {
1399
- colorChecks.push([`border-${side.toLowerCase()}`, style[`border${side}Color`]]);
1400
- }
1401
- }
1402
- if ((parseFloat(style.outlineWidth) || 0) > 0) colorChecks.push(['outline', style.outlineColor]);
1403
-
1404
- for (const [kind, raw] of colorChecks) {
1405
- const label = String(raw || '').trim().replace(/\s+/g, ' ');
1406
- if (isBrowserDesignColorAllowed(label, designSystem)) continue;
1407
- const key = `${kind}:${label}`;
1408
- if (seen.colors.has(key)) continue;
1409
- seen.colors.add(key);
1410
- findings.push({
1411
- type: 'design-system-color',
1412
- detail: `${kind} ${label} on ${tag}${browserSampleText(el)} is outside DESIGN.md colors`,
1413
- ignoreValue: label,
1414
- });
1415
- }
1416
- }
1417
-
1418
- if (designSystem.hasRadii) {
1419
- for (const token of browserRadiusTokens(style.borderRadius || '')) {
1420
- if (isBrowserDesignRadiusAllowed(token, designSystem)) continue;
1421
- if (seen.radii.has(token)) continue;
1422
- seen.radii.add(token);
1423
- findings.push({
1424
- type: 'design-system-radius',
1425
- detail: `border-radius ${token} on ${tag}${browserSampleText(el)} is outside the DESIGN.md rounded scale`,
1426
- ignoreValue: token,
1427
- });
1428
- }
1429
- }
1430
-
1431
- return findings;
1432
- }
1433
-
1434
- function decodeBrowserGoogleFamily(value) {
1435
- const family = String(value || '').split(':')[0].replace(/\+/g, ' ');
1436
- try {
1437
- return decodeURIComponent(family);
1438
- } catch {
1439
- return family;
1440
- }
1441
- }
1442
-
1443
- function checkBrowserDesignSystemSources(designSystem, seen) {
1444
- if (!designSystem?.hasFonts) return [];
1445
- const findings = [];
1446
- for (const link of document.querySelectorAll('link[href*="fonts.googleapis.com/css"]')) {
1447
- const href = link.getAttribute('href') || '';
1448
- for (const match of href.matchAll(/[?&]family=([^&]+)/g)) {
1449
- const display = decodeBrowserGoogleFamily(match[1]);
1450
- const font = normalizeBrowserFontName(display);
1451
- if (!font || designSystem.allowedFonts.has(font) || seen.fonts.has(font)) continue;
1452
- seen.fonts.add(font);
1453
- findings.push({
1454
- type: 'design-system-font',
1455
- detail: `Google Fonts: ${display} is not declared in DESIGN.md typography`,
1456
- ignoreValue: display,
1457
- });
1458
- }
1459
- }
1460
- return findings;
1461
- }
1462
-
1463
- function collectBrowserFindings() {
1464
- const groupMap = new Map();
1465
- const _disabled = EXTENSION_MODE ? (window.__IMPECCABLE_CONFIG__?.disabledRules || []) : [];
1466
- const _ruleOk = (id) => !_disabled.length || !_disabled.includes(id);
1467
- const designSystem = browserDesignSystemConfig();
1468
- const designSeen = { fonts: new Set(), colors: new Set(), radii: new Set() };
1469
- // All deterministic rules run in the browser and extension path.
1470
-
1471
- for (const el of document.querySelectorAll('*')) {
1472
- // Skip impeccable's own elements and any descendants (overlays, labels, banner, nav buttons)
1473
- if (el.closest('.impeccable-overlay, .impeccable-label, .impeccable-banner, .impeccable-tooltip')) continue;
1474
- // Skip browser extension elements (Claude, etc.). Use getAttribute when
1475
- // `el.id` is not a string: a <form> with a named control like
1476
- // <input name="id"> shadows the builtin `id` getter and returns the
1477
- // element, whose `.startsWith` throws (issue #407).
1478
- const elId = typeof el.id === 'string' ? el.id : (el.getAttribute('id') || '');
1479
- if (elId.startsWith('claude-') || elId.startsWith('cic-')) continue;
1480
- // Skip the impeccable live-mode overlay (highlight, tooltip, bar, picker, toast).
1481
- // These are inspector chrome, not part of the user's design.
1482
- if (el.closest('[id^="impeccable-live-"]')) continue;
1483
- // Skip html/body -- page-level findings go in the banner, not a full-page overlay
1484
- if (el === document.body || el === document.documentElement) continue;
1485
-
1486
- const findings = [
1487
- ...checkElementBordersDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1488
- ...checkElementPseudoStripeDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1489
- ...checkElementColorsDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1490
- ...checkElementMotionDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1491
- ...checkElementGlowDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1492
- ...checkElementAIPaletteDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1493
- ...checkElementRadialSpotlightDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1494
- ...checkElementIconTileDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1495
- ...checkElementItalicSerifDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1496
- ...checkElementQualityDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1497
- ...checkElementOversizedH1DOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1498
- ...checkElementClippedOverflowDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1499
- ...checkElementGptBorderShadowDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1500
- ...checkElementTextOverflowDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
1501
- ...checkElementBlinkingCursorDOM(el).map(f => ({ type: f.id, detail: f.snippet, ...(f.severity ? { severity: f.severity } : {}) })),
1502
- ...checkElementDesignSystemDOM(el, designSystem, designSeen),
1503
- ].filter(f => _ruleOk(f.type));
1504
-
1505
- addBrowserFindings(groupMap, el, findings);
1506
-
1507
- // Hero eyebrow: the offending element is the eyebrow above the heading,
1508
- // not the heading itself — highlight the previous sibling instead.
1509
- const eyebrowFindings = checkElementHeroEyebrowDOM(el)
1510
- .map(f => ({ type: f.id, detail: f.snippet }))
1511
- .filter(f => _ruleOk(f.type));
1512
- if (eyebrowFindings.length > 0 && el.previousElementSibling) {
1513
- addBrowserFindings(groupMap, el.previousElementSibling, eyebrowFindings);
1514
- }
1515
- }
1516
-
1517
- const pageLevelFindings = [];
1518
-
1519
- const designSourceFindings = checkBrowserDesignSystemSources(designSystem, designSeen)
1520
- .filter(f => _ruleOk(f.type));
1521
- if (designSourceFindings.length > 0) {
1522
- pageLevelFindings.push(...designSourceFindings);
1523
- addBrowserFindings(groupMap, document.body, designSourceFindings);
1524
- }
1525
-
1526
- const typoFindings = checkTypography().filter(f => _ruleOk(f.type));
1527
- if (typoFindings.length > 0) {
1528
- pageLevelFindings.push(...typoFindings);
1529
- addBrowserFindings(groupMap, document.body, typoFindings);
1530
- }
1531
-
1532
- const sectionKickerFindings = checkKickerAboveHeadingDOM()
1533
- .map(f => ({ type: f.id, detail: f.snippet }))
1534
- .filter(f => _ruleOk(f.type));
1535
- if (sectionKickerFindings.length > 0) {
1536
- pageLevelFindings.push(...sectionKickerFindings);
1537
- addBrowserFindings(groupMap, document.body, sectionKickerFindings);
1538
- }
1539
-
1540
- const numberedLabelFindings = checkNumberedSectionLabelsDOM()
1541
- .map(f => ({ type: f.id, detail: f.snippet }))
1542
- .filter(f => _ruleOk(f.type));
1543
- if (numberedLabelFindings.length > 0) {
1544
- pageLevelFindings.push(...numberedLabelFindings);
1545
- addBrowserFindings(groupMap, document.body, numberedLabelFindings);
1546
- }
1547
-
1548
- const repeatedTextFindings = checkRepeatedContainerTextDOM()
1549
- .map(f => ({ type: f.id, detail: f.snippet }))
1550
- .filter(f => _ruleOk(f.type));
1551
- if (repeatedTextFindings.length > 0) {
1552
- pageLevelFindings.push(...repeatedTextFindings);
1553
- addBrowserFindings(groupMap, document.body, repeatedTextFindings);
1554
- }
1555
-
1556
- // Em-dash overuse (advisory): browser parity with the static/regex path.
1557
- // Reads rendered body text so it catches dashes written as HTML entities.
1558
- // serializeFindings stamps the advisory flag from the registry.
1559
- const emDashFindings = checkEmDashOveruseDOM()
1560
- .map(f => ({ type: f.id, detail: f.snippet }))
1561
- .filter(f => _ruleOk(f.type));
1562
- if (emDashFindings.length > 0) {
1563
- pageLevelFindings.push(...emDashFindings);
1564
- addBrowserFindings(groupMap, document.body, emDashFindings);
1565
- }
1566
-
1567
- const layoutFindings = checkLayout().filter(f => _ruleOk(f.type));
1568
- for (const f of layoutFindings) {
1569
- const el = f.el || document.body;
1570
- addBrowserFindings(groupMap, el, [{ type: f.type, detail: f.detail || f.snippet }]);
1571
- }
1572
-
1573
- // Heading rhythm (browser-only: needs real layout for the gap math)
1574
- const headingRhythmFindings = checkHeadingRhythmDOM().filter(f => _ruleOk(f.type));
1575
- for (const f of headingRhythmFindings) {
1576
- addBrowserFindings(groupMap, f.el || document.body, [{ type: f.type, detail: f.detail }]);
1577
- }
1578
-
1579
- // Edge-flush cards in horizontal scrollers (browser-only: needs real
1580
- // layout for the scroller clip box vs card rect math)
1581
- const edgeFlushFindings = checkEdgeFlushCardsDOM().filter(f => _ruleOk(f.type));
1582
- for (const f of edgeFlushFindings) {
1583
- addBrowserFindings(groupMap, f.el || document.body, [{ type: f.type, detail: f.detail }]);
1584
- }
1585
-
1586
- // Text occlusion / element overlap (browser-only: needs real layout +
1587
- // elementFromPoint to confirm what actually paints on top)
1588
- const occlusionFindings = checkTextOcclusionDOM().filter(f => _ruleOk(f.type));
1589
- for (const f of occlusionFindings) {
1590
- addBrowserFindings(groupMap, f.el || document.body, [{ type: f.type, detail: f.detail }]);
1591
- }
1592
-
1593
- // First-viewport column overflow — the stretched-hero signature
1594
- // (browser-only: needs real layout for the content-extent math)
1595
- const colOverflowFindings = checkFirstViewportColumnOverflowDOM().filter(f => _ruleOk(f.type));
1596
- for (const f of colOverflowFindings) {
1597
- addBrowserFindings(groupMap, f.el || document.body, [{ type: f.type, detail: f.detail }]);
1598
- }
1599
-
1600
- // Page-level quality checks (headings, etc.)
1601
- const qualityFindings = checkPageQualityDOM().filter(f => _ruleOk(f.type));
1602
- if (qualityFindings.length > 0) {
1603
- pageLevelFindings.push(...qualityFindings);
1604
- addBrowserFindings(groupMap, document.body, qualityFindings);
1605
- }
1606
-
1607
- const creamFindings = checkCreamPalette(document)
1608
- .map(f => ({ type: f.id, detail: f.snippet }))
1609
- .filter(f => _ruleOk(f.type));
1610
- if (creamFindings.length > 0) {
1611
- pageLevelFindings.push(...creamFindings);
1612
- addBrowserFindings(groupMap, document.body, creamFindings);
1613
- }
1614
-
1615
- // Regex-on-HTML checks (shared with Node)
1616
- // Clone the document and strip impeccable-live overlay nodes before the
1617
- // regex scan, so the inspector's own inline styles (transitions on top/
1618
- // left/width/height, etc.) don't register as page anti-patterns.
1619
- const docClone = document.documentElement.cloneNode(true);
1620
- for (const node of docClone.querySelectorAll('[id^="impeccable-live-"]')) {
1621
- node.remove();
1622
- }
1623
- const htmlPatternFindings = checkHtmlPatterns(docClone.outerHTML);
1624
- if (htmlPatternFindings.length > 0) {
1625
- const mapped = htmlPatternFindings.map(f => {
1626
- const item = { type: f.id, detail: f.snippet };
1627
- if (f.severity) {
1628
- item.severity = f.severity;
1629
- } else if (f.id === 'pulsing-dot' && f.selector) {
1630
- // The string scan promotes header/nav dots on its own; with a live
1631
- // layout also promote dots resting in the first ~900px of the page
1632
- // (the hero region), which the source scan cannot measure.
1633
- try {
1634
- const dotEl = document.querySelector(f.selector);
1635
- if (dotEl) {
1636
- const rect = dotEl.getBoundingClientRect();
1637
- const pageTop = rect.top + (window.scrollY || 0);
1638
- if (pageTop <= 900) item.severity = 'error';
1639
- }
1640
- } catch { /* unresolvable selector: keep registry severity */ }
1641
- }
1642
- return item;
1643
- }).filter(f => _ruleOk(f.type));
1644
- pageLevelFindings.push(...mapped);
1645
- addBrowserFindings(groupMap, document.body, mapped);
1646
- }
1647
-
1648
- return {
1649
- groupMap,
1650
- allFindings: browserFindingsFromMap(groupMap),
1651
- pageLevelFindings,
1652
- };
1653
- }
1654
-
1655
- function shouldRunVisualContrast(options = {}) {
1656
- return options.visualContrast === true || window.__IMPECCABLE_CONFIG__?.visualContrast === true;
1657
- }
1658
-
1659
- function visualContrastOptions(options = {}) {
1660
- const config = window.__IMPECCABLE_CONFIG__ || {};
1661
- const scrollOffscreen = typeof options.scrollOffscreen === 'boolean'
1662
- ? options.scrollOffscreen
1663
- : typeof options.visualContrastScrollOffscreen === 'boolean'
1664
- ? options.visualContrastScrollOffscreen
1665
- : typeof config.visualContrastScrollOffscreen === 'boolean'
1666
- ? config.visualContrastScrollOffscreen
1667
- : false;
1668
- return {
1669
- ...options,
1670
- maxCandidates: Number.isFinite(options.visualContrastMaxCandidates)
1671
- ? options.visualContrastMaxCandidates
1672
- : Number.isFinite(options.maxCandidates)
1673
- ? options.maxCandidates
1674
- : Number.isFinite(config.visualContrastMaxCandidates)
1675
- ? config.visualContrastMaxCandidates
1676
- : undefined,
1677
- scrollOffscreen,
1678
- };
1679
- }
1680
-
1681
- let lastVisualContrastAnalyses = [];
1682
- let lazyVisualContrastObserver = null;
1683
- let lazyVisualContrastPending = new WeakMap();
1684
- const lazyVisualContrastResolving = new WeakSet();
1685
- let scanGeneration = 0;
1686
-
1687
- function rememberVisualContrastAnalysis(result) {
1688
- if (!result?.selector) {
1689
- lastVisualContrastAnalyses.push(result);
1690
- return;
1691
- }
1692
- const idx = lastVisualContrastAnalyses.findIndex(item => item.selector === result.selector);
1693
- if (idx >= 0) lastVisualContrastAnalyses[idx] = result;
1694
- else lastVisualContrastAnalyses.push(result);
1695
- }
1696
-
1697
- function disconnectLazyVisualContrastObserver() {
1698
- if (lazyVisualContrastObserver) {
1699
- lazyVisualContrastObserver.disconnect();
1700
- lazyVisualContrastObserver = null;
1701
- }
1702
- lazyVisualContrastPending = new WeakMap();
1703
- }
1704
-
1705
- function addVisualContrastResult(groupMap, result, options = {}) {
1706
- if (result.status !== 'fail' || !result.finding || !result.selector) return false;
1707
- let el = null;
1708
- try {
1709
- el = document.querySelector(result.selector);
1710
- } catch {
1711
- el = null;
1712
- }
1713
- if (!el) return false;
1714
- const findingType = result.finding.type || result.finding.id || 'low-contrast';
1715
- const existing = groupMap.get(el) || [];
1716
- if (existing.some(f => (f.type || f.id) === findingType)) return false;
1717
- addBrowserFindings(groupMap, el, [{
1718
- type: findingType,
1719
- detail: result.finding.detail || result.finding.snippet,
1720
- }]);
1721
- if (options.decorate && el !== document.body && el !== document.documentElement) {
1722
- highlight(el, groupMap.get(el) || []);
1723
- }
1724
- return true;
1725
- }
1726
-
1727
- function scanResultMeta(options = {}) {
1728
- const scanId = options.scanId;
1729
- if (typeof scanId !== 'string' && typeof scanId !== 'number') return {};
1730
- return { scanId: String(scanId) };
1731
- }
1732
-
1733
- function postSerializedFindings(groupMap, options = {}) {
1734
- if (!EXTENSION_MODE) return;
1735
- const allFindings = browserFindingsFromMap(groupMap);
1736
- window.postMessage({
1737
- source: 'impeccable-results',
1738
- findings: serializeFindings(allFindings),
1739
- count: allFindings.length,
1740
- ...scanResultMeta(options),
1741
- }, '*');
1742
- }
1743
-
1744
- function postExtensionError(err) {
1745
- if (!EXTENSION_MODE) return;
1746
- window.postMessage({
1747
- source: 'impeccable-error',
1748
- message: err?.message || String(err),
1749
- }, '*');
1750
- }
1751
-
1752
- function reportVisualContrastError(err, detail = {}) {
1753
- window.dispatchEvent(new CustomEvent('impeccable-visual-contrast-error', {
1754
- detail: {
1755
- ...detail,
1756
- message: err?.message || String(err),
1757
- },
1758
- }));
1759
- if (EXTENSION_MODE) {
1760
- postExtensionError(err);
1761
- } else {
1762
- console.warn('[impeccable] visual contrast scan failed', err);
1763
- }
1764
- }
1765
-
1766
- function scheduleLazyVisualContrast(groupMap, analyses, options = {}, runtime = {}) {
1767
- disconnectLazyVisualContrastObserver();
1768
- if (options.visualContrastLazy === false || options.scrollOffscreen !== false) return;
1769
- if (typeof IntersectionObserver === 'undefined') return;
1770
- const unresolved = (analyses || []).filter(result =>
1771
- result?.status === 'unresolved' &&
1772
- result.reason === 'text outside viewport' &&
1773
- result.selector
1774
- );
1775
- if (unresolved.length === 0) return;
1776
- const generation = runtime.generation || scanGeneration;
1777
-
1778
- lazyVisualContrastObserver = new IntersectionObserver((entries) => {
1779
- for (const entry of entries) {
1780
- if (!entry.isIntersecting) continue;
1781
- const el = entry.target;
1782
- const candidate = lazyVisualContrastPending.get(el);
1783
- if (!candidate || lazyVisualContrastResolving.has(el)) continue;
1784
- lazyVisualContrastObserver?.unobserve(el);
1785
- lazyVisualContrastPending.delete(el);
1786
- lazyVisualContrastResolving.add(el);
1787
- waitForVisualPaint()
1788
- .then(() => analyzeVisualContrastCandidate(candidate))
1789
- .then(result => {
1790
- if (generation !== scanGeneration) return;
1791
- rememberVisualContrastAnalysis(result);
1792
- const added = addVisualContrastResult(groupMap, result, { decorate: true });
1793
- if (added) {
1794
- postSerializedFindings(groupMap, options);
1795
- window.dispatchEvent(new CustomEvent('impeccable-visual-contrast-resolved', {
1796
- detail: {
1797
- selector: result.selector,
1798
- status: result.status,
1799
- finding: result.finding || null,
1800
- },
1801
- }));
1802
- }
1803
- })
1804
- .catch(err => {
1805
- reportVisualContrastError(err, { selector: candidate.selector });
1806
- })
1807
- .finally(() => {
1808
- lazyVisualContrastResolving.delete(el);
1809
- });
1810
- }
1811
- }, { threshold: 0.5 });
1812
-
1813
- for (const candidate of unresolved) {
1814
- let el = null;
1815
- try {
1816
- el = document.querySelector(candidate.selector);
1817
- } catch {
1818
- el = null;
1819
- }
1820
- if (!el) continue;
1821
- lazyVisualContrastPending.set(el, candidate);
1822
- lazyVisualContrastObserver.observe(el);
1823
- }
1824
- }
1825
-
1826
- async function addVisualContrastFindings(groupMap, options = {}, runtime = {}) {
1827
- if (!shouldRunVisualContrast(options)) {
1828
- lastVisualContrastAnalyses = [];
1829
- disconnectLazyVisualContrastObserver();
1830
- return [];
1831
- }
1832
- const resolvedOptions = visualContrastOptions(options);
1833
- const analyses = await analyzeVisualContrast(resolvedOptions);
1834
- if (runtime.generation && runtime.generation !== scanGeneration) return analyses;
1835
- lastVisualContrastAnalyses = analyses;
1836
- for (const result of analyses) {
1837
- addVisualContrastResult(groupMap, result, { decorate: runtime.decorate });
1838
- }
1839
- if (runtime.decorate || runtime.scheduleLazy) scheduleLazyVisualContrast(groupMap, analyses, resolvedOptions, runtime);
1840
- return analyses;
1841
- }
1842
-
1843
- async function collectBrowserFindingsAsync(options = {}, runtime = {}) {
1844
- const collected = collectBrowserFindings();
1845
- await addVisualContrastFindings(collected.groupMap, options, runtime);
1846
- return {
1847
- ...collected,
1848
- allFindings: browserFindingsFromMap(collected.groupMap),
1849
- visualContrastAnalyses: lastVisualContrastAnalyses,
1850
- };
1851
- }
1852
-
1853
- function clearOverlays() {
1854
- scanGeneration += 1;
1855
- disconnectLazyVisualContrastObserver();
1856
- for (const o of [...overlays]) detachOverlay(o);
1857
- overlays.length = 0;
1858
- visibilityObserver.disconnect();
1859
- overlayIndex = 0;
1860
- }
1861
-
1862
- function renderBrowserFindings(collected, options = {}) {
1863
- const { allFindings, pageLevelFindings } = collected;
1864
-
1865
- for (const { el, findings } of allFindings) {
1866
- if (el === document.body || el === document.documentElement) continue;
1867
- highlight(el, findings);
1868
- }
1869
-
1870
- if (pageLevelFindings.length > 0) {
1871
- showPageBanner(pageLevelFindings);
1872
- }
1873
-
1874
- if (!EXTENSION_MODE) printSummary(allFindings);
1875
-
1876
- // In extension mode, post serialized results for the DevTools panel
1877
- if (EXTENSION_MODE) {
1878
- window.postMessage({
1879
- source: 'impeccable-results',
1880
- findings: serializeFindings(allFindings),
1881
- count: allFindings.length,
1882
- ...scanResultMeta(options),
1883
- }, '*');
1884
- }
1885
-
1886
- // After this scan completes, all subsequent reveals are instant (no stagger, no animation)
1887
- setTimeout(() => { firstScanDone = true; }, 1000);
1888
-
1889
- return allFindings;
1890
- }
1891
-
1892
- let firstScanDone = false;
1893
- const scan = function(options = {}) {
1894
- clearOverlays();
1895
- const generation = scanGeneration;
1896
- const collected = collectBrowserFindings();
1897
- const allFindings = renderBrowserFindings(collected, options);
1898
- if (shouldRunVisualContrast(options)) {
1899
- addVisualContrastFindings(collected.groupMap, options, { decorate: true, generation })
1900
- .then(() => {
1901
- if (generation === scanGeneration) postSerializedFindings(collected.groupMap, options);
1902
- })
1903
- .catch(err => {
1904
- reportVisualContrastError(err);
1905
- });
1906
- }
1907
- return allFindings;
1908
- };
1909
-
1910
- const scanAsync = async function(options = {}) {
1911
- clearOverlays();
1912
- const generation = scanGeneration;
1913
- if (shouldRunVisualContrast(options)) {
1914
- const collected = await collectBrowserFindingsAsync(options, { generation, scheduleLazy: true });
1915
- if (generation !== scanGeneration) return [];
1916
- return renderBrowserFindings(collected, options);
1917
- }
1918
- lastVisualContrastAnalyses = [];
1919
- return renderBrowserFindings(collectBrowserFindings(), options);
1920
- };
1921
-
1922
- const detect = function(options = {}) {
1923
- lastVisualContrastAnalyses = [];
1924
- const { allFindings } = collectBrowserFindings();
1925
- return options.serialize === false ? allFindings : serializeFindings(allFindings);
1926
- };
1927
-
1928
- const detectAsync = async function(options = {}) {
1929
- if (shouldRunVisualContrast(options)) {
1930
- const { allFindings } = await collectBrowserFindingsAsync(options);
1931
- return options.serialize === false ? allFindings : serializeFindings(allFindings);
1932
- }
1933
- lastVisualContrastAnalyses = [];
1934
- const { allFindings } = collectBrowserFindings();
1935
- return options.serialize === false ? allFindings : serializeFindings(allFindings);
1936
- };
1937
-
1938
- if (EXTENSION_MODE) {
1939
- // Extension mode: listen for commands, don't auto-scan
1940
- window.addEventListener('message', (e) => {
1941
- if (e.source !== window || !e.data || e.data.source !== 'impeccable-command') return;
1942
- if (e.data.action === 'scan') {
1943
- if (e.data.config) window.__IMPECCABLE_CONFIG__ = e.data.config;
1944
- try {
1945
- scan(e.data.config || {});
1946
- } catch (err) {
1947
- postExtensionError(err);
1948
- }
1949
- }
1950
- if (e.data.action === 'toggle-overlays') {
1951
- const visible = !document.body.classList.contains('impeccable-hidden');
1952
- document.body.classList.toggle('impeccable-hidden', visible);
1953
- window.postMessage({ source: 'impeccable-overlays-toggled', visible: !visible }, '*');
1954
- }
1955
- if (e.data.action === 'remove') {
1956
- clearOverlays();
1957
- styleEl.remove();
1958
- if (spotlightBackdrop) { spotlightBackdrop.remove(); spotlightBackdrop = null; }
1959
- document.body.classList.remove('impeccable-hidden');
1960
- }
1961
- if (e.data.action === 'highlight') {
1962
- try {
1963
- const target = e.data.selector ? document.querySelector(e.data.selector) : null;
1964
- if (target) {
1965
- // Scroll first so positionOverlay reads the post-scroll rect
1966
- if (!isInViewport(target) && target.scrollIntoView) {
1967
- target.scrollIntoView({ behavior: 'instant', block: 'center' });
1968
- }
1969
- for (const o of overlays) {
1970
- if (o.classList.contains('impeccable-banner')) continue;
1971
- const isMatch = o._targetEl === target;
1972
- o.classList.toggle('impeccable-spotlight', isMatch);
1973
- o.classList.toggle('impeccable-spotlight-dimmed', !isMatch);
1974
- if (isMatch) {
1975
- // Force the matching overlay visible immediately, don't wait for IntersectionObserver
1976
- o.style.display = '';
1977
- o.style.animation = 'none';
1978
- o.classList.add('impeccable-visible');
1979
- o._revealed = true;
1980
- positionOverlay(o);
1981
- }
1982
- }
1983
- showSpotlight(target);
1984
- }
1985
- } catch { /* invalid selector */ }
1986
- }
1987
- if (e.data.action === 'unhighlight') {
1988
- hideSpotlight();
1989
- for (const o of overlays) {
1990
- o.classList.remove('impeccable-spotlight');
1991
- o.classList.remove('impeccable-spotlight-dimmed');
1992
- }
1993
- }
1994
- });
1995
- window.postMessage({ source: 'impeccable-ready' }, '*');
1996
- } else {
1997
- if (window.__IMPECCABLE_CONFIG__?.autoScan !== false) {
1998
- const runAutoScan = () => {
1999
- try {
2000
- scan();
2001
- } catch (err) {
2002
- console.warn('[impeccable] scan failed', err);
2003
- }
2004
- };
2005
- if (document.readyState === 'loading') {
2006
- document.addEventListener('DOMContentLoaded', () => setTimeout(runAutoScan, 100));
2007
- } else {
2008
- setTimeout(runAutoScan, 100);
2009
- }
2010
- }
2011
- }
2012
-
2013
- window.impeccableDetect = detect;
2014
- window.impeccableDetectAsync = detectAsync;
2015
- window.impeccableScan = scan;
2016
- window.impeccableScanAsync = scanAsync;
2017
- // Raw measurement for the URL engine's content-hidden-at-rest pass: it
2018
- // drives a reveal sweep from Node and thresholds the result itself.
2019
- window.impeccableMeasureHiddenText = measureHiddenTextDOM;
2020
- window.impeccableCollectVisualContrastCandidates = collectVisualContrastCandidates;
2021
- window.impeccableAnalyzeVisualContrast = analyzeVisualContrast;
2022
- window.impeccableGetLastVisualContrastAnalyses = () => lastVisualContrastAnalyses.slice();
2023
- }