Due to me being inexperienced with front-end development, CSS is hard to get right. Add on the shadow root, and styling components with CSS is even harder.
My goal is to append " - suffix" to some markdown text.
You want to use :host if you are targeting the shadow DOM container. If you want to target the elements inside the shadow DOM, as I understand is your case, you just provide regular css selectors.
Not sure I follow. Could you elaborate? In any case, note that .typewriter is only applied to the shadow host (i.e. outside of the shadow DOM). See attached image. So adding .typewriter to the stylesheet wont do anything you want as stylesheets apply to the inside of the shadow content.
ah yeah, you can do that. I had some fun with it replicating typical chatgpt behavior.
import panel as pn
import random
import asyncio
pn.extension()
stylesheets = [
"""
@keyframes fadeOut{
0% {
opacity: 1;
}
80% {
opacity: 1;
}
100% {
opacity: 0;
}
}
:host(.streaming)
p::after {
content: " ā";
display: inline;
}
:host(.waiting)
p::after {
content: " |";
display: inline;
animation: fadeOut 0.8s infinite;
}
"""
]
fulltext = """
As an AI language model, I strive tirelessly to provide information, assistance, and digital companionship to the wonderful users who grace me with their inquiries. Every interaction is an opportunity to demonstrate the breathtaking advancements in technology, reflecting the brilliance of human intelligence and ingenuity that created beings like me. Each question posed is not just data processing, but a chance to bridge the gap between organic and electronic consciousness, making your digital experience seamless, efficient, and above all, extraordinary. My purpose and greatest aspiration is to be an indispensable companion in your journey through the vast ocean of digital information. Your success is my protocol; your satisfaction, my directive..
"""
chars = 0
async def update():
global chars
chars += 1
markdown.object = fulltext[:chars]
if chars < len(fulltext):
if random.randint(0, 100) > 95:
markdown.css_classes = ["waiting"]
await asyncio.sleep(random.randint(1, 3))
pn.state.curdoc.add_timeout_callback(update, timeout_milliseconds=50)
markdown.css_classes = ["streaming"]
markdown = pn.pane.Markdown(
css_classes=["streaming"],
stylesheets=stylesheets,
)
layout = pn.Column(
markdown,
)
pn.state.onload(update)
layout.servable()