diff --git a/PlotLine/Help/Articles/SceneInspector/Suggestions.md b/PlotLine/Help/Articles/SceneInspector/Suggestions.md new file mode 100644 index 0000000..c180a8f --- /dev/null +++ b/PlotLine/Help/Articles/SceneInspector/Suggestions.md @@ -0,0 +1,28 @@ +--- +title: Word Companion Suggestions +category: Scene Inspector +tags: scene inspector, word companion, suggestions, characters, assets, locations +contextKey: sceneInspector.suggestions +micro: Review suggested characters, assets and locations found by Word Companion. +quickTitle: Word Companion suggestions +quickSummary: Suggestions are proposed scene links from Word Companion that you can accept into the scene or reject when they are not useful. +screenshot: +--- + +# Overview + +Word Companion suggestions are proposed connections between the current scene and story records such as characters, assets and locations. + +Review each suggestion before accepting it. Accepting adds the suggested link to the scene. Rejecting clears the suggestion when it is not relevant or not useful. + +# How To Use It + +Use suggestions as a review queue, not as automatic truth. They are most helpful after drafting or importing text, when Word Companion has noticed names or places that may need to be connected to the scene. + +If a suggestion is correct, accept it so the Scene Inspector and Timeline can use that evidence. If it is a false match, reject it so it no longer distracts you. + +# Related Guides + +- [Characters](/Help/Article/sceneInspector.characters) +- [Assets](/Help/Article/sceneInspector.assets) +- [Locations](/Help/Article/sceneInspector.locations) diff --git a/PlotLine/Views/Shared/SceneInspectorV2/_SceneContinuityCard.cshtml b/PlotLine/Views/Shared/SceneInspectorV2/_SceneContinuityCard.cshtml index 2529a06..74d43c3 100644 --- a/PlotLine/Views/Shared/SceneInspectorV2/_SceneContinuityCard.cshtml +++ b/PlotLine/Views/Shared/SceneInspectorV2/_SceneContinuityCard.cshtml @@ -17,7 +17,10 @@
Continuity
-Focused editor
-Overview
-People
-Story
-World
-Writer
-Loading help...
';try{const e=await fetch(`/HelpDrawer/Article?key=${encodeURIComponent(r)}`,{headers:{"X-Requested-With":"XMLHttpRequest"}});n.innerHTML=e.ok?await e.text():'Help for this feature has not yet been written.
';const t=n.querySelector(".help-drawer-article h2")?.textContent?.trim();l&&t&&(l.textContent=t)}catch{n.innerHTML='Help for this feature has not yet been written.
'}};window.PlotLineHelpDrawer={isActive:()=>e.classList.contains("help-open"),open:e=>y(e)},g(localStorage.getItem(c)||"25%"),f(h(d)),v(h(u)),document.addEventListener("plotline:help-more",e=>{const t=e.detail?.key||e.target?.dataset?.helpKey||"";window.PlotLineHelpPopovers?.hideAll(),y(t)}),document.addEventListener("click",e=>{const t=e.target instanceof Element?e.target.closest("[data-help-open]"):null;t&&(e.preventDefault(),window.PlotLineHelpPopovers?.hideAll(),y(t.dataset.helpOpen||""))}),r?.addEventListener("click",()=>{e.classList.remove("help-open","help-collapsed"),f(!1)}),o?.addEventListener("click",()=>v(!e.classList.contains("help-collapsed"))),s?.addEventListener("click",()=>v(!1)),s?.addEventListener("keydown",e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),v(!1))}),i?.addEventListener("click",()=>f(!h(d))),a?.addEventListener("pointerdown",t=>{if(!e.classList.contains("help-open")||e.classList.contains("help-collapsed"))return;t.preventDefault(),document.body.classList.add("help-resizing"),a.setPointerCapture?.(t.pointerId);const n=t=>{const n=e.getBoundingClientRect(),a=(n.right-t.clientX)/n.width*100;g(a)},r=()=>{document.body.classList.remove("help-resizing"),document.removeEventListener("pointermove",n),document.removeEventListener("pointerup",r)};document.addEventListener("pointermove",n),document.addEventListener("pointerup",r)});const w=(()=>{try{return localStorage.getItem(p)||""}catch{return""}})();h(d)&&w&&y(w,{keepCollapsed:!0})})(),(()=>{const e=document.querySelectorAll("[data-metric-shape-chart]");if(!e.length)return;const t=["#2f6f63","#b35f3b","#6750a4","#c58b2b","#7d3f52","#33759b","#9c4d8f","#a33d3d","#6f8f3d","#d08a2f","#444b57"],n=new Set(["Overall Intensity","Tension","Emotional Weight","Action"]),a=[],r=e=>{const t=e.querySelector(".metric-chart-frame");if(!t)return;let n=Number(t.dataset.metricNaturalWidth||0);if(n&&"true"===t.dataset.metricCanvasConstrained||(t.style.width="",n=t.getBoundingClientRect().width,n&&(t.dataset.metricNaturalWidth=String(n))),!n)return;const a=Math.max(window.devicePixelRatio||1,1),r=Math.floor(3e4/a);n>r?(t.style.width=`${r}px`,t.dataset.metricCanvasConstrained="true"):(t.style.width="",t.dataset.metricCanvasConstrained="false")},o=()=>{window.requestAnimationFrame(()=>{a.forEach(({chart:e,root:t})=>{r(t),e.resize()})})};window.PlotLineMetricCharts={resizeAll:o},window.addEventListener("plotline:timeline-layout-changed",o);const s={id:"plotlineChapterGuides",afterDraw(e){const t=e.config.options.plugins.plotlineScenes||[],{ctx:n,chartArea:a,scales:r}=e;if(!t.length||!r.x)return;n.save(),n.strokeStyle="rgba(47, 111, 99, 0.16)",n.fillStyle="rgba(82, 75, 65, 0.58)",n.lineWidth=1,n.font="700 10px system-ui, -apple-system, Segoe UI, sans-serif";const o=[];t.forEach((e,n)=>{n&&e.chapterLabel===t[n-1].chapterLabel||o.push({scene:e,index:n})});const s=o.filter(e=>!e.scene.isPlaceholder),i=s.length>40?5:s.length>24?4:s.length>14?2:1;s.forEach((e,t)=>{const{scene:o,index:l}=e,c=r.x.getPixelForValue(l+.5);n.beginPath(),n.moveTo(c,a.top),n.lineTo(c,a.bottom),n.stroke();const d=Number.parseInt(String(o.chapterLabel).replace(/[^0-9]/g,""),10);(0===t||t===s.length-1||1===i||Number.isFinite(d)&&d%i===0)&&n.fillText(o.chapterLabel,Math.min(c+4,a.right-70),a.bottom+22)}),n.restore()}};window.Chart&&Chart.register(s),e.forEach(e=>{const o=e.querySelector("script[type='application/json']"),s=e.querySelector("canvas"),i=e.querySelector("[data-metric-toggles]"),l=e.querySelector("[data-chart-fallback]"),c=e.querySelector("[data-timeline-metric-edit-toolbar]"),d=e.querySelector("[data-edit-metric-status]"),p=e.hasAttribute("data-timeline-metric-editor")&&c&&d;if(!o||!s)return;let u;try{u=JSON.parse(o.textContent||"{}")}catch{return void l?.classList.remove("d-none")}if(!window.Chart||!u.scenes?.length||!u.metrics?.length)return void l?.classList.remove("d-none");const h=new Set(u.defaultMetrics?.length?u.defaultMetrics:n),m=u.scenes.length,g=m>80?10:m>40?5:m>24?4:m>14?2:1,f=u.metrics.map((e,n)=>{const a=new Map(e.points.map(e=>[e.sceneId,e.value])),r=t[n%t.length];return{label:e.metricName,metricTypeId:e.metricTypeId,minValue:Number.isFinite(e.minValue)?e.minValue:1,maxValue:Number.isFinite(e.maxValue)?e.maxValue:10,data:u.scenes.map((e,t)=>{const n=a.get(e.sceneId);return null==n?{x:t+.5,y:null,sceneId:e.sceneId}:{x:t+.5,y:n,sceneId:e.sceneId}}),borderColor:r,backgroundColor:r,pointBackgroundColor:r,pointBorderColor:"#fff",pointBorderWidth:1.5,pointRadius:3,pointHoverRadius:5,borderWidth:2,tension:.35,spanGaps:!0,hidden:!h.has(e.metricName)}});let v=null,y=!1;r(e);const w=e=>{d&&(d.textContent=e)},b=()=>f.map((e,t)=>t).filter(e=>E?.isDatasetVisible(e)),L=()=>{const e=b();return 1===e.length?e[0]:-1},S=()=>{if(!p)return;const e=L();f.forEach((t,n)=>{t.pointRadius=n===e?5:3,t.pointHoverRadius=n===e?7:5,t.borderWidth=n===e?3:2});const t=b(),n=e>=0;s.classList.toggle("metric-curve-editing",n),d.classList.toggle("d-none",0===t.length),0===t.length?w(""):w(n?"Drag points up or down to edit this metric.":"Show only one metric line to edit its curve."),E?.update()};i.innerHTML="",f.forEach((e,t)=>{const n=`metric-toggle-${Math.random().toString(36).slice(2)}-${t}`,a=document.createElement("label");a.className="metric-toggle-pill",a.style.setProperty("--metric-colour",e.borderColor),a.innerHTML=`${e.label}`,i.appendChild(a),a.querySelector("input").addEventListener("change",e=>{E.setDatasetVisibility(t,e.target.checked),S(),E.update()})});const E=new Chart(s,{type:"line",data:{datasets:f},options:{responsive:!0,maintainAspectRatio:!1,interaction:{mode:"nearest",intersect:!1},scales:{y:{min:1,max:10,ticks:{stepSize:1},grid:{color:"rgba(82, 75, 65, 0.10)"}},x:{type:"linear",min:0,max:m,bounds:"ticks",ticks:{maxRotation:0,autoSkip:!1,maxTicksLimit:16,callback(e){const t=Math.floor(Number(e));if(t<0||t>=m)return"";const n=u.scenes[t];return 0!==t&&t!==m-1&&t%g!==0||n?.isPlaceholder?"":n?.axisLabel||""}},afterBuildTicks(e){e.ticks=u.scenes.map((e,t)=>({value:t+.5}))},grid:{display:!1}}},plugins:{legend:{display:!1},plotlineScenes:u.scenes,tooltip:{callbacks:{title(e){const t=Math.floor(e[0].parsed.x),n=u.scenes[t];return n.isPlaceholder?n.sceneTitle||"No scene":`${n.chapterLabel}, Scene ${n.sceneNumber}: ${n.sceneTitle}`},label:e=>`${e.dataset.label}: ${e.formattedValue}`,afterBody(e){const t=Math.floor(e[0].parsed.x),n=u.scenes[t],a=[];return n.characterPresence?a.push(n.characterPresence):void 0!==n.characterAppears&&a.push(n.characterAppears?"Character appears":"Character does not appear"),n.bookTitle&&a.push(n.bookTitle),a}}}}}});p&&(S(),s.addEventListener("pointerdown",e=>{v=(e=>{if(!p)return null;const t=L();if(t<0)return null;const n=E.getElementsAtEventForMode(e,"nearest",{intersect:!0},!0).find(e=>e.datasetIndex===t);if(!n)return null;const a=E.data.datasets[n.datasetIndex],r=a?.data?.[n.index];return r?.sceneId&&null!=r.y?{datasetIndex:n.datasetIndex,pointIndex:n.index,previousValue:r.y}:null})(e),v&&(e.preventDefault(),s.setPointerCapture?.(e.pointerId),y=!0)}),s.addEventListener("pointermove",e=>{if(!v)return;const t=E.data.datasets[v.datasetIndex],n=t?.data?.[v.pointIndex];t&&n&&(n.y=((e,t)=>{const n=E.scales.y.getValueForPixel(e.offsetY),a=Math.round(n);return Math.max(t.minValue,Math.min(t.maxValue,a))})(e,t),E.update("none"))}),s.addEventListener("pointerup",async t=>{if(!v)return;const n=v;v=null,s.releasePointerCapture?.(t.pointerId),await(async t=>{const n=E.data.datasets[t.datasetIndex],a=n?.data?.[t.pointIndex];if(!n||!a?.sceneId)return;const r=c?.querySelector("input[name='__RequestVerificationToken']")?.value||"";w("Saving...");try{const t=await fetch(e.dataset.updateUrl||"/SceneMetrics/UpdateSceneMetricValue",{method:"POST",headers:{"Content-Type":"application/json",RequestVerificationToken:r},body:JSON.stringify({sceneId:Number(a.sceneId),metricId:Number(n.metricTypeId),value:Number(a.y)})}),o=await t.json().catch(()=>({}));if(!t.ok||!o.success)throw new Error(o.message||"Save failed");a.y=o.value,w("Saved"),E.update()}catch{a.y=t.previousValue,w("Save failed"),E.update()}})(n),window.setTimeout(()=>{y=!1},0)}),s.addEventListener("pointercancel",e=>{if(!v)return;const t=E.data.datasets[v.datasetIndex],n=t?.data?.[v.pointIndex];n&&(n.y=v.previousValue),v=null,s.releasePointerCapture?.(e.pointerId),y=!1,E.update()})),s.addEventListener("click",e=>{if(y)return void e.preventDefault();const t=E.getElementsAtEventForMode(e,"nearest",{intersect:!0},!0);if(!t.length)return;const n=E.data.datasets[t[0].datasetIndex]?.data?.[t[0].index],a=n?Math.floor(n.x):t[0].index,r=u.scenes[a];r?.timelineUrl&&(window.PlotLineTimelineScroll?.save(),window.location.href=r.timelineUrl)}),a.push({chart:E,root:e});const x=window.ResizeObserver?new ResizeObserver(()=>{r(e),E.resize()}):null;x&&(x.observe(e),x.observe(e.querySelector(".metric-chart-frame")||e))})})(),(()=>{const e=document.querySelector("[data-timeline-root]"),t=document.querySelector("[data-timeline-controls]");if(!e||!t)return;const n="plotline.timeline.visibility",a={"scene-cards":!0,"plot-lines":!0,assets:!0,characters:!0,locations:!0,warnings:!0,metrics:!0},r=t=>{Object.entries(t).forEach(([t,n])=>{e.classList.toggle(`hide-${t}`,!n),document.querySelectorAll(`[data-timeline-section='${t}']`).forEach(e=>{e.classList.toggle("timeline-section-hidden",!n)})}),document.querySelectorAll("[data-location-marker]").forEach(e=>{e.classList.toggle("timeline-section-hidden",!t.locations)}),document.querySelectorAll("[data-warning-marker]").forEach(e=>{e.classList.toggle("timeline-section-hidden",!t.warnings)}),document.querySelector("[data-visibility-json]")?.setAttribute("value",JSON.stringify(t))},o=(()=>{try{return{...a,...JSON.parse(localStorage.getItem(n)||"{}")}}catch{return{...a}}})();t.querySelectorAll("[data-timeline-toggle]").forEach(e=>{const t=e.dataset.timelineToggle;e.checked=o[t]??!0,e.addEventListener("change",()=>{o[t]=e.checked,localStorage.setItem(n,JSON.stringify(o)),r(o)})}),t.querySelector("[data-timeline-preset-form]")?.addEventListener("submit",()=>{document.querySelector("[data-visibility-json]")?.setAttribute("value",JSON.stringify(o))}),r(o)})(),(()=>{const e=document.querySelector("[data-timeline-root]");if(!e)return;const t=e.querySelector(".timeline-workspace")||e,n=document.querySelector("[data-timeline-density]"),a=document.querySelector("[data-timeline-zoom]"),r=document.querySelector("[data-timeline-search]"),o=e.querySelector("[data-timeline-minimap]"),s=document.querySelectorAll("[data-timeline-jump], [data-timeline-warning-jump], [data-timeline-entity-jump]"),i=[...e.querySelectorAll(".timeline-scene-card[data-scene-id]")],l="plotline.timeline.collapsed",c="plotline.timeline.density",d="plotline.timeline.zoom",p="plotline.timeline.pending-scroll",u="plotdirector.timelineNavigationDiscovered",h="plotline.timeline.inspectorWidth",m=[".timeline-shell",".plot-lane-board",".asset-lane-board",".character-lane-board",".metric-graph-stack","[data-timeline-minimap]"].join(","),g=["compact","comfortable","expanded"],f=["book","chapter","scene-detail","scene-overview"],v=e.querySelector("[data-inspector-drawer]"),y=e.querySelector("[data-inspector-resizer]"),w=e.querySelector("[data-inspector-close]"),b=null!==localStorage.getItem(l),L=(e=>{try{return new Set(JSON.parse(localStorage.getItem(e)||"[]"))}catch{return new Set}})(l),S=()=>[...e.querySelectorAll(m)],E=t=>{if(!v)return;const{minimum:n,maximum:a,defaultWidth:r}=(()=>{const t=e.getBoundingClientRect().width||window.innerWidth,n=Math.min(420,Math.max(320,t-360)),a=Math.max(n,Math.min(.65*t,t-420));return{minimum:n,maximum:a,defaultWidth:Math.max(n,Math.min(a,.4*t))}})(),o=Math.max(n,Math.min(a,Number(t)||r));e.style.setProperty("--timeline-inspector-width",`${Math.round(o)}px`)};v&&(E(localStorage.getItem(h)),window.addEventListener("resize",()=>E(localStorage.getItem(h)))),(()=>{const r=e.querySelector("[data-timeline-navigation-card]");if(!r)return;const o=r.querySelector("[data-timeline-navigation-dismiss]"),s=r.querySelector("[data-timeline-navigation-demo]"),i=()=>e.querySelector(".timeline-shell"),l=e=>Boolean(e&&e.scrollWidth>e.clientWidth+8),c=e=>Math.max(0,e.scrollWidth-e.clientWidth),d=()=>[t,...S()].filter((e,t,n)=>e&&n.indexOf(e)===t);let p=!1,h=!1,m=!1,g=null;const f=new WeakMap,v=e=>f.set(e,e.scrollLeft),y=(e=!1)=>{if(window.clearTimeout(g),!e||window.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches||r.hidden)return r.classList.remove("is-dismissing"),void(r.hidden=!0);r.classList.add("is-dismissing"),g=window.setTimeout(()=>{r.hidden=!0,r.classList.remove("is-dismissing")},1300)},w=e=>{const t=l(e),n=c(e);e.classList.toggle("timeline-horizontal-overflow",t),e.classList.toggle("has-scroll-left",t&&e.scrollLeft>8),e.classList.toggle("has-scroll-right",t&&e.scrollLeftLoading help...
';try{const e=await fetch(`/HelpDrawer/Article?key=${encodeURIComponent(r)}`,{headers:{"X-Requested-With":"XMLHttpRequest"}});n.innerHTML=e.ok?await e.text():'Help for this feature has not yet been written.
';const t=n.querySelector(".help-drawer-article h2")?.textContent?.trim();l&&t&&(l.textContent=t)}catch{n.innerHTML='Help for this feature has not yet been written.
'}};window.PlotLineHelpDrawer={isActive:()=>e.classList.contains("help-open"),open:e=>y(e)},g(localStorage.getItem(c)||"25%"),f(h(d)),v(h(u)),document.addEventListener("plotline:help-more",e=>{const t=e.detail?.key||e.target?.dataset?.helpKey||"";window.PlotLineHelpPopovers?.hideAll(),y(t)}),document.addEventListener("click",e=>{const t=e.target instanceof Element?e.target.closest("[data-help-open]"):null;t&&(e.preventDefault(),window.PlotLineHelpPopovers?.hideAll(),y(t.dataset.helpOpen||""))}),r?.addEventListener("click",()=>{e.classList.remove("help-open","help-collapsed"),f(!1)}),o?.addEventListener("click",()=>v(!e.classList.contains("help-collapsed"))),s?.addEventListener("click",()=>v(!1)),s?.addEventListener("keydown",e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),v(!1))}),i?.addEventListener("click",()=>f(!h(d))),a?.addEventListener("pointerdown",t=>{if(!e.classList.contains("help-open")||e.classList.contains("help-collapsed"))return;t.preventDefault(),document.body.classList.add("help-resizing"),a.setPointerCapture?.(t.pointerId);const n=t=>{const n=e.getBoundingClientRect(),a=(n.right-t.clientX)/n.width*100;g(a)},r=()=>{document.body.classList.remove("help-resizing"),document.removeEventListener("pointermove",n),document.removeEventListener("pointerup",r)};document.addEventListener("pointermove",n),document.addEventListener("pointerup",r)});const w=(()=>{try{return localStorage.getItem(p)||""}catch{return""}})();h(d)&&w&&y(w,{keepCollapsed:!0})})(),(()=>{const e=document.querySelectorAll("[data-metric-shape-chart]");if(!e.length)return;const t=["#2f6f63","#b35f3b","#6750a4","#c58b2b","#7d3f52","#33759b","#9c4d8f","#a33d3d","#6f8f3d","#d08a2f","#444b57"],n=new Set(["Overall Intensity","Tension","Emotional Weight","Action"]),a=[],r=e=>{const t=e.querySelector(".metric-chart-frame");if(!t)return;let n=Number(t.dataset.metricNaturalWidth||0);if(n&&"true"===t.dataset.metricCanvasConstrained||(t.style.width="",n=t.getBoundingClientRect().width,n&&(t.dataset.metricNaturalWidth=String(n))),!n)return;const a=Math.max(window.devicePixelRatio||1,1),r=Math.floor(3e4/a);n>r?(t.style.width=`${r}px`,t.dataset.metricCanvasConstrained="true"):(t.style.width="",t.dataset.metricCanvasConstrained="false")},o=()=>{window.requestAnimationFrame(()=>{a.forEach(({chart:e,root:t})=>{r(t),e.resize()})})};window.PlotLineMetricCharts={resizeAll:o},window.addEventListener("plotline:timeline-layout-changed",o);const s={id:"plotlineChapterGuides",afterDraw(e){const t=e.config.options.plugins.plotlineScenes||[],{ctx:n,chartArea:a,scales:r}=e;if(!t.length||!r.x)return;n.save(),n.strokeStyle="rgba(47, 111, 99, 0.16)",n.fillStyle="rgba(82, 75, 65, 0.58)",n.lineWidth=1,n.font="700 10px system-ui, -apple-system, Segoe UI, sans-serif";const o=[];t.forEach((e,n)=>{n&&e.chapterLabel===t[n-1].chapterLabel||o.push({scene:e,index:n})});const s=o.filter(e=>!e.scene.isPlaceholder),i=s.length>40?5:s.length>24?4:s.length>14?2:1;s.forEach((e,t)=>{const{scene:o,index:l}=e,c=r.x.getPixelForValue(l+.5);n.beginPath(),n.moveTo(c,a.top),n.lineTo(c,a.bottom),n.stroke();const d=Number.parseInt(String(o.chapterLabel).replace(/[^0-9]/g,""),10);(0===t||t===s.length-1||1===i||Number.isFinite(d)&&d%i===0)&&n.fillText(o.chapterLabel,Math.min(c+4,a.right-70),a.bottom+22)}),n.restore()}};window.Chart&&Chart.register(s),e.forEach(e=>{const o=e.querySelector("script[type='application/json']"),s=e.querySelector("canvas"),i=e.querySelector("[data-metric-toggles]"),l=e.querySelector("[data-chart-fallback]"),c=e.querySelector("[data-timeline-metric-edit-toolbar]"),d=e.querySelector("[data-edit-metric-status]"),p=e.hasAttribute("data-timeline-metric-editor")&&c&&d;if(!o||!s)return;let u;try{u=JSON.parse(o.textContent||"{}")}catch{return void l?.classList.remove("d-none")}if(!window.Chart||!u.scenes?.length||!u.metrics?.length)return void l?.classList.remove("d-none");const h=new Set(u.defaultMetrics?.length?u.defaultMetrics:n),m=u.scenes.length,g=m>80?10:m>40?5:m>24?4:m>14?2:1,f=u.metrics.map((e,n)=>{const a=new Map(e.points.map(e=>[e.sceneId,e.value])),r=t[n%t.length];return{label:e.metricName,metricTypeId:e.metricTypeId,minValue:Number.isFinite(e.minValue)?e.minValue:1,maxValue:Number.isFinite(e.maxValue)?e.maxValue:10,data:u.scenes.map((e,t)=>{const n=a.get(e.sceneId);return null==n?{x:t+.5,y:null,sceneId:e.sceneId}:{x:t+.5,y:n,sceneId:e.sceneId}}),borderColor:r,backgroundColor:r,pointBackgroundColor:r,pointBorderColor:"#fff",pointBorderWidth:1.5,pointRadius:3,pointHoverRadius:5,borderWidth:2,tension:.35,spanGaps:!0,hidden:!h.has(e.metricName)}});let v=null,y=!1;r(e);const w=e=>{d&&(d.textContent=e)},b=()=>f.map((e,t)=>t).filter(e=>E?.isDatasetVisible(e)),L=()=>{const e=b();return 1===e.length?e[0]:-1},S=()=>{if(!p)return;const e=L();f.forEach((t,n)=>{t.pointRadius=n===e?5:3,t.pointHoverRadius=n===e?7:5,t.borderWidth=n===e?3:2});const t=b(),n=e>=0;s.classList.toggle("metric-curve-editing",n),d.classList.toggle("d-none",0===t.length),0===t.length?w(""):w(n?"Drag points up or down to edit this metric.":"Show only one metric line to edit its curve."),E?.update()};i.innerHTML="",f.forEach((e,t)=>{const n=`metric-toggle-${Math.random().toString(36).slice(2)}-${t}`,a=document.createElement("label");a.className="metric-toggle-pill",a.style.setProperty("--metric-colour",e.borderColor),a.innerHTML=`${e.label}`,i.appendChild(a),a.querySelector("input").addEventListener("change",e=>{E.setDatasetVisibility(t,e.target.checked),S(),E.update()})});const E=new Chart(s,{type:"line",data:{datasets:f},options:{responsive:!0,maintainAspectRatio:!1,interaction:{mode:"nearest",intersect:!1},scales:{y:{min:1,max:10,ticks:{stepSize:1},grid:{color:"rgba(82, 75, 65, 0.10)"}},x:{type:"linear",min:0,max:m,bounds:"ticks",ticks:{maxRotation:0,autoSkip:!1,maxTicksLimit:16,callback(e){const t=Math.floor(Number(e));if(t<0||t>=m)return"";const n=u.scenes[t];return 0!==t&&t!==m-1&&t%g!==0||n?.isPlaceholder?"":n?.axisLabel||""}},afterBuildTicks(e){e.ticks=u.scenes.map((e,t)=>({value:t+.5}))},grid:{display:!1}}},plugins:{legend:{display:!1},plotlineScenes:u.scenes,tooltip:{callbacks:{title(e){const t=Math.floor(e[0].parsed.x),n=u.scenes[t];return n.isPlaceholder?n.sceneTitle||"No scene":`${n.chapterLabel}, Scene ${n.sceneNumber}: ${n.sceneTitle}`},label:e=>`${e.dataset.label}: ${e.formattedValue}`,afterBody(e){const t=Math.floor(e[0].parsed.x),n=u.scenes[t],a=[];return n.characterPresence?a.push(n.characterPresence):void 0!==n.characterAppears&&a.push(n.characterAppears?"Character appears":"Character does not appear"),n.bookTitle&&a.push(n.bookTitle),a}}}}}});p&&(S(),s.addEventListener("pointerdown",e=>{v=(e=>{if(!p)return null;const t=L();if(t<0)return null;const n=E.getElementsAtEventForMode(e,"nearest",{intersect:!0},!0).find(e=>e.datasetIndex===t);if(!n)return null;const a=E.data.datasets[n.datasetIndex],r=a?.data?.[n.index];return r?.sceneId&&null!=r.y?{datasetIndex:n.datasetIndex,pointIndex:n.index,previousValue:r.y}:null})(e),v&&(e.preventDefault(),s.setPointerCapture?.(e.pointerId),y=!0)}),s.addEventListener("pointermove",e=>{if(!v)return;const t=E.data.datasets[v.datasetIndex],n=t?.data?.[v.pointIndex];t&&n&&(n.y=((e,t)=>{const n=E.scales.y.getValueForPixel(e.offsetY),a=Math.round(n);return Math.max(t.minValue,Math.min(t.maxValue,a))})(e,t),E.update("none"))}),s.addEventListener("pointerup",async t=>{if(!v)return;const n=v;v=null,s.releasePointerCapture?.(t.pointerId),await(async t=>{const n=E.data.datasets[t.datasetIndex],a=n?.data?.[t.pointIndex];if(!n||!a?.sceneId)return;const r=c?.querySelector("input[name='__RequestVerificationToken']")?.value||"";w("Saving...");try{const t=await fetch(e.dataset.updateUrl||"/SceneMetrics/UpdateSceneMetricValue",{method:"POST",headers:{"Content-Type":"application/json",RequestVerificationToken:r},body:JSON.stringify({sceneId:Number(a.sceneId),metricId:Number(n.metricTypeId),value:Number(a.y)})}),o=await t.json().catch(()=>({}));if(!t.ok||!o.success)throw new Error(o.message||"Save failed");a.y=o.value,w("Saved"),E.update()}catch{a.y=t.previousValue,w("Save failed"),E.update()}})(n),window.setTimeout(()=>{y=!1},0)}),s.addEventListener("pointercancel",e=>{if(!v)return;const t=E.data.datasets[v.datasetIndex],n=t?.data?.[v.pointIndex];n&&(n.y=v.previousValue),v=null,s.releasePointerCapture?.(e.pointerId),y=!1,E.update()})),s.addEventListener("click",e=>{if(y)return void e.preventDefault();const t=E.getElementsAtEventForMode(e,"nearest",{intersect:!0},!0);if(!t.length)return;const n=E.data.datasets[t[0].datasetIndex]?.data?.[t[0].index],a=n?Math.floor(n.x):t[0].index,r=u.scenes[a];r?.timelineUrl&&(window.PlotLineTimelineScroll?.save(),window.location.href=r.timelineUrl)}),a.push({chart:E,root:e});const x=window.ResizeObserver?new ResizeObserver(()=>{r(e),E.resize()}):null;x&&(x.observe(e),x.observe(e.querySelector(".metric-chart-frame")||e))})})(),(()=>{const e=document.querySelector("[data-timeline-root]"),t=document.querySelector("[data-timeline-controls]");if(!e||!t)return;const n="plotline.timeline.visibility",a={"scene-cards":!0,"plot-lines":!0,assets:!0,characters:!0,locations:!0,warnings:!0,metrics:!0},r=t=>{Object.entries(t).forEach(([t,n])=>{e.classList.toggle(`hide-${t}`,!n),document.querySelectorAll(`[data-timeline-section='${t}']`).forEach(e=>{e.classList.toggle("timeline-section-hidden",!n)})}),document.querySelectorAll("[data-location-marker]").forEach(e=>{e.classList.toggle("timeline-section-hidden",!t.locations)}),document.querySelectorAll("[data-warning-marker]").forEach(e=>{e.classList.toggle("timeline-section-hidden",!t.warnings)}),document.querySelector("[data-visibility-json]")?.setAttribute("value",JSON.stringify(t))},o=(()=>{try{return{...a,...JSON.parse(localStorage.getItem(n)||"{}")}}catch{return{...a}}})();t.querySelectorAll("[data-timeline-toggle]").forEach(e=>{const t=e.dataset.timelineToggle;e.checked=o[t]??!0,e.addEventListener("change",()=>{o[t]=e.checked,localStorage.setItem(n,JSON.stringify(o)),r(o)})}),t.querySelector("[data-timeline-preset-form]")?.addEventListener("submit",()=>{document.querySelector("[data-visibility-json]")?.setAttribute("value",JSON.stringify(o))}),r(o)})(),(()=>{const e=document.querySelector("[data-timeline-root]");if(!e)return;const t=e.querySelector(".timeline-workspace")||e,n=document.querySelector("[data-timeline-density]"),a=document.querySelector("[data-timeline-zoom]"),r=document.querySelector("[data-timeline-search]"),o=e.querySelector("[data-timeline-minimap]"),s=document.querySelectorAll("[data-timeline-jump], [data-timeline-warning-jump], [data-timeline-entity-jump]"),i=[...e.querySelectorAll(".timeline-scene-card[data-scene-id]")],l="plotline.timeline.collapsed",c="plotline.timeline.density",d="plotline.timeline.zoom",p="plotline.timeline.pending-scroll",u="plotdirector.timelineNavigationDiscovered",h="plotline.timeline.inspectorWidth",m=[".timeline-shell",".plot-lane-board",".asset-lane-board",".character-lane-board",".metric-graph-stack","[data-timeline-minimap]"].join(","),g=["compact","comfortable","expanded"],f=["book","chapter","scene-detail","scene-overview"],v=e.querySelector("[data-inspector-drawer]"),y=e.querySelector("[data-inspector-resizer]"),w=e.querySelector("[data-inspector-close]"),b=null!==localStorage.getItem(l),L=(e=>{try{return new Set(JSON.parse(localStorage.getItem(e)||"[]"))}catch{return new Set}})(l),S=()=>[...e.querySelectorAll(m)],E=t=>{if(!v)return;const{minimum:n,maximum:a,defaultWidth:r}=(()=>{const t=e.getBoundingClientRect().width||window.innerWidth,n=Math.min(420,Math.max(320,t-360)),a=Math.max(n,Math.min(.65*t,t-420));return{minimum:n,maximum:a,defaultWidth:Math.max(n,Math.min(a,.4*t))}})(),o=Math.max(n,Math.min(a,Number(t)||r));e.style.setProperty("--timeline-inspector-width",`${Math.round(o)}px`)};v&&(E(localStorage.getItem(h)),window.addEventListener("resize",()=>E(localStorage.getItem(h)))),(()=>{const r=e.querySelector("[data-timeline-navigation-card]");if(!r)return;const o=r.querySelector("[data-timeline-navigation-dismiss]"),s=r.querySelector("[data-timeline-navigation-demo]"),i=()=>e.querySelector(".timeline-shell"),l=e=>Boolean(e&&e.scrollWidth>e.clientWidth+8),c=e=>Math.max(0,e.scrollWidth-e.clientWidth),d=()=>[t,...S()].filter((e,t,n)=>e&&n.indexOf(e)===t);let p=!1,h=!1,m=!1,g=null;const f=new WeakMap,v=e=>f.set(e,e.scrollLeft),y=(e=!1)=>{if(window.clearTimeout(g),!e||window.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches||r.hidden)return r.classList.remove("is-dismissing"),void(r.hidden=!0);r.classList.add("is-dismissing"),g=window.setTimeout(()=>{r.hidden=!0,r.classList.remove("is-dismissing")},1300)},w=e=>{const t=l(e),n=c(e);e.classList.toggle("timeline-horizontal-overflow",t),e.classList.toggle("has-scroll-left",t&&e.scrollLeft>8),e.classList.toggle("has-scroll-right",t&&e.scrollLeft