@johnmorrisdotca/chikyu-earth 0.18.0 → 0.20.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 +9 -0
- package/NOTICE.md +4 -0
- package/README.md +27 -3
- 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/package.json +11 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.20.0 - 2026-11-09
|
|
6
|
+
|
|
7
|
+
- **Wide is theatre mode** (MODULES-717). Wide gives the globe the page's own column, centred, out to where the side panel was; the page no longer stretches to the window's edges.
|
|
8
|
+
- **The demo has a Wide layout and shows its zoom readout** (MODULES-717). kazoku-ui's `<kazoku-wide-toggle>` (and the T key, and `?wide=on` in the address) gives the globe the page's whole width, 16:9 and no taller than 80% of the screen, with the bar under it and the controls below as a row of boxes; the line globe, the realistic Earth and the space view all grow to the room, stay round, and the 3D looks draw again at the new size inside the renderer's caps. On a phone it is one column and there is no button. The toggle speaks the page's language. The shared bar's zoom readout (`2.4×`, between zoom out and zoom in; tap it for Fit) is checked on the buttons, Ctrl and the wheel, and a pinch. Demo and tests only: the package's code is unchanged. kazoku-ui is `^0.24.0`.
|
|
9
|
+
|
|
10
|
+
## 0.19.0 - 2026-11-09
|
|
11
|
+
|
|
12
|
+
- **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`.
|
|
13
|
+
|
|
5
14
|
## 0.18.0 - 2026-11-08
|
|
6
15
|
|
|
7
16
|
- **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`.
|
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
|
@@ -194,6 +194,18 @@ document.querySelector("chikyu-space")!.setSatellites("stations", createSatellit
|
|
|
194
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
|
|
195
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).
|
|
196
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
|
+
|
|
197
209
|
## Markers
|
|
198
210
|
|
|
199
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
|
|
@@ -387,6 +399,7 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
|
|
|
387
399
|
| [Satellites](docs/guides/satellites.md) | SGP4 and the space view |
|
|
388
400
|
| [Ride along](docs/guides/ride-along.md) | A camera on a moving body |
|
|
389
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 |
|
|
390
403
|
| [Why two packages](docs/guides/two-packages.md) | This package and wakusei-planets: which to install, alone and together |
|
|
391
404
|
| [How it stays light](docs/guides/how-it-works.md) | The budget |
|
|
392
405
|
| [Architecture](docs/guides/architecture.md) | How the layers fit |
|
|
@@ -484,7 +497,7 @@ Chikyu (地球, ちきゅう) is Japanese for the Earth.
|
|
|
484
497
|
## The family
|
|
485
498
|
|
|
486
499
|
<!-- family:start (made by scripts/family-readme.mjs from scripts/family-template.mjs; change those, not this) -->
|
|
487
|
-
Chikyu Earth is one of
|
|
500
|
+
Chikyu Earth is one of forty-one packages, each made for the same site, each at
|
|
488
501
|
[github.com/johnmorrisdotca](https://github.com/johnmorrisdotca) or [github.com/spxis](https://github.com/spxis). The code of every one is MIT.
|
|
489
502
|
|
|
490
503
|
**Games — board**
|
|
@@ -497,6 +510,7 @@ Chikyu Earth is one of thirty-three packages, each made for the same site, each
|
|
|
497
510
|
|
|
498
511
|
**Games — cards & tiles**
|
|
499
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/).
|
|
500
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/).
|
|
501
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/).
|
|
502
516
|
- [Kumimoji](https://github.com/johnmorrisdotca/kumimoji) (組み文字): a crossword tile race, in English and Japanese kana. [Demo](https://johnmorrisdotca.github.io/kumimoji/).
|
|
@@ -523,20 +537,30 @@ Chikyu Earth is one of thirty-three packages, each made for the same site, each
|
|
|
523
537
|
|
|
524
538
|
- [Bushu](https://github.com/johnmorrisdotca/bushu) (部首): find a kanji by the parts it is made of. [Demo](https://johnmorrisdotca.github.io/bushu/).
|
|
525
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/).
|
|
526
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/).
|
|
527
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
|
+
|
|
528
550
|
**Geography & data**
|
|
529
551
|
|
|
530
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/).
|
|
531
|
-
- [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/).
|
|
532
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/).
|
|
533
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/).
|
|
534
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/).
|
|
535
558
|
|
|
536
559
|
**Sports**
|
|
537
560
|
|
|
538
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/).
|
|
539
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/).
|
|
540
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/).
|
|
541
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/).
|
|
542
566
|
|
|
@@ -545,7 +569,7 @@ Chikyu Earth is one of thirty-three packages, each made for the same site, each
|
|
|
545
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/).
|
|
546
570
|
|
|
547
571
|
|
|
548
|
-
**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.
|
|
549
573
|
<!-- family:end -->
|
|
550
574
|
|
|
551
575
|
## The rest
|
|
@@ -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;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The "my country" sheet: the country's outline, big and thick, its capital marked with a star, a box to draw its flag in and three facts. Pure: a string of SVG measured in millimetres.
|
|
2
|
+
import { geoAzimuthalEqualArea, geoCentroid, geoPath } from "d3-geo";
|
|
3
|
+
import { countryShape } from "./land.js";
|
|
4
|
+
import { thickPath } from "./outline.js";
|
|
5
|
+
import { TITLES, SAY, countryFacts } from "./text.js";
|
|
6
|
+
import { TYPES, esc, factsBlock, haloText, innerMm, labelMm, outlineMm, svgOpen, textWidth, wrap } from "./common.js";
|
|
7
|
+
const GAP = 5;
|
|
8
|
+
/** A five-pointed star centred on `x`, `y`, `outer` from the middle to a point. */
|
|
9
|
+
function star(x, y, outer) {
|
|
10
|
+
const points = [];
|
|
11
|
+
for (let i = 0; i < 10; i += 1) {
|
|
12
|
+
const radius = i % 2 === 0 ? outer : outer * 0.42;
|
|
13
|
+
const angle = (Math.PI / 5) * i - Math.PI / 2;
|
|
14
|
+
points.push(`${(x + radius * Math.cos(angle)).toFixed(2)},${(y + radius * Math.sin(angle)).toFixed(2)}`);
|
|
15
|
+
}
|
|
16
|
+
return points.join(" ");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 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:
|
|
20
|
+
* the continent, the countries it touches, the capital. The flag is a box to fill in, never a picture: the sheet carries no flag.
|
|
21
|
+
* @param alpha2 - The country's two-letter code, such as `JP`.
|
|
22
|
+
* @param options - The room, the language, the type and the capital.
|
|
23
|
+
* @returns The `<svg>` markup, or `undefined` when the package has no outline for the code.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { countrySheetSvg } from "@johnmorrisdotca/chikyu-earth/sheets";
|
|
28
|
+
*
|
|
29
|
+
* const svg = countrySheetSvg("JP", { widthMm: 184.6, heightMm: 180, capital: { name: "Tokyo", lon: 139.7, lat: 35.7 } });
|
|
30
|
+
* console.log(svg?.includes("Tokyo"), svg?.includes("Draw the flag!"));
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function countrySheetSvg(alpha2, options) {
|
|
34
|
+
const shape = countryShape(alpha2);
|
|
35
|
+
if (shape === undefined)
|
|
36
|
+
return undefined;
|
|
37
|
+
const { widthMm: w, heightMm: h } = options;
|
|
38
|
+
const lang = options.lang ?? "en";
|
|
39
|
+
const type = options.type ?? "kid";
|
|
40
|
+
const outline = outlineMm(type);
|
|
41
|
+
const flagW = Math.min(58, w * 0.32);
|
|
42
|
+
const factsWidth = w - flagW - 8;
|
|
43
|
+
const capitalName = options.capital === undefined ? undefined : lang === "ja" ? (options.capital.ja ?? options.capital.name) : options.capital.name;
|
|
44
|
+
const facts = factsBlock(countryFacts(shape, capitalName, lang), factsWidth, 0, type);
|
|
45
|
+
const flagH = Math.max(facts.height, 40);
|
|
46
|
+
const strip = Math.max(facts.height, flagH);
|
|
47
|
+
const mapH = h - strip - GAP;
|
|
48
|
+
const centre = geoCentroid(shape.feature);
|
|
49
|
+
const pad = outline + 3;
|
|
50
|
+
const projection = geoAzimuthalEqualArea().rotate([-centre[0], -centre[1]]).fitExtent([[pad, pad], [w - pad, mapH - pad]], shape.feature);
|
|
51
|
+
const path = geoPath(projection);
|
|
52
|
+
const land = thickPath(path(shape.feature) ?? "", outline * 0.3, outline * 1.2);
|
|
53
|
+
let marks = `<path d="${land}" fill="none" stroke="#000" stroke-width="${outline}" stroke-linejoin="round" data-country="${shape.alpha2 ?? ""}"/>`;
|
|
54
|
+
if (options.capital !== undefined) {
|
|
55
|
+
const at = projection([options.capital.lon, options.capital.lat]);
|
|
56
|
+
if (at !== null) {
|
|
57
|
+
const size = labelMm(type);
|
|
58
|
+
const radius = type === "kid" ? 7 : 3.5;
|
|
59
|
+
const toRight = at[0] + radius + 2 + textWidth(capitalName, size) <= w;
|
|
60
|
+
const x = toRight ? at[0] + radius + 2 : at[0] - radius - 2;
|
|
61
|
+
marks += `<polygon points="${star(at[0], at[1], radius)}" fill="#000" stroke="#fff" stroke-width="${innerMm(type)}" stroke-linejoin="round" paint-order="stroke" data-capital=""/>`;
|
|
62
|
+
marks += haloText(x, at[1] + size * 0.34, size, capitalName, ' data-capital-name=""', toRight ? "start" : "end");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const top = mapH + GAP;
|
|
66
|
+
const left = `<g transform="translate(0 ${top + (strip - facts.height) / 2})">${facts.markup}</g>`;
|
|
67
|
+
const bodyMm = TYPES[type].bodyMm;
|
|
68
|
+
const box = `<g transform="translate(${w - flagW} ${top})"><rect x="${outline / 2}" y="${outline / 2}" width="${flagW - outline}" height="${strip - outline}" rx="3" fill="none" stroke="#000" stroke-width="${innerMm(type)}" data-flag-box=""/>${wrap(SAY[lang].flag, flagW - 2 * outline, bodyMm).map((line, i) => `<text x="${flagW / 2}" y="${outline + bodyMm * (0.9 + 1.2 * i)}" font-size="${bodyMm}" font-weight="700" fill="#000" text-anchor="middle" data-flag-say="">${esc(line)}</text>`).join("")}</g>`;
|
|
69
|
+
return `${svgOpen(w, h, TITLES.country(lang === "ja" ? shape.ja : shape.name, lang), "country")}${marks}${left}${box}</svg>`;
|
|
70
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type GlobeView } from "./text.ts";
|
|
2
|
+
import { type Lang, type TypeName } from "./common.ts";
|
|
3
|
+
/**
|
|
4
|
+
* What a sheet is drawn for: the room in millimetres, the language and the type.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { worldMapSvg, type SheetOptions } from "@johnmorrisdotca/chikyu-earth/sheets";
|
|
9
|
+
*
|
|
10
|
+
* const options: SheetOptions = { widthMm: 184.6, heightMm: 170, lang: "ja", type: "kid" };
|
|
11
|
+
* console.log(worldMapSvg(options).includes("たいへいよう"));
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export interface SheetOptions {
|
|
15
|
+
widthMm: number;
|
|
16
|
+
heightMm: number;
|
|
17
|
+
lang?: Lang;
|
|
18
|
+
/** `kid` (default): thick lines and big type. `normal`: thin lines and small type. */
|
|
19
|
+
type?: TypeName;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The globe as a colouring sheet: one side of the Earth as a big disc, the continents with thick outlines, the continents' and oceans' names written on them, and three facts under it. A view is the Americas, Europe and Africa, or Asia and Oceania.
|
|
23
|
+
* `widthMm` and `heightMm` are the room it is drawn for, and the viewBox is that room, so a millimetre is a millimetre on paper.
|
|
24
|
+
* @param view - `americas`, `europe-africa` or `asia-oceania`.
|
|
25
|
+
* @param options - The room, the language and the type.
|
|
26
|
+
* @returns The `<svg>` markup.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { globeSheetSvg } from "@johnmorrisdotca/chikyu-earth/sheets";
|
|
31
|
+
*
|
|
32
|
+
* const svg = globeSheetSvg("europe-africa", { widthMm: 184.6, heightMm: 180, lang: "en" });
|
|
33
|
+
* console.log(svg.includes("Africa"), svg.includes("Atlantic"));
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function globeSheetSvg(view: GlobeView, options: SheetOptions): string;
|
|
37
|
+
/**
|
|
38
|
+
* The world map as a colouring sheet: all the land on one flat map, the continents with thick outlines, the names of the continents and of the five oceans written on it, and three facts.
|
|
39
|
+
* @param options - The room, the language and the type.
|
|
40
|
+
* @returns The `<svg>` markup.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { worldMapSvg } from "@johnmorrisdotca/chikyu-earth/sheets";
|
|
45
|
+
*
|
|
46
|
+
* const svg = worldMapSvg({ widthMm: 184.6, heightMm: 180, lang: "en" });
|
|
47
|
+
* console.log(svg.includes("Pacific"));
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function worldMapSvg(options: SheetOptions): string;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// The globe sheet and the world map: the continents with thick outlines and their names and the oceans' written where they are, then three facts. Pure: each is a string of SVG measured in millimetres.
|
|
2
|
+
import { geoNaturalEarth1, geoOrthographic, geoPath } from "d3-geo";
|
|
3
|
+
import { continentLines } from "./land.js";
|
|
4
|
+
import { PLACES, VIEW_CENTRES, VIEW_LABELS, earthFacts } from "./text.js";
|
|
5
|
+
import { thickPath } from "./outline.js";
|
|
6
|
+
import { factsBlock, labelMm, nameBlock, outlineMm, svgOpen } from "./common.js";
|
|
7
|
+
import { TITLES } from "./text.js";
|
|
8
|
+
const SPHERE = { type: "Sphere" };
|
|
9
|
+
const GAP = 5;
|
|
10
|
+
/** The smallest island kept before the lines are made simpler. */
|
|
11
|
+
const MIN_ISLAND_SR = 0.0006;
|
|
12
|
+
/** The names written on a picture, each centred where `spot` says (a place with no spot is left out). A name that does not fit `inside` is left out too. */
|
|
13
|
+
function names(projection, lang, type, inside, spot, flat = false) {
|
|
14
|
+
const size = labelMm(type);
|
|
15
|
+
const out = [];
|
|
16
|
+
for (const place of PLACES) {
|
|
17
|
+
const at = spot(place);
|
|
18
|
+
if (at === undefined)
|
|
19
|
+
continue;
|
|
20
|
+
const point = projection([at[0], at[1]]);
|
|
21
|
+
if (point === null)
|
|
22
|
+
continue;
|
|
23
|
+
const lines = flat && place.oneLine === true ? [(lang === "ja" ? place.ja : place.en).join(" ")] : lang === "ja" ? place.ja : place.en;
|
|
24
|
+
const block = nameBlock(lines, point[0], point[1], size, ` data-place="${place.id}"`);
|
|
25
|
+
const box = { x0: point[0] - block.width / 2, x1: point[0] + block.width / 2, y0: point[1] - block.height / 2, y1: point[1] + block.height / 2 };
|
|
26
|
+
if (inside(box))
|
|
27
|
+
out.push(block.markup);
|
|
28
|
+
}
|
|
29
|
+
return out.join("");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The globe as a colouring sheet: one side of the Earth as a big disc, the continents with thick outlines, the continents' and oceans' names written on them, and three facts under it. A view is the Americas, Europe and Africa, or Asia and Oceania.
|
|
33
|
+
* `widthMm` and `heightMm` are the room it is drawn for, and the viewBox is that room, so a millimetre is a millimetre on paper.
|
|
34
|
+
* @param view - `americas`, `europe-africa` or `asia-oceania`.
|
|
35
|
+
* @param options - The room, the language and the type.
|
|
36
|
+
* @returns The `<svg>` markup.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { globeSheetSvg } from "@johnmorrisdotca/chikyu-earth/sheets";
|
|
41
|
+
*
|
|
42
|
+
* const svg = globeSheetSvg("europe-africa", { widthMm: 184.6, heightMm: 180, lang: "en" });
|
|
43
|
+
* console.log(svg.includes("Africa"), svg.includes("Atlantic"));
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function globeSheetSvg(view, options) {
|
|
47
|
+
const { widthMm: w, heightMm: h } = options;
|
|
48
|
+
const lang = options.lang ?? "en";
|
|
49
|
+
const type = options.type ?? "kid";
|
|
50
|
+
const outline = outlineMm(type);
|
|
51
|
+
const facts = factsBlock(earthFacts("globe", lang), w, 0, type);
|
|
52
|
+
const free = h - facts.height - GAP;
|
|
53
|
+
const diameter = Math.min(w, free);
|
|
54
|
+
const radius = diameter / 2 - outline / 2;
|
|
55
|
+
const cx = w / 2;
|
|
56
|
+
const cy = free / 2;
|
|
57
|
+
const centre = VIEW_CENTRES[view];
|
|
58
|
+
const projection = geoOrthographic().rotate([-centre[0], -centre[1]]).translate([cx, cy]).scale(radius).clipAngle(90).precision(0.3);
|
|
59
|
+
const path = geoPath(projection);
|
|
60
|
+
const coast = thickPath(path({ type: "MultiLineString", coordinates: continentLines(MIN_ISLAND_SR) }) ?? "", outline * 0.4, outline * 3.5);
|
|
61
|
+
const rim = `<circle cx="${cx}" cy="${cy}" r="${radius}" fill="none" stroke="#000" stroke-width="${outline}" data-rim=""/>`;
|
|
62
|
+
const lines = `<path d="${coast}" fill="none" stroke="#000" stroke-width="${outline}" stroke-linecap="round" stroke-linejoin="round" data-coast=""/>`;
|
|
63
|
+
const inside = (box) => [[box.x0, box.y0], [box.x1, box.y0], [box.x0, box.y1], [box.x1, box.y1]].every(([x, y]) => Math.hypot(x - cx, y - cy) <= radius - outline);
|
|
64
|
+
const words = names(projection, lang, type, inside, (place) => VIEW_LABELS[view][place.id]);
|
|
65
|
+
const label = TITLES.globe(view, lang);
|
|
66
|
+
return `${svgOpen(w, h, label, "globe")}${rim}${lines}${words}<g transform="translate(0 ${h - facts.height})">${facts.markup}</g></svg>`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The world map as a colouring sheet: all the land on one flat map, the continents with thick outlines, the names of the continents and of the five oceans written on it, and three facts.
|
|
70
|
+
* @param options - The room, the language and the type.
|
|
71
|
+
* @returns The `<svg>` markup.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { worldMapSvg } from "@johnmorrisdotca/chikyu-earth/sheets";
|
|
76
|
+
*
|
|
77
|
+
* const svg = worldMapSvg({ widthMm: 184.6, heightMm: 180, lang: "en" });
|
|
78
|
+
* console.log(svg.includes("Pacific"));
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export function worldMapSvg(options) {
|
|
82
|
+
const { widthMm: w, heightMm: h } = options;
|
|
83
|
+
const lang = options.lang ?? "en";
|
|
84
|
+
const type = options.type ?? "kid";
|
|
85
|
+
const outline = outlineMm(type);
|
|
86
|
+
const facts = factsBlock(earthFacts("map", lang), w, 0, type);
|
|
87
|
+
const free = h - facts.height - GAP;
|
|
88
|
+
const projection = geoNaturalEarth1();
|
|
89
|
+
projection.fitWidth(w - outline, SPHERE);
|
|
90
|
+
const [tx, ty] = projection.translate();
|
|
91
|
+
projection.translate([tx + outline / 2, ty + outline / 2]);
|
|
92
|
+
const path = geoPath(projection);
|
|
93
|
+
const bounds = path.bounds(SPHERE);
|
|
94
|
+
const mapH = bounds[1][1] - bounds[0][1] + outline;
|
|
95
|
+
const top = Math.max(0, (free - mapH) / 2);
|
|
96
|
+
const coast = thickPath(path({ type: "MultiLineString", coordinates: continentLines(MIN_ISLAND_SR) }) ?? "", outline * 0.4, outline * 3.5);
|
|
97
|
+
const frame = path(SPHERE) ?? "";
|
|
98
|
+
const inside = (box) => box.x0 >= 0 && box.x1 <= w && box.y0 >= bounds[0][1] && box.y1 <= bounds[1][1] + outline;
|
|
99
|
+
const words = names(projection, lang, type, inside, (place) => place.mapAt ?? place.at, true);
|
|
100
|
+
const label = TITLES.map(lang);
|
|
101
|
+
const picture = `<path d="${frame}" fill="none" stroke="#000" stroke-width="${outline}" stroke-linejoin="round" data-rim=""/><path d="${coast}" fill="none" stroke="#000" stroke-width="${outline}" stroke-linecap="round" stroke-linejoin="round" data-coast=""/>${words}`;
|
|
102
|
+
return `${svgOpen(w, h, label, "map")}<g transform="translate(0 ${top})">${picture}</g><g transform="translate(0 ${h - facts.height})">${facts.markup}</g></svg>`;
|
|
103
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface Bounds {
|
|
2
|
+
x0: number;
|
|
3
|
+
y0: number;
|
|
4
|
+
x1: number;
|
|
5
|
+
y1: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Parallel lines, `spacing` apart at `angleDeg`, cut to where `inside(x, y)` is true, as the data of one SVG path (a millimetre of the picture is a millimetre of the paper). Each end is found to a twentieth of a millimetre.
|
|
9
|
+
* @param bounds - The box the lines are laid over.
|
|
10
|
+
* @param spacing - The gap between lines, in millimetres.
|
|
11
|
+
* @param angleDeg - The turn of the lines, in degrees from the x axis.
|
|
12
|
+
* @param inside - Whether a point is in the shaded part.
|
|
13
|
+
* @returns Path data: `M x y L x y` for each stroke.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { hatchPath } from "@johnmorrisdotca/chikyu-earth/sheets";
|
|
18
|
+
*
|
|
19
|
+
* const d = hatchPath({ x0: 0, y0: 0, x1: 20, y1: 20 }, 4, 45, (x) => x < 10);
|
|
20
|
+
* console.log(d.startsWith("M"));
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function hatchPath(bounds: Bounds, spacing: number, angleDeg: number, inside: (x: number, y: number) => boolean): string;
|