Skip to content

Commit 77c1fb5

Browse files
committed
refinement
1 parent 53b26df commit 77c1fb5

File tree

4 files changed

+120
-30
lines changed

4 files changed

+120
-30
lines changed

README.md

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,19 @@ compiler('This text has <span>html</span> in it but it won't be rendered', { dis
660660
661661
When using [fenced code blocks](https://www.markdownguide.org/extended-syntax/#syntax-highlighting) with language annotation, that language will be added to the `<code>` element as `class="lang-${language}"`. For best results, you can use `options.overrides` to provide an appropriate syntax highlighting integration like this one using `highlight.js`:
662662
663+
```html
664+
<!-- Add the following tags to your page <head> to automatically load hljs and styles: -->
665+
<link
666+
rel="stylesheet"
667+
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/obsidian.min.css"
668+
/>
669+
670+
<script
671+
crossorigin
672+
src="https://unpkg.com/@highlightjs/[email protected]/highlight.min.js"
673+
></script>
674+
```
675+
663676
````tsx
664677
import { Markdown, RuleType } from 'markdown-to-jsx'
665678
@@ -678,23 +691,6 @@ function App() {
678691
)
679692
}
680693
681-
/**
682-
* Add the following tags to your page <head> to automatically load hljs and styles:
683-
684-
<link
685-
rel="stylesheet"
686-
href="https://unpkg.com/@highlightjs/[email protected]/styles/nord.min.css"
687-
/>
688-
689-
* NOTE: for best performance, load individual languages you need instead of all
690-
of them. See their docs for more info: https://highlightjs.org/
691-
692-
<script
693-
crossorigin
694-
src="https://unpkg.com/@highlightjs/[email protected]/highlight.min.js"
695-
></script>
696-
*/
697-
698694
function SyntaxHighlightedCode(props) {
699695
const ref = (React.useRef < HTMLElement) | (null > null)
700696
@@ -859,7 +855,7 @@ The two leading spaces in front of "# Hello" would be left-trimmed from all line
859855
<div>
860856
```js
861857
var some = code();
862-
``\`
858+
```
863859
</div>
864860
````
865861
@@ -1037,7 +1033,7 @@ The AST consists of the following node types (use `RuleType` to check node types
10371033
10381034
### Example AST Structure
10391035
1040-
```tsx
1036+
````tsx
10411037
import { parser, RuleType } from 'markdown-to-jsx'
10421038
10431039
const ast = parser(`# Hello World
@@ -1046,9 +1042,10 @@ This is a **paragraph** with [a link](https://example.com).
10461042

10471043
[linkref]: https://example.com
10481044

1049-
\`\`\`javascript
1045+
```javascript
10501046
console.log('code')
1051-
\`\`\`
1047+
```
1048+
10521049
`)
10531050
10541051
// AST structure:
@@ -1057,8 +1054,8 @@ console.log('code')
10571054
{
10581055
type: RuleType.refCollection,
10591056
refs: {
1060-
"linkref": { target: "https://example.com", title: undefined }
1061-
}
1057+
linkref: { target: 'https://example.com', title: undefined },
1058+
},
10621059
},
10631060
{
10641061
type: RuleType.heading,
@@ -1088,9 +1085,10 @@ console.log('code')
10881085
type: RuleType.codeBlock,
10891086
lang: 'javascript',
10901087
text: "console.log('code')",
1091-
})
1088+
},
10921089
]
1093-
```
1090+
1091+
````
10941092
10951093
### Type Checking
10961094

site.tsx

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,56 @@ function PresetSelector({
116116
)
117117
}
118118

119+
function FloatingText({ text }: { text: string }) {
120+
const letters = React.useMemo(() => {
121+
return text.split('').map((char, index) => {
122+
const maxOffset = 3
123+
const duration = 6 + Math.random() * 4
124+
const delay = Math.random() * 2
125+
126+
const offsets = [
127+
{
128+
x: (Math.random() - 0.5) * maxOffset * 2,
129+
y: (Math.random() - 0.5) * maxOffset * 2,
130+
},
131+
{
132+
x: (Math.random() - 0.5) * maxOffset * 2,
133+
y: (Math.random() - 0.5) * maxOffset * 2,
134+
},
135+
{
136+
x: (Math.random() - 0.5) * maxOffset * 2,
137+
y: (Math.random() - 0.5) * maxOffset * 2,
138+
},
139+
]
140+
141+
return {
142+
char,
143+
key: index,
144+
style: {
145+
'--offset-x-1': `${offsets[0].x}px`,
146+
'--offset-y-1': `${offsets[0].y}px`,
147+
'--offset-x-2': `${offsets[1].x}px`,
148+
'--offset-y-2': `${offsets[1].y}px`,
149+
'--offset-x-3': `${offsets[2].x}px`,
150+
'--offset-y-3': `${offsets[2].y}px`,
151+
'--duration': `${duration}s`,
152+
'--delay': `${delay}s`,
153+
} as React.CSSProperties,
154+
}
155+
})
156+
}, [text])
157+
158+
return (
159+
<>
160+
{letters.map(({ char, key, style }) => (
161+
<span key={key} className="float-letter" style={style}>
162+
{char === ' ' ? '\u00A0' : char}
163+
</span>
164+
))}
165+
</>
166+
)
167+
}
168+
119169
function TryItLive() {
120170
const [markdown, setMarkdown] = React.useState(
121171
document.getElementById('sample-content')?.textContent?.trim() || ''
@@ -145,7 +195,7 @@ function TryItLive() {
145195
<div className=" mx-auto text-base space-y-6">
146196
<h1 className="text-accent leading-tight">
147197
<span className="font-display tracking-widest text-[9vw]">
148-
markdown-to-jsx
198+
<FloatingText text="markdown-to-jsx" />
149199
<span className="text-[max(1vw,16px)] font-sans tracking-wider">
150200
v{VERSION}
151201
</span>
@@ -161,6 +211,13 @@ function TryItLive() {
161211
<a
162212
className={`no-underline py-1 px-3 backdrop-blur-xs rounded-xl text-sm ${gradient}`}
163213
href="#docs"
214+
onClick={e => {
215+
e.preventDefault()
216+
const element = document.getElementById('docs')
217+
if (element) {
218+
element.scrollIntoView({ behavior: 'smooth' })
219+
}
220+
}}
164221
>
165222
Jump to docs
166223
</a>
@@ -200,6 +257,7 @@ function TryItLive() {
200257

201258
<Markdown
202259
className="max-w-2xl prose prose-invert prose-sm center"
260+
id="docs"
203261
options={options}
204262
>
205263
{readmeContent}

src/site/index.css

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
color: var(--color-fg, #fefefe);
3838
font-family: var(--font-sans);
3939
font-size: 16px;
40-
line-height: 1.5;
40+
line-height: 1.375;
4141
}
4242

4343
h1,
@@ -181,6 +181,10 @@
181181
}
182182
}
183183

184+
.prose {
185+
line-height: inherit;
186+
}
187+
184188
.prose :is(h2, h3, h4, h5, h6) {
185189
margin: 3em 0 1em;
186190
}
@@ -243,3 +247,26 @@
243247
animation: gradient-shift 6s ease-in-out infinite alternate;
244248
background-size: 200% 200%;
245249
}
250+
251+
@keyframes float-wander {
252+
0%,
253+
100% {
254+
transform: translate(0, 0);
255+
}
256+
25% {
257+
transform: translate(var(--offset-x-1), var(--offset-y-1));
258+
}
259+
50% {
260+
transform: translate(var(--offset-x-2), var(--offset-y-2));
261+
}
262+
75% {
263+
transform: translate(var(--offset-x-3), var(--offset-y-3));
264+
}
265+
}
266+
267+
.float-letter {
268+
display: inline-block;
269+
animation: float-wander var(--duration, 4s)
270+
cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite;
271+
animation-delay: var(--delay, 0s);
272+
}

src/site/lava-lamp.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ export function LavaLamp({ className }: { className?: string }) {
492492
usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST,
493493
})
494494
let isSaving = false
495+
const saveArrayLength = numParticles * 12
496+
const saveArray = new Array<number>(saveArrayLength)
495497

496498
const updateCanvasSize = () => {
497499
const width = window.innerWidth
@@ -609,15 +611,20 @@ export function LavaLamp({ className }: { className?: string }) {
609611
stagingBuffer.getMappedRange()
610612
)
611613
if (
612-
data.length === numParticles * 12 &&
614+
data.length === saveArrayLength &&
613615
data.some(v => v !== 0)
614616
) {
615617
try {
618+
for (let i = 0; i < saveArrayLength; i++) {
619+
saveArray[i] = data[i]
620+
}
616621
localStorage.setItem(
617622
'lava-lamp-particles',
618-
JSON.stringify(Array.from(data))
623+
JSON.stringify(saveArray)
619624
)
620-
} catch (e) {}
625+
} catch (e) {
626+
console.error('Error saving particles:', e)
627+
}
621628
}
622629
stagingBuffer.unmap()
623630
isSaving = false

0 commit comments

Comments
 (0)