writetrack 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/pipes.js CHANGED
@@ -1 +1 @@
1
- function u(n){let{url:o,headers:a={},retries:t=0,backoffMs:e=100,maxBackoffMs:i=3e4,keepalive:s=!1}=n;return{async send(p){let m=null;for(let c=0;c<=t;c++){if(c>0){let r=Math.min(e*Math.pow(2,c-1),i);await new Promise(d=>setTimeout(d,r))}try{let r=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",...a},body:JSON.stringify(p),keepalive:s});if(r.ok)return;m=new Error(`Webhook failed: ${r.status} ${r.statusText}`)}catch(r){m=r instanceof Error?r:new Error(String(r))}}throw m}}}function l(n){let{client:o,actionName:a="writetrack_session",tags:t={}}=n;return{async send(e){let i={...t,duration:e.metadata.duration,keystrokeCount:e.session.events.length,qualityLevel:e.quality.qualityLevel,targetElement:e.metadata.targetElement,schemaVersion:e.version};e.metadata.userId&&(i.userId=e.metadata.userId),e.metadata.contentId&&(i.contentId=e.metadata.contentId),e.metadata.custom&&(i.custom=e.metadata.custom);try{o.addAction(a,i)}catch(s){throw new Error(`Datadog addAction failed: ${s instanceof Error?s.message:String(s)}`)}}}}function k(n){let{client:o,eventName:a="WriteTrack Session"}=n;return{async send(t){let e={duration:t.metadata.duration,keystrokeCount:t.session.events.length,qualityLevel:t.quality.qualityLevel,targetElement:t.metadata.targetElement,schemaVersion:t.version};t.metadata.userId&&(e.userId=t.metadata.userId),t.metadata.contentId&&(e.contentId=t.metadata.contentId),t.metadata.custom&&(e.custom=t.metadata.custom),o.track(a,e)}}}function f(n){let{tracer:o,spanName:a="writetrack.session"}=n;return{async send(t){let e=o.startSpan(a);try{e.setAttribute("writetrack.duration",t.metadata.duration),e.setAttribute("writetrack.keystroke_count",t.session.events.length),e.setAttribute("writetrack.quality_level",t.quality.qualityLevel),e.setAttribute("writetrack.target_element",t.metadata.targetElement),e.setAttribute("writetrack.schema_version",t.version),t.metadata.userId&&e.setAttribute("writetrack.user_id",t.metadata.userId),t.metadata.contentId&&e.setAttribute("writetrack.content_id",t.metadata.contentId),e.setStatus({code:1})}finally{e.end()}}}}export{l as datadog,f as opentelemetry,k as segment,u as webhook};
1
+ function p(n){let{url:o,headers:i={},retries:t=0,backoffMs:e=100,maxBackoffMs:a=3e4,keepalive:c=!1}=n;return{async send(f){let u=null;for(let s=0;s<=t;s++){if(s>0){let r=Math.min(e*Math.pow(2,s-1),a);await new Promise(l=>setTimeout(l,r))}try{let r=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",...i},body:JSON.stringify(f),keepalive:c});if(r.ok)return;u=new Error(`Webhook failed: ${r.status} ${r.statusText}`)}catch(r){u=r instanceof Error?r:new Error(String(r))}}throw u}}}function m(n){return n instanceof Error?n.message:String(n)}function d(n){let{client:o,actionName:i="writetrack_session",tags:t={}}=n;return{async send(e){let a={...t,duration:e.metadata.duration,keystrokeCount:e.session.events.length,qualityLevel:e.quality.qualityLevel,targetElement:e.metadata.targetElement,schemaVersion:e.version};e.metadata.userId&&(a.userId=e.metadata.userId),e.metadata.contentId&&(a.contentId=e.metadata.contentId),e.metadata.custom&&(a.custom=e.metadata.custom);try{o.addAction(i,a)}catch(c){throw new Error(`Datadog addAction failed: ${m(c)}`)}}}}function g(n){let{client:o,eventName:i="WriteTrack Session"}=n;return{async send(t){let e={duration:t.metadata.duration,keystrokeCount:t.session.events.length,qualityLevel:t.quality.qualityLevel,targetElement:t.metadata.targetElement,schemaVersion:t.version};t.metadata.userId&&(e.userId=t.metadata.userId),t.metadata.contentId&&(e.contentId=t.metadata.contentId),t.metadata.custom&&(e.custom=t.metadata.custom),o.track(i,e)}}}function v(n){let{tracer:o,spanName:i="writetrack.session"}=n;return{async send(t){let e=o.startSpan(i);try{e.setAttribute("writetrack.duration",t.metadata.duration),e.setAttribute("writetrack.keystroke_count",t.session.events.length),e.setAttribute("writetrack.quality_level",t.quality.qualityLevel),e.setAttribute("writetrack.target_element",t.metadata.targetElement),e.setAttribute("writetrack.schema_version",t.version),t.metadata.userId&&e.setAttribute("writetrack.user_id",t.metadata.userId),t.metadata.contentId&&e.setAttribute("writetrack.content_id",t.metadata.contentId),e.setStatus({code:1})}finally{e.end()}}}}export{d as datadog,v as opentelemetry,g as segment,p as webhook};
@@ -1,4 +1,4 @@
1
- import { S as SessionAnalysis } from './analysis-types-zqWj2pHM.js';
1
+ import { S as SessionAnalysis } from './analysis-types-B9TlyYRD.js';
2
2
  import './index-Cy91q_po.js';
3
3
 
4
4
  /**
package/dist/esm/viz.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { W as WriteTrackDataSchema } from './index-Cy91q_po.js';
2
- import { S as SessionAnalysis, a as SessionReport, d as IntegrityProof } from './analysis-types-zqWj2pHM.js';
2
+ import { S as SessionAnalysis, a as SessionReport, d as IntegrityProof } from './analysis-types-B9TlyYRD.js';
3
3
 
4
4
  /**
5
5
  * BaseChart — abstract web component base class for WriteTrack visualizations.
@@ -40,6 +40,8 @@ declare abstract class BaseChart<T = unknown> extends HTMLElement {
40
40
  destroy(): void;
41
41
  /** Called on container resize. Override in subclasses that shouldn't full re-render. */
42
42
  protected onResize(): void;
43
+ /** Wrap render() in try/catch so subclasses don't need individual error handling */
44
+ private safeRender;
43
45
  /** Subclasses implement this to draw their visualization */
44
46
  protected abstract render(): void;
45
47
  /** Register the custom element if not already defined */
package/dist/esm/viz.js CHANGED
@@ -1,4 +1,4 @@
1
- var ft=`:host {
1
+ var yt=`:host {
2
2
  --wt-color-primary: #fbbf24;
3
3
  --wt-color-secondary: #22d3ee;
4
4
  --wt-color-bg: #111113;
@@ -35,9 +35,9 @@ var ft=`:host {
35
35
  }
36
36
 
37
37
  /* Force light text on dark tooltips regardless of chart theme */
38
- [aria-label="tip"] { color: #fafafa; }`,S={fill:"#1a1a1d",stroke:"#27272a",textPadding:6,fontSize:11,fontFamily:"'JetBrains Mono', ui-monospace, monospace"};var g=class extends HTMLElement{constructor(){super();this._data=null;this._resizeObserver=null;this._resizeRaf=null;this.e=null;this.s=!0;this.a=!1;this.o=!1;this.shadow=this.attachShadow({mode:"open"});let r=document.createElement("style");r.textContent=this.getStylesheet(),this.shadow.appendChild(r),this.container=document.createElement("div"),this.container.className="wt-chart",this.shadow.appendChild(this.container)}static get observedAttributes(){return["data","theme","label"]}getStylesheet(){return ft}connectedCallback(){typeof ResizeObserver<"u"&&(this.s=!0,this._resizeObserver=new ResizeObserver(()=>{if(this.s){this.s=!1;return}this._data&&(this._resizeRaf&&cancelAnimationFrame(this._resizeRaf),this._resizeRaf=requestAnimationFrame(()=>{this._resizeRaf=null,this.onResize()}))}),this._resizeObserver.observe(this.container)),this.i(),typeof MutationObserver<"u"&&(this.e=new MutationObserver(()=>{this.i()}),this.e.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),document.body&&this.e.observe(document.body,{attributes:!0,attributeFilter:["data-theme"]}))}disconnectedCallback(){this.destroy()}attributeChangedCallback(r,a,t){if(r==="data"&&t)try{let s=JSON.parse(t);this.setData(s)}catch(s){console.warn("[WriteTrack] BaseChart: invalid JSON in data attribute:",s)}r==="theme"&&this._data&&this.a&&this.render()}setData(r){this._data=r,this.render()}getData(){return this._data}get hasRendered(){return this.a}replaceChart(...r){for(let a of r)if(a instanceof SVGElement){a.setAttribute("role","img");let t=this.getAttribute("label")??this.tagName.toLowerCase().replace("wt-","").replace(/-/g," ")+" chart";a.setAttribute("aria-label",t)}this.container.replaceChildren(...r),this.a=!0,this.dispatchEvent(new CustomEvent("wt-render",{bubbles:!1}))}showEmptyState(r="No data"){let a=document.createElement("div");a.className="wt-empty",a.textContent=r,a.style.cssText="display:flex;align-items:center;justify-content:center;height:100%;font-family:var(--wt-font-ui,system-ui,sans-serif);font-size:11px;color:var(--wt-color-text-muted,#a1a1aa);",this.container.replaceChildren(a),this.a=!1}destroy(){this._resizeRaf&&(cancelAnimationFrame(this._resizeRaf),this._resizeRaf=null),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),this.e&&(this.e.disconnect(),this.e=null),this.container.replaceChildren(),this._data=null,this.a=!1}onResize(){this.render()}static register(){customElements.get(this.tagName)||customElements.define(this.tagName,this)}i(){if(this.hasAttribute("theme")&&!this.o)return;let r=this.parentElement;for(;r;){let a=r.getAttribute("data-theme");if(a){this.shadow.host.setAttribute("theme",a),this.o=!0;return}r=r.parentElement}this.o&&(this.shadow.host.removeAttribute("theme"),this.o=!1)}};g.tagName="wt-base-chart";import*as $ from"@observablehq/plot";var Dt=5;function gt(n){var s;let e=(((s=n.session)==null?void 0:s.events)??[]).filter(o=>o.type==="keydown"&&o.flightTime!=null&&o.flightTime>0);if(e.length<2)return[[],[]];let r=n.session.sessionStartTime,a=[],t=[];for(let o=0;o<e.length;o++){let i=Math.max(0,o-Dt+1),c=0,l=0;for(let u=i;u<=o;u++)c+=e[u].flightTime,l++;let d=c/l,m=Math.round(6e4/d);a.push(Math.round((e[o].timestamp-r)/1e3*100)/100),t.push(m)}return[a,t]}var L=class L extends g{connectedCallback(){super.connectedCallback();let e=getComputedStyle(this);!this.style.display&&e.display==="inline"&&(this.style.display="inline-block"),!this.style.width&&(e.width==="auto"||e.width==="0px")&&(this.style.width="200px"),!this.style.height&&(e.height==="auto"||e.height==="0px")&&(this.style.height="40px")}render(){if(!this._data)return;let[e,r]=gt(this._data);if(e.length===0){this.showEmptyState("No data");return}let a=e.map((i,c)=>({time:i,speed:r[c]})),t=this.getBoundingClientRect(),s=Math.max(t.width||200,50),o=Math.max(t.height||40,20);try{let i=$.plot({width:s,height:o,axis:null,x:{axis:null},y:{axis:null},marks:[$.areaY(a,{x:"time",y:"speed",fill:"var(--wt-color-primary, #fbbf24)",fillOpacity:.1}),$.lineY(a,{x:"time",y:"speed",stroke:"var(--wt-color-primary, #fbbf24)",strokeWidth:1.5})],style:{background:"transparent",overflow:"visible"},margin:0,marginTop:2,marginBottom:2,marginLeft:0,marginRight:0});this.replaceChart(i)}catch(i){console.warn("[WriteTrack] Sparkline render failed:",i)}}static create(e,r){L.register();let a=document.createElement(L.tagName);return e.appendChild(a),a.setData(r),a}};L.tagName="wt-sparkline";var lt=L;import*as C from"@observablehq/plot";function F(n){var t,s,o;let e=(s=(t=n.temporalPatterns)==null?void 0:t.metrics)==null?void 0:s.speedTimeline;if(!((o=e==null?void 0:e.timestamps)!=null&&o.length))return[];let r=Math.min(e.timestamps.length,e.values.length),a=[];for(let i=0;i<r;i++)a.push({time:e.timestamps[i]/1e3,speed:e.values[i]});return a}var z=class extends g{render(){if(!this._data)return;let e=F(this._data);if(e.length===0){this.showEmptyState("No speed data");return}let r=this.clientWidth||640,a=this.clientHeight||200;try{let t=C.plot({width:r,height:a,marginLeft:50,marginBottom:35,x:{label:"Time (s)"},y:{label:"Speed (CPM)",grid:!0},marks:[C.areaY(e,{x:"time",y:"speed",fill:"var(--wt-color-primary, #fbbf24)",fillOpacity:.15,curve:"natural"}),C.lineY(e,{x:"time",y:"speed",stroke:"var(--wt-color-primary, #fbbf24)",strokeWidth:2,curve:"natural"}),C.ruleY([0],{stroke:"var(--wt-color-border, #27272a)"}),C.tip(e,C.pointerX({x:"time",y:"speed",title:s=>`${s.time.toFixed(1)}s \u2014 ${Math.round(s.speed)} CPM`,...S}))],style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(t)}catch(t){console.warn("[WriteTrack] SpeedTimeline render failed:",t)}}};z.tagName="wt-speed-timeline";import*as P from"@observablehq/plot";var ct={typing:"var(--wt-color-primary, #fbbf24)",paste:"var(--wt-color-secondary, #22d3ee)",pause:"var(--wt-color-text-muted, #a1a1aa)",tabAway:"#ef4444",autocomplete:"#a78bfa",navigating:"#34d399"};function H(n){let e=n.sessionTimeline;return e!=null&&e.length?e.map(r=>({start:r.startTime/1e3,end:r.endTime/1e3,type:r.type,color:ct[r.type]??"#666"})):[]}function yt(n){var r,a;return(((a=(r=n.contentOrigin)==null?void 0:r.metrics)==null?void 0:a.pasteEvents)??[]).map(t=>({time:t.timestamp/1e3,chars:t.characterCount,source:t.source}))}var G=class extends g{render(){if(!this._data)return;let e=H(this._data);if(e.length===0){this.showEmptyState("No session data");return}let r=yt(this._data),a=[P.barX(e,{x1:"start",x2:"end",fill:"color",y:()=>"Activity",inset:.5}),P.tip(e,P.pointer({x:o=>(o.start+o.end)/2,y:()=>"Activity",title:o=>`${o.type} \u2014 ${(o.end-o.start).toFixed(1)}s`,...S}))];r.length&&a.push(P.dot(r,{x:"time",y:()=>"Activity",r:"chars",fill:ct.paste,fillOpacity:.7,stroke:"var(--wt-color-bg, #111113)",strokeWidth:1}));let t=this.clientWidth||640,s=this.clientHeight||80;try{let o=P.plot({width:t,height:s,marginLeft:50,marginBottom:35,x:{label:"Time (s)"},y:{axis:null,padding:.3},marks:a,style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(o)}catch(o){console.warn("[WriteTrack] CompositionTimeline render failed:",o)}}};G.tagName="wt-composition-timeline";import*as j from"@observablehq/plot";var Ot=10;function Y(n){var o,i,c,l,d;let e=(i=(o=n.timingAuthenticity)==null?void 0:o.metrics)==null?void 0:i.timingOverTime;if(!((c=e==null?void 0:e.timestamps)!=null&&c.length))return[];let r=((l=e.series)==null?void 0:l.meanDwell)??[],a=((d=e.series)==null?void 0:d.meanFlight)??[];if(!r.length||!a.length)return[];let t=[],s=Math.min(e.timestamps.length,r.length,a.length);for(let m=0;m<s;m++)r[m]!=null&&a[m]!=null&&t.push({dwell:r[m],flight:a[m]});return t}var V=class extends g{render(){if(!this._data)return;let e=Y(this._data);if(e.length<Ot){this.showEmptyState("Insufficient timing data");return}let r=this.clientWidth||400,a=Math.min(r,this.clientHeight||400);try{let t=j.plot({width:r,height:a,marginLeft:50,marginBottom:35,x:{label:"Dwell (ms)",grid:!0},y:{label:"Flight (ms)",grid:!0},marks:[j.dot(e,{x:"dwell",y:"flight",fill:"var(--wt-color-primary, #fbbf24)",fillOpacity:.35,r:3,stroke:"var(--wt-color-primary, #fbbf24)",strokeOpacity:.6,strokeWidth:.5})],style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(t)}catch(t){console.warn("[WriteTrack] RhythmHeatmap render failed:",t)}}};V.tagName="wt-rhythm-heatmap";import*as _ from"@observablehq/plot";function bt(n){var r,a,t;let e=(a=(r=n.temporalPatterns)==null?void 0:r.metrics)==null?void 0:a.pauseDistribution;return(t=e==null?void 0:e.histogram)!=null&&t.length?e.histogram.map(s=>({start:s.binStart,end:s.binEnd,count:s.count})):[]}var q=class extends g{render(){if(!this._data)return;let e=bt(this._data);if(e.length===0){this.showEmptyState("No pause data");return}let r=this.clientWidth||640,a=this.clientHeight||200;try{let t=_.plot({width:r,height:a,marginLeft:50,marginBottom:35,x:{label:"Pause Duration (ms)"},y:{label:"Count",grid:!0},marks:[_.rectY(e,{x1:"start",x2:"end",y:"count",fill:"var(--wt-color-primary, #fbbf24)",fillOpacity:.8,inset:.5}),_.ruleY([0])],style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(t)}catch(t){console.warn("[WriteTrack] PauseDistribution render failed:",t)}}};q.tagName="wt-pause-distribution";import*as E from"@observablehq/plot";var K=/^.$/u;function v(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function Q(n){var i,c;let e=(i=n.session)==null?void 0:i.events;if(!(e!=null&&e.length))return[];let r=e.filter(l=>l.type==="keydown");if(r.length===0)return[];let a=r[0].timestamp,t=[];for(let l of r)l.key==="Backspace"||l.key==="Delete"?t.push({timestamp:l.timestamp,type:"key",delta:-1}):K.test(l.key)&&t.push({timestamp:l.timestamp,type:"key",delta:1});for(let l of((c=n.session)==null?void 0:c.clipboardEvents)??[])l.type==="paste"?t.push({timestamp:l.timestamp,type:"paste",delta:l.length,pasteLength:l.length}):l.type==="cut"&&t.push({timestamp:l.timestamp,type:"cut",delta:-l.length,cutLength:l.length});t.sort((l,d)=>l.timestamp-d.timestamp);let s=[],o=0;for(let l of t){let d=(l.timestamp-a)/1e3;l.type==="paste"?(s.push({time:d,chars:o,isPaste:!1,isCut:!1}),o+=l.delta,s.push({time:d+.001,chars:o,isPaste:!0,isCut:!1,pasteLength:l.pasteLength})):l.type==="cut"?(s.push({time:d,chars:o,isPaste:!1,isCut:!1}),o=Math.max(0,o+l.delta),s.push({time:d+.001,chars:o,isPaste:!1,isCut:!0,cutLength:l.cutLength})):(o=Math.max(0,o+l.delta),s.push({time:d,chars:o,isPaste:!1,isCut:!1}))}return s}var U=class extends g{render(){if(!this._data)return;let e=Q(this._data);if(e.length===0){this.showEmptyState("No keystroke data");return}let r=e.filter(o=>o.isPaste),a=e.filter(o=>o.isCut),t=this.clientWidth||640,s=this.clientHeight||200;try{let o=[E.lineY(e,{x:"time",y:"chars",stroke:"var(--wt-color-primary, #fbbf24)",strokeWidth:2})];r.length>0&&o.push(E.text(r,{x:"time",y:"chars",text:c=>`+${c.pasteLength}`,fill:"var(--wt-color-secondary, #22d3ee)",fontSize:10,dy:-8})),a.length>0&&o.push(E.text(a,{x:"time",y:"chars",text:c=>`\u2212${c.cutLength}`,fill:"#ef4444",fontSize:10,dy:12})),o.push(E.tip(e,E.pointerX({x:"time",y:"chars",title:c=>{let l=`${c.time.toFixed(1)}s \u2014 ${c.chars} chars`;return c.isPaste?`${l}
39
- +${c.pasteLength} pasted`:c.isCut?`${l}
40
- \u2212${c.cutLength} cut`:l},...S})));let i=E.plot({width:t,height:s,marginLeft:50,marginBottom:35,x:{label:"Time (s)"},y:{label:"Characters",grid:!0},marks:o,style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(i)}catch(o){console.warn("[WriteTrack] DocumentGrowth render failed:",o)}}};U.tagName="wt-document-growth";import*as A from"@observablehq/plot";function wt(n){var s;let e=(s=n.session)==null?void 0:s.events;if(!(e!=null&&e.length))return[];let r=e.filter(o=>o.type==="keydown");if(r.length===0)return[];let a=r[0].timestamp,t=[];for(let o=0;o<r.length;o++){let i=r[o],c=(i.timestamp-a)/1e3,l=o<r.length-1?(r[o+1].timestamp-a)/1e3:c+(i.dwellTime??50)/1e3,d=i.flightTime??0;t.push({start:c,end:l,flight:d})}return t}var X=class extends g{render(){if(!this._data)return;let e=wt(this._data);if(e.length===0){this.showEmptyState("No keystroke data");return}let r=this.clientWidth||640,a=this.clientHeight||80;try{let t=A.plot({width:r,height:a,marginLeft:50,marginBottom:35,x:{label:"Time (s)"},y:{axis:null},color:{type:"sequential",scheme:"YlOrRd",domain:[0,Math.max(1,e.reduce((s,o)=>o.flight>s?o.flight:s,0))],label:"Flight time (ms)"},marks:[A.rect(e,{x1:"start",x2:"end",y1:()=>0,y2:()=>1,fill:"flight",inset:.5}),A.tip(e,A.pointer({x:s=>(s.start+s.end)/2,y:()=>.5,title:s=>`${s.start.toFixed(1)}s \u2014 ${Math.round(s.flight)}ms flight time`,...S}))],style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(t)}catch(t){console.warn("[WriteTrack] DocumentRibbon render failed:",t)}}};X.tagName="wt-document-ribbon";import*as T from"@observablehq/plot";var Lt=null;function vt(){return Lt}function xt(n,e,r,a){let t=n.length;if(t<=e||e<3)return n;let s=vt();if(!s)return n;let o=new Float64Array(t),i=new Float64Array(t);for(let d=0;d<t;d++)o[d]=r(n[d]),i[d]=a(n[d]);let c=s.lttb_downsample(o,i,e);if(c.length===0)return n;let l=new Array(c.length);for(let d=0;d<c.length;d++)l[d]=n[c[d]];return l}var kt=2e3;function Z(n){var i,c;let e=(i=n.session)==null?void 0:i.events;if(!(e!=null&&e.length))return{keystrokes:[],pastes:[],cuts:[]};let r=e.filter(l=>l.type==="keydown"&&l.cursorPosition!=null);if(r.length===0)return{keystrokes:[],pastes:[],cuts:[]};let a=r[0].timestamp,t=r.map(l=>({time:(l.timestamp-a)/1e3,position:l.cursorPosition})),s=[],o=[];for(let l of((c=n.session)==null?void 0:c.clipboardEvents)??[])l.type==="paste"?s.push({time:Math.max(0,(l.timestamp-a)/1e3),position:l.position}):l.type==="cut"&&o.push({time:Math.max(0,(l.timestamp-a)/1e3),position:l.position});return{keystrokes:t,pastes:s,cuts:o}}var J=class extends g{render(){if(!this._data)return;let e=Z(this._data);if(e.keystrokes.length===0){this.showEmptyState("No cursor position data");return}let r=xt(e.keystrokes,kt,i=>i.time,i=>i.position),{pastes:a,cuts:t}=e,s=this.clientWidth||640,o=this.clientHeight||200;try{let i=[T.line(r,{x:"time",y:"position",stroke:"var(--wt-color-primary, #fbbf24)",strokeWidth:1,strokeOpacity:.5}),T.dot(r,{x:"time",y:"position",fill:"var(--wt-color-primary, #fbbf24)",r:2})];a.length>0&&i.push(T.dot(a,{x:"time",y:"position",fill:"var(--wt-color-secondary, #22d3ee)",r:6,stroke:"var(--wt-color-bg, #111113)",strokeWidth:1})),t.length>0&&i.push(T.dot(t,{x:"time",y:"position",fill:"#f97316",r:6,stroke:"var(--wt-color-bg, #111113)",strokeWidth:1})),i.push(T.tip(r,T.pointerX({x:"time",y:"position",title:l=>`${l.time.toFixed(1)}s \u2014 position ${l.position}`,...S})));let c=T.plot({width:s,height:o,marginLeft:50,marginBottom:35,x:{label:"Time (s)"},y:{label:"Position",reverse:!0,grid:!0},marks:i,style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(c)}catch(i){console.warn("[WriteTrack] EditWaterfall render failed:",i)}}};J.tagName="wt-edit-waterfall";import*as R from"@observablehq/plot";var St={insert:"#22c55e",delete:"#ef4444",paste:"var(--wt-color-secondary, #22d3ee)",cut:"#f97316"},Ct={insert:.6,delete:-.6,paste:0,cut:0};function et(n){var l,d;let e=(l=n.session)==null?void 0:l.events;if(!(e!=null&&e.length))return[];let r=e.filter(m=>m.type==="keydown");if(r.length===0)return[];let a=r[0].timestamp,t=[],s=null,o=0,i=0;function c(){s&&o>0&&t.push({time:i,chars:o,type:s,size:Math.max(4,Math.sqrt(o)*3)}),s=null,o=0}for(let m of r){let u=(m.timestamp-a)/1e3,p=null;m.key==="Backspace"||m.key==="Delete"?p="delete":K.test(m.key)&&(p="insert"),p!==null&&(p!==s&&(c(),s=p,i=u),o++)}c();for(let m of((d=n.session)==null?void 0:d.clipboardEvents)??[])if(m.type==="paste"||m.type==="cut"){let u=Math.max(0,(m.timestamp-a)/1e3),p=m.length;t.push({time:u,chars:p,type:m.type,size:Math.max(4,Math.sqrt(p)*3)})}return t.sort((m,u)=>m.time-u.time),t}var tt=class extends g{render(){if(!this._data)return;let e=et(this._data);if(e.length===0){this.showEmptyState("No edit data");return}let r=this.clientWidth||640,a=this.clientHeight||140;try{let t=R.plot({width:r,height:a,marginLeft:50,marginBottom:35,marginTop:10,x:{label:"Time (s)"},y:{axis:null,domain:[-1.5,1.5]},marks:[R.dot(e,{x:"time",y:o=>Ct[o.type],r:"size",fill:o=>St[o.type],fillOpacity:.65,stroke:o=>St[o.type],strokeWidth:1}),R.tip(e,R.pointer({x:"time",y:o=>Ct[o.type],title:o=>`${o.time.toFixed(1)}s \u2014 ${o.type}, ${o.chars} chars`,...S}))],style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(t);let s=document.createElement("div");s.className="wt-legend",s.style.cssText="display:flex;gap:12px;padding:6px 0 0;font-family:var(--wt-font-ui,system-ui,sans-serif);font-size:10px;color:var(--wt-color-text-muted,#a1a1aa);";for(let[o,i]of[["Insert","#22c55e"],["Delete","#ef4444"],["Paste","#22d3ee"],["Cut","#f97316"]]){let c=document.createElement("span");c.style.cssText="display:flex;align-items:center;gap:4px;";let l=document.createElement("span");l.style.cssText=`width:8px;height:8px;border-radius:50%;background:${i};`,c.appendChild(l),c.appendChild(document.createTextNode(o)),s.appendChild(c)}this.container.appendChild(s)}catch(t){console.warn("[WriteTrack] CorrectionsBubble render failed:",t)}}};tt.tagName="wt-corrections-bubble";var B=`:host {
38
+ [aria-label="tip"] { color: #fafafa; }`,k={fill:"#1a1a1d",stroke:"#27272a",textPadding:6,fontSize:11,fontFamily:"'JetBrains Mono', ui-monospace, monospace"};function W(a){console.warn(`[WriteTrack] ${a}`)}function ct(a){return a instanceof Error?a.message:String(a)}var g=class extends HTMLElement{constructor(){super();this._data=null;this._resizeObserver=null;this._resizeRaf=null;this.e=null;this.i=!0;this.o=!1;this.a=!1;this.shadow=this.attachShadow({mode:"open"});let e=document.createElement("style");e.textContent=this.getStylesheet(),this.shadow.appendChild(e),this.container=document.createElement("div"),this.container.className="wt-chart",this.shadow.appendChild(this.container)}static get observedAttributes(){return["data","theme","label"]}getStylesheet(){return yt}connectedCallback(){typeof ResizeObserver<"u"&&(this.i=!0,this._resizeObserver=new ResizeObserver(()=>{if(this.i){this.i=!1;return}this._data&&(this._resizeRaf&&cancelAnimationFrame(this._resizeRaf),this._resizeRaf=requestAnimationFrame(()=>{this._resizeRaf=null,this.onResize()}))}),this._resizeObserver.observe(this.container)),this.s(),typeof MutationObserver<"u"&&(this.e=new MutationObserver(()=>{this.s()}),this.e.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),document.body&&this.e.observe(document.body,{attributes:!0,attributeFilter:["data-theme"]}))}disconnectedCallback(){this.destroy()}attributeChangedCallback(e,n,r){if(e==="data"&&r)try{let o=JSON.parse(r);this.setData(o)}catch(o){W(`BaseChart: invalid JSON in data attribute: ${ct(o)}`)}e==="theme"&&this._data&&this.o&&this.safeRender()}setData(e){this._data=e,this.safeRender()}getData(){return this._data}get hasRendered(){return this.o}replaceChart(...e){for(let n of e)if(n instanceof SVGElement){n.setAttribute("role","img");let r=this.getAttribute("label")??this.tagName.toLowerCase().replace("wt-","").replace(/-/g," ")+" chart";n.setAttribute("aria-label",r)}this.container.replaceChildren(...e),this.o=!0,this.dispatchEvent(new CustomEvent("wt-render",{bubbles:!1}))}showEmptyState(e="No data"){let n=document.createElement("div");n.className="wt-empty",n.textContent=e,n.style.cssText="display:flex;align-items:center;justify-content:center;height:100%;font-family:var(--wt-font-ui,system-ui,sans-serif);font-size:11px;color:var(--wt-color-text-muted,#a1a1aa);",this.container.replaceChildren(n),this.o=!1}destroy(){this._resizeRaf&&(cancelAnimationFrame(this._resizeRaf),this._resizeRaf=null),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),this.e&&(this.e.disconnect(),this.e=null),this.container.replaceChildren(),this._data=null,this.o=!1}onResize(){this.safeRender()}safeRender(){try{this.render()}catch(e){W(`${this.constructor.name} render failed: ${ct(e)}`)}}static register(){customElements.get(this.tagName)||customElements.define(this.tagName,this)}s(){if(this.hasAttribute("theme")&&!this.a)return;let e=this.parentElement;for(;e;){let n=e.getAttribute("data-theme");if(n){this.shadow.host.setAttribute("theme",n),this.a=!0;return}e=e.parentElement}this.a&&(this.shadow.host.removeAttribute("theme"),this.a=!1)}};g.tagName="wt-base-chart";import*as D from"@observablehq/plot";var Lt=5;function bt(a){var o;let t=(((o=a.session)==null?void 0:o.events)??[]).filter(i=>i.type==="keydown"&&i.flightTime!=null&&i.flightTime>0);if(t.length<2)return[[],[]];let e=a.session.sessionStartTime,n=[],r=[];for(let i=0;i<t.length;i++){let s=Math.max(0,i-Lt+1),l=0,c=0;for(let u=s;u<=i;u++)l+=t[u].flightTime,c++;let d=l/c,m=Math.round(6e4/d);n.push(Math.round((t[i].timestamp-e)/1e3*100)/100),r.push(m)}return[n,r]}var B=class B extends g{connectedCallback(){super.connectedCallback();let t=getComputedStyle(this);!this.style.display&&t.display==="inline"&&(this.style.display="inline-block"),!this.style.width&&(t.width==="auto"||t.width==="0px")&&(this.style.width="200px"),!this.style.height&&(t.height==="auto"||t.height==="0px")&&(this.style.height="40px")}render(){if(!this._data)return;let[t,e]=bt(this._data);if(t.length===0){this.showEmptyState("No data");return}let n=t.map((l,c)=>({time:l,speed:e[c]})),r=this.getBoundingClientRect(),o=Math.max(r.width||200,50),i=Math.max(r.height||40,20),s=D.plot({width:o,height:i,axis:null,x:{axis:null},y:{axis:null},marks:[D.areaY(n,{x:"time",y:"speed",fill:"var(--wt-color-primary, #fbbf24)",fillOpacity:.1}),D.lineY(n,{x:"time",y:"speed",stroke:"var(--wt-color-primary, #fbbf24)",strokeWidth:1.5})],style:{background:"transparent",overflow:"visible"},margin:0,marginTop:2,marginBottom:2,marginLeft:0,marginRight:0});this.replaceChart(s)}static create(t,e){B.register();let n=document.createElement(B.tagName);return t.appendChild(n),n.setData(e),n}};B.tagName="wt-sparkline";var dt=B;import*as C from"@observablehq/plot";function G(a){var r,o,i;let t=(o=(r=a.temporalPatterns)==null?void 0:r.metrics)==null?void 0:o.speedTimeline;if(!((i=t==null?void 0:t.timestamps)!=null&&i.length))return[];let e=Math.min(t.timestamps.length,t.values.length),n=[];for(let s=0;s<e;s++)n.push({time:t.timestamps[s]/1e3,speed:t.values[s]});return n.sort((s,l)=>s.time-l.time),n}var z=class extends g{render(){if(!this._data)return;let t=G(this._data);if(t.length===0){this.showEmptyState("No speed data");return}let e=this.clientWidth||640,n=this.clientHeight||200,r=C.plot({width:e,height:n,marginLeft:50,marginBottom:35,x:{label:"Time (s)"},y:{label:"Speed (CPM)",grid:!0},marks:[C.areaY(t,{x:"time",y:"speed",fill:"var(--wt-color-primary, #fbbf24)",fillOpacity:.15,curve:"monotone-x"}),C.lineY(t,{x:"time",y:"speed",stroke:"var(--wt-color-primary, #fbbf24)",strokeWidth:2,curve:"monotone-x"}),C.ruleY([0],{stroke:"var(--wt-color-border, #27272a)"}),C.tip(t,C.pointerX({x:"time",y:"speed",title:o=>`${o.time.toFixed(1)}s \u2014 ${Math.round(o.speed)} CPM`,...k}))],style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(r)}};z.tagName="wt-speed-timeline";import*as P from"@observablehq/plot";var mt={typing:"var(--wt-color-primary, #fbbf24)",paste:"var(--wt-color-secondary, #22d3ee)",pause:"var(--wt-color-text-muted, #a1a1aa)",tabAway:"#ef4444",autocomplete:"#a78bfa",navigating:"#34d399"};function V(a){let t=a.sessionTimeline;return t!=null&&t.length?t.map(e=>({start:e.startTime/1e3,end:e.endTime/1e3,type:e.type,color:mt[e.type]??"#666"})):[]}function wt(a){var e,n;return(((n=(e=a.contentOrigin)==null?void 0:e.metrics)==null?void 0:n.pasteEvents)??[]).map(r=>({time:r.timestamp/1e3,chars:r.characterCount,source:r.source}))}var H=class extends g{render(){if(!this._data)return;let t=V(this._data);if(t.length===0){this.showEmptyState("No session data");return}let e=wt(this._data),n=[P.barX(t,{x1:"start",x2:"end",fill:"color",y:()=>"Activity",inset:.5}),P.tip(t,P.pointer({x:s=>(s.start+s.end)/2,y:()=>"Activity",title:s=>`${s.type} \u2014 ${(s.end-s.start).toFixed(1)}s`,...k}))];e.length&&n.push(P.dot(e,{x:"time",y:()=>"Activity",r:"chars",fill:mt.paste,fillOpacity:.7,stroke:"var(--wt-color-bg, #111113)",strokeWidth:1}));let r=this.clientWidth||640,o=this.clientHeight||80,i=P.plot({width:r,height:o,marginLeft:50,marginBottom:35,x:{label:"Time (s)"},y:{axis:null,padding:.3},marks:n,style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(i)}};H.tagName="wt-composition-timeline";import*as q from"@observablehq/plot";var Bt=10;function Y(a){var i,s,l,c,d;let t=(s=(i=a.timingAuthenticity)==null?void 0:i.metrics)==null?void 0:s.timingOverTime;if(!((l=t==null?void 0:t.timestamps)!=null&&l.length))return[];let e=((c=t.series)==null?void 0:c.meanDwell)??[],n=((d=t.series)==null?void 0:d.meanFlight)??[];if(!e.length||!n.length)return[];let r=[],o=Math.min(t.timestamps.length,e.length,n.length);for(let m=0;m<o;m++)e[m]!=null&&n[m]!=null&&r.push({dwell:e[m],flight:n[m]});return r}var j=class extends g{render(){if(!this._data)return;let t=Y(this._data);if(t.length<Bt){this.showEmptyState("Insufficient timing data");return}let e=this.clientWidth||400,n=Math.min(e,this.clientHeight||400),r=q.plot({width:e,height:n,marginLeft:50,marginBottom:35,x:{label:"Dwell (ms)",grid:!0},y:{label:"Flight (ms)",grid:!0},marks:[q.dot(t,{x:"dwell",y:"flight",fill:"var(--wt-color-primary, #fbbf24)",fillOpacity:.35,r:3,stroke:"var(--wt-color-primary, #fbbf24)",strokeOpacity:.6,strokeWidth:.5})],style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(r)}};j.tagName="wt-rhythm-heatmap";import*as _ from"@observablehq/plot";function vt(a){var e,n,r;let t=(n=(e=a.temporalPatterns)==null?void 0:e.metrics)==null?void 0:n.pauseDistribution;return(r=t==null?void 0:t.histogram)!=null&&r.length?t.histogram.map(o=>({start:o.binStart,end:o.binEnd,count:o.count})):[]}var K=class extends g{render(){if(!this._data)return;let t=vt(this._data);if(t.length===0){this.showEmptyState("No pause data");return}let e=this.clientWidth||640,n=this.clientHeight||200,r=_.plot({width:e,height:n,marginLeft:50,marginBottom:35,x:{label:"Pause Duration (ms)"},y:{label:"Count",grid:!0},marks:[_.rectY(t,{x1:"start",x2:"end",y:"count",fill:"var(--wt-color-primary, #fbbf24)",fillOpacity:.8,inset:.5}),_.ruleY([0])],style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(r)}};K.tagName="wt-pause-distribution";import*as E from"@observablehq/plot";var U=/^.$/u;function v(a){return a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function Nt(a){let t=[];for(let e of a)e.key==="Backspace"||e.key==="Delete"?t.push({timestamp:e.timestamp,type:"key",delta:-1}):U.test(e.key)&&t.push({timestamp:e.timestamp,type:"key",delta:1});return t}function It(a){let t=[];for(let e of a??[])e.type==="paste"?t.push({timestamp:e.timestamp,type:"paste",delta:e.length,pasteLength:e.length}):e.type==="cut"&&t.push({timestamp:e.timestamp,type:"cut",delta:-e.length,cutLength:e.length});return t}function Ft(a,t){let e=[],n=0;for(let r of a){let o=(r.timestamp-t)/1e3;r.type==="paste"?(e.push({time:o,chars:n,isPaste:!1,isCut:!1}),n+=r.delta,e.push({time:o+.001,chars:n,isPaste:!0,isCut:!1,pasteLength:r.pasteLength})):r.type==="cut"?(e.push({time:o,chars:n,isPaste:!1,isCut:!1}),n=Math.max(0,n+r.delta),e.push({time:o+.001,chars:n,isPaste:!1,isCut:!0,cutLength:r.cutLength})):(n=Math.max(0,n+r.delta),e.push({time:o,chars:n,isPaste:!1,isCut:!1}))}return e}function X(a){var o,i;let t=(o=a.session)==null?void 0:o.events;if(!(t!=null&&t.length))return[];let e=t.filter(s=>s.type==="keydown");if(e.length===0)return[];let n=e[0].timestamp,r=[...Nt(e),...It((i=a.session)==null?void 0:i.clipboardEvents)];return r.sort((s,l)=>s.timestamp-l.timestamp),Ft(r,n)}function zt(a,t,e){let n=[E.lineY(a,{x:"time",y:"chars",stroke:"var(--wt-color-primary, #fbbf24)",strokeWidth:2})];return t.length>0&&n.push(E.text(t,{x:"time",y:"chars",text:r=>`+${r.pasteLength}`,fill:"var(--wt-color-secondary, #22d3ee)",fontSize:10,dy:-8})),e.length>0&&n.push(E.text(e,{x:"time",y:"chars",text:r=>`\u2212${r.cutLength}`,fill:"#ef4444",fontSize:10,dy:12})),n.push(E.tip(a,E.pointerX({x:"time",y:"chars",title:r=>{let o=`${r.time.toFixed(1)}s \u2014 ${r.chars} chars`;return r.isPaste?`${o}
39
+ +${r.pasteLength} pasted`:r.isCut?`${o}
40
+ \u2212${r.cutLength} cut`:o},...k}))),n}var Q=class extends g{render(){if(!this._data)return;let t=X(this._data);if(t.length===0){this.showEmptyState("No keystroke data");return}let e=t.filter(i=>i.isPaste),n=t.filter(i=>i.isCut),r=this.clientWidth||640,o=this.clientHeight||200;try{let i=zt(t,e,n),s=E.plot({width:r,height:o,marginLeft:50,marginBottom:35,x:{label:"Time (s)"},y:{label:"Characters",grid:!0},marks:i,style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(s)}catch(i){W(`DocumentGrowth render failed: ${i}`)}}};Q.tagName="wt-document-growth";import*as A from"@observablehq/plot";function xt(a){var o;let t=(o=a.session)==null?void 0:o.events;if(!(t!=null&&t.length))return[];let e=t.filter(i=>i.type==="keydown");if(e.length===0)return[];let n=e[0].timestamp,r=[];for(let i=0;i<e.length;i++){let s=e[i],l=(s.timestamp-n)/1e3,c=i<e.length-1?(e[i+1].timestamp-n)/1e3:l+(s.dwellTime??50)/1e3,d=s.flightTime??0;r.push({start:l,end:c,flight:d})}return r}var J=class extends g{render(){if(!this._data)return;let t=xt(this._data);if(t.length===0){this.showEmptyState("No keystroke data");return}let e=this.clientWidth||640,n=this.clientHeight||80,r=A.plot({width:e,height:n,marginLeft:50,marginBottom:35,x:{label:"Time (s)"},y:{axis:null},color:{type:"sequential",scheme:"YlOrRd",domain:[0,Math.max(1,t.reduce((o,i)=>i.flight>o?i.flight:o,0))],label:"Flight time (ms)"},marks:[A.rect(t,{x1:"start",x2:"end",y1:()=>0,y2:()=>1,fill:"flight",inset:.5}),A.tip(t,A.pointer({x:o=>(o.start+o.end)/2,y:()=>.5,title:o=>`${o.start.toFixed(1)}s \u2014 ${Math.round(o.flight)}ms flight time`,...k}))],style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(r)}};J.tagName="wt-document-ribbon";import*as T from"@observablehq/plot";var Gt=null;function St(){return Gt}function kt(a,t,e,n){let r=a.length;if(r<=t||t<3)return a;let o=St();if(!o)return a;let i=new Float64Array(r),s=new Float64Array(r);for(let d=0;d<r;d++)i[d]=e(a[d]),s[d]=n(a[d]);let l=o.lttb_downsample(i,s,t);if(l.length===0)return a;let c=new Array(l.length);for(let d=0;d<l.length;d++)c[d]=a[l[d]];return c}var Ct=2e3;function Ht(a,t){let e=[],n=[];for(let r of a??[])r.type==="paste"?e.push({time:Math.max(0,(r.timestamp-t)/1e3),position:r.position}):r.type==="cut"&&n.push({time:Math.max(0,(r.timestamp-t)/1e3),position:r.position});return{pastes:e,cuts:n}}function tt(a){var s,l;let t=(s=a.session)==null?void 0:s.events;if(!(t!=null&&t.length))return{keystrokes:[],pastes:[],cuts:[]};let e=t.filter(c=>c.type==="keydown"&&c.cursorPosition!=null);if(e.length===0)return{keystrokes:[],pastes:[],cuts:[]};let n=e[0].timestamp,r=e.map(c=>({time:(c.timestamp-n)/1e3,position:c.cursorPosition})),{pastes:o,cuts:i}=Ht((l=a.session)==null?void 0:l.clipboardEvents,n);return{keystrokes:r,pastes:o,cuts:i}}function Vt(a,t,e){let n=[T.line(a,{x:"time",y:"position",stroke:"var(--wt-color-primary, #fbbf24)",strokeWidth:1,strokeOpacity:.5}),T.dot(a,{x:"time",y:"position",fill:"var(--wt-color-primary, #fbbf24)",r:2})];return t.length>0&&n.push(T.dot(t,{x:"time",y:"position",fill:"var(--wt-color-secondary, #22d3ee)",r:6,stroke:"var(--wt-color-bg, #111113)",strokeWidth:1})),e.length>0&&n.push(T.dot(e,{x:"time",y:"position",fill:"#f97316",r:6,stroke:"var(--wt-color-bg, #111113)",strokeWidth:1})),n.push(T.tip(a,T.pointerX({x:"time",y:"position",title:r=>`${r.time.toFixed(1)}s \u2014 position ${r.position}`,...k}))),n}var Z=class extends g{render(){if(!this._data)return;let t=tt(this._data);if(t.keystrokes.length===0){this.showEmptyState("No cursor position data");return}let e=kt(t.keystrokes,Ct,s=>s.time,s=>s.position),{pastes:n,cuts:r}=t,o=this.clientWidth||640,i=this.clientHeight||200;try{let s=Vt(e,n,r),l=T.plot({width:o,height:i,marginLeft:50,marginBottom:35,x:{label:"Time (s)"},y:{label:"Position",reverse:!0,grid:!0},marks:s,style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(l)}catch(s){W(`EditWaterfall render failed: ${s}`)}}};Z.tagName="wt-edit-waterfall";import*as M from"@observablehq/plot";var Tt={insert:"#22c55e",delete:"#ef4444",paste:"var(--wt-color-secondary, #22d3ee)",cut:"#f97316"},Et={insert:.6,delete:-.6,paste:0,cut:0};function rt(a){var c,d;let t=(c=a.session)==null?void 0:c.events;if(!(t!=null&&t.length))return[];let e=t.filter(m=>m.type==="keydown");if(e.length===0)return[];let n=e[0].timestamp,r=[],o=null,i=0,s=0;function l(){o&&i>0&&r.push({time:s,chars:i,type:o,size:Math.max(4,Math.sqrt(i)*3)}),o=null,i=0}for(let m of e){let u=(m.timestamp-n)/1e3,p=null;m.key==="Backspace"||m.key==="Delete"?p="delete":U.test(m.key)&&(p="insert"),p!==null&&(p!==o&&(l(),o=p,s=u),i++)}l();for(let m of((d=a.session)==null?void 0:d.clipboardEvents)??[])if(m.type==="paste"||m.type==="cut"){let u=Math.max(0,(m.timestamp-n)/1e3),p=m.length;r.push({time:u,chars:p,type:m.type,size:Math.max(4,Math.sqrt(p)*3)})}return r.sort((m,u)=>m.time-u.time),r}var et=class extends g{render(){if(!this._data)return;let t=rt(this._data);if(t.length===0){this.showEmptyState("No edit data");return}let e=this.clientWidth||640,n=this.clientHeight||140,r=M.plot({width:e,height:n,marginLeft:50,marginBottom:35,marginTop:10,x:{label:"Time (s)"},y:{axis:null,domain:[-1.5,1.5]},marks:[M.dot(t,{x:"time",y:i=>Et[i.type],r:"size",fill:i=>Tt[i.type],fillOpacity:.65,stroke:i=>Tt[i.type],strokeWidth:1}),M.tip(t,M.pointer({x:"time",y:i=>Et[i.type],title:i=>`${i.time.toFixed(1)}s \u2014 ${i.type}, ${i.chars} chars`,...k}))],style:{background:"transparent",color:"var(--wt-color-text, #fafafa)",fontFamily:"var(--wt-font-data)",fontSize:"11px"}});this.replaceChart(r);let o=document.createElement("div");o.className="wt-legend",o.style.cssText="display:flex;gap:12px;padding:6px 0 0;font-family:var(--wt-font-ui,system-ui,sans-serif);font-size:10px;color:var(--wt-color-text-muted,#a1a1aa);";for(let[i,s]of[["Insert","#22c55e"],["Delete","#ef4444"],["Paste","#22d3ee"],["Cut","#f97316"]]){let l=document.createElement("span");l.style.cssText="display:flex;align-items:center;gap:4px;";let c=document.createElement("span");c.style.cssText=`width:8px;height:8px;border-radius:50%;background:${s};`,l.appendChild(c),l.appendChild(document.createTextNode(i)),o.appendChild(l)}this.container.appendChild(o)}};et.tagName="wt-corrections-bubble";var N=`:host {
41
41
  /* \u2500\u2500 Surface colors (light default) \u2500\u2500 */
42
42
  --wt-scorecard-bg: #F7F6F2;
43
43
  --wt-scorecard-bg-card: #FFFFFF;
@@ -102,7 +102,7 @@ var ft=`:host {
102
102
  .wt-term:hover {
103
103
  text-decoration-color: var(--wt-scorecard-text-secondary);
104
104
  }
105
- `,Ke=(()=>{try{let n=new CSSStyleSheet;return n.replaceSync(B),n}catch{return null}})();var Bt={"--wt-color-bg":"var(--wt-scorecard-bg-card)","--wt-color-surface":"var(--wt-scorecard-bg-detail)","--wt-color-text":"var(--wt-scorecard-text)","--wt-color-text-muted":"var(--wt-scorecard-text-tertiary)","--wt-color-border":"var(--wt-scorecard-border)","--wt-color-primary":"var(--wt-scorecard-chart-accent)","--wt-color-secondary":"var(--wt-scorecard-chart-flagged)","--wt-font-data":"var(--wt-scorecard-font-data)","--wt-font-ui":"var(--wt-scorecard-font-body)"};function Tt(n){for(let[e,r]of Object.entries(Bt))n.style.setProperty(e,r)}var N=new Uint8Array(256),dt=new Uint8Array(256);(function(){let n=1;for(let e=0;e<255;e++)N[e]=n,dt[n]=e,n=n<<1^(n>=128?285:0);N[255]=N[0]})();function At(n,e){return n===0||e===0?0:N[(dt[n]+dt[e])%255]}function Nt(n){let e=[1];for(let r=0;r<n;r++){let a=new Array(e.length+1).fill(0);for(let t=0;t<e.length;t++)a[t]^=e[t],a[t+1]^=At(e[t],N[r]);e=a}return e}function It(n,e){let r=Nt(e),a=new Uint8Array(n.length+e);a.set(n);for(let t=0;t<n.length;t++){let s=a[t];if(s!==0)for(let o=0;o<r.length;o++)a[t+o]^=At(r[o],s)}return a.slice(n.length)}var zt=[{ver:1,size:21,dc:16,ec:10,blocks:1,cap:14},{ver:2,size:25,dc:28,ec:16,blocks:1,cap:26},{ver:3,size:29,dc:44,ec:26,blocks:1,cap:42},{ver:4,size:33,dc:64,ec:18,blocks:2,cap:62},{ver:5,size:37,dc:86,ec:24,blocks:2,cap:84},{ver:6,size:41,dc:108,ec:16,blocks:4,cap:106}],Ft=[[],[6,18],[6,22],[6,26],[6,30],[6,34]];function Gt(n){for(let e of zt)if(n<=e.cap)return e;return null}function Ht(n,e){let r=[];function a(h,w){for(let b=w-1;b>=0;b--)r.push(h>>b&1)}a(4,4),a(n.length,8);for(let h of n)a(h,8);let t=e.dc*8;for(a(0,Math.min(4,t-r.length));r.length%8!==0;)r.push(0);let s=[236,17],o=0;for(;r.length<t;)a(s[o%2],8),o++;let i=[];for(let h=0;h<r.length;h+=8){let w=0;for(let b=0;b<8;b++)w=w<<1|r[h+b];i.push(w)}let c=Math.floor(e.dc/e.blocks),l=e.dc-c*e.blocks,d=[],m=[],u=0;for(let h=0;h<e.blocks;h++){let w=c+(h>=e.blocks-l?1:0),b=new Uint8Array(i.slice(u,u+w));d.push(b),m.push(It(b,e.ec)),u+=w}let p=[],y=0;for(let h of d)y=Math.max(y,h.length);for(let h=0;h<y;h++)for(let w of d)h<w.length&&p.push(w[h]);for(let h=0;h<e.ec;h++)for(let w of m)p.push(w[h]);return p}function Vt(n){let e=n.size,r=[],a=[];for(let i=0;i<e;i++)r.push(new Int8Array(e)),a.push(new Uint8Array(e));function t(i,c,l){r[c][i]=l?1:-1,a[c][i]=1}function s(i,c){for(let d=-3;d<=3;d++)for(let m=-3;m<=3;m++){let u=i+m,p=c+d;u<0||u>=e||p<0||p>=e||t(u,p,Math.max(Math.abs(m),Math.abs(d))!==2)}let l=[[-4,0],[4,0],[0,-4],[0,4]];for(let d=-4;d<=4;d++)for(let m of l){let u=i+(m[0]!==0?m[0]:d),p=c+(m[1]!==0?m[1]:d);u>=0&&u<e&&p>=0&&p<e&&t(u,p,!1)}}s(3,3),s(e-4,3),s(3,e-4);for(let i=8;i<e-8;i++)t(i,6,i%2===0),t(6,i,i%2===0);let o=Ft[n.ver-1];if(o.length>0)for(let i=0;i<o.length;i++)for(let c=0;c<o.length;c++){let l=o[i],d=o[c];if(!a[l][d])for(let m=-2;m<=2;m++)for(let u=-2;u<=2;u++)t(d+u,l+m,Math.max(Math.abs(u),Math.abs(m))!==1)}t(8,4*n.ver+9,!0);for(let i=0;i<8;i++)a[8][i]||(a[8][i]=1),a[8][e-1-i]||(a[8][e-1-i]=1),a[i][8]||(a[i][8]=1),a[e-1-i][8]||(a[e-1-i][8]=1);return a[8][8]=1,{grid:r,reserved:a,n:e}}function jt(n,e){let{grid:r,reserved:a,n:t}=n,s=[];for(let l of e)for(let d=7;d>=0;d--)s.push(l>>d&1);let o=0,i=t-1,c=!0;for(;i>=0;){if(i===6){i--;continue}let l=c?t-1:0,d=c?-1:t,m=c?-1:1;for(let u=l;u!==d;u+=m)for(let p=0;p<2;p++){let y=i-p;y<0||a[u][y]||(r[u][y]=o<s.length&&s[o]?1:-1,o++)}i-=2,c=!c}}var Yt=[(n,e)=>(n+e)%2===0,(n,e)=>e%2===0,(n,e)=>n%3===0,(n,e)=>(n+e)%3===0,(n,e)=>(Math.floor(e/2)+Math.floor(n/3))%2===0,(n,e)=>n*e%2+n*e%3===0,(n,e)=>(n*e%2+n*e%3)%2===0,(n,e)=>((n+e)%2+n*e%3)%2===0];function Et(n,e,r,a){let t=Yt[a],s=n.map(o=>Int8Array.from(o));for(let o=0;o<r;o++)for(let i=0;i<r;i++)!e[o][i]&&t(i,o)&&(s[o][i]=s[o][i]===1?-1:1);return s}var qt=[21522,20773,24188,23371,17913,16590,20375,19104];function Pt(n,e,r){let a=qt[r],t=[];for(let i=14;i>=0;i--)t.push(a>>i&1);let s=[[0,8],[1,8],[2,8],[3,8],[4,8],[5,8],[7,8],[8,8],[8,7],[8,5],[8,4],[8,3],[8,2],[8,1],[8,0]],o=[[8,e-1],[8,e-2],[8,e-3],[8,e-4],[8,e-5],[8,e-6],[8,e-7],[e-8,8],[e-7,8],[e-6,8],[e-5,8],[e-4,8],[e-3,8],[e-2,8],[e-1,8]];for(let i=0;i<15;i++){let c=t[i]?1:-1;n[s[i][1]][s[i][0]]=c,n[o[i][1]][o[i][0]]=c}}function Kt(n,e){let r=0;for(let a=0;a<e;a++){let t=1;for(let s=1;s<e;s++)n[a][s]>0==n[a][s-1]>0?t++:(t>=5&&(r+=t-2),t=1);t>=5&&(r+=t-2)}for(let a=0;a<e;a++){let t=1;for(let s=1;s<e;s++)n[s][a]>0==n[s-1][a]>0?t++:(t>=5&&(r+=t-2),t=1);t>=5&&(r+=t-2)}return r}function Ut(n){let e=[];for(let c=0;c<n.length;c++){let l=n.charCodeAt(c);l<128?e.push(l):l<2048&&(e.push(192|l>>6),e.push(128|l&63))}let r=Gt(e.length);if(!r)return null;let a=Ht(e,r),t=Vt(r);jt(t,a);let s=0,o=1/0;for(let c=0;c<8;c++){let l=Et(t.grid,t.reserved,t.n,c);Pt(l,t.n,c);let d=Kt(l,t.n);d<o&&(o=d,s=c)}let i=Et(t.grid,t.reserved,t.n,s);return Pt(i,t.n,s),{grid:i,size:t.n}}function Qt(n,e,r){let a=n.size,t=Math.max(2,Math.floor(88/a)),s=a*t,o=t/2,i=o*.82,c=a/2,l=a*.18;function d(x,k){let O=Math.sin(x*31+k*17)*1e4;return .75+.25*(O-Math.floor(O))}let m="";for(let x=0;x<a;x++)for(let k=0;k<a;k++){if(n.grid[x][k]<=0)continue;let O=k-c,ht=x-c;if(Math.sqrt(O*O+ht*ht)<l)continue;if(k<7&&x<7||k>=a-7&&x<7||k<7&&x>=a-7)m+=`<rect x="${k*t}" y="${x*t}" width="${t}" height="${t}" rx="${t*.15}" fill="${e}"/>`;else{let _t=i*d(k,x);m+=`<circle cx="${k*t+o}" cy="${x*t+o}" r="${_t.toFixed(1)}" fill="${e}"/>`}}let u=c*t,p=c*t,y=l*t*.6,h=r||e,w=y*2/100,b=70*w,W=`<g transform="translate(${u-y},${p-b/2}) scale(${w.toFixed(4)})">`;return W+=`<path d="M86 2 L86 64" stroke="${h}" stroke-width="5" stroke-linecap="round"/>`,W+=`<path d="M7 12 L98 12" stroke="${h}" stroke-width="5" stroke-linecap="round"/>`,W+=`<path d="M7 18 C7 32, 16 64, 30 64 C44 64, 38 28, 52 28 C66 28, 62 64, 86 64" stroke="${e}" stroke-width="5" stroke-linecap="round" fill="none"/>`,W+=`<circle cx="7" cy="12" r="7" fill="${e}"/>`,W+=`<circle cx="86" cy="64" r="7" fill="${h}"/>`,W+="</g>",`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${s} ${s}" width="${s}" height="${s}">${m}${W}</svg>`}var Xt=`.integrity-section {
105
+ `,hr=(()=>{try{let a=new CSSStyleSheet;return a.replaceSync(N),a}catch{return null}})();var jt={"--wt-color-bg":"var(--wt-scorecard-bg-card)","--wt-color-surface":"var(--wt-scorecard-bg-detail)","--wt-color-text":"var(--wt-scorecard-text)","--wt-color-text-muted":"var(--wt-scorecard-text-tertiary)","--wt-color-border":"var(--wt-scorecard-border)","--wt-color-primary":"var(--wt-scorecard-chart-accent)","--wt-color-secondary":"var(--wt-scorecard-chart-flagged)","--wt-font-data":"var(--wt-scorecard-font-data)","--wt-font-ui":"var(--wt-scorecard-font-body)"};function Pt(a){for(let[t,e]of Object.entries(jt))a.style.setProperty(t,e)}var I=new Uint8Array(256),ut=new Uint8Array(256);(function(){let a=1;for(let t=0;t<255;t++)I[t]=a,ut[a]=t,a=a<<1^(a>=128?285:0);I[255]=I[0]})();function Rt(a,t){return a===0||t===0?0:I[(ut[a]+ut[t])%255]}function qt(a){let t=[1];for(let e=0;e<a;e++){let n=new Array(t.length+1).fill(0);for(let r=0;r<t.length;r++)n[r]^=t[r],n[r+1]^=Rt(t[r],I[e]);t=n}return t}function Yt(a,t){let e=qt(t),n=new Uint8Array(a.length+t);n.set(a);for(let r=0;r<a.length;r++){let o=n[r];if(o!==0)for(let i=0;i<e.length;i++)n[r+i]^=Rt(e[i],o)}return n.slice(a.length)}var Kt=[{ver:1,size:21,dc:16,ec:10,blocks:1,cap:14},{ver:2,size:25,dc:28,ec:16,blocks:1,cap:26},{ver:3,size:29,dc:44,ec:26,blocks:1,cap:42},{ver:4,size:33,dc:64,ec:18,blocks:2,cap:62},{ver:5,size:37,dc:86,ec:24,blocks:2,cap:84},{ver:6,size:41,dc:108,ec:16,blocks:4,cap:106}],Ut=[[],[6,18],[6,22],[6,26],[6,30],[6,34]];function Qt(a){for(let t of Kt)if(a<=t.cap)return t;return null}function Xt(a,t){let e=[];function n(h,w){for(let b=w-1;b>=0;b--)e.push(h>>b&1)}n(4,4),n(a.length,8);for(let h of a)n(h,8);let r=t.dc*8;for(n(0,Math.min(4,r-e.length));e.length%8!==0;)e.push(0);let o=[236,17],i=0;for(;e.length<r;)n(o[i%2],8),i++;let s=[];for(let h=0;h<e.length;h+=8){let w=0;for(let b=0;b<8;b++)w=w<<1|e[h+b];s.push(w)}let l=Math.floor(t.dc/t.blocks),c=t.dc-l*t.blocks,d=[],m=[],u=0;for(let h=0;h<t.blocks;h++){let w=l+(h>=t.blocks-c?1:0),b=new Uint8Array(s.slice(u,u+w));d.push(b),m.push(Yt(b,t.ec)),u+=w}let p=[],y=0;for(let h of d)y=Math.max(y,h.length);for(let h=0;h<y;h++)for(let w of d)h<w.length&&p.push(w[h]);for(let h=0;h<t.ec;h++)for(let w of m)p.push(w[h]);return p}function Jt(a){let t=a.size,e=[],n=[];for(let s=0;s<t;s++)e.push(new Int8Array(t)),n.push(new Uint8Array(t));function r(s,l,c){e[l][s]=c?1:-1,n[l][s]=1}function o(s,l){for(let d=-3;d<=3;d++)for(let m=-3;m<=3;m++){let u=s+m,p=l+d;u<0||u>=t||p<0||p>=t||r(u,p,Math.max(Math.abs(m),Math.abs(d))!==2)}let c=[[-4,0],[4,0],[0,-4],[0,4]];for(let d=-4;d<=4;d++)for(let m of c){let u=s+(m[0]!==0?m[0]:d),p=l+(m[1]!==0?m[1]:d);u>=0&&u<t&&p>=0&&p<t&&r(u,p,!1)}}o(3,3),o(t-4,3),o(3,t-4);for(let s=8;s<t-8;s++)r(s,6,s%2===0),r(6,s,s%2===0);let i=Ut[a.ver-1];if(i.length>0)for(let s=0;s<i.length;s++)for(let l=0;l<i.length;l++){let c=i[s],d=i[l];if(!n[c][d])for(let m=-2;m<=2;m++)for(let u=-2;u<=2;u++)r(d+u,c+m,Math.max(Math.abs(u),Math.abs(m))!==1)}r(8,4*a.ver+9,!0);for(let s=0;s<8;s++)n[8][s]||(n[8][s]=1),n[8][t-1-s]||(n[8][t-1-s]=1),n[s][8]||(n[s][8]=1),n[t-1-s][8]||(n[t-1-s][8]=1);return n[8][8]=1,{grid:e,reserved:n,n:t}}function Zt(a,t){let{grid:e,reserved:n,n:r}=a,o=[];for(let c of t)for(let d=7;d>=0;d--)o.push(c>>d&1);let i=0,s=r-1,l=!0;for(;s>=0;){if(s===6){s--;continue}let c=l?r-1:0,d=l?-1:r,m=l?-1:1;for(let u=c;u!==d;u+=m)for(let p=0;p<2;p++){let y=s-p;y<0||n[u][y]||(e[u][y]=i<o.length&&o[i]?1:-1,i++)}s-=2,l=!l}}var te=[(a,t)=>(a+t)%2===0,(a,t)=>t%2===0,(a,t)=>a%3===0,(a,t)=>(a+t)%3===0,(a,t)=>(Math.floor(t/2)+Math.floor(a/3))%2===0,(a,t)=>a*t%2+a*t%3===0,(a,t)=>(a*t%2+a*t%3)%2===0,(a,t)=>((a+t)%2+a*t%3)%2===0];function At(a,t,e,n){let r=te[n],o=a.map(i=>Int8Array.from(i));for(let i=0;i<e;i++)for(let s=0;s<e;s++)!t[i][s]&&r(s,i)&&(o[i][s]=o[i][s]===1?-1:1);return o}var ee=[21522,20773,24188,23371,17913,16590,20375,19104];function Mt(a,t,e){let n=ee[e],r=[];for(let s=14;s>=0;s--)r.push(n>>s&1);let o=[[0,8],[1,8],[2,8],[3,8],[4,8],[5,8],[7,8],[8,8],[8,7],[8,5],[8,4],[8,3],[8,2],[8,1],[8,0]],i=[[8,t-1],[8,t-2],[8,t-3],[8,t-4],[8,t-5],[8,t-6],[8,t-7],[t-8,8],[t-7,8],[t-6,8],[t-5,8],[t-4,8],[t-3,8],[t-2,8],[t-1,8]];for(let s=0;s<15;s++){let l=r[s]?1:-1;a[o[s][1]][o[s][0]]=l,a[i[s][1]][i[s][0]]=l}}function re(a,t){let e=0;for(let n=0;n<t;n++){let r=1;for(let o=1;o<t;o++)a[n][o]>0==a[n][o-1]>0?r++:(r>=5&&(e+=r-2),r=1);r>=5&&(e+=r-2)}for(let n=0;n<t;n++){let r=1;for(let o=1;o<t;o++)a[o][n]>0==a[o-1][n]>0?r++:(r>=5&&(e+=r-2),r=1);r>=5&&(e+=r-2)}return e}function ne(a){let t=[];for(let l=0;l<a.length;l++){let c=a.charCodeAt(l);c<128?t.push(c):c<2048&&(t.push(192|c>>6),t.push(128|c&63))}let e=Qt(t.length);if(!e)return null;let n=Xt(t,e),r=Jt(e);Zt(r,n);let o=0,i=1/0;for(let l=0;l<8;l++){let c=At(r.grid,r.reserved,r.n,l);Mt(c,r.n,l);let d=re(c,r.n);d<i&&(i=d,o=l)}let s=At(r.grid,r.reserved,r.n,o);return Mt(s,r.n,o),{grid:s,size:r.n}}function ae(a,t,e){let n=a.size,r=Math.max(2,Math.floor(88/n)),o=n*r,i=r/2,s=i*.82,l=n/2,c=n*.18;function d(x,S){let L=Math.sin(x*31+S*17)*1e4;return .75+.25*(L-Math.floor(L))}let m="";for(let x=0;x<n;x++)for(let S=0;S<n;S++){if(a.grid[x][S]<=0)continue;let L=S-l,gt=x-l;if(Math.sqrt(L*L+gt*gt)<c)continue;if(S<7&&x<7||S>=n-7&&x<7||S<7&&x>=n-7)m+=`<rect x="${S*r}" y="${x*r}" width="${r}" height="${r}" rx="${r*.15}" fill="${t}"/>`;else{let Ot=s*d(S,x);m+=`<circle cx="${S*r+i}" cy="${x*r+i}" r="${Ot.toFixed(1)}" fill="${t}"/>`}}let u=l*r,p=l*r,y=c*r*.6,h=e||t,w=y*2/100,b=70*w,R=`<g transform="translate(${u-y},${p-b/2}) scale(${w.toFixed(4)})">`;return R+=`<path d="M86 2 L86 64" stroke="${h}" stroke-width="5" stroke-linecap="round"/>`,R+=`<path d="M7 12 L98 12" stroke="${h}" stroke-width="5" stroke-linecap="round"/>`,R+=`<path d="M7 18 C7 32, 16 64, 30 64 C44 64, 38 28, 52 28 C66 28, 62 64, 86 64" stroke="${t}" stroke-width="5" stroke-linecap="round" fill="none"/>`,R+=`<circle cx="7" cy="12" r="7" fill="${t}"/>`,R+=`<circle cx="86" cy="64" r="7" fill="${h}"/>`,R+="</g>",`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${o} ${o}" width="${o}" height="${o}">${m}${R}</svg>`}var oe=`.integrity-section {
106
106
  margin-top: 2rem;
107
107
  padding-top: 1.5rem;
108
108
  border-top: 1px solid var(--wt-scorecard-border);
@@ -167,8 +167,8 @@ var ft=`:host {
167
167
  color: var(--wt-scorecard-text-tertiary);
168
168
  flex: 1;
169
169
  }
170
- `,D=class extends g{getStylesheet(){return B+`
171
- `+Xt}render(){if(!this._data)return;let{integrity:e,outputSignature:r}=this._data,a=document.createElement("div");a.className="integrity-section";let t=document.createElement("div");t.className="integrity-title",t.textContent="Integrity & Verification",a.appendChild(t);let s=document.createElement("div");s.className="integrity-stats",s.textContent=`${e.eventCount} events \xB7 ${e.checkpoints.length} checkpoints`,a.appendChild(s);let o=document.createElement("div");o.className="integrity-hash-block";let i=document.createElement("span");i.className="integrity-hash-label",i.textContent="Digest (SHA-256)";let c=document.createElement("code");c.className="hash",c.textContent=e.finalDigest,o.append(i,c),a.appendChild(o);let l=document.createElement("div");l.className="integrity-hash-block";let d=document.createElement("span");d.className="integrity-hash-label",d.textContent="Output Signature";let m=document.createElement("code");m.className="hash",m.textContent=r,l.append(d,m),a.appendChild(l);let u=document.createElement("div");u.className="integrity-bottom";let p=document.createElement("div");p.className="qr-container";let y=document.createElement("p");y.className="integrity-explainer",y.textContent="This scorecard includes cryptographic integrity verification. The digest covers all input events; the signature covers the analysis output. Compare against original session data or scan for verification.",u.appendChild(p),u.appendChild(y),a.appendChild(u),this.replaceChart(a),requestAnimationFrame(()=>this.renderQr(e.finalDigest))}renderQr(e){let r=this.shadow.querySelector(".qr-container");if(!r)return;let a=Ut(e);if(!a)return;let t=getComputedStyle(this),s=t.getPropertyValue("--wt-scorecard-text").trim()||"#E4E2DA",o=t.getPropertyValue("--wt-scorecard-status-clear").trim()||"#5EAE78";r.innerHTML=Qt(a,s,o)}};D.tagName="wt-integrity-footer";var Wt=new Set(["WT-104","WT-106","WT-204","WT-302","WT-403","WT-503","WT-506","WT-509","WT-601","WT-602","WT-603"]);function Jt(n){return Wt.has(n)}function M(n){return n?Wt.has(n)?"pass":"flag":"unknown"}var I={contentOrigin:"Content Origin",timingAuthenticity:"Timing & Rhythm",revisionBehavior:"Revision Behavior",sessionContinuity:"Session Continuity",physicalPlausibility:"Physical Plausibility",temporalPatterns:"Temporal Patterns"},rt=["contentOrigin","timingAuthenticity","revisionBehavior","sessionContinuity","physicalPlausibility","temporalPatterns"],mt=["contentOrigin","timingAuthenticity","revisionBehavior"],ut=["sessionContinuity","physicalPlausibility","temporalPatterns"],Zt={"WT-100":()=>"No content was recorded during this session.","WT-101":n=>{let e=n.params.pct??0,r=100-e;return`Nearly all content (${e}%) was pasted from an external source. Only ${r}% of characters were typed directly.`},"WT-102":n=>`${n.params.pct??0}% of text was inserted via autocomplete, suggesting reliance on predictive input rather than original composition.`,"WT-103":n=>{let e=n.params.pct??0,r=100-e;return`${e}% of text was pasted from external sources. The remaining ${r}% was typed directly.`},"WT-104":()=>"All text was typed directly \u2014 no paste or autocomplete events were detected.","WT-105":()=>"Unmodified external content detected \u2014 pasted text was not edited after insertion, suggesting pre-composed content.","WT-106":n=>`${n.params.rework??0}% of pasted content was subsequently reworked, indicating the writer integrated external material into their own composition.`,"WT-107":n=>{let e=n.params.pasteRatio??0,r=n.params.retentionPct??0;return`High paste volume (${e}% paste ratio) with ${r}% left unmodified \u2014 content was pasted in bulk without rework.`}},te={"WT-105":()=>"Unmodified external content detected \u2014 pasted text was not edited after insertion, suggesting pre-composed content.","WT-106":n=>`${n.params.rework??0}% of pasted content was subsequently reworked, indicating the writer integrated external material into their own composition.`,"WT-107":n=>{let e=n.params.pasteRatio??0,r=n.params.retentionPct??0;return`High paste volume (${e}% paste ratio) with ${r}% left unmodified \u2014 content was pasted in bulk without rework.`}},ee={"WT-200":n=>{let e=(n.params.dwellMean??0).toFixed(1),r=(n.params.flightMean??0).toFixed(1);return`Keystroke timing magnitudes (dwell ${e}ms, flight ${r}ms) fall below plausible human ranges, consistent with programmatic input injection.`},"WT-201":n=>`Keystroke timing is mechanically uniform \u2014 the coefficient of variation (${(n.params.cv??0).toFixed(2)}) falls far below the human range of 0.3\u20130.8. This pattern is consistent with automated input.`,"WT-202":n=>`A highly periodic keystroke pattern was detected (score ${(n.params.score??0).toFixed(2)}). Human typing naturally varies; metronomic regularity suggests automation.`,"WT-203":n=>`Flight times between keystrokes are suspiciously uniform (CV ${(n.params.cv??0).toFixed(2)}), lacking the natural variability expected from human finger movement.`,"WT-204":()=>"Keystroke timing variability falls within normal human ranges. The rhythm is consistent with natural typing."},re={"WT-500":(n,e)=>`Zero corrections across the entire session. Human writers make mistakes \u2014 a ${e.keydownCount}-keystroke session with no corrections is a strong signal content was not composed here.`,"WT-501":()=>"No keystrokes were recorded, so revision behavior could not be analyzed.","WT-502":n=>`Very low correction rate (${(n.params.pct??0).toFixed(1)}%). While some writers are precise, this level of accuracy across an entire session is unusual.`,"WT-503":n=>`Normal correction rate (${(n.params.pct??0).toFixed(1)}%). The writer made and fixed mistakes at a rate consistent with natural composition.`,"WT-504":n=>`No corrections, navigation, or undo in a ${n.params.count??0}-keystroke session \u2014 the text was entered linearly without any revision.`,"WT-505":()=>"Non-linear editing was detected despite a low correction rate, suggesting some revision activity.","WT-506":n=>`Authentic revision depth detected (product-process ratio ${(n.params.ratio??0).toFixed(2)}). The writing process shows genuine iterative refinement.`,"WT-507":n=>{let e=n.params.count??0,r=n.params.keydowns??0;return`Linear transcription pattern: only ${e} insertions in a ${r}-keystroke session, with minimal revision or restructuring.`},"WT-508":n=>`Forward-edge concentration: ${Math.round((n.params.ratio??0)*100)}% of keystrokes occurred at the end of the document with almost no in-document editing, consistent with copy-typing or automation.`,"WT-509":n=>`Multi-word restructuring detected (${Math.round((n.params.ratio??0)*100)}% of chars from multi-word pastes), suggesting authentic revision where the writer rearranged their own text.`},ae={"WT-300":n=>{let e=Math.round(n.params.timestamp??0),r=(n.params.magnitude??0).toFixed(1);return`Typing rhythm changed abruptly at ${e}s (magnitude ${r}), suggesting a possible switch in input method or author.`},"WT-301":n=>`${n.params.count??0} tab-away events detected \u2014 the writer left and returned to this field multiple times during the session.`,"WT-302":()=>"Behavior was consistent throughout the session with no abrupt changes in typing rhythm or style."},ne={"WT-400":n=>`${n.params.pct??0}% of events lack browser trust indicators (isTrusted=false), suggesting synthetic event injection.`,"WT-401":n=>{let e=n.params.count??0,r=n.params.pct??0;return`${e} keydown events had no matching keyup (${r}% of keydowns). Automation tools often omit keyup events.`},"WT-402":n=>`${n.params.count??0} keystroke sequences exceed the maximum human typing speed, indicating programmatic input.`,"WT-403":()=>"All keystroke timing is physically plausible \u2014 no evidence of synthetic or injected events.","WT-404":n=>{let e=n.params.chars??0,r=n.params.pct??0;return`${e} characters (${r}%) were inserted programmatically, bypassing normal keystroke input. This is consistent with automated text injection.`},"WT-405":n=>{let e=n.params.count??0,r=n.params.pct??0;return`${e} events (${r}% of keydowns) have sub-millisecond dwell time. Human key press/release always takes 30\u2013150ms; zero-latency events indicate programmatic injection.`}},oe={"WT-600":n=>`No speed variation over a ${n.params.minutes??0}-minute session. Human typing naturally fluctuates; constant speed suggests automation.`,"WT-601":()=>"Natural warmup and fatigue pattern detected \u2014 the writer started slow, reached peak speed, then gradually slowed.","WT-602":()=>"Significant fatigue detected toward the end of the session, consistent with sustained human cognitive effort.","WT-603":()=>"Temporal patterns fall within normal range \u2014 typing pace varied naturally over the session.","WT-604":n=>`${n.params.ratio??0}% of keystrokes occurred in machine-like bursts, suggesting automated input segments.`,"WT-605":n=>`Uniform typing pace across the session (fluency SD ${(n.params.sd??0).toFixed(1)}). Human writers show more variation as they think, pause, and revise.`,"WT-606":n=>`Frequent revision interruptions detected (R-burst median ${(n.params.median??0).toFixed(1)}s), consistent with active editing behavior.`,"WT-607":n=>`No linguistic pause structure detected (sentence/word pause ratio ${(n.params.ratio??0).toFixed(2)}). Human writers pause longer before sentences than within words.`,"WT-608":n=>`Low cognitive pause rate (${(n.params.rate??0).toFixed(1)}% of keystrokes), suggesting text was transcribed rather than composed.`},se={contentOrigin:Zt,timingAuthenticity:ee,revisionBehavior:re,sessionContinuity:ae,physicalPlausibility:ne,temporalPatterns:oe};function at(n,e){let r=e[n];if(!(r!=null&&r.indicator))return"Analysis data not available.";let a=se[n];if(!a)return Rt(r.indicator);if(n==="contentOrigin"&&r.pasteReworkIndicator){let s=r.pasteReworkIndicator.code,o=te[s];if(o)return o(r.pasteReworkIndicator,e)}let t=a[r.indicator.code];return t?t(r.indicator,e):Rt(r.indicator)}function Rt(n){return`Indicator ${n.code} detected.`}var ie={contentOrigin:"In a typical session, you'd see a continuous band of typed content with occasional small paste events. A single bulk insertion is characteristic of copy-paste submission.",timingAuthenticity:"A human heatmap shows scattered clusters reflecting natural variation in finger movement. Tight single-point concentration indicates programmatic keystroke injection.",revisionBehavior:"Human writers produce clusters of corrections as they re-read and revise. Absence of corrections suggests transcription rather than composition.",sessionContinuity:"Steady growth with small plateaus (thinking pauses) is typical. A sudden vertical jump indicates bulk content insertion.",physicalPlausibility:"Human editing jumps around the document \u2014 revising earlier sections, appending new text. Strictly sequential cursor movement suggests automated input.",temporalPatterns:"Human typing shows varied pause durations \u2014 short pauses within words, longer pauses between sentences. Uniform pause lengths suggest automated pacing."};function pt(n){return ie[n]??null}function nt(n,e){return({contentOrigin:a=>{let t=a.contentOrigin.metrics,s=Math.round(t.charactersByOrigin.pasted*100),o=Math.round(t.charactersByOrigin.typed*100),i=t.pasteEvents.length,c=t.pasteEvents.reduce((l,d)=>l+d.characterCount,0);return[{label:"pasted",value:`${s}%`,flagged:s>50},{label:"typed",value:`${o}%`,flagged:!1},{label:"paste events",value:String(i),flagged:!1},{label:"chars pasted",value:le(c),flagged:!1}]},timingAuthenticity:a=>{let t=a.timingAuthenticity.metrics,s=t.flightTimeDistribution.cv,o=t.dwellTimeDistribution.mean;return[{label:"timing cv",value:s.toFixed(2),flagged:s<.2},{label:"mean dwell",value:`${Math.round(o)}ms`,flagged:o<20},{label:"periodicity",value:t.periodicityScore.toFixed(2),flagged:t.periodicityScore>.5},{label:"entropy",value:t.entropy.toFixed(1),flagged:t.entropy<1.5}]},revisionBehavior:a=>{let t=a.revisionBehavior.metrics;return[{label:"corrections",value:String(t.correctionCount),flagged:t.correctionCount===0},{label:"navigation",value:String(t.navigationCount),flagged:t.navigationCount===0},{label:"undo / redo",value:String(t.undoRedoCount),flagged:!1},{label:"product-process",value:t.productProcessRatio.toFixed(2),flagged:t.productProcessRatio===0}]},sessionContinuity:a=>{let t=a.sessionContinuity.metrics;return[{label:"change points",value:String(t.changePoints.length),flagged:t.changePoints.length>2},{label:"tab-away events",value:String(t.tabAwayEvents.length),flagged:!1}]},physicalPlausibility:a=>{let t=a.physicalPlausibility.metrics;return[{label:"synthetic ratio",value:`${Math.round(t.syntheticEventRatio*100)}%`,flagged:t.syntheticEventRatio>.05},{label:"impossible seq.",value:String(t.impossibleSequences.count),flagged:t.impossibleSequences.count>0},{label:"unmatched keydowns",value:String(t.unmatchedKeydownCount),flagged:t.unmatchedKeydownCount>5},{label:"zero-latency",value:String(t.zeroLatencyEventCount),flagged:t.zeroLatencyEventCount>0},{label:"Bulk Insert",value:String(t.bulkInsertCharCount),flagged:t.bulkInsertCharCount>0}]},temporalPatterns:a=>{let t=a.temporalPatterns.metrics;return[{label:"duration",value:ot(t.sessionDurationMs),flagged:!1},{label:"warmup ratio",value:t.warmupRatio.toFixed(2),flagged:!1},{label:"fatigue ratio",value:t.fatigueRatio.toFixed(2),flagged:!1},{label:"burst ratio",value:t.burstPattern.burstToTotalRatio.toFixed(2),flagged:t.burstPattern.burstToTotalRatio>.7}]}}[n]??(()=>[]))(e)}function le(n){return n>=1e6?`${(n/1e6).toFixed(1)}m`:n>=1e3?`${(n/1e3).toFixed(1)}k`:String(n)}function ot(n){let e=Math.round(n/1e3);if(e<60)return`${e}s`;let r=Math.floor(e/60),a=e%60;return a===0?`${r}m`:`${r}m ${a}s`}var Mt={"coefficient of variation":{definition:"Standard deviation divided by the mean \u2014 measures how spread out values are relative to their average. Low CV means uniform timing.",docsPath:"/docs/analysis/timing/"},"dwell time":{definition:"How long a key is held down before being released.",docsPath:"/docs/analysis/timing/"},"flight time":{definition:"The gap between releasing one key and pressing the next.",docsPath:"/docs/analysis/timing/"},"product-process ratio":{definition:"The ratio of final text length to total characters typed. Low values suggest heavy revision; near 1.0 suggests linear transcription.",docsPath:"/docs/analysis/revision/"},periodicity:{definition:"How rhythmically regular the typing pattern is. High periodicity suggests metronomic (automated) input."},entropy:{definition:"A measure of randomness in timing. Low entropy means predictable, uniform intervals."},burst:{definition:"A rapid sequence of keystrokes between pauses. Human typing naturally occurs in bursts."},"synthetic event":{definition:"A keyboard event generated programmatically rather than by a real keypress. Browsers mark these with isTrusted=false."},"change point":{definition:"A moment where typing rhythm shifts abruptly, potentially indicating a switch in input method."}};function st(n,e){let r=v(n);for(let[a,t]of Object.entries(Mt)){let s=new RegExp(`\\b(${ce(a)})\\b`,"gi");r=r.replace(s,o=>{let i=`title="${v(t.definition)}" class="wt-term"`,c=v(o);if(t.docsPath){let l=(e??"https://writetrack.dev")+t.docsPath;return`<a href="${v(l)}" target="_blank" rel="noopener"><abbr ${i}>${c}</abbr></a>`}return`<abbr ${i}>${c}</abbr>`})}return r}function ce(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}import*as f from"@observablehq/plot";var de={contentOrigin:[0,1],timingAuthenticity:[0,1],revisionBehavior:[0,3],sessionContinuity:[0,1],physicalPlausibility:[0,1],temporalPatterns:[1,2]},me={contentOrigin:{name:"Composition Timeline",desc:"Horizontal bar showing typing vs paste segments over time"},timingAuthenticity:{name:"Rhythm Heatmap",desc:"Dwell time vs flight time scatter showing keystroke timing distribution"},revisionBehavior:{name:"Corrections Timeline",desc:"Edit operations plotted over session time, sized by magnitude"},sessionContinuity:{name:"Document Growth Curve",desc:"Document length over session time, highlighting change points"},physicalPlausibility:{name:"Edit Waterfall",desc:"Cursor position over time, showing insertion and deletion patterns"},temporalPatterns:{name:"Speed Timeline",desc:"Words per minute over session duration, showing warmup, peak, and fatigue"}},$t={contentOrigin:1,timingAuthenticity:1,revisionBehavior:1,sessionContinuity:2,physicalPlausibility:2,temporalPatterns:2},ue=`:host { display: block; overflow: hidden; }
170
+ `,O=class extends g{getStylesheet(){return N+`
171
+ `+oe}render(){if(!this._data)return;let{integrity:t,outputSignature:e}=this._data,n=document.createElement("div");n.className="integrity-section";let r=document.createElement("div");r.className="integrity-title",r.textContent="Integrity & Verification",n.appendChild(r);let o=document.createElement("div");o.className="integrity-stats",o.textContent=`${t.eventCount} events \xB7 ${t.checkpoints.length} checkpoints`,n.appendChild(o);let i=document.createElement("div");i.className="integrity-hash-block";let s=document.createElement("span");s.className="integrity-hash-label",s.textContent="Digest (SHA-256)";let l=document.createElement("code");l.className="hash",l.textContent=t.finalDigest,i.append(s,l),n.appendChild(i);let c=document.createElement("div");c.className="integrity-hash-block";let d=document.createElement("span");d.className="integrity-hash-label",d.textContent="Output Signature";let m=document.createElement("code");m.className="hash",m.textContent=e,c.append(d,m),n.appendChild(c);let u=document.createElement("div");u.className="integrity-bottom";let p=document.createElement("div");p.className="qr-container";let y=document.createElement("p");y.className="integrity-explainer",y.textContent="This scorecard includes cryptographic integrity verification. The digest covers all input events; the signature covers the analysis output. Compare against original session data or scan for verification.",u.appendChild(p),u.appendChild(y),n.appendChild(u),this.replaceChart(n),requestAnimationFrame(()=>this.renderQr(t.finalDigest))}renderQr(t){let e=this.shadow.querySelector(".qr-container");if(!e)return;let n=ne(t);if(!n)return;let r=getComputedStyle(this),o=r.getPropertyValue("--wt-scorecard-text").trim()||"#E4E2DA",i=r.getPropertyValue("--wt-scorecard-status-clear").trim()||"#5EAE78";e.innerHTML=ae(n,o,i)}};O.tagName="wt-integrity-footer";var $t=new Set(["WT-104","WT-106","WT-204","WT-302","WT-403","WT-503","WT-506","WT-509","WT-601","WT-602","WT-603"]);function ie(a){return $t.has(a)}function $(a){return a?$t.has(a)?"pass":"flag":"unknown"}var F={contentOrigin:"Content Origin",timingAuthenticity:"Timing & Rhythm",revisionBehavior:"Revision Behavior",sessionContinuity:"Session Continuity",physicalPlausibility:"Physical Plausibility",temporalPatterns:"Temporal Patterns"},nt=["contentOrigin","timingAuthenticity","revisionBehavior","sessionContinuity","physicalPlausibility","temporalPatterns"],pt=["contentOrigin","timingAuthenticity","revisionBehavior"],ht=["sessionContinuity","physicalPlausibility","temporalPatterns"],se={"WT-100":()=>"No content was recorded during this session.","WT-101":a=>{let t=a.params.pct??0,e=100-t;return`Nearly all content (${t}%) was pasted from an external source. Only ${e}% of characters were typed directly.`},"WT-102":a=>`${a.params.pct??0}% of text was inserted via autocomplete, suggesting reliance on predictive input rather than original composition.`,"WT-103":a=>{let t=a.params.pct??0,e=100-t;return`${t}% of text was pasted from external sources. The remaining ${e}% was typed directly.`},"WT-104":()=>"All text was typed directly \u2014 no paste or autocomplete events were detected.","WT-105":()=>"Unmodified external content detected \u2014 pasted text was not edited after insertion, suggesting pre-composed content.","WT-106":a=>`${a.params.rework??0}% of pasted content was subsequently reworked, indicating the writer integrated external material into their own composition.`,"WT-107":a=>{let t=a.params.pasteRatio??0,e=a.params.retentionPct??0;return`High paste volume (${t}% paste ratio) with ${e}% left unmodified \u2014 content was pasted in bulk without rework.`}},le={"WT-105":()=>"Unmodified external content detected \u2014 pasted text was not edited after insertion, suggesting pre-composed content.","WT-106":a=>`${a.params.rework??0}% of pasted content was subsequently reworked, indicating the writer integrated external material into their own composition.`,"WT-107":a=>{let t=a.params.pasteRatio??0,e=a.params.retentionPct??0;return`High paste volume (${t}% paste ratio) with ${e}% left unmodified \u2014 content was pasted in bulk without rework.`}},ce={"WT-200":a=>{let t=(a.params.dwellMean??0).toFixed(1),e=(a.params.flightMean??0).toFixed(1);return`Keystroke timing magnitudes (dwell ${t}ms, flight ${e}ms) fall below plausible human ranges, consistent with programmatic input injection.`},"WT-201":a=>`Keystroke timing is mechanically uniform \u2014 the coefficient of variation (${(a.params.cv??0).toFixed(2)}) falls far below the human range of 0.3\u20130.8. This pattern is consistent with automated input.`,"WT-202":a=>`A highly periodic keystroke pattern was detected (score ${(a.params.score??0).toFixed(2)}). Human typing naturally varies; metronomic regularity suggests automation.`,"WT-203":a=>`Flight times between keystrokes are suspiciously uniform (CV ${(a.params.cv??0).toFixed(2)}), lacking the natural variability expected from human finger movement.`,"WT-204":()=>"Keystroke timing variability falls within normal human ranges. The rhythm is consistent with natural typing."},de={"WT-500":(a,t)=>`Zero corrections across the entire session. Human writers make mistakes \u2014 a ${t.keydownCount}-keystroke session with no corrections is a strong signal content was not composed here.`,"WT-501":()=>"No keystrokes were recorded, so revision behavior could not be analyzed.","WT-502":a=>`Very low correction rate (${(a.params.pct??0).toFixed(1)}%). While some writers are precise, this level of accuracy across an entire session is unusual.`,"WT-503":a=>`Normal correction rate (${(a.params.pct??0).toFixed(1)}%). The writer made and fixed mistakes at a rate consistent with natural composition.`,"WT-504":a=>`No corrections, navigation, or undo in a ${a.params.count??0}-keystroke session \u2014 the text was entered linearly without any revision.`,"WT-505":()=>"Non-linear editing was detected despite a low correction rate, suggesting some revision activity.","WT-506":a=>`Authentic revision depth detected (product-process ratio ${(a.params.ratio??0).toFixed(2)}). The writing process shows genuine iterative refinement.`,"WT-507":a=>{let t=a.params.count??0,e=a.params.keydowns??0;return`Sequential typing pattern: ${t} mid-document insertions in a ${e}-keystroke session. Content was entered start-to-finish without returning to edit earlier sections.`},"WT-508":a=>`Forward-edge concentration: ${Math.round((a.params.ratio??0)*100)}% of keystrokes occurred at the end of the document with almost no in-document editing, consistent with copy-typing or automation.`,"WT-509":a=>`Multi-word restructuring detected (${Math.round((a.params.ratio??0)*100)}% of chars from multi-word pastes), suggesting authentic revision where the writer rearranged their own text.`},me={"WT-300":a=>{let t=Math.round(a.params.timestamp??0),e=(a.params.magnitude??0).toFixed(1);return`Typing rhythm changed abruptly at ${t}s (magnitude ${e}), suggesting a possible switch in input method or author.`},"WT-301":a=>`${a.params.count??0} tab-away events detected \u2014 the writer left and returned to this field multiple times during the session.`,"WT-302":()=>"Behavior was consistent throughout the session with no abrupt changes in typing rhythm or style."},ue={"WT-400":a=>`${a.params.pct??0}% of events lack browser trust indicators (isTrusted=false), suggesting synthetic event injection.`,"WT-401":a=>{let t=a.params.count??0,e=a.params.pct??0;return`${t} keydown events had no matching keyup (${e}% of keydowns). Automation tools often omit keyup events.`},"WT-402":a=>`${a.params.count??0} keystroke sequences exceed the maximum human typing speed, indicating programmatic input.`,"WT-403":()=>"All keystroke timing is physically plausible \u2014 no evidence of synthetic or injected events.","WT-404":a=>{let t=a.params.chars??0,e=a.params.pct??0;return`${t} characters (${e}%) were inserted via untrusted programmatic events rather than direct user input.`},"WT-405":a=>{let t=a.params.count??0,e=a.params.pct??0;return`${t} events (${e}% of keydowns) have sub-millisecond dwell time. Human key press/release always takes 30\u2013150ms; zero-latency events indicate programmatic injection.`}},pe={"WT-600":a=>`No speed variation over a ${a.params.minutes??0}-minute session. Human typing naturally fluctuates; constant speed suggests automation.`,"WT-601":()=>"Natural warmup and fatigue pattern detected \u2014 the writer started slow, reached peak speed, then gradually slowed.","WT-602":()=>"Significant fatigue detected toward the end of the session, consistent with sustained human cognitive effort.","WT-603":()=>"Temporal patterns fall within normal range \u2014 typing pace varied naturally over the session.","WT-604":a=>`${a.params.ratio??0}% of keystrokes occurred in machine-like bursts, suggesting automated input segments.`,"WT-605":a=>`Uniform typing pace across the session (fluency SD ${(a.params.sd??0).toFixed(1)}). Human writers show more variation as they think, pause, and revise.`,"WT-606":a=>`Frequent revision interruptions detected (R-burst median ${(a.params.median??0).toFixed(1)}s), consistent with active editing behavior.`,"WT-607":a=>`No linguistic pause structure detected (sentence/word pause ratio ${(a.params.ratio??0).toFixed(2)}). Human writers pause longer before sentences than within words.`,"WT-608":a=>`Low cognitive pause rate (${(a.params.rate??0).toFixed(1)}% of keystrokes), suggesting text was transcribed rather than composed.`},he={contentOrigin:se,timingAuthenticity:ce,revisionBehavior:de,sessionContinuity:me,physicalPlausibility:ue,temporalPatterns:pe};function at(a,t){let e=t[a];if(!(e!=null&&e.indicator))return"Analysis data not available.";let n=he[a];if(!n)return Wt(e.indicator);if(a==="contentOrigin"&&e.pasteReworkIndicator){let o=e.pasteReworkIndicator.code,i=le[o];if(i)return i(e.pasteReworkIndicator,t)}let r=n[e.indicator.code];return r?r(e.indicator,t):Wt(e.indicator)}function Wt(a){return`Indicator ${a.code} detected.`}var fe={contentOrigin:"Shows the mix of typed, pasted, and autocompleted content. Most writing sessions include some paste events \u2014 the balance and context matter more than presence alone.",timingAuthenticity:"A human heatmap shows scattered clusters reflecting natural variation in finger movement. Tight single-point concentration indicates programmatic keystroke injection.",revisionBehavior:"Human writers produce clusters of corrections as they re-read and revise. Absence of corrections suggests transcription rather than composition.",sessionContinuity:"Steady growth with small plateaus (thinking pauses) is typical. A sudden vertical jump indicates bulk content insertion.",physicalPlausibility:"Human editing jumps around the document \u2014 revising earlier sections, appending new text. Strictly sequential cursor movement suggests automated input.",temporalPatterns:"Human typing shows varied pause durations \u2014 short pauses within words, longer pauses between sentences. Uniform pause lengths suggest automated pacing."};function ft(a){return fe[a]??null}function ot(a,t){return({contentOrigin:ge,timingAuthenticity:ye,revisionBehavior:be,sessionContinuity:we,physicalPlausibility:ve,temporalPatterns:xe}[a]??(()=>[]))(t)}function ge(a){let t=a.contentOrigin.metrics,e=Math.round(t.charactersByOrigin.pasted*100),n=Math.round(t.charactersByOrigin.typed*100),r=t.pasteEvents.length,o=t.pasteEvents.reduce((i,s)=>i+s.characterCount,0);return[{label:"pasted",value:`${e}%`,flagged:e>50},{label:"typed",value:`${n}%`,flagged:!1},{label:"paste events",value:String(r),flagged:!1},{label:"chars pasted",value:Se(o),flagged:!1}]}function ye(a){let t=a.timingAuthenticity.metrics,e=t.flightTimeDistribution.cv,n=t.dwellTimeDistribution.mean;return[{label:"timing cv",value:e.toFixed(2),flagged:e<.2},{label:"mean dwell",value:`${Math.round(n)}ms`,flagged:n<20},{label:"periodicity",value:t.periodicityScore.toFixed(2),flagged:t.periodicityScore>.5},{label:"entropy",value:t.entropy.toFixed(1),flagged:t.entropy<1.5}]}function be(a){let t=a.revisionBehavior.metrics;return[{label:"corrections",value:String(t.correctionCount),flagged:t.correctionCount===0},{label:"navigation",value:String(t.navigationCount),flagged:t.navigationCount===0},{label:"undo / redo",value:String(t.undoRedoCount),flagged:!1},{label:"product-process",value:t.productProcessRatio.toFixed(2),flagged:t.productProcessRatio===0}]}function we(a){let t=a.sessionContinuity.metrics;return[{label:"change points",value:String(t.changePoints.length),flagged:t.changePoints.length>2},{label:"tab-away events",value:String(t.tabAwayEvents.length),flagged:!1}]}function ve(a){let t=a.physicalPlausibility.metrics;return[{label:"synthetic ratio",value:`${Math.round(t.syntheticEventRatio*100)}%`,flagged:t.syntheticEventRatio>.05},{label:"impossible seq.",value:String(t.impossibleSequences.count),flagged:t.impossibleSequences.count>0},{label:"unmatched keydowns",value:String(t.unmatchedKeydownCount),flagged:t.unmatchedKeydownCount>5},{label:"zero-latency",value:String(t.zeroLatencyEventCount),flagged:t.zeroLatencyEventCount>0},{label:"Bulk Insert",value:String(t.bulkInsertCharCount),flagged:t.bulkInsertCharCount>0}]}function xe(a){let t=a.temporalPatterns.metrics;return[{label:"duration",value:it(t.sessionDurationMs),flagged:!1},{label:"warmup ratio",value:t.warmupRatio.toFixed(2),flagged:!1},{label:"fatigue ratio",value:t.fatigueRatio.toFixed(2),flagged:!1},{label:"burst ratio",value:t.burstPattern.burstToTotalRatio.toFixed(2),flagged:t.burstPattern.burstToTotalRatio>.7}]}function Se(a){return a>=1e6?`${(a/1e6).toFixed(1)}m`:a>=1e3?`${(a/1e3).toFixed(1)}k`:String(a)}function it(a){let t=Math.round(a/1e3);if(t<60)return`${t}s`;let e=Math.floor(t/60),n=t%60;return n===0?`${e}m`:`${e}m ${n}s`}var Dt={"coefficient of variation":{definition:"Standard deviation divided by the mean \u2014 measures how spread out values are relative to their average. Low CV means uniform timing.",docsPath:"/docs/analysis/timing/"},"dwell time":{definition:"How long a key is held down before being released.",docsPath:"/docs/analysis/timing/"},"flight time":{definition:"The gap between releasing one key and pressing the next.",docsPath:"/docs/analysis/timing/"},"product-process ratio":{definition:"The ratio of final text length to total characters typed. Low values suggest heavy revision; near 1.0 suggests linear transcription.",docsPath:"/docs/analysis/revision/"},periodicity:{definition:"How rhythmically regular the typing pattern is. High periodicity suggests metronomic (automated) input."},entropy:{definition:"A measure of randomness in timing. Low entropy means predictable, uniform intervals."},burst:{definition:"A rapid sequence of keystrokes between pauses. Human typing naturally occurs in bursts."},"synthetic event":{definition:"A keyboard event generated programmatically rather than by a real keypress. Browsers mark these with isTrusted=false."},"change point":{definition:"A moment where typing rhythm shifts abruptly, potentially indicating a switch in input method."}};function st(a,t){let e=v(a);for(let[n,r]of Object.entries(Dt)){let o=new RegExp(`\\b(${ke(n)})\\b`,"gi");e=e.replace(o,i=>{let s=`title="${v(r.definition)}" class="wt-term"`,l=v(i);if(r.docsPath){let c=(t??"https://writetrack.dev")+r.docsPath;return`<a href="${v(c)}" target="_blank" rel="noopener"><abbr ${s}>${l}</abbr></a>`}return`<abbr ${s}>${l}</abbr>`})}return e}function ke(a){return a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}import*as f from"@observablehq/plot";var Ce={contentOrigin:[0,1],timingAuthenticity:[0,1],revisionBehavior:[0,3],sessionContinuity:[0,1],physicalPlausibility:[0,1],temporalPatterns:[1,2]},Te={contentOrigin:{name:"Composition Timeline",desc:"Horizontal bar showing typing vs paste segments over time"},timingAuthenticity:{name:"Rhythm Heatmap",desc:"Dwell time vs flight time scatter showing keystroke timing distribution"},revisionBehavior:{name:"Corrections Timeline",desc:"Edit operations plotted over session time, sized by magnitude"},sessionContinuity:{name:"Document Growth Curve",desc:"Document length over session time, highlighting change points"},physicalPlausibility:{name:"Edit Waterfall",desc:"Cursor position over time, showing insertion and deletion patterns"},temporalPatterns:{name:"Speed Timeline",desc:"Words per minute over session duration, showing warmup, peak, and fatigue"}},_t={contentOrigin:1,timingAuthenticity:1,revisionBehavior:1,sessionContinuity:2,physicalPlausibility:2,temporalPatterns:2},Ee=`:host { display: block; overflow: hidden; }
172
172
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
173
173
  .page {
174
174
  max-width: 100%;
@@ -355,5 +355,5 @@ var ft=`:host {
355
355
  .page { padding: 1.25rem 1rem 2rem; }
356
356
  .detail-inner { padding: 1rem; }
357
357
  }
358
- `,it=class extends g{constructor(){super();this.t={1:null,2:null};D.register()}onResize(){this.rerenderAllCharts()}getStylesheet(){return B+`
359
- `+ue}attributeChangedCallback(r,a,t){if(r==="theme"&&this._data&&this.hasRendered){let s=this.shadow.querySelector(".theme-toggle");s&&(s.textContent=t==="dark"?"Light":"Dark");let o=this.shadow.querySelector("wt-integrity-footer");o&&t&&o.setAttribute("theme",t),requestAnimationFrame(()=>this.rerenderAllCharts());return}super.attributeChangedCallback(r,a,t)}render(){var m;if(!((m=this._data)!=null&&m.analysis))return;let{data:r,analysis:a}=this._data;this.t={1:null,2:null};let t=document.createElement("div");t.className="page",t.appendChild(this.buildHeader(a,r.metadata.sessionId??"")),t.appendChild(this.buildSummary(a)),t.appendChild(this.buildTierLabel("Primary Evidence"));let s=this.buildGrid(1,a);t.appendChild(s);let o=this.buildDetailPanel(1);t.appendChild(o),t.appendChild(this.buildTierLabel("Supporting Context"));let i=this.buildGrid(2,a);t.appendChild(i);let c=this.buildDetailPanel(2);t.appendChild(c);let l=document.createElement("wt-integrity-footer"),d=this.getAttribute("theme");d&&l.setAttribute("theme",d),Tt(l),l.setData({integrity:a.integrity,outputSignature:a.outputSignature,sessionId:r.metadata.sessionId??""}),t.appendChild(l),this.replaceChart(t),requestAnimationFrame(()=>{this.renderAllCharts()})}buildHeader(r,a){let t=document.createElement("header");t.className="header";let s=document.createElement("div");s.className="header-meta";let o=document.createElement("span");o.textContent=`WriteTrack v${r.version}`;let i=document.createElement("span");i.className="sep",i.innerHTML="&middot;";let c=document.createElement("span"),l=new Date(r.analyzedAt);c.textContent=l.toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"});let d=document.createElement("span");d.className="sep",d.innerHTML="&middot;";let m=document.createElement("span");m.className="mono",m.textContent=a,s.append(o,i,c,d,m);let u=document.createElement("button");return u.className="theme-toggle",u.textContent=this.getAttribute("theme")==="dark"?"Light":"Dark",u.addEventListener("click",()=>{let y=this.getAttribute("theme")==="dark"?"light":"dark";this.setAttribute("theme",y);try{localStorage.setItem("writetrack-v4-theme",y)}catch{}}),t.append(s,u),t}buildSummary(r){let a=document.createElement("section");a.className="summary";let t=document.createElement("div");t.className="summary-headline";let s=document.createElement("h1");s.textContent="Session Scorecard";let o=rt.filter(d=>M(this.getIndicatorCode(r,d))==="pass").length,i=document.createElement("span");i.className="tally",i.textContent=`${o} of ${rt.length} clear`,t.append(s,i),a.appendChild(t);let c=document.createElement("div");c.className="summary-stats";let l=ot(r.temporalPatterns.metrics.sessionDurationMs);c.innerHTML=`<span>${v(l)} duration</span><span class="sep">&middot;</span><span>${r.keydownCount} keystrokes</span>`,a.appendChild(c);for(let d of rt)if(M(this.getIndicatorCode(r,d))==="flag"){let m=document.createElement("div");m.className="summary-flag";let u=at(d,r);m.innerHTML=`<strong>Flagged</strong> ${v(I[d]??d)}\u2009\u2014\u2009${v(u)}`,a.appendChild(m)}return a}buildTierLabel(r){let a=document.createElement("div");return a.className="tier-label",a.textContent=r,a}buildGrid(r,a){let t=document.createElement("div");t.className="indicator-grid",t.id=`grid-${r}`;let s=r===1?mt:ut;for(let o of s)t.appendChild(this.buildCell(o,a));return t}buildCell(r,a){let t=this.getIndicatorCode(a,r),o=M(t)==="flag",i=document.createElement("div");i.className="cell"+(o?" flagged":""),i.setAttribute("data-category",r),i.addEventListener("click",()=>this.selectCell(r));let c=document.createElement("div");c.className="cell-header";let l=document.createElement("div");l.className="cell-name-col";let d=document.createElement("span");d.className="cell-name",d.textContent=I[r]??r,l.appendChild(d);let m=document.createElement("span");m.className=`cell-status ${o?"flagged":"clear"}`,m.textContent=o?"flagged":"clear",c.append(l,m),i.appendChild(c);let u=document.createElement("div");u.className="cell-chart",i.appendChild(u);let p=nt(r,a),y=de[r];if(r==="physicalPlausibility"&&!o)if(p.every(b=>b.value==="0"||b.value==="0%")){let b=document.createElement("div");b.className="cell-allclear",b.innerHTML='<span class="cell-allclear-dot"></span>No anomalies detected',i.appendChild(b)}else i.appendChild(this.buildCellMetrics(p,y));else i.appendChild(this.buildCellMetrics(p,y));let h=document.createElement("div");return h.className="cell-affordance",h.innerHTML='<span>Details</span><span class="cell-affordance-arrow">&#x25B8;</span>',i.appendChild(h),i}buildCellMetrics(r,a){let t=document.createElement("div");t.className="cell-metrics";for(let s of a){let o=r[s];if(!o)continue;let i=document.createElement("div");i.className="cell-metric",i.innerHTML=`<span class="cell-metric-label">${v(o.label)}</span><span class="cell-metric-value">${v(o.value)}</span>`,t.appendChild(i)}return t}buildDetailPanel(r){let a=document.createElement("div");a.className="detail-panel",a.id=`detail-${r}`;let t=document.createElement("button");t.className="detail-close",t.setAttribute("aria-label","Close detail"),t.innerHTML="&times; Close",t.addEventListener("click",o=>{o.stopPropagation(),this.closeDetail(r)}),a.appendChild(t);let s=document.createElement("div");return s.className="detail-inner",s.id=`detail-${r}-inner`,a.appendChild(s),a}selectCell(r){var d;let a=(d=this._data)==null?void 0:d.analysis;if(!a)return;let t=$t[r],s=this.shadow.getElementById(`detail-${t}`),o=this.shadow.getElementById(`detail-${t}-inner`);if(!s||!o)return;let i=this.shadow.getElementById(`grid-${t}`);if(i==null||i.querySelectorAll(".cell").forEach(m=>m.classList.remove("selected")),this.t[t]===r){this.collapsePanel(s),this.t[t]=null;return}let c=this.t[t]!==null;this.t[t]=r;let l=i==null?void 0:i.querySelector(`[data-category="${r}"]`);l==null||l.classList.add("selected"),this.populateDetail(o,r,a),c?requestAnimationFrame(()=>{let m=o.querySelector(".detail-chart-area");if(m){let u=this.plotCategory(r,!1);u&&m.replaceChildren(u)}}):this.expandPanel(s,()=>{let m=o.querySelector(".detail-chart-area");if(m){let u=this.plotCategory(r,!1);u&&m.replaceChildren(u)}})}populateDetail(r,a,t){let s=this.getIndicatorCode(t,a),i=M(s)==="flag",c='<div class="detail-head">';c+=`<span class="detail-name">${v(I[a]??a)}</span>`,c+=`<span class="detail-code">${v(s??"")}</span>`,c+=`<span class="detail-status-label ${i?"flagged":"clear"}">${i?"flagged":"clear"}</span>`,c+="</div>";let l=at(a,t);c+=`<p class="detail-summary">${st(l)}</p>`,c+='<div class="detail-chart-area"></div>';let d=me[a];c+=`<div class="detail-chart-caption">${v(d.name)} \u2014 ${v(d.desc)}</div>`;let m=nt(a,t);c+='<div class="detail-metrics">';for(let p of m)c+=`<div class="detail-metric"><span class="detail-metric-value">${v(p.value)}</span><span class="detail-metric-label">${v(p.label)}</span></div>`;c+="</div>";let u=pt(a);u&&(c+=`<p class="detail-explainer">${st(u)}</p>`),r.innerHTML=c}closeDetail(r){let a=this.shadow.getElementById(`detail-${r}`);if(!a)return;let t=this.shadow.getElementById(`grid-${r}`);t==null||t.querySelectorAll(".cell").forEach(s=>s.classList.remove("selected")),this.collapsePanel(a),this.t[r]=null}expandPanel(r,a){let t=r.querySelector(".detail-inner");r.style.height="0px",r.style.display="block",r.offsetHeight,r.style.height=`${t.offsetHeight+40}px`;let s=()=>{r.style.height="auto",a==null||a()};r.addEventListener("transitionend",s,{once:!0})}collapsePanel(r){r.style.height=`${r.scrollHeight}px`,r.offsetHeight,r.style.height="0px";let a=()=>{r.style.display=""};r.addEventListener("transitionend",a,{once:!0})}getIndicatorCode(r,a){var s;let t=r[a];return(s=t==null?void 0:t.indicator)==null?void 0:s.code}getComputedColors(){let r=getComputedStyle(this);return{line:r.getPropertyValue("--wt-scorecard-chart-line").trim()||"#1C1B18",accent:r.getPropertyValue("--wt-scorecard-chart-accent").trim()||"#2B7A5D",flagged:r.getPropertyValue("--wt-scorecard-chart-flagged").trim()||"#B8412D",border:r.getPropertyValue("--wt-scorecard-border").trim()||"#E0DED6",tertiary:r.getPropertyValue("--wt-scorecard-text-tertiary").trim()||"#706E64"}}getChartWidth(r,a){var s;let t=a?`[data-category="${r}"] .cell-chart`:`#detail-${$t[r]}-inner .detail-chart-area`;return((s=this.shadow.querySelector(t))==null?void 0:s.getBoundingClientRect().width)??300}plotOpts(r,a,t,s,o){return{width:r,height:a?52:200,marginTop:a?4:36,marginRight:a?0:16,marginBottom:a?4:44,marginLeft:a?0:55,x:a?{axis:null,...s}:{...s},y:a?{axis:null,...o}:{...o},style:{background:"transparent",color:t.tertiary,fontFamily:"var(--wt-scorecard-font-data)",fontSize:"10px"}}}plotCategory(r,a){var d;if(!((d=this._data)!=null&&d.analysis))return null;let{data:t,analysis:s}=this._data,o=this.getComputedColors(),i=this.getIndicatorCode(s,r),l=M(i)==="flag"?o.flagged:o.accent;switch(r){case"contentOrigin":return this.plotContentOrigin(s,a,o);case"timingAuthenticity":return this.plotTimingAuthenticity(s,a,o,l);case"revisionBehavior":return this.plotRevisionBehavior(t,a,o);case"sessionContinuity":return this.plotSessionContinuity(t,s,a,o,l);case"physicalPlausibility":return this.plotPhysicalPlausibility(t,a,o);case"temporalPatterns":return this.plotTemporalPatterns(s,a,o,l)}}renderAllCharts(){this.shadow.querySelectorAll(".cell-chart").forEach(r=>{let a=r.closest(".cell"),t=a==null?void 0:a.getAttribute("data-category");if(!t)return;let s=this.plotCategory(t,!0);s&&r.replaceChildren(s)})}rerenderAllCharts(){this.renderAllCharts();for(let r of[1,2]){let a=this.t[r];if(a){let t=this.shadow.querySelector(`#detail-${r}-inner .detail-chart-area`);if(t){let s=this.plotCategory(a,!1);s&&t.replaceChildren(s)}}}}plotContentOrigin(r,a,t){let s=H(r);if(s.length===0)return null;let o={typing:t.accent,paste:t.flagged,pause:t.border,tabAway:t.tertiary,autocomplete:t.flagged,navigating:t.line},i=s.map(d=>({...d,color:o[d.type]??t.line})),c=this.getChartWidth("contentOrigin",a),l=this.plotOpts(c,a,t,{label:"Time (s)"},{padding:.2});return f.plot({...l,marginLeft:a?0:8,y:{axis:null,padding:.2},marks:[f.barX(i,{x1:"start",x2:"end",fill:"color",y:()=>"Activity",inset:.5})]})}plotTimingAuthenticity(r,a,t,s){let o=Y(r);if(o.length===0)return null;let i=this.getChartWidth("timingAuthenticity",a),c=[f.dot(o,{x:"dwell",y:"flight",fill:s,fillOpacity:a?.4:.5,r:a?2:3,stroke:"none"})];if(!a){let l=o.reduce((m,u)=>m+u.dwell,0)/o.length,d=o.reduce((m,u)=>m+u.flight,0)/o.length;c.push(f.ruleX([l],{stroke:t.accent,strokeDasharray:"4,4",strokeWidth:1}),f.ruleY([d],{stroke:t.accent,strokeDasharray:"4,4",strokeWidth:1}))}return f.plot({...this.plotOpts(i,a,t,{label:"Dwell (ms)"},{label:"Flight (ms)"}),marginRight:a?4:12,marks:c})}plotRevisionBehavior(r,a,t){let s=et(r);if(s.length===0)return null;let o={insert:t.accent,delete:t.flagged,paste:t.line,cut:t.tertiary},i=s.map(l=>({...l,color:o[l.type]??t.line})),c=this.getChartWidth("revisionBehavior",a);return a?f.plot({...this.plotOpts(c,a,t),marks:[f.dot(i,{x:"time",y:()=>0,fill:"color",fillOpacity:.6,r:Math.min(3,Math.max(2,c/i.length/4)),stroke:"none"})],style:{background:"transparent"}}):f.plot({...this.plotOpts(c,a,t,{label:"Time (s)"},{label:null,domain:["insert","delete","paste","cut"]}),marginLeft:70,r:{range:[3,12]},marks:[f.dot(i,{x:"time",y:"type",r:"chars",fill:"color",fillOpacity:.7,stroke:"none"})]})}plotSessionContinuity(r,a,t,s,o){var m,u;let i=Q(r);if(i.length===0)return null;let c=this.getChartWidth("sessionContinuity",t),l=[f.areaY(i,{x:"time",y:"chars",fill:o,fillOpacity:.1,curve:"step-after"}),f.lineY(i,{x:"time",y:"chars",stroke:o,strokeWidth:1.5,curve:"step-after"})],d=((u=(m=a.sessionContinuity)==null?void 0:m.metrics)==null?void 0:u.changePoints)??[];if(d.length>0){let p=d[0].timestamp/1e3;l.push(f.ruleX([p],{stroke:s.flagged,strokeDasharray:"4,3",strokeWidth:1}))}if(!t){let p=i.filter(h=>h.isPaste),y=i.filter(h=>h.isCut);p.length>0&&l.push(f.dot(p,{x:"time",y:"chars",fill:s.accent,r:4,stroke:"none"})),y.length>0&&l.push(f.dot(y,{x:"time",y:"chars",fill:s.flagged,r:4,symbol:"diamond",stroke:"none"}))}return f.plot({...this.plotOpts(c,t,s,{label:"Time (s)"},{label:"Characters",grid:!0}),marks:l})}plotPhysicalPlausibility(r,a,t){let s=Z(r);if(s.keystrokes.length===0)return null;let o=this.getChartWidth("physicalPlausibility",a),i=[f.line(s.keystrokes,{x:"time",y:"position",stroke:t.line,strokeWidth:a?1:1.5,strokeOpacity:a?.6:.8})];return a||(s.pastes.length>0&&i.push(f.dot(s.pastes,{x:"time",y:"position",fill:t.accent,r:4,stroke:"none"})),s.cuts.length>0&&i.push(f.dot(s.cuts,{x:"time",y:"position",fill:t.flagged,r:4,stroke:"none"}))),f.plot({...this.plotOpts(o,a,t,{label:"Time (s)"},{label:"Position",reverse:!0}),marks:i})}plotTemporalPatterns(r,a,t,s){let o=F(r);if(o.length===0)return null;let i=this.getChartWidth("temporalPatterns",a);return f.plot({...this.plotOpts(i,a,t,{label:"Time (s)"},{label:"Speed (CPM)",grid:!0}),marks:[f.areaY(o,{x:"time",y:"speed",fill:s,fillOpacity:.12,curve:"natural"}),f.lineY(o,{x:"time",y:"speed",stroke:s,strokeWidth:1.5,curve:"natural"})]})}};it.tagName="wt-scorecard";export{g as BaseChart,I as CATEGORY_NAMES,G as CompositionTimeline,tt as CorrectionsBubble,U as DocumentGrowth,X as DocumentRibbon,J as EditWaterfall,Mt as GLOSSARY,D as IntegrityFooter,q as PauseDistribution,V as RhythmHeatmap,ct as SEGMENT_COLORS,lt as Sparkline,z as SpeedTimeline,mt as TIER1_CATEGORIES,ut as TIER2_CATEGORIES,it as WtScorecard,et as extractCorrectionBubbles,Q as extractGrowthData,yt as extractPasteMarkers,bt as extractPauseHistogram,Y as extractRhythmPairs,wt as extractRibbonData,H as extractSegments,gt as extractSeries,F as extractSpeedData,Z as extractWaterfallData,ot as formatDuration,pt as generateCaption,at as generateSummary,nt as getMetrics,M as getStatus,Jt as isPass,st as wrapTerms};
358
+ `,lt=class extends g{constructor(){super();this.t={1:null,2:null};O.register()}onResize(){this.rerenderAllCharts()}getStylesheet(){return N+`
359
+ `+Ee}attributeChangedCallback(e,n,r){if(e==="theme"&&this._data&&this.hasRendered){let o=this.shadow.querySelector(".theme-toggle");o&&(o.textContent=r==="dark"?"Light":"Dark");let i=this.shadow.querySelector("wt-integrity-footer");i&&r&&i.setAttribute("theme",r),requestAnimationFrame(()=>this.rerenderAllCharts());return}super.attributeChangedCallback(e,n,r)}render(){var m;if(!((m=this._data)!=null&&m.analysis))return;let{data:e,analysis:n}=this._data;this.t={1:null,2:null};let r=document.createElement("div");r.className="page",r.appendChild(this.buildHeader(n,e.metadata.sessionId??"")),r.appendChild(this.buildSummary(n)),r.appendChild(this.buildTierLabel("Primary Evidence"));let o=this.buildGrid(1,n);r.appendChild(o);let i=this.buildDetailPanel(1);r.appendChild(i),r.appendChild(this.buildTierLabel("Supporting Context"));let s=this.buildGrid(2,n);r.appendChild(s);let l=this.buildDetailPanel(2);r.appendChild(l);let c=document.createElement("wt-integrity-footer"),d=this.getAttribute("theme");d&&c.setAttribute("theme",d),Pt(c),c.setData({integrity:n.integrity,outputSignature:n.outputSignature,sessionId:e.metadata.sessionId??""}),r.appendChild(c),this.replaceChart(r),requestAnimationFrame(()=>{this.renderAllCharts()})}buildHeader(e,n){let r=document.createElement("header");r.className="header";let o=document.createElement("div");o.className="header-meta";let i=document.createElement("span");i.textContent=`WriteTrack v${e.version}`;let s=document.createElement("span");s.className="sep",s.innerHTML="&middot;";let l=document.createElement("span"),c=new Date(e.analyzedAt);l.textContent=c.toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"});let d=document.createElement("span");d.className="sep",d.innerHTML="&middot;";let m=document.createElement("span");if(m.className="mono",m.textContent=n,o.append(i,s,l,d,m),this.hasAttribute("no-toggle"))r.append(o);else{let u=document.createElement("button");u.className="theme-toggle",u.textContent=this.getAttribute("theme")==="dark"?"Light":"Dark",u.addEventListener("click",()=>{let y=this.getAttribute("theme")==="dark"?"light":"dark";this.setAttribute("theme",y);try{localStorage.setItem("writetrack-v4-theme",y)}catch{}}),r.append(o,u)}return r}buildSummary(e){let n=document.createElement("section");n.className="summary";let r=document.createElement("div");r.className="summary-headline";let o=document.createElement("h1");o.textContent="Session Scorecard";let i=nt.filter(d=>$(this.getIndicatorCode(e,d))==="pass").length,s=document.createElement("span");s.className="tally",s.textContent=`${i} of ${nt.length} clear`,r.append(o,s),n.appendChild(r);let l=document.createElement("div");l.className="summary-stats";let c=it(e.temporalPatterns.metrics.sessionDurationMs);l.innerHTML=`<span>${v(c)} duration</span><span class="sep">&middot;</span><span>${e.keydownCount} keystrokes</span>`,n.appendChild(l);for(let d of nt)if($(this.getIndicatorCode(e,d))==="flag"){let m=document.createElement("div");m.className="summary-flag";let u=at(d,e);m.innerHTML=`<strong>Flagged</strong> ${v(F[d]??d)}\u2009\u2014\u2009${v(u)}`,n.appendChild(m)}return n}buildTierLabel(e){let n=document.createElement("div");return n.className="tier-label",n.textContent=e,n}buildGrid(e,n){let r=document.createElement("div");r.className="indicator-grid",r.id=`grid-${e}`;let o=e===1?pt:ht;for(let i of o)r.appendChild(this.buildCell(i,n));return r}buildCell(e,n){let r=this.getIndicatorCode(n,e),i=$(r)==="flag",s=document.createElement("div");s.className="cell"+(i?" flagged":""),s.setAttribute("data-category",e),s.addEventListener("click",()=>this.selectCell(e));let l=document.createElement("div");l.className="cell-header";let c=document.createElement("div");c.className="cell-name-col";let d=document.createElement("span");d.className="cell-name",d.textContent=F[e]??e,c.appendChild(d);let m=document.createElement("span");m.className=`cell-status ${i?"flagged":"clear"}`,m.textContent=i?"flagged":"clear",l.append(c,m),s.appendChild(l);let u=document.createElement("div");u.className="cell-chart",s.appendChild(u);let p=ot(e,n),y=Ce[e];if(e==="physicalPlausibility"&&!i)if(p.every(b=>b.value==="0"||b.value==="0%")){let b=document.createElement("div");b.className="cell-allclear",b.innerHTML='<span class="cell-allclear-dot"></span>No anomalies detected',s.appendChild(b)}else s.appendChild(this.buildCellMetrics(p,y));else s.appendChild(this.buildCellMetrics(p,y));let h=document.createElement("div");return h.className="cell-affordance",h.innerHTML='<span>Details</span><span class="cell-affordance-arrow">&#x25B8;</span>',s.appendChild(h),s}buildCellMetrics(e,n){let r=document.createElement("div");r.className="cell-metrics";for(let o of n){let i=e[o];if(!i)continue;let s=document.createElement("div");s.className="cell-metric",s.innerHTML=`<span class="cell-metric-label">${v(i.label)}</span><span class="cell-metric-value">${v(i.value)}</span>`,r.appendChild(s)}return r}buildDetailPanel(e){let n=document.createElement("div");n.className="detail-panel",n.id=`detail-${e}`;let r=document.createElement("button");r.className="detail-close",r.setAttribute("aria-label","Close detail"),r.innerHTML="&times; Close",r.addEventListener("click",i=>{i.stopPropagation(),this.closeDetail(e)}),n.appendChild(r);let o=document.createElement("div");return o.className="detail-inner",o.id=`detail-${e}-inner`,n.appendChild(o),n}selectCell(e){var d;let n=(d=this._data)==null?void 0:d.analysis;if(!n)return;let r=_t[e],o=this.shadow.getElementById(`detail-${r}`),i=this.shadow.getElementById(`detail-${r}-inner`);if(!o||!i)return;let s=this.shadow.getElementById(`grid-${r}`);if(s==null||s.querySelectorAll(".cell").forEach(m=>m.classList.remove("selected")),this.t[r]===e){this.collapsePanel(o),this.t[r]=null;return}let l=this.t[r]!==null;this.t[r]=e;let c=s==null?void 0:s.querySelector(`[data-category="${e}"]`);c==null||c.classList.add("selected"),this.populateDetail(i,e,n),l?requestAnimationFrame(()=>{let m=i.querySelector(".detail-chart-area");if(m){let u=this.plotCategory(e,!1);u&&m.replaceChildren(u)}}):this.expandPanel(o,()=>{let m=i.querySelector(".detail-chart-area");if(m){let u=this.plotCategory(e,!1);u&&m.replaceChildren(u)}})}populateDetail(e,n,r){let o=this.getIndicatorCode(r,n),s=$(o)==="flag",l='<div class="detail-head">';l+=`<span class="detail-name">${v(F[n]??n)}</span>`,l+=`<span class="detail-code">${v(o??"")}</span>`,l+=`<span class="detail-status-label ${s?"flagged":"clear"}">${s?"flagged":"clear"}</span>`,l+="</div>";let c=at(n,r);l+=`<p class="detail-summary">${st(c)}</p>`,l+='<div class="detail-chart-area"></div>';let d=Te[n];l+=`<div class="detail-chart-caption">${v(d.name)} \u2014 ${v(d.desc)}</div>`;let m=ot(n,r);l+='<div class="detail-metrics">';for(let p of m)l+=`<div class="detail-metric"><span class="detail-metric-value">${v(p.value)}</span><span class="detail-metric-label">${v(p.label)}</span></div>`;l+="</div>";let u=ft(n);u&&(l+=`<p class="detail-explainer">${st(u)}</p>`),e.innerHTML=l}closeDetail(e){let n=this.shadow.getElementById(`detail-${e}`);if(!n)return;let r=this.shadow.getElementById(`grid-${e}`);r==null||r.querySelectorAll(".cell").forEach(o=>o.classList.remove("selected")),this.collapsePanel(n),this.t[e]=null}expandPanel(e,n){let r=e.querySelector(".detail-inner");e.style.height="0px",e.style.display="block",e.offsetHeight,e.style.height=`${r.offsetHeight+40}px`;let o=()=>{e.style.height="auto",n==null||n()};e.addEventListener("transitionend",o,{once:!0})}collapsePanel(e){e.style.height=`${e.scrollHeight}px`,e.offsetHeight,e.style.height="0px";let n=()=>{e.style.display=""};e.addEventListener("transitionend",n,{once:!0})}getIndicatorCode(e,n){var o;let r=e[n];return(o=r==null?void 0:r.indicator)==null?void 0:o.code}getComputedColors(){let e=getComputedStyle(this);return{line:e.getPropertyValue("--wt-scorecard-chart-line").trim()||"#1C1B18",accent:e.getPropertyValue("--wt-scorecard-chart-accent").trim()||"#2B7A5D",flagged:e.getPropertyValue("--wt-scorecard-chart-flagged").trim()||"#B8412D",border:e.getPropertyValue("--wt-scorecard-border").trim()||"#E0DED6",tertiary:e.getPropertyValue("--wt-scorecard-text-tertiary").trim()||"#706E64"}}getChartWidth(e,n){var o;let r=n?`[data-category="${e}"] .cell-chart`:`#detail-${_t[e]}-inner .detail-chart-area`;return((o=this.shadow.querySelector(r))==null?void 0:o.getBoundingClientRect().width)??300}plotOpts(e,n,r,o,i){return{width:e,height:n?52:200,marginTop:n?4:36,marginRight:n?0:16,marginBottom:n?4:44,marginLeft:n?0:55,x:n?{axis:null,...o}:{...o},y:n?{axis:null,...i}:{...i},style:{background:"transparent",color:r.tertiary,fontFamily:"var(--wt-scorecard-font-data)",fontSize:"10px"}}}plotCategory(e,n){var d;if(!((d=this._data)!=null&&d.analysis))return null;let{data:r,analysis:o}=this._data,i=this.getComputedColors(),s=this.getIndicatorCode(o,e),c=$(s)==="flag"?i.flagged:i.accent;switch(e){case"contentOrigin":return this.plotContentOrigin(o,n,i);case"timingAuthenticity":return this.plotTimingAuthenticity(o,n,i,c);case"revisionBehavior":return this.plotRevisionBehavior(r,n,i);case"sessionContinuity":return this.plotSessionContinuity(r,o,n,i,c);case"physicalPlausibility":return this.plotPhysicalPlausibility(r,n,i);case"temporalPatterns":return this.plotTemporalPatterns(o,n,i,c)}}renderAllCharts(){this.shadow.querySelectorAll(".cell-chart").forEach(e=>{let n=e.closest(".cell"),r=n==null?void 0:n.getAttribute("data-category");if(!r)return;let o=this.plotCategory(r,!0);o&&e.replaceChildren(o)})}rerenderAllCharts(){this.renderAllCharts();for(let e of[1,2]){let n=this.t[e];if(n){let r=this.shadow.querySelector(`#detail-${e}-inner .detail-chart-area`);if(r){let o=this.plotCategory(n,!1);o&&r.replaceChildren(o)}}}}plotContentOrigin(e,n,r){let o=V(e);if(o.length===0)return null;let i={typing:r.accent,paste:r.flagged,pause:r.border,tabAway:r.tertiary,autocomplete:r.flagged,navigating:r.line},s=o.map(d=>({...d,color:i[d.type]??r.line})),l=this.getChartWidth("contentOrigin",n),c=this.plotOpts(l,n,r,{label:"Time (s)"},{padding:.2});return f.plot({...c,marginLeft:n?0:8,y:{axis:null,padding:.2},marks:[f.barX(s,{x1:"start",x2:"end",fill:"color",y:()=>"Activity",inset:.5})]})}plotTimingAuthenticity(e,n,r,o){let i=Y(e);if(i.length===0)return null;let s=this.getChartWidth("timingAuthenticity",n),l=[f.dot(i,{x:"dwell",y:"flight",fill:o,fillOpacity:n?.4:.5,r:n?2:3,stroke:"none"})];if(!n){let c=i.reduce((m,u)=>m+u.dwell,0)/i.length,d=i.reduce((m,u)=>m+u.flight,0)/i.length;l.push(f.ruleX([c],{stroke:r.accent,strokeDasharray:"4,4",strokeWidth:1}),f.ruleY([d],{stroke:r.accent,strokeDasharray:"4,4",strokeWidth:1}))}return f.plot({...this.plotOpts(s,n,r,{label:"Dwell (ms)"},{label:"Flight (ms)"}),marginRight:n?4:12,marks:l})}plotRevisionBehavior(e,n,r){let o=rt(e);if(o.length===0)return null;let i={insert:r.accent,delete:r.flagged,paste:r.line,cut:r.tertiary},s=o.map(c=>({...c,color:i[c.type]??r.line})),l=this.getChartWidth("revisionBehavior",n);return n?f.plot({...this.plotOpts(l,n,r),marks:[f.dot(s,{x:"time",y:()=>0,fill:"color",fillOpacity:.6,r:Math.min(3,Math.max(2,l/s.length/4)),stroke:"none"})],style:{background:"transparent"}}):f.plot({...this.plotOpts(l,n,r,{label:"Time (s)"},{label:null,domain:["insert","delete","paste","cut"]}),marginLeft:70,r:{range:[3,12]},marks:[f.dot(s,{x:"time",y:"type",r:"chars",fill:"color",fillOpacity:.7,stroke:"none"})]})}plotSessionContinuity(e,n,r,o,i){var m,u;let s=X(e);if(s.length===0)return null;let l=this.getChartWidth("sessionContinuity",r),c=[f.areaY(s,{x:"time",y:"chars",fill:i,fillOpacity:.1,curve:"step-after"}),f.lineY(s,{x:"time",y:"chars",stroke:i,strokeWidth:1.5,curve:"step-after"})],d=((u=(m=n.sessionContinuity)==null?void 0:m.metrics)==null?void 0:u.changePoints)??[];if(d.length>0){let p=d[0].timestamp/1e3;c.push(f.ruleX([p],{stroke:o.flagged,strokeDasharray:"4,3",strokeWidth:1}))}if(!r){let p=s.filter(h=>h.isPaste),y=s.filter(h=>h.isCut);p.length>0&&c.push(f.dot(p,{x:"time",y:"chars",fill:o.accent,r:4,stroke:"none"})),y.length>0&&c.push(f.dot(y,{x:"time",y:"chars",fill:o.flagged,r:4,symbol:"diamond",stroke:"none"}))}return f.plot({...this.plotOpts(l,r,o,{label:"Time (s)"},{label:"Characters",grid:!0}),marks:c})}plotPhysicalPlausibility(e,n,r){let o=tt(e);if(o.keystrokes.length===0)return null;let i=this.getChartWidth("physicalPlausibility",n),s=[f.line(o.keystrokes,{x:"time",y:"position",stroke:r.line,strokeWidth:n?1:1.5,strokeOpacity:n?.6:.8})];return n||(o.pastes.length>0&&s.push(f.dot(o.pastes,{x:"time",y:"position",fill:r.accent,r:4,stroke:"none"})),o.cuts.length>0&&s.push(f.dot(o.cuts,{x:"time",y:"position",fill:r.flagged,r:4,stroke:"none"}))),f.plot({...this.plotOpts(i,n,r,{label:"Time (s)"},{label:"Position",reverse:!0}),marks:s})}plotTemporalPatterns(e,n,r,o){let i=G(e);if(i.length===0)return null;let s=this.getChartWidth("temporalPatterns",n);return f.plot({...this.plotOpts(s,n,r,{label:"Time (s)"},{label:"Speed (CPM)",grid:!0}),marks:[f.areaY(i,{x:"time",y:"speed",fill:o,fillOpacity:.12,curve:"monotone-x"}),f.lineY(i,{x:"time",y:"speed",stroke:o,strokeWidth:1.5,curve:"monotone-x"})]})}};lt.tagName="wt-scorecard";export{g as BaseChart,F as CATEGORY_NAMES,H as CompositionTimeline,et as CorrectionsBubble,Q as DocumentGrowth,J as DocumentRibbon,Z as EditWaterfall,Dt as GLOSSARY,O as IntegrityFooter,K as PauseDistribution,j as RhythmHeatmap,mt as SEGMENT_COLORS,dt as Sparkline,z as SpeedTimeline,pt as TIER1_CATEGORIES,ht as TIER2_CATEGORIES,lt as WtScorecard,rt as extractCorrectionBubbles,X as extractGrowthData,wt as extractPasteMarkers,vt as extractPauseHistogram,Y as extractRhythmPairs,xt as extractRibbonData,V as extractSegments,bt as extractSeries,G as extractSpeedData,tt as extractWaterfallData,it as formatDuration,ft as generateCaption,at as generateSummary,ot as getMetrics,$ as getStatus,ie as isPass,st as wrapTerms};
Binary file