@taekwondo-db/web-app 0.1.3 → 0.2.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/README.md +27 -8
- package/assets/css/components/detail.css +17 -4
- package/assets/css/components/downloads.css +86 -0
- package/assets/css/components/layout.css +12 -0
- package/assets/css/components/pronunciation.css +113 -0
- package/assets/css/style.css +2 -0
- package/assets/fonts/noto-serif-kr.css +2 -1
- package/assets/js/main.js +4 -1
- package/assets/js/pronunciation.js +35 -0
- package/assets/js/pwa.js +160 -23
- package/assets/js/search.js +1 -1
- package/bin/taekwondo-db.js +30 -13
- package/i18n/de.json +25 -2
- package/i18n/en.json +25 -2
- package/i18n/ko.json +19 -2
- package/layouts/_partials/category-cards.html +1 -1
- package/layouts/_partials/category-section.html +1 -1
- package/layouts/_partials/downloads-dialog.html +20 -0
- package/layouts/_partials/fonts.html +1 -1
- package/layouts/_partials/head.html +6 -1
- package/layouts/_partials/meta-description.html +60 -0
- package/layouts/_partials/pronunciation.html +23 -0
- package/layouts/_partials/scripts.html +3 -7
- package/layouts/_partials/search-index.html +2 -0
- package/layouts/_partials/structured-data.html +54 -0
- package/layouts/baseof.html +5 -3
- package/layouts/robots.txt +4 -0
- package/layouts/source/page.html +1 -1
- package/layouts/technique/page.html +9 -5
- package/layouts/term/page.html +2 -1
- package/lib/database.js +1 -0
- package/lib/export.js +83 -11
- package/lib/fonts.js +36 -0
- package/lib/service-worker.js +170 -46
- package/lib/validate.js +14 -2
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ pnpm add @taekwondo-db/web-app # or: npm install @taekwondo-db/web-app
|
|
|
54
54
|
|
|
55
55
|
| Command | |
|
|
56
56
|
|---|---|
|
|
57
|
-
| `taekwondo-db dev [-- <hugo flags>]` | dev server; changes under `db/` and `
|
|
57
|
+
| `taekwondo-db dev [-- <hugo flags>]` | dev server; changes under `db/`, `img/` and `audio/` are picked up |
|
|
58
58
|
| `taekwondo-db build [-- <hugo flags>]` | static site in `dist/`, with service worker |
|
|
59
59
|
| `taekwondo-db validate` | checks the data, see [Validation](#validation) |
|
|
60
60
|
| `taekwondo-db export` | only prepares the data for Hugo |
|
|
@@ -63,6 +63,7 @@ pnpm add @taekwondo-db/web-app # or: npm install @taekwondo-db/web-app
|
|
|
63
63
|
|---|---|---|
|
|
64
64
|
| `--db` | `db/index.js` | module exporting the database options as `db` |
|
|
65
65
|
| `--img` | `img` | own image directory, repeatable |
|
|
66
|
+
| `--audio` | `audio` | own pronunciation directory, repeatable |
|
|
66
67
|
| `--data` | `db` | where `validate` checks `$schema` pointers |
|
|
67
68
|
|
|
68
69
|
`dist/` can be served by any web server from the root of a (sub)domain — the
|
|
@@ -77,6 +78,7 @@ i18n/<lang>.json own or changed interface texts
|
|
|
77
78
|
content/ own pages, e.g. imprint and privacy policy
|
|
78
79
|
assets/ logo, favicon; own styles
|
|
79
80
|
img/<group>/ own technique images
|
|
81
|
+
audio/<group>/ own pronunciations
|
|
80
82
|
layouts/ own templates
|
|
81
83
|
```
|
|
82
84
|
|
|
@@ -100,7 +102,7 @@ counts. It is needed for anything beyond the files, such as
|
|
|
100
102
|
`includeBuiltins: false`.
|
|
101
103
|
|
|
102
104
|
Only the composed result reaches the site: techniques left out by the whitelist,
|
|
103
|
-
and their images, are not published.
|
|
105
|
+
and their images and pronunciations, are not published.
|
|
104
106
|
|
|
105
107
|
### Configuration
|
|
106
108
|
|
|
@@ -125,6 +127,9 @@ keys, such as the names of own groups, and overrides single texts.
|
|
|
125
127
|
The footer states that the site is not affiliated with or endorsed by
|
|
126
128
|
Kukkiwon — the key `disclaimer`.
|
|
127
129
|
|
|
130
|
+
The meta description of a page is generated from its data; that of the home
|
|
131
|
+
page is the key `meta home`.
|
|
132
|
+
|
|
128
133
|
### Own pages
|
|
129
134
|
|
|
130
135
|
Markdown files in `content/` become pages of their own, one file per language
|
|
@@ -135,6 +140,7 @@ every language that has no version of its own:
|
|
|
135
140
|
```markdown
|
|
136
141
|
---
|
|
137
142
|
title: Datenschutz
|
|
143
|
+
description: Wie diese Website mit Daten umgeht.
|
|
138
144
|
menus: footer
|
|
139
145
|
---
|
|
140
146
|
|
|
@@ -173,6 +179,14 @@ group page) and a display name in `i18n/`. Groups outside
|
|
|
173
179
|
are left out. JPEG, PNG and WebP are scaled to WebP; images with `ai: true`
|
|
174
180
|
carry an "AI" badge.
|
|
175
181
|
|
|
182
|
+
### Pronunciations
|
|
183
|
+
|
|
184
|
+
`pronunciation.src` of techniques and terms is looked up the same way, in the
|
|
185
|
+
database's `audio/`, then in the site's `audio/`. A round button next to the
|
|
186
|
+
Hangeul of the title plays it; without JavaScript it opens the file. A sparkle
|
|
187
|
+
on the button marks `ai: true`, a recording's `speaker` is named in its tooltip
|
|
188
|
+
(i18n keys `listen to pronunciation`, `ai generated speech`, `spoken by`).
|
|
189
|
+
|
|
176
190
|
### Grades
|
|
177
191
|
|
|
178
192
|
With `grades`, technique pages, lists and search results show a badge such as
|
|
@@ -199,8 +213,8 @@ the export (`lib/export.js`).
|
|
|
199
213
|
- groups without a term, techniques without a translation in a configured
|
|
200
214
|
language (except `ko`).
|
|
201
215
|
|
|
202
|
-
It only warns about missing image files — the public database ships
|
|
203
|
-
images — and about description references to what is not loaded.
|
|
216
|
+
It only warns about missing image and audio files — the public database ships
|
|
217
|
+
without images — and about description references to what is not loaded.
|
|
204
218
|
|
|
205
219
|
### URLs
|
|
206
220
|
|
|
@@ -211,9 +225,14 @@ other characters replaced by `-` (`Momtong An Makgi` → `momtong-an-makgi`).
|
|
|
211
225
|
### Search and offline
|
|
212
226
|
|
|
213
227
|
The search runs in the browser on a per-language index; without JavaScript
|
|
214
|
-
every page still works.
|
|
215
|
-
|
|
216
|
-
|
|
228
|
+
every page still works. After the first visit the service worker caches, in
|
|
229
|
+
the background, the pages of the language being read and everything the
|
|
230
|
+
languages share (images, pronunciations, fonts, styles); pages of other languages as they are
|
|
231
|
+
visited. A browser in data-saving mode gets only the visited pages. A new
|
|
232
|
+
deploy is offered as an update and fetches only the files that changed. A
|
|
233
|
+
dialog at the bottom shows the progress of both downloads; cancelling holds
|
|
234
|
+
them for the session (the tab), and what was fetched is kept. The build cuts
|
|
235
|
+
the Hangeul font down to the characters the site shows.
|
|
217
236
|
|
|
218
237
|
## Development
|
|
219
238
|
|
|
@@ -236,7 +255,7 @@ component, next to a link to this theme:
|
|
|
236
255
|
```
|
|
237
256
|
.taekwondo-db/themes/web-app → this package
|
|
238
257
|
.taekwondo-db/themes/taekwondo-data/data/… the composed database
|
|
239
|
-
.taekwondo-db/themes/taekwondo-data/assets/… images, fonts, Bootstrap, the database's search
|
|
258
|
+
.taekwondo-db/themes/taekwondo-data/assets/… images, pronunciations, fonts, Bootstrap, the database's search
|
|
240
259
|
```
|
|
241
260
|
|
|
242
261
|
A content adapter (`content/_content.gotmpl`) turns the data into pages.
|
|
@@ -175,10 +175,16 @@
|
|
|
175
175
|
gap: var(--space-1) var(--space-5);
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
/*
|
|
179
|
+
* A long name, one word in romanisation, would run off a phone screen. It
|
|
180
|
+
* breaks at the soft hyphens between its terms, else anywhere; `anywhere`
|
|
181
|
+
* also lets the flex item shrink below its longest word.
|
|
182
|
+
*/
|
|
178
183
|
.title-block h1 {
|
|
179
184
|
margin: 0;
|
|
180
185
|
font-size: var(--text-h1);
|
|
181
186
|
line-height: 1.05;
|
|
187
|
+
overflow-wrap: anywhere;
|
|
182
188
|
}
|
|
183
189
|
|
|
184
190
|
/*
|
|
@@ -252,19 +258,26 @@
|
|
|
252
258
|
|
|
253
259
|
/* WeightBar */
|
|
254
260
|
.weight-bar {
|
|
255
|
-
display:
|
|
261
|
+
display: block;
|
|
262
|
+
width: 100%;
|
|
256
263
|
height: 14px;
|
|
257
|
-
gap: 3px;
|
|
258
264
|
border-radius: var(--radius-pill);
|
|
259
265
|
overflow: hidden;
|
|
260
266
|
}
|
|
261
267
|
|
|
262
268
|
.weight-bar__front {
|
|
263
|
-
|
|
269
|
+
fill: var(--color-accent);
|
|
264
270
|
}
|
|
265
271
|
|
|
266
272
|
.weight-bar__back {
|
|
267
|
-
|
|
273
|
+
fill: var(--color-accent-light);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/* Drawn in the card colour: a 3px gap however wide the bar is stretched. */
|
|
277
|
+
.weight-bar__gap {
|
|
278
|
+
stroke: var(--color-surface);
|
|
279
|
+
stroke-width: 3px;
|
|
280
|
+
vector-effect: non-scaling-stroke;
|
|
268
281
|
}
|
|
269
282
|
|
|
270
283
|
.weight-values {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The offline downloads and the offer of an update: a card at the bottom,
|
|
3
|
+
* not modal, so reading goes on meanwhile.
|
|
4
|
+
*/
|
|
5
|
+
.downloads {
|
|
6
|
+
position: fixed;
|
|
7
|
+
inset: auto var(--space-4) calc(var(--space-4) + env(safe-area-inset-bottom));
|
|
8
|
+
z-index: 1040;
|
|
9
|
+
width: auto;
|
|
10
|
+
max-width: 440px;
|
|
11
|
+
margin: 0 auto;
|
|
12
|
+
padding: var(--space-4) var(--space-5);
|
|
13
|
+
border: 1px solid var(--color-border);
|
|
14
|
+
border-radius: var(--radius-lg);
|
|
15
|
+
background: var(--color-surface);
|
|
16
|
+
color: var(--color-text);
|
|
17
|
+
box-shadow: 0 8px 28px rgb(22 24 29 / 16%);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.downloads[open] {
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
gap: var(--space-3);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.downloads [hidden] {
|
|
27
|
+
display: none !important;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.downloads__title {
|
|
31
|
+
margin: 0;
|
|
32
|
+
font-size: var(--text-sm);
|
|
33
|
+
font-weight: 600;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.downloads__progress {
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
gap: var(--space-3);
|
|
40
|
+
font-size: var(--text-xs);
|
|
41
|
+
font-variant-numeric: tabular-nums;
|
|
42
|
+
color: var(--color-text-muted);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.downloads__progress progress {
|
|
46
|
+
flex: 1;
|
|
47
|
+
height: 6px;
|
|
48
|
+
accent-color: var(--color-accent);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.downloads__actions {
|
|
52
|
+
display: flex;
|
|
53
|
+
justify-content: flex-end;
|
|
54
|
+
gap: var(--space-2);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.downloads__button {
|
|
58
|
+
min-height: 36px;
|
|
59
|
+
padding: 0 var(--space-4);
|
|
60
|
+
border: 1px solid transparent;
|
|
61
|
+
border-radius: var(--radius-pill);
|
|
62
|
+
background: transparent;
|
|
63
|
+
color: var(--color-text-secondary);
|
|
64
|
+
font-size: var(--text-sm);
|
|
65
|
+
font-weight: 600;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.downloads__button:hover {
|
|
69
|
+
background: var(--color-surface-muted);
|
|
70
|
+
color: var(--color-text);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.downloads__button--primary {
|
|
74
|
+
background: var(--color-accent);
|
|
75
|
+
color: #fff;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.downloads__button--primary:hover {
|
|
79
|
+
background: var(--color-accent-hover);
|
|
80
|
+
color: #fff;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.downloads__button:focus-visible {
|
|
84
|
+
outline: 3px solid var(--color-focus-ring);
|
|
85
|
+
outline-offset: 2px;
|
|
86
|
+
}
|
|
@@ -34,6 +34,18 @@
|
|
|
34
34
|
gap: var(--space-6);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
.stack-sm {
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-direction: column;
|
|
40
|
+
gap: 10px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.stack-md {
|
|
44
|
+
display: flex;
|
|
45
|
+
flex-direction: column;
|
|
46
|
+
gap: var(--space-4);
|
|
47
|
+
}
|
|
48
|
+
|
|
37
49
|
.stack-lg {
|
|
38
50
|
display: flex;
|
|
39
51
|
flex-direction: column;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The play button of a spoken name, on the title line next to the Hangeul.
|
|
3
|
+
* The line aligns on the baseline; the button centres itself instead. The
|
|
4
|
+
* sparkle marks synthesized speech, like the AI badge of an image.
|
|
5
|
+
*/
|
|
6
|
+
.pronounce {
|
|
7
|
+
position: relative;
|
|
8
|
+
display: inline-flex;
|
|
9
|
+
flex: none;
|
|
10
|
+
align-self: center;
|
|
11
|
+
align-items: center;
|
|
12
|
+
justify-content: center;
|
|
13
|
+
width: 44px;
|
|
14
|
+
height: 44px;
|
|
15
|
+
border: 1px solid var(--color-accent-border);
|
|
16
|
+
border-radius: var(--radius-pill);
|
|
17
|
+
background: var(--color-accent-soft);
|
|
18
|
+
color: var(--color-accent);
|
|
19
|
+
transition:
|
|
20
|
+
background-color 0.15s ease,
|
|
21
|
+
border-color 0.15s ease,
|
|
22
|
+
color 0.15s ease,
|
|
23
|
+
transform 0.1s ease;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.pronounce:hover,
|
|
27
|
+
.pronounce[data-playing] {
|
|
28
|
+
border-color: var(--color-accent);
|
|
29
|
+
background: var(--color-accent);
|
|
30
|
+
color: #fff;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.pronounce:active {
|
|
34
|
+
transform: scale(0.94);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.pronounce:focus-visible {
|
|
38
|
+
outline: 3px solid var(--color-focus-ring);
|
|
39
|
+
outline-offset: 2px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.pronounce__icon {
|
|
43
|
+
width: 22px;
|
|
44
|
+
height: 22px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.pronounce[data-playing] .pronounce__wave {
|
|
48
|
+
animation: pronounce-wave 0.8s ease-in-out infinite;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.pronounce[data-playing] .pronounce__wave--outer {
|
|
52
|
+
animation-delay: 0.2s;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@keyframes pronounce-wave {
|
|
56
|
+
50% {
|
|
57
|
+
opacity: 0.25;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.pronounce__ai {
|
|
62
|
+
position: absolute;
|
|
63
|
+
top: -4px;
|
|
64
|
+
right: -4px;
|
|
65
|
+
display: grid;
|
|
66
|
+
width: 18px;
|
|
67
|
+
height: 18px;
|
|
68
|
+
place-items: center;
|
|
69
|
+
border: 1px solid var(--color-accent-border);
|
|
70
|
+
border-radius: var(--radius-pill);
|
|
71
|
+
background: var(--color-surface);
|
|
72
|
+
color: var(--color-accent);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.pronounce__ai svg {
|
|
76
|
+
width: 10px;
|
|
77
|
+
height: 10px;
|
|
78
|
+
fill: currentColor;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@media (prefers-reduced-motion: reduce) {
|
|
82
|
+
.pronounce,
|
|
83
|
+
.pronounce[data-playing] .pronounce__wave {
|
|
84
|
+
transition: none;
|
|
85
|
+
animation: none;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* As tall as the Hangeul beside it, so the title above keeps its distance. */
|
|
90
|
+
@media (max-width: 767.98px) {
|
|
91
|
+
.pronounce {
|
|
92
|
+
width: 32px;
|
|
93
|
+
height: 32px;
|
|
94
|
+
margin-inline-start: calc(-1 * var(--space-2));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.pronounce__icon {
|
|
98
|
+
width: 18px;
|
|
99
|
+
height: 18px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.pronounce__ai {
|
|
103
|
+
top: -5px;
|
|
104
|
+
right: -6px;
|
|
105
|
+
width: 16px;
|
|
106
|
+
height: 16px;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.pronounce__ai svg {
|
|
110
|
+
width: 9px;
|
|
111
|
+
height: 9px;
|
|
112
|
+
}
|
|
113
|
+
}
|
package/assets/css/style.css
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Declared here instead of taking `@fontsource/noto-serif-kr/korean-*.css`,
|
|
5
5
|
* because those also reference a `.woff` fallback — 2.4 MB per weight that
|
|
6
|
-
* every browser of the last decade ignores.
|
|
6
|
+
* every browser of the last decade ignores. The build cuts the `.woff2` down to
|
|
7
|
+
* the characters the site shows (see lib/fonts.js).
|
|
7
8
|
*
|
|
8
9
|
* Weight 500 carries Hangeul next to romanised text. Weight 700 carries the
|
|
9
10
|
* headings of the Korean pages and, elsewhere, only the syllable tiles inside
|
package/assets/js/main.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { initEmailLinks } from "./email.js";
|
|
2
2
|
import { initGallery } from "./gallery.js";
|
|
3
3
|
import { initLanguageSelect } from "./language.js";
|
|
4
|
+
import { initPronunciation } from "./pronunciation.js";
|
|
4
5
|
import { registerServiceWorker } from "./pwa.js";
|
|
5
6
|
import { initSearch } from "./search.js";
|
|
6
7
|
import { initSorting } from "./sorting.js";
|
|
7
8
|
|
|
8
9
|
const config = JSON.parse(
|
|
9
|
-
document.
|
|
10
|
+
document.querySelector("script[data-config]")?.getAttribute("data-config") ??
|
|
11
|
+
"{}",
|
|
10
12
|
);
|
|
11
13
|
|
|
12
14
|
initSearch(config);
|
|
13
15
|
initGallery();
|
|
16
|
+
initPronunciation();
|
|
14
17
|
initSorting();
|
|
15
18
|
initLanguageSelect();
|
|
16
19
|
initEmailLinks();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plays a pronunciation in place instead of opening its file. Fetched rather
|
|
3
|
+
* than streamed: a media element asks for byte ranges, which the service
|
|
4
|
+
* worker's cache cannot answer in every browser — offline it would stay mute.
|
|
5
|
+
*/
|
|
6
|
+
export function initPronunciation() {
|
|
7
|
+
for (const link of /** @type {NodeListOf<HTMLAnchorElement>} */ (
|
|
8
|
+
document.querySelectorAll("a[data-pronunciation]")
|
|
9
|
+
)) {
|
|
10
|
+
/** @type {HTMLAudioElement | undefined} */
|
|
11
|
+
let audio;
|
|
12
|
+
link.addEventListener("click", async (event) => {
|
|
13
|
+
event.preventDefault();
|
|
14
|
+
try {
|
|
15
|
+
if (!audio) {
|
|
16
|
+
const response = await fetch(link.href);
|
|
17
|
+
if (!response.ok) throw new Error(String(response.status));
|
|
18
|
+
audio = new Audio(URL.createObjectURL(await response.blob()));
|
|
19
|
+
audio.addEventListener("playing", () => {
|
|
20
|
+
link.dataset.playing = "";
|
|
21
|
+
});
|
|
22
|
+
for (const type of ["pause", "ended"]) {
|
|
23
|
+
audio.addEventListener(type, () => {
|
|
24
|
+
delete link.dataset.playing;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
audio.currentTime = 0;
|
|
29
|
+
await audio.play();
|
|
30
|
+
} catch {
|
|
31
|
+
location.href = link.href;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
package/assets/js/pwa.js
CHANGED
|
@@ -1,48 +1,185 @@
|
|
|
1
1
|
/** How often an open site asks the server whether a new version was deployed. */
|
|
2
2
|
const UPDATE_INTERVAL = 60 * 60 * 1000;
|
|
3
|
+
/** How long the note that the site now works offline stays. */
|
|
4
|
+
const DONE_NOTE = 4000;
|
|
5
|
+
const POSTPONED = "taekwondo-db-downloads-postponed";
|
|
6
|
+
/** An install starting this soon after the page loaded is the browser's check on navigating here. */
|
|
7
|
+
const NAVIGATION_CHECK = 5000;
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
10
|
* Registers the service worker that makes the site work offline (written by
|
|
6
|
-
* `taekwondo-db build`, so only in production builds).
|
|
11
|
+
* `taekwondo-db build`, so only in production builds). It is asked to cache
|
|
12
|
+
* the pages of the language being read, unless the visitor asked the browser
|
|
13
|
+
* to save data; then only visited pages are cached.
|
|
7
14
|
*
|
|
8
|
-
* A new deploy
|
|
9
|
-
* activates it and reloads.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
15
|
+
* A new deploy downloads in the background and is then offered — accepting
|
|
16
|
+
* activates it and reloads. An installed app may stay open for days, so it
|
|
17
|
+
* also checks for updates periodically while online.
|
|
18
|
+
*
|
|
19
|
+
* A dialog shows how far both downloads got. Cancelling one, or declining an
|
|
20
|
+
* update, holds them for the session, that is the tab: the update the browser
|
|
21
|
+
* checks for on each navigation is cancelled right away; what was fetched is
|
|
22
|
+
* kept for the next start. Another tab is a session of its own.
|
|
23
|
+
*
|
|
24
|
+
* `register()` waits behind a running install, which on a slow line takes
|
|
25
|
+
* minutes; the page watches the registration `getRegistration()` gives at once.
|
|
12
26
|
*/
|
|
13
|
-
export async function registerServiceWorker({ serviceWorker, home
|
|
27
|
+
export async function registerServiceWorker({ serviceWorker, home }) {
|
|
14
28
|
if (!serviceWorker || !("serviceWorker" in navigator)) return;
|
|
29
|
+
const container = navigator.serviceWorker;
|
|
15
30
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
);
|
|
31
|
+
const registered = container.register(serviceWorker).catch(() => undefined);
|
|
32
|
+
const registration =
|
|
33
|
+
(await container.getRegistration()) ?? (await registered);
|
|
34
|
+
if (!registration) return;
|
|
35
|
+
|
|
36
|
+
const postponed = () => sessionStorage.getItem(POSTPONED) !== null;
|
|
37
|
+
const cancel = () => {
|
|
38
|
+
sessionStorage.setItem(POSTPONED, "");
|
|
39
|
+
for (const worker of [registration.installing, registration.active]) {
|
|
40
|
+
worker?.postMessage({ type: "CANCEL" });
|
|
41
|
+
}
|
|
42
|
+
};
|
|
20
43
|
|
|
21
|
-
// The first install takes control as well; only an accepted update reloads.
|
|
22
44
|
let accepted = false;
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
if (confirm(t.updateAvailable)) {
|
|
45
|
+
const dialog = downloadDialog({
|
|
46
|
+
apply: () => {
|
|
26
47
|
accepted = true;
|
|
27
|
-
|
|
48
|
+
registration.waiting?.postMessage({ type: "SKIP_WAITING" });
|
|
49
|
+
},
|
|
50
|
+
cancel,
|
|
51
|
+
later: () => sessionStorage.setItem(POSTPONED, ""),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Network Information API: Chromium only.
|
|
55
|
+
if (!(/** @type {any} */ (navigator).connection?.saveData)) {
|
|
56
|
+
container.ready.then(({ active }) => {
|
|
57
|
+
if (!postponed()) active?.postMessage({ home, type: "PRECACHE" });
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Only an update is offered; the first install takes control by itself.
|
|
62
|
+
const offer = (worker) => {
|
|
63
|
+
if (worker && registration.active && !postponed()) dialog.ready();
|
|
64
|
+
};
|
|
65
|
+
const watch = (worker) => {
|
|
66
|
+
if (!worker) return;
|
|
67
|
+
if (registration.active && postponed()) {
|
|
68
|
+
if (performance.now() < NAVIGATION_CHECK) {
|
|
69
|
+
worker.postMessage({ type: "CANCEL" });
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
28
72
|
}
|
|
73
|
+
worker.addEventListener("statechange", () => {
|
|
74
|
+
if (worker.state === "installed") offer(worker);
|
|
75
|
+
if (worker.state === "redundant") dialog.close("update");
|
|
76
|
+
});
|
|
29
77
|
};
|
|
30
78
|
|
|
31
79
|
offer(registration.waiting);
|
|
32
|
-
registration.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
80
|
+
watch(registration.installing);
|
|
81
|
+
registration.addEventListener("updatefound", () =>
|
|
82
|
+
watch(registration.installing),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
container.addEventListener("message", ({ data }) => {
|
|
86
|
+
if (data?.type === "PROGRESS" && !postponed()) {
|
|
87
|
+
dialog.progress(data.kind, data.done, data.total);
|
|
88
|
+
}
|
|
37
89
|
});
|
|
90
|
+
container.startMessages();
|
|
38
91
|
|
|
39
|
-
|
|
40
|
-
|
|
92
|
+
// Another tab may have switched; only an update accepted here reloads.
|
|
93
|
+
container.addEventListener("controllerchange", () => {
|
|
94
|
+
if (!accepted) return dialog.close("ready");
|
|
41
95
|
accepted = false;
|
|
42
96
|
location.reload();
|
|
43
97
|
});
|
|
44
98
|
|
|
45
99
|
setInterval(() => {
|
|
46
|
-
if (navigator.onLine) registration.update();
|
|
100
|
+
if (navigator.onLine && !postponed()) registration.update();
|
|
47
101
|
}, UPDATE_INTERVAL);
|
|
48
102
|
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The non-modal `dialog[data-downloads]` of the page. Its parts carry the
|
|
106
|
+
* states they belong to in `data-when`: "offline" and "update" while
|
|
107
|
+
* downloading, "done" once the site works offline, "ready" to switch.
|
|
108
|
+
*
|
|
109
|
+
* @param {{ apply: () => void, cancel: () => void, later: () => void }} actions
|
|
110
|
+
*/
|
|
111
|
+
function downloadDialog({ apply, cancel, later }) {
|
|
112
|
+
const dialog = /** @type {HTMLDialogElement | null} */ (
|
|
113
|
+
document.querySelector("dialog[data-downloads]")
|
|
114
|
+
);
|
|
115
|
+
if (!dialog) return { close() {}, progress() {}, ready() {} };
|
|
116
|
+
|
|
117
|
+
const bar = /** @type {HTMLProgressElement} */ (
|
|
118
|
+
dialog.querySelector("progress")
|
|
119
|
+
);
|
|
120
|
+
const percent = /** @type {HTMLElement} */ (
|
|
121
|
+
dialog.querySelector("[data-percent]")
|
|
122
|
+
);
|
|
123
|
+
const format = new Intl.NumberFormat(document.documentElement.lang, {
|
|
124
|
+
style: "percent",
|
|
125
|
+
});
|
|
126
|
+
let state = "";
|
|
127
|
+
let timer = 0;
|
|
128
|
+
|
|
129
|
+
const show = (next) => {
|
|
130
|
+
state = next;
|
|
131
|
+
clearTimeout(timer);
|
|
132
|
+
for (const part of /** @type {NodeListOf<HTMLElement>} */ (
|
|
133
|
+
dialog.querySelectorAll("[data-when]")
|
|
134
|
+
)) {
|
|
135
|
+
part.hidden = !part.dataset.when?.split(" ").includes(next);
|
|
136
|
+
}
|
|
137
|
+
if (dialog.open) return;
|
|
138
|
+
// show() focuses the first button; reading or typing elsewhere goes on.
|
|
139
|
+
const focused = document.activeElement;
|
|
140
|
+
dialog.show();
|
|
141
|
+
if (focused instanceof HTMLElement && focused !== document.body) {
|
|
142
|
+
focused.focus({ preventScroll: true });
|
|
143
|
+
} else if (document.activeElement instanceof HTMLElement) {
|
|
144
|
+
document.activeElement.blur();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const close = () => {
|
|
148
|
+
state = "";
|
|
149
|
+
dialog.close();
|
|
150
|
+
};
|
|
151
|
+
for (const [name, action] of Object.entries({ apply, cancel, later })) {
|
|
152
|
+
dialog.querySelector(`[data-${name}]`)?.addEventListener("click", () => {
|
|
153
|
+
action();
|
|
154
|
+
close();
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
/** Closes the dialog if it is in `which` state. */
|
|
160
|
+
close(which) {
|
|
161
|
+
if (state === which) close();
|
|
162
|
+
},
|
|
163
|
+
/**
|
|
164
|
+
* @param {"offline" | "update"} kind
|
|
165
|
+
* @param {number} done
|
|
166
|
+
* @param {number} total
|
|
167
|
+
*/
|
|
168
|
+
progress(kind, done, total) {
|
|
169
|
+
// An offered update outranks the background download.
|
|
170
|
+
if (state === "ready" || (kind === "offline" && state === "update")) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
bar.max = total;
|
|
174
|
+
bar.value = done;
|
|
175
|
+
percent.textContent = format.format(done / total);
|
|
176
|
+
if (kind === "offline" && done === total) {
|
|
177
|
+
show("done");
|
|
178
|
+
timer = setTimeout(close, DONE_NOTE);
|
|
179
|
+
} else {
|
|
180
|
+
show(kind);
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
ready: () => show("ready"),
|
|
184
|
+
};
|
|
185
|
+
}
|
package/assets/js/search.js
CHANGED
|
@@ -75,7 +75,7 @@ function gradeBadge(item) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
function section(title, rows) {
|
|
78
|
-
return `<section class="stack"
|
|
78
|
+
return `<section class="stack-sm">
|
|
79
79
|
<h2 class="section-title">${escapeHtml(title)}</h2>
|
|
80
80
|
<ul class="result-list">${rows.join("")}</ul>
|
|
81
81
|
</section>`;
|