igniteui-astro-components 0.0.29 → 1.0.0
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.
- package/package.json +17 -14
- package/src/components/DocsSidebar/DocsSidebar.scss +3 -2
- package/src/components/DocsSidebar/SidebarFilterInput.scss +1 -3
- package/src/components/DocsSubHeader/DocsSubHeader.scss +1 -1
- package/src/components/DocsTree/docs-tree.scss +0 -1
- package/src/components/mdx/Sample/README.md +16 -10
- package/src/components/mdx/Sample/Sample.astro +156 -19
- package/src/components/mdx/Sample/Sample.scss +238 -9
- package/src/integration.ts +26 -14
- package/src/layouts/DocsLayout/DocsLayout.scss +0 -4
- package/src/plugins/rehype-heading-anchors.ts +53 -61
- package/src/plugins/rehype-pagefind-ignore.ts +19 -28
- package/src/plugins/rehype-table-wrapper.ts +38 -36
- package/src/plugins/remark-env-vars.ts +26 -20
- package/src/plugins/remark-html-transforms.ts +21 -18
- package/src/plugins/remark-md-links.ts +43 -31
- package/src/scripts/sample-widget.ts +288 -1
- package/src/styles/global/_code-blocks.scss +2 -23
- package/src/styles/global/_copy-button.scss +32 -0
- package/src/styles/global/_search-shared.scss +1 -1
- package/src/styles/global/_variables.scss +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
@use 'igniteui-theming/sass/typography' as *;
|
|
2
|
+
@use '../../../styles/global/copy-button' as *;
|
|
2
3
|
|
|
3
4
|
igc-tabs {
|
|
4
5
|
position: relative;
|
|
@@ -28,6 +29,7 @@ igc-tabs {
|
|
|
28
29
|
.igd-code-view__header-actions {
|
|
29
30
|
border-block: rem(1px) solid light-dark(var(--ig-gray-300), var(--ig-gray-200));
|
|
30
31
|
}
|
|
32
|
+
border-radius: rem(4px) rem(4px) 0 0;
|
|
31
33
|
|
|
32
34
|
.igd-sample-container {
|
|
33
35
|
border-inline: none;
|
|
@@ -51,23 +53,37 @@ igc-tab {
|
|
|
51
53
|
border: none;
|
|
52
54
|
border-top: rem(1px) solid var(--ig-gray-300);
|
|
53
55
|
max-height: rem(400px);
|
|
54
|
-
|
|
56
|
+
// Vertical scroll only — long lines wrap (see the pre below) instead of
|
|
57
|
+
// forcing a horizontal scrollbar on the pane.
|
|
58
|
+
overflow: hidden auto;
|
|
55
59
|
overscroll-behavior: contain;
|
|
56
60
|
|
|
57
61
|
pre {
|
|
58
62
|
margin: 0;
|
|
59
63
|
border: none;
|
|
60
|
-
|
|
64
|
+
// Same spacing token the EXAMPLE pane uses for `md`, so the code
|
|
65
|
+
// and the demo share the same breathing room (and both follow an
|
|
66
|
+
// --igd-sample-spacing-md override).
|
|
67
|
+
padding: var(--igd-sample-spacing-md, #{rem(16px)});
|
|
61
68
|
border-radius: 0;
|
|
69
|
+
white-space: pre-wrap;
|
|
70
|
+
word-break: break-word;
|
|
62
71
|
}
|
|
63
72
|
|
|
73
|
+
// Match the page-level CopyCode button (.copy-btn): flat variant, same
|
|
74
|
+
// 8px corner offset, and the shared palette — the code pane is always
|
|
75
|
+
// dark (single dark Shiki theme) while the button's default colors
|
|
76
|
+
// follow the site theme, so without the palette the icon was invisible
|
|
77
|
+
// in light mode until hovered.
|
|
64
78
|
.cv-hljs-code-copy {
|
|
65
79
|
position: absolute;
|
|
66
|
-
|
|
67
|
-
|
|
80
|
+
inset-block-start: rem(8px);
|
|
81
|
+
inset-inline-end: rem(8px);
|
|
68
82
|
opacity: 0;
|
|
69
83
|
transition: opacity 0.2s ease;
|
|
70
84
|
pointer-events: none;
|
|
85
|
+
|
|
86
|
+
@include copy-button-colors;
|
|
71
87
|
}
|
|
72
88
|
|
|
73
89
|
&:hover .cv-hljs-code-copy,
|
|
@@ -93,6 +109,7 @@ igc-tab::part(tab-header) {
|
|
|
93
109
|
.igd-code-view {
|
|
94
110
|
width: 100%;
|
|
95
111
|
border: rem(1px) solid var(--ig-gray-300);
|
|
112
|
+
border-radius: rem(4px);
|
|
96
113
|
margin-block-end: rem(26px);
|
|
97
114
|
|
|
98
115
|
.igd-sample-container {
|
|
@@ -108,17 +125,19 @@ igc-tab::part(tab-header) {
|
|
|
108
125
|
.igd-sample-container {
|
|
109
126
|
--sample-container-header-height: #{rem(66px)};
|
|
110
127
|
|
|
128
|
+
display: grid;
|
|
111
129
|
position: relative;
|
|
112
130
|
border: rem(1px) solid var(--ig-gray-300);
|
|
113
|
-
|
|
114
|
-
max-height: rem(800px);
|
|
115
|
-
overflow: hidden auto;
|
|
131
|
+
overflow: hidden;
|
|
116
132
|
margin-block-end: rem(26px);
|
|
133
|
+
z-index: 0;
|
|
134
|
+
background: light-dark(var(--ig-gray-100), var(--ig-surface-500));
|
|
117
135
|
|
|
118
136
|
iframe {
|
|
119
137
|
display: block;
|
|
120
138
|
border: none;
|
|
121
139
|
margin: 0;
|
|
140
|
+
overflow: hidden;
|
|
122
141
|
}
|
|
123
142
|
|
|
124
143
|
.sample-loading-indicator {
|
|
@@ -136,6 +155,217 @@ igc-tab::part(tab-header) {
|
|
|
136
155
|
&.loading .sample-loading-indicator {
|
|
137
156
|
opacity: 1;
|
|
138
157
|
}
|
|
158
|
+
|
|
159
|
+
// Fit-content mode: the embedded content dictates the size — the `height`
|
|
160
|
+
// prop is ignored (Sample.astro emits no inline height). sample-widget.ts
|
|
161
|
+
// sets an exact px height on the iframe (from same-origin measurement or a
|
|
162
|
+
// postMessage from the demo) and the frame/container grow around it,
|
|
163
|
+
// spacing padding included.
|
|
164
|
+
&--fit-content {
|
|
165
|
+
height: auto;
|
|
166
|
+
min-height: 0;
|
|
167
|
+
max-height: none;
|
|
168
|
+
// `clip` (not `visible`): the container is sized exactly to the iframe,
|
|
169
|
+
// and anything spilling out (e.g. the +1px grid-pattern ::after overlay)
|
|
170
|
+
// would otherwise inflate the ancestor igc-tabs' scrollWidth and lock its
|
|
171
|
+
// header into scroll-button mode.
|
|
172
|
+
overflow: clip;
|
|
173
|
+
|
|
174
|
+
iframe {
|
|
175
|
+
max-width: 100%;
|
|
176
|
+
// The iframe starts at the `height` placeholder and snaps to the
|
|
177
|
+
// measured content size once the demo loads/reports — ease that
|
|
178
|
+
// jump instead of letting the page reflow abruptly.
|
|
179
|
+
transition:
|
|
180
|
+
width 0.25s ease,
|
|
181
|
+
height 0.25s ease;
|
|
182
|
+
|
|
183
|
+
@media (prefers-reduced-motion: reduce) {
|
|
184
|
+
transition: none;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Drop the default border/outline drawn around the iframe.
|
|
190
|
+
&--no-border {
|
|
191
|
+
border: none;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Hide the grid-pattern backdrop drawn behind the iframe (the ::after
|
|
195
|
+
// overlay below) — the container becomes fully transparent, so demos
|
|
196
|
+
// without a background of their own sit directly on the page.
|
|
197
|
+
&--no-background {
|
|
198
|
+
background: transparent;
|
|
199
|
+
|
|
200
|
+
&::after {
|
|
201
|
+
display: none;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Wrapper around the iframe. In the default (block) layout it is transparent
|
|
206
|
+
// (fills the container just like the bare iframe did); when the container
|
|
207
|
+
// opts into flex layout it becomes the positioned/resizable element.
|
|
208
|
+
.igd-sample-frame {
|
|
209
|
+
position: relative;
|
|
210
|
+
width: 100%;
|
|
211
|
+
height: 100%;
|
|
212
|
+
max-width: 100%;
|
|
213
|
+
flex: 0 0 auto;
|
|
214
|
+
overflow: auto;
|
|
215
|
+
z-index: 1;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// In fit-content mode the frame hugs the JS-sized iframe instead of filling
|
|
219
|
+
// the container, so flex alignment (position) can move the content-sized box
|
|
220
|
+
// around. Must come after the base .igd-sample-frame rule — same specificity,
|
|
221
|
+
// order decides.
|
|
222
|
+
&--fit-content .igd-sample-frame {
|
|
223
|
+
// Height hugs the JS-sized iframe. Width intentionally stays 100% (base
|
|
224
|
+
// rule): a shrink-to-fit frame would make the iframe's `width: 100%`
|
|
225
|
+
// indefinite and collapse it to the 300px intrinsic default — inner
|
|
226
|
+
// horizontal scrollbars on every unmeasured/cross-origin demo. When a
|
|
227
|
+
// real content width is measured/reported, sample-widget.ts switches
|
|
228
|
+
// the frame to `width: auto` inline so flex alignment can center it.
|
|
229
|
+
height: auto;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Padding around the iframe. Applied by the host, never inside the demo.
|
|
233
|
+
// `md` is the default emitted by Sample.astro; `none` removes it entirely.
|
|
234
|
+
// Each size reads a CSS variable with the default as fallback, so consumers
|
|
235
|
+
// can retune the whole scale from any ancestor, e.g.
|
|
236
|
+
// :root { --igd-sample-spacing-md: 24px; }
|
|
237
|
+
&[data-spacing='none'] {
|
|
238
|
+
padding: 0;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
&[data-spacing='sm'] {
|
|
242
|
+
padding: var(--igd-sample-spacing-sm, #{rem(8px)});
|
|
243
|
+
|
|
244
|
+
.igd-code-view__header-actions {
|
|
245
|
+
margin-inline: calc(var(--igd-sample-spacing-sm, #{rem(8px)}) * -1);
|
|
246
|
+
margin-block-end: calc(var(--igd-sample-spacing-sm, #{rem(8px)}) * -1);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
&[data-spacing='md'] {
|
|
251
|
+
padding: var(--igd-sample-spacing-md, #{rem(16px)});
|
|
252
|
+
|
|
253
|
+
.igd-code-view__header-actions {
|
|
254
|
+
margin-inline: calc(var(--igd-sample-spacing-md, #{rem(16px)}) * -1);
|
|
255
|
+
margin-block-end: calc(var(--igd-sample-spacing-md, #{rem(16px)}) * -1);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
&[data-spacing='lg'] {
|
|
260
|
+
padding: var(--igd-sample-spacing-lg, #{rem(32px)});
|
|
261
|
+
|
|
262
|
+
.igd-code-view__header-actions {
|
|
263
|
+
margin-inline: calc(var(--igd-sample-spacing-lg, #{rem(32px)}) * -1);
|
|
264
|
+
margin-block-end: calc(var(--igd-sample-spacing-lg, #{rem(32px)}) * -1);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Flex layout — only enabled when position/resize needs it. The `position`
|
|
269
|
+
// prop is emitted as data-justify / data-valign attributes.
|
|
270
|
+
&--flex {
|
|
271
|
+
display: flex;
|
|
272
|
+
justify-content: flex-start;
|
|
273
|
+
align-items: stretch;
|
|
274
|
+
|
|
275
|
+
&[data-justify='start'] {
|
|
276
|
+
justify-content: flex-start;
|
|
277
|
+
}
|
|
278
|
+
&[data-justify='center'] {
|
|
279
|
+
justify-content: center;
|
|
280
|
+
}
|
|
281
|
+
&[data-justify='end'] {
|
|
282
|
+
justify-content: flex-end;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
&[data-valign='top'] {
|
|
286
|
+
align-items: flex-start;
|
|
287
|
+
}
|
|
288
|
+
&[data-valign='center'] {
|
|
289
|
+
align-items: center;
|
|
290
|
+
}
|
|
291
|
+
&[data-valign='bottom'] {
|
|
292
|
+
align-items: flex-end;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// A frame that fills the container has nothing to align, so give it slack
|
|
296
|
+
// on any axis that has an explicit (non-start/stretch) alignment. `start`
|
|
297
|
+
// keeps full width — it looks identical to the default. Resizing overrides
|
|
298
|
+
// the width inline, so this is only the initial state. Fit-content frames
|
|
299
|
+
// are excluded: there the measured content defines the frame size.
|
|
300
|
+
&[data-justify='center']:not([data-fit-content]) .igd-sample-frame,
|
|
301
|
+
&[data-justify='end']:not([data-fit-content]) .igd-sample-frame {
|
|
302
|
+
width: 65%;
|
|
303
|
+
}
|
|
304
|
+
&[data-valign]:not([data-fit-content]) .igd-sample-frame {
|
|
305
|
+
height: 65%;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Keep the fullscreen bar pinned to the bottom instead of becoming a
|
|
309
|
+
// flex sibling of the iframe frame.
|
|
310
|
+
> .igd-code-view__header-actions {
|
|
311
|
+
position: absolute;
|
|
312
|
+
inset-inline: 0;
|
|
313
|
+
inset-block-end: 0;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Resizable mode: a drag handle on the right edge resizes the iframe's width
|
|
318
|
+
// (see sample-widget.ts). The handle is always visible.
|
|
319
|
+
&--resizable {
|
|
320
|
+
&:focus-visible {
|
|
321
|
+
outline: rem(2px) solid var(--igd-accent);
|
|
322
|
+
outline-offset: rem(-2px);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// While dragging, stop the iframe from swallowing pointer moves.
|
|
327
|
+
&.resizing iframe {
|
|
328
|
+
pointer-events: none;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.igd-sample-resize-handle {
|
|
332
|
+
position: absolute;
|
|
333
|
+
inset-block: 0;
|
|
334
|
+
// Kept 16px off the edge at all times: the demo may show a vertical
|
|
335
|
+
// scrollbar at the iframe's right edge, and a handle sitting on top of
|
|
336
|
+
// it would intercept the pointer and make the scrollbar unusable.
|
|
337
|
+
inset-inline-end: rem(16px);
|
|
338
|
+
display: flex;
|
|
339
|
+
align-items: center;
|
|
340
|
+
justify-content: center;
|
|
341
|
+
width: rem(10px);
|
|
342
|
+
cursor: ew-resize;
|
|
343
|
+
touch-action: none;
|
|
344
|
+
z-index: 2;
|
|
345
|
+
|
|
346
|
+
&::before {
|
|
347
|
+
content: '';
|
|
348
|
+
width: rem(4px);
|
|
349
|
+
height: rem(32px);
|
|
350
|
+
border-radius: rem(2px);
|
|
351
|
+
background: light-dark(var(--ig-gray-500), var(--ig-gray-400));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Shod this conditionally
|
|
356
|
+
//&::after {
|
|
357
|
+
// position: absolute;
|
|
358
|
+
// inset: 0;
|
|
359
|
+
// width: calc(100% + 1px);
|
|
360
|
+
// height: calc(100% + 1px);
|
|
361
|
+
// content: '';
|
|
362
|
+
// background-color: #f9f9f9;
|
|
363
|
+
// opacity: 0.1;
|
|
364
|
+
// background-image: repeating-linear-gradient(to right, transparent 0, transparent 2px, #f9f9f9 2px, #f9f9f9 6px, transparent 6px, transparent 8px), repeating-linear-gradient(to bottom, transparent 0, transparent 2px, #f9f9f9 2px, #f9f9f9 6px, transparent 6px, transparent 8px), linear-gradient(to bottom, #000000 0.72px, transparent 0.72px), linear-gradient(to right, #000000 0.72px, transparent 0.72px) ;
|
|
365
|
+
// background-size: 100% 100%, 100% 100%, 24px 24px, 24px 24px;
|
|
366
|
+
// background-position: 0 0, 0 0, 0 -0.24px, -0.24px 0;
|
|
367
|
+
// z-index: 0;
|
|
368
|
+
//}
|
|
139
369
|
}
|
|
140
370
|
|
|
141
371
|
.full-screen-btn {
|
|
@@ -158,11 +388,10 @@ igc-tab::part(tab-header) {
|
|
|
158
388
|
}
|
|
159
389
|
|
|
160
390
|
.igd-code-view__header-actions {
|
|
161
|
-
position: sticky;
|
|
162
|
-
inset-block-end: 0;
|
|
163
391
|
height: var(--sample-container-header-height);
|
|
164
392
|
border-block-start: rem(1px) solid var(--ig-gray-300);
|
|
165
393
|
background-color: var(--igd-layout-sections-bg);
|
|
394
|
+
z-index: 1;
|
|
166
395
|
}
|
|
167
396
|
|
|
168
397
|
igc-button {
|
package/src/integration.ts
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* { tag: 'link', attrs: { rel: 'stylesheet', href: '...' } },
|
|
26
26
|
* ],
|
|
27
27
|
* // Extra Astro options (markdown, image, build, …)
|
|
28
|
-
* markdown: {
|
|
28
|
+
* markdown: { mdastPlugins: [], hastPlugins: [] },
|
|
29
29
|
* });
|
|
30
30
|
*
|
|
31
31
|
* --- Option B: manual composition (for full control) ---
|
|
@@ -66,6 +66,7 @@ import {
|
|
|
66
66
|
import { buildSidebarFromToc } from './sidebar';
|
|
67
67
|
import { getPlatformHead } from './platform';
|
|
68
68
|
import type { HeadEntry, PlatformKey, NavLang } from './platform.ts';
|
|
69
|
+
import { satteri } from '@astrojs/markdown-satteri';
|
|
69
70
|
import { remarkEnvVars } from './plugins/remark-env-vars';
|
|
70
71
|
export { rehypeTableWrapper } from './plugins/rehype-table-wrapper';
|
|
71
72
|
import { rehypeTableWrapper } from './plugins/rehype-table-wrapper';
|
|
@@ -699,6 +700,13 @@ export function createDocsSite(
|
|
|
699
700
|
return defineConfig({
|
|
700
701
|
site,
|
|
701
702
|
...(base !== undefined ? { base } : {}),
|
|
703
|
+
// Astro 7 defaults to `compressHTML: 'jsx'`, which drops whitespace between
|
|
704
|
+
// inline elements entirely instead of collapsing it to a single space. That
|
|
705
|
+
// silently joins adjacent text — breadcrumb segments, badge labels and callout
|
|
706
|
+
// titles render as "Open SourceIgnite UI" / "InfoThe -y flag". Keeping the
|
|
707
|
+
// Astro 6 behaviour preserves the rendered copy; switch to 'jsx' only after
|
|
708
|
+
// auditing templates for the inline pairs that need an explicit {" "}.
|
|
709
|
+
compressHTML: true,
|
|
702
710
|
// Docs sites serve images statically — disable Astro's image optimization
|
|
703
711
|
// so relative image paths in markdown don't cause build errors.
|
|
704
712
|
image: { service: { entrypoint: 'astro/assets/services/noop' }, ...(astroExtra as any).image },
|
|
@@ -715,19 +723,23 @@ export function createDocsSite(
|
|
|
715
723
|
},
|
|
716
724
|
markdown: {
|
|
717
725
|
...(astroExtra as any).markdown,
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
726
|
+
// Astro 7 renders Markdown/MDX with Sätteri instead of remark/rehype.
|
|
727
|
+
// MDAST plugins run before HAST plugins, matching the old
|
|
728
|
+
// remarkPlugins-then-rehypePlugins ordering.
|
|
729
|
+
processor: satteri({
|
|
730
|
+
mdastPlugins: [
|
|
731
|
+
remarkEnvVars,
|
|
732
|
+
remarkMdLinks,
|
|
733
|
+
remarkHtmlTransforms,
|
|
734
|
+
...((astroExtra as any).markdown?.mdastPlugins ?? []),
|
|
735
|
+
],
|
|
736
|
+
hastPlugins: [
|
|
737
|
+
rehypeTableWrapper,
|
|
738
|
+
rehypeHeadingAnchors,
|
|
739
|
+
rehypePagefindIgnore,
|
|
740
|
+
...((astroExtra as any).markdown?.hastPlugins ?? []),
|
|
741
|
+
],
|
|
742
|
+
}),
|
|
731
743
|
},
|
|
732
744
|
integrations: [
|
|
733
745
|
siteMetaIntegration({
|
|
@@ -86,9 +86,6 @@
|
|
|
86
86
|
// ════════════════════════════════════════════════════════════════════════════
|
|
87
87
|
|
|
88
88
|
@media (min-width: #{$bp-desktop-wide}) {
|
|
89
|
-
.igd-page-layout {
|
|
90
|
-
--igd-page-layout-grid: #{rem(400px)} 1fr;
|
|
91
|
-
}
|
|
92
89
|
|
|
93
90
|
.igd-main-content__page {
|
|
94
91
|
gap: var(--ig-padding);
|
|
@@ -189,7 +186,6 @@
|
|
|
189
186
|
|
|
190
187
|
// This is the height of the input in fluent theme + 8px padding + height of the logo above
|
|
191
188
|
.sidebar-gutter {
|
|
192
|
-
min-height: rem(80px);
|
|
193
189
|
align-items: center;
|
|
194
190
|
}
|
|
195
191
|
}
|
|
@@ -1,74 +1,66 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineHastPlugin } from 'satteri';
|
|
2
2
|
import Slugger from 'github-slugger';
|
|
3
3
|
|
|
4
|
-
const HEADING_TAGS =
|
|
5
|
-
|
|
6
|
-
// Extract the text content of a hast node (ignores child elements, reads text/raw nodes).
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
-
function textContent(node: any): string {
|
|
9
|
-
let text = '';
|
|
10
|
-
visit(node, (child) => {
|
|
11
|
-
if (child.type === 'text' || child.type === 'raw') text += child.value ?? '';
|
|
12
|
-
});
|
|
13
|
-
return text;
|
|
14
|
-
}
|
|
4
|
+
const HEADING_TAGS = ['h2', 'h3', 'h4', 'h5', 'h6'];
|
|
15
5
|
|
|
16
6
|
/**
|
|
17
|
-
*
|
|
7
|
+
* Sätteri HAST plugin that appends a copy-link icon button to every heading
|
|
18
8
|
* (h2–h6).
|
|
19
9
|
*
|
|
20
|
-
* Runs before Astro's internal
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
10
|
+
* Runs before Astro's internal heading-id pass so it must generate its own slug
|
|
11
|
+
* using the same `github-slugger` algorithm. If the heading already has an `id`
|
|
12
|
+
* (e.g. set in raw HTML), it is reused. Headings without an existing id get one
|
|
13
|
+
* assigned here — the built-in pass will then see the id already present and
|
|
14
|
+
* skip re-assigning it, ensuring the button href and the heading's id always
|
|
15
|
+
* match.
|
|
16
|
+
*
|
|
17
|
+
* Exported as a factory so Sätteri calls it once per document, giving each page
|
|
18
|
+
* a fresh slugger and therefore a fresh duplicate-suffix counter.
|
|
26
19
|
*/
|
|
27
20
|
export function rehypeHeadingAnchors() {
|
|
28
|
-
|
|
29
|
-
return (tree: any) => {
|
|
30
|
-
const slugger = new Slugger();
|
|
31
|
-
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
-
visit(tree, 'element', (node: any) => {
|
|
34
|
-
if (!HEADING_TAGS.has(node.tagName)) return;
|
|
21
|
+
const slugger = new Slugger();
|
|
35
22
|
|
|
36
|
-
|
|
23
|
+
return defineHastPlugin({
|
|
24
|
+
name: 'heading-anchors',
|
|
25
|
+
element: {
|
|
26
|
+
filter: HEADING_TAGS,
|
|
27
|
+
visit(node, ctx) {
|
|
28
|
+
// Reuse an existing id or generate one from heading text.
|
|
29
|
+
const existing = node.properties?.id;
|
|
30
|
+
let id: string;
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
if (typeof existing === 'string' && existing) {
|
|
33
|
+
// Keep slugger in sync so it doesn't generate duplicate ids.
|
|
34
|
+
slugger.slug(existing);
|
|
35
|
+
id = existing;
|
|
36
|
+
} else {
|
|
37
|
+
id = slugger.slug(ctx.textContent(node));
|
|
38
|
+
ctx.setProperty(node, 'id', id);
|
|
39
|
+
}
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
'aria-label': 'Link to this section',
|
|
56
|
-
tabIndex: 0,
|
|
57
|
-
},
|
|
58
|
-
children: [
|
|
59
|
-
{
|
|
60
|
-
type: 'element',
|
|
61
|
-
tagName: 'igc-icon',
|
|
62
|
-
properties: {
|
|
63
|
-
name: 'link',
|
|
64
|
-
collection: 'docs',
|
|
65
|
-
},
|
|
66
|
-
children: [],
|
|
41
|
+
ctx.appendChild(node, {
|
|
42
|
+
type: 'element',
|
|
43
|
+
tagName: 'igc-icon-button',
|
|
44
|
+
properties: {
|
|
45
|
+
class: 'igd-anchor-link',
|
|
46
|
+
href: `#${id}`,
|
|
47
|
+
variant: 'flat',
|
|
48
|
+
'aria-label': 'Link to this section',
|
|
49
|
+
tabIndex: 0,
|
|
67
50
|
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
51
|
+
children: [
|
|
52
|
+
{
|
|
53
|
+
type: 'element',
|
|
54
|
+
tagName: 'igc-icon',
|
|
55
|
+
properties: {
|
|
56
|
+
name: 'link',
|
|
57
|
+
collection: 'docs',
|
|
58
|
+
},
|
|
59
|
+
children: [],
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
74
66
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineHastPlugin } from 'satteri';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Marks code with `data-pagefind-ignore` so Pagefind doesn't index it.
|
|
@@ -8,33 +8,24 @@ import { visit } from 'unist-util-visit';
|
|
|
8
8
|
* `keyof T` across unrelated pages. Excluding `<pre>` (and single-char inline
|
|
9
9
|
* `<code>`) removes that noise; real inline `<code>` like `dataSource` stays.
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
// Concatenate all descendant text of a HAST node.
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
function textContent(node: any): string {
|
|
15
|
-
if (node.type === 'text') return node.value ?? '';
|
|
16
|
-
if (!node.children) return '';
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
-
return node.children.map((c: any) => textContent(c)).join('');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
11
|
export function rehypePagefindIgnore() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
return defineHastPlugin({
|
|
13
|
+
name: 'pagefind-ignore',
|
|
14
|
+
element: {
|
|
15
|
+
filter: ['pre', 'code'],
|
|
16
|
+
visit(node, ctx) {
|
|
17
|
+
// Fenced code blocks (covers their inner <code> via subtree ignore).
|
|
18
|
+
if (node.tagName === 'pre') {
|
|
19
|
+
ctx.setProperty(node, 'data-pagefind-ignore', 'all');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
32
22
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
// Inline code that reduces to a single alphanumeric token.
|
|
24
|
+
const token = ctx.textContent(node).replace(/[^a-z0-9]/gi, '');
|
|
25
|
+
if (token.length <= 1) {
|
|
26
|
+
ctx.setProperty(node, 'data-pagefind-ignore', 'all');
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
});
|
|
40
31
|
}
|
|
@@ -1,49 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
let _counter = 0;
|
|
1
|
+
import { defineHastPlugin } from 'satteri';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
|
-
*
|
|
4
|
+
* Sätteri HAST plugin that wraps every <table> in a scroll container div.
|
|
7
5
|
* The wrapper is fully accessible per the recommendations in:
|
|
8
6
|
* https://piccalil.li/blog/styling-tables-the-modern-css-way/
|
|
9
7
|
*
|
|
10
8
|
* - role="region" + aria-labelledby pointing to the <caption> (or a generated id)
|
|
11
9
|
* - tabindex="0" makes the scroll region keyboard-focusable
|
|
10
|
+
*
|
|
11
|
+
* Exported as a factory so Sätteri calls it once per document, resetting the id
|
|
12
|
+
* counter — these ids only have to be unique within a single page.
|
|
12
13
|
*/
|
|
13
14
|
export function rehypeTableWrapper() {
|
|
14
|
-
|
|
15
|
-
return (tree: any) => {
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
-
visit(tree, 'element', (node: any, index: number | undefined, parent: any) => {
|
|
18
|
-
if (node.tagName !== 'table' || !parent || index == null) return;
|
|
19
|
-
|
|
20
|
-
// Find an existing <caption> to use as the accessible label.
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
const caption = node.children?.find((c: any) => c.tagName === 'caption');
|
|
23
|
-
let labelId: string;
|
|
15
|
+
let counter = 0;
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
return defineHastPlugin({
|
|
18
|
+
name: 'table-wrapper',
|
|
19
|
+
element: {
|
|
20
|
+
filter: ['table'],
|
|
21
|
+
visit(node, ctx) {
|
|
22
|
+
// Find an existing <caption> to use as the accessible label.
|
|
23
|
+
const caption = node.children?.find((c) => c.type === 'element' && c.tagName === 'caption');
|
|
24
|
+
let labelId: string;
|
|
33
25
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
26
|
+
if (caption && caption.type === 'element') {
|
|
27
|
+
// Reuse or assign an id on the caption element.
|
|
28
|
+
const existing = caption.properties?.id;
|
|
29
|
+
labelId =
|
|
30
|
+
typeof existing === 'string' && existing ? existing : `igd-table-caption-${++counter}`;
|
|
31
|
+
ctx.setProperty(caption, 'id', labelId);
|
|
32
|
+
} else {
|
|
33
|
+
// No caption — generate a unique id for the wrapper itself.
|
|
34
|
+
labelId = `igd-table-${++counter}`;
|
|
35
|
+
}
|
|
45
36
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
ctx.wrapNode(node, {
|
|
38
|
+
type: 'element',
|
|
39
|
+
tagName: 'div',
|
|
40
|
+
properties: {
|
|
41
|
+
className: ['igd-table-wrapper'],
|
|
42
|
+
role: 'region',
|
|
43
|
+
'aria-labelledby': labelId,
|
|
44
|
+
tabIndex: 0,
|
|
45
|
+
},
|
|
46
|
+
children: [],
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
49
51
|
}
|