-
-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathReadme.vue
More file actions
493 lines (418 loc) · 10.9 KB
/
Readme.vue
File metadata and controls
493 lines (418 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
<script setup lang="ts">
defineProps<{
html: string
}>()
const { copy } = useClipboard()
// Combined click handler for:
// 1. Intercepting npmjs.com links to route internally
// 2. Copy button functionality for code blocks
function handleClick(event: MouseEvent) {
const target = event.target as HTMLElement | undefined
if (!target) return
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button) {
return
}
// Handle copy button clicks
const copyTarget = target.closest('[data-copy]')
if (copyTarget) {
const wrapper = copyTarget.closest('.readme-code-block')
if (!wrapper) return
const pre = wrapper.querySelector('pre')
if (!pre?.textContent) return
copy(pre.textContent)
const icon = copyTarget.querySelector('span')
if (!icon) return
const originalIcon = 'i-lucide:copy'
const successIcon = 'i-lucide:check'
icon.classList.remove(originalIcon)
icon.classList.add(successIcon)
setTimeout(() => {
icon.classList.remove(successIcon)
icon.classList.add(originalIcon)
}, 2000)
return
}
// Handle npmjs.com link clicks - route internally
const anchor = target.closest('a')
if (!anchor) return
const href = anchor.getAttribute('href')
if (!href) return
// Handle relative anchor links
if (href.startsWith('#') || href.startsWith('/')) {
event.preventDefault()
navigateTo(href)
return
}
}
</script>
<template>
<article
class="readme max-w-[70ch] lg:max-w-none px-1"
dir="auto"
v-html="html"
:style="{
'--i18n-note': '\'' + $t('package.readme.callout.note') + '\'',
'--i18n-tip': '\'' + $t('package.readme.callout.tip') + '\'',
'--i18n-important': '\'' + $t('package.readme.callout.important') + '\'',
'--i18n-warning': '\'' + $t('package.readme.callout.warning') + '\'',
'--i18n-caution': '\'' + $t('package.readme.callout.caution') + '\'',
}"
@click="handleClick"
/>
</template>
<style scoped>
/* README prose styling */
.readme {
color: var(--fg-muted);
line-height: 1.75;
/* Prevent horizontal overflow on mobile */
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-word;
/* Contain all children */
overflow: hidden;
min-width: 0;
/* Contain all children z-index values inside this container */
isolation: isolate;
contain: layout paint;
}
/* README headings - styled by visual level (data-level), not semantic level */
.readme :deep(h3),
.readme :deep(h4),
.readme :deep(h5),
.readme :deep(h6) {
@apply font-mono scroll-mt-20;
color: var(--fg);
font-weight: 500;
margin-top: 1rem;
margin-bottom: 1rem;
line-height: 1.3;
a {
text-decoration: none;
}
}
/* Visual styling based on original README heading level */
.readme :deep([data-level='1']) {
font-size: 1.5rem;
}
.readme :deep([data-level='2']) {
font-size: 1.25rem;
padding-bottom: 0.5rem;
border-bottom: 1px solid var(--border);
}
.readme :deep([data-level='3']) {
font-size: 1.125rem;
}
.readme :deep([data-level='4']) {
font-size: 1rem;
}
.readme :deep([data-level='5']) {
font-size: 0.925rem;
}
.readme :deep([data-level='6']) {
font-size: 0.875rem;
}
.readme :deep(p) {
margin-bottom: 1rem;
}
.readme :deep(a) {
@apply underline-offset-[0.2rem] underline decoration-1 decoration-fg/30 font-mono text-fg transition-colors duration-200;
}
.readme :deep(a:hover) {
@apply decoration-accent text-accent;
}
.readme :deep(a:focus-visible) {
@apply decoration-accent text-accent;
}
.readme :deep(a[target='_blank']:not(:has(img))::after) {
/* I don't know what kind of sorcery this is, but it ensures this icon can't wrap to a new line on its own. */
content: '__';
@apply inline i-lucide:external-link rtl-flip ms-1 opacity-50;
}
.readme :deep(:is(h1, h2, h3, h4, h5, h6) a[href^='#']::after) {
/* I don't know what kind of sorcery this is, but it ensures this icon can't wrap to a new line on its own. */
content: '__';
@apply inline i-lucide:link rtl-flip ms-1 opacity-0;
font-size: 0.75em;
}
.readme
:deep(:is(h1, h2, h3, h4, h5, h6):is(:hover, :focus-visible, :focus-within) a[href^='#']::after) {
@apply opacity-100;
}
.readme :deep(code) {
@apply font-mono;
font-size: 0.875em;
background: var(--bg-muted);
padding: 0.2em 0.4em;
border-radius: 4px;
border: 1px solid var(--border);
}
/* Code blocks - including Shiki output */
.readme :deep(pre),
.readme :deep(.shiki) {
border: 1px solid var(--border);
border-radius: 8px;
padding: 1rem;
overflow-x: auto;
margin: 1.5rem 0;
/* Fix horizontal overflow */
max-width: 100%;
box-sizing: border-box;
}
.readme :deep(.readme-code-block) {
@apply bg-bg-subtle;
display: block;
width: 100%;
position: relative;
}
.readme :deep(.readme-copy-button) {
position: absolute;
top: 0.4rem;
inset-inline-end: 0.4rem;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0.25rem;
border-radius: 6px;
background: color-mix(in srgb, var(--bg-subtle) 80%, transparent);
border: 1px solid var(--border);
color: var(--fg-subtle);
opacity: 0;
transition:
opacity 0.2s ease,
color 0.2s ease,
border-color 0.2s ease;
}
.readme :deep(.readme-code-block:hover .readme-copy-button),
.readme :deep(.readme-copy-button:focus-visible) {
opacity: 1;
}
.readme :deep(.readme-copy-button:hover) {
color: var(--fg);
border-color: var(--border-hover);
}
.readme :deep(.readme-copy-button > span) {
width: 1.05rem;
height: 1.05rem;
display: inline-block;
pointer-events: none;
}
.readme :deep(pre code),
.readme :deep(.shiki code) {
background: transparent !important;
border: none;
padding: 0;
@apply font-mono;
font-size: 0.875rem;
color: var(--fg);
/* Prevent code from forcing width */
white-space: pre;
word-break: normal;
overflow-wrap: normal;
/* Makes unicode and ascii art work properly */
line-height: 1.25;
display: inline-block;
}
.readme :deep(ul),
.readme :deep(ol) {
margin: 1rem 0;
padding-inline-start: 1.5rem;
}
.readme :deep(ul) {
list-style-type: disc;
}
.readme :deep(ol) {
list-style-type: decimal;
}
.readme :deep(li) {
margin-bottom: 0.5rem;
display: list-item;
}
.readme :deep(li::marker) {
color: var(--border-hover);
}
.readme :deep(blockquote) {
border-inline-start: 2px solid var(--border);
padding-inline-start: 1rem;
margin: 1.5rem 0;
color: var(--fg-subtle);
font-style: italic;
}
/* GitHub-style callouts/alerts */
.readme :deep(blockquote[data-callout]) {
border-inline-start-width: 3px;
padding: 1rem;
padding-inline-start: 1.25rem;
background: var(--bg-subtle);
font-style: normal;
color: var(--fg-subtle);
position: relative;
}
.readme :deep(blockquote[data-callout]::before) {
display: block;
@apply font-mono;
font-size: 0.75rem;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.05em;
margin-bottom: 0.5rem;
padding-inline-start: 1.5rem;
}
.readme :deep(blockquote[data-callout]::after) {
content: '';
width: 1.25rem;
height: 1.25rem;
position: absolute;
top: 1rem;
left: 1rem;
}
.readme :deep(blockquote[data-callout] > p:first-child) {
margin-top: 0;
}
.readme :deep(blockquote[data-callout] > p:last-child) {
margin-bottom: 0;
}
/* Note - blue */
.readme :deep(blockquote[data-callout='note']) {
border-inline-start-color: var(--syntax-str);
background: rgba(59, 130, 246, 0.05);
}
.readme :deep(blockquote[data-callout='note']::before) {
content: var(--i18n-note, 'Note');
color: #3b82f6;
}
.readme :deep(blockquote[data-callout='note']::after) {
background-color: #3b82f6;
-webkit-mask: icon('i-lucide:info') no-repeat;
mask: icon('i-lucide:info') no-repeat;
}
/* Tip - green */
.readme :deep(blockquote[data-callout='tip']) {
border-inline-start-color: #22c55e;
background: rgba(34, 197, 94, 0.05);
}
.readme :deep(blockquote[data-callout='tip']::before) {
content: var(--i18n-tip, 'Tip');
color: #22c55e;
}
.readme :deep(blockquote[data-callout='tip']::after) {
background-color: #22c55e;
-webkit-mask: icon('i-lucide:lightbulb') no-repeat;
mask: icon('i-lucide:lightbulb') no-repeat;
}
/* Important - purple */
.readme :deep(blockquote[data-callout='important']) {
border-inline-start-color: var(--syntax-fn);
background: rgba(168, 85, 247, 0.05);
}
.readme :deep(blockquote[data-callout='important']::before) {
content: var(--i18n-important, 'Important');
color: var(--syntax-fn);
}
.readme :deep(blockquote[data-callout='important']::after) {
background-color: var(--syntax-fn);
-webkit-mask: icon('i-lucide:pin') no-repeat;
mask: icon('i-lucide:pin') no-repeat;
}
/* Warning - yellow/orange */
.readme :deep(blockquote[data-callout='warning']) {
border-inline-start-color: #eab308;
background: rgba(234, 179, 8, 0.05);
}
.readme :deep(blockquote[data-callout='warning']::before) {
content: var(--i18n-warning, 'Warning');
color: #eab308;
}
.readme :deep(blockquote[data-callout='warning']::after) {
background-color: #eab308;
-webkit-mask: icon('i-lucide:triangle-alert') no-repeat;
mask: icon('i-lucide:triangle-alert') no-repeat;
}
/* Caution - red */
.readme :deep(blockquote[data-callout='caution']) {
border-inline-start-color: #ef4444;
background: rgba(239, 68, 68, 0.05);
}
.readme :deep(blockquote[data-callout='caution']::before) {
content: var(--i18n-caution, 'Caution');
color: #ef4444;
}
.readme :deep(blockquote[data-callout='caution']::after) {
background-color: #ef4444;
-webkit-mask: icon('i-lucide:circle-alert') no-repeat;
mask: icon('i-lucide:circle-alert') no-repeat;
}
/* Table wrapper for horizontal scroll on mobile */
.readme :deep(table) {
display: block;
width: 100%;
overflow-x: auto;
border-collapse: collapse;
margin: 1.5rem 0;
font-size: 0.875rem;
word-break: keep-all;
}
.readme :deep(th),
.readme :deep(td) {
border: 1px solid var(--border);
padding: 0.75rem 1rem;
text-align: start;
}
.readme :deep(th) {
background: var(--bg-subtle);
color: var(--fg);
font-weight: 500;
}
.readme :deep(tr:hover) {
background: var(--bg-subtle);
}
.readme :deep(img) {
max-width: 100%;
height: revert-layer;
display: revert-layer;
border-radius: 8px;
margin: 1rem 0;
position: relative;
z-index: 1;
}
.readme :deep(video) {
height: revert-layer;
display: revert-layer;
}
.readme :deep(hr) {
border: none;
border-top: 1px solid var(--border);
margin: 2rem 0;
}
/* Badge images inline */
.readme :deep(p > a > img),
.readme :deep(p > img) {
display: inline-block;
margin: 0 0.25rem 0.25rem 0;
border-radius: 4px;
}
/* Screen reader only text */
.readme :deep(.sr-only) {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
/* Details element */
.readme :deep(details) {
/**
* same size as [data-level='5']
*/
font-size: 0.925rem;
color: var(--fg-subtle);
summary {
font-size: 1rem;
color: var(--fg-muted);
}
}
</style>