← Files Visual TruthARCHIVED FILE

skills/visual-truth/assets/visual-truth-generated.ts

2.57 KB · Oct 2, 2026 · 00:29 UTC

↓ Download file

// Generated by Visual Truth. Review in source control before publishing.
const media = { desktop: '(min-width: 1101px)', tablet: '(min-width: 681px) and (max-width: 1100px)', phone: '(max-width: 680px)' } as const
type Patch = { selector: string; previousSelector?: string; property: string; value: string; kind: string; parentSelector?: string; index?: number; html?: string; device?: keyof typeof media }
export const visualTruthPatches = [] as const satisfies readonly Patch[]

function target(selector: string, previousSelector?: string) {
  return document.querySelector<HTMLElement>(selector) ?? (previousSelector ? document.querySelector<HTMLElement>(previousSelector) : null)
}

function applyPatch(patch: Patch) {
  if (patch.device && !window.matchMedia(media[patch.device]).matches) return
  const element = target(patch.selector, patch.previousSelector)
  if (patch.kind === 'style' || patch.kind === 'responsive-style') { if (element?.style.getPropertyValue(patch.property) !== patch.value) element?.style.setProperty(patch.property, patch.value); return }
  if (patch.kind === 'text') { if (element && element.innerText !== patch.value) element.innerText = patch.value; return }
  if (patch.kind === 'attribute') { const name = patch.property.slice('attribute:'.length); if (patch.value && element?.getAttribute(name) !== patch.value) element?.setAttribute(name, patch.value); else if (!patch.value && element?.hasAttribute(name)) element.removeAttribute(name); return }
  const parent = patch.parentSelector ? document.querySelector<HTMLElement>(patch.parentSelector) : null
  if (patch.kind === 'remove') { element?.remove(); return }
  if (patch.kind === 'insert' && parent && !element && patch.html) { const box = document.createElement('template'); box.innerHTML = patch.html.trim(); const node = box.content.firstElementChild; if (node) parent.insertBefore(node, parent.children.item(patch.index ?? parent.children.length)); return }
  if (patch.kind === 'reorder' && parent && element) parent.insertBefore(element, parent.children.item(patch.index ?? 0))
}

export function installVisualTruthPatches() {
  let queued = false
  const apply = () => { queued = false; (visualTruthPatches as readonly Patch[]).forEach(applyPatch) }
  const schedule = () => { if (!queued) { queued = true; window.requestAnimationFrame(apply) } }
  schedule()
  window.addEventListener('resize', schedule)
  const observer = new MutationObserver(schedule)
  observer.observe(document.documentElement, { childList: true, subtree: true })
  return () => { observer.disconnect(); window.removeEventListener('resize', schedule) }
}

SHA-256: 577179822ed58981f26cc1dc83b6f8c0e2fd74038b25ff737b05da2d13824185