Loading files
2bbf844baThis file is pinned to the selected release. Download the original to open it in your design tool.
import{Bn as e,C as t,E as n,Er as r,Hn as i,S as a,Sr as o,T as s,Tr as c,i as l,kr as u,lr as d,n as f,r as p,ur as m,w as h}from"./globals-CtHxcH0F.js";import{t as g}from"./trash-2-4CTGvzn4.js";var _=c(`clipboard`,[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`,key:`116196`}]]),v=u(r(),1),y=m(),b={trace:`text-console-foreground/65`,info:`text-console-foreground`,warning:`text-warning`,error:`text-red-300`};function x({entries:r,onClear:c,title:u=`ログ`,emptyMessage:m=`ログはまだありません。`,className:x,viewportClassName:S}){let{t:C}=d(),w=(0,v.useRef)(null),[T,E]=(0,v.useState)(`all`),[D,O]=(0,v.useState)(`all`),[k,A]=(0,v.useState)(!0),[j,M]=(0,v.useState)(!1),N=(0,v.useMemo)(()=>Array.from(new Set(r.flatMap(e=>e.source?[e.source]:[]))),[r]),P=(0,v.useMemo)(()=>r.filter(e=>(T===`all`||e.level===T)&&(D===`all`||e.source===D)),[r,T,D]);(0,v.useEffect)(()=>{k&&w.current&&(w.current.scrollTop=w.current.scrollHeight)},[k,P]);let F=async()=>{await navigator.clipboard.writeText(P.map(e=>e.message).join(`
`)),M(!0),window.setTimeout(()=>M(!1),1200)};return(0,y.jsxs)(`section`,{className:i(`overflow-hidden rounded-xl border bg-card`,x),"aria-label":C(u),children:[(0,y.jsxs)(`header`,{className:`grid grid-cols-[minmax(0,1fr)_auto] items-center gap-2 border-b px-3 py-2`,children:[(0,y.jsx)(`h2`,{className:`min-w-0 truncate text-sm font-semibold`,children:C(u)}),(0,y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,y.jsxs)(a,{value:T,onValueChange:e=>e&&E(e),children:[(0,y.jsx)(s,{className:`w-28`,size:`sm`,"aria-label":C(`ログレベル`),children:(0,y.jsx)(n,{})}),(0,y.jsxs)(t,{children:[(0,y.jsx)(h,{value:`all`,children:C(`すべて`)}),(0,y.jsx)(h,{value:`trace`,children:`trace`}),(0,y.jsx)(h,{value:`info`,children:`info`}),(0,y.jsx)(h,{value:`warning`,children:`warning`}),(0,y.jsx)(h,{value:`error`,children:`error`})]})]}),N.length>1&&(0,y.jsxs)(a,{value:D,onValueChange:e=>e&&O(e),children:[(0,y.jsx)(s,{className:`w-28`,size:`sm`,"aria-label":C(`ログの生成元`),children:(0,y.jsx)(n,{})}),(0,y.jsxs)(t,{children:[(0,y.jsx)(h,{value:`all`,children:C(`すべて`)}),N.map(e=>(0,y.jsx)(h,{value:e,children:e},e))]})]}),(0,y.jsxs)(f,{children:[(0,y.jsx)(l,{render:(0,y.jsx)(e,{variant:`ghost`,size:`icon-sm`,onClick:()=>void F(),disabled:P.length===0,"aria-label":C(`ログをコピー`)}),children:j?(0,y.jsx)(o,{}):(0,y.jsx)(_,{})}),(0,y.jsx)(p,{children:C(j?`コピーしました`:`ログをコピー`)})]}),c&&(0,y.jsxs)(f,{children:[(0,y.jsx)(l,{render:(0,y.jsx)(e,{variant:`ghost`,size:`icon-sm`,onClick:c,disabled:r.length===0,"aria-label":C(`ログを消去`)}),children:(0,y.jsx)(g,{})}),(0,y.jsx)(p,{children:C(`ログを消去`)})]})]})]}),(0,y.jsx)(`div`,{ref:w,role:`log`,"aria-live":`polite`,"aria-relevant":`additions`,className:i(`h-56 overflow-auto bg-console px-3 py-2 font-mono text-xs leading-5 text-console-foreground`,S),onScroll:e=>{let t=e.currentTarget;A(t.scrollHeight-t.scrollTop-t.clientHeight<12)},children:P.length===0?(0,y.jsx)(`p`,{className:`text-console-foreground/55`,children:C(m)}):P.map(e=>(0,y.jsxs)(`div`,{className:i(`grid grid-cols-[auto_auto_1fr] gap-2`,b[e.level]),children:[e.timestamp?(0,y.jsx)(`time`,{dateTime:new Date(e.timestamp).toISOString(),children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}):(0,y.jsx)(`span`,{}),(0,y.jsx)(`span`,{children:e.source?`[${e.source}]`:``}),(0,y.jsx)(`span`,{className:`whitespace-pre-wrap break-words`,children:e.message})]},e.id))})]})}function S(e=400){let[t,n]=(0,v.useState)([]),r=(0,v.useRef)(0),i=Number.isFinite(e)?Math.max(0,Math.floor(e)):0,a=i===0?[]:t.length>i?t.slice(-i):t;return(0,v.useEffect)(()=>{n(e=>i===0?e.length===0?e:[]:e.length>i?e.slice(-i):e)},[i]),{entries:a,append:(0,v.useCallback)((e,t=`info`,a)=>{if(i===0)return;let o={id:`${Date.now()}-${r.current++}`,timestamp:Date.now(),level:t,source:a,message:e};n(e=>[...e,o].slice(-i))},[i]),clear:(0,v.useCallback)(()=>n([]),[])}}export{x as n,_ as r,S as t};