@lincyaw/aegis-ui 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/ask/AskPanel.cjs +1 -1
- package/dist/agent/ask/AskPanel.cjs.map +1 -1
- package/dist/agent/ask/AskPanel.js +25 -25
- package/dist/agent/ask/AskPanel.js.map +1 -1
- package/dist/components/ui/Button.cjs.map +1 -1
- package/dist/components/ui/Button.d.ts +4 -2
- package/dist/components/ui/Button.js.map +1 -1
- package/dist/components/ui/CheckGrid.cjs +1 -1
- package/dist/components/ui/CheckGrid.cjs.map +1 -1
- package/dist/components/ui/CheckGrid.js +18 -17
- package/dist/components/ui/CheckGrid.js.map +1 -1
- package/dist/components/ui/CodeEditor.cjs +1 -1
- package/dist/components/ui/CodeEditor.cjs.map +1 -1
- package/dist/components/ui/CodeEditor.js +95 -87
- package/dist/components/ui/CodeEditor.js.map +1 -1
- package/dist/components/ui/CommandInvocationCard.cjs +1 -1
- package/dist/components/ui/CommandInvocationCard.cjs.map +1 -1
- package/dist/components/ui/CommandInvocationCard.js +10 -10
- package/dist/components/ui/CommandInvocationCard.js.map +1 -1
- package/dist/components/ui/DangerZone.cjs +1 -1
- package/dist/components/ui/DangerZone.cjs.map +1 -1
- package/dist/components/ui/DangerZone.js +12 -12
- package/dist/components/ui/DangerZone.js.map +1 -1
- package/dist/components/ui/DataList.cjs +1 -1
- package/dist/components/ui/DataList.cjs.map +1 -1
- package/dist/components/ui/DataList.js +4 -3
- package/dist/components/ui/DataList.js.map +1 -1
- package/dist/components/ui/DataTable.cjs +1 -1
- package/dist/components/ui/DataTable.cjs.map +1 -1
- package/dist/components/ui/DataTable.d.ts +2 -1
- package/dist/components/ui/DataTable.js +125 -108
- package/dist/components/ui/DataTable.js.map +1 -1
- package/dist/components/ui/DiffViewer.cjs +1 -1
- package/dist/components/ui/DiffViewer.cjs.map +1 -1
- package/dist/components/ui/DiffViewer.js +29 -25
- package/dist/components/ui/DiffViewer.js.map +1 -1
- package/dist/components/ui/DropdownMenu.cjs.map +1 -1
- package/dist/components/ui/DropdownMenu.d.ts +1 -0
- package/dist/components/ui/DropdownMenu.js.map +1 -1
- package/dist/components/ui/FileDropzone.cjs +1 -1
- package/dist/components/ui/FileDropzone.cjs.map +1 -1
- package/dist/components/ui/FileDropzone.js +12 -12
- package/dist/components/ui/FileDropzone.js.map +1 -1
- package/dist/components/ui/FilePreview.cjs +1 -1
- package/dist/components/ui/FilePreview.cjs.map +1 -1
- package/dist/components/ui/FilePreview.js +16 -13
- package/dist/components/ui/FilePreview.js.map +1 -1
- package/dist/components/ui/ParetoChart.cjs +1 -1
- package/dist/components/ui/ParetoChart.cjs.map +1 -1
- package/dist/components/ui/ParetoChart.js +247 -212
- package/dist/components/ui/ParetoChart.js.map +1 -1
- package/dist/components/ui/QueryAutocomplete.cjs +1 -1
- package/dist/components/ui/QueryAutocomplete.cjs.map +1 -1
- package/dist/components/ui/QueryAutocomplete.d.ts +4 -1
- package/dist/components/ui/QueryAutocomplete.js +136 -123
- package/dist/components/ui/QueryAutocomplete.js.map +1 -1
- package/dist/components/ui/RankBar.cjs +1 -1
- package/dist/components/ui/RankBar.cjs.map +1 -1
- package/dist/components/ui/RankBar.js +9 -9
- package/dist/components/ui/RankBar.js.map +1 -1
- package/dist/components/ui/ReplayStepStrip.cjs +1 -1
- package/dist/components/ui/ReplayStepStrip.cjs.map +1 -1
- package/dist/components/ui/ReplayStepStrip.d.ts +6 -3
- package/dist/components/ui/ReplayStepStrip.js +71 -61
- package/dist/components/ui/ReplayStepStrip.js.map +1 -1
- package/dist/components/ui/ServiceMap.cjs +1 -1
- package/dist/components/ui/ServiceMap.cjs.map +1 -1
- package/dist/components/ui/ServiceMap.d.ts +9 -1
- package/dist/components/ui/ServiceMap.js +333 -268
- package/dist/components/ui/ServiceMap.js.map +1 -1
- package/dist/components/ui/SparkLine.cjs +1 -1
- package/dist/components/ui/SparkLine.cjs.map +1 -1
- package/dist/components/ui/SparkLine.d.ts +5 -2
- package/dist/components/ui/SparkLine.js +33 -29
- package/dist/components/ui/SparkLine.js.map +1 -1
- package/dist/components/ui/TableOfContents.cjs +1 -1
- package/dist/components/ui/TableOfContents.cjs.map +1 -1
- package/dist/components/ui/TableOfContents.js +16 -19
- package/dist/components/ui/TableOfContents.js.map +1 -1
- package/dist/components/ui/Tabs.cjs +2 -2
- package/dist/components/ui/Tabs.cjs.map +1 -1
- package/dist/components/ui/Tabs.js +107 -87
- package/dist/components/ui/Tabs.js.map +1 -1
- package/dist/components/ui/TimeRangePicker.cjs +1 -1
- package/dist/components/ui/TimeRangePicker.cjs.map +1 -1
- package/dist/components/ui/TimeRangePicker.d.ts +12 -1
- package/dist/components/ui/TimeRangePicker.js +69 -63
- package/dist/components/ui/TimeRangePicker.js.map +1 -1
- package/dist/components/ui/Timeline.cjs.map +1 -1
- package/dist/components/ui/Timeline.d.ts +4 -4
- package/dist/components/ui/Timeline.js.map +1 -1
- package/dist/components/ui/TimelineChart.cjs +2 -2
- package/dist/components/ui/TimelineChart.cjs.map +1 -1
- package/dist/components/ui/TimelineChart.d.ts +1 -0
- package/dist/components/ui/TimelineChart.js +131 -137
- package/dist/components/ui/TimelineChart.js.map +1 -1
- package/dist/components/ui/TraceTree.cjs +1 -1
- package/dist/components/ui/TraceTree.cjs.map +1 -1
- package/dist/components/ui/TraceTree.d.ts +4 -0
- package/dist/components/ui/TraceTree.js +88 -87
- package/dist/components/ui/TraceTree.js.map +1 -1
- package/dist/components/ui/TrajectoryStep.cjs +2 -1
- package/dist/components/ui/TrajectoryStep.cjs.map +1 -1
- package/dist/components/ui/TrajectoryStep.js +64 -43
- package/dist/components/ui/TrajectoryStep.js.map +1 -1
- package/dist/components/ui/useColumnWidths.cjs +1 -1
- package/dist/components/ui/useColumnWidths.cjs.map +1 -1
- package/dist/components/ui/useColumnWidths.d.ts +6 -1
- package/dist/components/ui/useColumnWidths.js +139 -123
- package/dist/components/ui/useColumnWidths.js.map +1 -1
- package/dist/layouts/shell/AegisShell.cjs +1 -1
- package/dist/layouts/shell/AegisShell.cjs.map +1 -1
- package/dist/layouts/shell/AegisShell.js +33 -34
- package/dist/layouts/shell/AegisShell.js.map +1 -1
- package/dist/lib/breakAtSeparators.cjs +2 -0
- package/dist/lib/breakAtSeparators.cjs.map +1 -0
- package/dist/lib/breakAtSeparators.d.ts +6 -0
- package/dist/lib/breakAtSeparators.js +10 -0
- package/dist/lib/breakAtSeparators.js.map +1 -0
- package/dist/locale/strings.cjs +1 -1
- package/dist/locale/strings.cjs.map +1 -1
- package/dist/locale/strings.d.ts +6 -0
- package/dist/locale/strings.js +27 -19
- package/dist/locale/strings.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/theme/antdTheme.cjs +1 -1
- package/dist/theme/antdTheme.cjs.map +1 -1
- package/dist/theme/antdTheme.js +50 -29
- package/dist/theme/antdTheme.js.map +1 -1
- package/dist/transports/agentm/AgentmChannelProvider.cjs +1 -1
- package/dist/transports/agentm/AgentmChannelProvider.cjs.map +1 -1
- package/dist/transports/agentm/AgentmChannelProvider.js +66 -61
- package/dist/transports/agentm/AgentmChannelProvider.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileDropzone.js","sources":["../../../src/components/ui/FileDropzone.tsx"],"sourcesContent":["import type { CSSProperties, ReactNode } from 'react';\n\nimport { type Accept, useDropzone } from 'react-dropzone';\n\nimport { formatBytes } from '../../lib/format';\nimport { useStrings } from '../../locale';\nimport './FileDropzone.css';\nimport { filesFromEvent } from './dropFiles';\n\ninterface FileDropzoneProps {\n onDrop: (files: File[]) => void;\n /** Accept map per react-dropzone, e.g. `{ 'image/*': ['.png'] }`. */\n accept?: Accept;\n multiple?: boolean;\n disabled?: boolean;\n /** Reject files bigger than this many bytes (forwarded to react-dropzone). */\n maxSize?: number;\n /**\n * When true, the `<input>` gets `webkitdirectory` so the user can select\n * an entire folder. Files of a picked or dropped folder carry their path\n * inside it in `webkitRelativePath`.\n */\n directory?: boolean;\n /**\n * `'inline'` (default) — standard dashed-border dropzone block.\n * `'overlay'` — fixed/absolute fullscreen overlay with a dashed border and\n * centred hint; use inside a `position: relative` container.\n */\n variant?: 'inline' | 'overlay';\n /** Override the body text in the drop area. */\n hint?: ReactNode;\n className?: string;\n style?: CSSProperties;\n}\n\nexport function FileDropzone({\n onDrop,\n accept,\n multiple = true,\n disabled = false,\n maxSize,\n directory = false,\n variant = 'inline',\n hint,\n className,\n style,\n}: FileDropzoneProps) {\n const strings = useStrings();\n const { getRootProps, getInputProps, isDragActive, isDragReject } =\n useDropzone({\n onDrop,\n accept,\n multiple,\n disabled,\n maxSize,\n getFilesFromEvent: filesFromEvent,\n });\n\n const isOverlay = variant === 'overlay';\n\n const rootClass = [\n 'aegis-file-dropzone',\n isOverlay ? 'aegis-file-dropzone--overlay' : '',\n isDragActive ? 'aegis-file-dropzone--active' : '',\n isDragReject ? 'aegis-file-dropzone--reject' : '',\n disabled ? 'aegis-file-dropzone--disabled' : '',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const inputProps = getInputProps();\n\n return (\n <div\n className={\n isOverlay\n ? 'aegis-file-dropzone__root aegis-file-dropzone__root--overlay'\n : 'aegis-file-dropzone__root'\n }\n style={style}\n >\n <div {...getRootProps({ className: rootClass })}>\n <input\n {...inputProps}\n {...(directory ? { webkitdirectory: '', mozdirectory: '' } : {})}\n />\n <div className=\"aegis-file-dropzone__hint\">\n {hint ?? (\n <>\n <span className=\"aegis-file-dropzone__primary\">\n {isDragActive\n ? directory\n ? strings.dropzoneDropFolder\n : strings.dropzoneDropFiles\n : directory\n ? strings.dropzoneBrowseFolder\n : strings.dropzoneBrowseFiles}\n </span>\n {accept ? (\n <span className=\"aegis-file-dropzone__meta\">\n {Object.keys(accept).join(', ')}\n </span>\n ) : null}\n {maxSize !== undefined ? (\n <span className=\"aegis-file-dropzone__meta\">\n {strings.dropzoneMaxSize(formatBytes(maxSize))}\n </span>\n ) : null}\n </>\n )}\n </div>\n </div>\n </div>\n );\n}\n"],"names":["FileDropzone","onDrop","accept","multiple","disabled","maxSize","directory","variant","hint","className","style","strings","useStrings","getRootProps","getInputProps","isDragActive","isDragReject","useDropzone","filesFromEvent","isOverlay","rootClass","inputProps","jsx","jsxs","Fragment","formatBytes"],"mappings":";;;;;;AAmCO,SAASA,EAAa;AAAA,EAC3B,QAAAC;AAAA,EACA,QAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,UAAAC,IAAW;AAAA,EACX,SAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,SAAAC,IAAU;AAAA,EACV,MAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AACF,GAAsB;AACpB,QAAMC,IAAUC,EAAA,GACV,EAAE,cAAAC,GAAc,eAAAC,GAAe,cAAAC,GAAc,cAAAC,EAAA,IACjDC,EAAY;AAAA,IACV,QAAAhB;AAAA,IACA,QAAAC;AAAA,IACA,UAAAC;AAAA,IACA,UAAAC;AAAA,IACA,SAAAC;AAAA,IACA,mBAAmBa;AAAA,EAAA,CACpB,GAEGC,IAAYZ,MAAY,WAExBa,IAAY;AAAA,IAChB;AAAA,IACAD,IAAY,iCAAiC;AAAA,IAC7CJ,IAAe,gCAAgC;AAAA,IAC/CC,IAAe,gCAAgC;AAAA,IAC/CZ,IAAW,kCAAkC;AAAA,IAC7CK,KAAa;AAAA,EAAA,EAEZ,OAAO,OAAO,EACd,KAAK,GAAG,GAELY,IAAaP,EAAA;AAEnB,SACE,gBAAAQ;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WACEH,IACI,iEACA;AAAA,MAEN,OAAAT;AAAA,MAEA,UAAA,gBAAAa,EAAC,SAAK,GAAGV,EAAa,EAAE,WAAWO,GAAW,GAC5C,UAAA;AAAA,QAAA,gBAAAE;AAAA,UAAC;AAAA,UAAA;AAAA,YACE,GAAGD;AAAA,YACH,GAAIf,IAAY,EAAE,iBAAiB,IAAI,cAAc,GAAA,IAAO,CAAA;AAAA,UAAC;AAAA,QAAA;AAAA,QAEhE,gBAAAgB,EAAC,OAAA,EAAI,WAAU,6BACZ,eACC,gBAAAC,EAAAC,GAAA,EACE,UAAA;AAAA,UAAA,gBAAAF,EAAC,QAAA,EAAK,WAAU,gCACb,UAAAP,IACGT,IACEK,EAAQ,qBACRA,EAAQ,oBACVL,IACEK,EAAQ,uBACRA,EAAQ,qBAChB;AAAA,UACCT,IACC,gBAAAoB,EAAC,QAAA,EAAK,WAAU,6BACb,UAAA,OAAO,KAAKpB,CAAM,EAAE,KAAK,IAAI,EAAA,CAChC,IACE;AAAA,UACHG,MAAY,SACX,gBAAAiB,EAAC,QAAA,EAAK,WAAU,
|
|
1
|
+
{"version":3,"file":"FileDropzone.js","sources":["../../../src/components/ui/FileDropzone.tsx"],"sourcesContent":["import type { CSSProperties, ReactNode } from 'react';\n\nimport { type Accept, useDropzone } from 'react-dropzone';\n\nimport { formatBytes } from '../../lib/format';\nimport { useStrings } from '../../locale';\nimport './FileDropzone.css';\nimport { filesFromEvent } from './dropFiles';\n\ninterface FileDropzoneProps {\n onDrop: (files: File[]) => void;\n /** Accept map per react-dropzone, e.g. `{ 'image/*': ['.png'] }`. */\n accept?: Accept;\n multiple?: boolean;\n disabled?: boolean;\n /** Reject files bigger than this many bytes (forwarded to react-dropzone). */\n maxSize?: number;\n /**\n * When true, the `<input>` gets `webkitdirectory` so the user can select\n * an entire folder. Files of a picked or dropped folder carry their path\n * inside it in `webkitRelativePath`.\n */\n directory?: boolean;\n /**\n * `'inline'` (default) — standard dashed-border dropzone block.\n * `'overlay'` — fixed/absolute fullscreen overlay with a dashed border and\n * centred hint; use inside a `position: relative` container.\n */\n variant?: 'inline' | 'overlay';\n /** Override the body text in the drop area. */\n hint?: ReactNode;\n className?: string;\n style?: CSSProperties;\n}\n\nexport function FileDropzone({\n onDrop,\n accept,\n multiple = true,\n disabled = false,\n maxSize,\n directory = false,\n variant = 'inline',\n hint,\n className,\n style,\n}: FileDropzoneProps) {\n const strings = useStrings();\n const { getRootProps, getInputProps, isDragActive, isDragReject } =\n useDropzone({\n onDrop,\n accept,\n multiple,\n disabled,\n maxSize,\n getFilesFromEvent: filesFromEvent,\n });\n\n const isOverlay = variant === 'overlay';\n\n const rootClass = [\n 'aegis-file-dropzone',\n isOverlay ? 'aegis-file-dropzone--overlay' : '',\n isDragActive ? 'aegis-file-dropzone--active' : '',\n isDragReject ? 'aegis-file-dropzone--reject' : '',\n disabled ? 'aegis-file-dropzone--disabled' : '',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const inputProps = getInputProps();\n\n return (\n <div\n className={\n isOverlay\n ? 'aegis-file-dropzone__root aegis-file-dropzone__root--overlay'\n : 'aegis-file-dropzone__root'\n }\n style={style}\n >\n <div {...getRootProps({ className: rootClass })}>\n <input\n {...inputProps}\n {...(directory ? { webkitdirectory: '', mozdirectory: '' } : {})}\n />\n <div className=\"aegis-file-dropzone__hint\">\n {hint ?? (\n <>\n <span className=\"aegis-file-dropzone__primary\">\n {isDragActive\n ? directory\n ? strings.dropzoneDropFolder\n : strings.dropzoneDropFiles\n : directory\n ? strings.dropzoneBrowseFolder\n : strings.dropzoneBrowseFiles}\n </span>\n {accept ? (\n <span className=\"aegis-file-dropzone__meta\">\n {Object.keys(accept).join(', ')}\n </span>\n ) : null}\n {maxSize !== undefined ? (\n <span className=\"aegis-file-dropzone__meta aegis-file-dropzone__meta--size\">\n {strings.dropzoneMaxSize(formatBytes(maxSize))}\n </span>\n ) : null}\n </>\n )}\n </div>\n </div>\n </div>\n );\n}\n"],"names":["FileDropzone","onDrop","accept","multiple","disabled","maxSize","directory","variant","hint","className","style","strings","useStrings","getRootProps","getInputProps","isDragActive","isDragReject","useDropzone","filesFromEvent","isOverlay","rootClass","inputProps","jsx","jsxs","Fragment","formatBytes"],"mappings":";;;;;;AAmCO,SAASA,EAAa;AAAA,EAC3B,QAAAC;AAAA,EACA,QAAAC;AAAA,EACA,UAAAC,IA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C,QAAA,EAAK,WAAU,6BACb,UAAA,OAAO,KAAKpB,CAAM,EAAE,KAAK,IAAI,EAAA,CAChC,IACE;AAAA,UACHG,MAAY,SACX,gBAAAiB,EAAC,QAAA,EAAK,WAAU,6DACb,UAAAX,EAAQ,gBAAgBc,EAAYpB,CAAO,CAAC,EAAA,CAC/C,IACE;AAAA,QAAA,EAAA,CACN,EAAA,CAEJ;AAAA,MAAA,EAAA,CACF;AAAA,IAAA;AAAA,EAAA;AAGN;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),d=require("react"),m=require("../../agent/core/usePrimitiveSurface.cjs"),_=require("../../lib/format.cjs");;/* empty css */const f=require("../../locale/useStrings.cjs"),h=256*1024;async function b(i,e){if(!i.body)return(await i.blob()).slice(0,e).text();const r=i.body.getReader(),s=new TextDecoder;let n="",o=0;for(;o<e;){const{done:l,value:a}=await r.read();if(l)return n+s.decode();const u=a.subarray(0,e-o);o+=u.byteLength,n+=s.decode(u,{stream:!0})}return await r.cancel(),n+s.decode()}function j({src:i,mimeType:e,name:r,size:s,fallback:n,maxHeight:o=480,className:l,style:a,surface:u}){const v=f.useStrings(),p=d.useRef(null),g=m.usePrimitiveSurface(u,{src:i,mimeType:e,name:r,size:s},"preview",p),c=N(e),w=["aegis-file-preview",l??""].filter(Boolean).join(" "),x={"--aegis-file-preview-max-height":typeof o=="number"?`${String(o)}px`:o,...a};return t.jsx("div",{ref:p,className:w,style:x,...g,children:c==="image"?t.jsx("img",{className:"aegis-file-preview__image",src:i,alt:r??""}):c==="video"?t.jsx("video",{className:"aegis-file-preview__video",src:i,controls:!0}):c==="audio"?t.jsx("audio",{className:"aegis-file-preview__audio",src:i,controls:!0}):c==="pdf"?t.jsx("iframe",{className:"aegis-file-preview__iframe",src:i,title:r??v.pdfPreview}):c==="text"?t.jsx(y,{src:i},i):t.jsx(S,{name:r,size:s,src:i,fallback:n})})}function y({src:i}){const e=f.useStrings(),[r,s]=d.useState(null),[n,o]=d.useState(null);return d.useEffect(()=>{const l=new AbortController;return(async()=>{try{const a=await fetch(i,{signal:l.signal});if(!a.ok)throw new Error(`HTTP ${a.status.toString()}`);s(await b(a,h))}catch(a){if(a instanceof DOMException&&a.name==="AbortError")return;o(a instanceof Error?a.message:String(a))}})(),()=>{l.abort()}},[i]),n!==null?t.jsx("div",{className:"aegis-file-preview__error",children:e.filePreviewFailed(n)}):r===null?t.jsx("div",{className:"aegis-file-preview__loading",children:e.filePreviewLoading}):t.jsx("pre",{className:"aegis-file-preview__text",children:r})}function S({src:i,name:e,size:r,fallback:s}){const n=f.useStrings();return s!==void 0?t.jsx("div",{className:"aegis-file-preview__fallback",children:s}):t.jsxs("div",{className:"aegis-file-preview__fallback",children:[t.jsx("span",{className:"aegis-file-preview__fallback-name",children:e??n.binaryFile}),r!==void 0?t.jsx("span",{className:"aegis-file-preview__fallback-meta",children:_.formatBytes(r)}):null,t.jsx("a",{className:"aegis-file-preview__fallback-download",href:i,download:e??!0,children:n.download})]})}function N(i){if(!i)return"binary";const e=i.split(";")[0].trim().toLowerCase();return e.startsWith("image/")?"image":e.startsWith("video/")?"video":e.startsWith("audio/")?"audio":e==="application/pdf"?"pdf":e.startsWith("text/")||e==="application/json"||e==="application/xml"||e==="application/yaml"||e==="application/x-yaml"||e==="application/javascript"||e==="application/x-sh"||e.endsWith("+json")||e.endsWith("+xml")?"text":"binary"}exports.FilePreview=j;
|
|
2
2
|
//# sourceMappingURL=FilePreview.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilePreview.cjs","sources":["../../../src/components/ui/FilePreview.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport {\n type PrimitiveSurface,\n usePrimitiveSurface,\n} from '../../agent/core/usePrimitiveSurface';\nimport { formatBytes } from '../../lib/format';\nimport { useStrings } from '../../locale';\nimport './FilePreview.css';\n\nexport type FilePreviewSurface = PrimitiveSurface<{\n src: string;\n mimeType?: string;\n name?: string;\n size?: number;\n}>;\n\ninterface FilePreviewProps {\n /** URL the browser can load the file from, as for `<img src>`. */\n src: string;\n /**\n * MIME type, parameters allowed (`application/json; charset=utf-8`);\n * chooses the renderer. Unknown ⇒ binary fallback.\n */\n mimeType?: string;\n /** File display name (download fallback + tooltip). */\n name?: string;\n /** Optional byte size (binary fallback uses this). */\n size?: number;\n /** Render slot when binary fallback fires (overrides default). */\n fallback?: ReactNode;\n /** Max height of preview viewport. */\n maxHeight?: number | string;\n className?: string;\n style?: CSSProperties;\n surface?: FilePreviewSurface;\n}\n\nconst TEXT_FETCH_LIMIT = 256 * 1024;\n\n/**\n * Reads at most `limit` bytes of the body and cancels the rest, so a large\n * file is not downloaded to show its first lines.\n */\nasync function readTextPrefix(res: Response, limit: number): Promise<string> {\n if (!res.body) {\n return (await res.blob()).slice(0, limit).text();\n }\n const reader = res.body.getReader();\n const decoder = new TextDecoder();\n let text = '';\n let read = 0;\n while (read < limit) {\n const { done, value } = await reader.read();\n if (done) {\n return text + decoder.decode();\n }\n const chunk = value.subarray(0, limit - read);\n read += chunk.byteLength;\n text += decoder.decode(chunk, { stream: true });\n }\n await reader.cancel();\n return text + decoder.decode();\n}\n\nexport function FilePreview({\n src,\n mimeType,\n name,\n size,\n fallback,\n maxHeight = 480,\n className,\n style,\n surface,\n}: FilePreviewProps) {\n const strings = useStrings();\n const wrapRef = useRef<HTMLDivElement>(null);\n const agentAttrs = usePrimitiveSurface(\n surface,\n { src, mimeType, name, size },\n 'preview',\n wrapRef,\n );\n const kind = classify(mimeType);\n const rootClass = ['aegis-file-preview', className ?? '']\n .filter(Boolean)\n .join(' ');\n const rootStyle: CSSProperties = { maxHeight, ...style };\n\n return (\n <div ref={wrapRef} className={rootClass} style={rootStyle} {...agentAttrs}>\n {kind === 'image' ? (\n <img className=\"aegis-file-preview__image\" src={src} alt={name ?? ''} />\n ) : kind === 'video' ? (\n // Preview surface for arbitrary uploads — captions are the producer's responsibility.\n // eslint-disable-next-line jsx-a11y/media-has-caption\n <video className=\"aegis-file-preview__video\" src={src} controls />\n ) : kind === 'audio' ? (\n // Same as <video> above.\n // eslint-disable-next-line jsx-a11y/media-has-caption\n <audio className=\"aegis-file-preview__audio\" src={src} controls />\n ) : kind === 'pdf' ? (\n <iframe\n className=\"aegis-file-preview__iframe\"\n src={src}\n title={name ?? strings.pdfPreview}\n />\n ) : kind === 'text' ? (\n // Keyed so a new file starts from a clean loading state.\n <TextPreview key={src} src={src} />\n ) : (\n <BinaryFallback name={name} size={size} src={src} fallback={fallback} />\n )}\n </div>\n );\n}\n\nfunction TextPreview({ src }: { src: string }) {\n const strings = useStrings();\n const [body, setBody] = useState<string | null>(null);\n const [err, setErr] = useState<string | null>(null);\n\n useEffect(() => {\n const ac = new AbortController();\n void (async () => {\n try {\n const res = await fetch(src, { signal: ac.signal });\n if (!res.ok) {\n throw new Error(`HTTP ${res.status.toString()}`);\n }\n setBody(await readTextPrefix(res, TEXT_FETCH_LIMIT));\n } catch (e) {\n if (e instanceof DOMException && e.name === 'AbortError') {\n return;\n }\n setErr(e instanceof Error ? e.message : String(e));\n }\n })();\n return () => {\n ac.abort();\n };\n }, [src]);\n\n if (err !== null) {\n return (\n <div className=\"aegis-file-preview__error\">\n {strings.filePreviewFailed(err)}\n </div>\n );\n }\n if (body === null) {\n return (\n <div className=\"aegis-file-preview__loading\">\n {strings.filePreviewLoading}\n </div>\n );\n }\n return <pre className=\"aegis-file-preview__text\">{body}</pre>;\n}\n\ninterface BinaryFallbackProps {\n src: string;\n name?: string;\n size?: number;\n fallback?: ReactNode;\n}\n\nfunction BinaryFallback({ src, name, size, fallback }: BinaryFallbackProps) {\n const strings = useStrings();\n if (fallback !== undefined) {\n return <div className=\"aegis-file-preview__fallback\">{fallback}</div>;\n }\n return (\n <div className=\"aegis-file-preview__fallback\">\n <span className=\"aegis-file-preview__fallback-name\">\n {name ?? strings.binaryFile}\n </span>\n {size !== undefined ? (\n <span className=\"aegis-file-preview__fallback-meta\">\n {formatBytes(size)}\n </span>\n ) : null}\n <a\n className=\"aegis-file-preview__fallback-download\"\n href={src}\n download={name ?? true}\n >\n {strings.download}\n </a>\n </div>\n );\n}\n\ntype Kind = 'image' | 'video' | 'audio' | 'pdf' | 'text' | 'binary';\n\nfunction classify(mime: string | undefined): Kind {\n if (!mime) {\n return 'binary';\n }\n const m = mime.split(';')[0].trim().toLowerCase();\n if (m.startsWith('image/')) {\n return 'image';\n }\n if (m.startsWith('video/')) {\n return 'video';\n }\n if (m.startsWith('audio/')) {\n return 'audio';\n }\n if (m === 'application/pdf') {\n return 'pdf';\n }\n if (\n m.startsWith('text/') ||\n m === 'application/json' ||\n m === 'application/xml' ||\n m === 'application/yaml' ||\n m === 'application/x-yaml' ||\n m === 'application/javascript' ||\n m === 'application/x-sh' ||\n m.endsWith('+json') ||\n m.endsWith('+xml')\n ) {\n return 'text';\n }\n return 'binary';\n}\n"],"names":["TEXT_FETCH_LIMIT","readTextPrefix","res","limit","reader","decoder","text","read","done","value","chunk","FilePreview","src","mimeType","name","size","fallback","maxHeight","className","style","surface","strings","useStrings","wrapRef","useRef","agentAttrs","usePrimitiveSurface","kind","classify","rootClass","rootStyle","jsx","TextPreview","BinaryFallback","body","setBody","useState","err","setErr","useEffect","ac","e","jsxs","formatBytes","mime","m"],"mappings":"gTA4CMA,EAAmB,IAAM,KAM/B,eAAeC,EAAeC,EAAeC,EAAgC,CAC3E,GAAI,CAACD,EAAI,KACP,OAAQ,MAAMA,EAAI,KAAA,GAAQ,MAAM,EAAGC,CAAK,EAAE,KAAA,EAE5C,MAAMC,EAASF,EAAI,KAAK,UAAA,EAClBG,EAAU,IAAI,YACpB,IAAIC,EAAO,GACPC,EAAO,EACX,KAAOA,EAAOJ,GAAO,CACnB,KAAM,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AAA,CAAI,UAAU,+BACb,SAAA,CAAAX,MAAC,OAAA,CAAK,UAAU,oCACb,SAAAjB,GAAQO,EAAQ,WACnB,EACCN,IAAS,OACRgB,MAAC,OAAA,CAAK,UAAU,oCACb,SAAAY,EAAAA,YAAY5B,CAAI,CAAA,CACnB,EACE,KACJgB,EAAAA,IAAC,IAAA,CACC,UAAU,wCACV,KAAMnB,EACN,SAAUE,GAAQ,GAEjB,SAAAO,EAAQ,QAAA,CAAA,CACX,EACF,CAEJ,CAIA,SAASO,EAASgB,EAAgC,CAChD,GAAI,CAACA,EACH,MAAO,SAET,MAAMC,EAAID,EAAK,MAAM,GAAG,EAAE,CAAC,EAAE,KAAA,EAAO,YAAA,EACpC,OAAIC,EAAE,WAAW,QAAQ,EAChB,QAELA,EAAE,WAAW,QAAQ,EAChB,QAELA,EAAE,WAAW,QAAQ,EAChB,QAELA,IAAM,kBACD,MAGPA,EAAE,WAAW,OAAO,GACpBA,IAAM,oBACNA,IAAM,mBACNA,IAAM,oBACNA,IAAM,sBACNA,IAAM,0BACNA,IAAM,oBACNA,EAAE,SAAS,OAAO,GAClBA,EAAE,SAAS,MAAM,EAEV,OAEF,QACT"}
|
|
1
|
+
{"version":3,"file":"FilePreview.cjs","sources":["../../../src/components/ui/FilePreview.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport {\n type PrimitiveSurface,\n usePrimitiveSurface,\n} from '../../agent/core/usePrimitiveSurface';\nimport { formatBytes } from '../../lib/format';\nimport { useStrings } from '../../locale';\nimport './FilePreview.css';\n\nexport type FilePreviewSurface = PrimitiveSurface<{\n src: string;\n mimeType?: string;\n name?: string;\n size?: number;\n}>;\n\ninterface FilePreviewProps {\n /** URL the browser can load the file from, as for `<img src>`. */\n src: string;\n /**\n * MIME type, parameters allowed (`application/json; charset=utf-8`);\n * chooses the renderer. Unknown ⇒ binary fallback.\n */\n mimeType?: string;\n /** File display name (download fallback + tooltip). */\n name?: string;\n /** Optional byte size (binary fallback uses this). */\n size?: number;\n /** Render slot when binary fallback fires (overrides default). */\n fallback?: ReactNode;\n /** Max height of preview viewport. */\n maxHeight?: number | string;\n className?: string;\n style?: CSSProperties;\n surface?: FilePreviewSurface;\n}\n\nconst TEXT_FETCH_LIMIT = 256 * 1024;\n\n/**\n * Reads at most `limit` bytes of the body and cancels the rest, so a large\n * file is not downloaded to show its first lines.\n */\nasync function readTextPrefix(res: Response, limit: number): Promise<string> {\n if (!res.body) {\n return (await res.blob()).slice(0, limit).text();\n }\n const reader = res.body.getReader();\n const decoder = new TextDecoder();\n let text = '';\n let read = 0;\n while (read < limit) {\n const { done, value } = await reader.read();\n if (done) {\n return text + decoder.decode();\n }\n const chunk = value.subarray(0, limit - read);\n read += chunk.byteLength;\n text += decoder.decode(chunk, { stream: true });\n }\n await reader.cancel();\n return text + decoder.decode();\n}\n\nexport function FilePreview({\n src,\n mimeType,\n name,\n size,\n fallback,\n maxHeight = 480,\n className,\n style,\n surface,\n}: FilePreviewProps) {\n const strings = useStrings();\n const wrapRef = useRef<HTMLDivElement>(null);\n const agentAttrs = usePrimitiveSurface(\n surface,\n { src, mimeType, name, size },\n 'preview',\n wrapRef,\n );\n const kind = classify(mimeType);\n const rootClass = ['aegis-file-preview', className ?? '']\n .filter(Boolean)\n .join(' ');\n const rootStyle = {\n '--aegis-file-preview-max-height':\n typeof maxHeight === 'number' ? `${String(maxHeight)}px` : maxHeight,\n ...style,\n } as CSSProperties;\n\n return (\n <div ref={wrapRef} className={rootClass} style={rootStyle} {...agentAttrs}>\n {kind === 'image' ? (\n <img className=\"aegis-file-preview__image\" src={src} alt={name ?? ''} />\n ) : kind === 'video' ? (\n // Preview surface for arbitrary uploads — captions are the producer's responsibility.\n // eslint-disable-next-line jsx-a11y/media-has-caption\n <video className=\"aegis-file-preview__video\" src={src} controls />\n ) : kind === 'audio' ? (\n // Same as <video> above.\n // eslint-disable-next-line jsx-a11y/media-has-caption\n <audio className=\"aegis-file-preview__audio\" src={src} controls />\n ) : kind === 'pdf' ? (\n <iframe\n className=\"aegis-file-preview__iframe\"\n src={src}\n title={name ?? strings.pdfPreview}\n />\n ) : kind === 'text' ? (\n // Keyed so a new file starts from a clean loading state.\n <TextPreview key={src} src={src} />\n ) : (\n <BinaryFallback name={name} size={size} src={src} fallback={fallback} />\n )}\n </div>\n );\n}\n\nfunction TextPreview({ src }: { src: string }) {\n const strings = useStrings();\n const [body, setBody] = useState<string | null>(null);\n const [err, setErr] = useState<string | null>(null);\n\n useEffect(() => {\n const ac = new AbortController();\n void (async () => {\n try {\n const res = await fetch(src, { signal: ac.signal });\n if (!res.ok) {\n throw new Error(`HTTP ${res.status.toString()}`);\n }\n setBody(await readTextPrefix(res, TEXT_FETCH_LIMIT));\n } catch (e) {\n if (e instanceof DOMException && e.name === 'AbortError') {\n return;\n }\n setErr(e instanceof Error ? e.message : String(e));\n }\n })();\n return () => {\n ac.abort();\n };\n }, [src]);\n\n if (err !== null) {\n return (\n <div className=\"aegis-file-preview__error\">\n {strings.filePreviewFailed(err)}\n </div>\n );\n }\n if (body === null) {\n return (\n <div className=\"aegis-file-preview__loading\">\n {strings.filePreviewLoading}\n </div>\n );\n }\n return <pre className=\"aegis-file-preview__text\">{body}</pre>;\n}\n\ninterface BinaryFallbackProps {\n src: string;\n name?: string;\n size?: number;\n fallback?: ReactNode;\n}\n\nfunction BinaryFallback({ src, name, size, fallback }: BinaryFallbackProps) {\n const strings = useStrings();\n if (fallback !== undefined) {\n return <div className=\"aegis-file-preview__fallback\">{fallback}</div>;\n }\n return (\n <div className=\"aegis-file-preview__fallback\">\n <span className=\"aegis-file-preview__fallback-name\">\n {name ?? strings.binaryFile}\n </span>\n {size !== undefined ? (\n <span className=\"aegis-file-preview__fallback-meta\">\n {formatBytes(size)}\n </span>\n ) : null}\n <a\n className=\"aegis-file-preview__fallback-download\"\n href={src}\n download={name ?? true}\n >\n {strings.download}\n </a>\n </div>\n );\n}\n\ntype Kind = 'image' | 'video' | 'audio' | 'pdf' | 'text' | 'binary';\n\nfunction classify(mime: string | undefined): Kind {\n if (!mime) {\n return 'binary';\n }\n const m = mime.split(';')[0].trim().toLowerCase();\n if (m.startsWith('image/')) {\n return 'image';\n }\n if (m.startsWith('video/')) {\n return 'video';\n }\n if (m.startsWith('audio/')) {\n return 'audio';\n }\n if (m === 'application/pdf') {\n return 'pdf';\n }\n if (\n m.startsWith('text/') ||\n m === 'application/json' ||\n m === 'application/xml' ||\n m === 'application/yaml' ||\n m === 'application/x-yaml' ||\n m === 'application/javascript' ||\n m === 'application/x-sh' ||\n m.endsWith('+json') ||\n m.endsWith('+xml')\n ) {\n return 'text';\n }\n return 'binary';\n}\n"],"names":["TEXT_FETCH_LIMIT","readTextPrefix","res","limit","reader","decoder","text","read","done","value","chunk","FilePreview","src","mimeType","name","size","fallback","maxHeight","className","style","surface","strings","useStrings","wrapRef","useRef","agentAttrs","usePrimitiveSurface","kind","classify","rootClass","rootStyle","jsx","TextPreview","BinaryFallback","body","setBody","useState","err","setErr","useEffect","ac","e","jsxs","formatBytes","mime","m"],"mappings":"gTA4CMA,EAAmB,IAAM,KAM/B,eAAeC,EAAeC,EAAeC,EAAgC,CAC3E,GAAI,CAACD,EAAI,KACP,OAAQ,MAAMA,EAAI,KAAA,GAAQ,MAAM,EAAGC,CAAK,EAAE,KAAA,EAE5C,MAAMC,EAASF,EAAI,KAAK,UAAA,EAClBG,EAAU,IAAI,YACpB,IAAIC,EAAO,GACPC,EAAO,EACX,KAAOA,EAAOJ,GAAO,CACnB,KAAM,CAAE,KAAAK,EAAM,MAAAC,CAAA,EAAU,MAAML,EAAO,KAAA,EACrC,GAAII,EACF,OAAOF,EAAOD,EAAQ,OAAA,EAExB,MAAMK,EAAQD,EAAM,SAAS,EAAGN,EAAQI,CAAI,EAC5CA,GAAQG,EAAM,WACdJ,GAAQD,EAAQ,OAAOK,EAAO,CAAE,OAAQ,GAAM,CAChD,CACA,aAAMN,EAAO,OAAA,EACNE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,CACC,UAAU,wCACV,KAAMnB,EACN,SAAUE,GAAQ,GAEjB,SAAAO,EAAQ,QAAA,CAAA,CACX,EACF,CAEJ,CAIA,SAASO,EAASgB,EAAgC,CAChD,GAAI,CAACA,EACH,MAAO,SAET,MAAMC,EAAID,EAAK,MAAM,GAAG,EAAE,CAAC,EAAE,KAAA,EAAO,YAAA,EACpC,OAAIC,EAAE,WAAW,QAAQ,EAChB,QAELA,EAAE,WAAW,QAAQ,EAChB,QAELA,EAAE,WAAW,QAAQ,EAChB,QAELA,IAAM,kBACD,MAGPA,EAAE,WAAW,OAAO,GACpBA,IAAM,oBACNA,IAAM,mBACNA,IAAM,oBACNA,IAAM,sBACNA,IAAM,0BACNA,IAAM,oBACNA,EAAE,SAAS,OAAO,GAClBA,EAAE,SAAS,MAAM,EAEV,OAEF,QACT"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as t, jsxs as _ } from "react/jsx-runtime";
|
|
2
2
|
import { useRef as h, useState as p, useEffect as b } from "react";
|
|
3
|
-
import { usePrimitiveSurface as
|
|
4
|
-
import { formatBytes as
|
|
3
|
+
import { usePrimitiveSurface as y } from "../../agent/core/usePrimitiveSurface.js";
|
|
4
|
+
import { formatBytes as x } from "../../lib/format.js";
|
|
5
5
|
/* empty css */
|
|
6
|
-
import { useStrings as
|
|
6
|
+
import { useStrings as d } from "../../locale/useStrings.js";
|
|
7
7
|
const N = 256 * 1024;
|
|
8
8
|
async function k(i, e) {
|
|
9
9
|
if (!i.body)
|
|
@@ -14,8 +14,8 @@ async function k(i, e) {
|
|
|
14
14
|
const { done: l, value: a } = await r.read();
|
|
15
15
|
if (l)
|
|
16
16
|
return o + n.decode();
|
|
17
|
-
const
|
|
18
|
-
s +=
|
|
17
|
+
const f = a.subarray(0, e - s);
|
|
18
|
+
s += f.byteLength, o += n.decode(f, { stream: !0 });
|
|
19
19
|
}
|
|
20
20
|
return await r.cancel(), o + n.decode();
|
|
21
21
|
}
|
|
@@ -28,15 +28,18 @@ function L({
|
|
|
28
28
|
maxHeight: s = 480,
|
|
29
29
|
className: l,
|
|
30
30
|
style: a,
|
|
31
|
-
surface:
|
|
31
|
+
surface: f
|
|
32
32
|
}) {
|
|
33
|
-
const v =
|
|
34
|
-
|
|
33
|
+
const v = d(), u = h(null), w = y(
|
|
34
|
+
f,
|
|
35
35
|
{ src: i, mimeType: e, name: r, size: n },
|
|
36
36
|
"preview",
|
|
37
37
|
u
|
|
38
|
-
), c = T(e),
|
|
39
|
-
|
|
38
|
+
), c = T(e), m = ["aegis-file-preview", l ?? ""].filter(Boolean).join(" "), g = {
|
|
39
|
+
"--aegis-file-preview-max-height": typeof s == "number" ? `${String(s)}px` : s,
|
|
40
|
+
...a
|
|
41
|
+
};
|
|
42
|
+
return /* @__PURE__ */ t("div", { ref: u, className: m, style: g, ...w, children: c === "image" ? /* @__PURE__ */ t("img", { className: "aegis-file-preview__image", src: i, alt: r ?? "" }) : c === "video" ? (
|
|
40
43
|
// Preview surface for arbitrary uploads — captions are the producer's responsibility.
|
|
41
44
|
// eslint-disable-next-line jsx-a11y/media-has-caption
|
|
42
45
|
/* @__PURE__ */ t("video", { className: "aegis-file-preview__video", src: i, controls: !0 })
|
|
@@ -57,7 +60,7 @@ function L({
|
|
|
57
60
|
) : /* @__PURE__ */ t(P, { name: r, size: n, src: i, fallback: o }) });
|
|
58
61
|
}
|
|
59
62
|
function E({ src: i }) {
|
|
60
|
-
const e =
|
|
63
|
+
const e = d(), [r, n] = p(null), [o, s] = p(null);
|
|
61
64
|
return b(() => {
|
|
62
65
|
const l = new AbortController();
|
|
63
66
|
return (async () => {
|
|
@@ -77,10 +80,10 @@ function E({ src: i }) {
|
|
|
77
80
|
}, [i]), o !== null ? /* @__PURE__ */ t("div", { className: "aegis-file-preview__error", children: e.filePreviewFailed(o) }) : r === null ? /* @__PURE__ */ t("div", { className: "aegis-file-preview__loading", children: e.filePreviewLoading }) : /* @__PURE__ */ t("pre", { className: "aegis-file-preview__text", children: r });
|
|
78
81
|
}
|
|
79
82
|
function P({ src: i, name: e, size: r, fallback: n }) {
|
|
80
|
-
const o =
|
|
83
|
+
const o = d();
|
|
81
84
|
return n !== void 0 ? /* @__PURE__ */ t("div", { className: "aegis-file-preview__fallback", children: n }) : /* @__PURE__ */ _("div", { className: "aegis-file-preview__fallback", children: [
|
|
82
85
|
/* @__PURE__ */ t("span", { className: "aegis-file-preview__fallback-name", children: e ?? o.binaryFile }),
|
|
83
|
-
r !== void 0 ? /* @__PURE__ */ t("span", { className: "aegis-file-preview__fallback-meta", children:
|
|
86
|
+
r !== void 0 ? /* @__PURE__ */ t("span", { className: "aegis-file-preview__fallback-meta", children: x(r) }) : null,
|
|
84
87
|
/* @__PURE__ */ t(
|
|
85
88
|
"a",
|
|
86
89
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilePreview.js","sources":["../../../src/components/ui/FilePreview.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport {\n type PrimitiveSurface,\n usePrimitiveSurface,\n} from '../../agent/core/usePrimitiveSurface';\nimport { formatBytes } from '../../lib/format';\nimport { useStrings } from '../../locale';\nimport './FilePreview.css';\n\nexport type FilePreviewSurface = PrimitiveSurface<{\n src: string;\n mimeType?: string;\n name?: string;\n size?: number;\n}>;\n\ninterface FilePreviewProps {\n /** URL the browser can load the file from, as for `<img src>`. */\n src: string;\n /**\n * MIME type, parameters allowed (`application/json; charset=utf-8`);\n * chooses the renderer. Unknown ⇒ binary fallback.\n */\n mimeType?: string;\n /** File display name (download fallback + tooltip). */\n name?: string;\n /** Optional byte size (binary fallback uses this). */\n size?: number;\n /** Render slot when binary fallback fires (overrides default). */\n fallback?: ReactNode;\n /** Max height of preview viewport. */\n maxHeight?: number | string;\n className?: string;\n style?: CSSProperties;\n surface?: FilePreviewSurface;\n}\n\nconst TEXT_FETCH_LIMIT = 256 * 1024;\n\n/**\n * Reads at most `limit` bytes of the body and cancels the rest, so a large\n * file is not downloaded to show its first lines.\n */\nasync function readTextPrefix(res: Response, limit: number): Promise<string> {\n if (!res.body) {\n return (await res.blob()).slice(0, limit).text();\n }\n const reader = res.body.getReader();\n const decoder = new TextDecoder();\n let text = '';\n let read = 0;\n while (read < limit) {\n const { done, value } = await reader.read();\n if (done) {\n return text + decoder.decode();\n }\n const chunk = value.subarray(0, limit - read);\n read += chunk.byteLength;\n text += decoder.decode(chunk, { stream: true });\n }\n await reader.cancel();\n return text + decoder.decode();\n}\n\nexport function FilePreview({\n src,\n mimeType,\n name,\n size,\n fallback,\n maxHeight = 480,\n className,\n style,\n surface,\n}: FilePreviewProps) {\n const strings = useStrings();\n const wrapRef = useRef<HTMLDivElement>(null);\n const agentAttrs = usePrimitiveSurface(\n surface,\n { src, mimeType, name, size },\n 'preview',\n wrapRef,\n );\n const kind = classify(mimeType);\n const rootClass = ['aegis-file-preview', className ?? '']\n .filter(Boolean)\n .join(' ');\n const rootStyle: CSSProperties = { maxHeight, ...style };\n\n return (\n <div ref={wrapRef} className={rootClass} style={rootStyle} {...agentAttrs}>\n {kind === 'image' ? (\n <img className=\"aegis-file-preview__image\" src={src} alt={name ?? ''} />\n ) : kind === 'video' ? (\n // Preview surface for arbitrary uploads — captions are the producer's responsibility.\n // eslint-disable-next-line jsx-a11y/media-has-caption\n <video className=\"aegis-file-preview__video\" src={src} controls />\n ) : kind === 'audio' ? (\n // Same as <video> above.\n // eslint-disable-next-line jsx-a11y/media-has-caption\n <audio className=\"aegis-file-preview__audio\" src={src} controls />\n ) : kind === 'pdf' ? (\n <iframe\n className=\"aegis-file-preview__iframe\"\n src={src}\n title={name ?? strings.pdfPreview}\n />\n ) : kind === 'text' ? (\n // Keyed so a new file starts from a clean loading state.\n <TextPreview key={src} src={src} />\n ) : (\n <BinaryFallback name={name} size={size} src={src} fallback={fallback} />\n )}\n </div>\n );\n}\n\nfunction TextPreview({ src }: { src: string }) {\n const strings = useStrings();\n const [body, setBody] = useState<string | null>(null);\n const [err, setErr] = useState<string | null>(null);\n\n useEffect(() => {\n const ac = new AbortController();\n void (async () => {\n try {\n const res = await fetch(src, { signal: ac.signal });\n if (!res.ok) {\n throw new Error(`HTTP ${res.status.toString()}`);\n }\n setBody(await readTextPrefix(res, TEXT_FETCH_LIMIT));\n } catch (e) {\n if (e instanceof DOMException && e.name === 'AbortError') {\n return;\n }\n setErr(e instanceof Error ? e.message : String(e));\n }\n })();\n return () => {\n ac.abort();\n };\n }, [src]);\n\n if (err !== null) {\n return (\n <div className=\"aegis-file-preview__error\">\n {strings.filePreviewFailed(err)}\n </div>\n );\n }\n if (body === null) {\n return (\n <div className=\"aegis-file-preview__loading\">\n {strings.filePreviewLoading}\n </div>\n );\n }\n return <pre className=\"aegis-file-preview__text\">{body}</pre>;\n}\n\ninterface BinaryFallbackProps {\n src: string;\n name?: string;\n size?: number;\n fallback?: ReactNode;\n}\n\nfunction BinaryFallback({ src, name, size, fallback }: BinaryFallbackProps) {\n const strings = useStrings();\n if (fallback !== undefined) {\n return <div className=\"aegis-file-preview__fallback\">{fallback}</div>;\n }\n return (\n <div className=\"aegis-file-preview__fallback\">\n <span className=\"aegis-file-preview__fallback-name\">\n {name ?? strings.binaryFile}\n </span>\n {size !== undefined ? (\n <span className=\"aegis-file-preview__fallback-meta\">\n {formatBytes(size)}\n </span>\n ) : null}\n <a\n className=\"aegis-file-preview__fallback-download\"\n href={src}\n download={name ?? true}\n >\n {strings.download}\n </a>\n </div>\n );\n}\n\ntype Kind = 'image' | 'video' | 'audio' | 'pdf' | 'text' | 'binary';\n\nfunction classify(mime: string | undefined): Kind {\n if (!mime) {\n return 'binary';\n }\n const m = mime.split(';')[0].trim().toLowerCase();\n if (m.startsWith('image/')) {\n return 'image';\n }\n if (m.startsWith('video/')) {\n return 'video';\n }\n if (m.startsWith('audio/')) {\n return 'audio';\n }\n if (m === 'application/pdf') {\n return 'pdf';\n }\n if (\n m.startsWith('text/') ||\n m === 'application/json' ||\n m === 'application/xml' ||\n m === 'application/yaml' ||\n m === 'application/x-yaml' ||\n m === 'application/javascript' ||\n m === 'application/x-sh' ||\n m.endsWith('+json') ||\n m.endsWith('+xml')\n ) {\n return 'text';\n }\n return 'binary';\n}\n"],"names":["TEXT_FETCH_LIMIT","readTextPrefix","res","limit","reader","decoder","text","read","done","value","chunk","FilePreview","src","mimeType","name","size","fallback","maxHeight","className","style","surface","strings","useStrings","wrapRef","useRef","agentAttrs","usePrimitiveSurface","kind","classify","rootClass","rootStyle","jsx","TextPreview","BinaryFallback","body","setBody","useState","err","setErr","useEffect","ac","e","jsxs","formatBytes","mime","m"],"mappings":";;;;;;AA4CA,MAAMA,IAAmB,MAAM;AAM/B,eAAeC,EAAeC,GAAeC,GAAgC;AAC3E,MAAI,CAACD,EAAI;AACP,YAAQ,MAAMA,EAAI,KAAA,GAAQ,MAAM,GAAGC,CAAK,EAAE,KAAA;AAE5C,QAAMC,IAASF,EAAI,KAAK,UAAA,GAClBG,IAAU,IAAI,YAAA;AACpB,MAAIC,IAAO,IACPC,IAAO;AACX,SAAOA,IAAOJ,KAAO;AACnB,UAAM,EAAE,MAAAK,GAAM,OAAAC,EAAA,IAAU,MAAML,EAAO,KAAA;AACrC,QAAII;AACF,aAAOF,IAAOD,EAAQ,OAAA;AAExB,UAAMK,IAAQD,EAAM,SAAS,GAAGN,IAAQI,CAAI;AAC5C,IAAAA,KAAQG,EAAM,YACdJ,KAAQD,EAAQ,OAAOK,GAAO,EAAE,QAAQ,IAAM;AAAA,EAChD;AACA,eAAMN,EAAO,OAAA,GACNE,IAAOD,EAAQ,OAAA;AACxB;AAEO,SAASM,EAAY;AAAA,EAC1B,KAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,SAAAC;AACF,GAAqB;AACnB,QAAMC,IAAUC,EAAA,GACVC,I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AA,QAEjB,UAAAO,EAAQ;AAAA,MAAA;AAAA,IAAA;AAAA,EACX,GACF;AAEJ;AAIA,SAASO,EAASgB,GAAgC;AAChD,MAAI,CAACA;AACH,WAAO;AAET,QAAMC,IAAID,EAAK,MAAM,GAAG,EAAE,CAAC,EAAE,KAAA,EAAO,YAAA;AACpC,SAAIC,EAAE,WAAW,QAAQ,IAChB,UAELA,EAAE,WAAW,QAAQ,IAChB,UAELA,EAAE,WAAW,QAAQ,IAChB,UAELA,MAAM,oBACD,QAGPA,EAAE,WAAW,OAAO,KACpBA,MAAM,sBACNA,MAAM,qBACNA,MAAM,sBACNA,MAAM,wBACNA,MAAM,4BACNA,MAAM,sBACNA,EAAE,SAAS,OAAO,KAClBA,EAAE,SAAS,MAAM,IAEV,SAEF;AACT;"}
|
|
1
|
+
{"version":3,"file":"FilePreview.js","sources":["../../../src/components/ui/FilePreview.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport {\n type PrimitiveSurface,\n usePrimitiveSurface,\n} from '../../agent/core/usePrimitiveSurface';\nimport { formatBytes } from '../../lib/format';\nimport { useStrings } from '../../locale';\nimport './FilePreview.css';\n\nexport type FilePreviewSurface = PrimitiveSurface<{\n src: string;\n mimeType?: string;\n name?: string;\n size?: number;\n}>;\n\ninterface FilePreviewProps {\n /** URL the browser can load the file from, as for `<img src>`. */\n src: string;\n /**\n * MIME type, parameters allowed (`application/json; charset=utf-8`);\n * chooses the renderer. Unknown ⇒ binary fallback.\n */\n mimeType?: string;\n /** File display name (download fallback + tooltip). */\n name?: string;\n /** Optional byte size (binary fallback uses this). */\n size?: number;\n /** Render slot when binary fallback fires (overrides default). */\n fallback?: ReactNode;\n /** Max height of preview viewport. */\n maxHeight?: number | string;\n className?: string;\n style?: CSSProperties;\n surface?: FilePreviewSurface;\n}\n\nconst TEXT_FETCH_LIMIT = 256 * 1024;\n\n/**\n * Reads at most `limit` bytes of the body and cancels the rest, so a large\n * file is not downloaded to show its first lines.\n */\nasync function readTextPrefix(res: Response, limit: number): Promise<string> {\n if (!res.body) {\n return (await res.blob()).slice(0, limit).text();\n }\n const reader = res.body.getReader();\n const decoder = new TextDecoder();\n let text = '';\n let read = 0;\n while (read < limit) {\n const { done, value } = await reader.read();\n if (done) {\n return text + decoder.decode();\n }\n const chunk = value.subarray(0, limit - read);\n read += chunk.byteLength;\n text += decoder.decode(chunk, { stream: true });\n }\n await reader.cancel();\n return text + decoder.decode();\n}\n\nexport function FilePreview({\n src,\n mimeType,\n name,\n size,\n fallback,\n maxHeight = 480,\n className,\n style,\n surface,\n}: FilePreviewProps) {\n const strings = useStrings();\n const wrapRef = useRef<HTMLDivElement>(null);\n const agentAttrs = usePrimitiveSurface(\n surface,\n { src, mimeType, name, size },\n 'preview',\n wrapRef,\n );\n const kind = classify(mimeType);\n const rootClass = ['aegis-file-preview', className ?? '']\n .filter(Boolean)\n .join(' ');\n const rootStyle = {\n '--aegis-file-preview-max-height':\n typeof maxHeight === 'number' ? `${String(maxHeight)}px` : maxHeight,\n ...style,\n } as CSSProperties;\n\n return (\n <div ref={wrapRef} className={rootClass} style={rootStyle} {...agentAttrs}>\n {kind === 'image' ? (\n <img className=\"aegis-file-preview__image\" src={src} alt={name ?? ''} />\n ) : kind === 'video' ? (\n // Preview surface for arbitrary uploads — captions are the producer's responsibility.\n // eslint-disable-next-line jsx-a11y/media-has-caption\n <video className=\"aegis-file-preview__video\" src={src} controls />\n ) : kind === 'audio' ? (\n // Same as <video> above.\n // eslint-disable-next-line jsx-a11y/media-has-caption\n <audio className=\"aegis-file-preview__audio\" src={src} controls />\n ) : kind === 'pdf' ? (\n <iframe\n className=\"aegis-file-preview__iframe\"\n src={src}\n title={name ?? strings.pdfPreview}\n />\n ) : kind === 'text' ? (\n // Keyed so a new file starts from a clean loading state.\n <TextPreview key={src} src={src} />\n ) : (\n <BinaryFallback name={name} size={size} src={src} fallback={fallback} />\n )}\n </div>\n );\n}\n\nfunction TextPreview({ src }: { src: string }) {\n const strings = useStrings();\n const [body, setBody] = useState<string | null>(null);\n const [err, setErr] = useState<string | null>(null);\n\n useEffect(() => {\n const ac = new AbortController();\n void (async () => {\n try {\n const res = await fetch(src, { signal: ac.signal });\n if (!res.ok) {\n throw new Error(`HTTP ${res.status.toString()}`);\n }\n setBody(await readTextPrefix(res, TEXT_FETCH_LIMIT));\n } catch (e) {\n if (e instanceof DOMException && e.name === 'AbortError') {\n return;\n }\n setErr(e instanceof Error ? e.message : String(e));\n }\n })();\n return () => {\n ac.abort();\n };\n }, [src]);\n\n if (err !== null) {\n return (\n <div className=\"aegis-file-preview__error\">\n {strings.filePreviewFailed(err)}\n </div>\n );\n }\n if (body === null) {\n return (\n <div className=\"aegis-file-preview__loading\">\n {strings.filePreviewLoading}\n </div>\n );\n }\n return <pre className=\"aegis-file-preview__text\">{body}</pre>;\n}\n\ninterface BinaryFallbackProps {\n src: string;\n name?: string;\n size?: number;\n fallback?: ReactNode;\n}\n\nfunction BinaryFallback({ src, name, size, fallback }: BinaryFallbackProps) {\n const strings = useStrings();\n if (fallback !== undefined) {\n return <div className=\"aegis-file-preview__fallback\">{fallback}</div>;\n }\n return (\n <div className=\"aegis-file-preview__fallback\">\n <span className=\"aegis-file-preview__fallback-name\">\n {name ?? strings.binaryFile}\n </span>\n {size !== undefined ? (\n <span className=\"aegis-file-preview__fallback-meta\">\n {formatBytes(size)}\n </span>\n ) : null}\n <a\n className=\"aegis-file-preview__fallback-download\"\n href={src}\n download={name ?? true}\n >\n {strings.download}\n </a>\n </div>\n );\n}\n\ntype Kind = 'image' | 'video' | 'audio' | 'pdf' | 'text' | 'binary';\n\nfunction classify(mime: string | undefined): Kind {\n if (!mime) {\n return 'binary';\n }\n const m = mime.split(';')[0].trim().toLowerCase();\n if (m.startsWith('image/')) {\n return 'image';\n }\n if (m.startsWith('video/')) {\n return 'video';\n }\n if (m.startsWith('audio/')) {\n return 'audio';\n }\n if (m === 'application/pdf') {\n return 'pdf';\n }\n if (\n m.startsWith('text/') ||\n m === 'application/json' ||\n m === 'application/xml' ||\n m === 'application/yaml' ||\n m === 'application/x-yaml' ||\n m === 'application/javascript' ||\n m === 'application/x-sh' ||\n m.endsWith('+json') ||\n m.endsWith('+xml')\n ) {\n return 'text';\n }\n return 'binary';\n}\n"],"names":["TEXT_FETCH_LIMIT","readTextPrefix","res","limit","reader","decoder","text","read","done","value","chunk","FilePreview","src","mimeType","name","size","fallback","maxHeight","className","style","surface","strings","useStrings","wrapRef","useRef","agentAttrs","usePrimitiveSurface","kind","classify","rootClass","rootStyle","jsx","TextPreview","BinaryFallback","body","setBody","useState","err","setErr","useEffect","ac","e","jsxs","formatBytes","mime","m"],"mappings":";;;;;;AA4CA,MAAMA,IAAmB,MAAM;AAM/B,eAAeC,EAAeC,GAAeC,GAAgC;AAC3E,MAAI,CAACD,EAAI;AACP,YAAQ,MAAMA,EAAI,KAAA,GAAQ,MAAM,GAAGC,CAAK,EAAE,KAAA;AAE5C,QAAMC,IAASF,EAAI,KAAK,UAAA,GAClBG,IAAU,IAAI,YAAA;AACpB,MAAIC,IAAO,IACPC,IAAO;AACX,SAAOA,IAAOJ,KAAO;AACnB,UAAM,EAAE,MAAAK,GAAM,OAAAC,EAAA,IAAU,MAAML,EAAO,KAAA;AACrC,QAAII;AACF,aAAOF,IAAOD,EAAQ,OAAA;AAExB,UAAMK,IAAQD,EAAM,SAAS,GAAGN,IAAQI,CAAI;AAC5C,IAAAA,KAAQG,EAAM,YACdJ,KAAQD,EAAQ,OAAOK,GAAO,EAAE,QAAQ,IAAM;AAAA,EAChD;AACA,eAAMN,EAAO,OAAA,GACNE,IAAOD,EAAQ,OAAA;AACxB;AAEO,SAASM,EAAY;AAAA,EAC1B,KAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,S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ACnB,IACE;AAAA,IACJ,gBAAAgB;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAU;AAAA,QACV,MAAMnB;AAAA,QACN,UAAUE,KAAQ;AAAA,QAEjB,UAAAO,EAAQ;AAAA,MAAA;AAAA,IAAA;AAAA,EACX,GACF;AAEJ;AAIA,SAASO,EAASgB,GAAgC;AAChD,MAAI,CAACA;AACH,WAAO;AAET,QAAMC,IAAID,EAAK,MAAM,GAAG,EAAE,CAAC,EAAE,KAAA,EAAO,YAAA;AACpC,SAAIC,EAAE,WAAW,QAAQ,IAChB,UAELA,EAAE,WAAW,QAAQ,IAChB,UAELA,EAAE,WAAW,QAAQ,IAChB,UAELA,MAAM,oBACD,QAGPA,EAAE,WAAW,OAAO,KACpBA,MAAM,sBACNA,MAAM,qBACNA,MAAM,sBACNA,MAAM,wBACNA,MAAM,4BACNA,MAAM,sBACNA,EAAE,SAAS,OAAO,KAClBA,EAAE,SAAS,MAAM,IAEV,SAEF;AACT;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),ae=require("react"),Ae=require("../../hooks/useElementWidth.cjs"),C=require("../../lib/chart.cjs"),Le=require("./ChartLegend.cjs"),Ne=require("./EmptyState.cjs");;/* empty css */const Ee=require("../../locale/useStrings.cjs"),Me=320,fe=220,Pe=56,Ie=16,we=28,Be=44,$=5,j=8,ue=4,Se=6.2,Ce=11,A=14,F=A/4,$e=520;function Y(t,g,x){return x==="lower"?t<g:t>g}function pe(t){return[...t].reduce((g,x)=>g+((x.codePointAt(0)??0)>255?Ce:Se),0)}function He([t,g],x){const f=g.x-t.x,y=g.y-t.y;let u=0,p=1;for(const[a,s]of[[-f,t.x-x.l],[f,x.r-t.x],[-y,t.y-x.t],[y,x.b-t.y]])if(a===0){if(s<0)return!1}else a<0?u=Math.max(u,s/a):p=Math.min(p,s/a);return u<=p}function Te(t,g,x,f,y){const u=[...f],p=new Map,a=$+j/2;for(const s of t){const L=pe(s.label),v=[{x:s.x+a,y:s.y+A/3,anchor:"start"},{x:s.x-a,y:s.y+A/3,anchor:"end"},{x:s.x-L/2,y:s.y-a,anchor:"start"},{x:s.x-L/2,y:s.y+a+A,anchor:"start"},{x:s.x-a,y:s.y-a,anchor:"end"},{x:s.x+a,y:s.y+a+A,anchor:"start"},{x:s.x+a,y:s.y-a,anchor:"start"},{x:s.x-a,y:s.y+a+A,anchor:"end"}],b=o=>{const d=o.anchor==="end"?o.x-L:o.x;return{l:d,r:d+L,t:o.y-A+F,b:o.y+F}},P=o=>{const{l:d,r:N,t:I,b:w}=b(o);return d>=y.left&&N<=y.right&&I>=y.top&&w<=y.bottom},R=o=>{const{l:d,r:N,t:I,b:w}=b(o);return P(o)&&u.every(n=>N<n.l||d>n.r||w<n.t||I>n.b)&&g.every(n=>n.key===s.key||n.x+$<d||n.x-$>N||n.y+$<I||n.y-$>w)},O=o=>R(o)&&x.every(d=>!He(d,b(o))),H=v.find(O)??v.find(R)??v.find(P)??v[s.x>(y.left+y.right)/2?1:0];u.push(b(H)),p.set(s.key,H)}return p}function qe({points:t,xLabel:g,yLabel:x,xDirection:f="lower",yDirection:y="higher",formatX:u=String,formatY:p=String,xScale:a="linear",xDomain:s,yDomain:L,xTicks:v,yTicks:b,labels:P="front",fadeDominated:R=!0,highlightKeys:O,maxHeight:H=Me,onSelect:o,legend:d,empty:N,emptyTitle:I,emptyDescription:w,progress:n,frontProgress:le,className:ve}){const ne=Ee.useStrings(),ce=ae.useId(),G=ae.useRef(null),E=Ae.useElementWidth(G),U=["aegis-pareto",n===void 0&&le===void 0?"":"aegis-pareto--scroll",ve??""].filter(Boolean).join(" "),m=ae.useMemo(()=>{if(t.length===0||E===0)return null;const e=Math.round(Math.min(H,Math.max(fe,E/2))),c=t.map(r=>r.x),_=Math.min(...c),K=Math.max(...c),[ee,de]=s??(a==="log"?[K>_?_:_/2,K>_?K:K*2]:C.zeroAnchoredDomain(c)),[q,te]=L??C.zeroAnchoredDomain(t.map(r=>r.y)),z=a==="log"?Math.log10:r=>r,D=Pe,re=E-Ie,he=we,se=e-Be,V=r=>D+(z(r)-z(ee))/(z(de)-z(ee))*(re-D),oe=r=>se-(r-q)/(te-q)*(se-he),me=t.filter(r=>!t.some(i=>i.key!==r.key&&(Y(i.x,r.x,f)||i.x===r.x)&&(Y(i.y,r.y,y)||i.y===r.y)&&(Y(i.x,r.x,f)||Y(i.y,r.y,y)))).sort((r,i)=>r.x-i.x),_e=Array.from({length:ue},(r,i)=>(i+1)/ue),je=new Map([...t].sort((r,i)=>V(r.x)-V(i.x)).map((r,i)=>[r.key,i]));return{height:e,order:je,left:D,right:re,top:he,bottom:se,sx:V,sy:oe,front:me,frontKeys:new Set(me.map(r=>r.key)),gridX:v?.map(V)??_e.map(r=>D+(re-D)*r),gridY:b?.map(oe)??_e.map(r=>oe(q+(te-q)*r)),xLabels:v??[ee,de],yLabels:b??[q,te]}},[t,E,f,y,a,s,L,v,b,H]);if(t.length===0)return l.jsx("div",{ref:G,className:U,children:N===void 0?l.jsx(Ne.EmptyState,{title:I??ne.paretoEmptyTitle,description:w}):l.jsx("div",{className:"aegis-pareto__empty",style:{"--aegis-pareto-min-height":`${fe.toString()}px`},children:N})});if(!m)return l.jsx("div",{ref:G,className:U});const{height:W,left:h,right:B,top:J,bottom:S,sx:k,sy:M,front:X,frontKeys:ie}=m,Q=O===void 0?null:new Set(O),xe=e=>Q!==null&&!Q.has(e),Z=J-j*2,ye=P==="all"&&E>=$e,be=Te(t.filter(e=>ye||ie.has(e.key)||(Q?.has(e.key)??!1)).map(e=>({key:e.key,label:e.label,x:k(e.x),y:M(e.y)})),t.map(e=>({key:e.key,x:k(e.x),y:M(e.y)})),X.slice(1).map((e,c)=>{const _=X[c];return[{x:k(_.x),y:M(_.y)},{x:k(e.x),y:M(e.y)}]}),[{l:h-j,r:h-j+pe(x),t:Z-A+F,b:Z+F}],{left:h,right:B,top:0,bottom:S}),ge=d?.map(e=>({key:e.key,label:e.label,color:e.color??"var(--bg-inverted)"}))??(P==="all"&&!ye?t.map(e=>({key:e.key,label:e.label,color:e.color??"var(--bg-inverted)"})):[]),T=le??(n===void 0?void 0:C.staggeredProgress(n,t.length,t.length+1)),ke=(e,c)=>{(e.key==="Enter"||e.key===" ")&&(e.preventDefault(),o?.(c))};return l.jsxs("div",{ref:G,className:U,children:[l.jsxs("svg",{className:"aegis-pareto__svg",width:E,height:W,viewBox:`0 0 ${E.toString()} ${W.toString()}`,role:o?"group":"img","aria-label":ne.paretoChartLabel(g,x),style:{"--aegis-pareto-count":t.length,...T===void 0?{}:{"--aegis-pareto-front-progress":T}},children:[m.gridY.map(e=>l.jsx("line",{className:"aegis-pareto__grid",x1:h,y1:e,x2:B,y2:e},`gy-${e.toString()}`)),m.gridX.map(e=>l.jsx("line",{className:"aegis-pareto__grid",x1:e,y1:J,x2:e,y2:S},`gx-${e.toString()}`)),l.jsx("line",{className:"aegis-pareto__axis",x1:h,y1:S,x2:B,y2:S}),l.jsx("line",{className:"aegis-pareto__axis",x1:h,y1:J,x2:h,y2:S}),T!==void 0&&l.jsx("clipPath",{id:ce,children:l.jsx("rect",{x:h,y:0,width:(B-h)*T,height:W})}),X.length>1&&l.jsx("polyline",{className:"aegis-pareto__front",clipPath:T===void 0?void 0:`url(#${ce})`,points:X.map(e=>`${k(e.x).toString()},${M(e.y).toString()}`).join(" ")}),t.map((e,c)=>l.jsx("circle",{className:["aegis-pareto__point",R&&!ie.has(e.key)?"aegis-pareto__point--dominated":"",xe(e.key)?"aegis-pareto__point--dimmed":"",o?"aegis-pareto__point--interactive":""].filter(Boolean).join(" "),style:{fill:e.color===void 0?void 0:C.chartColorValue(e.color),"--aegis-pareto-index":c,"--aegis-pareto-point-progress":n===void 0?1:C.staggeredProgress(n,m.order.get(e.key)??c,t.length+1)},cx:k(e.x),cy:M(e.y),r:$,role:o?"button":void 0,tabIndex:o?0:void 0,"aria-label":o?e.label:void 0,onClick:o?()=>{o(e.key)}:void 0,onKeyDown:o?_=>{ke(_,e.key)}:void 0,children:l.jsx("title",{children:e.label})},e.key)),t.map(e=>{const c=be.get(e.key);return c===void 0?null:l.jsx("text",{className:["aegis-pareto__point-label",xe(e.key)?"aegis-pareto__point-label--dimmed":""].filter(Boolean).join(" "),style:P==="all"?{"--aegis-pareto-front-progress":n===void 0?1:C.staggeredProgress(n,m.order.get(e.key)??0,t.length+1)}:void 0,x:c.x,y:c.y,textAnchor:c.anchor,children:e.label},`label-${e.key}`)}),m.xLabels.map((e,c)=>l.jsx("text",{className:"aegis-pareto__tick",x:k(e),y:S+j*2,textAnchor:c===m.xLabels.length-1&&k(e)>=B-1?"end":"middle",children:u(e)},`x-${e.toString()}`)),m.yLabels.map(e=>l.jsx("text",{className:"aegis-pareto__tick",x:h-j,y:M(e),textAnchor:"end",dominantBaseline:"middle",children:p(e)},`y-${e.toString()}`)),l.jsx("text",{className:"aegis-pareto__axis-label",x:B,y:W-j,textAnchor:"end",children:g}),l.jsx("text",{className:"aegis-pareto__axis-label",x:h-j,y:Z,textAnchor:"start",children:x})]}),ge.length>0?l.jsx(Le.ChartLegend,{className:"aegis-pareto__legend",shape:"dot",items:ge}):null]})}exports.ParetoChart=qe;
|
|
2
2
|
//# sourceMappingURL=ParetoChart.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParetoChart.cjs","sources":["../../../src/components/ui/ParetoChart.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type ReactNode,\n useId,\n useMemo,\n useRef,\n} from 'react';\n\nimport { useElementWidth } from '../../hooks/useElementWidth';\nimport {\n type ChartColor,\n chartColorValue,\n staggeredProgress,\n zeroAnchoredDomain,\n} from '../../lib/chart';\nimport { useStrings } from '../../locale';\nimport { ChartLegend } from './ChartLegend';\nimport { EmptyState } from './EmptyState';\nimport './ParetoChart.css';\n\nexport interface ParetoPoint {\n key: string;\n label: string;\n x: number;\n y: number;\n /** Point fill, e.g. `cat-2` or a series token, to match the series elsewhere. */\n color?: ChartColor;\n}\n\n/** One series in the legend under the plot, e.g. a model and its colour. */\nexport interface ParetoLegendItem {\n key: string;\n label: ReactNode;\n /** Swatch fill; the same value its points use. */\n color?: ChartColor;\n}\n\ninterface ParetoChartProps {\n points: ParetoPoint[];\n xLabel: string;\n yLabel: string;\n /** Which direction counts as better on each axis. */\n xDirection?: 'lower' | 'higher';\n yDirection?: 'lower' | 'higher';\n /** Formats the labels of each axis. */\n formatX?: (value: number) => string;\n formatY?: (value: number) => string;\n /**\n * `log` spaces the horizontal axis by ratio, e.g. for a cost that spans\n * orders of magnitude; its values must be above 0. Defaults to `linear`.\n */\n xScale?: 'linear' | 'log';\n /** The ends of each axis. Defaults to from 0, or the data's own range on a log axis. */\n xDomain?: [number, number];\n yDomain?: [number, number];\n /**\n * The labelled gridlines of each axis. Defaults to plain gridlines with\n * labels at the two ends.\n */\n xTicks?: number[];\n yTicks?: number[];\n /**\n * Which points carry their name. `front` names the frontier; `all` names\n * every point, so the chart needs no legend. A plot too narrow for them\n * names the frontier and `highlightKeys` and lists every point under it.\n * Defaults to `front`.\n */\n labels?: 'front' | 'all';\n /** Fades the points off the frontier. Defaults to true. */\n fadeDominated?: boolean;\n /** Fades every other point, to pick out the ones a finding is about. */\n highlightKeys?: string[];\n /** The tallest the plot grows. */\n maxHeight?: number;\n onSelect?: (key: string) => void;\n /** Series swatches with labels, listed under the plot. */\n legend?: ParetoLegendItem[];\n /**\n * Shown in place of the plot, at its minimum height, while there are no\n * points — e.g. an EmptyState with an icon asking for both axes. Replaces\n * the default empty state built from `emptyTitle`.\n */\n empty?: ReactNode;\n emptyTitle?: string;\n emptyDescription?: string;\n /**\n * How far the chart is drawn, 0 to 1, for a chart that draws as its\n * section scrolls in (`useScrollProgress`): points fade in from left to\n * right, then the frontier. Omitted, they fade in once on mount.\n */\n progress?: number;\n /**\n * How far the frontier is traced, 0 to 1, for a host that draws it apart\n * from the points, such as one step of a scrolling story.\n */\n frontProgress?: number;\n className?: string;\n}\n\n// The SVG is drawn at its measured CSS width, so these are true px.\nconst MAX_HEIGHT = 320;\nconst MIN_HEIGHT = 220;\nconst PAD_LEFT = 56;\nconst PAD_RIGHT = 16;\nconst PAD_TOP = 28;\nconst PAD_BOTTOM = 44;\nconst POINT_RADIUS = 5;\nconst LABEL_GAP = 8;\nconst GRID_STEPS = 4;\n// Estimates for placing labels: --fs-11 text, and the width below which\n// `labels='all'` would crowd the plot.\nconst LABEL_CHAR = 6.2;\nconst LABEL_WIDE_CHAR = 11;\nconst LABEL_LINE = 14;\nconst ALL_LABELS_MIN_WIDTH = 520;\n\ntype Direction = 'lower' | 'higher';\n\nfunction better(a: number, b: number, direction: Direction): boolean {\n return direction === 'lower' ? a < b : a > b;\n}\n\ninterface LabelBox {\n x: number;\n y: number;\n anchor: 'start' | 'end';\n}\n\nfunction labelWidth(text: string): number {\n return [...text].reduce(\n (sum, char) =>\n sum + ((char.codePointAt(0) ?? 0) > 255 ? LABEL_WIDE_CHAR : LABEL_CHAR),\n 0,\n );\n}\n\n/**\n * Puts each label beside its point on the first side where it stays on the\n * plot and clear of the labels already placed and of the other points.\n */\nfunction placeLabels(\n labelled: Array<{ key: string; label: string; x: number; y: number }>,\n allPoints: Array<{ key: string; x: number; y: number }>,\n bounds: { left: number; right: number; top: number; bottom: number },\n): Map<string, LabelBox> {\n const placed: Array<{ l: number; r: number; t: number; b: number }> = [];\n const result = new Map<string, LabelBox>();\n const reach = POINT_RADIUS + LABEL_GAP / 2;\n for (const point of labelled) {\n const w = labelWidth(point.label);\n const candidates: LabelBox[] = [\n { x: point.x + reach, y: point.y + LABEL_LINE / 3, anchor: 'start' },\n { x: point.x - reach, y: point.y + LABEL_LINE / 3, anchor: 'end' },\n { x: point.x - w / 2, y: point.y - reach, anchor: 'start' },\n { x: point.x - w / 2, y: point.y + reach + LABEL_LINE, anchor: 'start' },\n ];\n const box = (candidate: LabelBox) => {\n const l = candidate.anchor === 'end' ? candidate.x - w : candidate.x;\n return {\n l,\n r: l + w,\n t: candidate.y - LABEL_LINE,\n b: candidate.y,\n };\n };\n const onPlot = (candidate: LabelBox): boolean => {\n const { l, r, t, b } = box(candidate);\n return (\n l >= bounds.left &&\n r <= bounds.right &&\n t >= bounds.top &&\n b <= bounds.bottom\n );\n };\n const clear = (candidate: LabelBox): boolean => {\n const { l, r, t, b } = box(candidate);\n return (\n onPlot(candidate) &&\n placed.every(\n (other) => r < other.l || l > other.r || b < other.t || t > other.b,\n ) &&\n allPoints.every(\n (other) =>\n other.key === point.key ||\n other.x + POINT_RADIUS < l ||\n other.x - POINT_RADIUS > r ||\n other.y + POINT_RADIUS < t ||\n other.y - POINT_RADIUS > b,\n )\n );\n };\n // With no side free the label still stays on the plot, towards its middle.\n const chosen =\n candidates.find(clear) ??\n candidates.find(onPlot) ??\n candidates[point.x > (bounds.left + bounds.right) / 2 ? 1 : 0];\n placed.push(box(chosen));\n result.set(point.key, chosen);\n }\n return result;\n}\n\nexport function ParetoChart({\n points,\n xLabel,\n yLabel,\n xDirection = 'lower',\n yDirection = 'higher',\n formatX = String,\n formatY = String,\n xScale = 'linear',\n xDomain,\n yDomain,\n xTicks,\n yTicks,\n labels = 'front',\n fadeDominated = true,\n highlightKeys,\n maxHeight = MAX_HEIGHT,\n onSelect,\n legend,\n empty,\n emptyTitle,\n emptyDescription,\n progress,\n frontProgress,\n className,\n}: ParetoChartProps) {\n const strings = useStrings();\n const clipId = useId();\n const wrapRef = useRef<HTMLDivElement>(null);\n const width = useElementWidth(wrapRef);\n const cls = [\n 'aegis-pareto',\n progress === undefined && frontProgress === undefined\n ? ''\n : 'aegis-pareto--scroll',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const geometry = useMemo(() => {\n if (points.length === 0 || width === 0) {\n return null;\n }\n const height = Math.round(\n Math.min(maxHeight, Math.max(MIN_HEIGHT, width / 2)),\n );\n const xValues = points.map((point) => point.x);\n const logLo = Math.min(...xValues);\n const logHi = Math.max(...xValues);\n const [xLo, xHi] =\n xDomain ??\n (xScale === 'log'\n ? // One value has no span to divide, so it sits mid-axis.\n ([\n logHi > logLo ? logLo : logLo / 2,\n logHi > logLo ? logHi : logHi * 2,\n ] as const)\n : zeroAnchoredDomain(xValues));\n const [yLo, yHi] =\n yDomain ?? zeroAnchoredDomain(points.map((point) => point.y));\n const scaleX = xScale === 'log' ? Math.log10 : (value: number) => value;\n const left = PAD_LEFT;\n const right = width - PAD_RIGHT;\n const top = PAD_TOP;\n const bottom = height - PAD_BOTTOM;\n const sx = (value: number): number =>\n left +\n ((scaleX(value) - scaleX(xLo)) / (scaleX(xHi) - scaleX(xLo))) *\n (right - left);\n const sy = (value: number): number =>\n bottom - ((value - yLo) / (yHi - yLo)) * (bottom - top);\n const front = points\n .filter(\n (candidate) =>\n !points.some(\n (other) =>\n other.key !== candidate.key &&\n (better(other.x, candidate.x, xDirection) ||\n other.x === candidate.x) &&\n (better(other.y, candidate.y, yDirection) ||\n other.y === candidate.y) &&\n (better(other.x, candidate.x, xDirection) ||\n better(other.y, candidate.y, yDirection)),\n ),\n )\n .sort((a, b) => a.x - b.x);\n const steps = Array.from(\n { length: GRID_STEPS },\n (_, i) => (i + 1) / GRID_STEPS,\n );\n // Points draw in from left to right; the frontier comes last.\n const order = new Map(\n [...points]\n .sort((a, b) => sx(a.x) - sx(b.x))\n .map((point, rank) => [point.key, rank]),\n );\n return {\n height,\n order,\n left,\n right,\n top,\n bottom,\n sx,\n sy,\n front,\n frontKeys: new Set(front.map((point) => point.key)),\n // Even shares of the plot, which on a log axis are even ratios.\n gridX: xTicks?.map(sx) ?? steps.map((t) => left + (right - left) * t),\n gridY: yTicks?.map(sy) ?? steps.map((t) => sy(yLo + (yHi - yLo) * t)),\n xLabels: xTicks ?? [xLo, xHi],\n yLabels: yTicks ?? [yLo, yHi],\n };\n }, [\n points,\n width,\n xDirection,\n yDirection,\n xScale,\n xDomain,\n yDomain,\n xTicks,\n yTicks,\n maxHeight,\n ]);\n\n if (points.length === 0) {\n return (\n <div ref={wrapRef} className={cls}>\n {empty === undefined ? (\n <EmptyState\n title={emptyTitle ?? strings.paretoEmptyTitle}\n description={emptyDescription}\n />\n ) : (\n <div\n className=\"aegis-pareto__empty\"\n style={\n {\n '--aegis-pareto-min-height': `${MIN_HEIGHT.toString()}px`,\n } as CSSProperties\n }\n >\n {empty}\n </div>\n )}\n </div>\n );\n }\n\n if (!geometry) {\n return <div ref={wrapRef} className={cls} />;\n }\n\n const { height, left, right, top, bottom, sx, sy, front, frontKeys } =\n geometry;\n const highlighted =\n highlightKeys === undefined ? null : new Set(highlightKeys);\n const dimmed = (key: string): boolean =>\n highlighted !== null && !highlighted.has(key);\n const showAllLabels = labels === 'all' && width >= ALL_LABELS_MIN_WIDTH;\n const labelBoxes = placeLabels(\n points\n .filter(\n (point) =>\n showAllLabels ||\n frontKeys.has(point.key) ||\n (highlighted?.has(point.key) ?? false),\n )\n .map((point) => ({\n key: point.key,\n label: point.label,\n x: sx(point.x),\n y: sy(point.y),\n })),\n points.map((point) => ({\n key: point.key,\n x: sx(point.x),\n y: sy(point.y),\n })),\n // A label may run up into the space above the plot.\n { left, right, top: 0, bottom },\n );\n // A plot too narrow to name every point names them under it instead, so\n // none is left to a tooltip a phone cannot show.\n const legendItems =\n legend?.map((item) => ({\n key: item.key,\n label: item.label,\n color: item.color ?? ('var(--bg-inverted)' as const),\n })) ??\n (labels === 'all' && !showAllLabels\n ? points.map((point) => ({\n key: point.key,\n label: point.label,\n color: point.color ?? ('var(--bg-inverted)' as const),\n }))\n : []);\n const frontDrawn =\n frontProgress ??\n (progress === undefined\n ? undefined\n : staggeredProgress(progress, points.length, points.length + 1));\n const selectOnKey = (event: KeyboardEvent<SVGCircleElement>, key: string) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n onSelect?.(key);\n }\n };\n\n return (\n <div ref={wrapRef} className={cls}>\n <svg\n className=\"aegis-pareto__svg\"\n width={width}\n height={height}\n viewBox={`0 0 ${width.toString()} ${height.toString()}`}\n role={onSelect ? 'group' : 'img'}\n aria-label={strings.paretoChartLabel(xLabel, yLabel)}\n style={\n {\n '--aegis-pareto-count': points.length,\n ...(frontDrawn === undefined\n ? {}\n : { '--aegis-pareto-front-progress': frontDrawn }),\n } as CSSProperties\n }\n >\n {geometry.gridY.map((y) => (\n <line\n key={`gy-${y.toString()}`}\n className=\"aegis-pareto__grid\"\n x1={left}\n y1={y}\n x2={right}\n y2={y}\n />\n ))}\n {geometry.gridX.map((x) => (\n <line\n key={`gx-${x.toString()}`}\n className=\"aegis-pareto__grid\"\n x1={x}\n y1={top}\n x2={x}\n y2={bottom}\n />\n ))}\n <line\n className=\"aegis-pareto__axis\"\n x1={left}\n y1={bottom}\n x2={right}\n y2={bottom}\n />\n <line\n className=\"aegis-pareto__axis\"\n x1={left}\n y1={top}\n x2={left}\n y2={bottom}\n />\n {frontDrawn !== undefined && (\n <clipPath id={clipId}>\n <rect\n x={left}\n y={0}\n width={(right - left) * frontDrawn}\n height={height}\n />\n </clipPath>\n )}\n {front.length > 1 && (\n <polyline\n className=\"aegis-pareto__front\"\n clipPath={frontDrawn === undefined ? undefined : `url(#${clipId})`}\n points={front\n .map(\n (point) =>\n `${sx(point.x).toString()},${sy(point.y).toString()}`,\n )\n .join(' ')}\n />\n )}\n {points.map((point, index) => (\n <circle\n key={point.key}\n className={[\n 'aegis-pareto__point',\n fadeDominated && !frontKeys.has(point.key)\n ? 'aegis-pareto__point--dominated'\n : '',\n dimmed(point.key) ? 'aegis-pareto__point--dimmed' : '',\n onSelect ? 'aegis-pareto__point--interactive' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n style={\n {\n fill:\n point.color === undefined\n ? undefined\n : chartColorValue(point.color),\n '--aegis-pareto-index': index,\n '--aegis-pareto-point-progress':\n progress === undefined\n ? 1\n : staggeredProgress(\n progress,\n geometry.order.get(point.key) ?? index,\n points.length + 1,\n ),\n } as CSSProperties\n }\n cx={sx(point.x)}\n cy={sy(point.y)}\n r={POINT_RADIUS}\n role={onSelect ? 'button' : undefined}\n tabIndex={onSelect ? 0 : undefined}\n aria-label={onSelect ? point.label : undefined}\n onClick={\n onSelect\n ? () => {\n onSelect(point.key);\n }\n : undefined\n }\n onKeyDown={\n onSelect\n ? (event) => {\n selectOnKey(event, point.key);\n }\n : undefined\n }\n >\n <title>{point.label}</title>\n </circle>\n ))}\n {points.map((point) => {\n const box = labelBoxes.get(point.key);\n return box === undefined ? null : (\n <text\n key={`label-${point.key}`}\n className={[\n 'aegis-pareto__point-label',\n dimmed(point.key) ? 'aegis-pareto__point-label--dimmed' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n style={\n labels === 'all'\n ? ({\n '--aegis-pareto-front-progress':\n progress === undefined\n ? 1\n : staggeredProgress(\n progress,\n geometry.order.get(point.key) ?? 0,\n points.length + 1,\n ),\n } as CSSProperties)\n : undefined\n }\n x={box.x}\n y={box.y}\n textAnchor={box.anchor}\n >\n {point.label}\n </text>\n );\n })}\n {geometry.xLabels.map((value, index) => (\n <text\n key={`x-${value.toString()}`}\n className=\"aegis-pareto__tick\"\n x={sx(value)}\n y={bottom + LABEL_GAP * 2}\n textAnchor={\n index === geometry.xLabels.length - 1 && sx(value) >= right - 1\n ? 'end'\n : 'middle'\n }\n >\n {formatX(value)}\n </text>\n ))}\n {geometry.yLabels.map((value) => (\n <text\n key={`y-${value.toString()}`}\n className=\"aegis-pareto__tick\"\n x={left - LABEL_GAP}\n y={sy(value)}\n textAnchor=\"end\"\n dominantBaseline=\"middle\"\n >\n {formatY(value)}\n </text>\n ))}\n <text\n className=\"aegis-pareto__axis-label\"\n x={right}\n y={height - LABEL_GAP}\n textAnchor=\"end\"\n >\n {xLabel}\n </text>\n <text\n className=\"aegis-pareto__axis-label\"\n x={left - LABEL_GAP}\n y={top - LABEL_GAP * 2}\n textAnchor=\"start\"\n >\n {yLabel}\n </text>\n </svg>\n {legendItems.length > 0 ? (\n <ChartLegend\n className=\"aegis-pareto__legend\"\n shape=\"dot\"\n items={legendItems}\n />\n ) : null}\n </div>\n );\n}\n"],"names":["MAX_HEIGHT","MIN_HEIGHT","PAD_LEFT","PAD_RIGHT","PAD_TOP","PAD_BOTTOM","POINT_RADIUS","LABEL_GAP","GRID_STEPS","LABEL_CHAR","LABEL_WIDE_CHAR","LABEL_LINE","ALL_LABELS_MIN_WIDTH","better","a","b","direction","labelWidth","text","sum","char","placeLabels","labelled","allPoints","bounds","placed","result","reach","point","w","candidates","box","candidate","l","onPlot","r","t","clear","other","chosen","ParetoChart","points","xLabel","yLabel","xDirection","yDirection","formatX","formatY","xScale","xDomain","yDomain","xTicks","yTicks","labels","fadeDominated","highlightKeys","maxHeight","onSelect","legend","empty","emptyTitle","emptyDescription","progress","frontProgress","className","strings","useStrings","clipId","useId","wrapRef","useRef","width","useElementWidth","cls","geometry","useMemo","height","xValues","logLo","logHi","xLo","xHi","zeroAnchoredDomain","yLo","yHi","scaleX","value","left","right","top","bottom","sx","sy","front","steps","_","i","order","rank","jsx","EmptyState","frontKeys","highlighted","dimmed","key","showAllLabels","labelBoxes","legendItems","item","frontDrawn","staggeredProgress","selectOnKey","event","jsxs","y","x","index","chartColorValue","ChartLegend"],"mappings":"wWAqGMA,GAAa,IACbC,GAAa,IACbC,GAAW,GACXC,GAAY,GACZC,GAAU,GACVC,GAAa,GACbC,EAAe,EACfC,EAAY,EACZC,GAAa,EAGbC,GAAa,IACbC,GAAkB,GAClBC,EAAa,GACbC,GAAuB,IAI7B,SAASC,EAAOC,EAAWC,EAAWC,EAA+B,CACnE,OAAOA,IAAc,QAAUF,EAAIC,EAAID,EAAIC,CAC7C,CAQA,SAASE,GAAWC,EAAsB,CACxC,MAAO,CAAC,GAAGA,CAAI,EAAE,OACf,CAACC,EAAKC,IACJD,IAAQC,EAAK,YAAY,CAAC,GAAK,GAAK,IAAMV,GAAkBD,IAC9D,CAAA,CAEJ,CAMA,SAASY,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AH,EAAM,KAAA,EAzBF,SAASA,EAAM,GAAG,EAAA,CA4B7B,CAAC,EACA8C,EAAS,QAAQ,IAAI,CAACY,EAAO8B,IAC5BjB,EAAAA,IAAC,OAAA,CAEC,UAAU,qBACV,EAAGR,EAAGL,CAAK,EACX,EAAGI,EAASnF,EAAY,EACxB,WACE6G,IAAU1C,EAAS,QAAQ,OAAS,GAAKiB,EAAGL,CAAK,GAAKE,EAAQ,EAC1D,MACA,SAGL,WAAQF,CAAK,CAAA,EAVT,KAAKA,EAAM,UAAU,EAAA,CAY7B,EACAZ,EAAS,QAAQ,IAAKY,GACrBa,EAAAA,IAAC,OAAA,CAEC,UAAU,qBACV,EAAGZ,EAAOhF,EACV,EAAGqF,EAAGN,CAAK,EACX,WAAW,MACX,iBAAiB,SAEhB,WAAQA,CAAK,CAAA,EAPT,KAAKA,EAAM,UAAU,EAAA,CAS7B,EACDa,EAAAA,IAAC,OAAA,CACC,UAAU,2BACV,EAAGX,EACH,EAAGZ,EAASrE,EACZ,WAAW,MAEV,SAAAmC,CAAA,CAAA,EAEHyD,EAAAA,IAAC,OAAA,CACC,UAAU,2BACV,EAAGZ,EAAOhF,EACV,EAAGkF,EAAMlF,EAAY,EACrB,WAAW,QAEV,SAAAoC,CAAA,CAAA,CACH,CAAA,CAAA,EAEDgE,GAAY,OAAS,EACpBR,EAAAA,IAACmB,GAAAA,YAAA,CACC,UAAU,uBACV,MAAM,MACN,MAAOX,EAAA,CAAA,EAEP,IAAA,EACN,CAEJ"}
|
|
1
|
+
{"version":3,"file":"ParetoChart.cjs","sources":["../../../src/components/ui/ParetoChart.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type ReactNode,\n useId,\n useMemo,\n useRef,\n} from 'react';\n\nimport { useElementWidth } from '../../hooks/useElementWidth';\nimport {\n type ChartColor,\n chartColorValue,\n staggeredProgress,\n zeroAnchoredDomain,\n} from '../../lib/chart';\nimport { useStrings } from '../../locale';\nimport { ChartLegend } from './ChartLegend';\nimport { EmptyState } from './EmptyState';\nimport './ParetoChart.css';\n\nexport interface ParetoPoint {\n key: string;\n label: string;\n x: number;\n y: number;\n /** Point fill, e.g. `cat-2` or a series token, to match the series elsewhere. */\n color?: ChartColor;\n}\n\n/** One series in the legend under the plot, e.g. a model and its colour. */\nexport interface ParetoLegendItem {\n key: string;\n label: ReactNode;\n /** Swatch fill; the same value its points use. */\n color?: ChartColor;\n}\n\ninterface ParetoChartProps {\n points: ParetoPoint[];\n xLabel: string;\n yLabel: string;\n /** Which direction counts as better on each axis. */\n xDirection?: 'lower' | 'higher';\n yDirection?: 'lower' | 'higher';\n /** Formats the labels of each axis. */\n formatX?: (value: number) => string;\n formatY?: (value: number) => string;\n /**\n * `log` spaces the horizontal axis by ratio, e.g. for a cost that spans\n * orders of magnitude; its values must be above 0. Defaults to `linear`.\n */\n xScale?: 'linear' | 'log';\n /** The ends of each axis. Defaults to from 0, or the data's own range on a log axis. */\n xDomain?: [number, number];\n yDomain?: [number, number];\n /**\n * The labelled gridlines of each axis. Defaults to plain gridlines with\n * labels at the two ends.\n */\n xTicks?: number[];\n yTicks?: number[];\n /**\n * Which points carry their name. `front` names the frontier; `all` names\n * every point, so the chart needs no legend. A plot too narrow for them\n * names the frontier and `highlightKeys` and lists every point under it.\n * Defaults to `front`.\n */\n labels?: 'front' | 'all';\n /** Fades the points off the frontier. Defaults to true. */\n fadeDominated?: boolean;\n /** Fades every other point, to pick out the ones a finding is about. */\n highlightKeys?: string[];\n /** The tallest the plot grows. */\n maxHeight?: number;\n onSelect?: (key: string) => void;\n /** Series swatches with labels, listed under the plot. */\n legend?: ParetoLegendItem[];\n /**\n * Shown in place of the plot, at its minimum height, while there are no\n * points — e.g. an EmptyState with an icon asking for both axes. Replaces\n * the default empty state built from `emptyTitle`.\n */\n empty?: ReactNode;\n emptyTitle?: string;\n emptyDescription?: string;\n /**\n * How far the chart is drawn, 0 to 1, for a chart that draws as its\n * section scrolls in (`useScrollProgress`): points fade in from left to\n * right, then the frontier. Omitted, they fade in once on mount.\n */\n progress?: number;\n /**\n * How far the frontier is traced, 0 to 1, for a host that draws it apart\n * from the points, such as one step of a scrolling story.\n */\n frontProgress?: number;\n className?: string;\n}\n\n// The SVG is drawn at its measured CSS width, so these are true px.\nconst MAX_HEIGHT = 320;\nconst MIN_HEIGHT = 220;\nconst PAD_LEFT = 56;\nconst PAD_RIGHT = 16;\nconst PAD_TOP = 28;\nconst PAD_BOTTOM = 44;\nconst POINT_RADIUS = 5;\nconst LABEL_GAP = 8;\nconst GRID_STEPS = 4;\n// Estimates for placing labels: --fs-11 text, and the width below which\n// `labels='all'` would crowd the plot.\nconst LABEL_CHAR = 6.2;\nconst LABEL_WIDE_CHAR = 11;\nconst LABEL_LINE = 14;\n/** The part of a label's line below its baseline. */\nconst LABEL_DESCENT = LABEL_LINE / 4;\nconst ALL_LABELS_MIN_WIDTH = 520;\n\ntype Direction = 'lower' | 'higher';\n\nfunction better(a: number, b: number, direction: Direction): boolean {\n return direction === 'lower' ? a < b : a > b;\n}\n\ninterface LabelBox {\n x: number;\n y: number;\n anchor: 'start' | 'end';\n}\n\nfunction labelWidth(text: string): number {\n return [...text].reduce(\n (sum, char) =>\n sum + ((char.codePointAt(0) ?? 0) > 255 ? LABEL_WIDE_CHAR : LABEL_CHAR),\n 0,\n );\n}\n\ninterface Box {\n l: number;\n r: number;\n t: number;\n b: number;\n}\n\ntype Segment = [{ x: number; y: number }, { x: number; y: number }];\n\n/** Whether a straight segment crosses a box (Liang–Barsky clipping). */\nfunction segmentCrosses([a, b]: Segment, box: Box): boolean {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n let enter = 0;\n let exit = 1;\n for (const [p, q] of [\n [-dx, a.x - box.l],\n [dx, box.r - a.x],\n [-dy, a.y - box.t],\n [dy, box.b - a.y],\n ]) {\n if (p === 0) {\n if (q < 0) {\n return false;\n }\n } else if (p < 0) {\n enter = Math.max(enter, q / p);\n } else {\n exit = Math.min(exit, q / p);\n }\n }\n return enter <= exit;\n}\n\n/**\n * Puts each label beside its point on the first side where it stays on the\n * plot and clear of the labels already placed, of the `reserved` boxes, of\n * the other points and of the frontier. The frontier runs through the\n * points it joins, so the sides across it, diagonally off the point, are\n * candidates too.\n */\nfunction placeLabels(\n labelled: Array<{ key: string; label: string; x: number; y: number }>,\n allPoints: Array<{ key: string; x: number; y: number }>,\n frontier: Segment[],\n reserved: Box[],\n bounds: { left: number; right: number; top: number; bottom: number },\n): Map<string, LabelBox> {\n const placed: Box[] = [...reserved];\n const result = new Map<string, LabelBox>();\n const reach = POINT_RADIUS + LABEL_GAP / 2;\n for (const point of labelled) {\n const w = labelWidth(point.label);\n const candidates: LabelBox[] = [\n { x: point.x + reach, y: point.y + LABEL_LINE / 3, anchor: 'start' },\n { x: point.x - reach, y: point.y + LABEL_LINE / 3, anchor: 'end' },\n { x: point.x - w / 2, y: point.y - reach, anchor: 'start' },\n { x: point.x - w / 2, y: point.y + reach + LABEL_LINE, anchor: 'start' },\n { x: point.x - reach, y: point.y - reach, anchor: 'end' },\n { x: point.x + reach, y: point.y + reach + LABEL_LINE, anchor: 'start' },\n { x: point.x + reach, y: point.y - reach, anchor: 'start' },\n { x: point.x - reach, y: point.y + reach + LABEL_LINE, anchor: 'end' },\n ];\n const box = (candidate: LabelBox): Box => {\n const l = candidate.anchor === 'end' ? candidate.x - w : candidate.x;\n return {\n l,\n r: l + w,\n t: candidate.y - LABEL_LINE + LABEL_DESCENT,\n b: candidate.y + LABEL_DESCENT,\n };\n };\n const onPlot = (candidate: LabelBox): boolean => {\n const { l, r, t, b } = box(candidate);\n return (\n l >= bounds.left &&\n r <= bounds.right &&\n t >= bounds.top &&\n b <= bounds.bottom\n );\n };\n const clearOfMarks = (candidate: LabelBox): boolean => {\n const { l, r, t, b } = box(candidate);\n return (\n onPlot(candidate) &&\n placed.every(\n (other) => r < other.l || l > other.r || b < other.t || t > other.b,\n ) &&\n allPoints.every(\n (other) =>\n other.key === point.key ||\n other.x + POINT_RADIUS < l ||\n other.x - POINT_RADIUS > r ||\n other.y + POINT_RADIUS < t ||\n other.y - POINT_RADIUS > b,\n )\n );\n };\n const clear = (candidate: LabelBox): boolean =>\n clearOfMarks(candidate) &&\n frontier.every((segment) => !segmentCrosses(segment, box(candidate)));\n // With no side free the label still stays on the plot, towards its middle.\n const chosen =\n candidates.find(clear) ??\n candidates.find(clearOfMarks) ??\n candidates.find(onPlot) ??\n candidates[point.x > (bounds.left + bounds.right) / 2 ? 1 : 0];\n placed.push(box(chosen));\n result.set(point.key, chosen);\n }\n return result;\n}\n\nexport function ParetoChart({\n points,\n xLabel,\n yLabel,\n xDirection = 'lower',\n yDirection = 'higher',\n formatX = String,\n formatY = String,\n xScale = 'linear',\n xDomain,\n yDomain,\n xTicks,\n yTicks,\n labels = 'front',\n fadeDominated = true,\n highlightKeys,\n maxHeight = MAX_HEIGHT,\n onSelect,\n legend,\n empty,\n emptyTitle,\n emptyDescription,\n progress,\n frontProgress,\n className,\n}: ParetoChartProps) {\n const strings = useStrings();\n const clipId = useId();\n const wrapRef = useRef<HTMLDivElement>(null);\n const width = useElementWidth(wrapRef);\n const cls = [\n 'aegis-pareto',\n progress === undefined && frontProgress === undefined\n ? ''\n : 'aegis-pareto--scroll',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const geometry = useMemo(() => {\n if (points.length === 0 || width === 0) {\n return null;\n }\n const height = Math.round(\n Math.min(maxHeight, Math.max(MIN_HEIGHT, width / 2)),\n );\n const xValues = points.map((point) => point.x);\n const logLo = Math.min(...xValues);\n const logHi = Math.max(...xValues);\n const [xLo, xHi] =\n xDomain ??\n (xScale === 'log'\n ? // One value has no span to divide, so it sits mid-axis.\n ([\n logHi > logLo ? logLo : logLo / 2,\n logHi > logLo ? logHi : logHi * 2,\n ] as const)\n : zeroAnchoredDomain(xValues));\n const [yLo, yHi] =\n yDomain ?? zeroAnchoredDomain(points.map((point) => point.y));\n const scaleX = xScale === 'log' ? Math.log10 : (value: number) => value;\n const left = PAD_LEFT;\n const right = width - PAD_RIGHT;\n const top = PAD_TOP;\n const bottom = height - PAD_BOTTOM;\n const sx = (value: number): number =>\n left +\n ((scaleX(value) - scaleX(xLo)) / (scaleX(xHi) - scaleX(xLo))) *\n (right - left);\n const sy = (value: number): number =>\n bottom - ((value - yLo) / (yHi - yLo)) * (bottom - top);\n const front = points\n .filter(\n (candidate) =>\n !points.some(\n (other) =>\n other.key !== candidate.key &&\n (better(other.x, candidate.x, xDirection) ||\n other.x === candidate.x) &&\n (better(other.y, candidate.y, yDirection) ||\n other.y === candidate.y) &&\n (better(other.x, candidate.x, xDirection) ||\n better(other.y, candidate.y, yDirection)),\n ),\n )\n .sort((a, b) => a.x - b.x);\n const steps = Array.from(\n { length: GRID_STEPS },\n (_, i) => (i + 1) / GRID_STEPS,\n );\n // Points draw in from left to right; the frontier comes last.\n const order = new Map(\n [...points]\n .sort((a, b) => sx(a.x) - sx(b.x))\n .map((point, rank) => [point.key, rank]),\n );\n return {\n height,\n order,\n left,\n right,\n top,\n bottom,\n sx,\n sy,\n front,\n frontKeys: new Set(front.map((point) => point.key)),\n // Even shares of the plot, which on a log axis are even ratios.\n gridX: xTicks?.map(sx) ?? steps.map((t) => left + (right - left) * t),\n gridY: yTicks?.map(sy) ?? steps.map((t) => sy(yLo + (yHi - yLo) * t)),\n xLabels: xTicks ?? [xLo, xHi],\n yLabels: yTicks ?? [yLo, yHi],\n };\n }, [\n points,\n width,\n xDirection,\n yDirection,\n xScale,\n xDomain,\n yDomain,\n xTicks,\n yTicks,\n maxHeight,\n ]);\n\n if (points.length === 0) {\n return (\n <div ref={wrapRef} className={cls}>\n {empty === undefined ? (\n <EmptyState\n title={emptyTitle ?? strings.paretoEmptyTitle}\n description={emptyDescription}\n />\n ) : (\n <div\n className=\"aegis-pareto__empty\"\n style={\n {\n '--aegis-pareto-min-height': `${MIN_HEIGHT.toString()}px`,\n } as CSSProperties\n }\n >\n {empty}\n </div>\n )}\n </div>\n );\n }\n\n if (!geometry) {\n return <div ref={wrapRef} className={cls} />;\n }\n\n const { height, left, right, top, bottom, sx, sy, front, frontKeys } =\n geometry;\n const highlighted =\n highlightKeys === undefined ? null : new Set(highlightKeys);\n const dimmed = (key: string): boolean =>\n highlighted !== null && !highlighted.has(key);\n const yTitleBaseline = top - LABEL_GAP * 2;\n const showAllLabels = labels === 'all' && width >= ALL_LABELS_MIN_WIDTH;\n const labelBoxes = placeLabels(\n points\n .filter(\n (point) =>\n showAllLabels ||\n frontKeys.has(point.key) ||\n (highlighted?.has(point.key) ?? false),\n )\n .map((point) => ({\n key: point.key,\n label: point.label,\n x: sx(point.x),\n y: sy(point.y),\n })),\n points.map((point) => ({\n key: point.key,\n x: sx(point.x),\n y: sy(point.y),\n })),\n front.slice(1).map((point, index): Segment => {\n const previous = front[index];\n return [\n { x: sx(previous.x), y: sy(previous.y) },\n { x: sx(point.x), y: sy(point.y) },\n ];\n }),\n // The y axis's title, above the plot.\n [\n {\n l: left - LABEL_GAP,\n r: left - LABEL_GAP + labelWidth(yLabel),\n t: yTitleBaseline - LABEL_LINE + LABEL_DESCENT,\n b: yTitleBaseline + LABEL_DESCENT,\n },\n ],\n // A label may run up into the space above the plot.\n { left, right, top: 0, bottom },\n );\n // A plot too narrow to name every point names them under it instead, so\n // none is left to a tooltip a phone cannot show.\n const legendItems =\n legend?.map((item) => ({\n key: item.key,\n label: item.label,\n color: item.color ?? ('var(--bg-inverted)' as const),\n })) ??\n (labels === 'all' && !showAllLabels\n ? points.map((point) => ({\n key: point.key,\n label: point.label,\n color: point.color ?? ('var(--bg-inverted)' as const),\n }))\n : []);\n const frontDrawn =\n frontProgress ??\n (progress === undefined\n ? undefined\n : staggeredProgress(progress, points.length, points.length + 1));\n const selectOnKey = (event: KeyboardEvent<SVGCircleElement>, key: string) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n onSelect?.(key);\n }\n };\n\n return (\n <div ref={wrapRef} className={cls}>\n <svg\n className=\"aegis-pareto__svg\"\n width={width}\n height={height}\n viewBox={`0 0 ${width.toString()} ${height.toString()}`}\n role={onSelect ? 'group' : 'img'}\n aria-label={strings.paretoChartLabel(xLabel, yLabel)}\n style={\n {\n '--aegis-pareto-count': points.length,\n ...(frontDrawn === undefined\n ? {}\n : { '--aegis-pareto-front-progress': frontDrawn }),\n } as CSSProperties\n }\n >\n {geometry.gridY.map((y) => (\n <line\n key={`gy-${y.toString()}`}\n className=\"aegis-pareto__grid\"\n x1={left}\n y1={y}\n x2={right}\n y2={y}\n />\n ))}\n {geometry.gridX.map((x) => (\n <line\n key={`gx-${x.toString()}`}\n className=\"aegis-pareto__grid\"\n x1={x}\n y1={top}\n x2={x}\n y2={bottom}\n />\n ))}\n <line\n className=\"aegis-pareto__axis\"\n x1={left}\n y1={bottom}\n x2={right}\n y2={bottom}\n />\n <line\n className=\"aegis-pareto__axis\"\n x1={left}\n y1={top}\n x2={left}\n y2={bottom}\n />\n {frontDrawn !== undefined && (\n <clipPath id={clipId}>\n <rect\n x={left}\n y={0}\n width={(right - left) * frontDrawn}\n height={height}\n />\n </clipPath>\n )}\n {front.length > 1 && (\n <polyline\n className=\"aegis-pareto__front\"\n clipPath={frontDrawn === undefined ? undefined : `url(#${clipId})`}\n points={front\n .map(\n (point) =>\n `${sx(point.x).toString()},${sy(point.y).toString()}`,\n )\n .join(' ')}\n />\n )}\n {points.map((point, index) => (\n <circle\n key={point.key}\n className={[\n 'aegis-pareto__point',\n fadeDominated && !frontKeys.has(point.key)\n ? 'aegis-pareto__point--dominated'\n : '',\n dimmed(point.key) ? 'aegis-pareto__point--dimmed' : '',\n onSelect ? 'aegis-pareto__point--interactive' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n style={\n {\n fill:\n point.color === undefined\n ? undefined\n : chartColorValue(point.color),\n '--aegis-pareto-index': index,\n '--aegis-pareto-point-progress':\n progress === undefined\n ? 1\n : staggeredProgress(\n progress,\n geometry.order.get(point.key) ?? index,\n points.length + 1,\n ),\n } as CSSProperties\n }\n cx={sx(point.x)}\n cy={sy(point.y)}\n r={POINT_RADIUS}\n role={onSelect ? 'button' : undefined}\n tabIndex={onSelect ? 0 : undefined}\n aria-label={onSelect ? point.label : undefined}\n onClick={\n onSelect\n ? () => {\n onSelect(point.key);\n }\n : undefined\n }\n onKeyDown={\n onSelect\n ? (event) => {\n selectOnKey(event, point.key);\n }\n : undefined\n }\n >\n <title>{point.label}</title>\n </circle>\n ))}\n {points.map((point) => {\n const box = labelBoxes.get(point.key);\n return box === undefined ? null : (\n <text\n key={`label-${point.key}`}\n className={[\n 'aegis-pareto__point-label',\n dimmed(point.key) ? 'aegis-pareto__point-label--dimmed' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n style={\n labels === 'all'\n ? ({\n '--aegis-pareto-front-progress':\n progress === undefined\n ? 1\n : staggeredProgress(\n progress,\n geometry.order.get(point.key) ?? 0,\n points.length + 1,\n ),\n } as CSSProperties)\n : undefined\n }\n x={box.x}\n y={box.y}\n textAnchor={box.anchor}\n >\n {point.label}\n </text>\n );\n })}\n {geometry.xLabels.map((value, index) => (\n <text\n key={`x-${value.toString()}`}\n className=\"aegis-pareto__tick\"\n x={sx(value)}\n y={bottom + LABEL_GAP * 2}\n textAnchor={\n index === geometry.xLabels.length - 1 && sx(value) >= right - 1\n ? 'end'\n : 'middle'\n }\n >\n {formatX(value)}\n </text>\n ))}\n {geometry.yLabels.map((value) => (\n <text\n key={`y-${value.toString()}`}\n className=\"aegis-pareto__tick\"\n x={left - LABEL_GAP}\n y={sy(value)}\n textAnchor=\"end\"\n dominantBaseline=\"middle\"\n >\n {formatY(value)}\n </text>\n ))}\n <text\n className=\"aegis-pareto__axis-label\"\n x={right}\n y={height - LABEL_GAP}\n textAnchor=\"end\"\n >\n {xLabel}\n </text>\n <text\n className=\"aegis-pareto__axis-label\"\n x={left - LABEL_GAP}\n y={yTitleBaseline}\n textAnchor=\"start\"\n >\n {yLabel}\n </text>\n </svg>\n {legendItems.length > 0 ? (\n <ChartLegend\n className=\"aegis-pareto__legend\"\n shape=\"dot\"\n items={legendItems}\n />\n ) : null}\n </div>\n );\n}\n"],"names":["MAX_HEIGHT","MIN_HEIGHT","PAD_LEFT","PAD_RIGHT","PAD_TOP","PAD_BOTTOM","POINT_RADIUS","LABEL_GAP","GRID_STEPS","LABEL_CHAR","LABEL_WIDE_CHAR","LABEL_LINE","LABEL_DESCENT","ALL_LABELS_MIN_WIDTH","better","a","b","direction","labelWidth","text","sum","char","segmentCrosses","box","dx","dy","enter","exit","p","q","placeLabels","labelled","allPoints","frontier","reserved","bounds","placed","result","reach","point","w","candidates","candidate","l","onPlot","r","t","clearOfMarks","other","clear","segment","chosen","ParetoChart","points","xLabel","yLabel","xDirection","yDirection","formatX","formatY","xScale","xDomain","yDomain","xTicks","yTicks","labels","fadeDominated","highlightKeys","maxHeight","onSelect","legend","empty","emptyTitle","emptyDescription","progress","frontProgress","className","strings","useStrings","clipId","useId","wrapRef","useRef","width","useElementWidth","cls","geometry","useMemo","height","xValues","logLo","logHi","xLo","xHi","zeroAnchoredDomain","yLo","yHi","scaleX","value","left","right","top","bottom","sx","sy","front","steps","_","order","rank","jsx","EmptyState","frontKeys","highlighted","dimmed","key","yTitleBaseline","showAllLabels","labelBoxes","index","previous","legendItems","item","frontDrawn","staggeredProgress","selectOnKey","event","jsxs","y","x","chartColorValue","ChartLegend"],"mappings":"wWAqGMA,GAAa,IACbC,GAAa,IACbC,GAAW,GACXC,GAAY,GACZC,GAAU,GACVC,GAAa,GACbC,EAAe,EACfC,EAAY,EACZC,GAAa,EAGbC,GAAa,IACbC,GAAkB,GAClBC,EAAa,GAEbC,EAAgBD,EAAa,EAC7BE,GAAuB,IAI7B,SAASC,EAAOC,EAAWC,EAAWC,EAA+B,CACnE,OAAOA,IAAc,QAAUF,EAAIC,EAAID,EAAIC,CAC7C,CAQA,SAASE,GAAWC,EAAsB,CACxC,MAAO,CAAC,GAAGA,CAAI,EAAE,OACf,CAACC,EAAKC,IACJD,IAAQC,EAAK,YAAY,C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