@jacshuo/onyx 2.5.0 → 2.7.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/Extras/TypewriterText.cjs +2 -2
- package/dist/Extras/TypewriterText.css +1 -1
- package/dist/Extras/TypewriterText.js +2 -2
- package/dist/Extras/index.cjs +10 -10
- package/dist/Extras/index.css +1 -1
- package/dist/Extras/index.js +10 -10
- package/dist/_tsup-dts-rollup.d.cts +6 -0
- package/dist/_tsup-dts-rollup.d.ts +6 -0
- package/dist/index.cjs +11 -11
- package/dist/index.css +1 -1
- package/dist/index.js +11 -11
- package/dist/styles/Extras/TypewriterText.css +78 -2
- package/dist/styles/base.css +0 -3
- package/dist/styles.css +291 -3
- package/package.json +3 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var react=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),marked=require('marked'),jsxRuntime=require('react/jsx-runtime');function
|
|
2
|
-
exports.TypewriterText=
|
|
1
|
+
'use strict';var react=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),marked=require('marked'),K=require('katex'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var K__default=/*#__PURE__*/_interopDefault(K);function w(...r){return tailwindMerge.twMerge(clsx.clsx(r))}var Y='<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 T(r){return r.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}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:i}){let s=/^https?:\/\//i.test(r??"")?r:"",t=i?` alt="${T(i)}"`:' alt=""',n=e?` title="${T(e)}"`:"",c=T(i||"Image failed to load");return `<figure class="tw-rich-img-wrap"><img class="tw-rich-img" src="${T(s)}" loading="lazy"${t}${n} /><div class="tw-rich-img-error">`+Y+`<span>${c}</span></div></figure>`}}});function P(r){let{result:e,store:i}=J(r),s=F.parse(e,{async:false}),t=j(s);return Q(t,i)}function J(r){let e=[];return {result:r.replace(/\$\$([\s\S]+?)\$\$/g,(s,t)=>`<!--LATEX_${e.push({src:t,display:true})-1}-->`).replace(/\\\[([\s\S]+?)\\\]/g,(s,t)=>`<!--LATEX_${e.push({src:t,display:true})-1}-->`).replace(/\\\(([\s\S]+?)\\\)/g,(s,t)=>`<!--LATEX_${e.push({src:t,display:false})-1}-->`).replace(/(?<!\$)\$(?!\$)((?:[^\n$\\]|\\[^\n])+?)\$(?!\$)/g,(s,t)=>`<!--LATEX_${e.push({src:t,display:false})-1}-->`),store:e}}function Q(r,e){return e.length===0?r:r.replace(/<!--LATEX_(\d+)-->/g,(i,s)=>{let t=e[Number(s)];if(!t)return i;try{return K__default.default.renderToString(t.src,{displayMode:t.display,throwOnError:!1,output:"html",trust:!1})}catch{return t.display?`<span class="tw-latex-raw">\\[${t.src}\\]</span>`:`<code class="tw-latex-raw">$${t.src}$</code>`}})}function U({text:r="",mode:e="typewriter",speed:i=40,cursor:s=true,cursorChar:t="\u258B",thinking:n=false,streaming:c=false,delay:S=0,onComplete:z,as:N="span",className:A,rich:$=false}){let[b,u]=react.useState(e==="instant"?r:""),[k,l]=react.useState(false),[R,p]=react.useState(e==="instant"),[C,h]=react.useState(false),I=react.useRef(null),v=react.useRef(0),L=react.useRef(z);L.current=z;let x=react.useRef(r);x.current=r,react.useEffect(()=>{if(e!=="typewriter")return;if(u(""),p(false),h(false),l(false),!r){p(true);return}let d=Math.max(10,1e3/i),o=0,a,m=()=>{l(true),a=setInterval(()=>{let D=x.current;o++,u(D.slice(0,o)),o>=D.length&&(clearInterval(a),l(false),p(true),L.current?.());},d);},g;return S>0?g=setTimeout(m,S):m(),()=>{clearTimeout(g),clearInterval(a);}},[r,e]),react.useEffect(()=>{if(e!=="stream")return;if(r.length===0){v.current=0,u(""),l(false),p(false),h(false);return}if(r.length<=v.current)return;let d=Math.max(10,1e3/i),o=v.current;l(true),p(false),h(false);let a=setInterval(()=>{o++,v.current=o,u(x.current.slice(0,o)),o>=x.current.length&&(clearInterval(a),l(false),L.current?.());},d);return ()=>clearInterval(a)},[r,e]),react.useEffect(()=>{e==="instant"&&(u(r),l(false),p(true));},[r,e]);let _=react.useRef(c);react.useEffect(()=>{let d=_.current;if(_.current=c,d&&!c&&!k&&e==="stream"){h(true);let o=setTimeout(()=>{h(false),p(true);},650);return ()=>clearTimeout(o)}},[c,k,e]),react.useEffect(()=>{if(!$||!I.current)return;let o=Array.from(I.current.querySelectorAll(".tw-rich-img")).map(a=>{let m=()=>{let g=a.closest(".tw-rich-img-wrap");g&&g.classList.add("tw-rich-img-wrap--error");};return a.addEventListener("error",m,{once:true}),{img:a,onError:m}});return ()=>{o.forEach(({img:a,onError:m})=>a.removeEventListener("error",m));}},[b,$]);let H=s&&(n||k||C||e==="stream"&&c&&!R||e==="typewriter"&&!R),X=n?"tw-cursor--blink":k?"tw-cursor--solid":C?"tw-cursor--out":"tw-cursor--blink",B=N;return $?jsxRuntime.jsxs("div",{role:"region",className:w(A),children:[jsxRuntime.jsx("div",{ref:I,className:"tw-rich-prose",dangerouslySetInnerHTML:{__html:P(b)}}),H&&jsxRuntime.jsx("span",{className:w("tw-cursor",X),"aria-hidden":"true",children:t})]}):jsxRuntime.jsxs(B,{className:w(A),children:[n&&!b&&jsxRuntime.jsx("span",{"aria-hidden":"true",children:"\u200B"}),b,H&&jsxRuntime.jsx("span",{className:w("tw-cursor",X),"aria-hidden":"true",children:t})]})}
|
|
2
|
+
exports.TypewriterText=U;
|
|
@@ -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}}@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-
|
|
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;border:1px solid var(--color-primary-200)}.dark .tw-rich-prose :not(pre)>code{background-color:var(--color-primary-900);color:var(--color-primary-200);border-color:var(--color-primary-700)}.tw-rich-prose pre{background-color:var(--color-primary-100);border:1px solid var(--color-primary-200);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-900);border-color:var(--color-primary-700)}.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}.tw-rich-prose .katex-display{display:block;margin:.875rem 0;overflow-x:auto;overflow-y:hidden;text-align:center}.tw-rich-prose .katex{font-size:1.05em;line-height:1.2}.dark .tw-rich-prose .katex{color:inherit}.tw-latex-raw{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.8125em;color:var(--color-warning-600);background-color:var(--color-warning-50);padding:.1em .3em;border-radius:.25rem}.dark .tw-latex-raw{color:var(--color-warning-400);background-color:color-mix(in srgb,var(--color-warning-900) 40%,transparent)}
|
|
@@ -1,2 +1,2 @@
|
|
|
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
|
|
2
|
-
export{
|
|
1
|
+
import {useState,useRef,useEffect}from'react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {Marked}from'marked';import K from'katex';import {jsxs,jsx}from'react/jsx-runtime';function w(...r){return twMerge(clsx(r))}var Y='<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 T(r){return r.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}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:i}){let s=/^https?:\/\//i.test(r??"")?r:"",t=i?` alt="${T(i)}"`:' alt=""',n=e?` title="${T(e)}"`:"",c=T(i||"Image failed to load");return `<figure class="tw-rich-img-wrap"><img class="tw-rich-img" src="${T(s)}" loading="lazy"${t}${n} /><div class="tw-rich-img-error">`+Y+`<span>${c}</span></div></figure>`}}});function P(r){let{result:e,store:i}=J(r),s=F.parse(e,{async:false}),t=j(s);return Q(t,i)}function J(r){let e=[];return {result:r.replace(/\$\$([\s\S]+?)\$\$/g,(s,t)=>`<!--LATEX_${e.push({src:t,display:true})-1}-->`).replace(/\\\[([\s\S]+?)\\\]/g,(s,t)=>`<!--LATEX_${e.push({src:t,display:true})-1}-->`).replace(/\\\(([\s\S]+?)\\\)/g,(s,t)=>`<!--LATEX_${e.push({src:t,display:false})-1}-->`).replace(/(?<!\$)\$(?!\$)((?:[^\n$\\]|\\[^\n])+?)\$(?!\$)/g,(s,t)=>`<!--LATEX_${e.push({src:t,display:false})-1}-->`),store:e}}function Q(r,e){return e.length===0?r:r.replace(/<!--LATEX_(\d+)-->/g,(i,s)=>{let t=e[Number(s)];if(!t)return i;try{return K.renderToString(t.src,{displayMode:t.display,throwOnError:!1,output:"html",trust:!1})}catch{return t.display?`<span class="tw-latex-raw">\\[${t.src}\\]</span>`:`<code class="tw-latex-raw">$${t.src}$</code>`}})}function U({text:r="",mode:e="typewriter",speed:i=40,cursor:s=true,cursorChar:t="\u258B",thinking:n=false,streaming:c=false,delay:S=0,onComplete:z,as:N="span",className:A,rich:$=false}){let[b,u]=useState(e==="instant"?r:""),[k,l]=useState(false),[R,p]=useState(e==="instant"),[C,h]=useState(false),I=useRef(null),v=useRef(0),L=useRef(z);L.current=z;let x=useRef(r);x.current=r,useEffect(()=>{if(e!=="typewriter")return;if(u(""),p(false),h(false),l(false),!r){p(true);return}let d=Math.max(10,1e3/i),o=0,a,m=()=>{l(true),a=setInterval(()=>{let D=x.current;o++,u(D.slice(0,o)),o>=D.length&&(clearInterval(a),l(false),p(true),L.current?.());},d);},g;return S>0?g=setTimeout(m,S):m(),()=>{clearTimeout(g),clearInterval(a);}},[r,e]),useEffect(()=>{if(e!=="stream")return;if(r.length===0){v.current=0,u(""),l(false),p(false),h(false);return}if(r.length<=v.current)return;let d=Math.max(10,1e3/i),o=v.current;l(true),p(false),h(false);let a=setInterval(()=>{o++,v.current=o,u(x.current.slice(0,o)),o>=x.current.length&&(clearInterval(a),l(false),L.current?.());},d);return ()=>clearInterval(a)},[r,e]),useEffect(()=>{e==="instant"&&(u(r),l(false),p(true));},[r,e]);let _=useRef(c);useEffect(()=>{let d=_.current;if(_.current=c,d&&!c&&!k&&e==="stream"){h(true);let o=setTimeout(()=>{h(false),p(true);},650);return ()=>clearTimeout(o)}},[c,k,e]),useEffect(()=>{if(!$||!I.current)return;let o=Array.from(I.current.querySelectorAll(".tw-rich-img")).map(a=>{let m=()=>{let g=a.closest(".tw-rich-img-wrap");g&&g.classList.add("tw-rich-img-wrap--error");};return a.addEventListener("error",m,{once:true}),{img:a,onError:m}});return ()=>{o.forEach(({img:a,onError:m})=>a.removeEventListener("error",m));}},[b,$]);let H=s&&(n||k||C||e==="stream"&&c&&!R||e==="typewriter"&&!R),X=n?"tw-cursor--blink":k?"tw-cursor--solid":C?"tw-cursor--out":"tw-cursor--blink",B=N;return $?jsxs("div",{role:"region",className:w(A),children:[jsx("div",{ref:I,className:"tw-rich-prose",dangerouslySetInnerHTML:{__html:P(b)}}),H&&jsx("span",{className:w("tw-cursor",X),"aria-hidden":"true",children:t})]}):jsxs(B,{className:w(A),children:[n&&!b&&jsx("span",{"aria-hidden":"true",children:"\u200B"}),b,H&&jsx("span",{className:w("tw-cursor",X),"aria-hidden":"true",children:t})]})}
|
|
2
|
+
export{U as TypewriterText};
|