@writedocs/generator 0.10.9 → 0.10.10
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
CHANGED
|
@@ -57,8 +57,8 @@ interface Props {
|
|
|
57
57
|
// src/scripts/image-zoom.ts) - rendered as a bare `nozoom` attribute
|
|
58
58
|
// on both <img> tags, the same attribute a raw
|
|
59
59
|
// `<img nozoom src="..." />` written directly in MDX would carry, so
|
|
60
|
-
//
|
|
61
|
-
//
|
|
60
|
+
// lib/image-zoom-rules.js handles both cases identically rather than
|
|
61
|
+
// needing to special-case this component.
|
|
62
62
|
noZoom?: boolean;
|
|
63
63
|
}
|
|
64
64
|
const { src, srcDark, size, alt = "", caption, noZoom } = Astro.props as Props;
|
|
@@ -45,11 +45,31 @@ const { defaultTabIndex = 0 } = Astro.props as Props;
|
|
|
45
45
|
document.addEventListener('astro:page-load', () => initTabs(document));
|
|
46
46
|
</script>
|
|
47
47
|
<style is:global>
|
|
48
|
+
/* A border around the whole component - the tabs and the open tab's
|
|
49
|
+
content - so it's clear where it ends and the page goes on. */
|
|
50
|
+
.wd-tabs {
|
|
51
|
+
margin: 1.25rem 0;
|
|
52
|
+
border: 1px solid var(--wd-border);
|
|
53
|
+
border-radius: 0.6rem;
|
|
54
|
+
}
|
|
48
55
|
.wd-tabs-nav {
|
|
49
56
|
display: flex;
|
|
57
|
+
flex-wrap: wrap;
|
|
50
58
|
gap: 0.25rem;
|
|
59
|
+
padding: 0 0.5rem;
|
|
51
60
|
border-bottom: 1px solid var(--wd-border);
|
|
52
|
-
|
|
61
|
+
}
|
|
62
|
+
.wd-tab {
|
|
63
|
+
padding: 1rem 1.1rem;
|
|
64
|
+
min-width: 0;
|
|
65
|
+
}
|
|
66
|
+
/* The first thing shown - after the hidden icon a tab with `icon` holds. */
|
|
67
|
+
.wd-tab > :first-child,
|
|
68
|
+
.wd-tab > [hidden]:first-child + * {
|
|
69
|
+
margin-top: 0;
|
|
70
|
+
}
|
|
71
|
+
.wd-tab > :last-child {
|
|
72
|
+
margin-bottom: 0;
|
|
53
73
|
}
|
|
54
74
|
.wd-tabs-btn {
|
|
55
75
|
background: none;
|
|
@@ -59,6 +79,8 @@ const { defaultTabIndex = 0 } = Astro.props as Props;
|
|
|
59
79
|
font-size: 0.9rem;
|
|
60
80
|
color: var(--wd-text);
|
|
61
81
|
border-bottom: 2px solid transparent;
|
|
82
|
+
/* The current tab's underline sits on the row's bottom border. */
|
|
83
|
+
margin-bottom: -1px;
|
|
62
84
|
}
|
|
63
85
|
.wd-tabs-btn {
|
|
64
86
|
display: inline-flex;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Which page images open in the zoom lightbox (src/scripts/image-zoom.ts).
|
|
2
|
+
// Plain JavaScript, so scripts/image-zoom-rules.test.js can check it.
|
|
3
|
+
//
|
|
4
|
+
// Every image in a page's article zooms, except:
|
|
5
|
+
// - one opted out with `noZoom` (`<img noZoom>`, `<Image noZoom>`) - the
|
|
6
|
+
// DOM sees it as `nozoom`, since attribute names aren't case-sensitive;
|
|
7
|
+
// - a component's own picture - a Card's header image (.wd-card-image), an
|
|
8
|
+
// Icon's image (.wd-icon-image), anything in a Tile's preview
|
|
9
|
+
// (.wd-tile-preview): part of the component, not content to inspect;
|
|
10
|
+
// - an image inside a link (`[](/page/)`, `<a><img></a>`, a Tile
|
|
11
|
+
// or Card with `href`) - a click follows the link instead.
|
|
12
|
+
|
|
13
|
+
/** Images that never zoom, as a selector for `closest()`. */
|
|
14
|
+
export const NO_ZOOM_SELECTOR = '[nozoom], .wd-card-image, .wd-icon-image, .wd-tile-preview, a[href]';
|
|
15
|
+
|
|
16
|
+
/** Whether a page image opens in the lightbox. `img` is an <img> element
|
|
17
|
+
* (anything with `closest()`); only images in the article are passed in. */
|
|
18
|
+
export function zoomsOnClick(img) {
|
|
19
|
+
return img.closest(NO_ZOOM_SELECTOR) === null;
|
|
20
|
+
}
|
|
@@ -1,31 +1,21 @@
|
|
|
1
1
|
// Click-to-zoom lightbox for content images - opened by ImageZoom.astro's
|
|
2
2
|
// own overlay markup, mounted once in BaseLayout.astro alongside
|
|
3
3
|
// SearchModal. Every <img> inside .wd-article becomes clickable and opens
|
|
4
|
-
// a fullscreen view of itself
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// as `<img noZoom src="..." />` in source (Image.astro's own
|
|
12
|
-
// `noZoom` prop renders the same attribute - see its own comment),
|
|
13
|
-
// but HTML attribute names are ASCII-case-insensitive during
|
|
14
|
-
// parsing, so the DOM (and this selector) sees it as `nozoom`
|
|
15
|
-
// regardless of how it was cased in source.
|
|
16
|
-
// Scoped to .wd-article (not a bare `img` selector) so this never
|
|
17
|
-
// touches chrome images - the topbar/sidebar logo, sidebar icons, or
|
|
18
|
-
// anything else outside actual page content.
|
|
4
|
+
// a fullscreen view of itself - except the ones lib/image-zoom-rules.js
|
|
5
|
+
// leaves out: `noZoom`, a component's own picture (Card, Icon, Tile), and an
|
|
6
|
+
// image inside a link. Scoped to .wd-article (not a bare `img` selector) so
|
|
7
|
+
// this never touches chrome images - the topbar/sidebar logo, sidebar icons,
|
|
8
|
+
// or anything else outside actual page content.
|
|
9
|
+
import { zoomsOnClick } from '../lib/image-zoom-rules.js';
|
|
10
|
+
|
|
19
11
|
export function initImageZoom(root: ParentNode) {
|
|
20
12
|
const overlay = document.querySelector<HTMLElement>('#wd-zoom-overlay');
|
|
21
13
|
const overlayImg = document.querySelector<HTMLImageElement>('#wd-zoom-image');
|
|
22
14
|
if (!overlay || !overlayImg) return;
|
|
23
15
|
|
|
24
|
-
const images = root.querySelectorAll<HTMLImageElement>(
|
|
25
|
-
'.wd-article img:not(.wd-card-image):not(.wd-icon-image):not([nozoom])',
|
|
26
|
-
);
|
|
16
|
+
const images = root.querySelectorAll<HTMLImageElement>('.wd-article img');
|
|
27
17
|
images.forEach((img) => {
|
|
28
|
-
if (img.dataset.wdInit) return;
|
|
18
|
+
if (img.dataset.wdInit || !zoomsOnClick(img)) return;
|
|
29
19
|
img.dataset.wdInit = 'true';
|
|
30
20
|
img.classList.add('wd-zoomable');
|
|
31
21
|
img.addEventListener('click', () => open(img));
|