@jacshuo/onyx 2.3.0 → 2.5.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.
@@ -1 +1,2 @@
1
- 'use strict';var react=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');function g(...e){return tailwindMerge.twMerge(clsx.clsx(e))}function Y({text:e="",mode:t="typewriter",speed:k=40,cursor:D=true,cursorChar:M="\u258B",thinking:T=false,streaming:o=false,delay:v=0,onComplete:d,as:A="span",className:B}){let[b,i]=react.useState(t==="instant"?e:""),[u,n]=react.useState(false),[I,s]=react.useState(t==="instant"),[R,l]=react.useState(false),p=react.useRef(0),h=react.useRef(d);h.current=d;let f=react.useRef(e);f.current=e,react.useEffect(()=>{if(t!=="typewriter")return;if(i(""),s(false),l(false),n(false),!e){s(true);return}let c=Math.max(10,1e3/k),r=0,a,C=()=>{n(true),a=setInterval(()=>{let P=f.current;r++,i(P.slice(0,r)),r>=P.length&&(clearInterval(a),n(false),s(true),h.current?.());},c);},E;return v>0?E=setTimeout(C,v):C(),()=>{clearTimeout(E),clearInterval(a);}},[e,t]),react.useEffect(()=>{if(t!=="stream")return;if(e.length===0){p.current=0,i(""),n(false),s(false),l(false);return}if(e.length<=p.current)return;let c=Math.max(10,1e3/k),r=p.current;n(true),s(false),l(false);let a=setInterval(()=>{r++,p.current=r,i(f.current.slice(0,r)),r>=f.current.length&&(clearInterval(a),n(false),h.current?.());},c);return ()=>clearInterval(a)},[e,t]),react.useEffect(()=>{t==="instant"&&(i(e),n(false),s(true));},[e,t]);let x=react.useRef(o);react.useEffect(()=>{let c=x.current;if(x.current=o,c&&!o&&!u&&t==="stream"){l(true);let r=setTimeout(()=>{l(false),s(true);},650);return ()=>clearTimeout(r)}},[o,u,t]);let N=D&&(T||u||R||t==="stream"&&o&&!I||t==="typewriter"&&!I),V=T?"tw-cursor--blink":u?"tw-cursor--solid":R?"tw-cursor--out":"tw-cursor--blink";return jsxRuntime.jsxs(A,{className:g(B),children:[T&&!b&&jsxRuntime.jsx("span",{"aria-hidden":"true",children:"\u200B"}),b,N&&jsxRuntime.jsx("span",{className:g("tw-cursor",V),"aria-hidden":"true",children:M})]})}exports.TypewriterText=Y;
1
+ 'use strict';var react=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),marked=require('marked'),jsxRuntime=require('react/jsx-runtime');function u(...r){return tailwindMerge.twMerge(clsx.clsx(r))}var j='<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="2" y1="2" x2="22" y2="22"/><path d="M10.41 10.41a2 2 0 1 1-2.83-2.83"/><line x1="13.5" y1="6" x2="18" y2="6"/><line x1="6" y1="2" x2="14" y2="10"/><path d="M4 6h1.5"/><path d="M2 18.5C2 19.9 3.1 21 4.5 21H16"/><rect x="2" y="2" width="20" height="20" rx="5" ry="5"/></svg>';function x(r){return r.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function J(r){return r.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi,"").replace(/\s+on[a-z][a-z0-9]*\s*=\s*(?:"[^"]*"|'[^']*'|[^\s/>]*)/gi,"").replace(/\b(href|src|action)\s*=\s*["']\s*(?:javascript|vbscript)\s*:[^"'>]*/gi,'$1="#"').replace(/\bhref\s*=\s*["']\s*data\s*:[^"'>]*/gi,'href="#"')}var F=new marked.Marked;F.use({renderer:{image({href:r,title:e,text:c}){let I=/^https?:\/\//i.test(r??"")?r:"",f=c?` alt="${x(c)}"`:' alt=""',p=e?` title="${x(e)}"`:"",i=x(c||"Image failed to load");return `<figure class="tw-rich-img-wrap"><img class="tw-rich-img" src="${x(I)}" loading="lazy"${f}${p} /><div class="tw-rich-img-error">`+j+`<span>${i}</span></div></figure>`}}});function B(r){let e=F.parse(r,{async:false});return J(e)}function K({text:r="",mode:e="typewriter",speed:c=40,cursor:I=true,cursorChar:f="\u258B",thinking:p=false,streaming:i=false,delay:C=0,onComplete:S,as:_="span",className:H,rich:E=false}){let[y,m]=react.useState(e==="instant"?r:""),[v,a]=react.useState(false),[L,s]=react.useState(e==="instant"),[A,h]=react.useState(false),z=react.useRef(null),k=react.useRef(0),R=react.useRef(S);R.current=S;let b=react.useRef(r);b.current=r,react.useEffect(()=>{if(e!=="typewriter")return;if(m(""),s(false),h(false),a(false),!r){s(true);return}let l=Math.max(10,1e3/c),t=0,o,n=()=>{a(true),o=setInterval(()=>{let D=b.current;t++,m(D.slice(0,t)),t>=D.length&&(clearInterval(o),a(false),s(true),R.current?.());},l);},d;return C>0?d=setTimeout(n,C):n(),()=>{clearTimeout(d),clearInterval(o);}},[r,e]),react.useEffect(()=>{if(e!=="stream")return;if(r.length===0){k.current=0,m(""),a(false),s(false),h(false);return}if(r.length<=k.current)return;let l=Math.max(10,1e3/c),t=k.current;a(true),s(false),h(false);let o=setInterval(()=>{t++,k.current=t,m(b.current.slice(0,t)),t>=b.current.length&&(clearInterval(o),a(false),R.current?.());},l);return ()=>clearInterval(o)},[r,e]),react.useEffect(()=>{e==="instant"&&(m(r),a(false),s(true));},[r,e]);let P=react.useRef(i);react.useEffect(()=>{let l=P.current;if(P.current=i,l&&!i&&!v&&e==="stream"){h(true);let t=setTimeout(()=>{h(false),s(true);},650);return ()=>clearTimeout(t)}},[i,v,e]),react.useEffect(()=>{if(!E||!z.current)return;let t=Array.from(z.current.querySelectorAll(".tw-rich-img")).map(o=>{let n=()=>{let d=o.closest(".tw-rich-img-wrap");d&&d.classList.add("tw-rich-img-wrap--error");};return o.addEventListener("error",n,{once:true}),{img:o,onError:n}});return ()=>{t.forEach(({img:o,onError:n})=>o.removeEventListener("error",n));}},[y,E]);let $=I&&(p||v||A||e==="stream"&&i&&!L||e==="typewriter"&&!L),q=p?"tw-cursor--blink":v?"tw-cursor--solid":A?"tw-cursor--out":"tw-cursor--blink",G=_;return E?jsxRuntime.jsxs("div",{role:"region",className:u(H),children:[jsxRuntime.jsx("div",{ref:z,className:"tw-rich-prose",dangerouslySetInnerHTML:{__html:B(y)}}),$&&jsxRuntime.jsx("span",{className:u("tw-cursor",q),"aria-hidden":"true",children:f})]}):jsxRuntime.jsxs(G,{className:u(H),children:[p&&!y&&jsxRuntime.jsx("span",{"aria-hidden":"true",children:"\u200B"}),y,$&&jsxRuntime.jsx("span",{className:u("tw-cursor",q),"aria-hidden":"true",children:f})]})}
2
+ exports.TypewriterText=K;
@@ -1 +1 @@
1
- @keyframes tw-blink{0%,to{opacity:1}50%{opacity:0}}@keyframes tw-cursor-out{0%{opacity:1}80%{opacity:1}to{opacity:0}}.tw-cursor{display:inline-block;line-height:1;vertical-align:baseline;user-select:none;transform:scaleY(.88);transform-origin:50% 90%;color:currentColor}.tw-cursor--blink{animation:tw-blink 1s step-end infinite}.tw-cursor--solid{opacity:1;animation:none}.tw-cursor--out{animation:tw-cursor-out .6s ease-out forwards;pointer-events:none}
1
+ @keyframes tw-blink{0%,to{opacity:1}50%{opacity:0}}@keyframes tw-cursor-out{0%{opacity:1}80%{opacity:1}to{opacity:0}}@keyframes tw-img-fade-in{0%{opacity:0;transform:translateY(5px)}to{opacity:1;transform:translateY(0)}}.tw-cursor{display:inline-block;line-height:1;vertical-align:baseline;user-select:none;transform:scaleY(.88);transform-origin:50% 90%;color:currentColor}.tw-cursor--blink{animation:tw-blink 1s step-end infinite}.tw-cursor--solid{opacity:1;animation:none}.tw-cursor--out{animation:tw-cursor-out .6s ease-out forwards;pointer-events:none}.tw-rich-prose{font-size:.875rem;line-height:1.75;color:var(--color-primary-900);word-break:break-word;overflow-wrap:break-word}.dark .tw-rich-prose{color:var(--color-primary-100)}.tw-rich-prose h1,.tw-rich-prose h2,.tw-rich-prose h3,.tw-rich-prose h4,.tw-rich-prose h5,.tw-rich-prose h6{font-weight:700;line-height:1.3;margin-top:1.25rem;margin-bottom:.375rem;color:var(--color-primary-950)}.dark .tw-rich-prose h1,.dark .tw-rich-prose h2,.dark .tw-rich-prose h3,.dark .tw-rich-prose h4,.dark .tw-rich-prose h5,.dark .tw-rich-prose h6{color:var(--color-primary-50)}.tw-rich-prose h1{font-size:1.5rem}.tw-rich-prose h2{font-size:1.25rem}.tw-rich-prose h3{font-size:1.125rem}.tw-rich-prose h4{font-size:1rem}.tw-rich-prose h5,.tw-rich-prose h6{font-size:.875rem}.tw-rich-prose p{margin-top:.625rem;margin-bottom:.625rem}.tw-rich-prose p:first-child{margin-top:0}.tw-rich-prose p:last-child{margin-bottom:0}.tw-rich-prose :not(pre)>code{background-color:var(--color-primary-100);color:var(--color-primary-700);padding:.1em .35em;border-radius:.25rem;font-size:.8125em;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}.dark .tw-rich-prose :not(pre)>code{background-color:var(--color-primary-800);color:var(--color-primary-200)}.tw-rich-prose pre{background-color:var(--color-primary-100);border-radius:.5rem;padding:.875rem 1rem;overflow-x:auto;margin:.75rem 0;font-size:.8125rem;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;line-height:1.6}.dark .tw-rich-prose pre{background-color:var(--color-primary-800)}.tw-rich-prose pre>code{background:none;padding:0;font-size:inherit;color:inherit;border-radius:0}.tw-rich-prose blockquote{border-left:3px solid var(--color-primary-400);padding:.375rem 0 .375rem 1rem;margin:.75rem 0;color:var(--color-primary-600);font-style:italic}.dark .tw-rich-prose blockquote{border-left-color:var(--color-primary-500);color:var(--color-primary-400)}.tw-rich-prose ul,.tw-rich-prose ol{padding-left:1.5rem;margin:.5rem 0}.tw-rich-prose ul{list-style:disc}.tw-rich-prose ol{list-style:decimal}.tw-rich-prose li{margin:.25rem 0}.tw-rich-prose li>ul,.tw-rich-prose li>ol{margin:.125rem 0 .125rem .25rem}.tw-rich-prose hr{border:none;border-top:1px solid var(--color-primary-200);margin:1.25rem 0}.dark .tw-rich-prose hr{border-top-color:var(--color-primary-700)}.tw-rich-prose a{color:var(--color-primary-600);text-decoration:underline;text-underline-offset:2px}.tw-rich-prose a:hover{color:var(--color-primary-800)}.dark .tw-rich-prose a{color:var(--color-primary-400)}.dark .tw-rich-prose a:hover{color:var(--color-primary-200)}.tw-rich-prose strong{font-weight:700}.tw-rich-prose em{font-style:italic}.tw-rich-img-wrap{display:block;margin:.875rem 0}.tw-rich-img{display:block;max-width:100%;border-radius:.5rem;box-shadow:0 2px 8px #0000001a;animation:tw-img-fade-in .4s ease-out both}.dark .tw-rich-img{box-shadow:0 2px 8px #0000004d}.tw-rich-img-error{display:none;flex-direction:column;align-items:center;justify-content:center;gap:.5rem;padding:1.5rem;border-radius:.5rem;background-color:var(--color-primary-100);color:var(--color-primary-400);font-size:.75rem;font-style:normal;text-align:center;min-height:80px;max-width:100%}.dark .tw-rich-img-error{background-color:var(--color-primary-800);color:var(--color-primary-500)}.tw-rich-img-wrap--error .tw-rich-img{display:none}.tw-rich-img-wrap--error .tw-rich-img-error{display:flex}
@@ -1 +1,2 @@
1
- import {useState,useRef,useEffect}from'react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsxs,jsx}from'react/jsx-runtime';function g(...e){return twMerge(clsx(e))}function Y({text:e="",mode:t="typewriter",speed:k=40,cursor:D=true,cursorChar:M="\u258B",thinking:T=false,streaming:o=false,delay:v=0,onComplete:d,as:A="span",className:B}){let[b,i]=useState(t==="instant"?e:""),[u,n]=useState(false),[I,s]=useState(t==="instant"),[R,l]=useState(false),p=useRef(0),h=useRef(d);h.current=d;let f=useRef(e);f.current=e,useEffect(()=>{if(t!=="typewriter")return;if(i(""),s(false),l(false),n(false),!e){s(true);return}let c=Math.max(10,1e3/k),r=0,a,C=()=>{n(true),a=setInterval(()=>{let P=f.current;r++,i(P.slice(0,r)),r>=P.length&&(clearInterval(a),n(false),s(true),h.current?.());},c);},E;return v>0?E=setTimeout(C,v):C(),()=>{clearTimeout(E),clearInterval(a);}},[e,t]),useEffect(()=>{if(t!=="stream")return;if(e.length===0){p.current=0,i(""),n(false),s(false),l(false);return}if(e.length<=p.current)return;let c=Math.max(10,1e3/k),r=p.current;n(true),s(false),l(false);let a=setInterval(()=>{r++,p.current=r,i(f.current.slice(0,r)),r>=f.current.length&&(clearInterval(a),n(false),h.current?.());},c);return ()=>clearInterval(a)},[e,t]),useEffect(()=>{t==="instant"&&(i(e),n(false),s(true));},[e,t]);let x=useRef(o);useEffect(()=>{let c=x.current;if(x.current=o,c&&!o&&!u&&t==="stream"){l(true);let r=setTimeout(()=>{l(false),s(true);},650);return ()=>clearTimeout(r)}},[o,u,t]);let N=D&&(T||u||R||t==="stream"&&o&&!I||t==="typewriter"&&!I),V=T?"tw-cursor--blink":u?"tw-cursor--solid":R?"tw-cursor--out":"tw-cursor--blink";return jsxs(A,{className:g(B),children:[T&&!b&&jsx("span",{"aria-hidden":"true",children:"\u200B"}),b,N&&jsx("span",{className:g("tw-cursor",V),"aria-hidden":"true",children:M})]})}export{Y as TypewriterText};
1
+ import {useState,useRef,useEffect}from'react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {Marked}from'marked';import {jsxs,jsx}from'react/jsx-runtime';function u(...r){return twMerge(clsx(r))}var j='<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="2" y1="2" x2="22" y2="22"/><path d="M10.41 10.41a2 2 0 1 1-2.83-2.83"/><line x1="13.5" y1="6" x2="18" y2="6"/><line x1="6" y1="2" x2="14" y2="10"/><path d="M4 6h1.5"/><path d="M2 18.5C2 19.9 3.1 21 4.5 21H16"/><rect x="2" y="2" width="20" height="20" rx="5" ry="5"/></svg>';function x(r){return r.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function J(r){return r.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi,"").replace(/\s+on[a-z][a-z0-9]*\s*=\s*(?:"[^"]*"|'[^']*'|[^\s/>]*)/gi,"").replace(/\b(href|src|action)\s*=\s*["']\s*(?:javascript|vbscript)\s*:[^"'>]*/gi,'$1="#"').replace(/\bhref\s*=\s*["']\s*data\s*:[^"'>]*/gi,'href="#"')}var F=new Marked;F.use({renderer:{image({href:r,title:e,text:c}){let I=/^https?:\/\//i.test(r??"")?r:"",f=c?` alt="${x(c)}"`:' alt=""',p=e?` title="${x(e)}"`:"",i=x(c||"Image failed to load");return `<figure class="tw-rich-img-wrap"><img class="tw-rich-img" src="${x(I)}" loading="lazy"${f}${p} /><div class="tw-rich-img-error">`+j+`<span>${i}</span></div></figure>`}}});function B(r){let e=F.parse(r,{async:false});return J(e)}function K({text:r="",mode:e="typewriter",speed:c=40,cursor:I=true,cursorChar:f="\u258B",thinking:p=false,streaming:i=false,delay:C=0,onComplete:S,as:_="span",className:H,rich:E=false}){let[y,m]=useState(e==="instant"?r:""),[v,a]=useState(false),[L,s]=useState(e==="instant"),[A,h]=useState(false),z=useRef(null),k=useRef(0),R=useRef(S);R.current=S;let b=useRef(r);b.current=r,useEffect(()=>{if(e!=="typewriter")return;if(m(""),s(false),h(false),a(false),!r){s(true);return}let l=Math.max(10,1e3/c),t=0,o,n=()=>{a(true),o=setInterval(()=>{let D=b.current;t++,m(D.slice(0,t)),t>=D.length&&(clearInterval(o),a(false),s(true),R.current?.());},l);},d;return C>0?d=setTimeout(n,C):n(),()=>{clearTimeout(d),clearInterval(o);}},[r,e]),useEffect(()=>{if(e!=="stream")return;if(r.length===0){k.current=0,m(""),a(false),s(false),h(false);return}if(r.length<=k.current)return;let l=Math.max(10,1e3/c),t=k.current;a(true),s(false),h(false);let o=setInterval(()=>{t++,k.current=t,m(b.current.slice(0,t)),t>=b.current.length&&(clearInterval(o),a(false),R.current?.());},l);return ()=>clearInterval(o)},[r,e]),useEffect(()=>{e==="instant"&&(m(r),a(false),s(true));},[r,e]);let P=useRef(i);useEffect(()=>{let l=P.current;if(P.current=i,l&&!i&&!v&&e==="stream"){h(true);let t=setTimeout(()=>{h(false),s(true);},650);return ()=>clearTimeout(t)}},[i,v,e]),useEffect(()=>{if(!E||!z.current)return;let t=Array.from(z.current.querySelectorAll(".tw-rich-img")).map(o=>{let n=()=>{let d=o.closest(".tw-rich-img-wrap");d&&d.classList.add("tw-rich-img-wrap--error");};return o.addEventListener("error",n,{once:true}),{img:o,onError:n}});return ()=>{t.forEach(({img:o,onError:n})=>o.removeEventListener("error",n));}},[y,E]);let $=I&&(p||v||A||e==="stream"&&i&&!L||e==="typewriter"&&!L),q=p?"tw-cursor--blink":v?"tw-cursor--solid":A?"tw-cursor--out":"tw-cursor--blink",G=_;return E?jsxs("div",{role:"region",className:u(H),children:[jsx("div",{ref:z,className:"tw-rich-prose",dangerouslySetInnerHTML:{__html:B(y)}}),$&&jsx("span",{className:u("tw-cursor",q),"aria-hidden":"true",children:f})]}):jsxs(G,{className:u(H),children:[p&&!y&&jsx("span",{"aria-hidden":"true",children:"\u200B"}),y,$&&jsx("span",{className:u("tw-cursor",q),"aria-hidden":"true",children:f})]})}
2
+ export{K as TypewriterText};