@n1kname/components 0.27.0 → 0.29.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 +1 -1
- package/src/AtAGlance.astro +185 -0
- package/src/Clip.astro +198 -0
- package/src/FlowDiagram.astro +4 -177
- package/src/SectionNav.astro +53 -10
- package/src/Steps.astro +165 -0
- package/src/Tiers.astro +329 -0
- package/src/parts/DiagramZoom.astro +190 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* The Enlarge button and dialog a drawn diagram (Flow diagram, Tiers) carries. Put it inside the
|
|
4
|
+
* diagram's plate, after the drawing, and mark the drawing `data-zoom-source`. When the plate is
|
|
5
|
+
* narrower than `min`, the drawing fits it, smaller, and the button shows; it opens a copy of the
|
|
6
|
+
* drawing full size in a modal dialog, centred, to pan. Without script the button never shows.
|
|
7
|
+
*/
|
|
8
|
+
interface Props {
|
|
9
|
+
title: string;
|
|
10
|
+
/** The width the drawing reads well at, in px. */
|
|
11
|
+
min: number;
|
|
12
|
+
id: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { title, min, id } = Astro.props;
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
<div class="zoom-host" data-diagram-zoom data-min={min}>
|
|
19
|
+
<button type="button" class="enlarge" data-enlarge hidden>
|
|
20
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
21
|
+
<path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"></path>
|
|
22
|
+
</svg>
|
|
23
|
+
Enlarge<span class="visually-hidden">: {title}</span>
|
|
24
|
+
</button>
|
|
25
|
+
<dialog class="zoom" aria-labelledby={`${id}-zoom`}>
|
|
26
|
+
<div class="zoom-bar">
|
|
27
|
+
<p class="zoom-title" id={`${id}-zoom`}>{title}</p>
|
|
28
|
+
<button type="button" class="close" data-close>Close</button>
|
|
29
|
+
</div>
|
|
30
|
+
<div class="zoom-scroll" tabindex="0" role="region" aria-label={`${title}, full size`} data-zoom-body></div>
|
|
31
|
+
</dialog>
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
<style>
|
|
35
|
+
.zoom-host {
|
|
36
|
+
display: flex;
|
|
37
|
+
justify-content: flex-end;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.enlarge {
|
|
41
|
+
display: inline-flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
gap: var(--sp-1);
|
|
44
|
+
margin-top: var(--sp-3);
|
|
45
|
+
padding: var(--sp-1) var(--sp-3);
|
|
46
|
+
border: 1px solid var(--c-border);
|
|
47
|
+
border-radius: var(--radius-full);
|
|
48
|
+
background: var(--c-surface);
|
|
49
|
+
color: var(--c-text);
|
|
50
|
+
font: inherit;
|
|
51
|
+
font-size: var(--text-caption);
|
|
52
|
+
font-weight: 600;
|
|
53
|
+
cursor: pointer;
|
|
54
|
+
transition: border-color var(--motion-hover) var(--ease-hover);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.enlarge[hidden] {
|
|
58
|
+
display: none;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.enlarge svg {
|
|
62
|
+
display: inline-block;
|
|
63
|
+
width: 16px;
|
|
64
|
+
height: 16px;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.enlarge:hover {
|
|
68
|
+
border-color: var(--c-border-strong);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.enlarge:focus-visible,
|
|
72
|
+
.close:focus-visible,
|
|
73
|
+
.zoom-scroll:focus-visible {
|
|
74
|
+
outline: 2px solid var(--c-focus);
|
|
75
|
+
outline-offset: 2px;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.visually-hidden {
|
|
79
|
+
position: absolute;
|
|
80
|
+
width: 1px;
|
|
81
|
+
height: 1px;
|
|
82
|
+
overflow: hidden;
|
|
83
|
+
clip-path: inset(50%);
|
|
84
|
+
white-space: nowrap;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.zoom {
|
|
88
|
+
width: calc(100vw - var(--sp-4));
|
|
89
|
+
max-width: none;
|
|
90
|
+
height: calc(100dvh - var(--sp-4));
|
|
91
|
+
max-height: none;
|
|
92
|
+
padding: 0;
|
|
93
|
+
border: 1px solid var(--c-border);
|
|
94
|
+
border-radius: var(--radius-lg);
|
|
95
|
+
background: var(--c-bg);
|
|
96
|
+
color: var(--c-text);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.zoom[open] {
|
|
100
|
+
display: flex;
|
|
101
|
+
flex-direction: column;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.zoom::backdrop {
|
|
105
|
+
background: color-mix(in oklab, var(--c-bg) 70%, transparent);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.zoom-bar {
|
|
109
|
+
display: flex;
|
|
110
|
+
align-items: center;
|
|
111
|
+
justify-content: space-between;
|
|
112
|
+
gap: var(--sp-3);
|
|
113
|
+
padding: var(--sp-3) var(--sp-4);
|
|
114
|
+
border-bottom: 1px solid var(--c-border);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.zoom-title {
|
|
118
|
+
margin: 0;
|
|
119
|
+
font-weight: 600;
|
|
120
|
+
font-size: var(--text-body-sm);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.close {
|
|
124
|
+
padding: var(--sp-1) var(--sp-3);
|
|
125
|
+
border: 1px solid var(--c-border);
|
|
126
|
+
border-radius: var(--radius-full);
|
|
127
|
+
background: var(--c-surface);
|
|
128
|
+
color: var(--c-text);
|
|
129
|
+
font: inherit;
|
|
130
|
+
font-size: var(--text-caption);
|
|
131
|
+
font-weight: 600;
|
|
132
|
+
cursor: pointer;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* Full size, so the words read; it pans where the screen is smaller. */
|
|
136
|
+
.zoom-scroll {
|
|
137
|
+
flex: 1;
|
|
138
|
+
overflow: auto;
|
|
139
|
+
padding: var(--sp-5);
|
|
140
|
+
background: var(--c-surface-sunken);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.zoom-scroll > :global(svg) {
|
|
144
|
+
display: block;
|
|
145
|
+
width: var(--full);
|
|
146
|
+
min-width: var(--full);
|
|
147
|
+
max-width: none;
|
|
148
|
+
height: auto;
|
|
149
|
+
overflow: visible;
|
|
150
|
+
}
|
|
151
|
+
</style>
|
|
152
|
+
|
|
153
|
+
<script>
|
|
154
|
+
document.querySelectorAll<HTMLElement>('[data-diagram-zoom]').forEach((host) => {
|
|
155
|
+
const min = Number(host.dataset.min) || 0;
|
|
156
|
+
const plate = host.parentElement!;
|
|
157
|
+
const fig = host.closest('figure');
|
|
158
|
+
const source = plate.querySelector<SVGSVGElement>('[data-zoom-source]');
|
|
159
|
+
const button = host.querySelector<HTMLButtonElement>('[data-enlarge]')!;
|
|
160
|
+
const dialog = host.querySelector<HTMLDialogElement>('dialog')!;
|
|
161
|
+
const body = host.querySelector<HTMLElement>('[data-zoom-body]')!;
|
|
162
|
+
if (!source) return;
|
|
163
|
+
const fit = () => {
|
|
164
|
+
const small = plate.offsetParent !== null && plate.clientWidth < min;
|
|
165
|
+
button.hidden = !small;
|
|
166
|
+
fig?.classList.toggle('is-small', small);
|
|
167
|
+
};
|
|
168
|
+
new ResizeObserver(fit).observe(plate);
|
|
169
|
+
fit();
|
|
170
|
+
button.addEventListener('click', () => {
|
|
171
|
+
const copy = source.cloneNode(true) as SVGSVGElement;
|
|
172
|
+
copy.removeAttribute('aria-labelledby');
|
|
173
|
+
copy.removeAttribute('data-zoom-source');
|
|
174
|
+
copy.setAttribute('aria-hidden', 'true');
|
|
175
|
+
copy.querySelectorAll('[id]').forEach((el) => el.removeAttribute('id'));
|
|
176
|
+
copy.style.setProperty('--full', `${Math.max(min, 640)}px`);
|
|
177
|
+
body.replaceChildren(copy);
|
|
178
|
+
dialog.showModal();
|
|
179
|
+
// Open on the middle of the drawing, where its point usually is.
|
|
180
|
+
body.scrollLeft = (body.scrollWidth - body.clientWidth) / 2;
|
|
181
|
+
});
|
|
182
|
+
dialog.querySelector('[data-close]')?.addEventListener('click', () => dialog.close());
|
|
183
|
+
// Back to Enlarge on close, however it closed: Safari doesn't focus a button that's clicked,
|
|
184
|
+
// so it has nothing to go back to on its own.
|
|
185
|
+
dialog.addEventListener('close', () => button.focus());
|
|
186
|
+
dialog.addEventListener('click', (e) => {
|
|
187
|
+
if (e.target === dialog) dialog.close();
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
</script>
|