# Morse code signal lamp loader

> A signal lamp flashes the message in Morse code while a paper tape prints the dots and dashes.

- Category: [Loaders](https://library.aimran.es/components/loaders)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-ld-morse-lamp
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

A short script turns the text into real Morse timing, with dots, dashes and gaps, and plays it on a glowing signal lamp. A paper tape slides under a print head and keeps the marks, while the current letter and its code appear in large mono type. It suits radio, maritime, telecom and puzzle themed sites.

Write the message in the text field; accents are removed and letters and digits are encoded. The main color lights the lamp and the head, the second sets the tape, and speed changes the unit length.

## Code

### HTML

```html
<div class="uvq10-mrs" role="status"><span class="sr">Loading</span><div class="top" aria-hidden="true"><i class="lp"></i><span class="lt"></span><span class="cd"></span></div><div class="tp" aria-hidden="true"><div class="pr"><div class="sp"></div></div><i class="hd"></i></div></div>
```

### CSS

```css
.uvq10-mrs {
  --c1: #ffb000;
  --c2: #efe6d2;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq10-mrs {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: .9em;
  width: 13em;
}

.uvq10-mrs .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.uvq10-mrs .top {
  display: flex;
  align-items: center;
  gap: .8em;
}

.uvq10-mrs .lp {
  flex: none;
  width: 2.3em;
  height: 2.3em;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%,color-mix(in srgb,var(--c1) 25%,#3a3a3a),#151515);
  box-shadow: 0 0 0 .25em #262626,0 0 0 .32em #6b6b6b;
  transition: background calc(0.04s / var(--k)),box-shadow calc(0.04s / var(--k));
}

.uvq10-mrs .lp.on {
  background: radial-gradient(circle at 40% 35%,#fff,var(--c1) 45%,color-mix(in srgb,var(--c1) 70%,#000));
  box-shadow: 0 0 0 .25em #262626,0 0 0 .32em #6b6b6b,0 0 1.4em .25em var(--c1);
}

.uvq10-mrs .lt {
  min-width: 1ch;
  font: 700 2em/1 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
}

.uvq10-mrs .cd {
  font: 700 1.1em/1 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
  letter-spacing: .18em;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq10-mrs .tp {
  position: relative;
  height: 1.5em;
  border-radius: .2em;
  background: repeating-linear-gradient(90deg,transparent 0 .9em,rgba(0,0,0,.05) .9em calc(.9em + 1px)),var(--c2);
  box-shadow: inset 0 .08em 0 rgba(255,255,255,.5),0 .3em .6em -.3em rgba(0,0,0,.4);
}

.uvq10-mrs .pr {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 9em;
  overflow: hidden;
}

.uvq10-mrs .sp {
  position: absolute;
  left: 9em;
  top: 0;
  bottom: 0;
  will-change: transform;
}

.uvq10-mrs .sp i {
  position: absolute;
  top: 50%;
  height: .34em;
  margin-top: -.17em;
  border-radius: .2em;
  background: #1b1b1b;
}

.uvq10-mrs .hd {
  position: absolute;
  left: 9em;
  top: -.3em;
  bottom: -.3em;
  width: .18em;
  margin-left: -.09em;
  border-radius: .1em;
  background: var(--c1);
  box-shadow: 0 0 .4em var(--c1);
}

@media (prefers-reduced-motion:reduce) {
  .uvq10-mrs,.uvq10-mrs *,.uvq10-mrs *::before,.uvq10-mrs *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
```

### JavaScript

```js
document.querySelectorAll(".uvq10-mrs").forEach(el => {
  const k=parseFloat(getComputedStyle(el).getPropertyValue('--k'))||1;const rm=matchMedia('(prefers-reduced-motion: reduce)').matches;
const M={A:'.-',B:'-...',C:'-.-.',D:'-..',E:'.',F:'..-.',G:'--.',H:'....',I:'..',J:'.---',K:'-.-',L:'.-..',M:'--',N:'-.',O:'---',P:'.--.',Q:'--.-',R:'.-.',S:'...',T:'-',U:'..-',V:'...-',W:'.--',X:'-..-',Y:'-.--',Z:'--..',0:'-----',1:'.----',2:'..---',3:'...--',4:'....-',5:'.....',6:'-....',7:'--...',8:'---..',9:'----.'};
const txt=(el.querySelector('.sr').textContent||'').normalize('NFD').replace(/[\u0300-\u036f]/g,'').toUpperCase();
const sp=el.querySelector('.sp'),lp=el.querySelector('.lp'),lt=el.querySelector('.lt'),cd=el.querySelector('.cd');
const on=[],letters=[];let u=0;
for(const ch of txt){if(ch===' '){u+=4;continue;}const c=M[ch];if(!c)continue;const st=u;for(const s of c){const l=s==='.'?1:3;on.push([u,u+l]);u+=l+1;}u+=2;letters.push([st,u,ch,c]);}
const total=u+8,W=0.42,U=110/k;
sp.innerHTML=on.map(([a,b])=>'<i style="left:'+(a*W)+'em;width:'+((b-a)*W)+'em"></i>').join('');
let shown=null,raf=0,t0=performance.now();
const draw=(x)=>{sp.style.transform='translateX('+(-x*W)+'em)';lp.classList.toggle('on',on.some(([a,b])=>x>=a&&x<b));const L=letters.find(([a,b])=>x>=a&&x<b)||null;if(L!==shown){shown=L;lt.textContent=L?L[2]:'';cd.textContent=L?L[3].replace(/\./g,'·').replace(/-/g,'–'):'';}};
const frame=(now)=>{let x=(now-t0)/U;if(x>total){t0=now;x=0;}draw(x);raf=requestAnimationFrame(frame);};
if(rm){draw(u);lt.textContent=txt.slice(0,1);}else{raf=requestAnimationFrame(frame);}
return()=>cancelAnimationFrame(raf);
});
```

### React

```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq10-mrs {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: .9em;
  width: 13em;
}

.uvq10-mrs .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.uvq10-mrs .top {
  display: flex;
  align-items: center;
  gap: .8em;
}

.uvq10-mrs .lp {
  flex: none;
  width: 2.3em;
  height: 2.3em;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%,color-mix(in srgb,var(--c1) 25%,#3a3a3a),#151515);
  box-shadow: 0 0 0 .25em #262626,0 0 0 .32em #6b6b6b;
  transition: background calc(0.04s / var(--k)),box-shadow calc(0.04s / var(--k));
}

.uvq10-mrs .lp.on {
  background: radial-gradient(circle at 40% 35%,#fff,var(--c1) 45%,color-mix(in srgb,var(--c1) 70%,#000));
  box-shadow: 0 0 0 .25em #262626,0 0 0 .32em #6b6b6b,0 0 1.4em .25em var(--c1);
}

.uvq10-mrs .lt {
  min-width: 1ch;
  font: 700 2em/1 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
}

.uvq10-mrs .cd {
  font: 700 1.1em/1 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
  letter-spacing: .18em;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq10-mrs .tp {
  position: relative;
  height: 1.5em;
  border-radius: .2em;
  background: repeating-linear-gradient(90deg,transparent 0 .9em,rgba(0,0,0,.05) .9em calc(.9em + 1px)),var(--c2);
  box-shadow: inset 0 .08em 0 rgba(255,255,255,.5),0 .3em .6em -.3em rgba(0,0,0,.4);
}

.uvq10-mrs .pr {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 9em;
  overflow: hidden;
}

.uvq10-mrs .sp {
  position: absolute;
  left: 9em;
  top: 0;
  bottom: 0;
  will-change: transform;
}

.uvq10-mrs .sp i {
  position: absolute;
  top: 50%;
  height: .34em;
  margin-top: -.17em;
  border-radius: .2em;
  background: #1b1b1b;
}

.uvq10-mrs .hd {
  position: absolute;
  left: 9em;
  top: -.3em;
  bottom: -.3em;
  width: .18em;
  margin-left: -.09em;
  border-radius: .1em;
  background: var(--c1);
  box-shadow: 0 0 .4em var(--c1);
}

@media (prefers-reduced-motion:reduce) {
  .uvq10-mrs,.uvq10-mrs *,.uvq10-mrs *::before,.uvq10-mrs *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const k=parseFloat(getComputedStyle(el).getPropertyValue('--k'))||1;const rm=matchMedia('(prefers-reduced-motion: reduce)').matches;
const M={A:'.-',B:'-...',C:'-.-.',D:'-..',E:'.',F:'..-.',G:'--.',H:'....',I:'..',J:'.---',K:'-.-',L:'.-..',M:'--',N:'-.',O:'---',P:'.--.',Q:'--.-',R:'.-.',S:'...',T:'-',U:'..-',V:'...-',W:'.--',X:'-..-',Y:'-.--',Z:'--..',0:'-----',1:'.----',2:'..---',3:'...--',4:'....-',5:'.....',6:'-....',7:'--...',8:'---..',9:'----.'};
const txt=(el.querySelector('.sr').textContent||'').normalize('NFD').replace(/[\u0300-\u036f]/g,'').toUpperCase();
const sp=el.querySelector('.sp'),lp=el.querySelector('.lp'),lt=el.querySelector('.lt'),cd=el.querySelector('.cd');
const on=[],letters=[];let u=0;
for(const ch of txt){if(ch===' '){u+=4;continue;}const c=M[ch];if(!c)continue;const st=u;for(const s of c){const l=s==='.'?1:3;on.push([u,u+l]);u+=l+1;}u+=2;letters.push([st,u,ch,c]);}
const total=u+8,W=0.42,U=110/k;
sp.innerHTML=on.map(([a,b])=>'<i style="left:'+(a*W)+'em;width:'+((b-a)*W)+'em"></i>').join('');
let shown=null,raf=0,t0=performance.now();
const draw=(x)=>{sp.style.transform='translateX('+(-x*W)+'em)';lp.classList.toggle('on',on.some(([a,b])=>x>=a&&x<b));const L=letters.find(([a,b])=>x>=a&&x<b)||null;if(L!==shown){shown=L;lt.textContent=L?L[2]:'';cd.textContent=L?L[3].replace(/\./g,'·').replace(/-/g,'–'):'';}};
const frame=(now)=>{let x=(now-t0)/U;if(x>total){t0=now;x=0;}draw(x);raf=requestAnimationFrame(frame);};
if(rm){draw(u);lt.textContent=txt.slice(0,1);}else{raf=requestAnimationFrame(frame);}
return()=>cancelAnimationFrame(raf);
}

export default function LdMorseLamp() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#ffb000",
          "--c2": "#efe6d2",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq10-mrs" role="status"><span className="sr">Loading</span><div className="top" aria-hidden="true"><i className="lp"></i><span className="lt"></span><span className="cd"></span></div><div className="tp" aria-hidden="true"><div className="pr"><div className="sp"></div></div><i className="hd"></i></div></div>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Morse code signal lamp loader” block (Loaders) from AIMRAN Library to my project.

## What it is
A signal lamp flashes the message in Morse code while a paper tape prints the dots and dashes.

## Chosen settings
- Main color: #ffb000
- Secondary color: #efe6d2
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Cargando"

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq10-mrs {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: .9em;
  width: 13em;
}

.uvq10-mrs .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.uvq10-mrs .top {
  display: flex;
  align-items: center;
  gap: .8em;
}

.uvq10-mrs .lp {
  flex: none;
  width: 2.3em;
  height: 2.3em;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%,color-mix(in srgb,var(--c1) 25%,#3a3a3a),#151515);
  box-shadow: 0 0 0 .25em #262626,0 0 0 .32em #6b6b6b;
  transition: background calc(0.04s / var(--k)),box-shadow calc(0.04s / var(--k));
}

.uvq10-mrs .lp.on {
  background: radial-gradient(circle at 40% 35%,#fff,var(--c1) 45%,color-mix(in srgb,var(--c1) 70%,#000));
  box-shadow: 0 0 0 .25em #262626,0 0 0 .32em #6b6b6b,0 0 1.4em .25em var(--c1);
}

.uvq10-mrs .lt {
  min-width: 1ch;
  font: 700 2em/1 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
}

.uvq10-mrs .cd {
  font: 700 1.1em/1 ui-monospace,"SF Mono",Menlo,Consolas,monospace;
  letter-spacing: .18em;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq10-mrs .tp {
  position: relative;
  height: 1.5em;
  border-radius: .2em;
  background: repeating-linear-gradient(90deg,transparent 0 .9em,rgba(0,0,0,.05) .9em calc(.9em + 1px)),var(--c2);
  box-shadow: inset 0 .08em 0 rgba(255,255,255,.5),0 .3em .6em -.3em rgba(0,0,0,.4);
}

.uvq10-mrs .pr {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 9em;
  overflow: hidden;
}

.uvq10-mrs .sp {
  position: absolute;
  left: 9em;
  top: 0;
  bottom: 0;
  will-change: transform;
}

.uvq10-mrs .sp i {
  position: absolute;
  top: 50%;
  height: .34em;
  margin-top: -.17em;
  border-radius: .2em;
  background: #1b1b1b;
}

.uvq10-mrs .hd {
  position: absolute;
  left: 9em;
  top: -.3em;
  bottom: -.3em;
  width: .18em;
  margin-left: -.09em;
  border-radius: .1em;
  background: var(--c1);
  box-shadow: 0 0 .4em var(--c1);
}

@media (prefers-reduced-motion:reduce) {
  .uvq10-mrs,.uvq10-mrs *,.uvq10-mrs *::before,.uvq10-mrs *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const k=parseFloat(getComputedStyle(el).getPropertyValue('--k'))||1;const rm=matchMedia('(prefers-reduced-motion: reduce)').matches;
const M={A:'.-',B:'-...',C:'-.-.',D:'-..',E:'.',F:'..-.',G:'--.',H:'....',I:'..',J:'.---',K:'-.-',L:'.-..',M:'--',N:'-.',O:'---',P:'.--.',Q:'--.-',R:'.-.',S:'...',T:'-',U:'..-',V:'...-',W:'.--',X:'-..-',Y:'-.--',Z:'--..',0:'-----',1:'.----',2:'..---',3:'...--',4:'....-',5:'.....',6:'-....',7:'--...',8:'---..',9:'----.'};
const txt=(el.querySelector('.sr').textContent||'').normalize('NFD').replace(/[\u0300-\u036f]/g,'').toUpperCase();
const sp=el.querySelector('.sp'),lp=el.querySelector('.lp'),lt=el.querySelector('.lt'),cd=el.querySelector('.cd');
const on=[],letters=[];let u=0;
for(const ch of txt){if(ch===' '){u+=4;continue;}const c=M[ch];if(!c)continue;const st=u;for(const s of c){const l=s==='.'?1:3;on.push([u,u+l]);u+=l+1;}u+=2;letters.push([st,u,ch,c]);}
const total=u+8,W=0.42,U=110/k;
sp.innerHTML=on.map(([a,b])=>'<i style="left:'+(a*W)+'em;width:'+((b-a)*W)+'em"></i>').join('');
let shown=null,raf=0,t0=performance.now();
const draw=(x)=>{sp.style.transform='translateX('+(-x*W)+'em)';lp.classList.toggle('on',on.some(([a,b])=>x>=a&&x<b));const L=letters.find(([a,b])=>x>=a&&x<b)||null;if(L!==shown){shown=L;lt.textContent=L?L[2]:'';cd.textContent=L?L[3].replace(/\./g,'·').replace(/-/g,'–'):'';}};
const frame=(now)=>{let x=(now-t0)/U;if(x>total){t0=now;x=0;}draw(x);raf=requestAnimationFrame(frame);};
if(rm){draw(u);lt.textContent=txt.slice(0,1);}else{raf=requestAnimationFrame(frame);}
return()=>cancelAnimationFrame(raf);
}

export default function LdMorseLamp() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#ffb000",
          "--c2": "#efe6d2",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq10-mrs" role="status"><span className="sr">Loading</span><div className="top" aria-hidden="true"><i className="lp"></i><span className="lt"></span><span className="cd"></span></div><div className="tp" aria-hidden="true"><div className="pr"><div className="sp"></div></div><i className="hd"></i></div></div>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
