svelte-docsmith 0.12.1 → 0.12.2
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.
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
{/if}
|
|
99
99
|
|
|
100
100
|
<pre
|
|
101
|
-
class="not-prose shiki max-h-[32rem] flex shrink"
|
|
101
|
+
class="docsmith-code not-prose shiki max-h-[32rem] flex shrink"
|
|
102
102
|
class:docsmith-line-numbers={lineNumbers}
|
|
103
103
|
style={lineNumbers && startLine !== 1 ? `--docsmith-line-start: ${startLine - 1}` : undefined}
|
|
104
104
|
use:clipboard.readText>
|
|
@@ -113,8 +113,17 @@
|
|
|
113
113
|
* published package, where the consumer's Tailwind theme context isn't
|
|
114
114
|
* available to resolve @apply (Tailwind v4 compiles scoped styles in
|
|
115
115
|
* isolation).
|
|
116
|
+
*
|
|
117
|
+
* Shiki's markup arrives through `{@html}`, so Svelte cannot scope these for
|
|
118
|
+
* us and they have to be global. Every one is therefore anchored on
|
|
119
|
+
* `pre.docsmith-code`, the class this component puts on its own element.
|
|
120
|
+
* Anchoring on the bare element instead would restyle every code block on
|
|
121
|
+
* the page, including ones this component never rendered — and since a
|
|
122
|
+
* route's CSS only arrives when that route loads (SvelteKit preloads on
|
|
123
|
+
* link hover), the restyle would land mid-session and shift the layout
|
|
124
|
+
* under the pointer.
|
|
116
125
|
*/
|
|
117
|
-
:global(pre code) {
|
|
126
|
+
:global(pre.docsmith-code code) {
|
|
118
127
|
display: block;
|
|
119
128
|
flex-grow: 1;
|
|
120
129
|
height: 100%;
|
|
@@ -122,7 +131,7 @@
|
|
|
122
131
|
padding-block: 1rem;
|
|
123
132
|
}
|
|
124
133
|
|
|
125
|
-
:global(pre span.line) {
|
|
134
|
+
:global(pre.docsmith-code span.line) {
|
|
126
135
|
display: inline-block;
|
|
127
136
|
width: 100%;
|
|
128
137
|
padding-inline: 1rem;
|
|
@@ -149,15 +158,15 @@
|
|
|
149
158
|
A CSS counter on Shiki's existing per-line spans, so numbering adds no DOM
|
|
150
159
|
and stays out of the text the copy button reads. `--docsmith-line-start`
|
|
151
160
|
offsets the counter for a snippet lifted out of a larger file. */
|
|
152
|
-
:global(pre.docsmith-line-numbers code) {
|
|
161
|
+
:global(pre.docsmith-code.docsmith-line-numbers code) {
|
|
153
162
|
counter-reset: docsmith-line var(--docsmith-line-start, 0);
|
|
154
163
|
}
|
|
155
|
-
:global(pre.docsmith-line-numbers span.line) {
|
|
164
|
+
:global(pre.docsmith-code.docsmith-line-numbers span.line) {
|
|
156
165
|
counter-increment: docsmith-line;
|
|
157
166
|
position: relative;
|
|
158
167
|
padding-inline-start: 3.2rem;
|
|
159
168
|
}
|
|
160
|
-
:global(pre.docsmith-line-numbers span.line::before) {
|
|
169
|
+
:global(pre.docsmith-code.docsmith-line-numbers span.line::before) {
|
|
161
170
|
content: counter(docsmith-line);
|
|
162
171
|
position: absolute;
|
|
163
172
|
left: 0;
|
|
@@ -169,19 +178,19 @@
|
|
|
169
178
|
user-select: none;
|
|
170
179
|
}
|
|
171
180
|
/* The diff gutter glyph would collide with the number, so shift it over. */
|
|
172
|
-
:global(pre.docsmith-line-numbers span.line.diff::before) {
|
|
181
|
+
:global(pre.docsmith-code.docsmith-line-numbers span.line.diff::before) {
|
|
173
182
|
content: counter(docsmith-line);
|
|
174
183
|
}
|
|
175
|
-
:global(pre.docsmith-line-numbers span.line.diff::after) {
|
|
184
|
+
:global(pre.docsmith-code.docsmith-line-numbers span.line.diff::after) {
|
|
176
185
|
position: absolute;
|
|
177
186
|
left: 2.7rem;
|
|
178
187
|
font-weight: 600;
|
|
179
188
|
}
|
|
180
|
-
:global(pre.docsmith-line-numbers span.line.diff.add::after) {
|
|
189
|
+
:global(pre.docsmith-code.docsmith-line-numbers span.line.diff.add::after) {
|
|
181
190
|
content: '+';
|
|
182
191
|
color: oklch(0.6 0.15 150);
|
|
183
192
|
}
|
|
184
|
-
:global(pre.docsmith-line-numbers span.line.diff.remove::after) {
|
|
193
|
+
:global(pre.docsmith-code.docsmith-line-numbers span.line.diff.remove::after) {
|
|
185
194
|
content: '−';
|
|
186
195
|
color: oklch(0.58 0.19 25);
|
|
187
196
|
}
|
|
@@ -193,76 +202,76 @@
|
|
|
193
202
|
the code background via color-mix. */
|
|
194
203
|
|
|
195
204
|
/* --- Line highlight (// [!code highlight] and {1,3} meta) --- */
|
|
196
|
-
:global(pre span.line.highlighted) {
|
|
205
|
+
:global(pre.docsmith-code span.line.highlighted) {
|
|
197
206
|
background: color-mix(in oklch, var(--primary) 12%, transparent);
|
|
198
207
|
}
|
|
199
|
-
:global(.dark pre span.line.highlighted) {
|
|
208
|
+
:global(.dark pre.docsmith-code span.line.highlighted) {
|
|
200
209
|
background: color-mix(in oklch, var(--primary) 20%, transparent);
|
|
201
210
|
}
|
|
202
211
|
|
|
203
212
|
/* --- Diff (// [!code ++] / [!code --]) with +/- gutter glyphs --- */
|
|
204
|
-
:global(pre span.line.diff) {
|
|
213
|
+
:global(pre.docsmith-code span.line.diff) {
|
|
205
214
|
position: relative;
|
|
206
215
|
}
|
|
207
|
-
:global(pre span.line.diff.add) {
|
|
216
|
+
:global(pre.docsmith-code span.line.diff.add) {
|
|
208
217
|
background: color-mix(in oklch, oklch(0.7 0.16 150) 15%, transparent);
|
|
209
218
|
}
|
|
210
|
-
:global(pre span.line.diff.remove) {
|
|
219
|
+
:global(pre.docsmith-code span.line.diff.remove) {
|
|
211
220
|
background: color-mix(in oklch, oklch(0.62 0.2 25) 14%, transparent);
|
|
212
221
|
}
|
|
213
|
-
:global(.dark pre span.line.diff.add) {
|
|
222
|
+
:global(.dark pre.docsmith-code span.line.diff.add) {
|
|
214
223
|
background: color-mix(in oklch, oklch(0.7 0.16 150) 22%, transparent);
|
|
215
224
|
}
|
|
216
|
-
:global(.dark pre span.line.diff.remove) {
|
|
225
|
+
:global(.dark pre.docsmith-code span.line.diff.remove) {
|
|
217
226
|
background: color-mix(in oklch, oklch(0.62 0.2 25) 22%, transparent);
|
|
218
227
|
}
|
|
219
|
-
:global(pre span.line.diff::before) {
|
|
228
|
+
:global(pre.docsmith-code span.line.diff::before) {
|
|
220
229
|
position: absolute;
|
|
221
230
|
left: 0.45rem;
|
|
222
231
|
font-weight: 600;
|
|
223
232
|
}
|
|
224
|
-
:global(pre span.line.diff.add::before) {
|
|
233
|
+
:global(pre.docsmith-code span.line.diff.add::before) {
|
|
225
234
|
content: '+';
|
|
226
235
|
color: oklch(0.6 0.15 150);
|
|
227
236
|
}
|
|
228
|
-
:global(pre span.line.diff.remove::before) {
|
|
237
|
+
:global(pre.docsmith-code span.line.diff.remove::before) {
|
|
229
238
|
content: '−';
|
|
230
239
|
color: oklch(0.58 0.19 25);
|
|
231
240
|
}
|
|
232
|
-
:global(.dark pre span.line.diff.add::before) {
|
|
241
|
+
:global(.dark pre.docsmith-code span.line.diff.add::before) {
|
|
233
242
|
color: oklch(0.78 0.17 150);
|
|
234
243
|
}
|
|
235
|
-
:global(.dark pre span.line.diff.remove::before) {
|
|
244
|
+
:global(.dark pre.docsmith-code span.line.diff.remove::before) {
|
|
236
245
|
color: oklch(0.72 0.18 25);
|
|
237
246
|
}
|
|
238
247
|
|
|
239
248
|
/* --- Error / warning severity (// [!code error] / [!code warning]).
|
|
240
249
|
No gutter glyph, so they stay distinct from the +/- diff lines. --- */
|
|
241
|
-
:global(pre span.line.highlighted.error) {
|
|
250
|
+
:global(pre.docsmith-code span.line.highlighted.error) {
|
|
242
251
|
background: color-mix(in oklch, oklch(0.62 0.2 25) 18%, transparent);
|
|
243
252
|
}
|
|
244
|
-
:global(pre span.line.highlighted.warning) {
|
|
253
|
+
:global(pre.docsmith-code span.line.highlighted.warning) {
|
|
245
254
|
background: color-mix(in oklch, oklch(0.8 0.13 85) 22%, transparent);
|
|
246
255
|
}
|
|
247
|
-
:global(.dark pre span.line.highlighted.error) {
|
|
256
|
+
:global(.dark pre.docsmith-code span.line.highlighted.error) {
|
|
248
257
|
background: color-mix(in oklch, oklch(0.62 0.2 25) 26%, transparent);
|
|
249
258
|
}
|
|
250
|
-
:global(.dark pre span.line.highlighted.warning) {
|
|
259
|
+
:global(.dark pre.docsmith-code span.line.highlighted.warning) {
|
|
251
260
|
background: color-mix(in oklch, oklch(0.8 0.13 85) 20%, transparent);
|
|
252
261
|
}
|
|
253
262
|
|
|
254
263
|
/* --- Focus (// [!code focus]): dim the other lines and restore on hover.
|
|
255
264
|
A clean opacity fade reads calmer than a muddy blur. `:has` recreates
|
|
256
265
|
Shiki's stripped container flag from the line classes alone. --- */
|
|
257
|
-
:global(pre code:has(span.line.focused) span.line:not(.focused)) {
|
|
266
|
+
:global(pre.docsmith-code code:has(span.line.focused) span.line:not(.focused)) {
|
|
258
267
|
opacity: 0.42;
|
|
259
268
|
transition: opacity 0.25s ease;
|
|
260
269
|
}
|
|
261
|
-
:global(pre:hover code:has(span.line.focused) span.line:not(.focused)) {
|
|
270
|
+
:global(pre.docsmith-code:hover code:has(span.line.focused) span.line:not(.focused)) {
|
|
262
271
|
opacity: 1;
|
|
263
272
|
}
|
|
264
273
|
@media (prefers-reduced-motion: reduce) {
|
|
265
|
-
:global(pre code:has(span.line.focused) span.line:not(.focused)) {
|
|
274
|
+
:global(pre.docsmith-code code:has(span.line.focused) span.line:not(.focused)) {
|
|
266
275
|
transition: none;
|
|
267
276
|
}
|
|
268
277
|
}
|
|
@@ -273,11 +282,11 @@
|
|
|
273
282
|
inspectable; the popup is a hidden sibling revealed on hover. `unclipPopups`
|
|
274
283
|
then promotes it to fixed positioning so the code block's scrolling does not
|
|
275
284
|
clip it — see the comment there. */
|
|
276
|
-
:global(pre .twoslash-hover) {
|
|
285
|
+
:global(pre.docsmith-code .twoslash-hover) {
|
|
277
286
|
position: relative;
|
|
278
287
|
border-bottom: 1px dotted color-mix(in oklch, var(--muted-foreground) 55%, transparent);
|
|
279
288
|
}
|
|
280
|
-
:global(pre .twoslash-popup-container) {
|
|
289
|
+
:global(pre.docsmith-code .twoslash-popup-container) {
|
|
281
290
|
position: absolute;
|
|
282
291
|
z-index: 40;
|
|
283
292
|
display: none;
|
|
@@ -298,11 +307,11 @@
|
|
|
298
307
|
font-size: 0.85em;
|
|
299
308
|
line-height: 1.5;
|
|
300
309
|
}
|
|
301
|
-
:global(pre .twoslash-hover:hover .twoslash-popup-container) {
|
|
310
|
+
:global(pre.docsmith-code .twoslash-hover:hover .twoslash-popup-container) {
|
|
302
311
|
display: block;
|
|
303
312
|
}
|
|
304
313
|
/* The signature keeps Shiki's own colours and monospace. */
|
|
305
|
-
:global(pre .twoslash-popup-code) {
|
|
314
|
+
:global(pre.docsmith-code .twoslash-popup-code) {
|
|
306
315
|
display: block;
|
|
307
316
|
font-family: var(--font-mono, ui-monospace, monospace);
|
|
308
317
|
white-space: pre-wrap;
|
|
@@ -311,7 +320,7 @@
|
|
|
311
320
|
/* Prose, by contrast, is prose. Inside a <pre> it would otherwise inherit
|
|
312
321
|
monospace and whatever token colour the hovered span happened to carry,
|
|
313
322
|
which reads as more code rather than an explanation of it. */
|
|
314
|
-
:global(pre .twoslash-popup-docs) {
|
|
323
|
+
:global(pre.docsmith-code .twoslash-popup-docs) {
|
|
315
324
|
/* The dark-theme swap repaints every span inside `.shiki` with
|
|
316
325
|
`--shiki-dark`, which these spans inherit from whichever token was
|
|
317
326
|
hovered — so docs took on the colour of the word above them. Redefining
|
|
@@ -330,20 +339,20 @@
|
|
|
330
339
|
|
|
331
340
|
/* Each @param is its own line: the tags are inline spans, so without this
|
|
332
341
|
they run together into one paragraph. */
|
|
333
|
-
:global(pre .twoslash-popup-docs-tags) {
|
|
342
|
+
:global(pre.docsmith-code .twoslash-popup-docs-tags) {
|
|
334
343
|
display: flex;
|
|
335
344
|
flex-direction: column;
|
|
336
345
|
gap: 0.35rem;
|
|
337
346
|
}
|
|
338
|
-
:global(pre .twoslash-popup-docs-tag) {
|
|
347
|
+
:global(pre.docsmith-code .twoslash-popup-docs-tag) {
|
|
339
348
|
display: block;
|
|
340
349
|
}
|
|
341
|
-
:global(pre .twoslash-popup-docs-tag-value) {
|
|
350
|
+
:global(pre.docsmith-code .twoslash-popup-docs-tag-value) {
|
|
342
351
|
--shiki-dark: var(--muted-foreground);
|
|
343
352
|
color: var(--muted-foreground);
|
|
344
353
|
}
|
|
345
354
|
/* And the tag name needs a gap, or it reads as "@paramcallbackfn". */
|
|
346
|
-
:global(pre .twoslash-popup-docs-tag-name) {
|
|
355
|
+
:global(pre.docsmith-code .twoslash-popup-docs-tag-name) {
|
|
347
356
|
--shiki-dark: var(--primary);
|
|
348
357
|
margin-right: 0.4em;
|
|
349
358
|
font-family: var(--font-mono, ui-monospace, monospace);
|
|
@@ -351,18 +360,18 @@
|
|
|
351
360
|
color: var(--primary);
|
|
352
361
|
}
|
|
353
362
|
/* A snippet that deliberately shows an error (// @errors:) marks the line. */
|
|
354
|
-
:global(pre .twoslash-error) {
|
|
363
|
+
:global(pre.docsmith-code .twoslash-error) {
|
|
355
364
|
background: color-mix(in oklch, oklch(0.62 0.2 25) 14%, transparent);
|
|
356
365
|
}
|
|
357
366
|
|
|
358
367
|
/* --- Word highlight (// [!code word:name]): a primary-tinted inline pill --- */
|
|
359
|
-
:global(pre .highlighted-word) {
|
|
368
|
+
:global(pre.docsmith-code .highlighted-word) {
|
|
360
369
|
border-radius: 0.3rem;
|
|
361
370
|
padding: 0.1rem 0.3rem;
|
|
362
371
|
background: color-mix(in oklch, var(--primary) 16%, transparent);
|
|
363
372
|
box-shadow: 0 0 0 1px color-mix(in oklch, var(--primary) 35%, transparent);
|
|
364
373
|
}
|
|
365
|
-
:global(.dark pre .highlighted-word) {
|
|
374
|
+
:global(.dark pre.docsmith-code .highlighted-word) {
|
|
366
375
|
background: color-mix(in oklch, var(--primary) 24%, transparent);
|
|
367
376
|
}
|
|
368
377
|
</style>
|