@johnmorrisdotca/chikyu-earth 0.17.0 → 0.19.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/CHANGELOG.md +8 -0
- package/NOTICE.md +4 -0
- package/README.md +51 -15
- package/dist/element.d.ts +4 -0
- package/dist/element.js +26 -2
- package/dist/realistic/element.d.ts +3 -0
- package/dist/realistic/element.js +27 -2
- package/dist/sheets/common.d.ts +50 -0
- package/dist/sheets/common.js +94 -0
- package/dist/sheets/country.d.ts +50 -0
- package/dist/sheets/country.js +70 -0
- package/dist/sheets/earth.d.ts +50 -0
- package/dist/sheets/earth.js +103 -0
- package/dist/sheets/hatch.d.ts +23 -0
- package/dist/sheets/hatch.js +66 -0
- package/dist/sheets/index.d.ts +7 -0
- package/dist/sheets/index.js +9 -0
- package/dist/sheets/land.d.ts +83 -0
- package/dist/sheets/land.js +257 -0
- package/dist/sheets/outline.d.ts +15 -0
- package/dist/sheets/outline.js +116 -0
- package/dist/sheets/sun.d.ts +68 -0
- package/dist/sheets/sun.js +216 -0
- package/dist/sheets/text.d.ts +213 -0
- package/dist/sheets/text.js +244 -0
- package/dist/space/element.d.ts +5 -0
- package/dist/space/element.js +37 -0
- package/package.json +12 -8
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.19.0 - 2026-11-09
|
|
6
|
+
|
|
7
|
+
- **Printable sheets** (MODULES-686). A new entry point `@johnmorrisdotca/chikyu-earth/sheets`, pure SVG strings in millimetres, no browser and no dependency: `globeSheetSvg` (the globe to colour on three sides, the continents in 3 mm outlines with no border between two countries of one continent, Russia cut at the Urals, the continents and oceans named), `worldMapSvg`, `countrySheetSvg` (the country's outline, its capital as a star when given, a box to draw the flag, the continent and the countries it touches), `dayNightSvg` with `terminator` and `dayNightView` (the line between day and night is the great circle 90 degrees from the package's own `subsolarPoint`, the night side hatched with plain lines so black and white prints well), `seasonsSvg` (four Earths round the Sun, tilted 23.4 degrees, toward the Sun in June and away in December), and the helpers `continentLines`, `landShares`, `countryShape`, `countryCodes`, `thickPath`, `hatchPath`, `earthFacts`, `dayNightFacts`, `seasonsFacts`, `countryFacts`, `TITLES`, `SAY`, `PLACES`. A4, US Letter, A3, Tabloid; English and Japanese; `kid` type (3 mm outline, 2.5 mm lines, names 24 pt, facts 18 pt) or `normal`; three facts on every sheet. The demo has a new page, `kids.html` (a row of sheets, the paper, the type, a date and time, Print / save PDF with kazoku-ui's print part, and a flag from hata to check a drawing against, never on the sheet; capitals from kuni; both for the demo only), and the Pages build makes ready-made PDFs (`scripts/make-pdfs.mjs`). `@johnmorrisdotca/kazoku-ui` moves to ^0.22.0, `@johnmorrisdotca/kuni` and `@johnmorrisdotca/hata` join as dev dependencies. Guide in English and Japanese: `docs/guides/printable-sheets.md`.
|
|
8
|
+
|
|
9
|
+
## 0.18.0 - 2026-11-08
|
|
10
|
+
|
|
11
|
+
- **Every live view zooms, pans and turns by itself** (MODULES-643): `<chikyu-earth>`, `<chikyu-earth-realistic>` and `<chikyu-space>` carry kazoku-ui's controls through `carryControls`: drag, two-finger pinch, Ctrl and the wheel (a plain wheel at Fit scrolls the page), the keys, with no bar. `controls="none"` takes them off; `zoom-min`, `zoom-max`, `tilt-max` change the range; `element.controller` is the controller behind them. A `<kazoku-view-controls for="...">` on the element takes the hands over and reads the element's range. The ranges (tilt to either pole): the line globe 0.1 to 20 times (Natural Earth 1:110m, redrawn at each zoom; about 640 km across at 20 times); the realistic Earth 0.1 to 5, raised to 20 by the element itself when its `tiles` are found; the space view a millionth to 2.5, and 0.5 to 6 while riding from a body (the element sets and removes `zoom-min` and `zoom-max` itself, unless the page set them). The line globe's `setView` redraws the Auto-turn about once a second by itself, so a page no longer keeps that clock. The demo's bar is now `for` the element (not a wrapper), the code builder's preview frame and the example pages carry the hands, and `examples/controls.html` is the new pattern. The embed page takes the hands by default (as wakusei-planets' does): drag, pinch, Ctrl and the wheel, the keys, with a plain wheel at Fit scrolling the host page, in a frame of any size; `hands=0` makes it a still picture, `turn=auto` still turns it by itself and `turn=1` is accepted and does nothing more, and the code builder's preview frame and iframe code need no `turn`. `@johnmorrisdotca/kazoku-ui` (^0.21.1) is now a dependency, not an optional peer. Guide in English and Japanese: `docs/guides/zoom-and-pan.md`. Tests: `e2e/zoom.demo.ts` (demo, builder, embed, at desk and phone sizes), `e2e/zoom.gl.ts` (the 3D looks and the tile limit), the usage script's CDN, Vite and space examples; all through `e2e/hands.ts`.
|
|
12
|
+
|
|
5
13
|
## 0.17.0 - 2026-11-08
|
|
6
14
|
|
|
7
15
|
- **Sharp close zoom on the realistic Earth, from finer map tiles** (MODULES-645, the loader): `<chikyu-earth-realistic tiles="/tiles/">` (also `earth.tiles`) reads the tile set's `manifest.json`, picks the level from the zoom and the canvas (about one texel to a device pixel; day level 3 then 4, night level 2 then 3), loads only the tiles in view, six at a time, the middle first, and lays them over the package's pictures, which stay as the far view and the fallback. At most 48 tiles are held (about 70 MB of graphics memory); a tile that leaves view is kept 4 seconds and then freed, the oldest first when over the limit; the level drops when the tiles in view would be more. Each tile that arrives asks for one draw (30 a second at most, eight new tiles to a draw); nothing is drawn at rest or out of sight, a lost context comes back with the held tiles, and without the option, without a manifest or for a tile that fails the Earth is drawn as before. A device with no 4096 picture (`max-texture` under 4096, or 2 GB or less of memory) uses no tiles. `earth.stats.tiles` and the `chikyu-tiles` event say what it is doing. New pure parts in `/realistic`: `tileLevel`, `tilesInView`, `coveringTile`, `pointOnEarth`, `tileRect`, `tileColumns`, `tileRows`, `parseManifest`, `TEXEL_SLACK`, `TILE_LIMIT`, `TILE_KEEP_MS`. **The demo's zoom limit on the realistic look goes from 5 to 20** when its tiles are found (the finest tile level is 4 times the widest picture) and stays 5 when they are not. Tests: the level and tile maths (the antimeridian, the poles, a tile bigger than the box) in `test/tiles.test.ts`; a made-up tile set in `e2e/tiles.gl.ts` (requests, drawing over the base, freeing after zoom-out, night tiles, failed tiles, a lost context, batching); a tiles round in `pnpm test:freeze` (GPU objects flat over six zoom rounds). Guide in English and Japanese: `docs/guides/earth-tiles.md`.
|
package/NOTICE.md
CHANGED
|
@@ -103,3 +103,7 @@ also by John Morris, under the MIT licence. Its shared 3D renderer draws the rea
|
|
|
103
103
|
No country flags, emblems, coats of arms or other official marks are drawn. Country names appear only
|
|
104
104
|
as plain descriptive words. All trademarks belong to their owners; this project is not affiliated with,
|
|
105
105
|
sponsored by or endorsed by any of them.
|
|
106
|
+
|
|
107
|
+
## The printable sheets
|
|
108
|
+
|
|
109
|
+
The sheets (`src/sheets/`) are drawn from the package's own data: the outlines above, the Sun's place by `subsolarPoint` (the low-precision formulas of NOAA's solar calculator, Meeus, Astronomical Algorithms, chapter 25) and the Earth's tilt (23.4393 degrees, the IAU's obliquity of the ecliptic at J2000). Nothing is traced from a map or a flag. The few figures written into the facts are the Earth's mean diameter (12,742 km, the IAU's nominal radius 6,371 km) and equatorial circumference (40,075 km, WGS84), and that the Pacific Ocean (about 165 million square kilometres, NOAA's National Ocean Service) is bigger than all the land (about 149 million). The share of the land each continent has is worked out from the outlines. The demo's sheets page takes each country's capital from kuni (MIT, by John Morris) and a flag, to check a drawing against, from hata (MIT, by John Morris; each flag's own licence is in hata's NOTICE.md); neither is on a sheet and neither is a dependency of the package.
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<p align="center"><strong>A line-drawn globe that turns at the Earth's own rate, and opens centred on where you are.</strong><br>
|
|
6
6
|
Country outlines in the same thin-line style as Hako Devices and Uchusen Rockets: an orthographic disc, the countries drawn on it, and the rim. One SVG, no canvas.</p>
|
|
7
7
|
|
|
8
|
-
<p align="center">Part of <strong>
|
|
8
|
+
<p align="center">Part of <strong>Space Program X (SPX)</strong>, the space packages: <a href="https://github.com/johnmorrisdotca/wakusei-planets">Wakusei Planets</a> · <a href="https://github.com/johnmorrisdotca/hoshi-stars">Hoshi Stars</a> · <a href="https://github.com/johnmorrisdotca/chikyu-earth">Chikyu Earth</a> · <a href="https://github.com/johnmorrisdotca/uchusen-rockets">Uchusen Rockets</a></p>
|
|
9
9
|
|
|
10
10
|
<p align="center">
|
|
11
11
|
<a href="https://github.com/johnmorrisdotca/chikyu-earth/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/johnmorrisdotca/chikyu-earth/actions/workflows/ci.yml/badge.svg"></a>
|
|
@@ -32,7 +32,7 @@ Country outlines in the same thin-line style as Hako Devices and Uchusen Rockets
|
|
|
32
32
|
- The Sun, the Moon and the planets where they are on a date and time (`/space`), and satellites at the places SGP4 puts them (`/satellites`), with a camera that rides along.
|
|
33
33
|
- Markers with labels, groups, clusters and events (`/markers`), on either globe.
|
|
34
34
|
- Pure parts that run on a server: `globe()`, the rotation and view maths, `COUNTRIES` and `countryList()`.
|
|
35
|
-
-
|
|
35
|
+
- Every live view zooms, pans and turns by itself, with no bar: drag, two-finger pinch, Ctrl and the wheel (a plain wheel at Fit scrolls the page) and the keys, through kazoku-ui's controls, from a tenth of Fit to 20 times on the line globe ([each range and why](docs/guides/zoom-and-pan.md)). Add `<kazoku-view-controls>` for buttons and the address.
|
|
36
36
|
- Names in English and Japanese, and a strict content security policy is enough.
|
|
37
37
|
|
|
38
38
|
## Install and use
|
|
@@ -62,11 +62,11 @@ One script tag from [jsDelivr](https://www.jsdelivr.com/package/npm/@johnmorrisd
|
|
|
62
62
|
</html>
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
The globe appears centred where you say; with no `center` it centres on the reader (the browser asks for their location; until they answer, and if they decline, it starts on the Greenwich meridian). `look` is `line` or `thick`.
|
|
65
|
+
The globe appears centred where you say; with no `center` it centres on the reader (the browser asks for their location; until they answer, and if they decline, it starts on the Greenwich meridian). `look` is `line` or `thick`. It also zooms and turns: drag, pinch, Ctrl and the wheel, the arrow keys (`controls="none"` takes that off).
|
|
66
66
|
|
|
67
67
|
### With the shared controls
|
|
68
68
|
|
|
69
|
-
The [kazoku-ui](https://github.com/johnmorrisdotca/kazoku-ui) view controls
|
|
69
|
+
The [kazoku-ui](https://github.com/johnmorrisdotca/kazoku-ui) view controls bar adds buttons and a slider and keeps the view in the address. One listener passes its camera on:
|
|
70
70
|
|
|
71
71
|
```html
|
|
72
72
|
<!doctype html>
|
|
@@ -86,10 +86,8 @@ The [kazoku-ui](https://github.com/johnmorrisdotca/kazoku-ui) view controls turn
|
|
|
86
86
|
</script>
|
|
87
87
|
</head>
|
|
88
88
|
<body>
|
|
89
|
-
<
|
|
90
|
-
|
|
91
|
-
</div>
|
|
92
|
-
<kazoku-view-controls for="globe" address grab-radius="fit" controls="advanced" tilt-max="90" speed="0.004178"></kazoku-view-controls>
|
|
89
|
+
<chikyu-earth id="earth" size="420" look="thick" center="139.7,35.7" tabindex="0"></chikyu-earth>
|
|
90
|
+
<kazoku-view-controls for="earth" address grab-radius="fit" controls="advanced" tilt-max="90" speed="0.004178"></kazoku-view-controls>
|
|
93
91
|
</body>
|
|
94
92
|
</html>
|
|
95
93
|
```
|
|
@@ -196,6 +194,18 @@ document.querySelector("chikyu-space")!.setSatellites("stations", createSatellit
|
|
|
196
194
|
as the body moves along its orbit; switch to another body and the camera glides there. Straight down or toward the horizon, from the body or following it at a distance, time faster or slower. It animates continuously, so it keeps to the
|
|
197
195
|
same budget: at most 30 frames a second (one a second for reduced motion), nothing drawn while paused, out of sight or hidden. [Ride along guide](docs/guides/ride-along.md), [docs/ride-along.md](docs/ride-along.md).
|
|
198
196
|
|
|
197
|
+
## Printable sheets
|
|
198
|
+
|
|
199
|
+
`@johnmorrisdotca/chikyu-earth/sheets` draws five printable sheets for children and everyone as SVG strings measured in millimetres, with no browser and no dependency: the globe to colour (the continents in thick outlines, the continents and oceans named; three sides), a world map, a "my country" sheet (the outline, the capital as a star, a box to draw the flag), day and night for a date and time (the line between them from the package's own sun position, the night hatched so black and white prints well) and the seasons (the Earth at four points round the Sun, tilted 23.4 degrees). A4, US Letter, A3 or Tabloid, English or Japanese, thick lines and big type (`kid`) or thin and small (`normal`). The demo's [sheets page](https://johnmorrisdotca.github.io/chikyu-earth/kids.html) puts kazoku-ui's header (the brand, the title, a Name box) and footer (credits, version, a QR code) round them and has Print / save PDF, and the Pages build makes [ready-made PDFs](https://johnmorrisdotca.github.io/chikyu-earth/pdf/). [Guide](docs/guides/printable-sheets.md).
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
import { dayNightSvg, globeSheetSvg, terminator } from "@johnmorrisdotca/chikyu-earth/sheets";
|
|
203
|
+
|
|
204
|
+
const room = { widthMm: 184.6, heightMm: 180 };
|
|
205
|
+
console.log(globeSheetSvg("americas", { ...room, lang: "en" }).includes("North"));
|
|
206
|
+
console.log(dayNightSvg(Date.UTC(2026, 5, 21, 12), room).includes('data-sun="0.'), terminator(Date.UTC(2026, 5, 21, 12), 12).length);
|
|
207
|
+
```
|
|
208
|
+
|
|
199
209
|
## Markers
|
|
200
210
|
|
|
201
211
|
Mark any place at `[lon, lat]` with a label, colour or icon, in groups you can show or hide, on either look. Chikyu ships no places; yours move with the globe, fade on the far side, make room
|
|
@@ -211,13 +221,24 @@ markers.add({ id: "tokyo", lon: 139.69, lat: 35.69, label: "Tokyo", group: "Citi
|
|
|
211
221
|
|
|
212
222
|
## Controls
|
|
213
223
|
|
|
214
|
-
The shared [kazoku-ui view controls](https://github.com/johnmorrisdotca/kazoku-ui)
|
|
215
|
-
|
|
224
|
+
The elements carry the shared [kazoku-ui view controls](https://github.com/johnmorrisdotca/kazoku-ui) themselves, so
|
|
225
|
+
every live view zooms, pans and turns with no bar: drag to turn (and move, once zoomed), touch pinch, Ctrl and the
|
|
226
|
+
wheel to zoom (a plain wheel at Fit scrolls the page), the arrow keys, `+`, `-` and `0` once the element is focused.
|
|
227
|
+
`controls="none"` takes the hands off; `zoom-min` and `zoom-max` change the range. Chikyu does not draw its own zoom,
|
|
216
228
|
rotate or drag controls.
|
|
217
229
|
|
|
230
|
+
| Element | Zoom range | Why it stops there |
|
|
231
|
+
| --- | --- | --- |
|
|
232
|
+
| `<chikyu-earth>` | 0.1 to 20 times | Natural Earth 1:110m outlines, redrawn at each zoom; at 20 times the view is about 640 km across and a coast is a few straight segments |
|
|
233
|
+
| `<chikyu-earth-realistic>` | 0.1 to 5 times; 20 with `tiles` found | the package's pictures are 4096 pixels across at most; the finest tile level is 4 times that |
|
|
234
|
+
| `<chikyu-space>` | a millionth to 2.5 times; 0.5 to 6 riding from a body | the zoom is the camera's distance (the whole solar system needs a millionth); close in, the Earth's picture and the textures stay sharp to 2.5 |
|
|
235
|
+
|
|
236
|
+
[Zoom, pan and turn](docs/guides/zoom-and-pan.md) says more. For buttons, a slider, Auto-turn and the address, add the
|
|
237
|
+
bar for the element (give it an `id` and a `tabindex`); it takes the hands over and the page applies its events:
|
|
238
|
+
|
|
218
239
|
```html
|
|
219
|
-
<
|
|
220
|
-
<kazoku-view-controls id="controls" for="
|
|
240
|
+
<chikyu-earth id="earth" size="420" tabindex="0"></chikyu-earth>
|
|
241
|
+
<kazoku-view-controls id="controls" for="earth" address grab-radius="fit" controls="advanced" tilt-max="90" speed="0.004178" autoplay></kazoku-view-controls>
|
|
221
242
|
```
|
|
222
243
|
|
|
223
244
|
```ts no-run
|
|
@@ -259,6 +280,8 @@ The rotation is the pair d3-geo's `rotate` takes: `[-longitude, -latitude]` cent
|
|
|
259
280
|
| `center` | `"longitude,latitude"` to centre on. Wins over geolocation. | the reader's location, else `0,0` |
|
|
260
281
|
| `look` | `line` or `thick`. (`style` is the older name for it: a framework reads `style` as CSS, so use `look` there.) | `line` |
|
|
261
282
|
| `graticule` | Draw a light graticule under the countries. | off |
|
|
283
|
+
| `controls` | `none` takes off the drag, pinch, wheel and keys the element carries. | on |
|
|
284
|
+
| `zoom-min`, `zoom-max` | The zoom range, over the element's own (0.1 to 20). | 0.1, 20 |
|
|
262
285
|
|
|
263
286
|
`setView(view, final = true)` applies a shared controller's `{ yaw, tilt, zoom, panX, panY }`. Every call updates
|
|
264
287
|
the state; pass `final: false` for the cheap relative transform during a gesture and `final: true` for the full
|
|
@@ -375,6 +398,8 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
|
|
|
375
398
|
| [The realistic Earth and markers](docs/guides/realistic-and-markers.md) | The Earth from space, markers |
|
|
376
399
|
| [Satellites](docs/guides/satellites.md) | SGP4 and the space view |
|
|
377
400
|
| [Ride along](docs/guides/ride-along.md) | A camera on a moving body |
|
|
401
|
+
| [Zoom, pan and turn](docs/guides/zoom-and-pan.md) | The hands every view carries, each zoom range and why |
|
|
402
|
+
| [Printable sheets](docs/guides/printable-sheets.md) | The globe, a world map, my country, day and night and the seasons to print and colour |
|
|
378
403
|
| [Why two packages](docs/guides/two-packages.md) | This package and wakusei-planets: which to install, alone and together |
|
|
379
404
|
| [How it stays light](docs/guides/how-it-works.md) | The budget |
|
|
380
405
|
| [Architecture](docs/guides/architecture.md) | How the layers fit |
|
|
@@ -472,7 +497,7 @@ Chikyu (地球, ちきゅう) is Japanese for the Earth.
|
|
|
472
497
|
## The family
|
|
473
498
|
|
|
474
499
|
<!-- family:start (made by scripts/family-readme.mjs from scripts/family-template.mjs; change those, not this) -->
|
|
475
|
-
Chikyu Earth is one of
|
|
500
|
+
Chikyu Earth is one of forty-one packages, each made for the same site, each at
|
|
476
501
|
[github.com/johnmorrisdotca](https://github.com/johnmorrisdotca) or [github.com/spxis](https://github.com/spxis). The code of every one is MIT.
|
|
477
502
|
|
|
478
503
|
**Games — board**
|
|
@@ -485,6 +510,7 @@ Chikyu Earth is one of thirty-three packages, each made for the same site, each
|
|
|
485
510
|
|
|
486
511
|
**Games — cards & tiles**
|
|
487
512
|
|
|
513
|
+
- [Fuda Cards](https://github.com/johnmorrisdotca/fuda-cards) (札): collectible card frames with a true thickness, foil, stacks, wear and a binder, as two web components. [Demo](https://johnmorrisdotca.github.io/fuda-cards/).
|
|
488
514
|
- [Hitotsu](https://github.com/johnmorrisdotca/hitotsu) (一つ): a colour-card shedding game for two to eight, with the house rules people play. [Demo](https://johnmorrisdotca.github.io/hitotsu/).
|
|
489
515
|
- [Jarajara](https://github.com/johnmorrisdotca/jarajara) (ジャラジャラ): mahjong tiles drawn as SVG, stacked layouts, and the matching solitaire Awase. [Demo](https://johnmorrisdotca.github.io/jarajara/).
|
|
490
516
|
- [Kumimoji](https://github.com/johnmorrisdotca/kumimoji) (組み文字): a crossword tile race, in English and Japanese kana. [Demo](https://johnmorrisdotca.github.io/kumimoji/).
|
|
@@ -511,20 +537,30 @@ Chikyu Earth is one of thirty-three packages, each made for the same site, each
|
|
|
511
537
|
|
|
512
538
|
- [Bushu](https://github.com/johnmorrisdotca/bushu) (部首): find a kanji by the parts it is made of. [Demo](https://johnmorrisdotca.github.io/bushu/).
|
|
513
539
|
- [Hikidashi](https://github.com/johnmorrisdotca/hikidashi) (引き出し): a drawer of small Japanese text tools: era dates, kanji numerals, readings and sentence difficulty. [Demo](https://johnmorrisdotca.github.io/hikidashi/).
|
|
540
|
+
- [Jisho](https://github.com/johnmorrisdotca/jisho) (辞書): words of Japanese looked up by reading or written form, and the grades, JLPT levels, readings and look-alike pairs of 2,999 kanji. [Demo](https://johnmorrisdotca.github.io/jisho/).
|
|
514
541
|
- [Kotoba](https://github.com/johnmorrisdotca/kotoba) (言葉): word lists and word-game rules in English, French, German and Japanese. [Demo](https://johnmorrisdotca.github.io/kotoba/).
|
|
515
542
|
|
|
543
|
+
**Space Program X**
|
|
544
|
+
|
|
545
|
+
- [Chikyu Earth](https://github.com/johnmorrisdotca/chikyu-earth) (地球): a line-drawn globe that turns at the Earth's own rate, with an optional realistic Earth from space and markers for any place. [Demo](https://johnmorrisdotca.github.io/chikyu-earth/).
|
|
546
|
+
- [Hoshi Stars](https://github.com/johnmorrisdotca/hoshi-stars) (星): the stars you can see without a telescope, with names, colours and distances, the constellations with their lines and boundaries, and the Messier objects, drawn on any of seven sky maps. [Demo](https://johnmorrisdotca.github.io/hoshi-stars/).
|
|
547
|
+
- [Uchusen Rockets](https://github.com/johnmorrisdotca/uchusen-rockets) (宇宙船): rockets drawn from sourced sizes, as line drawings and 3D views you can take apart and turn, with a check that a rocket really goes together. [Demo](https://johnmorrisdotca.github.io/uchusen-rockets/).
|
|
548
|
+
- [Wakusei Planets](https://github.com/johnmorrisdotca/wakusei-planets) (惑星): the Sun, the planets and their moons, as line drawings, shaded drawings and painted surface maps, with their real sizes, tilt and rotation. [Demo](https://johnmorrisdotca.github.io/wakusei-planets/).
|
|
549
|
+
|
|
516
550
|
**Geography & data**
|
|
517
551
|
|
|
518
552
|
- [address-plus](https://github.com/johnmorrisdotca/address-plus) (アドレスプラス): parse and format addresses in the United States, Canada, Japan, Australia, France, Germany and the United Kingdom. [Demo](https://johnmorrisdotca.github.io/address-plus/).
|
|
519
|
-
- [Chikyu Earth](https://github.com/johnmorrisdotca/chikyu-earth) (地球): a line-drawn globe that turns at the Earth's own rate, with an optional realistic Earth from space and markers for any place. [Demo](https://johnmorrisdotca.github.io/chikyu-earth/).
|
|
520
553
|
- [Chizu](https://github.com/johnmorrisdotca/chizu) (地図): maps of the world and of countries' regions, in English and Japanese, with a quiz and callouts. [Demo](https://johnmorrisdotca.github.io/chizu/).
|
|
554
|
+
- [Hako Devices](https://github.com/johnmorrisdotca/hako-devices) (箱): line drawings and 3D views of computers, phones, consoles and NAS boxes, from published sizes. [Demo](https://johnmorrisdotca.github.io/hako-devices/).
|
|
521
555
|
- [Hata](https://github.com/johnmorrisdotca/hata) (旗): country and regional flags as SVG, at their true proportions and keyed by ISO code. [Demo](https://johnmorrisdotca.github.io/hata/).
|
|
556
|
+
- [Koyomi Calendars](https://github.com/johnmorrisdotca/koyomi-calendars) (暦): calendar-page icons and whole months as SVG, in light and dark, with page-turning from one day to the next. [Demo](https://johnmorrisdotca.github.io/koyomi-calendars/).
|
|
522
557
|
- [Kuni](https://github.com/johnmorrisdotca/kuni) (国): countries and their regions, with ISO codes and names in English and Japanese. [Demo](https://johnmorrisdotca.github.io/kuni/).
|
|
523
558
|
|
|
524
559
|
**Sports**
|
|
525
560
|
|
|
526
561
|
- [Dougu Sports](https://github.com/johnmorrisdotca/dougu-sports) (道具): sports emblems as SVG: trophies, medals, crests, and the ball and gear of every sport, with optional 3D turning. [Demo](https://johnmorrisdotca.github.io/dougu-sports/).
|
|
527
562
|
- [Kyogijo Stadiums](https://github.com/johnmorrisdotca/kyogijo-stadiums) (競技場): sports fields, rinks, courts and ballparks drawn to scale as SVG, with each team and the score on them. [Demo](https://johnmorrisdotca.github.io/kyogijo-stadiums/).
|
|
563
|
+
- [Meigen Sports](https://github.com/johnmorrisdotca/meigen-sports) (名言): sports quotations and on-this-day history. [Demo](https://johnmorrisdotca.github.io/meigen-sports/).
|
|
528
564
|
- [Senshu Jerseys](https://github.com/johnmorrisdotca/senshu-jerseys) (選手): sports jerseys, sweaters, kits, caps, helmets and retired-number banners as SVG, front and back, with optional 2.5D turning. [Demo](https://johnmorrisdotca.github.io/senshu-jerseys/).
|
|
529
565
|
- [Taisen Brackets](https://github.com/johnmorrisdotca/taisen-brackets) (対戦): a sport-agnostic tournament bracket, drawn as SVG, from a list of ties. [Demo](https://johnmorrisdotca.github.io/taisen-brackets/).
|
|
530
566
|
|
|
@@ -533,7 +569,7 @@ Chikyu Earth is one of thirty-three packages, each made for the same site, each
|
|
|
533
569
|
- [REST in Pieces](https://github.com/spxis/rest-in-pieces) (レスト・イン・ピーシーズ): seeded test data and REST APIs for frontend development, with latency and error drills. [Demo](https://spxis.github.io/rest-in-pieces/).
|
|
534
570
|
|
|
535
571
|
|
|
536
|
-
**This package is Chikyu Earth.** The demos of all
|
|
572
|
+
**This package is Chikyu Earth.** The demos of all forty-one share one header and footer, so each links the rest.
|
|
537
573
|
<!-- family:end -->
|
|
538
574
|
|
|
539
575
|
## The rest
|
package/dist/element.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
1
2
|
import type { OverlayHost } from "./markers/layer.ts";
|
|
2
3
|
import type { GeoPoint, GlobeView } from "./types.ts";
|
|
3
4
|
/**
|
|
4
5
|
* The `<chikyu-earth>` custom element: the line globe, drawn as SVG in its shadow root. Importing this entry point registers the tag once. It takes the attributes `size` (pixels, 320 by default), `center` (`"lon,lat"`; wins over the browser's location), `look` (`line` or `thick`; `style` is the older name for it, and a framework that reads `style` as CSS cannot use it) and `graticule`, and a shared view controller's camera through `setView`.
|
|
6
|
+
* It carries kazoku-ui's controls itself: a drag turns it, two fingers pinch, Ctrl and the wheel zoom (a plain wheel at Fit scrolls the page) and the arrow keys, + and - work once it is focused, from a tenth of Fit to 20 times. `controls="none"` turns them off; `zoom-min` and `zoom-max` change the range. A `<kazoku-view-controls for="...">` on the element takes the hands over, and the page applies its events with `setView`.
|
|
5
7
|
*
|
|
6
8
|
* @example
|
|
7
9
|
* ```ts no-run
|
|
@@ -16,6 +18,8 @@ import type { GeoPoint, GlobeView } from "./types.ts";
|
|
|
16
18
|
export declare class ChikyuEarth extends HTMLElement {
|
|
17
19
|
#private;
|
|
18
20
|
static observedAttributes: string[];
|
|
21
|
+
/** The controller behind the element's own hands (`play`, `set`, `fit`, `state`), while it is in a page. */
|
|
22
|
+
get controller(): ViewController | undefined;
|
|
19
23
|
/** Where the view is centred now: the `center` attribute, else the reader's place once the browser has answered. */
|
|
20
24
|
get centre(): GeoPoint;
|
|
21
25
|
/** A box laid over the globe for markers (see `@johnmorrisdotca/chikyu-earth/markers`): where it is, the pose of the last drawing, and a way to hear the next. */
|
package/dist/element.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// <chikyu-earth>: the globe as a web component. A shared view controller supplies its yaw, tilt, zoom and pan;
|
|
2
2
|
// it opens centred on where you are (the `center` attribute wins over geolocation). Importing registers it once.
|
|
3
|
+
import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
3
4
|
import { adoptStyles } from "./adopt.js";
|
|
4
5
|
import { globe } from "./globe.js";
|
|
5
6
|
import { cleanStyle } from "./styles.js";
|
|
@@ -16,9 +17,14 @@ const readCentre = (value) => {
|
|
|
16
17
|
};
|
|
17
18
|
/** The least time between two redraws of the projection while a hand is turning the globe: 30 a second at most. */
|
|
18
19
|
const LIVE_MS = 1000 / 30;
|
|
20
|
+
/** The automatic turn is slow enough that one redraw a second is smooth. */
|
|
21
|
+
const AUTO_MS = 1000;
|
|
22
|
+
/** Tilt to the poles; zoom from a tenth of Fit, which leaves the whole globe small in the view, to 20 times: the outlines are Natural Earth 1:110m, and past about 20 times their straight segments are longer than the view is wide. */
|
|
23
|
+
const LIMITS = { tiltMax: 90, zoomMin: 0.1, zoomMax: 20 };
|
|
19
24
|
const STYLE = ":host{display:block;position:relative}.holder svg{display:block;width:100%;height:auto}.overlay{position:absolute;inset:0;pointer-events:none;transform-origin:50% 50%}";
|
|
20
25
|
/**
|
|
21
26
|
* The `<chikyu-earth>` custom element: the line globe, drawn as SVG in its shadow root. Importing this entry point registers the tag once. It takes the attributes `size` (pixels, 320 by default), `center` (`"lon,lat"`; wins over the browser's location), `look` (`line` or `thick`; `style` is the older name for it, and a framework that reads `style` as CSS cannot use it) and `graticule`, and a shared view controller's camera through `setView`.
|
|
27
|
+
* It carries kazoku-ui's controls itself: a drag turns it, two fingers pinch, Ctrl and the wheel zoom (a plain wheel at Fit scrolls the page) and the arrow keys, + and - work once it is focused, from a tenth of Fit to 20 times. `controls="none"` turns them off; `zoom-min` and `zoom-max` change the range. A `<kazoku-view-controls for="...">` on the element takes the hands over, and the page applies its events with `setView`.
|
|
22
28
|
*
|
|
23
29
|
* @example
|
|
24
30
|
* ```ts no-run
|
|
@@ -40,6 +46,11 @@ export class ChikyuEarth extends HTMLElement {
|
|
|
40
46
|
#pose = null;
|
|
41
47
|
#liveTimer;
|
|
42
48
|
#liveAt = 0;
|
|
49
|
+
#hands;
|
|
50
|
+
/** The controller behind the element's own hands (`play`, `set`, `fit`, `state`), while it is in a page. */
|
|
51
|
+
get controller() {
|
|
52
|
+
return this.#hands?.controller;
|
|
53
|
+
}
|
|
43
54
|
/** Where the view is centred now: the `center` attribute, else the reader's place once the browser has answered. */
|
|
44
55
|
get centre() {
|
|
45
56
|
return { ...this.#centre };
|
|
@@ -59,11 +70,19 @@ export class ChikyuEarth extends HTMLElement {
|
|
|
59
70
|
disconnectedCallback() {
|
|
60
71
|
clearTimeout(this.#liveTimer);
|
|
61
72
|
this.#liveTimer = undefined;
|
|
73
|
+
this.#hands?.unbind();
|
|
74
|
+
this.#hands = undefined;
|
|
62
75
|
}
|
|
63
76
|
connectedCallback() {
|
|
64
77
|
this.#centre = readCentre(this.getAttribute("center")) ?? { lon: 0, lat: 0 };
|
|
65
78
|
this.#render();
|
|
66
79
|
this.#locate();
|
|
80
|
+
this.#hands = carryControls(this, {
|
|
81
|
+
initial: this.#view,
|
|
82
|
+
grabRadius: "fit",
|
|
83
|
+
limits: LIMITS,
|
|
84
|
+
onChange: (state, info) => this.setView(state, info.final, info.reason !== "auto"),
|
|
85
|
+
});
|
|
67
86
|
}
|
|
68
87
|
attributeChangedCallback(name, _old, value) {
|
|
69
88
|
if (name === "center")
|
|
@@ -85,12 +104,16 @@ export class ChikyuEarth extends HTMLElement {
|
|
|
85
104
|
this.#render();
|
|
86
105
|
return;
|
|
87
106
|
}
|
|
107
|
+
const turned = view.yaw !== this.#drawn.yaw || view.tilt !== this.#drawn.tilt;
|
|
108
|
+
if (!live && turned && performance.now() - this.#liveAt >= AUTO_MS) {
|
|
109
|
+
this.#render();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
88
112
|
this.#transform();
|
|
89
|
-
if (live &&
|
|
113
|
+
if (live && turned && this.#liveTimer === undefined) {
|
|
90
114
|
const wait = Math.max(0, LIVE_MS - (performance.now() - this.#liveAt));
|
|
91
115
|
this.#liveTimer = setTimeout(() => {
|
|
92
116
|
this.#liveTimer = undefined;
|
|
93
|
-
this.#liveAt = performance.now();
|
|
94
117
|
this.#render();
|
|
95
118
|
}, wait);
|
|
96
119
|
}
|
|
@@ -149,6 +172,7 @@ export class ChikyuEarth extends HTMLElement {
|
|
|
149
172
|
listener(pose);
|
|
150
173
|
}
|
|
151
174
|
#render() {
|
|
175
|
+
this.#liveAt = performance.now();
|
|
152
176
|
const size = Number(this.getAttribute("size")) || 320;
|
|
153
177
|
const style = cleanStyle(this.getAttribute("look") ?? this.getAttribute("style"));
|
|
154
178
|
const svg = globe({ size, style, centre: this.#centre, view: this.#view, graticule: this.hasAttribute("graticule") });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
1
2
|
import type { GeoPoint, GlobeView } from "../types.ts";
|
|
2
3
|
import { type LightMode } from "./earth.ts";
|
|
3
4
|
import { setSharedRenderer, setThreeLoader } from "./shared.ts";
|
|
@@ -53,6 +54,8 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
53
54
|
connectedCallback(): void;
|
|
54
55
|
disconnectedCallback(): void;
|
|
55
56
|
attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
|
|
57
|
+
/** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
|
|
58
|
+
get controller(): ViewController | undefined;
|
|
56
59
|
/** Where the finer map tiles are served from (a folder with `manifest.json`), or `null` for none; the attribute `tiles`. The Earth loads only the tiles in view, over its own pictures. */
|
|
57
60
|
get tiles(): string | null;
|
|
58
61
|
set tiles(value: string | null);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// <chikyu-earth-realistic>: the Earth from space as a web component, drawn by kazoku-ui's shared 3D renderer (one WebGL context for the
|
|
2
2
|
// page) with three.js, which is the page's own. Optional entry point: the flat `<chikyu-earth>` needs neither. It draws only when something
|
|
3
3
|
// changes, at most 30 times a second, and nothing at all while it is out of sight or the tab is hidden.
|
|
4
|
+
import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
4
5
|
import { adoptStyles } from "../adopt.js";
|
|
5
|
-
import { createEarthItem, lookAt, newModel } from "./earth.js";
|
|
6
|
+
import { createEarthItem, discRadius, lookAt, newModel } from "./earth.js";
|
|
6
7
|
import { createGate, frameCap } from "./gate.js";
|
|
7
8
|
import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
|
|
8
9
|
export { setSharedRenderer, setThreeLoader };
|
|
@@ -12,6 +13,10 @@ const RAD = Math.PI / 180;
|
|
|
12
13
|
/** The Sun and the clouds are re-placed this often while the time is "now": 15 degrees an hour is 0.25 degree a minute. */
|
|
13
14
|
const LIVE_TICK_MS = 60_000;
|
|
14
15
|
const MIN_TICK_MS = 1000;
|
|
16
|
+
/** Tilt to the poles; zoom from a tenth of Fit, which leaves the whole Earth small in the view, to 5 times: the package's own pictures are sharp to about 5 times. */
|
|
17
|
+
const LIMITS = { tiltMax: 90, zoomMin: 0.1, zoomMax: 5 };
|
|
18
|
+
/** With the finer tiles the detail runs 4 times further: the finest level is 4 times wider than the widest picture. */
|
|
19
|
+
const TILES_ZOOM_MAX = "20";
|
|
15
20
|
const readCentre = (value) => {
|
|
16
21
|
if (!value)
|
|
17
22
|
return null;
|
|
@@ -74,6 +79,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
74
79
|
#overlay;
|
|
75
80
|
#pose = null;
|
|
76
81
|
#listeners = new Set();
|
|
82
|
+
#hands;
|
|
83
|
+
#reach = null;
|
|
77
84
|
#onContext = (state) => {
|
|
78
85
|
if (state === "unavailable")
|
|
79
86
|
this.#fail("WebGL is not available");
|
|
@@ -116,10 +123,18 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
116
123
|
textureBase: () => this.#textureBase(),
|
|
117
124
|
cap: () => this.#textureCap(),
|
|
118
125
|
tiles: () => this.tiles ?? undefined,
|
|
119
|
-
onTiles: (layers) =>
|
|
126
|
+
onTiles: (layers) => {
|
|
127
|
+
if (!this.hasAttribute("zoom-max") || this.getAttribute("zoom-max") === this.#reach) {
|
|
128
|
+
this.#reach = TILES_ZOOM_MAX;
|
|
129
|
+
this.setAttribute("zoom-max", TILES_ZOOM_MAX);
|
|
130
|
+
}
|
|
131
|
+
this.dispatchEvent(new CustomEvent("chikyu-tiles", { detail: { layers } }));
|
|
132
|
+
},
|
|
120
133
|
drift: 1.5,
|
|
121
134
|
invalidate: () => this.#gate?.soon(),
|
|
122
135
|
onPose: (pose) => {
|
|
136
|
+
if (this.#hands)
|
|
137
|
+
this.#hands.controller.grabRadius = discRadius(pose.width, pose.height, 1);
|
|
123
138
|
this.#pose = { ...pose, transform: "" };
|
|
124
139
|
for (const listener of this.#listeners)
|
|
125
140
|
listener(this.#pose);
|
|
@@ -143,12 +158,18 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
143
158
|
});
|
|
144
159
|
this.addEventListener("pointerdown", this.#take);
|
|
145
160
|
this.addEventListener("focusin", this.#take);
|
|
161
|
+
this.#hands = carryControls(this, { initial: this.#model.view, limits: LIMITS, onChange: (state, info) => this.setView(state, info.final) });
|
|
146
162
|
this.#startTick();
|
|
147
163
|
this.#locate();
|
|
148
164
|
}
|
|
149
165
|
disconnectedCallback() {
|
|
150
166
|
this.removeEventListener("pointerdown", this.#take);
|
|
151
167
|
this.removeEventListener("focusin", this.#take);
|
|
168
|
+
this.#hands?.unbind();
|
|
169
|
+
this.#hands = undefined;
|
|
170
|
+
if (this.#reach !== null && this.getAttribute("zoom-max") === this.#reach)
|
|
171
|
+
this.removeAttribute("zoom-max");
|
|
172
|
+
this.#reach = null;
|
|
152
173
|
clearInterval(this.#tick);
|
|
153
174
|
this.#tick = undefined;
|
|
154
175
|
this.#gate?.cancel();
|
|
@@ -173,6 +194,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
173
194
|
else if (name === "tiles")
|
|
174
195
|
this.#gate?.soon();
|
|
175
196
|
}
|
|
197
|
+
/** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
|
|
198
|
+
get controller() {
|
|
199
|
+
return this.#hands?.controller;
|
|
200
|
+
}
|
|
176
201
|
/** Where the finer map tiles are served from (a folder with `manifest.json`), or `null` for none; the attribute `tiles`. The Earth loads only the tiles in view, over its own pictures. */
|
|
177
202
|
get tiles() {
|
|
178
203
|
const given = this.getAttribute("tiles");
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** The type of a printed sheet, in millimetres: `kid` is large and round for children, `normal` for everyone else. */
|
|
2
|
+
export interface SheetType {
|
|
3
|
+
titleMm: number;
|
|
4
|
+
nameMm: number;
|
|
5
|
+
bodyMm: number;
|
|
6
|
+
smallMm: number;
|
|
7
|
+
/** The thickness of a sheet's own lines. */
|
|
8
|
+
lineMm: number;
|
|
9
|
+
}
|
|
10
|
+
/** The two type presets: the same sizes as kazoku-ui's `TYPE_PRESETS` (title, name, body and small in points, and the line in millimetres), checked against it by a test. */
|
|
11
|
+
export declare const TYPES: Readonly<Record<"kid" | "normal", SheetType>>;
|
|
12
|
+
export type Lang = "en" | "ja";
|
|
13
|
+
export declare const n: (v: number) => string;
|
|
14
|
+
export declare const esc: (text: string) => string;
|
|
15
|
+
/** The width of a text in millimetres, estimated on the wide side so a fallback font still fits: a full-width character is as wide as the type is tall, a Latin capital or a digit 0.82 of it, a small letter 0.7 (DejaVu Sans Bold, the usual fallback on a server, is that wide), a percent sign or a wide capital (M, W) 1.0, a space or a stop 0.38. */
|
|
16
|
+
export declare function textWidth(text: string, sizeMm: number): number;
|
|
17
|
+
/** Break a sentence into lines no wider than `maxMm`: at spaces for English; for Japanese after a space or a comma or a full stop (the words are written with spaces between), and anywhere only for a word wider than the line. */
|
|
18
|
+
export declare function wrap(text: string, maxMm: number, sizeMm: number): string[];
|
|
19
|
+
export declare const text: (x: number, y: number, size: number, body: string, extra?: string) => string;
|
|
20
|
+
/** Lines of words one under the other, left aligned at `x`, the first baseline at `y`; the height they take is `lines * 1.3 * size`. */
|
|
21
|
+
export declare function paragraph(words: string, x: number, y: number, widthMm: number, sizeMm: number, extra?: string): {
|
|
22
|
+
markup: string;
|
|
23
|
+
height: number;
|
|
24
|
+
};
|
|
25
|
+
export declare const svgOpen: (width: number, height: number, label: string, id: string) => string;
|
|
26
|
+
/** Lines of words at the foot of a page: the last baseline sits `0.55` of a line above the edge, so the letters that hang below it still fit the room in a font taller than the sheet's own. */
|
|
27
|
+
export declare function footer(words: string, widthMm: number, heightMm: number, sizeMm: number, extra?: string): {
|
|
28
|
+
markup: string;
|
|
29
|
+
height: number;
|
|
30
|
+
};
|
|
31
|
+
export type TypeName = "kid" | "normal";
|
|
32
|
+
/** The thickness of a sheet's outline in millimetres, and of the lines inside it (2.5 mm when the outline is 3). */
|
|
33
|
+
export declare const outlineMm: (type: TypeName) => number;
|
|
34
|
+
export declare const innerMm: (type: TypeName) => number;
|
|
35
|
+
/** The size of the names written on a picture: 24 pt for a child (never less), else the normal name size. */
|
|
36
|
+
export declare const labelMm: (type: TypeName) => number;
|
|
37
|
+
/** Text with a white edge so it reads over a line: the edge is painted first. */
|
|
38
|
+
export declare const haloText: (x: number, y: number, size: number, body: string, extra?: string, anchor?: "start" | "middle" | "end") => string;
|
|
39
|
+
/** A name of one or more lines, centred on `x` with the middle of the block at `y`. */
|
|
40
|
+
export declare function nameBlock(lines: readonly string[], x: number, y: number, size: number, extra?: string): {
|
|
41
|
+
markup: string;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
};
|
|
45
|
+
export interface Block {
|
|
46
|
+
markup: string;
|
|
47
|
+
height: number;
|
|
48
|
+
}
|
|
49
|
+
/** The facts as numbered dots and lines of words, one under the other, `width` wide, the first at `y`. */
|
|
50
|
+
export declare function factsBlock(list: readonly string[], width: number, y: number, type?: TypeName): Block;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// What every printable sheet shares: the type sizes (the same numbers as kazoku-ui's print part, so a test holds them together), text measuring and wrapping, and the small helpers that write SVG.
|
|
2
|
+
// Pure: strings in, strings out. Nothing here touches the DOM, and kazoku-ui is not imported (this package has no runtime dependency).
|
|
3
|
+
const PT = 25.4 / 72;
|
|
4
|
+
/** The two type presets: the same sizes as kazoku-ui's `TYPE_PRESETS` (title, name, body and small in points, and the line in millimetres), checked against it by a test. */
|
|
5
|
+
export const TYPES = {
|
|
6
|
+
kid: { titleMm: 40 * PT, nameMm: 28 * PT, bodyMm: 18 * PT, smallMm: 10 * PT, lineMm: 3 },
|
|
7
|
+
normal: { titleMm: 24 * PT, nameMm: 14 * PT, bodyMm: 11 * PT, smallMm: 8 * PT, lineMm: 0.4 },
|
|
8
|
+
};
|
|
9
|
+
export const n = (v) => (Math.round(v * 100) / 100).toString();
|
|
10
|
+
export const esc = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
11
|
+
/** The width of a text in millimetres, estimated on the wide side so a fallback font still fits: a full-width character is as wide as the type is tall, a Latin capital or a digit 0.82 of it, a small letter 0.7 (DejaVu Sans Bold, the usual fallback on a server, is that wide), a percent sign or a wide capital (M, W) 1.0, a space or a stop 0.38. */
|
|
12
|
+
export function textWidth(text, sizeMm) {
|
|
13
|
+
let total = 0;
|
|
14
|
+
for (const ch of text)
|
|
15
|
+
total += /[\u3000-ヿ一-鿿-]/.test(ch) ? sizeMm : /[ .,:;!'|]/.test(ch) ? 0.38 * sizeMm : /[%@#&MW]/.test(ch) ? 1.0 * sizeMm : /[A-Z0-9]/.test(ch) ? 0.82 * sizeMm : 0.7 * sizeMm;
|
|
16
|
+
return total;
|
|
17
|
+
}
|
|
18
|
+
function cut(line, maxMm, sizeMm) {
|
|
19
|
+
const out = [];
|
|
20
|
+
let current = "";
|
|
21
|
+
for (const ch of line) {
|
|
22
|
+
if (current !== "" && textWidth(current + ch, sizeMm) > maxMm && !/[。、!?」)]/.test(ch)) {
|
|
23
|
+
out.push(current);
|
|
24
|
+
current = ch;
|
|
25
|
+
}
|
|
26
|
+
else
|
|
27
|
+
current += ch;
|
|
28
|
+
}
|
|
29
|
+
return current === "" ? out : [...out, current];
|
|
30
|
+
}
|
|
31
|
+
/** Break a sentence into lines no wider than `maxMm`: at spaces for English; for Japanese after a space or a comma or a full stop (the words are written with spaces between), and anywhere only for a word wider than the line. */
|
|
32
|
+
export function wrap(text, maxMm, sizeMm) {
|
|
33
|
+
const japanese = /[-ヿ一-鿿]/.test(text);
|
|
34
|
+
const pieces = japanese ? (text.match(/[^ 、。!]+[ 、。!]?/g) ?? [text]) : text.split(" ");
|
|
35
|
+
const joiner = japanese ? "" : " ";
|
|
36
|
+
const lines = [];
|
|
37
|
+
let line = "";
|
|
38
|
+
for (const piece of pieces) {
|
|
39
|
+
const next = line === "" ? piece : line + joiner + piece;
|
|
40
|
+
if (line !== "" && textWidth(next, sizeMm) > maxMm) {
|
|
41
|
+
lines.push(line);
|
|
42
|
+
line = piece;
|
|
43
|
+
}
|
|
44
|
+
else
|
|
45
|
+
line = next;
|
|
46
|
+
}
|
|
47
|
+
if (line !== "")
|
|
48
|
+
lines.push(line);
|
|
49
|
+
return japanese ? lines.flatMap((one) => cut(one.trimEnd(), maxMm, sizeMm)) : lines;
|
|
50
|
+
}
|
|
51
|
+
export const text = (x, y, size, body, extra = "") => `<text x="${n(x)}" y="${n(y)}" font-size="${n(size)}" font-weight="700" fill="#000"${extra}>${esc(body)}</text>`;
|
|
52
|
+
/** Lines of words one under the other, left aligned at `x`, the first baseline at `y`; the height they take is `lines * 1.3 * size`. */
|
|
53
|
+
export function paragraph(words, x, y, widthMm, sizeMm, extra = "") {
|
|
54
|
+
const lines = wrap(words, widthMm, sizeMm);
|
|
55
|
+
return { markup: lines.map((line, i) => text(x, y + sizeMm * 1.3 * i, sizeMm, line, extra)).join(""), height: lines.length * sizeMm * 1.3 };
|
|
56
|
+
}
|
|
57
|
+
export const svgOpen = (width, height, label, id) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${n(width)} ${n(height)}" width="100%" height="100%" preserveAspectRatio="xMidYMid meet" role="img" aria-label="${esc(label)}" data-chikyu-sheet="${esc(id)}" font-family="inherit"><title>${esc(label)}</title>`;
|
|
58
|
+
/** Lines of words at the foot of a page: the last baseline sits `0.55` of a line above the edge, so the letters that hang below it still fit the room in a font taller than the sheet's own. */
|
|
59
|
+
export function footer(words, widthMm, heightMm, sizeMm, extra = "") {
|
|
60
|
+
const lines = wrap(words, widthMm - 2.4, sizeMm);
|
|
61
|
+
const last = heightMm - 0.55 * sizeMm;
|
|
62
|
+
return { markup: lines.map((line, i) => text(1.2, last - (lines.length - 1 - i) * sizeMm * 1.3, sizeMm, line, extra)).join(""), height: lines.length * sizeMm * 1.3 + 0.25 * sizeMm };
|
|
63
|
+
}
|
|
64
|
+
/** The thickness of a sheet's outline in millimetres, and of the lines inside it (2.5 mm when the outline is 3). */
|
|
65
|
+
export const outlineMm = (type) => TYPES[type].lineMm;
|
|
66
|
+
export const innerMm = (type) => Math.max(TYPES[type].lineMm * (2.5 / 3), 0.3);
|
|
67
|
+
/** The size of the names written on a picture: 24 pt for a child (never less), else the normal name size. */
|
|
68
|
+
export const labelMm = (type) => (type === "kid" ? 24 * PT : TYPES.normal.nameMm);
|
|
69
|
+
/** Text with a white edge so it reads over a line: the edge is painted first. */
|
|
70
|
+
export const haloText = (x, y, size, body, extra = "", anchor = "middle") => `<text x="${n(x)}" y="${n(y)}" font-size="${n(size)}" font-weight="700" fill="#000" stroke="#fff" stroke-width="${n(size * 0.28)}" stroke-linejoin="round" paint-order="stroke" text-anchor="${anchor}"${extra}>${esc(body)}</text>`;
|
|
71
|
+
/** A name of one or more lines, centred on `x` with the middle of the block at `y`. */
|
|
72
|
+
export function nameBlock(lines, x, y, size, extra = "") {
|
|
73
|
+
const pitch = size * 1.12;
|
|
74
|
+
const top = y - ((lines.length - 1) * pitch) / 2 + size * 0.34;
|
|
75
|
+
return { markup: lines.map((line, i) => haloText(x, top + i * pitch, size, line, extra)).join(""), width: Math.max(...lines.map((line) => textWidth(line, size))), height: lines.length * pitch };
|
|
76
|
+
}
|
|
77
|
+
/** The facts as numbered dots and lines of words, one under the other, `width` wide, the first at `y`. */
|
|
78
|
+
export function factsBlock(list, width, y, type = "kid") {
|
|
79
|
+
const bodyMm = TYPES[type].bodyMm;
|
|
80
|
+
const dot = type === "kid" ? 4.6 : 2.6;
|
|
81
|
+
const left = 2 * dot + 4;
|
|
82
|
+
const lineHeight = bodyMm * 1.3;
|
|
83
|
+
const out = [];
|
|
84
|
+
let at = y;
|
|
85
|
+
list.forEach((fact, i) => {
|
|
86
|
+
const lines = wrap(fact, width - left, bodyMm);
|
|
87
|
+
const rowHeight = Math.max(2 * dot, lines.length * lineHeight);
|
|
88
|
+
const mid = at + rowHeight / 2;
|
|
89
|
+
out.push(`<circle cx="${n(dot)}" cy="${n(mid)}" r="${dot}" fill="#000"/>`, `<text x="${n(dot)}" y="${n(mid + bodyMm * 0.36)}" font-size="${n(bodyMm)}" font-weight="700" fill="#fff" text-anchor="middle">${i + 1}</text>`);
|
|
90
|
+
lines.forEach((line, k) => out.push(text(left, mid - (lines.length * lineHeight) / 2 + lineHeight * (k + 0.72), bodyMm, line, ' data-fact=""')));
|
|
91
|
+
at += rowHeight + 3.5;
|
|
92
|
+
});
|
|
93
|
+
return { markup: `<g data-facts="">${out.join("")}</g>`, height: at - y - 3.5 };
|
|
94
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { SheetOptions } from "./earth.ts";
|
|
2
|
+
/**
|
|
3
|
+
* A capital city: its name, as the sheet says it in each language, and where it is.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { type Capital } from "@johnmorrisdotca/chikyu-earth/sheets";
|
|
8
|
+
*
|
|
9
|
+
* const tokyo: Capital = { name: "Tokyo", ja: "東京", lon: 139.69, lat: 35.69 };
|
|
10
|
+
* console.log(tokyo.name);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface Capital {
|
|
14
|
+
name: string;
|
|
15
|
+
/** The Japanese name, when it has one. */
|
|
16
|
+
ja?: string;
|
|
17
|
+
lon: number;
|
|
18
|
+
lat: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* What a "my country" sheet is drawn for: the room, the language and the type, and the capital.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { countrySheetSvg, type CountryOptions } from "@johnmorrisdotca/chikyu-earth/sheets";
|
|
26
|
+
*
|
|
27
|
+
* const options: CountryOptions = { widthMm: 184.6, heightMm: 170, capital: { name: "Paris", lon: 2.35, lat: 48.86 } };
|
|
28
|
+
* console.log(countrySheetSvg("FR", options)?.includes("Paris"));
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export interface CountryOptions extends SheetOptions {
|
|
32
|
+
/** The capital, to put a star on it and say its name; without it the sheet asks the child to find it. */
|
|
33
|
+
capital?: Capital;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A "my country" colouring sheet: the country's outline as big as the room allows (an equal-area view centred on the country, with a far territory such as French Guiana left out), its capital as a star when `capital` is given, a box to draw the flag in, and three facts:
|
|
37
|
+
* the continent, the countries it touches, the capital. The flag is a box to fill in, never a picture: the sheet carries no flag.
|
|
38
|
+
* @param alpha2 - The country's two-letter code, such as `JP`.
|
|
39
|
+
* @param options - The room, the language, the type and the capital.
|
|
40
|
+
* @returns The `<svg>` markup, or `undefined` when the package has no outline for the code.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { countrySheetSvg } from "@johnmorrisdotca/chikyu-earth/sheets";
|
|
45
|
+
*
|
|
46
|
+
* const svg = countrySheetSvg("JP", { widthMm: 184.6, heightMm: 180, capital: { name: "Tokyo", lon: 139.7, lat: 35.7 } });
|
|
47
|
+
* console.log(svg?.includes("Tokyo"), svg?.includes("Draw the flag!"));
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function countrySheetSvg(alpha2: string, options: CountryOptions): string | undefined;
|